t-gnus-6_15-quimby: New branch for developing and synchronizing with Oort Gnus.
[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
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
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 ;; Recursive :-(.
41 ;; (require 'gnus-art)
42 (require 'nnoo)
43 (require 'mime-view)
44
45 (eval-when-compile
46   (require 'mime-play)
47   (require 'static))
48
49 (eval-and-compile
50   (autoload 'gnus-cache-articles-in-group "gnus-cache")
51   (autoload 'pgg-decrypt-region "pgg" nil t)
52   (autoload 'pgg-verify-region "pgg" nil t))
53
54 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
55 (autoload 'gnus-cache-write-active "gnus-cache")
56 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
57 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
58 (autoload 'mm-uu-dissect "mm-uu")
59
60 (defcustom gnus-kill-summary-on-exit t
61   "*If non-nil, kill the summary buffer when you exit from it.
62 If nil, the summary will become a \"*Dead Summary*\" buffer, and
63 it will be killed sometime later."
64   :group 'gnus-summary-exit
65   :type 'boolean)
66
67 (defcustom gnus-fetch-old-headers nil
68   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
69 If an unread article in the group refers to an older, already read (or
70 just marked as read) article, the old article will not normally be
71 displayed in the Summary buffer.  If this variable is non-nil, Gnus
72 will attempt to grab the headers to the old articles, and thereby
73 build complete threads.  If it has the value `some', only enough
74 headers to connect otherwise loose threads will be displayed.  This
75 variable can also be a number.  In that case, no more than that number
76 of old headers will be fetched.  If it has the value `invisible', all
77 old headers will be fetched, but none will be displayed.
78
79 The server has to support NOV for any of this to work."
80   :group 'gnus-thread
81   :type '(choice (const :tag "off" nil)
82                  (const some)
83                  number
84                  (sexp :menu-tag "other" t)))
85
86 (defcustom gnus-refer-thread-limit 200
87   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
88 If t, fetch all the available old headers."
89   :group 'gnus-thread
90   :type '(choice number
91                  (sexp :menu-tag "other" t)))
92
93 (defcustom gnus-summary-make-false-root 'adopt
94   "*nil means that Gnus won't gather loose threads.
95 If the root of a thread has expired or been read in a previous
96 session, the information necessary to build a complete thread has been
97 lost.  Instead of having many small sub-threads from this original thread
98 scattered all over the summary buffer, Gnus can gather them.
99
100 If non-nil, Gnus will try to gather all loose sub-threads from an
101 original thread into one large thread.
102
103 If this variable is non-nil, it should be one of `none', `adopt',
104 `dummy' or `empty'.
105
106 If this variable is `none', Gnus will not make a false root, but just
107 present the sub-threads after another.
108 If this variable is `dummy', Gnus will create a dummy root that will
109 have all the sub-threads as children.
110 If this variable is `adopt', Gnus will make one of the \"children\"
111 the parent and mark all the step-children as such.
112 If this variable is `empty', the \"children\" are printed with empty
113 subject fields.  (Or rather, they will be printed with a string
114 given by the `gnus-summary-same-subject' variable.)"
115   :group 'gnus-thread
116   :type '(choice (const :tag "off" nil)
117                  (const none)
118                  (const dummy)
119                  (const adopt)
120                  (const empty)))
121
122 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
123   "*A regexp to match subjects to be excluded from loose thread gathering.
124 As loose thread gathering is done on subjects only, that means that
125 there can be many false gatherings performed.  By rooting out certain
126 common subjects, gathering might become saner."
127   :group 'gnus-thread
128   :type 'regexp)
129
130 (defcustom gnus-summary-gather-subject-limit nil
131   "*Maximum length of subject comparisons when gathering loose threads.
132 Use nil to compare full subjects.  Setting this variable to a low
133 number will help gather threads that have been corrupted by
134 newsreaders chopping off subject lines, but it might also mean that
135 unrelated articles that have subject that happen to begin with the
136 same few characters will be incorrectly gathered.
137
138 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
139 comparing subjects."
140   :group 'gnus-thread
141   :type '(choice (const :tag "off" nil)
142                  (const fuzzy)
143                  (sexp :menu-tag "on" t)))
144
145 (defcustom gnus-simplify-subject-functions nil
146   "List of functions taking a string argument that simplify subjects.
147 The functions are applied recursively.
148
149 Useful functions to put in this list include: `gnus-simplify-subject-re',
150 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
151   :group 'gnus-thread
152   :type '(repeat function))
153
154 (defcustom gnus-simplify-ignored-prefixes nil
155   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
156   :group 'gnus-thread
157   :type '(choice (const :tag "off" nil)
158                  regexp))
159
160 (defcustom gnus-build-sparse-threads nil
161   "*If non-nil, fill in the gaps in threads.
162 If `some', only fill in the gaps that are needed to tie loose threads
163 together.  If `more', fill in all leaf nodes that Gnus can find.  If
164 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
165   :group 'gnus-thread
166   :type '(choice (const :tag "off" nil)
167                  (const some)
168                  (const more)
169                  (sexp :menu-tag "all" t)))
170
171 (defcustom gnus-summary-thread-gathering-function
172   'gnus-gather-threads-by-subject
173   "*Function used for gathering loose threads.
174 There are two pre-defined functions: `gnus-gather-threads-by-subject',
175 which only takes Subjects into consideration; and
176 `gnus-gather-threads-by-references', which compared the References
177 headers of the articles to find matches."
178   :group 'gnus-thread
179   :type '(radio (function-item gnus-gather-threads-by-subject)
180                 (function-item gnus-gather-threads-by-references)
181                 (function :tag "other")))
182
183 (defcustom gnus-summary-same-subject ""
184   "*String indicating that the current article has the same subject as the previous.
185 This variable will only be used if the value of
186 `gnus-summary-make-false-root' is `empty'."
187   :group 'gnus-summary-format
188   :type 'string)
189
190 (defcustom gnus-summary-goto-unread t
191   "*If t, many commands will go to the next unread article.
192 This applies to marking commands as well as other commands that
193 \"naturally\" select the next article, like, for instance, `SPC' at
194 the end of an article.
195
196 If nil, the marking commands do NOT go to the next unread article
197 (they go to the next article instead).  If `never', commands that
198 usually go to the next unread article, will go to the next article,
199 whether it is read or not."
200   :group 'gnus-summary-marks
201   :link '(custom-manual "(gnus)Setting Marks")
202   :type '(choice (const :tag "off" nil)
203                  (const never)
204                  (sexp :menu-tag "on" t)))
205
206 (defcustom gnus-summary-default-score 0
207   "*Default article score level.
208 All scores generated by the score files will be added to this score.
209 If this variable is nil, scoring will be disabled."
210   :group 'gnus-score-default
211   :type '(choice (const :tag "disable")
212                  integer))
213
214 (defcustom gnus-summary-zcore-fuzz 0
215   "*Fuzziness factor for the zcore in the summary buffer.
216 Articles with scores closer than this to `gnus-summary-default-score'
217 will not be marked."
218   :group 'gnus-summary-format
219   :type 'integer)
220
221 (defcustom gnus-simplify-subject-fuzzy-regexp nil
222   "*Strings to be removed when doing fuzzy matches.
223 This can either be a regular expression or list of regular expressions
224 that will be removed from subject strings if fuzzy subject
225 simplification is selected."
226   :group 'gnus-thread
227   :type '(repeat regexp))
228
229 (defcustom gnus-show-threads t
230   "*If non-nil, display threads in summary mode."
231   :group 'gnus-thread
232   :type 'boolean)
233
234 (defcustom gnus-thread-hide-subtree nil
235   "*If non-nil, hide all threads initially.
236 If threads are hidden, you have to run the command
237 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
238 to expose hidden threads."
239   :group 'gnus-thread
240   :type 'boolean)
241
242 (defcustom gnus-thread-hide-killed t
243   "*If non-nil, hide killed threads automatically."
244   :group 'gnus-thread
245   :type 'boolean)
246
247 (defcustom gnus-thread-ignore-subject t
248   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
249 If nil, articles that have different subjects from their parents will
250 start separate threads."
251   :group 'gnus-thread
252   :type 'boolean)
253
254 (defcustom gnus-thread-operation-ignore-subject t
255   "*If non-nil, subjects will be ignored when doing thread commands.
256 This affects commands like `gnus-summary-kill-thread' and
257 `gnus-summary-lower-thread'.
258
259 If this variable is nil, articles in the same thread with different
260 subjects will not be included in the operation in question.  If this
261 variable is `fuzzy', only articles that have subjects that are fuzzily
262 equal will be included."
263   :group 'gnus-thread
264   :type '(choice (const :tag "off" nil)
265                  (const fuzzy)
266                  (sexp :tag "on" t)))
267
268 (defcustom gnus-thread-indent-level 4
269   "*Number that says how much each sub-thread should be indented."
270   :group 'gnus-thread
271   :type 'integer)
272
273 (defcustom gnus-auto-extend-newsgroup t
274   "*If non-nil, extend newsgroup forward and backward when requested."
275   :group 'gnus-summary-choose
276   :type 'boolean)
277
278 (defcustom gnus-auto-select-first t
279   "*If nil, don't select the first unread article when entering a group.
280 If this variable is `best', select the highest-scored unread article
281 in the group.  If t, select the first unread article.
282
283 This variable can also be a function to place point on a likely
284 subject line.  Useful values include `gnus-summary-first-unread-subject',
285 `gnus-summary-first-unread-article' and
286 `gnus-summary-best-unread-article'.
287
288 If you want to prevent automatic selection of the first unread article
289 in some newsgroups, set the variable to nil in
290 `gnus-select-group-hook'."
291   :group 'gnus-group-select
292   :type '(choice (const :tag "none" nil)
293                  (const best)
294                  (sexp :menu-tag "first" t)
295                  (function-item gnus-summary-first-unread-subject)
296                  (function-item gnus-summary-first-unread-article)
297                  (function-item gnus-summary-best-unread-article)))
298
299 (defcustom gnus-dont-select-after-jump-to-other-group nil
300   "If non-nil, don't select the first unread article after entering the
301 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
302 it is depend on the value of `gnus-auto-select-first' whether to select
303 or not."
304   :group 'gnus-group-select
305   :type 'boolean)
306
307 (defcustom gnus-auto-select-next t
308   "*If non-nil, offer to go to the next group from the end of the previous.
309 If the value is t and the next newsgroup is empty, Gnus will exit
310 summary mode and go back to group mode.  If the value is neither nil
311 nor t, Gnus will select the following unread newsgroup.  In
312 particular, if the value is the symbol `quietly', the next unread
313 newsgroup will be selected without any confirmation, and if it is
314 `almost-quietly', the next group will be selected without any
315 confirmation if you are located on the last article in the group.
316 Finally, if this variable is `slightly-quietly', the `Z n' command
317 will go to the next group without confirmation."
318   :group 'gnus-summary-maneuvering
319   :type '(choice (const :tag "off" nil)
320                  (const quietly)
321                  (const almost-quietly)
322                  (const slightly-quietly)
323                  (sexp :menu-tag "on" t)))
324
325 (defcustom gnus-auto-select-same nil
326   "*If non-nil, select the next article with the same subject.
327 If there are no more articles with the same subject, go to
328 the first unread article."
329   :group 'gnus-summary-maneuvering
330   :type 'boolean)
331
332 (defcustom gnus-summary-check-current nil
333   "*If non-nil, consider the current article when moving.
334 The \"unread\" movement commands will stay on the same line if the
335 current article is unread."
336   :group 'gnus-summary-maneuvering
337   :type 'boolean)
338
339 (defcustom gnus-auto-center-summary t
340   "*If non-nil, always center the current summary buffer.
341 In particular, if `vertical' do only vertical recentering.  If non-nil
342 and non-`vertical', do both horizontal and vertical recentering."
343   :group 'gnus-summary-maneuvering
344   :type '(choice (const :tag "none" nil)
345                  (const vertical)
346                  (integer :tag "height")
347                  (sexp :menu-tag "both" t)))
348
349 (defcustom gnus-show-all-headers nil
350   "*If non-nil, don't hide any headers."
351   :group 'gnus-article-hiding
352   :group 'gnus-article-headers
353   :type 'boolean)
354
355 (defcustom gnus-summary-ignore-duplicates nil
356   "*If non-nil, ignore articles with identical Message-ID headers."
357   :group 'gnus-summary
358   :type 'boolean)
359
360 (defcustom gnus-single-article-buffer t
361   "*If non-nil, display all articles in the same buffer.
362 If nil, each group will get its own article buffer."
363   :group 'gnus-article-various
364   :type 'boolean)
365
366 (defcustom gnus-break-pages t
367   "*If non-nil, do page breaking on articles.
368 The page delimiter is specified by the `gnus-page-delimiter'
369 variable."
370   :group 'gnus-article-various
371   :type 'boolean)
372
373 (defcustom gnus-show-mime t
374   "*If non-nil, do mime processing of articles.
375 The articles will simply be fed to the function given by
376 `gnus-article-display-method-for-mime'."
377   :group 'gnus-article-mime
378   :type 'boolean)
379
380 (defcustom gnus-move-split-methods nil
381   "*Variable used to suggest where articles are to be moved to.
382 It uses the same syntax as the `gnus-split-methods' variable.
383 However, whereas `gnus-split-methods' specifies file names as targets,
384 this variable specifies group names."
385   :group 'gnus-summary-mail
386   :type '(repeat (choice (list :value (fun) function)
387                          (cons :value ("" "") regexp (repeat string))
388                          (sexp :value nil))))
389
390 (defcustom gnus-unread-mark ?  ;Whitespace
391   "*Mark used for unread articles."
392   :group 'gnus-summary-marks
393   :type 'character)
394
395 (defcustom gnus-ticked-mark ?!
396   "*Mark used for ticked articles."
397   :group 'gnus-summary-marks
398   :type 'character)
399
400 (defcustom gnus-dormant-mark ??
401   "*Mark used for dormant articles."
402   :group 'gnus-summary-marks
403   :type 'character)
404
405 (defcustom gnus-del-mark ?r
406   "*Mark used for del'd articles."
407   :group 'gnus-summary-marks
408   :type 'character)
409
410 (defcustom gnus-read-mark ?R
411   "*Mark used for read articles."
412   :group 'gnus-summary-marks
413   :type 'character)
414
415 (defcustom gnus-expirable-mark ?E
416   "*Mark used for expirable articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-killed-mark ?K
421   "*Mark used for killed articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-souped-mark ?F
426   "*Mark used for killed articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-kill-file-mark ?X
431   "*Mark used for articles killed by kill files."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-low-score-mark ?Y
436   "*Mark used for articles with a low score."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-catchup-mark ?C
441   "*Mark used for articles that are caught up."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-replied-mark ?A
446   "*Mark used for articles that have been replied to."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-cached-mark ?*
451   "*Mark used for articles that are in the cache."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-saved-mark ?S
456   "*Mark used for articles that have been saved to."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-ancient-mark ?O
461   "*Mark used for ancient articles."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-sparse-mark ?Q
466   "*Mark used for sparsely reffed articles."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-canceled-mark ?G
471   "*Mark used for canceled articles."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-duplicate-mark ?M
476   "*Mark used for duplicate articles."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-undownloaded-mark ?@
481   "*Mark used for articles that weren't downloaded."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-downloadable-mark ?%
486   "*Mark used for articles that are to be downloaded."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-unsendable-mark ?=
491   "*Mark used for articles that won't be sent."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-score-over-mark ?+
496   "*Score mark used for articles with high scores."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-score-below-mark ?-
501   "*Score mark used for articles with low scores."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-empty-thread-mark ?  ;Whitespace
506   "*There is no thread under the article."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-not-empty-thread-mark ?=
511   "*There is a thread under the article."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-view-pseudo-asynchronously nil
516   "*If non-nil, Gnus will view pseudo-articles asynchronously."
517   :group 'gnus-extract-view
518   :type 'boolean)
519
520 (defcustom gnus-auto-expirable-marks
521   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
522         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
523         gnus-souped-mark gnus-duplicate-mark)
524   "*The list of marks converted into expiration if a group is auto-expirable."
525   :version "21.1"
526   :group 'gnus-summary
527   :type '(repeat character))
528
529 (defcustom gnus-inhibit-user-auto-expire t
530   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
531   :version "21.1"
532   :group 'gnus-summary
533   :type 'boolean)
534
535 (defcustom gnus-view-pseudos nil
536   "*If `automatic', pseudo-articles will be viewed automatically.
537 If `not-confirm', pseudos will be viewed automatically, and the user
538 will not be asked to confirm the command."
539   :group 'gnus-extract-view
540   :type '(choice (const :tag "off" nil)
541                  (const automatic)
542                  (const not-confirm)))
543
544 (defcustom gnus-view-pseudos-separately t
545   "*If non-nil, one pseudo-article will be created for each file to be viewed.
546 If nil, all files that use the same viewing command will be given as a
547 list of parameters to that command."
548   :group 'gnus-extract-view
549   :type 'boolean)
550
551 (defcustom gnus-insert-pseudo-articles t
552   "*If non-nil, insert pseudo-articles when decoding articles."
553   :group 'gnus-extract-view
554   :type 'boolean)
555
556 (defcustom gnus-summary-dummy-line-format
557   "  %(:                          :%) %S\n"
558   "*The format specification for the dummy roots in the summary buffer.
559 It works along the same lines as a normal formatting string,
560 with some simple extensions.
561
562 %S  The subject"
563   :group 'gnus-threading
564   :type 'string)
565
566 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
567   "*The format specification for the summary mode line.
568 It works along the same lines as a normal formatting string,
569 with some simple extensions:
570
571 %G  Group name
572 %p  Unprefixed group name
573 %A  Current article number
574 %z  Current article score
575 %V  Gnus version
576 %U  Number of unread articles in the group
577 %e  Number of unselected articles in the group
578 %Z  A string with unread/unselected article counts
579 %g  Shortish group name
580 %S  Subject of the current article
581 %u  User-defined spec
582 %s  Current score file name
583 %d  Number of dormant articles
584 %r  Number of articles that have been marked as read in this session
585 %E  Number of articles expunged by the score files"
586   :group 'gnus-summary-format
587   :type 'string)
588
589 (defcustom gnus-list-identifiers nil
590   "Regexp that matches list identifiers to be removed from subject.
591 This can also be a list of regexps."
592   :version "21.1"
593   :group 'gnus-summary-format
594   :group 'gnus-article-hiding
595   :type '(choice (const :tag "none" nil)
596                  (regexp :value ".*")
597                  (repeat :value (".*") regexp)))
598
599 (defcustom gnus-summary-mark-below 0
600   "*Mark all articles with a score below this variable as read.
601 This variable is local to each summary buffer and usually set by the
602 score file."
603   :group 'gnus-score-default
604   :type 'integer)
605
606 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
607   "*List of functions used for sorting articles in the summary buffer.
608 This variable is only used when not using a threaded display."
609   :group 'gnus-summary-sort
610   :type '(repeat (choice (function-item gnus-article-sort-by-number)
611                          (function-item gnus-article-sort-by-author)
612                          (function-item gnus-article-sort-by-subject)
613                          (function-item gnus-article-sort-by-date)
614                          (function-item gnus-article-sort-by-score)
615                          (function :tag "other"))))
616
617 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
618   "*List of functions used for sorting threads in the summary buffer.
619 By default, threads are sorted by article number.
620
621 Each function takes two threads and return non-nil if the first thread
622 should be sorted before the other.  If you use more than one function,
623 the primary sort function should be the last.  You should probably
624 always include `gnus-thread-sort-by-number' in the list of sorting
625 functions -- preferably first.
626
627 Ready-made functions include `gnus-thread-sort-by-number',
628 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
629 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
630 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
631   :group 'gnus-summary-sort
632   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
633                          (function-item gnus-thread-sort-by-author)
634                          (function-item gnus-thread-sort-by-subject)
635                          (function-item gnus-thread-sort-by-date)
636                          (function-item gnus-thread-sort-by-score)
637                          (function-item gnus-thread-sort-by-total-score)
638                          (function :tag "other"))))
639
640 (defcustom gnus-thread-score-function '+
641   "*Function used for calculating the total score of a thread.
642
643 The function is called with the scores of the article and each
644 subthread and should then return the score of the thread.
645
646 Some functions you can use are `+', `max', or `min'."
647   :group 'gnus-summary-sort
648   :type 'function)
649
650 (defcustom gnus-summary-expunge-below nil
651   "All articles that have a score less than this variable will be expunged.
652 This variable is local to the summary buffers."
653   :group 'gnus-score-default
654   :type '(choice (const :tag "off" nil)
655                  integer))
656
657 (defcustom gnus-thread-expunge-below nil
658   "All threads that have a total score less than this variable will be expunged.
659 See `gnus-thread-score-function' for en explanation of what a
660 \"thread score\" is.
661
662 This variable is local to the summary buffers."
663   :group 'gnus-threading
664   :group 'gnus-score-default
665   :type '(choice (const :tag "off" nil)
666                  integer))
667
668 (defcustom gnus-summary-mode-hook nil
669   "*A hook for Gnus summary mode.
670 This hook is run before any variables are set in the summary buffer."
671   :options '(turn-on-gnus-mailing-list-mode)
672   :group 'gnus-summary-various
673   :type 'hook)
674
675 (defcustom gnus-summary-menu-hook nil
676   "*Hook run after the creation of the summary mode menu."
677   :group 'gnus-summary-visual
678   :type 'hook)
679
680 (defcustom gnus-summary-exit-hook nil
681   "*A hook called on exit from the summary buffer.
682 It will be called with point in the group buffer."
683   :group 'gnus-summary-exit
684   :type 'hook)
685
686 (defcustom gnus-summary-prepare-hook nil
687   "*A hook called after the summary buffer has been generated.
688 If you want to modify the summary buffer, you can use this hook."
689   :group 'gnus-summary-various
690   :type 'hook)
691
692 (defcustom gnus-summary-prepared-hook nil
693   "*A hook called as the last thing after the summary buffer has been generated."
694   :group 'gnus-summary-various
695   :type 'hook)
696
697 (defcustom gnus-summary-generate-hook nil
698   "*A hook run just before generating the summary buffer.
699 This hook is commonly used to customize threading variables and the
700 like."
701   :group 'gnus-summary-various
702   :type 'hook)
703
704 (defcustom gnus-select-group-hook nil
705   "*A hook called when a newsgroup is selected.
706
707 If you'd like to simplify subjects like the
708 `gnus-summary-next-same-subject' command does, you can use the
709 following hook:
710
711  (setq gnus-select-group-hook
712       (list
713         (lambda ()
714           (mapcar (lambda (header)
715                      (mail-header-set-subject
716                       header
717                       (gnus-simplify-subject
718                        (mail-header-subject header) 're-only)))
719                   gnus-newsgroup-headers))))"
720   :group 'gnus-group-select
721   :type 'hook)
722
723 (defcustom gnus-select-article-hook nil
724   "*A hook called when an article is selected."
725   :group 'gnus-summary-choose
726   :type 'hook)
727
728 (defcustom gnus-visual-mark-article-hook
729   (list 'gnus-highlight-selected-summary)
730   "*Hook run after selecting an article in the summary buffer.
731 It is meant to be used for highlighting the article in some way.  It
732 is not run if `gnus-visual' is nil."
733   :group 'gnus-summary-visual
734   :type 'hook)
735
736 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
737   "*A hook called before parsing the headers."
738   :group 'gnus-various
739   :type 'hook)
740
741 (defcustom gnus-exit-group-hook nil
742   "*A hook called when exiting summary mode.
743 This hook is not called from the non-updating exit commands like `Q'."
744   :group 'gnus-various
745   :type 'hook)
746
747 (defcustom gnus-summary-update-hook
748   (list 'gnus-summary-highlight-line)
749   "*A hook called when a summary line is changed.
750 The hook will not be called if `gnus-visual' is nil.
751
752 The default function `gnus-summary-highlight-line' will
753 highlight the line according to the `gnus-summary-highlight'
754 variable."
755   :group 'gnus-summary-visual
756   :type 'hook)
757
758 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
759   "*A hook called when an article is selected for the first time.
760 The hook is intended to mark an article as read (or unread)
761 automatically when it is selected."
762   :group 'gnus-summary-choose
763   :type 'hook)
764
765 (defcustom gnus-group-no-more-groups-hook nil
766   "*A hook run when returning to group mode having no more (unread) groups."
767   :group 'gnus-group-select
768   :type 'hook)
769
770 (defcustom gnus-ps-print-hook nil
771   "*A hook run before ps-printing something from Gnus."
772   :group 'gnus-summary
773   :type 'hook)
774
775 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
776   "Face used for highlighting the current article in the summary buffer."
777   :group 'gnus-summary-visual
778   :type 'face)
779
780 (defcustom gnus-summary-highlight
781   '(((= mark gnus-canceled-mark)
782      . gnus-summary-cancelled-face)
783     ((and (> score default)
784           (or (= mark gnus-dormant-mark)
785               (= mark gnus-ticked-mark)))
786      . gnus-summary-high-ticked-face)
787     ((and (< score default)
788           (or (= mark gnus-dormant-mark)
789               (= mark gnus-ticked-mark)))
790      . gnus-summary-low-ticked-face)
791     ((or (= mark gnus-dormant-mark)
792          (= mark gnus-ticked-mark))
793      . gnus-summary-normal-ticked-face)
794     ((and (> score default) (= mark gnus-ancient-mark))
795      . gnus-summary-high-ancient-face)
796     ((and (< score default) (= mark gnus-ancient-mark))
797      . gnus-summary-low-ancient-face)
798     ((= mark gnus-ancient-mark)
799      . gnus-summary-normal-ancient-face)
800     ((and (> score default) (= mark gnus-unread-mark))
801      . gnus-summary-high-unread-face)
802     ((and (< score default) (= mark gnus-unread-mark))
803      . gnus-summary-low-unread-face)
804     ((and (memq article gnus-newsgroup-incorporated)
805           (= mark gnus-unread-mark))
806      . gnus-summary-incorporated-face)
807     ((= mark gnus-unread-mark)
808      . gnus-summary-normal-unread-face)
809     ((and (> score default) (memq mark (list gnus-downloadable-mark
810                                              gnus-undownloaded-mark)))
811      . gnus-summary-high-unread-face)
812     ((and (< score default) (memq mark (list gnus-downloadable-mark
813                                              gnus-undownloaded-mark)))
814      . gnus-summary-low-unread-face)
815     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
816      . gnus-summary-normal-unread-face)
817     ((> score default)
818      . gnus-summary-high-read-face)
819     ((< score default)
820      . gnus-summary-low-read-face)
821     (t
822      . gnus-summary-normal-read-face))
823   "*Controls the highlighting of summary buffer lines.
824
825 A list of (FORM . FACE) pairs.  When deciding how a a particular
826 summary line should be displayed, each form is evaluated.  The content
827 of the face field after the first true form is used.  You can change
828 how those summary lines are displayed, by editing the face field.
829
830 You can use the following variables in the FORM field.
831
832 score:   The articles score
833 default: The default article score.
834 below:   The score below which articles are automatically marked as read.
835 mark:    The articles mark."
836   :group 'gnus-summary-visual
837   :type '(repeat (cons (sexp :tag "Form" nil)
838                        face)))
839
840 (defcustom gnus-alter-header-function nil
841   "Function called to allow alteration of article header structures.
842 The function is called with one parameter, the article header vector,
843 which it may alter in any way.")
844
845 (defvar gnus-decode-encoded-word-function
846   (mime-find-field-decoder 'From 'nov)
847   "Variable that says which function should be used to decode a string with encoded words.")
848
849 (defcustom gnus-extra-headers nil
850   "*Extra headers to parse."
851   :version "21.1"
852   :group 'gnus-summary
853   :type '(repeat symbol))
854
855 (defcustom gnus-ignored-from-addresses
856   (and user-mail-address (regexp-quote user-mail-address))
857   "*Regexp of From headers that may be suppressed in favor of To headers."
858   :version "21.1"
859   :group 'gnus-summary
860   :type 'regexp)
861
862 (defcustom gnus-group-charset-alist
863   '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" cn-big5)
864     ("^cn\\>\\|\\<chinese\\>" cn-gb-2312)
865     ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
866     ("^tnn\\>\\|^pin\\>\\|^sci.lang.japan" iso-2022-7bit)
867     ("^relcom\\>" koi8-r)
868     ("^fido7\\>" koi8-r)
869     ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
870     ("^israel\\>" iso-8859-1)
871     ("^han\\>" euc-kr)
872     ("^alt.chinese.text.big5\\>" chinese-big5)
873     ("^soc.culture.vietnamese\\>" vietnamese-viqr)
874     ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
875     (".*" iso-8859-1))
876   "Alist of regexps (to match group names) and default charsets to be used when reading."
877   :type '(repeat (list (regexp :tag "Group")
878                        (symbol :tag "Charset")))
879   :group 'gnus-charset)
880
881 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
882   "List of charsets that should be ignored.
883 When these charsets are used in the \"charset\" parameter, the
884 default charset will be used instead."
885   :version "21.1"
886   :type '(repeat symbol)
887   :group 'gnus-charset)
888
889 (defcustom gnus-group-ignored-charsets-alist
890   '(("alt\\.chinese\\.text" iso-8859-1))
891   "Alist of regexps (to match group names) and charsets that should be ignored.
892 When these charsets are used in the \"charset\" parameter, the
893 default charset will be used instead."
894   :type '(repeat (cons (regexp :tag "Group")
895                        (repeat symbol)))
896   :group 'gnus-charset)
897
898 (defcustom gnus-group-highlight-words-alist nil
899   "Alist of group regexps and highlight regexps.
900 This variable uses the same syntax as `gnus-emphasis-alist'."
901   :version "21.1"
902   :type '(repeat (cons (regexp :tag "Group")
903                        (repeat (list (regexp :tag "Highlight regexp")
904                                      (number :tag "Group for entire word" 0)
905                                      (number :tag "Group for displayed part" 0)
906                                      (symbol :tag "Face"
907                                              gnus-emphasis-highlight-words)))))
908   :group 'gnus-summary-visual)
909
910 (defcustom gnus-use-wheel nil
911   "Use Intelli-mouse on summary movement"
912   :type 'boolean
913   :group 'gnus-summary-maneuvering)
914
915 (defcustom gnus-wheel-scroll-amount '(5 . 1)
916   "Amount to scroll messages by spinning the mouse wheel.
917 This is actually a cons cell, where the first item is the amount to scroll
918 on a normal wheel event, and the second is the amount to scroll when the
919 wheel is moved with the shift key depressed."
920   :type '(cons (integer :tag "Shift") integer)
921   :group 'gnus-summary-maneuvering)
922
923 (defcustom gnus-wheel-edge-resistance 2
924   "How hard it should be to change the current article
925 by moving the mouse over the edge of the article window."
926   :type 'integer
927   :group 'gnus-summary-maneuvering)
928
929 (defcustom gnus-summary-show-article-charset-alist
930   nil
931   "Alist of number and charset.
932 The article will be shown with the charset corresponding to the
933 numbered argument.
934 For example: ((1 . cn-gb-2312) (2 . big5))."
935   :version "21.1"
936   :type '(repeat (cons (number :tag "Argument" 1)
937                        (symbol :tag "Charset")))
938   :group 'gnus-charset)
939
940 (defcustom gnus-preserve-marks t
941   "Whether marks are preserved when moving, copying and respooling messages."
942   :version "21.1"
943   :type 'boolean
944   :group 'gnus-summary-marks)
945
946 (defcustom gnus-alter-articles-to-read-function nil
947   "Function to be called to alter the list of articles to be selected."
948   :type 'function
949   :group 'gnus-summary)
950
951 (defcustom gnus-orphan-score nil
952   "*All orphans get this score added.  Set in the score file."
953   :group 'gnus-score-default
954   :type '(choice (const nil)
955                  integer))
956
957 (defcustom gnus-summary-save-parts-default-mime "image/.*"
958   "*A regexp to match MIME parts when saving multiple parts of a message
959 with gnus-summary-save-parts (X m). This regexp will be used by default
960 when prompting the user for which type of files to save."
961   :group 'gnus-summary
962   :type 'regexp)
963
964
965 (defcustom gnus-summary-save-parts-default-mime "image/.*"
966   "*A regexp to match MIME parts when saving multiple parts of a message
967 with gnus-summary-save-parts (X m). This regexp will be used by default
968 when prompting the user for which type of files to save."
969   :group 'gnus-summary
970   :type 'regexp)
971
972
973 ;;; Internal variables
974
975 (defvar gnus-article-mime-handles nil)
976 (defvar gnus-article-decoded-p nil)
977 (defvar gnus-article-charset nil)
978 (defvar gnus-article-ignored-charsets nil)
979 (defvar gnus-scores-exclude-files nil)
980 (defvar gnus-page-broken nil)
981 (defvar gnus-inhibit-mime-unbuttonizing nil)
982
983 (defvar gnus-original-article nil)
984 (defvar gnus-article-internal-prepare-hook nil)
985 (defvar gnus-newsgroup-process-stack nil)
986
987 (defvar gnus-thread-indent-array nil)
988 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
989 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
990   "Function called to sort the articles within a thread after it has been gathered together.")
991
992 (defvar gnus-summary-save-parts-type-history nil)
993 (defvar gnus-summary-save-parts-last-directory nil)
994
995 (defvar gnus-summary-save-parts-type-history nil)
996 (defvar gnus-summary-save-parts-last-directory nil)
997
998 ;; Avoid highlighting in kill files.
999 (defvar gnus-summary-inhibit-highlight nil)
1000 (defvar gnus-newsgroup-selected-overlay nil)
1001 (defvar gnus-inhibit-limiting nil)
1002 (defvar gnus-newsgroup-adaptive-score-file nil)
1003 (defvar gnus-current-score-file nil)
1004 (defvar gnus-current-move-group nil)
1005 (defvar gnus-current-copy-group nil)
1006 (defvar gnus-current-crosspost-group nil)
1007
1008 (defvar gnus-newsgroup-dependencies nil)
1009 (defvar gnus-newsgroup-adaptive nil)
1010 (defvar gnus-summary-display-article-function nil)
1011 (defvar gnus-summary-highlight-line-function nil
1012   "Function called after highlighting a summary line.")
1013
1014 (defvar gnus-summary-line-format-alist
1015   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1016     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1017     (?s gnus-tmp-subject-or-nil ?s)
1018     (?n gnus-tmp-name ?s)
1019     (?A (std11-address-string
1020          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1021     (?a (or (std11-full-name-string
1022              (car (mime-entity-read-field gnus-tmp-header 'From)))
1023             gnus-tmp-from) ?s)
1024     (?F gnus-tmp-from ?s)
1025     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1026     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1027     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1028     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1029     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1030     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1031     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1032     (?L gnus-tmp-lines ?d)
1033     (?I gnus-tmp-indentation ?s)
1034     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1035     (?R gnus-tmp-replied ?c)
1036     (?\[ gnus-tmp-opening-bracket ?c)
1037     (?\] gnus-tmp-closing-bracket ?c)
1038     (?\> (make-string gnus-tmp-level ? ) ?s)
1039     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1040     (?i gnus-tmp-score ?d)
1041     (?z gnus-tmp-score-char ?c)
1042     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1043     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1044     (?U gnus-tmp-unread ?c)
1045     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
1046     (?t (gnus-summary-number-of-articles-in-thread
1047          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1048         ?d)
1049     (?e (gnus-summary-number-of-articles-in-thread
1050          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1051         ?c)
1052     (?u gnus-tmp-user-defined ?s)
1053     (?P (gnus-pick-line-number) ?d))
1054   "An alist of format specifications that can appear in summary lines.
1055 These are paired with what variables they correspond with, along with
1056 the type of the variable (string, integer, character, etc).")
1057
1058 (defvar gnus-summary-dummy-line-format-alist
1059   `((?S gnus-tmp-subject ?s)
1060     (?N gnus-tmp-number ?d)
1061     (?u gnus-tmp-user-defined ?s)))
1062
1063 (defvar gnus-summary-mode-line-format-alist
1064   `((?G gnus-tmp-group-name ?s)
1065     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1066     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1067     (?A gnus-tmp-article-number ?d)
1068     (?Z gnus-tmp-unread-and-unselected ?s)
1069     (?V gnus-version ?s)
1070     (?U gnus-tmp-unread-and-unticked ?d)
1071     (?S gnus-tmp-subject ?s)
1072     (?e gnus-tmp-unselected ?d)
1073     (?u gnus-tmp-user-defined ?s)
1074     (?d (length gnus-newsgroup-dormant) ?d)
1075     (?t (length gnus-newsgroup-marked) ?d)
1076     (?r (length gnus-newsgroup-reads) ?d)
1077     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1078     (?E gnus-newsgroup-expunged-tally ?d)
1079     (?s (gnus-current-score-file-nondirectory) ?s)))
1080
1081 (defvar gnus-last-search-regexp nil
1082   "Default regexp for article search command.")
1083
1084 (defvar gnus-summary-search-article-matched-data nil
1085   "Last matched data of article search command.  It is the local variable
1086 in `gnus-article-buffer' which consists of the list of start position,
1087 end position and text.")
1088
1089 (defvar gnus-last-shell-command nil
1090   "Default shell command on article.")
1091
1092 (defvar gnus-newsgroup-begin nil)
1093 (defvar gnus-newsgroup-end nil)
1094 (defvar gnus-newsgroup-last-rmail nil)
1095 (defvar gnus-newsgroup-last-mail nil)
1096 (defvar gnus-newsgroup-last-folder nil)
1097 (defvar gnus-newsgroup-last-file nil)
1098 (defvar gnus-newsgroup-auto-expire nil)
1099 (defvar gnus-newsgroup-active nil)
1100
1101 (defvar gnus-newsgroup-data nil)
1102 (defvar gnus-newsgroup-data-reverse nil)
1103 (defvar gnus-newsgroup-limit nil)
1104 (defvar gnus-newsgroup-limits nil)
1105
1106 (defvar gnus-newsgroup-unreads nil
1107   "List of unread articles in the current newsgroup.")
1108
1109 (defvar gnus-newsgroup-unselected nil
1110   "List of unselected unread articles in the current newsgroup.")
1111
1112 (defvar gnus-newsgroup-reads nil
1113   "Alist of read articles and article marks in the current newsgroup.")
1114
1115 (defvar gnus-newsgroup-expunged-tally nil)
1116
1117 (defvar gnus-newsgroup-marked nil
1118   "List of ticked articles in the current newsgroup (a subset of unread art).")
1119
1120 (defvar gnus-newsgroup-killed nil
1121   "List of ranges of articles that have been through the scoring process.")
1122
1123 (defvar gnus-newsgroup-cached nil
1124   "List of articles that come from the article cache.")
1125
1126 (defvar gnus-newsgroup-saved nil
1127   "List of articles that have been saved.")
1128
1129 (defvar gnus-newsgroup-kill-headers nil)
1130
1131 (defvar gnus-newsgroup-replied nil
1132   "List of articles that have been replied to in the current newsgroup.")
1133
1134 (defvar gnus-newsgroup-expirable nil
1135   "List of articles in the current newsgroup that can be expired.")
1136
1137 (defvar gnus-newsgroup-processable nil
1138   "List of articles in the current newsgroup that can be processed.")
1139
1140 (defvar gnus-newsgroup-downloadable nil
1141   "List of articles in the current newsgroup that can be processed.")
1142
1143 (defvar gnus-newsgroup-undownloaded nil
1144   "List of articles in the current newsgroup that haven't been downloaded..")
1145
1146 (defvar gnus-newsgroup-unsendable nil
1147   "List of articles in the current newsgroup that won't be sent.")
1148
1149 (defvar gnus-newsgroup-bookmarks nil
1150   "List of articles in the current newsgroup that have bookmarks.")
1151
1152 (defvar gnus-newsgroup-dormant nil
1153   "List of dormant articles in the current newsgroup.")
1154
1155 (defvar gnus-newsgroup-scored nil
1156   "List of scored articles in the current newsgroup.")
1157
1158 (defvar gnus-newsgroup-incorporated nil
1159   "List of incorporated articles in the current newsgroup.")
1160
1161 (defvar gnus-newsgroup-headers nil
1162   "List of article headers in the current newsgroup.")
1163
1164 (defvar gnus-newsgroup-threads nil)
1165
1166 (defvar gnus-newsgroup-prepared nil
1167   "Whether the current group has been prepared properly.")
1168
1169 (defvar gnus-newsgroup-ancient nil
1170   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1171
1172 (defvar gnus-newsgroup-sparse nil)
1173
1174 (defvar gnus-current-article nil)
1175 (defvar gnus-article-current nil)
1176 (defvar gnus-current-headers nil)
1177 (defvar gnus-have-all-headers nil)
1178 (defvar gnus-last-article nil)
1179 (defvar gnus-newsgroup-history nil)
1180 (defvar gnus-newsgroup-charset nil)
1181 (defvar gnus-newsgroup-ephemeral-charset nil)
1182 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1183
1184 (defvar gnus-article-before-search nil)
1185
1186 (defconst gnus-summary-local-variables
1187   '(gnus-newsgroup-name
1188     gnus-newsgroup-begin gnus-newsgroup-end
1189     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1190     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1191     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1192     gnus-newsgroup-unselected gnus-newsgroup-marked
1193     gnus-newsgroup-reads gnus-newsgroup-saved
1194     gnus-newsgroup-replied gnus-newsgroup-expirable
1195     gnus-newsgroup-processable gnus-newsgroup-killed
1196     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1197     gnus-newsgroup-unsendable
1198     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1199     gnus-newsgroup-headers gnus-newsgroup-threads
1200     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1201     gnus-current-article gnus-current-headers gnus-have-all-headers
1202     gnus-last-article gnus-article-internal-prepare-hook
1203     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1204     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1205     gnus-thread-expunge-below
1206     gnus-score-alist gnus-current-score-file
1207     (gnus-summary-expunge-below . global)
1208     (gnus-summary-mark-below . global)
1209     (gnus-orphan-score . global)
1210     gnus-newsgroup-active gnus-scores-exclude-files
1211     gnus-newsgroup-history gnus-newsgroup-ancient
1212     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1213     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1214     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1215     (gnus-newsgroup-expunged-tally . 0)
1216     gnus-cache-removable-articles gnus-newsgroup-cached
1217     gnus-newsgroup-data gnus-newsgroup-data-reverse
1218     gnus-newsgroup-limit gnus-newsgroup-limits
1219     gnus-newsgroup-charset
1220     gnus-newsgroup-incorporated)
1221   "Variables that are buffer-local to the summary buffers.")
1222
1223 (defvar gnus-newsgroup-variables nil
1224   "Variables that have separate values in the newsgroups.")
1225
1226 ;; Byte-compiler warning.
1227 (eval-when-compile (defvar gnus-article-mode-map))
1228
1229 ;; Subject simplification.
1230
1231 (defun gnus-simplify-whitespace (str)
1232   "Remove excessive whitespace from STR."
1233   (let ((mystr str))
1234     ;; Multiple spaces.
1235     (while (string-match "[ \t][ \t]+" mystr)
1236       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1237                           " "
1238                           (substring mystr (match-end 0)))))
1239     ;; Leading spaces.
1240     (when (string-match "^[ \t]+" mystr)
1241       (setq mystr (substring mystr (match-end 0))))
1242     ;; Trailing spaces.
1243     (when (string-match "[ \t]+$" mystr)
1244       (setq mystr (substring mystr 0 (match-beginning 0))))
1245     mystr))
1246
1247 (defsubst gnus-simplify-subject-re (subject)
1248   "Remove \"Re:\" from subject lines."
1249   (if (string-match "^[Rr][Ee]: *" subject)
1250       (substring subject (match-end 0))
1251     subject))
1252
1253 (defun gnus-simplify-subject (subject &optional re-only)
1254   "Remove `Re:' and words in parentheses.
1255 If RE-ONLY is non-nil, strip leading `Re:'s only."
1256   (let ((case-fold-search t))           ;Ignore case.
1257     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1258     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1259       (setq subject (substring subject (match-end 0))))
1260     ;; Remove uninteresting prefixes.
1261     (when (and (not re-only)
1262                gnus-simplify-ignored-prefixes
1263                (string-match gnus-simplify-ignored-prefixes subject))
1264       (setq subject (substring subject (match-end 0))))
1265     ;; Remove words in parentheses from end.
1266     (unless re-only
1267       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1268         (setq subject (substring subject 0 (match-beginning 0)))))
1269     ;; Return subject string.
1270     subject))
1271
1272 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1273 ;; all whitespace.
1274 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1275   (goto-char (point-min))
1276   (while (re-search-forward regexp nil t)
1277     (replace-match (or newtext ""))))
1278
1279 (defun gnus-simplify-buffer-fuzzy ()
1280   "Simplify string in the buffer fuzzily.
1281 The string in the accessible portion of the current buffer is simplified.
1282 It is assumed to be a single-line subject.
1283 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1284 matter is removed.  Additional things can be deleted by setting
1285 `gnus-simplify-subject-fuzzy-regexp'."
1286   (let ((case-fold-search t)
1287         (modified-tick))
1288     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1289
1290     (while (not (eq modified-tick (buffer-modified-tick)))
1291       (setq modified-tick (buffer-modified-tick))
1292       (cond
1293        ((listp gnus-simplify-subject-fuzzy-regexp)
1294         (mapcar 'gnus-simplify-buffer-fuzzy-step
1295                 gnus-simplify-subject-fuzzy-regexp))
1296        (gnus-simplify-subject-fuzzy-regexp
1297         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1298       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1299       (gnus-simplify-buffer-fuzzy-step
1300        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1301       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1302
1303     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1304     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1305     (gnus-simplify-buffer-fuzzy-step " $")
1306     (gnus-simplify-buffer-fuzzy-step "^ +")))
1307
1308 (defun gnus-simplify-subject-fuzzy (subject)
1309   "Simplify a subject string fuzzily.
1310 See `gnus-simplify-buffer-fuzzy' for details."
1311   (save-excursion
1312     (gnus-set-work-buffer)
1313     (let ((case-fold-search t))
1314       ;; Remove uninteresting prefixes.
1315       (when (and gnus-simplify-ignored-prefixes
1316                  (string-match gnus-simplify-ignored-prefixes subject))
1317         (setq subject (substring subject (match-end 0))))
1318       (insert subject)
1319       (inline (gnus-simplify-buffer-fuzzy))
1320       (buffer-string))))
1321
1322 (defsubst gnus-simplify-subject-fully (subject)
1323   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1324   (cond
1325    (gnus-simplify-subject-functions
1326     (gnus-map-function gnus-simplify-subject-functions subject))
1327    ((null gnus-summary-gather-subject-limit)
1328     (gnus-simplify-subject-re subject))
1329    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1330     (gnus-simplify-subject-fuzzy subject))
1331    ((numberp gnus-summary-gather-subject-limit)
1332     (gnus-limit-string (gnus-simplify-subject-re subject)
1333                        gnus-summary-gather-subject-limit))
1334    (t
1335     subject)))
1336
1337 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1338   "Check whether two subjects are equal.
1339 If optional argument simple-first is t, first argument is already
1340 simplified."
1341   (cond
1342    ((null simple-first)
1343     (equal (gnus-simplify-subject-fully s1)
1344            (gnus-simplify-subject-fully s2)))
1345    (t
1346     (equal s1
1347            (gnus-simplify-subject-fully s2)))))
1348
1349 (defun gnus-summary-bubble-group ()
1350   "Increase the score of the current group.
1351 This is a handy function to add to `gnus-summary-exit-hook' to
1352 increase the score of each group you read."
1353   (gnus-group-add-score gnus-newsgroup-name))
1354
1355 \f
1356 ;;;
1357 ;;; Gnus summary mode
1358 ;;;
1359
1360 (put 'gnus-summary-mode 'mode-class 'special)
1361
1362 (when t
1363   ;; Non-orthogonal keys
1364
1365   (gnus-define-keys gnus-summary-mode-map
1366     " " gnus-summary-next-page
1367     "\177" gnus-summary-prev-page
1368     [delete] gnus-summary-prev-page
1369     [backspace] gnus-summary-prev-page
1370     "\r" gnus-summary-scroll-up
1371     "\M-\r" gnus-summary-scroll-down
1372     "n" gnus-summary-next-unread-article
1373     "p" gnus-summary-prev-unread-article
1374     "N" gnus-summary-next-article
1375     "P" gnus-summary-prev-article
1376     "\M-\C-n" gnus-summary-next-same-subject
1377     "\M-\C-p" gnus-summary-prev-same-subject
1378     "\M-n" gnus-summary-next-unread-subject
1379     "\M-p" gnus-summary-prev-unread-subject
1380     "." gnus-summary-first-unread-article
1381     "," gnus-summary-best-unread-article
1382     "\M-s" gnus-summary-search-article-forward
1383     "\M-r" gnus-summary-search-article-backward
1384     "<" gnus-summary-beginning-of-article
1385     ">" gnus-summary-end-of-article
1386     "j" gnus-summary-goto-article
1387     "^" gnus-summary-refer-parent-article
1388     "\M-^" gnus-summary-refer-article
1389     "u" gnus-summary-tick-article-forward
1390     "!" gnus-summary-tick-article-forward
1391     "U" gnus-summary-tick-article-backward
1392     "d" gnus-summary-mark-as-read-forward
1393     "D" gnus-summary-mark-as-read-backward
1394     "E" gnus-summary-mark-as-expirable
1395     "\M-u" gnus-summary-clear-mark-forward
1396     "\M-U" gnus-summary-clear-mark-backward
1397     "k" gnus-summary-kill-same-subject-and-select
1398     "\C-k" gnus-summary-kill-same-subject
1399     "\M-\C-k" gnus-summary-kill-thread
1400     "\M-\C-l" gnus-summary-lower-thread
1401     "e" gnus-summary-edit-article
1402     "#" gnus-summary-mark-as-processable
1403     "\M-#" gnus-summary-unmark-as-processable
1404     "\M-\C-t" gnus-summary-toggle-threads
1405     "\M-\C-s" gnus-summary-show-thread
1406     "\M-\C-h" gnus-summary-hide-thread
1407     "\M-\C-f" gnus-summary-next-thread
1408     "\M-\C-b" gnus-summary-prev-thread
1409     [(meta down)] gnus-summary-next-thread
1410     [(meta up)] gnus-summary-prev-thread
1411     "\M-\C-u" gnus-summary-up-thread
1412     "\M-\C-d" gnus-summary-down-thread
1413     "&" gnus-summary-execute-command
1414     "c" gnus-summary-catchup-and-exit
1415     "\C-w" gnus-summary-mark-region-as-read
1416     "\C-t" gnus-summary-toggle-truncation
1417     "?" gnus-summary-mark-as-dormant
1418     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1419     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1420     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1421     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1422     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1423     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1424     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1425     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1426     "=" gnus-summary-expand-window
1427     "\C-x\C-s" gnus-summary-reselect-current-group
1428     "\M-g" gnus-summary-rescan-group
1429     "w" gnus-summary-stop-page-breaking
1430     "\C-c\C-r" gnus-summary-caesar-message
1431     "\M-t" gnus-summary-toggle-mime
1432     "f" gnus-summary-followup
1433     "F" gnus-summary-followup-with-original
1434     "C" gnus-summary-cancel-article
1435     "r" gnus-summary-reply
1436     "R" gnus-summary-reply-with-original
1437     "\C-c\C-f" gnus-summary-mail-forward
1438     "o" gnus-summary-save-article
1439     "\C-o" gnus-summary-save-article-mail
1440     "|" gnus-summary-pipe-output
1441     "\M-k" gnus-summary-edit-local-kill
1442     "\M-K" gnus-summary-edit-global-kill
1443     ;; "V" gnus-version
1444     "\C-c\C-d" gnus-summary-describe-group
1445     "q" gnus-summary-exit
1446     "Q" gnus-summary-exit-no-update
1447     "\C-c\C-i" gnus-info-find-node
1448     gnus-mouse-2 gnus-mouse-pick-article
1449     "m" gnus-summary-mail-other-window
1450     "a" gnus-summary-post-news
1451     "x" gnus-summary-limit-to-unread
1452     "s" gnus-summary-isearch-article
1453     "t" gnus-article-toggle-headers
1454     "g" gnus-summary-show-article
1455     "l" gnus-summary-goto-last-article
1456     "v" gnus-summary-preview-mime-message
1457     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1458     "\C-d" gnus-summary-enter-digest-group
1459     "\M-\C-d" gnus-summary-read-document
1460     "\M-\C-e" gnus-summary-edit-parameters
1461     "\M-\C-a" gnus-summary-customize-parameters
1462     "\C-c\C-b" gnus-bug
1463     "*" gnus-cache-enter-article
1464     "\M-*" gnus-cache-remove-article
1465     "\M-&" gnus-summary-universal-argument
1466     "\C-l" gnus-recenter
1467     "I" gnus-summary-increase-score
1468     "L" gnus-summary-lower-score
1469     "\M-i" gnus-symbolic-argument
1470     "h" gnus-summary-select-article-buffer
1471
1472     "V" gnus-summary-score-map
1473     "X" gnus-uu-extract-map
1474     "S" gnus-summary-send-map)
1475
1476   ;; Sort of orthogonal keymap
1477   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1478     "t" gnus-summary-tick-article-forward
1479     "!" gnus-summary-tick-article-forward
1480     "d" gnus-summary-mark-as-read-forward
1481     "r" gnus-summary-mark-as-read-forward
1482     "c" gnus-summary-clear-mark-forward
1483     " " gnus-summary-clear-mark-forward
1484     "e" gnus-summary-mark-as-expirable
1485     "x" gnus-summary-mark-as-expirable
1486     "?" gnus-summary-mark-as-dormant
1487     "b" gnus-summary-set-bookmark
1488     "B" gnus-summary-remove-bookmark
1489     "#" gnus-summary-mark-as-processable
1490     "\M-#" gnus-summary-unmark-as-processable
1491     "S" gnus-summary-limit-include-expunged
1492     "C" gnus-summary-catchup
1493     "H" gnus-summary-catchup-to-here
1494     "\C-c" gnus-summary-catchup-all
1495     "k" gnus-summary-kill-same-subject-and-select
1496     "K" gnus-summary-kill-same-subject
1497     "P" gnus-uu-mark-map)
1498
1499   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1500     "c" gnus-summary-clear-above
1501     "u" gnus-summary-tick-above
1502     "m" gnus-summary-mark-above
1503     "k" gnus-summary-kill-below)
1504
1505   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1506     "/" gnus-summary-limit-to-subject
1507     "n" gnus-summary-limit-to-articles
1508     "w" gnus-summary-pop-limit
1509     "s" gnus-summary-limit-to-subject
1510     "a" gnus-summary-limit-to-author
1511     "u" gnus-summary-limit-to-unread
1512     "m" gnus-summary-limit-to-marks
1513     "M" gnus-summary-limit-exclude-marks
1514     "v" gnus-summary-limit-to-score
1515     "*" gnus-summary-limit-include-cached
1516     "D" gnus-summary-limit-include-dormant
1517     "T" gnus-summary-limit-include-thread
1518     "d" gnus-summary-limit-exclude-dormant
1519     "t" gnus-summary-limit-to-age
1520     "x" gnus-summary-limit-to-extra
1521     "E" gnus-summary-limit-include-expunged
1522     "c" gnus-summary-limit-exclude-childless-dormant
1523     "C" gnus-summary-limit-mark-excluded-as-read)
1524
1525   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1526     "n" gnus-summary-next-unread-article
1527     "p" gnus-summary-prev-unread-article
1528     "N" gnus-summary-next-article
1529     "P" gnus-summary-prev-article
1530     "\C-n" gnus-summary-next-same-subject
1531     "\C-p" gnus-summary-prev-same-subject
1532     "\M-n" gnus-summary-next-unread-subject
1533     "\M-p" gnus-summary-prev-unread-subject
1534     "f" gnus-summary-first-unread-article
1535     "b" gnus-summary-best-unread-article
1536     "j" gnus-summary-goto-article
1537     "g" gnus-summary-goto-subject
1538     "l" gnus-summary-goto-last-article
1539     "o" gnus-summary-pop-article)
1540
1541   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1542     "k" gnus-summary-kill-thread
1543     "l" gnus-summary-lower-thread
1544     "i" gnus-summary-raise-thread
1545     "T" gnus-summary-toggle-threads
1546     "t" gnus-summary-rethread-current
1547     "^" gnus-summary-reparent-thread
1548     "s" gnus-summary-show-thread
1549     "S" gnus-summary-show-all-threads
1550     "h" gnus-summary-hide-thread
1551     "H" gnus-summary-hide-all-threads
1552     "n" gnus-summary-next-thread
1553     "p" gnus-summary-prev-thread
1554     "u" gnus-summary-up-thread
1555     "o" gnus-summary-top-thread
1556     "d" gnus-summary-down-thread
1557     "#" gnus-uu-mark-thread
1558     "\M-#" gnus-uu-unmark-thread)
1559
1560   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1561     "g" gnus-summary-prepare
1562     "c" gnus-summary-insert-cached-articles)
1563
1564   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1565     "c" gnus-summary-catchup-and-exit
1566     "C" gnus-summary-catchup-all-and-exit
1567     "E" gnus-summary-exit-no-update
1568     "J" gnus-summary-jump-to-other-group
1569     "Q" gnus-summary-exit
1570     "Z" gnus-summary-exit
1571     "n" gnus-summary-catchup-and-goto-next-group
1572     "R" gnus-summary-reselect-current-group
1573     "G" gnus-summary-rescan-group
1574     "N" gnus-summary-next-group
1575     "s" gnus-summary-save-newsrc
1576     "P" gnus-summary-prev-group)
1577
1578   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1579     " " gnus-summary-next-page
1580     "n" gnus-summary-next-page
1581     "\177" gnus-summary-prev-page
1582     [delete] gnus-summary-prev-page
1583     "p" gnus-summary-prev-page
1584     "\r" gnus-summary-scroll-up
1585     "\M-\r" gnus-summary-scroll-down
1586     "<" gnus-summary-beginning-of-article
1587     ">" gnus-summary-end-of-article
1588     "b" gnus-summary-beginning-of-article
1589     "e" gnus-summary-end-of-article
1590     "^" gnus-summary-refer-parent-article
1591     "r" gnus-summary-refer-parent-article
1592     "D" gnus-summary-enter-digest-group
1593     "R" gnus-summary-refer-references
1594     "T" gnus-summary-refer-thread
1595     "g" gnus-summary-show-article
1596     "s" gnus-summary-isearch-article
1597     "P" gnus-summary-print-article
1598     "M" gnus-mailing-list-insinuate
1599     "t" gnus-article-babel)
1600
1601   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1602     "b" gnus-article-add-buttons
1603     "B" gnus-article-add-buttons-to-head
1604     "o" gnus-article-treat-overstrike
1605     "e" gnus-article-emphasize
1606     "w" gnus-article-fill-cited-article
1607     "Q" gnus-article-fill-long-lines
1608     "C" gnus-article-capitalize-sentences
1609     "c" gnus-article-remove-cr
1610     "Z" gnus-article-decode-HZ
1611     "f" gnus-article-display-x-face
1612     "l" gnus-summary-stop-page-breaking
1613     "r" gnus-summary-caesar-message
1614     "t" gnus-article-toggle-headers
1615     "v" gnus-summary-verbose-headers
1616     "m" gnus-summary-toggle-mime
1617     "H" gnus-article-strip-headers-in-body
1618     "p" gnus-article-verify-x-pgp-sig
1619     "d" gnus-article-treat-dumbquotes
1620     "s" gnus-smiley-display)
1621
1622   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1623     "a" gnus-article-hide
1624     "h" gnus-article-toggle-headers
1625     "b" gnus-article-hide-boring-headers
1626     "s" gnus-article-hide-signature
1627     "c" gnus-article-hide-citation
1628     "C" gnus-article-hide-citation-in-followups
1629     "l" gnus-article-hide-list-identifiers
1630     "p" gnus-article-hide-pgp
1631     "B" gnus-article-strip-banner
1632     "P" gnus-article-hide-pem
1633     "\C-c" gnus-article-hide-citation-maybe)
1634
1635   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1636     "a" gnus-article-highlight
1637     "h" gnus-article-highlight-headers
1638     "c" gnus-article-highlight-citation
1639     "s" gnus-article-highlight-signature)
1640
1641   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1642     "z" gnus-article-date-ut
1643     "u" gnus-article-date-ut
1644     "l" gnus-article-date-local
1645     "e" gnus-article-date-lapsed
1646     "o" gnus-article-date-original
1647     "i" gnus-article-date-iso8601
1648     "s" gnus-article-date-user)
1649
1650   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1651     "t" gnus-article-remove-trailing-blank-lines
1652     "l" gnus-article-strip-leading-blank-lines
1653     "m" gnus-article-strip-multiple-blank-lines
1654     "a" gnus-article-strip-blank-lines
1655     "A" gnus-article-strip-all-blank-lines
1656     "s" gnus-article-strip-leading-space
1657     "e" gnus-article-strip-trailing-space)
1658
1659   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1660     "v" gnus-version
1661     "f" gnus-summary-fetch-faq
1662     "d" gnus-summary-describe-group
1663     "h" gnus-summary-describe-briefly
1664     "i" gnus-info-find-node)
1665
1666   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1667     "e" gnus-summary-expire-articles
1668     "\M-\C-e" gnus-summary-expire-articles-now
1669     "\177" gnus-summary-delete-article
1670     [delete] gnus-summary-delete-article
1671     [backspace] gnus-summary-delete-article
1672     "m" gnus-summary-move-article
1673     "r" gnus-summary-respool-article
1674     "w" gnus-summary-edit-article
1675     "c" gnus-summary-copy-article
1676     "B" gnus-summary-crosspost-article
1677     "q" gnus-summary-respool-query
1678     "t" gnus-summary-respool-trace
1679     "i" gnus-summary-import-article
1680     "p" gnus-summary-article-posted-p)
1681
1682   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1683     "o" gnus-summary-save-article
1684     "m" gnus-summary-save-article-mail
1685     "F" gnus-summary-write-article-file
1686     "r" gnus-summary-save-article-rmail
1687     "f" gnus-summary-save-article-file
1688     "b" gnus-summary-save-article-body-file
1689     "h" gnus-summary-save-article-folder
1690     "v" gnus-summary-save-article-vm
1691     "p" gnus-summary-pipe-output
1692     "s" gnus-soup-add-article)
1693
1694   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1695     "b" gnus-summary-display-buttonized
1696     "m" gnus-summary-repair-multipart
1697     "v" gnus-article-view-part
1698     "o" gnus-article-save-part
1699     "c" gnus-article-copy-part
1700     "C" gnus-article-view-part-as-charset
1701     "e" gnus-article-externalize-part
1702     "E" gnus-article-encrypt-body
1703     "i" gnus-article-inline-part
1704     "|" gnus-article-pipe-part))
1705
1706 (defun gnus-summary-make-menu-bar ()
1707   (gnus-turn-off-edit-menu 'summary)
1708
1709   (unless (boundp 'gnus-summary-misc-menu)
1710
1711     (easy-menu-define
1712      gnus-summary-kill-menu gnus-summary-mode-map ""
1713      (cons
1714       "Score"
1715       (nconc
1716        (list
1717         ["Enter score..." gnus-summary-score-entry t]
1718         ["Customize" gnus-score-customize t])
1719        (gnus-make-score-map 'increase)
1720        (gnus-make-score-map 'lower)
1721        '(("Mark"
1722           ["Kill below" gnus-summary-kill-below t]
1723           ["Mark above" gnus-summary-mark-above t]
1724           ["Tick above" gnus-summary-tick-above t]
1725           ["Clear above" gnus-summary-clear-above t])
1726          ["Current score" gnus-summary-current-score t]
1727          ["Set score" gnus-summary-set-score t]
1728          ["Switch current score file..." gnus-score-change-score-file t]
1729          ["Set mark below..." gnus-score-set-mark-below t]
1730          ["Set expunge below..." gnus-score-set-expunge-below t]
1731          ["Edit current score file" gnus-score-edit-current-scores t]
1732          ["Edit score file" gnus-score-edit-file t]
1733          ["Trace score" gnus-score-find-trace t]
1734          ["Find words" gnus-score-find-favourite-words t]
1735          ["Rescore buffer" gnus-summary-rescore t]
1736          ["Increase score..." gnus-summary-increase-score t]
1737          ["Lower score..." gnus-summary-lower-score t]))))
1738
1739     ;; Define both the Article menu in the summary buffer and the equivalent
1740     ;; Commands menu in the article buffer here for consistency.
1741     (let ((innards
1742            `(("Hide"
1743               ["All" gnus-article-hide t]
1744               ["Headers" gnus-article-toggle-headers t]
1745               ["Signature" gnus-article-hide-signature t]
1746               ["Citation" gnus-article-hide-citation t]
1747               ["List identifiers" gnus-article-hide-list-identifiers t]
1748               ["PGP" gnus-article-hide-pgp t]
1749               ["Banner" gnus-article-strip-banner t]
1750               ["Boring headers" gnus-article-hide-boring-headers t])
1751              ("Highlight"
1752               ["All" gnus-article-highlight t]
1753               ["Headers" gnus-article-highlight-headers t]
1754               ["Signature" gnus-article-highlight-signature t]
1755               ["Citation" gnus-article-highlight-citation t])
1756              ("Date"
1757               ["Local" gnus-article-date-local t]
1758               ["ISO8601" gnus-article-date-iso8601 t]
1759               ["UT" gnus-article-date-ut t]
1760               ["Original" gnus-article-date-original t]
1761               ["Lapsed" gnus-article-date-lapsed t]
1762               ["User-defined" gnus-article-date-user t])
1763              ("Washing"
1764               ("Remove Blanks"
1765                ["Leading" gnus-article-strip-leading-blank-lines t]
1766                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1767                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1768                ["All of the above" gnus-article-strip-blank-lines t]
1769                ["All" gnus-article-strip-all-blank-lines t]
1770                ["Leading space" gnus-article-strip-leading-space t]
1771                ["Trailing space" gnus-article-strip-trailing-space t])
1772               ["Overstrike" gnus-article-treat-overstrike t]
1773               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1774               ["Emphasis" gnus-article-emphasize t]
1775               ["Word wrap" gnus-article-fill-cited-article t]
1776               ["Fill long lines" gnus-article-fill-long-lines t]
1777               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1778               ["CR" gnus-article-remove-cr t]
1779               ["Show X-Face" gnus-article-display-x-face t]
1780               ["Rot 13" gnus-summary-caesar-message
1781                ,@(if (featurep 'xemacs) nil
1782                    '(:help "\"Caesar rotate\" article by 13"))]
1783               ["Unix pipe" gnus-summary-pipe-message t]
1784               ["Add buttons" gnus-article-add-buttons t]
1785               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1786               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1787               ["Toggle MIME" gnus-summary-toggle-mime t]
1788               ["Verbose header" gnus-summary-verbose-headers t]
1789               ["Toggle header" gnus-summary-toggle-header t]
1790               ["Toggle smileys" gnus-smiley-display t]
1791               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1792               ["HZ" gnus-article-decode-HZ t])
1793              ("Output"
1794               ["Save in default format" gnus-summary-save-article
1795                ,@(if (featurep 'xemacs) nil
1796                    '(:help "Save article using default method"))]
1797               ["Save in file" gnus-summary-save-article-file
1798                ,@(if (featurep 'xemacs) nil
1799                    '(:help "Save article in file"))]
1800               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1801               ["Save in MH folder" gnus-summary-save-article-folder t]
1802               ["Save in VM folder" gnus-summary-save-article-vm t]
1803               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1804               ["Save body in file" gnus-summary-save-article-body-file t]
1805               ["Pipe through a filter" gnus-summary-pipe-output t]
1806               ["Add to SOUP packet" gnus-soup-add-article t]
1807               ["Print" gnus-summary-print-article t])
1808              ("Backend"
1809               ["Respool article..." gnus-summary-respool-article t]
1810               ["Move article..." gnus-summary-move-article
1811                (gnus-check-backend-function
1812                 'request-move-article gnus-newsgroup-name)]
1813               ["Copy article..." gnus-summary-copy-article t]
1814               ["Crosspost article..." gnus-summary-crosspost-article
1815                (gnus-check-backend-function
1816                 'request-replace-article gnus-newsgroup-name)]
1817               ["Import file..." gnus-summary-import-article t]
1818               ["Check if posted" gnus-summary-article-posted-p t]
1819               ["Edit article" gnus-summary-edit-article
1820                (not (gnus-group-read-only-p))]
1821               ["Delete article" gnus-summary-delete-article
1822                (gnus-check-backend-function
1823                 'request-expire-articles gnus-newsgroup-name)]
1824               ["Query respool" gnus-summary-respool-query t]
1825               ["Trace respool" gnus-summary-respool-trace t]
1826               ["Delete expirable articles" gnus-summary-expire-articles-now
1827                (gnus-check-backend-function
1828                 'request-expire-articles gnus-newsgroup-name)])
1829              ("Extract"
1830               ["Uudecode" gnus-uu-decode-uu
1831                ,@(if (featurep 'xemacs) nil
1832                    '(:help "Decode uuencoded article(s)"))]
1833               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1834               ["Unshar" gnus-uu-decode-unshar t]
1835               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1836               ["Save" gnus-uu-decode-save t]
1837               ["Binhex" gnus-uu-decode-binhex t]
1838               ["Postscript" gnus-uu-decode-postscript t])
1839              ("Cache"
1840               ["Enter article" gnus-cache-enter-article t]
1841               ["Remove article" gnus-cache-remove-article t])
1842              ["Translate" gnus-article-babel t]
1843              ["Select article buffer" gnus-summary-select-article-buffer t]
1844              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1845              ["Isearch article..." gnus-summary-isearch-article t]
1846              ["Beginning of the article" gnus-summary-beginning-of-article t]
1847              ["End of the article" gnus-summary-end-of-article t]
1848              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1849              ["Fetch referenced articles" gnus-summary-refer-references t]
1850              ["Fetch current thread" gnus-summary-refer-thread t]
1851              ["Fetch article with id..." gnus-summary-refer-article t]
1852              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1853              ["Redisplay" gnus-summary-show-article t])))
1854       (easy-menu-define
1855        gnus-summary-article-menu gnus-summary-mode-map ""
1856        (cons "Article" innards))
1857
1858       (easy-menu-define
1859        gnus-article-commands-menu gnus-article-mode-map ""
1860        (cons "Commands" innards)))
1861
1862     (easy-menu-define
1863      gnus-summary-thread-menu gnus-summary-mode-map ""
1864      '("Threads"
1865        ["Toggle threading" gnus-summary-toggle-threads t]
1866        ["Hide threads" gnus-summary-hide-all-threads t]
1867        ["Show threads" gnus-summary-show-all-threads t]
1868        ["Hide thread" gnus-summary-hide-thread t]
1869        ["Show thread" gnus-summary-show-thread t]
1870        ["Go to next thread" gnus-summary-next-thread t]
1871        ["Go to previous thread" gnus-summary-prev-thread t]
1872        ["Go down thread" gnus-summary-down-thread t]
1873        ["Go up thread" gnus-summary-up-thread t]
1874        ["Top of thread" gnus-summary-top-thread t]
1875        ["Mark thread as read" gnus-summary-kill-thread t]
1876        ["Lower thread score" gnus-summary-lower-thread t]
1877        ["Raise thread score" gnus-summary-raise-thread t]
1878        ["Rethread current" gnus-summary-rethread-current t]))
1879
1880     (easy-menu-define
1881      gnus-summary-post-menu gnus-summary-mode-map ""
1882      `("Post"
1883        ["Post an article" gnus-summary-post-news
1884         ,@(if (featurep 'xemacs) nil
1885             '(:help "Post an article"))]
1886        ["Followup" gnus-summary-followup
1887         ,@(if (featurep 'xemacs) nil
1888             '(:help "Post followup to this article"))]
1889        ["Followup and yank" gnus-summary-followup-with-original
1890         ,@(if (featurep 'xemacs) nil
1891             '(:help "Post followup to this article, quoting its contents"))]
1892        ["Supersede article" gnus-summary-supersede-article t]
1893        ["Cancel article" gnus-summary-cancel-article
1894         ,@(if (featurep 'xemacs) nil
1895             '(:help "Cancel an article you posted"))]
1896        ["Reply" gnus-summary-reply t]
1897        ["Reply and yank" gnus-summary-reply-with-original t]
1898        ["Wide reply" gnus-summary-wide-reply t]
1899        ["Wide reply and yank" gnus-summary-wide-reply-with-original
1900         ,@(if (featurep 'xemacs) nil
1901             '(:help "Mail a reply, quoting this article"))]
1902        ["Mail forward" gnus-summary-mail-forward t]
1903        ["Post forward" gnus-summary-post-forward t]
1904        ["Digest and mail" gnus-uu-digest-mail-forward t]
1905        ["Digest and post" gnus-uu-digest-post-forward t]
1906        ["Resend message" gnus-summary-resend-message t]
1907        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1908        ["Send a mail" gnus-summary-mail-other-window t]
1909        ["Uuencode and post" gnus-uu-post-news
1910         ,@(if (featurep 'xemacs) nil
1911             '(:help "Post a uuencoded article"))]
1912        ["Followup via news" gnus-summary-followup-to-mail t]
1913        ["Followup via news and yank"
1914         gnus-summary-followup-to-mail-with-original t]
1915        ;;("Draft"
1916        ;;["Send" gnus-summary-send-draft t]
1917        ;;["Send bounced" gnus-resend-bounced-mail t])
1918        ))
1919
1920     (easy-menu-define
1921      gnus-summary-misc-menu gnus-summary-mode-map ""
1922      `("Misc"
1923        ("Mark Read"
1924         ["Mark as read" gnus-summary-mark-as-read-forward t]
1925         ["Mark same subject and select"
1926          gnus-summary-kill-same-subject-and-select t]
1927         ["Mark same subject" gnus-summary-kill-same-subject t]
1928         ["Catchup" gnus-summary-catchup
1929          ,@(if (featurep 'xemacs) nil
1930              '(:help "Mark unread articles in this group as read"))]
1931         ["Catchup all" gnus-summary-catchup-all t]
1932         ["Catchup to here" gnus-summary-catchup-to-here t]
1933         ["Catchup region" gnus-summary-mark-region-as-read t]
1934         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1935        ("Mark Various"
1936         ["Tick" gnus-summary-tick-article-forward t]
1937         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1938         ["Remove marks" gnus-summary-clear-mark-forward t]
1939         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1940         ["Set bookmark" gnus-summary-set-bookmark t]
1941         ["Remove bookmark" gnus-summary-remove-bookmark t])
1942        ("Mark Limit"
1943         ["Marks..." gnus-summary-limit-to-marks t]
1944         ["Subject..." gnus-summary-limit-to-subject t]
1945         ["Author..." gnus-summary-limit-to-author t]
1946         ["Age..." gnus-summary-limit-to-age t]
1947         ["Extra..." gnus-summary-limit-to-extra t]
1948         ["Score" gnus-summary-limit-to-score t]
1949         ["Unread" gnus-summary-limit-to-unread t]
1950         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1951         ["Articles" gnus-summary-limit-to-articles t]
1952         ["Pop limit" gnus-summary-pop-limit t]
1953         ["Show dormant" gnus-summary-limit-include-dormant t]
1954         ["Hide childless dormant"
1955          gnus-summary-limit-exclude-childless-dormant t]
1956         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1957         ["Hide marked" gnus-summary-limit-exclude-marks t]
1958         ["Show expunged" gnus-summary-show-all-expunged t])
1959        ("Process Mark"
1960         ["Set mark" gnus-summary-mark-as-processable t]
1961         ["Remove mark" gnus-summary-unmark-as-processable t]
1962         ["Remove all marks" gnus-summary-unmark-all-processable t]
1963         ["Mark above" gnus-uu-mark-over t]
1964         ["Mark series" gnus-uu-mark-series t]
1965         ["Mark region" gnus-uu-mark-region t]
1966         ["Unmark region" gnus-uu-unmark-region t]
1967         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1968         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1969         ["Mark all" gnus-uu-mark-all t]
1970         ["Mark buffer" gnus-uu-mark-buffer t]
1971         ["Mark sparse" gnus-uu-mark-sparse t]
1972         ["Mark thread" gnus-uu-mark-thread t]
1973         ["Unmark thread" gnus-uu-unmark-thread t]
1974         ("Process Mark Sets"
1975          ["Kill" gnus-summary-kill-process-mark t]
1976          ["Yank" gnus-summary-yank-process-mark
1977           gnus-newsgroup-process-stack]
1978          ["Save" gnus-summary-save-process-mark t]))
1979        ("Scroll article"
1980         ["Page forward" gnus-summary-next-page
1981          ,@(if (featurep 'xemacs) nil
1982              '(:help "Show next page of article"))]
1983         ["Page backward" gnus-summary-prev-page
1984          ,@(if (featurep 'xemacs) nil
1985              '(:help "Show previous page of article"))]
1986         ["Line forward" gnus-summary-scroll-up t])
1987        ("Move"
1988         ["Next unread article" gnus-summary-next-unread-article t]
1989         ["Previous unread article" gnus-summary-prev-unread-article t]
1990         ["Next article" gnus-summary-next-article t]
1991         ["Previous article" gnus-summary-prev-article t]
1992         ["Next unread subject" gnus-summary-next-unread-subject t]
1993         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1994         ["Next article same subject" gnus-summary-next-same-subject t]
1995         ["Previous article same subject" gnus-summary-prev-same-subject t]
1996         ["First unread article" gnus-summary-first-unread-article t]
1997         ["Best unread article" gnus-summary-best-unread-article t]
1998         ["Go to subject number..." gnus-summary-goto-subject t]
1999         ["Go to article number..." gnus-summary-goto-article t]
2000         ["Go to the last article" gnus-summary-goto-last-article t]
2001         ["Pop article off history" gnus-summary-pop-article t])
2002        ("Sort"
2003         ["Sort by number" gnus-summary-sort-by-number t]
2004         ["Sort by author" gnus-summary-sort-by-author t]
2005         ["Sort by subject" gnus-summary-sort-by-subject t]
2006         ["Sort by date" gnus-summary-sort-by-date t]
2007         ["Sort by score" gnus-summary-sort-by-score t]
2008         ["Sort by lines" gnus-summary-sort-by-lines t]
2009         ["Sort by characters" gnus-summary-sort-by-chars t])
2010        ("Help"
2011         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2012         ["Describe group" gnus-summary-describe-group t]
2013         ["Read manual" gnus-info-find-node t])
2014        ("Modes"
2015         ["Pick and read" gnus-pick-mode t]
2016         ["Binary" gnus-binary-mode t])
2017        ("Regeneration"
2018         ["Regenerate" gnus-summary-prepare t]
2019         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2020         ["Toggle threading" gnus-summary-toggle-threads t])
2021        ["Filter articles..." gnus-summary-execute-command t]
2022        ["Run command on subjects..." gnus-summary-universal-argument t]
2023        ["Search articles forward..." gnus-summary-search-article-forward t]
2024        ["Search articles backward..." gnus-summary-search-article-backward t]
2025        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2026        ["Expand window" gnus-summary-expand-window t]
2027        ["Expire expirable articles" gnus-summary-expire-articles
2028         (gnus-check-backend-function
2029          'request-expire-articles gnus-newsgroup-name)]
2030        ["Edit local kill file" gnus-summary-edit-local-kill t]
2031        ["Edit main kill file" gnus-summary-edit-global-kill t]
2032        ["Edit group parameters" gnus-summary-edit-parameters t]
2033        ["Customize group parameters" gnus-summary-customize-parameters t]
2034        ["Send a bug report" gnus-bug t]
2035        ("Exit"
2036         ["Catchup and exit" gnus-summary-catchup-and-exit
2037          ,@(if (featurep 'xemacs) nil
2038              '(:help "Mark unread articles in this group as read, then exit"))]
2039         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2040         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2041         ["Exit group" gnus-summary-exit
2042          ,@(if (featurep 'xemacs) nil
2043              '(:help "Exit current group, return to group selection mode"))]
2044         ["Exit group without updating" gnus-summary-exit-no-update t]
2045         ["Exit and goto next group" gnus-summary-next-group t]
2046         ["Exit and goto prev group" gnus-summary-prev-group t]
2047         ["Reselect group" gnus-summary-reselect-current-group t]
2048         ["Rescan group" gnus-summary-rescan-group t]
2049         ["Update dribble" gnus-summary-save-newsrc t])))
2050
2051     (gnus-run-hooks 'gnus-summary-menu-hook)))
2052
2053 (defvar gnus-summary-tool-bar-map nil)
2054
2055 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2056 (defun gnus-summary-make-tool-bar ()
2057   (if (and (fboundp 'tool-bar-add-item-from-menu)
2058            (default-value 'tool-bar-mode)
2059            (not gnus-summary-tool-bar-map))
2060       (setq gnus-summary-tool-bar-map
2061             (let ((tool-bar-map (make-sparse-keymap)))
2062               (tool-bar-add-item-from-menu
2063                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2064               (tool-bar-add-item-from-menu
2065                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2066               (tool-bar-add-item-from-menu
2067                'gnus-summary-post-news "post" gnus-summary-mode-map)
2068               (tool-bar-add-item-from-menu
2069                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2070               (tool-bar-add-item-from-menu
2071                'gnus-summary-followup "followup" gnus-summary-mode-map)
2072               (tool-bar-add-item-from-menu
2073                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2074               (tool-bar-add-item-from-menu
2075                'gnus-summary-reply "reply" gnus-summary-mode-map)
2076               (tool-bar-add-item-from-menu
2077                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2078               (tool-bar-add-item-from-menu
2079                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2080               (tool-bar-add-item-from-menu
2081                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2082               (tool-bar-add-item-from-menu
2083                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2084               (tool-bar-add-item-from-menu
2085                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2086               (tool-bar-add-item-from-menu
2087                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2088               (tool-bar-add-item-from-menu
2089                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2090               (tool-bar-add-item-from-menu
2091                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2092               tool-bar-map)))
2093   (if gnus-summary-tool-bar-map
2094       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2095
2096 (defun gnus-score-set-default (var value)
2097   "A version of set that updates the GNU Emacs menu-bar."
2098   (set var value)
2099   ;; It is the message that forces the active status to be updated.
2100   (message ""))
2101
2102 (defun gnus-make-score-map (type)
2103   "Make a summary score map of type TYPE."
2104   (if t
2105       nil
2106     (let ((headers '(("author" "from" string)
2107                      ("subject" "subject" string)
2108                      ("article body" "body" string)
2109                      ("article head" "head" string)
2110                      ("xref" "xref" string)
2111                      ("extra header" "extra" string)
2112                      ("lines" "lines" number)
2113                      ("followups to author" "followup" string)))
2114           (types '((number ("less than" <)
2115                            ("greater than" >)
2116                            ("equal" =))
2117                    (string ("substring" s)
2118                            ("exact string" e)
2119                            ("fuzzy string" f)
2120                            ("regexp" r))))
2121           (perms '(("temporary" (current-time-string))
2122                    ("permanent" nil)
2123                    ("immediate" now)))
2124           header)
2125       (list
2126        (apply
2127         'nconc
2128         (list
2129          (if (eq type 'lower)
2130              "Lower score"
2131            "Increase score"))
2132         (let (outh)
2133           (while headers
2134             (setq header (car headers))
2135             (setq outh
2136                   (cons
2137                    (apply
2138                     'nconc
2139                     (list (car header))
2140                     (let ((ts (cdr (assoc (nth 2 header) types)))
2141                           outt)
2142                       (while ts
2143                         (setq outt
2144                               (cons
2145                                (apply
2146                                 'nconc
2147                                 (list (caar ts))
2148                                 (let ((ps perms)
2149                                       outp)
2150                                   (while ps
2151                                     (setq outp
2152                                           (cons
2153                                            (vector
2154                                             (caar ps)
2155                                             (list
2156                                              'gnus-summary-score-entry
2157                                              (nth 1 header)
2158                                              (if (or (string= (nth 1 header)
2159                                                               "head")
2160                                                      (string= (nth 1 header)
2161                                                               "body"))
2162                                                  ""
2163                                                (list 'gnus-summary-header
2164                                                      (nth 1 header)))
2165                                              (list 'quote (nth 1 (car ts)))
2166                                              (list 'gnus-score-delta-default
2167                                                    nil)
2168                                              (nth 1 (car ps))
2169                                              t)
2170                                             t)
2171                                            outp))
2172                                     (setq ps (cdr ps)))
2173                                   (list (nreverse outp))))
2174                                outt))
2175                         (setq ts (cdr ts)))
2176                       (list (nreverse outt))))
2177                    outh))
2178             (setq headers (cdr headers)))
2179           (list (nreverse outh))))))))
2180
2181 \f
2182
2183 (defun gnus-summary-mode (&optional group)
2184   "Major mode for reading articles.
2185
2186 All normal editing commands are switched off.
2187 \\<gnus-summary-mode-map>
2188 Each line in this buffer represents one article.  To read an
2189 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2190 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2191 respectively.
2192
2193 You can also post articles and send mail from this buffer.  To
2194 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2195 of an article, type `\\[gnus-summary-reply]'.
2196
2197 There are approx. one gazillion commands you can execute in this
2198 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2199
2200 The following commands are available:
2201
2202 \\{gnus-summary-mode-map}"
2203   (interactive)
2204   (kill-all-local-variables)
2205   (when (gnus-visual-p 'summary-menu 'menu)
2206     (gnus-summary-make-menu-bar)
2207     (gnus-summary-make-tool-bar))
2208   (gnus-summary-make-local-variables)
2209   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2210     (gnus-summary-make-local-variables))
2211   (gnus-make-thread-indent-array)
2212   (gnus-simplify-mode-line)
2213   (setq major-mode 'gnus-summary-mode)
2214   (setq mode-name "Summary")
2215   (make-local-variable 'minor-mode-alist)
2216   (use-local-map gnus-summary-mode-map)
2217   (buffer-disable-undo)
2218   (setq buffer-read-only t)             ;Disable modification
2219   (setq truncate-lines t)
2220   (setq selective-display t)
2221   (setq selective-display-ellipses t)   ;Display `...'
2222   (gnus-summary-set-display-table)
2223   (gnus-set-default-directory)
2224   (setq gnus-newsgroup-name group)
2225   (unless (gnus-news-group-p group)
2226     (setq gnus-newsgroup-incorporated
2227           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2228   (make-local-variable 'gnus-summary-line-format)
2229   (make-local-variable 'gnus-summary-line-format-spec)
2230   (make-local-variable 'gnus-summary-dummy-line-format)
2231   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2232   (make-local-variable 'gnus-summary-mark-positions)
2233   (make-local-hook 'pre-command-hook)
2234   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2235   (gnus-run-hooks 'gnus-summary-mode-hook)
2236   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2237   (gnus-update-summary-mark-positions))
2238
2239 (defun gnus-summary-make-local-variables ()
2240   "Make all the local summary buffer variables."
2241   (let (global)
2242     (dolist (local gnus-summary-local-variables)
2243       (if (consp local)
2244           (progn
2245             (if (eq (cdr local) 'global)
2246                 ;; Copy the global value of the variable.
2247                 (setq global (symbol-value (car local)))
2248               ;; Use the value from the list.
2249               (setq global (eval (cdr local))))
2250             (set (make-local-variable (car local)) global))
2251         ;; Simple nil-valued local variable.
2252         (set (make-local-variable local) nil)))))
2253
2254 (defun gnus-summary-clear-local-variables ()
2255   (let ((locals gnus-summary-local-variables))
2256     (while locals
2257       (if (consp (car locals))
2258           (and (vectorp (caar locals))
2259                (set (caar locals) nil))
2260         (and (vectorp (car locals))
2261              (set (car locals) nil)))
2262       (setq locals (cdr locals)))))
2263
2264 ;; Summary data functions.
2265
2266 (defmacro gnus-data-number (data)
2267   `(car ,data))
2268
2269 (defmacro gnus-data-set-number (data number)
2270   `(setcar ,data ,number))
2271
2272 (defmacro gnus-data-mark (data)
2273   `(nth 1 ,data))
2274
2275 (defmacro gnus-data-set-mark (data mark)
2276   `(setcar (nthcdr 1 ,data) ,mark))
2277
2278 (defmacro gnus-data-pos (data)
2279   `(nth 2 ,data))
2280
2281 (defmacro gnus-data-set-pos (data pos)
2282   `(setcar (nthcdr 2 ,data) ,pos))
2283
2284 (defmacro gnus-data-header (data)
2285   `(nth 3 ,data))
2286
2287 (defmacro gnus-data-set-header (data header)
2288   `(setcar (nthcdr 3 ,data) ,header))
2289
2290 (defmacro gnus-data-level (data)
2291   `(nth 4 ,data))
2292
2293 (defmacro gnus-data-unread-p (data)
2294   `(= (nth 1 ,data) gnus-unread-mark))
2295
2296 (defmacro gnus-data-read-p (data)
2297   `(/= (nth 1 ,data) gnus-unread-mark))
2298
2299 (defmacro gnus-data-pseudo-p (data)
2300   `(consp (nth 3 ,data)))
2301
2302 (defmacro gnus-data-find (number)
2303   `(assq ,number gnus-newsgroup-data))
2304
2305 (defmacro gnus-data-find-list (number &optional data)
2306   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2307      (memq (assq ,number bdata)
2308            bdata)))
2309
2310 (defmacro gnus-data-make (number mark pos header level)
2311   `(list ,number ,mark ,pos ,header ,level))
2312
2313 (defun gnus-data-enter (after-article number mark pos header level offset)
2314   (let ((data (gnus-data-find-list after-article)))
2315     (unless data
2316       (error "No such article: %d" after-article))
2317     (setcdr data (cons (gnus-data-make number mark pos header level)
2318                        (cdr data)))
2319     (setq gnus-newsgroup-data-reverse nil)
2320     (gnus-data-update-list (cddr data) offset)))
2321
2322 (defun gnus-data-enter-list (after-article list &optional offset)
2323   (when list
2324     (let ((data (and after-article (gnus-data-find-list after-article)))
2325           (ilist list))
2326       (if (not (or data
2327                    after-article))
2328           (let ((odata gnus-newsgroup-data))
2329             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2330             (when offset
2331               (gnus-data-update-list odata offset)))
2332         ;; Find the last element in the list to be spliced into the main
2333         ;; list.
2334         (while (cdr list)
2335           (setq list (cdr list)))
2336         (if (not data)
2337             (progn
2338               (setcdr list gnus-newsgroup-data)
2339               (setq gnus-newsgroup-data ilist)
2340               (when offset
2341                 (gnus-data-update-list (cdr list) offset)))
2342           (setcdr list (cdr data))
2343           (setcdr data ilist)
2344           (when offset
2345             (gnus-data-update-list (cdr list) offset))))
2346       (setq gnus-newsgroup-data-reverse nil))))
2347
2348 (defun gnus-data-remove (article &optional offset)
2349   (let ((data gnus-newsgroup-data))
2350     (if (= (gnus-data-number (car data)) article)
2351         (progn
2352           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2353                 gnus-newsgroup-data-reverse nil)
2354           (when offset
2355             (gnus-data-update-list gnus-newsgroup-data offset)))
2356       (while (cdr data)
2357         (when (= (gnus-data-number (cadr data)) article)
2358           (setcdr data (cddr data))
2359           (when offset
2360             (gnus-data-update-list (cdr data) offset))
2361           (setq data nil
2362                 gnus-newsgroup-data-reverse nil))
2363         (setq data (cdr data))))))
2364
2365 (defmacro gnus-data-list (backward)
2366   `(if ,backward
2367        (or gnus-newsgroup-data-reverse
2368            (setq gnus-newsgroup-data-reverse
2369                  (reverse gnus-newsgroup-data)))
2370      gnus-newsgroup-data))
2371
2372 (defun gnus-data-update-list (data offset)
2373   "Add OFFSET to the POS of all data entries in DATA."
2374   (setq gnus-newsgroup-data-reverse nil)
2375   (while data
2376     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2377     (setq data (cdr data))))
2378
2379 (defun gnus-summary-article-pseudo-p (article)
2380   "Say whether this article is a pseudo article or not."
2381   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2382
2383 (defmacro gnus-summary-article-sparse-p (article)
2384   "Say whether this article is a sparse article or not."
2385   `(memq ,article gnus-newsgroup-sparse))
2386
2387 (defmacro gnus-summary-article-ancient-p (article)
2388   "Say whether this article is a sparse article or not."
2389   `(memq ,article gnus-newsgroup-ancient))
2390
2391 (defun gnus-article-parent-p (number)
2392   "Say whether this article is a parent or not."
2393   (let ((data (gnus-data-find-list number)))
2394     (and (cdr data)                     ; There has to be an article after...
2395          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2396             (gnus-data-level (nth 1 data))))))
2397
2398 (defun gnus-article-children (number)
2399   "Return a list of all children to NUMBER."
2400   (let* ((data (gnus-data-find-list number))
2401          (level (gnus-data-level (car data)))
2402          children)
2403     (setq data (cdr data))
2404     (while (and data
2405                 (= (gnus-data-level (car data)) (1+ level)))
2406       (push (gnus-data-number (car data)) children)
2407       (setq data (cdr data)))
2408     children))
2409
2410 (defmacro gnus-summary-skip-intangible ()
2411   "If the current article is intangible, then jump to a different article."
2412   '(let ((to (get-text-property (point) 'gnus-intangible)))
2413      (and to (gnus-summary-goto-subject to))))
2414
2415 (defmacro gnus-summary-article-intangible-p ()
2416   "Say whether this article is intangible or not."
2417   '(get-text-property (point) 'gnus-intangible))
2418
2419 (defun gnus-article-read-p (article)
2420   "Say whether ARTICLE is read or not."
2421   (not (or (memq article gnus-newsgroup-marked)
2422            (memq article gnus-newsgroup-unreads)
2423            (memq article gnus-newsgroup-unselected)
2424            (memq article gnus-newsgroup-dormant))))
2425
2426 ;; Some summary mode macros.
2427
2428 (defmacro gnus-summary-article-number ()
2429   "The article number of the article on the current line.
2430 If there isn's an article number here, then we return the current
2431 article number."
2432   '(progn
2433      (gnus-summary-skip-intangible)
2434      (or (get-text-property (point) 'gnus-number)
2435          (gnus-summary-last-subject))))
2436
2437 (defmacro gnus-summary-article-header (&optional number)
2438   "Return the header of article NUMBER."
2439   `(gnus-data-header (gnus-data-find
2440                       ,(or number '(gnus-summary-article-number)))))
2441
2442 (defmacro gnus-summary-thread-level (&optional number)
2443   "Return the level of thread that starts with article NUMBER."
2444   `(if (and (eq gnus-summary-make-false-root 'dummy)
2445             (get-text-property (point) 'gnus-intangible))
2446        0
2447      (gnus-data-level (gnus-data-find
2448                        ,(or number '(gnus-summary-article-number))))))
2449
2450 (defmacro gnus-summary-article-mark (&optional number)
2451   "Return the mark of article NUMBER."
2452   `(gnus-data-mark (gnus-data-find
2453                     ,(or number '(gnus-summary-article-number)))))
2454
2455 (defmacro gnus-summary-article-pos (&optional number)
2456   "Return the position of the line of article NUMBER."
2457   `(gnus-data-pos (gnus-data-find
2458                    ,(or number '(gnus-summary-article-number)))))
2459
2460 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2461 (defmacro gnus-summary-article-subject (&optional number)
2462   "Return current subject string or nil if nothing."
2463   `(let ((headers
2464           ,(if number
2465                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2466              '(gnus-data-header (assq (gnus-summary-article-number)
2467                                       gnus-newsgroup-data)))))
2468      (and headers
2469           (vectorp headers)
2470           (mail-header-subject headers))))
2471
2472 (defmacro gnus-summary-article-score (&optional number)
2473   "Return current article score."
2474   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2475                   gnus-newsgroup-scored))
2476        gnus-summary-default-score 0))
2477
2478 (defun gnus-summary-article-children (&optional number)
2479   "Return a list of article numbers that are children of article NUMBER."
2480   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2481          (level (gnus-data-level (car data)))
2482          l children)
2483     (while (and (setq data (cdr data))
2484                 (> (setq l (gnus-data-level (car data))) level))
2485       (and (= (1+ level) l)
2486            (push (gnus-data-number (car data))
2487                  children)))
2488     (nreverse children)))
2489
2490 (defun gnus-summary-article-parent (&optional number)
2491   "Return the article number of the parent of article NUMBER."
2492   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2493                                     (gnus-data-list t)))
2494          (level (gnus-data-level (car data))))
2495     (if (zerop level)
2496         ()                              ; This is a root.
2497       ;; We search until we find an article with a level less than
2498       ;; this one.  That function has to be the parent.
2499       (while (and (setq data (cdr data))
2500                   (not (< (gnus-data-level (car data)) level))))
2501       (and data (gnus-data-number (car data))))))
2502
2503 (defun gnus-unread-mark-p (mark)
2504   "Say whether MARK is the unread mark."
2505   (= mark gnus-unread-mark))
2506
2507 (defun gnus-read-mark-p (mark)
2508   "Say whether MARK is one of the marks that mark as read.
2509 This is all marks except unread, ticked, dormant, and expirable."
2510   (not (or (= mark gnus-unread-mark)
2511            (= mark gnus-ticked-mark)
2512            (= mark gnus-dormant-mark)
2513            (= mark gnus-expirable-mark))))
2514
2515 (defmacro gnus-article-mark (number)
2516   "Return the MARK of article NUMBER.
2517 This macro should only be used when computing the mark the \"first\"
2518 time; i.e., when generating the summary lines.  After that,
2519 `gnus-summary-article-mark' should be used to examine the
2520 marks of articles."
2521   `(cond
2522     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2523     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2524     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2525     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2526     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2527     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2528     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2529     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2530            gnus-ancient-mark))))
2531
2532 ;; Saving hidden threads.
2533
2534 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2535 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2536
2537 (defmacro gnus-save-hidden-threads (&rest forms)
2538   "Save hidden threads, eval FORMS, and restore the hidden threads."
2539   (let ((config (make-symbol "config")))
2540     `(let ((,config (gnus-hidden-threads-configuration)))
2541        (unwind-protect
2542            (save-excursion
2543              ,@forms)
2544          (gnus-restore-hidden-threads-configuration ,config)))))
2545
2546 (defun gnus-data-compute-positions ()
2547   "Compute the positions of all articles."
2548   (setq gnus-newsgroup-data-reverse nil)
2549   (let ((data gnus-newsgroup-data))
2550     (save-excursion
2551       (gnus-save-hidden-threads
2552         (gnus-summary-show-all-threads)
2553         (goto-char (point-min))
2554         (while data
2555           (while (get-text-property (point) 'gnus-intangible)
2556             (forward-line 1))
2557           (gnus-data-set-pos (car data) (+ (point) 3))
2558           (setq data (cdr data))
2559           (forward-line 1))))))
2560
2561 (defun gnus-hidden-threads-configuration ()
2562   "Return the current hidden threads configuration."
2563   (save-excursion
2564     (let (config)
2565       (goto-char (point-min))
2566       (while (search-forward "\r" nil t)
2567         (push (1- (point)) config))
2568       config)))
2569
2570 (defun gnus-restore-hidden-threads-configuration (config)
2571   "Restore hidden threads configuration from CONFIG."
2572   (save-excursion
2573     (let (point buffer-read-only)
2574       (while (setq point (pop config))
2575         (when (and (< point (point-max))
2576                    (goto-char point)
2577                    (eq (char-after) ?\n))
2578           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2579
2580 ;; Various summary mode internalish functions.
2581
2582 (defun gnus-mouse-pick-article (e)
2583   (interactive "e")
2584   (mouse-set-point e)
2585   (gnus-summary-next-page nil t))
2586
2587 (defun gnus-summary-set-display-table ()
2588   "Change the display table.
2589 Odd characters have a tendency to mess
2590 up nicely formatted displays - we make all possible glyphs
2591 display only a single character."
2592
2593   ;; We start from the standard display table, if any.
2594   (let ((table (or (copy-sequence standard-display-table)
2595                    (make-display-table)))
2596         (i 32))
2597     ;; Nix out all the control chars...
2598     (while (>= (setq i (1- i)) 0)
2599       (aset table i [??]))
2600     ;; ... but not newline and cr, of course.  (cr is necessary for the
2601     ;; selective display).
2602     (aset table ?\n nil)
2603     (aset table ?\r nil)
2604     ;; We keep TAB as well.
2605     (aset table ?\t nil)
2606     ;; We nix out any glyphs over 126 that are not set already.
2607     (let ((i 256))
2608       (while (>= (setq i (1- i)) 127)
2609         ;; Only modify if the entry is nil.
2610         (unless (aref table i)
2611           (aset table i [??]))))
2612     (setq buffer-display-table table)))
2613
2614 (defun gnus-summary-setup-buffer (group)
2615   "Initialize summary buffer."
2616   (let ((buffer (concat "*Summary " group "*")))
2617     (if (get-buffer buffer)
2618         (progn
2619           (set-buffer buffer)
2620           (setq gnus-summary-buffer (current-buffer))
2621           (not gnus-newsgroup-prepared))
2622       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2623       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2624       (gnus-summary-mode group)
2625       (when gnus-carpal
2626         (gnus-carpal-setup-buffer 'summary))
2627       (unless gnus-single-article-buffer
2628         (make-local-variable 'gnus-article-buffer)
2629         (make-local-variable 'gnus-article-current)
2630         (make-local-variable 'gnus-original-article-buffer))
2631       (setq gnus-newsgroup-name group)
2632       t)))
2633
2634 (defun gnus-set-global-variables ()
2635   "Set the global equivalents of the buffer-local variables.
2636 They are set to the latest values they had.  These reflect the summary
2637 buffer that was in action when the last article was fetched."
2638   (when (eq major-mode 'gnus-summary-mode)
2639     (setq gnus-summary-buffer (current-buffer))
2640     (let ((name gnus-newsgroup-name)
2641           (marked gnus-newsgroup-marked)
2642           (unread gnus-newsgroup-unreads)
2643           (headers gnus-current-headers)
2644           (data gnus-newsgroup-data)
2645           (summary gnus-summary-buffer)
2646           (article-buffer gnus-article-buffer)
2647           (original gnus-original-article-buffer)
2648           (gac gnus-article-current)
2649           (reffed gnus-reffed-article-number)
2650           (score-file gnus-current-score-file)
2651           (default-charset gnus-newsgroup-charset)
2652           vlist)
2653       (let ((locals gnus-newsgroup-variables))
2654         (while locals
2655           (if (consp (car locals))
2656               (push (eval (caar locals)) vlist)
2657             (push (eval (car locals)) vlist))
2658           (setq locals (cdr locals)))
2659         (setq vlist (nreverse vlist)))
2660       (save-excursion
2661         (set-buffer gnus-group-buffer)
2662         (setq gnus-newsgroup-name name
2663               gnus-newsgroup-marked marked
2664               gnus-newsgroup-unreads unread
2665               gnus-current-headers headers
2666               gnus-newsgroup-data data
2667               gnus-article-current gac
2668               gnus-summary-buffer summary
2669               gnus-article-buffer article-buffer
2670               gnus-original-article-buffer original
2671               gnus-reffed-article-number reffed
2672               gnus-current-score-file score-file
2673               gnus-newsgroup-charset default-charset)
2674         (let ((locals gnus-newsgroup-variables))
2675           (while locals
2676             (if (consp (car locals))
2677                 (set (caar locals) (pop vlist))
2678               (set (car locals) (pop vlist)))
2679             (setq locals (cdr locals))))
2680         ;; The article buffer also has local variables.
2681         (when (gnus-buffer-live-p gnus-article-buffer)
2682           (set-buffer gnus-article-buffer)
2683           (setq gnus-summary-buffer summary))))))
2684
2685 (defun gnus-summary-article-unread-p (article)
2686   "Say whether ARTICLE is unread or not."
2687   (memq article gnus-newsgroup-unreads))
2688
2689 (defun gnus-summary-first-article-p (&optional article)
2690   "Return whether ARTICLE is the first article in the buffer."
2691   (if (not (setq article (or article (gnus-summary-article-number))))
2692       nil
2693     (eq article (caar gnus-newsgroup-data))))
2694
2695 (defun gnus-summary-last-article-p (&optional article)
2696   "Return whether ARTICLE is the last article in the buffer."
2697   (if (not (setq article (or article (gnus-summary-article-number))))
2698       ;; All non-existent numbers are the last article.  :-)
2699       t
2700     (not (cdr (gnus-data-find-list article)))))
2701
2702 (defun gnus-make-thread-indent-array ()
2703   (let ((n 200))
2704     (unless (and gnus-thread-indent-array
2705                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2706       (setq gnus-thread-indent-array (make-vector 201 "")
2707             gnus-thread-indent-array-level gnus-thread-indent-level)
2708       (while (>= n 0)
2709         (aset gnus-thread-indent-array n
2710               (make-string (* n gnus-thread-indent-level) ? ))
2711         (setq n (1- n))))))
2712
2713 (defun gnus-update-summary-mark-positions ()
2714   "Compute where the summary marks are to go."
2715   (save-excursion
2716     (when (gnus-buffer-exists-p gnus-summary-buffer)
2717       (set-buffer gnus-summary-buffer))
2718     (let ((gnus-replied-mark 129)
2719           (gnus-score-below-mark 130)
2720           (gnus-score-over-mark 130)
2721           (gnus-download-mark 131)
2722           (spec gnus-summary-line-format-spec)
2723           gnus-visual pos)
2724       (save-excursion
2725         (gnus-set-work-buffer)
2726         (let ((gnus-summary-line-format-spec spec)
2727               (gnus-newsgroup-downloadable '((0 . t))))
2728           (gnus-summary-insert-line
2729            (make-full-mail-header 0 "" "nobody" "" "" "" 0 0 "" nil)
2730            0 nil 128 t nil "" nil 1)
2731           (goto-char (point-min))
2732           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2733                                              (- (point) 2)))))
2734           (goto-char (point-min))
2735           (push (cons 'replied (and (search-forward "\201" nil t)
2736                                     (- (point) 2)))
2737                 pos)
2738           (goto-char (point-min))
2739           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2740                 pos)
2741           (goto-char (point-min))
2742           (push (cons 'download
2743                       (and (search-forward "\203" nil t) (- (point) 2)))
2744                 pos)))
2745       (setq gnus-summary-mark-positions pos))))
2746
2747 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2748   "Insert a dummy root in the summary buffer."
2749   (beginning-of-line)
2750   (gnus-add-text-properties
2751    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2752    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2753
2754 (defun gnus-summary-from-or-to-or-newsgroups (header)
2755   (let ((to (cdr (assq 'To (mail-header-extra header))))
2756         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2757         (default-mime-charset (with-current-buffer gnus-summary-buffer
2758                                 default-mime-charset)))
2759     (cond
2760      ((and to
2761            gnus-ignored-from-addresses
2762            (string-match gnus-ignored-from-addresses
2763                          (mail-header-from header)))
2764       (concat "-> "
2765               (or (car (funcall gnus-extract-address-components
2766                                 (funcall
2767                                  gnus-decode-encoded-word-function to)))
2768                   (funcall gnus-decode-encoded-word-function to))))
2769      ((and newsgroups
2770            gnus-ignored-from-addresses
2771            (string-match gnus-ignored-from-addresses
2772                          (mail-header-from header)))
2773       (concat "=> " newsgroups))
2774      (t
2775       (or (car (funcall gnus-extract-address-components
2776                         (mail-header-from header)))
2777           (mail-header-from header))))))
2778
2779 (defun gnus-summary-insert-line (gnus-tmp-header
2780                                  gnus-tmp-level gnus-tmp-current
2781                                  gnus-tmp-unread gnus-tmp-replied
2782                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2783                                  &optional gnus-tmp-dummy gnus-tmp-score
2784                                  gnus-tmp-process)
2785   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2786          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2787          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2788          (gnus-tmp-score-char
2789           (if (or (null gnus-summary-default-score)
2790                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2791                       gnus-summary-zcore-fuzz))
2792               ?  ;Whitespace
2793             (if (< gnus-tmp-score gnus-summary-default-score)
2794                 gnus-score-below-mark gnus-score-over-mark)))
2795          (gnus-tmp-replied
2796           (cond (gnus-tmp-process gnus-process-mark)
2797                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2798                  gnus-cached-mark)
2799                 (gnus-tmp-replied gnus-replied-mark)
2800                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2801                  gnus-saved-mark)
2802                 (t gnus-unread-mark)))
2803          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2804          (gnus-tmp-name
2805           (cond
2806            ((string-match "<[^>]+> *$" gnus-tmp-from)
2807             (let ((beg (match-beginning 0)))
2808               (or (and (string-match "^\".+\"" gnus-tmp-from)
2809                        (substring gnus-tmp-from 1 (1- (match-end 0))))
2810                   (substring gnus-tmp-from 0 beg))))
2811            ((string-match "(.+)" gnus-tmp-from)
2812             (substring gnus-tmp-from
2813                        (1+ (match-beginning 0)) (1- (match-end 0))))
2814            (t gnus-tmp-from)))
2815          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2816          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2817          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2818          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2819          (buffer-read-only nil))
2820     (when (string= gnus-tmp-name "")
2821       (setq gnus-tmp-name gnus-tmp-from))
2822     (unless (numberp gnus-tmp-lines)
2823       (setq gnus-tmp-lines 0))
2824     (gnus-put-text-property-excluding-characters-with-faces
2825      (point)
2826      (progn (eval gnus-summary-line-format-spec) (point))
2827      'gnus-number gnus-tmp-number)
2828     (when (gnus-visual-p 'summary-highlight 'highlight)
2829       (forward-line -1)
2830       (gnus-run-hooks 'gnus-summary-update-hook)
2831       (forward-line 1))))
2832
2833 (defun gnus-summary-update-line (&optional dont-update)
2834   "Update summary line after change."
2835   (when (and gnus-summary-default-score
2836              (not gnus-summary-inhibit-highlight))
2837     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2838            (article (gnus-summary-article-number))
2839            (score (gnus-summary-article-score article)))
2840       (unless dont-update
2841         (if (and gnus-summary-mark-below
2842                  (< (gnus-summary-article-score)
2843                     gnus-summary-mark-below))
2844             ;; This article has a low score, so we mark it as read.
2845             (when (memq article gnus-newsgroup-unreads)
2846               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2847           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2848             ;; This article was previously marked as read on account
2849             ;; of a low score, but now it has risen, so we mark it as
2850             ;; unread.
2851             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2852         (gnus-summary-update-mark
2853          (if (or (null gnus-summary-default-score)
2854                  (<= (abs (- score gnus-summary-default-score))
2855                      gnus-summary-zcore-fuzz))
2856              ?  ;Whitespace
2857            (if (< score gnus-summary-default-score)
2858                gnus-score-below-mark gnus-score-over-mark))
2859          'score))
2860       ;; Do visual highlighting.
2861       (when (gnus-visual-p 'summary-highlight 'highlight)
2862         (gnus-run-hooks 'gnus-summary-update-hook)))))
2863
2864 (defvar gnus-tmp-new-adopts nil)
2865
2866 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2867   "Return the number of articles in THREAD.
2868 This may be 0 in some cases -- if none of the articles in
2869 the thread are to be displayed."
2870   (let* ((number
2871           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2872           (cond
2873            ((not (listp thread))
2874             1)
2875            ((and (consp thread) (cdr thread))
2876             (apply
2877              '+ 1 (mapcar
2878                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2879            ((null thread)
2880             1)
2881            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2882             1)
2883            (t 0))))
2884     (when (and level (zerop level) gnus-tmp-new-adopts)
2885       (incf number
2886             (apply '+ (mapcar
2887                        'gnus-summary-number-of-articles-in-thread
2888                        gnus-tmp-new-adopts))))
2889     (if char
2890         (if (> number 1) gnus-not-empty-thread-mark
2891           gnus-empty-thread-mark)
2892       number)))
2893
2894 (defun gnus-summary-set-local-parameters (group)
2895   "Go through the local params of GROUP and set all variable specs in that list."
2896   (let ((params (gnus-group-find-parameter group))
2897         elem)
2898     (while params
2899       (setq elem (car params)
2900             params (cdr params))
2901       (and (consp elem)                 ; Has to be a cons.
2902            (consp (cdr elem))           ; The cdr has to be a list.
2903            (symbolp (car elem))         ; Has to be a symbol in there.
2904            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2905            (ignore-errors               ; So we set it.
2906              (make-local-variable (car elem))
2907              (set (car elem) (eval (nth 1 elem))))))))
2908
2909 (defun gnus-summary-read-group (group &optional show-all no-article
2910                                       kill-buffer no-display backward
2911                                       select-articles)
2912   "Start reading news in newsgroup GROUP.
2913 If SHOW-ALL is non-nil, already read articles are also listed.
2914 If NO-ARTICLE is non-nil, no article is selected initially.
2915 If NO-DISPLAY, don't generate a summary buffer."
2916   (let (result)
2917     (while (and group
2918                 (null (setq result
2919                             (let ((gnus-auto-select-next nil))
2920                               (or (gnus-summary-read-group-1
2921                                    group show-all no-article
2922                                    kill-buffer no-display
2923                                    select-articles)
2924                                   (setq show-all nil
2925                                         select-articles nil)))))
2926                 (eq gnus-auto-select-next 'quietly))
2927       (set-buffer gnus-group-buffer)
2928       ;; The entry function called above goes to the next
2929       ;; group automatically, so we go two groups back
2930       ;; if we are searching for the previous group.
2931       (when backward
2932         (gnus-group-prev-unread-group 2))
2933       (if (not (equal group (gnus-group-group-name)))
2934           (setq group (gnus-group-group-name))
2935         (setq group nil)))
2936     result))
2937
2938 (defun gnus-summary-jump-to-other-group (group &optional show-all)
2939   "Directly jump to the other GROUP from summary buffer.
2940 If SHOW-ALL is non-nil, already read articles are also listed."
2941   (interactive
2942    (if (eq gnus-summary-buffer (current-buffer))
2943        (list (completing-read
2944               "Group: " gnus-active-hashtb nil t
2945               (when (and gnus-newsgroup-name
2946                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
2947                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
2948               'gnus-group-history)
2949              current-prefix-arg)
2950      (error "%s must be invoked from a gnus summary buffer." this-command)))
2951   (unless (or (zerop (length group))
2952               (and gnus-newsgroup-name
2953                    (string-equal gnus-newsgroup-name group)))
2954     (gnus-summary-exit)
2955     (gnus-summary-read-group group show-all
2956                              gnus-dont-select-after-jump-to-other-group)))
2957
2958 (defun gnus-summary-read-group-1 (group show-all no-article
2959                                         kill-buffer no-display
2960                                         &optional select-articles)
2961   ;; Killed foreign groups can't be entered.
2962   (when (and (not (gnus-group-native-p group))
2963              (not (gnus-gethash group gnus-newsrc-hashtb)))
2964     (error "Dead non-native groups can't be entered"))
2965   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2966   (let* ((new-group (gnus-summary-setup-buffer group))
2967          (quit-config (gnus-group-quit-config group))
2968          (did-select (and new-group (gnus-select-newsgroup
2969                                      group show-all select-articles))))
2970     (cond
2971      ;; This summary buffer exists already, so we just select it.
2972      ((not new-group)
2973       (gnus-set-global-variables)
2974       (when kill-buffer
2975         (gnus-kill-or-deaden-summary kill-buffer))
2976       (gnus-configure-windows 'summary 'force)
2977       (gnus-set-mode-line 'summary)
2978       (gnus-summary-position-point)
2979       (message "")
2980       t)
2981      ;; We couldn't select this group.
2982      ((null did-select)
2983       (when (and (eq major-mode 'gnus-summary-mode)
2984                  (not (equal (current-buffer) kill-buffer)))
2985         (kill-buffer (current-buffer))
2986         (if (not quit-config)
2987             (progn
2988               ;; Update the info -- marks might need to be removed,
2989               ;; for instance.
2990               (gnus-summary-update-info)
2991               (set-buffer gnus-group-buffer)
2992               (gnus-group-jump-to-group group)
2993               (gnus-group-next-unread-group 1))
2994           (gnus-handle-ephemeral-exit quit-config)))
2995       (gnus-message 3 "Can't select group")
2996       nil)
2997      ;; The user did a `C-g' while prompting for number of articles,
2998      ;; so we exit this group.
2999      ((eq did-select 'quit)
3000       (and (eq major-mode 'gnus-summary-mode)
3001            (not (equal (current-buffer) kill-buffer))
3002            (kill-buffer (current-buffer)))
3003       (when kill-buffer
3004         (gnus-kill-or-deaden-summary kill-buffer))
3005       (if (not quit-config)
3006           (progn
3007             (set-buffer gnus-group-buffer)
3008             (gnus-group-jump-to-group group)
3009             (gnus-group-next-unread-group 1)
3010             (gnus-configure-windows 'group 'force))
3011         (gnus-handle-ephemeral-exit quit-config))
3012       ;; Finally signal the quit.
3013       (signal 'quit nil))
3014      ;; The group was successfully selected.
3015      (t
3016       (gnus-set-global-variables)
3017       ;; Save the active value in effect when the group was entered.
3018       (setq gnus-newsgroup-active
3019             (gnus-copy-sequence
3020              (gnus-active gnus-newsgroup-name)))
3021       ;; You can change the summary buffer in some way with this hook.
3022       (gnus-run-hooks 'gnus-select-group-hook)
3023       ;; Set any local variables in the group parameters.
3024       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3025       (gnus-update-format-specifications
3026        nil 'summary 'summary-mode 'summary-dummy)
3027       (gnus-update-summary-mark-positions)
3028       ;; Do score processing.
3029       (when gnus-use-scoring
3030         (gnus-possibly-score-headers))
3031       ;; Check whether to fill in the gaps in the threads.
3032       (when gnus-build-sparse-threads
3033         (gnus-build-sparse-threads))
3034       ;; Find the initial limit.
3035       (if gnus-show-threads
3036           (if show-all
3037               (let ((gnus-newsgroup-dormant nil))
3038                 (gnus-summary-initial-limit show-all))
3039             (gnus-summary-initial-limit show-all))
3040         ;; When untreaded, all articles are always shown.
3041         (setq gnus-newsgroup-limit
3042               (mapcar
3043                (lambda (header) (mail-header-number header))
3044                gnus-newsgroup-headers)))
3045       ;; Generate the summary buffer.
3046       (unless no-display
3047         (gnus-summary-prepare))
3048       (when gnus-use-trees
3049         (gnus-tree-open group)
3050         (setq gnus-summary-highlight-line-function
3051               'gnus-tree-highlight-article))
3052       ;; If the summary buffer is empty, but there are some low-scored
3053       ;; articles or some excluded dormants, we include these in the
3054       ;; buffer.
3055       (when (and (zerop (buffer-size))
3056                  (not no-display))
3057         (cond (gnus-newsgroup-dormant
3058                (gnus-summary-limit-include-dormant))
3059               ((and gnus-newsgroup-scored show-all)
3060                (gnus-summary-limit-include-expunged t))))
3061       ;; Function `gnus-apply-kill-file' must be called in this hook.
3062       (gnus-run-hooks 'gnus-apply-kill-hook)
3063       (if (and (zerop (buffer-size))
3064                (not no-display))
3065           (progn
3066             ;; This newsgroup is empty.
3067             (gnus-summary-catchup-and-exit nil t)
3068             (gnus-message 6 "No unread news")
3069             (when kill-buffer
3070               (gnus-kill-or-deaden-summary kill-buffer))
3071             ;; Return nil from this function.
3072             nil)
3073         ;; Hide conversation thread subtrees.  We cannot do this in
3074         ;; gnus-summary-prepare-hook since kill processing may not
3075         ;; work with hidden articles.
3076         (and gnus-show-threads
3077              gnus-thread-hide-subtree
3078              (gnus-summary-hide-all-threads))
3079         (when kill-buffer
3080           (gnus-kill-or-deaden-summary kill-buffer))
3081         ;; Show first unread article if requested.
3082         (if (and (not no-article)
3083                  (not no-display)
3084                  gnus-newsgroup-unreads
3085                  gnus-auto-select-first)
3086             (progn
3087               (gnus-configure-windows 'summary)
3088               (cond
3089                ((eq gnus-auto-select-first 'best)
3090                 (gnus-summary-best-unread-article))
3091                ((eq gnus-auto-select-first t)
3092                 (gnus-summary-first-unread-article))
3093                ((gnus-functionp gnus-auto-select-first)
3094                 (funcall gnus-auto-select-first))))
3095           ;; Don't select any articles, just move point to the first
3096           ;; article in the group.
3097           (goto-char (point-min))
3098           (gnus-summary-position-point)
3099           (gnus-configure-windows 'summary 'force)
3100           (gnus-set-mode-line 'summary))
3101         (when (get-buffer-window gnus-group-buffer t)
3102           ;; Gotta use windows, because recenter does weird stuff if
3103           ;; the current buffer ain't the displayed window.
3104           (let ((owin (selected-window)))
3105             (select-window (get-buffer-window gnus-group-buffer t))
3106             (when (gnus-group-goto-group group)
3107               (recenter))
3108             (select-window owin)))
3109         ;; Mark this buffer as "prepared".
3110         (setq gnus-newsgroup-prepared t)
3111         (gnus-run-hooks 'gnus-summary-prepared-hook)
3112         t)))))
3113
3114 (defun gnus-summary-prepare ()
3115   "Generate the summary buffer."
3116   (interactive)
3117   (let ((buffer-read-only nil))
3118     (erase-buffer)
3119     (setq gnus-newsgroup-data nil
3120           gnus-newsgroup-data-reverse nil)
3121     (gnus-run-hooks 'gnus-summary-generate-hook)
3122     ;; Generate the buffer, either with threads or without.
3123     (when gnus-newsgroup-headers
3124       (gnus-summary-prepare-threads
3125        (if gnus-show-threads
3126            (gnus-sort-gathered-threads
3127             (funcall gnus-summary-thread-gathering-function
3128                      (gnus-sort-threads
3129                       (gnus-cut-threads (gnus-make-threads)))))
3130          ;; Unthreaded display.
3131          (gnus-sort-articles gnus-newsgroup-headers))))
3132     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3133     ;; Call hooks for modifying summary buffer.
3134     (goto-char (point-min))
3135     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3136
3137 (defsubst gnus-general-simplify-subject (subject)
3138   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3139   (setq subject
3140         (cond
3141          ;; Truncate the subject.
3142          (gnus-simplify-subject-functions
3143           (gnus-map-function gnus-simplify-subject-functions subject))
3144          ((numberp gnus-summary-gather-subject-limit)
3145           (setq subject (gnus-simplify-subject-re subject))
3146           (if (> (length subject) gnus-summary-gather-subject-limit)
3147               (substring subject 0 gnus-summary-gather-subject-limit)
3148             subject))
3149          ;; Fuzzily simplify it.
3150          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3151           (gnus-simplify-subject-fuzzy subject))
3152          ;; Just remove the leading "Re:".
3153          (t
3154           (gnus-simplify-subject-re subject))))
3155
3156   (if (and gnus-summary-gather-exclude-subject
3157            (string-match gnus-summary-gather-exclude-subject subject))
3158       nil                               ; This article shouldn't be gathered
3159     subject))
3160
3161 (defun gnus-summary-simplify-subject-query ()
3162   "Query where the respool algorithm would put this article."
3163   (interactive)
3164   (gnus-summary-select-article)
3165   (message "%s"
3166            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3167
3168 (defun gnus-gather-threads-by-subject (threads)
3169   "Gather threads by looking at Subject headers."
3170   (if (not gnus-summary-make-false-root)
3171       threads
3172     (let ((hashtb (gnus-make-hashtable 1024))
3173           (prev threads)
3174           (result threads)
3175           subject hthread whole-subject)
3176       (while threads
3177         (setq subject (gnus-general-simplify-subject
3178                        (setq whole-subject (mail-header-subject
3179                                             (caar threads)))))
3180         (when subject
3181           (if (setq hthread (gnus-gethash subject hashtb))
3182               (progn
3183                 ;; We enter a dummy root into the thread, if we
3184                 ;; haven't done that already.
3185                 (unless (stringp (caar hthread))
3186                   (setcar hthread (list whole-subject (car hthread))))
3187                 ;; We add this new gathered thread to this gathered
3188                 ;; thread.
3189                 (setcdr (car hthread)
3190                         (nconc (cdar hthread) (list (car threads))))
3191                 ;; Remove it from the list of threads.
3192                 (setcdr prev (cdr threads))
3193                 (setq threads prev))
3194             ;; Enter this thread into the hash table.
3195             (gnus-sethash subject threads hashtb)))
3196         (setq prev threads)
3197         (setq threads (cdr threads)))
3198       result)))
3199
3200 (defun gnus-gather-threads-by-references (threads)
3201   "Gather threads by looking at References headers."
3202   (let ((idhashtb (gnus-make-hashtable 1024))
3203         (thhashtb (gnus-make-hashtable 1024))
3204         (prev threads)
3205         (result threads)
3206         ids references id gthread gid entered ref)
3207     (while threads
3208       (when (setq references (mail-header-references (caar threads)))
3209         (setq id (mail-header-id (caar threads))
3210               ids (gnus-split-references references)
3211               entered nil)
3212         (while (setq ref (pop ids))
3213           (setq ids (delete ref ids))
3214           (if (not (setq gid (gnus-gethash ref idhashtb)))
3215               (progn
3216                 (gnus-sethash ref id idhashtb)
3217                 (gnus-sethash id threads thhashtb))
3218             (setq gthread (gnus-gethash gid thhashtb))
3219             (unless entered
3220               ;; We enter a dummy root into the thread, if we
3221               ;; haven't done that already.
3222               (unless (stringp (caar gthread))
3223                 (setcar gthread (list (mail-header-subject (caar gthread))
3224                                       (car gthread))))
3225               ;; We add this new gathered thread to this gathered
3226               ;; thread.
3227               (setcdr (car gthread)
3228                       (nconc (cdar gthread) (list (car threads)))))
3229             ;; Add it into the thread hash table.
3230             (gnus-sethash id gthread thhashtb)
3231             (setq entered t)
3232             ;; Remove it from the list of threads.
3233             (setcdr prev (cdr threads))
3234             (setq threads prev))))
3235       (setq prev threads)
3236       (setq threads (cdr threads)))
3237     result))
3238
3239 (defun gnus-sort-gathered-threads (threads)
3240   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3241   (let ((result threads))
3242     (while threads
3243       (when (stringp (caar threads))
3244         (setcdr (car threads)
3245                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3246       (setq threads (cdr threads)))
3247     result))
3248
3249 (defun gnus-thread-loop-p (root thread)
3250   "Say whether ROOT is in THREAD."
3251   (let ((stack (list thread))
3252         (infloop 0)
3253         th)
3254     (while (setq thread (pop stack))
3255       (setq th (cdr thread))
3256       (while (and th
3257                   (not (eq (caar th) root)))
3258         (pop th))
3259       (if th
3260           ;; We have found a loop.
3261           (let (ref-dep)
3262             (setcdr thread (delq (car th) (cdr thread)))
3263             (if (boundp (setq ref-dep (intern "none"
3264                                               gnus-newsgroup-dependencies)))
3265                 (setcdr (symbol-value ref-dep)
3266                         (nconc (cdr (symbol-value ref-dep))
3267                                (list (car th))))
3268               (set ref-dep (list nil (car th))))
3269             (setq infloop 1
3270                   stack nil))
3271         ;; Push all the subthreads onto the stack.
3272         (push (cdr thread) stack)))
3273     infloop))
3274
3275 (defun gnus-make-threads ()
3276   "Go through the dependency hashtb and find the roots.  Return all threads."
3277   (let (threads)
3278     (while (catch 'infloop
3279              (mapatoms
3280               (lambda (refs)
3281                 ;; Deal with self-referencing References loops.
3282                 (when (and (car (symbol-value refs))
3283                            (not (zerop
3284                                  (apply
3285                                   '+
3286                                   (mapcar
3287                                    (lambda (thread)
3288                                      (gnus-thread-loop-p
3289                                       (car (symbol-value refs)) thread))
3290                                    (cdr (symbol-value refs)))))))
3291                   (setq threads nil)
3292                   (throw 'infloop t))
3293                 (unless (car (symbol-value refs))
3294                   ;; These threads do not refer back to any other articles,
3295                   ;; so they're roots.
3296                   (setq threads (append (cdr (symbol-value refs)) threads))))
3297               gnus-newsgroup-dependencies)))
3298     threads))
3299
3300 ;; Build the thread tree.
3301 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3302   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3303
3304 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3305 if it was already present.
3306
3307 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3308 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3309 Message-IDs will be renamed be renamed to a unique Message-ID before
3310 being entered.
3311
3312 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3313   (let* ((id (mail-header-id header))
3314          (id-dep (and id (intern id dependencies)))
3315          ref ref-dep ref-header)
3316     ;; Enter this `header' in the `dependencies' table.
3317     (cond
3318      ((not id-dep)
3319       (setq header nil))
3320      ;; The first two cases do the normal part: enter a new `header'
3321      ;; in the `dependencies' table.
3322      ((not (boundp id-dep))
3323       (set id-dep (list header)))
3324      ((null (car (symbol-value id-dep)))
3325       (setcar (symbol-value id-dep) header))
3326
3327      ;; From here the `header' was already present in the
3328      ;; `dependencies' table.
3329      (force-new
3330       ;; Overrides an existing entry;
3331       ;; just set the header part of the entry.
3332       (setcar (symbol-value id-dep) header))
3333
3334      ;; Renames the existing `header' to a unique Message-ID.
3335      ((not gnus-summary-ignore-duplicates)
3336       ;; An article with this Message-ID has already been seen.
3337       ;; We rename the Message-ID.
3338       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3339            (list header))
3340       (mail-header-set-id header id))
3341
3342      ;; The last case ignores an existing entry, except it adds any
3343      ;; additional Xrefs (in case the two articles came from different
3344      ;; servers.
3345      ;; Also sets `header' to `nil' meaning that the `dependencies'
3346      ;; table was *not* modified.
3347      (t
3348       (mail-header-set-xref
3349        (car (symbol-value id-dep))
3350        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3351                    "")
3352                (or (mail-header-xref header) "")))
3353       (setq header nil)))
3354
3355     (when header
3356       ;; First check if that we are not creating a References loop.
3357       (setq ref (gnus-parent-id (mail-header-references header)))
3358       (while (and ref
3359                   (setq ref-dep (intern-soft ref dependencies))
3360                   (boundp ref-dep)
3361                   (setq ref-header (car (symbol-value ref-dep))))
3362         (if (string= id ref)
3363             ;; Yuk!  This is a reference loop.  Make the article be a
3364             ;; root article.
3365             (progn
3366               (mail-header-set-references (car (symbol-value id-dep)) "none")
3367               (setq ref nil))
3368           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3369       (setq ref (gnus-parent-id (mail-header-references header)))
3370       (setq ref-dep (intern (or ref "none") dependencies))
3371       (if (boundp ref-dep)
3372           (setcdr (symbol-value ref-dep)
3373                   (nconc (cdr (symbol-value ref-dep))
3374                          (list (symbol-value id-dep))))
3375         (set ref-dep (list nil (symbol-value id-dep)))))
3376     header))
3377
3378 (defun gnus-build-sparse-threads ()
3379   (let ((headers gnus-newsgroup-headers)
3380         (mail-parse-charset gnus-newsgroup-charset)
3381         (gnus-summary-ignore-duplicates t)
3382         header references generation relations
3383         subject child end new-child date)
3384     ;; First we create an alist of generations/relations, where
3385     ;; generations is how much we trust the relation, and the relation
3386     ;; is parent/child.
3387     (gnus-message 7 "Making sparse threads...")
3388     (save-excursion
3389       (nnheader-set-temp-buffer " *gnus sparse threads*")
3390       (while (setq header (pop headers))
3391         (when (and (setq references (mail-header-references header))
3392                    (not (string= references "")))
3393           (insert references)
3394           (setq child (mail-header-id header)
3395                 subject (mail-header-subject header)
3396                 date (mail-header-date header)
3397                 generation 0)
3398           (while (search-backward ">" nil t)
3399             (setq end (1+ (point)))
3400             (when (search-backward "<" nil t)
3401               (setq new-child (buffer-substring (point) end))
3402               (push (list (incf generation)
3403                           child (setq child new-child)
3404                           subject date)
3405                     relations)))
3406           (when child
3407             (push (list (1+ generation) child nil subject) relations))
3408           (erase-buffer)))
3409       (kill-buffer (current-buffer)))
3410     ;; Sort over trustworthiness.
3411     (mapcar
3412      (lambda (relation)
3413        (when (gnus-dependencies-add-header
3414               (make-full-mail-header-from-decoded-header
3415                gnus-reffed-article-number
3416                (nth 3 relation) "" (or (nth 4 relation) "")
3417                (nth 1 relation)
3418                (or (nth 2 relation) "") 0 0 "")
3419               gnus-newsgroup-dependencies nil)
3420          (push gnus-reffed-article-number gnus-newsgroup-limit)
3421          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3422          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3423                gnus-newsgroup-reads)
3424          (decf gnus-reffed-article-number)))
3425      (sort relations 'car-less-than-car))
3426     (gnus-message 7 "Making sparse threads...done")))
3427
3428 (defun gnus-build-old-threads ()
3429   ;; Look at all the articles that refer back to old articles, and
3430   ;; fetch the headers for the articles that aren't there.  This will
3431   ;; build complete threads - if the roots haven't been expired by the
3432   ;; server, that is.
3433   (let ((mail-parse-charset gnus-newsgroup-charset)
3434         id heads)
3435     (mapatoms
3436      (lambda (refs)
3437        (when (not (car (symbol-value refs)))
3438          (setq heads (cdr (symbol-value refs)))
3439          (while heads
3440            (if (memq (mail-header-number (caar heads))
3441                      gnus-newsgroup-dormant)
3442                (setq heads (cdr heads))
3443              (setq id (symbol-name refs))
3444              (while (and (setq id (gnus-build-get-header id))
3445                          (not (car (gnus-id-to-thread id)))))
3446              (setq heads nil)))))
3447      gnus-newsgroup-dependencies)))
3448
3449 ;; This function has to be called with point after the article number
3450 ;; on the beginning of the line.
3451 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3452   (let ((eol (gnus-point-at-eol))
3453         (buffer (current-buffer))
3454         header)
3455
3456     ;; overview: [num subject from date id refs chars lines misc]
3457     (unwind-protect
3458         (progn
3459           (narrow-to-region (point) eol)
3460           (unless (eobp)
3461             (forward-char))
3462
3463           (setq header
3464                 (make-full-mail-header
3465                  number                         ; number
3466                  (nnheader-nov-field)           ; subject
3467                  (nnheader-nov-field)           ; from
3468                  (nnheader-nov-field)           ; date
3469                  (nnheader-nov-read-message-id) ; id
3470                  (nnheader-nov-field)           ; refs
3471                  (nnheader-nov-read-integer)    ; chars
3472                  (nnheader-nov-read-integer)    ; lines
3473                  (unless (eobp)
3474                    (if (looking-at "Xref: ")
3475                        (goto-char (match-end 0)))
3476                    (nnheader-nov-field))        ; Xref
3477                  (nnheader-nov-parse-extra))))  ; extra
3478
3479       (widen))
3480
3481     (when gnus-alter-header-function
3482       (funcall gnus-alter-header-function header))
3483     (gnus-dependencies-add-header header dependencies force-new)))
3484
3485 (defun gnus-build-get-header (id)
3486   "Look through the buffer of NOV lines and find the header to ID.
3487 Enter this line into the dependencies hash table, and return
3488 the id of the parent article (if any)."
3489   (let ((deps gnus-newsgroup-dependencies)
3490         found header)
3491     (prog1
3492         (save-excursion
3493           (set-buffer nntp-server-buffer)
3494           (let ((case-fold-search nil))
3495             (goto-char (point-min))
3496             (while (and (not found)
3497                         (search-forward id nil t))
3498               (beginning-of-line)
3499               (setq found (looking-at
3500                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3501                                    (regexp-quote id))))
3502               (or found (beginning-of-line 2)))
3503             (when found
3504               (beginning-of-line)
3505               (and
3506                (setq header (gnus-nov-parse-line
3507                              (read (current-buffer)) deps))
3508                (gnus-parent-id (mail-header-references header))))))
3509       (when header
3510         (let ((number (mail-header-number header)))
3511           (push number gnus-newsgroup-limit)
3512           (push header gnus-newsgroup-headers)
3513           (if (memq number gnus-newsgroup-unselected)
3514               (progn
3515                 (push number gnus-newsgroup-unreads)
3516                 (setq gnus-newsgroup-unselected
3517                       (delq number gnus-newsgroup-unselected)))
3518             (push number gnus-newsgroup-ancient)))))))
3519
3520 (defun gnus-build-all-threads ()
3521   "Read all the headers."
3522   (let ((gnus-summary-ignore-duplicates t)
3523         (mail-parse-charset gnus-newsgroup-charset)
3524         (dependencies gnus-newsgroup-dependencies)
3525         header article)
3526     (save-excursion
3527       (set-buffer nntp-server-buffer)
3528       (let ((case-fold-search nil))
3529         (goto-char (point-min))
3530         (while (not (eobp))
3531           (ignore-errors
3532             (setq article (read (current-buffer))
3533                   header (gnus-nov-parse-line article dependencies)))
3534           (when header
3535             (save-excursion
3536               (set-buffer gnus-summary-buffer)
3537               (push header gnus-newsgroup-headers)
3538               (if (memq (setq article (mail-header-number header))
3539                         gnus-newsgroup-unselected)
3540                   (progn
3541                     (push article gnus-newsgroup-unreads)
3542                     (setq gnus-newsgroup-unselected
3543                           (delq article gnus-newsgroup-unselected)))
3544                 (push article gnus-newsgroup-ancient)))
3545             (forward-line 1)))))))
3546
3547 (defun gnus-summary-update-article-line (article header)
3548   "Update the line for ARTICLE using HEADERS."
3549   (let* ((id (mail-header-id header))
3550          (thread (gnus-id-to-thread id)))
3551     (unless thread
3552       (error "Article in no thread"))
3553     ;; Update the thread.
3554     (setcar thread header)
3555     (gnus-summary-goto-subject article)
3556     (let* ((datal (gnus-data-find-list article))
3557            (data (car datal))
3558            (length (when (cdr datal)
3559                      (- (gnus-data-pos data)
3560                         (gnus-data-pos (cadr datal)))))
3561            (buffer-read-only nil)
3562            (level (gnus-summary-thread-level)))
3563       (gnus-delete-line)
3564       (gnus-summary-insert-line
3565        header level nil (gnus-article-mark article)
3566        (memq article gnus-newsgroup-replied)
3567        (memq article gnus-newsgroup-expirable)
3568        ;; Only insert the Subject string when it's different
3569        ;; from the previous Subject string.
3570        (if (and
3571             gnus-show-threads
3572             (gnus-subject-equal
3573              (condition-case ()
3574                  (mail-header-subject
3575                   (gnus-data-header
3576                    (cadr
3577                     (gnus-data-find-list
3578                      article
3579                      (gnus-data-list t)))))
3580                ;; Error on the side of excessive subjects.
3581                (error ""))
3582              (mail-header-subject header)))
3583            ""
3584          (mail-header-subject header))
3585        nil (cdr (assq article gnus-newsgroup-scored))
3586        (memq article gnus-newsgroup-processable))
3587       (when length
3588         (gnus-data-update-list
3589          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3590
3591 (defun gnus-summary-update-article (article &optional iheader)
3592   "Update ARTICLE in the summary buffer."
3593   (set-buffer gnus-summary-buffer)
3594   (let* ((header (gnus-summary-article-header article))
3595          (id (mail-header-id header))
3596          (data (gnus-data-find article))
3597          (thread (gnus-id-to-thread id))
3598          (references (mail-header-references header))
3599          (parent
3600           (gnus-id-to-thread
3601            (or (gnus-parent-id
3602                 (when (and references
3603                            (not (equal "" references)))
3604                   references))
3605                "none")))
3606          (buffer-read-only nil)
3607          (old (car thread)))
3608     (when thread
3609       (unless iheader
3610         (setcar thread nil)
3611         (when parent
3612           (delq thread parent)))
3613       (if (gnus-summary-insert-subject id header)
3614           ;; Set the (possibly) new article number in the data structure.
3615           (gnus-data-set-number data (gnus-id-to-article id))
3616         (setcar thread old)
3617         nil))))
3618
3619 (defun gnus-rebuild-thread (id &optional line)
3620   "Rebuild the thread containing ID.
3621 If LINE, insert the rebuilt thread starting on line LINE."
3622   (let ((buffer-read-only nil)
3623         old-pos current thread data)
3624     (if (not gnus-show-threads)
3625         (setq thread (list (car (gnus-id-to-thread id))))
3626       ;; Get the thread this article is part of.
3627       (setq thread (gnus-remove-thread id)))
3628     (setq old-pos (gnus-point-at-bol))
3629     (setq current (save-excursion
3630                     (and (zerop (forward-line -1))
3631                          (gnus-summary-article-number))))
3632     ;; If this is a gathered thread, we have to go some re-gathering.
3633     (when (stringp (car thread))
3634       (let ((subject (car thread))
3635             roots thr)
3636         (setq thread (cdr thread))
3637         (while thread
3638           (unless (memq (setq thr (gnus-id-to-thread
3639                                    (gnus-root-id
3640                                     (mail-header-id (caar thread)))))
3641                         roots)
3642             (push thr roots))
3643           (setq thread (cdr thread)))
3644         ;; We now have all (unique) roots.
3645         (if (= (length roots) 1)
3646             ;; All the loose roots are now one solid root.
3647             (setq thread (car roots))
3648           (setq thread (cons subject (gnus-sort-threads roots))))))
3649     (let (threads)
3650       ;; We then insert this thread into the summary buffer.
3651       (when line
3652         (goto-char (point-min))
3653         (forward-line (1- line)))
3654       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3655         (if gnus-show-threads
3656             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3657           (gnus-summary-prepare-unthreaded thread))
3658         (setq data (nreverse gnus-newsgroup-data))
3659         (setq threads gnus-newsgroup-threads))
3660       ;; We splice the new data into the data structure.
3661       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3662       ;;!!! then we want to insert at the beginning of the buffer.
3663       ;;!!! That happens to be true with Gnus now, but that may
3664       ;;!!! change in the future.  Perhaps.
3665       (gnus-data-enter-list
3666        (if line nil current) data (- (point) old-pos))
3667       (setq gnus-newsgroup-threads
3668             (nconc threads gnus-newsgroup-threads))
3669       (gnus-data-compute-positions))))
3670
3671 (defun gnus-number-to-header (number)
3672   "Return the header for article NUMBER."
3673   (let ((headers gnus-newsgroup-headers))
3674     (while (and headers
3675                 (not (= number (mail-header-number (car headers)))))
3676       (pop headers))
3677     (when headers
3678       (car headers))))
3679
3680 (defun gnus-parent-headers (in-headers &optional generation)
3681   "Return the headers of the GENERATIONeth parent of HEADERS."
3682   (unless generation
3683     (setq generation 1))
3684   (let ((parent t)
3685         (headers in-headers)
3686         references)
3687     (while (and parent
3688                 (not (zerop generation))
3689                 (setq references (mail-header-references headers)))
3690       (setq headers (if (and references
3691                              (setq parent (gnus-parent-id references)))
3692                         (car (gnus-id-to-thread parent))
3693                       nil))
3694       (decf generation))
3695     (and (not (eq headers in-headers))
3696          headers)))
3697
3698 (defun gnus-id-to-thread (id)
3699   "Return the (sub-)thread where ID appears."
3700   (gnus-gethash id gnus-newsgroup-dependencies))
3701
3702 (defun gnus-id-to-article (id)
3703   "Return the article number of ID."
3704   (let ((thread (gnus-id-to-thread id)))
3705     (when (and thread
3706                (car thread))
3707       (mail-header-number (car thread)))))
3708
3709 (defun gnus-id-to-header (id)
3710   "Return the article headers of ID."
3711   (car (gnus-id-to-thread id)))
3712
3713 (defun gnus-article-displayed-root-p (article)
3714   "Say whether ARTICLE is a root(ish) article."
3715   (let ((level (gnus-summary-thread-level article))
3716         (refs (mail-header-references  (gnus-summary-article-header article)))
3717         particle)
3718     (cond
3719      ((null level) nil)
3720      ((zerop level) t)
3721      ((null refs) t)
3722      ((null (gnus-parent-id refs)) t)
3723      ((and (= 1 level)
3724            (null (setq particle (gnus-id-to-article
3725                                  (gnus-parent-id refs))))
3726            (null (gnus-summary-thread-level particle)))))))
3727
3728 (defun gnus-root-id (id)
3729   "Return the id of the root of the thread where ID appears."
3730   (let (last-id prev)
3731     (while (and id (setq prev (car (gnus-id-to-thread id))))
3732       (setq last-id id
3733             id (gnus-parent-id (mail-header-references prev))))
3734     last-id))
3735
3736 (defun gnus-articles-in-thread (thread)
3737   "Return the list of articles in THREAD."
3738   (cons (mail-header-number (car thread))
3739         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3740
3741 (defun gnus-remove-thread (id &optional dont-remove)
3742   "Remove the thread that has ID in it."
3743   (let (headers thread last-id)
3744     ;; First go up in this thread until we find the root.
3745     (setq last-id (gnus-root-id id)
3746           headers (message-flatten-list (gnus-id-to-thread last-id)))
3747     ;; We have now found the real root of this thread.  It might have
3748     ;; been gathered into some loose thread, so we have to search
3749     ;; through the threads to find the thread we wanted.
3750     (let ((threads gnus-newsgroup-threads)
3751           sub)
3752       (while threads
3753         (setq sub (car threads))
3754         (if (stringp (car sub))
3755             ;; This is a gathered thread, so we look at the roots
3756             ;; below it to find whether this article is in this
3757             ;; gathered root.
3758             (progn
3759               (setq sub (cdr sub))
3760               (while sub
3761                 (when (member (caar sub) headers)
3762                   (setq thread (car threads)
3763                         threads nil
3764                         sub nil))
3765                 (setq sub (cdr sub))))
3766           ;; It's an ordinary thread, so we check it.
3767           (when (eq (car sub) (car headers))
3768             (setq thread sub
3769                   threads nil)))
3770         (setq threads (cdr threads)))
3771       ;; If this article is in no thread, then it's a root.
3772       (if thread
3773           (unless dont-remove
3774             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3775         (setq thread (gnus-id-to-thread last-id)))
3776       (when thread
3777         (prog1
3778             thread                      ; We return this thread.
3779           (unless dont-remove
3780             (if (stringp (car thread))
3781                 (progn
3782                   ;; If we use dummy roots, then we have to remove the
3783                   ;; dummy root as well.
3784                   (when (eq gnus-summary-make-false-root 'dummy)
3785                     ;; We go to the dummy root by going to
3786                     ;; the first sub-"thread", and then one line up.
3787                     (gnus-summary-goto-article
3788                      (mail-header-number (caadr thread)))
3789                     (forward-line -1)
3790                     (gnus-delete-line)
3791                     (gnus-data-compute-positions))
3792                   (setq thread (cdr thread))
3793                   (while thread
3794                     (gnus-remove-thread-1 (car thread))
3795                     (setq thread (cdr thread))))
3796               (gnus-remove-thread-1 thread))))))))
3797
3798 (defun gnus-remove-thread-1 (thread)
3799   "Remove the thread THREAD recursively."
3800   (let ((number (mail-header-number (pop thread)))
3801         d)
3802     (setq thread (reverse thread))
3803     (while thread
3804       (gnus-remove-thread-1 (pop thread)))
3805     (when (setq d (gnus-data-find number))
3806       (goto-char (gnus-data-pos d))
3807       (gnus-summary-show-thread)
3808       (gnus-data-remove
3809        number
3810        (- (gnus-point-at-bol)
3811           (prog1
3812               (1+ (gnus-point-at-eol))
3813             (gnus-delete-line)))))))
3814
3815 (defun gnus-sort-threads-1 (threads func)
3816   (sort (mapcar (lambda (thread)
3817                   (cons (car thread)
3818                         (and (cdr thread)
3819                              (gnus-sort-threads-1 (cdr thread) func))))
3820                 threads) func))
3821
3822 (defun gnus-sort-threads (threads)
3823   "Sort THREADS."
3824   (if (not gnus-thread-sort-functions)
3825       threads
3826     (gnus-message 8 "Sorting threads...")
3827     (prog1
3828         (gnus-sort-threads-1 
3829          threads 
3830          (gnus-make-sort-function gnus-thread-sort-functions))
3831       (gnus-message 8 "Sorting threads...done"))))
3832
3833 (defun gnus-sort-articles (articles)
3834   "Sort ARTICLES."
3835   (when gnus-article-sort-functions
3836     (gnus-message 7 "Sorting articles...")
3837     (prog1
3838         (setq gnus-newsgroup-headers
3839               (sort articles (gnus-make-sort-function
3840                               gnus-article-sort-functions)))
3841       (gnus-message 7 "Sorting articles...done"))))
3842
3843 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3844 (defmacro gnus-thread-header (thread)
3845   "Return header of first article in THREAD.
3846 Note that THREAD must never, ever be anything else than a variable -
3847 using some other form will lead to serious barfage."
3848   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3849   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3850   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
3851         (vector thread) 2))
3852
3853 (defsubst gnus-article-sort-by-number (h1 h2)
3854   "Sort articles by article number."
3855   (< (mail-header-number h1)
3856      (mail-header-number h2)))
3857
3858 (defun gnus-thread-sort-by-number (h1 h2)
3859   "Sort threads by root article number."
3860   (gnus-article-sort-by-number
3861    (gnus-thread-header h1) (gnus-thread-header h2)))
3862
3863 (defsubst gnus-article-sort-by-lines (h1 h2)
3864   "Sort articles by article Lines header."
3865   (< (mail-header-lines h1)
3866      (mail-header-lines h2)))
3867
3868 (defun gnus-thread-sort-by-lines (h1 h2)
3869   "Sort threads by root article Lines header."
3870   (gnus-article-sort-by-lines
3871    (gnus-thread-header h1) (gnus-thread-header h2)))
3872
3873 (defsubst gnus-article-sort-by-chars (h1 h2)
3874   "Sort articles by octet length."
3875   (< (mail-header-chars h1)
3876      (mail-header-chars h2)))
3877
3878 (defun gnus-thread-sort-by-chars (h1 h2)
3879   "Sort threads by root article octet length."
3880   (gnus-article-sort-by-chars
3881    (gnus-thread-header h1) (gnus-thread-header h2)))
3882
3883 (defsubst gnus-article-sort-by-author (h1 h2)
3884   "Sort articles by root author."
3885   (string-lessp
3886    (let ((addr (car (mime-entity-read-field h1 'From))))
3887      (or (std11-full-name-string addr)
3888          (std11-address-string addr)
3889          ""))
3890    (let ((addr (car (mime-entity-read-field h2 'From))))
3891      (or (std11-full-name-string addr)
3892          (std11-address-string addr)
3893          ""))
3894    ))
3895
3896 (defun gnus-thread-sort-by-author (h1 h2)
3897   "Sort threads by root author."
3898   (gnus-article-sort-by-author
3899    (gnus-thread-header h1)  (gnus-thread-header h2)))
3900
3901 (defsubst gnus-article-sort-by-subject (h1 h2)
3902   "Sort articles by root subject."
3903   (string-lessp
3904    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3905    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3906
3907 (defun gnus-thread-sort-by-subject (h1 h2)
3908   "Sort threads by root subject."
3909   (gnus-article-sort-by-subject
3910    (gnus-thread-header h1) (gnus-thread-header h2)))
3911
3912 (defsubst gnus-article-sort-by-date (h1 h2)
3913   "Sort articles by root article date."
3914   (time-less-p
3915    (gnus-date-get-time (mail-header-date h1))
3916    (gnus-date-get-time (mail-header-date h2))))
3917
3918 (defun gnus-thread-sort-by-date (h1 h2)
3919   "Sort threads by root article date."
3920   (gnus-article-sort-by-date
3921    (gnus-thread-header h1) (gnus-thread-header h2)))
3922
3923 (defsubst gnus-article-sort-by-score (h1 h2)
3924   "Sort articles by root article score.
3925 Unscored articles will be counted as having a score of zero."
3926   (> (or (cdr (assq (mail-header-number h1)
3927                     gnus-newsgroup-scored))
3928          gnus-summary-default-score 0)
3929      (or (cdr (assq (mail-header-number h2)
3930                     gnus-newsgroup-scored))
3931          gnus-summary-default-score 0)))
3932
3933 (defun gnus-thread-sort-by-score (h1 h2)
3934   "Sort threads by root article score."
3935   (gnus-article-sort-by-score
3936    (gnus-thread-header h1) (gnus-thread-header h2)))
3937
3938 (defun gnus-thread-sort-by-total-score (h1 h2)
3939   "Sort threads by the sum of all scores in the thread.
3940 Unscored articles will be counted as having a score of zero."
3941   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3942
3943 (defun gnus-thread-total-score (thread)
3944   ;; This function find the total score of THREAD.
3945   (cond ((null thread)
3946          0)
3947         ((consp thread)
3948          (if (stringp (car thread))
3949              (apply gnus-thread-score-function 0
3950                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3951            (gnus-thread-total-score-1 thread)))
3952         (t
3953          (gnus-thread-total-score-1 (list thread)))))
3954
3955 (defun gnus-thread-total-score-1 (root)
3956   ;; This function find the total score of the thread below ROOT.
3957   (setq root (car root))
3958   (apply gnus-thread-score-function
3959          (or (append
3960               (mapcar 'gnus-thread-total-score
3961                       (cdr (gnus-id-to-thread (mail-header-id root))))
3962               (when (> (mail-header-number root) 0)
3963                 (list (or (cdr (assq (mail-header-number root)
3964                                      gnus-newsgroup-scored))
3965                           gnus-summary-default-score 0))))
3966              (list gnus-summary-default-score)
3967              '(0))))
3968
3969 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3970 (defvar gnus-tmp-prev-subject nil)
3971 (defvar gnus-tmp-false-parent nil)
3972 (defvar gnus-tmp-root-expunged nil)
3973 (defvar gnus-tmp-dummy-line nil)
3974
3975 (eval-when-compile (defvar gnus-tmp-header))
3976 (defun gnus-extra-header (type &optional header)
3977   "Return the extra header of TYPE."
3978   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3979       ""))
3980
3981 (defun gnus-summary-prepare-threads (threads)
3982   "Prepare summary buffer from THREADS and indentation LEVEL.
3983 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3984 or a straight list of headers."
3985   (gnus-message 7 "Generating summary...")
3986
3987   (setq gnus-newsgroup-threads threads)
3988   (beginning-of-line)
3989
3990   (let ((gnus-tmp-level 0)
3991         (default-score (or gnus-summary-default-score 0))
3992         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3993         thread number subject stack state gnus-tmp-gathered beg-match
3994         new-roots gnus-tmp-new-adopts thread-end
3995         gnus-tmp-header gnus-tmp-unread
3996         gnus-tmp-replied gnus-tmp-subject-or-nil
3997         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
3998         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
3999         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
4000
4001     (setq gnus-tmp-prev-subject nil)
4002
4003     (if (vectorp (car threads))
4004         ;; If this is a straight (sic) list of headers, then a
4005         ;; threaded summary display isn't required, so we just create
4006         ;; an unthreaded one.
4007         (gnus-summary-prepare-unthreaded threads)
4008
4009       ;; Do the threaded display.
4010
4011       (while (or threads stack gnus-tmp-new-adopts new-roots)
4012
4013         (if (and (= gnus-tmp-level 0)
4014                  (or (not stack)
4015                      (= (caar stack) 0))
4016                  (not gnus-tmp-false-parent)
4017                  (or gnus-tmp-new-adopts new-roots))
4018             (if gnus-tmp-new-adopts
4019                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4020                       thread (list (car gnus-tmp-new-adopts))
4021                       gnus-tmp-header (caar thread)
4022                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4023               (when new-roots
4024                 (setq thread (list (car new-roots))
4025                       gnus-tmp-header (caar thread)
4026                       new-roots (cdr new-roots))))
4027
4028           (if threads
4029               ;; If there are some threads, we do them before the
4030               ;; threads on the stack.
4031               (setq thread threads
4032                     gnus-tmp-header (caar thread))
4033             ;; There were no current threads, so we pop something off
4034             ;; the stack.
4035             (setq state (car stack)
4036                   gnus-tmp-level (car state)
4037                   thread (cdr state)
4038                   stack (cdr stack)
4039                   gnus-tmp-header (caar thread))))
4040
4041         (setq gnus-tmp-false-parent nil)
4042         (setq gnus-tmp-root-expunged nil)
4043         (setq thread-end nil)
4044
4045         (if (stringp gnus-tmp-header)
4046             ;; The header is a dummy root.
4047             (cond
4048              ((eq gnus-summary-make-false-root 'adopt)
4049               ;; We let the first article adopt the rest.
4050               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4051                                                (cddar thread)))
4052               (setq gnus-tmp-gathered
4053                     (nconc (mapcar
4054                             (lambda (h) (mail-header-number (car h)))
4055                             (cddar thread))
4056                            gnus-tmp-gathered))
4057               (setq thread (cons (list (caar thread)
4058                                        (cadar thread))
4059                                  (cdr thread)))
4060               (setq gnus-tmp-level -1
4061                     gnus-tmp-false-parent t))
4062              ((eq gnus-summary-make-false-root 'empty)
4063               ;; We print adopted articles with empty subject fields.
4064               (setq gnus-tmp-gathered
4065                     (nconc (mapcar
4066                             (lambda (h) (mail-header-number (car h)))
4067                             (cddar thread))
4068                            gnus-tmp-gathered))
4069               (setq gnus-tmp-level -1))
4070              ((eq gnus-summary-make-false-root 'dummy)
4071               ;; We remember that we probably want to output a dummy
4072               ;; root.
4073               (setq gnus-tmp-dummy-line gnus-tmp-header)
4074               (setq gnus-tmp-prev-subject gnus-tmp-header))
4075              (t
4076               ;; We do not make a root for the gathered
4077               ;; sub-threads at all.
4078               (setq gnus-tmp-level -1)))
4079
4080           (setq number (mail-header-number gnus-tmp-header)
4081                 subject (mail-header-subject gnus-tmp-header))
4082
4083           (cond
4084            ;; If the thread has changed subject, we might want to make
4085            ;; this subthread into a root.
4086            ((and (null gnus-thread-ignore-subject)
4087                  (not (zerop gnus-tmp-level))
4088                  gnus-tmp-prev-subject
4089                  (not (inline
4090                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4091             (setq new-roots (nconc new-roots (list (car thread)))
4092                   thread-end t
4093                   gnus-tmp-header nil))
4094            ;; If the article lies outside the current limit,
4095            ;; then we do not display it.
4096            ((not (memq number gnus-newsgroup-limit))
4097             (setq gnus-tmp-gathered
4098                   (nconc (mapcar
4099                           (lambda (h) (mail-header-number (car h)))
4100                           (cdar thread))
4101                          gnus-tmp-gathered))
4102             (setq gnus-tmp-new-adopts (if (cdar thread)
4103                                           (append gnus-tmp-new-adopts
4104                                                   (cdar thread))
4105                                         gnus-tmp-new-adopts)
4106                   thread-end t
4107                   gnus-tmp-header nil)
4108             (when (zerop gnus-tmp-level)
4109               (setq gnus-tmp-root-expunged t)))
4110            ;; Perhaps this article is to be marked as read?
4111            ((and gnus-summary-mark-below
4112                  (< (or (cdr (assq number gnus-newsgroup-scored))
4113                         default-score)
4114                     gnus-summary-mark-below)
4115                  ;; Don't touch sparse articles.
4116                  (not (gnus-summary-article-sparse-p number))
4117                  (not (gnus-summary-article-ancient-p number)))
4118             (setq gnus-newsgroup-unreads
4119                   (delq number gnus-newsgroup-unreads))
4120             (if gnus-newsgroup-auto-expire
4121                 (push number gnus-newsgroup-expirable)
4122               (push (cons number gnus-low-score-mark)
4123                     gnus-newsgroup-reads))))
4124
4125           (when gnus-tmp-header
4126             ;; We may have an old dummy line to output before this
4127             ;; article.
4128             (when (and gnus-tmp-dummy-line
4129                        (gnus-subject-equal
4130                         gnus-tmp-dummy-line
4131                         (mail-header-subject gnus-tmp-header)))
4132               (gnus-summary-insert-dummy-line
4133                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4134               (setq gnus-tmp-dummy-line nil))
4135
4136             ;; Compute the mark.
4137             (setq gnus-tmp-unread (gnus-article-mark number))
4138
4139             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4140                                   gnus-tmp-header gnus-tmp-level)
4141                   gnus-newsgroup-data)
4142
4143             ;; Actually insert the line.
4144             (setq
4145              gnus-tmp-subject-or-nil
4146              (cond
4147               ((and gnus-thread-ignore-subject
4148                     gnus-tmp-prev-subject
4149                     (not (inline (gnus-subject-equal
4150                                   gnus-tmp-prev-subject subject))))
4151                subject)
4152               ((zerop gnus-tmp-level)
4153                (if (and (eq gnus-summary-make-false-root 'empty)
4154                         (memq number gnus-tmp-gathered)
4155                         gnus-tmp-prev-subject
4156                         (inline (gnus-subject-equal
4157                                  gnus-tmp-prev-subject subject)))
4158                    gnus-summary-same-subject
4159                  subject))
4160               (t gnus-summary-same-subject)))
4161             (if (and (eq gnus-summary-make-false-root 'adopt)
4162                      (= gnus-tmp-level 1)
4163                      (memq number gnus-tmp-gathered))
4164                 (setq gnus-tmp-opening-bracket ?\<
4165                       gnus-tmp-closing-bracket ?\>)
4166               (setq gnus-tmp-opening-bracket ?\[
4167                     gnus-tmp-closing-bracket ?\]))
4168             (setq
4169              gnus-tmp-indentation
4170              (aref gnus-thread-indent-array gnus-tmp-level)
4171              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4172              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4173                                 gnus-summary-default-score 0)
4174              gnus-tmp-score-char
4175              (if (or (null gnus-summary-default-score)
4176                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4177                          gnus-summary-zcore-fuzz))
4178                  ?  ;Whitespace
4179                (if (< gnus-tmp-score gnus-summary-default-score)
4180                    gnus-score-below-mark gnus-score-over-mark))
4181              gnus-tmp-replied
4182              (cond ((memq number gnus-newsgroup-processable)
4183                     gnus-process-mark)
4184                    ((memq number gnus-newsgroup-cached)
4185                     gnus-cached-mark)
4186                    ((memq number gnus-newsgroup-replied)
4187                     gnus-replied-mark)
4188                    ((memq number gnus-newsgroup-saved)
4189                     gnus-saved-mark)
4190                    (t gnus-unread-mark))
4191              gnus-tmp-from (mail-header-from gnus-tmp-header)
4192              gnus-tmp-name
4193              (cond
4194               ((string-match "<[^>]+> *$" gnus-tmp-from)
4195                (setq beg-match (match-beginning 0))
4196                (or (and (string-match "^\".+\"" gnus-tmp-from)
4197                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4198                    (substring gnus-tmp-from 0 beg-match)))
4199               ((string-match "(.+)" gnus-tmp-from)
4200                (substring gnus-tmp-from
4201                           (1+ (match-beginning 0)) (1- (match-end 0))))
4202               (t gnus-tmp-from)))
4203             (when (string= gnus-tmp-name "")
4204               (setq gnus-tmp-name gnus-tmp-from))
4205             (unless (numberp gnus-tmp-lines)
4206               (setq gnus-tmp-lines 0))
4207             (gnus-put-text-property
4208              (point)
4209              (progn (eval gnus-summary-line-format-spec) (point))
4210              'gnus-number number)
4211             (when gnus-visual-p
4212               (forward-line -1)
4213               (gnus-run-hooks 'gnus-summary-update-hook)
4214               (forward-line 1))
4215
4216             (setq gnus-tmp-prev-subject subject)))
4217
4218         (when (nth 1 thread)
4219           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
4220         (incf gnus-tmp-level)
4221         (setq threads (if thread-end nil (cdar thread)))
4222         (unless threads
4223           (setq gnus-tmp-level 0)))))
4224   (gnus-message 7 "Generating summary...done"))
4225
4226 (defun gnus-summary-prepare-unthreaded (headers)
4227   "Generate an unthreaded summary buffer based on HEADERS."
4228   (let (header number mark)
4229
4230     (beginning-of-line)
4231
4232     (while headers
4233       ;; We may have to root out some bad articles...
4234       (when (memq (setq number (mail-header-number
4235                                 (setq header (pop headers))))
4236                   gnus-newsgroup-limit)
4237         ;; Mark article as read when it has a low score.
4238         (when (and gnus-summary-mark-below
4239                    (< (or (cdr (assq number gnus-newsgroup-scored))
4240                           gnus-summary-default-score 0)
4241                       gnus-summary-mark-below)
4242                    (not (gnus-summary-article-ancient-p number)))
4243           (setq gnus-newsgroup-unreads
4244                 (delq number gnus-newsgroup-unreads))
4245           (if gnus-newsgroup-auto-expire
4246               (push number gnus-newsgroup-expirable)
4247             (push (cons number gnus-low-score-mark)
4248                   gnus-newsgroup-reads)))
4249
4250         (setq mark (gnus-article-mark number))
4251         (push (gnus-data-make number mark (1+ (point)) header 0)
4252               gnus-newsgroup-data)
4253         (gnus-summary-insert-line
4254          header 0 number
4255          mark (memq number gnus-newsgroup-replied)
4256          (memq number gnus-newsgroup-expirable)
4257          (mail-header-subject header) nil
4258          (cdr (assq number gnus-newsgroup-scored))
4259          (memq number gnus-newsgroup-processable))))))
4260
4261 (defun gnus-summary-remove-list-identifiers ()
4262   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4263   (let ((regexp (if (stringp gnus-list-identifiers)
4264                     gnus-list-identifiers
4265                   (mapconcat 'identity gnus-list-identifiers " *\\|"))))
4266     (dolist (header gnus-newsgroup-headers)
4267       (when (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
4268                                   " *\\)\\)+\\(Re: +\\)?\\)")
4269                           (mail-header-subject header))
4270         (mail-header-set-subject
4271          header (concat (substring (mail-header-subject header)
4272                                    0 (match-beginning 1))
4273                         (or
4274                          (match-string 3 (mail-header-subject header))
4275                          (match-string 5 (mail-header-subject header)))
4276                         (substring (mail-header-subject header)
4277                                    (match-end 1))))))))
4278
4279 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4280   "Select newsgroup GROUP.
4281 If READ-ALL is non-nil, all articles in the group are selected.
4282 If SELECT-ARTICLES, only select those articles from GROUP."
4283   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4284          ;;!!! Dirty hack; should be removed.
4285          (gnus-summary-ignore-duplicates
4286           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4287               t
4288             gnus-summary-ignore-duplicates))
4289          (info (nth 2 entry))
4290          articles fetched-articles cached)
4291
4292     (unless (gnus-check-server
4293              (setq gnus-current-select-method
4294                    (gnus-find-method-for-group group)))
4295       (error "Couldn't open server"))
4296
4297     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4298         (gnus-activate-group group)     ; Or we can activate it...
4299         (progn                          ; Or we bug out.
4300           (when (equal major-mode 'gnus-summary-mode)
4301             (kill-buffer (current-buffer)))
4302           (error "Couldn't activate group %s: %s"
4303                  group (gnus-status-message group))))
4304
4305     (unless (gnus-request-group group t)
4306       (when (equal major-mode 'gnus-summary-mode)
4307         (kill-buffer (current-buffer)))
4308       (error "Couldn't request group %s: %s"
4309              group (gnus-status-message group)))
4310
4311     (setq gnus-newsgroup-name group)
4312     (setq gnus-newsgroup-unselected nil)
4313     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4314     (gnus-summary-setup-default-charset)
4315
4316     ;; Adjust and set lists of article marks.
4317     (when info
4318       (gnus-adjust-marked-articles info))
4319
4320     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4321     (setq cached
4322           (if (gnus-virtual-group-p group)
4323               gnus-newsgroup-cached
4324             (gnus-cache-articles-in-group group)))
4325
4326     (setq gnus-newsgroup-unreads
4327           (gnus-set-difference
4328            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4329            gnus-newsgroup-dormant))
4330
4331     (setq gnus-newsgroup-processable nil)
4332
4333     (gnus-update-read-articles group gnus-newsgroup-unreads)
4334
4335     (if (setq articles select-articles)
4336         (setq gnus-newsgroup-unselected
4337               (gnus-sorted-intersection
4338                gnus-newsgroup-unreads
4339                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4340       (setq articles (gnus-articles-to-read group read-all)))
4341
4342     (cond
4343      ((null articles)
4344       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4345       'quit)
4346      ((eq articles 0) nil)
4347      (t
4348       ;; Init the dependencies hash table.
4349       (setq gnus-newsgroup-dependencies
4350             (gnus-make-hashtable (length articles)))
4351       (gnus-set-global-variables)
4352       ;; Retrieve the headers and read them in.
4353       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4354       (setq gnus-newsgroup-headers
4355             (gnus-retrieve-parsed-headers
4356              articles gnus-newsgroup-name
4357              ;; We might want to fetch old headers, but
4358              ;; not if there is only 1 article.
4359              (and (or (and (not (eq gnus-fetch-old-headers 'some))
4360                            (not (numberp gnus-fetch-old-headers)))
4361                       (> (length articles) 1))
4362                   gnus-fetch-old-headers)))
4363       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4364
4365       ;; Suppress duplicates?
4366       (when gnus-suppress-duplicates
4367         (gnus-dup-suppress-articles))
4368
4369       ;; Set the initial limit.
4370       (setq gnus-newsgroup-limit (copy-sequence articles))
4371       ;; Remove canceled articles from the list of unread articles.
4372       (setq gnus-newsgroup-unreads
4373             (gnus-set-sorted-intersection
4374              gnus-newsgroup-unreads
4375              (setq fetched-articles
4376                    (mapcar (lambda (headers) (mail-header-number headers))
4377                            gnus-newsgroup-headers))))
4378       ;; Removed marked articles that do not exist.
4379       (gnus-update-missing-marks
4380        (gnus-sorted-complement fetched-articles articles))
4381
4382       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4383       (when cached
4384         (setq gnus-newsgroup-cached cached))
4385
4386       ;; We might want to build some more threads first.
4387       (when (and gnus-fetch-old-headers
4388                  (eq gnus-headers-retrieved-by 'nov))
4389         (if (eq gnus-fetch-old-headers 'invisible)
4390             (gnus-build-all-threads)
4391           (gnus-build-old-threads)))
4392       ;; Let the Gnus agent mark articles as read.
4393       (when gnus-agent
4394         (gnus-agent-get-undownloaded-list))
4395       ;; Remove list identifiers from subject
4396       (when gnus-list-identifiers
4397         (gnus-summary-remove-list-identifiers))
4398       ;; Check whether auto-expire is to be done in this group.
4399       (setq gnus-newsgroup-auto-expire
4400             (gnus-group-auto-expirable-p group))
4401       ;; Set up the article buffer now, if necessary.
4402       (unless gnus-single-article-buffer
4403         (gnus-article-setup-buffer))
4404       ;; First and last article in this newsgroup.
4405       (when gnus-newsgroup-headers
4406         (setq gnus-newsgroup-begin
4407               (mail-header-number (car gnus-newsgroup-headers))
4408               gnus-newsgroup-end
4409               (mail-header-number
4410                (gnus-last-element gnus-newsgroup-headers))))
4411       ;; GROUP is successfully selected.
4412       (or gnus-newsgroup-headers t)))))
4413
4414 (defun gnus-articles-to-read (group &optional read-all)
4415   "Find out what articles the user wants to read."
4416   (let* ((articles
4417           ;; Select all articles if `read-all' is non-nil, or if there
4418           ;; are no unread articles.
4419           (if (or read-all
4420                   (and (zerop (length gnus-newsgroup-marked))
4421                        (zerop (length gnus-newsgroup-unreads)))
4422                   (eq (gnus-group-find-parameter group 'display)
4423                       'all))
4424               (or
4425                (gnus-uncompress-range (gnus-active group))
4426                (gnus-cache-articles-in-group group))
4427             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4428                           (copy-sequence gnus-newsgroup-unreads))
4429                   '<)))
4430          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4431          (scored (length scored-list))
4432          (number (length articles))
4433          (marked (+ (length gnus-newsgroup-marked)
4434                     (length gnus-newsgroup-dormant)))
4435          (select
4436           (cond
4437            ((numberp read-all)
4438             read-all)
4439            (t
4440             (condition-case ()
4441                 (cond
4442                  ((and (or (<= scored marked) (= scored number))
4443                        (natnump gnus-large-newsgroup)
4444                        (> number gnus-large-newsgroup))
4445                   (let* ((cursor-in-echo-area nil)
4446                          (input (read-from-minibuffer
4447                                  (format
4448                                   "How many articles from %s (max %d): "
4449                                   (gnus-limit-string gnus-newsgroup-name 35)
4450                                   number)
4451                                  (cons (number-to-string gnus-large-newsgroup)
4452                                        0))))
4453                     (if (string-match "^[ \t]*$" input)
4454                         number
4455                       input)))
4456                  ((and (> scored marked) (< scored number)
4457                        (> (- scored number) 20))
4458                   (let ((input
4459                          (read-string
4460                           (format "%s %s (%d scored, %d total): "
4461                                   "How many articles from"
4462                                   group scored number))))
4463                     (if (string-match "^[ \t]*$" input)
4464                         number input)))
4465                  (t number))
4466               (quit
4467                (message "Quit getting the articles to read")
4468                nil))))))
4469     (setq select (if (stringp select) (string-to-number select) select))
4470     (if (or (null select) (zerop select))
4471         select
4472       (if (and (not (zerop scored)) (<= (abs select) scored))
4473           (progn
4474             (setq articles (sort scored-list '<))
4475             (setq number (length articles)))
4476         (setq articles (copy-sequence articles)))
4477
4478       (when (< (abs select) number)
4479         (if (< select 0)
4480             ;; Select the N oldest articles.
4481             (setcdr (nthcdr (1- (abs select)) articles) nil)
4482           ;; Select the N most recent articles.
4483           (setq articles (nthcdr (- number select) articles))))
4484       (setq gnus-newsgroup-unselected
4485             (gnus-sorted-intersection
4486              gnus-newsgroup-unreads
4487              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4488       (when gnus-alter-articles-to-read-function
4489         (setq gnus-newsgroup-unreads
4490               (sort
4491                (funcall gnus-alter-articles-to-read-function
4492                         gnus-newsgroup-name gnus-newsgroup-unreads)
4493                '<)))
4494       articles)))
4495
4496 (defun gnus-killed-articles (killed articles)
4497   (let (out)
4498     (while articles
4499       (when (inline (gnus-member-of-range (car articles) killed))
4500         (push (car articles) out))
4501       (setq articles (cdr articles)))
4502     out))
4503
4504 (defun gnus-uncompress-marks (marks)
4505   "Uncompress the mark ranges in MARKS."
4506   (let ((uncompressed '(score bookmark))
4507         out)
4508     (while marks
4509       (if (memq (caar marks) uncompressed)
4510           (push (car marks) out)
4511         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4512       (setq marks (cdr marks)))
4513     out))
4514
4515 (defun gnus-adjust-marked-articles (info)
4516   "Set all article lists and remove all marks that are no longer valid."
4517   (let* ((marked-lists (gnus-info-marks info))
4518          (active (gnus-active (gnus-info-group info)))
4519          (min (car active))
4520          (max (cdr active))
4521          (types gnus-article-mark-lists)
4522          (uncompressed '(score bookmark killed))
4523          marks var articles article mark)
4524
4525     (while marked-lists
4526       (setq marks (pop marked-lists))
4527       (set (setq var (intern (format "gnus-newsgroup-%s"
4528                                      (car (rassq (setq mark (car marks))
4529                                                  types)))))
4530            (if (memq (car marks) uncompressed) (cdr marks)
4531              (gnus-uncompress-range (cdr marks))))
4532
4533       (setq articles (symbol-value var))
4534
4535       ;; All articles have to be subsets of the active articles.
4536       (cond
4537        ;; Adjust "simple" lists.
4538        ((memq mark '(tick dormant expire reply save))
4539         (while articles
4540           (when (or (< (setq article (pop articles)) min) (> article max))
4541             (set var (delq article (symbol-value var))))))
4542        ;; Adjust assocs.
4543        ((memq mark uncompressed)
4544         (when (not (listp (cdr (symbol-value var))))
4545           (set var (list (symbol-value var))))
4546         (when (not (listp (cdr articles)))
4547           (setq articles (list articles)))
4548         (while articles
4549           (when (or (not (consp (setq article (pop articles))))
4550                     (< (car article) min)
4551                     (> (car article) max))
4552             (set var (delq article (symbol-value var))))))))))
4553
4554 (defun gnus-update-missing-marks (missing)
4555   "Go through the list of MISSING articles and remove them from the mark lists."
4556   (when missing
4557     (let ((types gnus-article-mark-lists)
4558           var m)
4559       ;; Go through all types.
4560       (while types
4561         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4562         (when (symbol-value var)
4563           ;; This list has articles.  So we delete all missing articles
4564           ;; from it.
4565           (setq m missing)
4566           (while m
4567             (set var (delq (pop m) (symbol-value var)))))))))
4568
4569 (defun gnus-update-marks ()
4570   "Enter the various lists of marked articles into the newsgroup info list."
4571   (let ((types gnus-article-mark-lists)
4572         (info (gnus-get-info gnus-newsgroup-name))
4573         (uncompressed '(score bookmark killed))
4574         type list newmarked symbol delta-marks)
4575     (when info
4576       ;; Add all marks lists to the list of marks lists.
4577       (while (setq type (pop types))
4578         (setq list (symbol-value
4579                     (setq symbol
4580                           (intern (format "gnus-newsgroup-%s"
4581                                           (car type))))))
4582
4583         (when list
4584           ;; Get rid of the entries of the articles that have the
4585           ;; default score.
4586           (when (and (eq (cdr type) 'score)
4587                      gnus-save-score
4588                      list)
4589             (let* ((arts list)
4590                    (prev (cons nil list))
4591                    (all prev))
4592               (while arts
4593                 (if (or (not (consp (car arts)))
4594                         (= (cdar arts) gnus-summary-default-score))
4595                     (setcdr prev (cdr arts))
4596                   (setq prev arts))
4597                 (setq arts (cdr arts)))
4598               (setq list (cdr all)))))
4599
4600         (unless (memq (cdr type) uncompressed)
4601           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4602
4603         (when (gnus-check-backend-function
4604                'request-set-mark gnus-newsgroup-name)
4605           ;; propagate flags to server, with the following exceptions:
4606           ;; uncompressed:s are not proper flags (they are cons cells)
4607           ;; cache is a internal gnus flag
4608           ;; download are local to one gnus installation (well)
4609           ;; unsend are for nndraft groups only
4610           ;; xxx: generality of this?  this suits nnimap anyway
4611           (unless (memq (cdr type) (append '(cache download unsend)
4612                                            uncompressed))
4613             (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4614                    (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4615                    (add (gnus-remove-from-range
4616                          (gnus-copy-sequence list) old)))
4617               (when add
4618                 (push (list add 'add (list (cdr type))) delta-marks))
4619               (when del
4620                 (push (list del 'del (list (cdr type))) delta-marks)))))
4621
4622         (when list
4623           (push (cons (cdr type) list) newmarked)))
4624
4625       (when delta-marks
4626         (unless (gnus-check-group gnus-newsgroup-name)
4627           (error "Can't open server for %s" gnus-newsgroup-name))
4628         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4629
4630       ;; Enter these new marks into the info of the group.
4631       (if (nthcdr 3 info)
4632           (setcar (nthcdr 3 info) newmarked)
4633         ;; Add the marks lists to the end of the info.
4634         (when newmarked
4635           (setcdr (nthcdr 2 info) (list newmarked))))
4636
4637       ;; Cut off the end of the info if there's nothing else there.
4638       (let ((i 5))
4639         (while (and (> i 2)
4640                     (not (nth i info)))
4641           (when (nthcdr (decf i) info)
4642             (setcdr (nthcdr i info) nil)))))))
4643
4644 (defun gnus-set-mode-line (where)
4645   "Set the mode line of the article or summary buffers.
4646 If WHERE is `summary', the summary mode line format will be used."
4647   ;; Is this mode line one we keep updated?
4648   (when (and (memq where gnus-updated-mode-lines)
4649              (symbol-value
4650               (intern (format "gnus-%s-mode-line-format-spec" where))))
4651     (let (mode-string)
4652       (save-excursion
4653         ;; We evaluate this in the summary buffer since these
4654         ;; variables are buffer-local to that buffer.
4655         (set-buffer gnus-summary-buffer)
4656         ;; We bind all these variables that are used in the `eval' form
4657         ;; below.
4658         (let* ((mformat (symbol-value
4659                          (intern
4660                           (format "gnus-%s-mode-line-format-spec" where))))
4661                (gnus-tmp-group-name (gnus-group-name-decode
4662                                      gnus-newsgroup-name
4663                                      (gnus-group-name-charset
4664                                       nil
4665                                       gnus-newsgroup-name)))
4666                (gnus-tmp-article-number (or gnus-current-article 0))
4667                (gnus-tmp-unread gnus-newsgroup-unreads)
4668                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4669                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4670                (gnus-tmp-unread-and-unselected
4671                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4672                             (zerop gnus-tmp-unselected))
4673                        "")
4674                       ((zerop gnus-tmp-unselected)
4675                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4676                       (t (format "{%d(+%d) more}"
4677                                  gnus-tmp-unread-and-unticked
4678                                  gnus-tmp-unselected))))
4679                (gnus-tmp-subject
4680                 (if (and gnus-current-headers
4681                          (vectorp gnus-current-headers))
4682                     (gnus-mode-string-quote
4683                      (mail-header-subject gnus-current-headers))
4684                   ""))
4685                bufname-length max-len
4686                gnus-tmp-header);; passed as argument to any user-format-funcs
4687           (setq mode-string (eval mformat))
4688           (setq bufname-length (if (string-match "%b" mode-string)
4689                                    (- (length
4690                                        (buffer-name
4691                                         (if (eq where 'summary)
4692                                             nil
4693                                           (get-buffer gnus-article-buffer))))
4694                                       2)
4695                                  0))
4696           (setq max-len (max 4 (if gnus-mode-non-string-length
4697                                    (- (window-width)
4698                                       gnus-mode-non-string-length
4699                                       bufname-length)
4700                                  (length mode-string))))
4701           ;; We might have to chop a bit of the string off...
4702           (when (> (length mode-string) max-len)
4703             (setq mode-string
4704                   (concat (gnus-truncate-string mode-string (- max-len 3))
4705                           "...")))
4706           ;; Pad the mode string a bit.
4707           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4708       ;; Update the mode line.
4709       (setq mode-line-buffer-identification
4710             (gnus-mode-line-buffer-identification (list mode-string)))
4711       (set-buffer-modified-p t))))
4712
4713 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4714   "Go through the HEADERS list and add all Xrefs to a hash table.
4715 The resulting hash table is returned, or nil if no Xrefs were found."
4716   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4717          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4718          (xref-hashtb (gnus-make-hashtable))
4719          start group entry number xrefs header)
4720     (while headers
4721       (setq header (pop headers))
4722       (when (and (setq xrefs (mail-header-xref header))
4723                  (not (memq (setq number (mail-header-number header))
4724                             unreads)))
4725         (setq start 0)
4726         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4727           (setq start (match-end 0))
4728           (setq group (if prefix
4729                           (concat prefix (substring xrefs (match-beginning 1)
4730                                                     (match-end 1)))
4731                         (substring xrefs (match-beginning 1) (match-end 1))))
4732           (setq number
4733                 (string-to-int (substring xrefs (match-beginning 2)
4734                                           (match-end 2))))
4735           (if (setq entry (gnus-gethash group xref-hashtb))
4736               (setcdr entry (cons number (cdr entry)))
4737             (gnus-sethash group (cons number nil) xref-hashtb)))))
4738     (and start xref-hashtb)))
4739
4740 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4741   "Look through all the headers and mark the Xrefs as read."
4742   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4743         name entry info xref-hashtb idlist method nth4)
4744     (save-excursion
4745       (set-buffer gnus-group-buffer)
4746       (when (setq xref-hashtb
4747                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4748         (mapatoms
4749          (lambda (group)
4750            (unless (string= from-newsgroup (setq name (symbol-name group)))
4751              (setq idlist (symbol-value group))
4752              ;; Dead groups are not updated.
4753              (and (prog1
4754                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4755                             info (nth 2 entry))
4756                     (when (stringp (setq nth4 (gnus-info-method info)))
4757                       (setq nth4 (gnus-server-to-method nth4))))
4758                   ;; Only do the xrefs if the group has the same
4759                   ;; select method as the group we have just read.
4760                   (or (gnus-methods-equal-p
4761                        nth4 (gnus-find-method-for-group from-newsgroup))
4762                       virtual
4763                       (equal nth4 (setq method (gnus-find-method-for-group
4764                                                 from-newsgroup)))
4765                       (and (equal (car nth4) (car method))
4766                            (equal (nth 1 nth4) (nth 1 method))))
4767                   gnus-use-cross-reference
4768                   (or (not (eq gnus-use-cross-reference t))
4769                       virtual
4770                       ;; Only do cross-references on subscribed
4771                       ;; groups, if that is what is wanted.
4772                       (<= (gnus-info-level info) gnus-level-subscribed))
4773                   (gnus-group-make-articles-read name idlist))))
4774          xref-hashtb)))))
4775
4776 (defun gnus-compute-read-articles (group articles)
4777   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4778          (info (nth 2 entry))
4779          (active (gnus-active group))
4780          ninfo)
4781     (when entry
4782       ;; First peel off all invalid article numbers.
4783       (when active
4784         (let ((ids articles)
4785               id first)
4786           (while (setq id (pop ids))
4787             (when (and first (> id (cdr active)))
4788               ;; We'll end up in this situation in one particular
4789               ;; obscure situation.  If you re-scan a group and get
4790               ;; a new article that is cross-posted to a different
4791               ;; group that has not been re-scanned, you might get
4792               ;; crossposted article that has a higher number than
4793               ;; Gnus believes possible.  So we re-activate this
4794               ;; group as well.  This might mean doing the
4795               ;; crossposting thingy will *increase* the number
4796               ;; of articles in some groups.  Tsk, tsk.
4797               (setq active (or (gnus-activate-group group) active)))
4798             (when (or (> id (cdr active))
4799                       (< id (car active)))
4800               (setq articles (delq id articles))))))
4801       ;; If the read list is nil, we init it.
4802       (if (and active
4803                (null (gnus-info-read info))
4804                (> (car active) 1))
4805           (setq ninfo (cons 1 (1- (car active))))
4806         (setq ninfo (gnus-info-read info)))
4807       ;; Then we add the read articles to the range.
4808       (gnus-add-to-range
4809        ninfo (setq articles (sort articles '<))))))
4810
4811 (defun gnus-group-make-articles-read (group articles)
4812   "Update the info of GROUP to say that ARTICLES are read."
4813   (let* ((num 0)
4814          (entry (gnus-gethash group gnus-newsrc-hashtb))
4815          (info (nth 2 entry))
4816          (active (gnus-active group))
4817          range)
4818     (when entry
4819       (setq range (gnus-compute-read-articles group articles))
4820       (save-excursion
4821         (set-buffer gnus-group-buffer)
4822         (gnus-undo-register
4823           `(progn
4824              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4825              (gnus-info-set-read ',info ',(gnus-info-read info))
4826              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4827              (gnus-group-update-group ,group t))))
4828       ;; Add the read articles to the range.
4829       (gnus-info-set-read info range)
4830       ;; Then we have to re-compute how many unread
4831       ;; articles there are in this group.
4832       (when active
4833         (cond
4834          ((not range)
4835           (setq num (- (1+ (cdr active)) (car active))))
4836          ((not (listp (cdr range)))
4837           (setq num (- (cdr active) (- (1+ (cdr range))
4838                                        (car range)))))
4839          (t
4840           (while range
4841             (if (numberp (car range))
4842                 (setq num (1+ num))
4843               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4844             (setq range (cdr range)))
4845           (setq num (- (cdr active) num))))
4846         ;; Update the number of unread articles.
4847         (setcar entry num)
4848         ;; Update the group buffer.
4849         (gnus-group-update-group group t)))))
4850
4851 (defvar gnus-newsgroup-none-id 0)
4852
4853 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4854   (let ((cur nntp-server-buffer)
4855         (dependencies
4856          (or dependencies
4857              (save-excursion (set-buffer gnus-summary-buffer)
4858                              gnus-newsgroup-dependencies)))
4859         headers id end ref
4860         (mail-parse-charset gnus-newsgroup-charset)
4861         (mail-parse-ignored-charsets
4862          (save-excursion (condition-case nil
4863                              (set-buffer gnus-summary-buffer)
4864                            (error))
4865                          gnus-newsgroup-ignored-charsets)))
4866     (save-excursion
4867       (set-buffer nntp-server-buffer)
4868       ;; Translate all TAB characters into SPACE characters.
4869       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4870       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4871       (gnus-run-hooks 'gnus-parse-headers-hook)
4872       (let ((case-fold-search t)
4873             in-reply-to header p lines chars ctype)
4874         (goto-char (point-min))
4875         ;; Search to the beginning of the next header.  Error messages
4876         ;; do not begin with 2 or 3.
4877         (while (re-search-forward "^[23][0-9]+ " nil t)
4878           (setq id nil
4879                 ref nil)
4880           ;; This implementation of this function, with nine
4881           ;; search-forwards instead of the one re-search-forward and
4882           ;; a case (which basically was the old function) is actually
4883           ;; about twice as fast, even though it looks messier.  You
4884           ;; can't have everything, I guess.  Speed and elegance
4885           ;; doesn't always go hand in hand.
4886           (setq
4887            header
4888            (make-full-mail-header
4889             ;; Number.
4890             (prog1
4891                 (read cur)
4892               (end-of-line)
4893               (setq p (point))
4894               (narrow-to-region (point)
4895                                 (or (and (search-forward "\n.\n" nil t)
4896                                          (- (point) 2))
4897                                     (point))))
4898             ;; Subject.
4899             (progn
4900               (goto-char p)
4901               (if (search-forward "\nsubject: " nil t)
4902                   (nnheader-header-value)
4903                 "(none)"))
4904             ;; From.
4905             (progn
4906               (goto-char p)
4907               (if (or (search-forward "\nfrom: " nil t)
4908                       (search-forward "\nfrom:" nil t))
4909                   (nnheader-header-value)
4910                 "(nobody)"))
4911             ;; Date.
4912             (progn
4913               (goto-char p)
4914               (if (search-forward "\ndate: " nil t)
4915                   (nnheader-header-value)
4916                 ""))
4917             ;; Message-ID.
4918             (progn
4919               (goto-char p)
4920               (setq id (if (re-search-forward
4921                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4922                            ;; We do it this way to make sure the Message-ID
4923                            ;; is (somewhat) syntactically valid.
4924                            (buffer-substring (match-beginning 1)
4925                                              (match-end 1))
4926                          ;; If there was no message-id, we just fake one
4927                          ;; to make subsequent routines simpler.
4928                          (nnheader-generate-fake-message-id))))
4929             ;; References.
4930             (progn
4931               (goto-char p)
4932               (if (search-forward "\nreferences: " nil t)
4933                   (progn
4934                     (setq end (point))
4935                     (prog1
4936                         (nnheader-header-value)
4937                       (setq ref
4938                             (buffer-substring
4939                              (progn
4940                                ;; (end-of-line)
4941                                (search-backward ">" end t)
4942                                (1+ (point)))
4943                              (progn
4944                                (search-backward "<" end t)
4945                                (point))))))
4946                 ;; Get the references from the in-reply-to header if there
4947                 ;; were no references and the in-reply-to header looks
4948                 ;; promising.
4949                 (if (and (search-forward "\nin-reply-to: " nil t)
4950                          (setq in-reply-to (nnheader-header-value))
4951                          (string-match "<[^>]+>" in-reply-to))
4952                     (let (ref2)
4953                       (setq ref (substring in-reply-to (match-beginning 0)
4954                                            (match-end 0)))
4955                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4956                         (setq ref2 (substring in-reply-to (match-beginning 0)
4957                                               (match-end 0)))
4958                         (when (> (length ref2) (length ref))
4959                           (setq ref ref2)))
4960                       ref)
4961                   (setq ref nil))))
4962             ;; Chars.
4963             (progn
4964               (goto-char p)
4965               (if (search-forward "\nchars: " nil t)
4966                   (if (numberp (setq chars (ignore-errors (read cur))))
4967                       chars 0)
4968                 0))
4969             ;; Lines.
4970             (progn
4971               (goto-char p)
4972               (if (search-forward "\nlines: " nil t)
4973                   (if (numberp (setq lines (ignore-errors (read cur))))
4974                       lines 0)
4975                 0))
4976             ;; Xref.
4977             (progn
4978               (goto-char p)
4979               (and (search-forward "\nxref: " nil t)
4980                    (nnheader-header-value)))
4981             ;; Extra.
4982             (when gnus-extra-headers
4983               (let ((extra gnus-extra-headers)
4984                     out)
4985                 (while extra
4986                   (goto-char p)
4987                   (when (search-forward
4988                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
4989                     (push (cons (car extra) (nnheader-header-value)) out))
4990                   (pop extra))
4991                 out))))
4992           (goto-char p)
4993           (if (and (search-forward "\ncontent-type: " nil t)
4994                    (setq ctype (nnheader-header-value)))
4995               (mime-entity-set-content-type-internal
4996                header (mime-parse-Content-Type ctype)))
4997           (when (equal id ref)
4998             (setq ref nil))
4999
5000           (when gnus-alter-header-function
5001             (funcall gnus-alter-header-function header)
5002             (setq id (mail-header-id header)
5003                   ref (gnus-parent-id (mail-header-references header))))
5004
5005           (when (setq header
5006                       (gnus-dependencies-add-header
5007                        header dependencies force-new))
5008             (push header headers))
5009           (goto-char (point-max))
5010           (widen))
5011         (nreverse headers)))))
5012
5013 ;; Goes through the xover lines and returns a list of vectors
5014 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5015                                                   force-new dependencies
5016                                                   group also-fetch-heads)
5017   "Parse the news overview data in the server buffer.
5018 Return a list of headers that match SEQUENCE (see
5019 `nntp-retrieve-headers')."
5020   ;; Get the Xref when the users reads the articles since most/some
5021   ;; NNTP servers do not include Xrefs when using XOVER.
5022   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5023   (let ((mail-parse-charset gnus-newsgroup-charset)
5024         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5025         (cur nntp-server-buffer)
5026         (dependencies (or dependencies gnus-newsgroup-dependencies))
5027         number headers header)
5028     (save-excursion
5029       (set-buffer nntp-server-buffer)
5030       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5031       ;; Allow the user to mangle the headers before parsing them.
5032       (gnus-run-hooks 'gnus-parse-headers-hook)
5033       (goto-char (point-min))
5034       (while (not (eobp))
5035         (condition-case ()
5036             (while (and sequence (not (eobp)))
5037               (setq number (read cur))
5038               (while (and sequence
5039                           (< (car sequence) number))
5040                 (setq sequence (cdr sequence)))
5041               (and sequence
5042                    (eq number (car sequence))
5043                    (progn
5044                      (setq sequence (cdr sequence))
5045                      (setq header (inline
5046                                     (gnus-nov-parse-line
5047                                      number dependencies force-new))))
5048                    (push header headers))
5049               (forward-line 1))
5050           (error
5051            (gnus-error 4 "Strange nov line (%d)"
5052                        (count-lines (point-min) (point)))))
5053         (forward-line 1))
5054       ;; A common bug in inn is that if you have posted an article and
5055       ;; then retrieves the active file, it will answer correctly --
5056       ;; the new article is included.  However, a NOV entry for the
5057       ;; article may not have been generated yet, so this may fail.
5058       ;; We work around this problem by retrieving the last few
5059       ;; headers using HEAD.
5060       (if (or (not also-fetch-heads)
5061               (not sequence))
5062           ;; We (probably) got all the headers.
5063           (nreverse headers)
5064         (let ((gnus-nov-is-evil t))
5065           (nconc
5066            (nreverse headers)
5067            (gnus-retrieve-parsed-headers sequence group)
5068            ))))))
5069
5070 (defun gnus-article-get-xrefs ()
5071   "Fill in the Xref value in `gnus-current-headers', if necessary.
5072 This is meant to be called in `gnus-article-internal-prepare-hook'."
5073   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5074                                  gnus-current-headers)))
5075     (or (not gnus-use-cross-reference)
5076         (not headers)
5077         (and (mail-header-xref headers)
5078              (not (string= (mail-header-xref headers) "")))
5079         (let ((case-fold-search t)
5080               xref)
5081           (save-restriction
5082             (nnheader-narrow-to-headers)
5083             (goto-char (point-min))
5084             (when (or (and (not (eobp))
5085                            (eq (downcase (char-after)) ?x)
5086                            (looking-at "Xref:"))
5087                       (search-forward "\nXref:" nil t))
5088               (goto-char (1+ (match-end 0)))
5089               (setq xref (buffer-substring (point)
5090                                            (progn (end-of-line) (point))))
5091               (mail-header-set-xref headers xref)))))))
5092
5093 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5094   "Find article ID and insert the summary line for that article.
5095 OLD-HEADER can either be a header or a line number to insert
5096 the subject line on."
5097   (let* ((line (and (numberp old-header) old-header))
5098          (old-header (and (vectorp old-header) old-header))
5099          (header (cond ((and old-header use-old-header)
5100                         old-header)
5101                        ((and (numberp id)
5102                              (gnus-number-to-header id))
5103                         (gnus-number-to-header id))
5104                        (t
5105                         (gnus-read-header id))))
5106          (number (and (numberp id) id))
5107          d)
5108     (when header
5109       ;; Rebuild the thread that this article is part of and go to the
5110       ;; article we have fetched.
5111       (when (and (not gnus-show-threads)
5112                  old-header)
5113         (when (and number
5114                    (setq d (gnus-data-find (mail-header-number old-header))))
5115           (goto-char (gnus-data-pos d))
5116           (gnus-data-remove
5117            number
5118            (- (gnus-point-at-bol)
5119               (prog1
5120                   (1+ (gnus-point-at-eol))
5121                 (gnus-delete-line))))))
5122       (when old-header
5123         (mail-header-set-number header (mail-header-number old-header)))
5124       (setq gnus-newsgroup-sparse
5125             (delq (setq number (mail-header-number header))
5126                   gnus-newsgroup-sparse))
5127       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5128       (push number gnus-newsgroup-limit)
5129       (gnus-rebuild-thread (mail-header-id header) line)
5130       (gnus-summary-goto-subject number nil t))
5131     (when (and (numberp number)
5132                (> number 0))
5133       ;; We have to update the boundaries even if we can't fetch the
5134       ;; article if ID is a number -- so that the next `P' or `N'
5135       ;; command will fetch the previous (or next) article even
5136       ;; if the one we tried to fetch this time has been canceled.
5137       (when (> number gnus-newsgroup-end)
5138         (setq gnus-newsgroup-end number))
5139       (when (< number gnus-newsgroup-begin)
5140         (setq gnus-newsgroup-begin number))
5141       (setq gnus-newsgroup-unselected
5142             (delq number gnus-newsgroup-unselected)))
5143     ;; Report back a success?
5144     (and header (mail-header-number header))))
5145
5146 ;;; Process/prefix in the summary buffer
5147
5148 (defun gnus-summary-work-articles (n)
5149   "Return a list of articles to be worked upon.
5150 The prefix argument, the list of process marked articles, and the
5151 current article will be taken into consideration."
5152   (save-excursion
5153     (set-buffer gnus-summary-buffer)
5154     (cond
5155      (n
5156       ;; A numerical prefix has been given.
5157       (setq n (prefix-numeric-value n))
5158       (let ((backward (< n 0))
5159             (n (abs (prefix-numeric-value n)))
5160             articles article)
5161         (save-excursion
5162           (while
5163               (and (> n 0)
5164                    (push (setq article (gnus-summary-article-number))
5165                          articles)
5166                    (if backward
5167                        (gnus-summary-find-prev nil article)
5168                      (gnus-summary-find-next nil article)))
5169             (decf n)))
5170         (nreverse articles)))
5171      ((and (gnus-region-active-p) (mark))
5172       (message "region active")
5173       ;; Work on the region between point and mark.
5174       (let ((max (max (point) (mark)))
5175             articles article)
5176         (save-excursion
5177           (goto-char (min (point) (mark)))
5178           (while
5179               (and
5180                (push (setq article (gnus-summary-article-number)) articles)
5181                (gnus-summary-find-next nil article)
5182                (< (point) max)))
5183           (nreverse articles))))
5184      (gnus-newsgroup-processable
5185       ;; There are process-marked articles present.
5186       ;; Save current state.
5187       (gnus-summary-save-process-mark)
5188       ;; Return the list.
5189       (reverse gnus-newsgroup-processable))
5190      (t
5191       ;; Just return the current article.
5192       (list (gnus-summary-article-number))))))
5193
5194 (defmacro gnus-summary-iterate (arg &rest forms)
5195   "Iterate over the process/prefixed articles and do FORMS.
5196 ARG is the interactive prefix given to the command.  FORMS will be
5197 executed with point over the summary line of the articles."
5198   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5199     `(let ((,articles (gnus-summary-work-articles ,arg)))
5200        (while ,articles
5201          (gnus-summary-goto-subject (car ,articles))
5202          ,@forms
5203          (pop ,articles)))))
5204
5205 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5206 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5207
5208 (defun gnus-summary-save-process-mark ()
5209   "Push the current set of process marked articles on the stack."
5210   (interactive)
5211   (push (copy-sequence gnus-newsgroup-processable)
5212         gnus-newsgroup-process-stack))
5213
5214 (defun gnus-summary-kill-process-mark ()
5215   "Push the current set of process marked articles on the stack and unmark."
5216   (interactive)
5217   (gnus-summary-save-process-mark)
5218   (gnus-summary-unmark-all-processable))
5219
5220 (defun gnus-summary-yank-process-mark ()
5221   "Pop the last process mark state off the stack and restore it."
5222   (interactive)
5223   (unless gnus-newsgroup-process-stack
5224     (error "Empty mark stack"))
5225   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5226
5227 (defun gnus-summary-process-mark-set (set)
5228   "Make SET into the current process marked articles."
5229   (gnus-summary-unmark-all-processable)
5230   (while set
5231     (gnus-summary-set-process-mark (pop set))))
5232
5233 ;;; Searching and stuff
5234
5235 (defun gnus-summary-search-group (&optional backward use-level)
5236   "Search for next unread newsgroup.
5237 If optional argument BACKWARD is non-nil, search backward instead."
5238   (save-excursion
5239     (set-buffer gnus-group-buffer)
5240     (when (gnus-group-search-forward
5241            backward nil (if use-level (gnus-group-group-level) nil))
5242       (gnus-group-group-name))))
5243
5244 (defun gnus-summary-best-group (&optional exclude-group)
5245   "Find the name of the best unread group.
5246 If EXCLUDE-GROUP, do not go to this group."
5247   (save-excursion
5248     (set-buffer gnus-group-buffer)
5249     (save-excursion
5250       (gnus-group-best-unread-group exclude-group))))
5251
5252 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5253   (if backward (gnus-summary-find-prev)
5254     (let* ((dummy (gnus-summary-article-intangible-p))
5255            (article (or article (gnus-summary-article-number)))
5256            (arts (gnus-data-find-list article))
5257            result)
5258       (when (and (not dummy)
5259                  (or (not gnus-summary-check-current)
5260                      (not unread)
5261                      (not (gnus-data-unread-p (car arts)))))
5262         (setq arts (cdr arts)))
5263       (when (setq result
5264                   (if unread
5265                       (progn
5266                         (while arts
5267                           (when (or (and undownloaded
5268                                          (eq gnus-undownloaded-mark
5269                                              (gnus-data-mark (car arts))))
5270                                     (gnus-data-unread-p (car arts)))
5271                             (setq result (car arts)
5272                                   arts nil))
5273                           (setq arts (cdr arts)))
5274                         result)
5275                     (car arts)))
5276         (goto-char (gnus-data-pos result))
5277         (gnus-data-number result)))))
5278
5279 (defun gnus-summary-find-prev (&optional unread article)
5280   (let* ((eobp (eobp))
5281          (article (or article (gnus-summary-article-number)))
5282          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5283          result)
5284     (when (and (not eobp)
5285                (or (not gnus-summary-check-current)
5286                    (not unread)
5287                    (not (gnus-data-unread-p (car arts)))))
5288       (setq arts (cdr arts)))
5289     (when (setq result
5290                 (if unread
5291                     (progn
5292                       (while arts
5293                         (when (gnus-data-unread-p (car arts))
5294                           (setq result (car arts)
5295                                 arts nil))
5296                         (setq arts (cdr arts)))
5297                       result)
5298                   (car arts)))
5299       (goto-char (gnus-data-pos result))
5300       (gnus-data-number result))))
5301
5302 (defun gnus-summary-find-subject (subject &optional unread backward article)
5303   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5304          (article (or article (gnus-summary-article-number)))
5305          (articles (gnus-data-list backward))
5306          (arts (gnus-data-find-list article articles))
5307          result)
5308     (when (or (not gnus-summary-check-current)
5309               (not unread)
5310               (not (gnus-data-unread-p (car arts))))
5311       (setq arts (cdr arts)))
5312     (while arts
5313       (and (or (not unread)
5314                (gnus-data-unread-p (car arts)))
5315            (vectorp (gnus-data-header (car arts)))
5316            (gnus-subject-equal
5317             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5318            (setq result (car arts)
5319                  arts nil))
5320       (setq arts (cdr arts)))
5321     (and result
5322          (goto-char (gnus-data-pos result))
5323          (gnus-data-number result))))
5324
5325 (defun gnus-summary-search-forward (&optional unread subject backward)
5326   "Search forward for an article.
5327 If UNREAD, look for unread articles.  If SUBJECT, look for
5328 articles with that subject.  If BACKWARD, search backward instead."
5329   (cond (subject (gnus-summary-find-subject subject unread backward))
5330         (backward (gnus-summary-find-prev unread))
5331         (t (gnus-summary-find-next unread))))
5332
5333 (defun gnus-recenter (&optional n)
5334   "Center point in window and redisplay frame.
5335 Also do horizontal recentering."
5336   (interactive "P")
5337   (when (and gnus-auto-center-summary
5338              (not (eq gnus-auto-center-summary 'vertical)))
5339     (gnus-horizontal-recenter))
5340   (recenter n))
5341
5342 (defun gnus-summary-recenter ()
5343   "Center point in the summary window.
5344 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5345 displayed, no centering will be performed."
5346   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5347   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5348   (interactive)
5349   (let* ((top (cond ((< (window-height) 4) 0)
5350                     ((< (window-height) 7) 1)
5351                     (t (if (numberp gnus-auto-center-summary)
5352                            gnus-auto-center-summary
5353                          2))))
5354          (height (1- (window-height)))
5355          (bottom (save-excursion (goto-char (point-max))
5356                                  (forward-line (- height))
5357                                  (point)))
5358          (window (get-buffer-window (current-buffer))))
5359     ;; The user has to want it.
5360     (when gnus-auto-center-summary
5361       (when (get-buffer-window gnus-article-buffer)
5362         ;; Only do recentering when the article buffer is displayed,
5363         ;; Set the window start to either `bottom', which is the biggest
5364         ;; possible valid number, or the second line from the top,
5365         ;; whichever is the least.
5366         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5367           (if (> bottom top-pos)
5368               ;; Keep the second line from the top visible
5369               (set-window-start window top-pos t)
5370             ;; Try to keep the bottom line visible; if it's partially
5371             ;; obscured, either scroll one more line to make it fully
5372             ;; visible, or revert to using TOP-POS.
5373             (save-excursion
5374               (goto-char (point-max))
5375               (forward-line -1)
5376               (let ((last-line-start (point)))
5377                 (goto-char bottom)
5378                 (set-window-start window (point) t)
5379                 (when (not (pos-visible-in-window-p last-line-start window))
5380                   (forward-line 1)
5381                   (set-window-start window (min (point) top-pos) t)))))))
5382       ;; Do horizontal recentering while we're at it.
5383       (when (and (get-buffer-window (current-buffer) t)
5384                  (not (eq gnus-auto-center-summary 'vertical)))
5385         (let ((selected (selected-window)))
5386           (select-window (get-buffer-window (current-buffer) t))
5387           (gnus-summary-position-point)
5388           (gnus-horizontal-recenter)
5389           (select-window selected))))))
5390
5391 (defun gnus-summary-jump-to-group (newsgroup)
5392   "Move point to NEWSGROUP in group mode buffer."
5393   ;; Keep update point of group mode buffer if visible.
5394   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5395       (save-window-excursion
5396         ;; Take care of tree window mode.
5397         (when (get-buffer-window gnus-group-buffer)
5398           (pop-to-buffer gnus-group-buffer))
5399         (gnus-group-jump-to-group newsgroup))
5400     (save-excursion
5401       ;; Take care of tree window mode.
5402       (if (get-buffer-window gnus-group-buffer)
5403           (pop-to-buffer gnus-group-buffer)
5404         (set-buffer gnus-group-buffer))
5405       (gnus-group-jump-to-group newsgroup))))
5406
5407 ;; This function returns a list of article numbers based on the
5408 ;; difference between the ranges of read articles in this group and
5409 ;; the range of active articles.
5410 (defun gnus-list-of-unread-articles (group)
5411   (let* ((read (gnus-info-read (gnus-get-info group)))
5412          (active (or (gnus-active group) (gnus-activate-group group)))
5413          (last (cdr active))
5414          first nlast unread)
5415     ;; If none are read, then all are unread.
5416     (if (not read)
5417         (setq first (car active))
5418       ;; If the range of read articles is a single range, then the
5419       ;; first unread article is the article after the last read
5420       ;; article.  Sounds logical, doesn't it?
5421       (if (and (not (listp (cdr read)))
5422                (or (< (car read) (car active))
5423                    (progn (setq read (list read))
5424                           nil)))
5425           (setq first (max (car active) (1+ (cdr read))))
5426         ;; `read' is a list of ranges.
5427         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5428                                   (caar read)))
5429                   1)
5430           (setq first (car active)))
5431         (while read
5432           (when first
5433             (while (< first nlast)
5434               (push first unread)
5435               (setq first (1+ first))))
5436           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5437           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5438           (setq read (cdr read)))))
5439     ;; And add the last unread articles.
5440     (while (<= first last)
5441       (push first unread)
5442       (setq first (1+ first)))
5443     ;; Return the list of unread articles.
5444     (delq 0 (nreverse unread))))
5445
5446 (defun gnus-list-of-read-articles (group)
5447   "Return a list of unread, unticked and non-dormant articles."
5448   (let* ((info (gnus-get-info group))
5449          (marked (gnus-info-marks info))
5450          (active (gnus-active group)))
5451     (and info active
5452          (gnus-set-difference
5453           (gnus-sorted-complement
5454            (gnus-uncompress-range active)
5455            (gnus-list-of-unread-articles group))
5456           (append
5457            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5458            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5459
5460 ;; Various summary commands
5461
5462 (defun gnus-summary-select-article-buffer ()
5463   "Reconfigure windows to show article buffer."
5464   (interactive)
5465   (if (not (gnus-buffer-live-p gnus-article-buffer))
5466       (error "There is no article buffer for this summary buffer")
5467     (gnus-configure-windows 'article)
5468     (select-window (get-buffer-window gnus-article-buffer))))
5469
5470 (defun gnus-summary-universal-argument (arg)
5471   "Perform any operation on all articles that are process/prefixed."
5472   (interactive "P")
5473   (let ((articles (gnus-summary-work-articles arg))
5474         func article)
5475     (if (eq
5476          (setq
5477           func
5478           (key-binding
5479            (read-key-sequence
5480             (substitute-command-keys
5481              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5482          'undefined)
5483         (gnus-error 1 "Undefined key")
5484       (save-excursion
5485         (while articles
5486           (gnus-summary-goto-subject (setq article (pop articles)))
5487           (let (gnus-newsgroup-processable)
5488             (command-execute func))
5489           (gnus-summary-remove-process-mark article)))))
5490   (gnus-summary-position-point))
5491
5492 (defun gnus-summary-toggle-truncation (&optional arg)
5493   "Toggle truncation of summary lines.
5494 With arg, turn line truncation on iff arg is positive."
5495   (interactive "P")
5496   (setq truncate-lines
5497         (if (null arg) (not truncate-lines)
5498           (> (prefix-numeric-value arg) 0)))
5499   (redraw-display))
5500
5501 (defun gnus-summary-reselect-current-group (&optional all rescan)
5502   "Exit and then reselect the current newsgroup.
5503 The prefix argument ALL means to select all articles."
5504   (interactive "P")
5505   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5506     (error "Ephemeral groups can't be reselected"))
5507   (let ((current-subject (gnus-summary-article-number))
5508         (group gnus-newsgroup-name))
5509     (setq gnus-newsgroup-begin nil)
5510     (gnus-summary-exit)
5511     ;; We have to adjust the point of group mode buffer because
5512     ;; point was moved to the next unread newsgroup by exiting.
5513     (gnus-summary-jump-to-group group)
5514     (when rescan
5515       (save-excursion
5516         (save-window-excursion
5517           ;; Don't show group contents.
5518           (set-window-start (selected-window) (point-max))
5519           (gnus-group-get-new-news-this-group 1))))
5520     (gnus-group-read-group all t)
5521     (gnus-summary-goto-subject current-subject nil t)))
5522
5523 (defun gnus-summary-rescan-group (&optional all)
5524   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5525   (interactive "P")
5526   (gnus-summary-reselect-current-group all t))
5527
5528 (defun gnus-summary-update-info (&optional non-destructive)
5529   (save-excursion
5530     (let ((group gnus-newsgroup-name))
5531       (when group
5532         (when gnus-newsgroup-kill-headers
5533           (setq gnus-newsgroup-killed
5534                 (gnus-compress-sequence
5535                  (nconc
5536                   (gnus-set-sorted-intersection
5537                    (gnus-uncompress-range gnus-newsgroup-killed)
5538                    (setq gnus-newsgroup-unselected
5539                          (sort gnus-newsgroup-unselected '<)))
5540                   (setq gnus-newsgroup-unreads
5541                         (sort gnus-newsgroup-unreads '<)))
5542                  t)))
5543         (unless (listp (cdr gnus-newsgroup-killed))
5544           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5545         (let ((headers gnus-newsgroup-headers))
5546           ;; Set the new ranges of read articles.
5547           (save-excursion
5548             (set-buffer gnus-group-buffer)
5549             (gnus-undo-force-boundary))
5550           (gnus-update-read-articles
5551            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5552           ;; Set the current article marks.
5553           (let ((gnus-newsgroup-scored
5554                  (if (and (not gnus-save-score)
5555                           (not non-destructive))
5556                      nil
5557                    gnus-newsgroup-scored)))
5558             (save-excursion
5559               (gnus-update-marks)))
5560           ;; Do the cross-ref thing.
5561           (when gnus-use-cross-reference
5562             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5563           ;; Do not switch windows but change the buffer to work.
5564           (set-buffer gnus-group-buffer)
5565           (unless (gnus-ephemeral-group-p group)
5566             (gnus-group-update-group group)))))))
5567
5568 (defun gnus-summary-save-newsrc (&optional force)
5569   "Save the current number of read/marked articles in the dribble buffer.
5570 The dribble buffer will then be saved.
5571 If FORCE (the prefix), also save the .newsrc file(s)."
5572   (interactive "P")
5573   (gnus-summary-update-info t)
5574   (if force
5575       (gnus-save-newsrc-file)
5576     (gnus-dribble-save)))
5577
5578 (defun gnus-summary-exit (&optional temporary)
5579   "Exit reading current newsgroup, and then return to group selection mode.
5580 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5581   (interactive)
5582   (gnus-set-global-variables)
5583   (gnus-kill-save-kill-buffer)
5584   (gnus-async-halt-prefetch)
5585   (let* ((group gnus-newsgroup-name)
5586          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5587          (mode major-mode)
5588          (group-point nil)
5589          (buf (current-buffer)))
5590     (unless quit-config
5591       ;; Do adaptive scoring, and possibly save score files.
5592       (when gnus-newsgroup-adaptive
5593         (gnus-score-adaptive))
5594       (when gnus-use-scoring
5595         (gnus-score-save)))
5596     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5597     ;; If we have several article buffers, we kill them at exit.
5598     (unless gnus-single-article-buffer
5599       (gnus-kill-buffer gnus-original-article-buffer)
5600       (setq gnus-article-current nil))
5601     (when gnus-use-cache
5602       (gnus-cache-possibly-remove-articles)
5603       (gnus-cache-save-buffers))
5604     (gnus-async-prefetch-remove-group group)
5605     (when gnus-suppress-duplicates
5606       (gnus-dup-enter-articles))
5607     (when gnus-use-trees
5608       (gnus-tree-close group))
5609     (when gnus-use-cache
5610       (gnus-cache-write-active))
5611     ;; Remove entries for this group.
5612     (nnmail-purge-split-history (gnus-group-real-name group))
5613     ;; Make all changes in this group permanent.
5614     (unless quit-config
5615       (gnus-run-hooks 'gnus-exit-group-hook)
5616       (gnus-summary-update-info))
5617     (gnus-close-group group)
5618     ;; Make sure where we were, and go to next newsgroup.
5619     (set-buffer gnus-group-buffer)
5620     (unless quit-config
5621       (gnus-group-jump-to-group group))
5622     (gnus-run-hooks 'gnus-summary-exit-hook)
5623     (unless (or quit-config
5624                 ;; If this group has disappeared from the summary
5625                 ;; buffer, don't skip forwards.
5626                 (not (string= group (gnus-group-group-name))))
5627       (gnus-group-next-unread-group 1))
5628     (setq group-point (point))
5629     (if temporary
5630         nil                             ;Nothing to do.
5631       ;; If we have several article buffers, we kill them at exit.
5632       (unless gnus-single-article-buffer
5633         (gnus-kill-buffer gnus-article-buffer)
5634         (gnus-kill-buffer gnus-original-article-buffer)
5635         (setq gnus-article-current nil))
5636       (set-buffer buf)
5637       (if (not gnus-kill-summary-on-exit)
5638           (gnus-deaden-summary)
5639         ;; We set all buffer-local variables to nil.  It is unclear why
5640         ;; this is needed, but if we don't, buffer-local variables are
5641         ;; not garbage-collected, it seems.  This would the lead to en
5642         ;; ever-growing Emacs.
5643         (gnus-summary-clear-local-variables)
5644         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5645           (gnus-summary-clear-local-variables))
5646         (when (get-buffer gnus-article-buffer)
5647           (bury-buffer gnus-article-buffer))
5648         ;; We clear the global counterparts of the buffer-local
5649         ;; variables as well, just to be on the safe side.
5650         (set-buffer gnus-group-buffer)
5651         (gnus-summary-clear-local-variables)
5652         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5653           (gnus-summary-clear-local-variables))
5654         ;; Return to group mode buffer.
5655         (when (eq mode 'gnus-summary-mode)
5656           (gnus-kill-buffer buf)))
5657       (setq gnus-current-select-method gnus-select-method)
5658       (pop-to-buffer gnus-group-buffer)
5659       (if (not quit-config)
5660           (progn
5661             (goto-char group-point)
5662             (gnus-configure-windows 'group 'force)
5663             (unless (pos-visible-in-window-p)
5664               (forward-line (/ (static-if (featurep 'xemacs)
5665                                    (window-displayed-height)
5666                                  (1- (window-height)))
5667                                -2))
5668               (set-window-start (selected-window) (point))
5669               (goto-char group-point)))
5670         (gnus-handle-ephemeral-exit quit-config))
5671       ;; Clear the current group name.
5672       (unless quit-config
5673         (setq gnus-newsgroup-name nil)))))
5674
5675 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5676 (defun gnus-summary-exit-no-update (&optional no-questions)
5677   "Quit reading current newsgroup without updating read article info."
5678   (interactive)
5679   (let* ((group gnus-newsgroup-name)
5680          (quit-config (gnus-group-quit-config group)))
5681     (when (or no-questions
5682               gnus-expert-user
5683               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5684       (gnus-async-halt-prefetch)
5685       (mapcar 'funcall
5686               (delq 'gnus-summary-expire-articles
5687                     (copy-sequence gnus-summary-prepare-exit-hook)))
5688       ;; If we have several article buffers, we kill them at exit.
5689       (unless gnus-single-article-buffer
5690         (gnus-kill-buffer gnus-article-buffer)
5691         (gnus-kill-buffer gnus-original-article-buffer)
5692         (setq gnus-article-current nil))
5693       (if (not gnus-kill-summary-on-exit)
5694           (gnus-deaden-summary)
5695         (gnus-close-group group)
5696         (gnus-summary-clear-local-variables)
5697         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5698           (gnus-summary-clear-local-variables))
5699         (set-buffer gnus-group-buffer)
5700         (gnus-summary-clear-local-variables)
5701         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5702           (gnus-summary-clear-local-variables))
5703         (when (get-buffer gnus-summary-buffer)
5704           (kill-buffer gnus-summary-buffer)))
5705       (unless gnus-single-article-buffer
5706         (setq gnus-article-current nil))
5707       (when gnus-use-trees
5708         (gnus-tree-close group))
5709       (gnus-async-prefetch-remove-group group)
5710       (when (get-buffer gnus-article-buffer)
5711         (bury-buffer gnus-article-buffer))
5712       ;; Return to the group buffer.
5713       (gnus-configure-windows 'group 'force)
5714       ;; Clear the current group name.
5715       (setq gnus-newsgroup-name nil)
5716       (when (equal (gnus-group-group-name) group)
5717         (gnus-group-next-unread-group 1))
5718       (when quit-config
5719         (gnus-handle-ephemeral-exit quit-config)))))
5720
5721 (defun gnus-handle-ephemeral-exit (quit-config)
5722   "Handle movement when leaving an ephemeral group.
5723 The state which existed when entering the ephemeral is reset."
5724   (if (not (buffer-name (car quit-config)))
5725       (gnus-configure-windows 'group 'force)
5726     (set-buffer (car quit-config))
5727     (cond ((eq major-mode 'gnus-summary-mode)
5728            (gnus-set-global-variables))
5729           ((eq major-mode 'gnus-article-mode)
5730            (save-excursion
5731              ;; The `gnus-summary-buffer' variable may point
5732              ;; to the old summary buffer when using a single
5733              ;; article buffer.
5734              (unless (gnus-buffer-live-p gnus-summary-buffer)
5735                (set-buffer gnus-group-buffer))
5736              (set-buffer gnus-summary-buffer)
5737              (gnus-set-global-variables))))
5738     (if (or (eq (cdr quit-config) 'article)
5739             (eq (cdr quit-config) 'pick))
5740         (progn
5741           ;; The current article may be from the ephemeral group
5742           ;; thus it is best that we reload this article
5743           (gnus-summary-show-article)
5744           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5745               (gnus-configure-windows 'pick 'force)
5746             (gnus-configure-windows (cdr quit-config) 'force)))
5747       (gnus-configure-windows (cdr quit-config) 'force))
5748     (when (eq major-mode 'gnus-summary-mode)
5749       (gnus-summary-next-subject 1 nil t)
5750       (gnus-summary-recenter)
5751       (gnus-summary-position-point))))
5752
5753 (defun gnus-summary-preview-mime-message ()
5754   "MIME decode and play this message."
5755   (interactive)
5756   (let ((gnus-break-pages nil)
5757         (gnus-show-mime t))
5758     (gnus-summary-select-article gnus-show-all-headers t))
5759   (select-window (get-buffer-window gnus-article-buffer)))
5760
5761 ;;; Dead summaries.
5762
5763 (defvar gnus-dead-summary-mode-map nil)
5764
5765 (unless gnus-dead-summary-mode-map
5766   (setq gnus-dead-summary-mode-map (make-keymap))
5767   (suppress-keymap gnus-dead-summary-mode-map)
5768   (substitute-key-definition
5769    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5770   (let ((keys '("\C-d" "\r" "\177" [delete])))
5771     (while keys
5772       (define-key gnus-dead-summary-mode-map
5773         (pop keys) 'gnus-summary-wake-up-the-dead))))
5774
5775 (defvar gnus-dead-summary-mode nil
5776   "Minor mode for Gnus summary buffers.")
5777
5778 (defun gnus-dead-summary-mode (&optional arg)
5779   "Minor mode for Gnus summary buffers."
5780   (interactive "P")
5781   (when (eq major-mode 'gnus-summary-mode)
5782     (make-local-variable 'gnus-dead-summary-mode)
5783     (setq gnus-dead-summary-mode
5784           (if (null arg) (not gnus-dead-summary-mode)
5785             (> (prefix-numeric-value arg) 0)))
5786     (when gnus-dead-summary-mode
5787       (gnus-add-minor-mode
5788        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5789
5790 (defun gnus-deaden-summary ()
5791   "Make the current summary buffer into a dead summary buffer."
5792   ;; Kill any previous dead summary buffer.
5793   (when (and gnus-dead-summary
5794              (buffer-name gnus-dead-summary))
5795     (save-excursion
5796       (set-buffer gnus-dead-summary)
5797       (when gnus-dead-summary-mode
5798         (kill-buffer (current-buffer)))))
5799   ;; Make this the current dead summary.
5800   (setq gnus-dead-summary (current-buffer))
5801   (gnus-dead-summary-mode 1)
5802   (let ((name (buffer-name)))
5803     (when (string-match "Summary" name)
5804       (rename-buffer
5805        (concat (substring name 0 (match-beginning 0)) "Dead "
5806                (substring name (match-beginning 0)))
5807        t)
5808       (bury-buffer))))
5809
5810 (defun gnus-kill-or-deaden-summary (buffer)
5811   "Kill or deaden the summary BUFFER."
5812   (save-excursion
5813     (when (and (buffer-name buffer)
5814                (not gnus-single-article-buffer))
5815       (save-excursion
5816         (set-buffer buffer)
5817         (gnus-kill-buffer gnus-article-buffer)
5818         (gnus-kill-buffer gnus-original-article-buffer)))
5819     (cond (gnus-kill-summary-on-exit
5820            (when (and gnus-use-trees
5821                       (gnus-buffer-exists-p buffer))
5822              (save-excursion
5823                (set-buffer buffer)
5824                (gnus-tree-close gnus-newsgroup-name)))
5825            (gnus-kill-buffer buffer))
5826           ((gnus-buffer-exists-p buffer)
5827            (save-excursion
5828              (set-buffer buffer)
5829              (gnus-deaden-summary))))))
5830
5831 (defun gnus-summary-wake-up-the-dead (&rest args)
5832   "Wake up the dead summary buffer."
5833   (interactive)
5834   (gnus-dead-summary-mode -1)
5835   (let ((name (buffer-name)))
5836     (when (string-match "Dead " name)
5837       (rename-buffer
5838        (concat (substring name 0 (match-beginning 0))
5839                (substring name (match-end 0)))
5840        t)))
5841   (gnus-message 3 "This dead summary is now alive again"))
5842
5843 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5844 (defun gnus-summary-fetch-faq (&optional faq-dir)
5845   "Fetch the FAQ for the current group.
5846 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5847 in."
5848   (interactive
5849    (list
5850     (when current-prefix-arg
5851       (completing-read
5852        "Faq dir: " (and (listp gnus-group-faq-directory)
5853                         (mapcar (lambda (file) (list file))
5854                                 gnus-group-faq-directory))))))
5855   (let (gnus-faq-buffer)
5856     (when (setq gnus-faq-buffer
5857                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5858       (gnus-configure-windows 'summary-faq))))
5859
5860 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5861 (defun gnus-summary-describe-group (&optional force)
5862   "Describe the current newsgroup."
5863   (interactive "P")
5864   (gnus-group-describe-group force gnus-newsgroup-name))
5865
5866 (defun gnus-summary-describe-briefly ()
5867   "Describe summary mode commands briefly."
5868   (interactive)
5869   (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")))
5870
5871 ;; Walking around group mode buffer from summary mode.
5872
5873 (defun gnus-summary-next-group (&optional no-article target-group backward)
5874   "Exit current newsgroup and then select next unread newsgroup.
5875 If prefix argument NO-ARTICLE is non-nil, no article is selected
5876 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5877 previous group instead."
5878   (interactive "P")
5879   ;; Stop pre-fetching.
5880   (gnus-async-halt-prefetch)
5881   (let ((current-group gnus-newsgroup-name)
5882         (current-buffer (current-buffer))
5883         entered)
5884     ;; First we semi-exit this group to update Xrefs and all variables.
5885     ;; We can't do a real exit, because the window conf must remain
5886     ;; the same in case the user is prompted for info, and we don't
5887     ;; want the window conf to change before that...
5888     (gnus-summary-exit t)
5889     (while (not entered)
5890       ;; Then we find what group we are supposed to enter.
5891       (set-buffer gnus-group-buffer)
5892       (gnus-group-jump-to-group current-group)
5893       (setq target-group
5894             (or target-group
5895                 (if (eq gnus-keep-same-level 'best)
5896                     (gnus-summary-best-group gnus-newsgroup-name)
5897                   (gnus-summary-search-group backward gnus-keep-same-level))))
5898       (if (not target-group)
5899           ;; There are no further groups, so we return to the group
5900           ;; buffer.
5901           (progn
5902             (gnus-message 5 "Returning to the group buffer")
5903             (setq entered t)
5904             (when (gnus-buffer-live-p current-buffer)
5905               (set-buffer current-buffer)
5906               (gnus-summary-exit))
5907             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5908         ;; We try to enter the target group.
5909         (gnus-group-jump-to-group target-group)
5910         (let ((unreads (gnus-group-group-unread)))
5911           (if (and (or (eq t unreads)
5912                        (and unreads (not (zerop unreads))))
5913                    (gnus-summary-read-group
5914                     target-group nil no-article
5915                     (and (buffer-name current-buffer) current-buffer)
5916                     nil backward))
5917               (setq entered t)
5918             (setq current-group target-group
5919                   target-group nil)))))))
5920
5921 (defun gnus-summary-prev-group (&optional no-article)
5922   "Exit current newsgroup and then select previous unread newsgroup.
5923 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5924   (interactive "P")
5925   (gnus-summary-next-group no-article nil t))
5926
5927 ;; Walking around summary lines.
5928
5929 (defun gnus-summary-first-subject (&optional unread undownloaded)
5930   "Go to the first unread subject.
5931 If UNREAD is non-nil, go to the first unread article.
5932 Returns the article selected or nil if there are no unread articles."
5933   (interactive "P")
5934   (prog1
5935       (cond
5936        ;; Empty summary.
5937        ((null gnus-newsgroup-data)
5938         (gnus-message 3 "No articles in the group")
5939         nil)
5940        ;; Pick the first article.
5941        ((not unread)
5942         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5943         (gnus-data-number (car gnus-newsgroup-data)))
5944        ;; No unread articles.
5945        ((null gnus-newsgroup-unreads)
5946         (gnus-message 3 "No more unread articles")
5947         nil)
5948        ;; Find the first unread article.
5949        (t
5950         (let ((data gnus-newsgroup-data))
5951           (while (and data
5952                       (and (not (and undownloaded
5953                                      (eq gnus-undownloaded-mark
5954                                          (gnus-data-mark (car data)))))
5955                            (not (gnus-data-unread-p (car data)))))
5956             (setq data (cdr data)))
5957           (when data
5958             (goto-char (gnus-data-pos (car data)))
5959             (gnus-data-number (car data))))))
5960     (gnus-summary-position-point)))
5961
5962 (defun gnus-summary-next-subject (n &optional unread dont-display)
5963   "Go to next N'th summary line.
5964 If N is negative, go to the previous N'th subject line.
5965 If UNREAD is non-nil, only unread articles are selected.
5966 The difference between N and the actual number of steps taken is
5967 returned."
5968   (interactive "p")
5969   (let ((backward (< n 0))
5970         (n (abs n)))
5971     (while (and (> n 0)
5972                 (if backward
5973                     (gnus-summary-find-prev unread)
5974                   (gnus-summary-find-next unread)))
5975       (unless (zerop (setq n (1- n)))
5976         (gnus-summary-show-thread)))
5977     (when (/= 0 n)
5978       (gnus-message 7 "No more%s articles"
5979                     (if unread " unread" "")))
5980     (unless dont-display
5981       (gnus-summary-recenter)
5982       (gnus-summary-position-point))
5983     n))
5984
5985 (defun gnus-summary-next-unread-subject (n)
5986   "Go to next N'th unread summary line."
5987   (interactive "p")
5988   (gnus-summary-next-subject n t))
5989
5990 (defun gnus-summary-prev-subject (n &optional unread)
5991   "Go to previous N'th summary line.
5992 If optional argument UNREAD is non-nil, only unread article is selected."
5993   (interactive "p")
5994   (gnus-summary-next-subject (- n) unread))
5995
5996 (defun gnus-summary-prev-unread-subject (n)
5997   "Go to previous N'th unread summary line."
5998   (interactive "p")
5999   (gnus-summary-next-subject (- n) t))
6000
6001 (defun gnus-summary-goto-subject (article &optional force silent)
6002   "Go the subject line of ARTICLE.
6003 If FORCE, also allow jumping to articles not currently shown."
6004   (interactive "nArticle number: ")
6005   (let ((b (point))
6006         (data (gnus-data-find article)))
6007     ;; We read in the article if we have to.
6008     (and (not data)
6009          force
6010          (gnus-summary-insert-subject
6011           article
6012           (if (or (numberp force) (vectorp force)) force)
6013           t)
6014          (setq data (gnus-data-find article)))
6015     (goto-char b)
6016     (if (not data)
6017         (progn
6018           (unless silent
6019             (gnus-message 3 "Can't find article %d" article))
6020           nil)
6021       (goto-char (gnus-data-pos data))
6022       (gnus-summary-position-point)
6023       article)))
6024
6025 ;; Walking around summary lines with displaying articles.
6026
6027 (defun gnus-summary-expand-window (&optional arg)
6028   "Make the summary buffer take up the entire Emacs frame.
6029 Given a prefix, will force an `article' buffer configuration."
6030   (interactive "P")
6031   (if arg
6032       (gnus-configure-windows 'article 'force)
6033     (gnus-configure-windows 'summary 'force)))
6034
6035 (defun gnus-summary-display-article (article &optional all-header)
6036   "Display ARTICLE in article buffer."
6037   (when (gnus-buffer-live-p gnus-article-buffer)
6038     (with-current-buffer gnus-article-buffer
6039       (mm-enable-multibyte-mule4)))
6040   (gnus-set-global-variables)
6041   (when (gnus-buffer-live-p gnus-article-buffer)
6042     (with-current-buffer gnus-article-buffer
6043       (setq gnus-article-charset gnus-newsgroup-charset)
6044       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)))
6045   (if (null article)
6046       nil
6047     (prog1
6048         (if gnus-summary-display-article-function
6049             (funcall gnus-summary-display-article-function article all-header)
6050           (gnus-article-prepare article all-header))
6051       (with-current-buffer gnus-article-buffer
6052         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6053              nil))
6054       (gnus-run-hooks 'gnus-select-article-hook)
6055       (when (and gnus-current-article
6056                  (not (zerop gnus-current-article)))
6057         (gnus-summary-goto-subject gnus-current-article))
6058       (gnus-summary-recenter)
6059       (when (and gnus-use-trees gnus-show-threads)
6060         (gnus-possibly-generate-tree article)
6061         (gnus-highlight-selected-tree article))
6062       ;; Successfully display article.
6063       (gnus-article-set-window-start
6064        (cdr (assq article gnus-newsgroup-bookmarks))))))
6065
6066 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6067   "Select the current article.
6068 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6069 non-nil, the article will be re-fetched even if it already present in
6070 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6071 be displayed."
6072   ;; Make sure we are in the summary buffer to work around bbdb bug.
6073   (unless (eq major-mode 'gnus-summary-mode)
6074     (set-buffer gnus-summary-buffer))
6075   (let ((article (or article (gnus-summary-article-number)))
6076         (all-headers (not (not all-headers))) ;Must be T or NIL.
6077         gnus-summary-display-article-function)
6078     (and (not pseudo)
6079          (gnus-summary-article-pseudo-p article)
6080          (error "This is a pseudo-article"))
6081     (save-excursion
6082       (set-buffer gnus-summary-buffer)
6083       (if (or (and gnus-single-article-buffer
6084                    (or (null gnus-current-article)
6085                        (null gnus-article-current)
6086                        (null (get-buffer gnus-article-buffer))
6087                        (not (eq article (cdr gnus-article-current)))
6088                        (not (equal (car gnus-article-current)
6089                                    gnus-newsgroup-name))))
6090               (and (not gnus-single-article-buffer)
6091                    (or (null gnus-current-article)
6092                        (not (eq gnus-current-article article))))
6093               force)
6094           ;; The requested article is different from the current article.
6095           (progn
6096             (gnus-summary-display-article article all-headers)
6097             (when (or all-headers gnus-show-all-headers)
6098               (gnus-article-show-all-headers))
6099             (gnus-article-set-window-start
6100              (cdr (assq article gnus-newsgroup-bookmarks)))
6101             article)
6102         (when (or all-headers gnus-show-all-headers)
6103           (gnus-article-show-all-headers))
6104         'old))))
6105
6106 (defun gnus-summary-force-verify-and-decrypt ()
6107   (interactive)
6108   (let ((mm-verify-option 'known)
6109         (mm-decrypt-option 'known))
6110     (gnus-summary-select-article nil 'force)))
6111
6112 (defun gnus-summary-set-current-mark (&optional current-mark)
6113   "Obsolete function."
6114   nil)
6115
6116 (defun gnus-summary-next-article (&optional unread subject backward push)
6117   "Select the next article.
6118 If UNREAD, only unread articles are selected.
6119 If SUBJECT, only articles with SUBJECT are selected.
6120 If BACKWARD, the previous article is selected instead of the next."
6121   (interactive "P")
6122   (cond
6123    ;; Is there such an article?
6124    ((and (gnus-summary-search-forward unread subject backward)
6125          (or (gnus-summary-display-article (gnus-summary-article-number))
6126              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6127     (gnus-summary-position-point))
6128    ;; If not, we try the first unread, if that is wanted.
6129    ((and subject
6130          gnus-auto-select-same
6131          (gnus-summary-first-unread-article))
6132     (gnus-summary-position-point)
6133     (gnus-message 6 "Wrapped"))
6134    ;; Try to get next/previous article not displayed in this group.
6135    ((and gnus-auto-extend-newsgroup
6136          (not unread) (not subject))
6137     (gnus-summary-goto-article
6138      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6139      nil (count-lines (point-min) (point))))
6140    ;; Go to next/previous group.
6141    (t
6142     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6143       (gnus-summary-jump-to-group gnus-newsgroup-name))
6144     (let ((cmd last-command-char)
6145           (point
6146            (save-excursion
6147              (set-buffer gnus-group-buffer)
6148              (point)))
6149           (group
6150            (if (eq gnus-keep-same-level 'best)
6151                (gnus-summary-best-group gnus-newsgroup-name)
6152              (gnus-summary-search-group backward gnus-keep-same-level))))
6153       ;; For some reason, the group window gets selected.  We change
6154       ;; it back.
6155       (select-window (get-buffer-window (current-buffer)))
6156       ;; Select next unread newsgroup automagically.
6157       (cond
6158        ((or (not gnus-auto-select-next)
6159             (not cmd))
6160         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6161        ((or (eq gnus-auto-select-next 'quietly)
6162             (and (eq gnus-auto-select-next 'slightly-quietly)
6163                  push)
6164             (and (eq gnus-auto-select-next 'almost-quietly)
6165                  (gnus-summary-last-article-p)))
6166         ;; Select quietly.
6167         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6168             (gnus-summary-exit)
6169           (gnus-message 7 "No more%s articles (%s)..."
6170                         (if unread " unread" "")
6171                         (if group (concat "selecting " group)
6172                           "exiting"))
6173           (gnus-summary-next-group nil group backward)))
6174        (t
6175         (when (gnus-key-press-event-p last-input-event)
6176           (gnus-summary-walk-group-buffer
6177            gnus-newsgroup-name cmd unread backward point))))))))
6178
6179 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6180   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6181                       (?\C-p (gnus-group-prev-unread-group 1))))
6182         (cursor-in-echo-area t)
6183         keve key group ended)
6184     (save-excursion
6185       (set-buffer gnus-group-buffer)
6186       (goto-char start)
6187       (setq group
6188             (if (eq gnus-keep-same-level 'best)
6189                 (gnus-summary-best-group gnus-newsgroup-name)
6190               (gnus-summary-search-group backward gnus-keep-same-level))))
6191     (while (not ended)
6192       (gnus-message
6193        5 "No more%s articles%s" (if unread " unread" "")
6194        (if (and group
6195                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6196            (format " (Type %s for %s [%s])"
6197                    (single-key-description cmd) group
6198                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6199          (format " (Type %s to exit %s)"
6200                  (single-key-description cmd)
6201                  gnus-newsgroup-name)))
6202       ;; Confirm auto selection.
6203       (setq key (car (setq keve (gnus-read-event-char))))
6204       (setq ended t)
6205       (cond
6206        ((assq key keystrokes)
6207         (let ((obuf (current-buffer)))
6208           (switch-to-buffer gnus-group-buffer)
6209           (when group
6210             (gnus-group-jump-to-group group))
6211           (eval (cadr (assq key keystrokes)))
6212           (setq group (gnus-group-group-name))
6213           (switch-to-buffer obuf))
6214         (setq ended nil))
6215        ((equal key cmd)
6216         (if (or (not group)
6217                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6218             (gnus-summary-exit)
6219           (gnus-summary-next-group nil group backward)))
6220        (t
6221         (push (cdr keve) unread-command-events))))))
6222
6223 (defun gnus-summary-next-unread-article ()
6224   "Select unread article after current one."
6225   (interactive)
6226   (gnus-summary-next-article
6227    (or (not (eq gnus-summary-goto-unread 'never))
6228        (gnus-summary-last-article-p (gnus-summary-article-number)))
6229    (and gnus-auto-select-same
6230         (gnus-summary-article-subject))))
6231
6232 (defun gnus-summary-prev-article (&optional unread subject)
6233   "Select the article after the current one.
6234 If UNREAD is non-nil, only unread articles are selected."
6235   (interactive "P")
6236   (gnus-summary-next-article unread subject t))
6237
6238 (defun gnus-summary-prev-unread-article ()
6239   "Select unread article before current one."
6240   (interactive)
6241   (gnus-summary-prev-article
6242    (or (not (eq gnus-summary-goto-unread 'never))
6243        (gnus-summary-first-article-p (gnus-summary-article-number)))
6244    (and gnus-auto-select-same
6245         (gnus-summary-article-subject))))
6246
6247 (defun gnus-summary-next-page (&optional lines circular)
6248   "Show next page of the selected article.
6249 If at the end of the current article, select the next article.
6250 LINES says how many lines should be scrolled up.
6251
6252 If CIRCULAR is non-nil, go to the start of the article instead of
6253 selecting the next article when reaching the end of the current
6254 article."
6255   (interactive "P")
6256   (setq gnus-summary-buffer (current-buffer))
6257   (gnus-set-global-variables)
6258   (let ((article (gnus-summary-article-number))
6259         (article-window (get-buffer-window gnus-article-buffer t))
6260         endp)
6261     ;; If the buffer is empty, we have no article.
6262     (unless article
6263       (error "No article to select"))
6264     (gnus-configure-windows 'article)
6265     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6266         (if (and (eq gnus-summary-goto-unread 'never)
6267                  (not (gnus-summary-last-article-p article)))
6268             (gnus-summary-next-article)
6269           (gnus-summary-next-unread-article))
6270       (if (or (null gnus-current-article)
6271               (null gnus-article-current)
6272               (/= article (cdr gnus-article-current))
6273               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6274           ;; Selected subject is different from current article's.
6275           (gnus-summary-display-article article)
6276         (when article-window
6277           (gnus-eval-in-buffer-window gnus-article-buffer
6278             (setq endp (gnus-article-next-page lines)))
6279           (when endp
6280             (cond (circular
6281                    (gnus-summary-beginning-of-article))
6282                   (lines
6283                    (gnus-message 3 "End of message"))
6284                   ((null lines)
6285                    (if (and (eq gnus-summary-goto-unread 'never)
6286                             (not (gnus-summary-last-article-p article)))
6287                        (gnus-summary-next-article)
6288                      (gnus-summary-next-unread-article))))))))
6289     (gnus-summary-recenter)
6290     (gnus-summary-position-point)))
6291
6292 (defun gnus-summary-prev-page (&optional lines move)
6293   "Show previous page of selected article.
6294 Argument LINES specifies lines to be scrolled down.
6295 If MOVE, move to the previous unread article if point is at
6296 the beginning of the buffer."
6297   (interactive "P")
6298   (let ((article (gnus-summary-article-number))
6299         (article-window (get-buffer-window gnus-article-buffer t))
6300         endp)
6301     (gnus-configure-windows 'article)
6302     (if (or (null gnus-current-article)
6303             (null gnus-article-current)
6304             (/= article (cdr gnus-article-current))
6305             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6306         ;; Selected subject is different from current article's.
6307         (gnus-summary-display-article article)
6308       (gnus-summary-recenter)
6309       (when article-window
6310         (gnus-eval-in-buffer-window gnus-article-buffer
6311           (setq endp (gnus-article-prev-page lines)))
6312         (when (and move endp)
6313           (cond (lines
6314                  (gnus-message 3 "Beginning of message"))
6315                 ((null lines)
6316                  (if (and (eq gnus-summary-goto-unread 'never)
6317                           (not (gnus-summary-first-article-p article)))
6318                      (gnus-summary-prev-article)
6319                    (gnus-summary-prev-unread-article))))))))
6320   (gnus-summary-position-point))
6321
6322 (defun gnus-summary-prev-page-or-article (&optional lines)
6323   "Show previous page of selected article.
6324 Argument LINES specifies lines to be scrolled down.
6325 If at the beginning of the article, go to the next article."
6326   (interactive "P")
6327   (gnus-summary-prev-page lines t))
6328
6329 (defun gnus-summary-scroll-up (lines)
6330   "Scroll up (or down) one line current article.
6331 Argument LINES specifies lines to be scrolled up (or down if negative)."
6332   (interactive "p")
6333   (gnus-configure-windows 'article)
6334   (gnus-summary-show-thread)
6335   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6336     (gnus-eval-in-buffer-window gnus-article-buffer
6337       (cond ((> lines 0)
6338              (when (gnus-article-next-page lines)
6339                (gnus-message 3 "End of message")))
6340             ((< lines 0)
6341              (gnus-article-prev-page (- lines))))))
6342   (gnus-summary-recenter)
6343   (gnus-summary-position-point))
6344
6345 (defun gnus-summary-scroll-down (lines)
6346   "Scroll down (or up) one line current article.
6347 Argument LINES specifies lines to be scrolled down (or up if negative)."
6348   (interactive "p")
6349   (gnus-summary-scroll-up (- lines)))
6350
6351 (defun gnus-summary-next-same-subject ()
6352   "Select next article which has the same subject as current one."
6353   (interactive)
6354   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6355
6356 (defun gnus-summary-prev-same-subject ()
6357   "Select previous article which has the same subject as current one."
6358   (interactive)
6359   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6360
6361 (defun gnus-summary-next-unread-same-subject ()
6362   "Select next unread article which has the same subject as current one."
6363   (interactive)
6364   (gnus-summary-next-article t (gnus-summary-article-subject)))
6365
6366 (defun gnus-summary-prev-unread-same-subject ()
6367   "Select previous unread article which has the same subject as current one."
6368   (interactive)
6369   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6370
6371 (defun gnus-summary-first-unread-article ()
6372   "Select the first unread article.
6373 Return nil if there are no unread articles."
6374   (interactive)
6375   (prog1
6376       (when (gnus-summary-first-subject t)
6377         (gnus-summary-show-thread)
6378         (gnus-summary-first-subject t)
6379         (gnus-summary-display-article (gnus-summary-article-number)))
6380     (gnus-summary-position-point)))
6381
6382 (defun gnus-summary-first-unread-subject ()
6383   "Place the point on the subject line of the first unread article.
6384 Return nil if there are no unread articles."
6385   (interactive)
6386   (prog1
6387       (when (gnus-summary-first-subject t)
6388         (gnus-summary-show-thread)
6389         (gnus-summary-first-subject t))
6390     (gnus-summary-position-point)))
6391
6392 (defun gnus-summary-first-article ()
6393   "Select the first article.
6394 Return nil if there are no articles."
6395   (interactive)
6396   (prog1
6397       (when (gnus-summary-first-subject)
6398         (gnus-summary-show-thread)
6399         (gnus-summary-first-subject)
6400         (gnus-summary-display-article (gnus-summary-article-number)))
6401     (gnus-summary-position-point)))
6402
6403 (defun gnus-summary-best-unread-article ()
6404   "Select the unread article with the highest score."
6405   (interactive)
6406   (let ((best -1000000)
6407         (data gnus-newsgroup-data)
6408         article score)
6409     (while data
6410       (and (gnus-data-unread-p (car data))
6411            (> (setq score
6412                     (gnus-summary-article-score (gnus-data-number (car data))))
6413               best)
6414            (setq best score
6415                  article (gnus-data-number (car data))))
6416       (setq data (cdr data)))
6417     (prog1
6418         (if article
6419             (gnus-summary-goto-article article)
6420           (error "No unread articles"))
6421       (gnus-summary-position-point))))
6422
6423 (defun gnus-summary-last-subject ()
6424   "Go to the last displayed subject line in the group."
6425   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6426     (when article
6427       (gnus-summary-goto-subject article))))
6428
6429 (defun gnus-summary-goto-article (article &optional all-headers force)
6430   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6431 If ALL-HEADERS is non-nil, no header lines are hidden.
6432 If FORCE, go to the article even if it isn't displayed.  If FORCE
6433 is a number, it is the line the article is to be displayed on."
6434   (interactive
6435    (list
6436     (completing-read
6437      "Article number or Message-ID: "
6438      (mapcar (lambda (number) (list (int-to-string number)))
6439              gnus-newsgroup-limit))
6440     current-prefix-arg
6441     t))
6442   (prog1
6443       (if (and (stringp article)
6444                (string-match "@" article))
6445           (gnus-summary-refer-article article)
6446         (when (stringp article)
6447           (setq article (string-to-number article)))
6448         (if (gnus-summary-goto-subject article force)
6449             (gnus-summary-display-article article all-headers)
6450           (gnus-message 4 "Couldn't go to article %s" article) nil))
6451     (gnus-summary-position-point)))
6452
6453 (defun gnus-summary-goto-last-article ()
6454   "Go to the previously read article."
6455   (interactive)
6456   (prog1
6457       (when gnus-last-article
6458         (gnus-summary-goto-article gnus-last-article nil t))
6459     (gnus-summary-position-point)))
6460
6461 (defun gnus-summary-pop-article (number)
6462   "Pop one article off the history and go to the previous.
6463 NUMBER articles will be popped off."
6464   (interactive "p")
6465   (let (to)
6466     (setq gnus-newsgroup-history
6467           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6468     (if to
6469         (gnus-summary-goto-article (car to) nil t)
6470       (error "Article history empty")))
6471   (gnus-summary-position-point))
6472
6473 ;; Summary commands and functions for limiting the summary buffer.
6474
6475 (defun gnus-summary-limit-to-articles (n)
6476   "Limit the summary buffer to the next N articles.
6477 If not given a prefix, use the process marked articles instead."
6478   (interactive "P")
6479   (prog1
6480       (let ((articles (gnus-summary-work-articles n)))
6481         (setq gnus-newsgroup-processable nil)
6482         (gnus-summary-limit articles))
6483     (gnus-summary-position-point)))
6484
6485 (defun gnus-summary-pop-limit (&optional total)
6486   "Restore the previous limit.
6487 If given a prefix, remove all limits."
6488   (interactive "P")
6489   (when total
6490     (setq gnus-newsgroup-limits
6491           (list (mapcar (lambda (h) (mail-header-number h))
6492                         gnus-newsgroup-headers))))
6493   (unless gnus-newsgroup-limits
6494     (error "No limit to pop"))
6495   (prog1
6496       (gnus-summary-limit nil 'pop)
6497     (gnus-summary-position-point)))
6498
6499 (defun gnus-summary-limit-to-subject (subject &optional header)
6500   "Limit the summary buffer to articles that have subjects that match a regexp."
6501   (interactive "sLimit to subject (regexp): ")
6502   (unless header
6503     (setq header "subject"))
6504   (when (not (equal "" subject))
6505     (prog1
6506         (let ((articles (gnus-summary-find-matching
6507                          (or header "subject") subject 'all)))
6508           (unless articles
6509             (error "Found no matches for \"%s\"" subject))
6510           (gnus-summary-limit articles))
6511       (gnus-summary-position-point))))
6512
6513 (defun gnus-summary-limit-to-author (from)
6514   "Limit the summary buffer to articles that have authors that match a regexp."
6515   (interactive "sLimit to author (regexp): ")
6516   (gnus-summary-limit-to-subject from "from"))
6517
6518 (defun gnus-summary-limit-to-age (age &optional younger-p)
6519   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6520 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6521 articles that are younger than AGE days."
6522   (interactive
6523    (let ((younger current-prefix-arg)
6524          (days-got nil)
6525          days)
6526      (while (not days-got)
6527        (setq days (if younger
6528                       (read-string "Limit to articles within (in days): ")
6529                     (read-string "Limit to articles older than (in days): ")))
6530        (when (> (length days) 0)
6531          (setq days (read days)))
6532        (if (numberp days)
6533            (setq days-got t)
6534          (message "Please enter a number.")
6535          (sleep-for 1)))
6536      (list days younger)))
6537   (prog1
6538       (let ((data gnus-newsgroup-data)
6539             (cutoff (days-to-time age))
6540             articles d date is-younger)
6541         (while (setq d (pop data))
6542           (when (and (vectorp (gnus-data-header d))
6543                      (setq date (mail-header-date (gnus-data-header d))))
6544             (setq is-younger (time-less-p
6545                               (time-since (condition-case ()
6546                                               (date-to-time date)
6547                                             (error '(0 0))))
6548                               cutoff))
6549             (when (if younger-p
6550                       is-younger
6551                     (not is-younger))
6552               (push (gnus-data-number d) articles))))
6553         (gnus-summary-limit (nreverse articles)))
6554     (gnus-summary-position-point)))
6555
6556 (defun gnus-summary-limit-to-extra (header regexp)
6557   "Limit the summary buffer to articles that match an 'extra' header."
6558   (interactive
6559    (let ((header
6560           (intern
6561            (gnus-completing-read
6562             (symbol-name (car gnus-extra-headers))
6563             "Limit extra header:"
6564             (mapcar (lambda (x)
6565                       (cons (symbol-name x) x))
6566                     gnus-extra-headers)
6567             nil
6568             t))))
6569      (list header
6570            (read-string (format "Limit to header %s (regexp): " header)))))
6571   (when (not (equal "" regexp))
6572     (prog1
6573         (let ((articles (gnus-summary-find-matching
6574                          (cons 'extra header) regexp 'all)))
6575           (unless articles
6576             (error "Found no matches for \"%s\"" regexp))
6577           (gnus-summary-limit articles))
6578       (gnus-summary-position-point))))
6579
6580 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6581 (make-obsolete
6582  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6583
6584 (defun gnus-summary-limit-to-unread (&optional all)
6585   "Limit the summary buffer to articles that are not marked as read.
6586 If ALL is non-nil, limit strictly to unread articles."
6587   (interactive "P")
6588   (if all
6589       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6590     (gnus-summary-limit-to-marks
6591      ;; Concat all the marks that say that an article is read and have
6592      ;; those removed.
6593      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6594            gnus-killed-mark gnus-kill-file-mark
6595            gnus-low-score-mark gnus-expirable-mark
6596            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6597            gnus-duplicate-mark gnus-souped-mark)
6598      'reverse)))
6599
6600 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6601 (make-obsolete 'gnus-summary-delete-marked-with
6602                'gnus-summary-limit-exlude-marks)
6603
6604 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6605   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6606 If REVERSE, limit the summary buffer to articles that are marked
6607 with MARKS.  MARKS can either be a string of marks or a list of marks.
6608 Returns how many articles were removed."
6609   (interactive "sMarks: ")
6610   (gnus-summary-limit-to-marks marks t))
6611
6612 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6613   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6614 If REVERSE (the prefix), limit the summary buffer to articles that are
6615 not marked with MARKS.  MARKS can either be a string of marks or a
6616 list of marks.
6617 Returns how many articles were removed."
6618   (interactive "sMarks: \nP")
6619   (prog1
6620       (let ((data gnus-newsgroup-data)
6621             (marks (if (listp marks) marks
6622                      (append marks nil))) ; Transform to list.
6623             articles)
6624         (while data
6625           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6626                   (memq (gnus-data-mark (car data)) marks))
6627             (push (gnus-data-number (car data)) articles))
6628           (setq data (cdr data)))
6629         (gnus-summary-limit articles))
6630     (gnus-summary-position-point)))
6631
6632 (defun gnus-summary-limit-to-score (&optional score)
6633   "Limit to articles with score at or above SCORE."
6634   (interactive "P")
6635   (setq score (if score
6636                   (prefix-numeric-value score)
6637                 (or gnus-summary-default-score 0)))
6638   (let ((data gnus-newsgroup-data)
6639         articles)
6640     (while data
6641       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6642                 score)
6643         (push (gnus-data-number (car data)) articles))
6644       (setq data (cdr data)))
6645     (prog1
6646         (gnus-summary-limit articles)
6647       (gnus-summary-position-point))))
6648
6649 (defun gnus-summary-limit-include-thread (id)
6650   "Display all the hidden articles that in the current thread."
6651   (interactive (list (mail-header-id (gnus-summary-article-header))))
6652   (let ((articles (gnus-articles-in-thread
6653                    (gnus-id-to-thread (gnus-root-id id)))))
6654     (prog1
6655         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6656       (gnus-summary-position-point))))
6657
6658 (defun gnus-summary-limit-include-dormant ()
6659   "Display all the hidden articles that are marked as dormant.
6660 Note that this command only works on a subset of the articles currently
6661 fetched for this group."
6662   (interactive)
6663   (unless gnus-newsgroup-dormant
6664     (error "There are no dormant articles in this group"))
6665   (prog1
6666       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6667     (gnus-summary-position-point)))
6668
6669 (defun gnus-summary-limit-exclude-dormant ()
6670   "Hide all dormant articles."
6671   (interactive)
6672   (prog1
6673       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6674     (gnus-summary-position-point)))
6675
6676 (defun gnus-summary-limit-exclude-childless-dormant ()
6677   "Hide all dormant articles that have no children."
6678   (interactive)
6679   (let ((data (gnus-data-list t))
6680         articles d children)
6681     ;; Find all articles that are either not dormant or have
6682     ;; children.
6683     (while (setq d (pop data))
6684       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6685                 (and (setq children
6686                            (gnus-article-children (gnus-data-number d)))
6687                      (let (found)
6688                        (while children
6689                          (when (memq (car children) articles)
6690                            (setq children nil
6691                                  found t))
6692                          (pop children))
6693                        found)))
6694         (push (gnus-data-number d) articles)))
6695     ;; Do the limiting.
6696     (prog1
6697         (gnus-summary-limit articles)
6698       (gnus-summary-position-point))))
6699
6700 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6701   "Mark all unread excluded articles as read.
6702 If ALL, mark even excluded ticked and dormants as read."
6703   (interactive "P")
6704   (let ((articles (gnus-sorted-complement
6705                    (sort
6706                     (mapcar (lambda (h) (mail-header-number h))
6707                             gnus-newsgroup-headers)
6708                     '<)
6709                    (sort gnus-newsgroup-limit '<)))
6710         article)
6711     (setq gnus-newsgroup-unreads
6712           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6713     (if all
6714         (setq gnus-newsgroup-dormant nil
6715               gnus-newsgroup-marked nil
6716               gnus-newsgroup-reads
6717               (nconc
6718                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6719                gnus-newsgroup-reads))
6720       (while (setq article (pop articles))
6721         (unless (or (memq article gnus-newsgroup-dormant)
6722                     (memq article gnus-newsgroup-marked))
6723           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6724
6725 (defun gnus-summary-limit (articles &optional pop)
6726   (if pop
6727       ;; We pop the previous limit off the stack and use that.
6728       (setq articles (car gnus-newsgroup-limits)
6729             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6730     ;; We use the new limit, so we push the old limit on the stack.
6731     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6732   ;; Set the limit.
6733   (setq gnus-newsgroup-limit articles)
6734   (let ((total (length gnus-newsgroup-data))
6735         (data (gnus-data-find-list (gnus-summary-article-number)))
6736         (gnus-summary-mark-below nil)   ; Inhibit this.
6737         found)
6738     ;; This will do all the work of generating the new summary buffer
6739     ;; according to the new limit.
6740     (gnus-summary-prepare)
6741     ;; Hide any threads, possibly.
6742     (and gnus-show-threads
6743          gnus-thread-hide-subtree
6744          (gnus-summary-hide-all-threads))
6745     ;; Try to return to the article you were at, or one in the
6746     ;; neighborhood.
6747     (when data
6748       ;; We try to find some article after the current one.
6749       (while data
6750         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6751           (setq data nil
6752                 found t))
6753         (setq data (cdr data))))
6754     (unless found
6755       ;; If there is no data, that means that we were after the last
6756       ;; article.  The same goes when we can't find any articles
6757       ;; after the current one.
6758       (goto-char (point-max))
6759       (gnus-summary-find-prev))
6760     (gnus-set-mode-line 'summary)
6761     ;; We return how many articles were removed from the summary
6762     ;; buffer as a result of the new limit.
6763     (- total (length gnus-newsgroup-data))))
6764
6765 (defsubst gnus-invisible-cut-children (threads)
6766   (let ((num 0))
6767     (while threads
6768       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6769         (incf num))
6770       (pop threads))
6771     (< num 2)))
6772
6773 (defsubst gnus-cut-thread (thread)
6774   "Go forwards in the thread until we find an article that we want to display."
6775   (when (or (eq gnus-fetch-old-headers 'some)
6776             (eq gnus-fetch-old-headers 'invisible)
6777             (numberp gnus-fetch-old-headers)
6778             (eq gnus-build-sparse-threads 'some)
6779             (eq gnus-build-sparse-threads 'more))
6780     ;; Deal with old-fetched headers and sparse threads.
6781     (while (and
6782             thread
6783             (or
6784              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6785              (gnus-summary-article-ancient-p
6786               (mail-header-number (car thread))))
6787             (if (or (<= (length (cdr thread)) 1)
6788                     (eq gnus-fetch-old-headers 'invisible))
6789                 (setq gnus-newsgroup-limit
6790                       (delq (mail-header-number (car thread))
6791                             gnus-newsgroup-limit)
6792                       thread (cadr thread))
6793               (when (gnus-invisible-cut-children (cdr thread))
6794                 (let ((th (cdr thread)))
6795                   (while th
6796                     (if (memq (mail-header-number (caar th))
6797                               gnus-newsgroup-limit)
6798                         (setq thread (car th)
6799                               th nil)
6800                       (setq th (cdr th))))))))))
6801   thread)
6802
6803 (defun gnus-cut-threads (threads)
6804   "Cut off all uninteresting articles from the beginning of threads."
6805   (when (or (eq gnus-fetch-old-headers 'some)
6806             (eq gnus-fetch-old-headers 'invisible)
6807             (numberp gnus-fetch-old-headers)
6808             (eq gnus-build-sparse-threads 'some)
6809             (eq gnus-build-sparse-threads 'more))
6810     (let ((th threads))
6811       (while th
6812         (setcar th (gnus-cut-thread (car th)))
6813         (setq th (cdr th)))))
6814   ;; Remove nixed out threads.
6815   (delq nil threads))
6816
6817 (defun gnus-summary-initial-limit (&optional show-if-empty)
6818   "Figure out what the initial limit is supposed to be on group entry.
6819 This entails weeding out unwanted dormants, low-scored articles,
6820 fetch-old-headers verbiage, and so on."
6821   ;; Most groups have nothing to remove.
6822   (if (or gnus-inhibit-limiting
6823           (and (null gnus-newsgroup-dormant)
6824                (not (eq gnus-fetch-old-headers 'some))
6825                (not (numberp gnus-fetch-old-headers))
6826                (not (eq gnus-fetch-old-headers 'invisible))
6827                (null gnus-summary-expunge-below)
6828                (not (eq gnus-build-sparse-threads 'some))
6829                (not (eq gnus-build-sparse-threads 'more))
6830                (null gnus-thread-expunge-below)
6831                (not gnus-use-nocem)))
6832       ()                                ; Do nothing.
6833     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6834     (setq gnus-newsgroup-limit nil)
6835     (mapatoms
6836      (lambda (node)
6837        (unless (car (symbol-value node))
6838          ;; These threads have no parents -- they are roots.
6839          (let ((nodes (cdr (symbol-value node)))
6840                thread)
6841            (while nodes
6842              (if (and gnus-thread-expunge-below
6843                       (< (gnus-thread-total-score (car nodes))
6844                          gnus-thread-expunge-below))
6845                  (gnus-expunge-thread (pop nodes))
6846                (setq thread (pop nodes))
6847                (gnus-summary-limit-children thread))))))
6848      gnus-newsgroup-dependencies)
6849     ;; If this limitation resulted in an empty group, we might
6850     ;; pop the previous limit and use it instead.
6851     (when (and (not gnus-newsgroup-limit)
6852                show-if-empty)
6853       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6854     gnus-newsgroup-limit))
6855
6856 (defun gnus-summary-limit-children (thread)
6857   "Return 1 if this subthread is visible and 0 if it is not."
6858   ;; First we get the number of visible children to this thread.  This
6859   ;; is done by recursing down the thread using this function, so this
6860   ;; will really go down to a leaf article first, before slowly
6861   ;; working its way up towards the root.
6862   (when thread
6863     (let ((children
6864            (if (cdr thread)
6865                (apply '+ (mapcar 'gnus-summary-limit-children
6866                                  (cdr thread)))
6867              0))
6868           (number (mail-header-number (car thread)))
6869           score)
6870       (if (and
6871            (not (memq number gnus-newsgroup-marked))
6872            (or
6873             ;; If this article is dormant and has absolutely no visible
6874             ;; children, then this article isn't visible.
6875             (and (memq number gnus-newsgroup-dormant)
6876                  (zerop children))
6877             ;; If this is "fetch-old-headered" and there is no
6878             ;; visible children, then we don't want this article.
6879             (and (or (eq gnus-fetch-old-headers 'some)
6880                      (numberp gnus-fetch-old-headers))
6881                  (gnus-summary-article-ancient-p number)
6882                  (zerop children))
6883             ;; If this is "fetch-old-headered" and `invisible', then
6884             ;; we don't want this article.
6885             (and (eq gnus-fetch-old-headers 'invisible)
6886                  (gnus-summary-article-ancient-p number))
6887             ;; If this is a sparsely inserted article with no children,
6888             ;; we don't want it.
6889             (and (eq gnus-build-sparse-threads 'some)
6890                  (gnus-summary-article-sparse-p number)
6891                  (zerop children))
6892             ;; If we use expunging, and this article is really
6893             ;; low-scored, then we don't want this article.
6894             (when (and gnus-summary-expunge-below
6895                        (< (setq score
6896                                 (or (cdr (assq number gnus-newsgroup-scored))
6897                                     gnus-summary-default-score))
6898                           gnus-summary-expunge-below))
6899               ;; We increase the expunge-tally here, but that has
6900               ;; nothing to do with the limits, really.
6901               (incf gnus-newsgroup-expunged-tally)
6902               ;; We also mark as read here, if that's wanted.
6903               (when (and gnus-summary-mark-below
6904                          (< score gnus-summary-mark-below))
6905                 (setq gnus-newsgroup-unreads
6906                       (delq number gnus-newsgroup-unreads))
6907                 (if gnus-newsgroup-auto-expire
6908                     (push number gnus-newsgroup-expirable)
6909                   (push (cons number gnus-low-score-mark)
6910                         gnus-newsgroup-reads)))
6911               t)
6912             ;; Check NoCeM things.
6913             (if (and gnus-use-nocem
6914                      (gnus-nocem-unwanted-article-p
6915                       (mail-header-id (car thread))))
6916                 (progn
6917                   (setq gnus-newsgroup-unreads
6918                         (delq number gnus-newsgroup-unreads))
6919                   t))))
6920           ;; Nope, invisible article.
6921           0
6922         ;; Ok, this article is to be visible, so we add it to the limit
6923         ;; and return 1.
6924         (push number gnus-newsgroup-limit)
6925         1))))
6926
6927 (defun gnus-expunge-thread (thread)
6928   "Mark all articles in THREAD as read."
6929   (let* ((number (mail-header-number (car thread))))
6930     (incf gnus-newsgroup-expunged-tally)
6931     ;; We also mark as read here, if that's wanted.
6932     (setq gnus-newsgroup-unreads
6933           (delq number gnus-newsgroup-unreads))
6934     (if gnus-newsgroup-auto-expire
6935         (push number gnus-newsgroup-expirable)
6936       (push (cons number gnus-low-score-mark)
6937             gnus-newsgroup-reads)))
6938   ;; Go recursively through all subthreads.
6939   (mapcar 'gnus-expunge-thread (cdr thread)))
6940
6941 ;; Summary article oriented commands
6942
6943 (defun gnus-summary-refer-parent-article (n)
6944   "Refer parent article N times.
6945 If N is negative, go to ancestor -N instead.
6946 The difference between N and the number of articles fetched is returned."
6947   (interactive "p")
6948   (let ((skip 1)
6949         error header ref)
6950     (when (not (natnump n))
6951       (setq skip (abs n)
6952             n 1))
6953     (while (and (> n 0)
6954                 (not error))
6955       (setq header (gnus-summary-article-header))
6956       (if (and (eq (mail-header-number header)
6957                    (cdr gnus-article-current))
6958                (equal gnus-newsgroup-name
6959                       (car gnus-article-current)))
6960           ;; If we try to find the parent of the currently
6961           ;; displayed article, then we take a look at the actual
6962           ;; References header, since this is slightly more
6963           ;; reliable than the References field we got from the
6964           ;; server.
6965           (save-excursion
6966             (set-buffer gnus-original-article-buffer)
6967             (nnheader-narrow-to-headers)
6968             (unless (setq ref (message-fetch-field "references"))
6969               (setq ref (message-fetch-field "in-reply-to")))
6970             (widen))
6971         (setq ref
6972               ;; It's not the current article, so we take a bet on
6973               ;; the value we got from the server.
6974               (mail-header-references header)))
6975       (if (and ref
6976                (not (equal ref "")))
6977           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6978             (gnus-message 1 "Couldn't find parent"))
6979         (gnus-message 1 "No references in article %d"
6980                       (gnus-summary-article-number))
6981         (setq error t))
6982       (decf n))
6983     (gnus-summary-position-point)
6984     n))
6985
6986 (defun gnus-summary-refer-references ()
6987   "Fetch all articles mentioned in the References header.
6988 Return the number of articles fetched."
6989   (interactive)
6990   (let ((ref (mail-header-references (gnus-summary-article-header)))
6991         (current (gnus-summary-article-number))
6992         (n 0))
6993     (if (or (not ref)
6994             (equal ref ""))
6995         (error "No References in the current article")
6996       ;; For each Message-ID in the References header...
6997       (while (string-match "<[^>]*>" ref)
6998         (incf n)
6999         ;; ... fetch that article.
7000         (gnus-summary-refer-article
7001          (prog1 (match-string 0 ref)
7002            (setq ref (substring ref (match-end 0))))))
7003       (gnus-summary-goto-subject current)
7004       (gnus-summary-position-point)
7005       n)))
7006
7007 (defun gnus-summary-refer-thread (&optional limit)
7008   "Fetch all articles in the current thread.
7009 If LIMIT (the numerical prefix), fetch that many old headers instead
7010 of what's specified by the `gnus-refer-thread-limit' variable."
7011   (interactive "P")
7012   (let ((id (mail-header-id (gnus-summary-article-header)))
7013         (limit (if limit (prefix-numeric-value limit)
7014                  gnus-refer-thread-limit)))
7015     ;; We want to fetch LIMIT *old* headers, but we also have to
7016     ;; re-fetch all the headers in the current buffer, because many of
7017     ;; them may be undisplayed.  So we adjust LIMIT.
7018     (when (numberp limit)
7019       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7020     (unless (eq gnus-fetch-old-headers 'invisible)
7021       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7022       ;; Retrieve the headers and read them in.
7023       (if (eq (gnus-retrieve-headers
7024                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7025               'nov)
7026           (gnus-build-all-threads)
7027         (error "Can't fetch thread from backends that don't support NOV"))
7028       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7029     (gnus-summary-limit-include-thread id)))
7030
7031 (defun gnus-summary-refer-article (message-id)
7032   "Fetch an article specified by MESSAGE-ID."
7033   (interactive "sMessage-ID: ")
7034   (when (and (stringp message-id)
7035              (not (zerop (length message-id))))
7036     ;; Construct the correct Message-ID if necessary.
7037     ;; Suggested by tale@pawl.rpi.edu.
7038     (unless (string-match "^<" message-id)
7039       (setq message-id (concat "<" message-id)))
7040     (unless (string-match ">$" message-id)
7041       (setq message-id (concat message-id ">")))
7042     (let* ((header (gnus-id-to-header message-id))
7043            (sparse (and header
7044                         (gnus-summary-article-sparse-p
7045                          (mail-header-number header))
7046                         (memq (mail-header-number header)
7047                               gnus-newsgroup-limit)))
7048            number)
7049       (cond
7050        ;; If the article is present in the buffer we just go to it.
7051        ((and header
7052              (or (not (gnus-summary-article-sparse-p
7053                        (mail-header-number header)))
7054                  sparse))
7055         (prog1
7056             (gnus-summary-goto-article
7057              (mail-header-number header) nil t)
7058           (when sparse
7059             (gnus-summary-update-article (mail-header-number header)))))
7060        (t
7061         ;; We fetch the article.
7062         (catch 'found
7063           (dolist (gnus-override-method (gnus-refer-article-methods))
7064             (gnus-check-server gnus-override-method)
7065             ;; Fetch the header, and display the article.
7066             (when (setq number (gnus-summary-insert-subject message-id))
7067               (gnus-summary-select-article nil nil nil number)
7068               (throw 'found t)))
7069           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7070
7071 (defun gnus-refer-article-methods ()
7072   "Return a list of referrable methods."
7073   (cond
7074    ;; No method, so we default to current and native.
7075    ((null gnus-refer-article-method)
7076     (list gnus-current-select-method gnus-select-method))
7077    ;; Current.
7078    ((eq 'current gnus-refer-article-method)
7079     (list gnus-current-select-method))
7080    ;; List of select methods.
7081    ((not (and (symbolp (car gnus-refer-article-method))
7082               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7083     (let (out)
7084       (dolist (method gnus-refer-article-method)
7085         (push (if (eq 'current method)
7086                   gnus-current-select-method
7087                 method)
7088               out))
7089       (nreverse out)))
7090    ;; One single select method.
7091    (t
7092     (list gnus-refer-article-method))))
7093
7094 (defun gnus-summary-edit-parameters ()
7095   "Edit the group parameters of the current group."
7096   (interactive)
7097   (gnus-group-edit-group gnus-newsgroup-name 'params))
7098
7099 (defun gnus-summary-customize-parameters ()
7100   "Customize the group parameters of the current group."
7101   (interactive)
7102   (gnus-group-customize gnus-newsgroup-name))
7103
7104 (defun gnus-summary-enter-digest-group (&optional force)
7105   "Enter an nndoc group based on the current article.
7106 If FORCE, force a digest interpretation.  If not, try
7107 to guess what the document format is."
7108   (interactive "P")
7109   (let ((conf gnus-current-window-configuration))
7110     (save-excursion
7111       (gnus-summary-select-article))
7112     (setq gnus-current-window-configuration conf)
7113     (let* ((name (format "%s-%d"
7114                          (gnus-group-prefixed-name
7115                           gnus-newsgroup-name (list 'nndoc ""))
7116                          (save-excursion
7117                            (set-buffer gnus-summary-buffer)
7118                            gnus-current-article)))
7119            (ogroup gnus-newsgroup-name)
7120            (params (append (gnus-info-params (gnus-get-info ogroup))
7121                            (list (cons 'to-group ogroup))
7122                            (list (cons 'save-article-group ogroup))))
7123            (case-fold-search t)
7124            (buf (current-buffer))
7125            dig to-address)
7126       (save-excursion
7127         (set-buffer gnus-original-article-buffer)
7128         ;; Have the digest group inherit the main mail address of
7129         ;; the parent article.
7130         (when (setq to-address (or (message-fetch-field "reply-to")
7131                                    (message-fetch-field "from")))
7132           (setq params (append 
7133                         (list (cons 'to-address 
7134                                     (funcall gnus-decode-encoded-word-function
7135                                              to-address))))))
7136         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7137         (insert-buffer-substring gnus-original-article-buffer)
7138         ;; Remove lines that may lead nndoc to misinterpret the
7139         ;; document type.
7140         (narrow-to-region
7141          (goto-char (point-min))
7142          (or (search-forward "\n\n" nil t) (point)))
7143         (goto-char (point-min))
7144         (delete-matching-lines "^Path:\\|^From ")
7145         (widen))
7146       (unwind-protect
7147           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7148                     (gnus-newsgroup-ephemeral-ignored-charsets
7149                      gnus-newsgroup-ignored-charsets))
7150                 (gnus-group-read-ephemeral-group
7151                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7152                               (nndoc-article-type
7153                                ,(if force 'mbox 'guess))) t))
7154               ;; Make all postings to this group go to the parent group.
7155               (nconc (gnus-info-params (gnus-get-info name))
7156                      params)
7157             ;; Couldn't select this doc group.
7158             (switch-to-buffer buf)
7159             (gnus-set-global-variables)
7160             (gnus-configure-windows 'summary)
7161             (gnus-message 3 "Article couldn't be entered?"))
7162         (kill-buffer dig)))))
7163
7164 (defun gnus-summary-read-document (n)
7165   "Open a new group based on the current article(s).
7166 This will allow you to read digests and other similar
7167 documents as newsgroups.
7168 Obeys the standard process/prefix convention."
7169   (interactive "P")
7170   (let* ((articles (gnus-summary-work-articles n))
7171          (ogroup gnus-newsgroup-name)
7172          (params (append (gnus-info-params (gnus-get-info ogroup))
7173                          (list (cons 'to-group ogroup))))
7174          article group egroup groups vgroup)
7175     (while (setq article (pop articles))
7176       (setq group (format "%s-%d" gnus-newsgroup-name article))
7177       (gnus-summary-remove-process-mark article)
7178       (when (gnus-summary-display-article article)
7179         (save-excursion
7180           (with-temp-buffer
7181             (insert-buffer-substring gnus-original-article-buffer)
7182             ;; Remove some headers that may lead nndoc to make
7183             ;; the wrong guess.
7184             (message-narrow-to-head)
7185             (goto-char (point-min))
7186             (delete-matching-lines "^\\(Path\\):\\|^From ")
7187             (widen)
7188             (if (setq egroup
7189                       (gnus-group-read-ephemeral-group
7190                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7191                                      (nndoc-article-type guess))
7192                        t nil t))
7193                 (progn
7194                   ;; Make all postings to this group go to the parent group.
7195                   (nconc (gnus-info-params (gnus-get-info egroup))
7196                          params)
7197                   (push egroup groups))
7198               ;; Couldn't select this doc group.
7199               (gnus-error 3 "Article couldn't be entered"))))))
7200     ;; Now we have selected all the documents.
7201     (cond
7202      ((not groups)
7203       (error "None of the articles could be interpreted as documents"))
7204      ((gnus-group-read-ephemeral-group
7205        (setq vgroup (format
7206                      "nnvirtual:%s-%s" gnus-newsgroup-name
7207                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7208        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7209        t
7210        (cons (current-buffer) 'summary)))
7211      (t
7212       (error "Couldn't select virtual nndoc group")))))
7213
7214 (defun gnus-summary-isearch-article (&optional regexp-p)
7215   "Do incremental search forward on the current article.
7216 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7217   (interactive "P")
7218   (let* ((gnus-inhibit-treatment t)
7219          (old (gnus-summary-select-article)))
7220     (gnus-configure-windows 'article)
7221     (gnus-eval-in-buffer-window gnus-article-buffer
7222       (save-restriction
7223         (widen)
7224         (when (eq 'old old)
7225           (gnus-article-show-all-headers))
7226         (goto-char (point-min))
7227         (isearch-forward regexp-p)))))
7228
7229 (defun gnus-summary-search-article-forward (regexp &optional backward)
7230   "Search for an article containing REGEXP forward.
7231 If BACKWARD, search backward instead."
7232   (interactive
7233    (list (read-string
7234           (format "Search article %s (regexp%s): "
7235                   (if current-prefix-arg "backward" "forward")
7236                   (if gnus-last-search-regexp
7237                       (concat ", default " gnus-last-search-regexp)
7238                     "")))
7239          current-prefix-arg))
7240   (if (string-equal regexp "")
7241       (setq regexp (or gnus-last-search-regexp ""))
7242     (setq gnus-last-search-regexp regexp)
7243     (setq gnus-article-before-search gnus-current-article))
7244   ;; Intentionally set gnus-last-article.
7245   (setq gnus-last-article gnus-article-before-search)
7246   (let ((gnus-last-article gnus-last-article))
7247     (if (gnus-summary-search-article regexp backward)
7248         (gnus-summary-show-thread)
7249       (error "Search failed: \"%s\"" regexp))))
7250
7251 (defun gnus-summary-search-article-backward (regexp)
7252   "Search for an article containing REGEXP backward."
7253   (interactive
7254    (list (read-string
7255           (format "Search article backward (regexp%s): "
7256                   (if gnus-last-search-regexp
7257                       (concat ", default " gnus-last-search-regexp)
7258                     "")))))
7259   (gnus-summary-search-article-forward regexp 'backward))
7260
7261 (eval-when-compile
7262   (defmacro gnus-summary-search-article-position-point (regexp backward)
7263     "Dehighlight the last matched text and goto the beginning position."
7264     (` (if (and gnus-summary-search-article-matched-data
7265                 (let ((text (caddr gnus-summary-search-article-matched-data))
7266                       (inhibit-read-only t)
7267                       buffer-read-only)
7268                   (delete-region
7269                    (goto-char (car gnus-summary-search-article-matched-data))
7270                    (cadr gnus-summary-search-article-matched-data))
7271                   (insert text)
7272                   (string-match (, regexp) text)))
7273            (if (, backward) (beginning-of-line) (end-of-line))
7274          (goto-char (if (, backward) (point-max) (point-min))))))
7275
7276   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7277     "Place point where X-Face image is displayed."
7278     (if (featurep 'xemacs)
7279         (` (let ((end (if (search-forward "\n\n" nil t)
7280                           (goto-char (1- (point)))
7281                         (point-min)))
7282                  extent)
7283              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7284              (unless (and (re-search-forward "^From:" end t)
7285                           (setq extent (extent-at (point)))
7286                           (extent-begin-glyph extent))
7287                (goto-char (, opoint)))))
7288       (` (let ((end (if (search-forward "\n\n" nil t)
7289                         (goto-char (1- (point)))
7290                       (point-min)))
7291                (start (or (search-backward "\n\n" nil t) (point-min))))
7292            (goto-char
7293             (or (text-property-any start end 'x-face-image t);; x-face-e21
7294                 (text-property-any start end 'x-face-mule-bitmap-image t)
7295                 (, opoint)))))))
7296
7297   (defmacro gnus-summary-search-article-highlight-matched-text
7298     (backward treated x-face)
7299     "Highlight matched text in the function `gnus-summary-search-article'."
7300     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7301              (end (set-marker (make-marker) (match-end 0)))
7302              (inhibit-read-only t)
7303              buffer-read-only)
7304          (unless treated
7305            (let ((,@
7306                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7307                     (mapcar
7308                      (lambda (item) (setq items (delq item items)))
7309                      '(gnus-treat-buttonize
7310                        gnus-treat-fill-article
7311                        gnus-treat-fill-long-lines
7312                        gnus-treat-emphasize
7313                        gnus-treat-highlight-headers
7314                        gnus-treat-highlight-citation
7315                        gnus-treat-highlight-signature
7316                        gnus-treat-overstrike
7317                        gnus-treat-display-xface
7318                        gnus-treat-buttonize-head
7319                        gnus-treat-decode-article-as-default-mime-charset))
7320                     (static-if (featurep 'xemacs)
7321                         items
7322                       (cons '(x-face-mule-delete-x-face-field
7323                               (quote never))
7324                             items))))
7325                  (gnus-treat-display-xface
7326                   (when (, x-face) gnus-treat-display-xface)))
7327              (gnus-article-prepare-mime-display)))
7328          (goto-char (if (, backward) start end))
7329          (when (, x-face)
7330            (gnus-summary-search-article-highlight-goto-x-face (point)))
7331          (setq gnus-summary-search-article-matched-data
7332                (list start end (buffer-substring start end)))
7333          (unless (eq start end);; matched text has been deleted. :-<
7334            (put-text-property start end 'face
7335                               (or (find-face 'isearch)
7336                                   'secondary-selection))))))
7337   )
7338
7339 (defun gnus-summary-search-article (regexp &optional backward)
7340   "Search for an article containing REGEXP.
7341 Optional argument BACKWARD means do search for backward.
7342 `gnus-select-article-hook' is not called during the search."
7343   ;; We have to require this here to make sure that the following
7344   ;; dynamic binding isn't shadowed by autoloading.
7345   (require 'gnus-async)
7346   (require 'gnus-art)
7347   (let ((gnus-select-article-hook nil)  ;Disable hook.
7348         (gnus-article-display-hook nil)
7349         (gnus-article-prepare-hook nil)
7350         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7351         (gnus-use-article-prefetch nil)
7352         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7353         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7354         (sum (current-buffer))
7355         (found nil)
7356         point treated)
7357     (gnus-save-hidden-threads
7358       (static-if (featurep 'xemacs)
7359           (let ((gnus-inhibit-treatment t))
7360             (setq treated (eq 'old (gnus-summary-select-article)))
7361             (when (and treated
7362                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7363                                  (window-live-p (get-buffer-window
7364                                                  gnus-article-buffer t)))))
7365               (gnus-summary-select-article nil t)
7366               (setq treated nil)))
7367         (let ((gnus-inhibit-treatment t)
7368               (x-face-mule-delete-x-face-field 'never))
7369           (setq treated (eq 'old (gnus-summary-select-article)))
7370           (when (and treated
7371                      (not
7372                       (and (gnus-buffer-live-p gnus-article-buffer)
7373                            (window-live-p (get-buffer-window
7374                                            gnus-article-buffer t))
7375                            (or (not (string-match "^\\^X-Face:" regexp))
7376                                (with-current-buffer gnus-article-buffer
7377                                  gnus-summary-search-article-matched-data)))))
7378             (gnus-summary-select-article nil t)
7379             (setq treated nil))))
7380       (set-buffer gnus-article-buffer)
7381       (widen)
7382       (if treated
7383           (progn
7384             (gnus-article-show-all-headers)
7385             (gnus-summary-search-article-position-point regexp backward))
7386         (goto-char (if backward (point-max) (point-min))))
7387       (while (not found)
7388         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7389         (if (if backward
7390                 (re-search-backward regexp nil t)
7391               (re-search-forward regexp nil t))
7392             ;; We found the regexp.
7393             (progn
7394               (gnus-summary-search-article-highlight-matched-text
7395                backward treated (string-match "^\\^X-Face:" regexp))
7396               (setq found 'found)
7397               (forward-line
7398                (/ (- 2 (window-height
7399                         (get-buffer-window gnus-article-buffer t)))
7400                   2))
7401               (set-window-start
7402                (get-buffer-window (current-buffer))
7403                (point))
7404               (set-buffer sum)
7405               (setq point (point)))
7406           ;; We didn't find it, so we go to the next article.
7407           (set-buffer sum)
7408           (setq found 'not)
7409           (while (eq found 'not)
7410             (if (not (if backward (gnus-summary-find-prev)
7411                        (gnus-summary-find-next)))
7412                 ;; No more articles.
7413                 (setq found t)
7414               ;; Select the next article and adjust point.
7415               (unless (gnus-summary-article-sparse-p
7416                        (gnus-summary-article-number))
7417                 (setq found nil)
7418                 (let ((gnus-inhibit-treatment t))
7419                   (gnus-summary-select-article))
7420                 (setq treated nil)
7421                 (set-buffer gnus-article-buffer)
7422                 (widen)
7423                 (goto-char (if backward (point-max) (point-min))))))))
7424       (gnus-message 7 ""))
7425     ;; Return whether we found the regexp.
7426     (when (eq found 'found)
7427       (goto-char point)
7428       (gnus-summary-show-thread)
7429       (gnus-summary-goto-subject gnus-current-article)
7430       (gnus-summary-position-point)
7431       t)))
7432
7433 (defun gnus-summary-find-matching (header regexp &optional backward unread
7434                                           not-case-fold)
7435   "Return a list of all articles that match REGEXP on HEADER.
7436 The search stars on the current article and goes forwards unless
7437 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7438 If UNREAD is non-nil, only unread articles will
7439 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7440 in the comparisons."
7441   (let ((data (if (eq backward 'all) gnus-newsgroup-data
7442                 (gnus-data-find-list
7443                  (gnus-summary-article-number) (gnus-data-list backward))))
7444         (case-fold-search (not not-case-fold))
7445         articles d func)
7446     (if (consp header)
7447         (if (eq (car header) 'extra)
7448             (setq func
7449                   `(lambda (h)
7450                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7451                          "")))
7452           (error "%s is an invalid header" header))
7453       (unless (fboundp (intern (concat "mail-header-" header)))
7454         (error "%s is not a valid header" header))
7455       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7456     (while data
7457       (setq d (car data))
7458       (and (or (not unread)             ; We want all articles...
7459                (gnus-data-unread-p d))  ; Or just unreads.
7460            (vectorp (gnus-data-header d)) ; It's not a pseudo.
7461            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
7462            (push (gnus-data-number d) articles)) ; Success!
7463       (setq data (cdr data)))
7464     (nreverse articles)))
7465
7466 (defun gnus-summary-execute-command (header regexp command &optional backward)
7467   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7468 If HEADER is an empty string (or nil), the match is done on the entire
7469 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7470   (interactive
7471    (list (let ((completion-ignore-case t))
7472            (completing-read
7473             "Header name: "
7474             (mapcar (lambda (string) (list string))
7475                     '("Number" "Subject" "From" "Lines" "Date"
7476                       "Message-ID" "Xref" "References" "Body"))
7477             nil 'require-match))
7478          (read-string "Regexp: ")
7479          (read-key-sequence "Command: ")
7480          current-prefix-arg))
7481   (when (equal header "Body")
7482     (setq header ""))
7483   ;; Hidden thread subtrees must be searched as well.
7484   (gnus-summary-show-all-threads)
7485   ;; We don't want to change current point nor window configuration.
7486   (save-excursion
7487     (save-window-excursion
7488       (gnus-message 6 "Executing %s..." (key-description command))
7489       ;; We'd like to execute COMMAND interactively so as to give arguments.
7490       (gnus-execute header regexp
7491                     `(call-interactively ',(key-binding command))
7492                     backward)
7493       (gnus-message 6 "Executing %s...done" (key-description command)))))
7494
7495 (defun gnus-summary-beginning-of-article ()
7496   "Scroll the article back to the beginning."
7497   (interactive)
7498   (gnus-summary-select-article)
7499   (gnus-configure-windows 'article)
7500   (gnus-eval-in-buffer-window gnus-article-buffer
7501     (widen)
7502     (goto-char (point-min))
7503     (when gnus-page-broken
7504       (gnus-narrow-to-page))))
7505
7506 (defun gnus-summary-end-of-article ()
7507   "Scroll to the end of the article."
7508   (interactive)
7509   (gnus-summary-select-article)
7510   (gnus-configure-windows 'article)
7511   (gnus-eval-in-buffer-window gnus-article-buffer
7512     (widen)
7513     (goto-char (point-max))
7514     (recenter -3)
7515     (when gnus-page-broken
7516       (gnus-narrow-to-page))))
7517
7518 (defun gnus-summary-print-article (&optional filename n)
7519   "Generate and print a PostScript image of the N next (mail) articles.
7520
7521 If N is negative, print the N previous articles.  If N is nil and articles
7522 have been marked with the process mark, print these instead.
7523
7524 If the optional first argument FILENAME is nil, send the image to the
7525 printer.  If FILENAME is a string, save the PostScript image in a file with
7526 that name.  If FILENAME is a number, prompt the user for the name of the file
7527 to save in."
7528   (interactive (list (ps-print-preprint current-prefix-arg)
7529                      current-prefix-arg))
7530   (dolist (article (gnus-summary-work-articles n))
7531     (gnus-summary-select-article nil nil 'pseudo article)
7532     (gnus-eval-in-buffer-window gnus-article-buffer
7533       (let ((buffer (generate-new-buffer " *print*")))
7534         (unwind-protect
7535             (progn
7536               (copy-to-buffer buffer (point-min) (point-max))
7537               (set-buffer buffer)
7538               (gnus-article-delete-invisible-text)
7539               (let ((ps-left-header
7540                      (list
7541                       (concat "("
7542                               (mail-header-subject gnus-current-headers) ")")
7543                       (concat "("
7544                               (mail-header-from gnus-current-headers) ")")))
7545                     (ps-right-header
7546                      (list
7547                       "/pagenumberstring load"
7548                       (concat "("
7549                               (mail-header-date gnus-current-headers) ")"))))
7550                 (gnus-run-hooks 'gnus-ps-print-hook)
7551                 (save-excursion
7552                   (ps-print-buffer-with-faces filename))))
7553           (kill-buffer buffer))))))
7554
7555 (defun gnus-summary-show-article (&optional arg)
7556   "Force re-fetching of the current article.
7557 If ARG (the prefix) is a number, show the article with the charset
7558 defined in `gnus-summary-show-article-charset-alist', or the charset
7559 inputed.
7560 If ARG (the prefix) is non-nil and not a number, show the raw article
7561 without any article massaging functions being run."
7562   (interactive "P")
7563   (cond
7564    ((numberp arg)
7565     (let ((gnus-newsgroup-charset
7566            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7567                (read-coding-system "Charset: ")))
7568           (gnus-newsgroup-ignored-charsets 'gnus-all))
7569       (gnus-summary-select-article nil 'force)
7570       (let ((deps gnus-newsgroup-dependencies)
7571             head header)
7572         (save-excursion
7573           (set-buffer gnus-original-article-buffer)
7574           (save-restriction
7575             (message-narrow-to-head)
7576             (setq head (buffer-string)))
7577           (with-temp-buffer
7578             (insert (format "211 %d Article retrieved.\n"
7579                             (cdr gnus-article-current)))
7580             (insert head)
7581             (insert ".\n")
7582             (let ((nntp-server-buffer (current-buffer)))
7583               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7584         (gnus-data-set-header
7585          (gnus-data-find (cdr gnus-article-current))
7586          header)
7587         (gnus-summary-update-article-line
7588          (cdr gnus-article-current) header))))
7589    ((not arg)
7590     ;; Select the article the normal way.
7591     (gnus-summary-select-article nil 'force))
7592    (t
7593     ;; We have to require this here to make sure that the following
7594     ;; dynamic binding isn't shadowed by autoloading.
7595     (require 'gnus-async)
7596     (require 'gnus-art)
7597     ;; Bind the article treatment functions to nil.
7598     (let ((gnus-have-all-headers t)
7599           gnus-article-display-hook
7600           gnus-article-prepare-hook
7601           gnus-article-decode-hook
7602           gnus-break-pages
7603           gnus-show-mime)
7604       (gnus-summary-select-article nil 'force))))
7605   (gnus-summary-goto-subject gnus-current-article)
7606   (gnus-summary-position-point))
7607
7608 (defun gnus-summary-verbose-headers (&optional arg)
7609   "Toggle permanent full header display.
7610 If ARG is a positive number, turn header display on.
7611 If ARG is a negative number, turn header display off."
7612   (interactive "P")
7613   (setq gnus-show-all-headers
7614         (cond ((or (not (numberp arg))
7615                    (zerop arg))
7616                (not gnus-show-all-headers))
7617               ((natnump arg)
7618                t)))
7619   (gnus-summary-show-article))
7620
7621 (defun gnus-summary-toggle-header (&optional arg)
7622   "Show the headers if they are hidden, or hide them if they are shown.
7623 If ARG is a positive number, show the entire header.
7624 If ARG is a negative number, hide the unwanted header lines."
7625   (interactive "P")
7626   (save-excursion
7627     (set-buffer gnus-article-buffer)
7628     (save-restriction
7629       (let* ((buffer-read-only nil)
7630              (inhibit-point-motion-hooks t)
7631              hidden e)
7632         (setq hidden
7633               (if (numberp arg)
7634                   (>= arg 0)
7635                 (save-restriction
7636                   (article-narrow-to-head)
7637                   (gnus-article-hidden-text-p 'headers))))
7638         (goto-char (point-min))
7639         (when (search-forward "\n\n" nil t)
7640           (delete-region (point-min) (1- (point))))
7641         (goto-char (point-min))
7642         (save-excursion
7643           (set-buffer gnus-original-article-buffer)
7644           (goto-char (point-min))
7645           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7646         (insert-buffer-substring gnus-original-article-buffer 1 e)
7647         (save-restriction
7648           (narrow-to-region (point-min) (point))
7649           (article-decode-encoded-words)
7650           (if  hidden
7651               (let ((gnus-treat-hide-headers nil)
7652                     (gnus-treat-hide-boring-headers nil))
7653                 (setq gnus-article-wash-types
7654                       (delq 'headers gnus-article-wash-types))
7655                 (gnus-treat-article 'head))
7656             (gnus-treat-article 'head)))
7657         (gnus-set-mode-line 'article)))))
7658
7659 (defun gnus-summary-show-all-headers ()
7660   "Make all header lines visible."
7661   (interactive)
7662   (gnus-article-show-all-headers))
7663
7664 (defun gnus-summary-toggle-mime (&optional arg)
7665   "Toggle MIME processing.
7666 If ARG is a positive number, turn MIME processing on."
7667   (interactive "P")
7668   (setq gnus-show-mime
7669         (if (null arg)
7670             (not gnus-show-mime)
7671           (> (prefix-numeric-value arg) 0)))
7672   (gnus-summary-select-article t 'force))
7673
7674 (defun gnus-summary-caesar-message (&optional arg)
7675   "Caesar rotate the current article by 13.
7676 The numerical prefix specifies how many places to rotate each letter
7677 forward."
7678   (interactive "P")
7679   (gnus-summary-select-article)
7680   (let ((mail-header-separator ""))
7681     (gnus-eval-in-buffer-window gnus-article-buffer
7682       (save-restriction
7683         (widen)
7684         (let ((start (window-start))
7685               buffer-read-only)
7686           (message-caesar-buffer-body arg)
7687           (set-window-start (get-buffer-window (current-buffer)) start))))))
7688
7689 (defun gnus-summary-stop-page-breaking ()
7690   "Stop page breaking in the current article."
7691   (interactive)
7692   (gnus-summary-select-article)
7693   (gnus-eval-in-buffer-window gnus-article-buffer
7694     (widen)
7695     (when (gnus-visual-p 'page-marker)
7696       (let ((buffer-read-only nil))
7697         (gnus-remove-text-with-property 'gnus-prev)
7698         (gnus-remove-text-with-property 'gnus-next))
7699       (setq gnus-page-broken nil))))
7700
7701 (defun gnus-summary-move-article (&optional n to-newsgroup
7702                                             select-method action)
7703   "Move the current article to a different newsgroup.
7704 If N is a positive number, move the N next articles.
7705 If N is a negative number, move the N previous articles.
7706 If N is nil and any articles have been marked with the process mark,
7707 move those articles instead.
7708 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7709 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7710 re-spool using this method.
7711
7712 For this function to work, both the current newsgroup and the
7713 newsgroup that you want to move to have to support the `request-move'
7714 and `request-accept' functions.
7715
7716 ACTION can be either `move' (the default), `crosspost' or `copy'."
7717   (interactive "P")
7718   (unless action
7719     (setq action 'move))
7720   ;; Disable marking as read.
7721   (let (gnus-mark-article-hook)
7722     (save-window-excursion
7723       (gnus-summary-select-article)))
7724   ;; Check whether the source group supports the required functions.
7725   (cond ((and (eq action 'move)
7726               (not (gnus-check-backend-function
7727                     'request-move-article gnus-newsgroup-name)))
7728          (error "The current group does not support article moving"))
7729         ((and (eq action 'crosspost)
7730               (not (gnus-check-backend-function
7731                     'request-replace-article gnus-newsgroup-name)))
7732          (error "The current group does not support article editing")))
7733   (let ((articles (gnus-summary-work-articles n))
7734         (prefix (if (gnus-check-backend-function
7735                     'request-move-article gnus-newsgroup-name)
7736                     (gnus-group-real-prefix gnus-newsgroup-name)
7737                   ""))
7738         (names '((move "Move" "Moving")
7739                  (copy "Copy" "Copying")
7740                  (crosspost "Crosspost" "Crossposting")))
7741         (copy-buf (save-excursion
7742                     (nnheader-set-temp-buffer " *copy article*")))
7743         (default-marks gnus-article-mark-lists)
7744         (no-expire-marks (delete '(expirable . expire)
7745                                  (copy-sequence gnus-article-mark-lists)))
7746         art-group to-method new-xref article to-groups)
7747     (unless (assq action names)
7748       (error "Unknown action %s" action))
7749     ;; Read the newsgroup name.
7750     (when (and (not to-newsgroup)
7751                (not select-method))
7752       (setq to-newsgroup
7753             (gnus-read-move-group-name
7754              (cadr (assq action names))
7755              (symbol-value (intern (format "gnus-current-%s-group" action)))
7756              articles prefix))
7757       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7758     (setq to-method (or select-method
7759                         (gnus-server-to-method
7760                          (gnus-group-method to-newsgroup))))
7761     ;; Check the method we are to move this article to...
7762     (unless (gnus-check-backend-function
7763              'request-accept-article (car to-method))
7764       (error "%s does not support article copying" (car to-method)))
7765     (unless (gnus-check-server to-method)
7766       (error "Can't open server %s" (car to-method)))
7767     (gnus-message 6 "%s to %s: %s..."
7768                   (caddr (assq action names))
7769                   (or (car select-method) to-newsgroup) articles)
7770     (while articles
7771       (setq article (pop articles))
7772       (setq
7773        art-group
7774        (cond
7775         ;; Move the article.
7776         ((eq action 'move)
7777          ;; Remove this article from future suppression.
7778          (gnus-dup-unsuppress-article article)
7779          (gnus-request-move-article
7780           article                       ; Article to move
7781           gnus-newsgroup-name           ; From newsgroup
7782           (nth 1 (gnus-find-method-for-group
7783                   gnus-newsgroup-name)) ; Server
7784           (list 'gnus-request-accept-article
7785                 to-newsgroup (list 'quote select-method)
7786                 (not articles) t)       ; Accept form
7787           (not articles)))              ; Only save nov last time
7788         ;; Copy the article.
7789         ((eq action 'copy)
7790          (save-excursion
7791            (set-buffer copy-buf)
7792            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7793              (gnus-request-accept-article
7794               to-newsgroup select-method (not articles) t))))
7795         ;; Crosspost the article.
7796         ((eq action 'crosspost)
7797          (let ((xref (message-tokenize-header
7798                       (mail-header-xref (gnus-summary-article-header article))
7799                       " ")))
7800            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7801                                   ":" article))
7802            (unless xref
7803              (setq xref (list (system-name))))
7804            (setq new-xref
7805                  (concat
7806                   (mapconcat 'identity
7807                              (delete "Xref:" (delete new-xref xref))
7808                              " ")
7809                   " " new-xref))
7810            (save-excursion
7811              (set-buffer copy-buf)
7812              ;; First put the article in the destination group.
7813              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7814              (when (consp (setq art-group
7815                                 (gnus-request-accept-article
7816                                  to-newsgroup select-method (not articles))))
7817                (setq new-xref (concat new-xref " " (car art-group)
7818                                       ":" (cdr art-group)))
7819                ;; Now we have the new Xrefs header, so we insert
7820                ;; it and replace the new article.
7821                (nnheader-replace-header "Xref" new-xref)
7822                (gnus-request-replace-article
7823                 (cdr art-group) to-newsgroup (current-buffer))
7824                art-group))))))
7825       (cond
7826        ((not art-group)
7827         (gnus-message 1 "Couldn't %s article %s: %s"
7828                       (cadr (assq action names)) article
7829                       (nnheader-get-report (car to-method))))
7830        ((eq art-group 'junk)
7831         (when (eq action 'move)
7832           (gnus-summary-mark-article article gnus-canceled-mark)
7833           (gnus-message 4 "Deleted article %s" article)))
7834        (t
7835         (let* ((pto-group (gnus-group-prefixed-name
7836                            (car art-group) to-method))
7837                (entry
7838                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7839                (info (nth 2 entry))
7840                (to-group (gnus-info-group info))
7841                to-marks)
7842           ;; Update the group that has been moved to.
7843           (when (and info
7844                      (memq action '(move copy)))
7845             (unless (member to-group to-groups)
7846               (push to-group to-groups))
7847
7848             (unless (memq article gnus-newsgroup-unreads)
7849               (push 'read to-marks)
7850               (gnus-info-set-read
7851                info (gnus-add-to-range (gnus-info-read info)
7852                                        (list (cdr art-group)))))
7853
7854             ;; See whether the article is to be put in the cache.
7855             (let ((marks (if (gnus-group-auto-expirable-p to-group)
7856                              default-marks
7857                            no-expire-marks))
7858                   (to-article (cdr art-group)))
7859
7860               ;; Enter the article into the cache in the new group,
7861               ;; if that is required.
7862               (when gnus-use-cache
7863                 (gnus-cache-possibly-enter-article
7864                  to-group to-article
7865                  (let ((header (copy-sequence
7866                                 (gnus-summary-article-header article))))
7867                    (mail-header-set-number header to-article)
7868                    header)
7869                  (memq article gnus-newsgroup-marked)
7870                  (memq article gnus-newsgroup-dormant)
7871                  (memq article gnus-newsgroup-unreads)))
7872
7873               (when gnus-preserve-marks
7874                 ;; Copy any marks over to the new group.
7875                 (when (and (equal to-group gnus-newsgroup-name)
7876                            (not (memq article gnus-newsgroup-unreads)))
7877                   ;; Mark this article as read in this group.
7878                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7879                   (setcdr (gnus-active to-group) to-article)
7880                   (setcdr gnus-newsgroup-active to-article))
7881
7882                 (while marks
7883                   (when (memq article (symbol-value
7884                                        (intern (format "gnus-newsgroup-%s"
7885                                                        (caar marks)))))
7886                     (push (cdar marks) to-marks)
7887                     ;; If the other group is the same as this group,
7888                     ;; then we have to add the mark to the list.
7889                     (when (equal to-group gnus-newsgroup-name)
7890                       (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7891                            (cons to-article
7892                                  (symbol-value
7893                                   (intern (format "gnus-newsgroup-%s"
7894                                                   (caar marks)))))))
7895                     ;; Copy the marks to other group.
7896                     (gnus-add-marked-articles
7897                      to-group (cdar marks) (list to-article) info))
7898                   (setq marks (cdr marks)))
7899
7900                 (gnus-request-set-mark to-group (list (list (list to-article)
7901                                                             'set
7902                                                             to-marks))))
7903
7904               (gnus-dribble-enter
7905                (concat "(gnus-group-set-info '"
7906                        (gnus-prin1-to-string (gnus-get-info to-group))
7907                        ")"))))
7908
7909           ;; Update the Xref header in this article to point to
7910           ;; the new crossposted article we have just created.
7911           (when (eq action 'crosspost)
7912             (save-excursion
7913               (set-buffer copy-buf)
7914               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7915               (nnheader-replace-header "Xref" new-xref)
7916               (gnus-request-replace-article
7917                article gnus-newsgroup-name (current-buffer)))))
7918
7919         ;;;!!!Why is this necessary?
7920         (set-buffer gnus-summary-buffer)
7921
7922         (gnus-summary-goto-subject article)
7923         (when (eq action 'move)
7924           (gnus-summary-mark-article article gnus-canceled-mark))))
7925       (gnus-summary-remove-process-mark article))
7926     ;; Re-activate all groups that have been moved to.
7927     (while to-groups
7928       (save-excursion
7929         (set-buffer gnus-group-buffer)
7930         (when (gnus-group-goto-group (car to-groups) t)
7931           (gnus-group-get-new-news-this-group 1 t))
7932         (pop to-groups)))
7933
7934     (gnus-kill-buffer copy-buf)
7935     (gnus-summary-position-point)
7936     (gnus-set-mode-line 'summary)))
7937
7938 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7939   "Move the current article to a different newsgroup.
7940 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7941 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7942 re-spool using this method."
7943   (interactive "P")
7944   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7945
7946 (defun gnus-summary-crosspost-article (&optional n)
7947   "Crosspost the current article to some other group."
7948   (interactive "P")
7949   (gnus-summary-move-article n nil nil 'crosspost))
7950
7951 (defcustom gnus-summary-respool-default-method nil
7952   "Default method for respooling an article.
7953 If nil, use to the current newsgroup method."
7954   :type '(choice (gnus-select-method :value (nnml ""))
7955                  (const nil))
7956   :group 'gnus-summary-mail)
7957
7958 (defun gnus-summary-respool-article (&optional n method)
7959   "Respool the current article.
7960 The article will be squeezed through the mail spooling process again,
7961 which means that it will be put in some mail newsgroup or other
7962 depending on `nnmail-split-methods'.
7963 If N is a positive number, respool the N next articles.
7964 If N is a negative number, respool the N previous articles.
7965 If N is nil and any articles have been marked with the process mark,
7966 respool those articles instead.
7967
7968 Respooling can be done both from mail groups and \"real\" newsgroups.
7969 In the former case, the articles in question will be moved from the
7970 current group into whatever groups they are destined to.  In the
7971 latter case, they will be copied into the relevant groups."
7972   (interactive
7973    (list current-prefix-arg
7974          (let* ((methods (gnus-methods-using 'respool))
7975                 (methname
7976                  (symbol-name (or gnus-summary-respool-default-method
7977                                   (car (gnus-find-method-for-group
7978                                         gnus-newsgroup-name)))))
7979                 (method
7980                  (gnus-completing-read
7981                   methname "What backend do you want to use when respooling?"
7982                   methods nil t nil 'gnus-mail-method-history))
7983                 ms)
7984            (cond
7985             ((zerop (length (setq ms (gnus-servers-using-backend
7986                                       (intern method)))))
7987              (list (intern method) ""))
7988             ((= 1 (length ms))
7989              (car ms))
7990             (t
7991              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7992                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7993                            ms-alist))))))))
7994   (unless method
7995     (error "No method given for respooling"))
7996   (if (assoc (symbol-name
7997               (car (gnus-find-method-for-group gnus-newsgroup-name)))
7998              (gnus-methods-using 'respool))
7999       (gnus-summary-move-article n nil method)
8000     (gnus-summary-copy-article n nil method)))
8001
8002 (defun gnus-summary-import-article (file)
8003   "Import an arbitrary file into a mail newsgroup."
8004   (interactive "fImport file: ")
8005   (let ((group gnus-newsgroup-name)
8006         (now (current-time))
8007         atts lines)
8008     (unless (gnus-check-backend-function 'request-accept-article group)
8009       (error "%s does not support article importing" group))
8010     (or (file-readable-p file)
8011         (not (file-regular-p file))
8012         (error "Can't read %s" file))
8013     (save-excursion
8014       (set-buffer (gnus-get-buffer-create " *import file*"))
8015       (erase-buffer)
8016       (nnheader-insert-file-contents file)
8017       (goto-char (point-min))
8018       (unless (nnheader-article-p)
8019         ;; This doesn't look like an article, so we fudge some headers.
8020         (setq atts (file-attributes file)
8021               lines (count-lines (point-min) (point-max)))
8022         (insert "From: " (read-string "From: ") "\n"
8023                 "Subject: " (read-string "Subject: ") "\n"
8024                 "Date: " (message-make-date (nth 5 atts))
8025                 "\n"
8026                 "Message-ID: " (message-make-message-id) "\n"
8027                 "Lines: " (int-to-string lines) "\n"
8028                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8029       (gnus-request-accept-article group nil t)
8030       (kill-buffer (current-buffer)))))
8031
8032 (defun gnus-summary-article-posted-p ()
8033   "Say whether the current (mail) article is available from news as well.
8034 This will be the case if the article has both been mailed and posted."
8035   (interactive)
8036   (let ((id (mail-header-references (gnus-summary-article-header)))
8037         (gnus-override-method (car (gnus-refer-article-methods))))
8038     (if (gnus-request-head id "")
8039         (gnus-message 2 "The current message was found on %s"
8040                       gnus-override-method)
8041       (gnus-message 2 "The current message couldn't be found on %s"
8042                     gnus-override-method)
8043       nil)))
8044
8045 (defun gnus-summary-expire-articles (&optional now)
8046   "Expire all articles that are marked as expirable in the current group."
8047   (interactive)
8048   (when (gnus-check-backend-function
8049          'request-expire-articles gnus-newsgroup-name)
8050     ;; This backend supports expiry.
8051     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8052            (expirable (if total
8053                           (progn
8054                             ;; We need to update the info for
8055                             ;; this group for `gnus-list-of-read-articles'
8056                             ;; to give us the right answer.
8057                             (gnus-run-hooks 'gnus-exit-group-hook)
8058                             (gnus-summary-update-info)
8059                             (gnus-list-of-read-articles gnus-newsgroup-name))
8060                         (setq gnus-newsgroup-expirable
8061                               (sort gnus-newsgroup-expirable '<))))
8062            (expiry-wait (if now 'immediate
8063                           (gnus-group-find-parameter
8064                            gnus-newsgroup-name 'expiry-wait)))
8065            (nnmail-expiry-target
8066             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8067                 nnmail-expiry-target))
8068            es)
8069       (when expirable
8070         ;; There are expirable articles in this group, so we run them
8071         ;; through the expiry process.
8072         (gnus-message 6 "Expiring articles...")
8073         (unless (gnus-check-group gnus-newsgroup-name)
8074           (error "Can't open server for %s" gnus-newsgroup-name))
8075         ;; The list of articles that weren't expired is returned.
8076         (save-excursion
8077           (if expiry-wait
8078               (let ((nnmail-expiry-wait-function nil)
8079                     (nnmail-expiry-wait expiry-wait))
8080                 (setq es (gnus-request-expire-articles
8081                           expirable gnus-newsgroup-name)))
8082             (setq es (gnus-request-expire-articles
8083                       expirable gnus-newsgroup-name)))
8084           (unless total
8085             (setq gnus-newsgroup-expirable es))
8086           ;; We go through the old list of expirable, and mark all
8087           ;; really expired articles as nonexistent.
8088           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8089             (let ((gnus-use-cache nil))
8090               (while expirable
8091                 (unless (memq (car expirable) es)
8092                   (when (gnus-data-find (car expirable))
8093                     (gnus-summary-mark-article
8094                      (car expirable) gnus-canceled-mark)))
8095                 (setq expirable (cdr expirable))))))
8096         (gnus-message 6 "Expiring articles...done")))))
8097
8098 (defun gnus-summary-expire-articles-now ()
8099   "Expunge all expirable articles in the current group.
8100 This means that *all* articles that are marked as expirable will be
8101 deleted forever, right now."
8102   (interactive)
8103   (or gnus-expert-user
8104       (gnus-yes-or-no-p
8105        "Are you really, really, really sure you want to delete all these messages? ")
8106       (error "Phew!"))
8107   (gnus-summary-expire-articles t))
8108
8109 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8110 (defun gnus-summary-delete-article (&optional n)
8111   "Delete the N next (mail) articles.
8112 This command actually deletes articles.  This is not a marking
8113 command.  The article will disappear forever from your life, never to
8114 return.
8115 If N is negative, delete backwards.
8116 If N is nil and articles have been marked with the process mark,
8117 delete these instead."
8118   (interactive "P")
8119   (unless (gnus-check-backend-function 'request-expire-articles
8120                                        gnus-newsgroup-name)
8121     (error "The current newsgroup does not support article deletion"))
8122   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8123     (error "Couldn't open server"))
8124   ;; Compute the list of articles to delete.
8125   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8126         not-deleted)
8127     (if (and gnus-novice-user
8128              (not (gnus-yes-or-no-p
8129                    (format "Do you really want to delete %s forever? "
8130                            (if (> (length articles) 1)
8131                                (format "these %s articles" (length articles))
8132                              "this article")))))
8133         ()
8134       ;; Delete the articles.
8135       (setq not-deleted (gnus-request-expire-articles
8136                          articles gnus-newsgroup-name 'force))
8137       (while articles
8138         (gnus-summary-remove-process-mark (car articles))
8139         ;; The backend might not have been able to delete the article
8140         ;; after all.
8141         (unless (memq (car articles) not-deleted)
8142           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8143         (setq articles (cdr articles)))
8144       (when not-deleted
8145         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8146     (gnus-summary-position-point)
8147     (gnus-set-mode-line 'summary)
8148     not-deleted))
8149
8150 (defun gnus-summary-edit-article (&optional force)
8151   "Edit the current article.
8152 This will have permanent effect only in mail groups.
8153 If FORCE is non-nil, allow editing of articles even in read-only
8154 groups."
8155   (interactive "P")
8156   (save-excursion
8157     (set-buffer gnus-summary-buffer)
8158     (let ((mail-parse-charset gnus-newsgroup-charset)
8159           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8160       (gnus-set-global-variables)
8161       (when (and (not force)
8162                  (gnus-group-read-only-p))
8163         (error "The current newsgroup does not support article editing"))
8164       (gnus-summary-show-article t)
8165       (gnus-article-edit-article
8166        'ignore
8167        `(lambda (no-highlight)
8168           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8169                 (message-options message-options)
8170                 (message-options-set-recipient)
8171                 (mail-parse-ignored-charsets
8172                  ',gnus-newsgroup-ignored-charsets))
8173             (gnus-summary-edit-article-done
8174              ,(or (mail-header-references gnus-current-headers) "")
8175              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8176
8177 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8178
8179 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8180                                                  no-highlight)
8181   "Make edits to the current article permanent."
8182   (interactive)
8183   (save-excursion
8184     ;; The buffer restriction contains the entire article if it exists.
8185     (when (article-goto-body)
8186       (let ((lines (count-lines (point) (point-max)))
8187             (length (- (point-max) (point)))
8188             (case-fold-search t)
8189             (body (copy-marker (point))))
8190         (goto-char (point-min))
8191         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8192           (delete-region (match-beginning 1) (match-end 1))
8193           (insert (number-to-string length)))
8194         (goto-char (point-min))
8195         (when (re-search-forward
8196                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8197           (delete-region (match-beginning 1) (match-end 1))
8198           (insert (number-to-string length)))
8199         (goto-char (point-min))
8200         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8201           (delete-region (match-beginning 1) (match-end 1))
8202           (insert (number-to-string lines))))))
8203   ;; Replace the article.
8204   (let ((buf (current-buffer)))
8205     (with-temp-buffer
8206       (insert-buffer-substring buf)
8207       
8208       (if (and (not read-only)
8209                (not (gnus-request-replace-article
8210                      (cdr gnus-article-current) (car gnus-article-current)
8211                      (current-buffer) t)))
8212           (error "Couldn't replace article")
8213         ;; Update the summary buffer.
8214         (if (and references
8215                  (equal (message-tokenize-header references " ")
8216                         (message-tokenize-header
8217                          (or (message-fetch-field "references") "") " ")))
8218             ;; We only have to update this line.
8219             (save-excursion
8220               (save-restriction
8221                 (message-narrow-to-head)
8222                 (let ((head (buffer-string))
8223                       header)
8224                   (with-temp-buffer
8225                     (insert (format "211 %d Article retrieved.\n"
8226                                     (cdr gnus-article-current)))
8227                     (insert head)
8228                     (insert ".\n")
8229                     (let ((nntp-server-buffer (current-buffer)))
8230                       (setq header (car (gnus-get-newsgroup-headers
8231                                          (save-excursion
8232                                            (set-buffer gnus-summary-buffer)
8233                                            gnus-newsgroup-dependencies)
8234                                          t))))
8235                     (save-excursion
8236                       (set-buffer gnus-summary-buffer)
8237                       (gnus-data-set-header
8238                        (gnus-data-find (cdr gnus-article-current))
8239                        header)
8240                       (gnus-summary-update-article-line
8241                        (cdr gnus-article-current) header))))))
8242           ;; Update threads.
8243           (set-buffer (or buffer gnus-summary-buffer))
8244           (gnus-summary-update-article (cdr gnus-article-current)))
8245         ;; Prettify the article buffer again.
8246         (unless no-highlight
8247           (save-excursion
8248             (set-buffer gnus-article-buffer)
8249             ;;;!!! Fix this -- article should be rehighlighted.
8250             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8251             (set-buffer gnus-original-article-buffer)
8252             (gnus-request-article
8253              (cdr gnus-article-current)
8254              (car gnus-article-current) (current-buffer))))
8255         ;; Prettify the summary buffer line.
8256         (when (gnus-visual-p 'summary-highlight 'highlight)
8257           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8258
8259 (defun gnus-summary-edit-wash (key)
8260   "Perform editing command KEY in the article buffer."
8261   (interactive
8262    (list
8263     (progn
8264       (message "%s" (concat (this-command-keys) "- "))
8265       (read-char))))
8266   (message "")
8267   (gnus-summary-edit-article)
8268   (execute-kbd-macro (concat (this-command-keys) key))
8269   (gnus-article-edit-done))
8270
8271 ;;; Respooling
8272
8273 (defun gnus-summary-respool-query (&optional silent trace)
8274   "Query where the respool algorithm would put this article."
8275   (interactive)
8276   (let (gnus-mark-article-hook)
8277     (gnus-summary-select-article)
8278     (save-excursion
8279       (set-buffer gnus-original-article-buffer)
8280       (save-restriction
8281         (message-narrow-to-head)
8282         (let ((groups (nnmail-article-group 'identity trace)))
8283           (unless silent
8284             (if groups
8285                 (message "This message would go to %s"
8286                          (mapconcat 'car groups ", "))
8287               (message "This message would go to no groups"))
8288             groups))))))
8289
8290 (defun gnus-summary-respool-trace ()
8291   "Trace where the respool algorithm would put this article.
8292 Display a buffer showing all fancy splitting patterns which matched."
8293   (interactive)
8294   (gnus-summary-respool-query nil t))
8295
8296 ;; Summary marking commands.
8297
8298 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8299   "Mark articles which has the same subject as read, and then select the next.
8300 If UNMARK is positive, remove any kind of mark.
8301 If UNMARK is negative, tick articles."
8302   (interactive "P")
8303   (when unmark
8304     (setq unmark (prefix-numeric-value unmark)))
8305   (let ((count
8306          (gnus-summary-mark-same-subject
8307           (gnus-summary-article-subject) unmark)))
8308     ;; Select next unread article.  If auto-select-same mode, should
8309     ;; select the first unread article.
8310     (gnus-summary-next-article t (and gnus-auto-select-same
8311                                       (gnus-summary-article-subject)))
8312     (gnus-message 7 "%d article%s marked as %s"
8313                   count (if (= count 1) " is" "s are")
8314                   (if unmark "unread" "read"))))
8315
8316 (defun gnus-summary-kill-same-subject (&optional unmark)
8317   "Mark articles which has the same subject as read.
8318 If UNMARK is positive, remove any kind of mark.
8319 If UNMARK is negative, tick articles."
8320   (interactive "P")
8321   (when unmark
8322     (setq unmark (prefix-numeric-value unmark)))
8323   (let ((count
8324          (gnus-summary-mark-same-subject
8325           (gnus-summary-article-subject) unmark)))
8326     ;; If marked as read, go to next unread subject.
8327     (when (null unmark)
8328       ;; Go to next unread subject.
8329       (gnus-summary-next-subject 1 t))
8330     (gnus-message 7 "%d articles are marked as %s"
8331                   count (if unmark "unread" "read"))))
8332
8333 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8334   "Mark articles with same SUBJECT as read, and return marked number.
8335 If optional argument UNMARK is positive, remove any kinds of marks.
8336 If optional argument UNMARK is negative, mark articles as unread instead."
8337   (let ((count 1))
8338     (save-excursion
8339       (cond
8340        ((null unmark)                   ; Mark as read.
8341         (while (and
8342                 (progn
8343                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8344                   (gnus-summary-show-thread) t)
8345                 (gnus-summary-find-subject subject))
8346           (setq count (1+ count))))
8347        ((> unmark 0)                    ; Tick.
8348         (while (and
8349                 (progn
8350                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8351                   (gnus-summary-show-thread) t)
8352                 (gnus-summary-find-subject subject))
8353           (setq count (1+ count))))
8354        (t                               ; Mark as unread.
8355         (while (and
8356                 (progn
8357                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8358                   (gnus-summary-show-thread) t)
8359                 (gnus-summary-find-subject subject))
8360           (setq count (1+ count)))))
8361       (gnus-set-mode-line 'summary)
8362       ;; Return the number of marked articles.
8363       count)))
8364
8365 (defun gnus-summary-mark-as-processable (n &optional unmark)
8366   "Set the process mark on the next N articles.
8367 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8368 the process mark instead.  The difference between N and the actual
8369 number of articles marked is returned."
8370   (interactive "p")
8371   (let ((backward (< n 0))
8372         (n (abs n)))
8373     (while (and
8374             (> n 0)
8375             (if unmark
8376                 (gnus-summary-remove-process-mark
8377                  (gnus-summary-article-number))
8378               (gnus-summary-set-process-mark (gnus-summary-article-number)))
8379             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8380       (setq n (1- n)))
8381     (when (/= 0 n)
8382       (gnus-message 7 "No more articles"))
8383     (gnus-summary-recenter)
8384     (gnus-summary-position-point)
8385     n))
8386
8387 (defun gnus-summary-unmark-as-processable (n)
8388   "Remove the process mark from the next N articles.
8389 If N is negative, unmark backward instead.  The difference between N and
8390 the actual number of articles unmarked is returned."
8391   (interactive "p")
8392   (gnus-summary-mark-as-processable n t))
8393
8394 (defun gnus-summary-unmark-all-processable ()
8395   "Remove the process mark from all articles."
8396   (interactive)
8397   (save-excursion
8398     (while gnus-newsgroup-processable
8399       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8400   (gnus-summary-position-point))
8401
8402 (defun gnus-summary-mark-as-expirable (n)
8403   "Mark N articles forward as expirable.
8404 If N is negative, mark backward instead.  The difference between N and
8405 the actual number of articles marked is returned."
8406   (interactive "p")
8407   (gnus-summary-mark-forward n gnus-expirable-mark))
8408
8409 (defun gnus-summary-mark-article-as-replied (article)
8410   "Mark ARTICLE replied and update the summary line."
8411   (push article gnus-newsgroup-replied)
8412   (let ((buffer-read-only nil))
8413     (when (gnus-summary-goto-subject article nil t)
8414       (gnus-summary-update-secondary-mark article))))
8415
8416 (defun gnus-summary-set-bookmark (article)
8417   "Set a bookmark in current article."
8418   (interactive (list (gnus-summary-article-number)))
8419   (when (or (not (get-buffer gnus-article-buffer))
8420             (not gnus-current-article)
8421             (not gnus-article-current)
8422             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8423     (error "No current article selected"))
8424   ;; Remove old bookmark, if one exists.
8425   (let ((old (assq article gnus-newsgroup-bookmarks)))
8426     (when old
8427       (setq gnus-newsgroup-bookmarks
8428             (delq old gnus-newsgroup-bookmarks))))
8429   ;; Set the new bookmark, which is on the form
8430   ;; (article-number . line-number-in-body).
8431   (push
8432    (cons article
8433          (save-excursion
8434            (set-buffer gnus-article-buffer)
8435            (count-lines
8436             (min (point)
8437                  (save-excursion
8438                    (goto-char (point-min))
8439                    (search-forward "\n\n" nil t)
8440                    (point)))
8441             (point))))
8442    gnus-newsgroup-bookmarks)
8443   (gnus-message 6 "A bookmark has been added to the current article."))
8444
8445 (defun gnus-summary-remove-bookmark (article)
8446   "Remove the bookmark from the current article."
8447   (interactive (list (gnus-summary-article-number)))
8448   ;; Remove old bookmark, if one exists.
8449   (let ((old (assq article gnus-newsgroup-bookmarks)))
8450     (if old
8451         (progn
8452           (setq gnus-newsgroup-bookmarks
8453                 (delq old gnus-newsgroup-bookmarks))
8454           (gnus-message 6 "Removed bookmark."))
8455       (gnus-message 6 "No bookmark in current article."))))
8456
8457 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8458 (defun gnus-summary-mark-as-dormant (n)
8459   "Mark N articles forward as dormant.
8460 If N is negative, mark backward instead.  The difference between N and
8461 the actual number of articles marked is returned."
8462   (interactive "p")
8463   (gnus-summary-mark-forward n gnus-dormant-mark))
8464
8465 (defun gnus-summary-set-process-mark (article)
8466   "Set the process mark on ARTICLE and update the summary line."
8467   (setq gnus-newsgroup-processable
8468         (cons article
8469               (delq article gnus-newsgroup-processable)))
8470   (when (gnus-summary-goto-subject article)
8471     (gnus-summary-show-thread)
8472     (gnus-summary-goto-subject article)
8473     (gnus-summary-update-secondary-mark article)))
8474
8475 (defun gnus-summary-remove-process-mark (article)
8476   "Remove the process mark from ARTICLE and update the summary line."
8477   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8478   (when (gnus-summary-goto-subject article)
8479     (gnus-summary-show-thread)
8480     (gnus-summary-goto-subject article)
8481     (gnus-summary-update-secondary-mark article)))
8482
8483 (defun gnus-summary-set-saved-mark (article)
8484   "Set the process mark on ARTICLE and update the summary line."
8485   (push article gnus-newsgroup-saved)
8486   (when (gnus-summary-goto-subject article)
8487     (gnus-summary-update-secondary-mark article)))
8488
8489 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8490   "Mark N articles as read forwards.
8491 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8492 The difference between N and the actual number of articles marked is
8493 returned.
8494 Iff NO-EXPIRE, auto-expiry will be inhibited."
8495   (interactive "p")
8496   (gnus-summary-show-thread)
8497   (let ((backward (< n 0))
8498         (gnus-summary-goto-unread
8499          (and gnus-summary-goto-unread
8500               (not (eq gnus-summary-goto-unread 'never))
8501               (not (memq mark (list gnus-unread-mark
8502                                     gnus-ticked-mark gnus-dormant-mark)))))
8503         (n (abs n))
8504         (mark (or mark gnus-del-mark)))
8505     (while (and (> n 0)
8506                 (gnus-summary-mark-article nil mark no-expire)
8507                 (zerop (gnus-summary-next-subject
8508                         (if backward -1 1)
8509                         (and gnus-summary-goto-unread
8510                              (not (eq gnus-summary-goto-unread 'never)))
8511                         t)))
8512       (setq n (1- n)))
8513     (when (/= 0 n)
8514       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8515     (gnus-summary-recenter)
8516     (gnus-summary-position-point)
8517     (gnus-set-mode-line 'summary)
8518     n))
8519
8520 (defun gnus-summary-mark-article-as-read (mark)
8521   "Mark the current article quickly as read with MARK."
8522   (let ((article (gnus-summary-article-number)))
8523     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8524     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8525     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8526     (push (cons article mark) gnus-newsgroup-reads)
8527     ;; Possibly remove from cache, if that is used.
8528     (when gnus-use-cache
8529       (gnus-cache-enter-remove-article article))
8530     ;; Allow the backend to change the mark.
8531     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8532     ;; Check for auto-expiry.
8533     (when (and gnus-newsgroup-auto-expire
8534                (memq mark gnus-auto-expirable-marks))
8535       (setq mark gnus-expirable-mark)
8536       ;; Let the backend know about the mark change.
8537       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8538       (push article gnus-newsgroup-expirable))
8539     ;; Set the mark in the buffer.
8540     (gnus-summary-update-mark mark 'unread)
8541     t))
8542
8543 (defun gnus-summary-mark-article-as-unread (mark)
8544   "Mark the current article quickly as unread with MARK."
8545   (let* ((article (gnus-summary-article-number))
8546          (old-mark (gnus-summary-article-mark article)))
8547     ;; Allow the backend to change the mark.
8548     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8549     (if (eq mark old-mark)
8550         t
8551       (if (<= article 0)
8552           (progn
8553             (gnus-error 1 "Can't mark negative article numbers")
8554             nil)
8555         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8556         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8557         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8558         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8559         (cond ((= mark gnus-ticked-mark)
8560                (push article gnus-newsgroup-marked))
8561               ((= mark gnus-dormant-mark)
8562                (push article gnus-newsgroup-dormant))
8563               (t
8564                (push article gnus-newsgroup-unreads)))
8565         (gnus-pull article gnus-newsgroup-reads)
8566
8567         ;; See whether the article is to be put in the cache.
8568         (and gnus-use-cache
8569              (vectorp (gnus-summary-article-header article))
8570              (save-excursion
8571                (gnus-cache-possibly-enter-article
8572                 gnus-newsgroup-name article
8573                 (gnus-summary-article-header article)
8574                 (= mark gnus-ticked-mark)
8575                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8576
8577         ;; Fix the mark.
8578         (gnus-summary-update-mark mark 'unread)
8579         t))))
8580
8581 (defun gnus-summary-mark-article (&optional article mark no-expire)
8582   "Mark ARTICLE with MARK.  MARK can be any character.
8583 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8584 `??' (dormant) and `?E' (expirable).
8585 If MARK is nil, then the default character `?r' is used.
8586 If ARTICLE is nil, then the article on the current line will be
8587 marked.
8588 Iff NO-EXPIRE, auto-expiry will be inhibited."
8589   ;; The mark might be a string.
8590   (when (stringp mark)
8591     (setq mark (aref mark 0)))
8592   ;; If no mark is given, then we check auto-expiring.
8593   (when (null mark)
8594     (setq mark gnus-del-mark))
8595   (when (and (not no-expire)
8596              gnus-newsgroup-auto-expire
8597              (memq mark gnus-auto-expirable-marks))
8598     (setq mark gnus-expirable-mark))
8599   (let ((article (or article (gnus-summary-article-number)))
8600         (old-mark (gnus-summary-article-mark article)))
8601     ;; Allow the backend to change the mark.
8602     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8603     (if (eq mark old-mark)
8604         t
8605       (unless article
8606         (error "No article on current line"))
8607       (if (not (if (or (= mark gnus-unread-mark)
8608                        (= mark gnus-ticked-mark)
8609                        (= mark gnus-dormant-mark))
8610                    (gnus-mark-article-as-unread article mark)
8611                  (gnus-mark-article-as-read article mark)))
8612           t
8613         ;; See whether the article is to be put in the cache.
8614         (and gnus-use-cache
8615              (not (= mark gnus-canceled-mark))
8616              (vectorp (gnus-summary-article-header article))
8617              (save-excursion
8618                (gnus-cache-possibly-enter-article
8619                 gnus-newsgroup-name article
8620                 (gnus-summary-article-header article)
8621                 (= mark gnus-ticked-mark)
8622                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8623
8624         (when (gnus-summary-goto-subject article nil t)
8625           (let ((buffer-read-only nil))
8626             (gnus-summary-show-thread)
8627             ;; Fix the mark.
8628             (gnus-summary-update-mark mark 'unread)
8629             t))))))
8630
8631 (defun gnus-summary-update-secondary-mark (article)
8632   "Update the secondary (read, process, cache) mark."
8633   (gnus-summary-update-mark
8634    (cond ((memq article gnus-newsgroup-processable)
8635           gnus-process-mark)
8636          ((memq article gnus-newsgroup-cached)
8637           gnus-cached-mark)
8638          ((memq article gnus-newsgroup-replied)
8639           gnus-replied-mark)
8640          ((memq article gnus-newsgroup-saved)
8641           gnus-saved-mark)
8642          (t gnus-unread-mark))
8643    'replied)
8644   (when (gnus-visual-p 'summary-highlight 'highlight)
8645     (gnus-run-hooks 'gnus-summary-update-hook))
8646   t)
8647
8648 (defun gnus-summary-update-mark (mark type)
8649   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8650         (buffer-read-only nil))
8651     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
8652     (when forward
8653       (when (looking-at "\r")
8654         (incf forward))
8655       (when (<= (+ forward (point)) (point-max))
8656         ;; Go to the right position on the line.
8657         (goto-char (+ forward (point)))
8658         ;; Replace the old mark with the new mark.
8659         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8660         ;; Optionally update the marks by some user rule.
8661         (when (eq type 'unread)
8662           (gnus-data-set-mark
8663            (gnus-data-find (gnus-summary-article-number)) mark)
8664           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
8665
8666 (defun gnus-mark-article-as-read (article &optional mark)
8667   "Enter ARTICLE in the pertinent lists and remove it from others."
8668   ;; Make the article expirable.
8669   (let ((mark (or mark gnus-del-mark)))
8670     (if (= mark gnus-expirable-mark)
8671         (push article gnus-newsgroup-expirable)
8672       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8673     ;; Remove from unread and marked lists.
8674     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8675     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8676     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8677     (push (cons article mark) gnus-newsgroup-reads)
8678     ;; Possibly remove from cache, if that is used.
8679     (when gnus-use-cache
8680       (gnus-cache-enter-remove-article article))
8681     t))
8682
8683 (defun gnus-mark-article-as-unread (article &optional mark)
8684   "Enter ARTICLE in the pertinent lists and remove it from others."
8685   (let ((mark (or mark gnus-ticked-mark)))
8686     (if (<= article 0)
8687         (progn
8688           (gnus-error 1 "Can't mark negative article numbers")
8689           nil)
8690       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8691             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8692             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8693             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8694
8695       ;; Unsuppress duplicates?
8696       (when gnus-suppress-duplicates
8697         (gnus-dup-unsuppress-article article))
8698
8699       (cond ((= mark gnus-ticked-mark)
8700              (push article gnus-newsgroup-marked))
8701             ((= mark gnus-dormant-mark)
8702              (push article gnus-newsgroup-dormant))
8703             (t
8704              (push article gnus-newsgroup-unreads)))
8705       (gnus-pull article gnus-newsgroup-reads)
8706       t)))
8707
8708 (defalias 'gnus-summary-mark-as-unread-forward
8709   'gnus-summary-tick-article-forward)
8710 (make-obsolete 'gnus-summary-mark-as-unread-forward
8711                'gnus-summary-tick-article-forward)
8712 (defun gnus-summary-tick-article-forward (n)
8713   "Tick N articles forwards.
8714 If N is negative, tick backwards instead.
8715 The difference between N and the number of articles ticked is returned."
8716   (interactive "p")
8717   (gnus-summary-mark-forward n gnus-ticked-mark))
8718
8719 (defalias 'gnus-summary-mark-as-unread-backward
8720   'gnus-summary-tick-article-backward)
8721 (make-obsolete 'gnus-summary-mark-as-unread-backward
8722                'gnus-summary-tick-article-backward)
8723 (defun gnus-summary-tick-article-backward (n)
8724   "Tick N articles backwards.
8725 The difference between N and the number of articles ticked is returned."
8726   (interactive "p")
8727   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8728
8729 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8730 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8731 (defun gnus-summary-tick-article (&optional article clear-mark)
8732   "Mark current article as unread.
8733 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8734 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8735   (interactive)
8736   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8737                                        gnus-ticked-mark)))
8738
8739 (defun gnus-summary-mark-as-read-forward (n)
8740   "Mark N articles as read forwards.
8741 If N is negative, mark backwards instead.
8742 The difference between N and the actual number of articles marked is
8743 returned."
8744   (interactive "p")
8745   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8746
8747 (defun gnus-summary-mark-as-read-backward (n)
8748   "Mark the N articles as read backwards.
8749 The difference between N and the actual number of articles marked is
8750 returned."
8751   (interactive "p")
8752   (gnus-summary-mark-forward
8753    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8754
8755 (defun gnus-summary-mark-as-read (&optional article mark)
8756   "Mark current article as read.
8757 ARTICLE specifies the article to be marked as read.
8758 MARK specifies a string to be inserted at the beginning of the line."
8759   (gnus-summary-mark-article article mark))
8760
8761 (defun gnus-summary-clear-mark-forward (n)
8762   "Clear marks from N articles forward.
8763 If N is negative, clear backward instead.
8764 The difference between N and the number of marks cleared is returned."
8765   (interactive "p")
8766   (gnus-summary-mark-forward n gnus-unread-mark))
8767
8768 (defun gnus-summary-clear-mark-backward (n)
8769   "Clear marks from N articles backward.
8770 The difference between N and the number of marks cleared is returned."
8771   (interactive "p")
8772   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8773
8774 (defun gnus-summary-mark-unread-as-read ()
8775   "Intended to be used by `gnus-summary-mark-article-hook'."
8776   (when (memq gnus-current-article gnus-newsgroup-unreads)
8777     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8778
8779 (defun gnus-summary-mark-read-and-unread-as-read ()
8780   "Intended to be used by `gnus-summary-mark-article-hook'."
8781   (let ((mark (gnus-summary-article-mark)))
8782     (when (or (gnus-unread-mark-p mark)
8783               (gnus-read-mark-p mark))
8784       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8785
8786 (defun gnus-summary-mark-region-as-read (point mark all)
8787   "Mark all unread articles between point and mark as read.
8788 If given a prefix, mark all articles between point and mark as read,
8789 even ticked and dormant ones."
8790   (interactive "r\nP")
8791   (save-excursion
8792     (let (article)
8793       (goto-char point)
8794       (beginning-of-line)
8795       (while (and
8796               (< (point) mark)
8797               (progn
8798                 (when (or all
8799                           (memq (setq article (gnus-summary-article-number))
8800                                 gnus-newsgroup-unreads))
8801                   (gnus-summary-mark-article article gnus-del-mark))
8802                 t)
8803               (gnus-summary-find-next))))))
8804
8805 (defun gnus-summary-mark-below (score mark)
8806   "Mark articles with score less than SCORE with MARK."
8807   (interactive "P\ncMark: ")
8808   (setq score (if score
8809                   (prefix-numeric-value score)
8810                 (or gnus-summary-default-score 0)))
8811   (save-excursion
8812     (set-buffer gnus-summary-buffer)
8813     (goto-char (point-min))
8814     (while
8815         (progn
8816           (and (< (gnus-summary-article-score) score)
8817                (gnus-summary-mark-article nil mark))
8818           (gnus-summary-find-next)))))
8819
8820 (defun gnus-summary-kill-below (&optional score)
8821   "Mark articles with score below SCORE as read."
8822   (interactive "P")
8823   (gnus-summary-mark-below score gnus-killed-mark))
8824
8825 (defun gnus-summary-clear-above (&optional score)
8826   "Clear all marks from articles with score above SCORE."
8827   (interactive "P")
8828   (gnus-summary-mark-above score gnus-unread-mark))
8829
8830 (defun gnus-summary-tick-above (&optional score)
8831   "Tick all articles with score above SCORE."
8832   (interactive "P")
8833   (gnus-summary-mark-above score gnus-ticked-mark))
8834
8835 (defun gnus-summary-mark-above (score mark)
8836   "Mark articles with score over SCORE with MARK."
8837   (interactive "P\ncMark: ")
8838   (setq score (if score
8839                   (prefix-numeric-value score)
8840                 (or gnus-summary-default-score 0)))
8841   (save-excursion
8842     (set-buffer gnus-summary-buffer)
8843     (goto-char (point-min))
8844     (while (and (progn
8845                   (when (> (gnus-summary-article-score) score)
8846                     (gnus-summary-mark-article nil mark))
8847                   t)
8848                 (gnus-summary-find-next)))))
8849
8850 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8851 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8852 (defun gnus-summary-limit-include-expunged (&optional no-error)
8853   "Display all the hidden articles that were expunged for low scores."
8854   (interactive)
8855   (let ((buffer-read-only nil))
8856     (let ((scored gnus-newsgroup-scored)
8857           headers h)
8858       (while scored
8859         (unless (gnus-summary-goto-subject (caar scored))
8860           (and (setq h (gnus-summary-article-header (caar scored)))
8861                (< (cdar scored) gnus-summary-expunge-below)
8862                (push h headers)))
8863         (setq scored (cdr scored)))
8864       (if (not headers)
8865           (when (not no-error)
8866             (error "No expunged articles hidden"))
8867         (goto-char (point-min))
8868         (gnus-summary-prepare-unthreaded (nreverse headers))
8869         (goto-char (point-min))
8870         (gnus-summary-position-point)
8871         t))))
8872
8873 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8874   "Mark all unread articles in this newsgroup as read.
8875 If prefix argument ALL is non-nil, ticked and dormant articles will
8876 also be marked as read.
8877 If QUIETLY is non-nil, no questions will be asked.
8878 If TO-HERE is non-nil, it should be a point in the buffer.  All
8879 articles before this point will be marked as read.
8880 Note that this function will only catch up the unread article
8881 in the current summary buffer limitation.
8882 The number of articles marked as read is returned."
8883   (interactive "P")
8884   (prog1
8885       (save-excursion
8886         (when (or quietly
8887                   (not gnus-interactive-catchup) ;Without confirmation?
8888                   gnus-expert-user
8889                   (gnus-y-or-n-p
8890                    (if all
8891                        "Mark absolutely all articles as read? "
8892                      "Mark all unread articles as read? ")))
8893           (if (and not-mark
8894                    (not gnus-newsgroup-adaptive)
8895                    (not gnus-newsgroup-auto-expire)
8896                    (not gnus-suppress-duplicates)
8897                    (or (not gnus-use-cache)
8898                        (eq gnus-use-cache 'passive)))
8899               (progn
8900                 (when all
8901                   (setq gnus-newsgroup-marked nil
8902                         gnus-newsgroup-dormant nil))
8903                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8904             ;; We actually mark all articles as canceled, which we
8905             ;; have to do when using auto-expiry or adaptive scoring.
8906             (gnus-summary-show-all-threads)
8907             (when (gnus-summary-first-subject (not all) t)
8908               (while (and
8909                       (if to-here (< (point) to-here) t)
8910                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8911                       (gnus-summary-find-next (not all) nil nil t))))
8912             (gnus-set-mode-line 'summary))
8913           t))
8914     (gnus-summary-position-point)))
8915
8916 (defun gnus-summary-catchup-to-here (&optional all)
8917   "Mark all unticked articles before the current one as read.
8918 If ALL is non-nil, also mark ticked and dormant articles as read."
8919   (interactive "P")
8920   (save-excursion
8921     (gnus-save-hidden-threads
8922       (let ((beg (point)))
8923         ;; We check that there are unread articles.
8924         (when (or all (gnus-summary-find-prev))
8925           (gnus-summary-catchup all t beg)))))
8926   (gnus-summary-position-point))
8927
8928 (defun gnus-summary-catchup-all (&optional quietly)
8929   "Mark all articles in this newsgroup as read."
8930   (interactive "P")
8931   (gnus-summary-catchup t quietly))
8932
8933 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8934   "Mark all unread articles in this group as read, then exit.
8935 If prefix argument ALL is non-nil, all articles are marked as read."
8936   (interactive "P")
8937   (when (gnus-summary-catchup all quietly nil 'fast)
8938     ;; Select next newsgroup or exit.
8939     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8940              (eq gnus-auto-select-next 'quietly))
8941         (gnus-summary-next-group nil)
8942       (gnus-summary-exit))))
8943
8944 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8945   "Mark all articles in this newsgroup as read, and then exit."
8946   (interactive "P")
8947   (gnus-summary-catchup-and-exit t quietly))
8948
8949 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8950   "Mark all articles in this group as read and select the next group.
8951 If given a prefix, mark all articles, unread as well as ticked, as
8952 read."
8953   (interactive "P")
8954   (save-excursion
8955     (gnus-summary-catchup all))
8956   (gnus-summary-next-group))
8957
8958 ;;;
8959 ;;; with article
8960 ;;;
8961
8962 (defmacro gnus-with-article (article &rest forms)
8963   "Select ARTICLE and perform FORMS in the original article buffer.
8964 Then replace the article with the result."
8965   `(progn
8966      ;; We don't want the article to be marked as read.
8967      (let (gnus-mark-article-hook)
8968        (gnus-summary-select-article t t nil ,article))
8969      (set-buffer gnus-original-article-buffer)
8970      ,@forms
8971      (if (not (gnus-check-backend-function
8972                'request-replace-article (car gnus-article-current)))
8973          (gnus-message 5 "Read-only group; not replacing")
8974        (unless (gnus-request-replace-article
8975                 ,article (car gnus-article-current)
8976                 (current-buffer) t)
8977          (error "Couldn't replace article")))
8978      ;; The cache and backlog have to be flushed somewhat.
8979      (when gnus-keep-backlog
8980        (gnus-backlog-remove-article
8981         (car gnus-article-current) (cdr gnus-article-current)))
8982      (when gnus-use-cache
8983        (gnus-cache-update-article
8984         (car gnus-article-current) (cdr gnus-article-current)))))
8985
8986 (put 'gnus-with-article 'lisp-indent-function 1)
8987 (put 'gnus-with-article 'edebug-form-spec '(form body))
8988
8989 ;; Thread-based commands.
8990
8991 (defun gnus-summary-articles-in-thread (&optional article)
8992   "Return a list of all articles in the current thread.
8993 If ARTICLE is non-nil, return all articles in the thread that starts
8994 with that article."
8995   (let* ((article (or article (gnus-summary-article-number)))
8996          (data (gnus-data-find-list article))
8997          (top-level (gnus-data-level (car data)))
8998          (top-subject
8999           (cond ((null gnus-thread-operation-ignore-subject)
9000                  (gnus-simplify-subject-re
9001                   (mail-header-subject (gnus-data-header (car data)))))
9002                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9003                  (gnus-simplify-subject-fuzzy
9004                   (mail-header-subject (gnus-data-header (car data)))))
9005                 (t nil)))
9006          (end-point (save-excursion
9007                       (if (gnus-summary-go-to-next-thread)
9008                           (point) (point-max))))
9009          articles)
9010     (while (and data
9011                 (< (gnus-data-pos (car data)) end-point))
9012       (when (or (not top-subject)
9013                 (string= top-subject
9014                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9015                              (gnus-simplify-subject-fuzzy
9016                               (mail-header-subject
9017                                (gnus-data-header (car data))))
9018                            (gnus-simplify-subject-re
9019                             (mail-header-subject
9020                              (gnus-data-header (car data)))))))
9021         (push (gnus-data-number (car data)) articles))
9022       (unless (and (setq data (cdr data))
9023                    (> (gnus-data-level (car data)) top-level))
9024         (setq data nil)))
9025     ;; Return the list of articles.
9026     (nreverse articles)))
9027
9028 (defun gnus-summary-rethread-current ()
9029   "Rethread the thread the current article is part of."
9030   (interactive)
9031   (let* ((gnus-show-threads t)
9032          (article (gnus-summary-article-number))
9033          (id (mail-header-id (gnus-summary-article-header)))
9034          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9035     (unless id
9036       (error "No article on the current line"))
9037     (gnus-rebuild-thread id)
9038     (gnus-summary-goto-subject article)))
9039
9040 (defun gnus-summary-reparent-thread ()
9041   "Make the current article child of the marked (or previous) article.
9042
9043 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9044 is non-nil or the Subject: of both articles are the same."
9045   (interactive)
9046   (unless (not (gnus-group-read-only-p))
9047     (error "The current newsgroup does not support article editing"))
9048   (unless (<= (length gnus-newsgroup-processable) 1)
9049     (error "No more than one article may be marked"))
9050   (save-window-excursion
9051     (let ((gnus-article-buffer " *reparent*")
9052           (current-article (gnus-summary-article-number))
9053           ;; First grab the marked article, otherwise one line up.
9054           (parent-article (if (not (null gnus-newsgroup-processable))
9055                               (car gnus-newsgroup-processable)
9056                             (save-excursion
9057                               (if (eq (forward-line -1) 0)
9058                                   (gnus-summary-article-number)
9059                                 (error "Beginning of summary buffer"))))))
9060       (unless (not (eq current-article parent-article))
9061         (error "An article may not be self-referential"))
9062       (let ((message-id (mail-header-id
9063                          (gnus-summary-article-header parent-article))))
9064         (unless (and message-id (not (equal message-id "")))
9065           (error "No message-id in desired parent"))
9066         (gnus-with-article current-article
9067           (save-restriction
9068             (goto-char (point-min))
9069             (message-narrow-to-head)
9070             (if (re-search-forward "^References: " nil t)
9071                 (progn
9072                   (re-search-forward "^[^ \t]" nil t)
9073                   (forward-line -1)
9074                   (end-of-line)
9075                   (insert " " message-id))
9076               (insert "References: " message-id "\n"))))
9077         (set-buffer gnus-summary-buffer)
9078         (gnus-summary-unmark-all-processable)
9079         (gnus-summary-update-article current-article)
9080         (gnus-summary-rethread-current)
9081         (gnus-message 3 "Article %d is now the child of article %d"
9082                       current-article parent-article)))))
9083
9084 (defun gnus-summary-toggle-threads (&optional arg)
9085   "Toggle showing conversation threads.
9086 If ARG is positive number, turn showing conversation threads on."
9087   (interactive "P")
9088   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9089     (setq gnus-show-threads
9090           (if (null arg) (not gnus-show-threads)
9091             (> (prefix-numeric-value arg) 0)))
9092     (gnus-summary-prepare)
9093     (gnus-summary-goto-subject current)
9094     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9095     (gnus-summary-position-point)))
9096
9097 (defun gnus-summary-show-all-threads ()
9098   "Show all threads."
9099   (interactive)
9100   (save-excursion
9101     (let ((buffer-read-only nil))
9102       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9103   (gnus-summary-position-point))
9104
9105 (defun gnus-summary-show-thread ()
9106   "Show thread subtrees.
9107 Returns nil if no thread was there to be shown."
9108   (interactive)
9109   (let ((buffer-read-only nil)
9110         (orig (point))
9111         ;; first goto end then to beg, to have point at beg after let
9112         (end (progn (end-of-line) (point)))
9113         (beg (progn (beginning-of-line) (point))))
9114     (prog1
9115         ;; Any hidden lines here?
9116         (search-forward "\r" end t)
9117       (subst-char-in-region beg end ?\^M ?\n t)
9118       (goto-char orig)
9119       (gnus-summary-position-point))))
9120
9121 (defun gnus-summary-hide-all-threads ()
9122   "Hide all thread subtrees."
9123   (interactive)
9124   (save-excursion
9125     (goto-char (point-min))
9126     (gnus-summary-hide-thread)
9127     (while (zerop (gnus-summary-next-thread 1 t))
9128       (gnus-summary-hide-thread)))
9129   (gnus-summary-position-point))
9130
9131 (defun gnus-summary-hide-thread ()
9132   "Hide thread subtrees.
9133 Returns nil if no threads were there to be hidden."
9134   (interactive)
9135   (let ((buffer-read-only nil)
9136         (start (point))
9137         (article (gnus-summary-article-number)))
9138     (goto-char start)
9139     ;; Go forward until either the buffer ends or the subthread
9140     ;; ends.
9141     (when (and (not (eobp))
9142                (or (zerop (gnus-summary-next-thread 1 t))
9143                    (goto-char (point-max))))
9144       (prog1
9145           (if (and (> (point) start)
9146                    (search-backward "\n" start t))
9147               (progn
9148                 (subst-char-in-region start (point) ?\n ?\^M)
9149                 (gnus-summary-goto-subject article))
9150             (goto-char start)
9151             nil)))))
9152
9153 (defun gnus-summary-go-to-next-thread (&optional previous)
9154   "Go to the same level (or less) next thread.
9155 If PREVIOUS is non-nil, go to previous thread instead.
9156 Return the article number moved to, or nil if moving was impossible."
9157   (let ((level (gnus-summary-thread-level))
9158         (way (if previous -1 1))
9159         (beg (point)))
9160     (forward-line way)
9161     (while (and (not (eobp))
9162                 (< level (gnus-summary-thread-level)))
9163       (forward-line way))
9164     (if (eobp)
9165         (progn
9166           (goto-char beg)
9167           nil)
9168       (setq beg (point))
9169       (prog1
9170           (gnus-summary-article-number)
9171         (goto-char beg)))))
9172
9173 (defun gnus-summary-next-thread (n &optional silent)
9174   "Go to the same level next N'th thread.
9175 If N is negative, search backward instead.
9176 Returns the difference between N and the number of skips actually
9177 done.
9178
9179 If SILENT, don't output messages."
9180   (interactive "p")
9181   (let ((backward (< n 0))
9182         (n (abs n)))
9183     (while (and (> n 0)
9184                 (gnus-summary-go-to-next-thread backward))
9185       (decf n))
9186     (unless silent
9187       (gnus-summary-position-point))
9188     (when (and (not silent) (/= 0 n))
9189       (gnus-message 7 "No more threads"))
9190     n))
9191
9192 (defun gnus-summary-prev-thread (n)
9193   "Go to the same level previous N'th thread.
9194 Returns the difference between N and the number of skips actually
9195 done."
9196   (interactive "p")
9197   (gnus-summary-next-thread (- n)))
9198
9199 (defun gnus-summary-go-down-thread ()
9200   "Go down one level in the current thread."
9201   (let ((children (gnus-summary-article-children)))
9202     (when children
9203       (gnus-summary-goto-subject (car children)))))
9204
9205 (defun gnus-summary-go-up-thread ()
9206   "Go up one level in the current thread."
9207   (let ((parent (gnus-summary-article-parent)))
9208     (when parent
9209       (gnus-summary-goto-subject parent))))
9210
9211 (defun gnus-summary-down-thread (n)
9212   "Go down thread N steps.
9213 If N is negative, go up instead.
9214 Returns the difference between N and how many steps down that were
9215 taken."
9216   (interactive "p")
9217   (let ((up (< n 0))
9218         (n (abs n)))
9219     (while (and (> n 0)
9220                 (if up (gnus-summary-go-up-thread)
9221                   (gnus-summary-go-down-thread)))
9222       (setq n (1- n)))
9223     (gnus-summary-position-point)
9224     (when (/= 0 n)
9225       (gnus-message 7 "Can't go further"))
9226     n))
9227
9228 (defun gnus-summary-up-thread (n)
9229   "Go up thread N steps.
9230 If N is negative, go up instead.
9231 Returns the difference between N and how many steps down that were
9232 taken."
9233   (interactive "p")
9234   (gnus-summary-down-thread (- n)))
9235
9236 (defun gnus-summary-top-thread ()
9237   "Go to the top of the thread."
9238   (interactive)
9239   (while (gnus-summary-go-up-thread))
9240   (gnus-summary-article-number))
9241
9242 (defun gnus-summary-kill-thread (&optional unmark)
9243   "Mark articles under current thread as read.
9244 If the prefix argument is positive, remove any kinds of marks.
9245 If the prefix argument is negative, tick articles instead."
9246   (interactive "P")
9247   (when unmark
9248     (setq unmark (prefix-numeric-value unmark)))
9249   (let ((articles (gnus-summary-articles-in-thread)))
9250     (save-excursion
9251       ;; Expand the thread.
9252       (gnus-summary-show-thread)
9253       ;; Mark all the articles.
9254       (while articles
9255         (gnus-summary-goto-subject (car articles))
9256         (cond ((null unmark)
9257                (gnus-summary-mark-article-as-read gnus-killed-mark))
9258               ((> unmark 0)
9259                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9260               (t
9261                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9262         (setq articles (cdr articles))))
9263     ;; Hide killed subtrees.
9264     (and (null unmark)
9265          gnus-thread-hide-killed
9266          (gnus-summary-hide-thread))
9267     ;; If marked as read, go to next unread subject.
9268     (when (null unmark)
9269       ;; Go to next unread subject.
9270       (gnus-summary-next-subject 1 t)))
9271   (gnus-set-mode-line 'summary))
9272
9273 ;; Summary sorting commands
9274
9275 (defun gnus-summary-sort-by-number (&optional reverse)
9276   "Sort the summary buffer by article number.
9277 Argument REVERSE means reverse order."
9278   (interactive "P")
9279   (gnus-summary-sort 'number reverse))
9280
9281 (defun gnus-summary-sort-by-author (&optional reverse)
9282   "Sort the summary buffer by author name alphabetically.
9283 If `case-fold-search' is non-nil, case of letters is ignored.
9284 Argument REVERSE means reverse order."
9285   (interactive "P")
9286   (gnus-summary-sort 'author reverse))
9287
9288 (defun gnus-summary-sort-by-subject (&optional reverse)
9289   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9290 If `case-fold-search' is non-nil, case of letters is ignored.
9291 Argument REVERSE means reverse order."
9292   (interactive "P")
9293   (gnus-summary-sort 'subject reverse))
9294
9295 (defun gnus-summary-sort-by-date (&optional reverse)
9296   "Sort the summary buffer by date.
9297 Argument REVERSE means reverse order."
9298   (interactive "P")
9299   (gnus-summary-sort 'date reverse))
9300
9301 (defun gnus-summary-sort-by-score (&optional reverse)
9302   "Sort the summary buffer by score.
9303 Argument REVERSE means reverse order."
9304   (interactive "P")
9305   (gnus-summary-sort 'score reverse))
9306
9307 (defun gnus-summary-sort-by-lines (&optional reverse)
9308   "Sort the summary buffer by the number of lines.
9309 Argument REVERSE means reverse order."
9310   (interactive "P")
9311   (gnus-summary-sort 'lines reverse))
9312
9313 (defun gnus-summary-sort-by-chars (&optional reverse)
9314   "Sort the summary buffer by article length.
9315 Argument REVERSE means reverse order."
9316   (interactive "P")
9317   (gnus-summary-sort 'chars reverse))
9318
9319 (defun gnus-summary-sort (predicate reverse)
9320   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9321   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9322          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9323          (gnus-thread-sort-functions
9324           (if (not reverse)
9325               thread
9326             `(lambda (t1 t2)
9327                (,thread t2 t1))))
9328          (gnus-sort-gathered-threads-function
9329           gnus-thread-sort-functions)
9330          (gnus-article-sort-functions
9331           (if (not reverse)
9332               article
9333             `(lambda (t1 t2)
9334                (,article t2 t1))))
9335          (buffer-read-only)
9336          (gnus-summary-prepare-hook nil))
9337     ;; We do the sorting by regenerating the threads.
9338     (gnus-summary-prepare)
9339     ;; Hide subthreads if needed.
9340     (when (and gnus-show-threads gnus-thread-hide-subtree)
9341       (gnus-summary-hide-all-threads))))
9342
9343 ;; Summary saving commands.
9344
9345 (defun gnus-summary-save-article (&optional n not-saved)
9346   "Save the current article using the default saver function.
9347 If N is a positive number, save the N next articles.
9348 If N is a negative number, save the N previous articles.
9349 If N is nil and any articles have been marked with the process mark,
9350 save those articles instead.
9351 The variable `gnus-default-article-saver' specifies the saver function."
9352   (interactive "P")
9353   (let* ((articles (gnus-summary-work-articles n))
9354          (save-buffer (save-excursion
9355                         (nnheader-set-temp-buffer " *Gnus Save*")))
9356          (num (length articles))
9357          header file)
9358     (dolist (article articles)
9359       (setq header (gnus-summary-article-header article))
9360       (if (not (vectorp header))
9361           ;; This is a pseudo-article.
9362           (if (assq 'name header)
9363               (gnus-copy-file (cdr (assq 'name header)))
9364             (gnus-message 1 "Article %d is unsaveable" article))
9365         ;; This is a real article.
9366         (save-window-excursion
9367           (gnus-summary-select-article t nil nil article))
9368         (save-excursion
9369           (set-buffer save-buffer)
9370           (erase-buffer)
9371           (insert-buffer-substring gnus-original-article-buffer))
9372         (setq file (gnus-article-save save-buffer file num))
9373         (gnus-summary-remove-process-mark article)
9374         (unless not-saved
9375           (gnus-summary-set-saved-mark article))))
9376     (gnus-kill-buffer save-buffer)
9377     (gnus-summary-position-point)
9378     (gnus-set-mode-line 'summary)
9379     n))
9380
9381 (defun gnus-summary-pipe-output (&optional arg)
9382   "Pipe the current article to a subprocess.
9383 If N is a positive number, pipe the N next articles.
9384 If N is a negative number, pipe the N previous articles.
9385 If N is nil and any articles have been marked with the process mark,
9386 pipe those articles instead."
9387   (interactive "P")
9388   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9389     (gnus-summary-save-article arg t))
9390   (gnus-configure-windows 'pipe))
9391
9392 (defun gnus-summary-save-article-mail (&optional arg)
9393   "Append the current article to an mail file.
9394 If N is a positive number, save the N next articles.
9395 If N is a negative number, save the N previous articles.
9396 If N is nil and any articles have been marked with the process mark,
9397 save those articles instead."
9398   (interactive "P")
9399   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9400     (gnus-summary-save-article arg)))
9401
9402 (defun gnus-summary-save-article-rmail (&optional arg)
9403   "Append the current article to an rmail file.
9404 If N is a positive number, save the N next articles.
9405 If N is a negative number, save the N previous articles.
9406 If N is nil and any articles have been marked with the process mark,
9407 save those articles instead."
9408   (interactive "P")
9409   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9410     (gnus-summary-save-article arg)))
9411
9412 (defun gnus-summary-save-article-file (&optional arg)
9413   "Append the current article to a file.
9414 If N is a positive number, save the N next articles.
9415 If N is a negative number, save the N previous articles.
9416 If N is nil and any articles have been marked with the process mark,
9417 save those articles instead."
9418   (interactive "P")
9419   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9420     (gnus-summary-save-article arg)))
9421
9422 (defun gnus-summary-write-article-file (&optional arg)
9423   "Write the current article to a file, deleting the previous file.
9424 If N is a positive number, save the N next articles.
9425 If N is a negative number, save the N previous articles.
9426 If N is nil and any articles have been marked with the process mark,
9427 save those articles instead."
9428   (interactive "P")
9429   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9430     (gnus-summary-save-article arg)))
9431
9432 (defun gnus-summary-save-article-body-file (&optional arg)
9433   "Append the current article body to a file.
9434 If N is a positive number, save the N next articles.
9435 If N is a negative number, save the N previous articles.
9436 If N is nil and any articles have been marked with the process mark,
9437 save those articles instead."
9438   (interactive "P")
9439   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9440     (gnus-summary-save-article arg)))
9441
9442 (defun gnus-summary-pipe-message (program)
9443   "Pipe the current article through PROGRAM."
9444   (interactive "sProgram: ")
9445   (gnus-summary-select-article)
9446   (let ((mail-header-separator ""))
9447     (gnus-eval-in-buffer-window gnus-article-buffer
9448       (save-restriction
9449         (widen)
9450         (let ((start (window-start))
9451               buffer-read-only)
9452           (message-pipe-buffer-body program)
9453           (set-window-start (get-buffer-window (current-buffer)) start))))))
9454
9455 (defun gnus-get-split-value (methods)
9456   "Return a value based on the split METHODS."
9457   (let (split-name method result match)
9458     (when methods
9459       (save-excursion
9460         (set-buffer gnus-original-article-buffer)
9461         (save-restriction
9462           (nnheader-narrow-to-headers)
9463           (while (and methods (not split-name))
9464             (goto-char (point-min))
9465             (setq method (pop methods))
9466             (setq match (car method))
9467             (when (cond
9468                    ((stringp match)
9469                     ;; Regular expression.
9470                     (ignore-errors
9471                       (re-search-forward match nil t)))
9472                    ((gnus-functionp match)
9473                     ;; Function.
9474                     (save-restriction
9475                       (widen)
9476                       (setq result (funcall match gnus-newsgroup-name))))
9477                    ((consp match)
9478                     ;; Form.
9479                     (save-restriction
9480                       (widen)
9481                       (setq result (eval match)))))
9482               (setq split-name (cdr method))
9483               (cond ((stringp result)
9484                      (push (expand-file-name
9485                             result gnus-article-save-directory)
9486                            split-name))
9487                     ((consp result)
9488                      (setq split-name (append result split-name)))))))))
9489     (nreverse split-name)))
9490
9491 (defun gnus-valid-move-group-p (group)
9492   (and (boundp group)
9493        (symbol-name group)
9494        (symbol-value group)
9495        (gnus-get-function (gnus-find-method-for-group
9496                            (symbol-name group)) 'request-accept-article t)))
9497
9498 (defun gnus-read-move-group-name (prompt default articles prefix)
9499   "Read a group name."
9500   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9501          (minibuffer-confirm-incomplete nil) ; XEmacs
9502          (prom
9503           (format "%s %s to:"
9504                   prompt
9505                   (if (> (length articles) 1)
9506                       (format "these %d articles" (length articles))
9507                     "this article")))
9508          (to-newsgroup
9509           (cond
9510            ((null split-name)
9511             (gnus-completing-read default prom
9512                                   gnus-active-hashtb
9513                                   'gnus-valid-move-group-p
9514                                   nil prefix
9515                                   'gnus-group-history))
9516            ((= 1 (length split-name))
9517             (gnus-completing-read (car split-name) prom
9518                                   gnus-active-hashtb
9519                                   'gnus-valid-move-group-p
9520                                   nil nil
9521                                   'gnus-group-history))
9522            (t
9523             (gnus-completing-read nil prom
9524                                   (mapcar (lambda (el) (list el))
9525                                           (nreverse split-name))
9526                                   nil nil nil
9527                                   'gnus-group-history))))
9528          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
9529     (when to-newsgroup
9530       (if (or (string= to-newsgroup "")
9531               (string= to-newsgroup prefix))
9532           (setq to-newsgroup default))
9533       (unless to-newsgroup
9534         (error "No group name entered"))
9535       (or (gnus-active to-newsgroup)
9536           (gnus-activate-group to-newsgroup nil nil to-method)
9537           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
9538                                      to-newsgroup))
9539               (or (and (gnus-request-create-group to-newsgroup to-method)
9540                        (gnus-activate-group
9541                         to-newsgroup nil nil to-method)
9542                        (gnus-subscribe-group to-newsgroup))
9543                   (error "Couldn't create group %s" to-newsgroup)))
9544           (error "No such group: %s" to-newsgroup)))
9545     to-newsgroup))
9546
9547 (defun gnus-summary-save-parts (type dir n &optional reverse)
9548   "Save parts matching TYPE to DIR.
9549 If REVERSE, save parts that do not match TYPE."
9550   (interactive
9551    (list (read-string "Save parts of type: " 
9552                       (or (car gnus-summary-save-parts-type-history)
9553                           gnus-summary-save-parts-default-mime)
9554                       'gnus-summary-save-parts-type-history)
9555          (setq gnus-summary-save-parts-last-directory
9556                (read-file-name "Save to directory: " 
9557                                gnus-summary-save-parts-last-directory
9558                                nil t))
9559          current-prefix-arg))
9560   (gnus-summary-iterate n
9561     (let ((gnus-display-mime-function nil)
9562           (gnus-inhibit-treatment t))
9563       (gnus-summary-select-article))
9564     (save-excursion
9565       (set-buffer gnus-article-buffer)
9566       (let ((handles (or gnus-article-mime-handles
9567                          (mm-dissect-buffer) (mm-uu-dissect))))
9568         (when handles
9569           (gnus-summary-save-parts-1 type dir handles reverse)
9570           (unless gnus-article-mime-handles ;; Don't destroy this case.
9571             (mm-destroy-parts handles)))))))
9572
9573 (defun gnus-summary-save-parts-1 (type dir handle reverse)
9574   (if (stringp (car handle))
9575       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9576               (cdr handle))
9577     (when (if reverse
9578               (not (string-match type (mm-handle-media-type handle)))
9579             (string-match type (mm-handle-media-type handle)))
9580       (let ((file (expand-file-name
9581                    (file-name-nondirectory
9582                     (or
9583                      (mail-content-type-get
9584                       (mm-handle-disposition handle) 'filename)
9585                      (concat gnus-newsgroup-name
9586                              "." (number-to-string
9587                                   (cdr gnus-article-current)))))
9588                    dir)))
9589         (unless (file-exists-p file)
9590           (mm-save-part-to-file handle file))))))
9591
9592 ;; Summary extract commands
9593
9594 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
9595   (let ((buffer-read-only nil)
9596         (article (gnus-summary-article-number))
9597         after-article b e)
9598     (unless (gnus-summary-goto-subject article)
9599       (error "No such article: %d" article))
9600     (gnus-summary-position-point)
9601     ;; If all commands are to be bunched up on one line, we collect
9602     ;; them here.
9603     (unless gnus-view-pseudos-separately
9604       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9605             files action)
9606         (while ps
9607           (setq action (cdr (assq 'action (car ps))))
9608           (setq files (list (cdr (assq 'name (car ps)))))
9609           (while (and ps (cdr ps)
9610                       (string= (or action "1")
9611                                (or (cdr (assq 'action (cadr ps))) "2")))
9612             (push (cdr (assq 'name (cadr ps))) files)
9613             (setcdr ps (cddr ps)))
9614           (when files
9615             (when (not (string-match "%s" action))
9616               (push " " files))
9617             (push " " files)
9618             (when (assq 'execute (car ps))
9619               (setcdr (assq 'execute (car ps))
9620                       (funcall (if (string-match "%s" action)
9621                                    'format 'concat)
9622                                action
9623                                (mapconcat
9624                                 (lambda (f)
9625                                   (if (equal f " ")
9626                                       f
9627                                     (gnus-quote-arg-for-sh-or-csh f)))
9628                                 files " ")))))
9629           (setq ps (cdr ps)))))
9630     (if (and gnus-view-pseudos (not not-view))
9631         (while pslist
9632           (when (assq 'execute (car pslist))
9633             (gnus-execute-command (cdr (assq 'execute (car pslist)))
9634                                   (eq gnus-view-pseudos 'not-confirm)))
9635           (setq pslist (cdr pslist)))
9636       (save-excursion
9637         (while pslist
9638           (setq after-article (or (cdr (assq 'article (car pslist)))
9639                                   (gnus-summary-article-number)))
9640           (gnus-summary-goto-subject after-article)
9641           (forward-line 1)
9642           (setq b (point))
9643           (insert "    " (file-name-nondirectory
9644                           (cdr (assq 'name (car pslist))))
9645                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9646           (setq e (point))
9647           (forward-line -1)             ; back to `b'
9648           (gnus-add-text-properties
9649            b (1- e) (list 'gnus-number gnus-reffed-article-number
9650                           gnus-mouse-face-prop gnus-mouse-face))
9651           (gnus-data-enter
9652            after-article gnus-reffed-article-number
9653            gnus-unread-mark b (car pslist) 0 (- e b))
9654           (push gnus-reffed-article-number gnus-newsgroup-unreads)
9655           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9656           (setq pslist (cdr pslist)))))))
9657
9658 (defun gnus-pseudos< (p1 p2)
9659   (let ((c1 (cdr (assq 'action p1)))
9660         (c2 (cdr (assq 'action p2))))
9661     (and c1 c2 (string< c1 c2))))
9662
9663 (defun gnus-request-pseudo-article (props)
9664   (cond ((assq 'execute props)
9665          (gnus-execute-command (cdr (assq 'execute props)))))
9666   (let ((gnus-current-article (gnus-summary-article-number)))
9667     (gnus-run-hooks 'gnus-mark-article-hook)))
9668
9669 (defun gnus-execute-command (command &optional automatic)
9670   (save-excursion
9671     (gnus-article-setup-buffer)
9672     (set-buffer gnus-article-buffer)
9673     (setq buffer-read-only nil)
9674     (let ((command (if automatic command
9675                      (read-string "Command: " (cons command 0)))))
9676       (erase-buffer)
9677       (insert "$ " command "\n\n")
9678       (if gnus-view-pseudo-asynchronously
9679           (start-process "gnus-execute" (current-buffer) shell-file-name
9680                          shell-command-switch command)
9681         (call-process shell-file-name nil t nil
9682                       shell-command-switch command)))))
9683
9684 ;; Summary kill commands.
9685
9686 (defun gnus-summary-edit-global-kill (article)
9687   "Edit the \"global\" kill file."
9688   (interactive (list (gnus-summary-article-number)))
9689   (gnus-group-edit-global-kill article))
9690
9691 (defun gnus-summary-edit-local-kill ()
9692   "Edit a local kill file applied to the current newsgroup."
9693   (interactive)
9694   (setq gnus-current-headers (gnus-summary-article-header))
9695   (gnus-group-edit-local-kill
9696    (gnus-summary-article-number) gnus-newsgroup-name))
9697
9698 ;;; Header reading.
9699
9700 (defun gnus-read-header (id &optional header)
9701   "Read the headers of article ID and enter them into the Gnus system."
9702   (let ((group gnus-newsgroup-name)
9703         (gnus-override-method
9704          (or
9705           gnus-override-method
9706           (and (gnus-news-group-p gnus-newsgroup-name)
9707                (car (gnus-refer-article-methods)))))
9708         where)
9709     ;; First we check to see whether the header in question is already
9710     ;; fetched.
9711     (if (stringp id)
9712         ;; This is a Message-ID.
9713         (setq header (or header (gnus-id-to-header id)))
9714       ;; This is an article number.
9715       (setq header (or header (gnus-summary-article-header id))))
9716     (if (and header
9717              (not (gnus-summary-article-sparse-p (mail-header-number header))))
9718         ;; We have found the header.
9719         header
9720       ;; If this is a sparse article, we have to nix out its
9721       ;; previous entry in the thread hashtb.
9722       (when (and header
9723                  (gnus-summary-article-sparse-p (mail-header-number header)))
9724         (let* ((parent (gnus-parent-id (mail-header-references header)))
9725                (thread (and parent (gnus-id-to-thread parent))))
9726           (when thread
9727             (delq (assq header thread) thread))))
9728       ;; We have to really fetch the header to this article.
9729       (save-excursion
9730         (set-buffer nntp-server-buffer)
9731         (when (setq where (gnus-request-head id group))
9732           (nnheader-fold-continuation-lines)
9733           (goto-char (point-max))
9734           (insert ".\n")
9735           (goto-char (point-min))
9736           (insert "211 ")
9737           (princ (cond
9738                   ((numberp id) id)
9739                   ((cdr where) (cdr where))
9740                   (header (mail-header-number header))
9741                   (t gnus-reffed-article-number))
9742                  (current-buffer))
9743           (insert " Article retrieved.\n"))
9744         (if (or (not where)
9745                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9746             ()                          ; Malformed head.
9747           (unless (gnus-summary-article-sparse-p (mail-header-number header))
9748             (when (and (stringp id)
9749                        (not (string= (gnus-group-real-name group)
9750                                      (car where))))
9751               ;; If we fetched by Message-ID and the article came
9752               ;; from a different group, we fudge some bogus article
9753               ;; numbers for this article.
9754               (mail-header-set-number header gnus-reffed-article-number))
9755             (save-excursion
9756               (set-buffer gnus-summary-buffer)
9757               (decf gnus-reffed-article-number)
9758               (gnus-remove-header (mail-header-number header))
9759               (push header gnus-newsgroup-headers)
9760               (setq gnus-current-headers header)
9761               (push (mail-header-number header) gnus-newsgroup-limit)))
9762           header)))))
9763
9764 (defun gnus-remove-header (number)
9765   "Remove header NUMBER from `gnus-newsgroup-headers'."
9766   (if (and gnus-newsgroup-headers
9767            (= number (mail-header-number (car gnus-newsgroup-headers))))
9768       (pop gnus-newsgroup-headers)
9769     (let ((headers gnus-newsgroup-headers))
9770       (while (and (cdr headers)
9771                   (not (= number (mail-header-number (cadr headers)))))
9772         (pop headers))
9773       (when (cdr headers)
9774         (setcdr headers (cddr headers))))))
9775
9776 ;;;
9777 ;;; summary highlights
9778 ;;;
9779
9780 (defun gnus-highlight-selected-summary ()
9781   "Highlight selected article in summary buffer."
9782   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
9783   (when gnus-summary-selected-face
9784     (save-excursion
9785       (let* ((beg (progn (beginning-of-line) (point)))
9786              (end (progn (end-of-line) (point)))
9787              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9788              (from (if (get-text-property beg gnus-mouse-face-prop)
9789                        beg
9790                      (or (next-single-property-change
9791                           beg gnus-mouse-face-prop nil end)
9792                          beg)))
9793              (to
9794               (if (= from end)
9795                   (- from 2)
9796                 (or (next-single-property-change
9797                      from gnus-mouse-face-prop nil end)
9798                     end))))
9799         ;; If no mouse-face prop on line we will have to = from = end,
9800         ;; so we highlight the entire line instead.
9801         (when (= (+ to 2) from)
9802           (setq from beg)
9803           (setq to end))
9804         (if gnus-newsgroup-selected-overlay
9805             ;; Move old overlay.
9806             (gnus-move-overlay
9807              gnus-newsgroup-selected-overlay from to (current-buffer))
9808           ;; Create new overlay.
9809           (gnus-overlay-put
9810            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9811            'face gnus-summary-selected-face))))))
9812
9813 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9814 (defun gnus-summary-highlight-line ()
9815   "Highlight current line according to `gnus-summary-highlight'."
9816   (let* ((list gnus-summary-highlight)
9817          (p (point))
9818          (end (progn (end-of-line) (point)))
9819          ;; now find out where the line starts and leave point there.
9820          (beg (progn (beginning-of-line) (point)))
9821          (article (gnus-summary-article-number))
9822          (score (or (cdr (assq (or article gnus-current-article)
9823                                gnus-newsgroup-scored))
9824                     gnus-summary-default-score 0))
9825          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9826          (inhibit-read-only t))
9827     ;; Eval the cars of the lists until we find a match.
9828     (let ((default gnus-summary-default-score))
9829       (while (and list
9830                   (not (eval (caar list))))
9831         (setq list (cdr list))))
9832     (let ((face (cdar list)))
9833       (unless (eq face (get-text-property beg 'face))
9834         (gnus-put-text-property-excluding-characters-with-faces
9835          beg end 'face
9836          (setq face (if (boundp face) (symbol-value face) face)))
9837         (when gnus-summary-highlight-line-function
9838           (funcall gnus-summary-highlight-line-function article face))))
9839     (goto-char p)))
9840
9841 (defun gnus-update-read-articles (group unread &optional compute)
9842   "Update the list of read articles in GROUP."
9843   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9844          (entry (gnus-gethash group gnus-newsrc-hashtb))
9845          (info (nth 2 entry))
9846          (prev 1)
9847          (unread (sort (copy-sequence unread) '<))
9848          read)
9849     (if (or (not info) (not active))
9850         ;; There is no info on this group if it was, in fact,
9851         ;; killed.  Gnus stores no information on killed groups, so
9852         ;; there's nothing to be done.
9853         ;; One could store the information somewhere temporarily,
9854         ;; perhaps...  Hmmm...
9855         ()
9856       ;; Remove any negative articles numbers.
9857       (while (and unread (< (car unread) 0))
9858         (setq unread (cdr unread)))
9859       ;; Remove any expired article numbers
9860       (while (and unread (< (car unread) (car active)))
9861         (setq unread (cdr unread)))
9862       ;; Compute the ranges of read articles by looking at the list of
9863       ;; unread articles.
9864       (while unread
9865         (when (/= (car unread) prev)
9866           (push (if (= prev (1- (car unread))) prev
9867                   (cons prev (1- (car unread))))
9868                 read))
9869         (setq prev (1+ (car unread)))
9870         (setq unread (cdr unread)))
9871       (when (<= prev (cdr active))
9872         (push (cons prev (cdr active)) read))
9873       (setq read (if (> (length read) 1) (nreverse read) read))
9874       (if compute
9875           read
9876         (save-excursion
9877           (let (setmarkundo)
9878             ;; Propagate the read marks to the backend.
9879             (when (gnus-check-backend-function 'request-set-mark group)
9880               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9881                     (add (gnus-remove-from-range read (gnus-info-read info))))
9882                 (when (or add del)
9883                   (unless (gnus-check-group group)
9884                     (error "Can't open server for %s" group))
9885                   (gnus-request-set-mark
9886                    group (delq nil (list (if add (list add 'add '(read)))
9887                                          (if del (list del 'del '(read))))))
9888                   (setq setmarkundo
9889                         `(gnus-request-set-mark
9890                           ,group
9891                           ',(delq nil (list
9892                                        (if del (list del 'add '(read)))
9893                                        (if add (list add 'del '(read))))))))))
9894             (set-buffer gnus-group-buffer)
9895             (gnus-undo-register
9896               `(progn
9897                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9898                  (gnus-info-set-read ',info ',(gnus-info-read info))
9899                  (gnus-get-unread-articles-in-group ',info 
9900                                                     (gnus-active ,group))
9901                  (gnus-group-update-group ,group t)
9902                  ,setmarkundo))))
9903         ;; Enter this list into the group info.
9904         (gnus-info-set-read info read)
9905         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9906         (gnus-get-unread-articles-in-group info (gnus-active group))
9907         t))))
9908
9909 (defun gnus-offer-save-summaries ()
9910   "Offer to save all active summary buffers."
9911   (save-excursion
9912     (let ((buflist (buffer-list))
9913           buffers bufname)
9914       ;; Go through all buffers and find all summaries.
9915       (while buflist
9916         (and (setq bufname (buffer-name (car buflist)))
9917              (string-match "Summary" bufname)
9918              (save-excursion
9919                (set-buffer bufname)
9920                ;; We check that this is, indeed, a summary buffer.
9921                (and (eq major-mode 'gnus-summary-mode)
9922                     ;; Also make sure this isn't bogus.
9923                     gnus-newsgroup-prepared
9924                     ;; Also make sure that this isn't a dead summary buffer.
9925                     (not gnus-dead-summary-mode)))
9926              (push bufname buffers))
9927         (setq buflist (cdr buflist)))
9928       ;; Go through all these summary buffers and offer to save them.
9929       (when buffers
9930         (map-y-or-n-p
9931          "Update summary buffer %s? "
9932          (lambda (buf)
9933            (switch-to-buffer buf)
9934            (gnus-summary-exit))
9935          buffers)))))
9936
9937
9938 ;;; @ for mime-partial
9939 ;;;
9940
9941 (defun gnus-request-partial-message ()
9942   (save-excursion
9943     (let ((number (gnus-summary-article-number))
9944           (group gnus-newsgroup-name)
9945           (mother gnus-article-buffer))
9946       (set-buffer (get-buffer-create " *Partial Article*"))
9947       (erase-buffer)
9948       (setq mime-preview-buffer mother)
9949       (gnus-request-article-this-buffer number group)
9950       (mime-parse-buffer)
9951       )))
9952
9953 (autoload 'mime-combine-message/partial-pieces-automatically
9954   "mime-partial"
9955   "Internal method to combine message/partial messages automatically.")
9956
9957 (mime-add-condition
9958  'action '((type . message)(subtype . partial)
9959            (major-mode . gnus-original-article-mode)
9960            (method . mime-combine-message/partial-pieces-automatically)
9961            (summary-buffer-exp . gnus-summary-buffer)
9962            (request-partial-message-method . gnus-request-partial-message)
9963            ))
9964
9965
9966 ;;; @ for message/rfc822
9967 ;;;
9968
9969 (defun gnus-mime-extract-message/rfc822 (entity situation)
9970   (let (group article num cwin swin cur)
9971     (with-temp-buffer
9972       (mime-insert-entity-content entity)
9973       (setq group (or (cdr (assq 'group situation))
9974                       (completing-read "Group: "
9975                                        gnus-active-hashtb
9976                                        nil
9977                                        (gnus-read-active-file-p)
9978                                        gnus-newsgroup-name))
9979             article (gnus-request-accept-article group)))
9980     (when (and (consp article)
9981                (numberp (setq article (cdr article))))
9982       (setq num (1+ (or (cdr (assq 'number situation)) 0))
9983             cwin (get-buffer-window (current-buffer) t))
9984       (save-window-excursion
9985         (if (setq swin (get-buffer-window gnus-summary-buffer t))
9986             (select-window swin)
9987           (set-buffer gnus-summary-buffer))
9988         (setq cur gnus-current-article)
9989         (forward-line num)
9990         (let (gnus-show-threads)
9991           (gnus-summary-goto-subject article t))
9992         (gnus-summary-clear-mark-forward 1)
9993         (gnus-summary-goto-subject cur))
9994       (when (and cwin (window-frame cwin))
9995         (select-frame (window-frame cwin)))
9996       (when (boundp 'mime-acting-situation-to-override)
9997         (set-alist 'mime-acting-situation-to-override
9998                    'group
9999                    group)
10000         (set-alist 'mime-acting-situation-to-override
10001                    'after-method
10002                    `(progn
10003                       (save-current-buffer
10004                         (set-buffer gnus-group-buffer)
10005                         (gnus-activate-group ,group))
10006                       (gnus-summary-goto-article ,cur
10007                                                  gnus-show-all-headers)))
10008         (set-alist 'mime-acting-situation-to-override
10009                    'number num)))))
10010
10011 (mime-add-condition
10012  'action '((type . message)(subtype . rfc822)
10013            (major-mode . gnus-original-article-mode)
10014            (method . gnus-mime-extract-message/rfc822)
10015            (mode . "extract")
10016            ))
10017
10018 (mime-add-condition
10019  'action '((type . message)(subtype . news)
10020            (major-mode . gnus-original-article-mode)
10021            (method . gnus-mime-extract-message/rfc822)
10022            (mode . "extract")
10023            ))
10024
10025 (defun gnus-mime-extract-multipart (entity situation)
10026   (let ((children (mime-entity-children entity))
10027         mime-acting-situation-to-override
10028         f)
10029     (while children
10030       (mime-play-entity (car children)
10031                         (cons (assq 'mode situation)
10032                               mime-acting-situation-to-override))
10033       (setq children (cdr children)))
10034     (if (setq f (cdr (assq 'after-method
10035                            mime-acting-situation-to-override)))
10036         (eval f)
10037       )))
10038
10039 (mime-add-condition
10040  'action '((type . multipart)
10041            (method . gnus-mime-extract-multipart)
10042            (mode . "extract")
10043            )
10044  'with-default)
10045
10046
10047 ;;; @ end
10048 ;;;
10049
10050 (defun gnus-summary-setup-default-charset ()
10051   "Setup newsgroup default charset."
10052   (if (equal gnus-newsgroup-name "nndraft:drafts")
10053       (setq gnus-newsgroup-charset nil)
10054     (let* ((name (and gnus-newsgroup-name
10055                       (gnus-group-real-name gnus-newsgroup-name)))
10056            (ignored-charsets
10057             (or gnus-newsgroup-ephemeral-ignored-charsets
10058                 (append
10059                  (and gnus-newsgroup-name
10060                       (or (gnus-group-find-parameter gnus-newsgroup-name
10061                                                      'ignored-charsets t)
10062                           (let ((alist gnus-group-ignored-charsets-alist)
10063                                 elem (charsets nil))
10064                             (while (setq elem (pop alist))
10065                               (when (and name
10066                                          (string-match (car elem) name))
10067                                 (setq alist nil
10068                                       charsets (cdr elem))))
10069                             charsets)))
10070                  gnus-newsgroup-ignored-charsets))))
10071       (setq gnus-newsgroup-charset
10072             (or gnus-newsgroup-ephemeral-charset
10073                 (and gnus-newsgroup-name
10074                      (or (gnus-group-find-parameter gnus-newsgroup-name 'charset)
10075                          (let ((alist gnus-group-charset-alist)
10076                                elem charset)
10077                            (while (setq elem (pop alist))
10078                              (when (and name
10079                                         (string-match (car elem) name))
10080                                (setq alist nil
10081                                      charset (cadr elem))))
10082                            charset)))
10083                 gnus-default-charset))
10084       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10085            ignored-charsets))))
10086
10087 ;;;
10088 ;;; Mime Commands
10089 ;;;
10090
10091 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10092   "Display the current article buffer fully MIME-buttonized.
10093 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10094 treated as multipart/mixed."
10095   (interactive "P")
10096   (require 'gnus-art)
10097   (let ((gnus-unbuttonized-mime-types nil)
10098         (gnus-mime-display-multipart-as-mixed show-all-parts))
10099     (gnus-summary-show-article)))
10100
10101 (defun gnus-summary-repair-multipart (article)
10102   "Add a Content-Type header to a multipart article without one."
10103   (interactive (list (gnus-summary-article-number)))
10104   (gnus-with-article article
10105     (message-narrow-to-head)
10106     (message-remove-header "Mime-Version")
10107     (goto-char (point-max))
10108     (insert "Mime-Version: 1.0\n")
10109     (widen)
10110     (when (search-forward "\n--" nil t)
10111       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10112         (message-narrow-to-head)
10113         (message-remove-header "Content-Type")
10114         (goto-char (point-max))
10115         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10116                         separator))
10117         (widen))))
10118   (let (gnus-mark-article-hook)
10119     (gnus-summary-select-article t t nil article)))
10120
10121 (defun gnus-summary-toggle-display-buttonized ()
10122   "Toggle the buttonizing of the article buffer."
10123   (interactive)
10124   (require 'gnus-art)
10125   (if (setq gnus-inhibit-mime-unbuttonizing
10126             (not gnus-inhibit-mime-unbuttonizing))
10127       (let ((gnus-unbuttonized-mime-types nil))
10128         (gnus-summary-show-article))
10129     (gnus-summary-show-article)))
10130
10131 ;;;
10132 ;;; Intelli-mouse commmands
10133 ;;;
10134
10135 (defun gnus-wheel-summary-scroll (event)
10136   (interactive "e")
10137   (let ((amount (if (memq 'shift (event-modifiers event))
10138                     (car gnus-wheel-scroll-amount)
10139                   (cdr gnus-wheel-scroll-amount)))
10140         (direction (- (* (static-if (featurep 'xemacs)
10141                              (event-button event)
10142                            (cond ((eq 'mouse-4 (event-basic-type event))
10143                                   4)
10144                                  ((eq 'mouse-5 (event-basic-type event))
10145                                   5)))
10146                          2) 9))
10147         edge)
10148     (gnus-summary-scroll-up (* amount direction))
10149     (when (gnus-eval-in-buffer-window gnus-article-buffer
10150             (save-restriction
10151               (widen)
10152               (and (if (< 0 direction)
10153                        (gnus-article-next-page 0)
10154                      (gnus-article-prev-page 0)
10155                      (bobp))
10156                    (if (setq edge (get-text-property
10157                                    (point-min) 'gnus-wheel-edge))
10158                        (setq edge (* edge direction))
10159                      (setq edge -1))
10160                    (or (plusp edge)
10161                        (let ((buffer-read-only nil)
10162                              (inhibit-read-only t))
10163                          (put-text-property (point-min) (point-max)
10164                                             'gnus-wheel-edge direction)
10165                          nil))
10166                    (or (> edge gnus-wheel-edge-resistance)
10167                        (let ((buffer-read-only nil)
10168                              (inhibit-read-only t))
10169                          (put-text-property (point-min) (point-max)
10170                                             'gnus-wheel-edge
10171                                             (* (1+ edge) direction))
10172                          nil))
10173                    (eq last-command 'gnus-wheel-summary-scroll))))
10174       (gnus-summary-next-article nil nil (minusp direction)))))
10175
10176 (defun gnus-wheel-install ()
10177   "Enable mouse wheel support on summary window."
10178   (when gnus-use-wheel
10179     (let ((keys
10180            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
10181       (dolist (key keys)
10182         (define-key gnus-summary-mode-map key
10183           'gnus-wheel-summary-scroll)))))
10184
10185 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
10186
10187 ;;;
10188 ;;; Traditional PGP commmands
10189 ;;;
10190
10191 (defun gnus-summary-decrypt-article (&optional force)
10192   "Decrypt the current article in traditional PGP way.
10193 This will have permanent effect only in mail groups.
10194 If FORCE is non-nil, allow editing of articles even in read-only
10195 groups."
10196   (interactive "P")
10197   (gnus-summary-select-article t)
10198   (gnus-eval-in-buffer-window gnus-article-buffer
10199     (save-excursion
10200       (save-restriction
10201         (widen)
10202         (goto-char (point-min))
10203         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
10204           (error "Not a traditional PGP message!"))
10205         (let ((armor-start (match-beginning 0)))
10206           (if (and (pgg-decrypt-region armor-start (point-max))
10207                    (or force (not (gnus-group-read-only-p))))
10208               (let ((inhibit-read-only t)
10209                     buffer-read-only)
10210                 (delete-region armor-start
10211                                (progn
10212                                  (re-search-forward "^-+END PGP" nil t)
10213                                  (beginning-of-line 2)
10214                                  (point)))
10215                 (insert-buffer-substring pgg-output-buffer))))))))
10216
10217 (defun gnus-summary-verify-article ()
10218   "Verify the current article in traditional PGP way."
10219   (interactive)
10220   (save-excursion
10221     (set-buffer gnus-original-article-buffer)
10222     (goto-char (point-min))
10223     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
10224       (error "Not a traditional PGP message!"))
10225     (re-search-forward "^-+END PGP" nil t)
10226     (beginning-of-line 2)
10227     (call-interactively (function pgg-verify-region))))
10228
10229 ;;;
10230 ;;; Generic summary marking commands
10231 ;;;
10232
10233 (defvar gnus-summary-marking-alist
10234   '((read gnus-del-mark "d")
10235     (unread gnus-unread-mark "u")
10236     (ticked gnus-ticked-mark "!")
10237     (dormant gnus-dormant-mark "?")
10238     (expirable gnus-expirable-mark "e"))
10239   "An alist of names/marks/keystrokes.")
10240
10241 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10242 (defvar gnus-summary-mark-map)
10243
10244 (defun gnus-summary-make-all-marking-commands ()
10245   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10246   (dolist (elem gnus-summary-marking-alist)
10247     (apply 'gnus-summary-make-marking-command elem)))
10248
10249 (defun gnus-summary-make-marking-command (name mark keystroke)
10250   (let ((map (make-sparse-keymap)))
10251     (define-key gnus-summary-generic-mark-map keystroke map)
10252     (dolist (lway `((next "next" next nil "n")
10253                     (next-unread "next unread" next t "N")
10254                     (prev "previous" prev nil "p")
10255                     (prev-unread "previous unread" prev t "P")
10256                     (nomove "" nil nil ,keystroke)))
10257       (let ((func (gnus-summary-make-marking-command-1
10258                    mark (car lway) lway name)))
10259         (setq func (eval func))
10260         (define-key map (nth 4 lway) func)))))
10261
10262 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10263   `(defun ,(intern
10264             (format "gnus-summary-put-mark-as-%s%s"
10265                     name (if (eq way 'nomove)
10266                              ""
10267                            (concat "-" (symbol-name way)))))
10268      (n)
10269      ,(format
10270        "Mark the current article as %s%s.
10271 If N, the prefix, then repeat N times.
10272 If N is negative, move in reverse order.
10273 The difference between N and the actual number of articles marked is
10274 returned."
10275        name (car (cdr lway)))
10276      (interactive "p")
10277      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10278
10279 (defun gnus-summary-generic-mark (n mark move unread)
10280   "Mark N articles with MARK."
10281   (unless (eq major-mode 'gnus-summary-mode)
10282     (error "This command can only be used in the summary buffer"))
10283   (gnus-summary-show-thread)
10284   (let ((nummove
10285          (cond
10286           ((eq move 'next) 1)
10287           ((eq move 'prev) -1)
10288           (t 0))))
10289     (if (zerop nummove)
10290         (setq n 1)
10291       (when (< n 0)
10292         (setq n (abs n)
10293               nummove (* -1 nummove))))
10294     (while (and (> n 0)
10295                 (gnus-summary-mark-article nil mark)
10296                 (zerop (gnus-summary-next-subject nummove unread t)))
10297       (setq n (1- n)))
10298     (when (/= 0 n)
10299       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10300     (gnus-summary-recenter)
10301     (gnus-summary-position-point)
10302     (gnus-set-mode-line 'summary)
10303     n))
10304
10305 (gnus-summary-make-all-marking-commands)
10306
10307 (gnus-ems-redefine)
10308
10309 (provide 'gnus-sum)
10310
10311 (run-hooks 'gnus-sum-load-hook)
10312
10313 ;;; gnus-sum.el ends here