ad7075cca3809b5016c13b4d9948bd0fb5afab16
[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 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
59 (autoload 'mm-uu-dissect "mm-uu")
60
61 (defcustom gnus-kill-summary-on-exit t
62   "*If non-nil, kill the summary buffer when you exit from it.
63 If nil, the summary will become a \"*Dead Summary*\" buffer, and
64 it will be killed sometime later."
65   :group 'gnus-summary-exit
66   :type 'boolean)
67
68 (defcustom gnus-fetch-old-headers nil
69   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
70 If an unread article in the group refers to an older, already read (or
71 just marked as read) article, the old article will not normally be
72 displayed in the Summary buffer.  If this variable is non-nil, Gnus
73 will attempt to grab the headers to the old articles, and thereby
74 build complete threads.  If it has the value `some', only enough
75 headers to connect otherwise loose threads will be displayed.  This
76 variable can also be a number.  In that case, no more than that number
77 of old headers will be fetched.  If it has the value `invisible', all
78 old headers will be fetched, but none will be displayed.
79
80 The server has to support NOV for any of this to work."
81   :group 'gnus-thread
82   :type '(choice (const :tag "off" nil)
83                  (const some)
84                  number
85                  (sexp :menu-tag "other" t)))
86
87 (defcustom gnus-refer-thread-limit 200
88   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
89 If t, fetch all the available old headers."
90   :group 'gnus-thread
91   :type '(choice number
92                  (sexp :menu-tag "other" t)))
93
94 (defcustom gnus-summary-make-false-root 'adopt
95   "*nil means that Gnus won't gather loose threads.
96 If the root of a thread has expired or been read in a previous
97 session, the information necessary to build a complete thread has been
98 lost.  Instead of having many small sub-threads from this original thread
99 scattered all over the summary buffer, Gnus can gather them.
100
101 If non-nil, Gnus will try to gather all loose sub-threads from an
102 original thread into one large thread.
103
104 If this variable is non-nil, it should be one of `none', `adopt',
105 `dummy' or `empty'.
106
107 If this variable is `none', Gnus will not make a false root, but just
108 present the sub-threads after another.
109 If this variable is `dummy', Gnus will create a dummy root that will
110 have all the sub-threads as children.
111 If this variable is `adopt', Gnus will make one of the \"children\"
112 the parent and mark all the step-children as such.
113 If this variable is `empty', the \"children\" are printed with empty
114 subject fields.  (Or rather, they will be printed with a string
115 given by the `gnus-summary-same-subject' variable.)"
116   :group 'gnus-thread
117   :type '(choice (const :tag "off" nil)
118                  (const none)
119                  (const dummy)
120                  (const adopt)
121                  (const empty)))
122
123 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
124   "*A regexp to match subjects to be excluded from loose thread gathering.
125 As loose thread gathering is done on subjects only, that means that
126 there can be many false gatherings performed.  By rooting out certain
127 common subjects, gathering might become saner."
128   :group 'gnus-thread
129   :type 'regexp)
130
131 (defcustom gnus-summary-gather-subject-limit nil
132   "*Maximum length of subject comparisons when gathering loose threads.
133 Use nil to compare full subjects.  Setting this variable to a low
134 number will help gather threads that have been corrupted by
135 newsreaders chopping off subject lines, but it might also mean that
136 unrelated articles that have subject that happen to begin with the
137 same few characters will be incorrectly gathered.
138
139 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
140 comparing subjects."
141   :group 'gnus-thread
142   :type '(choice (const :tag "off" nil)
143                  (const fuzzy)
144                  (sexp :menu-tag "on" t)))
145
146 (defcustom gnus-simplify-subject-functions nil
147   "List of functions taking a string argument that simplify subjects.
148 The functions are applied recursively.
149
150 Useful functions to put in this list include: `gnus-simplify-subject-re',
151 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
152   :group 'gnus-thread
153   :type '(repeat function))
154
155 (defcustom gnus-simplify-ignored-prefixes nil
156   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
157   :group 'gnus-thread
158   :type '(choice (const :tag "off" nil)
159                  regexp))
160
161 (defcustom gnus-build-sparse-threads nil
162   "*If non-nil, fill in the gaps in threads.
163 If `some', only fill in the gaps that are needed to tie loose threads
164 together.  If `more', fill in all leaf nodes that Gnus can find.  If
165 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  (const some)
169                  (const more)
170                  (sexp :menu-tag "all" t)))
171
172 (defcustom gnus-summary-thread-gathering-function
173   'gnus-gather-threads-by-subject
174   "*Function used for gathering loose threads.
175 There are two pre-defined functions: `gnus-gather-threads-by-subject',
176 which only takes Subjects into consideration; and
177 `gnus-gather-threads-by-references', which compared the References
178 headers of the articles to find matches."
179   :group 'gnus-thread
180   :type '(radio (function-item gnus-gather-threads-by-subject)
181                 (function-item gnus-gather-threads-by-references)
182                 (function :tag "other")))
183
184 (defcustom gnus-summary-same-subject ""
185   "*String indicating that the current article has the same subject as the previous.
186 This variable will only be used if the value of
187 `gnus-summary-make-false-root' is `empty'."
188   :group 'gnus-summary-format
189   :type 'string)
190
191 (defcustom gnus-summary-goto-unread t
192   "*If t, many commands will go to the next unread article.
193 This applies to marking commands as well as other commands that
194 \"naturally\" select the next article, like, for instance, `SPC' at
195 the end of an article.
196
197 If nil, the marking commands do NOT go to the next unread article
198 (they go to the next article instead).  If `never', commands that
199 usually go to the next unread article, will go to the next article,
200 whether it is read or not."
201   :group 'gnus-summary-marks
202   :link '(custom-manual "(gnus)Setting Marks")
203   :type '(choice (const :tag "off" nil)
204                  (const never)
205                  (sexp :menu-tag "on" t)))
206
207 (defcustom gnus-summary-default-score 0
208   "*Default article score level.
209 All scores generated by the score files will be added to this score.
210 If this variable is nil, scoring will be disabled."
211   :group 'gnus-score-default
212   :type '(choice (const :tag "disable")
213                  integer))
214
215 (defcustom gnus-summary-zcore-fuzz 0
216   "*Fuzziness factor for the zcore in the summary buffer.
217 Articles with scores closer than this to `gnus-summary-default-score'
218 will not be marked."
219   :group 'gnus-summary-format
220   :type 'integer)
221
222 (defcustom gnus-simplify-subject-fuzzy-regexp nil
223   "*Strings to be removed when doing fuzzy matches.
224 This can either be a regular expression or list of regular expressions
225 that will be removed from subject strings if fuzzy subject
226 simplification is selected."
227   :group 'gnus-thread
228   :type '(repeat regexp))
229
230 (defcustom gnus-show-threads t
231   "*If non-nil, display threads in summary mode."
232   :group 'gnus-thread
233   :type 'boolean)
234
235 (defcustom gnus-thread-hide-subtree nil
236   "*If non-nil, hide all threads initially.
237 If threads are hidden, you have to run the command
238 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
239 to expose hidden threads."
240   :group 'gnus-thread
241   :type 'boolean)
242
243 (defcustom gnus-thread-hide-killed t
244   "*If non-nil, hide killed threads automatically."
245   :group 'gnus-thread
246   :type 'boolean)
247
248 (defcustom gnus-thread-ignore-subject t
249   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
250 If nil, articles that have different subjects from their parents will
251 start separate threads."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-operation-ignore-subject t
256   "*If non-nil, subjects will be ignored when doing thread commands.
257 This affects commands like `gnus-summary-kill-thread' and
258 `gnus-summary-lower-thread'.
259
260 If this variable is nil, articles in the same thread with different
261 subjects will not be included in the operation in question.  If this
262 variable is `fuzzy', only articles that have subjects that are fuzzily
263 equal will be included."
264   :group 'gnus-thread
265   :type '(choice (const :tag "off" nil)
266                  (const fuzzy)
267                  (sexp :tag "on" t)))
268
269 (defcustom gnus-thread-indent-level 4
270   "*Number that says how much each sub-thread should be indented."
271   :group 'gnus-thread
272   :type 'integer)
273
274 (defcustom gnus-auto-extend-newsgroup t
275   "*If non-nil, extend newsgroup forward and backward when requested."
276   :group 'gnus-summary-choose
277   :type 'boolean)
278
279 (defcustom gnus-auto-select-first t
280   "*If nil, don't select the first unread article when entering a group.
281 If this variable is `best', select the highest-scored unread article
282 in the group.  If t, select the first unread article.
283
284 This variable can also be a function to place point on a likely
285 subject line.  Useful values include `gnus-summary-first-unread-subject',
286 `gnus-summary-first-unread-article' and
287 `gnus-summary-best-unread-article'.
288
289 If you want to prevent automatic selection of the first unread article
290 in some newsgroups, set the variable to nil in
291 `gnus-select-group-hook'."
292   :group 'gnus-group-select
293   :type '(choice (const :tag "none" nil)
294                  (const best)
295                  (sexp :menu-tag "first" t)
296                  (function-item gnus-summary-first-unread-subject)
297                  (function-item gnus-summary-first-unread-article)
298                  (function-item gnus-summary-best-unread-article)))
299
300 (defcustom gnus-dont-select-after-jump-to-other-group nil
301   "If non-nil, don't select the first unread article after entering the
302 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
303 it is depend on the value of `gnus-auto-select-first' whether to select
304 or not."
305   :group 'gnus-group-select
306   :type 'boolean)
307
308 (defcustom gnus-auto-select-next t
309   "*If non-nil, offer to go to the next group from the end of the previous.
310 If the value is t and the next newsgroup is empty, Gnus will exit
311 summary mode and go back to group mode.  If the value is neither nil
312 nor t, Gnus will select the following unread newsgroup.  In
313 particular, if the value is the symbol `quietly', the next unread
314 newsgroup will be selected without any confirmation, and if it is
315 `almost-quietly', the next group will be selected without any
316 confirmation if you are located on the last article in the group.
317 Finally, if this variable is `slightly-quietly', the `Z n' command
318 will go to the next group without confirmation."
319   :group 'gnus-summary-maneuvering
320   :type '(choice (const :tag "off" nil)
321                  (const quietly)
322                  (const almost-quietly)
323                  (const slightly-quietly)
324                  (sexp :menu-tag "on" t)))
325
326 (defcustom gnus-auto-select-same nil
327   "*If non-nil, select the next article with the same subject.
328 If there are no more articles with the same subject, go to
329 the first unread article."
330   :group 'gnus-summary-maneuvering
331   :type 'boolean)
332
333 (defcustom gnus-summary-check-current nil
334   "*If non-nil, consider the current article when moving.
335 The \"unread\" movement commands will stay on the same line if the
336 current article is unread."
337   :group 'gnus-summary-maneuvering
338   :type 'boolean)
339
340 (defcustom gnus-auto-center-summary t
341   "*If non-nil, always center the current summary buffer.
342 In particular, if `vertical' do only vertical recentering.  If non-nil
343 and non-`vertical', do both horizontal and vertical recentering."
344   :group 'gnus-summary-maneuvering
345   :type '(choice (const :tag "none" nil)
346                  (const vertical)
347                  (integer :tag "height")
348                  (sexp :menu-tag "both" t)))
349
350 (defcustom gnus-show-all-headers nil
351   "*If non-nil, don't hide any headers."
352   :group 'gnus-article-hiding
353   :group 'gnus-article-headers
354   :type 'boolean)
355
356 (defcustom gnus-summary-ignore-duplicates nil
357   "*If non-nil, ignore articles with identical Message-ID headers."
358   :group 'gnus-summary
359   :type 'boolean)
360
361 (defcustom gnus-single-article-buffer t
362   "*If non-nil, display all articles in the same buffer.
363 If nil, each group will get its own article buffer."
364   :group 'gnus-article-various
365   :type 'boolean)
366
367 (defcustom gnus-break-pages t
368   "*If non-nil, do page breaking on articles.
369 The page delimiter is specified by the `gnus-page-delimiter'
370 variable."
371   :group 'gnus-article-various
372   :type 'boolean)
373
374 (defcustom gnus-show-mime t
375   "*If non-nil, do mime processing of articles.
376 The articles will simply be fed to the function given by
377 `gnus-article-display-method-for-mime'."
378   :group 'gnus-article-mime
379   :type 'boolean)
380
381 (defcustom gnus-move-split-methods nil
382   "*Variable used to suggest where articles are to be moved to.
383 It uses the same syntax as the `gnus-split-methods' variable.
384 However, whereas `gnus-split-methods' specifies file names as targets,
385 this variable specifies group names."
386   :group 'gnus-summary-mail
387   :type '(repeat (choice (list :value (fun) function)
388                          (cons :value ("" "") regexp (repeat string))
389                          (sexp :value nil))))
390
391 (defcustom gnus-unread-mark ?  ;Whitespace
392   "*Mark used for unread articles."
393   :group 'gnus-summary-marks
394   :type 'character)
395
396 (defcustom gnus-ticked-mark ?!
397   "*Mark used for ticked articles."
398   :group 'gnus-summary-marks
399   :type 'character)
400
401 (defcustom gnus-dormant-mark ??
402   "*Mark used for dormant articles."
403   :group 'gnus-summary-marks
404   :type 'character)
405
406 (defcustom gnus-del-mark ?r
407   "*Mark used for del'd articles."
408   :group 'gnus-summary-marks
409   :type 'character)
410
411 (defcustom gnus-read-mark ?R
412   "*Mark used for read articles."
413   :group 'gnus-summary-marks
414   :type 'character)
415
416 (defcustom gnus-expirable-mark ?E
417   "*Mark used for expirable articles."
418   :group 'gnus-summary-marks
419   :type 'character)
420
421 (defcustom gnus-killed-mark ?K
422   "*Mark used for killed articles."
423   :group 'gnus-summary-marks
424   :type 'character)
425
426 (defcustom gnus-souped-mark ?F
427   "*Mark used for killed articles."
428   :group 'gnus-summary-marks
429   :type 'character)
430
431 (defcustom gnus-kill-file-mark ?X
432   "*Mark used for articles killed by kill files."
433   :group 'gnus-summary-marks
434   :type 'character)
435
436 (defcustom gnus-low-score-mark ?Y
437   "*Mark used for articles with a low score."
438   :group 'gnus-summary-marks
439   :type 'character)
440
441 (defcustom gnus-catchup-mark ?C
442   "*Mark used for articles that are caught up."
443   :group 'gnus-summary-marks
444   :type 'character)
445
446 (defcustom gnus-replied-mark ?A
447   "*Mark used for articles that have been replied to."
448   :group 'gnus-summary-marks
449   :type 'character)
450
451 (defcustom gnus-cached-mark ?*
452   "*Mark used for articles that are in the cache."
453   :group 'gnus-summary-marks
454   :type 'character)
455
456 (defcustom gnus-saved-mark ?S
457   "*Mark used for articles that have been saved to."
458   :group 'gnus-summary-marks
459   :type 'character)
460
461 (defcustom gnus-ancient-mark ?O
462   "*Mark used for ancient articles."
463   :group 'gnus-summary-marks
464   :type 'character)
465
466 (defcustom gnus-sparse-mark ?Q
467   "*Mark used for sparsely reffed articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-canceled-mark ?G
472   "*Mark used for canceled articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-duplicate-mark ?M
477   "*Mark used for duplicate articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-undownloaded-mark ?@
482   "*Mark used for articles that weren't downloaded."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-downloadable-mark ?%
487   "*Mark used for articles that are to be downloaded."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-unsendable-mark ?=
492   "*Mark used for articles that won't be sent."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-score-over-mark ?+
497   "*Score mark used for articles with high scores."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-score-below-mark ?-
502   "*Score mark used for articles with low scores."
503   :group 'gnus-summary-marks
504   :type 'character)
505
506 (defcustom gnus-empty-thread-mark ?  ;Whitespace
507   "*There is no thread under the article."
508   :group 'gnus-summary-marks
509   :type 'character)
510
511 (defcustom gnus-not-empty-thread-mark ?=
512   "*There is a thread under the article."
513   :group 'gnus-summary-marks
514   :type 'character)
515
516 (defcustom gnus-view-pseudo-asynchronously nil
517   "*If non-nil, Gnus will view pseudo-articles asynchronously."
518   :group 'gnus-extract-view
519   :type 'boolean)
520
521 (defcustom gnus-auto-expirable-marks
522   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
523         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
524         gnus-souped-mark gnus-duplicate-mark)
525   "*The list of marks converted into expiration if a group is auto-expirable."
526   :version "21.1"
527   :group 'gnus-summary
528   :type '(repeat character))
529
530 (defcustom gnus-inhibit-user-auto-expire t
531   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
532   :version "21.1"
533   :group 'gnus-summary
534   :type 'boolean)
535
536 (defcustom gnus-view-pseudos nil
537   "*If `automatic', pseudo-articles will be viewed automatically.
538 If `not-confirm', pseudos will be viewed automatically, and the user
539 will not be asked to confirm the command."
540   :group 'gnus-extract-view
541   :type '(choice (const :tag "off" nil)
542                  (const automatic)
543                  (const not-confirm)))
544
545 (defcustom gnus-view-pseudos-separately t
546   "*If non-nil, one pseudo-article will be created for each file to be viewed.
547 If nil, all files that use the same viewing command will be given as a
548 list of parameters to that command."
549   :group 'gnus-extract-view
550   :type 'boolean)
551
552 (defcustom gnus-insert-pseudo-articles t
553   "*If non-nil, insert pseudo-articles when decoding articles."
554   :group 'gnus-extract-view
555   :type 'boolean)
556
557 (defcustom gnus-summary-dummy-line-format
558   "  %(:                          :%) %S\n"
559   "*The format specification for the dummy roots in the summary buffer.
560 It works along the same lines as a normal formatting string,
561 with some simple extensions.
562
563 %S  The subject"
564   :group 'gnus-threading
565   :type 'string)
566
567 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
568   "*The format specification for the summary mode line.
569 It works along the same lines as a normal formatting string,
570 with some simple extensions:
571
572 %G  Group name
573 %p  Unprefixed group name
574 %A  Current article number
575 %z  Current article score
576 %V  Gnus version
577 %U  Number of unread articles in the group
578 %e  Number of unselected articles in the group
579 %Z  A string with unread/unselected article counts
580 %g  Shortish group name
581 %S  Subject of the current article
582 %u  User-defined spec
583 %s  Current score file name
584 %d  Number of dormant articles
585 %r  Number of articles that have been marked as read in this session
586 %E  Number of articles expunged by the score files"
587   :group 'gnus-summary-format
588   :type 'string)
589
590 (defcustom gnus-list-identifiers nil
591   "Regexp that matches list identifiers to be removed from subject.
592 This can also be a list of regexps."
593   :version "21.1"
594   :group 'gnus-summary-format
595   :group 'gnus-article-hiding
596   :type '(choice (const :tag "none" nil)
597                  (regexp :value ".*")
598                  (repeat :value (".*") regexp)))
599
600 (defcustom gnus-summary-mark-below 0
601   "*Mark all articles with a score below this variable as read.
602 This variable is local to each summary buffer and usually set by the
603 score file."
604   :group 'gnus-score-default
605   :type 'integer)
606
607 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
608   "*List of functions used for sorting articles in the summary buffer.
609 This variable is only used when not using a threaded display."
610   :group 'gnus-summary-sort
611   :type '(repeat (choice (function-item gnus-article-sort-by-number)
612                          (function-item gnus-article-sort-by-author)
613                          (function-item gnus-article-sort-by-subject)
614                          (function-item gnus-article-sort-by-date)
615                          (function-item gnus-article-sort-by-score)
616                          (function :tag "other"))))
617
618 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
619   "*List of functions used for sorting threads in the summary buffer.
620 By default, threads are sorted by article number.
621
622 Each function takes two threads and return non-nil if the first thread
623 should be sorted before the other.  If you use more than one function,
624 the primary sort function should be the last.  You should probably
625 always include `gnus-thread-sort-by-number' in the list of sorting
626 functions -- preferably first.
627
628 Ready-made functions include `gnus-thread-sort-by-number',
629 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
630 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
631 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function')."
632   :group 'gnus-summary-sort
633   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
634                          (function-item gnus-thread-sort-by-author)
635                          (function-item gnus-thread-sort-by-subject)
636                          (function-item gnus-thread-sort-by-date)
637                          (function-item gnus-thread-sort-by-score)
638                          (function-item gnus-thread-sort-by-total-score)
639                          (function :tag "other"))))
640
641 (defcustom gnus-thread-score-function '+
642   "*Function used for calculating the total score of a thread.
643
644 The function is called with the scores of the article and each
645 subthread and should then return the score of the thread.
646
647 Some functions you can use are `+', `max', or `min'."
648   :group 'gnus-summary-sort
649   :type 'function)
650
651 (defcustom gnus-summary-expunge-below nil
652   "All articles that have a score less than this variable will be expunged.
653 This variable is local to the summary buffers."
654   :group 'gnus-score-default
655   :type '(choice (const :tag "off" nil)
656                  integer))
657
658 (defcustom gnus-thread-expunge-below nil
659   "All threads that have a total score less than this variable will be expunged.
660 See `gnus-thread-score-function' for en explanation of what a
661 \"thread score\" is.
662
663 This variable is local to the summary buffers."
664   :group 'gnus-threading
665   :group 'gnus-score-default
666   :type '(choice (const :tag "off" nil)
667                  integer))
668
669 (defcustom gnus-summary-mode-hook nil
670   "*A hook for Gnus summary mode.
671 This hook is run before any variables are set in the summary buffer."
672   :options '(turn-on-gnus-mailing-list-mode)
673   :group 'gnus-summary-various
674   :type 'hook)
675
676 (defcustom gnus-summary-menu-hook nil
677   "*Hook run after the creation of the summary mode menu."
678   :group 'gnus-summary-visual
679   :type 'hook)
680
681 (defcustom gnus-summary-exit-hook nil
682   "*A hook called on exit from the summary buffer.
683 It will be called with point in the group buffer."
684   :group 'gnus-summary-exit
685   :type 'hook)
686
687 (defcustom gnus-summary-prepare-hook nil
688   "*A hook called after the summary buffer has been generated.
689 If you want to modify the summary buffer, you can use this hook."
690   :group 'gnus-summary-various
691   :type 'hook)
692
693 (defcustom gnus-summary-prepared-hook nil
694   "*A hook called as the last thing after the summary buffer has been generated."
695   :group 'gnus-summary-various
696   :type 'hook)
697
698 (defcustom gnus-summary-generate-hook nil
699   "*A hook run just before generating the summary buffer.
700 This hook is commonly used to customize threading variables and the
701 like."
702   :group 'gnus-summary-various
703   :type 'hook)
704
705 (defcustom gnus-select-group-hook nil
706   "*A hook called when a newsgroup is selected.
707
708 If you'd like to simplify subjects like the
709 `gnus-summary-next-same-subject' command does, you can use the
710 following hook:
711
712  (setq gnus-select-group-hook
713       (list
714         (lambda ()
715           (mapcar (lambda (header)
716                      (mail-header-set-subject
717                       header
718                       (gnus-simplify-subject
719                        (mail-header-subject header) 're-only)))
720                   gnus-newsgroup-headers))))"
721   :group 'gnus-group-select
722   :type 'hook)
723
724 (defcustom gnus-select-article-hook nil
725   "*A hook called when an article is selected."
726   :group 'gnus-summary-choose
727   :type 'hook)
728
729 (defcustom gnus-visual-mark-article-hook
730   (list 'gnus-highlight-selected-summary)
731   "*Hook run after selecting an article in the summary buffer.
732 It is meant to be used for highlighting the article in some way.  It
733 is not run if `gnus-visual' is nil."
734   :group 'gnus-summary-visual
735   :type 'hook)
736
737 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
738   "*A hook called before parsing the headers."
739   :group 'gnus-various
740   :type 'hook)
741
742 (defcustom gnus-exit-group-hook nil
743   "*A hook called when exiting summary mode.
744 This hook is not called from the non-updating exit commands like `Q'."
745   :group 'gnus-various
746   :type 'hook)
747
748 (defcustom gnus-summary-update-hook
749   (list 'gnus-summary-highlight-line)
750   "*A hook called when a summary line is changed.
751 The hook will not be called if `gnus-visual' is nil.
752
753 The default function `gnus-summary-highlight-line' will
754 highlight the line according to the `gnus-summary-highlight'
755 variable."
756   :group 'gnus-summary-visual
757   :type 'hook)
758
759 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
760   "*A hook called when an article is selected for the first time.
761 The hook is intended to mark an article as read (or unread)
762 automatically when it is selected."
763   :group 'gnus-summary-choose
764   :type 'hook)
765
766 (defcustom gnus-group-no-more-groups-hook nil
767   "*A hook run when returning to group mode having no more (unread) groups."
768   :group 'gnus-group-select
769   :type 'hook)
770
771 (defcustom gnus-ps-print-hook nil
772   "*A hook run before ps-printing something from Gnus."
773   :group 'gnus-summary
774   :type 'hook)
775
776 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
777   "Face used for highlighting the current article in the summary buffer."
778   :group 'gnus-summary-visual
779   :type 'face)
780
781 (defcustom gnus-summary-highlight
782   '(((= mark gnus-canceled-mark)
783      . gnus-summary-cancelled-face)
784     ((and (> score default)
785           (or (= mark gnus-dormant-mark)
786               (= mark gnus-ticked-mark)))
787      . gnus-summary-high-ticked-face)
788     ((and (< score default)
789           (or (= mark gnus-dormant-mark)
790               (= mark gnus-ticked-mark)))
791      . gnus-summary-low-ticked-face)
792     ((or (= mark gnus-dormant-mark)
793          (= mark gnus-ticked-mark))
794      . gnus-summary-normal-ticked-face)
795     ((and (> score default) (= mark gnus-ancient-mark))
796      . gnus-summary-high-ancient-face)
797     ((and (< score default) (= mark gnus-ancient-mark))
798      . gnus-summary-low-ancient-face)
799     ((= mark gnus-ancient-mark)
800      . gnus-summary-normal-ancient-face)
801     ((and (> score default) (= mark gnus-unread-mark))
802      . gnus-summary-high-unread-face)
803     ((and (< score default) (= mark gnus-unread-mark))
804      . gnus-summary-low-unread-face)
805     ((and (memq article gnus-newsgroup-incorporated)
806           (= mark gnus-unread-mark))
807      . gnus-summary-incorporated-face)
808     ((= mark gnus-unread-mark)
809      . gnus-summary-normal-unread-face)
810     ((and (> score default) (memq mark (list gnus-downloadable-mark
811                                              gnus-undownloaded-mark)))
812      . gnus-summary-high-unread-face)
813     ((and (< score default) (memq mark (list gnus-downloadable-mark
814                                              gnus-undownloaded-mark)))
815      . gnus-summary-low-unread-face)
816     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
817      . gnus-summary-normal-unread-face)
818     ((> score default)
819      . gnus-summary-high-read-face)
820     ((< score default)
821      . gnus-summary-low-read-face)
822     (t
823      . gnus-summary-normal-read-face))
824   "*Controls the highlighting of summary buffer lines.
825
826 A list of (FORM . FACE) pairs.  When deciding how a a particular
827 summary line should be displayed, each form is evaluated.  The content
828 of the face field after the first true form is used.  You can change
829 how those summary lines are displayed, by editing the face field.
830
831 You can use the following variables in the FORM field.
832
833 score:   The articles score
834 default: The default article score.
835 below:   The score below which articles are automatically marked as read.
836 mark:    The articles mark."
837   :group 'gnus-summary-visual
838   :type '(repeat (cons (sexp :tag "Form" nil)
839                        face)))
840
841 (defcustom gnus-alter-header-function nil
842   "Function called to allow alteration of article header structures.
843 The function is called with one parameter, the article header vector,
844 which it may alter in any way.")
845
846 (defvar gnus-decode-encoded-word-function
847   (mime-find-field-decoder 'From 'nov)
848   "Variable that says which function should be used to decode a string with encoded words.")
849
850 (defcustom gnus-extra-headers nil
851   "*Extra headers to parse."
852   :version "21.1"
853   :group 'gnus-summary
854   :type '(repeat symbol))
855
856 (defcustom gnus-ignored-from-addresses
857   (and user-mail-address (regexp-quote user-mail-address))
858   "*Regexp of From headers that may be suppressed in favor of To headers."
859   :version "21.1"
860   :group 'gnus-summary
861   :type 'regexp)
862
863 (defcustom gnus-group-charset-alist
864   '(("^hk\\>\\|^tw\\>\\|\\<big5\\>" cn-big5)
865     ("^cn\\>\\|\\<chinese\\>" cn-gb-2312)
866     ("^fj\\>\\|^japan\\>" iso-2022-jp-2)
867     ("^tnn\\>\\|^pin\\>\\|^sci.lang.japan" iso-2022-7bit)
868     ("^relcom\\>" koi8-r)
869     ("^fido7\\>" koi8-r)
870     ("^\\(cz\\|hun\\|pl\\|sk\\|hr\\)\\>" iso-8859-2)
871     ("^israel\\>" iso-8859-1)
872     ("^han\\>" euc-kr)
873     ("^alt.chinese.text.big5\\>" chinese-big5)
874     ("^soc.culture.vietnamese\\>" vietnamese-viqr)
875     ("^\\(comp\\|rec\\|alt\\|sci\\|soc\\|news\\|gnu\\|bofh\\)\\>" iso-8859-1)
876     (".*" iso-8859-1))
877   "Alist of regexps (to match group names) and default charsets to be used when reading."
878   :type '(repeat (list (regexp :tag "Group")
879                        (symbol :tag "Charset")))
880   :group 'gnus-charset)
881
882 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
883   "List of charsets that should be ignored.
884 When these charsets are used in the \"charset\" parameter, the
885 default charset will be used instead."
886   :version "21.1"
887   :type '(repeat symbol)
888   :group 'gnus-charset)
889
890 (defcustom gnus-group-ignored-charsets-alist
891   '(("alt\\.chinese\\.text" iso-8859-1))
892   "Alist of regexps (to match group names) and charsets that should be ignored.
893 When these charsets are used in the \"charset\" parameter, the
894 default charset will be used instead."
895   :type '(repeat (cons (regexp :tag "Group")
896                        (repeat symbol)))
897   :group 'gnus-charset)
898
899 (defcustom gnus-group-highlight-words-alist nil
900   "Alist of group regexps and highlight regexps.
901 This variable uses the same syntax as `gnus-emphasis-alist'."
902   :version "21.1"
903   :type '(repeat (cons (regexp :tag "Group")
904                        (repeat (list (regexp :tag "Highlight regexp")
905                                      (number :tag "Group for entire word" 0)
906                                      (number :tag "Group for displayed part" 0)
907                                      (symbol :tag "Face"
908                                              gnus-emphasis-highlight-words)))))
909   :group 'gnus-summary-visual)
910
911 (defcustom gnus-use-wheel nil
912   "Use Intelli-mouse on summary movement"
913   :type 'boolean
914   :group 'gnus-summary-maneuvering)
915
916 (defcustom gnus-wheel-scroll-amount '(5 . 1)
917   "Amount to scroll messages by spinning the mouse wheel.
918 This is actually a cons cell, where the first item is the amount to scroll
919 on a normal wheel event, and the second is the amount to scroll when the
920 wheel is moved with the shift key depressed."
921   :type '(cons (integer :tag "Shift") integer)
922   :group 'gnus-summary-maneuvering)
923
924 (defcustom gnus-wheel-edge-resistance 2
925   "How hard it should be to change the current article
926 by moving the mouse over the edge of the article window."
927   :type 'integer
928   :group 'gnus-summary-maneuvering)
929
930 (defcustom gnus-summary-show-article-charset-alist
931   nil
932   "Alist of number and charset.
933 The article will be shown with the charset corresponding to the
934 numbered argument.
935 For example: ((1 . cn-gb-2312) (2 . big5))."
936   :version "21.1"
937   :type '(repeat (cons (number :tag "Argument" 1)
938                        (symbol :tag "Charset")))
939   :group 'gnus-charset)
940
941 (defcustom gnus-preserve-marks t
942   "Whether marks are preserved when moving, copying and respooling messages."
943   :version "21.1"
944   :type 'boolean
945   :group 'gnus-summary-marks)
946
947 (defcustom gnus-alter-articles-to-read-function nil
948   "Function to be called to alter the list of articles to be selected."
949   :type 'function
950   :group 'gnus-summary)
951
952 (defcustom gnus-orphan-score nil
953   "*All orphans get this score added.  Set in the score file."
954   :group 'gnus-score-default
955   :type '(choice (const nil)
956                  integer))
957
958 (defcustom gnus-summary-save-parts-default-mime "image/.*"
959   "*A regexp to match MIME parts when saving multiple parts of a message
960 with gnus-summary-save-parts (X m). This regexp will be used by default
961 when prompting the user for which type of files to save."
962   :group 'gnus-summary
963   :type 'regexp)
964
965
966 (defcustom gnus-summary-save-parts-default-mime "image/.*"
967   "*A regexp to match MIME parts when saving multiple parts of a message
968 with gnus-summary-save-parts (X m). This regexp will be used by default
969 when prompting the user for which type of files to save."
970   :group 'gnus-summary
971   :type 'regexp)
972
973
974 ;;; Internal variables
975
976 (defvar gnus-article-mime-handles nil)
977 (defvar gnus-article-decoded-p nil)
978 (defvar gnus-article-charset nil)
979 (defvar gnus-article-ignored-charsets nil)
980 (defvar gnus-scores-exclude-files nil)
981 (defvar gnus-page-broken nil)
982 (defvar gnus-inhibit-mime-unbuttonizing nil)
983
984 (defvar gnus-original-article nil)
985 (defvar gnus-article-internal-prepare-hook nil)
986 (defvar gnus-newsgroup-process-stack nil)
987
988 (defvar gnus-thread-indent-array nil)
989 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
990 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
991   "Function called to sort the articles within a thread after it has been gathered together.")
992
993 (defvar gnus-summary-save-parts-type-history nil)
994 (defvar gnus-summary-save-parts-last-directory nil)
995
996 (defvar gnus-summary-save-parts-type-history nil)
997 (defvar gnus-summary-save-parts-last-directory nil)
998
999 ;; Avoid highlighting in kill files.
1000 (defvar gnus-summary-inhibit-highlight nil)
1001 (defvar gnus-newsgroup-selected-overlay nil)
1002 (defvar gnus-inhibit-limiting nil)
1003 (defvar gnus-newsgroup-adaptive-score-file nil)
1004 (defvar gnus-current-score-file nil)
1005 (defvar gnus-current-move-group nil)
1006 (defvar gnus-current-copy-group nil)
1007 (defvar gnus-current-crosspost-group nil)
1008
1009 (defvar gnus-newsgroup-dependencies nil)
1010 (defvar gnus-newsgroup-adaptive nil)
1011 (defvar gnus-summary-display-article-function nil)
1012 (defvar gnus-summary-highlight-line-function nil
1013   "Function called after highlighting a summary line.")
1014
1015 (defvar gnus-summary-line-format-alist
1016   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1017     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1018     (?s gnus-tmp-subject-or-nil ?s)
1019     (?n gnus-tmp-name ?s)
1020     (?A (std11-address-string
1021          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1022     (?a (or (std11-full-name-string
1023              (car (mime-entity-read-field gnus-tmp-header 'From)))
1024             gnus-tmp-from) ?s)
1025     (?F gnus-tmp-from ?s)
1026     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1027     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1028     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1029     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1030     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1031     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1032     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1033     (?L gnus-tmp-lines ?d)
1034     (?I gnus-tmp-indentation ?s)
1035     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1036     (?R gnus-tmp-replied ?c)
1037     (?\[ gnus-tmp-opening-bracket ?c)
1038     (?\] gnus-tmp-closing-bracket ?c)
1039     (?\> (make-string gnus-tmp-level ? ) ?s)
1040     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1041     (?i gnus-tmp-score ?d)
1042     (?z gnus-tmp-score-char ?c)
1043     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1044     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1045     (?U gnus-tmp-unread ?c)
1046     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
1047     (?t (gnus-summary-number-of-articles-in-thread
1048          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1049         ?d)
1050     (?e (gnus-summary-number-of-articles-in-thread
1051          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1052         ?c)
1053     (?u gnus-tmp-user-defined ?s)
1054     (?P (gnus-pick-line-number) ?d))
1055   "An alist of format specifications that can appear in summary lines.
1056 These are paired with what variables they correspond with, along with
1057 the type of the variable (string, integer, character, etc).")
1058
1059 (defvar gnus-summary-dummy-line-format-alist
1060   `((?S gnus-tmp-subject ?s)
1061     (?N gnus-tmp-number ?d)
1062     (?u gnus-tmp-user-defined ?s)))
1063
1064 (defvar gnus-summary-mode-line-format-alist
1065   `((?G gnus-tmp-group-name ?s)
1066     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1067     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1068     (?A gnus-tmp-article-number ?d)
1069     (?Z gnus-tmp-unread-and-unselected ?s)
1070     (?V gnus-version ?s)
1071     (?U gnus-tmp-unread-and-unticked ?d)
1072     (?S gnus-tmp-subject ?s)
1073     (?e gnus-tmp-unselected ?d)
1074     (?u gnus-tmp-user-defined ?s)
1075     (?d (length gnus-newsgroup-dormant) ?d)
1076     (?t (length gnus-newsgroup-marked) ?d)
1077     (?r (length gnus-newsgroup-reads) ?d)
1078     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1079     (?E gnus-newsgroup-expunged-tally ?d)
1080     (?s (gnus-current-score-file-nondirectory) ?s)))
1081
1082 (defvar gnus-last-search-regexp nil
1083   "Default regexp for article search command.")
1084
1085 (defvar gnus-summary-search-article-matched-data nil
1086   "Last matched data of article search command.  It is the local variable
1087 in `gnus-article-buffer' which consists of the list of start position,
1088 end position and text.")
1089
1090 (defvar gnus-last-shell-command nil
1091   "Default shell command on article.")
1092
1093 (defvar gnus-newsgroup-begin nil)
1094 (defvar gnus-newsgroup-end nil)
1095 (defvar gnus-newsgroup-last-rmail nil)
1096 (defvar gnus-newsgroup-last-mail nil)
1097 (defvar gnus-newsgroup-last-folder nil)
1098 (defvar gnus-newsgroup-last-file nil)
1099 (defvar gnus-newsgroup-auto-expire nil)
1100 (defvar gnus-newsgroup-active nil)
1101
1102 (defvar gnus-newsgroup-data nil)
1103 (defvar gnus-newsgroup-data-reverse nil)
1104 (defvar gnus-newsgroup-limit nil)
1105 (defvar gnus-newsgroup-limits nil)
1106
1107 (defvar gnus-newsgroup-unreads nil
1108   "List of unread articles in the current newsgroup.")
1109
1110 (defvar gnus-newsgroup-unselected nil
1111   "List of unselected unread articles in the current newsgroup.")
1112
1113 (defvar gnus-newsgroup-reads nil
1114   "Alist of read articles and article marks in the current newsgroup.")
1115
1116 (defvar gnus-newsgroup-expunged-tally nil)
1117
1118 (defvar gnus-newsgroup-marked nil
1119   "List of ticked articles in the current newsgroup (a subset of unread art).")
1120
1121 (defvar gnus-newsgroup-killed nil
1122   "List of ranges of articles that have been through the scoring process.")
1123
1124 (defvar gnus-newsgroup-cached nil
1125   "List of articles that come from the article cache.")
1126
1127 (defvar gnus-newsgroup-saved nil
1128   "List of articles that have been saved.")
1129
1130 (defvar gnus-newsgroup-kill-headers nil)
1131
1132 (defvar gnus-newsgroup-replied nil
1133   "List of articles that have been replied to in the current newsgroup.")
1134
1135 (defvar gnus-newsgroup-expirable nil
1136   "List of articles in the current newsgroup that can be expired.")
1137
1138 (defvar gnus-newsgroup-processable nil
1139   "List of articles in the current newsgroup that can be processed.")
1140
1141 (defvar gnus-newsgroup-downloadable nil
1142   "List of articles in the current newsgroup that can be processed.")
1143
1144 (defvar gnus-newsgroup-undownloaded nil
1145   "List of articles in the current newsgroup that haven't been downloaded..")
1146
1147 (defvar gnus-newsgroup-unsendable nil
1148   "List of articles in the current newsgroup that won't be sent.")
1149
1150 (defvar gnus-newsgroup-bookmarks nil
1151   "List of articles in the current newsgroup that have bookmarks.")
1152
1153 (defvar gnus-newsgroup-dormant nil
1154   "List of dormant articles in the current newsgroup.")
1155
1156 (defvar gnus-newsgroup-scored nil
1157   "List of scored articles in the current newsgroup.")
1158
1159 (defvar gnus-newsgroup-incorporated nil
1160   "List of incorporated articles in the current newsgroup.")
1161
1162 (defvar gnus-newsgroup-headers nil
1163   "List of article headers in the current newsgroup.")
1164
1165 (defvar gnus-newsgroup-threads nil)
1166
1167 (defvar gnus-newsgroup-prepared nil
1168   "Whether the current group has been prepared properly.")
1169
1170 (defvar gnus-newsgroup-ancient nil
1171   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1172
1173 (defvar gnus-newsgroup-sparse nil)
1174
1175 (defvar gnus-current-article nil)
1176 (defvar gnus-article-current nil)
1177 (defvar gnus-current-headers nil)
1178 (defvar gnus-have-all-headers nil)
1179 (defvar gnus-last-article nil)
1180 (defvar gnus-newsgroup-history nil)
1181 (defvar gnus-newsgroup-charset nil)
1182 (defvar gnus-newsgroup-ephemeral-charset nil)
1183 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1184
1185 (defvar gnus-article-before-search nil)
1186
1187 (defconst gnus-summary-local-variables
1188   '(gnus-newsgroup-name
1189     gnus-newsgroup-begin gnus-newsgroup-end
1190     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1191     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1192     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1193     gnus-newsgroup-unselected gnus-newsgroup-marked
1194     gnus-newsgroup-reads gnus-newsgroup-saved
1195     gnus-newsgroup-replied gnus-newsgroup-expirable
1196     gnus-newsgroup-processable gnus-newsgroup-killed
1197     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1198     gnus-newsgroup-unsendable
1199     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1200     gnus-newsgroup-headers gnus-newsgroup-threads
1201     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1202     gnus-current-article gnus-current-headers gnus-have-all-headers
1203     gnus-last-article gnus-article-internal-prepare-hook
1204     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1205     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1206     gnus-thread-expunge-below
1207     gnus-score-alist gnus-current-score-file
1208     (gnus-summary-expunge-below . global)
1209     (gnus-summary-mark-below . global)
1210     (gnus-orphan-score . global)
1211     gnus-newsgroup-active gnus-scores-exclude-files
1212     gnus-newsgroup-history gnus-newsgroup-ancient
1213     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1214     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1215     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1216     (gnus-newsgroup-expunged-tally . 0)
1217     gnus-cache-removable-articles gnus-newsgroup-cached
1218     gnus-newsgroup-data gnus-newsgroup-data-reverse
1219     gnus-newsgroup-limit gnus-newsgroup-limits
1220     gnus-newsgroup-charset
1221     gnus-newsgroup-incorporated)
1222   "Variables that are buffer-local to the summary buffers.")
1223
1224 (defvar gnus-newsgroup-variables nil
1225   "Variables that have separate values in the newsgroups.")
1226
1227 ;; Byte-compiler warning.
1228 (eval-when-compile (defvar gnus-article-mode-map))
1229
1230 ;; Subject simplification.
1231
1232 (defun gnus-simplify-whitespace (str)
1233   "Remove excessive whitespace from STR."
1234   (let ((mystr str))
1235     ;; Multiple spaces.
1236     (while (string-match "[ \t][ \t]+" mystr)
1237       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1238                           " "
1239                           (substring mystr (match-end 0)))))
1240     ;; Leading spaces.
1241     (when (string-match "^[ \t]+" mystr)
1242       (setq mystr (substring mystr (match-end 0))))
1243     ;; Trailing spaces.
1244     (when (string-match "[ \t]+$" mystr)
1245       (setq mystr (substring mystr 0 (match-beginning 0))))
1246     mystr))
1247
1248 (defsubst gnus-simplify-subject-re (subject)
1249   "Remove \"Re:\" from subject lines."
1250   (if (string-match "^[Rr][Ee]: *" subject)
1251       (substring subject (match-end 0))
1252     subject))
1253
1254 (defun gnus-simplify-subject (subject &optional re-only)
1255   "Remove `Re:' and words in parentheses.
1256 If RE-ONLY is non-nil, strip leading `Re:'s only."
1257   (let ((case-fold-search t))           ;Ignore case.
1258     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1259     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1260       (setq subject (substring subject (match-end 0))))
1261     ;; Remove uninteresting prefixes.
1262     (when (and (not re-only)
1263                gnus-simplify-ignored-prefixes
1264                (string-match gnus-simplify-ignored-prefixes subject))
1265       (setq subject (substring subject (match-end 0))))
1266     ;; Remove words in parentheses from end.
1267     (unless re-only
1268       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1269         (setq subject (substring subject 0 (match-beginning 0)))))
1270     ;; Return subject string.
1271     subject))
1272
1273 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1274 ;; all whitespace.
1275 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1276   (goto-char (point-min))
1277   (while (re-search-forward regexp nil t)
1278     (replace-match (or newtext ""))))
1279
1280 (defun gnus-simplify-buffer-fuzzy ()
1281   "Simplify string in the buffer fuzzily.
1282 The string in the accessible portion of the current buffer is simplified.
1283 It is assumed to be a single-line subject.
1284 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1285 matter is removed.  Additional things can be deleted by setting
1286 `gnus-simplify-subject-fuzzy-regexp'."
1287   (let ((case-fold-search t)
1288         (modified-tick))
1289     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1290
1291     (while (not (eq modified-tick (buffer-modified-tick)))
1292       (setq modified-tick (buffer-modified-tick))
1293       (cond
1294        ((listp gnus-simplify-subject-fuzzy-regexp)
1295         (mapcar 'gnus-simplify-buffer-fuzzy-step
1296                 gnus-simplify-subject-fuzzy-regexp))
1297        (gnus-simplify-subject-fuzzy-regexp
1298         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1299       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1300       (gnus-simplify-buffer-fuzzy-step
1301        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1302       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1303
1304     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1305     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1306     (gnus-simplify-buffer-fuzzy-step " $")
1307     (gnus-simplify-buffer-fuzzy-step "^ +")))
1308
1309 (defun gnus-simplify-subject-fuzzy (subject)
1310   "Simplify a subject string fuzzily.
1311 See `gnus-simplify-buffer-fuzzy' for details."
1312   (save-excursion
1313     (gnus-set-work-buffer)
1314     (let ((case-fold-search t))
1315       ;; Remove uninteresting prefixes.
1316       (when (and gnus-simplify-ignored-prefixes
1317                  (string-match gnus-simplify-ignored-prefixes subject))
1318         (setq subject (substring subject (match-end 0))))
1319       (insert subject)
1320       (inline (gnus-simplify-buffer-fuzzy))
1321       (buffer-string))))
1322
1323 (defsubst gnus-simplify-subject-fully (subject)
1324   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1325   (cond
1326    (gnus-simplify-subject-functions
1327     (gnus-map-function gnus-simplify-subject-functions subject))
1328    ((null gnus-summary-gather-subject-limit)
1329     (gnus-simplify-subject-re subject))
1330    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1331     (gnus-simplify-subject-fuzzy subject))
1332    ((numberp gnus-summary-gather-subject-limit)
1333     (gnus-limit-string (gnus-simplify-subject-re subject)
1334                        gnus-summary-gather-subject-limit))
1335    (t
1336     subject)))
1337
1338 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1339   "Check whether two subjects are equal.
1340 If optional argument simple-first is t, first argument is already
1341 simplified."
1342   (cond
1343    ((null simple-first)
1344     (equal (gnus-simplify-subject-fully s1)
1345            (gnus-simplify-subject-fully s2)))
1346    (t
1347     (equal s1
1348            (gnus-simplify-subject-fully s2)))))
1349
1350 (defun gnus-summary-bubble-group ()
1351   "Increase the score of the current group.
1352 This is a handy function to add to `gnus-summary-exit-hook' to
1353 increase the score of each group you read."
1354   (gnus-group-add-score gnus-newsgroup-name))
1355
1356 \f
1357 ;;;
1358 ;;; Gnus summary mode
1359 ;;;
1360
1361 (put 'gnus-summary-mode 'mode-class 'special)
1362
1363 (when t
1364   ;; Non-orthogonal keys
1365
1366   (gnus-define-keys gnus-summary-mode-map
1367     " " gnus-summary-next-page
1368     "\177" gnus-summary-prev-page
1369     [delete] gnus-summary-prev-page
1370     [backspace] gnus-summary-prev-page
1371     "\r" gnus-summary-scroll-up
1372     "\M-\r" gnus-summary-scroll-down
1373     "n" gnus-summary-next-unread-article
1374     "p" gnus-summary-prev-unread-article
1375     "N" gnus-summary-next-article
1376     "P" gnus-summary-prev-article
1377     "\M-\C-n" gnus-summary-next-same-subject
1378     "\M-\C-p" gnus-summary-prev-same-subject
1379     "\M-n" gnus-summary-next-unread-subject
1380     "\M-p" gnus-summary-prev-unread-subject
1381     "." gnus-summary-first-unread-article
1382     "," gnus-summary-best-unread-article
1383     "\M-s" gnus-summary-search-article-forward
1384     "\M-r" gnus-summary-search-article-backward
1385     "<" gnus-summary-beginning-of-article
1386     ">" gnus-summary-end-of-article
1387     "j" gnus-summary-goto-article
1388     "^" gnus-summary-refer-parent-article
1389     "\M-^" gnus-summary-refer-article
1390     "u" gnus-summary-tick-article-forward
1391     "!" gnus-summary-tick-article-forward
1392     "U" gnus-summary-tick-article-backward
1393     "d" gnus-summary-mark-as-read-forward
1394     "D" gnus-summary-mark-as-read-backward
1395     "E" gnus-summary-mark-as-expirable
1396     "\M-u" gnus-summary-clear-mark-forward
1397     "\M-U" gnus-summary-clear-mark-backward
1398     "k" gnus-summary-kill-same-subject-and-select
1399     "\C-k" gnus-summary-kill-same-subject
1400     "\M-\C-k" gnus-summary-kill-thread
1401     "\M-\C-l" gnus-summary-lower-thread
1402     "e" gnus-summary-edit-article
1403     "#" gnus-summary-mark-as-processable
1404     "\M-#" gnus-summary-unmark-as-processable
1405     "\M-\C-t" gnus-summary-toggle-threads
1406     "\M-\C-s" gnus-summary-show-thread
1407     "\M-\C-h" gnus-summary-hide-thread
1408     "\M-\C-f" gnus-summary-next-thread
1409     "\M-\C-b" gnus-summary-prev-thread
1410     [(meta down)] gnus-summary-next-thread
1411     [(meta up)] gnus-summary-prev-thread
1412     "\M-\C-u" gnus-summary-up-thread
1413     "\M-\C-d" gnus-summary-down-thread
1414     "&" gnus-summary-execute-command
1415     "c" gnus-summary-catchup-and-exit
1416     "\C-w" gnus-summary-mark-region-as-read
1417     "\C-t" gnus-summary-toggle-truncation
1418     "?" gnus-summary-mark-as-dormant
1419     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1420     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1421     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1422     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1423     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1424     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1425     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1426     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1427     "=" gnus-summary-expand-window
1428     "\C-x\C-s" gnus-summary-reselect-current-group
1429     "\M-g" gnus-summary-rescan-group
1430     "w" gnus-summary-stop-page-breaking
1431     "\C-c\C-r" gnus-summary-caesar-message
1432     "\M-t" gnus-summary-toggle-mime
1433     "f" gnus-summary-followup
1434     "F" gnus-summary-followup-with-original
1435     "C" gnus-summary-cancel-article
1436     "r" gnus-summary-reply
1437     "R" gnus-summary-reply-with-original
1438     "\C-c\C-f" gnus-summary-mail-forward
1439     "o" gnus-summary-save-article
1440     "\C-o" gnus-summary-save-article-mail
1441     "|" gnus-summary-pipe-output
1442     "\M-k" gnus-summary-edit-local-kill
1443     "\M-K" gnus-summary-edit-global-kill
1444     ;; "V" gnus-version
1445     "\C-c\C-d" gnus-summary-describe-group
1446     "q" gnus-summary-exit
1447     "Q" gnus-summary-exit-no-update
1448     "\C-c\C-i" gnus-info-find-node
1449     gnus-mouse-2 gnus-mouse-pick-article
1450     "m" gnus-summary-mail-other-window
1451     "a" gnus-summary-post-news
1452     "x" gnus-summary-limit-to-unread
1453     "s" gnus-summary-isearch-article
1454     "t" gnus-article-toggle-headers
1455     "g" gnus-summary-show-article
1456     "l" gnus-summary-goto-last-article
1457     "v" gnus-summary-preview-mime-message
1458     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1459     "\C-d" gnus-summary-enter-digest-group
1460     "\M-\C-d" gnus-summary-read-document
1461     "\M-\C-e" gnus-summary-edit-parameters
1462     "\M-\C-a" gnus-summary-customize-parameters
1463     "\C-c\C-b" gnus-bug
1464     "*" gnus-cache-enter-article
1465     "\M-*" gnus-cache-remove-article
1466     "\M-&" gnus-summary-universal-argument
1467     "\C-l" gnus-recenter
1468     "I" gnus-summary-increase-score
1469     "L" gnus-summary-lower-score
1470     "\M-i" gnus-symbolic-argument
1471     "h" gnus-summary-select-article-buffer
1472
1473     "V" gnus-summary-score-map
1474     "X" gnus-uu-extract-map
1475     "S" gnus-summary-send-map)
1476
1477   ;; Sort of orthogonal keymap
1478   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1479     "t" gnus-summary-tick-article-forward
1480     "!" gnus-summary-tick-article-forward
1481     "d" gnus-summary-mark-as-read-forward
1482     "r" gnus-summary-mark-as-read-forward
1483     "c" gnus-summary-clear-mark-forward
1484     " " gnus-summary-clear-mark-forward
1485     "e" gnus-summary-mark-as-expirable
1486     "x" gnus-summary-mark-as-expirable
1487     "?" gnus-summary-mark-as-dormant
1488     "b" gnus-summary-set-bookmark
1489     "B" gnus-summary-remove-bookmark
1490     "#" gnus-summary-mark-as-processable
1491     "\M-#" gnus-summary-unmark-as-processable
1492     "S" gnus-summary-limit-include-expunged
1493     "C" gnus-summary-catchup
1494     "H" gnus-summary-catchup-to-here
1495     "\C-c" gnus-summary-catchup-all
1496     "k" gnus-summary-kill-same-subject-and-select
1497     "K" gnus-summary-kill-same-subject
1498     "P" gnus-uu-mark-map)
1499
1500   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1501     "c" gnus-summary-clear-above
1502     "u" gnus-summary-tick-above
1503     "m" gnus-summary-mark-above
1504     "k" gnus-summary-kill-below)
1505
1506   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1507     "/" gnus-summary-limit-to-subject
1508     "n" gnus-summary-limit-to-articles
1509     "w" gnus-summary-pop-limit
1510     "s" gnus-summary-limit-to-subject
1511     "a" gnus-summary-limit-to-author
1512     "u" gnus-summary-limit-to-unread
1513     "m" gnus-summary-limit-to-marks
1514     "M" gnus-summary-limit-exclude-marks
1515     "v" gnus-summary-limit-to-score
1516     "*" gnus-summary-limit-include-cached
1517     "D" gnus-summary-limit-include-dormant
1518     "T" gnus-summary-limit-include-thread
1519     "d" gnus-summary-limit-exclude-dormant
1520     "t" gnus-summary-limit-to-age
1521     "x" gnus-summary-limit-to-extra
1522     "E" gnus-summary-limit-include-expunged
1523     "c" gnus-summary-limit-exclude-childless-dormant
1524     "C" gnus-summary-limit-mark-excluded-as-read)
1525
1526   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1527     "n" gnus-summary-next-unread-article
1528     "p" gnus-summary-prev-unread-article
1529     "N" gnus-summary-next-article
1530     "P" gnus-summary-prev-article
1531     "\C-n" gnus-summary-next-same-subject
1532     "\C-p" gnus-summary-prev-same-subject
1533     "\M-n" gnus-summary-next-unread-subject
1534     "\M-p" gnus-summary-prev-unread-subject
1535     "f" gnus-summary-first-unread-article
1536     "b" gnus-summary-best-unread-article
1537     "j" gnus-summary-goto-article
1538     "g" gnus-summary-goto-subject
1539     "l" gnus-summary-goto-last-article
1540     "o" gnus-summary-pop-article)
1541
1542   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1543     "k" gnus-summary-kill-thread
1544     "l" gnus-summary-lower-thread
1545     "i" gnus-summary-raise-thread
1546     "T" gnus-summary-toggle-threads
1547     "t" gnus-summary-rethread-current
1548     "^" gnus-summary-reparent-thread
1549     "s" gnus-summary-show-thread
1550     "S" gnus-summary-show-all-threads
1551     "h" gnus-summary-hide-thread
1552     "H" gnus-summary-hide-all-threads
1553     "n" gnus-summary-next-thread
1554     "p" gnus-summary-prev-thread
1555     "u" gnus-summary-up-thread
1556     "o" gnus-summary-top-thread
1557     "d" gnus-summary-down-thread
1558     "#" gnus-uu-mark-thread
1559     "\M-#" gnus-uu-unmark-thread)
1560
1561   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1562     "g" gnus-summary-prepare
1563     "c" gnus-summary-insert-cached-articles)
1564
1565   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1566     "c" gnus-summary-catchup-and-exit
1567     "C" gnus-summary-catchup-all-and-exit
1568     "E" gnus-summary-exit-no-update
1569     "J" gnus-summary-jump-to-other-group
1570     "Q" gnus-summary-exit
1571     "Z" gnus-summary-exit
1572     "n" gnus-summary-catchup-and-goto-next-group
1573     "R" gnus-summary-reselect-current-group
1574     "G" gnus-summary-rescan-group
1575     "N" gnus-summary-next-group
1576     "s" gnus-summary-save-newsrc
1577     "P" gnus-summary-prev-group)
1578
1579   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1580     " " gnus-summary-next-page
1581     "n" gnus-summary-next-page
1582     "\177" gnus-summary-prev-page
1583     [delete] gnus-summary-prev-page
1584     "p" gnus-summary-prev-page
1585     "\r" gnus-summary-scroll-up
1586     "\M-\r" gnus-summary-scroll-down
1587     "<" gnus-summary-beginning-of-article
1588     ">" gnus-summary-end-of-article
1589     "b" gnus-summary-beginning-of-article
1590     "e" gnus-summary-end-of-article
1591     "^" gnus-summary-refer-parent-article
1592     "r" gnus-summary-refer-parent-article
1593     "D" gnus-summary-enter-digest-group
1594     "R" gnus-summary-refer-references
1595     "T" gnus-summary-refer-thread
1596     "g" gnus-summary-show-article
1597     "s" gnus-summary-isearch-article
1598     "P" gnus-summary-print-article
1599     "M" gnus-mailing-list-insinuate
1600     "t" gnus-article-babel)
1601
1602   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1603     "b" gnus-article-add-buttons
1604     "B" gnus-article-add-buttons-to-head
1605     "o" gnus-article-treat-overstrike
1606     "e" gnus-article-emphasize
1607     "w" gnus-article-fill-cited-article
1608     "Q" gnus-article-fill-long-lines
1609     "C" gnus-article-capitalize-sentences
1610     "c" gnus-article-remove-cr
1611     "Z" gnus-article-decode-HZ
1612     "f" gnus-article-display-x-face
1613     "l" gnus-summary-stop-page-breaking
1614     "r" gnus-summary-caesar-message
1615     "t" gnus-article-toggle-headers
1616     "v" gnus-summary-verbose-headers
1617     "m" gnus-summary-toggle-mime
1618     "H" gnus-article-strip-headers-in-body
1619     "p" gnus-article-verify-x-pgp-sig
1620     "d" gnus-article-treat-dumbquotes
1621     "s" gnus-smiley-display)
1622
1623   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1624     "a" gnus-article-hide
1625     "h" gnus-article-toggle-headers
1626     "b" gnus-article-hide-boring-headers
1627     "s" gnus-article-hide-signature
1628     "c" gnus-article-hide-citation
1629     "C" gnus-article-hide-citation-in-followups
1630     "l" gnus-article-hide-list-identifiers
1631     "p" gnus-article-hide-pgp
1632     "B" gnus-article-strip-banner
1633     "P" gnus-article-hide-pem
1634     "\C-c" gnus-article-hide-citation-maybe)
1635
1636   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1637     "a" gnus-article-highlight
1638     "h" gnus-article-highlight-headers
1639     "c" gnus-article-highlight-citation
1640     "s" gnus-article-highlight-signature)
1641
1642   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1643     "z" gnus-article-date-ut
1644     "u" gnus-article-date-ut
1645     "l" gnus-article-date-local
1646     "e" gnus-article-date-lapsed
1647     "o" gnus-article-date-original
1648     "i" gnus-article-date-iso8601
1649     "s" gnus-article-date-user)
1650
1651   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1652     "t" gnus-article-remove-trailing-blank-lines
1653     "l" gnus-article-strip-leading-blank-lines
1654     "m" gnus-article-strip-multiple-blank-lines
1655     "a" gnus-article-strip-blank-lines
1656     "A" gnus-article-strip-all-blank-lines
1657     "s" gnus-article-strip-leading-space
1658     "e" gnus-article-strip-trailing-space)
1659
1660   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1661     "v" gnus-version
1662     "f" gnus-summary-fetch-faq
1663     "d" gnus-summary-describe-group
1664     "h" gnus-summary-describe-briefly
1665     "i" gnus-info-find-node)
1666
1667   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1668     "e" gnus-summary-expire-articles
1669     "\M-\C-e" gnus-summary-expire-articles-now
1670     "\177" gnus-summary-delete-article
1671     [delete] gnus-summary-delete-article
1672     [backspace] gnus-summary-delete-article
1673     "m" gnus-summary-move-article
1674     "r" gnus-summary-respool-article
1675     "w" gnus-summary-edit-article
1676     "c" gnus-summary-copy-article
1677     "B" gnus-summary-crosspost-article
1678     "q" gnus-summary-respool-query
1679     "t" gnus-summary-respool-trace
1680     "i" gnus-summary-import-article
1681     "p" gnus-summary-article-posted-p)
1682
1683   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1684     "o" gnus-summary-save-article
1685     "m" gnus-summary-save-article-mail
1686     "F" gnus-summary-write-article-file
1687     "r" gnus-summary-save-article-rmail
1688     "f" gnus-summary-save-article-file
1689     "b" gnus-summary-save-article-body-file
1690     "h" gnus-summary-save-article-folder
1691     "v" gnus-summary-save-article-vm
1692     "p" gnus-summary-pipe-output
1693     "s" gnus-soup-add-article)
1694
1695   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1696     "b" gnus-summary-display-buttonized
1697     "m" gnus-summary-repair-multipart
1698     "v" gnus-article-view-part
1699     "o" gnus-article-save-part
1700     "c" gnus-article-copy-part
1701     "C" gnus-article-view-part-as-charset
1702     "e" gnus-article-externalize-part
1703     "E" gnus-article-encrypt-body
1704     "i" gnus-article-inline-part
1705     "|" gnus-article-pipe-part))
1706
1707 (defun gnus-summary-make-menu-bar ()
1708   (gnus-turn-off-edit-menu 'summary)
1709
1710   (unless (boundp 'gnus-summary-misc-menu)
1711
1712     (easy-menu-define
1713      gnus-summary-kill-menu gnus-summary-mode-map ""
1714      (cons
1715       "Score"
1716       (nconc
1717        (list
1718         ["Enter score..." gnus-summary-score-entry t]
1719         ["Customize" gnus-score-customize t])
1720        (gnus-make-score-map 'increase)
1721        (gnus-make-score-map 'lower)
1722        '(("Mark"
1723           ["Kill below" gnus-summary-kill-below t]
1724           ["Mark above" gnus-summary-mark-above t]
1725           ["Tick above" gnus-summary-tick-above t]
1726           ["Clear above" gnus-summary-clear-above t])
1727          ["Current score" gnus-summary-current-score t]
1728          ["Set score" gnus-summary-set-score t]
1729          ["Switch current score file..." gnus-score-change-score-file t]
1730          ["Set mark below..." gnus-score-set-mark-below t]
1731          ["Set expunge below..." gnus-score-set-expunge-below t]
1732          ["Edit current score file" gnus-score-edit-current-scores t]
1733          ["Edit score file" gnus-score-edit-file t]
1734          ["Trace score" gnus-score-find-trace t]
1735          ["Find words" gnus-score-find-favourite-words t]
1736          ["Rescore buffer" gnus-summary-rescore t]
1737          ["Increase score..." gnus-summary-increase-score t]
1738          ["Lower score..." gnus-summary-lower-score t]))))
1739
1740     ;; Define both the Article menu in the summary buffer and the equivalent
1741     ;; Commands menu in the article buffer here for consistency.
1742     (let ((innards
1743            `(("Hide"
1744               ["All" gnus-article-hide t]
1745               ["Headers" gnus-article-toggle-headers t]
1746               ["Signature" gnus-article-hide-signature t]
1747               ["Citation" gnus-article-hide-citation t]
1748               ["List identifiers" gnus-article-hide-list-identifiers t]
1749               ["PGP" gnus-article-hide-pgp t]
1750               ["Banner" gnus-article-strip-banner t]
1751               ["Boring headers" gnus-article-hide-boring-headers t])
1752              ("Highlight"
1753               ["All" gnus-article-highlight t]
1754               ["Headers" gnus-article-highlight-headers t]
1755               ["Signature" gnus-article-highlight-signature t]
1756               ["Citation" gnus-article-highlight-citation t])
1757              ("Date"
1758               ["Local" gnus-article-date-local t]
1759               ["ISO8601" gnus-article-date-iso8601 t]
1760               ["UT" gnus-article-date-ut t]
1761               ["Original" gnus-article-date-original t]
1762               ["Lapsed" gnus-article-date-lapsed t]
1763               ["User-defined" gnus-article-date-user t])
1764              ("Washing"
1765               ("Remove Blanks"
1766                ["Leading" gnus-article-strip-leading-blank-lines t]
1767                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1768                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1769                ["All of the above" gnus-article-strip-blank-lines t]
1770                ["All" gnus-article-strip-all-blank-lines t]
1771                ["Leading space" gnus-article-strip-leading-space t]
1772                ["Trailing space" gnus-article-strip-trailing-space t])
1773               ["Overstrike" gnus-article-treat-overstrike t]
1774               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1775               ["Emphasis" gnus-article-emphasize t]
1776               ["Word wrap" gnus-article-fill-cited-article t]
1777               ["Fill long lines" gnus-article-fill-long-lines t]
1778               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1779               ["CR" gnus-article-remove-cr t]
1780               ["Show X-Face" gnus-article-display-x-face t]
1781               ["Rot 13" gnus-summary-caesar-message
1782                ,@(if (featurep 'xemacs) nil
1783                    '(:help "\"Caesar rotate\" article by 13"))]
1784               ["Unix pipe" gnus-summary-pipe-message t]
1785               ["Add buttons" gnus-article-add-buttons t]
1786               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1787               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1788               ["Toggle MIME" gnus-summary-toggle-mime t]
1789               ["Verbose header" gnus-summary-verbose-headers t]
1790               ["Toggle header" gnus-summary-toggle-header t]
1791               ["Toggle smileys" gnus-smiley-display t]
1792               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1793               ["HZ" gnus-article-decode-HZ t])
1794              ("Output"
1795               ["Save in default format" gnus-summary-save-article
1796                ,@(if (featurep 'xemacs) nil
1797                    '(:help "Save article using default method"))]
1798               ["Save in file" gnus-summary-save-article-file
1799                ,@(if (featurep 'xemacs) nil
1800                    '(:help "Save article in file"))]
1801               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1802               ["Save in MH folder" gnus-summary-save-article-folder t]
1803               ["Save in VM folder" gnus-summary-save-article-vm t]
1804               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1805               ["Save body in file" gnus-summary-save-article-body-file t]
1806               ["Pipe through a filter" gnus-summary-pipe-output t]
1807               ["Add to SOUP packet" gnus-soup-add-article t]
1808               ["Print" gnus-summary-print-article t])
1809              ("Backend"
1810               ["Respool article..." gnus-summary-respool-article t]
1811               ["Move article..." gnus-summary-move-article
1812                (gnus-check-backend-function
1813                 'request-move-article gnus-newsgroup-name)]
1814               ["Copy article..." gnus-summary-copy-article t]
1815               ["Crosspost article..." gnus-summary-crosspost-article
1816                (gnus-check-backend-function
1817                 'request-replace-article gnus-newsgroup-name)]
1818               ["Import file..." gnus-summary-import-article t]
1819               ["Check if posted" gnus-summary-article-posted-p t]
1820               ["Edit article" gnus-summary-edit-article
1821                (not (gnus-group-read-only-p))]
1822               ["Delete article" gnus-summary-delete-article
1823                (gnus-check-backend-function
1824                 'request-expire-articles gnus-newsgroup-name)]
1825               ["Query respool" gnus-summary-respool-query t]
1826               ["Trace respool" gnus-summary-respool-trace t]
1827               ["Delete expirable articles" gnus-summary-expire-articles-now
1828                (gnus-check-backend-function
1829                 'request-expire-articles gnus-newsgroup-name)])
1830              ("Extract"
1831               ["Uudecode" gnus-uu-decode-uu
1832                ,@(if (featurep 'xemacs) nil
1833                    '(:help "Decode uuencoded article(s)"))]
1834               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1835               ["Unshar" gnus-uu-decode-unshar t]
1836               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1837               ["Save" gnus-uu-decode-save t]
1838               ["Binhex" gnus-uu-decode-binhex t]
1839               ["Postscript" gnus-uu-decode-postscript t])
1840              ("Cache"
1841               ["Enter article" gnus-cache-enter-article t]
1842               ["Remove article" gnus-cache-remove-article t])
1843              ["Translate" gnus-article-babel t]
1844              ["Select article buffer" gnus-summary-select-article-buffer t]
1845              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1846              ["Isearch article..." gnus-summary-isearch-article t]
1847              ["Beginning of the article" gnus-summary-beginning-of-article t]
1848              ["End of the article" gnus-summary-end-of-article t]
1849              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1850              ["Fetch referenced articles" gnus-summary-refer-references t]
1851              ["Fetch current thread" gnus-summary-refer-thread t]
1852              ["Fetch article with id..." gnus-summary-refer-article t]
1853              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1854              ["Redisplay" gnus-summary-show-article t])))
1855       (easy-menu-define
1856        gnus-summary-article-menu gnus-summary-mode-map ""
1857        (cons "Article" innards))
1858
1859       (easy-menu-define
1860        gnus-article-commands-menu gnus-article-mode-map ""
1861        (cons "Commands" innards)))
1862
1863     (easy-menu-define
1864      gnus-summary-thread-menu gnus-summary-mode-map ""
1865      '("Threads"
1866        ["Toggle threading" gnus-summary-toggle-threads t]
1867        ["Hide threads" gnus-summary-hide-all-threads t]
1868        ["Show threads" gnus-summary-show-all-threads t]
1869        ["Hide thread" gnus-summary-hide-thread t]
1870        ["Show thread" gnus-summary-show-thread t]
1871        ["Go to next thread" gnus-summary-next-thread t]
1872        ["Go to previous thread" gnus-summary-prev-thread t]
1873        ["Go down thread" gnus-summary-down-thread t]
1874        ["Go up thread" gnus-summary-up-thread t]
1875        ["Top of thread" gnus-summary-top-thread t]
1876        ["Mark thread as read" gnus-summary-kill-thread t]
1877        ["Lower thread score" gnus-summary-lower-thread t]
1878        ["Raise thread score" gnus-summary-raise-thread t]
1879        ["Rethread current" gnus-summary-rethread-current t]))
1880
1881     (easy-menu-define
1882      gnus-summary-post-menu gnus-summary-mode-map ""
1883      `("Post"
1884        ["Post an article" gnus-summary-post-news
1885         ,@(if (featurep 'xemacs) nil
1886             '(:help "Post an article"))]
1887        ["Followup" gnus-summary-followup
1888         ,@(if (featurep 'xemacs) nil
1889             '(:help "Post followup to this article"))]
1890        ["Followup and yank" gnus-summary-followup-with-original
1891         ,@(if (featurep 'xemacs) nil
1892             '(:help "Post followup to this article, quoting its contents"))]
1893        ["Supersede article" gnus-summary-supersede-article t]
1894        ["Cancel article" gnus-summary-cancel-article
1895         ,@(if (featurep 'xemacs) nil
1896             '(:help "Cancel an article you posted"))]
1897        ["Reply" gnus-summary-reply t]
1898        ["Reply and yank" gnus-summary-reply-with-original t]
1899        ["Wide reply" gnus-summary-wide-reply t]
1900        ["Wide reply and yank" gnus-summary-wide-reply-with-original
1901         ,@(if (featurep 'xemacs) nil
1902             '(:help "Mail a reply, quoting this article"))]
1903        ["Mail forward" gnus-summary-mail-forward t]
1904        ["Post forward" gnus-summary-post-forward t]
1905        ["Digest and mail" gnus-uu-digest-mail-forward t]
1906        ["Digest and post" gnus-uu-digest-post-forward t]
1907        ["Resend message" gnus-summary-resend-message t]
1908        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1909        ["Send a mail" gnus-summary-mail-other-window t]
1910        ["Uuencode and post" gnus-uu-post-news
1911         ,@(if (featurep 'xemacs) nil
1912             '(:help "Post a uuencoded article"))]
1913        ["Followup via news" gnus-summary-followup-to-mail t]
1914        ["Followup via news and yank"
1915         gnus-summary-followup-to-mail-with-original t]
1916        ;;("Draft"
1917        ;;["Send" gnus-summary-send-draft t]
1918        ;;["Send bounced" gnus-resend-bounced-mail t])
1919        ))
1920
1921     (easy-menu-define
1922      gnus-summary-misc-menu gnus-summary-mode-map ""
1923      `("Misc"
1924        ("Mark Read"
1925         ["Mark as read" gnus-summary-mark-as-read-forward t]
1926         ["Mark same subject and select"
1927          gnus-summary-kill-same-subject-and-select t]
1928         ["Mark same subject" gnus-summary-kill-same-subject t]
1929         ["Catchup" gnus-summary-catchup
1930          ,@(if (featurep 'xemacs) nil
1931              '(:help "Mark unread articles in this group as read"))]
1932         ["Catchup all" gnus-summary-catchup-all t]
1933         ["Catchup to here" gnus-summary-catchup-to-here t]
1934         ["Catchup region" gnus-summary-mark-region-as-read t]
1935         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1936        ("Mark Various"
1937         ["Tick" gnus-summary-tick-article-forward t]
1938         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1939         ["Remove marks" gnus-summary-clear-mark-forward t]
1940         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1941         ["Set bookmark" gnus-summary-set-bookmark t]
1942         ["Remove bookmark" gnus-summary-remove-bookmark t])
1943        ("Mark Limit"
1944         ["Marks..." gnus-summary-limit-to-marks t]
1945         ["Subject..." gnus-summary-limit-to-subject t]
1946         ["Author..." gnus-summary-limit-to-author t]
1947         ["Age..." gnus-summary-limit-to-age t]
1948         ["Extra..." gnus-summary-limit-to-extra t]
1949         ["Score" gnus-summary-limit-to-score t]
1950         ["Unread" gnus-summary-limit-to-unread t]
1951         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
1952         ["Articles" gnus-summary-limit-to-articles t]
1953         ["Pop limit" gnus-summary-pop-limit t]
1954         ["Show dormant" gnus-summary-limit-include-dormant t]
1955         ["Hide childless dormant"
1956          gnus-summary-limit-exclude-childless-dormant t]
1957         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
1958         ["Hide marked" gnus-summary-limit-exclude-marks t]
1959         ["Show expunged" gnus-summary-show-all-expunged t])
1960        ("Process Mark"
1961         ["Set mark" gnus-summary-mark-as-processable t]
1962         ["Remove mark" gnus-summary-unmark-as-processable t]
1963         ["Remove all marks" gnus-summary-unmark-all-processable t]
1964         ["Mark above" gnus-uu-mark-over t]
1965         ["Mark series" gnus-uu-mark-series t]
1966         ["Mark region" gnus-uu-mark-region t]
1967         ["Unmark region" gnus-uu-unmark-region t]
1968         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
1969         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
1970         ["Mark all" gnus-uu-mark-all t]
1971         ["Mark buffer" gnus-uu-mark-buffer t]
1972         ["Mark sparse" gnus-uu-mark-sparse t]
1973         ["Mark thread" gnus-uu-mark-thread t]
1974         ["Unmark thread" gnus-uu-unmark-thread t]
1975         ("Process Mark Sets"
1976          ["Kill" gnus-summary-kill-process-mark t]
1977          ["Yank" gnus-summary-yank-process-mark
1978           gnus-newsgroup-process-stack]
1979          ["Save" gnus-summary-save-process-mark t]))
1980        ("Scroll article"
1981         ["Page forward" gnus-summary-next-page
1982          ,@(if (featurep 'xemacs) nil
1983              '(:help "Show next page of article"))]
1984         ["Page backward" gnus-summary-prev-page
1985          ,@(if (featurep 'xemacs) nil
1986              '(:help "Show previous page of article"))]
1987         ["Line forward" gnus-summary-scroll-up t])
1988        ("Move"
1989         ["Next unread article" gnus-summary-next-unread-article t]
1990         ["Previous unread article" gnus-summary-prev-unread-article t]
1991         ["Next article" gnus-summary-next-article t]
1992         ["Previous article" gnus-summary-prev-article t]
1993         ["Next unread subject" gnus-summary-next-unread-subject t]
1994         ["Previous unread subject" gnus-summary-prev-unread-subject t]
1995         ["Next article same subject" gnus-summary-next-same-subject t]
1996         ["Previous article same subject" gnus-summary-prev-same-subject t]
1997         ["First unread article" gnus-summary-first-unread-article t]
1998         ["Best unread article" gnus-summary-best-unread-article t]
1999         ["Go to subject number..." gnus-summary-goto-subject t]
2000         ["Go to article number..." gnus-summary-goto-article t]
2001         ["Go to the last article" gnus-summary-goto-last-article t]
2002         ["Pop article off history" gnus-summary-pop-article t])
2003        ("Sort"
2004         ["Sort by number" gnus-summary-sort-by-number t]
2005         ["Sort by author" gnus-summary-sort-by-author t]
2006         ["Sort by subject" gnus-summary-sort-by-subject t]
2007         ["Sort by date" gnus-summary-sort-by-date t]
2008         ["Sort by score" gnus-summary-sort-by-score t]
2009         ["Sort by lines" gnus-summary-sort-by-lines t]
2010         ["Sort by characters" gnus-summary-sort-by-chars t])
2011        ("Help"
2012         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2013         ["Describe group" gnus-summary-describe-group t]
2014         ["Read manual" gnus-info-find-node t])
2015        ("Modes"
2016         ["Pick and read" gnus-pick-mode t]
2017         ["Binary" gnus-binary-mode t])
2018        ("Regeneration"
2019         ["Regenerate" gnus-summary-prepare t]
2020         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2021         ["Toggle threading" gnus-summary-toggle-threads t])
2022        ["Filter articles..." gnus-summary-execute-command t]
2023        ["Run command on subjects..." gnus-summary-universal-argument t]
2024        ["Search articles forward..." gnus-summary-search-article-forward t]
2025        ["Search articles backward..." gnus-summary-search-article-backward t]
2026        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2027        ["Expand window" gnus-summary-expand-window t]
2028        ["Expire expirable articles" gnus-summary-expire-articles
2029         (gnus-check-backend-function
2030          'request-expire-articles gnus-newsgroup-name)]
2031        ["Edit local kill file" gnus-summary-edit-local-kill t]
2032        ["Edit main kill file" gnus-summary-edit-global-kill t]
2033        ["Edit group parameters" gnus-summary-edit-parameters t]
2034        ["Customize group parameters" gnus-summary-customize-parameters t]
2035        ["Send a bug report" gnus-bug t]
2036        ("Exit"
2037         ["Catchup and exit" gnus-summary-catchup-and-exit
2038          ,@(if (featurep 'xemacs) nil
2039              '(:help "Mark unread articles in this group as read, then exit"))]
2040         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2041         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2042         ["Exit group" gnus-summary-exit
2043          ,@(if (featurep 'xemacs) nil
2044              '(:help "Exit current group, return to group selection mode"))]
2045         ["Exit group without updating" gnus-summary-exit-no-update t]
2046         ["Exit and goto next group" gnus-summary-next-group t]
2047         ["Exit and goto prev group" gnus-summary-prev-group t]
2048         ["Reselect group" gnus-summary-reselect-current-group t]
2049         ["Rescan group" gnus-summary-rescan-group t]
2050         ["Update dribble" gnus-summary-save-newsrc t])))
2051
2052     (gnus-run-hooks 'gnus-summary-menu-hook)))
2053
2054 (defvar gnus-summary-tool-bar-map nil)
2055
2056 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2057 (defun gnus-summary-make-tool-bar ()
2058   (if (and (fboundp 'tool-bar-add-item-from-menu)
2059            (default-value 'tool-bar-mode)
2060            (not gnus-summary-tool-bar-map))
2061       (setq gnus-summary-tool-bar-map
2062             (let ((tool-bar-map (make-sparse-keymap))
2063                   (load-path (mm-image-load-path)))
2064               (tool-bar-add-item-from-menu
2065                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2066               (tool-bar-add-item-from-menu
2067                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2068               (tool-bar-add-item-from-menu
2069                'gnus-summary-post-news "post" gnus-summary-mode-map)
2070               (tool-bar-add-item-from-menu
2071                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2072               (tool-bar-add-item-from-menu
2073                'gnus-summary-followup "followup" gnus-summary-mode-map)
2074               (tool-bar-add-item-from-menu
2075                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2076               (tool-bar-add-item-from-menu
2077                'gnus-summary-reply "reply" gnus-summary-mode-map)
2078               (tool-bar-add-item-from-menu
2079                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2080               (tool-bar-add-item-from-menu
2081                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2082               (tool-bar-add-item-from-menu
2083                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2084               (tool-bar-add-item-from-menu
2085                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2086               (tool-bar-add-item-from-menu
2087                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2088               (tool-bar-add-item-from-menu
2089                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2090               (tool-bar-add-item-from-menu
2091                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2092               (tool-bar-add-item-from-menu
2093                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2094               tool-bar-map)))
2095   (if gnus-summary-tool-bar-map
2096       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2097
2098 (defun gnus-score-set-default (var value)
2099   "A version of set that updates the GNU Emacs menu-bar."
2100   (set var value)
2101   ;; It is the message that forces the active status to be updated.
2102   (message ""))
2103
2104 (defun gnus-make-score-map (type)
2105   "Make a summary score map of type TYPE."
2106   (if t
2107       nil
2108     (let ((headers '(("author" "from" string)
2109                      ("subject" "subject" string)
2110                      ("article body" "body" string)
2111                      ("article head" "head" string)
2112                      ("xref" "xref" string)
2113                      ("extra header" "extra" string)
2114                      ("lines" "lines" number)
2115                      ("followups to author" "followup" string)))
2116           (types '((number ("less than" <)
2117                            ("greater than" >)
2118                            ("equal" =))
2119                    (string ("substring" s)
2120                            ("exact string" e)
2121                            ("fuzzy string" f)
2122                            ("regexp" r))))
2123           (perms '(("temporary" (current-time-string))
2124                    ("permanent" nil)
2125                    ("immediate" now)))
2126           header)
2127       (list
2128        (apply
2129         'nconc
2130         (list
2131          (if (eq type 'lower)
2132              "Lower score"
2133            "Increase score"))
2134         (let (outh)
2135           (while headers
2136             (setq header (car headers))
2137             (setq outh
2138                   (cons
2139                    (apply
2140                     'nconc
2141                     (list (car header))
2142                     (let ((ts (cdr (assoc (nth 2 header) types)))
2143                           outt)
2144                       (while ts
2145                         (setq outt
2146                               (cons
2147                                (apply
2148                                 'nconc
2149                                 (list (caar ts))
2150                                 (let ((ps perms)
2151                                       outp)
2152                                   (while ps
2153                                     (setq outp
2154                                           (cons
2155                                            (vector
2156                                             (caar ps)
2157                                             (list
2158                                              'gnus-summary-score-entry
2159                                              (nth 1 header)
2160                                              (if (or (string= (nth 1 header)
2161                                                               "head")
2162                                                      (string= (nth 1 header)
2163                                                               "body"))
2164                                                  ""
2165                                                (list 'gnus-summary-header
2166                                                      (nth 1 header)))
2167                                              (list 'quote (nth 1 (car ts)))
2168                                              (list 'gnus-score-delta-default
2169                                                    nil)
2170                                              (nth 1 (car ps))
2171                                              t)
2172                                             t)
2173                                            outp))
2174                                     (setq ps (cdr ps)))
2175                                   (list (nreverse outp))))
2176                                outt))
2177                         (setq ts (cdr ts)))
2178                       (list (nreverse outt))))
2179                    outh))
2180             (setq headers (cdr headers)))
2181           (list (nreverse outh))))))))
2182
2183 \f
2184
2185 (defun gnus-summary-mode (&optional group)
2186   "Major mode for reading articles.
2187
2188 All normal editing commands are switched off.
2189 \\<gnus-summary-mode-map>
2190 Each line in this buffer represents one article.  To read an
2191 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2192 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2193 respectively.
2194
2195 You can also post articles and send mail from this buffer.  To
2196 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2197 of an article, type `\\[gnus-summary-reply]'.
2198
2199 There are approx. one gazillion commands you can execute in this
2200 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2201
2202 The following commands are available:
2203
2204 \\{gnus-summary-mode-map}"
2205   (interactive)
2206   (kill-all-local-variables)
2207   (when (gnus-visual-p 'summary-menu 'menu)
2208     (gnus-summary-make-menu-bar)
2209     (gnus-summary-make-tool-bar))
2210   (gnus-summary-make-local-variables)
2211   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2212     (gnus-summary-make-local-variables))
2213   (gnus-make-thread-indent-array)
2214   (gnus-simplify-mode-line)
2215   (setq major-mode 'gnus-summary-mode)
2216   (setq mode-name "Summary")
2217   (make-local-variable 'minor-mode-alist)
2218   (use-local-map gnus-summary-mode-map)
2219   (buffer-disable-undo)
2220   (setq buffer-read-only t)             ;Disable modification
2221   (setq truncate-lines t)
2222   (setq selective-display t)
2223   (setq selective-display-ellipses t)   ;Display `...'
2224   (gnus-summary-set-display-table)
2225   (gnus-set-default-directory)
2226   (setq gnus-newsgroup-name group)
2227   (unless (gnus-news-group-p group)
2228     (setq gnus-newsgroup-incorporated
2229           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2230   (make-local-variable 'gnus-summary-line-format)
2231   (make-local-variable 'gnus-summary-line-format-spec)
2232   (make-local-variable 'gnus-summary-dummy-line-format)
2233   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2234   (make-local-variable 'gnus-summary-mark-positions)
2235   (make-local-hook 'pre-command-hook)
2236   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2237   (gnus-run-hooks 'gnus-summary-mode-hook)
2238   (turn-on-gnus-mailing-list-mode)
2239   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2240   (gnus-update-summary-mark-positions))
2241
2242 (defun gnus-summary-make-local-variables ()
2243   "Make all the local summary buffer variables."
2244   (let (global)
2245     (dolist (local gnus-summary-local-variables)
2246       (if (consp local)
2247           (progn
2248             (if (eq (cdr local) 'global)
2249                 ;; Copy the global value of the variable.
2250                 (setq global (symbol-value (car local)))
2251               ;; Use the value from the list.
2252               (setq global (eval (cdr local))))
2253             (set (make-local-variable (car local)) global))
2254         ;; Simple nil-valued local variable.
2255         (set (make-local-variable local) nil)))))
2256
2257 (defun gnus-summary-clear-local-variables ()
2258   (let ((locals gnus-summary-local-variables))
2259     (while locals
2260       (if (consp (car locals))
2261           (and (vectorp (caar locals))
2262                (set (caar locals) nil))
2263         (and (vectorp (car locals))
2264              (set (car locals) nil)))
2265       (setq locals (cdr locals)))))
2266
2267 ;; Summary data functions.
2268
2269 (defmacro gnus-data-number (data)
2270   `(car ,data))
2271
2272 (defmacro gnus-data-set-number (data number)
2273   `(setcar ,data ,number))
2274
2275 (defmacro gnus-data-mark (data)
2276   `(nth 1 ,data))
2277
2278 (defmacro gnus-data-set-mark (data mark)
2279   `(setcar (nthcdr 1 ,data) ,mark))
2280
2281 (defmacro gnus-data-pos (data)
2282   `(nth 2 ,data))
2283
2284 (defmacro gnus-data-set-pos (data pos)
2285   `(setcar (nthcdr 2 ,data) ,pos))
2286
2287 (defmacro gnus-data-header (data)
2288   `(nth 3 ,data))
2289
2290 (defmacro gnus-data-set-header (data header)
2291   `(setcar (nthcdr 3 ,data) ,header))
2292
2293 (defmacro gnus-data-level (data)
2294   `(nth 4 ,data))
2295
2296 (defmacro gnus-data-unread-p (data)
2297   `(= (nth 1 ,data) gnus-unread-mark))
2298
2299 (defmacro gnus-data-read-p (data)
2300   `(/= (nth 1 ,data) gnus-unread-mark))
2301
2302 (defmacro gnus-data-pseudo-p (data)
2303   `(consp (nth 3 ,data)))
2304
2305 (defmacro gnus-data-find (number)
2306   `(assq ,number gnus-newsgroup-data))
2307
2308 (defmacro gnus-data-find-list (number &optional data)
2309   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2310      (memq (assq ,number bdata)
2311            bdata)))
2312
2313 (defmacro gnus-data-make (number mark pos header level)
2314   `(list ,number ,mark ,pos ,header ,level))
2315
2316 (defun gnus-data-enter (after-article number mark pos header level offset)
2317   (let ((data (gnus-data-find-list after-article)))
2318     (unless data
2319       (error "No such article: %d" after-article))
2320     (setcdr data (cons (gnus-data-make number mark pos header level)
2321                        (cdr data)))
2322     (setq gnus-newsgroup-data-reverse nil)
2323     (gnus-data-update-list (cddr data) offset)))
2324
2325 (defun gnus-data-enter-list (after-article list &optional offset)
2326   (when list
2327     (let ((data (and after-article (gnus-data-find-list after-article)))
2328           (ilist list))
2329       (if (not (or data
2330                    after-article))
2331           (let ((odata gnus-newsgroup-data))
2332             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2333             (when offset
2334               (gnus-data-update-list odata offset)))
2335         ;; Find the last element in the list to be spliced into the main
2336         ;; list.
2337         (while (cdr list)
2338           (setq list (cdr list)))
2339         (if (not data)
2340             (progn
2341               (setcdr list gnus-newsgroup-data)
2342               (setq gnus-newsgroup-data ilist)
2343               (when offset
2344                 (gnus-data-update-list (cdr list) offset)))
2345           (setcdr list (cdr data))
2346           (setcdr data ilist)
2347           (when offset
2348             (gnus-data-update-list (cdr list) offset))))
2349       (setq gnus-newsgroup-data-reverse nil))))
2350
2351 (defun gnus-data-remove (article &optional offset)
2352   (let ((data gnus-newsgroup-data))
2353     (if (= (gnus-data-number (car data)) article)
2354         (progn
2355           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2356                 gnus-newsgroup-data-reverse nil)
2357           (when offset
2358             (gnus-data-update-list gnus-newsgroup-data offset)))
2359       (while (cdr data)
2360         (when (= (gnus-data-number (cadr data)) article)
2361           (setcdr data (cddr data))
2362           (when offset
2363             (gnus-data-update-list (cdr data) offset))
2364           (setq data nil
2365                 gnus-newsgroup-data-reverse nil))
2366         (setq data (cdr data))))))
2367
2368 (defmacro gnus-data-list (backward)
2369   `(if ,backward
2370        (or gnus-newsgroup-data-reverse
2371            (setq gnus-newsgroup-data-reverse
2372                  (reverse gnus-newsgroup-data)))
2373      gnus-newsgroup-data))
2374
2375 (defun gnus-data-update-list (data offset)
2376   "Add OFFSET to the POS of all data entries in DATA."
2377   (setq gnus-newsgroup-data-reverse nil)
2378   (while data
2379     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2380     (setq data (cdr data))))
2381
2382 (defun gnus-summary-article-pseudo-p (article)
2383   "Say whether this article is a pseudo article or not."
2384   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2385
2386 (defmacro gnus-summary-article-sparse-p (article)
2387   "Say whether this article is a sparse article or not."
2388   `(memq ,article gnus-newsgroup-sparse))
2389
2390 (defmacro gnus-summary-article-ancient-p (article)
2391   "Say whether this article is a sparse article or not."
2392   `(memq ,article gnus-newsgroup-ancient))
2393
2394 (defun gnus-article-parent-p (number)
2395   "Say whether this article is a parent or not."
2396   (let ((data (gnus-data-find-list number)))
2397     (and (cdr data)                     ; There has to be an article after...
2398          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2399             (gnus-data-level (nth 1 data))))))
2400
2401 (defun gnus-article-children (number)
2402   "Return a list of all children to NUMBER."
2403   (let* ((data (gnus-data-find-list number))
2404          (level (gnus-data-level (car data)))
2405          children)
2406     (setq data (cdr data))
2407     (while (and data
2408                 (= (gnus-data-level (car data)) (1+ level)))
2409       (push (gnus-data-number (car data)) children)
2410       (setq data (cdr data)))
2411     children))
2412
2413 (defmacro gnus-summary-skip-intangible ()
2414   "If the current article is intangible, then jump to a different article."
2415   '(let ((to (get-text-property (point) 'gnus-intangible)))
2416      (and to (gnus-summary-goto-subject to))))
2417
2418 (defmacro gnus-summary-article-intangible-p ()
2419   "Say whether this article is intangible or not."
2420   '(get-text-property (point) 'gnus-intangible))
2421
2422 (defun gnus-article-read-p (article)
2423   "Say whether ARTICLE is read or not."
2424   (not (or (memq article gnus-newsgroup-marked)
2425            (memq article gnus-newsgroup-unreads)
2426            (memq article gnus-newsgroup-unselected)
2427            (memq article gnus-newsgroup-dormant))))
2428
2429 ;; Some summary mode macros.
2430
2431 (defmacro gnus-summary-article-number ()
2432   "The article number of the article on the current line.
2433 If there isn's an article number here, then we return the current
2434 article number."
2435   '(progn
2436      (gnus-summary-skip-intangible)
2437      (or (get-text-property (point) 'gnus-number)
2438          (gnus-summary-last-subject))))
2439
2440 (defmacro gnus-summary-article-header (&optional number)
2441   "Return the header of article NUMBER."
2442   `(gnus-data-header (gnus-data-find
2443                       ,(or number '(gnus-summary-article-number)))))
2444
2445 (defmacro gnus-summary-thread-level (&optional number)
2446   "Return the level of thread that starts with article NUMBER."
2447   `(if (and (eq gnus-summary-make-false-root 'dummy)
2448             (get-text-property (point) 'gnus-intangible))
2449        0
2450      (gnus-data-level (gnus-data-find
2451                        ,(or number '(gnus-summary-article-number))))))
2452
2453 (defmacro gnus-summary-article-mark (&optional number)
2454   "Return the mark of article NUMBER."
2455   `(gnus-data-mark (gnus-data-find
2456                     ,(or number '(gnus-summary-article-number)))))
2457
2458 (defmacro gnus-summary-article-pos (&optional number)
2459   "Return the position of the line of article NUMBER."
2460   `(gnus-data-pos (gnus-data-find
2461                    ,(or number '(gnus-summary-article-number)))))
2462
2463 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2464 (defmacro gnus-summary-article-subject (&optional number)
2465   "Return current subject string or nil if nothing."
2466   `(let ((headers
2467           ,(if number
2468                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2469              '(gnus-data-header (assq (gnus-summary-article-number)
2470                                       gnus-newsgroup-data)))))
2471      (and headers
2472           (vectorp headers)
2473           (mail-header-subject headers))))
2474
2475 (defmacro gnus-summary-article-score (&optional number)
2476   "Return current article score."
2477   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2478                   gnus-newsgroup-scored))
2479        gnus-summary-default-score 0))
2480
2481 (defun gnus-summary-article-children (&optional number)
2482   "Return a list of article numbers that are children of article NUMBER."
2483   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2484          (level (gnus-data-level (car data)))
2485          l children)
2486     (while (and (setq data (cdr data))
2487                 (> (setq l (gnus-data-level (car data))) level))
2488       (and (= (1+ level) l)
2489            (push (gnus-data-number (car data))
2490                  children)))
2491     (nreverse children)))
2492
2493 (defun gnus-summary-article-parent (&optional number)
2494   "Return the article number of the parent of article NUMBER."
2495   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2496                                     (gnus-data-list t)))
2497          (level (gnus-data-level (car data))))
2498     (if (zerop level)
2499         ()                              ; This is a root.
2500       ;; We search until we find an article with a level less than
2501       ;; this one.  That function has to be the parent.
2502       (while (and (setq data (cdr data))
2503                   (not (< (gnus-data-level (car data)) level))))
2504       (and data (gnus-data-number (car data))))))
2505
2506 (defun gnus-unread-mark-p (mark)
2507   "Say whether MARK is the unread mark."
2508   (= mark gnus-unread-mark))
2509
2510 (defun gnus-read-mark-p (mark)
2511   "Say whether MARK is one of the marks that mark as read.
2512 This is all marks except unread, ticked, dormant, and expirable."
2513   (not (or (= mark gnus-unread-mark)
2514            (= mark gnus-ticked-mark)
2515            (= mark gnus-dormant-mark)
2516            (= mark gnus-expirable-mark))))
2517
2518 (defmacro gnus-article-mark (number)
2519   "Return the MARK of article NUMBER.
2520 This macro should only be used when computing the mark the \"first\"
2521 time; i.e., when generating the summary lines.  After that,
2522 `gnus-summary-article-mark' should be used to examine the
2523 marks of articles."
2524   `(cond
2525     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2526     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2527     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2528     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2529     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2530     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2531     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2532     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2533            gnus-ancient-mark))))
2534
2535 ;; Saving hidden threads.
2536
2537 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2538 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2539
2540 (defmacro gnus-save-hidden-threads (&rest forms)
2541   "Save hidden threads, eval FORMS, and restore the hidden threads."
2542   (let ((config (make-symbol "config")))
2543     `(let ((,config (gnus-hidden-threads-configuration)))
2544        (unwind-protect
2545            (save-excursion
2546              ,@forms)
2547          (gnus-restore-hidden-threads-configuration ,config)))))
2548
2549 (defun gnus-data-compute-positions ()
2550   "Compute the positions of all articles."
2551   (setq gnus-newsgroup-data-reverse nil)
2552   (let ((data gnus-newsgroup-data))
2553     (save-excursion
2554       (gnus-save-hidden-threads
2555         (gnus-summary-show-all-threads)
2556         (goto-char (point-min))
2557         (while data
2558           (while (get-text-property (point) 'gnus-intangible)
2559             (forward-line 1))
2560           (gnus-data-set-pos (car data) (+ (point) 3))
2561           (setq data (cdr data))
2562           (forward-line 1))))))
2563
2564 (defun gnus-hidden-threads-configuration ()
2565   "Return the current hidden threads configuration."
2566   (save-excursion
2567     (let (config)
2568       (goto-char (point-min))
2569       (while (search-forward "\r" nil t)
2570         (push (1- (point)) config))
2571       config)))
2572
2573 (defun gnus-restore-hidden-threads-configuration (config)
2574   "Restore hidden threads configuration from CONFIG."
2575   (save-excursion
2576     (let (point buffer-read-only)
2577       (while (setq point (pop config))
2578         (when (and (< point (point-max))
2579                    (goto-char point)
2580                    (eq (char-after) ?\n))
2581           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2582
2583 ;; Various summary mode internalish functions.
2584
2585 (defun gnus-mouse-pick-article (e)
2586   (interactive "e")
2587   (mouse-set-point e)
2588   (gnus-summary-next-page nil t))
2589
2590 (defun gnus-summary-set-display-table ()
2591   "Change the display table.
2592 Odd characters have a tendency to mess
2593 up nicely formatted displays - we make all possible glyphs
2594 display only a single character."
2595
2596   ;; We start from the standard display table, if any.
2597   (let ((table (or (copy-sequence standard-display-table)
2598                    (make-display-table)))
2599         (i 32))
2600     ;; Nix out all the control chars...
2601     (while (>= (setq i (1- i)) 0)
2602       (aset table i [??]))
2603     ;; ... but not newline and cr, of course.  (cr is necessary for the
2604     ;; selective display).
2605     (aset table ?\n nil)
2606     (aset table ?\r nil)
2607     ;; We keep TAB as well.
2608     (aset table ?\t nil)
2609     ;; We nix out any glyphs over 126 that are not set already.
2610     (let ((i 256))
2611       (while (>= (setq i (1- i)) 127)
2612         ;; Only modify if the entry is nil.
2613         (unless (aref table i)
2614           (aset table i [??]))))
2615     (setq buffer-display-table table)))
2616
2617 (defun gnus-summary-setup-buffer (group)
2618   "Initialize summary buffer."
2619   (let ((buffer (concat "*Summary " group "*")))
2620     (if (get-buffer buffer)
2621         (progn
2622           (set-buffer buffer)
2623           (setq gnus-summary-buffer (current-buffer))
2624           (not gnus-newsgroup-prepared))
2625       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2626       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2627       (gnus-summary-mode group)
2628       (when gnus-carpal
2629         (gnus-carpal-setup-buffer 'summary))
2630       (unless gnus-single-article-buffer
2631         (make-local-variable 'gnus-article-buffer)
2632         (make-local-variable 'gnus-article-current)
2633         (make-local-variable 'gnus-original-article-buffer))
2634       (setq gnus-newsgroup-name group)
2635       t)))
2636
2637 (defun gnus-set-global-variables ()
2638   "Set the global equivalents of the buffer-local variables.
2639 They are set to the latest values they had.  These reflect the summary
2640 buffer that was in action when the last article was fetched."
2641   (when (eq major-mode 'gnus-summary-mode)
2642     (setq gnus-summary-buffer (current-buffer))
2643     (let ((name gnus-newsgroup-name)
2644           (marked gnus-newsgroup-marked)
2645           (unread gnus-newsgroup-unreads)
2646           (headers gnus-current-headers)
2647           (data gnus-newsgroup-data)
2648           (summary gnus-summary-buffer)
2649           (article-buffer gnus-article-buffer)
2650           (original gnus-original-article-buffer)
2651           (gac gnus-article-current)
2652           (reffed gnus-reffed-article-number)
2653           (score-file gnus-current-score-file)
2654           (default-charset gnus-newsgroup-charset)
2655           vlist)
2656       (let ((locals gnus-newsgroup-variables))
2657         (while locals
2658           (if (consp (car locals))
2659               (push (eval (caar locals)) vlist)
2660             (push (eval (car locals)) vlist))
2661           (setq locals (cdr locals)))
2662         (setq vlist (nreverse vlist)))
2663       (save-excursion
2664         (set-buffer gnus-group-buffer)
2665         (setq gnus-newsgroup-name name
2666               gnus-newsgroup-marked marked
2667               gnus-newsgroup-unreads unread
2668               gnus-current-headers headers
2669               gnus-newsgroup-data data
2670               gnus-article-current gac
2671               gnus-summary-buffer summary
2672               gnus-article-buffer article-buffer
2673               gnus-original-article-buffer original
2674               gnus-reffed-article-number reffed
2675               gnus-current-score-file score-file
2676               gnus-newsgroup-charset default-charset)
2677         (let ((locals gnus-newsgroup-variables))
2678           (while locals
2679             (if (consp (car locals))
2680                 (set (caar locals) (pop vlist))
2681               (set (car locals) (pop vlist)))
2682             (setq locals (cdr locals))))
2683         ;; The article buffer also has local variables.
2684         (when (gnus-buffer-live-p gnus-article-buffer)
2685           (set-buffer gnus-article-buffer)
2686           (setq gnus-summary-buffer summary))))))
2687
2688 (defun gnus-summary-article-unread-p (article)
2689   "Say whether ARTICLE is unread or not."
2690   (memq article gnus-newsgroup-unreads))
2691
2692 (defun gnus-summary-first-article-p (&optional article)
2693   "Return whether ARTICLE is the first article in the buffer."
2694   (if (not (setq article (or article (gnus-summary-article-number))))
2695       nil
2696     (eq article (caar gnus-newsgroup-data))))
2697
2698 (defun gnus-summary-last-article-p (&optional article)
2699   "Return whether ARTICLE is the last article in the buffer."
2700   (if (not (setq article (or article (gnus-summary-article-number))))
2701       ;; All non-existent numbers are the last article.  :-)
2702       t
2703     (not (cdr (gnus-data-find-list article)))))
2704
2705 (defun gnus-make-thread-indent-array ()
2706   (let ((n 200))
2707     (unless (and gnus-thread-indent-array
2708                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2709       (setq gnus-thread-indent-array (make-vector 201 "")
2710             gnus-thread-indent-array-level gnus-thread-indent-level)
2711       (while (>= n 0)
2712         (aset gnus-thread-indent-array n
2713               (make-string (* n gnus-thread-indent-level) ? ))
2714         (setq n (1- n))))))
2715
2716 (defun gnus-update-summary-mark-positions ()
2717   "Compute where the summary marks are to go."
2718   (save-excursion
2719     (when (gnus-buffer-exists-p gnus-summary-buffer)
2720       (set-buffer gnus-summary-buffer))
2721     (let ((gnus-replied-mark 129)
2722           (gnus-score-below-mark 130)
2723           (gnus-score-over-mark 130)
2724           (gnus-download-mark 131)
2725           (spec gnus-summary-line-format-spec)
2726           gnus-visual pos)
2727       (save-excursion
2728         (gnus-set-work-buffer)
2729         (let ((gnus-summary-line-format-spec spec)
2730               (gnus-newsgroup-downloadable '((0 . t))))
2731           (gnus-summary-insert-line
2732            (make-full-mail-header 0 "" "nobody" "" "" "" 0 0 "" nil)
2733            0 nil 128 t nil "" nil 1)
2734           (goto-char (point-min))
2735           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2736                                              (- (point) 2)))))
2737           (goto-char (point-min))
2738           (push (cons 'replied (and (search-forward "\201" nil t)
2739                                     (- (point) 2)))
2740                 pos)
2741           (goto-char (point-min))
2742           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2743                 pos)
2744           (goto-char (point-min))
2745           (push (cons 'download
2746                       (and (search-forward "\203" nil t) (- (point) 2)))
2747                 pos)))
2748       (setq gnus-summary-mark-positions pos))))
2749
2750 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2751   "Insert a dummy root in the summary buffer."
2752   (beginning-of-line)
2753   (gnus-add-text-properties
2754    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2755    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2756
2757 (defun gnus-summary-from-or-to-or-newsgroups (header)
2758   (let ((to (cdr (assq 'To (mail-header-extra header))))
2759         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2760         (default-mime-charset (with-current-buffer gnus-summary-buffer
2761                                 default-mime-charset)))
2762     (cond
2763      ((and to
2764            gnus-ignored-from-addresses
2765            (string-match gnus-ignored-from-addresses
2766                          (mail-header-from header)))
2767       (concat "-> "
2768               (or (car (funcall gnus-extract-address-components
2769                                 (funcall
2770                                  gnus-decode-encoded-word-function to)))
2771                   (funcall gnus-decode-encoded-word-function to))))
2772      ((and newsgroups
2773            gnus-ignored-from-addresses
2774            (string-match gnus-ignored-from-addresses
2775                          (mail-header-from header)))
2776       (concat "=> " newsgroups))
2777      (t
2778       (or (car (funcall gnus-extract-address-components
2779                         (mail-header-from header)))
2780           (mail-header-from header))))))
2781
2782 (defun gnus-summary-insert-line (gnus-tmp-header
2783                                  gnus-tmp-level gnus-tmp-current
2784                                  gnus-tmp-unread gnus-tmp-replied
2785                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2786                                  &optional gnus-tmp-dummy gnus-tmp-score
2787                                  gnus-tmp-process)
2788   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2789          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2790          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2791          (gnus-tmp-score-char
2792           (if (or (null gnus-summary-default-score)
2793                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2794                       gnus-summary-zcore-fuzz))
2795               ?  ;Whitespace
2796             (if (< gnus-tmp-score gnus-summary-default-score)
2797                 gnus-score-below-mark gnus-score-over-mark)))
2798          (gnus-tmp-replied
2799           (cond (gnus-tmp-process gnus-process-mark)
2800                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2801                  gnus-cached-mark)
2802                 (gnus-tmp-replied gnus-replied-mark)
2803                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2804                  gnus-saved-mark)
2805                 (t gnus-unread-mark)))
2806          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2807          (gnus-tmp-name
2808           (cond
2809            ((string-match "<[^>]+> *$" gnus-tmp-from)
2810             (let ((beg (match-beginning 0)))
2811               (or (and (string-match "^\".+\"" gnus-tmp-from)
2812                        (substring gnus-tmp-from 1 (1- (match-end 0))))
2813                   (substring gnus-tmp-from 0 beg))))
2814            ((string-match "(.+)" gnus-tmp-from)
2815             (substring gnus-tmp-from
2816                        (1+ (match-beginning 0)) (1- (match-end 0))))
2817            (t gnus-tmp-from)))
2818          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2819          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2820          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2821          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2822          (buffer-read-only nil))
2823     (when (string= gnus-tmp-name "")
2824       (setq gnus-tmp-name gnus-tmp-from))
2825     (unless (numberp gnus-tmp-lines)
2826       (setq gnus-tmp-lines 0))
2827     (gnus-put-text-property-excluding-characters-with-faces
2828      (point)
2829      (progn (eval gnus-summary-line-format-spec) (point))
2830      'gnus-number gnus-tmp-number)
2831     (when (gnus-visual-p 'summary-highlight 'highlight)
2832       (forward-line -1)
2833       (gnus-run-hooks 'gnus-summary-update-hook)
2834       (forward-line 1))))
2835
2836 (defun gnus-summary-update-line (&optional dont-update)
2837   "Update summary line after change."
2838   (when (and gnus-summary-default-score
2839              (not gnus-summary-inhibit-highlight))
2840     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2841            (article (gnus-summary-article-number))
2842            (score (gnus-summary-article-score article)))
2843       (unless dont-update
2844         (if (and gnus-summary-mark-below
2845                  (< (gnus-summary-article-score)
2846                     gnus-summary-mark-below))
2847             ;; This article has a low score, so we mark it as read.
2848             (when (memq article gnus-newsgroup-unreads)
2849               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2850           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2851             ;; This article was previously marked as read on account
2852             ;; of a low score, but now it has risen, so we mark it as
2853             ;; unread.
2854             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2855         (gnus-summary-update-mark
2856          (if (or (null gnus-summary-default-score)
2857                  (<= (abs (- score gnus-summary-default-score))
2858                      gnus-summary-zcore-fuzz))
2859              ?  ;Whitespace
2860            (if (< score gnus-summary-default-score)
2861                gnus-score-below-mark gnus-score-over-mark))
2862          'score))
2863       ;; Do visual highlighting.
2864       (when (gnus-visual-p 'summary-highlight 'highlight)
2865         (gnus-run-hooks 'gnus-summary-update-hook)))))
2866
2867 (defvar gnus-tmp-new-adopts nil)
2868
2869 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2870   "Return the number of articles in THREAD.
2871 This may be 0 in some cases -- if none of the articles in
2872 the thread are to be displayed."
2873   (let* ((number
2874           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2875           (cond
2876            ((not (listp thread))
2877             1)
2878            ((and (consp thread) (cdr thread))
2879             (apply
2880              '+ 1 (mapcar
2881                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2882            ((null thread)
2883             1)
2884            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2885             1)
2886            (t 0))))
2887     (when (and level (zerop level) gnus-tmp-new-adopts)
2888       (incf number
2889             (apply '+ (mapcar
2890                        'gnus-summary-number-of-articles-in-thread
2891                        gnus-tmp-new-adopts))))
2892     (if char
2893         (if (> number 1) gnus-not-empty-thread-mark
2894           gnus-empty-thread-mark)
2895       number)))
2896
2897 (defun gnus-summary-set-local-parameters (group)
2898   "Go through the local params of GROUP and set all variable specs in that list."
2899   (let ((params (gnus-group-find-parameter group))
2900         elem)
2901     (while params
2902       (setq elem (car params)
2903             params (cdr params))
2904       (and (consp elem)                 ; Has to be a cons.
2905            (consp (cdr elem))           ; The cdr has to be a list.
2906            (symbolp (car elem))         ; Has to be a symbol in there.
2907            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2908            (ignore-errors               ; So we set it.
2909              (make-local-variable (car elem))
2910              (set (car elem) (eval (nth 1 elem))))))))
2911
2912 (defun gnus-summary-read-group (group &optional show-all no-article
2913                                       kill-buffer no-display backward
2914                                       select-articles)
2915   "Start reading news in newsgroup GROUP.
2916 If SHOW-ALL is non-nil, already read articles are also listed.
2917 If NO-ARTICLE is non-nil, no article is selected initially.
2918 If NO-DISPLAY, don't generate a summary buffer."
2919   (let (result)
2920     (while (and group
2921                 (null (setq result
2922                             (let ((gnus-auto-select-next nil))
2923                               (or (gnus-summary-read-group-1
2924                                    group show-all no-article
2925                                    kill-buffer no-display
2926                                    select-articles)
2927                                   (setq show-all nil
2928                                         select-articles nil)))))
2929                 (eq gnus-auto-select-next 'quietly))
2930       (set-buffer gnus-group-buffer)
2931       ;; The entry function called above goes to the next
2932       ;; group automatically, so we go two groups back
2933       ;; if we are searching for the previous group.
2934       (when backward
2935         (gnus-group-prev-unread-group 2))
2936       (if (not (equal group (gnus-group-group-name)))
2937           (setq group (gnus-group-group-name))
2938         (setq group nil)))
2939     result))
2940
2941 (defun gnus-summary-jump-to-other-group (group &optional show-all)
2942   "Directly jump to the other GROUP from summary buffer.
2943 If SHOW-ALL is non-nil, already read articles are also listed."
2944   (interactive
2945    (if (eq gnus-summary-buffer (current-buffer))
2946        (list (completing-read
2947               "Group: " gnus-active-hashtb nil t
2948               (when (and gnus-newsgroup-name
2949                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
2950                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
2951               'gnus-group-history)
2952              current-prefix-arg)
2953      (error "%s must be invoked from a gnus summary buffer." this-command)))
2954   (unless (or (zerop (length group))
2955               (and gnus-newsgroup-name
2956                    (string-equal gnus-newsgroup-name group)))
2957     (gnus-summary-exit)
2958     (gnus-summary-read-group group show-all
2959                              gnus-dont-select-after-jump-to-other-group)))
2960
2961 (defun gnus-summary-read-group-1 (group show-all no-article
2962                                         kill-buffer no-display
2963                                         &optional select-articles)
2964   ;; Killed foreign groups can't be entered.
2965   (when (and (not (gnus-group-native-p group))
2966              (not (gnus-gethash group gnus-newsrc-hashtb)))
2967     (error "Dead non-native groups can't be entered"))
2968   (gnus-message 5 "Retrieving newsgroup: %s..." group)
2969   (let* ((new-group (gnus-summary-setup-buffer group))
2970          (quit-config (gnus-group-quit-config group))
2971          (did-select (and new-group (gnus-select-newsgroup
2972                                      group show-all select-articles))))
2973     (cond
2974      ;; This summary buffer exists already, so we just select it.
2975      ((not new-group)
2976       (gnus-set-global-variables)
2977       (when kill-buffer
2978         (gnus-kill-or-deaden-summary kill-buffer))
2979       (gnus-configure-windows 'summary 'force)
2980       (gnus-set-mode-line 'summary)
2981       (gnus-summary-position-point)
2982       (message "")
2983       t)
2984      ;; We couldn't select this group.
2985      ((null did-select)
2986       (when (and (eq major-mode 'gnus-summary-mode)
2987                  (not (equal (current-buffer) kill-buffer)))
2988         (kill-buffer (current-buffer))
2989         (if (not quit-config)
2990             (progn
2991               ;; Update the info -- marks might need to be removed,
2992               ;; for instance.
2993               (gnus-summary-update-info)
2994               (set-buffer gnus-group-buffer)
2995               (gnus-group-jump-to-group group)
2996               (gnus-group-next-unread-group 1))
2997           (gnus-handle-ephemeral-exit quit-config)))
2998       (gnus-message 3 "Can't select group")
2999       nil)
3000      ;; The user did a `C-g' while prompting for number of articles,
3001      ;; so we exit this group.
3002      ((eq did-select 'quit)
3003       (and (eq major-mode 'gnus-summary-mode)
3004            (not (equal (current-buffer) kill-buffer))
3005            (kill-buffer (current-buffer)))
3006       (when kill-buffer
3007         (gnus-kill-or-deaden-summary kill-buffer))
3008       (if (not quit-config)
3009           (progn
3010             (set-buffer gnus-group-buffer)
3011             (gnus-group-jump-to-group group)
3012             (gnus-group-next-unread-group 1)
3013             (gnus-configure-windows 'group 'force))
3014         (gnus-handle-ephemeral-exit quit-config))
3015       ;; Finally signal the quit.
3016       (signal 'quit nil))
3017      ;; The group was successfully selected.
3018      (t
3019       (gnus-set-global-variables)
3020       ;; Save the active value in effect when the group was entered.
3021       (setq gnus-newsgroup-active
3022             (gnus-copy-sequence
3023              (gnus-active gnus-newsgroup-name)))
3024       ;; You can change the summary buffer in some way with this hook.
3025       (gnus-run-hooks 'gnus-select-group-hook)
3026       ;; Set any local variables in the group parameters.
3027       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3028       (gnus-update-format-specifications
3029        nil 'summary 'summary-mode 'summary-dummy)
3030       (gnus-update-summary-mark-positions)
3031       ;; Do score processing.
3032       (when gnus-use-scoring
3033         (gnus-possibly-score-headers))
3034       ;; Check whether to fill in the gaps in the threads.
3035       (when gnus-build-sparse-threads
3036         (gnus-build-sparse-threads))
3037       ;; Find the initial limit.
3038       (if gnus-show-threads
3039           (if show-all
3040               (let ((gnus-newsgroup-dormant nil))
3041                 (gnus-summary-initial-limit show-all))
3042             (gnus-summary-initial-limit show-all))
3043         ;; When untreaded, all articles are always shown.
3044         (setq gnus-newsgroup-limit
3045               (mapcar
3046                (lambda (header) (mail-header-number header))
3047                gnus-newsgroup-headers)))
3048       ;; Generate the summary buffer.
3049       (unless no-display
3050         (gnus-summary-prepare))
3051       (when gnus-use-trees
3052         (gnus-tree-open group)
3053         (setq gnus-summary-highlight-line-function
3054               'gnus-tree-highlight-article))
3055       ;; If the summary buffer is empty, but there are some low-scored
3056       ;; articles or some excluded dormants, we include these in the
3057       ;; buffer.
3058       (when (and (zerop (buffer-size))
3059                  (not no-display))
3060         (cond (gnus-newsgroup-dormant
3061                (gnus-summary-limit-include-dormant))
3062               ((and gnus-newsgroup-scored show-all)
3063                (gnus-summary-limit-include-expunged t))))
3064       ;; Function `gnus-apply-kill-file' must be called in this hook.
3065       (gnus-run-hooks 'gnus-apply-kill-hook)
3066       (if (and (zerop (buffer-size))
3067                (not no-display))
3068           (progn
3069             ;; This newsgroup is empty.
3070             (gnus-summary-catchup-and-exit nil t)
3071             (gnus-message 6 "No unread news")
3072             (when kill-buffer
3073               (gnus-kill-or-deaden-summary kill-buffer))
3074             ;; Return nil from this function.
3075             nil)
3076         ;; Hide conversation thread subtrees.  We cannot do this in
3077         ;; gnus-summary-prepare-hook since kill processing may not
3078         ;; work with hidden articles.
3079         (and gnus-show-threads
3080              gnus-thread-hide-subtree
3081              (gnus-summary-hide-all-threads))
3082         (when kill-buffer
3083           (gnus-kill-or-deaden-summary kill-buffer))
3084         ;; Show first unread article if requested.
3085         (if (and (not no-article)
3086                  (not no-display)
3087                  gnus-newsgroup-unreads
3088                  gnus-auto-select-first)
3089             (progn
3090               (gnus-configure-windows 'summary)
3091               (cond
3092                ((eq gnus-auto-select-first 'best)
3093                 (gnus-summary-best-unread-article))
3094                ((eq gnus-auto-select-first t)
3095                 (gnus-summary-first-unread-article))
3096                ((gnus-functionp gnus-auto-select-first)
3097                 (funcall gnus-auto-select-first))))
3098           ;; Don't select any articles, just move point to the first
3099           ;; article in the group.
3100           (goto-char (point-min))
3101           (gnus-summary-position-point)
3102           (gnus-configure-windows 'summary 'force)
3103           (gnus-set-mode-line 'summary))
3104         (when (get-buffer-window gnus-group-buffer t)
3105           ;; Gotta use windows, because recenter does weird stuff if
3106           ;; the current buffer ain't the displayed window.
3107           (let ((owin (selected-window)))
3108             (select-window (get-buffer-window gnus-group-buffer t))
3109             (when (gnus-group-goto-group group)
3110               (recenter))
3111             (select-window owin)))
3112         ;; Mark this buffer as "prepared".
3113         (setq gnus-newsgroup-prepared t)
3114         (gnus-run-hooks 'gnus-summary-prepared-hook)
3115         t)))))
3116
3117 (defun gnus-summary-prepare ()
3118   "Generate the summary buffer."
3119   (interactive)
3120   (let ((buffer-read-only nil))
3121     (erase-buffer)
3122     (setq gnus-newsgroup-data nil
3123           gnus-newsgroup-data-reverse nil)
3124     (gnus-run-hooks 'gnus-summary-generate-hook)
3125     ;; Generate the buffer, either with threads or without.
3126     (when gnus-newsgroup-headers
3127       (gnus-summary-prepare-threads
3128        (if gnus-show-threads
3129            (gnus-sort-gathered-threads
3130             (funcall gnus-summary-thread-gathering-function
3131                      (gnus-sort-threads
3132                       (gnus-cut-threads (gnus-make-threads)))))
3133          ;; Unthreaded display.
3134          (gnus-sort-articles gnus-newsgroup-headers))))
3135     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3136     ;; Call hooks for modifying summary buffer.
3137     (goto-char (point-min))
3138     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3139
3140 (defsubst gnus-general-simplify-subject (subject)
3141   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3142   (setq subject
3143         (cond
3144          ;; Truncate the subject.
3145          (gnus-simplify-subject-functions
3146           (gnus-map-function gnus-simplify-subject-functions subject))
3147          ((numberp gnus-summary-gather-subject-limit)
3148           (setq subject (gnus-simplify-subject-re subject))
3149           (if (> (length subject) gnus-summary-gather-subject-limit)
3150               (substring subject 0 gnus-summary-gather-subject-limit)
3151             subject))
3152          ;; Fuzzily simplify it.
3153          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3154           (gnus-simplify-subject-fuzzy subject))
3155          ;; Just remove the leading "Re:".
3156          (t
3157           (gnus-simplify-subject-re subject))))
3158
3159   (if (and gnus-summary-gather-exclude-subject
3160            (string-match gnus-summary-gather-exclude-subject subject))
3161       nil                               ; This article shouldn't be gathered
3162     subject))
3163
3164 (defun gnus-summary-simplify-subject-query ()
3165   "Query where the respool algorithm would put this article."
3166   (interactive)
3167   (gnus-summary-select-article)
3168   (message "%s"
3169            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3170
3171 (defun gnus-gather-threads-by-subject (threads)
3172   "Gather threads by looking at Subject headers."
3173   (if (not gnus-summary-make-false-root)
3174       threads
3175     (let ((hashtb (gnus-make-hashtable 1024))
3176           (prev threads)
3177           (result threads)
3178           subject hthread whole-subject)
3179       (while threads
3180         (setq subject (gnus-general-simplify-subject
3181                        (setq whole-subject (mail-header-subject
3182                                             (caar threads)))))
3183         (when subject
3184           (if (setq hthread (gnus-gethash subject hashtb))
3185               (progn
3186                 ;; We enter a dummy root into the thread, if we
3187                 ;; haven't done that already.
3188                 (unless (stringp (caar hthread))
3189                   (setcar hthread (list whole-subject (car hthread))))
3190                 ;; We add this new gathered thread to this gathered
3191                 ;; thread.
3192                 (setcdr (car hthread)
3193                         (nconc (cdar hthread) (list (car threads))))
3194                 ;; Remove it from the list of threads.
3195                 (setcdr prev (cdr threads))
3196                 (setq threads prev))
3197             ;; Enter this thread into the hash table.
3198             (gnus-sethash subject threads hashtb)))
3199         (setq prev threads)
3200         (setq threads (cdr threads)))
3201       result)))
3202
3203 (defun gnus-gather-threads-by-references (threads)
3204   "Gather threads by looking at References headers."
3205   (let ((idhashtb (gnus-make-hashtable 1024))
3206         (thhashtb (gnus-make-hashtable 1024))
3207         (prev threads)
3208         (result threads)
3209         ids references id gthread gid entered ref)
3210     (while threads
3211       (when (setq references (mail-header-references (caar threads)))
3212         (setq id (mail-header-id (caar threads))
3213               ids (gnus-split-references references)
3214               entered nil)
3215         (while (setq ref (pop ids))
3216           (setq ids (delete ref ids))
3217           (if (not (setq gid (gnus-gethash ref idhashtb)))
3218               (progn
3219                 (gnus-sethash ref id idhashtb)
3220                 (gnus-sethash id threads thhashtb))
3221             (setq gthread (gnus-gethash gid thhashtb))
3222             (unless entered
3223               ;; We enter a dummy root into the thread, if we
3224               ;; haven't done that already.
3225               (unless (stringp (caar gthread))
3226                 (setcar gthread (list (mail-header-subject (caar gthread))
3227                                       (car gthread))))
3228               ;; We add this new gathered thread to this gathered
3229               ;; thread.
3230               (setcdr (car gthread)
3231                       (nconc (cdar gthread) (list (car threads)))))
3232             ;; Add it into the thread hash table.
3233             (gnus-sethash id gthread thhashtb)
3234             (setq entered t)
3235             ;; Remove it from the list of threads.
3236             (setcdr prev (cdr threads))
3237             (setq threads prev))))
3238       (setq prev threads)
3239       (setq threads (cdr threads)))
3240     result))
3241
3242 (defun gnus-sort-gathered-threads (threads)
3243   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3244   (let ((result threads))
3245     (while threads
3246       (when (stringp (caar threads))
3247         (setcdr (car threads)
3248                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3249       (setq threads (cdr threads)))
3250     result))
3251
3252 (defun gnus-thread-loop-p (root thread)
3253   "Say whether ROOT is in THREAD."
3254   (let ((stack (list thread))
3255         (infloop 0)
3256         th)
3257     (while (setq thread (pop stack))
3258       (setq th (cdr thread))
3259       (while (and th
3260                   (not (eq (caar th) root)))
3261         (pop th))
3262       (if th
3263           ;; We have found a loop.
3264           (let (ref-dep)
3265             (setcdr thread (delq (car th) (cdr thread)))
3266             (if (boundp (setq ref-dep (intern "none"
3267                                               gnus-newsgroup-dependencies)))
3268                 (setcdr (symbol-value ref-dep)
3269                         (nconc (cdr (symbol-value ref-dep))
3270                                (list (car th))))
3271               (set ref-dep (list nil (car th))))
3272             (setq infloop 1
3273                   stack nil))
3274         ;; Push all the subthreads onto the stack.
3275         (push (cdr thread) stack)))
3276     infloop))
3277
3278 (defun gnus-make-threads ()
3279   "Go through the dependency hashtb and find the roots.  Return all threads."
3280   (let (threads)
3281     (while (catch 'infloop
3282              (mapatoms
3283               (lambda (refs)
3284                 ;; Deal with self-referencing References loops.
3285                 (when (and (car (symbol-value refs))
3286                            (not (zerop
3287                                  (apply
3288                                   '+
3289                                   (mapcar
3290                                    (lambda (thread)
3291                                      (gnus-thread-loop-p
3292                                       (car (symbol-value refs)) thread))
3293                                    (cdr (symbol-value refs)))))))
3294                   (setq threads nil)
3295                   (throw 'infloop t))
3296                 (unless (car (symbol-value refs))
3297                   ;; These threads do not refer back to any other articles,
3298                   ;; so they're roots.
3299                   (setq threads (append (cdr (symbol-value refs)) threads))))
3300               gnus-newsgroup-dependencies)))
3301     threads))
3302
3303 ;; Build the thread tree.
3304 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3305   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3306
3307 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3308 if it was already present.
3309
3310 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3311 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3312 Message-IDs will be renamed be renamed to a unique Message-ID before
3313 being entered.
3314
3315 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3316   (let* ((id (mail-header-id header))
3317          (id-dep (and id (intern id dependencies)))
3318          ref ref-dep ref-header)
3319     ;; Enter this `header' in the `dependencies' table.
3320     (cond
3321      ((not id-dep)
3322       (setq header nil))
3323      ;; The first two cases do the normal part: enter a new `header'
3324      ;; in the `dependencies' table.
3325      ((not (boundp id-dep))
3326       (set id-dep (list header)))
3327      ((null (car (symbol-value id-dep)))
3328       (setcar (symbol-value id-dep) header))
3329
3330      ;; From here the `header' was already present in the
3331      ;; `dependencies' table.
3332      (force-new
3333       ;; Overrides an existing entry;
3334       ;; just set the header part of the entry.
3335       (setcar (symbol-value id-dep) header))
3336
3337      ;; Renames the existing `header' to a unique Message-ID.
3338      ((not gnus-summary-ignore-duplicates)
3339       ;; An article with this Message-ID has already been seen.
3340       ;; We rename the Message-ID.
3341       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3342            (list header))
3343       (mail-header-set-id header id))
3344
3345      ;; The last case ignores an existing entry, except it adds any
3346      ;; additional Xrefs (in case the two articles came from different
3347      ;; servers.
3348      ;; Also sets `header' to `nil' meaning that the `dependencies'
3349      ;; table was *not* modified.
3350      (t
3351       (mail-header-set-xref
3352        (car (symbol-value id-dep))
3353        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3354                    "")
3355                (or (mail-header-xref header) "")))
3356       (setq header nil)))
3357
3358     (when header
3359       ;; First check if that we are not creating a References loop.
3360       (setq ref (gnus-parent-id (mail-header-references header)))
3361       (while (and ref
3362                   (setq ref-dep (intern-soft ref dependencies))
3363                   (boundp ref-dep)
3364                   (setq ref-header (car (symbol-value ref-dep))))
3365         (if (string= id ref)
3366             ;; Yuk!  This is a reference loop.  Make the article be a
3367             ;; root article.
3368             (progn
3369               (mail-header-set-references (car (symbol-value id-dep)) "none")
3370               (setq ref nil))
3371           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3372       (setq ref (gnus-parent-id (mail-header-references header)))
3373       (setq ref-dep (intern (or ref "none") dependencies))
3374       (if (boundp ref-dep)
3375           (setcdr (symbol-value ref-dep)
3376                   (nconc (cdr (symbol-value ref-dep))
3377                          (list (symbol-value id-dep))))
3378         (set ref-dep (list nil (symbol-value id-dep)))))
3379     header))
3380
3381 (defun gnus-build-sparse-threads ()
3382   (let ((headers gnus-newsgroup-headers)
3383         (mail-parse-charset gnus-newsgroup-charset)
3384         (gnus-summary-ignore-duplicates t)
3385         header references generation relations
3386         subject child end new-child date)
3387     ;; First we create an alist of generations/relations, where
3388     ;; generations is how much we trust the relation, and the relation
3389     ;; is parent/child.
3390     (gnus-message 7 "Making sparse threads...")
3391     (save-excursion
3392       (nnheader-set-temp-buffer " *gnus sparse threads*")
3393       (while (setq header (pop headers))
3394         (when (and (setq references (mail-header-references header))
3395                    (not (string= references "")))
3396           (insert references)
3397           (setq child (mail-header-id header)
3398                 subject (mail-header-subject header)
3399                 date (mail-header-date header)
3400                 generation 0)
3401           (while (search-backward ">" nil t)
3402             (setq end (1+ (point)))
3403             (when (search-backward "<" nil t)
3404               (setq new-child (buffer-substring (point) end))
3405               (push (list (incf generation)
3406                           child (setq child new-child)
3407                           subject date)
3408                     relations)))
3409           (when child
3410             (push (list (1+ generation) child nil subject) relations))
3411           (erase-buffer)))
3412       (kill-buffer (current-buffer)))
3413     ;; Sort over trustworthiness.
3414     (mapcar
3415      (lambda (relation)
3416        (when (gnus-dependencies-add-header
3417               (make-full-mail-header-from-decoded-header
3418                gnus-reffed-article-number
3419                (nth 3 relation) "" (or (nth 4 relation) "")
3420                (nth 1 relation)
3421                (or (nth 2 relation) "") 0 0 "")
3422               gnus-newsgroup-dependencies nil)
3423          (push gnus-reffed-article-number gnus-newsgroup-limit)
3424          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3425          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3426                gnus-newsgroup-reads)
3427          (decf gnus-reffed-article-number)))
3428      (sort relations 'car-less-than-car))
3429     (gnus-message 7 "Making sparse threads...done")))
3430
3431 (defun gnus-build-old-threads ()
3432   ;; Look at all the articles that refer back to old articles, and
3433   ;; fetch the headers for the articles that aren't there.  This will
3434   ;; build complete threads - if the roots haven't been expired by the
3435   ;; server, that is.
3436   (let ((mail-parse-charset gnus-newsgroup-charset)
3437         id heads)
3438     (mapatoms
3439      (lambda (refs)
3440        (when (not (car (symbol-value refs)))
3441          (setq heads (cdr (symbol-value refs)))
3442          (while heads
3443            (if (memq (mail-header-number (caar heads))
3444                      gnus-newsgroup-dormant)
3445                (setq heads (cdr heads))
3446              (setq id (symbol-name refs))
3447              (while (and (setq id (gnus-build-get-header id))
3448                          (not (car (gnus-id-to-thread id)))))
3449              (setq heads nil)))))
3450      gnus-newsgroup-dependencies)))
3451
3452 ;; This function has to be called with point after the article number
3453 ;; on the beginning of the line.
3454 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3455   (let ((eol (gnus-point-at-eol))
3456         (buffer (current-buffer))
3457         header)
3458
3459     ;; overview: [num subject from date id refs chars lines misc]
3460     (unwind-protect
3461         (progn
3462           (narrow-to-region (point) eol)
3463           (unless (eobp)
3464             (forward-char))
3465
3466           (setq header
3467                 (make-full-mail-header
3468                  number                         ; number
3469                  (nnheader-nov-field)           ; subject
3470                  (nnheader-nov-field)           ; from
3471                  (nnheader-nov-field)           ; date
3472                  (nnheader-nov-read-message-id) ; id
3473                  (nnheader-nov-field)           ; refs
3474                  (nnheader-nov-read-integer)    ; chars
3475                  (nnheader-nov-read-integer)    ; lines
3476                  (unless (eobp)
3477                    (if (looking-at "Xref: ")
3478                        (goto-char (match-end 0)))
3479                    (nnheader-nov-field))        ; Xref
3480                  (nnheader-nov-parse-extra))))  ; extra
3481
3482       (widen))
3483
3484     (when gnus-alter-header-function
3485       (funcall gnus-alter-header-function header))
3486     (gnus-dependencies-add-header header dependencies force-new)))
3487
3488 (defun gnus-build-get-header (id)
3489   "Look through the buffer of NOV lines and find the header to ID.
3490 Enter this line into the dependencies hash table, and return
3491 the id of the parent article (if any)."
3492   (let ((deps gnus-newsgroup-dependencies)
3493         found header)
3494     (prog1
3495         (save-excursion
3496           (set-buffer nntp-server-buffer)
3497           (let ((case-fold-search nil))
3498             (goto-char (point-min))
3499             (while (and (not found)
3500                         (search-forward id nil t))
3501               (beginning-of-line)
3502               (setq found (looking-at
3503                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3504                                    (regexp-quote id))))
3505               (or found (beginning-of-line 2)))
3506             (when found
3507               (beginning-of-line)
3508               (and
3509                (setq header (gnus-nov-parse-line
3510                              (read (current-buffer)) deps))
3511                (gnus-parent-id (mail-header-references header))))))
3512       (when header
3513         (let ((number (mail-header-number header)))
3514           (push number gnus-newsgroup-limit)
3515           (push header gnus-newsgroup-headers)
3516           (if (memq number gnus-newsgroup-unselected)
3517               (progn
3518                 (push number gnus-newsgroup-unreads)
3519                 (setq gnus-newsgroup-unselected
3520                       (delq number gnus-newsgroup-unselected)))
3521             (push number gnus-newsgroup-ancient)))))))
3522
3523 (defun gnus-build-all-threads ()
3524   "Read all the headers."
3525   (let ((gnus-summary-ignore-duplicates t)
3526         (mail-parse-charset gnus-newsgroup-charset)
3527         (dependencies gnus-newsgroup-dependencies)
3528         header article)
3529     (save-excursion
3530       (set-buffer nntp-server-buffer)
3531       (let ((case-fold-search nil))
3532         (goto-char (point-min))
3533         (while (not (eobp))
3534           (ignore-errors
3535             (setq article (read (current-buffer))
3536                   header (gnus-nov-parse-line article dependencies)))
3537           (when header
3538             (save-excursion
3539               (set-buffer gnus-summary-buffer)
3540               (push header gnus-newsgroup-headers)
3541               (if (memq (setq article (mail-header-number header))
3542                         gnus-newsgroup-unselected)
3543                   (progn
3544                     (push article gnus-newsgroup-unreads)
3545                     (setq gnus-newsgroup-unselected
3546                           (delq article gnus-newsgroup-unselected)))
3547                 (push article gnus-newsgroup-ancient)))
3548             (forward-line 1)))))))
3549
3550 (defun gnus-summary-update-article-line (article header)
3551   "Update the line for ARTICLE using HEADERS."
3552   (let* ((id (mail-header-id header))
3553          (thread (gnus-id-to-thread id)))
3554     (unless thread
3555       (error "Article in no thread"))
3556     ;; Update the thread.
3557     (setcar thread header)
3558     (gnus-summary-goto-subject article)
3559     (let* ((datal (gnus-data-find-list article))
3560            (data (car datal))
3561            (length (when (cdr datal)
3562                      (- (gnus-data-pos data)
3563                         (gnus-data-pos (cadr datal)))))
3564            (buffer-read-only nil)
3565            (level (gnus-summary-thread-level)))
3566       (gnus-delete-line)
3567       (gnus-summary-insert-line
3568        header level nil (gnus-article-mark article)
3569        (memq article gnus-newsgroup-replied)
3570        (memq article gnus-newsgroup-expirable)
3571        ;; Only insert the Subject string when it's different
3572        ;; from the previous Subject string.
3573        (if (and
3574             gnus-show-threads
3575             (gnus-subject-equal
3576              (condition-case ()
3577                  (mail-header-subject
3578                   (gnus-data-header
3579                    (cadr
3580                     (gnus-data-find-list
3581                      article
3582                      (gnus-data-list t)))))
3583                ;; Error on the side of excessive subjects.
3584                (error ""))
3585              (mail-header-subject header)))
3586            ""
3587          (mail-header-subject header))
3588        nil (cdr (assq article gnus-newsgroup-scored))
3589        (memq article gnus-newsgroup-processable))
3590       (when length
3591         (gnus-data-update-list
3592          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3593
3594 (defun gnus-summary-update-article (article &optional iheader)
3595   "Update ARTICLE in the summary buffer."
3596   (set-buffer gnus-summary-buffer)
3597   (let* ((header (gnus-summary-article-header article))
3598          (id (mail-header-id header))
3599          (data (gnus-data-find article))
3600          (thread (gnus-id-to-thread id))
3601          (references (mail-header-references header))
3602          (parent
3603           (gnus-id-to-thread
3604            (or (gnus-parent-id
3605                 (when (and references
3606                            (not (equal "" references)))
3607                   references))
3608                "none")))
3609          (buffer-read-only nil)
3610          (old (car thread)))
3611     (when thread
3612       (unless iheader
3613         (setcar thread nil)
3614         (when parent
3615           (delq thread parent)))
3616       (if (gnus-summary-insert-subject id header)
3617           ;; Set the (possibly) new article number in the data structure.
3618           (gnus-data-set-number data (gnus-id-to-article id))
3619         (setcar thread old)
3620         nil))))
3621
3622 (defun gnus-rebuild-thread (id &optional line)
3623   "Rebuild the thread containing ID.
3624 If LINE, insert the rebuilt thread starting on line LINE."
3625   (let ((buffer-read-only nil)
3626         old-pos current thread data)
3627     (if (not gnus-show-threads)
3628         (setq thread (list (car (gnus-id-to-thread id))))
3629       ;; Get the thread this article is part of.
3630       (setq thread (gnus-remove-thread id)))
3631     (setq old-pos (gnus-point-at-bol))
3632     (setq current (save-excursion
3633                     (and (zerop (forward-line -1))
3634                          (gnus-summary-article-number))))
3635     ;; If this is a gathered thread, we have to go some re-gathering.
3636     (when (stringp (car thread))
3637       (let ((subject (car thread))
3638             roots thr)
3639         (setq thread (cdr thread))
3640         (while thread
3641           (unless (memq (setq thr (gnus-id-to-thread
3642                                    (gnus-root-id
3643                                     (mail-header-id (caar thread)))))
3644                         roots)
3645             (push thr roots))
3646           (setq thread (cdr thread)))
3647         ;; We now have all (unique) roots.
3648         (if (= (length roots) 1)
3649             ;; All the loose roots are now one solid root.
3650             (setq thread (car roots))
3651           (setq thread (cons subject (gnus-sort-threads roots))))))
3652     (let (threads)
3653       ;; We then insert this thread into the summary buffer.
3654       (when line
3655         (goto-char (point-min))
3656         (forward-line (1- line)))
3657       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3658         (if gnus-show-threads
3659             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3660           (gnus-summary-prepare-unthreaded thread))
3661         (setq data (nreverse gnus-newsgroup-data))
3662         (setq threads gnus-newsgroup-threads))
3663       ;; We splice the new data into the data structure.
3664       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3665       ;;!!! then we want to insert at the beginning of the buffer.
3666       ;;!!! That happens to be true with Gnus now, but that may
3667       ;;!!! change in the future.  Perhaps.
3668       (gnus-data-enter-list
3669        (if line nil current) data (- (point) old-pos))
3670       (setq gnus-newsgroup-threads
3671             (nconc threads gnus-newsgroup-threads))
3672       (gnus-data-compute-positions))))
3673
3674 (defun gnus-number-to-header (number)
3675   "Return the header for article NUMBER."
3676   (let ((headers gnus-newsgroup-headers))
3677     (while (and headers
3678                 (not (= number (mail-header-number (car headers)))))
3679       (pop headers))
3680     (when headers
3681       (car headers))))
3682
3683 (defun gnus-parent-headers (in-headers &optional generation)
3684   "Return the headers of the GENERATIONeth parent of HEADERS."
3685   (unless generation
3686     (setq generation 1))
3687   (let ((parent t)
3688         (headers in-headers)
3689         references)
3690     (while (and parent
3691                 (not (zerop generation))
3692                 (setq references (mail-header-references headers)))
3693       (setq headers (if (and references
3694                              (setq parent (gnus-parent-id references)))
3695                         (car (gnus-id-to-thread parent))
3696                       nil))
3697       (decf generation))
3698     (and (not (eq headers in-headers))
3699          headers)))
3700
3701 (defun gnus-id-to-thread (id)
3702   "Return the (sub-)thread where ID appears."
3703   (gnus-gethash id gnus-newsgroup-dependencies))
3704
3705 (defun gnus-id-to-article (id)
3706   "Return the article number of ID."
3707   (let ((thread (gnus-id-to-thread id)))
3708     (when (and thread
3709                (car thread))
3710       (mail-header-number (car thread)))))
3711
3712 (defun gnus-id-to-header (id)
3713   "Return the article headers of ID."
3714   (car (gnus-id-to-thread id)))
3715
3716 (defun gnus-article-displayed-root-p (article)
3717   "Say whether ARTICLE is a root(ish) article."
3718   (let ((level (gnus-summary-thread-level article))
3719         (refs (mail-header-references  (gnus-summary-article-header article)))
3720         particle)
3721     (cond
3722      ((null level) nil)
3723      ((zerop level) t)
3724      ((null refs) t)
3725      ((null (gnus-parent-id refs)) t)
3726      ((and (= 1 level)
3727            (null (setq particle (gnus-id-to-article
3728                                  (gnus-parent-id refs))))
3729            (null (gnus-summary-thread-level particle)))))))
3730
3731 (defun gnus-root-id (id)
3732   "Return the id of the root of the thread where ID appears."
3733   (let (last-id prev)
3734     (while (and id (setq prev (car (gnus-id-to-thread id))))
3735       (setq last-id id
3736             id (gnus-parent-id (mail-header-references prev))))
3737     last-id))
3738
3739 (defun gnus-articles-in-thread (thread)
3740   "Return the list of articles in THREAD."
3741   (cons (mail-header-number (car thread))
3742         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3743
3744 (defun gnus-remove-thread (id &optional dont-remove)
3745   "Remove the thread that has ID in it."
3746   (let (headers thread last-id)
3747     ;; First go up in this thread until we find the root.
3748     (setq last-id (gnus-root-id id)
3749           headers (message-flatten-list (gnus-id-to-thread last-id)))
3750     ;; We have now found the real root of this thread.  It might have
3751     ;; been gathered into some loose thread, so we have to search
3752     ;; through the threads to find the thread we wanted.
3753     (let ((threads gnus-newsgroup-threads)
3754           sub)
3755       (while threads
3756         (setq sub (car threads))
3757         (if (stringp (car sub))
3758             ;; This is a gathered thread, so we look at the roots
3759             ;; below it to find whether this article is in this
3760             ;; gathered root.
3761             (progn
3762               (setq sub (cdr sub))
3763               (while sub
3764                 (when (member (caar sub) headers)
3765                   (setq thread (car threads)
3766                         threads nil
3767                         sub nil))
3768                 (setq sub (cdr sub))))
3769           ;; It's an ordinary thread, so we check it.
3770           (when (eq (car sub) (car headers))
3771             (setq thread sub
3772                   threads nil)))
3773         (setq threads (cdr threads)))
3774       ;; If this article is in no thread, then it's a root.
3775       (if thread
3776           (unless dont-remove
3777             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3778         (setq thread (gnus-id-to-thread last-id)))
3779       (when thread
3780         (prog1
3781             thread                      ; We return this thread.
3782           (unless dont-remove
3783             (if (stringp (car thread))
3784                 (progn
3785                   ;; If we use dummy roots, then we have to remove the
3786                   ;; dummy root as well.
3787                   (when (eq gnus-summary-make-false-root 'dummy)
3788                     ;; We go to the dummy root by going to
3789                     ;; the first sub-"thread", and then one line up.
3790                     (gnus-summary-goto-article
3791                      (mail-header-number (caadr thread)))
3792                     (forward-line -1)
3793                     (gnus-delete-line)
3794                     (gnus-data-compute-positions))
3795                   (setq thread (cdr thread))
3796                   (while thread
3797                     (gnus-remove-thread-1 (car thread))
3798                     (setq thread (cdr thread))))
3799               (gnus-remove-thread-1 thread))))))))
3800
3801 (defun gnus-remove-thread-1 (thread)
3802   "Remove the thread THREAD recursively."
3803   (let ((number (mail-header-number (pop thread)))
3804         d)
3805     (setq thread (reverse thread))
3806     (while thread
3807       (gnus-remove-thread-1 (pop thread)))
3808     (when (setq d (gnus-data-find number))
3809       (goto-char (gnus-data-pos d))
3810       (gnus-summary-show-thread)
3811       (gnus-data-remove
3812        number
3813        (- (gnus-point-at-bol)
3814           (prog1
3815               (1+ (gnus-point-at-eol))
3816             (gnus-delete-line)))))))
3817
3818 (defun gnus-sort-threads-1 (threads func)
3819   (sort (mapcar (lambda (thread)
3820                   (cons (car thread)
3821                         (and (cdr thread)
3822                              (gnus-sort-threads-1 (cdr thread) func))))
3823                 threads) func))
3824
3825 (defun gnus-sort-threads (threads)
3826   "Sort THREADS."
3827   (if (not gnus-thread-sort-functions)
3828       threads
3829     (gnus-message 8 "Sorting threads...")
3830     (prog1
3831         (gnus-sort-threads-1 
3832          threads 
3833          (gnus-make-sort-function gnus-thread-sort-functions))
3834       (gnus-message 8 "Sorting threads...done"))))
3835
3836 (defun gnus-sort-articles (articles)
3837   "Sort ARTICLES."
3838   (when gnus-article-sort-functions
3839     (gnus-message 7 "Sorting articles...")
3840     (prog1
3841         (setq gnus-newsgroup-headers
3842               (sort articles (gnus-make-sort-function
3843                               gnus-article-sort-functions)))
3844       (gnus-message 7 "Sorting articles...done"))))
3845
3846 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3847 (defmacro gnus-thread-header (thread)
3848   "Return header of first article in THREAD.
3849 Note that THREAD must never, ever be anything else than a variable -
3850 using some other form will lead to serious barfage."
3851   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3852   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3853   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
3854         (vector thread) 2))
3855
3856 (defsubst gnus-article-sort-by-number (h1 h2)
3857   "Sort articles by article number."
3858   (< (mail-header-number h1)
3859      (mail-header-number h2)))
3860
3861 (defun gnus-thread-sort-by-number (h1 h2)
3862   "Sort threads by root article number."
3863   (gnus-article-sort-by-number
3864    (gnus-thread-header h1) (gnus-thread-header h2)))
3865
3866 (defsubst gnus-article-sort-by-lines (h1 h2)
3867   "Sort articles by article Lines header."
3868   (< (mail-header-lines h1)
3869      (mail-header-lines h2)))
3870
3871 (defun gnus-thread-sort-by-lines (h1 h2)
3872   "Sort threads by root article Lines header."
3873   (gnus-article-sort-by-lines
3874    (gnus-thread-header h1) (gnus-thread-header h2)))
3875
3876 (defsubst gnus-article-sort-by-chars (h1 h2)
3877   "Sort articles by octet length."
3878   (< (mail-header-chars h1)
3879      (mail-header-chars h2)))
3880
3881 (defun gnus-thread-sort-by-chars (h1 h2)
3882   "Sort threads by root article octet length."
3883   (gnus-article-sort-by-chars
3884    (gnus-thread-header h1) (gnus-thread-header h2)))
3885
3886 (defsubst gnus-article-sort-by-author (h1 h2)
3887   "Sort articles by root author."
3888   (string-lessp
3889    (let ((addr (car (mime-entity-read-field h1 'From))))
3890      (or (std11-full-name-string addr)
3891          (std11-address-string addr)
3892          ""))
3893    (let ((addr (car (mime-entity-read-field h2 'From))))
3894      (or (std11-full-name-string addr)
3895          (std11-address-string addr)
3896          ""))
3897    ))
3898
3899 (defun gnus-thread-sort-by-author (h1 h2)
3900   "Sort threads by root author."
3901   (gnus-article-sort-by-author
3902    (gnus-thread-header h1)  (gnus-thread-header h2)))
3903
3904 (defsubst gnus-article-sort-by-subject (h1 h2)
3905   "Sort articles by root subject."
3906   (string-lessp
3907    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3908    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3909
3910 (defun gnus-thread-sort-by-subject (h1 h2)
3911   "Sort threads by root subject."
3912   (gnus-article-sort-by-subject
3913    (gnus-thread-header h1) (gnus-thread-header h2)))
3914
3915 (defsubst gnus-article-sort-by-date (h1 h2)
3916   "Sort articles by root article date."
3917   (time-less-p
3918    (gnus-date-get-time (mail-header-date h1))
3919    (gnus-date-get-time (mail-header-date h2))))
3920
3921 (defun gnus-thread-sort-by-date (h1 h2)
3922   "Sort threads by root article date."
3923   (gnus-article-sort-by-date
3924    (gnus-thread-header h1) (gnus-thread-header h2)))
3925
3926 (defsubst gnus-article-sort-by-score (h1 h2)
3927   "Sort articles by root article score.
3928 Unscored articles will be counted as having a score of zero."
3929   (> (or (cdr (assq (mail-header-number h1)
3930                     gnus-newsgroup-scored))
3931          gnus-summary-default-score 0)
3932      (or (cdr (assq (mail-header-number h2)
3933                     gnus-newsgroup-scored))
3934          gnus-summary-default-score 0)))
3935
3936 (defun gnus-thread-sort-by-score (h1 h2)
3937   "Sort threads by root article score."
3938   (gnus-article-sort-by-score
3939    (gnus-thread-header h1) (gnus-thread-header h2)))
3940
3941 (defun gnus-thread-sort-by-total-score (h1 h2)
3942   "Sort threads by the sum of all scores in the thread.
3943 Unscored articles will be counted as having a score of zero."
3944   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3945
3946 (defun gnus-thread-total-score (thread)
3947   ;; This function find the total score of THREAD.
3948   (cond ((null thread)
3949          0)
3950         ((consp thread)
3951          (if (stringp (car thread))
3952              (apply gnus-thread-score-function 0
3953                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3954            (gnus-thread-total-score-1 thread)))
3955         (t
3956          (gnus-thread-total-score-1 (list thread)))))
3957
3958 (defun gnus-thread-total-score-1 (root)
3959   ;; This function find the total score of the thread below ROOT.
3960   (setq root (car root))
3961   (apply gnus-thread-score-function
3962          (or (append
3963               (mapcar 'gnus-thread-total-score
3964                       (cdr (gnus-id-to-thread (mail-header-id root))))
3965               (when (> (mail-header-number root) 0)
3966                 (list (or (cdr (assq (mail-header-number root)
3967                                      gnus-newsgroup-scored))
3968                           gnus-summary-default-score 0))))
3969              (list gnus-summary-default-score)
3970              '(0))))
3971
3972 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
3973 (defvar gnus-tmp-prev-subject nil)
3974 (defvar gnus-tmp-false-parent nil)
3975 (defvar gnus-tmp-root-expunged nil)
3976 (defvar gnus-tmp-dummy-line nil)
3977
3978 (eval-when-compile (defvar gnus-tmp-header))
3979 (defun gnus-extra-header (type &optional header)
3980   "Return the extra header of TYPE."
3981   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
3982       ""))
3983
3984 (defun gnus-summary-prepare-threads (threads)
3985   "Prepare summary buffer from THREADS and indentation LEVEL.
3986 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
3987 or a straight list of headers."
3988   (gnus-message 7 "Generating summary...")
3989
3990   (setq gnus-newsgroup-threads threads)
3991   (beginning-of-line)
3992
3993   (let ((gnus-tmp-level 0)
3994         (default-score (or gnus-summary-default-score 0))
3995         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
3996         thread number subject stack state gnus-tmp-gathered beg-match
3997         new-roots gnus-tmp-new-adopts thread-end
3998         gnus-tmp-header gnus-tmp-unread
3999         gnus-tmp-replied gnus-tmp-subject-or-nil
4000         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4001         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4002         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
4003
4004     (setq gnus-tmp-prev-subject nil)
4005
4006     (if (vectorp (car threads))
4007         ;; If this is a straight (sic) list of headers, then a
4008         ;; threaded summary display isn't required, so we just create
4009         ;; an unthreaded one.
4010         (gnus-summary-prepare-unthreaded threads)
4011
4012       ;; Do the threaded display.
4013
4014       (while (or threads stack gnus-tmp-new-adopts new-roots)
4015
4016         (if (and (= gnus-tmp-level 0)
4017                  (or (not stack)
4018                      (= (caar stack) 0))
4019                  (not gnus-tmp-false-parent)
4020                  (or gnus-tmp-new-adopts new-roots))
4021             (if gnus-tmp-new-adopts
4022                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4023                       thread (list (car gnus-tmp-new-adopts))
4024                       gnus-tmp-header (caar thread)
4025                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4026               (when new-roots
4027                 (setq thread (list (car new-roots))
4028                       gnus-tmp-header (caar thread)
4029                       new-roots (cdr new-roots))))
4030
4031           (if threads
4032               ;; If there are some threads, we do them before the
4033               ;; threads on the stack.
4034               (setq thread threads
4035                     gnus-tmp-header (caar thread))
4036             ;; There were no current threads, so we pop something off
4037             ;; the stack.
4038             (setq state (car stack)
4039                   gnus-tmp-level (car state)
4040                   thread (cdr state)
4041                   stack (cdr stack)
4042                   gnus-tmp-header (caar thread))))
4043
4044         (setq gnus-tmp-false-parent nil)
4045         (setq gnus-tmp-root-expunged nil)
4046         (setq thread-end nil)
4047
4048         (if (stringp gnus-tmp-header)
4049             ;; The header is a dummy root.
4050             (cond
4051              ((eq gnus-summary-make-false-root 'adopt)
4052               ;; We let the first article adopt the rest.
4053               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4054                                                (cddar thread)))
4055               (setq gnus-tmp-gathered
4056                     (nconc (mapcar
4057                             (lambda (h) (mail-header-number (car h)))
4058                             (cddar thread))
4059                            gnus-tmp-gathered))
4060               (setq thread (cons (list (caar thread)
4061                                        (cadar thread))
4062                                  (cdr thread)))
4063               (setq gnus-tmp-level -1
4064                     gnus-tmp-false-parent t))
4065              ((eq gnus-summary-make-false-root 'empty)
4066               ;; We print adopted articles with empty subject fields.
4067               (setq gnus-tmp-gathered
4068                     (nconc (mapcar
4069                             (lambda (h) (mail-header-number (car h)))
4070                             (cddar thread))
4071                            gnus-tmp-gathered))
4072               (setq gnus-tmp-level -1))
4073              ((eq gnus-summary-make-false-root 'dummy)
4074               ;; We remember that we probably want to output a dummy
4075               ;; root.
4076               (setq gnus-tmp-dummy-line gnus-tmp-header)
4077               (setq gnus-tmp-prev-subject gnus-tmp-header))
4078              (t
4079               ;; We do not make a root for the gathered
4080               ;; sub-threads at all.
4081               (setq gnus-tmp-level -1)))
4082
4083           (setq number (mail-header-number gnus-tmp-header)
4084                 subject (mail-header-subject gnus-tmp-header))
4085
4086           (cond
4087            ;; If the thread has changed subject, we might want to make
4088            ;; this subthread into a root.
4089            ((and (null gnus-thread-ignore-subject)
4090                  (not (zerop gnus-tmp-level))
4091                  gnus-tmp-prev-subject
4092                  (not (inline
4093                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4094             (setq new-roots (nconc new-roots (list (car thread)))
4095                   thread-end t
4096                   gnus-tmp-header nil))
4097            ;; If the article lies outside the current limit,
4098            ;; then we do not display it.
4099            ((not (memq number gnus-newsgroup-limit))
4100             (setq gnus-tmp-gathered
4101                   (nconc (mapcar
4102                           (lambda (h) (mail-header-number (car h)))
4103                           (cdar thread))
4104                          gnus-tmp-gathered))
4105             (setq gnus-tmp-new-adopts (if (cdar thread)
4106                                           (append gnus-tmp-new-adopts
4107                                                   (cdar thread))
4108                                         gnus-tmp-new-adopts)
4109                   thread-end t
4110                   gnus-tmp-header nil)
4111             (when (zerop gnus-tmp-level)
4112               (setq gnus-tmp-root-expunged t)))
4113            ;; Perhaps this article is to be marked as read?
4114            ((and gnus-summary-mark-below
4115                  (< (or (cdr (assq number gnus-newsgroup-scored))
4116                         default-score)
4117                     gnus-summary-mark-below)
4118                  ;; Don't touch sparse articles.
4119                  (not (gnus-summary-article-sparse-p number))
4120                  (not (gnus-summary-article-ancient-p number)))
4121             (setq gnus-newsgroup-unreads
4122                   (delq number gnus-newsgroup-unreads))
4123             (if gnus-newsgroup-auto-expire
4124                 (push number gnus-newsgroup-expirable)
4125               (push (cons number gnus-low-score-mark)
4126                     gnus-newsgroup-reads))))
4127
4128           (when gnus-tmp-header
4129             ;; We may have an old dummy line to output before this
4130             ;; article.
4131             (when (and gnus-tmp-dummy-line
4132                        (gnus-subject-equal
4133                         gnus-tmp-dummy-line
4134                         (mail-header-subject gnus-tmp-header)))
4135               (gnus-summary-insert-dummy-line
4136                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4137               (setq gnus-tmp-dummy-line nil))
4138
4139             ;; Compute the mark.
4140             (setq gnus-tmp-unread (gnus-article-mark number))
4141
4142             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4143                                   gnus-tmp-header gnus-tmp-level)
4144                   gnus-newsgroup-data)
4145
4146             ;; Actually insert the line.
4147             (setq
4148              gnus-tmp-subject-or-nil
4149              (cond
4150               ((and gnus-thread-ignore-subject
4151                     gnus-tmp-prev-subject
4152                     (not (inline (gnus-subject-equal
4153                                   gnus-tmp-prev-subject subject))))
4154                subject)
4155               ((zerop gnus-tmp-level)
4156                (if (and (eq gnus-summary-make-false-root 'empty)
4157                         (memq number gnus-tmp-gathered)
4158                         gnus-tmp-prev-subject
4159                         (inline (gnus-subject-equal
4160                                  gnus-tmp-prev-subject subject)))
4161                    gnus-summary-same-subject
4162                  subject))
4163               (t gnus-summary-same-subject)))
4164             (if (and (eq gnus-summary-make-false-root 'adopt)
4165                      (= gnus-tmp-level 1)
4166                      (memq number gnus-tmp-gathered))
4167                 (setq gnus-tmp-opening-bracket ?\<
4168                       gnus-tmp-closing-bracket ?\>)
4169               (setq gnus-tmp-opening-bracket ?\[
4170                     gnus-tmp-closing-bracket ?\]))
4171             (setq
4172              gnus-tmp-indentation
4173              (aref gnus-thread-indent-array gnus-tmp-level)
4174              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4175              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4176                                 gnus-summary-default-score 0)
4177              gnus-tmp-score-char
4178              (if (or (null gnus-summary-default-score)
4179                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4180                          gnus-summary-zcore-fuzz))
4181                  ?  ;Whitespace
4182                (if (< gnus-tmp-score gnus-summary-default-score)
4183                    gnus-score-below-mark gnus-score-over-mark))
4184              gnus-tmp-replied
4185              (cond ((memq number gnus-newsgroup-processable)
4186                     gnus-process-mark)
4187                    ((memq number gnus-newsgroup-cached)
4188                     gnus-cached-mark)
4189                    ((memq number gnus-newsgroup-replied)
4190                     gnus-replied-mark)
4191                    ((memq number gnus-newsgroup-saved)
4192                     gnus-saved-mark)
4193                    (t gnus-unread-mark))
4194              gnus-tmp-from (mail-header-from gnus-tmp-header)
4195              gnus-tmp-name
4196              (cond
4197               ((string-match "<[^>]+> *$" gnus-tmp-from)
4198                (setq beg-match (match-beginning 0))
4199                (or (and (string-match "^\".+\"" gnus-tmp-from)
4200                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4201                    (substring gnus-tmp-from 0 beg-match)))
4202               ((string-match "(.+)" gnus-tmp-from)
4203                (substring gnus-tmp-from
4204                           (1+ (match-beginning 0)) (1- (match-end 0))))
4205               (t gnus-tmp-from)))
4206             (when (string= gnus-tmp-name "")
4207               (setq gnus-tmp-name gnus-tmp-from))
4208             (unless (numberp gnus-tmp-lines)
4209               (setq gnus-tmp-lines 0))
4210             (gnus-put-text-property
4211              (point)
4212              (progn (eval gnus-summary-line-format-spec) (point))
4213              'gnus-number number)
4214             (when gnus-visual-p
4215               (forward-line -1)
4216               (gnus-run-hooks 'gnus-summary-update-hook)
4217               (forward-line 1))
4218
4219             (setq gnus-tmp-prev-subject subject)))
4220
4221         (when (nth 1 thread)
4222           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
4223         (incf gnus-tmp-level)
4224         (setq threads (if thread-end nil (cdar thread)))
4225         (unless threads
4226           (setq gnus-tmp-level 0)))))
4227   (gnus-message 7 "Generating summary...done"))
4228
4229 (defun gnus-summary-prepare-unthreaded (headers)
4230   "Generate an unthreaded summary buffer based on HEADERS."
4231   (let (header number mark)
4232
4233     (beginning-of-line)
4234
4235     (while headers
4236       ;; We may have to root out some bad articles...
4237       (when (memq (setq number (mail-header-number
4238                                 (setq header (pop headers))))
4239                   gnus-newsgroup-limit)
4240         ;; Mark article as read when it has a low score.
4241         (when (and gnus-summary-mark-below
4242                    (< (or (cdr (assq number gnus-newsgroup-scored))
4243                           gnus-summary-default-score 0)
4244                       gnus-summary-mark-below)
4245                    (not (gnus-summary-article-ancient-p number)))
4246           (setq gnus-newsgroup-unreads
4247                 (delq number gnus-newsgroup-unreads))
4248           (if gnus-newsgroup-auto-expire
4249               (push number gnus-newsgroup-expirable)
4250             (push (cons number gnus-low-score-mark)
4251                   gnus-newsgroup-reads)))
4252
4253         (setq mark (gnus-article-mark number))
4254         (push (gnus-data-make number mark (1+ (point)) header 0)
4255               gnus-newsgroup-data)
4256         (gnus-summary-insert-line
4257          header 0 number
4258          mark (memq number gnus-newsgroup-replied)
4259          (memq number gnus-newsgroup-expirable)
4260          (mail-header-subject header) nil
4261          (cdr (assq number gnus-newsgroup-scored))
4262          (memq number gnus-newsgroup-processable))))))
4263
4264 (defun gnus-summary-remove-list-identifiers ()
4265   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4266   (let ((regexp (if (stringp gnus-list-identifiers)
4267                     gnus-list-identifiers
4268                   (mapconcat 'identity gnus-list-identifiers " *\\|"))))
4269     (dolist (header gnus-newsgroup-headers)
4270       (when (string-match (concat "\\(\\(\\(Re: +\\)?\\(" regexp
4271                                   " *\\)\\)+\\(Re: +\\)?\\)")
4272                           (mail-header-subject header))
4273         (mail-header-set-subject
4274          header (concat (substring (mail-header-subject header)
4275                                    0 (match-beginning 1))
4276                         (or
4277                          (match-string 3 (mail-header-subject header))
4278                          (match-string 5 (mail-header-subject header)))
4279                         (substring (mail-header-subject header)
4280                                    (match-end 1))))))))
4281
4282 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4283   "Select newsgroup GROUP.
4284 If READ-ALL is non-nil, all articles in the group are selected.
4285 If SELECT-ARTICLES, only select those articles from GROUP."
4286   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4287          ;;!!! Dirty hack; should be removed.
4288          (gnus-summary-ignore-duplicates
4289           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4290               t
4291             gnus-summary-ignore-duplicates))
4292          (info (nth 2 entry))
4293          articles fetched-articles cached)
4294
4295     (unless (gnus-check-server
4296              (setq gnus-current-select-method
4297                    (gnus-find-method-for-group group)))
4298       (error "Couldn't open server"))
4299
4300     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4301         (gnus-activate-group group)     ; Or we can activate it...
4302         (progn                          ; Or we bug out.
4303           (when (equal major-mode 'gnus-summary-mode)
4304             (kill-buffer (current-buffer)))
4305           (error "Couldn't activate group %s: %s"
4306                  group (gnus-status-message group))))
4307
4308     (unless (gnus-request-group group t)
4309       (when (equal major-mode 'gnus-summary-mode)
4310         (kill-buffer (current-buffer)))
4311       (error "Couldn't request group %s: %s"
4312              group (gnus-status-message group)))
4313
4314     (setq gnus-newsgroup-name group)
4315     (setq gnus-newsgroup-unselected nil)
4316     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4317     (gnus-summary-setup-default-charset)
4318
4319     ;; Adjust and set lists of article marks.
4320     (when info
4321       (gnus-adjust-marked-articles info))
4322
4323     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4324     (setq cached
4325           (if (gnus-virtual-group-p group)
4326               gnus-newsgroup-cached
4327             (gnus-cache-articles-in-group group)))
4328
4329     (setq gnus-newsgroup-unreads
4330           (gnus-set-difference
4331            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4332            gnus-newsgroup-dormant))
4333
4334     (setq gnus-newsgroup-processable nil)
4335
4336     (gnus-update-read-articles group gnus-newsgroup-unreads)
4337
4338     (if (setq articles select-articles)
4339         (setq gnus-newsgroup-unselected
4340               (gnus-sorted-intersection
4341                gnus-newsgroup-unreads
4342                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4343       (setq articles (gnus-articles-to-read group read-all)))
4344
4345     (cond
4346      ((null articles)
4347       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4348       'quit)
4349      ((eq articles 0) nil)
4350      (t
4351       ;; Init the dependencies hash table.
4352       (setq gnus-newsgroup-dependencies
4353             (gnus-make-hashtable (length articles)))
4354       (gnus-set-global-variables)
4355       ;; Retrieve the headers and read them in.
4356       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
4357       (setq gnus-newsgroup-headers
4358             (gnus-retrieve-parsed-headers
4359              articles gnus-newsgroup-name
4360              ;; We might want to fetch old headers, but
4361              ;; not if there is only 1 article.
4362              (and (or (and (not (eq gnus-fetch-old-headers 'some))
4363                            (not (numberp gnus-fetch-old-headers)))
4364                       (> (length articles) 1))
4365                   gnus-fetch-old-headers)))
4366       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name)
4367
4368       ;; Suppress duplicates?
4369       (when gnus-suppress-duplicates
4370         (gnus-dup-suppress-articles))
4371
4372       ;; Set the initial limit.
4373       (setq gnus-newsgroup-limit (copy-sequence articles))
4374       ;; Remove canceled articles from the list of unread articles.
4375       (setq gnus-newsgroup-unreads
4376             (gnus-set-sorted-intersection
4377              gnus-newsgroup-unreads
4378              (setq fetched-articles
4379                    (mapcar (lambda (headers) (mail-header-number headers))
4380                            gnus-newsgroup-headers))))
4381       ;; Removed marked articles that do not exist.
4382       (gnus-update-missing-marks
4383        (gnus-sorted-complement fetched-articles articles))
4384
4385       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4386       (when cached
4387         (setq gnus-newsgroup-cached cached))
4388
4389       ;; We might want to build some more threads first.
4390       (when (and gnus-fetch-old-headers
4391                  (eq gnus-headers-retrieved-by 'nov))
4392         (if (eq gnus-fetch-old-headers 'invisible)
4393             (gnus-build-all-threads)
4394           (gnus-build-old-threads)))
4395       ;; Let the Gnus agent mark articles as read.
4396       (when gnus-agent
4397         (gnus-agent-get-undownloaded-list))
4398       ;; Remove list identifiers from subject
4399       (when gnus-list-identifiers
4400         (gnus-summary-remove-list-identifiers))
4401       ;; Check whether auto-expire is to be done in this group.
4402       (setq gnus-newsgroup-auto-expire
4403             (gnus-group-auto-expirable-p group))
4404       ;; Set up the article buffer now, if necessary.
4405       (unless gnus-single-article-buffer
4406         (gnus-article-setup-buffer))
4407       ;; First and last article in this newsgroup.
4408       (when gnus-newsgroup-headers
4409         (setq gnus-newsgroup-begin
4410               (mail-header-number (car gnus-newsgroup-headers))
4411               gnus-newsgroup-end
4412               (mail-header-number
4413                (gnus-last-element gnus-newsgroup-headers))))
4414       ;; GROUP is successfully selected.
4415       (or gnus-newsgroup-headers t)))))
4416
4417 (defun gnus-articles-to-read (group &optional read-all)
4418   "Find out what articles the user wants to read."
4419   (let* ((articles
4420           ;; Select all articles if `read-all' is non-nil, or if there
4421           ;; are no unread articles.
4422           (if (or read-all
4423                   (and (zerop (length gnus-newsgroup-marked))
4424                        (zerop (length gnus-newsgroup-unreads)))
4425                   (eq (gnus-group-find-parameter group 'display)
4426                       'all))
4427               (or
4428                (gnus-uncompress-range (gnus-active group))
4429                (gnus-cache-articles-in-group group))
4430             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4431                           (copy-sequence gnus-newsgroup-unreads))
4432                   '<)))
4433          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4434          (scored (length scored-list))
4435          (number (length articles))
4436          (marked (+ (length gnus-newsgroup-marked)
4437                     (length gnus-newsgroup-dormant)))
4438          (select
4439           (cond
4440            ((numberp read-all)
4441             read-all)
4442            (t
4443             (condition-case ()
4444                 (cond
4445                  ((and (or (<= scored marked) (= scored number))
4446                        (natnump gnus-large-newsgroup)
4447                        (> number gnus-large-newsgroup))
4448                   (let* ((cursor-in-echo-area nil)
4449                          (input (read-from-minibuffer
4450                                  (format
4451                                   "How many articles from %s (max %d): "
4452                                   (gnus-limit-string gnus-newsgroup-name 35)
4453                                   number)
4454                                  (cons (number-to-string gnus-large-newsgroup)
4455                                        0))))
4456                     (if (string-match "^[ \t]*$" input)
4457                         number
4458                       input)))
4459                  ((and (> scored marked) (< scored number)
4460                        (> (- scored number) 20))
4461                   (let ((input
4462                          (read-string
4463                           (format "%s %s (%d scored, %d total): "
4464                                   "How many articles from"
4465                                   group scored number))))
4466                     (if (string-match "^[ \t]*$" input)
4467                         number input)))
4468                  (t number))
4469               (quit
4470                (message "Quit getting the articles to read")
4471                nil))))))
4472     (setq select (if (stringp select) (string-to-number select) select))
4473     (if (or (null select) (zerop select))
4474         select
4475       (if (and (not (zerop scored)) (<= (abs select) scored))
4476           (progn
4477             (setq articles (sort scored-list '<))
4478             (setq number (length articles)))
4479         (setq articles (copy-sequence articles)))
4480
4481       (when (< (abs select) number)
4482         (if (< select 0)
4483             ;; Select the N oldest articles.
4484             (setcdr (nthcdr (1- (abs select)) articles) nil)
4485           ;; Select the N most recent articles.
4486           (setq articles (nthcdr (- number select) articles))))
4487       (setq gnus-newsgroup-unselected
4488             (gnus-sorted-intersection
4489              gnus-newsgroup-unreads
4490              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4491       (when gnus-alter-articles-to-read-function
4492         (setq gnus-newsgroup-unreads
4493               (sort
4494                (funcall gnus-alter-articles-to-read-function
4495                         gnus-newsgroup-name gnus-newsgroup-unreads)
4496                '<)))
4497       articles)))
4498
4499 (defun gnus-killed-articles (killed articles)
4500   (let (out)
4501     (while articles
4502       (when (inline (gnus-member-of-range (car articles) killed))
4503         (push (car articles) out))
4504       (setq articles (cdr articles)))
4505     out))
4506
4507 (defun gnus-uncompress-marks (marks)
4508   "Uncompress the mark ranges in MARKS."
4509   (let ((uncompressed '(score bookmark))
4510         out)
4511     (while marks
4512       (if (memq (caar marks) uncompressed)
4513           (push (car marks) out)
4514         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4515       (setq marks (cdr marks)))
4516     out))
4517
4518 (defun gnus-adjust-marked-articles (info)
4519   "Set all article lists and remove all marks that are no longer valid."
4520   (let* ((marked-lists (gnus-info-marks info))
4521          (active (gnus-active (gnus-info-group info)))
4522          (min (car active))
4523          (max (cdr active))
4524          (types gnus-article-mark-lists)
4525          (uncompressed '(score bookmark killed))
4526          marks var articles article mark)
4527
4528     (while marked-lists
4529       (setq marks (pop marked-lists))
4530       (set (setq var (intern (format "gnus-newsgroup-%s"
4531                                      (car (rassq (setq mark (car marks))
4532                                                  types)))))
4533            (if (memq (car marks) uncompressed) (cdr marks)
4534              (gnus-uncompress-range (cdr marks))))
4535
4536       (setq articles (symbol-value var))
4537
4538       ;; All articles have to be subsets of the active articles.
4539       (cond
4540        ;; Adjust "simple" lists.
4541        ((memq mark '(tick dormant expire reply save))
4542         (while articles
4543           (when (or (< (setq article (pop articles)) min) (> article max))
4544             (set var (delq article (symbol-value var))))))
4545        ;; Adjust assocs.
4546        ((memq mark uncompressed)
4547         (when (not (listp (cdr (symbol-value var))))
4548           (set var (list (symbol-value var))))
4549         (when (not (listp (cdr articles)))
4550           (setq articles (list articles)))
4551         (while articles
4552           (when (or (not (consp (setq article (pop articles))))
4553                     (< (car article) min)
4554                     (> (car article) max))
4555             (set var (delq article (symbol-value var))))))))))
4556
4557 (defun gnus-update-missing-marks (missing)
4558   "Go through the list of MISSING articles and remove them from the mark lists."
4559   (when missing
4560     (let ((types gnus-article-mark-lists)
4561           var m)
4562       ;; Go through all types.
4563       (while types
4564         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4565         (when (symbol-value var)
4566           ;; This list has articles.  So we delete all missing articles
4567           ;; from it.
4568           (setq m missing)
4569           (while m
4570             (set var (delq (pop m) (symbol-value var)))))))))
4571
4572 (defun gnus-update-marks ()
4573   "Enter the various lists of marked articles into the newsgroup info list."
4574   (let ((types gnus-article-mark-lists)
4575         (info (gnus-get-info gnus-newsgroup-name))
4576         (uncompressed '(score bookmark killed))
4577         type list newmarked symbol delta-marks)
4578     (when info
4579       ;; Add all marks lists to the list of marks lists.
4580       (while (setq type (pop types))
4581         (setq list (symbol-value
4582                     (setq symbol
4583                           (intern (format "gnus-newsgroup-%s"
4584                                           (car type))))))
4585
4586         (when list
4587           ;; Get rid of the entries of the articles that have the
4588           ;; default score.
4589           (when (and (eq (cdr type) 'score)
4590                      gnus-save-score
4591                      list)
4592             (let* ((arts list)
4593                    (prev (cons nil list))
4594                    (all prev))
4595               (while arts
4596                 (if (or (not (consp (car arts)))
4597                         (= (cdar arts) gnus-summary-default-score))
4598                     (setcdr prev (cdr arts))
4599                   (setq prev arts))
4600                 (setq arts (cdr arts)))
4601               (setq list (cdr all)))))
4602
4603         (unless (memq (cdr type) uncompressed)
4604           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4605
4606         (when (gnus-check-backend-function
4607                'request-set-mark gnus-newsgroup-name)
4608           ;; propagate flags to server, with the following exceptions:
4609           ;; uncompressed:s are not proper flags (they are cons cells)
4610           ;; cache is a internal gnus flag
4611           ;; download are local to one gnus installation (well)
4612           ;; unsend are for nndraft groups only
4613           ;; xxx: generality of this?  this suits nnimap anyway
4614           (unless (memq (cdr type) (append '(cache download unsend)
4615                                            uncompressed))
4616             (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4617                    (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4618                    (add (gnus-remove-from-range
4619                          (gnus-copy-sequence list) old)))
4620               (when add
4621                 (push (list add 'add (list (cdr type))) delta-marks))
4622               (when del
4623                 (push (list del 'del (list (cdr type))) delta-marks)))))
4624
4625         (when list
4626           (push (cons (cdr type) list) newmarked)))
4627
4628       (when delta-marks
4629         (unless (gnus-check-group gnus-newsgroup-name)
4630           (error "Can't open server for %s" gnus-newsgroup-name))
4631         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4632
4633       ;; Enter these new marks into the info of the group.
4634       (if (nthcdr 3 info)
4635           (setcar (nthcdr 3 info) newmarked)
4636         ;; Add the marks lists to the end of the info.
4637         (when newmarked
4638           (setcdr (nthcdr 2 info) (list newmarked))))
4639
4640       ;; Cut off the end of the info if there's nothing else there.
4641       (let ((i 5))
4642         (while (and (> i 2)
4643                     (not (nth i info)))
4644           (when (nthcdr (decf i) info)
4645             (setcdr (nthcdr i info) nil)))))))
4646
4647 (defun gnus-set-mode-line (where)
4648   "Set the mode line of the article or summary buffers.
4649 If WHERE is `summary', the summary mode line format will be used."
4650   ;; Is this mode line one we keep updated?
4651   (when (and (memq where gnus-updated-mode-lines)
4652              (symbol-value
4653               (intern (format "gnus-%s-mode-line-format-spec" where))))
4654     (let (mode-string)
4655       (save-excursion
4656         ;; We evaluate this in the summary buffer since these
4657         ;; variables are buffer-local to that buffer.
4658         (set-buffer gnus-summary-buffer)
4659         ;; We bind all these variables that are used in the `eval' form
4660         ;; below.
4661         (let* ((mformat (symbol-value
4662                          (intern
4663                           (format "gnus-%s-mode-line-format-spec" where))))
4664                (gnus-tmp-group-name (gnus-group-name-decode
4665                                      gnus-newsgroup-name
4666                                      (gnus-group-name-charset
4667                                       nil
4668                                       gnus-newsgroup-name)))
4669                (gnus-tmp-article-number (or gnus-current-article 0))
4670                (gnus-tmp-unread gnus-newsgroup-unreads)
4671                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4672                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4673                (gnus-tmp-unread-and-unselected
4674                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4675                             (zerop gnus-tmp-unselected))
4676                        "")
4677                       ((zerop gnus-tmp-unselected)
4678                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4679                       (t (format "{%d(+%d) more}"
4680                                  gnus-tmp-unread-and-unticked
4681                                  gnus-tmp-unselected))))
4682                (gnus-tmp-subject
4683                 (if (and gnus-current-headers
4684                          (vectorp gnus-current-headers))
4685                     (gnus-mode-string-quote
4686                      (mail-header-subject gnus-current-headers))
4687                   ""))
4688                bufname-length max-len
4689                gnus-tmp-header);; passed as argument to any user-format-funcs
4690           (setq mode-string (eval mformat))
4691           (setq bufname-length (if (string-match "%b" mode-string)
4692                                    (- (length
4693                                        (buffer-name
4694                                         (if (eq where 'summary)
4695                                             nil
4696                                           (get-buffer gnus-article-buffer))))
4697                                       2)
4698                                  0))
4699           (setq max-len (max 4 (if gnus-mode-non-string-length
4700                                    (- (window-width)
4701                                       gnus-mode-non-string-length
4702                                       bufname-length)
4703                                  (length mode-string))))
4704           ;; We might have to chop a bit of the string off...
4705           (when (> (length mode-string) max-len)
4706             (setq mode-string
4707                   (concat (gnus-truncate-string mode-string (- max-len 3))
4708                           "...")))
4709           ;; Pad the mode string a bit.
4710           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4711       ;; Update the mode line.
4712       (setq mode-line-buffer-identification
4713             (gnus-mode-line-buffer-identification (list mode-string)))
4714       (set-buffer-modified-p t))))
4715
4716 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4717   "Go through the HEADERS list and add all Xrefs to a hash table.
4718 The resulting hash table is returned, or nil if no Xrefs were found."
4719   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4720          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4721          (xref-hashtb (gnus-make-hashtable))
4722          start group entry number xrefs header)
4723     (while headers
4724       (setq header (pop headers))
4725       (when (and (setq xrefs (mail-header-xref header))
4726                  (not (memq (setq number (mail-header-number header))
4727                             unreads)))
4728         (setq start 0)
4729         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4730           (setq start (match-end 0))
4731           (setq group (if prefix
4732                           (concat prefix (substring xrefs (match-beginning 1)
4733                                                     (match-end 1)))
4734                         (substring xrefs (match-beginning 1) (match-end 1))))
4735           (setq number
4736                 (string-to-int (substring xrefs (match-beginning 2)
4737                                           (match-end 2))))
4738           (if (setq entry (gnus-gethash group xref-hashtb))
4739               (setcdr entry (cons number (cdr entry)))
4740             (gnus-sethash group (cons number nil) xref-hashtb)))))
4741     (and start xref-hashtb)))
4742
4743 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4744   "Look through all the headers and mark the Xrefs as read."
4745   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4746         name entry info xref-hashtb idlist method nth4)
4747     (save-excursion
4748       (set-buffer gnus-group-buffer)
4749       (when (setq xref-hashtb
4750                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4751         (mapatoms
4752          (lambda (group)
4753            (unless (string= from-newsgroup (setq name (symbol-name group)))
4754              (setq idlist (symbol-value group))
4755              ;; Dead groups are not updated.
4756              (and (prog1
4757                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4758                             info (nth 2 entry))
4759                     (when (stringp (setq nth4 (gnus-info-method info)))
4760                       (setq nth4 (gnus-server-to-method nth4))))
4761                   ;; Only do the xrefs if the group has the same
4762                   ;; select method as the group we have just read.
4763                   (or (gnus-methods-equal-p
4764                        nth4 (gnus-find-method-for-group from-newsgroup))
4765                       virtual
4766                       (equal nth4 (setq method (gnus-find-method-for-group
4767                                                 from-newsgroup)))
4768                       (and (equal (car nth4) (car method))
4769                            (equal (nth 1 nth4) (nth 1 method))))
4770                   gnus-use-cross-reference
4771                   (or (not (eq gnus-use-cross-reference t))
4772                       virtual
4773                       ;; Only do cross-references on subscribed
4774                       ;; groups, if that is what is wanted.
4775                       (<= (gnus-info-level info) gnus-level-subscribed))
4776                   (gnus-group-make-articles-read name idlist))))
4777          xref-hashtb)))))
4778
4779 (defun gnus-compute-read-articles (group articles)
4780   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4781          (info (nth 2 entry))
4782          (active (gnus-active group))
4783          ninfo)
4784     (when entry
4785       ;; First peel off all invalid article numbers.
4786       (when active
4787         (let ((ids articles)
4788               id first)
4789           (while (setq id (pop ids))
4790             (when (and first (> id (cdr active)))
4791               ;; We'll end up in this situation in one particular
4792               ;; obscure situation.  If you re-scan a group and get
4793               ;; a new article that is cross-posted to a different
4794               ;; group that has not been re-scanned, you might get
4795               ;; crossposted article that has a higher number than
4796               ;; Gnus believes possible.  So we re-activate this
4797               ;; group as well.  This might mean doing the
4798               ;; crossposting thingy will *increase* the number
4799               ;; of articles in some groups.  Tsk, tsk.
4800               (setq active (or (gnus-activate-group group) active)))
4801             (when (or (> id (cdr active))
4802                       (< id (car active)))
4803               (setq articles (delq id articles))))))
4804       ;; If the read list is nil, we init it.
4805       (if (and active
4806                (null (gnus-info-read info))
4807                (> (car active) 1))
4808           (setq ninfo (cons 1 (1- (car active))))
4809         (setq ninfo (gnus-info-read info)))
4810       ;; Then we add the read articles to the range.
4811       (gnus-add-to-range
4812        ninfo (setq articles (sort articles '<))))))
4813
4814 (defun gnus-group-make-articles-read (group articles)
4815   "Update the info of GROUP to say that ARTICLES are read."
4816   (let* ((num 0)
4817          (entry (gnus-gethash group gnus-newsrc-hashtb))
4818          (info (nth 2 entry))
4819          (active (gnus-active group))
4820          range)
4821     (when entry
4822       (setq range (gnus-compute-read-articles group articles))
4823       (save-excursion
4824         (set-buffer gnus-group-buffer)
4825         (gnus-undo-register
4826           `(progn
4827              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4828              (gnus-info-set-read ',info ',(gnus-info-read info))
4829              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4830              (gnus-group-update-group ,group t))))
4831       ;; Add the read articles to the range.
4832       (gnus-info-set-read info range)
4833       ;; Then we have to re-compute how many unread
4834       ;; articles there are in this group.
4835       (when active
4836         (cond
4837          ((not range)
4838           (setq num (- (1+ (cdr active)) (car active))))
4839          ((not (listp (cdr range)))
4840           (setq num (- (cdr active) (- (1+ (cdr range))
4841                                        (car range)))))
4842          (t
4843           (while range
4844             (if (numberp (car range))
4845                 (setq num (1+ num))
4846               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4847             (setq range (cdr range)))
4848           (setq num (- (cdr active) num))))
4849         ;; Update the number of unread articles.
4850         (setcar entry num)
4851         ;; Update the group buffer.
4852         (gnus-group-update-group group t)))))
4853
4854 (defvar gnus-newsgroup-none-id 0)
4855
4856 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4857   (let ((cur nntp-server-buffer)
4858         (dependencies
4859          (or dependencies
4860              (save-excursion (set-buffer gnus-summary-buffer)
4861                              gnus-newsgroup-dependencies)))
4862         headers id end ref
4863         (mail-parse-charset gnus-newsgroup-charset)
4864         (mail-parse-ignored-charsets
4865          (save-excursion (condition-case nil
4866                              (set-buffer gnus-summary-buffer)
4867                            (error))
4868                          gnus-newsgroup-ignored-charsets)))
4869     (save-excursion
4870       (set-buffer nntp-server-buffer)
4871       ;; Translate all TAB characters into SPACE characters.
4872       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4873       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4874       (gnus-run-hooks 'gnus-parse-headers-hook)
4875       (let ((case-fold-search t)
4876             in-reply-to header p lines chars ctype)
4877         (goto-char (point-min))
4878         ;; Search to the beginning of the next header.  Error messages
4879         ;; do not begin with 2 or 3.
4880         (while (re-search-forward "^[23][0-9]+ " nil t)
4881           (setq id nil
4882                 ref nil)
4883           ;; This implementation of this function, with nine
4884           ;; search-forwards instead of the one re-search-forward and
4885           ;; a case (which basically was the old function) is actually
4886           ;; about twice as fast, even though it looks messier.  You
4887           ;; can't have everything, I guess.  Speed and elegance
4888           ;; doesn't always go hand in hand.
4889           (setq
4890            header
4891            (make-full-mail-header
4892             ;; Number.
4893             (prog1
4894                 (read cur)
4895               (end-of-line)
4896               (setq p (point))
4897               (narrow-to-region (point)
4898                                 (or (and (search-forward "\n.\n" nil t)
4899                                          (- (point) 2))
4900                                     (point))))
4901             ;; Subject.
4902             (progn
4903               (goto-char p)
4904               (if (search-forward "\nsubject: " nil t)
4905                   (nnheader-header-value)
4906                 "(none)"))
4907             ;; From.
4908             (progn
4909               (goto-char p)
4910               (if (or (search-forward "\nfrom: " nil t)
4911                       (search-forward "\nfrom:" nil t))
4912                   (nnheader-header-value)
4913                 "(nobody)"))
4914             ;; Date.
4915             (progn
4916               (goto-char p)
4917               (if (search-forward "\ndate: " nil t)
4918                   (nnheader-header-value)
4919                 ""))
4920             ;; Message-ID.
4921             (progn
4922               (goto-char p)
4923               (setq id (if (re-search-forward
4924                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4925                            ;; We do it this way to make sure the Message-ID
4926                            ;; is (somewhat) syntactically valid.
4927                            (buffer-substring (match-beginning 1)
4928                                              (match-end 1))
4929                          ;; If there was no message-id, we just fake one
4930                          ;; to make subsequent routines simpler.
4931                          (nnheader-generate-fake-message-id))))
4932             ;; References.
4933             (progn
4934               (goto-char p)
4935               (if (search-forward "\nreferences: " nil t)
4936                   (progn
4937                     (setq end (point))
4938                     (prog1
4939                         (nnheader-header-value)
4940                       (setq ref
4941                             (buffer-substring
4942                              (progn
4943                                ;; (end-of-line)
4944                                (search-backward ">" end t)
4945                                (1+ (point)))
4946                              (progn
4947                                (search-backward "<" end t)
4948                                (point))))))
4949                 ;; Get the references from the in-reply-to header if there
4950                 ;; were no references and the in-reply-to header looks
4951                 ;; promising.
4952                 (if (and (search-forward "\nin-reply-to: " nil t)
4953                          (setq in-reply-to (nnheader-header-value))
4954                          (string-match "<[^>]+>" in-reply-to))
4955                     (let (ref2)
4956                       (setq ref (substring in-reply-to (match-beginning 0)
4957                                            (match-end 0)))
4958                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
4959                         (setq ref2 (substring in-reply-to (match-beginning 0)
4960                                               (match-end 0)))
4961                         (when (> (length ref2) (length ref))
4962                           (setq ref ref2)))
4963                       ref)
4964                   (setq ref nil))))
4965             ;; Chars.
4966             (progn
4967               (goto-char p)
4968               (if (search-forward "\nchars: " nil t)
4969                   (if (numberp (setq chars (ignore-errors (read cur))))
4970                       chars 0)
4971                 0))
4972             ;; Lines.
4973             (progn
4974               (goto-char p)
4975               (if (search-forward "\nlines: " nil t)
4976                   (if (numberp (setq lines (ignore-errors (read cur))))
4977                       lines 0)
4978                 0))
4979             ;; Xref.
4980             (progn
4981               (goto-char p)
4982               (and (search-forward "\nxref: " nil t)
4983                    (nnheader-header-value)))
4984             ;; Extra.
4985             (when gnus-extra-headers
4986               (let ((extra gnus-extra-headers)
4987                     out)
4988                 (while extra
4989                   (goto-char p)
4990                   (when (search-forward
4991                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
4992                     (push (cons (car extra) (nnheader-header-value)) out))
4993                   (pop extra))
4994                 out))))
4995           (goto-char p)
4996           (if (and (search-forward "\ncontent-type: " nil t)
4997                    (setq ctype (nnheader-header-value)))
4998               (mime-entity-set-content-type-internal
4999                header (mime-parse-Content-Type ctype)))
5000           (when (equal id ref)
5001             (setq ref nil))
5002
5003           (when gnus-alter-header-function
5004             (funcall gnus-alter-header-function header)
5005             (setq id (mail-header-id header)
5006                   ref (gnus-parent-id (mail-header-references header))))
5007
5008           (when (setq header
5009                       (gnus-dependencies-add-header
5010                        header dependencies force-new))
5011             (push header headers))
5012           (goto-char (point-max))
5013           (widen))
5014         (nreverse headers)))))
5015
5016 ;; Goes through the xover lines and returns a list of vectors
5017 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5018                                                   force-new dependencies
5019                                                   group also-fetch-heads)
5020   "Parse the news overview data in the server buffer.
5021 Return a list of headers that match SEQUENCE (see
5022 `nntp-retrieve-headers')."
5023   ;; Get the Xref when the users reads the articles since most/some
5024   ;; NNTP servers do not include Xrefs when using XOVER.
5025   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5026   (let ((mail-parse-charset gnus-newsgroup-charset)
5027         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5028         (cur nntp-server-buffer)
5029         (dependencies (or dependencies gnus-newsgroup-dependencies))
5030         number headers header)
5031     (save-excursion
5032       (set-buffer nntp-server-buffer)
5033       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5034       ;; Allow the user to mangle the headers before parsing them.
5035       (gnus-run-hooks 'gnus-parse-headers-hook)
5036       (goto-char (point-min))
5037       (while (not (eobp))
5038         (condition-case ()
5039             (while (and sequence (not (eobp)))
5040               (setq number (read cur))
5041               (while (and sequence
5042                           (< (car sequence) number))
5043                 (setq sequence (cdr sequence)))
5044               (and sequence
5045                    (eq number (car sequence))
5046                    (progn
5047                      (setq sequence (cdr sequence))
5048                      (setq header (inline
5049                                     (gnus-nov-parse-line
5050                                      number dependencies force-new))))
5051                    (push header headers))
5052               (forward-line 1))
5053           (error
5054            (gnus-error 4 "Strange nov line (%d)"
5055                        (count-lines (point-min) (point)))))
5056         (forward-line 1))
5057       ;; A common bug in inn is that if you have posted an article and
5058       ;; then retrieves the active file, it will answer correctly --
5059       ;; the new article is included.  However, a NOV entry for the
5060       ;; article may not have been generated yet, so this may fail.
5061       ;; We work around this problem by retrieving the last few
5062       ;; headers using HEAD.
5063       (if (or (not also-fetch-heads)
5064               (not sequence))
5065           ;; We (probably) got all the headers.
5066           (nreverse headers)
5067         (let ((gnus-nov-is-evil t))
5068           (nconc
5069            (nreverse headers)
5070            (gnus-retrieve-parsed-headers sequence group)
5071            ))))))
5072
5073 (defun gnus-article-get-xrefs ()
5074   "Fill in the Xref value in `gnus-current-headers', if necessary.
5075 This is meant to be called in `gnus-article-internal-prepare-hook'."
5076   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5077                                  gnus-current-headers)))
5078     (or (not gnus-use-cross-reference)
5079         (not headers)
5080         (and (mail-header-xref headers)
5081              (not (string= (mail-header-xref headers) "")))
5082         (let ((case-fold-search t)
5083               xref)
5084           (save-restriction
5085             (nnheader-narrow-to-headers)
5086             (goto-char (point-min))
5087             (when (or (and (not (eobp))
5088                            (eq (downcase (char-after)) ?x)
5089                            (looking-at "Xref:"))
5090                       (search-forward "\nXref:" nil t))
5091               (goto-char (1+ (match-end 0)))
5092               (setq xref (buffer-substring (point)
5093                                            (progn (end-of-line) (point))))
5094               (mail-header-set-xref headers xref)))))))
5095
5096 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5097   "Find article ID and insert the summary line for that article.
5098 OLD-HEADER can either be a header or a line number to insert
5099 the subject line on."
5100   (let* ((line (and (numberp old-header) old-header))
5101          (old-header (and (vectorp old-header) old-header))
5102          (header (cond ((and old-header use-old-header)
5103                         old-header)
5104                        ((and (numberp id)
5105                              (gnus-number-to-header id))
5106                         (gnus-number-to-header id))
5107                        (t
5108                         (gnus-read-header id))))
5109          (number (and (numberp id) id))
5110          d)
5111     (when header
5112       ;; Rebuild the thread that this article is part of and go to the
5113       ;; article we have fetched.
5114       (when (and (not gnus-show-threads)
5115                  old-header)
5116         (when (and number
5117                    (setq d (gnus-data-find (mail-header-number old-header))))
5118           (goto-char (gnus-data-pos d))
5119           (gnus-data-remove
5120            number
5121            (- (gnus-point-at-bol)
5122               (prog1
5123                   (1+ (gnus-point-at-eol))
5124                 (gnus-delete-line))))))
5125       (when old-header
5126         (mail-header-set-number header (mail-header-number old-header)))
5127       (setq gnus-newsgroup-sparse
5128             (delq (setq number (mail-header-number header))
5129                   gnus-newsgroup-sparse))
5130       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5131       (push number gnus-newsgroup-limit)
5132       (gnus-rebuild-thread (mail-header-id header) line)
5133       (gnus-summary-goto-subject number nil t))
5134     (when (and (numberp number)
5135                (> number 0))
5136       ;; We have to update the boundaries even if we can't fetch the
5137       ;; article if ID is a number -- so that the next `P' or `N'
5138       ;; command will fetch the previous (or next) article even
5139       ;; if the one we tried to fetch this time has been canceled.
5140       (when (> number gnus-newsgroup-end)
5141         (setq gnus-newsgroup-end number))
5142       (when (< number gnus-newsgroup-begin)
5143         (setq gnus-newsgroup-begin number))
5144       (setq gnus-newsgroup-unselected
5145             (delq number gnus-newsgroup-unselected)))
5146     ;; Report back a success?
5147     (and header (mail-header-number header))))
5148
5149 ;;; Process/prefix in the summary buffer
5150
5151 (defun gnus-summary-work-articles (n)
5152   "Return a list of articles to be worked upon.
5153 The prefix argument, the list of process marked articles, and the
5154 current article will be taken into consideration."
5155   (save-excursion
5156     (set-buffer gnus-summary-buffer)
5157     (cond
5158      (n
5159       ;; A numerical prefix has been given.
5160       (setq n (prefix-numeric-value n))
5161       (let ((backward (< n 0))
5162             (n (abs (prefix-numeric-value n)))
5163             articles article)
5164         (save-excursion
5165           (while
5166               (and (> n 0)
5167                    (push (setq article (gnus-summary-article-number))
5168                          articles)
5169                    (if backward
5170                        (gnus-summary-find-prev nil article)
5171                      (gnus-summary-find-next nil article)))
5172             (decf n)))
5173         (nreverse articles)))
5174      ((and (gnus-region-active-p) (mark))
5175       (message "region active")
5176       ;; Work on the region between point and mark.
5177       (let ((max (max (point) (mark)))
5178             articles article)
5179         (save-excursion
5180           (goto-char (min (point) (mark)))
5181           (while
5182               (and
5183                (push (setq article (gnus-summary-article-number)) articles)
5184                (gnus-summary-find-next nil article)
5185                (< (point) max)))
5186           (nreverse articles))))
5187      (gnus-newsgroup-processable
5188       ;; There are process-marked articles present.
5189       ;; Save current state.
5190       (gnus-summary-save-process-mark)
5191       ;; Return the list.
5192       (reverse gnus-newsgroup-processable))
5193      (t
5194       ;; Just return the current article.
5195       (list (gnus-summary-article-number))))))
5196
5197 (defmacro gnus-summary-iterate (arg &rest forms)
5198   "Iterate over the process/prefixed articles and do FORMS.
5199 ARG is the interactive prefix given to the command.  FORMS will be
5200 executed with point over the summary line of the articles."
5201   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5202     `(let ((,articles (gnus-summary-work-articles ,arg)))
5203        (while ,articles
5204          (gnus-summary-goto-subject (car ,articles))
5205          ,@forms
5206          (pop ,articles)))))
5207
5208 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5209 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5210
5211 (defun gnus-summary-save-process-mark ()
5212   "Push the current set of process marked articles on the stack."
5213   (interactive)
5214   (push (copy-sequence gnus-newsgroup-processable)
5215         gnus-newsgroup-process-stack))
5216
5217 (defun gnus-summary-kill-process-mark ()
5218   "Push the current set of process marked articles on the stack and unmark."
5219   (interactive)
5220   (gnus-summary-save-process-mark)
5221   (gnus-summary-unmark-all-processable))
5222
5223 (defun gnus-summary-yank-process-mark ()
5224   "Pop the last process mark state off the stack and restore it."
5225   (interactive)
5226   (unless gnus-newsgroup-process-stack
5227     (error "Empty mark stack"))
5228   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5229
5230 (defun gnus-summary-process-mark-set (set)
5231   "Make SET into the current process marked articles."
5232   (gnus-summary-unmark-all-processable)
5233   (while set
5234     (gnus-summary-set-process-mark (pop set))))
5235
5236 ;;; Searching and stuff
5237
5238 (defun gnus-summary-search-group (&optional backward use-level)
5239   "Search for next unread newsgroup.
5240 If optional argument BACKWARD is non-nil, search backward instead."
5241   (save-excursion
5242     (set-buffer gnus-group-buffer)
5243     (when (gnus-group-search-forward
5244            backward nil (if use-level (gnus-group-group-level) nil))
5245       (gnus-group-group-name))))
5246
5247 (defun gnus-summary-best-group (&optional exclude-group)
5248   "Find the name of the best unread group.
5249 If EXCLUDE-GROUP, do not go to this group."
5250   (save-excursion
5251     (set-buffer gnus-group-buffer)
5252     (save-excursion
5253       (gnus-group-best-unread-group exclude-group))))
5254
5255 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5256   (if backward (gnus-summary-find-prev)
5257     (let* ((dummy (gnus-summary-article-intangible-p))
5258            (article (or article (gnus-summary-article-number)))
5259            (arts (gnus-data-find-list article))
5260            result)
5261       (when (and (not dummy)
5262                  (or (not gnus-summary-check-current)
5263                      (not unread)
5264                      (not (gnus-data-unread-p (car arts)))))
5265         (setq arts (cdr arts)))
5266       (when (setq result
5267                   (if unread
5268                       (progn
5269                         (while arts
5270                           (when (or (and undownloaded
5271                                          (eq gnus-undownloaded-mark
5272                                              (gnus-data-mark (car arts))))
5273                                     (gnus-data-unread-p (car arts)))
5274                             (setq result (car arts)
5275                                   arts nil))
5276                           (setq arts (cdr arts)))
5277                         result)
5278                     (car arts)))
5279         (goto-char (gnus-data-pos result))
5280         (gnus-data-number result)))))
5281
5282 (defun gnus-summary-find-prev (&optional unread article)
5283   (let* ((eobp (eobp))
5284          (article (or article (gnus-summary-article-number)))
5285          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5286          result)
5287     (when (and (not eobp)
5288                (or (not gnus-summary-check-current)
5289                    (not unread)
5290                    (not (gnus-data-unread-p (car arts)))))
5291       (setq arts (cdr arts)))
5292     (when (setq result
5293                 (if unread
5294                     (progn
5295                       (while arts
5296                         (when (gnus-data-unread-p (car arts))
5297                           (setq result (car arts)
5298                                 arts nil))
5299                         (setq arts (cdr arts)))
5300                       result)
5301                   (car arts)))
5302       (goto-char (gnus-data-pos result))
5303       (gnus-data-number result))))
5304
5305 (defun gnus-summary-find-subject (subject &optional unread backward article)
5306   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5307          (article (or article (gnus-summary-article-number)))
5308          (articles (gnus-data-list backward))
5309          (arts (gnus-data-find-list article articles))
5310          result)
5311     (when (or (not gnus-summary-check-current)
5312               (not unread)
5313               (not (gnus-data-unread-p (car arts))))
5314       (setq arts (cdr arts)))
5315     (while arts
5316       (and (or (not unread)
5317                (gnus-data-unread-p (car arts)))
5318            (vectorp (gnus-data-header (car arts)))
5319            (gnus-subject-equal
5320             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5321            (setq result (car arts)
5322                  arts nil))
5323       (setq arts (cdr arts)))
5324     (and result
5325          (goto-char (gnus-data-pos result))
5326          (gnus-data-number result))))
5327
5328 (defun gnus-summary-search-forward (&optional unread subject backward)
5329   "Search forward for an article.
5330 If UNREAD, look for unread articles.  If SUBJECT, look for
5331 articles with that subject.  If BACKWARD, search backward instead."
5332   (cond (subject (gnus-summary-find-subject subject unread backward))
5333         (backward (gnus-summary-find-prev unread))
5334         (t (gnus-summary-find-next unread))))
5335
5336 (defun gnus-recenter (&optional n)
5337   "Center point in window and redisplay frame.
5338 Also do horizontal recentering."
5339   (interactive "P")
5340   (when (and gnus-auto-center-summary
5341              (not (eq gnus-auto-center-summary 'vertical)))
5342     (gnus-horizontal-recenter))
5343   (recenter n))
5344
5345 (defun gnus-summary-recenter ()
5346   "Center point in the summary window.
5347 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5348 displayed, no centering will be performed."
5349   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5350   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5351   (interactive)
5352   (let* ((top (cond ((< (window-height) 4) 0)
5353                     ((< (window-height) 7) 1)
5354                     (t (if (numberp gnus-auto-center-summary)
5355                            gnus-auto-center-summary
5356                          2))))
5357          (height (1- (window-height)))
5358          (bottom (save-excursion (goto-char (point-max))
5359                                  (forward-line (- height))
5360                                  (point)))
5361          (window (get-buffer-window (current-buffer))))
5362     ;; The user has to want it.
5363     (when gnus-auto-center-summary
5364       (when (get-buffer-window gnus-article-buffer)
5365         ;; Only do recentering when the article buffer is displayed,
5366         ;; Set the window start to either `bottom', which is the biggest
5367         ;; possible valid number, or the second line from the top,
5368         ;; whichever is the least.
5369         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5370           (if (> bottom top-pos)
5371               ;; Keep the second line from the top visible
5372               (set-window-start window top-pos t)
5373             ;; Try to keep the bottom line visible; if it's partially
5374             ;; obscured, either scroll one more line to make it fully
5375             ;; visible, or revert to using TOP-POS.
5376             (save-excursion
5377               (goto-char (point-max))
5378               (forward-line -1)
5379               (let ((last-line-start (point)))
5380                 (goto-char bottom)
5381                 (set-window-start window (point) t)
5382                 (when (not (pos-visible-in-window-p last-line-start window))
5383                   (forward-line 1)
5384                   (set-window-start window (min (point) top-pos) t)))))))
5385       ;; Do horizontal recentering while we're at it.
5386       (when (and (get-buffer-window (current-buffer) t)
5387                  (not (eq gnus-auto-center-summary 'vertical)))
5388         (let ((selected (selected-window)))
5389           (select-window (get-buffer-window (current-buffer) t))
5390           (gnus-summary-position-point)
5391           (gnus-horizontal-recenter)
5392           (select-window selected))))))
5393
5394 (defun gnus-summary-jump-to-group (newsgroup)
5395   "Move point to NEWSGROUP in group mode buffer."
5396   ;; Keep update point of group mode buffer if visible.
5397   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5398       (save-window-excursion
5399         ;; Take care of tree window mode.
5400         (when (get-buffer-window gnus-group-buffer)
5401           (pop-to-buffer gnus-group-buffer))
5402         (gnus-group-jump-to-group newsgroup))
5403     (save-excursion
5404       ;; Take care of tree window mode.
5405       (if (get-buffer-window gnus-group-buffer)
5406           (pop-to-buffer gnus-group-buffer)
5407         (set-buffer gnus-group-buffer))
5408       (gnus-group-jump-to-group newsgroup))))
5409
5410 ;; This function returns a list of article numbers based on the
5411 ;; difference between the ranges of read articles in this group and
5412 ;; the range of active articles.
5413 (defun gnus-list-of-unread-articles (group)
5414   (let* ((read (gnus-info-read (gnus-get-info group)))
5415          (active (or (gnus-active group) (gnus-activate-group group)))
5416          (last (cdr active))
5417          first nlast unread)
5418     ;; If none are read, then all are unread.
5419     (if (not read)
5420         (setq first (car active))
5421       ;; If the range of read articles is a single range, then the
5422       ;; first unread article is the article after the last read
5423       ;; article.  Sounds logical, doesn't it?
5424       (if (and (not (listp (cdr read)))
5425                (or (< (car read) (car active))
5426                    (progn (setq read (list read))
5427                           nil)))
5428           (setq first (max (car active) (1+ (cdr read))))
5429         ;; `read' is a list of ranges.
5430         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5431                                   (caar read)))
5432                   1)
5433           (setq first (car active)))
5434         (while read
5435           (when first
5436             (while (< first nlast)
5437               (push first unread)
5438               (setq first (1+ first))))
5439           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5440           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5441           (setq read (cdr read)))))
5442     ;; And add the last unread articles.
5443     (while (<= first last)
5444       (push first unread)
5445       (setq first (1+ first)))
5446     ;; Return the list of unread articles.
5447     (delq 0 (nreverse unread))))
5448
5449 (defun gnus-list-of-read-articles (group)
5450   "Return a list of unread, unticked and non-dormant articles."
5451   (let* ((info (gnus-get-info group))
5452          (marked (gnus-info-marks info))
5453          (active (gnus-active group)))
5454     (and info active
5455          (gnus-set-difference
5456           (gnus-sorted-complement
5457            (gnus-uncompress-range active)
5458            (gnus-list-of-unread-articles group))
5459           (append
5460            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5461            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5462
5463 ;; Various summary commands
5464
5465 (defun gnus-summary-select-article-buffer ()
5466   "Reconfigure windows to show article buffer."
5467   (interactive)
5468   (if (not (gnus-buffer-live-p gnus-article-buffer))
5469       (error "There is no article buffer for this summary buffer")
5470     (gnus-configure-windows 'article)
5471     (select-window (get-buffer-window gnus-article-buffer))))
5472
5473 (defun gnus-summary-universal-argument (arg)
5474   "Perform any operation on all articles that are process/prefixed."
5475   (interactive "P")
5476   (let ((articles (gnus-summary-work-articles arg))
5477         func article)
5478     (if (eq
5479          (setq
5480           func
5481           (key-binding
5482            (read-key-sequence
5483             (substitute-command-keys
5484              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5485          'undefined)
5486         (gnus-error 1 "Undefined key")
5487       (save-excursion
5488         (while articles
5489           (gnus-summary-goto-subject (setq article (pop articles)))
5490           (let (gnus-newsgroup-processable)
5491             (command-execute func))
5492           (gnus-summary-remove-process-mark article)))))
5493   (gnus-summary-position-point))
5494
5495 (defun gnus-summary-toggle-truncation (&optional arg)
5496   "Toggle truncation of summary lines.
5497 With arg, turn line truncation on iff arg is positive."
5498   (interactive "P")
5499   (setq truncate-lines
5500         (if (null arg) (not truncate-lines)
5501           (> (prefix-numeric-value arg) 0)))
5502   (redraw-display))
5503
5504 (defun gnus-summary-reselect-current-group (&optional all rescan)
5505   "Exit and then reselect the current newsgroup.
5506 The prefix argument ALL means to select all articles."
5507   (interactive "P")
5508   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5509     (error "Ephemeral groups can't be reselected"))
5510   (let ((current-subject (gnus-summary-article-number))
5511         (group gnus-newsgroup-name))
5512     (setq gnus-newsgroup-begin nil)
5513     (gnus-summary-exit)
5514     ;; We have to adjust the point of group mode buffer because
5515     ;; point was moved to the next unread newsgroup by exiting.
5516     (gnus-summary-jump-to-group group)
5517     (when rescan
5518       (save-excursion
5519         (save-window-excursion
5520           ;; Don't show group contents.
5521           (set-window-start (selected-window) (point-max))
5522           (gnus-group-get-new-news-this-group 1))))
5523     (gnus-group-read-group all t)
5524     (gnus-summary-goto-subject current-subject nil t)))
5525
5526 (defun gnus-summary-rescan-group (&optional all)
5527   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5528   (interactive "P")
5529   (gnus-summary-reselect-current-group all t))
5530
5531 (defun gnus-summary-update-info (&optional non-destructive)
5532   (save-excursion
5533     (let ((group gnus-newsgroup-name))
5534       (when group
5535         (when gnus-newsgroup-kill-headers
5536           (setq gnus-newsgroup-killed
5537                 (gnus-compress-sequence
5538                  (nconc
5539                   (gnus-set-sorted-intersection
5540                    (gnus-uncompress-range gnus-newsgroup-killed)
5541                    (setq gnus-newsgroup-unselected
5542                          (sort gnus-newsgroup-unselected '<)))
5543                   (setq gnus-newsgroup-unreads
5544                         (sort gnus-newsgroup-unreads '<)))
5545                  t)))
5546         (unless (listp (cdr gnus-newsgroup-killed))
5547           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5548         (let ((headers gnus-newsgroup-headers))
5549           ;; Set the new ranges of read articles.
5550           (save-excursion
5551             (set-buffer gnus-group-buffer)
5552             (gnus-undo-force-boundary))
5553           (gnus-update-read-articles
5554            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5555           ;; Set the current article marks.
5556           (let ((gnus-newsgroup-scored
5557                  (if (and (not gnus-save-score)
5558                           (not non-destructive))
5559                      nil
5560                    gnus-newsgroup-scored)))
5561             (save-excursion
5562               (gnus-update-marks)))
5563           ;; Do the cross-ref thing.
5564           (when gnus-use-cross-reference
5565             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5566           ;; Do not switch windows but change the buffer to work.
5567           (set-buffer gnus-group-buffer)
5568           (unless (gnus-ephemeral-group-p group)
5569             (gnus-group-update-group group)))))))
5570
5571 (defun gnus-summary-save-newsrc (&optional force)
5572   "Save the current number of read/marked articles in the dribble buffer.
5573 The dribble buffer will then be saved.
5574 If FORCE (the prefix), also save the .newsrc file(s)."
5575   (interactive "P")
5576   (gnus-summary-update-info t)
5577   (if force
5578       (gnus-save-newsrc-file)
5579     (gnus-dribble-save)))
5580
5581 (defun gnus-summary-exit (&optional temporary)
5582   "Exit reading current newsgroup, and then return to group selection mode.
5583 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5584   (interactive)
5585   (gnus-set-global-variables)
5586   (gnus-kill-save-kill-buffer)
5587   (gnus-async-halt-prefetch)
5588   (let* ((group gnus-newsgroup-name)
5589          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5590          (mode major-mode)
5591          (group-point nil)
5592          (buf (current-buffer)))
5593     (unless quit-config
5594       ;; Do adaptive scoring, and possibly save score files.
5595       (when gnus-newsgroup-adaptive
5596         (gnus-score-adaptive))
5597       (when gnus-use-scoring
5598         (gnus-score-save)))
5599     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5600     ;; If we have several article buffers, we kill them at exit.
5601     (unless gnus-single-article-buffer
5602       (gnus-kill-buffer gnus-original-article-buffer)
5603       (setq gnus-article-current nil))
5604     (when gnus-use-cache
5605       (gnus-cache-possibly-remove-articles)
5606       (gnus-cache-save-buffers))
5607     (gnus-async-prefetch-remove-group group)
5608     (when gnus-suppress-duplicates
5609       (gnus-dup-enter-articles))
5610     (when gnus-use-trees
5611       (gnus-tree-close group))
5612     (when gnus-use-cache
5613       (gnus-cache-write-active))
5614     ;; Remove entries for this group.
5615     (nnmail-purge-split-history (gnus-group-real-name group))
5616     ;; Make all changes in this group permanent.
5617     (unless quit-config
5618       (gnus-run-hooks 'gnus-exit-group-hook)
5619       (gnus-summary-update-info))
5620     (gnus-close-group group)
5621     ;; Make sure where we were, and go to next newsgroup.
5622     (set-buffer gnus-group-buffer)
5623     (unless quit-config
5624       (gnus-group-jump-to-group group))
5625     (gnus-run-hooks 'gnus-summary-exit-hook)
5626     (unless (or quit-config
5627                 ;; If this group has disappeared from the summary
5628                 ;; buffer, don't skip forwards.
5629                 (not (string= group (gnus-group-group-name))))
5630       (gnus-group-next-unread-group 1))
5631     (setq group-point (point))
5632     (if temporary
5633         nil                             ;Nothing to do.
5634       ;; If we have several article buffers, we kill them at exit.
5635       (unless gnus-single-article-buffer
5636         (gnus-kill-buffer gnus-article-buffer)
5637         (gnus-kill-buffer gnus-original-article-buffer)
5638         (setq gnus-article-current nil))
5639       (set-buffer buf)
5640       (if (not gnus-kill-summary-on-exit)
5641           (gnus-deaden-summary)
5642         ;; We set all buffer-local variables to nil.  It is unclear why
5643         ;; this is needed, but if we don't, buffer-local variables are
5644         ;; not garbage-collected, it seems.  This would the lead to en
5645         ;; ever-growing Emacs.
5646         (gnus-summary-clear-local-variables)
5647         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5648           (gnus-summary-clear-local-variables))
5649         (when (get-buffer gnus-article-buffer)
5650           (bury-buffer gnus-article-buffer))
5651         ;; We clear the global counterparts of the buffer-local
5652         ;; variables as well, just to be on the safe side.
5653         (set-buffer gnus-group-buffer)
5654         (gnus-summary-clear-local-variables)
5655         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5656           (gnus-summary-clear-local-variables))
5657         ;; Return to group mode buffer.
5658         (when (eq mode 'gnus-summary-mode)
5659           (gnus-kill-buffer buf)))
5660       (setq gnus-current-select-method gnus-select-method)
5661       (pop-to-buffer gnus-group-buffer)
5662       (if (not quit-config)
5663           (progn
5664             (goto-char group-point)
5665             (gnus-configure-windows 'group 'force)
5666             (unless (pos-visible-in-window-p)
5667               (forward-line (/ (static-if (featurep 'xemacs)
5668                                    (window-displayed-height)
5669                                  (1- (window-height)))
5670                                -2))
5671               (set-window-start (selected-window) (point))
5672               (goto-char group-point)))
5673         (gnus-handle-ephemeral-exit quit-config))
5674       ;; Clear the current group name.
5675       (unless quit-config
5676         (setq gnus-newsgroup-name nil)))))
5677
5678 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5679 (defun gnus-summary-exit-no-update (&optional no-questions)
5680   "Quit reading current newsgroup without updating read article info."
5681   (interactive)
5682   (let* ((group gnus-newsgroup-name)
5683          (quit-config (gnus-group-quit-config group)))
5684     (when (or no-questions
5685               gnus-expert-user
5686               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5687       (gnus-async-halt-prefetch)
5688       (mapcar 'funcall
5689               (delq 'gnus-summary-expire-articles
5690                     (copy-sequence gnus-summary-prepare-exit-hook)))
5691       ;; If we have several article buffers, we kill them at exit.
5692       (unless gnus-single-article-buffer
5693         (gnus-kill-buffer gnus-article-buffer)
5694         (gnus-kill-buffer gnus-original-article-buffer)
5695         (setq gnus-article-current nil))
5696       (if (not gnus-kill-summary-on-exit)
5697           (gnus-deaden-summary)
5698         (gnus-close-group group)
5699         (gnus-summary-clear-local-variables)
5700         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5701           (gnus-summary-clear-local-variables))
5702         (set-buffer gnus-group-buffer)
5703         (gnus-summary-clear-local-variables)
5704         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5705           (gnus-summary-clear-local-variables))
5706         (when (get-buffer gnus-summary-buffer)
5707           (kill-buffer gnus-summary-buffer)))
5708       (unless gnus-single-article-buffer
5709         (setq gnus-article-current nil))
5710       (when gnus-use-trees
5711         (gnus-tree-close group))
5712       (gnus-async-prefetch-remove-group group)
5713       (when (get-buffer gnus-article-buffer)
5714         (bury-buffer gnus-article-buffer))
5715       ;; Return to the group buffer.
5716       (gnus-configure-windows 'group 'force)
5717       ;; Clear the current group name.
5718       (setq gnus-newsgroup-name nil)
5719       (when (equal (gnus-group-group-name) group)
5720         (gnus-group-next-unread-group 1))
5721       (when quit-config
5722         (gnus-handle-ephemeral-exit quit-config)))))
5723
5724 (defun gnus-handle-ephemeral-exit (quit-config)
5725   "Handle movement when leaving an ephemeral group.
5726 The state which existed when entering the ephemeral is reset."
5727   (if (not (buffer-name (car quit-config)))
5728       (gnus-configure-windows 'group 'force)
5729     (set-buffer (car quit-config))
5730     (cond ((eq major-mode 'gnus-summary-mode)
5731            (gnus-set-global-variables))
5732           ((eq major-mode 'gnus-article-mode)
5733            (save-excursion
5734              ;; The `gnus-summary-buffer' variable may point
5735              ;; to the old summary buffer when using a single
5736              ;; article buffer.
5737              (unless (gnus-buffer-live-p gnus-summary-buffer)
5738                (set-buffer gnus-group-buffer))
5739              (set-buffer gnus-summary-buffer)
5740              (gnus-set-global-variables))))
5741     (if (or (eq (cdr quit-config) 'article)
5742             (eq (cdr quit-config) 'pick))
5743         (progn
5744           ;; The current article may be from the ephemeral group
5745           ;; thus it is best that we reload this article
5746           (gnus-summary-show-article)
5747           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5748               (gnus-configure-windows 'pick 'force)
5749             (gnus-configure-windows (cdr quit-config) 'force)))
5750       (gnus-configure-windows (cdr quit-config) 'force))
5751     (when (eq major-mode 'gnus-summary-mode)
5752       (gnus-summary-next-subject 1 nil t)
5753       (gnus-summary-recenter)
5754       (gnus-summary-position-point))))
5755
5756 (defun gnus-summary-preview-mime-message ()
5757   "MIME decode and play this message."
5758   (interactive)
5759   (let ((gnus-break-pages nil)
5760         (gnus-show-mime t))
5761     (gnus-summary-select-article gnus-show-all-headers t))
5762   (select-window (get-buffer-window gnus-article-buffer)))
5763
5764 ;;; Dead summaries.
5765
5766 (defvar gnus-dead-summary-mode-map nil)
5767
5768 (unless gnus-dead-summary-mode-map
5769   (setq gnus-dead-summary-mode-map (make-keymap))
5770   (suppress-keymap gnus-dead-summary-mode-map)
5771   (substitute-key-definition
5772    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5773   (let ((keys '("\C-d" "\r" "\177" [delete])))
5774     (while keys
5775       (define-key gnus-dead-summary-mode-map
5776         (pop keys) 'gnus-summary-wake-up-the-dead))))
5777
5778 (defvar gnus-dead-summary-mode nil
5779   "Minor mode for Gnus summary buffers.")
5780
5781 (defun gnus-dead-summary-mode (&optional arg)
5782   "Minor mode for Gnus summary buffers."
5783   (interactive "P")
5784   (when (eq major-mode 'gnus-summary-mode)
5785     (make-local-variable 'gnus-dead-summary-mode)
5786     (setq gnus-dead-summary-mode
5787           (if (null arg) (not gnus-dead-summary-mode)
5788             (> (prefix-numeric-value arg) 0)))
5789     (when gnus-dead-summary-mode
5790       (gnus-add-minor-mode
5791        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5792
5793 (defun gnus-deaden-summary ()
5794   "Make the current summary buffer into a dead summary buffer."
5795   ;; Kill any previous dead summary buffer.
5796   (when (and gnus-dead-summary
5797              (buffer-name gnus-dead-summary))
5798     (save-excursion
5799       (set-buffer gnus-dead-summary)
5800       (when gnus-dead-summary-mode
5801         (kill-buffer (current-buffer)))))
5802   ;; Make this the current dead summary.
5803   (setq gnus-dead-summary (current-buffer))
5804   (gnus-dead-summary-mode 1)
5805   (let ((name (buffer-name)))
5806     (when (string-match "Summary" name)
5807       (rename-buffer
5808        (concat (substring name 0 (match-beginning 0)) "Dead "
5809                (substring name (match-beginning 0)))
5810        t)
5811       (bury-buffer))))
5812
5813 (defun gnus-kill-or-deaden-summary (buffer)
5814   "Kill or deaden the summary BUFFER."
5815   (save-excursion
5816     (when (and (buffer-name buffer)
5817                (not gnus-single-article-buffer))
5818       (save-excursion
5819         (set-buffer buffer)
5820         (gnus-kill-buffer gnus-article-buffer)
5821         (gnus-kill-buffer gnus-original-article-buffer)))
5822     (cond (gnus-kill-summary-on-exit
5823            (when (and gnus-use-trees
5824                       (gnus-buffer-exists-p buffer))
5825              (save-excursion
5826                (set-buffer buffer)
5827                (gnus-tree-close gnus-newsgroup-name)))
5828            (gnus-kill-buffer buffer))
5829           ((gnus-buffer-exists-p buffer)
5830            (save-excursion
5831              (set-buffer buffer)
5832              (gnus-deaden-summary))))))
5833
5834 (defun gnus-summary-wake-up-the-dead (&rest args)
5835   "Wake up the dead summary buffer."
5836   (interactive)
5837   (gnus-dead-summary-mode -1)
5838   (let ((name (buffer-name)))
5839     (when (string-match "Dead " name)
5840       (rename-buffer
5841        (concat (substring name 0 (match-beginning 0))
5842                (substring name (match-end 0)))
5843        t)))
5844   (gnus-message 3 "This dead summary is now alive again"))
5845
5846 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5847 (defun gnus-summary-fetch-faq (&optional faq-dir)
5848   "Fetch the FAQ for the current group.
5849 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5850 in."
5851   (interactive
5852    (list
5853     (when current-prefix-arg
5854       (completing-read
5855        "Faq dir: " (and (listp gnus-group-faq-directory)
5856                         (mapcar (lambda (file) (list file))
5857                                 gnus-group-faq-directory))))))
5858   (let (gnus-faq-buffer)
5859     (when (setq gnus-faq-buffer
5860                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5861       (gnus-configure-windows 'summary-faq))))
5862
5863 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5864 (defun gnus-summary-describe-group (&optional force)
5865   "Describe the current newsgroup."
5866   (interactive "P")
5867   (gnus-group-describe-group force gnus-newsgroup-name))
5868
5869 (defun gnus-summary-describe-briefly ()
5870   "Describe summary mode commands briefly."
5871   (interactive)
5872   (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")))
5873
5874 ;; Walking around group mode buffer from summary mode.
5875
5876 (defun gnus-summary-next-group (&optional no-article target-group backward)
5877   "Exit current newsgroup and then select next unread newsgroup.
5878 If prefix argument NO-ARTICLE is non-nil, no article is selected
5879 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5880 previous group instead."
5881   (interactive "P")
5882   ;; Stop pre-fetching.
5883   (gnus-async-halt-prefetch)
5884   (let ((current-group gnus-newsgroup-name)
5885         (current-buffer (current-buffer))
5886         entered)
5887     ;; First we semi-exit this group to update Xrefs and all variables.
5888     ;; We can't do a real exit, because the window conf must remain
5889     ;; the same in case the user is prompted for info, and we don't
5890     ;; want the window conf to change before that...
5891     (gnus-summary-exit t)
5892     (while (not entered)
5893       ;; Then we find what group we are supposed to enter.
5894       (set-buffer gnus-group-buffer)
5895       (gnus-group-jump-to-group current-group)
5896       (setq target-group
5897             (or target-group
5898                 (if (eq gnus-keep-same-level 'best)
5899                     (gnus-summary-best-group gnus-newsgroup-name)
5900                   (gnus-summary-search-group backward gnus-keep-same-level))))
5901       (if (not target-group)
5902           ;; There are no further groups, so we return to the group
5903           ;; buffer.
5904           (progn
5905             (gnus-message 5 "Returning to the group buffer")
5906             (setq entered t)
5907             (when (gnus-buffer-live-p current-buffer)
5908               (set-buffer current-buffer)
5909               (gnus-summary-exit))
5910             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5911         ;; We try to enter the target group.
5912         (gnus-group-jump-to-group target-group)
5913         (let ((unreads (gnus-group-group-unread)))
5914           (if (and (or (eq t unreads)
5915                        (and unreads (not (zerop unreads))))
5916                    (gnus-summary-read-group
5917                     target-group nil no-article
5918                     (and (buffer-name current-buffer) current-buffer)
5919                     nil backward))
5920               (setq entered t)
5921             (setq current-group target-group
5922                   target-group nil)))))))
5923
5924 (defun gnus-summary-prev-group (&optional no-article)
5925   "Exit current newsgroup and then select previous unread newsgroup.
5926 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5927   (interactive "P")
5928   (gnus-summary-next-group no-article nil t))
5929
5930 ;; Walking around summary lines.
5931
5932 (defun gnus-summary-first-subject (&optional unread undownloaded)
5933   "Go to the first unread subject.
5934 If UNREAD is non-nil, go to the first unread article.
5935 Returns the article selected or nil if there are no unread articles."
5936   (interactive "P")
5937   (prog1
5938       (cond
5939        ;; Empty summary.
5940        ((null gnus-newsgroup-data)
5941         (gnus-message 3 "No articles in the group")
5942         nil)
5943        ;; Pick the first article.
5944        ((not unread)
5945         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5946         (gnus-data-number (car gnus-newsgroup-data)))
5947        ;; No unread articles.
5948        ((null gnus-newsgroup-unreads)
5949         (gnus-message 3 "No more unread articles")
5950         nil)
5951        ;; Find the first unread article.
5952        (t
5953         (let ((data gnus-newsgroup-data))
5954           (while (and data
5955                       (and (not (and undownloaded
5956                                      (eq gnus-undownloaded-mark
5957                                          (gnus-data-mark (car data)))))
5958                            (not (gnus-data-unread-p (car data)))))
5959             (setq data (cdr data)))
5960           (when data
5961             (goto-char (gnus-data-pos (car data)))
5962             (gnus-data-number (car data))))))
5963     (gnus-summary-position-point)))
5964
5965 (defun gnus-summary-next-subject (n &optional unread dont-display)
5966   "Go to next N'th summary line.
5967 If N is negative, go to the previous N'th subject line.
5968 If UNREAD is non-nil, only unread articles are selected.
5969 The difference between N and the actual number of steps taken is
5970 returned."
5971   (interactive "p")
5972   (let ((backward (< n 0))
5973         (n (abs n)))
5974     (while (and (> n 0)
5975                 (if backward
5976                     (gnus-summary-find-prev unread)
5977                   (gnus-summary-find-next unread)))
5978       (unless (zerop (setq n (1- n)))
5979         (gnus-summary-show-thread)))
5980     (when (/= 0 n)
5981       (gnus-message 7 "No more%s articles"
5982                     (if unread " unread" "")))
5983     (unless dont-display
5984       (gnus-summary-recenter)
5985       (gnus-summary-position-point))
5986     n))
5987
5988 (defun gnus-summary-next-unread-subject (n)
5989   "Go to next N'th unread summary line."
5990   (interactive "p")
5991   (gnus-summary-next-subject n t))
5992
5993 (defun gnus-summary-prev-subject (n &optional unread)
5994   "Go to previous N'th summary line.
5995 If optional argument UNREAD is non-nil, only unread article is selected."
5996   (interactive "p")
5997   (gnus-summary-next-subject (- n) unread))
5998
5999 (defun gnus-summary-prev-unread-subject (n)
6000   "Go to previous N'th unread summary line."
6001   (interactive "p")
6002   (gnus-summary-next-subject (- n) t))
6003
6004 (defun gnus-summary-goto-subject (article &optional force silent)
6005   "Go the subject line of ARTICLE.
6006 If FORCE, also allow jumping to articles not currently shown."
6007   (interactive "nArticle number: ")
6008   (let ((b (point))
6009         (data (gnus-data-find article)))
6010     ;; We read in the article if we have to.
6011     (and (not data)
6012          force
6013          (gnus-summary-insert-subject
6014           article
6015           (if (or (numberp force) (vectorp force)) force)
6016           t)
6017          (setq data (gnus-data-find article)))
6018     (goto-char b)
6019     (if (not data)
6020         (progn
6021           (unless silent
6022             (gnus-message 3 "Can't find article %d" article))
6023           nil)
6024       (goto-char (gnus-data-pos data))
6025       (gnus-summary-position-point)
6026       article)))
6027
6028 ;; Walking around summary lines with displaying articles.
6029
6030 (defun gnus-summary-expand-window (&optional arg)
6031   "Make the summary buffer take up the entire Emacs frame.
6032 Given a prefix, will force an `article' buffer configuration."
6033   (interactive "P")
6034   (if arg
6035       (gnus-configure-windows 'article 'force)
6036     (gnus-configure-windows 'summary 'force)))
6037
6038 (defun gnus-summary-display-article (article &optional all-header)
6039   "Display ARTICLE in article buffer."
6040   (when (gnus-buffer-live-p gnus-article-buffer)
6041     (with-current-buffer gnus-article-buffer
6042       (mm-enable-multibyte-mule4)))
6043   (gnus-set-global-variables)
6044   (when (gnus-buffer-live-p gnus-article-buffer)
6045     (with-current-buffer gnus-article-buffer
6046       (setq gnus-article-charset gnus-newsgroup-charset)
6047       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)))
6048   (if (null article)
6049       nil
6050     (prog1
6051         (if gnus-summary-display-article-function
6052             (funcall gnus-summary-display-article-function article all-header)
6053           (gnus-article-prepare article all-header))
6054       (with-current-buffer gnus-article-buffer
6055         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6056              nil))
6057       (gnus-run-hooks 'gnus-select-article-hook)
6058       (when (and gnus-current-article
6059                  (not (zerop gnus-current-article)))
6060         (gnus-summary-goto-subject gnus-current-article))
6061       (gnus-summary-recenter)
6062       (when (and gnus-use-trees gnus-show-threads)
6063         (gnus-possibly-generate-tree article)
6064         (gnus-highlight-selected-tree article))
6065       ;; Successfully display article.
6066       (gnus-article-set-window-start
6067        (cdr (assq article gnus-newsgroup-bookmarks))))))
6068
6069 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6070   "Select the current article.
6071 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6072 non-nil, the article will be re-fetched even if it already present in
6073 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6074 be displayed."
6075   ;; Make sure we are in the summary buffer to work around bbdb bug.
6076   (unless (eq major-mode 'gnus-summary-mode)
6077     (set-buffer gnus-summary-buffer))
6078   (let ((article (or article (gnus-summary-article-number)))
6079         (all-headers (not (not all-headers))) ;Must be T or NIL.
6080         gnus-summary-display-article-function)
6081     (and (not pseudo)
6082          (gnus-summary-article-pseudo-p article)
6083          (error "This is a pseudo-article"))
6084     (save-excursion
6085       (set-buffer gnus-summary-buffer)
6086       (if (or (and gnus-single-article-buffer
6087                    (or (null gnus-current-article)
6088                        (null gnus-article-current)
6089                        (null (get-buffer gnus-article-buffer))
6090                        (not (eq article (cdr gnus-article-current)))
6091                        (not (equal (car gnus-article-current)
6092                                    gnus-newsgroup-name))))
6093               (and (not gnus-single-article-buffer)
6094                    (or (null gnus-current-article)
6095                        (not (eq gnus-current-article article))))
6096               force)
6097           ;; The requested article is different from the current article.
6098           (progn
6099             (gnus-summary-display-article article all-headers)
6100             (when (or all-headers gnus-show-all-headers)
6101               (gnus-article-show-all-headers))
6102             (gnus-article-set-window-start
6103              (cdr (assq article gnus-newsgroup-bookmarks)))
6104             article)
6105         (when (or all-headers gnus-show-all-headers)
6106           (gnus-article-show-all-headers))
6107         'old))))
6108
6109 (defun gnus-summary-force-verify-and-decrypt ()
6110   (interactive)
6111   (let ((mm-verify-option 'known)
6112         (mm-decrypt-option 'known))
6113     (gnus-summary-select-article nil 'force)))
6114
6115 (defun gnus-summary-set-current-mark (&optional current-mark)
6116   "Obsolete function."
6117   nil)
6118
6119 (defun gnus-summary-next-article (&optional unread subject backward push)
6120   "Select the next article.
6121 If UNREAD, only unread articles are selected.
6122 If SUBJECT, only articles with SUBJECT are selected.
6123 If BACKWARD, the previous article is selected instead of the next."
6124   (interactive "P")
6125   (cond
6126    ;; Is there such an article?
6127    ((and (gnus-summary-search-forward unread subject backward)
6128          (or (gnus-summary-display-article (gnus-summary-article-number))
6129              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6130     (gnus-summary-position-point))
6131    ;; If not, we try the first unread, if that is wanted.
6132    ((and subject
6133          gnus-auto-select-same
6134          (gnus-summary-first-unread-article))
6135     (gnus-summary-position-point)
6136     (gnus-message 6 "Wrapped"))
6137    ;; Try to get next/previous article not displayed in this group.
6138    ((and gnus-auto-extend-newsgroup
6139          (not unread) (not subject))
6140     (gnus-summary-goto-article
6141      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6142      nil (count-lines (point-min) (point))))
6143    ;; Go to next/previous group.
6144    (t
6145     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6146       (gnus-summary-jump-to-group gnus-newsgroup-name))
6147     (let ((cmd last-command-char)
6148           (point
6149            (save-excursion
6150              (set-buffer gnus-group-buffer)
6151              (point)))
6152           (group
6153            (if (eq gnus-keep-same-level 'best)
6154                (gnus-summary-best-group gnus-newsgroup-name)
6155              (gnus-summary-search-group backward gnus-keep-same-level))))
6156       ;; For some reason, the group window gets selected.  We change
6157       ;; it back.
6158       (select-window (get-buffer-window (current-buffer)))
6159       ;; Select next unread newsgroup automagically.
6160       (cond
6161        ((or (not gnus-auto-select-next)
6162             (not cmd))
6163         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6164        ((or (eq gnus-auto-select-next 'quietly)
6165             (and (eq gnus-auto-select-next 'slightly-quietly)
6166                  push)
6167             (and (eq gnus-auto-select-next 'almost-quietly)
6168                  (gnus-summary-last-article-p)))
6169         ;; Select quietly.
6170         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6171             (gnus-summary-exit)
6172           (gnus-message 7 "No more%s articles (%s)..."
6173                         (if unread " unread" "")
6174                         (if group (concat "selecting " group)
6175                           "exiting"))
6176           (gnus-summary-next-group nil group backward)))
6177        (t
6178         (when (gnus-key-press-event-p last-input-event)
6179           (gnus-summary-walk-group-buffer
6180            gnus-newsgroup-name cmd unread backward point))))))))
6181
6182 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6183   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6184                       (?\C-p (gnus-group-prev-unread-group 1))))
6185         (cursor-in-echo-area t)
6186         keve key group ended)
6187     (save-excursion
6188       (set-buffer gnus-group-buffer)
6189       (goto-char start)
6190       (setq group
6191             (if (eq gnus-keep-same-level 'best)
6192                 (gnus-summary-best-group gnus-newsgroup-name)
6193               (gnus-summary-search-group backward gnus-keep-same-level))))
6194     (while (not ended)
6195       (gnus-message
6196        5 "No more%s articles%s" (if unread " unread" "")
6197        (if (and group
6198                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6199            (format " (Type %s for %s [%s])"
6200                    (single-key-description cmd) group
6201                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6202          (format " (Type %s to exit %s)"
6203                  (single-key-description cmd)
6204                  gnus-newsgroup-name)))
6205       ;; Confirm auto selection.
6206       (setq key (car (setq keve (gnus-read-event-char))))
6207       (setq ended t)
6208       (cond
6209        ((assq key keystrokes)
6210         (let ((obuf (current-buffer)))
6211           (switch-to-buffer gnus-group-buffer)
6212           (when group
6213             (gnus-group-jump-to-group group))
6214           (eval (cadr (assq key keystrokes)))
6215           (setq group (gnus-group-group-name))
6216           (switch-to-buffer obuf))
6217         (setq ended nil))
6218        ((equal key cmd)
6219         (if (or (not group)
6220                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6221             (gnus-summary-exit)
6222           (gnus-summary-next-group nil group backward)))
6223        (t
6224         (push (cdr keve) unread-command-events))))))
6225
6226 (defun gnus-summary-next-unread-article ()
6227   "Select unread article after current one."
6228   (interactive)
6229   (gnus-summary-next-article
6230    (or (not (eq gnus-summary-goto-unread 'never))
6231        (gnus-summary-last-article-p (gnus-summary-article-number)))
6232    (and gnus-auto-select-same
6233         (gnus-summary-article-subject))))
6234
6235 (defun gnus-summary-prev-article (&optional unread subject)
6236   "Select the article after the current one.
6237 If UNREAD is non-nil, only unread articles are selected."
6238   (interactive "P")
6239   (gnus-summary-next-article unread subject t))
6240
6241 (defun gnus-summary-prev-unread-article ()
6242   "Select unread article before current one."
6243   (interactive)
6244   (gnus-summary-prev-article
6245    (or (not (eq gnus-summary-goto-unread 'never))
6246        (gnus-summary-first-article-p (gnus-summary-article-number)))
6247    (and gnus-auto-select-same
6248         (gnus-summary-article-subject))))
6249
6250 (defun gnus-summary-next-page (&optional lines circular)
6251   "Show next page of the selected article.
6252 If at the end of the current article, select the next article.
6253 LINES says how many lines should be scrolled up.
6254
6255 If CIRCULAR is non-nil, go to the start of the article instead of
6256 selecting the next article when reaching the end of the current
6257 article."
6258   (interactive "P")
6259   (setq gnus-summary-buffer (current-buffer))
6260   (gnus-set-global-variables)
6261   (let ((article (gnus-summary-article-number))
6262         (article-window (get-buffer-window gnus-article-buffer t))
6263         endp)
6264     ;; If the buffer is empty, we have no article.
6265     (unless article
6266       (error "No article to select"))
6267     (gnus-configure-windows 'article)
6268     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6269         (if (and (eq gnus-summary-goto-unread 'never)
6270                  (not (gnus-summary-last-article-p article)))
6271             (gnus-summary-next-article)
6272           (gnus-summary-next-unread-article))
6273       (if (or (null gnus-current-article)
6274               (null gnus-article-current)
6275               (/= article (cdr gnus-article-current))
6276               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6277           ;; Selected subject is different from current article's.
6278           (gnus-summary-display-article article)
6279         (when article-window
6280           (gnus-eval-in-buffer-window gnus-article-buffer
6281             (setq endp (gnus-article-next-page lines)))
6282           (when endp
6283             (cond (circular
6284                    (gnus-summary-beginning-of-article))
6285                   (lines
6286                    (gnus-message 3 "End of message"))
6287                   ((null lines)
6288                    (if (and (eq gnus-summary-goto-unread 'never)
6289                             (not (gnus-summary-last-article-p article)))
6290                        (gnus-summary-next-article)
6291                      (gnus-summary-next-unread-article))))))))
6292     (gnus-summary-recenter)
6293     (gnus-summary-position-point)))
6294
6295 (defun gnus-summary-prev-page (&optional lines move)
6296   "Show previous page of selected article.
6297 Argument LINES specifies lines to be scrolled down.
6298 If MOVE, move to the previous unread article if point is at
6299 the beginning of the buffer."
6300   (interactive "P")
6301   (let ((article (gnus-summary-article-number))
6302         (article-window (get-buffer-window gnus-article-buffer t))
6303         endp)
6304     (gnus-configure-windows 'article)
6305     (if (or (null gnus-current-article)
6306             (null gnus-article-current)
6307             (/= article (cdr gnus-article-current))
6308             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6309         ;; Selected subject is different from current article's.
6310         (gnus-summary-display-article article)
6311       (gnus-summary-recenter)
6312       (when article-window
6313         (gnus-eval-in-buffer-window gnus-article-buffer
6314           (setq endp (gnus-article-prev-page lines)))
6315         (when (and move endp)
6316           (cond (lines
6317                  (gnus-message 3 "Beginning of message"))
6318                 ((null lines)
6319                  (if (and (eq gnus-summary-goto-unread 'never)
6320                           (not (gnus-summary-first-article-p article)))
6321                      (gnus-summary-prev-article)
6322                    (gnus-summary-prev-unread-article))))))))
6323   (gnus-summary-position-point))
6324
6325 (defun gnus-summary-prev-page-or-article (&optional lines)
6326   "Show previous page of selected article.
6327 Argument LINES specifies lines to be scrolled down.
6328 If at the beginning of the article, go to the next article."
6329   (interactive "P")
6330   (gnus-summary-prev-page lines t))
6331
6332 (defun gnus-summary-scroll-up (lines)
6333   "Scroll up (or down) one line current article.
6334 Argument LINES specifies lines to be scrolled up (or down if negative)."
6335   (interactive "p")
6336   (gnus-configure-windows 'article)
6337   (gnus-summary-show-thread)
6338   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6339     (gnus-eval-in-buffer-window gnus-article-buffer
6340       (cond ((> lines 0)
6341              (when (gnus-article-next-page lines)
6342                (gnus-message 3 "End of message")))
6343             ((< lines 0)
6344              (gnus-article-prev-page (- lines))))))
6345   (gnus-summary-recenter)
6346   (gnus-summary-position-point))
6347
6348 (defun gnus-summary-scroll-down (lines)
6349   "Scroll down (or up) one line current article.
6350 Argument LINES specifies lines to be scrolled down (or up if negative)."
6351   (interactive "p")
6352   (gnus-summary-scroll-up (- lines)))
6353
6354 (defun gnus-summary-next-same-subject ()
6355   "Select next article which has the same subject as current one."
6356   (interactive)
6357   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6358
6359 (defun gnus-summary-prev-same-subject ()
6360   "Select previous article which has the same subject as current one."
6361   (interactive)
6362   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6363
6364 (defun gnus-summary-next-unread-same-subject ()
6365   "Select next unread article which has the same subject as current one."
6366   (interactive)
6367   (gnus-summary-next-article t (gnus-summary-article-subject)))
6368
6369 (defun gnus-summary-prev-unread-same-subject ()
6370   "Select previous unread article which has the same subject as current one."
6371   (interactive)
6372   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6373
6374 (defun gnus-summary-first-unread-article ()
6375   "Select the first unread article.
6376 Return nil if there are no unread articles."
6377   (interactive)
6378   (prog1
6379       (when (gnus-summary-first-subject t)
6380         (gnus-summary-show-thread)
6381         (gnus-summary-first-subject t)
6382         (gnus-summary-display-article (gnus-summary-article-number)))
6383     (gnus-summary-position-point)))
6384
6385 (defun gnus-summary-first-unread-subject ()
6386   "Place the point on the subject line of the first unread article.
6387 Return nil if there are no unread articles."
6388   (interactive)
6389   (prog1
6390       (when (gnus-summary-first-subject t)
6391         (gnus-summary-show-thread)
6392         (gnus-summary-first-subject t))
6393     (gnus-summary-position-point)))
6394
6395 (defun gnus-summary-first-article ()
6396   "Select the first article.
6397 Return nil if there are no articles."
6398   (interactive)
6399   (prog1
6400       (when (gnus-summary-first-subject)
6401         (gnus-summary-show-thread)
6402         (gnus-summary-first-subject)
6403         (gnus-summary-display-article (gnus-summary-article-number)))
6404     (gnus-summary-position-point)))
6405
6406 (defun gnus-summary-best-unread-article ()
6407   "Select the unread article with the highest score."
6408   (interactive)
6409   (let ((best -1000000)
6410         (data gnus-newsgroup-data)
6411         article score)
6412     (while data
6413       (and (gnus-data-unread-p (car data))
6414            (> (setq score
6415                     (gnus-summary-article-score (gnus-data-number (car data))))
6416               best)
6417            (setq best score
6418                  article (gnus-data-number (car data))))
6419       (setq data (cdr data)))
6420     (prog1
6421         (if article
6422             (gnus-summary-goto-article article)
6423           (error "No unread articles"))
6424       (gnus-summary-position-point))))
6425
6426 (defun gnus-summary-last-subject ()
6427   "Go to the last displayed subject line in the group."
6428   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6429     (when article
6430       (gnus-summary-goto-subject article))))
6431
6432 (defun gnus-summary-goto-article (article &optional all-headers force)
6433   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6434 If ALL-HEADERS is non-nil, no header lines are hidden.
6435 If FORCE, go to the article even if it isn't displayed.  If FORCE
6436 is a number, it is the line the article is to be displayed on."
6437   (interactive
6438    (list
6439     (completing-read
6440      "Article number or Message-ID: "
6441      (mapcar (lambda (number) (list (int-to-string number)))
6442              gnus-newsgroup-limit))
6443     current-prefix-arg
6444     t))
6445   (prog1
6446       (if (and (stringp article)
6447                (string-match "@" article))
6448           (gnus-summary-refer-article article)
6449         (when (stringp article)
6450           (setq article (string-to-number article)))
6451         (if (gnus-summary-goto-subject article force)
6452             (gnus-summary-display-article article all-headers)
6453           (gnus-message 4 "Couldn't go to article %s" article) nil))
6454     (gnus-summary-position-point)))
6455
6456 (defun gnus-summary-goto-last-article ()
6457   "Go to the previously read article."
6458   (interactive)
6459   (prog1
6460       (when gnus-last-article
6461         (gnus-summary-goto-article gnus-last-article nil t))
6462     (gnus-summary-position-point)))
6463
6464 (defun gnus-summary-pop-article (number)
6465   "Pop one article off the history and go to the previous.
6466 NUMBER articles will be popped off."
6467   (interactive "p")
6468   (let (to)
6469     (setq gnus-newsgroup-history
6470           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6471     (if to
6472         (gnus-summary-goto-article (car to) nil t)
6473       (error "Article history empty")))
6474   (gnus-summary-position-point))
6475
6476 ;; Summary commands and functions for limiting the summary buffer.
6477
6478 (defun gnus-summary-limit-to-articles (n)
6479   "Limit the summary buffer to the next N articles.
6480 If not given a prefix, use the process marked articles instead."
6481   (interactive "P")
6482   (prog1
6483       (let ((articles (gnus-summary-work-articles n)))
6484         (setq gnus-newsgroup-processable nil)
6485         (gnus-summary-limit articles))
6486     (gnus-summary-position-point)))
6487
6488 (defun gnus-summary-pop-limit (&optional total)
6489   "Restore the previous limit.
6490 If given a prefix, remove all limits."
6491   (interactive "P")
6492   (when total
6493     (setq gnus-newsgroup-limits
6494           (list (mapcar (lambda (h) (mail-header-number h))
6495                         gnus-newsgroup-headers))))
6496   (unless gnus-newsgroup-limits
6497     (error "No limit to pop"))
6498   (prog1
6499       (gnus-summary-limit nil 'pop)
6500     (gnus-summary-position-point)))
6501
6502 (defun gnus-summary-limit-to-subject (subject &optional header)
6503   "Limit the summary buffer to articles that have subjects that match a regexp."
6504   (interactive "sLimit to subject (regexp): ")
6505   (unless header
6506     (setq header "subject"))
6507   (when (not (equal "" subject))
6508     (prog1
6509         (let ((articles (gnus-summary-find-matching
6510                          (or header "subject") subject 'all)))
6511           (unless articles
6512             (error "Found no matches for \"%s\"" subject))
6513           (gnus-summary-limit articles))
6514       (gnus-summary-position-point))))
6515
6516 (defun gnus-summary-limit-to-author (from)
6517   "Limit the summary buffer to articles that have authors that match a regexp."
6518   (interactive "sLimit to author (regexp): ")
6519   (gnus-summary-limit-to-subject from "from"))
6520
6521 (defun gnus-summary-limit-to-age (age &optional younger-p)
6522   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6523 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6524 articles that are younger than AGE days."
6525   (interactive
6526    (let ((younger current-prefix-arg)
6527          (days-got nil)
6528          days)
6529      (while (not days-got)
6530        (setq days (if younger
6531                       (read-string "Limit to articles within (in days): ")
6532                     (read-string "Limit to articles older than (in days): ")))
6533        (when (> (length days) 0)
6534          (setq days (read days)))
6535        (if (numberp days)
6536            (setq days-got t)
6537          (message "Please enter a number.")
6538          (sleep-for 1)))
6539      (list days younger)))
6540   (prog1
6541       (let ((data gnus-newsgroup-data)
6542             (cutoff (days-to-time age))
6543             articles d date is-younger)
6544         (while (setq d (pop data))
6545           (when (and (vectorp (gnus-data-header d))
6546                      (setq date (mail-header-date (gnus-data-header d))))
6547             (setq is-younger (time-less-p
6548                               (time-since (condition-case ()
6549                                               (date-to-time date)
6550                                             (error '(0 0))))
6551                               cutoff))
6552             (when (if younger-p
6553                       is-younger
6554                     (not is-younger))
6555               (push (gnus-data-number d) articles))))
6556         (gnus-summary-limit (nreverse articles)))
6557     (gnus-summary-position-point)))
6558
6559 (defun gnus-summary-limit-to-extra (header regexp)
6560   "Limit the summary buffer to articles that match an 'extra' header."
6561   (interactive
6562    (let ((header
6563           (intern
6564            (gnus-completing-read
6565             (symbol-name (car gnus-extra-headers))
6566             "Limit extra header:"
6567             (mapcar (lambda (x)
6568                       (cons (symbol-name x) x))
6569                     gnus-extra-headers)
6570             nil
6571             t))))
6572      (list header
6573            (read-string (format "Limit to header %s (regexp): " header)))))
6574   (when (not (equal "" regexp))
6575     (prog1
6576         (let ((articles (gnus-summary-find-matching
6577                          (cons 'extra header) regexp 'all)))
6578           (unless articles
6579             (error "Found no matches for \"%s\"" regexp))
6580           (gnus-summary-limit articles))
6581       (gnus-summary-position-point))))
6582
6583 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6584 (make-obsolete
6585  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6586
6587 (defun gnus-summary-limit-to-unread (&optional all)
6588   "Limit the summary buffer to articles that are not marked as read.
6589 If ALL is non-nil, limit strictly to unread articles."
6590   (interactive "P")
6591   (if all
6592       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6593     (gnus-summary-limit-to-marks
6594      ;; Concat all the marks that say that an article is read and have
6595      ;; those removed.
6596      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6597            gnus-killed-mark gnus-kill-file-mark
6598            gnus-low-score-mark gnus-expirable-mark
6599            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6600            gnus-duplicate-mark gnus-souped-mark)
6601      'reverse)))
6602
6603 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6604 (make-obsolete 'gnus-summary-delete-marked-with
6605                'gnus-summary-limit-exlude-marks)
6606
6607 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6608   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6609 If REVERSE, limit the summary buffer to articles that are marked
6610 with MARKS.  MARKS can either be a string of marks or a list of marks.
6611 Returns how many articles were removed."
6612   (interactive "sMarks: ")
6613   (gnus-summary-limit-to-marks marks t))
6614
6615 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6616   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6617 If REVERSE (the prefix), limit the summary buffer to articles that are
6618 not marked with MARKS.  MARKS can either be a string of marks or a
6619 list of marks.
6620 Returns how many articles were removed."
6621   (interactive "sMarks: \nP")
6622   (prog1
6623       (let ((data gnus-newsgroup-data)
6624             (marks (if (listp marks) marks
6625                      (append marks nil))) ; Transform to list.
6626             articles)
6627         (while data
6628           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6629                   (memq (gnus-data-mark (car data)) marks))
6630             (push (gnus-data-number (car data)) articles))
6631           (setq data (cdr data)))
6632         (gnus-summary-limit articles))
6633     (gnus-summary-position-point)))
6634
6635 (defun gnus-summary-limit-to-score (&optional score)
6636   "Limit to articles with score at or above SCORE."
6637   (interactive "P")
6638   (setq score (if score
6639                   (prefix-numeric-value score)
6640                 (or gnus-summary-default-score 0)))
6641   (let ((data gnus-newsgroup-data)
6642         articles)
6643     (while data
6644       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6645                 score)
6646         (push (gnus-data-number (car data)) articles))
6647       (setq data (cdr data)))
6648     (prog1
6649         (gnus-summary-limit articles)
6650       (gnus-summary-position-point))))
6651
6652 (defun gnus-summary-limit-include-thread (id)
6653   "Display all the hidden articles that in the current thread."
6654   (interactive (list (mail-header-id (gnus-summary-article-header))))
6655   (let ((articles (gnus-articles-in-thread
6656                    (gnus-id-to-thread (gnus-root-id id)))))
6657     (prog1
6658         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6659       (gnus-summary-position-point))))
6660
6661 (defun gnus-summary-limit-include-dormant ()
6662   "Display all the hidden articles that are marked as dormant.
6663 Note that this command only works on a subset of the articles currently
6664 fetched for this group."
6665   (interactive)
6666   (unless gnus-newsgroup-dormant
6667     (error "There are no dormant articles in this group"))
6668   (prog1
6669       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6670     (gnus-summary-position-point)))
6671
6672 (defun gnus-summary-limit-exclude-dormant ()
6673   "Hide all dormant articles."
6674   (interactive)
6675   (prog1
6676       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6677     (gnus-summary-position-point)))
6678
6679 (defun gnus-summary-limit-exclude-childless-dormant ()
6680   "Hide all dormant articles that have no children."
6681   (interactive)
6682   (let ((data (gnus-data-list t))
6683         articles d children)
6684     ;; Find all articles that are either not dormant or have
6685     ;; children.
6686     (while (setq d (pop data))
6687       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6688                 (and (setq children
6689                            (gnus-article-children (gnus-data-number d)))
6690                      (let (found)
6691                        (while children
6692                          (when (memq (car children) articles)
6693                            (setq children nil
6694                                  found t))
6695                          (pop children))
6696                        found)))
6697         (push (gnus-data-number d) articles)))
6698     ;; Do the limiting.
6699     (prog1
6700         (gnus-summary-limit articles)
6701       (gnus-summary-position-point))))
6702
6703 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6704   "Mark all unread excluded articles as read.
6705 If ALL, mark even excluded ticked and dormants as read."
6706   (interactive "P")
6707   (let ((articles (gnus-sorted-complement
6708                    (sort
6709                     (mapcar (lambda (h) (mail-header-number h))
6710                             gnus-newsgroup-headers)
6711                     '<)
6712                    (sort gnus-newsgroup-limit '<)))
6713         article)
6714     (setq gnus-newsgroup-unreads
6715           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6716     (if all
6717         (setq gnus-newsgroup-dormant nil
6718               gnus-newsgroup-marked nil
6719               gnus-newsgroup-reads
6720               (nconc
6721                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6722                gnus-newsgroup-reads))
6723       (while (setq article (pop articles))
6724         (unless (or (memq article gnus-newsgroup-dormant)
6725                     (memq article gnus-newsgroup-marked))
6726           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6727
6728 (defun gnus-summary-limit (articles &optional pop)
6729   (if pop
6730       ;; We pop the previous limit off the stack and use that.
6731       (setq articles (car gnus-newsgroup-limits)
6732             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6733     ;; We use the new limit, so we push the old limit on the stack.
6734     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6735   ;; Set the limit.
6736   (setq gnus-newsgroup-limit articles)
6737   (let ((total (length gnus-newsgroup-data))
6738         (data (gnus-data-find-list (gnus-summary-article-number)))
6739         (gnus-summary-mark-below nil)   ; Inhibit this.
6740         found)
6741     ;; This will do all the work of generating the new summary buffer
6742     ;; according to the new limit.
6743     (gnus-summary-prepare)
6744     ;; Hide any threads, possibly.
6745     (and gnus-show-threads
6746          gnus-thread-hide-subtree
6747          (gnus-summary-hide-all-threads))
6748     ;; Try to return to the article you were at, or one in the
6749     ;; neighborhood.
6750     (when data
6751       ;; We try to find some article after the current one.
6752       (while data
6753         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6754           (setq data nil
6755                 found t))
6756         (setq data (cdr data))))
6757     (unless found
6758       ;; If there is no data, that means that we were after the last
6759       ;; article.  The same goes when we can't find any articles
6760       ;; after the current one.
6761       (goto-char (point-max))
6762       (gnus-summary-find-prev))
6763     (gnus-set-mode-line 'summary)
6764     ;; We return how many articles were removed from the summary
6765     ;; buffer as a result of the new limit.
6766     (- total (length gnus-newsgroup-data))))
6767
6768 (defsubst gnus-invisible-cut-children (threads)
6769   (let ((num 0))
6770     (while threads
6771       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6772         (incf num))
6773       (pop threads))
6774     (< num 2)))
6775
6776 (defsubst gnus-cut-thread (thread)
6777   "Go forwards in the thread until we find an article that we want to display."
6778   (when (or (eq gnus-fetch-old-headers 'some)
6779             (eq gnus-fetch-old-headers 'invisible)
6780             (numberp gnus-fetch-old-headers)
6781             (eq gnus-build-sparse-threads 'some)
6782             (eq gnus-build-sparse-threads 'more))
6783     ;; Deal with old-fetched headers and sparse threads.
6784     (while (and
6785             thread
6786             (or
6787              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6788              (gnus-summary-article-ancient-p
6789               (mail-header-number (car thread))))
6790             (if (or (<= (length (cdr thread)) 1)
6791                     (eq gnus-fetch-old-headers 'invisible))
6792                 (setq gnus-newsgroup-limit
6793                       (delq (mail-header-number (car thread))
6794                             gnus-newsgroup-limit)
6795                       thread (cadr thread))
6796               (when (gnus-invisible-cut-children (cdr thread))
6797                 (let ((th (cdr thread)))
6798                   (while th
6799                     (if (memq (mail-header-number (caar th))
6800                               gnus-newsgroup-limit)
6801                         (setq thread (car th)
6802                               th nil)
6803                       (setq th (cdr th))))))))))
6804   thread)
6805
6806 (defun gnus-cut-threads (threads)
6807   "Cut off all uninteresting articles from the beginning of threads."
6808   (when (or (eq gnus-fetch-old-headers 'some)
6809             (eq gnus-fetch-old-headers 'invisible)
6810             (numberp gnus-fetch-old-headers)
6811             (eq gnus-build-sparse-threads 'some)
6812             (eq gnus-build-sparse-threads 'more))
6813     (let ((th threads))
6814       (while th
6815         (setcar th (gnus-cut-thread (car th)))
6816         (setq th (cdr th)))))
6817   ;; Remove nixed out threads.
6818   (delq nil threads))
6819
6820 (defun gnus-summary-initial-limit (&optional show-if-empty)
6821   "Figure out what the initial limit is supposed to be on group entry.
6822 This entails weeding out unwanted dormants, low-scored articles,
6823 fetch-old-headers verbiage, and so on."
6824   ;; Most groups have nothing to remove.
6825   (if (or gnus-inhibit-limiting
6826           (and (null gnus-newsgroup-dormant)
6827                (not (eq gnus-fetch-old-headers 'some))
6828                (not (numberp gnus-fetch-old-headers))
6829                (not (eq gnus-fetch-old-headers 'invisible))
6830                (null gnus-summary-expunge-below)
6831                (not (eq gnus-build-sparse-threads 'some))
6832                (not (eq gnus-build-sparse-threads 'more))
6833                (null gnus-thread-expunge-below)
6834                (not gnus-use-nocem)))
6835       ()                                ; Do nothing.
6836     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6837     (setq gnus-newsgroup-limit nil)
6838     (mapatoms
6839      (lambda (node)
6840        (unless (car (symbol-value node))
6841          ;; These threads have no parents -- they are roots.
6842          (let ((nodes (cdr (symbol-value node)))
6843                thread)
6844            (while nodes
6845              (if (and gnus-thread-expunge-below
6846                       (< (gnus-thread-total-score (car nodes))
6847                          gnus-thread-expunge-below))
6848                  (gnus-expunge-thread (pop nodes))
6849                (setq thread (pop nodes))
6850                (gnus-summary-limit-children thread))))))
6851      gnus-newsgroup-dependencies)
6852     ;; If this limitation resulted in an empty group, we might
6853     ;; pop the previous limit and use it instead.
6854     (when (and (not gnus-newsgroup-limit)
6855                show-if-empty)
6856       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6857     gnus-newsgroup-limit))
6858
6859 (defun gnus-summary-limit-children (thread)
6860   "Return 1 if this subthread is visible and 0 if it is not."
6861   ;; First we get the number of visible children to this thread.  This
6862   ;; is done by recursing down the thread using this function, so this
6863   ;; will really go down to a leaf article first, before slowly
6864   ;; working its way up towards the root.
6865   (when thread
6866     (let ((children
6867            (if (cdr thread)
6868                (apply '+ (mapcar 'gnus-summary-limit-children
6869                                  (cdr thread)))
6870              0))
6871           (number (mail-header-number (car thread)))
6872           score)
6873       (if (and
6874            (not (memq number gnus-newsgroup-marked))
6875            (or
6876             ;; If this article is dormant and has absolutely no visible
6877             ;; children, then this article isn't visible.
6878             (and (memq number gnus-newsgroup-dormant)
6879                  (zerop children))
6880             ;; If this is "fetch-old-headered" and there is no
6881             ;; visible children, then we don't want this article.
6882             (and (or (eq gnus-fetch-old-headers 'some)
6883                      (numberp gnus-fetch-old-headers))
6884                  (gnus-summary-article-ancient-p number)
6885                  (zerop children))
6886             ;; If this is "fetch-old-headered" and `invisible', then
6887             ;; we don't want this article.
6888             (and (eq gnus-fetch-old-headers 'invisible)
6889                  (gnus-summary-article-ancient-p number))
6890             ;; If this is a sparsely inserted article with no children,
6891             ;; we don't want it.
6892             (and (eq gnus-build-sparse-threads 'some)
6893                  (gnus-summary-article-sparse-p number)
6894                  (zerop children))
6895             ;; If we use expunging, and this article is really
6896             ;; low-scored, then we don't want this article.
6897             (when (and gnus-summary-expunge-below
6898                        (< (setq score
6899                                 (or (cdr (assq number gnus-newsgroup-scored))
6900                                     gnus-summary-default-score))
6901                           gnus-summary-expunge-below))
6902               ;; We increase the expunge-tally here, but that has
6903               ;; nothing to do with the limits, really.
6904               (incf gnus-newsgroup-expunged-tally)
6905               ;; We also mark as read here, if that's wanted.
6906               (when (and gnus-summary-mark-below
6907                          (< score gnus-summary-mark-below))
6908                 (setq gnus-newsgroup-unreads
6909                       (delq number gnus-newsgroup-unreads))
6910                 (if gnus-newsgroup-auto-expire
6911                     (push number gnus-newsgroup-expirable)
6912                   (push (cons number gnus-low-score-mark)
6913                         gnus-newsgroup-reads)))
6914               t)
6915             ;; Check NoCeM things.
6916             (if (and gnus-use-nocem
6917                      (gnus-nocem-unwanted-article-p
6918                       (mail-header-id (car thread))))
6919                 (progn
6920                   (setq gnus-newsgroup-unreads
6921                         (delq number gnus-newsgroup-unreads))
6922                   t))))
6923           ;; Nope, invisible article.
6924           0
6925         ;; Ok, this article is to be visible, so we add it to the limit
6926         ;; and return 1.
6927         (push number gnus-newsgroup-limit)
6928         1))))
6929
6930 (defun gnus-expunge-thread (thread)
6931   "Mark all articles in THREAD as read."
6932   (let* ((number (mail-header-number (car thread))))
6933     (incf gnus-newsgroup-expunged-tally)
6934     ;; We also mark as read here, if that's wanted.
6935     (setq gnus-newsgroup-unreads
6936           (delq number gnus-newsgroup-unreads))
6937     (if gnus-newsgroup-auto-expire
6938         (push number gnus-newsgroup-expirable)
6939       (push (cons number gnus-low-score-mark)
6940             gnus-newsgroup-reads)))
6941   ;; Go recursively through all subthreads.
6942   (mapcar 'gnus-expunge-thread (cdr thread)))
6943
6944 ;; Summary article oriented commands
6945
6946 (defun gnus-summary-refer-parent-article (n)
6947   "Refer parent article N times.
6948 If N is negative, go to ancestor -N instead.
6949 The difference between N and the number of articles fetched is returned."
6950   (interactive "p")
6951   (let ((skip 1)
6952         error header ref)
6953     (when (not (natnump n))
6954       (setq skip (abs n)
6955             n 1))
6956     (while (and (> n 0)
6957                 (not error))
6958       (setq header (gnus-summary-article-header))
6959       (if (and (eq (mail-header-number header)
6960                    (cdr gnus-article-current))
6961                (equal gnus-newsgroup-name
6962                       (car gnus-article-current)))
6963           ;; If we try to find the parent of the currently
6964           ;; displayed article, then we take a look at the actual
6965           ;; References header, since this is slightly more
6966           ;; reliable than the References field we got from the
6967           ;; server.
6968           (save-excursion
6969             (set-buffer gnus-original-article-buffer)
6970             (nnheader-narrow-to-headers)
6971             (unless (setq ref (message-fetch-field "references"))
6972               (setq ref (message-fetch-field "in-reply-to")))
6973             (widen))
6974         (setq ref
6975               ;; It's not the current article, so we take a bet on
6976               ;; the value we got from the server.
6977               (mail-header-references header)))
6978       (if (and ref
6979                (not (equal ref "")))
6980           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
6981             (gnus-message 1 "Couldn't find parent"))
6982         (gnus-message 1 "No references in article %d"
6983                       (gnus-summary-article-number))
6984         (setq error t))
6985       (decf n))
6986     (gnus-summary-position-point)
6987     n))
6988
6989 (defun gnus-summary-refer-references ()
6990   "Fetch all articles mentioned in the References header.
6991 Return the number of articles fetched."
6992   (interactive)
6993   (let ((ref (mail-header-references (gnus-summary-article-header)))
6994         (current (gnus-summary-article-number))
6995         (n 0))
6996     (if (or (not ref)
6997             (equal ref ""))
6998         (error "No References in the current article")
6999       ;; For each Message-ID in the References header...
7000       (while (string-match "<[^>]*>" ref)
7001         (incf n)
7002         ;; ... fetch that article.
7003         (gnus-summary-refer-article
7004          (prog1 (match-string 0 ref)
7005            (setq ref (substring ref (match-end 0))))))
7006       (gnus-summary-goto-subject current)
7007       (gnus-summary-position-point)
7008       n)))
7009
7010 (defun gnus-summary-refer-thread (&optional limit)
7011   "Fetch all articles in the current thread.
7012 If LIMIT (the numerical prefix), fetch that many old headers instead
7013 of what's specified by the `gnus-refer-thread-limit' variable."
7014   (interactive "P")
7015   (let ((id (mail-header-id (gnus-summary-article-header)))
7016         (limit (if limit (prefix-numeric-value limit)
7017                  gnus-refer-thread-limit)))
7018     ;; We want to fetch LIMIT *old* headers, but we also have to
7019     ;; re-fetch all the headers in the current buffer, because many of
7020     ;; them may be undisplayed.  So we adjust LIMIT.
7021     (when (numberp limit)
7022       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7023     (unless (eq gnus-fetch-old-headers 'invisible)
7024       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7025       ;; Retrieve the headers and read them in.
7026       (if (eq (gnus-retrieve-headers
7027                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7028               'nov)
7029           (gnus-build-all-threads)
7030         (error "Can't fetch thread from backends that don't support NOV"))
7031       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7032     (gnus-summary-limit-include-thread id)))
7033
7034 (defun gnus-summary-refer-article (message-id)
7035   "Fetch an article specified by MESSAGE-ID."
7036   (interactive "sMessage-ID: ")
7037   (when (and (stringp message-id)
7038              (not (zerop (length message-id))))
7039     ;; Construct the correct Message-ID if necessary.
7040     ;; Suggested by tale@pawl.rpi.edu.
7041     (unless (string-match "^<" message-id)
7042       (setq message-id (concat "<" message-id)))
7043     (unless (string-match ">$" message-id)
7044       (setq message-id (concat message-id ">")))
7045     (let* ((header (gnus-id-to-header message-id))
7046            (sparse (and header
7047                         (gnus-summary-article-sparse-p
7048                          (mail-header-number header))
7049                         (memq (mail-header-number header)
7050                               gnus-newsgroup-limit)))
7051            number)
7052       (cond
7053        ;; If the article is present in the buffer we just go to it.
7054        ((and header
7055              (or (not (gnus-summary-article-sparse-p
7056                        (mail-header-number header)))
7057                  sparse))
7058         (prog1
7059             (gnus-summary-goto-article
7060              (mail-header-number header) nil t)
7061           (when sparse
7062             (gnus-summary-update-article (mail-header-number header)))))
7063        (t
7064         ;; We fetch the article.
7065         (catch 'found
7066           (dolist (gnus-override-method (gnus-refer-article-methods))
7067             (gnus-check-server gnus-override-method)
7068             ;; Fetch the header, and display the article.
7069             (when (setq number (gnus-summary-insert-subject message-id))
7070               (gnus-summary-select-article nil nil nil number)
7071               (throw 'found t)))
7072           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7073
7074 (defun gnus-refer-article-methods ()
7075   "Return a list of referrable methods."
7076   (cond
7077    ;; No method, so we default to current and native.
7078    ((null gnus-refer-article-method)
7079     (list gnus-current-select-method gnus-select-method))
7080    ;; Current.
7081    ((eq 'current gnus-refer-article-method)
7082     (list gnus-current-select-method))
7083    ;; List of select methods.
7084    ((not (and (symbolp (car gnus-refer-article-method))
7085               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7086     (let (out)
7087       (dolist (method gnus-refer-article-method)
7088         (push (if (eq 'current method)
7089                   gnus-current-select-method
7090                 method)
7091               out))
7092       (nreverse out)))
7093    ;; One single select method.
7094    (t
7095     (list gnus-refer-article-method))))
7096
7097 (defun gnus-summary-edit-parameters ()
7098   "Edit the group parameters of the current group."
7099   (interactive)
7100   (gnus-group-edit-group gnus-newsgroup-name 'params))
7101
7102 (defun gnus-summary-customize-parameters ()
7103   "Customize the group parameters of the current group."
7104   (interactive)
7105   (gnus-group-customize gnus-newsgroup-name))
7106
7107 (defun gnus-summary-enter-digest-group (&optional force)
7108   "Enter an nndoc group based on the current article.
7109 If FORCE, force a digest interpretation.  If not, try
7110 to guess what the document format is."
7111   (interactive "P")
7112   (let ((conf gnus-current-window-configuration))
7113     (save-excursion
7114       (gnus-summary-select-article))
7115     (setq gnus-current-window-configuration conf)
7116     (let* ((name (format "%s-%d"
7117                          (gnus-group-prefixed-name
7118                           gnus-newsgroup-name (list 'nndoc ""))
7119                          (save-excursion
7120                            (set-buffer gnus-summary-buffer)
7121                            gnus-current-article)))
7122            (ogroup gnus-newsgroup-name)
7123            (params (append (gnus-info-params (gnus-get-info ogroup))
7124                            (list (cons 'to-group ogroup))
7125                            (list (cons 'save-article-group ogroup))))
7126            (case-fold-search t)
7127            (buf (current-buffer))
7128            dig to-address)
7129       (save-excursion
7130         (set-buffer gnus-original-article-buffer)
7131         ;; Have the digest group inherit the main mail address of
7132         ;; the parent article.
7133         (when (setq to-address (or (message-fetch-field "reply-to")
7134                                    (message-fetch-field "from")))
7135           (setq params (append 
7136                         (list (cons 'to-address 
7137                                     (funcall gnus-decode-encoded-word-function
7138                                              to-address))))))
7139         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7140         (insert-buffer-substring gnus-original-article-buffer)
7141         ;; Remove lines that may lead nndoc to misinterpret the
7142         ;; document type.
7143         (narrow-to-region
7144          (goto-char (point-min))
7145          (or (search-forward "\n\n" nil t) (point)))
7146         (goto-char (point-min))
7147         (delete-matching-lines "^Path:\\|^From ")
7148         (widen))
7149       (unwind-protect
7150           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7151                     (gnus-newsgroup-ephemeral-ignored-charsets
7152                      gnus-newsgroup-ignored-charsets))
7153                 (gnus-group-read-ephemeral-group
7154                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7155                               (nndoc-article-type
7156                                ,(if force 'mbox 'guess))) t))
7157               ;; Make all postings to this group go to the parent group.
7158               (nconc (gnus-info-params (gnus-get-info name))
7159                      params)
7160             ;; Couldn't select this doc group.
7161             (switch-to-buffer buf)
7162             (gnus-set-global-variables)
7163             (gnus-configure-windows 'summary)
7164             (gnus-message 3 "Article couldn't be entered?"))
7165         (kill-buffer dig)))))
7166
7167 (defun gnus-summary-read-document (n)
7168   "Open a new group based on the current article(s).
7169 This will allow you to read digests and other similar
7170 documents as newsgroups.
7171 Obeys the standard process/prefix convention."
7172   (interactive "P")
7173   (let* ((articles (gnus-summary-work-articles n))
7174          (ogroup gnus-newsgroup-name)
7175          (params (append (gnus-info-params (gnus-get-info ogroup))
7176                          (list (cons 'to-group ogroup))))
7177          article group egroup groups vgroup)
7178     (while (setq article (pop articles))
7179       (setq group (format "%s-%d" gnus-newsgroup-name article))
7180       (gnus-summary-remove-process-mark article)
7181       (when (gnus-summary-display-article article)
7182         (save-excursion
7183           (with-temp-buffer
7184             (insert-buffer-substring gnus-original-article-buffer)
7185             ;; Remove some headers that may lead nndoc to make
7186             ;; the wrong guess.
7187             (message-narrow-to-head)
7188             (goto-char (point-min))
7189             (delete-matching-lines "^\\(Path\\):\\|^From ")
7190             (widen)
7191             (if (setq egroup
7192                       (gnus-group-read-ephemeral-group
7193                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7194                                      (nndoc-article-type guess))
7195                        t nil t))
7196                 (progn
7197                   ;; Make all postings to this group go to the parent group.
7198                   (nconc (gnus-info-params (gnus-get-info egroup))
7199                          params)
7200                   (push egroup groups))
7201               ;; Couldn't select this doc group.
7202               (gnus-error 3 "Article couldn't be entered"))))))
7203     ;; Now we have selected all the documents.
7204     (cond
7205      ((not groups)
7206       (error "None of the articles could be interpreted as documents"))
7207      ((gnus-group-read-ephemeral-group
7208        (setq vgroup (format
7209                      "nnvirtual:%s-%s" gnus-newsgroup-name
7210                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7211        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7212        t
7213        (cons (current-buffer) 'summary)))
7214      (t
7215       (error "Couldn't select virtual nndoc group")))))
7216
7217 (defun gnus-summary-isearch-article (&optional regexp-p)
7218   "Do incremental search forward on the current article.
7219 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7220   (interactive "P")
7221   (let* ((gnus-inhibit-treatment t)
7222          (old (gnus-summary-select-article)))
7223     (gnus-configure-windows 'article)
7224     (gnus-eval-in-buffer-window gnus-article-buffer
7225       (save-restriction
7226         (widen)
7227         (when (eq 'old old)
7228           (gnus-article-show-all-headers))
7229         (goto-char (point-min))
7230         (isearch-forward regexp-p)))))
7231
7232 (defun gnus-summary-search-article-forward (regexp &optional backward)
7233   "Search for an article containing REGEXP forward.
7234 If BACKWARD, search backward instead."
7235   (interactive
7236    (list (read-string
7237           (format "Search article %s (regexp%s): "
7238                   (if current-prefix-arg "backward" "forward")
7239                   (if gnus-last-search-regexp
7240                       (concat ", default " gnus-last-search-regexp)
7241                     "")))
7242          current-prefix-arg))
7243   (if (string-equal regexp "")
7244       (setq regexp (or gnus-last-search-regexp ""))
7245     (setq gnus-last-search-regexp regexp)
7246     (setq gnus-article-before-search gnus-current-article))
7247   ;; Intentionally set gnus-last-article.
7248   (setq gnus-last-article gnus-article-before-search)
7249   (let ((gnus-last-article gnus-last-article))
7250     (if (gnus-summary-search-article regexp backward)
7251         (gnus-summary-show-thread)
7252       (error "Search failed: \"%s\"" regexp))))
7253
7254 (defun gnus-summary-search-article-backward (regexp)
7255   "Search for an article containing REGEXP backward."
7256   (interactive
7257    (list (read-string
7258           (format "Search article backward (regexp%s): "
7259                   (if gnus-last-search-regexp
7260                       (concat ", default " gnus-last-search-regexp)
7261                     "")))))
7262   (gnus-summary-search-article-forward regexp 'backward))
7263
7264 (eval-when-compile
7265   (defmacro gnus-summary-search-article-position-point (regexp backward)
7266     "Dehighlight the last matched text and goto the beginning position."
7267     (` (if (and gnus-summary-search-article-matched-data
7268                 (let ((text (caddr gnus-summary-search-article-matched-data))
7269                       (inhibit-read-only t)
7270                       buffer-read-only)
7271                   (delete-region
7272                    (goto-char (car gnus-summary-search-article-matched-data))
7273                    (cadr gnus-summary-search-article-matched-data))
7274                   (insert text)
7275                   (string-match (, regexp) text)))
7276            (if (, backward) (beginning-of-line) (end-of-line))
7277          (goto-char (if (, backward) (point-max) (point-min))))))
7278
7279   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7280     "Place point where X-Face image is displayed."
7281     (if (featurep 'xemacs)
7282         (` (let ((end (if (search-forward "\n\n" nil t)
7283                           (goto-char (1- (point)))
7284                         (point-min)))
7285                  extent)
7286              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7287              (unless (and (re-search-forward "^From:" end t)
7288                           (setq extent (extent-at (point)))
7289                           (extent-begin-glyph extent))
7290                (goto-char (, opoint)))))
7291       (` (let ((end (if (search-forward "\n\n" nil t)
7292                         (goto-char (1- (point)))
7293                       (point-min)))
7294                (start (or (search-backward "\n\n" nil t) (point-min))))
7295            (goto-char
7296             (or (text-property-any start end 'x-face-image t);; x-face-e21
7297                 (text-property-any start end 'x-face-mule-bitmap-image t)
7298                 (, opoint)))))))
7299
7300   (defmacro gnus-summary-search-article-highlight-matched-text
7301     (backward treated x-face)
7302     "Highlight matched text in the function `gnus-summary-search-article'."
7303     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7304              (end (set-marker (make-marker) (match-end 0)))
7305              (inhibit-read-only t)
7306              buffer-read-only)
7307          (unless treated
7308            (let ((,@
7309                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7310                     (mapcar
7311                      (lambda (item) (setq items (delq item items)))
7312                      '(gnus-treat-buttonize
7313                        gnus-treat-fill-article
7314                        gnus-treat-fill-long-lines
7315                        gnus-treat-emphasize
7316                        gnus-treat-highlight-headers
7317                        gnus-treat-highlight-citation
7318                        gnus-treat-highlight-signature
7319                        gnus-treat-overstrike
7320                        gnus-treat-display-xface
7321                        gnus-treat-buttonize-head
7322                        gnus-treat-decode-article-as-default-mime-charset))
7323                     (static-if (featurep 'xemacs)
7324                         items
7325                       (cons '(x-face-mule-delete-x-face-field
7326                               (quote never))
7327                             items))))
7328                  (gnus-treat-display-xface
7329                   (when (, x-face) gnus-treat-display-xface)))
7330              (gnus-article-prepare-mime-display)))
7331          (goto-char (if (, backward) start end))
7332          (when (, x-face)
7333            (gnus-summary-search-article-highlight-goto-x-face (point)))
7334          (setq gnus-summary-search-article-matched-data
7335                (list start end (buffer-substring start end)))
7336          (unless (eq start end);; matched text has been deleted. :-<
7337            (put-text-property start end 'face
7338                               (or (find-face 'isearch)
7339                                   'secondary-selection))))))
7340   )
7341
7342 (defun gnus-summary-search-article (regexp &optional backward)
7343   "Search for an article containing REGEXP.
7344 Optional argument BACKWARD means do search for backward.
7345 `gnus-select-article-hook' is not called during the search."
7346   ;; We have to require this here to make sure that the following
7347   ;; dynamic binding isn't shadowed by autoloading.
7348   (require 'gnus-async)
7349   (require 'gnus-art)
7350   (let ((gnus-select-article-hook nil)  ;Disable hook.
7351         (gnus-article-display-hook nil)
7352         (gnus-article-prepare-hook nil)
7353         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7354         (gnus-use-article-prefetch nil)
7355         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7356         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7357         (sum (current-buffer))
7358         (found nil)
7359         point treated)
7360     (gnus-save-hidden-threads
7361       (static-if (featurep 'xemacs)
7362           (let ((gnus-inhibit-treatment t))
7363             (setq treated (eq 'old (gnus-summary-select-article)))
7364             (when (and treated
7365                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7366                                  (window-live-p (get-buffer-window
7367                                                  gnus-article-buffer t)))))
7368               (gnus-summary-select-article nil t)
7369               (setq treated nil)))
7370         (let ((gnus-inhibit-treatment t)
7371               (x-face-mule-delete-x-face-field 'never))
7372           (setq treated (eq 'old (gnus-summary-select-article)))
7373           (when (and treated
7374                      (not
7375                       (and (gnus-buffer-live-p gnus-article-buffer)
7376                            (window-live-p (get-buffer-window
7377                                            gnus-article-buffer t))
7378                            (or (not (string-match "^\\^X-Face:" regexp))
7379                                (with-current-buffer gnus-article-buffer
7380                                  gnus-summary-search-article-matched-data)))))
7381             (gnus-summary-select-article nil t)
7382             (setq treated nil))))
7383       (set-buffer gnus-article-buffer)
7384       (widen)
7385       (if treated
7386           (progn
7387             (gnus-article-show-all-headers)
7388             (gnus-summary-search-article-position-point regexp backward))
7389         (goto-char (if backward (point-max) (point-min))))
7390       (while (not found)
7391         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7392         (if (if backward
7393                 (re-search-backward regexp nil t)
7394               (re-search-forward regexp nil t))
7395             ;; We found the regexp.
7396             (progn
7397               (gnus-summary-search-article-highlight-matched-text
7398                backward treated (string-match "^\\^X-Face:" regexp))
7399               (setq found 'found)
7400               (forward-line
7401                (/ (- 2 (window-height
7402                         (get-buffer-window gnus-article-buffer t)))
7403                   2))
7404               (set-window-start
7405                (get-buffer-window (current-buffer))
7406                (point))
7407               (set-buffer sum)
7408               (setq point (point)))
7409           ;; We didn't find it, so we go to the next article.
7410           (set-buffer sum)
7411           (setq found 'not)
7412           (while (eq found 'not)
7413             (if (not (if backward (gnus-summary-find-prev)
7414                        (gnus-summary-find-next)))
7415                 ;; No more articles.
7416                 (setq found t)
7417               ;; Select the next article and adjust point.
7418               (unless (gnus-summary-article-sparse-p
7419                        (gnus-summary-article-number))
7420                 (setq found nil)
7421                 (let ((gnus-inhibit-treatment t))
7422                   (gnus-summary-select-article))
7423                 (setq treated nil)
7424                 (set-buffer gnus-article-buffer)
7425                 (widen)
7426                 (goto-char (if backward (point-max) (point-min))))))))
7427       (gnus-message 7 ""))
7428     ;; Return whether we found the regexp.
7429     (when (eq found 'found)
7430       (goto-char point)
7431       (gnus-summary-show-thread)
7432       (gnus-summary-goto-subject gnus-current-article)
7433       (gnus-summary-position-point)
7434       t)))
7435
7436 (defun gnus-summary-find-matching (header regexp &optional backward unread
7437                                           not-case-fold)
7438   "Return a list of all articles that match REGEXP on HEADER.
7439 The search stars on the current article and goes forwards unless
7440 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7441 If UNREAD is non-nil, only unread articles will
7442 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7443 in the comparisons."
7444   (let ((data (if (eq backward 'all) gnus-newsgroup-data
7445                 (gnus-data-find-list
7446                  (gnus-summary-article-number) (gnus-data-list backward))))
7447         (case-fold-search (not not-case-fold))
7448         articles d func)
7449     (if (consp header)
7450         (if (eq (car header) 'extra)
7451             (setq func
7452                   `(lambda (h)
7453                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7454                          "")))
7455           (error "%s is an invalid header" header))
7456       (unless (fboundp (intern (concat "mail-header-" header)))
7457         (error "%s is not a valid header" header))
7458       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7459     (while data
7460       (setq d (car data))
7461       (and (or (not unread)             ; We want all articles...
7462                (gnus-data-unread-p d))  ; Or just unreads.
7463            (vectorp (gnus-data-header d)) ; It's not a pseudo.
7464            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
7465            (push (gnus-data-number d) articles)) ; Success!
7466       (setq data (cdr data)))
7467     (nreverse articles)))
7468
7469 (defun gnus-summary-execute-command (header regexp command &optional backward)
7470   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7471 If HEADER is an empty string (or nil), the match is done on the entire
7472 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7473   (interactive
7474    (list (let ((completion-ignore-case t))
7475            (completing-read
7476             "Header name: "
7477             (mapcar (lambda (string) (list string))
7478                     '("Number" "Subject" "From" "Lines" "Date"
7479                       "Message-ID" "Xref" "References" "Body"))
7480             nil 'require-match))
7481          (read-string "Regexp: ")
7482          (read-key-sequence "Command: ")
7483          current-prefix-arg))
7484   (when (equal header "Body")
7485     (setq header ""))
7486   ;; Hidden thread subtrees must be searched as well.
7487   (gnus-summary-show-all-threads)
7488   ;; We don't want to change current point nor window configuration.
7489   (save-excursion
7490     (save-window-excursion
7491       (gnus-message 6 "Executing %s..." (key-description command))
7492       ;; We'd like to execute COMMAND interactively so as to give arguments.
7493       (gnus-execute header regexp
7494                     `(call-interactively ',(key-binding command))
7495                     backward)
7496       (gnus-message 6 "Executing %s...done" (key-description command)))))
7497
7498 (defun gnus-summary-beginning-of-article ()
7499   "Scroll the article back to the beginning."
7500   (interactive)
7501   (gnus-summary-select-article)
7502   (gnus-configure-windows 'article)
7503   (gnus-eval-in-buffer-window gnus-article-buffer
7504     (widen)
7505     (goto-char (point-min))
7506     (when gnus-page-broken
7507       (gnus-narrow-to-page))))
7508
7509 (defun gnus-summary-end-of-article ()
7510   "Scroll to the end of the article."
7511   (interactive)
7512   (gnus-summary-select-article)
7513   (gnus-configure-windows 'article)
7514   (gnus-eval-in-buffer-window gnus-article-buffer
7515     (widen)
7516     (goto-char (point-max))
7517     (recenter -3)
7518     (when gnus-page-broken
7519       (gnus-narrow-to-page))))
7520
7521 (defun gnus-summary-print-article (&optional filename n)
7522   "Generate and print a PostScript image of the N next (mail) articles.
7523
7524 If N is negative, print the N previous articles.  If N is nil and articles
7525 have been marked with the process mark, print these instead.
7526
7527 If the optional first argument FILENAME is nil, send the image to the
7528 printer.  If FILENAME is a string, save the PostScript image in a file with
7529 that name.  If FILENAME is a number, prompt the user for the name of the file
7530 to save in."
7531   (interactive (list (ps-print-preprint current-prefix-arg)
7532                      current-prefix-arg))
7533   (dolist (article (gnus-summary-work-articles n))
7534     (gnus-summary-select-article nil nil 'pseudo article)
7535     (gnus-eval-in-buffer-window gnus-article-buffer
7536       (let ((buffer (generate-new-buffer " *print*")))
7537         (unwind-protect
7538             (progn
7539               (copy-to-buffer buffer (point-min) (point-max))
7540               (set-buffer buffer)
7541               (gnus-article-delete-invisible-text)
7542               (let ((ps-left-header
7543                      (list
7544                       (concat "("
7545                               (mail-header-subject gnus-current-headers) ")")
7546                       (concat "("
7547                               (mail-header-from gnus-current-headers) ")")))
7548                     (ps-right-header
7549                      (list
7550                       "/pagenumberstring load"
7551                       (concat "("
7552                               (mail-header-date gnus-current-headers) ")"))))
7553                 (gnus-run-hooks 'gnus-ps-print-hook)
7554                 (save-excursion
7555                   (ps-print-buffer-with-faces filename))))
7556           (kill-buffer buffer))))))
7557
7558 (defun gnus-summary-show-article (&optional arg)
7559   "Force re-fetching of the current article.
7560 If ARG (the prefix) is a number, show the article with the charset
7561 defined in `gnus-summary-show-article-charset-alist', or the charset
7562 inputed.
7563 If ARG (the prefix) is non-nil and not a number, show the raw article
7564 without any article massaging functions being run."
7565   (interactive "P")
7566   (cond
7567    ((numberp arg)
7568     (let ((gnus-newsgroup-charset
7569            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7570                (read-coding-system "Charset: ")))
7571           (gnus-newsgroup-ignored-charsets 'gnus-all))
7572       (gnus-summary-select-article nil 'force)
7573       (let ((deps gnus-newsgroup-dependencies)
7574             head header)
7575         (save-excursion
7576           (set-buffer gnus-original-article-buffer)
7577           (save-restriction
7578             (message-narrow-to-head)
7579             (setq head (buffer-string)))
7580           (with-temp-buffer
7581             (insert (format "211 %d Article retrieved.\n"
7582                             (cdr gnus-article-current)))
7583             (insert head)
7584             (insert ".\n")
7585             (let ((nntp-server-buffer (current-buffer)))
7586               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7587         (gnus-data-set-header
7588          (gnus-data-find (cdr gnus-article-current))
7589          header)
7590         (gnus-summary-update-article-line
7591          (cdr gnus-article-current) header))))
7592    ((not arg)
7593     ;; Select the article the normal way.
7594     (gnus-summary-select-article nil 'force))
7595    (t
7596     ;; We have to require this here to make sure that the following
7597     ;; dynamic binding isn't shadowed by autoloading.
7598     (require 'gnus-async)
7599     (require 'gnus-art)
7600     ;; Bind the article treatment functions to nil.
7601     (let ((gnus-have-all-headers t)
7602           gnus-article-display-hook
7603           gnus-article-prepare-hook
7604           gnus-article-decode-hook
7605           gnus-break-pages
7606           gnus-show-mime)
7607       (gnus-summary-select-article nil 'force))))
7608   (gnus-summary-goto-subject gnus-current-article)
7609   (gnus-summary-position-point))
7610
7611 (defun gnus-summary-verbose-headers (&optional arg)
7612   "Toggle permanent full header display.
7613 If ARG is a positive number, turn header display on.
7614 If ARG is a negative number, turn header display off."
7615   (interactive "P")
7616   (setq gnus-show-all-headers
7617         (cond ((or (not (numberp arg))
7618                    (zerop arg))
7619                (not gnus-show-all-headers))
7620               ((natnump arg)
7621                t)))
7622   (gnus-summary-show-article))
7623
7624 (defun gnus-summary-toggle-header (&optional arg)
7625   "Show the headers if they are hidden, or hide them if they are shown.
7626 If ARG is a positive number, show the entire header.
7627 If ARG is a negative number, hide the unwanted header lines."
7628   (interactive "P")
7629   (save-excursion
7630     (set-buffer gnus-article-buffer)
7631     (save-restriction
7632       (let* ((buffer-read-only nil)
7633              (inhibit-point-motion-hooks t)
7634              hidden e)
7635         (setq hidden
7636               (if (numberp arg)
7637                   (>= arg 0)
7638                 (save-restriction
7639                   (article-narrow-to-head)
7640                   (gnus-article-hidden-text-p 'headers))))
7641         (goto-char (point-min))
7642         (when (search-forward "\n\n" nil t)
7643           (delete-region (point-min) (1- (point))))
7644         (goto-char (point-min))
7645         (save-excursion
7646           (set-buffer gnus-original-article-buffer)
7647           (goto-char (point-min))
7648           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7649         (insert-buffer-substring gnus-original-article-buffer 1 e)
7650         (save-restriction
7651           (narrow-to-region (point-min) (point))
7652           (article-decode-encoded-words)
7653           (if  hidden
7654               (let ((gnus-treat-hide-headers nil)
7655                     (gnus-treat-hide-boring-headers nil))
7656                 (setq gnus-article-wash-types
7657                       (delq 'headers gnus-article-wash-types))
7658                 (gnus-treat-article 'head))
7659             (gnus-treat-article 'head)))
7660         (gnus-set-mode-line 'article)))))
7661
7662 (defun gnus-summary-show-all-headers ()
7663   "Make all header lines visible."
7664   (interactive)
7665   (gnus-article-show-all-headers))
7666
7667 (defun gnus-summary-toggle-mime (&optional arg)
7668   "Toggle MIME processing.
7669 If ARG is a positive number, turn MIME processing on."
7670   (interactive "P")
7671   (setq gnus-show-mime
7672         (if (null arg)
7673             (not gnus-show-mime)
7674           (> (prefix-numeric-value arg) 0)))
7675   (gnus-summary-select-article t 'force))
7676
7677 (defun gnus-summary-caesar-message (&optional arg)
7678   "Caesar rotate the current article by 13.
7679 The numerical prefix specifies how many places to rotate each letter
7680 forward."
7681   (interactive "P")
7682   (gnus-summary-select-article)
7683   (let ((mail-header-separator ""))
7684     (gnus-eval-in-buffer-window gnus-article-buffer
7685       (save-restriction
7686         (widen)
7687         (let ((start (window-start))
7688               buffer-read-only)
7689           (message-caesar-buffer-body arg)
7690           (set-window-start (get-buffer-window (current-buffer)) start))))))
7691
7692 (defun gnus-summary-stop-page-breaking ()
7693   "Stop page breaking in the current article."
7694   (interactive)
7695   (gnus-summary-select-article)
7696   (gnus-eval-in-buffer-window gnus-article-buffer
7697     (widen)
7698     (when (gnus-visual-p 'page-marker)
7699       (let ((buffer-read-only nil))
7700         (gnus-remove-text-with-property 'gnus-prev)
7701         (gnus-remove-text-with-property 'gnus-next))
7702       (setq gnus-page-broken nil))))
7703
7704 (defun gnus-summary-move-article (&optional n to-newsgroup
7705                                             select-method action)
7706   "Move the current article to a different newsgroup.
7707 If N is a positive number, move the N next articles.
7708 If N is a negative number, move the N previous articles.
7709 If N is nil and any articles have been marked with the process mark,
7710 move those articles instead.
7711 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7712 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7713 re-spool using this method.
7714
7715 For this function to work, both the current newsgroup and the
7716 newsgroup that you want to move to have to support the `request-move'
7717 and `request-accept' functions.
7718
7719 ACTION can be either `move' (the default), `crosspost' or `copy'."
7720   (interactive "P")
7721   (unless action
7722     (setq action 'move))
7723   ;; Disable marking as read.
7724   (let (gnus-mark-article-hook)
7725     (save-window-excursion
7726       (gnus-summary-select-article)))
7727   ;; Check whether the source group supports the required functions.
7728   (cond ((and (eq action 'move)
7729               (not (gnus-check-backend-function
7730                     'request-move-article gnus-newsgroup-name)))
7731          (error "The current group does not support article moving"))
7732         ((and (eq action 'crosspost)
7733               (not (gnus-check-backend-function
7734                     'request-replace-article gnus-newsgroup-name)))
7735          (error "The current group does not support article editing")))
7736   (let ((articles (gnus-summary-work-articles n))
7737         (prefix (if (gnus-check-backend-function
7738                     'request-move-article gnus-newsgroup-name)
7739                     (gnus-group-real-prefix gnus-newsgroup-name)
7740                   ""))
7741         (names '((move "Move" "Moving")
7742                  (copy "Copy" "Copying")
7743                  (crosspost "Crosspost" "Crossposting")))
7744         (copy-buf (save-excursion
7745                     (nnheader-set-temp-buffer " *copy article*")))
7746         (default-marks gnus-article-mark-lists)
7747         (no-expire-marks (delete '(expirable . expire)
7748                                  (copy-sequence gnus-article-mark-lists)))
7749         art-group to-method new-xref article to-groups)
7750     (unless (assq action names)
7751       (error "Unknown action %s" action))
7752     ;; Read the newsgroup name.
7753     (when (and (not to-newsgroup)
7754                (not select-method))
7755       (setq to-newsgroup
7756             (gnus-read-move-group-name
7757              (cadr (assq action names))
7758              (symbol-value (intern (format "gnus-current-%s-group" action)))
7759              articles prefix))
7760       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7761     (setq to-method (or select-method
7762                         (gnus-server-to-method
7763                          (gnus-group-method to-newsgroup))))
7764     ;; Check the method we are to move this article to...
7765     (unless (gnus-check-backend-function
7766              'request-accept-article (car to-method))
7767       (error "%s does not support article copying" (car to-method)))
7768     (unless (gnus-check-server to-method)
7769       (error "Can't open server %s" (car to-method)))
7770     (gnus-message 6 "%s to %s: %s..."
7771                   (caddr (assq action names))
7772                   (or (car select-method) to-newsgroup) articles)
7773     (while articles
7774       (setq article (pop articles))
7775       (setq
7776        art-group
7777        (cond
7778         ;; Move the article.
7779         ((eq action 'move)
7780          ;; Remove this article from future suppression.
7781          (gnus-dup-unsuppress-article article)
7782          (gnus-request-move-article
7783           article                       ; Article to move
7784           gnus-newsgroup-name           ; From newsgroup
7785           (nth 1 (gnus-find-method-for-group
7786                   gnus-newsgroup-name)) ; Server
7787           (list 'gnus-request-accept-article
7788                 to-newsgroup (list 'quote select-method)
7789                 (not articles) t)       ; Accept form
7790           (not articles)))              ; Only save nov last time
7791         ;; Copy the article.
7792         ((eq action 'copy)
7793          (save-excursion
7794            (set-buffer copy-buf)
7795            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7796              (gnus-request-accept-article
7797               to-newsgroup select-method (not articles) t))))
7798         ;; Crosspost the article.
7799         ((eq action 'crosspost)
7800          (let ((xref (message-tokenize-header
7801                       (mail-header-xref (gnus-summary-article-header article))
7802                       " ")))
7803            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7804                                   ":" article))
7805            (unless xref
7806              (setq xref (list (system-name))))
7807            (setq new-xref
7808                  (concat
7809                   (mapconcat 'identity
7810                              (delete "Xref:" (delete new-xref xref))
7811                              " ")
7812                   " " new-xref))
7813            (save-excursion
7814              (set-buffer copy-buf)
7815              ;; First put the article in the destination group.
7816              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7817              (when (consp (setq art-group
7818                                 (gnus-request-accept-article
7819                                  to-newsgroup select-method (not articles))))
7820                (setq new-xref (concat new-xref " " (car art-group)
7821                                       ":" (cdr art-group)))
7822                ;; Now we have the new Xrefs header, so we insert
7823                ;; it and replace the new article.
7824                (nnheader-replace-header "Xref" new-xref)
7825                (gnus-request-replace-article
7826                 (cdr art-group) to-newsgroup (current-buffer))
7827                art-group))))))
7828       (cond
7829        ((not art-group)
7830         (gnus-message 1 "Couldn't %s article %s: %s"
7831                       (cadr (assq action names)) article
7832                       (nnheader-get-report (car to-method))))
7833        ((eq art-group 'junk)
7834         (when (eq action 'move)
7835           (gnus-summary-mark-article article gnus-canceled-mark)
7836           (gnus-message 4 "Deleted article %s" article)))
7837        (t
7838         (let* ((pto-group (gnus-group-prefixed-name
7839                            (car art-group) to-method))
7840                (entry
7841                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7842                (info (nth 2 entry))
7843                (to-group (gnus-info-group info))
7844                to-marks)
7845           ;; Update the group that has been moved to.
7846           (when (and info
7847                      (memq action '(move copy)))
7848             (unless (member to-group to-groups)
7849               (push to-group to-groups))
7850
7851             (unless (memq article gnus-newsgroup-unreads)
7852               (push 'read to-marks)
7853               (gnus-info-set-read
7854                info (gnus-add-to-range (gnus-info-read info)
7855                                        (list (cdr art-group)))))
7856
7857             ;; See whether the article is to be put in the cache.
7858             (let ((marks (if (gnus-group-auto-expirable-p to-group)
7859                              default-marks
7860                            no-expire-marks))
7861                   (to-article (cdr art-group)))
7862
7863               ;; Enter the article into the cache in the new group,
7864               ;; if that is required.
7865               (when gnus-use-cache
7866                 (gnus-cache-possibly-enter-article
7867                  to-group to-article
7868                  (let ((header (copy-sequence
7869                                 (gnus-summary-article-header article))))
7870                    (mail-header-set-number header to-article)
7871                    header)
7872                  (memq article gnus-newsgroup-marked)
7873                  (memq article gnus-newsgroup-dormant)
7874                  (memq article gnus-newsgroup-unreads)))
7875
7876               (when gnus-preserve-marks
7877                 ;; Copy any marks over to the new group.
7878                 (when (and (equal to-group gnus-newsgroup-name)
7879                            (not (memq article gnus-newsgroup-unreads)))
7880                   ;; Mark this article as read in this group.
7881                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7882                   (setcdr (gnus-active to-group) to-article)
7883                   (setcdr gnus-newsgroup-active to-article))
7884
7885                 (while marks
7886                   (when (memq article (symbol-value
7887                                        (intern (format "gnus-newsgroup-%s"
7888                                                        (caar marks)))))
7889                     (push (cdar marks) to-marks)
7890                     ;; If the other group is the same as this group,
7891                     ;; then we have to add the mark to the list.
7892                     (when (equal to-group gnus-newsgroup-name)
7893                       (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7894                            (cons to-article
7895                                  (symbol-value
7896                                   (intern (format "gnus-newsgroup-%s"
7897                                                   (caar marks)))))))
7898                     ;; Copy the marks to other group.
7899                     (gnus-add-marked-articles
7900                      to-group (cdar marks) (list to-article) info))
7901                   (setq marks (cdr marks)))
7902
7903                 (gnus-request-set-mark to-group (list (list (list to-article)
7904                                                             'set
7905                                                             to-marks))))
7906
7907               (gnus-dribble-enter
7908                (concat "(gnus-group-set-info '"
7909                        (gnus-prin1-to-string (gnus-get-info to-group))
7910                        ")"))))
7911
7912           ;; Update the Xref header in this article to point to
7913           ;; the new crossposted article we have just created.
7914           (when (eq action 'crosspost)
7915             (save-excursion
7916               (set-buffer copy-buf)
7917               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7918               (nnheader-replace-header "Xref" new-xref)
7919               (gnus-request-replace-article
7920                article gnus-newsgroup-name (current-buffer)))))
7921
7922         ;;;!!!Why is this necessary?
7923         (set-buffer gnus-summary-buffer)
7924
7925         (gnus-summary-goto-subject article)
7926         (when (eq action 'move)
7927           (gnus-summary-mark-article article gnus-canceled-mark))))
7928       (gnus-summary-remove-process-mark article))
7929     ;; Re-activate all groups that have been moved to.
7930     (while to-groups
7931       (save-excursion
7932         (set-buffer gnus-group-buffer)
7933         (when (gnus-group-goto-group (car to-groups) t)
7934           (gnus-group-get-new-news-this-group 1 t))
7935         (pop to-groups)))
7936
7937     (gnus-kill-buffer copy-buf)
7938     (gnus-summary-position-point)
7939     (gnus-set-mode-line 'summary)))
7940
7941 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7942   "Move the current article to a different newsgroup.
7943 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7944 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7945 re-spool using this method."
7946   (interactive "P")
7947   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7948
7949 (defun gnus-summary-crosspost-article (&optional n)
7950   "Crosspost the current article to some other group."
7951   (interactive "P")
7952   (gnus-summary-move-article n nil nil 'crosspost))
7953
7954 (defcustom gnus-summary-respool-default-method nil
7955   "Default method for respooling an article.
7956 If nil, use to the current newsgroup method."
7957   :type '(choice (gnus-select-method :value (nnml ""))
7958                  (const nil))
7959   :group 'gnus-summary-mail)
7960
7961 (defun gnus-summary-respool-article (&optional n method)
7962   "Respool the current article.
7963 The article will be squeezed through the mail spooling process again,
7964 which means that it will be put in some mail newsgroup or other
7965 depending on `nnmail-split-methods'.
7966 If N is a positive number, respool the N next articles.
7967 If N is a negative number, respool the N previous articles.
7968 If N is nil and any articles have been marked with the process mark,
7969 respool those articles instead.
7970
7971 Respooling can be done both from mail groups and \"real\" newsgroups.
7972 In the former case, the articles in question will be moved from the
7973 current group into whatever groups they are destined to.  In the
7974 latter case, they will be copied into the relevant groups."
7975   (interactive
7976    (list current-prefix-arg
7977          (let* ((methods (gnus-methods-using 'respool))
7978                 (methname
7979                  (symbol-name (or gnus-summary-respool-default-method
7980                                   (car (gnus-find-method-for-group
7981                                         gnus-newsgroup-name)))))
7982                 (method
7983                  (gnus-completing-read
7984                   methname "What backend do you want to use when respooling?"
7985                   methods nil t nil 'gnus-mail-method-history))
7986                 ms)
7987            (cond
7988             ((zerop (length (setq ms (gnus-servers-using-backend
7989                                       (intern method)))))
7990              (list (intern method) ""))
7991             ((= 1 (length ms))
7992              (car ms))
7993             (t
7994              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7995                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7996                            ms-alist))))))))
7997   (unless method
7998     (error "No method given for respooling"))
7999   (if (assoc (symbol-name
8000               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8001              (gnus-methods-using 'respool))
8002       (gnus-summary-move-article n nil method)
8003     (gnus-summary-copy-article n nil method)))
8004
8005 (defun gnus-summary-import-article (file)
8006   "Import an arbitrary file into a mail newsgroup."
8007   (interactive "fImport file: ")
8008   (let ((group gnus-newsgroup-name)
8009         (now (current-time))
8010         atts lines)
8011     (unless (gnus-check-backend-function 'request-accept-article group)
8012       (error "%s does not support article importing" group))
8013     (or (file-readable-p file)
8014         (not (file-regular-p file))
8015         (error "Can't read %s" file))
8016     (save-excursion
8017       (set-buffer (gnus-get-buffer-create " *import file*"))
8018       (erase-buffer)
8019       (nnheader-insert-file-contents file)
8020       (goto-char (point-min))
8021       (unless (nnheader-article-p)
8022         ;; This doesn't look like an article, so we fudge some headers.
8023         (setq atts (file-attributes file)
8024               lines (count-lines (point-min) (point-max)))
8025         (insert "From: " (read-string "From: ") "\n"
8026                 "Subject: " (read-string "Subject: ") "\n"
8027                 "Date: " (message-make-date (nth 5 atts))
8028                 "\n"
8029                 "Message-ID: " (message-make-message-id) "\n"
8030                 "Lines: " (int-to-string lines) "\n"
8031                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8032       (gnus-request-accept-article group nil t)
8033       (kill-buffer (current-buffer)))))
8034
8035 (defun gnus-summary-article-posted-p ()
8036   "Say whether the current (mail) article is available from news as well.
8037 This will be the case if the article has both been mailed and posted."
8038   (interactive)
8039   (let ((id (mail-header-references (gnus-summary-article-header)))
8040         (gnus-override-method (car (gnus-refer-article-methods))))
8041     (if (gnus-request-head id "")
8042         (gnus-message 2 "The current message was found on %s"
8043                       gnus-override-method)
8044       (gnus-message 2 "The current message couldn't be found on %s"
8045                     gnus-override-method)
8046       nil)))
8047
8048 (defun gnus-summary-expire-articles (&optional now)
8049   "Expire all articles that are marked as expirable in the current group."
8050   (interactive)
8051   (when (gnus-check-backend-function
8052          'request-expire-articles gnus-newsgroup-name)
8053     ;; This backend supports expiry.
8054     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8055            (expirable (if total
8056                           (progn
8057                             ;; We need to update the info for
8058                             ;; this group for `gnus-list-of-read-articles'
8059                             ;; to give us the right answer.
8060                             (gnus-run-hooks 'gnus-exit-group-hook)
8061                             (gnus-summary-update-info)
8062                             (gnus-list-of-read-articles gnus-newsgroup-name))
8063                         (setq gnus-newsgroup-expirable
8064                               (sort gnus-newsgroup-expirable '<))))
8065            (expiry-wait (if now 'immediate
8066                           (gnus-group-find-parameter
8067                            gnus-newsgroup-name 'expiry-wait)))
8068            (nnmail-expiry-target
8069             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8070                 nnmail-expiry-target))
8071            es)
8072       (when expirable
8073         ;; There are expirable articles in this group, so we run them
8074         ;; through the expiry process.
8075         (gnus-message 6 "Expiring articles...")
8076         (unless (gnus-check-group gnus-newsgroup-name)
8077           (error "Can't open server for %s" gnus-newsgroup-name))
8078         ;; The list of articles that weren't expired is returned.
8079         (save-excursion
8080           (if expiry-wait
8081               (let ((nnmail-expiry-wait-function nil)
8082                     (nnmail-expiry-wait expiry-wait))
8083                 (setq es (gnus-request-expire-articles
8084                           expirable gnus-newsgroup-name)))
8085             (setq es (gnus-request-expire-articles
8086                       expirable gnus-newsgroup-name)))
8087           (unless total
8088             (setq gnus-newsgroup-expirable es))
8089           ;; We go through the old list of expirable, and mark all
8090           ;; really expired articles as nonexistent.
8091           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8092             (let ((gnus-use-cache nil))
8093               (while expirable
8094                 (unless (memq (car expirable) es)
8095                   (when (gnus-data-find (car expirable))
8096                     (gnus-summary-mark-article
8097                      (car expirable) gnus-canceled-mark)))
8098                 (setq expirable (cdr expirable))))))
8099         (gnus-message 6 "Expiring articles...done")))))
8100
8101 (defun gnus-summary-expire-articles-now ()
8102   "Expunge all expirable articles in the current group.
8103 This means that *all* articles that are marked as expirable will be
8104 deleted forever, right now."
8105   (interactive)
8106   (or gnus-expert-user
8107       (gnus-yes-or-no-p
8108        "Are you really, really, really sure you want to delete all these messages? ")
8109       (error "Phew!"))
8110   (gnus-summary-expire-articles t))
8111
8112 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8113 (defun gnus-summary-delete-article (&optional n)
8114   "Delete the N next (mail) articles.
8115 This command actually deletes articles.  This is not a marking
8116 command.  The article will disappear forever from your life, never to
8117 return.
8118 If N is negative, delete backwards.
8119 If N is nil and articles have been marked with the process mark,
8120 delete these instead."
8121   (interactive "P")
8122   (unless (gnus-check-backend-function 'request-expire-articles
8123                                        gnus-newsgroup-name)
8124     (error "The current newsgroup does not support article deletion"))
8125   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8126     (error "Couldn't open server"))
8127   ;; Compute the list of articles to delete.
8128   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8129         not-deleted)
8130     (if (and gnus-novice-user
8131              (not (gnus-yes-or-no-p
8132                    (format "Do you really want to delete %s forever? "
8133                            (if (> (length articles) 1)
8134                                (format "these %s articles" (length articles))
8135                              "this article")))))
8136         ()
8137       ;; Delete the articles.
8138       (setq not-deleted (gnus-request-expire-articles
8139                          articles gnus-newsgroup-name 'force))
8140       (while articles
8141         (gnus-summary-remove-process-mark (car articles))
8142         ;; The backend might not have been able to delete the article
8143         ;; after all.
8144         (unless (memq (car articles) not-deleted)
8145           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8146         (setq articles (cdr articles)))
8147       (when not-deleted
8148         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8149     (gnus-summary-position-point)
8150     (gnus-set-mode-line 'summary)
8151     not-deleted))
8152
8153 (defun gnus-summary-edit-article (&optional force)
8154   "Edit the current article.
8155 This will have permanent effect only in mail groups.
8156 If FORCE is non-nil, allow editing of articles even in read-only
8157 groups."
8158   (interactive "P")
8159   (save-excursion
8160     (set-buffer gnus-summary-buffer)
8161     (let ((mail-parse-charset gnus-newsgroup-charset)
8162           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8163       (gnus-set-global-variables)
8164       (when (and (not force)
8165                  (gnus-group-read-only-p))
8166         (error "The current newsgroup does not support article editing"))
8167       (gnus-summary-show-article t)
8168       (gnus-article-edit-article
8169        'ignore
8170        `(lambda (no-highlight)
8171           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8172                 (message-options message-options)
8173                 (message-options-set-recipient)
8174                 (mail-parse-ignored-charsets
8175                  ',gnus-newsgroup-ignored-charsets))
8176             (gnus-summary-edit-article-done
8177              ,(or (mail-header-references gnus-current-headers) "")
8178              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8179
8180 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8181
8182 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8183                                                  no-highlight)
8184   "Make edits to the current article permanent."
8185   (interactive)
8186   (save-excursion
8187     ;; The buffer restriction contains the entire article if it exists.
8188     (when (article-goto-body)
8189       (let ((lines (count-lines (point) (point-max)))
8190             (length (- (point-max) (point)))
8191             (case-fold-search t)
8192             (body (copy-marker (point))))
8193         (goto-char (point-min))
8194         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8195           (delete-region (match-beginning 1) (match-end 1))
8196           (insert (number-to-string length)))
8197         (goto-char (point-min))
8198         (when (re-search-forward
8199                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8200           (delete-region (match-beginning 1) (match-end 1))
8201           (insert (number-to-string length)))
8202         (goto-char (point-min))
8203         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8204           (delete-region (match-beginning 1) (match-end 1))
8205           (insert (number-to-string lines))))))
8206   ;; Replace the article.
8207   (let ((buf (current-buffer)))
8208     (with-temp-buffer
8209       (insert-buffer-substring buf)
8210       
8211       (if (and (not read-only)
8212                (not (gnus-request-replace-article
8213                      (cdr gnus-article-current) (car gnus-article-current)
8214                      (current-buffer) t)))
8215           (error "Couldn't replace article")
8216         ;; Update the summary buffer.
8217         (if (and references
8218                  (equal (message-tokenize-header references " ")
8219                         (message-tokenize-header
8220                          (or (message-fetch-field "references") "") " ")))
8221             ;; We only have to update this line.
8222             (save-excursion
8223               (save-restriction
8224                 (message-narrow-to-head)
8225                 (let ((head (buffer-string))
8226                       header)
8227                   (with-temp-buffer
8228                     (insert (format "211 %d Article retrieved.\n"
8229                                     (cdr gnus-article-current)))
8230                     (insert head)
8231                     (insert ".\n")
8232                     (let ((nntp-server-buffer (current-buffer)))
8233                       (setq header (car (gnus-get-newsgroup-headers
8234                                          (save-excursion
8235                                            (set-buffer gnus-summary-buffer)
8236                                            gnus-newsgroup-dependencies)
8237                                          t))))
8238                     (save-excursion
8239                       (set-buffer gnus-summary-buffer)
8240                       (gnus-data-set-header
8241                        (gnus-data-find (cdr gnus-article-current))
8242                        header)
8243                       (gnus-summary-update-article-line
8244                        (cdr gnus-article-current) header))))))
8245           ;; Update threads.
8246           (set-buffer (or buffer gnus-summary-buffer))
8247           (gnus-summary-update-article (cdr gnus-article-current)))
8248         ;; Prettify the article buffer again.
8249         (unless no-highlight
8250           (save-excursion
8251             (set-buffer gnus-article-buffer)
8252             ;;;!!! Fix this -- article should be rehighlighted.
8253             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8254             (set-buffer gnus-original-article-buffer)
8255             (gnus-request-article
8256              (cdr gnus-article-current)
8257              (car gnus-article-current) (current-buffer))))
8258         ;; Prettify the summary buffer line.
8259         (when (gnus-visual-p 'summary-highlight 'highlight)
8260           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8261
8262 (defun gnus-summary-edit-wash (key)
8263   "Perform editing command KEY in the article buffer."
8264   (interactive
8265    (list
8266     (progn
8267       (message "%s" (concat (this-command-keys) "- "))
8268       (read-char))))
8269   (message "")
8270   (gnus-summary-edit-article)
8271   (execute-kbd-macro (concat (this-command-keys) key))
8272   (gnus-article-edit-done))
8273
8274 ;;; Respooling
8275
8276 (defun gnus-summary-respool-query (&optional silent trace)
8277   "Query where the respool algorithm would put this article."
8278   (interactive)
8279   (let (gnus-mark-article-hook)
8280     (gnus-summary-select-article)
8281     (save-excursion
8282       (set-buffer gnus-original-article-buffer)
8283       (save-restriction
8284         (message-narrow-to-head)
8285         (let ((groups (nnmail-article-group 'identity trace)))
8286           (unless silent
8287             (if groups
8288                 (message "This message would go to %s"
8289                          (mapconcat 'car groups ", "))
8290               (message "This message would go to no groups"))
8291             groups))))))
8292
8293 (defun gnus-summary-respool-trace ()
8294   "Trace where the respool algorithm would put this article.
8295 Display a buffer showing all fancy splitting patterns which matched."
8296   (interactive)
8297   (gnus-summary-respool-query nil t))
8298
8299 ;; Summary marking commands.
8300
8301 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8302   "Mark articles which has the same subject as read, and then select the next.
8303 If UNMARK is positive, remove any kind of mark.
8304 If UNMARK is negative, tick articles."
8305   (interactive "P")
8306   (when unmark
8307     (setq unmark (prefix-numeric-value unmark)))
8308   (let ((count
8309          (gnus-summary-mark-same-subject
8310           (gnus-summary-article-subject) unmark)))
8311     ;; Select next unread article.  If auto-select-same mode, should
8312     ;; select the first unread article.
8313     (gnus-summary-next-article t (and gnus-auto-select-same
8314                                       (gnus-summary-article-subject)))
8315     (gnus-message 7 "%d article%s marked as %s"
8316                   count (if (= count 1) " is" "s are")
8317                   (if unmark "unread" "read"))))
8318
8319 (defun gnus-summary-kill-same-subject (&optional unmark)
8320   "Mark articles which has the same subject as read.
8321 If UNMARK is positive, remove any kind of mark.
8322 If UNMARK is negative, tick articles."
8323   (interactive "P")
8324   (when unmark
8325     (setq unmark (prefix-numeric-value unmark)))
8326   (let ((count
8327          (gnus-summary-mark-same-subject
8328           (gnus-summary-article-subject) unmark)))
8329     ;; If marked as read, go to next unread subject.
8330     (when (null unmark)
8331       ;; Go to next unread subject.
8332       (gnus-summary-next-subject 1 t))
8333     (gnus-message 7 "%d articles are marked as %s"
8334                   count (if unmark "unread" "read"))))
8335
8336 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8337   "Mark articles with same SUBJECT as read, and return marked number.
8338 If optional argument UNMARK is positive, remove any kinds of marks.
8339 If optional argument UNMARK is negative, mark articles as unread instead."
8340   (let ((count 1))
8341     (save-excursion
8342       (cond
8343        ((null unmark)                   ; Mark as read.
8344         (while (and
8345                 (progn
8346                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8347                   (gnus-summary-show-thread) t)
8348                 (gnus-summary-find-subject subject))
8349           (setq count (1+ count))))
8350        ((> unmark 0)                    ; Tick.
8351         (while (and
8352                 (progn
8353                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8354                   (gnus-summary-show-thread) t)
8355                 (gnus-summary-find-subject subject))
8356           (setq count (1+ count))))
8357        (t                               ; Mark as unread.
8358         (while (and
8359                 (progn
8360                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8361                   (gnus-summary-show-thread) t)
8362                 (gnus-summary-find-subject subject))
8363           (setq count (1+ count)))))
8364       (gnus-set-mode-line 'summary)
8365       ;; Return the number of marked articles.
8366       count)))
8367
8368 (defun gnus-summary-mark-as-processable (n &optional unmark)
8369   "Set the process mark on the next N articles.
8370 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8371 the process mark instead.  The difference between N and the actual
8372 number of articles marked is returned."
8373   (interactive "p")
8374   (let ((backward (< n 0))
8375         (n (abs n)))
8376     (while (and
8377             (> n 0)
8378             (if unmark
8379                 (gnus-summary-remove-process-mark
8380                  (gnus-summary-article-number))
8381               (gnus-summary-set-process-mark (gnus-summary-article-number)))
8382             (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8383       (setq n (1- n)))
8384     (when (/= 0 n)
8385       (gnus-message 7 "No more articles"))
8386     (gnus-summary-recenter)
8387     (gnus-summary-position-point)
8388     n))
8389
8390 (defun gnus-summary-unmark-as-processable (n)
8391   "Remove the process mark from the next N articles.
8392 If N is negative, unmark backward instead.  The difference between N and
8393 the actual number of articles unmarked is returned."
8394   (interactive "p")
8395   (gnus-summary-mark-as-processable n t))
8396
8397 (defun gnus-summary-unmark-all-processable ()
8398   "Remove the process mark from all articles."
8399   (interactive)
8400   (save-excursion
8401     (while gnus-newsgroup-processable
8402       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8403   (gnus-summary-position-point))
8404
8405 (defun gnus-summary-mark-as-expirable (n)
8406   "Mark N articles forward as expirable.
8407 If N is negative, mark backward instead.  The difference between N and
8408 the actual number of articles marked is returned."
8409   (interactive "p")
8410   (gnus-summary-mark-forward n gnus-expirable-mark))
8411
8412 (defun gnus-summary-mark-article-as-replied (article)
8413   "Mark ARTICLE replied and update the summary line."
8414   (push article gnus-newsgroup-replied)
8415   (let ((buffer-read-only nil))
8416     (when (gnus-summary-goto-subject article nil t)
8417       (gnus-summary-update-secondary-mark article))))
8418
8419 (defun gnus-summary-set-bookmark (article)
8420   "Set a bookmark in current article."
8421   (interactive (list (gnus-summary-article-number)))
8422   (when (or (not (get-buffer gnus-article-buffer))
8423             (not gnus-current-article)
8424             (not gnus-article-current)
8425             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8426     (error "No current article selected"))
8427   ;; Remove old bookmark, if one exists.
8428   (let ((old (assq article gnus-newsgroup-bookmarks)))
8429     (when old
8430       (setq gnus-newsgroup-bookmarks
8431             (delq old gnus-newsgroup-bookmarks))))
8432   ;; Set the new bookmark, which is on the form
8433   ;; (article-number . line-number-in-body).
8434   (push
8435    (cons article
8436          (save-excursion
8437            (set-buffer gnus-article-buffer)
8438            (count-lines
8439             (min (point)
8440                  (save-excursion
8441                    (goto-char (point-min))
8442                    (search-forward "\n\n" nil t)
8443                    (point)))
8444             (point))))
8445    gnus-newsgroup-bookmarks)
8446   (gnus-message 6 "A bookmark has been added to the current article."))
8447
8448 (defun gnus-summary-remove-bookmark (article)
8449   "Remove the bookmark from the current article."
8450   (interactive (list (gnus-summary-article-number)))
8451   ;; Remove old bookmark, if one exists.
8452   (let ((old (assq article gnus-newsgroup-bookmarks)))
8453     (if old
8454         (progn
8455           (setq gnus-newsgroup-bookmarks
8456                 (delq old gnus-newsgroup-bookmarks))
8457           (gnus-message 6 "Removed bookmark."))
8458       (gnus-message 6 "No bookmark in current article."))))
8459
8460 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8461 (defun gnus-summary-mark-as-dormant (n)
8462   "Mark N articles forward as dormant.
8463 If N is negative, mark backward instead.  The difference between N and
8464 the actual number of articles marked is returned."
8465   (interactive "p")
8466   (gnus-summary-mark-forward n gnus-dormant-mark))
8467
8468 (defun gnus-summary-set-process-mark (article)
8469   "Set the process mark on ARTICLE and update the summary line."
8470   (setq gnus-newsgroup-processable
8471         (cons article
8472               (delq article gnus-newsgroup-processable)))
8473   (when (gnus-summary-goto-subject article)
8474     (gnus-summary-show-thread)
8475     (gnus-summary-goto-subject article)
8476     (gnus-summary-update-secondary-mark article)))
8477
8478 (defun gnus-summary-remove-process-mark (article)
8479   "Remove the process mark from ARTICLE and update the summary line."
8480   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8481   (when (gnus-summary-goto-subject article)
8482     (gnus-summary-show-thread)
8483     (gnus-summary-goto-subject article)
8484     (gnus-summary-update-secondary-mark article)))
8485
8486 (defun gnus-summary-set-saved-mark (article)
8487   "Set the process mark on ARTICLE and update the summary line."
8488   (push article gnus-newsgroup-saved)
8489   (when (gnus-summary-goto-subject article)
8490     (gnus-summary-update-secondary-mark article)))
8491
8492 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8493   "Mark N articles as read forwards.
8494 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8495 The difference between N and the actual number of articles marked is
8496 returned.
8497 Iff NO-EXPIRE, auto-expiry will be inhibited."
8498   (interactive "p")
8499   (gnus-summary-show-thread)
8500   (let ((backward (< n 0))
8501         (gnus-summary-goto-unread
8502          (and gnus-summary-goto-unread
8503               (not (eq gnus-summary-goto-unread 'never))
8504               (not (memq mark (list gnus-unread-mark
8505                                     gnus-ticked-mark gnus-dormant-mark)))))
8506         (n (abs n))
8507         (mark (or mark gnus-del-mark)))
8508     (while (and (> n 0)
8509                 (gnus-summary-mark-article nil mark no-expire)
8510                 (zerop (gnus-summary-next-subject
8511                         (if backward -1 1)
8512                         (and gnus-summary-goto-unread
8513                              (not (eq gnus-summary-goto-unread 'never)))
8514                         t)))
8515       (setq n (1- n)))
8516     (when (/= 0 n)
8517       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8518     (gnus-summary-recenter)
8519     (gnus-summary-position-point)
8520     (gnus-set-mode-line 'summary)
8521     n))
8522
8523 (defun gnus-summary-mark-article-as-read (mark)
8524   "Mark the current article quickly as read with MARK."
8525   (let ((article (gnus-summary-article-number)))
8526     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8527     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8528     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8529     (push (cons article mark) gnus-newsgroup-reads)
8530     ;; Possibly remove from cache, if that is used.
8531     (when gnus-use-cache
8532       (gnus-cache-enter-remove-article article))
8533     ;; Allow the backend to change the mark.
8534     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8535     ;; Check for auto-expiry.
8536     (when (and gnus-newsgroup-auto-expire
8537                (memq mark gnus-auto-expirable-marks))
8538       (setq mark gnus-expirable-mark)
8539       ;; Let the backend know about the mark change.
8540       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8541       (push article gnus-newsgroup-expirable))
8542     ;; Set the mark in the buffer.
8543     (gnus-summary-update-mark mark 'unread)
8544     t))
8545
8546 (defun gnus-summary-mark-article-as-unread (mark)
8547   "Mark the current article quickly as unread with MARK."
8548   (let* ((article (gnus-summary-article-number))
8549          (old-mark (gnus-summary-article-mark article)))
8550     ;; Allow the backend to change the mark.
8551     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8552     (if (eq mark old-mark)
8553         t
8554       (if (<= article 0)
8555           (progn
8556             (gnus-error 1 "Can't mark negative article numbers")
8557             nil)
8558         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8559         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8560         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8561         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8562         (cond ((= mark gnus-ticked-mark)
8563                (push article gnus-newsgroup-marked))
8564               ((= mark gnus-dormant-mark)
8565                (push article gnus-newsgroup-dormant))
8566               (t
8567                (push article gnus-newsgroup-unreads)))
8568         (gnus-pull article gnus-newsgroup-reads)
8569
8570         ;; See whether the article is to be put in the cache.
8571         (and gnus-use-cache
8572              (vectorp (gnus-summary-article-header article))
8573              (save-excursion
8574                (gnus-cache-possibly-enter-article
8575                 gnus-newsgroup-name article
8576                 (gnus-summary-article-header article)
8577                 (= mark gnus-ticked-mark)
8578                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8579
8580         ;; Fix the mark.
8581         (gnus-summary-update-mark mark 'unread)
8582         t))))
8583
8584 (defun gnus-summary-mark-article (&optional article mark no-expire)
8585   "Mark ARTICLE with MARK.  MARK can be any character.
8586 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8587 `??' (dormant) and `?E' (expirable).
8588 If MARK is nil, then the default character `?r' is used.
8589 If ARTICLE is nil, then the article on the current line will be
8590 marked.
8591 Iff NO-EXPIRE, auto-expiry will be inhibited."
8592   ;; The mark might be a string.
8593   (when (stringp mark)
8594     (setq mark (aref mark 0)))
8595   ;; If no mark is given, then we check auto-expiring.
8596   (when (null mark)
8597     (setq mark gnus-del-mark))
8598   (when (and (not no-expire)
8599              gnus-newsgroup-auto-expire
8600              (memq mark gnus-auto-expirable-marks))
8601     (setq mark gnus-expirable-mark))
8602   (let ((article (or article (gnus-summary-article-number)))
8603         (old-mark (gnus-summary-article-mark article)))
8604     ;; Allow the backend to change the mark.
8605     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8606     (if (eq mark old-mark)
8607         t
8608       (unless article
8609         (error "No article on current line"))
8610       (if (not (if (or (= mark gnus-unread-mark)
8611                        (= mark gnus-ticked-mark)
8612                        (= mark gnus-dormant-mark))
8613                    (gnus-mark-article-as-unread article mark)
8614                  (gnus-mark-article-as-read article mark)))
8615           t
8616         ;; See whether the article is to be put in the cache.
8617         (and gnus-use-cache
8618              (not (= mark gnus-canceled-mark))
8619              (vectorp (gnus-summary-article-header article))
8620              (save-excursion
8621                (gnus-cache-possibly-enter-article
8622                 gnus-newsgroup-name article
8623                 (gnus-summary-article-header article)
8624                 (= mark gnus-ticked-mark)
8625                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8626
8627         (when (gnus-summary-goto-subject article nil t)
8628           (let ((buffer-read-only nil))
8629             (gnus-summary-show-thread)
8630             ;; Fix the mark.
8631             (gnus-summary-update-mark mark 'unread)
8632             t))))))
8633
8634 (defun gnus-summary-update-secondary-mark (article)
8635   "Update the secondary (read, process, cache) mark."
8636   (gnus-summary-update-mark
8637    (cond ((memq article gnus-newsgroup-processable)
8638           gnus-process-mark)
8639          ((memq article gnus-newsgroup-cached)
8640           gnus-cached-mark)
8641          ((memq article gnus-newsgroup-replied)
8642           gnus-replied-mark)
8643          ((memq article gnus-newsgroup-saved)
8644           gnus-saved-mark)
8645          (t gnus-unread-mark))
8646    'replied)
8647   (when (gnus-visual-p 'summary-highlight 'highlight)
8648     (gnus-run-hooks 'gnus-summary-update-hook))
8649   t)
8650
8651 (defun gnus-summary-update-mark (mark type)
8652   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8653         (buffer-read-only nil))
8654     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
8655     (when forward
8656       (when (looking-at "\r")
8657         (incf forward))
8658       (when (<= (+ forward (point)) (point-max))
8659         ;; Go to the right position on the line.
8660         (goto-char (+ forward (point)))
8661         ;; Replace the old mark with the new mark.
8662         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8663         ;; Optionally update the marks by some user rule.
8664         (when (eq type 'unread)
8665           (gnus-data-set-mark
8666            (gnus-data-find (gnus-summary-article-number)) mark)
8667           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
8668
8669 (defun gnus-mark-article-as-read (article &optional mark)
8670   "Enter ARTICLE in the pertinent lists and remove it from others."
8671   ;; Make the article expirable.
8672   (let ((mark (or mark gnus-del-mark)))
8673     (if (= mark gnus-expirable-mark)
8674         (push article gnus-newsgroup-expirable)
8675       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8676     ;; Remove from unread and marked lists.
8677     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8678     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8679     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8680     (push (cons article mark) gnus-newsgroup-reads)
8681     ;; Possibly remove from cache, if that is used.
8682     (when gnus-use-cache
8683       (gnus-cache-enter-remove-article article))
8684     t))
8685
8686 (defun gnus-mark-article-as-unread (article &optional mark)
8687   "Enter ARTICLE in the pertinent lists and remove it from others."
8688   (let ((mark (or mark gnus-ticked-mark)))
8689     (if (<= article 0)
8690         (progn
8691           (gnus-error 1 "Can't mark negative article numbers")
8692           nil)
8693       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8694             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8695             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8696             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8697
8698       ;; Unsuppress duplicates?
8699       (when gnus-suppress-duplicates
8700         (gnus-dup-unsuppress-article article))
8701
8702       (cond ((= mark gnus-ticked-mark)
8703              (push article gnus-newsgroup-marked))
8704             ((= mark gnus-dormant-mark)
8705              (push article gnus-newsgroup-dormant))
8706             (t
8707              (push article gnus-newsgroup-unreads)))
8708       (gnus-pull article gnus-newsgroup-reads)
8709       t)))
8710
8711 (defalias 'gnus-summary-mark-as-unread-forward
8712   'gnus-summary-tick-article-forward)
8713 (make-obsolete 'gnus-summary-mark-as-unread-forward
8714                'gnus-summary-tick-article-forward)
8715 (defun gnus-summary-tick-article-forward (n)
8716   "Tick N articles forwards.
8717 If N is negative, tick backwards instead.
8718 The difference between N and the number of articles ticked is returned."
8719   (interactive "p")
8720   (gnus-summary-mark-forward n gnus-ticked-mark))
8721
8722 (defalias 'gnus-summary-mark-as-unread-backward
8723   'gnus-summary-tick-article-backward)
8724 (make-obsolete 'gnus-summary-mark-as-unread-backward
8725                'gnus-summary-tick-article-backward)
8726 (defun gnus-summary-tick-article-backward (n)
8727   "Tick N articles backwards.
8728 The difference between N and the number of articles ticked is returned."
8729   (interactive "p")
8730   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8731
8732 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8733 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8734 (defun gnus-summary-tick-article (&optional article clear-mark)
8735   "Mark current article as unread.
8736 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8737 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8738   (interactive)
8739   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8740                                        gnus-ticked-mark)))
8741
8742 (defun gnus-summary-mark-as-read-forward (n)
8743   "Mark N articles as read forwards.
8744 If N is negative, mark backwards instead.
8745 The difference between N and the actual number of articles marked is
8746 returned."
8747   (interactive "p")
8748   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8749
8750 (defun gnus-summary-mark-as-read-backward (n)
8751   "Mark the N articles as read backwards.
8752 The difference between N and the actual number of articles marked is
8753 returned."
8754   (interactive "p")
8755   (gnus-summary-mark-forward
8756    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8757
8758 (defun gnus-summary-mark-as-read (&optional article mark)
8759   "Mark current article as read.
8760 ARTICLE specifies the article to be marked as read.
8761 MARK specifies a string to be inserted at the beginning of the line."
8762   (gnus-summary-mark-article article mark))
8763
8764 (defun gnus-summary-clear-mark-forward (n)
8765   "Clear marks from N articles forward.
8766 If N is negative, clear backward instead.
8767 The difference between N and the number of marks cleared is returned."
8768   (interactive "p")
8769   (gnus-summary-mark-forward n gnus-unread-mark))
8770
8771 (defun gnus-summary-clear-mark-backward (n)
8772   "Clear marks from N articles backward.
8773 The difference between N and the number of marks cleared is returned."
8774   (interactive "p")
8775   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8776
8777 (defun gnus-summary-mark-unread-as-read ()
8778   "Intended to be used by `gnus-summary-mark-article-hook'."
8779   (when (memq gnus-current-article gnus-newsgroup-unreads)
8780     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8781
8782 (defun gnus-summary-mark-read-and-unread-as-read ()
8783   "Intended to be used by `gnus-summary-mark-article-hook'."
8784   (let ((mark (gnus-summary-article-mark)))
8785     (when (or (gnus-unread-mark-p mark)
8786               (gnus-read-mark-p mark))
8787       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8788
8789 (defun gnus-summary-mark-region-as-read (point mark all)
8790   "Mark all unread articles between point and mark as read.
8791 If given a prefix, mark all articles between point and mark as read,
8792 even ticked and dormant ones."
8793   (interactive "r\nP")
8794   (save-excursion
8795     (let (article)
8796       (goto-char point)
8797       (beginning-of-line)
8798       (while (and
8799               (< (point) mark)
8800               (progn
8801                 (when (or all
8802                           (memq (setq article (gnus-summary-article-number))
8803                                 gnus-newsgroup-unreads))
8804                   (gnus-summary-mark-article article gnus-del-mark))
8805                 t)
8806               (gnus-summary-find-next))))))
8807
8808 (defun gnus-summary-mark-below (score mark)
8809   "Mark articles with score less than SCORE with MARK."
8810   (interactive "P\ncMark: ")
8811   (setq score (if score
8812                   (prefix-numeric-value score)
8813                 (or gnus-summary-default-score 0)))
8814   (save-excursion
8815     (set-buffer gnus-summary-buffer)
8816     (goto-char (point-min))
8817     (while
8818         (progn
8819           (and (< (gnus-summary-article-score) score)
8820                (gnus-summary-mark-article nil mark))
8821           (gnus-summary-find-next)))))
8822
8823 (defun gnus-summary-kill-below (&optional score)
8824   "Mark articles with score below SCORE as read."
8825   (interactive "P")
8826   (gnus-summary-mark-below score gnus-killed-mark))
8827
8828 (defun gnus-summary-clear-above (&optional score)
8829   "Clear all marks from articles with score above SCORE."
8830   (interactive "P")
8831   (gnus-summary-mark-above score gnus-unread-mark))
8832
8833 (defun gnus-summary-tick-above (&optional score)
8834   "Tick all articles with score above SCORE."
8835   (interactive "P")
8836   (gnus-summary-mark-above score gnus-ticked-mark))
8837
8838 (defun gnus-summary-mark-above (score mark)
8839   "Mark articles with score over SCORE with MARK."
8840   (interactive "P\ncMark: ")
8841   (setq score (if score
8842                   (prefix-numeric-value score)
8843                 (or gnus-summary-default-score 0)))
8844   (save-excursion
8845     (set-buffer gnus-summary-buffer)
8846     (goto-char (point-min))
8847     (while (and (progn
8848                   (when (> (gnus-summary-article-score) score)
8849                     (gnus-summary-mark-article nil mark))
8850                   t)
8851                 (gnus-summary-find-next)))))
8852
8853 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8854 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8855 (defun gnus-summary-limit-include-expunged (&optional no-error)
8856   "Display all the hidden articles that were expunged for low scores."
8857   (interactive)
8858   (let ((buffer-read-only nil))
8859     (let ((scored gnus-newsgroup-scored)
8860           headers h)
8861       (while scored
8862         (unless (gnus-summary-goto-subject (caar scored))
8863           (and (setq h (gnus-summary-article-header (caar scored)))
8864                (< (cdar scored) gnus-summary-expunge-below)
8865                (push h headers)))
8866         (setq scored (cdr scored)))
8867       (if (not headers)
8868           (when (not no-error)
8869             (error "No expunged articles hidden"))
8870         (goto-char (point-min))
8871         (gnus-summary-prepare-unthreaded (nreverse headers))
8872         (goto-char (point-min))
8873         (gnus-summary-position-point)
8874         t))))
8875
8876 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8877   "Mark all unread articles in this newsgroup as read.
8878 If prefix argument ALL is non-nil, ticked and dormant articles will
8879 also be marked as read.
8880 If QUIETLY is non-nil, no questions will be asked.
8881 If TO-HERE is non-nil, it should be a point in the buffer.  All
8882 articles before this point will be marked as read.
8883 Note that this function will only catch up the unread article
8884 in the current summary buffer limitation.
8885 The number of articles marked as read is returned."
8886   (interactive "P")
8887   (prog1
8888       (save-excursion
8889         (when (or quietly
8890                   (not gnus-interactive-catchup) ;Without confirmation?
8891                   gnus-expert-user
8892                   (gnus-y-or-n-p
8893                    (if all
8894                        "Mark absolutely all articles as read? "
8895                      "Mark all unread articles as read? ")))
8896           (if (and not-mark
8897                    (not gnus-newsgroup-adaptive)
8898                    (not gnus-newsgroup-auto-expire)
8899                    (not gnus-suppress-duplicates)
8900                    (or (not gnus-use-cache)
8901                        (eq gnus-use-cache 'passive)))
8902               (progn
8903                 (when all
8904                   (setq gnus-newsgroup-marked nil
8905                         gnus-newsgroup-dormant nil))
8906                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8907             ;; We actually mark all articles as canceled, which we
8908             ;; have to do when using auto-expiry or adaptive scoring.
8909             (gnus-summary-show-all-threads)
8910             (when (gnus-summary-first-subject (not all) t)
8911               (while (and
8912                       (if to-here (< (point) to-here) t)
8913                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8914                       (gnus-summary-find-next (not all) nil nil t))))
8915             (gnus-set-mode-line 'summary))
8916           t))
8917     (gnus-summary-position-point)))
8918
8919 (defun gnus-summary-catchup-to-here (&optional all)
8920   "Mark all unticked articles before the current one as read.
8921 If ALL is non-nil, also mark ticked and dormant articles as read."
8922   (interactive "P")
8923   (save-excursion
8924     (gnus-save-hidden-threads
8925       (let ((beg (point)))
8926         ;; We check that there are unread articles.
8927         (when (or all (gnus-summary-find-prev))
8928           (gnus-summary-catchup all t beg)))))
8929   (gnus-summary-position-point))
8930
8931 (defun gnus-summary-catchup-all (&optional quietly)
8932   "Mark all articles in this newsgroup as read."
8933   (interactive "P")
8934   (gnus-summary-catchup t quietly))
8935
8936 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8937   "Mark all unread articles in this group as read, then exit.
8938 If prefix argument ALL is non-nil, all articles are marked as read."
8939   (interactive "P")
8940   (when (gnus-summary-catchup all quietly nil 'fast)
8941     ;; Select next newsgroup or exit.
8942     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8943              (eq gnus-auto-select-next 'quietly))
8944         (gnus-summary-next-group nil)
8945       (gnus-summary-exit))))
8946
8947 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8948   "Mark all articles in this newsgroup as read, and then exit."
8949   (interactive "P")
8950   (gnus-summary-catchup-and-exit t quietly))
8951
8952 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8953   "Mark all articles in this group as read and select the next group.
8954 If given a prefix, mark all articles, unread as well as ticked, as
8955 read."
8956   (interactive "P")
8957   (save-excursion
8958     (gnus-summary-catchup all))
8959   (gnus-summary-next-group))
8960
8961 ;;;
8962 ;;; with article
8963 ;;;
8964
8965 (defmacro gnus-with-article (article &rest forms)
8966   "Select ARTICLE and perform FORMS in the original article buffer.
8967 Then replace the article with the result."
8968   `(progn
8969      ;; We don't want the article to be marked as read.
8970      (let (gnus-mark-article-hook)
8971        (gnus-summary-select-article t t nil ,article))
8972      (set-buffer gnus-original-article-buffer)
8973      ,@forms
8974      (if (not (gnus-check-backend-function
8975                'request-replace-article (car gnus-article-current)))
8976          (gnus-message 5 "Read-only group; not replacing")
8977        (unless (gnus-request-replace-article
8978                 ,article (car gnus-article-current)
8979                 (current-buffer) t)
8980          (error "Couldn't replace article")))
8981      ;; The cache and backlog have to be flushed somewhat.
8982      (when gnus-keep-backlog
8983        (gnus-backlog-remove-article
8984         (car gnus-article-current) (cdr gnus-article-current)))
8985      (when gnus-use-cache
8986        (gnus-cache-update-article
8987         (car gnus-article-current) (cdr gnus-article-current)))))
8988
8989 (put 'gnus-with-article 'lisp-indent-function 1)
8990 (put 'gnus-with-article 'edebug-form-spec '(form body))
8991
8992 ;; Thread-based commands.
8993
8994 (defun gnus-summary-articles-in-thread (&optional article)
8995   "Return a list of all articles in the current thread.
8996 If ARTICLE is non-nil, return all articles in the thread that starts
8997 with that article."
8998   (let* ((article (or article (gnus-summary-article-number)))
8999          (data (gnus-data-find-list article))
9000          (top-level (gnus-data-level (car data)))
9001          (top-subject
9002           (cond ((null gnus-thread-operation-ignore-subject)
9003                  (gnus-simplify-subject-re
9004                   (mail-header-subject (gnus-data-header (car data)))))
9005                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9006                  (gnus-simplify-subject-fuzzy
9007                   (mail-header-subject (gnus-data-header (car data)))))
9008                 (t nil)))
9009          (end-point (save-excursion
9010                       (if (gnus-summary-go-to-next-thread)
9011                           (point) (point-max))))
9012          articles)
9013     (while (and data
9014                 (< (gnus-data-pos (car data)) end-point))
9015       (when (or (not top-subject)
9016                 (string= top-subject
9017                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9018                              (gnus-simplify-subject-fuzzy
9019                               (mail-header-subject
9020                                (gnus-data-header (car data))))
9021                            (gnus-simplify-subject-re
9022                             (mail-header-subject
9023                              (gnus-data-header (car data)))))))
9024         (push (gnus-data-number (car data)) articles))
9025       (unless (and (setq data (cdr data))
9026                    (> (gnus-data-level (car data)) top-level))
9027         (setq data nil)))
9028     ;; Return the list of articles.
9029     (nreverse articles)))
9030
9031 (defun gnus-summary-rethread-current ()
9032   "Rethread the thread the current article is part of."
9033   (interactive)
9034   (let* ((gnus-show-threads t)
9035          (article (gnus-summary-article-number))
9036          (id (mail-header-id (gnus-summary-article-header)))
9037          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9038     (unless id
9039       (error "No article on the current line"))
9040     (gnus-rebuild-thread id)
9041     (gnus-summary-goto-subject article)))
9042
9043 (defun gnus-summary-reparent-thread ()
9044   "Make the current article child of the marked (or previous) article.
9045
9046 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9047 is non-nil or the Subject: of both articles are the same."
9048   (interactive)
9049   (unless (not (gnus-group-read-only-p))
9050     (error "The current newsgroup does not support article editing"))
9051   (unless (<= (length gnus-newsgroup-processable) 1)
9052     (error "No more than one article may be marked"))
9053   (save-window-excursion
9054     (let ((gnus-article-buffer " *reparent*")
9055           (current-article (gnus-summary-article-number))
9056           ;; First grab the marked article, otherwise one line up.
9057           (parent-article (if (not (null gnus-newsgroup-processable))
9058                               (car gnus-newsgroup-processable)
9059                             (save-excursion
9060                               (if (eq (forward-line -1) 0)
9061                                   (gnus-summary-article-number)
9062                                 (error "Beginning of summary buffer"))))))
9063       (unless (not (eq current-article parent-article))
9064         (error "An article may not be self-referential"))
9065       (let ((message-id (mail-header-id
9066                          (gnus-summary-article-header parent-article))))
9067         (unless (and message-id (not (equal message-id "")))
9068           (error "No message-id in desired parent"))
9069         (gnus-with-article current-article
9070           (save-restriction
9071             (goto-char (point-min))
9072             (message-narrow-to-head)
9073             (if (re-search-forward "^References: " nil t)
9074                 (progn
9075                   (re-search-forward "^[^ \t]" nil t)
9076                   (forward-line -1)
9077                   (end-of-line)
9078                   (insert " " message-id))
9079               (insert "References: " message-id "\n"))))
9080         (set-buffer gnus-summary-buffer)
9081         (gnus-summary-unmark-all-processable)
9082         (gnus-summary-update-article current-article)
9083         (gnus-summary-rethread-current)
9084         (gnus-message 3 "Article %d is now the child of article %d"
9085                       current-article parent-article)))))
9086
9087 (defun gnus-summary-toggle-threads (&optional arg)
9088   "Toggle showing conversation threads.
9089 If ARG is positive number, turn showing conversation threads on."
9090   (interactive "P")
9091   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9092     (setq gnus-show-threads
9093           (if (null arg) (not gnus-show-threads)
9094             (> (prefix-numeric-value arg) 0)))
9095     (gnus-summary-prepare)
9096     (gnus-summary-goto-subject current)
9097     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9098     (gnus-summary-position-point)))
9099
9100 (defun gnus-summary-show-all-threads ()
9101   "Show all threads."
9102   (interactive)
9103   (save-excursion
9104     (let ((buffer-read-only nil))
9105       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9106   (gnus-summary-position-point))
9107
9108 (defun gnus-summary-show-thread ()
9109   "Show thread subtrees.
9110 Returns nil if no thread was there to be shown."
9111   (interactive)
9112   (let ((buffer-read-only nil)
9113         (orig (point))
9114         ;; first goto end then to beg, to have point at beg after let
9115         (end (progn (end-of-line) (point)))
9116         (beg (progn (beginning-of-line) (point))))
9117     (prog1
9118         ;; Any hidden lines here?
9119         (search-forward "\r" end t)
9120       (subst-char-in-region beg end ?\^M ?\n t)
9121       (goto-char orig)
9122       (gnus-summary-position-point))))
9123
9124 (defun gnus-summary-hide-all-threads ()
9125   "Hide all thread subtrees."
9126   (interactive)
9127   (save-excursion
9128     (goto-char (point-min))
9129     (gnus-summary-hide-thread)
9130     (while (zerop (gnus-summary-next-thread 1 t))
9131       (gnus-summary-hide-thread)))
9132   (gnus-summary-position-point))
9133
9134 (defun gnus-summary-hide-thread ()
9135   "Hide thread subtrees.
9136 Returns nil if no threads were there to be hidden."
9137   (interactive)
9138   (let ((buffer-read-only nil)
9139         (start (point))
9140         (article (gnus-summary-article-number)))
9141     (goto-char start)
9142     ;; Go forward until either the buffer ends or the subthread
9143     ;; ends.
9144     (when (and (not (eobp))
9145                (or (zerop (gnus-summary-next-thread 1 t))
9146                    (goto-char (point-max))))
9147       (prog1
9148           (if (and (> (point) start)
9149                    (search-backward "\n" start t))
9150               (progn
9151                 (subst-char-in-region start (point) ?\n ?\^M)
9152                 (gnus-summary-goto-subject article))
9153             (goto-char start)
9154             nil)))))
9155
9156 (defun gnus-summary-go-to-next-thread (&optional previous)
9157   "Go to the same level (or less) next thread.
9158 If PREVIOUS is non-nil, go to previous thread instead.
9159 Return the article number moved to, or nil if moving was impossible."
9160   (let ((level (gnus-summary-thread-level))
9161         (way (if previous -1 1))
9162         (beg (point)))
9163     (forward-line way)
9164     (while (and (not (eobp))
9165                 (< level (gnus-summary-thread-level)))
9166       (forward-line way))
9167     (if (eobp)
9168         (progn
9169           (goto-char beg)
9170           nil)
9171       (setq beg (point))
9172       (prog1
9173           (gnus-summary-article-number)
9174         (goto-char beg)))))
9175
9176 (defun gnus-summary-next-thread (n &optional silent)
9177   "Go to the same level next N'th thread.
9178 If N is negative, search backward instead.
9179 Returns the difference between N and the number of skips actually
9180 done.
9181
9182 If SILENT, don't output messages."
9183   (interactive "p")
9184   (let ((backward (< n 0))
9185         (n (abs n)))
9186     (while (and (> n 0)
9187                 (gnus-summary-go-to-next-thread backward))
9188       (decf n))
9189     (unless silent
9190       (gnus-summary-position-point))
9191     (when (and (not silent) (/= 0 n))
9192       (gnus-message 7 "No more threads"))
9193     n))
9194
9195 (defun gnus-summary-prev-thread (n)
9196   "Go to the same level previous N'th thread.
9197 Returns the difference between N and the number of skips actually
9198 done."
9199   (interactive "p")
9200   (gnus-summary-next-thread (- n)))
9201
9202 (defun gnus-summary-go-down-thread ()
9203   "Go down one level in the current thread."
9204   (let ((children (gnus-summary-article-children)))
9205     (when children
9206       (gnus-summary-goto-subject (car children)))))
9207
9208 (defun gnus-summary-go-up-thread ()
9209   "Go up one level in the current thread."
9210   (let ((parent (gnus-summary-article-parent)))
9211     (when parent
9212       (gnus-summary-goto-subject parent))))
9213
9214 (defun gnus-summary-down-thread (n)
9215   "Go down thread N steps.
9216 If N is negative, go up instead.
9217 Returns the difference between N and how many steps down that were
9218 taken."
9219   (interactive "p")
9220   (let ((up (< n 0))
9221         (n (abs n)))
9222     (while (and (> n 0)
9223                 (if up (gnus-summary-go-up-thread)
9224                   (gnus-summary-go-down-thread)))
9225       (setq n (1- n)))
9226     (gnus-summary-position-point)
9227     (when (/= 0 n)
9228       (gnus-message 7 "Can't go further"))
9229     n))
9230
9231 (defun gnus-summary-up-thread (n)
9232   "Go up thread N steps.
9233 If N is negative, go up instead.
9234 Returns the difference between N and how many steps down that were
9235 taken."
9236   (interactive "p")
9237   (gnus-summary-down-thread (- n)))
9238
9239 (defun gnus-summary-top-thread ()
9240   "Go to the top of the thread."
9241   (interactive)
9242   (while (gnus-summary-go-up-thread))
9243   (gnus-summary-article-number))
9244
9245 (defun gnus-summary-kill-thread (&optional unmark)
9246   "Mark articles under current thread as read.
9247 If the prefix argument is positive, remove any kinds of marks.
9248 If the prefix argument is negative, tick articles instead."
9249   (interactive "P")
9250   (when unmark
9251     (setq unmark (prefix-numeric-value unmark)))
9252   (let ((articles (gnus-summary-articles-in-thread)))
9253     (save-excursion
9254       ;; Expand the thread.
9255       (gnus-summary-show-thread)
9256       ;; Mark all the articles.
9257       (while articles
9258         (gnus-summary-goto-subject (car articles))
9259         (cond ((null unmark)
9260                (gnus-summary-mark-article-as-read gnus-killed-mark))
9261               ((> unmark 0)
9262                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9263               (t
9264                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9265         (setq articles (cdr articles))))
9266     ;; Hide killed subtrees.
9267     (and (null unmark)
9268          gnus-thread-hide-killed
9269          (gnus-summary-hide-thread))
9270     ;; If marked as read, go to next unread subject.
9271     (when (null unmark)
9272       ;; Go to next unread subject.
9273       (gnus-summary-next-subject 1 t)))
9274   (gnus-set-mode-line 'summary))
9275
9276 ;; Summary sorting commands
9277
9278 (defun gnus-summary-sort-by-number (&optional reverse)
9279   "Sort the summary buffer by article number.
9280 Argument REVERSE means reverse order."
9281   (interactive "P")
9282   (gnus-summary-sort 'number reverse))
9283
9284 (defun gnus-summary-sort-by-author (&optional reverse)
9285   "Sort the summary buffer by author name alphabetically.
9286 If `case-fold-search' is non-nil, case of letters is ignored.
9287 Argument REVERSE means reverse order."
9288   (interactive "P")
9289   (gnus-summary-sort 'author reverse))
9290
9291 (defun gnus-summary-sort-by-subject (&optional reverse)
9292   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9293 If `case-fold-search' is non-nil, case of letters is ignored.
9294 Argument REVERSE means reverse order."
9295   (interactive "P")
9296   (gnus-summary-sort 'subject reverse))
9297
9298 (defun gnus-summary-sort-by-date (&optional reverse)
9299   "Sort the summary buffer by date.
9300 Argument REVERSE means reverse order."
9301   (interactive "P")
9302   (gnus-summary-sort 'date reverse))
9303
9304 (defun gnus-summary-sort-by-score (&optional reverse)
9305   "Sort the summary buffer by score.
9306 Argument REVERSE means reverse order."
9307   (interactive "P")
9308   (gnus-summary-sort 'score reverse))
9309
9310 (defun gnus-summary-sort-by-lines (&optional reverse)
9311   "Sort the summary buffer by the number of lines.
9312 Argument REVERSE means reverse order."
9313   (interactive "P")
9314   (gnus-summary-sort 'lines reverse))
9315
9316 (defun gnus-summary-sort-by-chars (&optional reverse)
9317   "Sort the summary buffer by article length.
9318 Argument REVERSE means reverse order."
9319   (interactive "P")
9320   (gnus-summary-sort 'chars reverse))
9321
9322 (defun gnus-summary-sort (predicate reverse)
9323   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9324   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9325          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9326          (gnus-thread-sort-functions
9327           (if (not reverse)
9328               thread
9329             `(lambda (t1 t2)
9330                (,thread t2 t1))))
9331          (gnus-sort-gathered-threads-function
9332           gnus-thread-sort-functions)
9333          (gnus-article-sort-functions
9334           (if (not reverse)
9335               article
9336             `(lambda (t1 t2)
9337                (,article t2 t1))))
9338          (buffer-read-only)
9339          (gnus-summary-prepare-hook nil))
9340     ;; We do the sorting by regenerating the threads.
9341     (gnus-summary-prepare)
9342     ;; Hide subthreads if needed.
9343     (when (and gnus-show-threads gnus-thread-hide-subtree)
9344       (gnus-summary-hide-all-threads))))
9345
9346 ;; Summary saving commands.
9347
9348 (defun gnus-summary-save-article (&optional n not-saved)
9349   "Save the current article using the default saver function.
9350 If N is a positive number, save the N next articles.
9351 If N is a negative number, save the N previous articles.
9352 If N is nil and any articles have been marked with the process mark,
9353 save those articles instead.
9354 The variable `gnus-default-article-saver' specifies the saver function."
9355   (interactive "P")
9356   (let* ((articles (gnus-summary-work-articles n))
9357          (save-buffer (save-excursion
9358                         (nnheader-set-temp-buffer " *Gnus Save*")))
9359          (num (length articles))
9360          header file)
9361     (dolist (article articles)
9362       (setq header (gnus-summary-article-header article))
9363       (if (not (vectorp header))
9364           ;; This is a pseudo-article.
9365           (if (assq 'name header)
9366               (gnus-copy-file (cdr (assq 'name header)))
9367             (gnus-message 1 "Article %d is unsaveable" article))
9368         ;; This is a real article.
9369         (save-window-excursion
9370           (gnus-summary-select-article t nil nil article))
9371         (save-excursion
9372           (set-buffer save-buffer)
9373           (erase-buffer)
9374           (insert-buffer-substring gnus-original-article-buffer))
9375         (setq file (gnus-article-save save-buffer file num))
9376         (gnus-summary-remove-process-mark article)
9377         (unless not-saved
9378           (gnus-summary-set-saved-mark article))))
9379     (gnus-kill-buffer save-buffer)
9380     (gnus-summary-position-point)
9381     (gnus-set-mode-line 'summary)
9382     n))
9383
9384 (defun gnus-summary-pipe-output (&optional arg)
9385   "Pipe the current article to a subprocess.
9386 If N is a positive number, pipe the N next articles.
9387 If N is a negative number, pipe the N previous articles.
9388 If N is nil and any articles have been marked with the process mark,
9389 pipe those articles instead."
9390   (interactive "P")
9391   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9392     (gnus-summary-save-article arg t))
9393   (gnus-configure-windows 'pipe))
9394
9395 (defun gnus-summary-save-article-mail (&optional arg)
9396   "Append the current article to an mail file.
9397 If N is a positive number, save the N next articles.
9398 If N is a negative number, save the N previous articles.
9399 If N is nil and any articles have been marked with the process mark,
9400 save those articles instead."
9401   (interactive "P")
9402   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9403     (gnus-summary-save-article arg)))
9404
9405 (defun gnus-summary-save-article-rmail (&optional arg)
9406   "Append the current article to an rmail file.
9407 If N is a positive number, save the N next articles.
9408 If N is a negative number, save the N previous articles.
9409 If N is nil and any articles have been marked with the process mark,
9410 save those articles instead."
9411   (interactive "P")
9412   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9413     (gnus-summary-save-article arg)))
9414
9415 (defun gnus-summary-save-article-file (&optional arg)
9416   "Append the current article to a file.
9417 If N is a positive number, save the N next articles.
9418 If N is a negative number, save the N previous articles.
9419 If N is nil and any articles have been marked with the process mark,
9420 save those articles instead."
9421   (interactive "P")
9422   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9423     (gnus-summary-save-article arg)))
9424
9425 (defun gnus-summary-write-article-file (&optional arg)
9426   "Write the current article to a file, deleting the previous file.
9427 If N is a positive number, save the N next articles.
9428 If N is a negative number, save the N previous articles.
9429 If N is nil and any articles have been marked with the process mark,
9430 save those articles instead."
9431   (interactive "P")
9432   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9433     (gnus-summary-save-article arg)))
9434
9435 (defun gnus-summary-save-article-body-file (&optional arg)
9436   "Append the current article body to a file.
9437 If N is a positive number, save the N next articles.
9438 If N is a negative number, save the N previous articles.
9439 If N is nil and any articles have been marked with the process mark,
9440 save those articles instead."
9441   (interactive "P")
9442   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9443     (gnus-summary-save-article arg)))
9444
9445 (defun gnus-summary-pipe-message (program)
9446   "Pipe the current article through PROGRAM."
9447   (interactive "sProgram: ")
9448   (gnus-summary-select-article)
9449   (let ((mail-header-separator ""))
9450     (gnus-eval-in-buffer-window gnus-article-buffer
9451       (save-restriction
9452         (widen)
9453         (let ((start (window-start))
9454               buffer-read-only)
9455           (message-pipe-buffer-body program)
9456           (set-window-start (get-buffer-window (current-buffer)) start))))))
9457
9458 (defun gnus-get-split-value (methods)
9459   "Return a value based on the split METHODS."
9460   (let (split-name method result match)
9461     (when methods
9462       (save-excursion
9463         (set-buffer gnus-original-article-buffer)
9464         (save-restriction
9465           (nnheader-narrow-to-headers)
9466           (while (and methods (not split-name))
9467             (goto-char (point-min))
9468             (setq method (pop methods))
9469             (setq match (car method))
9470             (when (cond
9471                    ((stringp match)
9472                     ;; Regular expression.
9473                     (ignore-errors
9474                       (re-search-forward match nil t)))
9475                    ((gnus-functionp match)
9476                     ;; Function.
9477                     (save-restriction
9478                       (widen)
9479                       (setq result (funcall match gnus-newsgroup-name))))
9480                    ((consp match)
9481                     ;; Form.
9482                     (save-restriction
9483                       (widen)
9484                       (setq result (eval match)))))
9485               (setq split-name (cdr method))
9486               (cond ((stringp result)
9487                      (push (expand-file-name
9488                             result gnus-article-save-directory)
9489                            split-name))
9490                     ((consp result)
9491                      (setq split-name (append result split-name)))))))))
9492     (nreverse split-name)))
9493
9494 (defun gnus-valid-move-group-p (group)
9495   (and (boundp group)
9496        (symbol-name group)
9497        (symbol-value group)
9498        (gnus-get-function (gnus-find-method-for-group
9499                            (symbol-name group)) 'request-accept-article t)))
9500
9501 (defun gnus-read-move-group-name (prompt default articles prefix)
9502   "Read a group name."
9503   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9504          (minibuffer-confirm-incomplete nil) ; XEmacs
9505          (prom
9506           (format "%s %s to:"
9507                   prompt
9508                   (if (> (length articles) 1)
9509                       (format "these %d articles" (length articles))
9510                     "this article")))
9511          (to-newsgroup
9512           (cond
9513            ((null split-name)
9514             (gnus-completing-read default prom
9515                                   gnus-active-hashtb
9516                                   'gnus-valid-move-group-p
9517                                   nil prefix
9518                                   'gnus-group-history))
9519            ((= 1 (length split-name))
9520             (gnus-completing-read (car split-name) prom
9521                                   gnus-active-hashtb
9522                                   'gnus-valid-move-group-p
9523                                   nil nil
9524                                   'gnus-group-history))
9525            (t
9526             (gnus-completing-read nil prom
9527                                   (mapcar (lambda (el) (list el))
9528                                           (nreverse split-name))
9529                                   nil nil nil
9530                                   'gnus-group-history))))
9531          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
9532     (when to-newsgroup
9533       (if (or (string= to-newsgroup "")
9534               (string= to-newsgroup prefix))
9535           (setq to-newsgroup default))
9536       (unless to-newsgroup
9537         (error "No group name entered"))
9538       (or (gnus-active to-newsgroup)
9539           (gnus-activate-group to-newsgroup nil nil to-method)
9540           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
9541                                      to-newsgroup))
9542               (or (and (gnus-request-create-group to-newsgroup to-method)
9543                        (gnus-activate-group
9544                         to-newsgroup nil nil to-method)
9545                        (gnus-subscribe-group to-newsgroup))
9546                   (error "Couldn't create group %s" to-newsgroup)))
9547           (error "No such group: %s" to-newsgroup)))
9548     to-newsgroup))
9549
9550 (defun gnus-summary-save-parts (type dir n &optional reverse)
9551   "Save parts matching TYPE to DIR.
9552 If REVERSE, save parts that do not match TYPE."
9553   (interactive
9554    (list (read-string "Save parts of type: " 
9555                       (or (car gnus-summary-save-parts-type-history)
9556                           gnus-summary-save-parts-default-mime)
9557                       'gnus-summary-save-parts-type-history)
9558          (setq gnus-summary-save-parts-last-directory
9559                (read-file-name "Save to directory: " 
9560                                gnus-summary-save-parts-last-directory
9561                                nil t))
9562          current-prefix-arg))
9563   (gnus-summary-iterate n
9564     (let ((gnus-display-mime-function nil)
9565           (gnus-inhibit-treatment t))
9566       (gnus-summary-select-article))
9567     (save-excursion
9568       (set-buffer gnus-article-buffer)
9569       (let ((handles (or gnus-article-mime-handles
9570                          (mm-dissect-buffer) (mm-uu-dissect))))
9571         (when handles
9572           (gnus-summary-save-parts-1 type dir handles reverse)
9573           (unless gnus-article-mime-handles ;; Don't destroy this case.
9574             (mm-destroy-parts handles)))))))
9575
9576 (defun gnus-summary-save-parts-1 (type dir handle reverse)
9577   (if (stringp (car handle))
9578       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9579               (cdr handle))
9580     (when (if reverse
9581               (not (string-match type (mm-handle-media-type handle)))
9582             (string-match type (mm-handle-media-type handle)))
9583       (let ((file (expand-file-name
9584                    (file-name-nondirectory
9585                     (or
9586                      (mail-content-type-get
9587                       (mm-handle-disposition handle) 'filename)
9588                      (concat gnus-newsgroup-name
9589                              "." (number-to-string
9590                                   (cdr gnus-article-current)))))
9591                    dir)))
9592         (unless (file-exists-p file)
9593           (mm-save-part-to-file handle file))))))
9594
9595 ;; Summary extract commands
9596
9597 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
9598   (let ((buffer-read-only nil)
9599         (article (gnus-summary-article-number))
9600         after-article b e)
9601     (unless (gnus-summary-goto-subject article)
9602       (error "No such article: %d" article))
9603     (gnus-summary-position-point)
9604     ;; If all commands are to be bunched up on one line, we collect
9605     ;; them here.
9606     (unless gnus-view-pseudos-separately
9607       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9608             files action)
9609         (while ps
9610           (setq action (cdr (assq 'action (car ps))))
9611           (setq files (list (cdr (assq 'name (car ps)))))
9612           (while (and ps (cdr ps)
9613                       (string= (or action "1")
9614                                (or (cdr (assq 'action (cadr ps))) "2")))
9615             (push (cdr (assq 'name (cadr ps))) files)
9616             (setcdr ps (cddr ps)))
9617           (when files
9618             (when (not (string-match "%s" action))
9619               (push " " files))
9620             (push " " files)
9621             (when (assq 'execute (car ps))
9622               (setcdr (assq 'execute (car ps))
9623                       (funcall (if (string-match "%s" action)
9624                                    'format 'concat)
9625                                action
9626                                (mapconcat
9627                                 (lambda (f)
9628                                   (if (equal f " ")
9629                                       f
9630                                     (gnus-quote-arg-for-sh-or-csh f)))
9631                                 files " ")))))
9632           (setq ps (cdr ps)))))
9633     (if (and gnus-view-pseudos (not not-view))
9634         (while pslist
9635           (when (assq 'execute (car pslist))
9636             (gnus-execute-command (cdr (assq 'execute (car pslist)))
9637                                   (eq gnus-view-pseudos 'not-confirm)))
9638           (setq pslist (cdr pslist)))
9639       (save-excursion
9640         (while pslist
9641           (setq after-article (or (cdr (assq 'article (car pslist)))
9642                                   (gnus-summary-article-number)))
9643           (gnus-summary-goto-subject after-article)
9644           (forward-line 1)
9645           (setq b (point))
9646           (insert "    " (file-name-nondirectory
9647                           (cdr (assq 'name (car pslist))))
9648                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9649           (setq e (point))
9650           (forward-line -1)             ; back to `b'
9651           (gnus-add-text-properties
9652            b (1- e) (list 'gnus-number gnus-reffed-article-number
9653                           gnus-mouse-face-prop gnus-mouse-face))
9654           (gnus-data-enter
9655            after-article gnus-reffed-article-number
9656            gnus-unread-mark b (car pslist) 0 (- e b))
9657           (push gnus-reffed-article-number gnus-newsgroup-unreads)
9658           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9659           (setq pslist (cdr pslist)))))))
9660
9661 (defun gnus-pseudos< (p1 p2)
9662   (let ((c1 (cdr (assq 'action p1)))
9663         (c2 (cdr (assq 'action p2))))
9664     (and c1 c2 (string< c1 c2))))
9665
9666 (defun gnus-request-pseudo-article (props)
9667   (cond ((assq 'execute props)
9668          (gnus-execute-command (cdr (assq 'execute props)))))
9669   (let ((gnus-current-article (gnus-summary-article-number)))
9670     (gnus-run-hooks 'gnus-mark-article-hook)))
9671
9672 (defun gnus-execute-command (command &optional automatic)
9673   (save-excursion
9674     (gnus-article-setup-buffer)
9675     (set-buffer gnus-article-buffer)
9676     (setq buffer-read-only nil)
9677     (let ((command (if automatic command
9678                      (read-string "Command: " (cons command 0)))))
9679       (erase-buffer)
9680       (insert "$ " command "\n\n")
9681       (if gnus-view-pseudo-asynchronously
9682           (start-process "gnus-execute" (current-buffer) shell-file-name
9683                          shell-command-switch command)
9684         (call-process shell-file-name nil t nil
9685                       shell-command-switch command)))))
9686
9687 ;; Summary kill commands.
9688
9689 (defun gnus-summary-edit-global-kill (article)
9690   "Edit the \"global\" kill file."
9691   (interactive (list (gnus-summary-article-number)))
9692   (gnus-group-edit-global-kill article))
9693
9694 (defun gnus-summary-edit-local-kill ()
9695   "Edit a local kill file applied to the current newsgroup."
9696   (interactive)
9697   (setq gnus-current-headers (gnus-summary-article-header))
9698   (gnus-group-edit-local-kill
9699    (gnus-summary-article-number) gnus-newsgroup-name))
9700
9701 ;;; Header reading.
9702
9703 (defun gnus-read-header (id &optional header)
9704   "Read the headers of article ID and enter them into the Gnus system."
9705   (let ((group gnus-newsgroup-name)
9706         (gnus-override-method
9707          (or
9708           gnus-override-method
9709           (and (gnus-news-group-p gnus-newsgroup-name)
9710                (car (gnus-refer-article-methods)))))
9711         where)
9712     ;; First we check to see whether the header in question is already
9713     ;; fetched.
9714     (if (stringp id)
9715         ;; This is a Message-ID.
9716         (setq header (or header (gnus-id-to-header id)))
9717       ;; This is an article number.
9718       (setq header (or header (gnus-summary-article-header id))))
9719     (if (and header
9720              (not (gnus-summary-article-sparse-p (mail-header-number header))))
9721         ;; We have found the header.
9722         header
9723       ;; If this is a sparse article, we have to nix out its
9724       ;; previous entry in the thread hashtb.
9725       (when (and header
9726                  (gnus-summary-article-sparse-p (mail-header-number header)))
9727         (let* ((parent (gnus-parent-id (mail-header-references header)))
9728                (thread (and parent (gnus-id-to-thread parent))))
9729           (when thread
9730             (delq (assq header thread) thread))))
9731       ;; We have to really fetch the header to this article.
9732       (save-excursion
9733         (set-buffer nntp-server-buffer)
9734         (when (setq where (gnus-request-head id group))
9735           (nnheader-fold-continuation-lines)
9736           (goto-char (point-max))
9737           (insert ".\n")
9738           (goto-char (point-min))
9739           (insert "211 ")
9740           (princ (cond
9741                   ((numberp id) id)
9742                   ((cdr where) (cdr where))
9743                   (header (mail-header-number header))
9744                   (t gnus-reffed-article-number))
9745                  (current-buffer))
9746           (insert " Article retrieved.\n"))
9747         (if (or (not where)
9748                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9749             ()                          ; Malformed head.
9750           (unless (gnus-summary-article-sparse-p (mail-header-number header))
9751             (when (and (stringp id)
9752                        (not (string= (gnus-group-real-name group)
9753                                      (car where))))
9754               ;; If we fetched by Message-ID and the article came
9755               ;; from a different group, we fudge some bogus article
9756               ;; numbers for this article.
9757               (mail-header-set-number header gnus-reffed-article-number))
9758             (save-excursion
9759               (set-buffer gnus-summary-buffer)
9760               (decf gnus-reffed-article-number)
9761               (gnus-remove-header (mail-header-number header))
9762               (push header gnus-newsgroup-headers)
9763               (setq gnus-current-headers header)
9764               (push (mail-header-number header) gnus-newsgroup-limit)))
9765           header)))))
9766
9767 (defun gnus-remove-header (number)
9768   "Remove header NUMBER from `gnus-newsgroup-headers'."
9769   (if (and gnus-newsgroup-headers
9770            (= number (mail-header-number (car gnus-newsgroup-headers))))
9771       (pop gnus-newsgroup-headers)
9772     (let ((headers gnus-newsgroup-headers))
9773       (while (and (cdr headers)
9774                   (not (= number (mail-header-number (cadr headers)))))
9775         (pop headers))
9776       (when (cdr headers)
9777         (setcdr headers (cddr headers))))))
9778
9779 ;;;
9780 ;;; summary highlights
9781 ;;;
9782
9783 (defun gnus-highlight-selected-summary ()
9784   "Highlight selected article in summary buffer."
9785   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
9786   (when gnus-summary-selected-face
9787     (save-excursion
9788       (let* ((beg (progn (beginning-of-line) (point)))
9789              (end (progn (end-of-line) (point)))
9790              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9791              (from (if (get-text-property beg gnus-mouse-face-prop)
9792                        beg
9793                      (or (next-single-property-change
9794                           beg gnus-mouse-face-prop nil end)
9795                          beg)))
9796              (to
9797               (if (= from end)
9798                   (- from 2)
9799                 (or (next-single-property-change
9800                      from gnus-mouse-face-prop nil end)
9801                     end))))
9802         ;; If no mouse-face prop on line we will have to = from = end,
9803         ;; so we highlight the entire line instead.
9804         (when (= (+ to 2) from)
9805           (setq from beg)
9806           (setq to end))
9807         (if gnus-newsgroup-selected-overlay
9808             ;; Move old overlay.
9809             (gnus-move-overlay
9810              gnus-newsgroup-selected-overlay from to (current-buffer))
9811           ;; Create new overlay.
9812           (gnus-overlay-put
9813            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9814            'face gnus-summary-selected-face))))))
9815
9816 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9817 (defun gnus-summary-highlight-line ()
9818   "Highlight current line according to `gnus-summary-highlight'."
9819   (let* ((list gnus-summary-highlight)
9820          (p (point))
9821          (end (progn (end-of-line) (point)))
9822          ;; now find out where the line starts and leave point there.
9823          (beg (progn (beginning-of-line) (point)))
9824          (article (gnus-summary-article-number))
9825          (score (or (cdr (assq (or article gnus-current-article)
9826                                gnus-newsgroup-scored))
9827                     gnus-summary-default-score 0))
9828          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9829          (inhibit-read-only t))
9830     ;; Eval the cars of the lists until we find a match.
9831     (let ((default gnus-summary-default-score))
9832       (while (and list
9833                   (not (eval (caar list))))
9834         (setq list (cdr list))))
9835     (let ((face (cdar list)))
9836       (unless (eq face (get-text-property beg 'face))
9837         (gnus-put-text-property-excluding-characters-with-faces
9838          beg end 'face
9839          (setq face (if (boundp face) (symbol-value face) face)))
9840         (when gnus-summary-highlight-line-function
9841           (funcall gnus-summary-highlight-line-function article face))))
9842     (goto-char p)))
9843
9844 (defun gnus-update-read-articles (group unread &optional compute)
9845   "Update the list of read articles in GROUP."
9846   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9847          (entry (gnus-gethash group gnus-newsrc-hashtb))
9848          (info (nth 2 entry))
9849          (prev 1)
9850          (unread (sort (copy-sequence unread) '<))
9851          read)
9852     (if (or (not info) (not active))
9853         ;; There is no info on this group if it was, in fact,
9854         ;; killed.  Gnus stores no information on killed groups, so
9855         ;; there's nothing to be done.
9856         ;; One could store the information somewhere temporarily,
9857         ;; perhaps...  Hmmm...
9858         ()
9859       ;; Remove any negative articles numbers.
9860       (while (and unread (< (car unread) 0))
9861         (setq unread (cdr unread)))
9862       ;; Remove any expired article numbers
9863       (while (and unread (< (car unread) (car active)))
9864         (setq unread (cdr unread)))
9865       ;; Compute the ranges of read articles by looking at the list of
9866       ;; unread articles.
9867       (while unread
9868         (when (/= (car unread) prev)
9869           (push (if (= prev (1- (car unread))) prev
9870                   (cons prev (1- (car unread))))
9871                 read))
9872         (setq prev (1+ (car unread)))
9873         (setq unread (cdr unread)))
9874       (when (<= prev (cdr active))
9875         (push (cons prev (cdr active)) read))
9876       (setq read (if (> (length read) 1) (nreverse read) read))
9877       (if compute
9878           read
9879         (save-excursion
9880           (let (setmarkundo)
9881             ;; Propagate the read marks to the backend.
9882             (when (gnus-check-backend-function 'request-set-mark group)
9883               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9884                     (add (gnus-remove-from-range read (gnus-info-read info))))
9885                 (when (or add del)
9886                   (unless (gnus-check-group group)
9887                     (error "Can't open server for %s" group))
9888                   (gnus-request-set-mark
9889                    group (delq nil (list (if add (list add 'add '(read)))
9890                                          (if del (list del 'del '(read))))))
9891                   (setq setmarkundo
9892                         `(gnus-request-set-mark
9893                           ,group
9894                           ',(delq nil (list
9895                                        (if del (list del 'add '(read)))
9896                                        (if add (list add 'del '(read))))))))))
9897             (set-buffer gnus-group-buffer)
9898             (gnus-undo-register
9899               `(progn
9900                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9901                  (gnus-info-set-read ',info ',(gnus-info-read info))
9902                  (gnus-get-unread-articles-in-group ',info 
9903                                                     (gnus-active ,group))
9904                  (gnus-group-update-group ,group t)
9905                  ,setmarkundo))))
9906         ;; Enter this list into the group info.
9907         (gnus-info-set-read info read)
9908         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9909         (gnus-get-unread-articles-in-group info (gnus-active group))
9910         t))))
9911
9912 (defun gnus-offer-save-summaries ()
9913   "Offer to save all active summary buffers."
9914   (save-excursion
9915     (let ((buflist (buffer-list))
9916           buffers bufname)
9917       ;; Go through all buffers and find all summaries.
9918       (while buflist
9919         (and (setq bufname (buffer-name (car buflist)))
9920              (string-match "Summary" bufname)
9921              (save-excursion
9922                (set-buffer bufname)
9923                ;; We check that this is, indeed, a summary buffer.
9924                (and (eq major-mode 'gnus-summary-mode)
9925                     ;; Also make sure this isn't bogus.
9926                     gnus-newsgroup-prepared
9927                     ;; Also make sure that this isn't a dead summary buffer.
9928                     (not gnus-dead-summary-mode)))
9929              (push bufname buffers))
9930         (setq buflist (cdr buflist)))
9931       ;; Go through all these summary buffers and offer to save them.
9932       (when buffers
9933         (map-y-or-n-p
9934          "Update summary buffer %s? "
9935          (lambda (buf)
9936            (switch-to-buffer buf)
9937            (gnus-summary-exit))
9938          buffers)))))
9939
9940
9941 ;;; @ for mime-partial
9942 ;;;
9943
9944 (defun gnus-request-partial-message ()
9945   (save-excursion
9946     (let ((number (gnus-summary-article-number))
9947           (group gnus-newsgroup-name)
9948           (mother gnus-article-buffer))
9949       (set-buffer (get-buffer-create " *Partial Article*"))
9950       (erase-buffer)
9951       (setq mime-preview-buffer mother)
9952       (gnus-request-article-this-buffer number group)
9953       (mime-parse-buffer)
9954       )))
9955
9956 (autoload 'mime-combine-message/partial-pieces-automatically
9957   "mime-partial"
9958   "Internal method to combine message/partial messages automatically.")
9959
9960 (mime-add-condition
9961  'action '((type . message)(subtype . partial)
9962            (major-mode . gnus-original-article-mode)
9963            (method . mime-combine-message/partial-pieces-automatically)
9964            (summary-buffer-exp . gnus-summary-buffer)
9965            (request-partial-message-method . gnus-request-partial-message)
9966            ))
9967
9968
9969 ;;; @ for message/rfc822
9970 ;;;
9971
9972 (defun gnus-mime-extract-message/rfc822 (entity situation)
9973   (let (group article num cwin swin cur)
9974     (with-temp-buffer
9975       (mime-insert-entity-content entity)
9976       (setq group (or (cdr (assq 'group situation))
9977                       (completing-read "Group: "
9978                                        gnus-active-hashtb
9979                                        nil
9980                                        (gnus-read-active-file-p)
9981                                        gnus-newsgroup-name))
9982             article (gnus-request-accept-article group)))
9983     (when (and (consp article)
9984                (numberp (setq article (cdr article))))
9985       (setq num (1+ (or (cdr (assq 'number situation)) 0))
9986             cwin (get-buffer-window (current-buffer) t))
9987       (save-window-excursion
9988         (if (setq swin (get-buffer-window gnus-summary-buffer t))
9989             (select-window swin)
9990           (set-buffer gnus-summary-buffer))
9991         (setq cur gnus-current-article)
9992         (forward-line num)
9993         (let (gnus-show-threads)
9994           (gnus-summary-goto-subject article t))
9995         (gnus-summary-clear-mark-forward 1)
9996         (gnus-summary-goto-subject cur))
9997       (when (and cwin (window-frame cwin))
9998         (select-frame (window-frame cwin)))
9999       (when (boundp 'mime-acting-situation-to-override)
10000         (set-alist 'mime-acting-situation-to-override
10001                    'group
10002                    group)
10003         (set-alist 'mime-acting-situation-to-override
10004                    'after-method
10005                    `(progn
10006                       (save-current-buffer
10007                         (set-buffer gnus-group-buffer)
10008                         (gnus-activate-group ,group))
10009                       (gnus-summary-goto-article ,cur
10010                                                  gnus-show-all-headers)))
10011         (set-alist 'mime-acting-situation-to-override
10012                    'number num)))))
10013
10014 (mime-add-condition
10015  'action '((type . message)(subtype . rfc822)
10016            (major-mode . gnus-original-article-mode)
10017            (method . gnus-mime-extract-message/rfc822)
10018            (mode . "extract")
10019            ))
10020
10021 (mime-add-condition
10022  'action '((type . message)(subtype . news)
10023            (major-mode . gnus-original-article-mode)
10024            (method . gnus-mime-extract-message/rfc822)
10025            (mode . "extract")
10026            ))
10027
10028 (defun gnus-mime-extract-multipart (entity situation)
10029   (let ((children (mime-entity-children entity))
10030         mime-acting-situation-to-override
10031         f)
10032     (while children
10033       (mime-play-entity (car children)
10034                         (cons (assq 'mode situation)
10035                               mime-acting-situation-to-override))
10036       (setq children (cdr children)))
10037     (if (setq f (cdr (assq 'after-method
10038                            mime-acting-situation-to-override)))
10039         (eval f)
10040       )))
10041
10042 (mime-add-condition
10043  'action '((type . multipart)
10044            (method . gnus-mime-extract-multipart)
10045            (mode . "extract")
10046            )
10047  'with-default)
10048
10049
10050 ;;; @ end
10051 ;;;
10052
10053 (defun gnus-summary-setup-default-charset ()
10054   "Setup newsgroup default charset."
10055   (if (equal gnus-newsgroup-name "nndraft:drafts")
10056       (setq gnus-newsgroup-charset nil)
10057     (let* ((name (and gnus-newsgroup-name
10058                       (gnus-group-real-name gnus-newsgroup-name)))
10059            (ignored-charsets
10060             (or gnus-newsgroup-ephemeral-ignored-charsets
10061                 (append
10062                  (and gnus-newsgroup-name
10063                       (or (gnus-group-find-parameter gnus-newsgroup-name
10064                                                      'ignored-charsets t)
10065                           (let ((alist gnus-group-ignored-charsets-alist)
10066                                 elem (charsets nil))
10067                             (while (setq elem (pop alist))
10068                               (when (and name
10069                                          (string-match (car elem) name))
10070                                 (setq alist nil
10071                                       charsets (cdr elem))))
10072                             charsets)))
10073                  gnus-newsgroup-ignored-charsets))))
10074       (setq gnus-newsgroup-charset
10075             (or gnus-newsgroup-ephemeral-charset
10076                 (and gnus-newsgroup-name
10077                      (or (gnus-group-find-parameter gnus-newsgroup-name 'charset)
10078                          (let ((alist gnus-group-charset-alist)
10079                                elem charset)
10080                            (while (setq elem (pop alist))
10081                              (when (and name
10082                                         (string-match (car elem) name))
10083                                (setq alist nil
10084                                      charset (cadr elem))))
10085                            charset)))
10086                 gnus-default-charset))
10087       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10088            ignored-charsets))))
10089
10090 ;;;
10091 ;;; Mime Commands
10092 ;;;
10093
10094 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10095   "Display the current article buffer fully MIME-buttonized.
10096 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10097 treated as multipart/mixed."
10098   (interactive "P")
10099   (require 'gnus-art)
10100   (let ((gnus-unbuttonized-mime-types nil)
10101         (gnus-mime-display-multipart-as-mixed show-all-parts))
10102     (gnus-summary-show-article)))
10103
10104 (defun gnus-summary-repair-multipart (article)
10105   "Add a Content-Type header to a multipart article without one."
10106   (interactive (list (gnus-summary-article-number)))
10107   (gnus-with-article article
10108     (message-narrow-to-head)
10109     (message-remove-header "Mime-Version")
10110     (goto-char (point-max))
10111     (insert "Mime-Version: 1.0\n")
10112     (widen)
10113     (when (search-forward "\n--" nil t)
10114       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10115         (message-narrow-to-head)
10116         (message-remove-header "Content-Type")
10117         (goto-char (point-max))
10118         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10119                         separator))
10120         (widen))))
10121   (let (gnus-mark-article-hook)
10122     (gnus-summary-select-article t t nil article)))
10123
10124 (defun gnus-summary-toggle-display-buttonized ()
10125   "Toggle the buttonizing of the article buffer."
10126   (interactive)
10127   (require 'gnus-art)
10128   (if (setq gnus-inhibit-mime-unbuttonizing
10129             (not gnus-inhibit-mime-unbuttonizing))
10130       (let ((gnus-unbuttonized-mime-types nil))
10131         (gnus-summary-show-article))
10132     (gnus-summary-show-article)))
10133
10134 ;;;
10135 ;;; Intelli-mouse commmands
10136 ;;;
10137
10138 (defun gnus-wheel-summary-scroll (event)
10139   (interactive "e")
10140   (let ((amount (if (memq 'shift (event-modifiers event))
10141                     (car gnus-wheel-scroll-amount)
10142                   (cdr gnus-wheel-scroll-amount)))
10143         (direction (- (* (static-if (featurep 'xemacs)
10144                              (event-button event)
10145                            (cond ((eq 'mouse-4 (event-basic-type event))
10146                                   4)
10147                                  ((eq 'mouse-5 (event-basic-type event))
10148                                   5)))
10149                          2) 9))
10150         edge)
10151     (gnus-summary-scroll-up (* amount direction))
10152     (when (gnus-eval-in-buffer-window gnus-article-buffer
10153             (save-restriction
10154               (widen)
10155               (and (if (< 0 direction)
10156                        (gnus-article-next-page 0)
10157                      (gnus-article-prev-page 0)
10158                      (bobp))
10159                    (if (setq edge (get-text-property
10160                                    (point-min) 'gnus-wheel-edge))
10161                        (setq edge (* edge direction))
10162                      (setq edge -1))
10163                    (or (plusp edge)
10164                        (let ((buffer-read-only nil)
10165                              (inhibit-read-only t))
10166                          (put-text-property (point-min) (point-max)
10167                                             'gnus-wheel-edge direction)
10168                          nil))
10169                    (or (> edge gnus-wheel-edge-resistance)
10170                        (let ((buffer-read-only nil)
10171                              (inhibit-read-only t))
10172                          (put-text-property (point-min) (point-max)
10173                                             'gnus-wheel-edge
10174                                             (* (1+ edge) direction))
10175                          nil))
10176                    (eq last-command 'gnus-wheel-summary-scroll))))
10177       (gnus-summary-next-article nil nil (minusp direction)))))
10178
10179 (defun gnus-wheel-install ()
10180   "Enable mouse wheel support on summary window."
10181   (when gnus-use-wheel
10182     (let ((keys
10183            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
10184       (dolist (key keys)
10185         (define-key gnus-summary-mode-map key
10186           'gnus-wheel-summary-scroll)))))
10187
10188 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
10189
10190 ;;;
10191 ;;; Traditional PGP commmands
10192 ;;;
10193
10194 (defun gnus-summary-decrypt-article (&optional force)
10195   "Decrypt the current article in traditional PGP way.
10196 This will have permanent effect only in mail groups.
10197 If FORCE is non-nil, allow editing of articles even in read-only
10198 groups."
10199   (interactive "P")
10200   (gnus-summary-select-article t)
10201   (gnus-eval-in-buffer-window gnus-article-buffer
10202     (save-excursion
10203       (save-restriction
10204         (widen)
10205         (goto-char (point-min))
10206         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
10207           (error "Not a traditional PGP message!"))
10208         (let ((armor-start (match-beginning 0)))
10209           (if (and (pgg-decrypt-region armor-start (point-max))
10210                    (or force (not (gnus-group-read-only-p))))
10211               (let ((inhibit-read-only t)
10212                     buffer-read-only)
10213                 (delete-region armor-start
10214                                (progn
10215                                  (re-search-forward "^-+END PGP" nil t)
10216                                  (beginning-of-line 2)
10217                                  (point)))
10218                 (insert-buffer-substring pgg-output-buffer))))))))
10219
10220 (defun gnus-summary-verify-article ()
10221   "Verify the current article in traditional PGP way."
10222   (interactive)
10223   (save-excursion
10224     (set-buffer gnus-original-article-buffer)
10225     (goto-char (point-min))
10226     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
10227       (error "Not a traditional PGP message!"))
10228     (re-search-forward "^-+END PGP" nil t)
10229     (beginning-of-line 2)
10230     (call-interactively (function pgg-verify-region))))
10231
10232 ;;;
10233 ;;; Generic summary marking commands
10234 ;;;
10235
10236 (defvar gnus-summary-marking-alist
10237   '((read gnus-del-mark "d")
10238     (unread gnus-unread-mark "u")
10239     (ticked gnus-ticked-mark "!")
10240     (dormant gnus-dormant-mark "?")
10241     (expirable gnus-expirable-mark "e"))
10242   "An alist of names/marks/keystrokes.")
10243
10244 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10245 (defvar gnus-summary-mark-map)
10246
10247 (defun gnus-summary-make-all-marking-commands ()
10248   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10249   (dolist (elem gnus-summary-marking-alist)
10250     (apply 'gnus-summary-make-marking-command elem)))
10251
10252 (defun gnus-summary-make-marking-command (name mark keystroke)
10253   (let ((map (make-sparse-keymap)))
10254     (define-key gnus-summary-generic-mark-map keystroke map)
10255     (dolist (lway `((next "next" next nil "n")
10256                     (next-unread "next unread" next t "N")
10257                     (prev "previous" prev nil "p")
10258                     (prev-unread "previous unread" prev t "P")
10259                     (nomove "" nil nil ,keystroke)))
10260       (let ((func (gnus-summary-make-marking-command-1
10261                    mark (car lway) lway name)))
10262         (setq func (eval func))
10263         (define-key map (nth 4 lway) func)))))
10264
10265 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10266   `(defun ,(intern
10267             (format "gnus-summary-put-mark-as-%s%s"
10268                     name (if (eq way 'nomove)
10269                              ""
10270                            (concat "-" (symbol-name way)))))
10271      (n)
10272      ,(format
10273        "Mark the current article as %s%s.
10274 If N, the prefix, then repeat N times.
10275 If N is negative, move in reverse order.
10276 The difference between N and the actual number of articles marked is
10277 returned."
10278        name (car (cdr lway)))
10279      (interactive "p")
10280      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10281
10282 (defun gnus-summary-generic-mark (n mark move unread)
10283   "Mark N articles with MARK."
10284   (unless (eq major-mode 'gnus-summary-mode)
10285     (error "This command can only be used in the summary buffer"))
10286   (gnus-summary-show-thread)
10287   (let ((nummove
10288          (cond
10289           ((eq move 'next) 1)
10290           ((eq move 'prev) -1)
10291           (t 0))))
10292     (if (zerop nummove)
10293         (setq n 1)
10294       (when (< n 0)
10295         (setq n (abs n)
10296               nummove (* -1 nummove))))
10297     (while (and (> n 0)
10298                 (gnus-summary-mark-article nil mark)
10299                 (zerop (gnus-summary-next-subject nummove unread t)))
10300       (setq n (1- n)))
10301     (when (/= 0 n)
10302       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10303     (gnus-summary-recenter)
10304     (gnus-summary-position-point)
10305     (gnus-set-mode-line 'summary)
10306     n))
10307
10308 (gnus-summary-make-all-marking-commands)
10309
10310 (gnus-ems-redefine)
10311
10312 (provide 'gnus-sum)
10313
10314 (run-hooks 'gnus-sum-load-hook)
10315
10316 ;;; gnus-sum.el ends here