Revision: miles@gnu.org--gnu-2005/gnus--devo--0--patch-37
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
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 (require 'mm-decode)
41 (require 'nnoo)
42
43 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
44 (autoload 'gnus-cache-write-active "gnus-cache")
45 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
46 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
47 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
48 (autoload 'mm-uu-dissect "mm-uu")
49 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
50   "Deuglify broken Outlook (Express) articles and redisplay."
51   t)
52 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
53 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
54 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
55
56 (defcustom gnus-kill-summary-on-exit t
57   "*If non-nil, kill the summary buffer when you exit from it.
58 If nil, the summary will become a \"*Dead Summary*\" buffer, and
59 it will be killed sometime later."
60   :group 'gnus-summary-exit
61   :type 'boolean)
62
63 (defcustom gnus-fetch-old-headers nil
64   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
65 If an unread article in the group refers to an older, already read (or
66 just marked as read) article, the old article will not normally be
67 displayed in the Summary buffer.  If this variable is t, Gnus
68 will attempt to grab the headers to the old articles, and thereby
69 build complete threads.  If it has the value `some', only enough
70 headers to connect otherwise loose threads will be displayed.  This
71 variable can also be a number.  In that case, no more than that number
72 of old headers will be fetched.  If it has the value `invisible', all
73 old headers will be fetched, but none will be displayed.
74
75 The server has to support NOV for any of this to work."
76   :group 'gnus-thread
77   :type '(choice (const :tag "off" nil)
78                  (const :tag "on" t)
79                  (const some)
80                  (const invisible)
81                  number
82                  (sexp :menu-tag "other" t)))
83
84 (defcustom gnus-refer-thread-limit 200
85   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
86 If t, fetch all the available old headers."
87   :group 'gnus-thread
88   :type '(choice number
89                  (sexp :menu-tag "other" t)))
90
91 (defcustom gnus-summary-make-false-root 'adopt
92   "*nil means that Gnus won't gather loose threads.
93 If the root of a thread has expired or been read in a previous
94 session, the information necessary to build a complete thread has been
95 lost.  Instead of having many small sub-threads from this original thread
96 scattered all over the summary buffer, Gnus can gather them.
97
98 If non-nil, Gnus will try to gather all loose sub-threads from an
99 original thread into one large thread.
100
101 If this variable is non-nil, it should be one of `none', `adopt',
102 `dummy' or `empty'.
103
104 If this variable is `none', Gnus will not make a false root, but just
105 present the sub-threads after another.
106 If this variable is `dummy', Gnus will create a dummy root that will
107 have all the sub-threads as children.
108 If this variable is `adopt', Gnus will make one of the \"children\"
109 the parent and mark all the step-children as such.
110 If this variable is `empty', the \"children\" are printed with empty
111 subject fields.  (Or rather, they will be printed with a string
112 given by the `gnus-summary-same-subject' variable.)"
113   :group 'gnus-thread
114   :type '(choice (const :tag "off" nil)
115                  (const none)
116                  (const dummy)
117                  (const adopt)
118                  (const empty)))
119
120 (defcustom gnus-summary-make-false-root-always nil
121   "Always make a false dummy root."
122   :version "22.1"
123   :group 'gnus-thread
124   :type 'boolean)
125
126 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
127   "*A regexp to match subjects to be excluded from loose thread gathering.
128 As loose thread gathering is done on subjects only, that means that
129 there can be many false gatherings performed.  By rooting out certain
130 common subjects, gathering might become saner."
131   :group 'gnus-thread
132   :type 'regexp)
133
134 (defcustom gnus-summary-gather-subject-limit nil
135   "*Maximum length of subject comparisons when gathering loose threads.
136 Use nil to compare full subjects.  Setting this variable to a low
137 number will help gather threads that have been corrupted by
138 newsreaders chopping off subject lines, but it might also mean that
139 unrelated articles that have subject that happen to begin with the
140 same few characters will be incorrectly gathered.
141
142 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
143 comparing subjects."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  (const fuzzy)
147                  (sexp :menu-tag "on" t)))
148
149 (defcustom gnus-simplify-subject-functions nil
150   "List of functions taking a string argument that simplify subjects.
151 The functions are applied recursively.
152
153 Useful functions to put in this list include:
154 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
155 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
156   :group 'gnus-thread
157   :type '(repeat function))
158
159 (defcustom gnus-simplify-ignored-prefixes nil
160   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
161   :group 'gnus-thread
162   :type '(choice (const :tag "off" nil)
163                  regexp))
164
165 (defcustom gnus-build-sparse-threads nil
166   "*If non-nil, fill in the gaps in threads.
167 If `some', only fill in the gaps that are needed to tie loose threads
168 together.  If `more', fill in all leaf nodes that Gnus can find.  If
169 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  (const some)
173                  (const more)
174                  (sexp :menu-tag "all" t)))
175
176 (defcustom gnus-summary-thread-gathering-function
177   'gnus-gather-threads-by-subject
178   "*Function used for gathering loose threads.
179 There are two pre-defined functions: `gnus-gather-threads-by-subject',
180 which only takes Subjects into consideration; and
181 `gnus-gather-threads-by-references', which compared the References
182 headers of the articles to find matches."
183   :group 'gnus-thread
184   :type '(radio (function-item gnus-gather-threads-by-subject)
185                 (function-item gnus-gather-threads-by-references)
186                 (function :tag "other")))
187
188 (defcustom gnus-summary-same-subject ""
189   "*String indicating that the current article has the same subject as the previous.
190 This variable will only be used if the value of
191 `gnus-summary-make-false-root' is `empty'."
192   :group 'gnus-summary-format
193   :type 'string)
194
195 (defcustom gnus-summary-goto-unread t
196   "*If t, many commands will go to the next unread article.
197 This applies to marking commands as well as other commands that
198 \"naturally\" select the next article, like, for instance, `SPC' at
199 the end of an article.
200
201 If nil, the marking commands do NOT go to the next unread article
202 \(they go to the next article instead).  If `never', commands that
203 usually go to the next unread article, will go to the next article,
204 whether it is read or not."
205   :group 'gnus-summary-marks
206   :link '(custom-manual "(gnus)Setting Marks")
207   :type '(choice (const :tag "off" nil)
208                  (const never)
209                  (sexp :menu-tag "on" t)))
210
211 (defcustom gnus-summary-default-score 0
212   "*Default article score level.
213 All scores generated by the score files will be added to this score.
214 If this variable is nil, scoring will be disabled."
215   :group 'gnus-score-default
216   :type '(choice (const :tag "disable")
217                  integer))
218
219 (defcustom gnus-summary-default-high-score 0
220   "*Default threshold for a high scored article.
221 An article will be highlighted as high scored if its score is greater
222 than this score."
223   :version "22.1"
224   :group 'gnus-score-default
225   :type 'integer)
226
227 (defcustom gnus-summary-default-low-score 0
228   "*Default threshold for a low scored article.
229 An article will be highlighted as low scored if its score is smaller
230 than this score."
231   :version "22.1"
232   :group 'gnus-score-default
233   :type 'integer)
234
235 (defcustom gnus-summary-zcore-fuzz 0
236   "*Fuzziness factor for the zcore in the summary buffer.
237 Articles with scores closer than this to `gnus-summary-default-score'
238 will not be marked."
239   :group 'gnus-summary-format
240   :type 'integer)
241
242 (defcustom gnus-simplify-subject-fuzzy-regexp nil
243   "*Strings to be removed when doing fuzzy matches.
244 This can either be a regular expression or list of regular expressions
245 that will be removed from subject strings if fuzzy subject
246 simplification is selected."
247   :group 'gnus-thread
248   :type '(repeat regexp))
249
250 (defcustom gnus-show-threads t
251   "*If non-nil, display threads in summary mode."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-hide-subtree nil
256   "*If non-nil, hide all threads initially.
257 This can be a predicate specifier which says which threads to hide.
258 If threads are hidden, you have to run the command
259 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
260 to expose hidden threads."
261   :group 'gnus-thread
262   :type '(radio (sexp :format "Non-nil\n"
263                       :match (lambda (widget value)
264                                (not (or (consp value) (functionp value))))
265                       :value t)
266                 (const nil)
267                 (sexp :tag "Predicate specifier")))
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :version "22.1"
328   :group 'gnus-group-select
329   :type '(choice (const best)
330                  (const unread)
331                  (const first)
332                  (const unseen)
333                  (const unseen-or-unread)))
334
335 (defcustom gnus-auto-select-next t
336   "*If non-nil, offer to go to the next group from the end of the previous.
337 If the value is t and the next newsgroup is empty, Gnus will exit
338 summary mode and go back to group mode.  If the value is neither nil
339 nor t, Gnus will select the following unread newsgroup.  In
340 particular, if the value is the symbol `quietly', the next unread
341 newsgroup will be selected without any confirmation, and if it is
342 `almost-quietly', the next group will be selected without any
343 confirmation if you are located on the last article in the group.
344 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
345 will go to the next group without confirmation."
346   :group 'gnus-summary-maneuvering
347   :type '(choice (const :tag "off" nil)
348                  (const quietly)
349                  (const almost-quietly)
350                  (const slightly-quietly)
351                  (sexp :menu-tag "on" t)))
352
353 (defcustom gnus-auto-select-same nil
354   "*If non-nil, select the next article with the same subject.
355 If there are no more articles with the same subject, go to
356 the first unread article."
357   :group 'gnus-summary-maneuvering
358   :type 'boolean)
359
360 (defcustom gnus-auto-goto-ignores 'unfetched
361   "*Says how to handle unfetched articles when maneuvering.
362
363 This variable can either be the symbols nil (maneuver to any
364 article), `undownloaded' (maneuvering while unplugged ignores articles
365 that have not been fetched), `always-undownloaded' (maneuvering always
366 ignores articles that have not been fetched), `unfetched' (maneuvering
367 ignores articles whose headers have not been fetched).
368
369 NOTE: The list of unfetched articles will always be nil when plugged
370 and, when unplugged, a subset of the undownloaded article list."
371   :version "22.1"
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "None" nil)
374                  (const :tag "Undownloaded when unplugged" undownloaded)
375                  (const :tag "Undownloaded" always-undownloaded)
376                  (const :tag "Unfetched" unfetched)))
377
378 (defcustom gnus-summary-check-current nil
379   "*If non-nil, consider the current article when moving.
380 The \"unread\" movement commands will stay on the same line if the
381 current article is unread."
382   :group 'gnus-summary-maneuvering
383   :type 'boolean)
384
385 (defcustom gnus-auto-center-summary 2
386   "*If non-nil, always center the current summary buffer.
387 In particular, if `vertical' do only vertical recentering.  If non-nil
388 and non-`vertical', do both horizontal and vertical recentering."
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "none" nil)
391                  (const vertical)
392                  (integer :tag "height")
393                  (sexp :menu-tag "both" t)))
394
395 (defvar gnus-auto-center-group t
396   "*If non-nil, always center the group buffer.")
397
398 (defcustom gnus-show-all-headers nil
399   "*If non-nil, don't hide any headers."
400   :group 'gnus-article-hiding
401   :group 'gnus-article-headers
402   :type 'boolean)
403
404 (defcustom gnus-summary-ignore-duplicates nil
405   "*If non-nil, ignore articles with identical Message-ID headers."
406   :group 'gnus-summary
407   :type 'boolean)
408
409 (defcustom gnus-single-article-buffer t
410   "*If non-nil, display all articles in the same buffer.
411 If nil, each group will get its own article buffer."
412   :group 'gnus-article-various
413   :type 'boolean)
414
415 (defcustom gnus-break-pages t
416   "*If non-nil, do page breaking on articles.
417 The page delimiter is specified by the `gnus-page-delimiter'
418 variable."
419   :group 'gnus-article-various
420   :type 'boolean)
421
422 (defcustom gnus-move-split-methods nil
423   "*Variable used to suggest where articles are to be moved to.
424 It uses the same syntax as the `gnus-split-methods' variable.
425 However, whereas `gnus-split-methods' specifies file names as targets,
426 this variable specifies group names."
427   :group 'gnus-summary-mail
428   :type '(repeat (choice (list :value (fun) function)
429                          (cons :value ("" "") regexp (repeat string))
430                          (sexp :value nil))))
431
432 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
433   "Function used to compute default prefix for article move/copy/etc prompts.
434 The function should take one argument, a group name, and return a
435 string with the suggested prefix."
436   :group 'gnus-summary-mail
437   :type 'function)
438
439 ;; FIXME: Although the custom type is `character' for the following variables,
440 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
441
442 (defcustom gnus-unread-mark ?           ;Whitespace
443   "*Mark used for unread articles."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-ticked-mark ?!
448   "*Mark used for ticked articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-dormant-mark ??
453   "*Mark used for dormant articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-del-mark ?r
458   "*Mark used for del'd articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-read-mark ?R
463   "*Mark used for read articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-expirable-mark ?E
468   "*Mark used for expirable articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-killed-mark ?K
473   "*Mark used for killed articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-spam-mark ?$
478   "*Mark used for spam articles."
479   :version "22.1"
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-souped-mark ?F
484   "*Mark used for souped articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-kill-file-mark ?X
489   "*Mark used for articles killed by kill files."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-low-score-mark ?Y
494   "*Mark used for articles with a low score."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-catchup-mark ?C
499   "*Mark used for articles that are caught up."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-replied-mark ?A
504   "*Mark used for articles that have been replied to."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-forwarded-mark ?F
509   "*Mark used for articles that have been forwarded."
510   :version "22.1"
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-recent-mark ?N
515   "*Mark used for articles that are recent."
516   :version "22.1"
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :version "22.1"
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-no-mark ?               ;Whitespace
537   "*Mark used for articles that have no other secondary mark."
538   :version "22.1"
539   :group 'gnus-summary-marks
540   :type 'character)
541
542 (defcustom gnus-ancient-mark ?O
543   "*Mark used for ancient articles."
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-sparse-mark ?Q
548   "*Mark used for sparsely reffed articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-canceled-mark ?G
553   "*Mark used for canceled articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-duplicate-mark ?M
558   "*Mark used for duplicate articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-undownloaded-mark ?-
563   "*Mark used for articles that weren't downloaded."
564   :version "22.1"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-downloaded-mark ?+
569   "*Mark used for articles that were downloaded."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloadable-mark ?%
574   "*Mark used for articles that are to be downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unsendable-mark ?=
579   "*Mark used for articles that won't be sent."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-score-over-mark ?+
584   "*Score mark used for articles with high scores."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-below-mark ?-
589   "*Score mark used for articles with low scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-empty-thread-mark ?     ;Whitespace
594   "*There is no thread under the article."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-not-empty-thread-mark ?=
599   "*There is a thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-view-pseudo-asynchronously nil
604   "*If non-nil, Gnus will view pseudo-articles asynchronously."
605   :group 'gnus-extract-view
606   :type 'boolean)
607
608 (defcustom gnus-auto-expirable-marks
609   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
610         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
611         gnus-souped-mark gnus-duplicate-mark)
612   "*The list of marks converted into expiration if a group is auto-expirable."
613   :version "21.1"
614   :group 'gnus-summary
615   :type '(repeat character))
616
617 (defcustom gnus-inhibit-user-auto-expire t
618   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
619   :version "21.1"
620   :group 'gnus-summary
621   :type 'boolean)
622
623 (defcustom gnus-view-pseudos nil
624   "*If `automatic', pseudo-articles will be viewed automatically.
625 If `not-confirm', pseudos will be viewed automatically, and the user
626 will not be asked to confirm the command."
627   :group 'gnus-extract-view
628   :type '(choice (const :tag "off" nil)
629                  (const automatic)
630                  (const not-confirm)))
631
632 (defcustom gnus-view-pseudos-separately t
633   "*If non-nil, one pseudo-article will be created for each file to be viewed.
634 If nil, all files that use the same viewing command will be given as a
635 list of parameters to that command."
636   :group 'gnus-extract-view
637   :type 'boolean)
638
639 (defcustom gnus-insert-pseudo-articles t
640   "*If non-nil, insert pseudo-articles when decoding articles."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-summary-dummy-line-format
645   "   %(:                             :%) %S\n"
646   "*The format specification for the dummy roots in the summary buffer.
647 It works along the same lines as a normal formatting string,
648 with some simple extensions.
649
650 %S  The subject
651
652 General format specifiers can also be used.
653 See `(gnus)Formatting Variables'."
654   :link '(custom-manual "(gnus)Formatting Variables")
655   :group 'gnus-threading
656   :type 'string)
657
658 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
659   "*The format specification for the summary mode line.
660 It works along the same lines as a normal formatting string,
661 with some simple extensions:
662
663 %G  Group name
664 %p  Unprefixed group name
665 %A  Current article number
666 %z  Current article score
667 %V  Gnus version
668 %U  Number of unread articles in the group
669 %e  Number of unselected articles in the group
670 %Z  A string with unread/unselected article counts
671 %g  Shortish group name
672 %S  Subject of the current article
673 %u  User-defined spec
674 %s  Current score file name
675 %d  Number of dormant articles
676 %r  Number of articles that have been marked as read in this session
677 %E  Number of articles expunged by the score files"
678   :group 'gnus-summary-format
679   :type 'string)
680
681 (defcustom gnus-list-identifiers nil
682   "Regexp that matches list identifiers to be removed from subject.
683 This can also be a list of regexps."
684   :version "21.1"
685   :group 'gnus-summary-format
686   :group 'gnus-article-hiding
687   :type '(choice (const :tag "none" nil)
688                  (regexp :value ".*")
689                  (repeat :value (".*") regexp)))
690
691 (defcustom gnus-summary-mark-below 0
692   "*Mark all articles with a score below this variable as read.
693 This variable is local to each summary buffer and usually set by the
694 score file."
695   :group 'gnus-score-default
696   :type 'integer)
697
698 (defun gnus-widget-reversible-match (widget value)
699   "Ignoring WIDGET, convert VALUE to internal form.
700 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
701   ;; (debug value)
702   (or (symbolp value)
703       (and (listp value)
704            (eq (length value) 2)
705            (eq (nth 0 value) 'not)
706            (symbolp (nth 1 value)))))
707
708 (defun gnus-widget-reversible-to-internal (widget value)
709   "Ignoring WIDGET, convert VALUE to internal form.
710 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
711 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
712   ;; (debug value)
713   (if (atom value)
714       (list value nil)
715     (list (nth 1 value) t)))
716
717 (defun gnus-widget-reversible-to-external (widget value)
718   "Ignoring WIDGET, convert VALUE to external form.
719 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
720 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
721   ;; (debug value)
722   (if (nth 1 value)
723       (list 'not (nth 0 value))
724     (nth 0 value)))
725
726 (define-widget 'gnus-widget-reversible 'group
727   "A `group' that convert values."
728   :match 'gnus-widget-reversible-match
729   :value-to-internal 'gnus-widget-reversible-to-internal
730   :value-to-external 'gnus-widget-reversible-to-external)
731
732 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
733   "*List of functions used for sorting articles in the summary buffer.
734
735 Each function takes two articles and returns non-nil if the first
736 article should be sorted before the other.  If you use more than one
737 function, the primary sort function should be the last.  You should
738 probably always include `gnus-article-sort-by-number' in the list of
739 sorting functions -- preferably first.  Also note that sorting by date
740 is often much slower than sorting by number, and the sorting order is
741 very similar.  (Sorting by date means sorting by the time the message
742 was sent, sorting by number means sorting by arrival time.)
743
744 Each item can also be a list `(not F)' where F is a function;
745 this reverses the sort order.
746
747 Ready-made functions include `gnus-article-sort-by-number',
748 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
749 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
750 and `gnus-article-sort-by-score'.
751
752 When threading is turned on, the variable `gnus-thread-sort-functions'
753 controls how articles are sorted."
754   :group 'gnus-summary-sort
755   :type '(repeat (gnus-widget-reversible
756                   (choice (function-item gnus-article-sort-by-number)
757                           (function-item gnus-article-sort-by-author)
758                           (function-item gnus-article-sort-by-subject)
759                           (function-item gnus-article-sort-by-date)
760                           (function-item gnus-article-sort-by-score)
761                           (function-item gnus-article-sort-by-random)
762                           (function :tag "other"))
763                   (boolean :tag "Reverse order"))))
764
765
766 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
767   "*List of functions used for sorting threads in the summary buffer.
768 By default, threads are sorted by article number.
769
770 Each function takes two threads and returns non-nil if the first
771 thread should be sorted before the other.  If you use more than one
772 function, the primary sort function should be the last.  You should
773 probably always include `gnus-thread-sort-by-number' in the list of
774 sorting functions -- preferably first.  Also note that sorting by date
775 is often much slower than sorting by number, and the sorting order is
776 very similar.  (Sorting by date means sorting by the time the message
777 was sent, sorting by number means sorting by arrival time.)
778
779 Each list item can also be a list `(not F)' where F is a
780 function; this specifies reversed sort order.
781
782 Ready-made functions include `gnus-thread-sort-by-number',
783 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
784 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
785 `gnus-thread-sort-by-most-recent-number',
786 `gnus-thread-sort-by-most-recent-date',
787 `gnus-thread-sort-by-random', and
788 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
789
790 When threading is turned off, the variable
791 `gnus-article-sort-functions' controls how articles are sorted."
792   :group 'gnus-summary-sort
793   :type '(repeat 
794           (gnus-widget-reversible
795            (choice (function-item gnus-thread-sort-by-number)
796                    (function-item gnus-thread-sort-by-author)
797                    (function-item gnus-thread-sort-by-subject)
798                    (function-item gnus-thread-sort-by-date)
799                    (function-item gnus-thread-sort-by-score)
800                    (function-item gnus-thread-sort-by-most-recent-number)
801                    (function-item gnus-thread-sort-by-most-recent-date)
802                    (function-item gnus-thread-sort-by-random)
803                    (function-item gnus-thread-sort-by-total-score)
804                    (function :tag "other"))
805            (boolean :tag "Reverse order"))))
806
807 (defcustom gnus-thread-score-function '+
808   "*Function used for calculating the total score of a thread.
809
810 The function is called with the scores of the article and each
811 subthread and should then return the score of the thread.
812
813 Some functions you can use are `+', `max', or `min'."
814   :group 'gnus-summary-sort
815   :type 'function)
816
817 (defcustom gnus-summary-expunge-below nil
818   "All articles that have a score less than this variable will be expunged.
819 This variable is local to the summary buffers."
820   :group 'gnus-score-default
821   :type '(choice (const :tag "off" nil)
822                  integer))
823
824 (defcustom gnus-thread-expunge-below nil
825   "All threads that have a total score less than this variable will be expunged.
826 See `gnus-thread-score-function' for en explanation of what a
827 \"thread score\" is.
828
829 This variable is local to the summary buffers."
830   :group 'gnus-threading
831   :group 'gnus-score-default
832   :type '(choice (const :tag "off" nil)
833                  integer))
834
835 (defcustom gnus-summary-mode-hook nil
836   "*A hook for Gnus summary mode.
837 This hook is run before any variables are set in the summary buffer."
838   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
839   :group 'gnus-summary-various
840   :type 'hook)
841
842 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
843 (when (featurep 'xemacs)
844   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
845   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
846   (add-hook 'gnus-summary-mode-hook
847             'gnus-xmas-switch-horizontal-scrollbar-off))
848
849 (defcustom gnus-summary-menu-hook nil
850   "*Hook run after the creation of the summary mode menu."
851   :group 'gnus-summary-visual
852   :type 'hook)
853
854 (defcustom gnus-summary-exit-hook nil
855   "*A hook called on exit from the summary buffer.
856 It will be called with point in the group buffer."
857   :group 'gnus-summary-exit
858   :type 'hook)
859
860 (defcustom gnus-summary-prepare-hook nil
861   "*A hook called after the summary buffer has been generated.
862 If you want to modify the summary buffer, you can use this hook."
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 (defcustom gnus-summary-prepared-hook nil
867   "*A hook called as the last thing after the summary buffer has been generated."
868   :group 'gnus-summary-various
869   :type 'hook)
870
871 (defcustom gnus-summary-generate-hook nil
872   "*A hook run just before generating the summary buffer.
873 This hook is commonly used to customize threading variables and the
874 like."
875   :group 'gnus-summary-various
876   :type 'hook)
877
878 (defcustom gnus-select-group-hook nil
879   "*A hook called when a newsgroup is selected.
880
881 If you'd like to simplify subjects like the
882 `gnus-summary-next-same-subject' command does, you can use the
883 following hook:
884
885  (add-hook gnus-select-group-hook
886            (lambda ()
887              (mapcar (lambda (header)
888                        (mail-header-set-subject
889                         header
890                         (gnus-simplify-subject
891                          (mail-header-subject header) 're-only)))
892                      gnus-newsgroup-headers)))"
893   :group 'gnus-group-select
894   :type 'hook)
895
896 (defcustom gnus-select-article-hook nil
897   "*A hook called when an article is selected."
898   :group 'gnus-summary-choose
899   :options '(gnus-agent-fetch-selected-article)
900   :type 'hook)
901
902 (defcustom gnus-visual-mark-article-hook
903   (list 'gnus-highlight-selected-summary)
904   "*Hook run after selecting an article in the summary buffer.
905 It is meant to be used for highlighting the article in some way.  It
906 is not run if `gnus-visual' is nil."
907   :group 'gnus-summary-visual
908   :type 'hook)
909
910 (defcustom gnus-parse-headers-hook nil
911   "*A hook called before parsing the headers."
912   :group 'gnus-various
913   :type 'hook)
914
915 (defcustom gnus-exit-group-hook nil
916   "*A hook called when exiting summary mode.
917 This hook is not called from the non-updating exit commands like `Q'."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-summary-update-hook
922   (list 'gnus-summary-highlight-line)
923   "*A hook called when a summary line is changed.
924 The hook will not be called if `gnus-visual' is nil.
925
926 The default function `gnus-summary-highlight-line' will
927 highlight the line according to the `gnus-summary-highlight'
928 variable."
929   :group 'gnus-summary-visual
930   :type 'hook)
931
932 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
933   "*A hook called when an article is selected for the first time.
934 The hook is intended to mark an article as read (or unread)
935 automatically when it is selected."
936   :group 'gnus-summary-choose
937   :type 'hook)
938
939 (defcustom gnus-group-no-more-groups-hook nil
940   "*A hook run when returning to group mode having no more (unread) groups."
941   :group 'gnus-group-select
942   :type 'hook)
943
944 (defcustom gnus-ps-print-hook nil
945   "*A hook run before ps-printing something from Gnus."
946   :group 'gnus-summary
947   :type 'hook)
948
949 (defcustom gnus-summary-article-move-hook nil
950   "*A hook called after an article is moved, copied, respooled, or crossposted."
951   :version "22.1"
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-delete-hook nil
956   "*A hook called after an article is deleted."
957   :version "22.1"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-expire-hook nil
962   "*A hook called after an article is expired."
963   :version "22.1"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-display-arrow
968   (and (fboundp 'display-graphic-p)
969        (display-graphic-p))
970   "*If non-nil, display an arrow highlighting the current article."
971   :version "22.1"
972   :group 'gnus-summary
973   :type 'boolean)
974
975 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
976   "Face used for highlighting the current article in the summary buffer."
977   :group 'gnus-summary-visual
978   :type 'face)
979
980 (defvar gnus-tmp-downloaded nil)
981
982 (defcustom gnus-summary-highlight
983   '(((eq mark gnus-canceled-mark)
984      . gnus-summary-cancelled-face)
985     ((and uncached (> score default-high))
986      . gnus-summary-high-undownloaded-face)
987     ((and uncached (< score default-low))
988      . gnus-summary-low-undownloaded-face)
989     (uncached
990      . gnus-summary-normal-undownloaded-face)
991     ((and (> score default-high)
992           (or (eq mark gnus-dormant-mark)
993               (eq mark gnus-ticked-mark)))
994      . gnus-summary-high-ticked-face)
995     ((and (< score default-low)
996           (or (eq mark gnus-dormant-mark)
997               (eq mark gnus-ticked-mark)))
998      . gnus-summary-low-ticked-face)
999     ((or (eq mark gnus-dormant-mark)
1000          (eq mark gnus-ticked-mark))
1001      . gnus-summary-normal-ticked-face)
1002     ((and (> score default-high) (eq mark gnus-ancient-mark))
1003      . gnus-summary-high-ancient-face)
1004     ((and (< score default-low) (eq mark gnus-ancient-mark))
1005      . gnus-summary-low-ancient-face)
1006     ((eq mark gnus-ancient-mark)
1007      . gnus-summary-normal-ancient-face)
1008     ((and (> score default-high) (eq mark gnus-unread-mark))
1009      . gnus-summary-high-unread-face)
1010     ((and (< score default-low) (eq mark gnus-unread-mark))
1011      . gnus-summary-low-unread-face)
1012     ((eq mark gnus-unread-mark)
1013      . gnus-summary-normal-unread-face)
1014     ((> score default-high)
1015      . gnus-summary-high-read-face)
1016     ((< score default-low)
1017      . gnus-summary-low-read-face)
1018     (t
1019      . gnus-summary-normal-read-face))
1020   "*Controls the highlighting of summary buffer lines.
1021
1022 A list of (FORM . FACE) pairs.  When deciding how a a particular
1023 summary line should be displayed, each form is evaluated.  The content
1024 of the face field after the first true form is used.  You can change
1025 how those summary lines are displayed, by editing the face field.
1026
1027 You can use the following variables in the FORM field.
1028
1029 score:        The article's score
1030 default:      The default article score.
1031 default-high: The default score for high scored articles.
1032 default-low:  The default score for low scored articles.
1033 below:        The score below which articles are automatically marked as read.
1034 mark:         The article's mark.
1035 uncached:     Non-nil if the article is uncached."
1036   :group 'gnus-summary-visual
1037   :type '(repeat (cons (sexp :tag "Form" nil)
1038                        face)))
1039
1040 (defcustom gnus-alter-header-function nil
1041   "Function called to allow alteration of article header structures.
1042 The function is called with one parameter, the article header vector,
1043 which it may alter in any way."
1044   :type '(choice (const :tag "None" nil)
1045                  function)
1046   :group 'gnus-summary)
1047
1048 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1049   "Variable that says which function should be used to decode a string with encoded words.")
1050
1051 (defcustom gnus-extra-headers '(To Newsgroups)
1052   "*Extra headers to parse."
1053   :version "21.1"
1054   :group 'gnus-summary
1055   :type '(repeat symbol))
1056
1057 (defcustom gnus-ignored-from-addresses
1058   (and user-mail-address (regexp-quote user-mail-address))
1059   "*Regexp of From headers that may be suppressed in favor of To headers."
1060   :version "21.1"
1061   :group 'gnus-summary
1062   :type 'regexp)
1063
1064 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1065   "List of charsets that should be ignored.
1066 When these charsets are used in the \"charset\" parameter, the
1067 default charset will be used instead."
1068   :version "21.1"
1069   :type '(repeat symbol)
1070   :group 'gnus-charset)
1071
1072 (gnus-define-group-parameter
1073  ignored-charsets
1074  :type list
1075  :function-document
1076  "Return the ignored charsets of GROUP."
1077  :variable gnus-group-ignored-charsets-alist
1078  :variable-default
1079  '(("alt\\.chinese\\.text" iso-8859-1))
1080  :variable-document
1081  "Alist of regexps (to match group names) and charsets that should be ignored.
1082 When these charsets are used in the \"charset\" parameter, the
1083 default charset will be used instead."
1084  :variable-group gnus-charset
1085  :variable-type '(repeat (cons (regexp :tag "Group")
1086                                (repeat symbol)))
1087  :parameter-type '(choice :tag "Ignored charsets"
1088                           :value nil
1089                           (repeat (symbol)))
1090  :parameter-document       "\
1091 List of charsets that should be ignored.
1092
1093 When these charsets are used in the \"charset\" parameter, the
1094 default charset will be used instead.")
1095
1096 (defcustom gnus-group-highlight-words-alist nil
1097   "Alist of group regexps and highlight regexps.
1098 This variable uses the same syntax as `gnus-emphasis-alist'."
1099   :version "21.1"
1100   :type '(repeat (cons (regexp :tag "Group")
1101                        (repeat (list (regexp :tag "Highlight regexp")
1102                                      (number :tag "Group for entire word" 0)
1103                                      (number :tag "Group for displayed part" 0)
1104                                      (symbol :tag "Face"
1105                                              gnus-emphasis-highlight-words)))))
1106   :group 'gnus-summary-visual)
1107
1108 (defcustom gnus-summary-show-article-charset-alist
1109   nil
1110   "Alist of number and charset.
1111 The article will be shown with the charset corresponding to the
1112 numbered argument.
1113 For example: ((1 . cn-gb-2312) (2 . big5))."
1114   :version "21.1"
1115   :type '(repeat (cons (number :tag "Argument" 1)
1116                        (symbol :tag "Charset")))
1117   :group 'gnus-charset)
1118
1119 (defcustom gnus-preserve-marks t
1120   "Whether marks are preserved when moving, copying and respooling messages."
1121   :version "21.1"
1122   :type 'boolean
1123   :group 'gnus-summary-marks)
1124
1125 (defcustom gnus-alter-articles-to-read-function nil
1126   "Function to be called to alter the list of articles to be selected."
1127   :type '(choice (const nil) function)
1128   :group 'gnus-summary)
1129
1130 (defcustom gnus-orphan-score nil
1131   "*All orphans get this score added.  Set in the score file."
1132   :group 'gnus-score-default
1133   :type '(choice (const nil)
1134                  integer))
1135
1136 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1137   "*A regexp to match MIME parts when saving multiple parts of a
1138 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1139 This regexp will be used by default when prompting the user for which
1140 type of files to save."
1141   :group 'gnus-summary
1142   :type 'regexp)
1143
1144 (defcustom gnus-read-all-available-headers nil
1145   "Whether Gnus should parse all headers made available to it.
1146 This is mostly relevant for slow back ends where the user may
1147 wish to widen the summary buffer to include all headers
1148 that were fetched.  Say, for nnultimate groups."
1149   :version "22.1"
1150   :group 'gnus-summary
1151   :type '(choice boolean regexp))
1152
1153 (defcustom gnus-summary-muttprint-program "muttprint"
1154   "Command (and optional arguments) used to run Muttprint."
1155   :version "22.1"
1156   :group 'gnus-summary
1157   :type 'string)
1158
1159 (defcustom gnus-article-loose-mime t
1160   "If non-nil, don't require MIME-Version header.
1161 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1162 supply the MIME-Version header or deliberately strip it from the mail.
1163 If non-nil (the default), Gnus will treat some articles as MIME
1164 even if the MIME-Version header is missing."
1165   :version "22.1"
1166   :type 'boolean
1167   :group 'gnus-article-mime)
1168
1169 (defcustom gnus-article-emulate-mime t
1170   "If non-nil, use MIME emulation for uuencode and the like.
1171 This means that Gnus will search message bodies for text that look
1172 like uuencoded bits, yEncoded bits, and so on, and present that using
1173 the normal Gnus MIME machinery."
1174   :version "22.1"
1175   :type 'boolean
1176   :group 'gnus-article-mime)
1177
1178 ;;; Internal variables
1179
1180 (defvar gnus-summary-display-cache nil)
1181 (defvar gnus-article-mime-handles nil)
1182 (defvar gnus-article-decoded-p nil)
1183 (defvar gnus-article-charset nil)
1184 (defvar gnus-article-ignored-charsets nil)
1185 (defvar gnus-scores-exclude-files nil)
1186 (defvar gnus-page-broken nil)
1187
1188 (defvar gnus-original-article nil)
1189 (defvar gnus-article-internal-prepare-hook nil)
1190 (defvar gnus-newsgroup-process-stack nil)
1191
1192 (defvar gnus-thread-indent-array nil)
1193 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1194 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1195   "Function called to sort the articles within a thread after it has been gathered together.")
1196
1197 (defvar gnus-summary-save-parts-type-history nil)
1198 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1199
1200 ;; Avoid highlighting in kill files.
1201 (defvar gnus-summary-inhibit-highlight nil)
1202 (defvar gnus-newsgroup-selected-overlay nil)
1203 (defvar gnus-inhibit-limiting nil)
1204 (defvar gnus-newsgroup-adaptive-score-file nil)
1205 (defvar gnus-current-score-file nil)
1206 (defvar gnus-current-move-group nil)
1207 (defvar gnus-current-copy-group nil)
1208 (defvar gnus-current-crosspost-group nil)
1209 (defvar gnus-newsgroup-display nil)
1210
1211 (defvar gnus-newsgroup-dependencies nil)
1212 (defvar gnus-newsgroup-adaptive nil)
1213 (defvar gnus-summary-display-article-function nil)
1214 (defvar gnus-summary-highlight-line-function nil
1215   "Function called after highlighting a summary line.")
1216
1217 (defvar gnus-summary-line-format-alist
1218   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1219     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1220     (?s gnus-tmp-subject-or-nil ?s)
1221     (?n gnus-tmp-name ?s)
1222     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1223         ?s)
1224     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1225             gnus-tmp-from) ?s)
1226     (?F gnus-tmp-from ?s)
1227     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1228     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1229     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1230     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1231     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1232     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1233     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1234     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1235     (?L gnus-tmp-lines ?s)
1236     (?O gnus-tmp-downloaded ?c)
1237     (?I gnus-tmp-indentation ?s)
1238     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1239     (?R gnus-tmp-replied ?c)
1240     (?\[ gnus-tmp-opening-bracket ?c)
1241     (?\] gnus-tmp-closing-bracket ?c)
1242     (?\> (make-string gnus-tmp-level ? ) ?s)
1243     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1244     (?i gnus-tmp-score ?d)
1245     (?z gnus-tmp-score-char ?c)
1246     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1247     (?U gnus-tmp-unread ?c)
1248     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1249         ?s)
1250     (?t (gnus-summary-number-of-articles-in-thread
1251          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1252         ?d)
1253     (?e (gnus-summary-number-of-articles-in-thread
1254          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1255         ?c)
1256     (?u gnus-tmp-user-defined ?s)
1257     (?P (gnus-pick-line-number) ?d)
1258     (?B gnus-tmp-thread-tree-header-string ?s)
1259     (user-date (gnus-user-date
1260                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1261   "An alist of format specifications that can appear in summary lines.
1262 These are paired with what variables they correspond with, along with
1263 the type of the variable (string, integer, character, etc).")
1264
1265 (defvar gnus-summary-dummy-line-format-alist
1266   `((?S gnus-tmp-subject ?s)
1267     (?N gnus-tmp-number ?d)
1268     (?u gnus-tmp-user-defined ?s)))
1269
1270 (defvar gnus-summary-mode-line-format-alist
1271   `((?G gnus-tmp-group-name ?s)
1272     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1273     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1274     (?A gnus-tmp-article-number ?d)
1275     (?Z gnus-tmp-unread-and-unselected ?s)
1276     (?V gnus-version ?s)
1277     (?U gnus-tmp-unread-and-unticked ?d)
1278     (?S gnus-tmp-subject ?s)
1279     (?e gnus-tmp-unselected ?d)
1280     (?u gnus-tmp-user-defined ?s)
1281     (?d (length gnus-newsgroup-dormant) ?d)
1282     (?t (length gnus-newsgroup-marked) ?d)
1283     (?h (length gnus-newsgroup-spam-marked) ?d)
1284     (?r (length gnus-newsgroup-reads) ?d)
1285     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1286     (?E gnus-newsgroup-expunged-tally ?d)
1287     (?s (gnus-current-score-file-nondirectory) ?s)))
1288
1289 (defvar gnus-last-search-regexp nil
1290   "Default regexp for article search command.")
1291
1292 (defvar gnus-last-shell-command nil
1293   "Default shell command on article.")
1294
1295 (defvar gnus-newsgroup-agentized nil
1296   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1297 (defvar gnus-newsgroup-begin nil)
1298 (defvar gnus-newsgroup-end nil)
1299 (defvar gnus-newsgroup-last-rmail nil)
1300 (defvar gnus-newsgroup-last-mail nil)
1301 (defvar gnus-newsgroup-last-folder nil)
1302 (defvar gnus-newsgroup-last-file nil)
1303 (defvar gnus-newsgroup-auto-expire nil)
1304 (defvar gnus-newsgroup-active nil)
1305
1306 (defvar gnus-newsgroup-data nil)
1307 (defvar gnus-newsgroup-data-reverse nil)
1308 (defvar gnus-newsgroup-limit nil)
1309 (defvar gnus-newsgroup-limits nil)
1310 (defvar gnus-summary-use-undownloaded-faces nil)
1311
1312 (defvar gnus-newsgroup-unreads nil
1313   "Sorted list of unread articles in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-unselected nil
1316   "Sorted list of unselected unread articles in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-reads nil
1319   "Alist of read articles and article marks in the current newsgroup.")
1320
1321 (defvar gnus-newsgroup-expunged-tally nil)
1322
1323 (defvar gnus-newsgroup-marked nil
1324   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1325
1326 (defvar gnus-newsgroup-spam-marked nil
1327   "List of ranges of articles that have been marked as spam.")
1328
1329 (defvar gnus-newsgroup-killed nil
1330   "List of ranges of articles that have been through the scoring process.")
1331
1332 (defvar gnus-newsgroup-cached nil
1333   "Sorted list of articles that come from the article cache.")
1334
1335 (defvar gnus-newsgroup-saved nil
1336   "List of articles that have been saved.")
1337
1338 (defvar gnus-newsgroup-kill-headers nil)
1339
1340 (defvar gnus-newsgroup-replied nil
1341   "List of articles that have been replied to in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-forwarded nil
1344   "List of articles that have been forwarded in the current newsgroup.")
1345
1346 (defvar gnus-newsgroup-recent nil
1347   "List of articles that have are recent in the current newsgroup.")
1348
1349 (defvar gnus-newsgroup-expirable nil
1350   "Sorted list of articles in the current newsgroup that can be expired.")
1351
1352 (defvar gnus-newsgroup-processable nil
1353   "List of articles in the current newsgroup that can be processed.")
1354
1355 (defvar gnus-newsgroup-downloadable nil
1356   "Sorted list of articles in the current newsgroup that can be processed.")
1357
1358 (defvar gnus-newsgroup-unfetched nil
1359   "Sorted list of articles in the current newsgroup whose headers have
1360 not been fetched into the agent.
1361
1362 This list will always be a subset of gnus-newsgroup-undownloaded.")
1363
1364 (defvar gnus-newsgroup-undownloaded nil
1365   "List of articles in the current newsgroup that haven't been downloaded.")
1366
1367 (defvar gnus-newsgroup-unsendable nil
1368   "List of articles in the current newsgroup that won't be sent.")
1369
1370 (defvar gnus-newsgroup-bookmarks nil
1371   "List of articles in the current newsgroup that have bookmarks.")
1372
1373 (defvar gnus-newsgroup-dormant nil
1374   "Sorted list of dormant articles in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-unseen nil
1377   "List of unseen articles in the current newsgroup.")
1378
1379 (defvar gnus-newsgroup-seen nil
1380   "Range of seen articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-articles nil
1383   "List of articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-scored nil
1386   "List of scored articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-headers nil
1389   "List of article headers in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-threads nil)
1392
1393 (defvar gnus-newsgroup-prepared nil
1394   "Whether the current group has been prepared properly.")
1395
1396 (defvar gnus-newsgroup-ancient nil
1397   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-sparse nil)
1400
1401 (defvar gnus-current-article nil)
1402 (defvar gnus-article-current nil)
1403 (defvar gnus-current-headers nil)
1404 (defvar gnus-have-all-headers nil)
1405 (defvar gnus-last-article nil)
1406 (defvar gnus-newsgroup-history nil)
1407 (defvar gnus-newsgroup-charset nil)
1408 (defvar gnus-newsgroup-ephemeral-charset nil)
1409 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1410
1411 (defvar gnus-article-before-search nil)
1412
1413 (defvar gnus-summary-local-variables
1414   '(gnus-newsgroup-name
1415     gnus-newsgroup-begin gnus-newsgroup-end
1416     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1417     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1418     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1419     gnus-newsgroup-unselected gnus-newsgroup-marked
1420     gnus-newsgroup-spam-marked
1421     gnus-newsgroup-reads gnus-newsgroup-saved
1422     gnus-newsgroup-replied gnus-newsgroup-forwarded
1423     gnus-newsgroup-recent
1424     gnus-newsgroup-expirable
1425     gnus-newsgroup-processable gnus-newsgroup-killed
1426     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1427     gnus-newsgroup-unfetched
1428     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1429     gnus-newsgroup-seen gnus-newsgroup-articles
1430     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1431     gnus-newsgroup-headers gnus-newsgroup-threads
1432     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1433     gnus-current-article gnus-current-headers gnus-have-all-headers
1434     gnus-last-article gnus-article-internal-prepare-hook
1435     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1436     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1437     gnus-thread-expunge-below
1438     gnus-score-alist gnus-current-score-file
1439     (gnus-summary-expunge-below . global)
1440     (gnus-summary-mark-below . global)
1441     (gnus-orphan-score . global)
1442     gnus-newsgroup-active gnus-scores-exclude-files
1443     gnus-newsgroup-history gnus-newsgroup-ancient
1444     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1445     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1446     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1447     (gnus-newsgroup-expunged-tally . 0)
1448     gnus-cache-removable-articles gnus-newsgroup-cached
1449     gnus-newsgroup-data gnus-newsgroup-data-reverse
1450     gnus-newsgroup-limit gnus-newsgroup-limits
1451     gnus-newsgroup-charset gnus-newsgroup-display
1452     gnus-summary-use-undownloaded-faces)
1453   "Variables that are buffer-local to the summary buffers.")
1454
1455 (defvar gnus-newsgroup-variables nil
1456   "A list of variables that have separate values in different newsgroups.
1457 A list of newsgroup (summary buffer) local variables, or cons of
1458 variables and their default expressions to be evalled (when the default
1459 values are not nil), that should be made global while the summary buffer
1460 is active.
1461
1462 Note: The default expressions will be evaluated (using function `eval')
1463 before assignment to the local variable rather than just assigned to it.
1464 If the default expression is the symbol `global', that symbol will not
1465 be evaluated but the global value of the local variable will be used
1466 instead.
1467
1468 These variables can be used to set variables in the group parameters
1469 while still allowing them to affect operations done in other buffers.
1470 For example:
1471
1472 \(setq gnus-newsgroup-variables
1473      '(message-use-followup-to
1474        (gnus-visible-headers .
1475          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1476 ")
1477
1478 ;; Byte-compiler warning.
1479 (eval-when-compile
1480   ;; Bind features so that require will believe that gnus-sum has
1481   ;; already been loaded (avoids infinite recursion)
1482   (let ((features (cons 'gnus-sum features)))
1483     ;; Several of the declarations in gnus-sum are needed to load the
1484     ;; following files. Right now, these definitions have been
1485     ;; compiled but not defined (evaluated).  We could either do a
1486     ;; eval-and-compile about all of the declarations or evaluate the
1487     ;; source file.
1488     (if (boundp 'gnus-newsgroup-variables)
1489         nil
1490       (load "gnus-sum.el" t t t))
1491     (require 'gnus)
1492     (require 'gnus-art)))
1493
1494 ;; MIME stuff.
1495
1496 (defvar gnus-decode-encoded-word-methods
1497   '(mail-decode-encoded-word-string)
1498   "List of methods used to decode encoded words.
1499
1500 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1501 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1502 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1503 whose names match REGEXP.
1504
1505 For example:
1506 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1507  mail-decode-encoded-word-string
1508  (\"chinese\" . rfc1843-decode-string))")
1509
1510 (defvar gnus-decode-encoded-word-methods-cache nil)
1511
1512 (defun gnus-multi-decode-encoded-word-string (string)
1513   "Apply the functions from `gnus-encoded-word-methods' that match."
1514   (unless (and gnus-decode-encoded-word-methods-cache
1515                (eq gnus-newsgroup-name
1516                    (car gnus-decode-encoded-word-methods-cache)))
1517     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1518     (mapcar (lambda (x)
1519               (if (symbolp x)
1520                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1521                 (if (and gnus-newsgroup-name
1522                          (string-match (car x) gnus-newsgroup-name))
1523                     (nconc gnus-decode-encoded-word-methods-cache
1524                            (list (cdr x))))))
1525             gnus-decode-encoded-word-methods))
1526   (let ((xlist gnus-decode-encoded-word-methods-cache))
1527     (pop xlist)
1528     (while xlist
1529       (setq string (funcall (pop xlist) string))))
1530   string)
1531
1532 ;; Subject simplification.
1533
1534 (defun gnus-simplify-whitespace (str)
1535   "Remove excessive whitespace from STR."
1536   ;; Multiple spaces.
1537   (while (string-match "[ \t][ \t]+" str)
1538     (setq str (concat (substring str 0 (match-beginning 0))
1539                         " "
1540                         (substring str (match-end 0)))))
1541   ;; Leading spaces.
1542   (when (string-match "^[ \t]+" str)
1543     (setq str (substring str (match-end 0))))
1544   ;; Trailing spaces.
1545   (when (string-match "[ \t]+$" str)
1546     (setq str (substring str 0 (match-beginning 0))))
1547   str)
1548
1549 (defun gnus-simplify-all-whitespace (str)
1550   "Remove all whitespace from STR."
1551   (while (string-match "[ \t\n]+" str)
1552     (setq str (replace-match "" nil nil str)))
1553   str)
1554
1555 (defsubst gnus-simplify-subject-re (subject)
1556   "Remove \"Re:\" from subject lines."
1557   (if (string-match message-subject-re-regexp subject)
1558       (substring subject (match-end 0))
1559     subject))
1560
1561 (defun gnus-simplify-subject (subject &optional re-only)
1562   "Remove `Re:' and words in parentheses.
1563 If RE-ONLY is non-nil, strip leading `Re:'s only."
1564   (let ((case-fold-search t))           ;Ignore case.
1565     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1566     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1567       (setq subject (substring subject (match-end 0))))
1568     ;; Remove uninteresting prefixes.
1569     (when (and (not re-only)
1570                gnus-simplify-ignored-prefixes
1571                (string-match gnus-simplify-ignored-prefixes subject))
1572       (setq subject (substring subject (match-end 0))))
1573     ;; Remove words in parentheses from end.
1574     (unless re-only
1575       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1576         (setq subject (substring subject 0 (match-beginning 0)))))
1577     ;; Return subject string.
1578     subject))
1579
1580 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1581 ;; all whitespace.
1582 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1583   (goto-char (point-min))
1584   (while (re-search-forward regexp nil t)
1585     (replace-match (or newtext ""))))
1586
1587 (defun gnus-simplify-buffer-fuzzy ()
1588   "Simplify string in the buffer fuzzily.
1589 The string in the accessible portion of the current buffer is simplified.
1590 It is assumed to be a single-line subject.
1591 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1592 matter is removed.  Additional things can be deleted by setting
1593 `gnus-simplify-subject-fuzzy-regexp'."
1594   (let ((case-fold-search t)
1595         (modified-tick))
1596     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1597
1598     (while (not (eq modified-tick (buffer-modified-tick)))
1599       (setq modified-tick (buffer-modified-tick))
1600       (cond
1601        ((listp gnus-simplify-subject-fuzzy-regexp)
1602         (mapcar 'gnus-simplify-buffer-fuzzy-step
1603                 gnus-simplify-subject-fuzzy-regexp))
1604        (gnus-simplify-subject-fuzzy-regexp
1605         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1606       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1607       (gnus-simplify-buffer-fuzzy-step
1608        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1609       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1610
1611     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1612     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1613     (gnus-simplify-buffer-fuzzy-step " $")
1614     (gnus-simplify-buffer-fuzzy-step "^ +")))
1615
1616 (defun gnus-simplify-subject-fuzzy (subject)
1617   "Simplify a subject string fuzzily.
1618 See `gnus-simplify-buffer-fuzzy' for details."
1619   (save-excursion
1620     (gnus-set-work-buffer)
1621     (let ((case-fold-search t))
1622       ;; Remove uninteresting prefixes.
1623       (when (and gnus-simplify-ignored-prefixes
1624                  (string-match gnus-simplify-ignored-prefixes subject))
1625         (setq subject (substring subject (match-end 0))))
1626       (insert subject)
1627       (inline (gnus-simplify-buffer-fuzzy))
1628       (buffer-string))))
1629
1630 (defsubst gnus-simplify-subject-fully (subject)
1631   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1632   (cond
1633    (gnus-simplify-subject-functions
1634     (gnus-map-function gnus-simplify-subject-functions subject))
1635    ((null gnus-summary-gather-subject-limit)
1636     (gnus-simplify-subject-re subject))
1637    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1638     (gnus-simplify-subject-fuzzy subject))
1639    ((numberp gnus-summary-gather-subject-limit)
1640     (gnus-limit-string (gnus-simplify-subject-re subject)
1641                        gnus-summary-gather-subject-limit))
1642    (t
1643     subject)))
1644
1645 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1646   "Check whether two subjects are equal.
1647 If optional argument SIMPLE-FIRST is t, first argument is already
1648 simplified."
1649   (cond
1650    ((null simple-first)
1651     (equal (gnus-simplify-subject-fully s1)
1652            (gnus-simplify-subject-fully s2)))
1653    (t
1654     (equal s1
1655            (gnus-simplify-subject-fully s2)))))
1656
1657 (defun gnus-summary-bubble-group ()
1658   "Increase the score of the current group.
1659 This is a handy function to add to `gnus-summary-exit-hook' to
1660 increase the score of each group you read."
1661   (gnus-group-add-score gnus-newsgroup-name))
1662
1663 \f
1664 ;;;
1665 ;;; Gnus summary mode
1666 ;;;
1667
1668 (put 'gnus-summary-mode 'mode-class 'special)
1669
1670 (defvar gnus-article-commands-menu)
1671
1672 ;; Non-orthogonal keys
1673
1674 (gnus-define-keys gnus-summary-mode-map
1675   " " gnus-summary-next-page
1676   "\177" gnus-summary-prev-page
1677   [delete] gnus-summary-prev-page
1678   [backspace] gnus-summary-prev-page
1679   "\r" gnus-summary-scroll-up
1680   "\M-\r" gnus-summary-scroll-down
1681   "n" gnus-summary-next-unread-article
1682   "p" gnus-summary-prev-unread-article
1683   "N" gnus-summary-next-article
1684   "P" gnus-summary-prev-article
1685   "\M-\C-n" gnus-summary-next-same-subject
1686   "\M-\C-p" gnus-summary-prev-same-subject
1687   "\M-n" gnus-summary-next-unread-subject
1688   "\M-p" gnus-summary-prev-unread-subject
1689   "." gnus-summary-first-unread-article
1690   "," gnus-summary-best-unread-article
1691   "\M-s" gnus-summary-search-article-forward
1692   "\M-r" gnus-summary-search-article-backward
1693   "<" gnus-summary-beginning-of-article
1694   ">" gnus-summary-end-of-article
1695   "j" gnus-summary-goto-article
1696   "^" gnus-summary-refer-parent-article
1697   "\M-^" gnus-summary-refer-article
1698   "u" gnus-summary-tick-article-forward
1699   "!" gnus-summary-tick-article-forward
1700   "U" gnus-summary-tick-article-backward
1701   "d" gnus-summary-mark-as-read-forward
1702   "D" gnus-summary-mark-as-read-backward
1703   "E" gnus-summary-mark-as-expirable
1704   "\M-u" gnus-summary-clear-mark-forward
1705   "\M-U" gnus-summary-clear-mark-backward
1706   "k" gnus-summary-kill-same-subject-and-select
1707   "\C-k" gnus-summary-kill-same-subject
1708   "\M-\C-k" gnus-summary-kill-thread
1709   "\M-\C-l" gnus-summary-lower-thread
1710   "e" gnus-summary-edit-article
1711   "#" gnus-summary-mark-as-processable
1712   "\M-#" gnus-summary-unmark-as-processable
1713   "\M-\C-t" gnus-summary-toggle-threads
1714   "\M-\C-s" gnus-summary-show-thread
1715   "\M-\C-h" gnus-summary-hide-thread
1716   "\M-\C-f" gnus-summary-next-thread
1717   "\M-\C-b" gnus-summary-prev-thread
1718   [(meta down)] gnus-summary-next-thread
1719   [(meta up)] gnus-summary-prev-thread
1720   "\M-\C-u" gnus-summary-up-thread
1721   "\M-\C-d" gnus-summary-down-thread
1722   "&" gnus-summary-execute-command
1723   "c" gnus-summary-catchup-and-exit
1724   "\C-w" gnus-summary-mark-region-as-read
1725   "\C-t" gnus-summary-toggle-truncation
1726   "?" gnus-summary-mark-as-dormant
1727   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1728   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1729   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1730   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1731   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1732   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1733   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1734   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1735   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1736   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1737   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1738   "=" gnus-summary-expand-window
1739   "\C-x\C-s" gnus-summary-reselect-current-group
1740   "\M-g" gnus-summary-rescan-group
1741   "w" gnus-summary-stop-page-breaking
1742   "\C-c\C-r" gnus-summary-caesar-message
1743   "f" gnus-summary-followup
1744   "F" gnus-summary-followup-with-original
1745   "C" gnus-summary-cancel-article
1746   "r" gnus-summary-reply
1747   "R" gnus-summary-reply-with-original
1748   "\C-c\C-f" gnus-summary-mail-forward
1749   "o" gnus-summary-save-article
1750   "\C-o" gnus-summary-save-article-mail
1751   "|" gnus-summary-pipe-output
1752   "\M-k" gnus-summary-edit-local-kill
1753   "\M-K" gnus-summary-edit-global-kill
1754   ;; "V" gnus-version
1755   "\C-c\C-d" gnus-summary-describe-group
1756   "q" gnus-summary-exit
1757   "Q" gnus-summary-exit-no-update
1758   "\C-c\C-i" gnus-info-find-node
1759   gnus-mouse-2 gnus-mouse-pick-article
1760   [follow-link] mouse-face
1761   "m" gnus-summary-mail-other-window
1762   "a" gnus-summary-post-news
1763   "i" gnus-summary-news-other-window
1764   "x" gnus-summary-limit-to-unread
1765   "s" gnus-summary-isearch-article
1766   "t" gnus-summary-toggle-header
1767   "g" gnus-summary-show-article
1768   "l" gnus-summary-goto-last-article
1769   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1770   "\C-d" gnus-summary-enter-digest-group
1771   "\M-\C-d" gnus-summary-read-document
1772   "\M-\C-e" gnus-summary-edit-parameters
1773   "\M-\C-a" gnus-summary-customize-parameters
1774   "\C-c\C-b" gnus-bug
1775   "*" gnus-cache-enter-article
1776   "\M-*" gnus-cache-remove-article
1777   "\M-&" gnus-summary-universal-argument
1778   "\C-l" gnus-recenter
1779   "I" gnus-summary-increase-score
1780   "L" gnus-summary-lower-score
1781   "\M-i" gnus-symbolic-argument
1782   "h" gnus-summary-select-article-buffer
1783
1784   "b" gnus-article-view-part
1785   "\M-t" gnus-summary-toggle-display-buttonized
1786
1787   "V" gnus-summary-score-map
1788   "X" gnus-uu-extract-map
1789   "S" gnus-summary-send-map)
1790
1791 ;; Sort of orthogonal keymap
1792 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1793   "t" gnus-summary-tick-article-forward
1794   "!" gnus-summary-tick-article-forward
1795   "d" gnus-summary-mark-as-read-forward
1796   "r" gnus-summary-mark-as-read-forward
1797   "c" gnus-summary-clear-mark-forward
1798   " " gnus-summary-clear-mark-forward
1799   "e" gnus-summary-mark-as-expirable
1800   "x" gnus-summary-mark-as-expirable
1801   "?" gnus-summary-mark-as-dormant
1802   "b" gnus-summary-set-bookmark
1803   "B" gnus-summary-remove-bookmark
1804   "#" gnus-summary-mark-as-processable
1805   "\M-#" gnus-summary-unmark-as-processable
1806   "S" gnus-summary-limit-include-expunged
1807   "C" gnus-summary-catchup
1808   "H" gnus-summary-catchup-to-here
1809   "h" gnus-summary-catchup-from-here
1810   "\C-c" gnus-summary-catchup-all
1811   "k" gnus-summary-kill-same-subject-and-select
1812   "K" gnus-summary-kill-same-subject
1813   "P" gnus-uu-mark-map)
1814
1815 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1816   "c" gnus-summary-clear-above
1817   "u" gnus-summary-tick-above
1818   "m" gnus-summary-mark-above
1819   "k" gnus-summary-kill-below)
1820
1821 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1822   "/" gnus-summary-limit-to-subject
1823   "n" gnus-summary-limit-to-articles
1824   "w" gnus-summary-pop-limit
1825   "s" gnus-summary-limit-to-subject
1826   "a" gnus-summary-limit-to-author
1827   "u" gnus-summary-limit-to-unread
1828   "m" gnus-summary-limit-to-marks
1829   "M" gnus-summary-limit-exclude-marks
1830   "v" gnus-summary-limit-to-score
1831   "*" gnus-summary-limit-include-cached
1832   "D" gnus-summary-limit-include-dormant
1833   "T" gnus-summary-limit-include-thread
1834   "d" gnus-summary-limit-exclude-dormant
1835   "t" gnus-summary-limit-to-age
1836   "." gnus-summary-limit-to-unseen
1837   "x" gnus-summary-limit-to-extra
1838   "p" gnus-summary-limit-to-display-predicate
1839   "E" gnus-summary-limit-include-expunged
1840   "c" gnus-summary-limit-exclude-childless-dormant
1841   "C" gnus-summary-limit-mark-excluded-as-read
1842   "o" gnus-summary-insert-old-articles
1843   "N" gnus-summary-insert-new-articles
1844   "r" gnus-summary-limit-to-replied
1845   "R" gnus-summary-limit-to-recipient)
1846
1847 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1848   "n" gnus-summary-next-unread-article
1849   "p" gnus-summary-prev-unread-article
1850   "N" gnus-summary-next-article
1851   "P" gnus-summary-prev-article
1852   "\C-n" gnus-summary-next-same-subject
1853   "\C-p" gnus-summary-prev-same-subject
1854   "\M-n" gnus-summary-next-unread-subject
1855   "\M-p" gnus-summary-prev-unread-subject
1856   "f" gnus-summary-first-unread-article
1857   "b" gnus-summary-best-unread-article
1858   "j" gnus-summary-goto-article
1859   "g" gnus-summary-goto-subject
1860   "l" gnus-summary-goto-last-article
1861   "o" gnus-summary-pop-article)
1862
1863 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1864   "k" gnus-summary-kill-thread
1865   "l" gnus-summary-lower-thread
1866   "i" gnus-summary-raise-thread
1867   "T" gnus-summary-toggle-threads
1868   "t" gnus-summary-rethread-current
1869   "^" gnus-summary-reparent-thread
1870   "s" gnus-summary-show-thread
1871   "S" gnus-summary-show-all-threads
1872   "h" gnus-summary-hide-thread
1873   "H" gnus-summary-hide-all-threads
1874   "n" gnus-summary-next-thread
1875   "p" gnus-summary-prev-thread
1876   "u" gnus-summary-up-thread
1877   "o" gnus-summary-top-thread
1878   "d" gnus-summary-down-thread
1879   "#" gnus-uu-mark-thread
1880   "\M-#" gnus-uu-unmark-thread)
1881
1882 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1883   "g" gnus-summary-prepare
1884   "c" gnus-summary-insert-cached-articles
1885   "d" gnus-summary-insert-dormant-articles)
1886
1887 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1888   "c" gnus-summary-catchup-and-exit
1889   "C" gnus-summary-catchup-all-and-exit
1890   "E" gnus-summary-exit-no-update
1891   "Q" gnus-summary-exit
1892   "Z" gnus-summary-exit
1893   "n" gnus-summary-catchup-and-goto-next-group
1894   "R" gnus-summary-reselect-current-group
1895   "G" gnus-summary-rescan-group
1896   "N" gnus-summary-next-group
1897   "s" gnus-summary-save-newsrc
1898   "P" gnus-summary-prev-group)
1899
1900 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1901   " " gnus-summary-next-page
1902   "n" gnus-summary-next-page
1903   "\177" gnus-summary-prev-page
1904   [delete] gnus-summary-prev-page
1905   "p" gnus-summary-prev-page
1906   "\r" gnus-summary-scroll-up
1907   "\M-\r" gnus-summary-scroll-down
1908   "<" gnus-summary-beginning-of-article
1909   ">" gnus-summary-end-of-article
1910   "b" gnus-summary-beginning-of-article
1911   "e" gnus-summary-end-of-article
1912   "^" gnus-summary-refer-parent-article
1913   "r" gnus-summary-refer-parent-article
1914   "D" gnus-summary-enter-digest-group
1915   "R" gnus-summary-refer-references
1916   "T" gnus-summary-refer-thread
1917   "g" gnus-summary-show-article
1918   "s" gnus-summary-isearch-article
1919   "P" gnus-summary-print-article
1920   "M" gnus-mailing-list-insinuate
1921   "t" gnus-article-babel)
1922
1923 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1924   "b" gnus-article-add-buttons
1925   "B" gnus-article-add-buttons-to-head
1926   "o" gnus-article-treat-overstrike
1927   "e" gnus-article-emphasize
1928   "w" gnus-article-fill-cited-article
1929   "Q" gnus-article-fill-long-lines
1930   "C" gnus-article-capitalize-sentences
1931   "c" gnus-article-remove-cr
1932   "q" gnus-article-de-quoted-unreadable
1933   "6" gnus-article-de-base64-unreadable
1934   "Z" gnus-article-decode-HZ
1935   "A" gnus-article-treat-ansi-sequences
1936   "h" gnus-article-wash-html
1937   "u" gnus-article-unsplit-urls
1938   "s" gnus-summary-force-verify-and-decrypt
1939   "f" gnus-article-display-x-face
1940   "l" gnus-summary-stop-page-breaking
1941   "r" gnus-summary-caesar-message
1942   "m" gnus-summary-morse-message
1943   "t" gnus-summary-toggle-header
1944   "g" gnus-treat-smiley
1945   "v" gnus-summary-verbose-headers
1946   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1947   "p" gnus-article-verify-x-pgp-sig
1948   "d" gnus-article-treat-dumbquotes
1949   "i" gnus-summary-idna-message)
1950
1951 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1952   ;; mnemonic: deuglif*Y*
1953   "u" gnus-article-outlook-unwrap-lines
1954   "a" gnus-article-outlook-repair-attribution
1955   "c" gnus-article-outlook-rearrange-citation
1956   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1957
1958 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1959   "a" gnus-article-hide
1960   "h" gnus-article-hide-headers
1961   "b" gnus-article-hide-boring-headers
1962   "s" gnus-article-hide-signature
1963   "c" gnus-article-hide-citation
1964   "C" gnus-article-hide-citation-in-followups
1965   "l" gnus-article-hide-list-identifiers
1966   "B" gnus-article-strip-banner
1967   "P" gnus-article-hide-pem
1968   "\C-c" gnus-article-hide-citation-maybe)
1969
1970 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1971   "a" gnus-article-highlight
1972   "h" gnus-article-highlight-headers
1973   "c" gnus-article-highlight-citation
1974   "s" gnus-article-highlight-signature)
1975
1976 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1977   "f" gnus-article-treat-fold-headers
1978   "u" gnus-article-treat-unfold-headers
1979   "n" gnus-article-treat-fold-newsgroups)
1980
1981 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1982   "x" gnus-article-display-x-face
1983   "d" gnus-article-display-face
1984   "s" gnus-treat-smiley
1985   "D" gnus-article-remove-images
1986   "f" gnus-treat-from-picon
1987   "m" gnus-treat-mail-picon
1988   "n" gnus-treat-newsgroups-picon)
1989
1990 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1991   "w" gnus-article-decode-mime-words
1992   "c" gnus-article-decode-charset
1993   "v" gnus-mime-view-all-parts
1994   "b" gnus-article-view-part)
1995
1996 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1997   "z" gnus-article-date-ut
1998   "u" gnus-article-date-ut
1999   "l" gnus-article-date-local
2000   "p" gnus-article-date-english
2001   "e" gnus-article-date-lapsed
2002   "o" gnus-article-date-original
2003   "i" gnus-article-date-iso8601
2004   "s" gnus-article-date-user)
2005
2006 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2007   "t" gnus-article-remove-trailing-blank-lines
2008   "l" gnus-article-strip-leading-blank-lines
2009   "m" gnus-article-strip-multiple-blank-lines
2010   "a" gnus-article-strip-blank-lines
2011   "A" gnus-article-strip-all-blank-lines
2012   "s" gnus-article-strip-leading-space
2013   "e" gnus-article-strip-trailing-space
2014   "w" gnus-article-remove-leading-whitespace)
2015
2016 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2017   "v" gnus-version
2018   "f" gnus-summary-fetch-faq
2019   "d" gnus-summary-describe-group
2020   "h" gnus-summary-describe-briefly
2021   "i" gnus-info-find-node
2022   "c" gnus-group-fetch-charter
2023   "C" gnus-group-fetch-control)
2024
2025 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2026   "e" gnus-summary-expire-articles
2027   "\M-\C-e" gnus-summary-expire-articles-now
2028   "\177" gnus-summary-delete-article
2029   [delete] gnus-summary-delete-article
2030   [backspace] gnus-summary-delete-article
2031   "m" gnus-summary-move-article
2032   "r" gnus-summary-respool-article
2033   "w" gnus-summary-edit-article
2034   "c" gnus-summary-copy-article
2035   "B" gnus-summary-crosspost-article
2036   "q" gnus-summary-respool-query
2037   "t" gnus-summary-respool-trace
2038   "i" gnus-summary-import-article
2039   "I" gnus-summary-create-article
2040   "p" gnus-summary-article-posted-p)
2041
2042 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2043   "o" gnus-summary-save-article
2044   "m" gnus-summary-save-article-mail
2045   "F" gnus-summary-write-article-file
2046   "r" gnus-summary-save-article-rmail
2047   "f" gnus-summary-save-article-file
2048   "b" gnus-summary-save-article-body-file
2049   "h" gnus-summary-save-article-folder
2050   "v" gnus-summary-save-article-vm
2051   "p" gnus-summary-pipe-output
2052   "P" gnus-summary-muttprint
2053   "s" gnus-soup-add-article)
2054
2055 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2056   "b" gnus-summary-display-buttonized
2057   "m" gnus-summary-repair-multipart
2058   "v" gnus-article-view-part
2059   "o" gnus-article-save-part
2060   "c" gnus-article-copy-part
2061   "C" gnus-article-view-part-as-charset
2062   "e" gnus-article-view-part-externally
2063   "E" gnus-article-encrypt-body
2064   "i" gnus-article-inline-part
2065   "|" gnus-article-pipe-part)
2066
2067 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2068   "p" gnus-summary-mark-as-processable
2069   "u" gnus-summary-unmark-as-processable
2070   "U" gnus-summary-unmark-all-processable
2071   "v" gnus-uu-mark-over
2072   "s" gnus-uu-mark-series
2073   "r" gnus-uu-mark-region
2074   "g" gnus-uu-unmark-region
2075   "R" gnus-uu-mark-by-regexp
2076   "G" gnus-uu-unmark-by-regexp
2077   "t" gnus-uu-mark-thread
2078   "T" gnus-uu-unmark-thread
2079   "a" gnus-uu-mark-all
2080   "b" gnus-uu-mark-buffer
2081   "S" gnus-uu-mark-sparse
2082   "k" gnus-summary-kill-process-mark
2083   "y" gnus-summary-yank-process-mark
2084   "w" gnus-summary-save-process-mark
2085   "i" gnus-uu-invert-processable)
2086
2087 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2088   ;;"x" gnus-uu-extract-any
2089   "m" gnus-summary-save-parts
2090   "u" gnus-uu-decode-uu
2091   "U" gnus-uu-decode-uu-and-save
2092   "s" gnus-uu-decode-unshar
2093   "S" gnus-uu-decode-unshar-and-save
2094   "o" gnus-uu-decode-save
2095   "O" gnus-uu-decode-save
2096   "b" gnus-uu-decode-binhex
2097   "B" gnus-uu-decode-binhex
2098   "p" gnus-uu-decode-postscript
2099   "P" gnus-uu-decode-postscript-and-save)
2100
2101 (gnus-define-keys
2102     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2103   "u" gnus-uu-decode-uu-view
2104   "U" gnus-uu-decode-uu-and-save-view
2105   "s" gnus-uu-decode-unshar-view
2106   "S" gnus-uu-decode-unshar-and-save-view
2107   "o" gnus-uu-decode-save-view
2108   "O" gnus-uu-decode-save-view
2109   "b" gnus-uu-decode-binhex-view
2110   "B" gnus-uu-decode-binhex-view
2111   "p" gnus-uu-decode-postscript-view
2112   "P" gnus-uu-decode-postscript-and-save-view)
2113
2114 (defvar gnus-article-post-menu nil)
2115
2116 (defconst gnus-summary-menu-maxlen 20)
2117
2118 (defun gnus-summary-menu-split (menu)
2119   ;; If we have lots of elements, divide them into groups of 20
2120   ;; and make a pane (or submenu) for each one.
2121   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2122       (let ((menu menu) sublists next
2123             (i 1))
2124         (while menu
2125           ;; Pull off the next gnus-summary-menu-maxlen elements
2126           ;; and make them the next element of sublist.
2127           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2128           (if next
2129               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2130                       nil))
2131           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2132                                              (aref (car (last menu)) 0)) menu)
2133                                sublists))
2134           (setq i (1+ i))
2135           (setq menu next))
2136         (nreverse sublists))
2137     ;; Few elements--put them all in one pane.
2138     menu))
2139
2140 (defun gnus-summary-make-menu-bar ()
2141   (gnus-turn-off-edit-menu 'summary)
2142
2143   (unless (boundp 'gnus-summary-misc-menu)
2144
2145     (easy-menu-define
2146       gnus-summary-kill-menu gnus-summary-mode-map ""
2147       (cons
2148        "Score"
2149        (nconc
2150         (list
2151          ["Customize" gnus-score-customize t])
2152         (gnus-make-score-map 'increase)
2153         (gnus-make-score-map 'lower)
2154         '(("Mark"
2155            ["Kill below" gnus-summary-kill-below t]
2156            ["Mark above" gnus-summary-mark-above t]
2157            ["Tick above" gnus-summary-tick-above t]
2158            ["Clear above" gnus-summary-clear-above t])
2159           ["Current score" gnus-summary-current-score t]
2160           ["Set score" gnus-summary-set-score t]
2161           ["Switch current score file..." gnus-score-change-score-file t]
2162           ["Set mark below..." gnus-score-set-mark-below t]
2163           ["Set expunge below..." gnus-score-set-expunge-below t]
2164           ["Edit current score file" gnus-score-edit-current-scores t]
2165           ["Edit score file" gnus-score-edit-file t]
2166           ["Trace score" gnus-score-find-trace t]
2167           ["Find words" gnus-score-find-favourite-words t]
2168           ["Rescore buffer" gnus-summary-rescore t]
2169           ["Increase score..." gnus-summary-increase-score t]
2170           ["Lower score..." gnus-summary-lower-score t]))))
2171
2172     ;; Define both the Article menu in the summary buffer and the
2173     ;; equivalent Commands menu in the article buffer here for
2174     ;; consistency.
2175     (let ((innards
2176            `(("Hide"
2177               ["All" gnus-article-hide t]
2178               ["Headers" gnus-article-hide-headers t]
2179               ["Signature" gnus-article-hide-signature t]
2180               ["Citation" gnus-article-hide-citation t]
2181               ["List identifiers" gnus-article-hide-list-identifiers t]
2182               ["Banner" gnus-article-strip-banner t]
2183               ["Boring headers" gnus-article-hide-boring-headers t])
2184              ("Highlight"
2185               ["All" gnus-article-highlight t]
2186               ["Headers" gnus-article-highlight-headers t]
2187               ["Signature" gnus-article-highlight-signature t]
2188               ["Citation" gnus-article-highlight-citation t])
2189              ("MIME"
2190               ["Words" gnus-article-decode-mime-words t]
2191               ["Charset" gnus-article-decode-charset t]
2192               ["QP" gnus-article-de-quoted-unreadable t]
2193               ["Base64" gnus-article-de-base64-unreadable t]
2194               ["View MIME buttons" gnus-summary-display-buttonized t]
2195               ["View all" gnus-mime-view-all-parts t]
2196               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2197               ["Encrypt body" gnus-article-encrypt-body
2198                :active (not (gnus-group-read-only-p))
2199                ,@(if (featurep 'xemacs) nil
2200                    '(:help "Encrypt the message body on disk"))]
2201               ["Extract all parts..." gnus-summary-save-parts t]
2202               ("Multipart"
2203                ["Repair multipart" gnus-summary-repair-multipart t]
2204                ["Pipe part..." gnus-article-pipe-part t]
2205                ["Inline part" gnus-article-inline-part t]
2206                ["Encrypt body" gnus-article-encrypt-body
2207                 :active (not (gnus-group-read-only-p))
2208                ,@(if (featurep 'xemacs) nil
2209                    '(:help "Encrypt the message body on disk"))]
2210                ["View part externally" gnus-article-view-part-externally t]
2211                ["View part with charset..." gnus-article-view-part-as-charset t]
2212                ["Copy part" gnus-article-copy-part t]
2213                ["Save part..." gnus-article-save-part t]
2214                ["View part" gnus-article-view-part t]))
2215              ("Date"
2216               ["Local" gnus-article-date-local t]
2217               ["ISO8601" gnus-article-date-iso8601 t]
2218               ["UT" gnus-article-date-ut t]
2219               ["Original" gnus-article-date-original t]
2220               ["Lapsed" gnus-article-date-lapsed t]
2221               ["User-defined" gnus-article-date-user t])
2222              ("Display"
2223               ["Remove images" gnus-article-remove-images t]
2224               ["Toggle smiley" gnus-treat-smiley t]
2225               ["Show X-Face" gnus-article-display-x-face t]
2226               ["Show picons in From" gnus-treat-from-picon t]
2227               ["Show picons in mail headers" gnus-treat-mail-picon t]
2228               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2229               ("View as different encoding"
2230                ,@(gnus-summary-menu-split
2231                   (mapcar
2232                    (lambda (cs)
2233                      ;; Since easymenu under Emacs doesn't allow
2234                      ;; lambda forms for menu commands, we should
2235                      ;; provide intern'ed function symbols.
2236                      (let ((command (intern (format "\
2237 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2238                        (fset command
2239                              `(lambda ()
2240                                 (interactive)
2241                                 (let ((gnus-summary-show-article-charset-alist
2242                                        '((1 . ,cs))))
2243                                   (gnus-summary-show-article 1))))
2244                        `[,(symbol-name cs) ,command t]))
2245                    (sort (if (fboundp 'coding-system-list)
2246                              (coding-system-list)
2247                            (mapcar 'car mm-mime-mule-charset-alist))
2248                          'string<)))))
2249              ("Washing"
2250               ("Remove Blanks"
2251                ["Leading" gnus-article-strip-leading-blank-lines t]
2252                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2253                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2254                ["All of the above" gnus-article-strip-blank-lines t]
2255                ["All" gnus-article-strip-all-blank-lines t]
2256                ["Leading space" gnus-article-strip-leading-space t]
2257                ["Trailing space" gnus-article-strip-trailing-space t]
2258                ["Leading space in headers"
2259                 gnus-article-remove-leading-whitespace t])
2260               ["Overstrike" gnus-article-treat-overstrike t]
2261               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2262               ["Emphasis" gnus-article-emphasize t]
2263               ["Word wrap" gnus-article-fill-cited-article t]
2264               ["Fill long lines" gnus-article-fill-long-lines t]
2265               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2266               ["Remove CR" gnus-article-remove-cr t]
2267               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2268               ["Base64" gnus-article-de-base64-unreadable t]
2269               ["Rot 13" gnus-summary-caesar-message
2270                ,@(if (featurep 'xemacs) '(t)
2271                    '(:help "\"Caesar rotate\" article by 13"))]
2272               ["De-IDNA" gnus-summary-idna-message t]
2273               ["Morse decode" gnus-summary-morse-message t]
2274               ["Unix pipe..." gnus-summary-pipe-message t]
2275               ["Add buttons" gnus-article-add-buttons t]
2276               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2277               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2278               ["Verbose header" gnus-summary-verbose-headers t]
2279               ["Toggle header" gnus-summary-toggle-header t]
2280               ["Unfold headers" gnus-article-treat-unfold-headers t]
2281               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2282               ["Html" gnus-article-wash-html t]
2283               ["Unsplit URLs" gnus-article-unsplit-urls t]
2284               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2285               ["Decode HZ" gnus-article-decode-HZ t]
2286               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2287               ("(Outlook) Deuglify"
2288                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2289                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2290                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2291                ["Full (Outlook) deuglify"
2292                 gnus-article-outlook-deuglify-article t])
2293               )
2294              ("Output"
2295               ["Save in default format..." gnus-summary-save-article
2296                ,@(if (featurep 'xemacs) '(t)
2297                    '(:help "Save article using default method"))]
2298               ["Save in file..." gnus-summary-save-article-file
2299                ,@(if (featurep 'xemacs) '(t)
2300                    '(:help "Save article in file"))]
2301               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2302               ["Save in MH folder..." gnus-summary-save-article-folder t]
2303               ["Save in VM folder..." gnus-summary-save-article-vm t]
2304               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2305               ["Save body in file..." gnus-summary-save-article-body-file t]
2306               ["Pipe through a filter..." gnus-summary-pipe-output t]
2307               ["Add to SOUP packet" gnus-soup-add-article t]
2308               ["Print with Muttprint..." gnus-summary-muttprint t]
2309               ["Print" gnus-summary-print-article
2310                ,@(if (featurep 'xemacs) '(t)
2311                    '(:help "Generate and print a PostScript image"))])
2312              ("Copy, move,... (Backend)"
2313               ,@(if (featurep 'xemacs) nil
2314                   '(:help "Copying, moving, expiring articles..."))
2315               ["Respool article..." gnus-summary-respool-article t]
2316               ["Move article..." gnus-summary-move-article
2317                (gnus-check-backend-function
2318                 'request-move-article gnus-newsgroup-name)]
2319               ["Copy article..." gnus-summary-copy-article t]
2320               ["Crosspost article..." gnus-summary-crosspost-article
2321                (gnus-check-backend-function
2322                 'request-replace-article gnus-newsgroup-name)]
2323               ["Import file..." gnus-summary-import-article
2324                (gnus-check-backend-function
2325                 'request-accept-article gnus-newsgroup-name)]
2326               ["Create article..." gnus-summary-create-article
2327                (gnus-check-backend-function
2328                 'request-accept-article gnus-newsgroup-name)]
2329               ["Check if posted" gnus-summary-article-posted-p t]
2330               ["Edit article" gnus-summary-edit-article
2331                (not (gnus-group-read-only-p))]
2332               ["Delete article" gnus-summary-delete-article
2333                (gnus-check-backend-function
2334                 'request-expire-articles gnus-newsgroup-name)]
2335               ["Query respool" gnus-summary-respool-query t]
2336               ["Trace respool" gnus-summary-respool-trace t]
2337               ["Delete expirable articles" gnus-summary-expire-articles-now
2338                (gnus-check-backend-function
2339                 'request-expire-articles gnus-newsgroup-name)])
2340              ("Extract"
2341               ["Uudecode" gnus-uu-decode-uu
2342                ,@(if (featurep 'xemacs) '(t)
2343                    '(:help "Decode uuencoded article(s)"))]
2344               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2345               ["Unshar" gnus-uu-decode-unshar t]
2346               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2347               ["Save" gnus-uu-decode-save t]
2348               ["Binhex" gnus-uu-decode-binhex t]
2349               ["Postscript" gnus-uu-decode-postscript t]
2350               ["All MIME parts" gnus-summary-save-parts t])
2351              ("Cache"
2352               ["Enter article" gnus-cache-enter-article t]
2353               ["Remove article" gnus-cache-remove-article t])
2354              ["Translate" gnus-article-babel t]
2355              ["Select article buffer" gnus-summary-select-article-buffer t]
2356              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2357              ["Isearch article..." gnus-summary-isearch-article t]
2358              ["Beginning of the article" gnus-summary-beginning-of-article t]
2359              ["End of the article" gnus-summary-end-of-article t]
2360              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2361              ["Fetch referenced articles" gnus-summary-refer-references t]
2362              ["Fetch current thread" gnus-summary-refer-thread t]
2363              ["Fetch article with id..." gnus-summary-refer-article t]
2364              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2365              ["Redisplay" gnus-summary-show-article t]
2366              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2367       (easy-menu-define
2368         gnus-summary-article-menu gnus-summary-mode-map ""
2369         (cons "Article" innards))
2370
2371       (if (not (keymapp gnus-summary-article-menu))
2372           (easy-menu-define
2373             gnus-article-commands-menu gnus-article-mode-map ""
2374             (cons "Commands" innards))
2375         ;; in Emacs, don't share menu.
2376         (setq gnus-article-commands-menu
2377               (copy-keymap gnus-summary-article-menu))
2378         (define-key gnus-article-mode-map [menu-bar commands]
2379           (cons "Commands" gnus-article-commands-menu))))
2380
2381     (easy-menu-define
2382       gnus-summary-thread-menu gnus-summary-mode-map ""
2383       '("Threads"
2384         ["Find all messages in thread" gnus-summary-refer-thread t]
2385         ["Toggle threading" gnus-summary-toggle-threads t]
2386         ["Hide threads" gnus-summary-hide-all-threads t]
2387         ["Show threads" gnus-summary-show-all-threads t]
2388         ["Hide thread" gnus-summary-hide-thread t]
2389         ["Show thread" gnus-summary-show-thread t]
2390         ["Go to next thread" gnus-summary-next-thread t]
2391         ["Go to previous thread" gnus-summary-prev-thread t]
2392         ["Go down thread" gnus-summary-down-thread t]
2393         ["Go up thread" gnus-summary-up-thread t]
2394         ["Top of thread" gnus-summary-top-thread t]
2395         ["Mark thread as read" gnus-summary-kill-thread t]
2396         ["Lower thread score" gnus-summary-lower-thread t]
2397         ["Raise thread score" gnus-summary-raise-thread t]
2398         ["Rethread current" gnus-summary-rethread-current t]))
2399
2400     (easy-menu-define
2401       gnus-summary-post-menu gnus-summary-mode-map ""
2402       `("Post"
2403         ["Send a message (mail or news)" gnus-summary-post-news
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Compose a new message (mail or news)"))]
2406         ["Followup" gnus-summary-followup
2407          ,@(if (featurep 'xemacs) '(t)
2408              '(:help "Post followup to this article"))]
2409         ["Followup and yank" gnus-summary-followup-with-original
2410          ,@(if (featurep 'xemacs) '(t)
2411              '(:help "Post followup to this article, quoting its contents"))]
2412         ["Supersede article" gnus-summary-supersede-article t]
2413         ["Cancel article" gnus-summary-cancel-article
2414          ,@(if (featurep 'xemacs) '(t)
2415              '(:help "Cancel an article you posted"))]
2416         ["Reply" gnus-summary-reply t]
2417         ["Reply and yank" gnus-summary-reply-with-original t]
2418         ["Wide reply" gnus-summary-wide-reply t]
2419         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2420          ,@(if (featurep 'xemacs) '(t)
2421              '(:help "Mail a reply, quoting this article"))]
2422         ["Very wide reply" gnus-summary-very-wide-reply t]
2423         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2424          ,@(if (featurep 'xemacs) '(t)
2425              '(:help "Mail a very wide reply, quoting this article"))]
2426         ["Mail forward" gnus-summary-mail-forward t]
2427         ["Post forward" gnus-summary-post-forward t]
2428         ["Digest and mail" gnus-uu-digest-mail-forward t]
2429         ["Digest and post" gnus-uu-digest-post-forward t]
2430         ["Resend message" gnus-summary-resend-message t]
2431         ["Resend message edit" gnus-summary-resend-message-edit t]
2432         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2433         ["Send a mail" gnus-summary-mail-other-window t]
2434         ["Create a local message" gnus-summary-news-other-window t]
2435         ["Uuencode and post" gnus-uu-post-news
2436          ,@(if (featurep 'xemacs) '(t)
2437              '(:help "Post a uuencoded article"))]
2438         ["Followup via news" gnus-summary-followup-to-mail t]
2439         ["Followup via news and yank"
2440          gnus-summary-followup-to-mail-with-original t]
2441         ;;("Draft"
2442         ;;["Send" gnus-summary-send-draft t]
2443         ;;["Send bounced" gnus-resend-bounced-mail t])
2444         ))
2445
2446     (cond
2447      ((not (keymapp gnus-summary-post-menu))
2448       (setq gnus-article-post-menu gnus-summary-post-menu))
2449      ((not gnus-article-post-menu)
2450       ;; Don't share post menu.
2451       (setq gnus-article-post-menu
2452             (copy-keymap gnus-summary-post-menu))))
2453     (define-key gnus-article-mode-map [menu-bar post]
2454       (cons "Post" gnus-article-post-menu))
2455
2456     (easy-menu-define
2457       gnus-summary-misc-menu gnus-summary-mode-map ""
2458       `("Gnus"
2459         ("Mark Read"
2460          ["Mark as read" gnus-summary-mark-as-read-forward t]
2461          ["Mark same subject and select"
2462           gnus-summary-kill-same-subject-and-select t]
2463          ["Mark same subject" gnus-summary-kill-same-subject t]
2464          ["Catchup" gnus-summary-catchup
2465           ,@(if (featurep 'xemacs) '(t)
2466               '(:help "Mark unread articles in this group as read"))]
2467          ["Catchup all" gnus-summary-catchup-all t]
2468          ["Catchup to here" gnus-summary-catchup-to-here t]
2469          ["Catchup from here" gnus-summary-catchup-from-here t]
2470          ["Catchup region" gnus-summary-mark-region-as-read
2471           (gnus-mark-active-p)]
2472          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2473         ("Mark Various"
2474          ["Tick" gnus-summary-tick-article-forward t]
2475          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2476          ["Remove marks" gnus-summary-clear-mark-forward t]
2477          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2478          ["Set bookmark" gnus-summary-set-bookmark t]
2479          ["Remove bookmark" gnus-summary-remove-bookmark t])
2480         ("Limit to"
2481          ["Marks..." gnus-summary-limit-to-marks t]
2482          ["Subject..." gnus-summary-limit-to-subject t]
2483          ["Author..." gnus-summary-limit-to-author t]
2484          ["Recipient..." gnus-summary-limit-to-recipient t]
2485          ["Age..." gnus-summary-limit-to-age t]
2486          ["Extra..." gnus-summary-limit-to-extra t]
2487          ["Score..." gnus-summary-limit-to-score t]
2488          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2489          ["Unread" gnus-summary-limit-to-unread t]
2490          ["Unseen" gnus-summary-limit-to-unseen t]
2491          ["Replied" gnus-summary-limit-to-replied t]
2492          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2493          ["Next articles" gnus-summary-limit-to-articles t]
2494          ["Pop limit" gnus-summary-pop-limit t]
2495          ["Show dormant" gnus-summary-limit-include-dormant t]
2496          ["Hide childless dormant"
2497           gnus-summary-limit-exclude-childless-dormant t]
2498          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2499          ["Hide marked" gnus-summary-limit-exclude-marks t]
2500          ["Show expunged" gnus-summary-limit-include-expunged t])
2501         ("Process Mark"
2502          ["Set mark" gnus-summary-mark-as-processable t]
2503          ["Remove mark" gnus-summary-unmark-as-processable t]
2504          ["Remove all marks" gnus-summary-unmark-all-processable t]
2505          ["Invert marks" gnus-uu-invert-processable t]
2506          ["Mark above" gnus-uu-mark-over t]
2507          ["Mark series" gnus-uu-mark-series t]
2508          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2509          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2510          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2511          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2512          ["Mark all" gnus-uu-mark-all t]
2513          ["Mark buffer" gnus-uu-mark-buffer t]
2514          ["Mark sparse" gnus-uu-mark-sparse t]
2515          ["Mark thread" gnus-uu-mark-thread t]
2516          ["Unmark thread" gnus-uu-unmark-thread t]
2517          ("Process Mark Sets"
2518           ["Kill" gnus-summary-kill-process-mark t]
2519           ["Yank" gnus-summary-yank-process-mark
2520            gnus-newsgroup-process-stack]
2521           ["Save" gnus-summary-save-process-mark t]
2522           ["Run command on marked..." gnus-summary-universal-argument t]))
2523         ("Scroll article"
2524          ["Page forward" gnus-summary-next-page
2525           ,@(if (featurep 'xemacs) '(t)
2526               '(:help "Show next page of article"))]
2527          ["Page backward" gnus-summary-prev-page
2528           ,@(if (featurep 'xemacs) '(t)
2529               '(:help "Show previous page of article"))]
2530          ["Line forward" gnus-summary-scroll-up t])
2531         ("Move"
2532          ["Next unread article" gnus-summary-next-unread-article t]
2533          ["Previous unread article" gnus-summary-prev-unread-article t]
2534          ["Next article" gnus-summary-next-article t]
2535          ["Previous article" gnus-summary-prev-article t]
2536          ["Next unread subject" gnus-summary-next-unread-subject t]
2537          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2538          ["Next article same subject" gnus-summary-next-same-subject t]
2539          ["Previous article same subject" gnus-summary-prev-same-subject t]
2540          ["First unread article" gnus-summary-first-unread-article t]
2541          ["Best unread article" gnus-summary-best-unread-article t]
2542          ["Go to subject number..." gnus-summary-goto-subject t]
2543          ["Go to article number..." gnus-summary-goto-article t]
2544          ["Go to the last article" gnus-summary-goto-last-article t]
2545          ["Pop article off history" gnus-summary-pop-article t])
2546         ("Sort"
2547          ["Sort by number" gnus-summary-sort-by-number t]
2548          ["Sort by author" gnus-summary-sort-by-author t]
2549          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2550          ["Sort by subject" gnus-summary-sort-by-subject t]
2551          ["Sort by date" gnus-summary-sort-by-date t]
2552          ["Sort by score" gnus-summary-sort-by-score t]
2553          ["Sort by lines" gnus-summary-sort-by-lines t]
2554          ["Sort by characters" gnus-summary-sort-by-chars t]
2555          ["Randomize" gnus-summary-sort-by-random t]
2556          ["Original sort" gnus-summary-sort-by-original t])
2557         ("Help"
2558          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2559          ["Describe group" gnus-summary-describe-group t]
2560          ["Fetch charter" gnus-group-fetch-charter
2561           ,@(if (featurep 'xemacs) nil
2562               '(:help "Display the charter of the current group"))]
2563          ["Fetch control message" gnus-group-fetch-control
2564           ,@(if (featurep 'xemacs) nil
2565               '(:help "Display the archived control message for the current group"))]
2566          ["Read manual" gnus-info-find-node t])
2567         ("Modes"
2568          ["Pick and read" gnus-pick-mode t]
2569          ["Binary" gnus-binary-mode t])
2570         ("Regeneration"
2571          ["Regenerate" gnus-summary-prepare t]
2572          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2573          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2574          ["Toggle threading" gnus-summary-toggle-threads t])
2575         ["See old articles" gnus-summary-insert-old-articles t]
2576         ["See new articles" gnus-summary-insert-new-articles t]
2577         ["Filter articles..." gnus-summary-execute-command t]
2578         ["Run command on articles..." gnus-summary-universal-argument t]
2579         ["Search articles forward..." gnus-summary-search-article-forward t]
2580         ["Search articles backward..." gnus-summary-search-article-backward t]
2581         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2582         ["Expand window" gnus-summary-expand-window t]
2583         ["Expire expirable articles" gnus-summary-expire-articles
2584          (gnus-check-backend-function
2585           'request-expire-articles gnus-newsgroup-name)]
2586         ["Edit local kill file" gnus-summary-edit-local-kill t]
2587         ["Edit main kill file" gnus-summary-edit-global-kill t]
2588         ["Edit group parameters" gnus-summary-edit-parameters t]
2589         ["Customize group parameters" gnus-summary-customize-parameters t]
2590         ["Send a bug report" gnus-bug t]
2591         ("Exit"
2592          ["Catchup and exit" gnus-summary-catchup-and-exit
2593           ,@(if (featurep 'xemacs) '(t)
2594               '(:help "Mark unread articles in this group as read, then exit"))]
2595          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2596          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2597          ["Exit group" gnus-summary-exit
2598           ,@(if (featurep 'xemacs) '(t)
2599               '(:help "Exit current group, return to group selection mode"))]
2600          ["Exit group without updating" gnus-summary-exit-no-update t]
2601          ["Exit and goto next group" gnus-summary-next-group t]
2602          ["Exit and goto prev group" gnus-summary-prev-group t]
2603          ["Reselect group" gnus-summary-reselect-current-group t]
2604          ["Rescan group" gnus-summary-rescan-group t]
2605          ["Update dribble" gnus-summary-save-newsrc t])))
2606
2607     (gnus-run-hooks 'gnus-summary-menu-hook)))
2608
2609 (defvar gnus-summary-tool-bar-map nil)
2610
2611 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2612 (defun gnus-summary-make-tool-bar ()
2613   (if (and (fboundp 'tool-bar-add-item-from-menu)
2614            (default-value 'tool-bar-mode)
2615            (not gnus-summary-tool-bar-map))
2616       (setq gnus-summary-tool-bar-map
2617             (let ((tool-bar-map (make-sparse-keymap))
2618                   (load-path (mm-image-load-path)))
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-post-news "post" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-followup "followup" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-reply "reply" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2649               (tool-bar-add-item-from-menu
2650                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2651               tool-bar-map)))
2652   (if gnus-summary-tool-bar-map
2653       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2654
2655 (defun gnus-score-set-default (var value)
2656   "A version of set that updates the GNU Emacs menu-bar."
2657   (set var value)
2658   ;; It is the message that forces the active status to be updated.
2659   (message ""))
2660
2661 (defun gnus-make-score-map (type)
2662   "Make a summary score map of type TYPE."
2663   (if t
2664       nil
2665     (let ((headers '(("author" "from" string)
2666                      ("subject" "subject" string)
2667                      ("article body" "body" string)
2668                      ("article head" "head" string)
2669                      ("xref" "xref" string)
2670                      ("extra header" "extra" string)
2671                      ("lines" "lines" number)
2672                      ("followups to author" "followup" string)))
2673           (types '((number ("less than" <)
2674                            ("greater than" >)
2675                            ("equal" =))
2676                    (string ("substring" s)
2677                            ("exact string" e)
2678                            ("fuzzy string" f)
2679                            ("regexp" r))))
2680           (perms '(("temporary" (current-time-string))
2681                    ("permanent" nil)
2682                    ("immediate" now)))
2683           header)
2684       (list
2685        (apply
2686         'nconc
2687         (list
2688          (if (eq type 'lower)
2689              "Lower score"
2690            "Increase score"))
2691         (let (outh)
2692           (while headers
2693             (setq header (car headers))
2694             (setq outh
2695                   (cons
2696                    (apply
2697                     'nconc
2698                     (list (car header))
2699                     (let ((ts (cdr (assoc (nth 2 header) types)))
2700                           outt)
2701                       (while ts
2702                         (setq outt
2703                               (cons
2704                                (apply
2705                                 'nconc
2706                                 (list (caar ts))
2707                                 (let ((ps perms)
2708                                       outp)
2709                                   (while ps
2710                                     (setq outp
2711                                           (cons
2712                                            (vector
2713                                             (caar ps)
2714                                             (list
2715                                              'gnus-summary-score-entry
2716                                              (nth 1 header)
2717                                              (if (or (string= (nth 1 header)
2718                                                               "head")
2719                                                      (string= (nth 1 header)
2720                                                               "body"))
2721                                                  ""
2722                                                (list 'gnus-summary-header
2723                                                      (nth 1 header)))
2724                                              (list 'quote (nth 1 (car ts)))
2725                                              (list 'gnus-score-delta-default
2726                                                    nil)
2727                                              (nth 1 (car ps))
2728                                              t)
2729                                             t)
2730                                            outp))
2731                                     (setq ps (cdr ps)))
2732                                   (list (nreverse outp))))
2733                                outt))
2734                         (setq ts (cdr ts)))
2735                       (list (nreverse outt))))
2736                    outh))
2737             (setq headers (cdr headers)))
2738           (list (nreverse outh))))))))
2739
2740 \f
2741
2742 (defun gnus-summary-mode (&optional group)
2743   "Major mode for reading articles.
2744
2745 All normal editing commands are switched off.
2746 \\<gnus-summary-mode-map>
2747 Each line in this buffer represents one article.  To read an
2748 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2749 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2750 respectively.
2751
2752 You can also post articles and send mail from this buffer.  To
2753 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2754 of an article, type `\\[gnus-summary-reply]'.
2755
2756 There are approx. one gazillion commands you can execute in this
2757 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2758
2759 The following commands are available:
2760
2761 \\{gnus-summary-mode-map}"
2762   (interactive)
2763   (kill-all-local-variables)
2764   (when (gnus-visual-p 'summary-menu 'menu)
2765     (gnus-summary-make-menu-bar)
2766     (gnus-summary-make-tool-bar))
2767   (gnus-summary-make-local-variables)
2768   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2769     (gnus-summary-make-local-variables))
2770   (gnus-make-thread-indent-array)
2771   (gnus-simplify-mode-line)
2772   (setq major-mode 'gnus-summary-mode)
2773   (setq mode-name "Summary")
2774   (make-local-variable 'minor-mode-alist)
2775   (use-local-map gnus-summary-mode-map)
2776   (buffer-disable-undo)
2777   (setq buffer-read-only t              ;Disable modification
2778         show-trailing-whitespace nil)
2779   (setq truncate-lines t)
2780   (setq selective-display t)
2781   (setq selective-display-ellipses t)   ;Display `...'
2782   (gnus-summary-set-display-table)
2783   (gnus-set-default-directory)
2784   (setq gnus-newsgroup-name group)
2785   (make-local-variable 'gnus-summary-line-format)
2786   (make-local-variable 'gnus-summary-line-format-spec)
2787   (make-local-variable 'gnus-summary-dummy-line-format)
2788   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2789   (make-local-variable 'gnus-summary-mark-positions)
2790   (gnus-make-local-hook 'pre-command-hook)
2791   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2792   (gnus-run-hooks 'gnus-summary-mode-hook)
2793   (turn-on-gnus-mailing-list-mode)
2794   (mm-enable-multibyte)
2795   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2796   (gnus-update-summary-mark-positions))
2797
2798 (defun gnus-summary-make-local-variables ()
2799   "Make all the local summary buffer variables."
2800   (let (global)
2801     (dolist (local gnus-summary-local-variables)
2802       (if (consp local)
2803           (progn
2804             (if (eq (cdr local) 'global)
2805                 ;; Copy the global value of the variable.
2806                 (setq global (symbol-value (car local)))
2807               ;; Use the value from the list.
2808               (setq global (eval (cdr local))))
2809             (set (make-local-variable (car local)) global))
2810         ;; Simple nil-valued local variable.
2811         (set (make-local-variable local) nil)))))
2812
2813 (defun gnus-summary-clear-local-variables ()
2814   (let ((locals gnus-summary-local-variables))
2815     (while locals
2816       (if (consp (car locals))
2817           (and (symbolp (caar locals))
2818                (set (caar locals) nil))
2819         (and (symbolp (car locals))
2820              (set (car locals) nil)))
2821       (setq locals (cdr locals)))))
2822
2823 ;; Summary data functions.
2824
2825 (defmacro gnus-data-number (data)
2826   `(car ,data))
2827
2828 (defmacro gnus-data-set-number (data number)
2829   `(setcar ,data ,number))
2830
2831 (defmacro gnus-data-mark (data)
2832   `(nth 1 ,data))
2833
2834 (defmacro gnus-data-set-mark (data mark)
2835   `(setcar (nthcdr 1 ,data) ,mark))
2836
2837 (defmacro gnus-data-pos (data)
2838   `(nth 2 ,data))
2839
2840 (defmacro gnus-data-set-pos (data pos)
2841   `(setcar (nthcdr 2 ,data) ,pos))
2842
2843 (defmacro gnus-data-header (data)
2844   `(nth 3 ,data))
2845
2846 (defmacro gnus-data-set-header (data header)
2847   `(setf (nth 3 ,data) ,header))
2848
2849 (defmacro gnus-data-level (data)
2850   `(nth 4 ,data))
2851
2852 (defmacro gnus-data-unread-p (data)
2853   `(= (nth 1 ,data) gnus-unread-mark))
2854
2855 (defmacro gnus-data-read-p (data)
2856   `(/= (nth 1 ,data) gnus-unread-mark))
2857
2858 (defmacro gnus-data-pseudo-p (data)
2859   `(consp (nth 3 ,data)))
2860
2861 (defmacro gnus-data-find (number)
2862   `(assq ,number gnus-newsgroup-data))
2863
2864 (defmacro gnus-data-find-list (number &optional data)
2865   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2866      (memq (assq ,number bdata)
2867            bdata)))
2868
2869 (defmacro gnus-data-make (number mark pos header level)
2870   `(list ,number ,mark ,pos ,header ,level))
2871
2872 (defun gnus-data-enter (after-article number mark pos header level offset)
2873   (let ((data (gnus-data-find-list after-article)))
2874     (unless data
2875       (error "No such article: %d" after-article))
2876     (setcdr data (cons (gnus-data-make number mark pos header level)
2877                        (cdr data)))
2878     (setq gnus-newsgroup-data-reverse nil)
2879     (gnus-data-update-list (cddr data) offset)))
2880
2881 (defun gnus-data-enter-list (after-article list &optional offset)
2882   (when list
2883     (let ((data (and after-article (gnus-data-find-list after-article)))
2884           (ilist list))
2885       (if (not (or data
2886                    after-article))
2887           (let ((odata gnus-newsgroup-data))
2888             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2889             (when offset
2890               (gnus-data-update-list odata offset)))
2891         ;; Find the last element in the list to be spliced into the main
2892         ;; list.
2893         (setq list (last list))
2894         (if (not data)
2895             (progn
2896               (setcdr list gnus-newsgroup-data)
2897               (setq gnus-newsgroup-data ilist)
2898               (when offset
2899                 (gnus-data-update-list (cdr list) offset)))
2900           (setcdr list (cdr data))
2901           (setcdr data ilist)
2902           (when offset
2903             (gnus-data-update-list (cdr list) offset))))
2904       (setq gnus-newsgroup-data-reverse nil))))
2905
2906 (defun gnus-data-remove (article &optional offset)
2907   (let ((data gnus-newsgroup-data))
2908     (if (= (gnus-data-number (car data)) article)
2909         (progn
2910           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2911                 gnus-newsgroup-data-reverse nil)
2912           (when offset
2913             (gnus-data-update-list gnus-newsgroup-data offset)))
2914       (while (cdr data)
2915         (when (= (gnus-data-number (cadr data)) article)
2916           (setcdr data (cddr data))
2917           (when offset
2918             (gnus-data-update-list (cdr data) offset))
2919           (setq data nil
2920                 gnus-newsgroup-data-reverse nil))
2921         (setq data (cdr data))))))
2922
2923 (defmacro gnus-data-list (backward)
2924   `(if ,backward
2925        (or gnus-newsgroup-data-reverse
2926            (setq gnus-newsgroup-data-reverse
2927                  (reverse gnus-newsgroup-data)))
2928      gnus-newsgroup-data))
2929
2930 (defun gnus-data-update-list (data offset)
2931   "Add OFFSET to the POS of all data entries in DATA."
2932   (setq gnus-newsgroup-data-reverse nil)
2933   (while data
2934     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2935     (setq data (cdr data))))
2936
2937 (defun gnus-summary-article-pseudo-p (article)
2938   "Say whether this article is a pseudo article or not."
2939   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2940
2941 (defmacro gnus-summary-article-sparse-p (article)
2942   "Say whether this article is a sparse article or not."
2943   `(memq ,article gnus-newsgroup-sparse))
2944
2945 (defmacro gnus-summary-article-ancient-p (article)
2946   "Say whether this article is a sparse article or not."
2947   `(memq ,article gnus-newsgroup-ancient))
2948
2949 (defun gnus-article-parent-p (number)
2950   "Say whether this article is a parent or not."
2951   (let ((data (gnus-data-find-list number)))
2952     (and (cdr data)              ; There has to be an article after...
2953          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2954             (gnus-data-level (nth 1 data))))))
2955
2956 (defun gnus-article-children (number)
2957   "Return a list of all children to NUMBER."
2958   (let* ((data (gnus-data-find-list number))
2959          (level (gnus-data-level (car data)))
2960          children)
2961     (setq data (cdr data))
2962     (while (and data
2963                 (= (gnus-data-level (car data)) (1+ level)))
2964       (push (gnus-data-number (car data)) children)
2965       (setq data (cdr data)))
2966     children))
2967
2968 (defmacro gnus-summary-skip-intangible ()
2969   "If the current article is intangible, then jump to a different article."
2970   '(let ((to (get-text-property (point) 'gnus-intangible)))
2971      (and to (gnus-summary-goto-subject to))))
2972
2973 (defmacro gnus-summary-article-intangible-p ()
2974   "Say whether this article is intangible or not."
2975   '(get-text-property (point) 'gnus-intangible))
2976
2977 (defun gnus-article-read-p (article)
2978   "Say whether ARTICLE is read or not."
2979   (not (or (memq article gnus-newsgroup-marked)
2980            (memq article gnus-newsgroup-spam-marked)
2981            (memq article gnus-newsgroup-unreads)
2982            (memq article gnus-newsgroup-unselected)
2983            (memq article gnus-newsgroup-dormant))))
2984
2985 ;; Some summary mode macros.
2986
2987 (defmacro gnus-summary-article-number ()
2988   "The article number of the article on the current line.
2989 If there isn't an article number here, then we return the current
2990 article number."
2991   '(progn
2992      (gnus-summary-skip-intangible)
2993      (or (get-text-property (point) 'gnus-number)
2994          (gnus-summary-last-subject))))
2995
2996 (defmacro gnus-summary-article-header (&optional number)
2997   "Return the header of article NUMBER."
2998   `(gnus-data-header (gnus-data-find
2999                       ,(or number '(gnus-summary-article-number)))))
3000
3001 (defmacro gnus-summary-thread-level (&optional number)
3002   "Return the level of thread that starts with article NUMBER."
3003   `(if (and (eq gnus-summary-make-false-root 'dummy)
3004             (get-text-property (point) 'gnus-intangible))
3005        0
3006      (gnus-data-level (gnus-data-find
3007                        ,(or number '(gnus-summary-article-number))))))
3008
3009 (defmacro gnus-summary-article-mark (&optional number)
3010   "Return the mark of article NUMBER."
3011   `(gnus-data-mark (gnus-data-find
3012                     ,(or number '(gnus-summary-article-number)))))
3013
3014 (defmacro gnus-summary-article-pos (&optional number)
3015   "Return the position of the line of article NUMBER."
3016   `(gnus-data-pos (gnus-data-find
3017                    ,(or number '(gnus-summary-article-number)))))
3018
3019 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3020 (defmacro gnus-summary-article-subject (&optional number)
3021   "Return current subject string or nil if nothing."
3022   `(let ((headers
3023           ,(if number
3024                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3025              '(gnus-data-header (assq (gnus-summary-article-number)
3026                                       gnus-newsgroup-data)))))
3027      (and headers
3028           (vectorp headers)
3029           (mail-header-subject headers))))
3030
3031 (defmacro gnus-summary-article-score (&optional number)
3032   "Return current article score."
3033   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3034                   gnus-newsgroup-scored))
3035        gnus-summary-default-score 0))
3036
3037 (defun gnus-summary-article-children (&optional number)
3038   "Return a list of article numbers that are children of article NUMBER."
3039   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3040          (level (gnus-data-level (car data)))
3041          l children)
3042     (while (and (setq data (cdr data))
3043                 (> (setq l (gnus-data-level (car data))) level))
3044       (and (= (1+ level) l)
3045            (push (gnus-data-number (car data))
3046                  children)))
3047     (nreverse children)))
3048
3049 (defun gnus-summary-article-parent (&optional number)
3050   "Return the article number of the parent of article NUMBER."
3051   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3052                                     (gnus-data-list t)))
3053          (level (gnus-data-level (car data))))
3054     (if (zerop level)
3055         ()                              ; This is a root.
3056       ;; We search until we find an article with a level less than
3057       ;; this one.  That function has to be the parent.
3058       (while (and (setq data (cdr data))
3059                   (not (< (gnus-data-level (car data)) level))))
3060       (and data (gnus-data-number (car data))))))
3061
3062 (defun gnus-unread-mark-p (mark)
3063   "Say whether MARK is the unread mark."
3064   (= mark gnus-unread-mark))
3065
3066 (defun gnus-read-mark-p (mark)
3067   "Say whether MARK is one of the marks that mark as read.
3068 This is all marks except unread, ticked, dormant, and expirable."
3069   (not (or (= mark gnus-unread-mark)
3070            (= mark gnus-ticked-mark)
3071            (= mark gnus-spam-mark)
3072            (= mark gnus-dormant-mark)
3073            (= mark gnus-expirable-mark))))
3074
3075 (defmacro gnus-article-mark (number)
3076   "Return the MARK of article NUMBER.
3077 This macro should only be used when computing the mark the \"first\"
3078 time; i.e., when generating the summary lines.  After that,
3079 `gnus-summary-article-mark' should be used to examine the
3080 marks of articles."
3081   `(cond
3082     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3083     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3084     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3085     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3086     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3087     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3088     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3089     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3090            gnus-ancient-mark))))
3091
3092 ;; Saving hidden threads.
3093
3094 (defmacro gnus-save-hidden-threads (&rest forms)
3095   "Save hidden threads, eval FORMS, and restore the hidden threads."
3096   (let ((config (make-symbol "config")))
3097     `(let ((,config (gnus-hidden-threads-configuration)))
3098        (unwind-protect
3099            (save-excursion
3100              ,@forms)
3101          (gnus-restore-hidden-threads-configuration ,config)))))
3102 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3103 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3104
3105 (defun gnus-data-compute-positions ()
3106   "Compute the positions of all articles."
3107   (setq gnus-newsgroup-data-reverse nil)
3108   (let ((data gnus-newsgroup-data))
3109     (save-excursion
3110       (gnus-save-hidden-threads
3111         (gnus-summary-show-all-threads)
3112         (goto-char (point-min))
3113         (while data
3114           (while (get-text-property (point) 'gnus-intangible)
3115             (forward-line 1))
3116           (gnus-data-set-pos (car data) (+ (point) 3))
3117           (setq data (cdr data))
3118           (forward-line 1))))))
3119
3120 (defun gnus-hidden-threads-configuration ()
3121   "Return the current hidden threads configuration."
3122   (save-excursion
3123     (let (config)
3124       (goto-char (point-min))
3125       (while (search-forward "\r" nil t)
3126         (push (1- (point)) config))
3127       config)))
3128
3129 (defun gnus-restore-hidden-threads-configuration (config)
3130   "Restore hidden threads configuration from CONFIG."
3131   (save-excursion
3132     (let (point buffer-read-only)
3133       (while (setq point (pop config))
3134         (when (and (< point (point-max))
3135                    (goto-char point)
3136                    (eq (char-after) ?\n))
3137           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3138
3139 ;; Various summary mode internalish functions.
3140
3141 (defun gnus-mouse-pick-article (e)
3142   (interactive "e")
3143   (mouse-set-point e)
3144   (gnus-summary-next-page nil t))
3145
3146 (defun gnus-summary-set-display-table ()
3147   "Change the display table.
3148 Odd characters have a tendency to mess
3149 up nicely formatted displays - we make all possible glyphs
3150 display only a single character."
3151
3152   ;; We start from the standard display table, if any.
3153   (let ((table (or (copy-sequence standard-display-table)
3154                    (make-display-table)))
3155         (i 32))
3156     ;; Nix out all the control chars...
3157     (while (>= (setq i (1- i)) 0)
3158       (aset table i [??]))
3159    ;; ... but not newline and cr, of course.  (cr is necessary for the
3160     ;; selective display).
3161     (aset table ?\n nil)
3162     (aset table ?\r nil)
3163     ;; We keep TAB as well.
3164     (aset table ?\t nil)
3165     ;; We nix out any glyphs over 126 that are not set already.
3166     (let ((i 256))
3167       (while (>= (setq i (1- i)) 127)
3168         ;; Only modify if the entry is nil.
3169         (unless (aref table i)
3170           (aset table i [??]))))
3171     (setq buffer-display-table table)))
3172
3173 (defun gnus-summary-set-article-display-arrow (pos)
3174   "Update the overlay arrow to point to line at position POS."
3175   (when (and gnus-summary-display-arrow
3176              (boundp 'overlay-arrow-position)
3177              (boundp 'overlay-arrow-string))
3178     (save-excursion
3179       (goto-char pos)
3180       (beginning-of-line)
3181       (unless overlay-arrow-position
3182         (setq overlay-arrow-position (make-marker)))
3183       (setq overlay-arrow-string "=>"
3184             overlay-arrow-position (set-marker overlay-arrow-position
3185                                                (point)
3186                                                (current-buffer))))))
3187
3188 (defun gnus-summary-setup-buffer (group)
3189   "Initialize summary buffer."
3190   (let ((buffer (gnus-summary-buffer-name group))
3191         (dead-name (concat "*Dead Summary "
3192                            (gnus-group-decoded-name group) "*")))
3193     ;; If a dead summary buffer exists, we kill it.
3194     (when (gnus-buffer-live-p dead-name)
3195       (gnus-kill-buffer dead-name))
3196     (if (get-buffer buffer)
3197         (progn
3198           (set-buffer buffer)
3199           (setq gnus-summary-buffer (current-buffer))
3200           (not gnus-newsgroup-prepared))
3201       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3202       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3203       (gnus-summary-mode group)
3204       (when gnus-carpal
3205         (gnus-carpal-setup-buffer 'summary))
3206       (unless gnus-single-article-buffer
3207         (make-local-variable 'gnus-article-buffer)
3208         (make-local-variable 'gnus-article-current)
3209         (make-local-variable 'gnus-original-article-buffer))
3210       (setq gnus-newsgroup-name group)
3211       ;; Set any local variables in the group parameters.
3212       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3213       t)))
3214
3215 (defun gnus-set-global-variables ()
3216   "Set the global equivalents of the buffer-local variables.
3217 They are set to the latest values they had.  These reflect the summary
3218 buffer that was in action when the last article was fetched."
3219   (when (eq major-mode 'gnus-summary-mode)
3220     (setq gnus-summary-buffer (current-buffer))
3221     (let ((name gnus-newsgroup-name)
3222           (marked gnus-newsgroup-marked)
3223           (spam gnus-newsgroup-spam-marked)
3224           (unread gnus-newsgroup-unreads)
3225           (headers gnus-current-headers)
3226           (data gnus-newsgroup-data)
3227           (summary gnus-summary-buffer)
3228           (article-buffer gnus-article-buffer)
3229           (original gnus-original-article-buffer)
3230           (gac gnus-article-current)
3231           (reffed gnus-reffed-article-number)
3232           (score-file gnus-current-score-file)
3233           (default-charset gnus-newsgroup-charset)
3234           vlist)
3235       (let ((locals gnus-newsgroup-variables))
3236         (while locals
3237           (if (consp (car locals))
3238               (push (eval (caar locals)) vlist)
3239             (push (eval (car locals)) vlist))
3240           (setq locals (cdr locals)))
3241         (setq vlist (nreverse vlist)))
3242       (with-current-buffer gnus-group-buffer
3243         (setq gnus-newsgroup-name name
3244               gnus-newsgroup-marked marked
3245               gnus-newsgroup-spam-marked spam
3246               gnus-newsgroup-unreads unread
3247               gnus-current-headers headers
3248               gnus-newsgroup-data data
3249               gnus-article-current gac
3250               gnus-summary-buffer summary
3251               gnus-article-buffer article-buffer
3252               gnus-original-article-buffer original
3253               gnus-reffed-article-number reffed
3254               gnus-current-score-file score-file
3255               gnus-newsgroup-charset default-charset)
3256         (let ((locals gnus-newsgroup-variables))
3257           (while locals
3258             (if (consp (car locals))
3259                 (set (caar locals) (pop vlist))
3260               (set (car locals) (pop vlist)))
3261             (setq locals (cdr locals))))
3262         ;; The article buffer also has local variables.
3263         (when (gnus-buffer-live-p gnus-article-buffer)
3264           (set-buffer gnus-article-buffer)
3265           (setq gnus-summary-buffer summary))))))
3266
3267 (defun gnus-summary-article-unread-p (article)
3268   "Say whether ARTICLE is unread or not."
3269   (memq article gnus-newsgroup-unreads))
3270
3271 (defun gnus-summary-first-article-p (&optional article)
3272   "Return whether ARTICLE is the first article in the buffer."
3273   (if (not (setq article (or article (gnus-summary-article-number))))
3274       nil
3275     (eq article (caar gnus-newsgroup-data))))
3276
3277 (defun gnus-summary-last-article-p (&optional article)
3278   "Return whether ARTICLE is the last article in the buffer."
3279   (if (not (setq article (or article (gnus-summary-article-number))))
3280       ;; All non-existent numbers are the last article.  :-)
3281       t
3282     (not (cdr (gnus-data-find-list article)))))
3283
3284 (defun gnus-make-thread-indent-array ()
3285   (let ((n 200))
3286     (unless (and gnus-thread-indent-array
3287                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3288       (setq gnus-thread-indent-array (make-vector 201 "")
3289             gnus-thread-indent-array-level gnus-thread-indent-level)
3290       (while (>= n 0)
3291         (aset gnus-thread-indent-array n
3292               (make-string (* n gnus-thread-indent-level) ? ))
3293         (setq n (1- n))))))
3294
3295 (defun gnus-update-summary-mark-positions ()
3296   "Compute where the summary marks are to go."
3297   (save-excursion
3298     (when (gnus-buffer-exists-p gnus-summary-buffer)
3299       (set-buffer gnus-summary-buffer))
3300     (let ((spec gnus-summary-line-format-spec)
3301           pos)
3302       (save-excursion
3303         (gnus-set-work-buffer)
3304         (let ((gnus-tmp-unread ?Z)
3305               (gnus-replied-mark ?Z)
3306               (gnus-score-below-mark ?Z)
3307               (gnus-score-over-mark ?Z)
3308               (gnus-undownloaded-mark ?Z)
3309               (gnus-summary-line-format-spec spec)
3310               (gnus-newsgroup-downloadable '(0))
3311               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3312               case-fold-search ignores)
3313           ;; Here, all marks are bound to Z.
3314           (gnus-summary-insert-line header
3315                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3316           (goto-char (point-min))
3317           ;; Memorize the positions of the same characters as dummy marks.
3318           (while (re-search-forward "[A-D]" nil t)
3319             (push (point) ignores))
3320           (erase-buffer)
3321           ;; We use A-D as dummy marks in order to know column positions
3322           ;; where marks should be inserted.
3323           (setq gnus-tmp-unread ?A
3324                 gnus-replied-mark ?B
3325                 gnus-score-below-mark ?C
3326                 gnus-score-over-mark ?C
3327                 gnus-undownloaded-mark ?D)
3328           (gnus-summary-insert-line header
3329                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3330           ;; Ignore characters which aren't dummy marks.
3331           (dolist (p ignores)
3332             (delete-region (goto-char (1- p)) p)
3333             (insert ?Z))
3334           (goto-char (point-min))
3335           (setq pos (list (cons 'unread
3336                                 (and (search-forward "A" nil t)
3337                                      (- (point) (point-min) 1)))))
3338           (goto-char (point-min))
3339           (push (cons 'replied (and (search-forward "B" nil t)
3340                                     (- (point) (point-min) 1)))
3341                 pos)
3342           (goto-char (point-min))
3343           (push (cons 'score (and (search-forward "C" nil t)
3344                                   (- (point) (point-min) 1)))
3345                 pos)
3346           (goto-char (point-min))
3347           (push (cons 'download (and (search-forward "D" nil t)
3348                                      (- (point) (point-min) 1)))
3349                 pos)))
3350       (setq gnus-summary-mark-positions pos))))
3351
3352 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3353   "Insert a dummy root in the summary buffer."
3354   (beginning-of-line)
3355   (gnus-add-text-properties
3356    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3357    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3358
3359 (defun gnus-summary-extract-address-component (from)
3360   (or (car (funcall gnus-extract-address-components from))
3361       from))
3362
3363 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3364   (let ((mail-parse-charset gnus-newsgroup-charset)
3365         ; Is it really necessary to do this next part for each summary line?
3366         ; Luckily, doesn't seem to slow things down much.
3367         (mail-parse-ignored-charsets
3368          (with-current-buffer gnus-summary-buffer
3369            gnus-newsgroup-ignored-charsets)))
3370     (or
3371      (and gnus-ignored-from-addresses
3372           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3373           (let ((extra-headers (mail-header-extra header))
3374                 to
3375                 newsgroups)
3376             (cond
3377              ((setq to (cdr (assq 'To extra-headers)))
3378               (concat "-> "
3379                       (inline
3380                         (gnus-summary-extract-address-component
3381                          (funcall gnus-decode-encoded-word-function to)))))
3382              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3383               (concat "=> " newsgroups)))))
3384      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3385
3386 (defun gnus-summary-insert-line (gnus-tmp-header
3387                                  gnus-tmp-level gnus-tmp-current
3388                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3389                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3390                                  &optional gnus-tmp-dummy gnus-tmp-score
3391                                  gnus-tmp-process)
3392   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3393          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3394          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3395          (gnus-tmp-score-char
3396           (if (or (null gnus-summary-default-score)
3397                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3398                       gnus-summary-zcore-fuzz))
3399               ?                         ;Whitespace
3400             (if (< gnus-tmp-score gnus-summary-default-score)
3401                 gnus-score-below-mark gnus-score-over-mark)))
3402          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3403          (gnus-tmp-replied
3404           (cond (gnus-tmp-process gnus-process-mark)
3405                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3406                  gnus-cached-mark)
3407                 (gnus-tmp-replied gnus-replied-mark)
3408                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3409                  gnus-forwarded-mark)
3410                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3411                  gnus-saved-mark)
3412                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3413                  gnus-recent-mark)
3414                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3415                  gnus-unseen-mark)
3416                 (t gnus-no-mark)))
3417          (gnus-tmp-downloaded
3418           (cond (undownloaded
3419                  gnus-undownloaded-mark)
3420                 (gnus-newsgroup-agentized
3421                  gnus-downloaded-mark)
3422                 (t
3423                  gnus-no-mark)))
3424          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3425          (gnus-tmp-name
3426           (cond
3427            ((string-match "<[^>]+> *$" gnus-tmp-from)
3428             (let ((beg (match-beginning 0)))
3429               (or (and (string-match "^\".+\"" gnus-tmp-from)
3430                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3431                   (substring gnus-tmp-from 0 beg))))
3432            ((string-match "(.+)" gnus-tmp-from)
3433             (substring gnus-tmp-from
3434                        (1+ (match-beginning 0)) (1- (match-end 0))))
3435            (t gnus-tmp-from)))
3436          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3437          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3438          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3439          (buffer-read-only nil))
3440     (when (string= gnus-tmp-name "")
3441       (setq gnus-tmp-name gnus-tmp-from))
3442     (unless (numberp gnus-tmp-lines)
3443       (setq gnus-tmp-lines -1))
3444     (if (= gnus-tmp-lines -1)
3445         (setq gnus-tmp-lines "?")
3446       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3447       (gnus-put-text-property
3448      (point)
3449      (progn (eval gnus-summary-line-format-spec) (point))
3450        'gnus-number gnus-tmp-number)
3451     (when (gnus-visual-p 'summary-highlight 'highlight)
3452       (forward-line -1)
3453       (gnus-run-hooks 'gnus-summary-update-hook)
3454       (forward-line 1))))
3455
3456 (defun gnus-summary-update-line (&optional dont-update)
3457   "Update summary line after change."
3458   (when (and gnus-summary-default-score
3459              (not gnus-summary-inhibit-highlight))
3460     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3461            (article (gnus-summary-article-number))
3462            (score (gnus-summary-article-score article)))
3463       (unless dont-update
3464         (if (and gnus-summary-mark-below
3465                  (< (gnus-summary-article-score)
3466                     gnus-summary-mark-below))
3467             ;; This article has a low score, so we mark it as read.
3468             (when (memq article gnus-newsgroup-unreads)
3469               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3470           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3471             ;; This article was previously marked as read on account
3472             ;; of a low score, but now it has risen, so we mark it as
3473             ;; unread.
3474             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3475         (gnus-summary-update-mark
3476          (if (or (null gnus-summary-default-score)
3477                  (<= (abs (- score gnus-summary-default-score))
3478                      gnus-summary-zcore-fuzz))
3479              ?                          ;Whitespace
3480            (if (< score gnus-summary-default-score)
3481                gnus-score-below-mark gnus-score-over-mark))
3482          'score))
3483       ;; Do visual highlighting.
3484       (when (gnus-visual-p 'summary-highlight 'highlight)
3485         (gnus-run-hooks 'gnus-summary-update-hook)))))
3486
3487 (defvar gnus-tmp-new-adopts nil)
3488
3489 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3490   "Return the number of articles in THREAD.
3491 This may be 0 in some cases -- if none of the articles in
3492 the thread are to be displayed."
3493   (let* ((number
3494          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3495           (cond
3496            ((not (listp thread))
3497             1)
3498            ((and (consp thread) (cdr thread))
3499             (apply
3500              '+ 1 (mapcar
3501                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3502            ((null thread)
3503             1)
3504            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3505             1)
3506            (t 0))))
3507     (when (and level (zerop level) gnus-tmp-new-adopts)
3508       (incf number
3509             (apply '+ (mapcar
3510                        'gnus-summary-number-of-articles-in-thread
3511                        gnus-tmp-new-adopts))))
3512     (if char
3513         (if (> number 1) gnus-not-empty-thread-mark
3514           gnus-empty-thread-mark)
3515       number)))
3516
3517 (defsubst gnus-summary-line-message-size (head)
3518   "Return pretty-printed version of message size.
3519 This function is intended to be used in
3520 `gnus-summary-line-format-alist'."
3521   (let ((c (or (mail-header-chars head) -1)))
3522     (cond ((< c 0) "n/a")               ; chars not available
3523           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3524           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3525           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3526           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3527
3528
3529 (defun gnus-summary-set-local-parameters (group)
3530   "Go through the local params of GROUP and set all variable specs in that list."
3531   (let ((vars '(quit-config)))          ; Ignore quit-config.
3532     (dolist (elem (gnus-group-find-parameter group))
3533       (and (consp elem)                 ; Has to be a cons.
3534            (consp (cdr elem))           ; The cdr has to be a list.
3535            (symbolp (car elem))         ; Has to be a symbol in there.
3536            (not (memq (car elem) vars))
3537            (ignore-errors               ; So we set it.
3538              (push (car elem) vars)
3539              (make-local-variable (car elem))
3540              (set (car elem) (eval (nth 1 elem))))))))
3541
3542 (defun gnus-summary-read-group (group &optional show-all no-article
3543                                       kill-buffer no-display backward
3544                                       select-articles)
3545   "Start reading news in newsgroup GROUP.
3546 If SHOW-ALL is non-nil, already read articles are also listed.
3547 If NO-ARTICLE is non-nil, no article is selected initially.
3548 If NO-DISPLAY, don't generate a summary buffer."
3549   (let (result)
3550     (while (and group
3551                 (null (setq result
3552                             (let ((gnus-auto-select-next nil))
3553                               (or (gnus-summary-read-group-1
3554                                    group show-all no-article
3555                                    kill-buffer no-display
3556                                    select-articles)
3557                                   (setq show-all nil
3558                                         select-articles nil)))))
3559                 (eq gnus-auto-select-next 'quietly))
3560       (set-buffer gnus-group-buffer)
3561       ;; The entry function called above goes to the next
3562       ;; group automatically, so we go two groups back
3563       ;; if we are searching for the previous group.
3564       (when backward
3565         (gnus-group-prev-unread-group 2))
3566       (if (not (equal group (gnus-group-group-name)))
3567           (setq group (gnus-group-group-name))
3568         (setq group nil)))
3569     result))
3570
3571 (defun gnus-summary-read-group-1 (group show-all no-article
3572                                         kill-buffer no-display
3573                                         &optional select-articles)
3574   ;; Killed foreign groups can't be entered.
3575   ;;  (when (and (not (gnus-group-native-p group))
3576   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3577   ;;    (error "Dead non-native groups can't be entered"))
3578   (gnus-message 5 "Retrieving newsgroup: %s..."
3579                 (gnus-group-decoded-name group))
3580   (let* ((new-group (gnus-summary-setup-buffer group))
3581          (quit-config (gnus-group-quit-config group))
3582          (did-select (and new-group (gnus-select-newsgroup
3583                                      group show-all select-articles))))
3584     (cond
3585      ;; This summary buffer exists already, so we just select it.
3586      ((not new-group)
3587       (gnus-set-global-variables)
3588       (when kill-buffer
3589         (gnus-kill-or-deaden-summary kill-buffer))
3590       (gnus-configure-windows 'summary 'force)
3591       (gnus-set-mode-line 'summary)
3592       (gnus-summary-position-point)
3593       (message "")
3594       t)
3595      ;; We couldn't select this group.
3596      ((null did-select)
3597       (when (and (eq major-mode 'gnus-summary-mode)
3598                  (not (equal (current-buffer) kill-buffer)))
3599         (kill-buffer (current-buffer))
3600         (if (not quit-config)
3601             (progn
3602               ;; Update the info -- marks might need to be removed,
3603               ;; for instance.
3604               (gnus-summary-update-info)
3605               (set-buffer gnus-group-buffer)
3606               (gnus-group-jump-to-group group)
3607               (gnus-group-next-unread-group 1))
3608           (gnus-handle-ephemeral-exit quit-config)))
3609       (let ((grpinfo (gnus-get-info group)))
3610         (if (null (gnus-info-read grpinfo))
3611             (gnus-message 3 "Group %s contains no messages"
3612                           (gnus-group-decoded-name group))
3613           (gnus-message 3 "Can't select group")))
3614       nil)
3615      ;; The user did a `C-g' while prompting for number of articles,
3616      ;; so we exit this group.
3617      ((eq did-select 'quit)
3618       (and (eq major-mode 'gnus-summary-mode)
3619            (not (equal (current-buffer) kill-buffer))
3620            (kill-buffer (current-buffer)))
3621       (when kill-buffer
3622         (gnus-kill-or-deaden-summary kill-buffer))
3623       (if (not quit-config)
3624           (progn
3625             (set-buffer gnus-group-buffer)
3626             (gnus-group-jump-to-group group)
3627             (gnus-group-next-unread-group 1)
3628             (gnus-configure-windows 'group 'force))
3629         (gnus-handle-ephemeral-exit quit-config))
3630       ;; Finally signal the quit.
3631       (signal 'quit nil))
3632      ;; The group was successfully selected.
3633      (t
3634       (gnus-set-global-variables)
3635       ;; Save the active value in effect when the group was entered.
3636       (setq gnus-newsgroup-active
3637             (gnus-copy-sequence
3638              (gnus-active gnus-newsgroup-name)))
3639       ;; You can change the summary buffer in some way with this hook.
3640       (gnus-run-hooks 'gnus-select-group-hook)
3641       (when (memq 'summary (gnus-update-format-specifications
3642                             nil 'summary 'summary-mode 'summary-dummy))
3643         ;; The format specification for the summary line was updated,
3644         ;; so we need to update the mark positions as well.
3645         (gnus-update-summary-mark-positions))
3646       ;; Do score processing.
3647       (when gnus-use-scoring
3648         (gnus-possibly-score-headers))
3649       ;; Check whether to fill in the gaps in the threads.
3650       (when gnus-build-sparse-threads
3651         (gnus-build-sparse-threads))
3652       ;; Find the initial limit.
3653       (if show-all
3654           (let ((gnus-newsgroup-dormant nil))
3655             (gnus-summary-initial-limit show-all))
3656         (gnus-summary-initial-limit show-all))
3657       ;; Generate the summary buffer.
3658       (unless no-display
3659         (gnus-summary-prepare))
3660       (when gnus-use-trees
3661         (gnus-tree-open group)
3662         (setq gnus-summary-highlight-line-function
3663               'gnus-tree-highlight-article))
3664       ;; If the summary buffer is empty, but there are some low-scored
3665       ;; articles or some excluded dormants, we include these in the
3666       ;; buffer.
3667       (when (and (zerop (buffer-size))
3668                  (not no-display))
3669         (cond (gnus-newsgroup-dormant
3670                (gnus-summary-limit-include-dormant))
3671               ((and gnus-newsgroup-scored show-all)
3672                (gnus-summary-limit-include-expunged t))))
3673       ;; Function `gnus-apply-kill-file' must be called in this hook.
3674       (gnus-run-hooks 'gnus-apply-kill-hook)
3675       (if (and (zerop (buffer-size))
3676                (not no-display))
3677           (progn
3678             ;; This newsgroup is empty.
3679             (gnus-summary-catchup-and-exit nil t)
3680             (gnus-message 6 "No unread news")
3681             (when kill-buffer
3682               (gnus-kill-or-deaden-summary kill-buffer))
3683             ;; Return nil from this function.
3684             nil)
3685         ;; Hide conversation thread subtrees.  We cannot do this in
3686         ;; gnus-summary-prepare-hook since kill processing may not
3687         ;; work with hidden articles.
3688         (gnus-summary-maybe-hide-threads)
3689         (when kill-buffer
3690           (gnus-kill-or-deaden-summary kill-buffer))
3691         (gnus-summary-auto-select-subject)
3692         ;; Show first unread article if requested.
3693         (if (and (not no-article)
3694                  (not no-display)
3695                  gnus-newsgroup-unreads
3696                  gnus-auto-select-first)
3697             (progn
3698               (gnus-configure-windows 'summary)
3699               (let ((art (gnus-summary-article-number)))
3700                 (unless (and (not gnus-plugged)
3701                              (or (memq art gnus-newsgroup-undownloaded)
3702                                  (memq art gnus-newsgroup-downloadable)))
3703                   (gnus-summary-goto-article art))))
3704           ;; Don't select any articles.
3705           (gnus-summary-position-point)
3706           (gnus-configure-windows 'summary 'force)
3707           (gnus-set-mode-line 'summary))
3708         (when (and gnus-auto-center-group
3709                    (get-buffer-window gnus-group-buffer t))
3710           ;; Gotta use windows, because recenter does weird stuff if
3711           ;; the current buffer ain't the displayed window.
3712           (let ((owin (selected-window)))
3713             (select-window (get-buffer-window gnus-group-buffer t))
3714             (when (gnus-group-goto-group group)
3715               (recenter))
3716             (select-window owin)))
3717         ;; Mark this buffer as "prepared".
3718         (setq gnus-newsgroup-prepared t)
3719         (gnus-run-hooks 'gnus-summary-prepared-hook)
3720         (unless (gnus-ephemeral-group-p group)
3721           (gnus-group-update-group group))
3722         t)))))
3723
3724 (defun gnus-summary-auto-select-subject ()
3725   "Select the subject line on initial group entry."
3726   (goto-char (point-min))
3727   (cond
3728    ((eq gnus-auto-select-subject 'best)
3729     (gnus-summary-best-unread-subject))
3730    ((eq gnus-auto-select-subject 'unread)
3731     (gnus-summary-first-unread-subject))
3732    ((eq gnus-auto-select-subject 'unseen)
3733     (gnus-summary-first-unseen-subject))
3734    ((eq gnus-auto-select-subject 'unseen-or-unread)
3735     (gnus-summary-first-unseen-or-unread-subject))
3736    ((eq gnus-auto-select-subject 'first)
3737     ;; Do nothing.
3738     )
3739    ((functionp gnus-auto-select-subject)
3740     (funcall gnus-auto-select-subject))))
3741
3742 (defun gnus-summary-prepare ()
3743   "Generate the summary buffer."
3744   (interactive)
3745   (let ((buffer-read-only nil))
3746     (erase-buffer)
3747     (setq gnus-newsgroup-data nil
3748           gnus-newsgroup-data-reverse nil)
3749     (gnus-run-hooks 'gnus-summary-generate-hook)
3750     ;; Generate the buffer, either with threads or without.
3751     (when gnus-newsgroup-headers
3752       (gnus-summary-prepare-threads
3753        (if gnus-show-threads
3754            (gnus-sort-gathered-threads
3755             (funcall gnus-summary-thread-gathering-function
3756                      (gnus-sort-threads
3757                       (gnus-cut-threads (gnus-make-threads)))))
3758          ;; Unthreaded display.
3759          (gnus-sort-articles gnus-newsgroup-headers))))
3760     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3761     ;; Call hooks for modifying summary buffer.
3762     (goto-char (point-min))
3763     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3764
3765 (defsubst gnus-general-simplify-subject (subject)
3766   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3767   (setq subject
3768         (cond
3769          ;; Truncate the subject.
3770          (gnus-simplify-subject-functions
3771           (gnus-map-function gnus-simplify-subject-functions subject))
3772          ((numberp gnus-summary-gather-subject-limit)
3773           (setq subject (gnus-simplify-subject-re subject))
3774           (if (> (length subject) gnus-summary-gather-subject-limit)
3775               (substring subject 0 gnus-summary-gather-subject-limit)
3776             subject))
3777          ;; Fuzzily simplify it.
3778          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3779           (gnus-simplify-subject-fuzzy subject))
3780          ;; Just remove the leading "Re:".
3781          (t
3782           (gnus-simplify-subject-re subject))))
3783
3784   (if (and gnus-summary-gather-exclude-subject
3785            (string-match gnus-summary-gather-exclude-subject subject))
3786       nil                         ; This article shouldn't be gathered
3787     subject))
3788
3789 (defun gnus-summary-simplify-subject-query ()
3790   "Query where the respool algorithm would put this article."
3791   (interactive)
3792   (gnus-summary-select-article)
3793   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3794
3795 (defun gnus-gather-threads-by-subject (threads)
3796   "Gather threads by looking at Subject headers."
3797   (if (not gnus-summary-make-false-root)
3798       threads
3799     (let ((hashtb (gnus-make-hashtable 1024))
3800           (prev threads)
3801           (result threads)
3802           subject hthread whole-subject)
3803       (while threads
3804         (setq subject (gnus-general-simplify-subject
3805                        (setq whole-subject (mail-header-subject
3806                                             (caar threads)))))
3807         (when subject
3808           (if (setq hthread (gnus-gethash subject hashtb))
3809               (progn
3810                 ;; We enter a dummy root into the thread, if we
3811                 ;; haven't done that already.
3812                 (unless (stringp (caar hthread))
3813                   (setcar hthread (list whole-subject (car hthread))))
3814                 ;; We add this new gathered thread to this gathered
3815                 ;; thread.
3816                 (setcdr (car hthread)
3817                         (nconc (cdar hthread) (list (car threads))))
3818                 ;; Remove it from the list of threads.
3819                 (setcdr prev (cdr threads))
3820                 (setq threads prev))
3821             ;; Enter this thread into the hash table.
3822             (gnus-sethash subject
3823                           (if gnus-summary-make-false-root-always
3824                               (progn
3825                                 ;; If you want a dummy root above all
3826                                 ;; threads...
3827                                 (setcar threads (list whole-subject
3828                                                       (car threads)))
3829                                 threads)
3830                             threads)
3831                           hashtb)))
3832         (setq prev threads)
3833         (setq threads (cdr threads)))
3834       result)))
3835
3836 (defun gnus-gather-threads-by-references (threads)
3837   "Gather threads by looking at References headers."
3838   (let ((idhashtb (gnus-make-hashtable 1024))
3839         (thhashtb (gnus-make-hashtable 1024))
3840         (prev threads)
3841         (result threads)
3842         ids references id gthread gid entered ref)
3843     (while threads
3844       (when (setq references (mail-header-references (caar threads)))
3845         (setq id (mail-header-id (caar threads))
3846               ids (inline (gnus-split-references references))
3847               entered nil)
3848         (while (setq ref (pop ids))
3849           (setq ids (delete ref ids))
3850           (if (not (setq gid (gnus-gethash ref idhashtb)))
3851               (progn
3852                 (gnus-sethash ref id idhashtb)
3853                 (gnus-sethash id threads thhashtb))
3854             (setq gthread (gnus-gethash gid thhashtb))
3855             (unless entered
3856               ;; We enter a dummy root into the thread, if we
3857               ;; haven't done that already.
3858               (unless (stringp (caar gthread))
3859                 (setcar gthread (list (mail-header-subject (caar gthread))
3860                                       (car gthread))))
3861               ;; We add this new gathered thread to this gathered
3862               ;; thread.
3863               (setcdr (car gthread)
3864                       (nconc (cdar gthread) (list (car threads)))))
3865             ;; Add it into the thread hash table.
3866             (gnus-sethash id gthread thhashtb)
3867             (setq entered t)
3868             ;; Remove it from the list of threads.
3869             (setcdr prev (cdr threads))
3870             (setq threads prev))))
3871       (setq prev threads)
3872       (setq threads (cdr threads)))
3873     result))
3874
3875 (defun gnus-sort-gathered-threads (threads)
3876   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3877   (let ((result threads))
3878     (while threads
3879       (when (stringp (caar threads))
3880         (setcdr (car threads)
3881                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3882       (setq threads (cdr threads)))
3883     result))
3884
3885 (defun gnus-thread-loop-p (root thread)
3886   "Say whether ROOT is in THREAD."
3887   (let ((stack (list thread))
3888         (infloop 0)
3889         th)
3890     (while (setq thread (pop stack))
3891       (setq th (cdr thread))
3892       (while (and th
3893                   (not (eq (caar th) root)))
3894         (pop th))
3895       (if th
3896           ;; We have found a loop.
3897           (let (ref-dep)
3898             (setcdr thread (delq (car th) (cdr thread)))
3899             (if (boundp (setq ref-dep (intern "none"
3900                                               gnus-newsgroup-dependencies)))
3901                 (setcdr (symbol-value ref-dep)
3902                         (nconc (cdr (symbol-value ref-dep))
3903                                (list (car th))))
3904               (set ref-dep (list nil (car th))))
3905             (setq infloop 1
3906                   stack nil))
3907         ;; Push all the subthreads onto the stack.
3908         (push (cdr thread) stack)))
3909     infloop))
3910
3911 (defun gnus-make-threads ()
3912   "Go through the dependency hashtb and find the roots.  Return all threads."
3913   (let (threads)
3914     (while (catch 'infloop
3915              (mapatoms
3916               (lambda (refs)
3917                 ;; Deal with self-referencing References loops.
3918                 (when (and (car (symbol-value refs))
3919                            (not (zerop
3920                                  (apply
3921                                   '+
3922                                   (mapcar
3923                                    (lambda (thread)
3924                                      (gnus-thread-loop-p
3925                                       (car (symbol-value refs)) thread))
3926                                    (cdr (symbol-value refs)))))))
3927                   (setq threads nil)
3928                   (throw 'infloop t))
3929                 (unless (car (symbol-value refs))
3930                   ;; These threads do not refer back to any other
3931                   ;; articles, so they're roots.
3932                   (setq threads (append (cdr (symbol-value refs)) threads))))
3933               gnus-newsgroup-dependencies)))
3934     threads))
3935
3936 ;; Build the thread tree.
3937 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3938   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3939
3940 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3941 if it was already present.
3942
3943 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3944 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3945 Message-IDs will be renamed to a unique Message-ID before being
3946 entered.
3947
3948 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3949   (let* ((id (mail-header-id header))
3950          (id-dep (and id (intern id dependencies)))
3951          parent-id ref ref-dep ref-header replaced)
3952     ;; Enter this `header' in the `dependencies' table.
3953     (cond
3954      ((not id-dep)
3955       (setq header nil))
3956      ;; The first two cases do the normal part: enter a new `header'
3957      ;; in the `dependencies' table.
3958      ((not (boundp id-dep))
3959       (set id-dep (list header)))
3960      ((null (car (symbol-value id-dep)))
3961       (setcar (symbol-value id-dep) header))
3962
3963      ;; From here the `header' was already present in the
3964      ;; `dependencies' table.
3965      (force-new
3966       ;; Overrides an existing entry;
3967       ;; just set the header part of the entry.
3968       (setcar (symbol-value id-dep) header)
3969       (setq replaced t))
3970
3971      ;; Renames the existing `header' to a unique Message-ID.
3972      ((not gnus-summary-ignore-duplicates)
3973       ;; An article with this Message-ID has already been seen.
3974       ;; We rename the Message-ID.
3975       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3976            (list header))
3977       (mail-header-set-id header id))
3978
3979      ;; The last case ignores an existing entry, except it adds any
3980      ;; additional Xrefs (in case the two articles came from different
3981      ;; servers.
3982      ;; Also sets `header' to `nil' meaning that the `dependencies'
3983      ;; table was *not* modified.
3984      (t
3985       (mail-header-set-xref
3986        (car (symbol-value id-dep))
3987        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3988                    "")
3989                (or (mail-header-xref header) "")))
3990       (setq header nil)))
3991
3992     (when (and header (not replaced))
3993       ;; First check that we are not creating a References loop.
3994       (setq parent-id (gnus-parent-id (mail-header-references header)))
3995       (setq ref parent-id)
3996       (while (and ref
3997                   (setq ref-dep (intern-soft ref dependencies))
3998                   (boundp ref-dep)
3999                   (setq ref-header (car (symbol-value ref-dep))))
4000         (if (string= id ref)
4001             ;; Yuk!  This is a reference loop.  Make the article be a
4002             ;; root article.
4003             (progn
4004               (mail-header-set-references (car (symbol-value id-dep)) "none")
4005               (setq ref nil)
4006               (setq parent-id nil))
4007           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4008       (setq ref-dep (intern (or parent-id "none") dependencies))
4009       (if (boundp ref-dep)
4010           (setcdr (symbol-value ref-dep)
4011                   (nconc (cdr (symbol-value ref-dep))
4012                          (list (symbol-value id-dep))))
4013         (set ref-dep (list nil (symbol-value id-dep)))))
4014     header))
4015
4016 (defun gnus-extract-message-id-from-in-reply-to (string)
4017   (if (string-match "<[^>]+>" string)
4018       (substring string (match-beginning 0) (match-end 0))
4019     nil))
4020
4021 (defun gnus-build-sparse-threads ()
4022   (let ((headers gnus-newsgroup-headers)
4023         (mail-parse-charset gnus-newsgroup-charset)
4024         (gnus-summary-ignore-duplicates t)
4025         header references generation relations
4026         subject child end new-child date)
4027     ;; First we create an alist of generations/relations, where
4028     ;; generations is how much we trust the relation, and the relation
4029     ;; is parent/child.
4030     (gnus-message 7 "Making sparse threads...")
4031     (save-excursion
4032       (nnheader-set-temp-buffer " *gnus sparse threads*")
4033       (while (setq header (pop headers))
4034         (when (and (setq references (mail-header-references header))
4035                    (not (string= references "")))
4036           (insert references)
4037           (setq child (mail-header-id header)
4038                 subject (mail-header-subject header)
4039                 date (mail-header-date header)
4040                 generation 0)
4041           (while (search-backward ">" nil t)
4042             (setq end (1+ (point)))
4043             (when (search-backward "<" nil t)
4044               (setq new-child (buffer-substring (point) end))
4045               (push (list (incf generation)
4046                           child (setq child new-child)
4047                           subject date)
4048                     relations)))
4049           (when child
4050             (push (list (1+ generation) child nil subject) relations))
4051           (erase-buffer)))
4052       (kill-buffer (current-buffer)))
4053     ;; Sort over trustworthiness.
4054     (mapcar
4055      (lambda (relation)
4056        (when (gnus-dependencies-add-header
4057               (make-full-mail-header
4058                gnus-reffed-article-number
4059                (nth 3 relation) "" (or (nth 4 relation) "")
4060                (nth 1 relation)
4061                (or (nth 2 relation) "") 0 0 "")
4062               gnus-newsgroup-dependencies nil)
4063          (push gnus-reffed-article-number gnus-newsgroup-limit)
4064          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4065          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4066                gnus-newsgroup-reads)
4067          (decf gnus-reffed-article-number)))
4068      (sort relations 'car-less-than-car))
4069     (gnus-message 7 "Making sparse threads...done")))
4070
4071 (defun gnus-build-old-threads ()
4072   ;; Look at all the articles that refer back to old articles, and
4073   ;; fetch the headers for the articles that aren't there.  This will
4074   ;; build complete threads - if the roots haven't been expired by the
4075   ;; server, that is.
4076   (let ((mail-parse-charset gnus-newsgroup-charset)
4077         id heads)
4078     (mapatoms
4079      (lambda (refs)
4080        (when (not (car (symbol-value refs)))
4081          (setq heads (cdr (symbol-value refs)))
4082          (while heads
4083            (if (memq (mail-header-number (caar heads))
4084                      gnus-newsgroup-dormant)
4085                (setq heads (cdr heads))
4086              (setq id (symbol-name refs))
4087              (while (and (setq id (gnus-build-get-header id))
4088                          (not (car (gnus-id-to-thread id)))))
4089              (setq heads nil)))))
4090      gnus-newsgroup-dependencies)))
4091
4092 (defsubst gnus-remove-odd-characters (string)
4093   "Translate STRING into something that doesn't contain weird characters."
4094   (mm-subst-char-in-string
4095    ?\r ?\-
4096    (mm-subst-char-in-string ?\n ?\- string t) t))
4097
4098 ;; This function has to be called with point after the article number
4099 ;; on the beginning of the line.
4100 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4101   (let ((eol (point-at-eol))
4102         (buffer (current-buffer))
4103         header references in-reply-to)
4104
4105     ;; overview: [num subject from date id refs chars lines misc]
4106     (unwind-protect
4107         (let (x)
4108           (narrow-to-region (point) eol)
4109           (unless (eobp)
4110             (forward-char))
4111
4112           (setq header
4113                 (make-full-mail-header
4114                  number                 ; number
4115                  (condition-case ()     ; subject
4116                      (gnus-remove-odd-characters
4117                       (funcall gnus-decode-encoded-word-function
4118                                (setq x (nnheader-nov-field))))
4119                    (error x))
4120                  (condition-case ()     ; from
4121                      (gnus-remove-odd-characters
4122                       (funcall gnus-decode-encoded-word-function
4123                                (setq x (nnheader-nov-field))))
4124                    (error x))
4125                  (nnheader-nov-field)   ; date
4126                  (nnheader-nov-read-message-id number)  ; id
4127                  (setq references (nnheader-nov-field)) ; refs
4128                  (nnheader-nov-read-integer) ; chars
4129                  (nnheader-nov-read-integer) ; lines
4130                  (unless (eobp)
4131                    (if (looking-at "Xref: ")
4132                        (goto-char (match-end 0)))
4133                    (nnheader-nov-field)) ; Xref
4134                  (nnheader-nov-parse-extra)))) ; extra
4135
4136       (widen))
4137
4138     (when (and (string= references "")
4139                (setq in-reply-to (mail-header-extra header))
4140                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4141       (mail-header-set-references
4142        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4143
4144     (when gnus-alter-header-function
4145       (funcall gnus-alter-header-function header))
4146     (gnus-dependencies-add-header header dependencies force-new)))
4147
4148 (defun gnus-build-get-header (id)
4149   "Look through the buffer of NOV lines and find the header to ID.
4150 Enter this line into the dependencies hash table, and return
4151 the id of the parent article (if any)."
4152   (let ((deps gnus-newsgroup-dependencies)
4153         found header)
4154     (prog1
4155         (save-excursion
4156           (set-buffer nntp-server-buffer)
4157           (let ((case-fold-search nil))
4158             (goto-char (point-min))
4159             (while (and (not found)
4160                         (search-forward id nil t))
4161               (beginning-of-line)
4162               (setq found (looking-at
4163                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4164                                    (regexp-quote id))))
4165               (or found (beginning-of-line 2)))
4166             (when found
4167               (beginning-of-line)
4168               (and
4169                (setq header (gnus-nov-parse-line
4170                              (read (current-buffer)) deps))
4171                (gnus-parent-id (mail-header-references header))))))
4172       (when header
4173         (let ((number (mail-header-number header)))
4174           (push number gnus-newsgroup-limit)
4175           (push header gnus-newsgroup-headers)
4176           (if (memq number gnus-newsgroup-unselected)
4177               (progn
4178                 (setq gnus-newsgroup-unreads
4179                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4180                                                number))
4181                 (setq gnus-newsgroup-unselected
4182                       (delq number gnus-newsgroup-unselected)))
4183             (push number gnus-newsgroup-ancient)))))))
4184
4185 (defun gnus-build-all-threads ()
4186   "Read all the headers."
4187   (let ((gnus-summary-ignore-duplicates t)
4188         (mail-parse-charset gnus-newsgroup-charset)
4189         (dependencies gnus-newsgroup-dependencies)
4190         header article)
4191     (save-excursion
4192       (set-buffer nntp-server-buffer)
4193       (let ((case-fold-search nil))
4194         (goto-char (point-min))
4195         (while (not (eobp))
4196           (ignore-errors
4197             (setq article (read (current-buffer))
4198                   header (gnus-nov-parse-line article dependencies)))
4199           (when header
4200             (with-current-buffer gnus-summary-buffer
4201               (push header gnus-newsgroup-headers)
4202               (if (memq (setq article (mail-header-number header))
4203                         gnus-newsgroup-unselected)
4204                   (progn
4205                     (setq gnus-newsgroup-unreads
4206                           (gnus-add-to-sorted-list
4207                            gnus-newsgroup-unreads article))
4208                     (setq gnus-newsgroup-unselected
4209                           (delq article gnus-newsgroup-unselected)))
4210                 (push article gnus-newsgroup-ancient)))
4211             (forward-line 1)))))))
4212
4213 (defun gnus-summary-update-article-line (article header)
4214   "Update the line for ARTICLE using HEADER."
4215   (let* ((id (mail-header-id header))
4216          (thread (gnus-id-to-thread id)))
4217     (unless thread
4218       (error "Article in no thread"))
4219     ;; Update the thread.
4220     (setcar thread header)
4221     (gnus-summary-goto-subject article)
4222     (let* ((datal (gnus-data-find-list article))
4223            (data (car datal))
4224            (buffer-read-only nil)
4225            (level (gnus-summary-thread-level)))
4226       (gnus-delete-line)
4227       (let ((inserted (- (point)
4228                          (progn
4229                            (gnus-summary-insert-line
4230                             header level nil
4231                             (memq article gnus-newsgroup-undownloaded)
4232                             (gnus-article-mark article)
4233                             (memq article gnus-newsgroup-replied)
4234                             (memq article gnus-newsgroup-expirable)
4235                             ;; Only insert the Subject string when it's different
4236                             ;; from the previous Subject string.
4237                             (if (and
4238                                  gnus-show-threads
4239                                  (gnus-subject-equal
4240                                   (condition-case ()
4241                                       (mail-header-subject
4242                                        (gnus-data-header
4243                                         (cadr
4244                                          (gnus-data-find-list
4245                                           article
4246                                           (gnus-data-list t)))))
4247                                     ;; Error on the side of excessive subjects.
4248                                     (error ""))
4249                                   (mail-header-subject header)))
4250                                 ""
4251                               (mail-header-subject header))
4252                             nil (cdr (assq article gnus-newsgroup-scored))
4253                             (memq article gnus-newsgroup-processable))
4254                            (point)))))
4255         (when (cdr datal)
4256           (gnus-data-update-list
4257            (cdr datal)
4258            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4259
4260 (defun gnus-summary-update-article (article &optional iheader)
4261   "Update ARTICLE in the summary buffer."
4262   (set-buffer gnus-summary-buffer)
4263   (let* ((header (gnus-summary-article-header article))
4264          (id (mail-header-id header))
4265          (data (gnus-data-find article))
4266          (thread (gnus-id-to-thread id))
4267          (references (mail-header-references header))
4268          (parent
4269           (gnus-id-to-thread
4270            (or (gnus-parent-id
4271                 (when (and references
4272                            (not (equal "" references)))
4273                   references))
4274                "none")))
4275          (buffer-read-only nil)
4276          (old (car thread)))
4277     (when thread
4278       (unless iheader
4279         (setcar thread nil)
4280         (when parent
4281           (delq thread parent)))
4282       (if (gnus-summary-insert-subject id header)
4283           ;; Set the (possibly) new article number in the data structure.
4284           (gnus-data-set-number data (gnus-id-to-article id))
4285         (setcar thread old)
4286         nil))))
4287
4288 (defun gnus-rebuild-thread (id &optional line)
4289   "Rebuild the thread containing ID.
4290 If LINE, insert the rebuilt thread starting on line LINE."
4291   (let ((buffer-read-only nil)
4292         old-pos current thread data)
4293     (if (not gnus-show-threads)
4294         (setq thread (list (car (gnus-id-to-thread id))))
4295       ;; Get the thread this article is part of.
4296       (setq thread (gnus-remove-thread id)))
4297     (setq old-pos (point-at-bol))
4298     (setq current (save-excursion
4299                     (and (re-search-backward "[\r\n]" nil t)
4300                          (gnus-summary-article-number))))
4301     ;; If this is a gathered thread, we have to go some re-gathering.
4302     (when (stringp (car thread))
4303       (let ((subject (car thread))
4304             roots thr)
4305         (setq thread (cdr thread))
4306         (while thread
4307           (unless (memq (setq thr (gnus-id-to-thread
4308                                    (gnus-root-id
4309                                     (mail-header-id (caar thread)))))
4310                         roots)
4311             (push thr roots))
4312           (setq thread (cdr thread)))
4313         ;; We now have all (unique) roots.
4314         (if (= (length roots) 1)
4315             ;; All the loose roots are now one solid root.
4316             (setq thread (car roots))
4317           (setq thread (cons subject (gnus-sort-threads roots))))))
4318     (let (threads)
4319       ;; We then insert this thread into the summary buffer.
4320       (when line
4321         (goto-char (point-min))
4322         (forward-line (1- line)))
4323       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4324         (if gnus-show-threads
4325             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4326           (gnus-summary-prepare-unthreaded thread))
4327         (setq data (nreverse gnus-newsgroup-data))
4328         (setq threads gnus-newsgroup-threads))
4329       ;; We splice the new data into the data structure.
4330       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4331       ;;!!! then we want to insert at the beginning of the buffer.
4332       ;;!!! That happens to be true with Gnus now, but that may
4333       ;;!!! change in the future.  Perhaps.
4334       (gnus-data-enter-list
4335        (if line nil current) data (- (point) old-pos))
4336       (setq gnus-newsgroup-threads
4337             (nconc threads gnus-newsgroup-threads))
4338       (gnus-data-compute-positions))))
4339
4340 (defun gnus-number-to-header (number)
4341   "Return the header for article NUMBER."
4342   (let ((headers gnus-newsgroup-headers))
4343     (while (and headers
4344                 (not (= number (mail-header-number (car headers)))))
4345       (pop headers))
4346     (when headers
4347       (car headers))))
4348
4349 (defun gnus-parent-headers (in-headers &optional generation)
4350   "Return the headers of the GENERATIONeth parent of HEADERS."
4351   (unless generation
4352     (setq generation 1))
4353   (let ((parent t)
4354         (headers in-headers)
4355         references)
4356     (while (and parent
4357                 (not (zerop generation))
4358                 (setq references (mail-header-references headers)))
4359       (setq headers (if (and references
4360                              (setq parent (gnus-parent-id references)))
4361                         (car (gnus-id-to-thread parent))
4362                       nil))
4363       (decf generation))
4364     (and (not (eq headers in-headers))
4365          headers)))
4366
4367 (defun gnus-id-to-thread (id)
4368   "Return the (sub-)thread where ID appears."
4369   (gnus-gethash id gnus-newsgroup-dependencies))
4370
4371 (defun gnus-id-to-article (id)
4372   "Return the article number of ID."
4373   (let ((thread (gnus-id-to-thread id)))
4374     (when (and thread
4375                (car thread))
4376       (mail-header-number (car thread)))))
4377
4378 (defun gnus-id-to-header (id)
4379   "Return the article headers of ID."
4380   (car (gnus-id-to-thread id)))
4381
4382 (defun gnus-article-displayed-root-p (article)
4383   "Say whether ARTICLE is a root(ish) article."
4384   (let ((level (gnus-summary-thread-level article))
4385         (refs (mail-header-references  (gnus-summary-article-header article)))
4386         particle)
4387     (cond
4388      ((null level) nil)
4389      ((zerop level) t)
4390      ((null refs) t)
4391      ((null (gnus-parent-id refs)) t)
4392      ((and (= 1 level)
4393            (null (setq particle (gnus-id-to-article
4394                                  (gnus-parent-id refs))))
4395            (null (gnus-summary-thread-level particle)))))))
4396
4397 (defun gnus-root-id (id)
4398   "Return the id of the root of the thread where ID appears."
4399   (let (last-id prev)
4400     (while (and id (setq prev (car (gnus-id-to-thread id))))
4401       (setq last-id id
4402             id (gnus-parent-id (mail-header-references prev))))
4403     last-id))
4404
4405 (defun gnus-articles-in-thread (thread)
4406   "Return the list of articles in THREAD."
4407   (cons (mail-header-number (car thread))
4408         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4409
4410 (defun gnus-remove-thread (id &optional dont-remove)
4411   "Remove the thread that has ID in it."
4412   (let (headers thread last-id)
4413     ;; First go up in this thread until we find the root.
4414     (setq last-id (gnus-root-id id)
4415           headers (message-flatten-list (gnus-id-to-thread last-id)))
4416     ;; We have now found the real root of this thread.  It might have
4417     ;; been gathered into some loose thread, so we have to search
4418     ;; through the threads to find the thread we wanted.
4419     (let ((threads gnus-newsgroup-threads)
4420           sub)
4421       (while threads
4422         (setq sub (car threads))
4423         (if (stringp (car sub))
4424             ;; This is a gathered thread, so we look at the roots
4425             ;; below it to find whether this article is in this
4426             ;; gathered root.
4427             (progn
4428               (setq sub (cdr sub))
4429               (while sub
4430                 (when (member (caar sub) headers)
4431                   (setq thread (car threads)
4432                         threads nil
4433                         sub nil))
4434                 (setq sub (cdr sub))))
4435           ;; It's an ordinary thread, so we check it.
4436           (when (eq (car sub) (car headers))
4437             (setq thread sub
4438                   threads nil)))
4439         (setq threads (cdr threads)))
4440       ;; If this article is in no thread, then it's a root.
4441       (if thread
4442           (unless dont-remove
4443             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4444         (setq thread (gnus-id-to-thread last-id)))
4445       (when thread
4446         (prog1
4447             thread                      ; We return this thread.
4448           (unless dont-remove
4449             (if (stringp (car thread))
4450                 (progn
4451                   ;; If we use dummy roots, then we have to remove the
4452                   ;; dummy root as well.
4453                   (when (eq gnus-summary-make-false-root 'dummy)
4454                     ;; We go to the dummy root by going to
4455                     ;; the first sub-"thread", and then one line up.
4456                     (gnus-summary-goto-article
4457                      (mail-header-number (caadr thread)))
4458                     (forward-line -1)
4459                     (gnus-delete-line)
4460                     (gnus-data-compute-positions))
4461                   (setq thread (cdr thread))
4462                   (while thread
4463                     (gnus-remove-thread-1 (car thread))
4464                     (setq thread (cdr thread))))
4465               (gnus-remove-thread-1 thread))))))))
4466
4467 (defun gnus-remove-thread-1 (thread)
4468   "Remove the thread THREAD recursively."
4469   (let ((number (mail-header-number (pop thread)))
4470         d)
4471     (setq thread (reverse thread))
4472     (while thread
4473       (gnus-remove-thread-1 (pop thread)))
4474     (when (setq d (gnus-data-find number))
4475       (goto-char (gnus-data-pos d))
4476       (gnus-summary-show-thread)
4477       (gnus-data-remove
4478        number
4479        (- (point-at-bol)
4480           (prog1
4481               (1+ (point-at-eol))
4482             (gnus-delete-line)))))))
4483
4484 (defun gnus-sort-threads-1 (threads func)
4485   (sort (mapcar (lambda (thread)
4486                   (cons (car thread)
4487                         (and (cdr thread)
4488                              (gnus-sort-threads-1 (cdr thread) func))))
4489                 threads) func))
4490
4491 (defun gnus-sort-threads (threads)
4492   "Sort THREADS."
4493   (if (not gnus-thread-sort-functions)
4494       threads
4495     (gnus-message 8 "Sorting threads...")
4496     (let ((max-lisp-eval-depth 5000))
4497       (prog1 (gnus-sort-threads-1
4498          threads
4499          (gnus-make-sort-function gnus-thread-sort-functions))
4500         (gnus-message 8 "Sorting threads...done")))))
4501
4502 (defun gnus-sort-articles (articles)
4503   "Sort ARTICLES."
4504   (when gnus-article-sort-functions
4505     (gnus-message 7 "Sorting articles...")
4506     (prog1
4507         (setq gnus-newsgroup-headers
4508               (sort articles (gnus-make-sort-function
4509                               gnus-article-sort-functions)))
4510       (gnus-message 7 "Sorting articles...done"))))
4511
4512 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4513 (defmacro gnus-thread-header (thread)
4514   "Return header of first article in THREAD.
4515 Note that THREAD must never, ever be anything else than a variable -
4516 using some other form will lead to serious barfage."
4517   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4518   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4519   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4520         (vector thread) 2))
4521
4522 (defsubst gnus-article-sort-by-number (h1 h2)
4523   "Sort articles by article number."
4524   (< (mail-header-number h1)
4525      (mail-header-number h2)))
4526
4527 (defun gnus-thread-sort-by-number (h1 h2)
4528   "Sort threads by root article number."
4529   (gnus-article-sort-by-number
4530    (gnus-thread-header h1) (gnus-thread-header h2)))
4531
4532 (defsubst gnus-article-sort-by-random (h1 h2)
4533   "Sort articles by article number."
4534   (zerop (random 2)))
4535
4536 (defun gnus-thread-sort-by-random (h1 h2)
4537   "Sort threads by root article number."
4538   (gnus-article-sort-by-random
4539    (gnus-thread-header h1) (gnus-thread-header h2)))
4540
4541 (defsubst gnus-article-sort-by-lines (h1 h2)
4542   "Sort articles by article Lines header."
4543   (< (mail-header-lines h1)
4544      (mail-header-lines h2)))
4545
4546 (defun gnus-thread-sort-by-lines (h1 h2)
4547   "Sort threads by root article Lines header."
4548   (gnus-article-sort-by-lines
4549    (gnus-thread-header h1) (gnus-thread-header h2)))
4550
4551 (defsubst gnus-article-sort-by-chars (h1 h2)
4552   "Sort articles by octet length."
4553   (< (mail-header-chars h1)
4554      (mail-header-chars h2)))
4555
4556 (defun gnus-thread-sort-by-chars (h1 h2)
4557   "Sort threads by root article octet length."
4558   (gnus-article-sort-by-chars
4559    (gnus-thread-header h1) (gnus-thread-header h2)))
4560
4561 (defsubst gnus-article-sort-by-author (h1 h2)
4562   "Sort articles by root author."
4563   (string-lessp
4564    (let ((extract (funcall
4565                    gnus-extract-address-components
4566                    (mail-header-from h1))))
4567      (or (car extract) (cadr extract) ""))
4568    (let ((extract (funcall
4569                    gnus-extract-address-components
4570                    (mail-header-from h2))))
4571      (or (car extract) (cadr extract) ""))))
4572
4573 (defun gnus-thread-sort-by-author (h1 h2)
4574   "Sort threads by root author."
4575   (gnus-article-sort-by-author
4576    (gnus-thread-header h1)  (gnus-thread-header h2)))
4577
4578 (defsubst gnus-article-sort-by-recipient (h1 h2)
4579   "Sort articles by recipient."
4580   (string-lessp
4581    (let ((extract (funcall
4582                    gnus-extract-address-components
4583                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4584      (or (car extract) (cadr extract)))
4585    (let ((extract (funcall
4586                    gnus-extract-address-components
4587                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4588      (or (car extract) (cadr extract)))))
4589
4590 (defsubst gnus-article-sort-by-subject (h1 h2)
4591   "Sort articles by root subject."
4592   (string-lessp
4593    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4594    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4595
4596 (defun gnus-thread-sort-by-subject (h1 h2)
4597   "Sort threads by root subject."
4598   (gnus-article-sort-by-subject
4599    (gnus-thread-header h1) (gnus-thread-header h2)))
4600
4601 (defsubst gnus-article-sort-by-date (h1 h2)
4602   "Sort articles by root article date."
4603   (time-less-p
4604    (gnus-date-get-time (mail-header-date h1))
4605    (gnus-date-get-time (mail-header-date h2))))
4606
4607 (defun gnus-thread-sort-by-date (h1 h2)
4608   "Sort threads by root article date."
4609   (gnus-article-sort-by-date
4610    (gnus-thread-header h1) (gnus-thread-header h2)))
4611
4612 (defsubst gnus-article-sort-by-score (h1 h2)
4613   "Sort articles by root article score.
4614 Unscored articles will be counted as having a score of zero."
4615   (> (or (cdr (assq (mail-header-number h1)
4616                     gnus-newsgroup-scored))
4617          gnus-summary-default-score 0)
4618      (or (cdr (assq (mail-header-number h2)
4619                     gnus-newsgroup-scored))
4620          gnus-summary-default-score 0)))
4621
4622 (defun gnus-thread-sort-by-score (h1 h2)
4623   "Sort threads by root article score."
4624   (gnus-article-sort-by-score
4625    (gnus-thread-header h1) (gnus-thread-header h2)))
4626
4627 (defun gnus-thread-sort-by-total-score (h1 h2)
4628   "Sort threads by the sum of all scores in the thread.
4629 Unscored articles will be counted as having a score of zero."
4630   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4631
4632 (defun gnus-thread-total-score (thread)
4633   ;; This function find the total score of THREAD.
4634   (cond
4635    ((null thread)
4636     0)
4637    ((consp thread)
4638     (if (stringp (car thread))
4639         (apply gnus-thread-score-function 0
4640                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4641       (gnus-thread-total-score-1 thread)))
4642    (t
4643     (gnus-thread-total-score-1 (list thread)))))
4644
4645 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4646   "Sort threads such that the thread with the most recently arrived article comes first."
4647   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4648
4649 (defun gnus-thread-highest-number (thread)
4650   "Return the highest article number in THREAD."
4651   (apply 'max (mapcar (lambda (header)
4652                         (mail-header-number header))
4653                       (message-flatten-list thread))))
4654
4655 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4656   "Sort threads such that the thread with the most recently dated article comes first."
4657   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4658
4659 (defun gnus-thread-latest-date (thread)
4660   "Return the highest article date in THREAD."
4661   (let ((previous-time 0))
4662     (apply 'max
4663            (mapcar
4664             (lambda (header)
4665               (setq previous-time
4666                     (condition-case ()
4667                         (time-to-seconds (mail-header-parse-date
4668                                           (mail-header-date header)))
4669                       (error previous-time))))
4670             (sort
4671              (message-flatten-list thread)
4672              (lambda (h1 h2)
4673                (< (mail-header-number h1)
4674                   (mail-header-number h2))))))))
4675
4676 (defun gnus-thread-total-score-1 (root)
4677   ;; This function find the total score of the thread below ROOT.
4678   (setq root (car root))
4679   (apply gnus-thread-score-function
4680          (or (append
4681               (mapcar 'gnus-thread-total-score
4682                       (cdr (gnus-id-to-thread (mail-header-id root))))
4683               (when (> (mail-header-number root) 0)
4684                 (list (or (cdr (assq (mail-header-number root)
4685                                      gnus-newsgroup-scored))
4686                           gnus-summary-default-score 0))))
4687              (list gnus-summary-default-score)
4688              '(0))))
4689
4690 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4691 (defvar gnus-tmp-prev-subject nil)
4692 (defvar gnus-tmp-false-parent nil)
4693 (defvar gnus-tmp-root-expunged nil)
4694 (defvar gnus-tmp-dummy-line nil)
4695
4696 (eval-when-compile (defvar gnus-tmp-header))
4697 (defun gnus-extra-header (type &optional header)
4698   "Return the extra header of TYPE."
4699   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4700       ""))
4701
4702 (defvar gnus-tmp-thread-tree-header-string "")
4703
4704 (defcustom gnus-sum-thread-tree-root "> "
4705   "With %B spec, used for the root of a thread.
4706 If nil, use subject instead."
4707   :version "22.1"
4708   :type '(radio (const :format "%v  " nil) string)
4709   :group 'gnus-thread)
4710 (defcustom gnus-sum-thread-tree-false-root "> "
4711   "With %B spec, used for a false root of a thread.
4712 If nil, use subject instead."
4713   :version "22.1"
4714   :type '(radio (const :format "%v  " nil) string)
4715   :group 'gnus-thread)
4716 (defcustom gnus-sum-thread-tree-single-indent ""
4717   "With %B spec, used for a thread with just one message.
4718 If nil, use subject instead."
4719   :version "22.1"
4720   :type '(radio (const :format "%v  " nil) string)
4721   :group 'gnus-thread)
4722 (defcustom gnus-sum-thread-tree-vertical "| "
4723   "With %B spec, used for drawing a vertical line."
4724   :version "22.1"
4725   :type 'string
4726   :group 'gnus-thread)
4727 (defcustom gnus-sum-thread-tree-indent "  "
4728   "With %B spec, used for indenting."
4729   :version "22.1"
4730   :type 'string
4731   :group 'gnus-thread)
4732 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4733   "With %B spec, used for a leaf with brothers."
4734   :version "22.1"
4735   :type 'string
4736   :group 'gnus-thread)
4737 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4738   "With %B spec, used for a leaf without brothers."
4739   :version "22.1"
4740   :type 'string
4741   :group 'gnus-thread)
4742
4743 (defun gnus-summary-prepare-threads (threads)
4744   "Prepare summary buffer from THREADS and indentation LEVEL.
4745 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4746 or a straight list of headers."
4747   (gnus-message 7 "Generating summary...")
4748
4749   (setq gnus-newsgroup-threads threads)
4750   (beginning-of-line)
4751
4752   (let ((gnus-tmp-level 0)
4753         (default-score (or gnus-summary-default-score 0))
4754         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4755         (building-line-count gnus-summary-display-while-building)
4756         (building-count (integerp gnus-summary-display-while-building))
4757         thread number subject stack state gnus-tmp-gathered beg-match
4758         new-roots gnus-tmp-new-adopts thread-end simp-subject
4759         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4760         gnus-tmp-replied gnus-tmp-subject-or-nil
4761         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4762         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4763         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4764         tree-stack)
4765
4766     (setq gnus-tmp-prev-subject nil
4767           gnus-tmp-thread-tree-header-string "")
4768
4769     (if (vectorp (car threads))
4770         ;; If this is a straight (sic) list of headers, then a
4771         ;; threaded summary display isn't required, so we just create
4772         ;; an unthreaded one.
4773         (gnus-summary-prepare-unthreaded threads)
4774
4775       ;; Do the threaded display.
4776
4777       (if gnus-summary-display-while-building
4778           (switch-to-buffer (buffer-name)))
4779       (while (or threads stack gnus-tmp-new-adopts new-roots)
4780
4781         (if (and (= gnus-tmp-level 0)
4782                  (or (not stack)
4783                      (= (caar stack) 0))
4784                  (not gnus-tmp-false-parent)
4785                  (or gnus-tmp-new-adopts new-roots))
4786             (if gnus-tmp-new-adopts
4787                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4788                       thread (list (car gnus-tmp-new-adopts))
4789                       gnus-tmp-header (caar thread)
4790                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4791               (when new-roots
4792                 (setq thread (list (car new-roots))
4793                       gnus-tmp-header (caar thread)
4794                       new-roots (cdr new-roots))))
4795
4796           (if threads
4797               ;; If there are some threads, we do them before the
4798               ;; threads on the stack.
4799               (setq thread threads
4800                     gnus-tmp-header (caar thread))
4801             ;; There were no current threads, so we pop something off
4802             ;; the stack.
4803             (setq state (car stack)
4804                   gnus-tmp-level (car state)
4805                   tree-stack (cadr state)
4806                   thread (caddr state)
4807                   stack (cdr stack)
4808                   gnus-tmp-header (caar thread))))
4809
4810         (setq gnus-tmp-false-parent nil)
4811         (setq gnus-tmp-root-expunged nil)
4812         (setq thread-end nil)
4813
4814         (if (stringp gnus-tmp-header)
4815             ;; The header is a dummy root.
4816             (cond
4817              ((eq gnus-summary-make-false-root 'adopt)
4818               ;; We let the first article adopt the rest.
4819               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4820                                                (cddar thread)))
4821               (setq gnus-tmp-gathered
4822                     (nconc (mapcar
4823                             (lambda (h) (mail-header-number (car h)))
4824                             (cddar thread))
4825                            gnus-tmp-gathered))
4826               (setq thread (cons (list (caar thread)
4827                                        (cadar thread))
4828                                  (cdr thread)))
4829               (setq gnus-tmp-level -1
4830                     gnus-tmp-false-parent t))
4831              ((eq gnus-summary-make-false-root 'empty)
4832               ;; We print adopted articles with empty subject fields.
4833               (setq gnus-tmp-gathered
4834                     (nconc (mapcar
4835                             (lambda (h) (mail-header-number (car h)))
4836                             (cddar thread))
4837                            gnus-tmp-gathered))
4838               (setq gnus-tmp-level -1))
4839              ((eq gnus-summary-make-false-root 'dummy)
4840               ;; We remember that we probably want to output a dummy
4841               ;; root.
4842               (setq gnus-tmp-dummy-line gnus-tmp-header)
4843               (setq gnus-tmp-prev-subject gnus-tmp-header))
4844              (t
4845               ;; We do not make a root for the gathered
4846               ;; sub-threads at all.
4847               (setq gnus-tmp-level -1)))
4848
4849           (setq number (mail-header-number gnus-tmp-header)
4850                 subject (mail-header-subject gnus-tmp-header)
4851                 simp-subject (gnus-simplify-subject-fully subject))
4852
4853           (cond
4854            ;; If the thread has changed subject, we might want to make
4855            ;; this subthread into a root.
4856            ((and (null gnus-thread-ignore-subject)
4857                  (not (zerop gnus-tmp-level))
4858                  gnus-tmp-prev-subject
4859                  (not (string= gnus-tmp-prev-subject simp-subject)))
4860             (setq new-roots (nconc new-roots (list (car thread)))
4861                   thread-end t
4862                   gnus-tmp-header nil))
4863            ;; If the article lies outside the current limit,
4864            ;; then we do not display it.
4865            ((not (memq number gnus-newsgroup-limit))
4866             (setq gnus-tmp-gathered
4867                   (nconc (mapcar
4868                           (lambda (h) (mail-header-number (car h)))
4869                           (cdar thread))
4870                          gnus-tmp-gathered))
4871             (setq gnus-tmp-new-adopts (if (cdar thread)
4872                                           (append gnus-tmp-new-adopts
4873                                                   (cdar thread))
4874                                         gnus-tmp-new-adopts)
4875                   thread-end t
4876                   gnus-tmp-header nil)
4877             (when (zerop gnus-tmp-level)
4878               (setq gnus-tmp-root-expunged t)))
4879            ;; Perhaps this article is to be marked as read?
4880            ((and gnus-summary-mark-below
4881                  (< (or (cdr (assq number gnus-newsgroup-scored))
4882                         default-score)
4883                     gnus-summary-mark-below)
4884                  ;; Don't touch sparse articles.
4885                  (not (gnus-summary-article-sparse-p number))
4886                  (not (gnus-summary-article-ancient-p number)))
4887             (setq gnus-newsgroup-unreads
4888                   (delq number gnus-newsgroup-unreads))
4889             (if gnus-newsgroup-auto-expire
4890                 (setq gnus-newsgroup-expirable
4891                       (gnus-add-to-sorted-list
4892                        gnus-newsgroup-expirable number))
4893               (push (cons number gnus-low-score-mark)
4894                     gnus-newsgroup-reads))))
4895
4896           (when gnus-tmp-header
4897             ;; We may have an old dummy line to output before this
4898             ;; article.
4899             (when (and gnus-tmp-dummy-line
4900                        (gnus-subject-equal
4901                         gnus-tmp-dummy-line
4902                         (mail-header-subject gnus-tmp-header)))
4903               (gnus-summary-insert-dummy-line
4904                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4905               (setq gnus-tmp-dummy-line nil))
4906
4907             ;; Compute the mark.
4908             (setq gnus-tmp-unread (gnus-article-mark number))
4909
4910             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4911                                   gnus-tmp-header gnus-tmp-level)
4912                   gnus-newsgroup-data)
4913
4914             ;; Actually insert the line.
4915             (setq
4916              gnus-tmp-subject-or-nil
4917              (cond
4918               ((and gnus-thread-ignore-subject
4919                     gnus-tmp-prev-subject
4920                     (not (string= gnus-tmp-prev-subject simp-subject)))
4921                subject)
4922               ((zerop gnus-tmp-level)
4923                (if (and (eq gnus-summary-make-false-root 'empty)
4924                         (memq number gnus-tmp-gathered)
4925                         gnus-tmp-prev-subject
4926                         (string= gnus-tmp-prev-subject simp-subject))
4927                    gnus-summary-same-subject
4928                  subject))
4929               (t gnus-summary-same-subject)))
4930             (if (and (eq gnus-summary-make-false-root 'adopt)
4931                      (= gnus-tmp-level 1)
4932                      (memq number gnus-tmp-gathered))
4933                 (setq gnus-tmp-opening-bracket ?\<
4934                       gnus-tmp-closing-bracket ?\>)
4935               (setq gnus-tmp-opening-bracket ?\[
4936                     gnus-tmp-closing-bracket ?\]))
4937             (setq
4938              gnus-tmp-indentation
4939              (aref gnus-thread-indent-array gnus-tmp-level)
4940              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4941              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4942                                 gnus-summary-default-score 0)
4943              gnus-tmp-score-char
4944              (if (or (null gnus-summary-default-score)
4945                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4946                          gnus-summary-zcore-fuzz))
4947                  ?                      ;Whitespace
4948                (if (< gnus-tmp-score gnus-summary-default-score)
4949                    gnus-score-below-mark gnus-score-over-mark))
4950              gnus-tmp-replied
4951              (cond ((memq number gnus-newsgroup-processable)
4952                     gnus-process-mark)
4953                    ((memq number gnus-newsgroup-cached)
4954                     gnus-cached-mark)
4955                    ((memq number gnus-newsgroup-replied)
4956                     gnus-replied-mark)
4957                    ((memq number gnus-newsgroup-forwarded)
4958                     gnus-forwarded-mark)
4959                    ((memq number gnus-newsgroup-saved)
4960                     gnus-saved-mark)
4961                    ((memq number gnus-newsgroup-recent)
4962                     gnus-recent-mark)
4963                    ((memq number gnus-newsgroup-unseen)
4964                     gnus-unseen-mark)
4965                    (t gnus-no-mark))
4966              gnus-tmp-downloaded
4967              (cond ((memq number gnus-newsgroup-undownloaded)
4968                     gnus-undownloaded-mark)
4969                    (gnus-newsgroup-agentized
4970                     gnus-downloaded-mark)
4971                    (t
4972                     gnus-no-mark))
4973              gnus-tmp-from (mail-header-from gnus-tmp-header)
4974              gnus-tmp-name
4975              (cond
4976               ((string-match "<[^>]+> *$" gnus-tmp-from)
4977                (setq beg-match (match-beginning 0))
4978                (or (and (string-match "^\".+\"" gnus-tmp-from)
4979                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4980                    (substring gnus-tmp-from 0 beg-match)))
4981               ((string-match "(.+)" gnus-tmp-from)
4982                (substring gnus-tmp-from
4983                           (1+ (match-beginning 0)) (1- (match-end 0))))
4984               (t gnus-tmp-from))
4985
4986              ;; Do the %B string
4987              gnus-tmp-thread-tree-header-string
4988              (cond
4989               ((not gnus-show-threads) "")
4990               ((zerop gnus-tmp-level)
4991                (cond ((cdar thread)
4992                       (or gnus-sum-thread-tree-root subject))
4993                      (gnus-tmp-new-adopts
4994                       (or gnus-sum-thread-tree-false-root subject))
4995                      (t
4996                       (or gnus-sum-thread-tree-single-indent subject))))
4997               (t
4998                (concat (apply 'concat
4999                               (mapcar (lambda (item)
5000                                         (if (= item 1)
5001                                             gnus-sum-thread-tree-vertical
5002                                           gnus-sum-thread-tree-indent))
5003                                       (cdr (reverse tree-stack))))
5004                        (if (nth 1 thread)
5005                            gnus-sum-thread-tree-leaf-with-other
5006                          gnus-sum-thread-tree-single-leaf)))))
5007             (when (string= gnus-tmp-name "")
5008               (setq gnus-tmp-name gnus-tmp-from))
5009             (unless (numberp gnus-tmp-lines)
5010               (setq gnus-tmp-lines -1))
5011             (if (= gnus-tmp-lines -1)
5012                 (setq gnus-tmp-lines "?")
5013               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5014               (gnus-put-text-property
5015              (point)
5016              (progn (eval gnus-summary-line-format-spec) (point))
5017                'gnus-number number)
5018             (when gnus-visual-p
5019               (forward-line -1)
5020               (gnus-run-hooks 'gnus-summary-update-hook)
5021               (forward-line 1))
5022
5023             (setq gnus-tmp-prev-subject simp-subject)))
5024
5025         (when (nth 1 thread)
5026           (push (list (max 0 gnus-tmp-level)
5027                       (copy-sequence tree-stack)
5028                       (nthcdr 1 thread))
5029                 stack))
5030         (push (if (nth 1 thread) 1 0) tree-stack)
5031         (incf gnus-tmp-level)
5032         (setq threads (if thread-end nil (cdar thread)))
5033         (if gnus-summary-display-while-building
5034             (if building-count
5035                 (progn
5036                   ;; use a set frequency
5037                   (setq building-line-count (1- building-line-count))
5038                   (when (= building-line-count 0)
5039                     (sit-for 0)
5040                     (setq building-line-count
5041                           gnus-summary-display-while-building)))
5042               ;; always
5043               (sit-for 0)))
5044         (unless threads
5045           (setq gnus-tmp-level 0)))))
5046   (gnus-message 7 "Generating summary...done"))
5047
5048 (defun gnus-summary-prepare-unthreaded (headers)
5049   "Generate an unthreaded summary buffer based on HEADERS."
5050   (let (header number mark)
5051
5052     (beginning-of-line)
5053
5054     (while headers
5055       ;; We may have to root out some bad articles...
5056       (when (memq (setq number (mail-header-number
5057                                 (setq header (pop headers))))
5058                   gnus-newsgroup-limit)
5059         ;; Mark article as read when it has a low score.
5060         (when (and gnus-summary-mark-below
5061                    (< (or (cdr (assq number gnus-newsgroup-scored))
5062                           gnus-summary-default-score 0)
5063                       gnus-summary-mark-below)
5064                    (not (gnus-summary-article-ancient-p number)))
5065           (setq gnus-newsgroup-unreads
5066                 (delq number gnus-newsgroup-unreads))
5067           (if gnus-newsgroup-auto-expire
5068               (push number gnus-newsgroup-expirable)
5069             (push (cons number gnus-low-score-mark)
5070                   gnus-newsgroup-reads)))
5071
5072         (setq mark (gnus-article-mark number))
5073         (push (gnus-data-make number mark (1+ (point)) header 0)
5074               gnus-newsgroup-data)
5075         (gnus-summary-insert-line
5076          header 0 number
5077          (memq number gnus-newsgroup-undownloaded)
5078          mark (memq number gnus-newsgroup-replied)
5079          (memq number gnus-newsgroup-expirable)
5080          (mail-header-subject header) nil
5081          (cdr (assq number gnus-newsgroup-scored))
5082          (memq number gnus-newsgroup-processable))))))
5083
5084 (defun gnus-summary-remove-list-identifiers ()
5085   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5086   (let ((regexp (if (consp gnus-list-identifiers)
5087                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5088                   gnus-list-identifiers))
5089         changed subject)
5090     (when regexp
5091       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5092       (dolist (header gnus-newsgroup-headers)
5093         (setq subject (mail-header-subject header)
5094               changed nil)
5095         (while (string-match regexp subject)
5096           (setq subject
5097                 (concat (substring subject 0 (match-beginning 1))
5098                         (substring subject (match-end 0)))
5099                 changed t))
5100         (when changed
5101           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5102             (setq subject
5103                   (concat (substring subject 0 (match-beginning 1))
5104                           (substring subject (match-end 1)))))
5105           (mail-header-set-subject header subject))))))
5106
5107 (defun gnus-fetch-headers (articles)
5108   "Fetch headers of ARTICLES."
5109   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5110     (gnus-message 5 "Fetching headers for %s..." name)
5111     (prog1
5112         (if (eq 'nov
5113                 (setq gnus-headers-retrieved-by
5114                       (gnus-retrieve-headers
5115                        articles gnus-newsgroup-name
5116                        ;; We might want to fetch old headers, but
5117                        ;; not if there is only 1 article.
5118                        (and (or (and
5119                                  (not (eq gnus-fetch-old-headers 'some))
5120                                  (not (numberp gnus-fetch-old-headers)))
5121                                 (> (length articles) 1))
5122                             gnus-fetch-old-headers))))
5123             (gnus-get-newsgroup-headers-xover
5124              articles nil nil gnus-newsgroup-name t)
5125           (gnus-get-newsgroup-headers))
5126       (gnus-message 5 "Fetching headers for %s...done" name))))
5127
5128 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5129   "Select newsgroup GROUP.
5130 If READ-ALL is non-nil, all articles in the group are selected.
5131 If SELECT-ARTICLES, only select those articles from GROUP."
5132   (let* ((entry (gnus-group-entry group))
5133          ;;!!! Dirty hack; should be removed.
5134          (gnus-summary-ignore-duplicates
5135           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5136               t
5137             gnus-summary-ignore-duplicates))
5138          (info (nth 2 entry))
5139          articles fetched-articles cached)
5140
5141     (unless (gnus-check-server
5142              (set (make-local-variable 'gnus-current-select-method)
5143                   (gnus-find-method-for-group group)))
5144       (error "Couldn't open server"))
5145
5146     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5147         (gnus-activate-group group)     ; Or we can activate it...
5148         (progn                          ; Or we bug out.
5149           (when (equal major-mode 'gnus-summary-mode)
5150             (gnus-kill-buffer (current-buffer)))
5151           (error "Couldn't activate group %s: %s"
5152                  group (gnus-status-message group))))
5153
5154     (unless (gnus-request-group group t)
5155       (when (equal major-mode 'gnus-summary-mode)
5156         (gnus-kill-buffer (current-buffer)))
5157       (error "Couldn't request group %s: %s"
5158              group (gnus-status-message group)))
5159
5160     (when gnus-agent
5161       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5162
5163       (setq gnus-summary-use-undownloaded-faces
5164             (gnus-agent-find-parameter
5165              group
5166              'agent-enable-undownloaded-faces)))
5167
5168     (setq gnus-newsgroup-name group
5169           gnus-newsgroup-unselected nil
5170           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5171
5172     (let ((display (gnus-group-find-parameter group 'display)))
5173       (setq gnus-newsgroup-display
5174             (cond
5175              ((not (zerop (or (car-safe read-all) 0)))
5176               ;; The user entered the group with C-u SPC/RET, let's show
5177               ;; all articles.
5178               'gnus-not-ignore)
5179              ((eq display 'all)
5180               'gnus-not-ignore)
5181              ((arrayp display)
5182               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5183              ((numberp display)
5184               ;; The following is probably the "correct" solution, but
5185               ;; it makes Gnus fetch all headers and then limit the
5186               ;; articles (which is slow), so instead we hack the
5187               ;; select-articles parameter instead. -- Simon Josefsson
5188               ;; <jas@kth.se>
5189               ;;
5190               ;; (gnus-byte-compile
5191               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5192               ;;                         display)))))
5193               (setq select-articles
5194                     (gnus-uncompress-range
5195                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5196                              (if (> tmp 0)
5197                                  tmp
5198                                1))
5199                            (cdr (gnus-active group)))))
5200               nil)
5201              (t
5202               nil))))
5203
5204     (gnus-summary-setup-default-charset)
5205
5206     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5207     (when (gnus-virtual-group-p group)
5208       (setq cached gnus-newsgroup-cached))
5209
5210     (setq gnus-newsgroup-unreads
5211           (gnus-sorted-ndifference
5212            (gnus-sorted-ndifference gnus-newsgroup-unreads
5213                                     gnus-newsgroup-marked)
5214            gnus-newsgroup-dormant))
5215
5216     (setq gnus-newsgroup-processable nil)
5217
5218     (gnus-update-read-articles group gnus-newsgroup-unreads)
5219
5220     ;; Adjust and set lists of article marks.
5221     (when info
5222       (gnus-adjust-marked-articles info))
5223     (if (setq articles select-articles)
5224         (setq gnus-newsgroup-unselected
5225               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5226       (setq articles (gnus-articles-to-read group read-all)))
5227
5228     (cond
5229      ((null articles)
5230       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5231       'quit)
5232      ((eq articles 0) nil)
5233      (t
5234       ;; Init the dependencies hash table.
5235       (setq gnus-newsgroup-dependencies
5236             (gnus-make-hashtable (length articles)))
5237       (gnus-set-global-variables)
5238       ;; Retrieve the headers and read them in.
5239
5240       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5241
5242       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5243       (when cached
5244         (setq gnus-newsgroup-cached cached))
5245
5246       ;; Suppress duplicates?
5247       (when gnus-suppress-duplicates
5248         (gnus-dup-suppress-articles))
5249
5250       ;; Set the initial limit.
5251       (setq gnus-newsgroup-limit (copy-sequence articles))
5252       ;; Remove canceled articles from the list of unread articles.
5253       (setq fetched-articles
5254             (mapcar (lambda (headers) (mail-header-number headers))
5255                     gnus-newsgroup-headers))
5256       (setq gnus-newsgroup-articles fetched-articles)
5257       (setq gnus-newsgroup-unreads
5258             (gnus-sorted-nintersection
5259              gnus-newsgroup-unreads fetched-articles))
5260       (gnus-compute-unseen-list)
5261
5262       ;; Removed marked articles that do not exist.
5263       (gnus-update-missing-marks
5264        (gnus-sorted-difference articles fetched-articles))
5265       ;; We might want to build some more threads first.
5266       (when (and gnus-fetch-old-headers
5267                  (eq gnus-headers-retrieved-by 'nov))
5268         (if (eq gnus-fetch-old-headers 'invisible)
5269             (gnus-build-all-threads)
5270           (gnus-build-old-threads)))
5271       ;; Let the Gnus agent mark articles as read.
5272       (when gnus-agent
5273         (gnus-agent-get-undownloaded-list))
5274       ;; Remove list identifiers from subject
5275       (when gnus-list-identifiers
5276         (gnus-summary-remove-list-identifiers))
5277       ;; Check whether auto-expire is to be done in this group.
5278       (setq gnus-newsgroup-auto-expire
5279             (gnus-group-auto-expirable-p group))
5280       ;; Set up the article buffer now, if necessary.
5281       (unless gnus-single-article-buffer
5282         (gnus-article-setup-buffer))
5283       ;; First and last article in this newsgroup.
5284       (when gnus-newsgroup-headers
5285         (setq gnus-newsgroup-begin
5286               (mail-header-number (car gnus-newsgroup-headers))
5287               gnus-newsgroup-end
5288               (mail-header-number
5289                (gnus-last-element gnus-newsgroup-headers))))
5290       ;; GROUP is successfully selected.
5291       (or gnus-newsgroup-headers t)))))
5292
5293 (defun gnus-compute-unseen-list ()
5294   ;; The `seen' marks are treated specially.
5295   (if (not gnus-newsgroup-seen)
5296       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5297     (setq gnus-newsgroup-unseen
5298           (gnus-inverse-list-range-intersection
5299            gnus-newsgroup-articles gnus-newsgroup-seen))))
5300
5301 (defun gnus-summary-display-make-predicate (display)
5302   (require 'gnus-agent)
5303   (when (= (length display) 1)
5304     (setq display (car display)))
5305   (unless gnus-summary-display-cache
5306     (dolist (elem (append '((unread . unread)
5307                             (read . read)
5308                             (unseen . unseen))
5309                           gnus-article-mark-lists))
5310       (push (cons (cdr elem)
5311                   (gnus-byte-compile
5312                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5313             gnus-summary-display-cache)))
5314   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5315         (gnus-category-predicate-cache gnus-summary-display-cache))
5316     (gnus-get-predicate display)))
5317
5318 ;; Uses the dynamically bound `number' variable.
5319 (eval-when-compile
5320   (defvar number))
5321 (defun gnus-article-marked-p (type &optional article)
5322   (let ((article (or article number)))
5323     (cond
5324      ((eq type 'tick)
5325       (memq article gnus-newsgroup-marked))
5326      ((eq type 'spam)
5327       (memq article gnus-newsgroup-spam-marked))
5328      ((eq type 'unsend)
5329       (memq article gnus-newsgroup-unsendable))
5330      ((eq type 'undownload)
5331       (memq article gnus-newsgroup-undownloaded))
5332      ((eq type 'download)
5333       (memq article gnus-newsgroup-downloadable))
5334      ((eq type 'unread)
5335       (memq article gnus-newsgroup-unreads))
5336      ((eq type 'read)
5337       (memq article gnus-newsgroup-reads))
5338      ((eq type 'dormant)
5339       (memq article gnus-newsgroup-dormant) )
5340      ((eq type 'expire)
5341       (memq article gnus-newsgroup-expirable))
5342      ((eq type 'reply)
5343       (memq article gnus-newsgroup-replied))
5344      ((eq type 'killed)
5345       (memq article gnus-newsgroup-killed))
5346      ((eq type 'bookmark)
5347       (assq article gnus-newsgroup-bookmarks))
5348      ((eq type 'score)
5349       (assq article gnus-newsgroup-scored))
5350      ((eq type 'save)
5351       (memq article gnus-newsgroup-saved))
5352      ((eq type 'cache)
5353       (memq article gnus-newsgroup-cached))
5354      ((eq type 'forward)
5355       (memq article gnus-newsgroup-forwarded))
5356      ((eq type 'seen)
5357       (not (memq article gnus-newsgroup-unseen)))
5358      ((eq type 'recent)
5359       (memq article gnus-newsgroup-recent))
5360      (t t))))
5361
5362 (defun gnus-articles-to-read (group &optional read-all)
5363   "Find out what articles the user wants to read."
5364   (let* ((articles
5365           ;; Select all articles if `read-all' is non-nil, or if there
5366           ;; are no unread articles.
5367           (if (or read-all
5368                   (and (zerop (length gnus-newsgroup-marked))
5369                        (zerop (length gnus-newsgroup-unreads)))
5370                   ;; Fetch all if the predicate is non-nil.
5371                   gnus-newsgroup-display)
5372               ;; We want to select the headers for all the articles in
5373               ;; the group, so we select either all the active
5374               ;; articles in the group, or (if that's nil), the
5375               ;; articles in the cache.
5376               (or
5377                (gnus-uncompress-range (gnus-active group))
5378                (gnus-cache-articles-in-group group))
5379             ;; Select only the "normal" subset of articles.
5380             (gnus-sorted-nunion
5381              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5382              gnus-newsgroup-unreads)))
5383          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5384          (scored (length scored-list))
5385          (number (length articles))
5386          (marked (+ (length gnus-newsgroup-marked)
5387                     (length gnus-newsgroup-dormant)))
5388          (select
5389           (cond
5390            ((numberp read-all)
5391             read-all)
5392            ((numberp gnus-newsgroup-display)
5393             gnus-newsgroup-display)
5394            (t
5395             (condition-case ()
5396                 (cond
5397                  ((and (or (<= scored marked) (= scored number))
5398                        (numberp gnus-large-newsgroup)
5399                        (> number gnus-large-newsgroup))
5400                   (let* ((cursor-in-echo-area nil)
5401                          (initial (gnus-parameter-large-newsgroup-initial
5402                                    gnus-newsgroup-name))
5403                          (input
5404                           (read-string
5405                            (format
5406                             "How many articles from %s (%s %d): "
5407                             (gnus-limit-string
5408                              (gnus-group-decoded-name gnus-newsgroup-name)
5409                              35)
5410                             (if initial "max" "default")
5411                             number)
5412                            (if initial
5413                                (cons (number-to-string initial)
5414                                      0)))))
5415                     (if (string-match "^[ \t]*$" input) number input)))
5416                  ((and (> scored marked) (< scored number)
5417                        (> (- scored number) 20))
5418                   (let ((input
5419                          (read-string
5420                           (format "%s %s (%d scored, %d total): "
5421                                   "How many articles from"
5422                                   (gnus-group-decoded-name group)
5423                                   scored number))))
5424                     (if (string-match "^[ \t]*$" input)
5425                         number input)))
5426                  (t number))
5427               (quit
5428                (message "Quit getting the articles to read")
5429                nil))))))
5430     (setq select (if (stringp select) (string-to-number select) select))
5431     (if (or (null select) (zerop select))
5432         select
5433       (if (and (not (zerop scored)) (<= (abs select) scored))
5434           (progn
5435             (setq articles (sort scored-list '<))
5436             (setq number (length articles)))
5437         (setq articles (copy-sequence articles)))
5438
5439       (when (< (abs select) number)
5440         (if (< select 0)
5441             ;; Select the N oldest articles.
5442             (setcdr (nthcdr (1- (abs select)) articles) nil)
5443           ;; Select the N most recent articles.
5444           (setq articles (nthcdr (- number select) articles))))
5445       (setq gnus-newsgroup-unselected
5446             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5447       (when gnus-alter-articles-to-read-function
5448         (setq articles
5449               (sort
5450                (funcall gnus-alter-articles-to-read-function
5451                         gnus-newsgroup-name articles)
5452                '<)))
5453       articles)))
5454
5455 (defun gnus-killed-articles (killed articles)
5456   (let (out)
5457     (while articles
5458       (when (inline (gnus-member-of-range (car articles) killed))
5459         (push (car articles) out))
5460       (setq articles (cdr articles)))
5461     out))
5462
5463 (defun gnus-uncompress-marks (marks)
5464   "Uncompress the mark ranges in MARKS."
5465   (let ((uncompressed '(score bookmark))
5466         out)
5467     (while marks
5468       (if (memq (caar marks) uncompressed)
5469           (push (car marks) out)
5470         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5471       (setq marks (cdr marks)))
5472     out))
5473
5474 (defun gnus-article-mark-to-type (mark)
5475   "Return the type of MARK."
5476   (or (cadr (assq mark gnus-article-special-mark-lists))
5477       'list))
5478
5479 (defun gnus-article-unpropagatable-p (mark)
5480   "Return whether MARK should be propagated to back end."
5481   (memq mark gnus-article-unpropagated-mark-lists))
5482
5483 (defun gnus-adjust-marked-articles (info)
5484   "Set all article lists and remove all marks that are no longer valid."
5485   (let* ((marked-lists (gnus-info-marks info))
5486          (active (gnus-active (gnus-info-group info)))
5487          (min (car active))
5488          (max (cdr active))
5489          (types gnus-article-mark-lists)
5490          marks var articles article mark mark-type
5491          bgn end)
5492
5493     (dolist (marks marked-lists)
5494       (setq mark (car marks)
5495             mark-type (gnus-article-mark-to-type mark)
5496             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5497
5498       ;; We set the variable according to the type of the marks list,
5499       ;; and then adjust the marks to a subset of the active articles.
5500       (cond
5501        ;; Adjust "simple" lists - compressed yet unsorted
5502        ((eq mark-type 'list)
5503         ;; Simultaneously uncompress and clip to active range
5504         ;; See gnus-uncompress-range for a description of possible marks
5505         (let (l lh)
5506           (if (not (cadr marks))
5507               (set var nil)
5508             (setq articles (if (numberp (cddr marks))
5509                                (list (cdr marks))
5510                              (cdr marks))
5511                   lh (cons nil nil)
5512                   l lh)
5513
5514             (while (setq article (pop articles))
5515               (cond ((consp article)
5516                      (setq bgn (max (car article) min)
5517                            end (min (cdr article) max))
5518                      (while (<= bgn end)
5519                        (setq l (setcdr l (cons bgn nil))
5520                              bgn (1+ bgn))))
5521                     ((and (<= min article)
5522                           (>= max article))
5523                      (setq l (setcdr l (cons article nil))))))
5524             (set var (cdr lh)))))
5525        ;; Adjust assocs.
5526        ((eq mark-type 'tuple)
5527         (set var (setq articles (cdr marks)))
5528         (when (not (listp (cdr (symbol-value var))))
5529           (set var (list (symbol-value var))))
5530         (when (not (listp (cdr articles)))
5531           (setq articles (list articles)))
5532         (while articles
5533           (when (or (not (consp (setq article (pop articles))))
5534                     (< (car article) min)
5535                     (> (car article) max))
5536             (set var (delq article (symbol-value var))))))
5537        ;; Adjust ranges (sloppily).
5538        ((eq mark-type 'range)
5539         (cond
5540          ((eq mark 'seen)
5541           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5542           ;; It should be (seen (NUM1 . NUM2)).
5543           (when (numberp (cddr marks))
5544             (setcdr marks (list (cdr marks))))
5545           (setq articles (cdr marks))
5546           (while (and articles
5547                       (or (and (consp (car articles))
5548                                (> min (cdar articles)))
5549                           (and (numberp (car articles))
5550                                (> min (car articles)))))
5551             (pop articles))
5552           (set var articles))))))))
5553
5554 (defun gnus-update-missing-marks (missing)
5555   "Go through the list of MISSING articles and remove them from the mark lists."
5556   (when missing
5557     (let (var m)
5558       ;; Go through all types.
5559       (dolist (elem gnus-article-mark-lists)
5560         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5561           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5562           (when (symbol-value var)
5563             ;; This list has articles.  So we delete all missing
5564             ;; articles from it.
5565             (setq m missing)
5566             (while m
5567               (set var (delq (pop m) (symbol-value var))))))))))
5568
5569 (defun gnus-update-marks ()
5570   "Enter the various lists of marked articles into the newsgroup info list."
5571   (let ((types gnus-article-mark-lists)
5572         (info (gnus-get-info gnus-newsgroup-name))
5573         type list newmarked symbol delta-marks)
5574     (when info
5575       ;; Add all marks lists to the list of marks lists.
5576       (while (setq type (pop types))
5577         (setq list (symbol-value
5578                     (setq symbol
5579                           (intern (format "gnus-newsgroup-%s" (car type))))))
5580
5581         (when list
5582           ;; Get rid of the entries of the articles that have the
5583           ;; default score.
5584           (when (and (eq (cdr type) 'score)
5585                      gnus-save-score
5586                      list)
5587             (let* ((arts list)
5588                    (prev (cons nil list))
5589                    (all prev))
5590               (while arts
5591                 (if (or (not (consp (car arts)))
5592                         (= (cdar arts) gnus-summary-default-score))
5593                     (setcdr prev (cdr arts))
5594                   (setq prev arts))
5595                 (setq arts (cdr arts)))
5596               (setq list (cdr all)))))
5597
5598         (when (eq (cdr type) 'seen)
5599           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5600
5601         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5602           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5603
5604         (when (and (gnus-check-backend-function
5605                     'request-set-mark gnus-newsgroup-name)
5606                    (not (gnus-article-unpropagatable-p (cdr type))))
5607           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5608                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5609                  (add (gnus-remove-from-range
5610                        (gnus-copy-sequence list) old)))
5611             (when add
5612               (push (list add 'add (list (cdr type))) delta-marks))
5613             (when del
5614               (push (list del 'del (list (cdr type))) delta-marks))))
5615
5616         (when list
5617           (push (cons (cdr type) list) newmarked)))
5618
5619       (when delta-marks
5620         (unless (gnus-check-group gnus-newsgroup-name)
5621           (error "Can't open server for %s" gnus-newsgroup-name))
5622         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5623
5624       ;; Enter these new marks into the info of the group.
5625       (if (nthcdr 3 info)
5626           (setcar (nthcdr 3 info) newmarked)
5627         ;; Add the marks lists to the end of the info.
5628         (when newmarked
5629           (setcdr (nthcdr 2 info) (list newmarked))))
5630
5631       ;; Cut off the end of the info if there's nothing else there.
5632       (let ((i 5))
5633         (while (and (> i 2)
5634                     (not (nth i info)))
5635           (when (nthcdr (decf i) info)
5636             (setcdr (nthcdr i info) nil)))))))
5637
5638 (defun gnus-set-mode-line (where)
5639   "Set the mode line of the article or summary buffers.
5640 If WHERE is `summary', the summary mode line format will be used."
5641   ;; Is this mode line one we keep updated?
5642   (when (and (memq where gnus-updated-mode-lines)
5643              (symbol-value
5644               (intern (format "gnus-%s-mode-line-format-spec" where))))
5645     (let (mode-string)
5646       (save-excursion
5647         ;; We evaluate this in the summary buffer since these
5648         ;; variables are buffer-local to that buffer.
5649         (set-buffer gnus-summary-buffer)
5650        ;; We bind all these variables that are used in the `eval' form
5651         ;; below.
5652         (let* ((mformat (symbol-value
5653                          (intern
5654                           (format "gnus-%s-mode-line-format-spec" where))))
5655                (gnus-tmp-group-name (gnus-group-decoded-name
5656                                      gnus-newsgroup-name))
5657                (gnus-tmp-article-number (or gnus-current-article 0))
5658                (gnus-tmp-unread gnus-newsgroup-unreads)
5659                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5660                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5661                (gnus-tmp-unread-and-unselected
5662                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5663                             (zerop gnus-tmp-unselected))
5664                        "")
5665                       ((zerop gnus-tmp-unselected)
5666                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5667                       (t (format "{%d(+%d) more}"
5668                                  gnus-tmp-unread-and-unticked
5669                                  gnus-tmp-unselected))))
5670                (gnus-tmp-subject
5671                 (if (and gnus-current-headers
5672                          (vectorp gnus-current-headers))
5673                     (gnus-mode-string-quote
5674                      (mail-header-subject gnus-current-headers))
5675                   ""))
5676                bufname-length max-len
5677                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5678           (setq mode-string (eval mformat))
5679           (setq bufname-length (if (string-match "%b" mode-string)
5680                                    (- (length
5681                                        (buffer-name
5682                                         (if (eq where 'summary)
5683                                             nil
5684                                           (get-buffer gnus-article-buffer))))
5685                                       2)
5686                                  0))
5687           (setq max-len (max 4 (if gnus-mode-non-string-length
5688                                    (- (window-width)
5689                                       gnus-mode-non-string-length
5690                                       bufname-length)
5691                                  (length mode-string))))
5692           ;; We might have to chop a bit of the string off...
5693           (when (> (length mode-string) max-len)
5694             (setq mode-string
5695                   (concat (truncate-string-to-width mode-string (- max-len 3))
5696                           "...")))
5697           ;; Pad the mode string a bit.
5698           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5699       ;; Update the mode line.
5700       (setq mode-line-buffer-identification
5701             (gnus-mode-line-buffer-identification (list mode-string)))
5702       (set-buffer-modified-p t))))
5703
5704 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5705   "Go through the HEADERS list and add all Xrefs to a hash table.
5706 The resulting hash table is returned, or nil if no Xrefs were found."
5707   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5708          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5709          (xref-hashtb (gnus-make-hashtable))
5710          start group entry number xrefs header)
5711     (while headers
5712       (setq header (pop headers))
5713       (when (and (setq xrefs (mail-header-xref header))
5714                  (not (memq (setq number (mail-header-number header))
5715                             unreads)))
5716         (setq start 0)
5717         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5718           (setq start (match-end 0))
5719           (setq group (if prefix
5720                           (concat prefix (substring xrefs (match-beginning 1)
5721                                                     (match-end 1)))
5722                         (substring xrefs (match-beginning 1) (match-end 1))))
5723           (setq number
5724                 (string-to-int (substring xrefs (match-beginning 2)
5725                                           (match-end 2))))
5726           (if (setq entry (gnus-gethash group xref-hashtb))
5727               (setcdr entry (cons number (cdr entry)))
5728             (gnus-sethash group (cons number nil) xref-hashtb)))))
5729     (and start xref-hashtb)))
5730
5731 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5732   "Look through all the headers and mark the Xrefs as read."
5733   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5734         name info xref-hashtb idlist method nth4)
5735     (save-excursion
5736       (set-buffer gnus-group-buffer)
5737       (when (setq xref-hashtb
5738                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5739         (mapatoms
5740          (lambda (group)
5741            (unless (string= from-newsgroup (setq name (symbol-name group)))
5742              (setq idlist (symbol-value group))
5743              ;; Dead groups are not updated.
5744              (and (prog1
5745                       (setq info (gnus-get-info name))
5746                     (when (stringp (setq nth4 (gnus-info-method info)))
5747                       (setq nth4 (gnus-server-to-method nth4))))
5748                   ;; Only do the xrefs if the group has the same
5749                   ;; select method as the group we have just read.
5750                   (or (gnus-methods-equal-p
5751                        nth4 (gnus-find-method-for-group from-newsgroup))
5752                       virtual
5753                       (equal nth4 (setq method (gnus-find-method-for-group
5754                                                 from-newsgroup)))
5755                       (and (equal (car nth4) (car method))
5756                            (equal (nth 1 nth4) (nth 1 method))))
5757                   gnus-use-cross-reference
5758                   (or (not (eq gnus-use-cross-reference t))
5759                       virtual
5760                       ;; Only do cross-references on subscribed
5761                       ;; groups, if that is what is wanted.
5762                       (<= (gnus-info-level info) gnus-level-subscribed))
5763                   (gnus-group-make-articles-read name idlist))))
5764          xref-hashtb)))))
5765
5766 (defun gnus-compute-read-articles (group articles)
5767   (let* ((entry (gnus-group-entry group))
5768          (info (nth 2 entry))
5769          (active (gnus-active group))
5770          ninfo)
5771     (when entry
5772       ;; First peel off all invalid article numbers.
5773       (when active
5774         (let ((ids articles)
5775               id first)
5776           (while (setq id (pop ids))
5777             (when (and first (> id (cdr active)))
5778               ;; We'll end up in this situation in one particular
5779               ;; obscure situation.  If you re-scan a group and get
5780               ;; a new article that is cross-posted to a different
5781               ;; group that has not been re-scanned, you might get
5782               ;; crossposted article that has a higher number than
5783               ;; Gnus believes possible.  So we re-activate this
5784               ;; group as well.  This might mean doing the
5785               ;; crossposting thingy will *increase* the number
5786               ;; of articles in some groups.  Tsk, tsk.
5787               (setq active (or (gnus-activate-group group) active)))
5788             (when (or (> id (cdr active))
5789                       (< id (car active)))
5790               (setq articles (delq id articles))))))
5791       ;; If the read list is nil, we init it.
5792       (if (and active
5793                (null (gnus-info-read info))
5794                (> (car active) 1))
5795           (setq ninfo (cons 1 (1- (car active))))
5796         (setq ninfo (gnus-info-read info)))
5797       ;; Then we add the read articles to the range.
5798       (gnus-add-to-range
5799        ninfo (setq articles (sort articles '<))))))
5800
5801 (defun gnus-group-make-articles-read (group articles)
5802   "Update the info of GROUP to say that ARTICLES are read."
5803   (let* ((num 0)
5804          (entry (gnus-group-entry group))
5805          (info (nth 2 entry))
5806          (active (gnus-active group))
5807          range)
5808     (when entry
5809       (setq range (gnus-compute-read-articles group articles))
5810       (with-current-buffer gnus-group-buffer
5811         (gnus-undo-register
5812           `(progn
5813              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5814              (gnus-info-set-read ',info ',(gnus-info-read info))
5815              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5816              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5817              (gnus-group-update-group ,group t))))
5818       ;; Add the read articles to the range.
5819       (gnus-info-set-read info range)
5820       (gnus-request-set-mark group (list (list range 'add '(read))))
5821       ;; Then we have to re-compute how many unread
5822       ;; articles there are in this group.
5823       (when active
5824         (cond
5825          ((not range)
5826           (setq num (- (1+ (cdr active)) (car active))))
5827          ((not (listp (cdr range)))
5828           (setq num (- (cdr active) (- (1+ (cdr range))
5829                                        (car range)))))
5830          (t
5831           (while range
5832             (if (numberp (car range))
5833                 (setq num (1+ num))
5834               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5835             (setq range (cdr range)))
5836           (setq num (- (cdr active) num))))
5837         ;; Update the number of unread articles.
5838         (setcar entry num)
5839         ;; Update the group buffer.
5840         (unless (gnus-ephemeral-group-p group)
5841           (gnus-group-update-group group t))))))
5842
5843 (defvar gnus-newsgroup-none-id 0)
5844
5845 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5846   (let ((cur nntp-server-buffer)
5847         (dependencies
5848          (or dependencies
5849              (with-current-buffer gnus-summary-buffer
5850                gnus-newsgroup-dependencies)))
5851         headers id end ref number
5852         (mail-parse-charset gnus-newsgroup-charset)
5853         (mail-parse-ignored-charsets
5854          (save-excursion (condition-case nil
5855                              (set-buffer gnus-summary-buffer)
5856                            (error))
5857                          gnus-newsgroup-ignored-charsets)))
5858     (save-excursion
5859       (set-buffer nntp-server-buffer)
5860       ;; Translate all TAB characters into SPACE characters.
5861       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5862       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5863       (ietf-drums-unfold-fws)
5864       (gnus-run-hooks 'gnus-parse-headers-hook)
5865       (let ((case-fold-search t)
5866             in-reply-to header p lines chars)
5867         (goto-char (point-min))
5868         ;; Search to the beginning of the next header.  Error messages
5869         ;; do not begin with 2 or 3.
5870         (while (re-search-forward "^[23][0-9]+ " nil t)
5871           (setq id nil
5872                 ref nil)
5873           ;; This implementation of this function, with nine
5874           ;; search-forwards instead of the one re-search-forward and
5875           ;; a case (which basically was the old function) is actually
5876           ;; about twice as fast, even though it looks messier.  You
5877           ;; can't have everything, I guess.  Speed and elegance
5878           ;; doesn't always go hand in hand.
5879           (setq
5880            header
5881            (vector
5882             ;; Number.
5883             (prog1
5884                 (setq number (read cur))
5885               (end-of-line)
5886               (setq p (point))
5887               (narrow-to-region (point)
5888                                 (or (and (search-forward "\n.\n" nil t)
5889                                          (- (point) 2))
5890                                     (point))))
5891             ;; Subject.
5892             (progn
5893               (goto-char p)
5894               (if (search-forward "\nsubject:" nil t)
5895                   (funcall gnus-decode-encoded-word-function
5896                            (nnheader-header-value))
5897                 "(none)"))
5898             ;; From.
5899             (progn
5900               (goto-char p)
5901               (if (search-forward "\nfrom:" nil t)
5902                   (funcall gnus-decode-encoded-word-function
5903                            (nnheader-header-value))
5904                 "(nobody)"))
5905             ;; Date.
5906             (progn
5907               (goto-char p)
5908               (if (search-forward "\ndate:" nil t)
5909                   (nnheader-header-value) ""))
5910             ;; Message-ID.
5911             (progn
5912               (goto-char p)
5913               (setq id (if (re-search-forward
5914                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5915                            ;; We do it this way to make sure the Message-ID
5916                            ;; is (somewhat) syntactically valid.
5917                            (buffer-substring (match-beginning 1)
5918                                              (match-end 1))
5919                          ;; If there was no message-id, we just fake one
5920                          ;; to make subsequent routines simpler.
5921                          (nnheader-generate-fake-message-id number))))
5922             ;; References.
5923             (progn
5924               (goto-char p)
5925               (if (search-forward "\nreferences:" nil t)
5926                   (progn
5927                     (setq end (point))
5928                     (prog1
5929                         (nnheader-header-value)
5930                       (setq ref
5931                             (buffer-substring
5932                              (progn
5933                                (end-of-line)
5934                                (search-backward ">" end t)
5935                                (1+ (point)))
5936                              (progn
5937                                (search-backward "<" end t)
5938                                (point))))))
5939                 ;; Get the references from the in-reply-to header if there
5940                 ;; were no references and the in-reply-to header looks
5941                 ;; promising.
5942                 (if (and (search-forward "\nin-reply-to:" nil t)
5943                          (setq in-reply-to (nnheader-header-value))
5944                          (string-match "<[^>]+>" in-reply-to))
5945                     (let (ref2)
5946                       (setq ref (substring in-reply-to (match-beginning 0)
5947                                            (match-end 0)))
5948                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5949                         (setq ref2 (substring in-reply-to (match-beginning 0)
5950                                               (match-end 0)))
5951                         (when (> (length ref2) (length ref))
5952                           (setq ref ref2)))
5953                       ref)
5954                   (setq ref nil))))
5955             ;; Chars.
5956             (progn
5957               (goto-char p)
5958               (if (search-forward "\nchars: " nil t)
5959                   (if (numberp (setq chars (ignore-errors (read cur))))
5960                       chars -1)
5961                 -1))
5962             ;; Lines.
5963             (progn
5964               (goto-char p)
5965               (if (search-forward "\nlines: " nil t)
5966                   (if (numberp (setq lines (ignore-errors (read cur))))
5967                       lines -1)
5968                 -1))
5969             ;; Xref.
5970             (progn
5971               (goto-char p)
5972               (and (search-forward "\nxref:" nil t)
5973                    (nnheader-header-value)))
5974             ;; Extra.
5975             (when gnus-extra-headers
5976               (let ((extra gnus-extra-headers)
5977                     out)
5978                 (while extra
5979                   (goto-char p)
5980                   (when (search-forward
5981                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5982                     (push (cons (car extra) (nnheader-header-value))
5983                           out))
5984                   (pop extra))
5985                 out))))
5986           (when (equal id ref)
5987             (setq ref nil))
5988
5989           (when gnus-alter-header-function
5990             (funcall gnus-alter-header-function header)
5991             (setq id (mail-header-id header)
5992                   ref (gnus-parent-id (mail-header-references header))))
5993
5994           (when (setq header
5995                       (gnus-dependencies-add-header
5996                        header dependencies force-new))
5997             (push header headers))
5998           (goto-char (point-max))
5999           (widen))
6000         (nreverse headers)))))
6001
6002 ;; Goes through the xover lines and returns a list of vectors
6003 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6004                                                   force-new dependencies
6005                                                   group also-fetch-heads)
6006   "Parse the news overview data in the server buffer.
6007 Return a list of headers that match SEQUENCE (see
6008 `nntp-retrieve-headers')."
6009   ;; Get the Xref when the users reads the articles since most/some
6010   ;; NNTP servers do not include Xrefs when using XOVER.
6011   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6012   (let ((mail-parse-charset gnus-newsgroup-charset)
6013         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6014         (cur nntp-server-buffer)
6015         (dependencies (or dependencies gnus-newsgroup-dependencies))
6016         (allp (cond
6017                ((eq gnus-read-all-available-headers t)
6018                 t)
6019                ((stringp gnus-read-all-available-headers)
6020                 (string-match gnus-read-all-available-headers group))
6021                (t
6022                 nil)))
6023         number headers header)
6024     (save-excursion
6025       (set-buffer nntp-server-buffer)
6026       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6027       ;; Allow the user to mangle the headers before parsing them.
6028       (gnus-run-hooks 'gnus-parse-headers-hook)
6029       (goto-char (point-min))
6030       (gnus-parse-without-error
6031         (while (and (or sequence allp)
6032                     (not (eobp)))
6033           (setq number (read cur))
6034           (when (not allp)
6035             (while (and sequence
6036                         (< (car sequence) number))
6037               (setq sequence (cdr sequence))))
6038           (when (and (or allp
6039                          (and sequence
6040                               (eq number (car sequence))))
6041                      (progn
6042                        (setq sequence (cdr sequence))
6043                        (setq header (inline
6044                                       (gnus-nov-parse-line
6045                                        number dependencies force-new)))))
6046             (push header headers))
6047           (forward-line 1)))
6048       ;; A common bug in inn is that if you have posted an article and
6049       ;; then retrieves the active file, it will answer correctly --
6050       ;; the new article is included.  However, a NOV entry for the
6051       ;; article may not have been generated yet, so this may fail.
6052       ;; We work around this problem by retrieving the last few
6053       ;; headers using HEAD.
6054       (if (or (not also-fetch-heads)
6055               (not sequence))
6056           ;; We (probably) got all the headers.
6057           (nreverse headers)
6058         (let ((gnus-nov-is-evil t))
6059           (nconc
6060            (nreverse headers)
6061            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6062              (gnus-get-newsgroup-headers))))))))
6063
6064 (defun gnus-article-get-xrefs ()
6065   "Fill in the Xref value in `gnus-current-headers', if necessary.
6066 This is meant to be called in `gnus-article-internal-prepare-hook'."
6067   (let ((headers (with-current-buffer gnus-summary-buffer
6068                    gnus-current-headers)))
6069     (or (not gnus-use-cross-reference)
6070         (not headers)
6071         (and (mail-header-xref headers)
6072              (not (string= (mail-header-xref headers) "")))
6073         (let ((case-fold-search t)
6074               xref)
6075           (save-restriction
6076             (nnheader-narrow-to-headers)
6077             (goto-char (point-min))
6078             (when (or (and (not (eobp))
6079                            (eq (downcase (char-after)) ?x)
6080                            (looking-at "Xref:"))
6081                       (search-forward "\nXref:" nil t))
6082               (goto-char (1+ (match-end 0)))
6083               (setq xref (buffer-substring (point) (point-at-eol)))
6084               (mail-header-set-xref headers xref)))))))
6085
6086 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6087   "Find article ID and insert the summary line for that article.
6088 OLD-HEADER can either be a header or a line number to insert
6089 the subject line on."
6090   (let* ((line (and (numberp old-header) old-header))
6091          (old-header (and (vectorp old-header) old-header))
6092          (header (cond ((and old-header use-old-header)
6093                         old-header)
6094                        ((and (numberp id)
6095                              (gnus-number-to-header id))
6096                         (gnus-number-to-header id))
6097                        (t
6098                         (gnus-read-header id))))
6099          (number (and (numberp id) id))
6100          d)
6101     (when header
6102       ;; Rebuild the thread that this article is part of and go to the
6103       ;; article we have fetched.
6104       (when (and (not gnus-show-threads)
6105                  old-header)
6106         (when (and number
6107                    (setq d (gnus-data-find (mail-header-number old-header))))
6108           (goto-char (gnus-data-pos d))
6109           (gnus-data-remove
6110            number
6111            (- (point-at-bol)
6112               (prog1
6113                   (1+ (point-at-eol))
6114                 (gnus-delete-line))))))
6115       ;; Remove list identifiers from subject.
6116       (when gnus-list-identifiers
6117         (let ((gnus-newsgroup-headers (list header)))
6118           (gnus-summary-remove-list-identifiers)))
6119       (when old-header
6120         (mail-header-set-number header (mail-header-number old-header)))
6121       (setq gnus-newsgroup-sparse
6122             (delq (setq number (mail-header-number header))
6123                   gnus-newsgroup-sparse))
6124       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6125       (push number gnus-newsgroup-limit)
6126       (gnus-rebuild-thread (mail-header-id header) line)
6127       (gnus-summary-goto-subject number nil t))
6128     (when (and (numberp number)
6129                (> number 0))
6130       ;; We have to update the boundaries even if we can't fetch the
6131       ;; article if ID is a number -- so that the next `P' or `N'
6132       ;; command will fetch the previous (or next) article even
6133       ;; if the one we tried to fetch this time has been canceled.
6134       (when (> number gnus-newsgroup-end)
6135         (setq gnus-newsgroup-end number))
6136       (when (< number gnus-newsgroup-begin)
6137         (setq gnus-newsgroup-begin number))
6138       (setq gnus-newsgroup-unselected
6139             (delq number gnus-newsgroup-unselected)))
6140     ;; Report back a success?
6141     (and header (mail-header-number header))))
6142
6143 ;;; Process/prefix in the summary buffer
6144
6145 (defun gnus-summary-work-articles (n)
6146   "Return a list of articles to be worked upon.
6147 The prefix argument, the list of process marked articles, and the
6148 current article will be taken into consideration."
6149   (save-excursion
6150     (set-buffer gnus-summary-buffer)
6151     (cond
6152      (n
6153       ;; A numerical prefix has been given.
6154       (setq n (prefix-numeric-value n))
6155       (let ((backward (< n 0))
6156             (n (abs (prefix-numeric-value n)))
6157             articles article)
6158         (save-excursion
6159           (while
6160               (and (> n 0)
6161                    (push (setq article (gnus-summary-article-number))
6162                          articles)
6163                    (if backward
6164                        (gnus-summary-find-prev nil article)
6165                      (gnus-summary-find-next nil article)))
6166             (decf n)))
6167         (nreverse articles)))
6168      ((and (gnus-region-active-p) (mark))
6169       (message "region active")
6170       ;; Work on the region between point and mark.
6171       (let ((max (max (point) (mark)))
6172             articles article)
6173         (save-excursion
6174           (goto-char (min (min (point) (mark))))
6175           (while
6176               (and
6177                (push (setq article (gnus-summary-article-number)) articles)
6178                (gnus-summary-find-next nil article)
6179                (< (point) max)))
6180           (nreverse articles))))
6181      (gnus-newsgroup-processable
6182       ;; There are process-marked articles present.
6183       ;; Save current state.
6184       (gnus-summary-save-process-mark)
6185       ;; Return the list.
6186       (reverse gnus-newsgroup-processable))
6187      (t
6188       ;; Just return the current article.
6189       (list (gnus-summary-article-number))))))
6190
6191 (defmacro gnus-summary-iterate (arg &rest forms)
6192   "Iterate over the process/prefixed articles and do FORMS.
6193 ARG is the interactive prefix given to the command.  FORMS will be
6194 executed with point over the summary line of the articles."
6195   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6196     `(let ((,articles (gnus-summary-work-articles ,arg)))
6197        (while ,articles
6198          (gnus-summary-goto-subject (car ,articles))
6199          ,@forms
6200          (pop ,articles)))))
6201
6202 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6203 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6204
6205 (defun gnus-summary-save-process-mark ()
6206   "Push the current set of process marked articles on the stack."
6207   (interactive)
6208   (push (copy-sequence gnus-newsgroup-processable)
6209         gnus-newsgroup-process-stack))
6210
6211 (defun gnus-summary-kill-process-mark ()
6212   "Push the current set of process marked articles on the stack and unmark."
6213   (interactive)
6214   (gnus-summary-save-process-mark)
6215   (gnus-summary-unmark-all-processable))
6216
6217 (defun gnus-summary-yank-process-mark ()
6218   "Pop the last process mark state off the stack and restore it."
6219   (interactive)
6220   (unless gnus-newsgroup-process-stack
6221     (error "Empty mark stack"))
6222   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6223
6224 (defun gnus-summary-process-mark-set (set)
6225   "Make SET into the current process marked articles."
6226   (gnus-summary-unmark-all-processable)
6227   (mapc 'gnus-summary-set-process-mark set))
6228
6229 ;;; Searching and stuff
6230
6231 (defun gnus-summary-search-group (&optional backward use-level)
6232   "Search for next unread newsgroup.
6233 If optional argument BACKWARD is non-nil, search backward instead."
6234   (save-excursion
6235     (set-buffer gnus-group-buffer)
6236     (when (gnus-group-search-forward
6237            backward nil (if use-level (gnus-group-group-level) nil))
6238       (gnus-group-group-name))))
6239
6240 (defun gnus-summary-best-group (&optional exclude-group)
6241   "Find the name of the best unread group.
6242 If EXCLUDE-GROUP, do not go to this group."
6243   (with-current-buffer gnus-group-buffer
6244     (save-excursion
6245       (gnus-group-best-unread-group exclude-group))))
6246
6247 (defun gnus-summary-find-next (&optional unread article backward)
6248   (if backward
6249       (gnus-summary-find-prev unread article)
6250     (let* ((dummy (gnus-summary-article-intangible-p))
6251            (article (or article (gnus-summary-article-number)))
6252            (data (gnus-data-find-list article))
6253            result)
6254       (when (and (not dummy)
6255                  (or (not gnus-summary-check-current)
6256                      (not unread)
6257                      (not (gnus-data-unread-p (car data)))))
6258         (setq data (cdr data)))
6259       (when (setq result
6260                   (if unread
6261                       (progn
6262                         (while data
6263                           (unless (memq (gnus-data-number (car data))
6264                                         (cond
6265                                          ((eq gnus-auto-goto-ignores
6266                                               'always-undownloaded)
6267                                           gnus-newsgroup-undownloaded)
6268                                          (gnus-plugged
6269                                           nil)
6270                                          ((eq gnus-auto-goto-ignores
6271                                               'unfetched)
6272                                           gnus-newsgroup-unfetched)
6273                                          ((eq gnus-auto-goto-ignores
6274                                               'undownloaded)
6275                                           gnus-newsgroup-undownloaded)))
6276                             (when (gnus-data-unread-p (car data))
6277                               (setq result (car data)
6278                                     data nil)))
6279                           (setq data (cdr data)))
6280                         result)
6281                     (car data)))
6282         (goto-char (gnus-data-pos result))
6283         (gnus-data-number result)))))
6284
6285 (defun gnus-summary-find-prev (&optional unread article)
6286   (let* ((eobp (eobp))
6287          (article (or article (gnus-summary-article-number)))
6288          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6289          result)
6290     (when (and (not eobp)
6291                (or (not gnus-summary-check-current)
6292                    (not unread)
6293                    (not (gnus-data-unread-p (car data)))))
6294       (setq data (cdr data)))
6295     (when (setq result
6296                 (if unread
6297                     (progn
6298                       (while data
6299                         (unless (memq (gnus-data-number (car data))
6300                                       (cond
6301                                        ((eq gnus-auto-goto-ignores
6302                                             'always-undownloaded)
6303                                         gnus-newsgroup-undownloaded)
6304                                        (gnus-plugged
6305                                         nil)
6306                                        ((eq gnus-auto-goto-ignores
6307                                             'unfetched)
6308                                         gnus-newsgroup-unfetched)
6309                                        ((eq gnus-auto-goto-ignores
6310                                             'undownloaded)
6311                                         gnus-newsgroup-undownloaded)))
6312                           (when (gnus-data-unread-p (car data))
6313                             (setq result (car data)
6314                                   data nil)))
6315                         (setq data (cdr data)))
6316                       result)
6317                   (car data)))
6318       (goto-char (gnus-data-pos result))
6319       (gnus-data-number result))))
6320
6321 (defun gnus-summary-find-subject (subject &optional unread backward article)
6322   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6323          (article (or article (gnus-summary-article-number)))
6324          (articles (gnus-data-list backward))
6325          (arts (gnus-data-find-list article articles))
6326          result)
6327     (when (or (not gnus-summary-check-current)
6328               (not unread)
6329               (not (gnus-data-unread-p (car arts))))
6330       (setq arts (cdr arts)))
6331     (while arts
6332       (and (or (not unread)
6333                (gnus-data-unread-p (car arts)))
6334            (vectorp (gnus-data-header (car arts)))
6335            (gnus-subject-equal
6336             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6337            (setq result (car arts)
6338                  arts nil))
6339       (setq arts (cdr arts)))
6340     (and result
6341          (goto-char (gnus-data-pos result))
6342          (gnus-data-number result))))
6343
6344 (defun gnus-summary-search-forward (&optional unread subject backward)
6345   "Search forward for an article.
6346 If UNREAD, look for unread articles.  If SUBJECT, look for
6347 articles with that subject.  If BACKWARD, search backward instead."
6348   (cond (subject (gnus-summary-find-subject subject unread backward))
6349         (backward (gnus-summary-find-prev unread))
6350         (t (gnus-summary-find-next unread))))
6351
6352 (defun gnus-recenter (&optional n)
6353   "Center point in window and redisplay frame.
6354 Also do horizontal recentering."
6355   (interactive "P")
6356   (when (and gnus-auto-center-summary
6357              (not (eq gnus-auto-center-summary 'vertical)))
6358     (gnus-horizontal-recenter))
6359   (recenter n))
6360
6361 (defun gnus-summary-recenter ()
6362   "Center point in the summary window.
6363 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6364 displayed, no centering will be performed."
6365   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6366   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6367   (interactive)
6368   ;; The user has to want it.
6369   (when gnus-auto-center-summary
6370     (let* ((top (cond ((< (window-height) 4) 0)
6371                       ((< (window-height) 7) 1)
6372                       (t (if (numberp gnus-auto-center-summary)
6373                              gnus-auto-center-summary
6374                            (/ (1- (window-height)) 2)))))
6375            (height (1- (window-height)))
6376            (bottom (save-excursion (goto-char (point-max))
6377                                    (forward-line (- height))
6378                                    (point)))
6379            (window (get-buffer-window (current-buffer))))
6380       (when (get-buffer-window gnus-article-buffer)
6381         ;; Only do recentering when the article buffer is displayed,
6382         ;; Set the window start to either `bottom', which is the biggest
6383         ;; possible valid number, or the second line from the top,
6384         ;; whichever is the least.
6385         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6386           (if (> bottom top-pos)
6387               ;; Keep the second line from the top visible
6388               (set-window-start window top-pos t)
6389             ;; Try to keep the bottom line visible; if it's partially
6390             ;; obscured, either scroll one more line to make it fully
6391             ;; visible, or revert to using TOP-POS.
6392             (save-excursion
6393               (goto-char (point-max))
6394               (forward-line -1)
6395               (let ((last-line-start (point)))
6396                 (goto-char bottom)
6397                 (set-window-start window (point) t)
6398                 (when (not (pos-visible-in-window-p last-line-start window))
6399                   (forward-line 1)
6400                   (set-window-start window (min (point) top-pos) t)))))))
6401       ;; Do horizontal recentering while we're at it.
6402       (when (and (get-buffer-window (current-buffer) t)
6403                  (not (eq gnus-auto-center-summary 'vertical)))
6404         (let ((selected (selected-window)))
6405           (select-window (get-buffer-window (current-buffer) t))
6406           (gnus-summary-position-point)
6407           (gnus-horizontal-recenter)
6408           (select-window selected))))))
6409
6410 (defun gnus-summary-jump-to-group (newsgroup)
6411   "Move point to NEWSGROUP in group mode buffer."
6412   ;; Keep update point of group mode buffer if visible.
6413   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6414       (save-window-excursion
6415         ;; Take care of tree window mode.
6416         (when (get-buffer-window gnus-group-buffer)
6417           (pop-to-buffer gnus-group-buffer))
6418         (gnus-group-jump-to-group newsgroup))
6419     (save-excursion
6420       ;; Take care of tree window mode.
6421       (if (get-buffer-window gnus-group-buffer)
6422           (pop-to-buffer gnus-group-buffer)
6423         (set-buffer gnus-group-buffer))
6424       (gnus-group-jump-to-group newsgroup))))
6425
6426 ;; This function returns a list of article numbers based on the
6427 ;; difference between the ranges of read articles in this group and
6428 ;; the range of active articles.
6429 (defun gnus-list-of-unread-articles (group)
6430   (let* ((read (gnus-info-read (gnus-get-info group)))
6431          (active (or (gnus-active group) (gnus-activate-group group)))
6432          (last (or (cdr active)
6433                    (error "Group %s couldn't be activated " group)))
6434          first nlast unread)
6435     ;; If none are read, then all are unread.
6436     (if (not read)
6437         (setq first (car active))
6438       ;; If the range of read articles is a single range, then the
6439       ;; first unread article is the article after the last read
6440       ;; article.  Sounds logical, doesn't it?
6441       (if (and (not (listp (cdr read)))
6442                (or (< (car read) (car active))
6443                    (progn (setq read (list read))
6444                           nil)))
6445           (setq first (max (car active) (1+ (cdr read))))
6446         ;; `read' is a list of ranges.
6447         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6448                                   (caar read)))
6449                   1)
6450           (setq first (car active)))
6451         (while read
6452           (when first
6453             (while (< first nlast)
6454               (setq unread (cons first unread)
6455                     first (1+ first))))
6456           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6457           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6458           (setq read (cdr read)))))
6459     ;; And add the last unread articles.
6460     (while (<= first last)
6461       (setq unread (cons first unread)
6462             first (1+ first)))
6463     ;; Return the list of unread articles.
6464     (delq 0 (nreverse unread))))
6465
6466 (defun gnus-list-of-read-articles (group)
6467   "Return a list of unread, unticked and non-dormant articles."
6468   (let* ((info (gnus-get-info group))
6469          (marked (gnus-info-marks info))
6470          (active (gnus-active group)))
6471     (and info active
6472          (gnus-list-range-difference
6473           (gnus-list-range-difference
6474            (gnus-sorted-complement
6475             (gnus-uncompress-range active)
6476             (gnus-list-of-unread-articles group))
6477            (cdr (assq 'dormant marked)))
6478           (cdr (assq 'tick marked))))))
6479
6480 ;; This function returns a sequence of article numbers based on the
6481 ;; difference between the ranges of read articles in this group and
6482 ;; the range of active articles.
6483 (defun gnus-sequence-of-unread-articles (group)
6484   (let* ((read (gnus-info-read (gnus-get-info group)))
6485          (active (or (gnus-active group) (gnus-activate-group group)))
6486          (last (cdr active))
6487          first nlast unread)
6488     ;; If none are read, then all are unread.
6489     (if (not read)
6490         (setq first (car active))
6491       ;; If the range of read articles is a single range, then the
6492       ;; first unread article is the article after the last read
6493       ;; article.  Sounds logical, doesn't it?
6494       (if (and (not (listp (cdr read)))
6495                (or (< (car read) (car active))
6496                    (progn (setq read (list read))
6497                           nil)))
6498           (setq first (max (car active) (1+ (cdr read))))
6499         ;; `read' is a list of ranges.
6500         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6501                                   (caar read)))
6502                   1)
6503           (setq first (car active)))
6504         (while read
6505           (when first
6506             (push (cons first nlast) unread))
6507           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6508           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6509           (setq read (cdr read)))))
6510     ;; And add the last unread articles.
6511     (cond ((< first last)
6512            (push (cons first last) unread))
6513           ((= first last)
6514            (push first unread)))
6515     ;; Return the sequence of unread articles.
6516     (delq 0 (nreverse unread))))
6517
6518 ;; Various summary commands
6519
6520 (defun gnus-summary-select-article-buffer ()
6521   "Reconfigure windows to show article buffer."
6522   (interactive)
6523   (if (not (gnus-buffer-live-p gnus-article-buffer))
6524       (error "There is no article buffer for this summary buffer")
6525     (gnus-configure-windows 'article)
6526     (select-window (get-buffer-window gnus-article-buffer))))
6527
6528 (defun gnus-summary-universal-argument (arg)
6529   "Perform any operation on all articles that are process/prefixed."
6530   (interactive "P")
6531   (let ((articles (gnus-summary-work-articles arg))
6532         func article)
6533     (if (eq
6534          (setq
6535           func
6536           (key-binding
6537            (read-key-sequence
6538             (substitute-command-keys
6539              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6540          'undefined)
6541         (gnus-error 1 "Undefined key")
6542       (save-excursion
6543         (while articles
6544           (gnus-summary-goto-subject (setq article (pop articles)))
6545           (let (gnus-newsgroup-processable)
6546             (command-execute func))
6547           (gnus-summary-remove-process-mark article)))))
6548   (gnus-summary-position-point))
6549
6550 (defun gnus-summary-toggle-truncation (&optional arg)
6551   "Toggle truncation of summary lines.
6552 With ARG, turn line truncation on if ARG is positive."
6553   (interactive "P")
6554   (setq truncate-lines
6555         (if (null arg) (not truncate-lines)
6556           (> (prefix-numeric-value arg) 0)))
6557   (redraw-display))
6558
6559 (defun gnus-summary-find-for-reselect ()
6560   "Return the number of an article to stay on across a reselect.
6561 The current article is considered, then following articles, then previous
6562 articles.  An article is sought which is not cancelled and isn't a temporary
6563 insertion from another group.  If there's no such then return a dummy 0."
6564   (let (found)
6565     (dolist (rev '(nil t))
6566       (unless found      ; don't demand the reverse list if we don't need it
6567         (let ((data (gnus-data-find-list
6568                      (gnus-summary-article-number) (gnus-data-list rev))))
6569           (while (and data (not found))
6570             (if (and (< 0 (gnus-data-number (car data)))
6571                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6572                 (setq found (gnus-data-number (car data))))
6573             (setq data (cdr data))))))
6574     (or found 0)))
6575
6576 (defun gnus-summary-reselect-current-group (&optional all rescan)
6577   "Exit and then reselect the current newsgroup.
6578 The prefix argument ALL means to select all articles."
6579   (interactive "P")
6580   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6581     (error "Ephemeral groups can't be reselected"))
6582   (let ((current-subject (gnus-summary-find-for-reselect))
6583         (group gnus-newsgroup-name))
6584     (setq gnus-newsgroup-begin nil)
6585     (gnus-summary-exit nil 'leave-hidden)
6586     ;; We have to adjust the point of group mode buffer because
6587     ;; point was moved to the next unread newsgroup by exiting.
6588     (gnus-summary-jump-to-group group)
6589     (when rescan
6590       (save-excursion
6591         (gnus-group-get-new-news-this-group 1)))
6592     (gnus-group-read-group all t)
6593     (gnus-summary-goto-subject current-subject nil t)))
6594
6595 (defun gnus-summary-rescan-group (&optional all)
6596   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6597   (interactive "P")
6598   (gnus-summary-reselect-current-group all t))
6599
6600 (defun gnus-summary-update-info (&optional non-destructive)
6601   (save-excursion
6602     (let ((group gnus-newsgroup-name))
6603       (when group
6604         (when gnus-newsgroup-kill-headers
6605           (setq gnus-newsgroup-killed
6606                 (gnus-compress-sequence
6607                  (gnus-sorted-union
6608                   (gnus-list-range-intersection
6609                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6610                   gnus-newsgroup-unreads)
6611                  t)))
6612         (unless (listp (cdr gnus-newsgroup-killed))
6613           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6614         (let ((headers gnus-newsgroup-headers))
6615           ;; Set the new ranges of read articles.
6616           (with-current-buffer gnus-group-buffer
6617             (gnus-undo-force-boundary))
6618           (gnus-update-read-articles
6619            group (gnus-sorted-union
6620                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6621           ;; Set the current article marks.
6622           (let ((gnus-newsgroup-scored
6623                  (if (and (not gnus-save-score)
6624                           (not non-destructive))
6625                      nil
6626                    gnus-newsgroup-scored)))
6627             (save-excursion
6628               (gnus-update-marks)))
6629           ;; Do the cross-ref thing.
6630           (when gnus-use-cross-reference
6631             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6632           ;; Do not switch windows but change the buffer to work.
6633           (set-buffer gnus-group-buffer)
6634           (unless (gnus-ephemeral-group-p group)
6635             (gnus-group-update-group group)))))))
6636
6637 (defun gnus-summary-save-newsrc (&optional force)
6638   "Save the current number of read/marked articles in the dribble buffer.
6639 The dribble buffer will then be saved.
6640 If FORCE (the prefix), also save the .newsrc file(s)."
6641   (interactive "P")
6642   (gnus-summary-update-info t)
6643   (if force
6644       (gnus-save-newsrc-file)
6645     (gnus-dribble-save)))
6646
6647 (defun gnus-summary-exit (&optional temporary leave-hidden)
6648   "Exit reading current newsgroup, and then return to group selection mode.
6649 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6650   (interactive)
6651   (gnus-set-global-variables)
6652   (when (gnus-buffer-live-p gnus-article-buffer)
6653     (save-excursion
6654       (set-buffer gnus-article-buffer)
6655       (mm-destroy-parts gnus-article-mime-handles)
6656       ;; Set it to nil for safety reason.
6657       (setq gnus-article-mime-handle-alist nil)
6658       (setq gnus-article-mime-handles nil)))
6659   (gnus-kill-save-kill-buffer)
6660   (gnus-async-halt-prefetch)
6661   (let* ((group gnus-newsgroup-name)
6662          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6663          (gnus-group-is-exiting-p t)
6664          (mode major-mode)
6665          (group-point nil)
6666          (buf (current-buffer)))
6667     (unless quit-config
6668       ;; Do adaptive scoring, and possibly save score files.
6669       (when gnus-newsgroup-adaptive
6670         (gnus-score-adaptive))
6671       (when gnus-use-scoring
6672         (gnus-score-save)))
6673     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6674     ;; If we have several article buffers, we kill them at exit.
6675     (unless gnus-single-article-buffer
6676       (gnus-kill-buffer gnus-original-article-buffer)
6677       (setq gnus-article-current nil))
6678     (when gnus-use-cache
6679       (gnus-cache-possibly-remove-articles)
6680       (gnus-cache-save-buffers))
6681     (gnus-async-prefetch-remove-group group)
6682     (when gnus-suppress-duplicates
6683       (gnus-dup-enter-articles))
6684     (when gnus-use-trees
6685       (gnus-tree-close group))
6686     (when gnus-use-cache
6687       (gnus-cache-write-active))
6688     ;; Remove entries for this group.
6689     (nnmail-purge-split-history (gnus-group-real-name group))
6690     ;; Make all changes in this group permanent.
6691     (unless quit-config
6692       (gnus-run-hooks 'gnus-exit-group-hook)
6693       (gnus-summary-update-info))
6694     (gnus-close-group group)
6695     ;; Make sure where we were, and go to next newsgroup.
6696     (set-buffer gnus-group-buffer)
6697     (unless quit-config
6698       (gnus-group-jump-to-group group))
6699     (gnus-run-hooks 'gnus-summary-exit-hook)
6700     (unless (or quit-config
6701                 ;; If this group has disappeared from the summary
6702                 ;; buffer, don't skip forwards.
6703                 (not (string= group (gnus-group-group-name))))
6704       (gnus-group-next-unread-group 1))
6705     (setq group-point (point))
6706     (if temporary
6707         nil                             ;Nothing to do.
6708       ;; If we have several article buffers, we kill them at exit.
6709       (unless gnus-single-article-buffer
6710         (gnus-kill-buffer gnus-article-buffer)
6711         (gnus-kill-buffer gnus-original-article-buffer)
6712         (setq gnus-article-current nil))
6713       (set-buffer buf)
6714       (if (not gnus-kill-summary-on-exit)
6715           (progn
6716             (gnus-deaden-summary)
6717             (setq mode nil))
6718         ;; We set all buffer-local variables to nil.  It is unclear why
6719         ;; this is needed, but if we don't, buffer-local variables are
6720         ;; not garbage-collected, it seems.  This would the lead to en
6721         ;; ever-growing Emacs.
6722         (gnus-summary-clear-local-variables)
6723         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6724           (gnus-summary-clear-local-variables))
6725         (when (get-buffer gnus-article-buffer)
6726           (bury-buffer gnus-article-buffer))
6727         ;; Return to group mode buffer.
6728         (when (eq mode 'gnus-summary-mode)
6729           (gnus-kill-buffer buf)))
6730       (setq gnus-current-select-method gnus-select-method)
6731       (set-buffer gnus-group-buffer)
6732       (if quit-config
6733           (gnus-handle-ephemeral-exit quit-config)
6734         (goto-char group-point)
6735         (unless leave-hidden
6736           (gnus-configure-windows 'group 'force)))
6737       ;; Clear the current group name.
6738       (unless quit-config
6739         (setq gnus-newsgroup-name nil)))))
6740
6741 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6742 (defun gnus-summary-exit-no-update (&optional no-questions)
6743   "Quit reading current newsgroup without updating read article info."
6744   (interactive)
6745   (let* ((group gnus-newsgroup-name)
6746          (gnus-group-is-exiting-p t)
6747          (gnus-group-is-exiting-without-update-p t)
6748          (quit-config (gnus-group-quit-config group)))
6749     (when (or no-questions
6750               gnus-expert-user
6751               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6752       (gnus-async-halt-prefetch)
6753       (run-hooks 'gnus-summary-prepare-exit-hook)
6754       (when (gnus-buffer-live-p gnus-article-buffer)
6755         (save-excursion
6756           (set-buffer gnus-article-buffer)
6757           (mm-destroy-parts gnus-article-mime-handles)
6758           ;; Set it to nil for safety reason.
6759           (setq gnus-article-mime-handle-alist nil)
6760           (setq gnus-article-mime-handles nil)))
6761       ;; If we have several article buffers, we kill them at exit.
6762       (unless gnus-single-article-buffer
6763         (gnus-kill-buffer gnus-article-buffer)
6764         (gnus-kill-buffer gnus-original-article-buffer)
6765         (setq gnus-article-current nil))
6766       (if (not gnus-kill-summary-on-exit)
6767           (gnus-deaden-summary)
6768         (gnus-close-group group)
6769         (gnus-summary-clear-local-variables)
6770         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6771           (gnus-summary-clear-local-variables))
6772         (gnus-kill-buffer gnus-summary-buffer))
6773       (unless gnus-single-article-buffer
6774         (setq gnus-article-current nil))
6775       (when gnus-use-trees
6776         (gnus-tree-close group))
6777       (gnus-async-prefetch-remove-group group)
6778       (when (get-buffer gnus-article-buffer)
6779         (bury-buffer gnus-article-buffer))
6780       ;; Return to the group buffer.
6781       (gnus-configure-windows 'group 'force)
6782       ;; Clear the current group name.
6783       (setq gnus-newsgroup-name nil)
6784       (unless (gnus-ephemeral-group-p group)
6785         (gnus-group-update-group group))
6786       (when (equal (gnus-group-group-name) group)
6787         (gnus-group-next-unread-group 1))
6788       (when quit-config
6789         (gnus-handle-ephemeral-exit quit-config)))))
6790
6791 (defun gnus-handle-ephemeral-exit (quit-config)
6792   "Handle movement when leaving an ephemeral group.
6793 The state which existed when entering the ephemeral is reset."
6794   (if (not (buffer-name (car quit-config)))
6795       (gnus-configure-windows 'group 'force)
6796     (set-buffer (car quit-config))
6797     (cond ((eq major-mode 'gnus-summary-mode)
6798            (gnus-set-global-variables))
6799           ((eq major-mode 'gnus-article-mode)
6800            (save-excursion
6801              ;; The `gnus-summary-buffer' variable may point
6802              ;; to the old summary buffer when using a single
6803              ;; article buffer.
6804              (unless (gnus-buffer-live-p gnus-summary-buffer)
6805                (set-buffer gnus-group-buffer))
6806              (set-buffer gnus-summary-buffer)
6807              (gnus-set-global-variables))))
6808     (if (or (eq (cdr quit-config) 'article)
6809             (eq (cdr quit-config) 'pick))
6810         (progn
6811           ;; The current article may be from the ephemeral group
6812           ;; thus it is best that we reload this article
6813           ;;
6814           ;; If we're exiting from a large digest, this can be
6815           ;; extremely slow.  So, it's better not to reload it. -- jh.
6816           ;;(gnus-summary-show-article)
6817           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6818               (gnus-configure-windows 'pick 'force)
6819             (gnus-configure-windows (cdr quit-config) 'force)))
6820       (gnus-configure-windows (cdr quit-config) 'force))
6821     (when (eq major-mode 'gnus-summary-mode)
6822       (gnus-summary-next-subject 1 nil t)
6823       (gnus-summary-recenter)
6824       (gnus-summary-position-point))))
6825
6826 ;;; Dead summaries.
6827
6828 (defvar gnus-dead-summary-mode-map nil)
6829
6830 (unless gnus-dead-summary-mode-map
6831   (setq gnus-dead-summary-mode-map (make-keymap))
6832   (suppress-keymap gnus-dead-summary-mode-map)
6833   (substitute-key-definition
6834    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6835   (dolist (key '("\C-d" "\r" "\177" [delete]))
6836     (define-key gnus-dead-summary-mode-map
6837       key 'gnus-summary-wake-up-the-dead))
6838   (dolist (key '("q" "Q"))
6839     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6840
6841 (defvar gnus-dead-summary-mode nil
6842   "Minor mode for Gnus summary buffers.")
6843
6844 (defun gnus-dead-summary-mode (&optional arg)
6845   "Minor mode for Gnus summary buffers."
6846   (interactive "P")
6847   (when (eq major-mode 'gnus-summary-mode)
6848     (make-local-variable 'gnus-dead-summary-mode)
6849     (setq gnus-dead-summary-mode
6850           (if (null arg) (not gnus-dead-summary-mode)
6851             (> (prefix-numeric-value arg) 0)))
6852     (when gnus-dead-summary-mode
6853       (add-minor-mode
6854        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6855
6856 (defun gnus-deaden-summary ()
6857   "Make the current summary buffer into a dead summary buffer."
6858   ;; Kill any previous dead summary buffer.
6859   (when (and gnus-dead-summary
6860              (buffer-name gnus-dead-summary))
6861     (with-current-buffer gnus-dead-summary
6862       (when gnus-dead-summary-mode
6863         (kill-buffer (current-buffer)))))
6864   ;; Make this the current dead summary.
6865   (setq gnus-dead-summary (current-buffer))
6866   (gnus-dead-summary-mode 1)
6867   (let ((name (buffer-name)))
6868     (when (string-match "Summary" name)
6869       (rename-buffer
6870        (concat (substring name 0 (match-beginning 0)) "Dead "
6871                (substring name (match-beginning 0)))
6872        t)
6873       (bury-buffer))))
6874
6875 (defun gnus-kill-or-deaden-summary (buffer)
6876   "Kill or deaden the summary BUFFER."
6877   (save-excursion
6878     (when (and (buffer-name buffer)
6879                (not gnus-single-article-buffer))
6880       (with-current-buffer buffer
6881         (gnus-kill-buffer gnus-article-buffer)
6882         (gnus-kill-buffer gnus-original-article-buffer)))
6883     (cond
6884      ;; Kill the buffer.
6885      (gnus-kill-summary-on-exit
6886       (when (and gnus-use-trees
6887                  (gnus-buffer-exists-p buffer))
6888         (save-excursion
6889           (set-buffer buffer)
6890           (gnus-tree-close gnus-newsgroup-name)))
6891       (gnus-kill-buffer buffer))
6892      ;; Deaden the buffer.
6893      ((gnus-buffer-exists-p buffer)
6894       (save-excursion
6895         (set-buffer buffer)
6896         (gnus-deaden-summary))))))
6897
6898 (defun gnus-summary-wake-up-the-dead (&rest args)
6899   "Wake up the dead summary buffer."
6900   (interactive)
6901   (gnus-dead-summary-mode -1)
6902   (let ((name (buffer-name)))
6903     (when (string-match "Dead " name)
6904       (rename-buffer
6905        (concat (substring name 0 (match-beginning 0))
6906                (substring name (match-end 0)))
6907        t)))
6908   (gnus-message 3 "This dead summary is now alive again"))
6909
6910 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6911 (defun gnus-summary-fetch-faq (&optional faq-dir)
6912   "Fetch the FAQ for the current group.
6913 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6914 in."
6915   (interactive
6916    (list
6917     (when current-prefix-arg
6918       (completing-read
6919        "FAQ dir: " (and (listp gnus-group-faq-directory)
6920                         (mapcar 'list
6921                                 gnus-group-faq-directory))))))
6922   (let (gnus-faq-buffer)
6923     (when (setq gnus-faq-buffer
6924                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6925       (gnus-configure-windows 'summary-faq))))
6926
6927 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6928 (defun gnus-summary-describe-group (&optional force)
6929   "Describe the current newsgroup."
6930   (interactive "P")
6931   (gnus-group-describe-group force gnus-newsgroup-name))
6932
6933 (defun gnus-summary-describe-briefly ()
6934   "Describe summary mode commands briefly."
6935   (interactive)
6936   (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")))
6937
6938 ;; Walking around group mode buffer from summary mode.
6939
6940 (defun gnus-summary-next-group (&optional no-article target-group backward)
6941   "Exit current newsgroup and then select next unread newsgroup.
6942 If prefix argument NO-ARTICLE is non-nil, no article is selected
6943 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6944 previous group instead."
6945   (interactive "P")
6946   ;; Stop pre-fetching.
6947   (gnus-async-halt-prefetch)
6948   (let ((current-group gnus-newsgroup-name)
6949         (current-buffer (current-buffer))
6950         entered)
6951     ;; First we semi-exit this group to update Xrefs and all variables.
6952     ;; We can't do a real exit, because the window conf must remain
6953     ;; the same in case the user is prompted for info, and we don't
6954     ;; want the window conf to change before that...
6955     (gnus-summary-exit t)
6956     (while (not entered)
6957       ;; Then we find what group we are supposed to enter.
6958       (set-buffer gnus-group-buffer)
6959       (gnus-group-jump-to-group current-group)
6960       (setq target-group
6961             (or target-group
6962                 (if (eq gnus-keep-same-level 'best)
6963                     (gnus-summary-best-group gnus-newsgroup-name)
6964                   (gnus-summary-search-group backward gnus-keep-same-level))))
6965       (if (not target-group)
6966           ;; There are no further groups, so we return to the group
6967           ;; buffer.
6968           (progn
6969             (gnus-message 5 "Returning to the group buffer")
6970             (setq entered t)
6971             (when (gnus-buffer-live-p current-buffer)
6972               (set-buffer current-buffer)
6973               (gnus-summary-exit))
6974             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6975         ;; We try to enter the target group.
6976         (gnus-group-jump-to-group target-group)
6977         (let ((unreads (gnus-group-group-unread)))
6978           (if (and (or (eq t unreads)
6979                        (and unreads (not (zerop unreads))))
6980                    (gnus-summary-read-group
6981                     target-group nil no-article
6982                     (and (buffer-name current-buffer) current-buffer)
6983                     nil backward))
6984               (setq entered t)
6985             (setq current-group target-group
6986                   target-group nil)))))))
6987
6988 (defun gnus-summary-prev-group (&optional no-article)
6989   "Exit current newsgroup and then select previous unread newsgroup.
6990 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6991   (interactive "P")
6992   (gnus-summary-next-group no-article nil t))
6993
6994 ;; Walking around summary lines.
6995
6996 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6997   "Go to the first subject satisfying any non-nil constraint.
6998 If UNREAD is non-nil, the article should be unread.
6999 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7000 If UNSEEN is non-nil, the article should be unseen.
7001 Returns the article selected or nil if there are no matching articles."
7002   (interactive "P")
7003   (cond
7004    ;; Empty summary.
7005    ((null gnus-newsgroup-data)
7006     (gnus-message 3 "No articles in the group")
7007     nil)
7008    ;; Pick the first article.
7009    ((not (or unread undownloaded unseen))
7010     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7011     (gnus-data-number (car gnus-newsgroup-data)))
7012    ;; Find the first unread article.
7013    (t
7014     (let ((data gnus-newsgroup-data))
7015       (while (and data
7016                   (let ((num (gnus-data-number (car data))))
7017                     (or (memq num gnus-newsgroup-unfetched)
7018                         (not (or (and unread
7019                                       (memq num gnus-newsgroup-unreads))
7020                                  (and undownloaded
7021                                       (memq num gnus-newsgroup-undownloaded))
7022                                  (and unseen
7023                                       (memq num gnus-newsgroup-unseen)))))))
7024         (setq data (cdr data)))
7025       (prog1
7026           (if data
7027               (progn
7028                 (goto-char (gnus-data-pos (car data)))
7029                 (gnus-data-number (car data)))
7030             (gnus-message 3 "No more%s articles"
7031                           (let* ((r (when unread " unread"))
7032                                  (d (when undownloaded " undownloaded"))
7033                                  (s (when unseen " unseen"))
7034                                  (l (delq nil (list r d s))))
7035                             (cond ((= 3 (length l))
7036                                    (concat r "," d ", or" s))
7037                                   ((= 2 (length l))
7038                                    (concat (car l) ", or" (cadr l)))
7039                                   ((= 1 (length l))
7040                                    (car l))
7041                                   (t
7042                                    ""))))
7043             nil
7044             )
7045         (gnus-summary-position-point))))))
7046
7047 (defun gnus-summary-next-subject (n &optional unread dont-display)
7048   "Go to next N'th summary line.
7049 If N is negative, go to the previous N'th subject line.
7050 If UNREAD is non-nil, only unread articles are selected.
7051 The difference between N and the actual number of steps taken is
7052 returned."
7053   (interactive "p")
7054   (let ((backward (< n 0))
7055         (n (abs n)))
7056     (while (and (> n 0)
7057                 (if backward
7058                     (gnus-summary-find-prev unread)
7059                   (gnus-summary-find-next unread)))
7060       (unless (zerop (setq n (1- n)))
7061         (gnus-summary-show-thread)))
7062     (when (/= 0 n)
7063       (gnus-message 7 "No more%s articles"
7064                     (if unread " unread" "")))
7065     (unless dont-display
7066       (gnus-summary-recenter)
7067       (gnus-summary-position-point))
7068     n))
7069
7070 (defun gnus-summary-next-unread-subject (n)
7071   "Go to next N'th unread summary line."
7072   (interactive "p")
7073   (gnus-summary-next-subject n t))
7074
7075 (defun gnus-summary-prev-subject (n &optional unread)
7076   "Go to previous N'th summary line.
7077 If optional argument UNREAD is non-nil, only unread article is selected."
7078   (interactive "p")
7079   (gnus-summary-next-subject (- n) unread))
7080
7081 (defun gnus-summary-prev-unread-subject (n)
7082   "Go to previous N'th unread summary line."
7083   (interactive "p")
7084   (gnus-summary-next-subject (- n) t))
7085
7086 (defun gnus-summary-goto-subjects (articles)
7087   "Insert the subject header for ARTICLES in the current buffer."
7088   (save-excursion
7089     (dolist (article articles)
7090       (gnus-summary-goto-subject article t)))
7091   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7092   (gnus-summary-position-point))
7093
7094 (defun gnus-summary-goto-subject (article &optional force silent)
7095   "Go the subject line of ARTICLE.
7096 If FORCE, also allow jumping to articles not currently shown."
7097   (interactive "nArticle number: ")
7098   (unless (numberp article)
7099     (error "Article %s is not a number" article))
7100   (let ((b (point))
7101         (data (gnus-data-find article)))
7102     ;; We read in the article if we have to.
7103     (and (not data)
7104          force
7105          (gnus-summary-insert-subject
7106           article
7107           (if (or (numberp force) (vectorp force)) force)
7108           t)
7109          (setq data (gnus-data-find article)))
7110     (goto-char b)
7111     (if (not data)
7112         (progn
7113           (unless silent
7114             (gnus-message 3 "Can't find article %d" article))
7115           nil)
7116       (let ((pt (gnus-data-pos data)))
7117         (goto-char pt)
7118         (gnus-summary-set-article-display-arrow pt))
7119       (gnus-summary-position-point)
7120       article)))
7121
7122 ;; Walking around summary lines with displaying articles.
7123
7124 (defun gnus-summary-expand-window (&optional arg)
7125   "Make the summary buffer take up the entire Emacs frame.
7126 Given a prefix, will force an `article' buffer configuration."
7127   (interactive "P")
7128   (if arg
7129       (gnus-configure-windows 'article 'force)
7130     (gnus-configure-windows 'summary 'force)))
7131
7132 (defun gnus-summary-display-article (article &optional all-header)
7133   "Display ARTICLE in article buffer."
7134   (when (gnus-buffer-live-p gnus-article-buffer)
7135     (with-current-buffer gnus-article-buffer
7136       (mm-enable-multibyte)))
7137   (gnus-set-global-variables)
7138   (when (gnus-buffer-live-p gnus-article-buffer)
7139     (with-current-buffer gnus-article-buffer
7140       (setq gnus-article-charset gnus-newsgroup-charset)
7141       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7142       (mm-enable-multibyte)))
7143   (if (null article)
7144       nil
7145     (prog1
7146         (if gnus-summary-display-article-function
7147             (funcall gnus-summary-display-article-function article all-header)
7148           (gnus-article-prepare article all-header))
7149       (gnus-run-hooks 'gnus-select-article-hook)
7150       (when (and gnus-current-article
7151                  (not (zerop gnus-current-article)))
7152         (gnus-summary-goto-subject gnus-current-article))
7153       (gnus-summary-recenter)
7154       (when (and gnus-use-trees gnus-show-threads)
7155         (gnus-possibly-generate-tree article)
7156         (gnus-highlight-selected-tree article))
7157       ;; Successfully display article.
7158       (gnus-article-set-window-start
7159        (cdr (assq article gnus-newsgroup-bookmarks))))))
7160
7161 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7162   "Select the current article.
7163 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7164 non-nil, the article will be re-fetched even if it already present in
7165 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7166 be displayed."
7167   ;; Make sure we are in the summary buffer to work around bbdb bug.
7168   (unless (eq major-mode 'gnus-summary-mode)
7169     (set-buffer gnus-summary-buffer))
7170   (let ((article (or article (gnus-summary-article-number)))
7171         (all-headers (not (not all-headers))) ;Must be t or nil.
7172         gnus-summary-display-article-function)
7173     (and (not pseudo)
7174          (gnus-summary-article-pseudo-p article)
7175          (error "This is a pseudo-article"))
7176     (save-excursion
7177       (set-buffer gnus-summary-buffer)
7178       (if (or (and gnus-single-article-buffer
7179                    (or (null gnus-current-article)
7180                        (null gnus-article-current)
7181                        (null (get-buffer gnus-article-buffer))
7182                        (not (eq article (cdr gnus-article-current)))
7183                        (not (equal (car gnus-article-current)
7184                                    gnus-newsgroup-name))))
7185               (and (not gnus-single-article-buffer)
7186                    (or (null gnus-current-article)
7187                        (not (eq gnus-current-article article))))
7188               force)
7189           ;; The requested article is different from the current article.
7190           (progn
7191             (gnus-summary-display-article article all-headers)
7192             (when (gnus-buffer-live-p gnus-article-buffer)
7193               (with-current-buffer gnus-article-buffer
7194                 (if (not gnus-article-decoded-p) ;; a local variable
7195                     (mm-disable-multibyte))))
7196             (gnus-article-set-window-start
7197              (cdr (assq article gnus-newsgroup-bookmarks)))
7198             article)
7199         'old))))
7200
7201 (defun gnus-summary-force-verify-and-decrypt ()
7202   "Display buttons for signed/encrypted parts and verify/decrypt them."
7203   (interactive)
7204   (let ((mm-verify-option 'known)
7205         (mm-decrypt-option 'known)
7206         (gnus-article-emulate-mime t)
7207         (gnus-buttonized-mime-types (append (list "multipart/signed"
7208                                                   "multipart/encrypted")
7209                                             gnus-buttonized-mime-types)))
7210     (gnus-summary-select-article nil 'force)))
7211
7212 (defun gnus-summary-set-current-mark (&optional current-mark)
7213   "Obsolete function."
7214   nil)
7215
7216 (defun gnus-summary-next-article (&optional unread subject backward push)
7217   "Select the next article.
7218 If UNREAD, only unread articles are selected.
7219 If SUBJECT, only articles with SUBJECT are selected.
7220 If BACKWARD, the previous article is selected instead of the next."
7221   (interactive "P")
7222   (cond
7223    ;; Is there such an article?
7224    ((and (gnus-summary-search-forward unread subject backward)
7225          (or (gnus-summary-display-article (gnus-summary-article-number))
7226              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7227     (gnus-summary-position-point))
7228    ;; If not, we try the first unread, if that is wanted.
7229    ((and subject
7230          gnus-auto-select-same
7231          (gnus-summary-first-unread-article))
7232     (gnus-summary-position-point)
7233     (gnus-message 6 "Wrapped"))
7234    ;; Try to get next/previous article not displayed in this group.
7235    ((and gnus-auto-extend-newsgroup
7236          (not unread) (not subject))
7237     (gnus-summary-goto-article
7238      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7239      nil (count-lines (point-min) (point))))
7240    ;; Go to next/previous group.
7241    (t
7242     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7243       (gnus-summary-jump-to-group gnus-newsgroup-name))
7244     (let ((cmd last-command-char)
7245           (point
7246            (with-current-buffer gnus-group-buffer
7247              (point)))
7248           (group
7249            (if (eq gnus-keep-same-level 'best)
7250                (gnus-summary-best-group gnus-newsgroup-name)
7251              (gnus-summary-search-group backward gnus-keep-same-level))))
7252       ;; For some reason, the group window gets selected.  We change
7253       ;; it back.
7254       (select-window (get-buffer-window (current-buffer)))
7255       ;; Select next unread newsgroup automagically.
7256       (cond
7257        ((or (not gnus-auto-select-next)
7258             (not cmd))
7259         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7260        ((or (eq gnus-auto-select-next 'quietly)
7261             (and (eq gnus-auto-select-next 'slightly-quietly)
7262                  push)
7263             (and (eq gnus-auto-select-next 'almost-quietly)
7264                  (gnus-summary-last-article-p)))
7265         ;; Select quietly.
7266         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7267             (gnus-summary-exit)
7268           (gnus-message 7 "No more%s articles (%s)..."
7269                         (if unread " unread" "")
7270                         (if group (concat "selecting " group)
7271                           "exiting"))
7272           (gnus-summary-next-group nil group backward)))
7273        (t
7274         (when (gnus-key-press-event-p last-input-event)
7275           (gnus-summary-walk-group-buffer
7276            gnus-newsgroup-name cmd unread backward point))))))))
7277
7278 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7279   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7280                       (?\C-p (gnus-group-prev-unread-group 1))))
7281         (cursor-in-echo-area t)
7282         keve key group ended prompt)
7283     (save-excursion
7284       (set-buffer gnus-group-buffer)
7285       (goto-char start)
7286       (setq group
7287             (if (eq gnus-keep-same-level 'best)
7288                 (gnus-summary-best-group gnus-newsgroup-name)
7289               (gnus-summary-search-group backward gnus-keep-same-level))))
7290     (while (not ended)
7291       (setq prompt
7292             (format
7293              "No more%s articles%s " (if unread " unread" "")
7294              (if (and group
7295                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7296                  (format " (Type %s for %s [%s])"
7297                          (single-key-description cmd)
7298                          (gnus-group-decoded-name group)
7299                          (gnus-group-unread group))
7300                (format " (Type %s to exit %s)"
7301                        (single-key-description cmd)
7302                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7303       ;; Confirm auto selection.
7304       (setq key (car (setq keve (gnus-read-event-char prompt)))
7305             ended t)
7306       (cond
7307        ((assq key keystrokes)
7308         (let ((obuf (current-buffer)))
7309           (switch-to-buffer gnus-group-buffer)
7310           (when group
7311             (gnus-group-jump-to-group group))
7312           (eval (cadr (assq key keystrokes)))
7313           (setq group (gnus-group-group-name))
7314           (switch-to-buffer obuf))
7315         (setq ended nil))
7316        ((equal key cmd)
7317         (if (or (not group)
7318                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7319             (gnus-summary-exit)
7320           (gnus-summary-next-group nil group backward)))
7321        (t
7322         (push (cdr keve) unread-command-events))))))
7323
7324 (defun gnus-summary-next-unread-article ()
7325   "Select unread article after current one."
7326   (interactive)
7327   (gnus-summary-next-article
7328    (or (not (eq gnus-summary-goto-unread 'never))
7329        (gnus-summary-last-article-p (gnus-summary-article-number)))
7330    (and gnus-auto-select-same
7331         (gnus-summary-article-subject))))
7332
7333 (defun gnus-summary-prev-article (&optional unread subject)
7334   "Select the article after the current one.
7335 If UNREAD is non-nil, only unread articles are selected."
7336   (interactive "P")
7337   (gnus-summary-next-article unread subject t))
7338
7339 (defun gnus-summary-prev-unread-article ()
7340   "Select unread article before current one."
7341   (interactive)
7342   (gnus-summary-prev-article
7343    (or (not (eq gnus-summary-goto-unread 'never))
7344        (gnus-summary-first-article-p (gnus-summary-article-number)))
7345    (and gnus-auto-select-same
7346         (gnus-summary-article-subject))))
7347
7348 (defun gnus-summary-next-page (&optional lines circular stop)
7349   "Show next page of the selected article.
7350 If at the end of the current article, select the next article.
7351 LINES says how many lines should be scrolled up.
7352
7353 If CIRCULAR is non-nil, go to the start of the article instead of
7354 selecting the next article when reaching the end of the current
7355 article.
7356
7357 If STOP is non-nil, just stop when reaching the end of the message.
7358
7359 Also see the variable `gnus-article-skip-boring'."
7360   (interactive "P")
7361   (setq gnus-summary-buffer (current-buffer))
7362   (gnus-set-global-variables)
7363   (let ((article (gnus-summary-article-number))
7364         (article-window (get-buffer-window gnus-article-buffer t))
7365         endp)
7366     ;; If the buffer is empty, we have no article.
7367     (unless article
7368       (error "No article to select"))
7369     (gnus-configure-windows 'article)
7370     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7371         (if (and (eq gnus-summary-goto-unread 'never)
7372                  (not (gnus-summary-last-article-p article)))
7373             (gnus-summary-next-article)
7374           (gnus-summary-next-unread-article))
7375       (if (or (null gnus-current-article)
7376               (null gnus-article-current)
7377               (/= article (cdr gnus-article-current))
7378               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7379           ;; Selected subject is different from current article's.
7380           (gnus-summary-display-article article)
7381         (when article-window
7382           (gnus-eval-in-buffer-window gnus-article-buffer
7383             (setq endp (or (gnus-article-next-page lines)
7384                            (gnus-article-only-boring-p))))
7385           (when endp
7386             (cond (stop
7387                    (gnus-message 3 "End of message"))
7388                   (circular
7389                    (gnus-summary-beginning-of-article))
7390                   (lines
7391                    (gnus-message 3 "End of message"))
7392                   ((null lines)
7393                    (if (and (eq gnus-summary-goto-unread 'never)
7394                             (not (gnus-summary-last-article-p article)))
7395                        (gnus-summary-next-article)
7396                      (gnus-summary-next-unread-article))))))))
7397     (gnus-summary-recenter)
7398     (gnus-summary-position-point)))
7399
7400 (defun gnus-summary-prev-page (&optional lines move)
7401   "Show previous page of selected article.
7402 Argument LINES specifies lines to be scrolled down.
7403 If MOVE, move to the previous unread article if point is at
7404 the beginning of the buffer."
7405   (interactive "P")
7406   (let ((article (gnus-summary-article-number))
7407         (article-window (get-buffer-window gnus-article-buffer t))
7408         endp)
7409     (gnus-configure-windows 'article)
7410     (if (or (null gnus-current-article)
7411             (null gnus-article-current)
7412             (/= article (cdr gnus-article-current))
7413             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7414         ;; Selected subject is different from current article's.
7415         (gnus-summary-display-article article)
7416       (gnus-summary-recenter)
7417       (when article-window
7418         (gnus-eval-in-buffer-window gnus-article-buffer
7419           (setq endp (gnus-article-prev-page lines)))
7420         (when (and move endp)
7421           (cond (lines
7422                  (gnus-message 3 "Beginning of message"))
7423                 ((null lines)
7424                  (if (and (eq gnus-summary-goto-unread 'never)
7425                           (not (gnus-summary-first-article-p article)))
7426                      (gnus-summary-prev-article)
7427                    (gnus-summary-prev-unread-article))))))))
7428   (gnus-summary-position-point))
7429
7430 (defun gnus-summary-prev-page-or-article (&optional lines)
7431   "Show previous page of selected article.
7432 Argument LINES specifies lines to be scrolled down.
7433 If at the beginning of the article, go to the next article."
7434   (interactive "P")
7435   (gnus-summary-prev-page lines t))
7436
7437 (defun gnus-summary-scroll-up (lines)
7438   "Scroll up (or down) one line current article.
7439 Argument LINES specifies lines to be scrolled up (or down if negative)."
7440   (interactive "p")
7441   (gnus-configure-windows 'article)
7442   (gnus-summary-show-thread)
7443   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7444     (gnus-eval-in-buffer-window gnus-article-buffer
7445       (cond ((> lines 0)
7446              (when (gnus-article-next-page lines)
7447                (gnus-message 3 "End of message")))
7448             ((< lines 0)
7449              (gnus-article-prev-page (- lines))))))
7450   (gnus-summary-recenter)
7451   (gnus-summary-position-point))
7452
7453 (defun gnus-summary-scroll-down (lines)
7454   "Scroll down (or up) one line current article.
7455 Argument LINES specifies lines to be scrolled down (or up if negative)."
7456   (interactive "p")
7457   (gnus-summary-scroll-up (- lines)))
7458
7459 (defun gnus-summary-next-same-subject ()
7460   "Select next article which has the same subject as current one."
7461   (interactive)
7462   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7463
7464 (defun gnus-summary-prev-same-subject ()
7465   "Select previous article which has the same subject as current one."
7466   (interactive)
7467   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7468
7469 (defun gnus-summary-next-unread-same-subject ()
7470   "Select next unread article which has the same subject as current one."
7471   (interactive)
7472   (gnus-summary-next-article t (gnus-summary-article-subject)))
7473
7474 (defun gnus-summary-prev-unread-same-subject ()
7475   "Select previous unread article which has the same subject as current one."
7476   (interactive)
7477   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7478
7479 (defun gnus-summary-first-unread-article ()
7480   "Select the first unread article.
7481 Return nil if there are no unread articles."
7482   (interactive)
7483   (prog1
7484       (when (gnus-summary-first-subject t)
7485         (gnus-summary-show-thread)
7486         (gnus-summary-first-subject t)
7487         (gnus-summary-display-article (gnus-summary-article-number)))
7488     (gnus-summary-position-point)))
7489
7490 (defun gnus-summary-first-unread-subject ()
7491   "Place the point on the subject line of the first unread article.
7492 Return nil if there are no unread articles."
7493   (interactive)
7494   (prog1
7495       (when (gnus-summary-first-subject t)
7496         (gnus-summary-show-thread)
7497         (gnus-summary-first-subject t))
7498     (gnus-summary-position-point)))
7499
7500 (defun gnus-summary-first-unseen-subject ()
7501   "Place the point on the subject line of the first unseen article.
7502 Return nil if there are no unseen articles."
7503   (interactive)
7504   (prog1
7505       (when (gnus-summary-first-subject nil nil t)
7506         (gnus-summary-show-thread)
7507         (gnus-summary-first-subject nil nil t))
7508     (gnus-summary-position-point)))
7509
7510 (defun gnus-summary-first-unseen-or-unread-subject ()
7511   "Place the point on the subject line of the first unseen article or,
7512 if all article have been seen, on the subject line of the first unread
7513 article."
7514   (interactive)
7515   (prog1
7516       (unless (when (gnus-summary-first-subject nil nil t)
7517                 (gnus-summary-show-thread)
7518                 (gnus-summary-first-subject nil nil t))
7519         (when (gnus-summary-first-subject t)
7520           (gnus-summary-show-thread)
7521           (gnus-summary-first-subject t)))
7522     (gnus-summary-position-point)))
7523
7524 (defun gnus-summary-first-article ()
7525   "Select the first article.
7526 Return nil if there are no articles."
7527   (interactive)
7528   (prog1
7529       (when (gnus-summary-first-subject)
7530         (gnus-summary-show-thread)
7531         (gnus-summary-first-subject)
7532         (gnus-summary-display-article (gnus-summary-article-number)))
7533     (gnus-summary-position-point)))
7534
7535 (defun gnus-summary-best-unread-article (&optional arg)
7536   "Select the unread article with the highest score.
7537 If given a prefix argument, select the next unread article that has a
7538 score higher than the default score."
7539   (interactive "P")
7540   (let ((article (if arg
7541                      (gnus-summary-better-unread-subject)
7542                    (gnus-summary-best-unread-subject))))
7543     (if article
7544         (gnus-summary-goto-article article)
7545       (error "No unread articles"))))
7546
7547 (defun gnus-summary-best-unread-subject ()
7548   "Select the unread subject with the highest score."
7549   (interactive)
7550   (let ((best -1000000)
7551         (data gnus-newsgroup-data)
7552         article score)
7553     (while data
7554       (and (gnus-data-unread-p (car data))
7555            (> (setq score
7556                     (gnus-summary-article-score (gnus-data-number (car data))))
7557               best)
7558            (setq best score
7559                  article (gnus-data-number (car data))))
7560       (setq data (cdr data)))
7561     (when article
7562       (gnus-summary-goto-subject article))
7563     (gnus-summary-position-point)
7564     article))
7565
7566 (defun gnus-summary-better-unread-subject ()
7567   "Select the first unread subject that has a score over the default score."
7568   (interactive)
7569   (let ((data gnus-newsgroup-data)
7570         article score)
7571     (while (and (setq article (gnus-data-number (car data)))
7572                 (or (gnus-data-read-p (car data))
7573                     (not (> (gnus-summary-article-score article)
7574                             gnus-summary-default-score))))
7575       (setq data (cdr data)))
7576     (when article
7577       (gnus-summary-goto-subject article))
7578     (gnus-summary-position-point)
7579     article))
7580
7581 (defun gnus-summary-last-subject ()
7582   "Go to the last displayed subject line in the group."
7583   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7584     (when article
7585       (gnus-summary-goto-subject article))))
7586
7587 (defun gnus-summary-goto-article (article &optional all-headers force)
7588   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7589 If ALL-HEADERS is non-nil, no header lines are hidden.
7590 If FORCE, go to the article even if it isn't displayed.  If FORCE
7591 is a number, it is the line the article is to be displayed on."
7592   (interactive
7593    (list
7594     (completing-read
7595      "Article number or Message-ID: "
7596      (mapcar (lambda (number) (list (int-to-string number)))
7597              gnus-newsgroup-limit))
7598     current-prefix-arg
7599     t))
7600   (prog1
7601       (if (and (stringp article)
7602                (string-match "@\\|%40" article))
7603           (gnus-summary-refer-article article)
7604         (when (stringp article)
7605           (setq article (string-to-number article)))
7606         (if (gnus-summary-goto-subject article force)
7607             (gnus-summary-display-article article all-headers)
7608           (gnus-message 4 "Couldn't go to article %s" article) nil))
7609     (gnus-summary-position-point)))
7610
7611 (defun gnus-summary-goto-last-article ()
7612   "Go to the previously read article."
7613   (interactive)
7614   (prog1
7615       (when gnus-last-article
7616         (gnus-summary-goto-article gnus-last-article nil t))
7617     (gnus-summary-position-point)))
7618
7619 (defun gnus-summary-pop-article (number)
7620   "Pop one article off the history and go to the previous.
7621 NUMBER articles will be popped off."
7622   (interactive "p")
7623   (let (to)
7624     (setq gnus-newsgroup-history
7625           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7626     (if to
7627         (gnus-summary-goto-article (car to) nil t)
7628       (error "Article history empty")))
7629   (gnus-summary-position-point))
7630
7631 ;; Summary commands and functions for limiting the summary buffer.
7632
7633 (defun gnus-summary-limit-to-articles (n)
7634   "Limit the summary buffer to the next N articles.
7635 If not given a prefix, use the process marked articles instead."
7636   (interactive "P")
7637   (prog1
7638       (let ((articles (gnus-summary-work-articles n)))
7639         (setq gnus-newsgroup-processable nil)
7640         (gnus-summary-limit articles))
7641     (gnus-summary-position-point)))
7642
7643 (defun gnus-summary-pop-limit (&optional total)
7644   "Restore the previous limit.
7645 If given a prefix, remove all limits."
7646   (interactive "P")
7647   (when total
7648     (setq gnus-newsgroup-limits
7649           (list (mapcar (lambda (h) (mail-header-number h))
7650                         gnus-newsgroup-headers))))
7651   (unless gnus-newsgroup-limits
7652     (error "No limit to pop"))
7653   (prog1
7654       (gnus-summary-limit nil 'pop)
7655     (gnus-summary-position-point)))
7656
7657 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7658   "Limit the summary buffer to articles that have subjects that match a regexp.
7659 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7660   (interactive
7661    (list (read-string (if current-prefix-arg
7662                           "Exclude subject (regexp): "
7663                         "Limit to subject (regexp): "))
7664          nil current-prefix-arg))
7665   (unless header
7666     (setq header "subject"))
7667   (when (not (equal "" subject))
7668     (prog1
7669         (let ((articles (gnus-summary-find-matching
7670                          (or header "subject") subject 'all nil nil
7671                          not-matching)))
7672           (unless articles
7673             (error "Found no matches for \"%s\"" subject))
7674           (gnus-summary-limit articles))
7675       (gnus-summary-position-point))))
7676
7677 (defun gnus-summary-limit-to-author (from &optional not-matching)
7678   "Limit the summary buffer to articles that have authors that match a regexp.
7679 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7680   (interactive
7681    (list (read-string (if current-prefix-arg
7682                           "Exclude author (regexp): "
7683                         "Limit to author (regexp): "))
7684          current-prefix-arg))
7685   (gnus-summary-limit-to-subject from "from" not-matching))
7686
7687 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7688   "Limit the summary buffer to articles with the given RECIPIENT.
7689
7690 If NOT-MATCHING, exclude RECIPIENT.
7691
7692 To and Cc headers are checked.  You need to include them in
7693 `nnmail-extra-headers'."
7694   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7695   (interactive
7696    (list (read-string (format "%s recipient (regexp): "
7697                               (if current-prefix-arg "Exclude" "Limit to")))
7698          current-prefix-arg))
7699   (when (not (equal "" recipient))
7700     (prog1 (let* ((to
7701                    (if (memq 'To nnmail-extra-headers)
7702                        (gnus-summary-find-matching
7703                         (cons 'extra 'To) recipient 'all nil nil
7704                         not-matching)
7705                      (gnus-message
7706                       1 "`To' isn't present in `nnmail-extra-headers'")
7707                      (sit-for 1)
7708                      nil))
7709                   (cc
7710                    (if (memq 'Cc nnmail-extra-headers)
7711                        (gnus-summary-find-matching
7712                         (cons 'extra 'Cc) recipient 'all nil nil
7713                         not-matching)
7714                      (gnus-message
7715                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7716                      (sit-for 1)
7717                      nil))
7718                   (articles
7719                    (if not-matching
7720                        ;; We need the numbers that are in both lists:
7721                        (mapcar (lambda (a)
7722                                  (and (memq a to) a))
7723                                cc)
7724                      (nconc to cc))))
7725              (unless articles
7726                (error "Found no matches for \"%s\"" recipient))
7727              (gnus-summary-limit articles))
7728       (gnus-summary-position-point))))
7729
7730 (defun gnus-summary-limit-to-age (age &optional younger-p)
7731   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7732 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7733 articles that are younger than AGE days."
7734   (interactive
7735    (let ((younger current-prefix-arg)
7736          (days-got nil)
7737          days)
7738      (while (not days-got)
7739        (setq days (if younger
7740                       (read-string "Limit to articles younger than (in days, older when negative): ")
7741                     (read-string
7742                      "Limit to articles older than (in days, younger when negative): ")))
7743        (when (> (length days) 0)
7744          (setq days (read days)))
7745        (if (numberp days)
7746            (progn
7747              (setq days-got t)
7748              (when (< days 0)
7749                (setq younger (not younger))
7750                (setq days (* days -1))))
7751          (message "Please enter a number.")
7752          (sleep-for 1)))
7753      (list days younger)))
7754   (prog1
7755       (let ((data gnus-newsgroup-data)
7756             (cutoff (days-to-time age))
7757             articles d date is-younger)
7758         (while (setq d (pop data))
7759           (when (and (vectorp (gnus-data-header d))
7760                      (setq date (mail-header-date (gnus-data-header d))))
7761             (setq is-younger (time-less-p
7762                               (time-since (condition-case ()
7763                                               (date-to-time date)
7764                                             (error '(0 0))))
7765                               cutoff))
7766             (when (if younger-p
7767                       is-younger
7768                     (not is-younger))
7769               (push (gnus-data-number d) articles))))
7770         (gnus-summary-limit (nreverse articles)))
7771     (gnus-summary-position-point)))
7772
7773 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7774   "Limit the summary buffer to articles that match an 'extra' header."
7775   (interactive
7776    (let ((header
7777           (intern
7778            (gnus-completing-read-with-default
7779             (symbol-name (car gnus-extra-headers))
7780             (if current-prefix-arg
7781                 "Exclude extra header:"
7782               "Limit extra header:")
7783             (mapcar (lambda (x)
7784                       (cons (symbol-name x) x))
7785                     gnus-extra-headers)
7786             nil
7787             t))))
7788      (list header
7789            (read-string (format "%s header %s (regexp): "
7790                                 (if current-prefix-arg "Exclude" "Limit to")
7791                                 header))
7792            current-prefix-arg)))
7793   (when (not (equal "" regexp))
7794     (prog1
7795         (let ((articles (gnus-summary-find-matching
7796                          (cons 'extra header) regexp 'all nil nil
7797                          not-matching)))
7798           (unless articles
7799             (error "Found no matches for \"%s\"" regexp))
7800           (gnus-summary-limit articles))
7801       (gnus-summary-position-point))))
7802
7803 (defun gnus-summary-limit-to-display-predicate ()
7804   "Limit the summary buffer to the predicated in the `display' group parameter."
7805   (interactive)
7806   (unless gnus-newsgroup-display
7807     (error "There is no `display' group parameter"))
7808   (let (articles)
7809     (dolist (number gnus-newsgroup-articles)
7810       (when (funcall gnus-newsgroup-display)
7811         (push number articles)))
7812     (gnus-summary-limit articles))
7813   (gnus-summary-position-point))
7814
7815 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7816 (make-obsolete
7817  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7818
7819 (defun gnus-summary-limit-to-unread (&optional all)
7820   "Limit the summary buffer to articles that are not marked as read.
7821 If ALL is non-nil, limit strictly to unread articles."
7822   (interactive "P")
7823   (if all
7824       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7825     (gnus-summary-limit-to-marks
7826      ;; Concat all the marks that say that an article is read and have
7827      ;; those removed.
7828      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7829            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7830            gnus-low-score-mark gnus-expirable-mark
7831            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7832            gnus-duplicate-mark gnus-souped-mark)
7833      'reverse)))
7834
7835 (defun gnus-summary-limit-to-replied (&optional unreplied)
7836   "Limit the summary buffer to replied articles.
7837 If UNREPLIED (the prefix), limit to unreplied articles."
7838   (interactive "P")
7839   (if unreplied
7840       (gnus-summary-limit
7841        (gnus-set-difference gnus-newsgroup-articles
7842         gnus-newsgroup-replied))
7843     (gnus-summary-limit gnus-newsgroup-replied))
7844   (gnus-summary-position-point))
7845
7846 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7847 (make-obsolete 'gnus-summary-delete-marked-with
7848                'gnus-summary-limit-exclude-marks)
7849
7850 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7851   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7852 If REVERSE, limit the summary buffer to articles that are marked
7853 with MARKS.  MARKS can either be a string of marks or a list of marks.
7854 Returns how many articles were removed."
7855   (interactive "sMarks: ")
7856   (gnus-summary-limit-to-marks marks t))
7857
7858 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7859   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7860 If REVERSE (the prefix), limit the summary buffer to articles that are
7861 not marked with MARKS.  MARKS can either be a string of marks or a
7862 list of marks.
7863 Returns how many articles were removed."
7864   (interactive "sMarks: \nP")
7865   (prog1
7866       (let ((data gnus-newsgroup-data)
7867             (marks (if (listp marks) marks
7868                      (append marks nil))) ; Transform to list.
7869             articles)
7870         (while data
7871           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7872                   (memq (gnus-data-mark (car data)) marks))
7873             (push (gnus-data-number (car data)) articles))
7874           (setq data (cdr data)))
7875         (gnus-summary-limit articles))
7876     (gnus-summary-position-point)))
7877
7878 (defun gnus-summary-limit-to-score (score)
7879   "Limit to articles with score at or above SCORE."
7880   (interactive "NLimit to articles with score of at least: ")
7881   (let ((data gnus-newsgroup-data)
7882         articles)
7883     (while data
7884       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7885                 score)
7886         (push (gnus-data-number (car data)) articles))
7887       (setq data (cdr data)))
7888     (prog1
7889         (gnus-summary-limit articles)
7890       (gnus-summary-position-point))))
7891
7892 (defun gnus-summary-limit-to-unseen ()
7893   "Limit to unseen articles."
7894   (interactive)
7895   (prog1
7896       (gnus-summary-limit gnus-newsgroup-unseen)
7897     (gnus-summary-position-point)))
7898
7899 (defun gnus-summary-limit-include-thread (id)
7900   "Display all the hidden articles that is in the thread with ID in it.
7901 When called interactively, ID is the Message-ID of the current
7902 article."
7903   (interactive (list (mail-header-id (gnus-summary-article-header))))
7904   (let ((articles (gnus-articles-in-thread
7905                    (gnus-id-to-thread (gnus-root-id id)))))
7906     (prog1
7907         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7908       (gnus-summary-limit-include-matching-articles
7909        "subject"
7910        (regexp-quote (gnus-simplify-subject-re
7911                       (mail-header-subject (gnus-id-to-header id)))))
7912       (gnus-summary-position-point))))
7913
7914 (defun gnus-summary-limit-include-matching-articles (header regexp)
7915   "Display all the hidden articles that have HEADERs that match REGEXP."
7916   (interactive (list (read-string "Match on header: ")
7917                      (read-string "Regexp: ")))
7918   (let ((articles (gnus-find-matching-articles header regexp)))
7919     (prog1
7920         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7921       (gnus-summary-position-point))))
7922
7923 (defun gnus-summary-insert-dormant-articles ()
7924   "Insert all the dormant articles for this group into the current buffer."
7925   (interactive)
7926   (let ((gnus-verbose (max 6 gnus-verbose)))
7927     (if (not gnus-newsgroup-dormant)
7928         (gnus-message 3 "No cached articles for this group")
7929       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7930
7931 (defun gnus-summary-limit-include-dormant ()
7932   "Display all the hidden articles that are marked as dormant.
7933 Note that this command only works on a subset of the articles currently
7934 fetched for this group."
7935   (interactive)
7936   (unless gnus-newsgroup-dormant
7937     (error "There are no dormant articles in this group"))
7938   (prog1
7939       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7940     (gnus-summary-position-point)))
7941
7942 (defun gnus-summary-limit-exclude-dormant ()
7943   "Hide all dormant articles."
7944   (interactive)
7945   (prog1
7946       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7947     (gnus-summary-position-point)))
7948
7949 (defun gnus-summary-limit-exclude-childless-dormant ()
7950   "Hide all dormant articles that have no children."
7951   (interactive)
7952   (let ((data (gnus-data-list t))
7953         articles d children)
7954     ;; Find all articles that are either not dormant or have
7955     ;; children.
7956     (while (setq d (pop data))
7957       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7958                 (and (setq children
7959                            (gnus-article-children (gnus-data-number d)))
7960                      (let (found)
7961                        (while children
7962                          (when (memq (car children) articles)
7963                            (setq children nil
7964                                  found t))
7965                          (pop children))
7966                        found)))
7967         (push (gnus-data-number d) articles)))
7968     ;; Do the limiting.
7969     (prog1
7970         (gnus-summary-limit articles)
7971       (gnus-summary-position-point))))
7972
7973 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7974   "Mark all unread excluded articles as read.
7975 If ALL, mark even excluded ticked and dormants as read."
7976   (interactive "P")
7977   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7978   (let ((articles (gnus-sorted-ndifference
7979                    (sort
7980                     (mapcar (lambda (h) (mail-header-number h))
7981                             gnus-newsgroup-headers)
7982                     '<)
7983                    gnus-newsgroup-limit))
7984         article)
7985     (setq gnus-newsgroup-unreads
7986           (gnus-sorted-intersection gnus-newsgroup-unreads
7987                                     gnus-newsgroup-limit))
7988     (if all
7989         (setq gnus-newsgroup-dormant nil
7990               gnus-newsgroup-marked nil
7991               gnus-newsgroup-reads
7992               (nconc
7993                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7994                gnus-newsgroup-reads))
7995       (while (setq article (pop articles))
7996         (unless (or (memq article gnus-newsgroup-dormant)
7997                     (memq article gnus-newsgroup-marked))
7998           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7999
8000 (defun gnus-summary-limit (articles &optional pop)
8001   (if pop
8002       ;; We pop the previous limit off the stack and use that.
8003       (setq articles (car gnus-newsgroup-limits)
8004             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8005     ;; We use the new limit, so we push the old limit on the stack.
8006     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8007   ;; Set the limit.
8008   (setq gnus-newsgroup-limit articles)
8009   (let ((total (length gnus-newsgroup-data))
8010         (data (gnus-data-find-list (gnus-summary-article-number)))
8011         (gnus-summary-mark-below nil)   ; Inhibit this.
8012         found)
8013     ;; This will do all the work of generating the new summary buffer
8014     ;; according to the new limit.
8015     (gnus-summary-prepare)
8016     ;; Hide any threads, possibly.
8017     (gnus-summary-maybe-hide-threads)
8018     ;; Try to return to the article you were at, or one in the
8019     ;; neighborhood.
8020     (when data
8021       ;; We try to find some article after the current one.
8022       (while data
8023         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8024           (setq data nil
8025                 found t))
8026         (setq data (cdr data))))
8027     (unless found
8028       ;; If there is no data, that means that we were after the last
8029       ;; article.  The same goes when we can't find any articles
8030       ;; after the current one.
8031       (goto-char (point-max))
8032       (gnus-summary-find-prev))
8033     (gnus-set-mode-line 'summary)
8034     ;; We return how many articles were removed from the summary
8035     ;; buffer as a result of the new limit.
8036     (- total (length gnus-newsgroup-data))))
8037
8038 (defsubst gnus-invisible-cut-children (threads)
8039   (let ((num 0))
8040     (while threads
8041       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8042         (incf num))
8043       (pop threads))
8044     (< num 2)))
8045
8046 (defsubst gnus-cut-thread (thread)
8047   "Go forwards in the thread until we find an article that we want to display."
8048   (when (or (eq gnus-fetch-old-headers 'some)
8049             (eq gnus-fetch-old-headers 'invisible)
8050             (numberp gnus-fetch-old-headers)
8051             (eq gnus-build-sparse-threads 'some)
8052             (eq gnus-build-sparse-threads 'more))
8053     ;; Deal with old-fetched headers and sparse threads.
8054     (while (and
8055             thread
8056             (or
8057              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8058              (gnus-summary-article-ancient-p
8059               (mail-header-number (car thread))))
8060             (if (or (<= (length (cdr thread)) 1)
8061                     (eq gnus-fetch-old-headers 'invisible))
8062                 (setq gnus-newsgroup-limit
8063                       (delq (mail-header-number (car thread))
8064                             gnus-newsgroup-limit)
8065                       thread (cadr thread))
8066               (when (gnus-invisible-cut-children (cdr thread))
8067                 (let ((th (cdr thread)))
8068                   (while th
8069                     (if (memq (mail-header-number (caar th))
8070                               gnus-newsgroup-limit)
8071                         (setq thread (car th)
8072                               th nil)
8073                       (setq th (cdr th))))))))))
8074   thread)
8075
8076 (defun gnus-cut-threads (threads)
8077   "Cut off all uninteresting articles from the beginning of THREADS."
8078   (when (or (eq gnus-fetch-old-headers 'some)
8079             (eq gnus-fetch-old-headers 'invisible)
8080             (numberp gnus-fetch-old-headers)
8081             (eq gnus-build-sparse-threads 'some)
8082             (eq gnus-build-sparse-threads 'more))
8083     (let ((th threads))
8084       (while th
8085         (setcar th (gnus-cut-thread (car th)))
8086         (setq th (cdr th)))))
8087   ;; Remove nixed out threads.
8088   (delq nil threads))
8089
8090 (defun gnus-summary-initial-limit (&optional show-if-empty)
8091   "Figure out what the initial limit is supposed to be on group entry.
8092 This entails weeding out unwanted dormants, low-scored articles,
8093 fetch-old-headers verbiage, and so on."
8094   ;; Most groups have nothing to remove.
8095   (if (or gnus-inhibit-limiting
8096           (and (null gnus-newsgroup-dormant)
8097                (eq gnus-newsgroup-display 'gnus-not-ignore)
8098                (not (eq gnus-fetch-old-headers 'some))
8099                (not (numberp gnus-fetch-old-headers))
8100                (not (eq gnus-fetch-old-headers 'invisible))
8101                (null gnus-summary-expunge-below)
8102                (not (eq gnus-build-sparse-threads 'some))
8103                (not (eq gnus-build-sparse-threads 'more))
8104                (null gnus-thread-expunge-below)
8105                (not gnus-use-nocem)))
8106       ()                                ; Do nothing.
8107     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8108     (setq gnus-newsgroup-limit nil)
8109     (mapatoms
8110      (lambda (node)
8111        (unless (car (symbol-value node))
8112          ;; These threads have no parents -- they are roots.
8113          (let ((nodes (cdr (symbol-value node)))
8114                thread)
8115            (while nodes
8116              (if (and gnus-thread-expunge-below
8117                       (< (gnus-thread-total-score (car nodes))
8118                          gnus-thread-expunge-below))
8119                  (gnus-expunge-thread (pop nodes))
8120                (setq thread (pop nodes))
8121                (gnus-summary-limit-children thread))))))
8122      gnus-newsgroup-dependencies)
8123     ;; If this limitation resulted in an empty group, we might
8124     ;; pop the previous limit and use it instead.
8125     (when (and (not gnus-newsgroup-limit)
8126                show-if-empty)
8127       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8128     gnus-newsgroup-limit))
8129
8130 (defun gnus-summary-limit-children (thread)
8131   "Return 1 if this subthread is visible and 0 if it is not."
8132   ;; First we get the number of visible children to this thread.  This
8133   ;; is done by recursing down the thread using this function, so this
8134   ;; will really go down to a leaf article first, before slowly
8135   ;; working its way up towards the root.
8136   (when thread
8137     (let* ((max-lisp-eval-depth 5000)
8138            (children
8139            (if (cdr thread)
8140                (apply '+ (mapcar 'gnus-summary-limit-children
8141                                  (cdr thread)))
8142              0))
8143           (number (mail-header-number (car thread)))
8144           score)
8145       (if (and
8146            (not (memq number gnus-newsgroup-marked))
8147            (or
8148             ;; If this article is dormant and has absolutely no visible
8149             ;; children, then this article isn't visible.
8150             (and (memq number gnus-newsgroup-dormant)
8151                  (zerop children))
8152             ;; If this is "fetch-old-headered" and there is no
8153             ;; visible children, then we don't want this article.
8154             (and (or (eq gnus-fetch-old-headers 'some)
8155                      (numberp gnus-fetch-old-headers))
8156                  (gnus-summary-article-ancient-p number)
8157                  (zerop children))
8158             ;; If this is "fetch-old-headered" and `invisible', then
8159             ;; we don't want this article.
8160             (and (eq gnus-fetch-old-headers 'invisible)
8161                  (gnus-summary-article-ancient-p number))
8162             ;; If this is a sparsely inserted article with no children,
8163             ;; we don't want it.
8164             (and (eq gnus-build-sparse-threads 'some)
8165                  (gnus-summary-article-sparse-p number)
8166                  (zerop children))
8167             ;; If we use expunging, and this article is really
8168             ;; low-scored, then we don't want this article.
8169             (when (and gnus-summary-expunge-below
8170                        (< (setq score
8171                                 (or (cdr (assq number gnus-newsgroup-scored))
8172                                     gnus-summary-default-score))
8173                           gnus-summary-expunge-below))
8174               ;; We increase the expunge-tally here, but that has
8175               ;; nothing to do with the limits, really.
8176               (incf gnus-newsgroup-expunged-tally)
8177               ;; We also mark as read here, if that's wanted.
8178               (when (and gnus-summary-mark-below
8179                          (< score gnus-summary-mark-below))
8180                 (setq gnus-newsgroup-unreads
8181                       (delq number gnus-newsgroup-unreads))
8182                 (if gnus-newsgroup-auto-expire
8183                     (push number gnus-newsgroup-expirable)
8184                   (push (cons number gnus-low-score-mark)
8185                         gnus-newsgroup-reads)))
8186               t)
8187             ;; Do the `display' group parameter.
8188             (and gnus-newsgroup-display
8189                  (not (funcall gnus-newsgroup-display)))
8190             ;; Check NoCeM things.
8191             (when (and gnus-use-nocem
8192                        (gnus-nocem-unwanted-article-p
8193                         (mail-header-id (car thread))))
8194               (setq gnus-newsgroup-unreads
8195                     (delq number gnus-newsgroup-unreads))
8196               t)))
8197           ;; Nope, invisible article.
8198           0
8199         ;; Ok, this article is to be visible, so we add it to the limit
8200         ;; and return 1.
8201         (push number gnus-newsgroup-limit)
8202         1))))
8203
8204 (defun gnus-expunge-thread (thread)
8205   "Mark all articles in THREAD as read."
8206   (let* ((number (mail-header-number (car thread))))
8207     (incf gnus-newsgroup-expunged-tally)
8208     ;; We also mark as read here, if that's wanted.
8209     (setq gnus-newsgroup-unreads
8210           (delq number gnus-newsgroup-unreads))
8211     (if gnus-newsgroup-auto-expire
8212         (push number gnus-newsgroup-expirable)
8213       (push (cons number gnus-low-score-mark)
8214             gnus-newsgroup-reads)))
8215   ;; Go recursively through all subthreads.
8216   (mapcar 'gnus-expunge-thread (cdr thread)))
8217
8218 ;; Summary article oriented commands
8219
8220 (defun gnus-summary-refer-parent-article (n)
8221   "Refer parent article N times.
8222 If N is negative, go to ancestor -N instead.
8223 The difference between N and the number of articles fetched is returned."
8224   (interactive "p")
8225   (let ((skip 1)
8226         error header ref)
8227     (when (not (natnump n))
8228       (setq skip (abs n)
8229             n 1))
8230     (while (and (> n 0)
8231                 (not error))
8232       (setq header (gnus-summary-article-header))
8233       (if (and (eq (mail-header-number header)
8234                    (cdr gnus-article-current))
8235                (equal gnus-newsgroup-name
8236                       (car gnus-article-current)))
8237           ;; If we try to find the parent of the currently
8238           ;; displayed article, then we take a look at the actual
8239           ;; References header, since this is slightly more
8240           ;; reliable than the References field we got from the
8241           ;; server.
8242           (save-excursion
8243             (set-buffer gnus-original-article-buffer)
8244             (nnheader-narrow-to-headers)
8245             (unless (setq ref (message-fetch-field "references"))
8246               (when (setq ref (message-fetch-field "in-reply-to"))
8247                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8248             (widen))
8249         (setq ref
8250               ;; It's not the current article, so we take a bet on
8251               ;; the value we got from the server.
8252               (mail-header-references header)))
8253       (if (and ref
8254                (not (equal ref "")))
8255           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8256             (gnus-message 1 "Couldn't find parent"))
8257         (gnus-message 1 "No references in article %d"
8258                       (gnus-summary-article-number))
8259         (setq error t))
8260       (decf n))
8261     (gnus-summary-position-point)
8262     n))
8263
8264 (defun gnus-summary-refer-references ()
8265   "Fetch all articles mentioned in the References header.
8266 Return the number of articles fetched."
8267   (interactive)
8268   (let ((ref (mail-header-references (gnus-summary-article-header)))
8269         (current (gnus-summary-article-number))
8270         (n 0))
8271     (if (or (not ref)
8272             (equal ref ""))
8273         (error "No References in the current article")
8274       ;; For each Message-ID in the References header...
8275       (while (string-match "<[^>]*>" ref)
8276         (incf n)
8277         ;; ... fetch that article.
8278         (gnus-summary-refer-article
8279          (prog1 (match-string 0 ref)
8280            (setq ref (substring ref (match-end 0))))))
8281       (gnus-summary-goto-subject current)
8282       (gnus-summary-position-point)
8283       n)))
8284
8285 (defun gnus-summary-refer-thread (&optional limit)
8286   "Fetch all articles in the current thread.
8287 If LIMIT (the numerical prefix), fetch that many old headers instead
8288 of what's specified by the `gnus-refer-thread-limit' variable."
8289   (interactive "P")
8290   (let ((id (mail-header-id (gnus-summary-article-header)))
8291         (limit (if limit (prefix-numeric-value limit)
8292                  gnus-refer-thread-limit)))
8293     (unless (eq gnus-fetch-old-headers 'invisible)
8294       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8295       ;; Retrieve the headers and read them in.
8296       (if (eq (if (numberp limit)
8297                   (gnus-retrieve-headers
8298                    (list (min
8299                           (+ (mail-header-number
8300                               (gnus-summary-article-header))
8301                              limit)
8302                           gnus-newsgroup-end))
8303                    gnus-newsgroup-name (* limit 2))
8304                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8305                 ;; headers.
8306                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8307                                        gnus-newsgroup-name limit))
8308               'nov)
8309           (gnus-build-all-threads)
8310         (error "Can't fetch thread from back ends that don't support NOV"))
8311       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8312     (gnus-summary-limit-include-thread id)))
8313
8314 (defun gnus-summary-refer-article (message-id)
8315   "Fetch an article specified by MESSAGE-ID."
8316   (interactive "sMessage-ID: ")
8317   (when (and (stringp message-id)
8318              (not (zerop (length message-id))))
8319     (setq message-id (gnus-replace-in-string message-id " " ""))
8320     ;; Construct the correct Message-ID if necessary.
8321     ;; Suggested by tale@pawl.rpi.edu.
8322     (unless (string-match "^<" message-id)
8323       (setq message-id (concat "<" message-id)))
8324     (unless (string-match ">$" message-id)
8325       (setq message-id (concat message-id ">")))
8326     ;; People often post MIDs from URLs, so unhex it:
8327     (unless (string-match "@" message-id)
8328       (setq message-id (gnus-url-unhex-string message-id)))
8329     (let* ((header (gnus-id-to-header message-id))
8330            (sparse (and header
8331                         (gnus-summary-article-sparse-p
8332                          (mail-header-number header))
8333                         (memq (mail-header-number header)
8334                               gnus-newsgroup-limit)))
8335            number)
8336       (cond
8337        ;; If the article is present in the buffer we just go to it.
8338        ((and header
8339              (or (not (gnus-summary-article-sparse-p
8340                        (mail-header-number header)))
8341                  sparse))
8342         (prog1
8343             (gnus-summary-goto-article
8344              (mail-header-number header) nil t)
8345           (when sparse
8346             (gnus-summary-update-article (mail-header-number header)))))
8347        (t
8348         ;; We fetch the article.
8349         (catch 'found
8350           (dolist (gnus-override-method (gnus-refer-article-methods))
8351             (when (and (gnus-check-server gnus-override-method)
8352                        ;; Fetch the header,
8353                        (setq number (gnus-summary-insert-subject message-id)))
8354               ;; and display the article.
8355               (gnus-summary-select-article nil nil nil number)
8356               (throw 'found t)))
8357           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8358
8359 (defun gnus-refer-article-methods ()
8360   "Return a list of referable methods."
8361   (cond
8362    ;; No method, so we default to current and native.
8363    ((null gnus-refer-article-method)
8364     (list gnus-current-select-method gnus-select-method))
8365    ;; Current.
8366    ((eq 'current gnus-refer-article-method)
8367     (list gnus-current-select-method))
8368    ;; List of select methods.
8369    ((not (and (symbolp (car gnus-refer-article-method))
8370               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8371     (let (out)
8372       (dolist (method gnus-refer-article-method)
8373         (push (if (eq 'current method)
8374                   gnus-current-select-method
8375                 method)
8376               out))
8377       (nreverse out)))
8378    ;; One single select method.
8379    (t
8380     (list gnus-refer-article-method))))
8381
8382 (defun gnus-summary-edit-parameters ()
8383   "Edit the group parameters of the current group."
8384   (interactive)
8385   (gnus-group-edit-group gnus-newsgroup-name 'params))
8386
8387 (defun gnus-summary-customize-parameters ()
8388   "Customize the group parameters of the current group."
8389   (interactive)
8390   (gnus-group-customize gnus-newsgroup-name))
8391
8392 (defun gnus-summary-enter-digest-group (&optional force)
8393   "Enter an nndoc group based on the current article.
8394 If FORCE, force a digest interpretation.  If not, try
8395 to guess what the document format is."
8396   (interactive "P")
8397   (let ((conf gnus-current-window-configuration))
8398     (save-window-excursion
8399       (save-excursion
8400         (let (gnus-article-prepare-hook
8401               gnus-display-mime-function
8402               gnus-break-pages)
8403           (gnus-summary-select-article))))
8404     (setq gnus-current-window-configuration conf)
8405     (let* ((name (format "%s-%d"
8406                          (gnus-group-prefixed-name
8407                           gnus-newsgroup-name (list 'nndoc ""))
8408                          (with-current-buffer gnus-summary-buffer
8409                            gnus-current-article)))
8410            (ogroup gnus-newsgroup-name)
8411            (params (append (gnus-info-params (gnus-get-info ogroup))
8412                            (list (cons 'to-group ogroup))
8413                            (list (cons 'parent-group ogroup))
8414                            (list (cons 'save-article-group ogroup))))
8415            (case-fold-search t)
8416            (buf (current-buffer))
8417            dig to-address)
8418       (save-excursion
8419         (set-buffer gnus-original-article-buffer)
8420         ;; Have the digest group inherit the main mail address of
8421         ;; the parent article.
8422         (when (setq to-address (or (gnus-fetch-field "reply-to")
8423                                    (gnus-fetch-field "from")))
8424           (setq params (append
8425                         (list (cons 'to-address
8426                                     (funcall gnus-decode-encoded-word-function
8427                                              to-address))))))
8428         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8429         (insert-buffer-substring gnus-original-article-buffer)
8430         ;; Remove lines that may lead nndoc to misinterpret the
8431         ;; document type.
8432         (narrow-to-region
8433          (goto-char (point-min))
8434          (or (search-forward "\n\n" nil t) (point)))
8435         (goto-char (point-min))
8436         (delete-matching-lines "^Path:\\|^From ")
8437         (widen))
8438       (unwind-protect
8439           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8440                     (gnus-newsgroup-ephemeral-ignored-charsets
8441                      gnus-newsgroup-ignored-charsets))
8442                 (gnus-group-read-ephemeral-group
8443                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8444                               (nndoc-article-type
8445                                ,(if force 'mbox 'guess)))
8446                  t nil nil nil
8447                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8448                                                         "ADAPT")))))
8449               ;; Make all postings to this group go to the parent group.
8450               (nconc (gnus-info-params (gnus-get-info name))
8451                      params)
8452             ;; Couldn't select this doc group.
8453             (switch-to-buffer buf)
8454             (gnus-set-global-variables)
8455             (gnus-configure-windows 'summary)
8456             (gnus-message 3 "Article couldn't be entered?"))
8457         (kill-buffer dig)))))
8458
8459 (defun gnus-summary-read-document (n)
8460   "Open a new group based on the current article(s).
8461 This will allow you to read digests and other similar
8462 documents as newsgroups.
8463 Obeys the standard process/prefix convention."
8464   (interactive "P")
8465   (let* ((ogroup gnus-newsgroup-name)
8466          (params (append (gnus-info-params (gnus-get-info ogroup))
8467                          (list (cons 'to-group ogroup))))
8468          group egroup groups vgroup)
8469     (dolist (article (gnus-summary-work-articles n))
8470       (setq group (format "%s-%d" gnus-newsgroup-name article))
8471       (gnus-summary-remove-process-mark article)
8472       (when (gnus-summary-display-article article)
8473         (save-excursion
8474           (with-temp-buffer
8475             (insert-buffer-substring gnus-original-article-buffer)
8476             ;; Remove some headers that may lead nndoc to make
8477             ;; the wrong guess.
8478             (message-narrow-to-head)
8479             (goto-char (point-min))
8480             (delete-matching-lines "^Path:\\|^From ")
8481             (widen)
8482             (if (setq egroup
8483                       (gnus-group-read-ephemeral-group
8484                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8485                                      (nndoc-article-type guess))
8486                        t nil t))
8487                 (progn
8488             ;; Make all postings to this group go to the parent group.
8489                   (nconc (gnus-info-params (gnus-get-info egroup))
8490                          params)
8491                   (push egroup groups))
8492               ;; Couldn't select this doc group.
8493               (gnus-error 3 "Article couldn't be entered"))))))
8494     ;; Now we have selected all the documents.
8495     (cond
8496      ((not groups)
8497       (error "None of the articles could be interpreted as documents"))
8498      ((gnus-group-read-ephemeral-group
8499        (setq vgroup (format
8500                      "nnvirtual:%s-%s" gnus-newsgroup-name
8501                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8502        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8503        t
8504        (cons (current-buffer) 'summary)))
8505      (t
8506       (error "Couldn't select virtual nndoc group")))))
8507
8508 (defun gnus-summary-isearch-article (&optional regexp-p)
8509   "Do incremental search forward on the current article.
8510 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8511   (interactive "P")
8512   (gnus-summary-select-article)
8513   (gnus-configure-windows 'article)
8514   (gnus-eval-in-buffer-window gnus-article-buffer
8515     (save-restriction
8516       (widen)
8517       (isearch-forward regexp-p))))
8518
8519 (defun gnus-summary-search-article-forward (regexp &optional backward)
8520   "Search for an article containing REGEXP forward.
8521 If BACKWARD, search backward instead."
8522   (interactive
8523    (list (read-string
8524           (format "Search article %s (regexp%s): "
8525                   (if current-prefix-arg "backward" "forward")
8526                   (if gnus-last-search-regexp
8527                       (concat ", default " gnus-last-search-regexp)
8528                     "")))
8529          current-prefix-arg))
8530   (if (string-equal regexp "")
8531       (setq regexp (or gnus-last-search-regexp ""))
8532     (setq gnus-last-search-regexp regexp)
8533     (setq gnus-article-before-search gnus-current-article))
8534   ;; Intentionally set gnus-last-article.
8535   (setq gnus-last-article gnus-article-before-search)
8536   (let ((gnus-last-article gnus-last-article))
8537     (if (gnus-summary-search-article regexp backward)
8538         (gnus-summary-show-thread)
8539       (signal 'search-failed (list regexp)))))
8540
8541 (defun gnus-summary-search-article-backward (regexp)
8542   "Search for an article containing REGEXP backward."
8543   (interactive
8544    (list (read-string
8545           (format "Search article backward (regexp%s): "
8546                   (if gnus-last-search-regexp
8547                       (concat ", default " gnus-last-search-regexp)
8548                     "")))))
8549   (gnus-summary-search-article-forward regexp 'backward))
8550
8551 (defun gnus-summary-search-article (regexp &optional backward)
8552   "Search for an article containing REGEXP.
8553 Optional argument BACKWARD means do search for backward.
8554 `gnus-select-article-hook' is not called during the search."
8555   ;; We have to require this here to make sure that the following
8556   ;; dynamic binding isn't shadowed by autoloading.
8557   (require 'gnus-async)
8558   (require 'gnus-art)
8559   (let ((gnus-select-article-hook nil)  ;Disable hook.
8560         (gnus-article-prepare-hook nil)
8561         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8562         (gnus-use-article-prefetch nil)
8563         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8564         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8565         (gnus-visual nil)
8566         (gnus-keep-backlog nil)
8567         (gnus-break-pages nil)
8568         (gnus-summary-display-arrow nil)
8569         (gnus-updated-mode-lines nil)
8570         (gnus-auto-center-summary nil)
8571         (sum (current-buffer))
8572         (gnus-display-mime-function nil)
8573         (found nil)
8574         point)
8575     (gnus-save-hidden-threads
8576       (gnus-summary-select-article)
8577       (set-buffer gnus-article-buffer)
8578       (goto-char (window-point (get-buffer-window (current-buffer))))
8579       (when backward
8580         (forward-line -1))
8581       (while (not found)
8582         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8583         (if (if backward
8584                 (re-search-backward regexp nil t)
8585               (re-search-forward regexp nil t))
8586             ;; We found the regexp.
8587             (progn
8588               (setq found 'found)
8589               (beginning-of-line)
8590               (set-window-start
8591                (get-buffer-window (current-buffer))
8592                (point))
8593               (forward-line 1)
8594               (set-window-point
8595                (get-buffer-window (current-buffer))
8596                (point))
8597               (set-buffer sum)
8598               (setq point (point)))
8599           ;; We didn't find it, so we go to the next article.
8600           (set-buffer sum)
8601           (setq found 'not)
8602           (while (eq found 'not)
8603             (if (not (if backward (gnus-summary-find-prev)
8604                        (gnus-summary-find-next)))
8605                 ;; No more articles.
8606                 (setq found t)
8607               ;; Select the next article and adjust point.
8608               (unless (gnus-summary-article-sparse-p
8609                        (gnus-summary-article-number))
8610                 (setq found nil)
8611                 (gnus-summary-select-article)
8612                 (set-buffer gnus-article-buffer)
8613                 (widen)
8614                 (goto-char (if backward (point-max) (point-min))))))))
8615       (gnus-message 7 ""))
8616     ;; Return whether we found the regexp.
8617     (when (eq found 'found)
8618       (goto-char point)
8619       (gnus-summary-show-thread)
8620       (gnus-summary-goto-subject gnus-current-article)
8621       (gnus-summary-position-point)
8622       t)))
8623
8624 (defun gnus-find-matching-articles (header regexp)
8625   "Return a list of all articles that match REGEXP on HEADER.
8626 This search includes all articles in the current group that Gnus has
8627 fetched headers for, whether they are displayed or not."
8628   (let ((articles nil)
8629         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8630         (case-fold-search t))
8631     (dolist (header gnus-newsgroup-headers)
8632       (when (string-match regexp (funcall func header))
8633         (push (mail-header-number header) articles)))
8634     (nreverse articles)))
8635
8636 (defun gnus-summary-find-matching (header regexp &optional backward unread
8637                                           not-case-fold not-matching)
8638   "Return a list of all articles that match REGEXP on HEADER.
8639 The search stars on the current article and goes forwards unless
8640 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8641 If UNREAD is non-nil, only unread articles will
8642 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8643 in the comparisons. If NOT-MATCHING, return a list of all articles that
8644 not match REGEXP on HEADER."
8645   (let ((case-fold-search (not not-case-fold))
8646         articles d func)
8647     (if (consp header)
8648         (if (eq (car header) 'extra)
8649             (setq func
8650                   `(lambda (h)
8651                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8652                          "")))
8653           (error "%s is an invalid header" header))
8654       (unless (fboundp (intern (concat "mail-header-" header)))
8655         (error "%s is not a valid header" header))
8656       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8657     (dolist (d (if (eq backward 'all)
8658                    gnus-newsgroup-data
8659                  (gnus-data-find-list
8660                   (gnus-summary-article-number)
8661                   (gnus-data-list backward))))
8662       (when (and (or (not unread)       ; We want all articles...
8663                      (gnus-data-unread-p d)) ; Or just unreads.
8664                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8665                  (if not-matching
8666                      (not (string-match
8667                            regexp
8668                            (funcall func (gnus-data-header d))))
8669                    (string-match regexp
8670                                  (funcall func (gnus-data-header d)))))
8671         (push (gnus-data-number d) articles))) ; Success!
8672     (nreverse articles)))
8673
8674 (defun gnus-summary-execute-command (header regexp command &optional backward)
8675   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8676 If HEADER is an empty string (or nil), the match is done on the entire
8677 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8678   (interactive
8679    (list (let ((completion-ignore-case t))
8680            (completing-read
8681             "Header name: "
8682             (mapcar (lambda (header) (list (format "%s" header)))
8683                     (append
8684                      '("Number" "Subject" "From" "Lines" "Date"
8685                        "Message-ID" "Xref" "References" "Body")
8686                      gnus-extra-headers))
8687             nil 'require-match))
8688          (read-string "Regexp: ")
8689          (read-key-sequence "Command: ")
8690          current-prefix-arg))
8691   (when (equal header "Body")
8692     (setq header ""))
8693   ;; Hidden thread subtrees must be searched as well.
8694   (gnus-summary-show-all-threads)
8695   ;; We don't want to change current point nor window configuration.
8696   (save-excursion
8697     (save-window-excursion
8698       (let (gnus-visual
8699             gnus-treat-strip-trailing-blank-lines
8700             gnus-treat-strip-leading-blank-lines
8701             gnus-treat-strip-multiple-blank-lines
8702             gnus-treat-hide-boring-headers
8703             gnus-treat-fold-newsgroups
8704             gnus-article-prepare-hook)
8705         (gnus-message 6 "Executing %s..." (key-description command))
8706         ;; We'd like to execute COMMAND interactively so as to give arguments.
8707         (gnus-execute header regexp
8708                       `(call-interactively ',(key-binding command))
8709                       backward)
8710         (gnus-message 6 "Executing %s...done" (key-description command))))))
8711
8712 (defun gnus-summary-beginning-of-article ()
8713   "Scroll the article back to the beginning."
8714   (interactive)
8715   (gnus-summary-select-article)
8716   (gnus-configure-windows 'article)
8717   (gnus-eval-in-buffer-window gnus-article-buffer
8718     (widen)
8719     (goto-char (point-min))
8720     (when gnus-break-pages
8721       (gnus-narrow-to-page))))
8722
8723 (defun gnus-summary-end-of-article ()
8724   "Scroll to the end of the article."
8725   (interactive)
8726   (gnus-summary-select-article)
8727   (gnus-configure-windows 'article)
8728   (gnus-eval-in-buffer-window gnus-article-buffer
8729     (widen)
8730     (goto-char (point-max))
8731     (recenter -3)
8732     (when gnus-break-pages
8733       (when (re-search-backward page-delimiter nil t)
8734         (narrow-to-region (match-end 0) (point-max)))
8735       (gnus-narrow-to-page))))
8736
8737 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8738   "Truncate to LEN and quote all \"(\"'s in STRING."
8739   (gnus-replace-in-string (if (and len (> (length string) len))
8740                               (substring string 0 len)
8741                             string)
8742                           "[()]" "\\\\\\&"))
8743
8744 (defun gnus-summary-print-article (&optional filename n)
8745   "Generate and print a PostScript image of the process-marked (mail) articles.
8746
8747 If used interactively, print the current article if none are
8748 process-marked.  With prefix arg, prompt the user for the name of the
8749 file to save in.
8750
8751 When used from Lisp, accept two optional args FILENAME and N.  N means
8752 to print the next N articles.  If N is negative, print the N previous
8753 articles.  If N is nil and articles have been marked with the process
8754 mark, print these instead.
8755
8756 If the optional first argument FILENAME is nil, send the image to the
8757 printer.  If FILENAME is a string, save the PostScript image in a file with
8758 that name.  If FILENAME is a number, prompt the user for the name of the file
8759 to save in."
8760   (interactive (list (ps-print-preprint current-prefix-arg)))
8761   (dolist (article (gnus-summary-work-articles n))
8762     (gnus-summary-select-article nil nil 'pseudo article)
8763     (gnus-eval-in-buffer-window gnus-article-buffer
8764       (gnus-print-buffer))
8765     (gnus-summary-remove-process-mark article))
8766   (ps-despool filename))
8767
8768 (defun gnus-print-buffer ()
8769   (let ((buffer (generate-new-buffer " *print*")))
8770     (unwind-protect
8771         (progn
8772           (copy-to-buffer buffer (point-min) (point-max))
8773           (set-buffer buffer)
8774           (gnus-remove-text-with-property 'gnus-decoration)
8775           (when (gnus-visual-p 'article-highlight 'highlight)
8776             ;; Copy-to-buffer doesn't copy overlay.  So redo
8777             ;; highlight.
8778             (let ((gnus-article-buffer buffer))
8779               (gnus-article-highlight-citation t)
8780               (gnus-article-highlight-signature)
8781               (gnus-article-emphasize)
8782               (gnus-article-delete-invisible-text)))
8783           (let ((ps-left-header
8784                  (list
8785                   (concat "("
8786                           (gnus-summary-print-truncate-and-quote
8787                            (mail-header-subject gnus-current-headers)
8788                            66) ")")
8789                   (concat "("
8790                           (gnus-summary-print-truncate-and-quote
8791                            (mail-header-from gnus-current-headers)
8792                            45) ")")))
8793                 (ps-right-header
8794                  (list
8795                   "/pagenumberstring load"
8796                   (concat "("
8797                           (mail-header-date gnus-current-headers) ")"))))
8798             (gnus-run-hooks 'gnus-ps-print-hook)
8799             (save-excursion
8800               (if window-system
8801                   (ps-spool-buffer-with-faces)
8802                 (ps-spool-buffer)))))
8803       (kill-buffer buffer))))
8804
8805 (defun gnus-summary-show-article (&optional arg)
8806   "Force redisplaying of the current article.
8807 If ARG (the prefix) is a number, show the article with the charset
8808 defined in `gnus-summary-show-article-charset-alist', or the charset
8809 input.
8810 If ARG (the prefix) is non-nil and not a number, show the raw article
8811 without any article massaging functions being run.  Normally, the key
8812 strokes are `C-u g'."
8813   (interactive "P")
8814   (cond
8815    ((numberp arg)
8816     (gnus-summary-show-article t)
8817     (let ((gnus-newsgroup-charset
8818            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8819                (mm-read-coding-system
8820                 "View as charset: " ;; actually it is coding system.
8821                 (with-current-buffer gnus-article-buffer
8822                   (mm-detect-coding-region (point) (point-max))))))
8823           (gnus-newsgroup-ignored-charsets 'gnus-all))
8824       (gnus-summary-select-article nil 'force)
8825       (let ((deps gnus-newsgroup-dependencies)
8826             head header lines)
8827         (save-excursion
8828           (set-buffer gnus-original-article-buffer)
8829           (save-restriction
8830             (message-narrow-to-head)
8831             (setq head (buffer-string))
8832             (goto-char (point-min))
8833             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8834               (goto-char (point-max))
8835               (widen)
8836               (setq lines (1- (count-lines (point) (point-max))))))
8837           (with-temp-buffer
8838             (insert (format "211 %d Article retrieved.\n"
8839                             (cdr gnus-article-current)))
8840             (insert head)
8841             (if lines (insert (format "Lines: %d\n" lines)))
8842             (insert ".\n")
8843             (let ((nntp-server-buffer (current-buffer)))
8844               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8845         (gnus-data-set-header
8846          (gnus-data-find (cdr gnus-article-current))
8847          header)
8848         (gnus-summary-update-article-line
8849          (cdr gnus-article-current) header)
8850         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8851           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8852    ((not arg)
8853     ;; Select the article the normal way.
8854     (gnus-summary-select-article nil 'force))
8855    (t
8856     ;; We have to require this here to make sure that the following
8857     ;; dynamic binding isn't shadowed by autoloading.
8858     (require 'gnus-async)
8859     (require 'gnus-art)
8860     ;; Bind the article treatment functions to nil.
8861     (let ((gnus-have-all-headers t)
8862           gnus-article-prepare-hook
8863           gnus-article-decode-hook
8864           gnus-display-mime-function
8865           gnus-break-pages)
8866       ;; Destroy any MIME parts.
8867       (when (gnus-buffer-live-p gnus-article-buffer)
8868         (save-excursion
8869           (set-buffer gnus-article-buffer)
8870           (mm-destroy-parts gnus-article-mime-handles)
8871           ;; Set it to nil for safety reason.
8872           (setq gnus-article-mime-handle-alist nil)
8873           (setq gnus-article-mime-handles nil)))
8874       (gnus-summary-select-article nil 'force))))
8875   (gnus-summary-goto-subject gnus-current-article)
8876   (gnus-summary-position-point))
8877
8878 (defun gnus-summary-show-raw-article ()
8879   "Show the raw article without any article massaging functions being run."
8880   (interactive)
8881   (gnus-summary-show-article t))
8882
8883 (defun gnus-summary-verbose-headers (&optional arg)
8884   "Toggle permanent full header display.
8885 If ARG is a positive number, turn header display on.
8886 If ARG is a negative number, turn header display off."
8887   (interactive "P")
8888   (setq gnus-show-all-headers
8889         (cond ((or (not (numberp arg))
8890                    (zerop arg))
8891                (not gnus-show-all-headers))
8892               ((natnump arg)
8893                t)))
8894   (gnus-summary-show-article))
8895
8896 (defun gnus-summary-toggle-header (&optional arg)
8897   "Show the headers if they are hidden, or hide them if they are shown.
8898 If ARG is a positive number, show the entire header.
8899 If ARG is a negative number, hide the unwanted header lines."
8900   (interactive "P")
8901   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8902                      (get-buffer-window gnus-article-buffer t))))
8903     (with-current-buffer gnus-article-buffer
8904       (widen)
8905       (article-narrow-to-head)
8906       (let* ((buffer-read-only nil)
8907              (inhibit-point-motion-hooks t)
8908              (hidden (if (numberp arg)
8909                          (>= arg 0)
8910                        (or (not (looking-at "[^ \t\n]+:"))
8911                            (gnus-article-hidden-text-p 'headers))))
8912              s e)
8913         (delete-region (point-min) (point-max))
8914         (with-current-buffer gnus-original-article-buffer
8915           (goto-char (setq s (point-min)))
8916           (setq e (if (search-forward "\n\n" nil t)
8917                       (1- (point))
8918                     (point-max))))
8919         (insert-buffer-substring gnus-original-article-buffer s e)
8920         (run-hooks 'gnus-article-decode-hook)
8921         (if hidden
8922             (let ((gnus-treat-hide-headers nil)
8923                   (gnus-treat-hide-boring-headers nil))
8924               (gnus-delete-wash-type 'headers)
8925               (gnus-treat-article 'head))
8926           (gnus-treat-article 'head))
8927         (widen)
8928         (if window
8929             (set-window-start window (goto-char (point-min))))
8930         (if gnus-break-pages
8931             (gnus-narrow-to-page)
8932           (when (gnus-visual-p 'page-marker)
8933             (let ((buffer-read-only nil))
8934               (gnus-remove-text-with-property 'gnus-prev)
8935               (gnus-remove-text-with-property 'gnus-next))))
8936         (gnus-set-mode-line 'article)))))
8937
8938 (defun gnus-summary-show-all-headers ()
8939   "Make all header lines visible."
8940   (interactive)
8941   (gnus-summary-toggle-header 1))
8942
8943 (defun gnus-summary-caesar-message (&optional arg)
8944   "Caesar rotate the current article by 13.
8945 The numerical prefix specifies how many places to rotate each letter
8946 forward."
8947   (interactive "P")
8948   (gnus-summary-select-article)
8949   (let ((mail-header-separator ""))
8950     (gnus-eval-in-buffer-window gnus-article-buffer
8951       (save-restriction
8952         (widen)
8953         (let ((start (window-start))
8954               buffer-read-only)
8955           (message-caesar-buffer-body arg)
8956           (set-window-start (get-buffer-window (current-buffer)) start))))))
8957
8958 (defun gnus-summary-idna-message (&optional arg)
8959   "Decode IDNA encoded domain names in the current articles.
8960 IDNA encoded domain names looks like `xn--bar'.  If a string
8961 remain unencoded after running this function, it is likely an
8962 invalid IDNA string (`xn--bar' is invalid).
8963
8964 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
8965 installed for this command to work."
8966   (interactive "P")
8967   (if (not (and (condition-case nil (require 'idna)
8968                   (file-error))
8969                 (mm-coding-system-p 'utf-8)
8970                 (executable-find (symbol-value 'idna-program))))
8971       (gnus-message
8972        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
8973     (gnus-summary-select-article)
8974     (let ((mail-header-separator ""))
8975       (gnus-eval-in-buffer-window gnus-article-buffer
8976         (save-restriction
8977           (widen)
8978           (let ((start (window-start))
8979                 buffer-read-only)
8980             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
8981               (replace-match (idna-to-unicode (match-string 1))))
8982             (set-window-start (get-buffer-window (current-buffer)) start)))))))
8983
8984 (autoload 'unmorse-region "morse"
8985   "Convert morse coded text in region to ordinary ASCII text."
8986   t)
8987
8988 (defun gnus-summary-morse-message (&optional arg)
8989   "Morse decode the current article."
8990   (interactive "P")
8991   (gnus-summary-select-article)
8992   (let ((mail-header-separator ""))
8993     (gnus-eval-in-buffer-window gnus-article-buffer
8994       (save-excursion
8995         (save-restriction
8996           (widen)
8997           (let ((pos (window-start))
8998                 buffer-read-only)
8999             (goto-char (point-min))
9000             (when (message-goto-body)
9001               (gnus-narrow-to-body))
9002             (goto-char (point-min))
9003             (while (search-forward "·" (point-max) t)
9004               (replace-match "."))
9005             (unmorse-region (point-min) (point-max))
9006             (widen)
9007             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9008
9009 (defun gnus-summary-stop-page-breaking ()
9010   "Stop page breaking in the current article."
9011   (interactive)
9012   (gnus-summary-select-article)
9013   (gnus-eval-in-buffer-window gnus-article-buffer
9014     (widen)
9015     (when (gnus-visual-p 'page-marker)
9016       (let ((buffer-read-only nil))
9017         (gnus-remove-text-with-property 'gnus-prev)
9018         (gnus-remove-text-with-property 'gnus-next))
9019       (setq gnus-page-broken nil))))
9020
9021 (defun gnus-summary-move-article (&optional n to-newsgroup
9022                                             select-method action)
9023   "Move the current article to a different newsgroup.
9024 If N is a positive number, move the N next articles.
9025 If N is a negative number, move the N previous articles.
9026 If N is nil and any articles have been marked with the process mark,
9027 move those articles instead.
9028 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9029 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9030 re-spool using this method.
9031
9032 When called interactively with TO-NEWSGROUP being nil, the value of
9033 the variable `gnus-move-split-methods' is used for finding a default
9034 for the target newsgroup.
9035
9036 For this function to work, both the current newsgroup and the
9037 newsgroup that you want to move to have to support the `request-move'
9038 and `request-accept' functions.
9039
9040 ACTION can be either `move' (the default), `crosspost' or `copy'."
9041   (interactive "P")
9042   (unless action
9043     (setq action 'move))
9044   ;; Check whether the source group supports the required functions.
9045   (cond ((and (eq action 'move)
9046               (not (gnus-check-backend-function
9047                     'request-move-article gnus-newsgroup-name)))
9048          (error "The current group does not support article moving"))
9049         ((and (eq action 'crosspost)
9050               (not (gnus-check-backend-function
9051                     'request-replace-article gnus-newsgroup-name)))
9052          (error "The current group does not support article editing")))
9053   (let ((articles (gnus-summary-work-articles n))
9054         (prefix (if (gnus-check-backend-function
9055                      'request-move-article gnus-newsgroup-name)
9056                     (funcall gnus-move-group-prefix-function
9057                              gnus-newsgroup-name)
9058                   ""))
9059         (names '((move "Move" "Moving")
9060                  (copy "Copy" "Copying")
9061                  (crosspost "Crosspost" "Crossposting")))
9062         (copy-buf (save-excursion
9063                     (nnheader-set-temp-buffer " *copy article*")))
9064         art-group to-method new-xref article to-groups)
9065     (unless (assq action names)
9066       (error "Unknown action %s" action))
9067     ;; Read the newsgroup name.
9068     (when (and (not to-newsgroup)
9069                (not select-method))
9070       (if (and gnus-move-split-methods
9071                (not
9072                 (and (memq gnus-current-article articles)
9073                      (gnus-buffer-live-p gnus-original-article-buffer))))
9074           ;; When `gnus-move-split-methods' is non-nil, we have to
9075           ;; select an article to give `gnus-read-move-group-name' an
9076           ;; opportunity to suggest an appropriate default.  However,
9077           ;; we needn't render or mark the article.
9078           (let ((gnus-display-mime-function nil)
9079                 (gnus-article-prepare-hook nil)
9080                 (gnus-mark-article-hook nil))
9081             (gnus-summary-select-article nil nil nil (car articles))))
9082       (setq to-newsgroup
9083             (gnus-read-move-group-name
9084              (cadr (assq action names))
9085              (symbol-value (intern (format "gnus-current-%s-group" action)))
9086              articles prefix))
9087       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9088     (setq to-method (or select-method
9089                         (gnus-server-to-method
9090                          (gnus-group-method to-newsgroup))))
9091     ;; Check the method we are to move this article to...
9092     (unless (gnus-check-backend-function
9093              'request-accept-article (car to-method))
9094       (error "%s does not support article copying" (car to-method)))
9095     (unless (gnus-check-server to-method)
9096       (error "Can't open server %s" (car to-method)))
9097     (gnus-message 6 "%s to %s: %s..."
9098                   (caddr (assq action names))
9099                   (or (car select-method) to-newsgroup) articles)
9100     (while articles
9101       (setq article (pop articles))
9102       (setq
9103        art-group
9104        (cond
9105         ;; Move the article.
9106         ((eq action 'move)
9107          ;; Remove this article from future suppression.
9108          (gnus-dup-unsuppress-article article)
9109          (gnus-request-move-article
9110           article                       ; Article to move
9111           gnus-newsgroup-name           ; From newsgroup
9112           (nth 1 (gnus-find-method-for-group
9113                   gnus-newsgroup-name)) ; Server
9114           (list 'gnus-request-accept-article
9115                 to-newsgroup (list 'quote select-method)
9116                 (not articles) t)       ; Accept form
9117           (not articles)))              ; Only save nov last time
9118         ;; Copy the article.
9119         ((eq action 'copy)
9120          (save-excursion
9121            (set-buffer copy-buf)
9122            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9123              (save-restriction
9124                (nnheader-narrow-to-headers)
9125                (dolist (hdr gnus-copy-article-ignored-headers)
9126                  (message-remove-header hdr t)))
9127              (gnus-request-accept-article
9128               to-newsgroup select-method (not articles) t))))
9129         ;; Crosspost the article.
9130         ((eq action 'crosspost)
9131          (let ((xref (message-tokenize-header
9132                       (mail-header-xref (gnus-summary-article-header article))
9133                       " ")))
9134            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9135                                   ":" (number-to-string article)))
9136            (unless xref
9137              (setq xref (list (system-name))))
9138            (setq new-xref
9139                  (concat
9140                   (mapconcat 'identity
9141                              (delete "Xref:" (delete new-xref xref))
9142                              " ")
9143                   " " new-xref))
9144            (save-excursion
9145              (set-buffer copy-buf)
9146              ;; First put the article in the destination group.
9147              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9148              (when (consp (setq art-group
9149                                 (gnus-request-accept-article
9150                                  to-newsgroup select-method (not articles))))
9151                (setq new-xref (concat new-xref " " (car art-group)
9152                                       ":"
9153                                       (number-to-string (cdr art-group))))
9154                ;; Now we have the new Xrefs header, so we insert
9155                ;; it and replace the new article.
9156                (nnheader-replace-header "Xref" new-xref)
9157                (gnus-request-replace-article
9158                 (cdr art-group) to-newsgroup (current-buffer))
9159                art-group))))))
9160       (cond
9161        ((not art-group)
9162         (gnus-message 1 "Couldn't %s article %s: %s"
9163                       (cadr (assq action names)) article
9164                       (nnheader-get-report (car to-method))))
9165        ((eq art-group 'junk)
9166         (when (eq action 'move)
9167           (gnus-summary-mark-article article gnus-canceled-mark)
9168           (gnus-message 4 "Deleted article %s" article)
9169           ;; run the delete hook
9170           (run-hook-with-args 'gnus-summary-article-delete-hook
9171                               action
9172                               (gnus-data-header
9173                                (assoc article (gnus-data-list nil)))
9174                               gnus-newsgroup-name nil
9175                               select-method)))
9176        (t
9177         (let* ((pto-group (gnus-group-prefixed-name
9178                            (car art-group) to-method))
9179                (info (gnus-get-info pto-group))
9180                (to-group (gnus-info-group info))
9181                to-marks)
9182           ;; Update the group that has been moved to.
9183           (when (and info
9184                      (memq action '(move copy)))
9185             (unless (member to-group to-groups)
9186               (push to-group to-groups))
9187
9188             (unless (memq article gnus-newsgroup-unreads)
9189               (push 'read to-marks)
9190               (gnus-info-set-read
9191                info (gnus-add-to-range (gnus-info-read info)
9192                                        (list (cdr art-group)))))
9193
9194             ;; See whether the article is to be put in the cache.
9195             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9196                              gnus-article-mark-lists
9197                            (delete '(expirable . expire)
9198                                    (copy-sequence gnus-article-mark-lists))))
9199                   (to-article (cdr art-group)))
9200
9201               ;; Enter the article into the cache in the new group,
9202               ;; if that is required.
9203               (when gnus-use-cache
9204                 (gnus-cache-possibly-enter-article
9205                  to-group to-article
9206                  (memq article gnus-newsgroup-marked)
9207                  (memq article gnus-newsgroup-dormant)
9208                  (memq article gnus-newsgroup-unreads)))
9209
9210               (when gnus-preserve-marks
9211                 ;; Copy any marks over to the new group.
9212                 (when (and (equal to-group gnus-newsgroup-name)
9213                            (not (memq article gnus-newsgroup-unreads)))
9214                   ;; Mark this article as read in this group.
9215                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9216                   (setcdr (gnus-active to-group) to-article)
9217                   (setcdr gnus-newsgroup-active to-article))
9218
9219                 (while marks
9220                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9221                     (when (memq article (symbol-value
9222                                          (intern (format "gnus-newsgroup-%s"
9223                                                          (caar marks)))))
9224                       (push (cdar marks) to-marks)
9225                       ;; If the other group is the same as this group,
9226                       ;; then we have to add the mark to the list.
9227                       (when (equal to-group gnus-newsgroup-name)
9228                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9229                              (cons to-article
9230                                    (symbol-value
9231                                     (intern (format "gnus-newsgroup-%s"
9232                                                     (caar marks)))))))
9233                       ;; Copy the marks to other group.
9234                       (gnus-add-marked-articles
9235                        to-group (cdar marks) (list to-article) info)))
9236                   (setq marks (cdr marks)))
9237
9238                 (gnus-request-set-mark
9239                  to-group (list (list (list to-article) 'add to-marks))))
9240
9241               (gnus-dribble-enter
9242                (concat "(gnus-group-set-info '"
9243                        (gnus-prin1-to-string (gnus-get-info to-group))
9244                        ")"))))
9245
9246           ;; Update the Xref header in this article to point to
9247           ;; the new crossposted article we have just created.
9248           (when (eq action 'crosspost)
9249             (save-excursion
9250               (set-buffer copy-buf)
9251               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9252               (nnheader-replace-header "Xref" new-xref)
9253               (gnus-request-replace-article
9254                article gnus-newsgroup-name (current-buffer))))
9255
9256           ;; run the move/copy/crosspost/respool hook
9257           (run-hook-with-args 'gnus-summary-article-move-hook
9258                               action
9259                               (gnus-data-header
9260                                (assoc article (gnus-data-list nil)))
9261                               gnus-newsgroup-name
9262                               to-newsgroup
9263                               select-method))
9264
9265         ;;;!!!Why is this necessary?
9266         (set-buffer gnus-summary-buffer)
9267
9268         (gnus-summary-goto-subject article)
9269         (when (eq action 'move)
9270           (gnus-summary-mark-article article gnus-canceled-mark))))
9271       (gnus-summary-remove-process-mark article))
9272     ;; Re-activate all groups that have been moved to.
9273     (save-excursion
9274       (set-buffer gnus-group-buffer)
9275       (let ((gnus-group-marked to-groups))
9276         (gnus-group-get-new-news-this-group nil t)))
9277
9278     (gnus-kill-buffer copy-buf)
9279     (gnus-summary-position-point)
9280     (gnus-set-mode-line 'summary)))
9281
9282 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9283   "Copy the current article to some other group.
9284 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9285 When called interactively, if TO-NEWSGROUP is nil, use the value of
9286 the variable `gnus-move-split-methods' for finding a default target
9287 newsgroup.
9288 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9289 re-spool using this method."
9290   (interactive "P")
9291   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9292
9293 (defun gnus-summary-crosspost-article (&optional n)
9294   "Crosspost the current article to some other group."
9295   (interactive "P")
9296   (gnus-summary-move-article n nil nil 'crosspost))
9297
9298 (defcustom gnus-summary-respool-default-method nil
9299   "Default method type for respooling an article.
9300 If nil, use to the current newsgroup method."
9301   :type 'symbol
9302   :group 'gnus-summary-mail)
9303
9304 (defcustom gnus-summary-display-while-building nil
9305   "If non-nil, show and update the summary buffer as it's being built.
9306 If the value is t, update the buffer after every line is inserted.  If
9307 the value is an integer (N), update the display every N lines."
9308   :version "22.1"
9309   :group 'gnus-thread
9310   :type '(choice (const :tag "off" nil)
9311                  number
9312                  (const :tag "frequently" t)))
9313
9314 (defun gnus-summary-respool-article (&optional n method)
9315   "Respool the current article.
9316 The article will be squeezed through the mail spooling process again,
9317 which means that it will be put in some mail newsgroup or other
9318 depending on `nnmail-split-methods'.
9319 If N is a positive number, respool the N next articles.
9320 If N is a negative number, respool the N previous articles.
9321 If N is nil and any articles have been marked with the process mark,
9322 respool those articles instead.
9323
9324 Respooling can be done both from mail groups and \"real\" newsgroups.
9325 In the former case, the articles in question will be moved from the
9326 current group into whatever groups they are destined to.  In the
9327 latter case, they will be copied into the relevant groups."
9328   (interactive
9329    (list current-prefix-arg
9330          (let* ((methods (gnus-methods-using 'respool))
9331                 (methname
9332                  (symbol-name (or gnus-summary-respool-default-method
9333                                   (car (gnus-find-method-for-group
9334                                         gnus-newsgroup-name)))))
9335                 (method
9336                  (gnus-completing-read-with-default
9337                   methname "What backend do you want to use when respooling?"
9338                   methods nil t nil 'gnus-mail-method-history))
9339                 ms)
9340            (cond
9341             ((zerop (length (setq ms (gnus-servers-using-backend
9342                                       (intern method)))))
9343              (list (intern method) ""))
9344             ((= 1 (length ms))
9345              (car ms))
9346             (t
9347              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9348                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9349                            ms-alist))))))))
9350   (unless method
9351     (error "No method given for respooling"))
9352   (if (assoc (symbol-name
9353               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9354              (gnus-methods-using 'respool))
9355       (gnus-summary-move-article n nil method)
9356     (gnus-summary-copy-article n nil method)))
9357
9358 (defun gnus-summary-import-article (file &optional edit)
9359   "Import an arbitrary file into a mail newsgroup."
9360   (interactive "fImport file: \nP")
9361   (let ((group gnus-newsgroup-name)
9362         (now (current-time))
9363         atts lines group-art)
9364     (unless (gnus-check-backend-function 'request-accept-article group)
9365       (error "%s does not support article importing" group))
9366     (or (file-readable-p file)
9367         (not (file-regular-p file))
9368         (error "Can't read %s" file))
9369     (save-excursion
9370       (set-buffer (gnus-get-buffer-create " *import file*"))
9371       (erase-buffer)
9372       (nnheader-insert-file-contents file)
9373       (goto-char (point-min))
9374       (if (nnheader-article-p)
9375           (save-restriction
9376             (goto-char (point-min))
9377             (search-forward "\n\n" nil t)
9378             (narrow-to-region (point-min) (1- (point)))
9379             (goto-char (point-min))
9380             (unless (re-search-forward "^date:" nil t)
9381               (goto-char (point-max))
9382               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9383        ;; This doesn't look like an article, so we fudge some headers.
9384         (setq atts (file-attributes file)
9385               lines (count-lines (point-min) (point-max)))
9386         (insert "From: " (read-string "From: ") "\n"
9387                 "Subject: " (read-string "Subject: ") "\n"
9388                 "Date: " (message-make-date (nth 5 atts)) "\n"
9389                 "Message-ID: " (message-make-message-id) "\n"
9390                 "Lines: " (int-to-string lines) "\n"
9391                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9392       (setq group-art (gnus-request-accept-article group nil t))
9393       (kill-buffer (current-buffer)))
9394     (setq gnus-newsgroup-active (gnus-activate-group group))
9395     (forward-line 1)
9396     (gnus-summary-goto-article (cdr group-art) nil t)
9397     (when edit
9398       (gnus-summary-edit-article))))
9399
9400 (defun gnus-summary-create-article ()
9401   "Create an article in a mail newsgroup."
9402   (interactive)
9403   (let ((group gnus-newsgroup-name)
9404         (now (current-time))
9405         group-art)
9406     (unless (gnus-check-backend-function 'request-accept-article group)
9407       (error "%s does not support article importing" group))
9408     (save-excursion
9409       (set-buffer (gnus-get-buffer-create " *import file*"))
9410       (erase-buffer)
9411       (goto-char (point-min))
9412       ;; This doesn't look like an article, so we fudge some headers.
9413       (insert "From: " (read-string "From: ") "\n"
9414               "Subject: " (read-string "Subject: ") "\n"
9415               "Date: " (message-make-date now) "\n"
9416               "Message-ID: " (message-make-message-id) "\n")
9417       (setq group-art (gnus-request-accept-article group nil t))
9418       (kill-buffer (current-buffer)))
9419     (setq gnus-newsgroup-active (gnus-activate-group group))
9420     (forward-line 1)
9421     (gnus-summary-goto-article (cdr group-art) nil t)
9422     (gnus-summary-edit-article)))
9423
9424 (defun gnus-summary-article-posted-p ()
9425   "Say whether the current (mail) article is available from news as well.
9426 This will be the case if the article has both been mailed and posted."
9427   (interactive)
9428   (let ((id (mail-header-references (gnus-summary-article-header)))
9429         (gnus-override-method (car (gnus-refer-article-methods))))
9430     (if (gnus-request-head id "")
9431         (gnus-message 2 "The current message was found on %s"
9432                       gnus-override-method)
9433       (gnus-message 2 "The current message couldn't be found on %s"
9434                     gnus-override-method)
9435       nil)))
9436
9437 (defun gnus-summary-expire-articles (&optional now)
9438   "Expire all articles that are marked as expirable in the current group."
9439   (interactive)
9440   (when (and (not gnus-group-is-exiting-without-update-p)
9441              (gnus-check-backend-function
9442               'request-expire-articles gnus-newsgroup-name))
9443     ;; This backend supports expiry.
9444     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9445            (expirable (if total
9446                           (progn
9447                             ;; We need to update the info for
9448                             ;; this group for `gnus-list-of-read-articles'
9449                             ;; to give us the right answer.
9450                             (gnus-run-hooks 'gnus-exit-group-hook)
9451                             (gnus-summary-update-info)
9452                             (gnus-list-of-read-articles gnus-newsgroup-name))
9453                         (setq gnus-newsgroup-expirable
9454                               (sort gnus-newsgroup-expirable '<))))
9455            (expiry-wait (if now 'immediate
9456                           (gnus-group-find-parameter
9457                            gnus-newsgroup-name 'expiry-wait)))
9458            (nnmail-expiry-target
9459             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9460                 nnmail-expiry-target))
9461            es)
9462       (when expirable
9463         ;; There are expirable articles in this group, so we run them
9464         ;; through the expiry process.
9465         (gnus-message 6 "Expiring articles...")
9466         (unless (gnus-check-group gnus-newsgroup-name)
9467           (error "Can't open server for %s" gnus-newsgroup-name))
9468         ;; The list of articles that weren't expired is returned.
9469         (save-excursion
9470           (if expiry-wait
9471               (let ((nnmail-expiry-wait-function nil)
9472                     (nnmail-expiry-wait expiry-wait))
9473                 (setq es (gnus-request-expire-articles
9474                           expirable gnus-newsgroup-name)))
9475             (setq es (gnus-request-expire-articles
9476                       expirable gnus-newsgroup-name)))
9477           (unless total
9478             (setq gnus-newsgroup-expirable es))
9479           ;; We go through the old list of expirable, and mark all
9480           ;; really expired articles as nonexistent.
9481           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9482             (let ((gnus-use-cache nil))
9483               (dolist (article expirable)
9484                 (when (and (not (memq article es))
9485                            (gnus-data-find article))
9486                   (gnus-summary-mark-article article gnus-canceled-mark)
9487                   (run-hook-with-args 'gnus-summary-article-expire-hook
9488                                       'delete
9489                                       (gnus-data-header
9490                                        (assoc article (gnus-data-list nil)))
9491                                       gnus-newsgroup-name
9492                                       nil
9493                                       nil))))))
9494         (gnus-message 6 "Expiring articles...done")))))
9495
9496 (defun gnus-summary-expire-articles-now ()
9497   "Expunge all expirable articles in the current group.
9498 This means that *all* articles that are marked as expirable will be
9499 deleted forever, right now."
9500   (interactive)
9501   (or gnus-expert-user
9502       (gnus-yes-or-no-p
9503        "Are you really, really, really sure you want to delete all these messages? ")
9504       (error "Phew!"))
9505   (gnus-summary-expire-articles t))
9506
9507 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9508 (defun gnus-summary-delete-article (&optional n)
9509   "Delete the N next (mail) articles.
9510 This command actually deletes articles.  This is not a marking
9511 command.  The article will disappear forever from your life, never to
9512 return.
9513
9514 If N is negative, delete backwards.
9515 If N is nil and articles have been marked with the process mark,
9516 delete these instead.
9517
9518 If `gnus-novice-user' is non-nil you will be asked for
9519 confirmation before the articles are deleted."
9520   (interactive "P")
9521   (unless (gnus-check-backend-function 'request-expire-articles
9522                                        gnus-newsgroup-name)
9523     (error "The current newsgroup does not support article deletion"))
9524   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9525     (error "Couldn't open server"))
9526   ;; Compute the list of articles to delete.
9527   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9528         (nnmail-expiry-target 'delete)
9529         not-deleted)
9530     (if (and gnus-novice-user
9531              (not (gnus-yes-or-no-p
9532                    (format "Do you really want to delete %s forever? "
9533                            (if (> (length articles) 1)
9534                                (format "these %s articles" (length articles))
9535                              "this article")))))
9536         ()
9537       ;; Delete the articles.
9538       (setq not-deleted (gnus-request-expire-articles
9539                          articles gnus-newsgroup-name 'force))
9540       (while articles
9541         (gnus-summary-remove-process-mark (car articles))
9542         ;; The backend might not have been able to delete the article
9543         ;; after all.
9544         (unless (memq (car articles) not-deleted)
9545           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9546         (let* ((article (car articles))
9547                (ghead  (gnus-data-header
9548                                     (assoc article (gnus-data-list nil)))))
9549           (run-hook-with-args 'gnus-summary-article-delete-hook
9550                               'delete ghead gnus-newsgroup-name nil
9551                               nil))
9552         (setq articles (cdr articles)))
9553       (when not-deleted
9554         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9555     (gnus-summary-position-point)
9556     (gnus-set-mode-line 'summary)
9557     not-deleted))
9558
9559 (defun gnus-summary-edit-article (&optional arg)
9560   "Edit the current article.
9561 This will have permanent effect only in mail groups.
9562 If ARG is nil, edit the decoded articles.
9563 If ARG is 1, edit the raw articles.
9564 If ARG is 2, edit the raw articles even in read-only groups.
9565 If ARG is 3, edit the articles with the current handles.
9566 Otherwise, allow editing of articles even in read-only
9567 groups."
9568   (interactive "P")
9569   (let (force raw current-handles)
9570     (cond
9571      ((null arg))
9572      ((eq arg 1)
9573       (setq raw t))
9574      ((eq arg 2)
9575       (setq raw t
9576             force t))
9577      ((eq arg 3)
9578       (setq current-handles
9579             (and (gnus-buffer-live-p gnus-article-buffer)
9580                  (with-current-buffer gnus-article-buffer
9581                    (prog1
9582                        gnus-article-mime-handles
9583                      (setq gnus-article-mime-handles nil))))))
9584      (t
9585       (setq force t)))
9586     (when (and raw (not force)
9587                (member gnus-newsgroup-name '("nndraft:delayed"
9588                                              "nndraft:drafts"
9589                                              "nndraft:queue")))
9590       (error "Can't edit the raw article in group %s"
9591              gnus-newsgroup-name))
9592     (save-excursion
9593       (set-buffer gnus-summary-buffer)
9594       (let ((mail-parse-charset gnus-newsgroup-charset)
9595             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9596         (gnus-set-global-variables)
9597         (when (and (not force)
9598                    (gnus-group-read-only-p))
9599           (error "The current newsgroup does not support article editing"))
9600         (gnus-summary-show-article t)
9601         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9602           (with-current-buffer gnus-article-buffer
9603             (mm-enable-multibyte)))
9604         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9605             (setq raw t))
9606         (gnus-article-edit-article
9607          (if raw 'ignore
9608            `(lambda ()
9609               (let ((mbl mml-buffer-list))
9610                 (setq mml-buffer-list nil)
9611                 (mime-to-mml ,'current-handles)
9612                 (let ((mbl1 mml-buffer-list))
9613                   (setq mml-buffer-list mbl)
9614                   (set (make-local-variable 'mml-buffer-list) mbl1))
9615                 (gnus-make-local-hook 'kill-buffer-hook)
9616                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9617          `(lambda (no-highlight)
9618             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9619                   (message-options message-options)
9620                   (message-options-set-recipient)
9621                   (mail-parse-ignored-charsets
9622                    ',gnus-newsgroup-ignored-charsets))
9623               ,(if (not raw) '(progn
9624                                 (mml-to-mime)
9625                                 (mml-destroy-buffers)
9626                                 (remove-hook 'kill-buffer-hook
9627                                              'mml-destroy-buffers t)
9628                                 (kill-local-variable 'mml-buffer-list)))
9629               (gnus-summary-edit-article-done
9630                ,(or (mail-header-references gnus-current-headers) "")
9631                ,(gnus-group-read-only-p)
9632                ,gnus-summary-buffer no-highlight))))))))
9633
9634 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9635
9636 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9637                                                  no-highlight)
9638   "Make edits to the current article permanent."
9639   (interactive)
9640   (save-excursion
9641    ;; The buffer restriction contains the entire article if it exists.
9642     (when (article-goto-body)
9643       (let ((lines (count-lines (point) (point-max)))
9644             (length (- (point-max) (point)))
9645             (case-fold-search t)
9646             (body (copy-marker (point))))
9647         (goto-char (point-min))
9648         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9649           (delete-region (match-beginning 1) (match-end 1))
9650           (insert (number-to-string length)))
9651         (goto-char (point-min))
9652         (when (re-search-forward
9653                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9654           (delete-region (match-beginning 1) (match-end 1))
9655           (insert (number-to-string length)))
9656         (goto-char (point-min))
9657         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9658           (delete-region (match-beginning 1) (match-end 1))
9659           (insert (number-to-string lines))))))
9660   ;; Replace the article.
9661   (let ((buf (current-buffer)))
9662     (with-temp-buffer
9663       (insert-buffer-substring buf)
9664
9665       (if (and (not read-only)
9666                (not (gnus-request-replace-article
9667                      (cdr gnus-article-current) (car gnus-article-current)
9668                      (current-buffer) t)))
9669           (error "Couldn't replace article")
9670         ;; Update the summary buffer.
9671         (if (and references
9672                  (equal (message-tokenize-header references " ")
9673                         (message-tokenize-header
9674                          (or (message-fetch-field "references") "") " ")))
9675             ;; We only have to update this line.
9676             (save-excursion
9677               (save-restriction
9678                 (message-narrow-to-head)
9679                 (let ((head (buffer-string))
9680                       header)
9681                   (with-temp-buffer
9682                     (insert (format "211 %d Article retrieved.\n"
9683                                     (cdr gnus-article-current)))
9684                     (insert head)
9685                     (insert ".\n")
9686                     (let ((nntp-server-buffer (current-buffer)))
9687                       (setq header (car (gnus-get-newsgroup-headers
9688                                          nil t))))
9689                     (save-excursion
9690                       (set-buffer gnus-summary-buffer)
9691                       (gnus-data-set-header
9692                        (gnus-data-find (cdr gnus-article-current))
9693                        header)
9694                       (gnus-summary-update-article-line
9695                        (cdr gnus-article-current) header)
9696                       (if (gnus-summary-goto-subject
9697                            (cdr gnus-article-current) nil t)
9698                           (gnus-summary-update-secondary-mark
9699                            (cdr gnus-article-current))))))))
9700           ;; Update threads.
9701           (set-buffer (or buffer gnus-summary-buffer))
9702           (gnus-summary-update-article (cdr gnus-article-current))
9703           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9704               (gnus-summary-update-secondary-mark
9705                (cdr gnus-article-current))))
9706         ;; Prettify the article buffer again.
9707         (unless no-highlight
9708           (save-excursion
9709             (set-buffer gnus-article-buffer)
9710             ;;;!!! Fix this -- article should be rehighlighted.
9711             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9712             (set-buffer gnus-original-article-buffer)
9713             (gnus-request-article
9714              (cdr gnus-article-current)
9715              (car gnus-article-current) (current-buffer))))
9716         ;; Prettify the summary buffer line.
9717         (when (gnus-visual-p 'summary-highlight 'highlight)
9718           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9719
9720 (defun gnus-summary-edit-wash (key)
9721   "Perform editing command KEY in the article buffer."
9722   (interactive
9723    (list
9724     (progn
9725       (message "%s" (concat (this-command-keys) "- "))
9726       (read-char))))
9727   (message "")
9728   (gnus-summary-edit-article)
9729   (execute-kbd-macro (concat (this-command-keys) key))
9730   (gnus-article-edit-done))
9731
9732 ;;; Respooling
9733
9734 (defun gnus-summary-respool-query (&optional silent trace)
9735   "Query where the respool algorithm would put this article."
9736   (interactive)
9737   (let (gnus-mark-article-hook)
9738     (gnus-summary-select-article)
9739     (save-excursion
9740       (set-buffer gnus-original-article-buffer)
9741       (let ((groups (nnmail-article-group 'identity trace)))
9742         (unless silent
9743           (if groups
9744               (message "This message would go to %s"
9745                        (mapconcat 'car groups ", "))
9746             (message "This message would go to no groups"))
9747           groups)))))
9748
9749 (defun gnus-summary-respool-trace ()
9750   "Trace where the respool algorithm would put this article.
9751 Display a buffer showing all fancy splitting patterns which matched."
9752   (interactive)
9753   (gnus-summary-respool-query nil t))
9754
9755 ;; Summary marking commands.
9756
9757 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9758   "Mark articles which has the same subject as read, and then select the next.
9759 If UNMARK is positive, remove any kind of mark.
9760 If UNMARK is negative, tick articles."
9761   (interactive "P")
9762   (when unmark
9763     (setq unmark (prefix-numeric-value unmark)))
9764   (let ((count
9765          (gnus-summary-mark-same-subject
9766           (gnus-summary-article-subject) unmark)))
9767     ;; Select next unread article.  If auto-select-same mode, should
9768     ;; select the first unread article.
9769     (gnus-summary-next-article t (and gnus-auto-select-same
9770                                       (gnus-summary-article-subject)))
9771     (gnus-message 7 "%d article%s marked as %s"
9772                   count (if (= count 1) " is" "s are")
9773                   (if unmark "unread" "read"))))
9774
9775 (defun gnus-summary-kill-same-subject (&optional unmark)
9776   "Mark articles which has the same subject as read.
9777 If UNMARK is positive, remove any kind of mark.
9778 If UNMARK is negative, tick articles."
9779   (interactive "P")
9780   (when unmark
9781     (setq unmark (prefix-numeric-value unmark)))
9782   (let ((count
9783          (gnus-summary-mark-same-subject
9784           (gnus-summary-article-subject) unmark)))
9785     ;; If marked as read, go to next unread subject.
9786     (when (null unmark)
9787       ;; Go to next unread subject.
9788       (gnus-summary-next-subject 1 t))
9789     (gnus-message 7 "%d articles are marked as %s"
9790                   count (if unmark "unread" "read"))))
9791
9792 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9793   "Mark articles with same SUBJECT as read, and return marked number.
9794 If optional argument UNMARK is positive, remove any kinds of marks.
9795 If optional argument UNMARK is negative, mark articles as unread instead."
9796   (let ((count 1))
9797     (save-excursion
9798       (cond
9799        ((null unmark)                   ; Mark as read.
9800         (while (and
9801                 (progn
9802                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9803                   (gnus-summary-show-thread) t)
9804                 (gnus-summary-find-subject subject))
9805           (setq count (1+ count))))
9806        ((> unmark 0)                    ; Tick.
9807         (while (and
9808                 (progn
9809                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9810                   (gnus-summary-show-thread) t)
9811                 (gnus-summary-find-subject subject))
9812           (setq count (1+ count))))
9813        (t                               ; Mark as unread.
9814         (while (and
9815                 (progn
9816                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9817                   (gnus-summary-show-thread) t)
9818                 (gnus-summary-find-subject subject))
9819           (setq count (1+ count)))))
9820       (gnus-set-mode-line 'summary)
9821       ;; Return the number of marked articles.
9822       count)))
9823
9824 (defun gnus-summary-mark-as-processable (n &optional unmark)
9825   "Set the process mark on the next N articles.
9826 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9827 the process mark instead.  The difference between N and the actual
9828 number of articles marked is returned."
9829   (interactive "P")
9830   (if (and (null n) (gnus-region-active-p))
9831       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9832     (setq n (prefix-numeric-value n))
9833     (let ((backward (< n 0))
9834           (n (abs n)))
9835       (while (and
9836               (> n 0)
9837               (if unmark
9838                   (gnus-summary-remove-process-mark
9839                    (gnus-summary-article-number))
9840                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9841               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9842         (setq n (1- n)))
9843       (when (/= 0 n)
9844         (gnus-message 7 "No more articles"))
9845       (gnus-summary-recenter)
9846       (gnus-summary-position-point)
9847       n)))
9848
9849 (defun gnus-summary-unmark-as-processable (n)
9850   "Remove the process mark from the next N articles.
9851 If N is negative, unmark backward instead.  The difference between N and
9852 the actual number of articles unmarked is returned."
9853   (interactive "P")
9854   (gnus-summary-mark-as-processable n t))
9855
9856 (defun gnus-summary-unmark-all-processable ()
9857   "Remove the process mark from all articles."
9858   (interactive)
9859   (save-excursion
9860     (while gnus-newsgroup-processable
9861       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9862   (gnus-summary-position-point))
9863
9864 (defun gnus-summary-add-mark (article type)
9865   "Mark ARTICLE with a mark of TYPE."
9866   (let ((vtype (car (assq type gnus-article-mark-lists)))
9867         var)
9868     (if (not vtype)
9869         (error "No such mark type: %s" type)
9870       (setq var (intern (format "gnus-newsgroup-%s" type)))
9871       (set var (cons article (symbol-value var)))
9872       (if (memq type '(processable cached replied forwarded recent saved))
9873           (gnus-summary-update-secondary-mark article)
9874         ;;; !!! This is bogus.  We should find out what primary
9875         ;;; !!! mark we want to set.
9876         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9877
9878 (defun gnus-summary-mark-as-expirable (n)
9879   "Mark N articles forward as expirable.
9880 If N is negative, mark backward instead.  The difference between N and
9881 the actual number of articles marked is returned."
9882   (interactive "p")
9883   (gnus-summary-mark-forward n gnus-expirable-mark))
9884
9885 (defun gnus-summary-mark-as-spam (n)
9886   "Mark N articles forward as spam.
9887 If N is negative, mark backward instead.  The difference between N and
9888 the actual number of articles marked is returned."
9889   (interactive "p")
9890   (gnus-summary-mark-forward n gnus-spam-mark))
9891
9892 (defun gnus-summary-mark-article-as-replied (article)
9893   "Mark ARTICLE as replied to and update the summary line.
9894 ARTICLE can also be a list of articles."
9895   (interactive (list (gnus-summary-article-number)))
9896   (let ((articles (if (listp article) article (list article))))
9897     (dolist (article articles)
9898       (unless (numberp article)
9899         (error "%s is not a number" article))
9900       (push article gnus-newsgroup-replied)
9901       (let ((buffer-read-only nil))
9902         (when (gnus-summary-goto-subject article nil t)
9903           (gnus-summary-update-secondary-mark article))))))
9904
9905 (defun gnus-summary-mark-article-as-forwarded (article)
9906   "Mark ARTICLE as forwarded and update the summary line.
9907 ARTICLE can also be a list of articles."
9908   (let ((articles (if (listp article) article (list article))))
9909     (dolist (article articles)
9910       (push article gnus-newsgroup-forwarded)
9911       (let ((buffer-read-only nil))
9912         (when (gnus-summary-goto-subject article nil t)
9913           (gnus-summary-update-secondary-mark article))))))
9914
9915 (defun gnus-summary-set-bookmark (article)
9916   "Set a bookmark in current article."
9917   (interactive (list (gnus-summary-article-number)))
9918   (when (or (not (get-buffer gnus-article-buffer))
9919             (not gnus-current-article)
9920             (not gnus-article-current)
9921             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9922     (error "No current article selected"))
9923   ;; Remove old bookmark, if one exists.
9924   (gnus-pull article gnus-newsgroup-bookmarks)
9925   ;; Set the new bookmark, which is on the form
9926   ;; (article-number . line-number-in-body).
9927   (push
9928    (cons article
9929          (with-current-buffer gnus-article-buffer
9930            (count-lines
9931             (min (point)
9932                  (save-excursion
9933                    (article-goto-body)
9934                    (point)))
9935             (point))))
9936    gnus-newsgroup-bookmarks)
9937   (gnus-message 6 "A bookmark has been added to the current article."))
9938
9939 (defun gnus-summary-remove-bookmark (article)
9940   "Remove the bookmark from the current article."
9941   (interactive (list (gnus-summary-article-number)))
9942   ;; Remove old bookmark, if one exists.
9943   (if (not (assq article gnus-newsgroup-bookmarks))
9944       (gnus-message 6 "No bookmark in current article.")
9945     (gnus-pull article gnus-newsgroup-bookmarks)
9946     (gnus-message 6 "Removed bookmark.")))
9947
9948 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9949 (defun gnus-summary-mark-as-dormant (n)
9950   "Mark N articles forward as dormant.
9951 If N is negative, mark backward instead.  The difference between N and
9952 the actual number of articles marked is returned."
9953   (interactive "p")
9954   (gnus-summary-mark-forward n gnus-dormant-mark))
9955
9956 (defun gnus-summary-set-process-mark (article)
9957   "Set the process mark on ARTICLE and update the summary line."
9958   (setq gnus-newsgroup-processable
9959         (cons article
9960               (delq article gnus-newsgroup-processable)))
9961   (when (gnus-summary-goto-subject article)
9962     (gnus-summary-show-thread)
9963     (gnus-summary-goto-subject article)
9964     (gnus-summary-update-secondary-mark article)))
9965
9966 (defun gnus-summary-remove-process-mark (article)
9967   "Remove the process mark from ARTICLE and update the summary line."
9968   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9969   (when (gnus-summary-goto-subject article)
9970     (gnus-summary-show-thread)
9971     (gnus-summary-goto-subject article)
9972     (gnus-summary-update-secondary-mark article)))
9973
9974 (defun gnus-summary-set-saved-mark (article)
9975   "Set the process mark on ARTICLE and update the summary line."
9976   (push article gnus-newsgroup-saved)
9977   (when (gnus-summary-goto-subject article)
9978     (gnus-summary-update-secondary-mark article)))
9979
9980 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9981   "Mark N articles as read forwards.
9982 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9983 The difference between N and the actual number of articles marked is
9984 returned.
9985 If NO-EXPIRE, auto-expiry will be inhibited."
9986   (interactive "p")
9987   (gnus-summary-show-thread)
9988   (let ((backward (< n 0))
9989         (gnus-summary-goto-unread
9990          (and gnus-summary-goto-unread
9991               (not (eq gnus-summary-goto-unread 'never))
9992               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9993                                     gnus-ticked-mark gnus-dormant-mark)))))
9994         (n (abs n))
9995         (mark (or mark gnus-del-mark)))
9996     (while (and (> n 0)
9997                 (gnus-summary-mark-article nil mark no-expire)
9998                 (zerop (gnus-summary-next-subject
9999                         (if backward -1 1)
10000                         (and gnus-summary-goto-unread
10001                              (not (eq gnus-summary-goto-unread 'never)))
10002                         t)))
10003       (setq n (1- n)))
10004     (when (/= 0 n)
10005       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10006     (gnus-summary-recenter)
10007     (gnus-summary-position-point)
10008     (gnus-set-mode-line 'summary)
10009     n))
10010
10011 (defun gnus-summary-mark-article-as-read (mark)
10012   "Mark the current article quickly as read with MARK."
10013   (let ((article (gnus-summary-article-number)))
10014     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10015     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10016     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10017     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10018     (push (cons article mark) gnus-newsgroup-reads)
10019     ;; Possibly remove from cache, if that is used.
10020     (when gnus-use-cache
10021       (gnus-cache-enter-remove-article article))
10022     ;; Allow the backend to change the mark.
10023     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10024     ;; Check for auto-expiry.
10025     (when (and gnus-newsgroup-auto-expire
10026                (memq mark gnus-auto-expirable-marks))
10027       (setq mark gnus-expirable-mark)
10028       ;; Let the backend know about the mark change.
10029       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10030       (push article gnus-newsgroup-expirable))
10031     ;; Set the mark in the buffer.
10032     (gnus-summary-update-mark mark 'unread)
10033     t))
10034
10035 (defun gnus-summary-mark-article-as-unread (mark)
10036   "Mark the current article quickly as unread with MARK."
10037   (let* ((article (gnus-summary-article-number))
10038          (old-mark (gnus-summary-article-mark article)))
10039     ;; Allow the backend to change the mark.
10040     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10041     (if (eq mark old-mark)
10042         t
10043       (if (<= article 0)
10044           (progn
10045             (gnus-error 1 "Can't mark negative article numbers")
10046             nil)
10047         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10048         (setq gnus-newsgroup-spam-marked
10049               (delq article gnus-newsgroup-spam-marked))
10050         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10051         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10052         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10053         (cond ((= mark gnus-ticked-mark)
10054                (setq gnus-newsgroup-marked
10055                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10056                                               article)))
10057               ((= mark gnus-spam-mark)
10058                (setq gnus-newsgroup-spam-marked
10059                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10060                                               article)))
10061               ((= mark gnus-dormant-mark)
10062                (setq gnus-newsgroup-dormant
10063                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10064                                               article)))
10065               (t
10066                (setq gnus-newsgroup-unreads
10067                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10068                                               article))))
10069         (gnus-pull article gnus-newsgroup-reads)
10070
10071         ;; See whether the article is to be put in the cache.
10072         (and gnus-use-cache
10073              (vectorp (gnus-summary-article-header article))
10074              (save-excursion
10075                (gnus-cache-possibly-enter-article
10076                 gnus-newsgroup-name article
10077                 (= mark gnus-ticked-mark)
10078                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10079
10080         ;; Fix the mark.
10081         (gnus-summary-update-mark mark 'unread)
10082         t))))
10083
10084 (defun gnus-summary-mark-article (&optional article mark no-expire)
10085   "Mark ARTICLE with MARK.  MARK can be any character.
10086 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10087 `??' (dormant) and `?E' (expirable).
10088 If MARK is nil, then the default character `?r' is used.
10089 If ARTICLE is nil, then the article on the current line will be
10090 marked.
10091 If NO-EXPIRE, auto-expiry will be inhibited."
10092   ;; The mark might be a string.
10093   (when (stringp mark)
10094     (setq mark (aref mark 0)))
10095   ;; If no mark is given, then we check auto-expiring.
10096   (when (null mark)
10097     (setq mark gnus-del-mark))
10098   (when (and (not no-expire)
10099              gnus-newsgroup-auto-expire
10100              (memq mark gnus-auto-expirable-marks))
10101     (setq mark gnus-expirable-mark))
10102   (let ((article (or article (gnus-summary-article-number)))
10103         (old-mark (gnus-summary-article-mark article)))
10104     ;; Allow the backend to change the mark.
10105     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10106     (if (eq mark old-mark)
10107         t
10108       (unless article
10109         (error "No article on current line"))
10110       (if (not (if (or (= mark gnus-unread-mark)
10111                        (= mark gnus-ticked-mark)
10112                        (= mark gnus-spam-mark)
10113                        (= mark gnus-dormant-mark))
10114                    (gnus-mark-article-as-unread article mark)
10115                  (gnus-mark-article-as-read article mark)))
10116           t
10117         ;; See whether the article is to be put in the cache.
10118         (and gnus-use-cache
10119              (not (= mark gnus-canceled-mark))
10120              (vectorp (gnus-summary-article-header article))
10121              (save-excursion
10122                (gnus-cache-possibly-enter-article
10123                 gnus-newsgroup-name article
10124                 (= mark gnus-ticked-mark)
10125                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10126
10127         (when (gnus-summary-goto-subject article nil t)
10128           (let ((buffer-read-only nil))
10129             (gnus-summary-show-thread)
10130             ;; Fix the mark.
10131             (gnus-summary-update-mark mark 'unread)
10132             t))))))
10133
10134 (defun gnus-summary-update-secondary-mark (article)
10135   "Update the secondary (read, process, cache) mark."
10136   (gnus-summary-update-mark
10137    (cond ((memq article gnus-newsgroup-processable)
10138           gnus-process-mark)
10139          ((memq article gnus-newsgroup-cached)
10140           gnus-cached-mark)
10141          ((memq article gnus-newsgroup-replied)
10142           gnus-replied-mark)
10143          ((memq article gnus-newsgroup-forwarded)
10144           gnus-forwarded-mark)
10145          ((memq article gnus-newsgroup-saved)
10146           gnus-saved-mark)
10147          ((memq article gnus-newsgroup-recent)
10148           gnus-recent-mark)
10149          ((memq article gnus-newsgroup-unseen)
10150           gnus-unseen-mark)
10151          (t gnus-no-mark))
10152    'replied)
10153   (when (gnus-visual-p 'summary-highlight 'highlight)
10154     (gnus-run-hooks 'gnus-summary-update-hook))
10155   t)
10156
10157 (defun gnus-summary-update-download-mark (article)
10158   "Update the download mark."
10159   (gnus-summary-update-mark
10160    (cond ((memq article gnus-newsgroup-undownloaded)
10161           gnus-undownloaded-mark)
10162          (gnus-newsgroup-agentized
10163           gnus-downloaded-mark)
10164          (t
10165           gnus-no-mark))
10166    'download)
10167   (gnus-summary-update-line t)
10168   t)
10169
10170 (defun gnus-summary-update-mark (mark type)
10171   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10172         (buffer-read-only nil))
10173     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10174     (when forward
10175       (when (looking-at "\r")
10176         (incf forward))
10177       (when (<= (+ forward (point)) (point-max))
10178         ;; Go to the right position on the line.
10179         (goto-char (+ forward (point)))
10180         ;; Replace the old mark with the new mark.
10181         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10182         ;; Optionally update the marks by some user rule.
10183         (when (eq type 'unread)
10184           (gnus-data-set-mark
10185            (gnus-data-find (gnus-summary-article-number)) mark)
10186           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10187
10188 (defun gnus-mark-article-as-read (article &optional mark)
10189   "Enter ARTICLE in the pertinent lists and remove it from others."
10190   ;; Make the article expirable.
10191   (let ((mark (or mark gnus-del-mark)))
10192     (setq gnus-newsgroup-expirable
10193           (if (= mark gnus-expirable-mark)
10194               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10195             (delq article gnus-newsgroup-expirable)))
10196     ;; Remove from unread and marked lists.
10197     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10198     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10199     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10200     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10201     (push (cons article mark) gnus-newsgroup-reads)
10202     ;; Possibly remove from cache, if that is used.
10203     (when gnus-use-cache
10204       (gnus-cache-enter-remove-article article))
10205     t))
10206
10207 (defun gnus-mark-article-as-unread (article &optional mark)
10208   "Enter ARTICLE in the pertinent lists and remove it from others."
10209   (let ((mark (or mark gnus-ticked-mark)))
10210     (if (<= article 0)
10211         (progn
10212           (gnus-error 1 "Can't mark negative article numbers")
10213           nil)
10214       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10215             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10216             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10217             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10218             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10219
10220       ;; Unsuppress duplicates?
10221       (when gnus-suppress-duplicates
10222         (gnus-dup-unsuppress-article article))
10223
10224       (cond ((= mark gnus-ticked-mark)
10225              (setq gnus-newsgroup-marked
10226                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10227             ((= mark gnus-spam-mark)
10228              (setq gnus-newsgroup-spam-marked
10229                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10230                                             article)))
10231             ((= mark gnus-dormant-mark)
10232              (setq gnus-newsgroup-dormant
10233                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10234             (t
10235              (setq gnus-newsgroup-unreads
10236                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10237       (gnus-pull article gnus-newsgroup-reads)
10238       t)))
10239
10240 (defalias 'gnus-summary-mark-as-unread-forward
10241   'gnus-summary-tick-article-forward)
10242 (make-obsolete 'gnus-summary-mark-as-unread-forward
10243                'gnus-summary-tick-article-forward)
10244 (defun gnus-summary-tick-article-forward (n)
10245   "Tick N articles forwards.
10246 If N is negative, tick backwards instead.
10247 The difference between N and the number of articles ticked is returned."
10248   (interactive "p")
10249   (gnus-summary-mark-forward n gnus-ticked-mark))
10250
10251 (defalias 'gnus-summary-mark-as-unread-backward
10252   'gnus-summary-tick-article-backward)
10253 (make-obsolete 'gnus-summary-mark-as-unread-backward
10254                'gnus-summary-tick-article-backward)
10255 (defun gnus-summary-tick-article-backward (n)
10256   "Tick N articles backwards.
10257 The difference between N and the number of articles ticked is returned."
10258   (interactive "p")
10259   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10260
10261 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10262 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10263 (defun gnus-summary-tick-article (&optional article clear-mark)
10264   "Mark current article as unread.
10265 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10266 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10267   (interactive)
10268   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10269                                        gnus-ticked-mark)))
10270
10271 (defun gnus-summary-mark-as-read-forward (n)
10272   "Mark N articles as read forwards.
10273 If N is negative, mark backwards instead.
10274 The difference between N and the actual number of articles marked is
10275 returned."
10276   (interactive "p")
10277   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10278
10279 (defun gnus-summary-mark-as-read-backward (n)
10280   "Mark the N articles as read backwards.
10281 The difference between N and the actual number of articles marked is
10282 returned."
10283   (interactive "p")
10284   (gnus-summary-mark-forward
10285    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10286
10287 (defun gnus-summary-mark-as-read (&optional article mark)
10288   "Mark current article as read.
10289 ARTICLE specifies the article to be marked as read.
10290 MARK specifies a string to be inserted at the beginning of the line."
10291   (gnus-summary-mark-article article mark))
10292
10293 (defun gnus-summary-clear-mark-forward (n)
10294   "Clear marks from N articles forward.
10295 If N is negative, clear backward instead.
10296 The difference between N and the number of marks cleared is returned."
10297   (interactive "p")
10298   (gnus-summary-mark-forward n gnus-unread-mark))
10299
10300 (defun gnus-summary-clear-mark-backward (n)
10301   "Clear marks from N articles backward.
10302 The difference between N and the number of marks cleared is returned."
10303   (interactive "p")
10304   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10305
10306 (defun gnus-summary-mark-unread-as-read ()
10307   "Intended to be used by `gnus-summary-mark-article-hook'."
10308   (when (memq gnus-current-article gnus-newsgroup-unreads)
10309     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10310
10311 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10312   "Intended to be used by `gnus-summary-mark-article-hook'."
10313   (let ((mark (gnus-summary-article-mark)))
10314     (when (or (gnus-unread-mark-p mark)
10315               (gnus-read-mark-p mark))
10316       (gnus-summary-mark-article gnus-current-article
10317                                  (or new-mark gnus-read-mark)))))
10318
10319 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10320   "Intended to be used by `gnus-summary-mark-article-hook'."
10321   (let ((mark (gnus-summary-article-mark)))
10322     (when (or (gnus-unread-mark-p mark)
10323               (gnus-read-mark-p mark))
10324       (gnus-summary-mark-article (gnus-summary-article-number)
10325                                  (or new-mark gnus-read-mark)))))
10326
10327 (defun gnus-summary-mark-unread-as-ticked ()
10328   "Intended to be used by `gnus-summary-mark-article-hook'."
10329   (when (memq gnus-current-article gnus-newsgroup-unreads)
10330     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10331
10332 (defun gnus-summary-mark-region-as-read (point mark all)
10333   "Mark all unread articles between point and mark as read.
10334 If given a prefix, mark all articles between point and mark as read,
10335 even ticked and dormant ones."
10336   (interactive "r\nP")
10337   (save-excursion
10338     (let (article)
10339       (goto-char point)
10340       (beginning-of-line)
10341       (while (and
10342               (< (point) mark)
10343               (progn
10344                 (when (or all
10345                           (memq (setq article (gnus-summary-article-number))
10346                                 gnus-newsgroup-unreads))
10347                   (gnus-summary-mark-article article gnus-del-mark))
10348                 t)
10349               (gnus-summary-find-next))))))
10350
10351 (defun gnus-summary-mark-below (score mark)
10352   "Mark articles with score less than SCORE with MARK."
10353   (interactive "P\ncMark: ")
10354   (setq score (if score
10355                   (prefix-numeric-value score)
10356                 (or gnus-summary-default-score 0)))
10357   (save-excursion
10358     (set-buffer gnus-summary-buffer)
10359     (goto-char (point-min))
10360     (while
10361         (progn
10362           (and (< (gnus-summary-article-score) score)
10363                (gnus-summary-mark-article nil mark))
10364           (gnus-summary-find-next)))))
10365
10366 (defun gnus-summary-kill-below (&optional score)
10367   "Mark articles with score below SCORE as read."
10368   (interactive "P")
10369   (gnus-summary-mark-below score gnus-killed-mark))
10370
10371 (defun gnus-summary-clear-above (&optional score)
10372   "Clear all marks from articles with score above SCORE."
10373   (interactive "P")
10374   (gnus-summary-mark-above score gnus-unread-mark))
10375
10376 (defun gnus-summary-tick-above (&optional score)
10377   "Tick all articles with score above SCORE."
10378   (interactive "P")
10379   (gnus-summary-mark-above score gnus-ticked-mark))
10380
10381 (defun gnus-summary-mark-above (score mark)
10382   "Mark articles with score over SCORE with MARK."
10383   (interactive "P\ncMark: ")
10384   (setq score (if score
10385                   (prefix-numeric-value score)
10386                 (or gnus-summary-default-score 0)))
10387   (save-excursion
10388     (set-buffer gnus-summary-buffer)
10389     (goto-char (point-min))
10390     (while (and (progn
10391                   (when (> (gnus-summary-article-score) score)
10392                     (gnus-summary-mark-article nil mark))
10393                   t)
10394                 (gnus-summary-find-next)))))
10395
10396 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10397 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10398 (defun gnus-summary-limit-include-expunged (&optional no-error)
10399   "Display all the hidden articles that were expunged for low scores."
10400   (interactive)
10401   (let ((buffer-read-only nil))
10402     (let ((scored gnus-newsgroup-scored)
10403           headers h)
10404       (while scored
10405         (unless (gnus-summary-article-header (caar scored))
10406           (and (setq h (gnus-number-to-header (caar scored)))
10407                (< (cdar scored) gnus-summary-expunge-below)
10408                (push h headers)))
10409         (setq scored (cdr scored)))
10410       (if (not headers)
10411           (when (not no-error)
10412             (error "No expunged articles hidden"))
10413         (goto-char (point-min))
10414         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10415         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10416         (mapcar (lambda (x) (push (mail-header-number x)
10417                                   gnus-newsgroup-limit))
10418                 headers)
10419         (gnus-summary-prepare-unthreaded (nreverse headers))
10420         (goto-char (point-min))
10421         (gnus-summary-position-point)
10422         t))))
10423
10424 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10425   "Mark all unread articles in this newsgroup as read.
10426 If prefix argument ALL is non-nil, ticked and dormant articles will
10427 also be marked as read.
10428 If QUIETLY is non-nil, no questions will be asked.
10429
10430 If TO-HERE is non-nil, it should be a point in the buffer.  All
10431 articles before (after, if REVERSE is set) this point will be marked
10432 as read.
10433
10434 Note that this function will only catch up the unread article
10435 in the current summary buffer limitation.
10436
10437 The number of articles marked as read is returned."
10438   (interactive "P")
10439   (prog1
10440       (save-excursion
10441         (when (or quietly
10442                   (not gnus-interactive-catchup) ;Without confirmation?
10443                   gnus-expert-user
10444                   (gnus-y-or-n-p
10445                    (if all
10446                        "Mark absolutely all articles as read? "
10447                      "Mark all unread articles as read? ")))
10448           (if (and not-mark
10449                    (not gnus-newsgroup-adaptive)
10450                    (not gnus-newsgroup-auto-expire)
10451                    (not gnus-suppress-duplicates)
10452                    (or (not gnus-use-cache)
10453                        (eq gnus-use-cache 'passive)))
10454               (progn
10455                 (when all
10456                   (setq gnus-newsgroup-marked nil
10457                         gnus-newsgroup-spam-marked nil
10458                         gnus-newsgroup-dormant nil))
10459                 (setq gnus-newsgroup-unreads
10460                       (gnus-sorted-nunion
10461                        (gnus-intersection gnus-newsgroup-unreads
10462                                           gnus-newsgroup-downloadable)
10463                        gnus-newsgroup-unfetched)))
10464             ;; We actually mark all articles as canceled, which we
10465             ;; have to do when using auto-expiry or adaptive scoring.
10466             (gnus-summary-show-all-threads)
10467             (if (and to-here reverse)
10468                 (progn
10469                   (goto-char to-here)
10470                   (gnus-summary-mark-current-read-and-unread-as-read
10471                    gnus-catchup-mark)
10472                   (while (gnus-summary-find-next (not all))
10473                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10474               (when (gnus-summary-first-subject (not all))
10475                 (while (and
10476                         (if to-here (< (point) to-here) t)
10477                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10478                         (gnus-summary-find-next (not all))))))
10479             (gnus-set-mode-line 'summary))
10480           t))
10481     (gnus-summary-position-point)))
10482
10483 (defun gnus-summary-catchup-to-here (&optional all)
10484   "Mark all unticked articles before the current one as read.
10485 If ALL is non-nil, also mark ticked and dormant articles as read."
10486   (interactive "P")
10487   (save-excursion
10488     (gnus-save-hidden-threads
10489       (let ((beg (point)))
10490         ;; We check that there are unread articles.
10491         (when (or all (gnus-summary-find-prev))
10492           (gnus-summary-catchup all t beg)))))
10493   (gnus-summary-position-point))
10494
10495 (defun gnus-summary-catchup-from-here (&optional all)
10496   "Mark all unticked articles after (and including) the current one as read.
10497 If ALL is non-nil, also mark ticked and dormant articles as read."
10498   (interactive "P")
10499   (save-excursion
10500     (gnus-save-hidden-threads
10501       (let ((beg (point)))
10502         ;; We check that there are unread articles.
10503         (when (or all (gnus-summary-find-next))
10504           (gnus-summary-catchup all t beg nil t)))))
10505   (gnus-summary-position-point))
10506
10507 (defun gnus-summary-catchup-all (&optional quietly)
10508   "Mark all articles in this newsgroup as read.
10509 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10510 instead, which marks only unread articles as read."
10511   (interactive "P")
10512   (gnus-summary-catchup t quietly))
10513
10514 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10515   "Mark all unread articles in this group as read, then exit.
10516 If prefix argument ALL is non-nil, all articles are marked as read.
10517 If QUIETLY is non-nil, no questions will be asked."
10518   (interactive "P")
10519   (when (gnus-summary-catchup all quietly nil 'fast)
10520     ;; Select next newsgroup or exit.
10521     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10522              (eq gnus-auto-select-next 'quietly))
10523         (gnus-summary-next-group nil)
10524       (gnus-summary-exit))))
10525
10526 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10527   "Mark all articles in this newsgroup as read, and then exit.
10528 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10529 instead, which marks only unread articles as read."
10530   (interactive "P")
10531   (gnus-summary-catchup-and-exit t quietly))
10532
10533 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10534   "Mark all articles in this group as read and select the next group.
10535 If given a prefix, mark all articles, unread as well as ticked, as
10536 read."
10537   (interactive "P")
10538   (save-excursion
10539     (gnus-summary-catchup all))
10540   (gnus-summary-next-group))
10541
10542 ;;;
10543 ;;; with article
10544 ;;;
10545
10546 (defmacro gnus-with-article (article &rest forms)
10547   "Select ARTICLE and perform FORMS in the original article buffer.
10548 Then replace the article with the result."
10549   `(progn
10550      ;; We don't want the article to be marked as read.
10551      (let (gnus-mark-article-hook)
10552        (gnus-summary-select-article t t nil ,article))
10553      (set-buffer gnus-original-article-buffer)
10554      ,@forms
10555      (if (not (gnus-check-backend-function
10556                'request-replace-article (car gnus-article-current)))
10557          (gnus-message 5 "Read-only group; not replacing")
10558        (unless (gnus-request-replace-article
10559                 ,article (car gnus-article-current)
10560                 (current-buffer) t)
10561          (error "Couldn't replace article")))
10562      ;; The cache and backlog have to be flushed somewhat.
10563      (when gnus-keep-backlog
10564        (gnus-backlog-remove-article
10565         (car gnus-article-current) (cdr gnus-article-current)))
10566      (when gnus-use-cache
10567        (gnus-cache-update-article
10568         (car gnus-article-current) (cdr gnus-article-current)))))
10569
10570 (put 'gnus-with-article 'lisp-indent-function 1)
10571 (put 'gnus-with-article 'edebug-form-spec '(form body))
10572
10573 ;; Thread-based commands.
10574
10575 (defun gnus-summary-articles-in-thread (&optional article)
10576   "Return a list of all articles in the current thread.
10577 If ARTICLE is non-nil, return all articles in the thread that starts
10578 with that article."
10579   (let* ((article (or article (gnus-summary-article-number)))
10580          (data (gnus-data-find-list article))
10581          (top-level (gnus-data-level (car data)))
10582          (top-subject
10583           (cond ((null gnus-thread-operation-ignore-subject)
10584                  (gnus-simplify-subject-re
10585                   (mail-header-subject (gnus-data-header (car data)))))
10586                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10587                  (gnus-simplify-subject-fuzzy
10588                   (mail-header-subject (gnus-data-header (car data)))))
10589                 (t nil)))
10590          (end-point (save-excursion
10591                       (if (gnus-summary-go-to-next-thread)
10592                           (point) (point-max))))
10593          articles)
10594     (while (and data
10595                 (< (gnus-data-pos (car data)) end-point))
10596       (when (or (not top-subject)
10597                 (string= top-subject
10598                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10599                              (gnus-simplify-subject-fuzzy
10600                               (mail-header-subject
10601                                (gnus-data-header (car data))))
10602                            (gnus-simplify-subject-re
10603                             (mail-header-subject
10604                              (gnus-data-header (car data)))))))
10605         (push (gnus-data-number (car data)) articles))
10606       (unless (and (setq data (cdr data))
10607                    (> (gnus-data-level (car data)) top-level))
10608         (setq data nil)))
10609     ;; Return the list of articles.
10610     (nreverse articles)))
10611
10612 (defun gnus-summary-rethread-current ()
10613   "Rethread the thread the current article is part of."
10614   (interactive)
10615   (let* ((gnus-show-threads t)
10616          (article (gnus-summary-article-number))
10617          (id (mail-header-id (gnus-summary-article-header)))
10618          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10619     (unless id
10620       (error "No article on the current line"))
10621     (gnus-rebuild-thread id)
10622     (gnus-summary-goto-subject article)))
10623
10624 (defun gnus-summary-reparent-thread ()
10625   "Make the current article child of the marked (or previous) article.
10626
10627 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10628 is non-nil or the Subject: of both articles are the same."
10629   (interactive)
10630   (unless (not (gnus-group-read-only-p))
10631     (error "The current newsgroup does not support article editing"))
10632   (unless (<= (length gnus-newsgroup-processable) 1)
10633     (error "No more than one article may be marked"))
10634   (save-window-excursion
10635     (let ((gnus-article-buffer " *reparent*")
10636           (current-article (gnus-summary-article-number))
10637           ;; First grab the marked article, otherwise one line up.
10638           (parent-article (if (not (null gnus-newsgroup-processable))
10639                               (car gnus-newsgroup-processable)
10640                             (save-excursion
10641                               (if (eq (forward-line -1) 0)
10642                                   (gnus-summary-article-number)
10643                                 (error "Beginning of summary buffer"))))))
10644       (unless (not (eq current-article parent-article))
10645         (error "An article may not be self-referential"))
10646       (let ((message-id (mail-header-id
10647                          (gnus-summary-article-header parent-article))))
10648         (unless (and message-id (not (equal message-id "")))
10649           (error "No message-id in desired parent"))
10650         (gnus-with-article current-article
10651           (save-restriction
10652             (goto-char (point-min))
10653             (message-narrow-to-head)
10654             (if (re-search-forward "^References: " nil t)
10655                 (progn
10656                   (re-search-forward "^[^ \t]" nil t)
10657                   (forward-line -1)
10658                   (end-of-line)
10659                   (insert " " message-id))
10660               (insert "References: " message-id "\n"))))
10661         (set-buffer gnus-summary-buffer)
10662         (gnus-summary-unmark-all-processable)
10663         (gnus-summary-update-article current-article)
10664         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10665             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10666         (gnus-summary-rethread-current)
10667         (gnus-message 3 "Article %d is now the child of article %d"
10668                       current-article parent-article)))))
10669
10670 (defun gnus-summary-toggle-threads (&optional arg)
10671   "Toggle showing conversation threads.
10672 If ARG is positive number, turn showing conversation threads on."
10673   (interactive "P")
10674   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10675     (setq gnus-show-threads
10676           (if (null arg) (not gnus-show-threads)
10677             (> (prefix-numeric-value arg) 0)))
10678     (gnus-summary-prepare)
10679     (gnus-summary-goto-subject current)
10680     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10681     (gnus-summary-position-point)))
10682
10683 (defun gnus-summary-show-all-threads ()
10684   "Show all threads."
10685   (interactive)
10686   (save-excursion
10687     (let ((buffer-read-only nil))
10688       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10689   (gnus-summary-position-point))
10690
10691 (defun gnus-summary-show-thread ()
10692   "Show thread subtrees.
10693 Returns nil if no thread was there to be shown."
10694   (interactive)
10695   (let ((buffer-read-only nil)
10696         (orig (point))
10697         (end (point-at-eol))
10698         ;; Leave point at bol
10699         (beg (progn (beginning-of-line) (point))))
10700     (prog1
10701         ;; Any hidden lines here?
10702         (search-forward "\r" end t)
10703       (subst-char-in-region beg end ?\^M ?\n t)
10704       (goto-char orig)
10705       (gnus-summary-position-point))))
10706
10707 (defun gnus-summary-maybe-hide-threads ()
10708   "If requested, hide the threads that should be hidden."
10709   (when (and gnus-show-threads
10710              gnus-thread-hide-subtree)
10711     (gnus-summary-hide-all-threads
10712      (if (or (consp gnus-thread-hide-subtree)
10713              (functionp gnus-thread-hide-subtree))
10714          (gnus-make-predicate gnus-thread-hide-subtree)
10715        nil))))
10716
10717 ;;; Hiding predicates.
10718
10719 (defun gnus-article-unread-p (header)
10720   (memq (mail-header-number header) gnus-newsgroup-unreads))
10721
10722 (defun gnus-article-unseen-p (header)
10723   (memq (mail-header-number header) gnus-newsgroup-unseen))
10724
10725 (defun gnus-map-articles (predicate articles)
10726   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10727   (apply 'gnus-or (mapcar predicate
10728                           (mapcar 'gnus-summary-article-header articles))))
10729
10730 (defun gnus-summary-hide-all-threads (&optional predicate)
10731   "Hide all thread subtrees.
10732 If PREDICATE is supplied, threads that satisfy this predicate
10733 will not be hidden."
10734   (interactive)
10735   (save-excursion
10736     (goto-char (point-min))
10737     (let ((end nil))
10738       (while (not end)
10739         (when (or (not predicate)
10740                   (gnus-map-articles
10741                    predicate (gnus-summary-article-children)))
10742             (gnus-summary-hide-thread))
10743         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10744   (gnus-summary-position-point))
10745
10746 (defun gnus-summary-hide-thread ()
10747   "Hide thread subtrees.
10748 If PREDICATE is supplied, threads that satisfy this predicate
10749 will not be hidden.
10750 Returns nil if no threads were there to be hidden."
10751   (interactive)
10752   (let ((buffer-read-only nil)
10753         (start (point))
10754         (article (gnus-summary-article-number)))
10755     (goto-char start)
10756     ;; Go forward until either the buffer ends or the subthread
10757     ;; ends.
10758     (when (and (not (eobp))
10759                (or (zerop (gnus-summary-next-thread 1 t))
10760                    (goto-char (point-max))))
10761       (prog1
10762           (if (and (> (point) start)
10763                    (search-backward "\n" start t))
10764               (progn
10765                 (subst-char-in-region start (point) ?\n ?\^M)
10766                 (gnus-summary-goto-subject article))
10767             (goto-char start)
10768             nil)))))
10769
10770 (defun gnus-summary-go-to-next-thread (&optional previous)
10771   "Go to the same level (or less) next thread.
10772 If PREVIOUS is non-nil, go to previous thread instead.
10773 Return the article number moved to, or nil if moving was impossible."
10774   (let ((level (gnus-summary-thread-level))
10775         (way (if previous -1 1))
10776         (beg (point)))
10777     (forward-line way)
10778     (while (and (not (eobp))
10779                 (< level (gnus-summary-thread-level)))
10780       (forward-line way))
10781     (if (eobp)
10782         (progn
10783           (goto-char beg)
10784           nil)
10785       (setq beg (point))
10786       (prog1
10787           (gnus-summary-article-number)
10788         (goto-char beg)))))
10789
10790 (defun gnus-summary-next-thread (n &optional silent)
10791   "Go to the same level next N'th thread.
10792 If N is negative, search backward instead.
10793 Returns the difference between N and the number of skips actually
10794 done.
10795
10796 If SILENT, don't output messages."
10797   (interactive "p")
10798   (let ((backward (< n 0))
10799         (n (abs n)))
10800     (while (and (> n 0)
10801                 (gnus-summary-go-to-next-thread backward))
10802       (decf n))
10803     (unless silent
10804       (gnus-summary-position-point))
10805     (when (and (not silent) (/= 0 n))
10806       (gnus-message 7 "No more threads"))
10807     n))
10808
10809 (defun gnus-summary-prev-thread (n)
10810   "Go to the same level previous N'th thread.
10811 Returns the difference between N and the number of skips actually
10812 done."
10813   (interactive "p")
10814   (gnus-summary-next-thread (- n)))
10815
10816 (defun gnus-summary-go-down-thread ()
10817   "Go down one level in the current thread."
10818   (let ((children (gnus-summary-article-children)))
10819     (when children
10820       (gnus-summary-goto-subject (car children)))))
10821
10822 (defun gnus-summary-go-up-thread ()
10823   "Go up one level in the current thread."
10824   (let ((parent (gnus-summary-article-parent)))
10825     (when parent
10826       (gnus-summary-goto-subject parent))))
10827
10828 (defun gnus-summary-down-thread (n)
10829   "Go down thread N steps.
10830 If N is negative, go up instead.
10831 Returns the difference between N and how many steps down that were
10832 taken."
10833   (interactive "p")
10834   (let ((up (< n 0))
10835         (n (abs n)))
10836     (while (and (> n 0)
10837                 (if up (gnus-summary-go-up-thread)
10838                   (gnus-summary-go-down-thread)))
10839       (setq n (1- n)))
10840     (gnus-summary-position-point)
10841     (when (/= 0 n)
10842       (gnus-message 7 "Can't go further"))
10843     n))
10844
10845 (defun gnus-summary-up-thread (n)
10846   "Go up thread N steps.
10847 If N is negative, go down instead.
10848 Returns the difference between N and how many steps down that were
10849 taken."
10850   (interactive "p")
10851   (gnus-summary-down-thread (- n)))
10852
10853 (defun gnus-summary-top-thread ()
10854   "Go to the top of the thread."
10855   (interactive)
10856   (while (gnus-summary-go-up-thread))
10857   (gnus-summary-article-number))
10858
10859 (defun gnus-summary-kill-thread (&optional unmark)
10860   "Mark articles under current thread as read.
10861 If the prefix argument is positive, remove any kinds of marks.
10862 If the prefix argument is negative, tick articles instead."
10863   (interactive "P")
10864   (when unmark
10865     (setq unmark (prefix-numeric-value unmark)))
10866   (let ((articles (gnus-summary-articles-in-thread)))
10867     (save-excursion
10868       ;; Expand the thread.
10869       (gnus-summary-show-thread)
10870       ;; Mark all the articles.
10871       (while articles
10872         (gnus-summary-goto-subject (car articles))
10873         (cond ((null unmark)
10874                (gnus-summary-mark-article-as-read gnus-killed-mark))
10875               ((> unmark 0)
10876                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10877               (t
10878                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10879         (setq articles (cdr articles))))
10880     ;; Hide killed subtrees.
10881     (and (null unmark)
10882          gnus-thread-hide-killed
10883          (gnus-summary-hide-thread))
10884     ;; If marked as read, go to next unread subject.
10885     (when (null unmark)
10886       ;; Go to next unread subject.
10887       (gnus-summary-next-subject 1 t)))
10888   (gnus-set-mode-line 'summary))
10889
10890 ;; Summary sorting commands
10891
10892 (defun gnus-summary-sort-by-number (&optional reverse)
10893   "Sort the summary buffer by article number.
10894 Argument REVERSE means reverse order."
10895   (interactive "P")
10896   (gnus-summary-sort 'number reverse))
10897
10898 (defun gnus-summary-sort-by-random (&optional reverse)
10899   "Randomize the order in the summary buffer.
10900 Argument REVERSE means to randomize in reverse order."
10901   (interactive "P")
10902   (gnus-summary-sort 'random reverse))
10903
10904 (defun gnus-summary-sort-by-author (&optional reverse)
10905   "Sort the summary buffer by author name alphabetically.
10906 If `case-fold-search' is non-nil, case of letters is ignored.
10907 Argument REVERSE means reverse order."
10908   (interactive "P")
10909   (gnus-summary-sort 'author reverse))
10910
10911 (defun gnus-summary-sort-by-recipient (&optional reverse)
10912   "Sort the summary buffer by recipient name alphabetically.
10913 If `case-fold-search' is non-nil, case of letters is ignored.
10914 Argument REVERSE means reverse order."
10915   (interactive "P")
10916   (gnus-summary-sort 'recipient reverse))
10917
10918 (defun gnus-summary-sort-by-subject (&optional reverse)
10919   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10920 If `case-fold-search' is non-nil, case of letters is ignored.
10921 Argument REVERSE means reverse order."
10922   (interactive "P")
10923   (gnus-summary-sort 'subject reverse))
10924
10925 (defun gnus-summary-sort-by-date (&optional reverse)
10926   "Sort the summary buffer by date.
10927 Argument REVERSE means reverse order."
10928   (interactive "P")
10929   (gnus-summary-sort 'date reverse))
10930
10931 (defun gnus-summary-sort-by-score (&optional reverse)
10932   "Sort the summary buffer by score.
10933 Argument REVERSE means reverse order."
10934   (interactive "P")
10935   (gnus-summary-sort 'score reverse))
10936
10937 (defun gnus-summary-sort-by-lines (&optional reverse)
10938   "Sort the summary buffer by the number of lines.
10939 Argument REVERSE means reverse order."
10940   (interactive "P")
10941   (gnus-summary-sort 'lines reverse))
10942
10943 (defun gnus-summary-sort-by-chars (&optional reverse)
10944   "Sort the summary buffer by article length.
10945 Argument REVERSE means reverse order."
10946   (interactive "P")
10947   (gnus-summary-sort 'chars reverse))
10948
10949 (defun gnus-summary-sort-by-original (&optional reverse)
10950   "Sort the summary buffer using the default sorting method.
10951 Argument REVERSE means reverse order."
10952   (interactive "P")
10953   (let* ((buffer-read-only)
10954          (gnus-summary-prepare-hook nil))
10955     ;; We do the sorting by regenerating the threads.
10956     (gnus-summary-prepare)
10957     ;; Hide subthreads if needed.
10958     (gnus-summary-maybe-hide-threads)))
10959
10960 (defun gnus-summary-sort (predicate reverse)
10961   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10962   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10963          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10964          (gnus-thread-sort-functions
10965           (if (not reverse)
10966               thread
10967             `(lambda (t1 t2)
10968                (,thread t2 t1))))
10969          (gnus-sort-gathered-threads-function
10970           gnus-thread-sort-functions)
10971          (gnus-article-sort-functions
10972           (if (not reverse)
10973               article
10974             `(lambda (t1 t2)
10975                (,article t2 t1))))
10976          (buffer-read-only)
10977          (gnus-summary-prepare-hook nil))
10978     ;; We do the sorting by regenerating the threads.
10979     (gnus-summary-prepare)
10980     ;; Hide subthreads if needed.
10981     (gnus-summary-maybe-hide-threads)))
10982
10983 ;; Summary saving commands.
10984
10985 (defun gnus-summary-save-article (&optional n not-saved)
10986   "Save the current article using the default saver function.
10987 If N is a positive number, save the N next articles.
10988 If N is a negative number, save the N previous articles.
10989 If N is nil and any articles have been marked with the process mark,
10990 save those articles instead.
10991 The variable `gnus-default-article-saver' specifies the saver function."
10992   (interactive "P")
10993   (let* ((articles (gnus-summary-work-articles n))
10994          (save-buffer (save-excursion
10995                         (nnheader-set-temp-buffer " *Gnus Save*")))
10996          (num (length articles))
10997          header file)
10998     (dolist (article articles)
10999       (setq header (gnus-summary-article-header article))
11000       (if (not (vectorp header))
11001           ;; This is a pseudo-article.
11002           (if (assq 'name header)
11003               (gnus-copy-file (cdr (assq 'name header)))
11004             (gnus-message 1 "Article %d is unsaveable" article))
11005         ;; This is a real article.
11006         (save-window-excursion
11007           (let ((gnus-display-mime-function nil)
11008                 (gnus-article-prepare-hook nil))
11009             (gnus-summary-select-article t nil nil article)))
11010         (save-excursion
11011           (set-buffer save-buffer)
11012           (erase-buffer)
11013           (insert-buffer-substring gnus-original-article-buffer))
11014         (setq file (gnus-article-save save-buffer file num))
11015         (gnus-summary-remove-process-mark article)
11016         (unless not-saved
11017           (gnus-summary-set-saved-mark article))))
11018     (gnus-kill-buffer save-buffer)
11019     (gnus-summary-position-point)
11020     (gnus-set-mode-line 'summary)
11021     n))
11022
11023 (defun gnus-summary-pipe-output (&optional arg headers)
11024   "Pipe the current article to a subprocess.
11025 If N is a positive number, pipe the N next articles.
11026 If N is a negative number, pipe the N previous articles.
11027 If N is nil and any articles have been marked with the process mark,
11028 pipe those articles instead.
11029 If HEADERS (the symbolic prefix), include the headers, too."
11030   (interactive (gnus-interactive "P\ny"))
11031   (require 'gnus-art)
11032   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11033         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11034     (gnus-summary-save-article arg t))
11035   (let ((buffer (get-buffer "*Shell Command Output*")))
11036     (when (and buffer
11037                (not (zerop (buffer-size buffer))))
11038       (gnus-configure-windows 'pipe))))
11039
11040 (defun gnus-summary-save-article-mail (&optional arg)
11041   "Append the current article to an mail file.
11042 If N is a positive number, save the N next articles.
11043 If N is a negative number, save the N previous articles.
11044 If N is nil and any articles have been marked with the process mark,
11045 save those articles instead."
11046   (interactive "P")
11047   (require 'gnus-art)
11048   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11049     (gnus-summary-save-article arg)))
11050
11051 (defun gnus-summary-save-article-rmail (&optional arg)
11052   "Append the current article to an rmail file.
11053 If N is a positive number, save the N next articles.
11054 If N is a negative number, save the N previous articles.
11055 If N is nil and any articles have been marked with the process mark,
11056 save those articles instead."
11057   (interactive "P")
11058   (require 'gnus-art)
11059   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11060     (gnus-summary-save-article arg)))
11061
11062 (defun gnus-summary-save-article-file (&optional arg)
11063   "Append the current article to a file.
11064 If N is a positive number, save the N next articles.
11065 If N is a negative number, save the N previous articles.
11066 If N is nil and any articles have been marked with the process mark,
11067 save those articles instead."
11068   (interactive "P")
11069   (require 'gnus-art)
11070   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11071     (gnus-summary-save-article arg)))
11072
11073 (defun gnus-summary-write-article-file (&optional arg)
11074   "Write the current article to a file, deleting the previous file.
11075 If N is a positive number, save the N next articles.
11076 If N is a negative number, save the N previous articles.
11077 If N is nil and any articles have been marked with the process mark,
11078 save those articles instead."
11079   (interactive "P")
11080   (require 'gnus-art)
11081   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11082     (gnus-summary-save-article arg)))
11083
11084 (defun gnus-summary-save-article-body-file (&optional arg)
11085   "Append the current article body to a file.
11086 If N is a positive number, save the N next articles.
11087 If N is a negative number, save the N previous articles.
11088 If N is nil and any articles have been marked with the process mark,
11089 save those articles instead."
11090   (interactive "P")
11091   (require 'gnus-art)
11092   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11093     (gnus-summary-save-article arg)))
11094
11095 (defun gnus-summary-muttprint (&optional arg)
11096   "Print the current article using Muttprint.
11097 If N is a positive number, save the N next articles.
11098 If N is a negative number, save the N previous articles.
11099 If N is nil and any articles have been marked with the process mark,
11100 save those articles instead."
11101   (interactive "P")
11102   (require 'gnus-art)
11103   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11104     (gnus-summary-save-article arg t)))
11105
11106 (defun gnus-summary-pipe-message (program)
11107   "Pipe the current article through PROGRAM."
11108   (interactive "sProgram: ")
11109   (gnus-summary-select-article)
11110   (let ((mail-header-separator ""))
11111     (gnus-eval-in-buffer-window gnus-article-buffer
11112       (save-restriction
11113         (widen)
11114         (let ((start (window-start))
11115               buffer-read-only)
11116           (message-pipe-buffer-body program)
11117           (set-window-start (get-buffer-window (current-buffer)) start))))))
11118
11119 (defun gnus-get-split-value (methods)
11120   "Return a value based on the split METHODS."
11121   (let (split-name method result match)
11122     (when methods
11123       (save-excursion
11124         (set-buffer gnus-original-article-buffer)
11125         (save-restriction
11126           (nnheader-narrow-to-headers)
11127           (while (and methods (not split-name))
11128             (goto-char (point-min))
11129             (setq method (pop methods))
11130             (setq match (car method))
11131             (when (cond
11132                    ((stringp match)
11133                     ;; Regular expression.
11134                     (ignore-errors
11135                       (re-search-forward match nil t)))
11136                    ((functionp match)
11137                     ;; Function.
11138                     (save-restriction
11139                       (widen)
11140                       (setq result (funcall match gnus-newsgroup-name))))
11141                    ((consp match)
11142                     ;; Form.
11143                     (save-restriction
11144                       (widen)
11145                       (setq result (eval match)))))
11146               (setq split-name (cdr method))
11147               (cond ((stringp result)
11148                      (push (expand-file-name
11149                             result gnus-article-save-directory)
11150                            split-name))
11151                     ((consp result)
11152                      (setq split-name (append result split-name)))))))))
11153     (nreverse split-name)))
11154
11155 (defun gnus-valid-move-group-p (group)
11156   (and (boundp group)
11157        (symbol-name group)
11158        (symbol-value group)
11159        (gnus-get-function (gnus-find-method-for-group
11160                            (symbol-name group)) 'request-accept-article t)))
11161
11162 (defun gnus-read-move-group-name (prompt default articles prefix)
11163   "Read a group name."
11164   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11165          (minibuffer-confirm-incomplete nil) ; XEmacs
11166          (prom
11167           (format "%s %s to:"
11168                   prompt
11169                   (if (> (length articles) 1)
11170                       (format "these %d articles" (length articles))
11171                     "this article")))
11172          (to-newsgroup
11173           (cond
11174            ((null split-name)
11175             (gnus-completing-read-with-default
11176              default prom
11177              gnus-active-hashtb
11178              'gnus-valid-move-group-p
11179              nil prefix
11180              'gnus-group-history))
11181            ((= 1 (length split-name))
11182             (gnus-completing-read-with-default
11183              (car split-name) prom
11184              gnus-active-hashtb
11185              'gnus-valid-move-group-p
11186              nil nil
11187              'gnus-group-history))
11188            (t
11189             (gnus-completing-read-with-default
11190              nil prom
11191              (mapcar 'list (nreverse split-name))
11192              nil nil nil
11193              'gnus-group-history))))
11194          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11195     (when to-newsgroup
11196       (if (or (string= to-newsgroup "")
11197               (string= to-newsgroup prefix))
11198           (setq to-newsgroup default))
11199       (unless to-newsgroup
11200         (error "No group name entered"))
11201       (or (gnus-active to-newsgroup)
11202           (gnus-activate-group to-newsgroup nil nil to-method)
11203           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11204                                      to-newsgroup))
11205               (or (and (gnus-request-create-group to-newsgroup to-method)
11206                        (gnus-activate-group
11207                         to-newsgroup nil nil to-method)
11208                        (gnus-subscribe-group to-newsgroup))
11209                   (error "Couldn't create group %s" to-newsgroup)))
11210           (error "No such group: %s" to-newsgroup)))
11211     to-newsgroup))
11212
11213 (defun gnus-summary-save-parts (type dir n &optional reverse)
11214   "Save parts matching TYPE to DIR.
11215 If REVERSE, save parts that do not match TYPE."
11216   (interactive
11217    (list (read-string "Save parts of type: "
11218                       (or (car gnus-summary-save-parts-type-history)
11219                           gnus-summary-save-parts-default-mime)
11220                       'gnus-summary-save-parts-type-history)
11221          (setq gnus-summary-save-parts-last-directory
11222                (read-file-name "Save to directory: "
11223                                gnus-summary-save-parts-last-directory
11224                                nil t))
11225          current-prefix-arg))
11226   (gnus-summary-iterate n
11227     (let ((gnus-display-mime-function nil)
11228           (gnus-inhibit-treatment t))
11229       (gnus-summary-select-article))
11230     (save-excursion
11231       (set-buffer gnus-article-buffer)
11232       (let ((handles (or gnus-article-mime-handles
11233                          (mm-dissect-buffer nil gnus-article-loose-mime)
11234                          (and gnus-article-emulate-mime
11235                               (mm-uu-dissect)))))
11236         (when handles
11237           (gnus-summary-save-parts-1 type dir handles reverse)
11238           (unless gnus-article-mime-handles ;; Don't destroy this case.
11239             (mm-destroy-parts handles)))))))
11240
11241 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11242   (if (stringp (car handle))
11243       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11244               (cdr handle))
11245     (when (if reverse
11246               (not (string-match type (mm-handle-media-type handle)))
11247             (string-match type (mm-handle-media-type handle)))
11248       (let ((file (expand-file-name
11249                    (gnus-map-function
11250                     mm-file-name-rewrite-functions
11251                     (file-name-nondirectory
11252                      (or
11253                       (mail-content-type-get
11254                        (mm-handle-disposition handle) 'filename)
11255                       (mail-content-type-get
11256                        (mm-handle-type handle) 'name)
11257                       (concat gnus-newsgroup-name
11258                               "." (number-to-string
11259                                    (cdr gnus-article-current))))))
11260                    dir)))
11261         (unless (file-exists-p file)
11262           (mm-save-part-to-file handle file))))))
11263
11264 ;; Summary extract commands
11265
11266 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11267   (let ((buffer-read-only nil)
11268         (article (gnus-summary-article-number))
11269         after-article b e)
11270     (unless (gnus-summary-goto-subject article)
11271       (error "No such article: %d" article))
11272     (gnus-summary-position-point)
11273     ;; If all commands are to be bunched up on one line, we collect
11274     ;; them here.
11275     (unless gnus-view-pseudos-separately
11276       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11277             files action)
11278         (while ps
11279           (setq action (cdr (assq 'action (car ps))))
11280           (setq files (list (cdr (assq 'name (car ps)))))
11281           (while (and ps (cdr ps)
11282                       (string= (or action "1")
11283                                (or (cdr (assq 'action (cadr ps))) "2")))
11284             (push (cdr (assq 'name (cadr ps))) files)
11285             (setcdr ps (cddr ps)))
11286           (when files
11287             (when (not (string-match "%s" action))
11288               (push " " files))
11289             (push " " files)
11290             (when (assq 'execute (car ps))
11291               (setcdr (assq 'execute (car ps))
11292                       (funcall (if (string-match "%s" action)
11293                                    'format 'concat)
11294                                action
11295                                (mapconcat
11296                                 (lambda (f)
11297                                   (if (equal f " ")
11298                                       f
11299                                     (shell-quote-argument f)))
11300                                 files " ")))))
11301           (setq ps (cdr ps)))))
11302     (if (and gnus-view-pseudos (not not-view))
11303         (while pslist
11304           (when (assq 'execute (car pslist))
11305             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11306                                   (eq gnus-view-pseudos 'not-confirm)))
11307           (setq pslist (cdr pslist)))
11308       (save-excursion
11309         (while pslist
11310           (setq after-article (or (cdr (assq 'article (car pslist)))
11311                                   (gnus-summary-article-number)))
11312           (gnus-summary-goto-subject after-article)
11313           (forward-line 1)
11314           (setq b (point))
11315           (insert "    " (file-name-nondirectory
11316                           (cdr (assq 'name (car pslist))))
11317                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11318           (setq e (point))
11319           (forward-line -1)             ; back to `b'
11320           (gnus-add-text-properties
11321            b (1- e) (list 'gnus-number gnus-reffed-article-number
11322                           gnus-mouse-face-prop gnus-mouse-face))
11323           (gnus-data-enter
11324            after-article gnus-reffed-article-number
11325            gnus-unread-mark b (car pslist) 0 (- e b))
11326           (setq gnus-newsgroup-unreads
11327                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11328                                          gnus-reffed-article-number))
11329           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11330           (setq pslist (cdr pslist)))))))
11331
11332 (defun gnus-pseudos< (p1 p2)
11333   (let ((c1 (cdr (assq 'action p1)))
11334         (c2 (cdr (assq 'action p2))))
11335     (and c1 c2 (string< c1 c2))))
11336
11337 (defun gnus-request-pseudo-article (props)
11338   (cond ((assq 'execute props)
11339          (gnus-execute-command (cdr (assq 'execute props)))))
11340   (let ((gnus-current-article (gnus-summary-article-number)))
11341     (gnus-run-hooks 'gnus-mark-article-hook)))
11342
11343 (defun gnus-execute-command (command &optional automatic)
11344   (save-excursion
11345     (gnus-article-setup-buffer)
11346     (set-buffer gnus-article-buffer)
11347     (setq buffer-read-only nil)
11348     (let ((command (if automatic command
11349                      (read-string "Command: " (cons command 0)))))
11350       (erase-buffer)
11351       (insert "$ " command "\n\n")
11352       (if gnus-view-pseudo-asynchronously
11353           (start-process "gnus-execute" (current-buffer) shell-file-name
11354                          shell-command-switch command)
11355         (call-process shell-file-name nil t nil
11356                       shell-command-switch command)))))
11357
11358 ;; Summary kill commands.
11359
11360 (defun gnus-summary-edit-global-kill (article)
11361   "Edit the \"global\" kill file."
11362   (interactive (list (gnus-summary-article-number)))
11363   (gnus-group-edit-global-kill article))
11364
11365 (defun gnus-summary-edit-local-kill ()
11366   "Edit a local kill file applied to the current newsgroup."
11367   (interactive)
11368   (setq gnus-current-headers (gnus-summary-article-header))
11369   (gnus-group-edit-local-kill
11370    (gnus-summary-article-number) gnus-newsgroup-name))
11371
11372 ;;; Header reading.
11373
11374 (defun gnus-read-header (id &optional header)
11375   "Read the headers of article ID and enter them into the Gnus system."
11376   (let ((group gnus-newsgroup-name)
11377         (gnus-override-method
11378          (or
11379           gnus-override-method
11380           (and (gnus-news-group-p gnus-newsgroup-name)
11381                (car (gnus-refer-article-methods)))))
11382         where)
11383     ;; First we check to see whether the header in question is already
11384     ;; fetched.
11385     (if (stringp id)
11386         ;; This is a Message-ID.
11387         (setq header (or header (gnus-id-to-header id)))
11388       ;; This is an article number.
11389       (setq header (or header (gnus-summary-article-header id))))
11390     (if (and header
11391              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11392         ;; We have found the header.
11393         header
11394       ;; We have to really fetch the header to this article.
11395       (save-excursion
11396         (set-buffer nntp-server-buffer)
11397         (when (setq where (gnus-request-head id group))
11398           (nnheader-fold-continuation-lines)
11399           (goto-char (point-max))
11400           (insert ".\n")
11401           (goto-char (point-min))
11402           (insert "211 ")
11403           (princ (cond
11404                   ((numberp id) id)
11405                   ((cdr where) (cdr where))
11406                   (header (mail-header-number header))
11407                   (t gnus-reffed-article-number))
11408                  (current-buffer))
11409           (insert " Article retrieved.\n"))
11410         (if (or (not where)
11411                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11412             ()                          ; Malformed head.
11413           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11414             (when (and (stringp id)
11415                        (not (string= (gnus-group-real-name group)
11416                                      (car where))))
11417               ;; If we fetched by Message-ID and the article came
11418               ;; from a different group, we fudge some bogus article
11419               ;; numbers for this article.
11420               (mail-header-set-number header gnus-reffed-article-number))
11421             (save-excursion
11422               (set-buffer gnus-summary-buffer)
11423               (decf gnus-reffed-article-number)
11424               (gnus-remove-header (mail-header-number header))
11425               (push header gnus-newsgroup-headers)
11426               (setq gnus-current-headers header)
11427               (push (mail-header-number header) gnus-newsgroup-limit)))
11428           header)))))
11429
11430 (defun gnus-remove-header (number)
11431   "Remove header NUMBER from `gnus-newsgroup-headers'."
11432   (if (and gnus-newsgroup-headers
11433            (= number (mail-header-number (car gnus-newsgroup-headers))))
11434       (pop gnus-newsgroup-headers)
11435     (let ((headers gnus-newsgroup-headers))
11436       (while (and (cdr headers)
11437                   (not (= number (mail-header-number (cadr headers)))))
11438         (pop headers))
11439       (when (cdr headers)
11440         (setcdr headers (cddr headers))))))
11441
11442 ;;;
11443 ;;; summary highlights
11444 ;;;
11445
11446 (defun gnus-highlight-selected-summary ()
11447   "Highlight selected article in summary buffer."
11448   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11449   (when gnus-summary-selected-face
11450     (save-excursion
11451       (let* ((beg (point-at-bol))
11452              (end (point-at-eol))
11453              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11454              (from (if (get-text-property beg gnus-mouse-face-prop)
11455                        beg
11456                      (or (next-single-property-change
11457                           beg gnus-mouse-face-prop nil end)
11458                          beg)))
11459              (to
11460               (if (= from end)
11461                   (- from 2)
11462                 (or (next-single-property-change
11463                      from gnus-mouse-face-prop nil end)
11464                     end))))
11465         ;; If no mouse-face prop on line we will have to = from = end,
11466         ;; so we highlight the entire line instead.
11467         (when (= (+ to 2) from)
11468           (setq from beg)
11469           (setq to end))
11470         (if gnus-newsgroup-selected-overlay
11471             ;; Move old overlay.
11472             (gnus-move-overlay
11473              gnus-newsgroup-selected-overlay from to (current-buffer))
11474           ;; Create new overlay.
11475           (gnus-overlay-put
11476            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11477            'face gnus-summary-selected-face))))))
11478
11479 (defvar gnus-summary-highlight-line-cached nil)
11480 (defvar gnus-summary-highlight-line-trigger nil)
11481
11482 (defun gnus-summary-highlight-line-0 ()
11483   (if (and (eq gnus-summary-highlight-line-trigger
11484                gnus-summary-highlight)
11485            gnus-summary-highlight-line-cached)
11486       gnus-summary-highlight-line-cached
11487     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11488           gnus-summary-highlight-line-cached
11489           (let* ((cond (list 'cond))
11490                  (c cond)
11491                  (list gnus-summary-highlight))
11492             (while list
11493               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11494                               nil))
11495               (setq c (cdr c)
11496                     list (cdr list)))
11497             (gnus-byte-compile (list 'lambda nil cond))))))
11498
11499 (defun gnus-summary-highlight-line ()
11500   "Highlight current line according to `gnus-summary-highlight'."
11501   (let* ((beg (point-at-bol))
11502          (article (or (gnus-summary-article-number) gnus-current-article))
11503          (score (or (cdr (assq article
11504                                gnus-newsgroup-scored))
11505                     gnus-summary-default-score 0))
11506          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11507          (inhibit-read-only t)
11508          (default gnus-summary-default-score)
11509          (default-high gnus-summary-default-high-score)
11510          (default-low gnus-summary-default-low-score)
11511          (uncached (and gnus-summary-use-undownloaded-faces
11512                         (memq article gnus-newsgroup-undownloaded)
11513                         (not (memq article gnus-newsgroup-cached)))))
11514     (let ((face (funcall (gnus-summary-highlight-line-0))))
11515       (unless (eq face (get-text-property beg 'face))
11516         (gnus-put-text-property-excluding-characters-with-faces
11517          beg (point-at-eol) 'face
11518          (setq face (if (boundp face) (symbol-value face) face)))
11519         (when gnus-summary-highlight-line-function
11520           (funcall gnus-summary-highlight-line-function article face))))))
11521
11522 (defun gnus-update-read-articles (group unread &optional compute)
11523   "Update the list of read articles in GROUP.
11524 UNREAD is a sorted list."
11525   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11526         (info (gnus-get-info group))
11527         (prev 1)
11528         read)
11529     (if (or (not info) (not active))
11530         ;; There is no info on this group if it was, in fact,
11531         ;; killed.  Gnus stores no information on killed groups, so
11532         ;; there's nothing to be done.
11533         ;; One could store the information somewhere temporarily,
11534         ;; perhaps...  Hmmm...
11535         ()
11536       ;; Remove any negative articles numbers.
11537       (while (and unread (< (car unread) 0))
11538         (setq unread (cdr unread)))
11539       ;; Remove any expired article numbers
11540       (while (and unread (< (car unread) (car active)))
11541         (setq unread (cdr unread)))
11542       ;; Compute the ranges of read articles by looking at the list of
11543       ;; unread articles.
11544       (while unread
11545         (when (/= (car unread) prev)
11546           (push (if (= prev (1- (car unread))) prev
11547                   (cons prev (1- (car unread))))
11548                 read))
11549         (setq prev (1+ (car unread)))
11550         (setq unread (cdr unread)))
11551       (when (<= prev (cdr active))
11552         (push (cons prev (cdr active)) read))
11553       (setq read (if (> (length read) 1) (nreverse read) read))
11554       (if compute
11555           read
11556         (save-excursion
11557           (let (setmarkundo)
11558             ;; Propagate the read marks to the backend.
11559             (when (gnus-check-backend-function 'request-set-mark group)
11560               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11561                     (add (gnus-remove-from-range read (gnus-info-read info))))
11562                 (when (or add del)
11563                   (unless (gnus-check-group group)
11564                     (error "Can't open server for %s" group))
11565                   (gnus-request-set-mark
11566                    group (delq nil (list (if add (list add 'add '(read)))
11567                                          (if del (list del 'del '(read))))))
11568                   (setq setmarkundo
11569                         `(gnus-request-set-mark
11570                           ,group
11571                           ',(delq nil (list
11572                                        (if del (list del 'add '(read)))
11573                                        (if add (list add 'del '(read))))))))))
11574             (set-buffer gnus-group-buffer)
11575             (gnus-undo-register
11576               `(progn
11577                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11578                  (gnus-info-set-read ',info ',(gnus-info-read info))
11579                  (gnus-get-unread-articles-in-group ',info
11580                                                     (gnus-active ,group))
11581                  (gnus-group-update-group ,group t)
11582                  ,setmarkundo))))
11583         ;; Enter this list into the group info.
11584         (gnus-info-set-read info read)
11585         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11586         (gnus-get-unread-articles-in-group info (gnus-active group))
11587         t))))
11588
11589 (defun gnus-offer-save-summaries ()
11590   "Offer to save all active summary buffers."
11591   (let (buffers)
11592     ;; Go through all buffers and find all summaries.
11593     (dolist (buffer (buffer-list))
11594       (when (and (setq buffer (buffer-name buffer))
11595                  (string-match "Summary" buffer)
11596                  (with-current-buffer buffer
11597                    ;; We check that this is, indeed, a summary buffer.
11598                    (and (eq major-mode 'gnus-summary-mode)
11599                         ;; Also make sure this isn't bogus.
11600                         gnus-newsgroup-prepared
11601                         ;; Also make sure that this isn't a
11602                         ;; dead summary buffer.
11603                         (not gnus-dead-summary-mode))))
11604         (push buffer buffers)))
11605     ;; Go through all these summary buffers and offer to save them.
11606     (when buffers
11607       (save-excursion
11608         (map-y-or-n-p
11609          "Update summary buffer %s? "
11610          (lambda (buf)
11611            (switch-to-buffer buf)
11612            (gnus-summary-exit))
11613          buffers)))))
11614
11615 (defun gnus-summary-setup-default-charset ()
11616   "Setup newsgroup default charset."
11617   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11618       (setq gnus-newsgroup-charset nil)
11619     (let* ((ignored-charsets
11620             (or gnus-newsgroup-ephemeral-ignored-charsets
11621                 (append
11622                  (and gnus-newsgroup-name
11623                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11624                  gnus-newsgroup-ignored-charsets))))
11625       (setq gnus-newsgroup-charset
11626             (or gnus-newsgroup-ephemeral-charset
11627                 (and gnus-newsgroup-name
11628                      (gnus-parameter-charset gnus-newsgroup-name))
11629                 gnus-default-charset))
11630       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11631            ignored-charsets))))
11632
11633 ;;;
11634 ;;; Mime Commands
11635 ;;;
11636
11637 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11638   "Display the current article buffer fully MIME-buttonized.
11639 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11640 treated as multipart/mixed."
11641   (interactive "P")
11642   (require 'gnus-art)
11643   (let ((gnus-unbuttonized-mime-types nil)
11644         (gnus-mime-display-multipart-as-mixed show-all-parts))
11645     (gnus-summary-show-article)))
11646
11647 (defun gnus-summary-repair-multipart (article)
11648   "Add a Content-Type header to a multipart article without one."
11649   (interactive (list (gnus-summary-article-number)))
11650   (gnus-with-article article
11651     (message-narrow-to-head)
11652     (message-remove-header "Mime-Version")
11653     (goto-char (point-max))
11654     (insert "Mime-Version: 1.0\n")
11655     (widen)
11656     (when (search-forward "\n--" nil t)
11657       (let ((separator (buffer-substring (point) (point-at-eol))))
11658         (message-narrow-to-head)
11659         (message-remove-header "Content-Type")
11660         (goto-char (point-max))
11661         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11662                         separator))
11663         (widen))))
11664   (let (gnus-mark-article-hook)
11665     (gnus-summary-select-article t t nil article)))
11666
11667 (defun gnus-summary-toggle-display-buttonized ()
11668   "Toggle the buttonizing of the article buffer."
11669   (interactive)
11670   (require 'gnus-art)
11671   (if (setq gnus-inhibit-mime-unbuttonizing
11672             (not gnus-inhibit-mime-unbuttonizing))
11673       (let ((gnus-unbuttonized-mime-types nil))
11674         (gnus-summary-show-article))
11675     (gnus-summary-show-article)))
11676
11677 ;;;
11678 ;;; Generic summary marking commands
11679 ;;;
11680
11681 (defvar gnus-summary-marking-alist
11682   '((read gnus-del-mark "d")
11683     (unread gnus-unread-mark "u")
11684     (ticked gnus-ticked-mark "!")
11685     (dormant gnus-dormant-mark "?")
11686     (expirable gnus-expirable-mark "e"))
11687   "An alist of names/marks/keystrokes.")
11688
11689 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11690 (defvar gnus-summary-mark-map)
11691
11692 (defun gnus-summary-make-all-marking-commands ()
11693   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11694   (dolist (elem gnus-summary-marking-alist)
11695     (apply 'gnus-summary-make-marking-command elem)))
11696
11697 (defun gnus-summary-make-marking-command (name mark keystroke)
11698   (let ((map (make-sparse-keymap)))
11699     (define-key gnus-summary-generic-mark-map keystroke map)
11700     (dolist (lway `((next "next" next nil "n")
11701                     (next-unread "next unread" next t "N")
11702                     (prev "previous" prev nil "p")
11703                     (prev-unread "previous unread" prev t "P")
11704                     (nomove "" nil nil ,keystroke)))
11705       (let ((func (gnus-summary-make-marking-command-1
11706                    mark (car lway) lway name)))
11707         (setq func (eval func))
11708         (define-key map (nth 4 lway) func)))))
11709
11710 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11711   `(defun ,(intern
11712             (format "gnus-summary-put-mark-as-%s%s"
11713                     name (if (eq way 'nomove)
11714                              ""
11715                            (concat "-" (symbol-name way)))))
11716      (n)
11717      ,(format
11718        "Mark the current article as %s%s.
11719 If N, the prefix, then repeat N times.
11720 If N is negative, move in reverse order.
11721 The difference between N and the actual number of articles marked is
11722 returned."
11723        name (cadr lway))
11724      (interactive "p")
11725      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11726
11727 (defun gnus-summary-generic-mark (n mark move unread)
11728   "Mark N articles with MARK."
11729   (unless (eq major-mode 'gnus-summary-mode)
11730     (error "This command can only be used in the summary buffer"))
11731   (gnus-summary-show-thread)
11732   (let ((nummove
11733          (cond
11734           ((eq move 'next) 1)
11735           ((eq move 'prev) -1)
11736           (t 0))))
11737     (if (zerop nummove)
11738         (setq n 1)
11739       (when (< n 0)
11740         (setq n (abs n)
11741               nummove (* -1 nummove))))
11742     (while (and (> n 0)
11743                 (gnus-summary-mark-article nil mark)
11744                 (zerop (gnus-summary-next-subject nummove unread t)))
11745       (setq n (1- n)))
11746     (when (/= 0 n)
11747       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11748     (gnus-summary-recenter)
11749     (gnus-summary-position-point)
11750     (gnus-set-mode-line 'summary)
11751     n))
11752
11753 (defun gnus-summary-insert-articles (articles)
11754   (when (setq articles
11755               (gnus-sorted-difference articles
11756                                       (mapcar (lambda (h)
11757                                                 (mail-header-number h))
11758                                               gnus-newsgroup-headers)))
11759     (setq gnus-newsgroup-headers
11760           (gnus-merge 'list
11761                       gnus-newsgroup-headers
11762                       (gnus-fetch-headers articles)
11763                       'gnus-article-sort-by-number))
11764     ;; Suppress duplicates?
11765     (when gnus-suppress-duplicates
11766       (gnus-dup-suppress-articles))
11767
11768     ;; We might want to build some more threads first.
11769     (when (and gnus-fetch-old-headers
11770                (eq gnus-headers-retrieved-by 'nov))
11771       (if (eq gnus-fetch-old-headers 'invisible)
11772           (gnus-build-all-threads)
11773         (gnus-build-old-threads)))
11774     ;; Let the Gnus agent mark articles as read.
11775     (when gnus-agent
11776       (gnus-agent-get-undownloaded-list))
11777     ;; Remove list identifiers from subject
11778     (when gnus-list-identifiers
11779       (gnus-summary-remove-list-identifiers))
11780     ;; First and last article in this newsgroup.
11781     (when gnus-newsgroup-headers
11782       (setq gnus-newsgroup-begin
11783             (mail-header-number (car gnus-newsgroup-headers))
11784             gnus-newsgroup-end
11785             (mail-header-number
11786              (gnus-last-element gnus-newsgroup-headers))))
11787     (when gnus-use-scoring
11788       (gnus-possibly-score-headers))))
11789
11790 (defun gnus-summary-insert-old-articles (&optional all)
11791   "Insert all old articles in this group.
11792 If ALL is non-nil, already read articles become readable.
11793 If ALL is a number, fetch this number of articles."
11794   (interactive "P")
11795   (prog1
11796       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11797             older len)
11798         (setq older
11799               ;; Some nntp servers lie about their active range.  When
11800               ;; this happens, the active range can be in the millions.
11801               ;; Use a compressed range to avoid creating a huge list.
11802               (gnus-range-difference (list gnus-newsgroup-active) old))
11803         (setq len (gnus-range-length older))
11804         (cond
11805          ((null older) nil)
11806          ((numberp all)
11807           (if (< all len)
11808               (let ((older-range (nreverse older)))
11809                 (setq older nil)
11810
11811                 (while (> all 0)
11812                   (let* ((r (pop older-range))
11813                          (min (if (numberp r) r (car r)))
11814                          (max (if (numberp r) r (cdr r))))
11815                     (while (and (<= min max)
11816                                 (> all 0))
11817                       (push max older)
11818                       (setq all (1- all)
11819                             max (1- max))))))
11820             (setq older (gnus-uncompress-range older))))
11821          (all
11822           (setq older (gnus-uncompress-range older)))
11823          (t
11824           (when (and (numberp gnus-large-newsgroup)
11825                    (> len gnus-large-newsgroup))
11826               (let* ((cursor-in-echo-area nil)
11827                      (initial (gnus-parameter-large-newsgroup-initial
11828                                gnus-newsgroup-name))
11829                      (input
11830                       (read-string
11831                        (format
11832                         "How many articles from %s (%s %d): "
11833                         (gnus-limit-string
11834                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11835                         (if initial "max" "default")
11836                         len)
11837                        (if initial
11838                            (cons (number-to-string initial)
11839                                  0)))))
11840                 (unless (string-match "^[ \t]*$" input)
11841                   (setq all (string-to-number input))
11842                   (if (< all len)
11843                       (let ((older-range (nreverse older)))
11844                         (setq older nil)
11845
11846                         (while (> all 0)
11847                           (let* ((r (pop older-range))
11848                                  (min (if (numberp r) r (car r)))
11849                                  (max (if (numberp r) r (cdr r))))
11850                             (while (and (<= min max)
11851                                         (> all 0))
11852                               (push max older)
11853                               (setq all (1- all)
11854                                     max (1- max))))))))))
11855           (setq older (gnus-uncompress-range older))))
11856         (if (not older)
11857             (message "No old news.")
11858           (gnus-summary-insert-articles older)
11859           (gnus-summary-limit (gnus-sorted-nunion old older))))
11860     (gnus-summary-position-point)))
11861
11862 (defun gnus-summary-insert-new-articles ()
11863   "Insert all new articles in this group."
11864   (interactive)
11865   (prog1
11866       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11867             (old-active gnus-newsgroup-active)
11868             (nnmail-fetched-sources (list t))
11869             i new)
11870         (setq gnus-newsgroup-active
11871               (gnus-activate-group gnus-newsgroup-name 'scan))
11872         (setq i (cdr gnus-newsgroup-active))
11873         (while (> i (cdr old-active))
11874           (push i new)
11875           (decf i))
11876         (if (not new)
11877             (message "No gnus is bad news")
11878           (gnus-summary-insert-articles new)
11879           (setq gnus-newsgroup-unreads
11880                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11881           (gnus-summary-limit (gnus-sorted-nunion old new))))
11882     (gnus-summary-position-point)))
11883
11884 (gnus-summary-make-all-marking-commands)
11885
11886 (gnus-ems-redefine)
11887
11888 (provide 'gnus-sum)
11889
11890 (run-hooks 'gnus-sum-load-hook)
11891
11892 ;; Local Variables:
11893 ;; coding: iso-8859-1
11894 ;; End:
11895
11896 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11897 ;;; gnus-sum.el ends here