f7eafe97eb2a96bbce500bf025cd51db06d3eadf
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'mm-uu-dissect "mm-uu")
57 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
58   "Deuglify broken Outlook (Express) articles and redisplay."
59   t)
60 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
61 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
62 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
63
64 (defcustom gnus-kill-summary-on-exit t
65   "*If non-nil, kill the summary buffer when you exit from it.
66 If nil, the summary will become a \"*Dead Summary*\" buffer, and
67 it will be killed sometime later."
68   :group 'gnus-summary-exit
69   :type 'boolean)
70
71 (defcustom gnus-fetch-old-headers nil
72   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
73 If an unread article in the group refers to an older, already read (or
74 just marked as read) article, the old article will not normally be
75 displayed in the Summary buffer.  If this variable is non-nil, Gnus
76 will attempt to grab the headers to the old articles, and thereby
77 build complete threads.  If it has the value `some', only enough
78 headers to connect otherwise loose threads will be displayed.  This
79 variable can also be a number.  In that case, no more than that number
80 of old headers will be fetched.  If it has the value `invisible', all
81 old headers will be fetched, but none will be displayed.
82
83 The server has to support NOV for any of this to work."
84   :group 'gnus-thread
85   :type '(choice (const :tag "off" nil)
86                  (const some)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 200
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :group 'gnus-thread
129   :type 'boolean)
130
131 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
132   "*A regexp to match subjects to be excluded from loose thread gathering.
133 As loose thread gathering is done on subjects only, that means that
134 there can be many false gatherings performed.  By rooting out certain
135 common subjects, gathering might become saner."
136   :group 'gnus-thread
137   :type 'regexp)
138
139 (defcustom gnus-summary-gather-subject-limit nil
140   "*Maximum length of subject comparisons when gathering loose threads.
141 Use nil to compare full subjects.  Setting this variable to a low
142 number will help gather threads that have been corrupted by
143 newsreaders chopping off subject lines, but it might also mean that
144 unrelated articles that have subject that happen to begin with the
145 same few characters will be incorrectly gathered.
146
147 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
148 comparing subjects."
149   :group 'gnus-thread
150   :type '(choice (const :tag "off" nil)
151                  (const fuzzy)
152                  (sexp :menu-tag "on" t)))
153
154 (defcustom gnus-simplify-subject-functions nil
155   "List of functions taking a string argument that simplify subjects.
156 The functions are applied recursively.
157
158 Useful functions to put in this list include:
159 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
160 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
161   :group 'gnus-thread
162   :type '(repeat function))
163
164 (defcustom gnus-simplify-ignored-prefixes nil
165   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  regexp))
169
170 (defcustom gnus-build-sparse-threads nil
171   "*If non-nil, fill in the gaps in threads.
172 If `some', only fill in the gaps that are needed to tie loose threads
173 together.  If `more', fill in all leaf nodes that Gnus can find.  If
174 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
175   :group 'gnus-thread
176   :type '(choice (const :tag "off" nil)
177                  (const some)
178                  (const more)
179                  (sexp :menu-tag "all" t)))
180
181 (defcustom gnus-summary-thread-gathering-function
182   'gnus-gather-threads-by-subject
183   "*Function used for gathering loose threads.
184 There are two pre-defined functions: `gnus-gather-threads-by-subject',
185 which only takes Subjects into consideration; and
186 `gnus-gather-threads-by-references', which compared the References
187 headers of the articles to find matches."
188   :group 'gnus-thread
189   :type '(radio (function-item gnus-gather-threads-by-subject)
190                 (function-item gnus-gather-threads-by-references)
191                 (function :tag "other")))
192
193 (defcustom gnus-summary-same-subject ""
194   "*String indicating that the current article has the same subject as the previous.
195 This variable will only be used if the value of
196 `gnus-summary-make-false-root' is `empty'."
197   :group 'gnus-summary-format
198   :type 'string)
199
200 (defcustom gnus-summary-goto-unread t
201   "*If t, many commands will go to the next unread article.
202 This applies to marking commands as well as other commands that
203 \"naturally\" select the next article, like, for instance, `SPC' at
204 the end of an article.
205
206 If nil, the marking commands do NOT go to the next unread article
207 \(they go to the next article instead).  If `never', commands that
208 usually go to the next unread article, will go to the next article,
209 whether it is read or not."
210   :group 'gnus-summary-marks
211   :link '(custom-manual "(gnus)Setting Marks")
212   :type '(choice (const :tag "off" nil)
213                  (const never)
214                  (sexp :menu-tag "on" t)))
215
216 (defcustom gnus-summary-default-score 0
217   "*Default article score level.
218 All scores generated by the score files will be added to this score.
219 If this variable is nil, scoring will be disabled."
220   :group 'gnus-score-default
221   :type '(choice (const :tag "disable")
222                  integer))
223
224 (defcustom gnus-summary-default-high-score 0
225   "*Default threshold for a high scored article.
226 An article will be highlighted as high scored if its score is greater
227 than this score."
228   :group 'gnus-score-default
229   :type 'integer)
230
231 (defcustom gnus-summary-default-low-score 0
232   "*Default threshold for a low scored article.
233 An article will be highlighted as low scored if its score is smaller
234 than this score."
235   :group 'gnus-score-default
236   :type 'integer)
237
238 (defcustom gnus-summary-zcore-fuzz 0
239   "*Fuzziness factor for the zcore in the summary buffer.
240 Articles with scores closer than this to `gnus-summary-default-score'
241 will not be marked."
242   :group 'gnus-summary-format
243   :type 'integer)
244
245 (defcustom gnus-simplify-subject-fuzzy-regexp nil
246   "*Strings to be removed when doing fuzzy matches.
247 This can either be a regular expression or list of regular expressions
248 that will be removed from subject strings if fuzzy subject
249 simplification is selected."
250   :group 'gnus-thread
251   :type '(repeat regexp))
252
253 (defcustom gnus-show-threads t
254   "*If non-nil, display threads in summary mode."
255   :group 'gnus-thread
256   :type 'boolean)
257
258 (defcustom gnus-thread-hide-subtree nil
259   "*If non-nil, hide all threads initially.
260 This can be a predicate specifier which says which threads to hide.
261 If threads are hidden, you have to run the command
262 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
263 to expose hidden threads."
264   :group 'gnus-thread
265   :type 'boolean)
266
267 (defcustom gnus-thread-hide-killed t
268   "*If non-nil, hide killed threads automatically."
269   :group 'gnus-thread
270   :type 'boolean)
271
272 (defcustom gnus-thread-ignore-subject t
273   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
274 If nil, articles that have different subjects from their parents will
275 start separate threads."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-operation-ignore-subject t
280   "*If non-nil, subjects will be ignored when doing thread commands.
281 This affects commands like `gnus-summary-kill-thread' and
282 `gnus-summary-lower-thread'.
283
284 If this variable is nil, articles in the same thread with different
285 subjects will not be included in the operation in question.  If this
286 variable is `fuzzy', only articles that have subjects that are fuzzily
287 equal will be included."
288   :group 'gnus-thread
289   :type '(choice (const :tag "off" nil)
290                  (const fuzzy)
291                  (sexp :tag "on" t)))
292
293 (defcustom gnus-thread-indent-level 4
294   "*Number that says how much each sub-thread should be indented."
295   :group 'gnus-thread
296   :type 'integer)
297
298 (defcustom gnus-auto-extend-newsgroup t
299   "*If non-nil, extend newsgroup forward and backward when requested."
300   :group 'gnus-summary-choose
301   :type 'boolean)
302
303 (defcustom gnus-auto-select-first t
304   "*If non-nil, select the article under point.
305 Which article this is is controlled by the `gnus-auto-select-subject'
306 variable.
307
308 If you want to prevent automatic selection of articles in some
309 newsgroups, set the variable to nil in `gnus-select-group-hook'."
310   :group 'gnus-group-select
311   :type '(choice (const :tag "none" nil)
312                  (sexp :menu-tag "first" t)))
313
314 (defcustom gnus-auto-select-subject 'unread
315   "*Says what subject to place under point when entering a group.
316
317 This variable can either be the symbols `first' (place point on the
318 first subject), `unread' (place point on the subject line of the first
319 unread article), `best' (place point on the subject line of the
320 higest-scored article), `unseen' (place point on the subject line of
321 the first unseen article), 'unseen-or-unread' (place point on the subject
322 line of the first unseen article or, if all article have been seen, on the
323 subject line of the first unread article), or a function to be called to
324 place point on some subject line."
325   :group 'gnus-group-select
326   :type '(choice (const best)
327                  (const unread)
328                  (const first)
329                  (const unseen)
330                  (const unseen-or-unread)))
331
332 (defcustom gnus-dont-select-after-jump-to-other-group nil
333   "If non-nil, don't select the first unread article after entering the
334 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
335 it is depend on the value of `gnus-auto-select-first' whether to select
336 or not."
337   :group 'gnus-group-select
338   :type 'boolean)
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `Z n' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
364
365 (defcustom gnus-summary-check-current nil
366   "*If non-nil, consider the current article when moving.
367 The \"unread\" movement commands will stay on the same line if the
368 current article is unread."
369   :group 'gnus-summary-maneuvering
370   :type 'boolean)
371
372 (defcustom gnus-auto-center-summary t
373   "*If non-nil, always center the current summary buffer.
374 In particular, if `vertical' do only vertical recentering.  If non-nil
375 and non-`vertical', do both horizontal and vertical recentering."
376   :group 'gnus-summary-maneuvering
377   :type '(choice (const :tag "none" nil)
378                  (const vertical)
379                  (integer :tag "height")
380                  (sexp :menu-tag "both" t)))
381
382 (defcustom gnus-show-all-headers nil
383   "*If non-nil, don't hide any headers."
384   :group 'gnus-article-hiding
385   :group 'gnus-article-headers
386   :type 'boolean)
387
388 (defcustom gnus-summary-ignore-duplicates nil
389   "*If non-nil, ignore articles with identical Message-ID headers."
390   :group 'gnus-summary
391   :type 'boolean)
392
393 (defcustom gnus-single-article-buffer t
394   "*If non-nil, display all articles in the same buffer.
395 If nil, each group will get its own article buffer."
396   :group 'gnus-article-various
397   :type 'boolean)
398
399 (defcustom gnus-break-pages t
400   "*If non-nil, do page breaking on articles.
401 The page delimiter is specified by the `gnus-page-delimiter'
402 variable."
403   :group 'gnus-article-various
404   :type 'boolean)
405
406 (defcustom gnus-show-mime t
407   "*If non-nil, do mime processing of articles.
408 The articles will simply be fed to the function given by
409 `gnus-article-display-method-for-mime'."
410   :group 'gnus-article-mime
411   :type 'boolean)
412
413 (defcustom gnus-move-split-methods nil
414   "*Variable used to suggest where articles are to be moved to.
415 It uses the same syntax as the `gnus-split-methods' variable.
416 However, whereas `gnus-split-methods' specifies file names as targets,
417 this variable specifies group names."
418   :group 'gnus-summary-mail
419   :type '(repeat (choice (list :value (fun) function)
420                          (cons :value ("" "") regexp (repeat string))
421                          (sexp :value nil))))
422
423 (defcustom gnus-unread-mark ?\ ;;;Whitespace
424   "*Mark used for unread articles."
425   :group 'gnus-summary-marks
426   :type 'character)
427
428 (defcustom gnus-ticked-mark ?!
429   "*Mark used for ticked articles."
430   :group 'gnus-summary-marks
431   :type 'character)
432
433 (defcustom gnus-dormant-mark ??
434   "*Mark used for dormant articles."
435   :group 'gnus-summary-marks
436   :type 'character)
437
438 (defcustom gnus-del-mark ?r
439   "*Mark used for del'd articles."
440   :group 'gnus-summary-marks
441   :type 'character)
442
443 (defcustom gnus-read-mark ?R
444   "*Mark used for read articles."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-expirable-mark ?E
449   "*Mark used for expirable articles."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-killed-mark ?K
454   "*Mark used for killed articles."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-spam-mark ?H
459   "*Mark used for spam articles."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-souped-mark ?F
464   "*Mark used for souped articles."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-kill-file-mark ?X
469   "*Mark used for articles killed by kill files."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-low-score-mark ?Y
474   "*Mark used for articles with a low score."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-catchup-mark ?C
479   "*Mark used for articles that are caught up."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-replied-mark ?A
484   "*Mark used for articles that have been replied to."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-forwarded-mark ?F
489   "*Mark used for articles that have been forwarded."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-recent-mark ?N
494   "*Mark used for articles that are recent."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-cached-mark ?*
499   "*Mark used for articles that are in the cache."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-saved-mark ?S
504   "*Mark used for articles that have been saved."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-unseen-mark ?.
509   "*Mark used for articles that haven't been seen."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-no-mark ?\ ;;;Whitespace
514   "*Mark used for articles that have no other secondary mark."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-ancient-mark ?O
519   "*Mark used for ancient articles."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-sparse-mark ?Q
524   "*Mark used for sparsely reffed articles."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-canceled-mark ?G
529   "*Mark used for canceled articles."
530   :group 'gnus-summary-marks
531   :type 'character)
532
533 (defcustom gnus-duplicate-mark ?M
534   "*Mark used for duplicate articles."
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-undownloaded-mark ?-
539   "*Mark used for articles that weren't downloaded."
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-downloaded-mark ?+
544   "*Mark used for articles that were downloaded."
545   :group 'gnus-summary-marks
546   :type 'character)
547
548 (defcustom gnus-downloadable-mark ?%
549   "*Mark used for articles that are to be downloaded."
550   :group 'gnus-summary-marks
551   :type 'character)
552
553 (defcustom gnus-unsendable-mark ?=
554   "*Mark used for articles that won't be sent."
555   :group 'gnus-summary-marks
556   :type 'character)
557
558 (defcustom gnus-score-over-mark ?+
559   "*Score mark used for articles with high scores."
560   :group 'gnus-summary-marks
561   :type 'character)
562
563 (defcustom gnus-score-below-mark ?-
564   "*Score mark used for articles with low scores."
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
569   "*There is no thread under the article."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-not-empty-thread-mark ?=
574   "*There is a thread under the article."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-view-pseudo-asynchronously nil
579   "*If non-nil, Gnus will view pseudo-articles asynchronously."
580   :group 'gnus-extract-view
581   :type 'boolean)
582
583 (defcustom gnus-auto-expirable-marks
584   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
585         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
586         gnus-souped-mark gnus-duplicate-mark)
587   "*The list of marks converted into expiration if a group is auto-expirable."
588   :version "21.1"
589   :group 'gnus-summary
590   :type '(repeat character))
591
592 (defcustom gnus-inhibit-user-auto-expire t
593   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
594   :version "21.1"
595   :group 'gnus-summary
596   :type 'boolean)
597
598 (defcustom gnus-view-pseudos nil
599   "*If `automatic', pseudo-articles will be viewed automatically.
600 If `not-confirm', pseudos will be viewed automatically, and the user
601 will not be asked to confirm the command."
602   :group 'gnus-extract-view
603   :type '(choice (const :tag "off" nil)
604                  (const automatic)
605                  (const not-confirm)))
606
607 (defcustom gnus-view-pseudos-separately t
608   "*If non-nil, one pseudo-article will be created for each file to be viewed.
609 If nil, all files that use the same viewing command will be given as a
610 list of parameters to that command."
611   :group 'gnus-extract-view
612   :type 'boolean)
613
614 (defcustom gnus-insert-pseudo-articles t
615   "*If non-nil, insert pseudo-articles when decoding articles."
616   :group 'gnus-extract-view
617   :type 'boolean)
618
619 (defcustom gnus-summary-dummy-line-format
620   "   %(:                             :%) %S\n"
621   "*The format specification for the dummy roots in the summary buffer.
622 It works along the same lines as a normal formatting string,
623 with some simple extensions.
624
625 %S  The subject
626
627 General format specifiers can also be used.
628 See `(gnus)Formatting Variables'."
629   :link '(custom-manual "(gnus)Formatting Variables")
630   :group 'gnus-threading
631   :type 'string)
632
633 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
634   "*The format specification for the summary mode line.
635 It works along the same lines as a normal formatting string,
636 with some simple extensions:
637
638 %G  Group name
639 %p  Unprefixed group name
640 %A  Current article number
641 %z  Current article score
642 %V  Gnus version
643 %U  Number of unread articles in the group
644 %e  Number of unselected articles in the group
645 %Z  A string with unread/unselected article counts
646 %g  Shortish group name
647 %S  Subject of the current article
648 %u  User-defined spec
649 %s  Current score file name
650 %d  Number of dormant articles
651 %r  Number of articles that have been marked as read in this session
652 %E  Number of articles expunged by the score files"
653   :group 'gnus-summary-format
654   :type 'string)
655
656 (defcustom gnus-list-identifiers nil
657   "Regexp that matches list identifiers to be removed from subject.
658 This can also be a list of regexps."
659   :version "21.1"
660   :group 'gnus-summary-format
661   :group 'gnus-article-hiding
662   :type '(choice (const :tag "none" nil)
663                  (regexp :value ".*")
664                  (repeat :value (".*") regexp)))
665
666 (defcustom gnus-summary-mark-below 0
667   "*Mark all articles with a score below this variable as read.
668 This variable is local to each summary buffer and usually set by the
669 score file."
670   :group 'gnus-score-default
671   :type 'integer)
672
673 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
674   "*List of functions used for sorting articles in the summary buffer.
675
676 Each function takes two articles and returns non-nil if the first
677 article should be sorted before the other.  If you use more than one
678 function, the primary sort function should be the last.  You should
679 probably always include `gnus-article-sort-by-number' in the list of
680 sorting functions -- preferably first.  Also note that sorting by date
681 is often much slower than sorting by number, and the sorting order is
682 very similar.  (Sorting by date means sorting by the time the message
683 was sent, sorting by number means sorting by arrival time.)
684
685 Ready-made functions include `gnus-article-sort-by-number',
686 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
687 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
688 and `gnus-article-sort-by-score'.
689
690 When threading is turned on, the variable `gnus-thread-sort-functions'
691 controls how articles are sorted."
692   :group 'gnus-summary-sort
693   :type '(repeat (choice (function-item gnus-article-sort-by-number)
694                          (function-item gnus-article-sort-by-author)
695                          (function-item gnus-article-sort-by-subject)
696                          (function-item gnus-article-sort-by-date)
697                          (function-item gnus-article-sort-by-score)
698                          (function-item gnus-article-sort-by-random)
699                          (function :tag "other"))))
700
701 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
702   "*List of functions used for sorting threads in the summary buffer.
703 By default, threads are sorted by article number.
704
705 Each function takes two threads and returns non-nil if the first
706 thread should be sorted before the other.  If you use more than one
707 function, the primary sort function should be the last.  You should
708 probably always include `gnus-thread-sort-by-number' in the list of
709 sorting functions -- preferably first.  Also note that sorting by date
710 is often much slower than sorting by number, and the sorting order is
711 very similar.  (Sorting by date means sorting by the time the message
712 was sent, sorting by number means sorting by arrival time.)
713
714 Ready-made functions include `gnus-thread-sort-by-number',
715 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
716 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
717 `gnus-thread-sort-by-most-recent-number',
718 `gnus-thread-sort-by-most-recent-date',
719 `gnus-thread-sort-by-random', and
720 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
721
722 When threading is turned off, the variable
723 `gnus-article-sort-functions' controls how articles are sorted."
724   :group 'gnus-summary-sort
725   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
726                          (function-item gnus-thread-sort-by-author)
727                          (function-item gnus-thread-sort-by-subject)
728                          (function-item gnus-thread-sort-by-date)
729                          (function-item gnus-thread-sort-by-score)
730                          (function-item gnus-thread-sort-by-total-score)
731                          (function-item gnus-thread-sort-by-random)
732                          (function :tag "other"))))
733
734 (defcustom gnus-thread-score-function '+
735   "*Function used for calculating the total score of a thread.
736
737 The function is called with the scores of the article and each
738 subthread and should then return the score of the thread.
739
740 Some functions you can use are `+', `max', or `min'."
741   :group 'gnus-summary-sort
742   :type 'function)
743
744 (defcustom gnus-summary-expunge-below nil
745   "All articles that have a score less than this variable will be expunged.
746 This variable is local to the summary buffers."
747   :group 'gnus-score-default
748   :type '(choice (const :tag "off" nil)
749                  integer))
750
751 (defcustom gnus-thread-expunge-below nil
752   "All threads that have a total score less than this variable will be expunged.
753 See `gnus-thread-score-function' for en explanation of what a
754 \"thread score\" is.
755
756 This variable is local to the summary buffers."
757   :group 'gnus-threading
758   :group 'gnus-score-default
759   :type '(choice (const :tag "off" nil)
760                  integer))
761
762 (defcustom gnus-summary-mode-hook nil
763   "*A hook for Gnus summary mode.
764 This hook is run before any variables are set in the summary buffer."
765   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
766   :group 'gnus-summary-various
767   :type 'hook)
768
769 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
770 (when (featurep 'xemacs)
771   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
772   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
773   (add-hook 'gnus-summary-mode-hook
774             'gnus-xmas-switch-horizontal-scrollbar-off))
775
776 (defcustom gnus-summary-menu-hook nil
777   "*Hook run after the creation of the summary mode menu."
778   :group 'gnus-summary-visual
779   :type 'hook)
780
781 (defcustom gnus-summary-exit-hook nil
782   "*A hook called on exit from the summary buffer.
783 It will be called with point in the group buffer."
784   :group 'gnus-summary-exit
785   :type 'hook)
786
787 (defcustom gnus-summary-prepare-hook nil
788   "*A hook called after the summary buffer has been generated.
789 If you want to modify the summary buffer, you can use this hook."
790   :group 'gnus-summary-various
791   :type 'hook)
792
793 (defcustom gnus-summary-prepared-hook nil
794   "*A hook called as the last thing after the summary buffer has been generated."
795   :group 'gnus-summary-various
796   :type 'hook)
797
798 (defcustom gnus-summary-generate-hook nil
799   "*A hook run just before generating the summary buffer.
800 This hook is commonly used to customize threading variables and the
801 like."
802   :group 'gnus-summary-various
803   :type 'hook)
804
805 (defcustom gnus-select-group-hook nil
806   "*A hook called when a newsgroup is selected.
807
808 If you'd like to simplify subjects like the
809 `gnus-summary-next-same-subject' command does, you can use the
810 following hook:
811
812  (add-hook gnus-select-group-hook
813            (lambda ()
814              (mapcar (lambda (header)
815                        (mail-header-set-subject
816                         header
817                         (gnus-simplify-subject
818                          (mail-header-subject header) 're-only)))
819                      gnus-newsgroup-headers)))"
820   :group 'gnus-group-select
821   :type 'hook)
822
823 (defcustom gnus-select-article-hook nil
824   "*A hook called when an article is selected."
825   :group 'gnus-summary-choose
826   :options '(gnus-agent-fetch-selected-article)
827   :type 'hook)
828
829 (defcustom gnus-visual-mark-article-hook
830   (list 'gnus-highlight-selected-summary)
831   "*Hook run after selecting an article in the summary buffer.
832 It is meant to be used for highlighting the article in some way.  It
833 is not run if `gnus-visual' is nil."
834   :group 'gnus-summary-visual
835   :type 'hook)
836
837 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
838   "*A hook called before parsing the headers."
839   :group 'gnus-various
840   :type 'hook)
841
842 (defcustom gnus-exit-group-hook nil
843   "*A hook called when exiting summary mode.
844 This hook is not called from the non-updating exit commands like `Q'."
845   :group 'gnus-various
846   :type 'hook)
847
848 (defcustom gnus-summary-update-hook
849   (list 'gnus-summary-highlight-line)
850   "*A hook called when a summary line is changed.
851 The hook will not be called if `gnus-visual' is nil.
852
853 The default function `gnus-summary-highlight-line' will
854 highlight the line according to the `gnus-summary-highlight'
855 variable."
856   :group 'gnus-summary-visual
857   :type 'hook)
858
859 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
860   "*A hook called when an article is selected for the first time.
861 The hook is intended to mark an article as read (or unread)
862 automatically when it is selected."
863   :group 'gnus-summary-choose
864   :type 'hook)
865
866 (defcustom gnus-group-no-more-groups-hook nil
867   "*A hook run when returning to group mode having no more (unread) groups."
868   :group 'gnus-group-select
869   :type 'hook)
870
871 (defcustom gnus-ps-print-hook nil
872   "*A hook run before ps-printing something from Gnus."
873   :group 'gnus-summary
874   :type 'hook)
875
876 (defcustom gnus-summary-display-arrow
877   (and (fboundp 'display-graphic-p)
878        (display-graphic-p))
879   "*If non-nil, display an arrow highlighting the current article."
880   :version "21.1"
881   :group 'gnus-summary
882   :type 'boolean)
883
884 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
885   "Face used for highlighting the current article in the summary buffer."
886   :group 'gnus-summary-visual
887   :type 'face)
888
889 (defvar gnus-tmp-downloaded nil)
890
891 (defcustom gnus-summary-highlight
892   '(((eq mark gnus-canceled-mark)
893      . gnus-summary-cancelled-face)
894     ((and uncached (> score default-high))
895      . gnus-summary-high-undownloaded-face)
896     ((and uncached (< score default-low))
897      . gnus-summary-low-undownloaded-face)
898     (uncached
899      . gnus-summary-normal-undownloaded-face)
900     ((and (> score default-high)
901           (or (eq mark gnus-dormant-mark)
902               (eq mark gnus-ticked-mark)))
903      . gnus-summary-high-ticked-face)
904     ((and (< score default-low)
905           (or (eq mark gnus-dormant-mark)
906               (eq mark gnus-ticked-mark)))
907      . gnus-summary-low-ticked-face)
908     ((or (eq mark gnus-dormant-mark)
909          (eq mark gnus-ticked-mark))
910      . gnus-summary-normal-ticked-face)
911     ((and (> score default-high) (eq mark gnus-ancient-mark))
912      . gnus-summary-high-ancient-face)
913     ((and (< score default-low) (eq mark gnus-ancient-mark))
914      . gnus-summary-low-ancient-face)
915     ((eq mark gnus-ancient-mark)
916      . gnus-summary-normal-ancient-face)
917     ((and (> score default-high) (eq mark gnus-unread-mark))
918      . gnus-summary-high-unread-face)
919     ((and (< score default-low) (eq mark gnus-unread-mark))
920      . gnus-summary-low-unread-face)
921     ((eq mark gnus-unread-mark)
922      . gnus-summary-normal-unread-face)
923     ((> score default-high)
924      . gnus-summary-high-read-face)
925     ((< score default-low)
926      . gnus-summary-low-read-face)
927     (t
928      . gnus-summary-normal-read-face))
929   "*Controls the highlighting of summary buffer lines.
930
931 A list of (FORM . FACE) pairs.  When deciding how a a particular
932 summary line should be displayed, each form is evaluated.  The content
933 of the face field after the first true form is used.  You can change
934 how those summary lines are displayed, by editing the face field.
935
936 You can use the following variables in the FORM field.
937
938 score:        The article's score
939 default:      The default article score.
940 default-high: The default score for high scored articles.
941 default-low:  The default score for low scored articles.
942 below:        The score below which articles are automatically marked as read.
943 mark:         The articles mark."
944   :group 'gnus-summary-visual
945   :type '(repeat (cons (sexp :tag "Form" nil)
946                        face)))
947
948 (defcustom gnus-alter-header-function nil
949   "Function called to allow alteration of article header structures.
950 The function is called with one parameter, the article header vector,
951 which it may alter in any way."
952   :type '(choice (const :tag "None" nil)
953                  function)
954   :group 'gnus-summary)
955
956 (defvar gnus-decode-encoded-word-function
957   (mime-find-field-decoder 'From 'nov)
958   "Variable that says which function should be used to decode a string with encoded words.")
959
960 (defcustom gnus-extra-headers '(To Newsgroups)
961   "*Extra headers to parse."
962   :version "21.1"
963   :group 'gnus-summary
964   :type '(repeat symbol))
965
966 (defcustom gnus-ignored-from-addresses
967   (and user-mail-address (regexp-quote user-mail-address))
968   "*Regexp of From headers that may be suppressed in favor of To headers."
969   :version "21.1"
970   :group 'gnus-summary
971   :type 'regexp)
972
973 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
974   "List of charsets that should be ignored.
975 When these charsets are used in the \"charset\" parameter, the
976 default charset will be used instead."
977   :version "21.1"
978   :type '(repeat symbol)
979   :group 'gnus-charset)
980
981 (gnus-define-group-parameter
982  ignored-charsets
983  :type list
984  :function-document
985  "Return the ignored charsets of GROUP."
986  :variable gnus-group-ignored-charsets-alist
987  :variable-default
988  '(("alt\\.chinese\\.text" iso-8859-1))
989  :variable-document
990  "Alist of regexps (to match group names) and charsets that should be ignored.
991 When these charsets are used in the \"charset\" parameter, the
992 default charset will be used instead."
993  :variable-group gnus-charset
994  :variable-type '(repeat (cons (regexp :tag "Group")
995                                (repeat symbol)))
996  :parameter-type '(choice :tag "Ignored charsets"
997                           :value nil
998                           (repeat (symbol)))
999  :parameter-document       "\
1000 List of charsets that should be ignored.
1001
1002 When these charsets are used in the \"charset\" parameter, the
1003 default charset will be used instead.")
1004
1005 (defcustom gnus-group-highlight-words-alist nil
1006   "Alist of group regexps and highlight regexps.
1007 This variable uses the same syntax as `gnus-emphasis-alist'."
1008   :version "21.1"
1009   :type '(repeat (cons (regexp :tag "Group")
1010                        (repeat (list (regexp :tag "Highlight regexp")
1011                                      (number :tag "Group for entire word" 0)
1012                                      (number :tag "Group for displayed part" 0)
1013                                      (symbol :tag "Face"
1014                                              gnus-emphasis-highlight-words)))))
1015   :group 'gnus-summary-visual)
1016
1017 (defcustom gnus-use-wheel nil
1018   "Use Intelli-mouse on summary movement"
1019   :type 'boolean
1020   :group 'gnus-summary-maneuvering)
1021
1022 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1023   "Amount to scroll messages by spinning the mouse wheel.
1024 This is actually a cons cell, where the first item is the amount to scroll
1025 on a normal wheel event, and the second is the amount to scroll when the
1026 wheel is moved with the shift key depressed."
1027   :type '(cons (integer :tag "Shift") integer)
1028   :group 'gnus-summary-maneuvering)
1029
1030 (defcustom gnus-wheel-edge-resistance 2
1031   "How hard it should be to change the current article
1032 by moving the mouse over the edge of the article window."
1033   :type 'integer
1034   :group 'gnus-summary-maneuvering)
1035
1036 (defcustom gnus-summary-show-article-charset-alist
1037   nil
1038   "Alist of number and charset.
1039 The article will be shown with the charset corresponding to the
1040 numbered argument.
1041 For example: ((1 . cn-gb-2312) (2 . big5))."
1042   :version "21.1"
1043   :type '(repeat (cons (number :tag "Argument" 1)
1044                        (symbol :tag "Charset")))
1045   :group 'gnus-charset)
1046
1047 (defcustom gnus-preserve-marks t
1048   "Whether marks are preserved when moving, copying and respooling messages."
1049   :version "21.1"
1050   :type 'boolean
1051   :group 'gnus-summary-marks)
1052
1053 (defcustom gnus-alter-articles-to-read-function nil
1054   "Function to be called to alter the list of articles to be selected."
1055   :type '(choice (const nil) function)
1056   :group 'gnus-summary)
1057
1058 (defcustom gnus-orphan-score nil
1059   "*All orphans get this score added.  Set in the score file."
1060   :group 'gnus-score-default
1061   :type '(choice (const nil)
1062                  integer))
1063
1064 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1065   "*A regexp to match MIME parts when saving multiple parts of a message
1066 with gnus-summary-save-parts (X m). This regexp will be used by default
1067 when prompting the user for which type of files to save."
1068   :group 'gnus-summary
1069   :type 'regexp)
1070
1071 (defcustom gnus-read-all-available-headers nil
1072   "Whether Gnus should parse all headers made available to it.
1073 This is mostly relevant for slow backends where the user may
1074 wish to widen the summary buffer to include all headers
1075 that were fetched.  Say, for nnultimate groups."
1076   :group 'gnus-summary
1077   :type '(choice boolean regexp))
1078
1079 (defcustom gnus-summary-muttprint-program "muttprint"
1080   "Command (and optional arguments) used to run Muttprint."
1081   :version "21.3"
1082   :group 'gnus-summary
1083   :type 'string)
1084
1085 (defcustom gnus-article-loose-mime nil
1086   "If non-nil, don't require MIME-Version header.
1087 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1088 supply the MIME-Version header or deliberately strip it From the mail.
1089 Set it to non-nil, Gnus will treat some articles as MIME even if
1090 the MIME-Version header is missed."
1091   :version "21.3"
1092   :type 'boolean
1093   :group 'gnus-article)
1094
1095 (defcustom gnus-article-emulate-mime t
1096   "If non-nil, use MIME emulation for uuencode and the like.
1097 This means that Gnus will search message bodies for text that look
1098 like uuencoded bits, yEncoded bits, and so on, and present that using
1099 the normal Gnus MIME machinery."
1100   :type 'boolean
1101   :group 'gnus-article)
1102
1103 ;;; Internal variables
1104
1105 (defvar gnus-summary-display-cache nil)
1106 (defvar gnus-article-mime-handles nil)
1107 (defvar gnus-article-decoded-p nil)
1108 (defvar gnus-article-charset nil)
1109 (defvar gnus-article-ignored-charsets nil)
1110 (defvar gnus-scores-exclude-files nil)
1111 (defvar gnus-page-broken nil)
1112
1113 (defvar gnus-original-article nil)
1114 (defvar gnus-article-internal-prepare-hook nil)
1115 (defvar gnus-newsgroup-process-stack nil)
1116
1117 (defvar gnus-thread-indent-array nil)
1118 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1119 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1120   "Function called to sort the articles within a thread after it has been gathered together.")
1121
1122 (defvar gnus-summary-save-parts-type-history nil)
1123 (defvar gnus-summary-save-parts-last-directory nil)
1124
1125 ;; Avoid highlighting in kill files.
1126 (defvar gnus-summary-inhibit-highlight nil)
1127 (defvar gnus-newsgroup-selected-overlay nil)
1128 (defvar gnus-inhibit-limiting nil)
1129 (defvar gnus-newsgroup-adaptive-score-file nil)
1130 (defvar gnus-current-score-file nil)
1131 (defvar gnus-current-move-group nil)
1132 (defvar gnus-current-copy-group nil)
1133 (defvar gnus-current-crosspost-group nil)
1134 (defvar gnus-newsgroup-display nil)
1135
1136 (defvar gnus-newsgroup-dependencies nil)
1137 (defvar gnus-newsgroup-adaptive nil)
1138 (defvar gnus-summary-display-article-function nil)
1139 (defvar gnus-summary-highlight-line-function nil
1140   "Function called after highlighting a summary line.")
1141
1142 (defvar gnus-summary-line-format-alist
1143   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1144     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1145     (?s gnus-tmp-subject-or-nil ?s)
1146     (?n gnus-tmp-name ?s)
1147     (?A (std11-address-string
1148          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1149     (?a (or (std11-full-name-string
1150              (car (mime-entity-read-field gnus-tmp-header 'From)))
1151             gnus-tmp-from) ?s)
1152     (?F gnus-tmp-from ?s)
1153     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1154     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1155     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1156     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1157     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1158     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1159     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1160     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1161     (?L gnus-tmp-lines ?s)
1162     (?O gnus-tmp-downloaded ?c)
1163     (?I gnus-tmp-indentation ?s)
1164     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1165     (?R gnus-tmp-replied ?c)
1166     (?\[ gnus-tmp-opening-bracket ?c)
1167     (?\] gnus-tmp-closing-bracket ?c)
1168     (?\> (make-string gnus-tmp-level ? ) ?s)
1169     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1170     (?i gnus-tmp-score ?d)
1171     (?z gnus-tmp-score-char ?c)
1172     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1173     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1174     (?U gnus-tmp-unread ?c)
1175     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1176         ?s)
1177     (?t (gnus-summary-number-of-articles-in-thread
1178          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1179         ?d)
1180     (?e (gnus-summary-number-of-articles-in-thread
1181          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1182         ?c)
1183     (?u gnus-tmp-user-defined ?s)
1184     (?P (gnus-pick-line-number) ?d)
1185     (?B gnus-tmp-thread-tree-header-string ?s)
1186     (user-date (gnus-user-date
1187                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1188   "An alist of format specifications that can appear in summary lines.
1189 These are paired with what variables they correspond with, along with
1190 the type of the variable (string, integer, character, etc).")
1191
1192 (defvar gnus-summary-dummy-line-format-alist
1193   `((?S gnus-tmp-subject ?s)
1194     (?N gnus-tmp-number ?d)
1195     (?u gnus-tmp-user-defined ?s)))
1196
1197 (defvar gnus-summary-mode-line-format-alist
1198   `((?G gnus-tmp-group-name ?s)
1199     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1200     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1201     (?A gnus-tmp-article-number ?d)
1202     (?Z gnus-tmp-unread-and-unselected ?s)
1203     (?V gnus-version ?s)
1204     (?U gnus-tmp-unread-and-unticked ?d)
1205     (?S gnus-tmp-subject ?s)
1206     (?e gnus-tmp-unselected ?d)
1207     (?u gnus-tmp-user-defined ?s)
1208     (?d (length gnus-newsgroup-dormant) ?d)
1209     (?t (length gnus-newsgroup-marked) ?d)
1210     (?h (length gnus-newsgroup-spam-marked) ?d)
1211     (?r (length gnus-newsgroup-reads) ?d)
1212     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1213     (?E gnus-newsgroup-expunged-tally ?d)
1214     (?s (gnus-current-score-file-nondirectory) ?s)))
1215
1216 (defvar gnus-last-search-regexp nil
1217   "Default regexp for article search command.")
1218
1219 (defvar gnus-summary-search-article-matched-data nil
1220   "Last matched data of article search command.  It is the local variable
1221 in `gnus-article-buffer' which consists of the list of start position,
1222 end position and text.")
1223
1224 (defvar gnus-last-shell-command nil
1225   "Default shell command on article.")
1226
1227 (defvar gnus-newsgroup-agentized nil
1228   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1229 (defvar gnus-newsgroup-begin nil)
1230 (defvar gnus-newsgroup-end nil)
1231 (defvar gnus-newsgroup-last-rmail nil)
1232 (defvar gnus-newsgroup-last-mail nil)
1233 (defvar gnus-newsgroup-last-folder nil)
1234 (defvar gnus-newsgroup-last-file nil)
1235 (defvar gnus-newsgroup-auto-expire nil)
1236 (defvar gnus-newsgroup-active nil)
1237
1238 (defvar gnus-newsgroup-data nil)
1239 (defvar gnus-newsgroup-data-reverse nil)
1240 (defvar gnus-newsgroup-limit nil)
1241 (defvar gnus-newsgroup-limits nil)
1242
1243 (defvar gnus-newsgroup-unreads nil
1244   "Sorted list of unread articles in the current newsgroup.")
1245
1246 (defvar gnus-newsgroup-unselected nil
1247   "Sorted list of unselected unread articles in the current newsgroup.")
1248
1249 (defvar gnus-newsgroup-reads nil
1250   "Alist of read articles and article marks in the current newsgroup.")
1251
1252 (defvar gnus-newsgroup-expunged-tally nil)
1253
1254 (defvar gnus-newsgroup-marked nil
1255   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1256
1257 (defvar gnus-newsgroup-spam-marked nil
1258   "List of ranges of articles that have been marked as spam.")
1259
1260 (defvar gnus-newsgroup-killed nil
1261   "List of ranges of articles that have been through the scoring process.")
1262
1263 (defvar gnus-newsgroup-cached nil
1264   "Sorted list of articles that come from the article cache.")
1265
1266 (defvar gnus-newsgroup-saved nil
1267   "List of articles that have been saved.")
1268
1269 (defvar gnus-newsgroup-kill-headers nil)
1270
1271 (defvar gnus-newsgroup-replied nil
1272   "List of articles that have been replied to in the current newsgroup.")
1273
1274 (defvar gnus-newsgroup-forwarded nil
1275   "List of articles that have been forwarded in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-recent nil
1278   "List of articles that have are recent in the current newsgroup.")
1279
1280 (defvar gnus-newsgroup-expirable nil
1281   "Sorted list of articles in the current newsgroup that can be expired.")
1282
1283 (defvar gnus-newsgroup-processable nil
1284   "List of articles in the current newsgroup that can be processed.")
1285
1286 (defvar gnus-newsgroup-downloadable nil
1287   "Sorted list of articles in the current newsgroup that can be processed.")
1288
1289 (defvar gnus-newsgroup-undownloaded nil
1290   "List of articles in the current newsgroup that haven't been downloaded..")
1291
1292 (defvar gnus-newsgroup-unsendable nil
1293   "List of articles in the current newsgroup that won't be sent.")
1294
1295 (defvar gnus-newsgroup-bookmarks nil
1296   "List of articles in the current newsgroup that have bookmarks.")
1297
1298 (defvar gnus-newsgroup-dormant nil
1299   "Sorted list of dormant articles in the current newsgroup.")
1300
1301 (defvar gnus-newsgroup-unseen nil
1302   "List of unseen articles in the current newsgroup.")
1303
1304 (defvar gnus-newsgroup-seen nil
1305   "Range of seen articles in the current newsgroup.")
1306
1307 (defvar gnus-newsgroup-articles nil
1308   "List of articles in the current newsgroup.")
1309
1310 (defvar gnus-newsgroup-scored nil
1311   "List of scored articles in the current newsgroup.")
1312
1313 (defvar gnus-newsgroup-incorporated nil
1314   "List of incorporated articles in the current newsgroup.")
1315
1316 (defvar gnus-newsgroup-headers nil
1317   "List of article headers in the current newsgroup.")
1318
1319 (defvar gnus-newsgroup-threads nil)
1320
1321 (defvar gnus-newsgroup-prepared nil
1322   "Whether the current group has been prepared properly.")
1323
1324 (defvar gnus-newsgroup-ancient nil
1325   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1326
1327 (defvar gnus-newsgroup-sparse nil)
1328
1329 (defvar gnus-current-article nil)
1330 (defvar gnus-article-current nil)
1331 (defvar gnus-current-headers nil)
1332 (defvar gnus-have-all-headers nil)
1333 (defvar gnus-last-article nil)
1334 (defvar gnus-newsgroup-history nil)
1335 (defvar gnus-newsgroup-charset nil)
1336 (defvar gnus-newsgroup-ephemeral-charset nil)
1337 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1338
1339 (defvar gnus-article-before-search nil)
1340
1341 (defconst gnus-summary-local-variables
1342   '(gnus-newsgroup-name
1343     gnus-newsgroup-begin gnus-newsgroup-end
1344     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1345     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1346     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1347     gnus-newsgroup-unselected gnus-newsgroup-marked
1348     gnus-newsgroup-spam-marked
1349     gnus-newsgroup-reads gnus-newsgroup-saved
1350     gnus-newsgroup-replied gnus-newsgroup-forwarded
1351     gnus-newsgroup-recent
1352     gnus-newsgroup-expirable
1353     gnus-newsgroup-processable gnus-newsgroup-killed
1354     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1355     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1356     gnus-newsgroup-seen gnus-newsgroup-articles
1357     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1358     gnus-newsgroup-headers gnus-newsgroup-threads
1359     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1360     gnus-current-article gnus-current-headers gnus-have-all-headers
1361     gnus-last-article gnus-article-internal-prepare-hook
1362     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1363     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1364     gnus-thread-expunge-below
1365     gnus-score-alist gnus-current-score-file
1366     (gnus-summary-expunge-below . global)
1367     (gnus-summary-mark-below . global)
1368     (gnus-orphan-score . global)
1369     gnus-newsgroup-active gnus-scores-exclude-files
1370     gnus-newsgroup-history gnus-newsgroup-ancient
1371     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1372     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1373     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1374     (gnus-newsgroup-expunged-tally . 0)
1375     gnus-cache-removable-articles gnus-newsgroup-cached
1376     gnus-newsgroup-data gnus-newsgroup-data-reverse
1377     gnus-newsgroup-limit gnus-newsgroup-limits
1378     gnus-newsgroup-charset gnus-newsgroup-display
1379     gnus-newsgroup-incorporated)
1380   "Variables that are buffer-local to the summary buffers.")
1381
1382 (defvar gnus-newsgroup-variables nil
1383   "A list of variables that have separate values in different newsgroups.
1384 A list of newsgroup (summary buffer) local variables, or cons of
1385 variables and their default values (when the default values are not
1386 nil), that should be made global while the summary buffer is active.
1387 These variables can be used to set variables in the group parameters
1388 while still allowing them to affect operations done in other
1389 buffers. For example:
1390
1391 \(setq gnus-newsgroup-variables
1392      '(message-use-followup-to
1393        (gnus-visible-headers .
1394          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1395 ")
1396
1397 ;; Byte-compiler warning.
1398 ;(eval-when-compile (defvar gnus-article-mode-map))
1399 (eval-when-compile
1400   (let ((features (cons 'gnus-sum features)))
1401     (require 'gnus)
1402     (require 'gnus-agent)
1403     (require 'gnus-art)))
1404
1405 ;; Subject simplification.
1406
1407 (defun gnus-simplify-whitespace (str)
1408   "Remove excessive whitespace from STR."
1409   (let ((mystr str))
1410     ;; Multiple spaces.
1411     (while (string-match "[ \t][ \t]+" mystr)
1412       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1413                           " "
1414                           (substring mystr (match-end 0)))))
1415     ;; Leading spaces.
1416     (when (string-match "^[ \t]+" mystr)
1417       (setq mystr (substring mystr (match-end 0))))
1418     ;; Trailing spaces.
1419     (when (string-match "[ \t]+$" mystr)
1420       (setq mystr (substring mystr 0 (match-beginning 0))))
1421     mystr))
1422
1423 (defun gnus-simplify-all-whitespace (str)
1424   "Remove all whitespace from STR."
1425   (let ((mystr str))
1426     (while (string-match "[ \t\n]+" mystr)
1427       (setq mystr (replace-match "" nil nil mystr)))
1428     mystr))
1429
1430 (defsubst gnus-simplify-subject-re (subject)
1431   "Remove \"Re:\" from subject lines."
1432   (if (string-match message-subject-re-regexp subject)
1433       (substring subject (match-end 0))
1434     subject))
1435
1436 (defun gnus-simplify-subject (subject &optional re-only)
1437   "Remove `Re:' and words in parentheses.
1438 If RE-ONLY is non-nil, strip leading `Re:'s only."
1439   (let ((case-fold-search t))           ;Ignore case.
1440     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1441     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1442       (setq subject (substring subject (match-end 0))))
1443     ;; Remove uninteresting prefixes.
1444     (when (and (not re-only)
1445                gnus-simplify-ignored-prefixes
1446                (string-match gnus-simplify-ignored-prefixes subject))
1447       (setq subject (substring subject (match-end 0))))
1448     ;; Remove words in parentheses from end.
1449     (unless re-only
1450       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1451         (setq subject (substring subject 0 (match-beginning 0)))))
1452     ;; Return subject string.
1453     subject))
1454
1455 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1456 ;; all whitespace.
1457 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1458   (goto-char (point-min))
1459   (while (re-search-forward regexp nil t)
1460     (replace-match (or newtext ""))))
1461
1462 (defun gnus-simplify-buffer-fuzzy ()
1463   "Simplify string in the buffer fuzzily.
1464 The string in the accessible portion of the current buffer is simplified.
1465 It is assumed to be a single-line subject.
1466 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1467 matter is removed.  Additional things can be deleted by setting
1468 `gnus-simplify-subject-fuzzy-regexp'."
1469   (let ((case-fold-search t)
1470         (modified-tick))
1471     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1472
1473     (while (not (eq modified-tick (buffer-modified-tick)))
1474       (setq modified-tick (buffer-modified-tick))
1475       (cond
1476        ((listp gnus-simplify-subject-fuzzy-regexp)
1477         (mapcar 'gnus-simplify-buffer-fuzzy-step
1478                 gnus-simplify-subject-fuzzy-regexp))
1479        (gnus-simplify-subject-fuzzy-regexp
1480         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1481       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1482       (gnus-simplify-buffer-fuzzy-step
1483        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1484       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1485
1486     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1487     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1488     (gnus-simplify-buffer-fuzzy-step " $")
1489     (gnus-simplify-buffer-fuzzy-step "^ +")))
1490
1491 (defun gnus-simplify-subject-fuzzy (subject)
1492   "Simplify a subject string fuzzily.
1493 See `gnus-simplify-buffer-fuzzy' for details."
1494   (save-excursion
1495     (gnus-set-work-buffer)
1496     (let ((case-fold-search t))
1497       ;; Remove uninteresting prefixes.
1498       (when (and gnus-simplify-ignored-prefixes
1499                  (string-match gnus-simplify-ignored-prefixes subject))
1500         (setq subject (substring subject (match-end 0))))
1501       (insert subject)
1502       (inline (gnus-simplify-buffer-fuzzy))
1503       (buffer-string))))
1504
1505 (defsubst gnus-simplify-subject-fully (subject)
1506   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1507   (cond
1508    (gnus-simplify-subject-functions
1509     (gnus-map-function gnus-simplify-subject-functions subject))
1510    ((null gnus-summary-gather-subject-limit)
1511     (gnus-simplify-subject-re subject))
1512    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1513     (gnus-simplify-subject-fuzzy subject))
1514    ((numberp gnus-summary-gather-subject-limit)
1515     (gnus-limit-string (gnus-simplify-subject-re subject)
1516                        gnus-summary-gather-subject-limit))
1517    (t
1518     subject)))
1519
1520 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1521   "Check whether two subjects are equal.
1522 If optional argument simple-first is t, first argument is already
1523 simplified."
1524   (cond
1525    ((null simple-first)
1526     (equal (gnus-simplify-subject-fully s1)
1527            (gnus-simplify-subject-fully s2)))
1528    (t
1529     (equal s1
1530            (gnus-simplify-subject-fully s2)))))
1531
1532 (defun gnus-summary-bubble-group ()
1533   "Increase the score of the current group.
1534 This is a handy function to add to `gnus-summary-exit-hook' to
1535 increase the score of each group you read."
1536   (gnus-group-add-score gnus-newsgroup-name))
1537
1538 \f
1539 ;;;
1540 ;;; Gnus summary mode
1541 ;;;
1542
1543 (put 'gnus-summary-mode 'mode-class 'special)
1544
1545 (defvar gnus-article-commands-menu)
1546
1547 ;; Non-orthogonal keys
1548
1549 (gnus-define-keys gnus-summary-mode-map
1550   " " gnus-summary-next-page
1551   "\177" gnus-summary-prev-page
1552   [delete] gnus-summary-prev-page
1553   [backspace] gnus-summary-prev-page
1554   "\r" gnus-summary-scroll-up
1555   "\M-\r" gnus-summary-scroll-down
1556   "n" gnus-summary-next-unread-article
1557   "p" gnus-summary-prev-unread-article
1558   "N" gnus-summary-next-article
1559   "P" gnus-summary-prev-article
1560   "\M-\C-n" gnus-summary-next-same-subject
1561   "\M-\C-p" gnus-summary-prev-same-subject
1562   "\M-n" gnus-summary-next-unread-subject
1563   "\M-p" gnus-summary-prev-unread-subject
1564   "." gnus-summary-first-unread-article
1565   "," gnus-summary-best-unread-article
1566   "\M-s" gnus-summary-search-article-forward
1567   "\M-r" gnus-summary-search-article-backward
1568   "<" gnus-summary-beginning-of-article
1569   ">" gnus-summary-end-of-article
1570   "j" gnus-summary-goto-article
1571   "^" gnus-summary-refer-parent-article
1572   "\M-^" gnus-summary-refer-article
1573   "u" gnus-summary-tick-article-forward
1574   "!" gnus-summary-tick-article-forward
1575   "U" gnus-summary-tick-article-backward
1576   "d" gnus-summary-mark-as-read-forward
1577   "D" gnus-summary-mark-as-read-backward
1578   "E" gnus-summary-mark-as-expirable
1579   "\M-u" gnus-summary-clear-mark-forward
1580   "\M-U" gnus-summary-clear-mark-backward
1581   "k" gnus-summary-kill-same-subject-and-select
1582   "\C-k" gnus-summary-kill-same-subject
1583   "\M-\C-k" gnus-summary-kill-thread
1584   "\M-\C-l" gnus-summary-lower-thread
1585   "e" gnus-summary-edit-article
1586   "#" gnus-summary-mark-as-processable
1587   "\M-#" gnus-summary-unmark-as-processable
1588   "\M-\C-t" gnus-summary-toggle-threads
1589   "\M-\C-s" gnus-summary-show-thread
1590   "\M-\C-h" gnus-summary-hide-thread
1591   "\M-\C-f" gnus-summary-next-thread
1592   "\M-\C-b" gnus-summary-prev-thread
1593   [(meta down)] gnus-summary-next-thread
1594   [(meta up)] gnus-summary-prev-thread
1595   "\M-\C-u" gnus-summary-up-thread
1596   "\M-\C-d" gnus-summary-down-thread
1597   "&" gnus-summary-execute-command
1598   "c" gnus-summary-catchup-and-exit
1599   "\C-w" gnus-summary-mark-region-as-read
1600   "\C-t" gnus-summary-toggle-truncation
1601   "?" gnus-summary-mark-as-dormant
1602   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1603   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1604   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1605   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1606   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1607   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1608   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1609   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1610   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1611   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1612   "=" gnus-summary-expand-window
1613   "\C-x\C-s" gnus-summary-reselect-current-group
1614   "\M-g" gnus-summary-rescan-group
1615   "w" gnus-summary-stop-page-breaking
1616   "\C-c\C-r" gnus-summary-caesar-message
1617   "\M-t" gnus-summary-toggle-mime
1618   "f" gnus-summary-followup
1619   "F" gnus-summary-followup-with-original
1620   "C" gnus-summary-cancel-article
1621   "r" gnus-summary-reply
1622   "R" gnus-summary-reply-with-original
1623   "\C-c\C-f" gnus-summary-mail-forward
1624   "o" gnus-summary-save-article
1625   "\C-o" gnus-summary-save-article-mail
1626   "|" gnus-summary-pipe-output
1627   "\M-k" gnus-summary-edit-local-kill
1628   "\M-K" gnus-summary-edit-global-kill
1629   ;; "V" gnus-version
1630   "\C-c\C-d" gnus-summary-describe-group
1631   "q" gnus-summary-exit
1632   "Q" gnus-summary-exit-no-update
1633   "\C-c\C-i" gnus-info-find-node
1634   gnus-mouse-2 gnus-mouse-pick-article
1635   "m" gnus-summary-mail-other-window
1636   "a" gnus-summary-post-news
1637   "i" gnus-summary-news-other-window
1638   "x" gnus-summary-limit-to-unread
1639   "s" gnus-summary-isearch-article
1640   "t" gnus-summary-toggle-header
1641   "g" gnus-summary-show-article
1642   "l" gnus-summary-goto-last-article
1643   "v" gnus-summary-preview-mime-message
1644   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1645   "\C-d" gnus-summary-enter-digest-group
1646   "\M-\C-d" gnus-summary-read-document
1647   "\M-\C-e" gnus-summary-edit-parameters
1648   "\M-\C-a" gnus-summary-customize-parameters
1649   "\C-c\C-b" gnus-bug
1650   "\C-c\C-n" gnus-namazu-search
1651   "*" gnus-cache-enter-article
1652   "\M-*" gnus-cache-remove-article
1653   "\M-&" gnus-summary-universal-argument
1654   "\C-l" gnus-recenter
1655   "I" gnus-summary-increase-score
1656   "L" gnus-summary-lower-score
1657   "\M-i" gnus-symbolic-argument
1658   "h" gnus-summary-select-article-buffer
1659
1660   "V" gnus-summary-score-map
1661   "X" gnus-uu-extract-map
1662   "S" gnus-summary-send-map)
1663
1664   ;; Sort of orthogonal keymap
1665 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1666   "t" gnus-summary-tick-article-forward
1667   "!" gnus-summary-tick-article-forward
1668   "d" gnus-summary-mark-as-read-forward
1669   "r" gnus-summary-mark-as-read-forward
1670   "c" gnus-summary-clear-mark-forward
1671   " " gnus-summary-clear-mark-forward
1672   "e" gnus-summary-mark-as-expirable
1673   "x" gnus-summary-mark-as-expirable
1674   "?" gnus-summary-mark-as-dormant
1675   "b" gnus-summary-set-bookmark
1676   "B" gnus-summary-remove-bookmark
1677   "#" gnus-summary-mark-as-processable
1678   "\M-#" gnus-summary-unmark-as-processable
1679   "S" gnus-summary-limit-include-expunged
1680   "C" gnus-summary-catchup
1681   "H" gnus-summary-catchup-to-here
1682   "h" gnus-summary-catchup-from-here
1683   "\C-c" gnus-summary-catchup-all
1684   "k" gnus-summary-kill-same-subject-and-select
1685   "K" gnus-summary-kill-same-subject
1686   "P" gnus-uu-mark-map)
1687
1688 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1689   "c" gnus-summary-clear-above
1690   "u" gnus-summary-tick-above
1691   "m" gnus-summary-mark-above
1692   "k" gnus-summary-kill-below)
1693
1694 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1695   "/" gnus-summary-limit-to-subject
1696   "n" gnus-summary-limit-to-articles
1697   "w" gnus-summary-pop-limit
1698   "s" gnus-summary-limit-to-subject
1699   "a" gnus-summary-limit-to-author
1700   "u" gnus-summary-limit-to-unread
1701   "m" gnus-summary-limit-to-marks
1702   "M" gnus-summary-limit-exclude-marks
1703   "v" gnus-summary-limit-to-score
1704   "*" gnus-summary-limit-include-cached
1705   "D" gnus-summary-limit-include-dormant
1706   "T" gnus-summary-limit-include-thread
1707   "d" gnus-summary-limit-exclude-dormant
1708   "t" gnus-summary-limit-to-age
1709   "." gnus-summary-limit-to-unseen
1710   "x" gnus-summary-limit-to-extra
1711   "p" gnus-summary-limit-to-display-predicate
1712   "E" gnus-summary-limit-include-expunged
1713   "c" gnus-summary-limit-exclude-childless-dormant
1714   "C" gnus-summary-limit-mark-excluded-as-read
1715   "o" gnus-summary-insert-old-articles
1716   "N" gnus-summary-insert-new-articles)
1717
1718 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1719   "n" gnus-summary-next-unread-article
1720   "p" gnus-summary-prev-unread-article
1721   "N" gnus-summary-next-article
1722   "P" gnus-summary-prev-article
1723   "\C-n" gnus-summary-next-same-subject
1724   "\C-p" gnus-summary-prev-same-subject
1725   "\M-n" gnus-summary-next-unread-subject
1726   "\M-p" gnus-summary-prev-unread-subject
1727   "f" gnus-summary-first-unread-article
1728   "b" gnus-summary-best-unread-article
1729   "j" gnus-summary-goto-article
1730   "g" gnus-summary-goto-subject
1731   "l" gnus-summary-goto-last-article
1732   "o" gnus-summary-pop-article)
1733
1734 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1735   "k" gnus-summary-kill-thread
1736   "l" gnus-summary-lower-thread
1737   "i" gnus-summary-raise-thread
1738   "T" gnus-summary-toggle-threads
1739   "t" gnus-summary-rethread-current
1740   "^" gnus-summary-reparent-thread
1741   "s" gnus-summary-show-thread
1742   "S" gnus-summary-show-all-threads
1743   "h" gnus-summary-hide-thread
1744   "H" gnus-summary-hide-all-threads
1745   "n" gnus-summary-next-thread
1746   "p" gnus-summary-prev-thread
1747   "u" gnus-summary-up-thread
1748   "o" gnus-summary-top-thread
1749   "d" gnus-summary-down-thread
1750   "#" gnus-uu-mark-thread
1751   "\M-#" gnus-uu-unmark-thread)
1752
1753 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1754   "g" gnus-summary-prepare
1755   "c" gnus-summary-insert-cached-articles
1756   "d" gnus-summary-insert-dormant-articles)
1757
1758 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1759   "c" gnus-summary-catchup-and-exit
1760   "C" gnus-summary-catchup-all-and-exit
1761   "E" gnus-summary-exit-no-update
1762   "J" gnus-summary-jump-to-other-group
1763   "Q" gnus-summary-exit
1764   "Z" gnus-summary-exit
1765   "n" gnus-summary-catchup-and-goto-next-group
1766   "R" gnus-summary-reselect-current-group
1767   "G" gnus-summary-rescan-group
1768   "N" gnus-summary-next-group
1769   "s" gnus-summary-save-newsrc
1770   "P" gnus-summary-prev-group)
1771
1772 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1773   " " gnus-summary-next-page
1774   "n" gnus-summary-next-page
1775   "\177" gnus-summary-prev-page
1776   [delete] gnus-summary-prev-page
1777   "p" gnus-summary-prev-page
1778   "\r" gnus-summary-scroll-up
1779   "\M-\r" gnus-summary-scroll-down
1780   "<" gnus-summary-beginning-of-article
1781   ">" gnus-summary-end-of-article
1782   "b" gnus-summary-beginning-of-article
1783   "e" gnus-summary-end-of-article
1784   "^" gnus-summary-refer-parent-article
1785   "r" gnus-summary-refer-parent-article
1786   "D" gnus-summary-enter-digest-group
1787   "R" gnus-summary-refer-references
1788   "T" gnus-summary-refer-thread
1789   "g" gnus-summary-show-article
1790   "s" gnus-summary-isearch-article
1791   "P" gnus-summary-print-article
1792   "M" gnus-mailing-list-insinuate
1793   "t" gnus-article-babel)
1794
1795 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1796   "b" gnus-article-add-buttons
1797   "B" gnus-article-add-buttons-to-head
1798   "o" gnus-article-treat-overstrike
1799   "e" gnus-article-emphasize
1800   "w" gnus-article-fill-cited-article
1801   "Q" gnus-article-fill-long-lines
1802   "C" gnus-article-capitalize-sentences
1803   "c" gnus-article-remove-cr
1804   "Z" gnus-article-decode-HZ
1805   "h" gnus-article-wash-html
1806   "u" gnus-article-unsplit-urls
1807   "f" gnus-article-display-x-face
1808   "l" gnus-summary-stop-page-breaking
1809   "r" gnus-summary-caesar-message
1810   "m" gnus-summary-morse-message
1811   "t" gnus-summary-toggle-header
1812   "g" gnus-treat-smiley
1813   "v" gnus-summary-verbose-headers
1814   "m" gnus-summary-toggle-mime
1815   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1816   "p" gnus-article-verify-x-pgp-sig
1817   "d" gnus-article-treat-dumbquotes)
1818
1819 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1820   ;; mnemonic: deuglif*Y*
1821   "u" gnus-article-outlook-unwrap-lines
1822   "a" gnus-article-outlook-repair-attribution
1823   "c" gnus-article-outlook-rearrange-citation
1824   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1825
1826 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1827   "a" gnus-article-hide
1828   "h" gnus-article-hide-headers
1829   "b" gnus-article-hide-boring-headers
1830   "s" gnus-article-hide-signature
1831   "c" gnus-article-hide-citation
1832   "C" gnus-article-hide-citation-in-followups
1833   "l" gnus-article-hide-list-identifiers
1834   "p" gnus-article-hide-pgp
1835   "B" gnus-article-strip-banner
1836   "P" gnus-article-hide-pem
1837   "\C-c" gnus-article-hide-citation-maybe)
1838
1839 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1840   "a" gnus-article-highlight
1841   "h" gnus-article-highlight-headers
1842   "c" gnus-article-highlight-citation
1843   "s" gnus-article-highlight-signature)
1844
1845 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1846   "f" gnus-article-treat-fold-headers
1847   "u" gnus-article-treat-unfold-headers
1848   "n" gnus-article-treat-fold-newsgroups)
1849
1850 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1851   "x" gnus-article-display-x-face
1852   "d" gnus-article-display-face
1853   "s" gnus-treat-smiley
1854   "D" gnus-article-remove-images
1855   "f" gnus-treat-from-picon
1856   "m" gnus-treat-mail-picon
1857   "n" gnus-treat-newsgroups-picon)
1858
1859 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1860   "z" gnus-article-date-ut
1861   "u" gnus-article-date-ut
1862   "l" gnus-article-date-local
1863   "p" gnus-article-date-english
1864   "e" gnus-article-date-lapsed
1865   "o" gnus-article-date-original
1866   "i" gnus-article-date-iso8601
1867   "s" gnus-article-date-user)
1868
1869 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1870   "t" gnus-article-remove-trailing-blank-lines
1871   "l" gnus-article-strip-leading-blank-lines
1872   "m" gnus-article-strip-multiple-blank-lines
1873   "a" gnus-article-strip-blank-lines
1874   "A" gnus-article-strip-all-blank-lines
1875   "s" gnus-article-strip-leading-space
1876   "e" gnus-article-strip-trailing-space
1877   "w" gnus-article-remove-leading-whitespace)
1878
1879 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1880   "v" gnus-version
1881   "f" gnus-summary-fetch-faq
1882   "d" gnus-summary-describe-group
1883   "h" gnus-summary-describe-briefly
1884   "i" gnus-info-find-node
1885   "c" gnus-group-fetch-charter
1886   "C" gnus-group-fetch-control)
1887
1888 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1889   "e" gnus-summary-expire-articles
1890   "\M-\C-e" gnus-summary-expire-articles-now
1891   "\177" gnus-summary-delete-article
1892   [delete] gnus-summary-delete-article
1893   [backspace] gnus-summary-delete-article
1894   "m" gnus-summary-move-article
1895   "r" gnus-summary-respool-article
1896   "w" gnus-summary-edit-article
1897   "c" gnus-summary-copy-article
1898   "B" gnus-summary-crosspost-article
1899   "q" gnus-summary-respool-query
1900   "t" gnus-summary-respool-trace
1901   "i" gnus-summary-import-article
1902   "I" gnus-summary-create-article
1903   "p" gnus-summary-article-posted-p)
1904
1905 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1906   "o" gnus-summary-save-article
1907   "m" gnus-summary-save-article-mail
1908   "F" gnus-summary-write-article-file
1909   "r" gnus-summary-save-article-rmail
1910   "f" gnus-summary-save-article-file
1911   "b" gnus-summary-save-article-body-file
1912   "h" gnus-summary-save-article-folder
1913   "v" gnus-summary-save-article-vm
1914   "p" gnus-summary-pipe-output
1915   "P" gnus-summary-muttprint
1916   "s" gnus-soup-add-article)
1917
1918 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1919   "b" gnus-summary-display-buttonized
1920   "m" gnus-summary-repair-multipart
1921   "v" gnus-article-view-part
1922   "o" gnus-article-save-part
1923   "c" gnus-article-copy-part
1924   "C" gnus-article-view-part-as-charset
1925   "e" gnus-article-view-part-externally
1926   "E" gnus-article-encrypt-body
1927   "i" gnus-article-inline-part
1928   "|" gnus-article-pipe-part)
1929
1930 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1931   "p" gnus-summary-mark-as-processable
1932   "u" gnus-summary-unmark-as-processable
1933   "U" gnus-summary-unmark-all-processable
1934   "v" gnus-uu-mark-over
1935   "s" gnus-uu-mark-series
1936   "r" gnus-uu-mark-region
1937   "g" gnus-uu-unmark-region
1938   "R" gnus-uu-mark-by-regexp
1939   "G" gnus-uu-unmark-by-regexp
1940   "t" gnus-uu-mark-thread
1941   "T" gnus-uu-unmark-thread
1942   "a" gnus-uu-mark-all
1943   "b" gnus-uu-mark-buffer
1944   "S" gnus-uu-mark-sparse
1945   "k" gnus-summary-kill-process-mark
1946   "y" gnus-summary-yank-process-mark
1947   "w" gnus-summary-save-process-mark
1948   "i" gnus-uu-invert-processable)
1949
1950 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1951   ;;"x" gnus-uu-extract-any
1952   "m" gnus-summary-save-parts
1953   "u" gnus-uu-decode-uu
1954   "U" gnus-uu-decode-uu-and-save
1955   "s" gnus-uu-decode-unshar
1956   "S" gnus-uu-decode-unshar-and-save
1957   "o" gnus-uu-decode-save
1958   "O" gnus-uu-decode-save
1959   "b" gnus-uu-decode-binhex
1960   "B" gnus-uu-decode-binhex
1961   "p" gnus-uu-decode-postscript
1962   "P" gnus-uu-decode-postscript-and-save)
1963
1964 (gnus-define-keys
1965     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1966   "u" gnus-uu-decode-uu-view
1967   "U" gnus-uu-decode-uu-and-save-view
1968   "s" gnus-uu-decode-unshar-view
1969   "S" gnus-uu-decode-unshar-and-save-view
1970   "o" gnus-uu-decode-save-view
1971   "O" gnus-uu-decode-save-view
1972   "b" gnus-uu-decode-binhex-view
1973   "B" gnus-uu-decode-binhex-view
1974   "p" gnus-uu-decode-postscript-view
1975   "P" gnus-uu-decode-postscript-and-save-view)
1976
1977 (defvar gnus-article-post-menu nil)
1978
1979 (defconst gnus-summary-menu-maxlen 20)
1980
1981 (defun gnus-summary-menu-split (menu)
1982   ;; If we have lots of elements, divide them into groups of 20
1983   ;; and make a pane (or submenu) for each one.
1984   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
1985       (let ((menu menu) sublists next
1986             (i 1))
1987         (while menu
1988           ;; Pull off the next gnus-summary-menu-maxlen elements
1989           ;; and make them the next element of sublist.
1990           (setq next (nthcdr gnus-summary-menu-maxlen menu))
1991           (if next
1992               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
1993                       nil))
1994           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
1995                                              (aref (car (last menu)) 0)) menu)
1996                                sublists))
1997           (setq i (1+ i))
1998           (setq menu next))
1999         (nreverse sublists))
2000     ;; Few elements--put them all in one pane.
2001     menu))
2002
2003 (defun gnus-summary-make-menu-bar ()
2004   (gnus-turn-off-edit-menu 'summary)
2005
2006   (unless (boundp 'gnus-summary-misc-menu)
2007
2008     (easy-menu-define
2009      gnus-summary-kill-menu gnus-summary-mode-map ""
2010      (cons
2011       "Score"
2012       (nconc
2013        (list
2014         ["Customize" gnus-score-customize t])
2015        (gnus-make-score-map 'increase)
2016        (gnus-make-score-map 'lower)
2017        '(("Mark"
2018           ["Kill below" gnus-summary-kill-below t]
2019           ["Mark above" gnus-summary-mark-above t]
2020           ["Tick above" gnus-summary-tick-above t]
2021           ["Clear above" gnus-summary-clear-above t])
2022          ["Current score" gnus-summary-current-score t]
2023          ["Set score" gnus-summary-set-score t]
2024          ["Switch current score file..." gnus-score-change-score-file t]
2025          ["Set mark below..." gnus-score-set-mark-below t]
2026          ["Set expunge below..." gnus-score-set-expunge-below t]
2027          ["Edit current score file" gnus-score-edit-current-scores t]
2028          ["Edit score file" gnus-score-edit-file t]
2029          ["Trace score" gnus-score-find-trace t]
2030          ["Find words" gnus-score-find-favourite-words t]
2031          ["Rescore buffer" gnus-summary-rescore t]
2032          ["Increase score..." gnus-summary-increase-score t]
2033          ["Lower score..." gnus-summary-lower-score t]))))
2034
2035     ;; Define both the Article menu in the summary buffer and the
2036     ;; equivalent Commands menu in the article buffer here for
2037     ;; consistency.
2038     (let ((innards
2039            `(("Hide"
2040               ["All" gnus-article-hide t]
2041               ["Headers" gnus-article-hide-headers t]
2042               ["Signature" gnus-article-hide-signature t]
2043               ["Citation" gnus-article-hide-citation t]
2044               ["List identifiers" gnus-article-hide-list-identifiers t]
2045               ["PGP" gnus-article-hide-pgp t]
2046               ["Banner" gnus-article-strip-banner t]
2047               ["Boring headers" gnus-article-hide-boring-headers t])
2048              ("Highlight"
2049               ["All" gnus-article-highlight t]
2050               ["Headers" gnus-article-highlight-headers t]
2051               ["Signature" gnus-article-highlight-signature t]
2052               ["Citation" gnus-article-highlight-citation t])
2053              ("Date"
2054               ["Local" gnus-article-date-local t]
2055               ["ISO8601" gnus-article-date-iso8601 t]
2056               ["UT" gnus-article-date-ut t]
2057               ["Original" gnus-article-date-original t]
2058               ["Lapsed" gnus-article-date-lapsed t]
2059               ["User-defined" gnus-article-date-user t])
2060              ("Display"
2061               ["Remove images" gnus-article-remove-images t]
2062               ["Toggle smiley" gnus-treat-smiley t]
2063               ["Show X-Face" gnus-article-display-x-face t]
2064               ["Show picons in From" gnus-treat-from-picon t]
2065               ["Show picons in mail headers" gnus-treat-mail-picon t]
2066               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2067               ("View as different encoding"
2068                ,@(gnus-summary-menu-split
2069                   (mapcar
2070                    (lambda (cs)
2071                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2072                      ;; forms for menu commands, we should provide intern'ed
2073                      ;; function symbols.
2074                      (let ((command (intern (format "\
2075 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2076                        (fset command
2077                              `(lambda ()
2078                                 (interactive)
2079                                 (let ((gnus-summary-show-article-charset-alist
2080                                        '((1 . ,cs))))
2081                                   (gnus-summary-show-article 1))))
2082                        `[,(symbol-name cs) ,command t]))
2083                    (sort (if (fboundp 'coding-system-list)
2084                              (coding-system-list)
2085                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2086                            )
2087                          'string<)))))
2088              ("Washing"
2089               ("Remove Blanks"
2090                ["Leading" gnus-article-strip-leading-blank-lines t]
2091                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2092                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2093                ["All of the above" gnus-article-strip-blank-lines t]
2094                ["All" gnus-article-strip-all-blank-lines t]
2095                ["Leading space" gnus-article-strip-leading-space t]
2096                ["Trailing space" gnus-article-strip-trailing-space t]
2097                ["Leading space in headers"
2098                 gnus-article-remove-leading-whitespace t])
2099               ["Overstrike" gnus-article-treat-overstrike t]
2100               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2101               ["Emphasis" gnus-article-emphasize t]
2102               ["Word wrap" gnus-article-fill-cited-article t]
2103               ["Fill long lines" gnus-article-fill-long-lines t]
2104               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2105               ["CR" gnus-article-remove-cr t]
2106               ["Rot 13" gnus-summary-caesar-message
2107                ,@(if (featurep 'xemacs) '(t)
2108                    '(:help "\"Caesar rotate\" article by 13"))]
2109               ["Morse decode" gnus-summary-morse-message t]
2110               ["Unix pipe..." gnus-summary-pipe-message t]
2111               ["Add buttons" gnus-article-add-buttons t]
2112               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2113               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2114               ["Toggle MIME" gnus-summary-toggle-mime t]
2115               ["Verbose header" gnus-summary-verbose-headers t]
2116               ["Toggle header" gnus-summary-toggle-header t]
2117               ["Unfold headers" gnus-article-treat-unfold-headers t]
2118               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2119               ["Html" gnus-article-wash-html t]
2120               ["URLs" gnus-article-unsplit-urls t]
2121               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2122               ["HZ" gnus-article-decode-HZ t]
2123               ("(Outlook) Deuglify"
2124                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2125                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2126                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2127                ["Full (Outlook) deuglify"
2128                 gnus-article-outlook-deuglify-article t])
2129               )
2130              ("Output"
2131               ["Save in default format" gnus-summary-save-article
2132                ,@(if (featurep 'xemacs) '(t)
2133                    '(:help "Save article using default method"))]
2134               ["Save in file" gnus-summary-save-article-file
2135                ,@(if (featurep 'xemacs) '(t)
2136                    '(:help "Save article in file"))]
2137               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2138               ["Save in MH folder" gnus-summary-save-article-folder t]
2139               ["Save in VM folder" gnus-summary-save-article-vm t]
2140               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2141               ["Save body in file" gnus-summary-save-article-body-file t]
2142               ["Pipe through a filter" gnus-summary-pipe-output t]
2143               ["Add to SOUP packet" gnus-soup-add-article t]
2144               ["Print with Muttprint" gnus-summary-muttprint t]
2145               ["Print" gnus-summary-print-article t])
2146              ("Backend"
2147               ["Respool article..." gnus-summary-respool-article t]
2148               ["Move article..." gnus-summary-move-article
2149                (gnus-check-backend-function
2150                 'request-move-article gnus-newsgroup-name)]
2151               ["Copy article..." gnus-summary-copy-article t]
2152               ["Crosspost article..." gnus-summary-crosspost-article
2153                (gnus-check-backend-function
2154                 'request-replace-article gnus-newsgroup-name)]
2155               ["Import file..." gnus-summary-import-article t]
2156               ["Create article..." gnus-summary-create-article t]
2157               ["Check if posted" gnus-summary-article-posted-p t]
2158               ["Edit article" gnus-summary-edit-article
2159                (not (gnus-group-read-only-p))]
2160               ["Delete article" gnus-summary-delete-article
2161                (gnus-check-backend-function
2162                 'request-expire-articles gnus-newsgroup-name)]
2163               ["Query respool" gnus-summary-respool-query t]
2164               ["Trace respool" gnus-summary-respool-trace t]
2165               ["Delete expirable articles" gnus-summary-expire-articles-now
2166                (gnus-check-backend-function
2167                 'request-expire-articles gnus-newsgroup-name)])
2168              ("Extract"
2169               ["Uudecode" gnus-uu-decode-uu
2170                ,@(if (featurep 'xemacs) '(t)
2171                    '(:help "Decode uuencoded article(s)"))]
2172               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2173               ["Unshar" gnus-uu-decode-unshar t]
2174               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2175               ["Save" gnus-uu-decode-save t]
2176               ["Binhex" gnus-uu-decode-binhex t]
2177               ["Postscript" gnus-uu-decode-postscript t])
2178              ("Cache"
2179               ["Enter article" gnus-cache-enter-article t]
2180               ["Remove article" gnus-cache-remove-article t])
2181              ["Translate" gnus-article-babel t]
2182              ["Select article buffer" gnus-summary-select-article-buffer t]
2183              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2184              ["Isearch article..." gnus-summary-isearch-article t]
2185              ["Beginning of the article" gnus-summary-beginning-of-article t]
2186              ["End of the article" gnus-summary-end-of-article t]
2187              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2188              ["Fetch referenced articles" gnus-summary-refer-references t]
2189              ["Fetch current thread" gnus-summary-refer-thread t]
2190              ["Fetch article with id..." gnus-summary-refer-article t]
2191              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2192              ["Redisplay" gnus-summary-show-article t]
2193              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2194       (easy-menu-define
2195        gnus-summary-article-menu gnus-summary-mode-map ""
2196        (cons "Article" innards))
2197
2198       (if (not (keymapp gnus-summary-article-menu))
2199           (easy-menu-define
2200            gnus-article-commands-menu gnus-article-mode-map ""
2201            (cons "Commands" innards))
2202         ;; in Emacs, don't share menu.
2203         (setq gnus-article-commands-menu
2204               (copy-keymap gnus-summary-article-menu))
2205         (define-key gnus-article-mode-map [menu-bar commands]
2206           (cons "Commands" gnus-article-commands-menu))))
2207
2208     (easy-menu-define
2209      gnus-summary-thread-menu gnus-summary-mode-map ""
2210      '("Threads"
2211        ["Find all messages in thread" gnus-summary-refer-thread t]
2212        ["Toggle threading" gnus-summary-toggle-threads t]
2213        ["Hide threads" gnus-summary-hide-all-threads t]
2214        ["Show threads" gnus-summary-show-all-threads t]
2215        ["Hide thread" gnus-summary-hide-thread t]
2216        ["Show thread" gnus-summary-show-thread t]
2217        ["Go to next thread" gnus-summary-next-thread t]
2218        ["Go to previous thread" gnus-summary-prev-thread t]
2219        ["Go down thread" gnus-summary-down-thread t]
2220        ["Go up thread" gnus-summary-up-thread t]
2221        ["Top of thread" gnus-summary-top-thread t]
2222        ["Mark thread as read" gnus-summary-kill-thread t]
2223        ["Lower thread score" gnus-summary-lower-thread t]
2224        ["Raise thread score" gnus-summary-raise-thread t]
2225        ["Rethread current" gnus-summary-rethread-current t]))
2226
2227     (easy-menu-define
2228      gnus-summary-post-menu gnus-summary-mode-map ""
2229      `("Post"
2230        ["Send a message (mail or news)" gnus-summary-post-news
2231         ,@(if (featurep 'xemacs) '(t)
2232             '(:help "Post an article"))]
2233        ["Followup" gnus-summary-followup
2234         ,@(if (featurep 'xemacs) '(t)
2235             '(:help "Post followup to this article"))]
2236        ["Followup and yank" gnus-summary-followup-with-original
2237         ,@(if (featurep 'xemacs) '(t)
2238             '(:help "Post followup to this article, quoting its contents"))]
2239        ["Supersede article" gnus-summary-supersede-article t]
2240        ["Cancel article" gnus-summary-cancel-article
2241         ,@(if (featurep 'xemacs) '(t)
2242             '(:help "Cancel an article you posted"))]
2243        ["Reply" gnus-summary-reply t]
2244        ["Reply and yank" gnus-summary-reply-with-original t]
2245        ["Wide reply" gnus-summary-wide-reply t]
2246        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2247         ,@(if (featurep 'xemacs) '(t)
2248             '(:help "Mail a reply, quoting this article"))]
2249        ["Very wide reply" gnus-summary-very-wide-reply t]
2250        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2251         ,@(if (featurep 'xemacs) '(t)
2252             '(:help "Mail a very wide reply, quoting this article"))]
2253        ["Mail forward" gnus-summary-mail-forward t]
2254        ["Post forward" gnus-summary-post-forward t]
2255        ["Digest and mail" gnus-summary-digest-mail-forward t]
2256        ["Digest and post" gnus-summary-digest-post-forward t]
2257        ["Resend message" gnus-summary-resend-message t]
2258        ["Resend message edit" gnus-summary-resend-message-edit t]
2259        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2260        ["Send a mail" gnus-summary-mail-other-window t]
2261        ["Create a local message" gnus-summary-news-other-window t]
2262        ["Uuencode and post" gnus-uu-post-news
2263         ,@(if (featurep 'xemacs) '(t)
2264             '(:help "Post a uuencoded article"))]
2265        ["Followup via news" gnus-summary-followup-to-mail t]
2266        ["Followup via news and yank"
2267         gnus-summary-followup-to-mail-with-original t]
2268        ;;("Draft"
2269        ;;["Send" gnus-summary-send-draft t]
2270        ;;["Send bounced" gnus-resend-bounced-mail t])
2271        ))
2272
2273     (cond
2274      ((not (keymapp gnus-summary-post-menu))
2275       (setq gnus-article-post-menu gnus-summary-post-menu))
2276      ((not gnus-article-post-menu)
2277       ;; Don't share post menu.
2278       (setq gnus-article-post-menu
2279             (copy-keymap gnus-summary-post-menu))))
2280     (define-key gnus-article-mode-map [menu-bar post]
2281       (cons "Post" gnus-article-post-menu))
2282
2283     (easy-menu-define
2284      gnus-summary-misc-menu gnus-summary-mode-map ""
2285      `("Gnus"
2286        ("Mark Read"
2287         ["Mark as read" gnus-summary-mark-as-read-forward t]
2288         ["Mark same subject and select"
2289          gnus-summary-kill-same-subject-and-select t]
2290         ["Mark same subject" gnus-summary-kill-same-subject t]
2291         ["Catchup" gnus-summary-catchup
2292          ,@(if (featurep 'xemacs) '(t)
2293              '(:help "Mark unread articles in this group as read"))]
2294         ["Catchup all" gnus-summary-catchup-all t]
2295         ["Catchup to here" gnus-summary-catchup-to-here t]
2296         ["Catchup from here" gnus-summary-catchup-from-here t]
2297         ["Catchup region" gnus-summary-mark-region-as-read
2298          (gnus-mark-active-p)]
2299         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2300        ("Mark Various"
2301         ["Tick" gnus-summary-tick-article-forward t]
2302         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2303         ["Remove marks" gnus-summary-clear-mark-forward t]
2304         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2305         ["Set bookmark" gnus-summary-set-bookmark t]
2306         ["Remove bookmark" gnus-summary-remove-bookmark t])
2307        ("Limit to"
2308         ["Marks..." gnus-summary-limit-to-marks t]
2309         ["Subject..." gnus-summary-limit-to-subject t]
2310         ["Author..." gnus-summary-limit-to-author t]
2311         ["Age..." gnus-summary-limit-to-age t]
2312         ["Extra..." gnus-summary-limit-to-extra t]
2313         ["Score..." gnus-summary-limit-to-score t]
2314         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2315         ["Unread" gnus-summary-limit-to-unread t]
2316         ["Unseen" gnus-summary-limit-to-unseen t]
2317         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2318         ["Next articles" gnus-summary-limit-to-articles t]
2319         ["Pop limit" gnus-summary-pop-limit t]
2320         ["Show dormant" gnus-summary-limit-include-dormant t]
2321         ["Hide childless dormant"
2322          gnus-summary-limit-exclude-childless-dormant t]
2323         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2324         ["Hide marked" gnus-summary-limit-exclude-marks t]
2325         ["Show expunged" gnus-summary-limit-include-expunged t])
2326        ("Process Mark"
2327         ["Set mark" gnus-summary-mark-as-processable t]
2328         ["Remove mark" gnus-summary-unmark-as-processable t]
2329         ["Remove all marks" gnus-summary-unmark-all-processable t]
2330         ["Mark above" gnus-uu-mark-over t]
2331         ["Mark series" gnus-uu-mark-series t]
2332         ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2333         ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2334         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2335         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2336         ["Mark all" gnus-uu-mark-all t]
2337         ["Mark buffer" gnus-uu-mark-buffer t]
2338         ["Mark sparse" gnus-uu-mark-sparse t]
2339         ["Mark thread" gnus-uu-mark-thread t]
2340         ["Unmark thread" gnus-uu-unmark-thread t]
2341         ("Process Mark Sets"
2342          ["Kill" gnus-summary-kill-process-mark t]
2343          ["Yank" gnus-summary-yank-process-mark
2344           gnus-newsgroup-process-stack]
2345          ["Save" gnus-summary-save-process-mark t]))
2346        ("Scroll article"
2347         ["Page forward" gnus-summary-next-page
2348          ,@(if (featurep 'xemacs) '(t)
2349              '(:help "Show next page of article"))]
2350         ["Page backward" gnus-summary-prev-page
2351          ,@(if (featurep 'xemacs) '(t)
2352              '(:help "Show previous page of article"))]
2353         ["Line forward" gnus-summary-scroll-up t])
2354        ("Move"
2355         ["Next unread article" gnus-summary-next-unread-article t]
2356         ["Previous unread article" gnus-summary-prev-unread-article t]
2357         ["Next article" gnus-summary-next-article t]
2358         ["Previous article" gnus-summary-prev-article t]
2359         ["Next unread subject" gnus-summary-next-unread-subject t]
2360         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2361         ["Next article same subject" gnus-summary-next-same-subject t]
2362         ["Previous article same subject" gnus-summary-prev-same-subject t]
2363         ["First unread article" gnus-summary-first-unread-article t]
2364         ["Best unread article" gnus-summary-best-unread-article t]
2365         ["Go to subject number..." gnus-summary-goto-subject t]
2366         ["Go to article number..." gnus-summary-goto-article t]
2367         ["Go to the last article" gnus-summary-goto-last-article t]
2368         ["Pop article off history" gnus-summary-pop-article t])
2369        ("Sort"
2370         ["Sort by number" gnus-summary-sort-by-number t]
2371         ["Sort by author" gnus-summary-sort-by-author t]
2372         ["Sort by subject" gnus-summary-sort-by-subject t]
2373         ["Sort by date" gnus-summary-sort-by-date t]
2374         ["Sort by score" gnus-summary-sort-by-score t]
2375         ["Sort by lines" gnus-summary-sort-by-lines t]
2376         ["Sort by characters" gnus-summary-sort-by-chars t]
2377         ["Randomize" gnus-summary-sort-by-random t]
2378         ["Original sort" gnus-summary-sort-by-original t])
2379        ("Help"
2380         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2381         ["Describe group" gnus-summary-describe-group t]
2382         ["Fetch charter" gnus-group-fetch-charter
2383          ,@(if (featurep 'xemacs) nil
2384              '(:help "Display the charter of the current group"))]
2385         ["Fetch control message" gnus-group-fetch-control
2386          ,@(if (featurep 'xemacs) nil
2387              '(:help "Display the archived control message for the current group"))]
2388         ["Read manual" gnus-info-find-node t])
2389        ("Modes"
2390         ["Pick and read" gnus-pick-mode t]
2391         ["Binary" gnus-binary-mode t])
2392        ("Regeneration"
2393         ["Regenerate" gnus-summary-prepare t]
2394         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2395         ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2396         ["Toggle threading" gnus-summary-toggle-threads t])
2397        ["See old articles" gnus-summary-insert-old-articles t]
2398        ["See new articles" gnus-summary-insert-new-articles t]
2399        ["Filter articles..." gnus-summary-execute-command t]
2400        ["Run command on subjects..." gnus-summary-universal-argument t]
2401        ["Search articles forward..." gnus-summary-search-article-forward t]
2402        ["Search articles backward..." gnus-summary-search-article-backward t]
2403        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2404        ["Expand window" gnus-summary-expand-window t]
2405        ["Expire expirable articles" gnus-summary-expire-articles
2406         (gnus-check-backend-function
2407          'request-expire-articles gnus-newsgroup-name)]
2408        ["Edit local kill file" gnus-summary-edit-local-kill t]
2409        ["Edit main kill file" gnus-summary-edit-global-kill t]
2410        ["Edit group parameters" gnus-summary-edit-parameters t]
2411        ["Customize group parameters" gnus-summary-customize-parameters t]
2412        ["Send a bug report" gnus-bug t]
2413        ("Exit"
2414         ["Catchup and exit" gnus-summary-catchup-and-exit
2415          ,@(if (featurep 'xemacs) '(t)
2416              '(:help "Mark unread articles in this group as read, then exit"))]
2417         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2418         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2419         ["Exit group" gnus-summary-exit
2420          ,@(if (featurep 'xemacs) '(t)
2421              '(:help "Exit current group, return to group selection mode"))]
2422         ["Exit group without updating" gnus-summary-exit-no-update t]
2423         ["Exit and goto next group" gnus-summary-next-group t]
2424         ["Exit and goto prev group" gnus-summary-prev-group t]
2425         ["Reselect group" gnus-summary-reselect-current-group t]
2426         ["Rescan group" gnus-summary-rescan-group t]
2427         ["Update dribble" gnus-summary-save-newsrc t])))
2428
2429     (gnus-run-hooks 'gnus-summary-menu-hook)))
2430
2431 (defvar gnus-summary-tool-bar-map nil)
2432
2433 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2434 (defun gnus-summary-make-tool-bar ()
2435   (if (and (fboundp 'tool-bar-add-item-from-menu)
2436            (default-value 'tool-bar-mode)
2437            (not gnus-summary-tool-bar-map))
2438       (setq gnus-summary-tool-bar-map
2439             (let ((tool-bar-map (make-sparse-keymap))
2440                   (load-path (mm-image-load-path)))
2441               (tool-bar-add-item-from-menu
2442                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2443               (tool-bar-add-item-from-menu
2444                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2445               (tool-bar-add-item-from-menu
2446                'gnus-summary-post-news "post" gnus-summary-mode-map)
2447               (tool-bar-add-item-from-menu
2448                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2449               (tool-bar-add-item-from-menu
2450                'gnus-summary-followup "followup" gnus-summary-mode-map)
2451               (tool-bar-add-item-from-menu
2452                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2453               (tool-bar-add-item-from-menu
2454                'gnus-summary-reply "reply" gnus-summary-mode-map)
2455               (tool-bar-add-item-from-menu
2456                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2457               (tool-bar-add-item-from-menu
2458                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2459               (tool-bar-add-item-from-menu
2460                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2461               (tool-bar-add-item-from-menu
2462                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2463               (tool-bar-add-item-from-menu
2464                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2465               (tool-bar-add-item-from-menu
2466                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2467               (tool-bar-add-item-from-menu
2468                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2469               (tool-bar-add-item-from-menu
2470                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2471               tool-bar-map)))
2472   (if gnus-summary-tool-bar-map
2473       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2474
2475 (defun gnus-score-set-default (var value)
2476   "A version of set that updates the GNU Emacs menu-bar."
2477   (set var value)
2478   ;; It is the message that forces the active status to be updated.
2479   (message ""))
2480
2481 (defun gnus-make-score-map (type)
2482   "Make a summary score map of type TYPE."
2483   (if t
2484       nil
2485     (let ((headers '(("author" "from" string)
2486                      ("subject" "subject" string)
2487                      ("article body" "body" string)
2488                      ("article head" "head" string)
2489                      ("xref" "xref" string)
2490                      ("extra header" "extra" string)
2491                      ("lines" "lines" number)
2492                      ("followups to author" "followup" string)))
2493           (types '((number ("less than" <)
2494                            ("greater than" >)
2495                            ("equal" =))
2496                    (string ("substring" s)
2497                            ("exact string" e)
2498                            ("fuzzy string" f)
2499                            ("regexp" r))))
2500           (perms '(("temporary" (current-time-string))
2501                    ("permanent" nil)
2502                    ("immediate" now)))
2503           header)
2504       (list
2505        (apply
2506         'nconc
2507         (list
2508          (if (eq type 'lower)
2509              "Lower score"
2510            "Increase score"))
2511         (let (outh)
2512           (while headers
2513             (setq header (car headers))
2514             (setq outh
2515                   (cons
2516                    (apply
2517                     'nconc
2518                     (list (car header))
2519                     (let ((ts (cdr (assoc (nth 2 header) types)))
2520                           outt)
2521                       (while ts
2522                         (setq outt
2523                               (cons
2524                                (apply
2525                                 'nconc
2526                                 (list (caar ts))
2527                                 (let ((ps perms)
2528                                       outp)
2529                                   (while ps
2530                                     (setq outp
2531                                           (cons
2532                                            (vector
2533                                             (caar ps)
2534                                             (list
2535                                              'gnus-summary-score-entry
2536                                              (nth 1 header)
2537                                              (if (or (string= (nth 1 header)
2538                                                               "head")
2539                                                      (string= (nth 1 header)
2540                                                               "body"))
2541                                                  ""
2542                                                (list 'gnus-summary-header
2543                                                      (nth 1 header)))
2544                                              (list 'quote (nth 1 (car ts)))
2545                                              (list 'gnus-score-delta-default
2546                                                    nil)
2547                                              (nth 1 (car ps))
2548                                              t)
2549                                             t)
2550                                            outp))
2551                                     (setq ps (cdr ps)))
2552                                   (list (nreverse outp))))
2553                                outt))
2554                         (setq ts (cdr ts)))
2555                       (list (nreverse outt))))
2556                    outh))
2557             (setq headers (cdr headers)))
2558           (list (nreverse outh))))))))
2559
2560 \f
2561
2562 (defun gnus-summary-mode (&optional group)
2563   "Major mode for reading articles.
2564
2565 All normal editing commands are switched off.
2566 \\<gnus-summary-mode-map>
2567 Each line in this buffer represents one article.  To read an
2568 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2569 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2570 respectively.
2571
2572 You can also post articles and send mail from this buffer.  To
2573 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2574 of an article, type `\\[gnus-summary-reply]'.
2575
2576 There are approx. one gazillion commands you can execute in this
2577 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2578
2579 The following commands are available:
2580
2581 \\{gnus-summary-mode-map}"
2582   (interactive)
2583   (kill-all-local-variables)
2584   (when (gnus-visual-p 'summary-menu 'menu)
2585     (gnus-summary-make-menu-bar)
2586     (gnus-summary-make-tool-bar))
2587   (gnus-summary-make-local-variables)
2588   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2589     (gnus-summary-make-local-variables))
2590   (gnus-make-thread-indent-array)
2591   (gnus-simplify-mode-line)
2592   (setq major-mode 'gnus-summary-mode)
2593   (setq mode-name "Summary")
2594   (make-local-variable 'minor-mode-alist)
2595   (use-local-map gnus-summary-mode-map)
2596   (buffer-disable-undo)
2597   (setq buffer-read-only t)             ;Disable modification
2598   (setq truncate-lines t)
2599   (setq selective-display t)
2600   (setq selective-display-ellipses t)   ;Display `...'
2601   (gnus-summary-set-display-table)
2602   (gnus-set-default-directory)
2603   (setq gnus-newsgroup-name group)
2604   (unless (gnus-news-group-p group)
2605     (setq gnus-newsgroup-incorporated
2606           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2607   (make-local-variable 'gnus-summary-line-format)
2608   (make-local-variable 'gnus-summary-line-format-spec)
2609   (make-local-variable 'gnus-summary-dummy-line-format)
2610   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2611   (make-local-variable 'gnus-summary-mark-positions)
2612   (make-local-hook 'pre-command-hook)
2613   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2614   (gnus-run-hooks 'gnus-summary-mode-hook)
2615   (turn-on-gnus-mailing-list-mode)
2616   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2617   (gnus-update-summary-mark-positions))
2618
2619 (defun gnus-summary-make-local-variables ()
2620   "Make all the local summary buffer variables."
2621   (let (global)
2622     (dolist (local gnus-summary-local-variables)
2623       (if (consp local)
2624           (progn
2625             (if (eq (cdr local) 'global)
2626                 ;; Copy the global value of the variable.
2627                 (setq global (symbol-value (car local)))
2628               ;; Use the value from the list.
2629               (setq global (eval (cdr local))))
2630             (set (make-local-variable (car local)) global))
2631         ;; Simple nil-valued local variable.
2632         (set (make-local-variable local) nil)))))
2633
2634 (defun gnus-summary-clear-local-variables ()
2635   (let ((locals gnus-summary-local-variables))
2636     (while locals
2637       (if (consp (car locals))
2638           (and (vectorp (caar locals))
2639                (set (caar locals) nil))
2640         (and (vectorp (car locals))
2641              (set (car locals) nil)))
2642       (setq locals (cdr locals)))))
2643
2644 ;; Summary data functions.
2645
2646 (defmacro gnus-data-number (data)
2647   `(car ,data))
2648
2649 (defmacro gnus-data-set-number (data number)
2650   `(setcar ,data ,number))
2651
2652 (defmacro gnus-data-mark (data)
2653   `(nth 1 ,data))
2654
2655 (defmacro gnus-data-set-mark (data mark)
2656   `(setcar (nthcdr 1 ,data) ,mark))
2657
2658 (defmacro gnus-data-pos (data)
2659   `(nth 2 ,data))
2660
2661 (defmacro gnus-data-set-pos (data pos)
2662   `(setcar (nthcdr 2 ,data) ,pos))
2663
2664 (defmacro gnus-data-header (data)
2665   `(nth 3 ,data))
2666
2667 (defmacro gnus-data-set-header (data header)
2668   `(setcar (nthcdr 3 ,data) ,header))
2669
2670 (defmacro gnus-data-level (data)
2671   `(nth 4 ,data))
2672
2673 (defmacro gnus-data-unread-p (data)
2674   `(= (nth 1 ,data) gnus-unread-mark))
2675
2676 (defmacro gnus-data-read-p (data)
2677   `(/= (nth 1 ,data) gnus-unread-mark))
2678
2679 (defmacro gnus-data-pseudo-p (data)
2680   `(consp (nth 3 ,data)))
2681
2682 (defmacro gnus-data-find (number)
2683   `(assq ,number gnus-newsgroup-data))
2684
2685 (defmacro gnus-data-find-list (number &optional data)
2686   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2687      (memq (assq ,number bdata)
2688            bdata)))
2689
2690 (defmacro gnus-data-make (number mark pos header level)
2691   `(list ,number ,mark ,pos ,header ,level))
2692
2693 (defun gnus-data-enter (after-article number mark pos header level offset)
2694   (let ((data (gnus-data-find-list after-article)))
2695     (unless data
2696       (error "No such article: %d" after-article))
2697     (setcdr data (cons (gnus-data-make number mark pos header level)
2698                        (cdr data)))
2699     (setq gnus-newsgroup-data-reverse nil)
2700     (gnus-data-update-list (cddr data) offset)))
2701
2702 (defun gnus-data-enter-list (after-article list &optional offset)
2703   (when list
2704     (let ((data (and after-article (gnus-data-find-list after-article)))
2705           (ilist list))
2706       (if (not (or data
2707                    after-article))
2708           (let ((odata gnus-newsgroup-data))
2709             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2710             (when offset
2711               (gnus-data-update-list odata offset)))
2712         ;; Find the last element in the list to be spliced into the main
2713         ;; list.
2714         (while (cdr list)
2715           (setq list (cdr list)))
2716         (if (not data)
2717             (progn
2718               (setcdr list gnus-newsgroup-data)
2719               (setq gnus-newsgroup-data ilist)
2720               (when offset
2721                 (gnus-data-update-list (cdr list) offset)))
2722           (setcdr list (cdr data))
2723           (setcdr data ilist)
2724           (when offset
2725             (gnus-data-update-list (cdr list) offset))))
2726       (setq gnus-newsgroup-data-reverse nil))))
2727
2728 (defun gnus-data-remove (article &optional offset)
2729   (let ((data gnus-newsgroup-data))
2730     (if (= (gnus-data-number (car data)) article)
2731         (progn
2732           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2733                 gnus-newsgroup-data-reverse nil)
2734           (when offset
2735             (gnus-data-update-list gnus-newsgroup-data offset)))
2736       (while (cdr data)
2737         (when (= (gnus-data-number (cadr data)) article)
2738           (setcdr data (cddr data))
2739           (when offset
2740             (gnus-data-update-list (cdr data) offset))
2741           (setq data nil
2742                 gnus-newsgroup-data-reverse nil))
2743         (setq data (cdr data))))))
2744
2745 (defmacro gnus-data-list (backward)
2746   `(if ,backward
2747        (or gnus-newsgroup-data-reverse
2748            (setq gnus-newsgroup-data-reverse
2749                  (reverse gnus-newsgroup-data)))
2750      gnus-newsgroup-data))
2751
2752 (defun gnus-data-update-list (data offset)
2753   "Add OFFSET to the POS of all data entries in DATA."
2754   (setq gnus-newsgroup-data-reverse nil)
2755   (while data
2756     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2757     (setq data (cdr data))))
2758
2759 (defun gnus-summary-article-pseudo-p (article)
2760   "Say whether this article is a pseudo article or not."
2761   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2762
2763 (defmacro gnus-summary-article-sparse-p (article)
2764   "Say whether this article is a sparse article or not."
2765   `(memq ,article gnus-newsgroup-sparse))
2766
2767 (defmacro gnus-summary-article-ancient-p (article)
2768   "Say whether this article is a sparse article or not."
2769   `(memq ,article gnus-newsgroup-ancient))
2770
2771 (defun gnus-article-parent-p (number)
2772   "Say whether this article is a parent or not."
2773   (let ((data (gnus-data-find-list number)))
2774     (and (cdr data)                     ; There has to be an article after...
2775          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2776             (gnus-data-level (nth 1 data))))))
2777
2778 (defun gnus-article-children (number)
2779   "Return a list of all children to NUMBER."
2780   (let* ((data (gnus-data-find-list number))
2781          (level (gnus-data-level (car data)))
2782          children)
2783     (setq data (cdr data))
2784     (while (and data
2785                 (= (gnus-data-level (car data)) (1+ level)))
2786       (push (gnus-data-number (car data)) children)
2787       (setq data (cdr data)))
2788     children))
2789
2790 (defmacro gnus-summary-skip-intangible ()
2791   "If the current article is intangible, then jump to a different article."
2792   '(let ((to (get-text-property (point) 'gnus-intangible)))
2793      (and to (gnus-summary-goto-subject to))))
2794
2795 (defmacro gnus-summary-article-intangible-p ()
2796   "Say whether this article is intangible or not."
2797   '(get-text-property (point) 'gnus-intangible))
2798
2799 (defun gnus-article-read-p (article)
2800   "Say whether ARTICLE is read or not."
2801   (not (or (memq article gnus-newsgroup-marked)
2802            (memq article gnus-newsgroup-spam-marked)
2803            (memq article gnus-newsgroup-unreads)
2804            (memq article gnus-newsgroup-unselected)
2805            (memq article gnus-newsgroup-dormant))))
2806
2807 ;; Some summary mode macros.
2808
2809 (defmacro gnus-summary-article-number ()
2810   "The article number of the article on the current line.
2811 If there isn't an article number here, then we return the current
2812 article number."
2813   '(progn
2814      (gnus-summary-skip-intangible)
2815      (or (get-text-property (point) 'gnus-number)
2816          (gnus-summary-last-subject))))
2817
2818 (defmacro gnus-summary-article-header (&optional number)
2819   "Return the header of article NUMBER."
2820   `(gnus-data-header (gnus-data-find
2821                       ,(or number '(gnus-summary-article-number)))))
2822
2823 (defmacro gnus-summary-thread-level (&optional number)
2824   "Return the level of thread that starts with article NUMBER."
2825   `(if (and (eq gnus-summary-make-false-root 'dummy)
2826             (get-text-property (point) 'gnus-intangible))
2827        0
2828      (gnus-data-level (gnus-data-find
2829                        ,(or number '(gnus-summary-article-number))))))
2830
2831 (defmacro gnus-summary-article-mark (&optional number)
2832   "Return the mark of article NUMBER."
2833   `(gnus-data-mark (gnus-data-find
2834                     ,(or number '(gnus-summary-article-number)))))
2835
2836 (defmacro gnus-summary-article-pos (&optional number)
2837   "Return the position of the line of article NUMBER."
2838   `(gnus-data-pos (gnus-data-find
2839                    ,(or number '(gnus-summary-article-number)))))
2840
2841 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2842 (defmacro gnus-summary-article-subject (&optional number)
2843   "Return current subject string or nil if nothing."
2844   `(let ((headers
2845           ,(if number
2846                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2847              '(gnus-data-header (assq (gnus-summary-article-number)
2848                                       gnus-newsgroup-data)))))
2849      (and headers
2850           (vectorp headers)
2851           (mail-header-subject headers))))
2852
2853 (defmacro gnus-summary-article-score (&optional number)
2854   "Return current article score."
2855   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2856                   gnus-newsgroup-scored))
2857        gnus-summary-default-score 0))
2858
2859 (defun gnus-summary-article-children (&optional number)
2860   "Return a list of article numbers that are children of article NUMBER."
2861   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2862          (level (gnus-data-level (car data)))
2863          l children)
2864     (while (and (setq data (cdr data))
2865                 (> (setq l (gnus-data-level (car data))) level))
2866       (and (= (1+ level) l)
2867            (push (gnus-data-number (car data))
2868                  children)))
2869     (nreverse children)))
2870
2871 (defun gnus-summary-article-parent (&optional number)
2872   "Return the article number of the parent of article NUMBER."
2873   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2874                                     (gnus-data-list t)))
2875          (level (gnus-data-level (car data))))
2876     (if (zerop level)
2877         ()                              ; This is a root.
2878       ;; We search until we find an article with a level less than
2879       ;; this one.  That function has to be the parent.
2880       (while (and (setq data (cdr data))
2881                   (not (< (gnus-data-level (car data)) level))))
2882       (and data (gnus-data-number (car data))))))
2883
2884 (defun gnus-unread-mark-p (mark)
2885   "Say whether MARK is the unread mark."
2886   (= mark gnus-unread-mark))
2887
2888 (defun gnus-read-mark-p (mark)
2889   "Say whether MARK is one of the marks that mark as read.
2890 This is all marks except unread, ticked, dormant, and expirable."
2891   (not (or (= mark gnus-unread-mark)
2892            (= mark gnus-ticked-mark)
2893            (= mark gnus-spam-mark)
2894            (= mark gnus-dormant-mark)
2895            (= mark gnus-expirable-mark))))
2896
2897 (defmacro gnus-article-mark (number)
2898   "Return the MARK of article NUMBER.
2899 This macro should only be used when computing the mark the \"first\"
2900 time; i.e., when generating the summary lines.  After that,
2901 `gnus-summary-article-mark' should be used to examine the
2902 marks of articles."
2903   `(cond
2904     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2905     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2906     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2907     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2908     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2909     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2910     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2911     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2912            gnus-ancient-mark))))
2913
2914 ;; Saving hidden threads.
2915
2916 (defmacro gnus-save-hidden-threads (&rest forms)
2917   "Save hidden threads, eval FORMS, and restore the hidden threads."
2918   (let ((config (make-symbol "config")))
2919     `(let ((,config (gnus-hidden-threads-configuration)))
2920        (unwind-protect
2921            (save-excursion
2922              ,@forms)
2923          (gnus-restore-hidden-threads-configuration ,config)))))
2924 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2925 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2926
2927 (defun gnus-data-compute-positions ()
2928   "Compute the positions of all articles."
2929   (setq gnus-newsgroup-data-reverse nil)
2930   (let ((data gnus-newsgroup-data))
2931     (save-excursion
2932       (gnus-save-hidden-threads
2933         (gnus-summary-show-all-threads)
2934         (goto-char (point-min))
2935         (while data
2936           (while (get-text-property (point) 'gnus-intangible)
2937             (forward-line 1))
2938           (gnus-data-set-pos (car data) (+ (point) 3))
2939           (setq data (cdr data))
2940           (forward-line 1))))))
2941
2942 (defun gnus-hidden-threads-configuration ()
2943   "Return the current hidden threads configuration."
2944   (save-excursion
2945     (let (config)
2946       (goto-char (point-min))
2947       (while (search-forward "\r" nil t)
2948         (push (1- (point)) config))
2949       config)))
2950
2951 (defun gnus-restore-hidden-threads-configuration (config)
2952   "Restore hidden threads configuration from CONFIG."
2953   (save-excursion
2954     (let (point buffer-read-only)
2955       (while (setq point (pop config))
2956         (when (and (< point (point-max))
2957                    (goto-char point)
2958                    (eq (char-after) ?\n))
2959           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2960
2961 ;; Various summary mode internalish functions.
2962
2963 (defun gnus-mouse-pick-article (e)
2964   (interactive "e")
2965   (mouse-set-point e)
2966   (gnus-summary-next-page nil t))
2967
2968 (defun gnus-summary-set-display-table ()
2969   "Change the display table.
2970 Odd characters have a tendency to mess
2971 up nicely formatted displays - we make all possible glyphs
2972 display only a single character."
2973
2974   ;; We start from the standard display table, if any.
2975   (let ((table (or (copy-sequence standard-display-table)
2976                    (make-display-table)))
2977         (i 32))
2978     ;; Nix out all the control chars...
2979     (while (>= (setq i (1- i)) 0)
2980       (aset table i [??]))
2981     ;; ... but not newline and cr, of course.  (cr is necessary for the
2982     ;; selective display).
2983     (aset table ?\n nil)
2984     (aset table ?\r nil)
2985     ;; We keep TAB as well.
2986     (aset table ?\t nil)
2987     ;; We nix out any glyphs over 126 that are not set already.
2988     (let ((i 256))
2989       (while (>= (setq i (1- i)) 127)
2990         ;; Only modify if the entry is nil.
2991         (unless (aref table i)
2992           (aset table i [??]))))
2993     (setq buffer-display-table table)))
2994
2995 (defun gnus-summary-set-article-display-arrow (pos)
2996   "Update the overlay arrow to point to line at position POS."
2997   (when (and gnus-summary-display-arrow
2998              (boundp 'overlay-arrow-position)
2999              (boundp 'overlay-arrow-string))
3000     (save-excursion
3001       (goto-char pos)
3002       (beginning-of-line)
3003       (unless overlay-arrow-position
3004         (setq overlay-arrow-position (make-marker)))
3005       (setq overlay-arrow-string "=>"
3006             overlay-arrow-position (set-marker overlay-arrow-position
3007                                                (point)
3008                                                (current-buffer))))))
3009
3010 (defun gnus-summary-buffer-name (group)
3011   "Return the summary buffer name of GROUP."
3012   (concat "*Summary " (gnus-group-decoded-name group) "*"))
3013
3014 (defun gnus-summary-setup-buffer (group)
3015   "Initialize summary buffer."
3016   (let ((buffer (gnus-summary-buffer-name group))
3017         (dead-name (concat "*Dead Summary "
3018                            (gnus-group-decoded-name group) "*")))
3019     ;; If a dead summary buffer exists, we kill it.
3020     (when (gnus-buffer-live-p dead-name)
3021       (gnus-kill-buffer dead-name))
3022     (if (get-buffer buffer)
3023         (progn
3024           (set-buffer buffer)
3025           (setq gnus-summary-buffer (current-buffer))
3026           (not gnus-newsgroup-prepared))
3027       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3028       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3029       (gnus-summary-mode group)
3030       (when gnus-carpal
3031         (gnus-carpal-setup-buffer 'summary))
3032       (unless gnus-single-article-buffer
3033         (make-local-variable 'gnus-article-buffer)
3034         (make-local-variable 'gnus-article-current)
3035         (make-local-variable 'gnus-original-article-buffer))
3036       (setq gnus-newsgroup-name group)
3037       ;; Set any local variables in the group parameters.
3038       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3039       t)))
3040
3041 (defun gnus-set-global-variables ()
3042   "Set the global equivalents of the buffer-local variables.
3043 They are set to the latest values they had.  These reflect the summary
3044 buffer that was in action when the last article was fetched."
3045   (when (eq major-mode 'gnus-summary-mode)
3046     (setq gnus-summary-buffer (current-buffer))
3047     (let ((name gnus-newsgroup-name)
3048           (marked gnus-newsgroup-marked)
3049           (spam gnus-newsgroup-spam-marked)
3050           (unread gnus-newsgroup-unreads)
3051           (headers gnus-current-headers)
3052           (data gnus-newsgroup-data)
3053           (summary gnus-summary-buffer)
3054           (article-buffer gnus-article-buffer)
3055           (original gnus-original-article-buffer)
3056           (gac gnus-article-current)
3057           (reffed gnus-reffed-article-number)
3058           (score-file gnus-current-score-file)
3059           (default-charset gnus-newsgroup-charset)
3060           vlist)
3061       (let ((locals gnus-newsgroup-variables))
3062         (while locals
3063           (if (consp (car locals))
3064               (push (eval (caar locals)) vlist)
3065             (push (eval (car locals)) vlist))
3066           (setq locals (cdr locals)))
3067         (setq vlist (nreverse vlist)))
3068       (save-excursion
3069         (set-buffer gnus-group-buffer)
3070         (setq gnus-newsgroup-name name
3071               gnus-newsgroup-marked marked
3072               gnus-newsgroup-spam-marked spam
3073               gnus-newsgroup-unreads unread
3074               gnus-current-headers headers
3075               gnus-newsgroup-data data
3076               gnus-article-current gac
3077               gnus-summary-buffer summary
3078               gnus-article-buffer article-buffer
3079               gnus-original-article-buffer original
3080               gnus-reffed-article-number reffed
3081               gnus-current-score-file score-file
3082               gnus-newsgroup-charset default-charset)
3083         (let ((locals gnus-newsgroup-variables))
3084           (while locals
3085             (if (consp (car locals))
3086                 (set (caar locals) (pop vlist))
3087               (set (car locals) (pop vlist)))
3088             (setq locals (cdr locals))))
3089         ;; The article buffer also has local variables.
3090         (when (gnus-buffer-live-p gnus-article-buffer)
3091           (set-buffer gnus-article-buffer)
3092           (setq gnus-summary-buffer summary))))))
3093
3094 (defun gnus-summary-article-unread-p (article)
3095   "Say whether ARTICLE is unread or not."
3096   (memq article gnus-newsgroup-unreads))
3097
3098 (defun gnus-summary-first-article-p (&optional article)
3099   "Return whether ARTICLE is the first article in the buffer."
3100   (if (not (setq article (or article (gnus-summary-article-number))))
3101       nil
3102     (eq article (caar gnus-newsgroup-data))))
3103
3104 (defun gnus-summary-last-article-p (&optional article)
3105   "Return whether ARTICLE is the last article in the buffer."
3106   (if (not (setq article (or article (gnus-summary-article-number))))
3107       ;; All non-existent numbers are the last article.  :-)
3108       t
3109     (not (cdr (gnus-data-find-list article)))))
3110
3111 (defun gnus-make-thread-indent-array ()
3112   (let ((n 200))
3113     (unless (and gnus-thread-indent-array
3114                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3115       (setq gnus-thread-indent-array (make-vector 201 "")
3116             gnus-thread-indent-array-level gnus-thread-indent-level)
3117       (while (>= n 0)
3118         (aset gnus-thread-indent-array n
3119               (make-string (* n gnus-thread-indent-level) ? ))
3120         (setq n (1- n))))))
3121
3122 (defun gnus-update-summary-mark-positions ()
3123   "Compute where the summary marks are to go."
3124   (save-excursion
3125     (when (gnus-buffer-exists-p gnus-summary-buffer)
3126       (set-buffer gnus-summary-buffer))
3127     (let ((gnus-replied-mark 129)
3128           (gnus-score-below-mark 130)
3129           (gnus-score-over-mark 130)
3130           (gnus-undownloaded-mark 131)
3131           (spec gnus-summary-line-format-spec)
3132           gnus-visual pos)
3133       (save-excursion
3134         (gnus-set-work-buffer)
3135         (let ((gnus-summary-line-format-spec spec)
3136               (gnus-newsgroup-downloadable '(0)))
3137           (gnus-summary-insert-line
3138            (make-full-mail-header 0 "" "nobody"
3139                                   "05 Apr 2001 23:33:09 +0400"
3140                                   "" "" 0 0 "" nil)
3141            0 nil t 128 t nil "" nil 1)
3142           (goto-char (point-min))
3143           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3144                                              (- (point) (point-min) 1)))))
3145           (goto-char (point-min))
3146           (push (cons 'replied (and (search-forward "\201" nil t)
3147                                     (- (point) (point-min) 1)))
3148                 pos)
3149           (goto-char (point-min))
3150           (push (cons 'score (and (search-forward "\202" nil t)
3151                                   (- (point) (point-min) 1)))
3152                 pos)
3153           (goto-char (point-min))
3154           (push (cons 'download
3155                       (and (search-forward "\203" nil t)
3156                            (- (point) (point-min) 1)))
3157                 pos)))
3158       (setq gnus-summary-mark-positions pos))))
3159
3160 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3161   "Insert a dummy root in the summary buffer."
3162   (beginning-of-line)
3163   (gnus-add-text-properties
3164    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3165    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3166
3167 (defun gnus-summary-extract-address-component (from)
3168   (or (car (funcall gnus-extract-address-components from))
3169       from))
3170
3171 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3172   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3173                                 default-mime-charset)))
3174     ;; Is it really necessary to do this next part for each summary line?
3175     ;; Luckily, doesn't seem to slow things down much.
3176     (or
3177      (and gnus-ignored-from-addresses
3178           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3179           (let ((extra-headers (mail-header-extra header))
3180                 to
3181                 newsgroups)
3182             (cond
3183              ((setq to (cdr (assq 'To extra-headers)))
3184               (concat "-> "
3185                       (inline
3186                         (gnus-summary-extract-address-component
3187                          (funcall gnus-decode-encoded-word-function to)))))
3188              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3189               (concat "=> " newsgroups)))))
3190      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3191
3192 (defun gnus-summary-insert-line (gnus-tmp-header
3193                                  gnus-tmp-level gnus-tmp-current
3194                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3195                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3196                                  &optional gnus-tmp-dummy gnus-tmp-score
3197                                  gnus-tmp-process)
3198   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3199          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3200          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3201          (gnus-tmp-score-char
3202           (if (or (null gnus-summary-default-score)
3203                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3204                       gnus-summary-zcore-fuzz))
3205               ?\ ;;;Whitespace
3206             (if (< gnus-tmp-score gnus-summary-default-score)
3207                 gnus-score-below-mark gnus-score-over-mark)))
3208          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3209          (gnus-tmp-replied
3210           (cond (gnus-tmp-process gnus-process-mark)
3211                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3212                  gnus-cached-mark)
3213                 (gnus-tmp-replied gnus-replied-mark)
3214                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3215                  gnus-forwarded-mark)
3216                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3217                  gnus-saved-mark)
3218                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3219                  gnus-recent-mark)
3220                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3221                  gnus-unseen-mark)
3222                 (t gnus-no-mark)))
3223          (gnus-tmp-downloaded
3224           (cond (undownloaded 
3225                  gnus-undownloaded-mark)
3226                 (gnus-newsgroup-agentized
3227                  gnus-downloaded-mark)
3228                 (t
3229                  gnus-no-mark)))
3230          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3231          (gnus-tmp-name
3232           (cond
3233            ((string-match "<[^>]+> *$" gnus-tmp-from)
3234             (let ((beg (match-beginning 0)))
3235               (or (and (string-match "^\".+\"" gnus-tmp-from)
3236                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3237                   (substring gnus-tmp-from 0 beg))))
3238            ((string-match "(.+)" gnus-tmp-from)
3239             (substring gnus-tmp-from
3240                        (1+ (match-beginning 0)) (1- (match-end 0))))
3241            (t gnus-tmp-from)))
3242          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3243          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3244          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3245          (buffer-read-only nil))
3246     (when (string= gnus-tmp-name "")
3247       (setq gnus-tmp-name gnus-tmp-from))
3248     (unless (numberp gnus-tmp-lines)
3249       (setq gnus-tmp-lines -1))
3250     (if (= gnus-tmp-lines -1)
3251         (setq gnus-tmp-lines "?")
3252       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3253     (gnus-put-text-property-excluding-characters-with-faces
3254      (point)
3255      (progn (eval gnus-summary-line-format-spec) (point))
3256      'gnus-number gnus-tmp-number)
3257     (when (gnus-visual-p 'summary-highlight 'highlight)
3258       (forward-line -1)
3259       (gnus-run-hooks 'gnus-summary-update-hook)
3260       (forward-line 1))))
3261
3262 (defun gnus-summary-update-line (&optional dont-update)
3263   "Update summary line after change."
3264   (when (and gnus-summary-default-score
3265              (not gnus-summary-inhibit-highlight))
3266     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3267            (article (gnus-summary-article-number))
3268            (score (gnus-summary-article-score article)))
3269       (unless dont-update
3270         (if (and gnus-summary-mark-below
3271                  (< (gnus-summary-article-score)
3272                     gnus-summary-mark-below))
3273             ;; This article has a low score, so we mark it as read.
3274             (when (memq article gnus-newsgroup-unreads)
3275               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3276           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3277             ;; This article was previously marked as read on account
3278             ;; of a low score, but now it has risen, so we mark it as
3279             ;; unread.
3280             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3281         (gnus-summary-update-mark
3282          (if (or (null gnus-summary-default-score)
3283                  (<= (abs (- score gnus-summary-default-score))
3284                      gnus-summary-zcore-fuzz))
3285              ?\ ;;;Whitespace
3286            (if (< score gnus-summary-default-score)
3287                gnus-score-below-mark gnus-score-over-mark))
3288          'score))
3289       ;; Do visual highlighting.
3290       (when (gnus-visual-p 'summary-highlight 'highlight)
3291         (gnus-run-hooks 'gnus-summary-update-hook)))))
3292
3293 (defvar gnus-tmp-new-adopts nil)
3294
3295 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3296   "Return the number of articles in THREAD.
3297 This may be 0 in some cases -- if none of the articles in
3298 the thread are to be displayed."
3299   (let* ((number
3300           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3301           (cond
3302            ((not (listp thread))
3303             1)
3304            ((and (consp thread) (cdr thread))
3305             (apply
3306              '+ 1 (mapcar
3307                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3308            ((null thread)
3309             1)
3310            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3311             1)
3312            (t 0))))
3313     (when (and level (zerop level) gnus-tmp-new-adopts)
3314       (incf number
3315             (apply '+ (mapcar
3316                        'gnus-summary-number-of-articles-in-thread
3317                        gnus-tmp-new-adopts))))
3318     (if char
3319         (if (> number 1) gnus-not-empty-thread-mark
3320           gnus-empty-thread-mark)
3321       number)))
3322
3323 (defsubst gnus-summary-line-message-size (head)
3324   "Return pretty-printed version of message size.
3325 This function is intended to be used in
3326 `gnus-summary-line-format-alist', which see."
3327   (let ((c (or (mail-header-chars head) -1)))
3328     (cond ((< c 0) "n/a")               ; chars not available
3329           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3330           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3331           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3332           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3333
3334
3335 (defun gnus-summary-set-local-parameters (group)
3336   "Go through the local params of GROUP and set all variable specs in that list."
3337   (let ((params (gnus-group-find-parameter group))
3338         (vars '(quit-config))           ; Ignore quit-config.
3339         elem)
3340     (while params
3341       (setq elem (car params)
3342             params (cdr params))
3343       (and (consp elem)                 ; Has to be a cons.
3344            (consp (cdr elem))           ; The cdr has to be a list.
3345            (symbolp (car elem))         ; Has to be a symbol in there.
3346            (not (memq (car elem) vars))
3347            (ignore-errors               ; So we set it.
3348              (push (car elem) vars)
3349              (make-local-variable (car elem))
3350              (set (car elem) (eval (nth 1 elem))))))))
3351
3352 (defun gnus-summary-read-group (group &optional show-all no-article
3353                                       kill-buffer no-display backward
3354                                       select-articles)
3355   "Start reading news in newsgroup GROUP.
3356 If SHOW-ALL is non-nil, already read articles are also listed.
3357 If NO-ARTICLE is non-nil, no article is selected initially.
3358 If NO-DISPLAY, don't generate a summary buffer."
3359   (let (result)
3360     (while (and group
3361                 (null (setq result
3362                             (let ((gnus-auto-select-next nil))
3363                               (or (gnus-summary-read-group-1
3364                                    group show-all no-article
3365                                    kill-buffer no-display
3366                                    select-articles)
3367                                   (setq show-all nil
3368                                         select-articles nil)))))
3369                 (eq gnus-auto-select-next 'quietly))
3370       (set-buffer gnus-group-buffer)
3371       ;; The entry function called above goes to the next
3372       ;; group automatically, so we go two groups back
3373       ;; if we are searching for the previous group.
3374       (when backward
3375         (gnus-group-prev-unread-group 2))
3376       (if (not (equal group (gnus-group-group-name)))
3377           (setq group (gnus-group-group-name))
3378         (setq group nil)))
3379     result))
3380
3381 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3382   "Directly jump to the other GROUP from summary buffer.
3383 If SHOW-ALL is non-nil, already read articles are also listed."
3384   (interactive
3385    (if (eq gnus-summary-buffer (current-buffer))
3386        (list (completing-read
3387               "Group: " gnus-active-hashtb nil t
3388               (when (and gnus-newsgroup-name
3389                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3390                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3391               'gnus-group-history)
3392              current-prefix-arg)
3393      (error "%s must be invoked from a gnus summary buffer." this-command)))
3394   (unless (or (zerop (length group))
3395               (and gnus-newsgroup-name
3396                    (string-equal gnus-newsgroup-name group)))
3397     (gnus-summary-exit)
3398     (gnus-summary-read-group group show-all
3399                              gnus-dont-select-after-jump-to-other-group)))
3400
3401 (defun gnus-summary-read-group-1 (group show-all no-article
3402                                         kill-buffer no-display
3403                                         &optional select-articles)
3404   ;; Killed foreign groups can't be entered.
3405   ;;  (when (and (not (gnus-group-native-p group))
3406   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3407   ;;    (error "Dead non-native groups can't be entered"))
3408   (gnus-message 5 "Retrieving newsgroup: %s..."
3409                 (gnus-group-decoded-name group))
3410   (let* ((new-group (gnus-summary-setup-buffer group))
3411          (quit-config (gnus-group-quit-config group))
3412          (did-select (and new-group (gnus-select-newsgroup
3413                                      group show-all select-articles))))
3414     (cond
3415      ;; This summary buffer exists already, so we just select it.
3416      ((not new-group)
3417       (gnus-set-global-variables)
3418       (when kill-buffer
3419         (gnus-kill-or-deaden-summary kill-buffer))
3420       (gnus-configure-windows 'summary 'force)
3421       (gnus-set-mode-line 'summary)
3422       (gnus-summary-position-point)
3423       (message "")
3424       t)
3425      ;; We couldn't select this group.
3426      ((null did-select)
3427       (when (and (eq major-mode 'gnus-summary-mode)
3428                  (not (equal (current-buffer) kill-buffer)))
3429         (kill-buffer (current-buffer))
3430         (if (not quit-config)
3431             (progn
3432               ;; Update the info -- marks might need to be removed,
3433               ;; for instance.
3434               (gnus-summary-update-info)
3435               (set-buffer gnus-group-buffer)
3436               (gnus-group-jump-to-group group)
3437               (gnus-group-next-unread-group 1))
3438           (gnus-handle-ephemeral-exit quit-config)))
3439       (let ((grpinfo (gnus-get-info group)))
3440         (if (null (gnus-info-read grpinfo))
3441             (gnus-message 3 "Group %s contains no messages"
3442                           (gnus-group-decoded-name group))
3443           (gnus-message 3 "Can't select group")))
3444       nil)
3445      ;; The user did a `C-g' while prompting for number of articles,
3446      ;; so we exit this group.
3447      ((eq did-select 'quit)
3448       (and (eq major-mode 'gnus-summary-mode)
3449            (not (equal (current-buffer) kill-buffer))
3450            (kill-buffer (current-buffer)))
3451       (when kill-buffer
3452         (gnus-kill-or-deaden-summary kill-buffer))
3453       (if (not quit-config)
3454           (progn
3455             (set-buffer gnus-group-buffer)
3456             (gnus-group-jump-to-group group)
3457             (gnus-group-next-unread-group 1)
3458             (gnus-configure-windows 'group 'force))
3459         (gnus-handle-ephemeral-exit quit-config))
3460       ;; Finally signal the quit.
3461       (signal 'quit nil))
3462      ;; The group was successfully selected.
3463      (t
3464       (gnus-set-global-variables)
3465       ;; Save the active value in effect when the group was entered.
3466       (setq gnus-newsgroup-active
3467             (gnus-copy-sequence
3468              (gnus-active gnus-newsgroup-name)))
3469       ;; You can change the summary buffer in some way with this hook.
3470       (gnus-run-hooks 'gnus-select-group-hook)
3471       (gnus-update-format-specifications
3472        nil 'summary 'summary-mode 'summary-dummy)
3473       (gnus-update-summary-mark-positions)
3474       ;; Do score processing.
3475       (when gnus-use-scoring
3476         (gnus-possibly-score-headers))
3477       ;; Check whether to fill in the gaps in the threads.
3478       (when gnus-build-sparse-threads
3479         (gnus-build-sparse-threads))
3480       ;; Find the initial limit.
3481       (if gnus-show-threads
3482           (if show-all
3483               (let ((gnus-newsgroup-dormant nil))
3484                 (gnus-summary-initial-limit show-all))
3485             (gnus-summary-initial-limit show-all))
3486         ;; When unthreaded, all articles are always shown.
3487         (setq gnus-newsgroup-limit
3488               (mapcar
3489                (lambda (header) (mail-header-number header))
3490                gnus-newsgroup-headers)))
3491       ;; Generate the summary buffer.
3492       (unless no-display
3493         (gnus-summary-prepare))
3494       (when gnus-use-trees
3495         (gnus-tree-open group)
3496         (setq gnus-summary-highlight-line-function
3497               'gnus-tree-highlight-article))
3498       ;; If the summary buffer is empty, but there are some low-scored
3499       ;; articles or some excluded dormants, we include these in the
3500       ;; buffer.
3501       (when (and (zerop (buffer-size))
3502                  (not no-display))
3503         (cond (gnus-newsgroup-dormant
3504                (gnus-summary-limit-include-dormant))
3505               ((and gnus-newsgroup-scored show-all)
3506                (gnus-summary-limit-include-expunged t))))
3507       ;; Function `gnus-apply-kill-file' must be called in this hook.
3508       (gnus-run-hooks 'gnus-apply-kill-hook)
3509       (if (and (zerop (buffer-size))
3510                (not no-display))
3511           (progn
3512             ;; This newsgroup is empty.
3513             (gnus-summary-catchup-and-exit nil t)
3514             (gnus-message 6 "No unread news")
3515             (when kill-buffer
3516               (gnus-kill-or-deaden-summary kill-buffer))
3517             ;; Return nil from this function.
3518             nil)
3519         ;; Hide conversation thread subtrees.  We cannot do this in
3520         ;; gnus-summary-prepare-hook since kill processing may not
3521         ;; work with hidden articles.
3522         (gnus-summary-maybe-hide-threads)
3523         (when kill-buffer
3524           (gnus-kill-or-deaden-summary kill-buffer))
3525         (gnus-summary-auto-select-subject)
3526         ;; Show first unread article if requested.
3527         (if (and (not no-article)
3528                  (not no-display)
3529                  gnus-newsgroup-unreads
3530                  gnus-auto-select-first)
3531             (progn
3532               (gnus-configure-windows 'summary)
3533               (let ((art (gnus-summary-article-number)))
3534                 (unless (and (not gnus-plugged)
3535                              (or (memq art gnus-newsgroup-undownloaded)
3536                                  (memq art gnus-newsgroup-downloadable)))
3537                   (gnus-summary-goto-article art))))
3538           ;; Don't select any articles.
3539           (gnus-summary-position-point)
3540           (gnus-configure-windows 'summary 'force)
3541           (gnus-set-mode-line 'summary))
3542         (when (get-buffer-window gnus-group-buffer t)
3543           ;; Gotta use windows, because recenter does weird stuff if
3544           ;; the current buffer ain't the displayed window.
3545           (let ((owin (selected-window)))
3546             (select-window (get-buffer-window gnus-group-buffer t))
3547             (when (gnus-group-goto-group group)
3548               (recenter))
3549             (select-window owin)))
3550         ;; Mark this buffer as "prepared".
3551         (setq gnus-newsgroup-prepared t)
3552         (gnus-run-hooks 'gnus-summary-prepared-hook)
3553         (unless (gnus-ephemeral-group-p group)
3554           (gnus-group-update-group group))
3555         t)))))
3556
3557 (defun gnus-summary-auto-select-subject ()
3558   "Select the subject line on initial group entry."
3559   (goto-char (point-min))
3560   (cond
3561    ((eq gnus-auto-select-subject 'best)
3562     (gnus-summary-best-unread-subject))
3563    ((eq gnus-auto-select-subject 'unread)
3564     (gnus-summary-first-unread-subject))
3565    ((eq gnus-auto-select-subject 'unseen)
3566     (gnus-summary-first-unseen-subject))
3567    ((eq gnus-auto-select-subject 'unseen-or-unread)
3568     (gnus-summary-first-unseen-or-unread-subject))
3569    ((eq gnus-auto-select-subject 'first)
3570     ;; Do nothing.
3571     )
3572    ((gnus-functionp gnus-auto-select-subject)
3573     (funcall gnus-auto-select-subject))))
3574
3575 (defun gnus-summary-prepare ()
3576   "Generate the summary buffer."
3577   (interactive)
3578   (let ((buffer-read-only nil))
3579     (erase-buffer)
3580     (setq gnus-newsgroup-data nil
3581           gnus-newsgroup-data-reverse nil)
3582     (gnus-run-hooks 'gnus-summary-generate-hook)
3583     ;; Generate the buffer, either with threads or without.
3584     (when gnus-newsgroup-headers
3585       (gnus-summary-prepare-threads
3586        (if gnus-show-threads
3587            (gnus-sort-gathered-threads
3588             (funcall gnus-summary-thread-gathering-function
3589                      (gnus-sort-threads
3590                       (gnus-cut-threads (gnus-make-threads)))))
3591          ;; Unthreaded display.
3592          (gnus-sort-articles gnus-newsgroup-headers))))
3593     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3594     ;; Call hooks for modifying summary buffer.
3595     (goto-char (point-min))
3596     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3597
3598 (defsubst gnus-general-simplify-subject (subject)
3599   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3600   (setq subject
3601         (cond
3602          ;; Truncate the subject.
3603          (gnus-simplify-subject-functions
3604           (gnus-map-function gnus-simplify-subject-functions subject))
3605          ((numberp gnus-summary-gather-subject-limit)
3606           (setq subject (gnus-simplify-subject-re subject))
3607           (if (> (length subject) gnus-summary-gather-subject-limit)
3608               (substring subject 0 gnus-summary-gather-subject-limit)
3609             subject))
3610          ;; Fuzzily simplify it.
3611          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3612           (gnus-simplify-subject-fuzzy subject))
3613          ;; Just remove the leading "Re:".
3614          (t
3615           (gnus-simplify-subject-re subject))))
3616
3617   (if (and gnus-summary-gather-exclude-subject
3618            (string-match gnus-summary-gather-exclude-subject subject))
3619       nil                               ; This article shouldn't be gathered
3620     subject))
3621
3622 (defun gnus-summary-simplify-subject-query ()
3623   "Query where the respool algorithm would put this article."
3624   (interactive)
3625   (gnus-summary-select-article)
3626   (message "%s"
3627            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3628
3629 (defun gnus-gather-threads-by-subject (threads)
3630   "Gather threads by looking at Subject headers."
3631   (if (not gnus-summary-make-false-root)
3632       threads
3633     (let ((hashtb (gnus-make-hashtable 1024))
3634           (prev threads)
3635           (result threads)
3636           subject hthread whole-subject)
3637       (while threads
3638         (setq subject (gnus-general-simplify-subject
3639                        (setq whole-subject (mail-header-subject
3640                                             (caar threads)))))
3641         (when subject
3642           (if (setq hthread (gnus-gethash subject hashtb))
3643               (progn
3644                 ;; We enter a dummy root into the thread, if we
3645                 ;; haven't done that already.
3646                 (unless (stringp (caar hthread))
3647                   (setcar hthread (list whole-subject (car hthread))))
3648                 ;; We add this new gathered thread to this gathered
3649                 ;; thread.
3650                 (setcdr (car hthread)
3651                         (nconc (cdar hthread) (list (car threads))))
3652                 ;; Remove it from the list of threads.
3653                 (setcdr prev (cdr threads))
3654                 (setq threads prev))
3655             ;; Enter this thread into the hash table.
3656             (gnus-sethash subject
3657                           (if gnus-summary-make-false-root-always
3658                               (progn
3659                                 ;; If you want a dummy root above all
3660                                 ;; threads...
3661                                 (setcar threads (list whole-subject
3662                                                       (car threads)))
3663                                 threads)
3664                             threads)
3665                           hashtb)))
3666         (setq prev threads)
3667         (setq threads (cdr threads)))
3668       result)))
3669
3670 (defun gnus-gather-threads-by-references (threads)
3671   "Gather threads by looking at References headers."
3672   (let ((idhashtb (gnus-make-hashtable 1024))
3673         (thhashtb (gnus-make-hashtable 1024))
3674         (prev threads)
3675         (result threads)
3676         ids references id gthread gid entered ref)
3677     (while threads
3678       (when (setq references (mail-header-references (caar threads)))
3679         (setq id (mail-header-id (caar threads))
3680               ids (inline (gnus-split-references references))
3681               entered nil)
3682         (while (setq ref (pop ids))
3683           (setq ids (delete ref ids))
3684           (if (not (setq gid (gnus-gethash ref idhashtb)))
3685               (progn
3686                 (gnus-sethash ref id idhashtb)
3687                 (gnus-sethash id threads thhashtb))
3688             (setq gthread (gnus-gethash gid thhashtb))
3689             (unless entered
3690               ;; We enter a dummy root into the thread, if we
3691               ;; haven't done that already.
3692               (unless (stringp (caar gthread))
3693                 (setcar gthread (list (mail-header-subject (caar gthread))
3694                                       (car gthread))))
3695               ;; We add this new gathered thread to this gathered
3696               ;; thread.
3697               (setcdr (car gthread)
3698                       (nconc (cdar gthread) (list (car threads)))))
3699             ;; Add it into the thread hash table.
3700             (gnus-sethash id gthread thhashtb)
3701             (setq entered t)
3702             ;; Remove it from the list of threads.
3703             (setcdr prev (cdr threads))
3704             (setq threads prev))))
3705       (setq prev threads)
3706       (setq threads (cdr threads)))
3707     result))
3708
3709 (defun gnus-sort-gathered-threads (threads)
3710   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3711   (let ((result threads))
3712     (while threads
3713       (when (stringp (caar threads))
3714         (setcdr (car threads)
3715                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3716       (setq threads (cdr threads)))
3717     result))
3718
3719 (defun gnus-thread-loop-p (root thread)
3720   "Say whether ROOT is in THREAD."
3721   (let ((stack (list thread))
3722         (infloop 0)
3723         th)
3724     (while (setq thread (pop stack))
3725       (setq th (cdr thread))
3726       (while (and th
3727                   (not (eq (caar th) root)))
3728         (pop th))
3729       (if th
3730           ;; We have found a loop.
3731           (let (ref-dep)
3732             (setcdr thread (delq (car th) (cdr thread)))
3733             (if (boundp (setq ref-dep (intern "none"
3734                                               gnus-newsgroup-dependencies)))
3735                 (setcdr (symbol-value ref-dep)
3736                         (nconc (cdr (symbol-value ref-dep))
3737                                (list (car th))))
3738               (set ref-dep (list nil (car th))))
3739             (setq infloop 1
3740                   stack nil))
3741         ;; Push all the subthreads onto the stack.
3742         (push (cdr thread) stack)))
3743     infloop))
3744
3745 (defun gnus-make-threads ()
3746   "Go through the dependency hashtb and find the roots.  Return all threads."
3747   (let (threads)
3748     (while (catch 'infloop
3749              (mapatoms
3750               (lambda (refs)
3751                 ;; Deal with self-referencing References loops.
3752                 (when (and (car (symbol-value refs))
3753                            (not (zerop
3754                                  (apply
3755                                   '+
3756                                   (mapcar
3757                                    (lambda (thread)
3758                                      (gnus-thread-loop-p
3759                                       (car (symbol-value refs)) thread))
3760                                    (cdr (symbol-value refs)))))))
3761                   (setq threads nil)
3762                   (throw 'infloop t))
3763                 (unless (car (symbol-value refs))
3764                   ;; These threads do not refer back to any other articles,
3765                   ;; so they're roots.
3766                   (setq threads (append (cdr (symbol-value refs)) threads))))
3767               gnus-newsgroup-dependencies)))
3768     threads))
3769
3770 ;; Build the thread tree.
3771 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3772   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3773
3774 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3775 if it was already present.
3776
3777 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3778 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3779 Message-IDs will be renamed to a unique Message-ID before being
3780 entered.
3781
3782 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3783   (let* ((id (mail-header-id header))
3784          (id-dep (and id (intern id dependencies)))
3785          parent-id ref ref-dep ref-header replaced)
3786     ;; Enter this `header' in the `dependencies' table.
3787     (cond
3788      ((not id-dep)
3789       (setq header nil))
3790      ;; The first two cases do the normal part: enter a new `header'
3791      ;; in the `dependencies' table.
3792      ((not (boundp id-dep))
3793       (set id-dep (list header)))
3794      ((null (car (symbol-value id-dep)))
3795       (setcar (symbol-value id-dep) header))
3796
3797      ;; From here the `header' was already present in the
3798      ;; `dependencies' table.
3799      (force-new
3800       ;; Overrides an existing entry;
3801       ;; just set the header part of the entry.
3802       (setcar (symbol-value id-dep) header)
3803       (setq replaced t))
3804
3805      ;; Renames the existing `header' to a unique Message-ID.
3806      ((not gnus-summary-ignore-duplicates)
3807       ;; An article with this Message-ID has already been seen.
3808       ;; We rename the Message-ID.
3809       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3810            (list header))
3811       (mail-header-set-id header id))
3812
3813      ;; The last case ignores an existing entry, except it adds any
3814      ;; additional Xrefs (in case the two articles came from different
3815      ;; servers.
3816      ;; Also sets `header' to `nil' meaning that the `dependencies'
3817      ;; table was *not* modified.
3818      (t
3819       (mail-header-set-xref
3820        (car (symbol-value id-dep))
3821        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3822                    "")
3823                (or (mail-header-xref header) "")))
3824       (setq header nil)))
3825
3826     (when (and header (not replaced))
3827       ;; First check that we are not creating a References loop.
3828       (setq parent-id (gnus-parent-id (mail-header-references header)))
3829       (setq ref parent-id)
3830       (while (and ref
3831                   (setq ref-dep (intern-soft ref dependencies))
3832                   (boundp ref-dep)
3833                   (setq ref-header (car (symbol-value ref-dep))))
3834         (if (string= id ref)
3835             ;; Yuk!  This is a reference loop.  Make the article be a
3836             ;; root article.
3837             (progn
3838               (mail-header-set-references (car (symbol-value id-dep)) "none")
3839               (setq ref nil)
3840               (setq parent-id nil))
3841           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3842       (setq ref-dep (intern (or parent-id "none") dependencies))
3843       (if (boundp ref-dep)
3844           (setcdr (symbol-value ref-dep)
3845                   (nconc (cdr (symbol-value ref-dep))
3846                          (list (symbol-value id-dep))))
3847         (set ref-dep (list nil (symbol-value id-dep)))))
3848     header))
3849
3850 (defun gnus-extract-message-id-from-in-reply-to (string)
3851   (if (string-match "<[^>]+>" string)
3852       (substring string (match-beginning 0) (match-end 0))
3853     nil))
3854
3855 (defun gnus-build-sparse-threads ()
3856   (let ((headers gnus-newsgroup-headers)
3857         (mail-parse-charset gnus-newsgroup-charset)
3858         (gnus-summary-ignore-duplicates t)
3859         header references generation relations
3860         subject child end new-child date)
3861     ;; First we create an alist of generations/relations, where
3862     ;; generations is how much we trust the relation, and the relation
3863     ;; is parent/child.
3864     (gnus-message 7 "Making sparse threads...")
3865     (save-excursion
3866       (nnheader-set-temp-buffer " *gnus sparse threads*")
3867       (while (setq header (pop headers))
3868         (when (and (setq references (mail-header-references header))
3869                    (not (string= references "")))
3870           (insert references)
3871           (setq child (mail-header-id header)
3872                 subject (mail-header-subject header)
3873                 date (mail-header-date header)
3874                 generation 0)
3875           (while (search-backward ">" nil t)
3876             (setq end (1+ (point)))
3877             (when (search-backward "<" nil t)
3878               (setq new-child (buffer-substring (point) end))
3879               (push (list (incf generation)
3880                           child (setq child new-child)
3881                           subject date)
3882                     relations)))
3883           (when child
3884             (push (list (1+ generation) child nil subject) relations))
3885           (erase-buffer)))
3886       (kill-buffer (current-buffer)))
3887     ;; Sort over trustworthiness.
3888     (mapcar
3889      (lambda (relation)
3890        (when (gnus-dependencies-add-header
3891               (make-full-mail-header-from-decoded-header
3892                gnus-reffed-article-number
3893                (nth 3 relation) "" (or (nth 4 relation) "")
3894                (nth 1 relation)
3895                (or (nth 2 relation) "") 0 0 "")
3896               gnus-newsgroup-dependencies nil)
3897          (push gnus-reffed-article-number gnus-newsgroup-limit)
3898          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3899          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3900                gnus-newsgroup-reads)
3901          (decf gnus-reffed-article-number)))
3902      (sort relations 'car-less-than-car))
3903     (gnus-message 7 "Making sparse threads...done")))
3904
3905 (defun gnus-build-old-threads ()
3906   ;; Look at all the articles that refer back to old articles, and
3907   ;; fetch the headers for the articles that aren't there.  This will
3908   ;; build complete threads - if the roots haven't been expired by the
3909   ;; server, that is.
3910   (let ((mail-parse-charset gnus-newsgroup-charset)
3911         id heads)
3912     (mapatoms
3913      (lambda (refs)
3914        (when (not (car (symbol-value refs)))
3915          (setq heads (cdr (symbol-value refs)))
3916          (while heads
3917            (if (memq (mail-header-number (caar heads))
3918                      gnus-newsgroup-dormant)
3919                (setq heads (cdr heads))
3920              (setq id (symbol-name refs))
3921              (while (and (setq id (gnus-build-get-header id))
3922                          (not (car (gnus-id-to-thread id)))))
3923              (setq heads nil)))))
3924      gnus-newsgroup-dependencies)))
3925
3926 ;; This function has to be called with point after the article number
3927 ;; on the beginning of the line.
3928 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3929   (let ((eol (gnus-point-at-eol))
3930         (buffer (current-buffer))
3931         header references in-reply-to)
3932
3933     ;; overview: [num subject from date id refs chars lines misc]
3934     (unwind-protect
3935         (progn
3936           (narrow-to-region (point) eol)
3937           (unless (eobp)
3938             (forward-char))
3939
3940           (setq header
3941                 (make-full-mail-header
3942                  number                         ; number
3943                  (nnheader-nov-field)           ; subject
3944                  (nnheader-nov-field)           ; from
3945                  (nnheader-nov-field)           ; date
3946                  (nnheader-nov-read-message-id) ; id
3947                  (nnheader-nov-field)           ; refs
3948                  (nnheader-nov-read-integer)    ; chars
3949                  (nnheader-nov-read-integer)    ; lines
3950                  (unless (eobp)
3951                    (if (looking-at "Xref: ")
3952                        (goto-char (match-end 0)))
3953                    (nnheader-nov-field))        ; Xref
3954                  (nnheader-nov-parse-extra))))  ; extra
3955
3956       (widen))
3957
3958     (when (and (string= references "")
3959                (setq in-reply-to (mail-header-extra header))
3960                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3961       (mail-header-set-references
3962        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3963
3964     (when gnus-alter-header-function
3965       (funcall gnus-alter-header-function header))
3966     (gnus-dependencies-add-header header dependencies force-new)))
3967
3968 (defun gnus-build-get-header (id)
3969   "Look through the buffer of NOV lines and find the header to ID.
3970 Enter this line into the dependencies hash table, and return
3971 the id of the parent article (if any)."
3972   (let ((deps gnus-newsgroup-dependencies)
3973         found header)
3974     (prog1
3975         (save-excursion
3976           (set-buffer nntp-server-buffer)
3977           (let ((case-fold-search nil))
3978             (goto-char (point-min))
3979             (while (and (not found)
3980                         (search-forward id nil t))
3981               (beginning-of-line)
3982               (setq found (looking-at
3983                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3984                                    (regexp-quote id))))
3985               (or found (beginning-of-line 2)))
3986             (when found
3987               (beginning-of-line)
3988               (and
3989                (setq header (gnus-nov-parse-line
3990                              (read (current-buffer)) deps))
3991                (gnus-parent-id (mail-header-references header))))))
3992       (when header
3993         (let ((number (mail-header-number header)))
3994           (push number gnus-newsgroup-limit)
3995           (push header gnus-newsgroup-headers)
3996           (if (memq number gnus-newsgroup-unselected)
3997               (progn
3998                 (setq gnus-newsgroup-unreads
3999                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4000                                                number))
4001                 (setq gnus-newsgroup-unselected
4002                       (delq number gnus-newsgroup-unselected)))
4003             (push number gnus-newsgroup-ancient)))))))
4004
4005 (defun gnus-build-all-threads ()
4006   "Read all the headers."
4007   (let ((gnus-summary-ignore-duplicates t)
4008         (mail-parse-charset gnus-newsgroup-charset)
4009         (dependencies gnus-newsgroup-dependencies)
4010         header article)
4011     (save-excursion
4012       (set-buffer nntp-server-buffer)
4013       (let ((case-fold-search nil))
4014         (goto-char (point-min))
4015         (while (not (eobp))
4016           (ignore-errors
4017             (setq article (read (current-buffer))
4018                   header (gnus-nov-parse-line article dependencies)))
4019           (when header
4020             (save-excursion
4021               (set-buffer gnus-summary-buffer)
4022               (push header gnus-newsgroup-headers)
4023               (if (memq (setq article (mail-header-number header))
4024                         gnus-newsgroup-unselected)
4025                   (progn
4026                     (setq gnus-newsgroup-unreads
4027                           (gnus-add-to-sorted-list
4028                            gnus-newsgroup-unreads article))
4029                     (setq gnus-newsgroup-unselected
4030                           (delq article gnus-newsgroup-unselected)))
4031                 (push article gnus-newsgroup-ancient)))
4032             (forward-line 1)))))))
4033
4034 (defun gnus-summary-update-article-line (article header)
4035   "Update the line for ARTICLE using HEADERS."
4036   (let* ((id (mail-header-id header))
4037          (thread (gnus-id-to-thread id)))
4038     (unless thread
4039       (error "Article in no thread"))
4040     ;; Update the thread.
4041     (setcar thread header)
4042     (gnus-summary-goto-subject article)
4043     (let* ((datal (gnus-data-find-list article))
4044            (data (car datal))
4045            (buffer-read-only nil)
4046            (level (gnus-summary-thread-level)))
4047       (gnus-delete-line)
4048       (let ((inserted (- (point)
4049                          (progn
4050                            (gnus-summary-insert-line
4051                             header level nil 
4052                             (memq article gnus-newsgroup-undownloaded)
4053                             (gnus-article-mark article)
4054                             (memq article gnus-newsgroup-replied)
4055                             (memq article gnus-newsgroup-expirable)
4056                             ;; Only insert the Subject string when it's different
4057                             ;; from the previous Subject string.
4058                             (if (and
4059                                  gnus-show-threads
4060                                  (gnus-subject-equal
4061                                   (condition-case ()
4062                                       (mail-header-subject
4063                                        (gnus-data-header
4064                                         (cadr
4065                                          (gnus-data-find-list
4066                                           article
4067                                           (gnus-data-list t)))))
4068                                     ;; Error on the side of excessive subjects.
4069                                     (error ""))
4070                                   (mail-header-subject header)))
4071                                 ""
4072                               (mail-header-subject header))
4073                             nil (cdr (assq article gnus-newsgroup-scored))
4074                             (memq article gnus-newsgroup-processable))
4075                            (point)))))
4076         (when (cdr datal)
4077           (gnus-data-update-list
4078            (cdr datal) 
4079            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4080
4081 (defun gnus-summary-update-article (article &optional iheader)
4082   "Update ARTICLE in the summary buffer."
4083   (set-buffer gnus-summary-buffer)
4084   (let* ((header (gnus-summary-article-header article))
4085          (id (mail-header-id header))
4086          (data (gnus-data-find article))
4087          (thread (gnus-id-to-thread id))
4088          (references (mail-header-references header))
4089          (parent
4090           (gnus-id-to-thread
4091            (or (gnus-parent-id
4092                 (when (and references
4093                            (not (equal "" references)))
4094                   references))
4095                "none")))
4096          (buffer-read-only nil)
4097          (old (car thread)))
4098     (when thread
4099       (unless iheader
4100         (setcar thread nil)
4101         (when parent
4102           (delq thread parent)))
4103       (if (gnus-summary-insert-subject id header)
4104           ;; Set the (possibly) new article number in the data structure.
4105           (gnus-data-set-number data (gnus-id-to-article id))
4106         (setcar thread old)
4107         nil))))
4108
4109 (defun gnus-rebuild-thread (id &optional line)
4110   "Rebuild the thread containing ID.
4111 If LINE, insert the rebuilt thread starting on line LINE."
4112   (let ((buffer-read-only nil)
4113         old-pos current thread data)
4114     (if (not gnus-show-threads)
4115         (setq thread (list (car (gnus-id-to-thread id))))
4116       ;; Get the thread this article is part of.
4117       (setq thread (gnus-remove-thread id)))
4118     (setq old-pos (gnus-point-at-bol))
4119     (setq current (save-excursion
4120                     (and (re-search-backward "[\r\n]" nil t)
4121                          (gnus-summary-article-number))))
4122     ;; If this is a gathered thread, we have to go some re-gathering.
4123     (when (stringp (car thread))
4124       (let ((subject (car thread))
4125             roots thr)
4126         (setq thread (cdr thread))
4127         (while thread
4128           (unless (memq (setq thr (gnus-id-to-thread
4129                                    (gnus-root-id
4130                                     (mail-header-id (caar thread)))))
4131                         roots)
4132             (push thr roots))
4133           (setq thread (cdr thread)))
4134         ;; We now have all (unique) roots.
4135         (if (= (length roots) 1)
4136             ;; All the loose roots are now one solid root.
4137             (setq thread (car roots))
4138           (setq thread (cons subject (gnus-sort-threads roots))))))
4139     (let (threads)
4140       ;; We then insert this thread into the summary buffer.
4141       (when line
4142         (goto-char (point-min))
4143         (forward-line (1- line)))
4144       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4145         (if gnus-show-threads
4146             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4147           (gnus-summary-prepare-unthreaded thread))
4148         (setq data (nreverse gnus-newsgroup-data))
4149         (setq threads gnus-newsgroup-threads))
4150       ;; We splice the new data into the data structure.
4151       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4152       ;;!!! then we want to insert at the beginning of the buffer.
4153       ;;!!! That happens to be true with Gnus now, but that may
4154       ;;!!! change in the future.  Perhaps.
4155       (gnus-data-enter-list
4156        (if line nil current) data (- (point) old-pos))
4157       (setq gnus-newsgroup-threads
4158             (nconc threads gnus-newsgroup-threads))
4159       (gnus-data-compute-positions))))
4160
4161 (defun gnus-number-to-header (number)
4162   "Return the header for article NUMBER."
4163   (let ((headers gnus-newsgroup-headers))
4164     (while (and headers
4165                 (not (= number (mail-header-number (car headers)))))
4166       (pop headers))
4167     (when headers
4168       (car headers))))
4169
4170 (defun gnus-parent-headers (in-headers &optional generation)
4171   "Return the headers of the GENERATIONeth parent of HEADERS."
4172   (unless generation
4173     (setq generation 1))
4174   (let ((parent t)
4175         (headers in-headers)
4176         references)
4177     (while (and parent
4178                 (not (zerop generation))
4179                 (setq references (mail-header-references headers)))
4180       (setq headers (if (and references
4181                              (setq parent (gnus-parent-id references)))
4182                         (car (gnus-id-to-thread parent))
4183                       nil))
4184       (decf generation))
4185     (and (not (eq headers in-headers))
4186          headers)))
4187
4188 (defun gnus-id-to-thread (id)
4189   "Return the (sub-)thread where ID appears."
4190   (gnus-gethash id gnus-newsgroup-dependencies))
4191
4192 (defun gnus-id-to-article (id)
4193   "Return the article number of ID."
4194   (let ((thread (gnus-id-to-thread id)))
4195     (when (and thread
4196                (car thread))
4197       (mail-header-number (car thread)))))
4198
4199 (defun gnus-id-to-header (id)
4200   "Return the article headers of ID."
4201   (car (gnus-id-to-thread id)))
4202
4203 (defun gnus-article-displayed-root-p (article)
4204   "Say whether ARTICLE is a root(ish) article."
4205   (let ((level (gnus-summary-thread-level article))
4206         (refs (mail-header-references  (gnus-summary-article-header article)))
4207         particle)
4208     (cond
4209      ((null level) nil)
4210      ((zerop level) t)
4211      ((null refs) t)
4212      ((null (gnus-parent-id refs)) t)
4213      ((and (= 1 level)
4214            (null (setq particle (gnus-id-to-article
4215                                  (gnus-parent-id refs))))
4216            (null (gnus-summary-thread-level particle)))))))
4217
4218 (defun gnus-root-id (id)
4219   "Return the id of the root of the thread where ID appears."
4220   (let (last-id prev)
4221     (while (and id (setq prev (car (gnus-id-to-thread id))))
4222       (setq last-id id
4223             id (gnus-parent-id (mail-header-references prev))))
4224     last-id))
4225
4226 (defun gnus-articles-in-thread (thread)
4227   "Return the list of articles in THREAD."
4228   (cons (mail-header-number (car thread))
4229         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4230
4231 (defun gnus-remove-thread (id &optional dont-remove)
4232   "Remove the thread that has ID in it."
4233   (let (headers thread last-id)
4234     ;; First go up in this thread until we find the root.
4235     (setq last-id (gnus-root-id id)
4236           headers (message-flatten-list (gnus-id-to-thread last-id)))
4237     ;; We have now found the real root of this thread.  It might have
4238     ;; been gathered into some loose thread, so we have to search
4239     ;; through the threads to find the thread we wanted.
4240     (let ((threads gnus-newsgroup-threads)
4241           sub)
4242       (while threads
4243         (setq sub (car threads))
4244         (if (stringp (car sub))
4245             ;; This is a gathered thread, so we look at the roots
4246             ;; below it to find whether this article is in this
4247             ;; gathered root.
4248             (progn
4249               (setq sub (cdr sub))
4250               (while sub
4251                 (when (member (caar sub) headers)
4252                   (setq thread (car threads)
4253                         threads nil
4254                         sub nil))
4255                 (setq sub (cdr sub))))
4256           ;; It's an ordinary thread, so we check it.
4257           (when (eq (car sub) (car headers))
4258             (setq thread sub
4259                   threads nil)))
4260         (setq threads (cdr threads)))
4261       ;; If this article is in no thread, then it's a root.
4262       (if thread
4263           (unless dont-remove
4264             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4265         (setq thread (gnus-id-to-thread last-id)))
4266       (when thread
4267         (prog1
4268             thread                      ; We return this thread.
4269           (unless dont-remove
4270             (if (stringp (car thread))
4271                 (progn
4272                   ;; If we use dummy roots, then we have to remove the
4273                   ;; dummy root as well.
4274                   (when (eq gnus-summary-make-false-root 'dummy)
4275                     ;; We go to the dummy root by going to
4276                     ;; the first sub-"thread", and then one line up.
4277                     (gnus-summary-goto-article
4278                      (mail-header-number (caadr thread)))
4279                     (forward-line -1)
4280                     (gnus-delete-line)
4281                     (gnus-data-compute-positions))
4282                   (setq thread (cdr thread))
4283                   (while thread
4284                     (gnus-remove-thread-1 (car thread))
4285                     (setq thread (cdr thread))))
4286               (gnus-remove-thread-1 thread))))))))
4287
4288 (defun gnus-remove-thread-1 (thread)
4289   "Remove the thread THREAD recursively."
4290   (let ((number (mail-header-number (pop thread)))
4291         d)
4292     (setq thread (reverse thread))
4293     (while thread
4294       (gnus-remove-thread-1 (pop thread)))
4295     (when (setq d (gnus-data-find number))
4296       (goto-char (gnus-data-pos d))
4297       (gnus-summary-show-thread)
4298       (gnus-data-remove
4299        number
4300        (- (gnus-point-at-bol)
4301           (prog1
4302               (1+ (gnus-point-at-eol))
4303             (gnus-delete-line)))))))
4304
4305 (defun gnus-sort-threads-1 (threads func)
4306   (sort (mapcar (lambda (thread)
4307                   (cons (car thread)
4308                         (and (cdr thread)
4309                              (gnus-sort-threads-1 (cdr thread) func))))
4310                 threads) func))
4311
4312 (defun gnus-sort-threads (threads)
4313   "Sort THREADS."
4314   (if (not gnus-thread-sort-functions)
4315       threads
4316     (gnus-message 8 "Sorting threads...")
4317     (let ((max-lisp-eval-depth 5000))
4318       (prog1 (gnus-sort-threads-1
4319          threads
4320          (gnus-make-sort-function gnus-thread-sort-functions))
4321         (gnus-message 8 "Sorting threads...done")))))
4322
4323 (defun gnus-sort-articles (articles)
4324   "Sort ARTICLES."
4325   (when gnus-article-sort-functions
4326     (gnus-message 7 "Sorting articles...")
4327     (prog1
4328         (setq gnus-newsgroup-headers
4329               (sort articles (gnus-make-sort-function
4330                               gnus-article-sort-functions)))
4331       (gnus-message 7 "Sorting articles...done"))))
4332
4333 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4334 (defmacro gnus-thread-header (thread)
4335   "Return header of first article in THREAD.
4336 Note that THREAD must never, ever be anything else than a variable -
4337 using some other form will lead to serious barfage."
4338   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4339   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4340   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4341         (vector thread) 2))
4342
4343 (defsubst gnus-article-sort-by-number (h1 h2)
4344   "Sort articles by article number."
4345   (< (mail-header-number h1)
4346      (mail-header-number h2)))
4347
4348 (defun gnus-thread-sort-by-number (h1 h2)
4349   "Sort threads by root article number."
4350   (gnus-article-sort-by-number
4351    (gnus-thread-header h1) (gnus-thread-header h2)))
4352
4353 (defsubst gnus-article-sort-by-random (h1 h2)
4354   "Sort articles by article number."
4355   (zerop (random 2)))
4356
4357 (defun gnus-thread-sort-by-random (h1 h2)
4358   "Sort threads by root article number."
4359   (gnus-article-sort-by-random
4360    (gnus-thread-header h1) (gnus-thread-header h2)))
4361
4362 (defsubst gnus-article-sort-by-lines (h1 h2)
4363   "Sort articles by article Lines header."
4364   (< (mail-header-lines h1)
4365      (mail-header-lines h2)))
4366
4367 (defun gnus-thread-sort-by-lines (h1 h2)
4368   "Sort threads by root article Lines header."
4369   (gnus-article-sort-by-lines
4370    (gnus-thread-header h1) (gnus-thread-header h2)))
4371
4372 (defsubst gnus-article-sort-by-chars (h1 h2)
4373   "Sort articles by octet length."
4374   (< (mail-header-chars h1)
4375      (mail-header-chars h2)))
4376
4377 (defun gnus-thread-sort-by-chars (h1 h2)
4378   "Sort threads by root article octet length."
4379   (gnus-article-sort-by-chars
4380    (gnus-thread-header h1) (gnus-thread-header h2)))
4381
4382 (defsubst gnus-article-sort-by-author (h1 h2)
4383   "Sort articles by root author."
4384   (string-lessp
4385    (let ((addr (car (mime-entity-read-field h1 'From))))
4386      (or (std11-full-name-string addr)
4387          (std11-address-string addr)
4388          ""))
4389    (let ((addr (car (mime-entity-read-field h2 'From))))
4390      (or (std11-full-name-string addr)
4391          (std11-address-string addr)
4392          ""))
4393    ))
4394
4395 (defun gnus-thread-sort-by-author (h1 h2)
4396   "Sort threads by root author."
4397   (gnus-article-sort-by-author
4398    (gnus-thread-header h1)  (gnus-thread-header h2)))
4399
4400 (defsubst gnus-article-sort-by-subject (h1 h2)
4401   "Sort articles by root subject."
4402   (string-lessp
4403    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4404    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4405
4406 (defun gnus-thread-sort-by-subject (h1 h2)
4407   "Sort threads by root subject."
4408   (gnus-article-sort-by-subject
4409    (gnus-thread-header h1) (gnus-thread-header h2)))
4410
4411 (defsubst gnus-article-sort-by-date (h1 h2)
4412   "Sort articles by root article date."
4413   (time-less-p
4414    (gnus-date-get-time (mail-header-date h1))
4415    (gnus-date-get-time (mail-header-date h2))))
4416
4417 (defun gnus-thread-sort-by-date (h1 h2)
4418   "Sort threads by root article date."
4419   (gnus-article-sort-by-date
4420    (gnus-thread-header h1) (gnus-thread-header h2)))
4421
4422 (defsubst gnus-article-sort-by-score (h1 h2)
4423   "Sort articles by root article score.
4424 Unscored articles will be counted as having a score of zero."
4425   (> (or (cdr (assq (mail-header-number h1)
4426                     gnus-newsgroup-scored))
4427          gnus-summary-default-score 0)
4428      (or (cdr (assq (mail-header-number h2)
4429                     gnus-newsgroup-scored))
4430          gnus-summary-default-score 0)))
4431
4432 (defun gnus-thread-sort-by-score (h1 h2)
4433   "Sort threads by root article score."
4434   (gnus-article-sort-by-score
4435    (gnus-thread-header h1) (gnus-thread-header h2)))
4436
4437 (defun gnus-thread-sort-by-total-score (h1 h2)
4438   "Sort threads by the sum of all scores in the thread.
4439 Unscored articles will be counted as having a score of zero."
4440   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4441
4442 (defun gnus-thread-total-score (thread)
4443   ;; This function find the total score of THREAD.
4444   (cond
4445    ((null thread)
4446     0)
4447    ((consp thread)
4448     (if (stringp (car thread))
4449         (apply gnus-thread-score-function 0
4450                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4451       (gnus-thread-total-score-1 thread)))
4452    (t
4453     (gnus-thread-total-score-1 (list thread)))))
4454
4455 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4456   "Sort threads such that the thread with the most recently arrived article comes first."
4457   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4458
4459 (defun gnus-thread-highest-number (thread)
4460   "Return the highest article number in THREAD."
4461   (apply 'max (mapcar (lambda (header)
4462                         (mail-header-number header))
4463                       (message-flatten-list thread))))
4464
4465 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4466   "Sort threads such that the thread with the most recently dated article comes first."
4467   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4468
4469 (defun gnus-thread-latest-date (thread)
4470   "Return the highest article date in THREAD."
4471   (let ((previous-time 0))
4472     (apply 'max
4473            (mapcar
4474             (lambda (header)
4475               (setq previous-time
4476                     (time-to-seconds
4477                      (condition-case ()
4478                          (mail-header-parse-date (mail-header-date header))
4479                        (error previous-time)))))
4480             (sort
4481              (message-flatten-list thread)
4482              (lambda (h1 h2)
4483                (< (mail-header-number h1)
4484                   (mail-header-number h2))))))))
4485
4486 (defun gnus-thread-total-score-1 (root)
4487   ;; This function find the total score of the thread below ROOT.
4488   (setq root (car root))
4489   (apply gnus-thread-score-function
4490          (or (append
4491               (mapcar 'gnus-thread-total-score
4492                       (cdr (gnus-id-to-thread (mail-header-id root))))
4493               (when (> (mail-header-number root) 0)
4494                 (list (or (cdr (assq (mail-header-number root)
4495                                      gnus-newsgroup-scored))
4496                           gnus-summary-default-score 0))))
4497              (list gnus-summary-default-score)
4498              '(0))))
4499
4500 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4501 (defvar gnus-tmp-prev-subject nil)
4502 (defvar gnus-tmp-false-parent nil)
4503 (defvar gnus-tmp-root-expunged nil)
4504 (defvar gnus-tmp-dummy-line nil)
4505
4506 (eval-when-compile (defvar gnus-tmp-header))
4507 (defun gnus-extra-header (type &optional header)
4508   "Return the extra header of TYPE."
4509   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4510       ""))
4511
4512 (defvar gnus-tmp-thread-tree-header-string "")
4513
4514 (defcustom gnus-sum-thread-tree-root "> "
4515   "With %B spec, used for the root of a thread.
4516 If nil, use subject instead."
4517   :type 'string
4518   :group 'gnus-thread)
4519 (defcustom gnus-sum-thread-tree-single-indent ""
4520   "With %B spec, used for a thread with just one message.
4521 If nil, use subject instead."
4522   :type 'string
4523   :group 'gnus-thread)
4524 (defcustom gnus-sum-thread-tree-vertical "| "
4525   "With %B spec, used for drawing a vertical line."
4526   :type 'string
4527   :group 'gnus-thread)
4528 (defcustom gnus-sum-thread-tree-indent "  "
4529   "With %B spec, used for indenting."
4530   :type 'string
4531   :group 'gnus-thread)
4532 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4533   "With %B spec, used for a leaf with brothers."
4534   :type 'string
4535   :group 'gnus-thread)
4536 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4537   "With %B spec, used for a leaf without brothers."
4538   :type 'string
4539   :group 'gnus-thread)
4540
4541 (defun gnus-summary-prepare-threads (threads)
4542   "Prepare summary buffer from THREADS and indentation LEVEL.
4543 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4544 or a straight list of headers."
4545   (gnus-message 7 "Generating summary...")
4546
4547   (setq gnus-newsgroup-threads threads)
4548   (beginning-of-line)
4549
4550   (let ((gnus-tmp-level 0)
4551         (default-score (or gnus-summary-default-score 0))
4552         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4553         (building-line-count gnus-summary-display-while-building)
4554         (building-count (integerp gnus-summary-display-while-building))
4555         thread number subject stack state gnus-tmp-gathered beg-match
4556         new-roots gnus-tmp-new-adopts thread-end simp-subject
4557         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4558         gnus-tmp-replied gnus-tmp-subject-or-nil
4559         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4560         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4561         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4562         tree-stack)
4563
4564     (setq gnus-tmp-prev-subject nil)
4565
4566     (if (vectorp (car threads))
4567         ;; If this is a straight (sic) list of headers, then a
4568         ;; threaded summary display isn't required, so we just create
4569         ;; an unthreaded one.
4570         (gnus-summary-prepare-unthreaded threads)
4571
4572       ;; Do the threaded display.
4573
4574       (if gnus-summary-display-while-building
4575           (switch-to-buffer (buffer-name)))
4576       (while (or threads stack gnus-tmp-new-adopts new-roots)
4577
4578         (if (and (= gnus-tmp-level 0)
4579                  (or (not stack)
4580                      (= (caar stack) 0))
4581                  (not gnus-tmp-false-parent)
4582                  (or gnus-tmp-new-adopts new-roots))
4583             (if gnus-tmp-new-adopts
4584                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4585                       thread (list (car gnus-tmp-new-adopts))
4586                       gnus-tmp-header (caar thread)
4587                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4588               (when new-roots
4589                 (setq thread (list (car new-roots))
4590                       gnus-tmp-header (caar thread)
4591                       new-roots (cdr new-roots))))
4592
4593           (if threads
4594               ;; If there are some threads, we do them before the
4595               ;; threads on the stack.
4596               (setq thread threads
4597                     gnus-tmp-header (caar thread))
4598             ;; There were no current threads, so we pop something off
4599             ;; the stack.
4600             (setq state (car stack)
4601                   gnus-tmp-level (car state)
4602                   tree-stack (cadr state)
4603                   thread (caddr state)
4604                   stack (cdr stack)
4605                   gnus-tmp-header (caar thread))))
4606
4607         (setq gnus-tmp-false-parent nil)
4608         (setq gnus-tmp-root-expunged nil)
4609         (setq thread-end nil)
4610
4611         (if (stringp gnus-tmp-header)
4612             ;; The header is a dummy root.
4613             (cond
4614              ((eq gnus-summary-make-false-root 'adopt)
4615               ;; We let the first article adopt the rest.
4616               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4617                                                (cddar thread)))
4618               (setq gnus-tmp-gathered
4619                     (nconc (mapcar
4620                             (lambda (h) (mail-header-number (car h)))
4621                             (cddar thread))
4622                            gnus-tmp-gathered))
4623               (setq thread (cons (list (caar thread)
4624                                        (cadar thread))
4625                                  (cdr thread)))
4626               (setq gnus-tmp-level -1
4627                     gnus-tmp-false-parent t))
4628              ((eq gnus-summary-make-false-root 'empty)
4629               ;; We print adopted articles with empty subject fields.
4630               (setq gnus-tmp-gathered
4631                     (nconc (mapcar
4632                             (lambda (h) (mail-header-number (car h)))
4633                             (cddar thread))
4634                            gnus-tmp-gathered))
4635               (setq gnus-tmp-level -1))
4636              ((eq gnus-summary-make-false-root 'dummy)
4637               ;; We remember that we probably want to output a dummy
4638               ;; root.
4639               (setq gnus-tmp-dummy-line gnus-tmp-header)
4640               (setq gnus-tmp-prev-subject gnus-tmp-header))
4641              (t
4642               ;; We do not make a root for the gathered
4643               ;; sub-threads at all.
4644               (setq gnus-tmp-level -1)))
4645
4646           (setq number (mail-header-number gnus-tmp-header)
4647                 subject (mail-header-subject gnus-tmp-header)
4648                 simp-subject (gnus-simplify-subject-fully subject))
4649
4650           (cond
4651            ;; If the thread has changed subject, we might want to make
4652            ;; this subthread into a root.
4653            ((and (null gnus-thread-ignore-subject)
4654                  (not (zerop gnus-tmp-level))
4655                  gnus-tmp-prev-subject
4656                  (not (string= gnus-tmp-prev-subject simp-subject)))
4657             (setq new-roots (nconc new-roots (list (car thread)))
4658                   thread-end t
4659                   gnus-tmp-header nil))
4660            ;; If the article lies outside the current limit,
4661            ;; then we do not display it.
4662            ((not (memq number gnus-newsgroup-limit))
4663             (setq gnus-tmp-gathered
4664                   (nconc (mapcar
4665                           (lambda (h) (mail-header-number (car h)))
4666                           (cdar thread))
4667                          gnus-tmp-gathered))
4668             (setq gnus-tmp-new-adopts (if (cdar thread)
4669                                           (append gnus-tmp-new-adopts
4670                                                   (cdar thread))
4671                                         gnus-tmp-new-adopts)
4672                   thread-end t
4673                   gnus-tmp-header nil)
4674             (when (zerop gnus-tmp-level)
4675               (setq gnus-tmp-root-expunged t)))
4676            ;; Perhaps this article is to be marked as read?
4677            ((and gnus-summary-mark-below
4678                  (< (or (cdr (assq number gnus-newsgroup-scored))
4679                         default-score)
4680                     gnus-summary-mark-below)
4681                  ;; Don't touch sparse articles.
4682                  (not (gnus-summary-article-sparse-p number))
4683                  (not (gnus-summary-article-ancient-p number)))
4684             (setq gnus-newsgroup-unreads
4685                   (delq number gnus-newsgroup-unreads))
4686             (if gnus-newsgroup-auto-expire
4687                 (setq gnus-newsgroup-expirable
4688                       (gnus-add-to-sorted-list
4689                        gnus-newsgroup-expirable number))
4690               (push (cons number gnus-low-score-mark)
4691                     gnus-newsgroup-reads))))
4692
4693           (when gnus-tmp-header
4694             ;; We may have an old dummy line to output before this
4695             ;; article.
4696             (when (and gnus-tmp-dummy-line
4697                        (gnus-subject-equal
4698                         gnus-tmp-dummy-line
4699                         (mail-header-subject gnus-tmp-header)))
4700               (gnus-summary-insert-dummy-line
4701                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4702               (setq gnus-tmp-dummy-line nil))
4703
4704             ;; Compute the mark.
4705             (setq gnus-tmp-unread (gnus-article-mark number))
4706
4707             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4708                                   gnus-tmp-header gnus-tmp-level)
4709                   gnus-newsgroup-data)
4710
4711             ;; Actually insert the line.
4712             (setq
4713              gnus-tmp-subject-or-nil
4714              (cond
4715               ((and gnus-thread-ignore-subject
4716                     gnus-tmp-prev-subject
4717                     (not (string= gnus-tmp-prev-subject simp-subject)))
4718                subject)
4719               ((zerop gnus-tmp-level)
4720                (if (and (eq gnus-summary-make-false-root 'empty)
4721                         (memq number gnus-tmp-gathered)
4722                         gnus-tmp-prev-subject
4723                         (string= gnus-tmp-prev-subject simp-subject))
4724                    gnus-summary-same-subject
4725                  subject))
4726               (t gnus-summary-same-subject)))
4727             (if (and (eq gnus-summary-make-false-root 'adopt)
4728                      (= gnus-tmp-level 1)
4729                      (memq number gnus-tmp-gathered))
4730                 (setq gnus-tmp-opening-bracket ?\<
4731                       gnus-tmp-closing-bracket ?\>)
4732               (setq gnus-tmp-opening-bracket ?\[
4733                     gnus-tmp-closing-bracket ?\]))
4734             (setq
4735              gnus-tmp-indentation
4736              (aref gnus-thread-indent-array gnus-tmp-level)
4737              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4738              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4739                                 gnus-summary-default-score 0)
4740              gnus-tmp-score-char
4741              (if (or (null gnus-summary-default-score)
4742                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4743                          gnus-summary-zcore-fuzz))
4744                  ?\ ;;;Whitespace
4745                (if (< gnus-tmp-score gnus-summary-default-score)
4746                    gnus-score-below-mark gnus-score-over-mark))
4747              gnus-tmp-replied
4748              (cond ((memq number gnus-newsgroup-processable)
4749                     gnus-process-mark)
4750                    ((memq number gnus-newsgroup-cached)
4751                     gnus-cached-mark)
4752                    ((memq number gnus-newsgroup-replied)
4753                     gnus-replied-mark)
4754                    ((memq number gnus-newsgroup-forwarded)
4755                     gnus-forwarded-mark)
4756                    ((memq number gnus-newsgroup-saved)
4757                     gnus-saved-mark)
4758                    ((memq number gnus-newsgroup-recent)
4759                     gnus-recent-mark)
4760                    ((memq number gnus-newsgroup-unseen)
4761                     gnus-unseen-mark)
4762                    (t gnus-no-mark))
4763              gnus-tmp-downloaded
4764              (cond ((memq number gnus-newsgroup-undownloaded) 
4765                     gnus-undownloaded-mark)
4766                    (gnus-newsgroup-agentized
4767                     gnus-downloaded-mark)
4768                    (t
4769                     gnus-no-mark))
4770              gnus-tmp-from (mail-header-from gnus-tmp-header)
4771              gnus-tmp-name
4772              (cond
4773               ((string-match "<[^>]+> *$" gnus-tmp-from)
4774                (setq beg-match (match-beginning 0))
4775                (or (and (string-match "^\".+\"" gnus-tmp-from)
4776                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4777                    (substring gnus-tmp-from 0 beg-match)))
4778               ((string-match "(.+)" gnus-tmp-from)
4779                (substring gnus-tmp-from
4780                           (1+ (match-beginning 0)) (1- (match-end 0))))
4781               (t gnus-tmp-from))
4782              gnus-tmp-thread-tree-header-string
4783              (cond
4784               ((not gnus-show-threads) "")
4785               ((zerop gnus-tmp-level)
4786                (if (cdar thread)
4787                    (or gnus-sum-thread-tree-root subject)
4788                  (or gnus-sum-thread-tree-single-indent subject)))
4789               (t
4790                (concat (apply 'concat
4791                               (mapcar (lambda (item)
4792                                         (if (= item 1)
4793                                             gnus-sum-thread-tree-vertical
4794                                           gnus-sum-thread-tree-indent))
4795                                       (cdr (reverse tree-stack))))
4796                        (if (nth 1 thread)
4797                            gnus-sum-thread-tree-leaf-with-other
4798                          gnus-sum-thread-tree-single-leaf)))))
4799             (when (string= gnus-tmp-name "")
4800               (setq gnus-tmp-name gnus-tmp-from))
4801             (unless (numberp gnus-tmp-lines)
4802               (setq gnus-tmp-lines -1))
4803             (if (= gnus-tmp-lines -1)
4804                 (setq gnus-tmp-lines "?")
4805               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4806             (gnus-put-text-property
4807              (point)
4808              (progn (eval gnus-summary-line-format-spec) (point))
4809              'gnus-number number)
4810             (when gnus-visual-p
4811               (forward-line -1)
4812               (gnus-run-hooks 'gnus-summary-update-hook)
4813               (forward-line 1))
4814
4815             (setq gnus-tmp-prev-subject simp-subject)))
4816
4817         (when (nth 1 thread)
4818           (push (list (max 0 gnus-tmp-level)
4819                       (copy-list tree-stack)
4820                       (nthcdr 1 thread))
4821                 stack))
4822         (push (if (nth 1 thread) 1 0) tree-stack)
4823         (incf gnus-tmp-level)
4824         (setq threads (if thread-end nil (cdar thread)))
4825         (if gnus-summary-display-while-building
4826             (if building-count
4827                 (progn
4828                   ;; use a set frequency
4829                   (setq building-line-count (1- building-line-count))
4830                   (when (= building-line-count 0)
4831                     (sit-for 0)
4832                     (setq building-line-count
4833                           gnus-summary-display-while-building)))
4834               ;; always
4835               (sit-for 0)))
4836         (unless threads
4837           (setq gnus-tmp-level 0)))))
4838   (gnus-message 7 "Generating summary...done"))
4839
4840 (defun gnus-summary-prepare-unthreaded (headers)
4841   "Generate an unthreaded summary buffer based on HEADERS."
4842   (let (header number mark)
4843
4844     (beginning-of-line)
4845
4846     (while headers
4847       ;; We may have to root out some bad articles...
4848       (when (memq (setq number (mail-header-number
4849                                 (setq header (pop headers))))
4850                   gnus-newsgroup-limit)
4851         ;; Mark article as read when it has a low score.
4852         (when (and gnus-summary-mark-below
4853                    (< (or (cdr (assq number gnus-newsgroup-scored))
4854                           gnus-summary-default-score 0)
4855                       gnus-summary-mark-below)
4856                    (not (gnus-summary-article-ancient-p number)))
4857           (setq gnus-newsgroup-unreads
4858                 (delq number gnus-newsgroup-unreads))
4859           (if gnus-newsgroup-auto-expire
4860               (push number gnus-newsgroup-expirable)
4861             (push (cons number gnus-low-score-mark)
4862                   gnus-newsgroup-reads)))
4863
4864         (setq mark (gnus-article-mark number))
4865         (push (gnus-data-make number mark (1+ (point)) header 0)
4866               gnus-newsgroup-data)
4867         (gnus-summary-insert-line
4868          header 0 number
4869          (memq number gnus-newsgroup-undownloaded)
4870          mark (memq number gnus-newsgroup-replied)
4871          (memq number gnus-newsgroup-expirable)
4872          (mail-header-subject header) nil
4873          (cdr (assq number gnus-newsgroup-scored))
4874          (memq number gnus-newsgroup-processable))))))
4875
4876 (defun gnus-summary-remove-list-identifiers ()
4877   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4878   (let ((regexp (if (consp gnus-list-identifiers)
4879                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4880                   gnus-list-identifiers))
4881         changed subject)
4882     (when regexp
4883       (dolist (header gnus-newsgroup-headers)
4884         (setq subject (mail-header-subject header)
4885               changed nil)
4886         (while (string-match
4887                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4888                 subject)
4889           (setq subject
4890                 (concat (substring subject 0 (match-beginning 2))
4891                         (substring subject (match-end 0)))
4892                 changed t))
4893         (when (and changed
4894                    (string-match
4895                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4896           (setq subject
4897                 (concat (substring subject 0 (match-beginning 1))
4898                         (substring subject (match-end 1)))))
4899         (when changed
4900           (mail-header-set-subject header subject))))))
4901
4902 (defun gnus-fetch-headers (articles)
4903   "Fetch headers of ARTICLES."
4904   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4905     (gnus-message 5 "Fetching headers for %s..." name)
4906     (prog1
4907         (if (eq 'nov
4908                 (setq gnus-headers-retrieved-by
4909                       (gnus-retrieve-headers
4910                        articles gnus-newsgroup-name
4911                        ;; We might want to fetch old headers, but
4912                        ;; not if there is only 1 article.
4913                        (and (or (and
4914                                  (not (eq gnus-fetch-old-headers 'some))
4915                                  (not (numberp gnus-fetch-old-headers)))
4916                                 (> (length articles) 1))
4917                             gnus-fetch-old-headers))))
4918             (gnus-get-newsgroup-headers-xover
4919              articles nil nil gnus-newsgroup-name t)
4920           (gnus-get-newsgroup-headers))
4921       (gnus-message 5 "Fetching headers for %s...done" name))))
4922
4923 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4924   "Select newsgroup GROUP.
4925 If READ-ALL is non-nil, all articles in the group are selected.
4926 If SELECT-ARTICLES, only select those articles from GROUP."
4927   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4928          ;;!!! Dirty hack; should be removed.
4929          (gnus-summary-ignore-duplicates
4930           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4931               t
4932             gnus-summary-ignore-duplicates))
4933          (info (nth 2 entry))
4934          articles fetched-articles cached)
4935
4936     (unless (gnus-check-server
4937              (set (make-local-variable 'gnus-current-select-method)
4938                   (gnus-find-method-for-group group)))
4939       (error "Couldn't open server"))
4940
4941     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4942         (gnus-activate-group group)     ; Or we can activate it...
4943         (progn                          ; Or we bug out.
4944           (when (equal major-mode 'gnus-summary-mode)
4945             (kill-buffer (current-buffer)))
4946           (error "Couldn't activate group %s: %s"
4947                  group (gnus-status-message group))))
4948
4949     (unless (gnus-request-group group t)
4950       (when (equal major-mode 'gnus-summary-mode)
4951         (kill-buffer (current-buffer)))
4952       (error "Couldn't request group %s: %s"
4953              group (gnus-status-message group)))
4954
4955     (setq gnus-newsgroup-name group
4956           gnus-newsgroup-unselected nil
4957           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4958
4959     (let ((display (gnus-group-find-parameter group 'display)))
4960       (setq gnus-newsgroup-display
4961             (cond
4962              ((not (zerop (or (car-safe read-all) 0)))
4963               ;; The user entered the group with C-u SPC/RET, let's show
4964               ;; all articles.
4965               'gnus-not-ignore)
4966              ((eq display 'all)
4967               'gnus-not-ignore)
4968              ((arrayp display)
4969               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4970              ((numberp display)
4971               ;; The following is probably the "correct" solution, but
4972               ;; it makes Gnus fetch all headers and then limit the
4973               ;; articles (which is slow), so instead we hack the
4974               ;; select-articles parameter instead. -- Simon Josefsson
4975               ;; <jas@kth.se>
4976               ;;
4977               ;; (gnus-byte-compile
4978               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4979               ;;                         display)))))
4980               (setq select-articles
4981                     (gnus-uncompress-range
4982                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4983                              (if (> tmp 0)
4984                                  tmp
4985                                1))
4986                            (cdr (gnus-active group)))))
4987               nil)
4988              (t
4989               nil))))
4990
4991     (gnus-summary-setup-default-charset)
4992
4993     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4994     (when (gnus-virtual-group-p group)
4995       (setq cached gnus-newsgroup-cached))
4996
4997     (setq gnus-newsgroup-unreads
4998           (gnus-sorted-ndifference
4999            (gnus-sorted-ndifference gnus-newsgroup-unreads
5000                                     gnus-newsgroup-marked)
5001            gnus-newsgroup-dormant))
5002
5003     (setq gnus-newsgroup-processable nil)
5004
5005     (gnus-update-read-articles group gnus-newsgroup-unreads)
5006
5007     ;; Adjust and set lists of article marks.
5008     (when info
5009       (gnus-adjust-marked-articles info))
5010     (if (setq articles select-articles)
5011         (setq gnus-newsgroup-unselected
5012               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5013       (setq articles (gnus-articles-to-read group read-all)))
5014
5015     (cond
5016      ((null articles)
5017       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5018       'quit)
5019      ((eq articles 0) nil)
5020      (t
5021       ;; Init the dependencies hash table.
5022       (setq gnus-newsgroup-dependencies
5023             (gnus-make-hashtable (length articles)))
5024       (gnus-set-global-variables)
5025       ;; Retrieve the headers and read them in.
5026
5027       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5028
5029       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5030       (when cached
5031         (setq gnus-newsgroup-cached cached))
5032
5033       ;; Suppress duplicates?
5034       (when gnus-suppress-duplicates
5035         (gnus-dup-suppress-articles))
5036
5037       ;; Set the initial limit.
5038       (setq gnus-newsgroup-limit (copy-sequence articles))
5039       ;; Remove canceled articles from the list of unread articles.
5040       (setq fetched-articles
5041             (mapcar (lambda (headers) (mail-header-number headers))
5042                     gnus-newsgroup-headers))
5043       (setq gnus-newsgroup-articles fetched-articles)
5044       (setq gnus-newsgroup-unreads
5045             (gnus-sorted-nintersection
5046              gnus-newsgroup-unreads fetched-articles))
5047       (gnus-compute-unseen-list)
5048
5049       ;; Removed marked articles that do not exist.
5050       (gnus-update-missing-marks
5051        (gnus-sorted-difference articles fetched-articles))
5052       ;; We might want to build some more threads first.
5053       (when (and gnus-fetch-old-headers
5054                  (eq gnus-headers-retrieved-by 'nov))
5055         (if (eq gnus-fetch-old-headers 'invisible)
5056             (gnus-build-all-threads)
5057           (gnus-build-old-threads)))
5058       ;; Let the Gnus agent mark articles as read.
5059       (when gnus-agent
5060         (gnus-agent-get-undownloaded-list))
5061       ;; Remove list identifiers from subject
5062       (when gnus-list-identifiers
5063         (gnus-summary-remove-list-identifiers))
5064       ;; Check whether auto-expire is to be done in this group.
5065       (setq gnus-newsgroup-auto-expire
5066             (gnus-group-auto-expirable-p group))
5067       ;; Set up the article buffer now, if necessary.
5068       (unless gnus-single-article-buffer
5069         (gnus-article-setup-buffer))
5070       ;; First and last article in this newsgroup.
5071       (when gnus-newsgroup-headers
5072         (setq gnus-newsgroup-begin
5073               (mail-header-number (car gnus-newsgroup-headers))
5074               gnus-newsgroup-end
5075               (mail-header-number
5076                (gnus-last-element gnus-newsgroup-headers))))
5077       ;; GROUP is successfully selected.
5078       (or gnus-newsgroup-headers t)))))
5079
5080 (defun gnus-compute-unseen-list ()
5081   ;; The `seen' marks are treated specially.
5082   (if (not gnus-newsgroup-seen)
5083       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5084     (setq gnus-newsgroup-unseen
5085           (gnus-inverse-list-range-intersection
5086            gnus-newsgroup-articles gnus-newsgroup-seen))))
5087
5088 (defun gnus-summary-display-make-predicate (display)
5089   (require 'gnus-agent)
5090   (when (= (length display) 1)
5091     (setq display (car display)))
5092   (unless gnus-summary-display-cache
5093     (dolist (elem (append '((unread . unread)
5094                             (read . read)
5095                             (unseen . unseen))
5096                           gnus-article-mark-lists))
5097       (push (cons (cdr elem)
5098                   (gnus-byte-compile
5099                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5100             gnus-summary-display-cache)))
5101   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5102         (gnus-category-predicate-cache gnus-summary-display-cache))
5103     (gnus-get-predicate display)))
5104
5105 ;; Uses the dynamically bound `number' variable.
5106 (eval-when-compile
5107   (defvar number))
5108 (defun gnus-article-marked-p (type &optional article)
5109   (let ((article (or article number)))
5110     (cond
5111      ((eq type 'tick)
5112       (memq article gnus-newsgroup-marked))
5113      ((eq type 'spam)
5114       (memq article gnus-newsgroup-spam-marked))
5115      ((eq type 'unsend)
5116       (memq article gnus-newsgroup-unsendable))
5117      ((eq type 'undownload)
5118       (memq article gnus-newsgroup-undownloaded))
5119      ((eq type 'download)
5120       (memq article gnus-newsgroup-downloadable))
5121      ((eq type 'unread)
5122       (memq article gnus-newsgroup-unreads))
5123      ((eq type 'read)
5124       (memq article gnus-newsgroup-reads))
5125      ((eq type 'dormant)
5126       (memq article gnus-newsgroup-dormant) )
5127      ((eq type 'expire)
5128       (memq article gnus-newsgroup-expirable))
5129      ((eq type 'reply)
5130       (memq article gnus-newsgroup-replied))
5131      ((eq type 'killed)
5132       (memq article gnus-newsgroup-killed))
5133      ((eq type 'bookmark)
5134       (assq article gnus-newsgroup-bookmarks))
5135      ((eq type 'score)
5136       (assq article gnus-newsgroup-scored))
5137      ((eq type 'save)
5138       (memq article gnus-newsgroup-saved))
5139      ((eq type 'cache)
5140       (memq article gnus-newsgroup-cached))
5141      ((eq type 'forward)
5142       (memq article gnus-newsgroup-forwarded))
5143      ((eq type 'seen)
5144       (not (memq article gnus-newsgroup-unseen)))
5145      ((eq type 'recent)
5146       (memq article gnus-newsgroup-recent))
5147      (t t))))
5148
5149 (defun gnus-articles-to-read (group &optional read-all)
5150   "Find out what articles the user wants to read."
5151   (let* ((display (gnus-group-find-parameter group 'display))
5152          (articles
5153           ;; Select all articles if `read-all' is non-nil, or if there
5154           ;; are no unread articles.
5155           (if (or read-all
5156                   (and (zerop (length gnus-newsgroup-marked))
5157                        (zerop (length gnus-newsgroup-unreads)))
5158                   ;; Fetch all if the predicate is non-nil.
5159                   gnus-newsgroup-display)
5160               ;; We want to select the headers for all the articles in
5161               ;; the group, so we select either all the active
5162               ;; articles in the group, or (if that's nil), the
5163               ;; articles in the cache.
5164               (or
5165                (gnus-uncompress-range (gnus-active group))
5166                (gnus-cache-articles-in-group group))
5167             ;; Select only the "normal" subset of articles.
5168             (gnus-sorted-nunion
5169              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5170              gnus-newsgroup-unreads)))
5171          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5172          (scored (length scored-list))
5173          (number (length articles))
5174          (marked (+ (length gnus-newsgroup-marked)
5175                     (length gnus-newsgroup-dormant)))
5176          (select
5177           (cond
5178            ((numberp read-all)
5179             read-all)
5180            ((numberp gnus-newsgroup-display)
5181             gnus-newsgroup-display)
5182            (t
5183             (condition-case ()
5184                 (cond
5185                  ((and (or (<= scored marked) (= scored number))
5186                        (numberp gnus-large-newsgroup)
5187                        (> number gnus-large-newsgroup))
5188                   (let* ((cursor-in-echo-area nil)
5189                          (initial (gnus-parameter-large-newsgroup-initial
5190                                    gnus-newsgroup-name))
5191                          (input
5192                           (read-string
5193                            (format
5194                             "How many articles from %s (%s %d): "
5195                             (gnus-limit-string
5196                              (gnus-group-decoded-name gnus-newsgroup-name)
5197                              35)
5198                             (if initial "max" "default")
5199                             number)
5200                            (if initial
5201                                (cons (number-to-string initial)
5202                                      0)))))
5203                     (if (string-match "^[ \t]*$" input) number input)))
5204                  ((and (> scored marked) (< scored number)
5205                        (> (- scored number) 20))
5206                   (let ((input
5207                          (read-string
5208                           (format "%s %s (%d scored, %d total): "
5209                                   "How many articles from"
5210                                   (gnus-group-decoded-name group)
5211                                   scored number))))
5212                     (if (string-match "^[ \t]*$" input)
5213                         number input)))
5214                  (t number))
5215               (quit
5216                (message "Quit getting the articles to read")
5217                nil))))))
5218     (setq select (if (stringp select) (string-to-number select) select))
5219     (if (or (null select) (zerop select))
5220         select
5221       (if (and (not (zerop scored)) (<= (abs select) scored))
5222           (progn
5223             (setq articles (sort scored-list '<))
5224             (setq number (length articles)))
5225         (setq articles (copy-sequence articles)))
5226
5227       (when (< (abs select) number)
5228         (if (< select 0)
5229             ;; Select the N oldest articles.
5230             (setcdr (nthcdr (1- (abs select)) articles) nil)
5231           ;; Select the N most recent articles.
5232           (setq articles (nthcdr (- number select) articles))))
5233       (setq gnus-newsgroup-unselected
5234             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5235       (when gnus-alter-articles-to-read-function
5236         (setq articles
5237               (sort
5238                (funcall gnus-alter-articles-to-read-function
5239                         gnus-newsgroup-name articles)
5240                '<)))
5241       articles)))
5242
5243 (defun gnus-killed-articles (killed articles)
5244   (let (out)
5245     (while articles
5246       (when (inline (gnus-member-of-range (car articles) killed))
5247         (push (car articles) out))
5248       (setq articles (cdr articles)))
5249     out))
5250
5251 (defun gnus-uncompress-marks (marks)
5252   "Uncompress the mark ranges in MARKS."
5253   (let ((uncompressed '(score bookmark))
5254         out)
5255     (while marks
5256       (if (memq (caar marks) uncompressed)
5257           (push (car marks) out)
5258         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5259       (setq marks (cdr marks)))
5260     out))
5261
5262 (defun gnus-article-mark-to-type (mark)
5263   "Return the type of MARK."
5264   (or (cadr (assq mark gnus-article-special-mark-lists))
5265       'list))
5266
5267 (defun gnus-article-unpropagatable-p (mark)
5268   "Return whether MARK should be propagated to backend."
5269   (memq mark gnus-article-unpropagated-mark-lists))
5270
5271 (defun gnus-adjust-marked-articles (info)
5272   "Set all article lists and remove all marks that are no longer valid."
5273   (let* ((marked-lists (gnus-info-marks info))
5274          (active (gnus-active (gnus-info-group info)))
5275          (min (car active))
5276          (max (cdr active))
5277          (types gnus-article-mark-lists)
5278          marks var articles article mark mark-type)
5279
5280     (dolist (marks marked-lists)
5281       (setq mark (car marks)
5282             mark-type (gnus-article-mark-to-type mark)
5283             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5284
5285       ;; We set the variable according to the type of the marks list,
5286       ;; and then adjust the marks to a subset of the active articles.
5287       (cond
5288        ;; Adjust "simple" lists.
5289        ((eq mark-type 'list)
5290         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5291         (when (memq mark '(tick dormant expire reply save))
5292           (while articles
5293             (when (or (< (setq article (pop articles)) min) (> article max))
5294               (set var (delq article (symbol-value var)))))))
5295        ;; Adjust assocs.
5296        ((eq mark-type 'tuple)
5297         (set var (setq articles (cdr marks)))
5298         (when (not (listp (cdr (symbol-value var))))
5299           (set var (list (symbol-value var))))
5300         (when (not (listp (cdr articles)))
5301           (setq articles (list articles)))
5302         (while articles
5303           (when (or (not (consp (setq article (pop articles))))
5304                     (< (car article) min)
5305                     (> (car article) max))
5306             (set var (delq article (symbol-value var))))))
5307        ;; Adjust ranges (sloppily).
5308        ((eq mark-type 'range)
5309         (cond
5310          ((eq mark 'seen)
5311           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5312           ;; It should be (seen (NUM1 . NUM2)).
5313           (when (numberp (cddr marks))
5314             (setcdr marks (list (cdr marks))))
5315           (setq articles (cdr marks))
5316           (while (and articles
5317                       (or (and (consp (car articles))
5318                                (> min (cdar articles)))
5319                           (and (numberp (car articles))
5320                                (> min (car articles)))))
5321             (pop articles))
5322           (set var articles))))))))
5323
5324 (defun gnus-update-missing-marks (missing)
5325   "Go through the list of MISSING articles and remove them from the mark lists."
5326   (when missing
5327     (let (var m)
5328       ;; Go through all types.
5329       (dolist (elem gnus-article-mark-lists)
5330         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5331           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5332           (when (symbol-value var)
5333             ;; This list has articles.  So we delete all missing
5334             ;; articles from it.
5335             (setq m missing)
5336             (while m
5337               (set var (delq (pop m) (symbol-value var))))))))))
5338
5339 (defun gnus-update-marks ()
5340   "Enter the various lists of marked articles into the newsgroup info list."
5341   (let ((types gnus-article-mark-lists)
5342         (info (gnus-get-info gnus-newsgroup-name))
5343         type list newmarked symbol delta-marks)
5344     (when info
5345       ;; Add all marks lists to the list of marks lists.
5346       (while (setq type (pop types))
5347         (setq list (symbol-value
5348                     (setq symbol
5349                           (intern (format "gnus-newsgroup-%s" (car type))))))
5350
5351         (when list
5352           ;; Get rid of the entries of the articles that have the
5353           ;; default score.
5354           (when (and (eq (cdr type) 'score)
5355                      gnus-save-score
5356                      list)
5357             (let* ((arts list)
5358                    (prev (cons nil list))
5359                    (all prev))
5360               (while arts
5361                 (if (or (not (consp (car arts)))
5362                         (= (cdar arts) gnus-summary-default-score))
5363                     (setcdr prev (cdr arts))
5364                   (setq prev arts))
5365                 (setq arts (cdr arts)))
5366               (setq list (cdr all)))))
5367
5368         (when (eq (cdr type) 'seen)
5369           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5370
5371         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5372           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5373
5374         (when (and (gnus-check-backend-function
5375                     'request-set-mark gnus-newsgroup-name)
5376                    (not (gnus-article-unpropagatable-p (cdr type))))
5377           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5378                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5379                  (add (gnus-remove-from-range
5380                        (gnus-copy-sequence list) old)))
5381             (when add
5382               (push (list add 'add (list (cdr type))) delta-marks))
5383             (when del
5384               (push (list del 'del (list (cdr type))) delta-marks))))
5385
5386         (when list
5387           (push (cons (cdr type) list) newmarked)))
5388
5389       (when delta-marks
5390         (unless (gnus-check-group gnus-newsgroup-name)
5391           (error "Can't open server for %s" gnus-newsgroup-name))
5392         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5393
5394       ;; Enter these new marks into the info of the group.
5395       (if (nthcdr 3 info)
5396           (setcar (nthcdr 3 info) newmarked)
5397         ;; Add the marks lists to the end of the info.
5398         (when newmarked
5399           (setcdr (nthcdr 2 info) (list newmarked))))
5400
5401       ;; Cut off the end of the info if there's nothing else there.
5402       (let ((i 5))
5403         (while (and (> i 2)
5404                     (not (nth i info)))
5405           (when (nthcdr (decf i) info)
5406             (setcdr (nthcdr i info) nil)))))))
5407
5408 (defun gnus-set-mode-line (where)
5409   "Set the mode line of the article or summary buffers.
5410 If WHERE is `summary', the summary mode line format will be used."
5411   ;; Is this mode line one we keep updated?
5412   (when (and (memq where gnus-updated-mode-lines)
5413              (symbol-value
5414               (intern (format "gnus-%s-mode-line-format-spec" where))))
5415     (let (mode-string)
5416       (save-excursion
5417         ;; We evaluate this in the summary buffer since these
5418         ;; variables are buffer-local to that buffer.
5419         (set-buffer gnus-summary-buffer)
5420         ;; We bind all these variables that are used in the `eval' form
5421         ;; below.
5422         (let* ((mformat (symbol-value
5423                          (intern
5424                           (format "gnus-%s-mode-line-format-spec" where))))
5425                (gnus-tmp-group-name (gnus-group-decoded-name
5426                                      gnus-newsgroup-name))
5427                (gnus-tmp-article-number (or gnus-current-article 0))
5428                (gnus-tmp-unread gnus-newsgroup-unreads)
5429                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5430                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5431                (gnus-tmp-unread-and-unselected
5432                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5433                             (zerop gnus-tmp-unselected))
5434                        "")
5435                       ((zerop gnus-tmp-unselected)
5436                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5437                       (t (format "{%d(+%d) more}"
5438                                  gnus-tmp-unread-and-unticked
5439                                  gnus-tmp-unselected))))
5440                (gnus-tmp-subject
5441                 (if (and gnus-current-headers
5442                          (vectorp gnus-current-headers))
5443                     (gnus-mode-string-quote
5444                      (mail-header-subject gnus-current-headers))
5445                   ""))
5446                bufname-length max-len
5447                gnus-tmp-header);; passed as argument to any user-format-funcs
5448           (setq mode-string (eval mformat))
5449           (setq bufname-length (if (string-match "%b" mode-string)
5450                                    (- (length
5451                                        (buffer-name
5452                                         (if (eq where 'summary)
5453                                             nil
5454                                           (get-buffer gnus-article-buffer))))
5455                                       2)
5456                                  0))
5457           (setq max-len (max 4 (if gnus-mode-non-string-length
5458                                    (- (window-width)
5459                                       gnus-mode-non-string-length
5460                                       bufname-length)
5461                                  (length mode-string))))
5462           ;; We might have to chop a bit of the string off...
5463           (when (> (length mode-string) max-len)
5464             (setq mode-string
5465                   (concat (gnus-truncate-string mode-string (- max-len 3))
5466                           "...")))
5467           ;; Pad the mode string a bit.
5468           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5469       ;; Update the mode line.
5470       (setq mode-line-buffer-identification
5471             (gnus-mode-line-buffer-identification (list mode-string)))
5472       (set-buffer-modified-p t))))
5473
5474 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5475   "Go through the HEADERS list and add all Xrefs to a hash table.
5476 The resulting hash table is returned, or nil if no Xrefs were found."
5477   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5478          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5479          (xref-hashtb (gnus-make-hashtable))
5480          start group entry number xrefs header)
5481     (while headers
5482       (setq header (pop headers))
5483       (when (and (setq xrefs (mail-header-xref header))
5484                  (not (memq (setq number (mail-header-number header))
5485                             unreads)))
5486         (setq start 0)
5487         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5488           (setq start (match-end 0))
5489           (setq group (if prefix
5490                           (concat prefix (substring xrefs (match-beginning 1)
5491                                                     (match-end 1)))
5492                         (substring xrefs (match-beginning 1) (match-end 1))))
5493           (setq number
5494                 (string-to-int (substring xrefs (match-beginning 2)
5495                                           (match-end 2))))
5496           (if (setq entry (gnus-gethash group xref-hashtb))
5497               (setcdr entry (cons number (cdr entry)))
5498             (gnus-sethash group (cons number nil) xref-hashtb)))))
5499     (and start xref-hashtb)))
5500
5501 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5502   "Look through all the headers and mark the Xrefs as read."
5503   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5504         name entry info xref-hashtb idlist method nth4)
5505     (save-excursion
5506       (set-buffer gnus-group-buffer)
5507       (when (setq xref-hashtb
5508                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5509         (mapatoms
5510          (lambda (group)
5511            (unless (string= from-newsgroup (setq name (symbol-name group)))
5512              (setq idlist (symbol-value group))
5513              ;; Dead groups are not updated.
5514              (and (prog1
5515                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5516                             info (nth 2 entry))
5517                     (when (stringp (setq nth4 (gnus-info-method info)))
5518                       (setq nth4 (gnus-server-to-method nth4))))
5519                   ;; Only do the xrefs if the group has the same
5520                   ;; select method as the group we have just read.
5521                   (or (gnus-methods-equal-p
5522                        nth4 (gnus-find-method-for-group from-newsgroup))
5523                       virtual
5524                       (equal nth4 (setq method (gnus-find-method-for-group
5525                                                 from-newsgroup)))
5526                       (and (equal (car nth4) (car method))
5527                            (equal (nth 1 nth4) (nth 1 method))))
5528                   gnus-use-cross-reference
5529                   (or (not (eq gnus-use-cross-reference t))
5530                       virtual
5531                       ;; Only do cross-references on subscribed
5532                       ;; groups, if that is what is wanted.
5533                       (<= (gnus-info-level info) gnus-level-subscribed))
5534                   (gnus-group-make-articles-read name idlist))))
5535          xref-hashtb)))))
5536
5537 (defun gnus-compute-read-articles (group articles)
5538   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5539          (info (nth 2 entry))
5540          (active (gnus-active group))
5541          ninfo)
5542     (when entry
5543       ;; First peel off all invalid article numbers.
5544       (when active
5545         (let ((ids articles)
5546               id first)
5547           (while (setq id (pop ids))
5548             (when (and first (> id (cdr active)))
5549               ;; We'll end up in this situation in one particular
5550               ;; obscure situation.  If you re-scan a group and get
5551               ;; a new article that is cross-posted to a different
5552               ;; group that has not been re-scanned, you might get
5553               ;; crossposted article that has a higher number than
5554               ;; Gnus believes possible.  So we re-activate this
5555               ;; group as well.  This might mean doing the
5556               ;; crossposting thingy will *increase* the number
5557               ;; of articles in some groups.  Tsk, tsk.
5558               (setq active (or (gnus-activate-group group) active)))
5559             (when (or (> id (cdr active))
5560                       (< id (car active)))
5561               (setq articles (delq id articles))))))
5562       ;; If the read list is nil, we init it.
5563       (if (and active
5564                (null (gnus-info-read info))
5565                (> (car active) 1))
5566           (setq ninfo (cons 1 (1- (car active))))
5567         (setq ninfo (gnus-info-read info)))
5568       ;; Then we add the read articles to the range.
5569       (gnus-add-to-range
5570        ninfo (setq articles (sort articles '<))))))
5571
5572 (defun gnus-group-make-articles-read (group articles)
5573   "Update the info of GROUP to say that ARTICLES are read."
5574   (let* ((num 0)
5575          (entry (gnus-gethash group gnus-newsrc-hashtb))
5576          (info (nth 2 entry))
5577          (active (gnus-active group))
5578          range)
5579     (when entry
5580       (setq range (gnus-compute-read-articles group articles))
5581       (save-excursion
5582         (set-buffer gnus-group-buffer)
5583         (gnus-undo-register
5584           `(progn
5585              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5586              (gnus-info-set-read ',info ',(gnus-info-read info))
5587              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5588              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5589              (gnus-group-update-group ,group t))))
5590       ;; Add the read articles to the range.
5591       (gnus-info-set-read info range)
5592       (gnus-request-set-mark group (list (list range 'add '(read))))
5593       ;; Then we have to re-compute how many unread
5594       ;; articles there are in this group.
5595       (when active
5596         (cond
5597          ((not range)
5598           (setq num (- (1+ (cdr active)) (car active))))
5599          ((not (listp (cdr range)))
5600           (setq num (- (cdr active) (- (1+ (cdr range))
5601                                        (car range)))))
5602          (t
5603           (while range
5604             (if (numberp (car range))
5605                 (setq num (1+ num))
5606               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5607             (setq range (cdr range)))
5608           (setq num (- (cdr active) num))))
5609         ;; Update the number of unread articles.
5610         (setcar entry num)
5611         ;; Update the group buffer.
5612         (unless (gnus-ephemeral-group-p group)
5613           (gnus-group-update-group group t))))))
5614
5615 (defvar gnus-newsgroup-none-id 0)
5616
5617 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5618   (let ((cur nntp-server-buffer)
5619         (dependencies
5620          (or dependencies
5621              (save-excursion (set-buffer gnus-summary-buffer)
5622                              gnus-newsgroup-dependencies)))
5623         headers id end ref
5624         (mail-parse-charset gnus-newsgroup-charset)
5625         (mail-parse-ignored-charsets
5626          (save-excursion (condition-case nil
5627                              (set-buffer gnus-summary-buffer)
5628                            (error))
5629                          gnus-newsgroup-ignored-charsets)))
5630     (save-excursion
5631       (set-buffer nntp-server-buffer)
5632       ;; Translate all TAB characters into SPACE characters.
5633       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5634       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5635       (gnus-run-hooks 'gnus-parse-headers-hook)
5636       (let ((case-fold-search t)
5637             in-reply-to header p lines chars ctype)
5638         (goto-char (point-min))
5639         ;; Search to the beginning of the next header.  Error messages
5640         ;; do not begin with 2 or 3.
5641         (while (re-search-forward "^[23][0-9]+ " nil t)
5642           (setq id nil
5643                 ref nil)
5644           ;; This implementation of this function, with nine
5645           ;; search-forwards instead of the one re-search-forward and
5646           ;; a case (which basically was the old function) is actually
5647           ;; about twice as fast, even though it looks messier.  You
5648           ;; can't have everything, I guess.  Speed and elegance
5649           ;; doesn't always go hand in hand.
5650           (setq
5651            header
5652            (make-full-mail-header
5653             ;; Number.
5654             (prog1
5655                 (read cur)
5656               (end-of-line)
5657               (setq p (point))
5658               (narrow-to-region (point)
5659                                 (or (and (search-forward "\n.\n" nil t)
5660                                          (- (point) 2))
5661                                     (point))))
5662             ;; Subject.
5663             (progn
5664               (goto-char p)
5665               (if (search-forward "\nsubject:" nil t)
5666                   (nnheader-header-value)
5667                 "(none)"))
5668             ;; From.
5669             (progn
5670               (goto-char p)
5671               (if (search-forward "\nfrom:" nil t)
5672                   (nnheader-header-value)
5673                 "(nobody)"))
5674             ;; Date.
5675             (progn
5676               (goto-char p)
5677               (if (search-forward "\ndate:" nil t)
5678                   (nnheader-header-value) ""))
5679             ;; Message-ID.
5680             (progn
5681               (goto-char p)
5682               (setq id (if (re-search-forward
5683                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5684                            ;; We do it this way to make sure the Message-ID
5685                            ;; is (somewhat) syntactically valid.
5686                            (buffer-substring (match-beginning 1)
5687                                              (match-end 1))
5688                          ;; If there was no message-id, we just fake one
5689                          ;; to make subsequent routines simpler.
5690                          (nnheader-generate-fake-message-id))))
5691             ;; References.
5692             (progn
5693               (goto-char p)
5694               (if (search-forward "\nreferences:" nil t)
5695                   (progn
5696                     (setq end (point))
5697                     (prog1
5698                         (nnheader-header-value)
5699                       (setq ref
5700                             (buffer-substring
5701                              (progn
5702                                ;; (end-of-line)
5703                                (search-backward ">" end t)
5704                                (1+ (point)))
5705                              (progn
5706                                (search-backward "<" end t)
5707                                (point))))))
5708                 ;; Get the references from the in-reply-to header if there
5709                 ;; were no references and the in-reply-to header looks
5710                 ;; promising.
5711                 (if (and (search-forward "\nin-reply-to:" nil t)
5712                          (setq in-reply-to (nnheader-header-value))
5713                          (string-match "<[^>]+>" in-reply-to))
5714                     (let (ref2)
5715                       (setq ref (substring in-reply-to (match-beginning 0)
5716                                            (match-end 0)))
5717                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5718                         (setq ref2 (substring in-reply-to (match-beginning 0)
5719                                               (match-end 0)))
5720                         (when (> (length ref2) (length ref))
5721                           (setq ref ref2)))
5722                       ref)
5723                   (setq ref nil))))
5724             ;; Chars.
5725             (progn
5726               (goto-char p)
5727               (if (search-forward "\nchars: " nil t)
5728                   (if (numberp (setq chars (ignore-errors (read cur))))
5729                       chars -1)
5730                 -1))
5731             ;; Lines.
5732             (progn
5733               (goto-char p)
5734               (if (search-forward "\nlines: " nil t)
5735                   (if (numberp (setq lines (ignore-errors (read cur))))
5736                       lines -1)
5737                 -1))
5738             ;; Xref.
5739             (progn
5740               (goto-char p)
5741               (and (search-forward "\nxref:" nil t)
5742                    (nnheader-header-value)))
5743             ;; Extra.
5744             (when gnus-extra-headers
5745               (let ((extra gnus-extra-headers)
5746                     out)
5747                 (while extra
5748                   (goto-char p)
5749                   (when (search-forward
5750                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5751                     (push (cons (car extra) (nnheader-header-value)) out))
5752                   (pop extra))
5753                 out))))
5754           (goto-char p)
5755           (if (and (search-forward "\ncontent-type: " nil t)
5756                    (setq ctype (nnheader-header-value)))
5757               (mime-entity-set-content-type-internal
5758                header (mime-parse-Content-Type ctype)))
5759           (when (equal id ref)
5760             (setq ref nil))
5761
5762           (when gnus-alter-header-function
5763             (funcall gnus-alter-header-function header)
5764             (setq id (mail-header-id header)
5765                   ref (gnus-parent-id (mail-header-references header))))
5766
5767           (when (setq header
5768                       (gnus-dependencies-add-header
5769                        header dependencies force-new))
5770             (push header headers))
5771           (goto-char (point-max))
5772           (widen))
5773         (nreverse headers)))))
5774
5775 ;; Goes through the xover lines and returns a list of vectors
5776 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5777                                                   force-new dependencies
5778                                                   group also-fetch-heads)
5779   "Parse the news overview data in the server buffer.
5780 Return a list of headers that match SEQUENCE (see
5781 `nntp-retrieve-headers')."
5782   ;; Get the Xref when the users reads the articles since most/some
5783   ;; NNTP servers do not include Xrefs when using XOVER.
5784   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5785   (let ((mail-parse-charset gnus-newsgroup-charset)
5786         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5787         (cur nntp-server-buffer)
5788         (dependencies (or dependencies gnus-newsgroup-dependencies))
5789         (allp (cond
5790                ((eq gnus-read-all-available-headers t)
5791                 t)
5792                ((stringp gnus-read-all-available-headers)
5793                 (string-match gnus-read-all-available-headers group))
5794                (t
5795                 nil)))
5796         number headers header)
5797     (save-excursion
5798       (set-buffer nntp-server-buffer)
5799       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5800       ;; Allow the user to mangle the headers before parsing them.
5801       (gnus-run-hooks 'gnus-parse-headers-hook)
5802       (goto-char (point-min))
5803       (gnus-parse-without-error
5804         (while (and (or sequence allp)
5805                     (not (eobp)))
5806           (setq number (read cur))
5807           (when (not allp)
5808             (while (and sequence
5809                         (< (car sequence) number))
5810               (setq sequence (cdr sequence))))
5811           (when (and (or allp
5812                          (and sequence
5813                               (eq number (car sequence))))
5814                      (progn
5815                        (setq sequence (cdr sequence))
5816                        (setq header (inline
5817                                       (gnus-nov-parse-line
5818                                        number dependencies force-new)))))
5819             (push header headers))
5820           (forward-line 1)))
5821       ;; A common bug in inn is that if you have posted an article and
5822       ;; then retrieves the active file, it will answer correctly --
5823       ;; the new article is included.  However, a NOV entry for the
5824       ;; article may not have been generated yet, so this may fail.
5825       ;; We work around this problem by retrieving the last few
5826       ;; headers using HEAD.
5827       (if (or (not also-fetch-heads)
5828               (not sequence))
5829           ;; We (probably) got all the headers.
5830           (nreverse headers)
5831         (let ((gnus-nov-is-evil t))
5832           (nconc
5833            (nreverse headers)
5834            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5835              (gnus-get-newsgroup-headers))))))))
5836
5837 (defun gnus-article-get-xrefs ()
5838   "Fill in the Xref value in `gnus-current-headers', if necessary.
5839 This is meant to be called in `gnus-article-internal-prepare-hook'."
5840   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5841                                  gnus-current-headers)))
5842     (or (not gnus-use-cross-reference)
5843         (not headers)
5844         (and (mail-header-xref headers)
5845              (not (string= (mail-header-xref headers) "")))
5846         (let ((case-fold-search t)
5847               xref)
5848           (save-restriction
5849             (nnheader-narrow-to-headers)
5850             (goto-char (point-min))
5851             (when (or (and (not (eobp))
5852                            (eq (downcase (char-after)) ?x)
5853                            (looking-at "Xref:"))
5854                       (search-forward "\nXref:" nil t))
5855               (goto-char (1+ (match-end 0)))
5856               (setq xref (buffer-substring (point)
5857                                            (progn (end-of-line) (point))))
5858               (mail-header-set-xref headers xref)))))))
5859
5860 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5861   "Find article ID and insert the summary line for that article.
5862 OLD-HEADER can either be a header or a line number to insert
5863 the subject line on."
5864   (let* ((line (and (numberp old-header) old-header))
5865          (old-header (and (vectorp old-header) old-header))
5866          (header (cond ((and old-header use-old-header)
5867                         old-header)
5868                        ((and (numberp id)
5869                              (gnus-number-to-header id))
5870                         (gnus-number-to-header id))
5871                        (t
5872                         (gnus-read-header id))))
5873          (number (and (numberp id) id))
5874          d)
5875     (when header
5876       ;; Rebuild the thread that this article is part of and go to the
5877       ;; article we have fetched.
5878       (when (and (not gnus-show-threads)
5879                  old-header)
5880         (when (and number
5881                    (setq d (gnus-data-find (mail-header-number old-header))))
5882           (goto-char (gnus-data-pos d))
5883           (gnus-data-remove
5884            number
5885            (- (gnus-point-at-bol)
5886               (prog1
5887                   (1+ (gnus-point-at-eol))
5888                 (gnus-delete-line))))))
5889       (when old-header
5890         (mail-header-set-number header (mail-header-number old-header)))
5891       (setq gnus-newsgroup-sparse
5892             (delq (setq number (mail-header-number header))
5893                   gnus-newsgroup-sparse))
5894       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5895       (push number gnus-newsgroup-limit)
5896       (gnus-rebuild-thread (mail-header-id header) line)
5897       (gnus-summary-goto-subject number nil t))
5898     (when (and (numberp number)
5899                (> number 0))
5900       ;; We have to update the boundaries even if we can't fetch the
5901       ;; article if ID is a number -- so that the next `P' or `N'
5902       ;; command will fetch the previous (or next) article even
5903       ;; if the one we tried to fetch this time has been canceled.
5904       (when (> number gnus-newsgroup-end)
5905         (setq gnus-newsgroup-end number))
5906       (when (< number gnus-newsgroup-begin)
5907         (setq gnus-newsgroup-begin number))
5908       (setq gnus-newsgroup-unselected
5909             (delq number gnus-newsgroup-unselected)))
5910     ;; Report back a success?
5911     (and header (mail-header-number header))))
5912
5913 ;;; Process/prefix in the summary buffer
5914
5915 (defun gnus-summary-work-articles (n)
5916   "Return a list of articles to be worked upon.
5917 The prefix argument, the list of process marked articles, and the
5918 current article will be taken into consideration."
5919   (save-excursion
5920     (set-buffer gnus-summary-buffer)
5921     (cond
5922      (n
5923       ;; A numerical prefix has been given.
5924       (setq n (prefix-numeric-value n))
5925       (let ((backward (< n 0))
5926             (n (abs (prefix-numeric-value n)))
5927             articles article)
5928         (save-excursion
5929           (while
5930               (and (> n 0)
5931                    (push (setq article (gnus-summary-article-number))
5932                          articles)
5933                    (if backward
5934                        (gnus-summary-find-prev nil article)
5935                      (gnus-summary-find-next nil article)))
5936             (decf n)))
5937         (nreverse articles)))
5938      ((and (gnus-region-active-p) (mark))
5939       (message "region active")
5940       ;; Work on the region between point and mark.
5941       (let ((max (max (point) (mark)))
5942             articles article)
5943         (save-excursion
5944           (goto-char (min (point) (mark)))
5945           (while
5946               (and
5947                (push (setq article (gnus-summary-article-number)) articles)
5948                (gnus-summary-find-next nil article)
5949                (< (point) max)))
5950           (nreverse articles))))
5951      (gnus-newsgroup-processable
5952       ;; There are process-marked articles present.
5953       ;; Save current state.
5954       (gnus-summary-save-process-mark)
5955       ;; Return the list.
5956       (reverse gnus-newsgroup-processable))
5957      (t
5958       ;; Just return the current article.
5959       (list (gnus-summary-article-number))))))
5960
5961 (defmacro gnus-summary-iterate (arg &rest forms)
5962   "Iterate over the process/prefixed articles and do FORMS.
5963 ARG is the interactive prefix given to the command.  FORMS will be
5964 executed with point over the summary line of the articles."
5965   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5966     `(let ((,articles (gnus-summary-work-articles ,arg)))
5967        (while ,articles
5968          (gnus-summary-goto-subject (car ,articles))
5969          ,@forms
5970          (pop ,articles)))))
5971
5972 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5973 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5974
5975 (defun gnus-summary-save-process-mark ()
5976   "Push the current set of process marked articles on the stack."
5977   (interactive)
5978   (push (copy-sequence gnus-newsgroup-processable)
5979         gnus-newsgroup-process-stack))
5980
5981 (defun gnus-summary-kill-process-mark ()
5982   "Push the current set of process marked articles on the stack and unmark."
5983   (interactive)
5984   (gnus-summary-save-process-mark)
5985   (gnus-summary-unmark-all-processable))
5986
5987 (defun gnus-summary-yank-process-mark ()
5988   "Pop the last process mark state off the stack and restore it."
5989   (interactive)
5990   (unless gnus-newsgroup-process-stack
5991     (error "Empty mark stack"))
5992   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5993
5994 (defun gnus-summary-process-mark-set (set)
5995   "Make SET into the current process marked articles."
5996   (gnus-summary-unmark-all-processable)
5997   (while set
5998     (gnus-summary-set-process-mark (pop set))))
5999
6000 ;;; Searching and stuff
6001
6002 (defun gnus-summary-search-group (&optional backward use-level)
6003   "Search for next unread newsgroup.
6004 If optional argument BACKWARD is non-nil, search backward instead."
6005   (save-excursion
6006     (set-buffer gnus-group-buffer)
6007     (when (gnus-group-search-forward
6008            backward nil (if use-level (gnus-group-group-level) nil))
6009       (gnus-group-group-name))))
6010
6011 (defun gnus-summary-best-group (&optional exclude-group)
6012   "Find the name of the best unread group.
6013 If EXCLUDE-GROUP, do not go to this group."
6014   (save-excursion
6015     (set-buffer gnus-group-buffer)
6016     (save-excursion
6017       (gnus-group-best-unread-group exclude-group))))
6018
6019 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
6020   (if backward (gnus-summary-find-prev)
6021     (let* ((dummy (gnus-summary-article-intangible-p))
6022            (article (or article (gnus-summary-article-number)))
6023            (arts (gnus-data-find-list article))
6024            result)
6025       (when (and (not dummy)
6026                  (or (not gnus-summary-check-current)
6027                      (not unread)
6028                      (not (gnus-data-unread-p (car arts)))))
6029         (setq arts (cdr arts)))
6030       (when (setq result
6031                   (if unread
6032                       (progn
6033                         (while arts
6034                           (when (or (and undownloaded
6035                                          (memq (car arts)
6036                                                gnus-newsgroup-undownloaded))
6037                                     (gnus-data-unread-p (car arts)))
6038                             (setq result (car arts)
6039                                   arts nil))
6040                           (setq arts (cdr arts)))
6041                         result)
6042                     (car arts)))
6043         (goto-char (gnus-data-pos result))
6044         (gnus-data-number result)))))
6045
6046 (defun gnus-summary-find-prev (&optional unread article)
6047   (let* ((eobp (eobp))
6048          (article (or article (gnus-summary-article-number)))
6049          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
6050          result)
6051     (when (and (not eobp)
6052                (or (not gnus-summary-check-current)
6053                    (not unread)
6054                    (not (gnus-data-unread-p (car arts)))))
6055       (setq arts (cdr arts)))
6056     (when (setq result
6057                 (if unread
6058                     (progn
6059                       (while arts
6060                         (when (gnus-data-unread-p (car arts))
6061                           (setq result (car arts)
6062                                 arts nil))
6063                         (setq arts (cdr arts)))
6064                       result)
6065                   (car arts)))
6066       (goto-char (gnus-data-pos result))
6067       (gnus-data-number result))))
6068
6069 (defun gnus-summary-find-subject (subject &optional unread backward article)
6070   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6071          (article (or article (gnus-summary-article-number)))
6072          (articles (gnus-data-list backward))
6073          (arts (gnus-data-find-list article articles))
6074          result)
6075     (when (or (not gnus-summary-check-current)
6076               (not unread)
6077               (not (gnus-data-unread-p (car arts))))
6078       (setq arts (cdr arts)))
6079     (while arts
6080       (and (or (not unread)
6081                (gnus-data-unread-p (car arts)))
6082            (vectorp (gnus-data-header (car arts)))
6083            (gnus-subject-equal
6084             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6085            (setq result (car arts)
6086                  arts nil))
6087       (setq arts (cdr arts)))
6088     (and result
6089          (goto-char (gnus-data-pos result))
6090          (gnus-data-number result))))
6091
6092 (defun gnus-summary-search-forward (&optional unread subject backward)
6093   "Search forward for an article.
6094 If UNREAD, look for unread articles.  If SUBJECT, look for
6095 articles with that subject.  If BACKWARD, search backward instead."
6096   (cond (subject (gnus-summary-find-subject subject unread backward))
6097         (backward (gnus-summary-find-prev unread))
6098         (t (gnus-summary-find-next unread))))
6099
6100 (defun gnus-recenter (&optional n)
6101   "Center point in window and redisplay frame.
6102 Also do horizontal recentering."
6103   (interactive "P")
6104   (when (and gnus-auto-center-summary
6105              (not (eq gnus-auto-center-summary 'vertical)))
6106     (gnus-horizontal-recenter))
6107   (recenter n))
6108
6109 (defun gnus-summary-recenter ()
6110   "Center point in the summary window.
6111 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6112 displayed, no centering will be performed."
6113   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6114   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6115   (interactive)
6116   (let* ((top (cond ((< (window-height) 4) 0)
6117                     ((< (window-height) 7) 1)
6118                     (t (if (numberp gnus-auto-center-summary)
6119                            gnus-auto-center-summary
6120                          2))))
6121          (height (1- (window-height)))
6122          (bottom (save-excursion (goto-char (point-max))
6123                                  (forward-line (- height))
6124                                  (point)))
6125          (window (get-buffer-window (current-buffer))))
6126     ;; The user has to want it.
6127     (when gnus-auto-center-summary
6128       (when (get-buffer-window gnus-article-buffer)
6129         ;; Only do recentering when the article buffer is displayed,
6130         ;; Set the window start to either `bottom', which is the biggest
6131         ;; possible valid number, or the second line from the top,
6132         ;; whichever is the least.
6133         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6134           (if (> bottom top-pos)
6135               ;; Keep the second line from the top visible
6136               (set-window-start window top-pos t)
6137             ;; Try to keep the bottom line visible; if it's partially
6138             ;; obscured, either scroll one more line to make it fully
6139             ;; visible, or revert to using TOP-POS.
6140             (save-excursion
6141               (goto-char (point-max))
6142               (forward-line -1)
6143               (let ((last-line-start (point)))
6144                 (goto-char bottom)
6145                 (set-window-start window (point) t)
6146                 (when (not (pos-visible-in-window-p last-line-start window))
6147                   (forward-line 1)
6148                   (set-window-start window (min (point) top-pos) t)))))))
6149       ;; Do horizontal recentering while we're at it.
6150       (when (and (get-buffer-window (current-buffer) t)
6151                  (not (eq gnus-auto-center-summary 'vertical)))
6152         (let ((selected (selected-window)))
6153           (select-window (get-buffer-window (current-buffer) t))
6154           (gnus-summary-position-point)
6155           (gnus-horizontal-recenter)
6156           (select-window selected))))))
6157
6158 (defun gnus-summary-jump-to-group (newsgroup)
6159   "Move point to NEWSGROUP in group mode buffer."
6160   ;; Keep update point of group mode buffer if visible.
6161   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6162       (save-window-excursion
6163         ;; Take care of tree window mode.
6164         (when (get-buffer-window gnus-group-buffer)
6165           (pop-to-buffer gnus-group-buffer))
6166         (gnus-group-jump-to-group newsgroup))
6167     (save-excursion
6168       ;; Take care of tree window mode.
6169       (if (get-buffer-window gnus-group-buffer)
6170           (pop-to-buffer gnus-group-buffer)
6171         (set-buffer gnus-group-buffer))
6172       (gnus-group-jump-to-group newsgroup))))
6173
6174 ;; This function returns a list of article numbers based on the
6175 ;; difference between the ranges of read articles in this group and
6176 ;; the range of active articles.
6177 (defun gnus-list-of-unread-articles (group)
6178   (let* ((read (gnus-info-read (gnus-get-info group)))
6179          (active (or (gnus-active group) (gnus-activate-group group)))
6180          (last (cdr active))
6181          first nlast unread)
6182     ;; If none are read, then all are unread.
6183     (if (not read)
6184         (setq first (car active))
6185       ;; If the range of read articles is a single range, then the
6186       ;; first unread article is the article after the last read
6187       ;; article.  Sounds logical, doesn't it?
6188       (if (and (not (listp (cdr read)))
6189                (or (< (car read) (car active))
6190                    (progn (setq read (list read))
6191                           nil)))
6192           (setq first (max (car active) (1+ (cdr read))))
6193         ;; `read' is a list of ranges.
6194         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6195                                   (caar read)))
6196                   1)
6197           (setq first (car active)))
6198         (while read
6199           (when first
6200             (while (< first nlast)
6201               (push first unread)
6202               (setq first (1+ first))))
6203           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6204           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6205           (setq read (cdr read)))))
6206     ;; And add the last unread articles.
6207     (while (<= first last)
6208       (push first unread)
6209       (setq first (1+ first)))
6210     ;; Return the list of unread articles.
6211     (delq 0 (nreverse unread))))
6212
6213 (defun gnus-list-of-read-articles (group)
6214   "Return a list of unread, unticked and non-dormant articles."
6215   (let* ((info (gnus-get-info group))
6216          (marked (gnus-info-marks info))
6217          (active (gnus-active group)))
6218     (and info active
6219          (gnus-list-range-difference
6220           (gnus-list-range-difference
6221            (gnus-sorted-complement
6222             (gnus-uncompress-range active)
6223             (gnus-list-of-unread-articles group))
6224            (cdr (assq 'dormant marked)))
6225           (cdr (assq 'tick marked))))))
6226
6227 ;; Various summary commands
6228
6229 (defun gnus-summary-select-article-buffer ()
6230   "Reconfigure windows to show article buffer."
6231   (interactive)
6232   (if (not (gnus-buffer-live-p gnus-article-buffer))
6233       (error "There is no article buffer for this summary buffer")
6234     (gnus-configure-windows 'article)
6235     (select-window (get-buffer-window gnus-article-buffer))))
6236
6237 (defun gnus-summary-universal-argument (arg)
6238   "Perform any operation on all articles that are process/prefixed."
6239   (interactive "P")
6240   (let ((articles (gnus-summary-work-articles arg))
6241         func article)
6242     (if (eq
6243          (setq
6244           func
6245           (key-binding
6246            (read-key-sequence
6247             (substitute-command-keys
6248              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6249          'undefined)
6250         (gnus-error 1 "Undefined key")
6251       (save-excursion
6252         (while articles
6253           (gnus-summary-goto-subject (setq article (pop articles)))
6254           (let (gnus-newsgroup-processable)
6255             (command-execute func))
6256           (gnus-summary-remove-process-mark article)))))
6257   (gnus-summary-position-point))
6258
6259 (defun gnus-summary-toggle-truncation (&optional arg)
6260   "Toggle truncation of summary lines.
6261 With arg, turn line truncation on if arg is positive."
6262   (interactive "P")
6263   (setq truncate-lines
6264         (if (null arg) (not truncate-lines)
6265           (> (prefix-numeric-value arg) 0)))
6266   (redraw-display))
6267
6268 (defun gnus-summary-find-uncancelled ()
6269   "Return the number of an uncancelled article.
6270 The current article is considered, then following articles, then previous
6271 articles.  If all articles are cancelled then return a dummy 0."
6272   (let (found)
6273     (dolist (rev '(nil t))
6274       (unless found      ; don't demand the reverse list if we don't need it
6275         (let ((data (gnus-data-find-list
6276                      (gnus-summary-article-number) (gnus-data-list rev))))
6277           (while (and data (not found))
6278             (if (not (eq gnus-canceled-mark (gnus-data-mark (car data))))
6279                 (setq found (gnus-data-number (car data))))
6280             (setq data (cdr data))))))
6281     (or found 0)))
6282
6283 (defun gnus-summary-reselect-current-group (&optional all rescan)
6284   "Exit and then reselect the current newsgroup.
6285 The prefix argument ALL means to select all articles."
6286   (interactive "P")
6287   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6288     (error "Ephemeral groups can't be reselected"))
6289   (let ((current-subject (gnus-summary-find-uncancelled))
6290         (group gnus-newsgroup-name))
6291     (setq gnus-newsgroup-begin nil)
6292     (gnus-summary-exit)
6293     ;; We have to adjust the point of group mode buffer because
6294     ;; point was moved to the next unread newsgroup by exiting.
6295     (gnus-summary-jump-to-group group)
6296     (when rescan
6297       (save-excursion
6298         (save-window-excursion
6299           ;; Don't show group contents.
6300           (set-window-start (selected-window) (point-max))
6301           (gnus-group-get-new-news-this-group 1))))
6302     (gnus-group-read-group all t)
6303     (gnus-summary-goto-subject current-subject nil t)))
6304
6305 (defun gnus-summary-rescan-group (&optional all)
6306   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6307   (interactive "P")
6308   (gnus-summary-reselect-current-group all t))
6309
6310 (defun gnus-summary-update-info (&optional non-destructive)
6311   (save-excursion
6312     (let ((group gnus-newsgroup-name))
6313       (when group
6314         (when gnus-newsgroup-kill-headers
6315           (setq gnus-newsgroup-killed
6316                 (gnus-compress-sequence
6317                  (gnus-sorted-union
6318                   (gnus-list-range-intersection
6319                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6320                   gnus-newsgroup-unreads)
6321                  t)))
6322         (unless (listp (cdr gnus-newsgroup-killed))
6323           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6324         (let ((headers gnus-newsgroup-headers))
6325           ;; Set the new ranges of read articles.
6326           (save-excursion
6327             (set-buffer gnus-group-buffer)
6328             (gnus-undo-force-boundary))
6329           (gnus-update-read-articles
6330            group (gnus-sorted-union
6331                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6332           ;; Set the current article marks.
6333           (let ((gnus-newsgroup-scored
6334                  (if (and (not gnus-save-score)
6335                           (not non-destructive))
6336                      nil
6337                    gnus-newsgroup-scored)))
6338             (save-excursion
6339               (gnus-update-marks)))
6340           ;; Do the cross-ref thing.
6341           (when gnus-use-cross-reference
6342             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6343           ;; Do not switch windows but change the buffer to work.
6344           (set-buffer gnus-group-buffer)
6345           (unless (gnus-ephemeral-group-p group)
6346             (gnus-group-update-group group)))))))
6347
6348 (defun gnus-summary-save-newsrc (&optional force)
6349   "Save the current number of read/marked articles in the dribble buffer.
6350 The dribble buffer will then be saved.
6351 If FORCE (the prefix), also save the .newsrc file(s)."
6352   (interactive "P")
6353   (gnus-summary-update-info t)
6354   (if force
6355       (gnus-save-newsrc-file)
6356     (gnus-dribble-save)))
6357
6358 (defun gnus-summary-exit (&optional temporary)
6359   "Exit reading current newsgroup, and then return to group selection mode.
6360 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6361   (interactive)
6362   (gnus-set-global-variables)
6363   (gnus-kill-save-kill-buffer)
6364   (gnus-async-halt-prefetch)
6365   (let* ((group gnus-newsgroup-name)
6366          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6367          (gnus-group-is-exiting-p t)
6368          (mode major-mode)
6369          (group-point nil)
6370          (buf (current-buffer)))
6371     (unless quit-config
6372       ;; Do adaptive scoring, and possibly save score files.
6373       (when gnus-newsgroup-adaptive
6374         (gnus-score-adaptive))
6375       (when gnus-use-scoring
6376         (gnus-score-save)))
6377     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6378     ;; If we have several article buffers, we kill them at exit.
6379     (unless gnus-single-article-buffer
6380       (gnus-kill-buffer gnus-original-article-buffer)
6381       (setq gnus-article-current nil))
6382     (when gnus-use-cache
6383       (gnus-cache-possibly-remove-articles)
6384       (gnus-cache-save-buffers))
6385     (gnus-async-prefetch-remove-group group)
6386     (when gnus-suppress-duplicates
6387       (gnus-dup-enter-articles))
6388     (when gnus-use-trees
6389       (gnus-tree-close group))
6390     (when gnus-use-cache
6391       (gnus-cache-write-active))
6392     ;; Remove entries for this group.
6393     (nnmail-purge-split-history (gnus-group-real-name group))
6394     ;; Make all changes in this group permanent.
6395     (unless quit-config
6396       (gnus-run-hooks 'gnus-exit-group-hook)
6397       (gnus-summary-update-info))
6398     (gnus-close-group group)
6399     ;; Make sure where we were, and go to next newsgroup.
6400     (set-buffer gnus-group-buffer)
6401     (unless quit-config
6402       (gnus-group-jump-to-group group))
6403     (gnus-run-hooks 'gnus-summary-exit-hook)
6404     (unless (or quit-config
6405                 ;; If this group has disappeared from the summary
6406                 ;; buffer, don't skip forwards.
6407                 (not (string= group (gnus-group-group-name))))
6408       (gnus-group-next-unread-group 1))
6409     (setq group-point (point))
6410     (if temporary
6411         nil                             ;Nothing to do.
6412       ;; If we have several article buffers, we kill them at exit.
6413       (unless gnus-single-article-buffer
6414         (gnus-kill-buffer gnus-article-buffer)
6415         (gnus-kill-buffer gnus-original-article-buffer)
6416         (setq gnus-article-current nil))
6417       (set-buffer buf)
6418       (if (not gnus-kill-summary-on-exit)
6419           (progn
6420             (gnus-deaden-summary)
6421             (setq mode nil))
6422         ;; We set all buffer-local variables to nil.  It is unclear why
6423         ;; this is needed, but if we don't, buffer-local variables are
6424         ;; not garbage-collected, it seems.  This would the lead to en
6425         ;; ever-growing Emacs.
6426         (gnus-summary-clear-local-variables)
6427         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6428           (gnus-summary-clear-local-variables))
6429         (when (get-buffer gnus-article-buffer)
6430           (bury-buffer gnus-article-buffer))
6431         ;; We clear the global counterparts of the buffer-local
6432         ;; variables as well, just to be on the safe side.
6433         (set-buffer gnus-group-buffer)
6434         (gnus-summary-clear-local-variables)
6435         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6436           (gnus-summary-clear-local-variables))
6437         ;; Return to group mode buffer.
6438         (when (eq mode 'gnus-summary-mode)
6439           (gnus-kill-buffer buf)))
6440       (setq gnus-current-select-method gnus-select-method)
6441       (pop-to-buffer gnus-group-buffer)
6442       (if (not quit-config)
6443           (progn
6444             (goto-char group-point)
6445             (gnus-configure-windows 'group 'force)
6446             (unless (pos-visible-in-window-p)
6447               (forward-line (/ (static-if (featurep 'xemacs)
6448                                    (window-displayed-height)
6449                                  (1- (window-height)))
6450                                -2))
6451               (set-window-start (selected-window) (point))
6452               (goto-char group-point)))
6453         (gnus-handle-ephemeral-exit quit-config))
6454       ;; Clear the current group name.
6455       (unless quit-config
6456         (setq gnus-newsgroup-name nil)))))
6457
6458 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6459 (defun gnus-summary-exit-no-update (&optional no-questions)
6460   "Quit reading current newsgroup without updating read article info."
6461   (interactive)
6462   (let* ((group gnus-newsgroup-name)
6463          (gnus-group-is-exiting-p t)
6464          (quit-config (gnus-group-quit-config group)))
6465     (when (or no-questions
6466               gnus-expert-user
6467               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6468       (gnus-async-halt-prefetch)
6469       (mapcar 'funcall
6470               (delq 'gnus-summary-expire-articles
6471                     (copy-sequence gnus-summary-prepare-exit-hook)))
6472       ;; If we have several article buffers, we kill them at exit.
6473       (unless gnus-single-article-buffer
6474         (gnus-kill-buffer gnus-article-buffer)
6475         (gnus-kill-buffer gnus-original-article-buffer)
6476         (setq gnus-article-current nil))
6477       (if (not gnus-kill-summary-on-exit)
6478           (gnus-deaden-summary)
6479         (gnus-close-group group)
6480         (gnus-summary-clear-local-variables)
6481         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6482           (gnus-summary-clear-local-variables))
6483         (set-buffer gnus-group-buffer)
6484         (gnus-summary-clear-local-variables)
6485         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6486           (gnus-summary-clear-local-variables))
6487         (when (get-buffer gnus-summary-buffer)
6488           (kill-buffer gnus-summary-buffer)))
6489       (unless gnus-single-article-buffer
6490         (setq gnus-article-current nil))
6491       (when gnus-use-trees
6492         (gnus-tree-close group))
6493       (gnus-async-prefetch-remove-group group)
6494       (when (get-buffer gnus-article-buffer)
6495         (bury-buffer gnus-article-buffer))
6496       ;; Return to the group buffer.
6497       (gnus-configure-windows 'group 'force)
6498       ;; Clear the current group name.
6499       (setq gnus-newsgroup-name nil)
6500       (unless (gnus-ephemeral-group-p group)
6501         (gnus-group-update-group group))
6502       (when (equal (gnus-group-group-name) group)
6503         (gnus-group-next-unread-group 1))
6504       (when quit-config
6505         (gnus-handle-ephemeral-exit quit-config)))))
6506
6507 (defun gnus-handle-ephemeral-exit (quit-config)
6508   "Handle movement when leaving an ephemeral group.
6509 The state which existed when entering the ephemeral is reset."
6510   (if (not (buffer-name (car quit-config)))
6511       (gnus-configure-windows 'group 'force)
6512     (set-buffer (car quit-config))
6513     (cond ((eq major-mode 'gnus-summary-mode)
6514            (gnus-set-global-variables))
6515           ((eq major-mode 'gnus-article-mode)
6516            (save-excursion
6517              ;; The `gnus-summary-buffer' variable may point
6518              ;; to the old summary buffer when using a single
6519              ;; article buffer.
6520              (unless (gnus-buffer-live-p gnus-summary-buffer)
6521                (set-buffer gnus-group-buffer))
6522              (set-buffer gnus-summary-buffer)
6523              (gnus-set-global-variables))))
6524     (if (or (eq (cdr quit-config) 'article)
6525             (eq (cdr quit-config) 'pick))
6526         (progn
6527           ;; The current article may be from the ephemeral group
6528           ;; thus it is best that we reload this article
6529           (gnus-summary-show-article)
6530           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6531               (gnus-configure-windows 'pick 'force)
6532             (gnus-configure-windows (cdr quit-config) 'force)))
6533       (gnus-configure-windows (cdr quit-config) 'force))
6534     (when (eq major-mode 'gnus-summary-mode)
6535       (gnus-summary-next-subject 1 nil t)
6536       (gnus-summary-recenter)
6537       (gnus-summary-position-point))))
6538
6539 (defun gnus-summary-preview-mime-message ()
6540   "MIME decode and play this message."
6541   (interactive)
6542   (let ((gnus-break-pages nil)
6543         (gnus-show-mime t))
6544     (gnus-summary-select-article gnus-show-all-headers t))
6545   (let ((w (get-buffer-window gnus-article-buffer)))
6546     (when w
6547       (select-window (get-buffer-window gnus-article-buffer)))))
6548
6549 ;;; Dead summaries.
6550
6551 (defvar gnus-dead-summary-mode-map nil)
6552
6553 (unless gnus-dead-summary-mode-map
6554   (setq gnus-dead-summary-mode-map (make-keymap))
6555   (suppress-keymap gnus-dead-summary-mode-map)
6556   (substitute-key-definition
6557    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6558   (dolist (key '("\C-d" "\r" "\177" [delete]))
6559     (define-key gnus-dead-summary-mode-map
6560       key 'gnus-summary-wake-up-the-dead))
6561   (dolist (key '("q" "Q"))
6562     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6563
6564 (defvar gnus-dead-summary-mode nil
6565   "Minor mode for Gnus summary buffers.")
6566
6567 (defun gnus-dead-summary-mode (&optional arg)
6568   "Minor mode for Gnus summary buffers."
6569   (interactive "P")
6570   (when (eq major-mode 'gnus-summary-mode)
6571     (make-local-variable 'gnus-dead-summary-mode)
6572     (setq gnus-dead-summary-mode
6573           (if (null arg) (not gnus-dead-summary-mode)
6574             (> (prefix-numeric-value arg) 0)))
6575     (when gnus-dead-summary-mode
6576       (gnus-add-minor-mode
6577        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6578
6579 (defun gnus-deaden-summary ()
6580   "Make the current summary buffer into a dead summary buffer."
6581   ;; Kill any previous dead summary buffer.
6582   (when (and gnus-dead-summary
6583              (buffer-name gnus-dead-summary))
6584     (save-excursion
6585       (set-buffer gnus-dead-summary)
6586       (when gnus-dead-summary-mode
6587         (kill-buffer (current-buffer)))))
6588   ;; Make this the current dead summary.
6589   (setq gnus-dead-summary (current-buffer))
6590   (gnus-dead-summary-mode 1)
6591   (let ((name (buffer-name)))
6592     (when (string-match "Summary" name)
6593       (rename-buffer
6594        (concat (substring name 0 (match-beginning 0)) "Dead "
6595                (substring name (match-beginning 0)))
6596        t)
6597       (bury-buffer))))
6598
6599 (defun gnus-kill-or-deaden-summary (buffer)
6600   "Kill or deaden the summary BUFFER."
6601   (save-excursion
6602     (when (and (buffer-name buffer)
6603                (not gnus-single-article-buffer))
6604       (save-excursion
6605         (set-buffer buffer)
6606         (gnus-kill-buffer gnus-article-buffer)
6607         (gnus-kill-buffer gnus-original-article-buffer)))
6608     (cond
6609      ;; Kill the buffer.
6610      (gnus-kill-summary-on-exit
6611       (when (and gnus-use-trees
6612                  (gnus-buffer-exists-p buffer))
6613         (save-excursion
6614           (set-buffer buffer)
6615           (gnus-tree-close gnus-newsgroup-name)))
6616       (gnus-kill-buffer buffer))
6617      ;; Deaden the buffer.
6618      ((gnus-buffer-exists-p buffer)
6619       (save-excursion
6620         (set-buffer buffer)
6621         (gnus-deaden-summary))))))
6622
6623 (defun gnus-summary-wake-up-the-dead (&rest args)
6624   "Wake up the dead summary buffer."
6625   (interactive)
6626   (gnus-dead-summary-mode -1)
6627   (let ((name (buffer-name)))
6628     (when (string-match "Dead " name)
6629       (rename-buffer
6630        (concat (substring name 0 (match-beginning 0))
6631                (substring name (match-end 0)))
6632        t)))
6633   (gnus-message 3 "This dead summary is now alive again"))
6634
6635 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6636 (defun gnus-summary-fetch-faq (&optional faq-dir)
6637   "Fetch the FAQ for the current group.
6638 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6639 in."
6640   (interactive
6641    (list
6642     (when current-prefix-arg
6643       (completing-read
6644        "FAQ dir: " (and (listp gnus-group-faq-directory)
6645                         (mapcar (lambda (file) (list file))
6646                                 gnus-group-faq-directory))))))
6647   (let (gnus-faq-buffer)
6648     (when (setq gnus-faq-buffer
6649                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6650       (gnus-configure-windows 'summary-faq))))
6651
6652 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6653 (defun gnus-summary-describe-group (&optional force)
6654   "Describe the current newsgroup."
6655   (interactive "P")
6656   (gnus-group-describe-group force gnus-newsgroup-name))
6657
6658 (defun gnus-summary-describe-briefly ()
6659   "Describe summary mode commands briefly."
6660   (interactive)
6661   (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")))
6662
6663 ;; Walking around group mode buffer from summary mode.
6664
6665 (defun gnus-summary-next-group (&optional no-article target-group backward)
6666   "Exit current newsgroup and then select next unread newsgroup.
6667 If prefix argument NO-ARTICLE is non-nil, no article is selected
6668 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6669 previous group instead."
6670   (interactive "P")
6671   ;; Stop pre-fetching.
6672   (gnus-async-halt-prefetch)
6673   (let ((current-group gnus-newsgroup-name)
6674         (current-buffer (current-buffer))
6675         entered)
6676     (gnus-summary-exit t)
6677     (while (not entered)
6678       ;; Then we find what group we are supposed to enter.
6679       (set-buffer gnus-group-buffer)
6680       (gnus-group-jump-to-group current-group)
6681       (setq target-group
6682             (or target-group
6683                 (if (eq gnus-keep-same-level 'best)
6684                     (gnus-summary-best-group gnus-newsgroup-name)
6685                   (gnus-summary-search-group backward gnus-keep-same-level))))
6686       (if (not target-group)
6687           ;; There are no further groups, so we return to the group
6688           ;; buffer.
6689           (progn
6690             (gnus-message 5 "Returning to the group buffer")
6691             (setq entered t)
6692             (when (gnus-buffer-live-p current-buffer)
6693               (set-buffer current-buffer)
6694               (gnus-summary-exit))
6695             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6696         ;; We try to enter the target group.
6697         (gnus-group-jump-to-group target-group)
6698         (let ((unreads (gnus-group-group-unread)))
6699           (if (and (or (eq t unreads)
6700                        (and unreads (not (zerop unreads))))
6701                    (progn
6702                      ;; Now we semi-exit this group to update Xrefs
6703                      ;; and all variables.  We can't do a real exit,
6704                      ;; because the window conf must remain the same
6705                      ;; in case the user is prompted for info, and we
6706                      ;; don't want the window conf to change before
6707                      ;; that...
6708                      (when (gnus-buffer-live-p current-buffer)
6709                        (set-buffer current-buffer)
6710                        (gnus-summary-exit t))
6711                      (gnus-summary-read-group
6712                       target-group nil no-article
6713                       (and (buffer-name current-buffer) current-buffer)
6714                       nil backward)))
6715               (setq entered t)
6716             (setq current-group target-group
6717                   target-group nil)))))))
6718
6719 (defun gnus-summary-prev-group (&optional no-article)
6720   "Exit current newsgroup and then select previous unread newsgroup.
6721 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6722   (interactive "P")
6723   (gnus-summary-next-group no-article nil t))
6724
6725 ;; Walking around summary lines.
6726
6727 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6728   "Go to the first unread subject.
6729 If UNREAD is non-nil, go to the first unread article.
6730 Returns the article selected or nil if there are no unread articles."
6731   (interactive "P")
6732   (prog1
6733       (cond
6734        ;; Empty summary.
6735        ((null gnus-newsgroup-data)
6736         (gnus-message 3 "No articles in the group")
6737         nil)
6738        ;; Pick the first article.
6739        ((not unread)
6740         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6741         (gnus-data-number (car gnus-newsgroup-data)))
6742        ;; No unread articles.
6743        ((null gnus-newsgroup-unreads)
6744         (gnus-message 3 "No more unread articles")
6745         nil)
6746        ;; Find the first unread article.
6747        (t
6748         (let ((data gnus-newsgroup-data))
6749           (while (and data
6750                       (and (not (and undownloaded
6751                                      (memq (car data)
6752                                            gnus-newsgroup-undownloaded)))
6753                            (if unseen
6754                                (or (not (memq
6755                                          (gnus-data-number (car data))
6756                                          gnus-newsgroup-unseen))
6757                                    (not (gnus-data-unread-p (car data))))
6758                              (not (gnus-data-unread-p (car data))))))
6759             (setq data (cdr data)))
6760           (when data
6761             (goto-char (gnus-data-pos (car data)))
6762             (gnus-data-number (car data))))))
6763     (gnus-summary-position-point)))
6764
6765 (defun gnus-summary-next-subject (n &optional unread dont-display)
6766   "Go to next N'th summary line.
6767 If N is negative, go to the previous N'th subject line.
6768 If UNREAD is non-nil, only unread articles are selected.
6769 The difference between N and the actual number of steps taken is
6770 returned."
6771   (interactive "p")
6772   (let ((backward (< n 0))
6773         (n (abs n)))
6774     (while (and (> n 0)
6775                 (if backward
6776                     (gnus-summary-find-prev unread)
6777                   (gnus-summary-find-next unread)))
6778       (unless (zerop (setq n (1- n)))
6779         (gnus-summary-show-thread)))
6780     (when (/= 0 n)
6781       (gnus-message 7 "No more%s articles"
6782                     (if unread " unread" "")))
6783     (unless dont-display
6784       (gnus-summary-recenter)
6785       (gnus-summary-position-point))
6786     n))
6787
6788 (defun gnus-summary-next-unread-subject (n)
6789   "Go to next N'th unread summary line."
6790   (interactive "p")
6791   (gnus-summary-next-subject n t))
6792
6793 (defun gnus-summary-prev-subject (n &optional unread)
6794   "Go to previous N'th summary line.
6795 If optional argument UNREAD is non-nil, only unread article is selected."
6796   (interactive "p")
6797   (gnus-summary-next-subject (- n) unread))
6798
6799 (defun gnus-summary-prev-unread-subject (n)
6800   "Go to previous N'th unread summary line."
6801   (interactive "p")
6802   (gnus-summary-next-subject (- n) t))
6803
6804 (defun gnus-summary-goto-subjects (articles)
6805   "Insert the subject header for ARTICLES in the current buffer."
6806   (save-excursion
6807     (dolist (article articles)
6808       (gnus-summary-goto-subject article t)))
6809   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6810   (gnus-summary-position-point))
6811  
6812 (defun gnus-summary-goto-subject (article &optional force silent)
6813   "Go the subject line of ARTICLE.
6814 If FORCE, also allow jumping to articles not currently shown."
6815   (interactive "nArticle number: ")
6816   (unless (numberp article)
6817     (error "Article %s is not a number" article))
6818   (let ((b (point))
6819         (data (gnus-data-find article)))
6820     ;; We read in the article if we have to.
6821     (and (not data)
6822          force
6823          (gnus-summary-insert-subject
6824           article
6825           (if (or (numberp force) (vectorp force)) force)
6826           t)
6827          (setq data (gnus-data-find article)))
6828     (goto-char b)
6829     (if (not data)
6830         (progn
6831           (unless silent
6832             (gnus-message 3 "Can't find article %d" article))
6833           nil)
6834       (let ((pt (gnus-data-pos data)))
6835         (goto-char pt)
6836         (gnus-summary-set-article-display-arrow pt))
6837       (gnus-summary-position-point)
6838       article)))
6839
6840 ;; Walking around summary lines with displaying articles.
6841
6842 (defun gnus-summary-expand-window (&optional arg)
6843   "Make the summary buffer take up the entire Emacs frame.
6844 Given a prefix, will force an `article' buffer configuration."
6845   (interactive "P")
6846   (if arg
6847       (gnus-configure-windows 'article 'force)
6848     (gnus-configure-windows 'summary 'force)))
6849
6850 (defun gnus-summary-display-article (article &optional all-header)
6851   "Display ARTICLE in article buffer."
6852   (when (gnus-buffer-live-p gnus-article-buffer)
6853     (with-current-buffer gnus-article-buffer
6854       (set-buffer-multibyte t)))
6855   (gnus-set-global-variables)
6856   (when (gnus-buffer-live-p gnus-article-buffer)
6857     (with-current-buffer gnus-article-buffer
6858       (setq gnus-article-charset gnus-newsgroup-charset)
6859       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6860       (set-buffer-multibyte t)))
6861   (if (null article)
6862       nil
6863     (prog1
6864         (if gnus-summary-display-article-function
6865             (funcall gnus-summary-display-article-function article all-header)
6866           (gnus-article-prepare article all-header))
6867       (with-current-buffer gnus-article-buffer
6868         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6869              nil))
6870       (gnus-run-hooks 'gnus-select-article-hook)
6871       (when (and gnus-current-article
6872                  (not (zerop gnus-current-article)))
6873         (gnus-summary-goto-subject gnus-current-article))
6874       (gnus-summary-recenter)
6875       (when (and gnus-use-trees gnus-show-threads)
6876         (gnus-possibly-generate-tree article)
6877         (gnus-highlight-selected-tree article))
6878       ;; Successfully display article.
6879       (gnus-article-set-window-start
6880        (cdr (assq article gnus-newsgroup-bookmarks))))))
6881
6882 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6883   "Select the current article.
6884 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6885 non-nil, the article will be re-fetched even if it already present in
6886 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6887 be displayed."
6888   ;; Make sure we are in the summary buffer to work around bbdb bug.
6889   (unless (eq major-mode 'gnus-summary-mode)
6890     (set-buffer gnus-summary-buffer))
6891   (let ((article (or article (gnus-summary-article-number)))
6892         (all-headers (not (not all-headers))) ;Must be T or NIL.
6893         gnus-summary-display-article-function)
6894     (and (not pseudo)
6895          (gnus-summary-article-pseudo-p article)
6896          (error "This is a pseudo-article"))
6897     (save-excursion
6898       (set-buffer gnus-summary-buffer)
6899       (if (or (and gnus-single-article-buffer
6900                    (or (null gnus-current-article)
6901                        (null gnus-article-current)
6902                        (null (get-buffer gnus-article-buffer))
6903                        (not (eq article (cdr gnus-article-current)))
6904                        (not (equal (car gnus-article-current)
6905                                    gnus-newsgroup-name))))
6906               (and (not gnus-single-article-buffer)
6907                    (or (null gnus-current-article)
6908                        (not (eq gnus-current-article article))))
6909               force)
6910           ;; The requested article is different from the current article.
6911           (progn
6912             (gnus-summary-display-article article all-headers)
6913             (gnus-article-set-window-start
6914              (cdr (assq article gnus-newsgroup-bookmarks)))
6915             article)
6916         'old))))
6917
6918 (defun gnus-summary-force-verify-and-decrypt ()
6919   (interactive)
6920   (let ((mm-verify-option 'known)
6921         (mm-decrypt-option 'known)
6922         (gnus-buttonized-mime-types (append (list "multipart/signed"
6923                                                   "multipart/encrypted")
6924                                             gnus-buttonized-mime-types)))
6925     (gnus-summary-select-article nil 'force)))
6926
6927 (defun gnus-summary-set-current-mark (&optional current-mark)
6928   "Obsolete function."
6929   nil)
6930
6931 (defun gnus-summary-next-article (&optional unread subject backward push)
6932   "Select the next article.
6933 If UNREAD, only unread articles are selected.
6934 If SUBJECT, only articles with SUBJECT are selected.
6935 If BACKWARD, the previous article is selected instead of the next."
6936   (interactive "P")
6937   (cond
6938    ;; Is there such an article?
6939    ((and (gnus-summary-search-forward unread subject backward)
6940          (or (gnus-summary-display-article (gnus-summary-article-number))
6941              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6942     (gnus-summary-position-point))
6943    ;; If not, we try the first unread, if that is wanted.
6944    ((and subject
6945          gnus-auto-select-same
6946          (gnus-summary-first-unread-article))
6947     (gnus-summary-position-point)
6948     (gnus-message 6 "Wrapped"))
6949    ;; Try to get next/previous article not displayed in this group.
6950    ((and gnus-auto-extend-newsgroup
6951          (not unread) (not subject))
6952     (gnus-summary-goto-article
6953      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6954      nil (count-lines (point-min) (point))))
6955    ;; Go to next/previous group.
6956    (t
6957     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6958       (gnus-summary-jump-to-group gnus-newsgroup-name))
6959     (let ((cmd last-command-char)
6960           (point
6961            (save-excursion
6962              (set-buffer gnus-group-buffer)
6963              (point)))
6964           (group
6965            (if (eq gnus-keep-same-level 'best)
6966                (gnus-summary-best-group gnus-newsgroup-name)
6967              (gnus-summary-search-group backward gnus-keep-same-level))))
6968       ;; For some reason, the group window gets selected.  We change
6969       ;; it back.
6970       (select-window (get-buffer-window (current-buffer)))
6971       ;; Select next unread newsgroup automagically.
6972       (cond
6973        ((or (not gnus-auto-select-next)
6974             (not cmd))
6975         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6976        ((or (eq gnus-auto-select-next 'quietly)
6977             (and (eq gnus-auto-select-next 'slightly-quietly)
6978                  push)
6979             (and (eq gnus-auto-select-next 'almost-quietly)
6980                  (gnus-summary-last-article-p)))
6981         ;; Select quietly.
6982         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6983             (gnus-summary-exit)
6984           (gnus-message 7 "No more%s articles (%s)..."
6985                         (if unread " unread" "")
6986                         (if group (concat "selecting " group)
6987                           "exiting"))
6988           (gnus-summary-next-group nil group backward)))
6989        (t
6990         (when (gnus-key-press-event-p last-input-event)
6991           (gnus-summary-walk-group-buffer
6992            gnus-newsgroup-name cmd unread backward point))))))))
6993
6994 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6995   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6996                       (?\C-p (gnus-group-prev-unread-group 1))))
6997         (cursor-in-echo-area t)
6998         keve key group ended prompt)
6999     (save-excursion
7000       (set-buffer gnus-group-buffer)
7001       (goto-char start)
7002       (setq group
7003             (if (eq gnus-keep-same-level 'best)
7004                 (gnus-summary-best-group gnus-newsgroup-name)
7005               (gnus-summary-search-group backward gnus-keep-same-level))))
7006     (while (not ended)
7007       (setq prompt
7008             (format
7009              "No more%s articles%s " (if unread " unread" "")
7010              (if (and group
7011                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7012                  (format " (Type %s for %s [%s])"
7013                          (single-key-description cmd) group
7014                          (car (gnus-gethash group gnus-newsrc-hashtb)))
7015                (format " (Type %s to exit %s)"
7016                        (single-key-description cmd)
7017                        gnus-newsgroup-name))))
7018       ;; Confirm auto selection.
7019       (setq key (car (setq keve (gnus-read-event-char prompt)))
7020             ended t)
7021       (cond
7022        ((assq key keystrokes)
7023         (let ((obuf (current-buffer)))
7024           (switch-to-buffer gnus-group-buffer)
7025           (when group
7026             (gnus-group-jump-to-group group))
7027           (eval (cadr (assq key keystrokes)))
7028           (setq group (gnus-group-group-name))
7029           (switch-to-buffer obuf))
7030         (setq ended nil))
7031        ((equal key cmd)
7032         (if (or (not group)
7033                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7034             (gnus-summary-exit)
7035           (gnus-summary-next-group nil group backward)))
7036        (t
7037         (push (cdr keve) unread-command-events))))))
7038
7039 (defun gnus-summary-next-unread-article ()
7040   "Select unread article after current one."
7041   (interactive)
7042   (gnus-summary-next-article
7043    (or (not (eq gnus-summary-goto-unread 'never))
7044        (gnus-summary-last-article-p (gnus-summary-article-number)))
7045    (and gnus-auto-select-same
7046         (gnus-summary-article-subject))))
7047
7048 (defun gnus-summary-prev-article (&optional unread subject)
7049   "Select the article after the current one.
7050 If UNREAD is non-nil, only unread articles are selected."
7051   (interactive "P")
7052   (gnus-summary-next-article unread subject t))
7053
7054 (defun gnus-summary-prev-unread-article ()
7055   "Select unread article before current one."
7056   (interactive)
7057   (gnus-summary-prev-article
7058    (or (not (eq gnus-summary-goto-unread 'never))
7059        (gnus-summary-first-article-p (gnus-summary-article-number)))
7060    (and gnus-auto-select-same
7061         (gnus-summary-article-subject))))
7062
7063 (defun gnus-summary-next-page (&optional lines circular stop)
7064   "Show next page of the selected article.
7065 If at the end of the current article, select the next article.
7066 LINES says how many lines should be scrolled up.
7067
7068 If CIRCULAR is non-nil, go to the start of the article instead of
7069 selecting the next article when reaching the end of the current
7070 article.
7071
7072 If STOP is non-nil, just stop when reaching the end of the message."
7073   (interactive "P")
7074   (setq gnus-summary-buffer (current-buffer))
7075   (gnus-set-global-variables)
7076   (let ((article (gnus-summary-article-number))
7077         (article-window (get-buffer-window gnus-article-buffer t))
7078         endp)
7079     ;; If the buffer is empty, we have no article.
7080     (unless article
7081       (error "No article to select"))
7082     (gnus-configure-windows 'article)
7083     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7084         (if (and (eq gnus-summary-goto-unread 'never)
7085                  (not (gnus-summary-last-article-p article)))
7086             (gnus-summary-next-article)
7087           (gnus-summary-next-unread-article))
7088       (if (or (null gnus-current-article)
7089               (null gnus-article-current)
7090               (/= article (cdr gnus-article-current))
7091               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7092           ;; Selected subject is different from current article's.
7093           (gnus-summary-display-article article)
7094         (when article-window
7095           (gnus-eval-in-buffer-window gnus-article-buffer
7096             (setq endp (gnus-article-next-page lines)))
7097           (when endp
7098             (cond (stop
7099                    (gnus-message 3 "End of message"))
7100                   (circular
7101                    (gnus-summary-beginning-of-article))
7102                   (lines
7103                    (gnus-message 3 "End of message"))
7104                   ((null lines)
7105                    (if (and (eq gnus-summary-goto-unread 'never)
7106                             (not (gnus-summary-last-article-p article)))
7107                        (gnus-summary-next-article)
7108                      (gnus-summary-next-unread-article))))))))
7109     (gnus-summary-recenter)
7110     (gnus-summary-position-point)))
7111
7112 (defun gnus-summary-prev-page (&optional lines move)
7113   "Show previous page of selected article.
7114 Argument LINES specifies lines to be scrolled down.
7115 If MOVE, move to the previous unread article if point is at
7116 the beginning of the buffer."
7117   (interactive "P")
7118   (let ((article (gnus-summary-article-number))
7119         (article-window (get-buffer-window gnus-article-buffer t))
7120         endp)
7121     (gnus-configure-windows 'article)
7122     (if (or (null gnus-current-article)
7123             (null gnus-article-current)
7124             (/= article (cdr gnus-article-current))
7125             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7126         ;; Selected subject is different from current article's.
7127         (gnus-summary-display-article article)
7128       (gnus-summary-recenter)
7129       (when article-window
7130         (gnus-eval-in-buffer-window gnus-article-buffer
7131           (setq endp (gnus-article-prev-page lines)))
7132         (when (and move endp)
7133           (cond (lines
7134                  (gnus-message 3 "Beginning of message"))
7135                 ((null lines)
7136                  (if (and (eq gnus-summary-goto-unread 'never)
7137                           (not (gnus-summary-first-article-p article)))
7138                      (gnus-summary-prev-article)
7139                    (gnus-summary-prev-unread-article))))))))
7140   (gnus-summary-position-point))
7141
7142 (defun gnus-summary-prev-page-or-article (&optional lines)
7143   "Show previous page of selected article.
7144 Argument LINES specifies lines to be scrolled down.
7145 If at the beginning of the article, go to the next article."
7146   (interactive "P")
7147   (gnus-summary-prev-page lines t))
7148
7149 (defun gnus-summary-scroll-up (lines)
7150   "Scroll up (or down) one line current article.
7151 Argument LINES specifies lines to be scrolled up (or down if negative)."
7152   (interactive "p")
7153   (gnus-configure-windows 'article)
7154   (gnus-summary-show-thread)
7155   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7156     (gnus-eval-in-buffer-window gnus-article-buffer
7157       (cond ((> lines 0)
7158              (when (gnus-article-next-page lines)
7159                (gnus-message 3 "End of message")))
7160             ((< lines 0)
7161              (gnus-article-prev-page (- lines))))))
7162   (gnus-summary-recenter)
7163   (gnus-summary-position-point))
7164
7165 (defun gnus-summary-scroll-down (lines)
7166   "Scroll down (or up) one line current article.
7167 Argument LINES specifies lines to be scrolled down (or up if negative)."
7168   (interactive "p")
7169   (gnus-summary-scroll-up (- lines)))
7170
7171 (defun gnus-summary-next-same-subject ()
7172   "Select next article which has the same subject as current one."
7173   (interactive)
7174   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7175
7176 (defun gnus-summary-prev-same-subject ()
7177   "Select previous article which has the same subject as current one."
7178   (interactive)
7179   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7180
7181 (defun gnus-summary-next-unread-same-subject ()
7182   "Select next unread article which has the same subject as current one."
7183   (interactive)
7184   (gnus-summary-next-article t (gnus-summary-article-subject)))
7185
7186 (defun gnus-summary-prev-unread-same-subject ()
7187   "Select previous unread article which has the same subject as current one."
7188   (interactive)
7189   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7190
7191 (defun gnus-summary-first-unread-article ()
7192   "Select the first unread article.
7193 Return nil if there are no unread articles."
7194   (interactive)
7195   (prog1
7196       (when (gnus-summary-first-subject t)
7197         (gnus-summary-show-thread)
7198         (gnus-summary-first-subject t)
7199         (gnus-summary-display-article (gnus-summary-article-number)))
7200     (gnus-summary-position-point)))
7201
7202 (defun gnus-summary-first-unread-subject ()
7203   "Place the point on the subject line of the first unread article.
7204 Return nil if there are no unread articles."
7205   (interactive)
7206   (prog1
7207       (when (gnus-summary-first-subject t)
7208         (gnus-summary-show-thread)
7209         (gnus-summary-first-subject t))
7210     (gnus-summary-position-point)))
7211
7212 (defun gnus-summary-first-unseen-subject ()
7213   "Place the point on the subject line of the first unseen article.
7214 Return nil if there are no unseen articles."
7215   (interactive)
7216   (prog1
7217       (when (gnus-summary-first-subject t t t)
7218         (gnus-summary-show-thread)
7219         (gnus-summary-first-subject t t t))
7220     (gnus-summary-position-point)))
7221
7222 (defun gnus-summary-first-unseen-or-unread-subject ()
7223   "Place the point on the subject line of the first unseen article.
7224 Return nil if there are no unseen articles."
7225   (interactive)
7226   (prog1
7227       (unless (when (gnus-summary-first-subject t t t)
7228                 (gnus-summary-show-thread)
7229                 (gnus-summary-first-subject t t t))
7230         (when (gnus-summary-first-subject t)
7231           (gnus-summary-show-thread)
7232           (gnus-summary-first-subject t)))
7233     (gnus-summary-position-point)))
7234
7235 (defun gnus-summary-first-article ()
7236   "Select the first article.
7237 Return nil if there are no articles."
7238   (interactive)
7239   (prog1
7240       (when (gnus-summary-first-subject)
7241         (gnus-summary-show-thread)
7242         (gnus-summary-first-subject)
7243         (gnus-summary-display-article (gnus-summary-article-number)))
7244     (gnus-summary-position-point)))
7245
7246 (defun gnus-summary-best-unread-article (&optional arg)
7247   "Select the unread article with the highest score.
7248 If given a prefix argument, select the next unread article that has a
7249 score higher than the default score."
7250   (interactive "P")
7251   (let ((article (if arg
7252                      (gnus-summary-better-unread-subject)
7253                    (gnus-summary-best-unread-subject))))
7254     (if article
7255         (gnus-summary-goto-article article)
7256       (error "No unread articles"))))
7257
7258 (defun gnus-summary-best-unread-subject ()
7259   "Select the unread subject with the highest score."
7260   (interactive)
7261   (let ((best -1000000)
7262         (data gnus-newsgroup-data)
7263         article score)
7264     (while data
7265       (and (gnus-data-unread-p (car data))
7266            (> (setq score
7267                     (gnus-summary-article-score (gnus-data-number (car data))))
7268               best)
7269            (setq best score
7270                  article (gnus-data-number (car data))))
7271       (setq data (cdr data)))
7272     (when article
7273       (gnus-summary-goto-subject article))
7274     (gnus-summary-position-point)
7275     article))
7276
7277 (defun gnus-summary-better-unread-subject ()
7278   "Select the first unread subject that has a score over the default score."
7279   (interactive)
7280   (let ((data gnus-newsgroup-data)
7281         article score)
7282     (while (and (setq article (gnus-data-number (car data)))
7283                 (or (gnus-data-read-p (car data))
7284                     (not (> (gnus-summary-article-score article)
7285                             gnus-summary-default-score))))
7286       (setq data (cdr data)))
7287     (when article
7288       (gnus-summary-goto-subject article))
7289     (gnus-summary-position-point)
7290     article))
7291
7292 (defun gnus-summary-last-subject ()
7293   "Go to the last displayed subject line in the group."
7294   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7295     (when article
7296       (gnus-summary-goto-subject article))))
7297
7298 (defun gnus-summary-goto-article (article &optional all-headers force)
7299   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7300 If ALL-HEADERS is non-nil, no header lines are hidden.
7301 If FORCE, go to the article even if it isn't displayed.  If FORCE
7302 is a number, it is the line the article is to be displayed on."
7303   (interactive
7304    (list
7305     (completing-read
7306      "Article number or Message-ID: "
7307      (mapcar (lambda (number) (list (int-to-string number)))
7308              gnus-newsgroup-limit))
7309     current-prefix-arg
7310     t))
7311   (prog1
7312       (if (and (stringp article)
7313                (string-match "@" article))
7314           (gnus-summary-refer-article article)
7315         (when (stringp article)
7316           (setq article (string-to-number article)))
7317         (if (gnus-summary-goto-subject article force)
7318             (gnus-summary-display-article article all-headers)
7319           (gnus-message 4 "Couldn't go to article %s" article) nil))
7320     (gnus-summary-position-point)))
7321
7322 (defun gnus-summary-goto-last-article ()
7323   "Go to the previously read article."
7324   (interactive)
7325   (prog1
7326       (when gnus-last-article
7327         (gnus-summary-goto-article gnus-last-article nil t))
7328     (gnus-summary-position-point)))
7329
7330 (defun gnus-summary-pop-article (number)
7331   "Pop one article off the history and go to the previous.
7332 NUMBER articles will be popped off."
7333   (interactive "p")
7334   (let (to)
7335     (setq gnus-newsgroup-history
7336           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7337     (if to
7338         (gnus-summary-goto-article (car to) nil t)
7339       (error "Article history empty")))
7340   (gnus-summary-position-point))
7341
7342 ;; Summary commands and functions for limiting the summary buffer.
7343
7344 (defun gnus-summary-limit-to-articles (n)
7345   "Limit the summary buffer to the next N articles.
7346 If not given a prefix, use the process marked articles instead."
7347   (interactive "P")
7348   (prog1
7349       (let ((articles (gnus-summary-work-articles n)))
7350         (setq gnus-newsgroup-processable nil)
7351         (gnus-summary-limit articles))
7352     (gnus-summary-position-point)))
7353
7354 (defun gnus-summary-pop-limit (&optional total)
7355   "Restore the previous limit.
7356 If given a prefix, remove all limits."
7357   (interactive "P")
7358   (when total
7359     (setq gnus-newsgroup-limits
7360           (list (mapcar (lambda (h) (mail-header-number h))
7361                         gnus-newsgroup-headers))))
7362   (unless gnus-newsgroup-limits
7363     (error "No limit to pop"))
7364   (prog1
7365       (gnus-summary-limit nil 'pop)
7366     (gnus-summary-position-point)))
7367
7368 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7369   "Limit the summary buffer to articles that have subjects that match a regexp.
7370 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7371   (interactive
7372    (list (read-string (if current-prefix-arg
7373                           "Exclude subject (regexp): "
7374                         "Limit to subject (regexp): "))
7375          nil current-prefix-arg))
7376   (unless header
7377     (setq header "subject"))
7378   (when (not (equal "" subject))
7379     (prog1
7380         (let ((articles (gnus-summary-find-matching
7381                          (or header "subject") subject 'all nil nil
7382                          not-matching)))
7383           (unless articles
7384             (error "Found no matches for \"%s\"" subject))
7385           (gnus-summary-limit articles))
7386       (gnus-summary-position-point))))
7387
7388 (defun gnus-summary-limit-to-author (from &optional not-matching)
7389   "Limit the summary buffer to articles that have authors that match a regexp.
7390 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7391   (interactive
7392    (list (read-string (if current-prefix-arg
7393                           "Exclude author (regexp): "
7394                         "Limit to author (regexp): "))
7395          current-prefix-arg))
7396   (gnus-summary-limit-to-subject from "from" not-matching))
7397
7398 (defun gnus-summary-limit-to-age (age &optional younger-p)
7399   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7400 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7401 articles that are younger than AGE days."
7402   (interactive
7403    (let ((younger current-prefix-arg)
7404          (days-got nil)
7405          days)
7406      (while (not days-got)
7407        (setq days (if younger
7408                       (read-string "Limit to articles younger than (in days, older when negative): ")
7409                     (read-string
7410                      "Limit to articles older than (in days, younger when negative): ")))
7411        (when (> (length days) 0)
7412          (setq days (read days)))
7413        (if (numberp days)
7414            (progn
7415              (setq days-got t)
7416              (if (< days 0)
7417                  (progn
7418                    (setq younger (not younger))
7419                    (setq days (* days -1)))))
7420          (message "Please enter a number.")
7421          (sleep-for 1)))
7422      (list days younger)))
7423   (prog1
7424       (let ((data gnus-newsgroup-data)
7425             (cutoff (days-to-time age))
7426             articles d date is-younger)
7427         (while (setq d (pop data))
7428           (when (and (vectorp (gnus-data-header d))
7429                      (setq date (mail-header-date (gnus-data-header d))))
7430             (setq is-younger (time-less-p
7431                               (time-since (condition-case ()
7432                                               (date-to-time date)
7433                                             (error '(0 0))))
7434                               cutoff))
7435             (when (if younger-p
7436                       is-younger
7437                     (not is-younger))
7438               (push (gnus-data-number d) articles))))
7439         (gnus-summary-limit (nreverse articles)))
7440     (gnus-summary-position-point)))
7441
7442 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7443   "Limit the summary buffer to articles that match an 'extra' header."
7444   (interactive
7445    (let ((header
7446           (intern
7447            (gnus-completing-read-with-default
7448             (symbol-name (car gnus-extra-headers))
7449             (if current-prefix-arg
7450                 "Exclude extra header:"
7451               "Limit extra header:")
7452             (mapcar (lambda (x)
7453                       (cons (symbol-name x) x))
7454                     gnus-extra-headers)
7455             nil
7456             t))))
7457      (list header
7458            (read-string (format "%s header %s (regexp): "
7459                                 (if current-prefix-arg "Exclude" "Limit to")
7460                                 header))
7461            current-prefix-arg)))
7462   (when (not (equal "" regexp))
7463     (prog1
7464         (let ((articles (gnus-summary-find-matching
7465                          (cons 'extra header) regexp 'all nil nil
7466                          not-matching)))
7467           (unless articles
7468             (error "Found no matches for \"%s\"" regexp))
7469           (gnus-summary-limit articles))
7470       (gnus-summary-position-point))))
7471
7472 (defun gnus-summary-limit-to-display-predicate ()
7473   "Limit the summary buffer to the predicated in the `display' group parameter."
7474   (interactive)
7475   (unless gnus-newsgroup-display
7476     (error "There is no `display' group parameter"))
7477   (let (articles)
7478     (dolist (number gnus-newsgroup-articles)
7479       (when (funcall gnus-newsgroup-display)
7480         (push number articles)))
7481     (gnus-summary-limit articles))
7482   (gnus-summary-position-point))
7483
7484 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7485 (make-obsolete
7486  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7487
7488 (defun gnus-summary-limit-to-unread (&optional all)
7489   "Limit the summary buffer to articles that are not marked as read.
7490 If ALL is non-nil, limit strictly to unread articles."
7491   (interactive "P")
7492   (if all
7493       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7494     (gnus-summary-limit-to-marks
7495      ;; Concat all the marks that say that an article is read and have
7496      ;; those removed.
7497      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7498            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7499            gnus-low-score-mark gnus-expirable-mark
7500            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7501            gnus-duplicate-mark gnus-souped-mark)
7502      'reverse)))
7503
7504 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7505 (make-obsolete 'gnus-summary-delete-marked-with
7506                'gnus-summary-limit-exclude-marks)
7507
7508 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7509   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7510 If REVERSE, limit the summary buffer to articles that are marked
7511 with MARKS.  MARKS can either be a string of marks or a list of marks.
7512 Returns how many articles were removed."
7513   (interactive "sMarks: ")
7514   (gnus-summary-limit-to-marks marks t))
7515
7516 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7517   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7518 If REVERSE (the prefix), limit the summary buffer to articles that are
7519 not marked with MARKS.  MARKS can either be a string of marks or a
7520 list of marks.
7521 Returns how many articles were removed."
7522   (interactive "sMarks: \nP")
7523   (prog1
7524       (let ((data gnus-newsgroup-data)
7525             (marks (if (listp marks) marks
7526                      (append marks nil))) ; Transform to list.
7527             articles)
7528         (while data
7529           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7530                   (memq (gnus-data-mark (car data)) marks))
7531             (push (gnus-data-number (car data)) articles))
7532           (setq data (cdr data)))
7533         (gnus-summary-limit articles))
7534     (gnus-summary-position-point)))
7535
7536 (defun gnus-summary-limit-to-score (score)
7537   "Limit to articles with score at or above SCORE."
7538   (interactive "NLimit to articles with score of at least: ")
7539   (let ((data gnus-newsgroup-data)
7540         articles)
7541     (while data
7542       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7543                 score)
7544         (push (gnus-data-number (car data)) articles))
7545       (setq data (cdr data)))
7546     (prog1
7547         (gnus-summary-limit articles)
7548       (gnus-summary-position-point))))
7549
7550 (defun gnus-summary-limit-to-unseen ()
7551   "Limit to unseen articles."
7552   (interactive)
7553   (prog1
7554       (gnus-summary-limit gnus-newsgroup-unseen)
7555     (gnus-summary-position-point)))
7556
7557 (defun gnus-summary-limit-include-thread (id)
7558   "Display all the hidden articles that is in the thread with ID in it.
7559 When called interactively, ID is the Message-ID of the current
7560 article."
7561   (interactive (list (mail-header-id (gnus-summary-article-header))))
7562   (let ((articles (gnus-articles-in-thread
7563                    (gnus-id-to-thread (gnus-root-id id)))))
7564     (prog1
7565         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7566       (gnus-summary-limit-include-matching-articles
7567        "subject"
7568        (regexp-quote (gnus-simplify-subject-re
7569                       (mail-header-subject (gnus-id-to-header id)))))
7570       (gnus-summary-position-point))))
7571
7572 (defun gnus-summary-limit-include-matching-articles (header regexp)
7573   "Display all the hidden articles that have HEADERs that match REGEXP."
7574   (interactive (list (read-string "Match on header: ")
7575                      (read-string "Regexp: ")))
7576   (let ((articles (gnus-find-matching-articles header regexp)))
7577     (prog1
7578         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7579       (gnus-summary-position-point))))
7580
7581 (defun gnus-summary-insert-dormant-articles ()
7582   "Insert all the dormat articles for this group into the current buffer."
7583   (interactive)
7584   (let ((gnus-verbose (max 6 gnus-verbose)))
7585     (if (not gnus-newsgroup-dormant)
7586         (gnus-message 3 "No cached articles for this group")
7587       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7588
7589 (defun gnus-summary-limit-include-dormant ()
7590   "Display all the hidden articles that are marked as dormant.
7591 Note that this command only works on a subset of the articles currently
7592 fetched for this group."
7593   (interactive)
7594   (unless gnus-newsgroup-dormant
7595     (error "There are no dormant articles in this group"))
7596   (prog1
7597       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7598     (gnus-summary-position-point)))
7599
7600 (defun gnus-summary-limit-exclude-dormant ()
7601   "Hide all dormant articles."
7602   (interactive)
7603   (prog1
7604       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7605     (gnus-summary-position-point)))
7606
7607 (defun gnus-summary-limit-exclude-childless-dormant ()
7608   "Hide all dormant articles that have no children."
7609   (interactive)
7610   (let ((data (gnus-data-list t))
7611         articles d children)
7612     ;; Find all articles that are either not dormant or have
7613     ;; children.
7614     (while (setq d (pop data))
7615       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7616                 (and (setq children
7617                            (gnus-article-children (gnus-data-number d)))
7618                      (let (found)
7619                        (while children
7620                          (when (memq (car children) articles)
7621                            (setq children nil
7622                                  found t))
7623                          (pop children))
7624                        found)))
7625         (push (gnus-data-number d) articles)))
7626     ;; Do the limiting.
7627     (prog1
7628         (gnus-summary-limit articles)
7629       (gnus-summary-position-point))))
7630
7631 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7632   "Mark all unread excluded articles as read.
7633 If ALL, mark even excluded ticked and dormants as read."
7634   (interactive "P")
7635   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7636   (let ((articles (gnus-sorted-ndifference
7637                    (sort
7638                     (mapcar (lambda (h) (mail-header-number h))
7639                             gnus-newsgroup-headers)
7640                     '<)
7641                    gnus-newsgroup-limit))
7642         article)
7643     (setq gnus-newsgroup-unreads
7644           (gnus-sorted-intersection gnus-newsgroup-unreads
7645                                     gnus-newsgroup-limit))
7646     (if all
7647         (setq gnus-newsgroup-dormant nil
7648               gnus-newsgroup-marked nil
7649               gnus-newsgroup-reads
7650               (nconc
7651                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7652                gnus-newsgroup-reads))
7653       (while (setq article (pop articles))
7654         (unless (or (memq article gnus-newsgroup-dormant)
7655                     (memq article gnus-newsgroup-marked))
7656           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7657
7658 (defun gnus-summary-limit (articles &optional pop)
7659   (if pop
7660       ;; We pop the previous limit off the stack and use that.
7661       (setq articles (car gnus-newsgroup-limits)
7662             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7663     ;; We use the new limit, so we push the old limit on the stack.
7664     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7665   ;; Set the limit.
7666   (setq gnus-newsgroup-limit articles)
7667   (let ((total (length gnus-newsgroup-data))
7668         (data (gnus-data-find-list (gnus-summary-article-number)))
7669         (gnus-summary-mark-below nil)   ; Inhibit this.
7670         found)
7671     ;; This will do all the work of generating the new summary buffer
7672     ;; according to the new limit.
7673     (gnus-summary-prepare)
7674     ;; Hide any threads, possibly.
7675     (gnus-summary-maybe-hide-threads)
7676     ;; Try to return to the article you were at, or one in the
7677     ;; neighborhood.
7678     (when data
7679       ;; We try to find some article after the current one.
7680       (while data
7681         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7682           (setq data nil
7683                 found t))
7684         (setq data (cdr data))))
7685     (unless found
7686       ;; If there is no data, that means that we were after the last
7687       ;; article.  The same goes when we can't find any articles
7688       ;; after the current one.
7689       (goto-char (point-max))
7690       (gnus-summary-find-prev))
7691     (gnus-set-mode-line 'summary)
7692     ;; We return how many articles were removed from the summary
7693     ;; buffer as a result of the new limit.
7694     (- total (length gnus-newsgroup-data))))
7695
7696 (defsubst gnus-invisible-cut-children (threads)
7697   (let ((num 0))
7698     (while threads
7699       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7700         (incf num))
7701       (pop threads))
7702     (< num 2)))
7703
7704 (defsubst gnus-cut-thread (thread)
7705   "Go forwards in the thread until we find an article that we want to display."
7706   (when (or (eq gnus-fetch-old-headers 'some)
7707             (eq gnus-fetch-old-headers 'invisible)
7708             (numberp gnus-fetch-old-headers)
7709             (eq gnus-build-sparse-threads 'some)
7710             (eq gnus-build-sparse-threads 'more))
7711     ;; Deal with old-fetched headers and sparse threads.
7712     (while (and
7713             thread
7714             (or
7715              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7716              (gnus-summary-article-ancient-p
7717               (mail-header-number (car thread))))
7718             (if (or (<= (length (cdr thread)) 1)
7719                     (eq gnus-fetch-old-headers 'invisible))
7720                 (setq gnus-newsgroup-limit
7721                       (delq (mail-header-number (car thread))
7722                             gnus-newsgroup-limit)
7723                       thread (cadr thread))
7724               (when (gnus-invisible-cut-children (cdr thread))
7725                 (let ((th (cdr thread)))
7726                   (while th
7727                     (if (memq (mail-header-number (caar th))
7728                               gnus-newsgroup-limit)
7729                         (setq thread (car th)
7730                               th nil)
7731                       (setq th (cdr th))))))))))
7732   thread)
7733
7734 (defun gnus-cut-threads (threads)
7735   "Cut off all uninteresting articles from the beginning of threads."
7736   (when (or (eq gnus-fetch-old-headers 'some)
7737             (eq gnus-fetch-old-headers 'invisible)
7738             (numberp gnus-fetch-old-headers)
7739             (eq gnus-build-sparse-threads 'some)
7740             (eq gnus-build-sparse-threads 'more))
7741     (let ((th threads))
7742       (while th
7743         (setcar th (gnus-cut-thread (car th)))
7744         (setq th (cdr th)))))
7745   ;; Remove nixed out threads.
7746   (delq nil threads))
7747
7748 (defun gnus-summary-initial-limit (&optional show-if-empty)
7749   "Figure out what the initial limit is supposed to be on group entry.
7750 This entails weeding out unwanted dormants, low-scored articles,
7751 fetch-old-headers verbiage, and so on."
7752   ;; Most groups have nothing to remove.
7753   (if (or gnus-inhibit-limiting
7754           (and (null gnus-newsgroup-dormant)
7755                (eq gnus-newsgroup-display 'gnus-not-ignore)
7756                (not (eq gnus-fetch-old-headers 'some))
7757                (not (numberp gnus-fetch-old-headers))
7758                (not (eq gnus-fetch-old-headers 'invisible))
7759                (null gnus-summary-expunge-below)
7760                (not (eq gnus-build-sparse-threads 'some))
7761                (not (eq gnus-build-sparse-threads 'more))
7762                (null gnus-thread-expunge-below)
7763                (not gnus-use-nocem)))
7764       ()                                ; Do nothing.
7765     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7766     (setq gnus-newsgroup-limit nil)
7767     (mapatoms
7768      (lambda (node)
7769        (unless (car (symbol-value node))
7770          ;; These threads have no parents -- they are roots.
7771          (let ((nodes (cdr (symbol-value node)))
7772                thread)
7773            (while nodes
7774              (if (and gnus-thread-expunge-below
7775                       (< (gnus-thread-total-score (car nodes))
7776                          gnus-thread-expunge-below))
7777                  (gnus-expunge-thread (pop nodes))
7778                (setq thread (pop nodes))
7779                (gnus-summary-limit-children thread))))))
7780      gnus-newsgroup-dependencies)
7781     ;; If this limitation resulted in an empty group, we might
7782     ;; pop the previous limit and use it instead.
7783     (when (and (not gnus-newsgroup-limit)
7784                show-if-empty)
7785       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7786     gnus-newsgroup-limit))
7787
7788 (defun gnus-summary-limit-children (thread)
7789   "Return 1 if this subthread is visible and 0 if it is not."
7790   ;; First we get the number of visible children to this thread.  This
7791   ;; is done by recursing down the thread using this function, so this
7792   ;; will really go down to a leaf article first, before slowly
7793   ;; working its way up towards the root.
7794   (when thread
7795     (let* ((max-lisp-eval-depth 5000)
7796            (children
7797            (if (cdr thread)
7798                (apply '+ (mapcar 'gnus-summary-limit-children
7799                                  (cdr thread)))
7800              0))
7801           (number (mail-header-number (car thread)))
7802           score)
7803       (if (and
7804            (not (memq number gnus-newsgroup-marked))
7805            (or
7806             ;; If this article is dormant and has absolutely no visible
7807             ;; children, then this article isn't visible.
7808             (and (memq number gnus-newsgroup-dormant)
7809                  (zerop children))
7810             ;; If this is "fetch-old-headered" and there is no
7811             ;; visible children, then we don't want this article.
7812             (and (or (eq gnus-fetch-old-headers 'some)
7813                      (numberp gnus-fetch-old-headers))
7814                  (gnus-summary-article-ancient-p number)
7815                  (zerop children))
7816             ;; If this is "fetch-old-headered" and `invisible', then
7817             ;; we don't want this article.
7818             (and (eq gnus-fetch-old-headers 'invisible)
7819                  (gnus-summary-article-ancient-p number))
7820             ;; If this is a sparsely inserted article with no children,
7821             ;; we don't want it.
7822             (and (eq gnus-build-sparse-threads 'some)
7823                  (gnus-summary-article-sparse-p number)
7824                  (zerop children))
7825             ;; If we use expunging, and this article is really
7826             ;; low-scored, then we don't want this article.
7827             (when (and gnus-summary-expunge-below
7828                        (< (setq score
7829                                 (or (cdr (assq number gnus-newsgroup-scored))
7830                                     gnus-summary-default-score))
7831                           gnus-summary-expunge-below))
7832               ;; We increase the expunge-tally here, but that has
7833               ;; nothing to do with the limits, really.
7834               (incf gnus-newsgroup-expunged-tally)
7835               ;; We also mark as read here, if that's wanted.
7836               (when (and gnus-summary-mark-below
7837                          (< score gnus-summary-mark-below))
7838                 (setq gnus-newsgroup-unreads
7839                       (delq number gnus-newsgroup-unreads))
7840                 (if gnus-newsgroup-auto-expire
7841                     (push number gnus-newsgroup-expirable)
7842                   (push (cons number gnus-low-score-mark)
7843                         gnus-newsgroup-reads)))
7844               t)
7845             ;; Do the `display' group parameter.
7846             (and gnus-newsgroup-display
7847                  (not (funcall gnus-newsgroup-display)))
7848             ;; Check NoCeM things.
7849             (if (and gnus-use-nocem
7850                      (gnus-nocem-unwanted-article-p
7851                       (mail-header-id (car thread))))
7852                 (progn
7853                   (setq gnus-newsgroup-unreads
7854                         (delq number gnus-newsgroup-unreads))
7855                   t))))
7856           ;; Nope, invisible article.
7857           0
7858         ;; Ok, this article is to be visible, so we add it to the limit
7859         ;; and return 1.
7860         (push number gnus-newsgroup-limit)
7861         1))))
7862
7863 (defun gnus-expunge-thread (thread)
7864   "Mark all articles in THREAD as read."
7865   (let* ((number (mail-header-number (car thread))))
7866     (incf gnus-newsgroup-expunged-tally)
7867     ;; We also mark as read here, if that's wanted.
7868     (setq gnus-newsgroup-unreads
7869           (delq number gnus-newsgroup-unreads))
7870     (if gnus-newsgroup-auto-expire
7871         (push number gnus-newsgroup-expirable)
7872       (push (cons number gnus-low-score-mark)
7873             gnus-newsgroup-reads)))
7874   ;; Go recursively through all subthreads.
7875   (mapcar 'gnus-expunge-thread (cdr thread)))
7876
7877 ;; Summary article oriented commands
7878
7879 (defun gnus-summary-refer-parent-article (n)
7880   "Refer parent article N times.
7881 If N is negative, go to ancestor -N instead.
7882 The difference between N and the number of articles fetched is returned."
7883   (interactive "p")
7884   (let ((skip 1)
7885         error header ref)
7886     (when (not (natnump n))
7887       (setq skip (abs n)
7888             n 1))
7889     (while (and (> n 0)
7890                 (not error))
7891       (setq header (gnus-summary-article-header))
7892       (if (and (eq (mail-header-number header)
7893                    (cdr gnus-article-current))
7894                (equal gnus-newsgroup-name
7895                       (car gnus-article-current)))
7896           ;; If we try to find the parent of the currently
7897           ;; displayed article, then we take a look at the actual
7898           ;; References header, since this is slightly more
7899           ;; reliable than the References field we got from the
7900           ;; server.
7901           (save-excursion
7902             (set-buffer gnus-original-article-buffer)
7903             (nnheader-narrow-to-headers)
7904             (unless (setq ref (message-fetch-field "references"))
7905               (setq ref (message-fetch-field "in-reply-to")))
7906             (widen))
7907         (setq ref
7908               ;; It's not the current article, so we take a bet on
7909               ;; the value we got from the server.
7910               (mail-header-references header)))
7911       (if (and ref
7912                (not (equal ref "")))
7913           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7914             (gnus-message 1 "Couldn't find parent"))
7915         (gnus-message 1 "No references in article %d"
7916                       (gnus-summary-article-number))
7917         (setq error t))
7918       (decf n))
7919     (gnus-summary-position-point)
7920     n))
7921
7922 (defun gnus-summary-refer-references ()
7923   "Fetch all articles mentioned in the References header.
7924 Return the number of articles fetched."
7925   (interactive)
7926   (let ((ref (mail-header-references (gnus-summary-article-header)))
7927         (current (gnus-summary-article-number))
7928         (n 0))
7929     (if (or (not ref)
7930             (equal ref ""))
7931         (error "No References in the current article")
7932       ;; For each Message-ID in the References header...
7933       (while (string-match "<[^>]*>" ref)
7934         (incf n)
7935         ;; ... fetch that article.
7936         (gnus-summary-refer-article
7937          (prog1 (match-string 0 ref)
7938            (setq ref (substring ref (match-end 0))))))
7939       (gnus-summary-goto-subject current)
7940       (gnus-summary-position-point)
7941       n)))
7942
7943 (defun gnus-summary-refer-thread (&optional limit)
7944   "Fetch all articles in the current thread.
7945 If LIMIT (the numerical prefix), fetch that many old headers instead
7946 of what's specified by the `gnus-refer-thread-limit' variable."
7947   (interactive "P")
7948   (let ((id (mail-header-id (gnus-summary-article-header)))
7949         (limit (if limit (prefix-numeric-value limit)
7950                  gnus-refer-thread-limit)))
7951     ;; We want to fetch LIMIT *old* headers, but we also have to
7952     ;; re-fetch all the headers in the current buffer, because many of
7953     ;; them may be undisplayed.  So we adjust LIMIT.
7954     (when (numberp limit)
7955       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7956     (unless (eq gnus-fetch-old-headers 'invisible)
7957       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7958       ;; Retrieve the headers and read them in.
7959       (if (eq (gnus-retrieve-headers
7960                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7961               'nov)
7962           (gnus-build-all-threads)
7963         (error "Can't fetch thread from backends that don't support NOV"))
7964       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7965     (gnus-summary-limit-include-thread id)))
7966
7967 (defun gnus-summary-refer-article (message-id)
7968   "Fetch an article specified by MESSAGE-ID."
7969   (interactive "sMessage-ID: ")
7970   (when (and (stringp message-id)
7971              (not (zerop (length message-id))))
7972     ;; Construct the correct Message-ID if necessary.
7973     ;; Suggested by tale@pawl.rpi.edu.
7974     (unless (string-match "^<" message-id)
7975       (setq message-id (concat "<" message-id)))
7976     (unless (string-match ">$" message-id)
7977       (setq message-id (concat message-id ">")))
7978     (let* ((header (gnus-id-to-header message-id))
7979            (sparse (and header
7980                         (gnus-summary-article-sparse-p
7981                          (mail-header-number header))
7982                         (memq (mail-header-number header)
7983                               gnus-newsgroup-limit)))
7984            number)
7985       (cond
7986        ;; If the article is present in the buffer we just go to it.
7987        ((and header
7988              (or (not (gnus-summary-article-sparse-p
7989                        (mail-header-number header)))
7990                  sparse))
7991         (prog1
7992             (gnus-summary-goto-article
7993              (mail-header-number header) nil t)
7994           (when sparse
7995             (gnus-summary-update-article (mail-header-number header)))))
7996        (t
7997         ;; We fetch the article.
7998         (catch 'found
7999           (dolist (gnus-override-method (gnus-refer-article-methods))
8000             (gnus-check-server gnus-override-method)
8001             ;; Fetch the header, and display the article.
8002             (when (setq number (gnus-summary-insert-subject message-id))
8003               (gnus-summary-select-article nil nil nil number)
8004               (throw 'found t)))
8005           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8006
8007 (defun gnus-refer-article-methods ()
8008   "Return a list of referable methods."
8009   (cond
8010    ;; No method, so we default to current and native.
8011    ((null gnus-refer-article-method)
8012     (list gnus-current-select-method gnus-select-method))
8013    ;; Current.
8014    ((eq 'current gnus-refer-article-method)
8015     (list gnus-current-select-method))
8016    ;; List of select methods.
8017    ((not (and (symbolp (car gnus-refer-article-method))
8018               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8019     (let (out)
8020       (dolist (method gnus-refer-article-method)
8021         (push (if (eq 'current method)
8022                   gnus-current-select-method
8023                 method)
8024               out))
8025       (nreverse out)))
8026    ;; One single select method.
8027    (t
8028     (list gnus-refer-article-method))))
8029
8030 (defun gnus-summary-edit-parameters ()
8031   "Edit the group parameters of the current group."
8032   (interactive)
8033   (gnus-group-edit-group gnus-newsgroup-name 'params))
8034
8035 (defun gnus-summary-customize-parameters ()
8036   "Customize the group parameters of the current group."
8037   (interactive)
8038   (gnus-group-customize gnus-newsgroup-name))
8039
8040 (defun gnus-summary-enter-digest-group (&optional force)
8041   "Enter an nndoc group based on the current article.
8042 If FORCE, force a digest interpretation.  If not, try
8043 to guess what the document format is."
8044   (interactive "P")
8045   (let ((conf gnus-current-window-configuration))
8046     (save-excursion
8047       (gnus-summary-select-article))
8048     (setq gnus-current-window-configuration conf)
8049     (let* ((name (format "%s-%d"
8050                          (gnus-group-prefixed-name
8051                           gnus-newsgroup-name (list 'nndoc ""))
8052                          (save-excursion
8053                            (set-buffer gnus-summary-buffer)
8054                            gnus-current-article)))
8055            (ogroup gnus-newsgroup-name)
8056            (params (append (gnus-info-params (gnus-get-info ogroup))
8057                            (list (cons 'to-group ogroup))
8058                            (list (cons 'save-article-group ogroup))))
8059            (case-fold-search t)
8060            (buf (current-buffer))
8061            dig to-address)
8062       (save-excursion
8063         (set-buffer gnus-original-article-buffer)
8064         ;; Have the digest group inherit the main mail address of
8065         ;; the parent article.
8066         (when (setq to-address (or (gnus-fetch-field "reply-to")
8067                                    (gnus-fetch-field "from")))
8068           (setq params (append
8069                         (list (cons 'to-address
8070                                     (funcall gnus-decode-encoded-word-function
8071                                              to-address))))))
8072         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8073         (insert-buffer-substring gnus-original-article-buffer)
8074         ;; Remove lines that may lead nndoc to misinterpret the
8075         ;; document type.
8076         (narrow-to-region
8077          (goto-char (point-min))
8078          (or (search-forward "\n\n" nil t) (point)))
8079         (goto-char (point-min))
8080         (delete-matching-lines "^Path:\\|^From ")
8081         (widen))
8082       (unwind-protect
8083           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8084                     (gnus-newsgroup-ephemeral-ignored-charsets
8085                      gnus-newsgroup-ignored-charsets))
8086                 (gnus-group-read-ephemeral-group
8087                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8088                               (nndoc-article-type
8089                                ,(if force 'mbox 'guess)))
8090                  t nil nil nil
8091                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8092                                                         "ADAPT")))))
8093               ;; Make all postings to this group go to the parent group.
8094               (nconc (gnus-info-params (gnus-get-info name))
8095                      params)
8096             ;; Couldn't select this doc group.
8097             (switch-to-buffer buf)
8098             (gnus-set-global-variables)
8099             (gnus-configure-windows 'summary)
8100             (gnus-message 3 "Article couldn't be entered?"))
8101         (kill-buffer dig)))))
8102
8103 (defun gnus-summary-read-document (n)
8104   "Open a new group based on the current article(s).
8105 This will allow you to read digests and other similar
8106 documents as newsgroups.
8107 Obeys the standard process/prefix convention."
8108   (interactive "P")
8109   (let* ((articles (gnus-summary-work-articles n))
8110          (ogroup gnus-newsgroup-name)
8111          (params (append (gnus-info-params (gnus-get-info ogroup))
8112                          (list (cons 'to-group ogroup))))
8113          article group egroup groups vgroup)
8114     (while (setq article (pop articles))
8115       (setq group (format "%s-%d" gnus-newsgroup-name article))
8116       (gnus-summary-remove-process-mark article)
8117       (when (gnus-summary-display-article article)
8118         (save-excursion
8119           (with-temp-buffer
8120             (insert-buffer-substring gnus-original-article-buffer)
8121             ;; Remove some headers that may lead nndoc to make
8122             ;; the wrong guess.
8123             (message-narrow-to-head)
8124             (goto-char (point-min))
8125             (delete-matching-lines "^\\(Path\\):\\|^From ")
8126             (widen)
8127             (if (setq egroup
8128                       (gnus-group-read-ephemeral-group
8129                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8130                                      (nndoc-article-type guess))
8131                        t nil t))
8132                 (progn
8133                   ;; Make all postings to this group go to the parent group.
8134                   (nconc (gnus-info-params (gnus-get-info egroup))
8135                          params)
8136                   (push egroup groups))
8137               ;; Couldn't select this doc group.
8138               (gnus-error 3 "Article couldn't be entered"))))))
8139     ;; Now we have selected all the documents.
8140     (cond
8141      ((not groups)
8142       (error "None of the articles could be interpreted as documents"))
8143      ((gnus-group-read-ephemeral-group
8144        (setq vgroup (format
8145                      "nnvirtual:%s-%s" gnus-newsgroup-name
8146                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8147        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8148        t
8149        (cons (current-buffer) 'summary)))
8150      (t
8151       (error "Couldn't select virtual nndoc group")))))
8152
8153 (defun gnus-summary-isearch-article (&optional regexp-p)
8154   "Do incremental search forward on the current article.
8155 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8156   (interactive "P")
8157   (let* ((gnus-inhibit-treatment t)
8158          (old (gnus-summary-select-article)))
8159     (gnus-configure-windows 'article)
8160     (gnus-eval-in-buffer-window gnus-article-buffer
8161       (save-restriction
8162         (widen)
8163         (when (eq 'old old)
8164           (gnus-article-show-all-headers))
8165         (goto-char (point-min))
8166         (isearch-forward regexp-p)))))
8167
8168 (defun gnus-summary-search-article-forward (regexp &optional backward)
8169   "Search for an article containing REGEXP forward.
8170 If BACKWARD, search backward instead."
8171   (interactive
8172    (list (read-string
8173           (format "Search article %s (regexp%s): "
8174                   (if current-prefix-arg "backward" "forward")
8175                   (if gnus-last-search-regexp
8176                       (concat ", default " gnus-last-search-regexp)
8177                     "")))
8178          current-prefix-arg))
8179   (if (string-equal regexp "")
8180       (setq regexp (or gnus-last-search-regexp ""))
8181     (setq gnus-last-search-regexp regexp)
8182     (setq gnus-article-before-search gnus-current-article))
8183   ;; Intentionally set gnus-last-article.
8184   (setq gnus-last-article gnus-article-before-search)
8185   (let ((gnus-last-article gnus-last-article))
8186     (if (gnus-summary-search-article regexp backward)
8187         (gnus-summary-show-thread)
8188       (error "Search failed: \"%s\"" regexp))))
8189
8190 (defun gnus-summary-search-article-backward (regexp)
8191   "Search for an article containing REGEXP backward."
8192   (interactive
8193    (list (read-string
8194           (format "Search article backward (regexp%s): "
8195                   (if gnus-last-search-regexp
8196                       (concat ", default " gnus-last-search-regexp)
8197                     "")))))
8198   (gnus-summary-search-article-forward regexp 'backward))
8199
8200 (eval-when-compile
8201   (defmacro gnus-summary-search-article-position-point (regexp backward)
8202     "Dehighlight the last matched text and goto the beginning position."
8203     (` (if (and gnus-summary-search-article-matched-data
8204                 (let ((text (caddr gnus-summary-search-article-matched-data))
8205                       (inhibit-read-only t)
8206                       buffer-read-only)
8207                   (delete-region
8208                    (goto-char (car gnus-summary-search-article-matched-data))
8209                    (cadr gnus-summary-search-article-matched-data))
8210                   (insert text)
8211                   (string-match (, regexp) text)))
8212            (if (, backward) (beginning-of-line) (end-of-line))
8213          (goto-char (if (, backward) (point-max) (point-min))))))
8214
8215   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8216     "Place point where X-Face image is displayed."
8217     (if (featurep 'xemacs)
8218         (` (let ((end (if (search-forward "\n\n" nil t)
8219                           (goto-char (1- (point)))
8220                         (point-min)))
8221                  extent)
8222              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8223              (unless (and (re-search-forward "^From:" end t)
8224                           (setq extent (extent-at (point)))
8225                           (extent-begin-glyph extent))
8226                (goto-char (, opoint)))))
8227       (` (let ((end (if (search-forward "\n\n" nil t)
8228                         (goto-char (1- (point)))
8229                       (point-min)))
8230                (start (or (search-backward "\n\n" nil t) (point-min))))
8231            (goto-char
8232             (or (text-property-any start end 'x-face-image t);; x-face-e21
8233                 (text-property-any start end 'x-face-mule-bitmap-image t)
8234                 (, opoint)))))))
8235
8236   (defmacro gnus-summary-search-article-highlight-matched-text
8237     (backward treated x-face)
8238     "Highlight matched text in the function `gnus-summary-search-article'."
8239     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8240              (end (set-marker (make-marker) (match-end 0)))
8241              (inhibit-read-only t)
8242              buffer-read-only)
8243          (unless treated
8244            (let ((,@
8245                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8246                     (mapcar
8247                      (lambda (item) (setq items (delq item items)))
8248                      '(gnus-treat-buttonize
8249                        gnus-treat-fill-article
8250                        gnus-treat-fill-long-lines
8251                        gnus-treat-emphasize
8252                        gnus-treat-highlight-headers
8253                        gnus-treat-highlight-citation
8254                        gnus-treat-highlight-signature
8255                        gnus-treat-overstrike
8256                        gnus-treat-display-xface
8257                        gnus-treat-buttonize-head
8258                        gnus-treat-decode-article-as-default-mime-charset))
8259                     (static-if (featurep 'xemacs)
8260                         items
8261                       (cons '(x-face-mule-delete-x-face-field
8262                               (quote never))
8263                             items))))
8264                  (gnus-treat-display-xface
8265                   (when (, x-face) gnus-treat-display-xface)))
8266              (gnus-article-prepare-mime-display)))
8267          (goto-char (if (, backward) start end))
8268          (when (, x-face)
8269            (gnus-summary-search-article-highlight-goto-x-face (point)))
8270          (setq gnus-summary-search-article-matched-data
8271                (list start end (buffer-substring start end)))
8272          (unless (eq start end);; matched text has been deleted. :-<
8273            (put-text-property start end 'face
8274                               (or (find-face 'isearch)
8275                                   'secondary-selection))))))
8276   )
8277
8278 (defun gnus-summary-search-article (regexp &optional backward)
8279   "Search for an article containing REGEXP.
8280 Optional argument BACKWARD means do search for backward.
8281 `gnus-select-article-hook' is not called during the search."
8282   ;; We have to require this here to make sure that the following
8283   ;; dynamic binding isn't shadowed by autoloading.
8284   (require 'gnus-async)
8285   (require 'gnus-art)
8286   (let ((gnus-select-article-hook nil)  ;Disable hook.
8287         (gnus-article-prepare-hook nil)
8288         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8289         (gnus-use-article-prefetch nil)
8290         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8291         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8292         (sum (current-buffer))
8293         (found nil)
8294         point treated)
8295     (gnus-save-hidden-threads
8296       (static-if (featurep 'xemacs)
8297           (let ((gnus-inhibit-treatment t))
8298             (setq treated (eq 'old (gnus-summary-select-article)))
8299             (when (and treated
8300                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8301                                  (window-live-p (get-buffer-window
8302                                                  gnus-article-buffer t)))))
8303               (gnus-summary-select-article nil t)
8304               (setq treated nil)))
8305         (let ((gnus-inhibit-treatment t)
8306               (x-face-mule-delete-x-face-field 'never))
8307           (setq treated (eq 'old (gnus-summary-select-article)))
8308           (when (and treated
8309                      (not
8310                       (and (gnus-buffer-live-p gnus-article-buffer)
8311                            (window-live-p (get-buffer-window
8312                                            gnus-article-buffer t))
8313                            (or (not (string-match "^\\^X-Face:" regexp))
8314                                (with-current-buffer gnus-article-buffer
8315                                  gnus-summary-search-article-matched-data)))))
8316             (gnus-summary-select-article nil t)
8317             (setq treated nil))))
8318       (set-buffer gnus-article-buffer)
8319       (widen)
8320       (if treated
8321           (progn
8322             (gnus-article-show-all-headers)
8323             (gnus-summary-search-article-position-point regexp backward))
8324         (goto-char (if backward (point-max) (point-min))))
8325       (while (not found)
8326         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8327         (if (if backward
8328                 (re-search-backward regexp nil t)
8329               (re-search-forward regexp nil t))
8330             ;; We found the regexp.
8331             (progn
8332               (gnus-summary-search-article-highlight-matched-text
8333                backward treated (string-match "^\\^X-Face:" regexp))
8334               (setq found 'found)
8335               (forward-line
8336                (/ (- 2 (window-height
8337                         (get-buffer-window gnus-article-buffer t)))
8338                   2))
8339               (set-window-start
8340                (get-buffer-window (current-buffer))
8341                (point))
8342               (set-buffer sum)
8343               (setq point (point)))
8344           ;; We didn't find it, so we go to the next article.
8345           (set-buffer sum)
8346           (setq found 'not)
8347           (while (eq found 'not)
8348             (if (not (if backward (gnus-summary-find-prev)
8349                        (gnus-summary-find-next)))
8350                 ;; No more articles.
8351                 (setq found t)
8352               ;; Select the next article and adjust point.
8353               (unless (gnus-summary-article-sparse-p
8354                        (gnus-summary-article-number))
8355                 (setq found nil)
8356                 (let ((gnus-inhibit-treatment t))
8357                   (gnus-summary-select-article))
8358                 (setq treated nil)
8359                 (set-buffer gnus-article-buffer)
8360                 (widen)
8361                 (goto-char (if backward (point-max) (point-min))))))))
8362       (gnus-message 7 ""))
8363     ;; Return whether we found the regexp.
8364     (when (eq found 'found)
8365       (goto-char point)
8366       (gnus-summary-show-thread)
8367       (gnus-summary-goto-subject gnus-current-article)
8368       (gnus-summary-position-point)
8369       t)))
8370
8371 (defun gnus-find-matching-articles (header regexp)
8372   "Return a list of all articles that match REGEXP on HEADER.
8373 This search includes all articles in the current group that Gnus has
8374 fetched headers for, whether they are displayed or not."
8375   (let ((articles nil)
8376         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8377         (case-fold-search t))
8378     (dolist (header gnus-newsgroup-headers)
8379       (when (string-match regexp (funcall func header))
8380         (push (mail-header-number header) articles)))
8381     (nreverse articles)))
8382
8383 (defun gnus-summary-find-matching (header regexp &optional backward unread
8384                                           not-case-fold not-matching)
8385   "Return a list of all articles that match REGEXP on HEADER.
8386 The search stars on the current article and goes forwards unless
8387 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8388 If UNREAD is non-nil, only unread articles will
8389 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8390 in the comparisons. If NOT-MATCHING, return a list of all articles that
8391 not match REGEXP on HEADER."
8392   (let ((case-fold-search (not not-case-fold))
8393         articles d func)
8394     (if (consp header)
8395         (if (eq (car header) 'extra)
8396             (setq func
8397                   `(lambda (h)
8398                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8399                          "")))
8400           (error "%s is an invalid header" header))
8401       (unless (fboundp (intern (concat "mail-header-" header)))
8402         (error "%s is not a valid header" header))
8403       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8404     (dolist (d (if (eq backward 'all)
8405                    gnus-newsgroup-data
8406                  (gnus-data-find-list
8407                   (gnus-summary-article-number)
8408                   (gnus-data-list backward))))
8409       (when (and (or (not unread)       ; We want all articles...
8410                      (gnus-data-unread-p d)) ; Or just unreads.
8411                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8412                  (if not-matching
8413                      (not (string-match
8414                            regexp
8415                            (funcall func (gnus-data-header d))))
8416                    (string-match regexp
8417                                  (funcall func (gnus-data-header d)))))
8418         (push (gnus-data-number d) articles))) ; Success!
8419     (nreverse articles)))
8420
8421 (defun gnus-summary-execute-command (header regexp command &optional backward)
8422   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8423 If HEADER is an empty string (or nil), the match is done on the entire
8424 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8425   (interactive
8426    (list (let ((completion-ignore-case t))
8427            (completing-read
8428             "Header name: "
8429             (mapcar (lambda (header) (list (format "%s" header)))
8430                     (append
8431                      '("Number" "Subject" "From" "Lines" "Date"
8432                        "Message-ID" "Xref" "References" "Body")
8433                      gnus-extra-headers))
8434             nil 'require-match))
8435          (read-string "Regexp: ")
8436          (read-key-sequence "Command: ")
8437          current-prefix-arg))
8438   (when (equal header "Body")
8439     (setq header ""))
8440   ;; Hidden thread subtrees must be searched as well.
8441   (gnus-summary-show-all-threads)
8442   ;; We don't want to change current point nor window configuration.
8443   (save-excursion
8444     (save-window-excursion
8445       (let (gnus-visual
8446             gnus-treat-strip-trailing-blank-lines
8447             gnus-treat-strip-leading-blank-lines
8448             gnus-treat-strip-multiple-blank-lines
8449             gnus-treat-hide-boring-headers
8450             gnus-treat-fold-newsgroups
8451             gnus-article-prepare-hook)
8452         (gnus-message 6 "Executing %s..." (key-description command))
8453         ;; We'd like to execute COMMAND interactively so as to give arguments.
8454         (gnus-execute header regexp
8455                       `(call-interactively ',(key-binding command))
8456                       backward)
8457         (gnus-message 6 "Executing %s...done" (key-description command))))))
8458
8459 (defun gnus-summary-beginning-of-article ()
8460   "Scroll the article back to the beginning."
8461   (interactive)
8462   (gnus-summary-select-article)
8463   (gnus-configure-windows 'article)
8464   (gnus-eval-in-buffer-window gnus-article-buffer
8465     (widen)
8466     (goto-char (point-min))
8467     (when gnus-page-broken
8468       (gnus-narrow-to-page))))
8469
8470 (defun gnus-summary-end-of-article ()
8471   "Scroll to the end of the article."
8472   (interactive)
8473   (gnus-summary-select-article)
8474   (gnus-configure-windows 'article)
8475   (gnus-eval-in-buffer-window gnus-article-buffer
8476     (widen)
8477     (goto-char (point-max))
8478     (recenter -3)
8479     (when gnus-page-broken
8480       (gnus-narrow-to-page))))
8481
8482 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8483   "Truncate to LEN and quote all \"(\"'s in STRING."
8484   (gnus-replace-in-string (if (and len (> (length string) len))
8485                               (substring string 0 len)
8486                             string)
8487                           "[()]" "\\\\\\&"))
8488
8489 (defun gnus-summary-print-article (&optional filename n)
8490   "Generate and print a PostScript image of the N next (mail) articles.
8491
8492 If N is negative, print the N previous articles.  If N is nil and articles
8493 have been marked with the process mark, print these instead.
8494
8495 If the optional first argument FILENAME is nil, send the image to the
8496 printer.  If FILENAME is a string, save the PostScript image in a file with
8497 that name.  If FILENAME is a number, prompt the user for the name of the file
8498 to save in."
8499   (interactive (list (ps-print-preprint current-prefix-arg)))
8500   (dolist (article (gnus-summary-work-articles n))
8501     (gnus-summary-select-article nil nil 'pseudo article)
8502     (gnus-eval-in-buffer-window gnus-article-buffer
8503       (gnus-print-buffer))
8504     (gnus-summary-remove-process-mark article))
8505   (ps-despool filename))
8506
8507 (defun gnus-print-buffer ()
8508   (let ((buffer (generate-new-buffer " *print*")))
8509     (unwind-protect
8510         (progn
8511           (copy-to-buffer buffer (point-min) (point-max))
8512           (set-buffer buffer)
8513           (gnus-article-delete-invisible-text)
8514           (gnus-remove-text-with-property 'gnus-decoration)
8515           (when (gnus-visual-p 'article-highlight 'highlight)
8516             ;; Copy-to-buffer doesn't copy overlay.  So redo
8517             ;; highlight.
8518             (let ((gnus-article-buffer buffer))
8519               (gnus-article-highlight-citation t)
8520               (gnus-article-highlight-signature)))
8521           (let ((ps-left-header
8522                  (list
8523                   (concat "("
8524                           (gnus-summary-print-truncate-and-quote
8525                            (mail-header-subject gnus-current-headers)
8526                            66) ")")
8527                   (concat "("
8528                           (gnus-summary-print-truncate-and-quote
8529                            (mail-header-from gnus-current-headers)
8530                            45) ")")))
8531                 (ps-right-header
8532                  (list
8533                   "/pagenumberstring load"
8534                   (concat "("
8535                           (mail-header-date gnus-current-headers) ")"))))
8536             (gnus-run-hooks 'gnus-ps-print-hook)
8537             (save-excursion
8538               (if window-system
8539                   (ps-spool-buffer-with-faces)
8540                 (ps-spool-buffer)))))
8541       (kill-buffer buffer))))
8542
8543 (defun gnus-summary-show-article (&optional arg)
8544   "Force redisplaying of the current article.
8545 If ARG (the prefix) is a number, show the article with the charset
8546 defined in `gnus-summary-show-article-charset-alist', or the charset
8547 input.
8548 If ARG (the prefix) is non-nil and not a number, show the raw article
8549 without any article massaging functions being run.  Normally, the key strokes
8550 are `C-u g'."
8551   (interactive "P")
8552   (cond
8553    ((numberp arg)
8554     (gnus-summary-show-article t)
8555     (let* ((gnus-newsgroup-charset
8556             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8557                 (mm-read-coding-system
8558                  "View as charset: " ;; actually it is coding system.
8559                  (save-excursion
8560                    (set-buffer gnus-article-buffer)
8561                    (mm-detect-coding-region (point) (point-max))))))
8562            (default-mime-charset gnus-newsgroup-charset)
8563            (gnus-newsgroup-ignored-charsets 'gnus-all))
8564       (gnus-summary-select-article nil 'force)
8565       (let ((deps gnus-newsgroup-dependencies)
8566             head header lines)
8567         (save-excursion
8568           (set-buffer gnus-original-article-buffer)
8569           (save-restriction
8570             (message-narrow-to-head)
8571             (setq head (buffer-string))
8572             (goto-char (point-min))
8573             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8574               (goto-char (point-max))
8575               (widen)
8576               (setq lines (1- (count-lines (point) (point-max))))))
8577           (with-temp-buffer
8578             (insert (format "211 %d Article retrieved.\n"
8579                             (cdr gnus-article-current)))
8580             (insert head)
8581             (if lines (insert (format "Lines: %d\n" lines)))
8582             (insert ".\n")
8583             (let ((nntp-server-buffer (current-buffer)))
8584               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8585         (gnus-data-set-header
8586          (gnus-data-find (cdr gnus-article-current))
8587          header)
8588         (gnus-summary-update-article-line
8589          (cdr gnus-article-current) header)
8590         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8591           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8592    ((not arg)
8593     ;; Select the article the normal way.
8594     (gnus-summary-select-article nil 'force))
8595    (t
8596     ;; We have to require this here to make sure that the following
8597     ;; dynamic binding isn't shadowed by autoloading.
8598     (require 'gnus-async)
8599     (require 'gnus-art)
8600     ;; Bind the article treatment functions to nil.
8601     (let ((gnus-have-all-headers t)
8602           gnus-article-prepare-hook
8603           gnus-article-decode-hook
8604           gnus-break-pages
8605           gnus-show-mime
8606           (gnus-inhibit-treatment t))
8607       (gnus-summary-select-article nil 'force))))
8608   (gnus-summary-goto-subject gnus-current-article)
8609   (gnus-summary-position-point))
8610
8611 (defun gnus-summary-show-raw-article ()
8612   "Show the raw article without any article massaging functions being run."
8613   (interactive)
8614   (gnus-summary-show-article t))
8615
8616 (defun gnus-summary-verbose-headers (&optional arg)
8617   "Toggle permanent full header display.
8618 If ARG is a positive number, turn header display on.
8619 If ARG is a negative number, turn header display off."
8620   (interactive "P")
8621   (setq gnus-show-all-headers
8622         (cond ((or (not (numberp arg))
8623                    (zerop arg))
8624                (not gnus-show-all-headers))
8625               ((natnump arg)
8626                t)))
8627   (gnus-summary-show-article))
8628
8629 (defun gnus-summary-toggle-header (&optional arg)
8630   "Show the headers if they are hidden, or hide them if they are shown.
8631 If ARG is a positive number, show the entire header.
8632 If ARG is a negative number, hide the unwanted header lines."
8633   (interactive "P")
8634   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8635                      (get-buffer-window gnus-article-buffer t))))
8636     (with-current-buffer gnus-article-buffer
8637       (widen)
8638       (article-narrow-to-head)
8639       (let* ((buffer-read-only nil)
8640              (inhibit-point-motion-hooks t)
8641              (hidden (if (numberp arg)
8642                          (>= arg 0)
8643                        (gnus-article-hidden-text-p 'headers)))
8644              s e)
8645         (delete-region (point-min) (point-max))
8646         (with-current-buffer gnus-original-article-buffer
8647           (goto-char (setq s (point-min)))
8648           (setq e (if (search-forward "\n\n" nil t)
8649                       (1- (point))
8650                     (point-max))))
8651         (insert-buffer-substring gnus-original-article-buffer s e)
8652         (article-decode-encoded-words)
8653         (if hidden
8654             (let ((gnus-treat-hide-headers nil)
8655                   (gnus-treat-hide-boring-headers nil))
8656               (gnus-delete-wash-type 'headers)
8657               (gnus-treat-article 'head))
8658           (gnus-treat-article 'head))
8659         (widen)
8660         (if window
8661             (set-window-start window (goto-char (point-min))))
8662         (setq gnus-page-broken
8663               (when gnus-break-pages
8664                 (gnus-narrow-to-page)
8665                 t))
8666         (gnus-set-mode-line 'article)))))
8667
8668 (defun gnus-summary-show-all-headers ()
8669   "Make all header lines visible."
8670   (interactive)
8671   (gnus-summary-toggle-header 1))
8672
8673 (defun gnus-summary-toggle-mime (&optional arg)
8674   "Toggle MIME processing.
8675 If ARG is a positive number, turn MIME processing on."
8676   (interactive "P")
8677   (setq gnus-show-mime
8678         (if (null arg)
8679             (not gnus-show-mime)
8680           (> (prefix-numeric-value arg) 0)))
8681   (gnus-summary-select-article t 'force))
8682
8683 (defun gnus-summary-caesar-message (&optional arg)
8684   "Caesar rotate the current article by 13.
8685 The numerical prefix specifies how many places to rotate each letter
8686 forward."
8687   (interactive "P")
8688   (gnus-summary-select-article)
8689   (let ((mail-header-separator ""))
8690     (gnus-eval-in-buffer-window gnus-article-buffer
8691       (save-restriction
8692         (widen)
8693         (let ((start (window-start))
8694               buffer-read-only)
8695           (message-caesar-buffer-body arg)
8696           (set-window-start (get-buffer-window (current-buffer)) start))))))
8697
8698 (autoload 'unmorse-region "morse"
8699   "Convert morse coded text in region to ordinary ASCII text."
8700   t)
8701
8702 (defun gnus-summary-morse-message (&optional arg)
8703   "Morse decode the current article."
8704   (interactive "P")
8705   (gnus-summary-select-article)
8706   (let ((mail-header-separator ""))
8707     (gnus-eval-in-buffer-window gnus-article-buffer
8708       (save-excursion
8709         (save-restriction
8710           (widen)
8711           (let ((pos (window-start))
8712                 buffer-read-only)
8713             (goto-char (point-min))
8714             (when (message-goto-body)
8715               (gnus-narrow-to-body))
8716             (goto-char (point-min))
8717             (while (re-search-forward "·" (point-max) t)
8718               (replace-match "."))
8719             (unmorse-region (point-min) (point-max))
8720             (widen)
8721             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8722
8723 (defun gnus-summary-stop-page-breaking ()
8724   "Stop page breaking in the current article."
8725   (interactive)
8726   (gnus-summary-select-article)
8727   (gnus-eval-in-buffer-window gnus-article-buffer
8728     (widen)
8729     (when (gnus-visual-p 'page-marker)
8730       (let ((buffer-read-only nil))
8731         (gnus-remove-text-with-property 'gnus-prev)
8732         (gnus-remove-text-with-property 'gnus-next))
8733       (setq gnus-page-broken nil))))
8734
8735 (defun gnus-summary-move-article (&optional n to-newsgroup
8736                                             select-method action)
8737   "Move the current article to a different newsgroup.
8738 If N is a positive number, move the N next articles.
8739 If N is a negative number, move the N previous articles.
8740 If N is nil and any articles have been marked with the process mark,
8741 move those articles instead.
8742 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8743 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8744 re-spool using this method.
8745
8746 When called interactively with TO-NEWSGROUP being nil, the value of
8747 the variable `gnus-move-split-methods' is used for finding a default
8748 for the target newsgroup.
8749
8750 For this function to work, both the current newsgroup and the
8751 newsgroup that you want to move to have to support the `request-move'
8752 and `request-accept' functions.
8753
8754 ACTION can be either `move' (the default), `crosspost' or `copy'."
8755   (interactive "P")
8756   (unless action
8757     (setq action 'move))
8758   ;; Check whether the source group supports the required functions.
8759   (cond ((and (eq action 'move)
8760               (not (gnus-check-backend-function
8761                     'request-move-article gnus-newsgroup-name)))
8762          (error "The current group does not support article moving"))
8763         ((and (eq action 'crosspost)
8764               (not (gnus-check-backend-function
8765                     'request-replace-article gnus-newsgroup-name)))
8766          (error "The current group does not support article editing")))
8767   (let ((articles (gnus-summary-work-articles n))
8768         (prefix (if (gnus-check-backend-function
8769                      'request-move-article gnus-newsgroup-name)
8770                     (gnus-group-real-prefix gnus-newsgroup-name)
8771                   ""))
8772         (names '((move "Move" "Moving")
8773                  (copy "Copy" "Copying")
8774                  (crosspost "Crosspost" "Crossposting")))
8775         (copy-buf (save-excursion
8776                     (nnheader-set-temp-buffer " *copy article*")))
8777         (default-marks gnus-article-mark-lists)
8778         (no-expire-marks (delete '(expirable . expire)
8779                                  (copy-sequence gnus-article-mark-lists)))
8780         art-group to-method new-xref article to-groups)
8781     (unless (assq action names)
8782       (error "Unknown action %s" action))
8783     ;; Read the newsgroup name.
8784     (when (and (not to-newsgroup)
8785                (not select-method))
8786       (if (and gnus-move-split-methods
8787                (not
8788                 (and (memq gnus-current-article articles)
8789                      (gnus-buffer-live-p gnus-original-article-buffer))))
8790           ;; When `gnus-move-split-methods' is non-nil, we have to
8791           ;; select an article to give `gnus-read-move-group-name' an
8792           ;; opportunity to suggest an appropriate default.  However,
8793           ;; we needn't render or mark the article.
8794           (let ((gnus-display-mime-function nil)
8795                 (gnus-article-prepare-hook nil)
8796                 (gnus-mark-article-hook nil))
8797             (gnus-summary-select-article nil nil nil (car articles))))
8798       (setq to-newsgroup
8799             (gnus-read-move-group-name
8800              (cadr (assq action names))
8801              (symbol-value (intern (format "gnus-current-%s-group" action)))
8802              articles prefix))
8803       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8804     (setq to-method (or select-method
8805                         (gnus-server-to-method
8806                          (gnus-group-method to-newsgroup))))
8807     ;; Check the method we are to move this article to...
8808     (unless (gnus-check-backend-function
8809              'request-accept-article (car to-method))
8810       (error "%s does not support article copying" (car to-method)))
8811     (unless (gnus-check-server to-method)
8812       (error "Can't open server %s" (car to-method)))
8813     (gnus-message 6 "%s to %s: %s..."
8814                   (caddr (assq action names))
8815                   (or (car select-method) to-newsgroup) articles)
8816     (while articles
8817       (setq article (pop articles))
8818       (setq
8819        art-group
8820        (cond
8821         ;; Move the article.
8822         ((eq action 'move)
8823          ;; Remove this article from future suppression.
8824          (gnus-dup-unsuppress-article article)
8825          (gnus-request-move-article
8826           article                       ; Article to move
8827           gnus-newsgroup-name           ; From newsgroup
8828           (nth 1 (gnus-find-method-for-group
8829                   gnus-newsgroup-name)) ; Server
8830           (list 'gnus-request-accept-article
8831                 to-newsgroup (list 'quote select-method)
8832                 (not articles) t)       ; Accept form
8833           (not articles)))              ; Only save nov last time
8834         ;; Copy the article.
8835         ((eq action 'copy)
8836          (save-excursion
8837            (set-buffer copy-buf)
8838            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8839              (gnus-request-accept-article
8840               to-newsgroup select-method (not articles) t))))
8841         ;; Crosspost the article.
8842         ((eq action 'crosspost)
8843          (let ((xref (message-tokenize-header
8844                       (mail-header-xref (gnus-summary-article-header article))
8845                       " ")))
8846            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8847                                   ":" (number-to-string article)))
8848            (unless xref
8849              (setq xref (list (system-name))))
8850            (setq new-xref
8851                  (concat
8852                   (mapconcat 'identity
8853                              (delete "Xref:" (delete new-xref xref))
8854                              " ")
8855                   " " new-xref))
8856            (save-excursion
8857              (set-buffer copy-buf)
8858              ;; First put the article in the destination group.
8859              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8860              (when (consp (setq art-group
8861                                 (gnus-request-accept-article
8862                                  to-newsgroup select-method (not articles))))
8863                (setq new-xref (concat new-xref " " (car art-group)
8864                                       ":"
8865                                       (number-to-string (cdr art-group))))
8866                ;; Now we have the new Xrefs header, so we insert
8867                ;; it and replace the new article.
8868                (nnheader-replace-header "Xref" new-xref)
8869                (gnus-request-replace-article
8870                 (cdr art-group) to-newsgroup (current-buffer))
8871                art-group))))))
8872       (cond
8873        ((not art-group)
8874         (gnus-message 1 "Couldn't %s article %s: %s"
8875                       (cadr (assq action names)) article
8876                       (nnheader-get-report (car to-method))))
8877        ((eq art-group 'junk)
8878         (when (eq action 'move)
8879           (gnus-summary-mark-article article gnus-canceled-mark)
8880           (gnus-message 4 "Deleted article %s" article)))
8881        (t
8882         (let* ((pto-group (gnus-group-prefixed-name
8883                            (car art-group) to-method))
8884                (entry
8885                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8886                (info (nth 2 entry))
8887                (to-group (gnus-info-group info))
8888                to-marks)
8889           ;; Update the group that has been moved to.
8890           (when (and info
8891                      (memq action '(move copy)))
8892             (unless (member to-group to-groups)
8893               (push to-group to-groups))
8894
8895             (unless (memq article gnus-newsgroup-unreads)
8896               (push 'read to-marks)
8897               (gnus-info-set-read
8898                info (gnus-add-to-range (gnus-info-read info)
8899                                        (list (cdr art-group)))))
8900
8901             ;; See whether the article is to be put in the cache.
8902             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8903                              default-marks
8904                            no-expire-marks))
8905                   (to-article (cdr art-group)))
8906
8907               ;; Enter the article into the cache in the new group,
8908               ;; if that is required.
8909               (when gnus-use-cache
8910                 (gnus-cache-possibly-enter-article
8911                  to-group to-article
8912                  (let ((header (copy-sequence
8913                                 (gnus-summary-article-header article))))
8914                    (mail-header-set-number header to-article)
8915                    header)
8916                  (memq article gnus-newsgroup-marked)
8917                  (memq article gnus-newsgroup-dormant)
8918                  (memq article gnus-newsgroup-unreads)))
8919
8920               (when gnus-preserve-marks
8921                 ;; Copy any marks over to the new group.
8922                 (when (and (equal to-group gnus-newsgroup-name)
8923                            (not (memq article gnus-newsgroup-unreads)))
8924                   ;; Mark this article as read in this group.
8925                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8926                   (setcdr (gnus-active to-group) to-article)
8927                   (setcdr gnus-newsgroup-active to-article))
8928
8929                 (while marks
8930                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8931                     (when (memq article (symbol-value
8932                                          (intern (format "gnus-newsgroup-%s"
8933                                                          (caar marks)))))
8934                       (push (cdar marks) to-marks)
8935                       ;; If the other group is the same as this group,
8936                       ;; then we have to add the mark to the list.
8937                       (when (equal to-group gnus-newsgroup-name)
8938                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8939                              (cons to-article
8940                                    (symbol-value
8941                                     (intern (format "gnus-newsgroup-%s"
8942                                                     (caar marks)))))))
8943                       ;; Copy the marks to other group.
8944                       (gnus-add-marked-articles
8945                        to-group (cdar marks) (list to-article) info)))
8946                   (setq marks (cdr marks)))
8947
8948                 (gnus-request-set-mark
8949                  to-group (list (list (list to-article) 'add to-marks))))
8950
8951               (gnus-dribble-enter
8952                (concat "(gnus-group-set-info '"
8953                        (gnus-prin1-to-string (gnus-get-info to-group))
8954                        ")"))))
8955
8956           ;; Update the Xref header in this article to point to
8957           ;; the new crossposted article we have just created.
8958           (when (eq action 'crosspost)
8959             (save-excursion
8960               (set-buffer copy-buf)
8961               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8962               (nnheader-replace-header "Xref" new-xref)
8963               (gnus-request-replace-article
8964                article gnus-newsgroup-name (current-buffer)))))
8965
8966         ;;;!!!Why is this necessary?
8967         (set-buffer gnus-summary-buffer)
8968
8969         (gnus-summary-goto-subject article)
8970         (when (eq action 'move)
8971           (gnus-summary-mark-article article gnus-canceled-mark))))
8972       (gnus-summary-remove-process-mark article))
8973     ;; Re-activate all groups that have been moved to.
8974     (save-excursion
8975       (set-buffer gnus-group-buffer)
8976       (let ((gnus-group-marked to-groups))
8977         (gnus-group-get-new-news-this-group nil t)))
8978
8979     (gnus-kill-buffer copy-buf)
8980     (gnus-summary-position-point)
8981     (gnus-set-mode-line 'summary)))
8982
8983 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8984   "Move the current article to a different newsgroup.
8985 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8986 When called interactively, if TO-NEWSGROUP is nil, use the value of
8987 the variable `gnus-move-split-methods' for finding a default target
8988 newsgroup.
8989 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8990 re-spool using this method."
8991   (interactive "P")
8992   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8993
8994 (defun gnus-summary-crosspost-article (&optional n)
8995   "Crosspost the current article to some other group."
8996   (interactive "P")
8997   (gnus-summary-move-article n nil nil 'crosspost))
8998
8999 (defcustom gnus-summary-respool-default-method nil
9000   "Default method type for respooling an article.
9001 If nil, use to the current newsgroup method."
9002   :type 'symbol
9003   :group 'gnus-summary-mail)
9004
9005 (defcustom gnus-summary-display-while-building nil
9006   "If not-nil, show and update the summary buffer as it's being built.
9007 If the value is t, update the buffer after every line is inserted.  If
9008 the value is an integer (N), update the display every N lines."
9009   :group 'gnus-thread
9010   :type '(choice (const :tag "off" nil)
9011                  number
9012                  (const :tag "frequently" t)))
9013
9014 (defun gnus-summary-respool-article (&optional n method)
9015   "Respool the current article.
9016 The article will be squeezed through the mail spooling process again,
9017 which means that it will be put in some mail newsgroup or other
9018 depending on `nnmail-split-methods'.
9019 If N is a positive number, respool the N next articles.
9020 If N is a negative number, respool the N previous articles.
9021 If N is nil and any articles have been marked with the process mark,
9022 respool those articles instead.
9023
9024 Respooling can be done both from mail groups and \"real\" newsgroups.
9025 In the former case, the articles in question will be moved from the
9026 current group into whatever groups they are destined to.  In the
9027 latter case, they will be copied into the relevant groups."
9028   (interactive
9029    (list current-prefix-arg
9030          (let* ((methods (gnus-methods-using 'respool))
9031                 (methname
9032                  (symbol-name (or gnus-summary-respool-default-method
9033                                   (car (gnus-find-method-for-group
9034                                         gnus-newsgroup-name)))))
9035                 (method
9036                  (gnus-completing-read-with-default
9037                   methname "What backend do you want to use when respooling?"
9038                   methods nil t nil 'gnus-mail-method-history))
9039                 ms)
9040            (cond
9041             ((zerop (length (setq ms (gnus-servers-using-backend
9042                                       (intern method)))))
9043              (list (intern method) ""))
9044             ((= 1 (length ms))
9045              (car ms))
9046             (t
9047              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9048                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9049                            ms-alist))))))))
9050   (unless method
9051     (error "No method given for respooling"))
9052   (if (assoc (symbol-name
9053               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9054              (gnus-methods-using 'respool))
9055       (gnus-summary-move-article n nil method)
9056     (gnus-summary-copy-article n nil method)))
9057
9058 (defun gnus-summary-import-article (file &optional edit)
9059   "Import an arbitrary file into a mail newsgroup."
9060   (interactive "fImport file: \nP")
9061   (let ((group gnus-newsgroup-name)
9062         (now (current-time))
9063         atts lines group-art)
9064     (unless (gnus-check-backend-function 'request-accept-article group)
9065       (error "%s does not support article importing" group))
9066     (or (file-readable-p file)
9067         (not (file-regular-p file))
9068         (error "Can't read %s" file))
9069     (save-excursion
9070       (set-buffer (gnus-get-buffer-create " *import file*"))
9071       (erase-buffer)
9072       (nnheader-insert-file-contents file)
9073       (goto-char (point-min))
9074       (if (nnheader-article-p)
9075           (save-restriction
9076             (goto-char (point-min))
9077             (search-forward "\n\n" nil t)
9078             (narrow-to-region (point-min) (1- (point)))
9079             (goto-char (point-min))
9080             (unless (re-search-forward "^date:" nil t)
9081               (goto-char (point-max))
9082               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9083         ;; This doesn't look like an article, so we fudge some headers.
9084         (setq atts (file-attributes file)
9085               lines (count-lines (point-min) (point-max)))
9086         (insert "From: " (read-string "From: ") "\n"
9087                 "Subject: " (read-string "Subject: ") "\n"
9088                 "Date: " (message-make-date (nth 5 atts)) "\n"
9089                 "Message-ID: " (message-make-message-id) "\n"
9090                 "Lines: " (int-to-string lines) "\n"
9091                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9092       (setq group-art (gnus-request-accept-article group nil t))
9093       (kill-buffer (current-buffer)))
9094     (setq gnus-newsgroup-active (gnus-activate-group group))
9095     (forward-line 1)
9096     (gnus-summary-goto-article (cdr group-art) nil t)
9097     (when edit
9098       (gnus-summary-edit-article))))
9099
9100 (defun gnus-summary-create-article ()
9101   "Create an article in a mail newsgroup."
9102   (interactive)
9103   (let ((group gnus-newsgroup-name)
9104         (now (current-time))
9105         group-art)
9106     (unless (gnus-check-backend-function 'request-accept-article group)
9107       (error "%s does not support article importing" group))
9108     (save-excursion
9109       (set-buffer (gnus-get-buffer-create " *import file*"))
9110       (erase-buffer)
9111       (goto-char (point-min))
9112       ;; This doesn't look like an article, so we fudge some headers.
9113       (insert "From: " (read-string "From: ") "\n"
9114               "Subject: " (read-string "Subject: ") "\n"
9115               "Date: " (message-make-date now) "\n"
9116               "Message-ID: " (message-make-message-id) "\n")
9117       (setq group-art (gnus-request-accept-article group nil t))
9118       (kill-buffer (current-buffer)))
9119     (setq gnus-newsgroup-active (gnus-activate-group group))
9120     (forward-line 1)
9121     (gnus-summary-goto-article (cdr group-art) nil t)
9122     (gnus-summary-edit-article)))
9123
9124 (defun gnus-summary-article-posted-p ()
9125   "Say whether the current (mail) article is available from news as well.
9126 This will be the case if the article has both been mailed and posted."
9127   (interactive)
9128   (let ((id (mail-header-references (gnus-summary-article-header)))
9129         (gnus-override-method (car (gnus-refer-article-methods))))
9130     (if (gnus-request-head id "")
9131         (gnus-message 2 "The current message was found on %s"
9132                       gnus-override-method)
9133       (gnus-message 2 "The current message couldn't be found on %s"
9134                     gnus-override-method)
9135       nil)))
9136
9137 (defun gnus-summary-expire-articles (&optional now)
9138   "Expire all articles that are marked as expirable in the current group."
9139   (interactive)
9140   (when (gnus-check-backend-function
9141          'request-expire-articles gnus-newsgroup-name)
9142     ;; This backend supports expiry.
9143     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9144            (expirable (if total
9145                           (progn
9146                             ;; We need to update the info for
9147                             ;; this group for `gnus-list-of-read-articles'
9148                             ;; to give us the right answer.
9149                             (gnus-run-hooks 'gnus-exit-group-hook)
9150                             (gnus-summary-update-info)
9151                             (gnus-list-of-read-articles gnus-newsgroup-name))
9152                         (setq gnus-newsgroup-expirable
9153                               (sort gnus-newsgroup-expirable '<))))
9154            (expiry-wait (if now 'immediate
9155                           (gnus-group-find-parameter
9156                            gnus-newsgroup-name 'expiry-wait)))
9157            (nnmail-expiry-target
9158             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9159                 nnmail-expiry-target))
9160            es)
9161       (when expirable
9162         ;; There are expirable articles in this group, so we run them
9163         ;; through the expiry process.
9164         (gnus-message 6 "Expiring articles...")
9165         (unless (gnus-check-group gnus-newsgroup-name)
9166           (error "Can't open server for %s" gnus-newsgroup-name))
9167         ;; The list of articles that weren't expired is returned.
9168         (save-excursion
9169           (if expiry-wait
9170               (let ((nnmail-expiry-wait-function nil)
9171                     (nnmail-expiry-wait expiry-wait))
9172                 (setq es (gnus-request-expire-articles
9173                           expirable gnus-newsgroup-name)))
9174             (setq es (gnus-request-expire-articles
9175                       expirable gnus-newsgroup-name)))
9176           (unless total
9177             (setq gnus-newsgroup-expirable es))
9178           ;; We go through the old list of expirable, and mark all
9179           ;; really expired articles as nonexistent.
9180           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9181             (let ((gnus-use-cache nil))
9182               (dolist (article expirable)
9183                 (when (and (not (memq article es))
9184                            (gnus-data-find article))
9185                   (gnus-summary-mark-article article gnus-canceled-mark))))))
9186         (gnus-message 6 "Expiring articles...done")))))
9187
9188 (defun gnus-summary-expire-articles-now ()
9189   "Expunge all expirable articles in the current group.
9190 This means that *all* articles that are marked as expirable will be
9191 deleted forever, right now."
9192   (interactive)
9193   (or gnus-expert-user
9194       (gnus-yes-or-no-p
9195        "Are you really, really, really sure you want to delete all these messages? ")
9196       (error "Phew!"))
9197   (gnus-summary-expire-articles t))
9198
9199 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9200 (defun gnus-summary-delete-article (&optional n)
9201   "Delete the N next (mail) articles.
9202 This command actually deletes articles.  This is not a marking
9203 command.  The article will disappear forever from your life, never to
9204 return.
9205 If N is negative, delete backwards.
9206 If N is nil and articles have been marked with the process mark,
9207 delete these instead."
9208   (interactive "P")
9209   (unless (gnus-check-backend-function 'request-expire-articles
9210                                        gnus-newsgroup-name)
9211     (error "The current newsgroup does not support article deletion"))
9212   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9213     (error "Couldn't open server"))
9214   ;; Compute the list of articles to delete.
9215   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9216         (nnmail-expiry-target 'delete)
9217         not-deleted)
9218     (if (and gnus-novice-user
9219              (not (gnus-yes-or-no-p
9220                    (format "Do you really want to delete %s forever? "
9221                            (if (> (length articles) 1)
9222                                (format "these %s articles" (length articles))
9223                              "this article")))))
9224         ()
9225       ;; Delete the articles.
9226       (setq not-deleted (gnus-request-expire-articles
9227                          articles gnus-newsgroup-name 'force))
9228       (while articles
9229         (gnus-summary-remove-process-mark (car articles))
9230         ;; The backend might not have been able to delete the article
9231         ;; after all.
9232         (unless (memq (car articles) not-deleted)
9233           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9234         (setq articles (cdr articles)))
9235       (when not-deleted
9236         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9237     (gnus-summary-position-point)
9238     (gnus-set-mode-line 'summary)
9239     not-deleted))
9240
9241 (defun gnus-summary-edit-article (&optional force)
9242   "Edit the current article.
9243 This will have permanent effect only in mail groups.
9244 If FORCE is non-nil, allow editing of articles even in read-only
9245 groups."
9246   (interactive "P")
9247   (save-excursion
9248     (set-buffer gnus-summary-buffer)
9249     (let ((mail-parse-charset gnus-newsgroup-charset)
9250           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9251       (gnus-set-global-variables)
9252       (when (and (not force)
9253                  (gnus-group-read-only-p))
9254         (error "The current newsgroup does not support article editing"))
9255       (gnus-summary-show-article t)
9256       (gnus-article-edit-article
9257        'ignore
9258        `(lambda (no-highlight)
9259           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9260                 (message-options message-options)
9261                 (message-options-set-recipient)
9262                 (mail-parse-ignored-charsets
9263                  ',gnus-newsgroup-ignored-charsets))
9264             (gnus-summary-edit-article-done
9265              ,(or (mail-header-references gnus-current-headers) "")
9266              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9267
9268 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9269
9270 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9271                                                  no-highlight)
9272   "Make edits to the current article permanent."
9273   (interactive)
9274   (save-excursion
9275     ;; The buffer restriction contains the entire article if it exists.
9276     (when (article-goto-body)
9277       (let ((lines (count-lines (point) (point-max)))
9278             (length (- (point-max) (point)))
9279             (case-fold-search t)
9280             (body (copy-marker (point))))
9281         (goto-char (point-min))
9282         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9283           (delete-region (match-beginning 1) (match-end 1))
9284           (insert (number-to-string length)))
9285         (goto-char (point-min))
9286         (when (re-search-forward
9287                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9288           (delete-region (match-beginning 1) (match-end 1))
9289           (insert (number-to-string length)))
9290         (goto-char (point-min))
9291         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9292           (delete-region (match-beginning 1) (match-end 1))
9293           (insert (number-to-string lines))))))
9294   ;; Replace the article.
9295   (let ((buf (current-buffer)))
9296     (with-temp-buffer
9297       (insert-buffer-substring buf)
9298
9299       (if (and (not read-only)
9300                (not (gnus-request-replace-article
9301                      (cdr gnus-article-current) (car gnus-article-current)
9302                      (current-buffer) t)))
9303           (error "Couldn't replace article")
9304         ;; Update the summary buffer.
9305         (if (and references
9306                  (equal (message-tokenize-header references " ")
9307                         (message-tokenize-header
9308                          (or (message-fetch-field "references") "") " ")))
9309             ;; We only have to update this line.
9310             (save-excursion
9311               (save-restriction
9312                 (message-narrow-to-head)
9313                 (let ((head (buffer-string))
9314                       header)
9315                   (with-temp-buffer
9316                     (insert (format "211 %d Article retrieved.\n"
9317                                     (cdr gnus-article-current)))
9318                     (insert head)
9319                     (insert ".\n")
9320                     (let ((nntp-server-buffer (current-buffer)))
9321                       (setq header (car (gnus-get-newsgroup-headers
9322                                          nil t))))
9323                     (save-excursion
9324                       (set-buffer gnus-summary-buffer)
9325                       (gnus-data-set-header
9326                        (gnus-data-find (cdr gnus-article-current))
9327                        header)
9328                       (gnus-summary-update-article-line
9329                        (cdr gnus-article-current) header)
9330                       (if (gnus-summary-goto-subject
9331                            (cdr gnus-article-current) nil t)
9332                           (gnus-summary-update-secondary-mark
9333                            (cdr gnus-article-current))))))))
9334           ;; Update threads.
9335           (set-buffer (or buffer gnus-summary-buffer))
9336           (gnus-summary-update-article (cdr gnus-article-current))
9337           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9338               (gnus-summary-update-secondary-mark
9339                (cdr gnus-article-current))))
9340         ;; Prettify the article buffer again.
9341         (unless no-highlight
9342           (save-excursion
9343             (set-buffer gnus-article-buffer)
9344             ;;;!!! Fix this -- article should be rehighlighted.
9345             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9346             (set-buffer gnus-original-article-buffer)
9347             (gnus-request-article
9348              (cdr gnus-article-current)
9349              (car gnus-article-current) (current-buffer))))
9350         ;; Prettify the summary buffer line.
9351         (when (gnus-visual-p 'summary-highlight 'highlight)
9352           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9353
9354 (defun gnus-summary-edit-wash (key)
9355   "Perform editing command KEY in the article buffer."
9356   (interactive
9357    (list
9358     (progn
9359       (message "%s" (concat (this-command-keys) "- "))
9360       (read-char))))
9361   (message "")
9362   (gnus-summary-edit-article)
9363   (execute-kbd-macro (concat (this-command-keys) key))
9364   (gnus-article-edit-done))
9365
9366 ;;; Respooling
9367
9368 (defun gnus-summary-respool-query (&optional silent trace)
9369   "Query where the respool algorithm would put this article."
9370   (interactive)
9371   (let (gnus-mark-article-hook)
9372     (gnus-summary-select-article)
9373     (save-excursion
9374       (set-buffer gnus-original-article-buffer)
9375       (save-restriction
9376         (message-narrow-to-head)
9377         (let ((groups (nnmail-article-group 'identity trace)))
9378           (unless silent
9379             (if groups
9380                 (message "This message would go to %s"
9381                          (mapconcat 'car groups ", "))
9382               (message "This message would go to no groups"))
9383             groups))))))
9384
9385 (defun gnus-summary-respool-trace ()
9386   "Trace where the respool algorithm would put this article.
9387 Display a buffer showing all fancy splitting patterns which matched."
9388   (interactive)
9389   (gnus-summary-respool-query nil t))
9390
9391 ;; Summary marking commands.
9392
9393 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9394   "Mark articles which has the same subject as read, and then select the next.
9395 If UNMARK is positive, remove any kind of mark.
9396 If UNMARK is negative, tick articles."
9397   (interactive "P")
9398   (when unmark
9399     (setq unmark (prefix-numeric-value unmark)))
9400   (let ((count
9401          (gnus-summary-mark-same-subject
9402           (gnus-summary-article-subject) unmark)))
9403     ;; Select next unread article.  If auto-select-same mode, should
9404     ;; select the first unread article.
9405     (gnus-summary-next-article t (and gnus-auto-select-same
9406                                       (gnus-summary-article-subject)))
9407     (gnus-message 7 "%d article%s marked as %s"
9408                   count (if (= count 1) " is" "s are")
9409                   (if unmark "unread" "read"))))
9410
9411 (defun gnus-summary-kill-same-subject (&optional unmark)
9412   "Mark articles which has the same subject as read.
9413 If UNMARK is positive, remove any kind of mark.
9414 If UNMARK is negative, tick articles."
9415   (interactive "P")
9416   (when unmark
9417     (setq unmark (prefix-numeric-value unmark)))
9418   (let ((count
9419          (gnus-summary-mark-same-subject
9420           (gnus-summary-article-subject) unmark)))
9421     ;; If marked as read, go to next unread subject.
9422     (when (null unmark)
9423       ;; Go to next unread subject.
9424       (gnus-summary-next-subject 1 t))
9425     (gnus-message 7 "%d articles are marked as %s"
9426                   count (if unmark "unread" "read"))))
9427
9428 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9429   "Mark articles with same SUBJECT as read, and return marked number.
9430 If optional argument UNMARK is positive, remove any kinds of marks.
9431 If optional argument UNMARK is negative, mark articles as unread instead."
9432   (let ((count 1))
9433     (save-excursion
9434       (cond
9435        ((null unmark)                   ; Mark as read.
9436         (while (and
9437                 (progn
9438                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9439                   (gnus-summary-show-thread) t)
9440                 (gnus-summary-find-subject subject))
9441           (setq count (1+ count))))
9442        ((> unmark 0)                    ; Tick.
9443         (while (and
9444                 (progn
9445                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9446                   (gnus-summary-show-thread) t)
9447                 (gnus-summary-find-subject subject))
9448           (setq count (1+ count))))
9449        (t                               ; Mark as unread.
9450         (while (and
9451                 (progn
9452                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9453                   (gnus-summary-show-thread) t)
9454                 (gnus-summary-find-subject subject))
9455           (setq count (1+ count)))))
9456       (gnus-set-mode-line 'summary)
9457       ;; Return the number of marked articles.
9458       count)))
9459
9460 (defun gnus-summary-mark-as-processable (n &optional unmark)
9461   "Set the process mark on the next N articles.
9462 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9463 the process mark instead.  The difference between N and the actual
9464 number of articles marked is returned."
9465   (interactive "P")
9466   (if (and (null n) (gnus-region-active-p))
9467       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9468     (setq n (prefix-numeric-value n))
9469     (let ((backward (< n 0))
9470           (n (abs n)))
9471       (while (and
9472               (> n 0)
9473               (if unmark
9474                   (gnus-summary-remove-process-mark
9475                    (gnus-summary-article-number))
9476                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9477               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9478         (setq n (1- n)))
9479       (when (/= 0 n)
9480         (gnus-message 7 "No more articles"))
9481       (gnus-summary-recenter)
9482       (gnus-summary-position-point)
9483       n)))
9484
9485 (defun gnus-summary-unmark-as-processable (n)
9486   "Remove the process mark from the next N articles.
9487 If N is negative, unmark backward instead.  The difference between N and
9488 the actual number of articles unmarked is returned."
9489   (interactive "P")
9490   (gnus-summary-mark-as-processable n t))
9491
9492 (defun gnus-summary-unmark-all-processable ()
9493   "Remove the process mark from all articles."
9494   (interactive)
9495   (save-excursion
9496     (while gnus-newsgroup-processable
9497       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9498   (gnus-summary-position-point))
9499
9500 (defun gnus-summary-add-mark (article type)
9501   "Mark ARTICLE with a mark of TYPE."
9502   (let ((vtype (car (assq type gnus-article-mark-lists)))
9503         var)
9504     (if (not vtype)
9505         (error "No such mark type: %s" type)
9506       (setq var (intern (format "gnus-newsgroup-%s" type)))
9507       (set var (cons article (symbol-value var)))
9508       (if (memq type '(processable cached replied forwarded recent saved))
9509           (gnus-summary-update-secondary-mark article)
9510         ;;; !!! This is bogus.  We should find out what primary
9511         ;;; !!! mark we want to set.
9512         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9513
9514 (defun gnus-summary-mark-as-expirable (n)
9515   "Mark N articles forward as expirable.
9516 If N is negative, mark backward instead.  The difference between N and
9517 the actual number of articles marked is returned."
9518   (interactive "p")
9519   (gnus-summary-mark-forward n gnus-expirable-mark))
9520
9521 (defun gnus-summary-mark-as-spam (n)
9522   "Mark N articles forward as spam.
9523 If N is negative, mark backward instead.  The difference between N and
9524 the actual number of articles marked is returned."
9525   (interactive "p")
9526   (gnus-summary-mark-forward n gnus-spam-mark))
9527
9528 (defun gnus-summary-mark-article-as-replied (article)
9529   "Mark ARTICLE as replied to and update the summary line.
9530 ARTICLE can also be a list of articles."
9531   (interactive (list (gnus-summary-article-number)))
9532   (let ((articles (if (listp article) article (list article))))
9533     (dolist (article articles)
9534       (push article gnus-newsgroup-replied)
9535       (let ((buffer-read-only nil))
9536         (when (gnus-summary-goto-subject article nil t)
9537           (gnus-summary-update-secondary-mark article))))))
9538
9539 (defun gnus-summary-mark-article-as-forwarded (article)
9540   "Mark ARTICLE as forwarded and update the summary line.
9541 ARTICLE can also be a list of articles."
9542   (let ((articles (if (listp article) article (list article))))
9543     (dolist (article articles)
9544       (push article gnus-newsgroup-forwarded)
9545       (let ((buffer-read-only nil))
9546         (when (gnus-summary-goto-subject article nil t)
9547           (gnus-summary-update-secondary-mark article))))))
9548
9549 (defun gnus-summary-set-bookmark (article)
9550   "Set a bookmark in current article."
9551   (interactive (list (gnus-summary-article-number)))
9552   (when (or (not (get-buffer gnus-article-buffer))
9553             (not gnus-current-article)
9554             (not gnus-article-current)
9555             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9556     (error "No current article selected"))
9557   ;; Remove old bookmark, if one exists.
9558   (gnus-pull article gnus-newsgroup-bookmarks)
9559   ;; Set the new bookmark, which is on the form
9560   ;; (article-number . line-number-in-body).
9561   (push
9562    (cons article
9563          (save-excursion
9564            (set-buffer gnus-article-buffer)
9565            (count-lines
9566             (min (point)
9567                  (save-excursion
9568                    (article-goto-body)
9569                    (point)))
9570             (point))))
9571    gnus-newsgroup-bookmarks)
9572   (gnus-message 6 "A bookmark has been added to the current article."))
9573
9574 (defun gnus-summary-remove-bookmark (article)
9575   "Remove the bookmark from the current article."
9576   (interactive (list (gnus-summary-article-number)))
9577   ;; Remove old bookmark, if one exists.
9578   (if (not (assq article gnus-newsgroup-bookmarks))
9579       (gnus-message 6 "No bookmark in current article.")
9580     (gnus-pull article gnus-newsgroup-bookmarks)
9581     (gnus-message 6 "Removed bookmark.")))
9582
9583 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9584 (defun gnus-summary-mark-as-dormant (n)
9585   "Mark N articles forward as dormant.
9586 If N is negative, mark backward instead.  The difference between N and
9587 the actual number of articles marked is returned."
9588   (interactive "p")
9589   (gnus-summary-mark-forward n gnus-dormant-mark))
9590
9591 (defun gnus-summary-set-process-mark (article)
9592   "Set the process mark on ARTICLE and update the summary line."
9593   (setq gnus-newsgroup-processable
9594         (cons article
9595               (delq article gnus-newsgroup-processable)))
9596   (when (gnus-summary-goto-subject article)
9597     (gnus-summary-show-thread)
9598     (gnus-summary-goto-subject article)
9599     (gnus-summary-update-secondary-mark article)))
9600
9601 (defun gnus-summary-remove-process-mark (article)
9602   "Remove the process mark from ARTICLE and update the summary line."
9603   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9604   (when (gnus-summary-goto-subject article)
9605     (gnus-summary-show-thread)
9606     (gnus-summary-goto-subject article)
9607     (gnus-summary-update-secondary-mark article)))
9608
9609 (defun gnus-summary-set-saved-mark (article)
9610   "Set the process mark on ARTICLE and update the summary line."
9611   (push article gnus-newsgroup-saved)
9612   (when (gnus-summary-goto-subject article)
9613     (gnus-summary-update-secondary-mark article)))
9614
9615 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9616   "Mark N articles as read forwards.
9617 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9618 The difference between N and the actual number of articles marked is
9619 returned.
9620 If NO-EXPIRE, auto-expiry will be inhibited."
9621   (interactive "p")
9622   (gnus-summary-show-thread)
9623   (let ((backward (< n 0))
9624         (gnus-summary-goto-unread
9625          (and gnus-summary-goto-unread
9626               (not (eq gnus-summary-goto-unread 'never))
9627               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9628                                     gnus-ticked-mark gnus-dormant-mark)))))
9629         (n (abs n))
9630         (mark (or mark gnus-del-mark)))
9631     (while (and (> n 0)
9632                 (gnus-summary-mark-article nil mark no-expire)
9633                 (zerop (gnus-summary-next-subject
9634                         (if backward -1 1)
9635                         (and gnus-summary-goto-unread
9636                              (not (eq gnus-summary-goto-unread 'never)))
9637                         t)))
9638       (setq n (1- n)))
9639     (when (/= 0 n)
9640       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9641     (gnus-summary-recenter)
9642     (gnus-summary-position-point)
9643     (gnus-set-mode-line 'summary)
9644     n))
9645
9646 (defun gnus-summary-mark-article-as-read (mark)
9647   "Mark the current article quickly as read with MARK."
9648   (let ((article (gnus-summary-article-number)))
9649     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9650     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9651     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9652     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9653     (push (cons article mark) gnus-newsgroup-reads)
9654     ;; Possibly remove from cache, if that is used.
9655     (when gnus-use-cache
9656       (gnus-cache-enter-remove-article article))
9657     ;; Allow the backend to change the mark.
9658     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9659     ;; Check for auto-expiry.
9660     (when (and gnus-newsgroup-auto-expire
9661                (memq mark gnus-auto-expirable-marks))
9662       (setq mark gnus-expirable-mark)
9663       ;; Let the backend know about the mark change.
9664       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9665       (push article gnus-newsgroup-expirable))
9666     ;; Set the mark in the buffer.
9667     (gnus-summary-update-mark mark 'unread)
9668     t))
9669
9670 (defun gnus-summary-mark-article-as-unread (mark)
9671   "Mark the current article quickly as unread with MARK."
9672   (let* ((article (gnus-summary-article-number))
9673          (old-mark (gnus-summary-article-mark article)))
9674     ;; Allow the backend to change the mark.
9675     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9676     (if (eq mark old-mark)
9677         t
9678       (if (<= article 0)
9679           (progn
9680             (gnus-error 1 "Can't mark negative article numbers")
9681             nil)
9682         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9683         (setq gnus-newsgroup-spam-marked
9684               (delq article gnus-newsgroup-spam-marked))
9685         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9686         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9687         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9688         (cond ((= mark gnus-ticked-mark)
9689                (setq gnus-newsgroup-marked
9690                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9691                                               article)))
9692               ((= mark gnus-spam-mark)
9693                (setq gnus-newsgroup-spam-marked
9694                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9695                                               article)))
9696               ((= mark gnus-dormant-mark)
9697                (setq gnus-newsgroup-dormant
9698                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9699                                               article)))
9700               (t
9701                (setq gnus-newsgroup-unreads
9702                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9703                                               article))))
9704         (gnus-pull article gnus-newsgroup-reads)
9705
9706         ;; See whether the article is to be put in the cache.
9707         (and gnus-use-cache
9708              (vectorp (gnus-summary-article-header article))
9709              (save-excursion
9710                (gnus-cache-possibly-enter-article
9711                 gnus-newsgroup-name article
9712                 (gnus-summary-article-header article)
9713                 (= mark gnus-ticked-mark)
9714                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9715
9716         ;; Fix the mark.
9717         (gnus-summary-update-mark mark 'unread)
9718         t))))
9719
9720 (defun gnus-summary-mark-article (&optional article mark no-expire)
9721   "Mark ARTICLE with MARK.  MARK can be any character.
9722 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9723 `??' (dormant) and `?E' (expirable).
9724 If MARK is nil, then the default character `?r' is used.
9725 If ARTICLE is nil, then the article on the current line will be
9726 marked.
9727 If NO-EXPIRE, auto-expiry will be inhibited."
9728   ;; The mark might be a string.
9729   (when (stringp mark)
9730     (setq mark (aref mark 0)))
9731   ;; If no mark is given, then we check auto-expiring.
9732   (when (null mark)
9733     (setq mark gnus-del-mark))
9734   (when (and (not no-expire)
9735              gnus-newsgroup-auto-expire
9736              (memq mark gnus-auto-expirable-marks))
9737     (setq mark gnus-expirable-mark))
9738   (let ((article (or article (gnus-summary-article-number)))
9739         (old-mark (gnus-summary-article-mark article)))
9740     ;; Allow the backend to change the mark.
9741     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9742     (if (eq mark old-mark)
9743         t
9744       (unless article
9745         (error "No article on current line"))
9746       (if (not (if (or (= mark gnus-unread-mark)
9747                        (= mark gnus-ticked-mark)
9748                        (= mark gnus-spam-mark)
9749                        (= mark gnus-dormant-mark))
9750                    (gnus-mark-article-as-unread article mark)
9751                  (gnus-mark-article-as-read article mark)))
9752           t
9753         ;; See whether the article is to be put in the cache.
9754         (and gnus-use-cache
9755              (not (= mark gnus-canceled-mark))
9756              (vectorp (gnus-summary-article-header article))
9757              (save-excursion
9758                (gnus-cache-possibly-enter-article
9759                 gnus-newsgroup-name article
9760                 (gnus-summary-article-header article)
9761                 (= mark gnus-ticked-mark)
9762                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9763
9764         (when (gnus-summary-goto-subject article nil t)
9765           (let ((buffer-read-only nil))
9766             (gnus-summary-show-thread)
9767             ;; Fix the mark.
9768             (gnus-summary-update-mark mark 'unread)
9769             t))))))
9770
9771 (defun gnus-summary-update-secondary-mark (article)
9772   "Update the secondary (read, process, cache) mark."
9773   (gnus-summary-update-mark
9774    (cond ((memq article gnus-newsgroup-processable)
9775           gnus-process-mark)
9776          ((memq article gnus-newsgroup-cached)
9777           gnus-cached-mark)
9778          ((memq article gnus-newsgroup-replied)
9779           gnus-replied-mark)
9780          ((memq article gnus-newsgroup-forwarded)
9781           gnus-forwarded-mark)
9782          ((memq article gnus-newsgroup-saved)
9783           gnus-saved-mark)
9784          ((memq article gnus-newsgroup-recent)
9785           gnus-recent-mark)
9786          ((memq article gnus-newsgroup-unseen)
9787           gnus-unseen-mark)
9788          (t gnus-no-mark))
9789    'replied)
9790   (when (gnus-visual-p 'summary-highlight 'highlight)
9791     (gnus-run-hooks 'gnus-summary-update-hook))
9792   t)
9793
9794 (defun gnus-summary-update-download-mark (article)
9795   "Update the secondary (read, process, cache) mark."
9796   (gnus-summary-update-mark
9797    (cond ((memq article gnus-newsgroup-undownloaded) 
9798           gnus-undownloaded-mark)
9799          (gnus-newsgroup-agentized
9800           gnus-downloaded-mark)
9801          (t
9802           gnus-no-mark))
9803    'download)
9804   (gnus-summary-update-line t)
9805   t)
9806
9807 (defun gnus-summary-update-mark (mark type)
9808   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9809         (buffer-read-only nil))
9810     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9811     (when forward
9812       (when (looking-at "\r")
9813         (incf forward))
9814       (when (<= (+ forward (point)) (point-max))
9815         ;; Go to the right position on the line.
9816         (goto-char (+ forward (point)))
9817         ;; Replace the old mark with the new mark.
9818         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9819         ;; Optionally update the marks by some user rule.
9820         (when (eq type 'unread)
9821           (gnus-data-set-mark
9822            (gnus-data-find (gnus-summary-article-number)) mark)
9823           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9824
9825 (defun gnus-mark-article-as-read (article &optional mark)
9826   "Enter ARTICLE in the pertinent lists and remove it from others."
9827   ;; Make the article expirable.
9828   (let ((mark (or mark gnus-del-mark)))
9829     (setq gnus-newsgroup-expirable
9830           (if (= mark gnus-expirable-mark)
9831               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9832             (delq article gnus-newsgroup-expirable)))
9833     ;; Remove from unread and marked lists.
9834     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9835     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9836     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9837     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9838     (push (cons article mark) gnus-newsgroup-reads)
9839     ;; Possibly remove from cache, if that is used.
9840     (when gnus-use-cache
9841       (gnus-cache-enter-remove-article article))
9842     t))
9843
9844 (defun gnus-mark-article-as-unread (article &optional mark)
9845   "Enter ARTICLE in the pertinent lists and remove it from others."
9846   (let ((mark (or mark gnus-ticked-mark)))
9847     (if (<= article 0)
9848         (progn
9849           (gnus-error 1 "Can't mark negative article numbers")
9850           nil)
9851       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9852             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9853             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9854             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9855             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9856
9857       ;; Unsuppress duplicates?
9858       (when gnus-suppress-duplicates
9859         (gnus-dup-unsuppress-article article))
9860
9861       (cond ((= mark gnus-ticked-mark)
9862              (setq gnus-newsgroup-marked
9863                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9864             ((= mark gnus-spam-mark)
9865              (setq gnus-newsgroup-spam-marked
9866                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9867                                             article)))
9868             ((= mark gnus-dormant-mark)
9869              (setq gnus-newsgroup-dormant
9870                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9871             (t
9872              (setq gnus-newsgroup-unreads
9873                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9874       (gnus-pull article gnus-newsgroup-reads)
9875       t)))
9876
9877 (defalias 'gnus-summary-mark-as-unread-forward
9878   'gnus-summary-tick-article-forward)
9879 (make-obsolete 'gnus-summary-mark-as-unread-forward
9880                'gnus-summary-tick-article-forward)
9881 (defun gnus-summary-tick-article-forward (n)
9882   "Tick N articles forwards.
9883 If N is negative, tick backwards instead.
9884 The difference between N and the number of articles ticked is returned."
9885   (interactive "p")
9886   (gnus-summary-mark-forward n gnus-ticked-mark))
9887
9888 (defalias 'gnus-summary-mark-as-unread-backward
9889   'gnus-summary-tick-article-backward)
9890 (make-obsolete 'gnus-summary-mark-as-unread-backward
9891                'gnus-summary-tick-article-backward)
9892 (defun gnus-summary-tick-article-backward (n)
9893   "Tick N articles backwards.
9894 The difference between N and the number of articles ticked is returned."
9895   (interactive "p")
9896   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9897
9898 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9899 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9900 (defun gnus-summary-tick-article (&optional article clear-mark)
9901   "Mark current article as unread.
9902 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9903 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9904   (interactive)
9905   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9906                                        gnus-ticked-mark)))
9907
9908 (defun gnus-summary-mark-as-read-forward (n)
9909   "Mark N articles as read forwards.
9910 If N is negative, mark backwards instead.
9911 The difference between N and the actual number of articles marked is
9912 returned."
9913   (interactive "p")
9914   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9915
9916 (defun gnus-summary-mark-as-read-backward (n)
9917   "Mark the N articles as read backwards.
9918 The difference between N and the actual number of articles marked is
9919 returned."
9920   (interactive "p")
9921   (gnus-summary-mark-forward
9922    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9923
9924 (defun gnus-summary-mark-as-read (&optional article mark)
9925   "Mark current article as read.
9926 ARTICLE specifies the article to be marked as read.
9927 MARK specifies a string to be inserted at the beginning of the line."
9928   (gnus-summary-mark-article article mark))
9929
9930 (defun gnus-summary-clear-mark-forward (n)
9931   "Clear marks from N articles forward.
9932 If N is negative, clear backward instead.
9933 The difference between N and the number of marks cleared is returned."
9934   (interactive "p")
9935   (gnus-summary-mark-forward n gnus-unread-mark))
9936
9937 (defun gnus-summary-clear-mark-backward (n)
9938   "Clear marks from N articles backward.
9939 The difference between N and the number of marks cleared is returned."
9940   (interactive "p")
9941   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9942
9943 (defun gnus-summary-mark-unread-as-read ()
9944   "Intended to be used by `gnus-summary-mark-article-hook'."
9945   (when (memq gnus-current-article gnus-newsgroup-unreads)
9946     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9947
9948 (defun gnus-summary-mark-read-and-unread-as-read ()
9949   "Intended to be used by `gnus-summary-mark-article-hook'."
9950   (let ((mark (gnus-summary-article-mark)))
9951     (when (or (gnus-unread-mark-p mark)
9952               (gnus-read-mark-p mark))
9953       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9954
9955 (defun gnus-summary-mark-unread-as-ticked ()
9956   "Intended to be used by `gnus-summary-mark-article-hook'."
9957   (when (memq gnus-current-article gnus-newsgroup-unreads)
9958     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9959
9960 (defun gnus-summary-mark-region-as-read (point mark all)
9961   "Mark all unread articles between point and mark as read.
9962 If given a prefix, mark all articles between point and mark as read,
9963 even ticked and dormant ones."
9964   (interactive "r\nP")
9965   (save-excursion
9966     (let (article)
9967       (goto-char point)
9968       (beginning-of-line)
9969       (while (and
9970               (< (point) mark)
9971               (progn
9972                 (when (or all
9973                           (memq (setq article (gnus-summary-article-number))
9974                                 gnus-newsgroup-unreads))
9975                   (gnus-summary-mark-article article gnus-del-mark))
9976                 t)
9977               (gnus-summary-find-next))))))
9978
9979 (defun gnus-summary-mark-below (score mark)
9980   "Mark articles with score less than SCORE with MARK."
9981   (interactive "P\ncMark: ")
9982   (setq score (if score
9983                   (prefix-numeric-value score)
9984                 (or gnus-summary-default-score 0)))
9985   (save-excursion
9986     (set-buffer gnus-summary-buffer)
9987     (goto-char (point-min))
9988     (while
9989         (progn
9990           (and (< (gnus-summary-article-score) score)
9991                (gnus-summary-mark-article nil mark))
9992           (gnus-summary-find-next)))))
9993
9994 (defun gnus-summary-kill-below (&optional score)
9995   "Mark articles with score below SCORE as read."
9996   (interactive "P")
9997   (gnus-summary-mark-below score gnus-killed-mark))
9998
9999 (defun gnus-summary-clear-above (&optional score)
10000   "Clear all marks from articles with score above SCORE."
10001   (interactive "P")
10002   (gnus-summary-mark-above score gnus-unread-mark))
10003
10004 (defun gnus-summary-tick-above (&optional score)
10005   "Tick all articles with score above SCORE."
10006   (interactive "P")
10007   (gnus-summary-mark-above score gnus-ticked-mark))
10008
10009 (defun gnus-summary-mark-above (score mark)
10010   "Mark articles with score over SCORE with MARK."
10011   (interactive "P\ncMark: ")
10012   (setq score (if score
10013                   (prefix-numeric-value score)
10014                 (or gnus-summary-default-score 0)))
10015   (save-excursion
10016     (set-buffer gnus-summary-buffer)
10017     (goto-char (point-min))
10018     (while (and (progn
10019                   (when (> (gnus-summary-article-score) score)
10020                     (gnus-summary-mark-article nil mark))
10021                   t)
10022                 (gnus-summary-find-next)))))
10023
10024 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10025 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10026 (defun gnus-summary-limit-include-expunged (&optional no-error)
10027   "Display all the hidden articles that were expunged for low scores."
10028   (interactive)
10029   (let ((buffer-read-only nil))
10030     (let ((scored gnus-newsgroup-scored)
10031           headers h)
10032       (while scored
10033         (unless (gnus-summary-article-header (caar scored))
10034           (and (setq h (gnus-number-to-header (caar scored)))
10035                (< (cdar scored) gnus-summary-expunge-below)
10036                (push h headers)))
10037         (setq scored (cdr scored)))
10038       (if (not headers)
10039           (when (not no-error)
10040             (error "No expunged articles hidden"))
10041         (goto-char (point-min))
10042         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10043         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10044         (mapcar (lambda (x) (push (mail-header-number x)
10045                                   gnus-newsgroup-limit))
10046                 headers)
10047         (gnus-summary-prepare-unthreaded (nreverse headers))
10048         (goto-char (point-min))
10049         (gnus-summary-position-point)
10050         t))))
10051
10052 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10053   "Mark all unread articles in this newsgroup as read.
10054 If prefix argument ALL is non-nil, ticked and dormant articles will
10055 also be marked as read.
10056 If QUIETLY is non-nil, no questions will be asked.
10057 If TO-HERE is non-nil, it should be a point in the buffer.  All
10058 articles before (after, if REVERSE is set) this point will be marked as read.
10059 Note that this function will only catch up the unread article
10060 in the current summary buffer limitation.
10061 The number of articles marked as read is returned."
10062   (interactive "P")
10063   (prog1
10064       (save-excursion
10065         (when (or quietly
10066                   (not gnus-interactive-catchup) ;Without confirmation?
10067                   gnus-expert-user
10068                   (gnus-y-or-n-p
10069                    (if all
10070                        "Mark absolutely all articles as read? "
10071                      "Mark all unread articles as read? ")))
10072           (if (and not-mark
10073                    (not gnus-newsgroup-adaptive)
10074                    (not gnus-newsgroup-auto-expire)
10075                    (not gnus-suppress-duplicates)
10076                    (or (not gnus-use-cache)
10077                        (eq gnus-use-cache 'passive)))
10078               (progn
10079                 (when all
10080                   (setq gnus-newsgroup-marked nil
10081                         gnus-newsgroup-spam-marked nil
10082                         gnus-newsgroup-dormant nil))
10083                 (setq gnus-newsgroup-unreads
10084                       (gnus-intersection gnus-newsgroup-unreads
10085                                          gnus-newsgroup-downloadable)))
10086             ;; We actually mark all articles as canceled, which we
10087             ;; have to do when using auto-expiry or adaptive scoring.
10088             (gnus-summary-show-all-threads)
10089             (if (and to-here reverse)
10090                 (progn
10091                   (goto-char to-here)
10092                   (while (and
10093                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
10094                           (gnus-summary-find-next (not all) nil nil t))))
10095               (when (gnus-summary-first-subject (not all) t)
10096                 (while (and
10097                         (if to-here (< (point) to-here) t)
10098                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10099                         (gnus-summary-find-next (not all) nil nil t)))))
10100             (gnus-set-mode-line 'summary))
10101           t))
10102     (gnus-summary-position-point)))
10103
10104 (defun gnus-summary-catchup-to-here (&optional all)
10105   "Mark all unticked articles before the current one as read.
10106 If ALL is non-nil, also mark ticked and dormant articles as read."
10107   (interactive "P")
10108   (save-excursion
10109     (gnus-save-hidden-threads
10110       (let ((beg (point)))
10111         ;; We check that there are unread articles.
10112         (when (or all (gnus-summary-find-prev))
10113           (gnus-summary-catchup all t beg)))))
10114   (gnus-summary-position-point))
10115
10116 (defun gnus-summary-catchup-from-here (&optional all)
10117   "Mark all unticked articles after the current one as read.
10118 If ALL is non-nil, also mark ticked and dormant articles as read."
10119   (interactive "P")
10120   (save-excursion
10121     (gnus-save-hidden-threads
10122       (let ((beg (point)))
10123         ;; We check that there are unread articles.
10124         (when (or all (gnus-summary-find-next))
10125           (gnus-summary-catchup all t beg nil t)))))
10126   (gnus-summary-position-point))
10127
10128 (defun gnus-summary-catchup-all (&optional quietly)
10129   "Mark all articles in this newsgroup as read.
10130 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10131 instead, which marks only unread articles as read."
10132   (interactive "P")
10133   (gnus-summary-catchup t quietly))
10134
10135 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10136   "Mark all unread articles in this group as read, then exit.
10137 If prefix argument ALL is non-nil, all articles are marked as read.
10138 If QUIETLY is non-nil, no questions will be asked."
10139   (interactive "P")
10140   (when (gnus-summary-catchup all quietly nil 'fast)
10141     ;; Select next newsgroup or exit.
10142     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10143              (eq gnus-auto-select-next 'quietly))
10144         (gnus-summary-next-group nil)
10145       (gnus-summary-exit))))
10146
10147 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10148   "Mark all articles in this newsgroup as read, and then exit.
10149 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10150 instead, which marks only unread articles as read."
10151   (interactive "P")
10152   (gnus-summary-catchup-and-exit t quietly))
10153
10154 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10155   "Mark all articles in this group as read and select the next group.
10156 If given a prefix, mark all articles, unread as well as ticked, as
10157 read."
10158   (interactive "P")
10159   (save-excursion
10160     (gnus-summary-catchup all))
10161   (gnus-summary-next-group))
10162
10163 ;;;
10164 ;;; with article
10165 ;;;
10166
10167 (defmacro gnus-with-article (article &rest forms)
10168   "Select ARTICLE and perform FORMS in the original article buffer.
10169 Then replace the article with the result."
10170   `(progn
10171      ;; We don't want the article to be marked as read.
10172      (let (gnus-mark-article-hook)
10173        (gnus-summary-select-article t t nil ,article))
10174      (set-buffer gnus-original-article-buffer)
10175      ,@forms
10176      (if (not (gnus-check-backend-function
10177                'request-replace-article (car gnus-article-current)))
10178          (gnus-message 5 "Read-only group; not replacing")
10179        (unless (gnus-request-replace-article
10180                 ,article (car gnus-article-current)
10181                 (current-buffer) t)
10182          (error "Couldn't replace article")))
10183      ;; The cache and backlog have to be flushed somewhat.
10184      (when gnus-keep-backlog
10185        (gnus-backlog-remove-article
10186         (car gnus-article-current) (cdr gnus-article-current)))
10187      (when gnus-use-cache
10188        (gnus-cache-update-article
10189         (car gnus-article-current) (cdr gnus-article-current)))))
10190
10191 (put 'gnus-with-article 'lisp-indent-function 1)
10192 (put 'gnus-with-article 'edebug-form-spec '(form body))
10193
10194 ;; Thread-based commands.
10195
10196 (defun gnus-summary-articles-in-thread (&optional article)
10197   "Return a list of all articles in the current thread.
10198 If ARTICLE is non-nil, return all articles in the thread that starts
10199 with that article."
10200   (let* ((article (or article (gnus-summary-article-number)))
10201          (data (gnus-data-find-list article))
10202          (top-level (gnus-data-level (car data)))
10203          (top-subject
10204           (cond ((null gnus-thread-operation-ignore-subject)
10205                  (gnus-simplify-subject-re
10206                   (mail-header-subject (gnus-data-header (car data)))))
10207                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10208                  (gnus-simplify-subject-fuzzy
10209                   (mail-header-subject (gnus-data-header (car data)))))
10210                 (t nil)))
10211          (end-point (save-excursion
10212                       (if (gnus-summary-go-to-next-thread)
10213                           (point) (point-max))))
10214          articles)
10215     (while (and data
10216                 (< (gnus-data-pos (car data)) end-point))
10217       (when (or (not top-subject)
10218                 (string= top-subject
10219                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10220                              (gnus-simplify-subject-fuzzy
10221                               (mail-header-subject
10222                                (gnus-data-header (car data))))
10223                            (gnus-simplify-subject-re
10224                             (mail-header-subject
10225                              (gnus-data-header (car data)))))))
10226         (push (gnus-data-number (car data)) articles))
10227       (unless (and (setq data (cdr data))
10228                    (> (gnus-data-level (car data)) top-level))
10229         (setq data nil)))
10230     ;; Return the list of articles.
10231     (nreverse articles)))
10232
10233 (defun gnus-summary-rethread-current ()
10234   "Rethread the thread the current article is part of."
10235   (interactive)
10236   (let* ((gnus-show-threads t)
10237          (article (gnus-summary-article-number))
10238          (id (mail-header-id (gnus-summary-article-header)))
10239          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10240     (unless id
10241       (error "No article on the current line"))
10242     (gnus-rebuild-thread id)
10243     (gnus-summary-goto-subject article)))
10244
10245 (defun gnus-summary-reparent-thread ()
10246   "Make the current article child of the marked (or previous) article.
10247
10248 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10249 is non-nil or the Subject: of both articles are the same."
10250   (interactive)
10251   (unless (not (gnus-group-read-only-p))
10252     (error "The current newsgroup does not support article editing"))
10253   (unless (<= (length gnus-newsgroup-processable) 1)
10254     (error "No more than one article may be marked"))
10255   (save-window-excursion
10256     (let ((gnus-article-buffer " *reparent*")
10257           (current-article (gnus-summary-article-number))
10258           ;; First grab the marked article, otherwise one line up.
10259           (parent-article (if (not (null gnus-newsgroup-processable))
10260                               (car gnus-newsgroup-processable)
10261                             (save-excursion
10262                               (if (eq (forward-line -1) 0)
10263                                   (gnus-summary-article-number)
10264                                 (error "Beginning of summary buffer"))))))
10265       (unless (not (eq current-article parent-article))
10266         (error "An article may not be self-referential"))
10267       (let ((message-id (mail-header-id
10268                          (gnus-summary-article-header parent-article))))
10269         (unless (and message-id (not (equal message-id "")))
10270           (error "No message-id in desired parent"))
10271         (gnus-with-article current-article
10272           (save-restriction
10273             (goto-char (point-min))
10274             (message-narrow-to-head)
10275             (if (re-search-forward "^References: " nil t)
10276                 (progn
10277                   (re-search-forward "^[^ \t]" nil t)
10278                   (forward-line -1)
10279                   (end-of-line)
10280                   (insert " " message-id))
10281               (insert "References: " message-id "\n"))))
10282         (set-buffer gnus-summary-buffer)
10283         (gnus-summary-unmark-all-processable)
10284         (gnus-summary-update-article current-article)
10285         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10286             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10287         (gnus-summary-rethread-current)
10288         (gnus-message 3 "Article %d is now the child of article %d"
10289                       current-article parent-article)))))
10290
10291 (defun gnus-summary-toggle-threads (&optional arg)
10292   "Toggle showing conversation threads.
10293 If ARG is positive number, turn showing conversation threads on."
10294   (interactive "P")
10295   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10296     (setq gnus-show-threads
10297           (if (null arg) (not gnus-show-threads)
10298             (> (prefix-numeric-value arg) 0)))
10299     (gnus-summary-prepare)
10300     (gnus-summary-goto-subject current)
10301     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10302     (gnus-summary-position-point)))
10303
10304 (defun gnus-summary-show-all-threads ()
10305   "Show all threads."
10306   (interactive)
10307   (save-excursion
10308     (let ((buffer-read-only nil))
10309       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10310   (gnus-summary-position-point))
10311
10312 (defun gnus-summary-show-thread ()
10313   "Show thread subtrees.
10314 Returns nil if no thread was there to be shown."
10315   (interactive)
10316   (let ((buffer-read-only nil)
10317         (orig (point))
10318         ;; first goto end then to beg, to have point at beg after let
10319         (end (progn (end-of-line) (point)))
10320         (beg (progn (beginning-of-line) (point))))
10321     (prog1
10322         ;; Any hidden lines here?
10323         (search-forward "\r" end t)
10324       (subst-char-in-region beg end ?\^M ?\n t)
10325       (goto-char orig)
10326       (gnus-summary-position-point))))
10327
10328 (defun gnus-summary-maybe-hide-threads ()
10329   "If requested, hide the threads that should be hidden."
10330   (when (and gnus-show-threads
10331              gnus-thread-hide-subtree)
10332     (gnus-summary-hide-all-threads
10333      (if (or (consp gnus-thread-hide-subtree)
10334              (gnus-functionp gnus-thread-hide-subtree))
10335          (gnus-make-predicate gnus-thread-hide-subtree)
10336        nil))))
10337
10338 ;;; Hiding predicates.
10339
10340 (defun gnus-article-unread-p (header)
10341   (memq (mail-header-number header) gnus-newsgroup-unreads))
10342
10343 (defun gnus-article-unseen-p (header)
10344   (memq (mail-header-number header) gnus-newsgroup-unseen))
10345
10346 (defun gnus-map-articles (predicate articles)
10347   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10348   (apply 'gnus-or (mapcar predicate
10349                           (mapcar 'gnus-summary-article-header articles))))
10350
10351 (defun gnus-summary-hide-all-threads (&optional predicate)
10352   "Hide all thread subtrees.
10353 If PREDICATE is supplied, threads that satisfy this predicate
10354 will not be hidden."
10355   (interactive)
10356   (save-excursion
10357     (goto-char (point-min))
10358     (let ((end nil))
10359       (while (not end)
10360         (when (or (not predicate)
10361                   (gnus-map-articles
10362                    predicate (gnus-summary-article-children)))
10363             (gnus-summary-hide-thread))
10364         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10365   (gnus-summary-position-point))
10366
10367 (defun gnus-summary-hide-thread ()
10368   "Hide thread subtrees.
10369 If PREDICATE is supplied, threads that satisfy this predicate
10370 will not be hidden.
10371 Returns nil if no threads were there to be hidden."
10372   (interactive)
10373   (let ((buffer-read-only nil)
10374         (start (point))
10375         (article (gnus-summary-article-number)))
10376     (goto-char start)
10377     ;; Go forward until either the buffer ends or the subthread
10378     ;; ends.
10379     (when (and (not (eobp))
10380                (or (zerop (gnus-summary-next-thread 1 t))
10381                    (goto-char (point-max))))
10382       (prog1
10383           (if (and (> (point) start)
10384                    (search-backward "\n" start t))
10385               (progn
10386                 (subst-char-in-region start (point) ?\n ?\^M)
10387                 (gnus-summary-goto-subject article))
10388             (goto-char start)
10389             nil)))))
10390
10391 (defun gnus-summary-go-to-next-thread (&optional previous)
10392   "Go to the same level (or less) next thread.
10393 If PREVIOUS is non-nil, go to previous thread instead.
10394 Return the article number moved to, or nil if moving was impossible."
10395   (let ((level (gnus-summary-thread-level))
10396         (way (if previous -1 1))
10397         (beg (point)))
10398     (forward-line way)
10399     (while (and (not (eobp))
10400                 (< level (gnus-summary-thread-level)))
10401       (forward-line way))
10402     (if (eobp)
10403         (progn
10404           (goto-char beg)
10405           nil)
10406       (setq beg (point))
10407       (prog1
10408           (gnus-summary-article-number)
10409         (goto-char beg)))))
10410
10411 (defun gnus-summary-next-thread (n &optional silent)
10412   "Go to the same level next N'th thread.
10413 If N is negative, search backward instead.
10414 Returns the difference between N and the number of skips actually
10415 done.
10416
10417 If SILENT, don't output messages."
10418   (interactive "p")
10419   (let ((backward (< n 0))
10420         (n (abs n)))
10421     (while (and (> n 0)
10422                 (gnus-summary-go-to-next-thread backward))
10423       (decf n))
10424     (unless silent
10425       (gnus-summary-position-point))
10426     (when (and (not silent) (/= 0 n))
10427       (gnus-message 7 "No more threads"))
10428     n))
10429
10430 (defun gnus-summary-prev-thread (n)
10431   "Go to the same level previous N'th thread.
10432 Returns the difference between N and the number of skips actually
10433 done."
10434   (interactive "p")
10435   (gnus-summary-next-thread (- n)))
10436
10437 (defun gnus-summary-go-down-thread ()
10438   "Go down one level in the current thread."
10439   (let ((children (gnus-summary-article-children)))
10440     (when children
10441       (gnus-summary-goto-subject (car children)))))
10442
10443 (defun gnus-summary-go-up-thread ()
10444   "Go up one level in the current thread."
10445   (let ((parent (gnus-summary-article-parent)))
10446     (when parent
10447       (gnus-summary-goto-subject parent))))
10448
10449 (defun gnus-summary-down-thread (n)
10450   "Go down thread N steps.
10451 If N is negative, go up instead.
10452 Returns the difference between N and how many steps down that were
10453 taken."
10454   (interactive "p")
10455   (let ((up (< n 0))
10456         (n (abs n)))
10457     (while (and (> n 0)
10458                 (if up (gnus-summary-go-up-thread)
10459                   (gnus-summary-go-down-thread)))
10460       (setq n (1- n)))
10461     (gnus-summary-position-point)
10462     (when (/= 0 n)
10463       (gnus-message 7 "Can't go further"))
10464     n))
10465
10466 (defun gnus-summary-up-thread (n)
10467   "Go up thread N steps.
10468 If N is negative, go down instead.
10469 Returns the difference between N and how many steps down that were
10470 taken."
10471   (interactive "p")
10472   (gnus-summary-down-thread (- n)))
10473
10474 (defun gnus-summary-top-thread ()
10475   "Go to the top of the thread."
10476   (interactive)
10477   (while (gnus-summary-go-up-thread))
10478   (gnus-summary-article-number))
10479
10480 (defun gnus-summary-kill-thread (&optional unmark)
10481   "Mark articles under current thread as read.
10482 If the prefix argument is positive, remove any kinds of marks.
10483 If the prefix argument is negative, tick articles instead."
10484   (interactive "P")
10485   (when unmark
10486     (setq unmark (prefix-numeric-value unmark)))
10487   (let ((articles (gnus-summary-articles-in-thread)))
10488     (save-excursion
10489       ;; Expand the thread.
10490       (gnus-summary-show-thread)
10491       ;; Mark all the articles.
10492       (while articles
10493         (gnus-summary-goto-subject (car articles))
10494         (cond ((null unmark)
10495                (gnus-summary-mark-article-as-read gnus-killed-mark))
10496               ((> unmark 0)
10497                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10498               (t
10499                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10500         (setq articles (cdr articles))))
10501     ;; Hide killed subtrees.
10502     (and (null unmark)
10503          gnus-thread-hide-killed
10504          (gnus-summary-hide-thread))
10505     ;; If marked as read, go to next unread subject.
10506     (when (null unmark)
10507       ;; Go to next unread subject.
10508       (gnus-summary-next-subject 1 t)))
10509   (gnus-set-mode-line 'summary))
10510
10511 ;; Summary sorting commands
10512
10513 (defun gnus-summary-sort-by-number (&optional reverse)
10514   "Sort the summary buffer by article number.
10515 Argument REVERSE means reverse order."
10516   (interactive "P")
10517   (gnus-summary-sort 'number reverse))
10518
10519 (defun gnus-summary-sort-by-random (&optional reverse)
10520   "Randomize the order in the summary buffer.
10521 Argument REVERSE means to randomize in reverse order."
10522   (interactive "P")
10523   (gnus-summary-sort 'random reverse))
10524
10525 (defun gnus-summary-sort-by-author (&optional reverse)
10526   "Sort the summary buffer by author name alphabetically.
10527 If `case-fold-search' is non-nil, case of letters is ignored.
10528 Argument REVERSE means reverse order."
10529   (interactive "P")
10530   (gnus-summary-sort 'author reverse))
10531
10532 (defun gnus-summary-sort-by-subject (&optional reverse)
10533   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10534 If `case-fold-search' is non-nil, case of letters is ignored.
10535 Argument REVERSE means reverse order."
10536   (interactive "P")
10537   (gnus-summary-sort 'subject reverse))
10538
10539 (defun gnus-summary-sort-by-date (&optional reverse)
10540   "Sort the summary buffer by date.
10541 Argument REVERSE means reverse order."
10542   (interactive "P")
10543   (gnus-summary-sort 'date reverse))
10544
10545 (defun gnus-summary-sort-by-score (&optional reverse)
10546   "Sort the summary buffer by score.
10547 Argument REVERSE means reverse order."
10548   (interactive "P")
10549   (gnus-summary-sort 'score reverse))
10550
10551 (defun gnus-summary-sort-by-lines (&optional reverse)
10552   "Sort the summary buffer by the number of lines.
10553 Argument REVERSE means reverse order."
10554   (interactive "P")
10555   (gnus-summary-sort 'lines reverse))
10556
10557 (defun gnus-summary-sort-by-chars (&optional reverse)
10558   "Sort the summary buffer by article length.
10559 Argument REVERSE means reverse order."
10560   (interactive "P")
10561   (gnus-summary-sort 'chars reverse))
10562
10563 (defun gnus-summary-sort-by-original (&optional reverse)
10564   "Sort the summary buffer using the default sorting method.
10565 Argument REVERSE means reverse order."
10566   (interactive "P")
10567   (let* ((buffer-read-only)
10568          (gnus-summary-prepare-hook nil))
10569     ;; We do the sorting by regenerating the threads.
10570     (gnus-summary-prepare)
10571     ;; Hide subthreads if needed.
10572     (gnus-summary-maybe-hide-threads)))
10573
10574 (defun gnus-summary-sort (predicate reverse)
10575   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10576   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10577          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10578          (gnus-thread-sort-functions
10579           (if (not reverse)
10580               thread
10581             `(lambda (t1 t2)
10582                (,thread t2 t1))))
10583          (gnus-sort-gathered-threads-function
10584           gnus-thread-sort-functions)
10585          (gnus-article-sort-functions
10586           (if (not reverse)
10587               article
10588             `(lambda (t1 t2)
10589                (,article t2 t1))))
10590          (buffer-read-only)
10591          (gnus-summary-prepare-hook nil))
10592     ;; We do the sorting by regenerating the threads.
10593     (gnus-summary-prepare)
10594     ;; Hide subthreads if needed.
10595     (gnus-summary-maybe-hide-threads)))
10596
10597 ;; Summary saving commands.
10598
10599 (defun gnus-summary-save-article (&optional n not-saved)
10600   "Save the current article using the default saver function.
10601 If N is a positive number, save the N next articles.
10602 If N is a negative number, save the N previous articles.
10603 If N is nil and any articles have been marked with the process mark,
10604 save those articles instead.
10605 The variable `gnus-default-article-saver' specifies the saver function."
10606   (interactive "P")
10607   (let* ((articles (gnus-summary-work-articles n))
10608          (save-buffer (save-excursion
10609                         (nnheader-set-temp-buffer " *Gnus Save*")))
10610          (num (length articles))
10611          header file)
10612     (dolist (article articles)
10613       (setq header (gnus-summary-article-header article))
10614       (if (not (vectorp header))
10615           ;; This is a pseudo-article.
10616           (if (assq 'name header)
10617               (gnus-copy-file (cdr (assq 'name header)))
10618             (gnus-message 1 "Article %d is unsaveable" article))
10619         ;; This is a real article.
10620         (save-window-excursion
10621           (let ((gnus-display-mime-function nil)
10622                 (gnus-article-prepare-hook nil))
10623             (gnus-summary-select-article t nil nil article)))
10624         (save-excursion
10625           (set-buffer save-buffer)
10626           (erase-buffer)
10627           (insert-buffer-substring gnus-original-article-buffer))
10628         (setq file (gnus-article-save save-buffer file num))
10629         (gnus-summary-remove-process-mark article)
10630         (unless not-saved
10631           (gnus-summary-set-saved-mark article))))
10632     (gnus-kill-buffer save-buffer)
10633     (gnus-summary-position-point)
10634     (gnus-set-mode-line 'summary)
10635     n))
10636
10637 (defun gnus-summary-pipe-output (&optional arg headers)
10638   "Pipe the current article to a subprocess.
10639 If N is a positive number, pipe the N next articles.
10640 If N is a negative number, pipe the N previous articles.
10641 If N is nil and any articles have been marked with the process mark,
10642 pipe those articles instead.
10643 If HEADERS (the symbolic prefix), include the headers, too."
10644   (interactive (gnus-interactive "P\ny"))
10645   (require 'gnus-art)
10646   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10647         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10648     (gnus-summary-save-article arg t))
10649   (let ((buffer (get-buffer "*Shell Command Output*")))
10650     (when (and buffer
10651                (not (zerop (buffer-size buffer))))
10652       (gnus-configure-windows 'pipe))))
10653
10654 (defun gnus-summary-save-article-mail (&optional arg)
10655   "Append the current article to an mail file.
10656 If N is a positive number, save the N next articles.
10657 If N is a negative number, save the N previous articles.
10658 If N is nil and any articles have been marked with the process mark,
10659 save those articles instead."
10660   (interactive "P")
10661   (require 'gnus-art)
10662   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10663     (gnus-summary-save-article arg)))
10664
10665 (defun gnus-summary-save-article-rmail (&optional arg)
10666   "Append the current article to an rmail file.
10667 If N is a positive number, save the N next articles.
10668 If N is a negative number, save the N previous articles.
10669 If N is nil and any articles have been marked with the process mark,
10670 save those articles instead."
10671   (interactive "P")
10672   (require 'gnus-art)
10673   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10674     (gnus-summary-save-article arg)))
10675
10676 (defun gnus-summary-save-article-file (&optional arg)
10677   "Append the current article to a file.
10678 If N is a positive number, save the N next articles.
10679 If N is a negative number, save the N previous articles.
10680 If N is nil and any articles have been marked with the process mark,
10681 save those articles instead."
10682   (interactive "P")
10683   (require 'gnus-art)
10684   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10685     (gnus-summary-save-article arg)))
10686
10687 (defun gnus-summary-write-article-file (&optional arg)
10688   "Write the current article to a file, deleting the previous file.
10689 If N is a positive number, save the N next articles.
10690 If N is a negative number, save the N previous articles.
10691 If N is nil and any articles have been marked with the process mark,
10692 save those articles instead."
10693   (interactive "P")
10694   (require 'gnus-art)
10695   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10696     (gnus-summary-save-article arg)))
10697
10698 (defun gnus-summary-save-article-body-file (&optional arg)
10699   "Append the current article body to a file.
10700 If N is a positive number, save the N next articles.
10701 If N is a negative number, save the N previous articles.
10702 If N is nil and any articles have been marked with the process mark,
10703 save those articles instead."
10704   (interactive "P")
10705   (require 'gnus-art)
10706   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10707     (gnus-summary-save-article arg)))
10708
10709 (defun gnus-summary-muttprint (&optional arg)
10710   "Print the current article using Muttprint.
10711 If N is a positive number, save the N next articles.
10712 If N is a negative number, save the N previous articles.
10713 If N is nil and any articles have been marked with the process mark,
10714 save those articles instead."
10715   (interactive "P")
10716   (require 'gnus-art)
10717   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10718     (gnus-summary-save-article arg t)))
10719
10720 (defun gnus-summary-pipe-message (program)
10721   "Pipe the current article through PROGRAM."
10722   (interactive "sProgram: ")
10723   (gnus-summary-select-article)
10724   (let ((mail-header-separator ""))
10725     (gnus-eval-in-buffer-window gnus-article-buffer
10726       (save-restriction
10727         (widen)
10728         (let ((start (window-start))
10729               buffer-read-only)
10730           (message-pipe-buffer-body program)
10731           (set-window-start (get-buffer-window (current-buffer)) start))))))
10732
10733 (defun gnus-get-split-value (methods)
10734   "Return a value based on the split METHODS."
10735   (let (split-name method result match)
10736     (when methods
10737       (save-excursion
10738         (set-buffer gnus-original-article-buffer)
10739         (save-restriction
10740           (nnheader-narrow-to-headers)
10741           (while (and methods (not split-name))
10742             (goto-char (point-min))
10743             (setq method (pop methods))
10744             (setq match (car method))
10745             (when (cond
10746                    ((stringp match)
10747                     ;; Regular expression.
10748                     (ignore-errors
10749                       (re-search-forward match nil t)))
10750                    ((gnus-functionp match)
10751                     ;; Function.
10752                     (save-restriction
10753                       (widen)
10754                       (setq result (funcall match gnus-newsgroup-name))))
10755                    ((consp match)
10756                     ;; Form.
10757                     (save-restriction
10758                       (widen)
10759                       (setq result (eval match)))))
10760               (setq split-name (cdr method))
10761               (cond ((stringp result)
10762                      (push (expand-file-name
10763                             result gnus-article-save-directory)
10764                            split-name))
10765                     ((consp result)
10766                      (setq split-name (append result split-name)))))))))
10767     (nreverse split-name)))
10768
10769 (defun gnus-valid-move-group-p (group)
10770   (and (boundp group)
10771        (symbol-name group)
10772        (symbol-value group)
10773        (gnus-get-function (gnus-find-method-for-group
10774                            (symbol-name group)) 'request-accept-article t)))
10775
10776 (defun gnus-read-move-group-name (prompt default articles prefix)
10777   "Read a group name."
10778   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10779          (minibuffer-confirm-incomplete nil) ; XEmacs
10780          (prom
10781           (format "%s %s to:"
10782                   prompt
10783                   (if (> (length articles) 1)
10784                       (format "these %d articles" (length articles))
10785                     "this article")))
10786          (to-newsgroup
10787           (cond
10788            ((null split-name)
10789             (gnus-completing-read-with-default
10790              default prom
10791              gnus-active-hashtb
10792              'gnus-valid-move-group-p
10793              nil prefix
10794              'gnus-group-history))
10795            ((= 1 (length split-name))
10796             (gnus-completing-read-with-default
10797              (car split-name) prom
10798              gnus-active-hashtb
10799              'gnus-valid-move-group-p
10800              nil nil
10801              'gnus-group-history))
10802            (t
10803             (gnus-completing-read-with-default
10804              nil prom
10805              (mapcar (lambda (el) (list el))
10806                      (nreverse split-name))
10807              nil nil nil
10808              'gnus-group-history))))
10809          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10810     (when to-newsgroup
10811       (if (or (string= to-newsgroup "")
10812               (string= to-newsgroup prefix))
10813           (setq to-newsgroup default))
10814       (unless to-newsgroup
10815         (error "No group name entered"))
10816       (or (gnus-active to-newsgroup)
10817           (gnus-activate-group to-newsgroup nil nil to-method)
10818           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10819                                      to-newsgroup))
10820               (or (and (gnus-request-create-group to-newsgroup to-method)
10821                        (gnus-activate-group
10822                         to-newsgroup nil nil to-method)
10823                        (gnus-subscribe-group to-newsgroup))
10824                   (error "Couldn't create group %s" to-newsgroup)))
10825           (error "No such group: %s" to-newsgroup)))
10826     to-newsgroup))
10827
10828 (defun gnus-summary-save-parts (type dir n &optional reverse)
10829   "Save parts matching TYPE to DIR.
10830 If REVERSE, save parts that do not match TYPE."
10831   (interactive
10832    (list (read-string "Save parts of type: "
10833                       (or (car gnus-summary-save-parts-type-history)
10834                           gnus-summary-save-parts-default-mime)
10835                       'gnus-summary-save-parts-type-history)
10836          (setq gnus-summary-save-parts-last-directory
10837                (read-file-name "Save to directory: "
10838                                gnus-summary-save-parts-last-directory
10839                                nil t))
10840          current-prefix-arg))
10841   (gnus-summary-iterate n
10842     (let ((gnus-display-mime-function nil)
10843           (gnus-inhibit-treatment t))
10844       (gnus-summary-select-article))
10845     (save-excursion
10846       (set-buffer gnus-article-buffer)
10847       (let ((handles (or gnus-article-mime-handles
10848                          (mm-dissect-buffer nil gnus-article-loose-mime)
10849                          (and gnus-article-emulate-mime
10850                               (mm-uu-dissect)))))
10851         (when handles
10852           (gnus-summary-save-parts-1 type dir handles reverse)
10853           (unless gnus-article-mime-handles ;; Don't destroy this case.
10854             (mm-destroy-parts handles)))))))
10855
10856 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10857   (if (stringp (car handle))
10858       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10859               (cdr handle))
10860     (when (if reverse
10861               (not (string-match type (mm-handle-media-type handle)))
10862             (string-match type (mm-handle-media-type handle)))
10863       (let ((file (expand-file-name
10864                    (file-name-nondirectory
10865                     (or
10866                      (mail-content-type-get
10867                       (mm-handle-disposition handle) 'filename)
10868                      (concat gnus-newsgroup-name
10869                              "." (number-to-string
10870                                   (cdr gnus-article-current)))))
10871                    dir)))
10872         (unless (file-exists-p file)
10873           (mm-save-part-to-file handle file))))))
10874
10875 ;; Summary extract commands
10876
10877 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10878   (let ((buffer-read-only nil)
10879         (article (gnus-summary-article-number))
10880         after-article b e)
10881     (unless (gnus-summary-goto-subject article)
10882       (error "No such article: %d" article))
10883     (gnus-summary-position-point)
10884     ;; If all commands are to be bunched up on one line, we collect
10885     ;; them here.
10886     (unless gnus-view-pseudos-separately
10887       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10888             files action)
10889         (while ps
10890           (setq action (cdr (assq 'action (car ps))))
10891           (setq files (list (cdr (assq 'name (car ps)))))
10892           (while (and ps (cdr ps)
10893                       (string= (or action "1")
10894                                (or (cdr (assq 'action (cadr ps))) "2")))
10895             (push (cdr (assq 'name (cadr ps))) files)
10896             (setcdr ps (cddr ps)))
10897           (when files
10898             (when (not (string-match "%s" action))
10899               (push " " files))
10900             (push " " files)
10901             (when (assq 'execute (car ps))
10902               (setcdr (assq 'execute (car ps))
10903                       (funcall (if (string-match "%s" action)
10904                                    'format 'concat)
10905                                action
10906                                (mapconcat
10907                                 (lambda (f)
10908                                   (if (equal f " ")
10909                                       f
10910                                     (gnus-quote-arg-for-sh-or-csh f)))
10911                                 files " ")))))
10912           (setq ps (cdr ps)))))
10913     (if (and gnus-view-pseudos (not not-view))
10914         (while pslist
10915           (when (assq 'execute (car pslist))
10916             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10917                                   (eq gnus-view-pseudos 'not-confirm)))
10918           (setq pslist (cdr pslist)))
10919       (save-excursion
10920         (while pslist
10921           (setq after-article (or (cdr (assq 'article (car pslist)))
10922                                   (gnus-summary-article-number)))
10923           (gnus-summary-goto-subject after-article)
10924           (forward-line 1)
10925           (setq b (point))
10926           (insert "    " (file-name-nondirectory
10927                           (cdr (assq 'name (car pslist))))
10928                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10929           (setq e (point))
10930           (forward-line -1)             ; back to `b'
10931           (gnus-add-text-properties
10932            b (1- e) (list 'gnus-number gnus-reffed-article-number
10933                           gnus-mouse-face-prop gnus-mouse-face))
10934           (gnus-data-enter
10935            after-article gnus-reffed-article-number
10936            gnus-unread-mark b (car pslist) 0 (- e b))
10937           (setq gnus-newsgroup-unreads
10938                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10939                                          gnus-reffed-article-number))
10940           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10941           (setq pslist (cdr pslist)))))))
10942
10943 (defun gnus-pseudos< (p1 p2)
10944   (let ((c1 (cdr (assq 'action p1)))
10945         (c2 (cdr (assq 'action p2))))
10946     (and c1 c2 (string< c1 c2))))
10947
10948 (defun gnus-request-pseudo-article (props)
10949   (cond ((assq 'execute props)
10950          (gnus-execute-command (cdr (assq 'execute props)))))
10951   (let ((gnus-current-article (gnus-summary-article-number)))
10952     (gnus-run-hooks 'gnus-mark-article-hook)))
10953
10954 (defun gnus-execute-command (command &optional automatic)
10955   (save-excursion
10956     (gnus-article-setup-buffer)
10957     (set-buffer gnus-article-buffer)
10958     (setq buffer-read-only nil)
10959     (let ((command (if automatic command
10960                      (read-string "Command: " (cons command 0)))))
10961       (erase-buffer)
10962       (insert "$ " command "\n\n")
10963       (if gnus-view-pseudo-asynchronously
10964           (start-process "gnus-execute" (current-buffer) shell-file-name
10965                          shell-command-switch command)
10966         (call-process shell-file-name nil t nil
10967                       shell-command-switch command)))))
10968
10969 ;; Summary kill commands.
10970
10971 (defun gnus-summary-edit-global-kill (article)
10972   "Edit the \"global\" kill file."
10973   (interactive (list (gnus-summary-article-number)))
10974   (gnus-group-edit-global-kill article))
10975
10976 (defun gnus-summary-edit-local-kill ()
10977   "Edit a local kill file applied to the current newsgroup."
10978   (interactive)
10979   (setq gnus-current-headers (gnus-summary-article-header))
10980   (gnus-group-edit-local-kill
10981    (gnus-summary-article-number) gnus-newsgroup-name))
10982
10983 ;;; Header reading.
10984
10985 (defun gnus-read-header (id &optional header)
10986   "Read the headers of article ID and enter them into the Gnus system."
10987   (let ((group gnus-newsgroup-name)
10988         (gnus-override-method
10989          (or
10990           gnus-override-method
10991           (and (gnus-news-group-p gnus-newsgroup-name)
10992                (car (gnus-refer-article-methods)))))
10993         where)
10994     ;; First we check to see whether the header in question is already
10995     ;; fetched.
10996     (if (stringp id)
10997         ;; This is a Message-ID.
10998         (setq header (or header (gnus-id-to-header id)))
10999       ;; This is an article number.
11000       (setq header (or header (gnus-summary-article-header id))))
11001     (if (and header
11002              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11003         ;; We have found the header.
11004         header
11005       ;; If this is a sparse article, we have to nix out its
11006       ;; previous entry in the thread hashtb.
11007       (when (and header
11008                  (gnus-summary-article-sparse-p (mail-header-number header)))
11009         (let* ((parent (gnus-parent-id (mail-header-references header)))
11010                (thread (and parent (gnus-id-to-thread parent))))
11011           (when thread
11012             (delq (assq header thread) thread))))
11013       ;; We have to really fetch the header to this article.
11014       (save-excursion
11015         (set-buffer nntp-server-buffer)
11016         (when (setq where (gnus-request-head id group))
11017           (nnheader-fold-continuation-lines)
11018           (goto-char (point-max))
11019           (insert ".\n")
11020           (goto-char (point-min))
11021           (insert "211 ")
11022           (princ (cond
11023                   ((numberp id) id)
11024                   ((cdr where) (cdr where))
11025                   (header (mail-header-number header))
11026                   (t gnus-reffed-article-number))
11027                  (current-buffer))
11028           (insert " Article retrieved.\n"))
11029         (if (or (not where)
11030                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11031             ()                          ; Malformed head.
11032           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11033             (when (and (stringp id)
11034                        (not (string= (gnus-group-real-name group)
11035                                      (car where))))
11036               ;; If we fetched by Message-ID and the article came
11037               ;; from a different group, we fudge some bogus article
11038               ;; numbers for this article.
11039               (mail-header-set-number header gnus-reffed-article-number))
11040             (save-excursion
11041               (set-buffer gnus-summary-buffer)
11042               (decf gnus-reffed-article-number)
11043               (gnus-remove-header (mail-header-number header))
11044               (push header gnus-newsgroup-headers)
11045               (setq gnus-current-headers header)
11046               (push (mail-header-number header) gnus-newsgroup-limit)))
11047           header)))))
11048
11049 (defun gnus-remove-header (number)
11050   "Remove header NUMBER from `gnus-newsgroup-headers'."
11051   (if (and gnus-newsgroup-headers
11052            (= number (mail-header-number (car gnus-newsgroup-headers))))
11053       (pop gnus-newsgroup-headers)
11054     (let ((headers gnus-newsgroup-headers))
11055       (while (and (cdr headers)
11056                   (not (= number (mail-header-number (cadr headers)))))
11057         (pop headers))
11058       (when (cdr headers)
11059         (setcdr headers (cddr headers))))))
11060
11061 ;;;
11062 ;;; summary highlights
11063 ;;;
11064
11065 (defun gnus-highlight-selected-summary ()
11066   "Highlight selected article in summary buffer."
11067   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11068   (when gnus-summary-selected-face
11069     (save-excursion
11070       (let* ((beg (progn (beginning-of-line) (point)))
11071              (end (progn (end-of-line) (point)))
11072              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11073              (from (if (get-text-property beg gnus-mouse-face-prop)
11074                        beg
11075                      (or (next-single-property-change
11076                           beg gnus-mouse-face-prop nil end)
11077                          beg)))
11078              (to
11079               (if (= from end)
11080                   (- from 2)
11081                 (or (next-single-property-change
11082                      from gnus-mouse-face-prop nil end)
11083                     end))))
11084         ;; If no mouse-face prop on line we will have to = from = end,
11085         ;; so we highlight the entire line instead.
11086         (when (= (+ to 2) from)
11087           (setq from beg)
11088           (setq to end))
11089         (if gnus-newsgroup-selected-overlay
11090             ;; Move old overlay.
11091             (gnus-move-overlay
11092              gnus-newsgroup-selected-overlay from to (current-buffer))
11093           ;; Create new overlay.
11094           (gnus-overlay-put
11095            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11096            'face gnus-summary-selected-face))))))
11097
11098 (defvar gnus-summary-highlight-line-cached nil)
11099 (defvar gnus-summary-highlight-line-trigger nil)
11100
11101 (defun gnus-summary-highlight-line-0 ()
11102   (if (and (eq gnus-summary-highlight-line-trigger 
11103                gnus-summary-highlight)
11104            gnus-summary-highlight-line-cached)
11105       gnus-summary-highlight-line-cached
11106     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11107           gnus-summary-highlight-line-cached
11108           (let* ((cond (list 'cond))
11109                  (c cond)
11110                  (list gnus-summary-highlight))
11111             (while list
11112               (setcdr c (cons (list (caar list) (list 'quote (cdar list))) nil))
11113               (setq c (cdr c)
11114                     list (cdr list)))
11115             (gnus-byte-compile (list 'lambda nil cond))))))
11116
11117 (defun gnus-summary-highlight-line ()
11118   "Highlight current line according to `gnus-summary-highlight'."
11119   (let* ((beg (gnus-point-at-bol))
11120          (article (or (gnus-summary-article-number) gnus-current-article))
11121          (score (or (cdr (assq article
11122                                gnus-newsgroup-scored))
11123                     gnus-summary-default-score 0))
11124          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11125          (inhibit-read-only t)
11126          (default gnus-summary-default-score)
11127          (default-high gnus-summary-default-high-score)
11128          (default-low gnus-summary-default-low-score)
11129          (uncached (memq article gnus-newsgroup-undownloaded))
11130          (downloaded (not uncached)))
11131     (let ((face (funcall (gnus-summary-highlight-line-0))))
11132       (unless (eq face (get-text-property beg 'face))
11133         (gnus-put-text-property-excluding-characters-with-faces
11134          beg (gnus-point-at-eol) 'face
11135          (setq face (if (boundp face) (symbol-value face) face)))
11136         (when gnus-summary-highlight-line-function
11137           (funcall gnus-summary-highlight-line-function article face))))))
11138
11139 (defun gnus-update-read-articles (group unread &optional compute)
11140   "Update the list of read articles in GROUP.
11141 UNREAD is a sorted list."
11142   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
11143          (entry (gnus-gethash group gnus-newsrc-hashtb))
11144          (info (nth 2 entry))
11145          (prev 1)
11146          read)
11147     (if (or (not info) (not active))
11148         ;; There is no info on this group if it was, in fact,
11149         ;; killed.  Gnus stores no information on killed groups, so
11150         ;; there's nothing to be done.
11151         ;; One could store the information somewhere temporarily,
11152         ;; perhaps...  Hmmm...
11153         ()
11154       ;; Remove any negative articles numbers.
11155       (while (and unread (< (car unread) 0))
11156         (setq unread (cdr unread)))
11157       ;; Remove any expired article numbers
11158       (while (and unread (< (car unread) (car active)))
11159         (setq unread (cdr unread)))
11160       ;; Compute the ranges of read articles by looking at the list of
11161       ;; unread articles.
11162       (while unread
11163         (when (/= (car unread) prev)
11164           (push (if (= prev (1- (car unread))) prev
11165                   (cons prev (1- (car unread))))
11166                 read))
11167         (setq prev (1+ (car unread)))
11168         (setq unread (cdr unread)))
11169       (when (<= prev (cdr active))
11170         (push (cons prev (cdr active)) read))
11171       (setq read (if (> (length read) 1) (nreverse read) read))
11172       (if compute
11173           read
11174         (save-excursion
11175           (let (setmarkundo)
11176             ;; Propagate the read marks to the backend.
11177             (when (gnus-check-backend-function 'request-set-mark group)
11178               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11179                     (add (gnus-remove-from-range read (gnus-info-read info))))
11180                 (when (or add del)
11181                   (unless (gnus-check-group group)
11182                     (error "Can't open server for %s" group))
11183                   (gnus-request-set-mark
11184                    group (delq nil (list (if add (list add 'add '(read)))
11185                                          (if del (list del 'del '(read))))))
11186                   (setq setmarkundo
11187                         `(gnus-request-set-mark
11188                           ,group
11189                           ',(delq nil (list
11190                                        (if del (list del 'add '(read)))
11191                                        (if add (list add 'del '(read))))))))))
11192             (set-buffer gnus-group-buffer)
11193             (gnus-undo-register
11194               `(progn
11195                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11196                  (gnus-info-set-read ',info ',(gnus-info-read info))
11197                  (gnus-get-unread-articles-in-group ',info
11198                                                     (gnus-active ,group))
11199                  (gnus-group-update-group ,group t)
11200                  ,setmarkundo))))
11201         ;; Enter this list into the group info.
11202         (gnus-info-set-read info read)
11203         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11204         (gnus-get-unread-articles-in-group info (gnus-active group))
11205         t))))
11206
11207 (defun gnus-offer-save-summaries ()
11208   "Offer to save all active summary buffers."
11209   (let (buffers)
11210     ;; Go through all buffers and find all summaries.
11211     (dolist (buffer (buffer-list))
11212       (when (and (setq buffer (buffer-name buffer))
11213                  (string-match "Summary" buffer)
11214                  (save-excursion
11215                    (set-buffer buffer)
11216                    ;; We check that this is, indeed, a summary buffer.
11217                    (and (eq major-mode 'gnus-summary-mode)
11218                         ;; Also make sure this isn't bogus.
11219                         gnus-newsgroup-prepared
11220                         ;; Also make sure that this isn't a
11221                         ;; dead summary buffer.
11222                         (not gnus-dead-summary-mode))))
11223         (push buffer buffers)))
11224     ;; Go through all these summary buffers and offer to save them.
11225     (when buffers
11226       (save-excursion
11227         (map-y-or-n-p
11228          "Update summary buffer %s? "
11229          (lambda (buf)
11230            (switch-to-buffer buf)
11231            (gnus-summary-exit))
11232          buffers)))))
11233
11234
11235 ;;; @ for mime-partial
11236 ;;;
11237
11238 (defun gnus-request-partial-message ()
11239   (save-excursion
11240     (let ((number (gnus-summary-article-number))
11241           (group gnus-newsgroup-name)
11242           (mother gnus-article-buffer))
11243       (set-buffer (get-buffer-create " *Partial Article*"))
11244       (erase-buffer)
11245       (setq mime-preview-buffer mother)
11246       (gnus-request-article-this-buffer number group)
11247       (mime-parse-buffer)
11248       )))
11249
11250 (autoload 'mime-combine-message/partial-pieces-automatically
11251   "mime-partial"
11252   "Internal method to combine message/partial messages automatically.")
11253
11254 (mime-add-condition
11255  'action '((type . message)(subtype . partial)
11256            (major-mode . gnus-original-article-mode)
11257            (method . mime-combine-message/partial-pieces-automatically)
11258            (summary-buffer-exp . gnus-summary-buffer)
11259            (request-partial-message-method . gnus-request-partial-message)
11260            ))
11261
11262
11263 ;;; @ for message/rfc822
11264 ;;;
11265
11266 (defun gnus-mime-extract-message/rfc822 (entity situation)
11267   "Burst a forwarded article."
11268   (save-excursion
11269     (set-buffer gnus-summary-buffer)
11270     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11271                                    gnus-newsgroup-name 'gnus-group-history))
11272            (gnus-group-marked (list group))
11273            article info)
11274       (with-temp-buffer
11275         (mime-insert-entity-content entity)
11276         (setq article (gnus-request-accept-article group)))
11277       (when (and (consp article)
11278                  (numberp (setq article (cdr article))))
11279         (setq info (gnus-get-info group))
11280         (gnus-info-set-read info
11281                             (gnus-remove-from-range (gnus-info-read info)
11282                                                     (list article)))
11283         (when (string-equal group gnus-newsgroup-name)
11284           (forward-line 1)
11285           (let (gnus-show-threads)
11286             (gnus-summary-goto-subject article t))
11287           (gnus-summary-clear-mark-forward 1))
11288         (set-buffer gnus-group-buffer)
11289         (gnus-group-get-new-news-this-group nil t)))))
11290
11291 (mime-add-condition
11292  'action '((type . message)(subtype . rfc822)
11293            (major-mode . gnus-original-article-mode)
11294            (method . gnus-mime-extract-message/rfc822)
11295            (mode . "extract")
11296            ))
11297
11298 (mime-add-condition
11299  'action '((type . message)(subtype . news)
11300            (major-mode . gnus-original-article-mode)
11301            (method . gnus-mime-extract-message/rfc822)
11302            (mode . "extract")
11303            ))
11304
11305 (defun gnus-mime-extract-multipart (entity situation)
11306   (let ((children (mime-entity-children entity))
11307         mime-acting-situation-to-override
11308         f)
11309     (while children
11310       (mime-play-entity (car children)
11311                         (cons (assq 'mode situation)
11312                               mime-acting-situation-to-override))
11313       (setq children (cdr children)))
11314     (if (setq f (cdr (assq 'after-method
11315                            mime-acting-situation-to-override)))
11316         (eval f)
11317       )))
11318
11319 (mime-add-condition
11320  'action '((type . multipart)
11321            (method . gnus-mime-extract-multipart)
11322            (mode . "extract")
11323            )
11324  'with-default)
11325
11326
11327 ;;; @ end
11328 ;;;
11329
11330 (defun gnus-summary-inherit-default-charset ()
11331   "Import `default-mime-charset' from summary buffer.
11332 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11333 of FLIM is used."
11334   (if (buffer-live-p gnus-summary-buffer)
11335       (let (d-m-c d-m-c-u)
11336         (with-current-buffer gnus-summary-buffer
11337           (setq d-m-c (if (local-variable-p 'default-mime-charset
11338                                             gnus-summary-buffer)
11339                           default-mime-charset
11340                         t)
11341                 ;; LIMIT
11342                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11343                                               gnus-summary-buffer)
11344                             (symbol-value 'default-mime-charset-unlimited)
11345                           t)))
11346         (if (eq t d-m-c)
11347             (kill-local-variable 'default-mime-charset)
11348           (set (make-local-variable 'default-mime-charset) d-m-c))
11349         (if (eq t d-m-c-u)
11350             (kill-local-variable 'default-mime-charset-unlimited)
11351           (set (make-local-variable 'default-mime-charset-unlimited)
11352                d-m-c-u)))))
11353
11354 (defun gnus-summary-setup-default-charset ()
11355   "Setup newsgroup default charset."
11356   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11357       (progn
11358         (setq gnus-newsgroup-charset nil)
11359         (set (make-local-variable 'default-mime-charset) nil)
11360         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11361           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11362     (let ((ignored-charsets
11363            (or gnus-newsgroup-ephemeral-ignored-charsets
11364                (append
11365                 (and gnus-newsgroup-name
11366                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11367                 gnus-newsgroup-ignored-charsets)))
11368           charset)
11369       (setq gnus-newsgroup-charset
11370             (or gnus-newsgroup-ephemeral-charset
11371                 (when (and gnus-newsgroup-name
11372                            (setq charset (gnus-parameter-charset
11373                                           gnus-newsgroup-name)))
11374                   (make-local-variable 'default-mime-charset)
11375                   (setq default-mime-charset charset))
11376                 gnus-default-charset))
11377       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11378            ignored-charsets))))
11379
11380 ;;;
11381 ;;; Mime Commands
11382 ;;;
11383
11384 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11385   "Display the current article buffer fully MIME-buttonized.
11386 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11387 treated as multipart/mixed."
11388   (interactive "P")
11389   (require 'gnus-art)
11390   (let ((gnus-unbuttonized-mime-types nil)
11391         (gnus-mime-display-multipart-as-mixed show-all-parts))
11392     (gnus-summary-show-article)))
11393
11394 (defun gnus-summary-repair-multipart (article)
11395   "Add a Content-Type header to a multipart article without one."
11396   (interactive (list (gnus-summary-article-number)))
11397   (gnus-with-article article
11398     (message-narrow-to-head)
11399     (message-remove-header "Mime-Version")
11400     (goto-char (point-max))
11401     (insert "Mime-Version: 1.0\n")
11402     (widen)
11403     (when (search-forward "\n--" nil t)
11404       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11405         (message-narrow-to-head)
11406         (message-remove-header "Content-Type")
11407         (goto-char (point-max))
11408         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11409                         separator))
11410         (widen))))
11411   (let (gnus-mark-article-hook)
11412     (gnus-summary-select-article t t nil article)))
11413
11414 (defun gnus-summary-toggle-display-buttonized ()
11415   "Toggle the buttonizing of the article buffer."
11416   (interactive)
11417   (require 'gnus-art)
11418   (if (setq gnus-inhibit-mime-unbuttonizing
11419             (not gnus-inhibit-mime-unbuttonizing))
11420       (let ((gnus-unbuttonized-mime-types nil))
11421         (gnus-summary-show-article))
11422     (gnus-summary-show-article)))
11423
11424 ;;;
11425 ;;; Intelli-mouse commmands
11426 ;;;
11427
11428 (defun gnus-wheel-summary-scroll (event)
11429   (interactive "e")
11430   (let ((amount (if (memq 'shift (event-modifiers event))
11431                     (car gnus-wheel-scroll-amount)
11432                   (cdr gnus-wheel-scroll-amount)))
11433         (direction (- (* (static-if (featurep 'xemacs)
11434                              (event-button event)
11435                            (cond ((eq 'mouse-4 (event-basic-type event))
11436                                   4)
11437                                  ((eq 'mouse-5 (event-basic-type event))
11438                                   5)))
11439                          2) 9))
11440         edge)
11441     (gnus-summary-scroll-up (* amount direction))
11442     (when (gnus-eval-in-buffer-window gnus-article-buffer
11443             (save-restriction
11444               (widen)
11445               (and (if (< 0 direction)
11446                        (gnus-article-next-page 0)
11447                      (gnus-article-prev-page 0)
11448                      (bobp))
11449                    (if (setq edge (get-text-property
11450                                    (point-min) 'gnus-wheel-edge))
11451                        (setq edge (* edge direction))
11452                      (setq edge -1))
11453                    (or (plusp edge)
11454                        (let ((buffer-read-only nil)
11455                              (inhibit-read-only t))
11456                          (put-text-property (point-min) (point-max)
11457                                             'gnus-wheel-edge direction)
11458                          nil))
11459                    (or (> edge gnus-wheel-edge-resistance)
11460                        (let ((buffer-read-only nil)
11461                              (inhibit-read-only t))
11462                          (put-text-property (point-min) (point-max)
11463                                             'gnus-wheel-edge
11464                                             (* (1+ edge) direction))
11465                          nil))
11466                    (eq last-command 'gnus-wheel-summary-scroll))))
11467       (gnus-summary-next-article nil nil (minusp direction)))))
11468
11469 (defun gnus-wheel-install ()
11470   "Enable mouse wheel support on summary window."
11471   (when gnus-use-wheel
11472     (let ((keys
11473            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11474       (dolist (key keys)
11475         (define-key gnus-summary-mode-map key
11476           'gnus-wheel-summary-scroll)))))
11477
11478 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11479
11480 ;;;
11481 ;;; Traditional PGP commmands
11482 ;;;
11483
11484 (defun gnus-summary-decrypt-article (&optional force)
11485   "Decrypt the current article in traditional PGP way.
11486 This will have permanent effect only in mail groups.
11487 If FORCE is non-nil, allow editing of articles even in read-only
11488 groups."
11489   (interactive "P")
11490   (gnus-summary-select-article t)
11491   (gnus-eval-in-buffer-window gnus-article-buffer
11492     (save-excursion
11493       (save-restriction
11494         (widen)
11495         (goto-char (point-min))
11496         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11497           (error "Not a traditional PGP message!"))
11498         (let ((armor-start (match-beginning 0)))
11499           (if (and (pgg-decrypt-region armor-start (point-max))
11500                    (or force (not (gnus-group-read-only-p))))
11501               (let ((inhibit-read-only t)
11502                     buffer-read-only)
11503                 (delete-region armor-start
11504                                (progn
11505                                  (re-search-forward "^-+END PGP" nil t)
11506                                  (beginning-of-line 2)
11507                                  (point)))
11508                 (insert-buffer-substring pgg-output-buffer))))))))
11509
11510 (defun gnus-summary-verify-article ()
11511   "Verify the current article in traditional PGP way."
11512   (interactive)
11513   (save-excursion
11514     (set-buffer gnus-original-article-buffer)
11515     (goto-char (point-min))
11516     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11517       (error "Not a traditional PGP message!"))
11518     (re-search-forward "^-+END PGP" nil t)
11519     (beginning-of-line 2)
11520     (call-interactively (function pgg-verify-region))))
11521
11522 ;;;
11523 ;;; Generic summary marking commands
11524 ;;;
11525
11526 (defvar gnus-summary-marking-alist
11527   '((read gnus-del-mark "d")
11528     (unread gnus-unread-mark "u")
11529     (ticked gnus-ticked-mark "!")
11530     (dormant gnus-dormant-mark "?")
11531     (expirable gnus-expirable-mark "e"))
11532   "An alist of names/marks/keystrokes.")
11533
11534 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11535 (defvar gnus-summary-mark-map)
11536
11537 (defun gnus-summary-make-all-marking-commands ()
11538   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11539   (dolist (elem gnus-summary-marking-alist)
11540     (apply 'gnus-summary-make-marking-command elem)))
11541
11542 (defun gnus-summary-make-marking-command (name mark keystroke)
11543   (let ((map (make-sparse-keymap)))
11544     (define-key gnus-summary-generic-mark-map keystroke map)
11545     (dolist (lway `((next "next" next nil "n")
11546                     (next-unread "next unread" next t "N")
11547                     (prev "previous" prev nil "p")
11548                     (prev-unread "previous unread" prev t "P")
11549                     (nomove "" nil nil ,keystroke)))
11550       (let ((func (gnus-summary-make-marking-command-1
11551                    mark (car lway) lway name)))
11552         (setq func (eval func))
11553         (define-key map (nth 4 lway) func)))))
11554
11555 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11556   `(defun ,(intern
11557             (format "gnus-summary-put-mark-as-%s%s"
11558                     name (if (eq way 'nomove)
11559                              ""
11560                            (concat "-" (symbol-name way)))))
11561      (n)
11562      ,(format
11563        "Mark the current article as %s%s.
11564 If N, the prefix, then repeat N times.
11565 If N is negative, move in reverse order.
11566 The difference between N and the actual number of articles marked is
11567 returned."
11568        name (car (cdr lway)))
11569      (interactive "p")
11570      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11571
11572 (defun gnus-summary-generic-mark (n mark move unread)
11573   "Mark N articles with MARK."
11574   (unless (eq major-mode 'gnus-summary-mode)
11575     (error "This command can only be used in the summary buffer"))
11576   (gnus-summary-show-thread)
11577   (let ((nummove
11578          (cond
11579           ((eq move 'next) 1)
11580           ((eq move 'prev) -1)
11581           (t 0))))
11582     (if (zerop nummove)
11583         (setq n 1)
11584       (when (< n 0)
11585         (setq n (abs n)
11586               nummove (* -1 nummove))))
11587     (while (and (> n 0)
11588                 (gnus-summary-mark-article nil mark)
11589                 (zerop (gnus-summary-next-subject nummove unread t)))
11590       (setq n (1- n)))
11591     (when (/= 0 n)
11592       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11593     (gnus-summary-recenter)
11594     (gnus-summary-position-point)
11595     (gnus-set-mode-line 'summary)
11596     n))
11597
11598 (defun gnus-summary-insert-articles (articles)
11599   (when (setq articles
11600               (gnus-sorted-difference articles
11601                                       (mapcar (lambda (h)
11602                                                 (mail-header-number h))
11603                                               gnus-newsgroup-headers)))
11604     (setq gnus-newsgroup-headers
11605           (merge 'list
11606                  gnus-newsgroup-headers
11607                  (gnus-fetch-headers articles)
11608                  'gnus-article-sort-by-number))
11609     ;; Suppress duplicates?
11610     (when gnus-suppress-duplicates
11611       (gnus-dup-suppress-articles))
11612
11613     ;; We might want to build some more threads first.
11614     (when (and gnus-fetch-old-headers
11615                (eq gnus-headers-retrieved-by 'nov))
11616       (if (eq gnus-fetch-old-headers 'invisible)
11617           (gnus-build-all-threads)
11618         (gnus-build-old-threads)))
11619     ;; Let the Gnus agent mark articles as read.
11620     (when gnus-agent
11621       (gnus-agent-get-undownloaded-list))
11622     ;; Remove list identifiers from subject
11623     (when gnus-list-identifiers
11624       (gnus-summary-remove-list-identifiers))
11625     ;; First and last article in this newsgroup.
11626     (when gnus-newsgroup-headers
11627       (setq gnus-newsgroup-begin
11628             (mail-header-number (car gnus-newsgroup-headers))
11629             gnus-newsgroup-end
11630             (mail-header-number
11631              (gnus-last-element gnus-newsgroup-headers))))
11632     (when gnus-use-scoring
11633       (gnus-possibly-score-headers))))
11634
11635 (defun gnus-summary-insert-old-articles (&optional all)
11636   "Insert all old articles in this group.
11637 If ALL is non-nil, already read articles become readable.
11638 If ALL is a number, fetch this number of articles."
11639   (interactive "P")
11640   (prog1
11641       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11642             older len)
11643         (setq older
11644               ;; Some nntp servers lie about their active range.  When
11645               ;; this happens, the active range can be in the millions.
11646               ;; Use a compressed range to avoid creating a huge list.
11647               (gnus-range-difference (list gnus-newsgroup-active) old))
11648         (setq len (gnus-range-length older))
11649         (cond
11650          ((null older) nil)
11651          ((numberp all)
11652           (if (< all len)
11653               (let ((older-range (nreverse older)))
11654                 (setq older nil)
11655
11656                 (while (> all 0)
11657                   (let* ((r (pop older-range))
11658                          (min (if (numberp r) r (car r)))
11659                          (max (if (numberp r) r (cdr r))))
11660                     (while (and (<= min max)
11661                                 (> all 0))
11662                       (push max older)
11663                       (setq all (1- all)
11664                             max (1- max))))))
11665             (setq older (gnus-uncompress-range older))))
11666          (all
11667           (setq older (gnus-uncompress-range older)))
11668          (t
11669           (when (and (numberp gnus-large-newsgroup)
11670                    (> len gnus-large-newsgroup))
11671               (let* ((cursor-in-echo-area nil)
11672                      (initial (gnus-parameter-large-newsgroup-initial
11673                                gnus-newsgroup-name))
11674                      (input
11675                       (read-string
11676                        (format
11677                         "How many articles from %s (%s %d): "
11678                         (gnus-limit-string
11679                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11680                         (if initial "max" "default")
11681                         len)
11682                        (if initial
11683                            (cons (number-to-string initial)
11684                                  0)))))
11685                 (unless (string-match "^[ \t]*$" input)
11686                   (setq all (string-to-number input))
11687                   (if (< all len)
11688                       (let ((older-range (nreverse older)))
11689                         (setq older nil)
11690
11691                         (while (> all 0)
11692                           (let* ((r (pop older-range))
11693                                  (min (if (numberp r) r (car r)))
11694                                  (max (if (numberp r) r (cdr r))))
11695                             (while (and (<= min max)
11696                                         (> all 0))
11697                               (push max older)
11698                               (setq all (1- all)
11699                                     max (1- max))))))))))
11700           (setq older (gnus-uncompress-range older))))
11701         (if (not older)
11702             (message "No old news.")
11703           (gnus-summary-insert-articles older)
11704           (gnus-summary-limit (gnus-sorted-nunion old older))))
11705     (gnus-summary-position-point)))
11706
11707 (defun gnus-summary-insert-new-articles ()
11708   "Insert all new articles in this group."
11709   (interactive)
11710   (prog1
11711       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11712             (old-active gnus-newsgroup-active)
11713             (nnmail-fetched-sources (list t))
11714             i new)
11715         (setq gnus-newsgroup-active
11716               (gnus-activate-group gnus-newsgroup-name 'scan))
11717         (setq i (cdr gnus-newsgroup-active))
11718         (while (> i (cdr old-active))
11719           (push i new)
11720           (decf i))
11721         (if (not new)
11722             (message "No gnus is bad news.")
11723           (gnus-summary-insert-articles new)
11724           (setq gnus-newsgroup-unreads
11725                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11726           (gnus-summary-limit (gnus-sorted-nunion old new))))
11727     (gnus-summary-position-point)))
11728
11729 (gnus-summary-make-all-marking-commands)
11730
11731 (gnus-ems-redefine)
11732
11733 (provide 'gnus-sum)
11734
11735 (run-hooks 'gnus-sum-load-hook)
11736
11737 ;;; gnus-sum.el ends here