Synch to No Gnus 200602081205.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
9 ;; Keywords: mail, news, MIME
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;;; Code:
31
32 (eval-when-compile
33   (require 'cl)
34   (defvar tool-bar-mode))
35
36 (require 'gnus)
37 (require 'gnus-group)
38 (require 'gnus-spec)
39 (require 'gnus-range)
40 (require 'gnus-int)
41 (require 'gnus-undo)
42 (require 'gnus-util)
43 (require 'gmm-utils)
44 (require 'nnoo)
45
46 (eval-when-compile
47   (require 'mime-play)
48   (require 'static))
49
50 (eval-and-compile
51   (autoload 'pgg-decrypt-region "pgg" nil t)
52   (autoload 'pgg-verify-region "pgg" nil t))
53
54 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
55 (autoload 'gnus-cache-write-active "gnus-cache")
56 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
57 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
58 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
59 (autoload 'mm-uu-dissect "mm-uu")
60 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
61   "Deuglify broken Outlook (Express) articles and redisplay."
62   t)
63 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
64 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
65 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
66
67 (defcustom gnus-kill-summary-on-exit t
68   "*If non-nil, kill the summary buffer when you exit from it.
69 If nil, the summary will become a \"*Dead Summary*\" buffer, and
70 it will be killed sometime later."
71   :group 'gnus-summary-exit
72   :type 'boolean)
73
74 (defcustom gnus-fetch-old-headers nil
75   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
76 If an unread article in the group refers to an older, already
77 read (or just marked as read) article, the old article will not
78 normally be displayed in the Summary buffer.  If this variable is
79 t, Gnus will attempt to grab the headers to the old articles, and
80 thereby build complete threads.  If it has the value `some', all
81 old headers will be fetched but only enough headers to connect
82 otherwise loose threads will be displayed.  This variable can
83 also be a number.  In that case, no more than that number of old
84 headers will be fetched.  If it has the value `invisible', all
85 old headers will be fetched, but none will be displayed.
86
87 The server has to support NOV for any of this to work.
88
89 This feature can seriously impact performance it ignores all
90 locally cached header entries."
91   :group 'gnus-thread
92   :type '(choice (const :tag "off" nil)
93                  (const :tag "on" t)
94                  (const some)
95                  (const invisible)
96                  number
97                  (sexp :menu-tag "other" t)))
98
99 (defcustom gnus-refer-thread-limit 200
100   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
101 If t, fetch all the available old headers."
102   :group 'gnus-thread
103   :type '(choice number
104                  (sexp :menu-tag "other" t)))
105
106 (defcustom gnus-summary-make-false-root 'adopt
107   "*nil means that Gnus won't gather loose threads.
108 If the root of a thread has expired or been read in a previous
109 session, the information necessary to build a complete thread has been
110 lost.  Instead of having many small sub-threads from this original thread
111 scattered all over the summary buffer, Gnus can gather them.
112
113 If non-nil, Gnus will try to gather all loose sub-threads from an
114 original thread into one large thread.
115
116 If this variable is non-nil, it should be one of `none', `adopt',
117 `dummy' or `empty'.
118
119 If this variable is `none', Gnus will not make a false root, but just
120 present the sub-threads after another.
121 If this variable is `dummy', Gnus will create a dummy root that will
122 have all the sub-threads as children.
123 If this variable is `adopt', Gnus will make one of the \"children\"
124 the parent and mark all the step-children as such.
125 If this variable is `empty', the \"children\" are printed with empty
126 subject fields.  (Or rather, they will be printed with a string
127 given by the `gnus-summary-same-subject' variable.)"
128   :group 'gnus-thread
129   :type '(choice (const :tag "off" nil)
130                  (const none)
131                  (const dummy)
132                  (const adopt)
133                  (const empty)))
134
135 (defcustom gnus-summary-make-false-root-always nil
136   "Always make a false dummy root."
137   :version "22.1"
138   :group 'gnus-thread
139   :type 'boolean)
140
141 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
142   "*A regexp to match subjects to be excluded from loose thread gathering.
143 As loose thread gathering is done on subjects only, that means that
144 there can be many false gatherings performed.  By rooting out certain
145 common subjects, gathering might become saner."
146   :group 'gnus-thread
147   :type 'regexp)
148
149 (defcustom gnus-summary-gather-subject-limit nil
150   "*Maximum length of subject comparisons when gathering loose threads.
151 Use nil to compare full subjects.  Setting this variable to a low
152 number will help gather threads that have been corrupted by
153 newsreaders chopping off subject lines, but it might also mean that
154 unrelated articles that have subject that happen to begin with the
155 same few characters will be incorrectly gathered.
156
157 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
158 comparing subjects."
159   :group 'gnus-thread
160   :type '(choice (const :tag "off" nil)
161                  (const fuzzy)
162                  (sexp :menu-tag "on" t)))
163
164 (defcustom gnus-simplify-subject-functions nil
165   "List of functions taking a string argument that simplify subjects.
166 The functions are applied recursively.
167
168 Useful functions to put in this list include:
169 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
170 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
171   :group 'gnus-thread
172   :type '(repeat function))
173
174 (defcustom gnus-simplify-ignored-prefixes nil
175   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  regexp))
179
180 (defcustom gnus-build-sparse-threads nil
181   "*If non-nil, fill in the gaps in threads.
182 If `some', only fill in the gaps that are needed to tie loose threads
183 together.  If `more', fill in all leaf nodes that Gnus can find.  If
184 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
185   :group 'gnus-thread
186   :type '(choice (const :tag "off" nil)
187                  (const some)
188                  (const more)
189                  (sexp :menu-tag "all" t)))
190
191 (defcustom gnus-summary-thread-gathering-function
192   'gnus-gather-threads-by-subject
193   "*Function used for gathering loose threads.
194 There are two pre-defined functions: `gnus-gather-threads-by-subject',
195 which only takes Subjects into consideration; and
196 `gnus-gather-threads-by-references', which compared the References
197 headers of the articles to find matches."
198   :group 'gnus-thread
199   :type '(radio (function-item gnus-gather-threads-by-subject)
200                 (function-item gnus-gather-threads-by-references)
201                 (function :tag "other")))
202
203 (defcustom gnus-summary-same-subject ""
204   "*String indicating that the current article has the same subject as the previous.
205 This variable will only be used if the value of
206 `gnus-summary-make-false-root' is `empty'."
207   :group 'gnus-summary-format
208   :type 'string)
209
210 (defcustom gnus-summary-goto-unread t
211   "*If t, many commands will go to the next unread article.
212 This applies to marking commands as well as other commands that
213 \"naturally\" select the next article, like, for instance, `SPC' at
214 the end of an article.
215
216 If nil, the marking commands do NOT go to the next unread article
217 \(they go to the next article instead).  If `never', commands that
218 usually go to the next unread article, will go to the next article,
219 whether it is read or not."
220   :group 'gnus-summary-marks
221   :link '(custom-manual "(gnus)Setting Marks")
222   :type '(choice (const :tag "off" nil)
223                  (const never)
224                  (sexp :menu-tag "on" t)))
225
226 (defcustom gnus-summary-default-score 0
227   "*Default article score level.
228 All scores generated by the score files will be added to this score.
229 If this variable is nil, scoring will be disabled."
230   :group 'gnus-score-default
231   :type '(choice (const :tag "disable")
232                  integer))
233
234 (defcustom gnus-summary-default-high-score 0
235   "*Default threshold for a high scored article.
236 An article will be highlighted as high scored if its score is greater
237 than this score."
238   :version "22.1"
239   :group 'gnus-score-default
240   :type 'integer)
241
242 (defcustom gnus-summary-default-low-score 0
243   "*Default threshold for a low scored article.
244 An article will be highlighted as low scored if its score is smaller
245 than this score."
246   :version "22.1"
247   :group 'gnus-score-default
248   :type 'integer)
249
250 (defcustom gnus-summary-zcore-fuzz 0
251   "*Fuzziness factor for the zcore in the summary buffer.
252 Articles with scores closer than this to `gnus-summary-default-score'
253 will not be marked."
254   :group 'gnus-summary-format
255   :type 'integer)
256
257 (defcustom gnus-simplify-subject-fuzzy-regexp nil
258   "*Strings to be removed when doing fuzzy matches.
259 This can either be a regular expression or list of regular expressions
260 that will be removed from subject strings if fuzzy subject
261 simplification is selected."
262   :group 'gnus-thread
263   :type '(repeat regexp))
264
265 (defcustom gnus-show-threads t
266   "*If non-nil, display threads in summary mode."
267   :group 'gnus-thread
268   :type 'boolean)
269
270 (defcustom gnus-thread-hide-subtree nil
271   "*If non-nil, hide all threads initially.
272 This can be a predicate specifier which says which threads to hide.
273 If threads are hidden, you have to run the command
274 `gnus-summary-show-thread' by hand or or select an article."
275   :group 'gnus-thread
276   :type '(radio (sexp :format "Non-nil\n"
277                       :match (lambda (widget value)
278                                (not (or (consp value) (functionp value))))
279                       :value t)
280                 (const nil)
281                 (sexp :tag "Predicate specifier")))
282
283 (defcustom gnus-thread-hide-killed t
284   "*If non-nil, hide killed threads automatically."
285   :group 'gnus-thread
286   :type 'boolean)
287
288 (defcustom gnus-thread-ignore-subject t
289   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
290 If nil, articles that have different subjects from their parents will
291 start separate threads."
292   :group 'gnus-thread
293   :type 'boolean)
294
295 (defcustom gnus-thread-operation-ignore-subject t
296   "*If non-nil, subjects will be ignored when doing thread commands.
297 This affects commands like `gnus-summary-kill-thread' and
298 `gnus-summary-lower-thread'.
299
300 If this variable is nil, articles in the same thread with different
301 subjects will not be included in the operation in question.  If this
302 variable is `fuzzy', only articles that have subjects that are fuzzily
303 equal will be included."
304   :group 'gnus-thread
305   :type '(choice (const :tag "off" nil)
306                  (const fuzzy)
307                  (sexp :tag "on" t)))
308
309 (defcustom gnus-thread-indent-level 4
310   "*Number that says how much each sub-thread should be indented."
311   :group 'gnus-thread
312   :type 'integer)
313
314 (defcustom gnus-auto-extend-newsgroup t
315   "*If non-nil, extend newsgroup forward and backward when requested."
316   :group 'gnus-summary-choose
317   :type 'boolean)
318
319 (defcustom gnus-auto-select-first t
320   "*If non-nil, select the article under point.
321 Which article this is is controlled by the `gnus-auto-select-subject'
322 variable.
323
324 If you want to prevent automatic selection of articles in some
325 newsgroups, set the variable to nil in `gnus-select-group-hook'."
326   :group 'gnus-group-select
327   :type '(choice (const :tag "none" nil)
328                  (sexp :menu-tag "first" t)))
329
330 (defcustom gnus-auto-select-subject 'unread
331   "*Says what subject to place under point when entering a group.
332
333 This variable can either be the symbols `first' (place point on the
334 first subject), `unread' (place point on the subject line of the first
335 unread article), `best' (place point on the subject line of the
336 higest-scored article), `unseen' (place point on the subject line of
337 the first unseen article), `unseen-or-unread' (place point on the subject
338 line of the first unseen article or, if all article have been seen, on the
339 subject line of the first unread article), or a function to be called to
340 place point on some subject line."
341   :version "22.1"
342   :group 'gnus-group-select
343   :type '(choice (const best)
344                  (const unread)
345                  (const first)
346                  (const unseen)
347                  (const unseen-or-unread)))
348
349 (defcustom gnus-dont-select-after-jump-to-other-group nil
350   "If non-nil, don't select the first unread article after entering the
351 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
352 it is depend on the value of `gnus-auto-select-first' whether to select
353 or not."
354   :group 'gnus-group-select
355   :type 'boolean)
356
357 (defcustom gnus-auto-select-next t
358   "*If non-nil, offer to go to the next group from the end of the previous.
359 If the value is t and the next newsgroup is empty, Gnus will exit
360 summary mode and go back to group mode.  If the value is neither nil
361 nor t, Gnus will select the following unread newsgroup.  In
362 particular, if the value is the symbol `quietly', the next unread
363 newsgroup will be selected without any confirmation, and if it is
364 `almost-quietly', the next group will be selected without any
365 confirmation if you are located on the last article in the group.
366 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
367 will go to the next group without confirmation."
368   :group 'gnus-summary-maneuvering
369   :type '(choice (const :tag "off" nil)
370                  (const quietly)
371                  (const almost-quietly)
372                  (const slightly-quietly)
373                  (sexp :menu-tag "on" t)))
374
375 (defcustom gnus-auto-select-same nil
376   "*If non-nil, select the next article with the same subject.
377 If there are no more articles with the same subject, go to
378 the first unread article."
379   :group 'gnus-summary-maneuvering
380   :type 'boolean)
381
382 (defcustom gnus-auto-goto-ignores 'unfetched
383   "*Says how to handle unfetched articles when maneuvering.
384
385 This variable can either be the symbols nil (maneuver to any
386 article), `undownloaded' (maneuvering while unplugged ignores articles
387 that have not been fetched), `always-undownloaded' (maneuvering always
388 ignores articles that have not been fetched), `unfetched' (maneuvering
389 ignores articles whose headers have not been fetched).
390
391 NOTE: The list of unfetched articles will always be nil when plugged
392 and, when unplugged, a subset of the undownloaded article list."
393   :version "22.1"
394   :group 'gnus-summary-maneuvering
395   :type '(choice (const :tag "None" nil)
396                  (const :tag "Undownloaded when unplugged" undownloaded)
397                  (const :tag "Undownloaded" always-undownloaded)
398                  (const :tag "Unfetched" unfetched)))
399
400 (defcustom gnus-summary-check-current nil
401   "*If non-nil, consider the current article when moving.
402 The \"unread\" movement commands will stay on the same line if the
403 current article is unread."
404   :group 'gnus-summary-maneuvering
405   :type 'boolean)
406
407 (defcustom gnus-auto-center-summary 2
408   "*If non-nil, always center the current summary buffer.
409 In particular, if `vertical' do only vertical recentering.  If non-nil
410 and non-`vertical', do both horizontal and vertical recentering."
411   :group 'gnus-summary-maneuvering
412   :type '(choice (const :tag "none" nil)
413                  (const vertical)
414                  (integer :tag "height")
415                  (sexp :menu-tag "both" t)))
416
417 (defvar gnus-auto-center-group t
418   "*If non-nil, always center the group buffer.")
419
420 (defcustom gnus-show-all-headers nil
421   "*If non-nil, don't hide any headers."
422   :group 'gnus-article-hiding
423   :group 'gnus-article-headers
424   :type 'boolean)
425
426 (defcustom gnus-summary-ignore-duplicates nil
427   "*If non-nil, ignore articles with identical Message-ID headers."
428   :group 'gnus-summary
429   :type 'boolean)
430
431 (defcustom gnus-single-article-buffer t
432   "*If non-nil, display all articles in the same buffer.
433 If nil, each group will get its own article buffer."
434   :group 'gnus-article-various
435   :type 'boolean)
436
437 (defcustom gnus-break-pages t
438   "*If non-nil, do page breaking on articles.
439 The page delimiter is specified by the `gnus-page-delimiter'
440 variable."
441   :group 'gnus-article-various
442   :type 'boolean)
443
444 (defcustom gnus-show-mime t
445   "*If non-nil, do mime processing of articles.
446 The articles will simply be fed to the function given by
447 `gnus-article-display-method-for-mime'."
448   :group 'gnus-article-mime
449   :type 'boolean)
450
451 (defcustom gnus-move-split-methods nil
452   "*Variable used to suggest where articles are to be moved to.
453 It uses the same syntax as the `gnus-split-methods' variable.
454 However, whereas `gnus-split-methods' specifies file names as targets,
455 this variable specifies group names."
456   :group 'gnus-summary-mail
457   :type '(repeat (choice (list :value (fun) function)
458                          (cons :value ("" "") regexp (repeat string))
459                          (sexp :value nil))))
460
461 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
462   "Function used to compute default prefix for article move/copy/etc prompts.
463 The function should take one argument, a group name, and return a
464 string with the suggested prefix."
465   :group 'gnus-summary-mail
466   :type 'function)
467
468 ;; FIXME: Although the custom type is `character' for the following variables,
469 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
470
471 (defcustom gnus-unread-mark ?\ ;;;Whitespace
472   "*Mark used for unread articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-ticked-mark ?!
477   "*Mark used for ticked articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-dormant-mark ??
482   "*Mark used for dormant articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-del-mark ?r
487   "*Mark used for del'd articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-read-mark ?R
492   "*Mark used for read articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-expirable-mark ?E
497   "*Mark used for expirable articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-killed-mark ?K
502   "*Mark used for killed articles."
503   :group 'gnus-summary-marks
504   :type 'character)
505
506 (defcustom gnus-spam-mark ?$
507   "*Mark used for spam articles."
508   :version "22.1"
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-souped-mark ?F
513   "*Mark used for souped articles."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-kill-file-mark ?X
518   "*Mark used for articles killed by kill files."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-low-score-mark ?Y
523   "*Mark used for articles with a low score."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-catchup-mark ?C
528   "*Mark used for articles that are caught up."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-replied-mark ?A
533   "*Mark used for articles that have been replied to."
534   :group 'gnus-summary-marks
535   :type 'character)
536
537 (defcustom gnus-forwarded-mark ?F
538   "*Mark used for articles that have been forwarded."
539   :version "22.1"
540   :group 'gnus-summary-marks
541   :type 'character)
542
543 (defcustom gnus-recent-mark ?N
544   "*Mark used for articles that are recent."
545   :version "22.1"
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-cached-mark ?*
550   "*Mark used for articles that are in the cache."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-saved-mark ?S
555   "*Mark used for articles that have been saved."
556   :group 'gnus-summary-marks
557   :type 'character)
558
559 (defcustom gnus-unseen-mark ?.
560   "*Mark used for articles that haven't been seen."
561   :version "22.1"
562   :group 'gnus-summary-marks
563   :type 'character)
564
565 (defcustom gnus-no-mark ?\ ;;;Whitespace
566   "*Mark used for articles that have no other secondary mark."
567   :version "22.1"
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-ancient-mark ?O
572   "*Mark used for ancient articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-sparse-mark ?Q
577   "*Mark used for sparsely reffed articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-canceled-mark ?G
582   "*Mark used for canceled articles."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-duplicate-mark ?M
587   "*Mark used for duplicate articles."
588   :group 'gnus-summary-marks
589   :type 'character)
590
591 (defcustom gnus-undownloaded-mark ?-
592   "*Mark used for articles that weren't downloaded."
593   :version "22.1"
594   :group 'gnus-summary-marks
595   :type 'character)
596
597 (defcustom gnus-downloaded-mark ?+
598   "*Mark used for articles that were downloaded."
599   :group 'gnus-summary-marks
600   :type 'character)
601
602 (defcustom gnus-downloadable-mark ?%
603   "*Mark used for articles that are to be downloaded."
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-unsendable-mark ?=
608   "*Mark used for articles that won't be sent."
609   :group 'gnus-summary-marks
610   :type 'character)
611
612 (defcustom gnus-score-over-mark ?+
613   "*Score mark used for articles with high scores."
614   :group 'gnus-summary-marks
615   :type 'character)
616
617 (defcustom gnus-score-below-mark ?-
618   "*Score mark used for articles with low scores."
619   :group 'gnus-summary-marks
620   :type 'character)
621
622 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
623   "*There is no thread under the article."
624   :group 'gnus-summary-marks
625   :type 'character)
626
627 (defcustom gnus-not-empty-thread-mark ?=
628   "*There is a thread under the article."
629   :group 'gnus-summary-marks
630   :type 'character)
631
632 (defcustom gnus-view-pseudo-asynchronously nil
633   "*If non-nil, Gnus will view pseudo-articles asynchronously."
634   :group 'gnus-extract-view
635   :type 'boolean)
636
637 (defcustom gnus-auto-expirable-marks
638   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
639         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
640         gnus-souped-mark gnus-duplicate-mark)
641   "*The list of marks converted into expiration if a group is auto-expirable."
642   :version "21.1"
643   :group 'gnus-summary
644   :type '(repeat character))
645
646 (defcustom gnus-inhibit-user-auto-expire t
647   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
648   :version "21.1"
649   :group 'gnus-summary
650   :type 'boolean)
651
652 (defcustom gnus-view-pseudos nil
653   "*If `automatic', pseudo-articles will be viewed automatically.
654 If `not-confirm', pseudos will be viewed automatically, and the user
655 will not be asked to confirm the command."
656   :group 'gnus-extract-view
657   :type '(choice (const :tag "off" nil)
658                  (const automatic)
659                  (const not-confirm)))
660
661 (defcustom gnus-view-pseudos-separately t
662   "*If non-nil, one pseudo-article will be created for each file to be viewed.
663 If nil, all files that use the same viewing command will be given as a
664 list of parameters to that command."
665   :group 'gnus-extract-view
666   :type 'boolean)
667
668 (defcustom gnus-insert-pseudo-articles t
669   "*If non-nil, insert pseudo-articles when decoding articles."
670   :group 'gnus-extract-view
671   :type 'boolean)
672
673 (defcustom gnus-summary-dummy-line-format
674   "   %(:                             :%) %S\n"
675   "*The format specification for the dummy roots in the summary buffer.
676 It works along the same lines as a normal formatting string,
677 with some simple extensions.
678
679 %S  The subject
680
681 General format specifiers can also be used.
682 See `(gnus)Formatting Variables'."
683   :link '(custom-manual "(gnus)Formatting Variables")
684   :group 'gnus-threading
685   :type 'string)
686
687 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
688   "*The format specification for the summary mode line.
689 It works along the same lines as a normal formatting string,
690 with some simple extensions:
691
692 %G  Group name
693 %p  Unprefixed group name
694 %A  Current article number
695 %z  Current article score
696 %V  Gnus version
697 %U  Number of unread articles in the group
698 %e  Number of unselected articles in the group
699 %Z  A string with unread/unselected article counts
700 %g  Shortish group name
701 %S  Subject of the current article
702 %u  User-defined spec
703 %s  Current score file name
704 %d  Number of dormant articles
705 %r  Number of articles that have been marked as read in this session
706 %E  Number of articles expunged by the score files"
707   :group 'gnus-summary-format
708   :type 'string)
709
710 (defcustom gnus-list-identifiers nil
711   "Regexp that matches list identifiers to be removed from subject.
712 This can also be a list of regexps."
713   :version "21.1"
714   :group 'gnus-summary-format
715   :group 'gnus-article-hiding
716   :type '(choice (const :tag "none" nil)
717                  (regexp :value ".*")
718                  (repeat :value (".*") regexp)))
719
720 (defcustom gnus-summary-mark-below 0
721   "*Mark all articles with a score below this variable as read.
722 This variable is local to each summary buffer and usually set by the
723 score file."
724   :group 'gnus-score-default
725   :type 'integer)
726
727 (defun gnus-widget-reversible-match (widget value)
728   "Ignoring WIDGET, convert VALUE to internal form.
729 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
730   ;; (debug value)
731   (or (symbolp value)
732       (and (listp value)
733            (eq (length value) 2)
734            (eq (nth 0 value) 'not)
735            (symbolp (nth 1 value)))))
736
737 (defun gnus-widget-reversible-to-internal (widget value)
738   "Ignoring WIDGET, convert VALUE to internal form.
739 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
740 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
741   ;; (debug value)
742   (if (atom value)
743       (list value nil)
744     (list (nth 1 value) t)))
745
746 (defun gnus-widget-reversible-to-external (widget value)
747   "Ignoring WIDGET, convert VALUE to external form.
748 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
749 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
750   ;; (debug value)
751   (if (nth 1 value)
752       (list 'not (nth 0 value))
753     (nth 0 value)))
754
755 (define-widget 'gnus-widget-reversible 'group
756   "A `group' that convert values."
757   :match 'gnus-widget-reversible-match
758   :value-to-internal 'gnus-widget-reversible-to-internal
759   :value-to-external 'gnus-widget-reversible-to-external)
760
761 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
762   "*List of functions used for sorting articles in the summary buffer.
763
764 Each function takes two articles and returns non-nil if the first
765 article should be sorted before the other.  If you use more than one
766 function, the primary sort function should be the last.  You should
767 probably always include `gnus-article-sort-by-number' in the list of
768 sorting functions -- preferably first.  Also note that sorting by date
769 is often much slower than sorting by number, and the sorting order is
770 very similar.  (Sorting by date means sorting by the time the message
771 was sent, sorting by number means sorting by arrival time.)
772
773 Each item can also be a list `(not F)' where F is a function;
774 this reverses the sort order.
775
776 Ready-made functions include `gnus-article-sort-by-number',
777 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
778 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
779 and `gnus-article-sort-by-score'.
780
781 When threading is turned on, the variable `gnus-thread-sort-functions'
782 controls how articles are sorted."
783   :group 'gnus-summary-sort
784   :type '(repeat (gnus-widget-reversible
785                   (choice (function-item gnus-article-sort-by-number)
786                           (function-item gnus-article-sort-by-author)
787                           (function-item gnus-article-sort-by-subject)
788                           (function-item gnus-article-sort-by-date)
789                           (function-item gnus-article-sort-by-score)
790                           (function-item gnus-article-sort-by-random)
791                           (function :tag "other"))
792                   (boolean :tag "Reverse order"))))
793
794
795 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
796   "*List of functions used for sorting threads in the summary buffer.
797 By default, threads are sorted by article number.
798
799 Each function takes two threads and returns non-nil if the first
800 thread should be sorted before the other.  If you use more than one
801 function, the primary sort function should be the last.  You should
802 probably always include `gnus-thread-sort-by-number' in the list of
803 sorting functions -- preferably first.  Also note that sorting by date
804 is often much slower than sorting by number, and the sorting order is
805 very similar.  (Sorting by date means sorting by the time the message
806 was sent, sorting by number means sorting by arrival time.)
807
808 Each list item can also be a list `(not F)' where F is a
809 function; this specifies reversed sort order.
810
811 Ready-made functions include `gnus-thread-sort-by-number',
812 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
813 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
814 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
815 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
816 and `gnus-thread-sort-by-total-score' (see
817 `gnus-thread-score-function').
818
819 When threading is turned off, the variable
820 `gnus-article-sort-functions' controls how articles are sorted."
821   :group 'gnus-summary-sort
822   :type '(repeat
823           (gnus-widget-reversible
824            (choice (function-item gnus-thread-sort-by-number)
825                    (function-item gnus-thread-sort-by-author)
826                    (function-item gnus-thread-sort-by-recipient)
827                    (function-item gnus-thread-sort-by-subject)
828                    (function-item gnus-thread-sort-by-date)
829                    (function-item gnus-thread-sort-by-score)
830                    (function-item gnus-thread-sort-by-most-recent-number)
831                    (function-item gnus-thread-sort-by-most-recent-date)
832                    (function-item gnus-thread-sort-by-random)
833                    (function-item gnus-thread-sort-by-total-score)
834                    (function :tag "other"))
835            (boolean :tag "Reverse order"))))
836
837 (defcustom gnus-thread-score-function '+
838   "*Function used for calculating the total score of a thread.
839
840 The function is called with the scores of the article and each
841 subthread and should then return the score of the thread.
842
843 Some functions you can use are `+', `max', or `min'."
844   :group 'gnus-summary-sort
845   :type 'function)
846
847 (defcustom gnus-summary-expunge-below nil
848   "All articles that have a score less than this variable will be expunged.
849 This variable is local to the summary buffers."
850   :group 'gnus-score-default
851   :type '(choice (const :tag "off" nil)
852                  integer))
853
854 (defcustom gnus-thread-expunge-below nil
855   "All threads that have a total score less than this variable will be expunged.
856 See `gnus-thread-score-function' for en explanation of what a
857 \"thread score\" is.
858
859 This variable is local to the summary buffers."
860   :group 'gnus-threading
861   :group 'gnus-score-default
862   :type '(choice (const :tag "off" nil)
863                  integer))
864
865 (defcustom gnus-summary-mode-hook nil
866   "*A hook for Gnus summary mode.
867 This hook is run before any variables are set in the summary buffer."
868   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
869   :group 'gnus-summary-various
870   :type 'hook)
871
872 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
873 (when (featurep 'xemacs)
874   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
875   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
876   (add-hook 'gnus-summary-mode-hook
877             'gnus-xmas-switch-horizontal-scrollbar-off))
878
879 (defcustom gnus-summary-menu-hook nil
880   "*Hook run after the creation of the summary mode menu."
881   :group 'gnus-summary-visual
882   :type 'hook)
883
884 (defcustom gnus-summary-exit-hook nil
885   "*A hook called on exit from the summary buffer.
886 It will be called with point in the group buffer."
887   :group 'gnus-summary-exit
888   :type 'hook)
889
890 (defcustom gnus-summary-prepare-hook nil
891   "*A hook called after the summary buffer has been generated.
892 If you want to modify the summary buffer, you can use this hook."
893   :group 'gnus-summary-various
894   :type 'hook)
895
896 (defcustom gnus-summary-prepared-hook nil
897   "*A hook called as the last thing after the summary buffer has been generated."
898   :group 'gnus-summary-various
899   :type 'hook)
900
901 (defcustom gnus-summary-generate-hook nil
902   "*A hook run just before generating the summary buffer.
903 This hook is commonly used to customize threading variables and the
904 like."
905   :group 'gnus-summary-various
906   :type 'hook)
907
908 (defcustom gnus-select-group-hook nil
909   "*A hook called when a newsgroup is selected.
910
911 If you'd like to simplify subjects like the
912 `gnus-summary-next-same-subject' command does, you can use the
913 following hook:
914
915  (add-hook gnus-select-group-hook
916            (lambda ()
917              (mapcar (lambda (header)
918                        (mail-header-set-subject
919                         header
920                         (gnus-simplify-subject
921                          (mail-header-subject header) 're-only)))
922                      gnus-newsgroup-headers)))"
923   :group 'gnus-group-select
924   :type 'hook)
925
926 (defcustom gnus-select-article-hook nil
927   "*A hook called when an article is selected."
928   :group 'gnus-summary-choose
929   :options '(gnus-agent-fetch-selected-article)
930   :type 'hook)
931
932 (defcustom gnus-visual-mark-article-hook
933   (list 'gnus-highlight-selected-summary)
934   "*Hook run after selecting an article in the summary buffer.
935 It is meant to be used for highlighting the article in some way.  It
936 is not run if `gnus-visual' is nil."
937   :group 'gnus-summary-visual
938   :type 'hook)
939
940 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
941   "*A hook called before parsing the headers."
942   :group 'gnus-various
943   :type 'hook)
944
945 (defcustom gnus-exit-group-hook nil
946   "*A hook called when exiting summary mode.
947 This hook is not called from the non-updating exit commands like `Q'."
948   :group 'gnus-various
949   :type 'hook)
950
951 (defcustom gnus-summary-update-hook
952   (list 'gnus-summary-highlight-line)
953   "*A hook called when a summary line is changed.
954 The hook will not be called if `gnus-visual' is nil.
955
956 The default function `gnus-summary-highlight-line' will
957 highlight the line according to the `gnus-summary-highlight'
958 variable."
959   :group 'gnus-summary-visual
960   :type 'hook)
961
962 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
963   "*A hook called when an article is selected for the first time.
964 The hook is intended to mark an article as read (or unread)
965 automatically when it is selected."
966   :group 'gnus-summary-choose
967   :type 'hook)
968
969 (defcustom gnus-group-no-more-groups-hook nil
970   "*A hook run when returning to group mode having no more (unread) groups."
971   :group 'gnus-group-select
972   :type 'hook)
973
974 (defcustom gnus-ps-print-hook nil
975   "*A hook run before ps-printing something from Gnus."
976   :group 'gnus-summary
977   :type 'hook)
978
979 (defcustom gnus-summary-article-move-hook nil
980   "*A hook called after an article is moved, copied, respooled, or crossposted."
981   :version "22.1"
982   :group 'gnus-summary
983   :type 'hook)
984
985 (defcustom gnus-summary-article-delete-hook nil
986   "*A hook called after an article is deleted."
987   :version "22.1"
988   :group 'gnus-summary
989   :type 'hook)
990
991 (defcustom gnus-summary-article-expire-hook nil
992   "*A hook called after an article is expired."
993   :version "22.1"
994   :group 'gnus-summary
995   :type 'hook)
996
997 (defcustom gnus-summary-display-arrow
998   (and (fboundp 'display-graphic-p)
999        (display-graphic-p))
1000   "*If non-nil, display an arrow highlighting the current article."
1001   :version "22.1"
1002   :group 'gnus-summary
1003   :type 'boolean)
1004
1005 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1006   "Face used for highlighting the current article in the summary buffer."
1007   :group 'gnus-summary-visual
1008   :type 'face)
1009
1010 (defvar gnus-tmp-downloaded nil)
1011
1012 (defcustom gnus-summary-highlight
1013   '(((eq mark gnus-canceled-mark)
1014      . gnus-summary-cancelled)
1015     ((and uncached (> score default-high))
1016      . gnus-summary-high-undownloaded)
1017     ((and uncached (< score default-low))
1018      . gnus-summary-low-undownloaded)
1019     (uncached
1020      . gnus-summary-normal-undownloaded)
1021     ((and (> score default-high)
1022           (or (eq mark gnus-dormant-mark)
1023               (eq mark gnus-ticked-mark)))
1024      . gnus-summary-high-ticked)
1025     ((and (< score default-low)
1026           (or (eq mark gnus-dormant-mark)
1027               (eq mark gnus-ticked-mark)))
1028      . gnus-summary-low-ticked)
1029     ((or (eq mark gnus-dormant-mark)
1030          (eq mark gnus-ticked-mark))
1031      . gnus-summary-normal-ticked)
1032     ((and (> score default-high) (eq mark gnus-ancient-mark))
1033      . gnus-summary-high-ancient)
1034     ((and (< score default-low) (eq mark gnus-ancient-mark))
1035      . gnus-summary-low-ancient)
1036     ((eq mark gnus-ancient-mark)
1037      . gnus-summary-normal-ancient)
1038     ((and (> score default-high) (eq mark gnus-unread-mark))
1039      . gnus-summary-high-unread)
1040     ((and (< score default-low) (eq mark gnus-unread-mark))
1041      . gnus-summary-low-unread)
1042     ((eq mark gnus-unread-mark)
1043      . gnus-summary-normal-unread)
1044     ((> score default-high)
1045      . gnus-summary-high-read)
1046     ((< score default-low)
1047      . gnus-summary-low-read)
1048     (t
1049      . gnus-summary-normal-read))
1050   "*Controls the highlighting of summary buffer lines.
1051
1052 A list of (FORM . FACE) pairs.  When deciding how a a particular
1053 summary line should be displayed, each form is evaluated.  The content
1054 of the face field after the first true form is used.  You can change
1055 how those summary lines are displayed, by editing the face field.
1056
1057 You can use the following variables in the FORM field.
1058
1059 score:        The article's score
1060 default:      The default article score.
1061 default-high: The default score for high scored articles.
1062 default-low:  The default score for low scored articles.
1063 below:        The score below which articles are automatically marked as read.
1064 mark:         The article's mark.
1065 uncached:     Non-nil if the article is uncached."
1066   :group 'gnus-summary-visual
1067   :type '(repeat (cons (sexp :tag "Form" nil)
1068                        face)))
1069
1070 (defcustom gnus-alter-header-function nil
1071   "Function called to allow alteration of article header structures.
1072 The function is called with one parameter, the article header vector,
1073 which it may alter in any way."
1074   :type '(choice (const :tag "None" nil)
1075                  function)
1076   :group 'gnus-summary)
1077
1078 (defvar gnus-decode-encoded-word-function
1079   (mime-find-field-decoder 'From 'nov)
1080   "Variable that says which function should be used to decode a string with encoded words.")
1081
1082 (defcustom gnus-extra-headers '(To Newsgroups)
1083   "*Extra headers to parse."
1084   :version "21.1"
1085   :group 'gnus-summary
1086   :type '(repeat symbol))
1087
1088 (defcustom gnus-ignored-from-addresses
1089   (and user-mail-address  
1090        (not (string= user-mail-address ""))
1091        (regexp-quote user-mail-address))
1092   "*Regexp of From headers that may be suppressed in favor of To headers."
1093   :version "21.1"
1094   :group 'gnus-summary
1095   :type 'regexp)
1096
1097 (defcustom gnus-summary-to-prefix "-> "
1098   "*String prefixed to the To field in the summary line when
1099 using `gnus-ignored-from-addresses'."
1100   :version "22.1"
1101   :group 'gnus-summary
1102   :type 'string)
1103
1104 (defcustom gnus-summary-newsgroup-prefix "=> "
1105   "*String prefixed to the Newsgroup field in the summary
1106 line when using `gnus-ignored-from-addresses'."
1107   :version "22.1"
1108   :group 'gnus-summary
1109   :type 'string)
1110
1111 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1112   "List of charsets that should be ignored.
1113 When these charsets are used in the \"charset\" parameter, the
1114 default charset will be used instead."
1115   :version "21.1"
1116   :type '(repeat symbol)
1117   :group 'gnus-charset)
1118
1119 (gnus-define-group-parameter
1120  ignored-charsets
1121  :type list
1122  :function-document
1123  "Return the ignored charsets of GROUP."
1124  :variable gnus-group-ignored-charsets-alist
1125  :variable-default
1126  '(("alt\\.chinese\\.text" iso-8859-1))
1127  :variable-document
1128  "Alist of regexps (to match group names) and charsets that should be ignored.
1129 When these charsets are used in the \"charset\" parameter, the
1130 default charset will be used instead."
1131  :variable-group gnus-charset
1132  :variable-type '(repeat (cons (regexp :tag "Group")
1133                                (repeat symbol)))
1134  :parameter-type '(choice :tag "Ignored charsets"
1135                           :value nil
1136                           (repeat (symbol)))
1137  :parameter-document       "\
1138 List of charsets that should be ignored.
1139
1140 When these charsets are used in the \"charset\" parameter, the
1141 default charset will be used instead.")
1142
1143 (defcustom gnus-group-highlight-words-alist nil
1144   "Alist of group regexps and highlight regexps.
1145 This variable uses the same syntax as `gnus-emphasis-alist'."
1146   :version "21.1"
1147   :type '(repeat (cons (regexp :tag "Group")
1148                        (repeat (list (regexp :tag "Highlight regexp")
1149                                      (number :tag "Group for entire word" 0)
1150                                      (number :tag "Group for displayed part" 0)
1151                                      (symbol :tag "Face"
1152                                              gnus-emphasis-highlight-words)))))
1153   :group 'gnus-summary-visual)
1154
1155 (defcustom gnus-use-wheel nil
1156   "Use Intelli-mouse on summary movement"
1157   :type 'boolean
1158   :group 'gnus-summary-maneuvering)
1159
1160 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1161   "Amount to scroll messages by spinning the mouse wheel.
1162 This is actually a cons cell, where the first item is the amount to scroll
1163 on a normal wheel event, and the second is the amount to scroll when the
1164 wheel is moved with the shift key depressed."
1165   :type '(cons (integer :tag "Shift") integer)
1166   :group 'gnus-summary-maneuvering)
1167
1168 (defcustom gnus-wheel-edge-resistance 2
1169   "How hard it should be to change the current article
1170 by moving the mouse over the edge of the article window."
1171   :type 'integer
1172   :group 'gnus-summary-maneuvering)
1173
1174 (defcustom gnus-summary-show-article-charset-alist
1175   nil
1176   "Alist of number and charset.
1177 The article will be shown with the charset corresponding to the
1178 numbered argument.
1179 For example: ((1 . cn-gb-2312) (2 . big5))."
1180   :version "21.1"
1181   :type '(repeat (cons (number :tag "Argument" 1)
1182                        (symbol :tag "Charset")))
1183   :group 'gnus-charset)
1184
1185 (defcustom gnus-preserve-marks t
1186   "Whether marks are preserved when moving, copying and respooling messages."
1187   :version "21.1"
1188   :type 'boolean
1189   :group 'gnus-summary-marks)
1190
1191 (defcustom gnus-alter-articles-to-read-function nil
1192   "Function to be called to alter the list of articles to be selected."
1193   :type '(choice (const nil) function)
1194   :group 'gnus-summary)
1195
1196 (defcustom gnus-orphan-score nil
1197   "*All orphans get this score added.  Set in the score file."
1198   :group 'gnus-score-default
1199   :type '(choice (const nil)
1200                  integer))
1201
1202 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1203   "*A regexp to match MIME parts when saving multiple parts of a
1204 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1205 This regexp will be used by default when prompting the user for which
1206 type of files to save."
1207   :group 'gnus-summary
1208   :type 'regexp)
1209
1210 (defcustom gnus-read-all-available-headers nil
1211   "Whether Gnus should parse all headers made available to it.
1212 This is mostly relevant for slow back ends where the user may
1213 wish to widen the summary buffer to include all headers
1214 that were fetched.  Say, for nnultimate groups."
1215   :version "22.1"
1216   :group 'gnus-summary
1217   :type '(choice boolean regexp))
1218
1219 (defcustom gnus-summary-muttprint-program "muttprint"
1220   "Command (and optional arguments) used to run Muttprint."
1221   :version "22.1"
1222   :group 'gnus-summary
1223   :type 'string)
1224
1225 (defcustom gnus-article-loose-mime t
1226   "If non-nil, don't require MIME-Version header.
1227 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1228 supply the MIME-Version header or deliberately strip it from the mail.
1229 If non-nil (the default), Gnus will treat some articles as MIME
1230 even if the MIME-Version header is missing."
1231   :version "22.1"
1232   :type 'boolean
1233   :group 'gnus-article-mime)
1234
1235 (defcustom gnus-article-emulate-mime t
1236   "If non-nil, use MIME emulation for uuencode and the like.
1237 This means that Gnus will search message bodies for text that look
1238 like uuencoded bits, yEncoded bits, and so on, and present that using
1239 the normal Gnus MIME machinery."
1240   :version "22.1"
1241   :type 'boolean
1242   :group 'gnus-article-mime)
1243
1244 ;;; Internal variables
1245
1246 (defvar gnus-summary-display-cache nil)
1247 (defvar gnus-article-mime-handles nil)
1248 (defvar gnus-article-decoded-p nil)
1249 (defvar gnus-article-charset nil)
1250 (defvar gnus-article-ignored-charsets nil)
1251 (defvar gnus-scores-exclude-files nil)
1252 (defvar gnus-page-broken nil)
1253
1254 (defvar gnus-original-article nil)
1255 (defvar gnus-article-internal-prepare-hook nil)
1256 (defvar gnus-newsgroup-process-stack nil)
1257
1258 (defvar gnus-thread-indent-array nil)
1259 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1260 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1261   "Function called to sort the articles within a thread after it has been gathered together.")
1262
1263 (defvar gnus-summary-save-parts-type-history nil)
1264 (defvar gnus-summary-save-parts-last-directory nil)
1265
1266 ;; Avoid highlighting in kill files.
1267 (defvar gnus-summary-inhibit-highlight nil)
1268 (defvar gnus-newsgroup-selected-overlay nil)
1269 (defvar gnus-inhibit-limiting nil)
1270 (defvar gnus-newsgroup-adaptive-score-file nil)
1271 (defvar gnus-current-score-file nil)
1272 (defvar gnus-current-move-group nil)
1273 (defvar gnus-current-copy-group nil)
1274 (defvar gnus-current-crosspost-group nil)
1275 (defvar gnus-newsgroup-display nil)
1276
1277 (defvar gnus-newsgroup-dependencies nil)
1278 (defvar gnus-newsgroup-adaptive nil)
1279 (defvar gnus-summary-display-article-function nil)
1280 (defvar gnus-summary-highlight-line-function nil
1281   "Function called after highlighting a summary line.")
1282
1283 (defvar gnus-summary-line-format-alist
1284   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1285     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1286     (?s gnus-tmp-subject-or-nil ?s)
1287     (?n gnus-tmp-name ?s)
1288     (?A (std11-address-string
1289          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1290     (?a (or (std11-full-name-string
1291              (car (mime-entity-read-field gnus-tmp-header 'From)))
1292             gnus-tmp-from) ?s)
1293     (?F gnus-tmp-from ?s)
1294     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1295     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1296     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1297     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1298     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1299     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1300     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1301     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1302     (?L gnus-tmp-lines ?s)
1303     (?O gnus-tmp-downloaded ?c)
1304     (?I gnus-tmp-indentation ?s)
1305     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1306     (?R gnus-tmp-replied ?c)
1307     (?\[ gnus-tmp-opening-bracket ?c)
1308     (?\] gnus-tmp-closing-bracket ?c)
1309     (?\> (make-string gnus-tmp-level ? ) ?s)
1310     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1311     (?i gnus-tmp-score ?d)
1312     (?z gnus-tmp-score-char ?c)
1313     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1314     (?U gnus-tmp-unread ?c)
1315     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1316         ?s)
1317     (?t (gnus-summary-number-of-articles-in-thread
1318          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1319         ?d)
1320     (?e (gnus-summary-number-of-articles-in-thread
1321          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1322         ?c)
1323     (?u gnus-tmp-user-defined ?s)
1324     (?P (gnus-pick-line-number) ?d)
1325     (?B gnus-tmp-thread-tree-header-string ?s)
1326     (user-date (gnus-user-date
1327                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1328   "An alist of format specifications that can appear in summary lines.
1329 These are paired with what variables they correspond with, along with
1330 the type of the variable (string, integer, character, etc).")
1331
1332 (defvar gnus-summary-dummy-line-format-alist
1333   `((?S gnus-tmp-subject ?s)
1334     (?N gnus-tmp-number ?d)
1335     (?u gnus-tmp-user-defined ?s)))
1336
1337 (defvar gnus-summary-mode-line-format-alist
1338   `((?G gnus-tmp-group-name ?s)
1339     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1340     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1341     (?A gnus-tmp-article-number ?d)
1342     (?Z gnus-tmp-unread-and-unselected ?s)
1343     (?V gnus-version ?s)
1344     (?U gnus-tmp-unread-and-unticked ?d)
1345     (?S gnus-tmp-subject ?s)
1346     (?e gnus-tmp-unselected ?d)
1347     (?u gnus-tmp-user-defined ?s)
1348     (?d (length gnus-newsgroup-dormant) ?d)
1349     (?t (length gnus-newsgroup-marked) ?d)
1350     (?h (length gnus-newsgroup-spam-marked) ?d)
1351     (?r (length gnus-newsgroup-reads) ?d)
1352     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1353     (?E gnus-newsgroup-expunged-tally ?d)
1354     (?s (gnus-current-score-file-nondirectory) ?s)))
1355
1356 (defvar gnus-last-search-regexp nil
1357   "Default regexp for article search command.")
1358
1359 (defvar gnus-summary-search-article-matched-data nil
1360   "Last matched data of article search command.  It is the local variable
1361 in `gnus-article-buffer' which consists of the list of start position,
1362 end position and text.")
1363
1364 (defvar gnus-last-shell-command nil
1365   "Default shell command on article.")
1366
1367 (defvar gnus-newsgroup-agentized nil
1368   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1369 (defvar gnus-newsgroup-begin nil)
1370 (defvar gnus-newsgroup-end nil)
1371 (defvar gnus-newsgroup-last-rmail nil)
1372 (defvar gnus-newsgroup-last-mail nil)
1373 (defvar gnus-newsgroup-last-folder nil)
1374 (defvar gnus-newsgroup-last-file nil)
1375 (defvar gnus-newsgroup-auto-expire nil)
1376 (defvar gnus-newsgroup-active nil)
1377
1378 (defvar gnus-newsgroup-data nil)
1379 (defvar gnus-newsgroup-data-reverse nil)
1380 (defvar gnus-newsgroup-limit nil)
1381 (defvar gnus-newsgroup-limits nil)
1382 (defvar gnus-summary-use-undownloaded-faces nil)
1383
1384 (defvar gnus-newsgroup-unreads nil
1385   "Sorted list of unread articles in the current newsgroup.")
1386
1387 (defvar gnus-newsgroup-unselected nil
1388   "Sorted list of unselected unread articles in the current newsgroup.")
1389
1390 (defvar gnus-newsgroup-reads nil
1391   "Alist of read articles and article marks in the current newsgroup.")
1392
1393 (defvar gnus-newsgroup-expunged-tally nil)
1394
1395 (defvar gnus-newsgroup-marked nil
1396   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1397
1398 (defvar gnus-newsgroup-spam-marked nil
1399   "List of ranges of articles that have been marked as spam.")
1400
1401 (defvar gnus-newsgroup-killed nil
1402   "List of ranges of articles that have been through the scoring process.")
1403
1404 (defvar gnus-newsgroup-cached nil
1405   "Sorted list of articles that come from the article cache.")
1406
1407 (defvar gnus-newsgroup-saved nil
1408   "List of articles that have been saved.")
1409
1410 (defvar gnus-newsgroup-kill-headers nil)
1411
1412 (defvar gnus-newsgroup-replied nil
1413   "List of articles that have been replied to in the current newsgroup.")
1414
1415 (defvar gnus-newsgroup-forwarded nil
1416   "List of articles that have been forwarded in the current newsgroup.")
1417
1418 (defvar gnus-newsgroup-recent nil
1419   "List of articles that have are recent in the current newsgroup.")
1420
1421 (defvar gnus-newsgroup-expirable nil
1422   "Sorted list of articles in the current newsgroup that can be expired.")
1423
1424 (defvar gnus-newsgroup-processable nil
1425   "List of articles in the current newsgroup that can be processed.")
1426
1427 (defvar gnus-newsgroup-downloadable nil
1428   "Sorted list of articles in the current newsgroup that can be processed.")
1429
1430 (defvar gnus-newsgroup-unfetched nil
1431   "Sorted list of articles in the current newsgroup whose headers have
1432 not been fetched into the agent.
1433
1434 This list will always be a subset of gnus-newsgroup-undownloaded.")
1435
1436 (defvar gnus-newsgroup-undownloaded nil
1437   "List of articles in the current newsgroup that haven't been downloaded.")
1438
1439 (defvar gnus-newsgroup-unsendable nil
1440   "List of articles in the current newsgroup that won't be sent.")
1441
1442 (defvar gnus-newsgroup-bookmarks nil
1443   "List of articles in the current newsgroup that have bookmarks.")
1444
1445 (defvar gnus-newsgroup-dormant nil
1446   "Sorted list of dormant articles in the current newsgroup.")
1447
1448 (defvar gnus-newsgroup-unseen nil
1449   "List of unseen articles in the current newsgroup.")
1450
1451 (defvar gnus-newsgroup-seen nil
1452   "Range of seen articles in the current newsgroup.")
1453
1454 (defvar gnus-newsgroup-articles nil
1455   "List of articles in the current newsgroup.")
1456
1457 (defvar gnus-newsgroup-scored nil
1458   "List of scored articles in the current newsgroup.")
1459
1460 (defvar gnus-newsgroup-incorporated nil
1461   "List of incorporated articles in the current newsgroup.")
1462
1463 (defvar gnus-newsgroup-headers nil
1464   "List of article headers in the current newsgroup.")
1465
1466 (defvar gnus-newsgroup-threads nil)
1467
1468 (defvar gnus-newsgroup-prepared nil
1469   "Whether the current group has been prepared properly.")
1470
1471 (defvar gnus-newsgroup-ancient nil
1472   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1473
1474 (defvar gnus-newsgroup-sparse nil)
1475
1476 (defvar gnus-current-article nil)
1477 (defvar gnus-article-current nil)
1478 (defvar gnus-current-headers nil)
1479 (defvar gnus-have-all-headers nil)
1480 (defvar gnus-last-article nil)
1481 (defvar gnus-newsgroup-history nil)
1482 (defvar gnus-newsgroup-charset nil)
1483 (defvar gnus-newsgroup-ephemeral-charset nil)
1484 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1485
1486 (defvar gnus-article-before-search nil)
1487
1488 (defvar gnus-summary-local-variables
1489   '(gnus-newsgroup-name
1490     gnus-newsgroup-begin gnus-newsgroup-end
1491     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1492     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1493     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1494     gnus-newsgroup-unselected gnus-newsgroup-marked
1495     gnus-newsgroup-spam-marked
1496     gnus-newsgroup-reads gnus-newsgroup-saved
1497     gnus-newsgroup-replied gnus-newsgroup-forwarded
1498     gnus-newsgroup-recent
1499     gnus-newsgroup-expirable
1500     gnus-newsgroup-processable gnus-newsgroup-killed
1501     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1502     gnus-newsgroup-unfetched
1503     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1504     gnus-newsgroup-seen gnus-newsgroup-articles
1505     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1506     gnus-newsgroup-headers gnus-newsgroup-threads
1507     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1508     gnus-current-article gnus-current-headers gnus-have-all-headers
1509     gnus-last-article gnus-article-internal-prepare-hook
1510     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1511     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1512     gnus-thread-expunge-below
1513     gnus-score-alist gnus-current-score-file
1514     (gnus-summary-expunge-below . global)
1515     (gnus-summary-mark-below . global)
1516     (gnus-orphan-score . global)
1517     gnus-newsgroup-active gnus-scores-exclude-files
1518     gnus-newsgroup-history gnus-newsgroup-ancient
1519     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1520     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1521     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1522     (gnus-newsgroup-expunged-tally . 0)
1523     gnus-cache-removable-articles gnus-newsgroup-cached
1524     gnus-newsgroup-data gnus-newsgroup-data-reverse
1525     gnus-newsgroup-limit gnus-newsgroup-limits
1526     gnus-newsgroup-charset gnus-newsgroup-display
1527     gnus-summary-use-undownloaded-faces
1528     gnus-newsgroup-incorporated)
1529   "Variables that are buffer-local to the summary buffers.")
1530
1531 (defvar gnus-newsgroup-variables nil
1532   "A list of variables that have separate values in different newsgroups.
1533 A list of newsgroup (summary buffer) local variables, or cons of
1534 variables and their default expressions to be evalled (when the default
1535 values are not nil), that should be made global while the summary buffer
1536 is active.
1537
1538 Note: The default expressions will be evaluated (using function `eval')
1539 before assignment to the local variable rather than just assigned to it.
1540 If the default expression is the symbol `global', that symbol will not
1541 be evaluated but the global value of the local variable will be used
1542 instead.
1543
1544 These variables can be used to set variables in the group parameters
1545 while still allowing them to affect operations done in other buffers.
1546 For example:
1547
1548 \(setq gnus-newsgroup-variables
1549      '(message-use-followup-to
1550        (gnus-visible-headers .
1551          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1552 ")
1553
1554 ;; Byte-compiler warning.
1555 (eval-when-compile
1556   ;; Bind features so that require will believe that gnus-sum has
1557   ;; already been loaded (avoids infinite recursion)
1558   (let ((features (cons 'gnus-sum features)))
1559     ;; Several of the declarations in gnus-sum are needed to load the
1560     ;; following files. Right now, these definitions have been
1561     ;; compiled but not defined (evaluated).  We could either do a
1562     ;; eval-and-compile about all of the declarations or evaluate the
1563     ;; source file.
1564     (if (boundp 'gnus-newsgroup-variables)
1565         nil
1566       (load "gnus-sum.el" t t t))
1567     (require 'gnus)
1568     (require 'gnus-art)))
1569
1570 ;; Subject simplification.
1571
1572 (defun gnus-simplify-whitespace (str)
1573   "Remove excessive whitespace from STR."
1574   ;; Multiple spaces.
1575   (while (string-match "[ \t][ \t]+" str)
1576     (setq str (concat (substring str 0 (match-beginning 0))
1577                         " "
1578                         (substring str (match-end 0)))))
1579   ;; Leading spaces.
1580   (when (string-match "^[ \t]+" str)
1581     (setq str (substring str (match-end 0))))
1582   ;; Trailing spaces.
1583   (when (string-match "[ \t]+$" str)
1584     (setq str (substring str 0 (match-beginning 0))))
1585   str)
1586
1587 (defun gnus-simplify-all-whitespace (str)
1588   "Remove all whitespace from STR."
1589   (while (string-match "[ \t\n]+" str)
1590     (setq str (replace-match "" nil nil str)))
1591   str)
1592
1593 (defsubst gnus-simplify-subject-re (subject)
1594   "Remove \"Re:\" from subject lines."
1595   (if (string-match message-subject-re-regexp subject)
1596       (substring subject (match-end 0))
1597     subject))
1598
1599 (defun gnus-simplify-subject (subject &optional re-only)
1600   "Remove `Re:' and words in parentheses.
1601 If RE-ONLY is non-nil, strip leading `Re:'s only."
1602   (let ((case-fold-search t))           ;Ignore case.
1603     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1604     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1605       (setq subject (substring subject (match-end 0))))
1606     ;; Remove uninteresting prefixes.
1607     (when (and (not re-only)
1608                gnus-simplify-ignored-prefixes
1609                (string-match gnus-simplify-ignored-prefixes subject))
1610       (setq subject (substring subject (match-end 0))))
1611     ;; Remove words in parentheses from end.
1612     (unless re-only
1613       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1614         (setq subject (substring subject 0 (match-beginning 0)))))
1615     ;; Return subject string.
1616     subject))
1617
1618 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1619 ;; all whitespace.
1620 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1621   (goto-char (point-min))
1622   (while (re-search-forward regexp nil t)
1623     (replace-match (or newtext ""))))
1624
1625 (defun gnus-simplify-buffer-fuzzy ()
1626   "Simplify string in the buffer fuzzily.
1627 The string in the accessible portion of the current buffer is simplified.
1628 It is assumed to be a single-line subject.
1629 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1630 matter is removed.  Additional things can be deleted by setting
1631 `gnus-simplify-subject-fuzzy-regexp'."
1632   (let ((case-fold-search t)
1633         (modified-tick))
1634     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1635
1636     (while (not (eq modified-tick (buffer-modified-tick)))
1637       (setq modified-tick (buffer-modified-tick))
1638       (cond
1639        ((listp gnus-simplify-subject-fuzzy-regexp)
1640         (mapcar 'gnus-simplify-buffer-fuzzy-step
1641                 gnus-simplify-subject-fuzzy-regexp))
1642        (gnus-simplify-subject-fuzzy-regexp
1643         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1644       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1645       (gnus-simplify-buffer-fuzzy-step
1646        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1647       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1648
1649     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1650     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1651     (gnus-simplify-buffer-fuzzy-step " $")
1652     (gnus-simplify-buffer-fuzzy-step "^ +")))
1653
1654 (defun gnus-simplify-subject-fuzzy (subject)
1655   "Simplify a subject string fuzzily.
1656 See `gnus-simplify-buffer-fuzzy' for details."
1657   (save-excursion
1658     (gnus-set-work-buffer)
1659     (let ((case-fold-search t))
1660       ;; Remove uninteresting prefixes.
1661       (when (and gnus-simplify-ignored-prefixes
1662                  (string-match gnus-simplify-ignored-prefixes subject))
1663         (setq subject (substring subject (match-end 0))))
1664       (insert subject)
1665       (inline (gnus-simplify-buffer-fuzzy))
1666       (buffer-string))))
1667
1668 (defsubst gnus-simplify-subject-fully (subject)
1669   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1670   (cond
1671    (gnus-simplify-subject-functions
1672     (gnus-map-function gnus-simplify-subject-functions subject))
1673    ((null gnus-summary-gather-subject-limit)
1674     (gnus-simplify-subject-re subject))
1675    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1676     (gnus-simplify-subject-fuzzy subject))
1677    ((numberp gnus-summary-gather-subject-limit)
1678     (gnus-limit-string (gnus-simplify-subject-re subject)
1679                        gnus-summary-gather-subject-limit))
1680    (t
1681     subject)))
1682
1683 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1684   "Check whether two subjects are equal.
1685 If optional argument SIMPLE-FIRST is t, first argument is already
1686 simplified."
1687   (cond
1688    ((null simple-first)
1689     (equal (gnus-simplify-subject-fully s1)
1690            (gnus-simplify-subject-fully s2)))
1691    (t
1692     (equal s1
1693            (gnus-simplify-subject-fully s2)))))
1694
1695 (defun gnus-summary-bubble-group ()
1696   "Increase the score of the current group.
1697 This is a handy function to add to `gnus-summary-exit-hook' to
1698 increase the score of each group you read."
1699   (gnus-group-add-score gnus-newsgroup-name))
1700
1701 \f
1702 ;;;
1703 ;;; Gnus summary mode
1704 ;;;
1705
1706 (put 'gnus-summary-mode 'mode-class 'special)
1707
1708 (defvar gnus-article-commands-menu)
1709
1710 ;; Non-orthogonal keys
1711
1712 (gnus-define-keys gnus-summary-mode-map
1713   " " gnus-summary-next-page
1714   "\177" gnus-summary-prev-page
1715   [delete] gnus-summary-prev-page
1716   [backspace] gnus-summary-prev-page
1717   "\r" gnus-summary-scroll-up
1718   "\M-\r" gnus-summary-scroll-down
1719   "n" gnus-summary-next-unread-article
1720   "p" gnus-summary-prev-unread-article
1721   "N" gnus-summary-next-article
1722   "P" gnus-summary-prev-article
1723   "\M-\C-n" gnus-summary-next-same-subject
1724   "\M-\C-p" gnus-summary-prev-same-subject
1725   "\M-n" gnus-summary-next-unread-subject
1726   "\M-p" gnus-summary-prev-unread-subject
1727   "." gnus-summary-first-unread-article
1728   "," gnus-summary-best-unread-article
1729   "\M-s" gnus-summary-search-article-forward
1730   "\M-r" gnus-summary-search-article-backward
1731   "<" gnus-summary-beginning-of-article
1732   ">" gnus-summary-end-of-article
1733   "j" gnus-summary-goto-article
1734   "^" gnus-summary-refer-parent-article
1735   "\M-^" gnus-summary-refer-article
1736   "u" gnus-summary-tick-article-forward
1737   "!" gnus-summary-tick-article-forward
1738   "U" gnus-summary-tick-article-backward
1739   "d" gnus-summary-mark-as-read-forward
1740   "D" gnus-summary-mark-as-read-backward
1741   "E" gnus-summary-mark-as-expirable
1742   "\M-u" gnus-summary-clear-mark-forward
1743   "\M-U" gnus-summary-clear-mark-backward
1744   "k" gnus-summary-kill-same-subject-and-select
1745   "\C-k" gnus-summary-kill-same-subject
1746   "\M-\C-k" gnus-summary-kill-thread
1747   "\M-\C-l" gnus-summary-lower-thread
1748   "e" gnus-summary-edit-article
1749   "#" gnus-summary-mark-as-processable
1750   "\M-#" gnus-summary-unmark-as-processable
1751   "\M-\C-t" gnus-summary-toggle-threads
1752   "\M-\C-s" gnus-summary-show-thread
1753   "\M-\C-h" gnus-summary-hide-thread
1754   "\M-\C-f" gnus-summary-next-thread
1755   "\M-\C-b" gnus-summary-prev-thread
1756   [(meta down)] gnus-summary-next-thread
1757   [(meta up)] gnus-summary-prev-thread
1758   "\M-\C-u" gnus-summary-up-thread
1759   "\M-\C-d" gnus-summary-down-thread
1760   "&" gnus-summary-execute-command
1761   "c" gnus-summary-catchup-and-exit
1762   "\C-w" gnus-summary-mark-region-as-read
1763   "\C-t" gnus-summary-toggle-truncation
1764   "?" gnus-summary-mark-as-dormant
1765   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1766   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1767   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1768   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1769   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1770   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1771   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1772   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1773   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1774   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1775   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1776   "=" gnus-summary-expand-window
1777   "\C-x\C-s" gnus-summary-reselect-current-group
1778   "\M-g" gnus-summary-rescan-group
1779   "w" gnus-summary-stop-page-breaking
1780   "\C-c\C-r" gnus-summary-caesar-message
1781   "\M-t" gnus-summary-toggle-mime
1782   "f" gnus-summary-followup
1783   "F" gnus-summary-followup-with-original
1784   "C" gnus-summary-cancel-article
1785   "r" gnus-summary-reply
1786   "R" gnus-summary-reply-with-original
1787   "\C-c\C-f" gnus-summary-mail-forward
1788   "o" gnus-summary-save-article
1789   "\C-o" gnus-summary-save-article-mail
1790   "|" gnus-summary-pipe-output
1791   "\M-k" gnus-summary-edit-local-kill
1792   "\M-K" gnus-summary-edit-global-kill
1793   ;; "V" gnus-version
1794   "\C-c\C-d" gnus-summary-describe-group
1795   "q" gnus-summary-exit
1796   "Q" gnus-summary-exit-no-update
1797   "\C-c\C-i" gnus-info-find-node
1798   gnus-mouse-2 gnus-mouse-pick-article
1799   [follow-link] mouse-face
1800   "m" gnus-summary-mail-other-window
1801   "a" gnus-summary-post-news
1802   "i" gnus-summary-news-other-window
1803   "x" gnus-summary-limit-to-unread
1804   "s" gnus-summary-isearch-article
1805   "t" gnus-summary-toggle-header
1806   "g" gnus-summary-show-article
1807   "l" gnus-summary-goto-last-article
1808   "v" gnus-summary-preview-mime-message
1809   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1810   "\C-d" gnus-summary-enter-digest-group
1811   "\M-\C-d" gnus-summary-read-document
1812   "\M-\C-e" gnus-summary-edit-parameters
1813   "\M-\C-a" gnus-summary-customize-parameters
1814   "\C-c\C-b" gnus-bug
1815   "\C-c\C-n" gnus-namazu-search
1816   "*" gnus-cache-enter-article
1817   "\M-*" gnus-cache-remove-article
1818   "\M-&" gnus-summary-universal-argument
1819   "\C-l" gnus-recenter
1820   "I" gnus-summary-increase-score
1821   "L" gnus-summary-lower-score
1822   "\M-i" gnus-symbolic-argument
1823   "h" gnus-summary-select-article-buffer
1824
1825   "V" gnus-summary-score-map
1826   "X" gnus-uu-extract-map
1827   "S" gnus-summary-send-map)
1828
1829   ;; Sort of orthogonal keymap
1830 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1831   "t" gnus-summary-tick-article-forward
1832   "!" gnus-summary-tick-article-forward
1833   "d" gnus-summary-mark-as-read-forward
1834   "r" gnus-summary-mark-as-read-forward
1835   "c" gnus-summary-clear-mark-forward
1836   " " gnus-summary-clear-mark-forward
1837   "e" gnus-summary-mark-as-expirable
1838   "x" gnus-summary-mark-as-expirable
1839   "?" gnus-summary-mark-as-dormant
1840   "b" gnus-summary-set-bookmark
1841   "B" gnus-summary-remove-bookmark
1842   "#" gnus-summary-mark-as-processable
1843   "\M-#" gnus-summary-unmark-as-processable
1844   "S" gnus-summary-limit-include-expunged
1845   "C" gnus-summary-catchup
1846   "H" gnus-summary-catchup-to-here
1847   "h" gnus-summary-catchup-from-here
1848   "\C-c" gnus-summary-catchup-all
1849   "k" gnus-summary-kill-same-subject-and-select
1850   "K" gnus-summary-kill-same-subject
1851   "P" gnus-uu-mark-map)
1852
1853 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1854   "c" gnus-summary-clear-above
1855   "u" gnus-summary-tick-above
1856   "m" gnus-summary-mark-above
1857   "k" gnus-summary-kill-below)
1858
1859 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1860   "/" gnus-summary-limit-to-subject
1861   "n" gnus-summary-limit-to-articles
1862   "w" gnus-summary-pop-limit
1863   "s" gnus-summary-limit-to-subject
1864   "a" gnus-summary-limit-to-author
1865   "u" gnus-summary-limit-to-unread
1866   "m" gnus-summary-limit-to-marks
1867   "M" gnus-summary-limit-exclude-marks
1868   "v" gnus-summary-limit-to-score
1869   "*" gnus-summary-limit-include-cached
1870   "D" gnus-summary-limit-include-dormant
1871   "T" gnus-summary-limit-include-thread
1872   "d" gnus-summary-limit-exclude-dormant
1873   "t" gnus-summary-limit-to-age
1874   "." gnus-summary-limit-to-unseen
1875   "x" gnus-summary-limit-to-extra
1876   "p" gnus-summary-limit-to-display-predicate
1877   "E" gnus-summary-limit-include-expunged
1878   "c" gnus-summary-limit-exclude-childless-dormant
1879   "C" gnus-summary-limit-mark-excluded-as-read
1880   "o" gnus-summary-insert-old-articles
1881   "N" gnus-summary-insert-new-articles
1882   "r" gnus-summary-limit-to-replied
1883   "R" gnus-summary-limit-to-recipient)
1884
1885 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1886   "n" gnus-summary-next-unread-article
1887   "p" gnus-summary-prev-unread-article
1888   "N" gnus-summary-next-article
1889   "P" gnus-summary-prev-article
1890   "\C-n" gnus-summary-next-same-subject
1891   "\C-p" gnus-summary-prev-same-subject
1892   "\M-n" gnus-summary-next-unread-subject
1893   "\M-p" gnus-summary-prev-unread-subject
1894   "f" gnus-summary-first-unread-article
1895   "b" gnus-summary-best-unread-article
1896   "j" gnus-summary-goto-article
1897   "g" gnus-summary-goto-subject
1898   "l" gnus-summary-goto-last-article
1899   "o" gnus-summary-pop-article)
1900
1901 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1902   "k" gnus-summary-kill-thread
1903   "l" gnus-summary-lower-thread
1904   "i" gnus-summary-raise-thread
1905   "T" gnus-summary-toggle-threads
1906   "t" gnus-summary-rethread-current
1907   "^" gnus-summary-reparent-thread
1908   "s" gnus-summary-show-thread
1909   "S" gnus-summary-show-all-threads
1910   "h" gnus-summary-hide-thread
1911   "H" gnus-summary-hide-all-threads
1912   "n" gnus-summary-next-thread
1913   "p" gnus-summary-prev-thread
1914   "u" gnus-summary-up-thread
1915   "o" gnus-summary-top-thread
1916   "d" gnus-summary-down-thread
1917   "#" gnus-uu-mark-thread
1918   "\M-#" gnus-uu-unmark-thread)
1919
1920 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1921   "g" gnus-summary-prepare
1922   "c" gnus-summary-insert-cached-articles
1923   "d" gnus-summary-insert-dormant-articles)
1924
1925 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1926   "c" gnus-summary-catchup-and-exit
1927   "C" gnus-summary-catchup-all-and-exit
1928   "E" gnus-summary-exit-no-update
1929   "J" gnus-summary-jump-to-other-group
1930   "Q" gnus-summary-exit
1931   "Z" gnus-summary-exit
1932   "n" gnus-summary-catchup-and-goto-next-group
1933   "p" gnus-summary-catchup-and-goto-prev-group
1934   "R" gnus-summary-reselect-current-group
1935   "G" gnus-summary-rescan-group
1936   "N" gnus-summary-next-group
1937   "s" gnus-summary-save-newsrc
1938   "P" gnus-summary-prev-group)
1939
1940 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1941   " " gnus-summary-next-page
1942   "n" gnus-summary-next-page
1943   "\177" gnus-summary-prev-page
1944   [delete] gnus-summary-prev-page
1945   "p" gnus-summary-prev-page
1946   "\r" gnus-summary-scroll-up
1947   "\M-\r" gnus-summary-scroll-down
1948   "<" gnus-summary-beginning-of-article
1949   ">" gnus-summary-end-of-article
1950   "b" gnus-summary-beginning-of-article
1951   "e" gnus-summary-end-of-article
1952   "^" gnus-summary-refer-parent-article
1953   "r" gnus-summary-refer-parent-article
1954   "D" gnus-summary-enter-digest-group
1955   "R" gnus-summary-refer-references
1956   "T" gnus-summary-refer-thread
1957   "g" gnus-summary-show-article
1958   "s" gnus-summary-isearch-article
1959   "P" gnus-summary-print-article
1960   "M" gnus-mailing-list-insinuate
1961   "t" gnus-article-babel)
1962
1963 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1964   "b" gnus-article-add-buttons
1965   "B" gnus-article-add-buttons-to-head
1966   "o" gnus-article-treat-overstrike
1967   "e" gnus-article-emphasize
1968   "w" gnus-article-fill-cited-article
1969   "Q" gnus-article-fill-long-lines
1970   "C" gnus-article-capitalize-sentences
1971   "c" gnus-article-remove-cr
1972   "Z" gnus-article-decode-HZ
1973   "A" gnus-article-treat-ansi-sequences
1974   "h" gnus-article-wash-html
1975   "u" gnus-article-unsplit-urls
1976   "f" gnus-article-display-x-face
1977   "l" gnus-summary-stop-page-breaking
1978   "r" gnus-summary-caesar-message
1979   "m" gnus-summary-morse-message
1980   "t" gnus-summary-toggle-header
1981   "g" gnus-treat-smiley
1982   "v" gnus-summary-verbose-headers
1983   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1984   "p" gnus-article-verify-x-pgp-sig
1985   "d" gnus-article-treat-dumbquotes
1986   "i" gnus-summary-idna-message)
1987
1988 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1989   ;; mnemonic: deuglif*Y*
1990   "u" gnus-article-outlook-unwrap-lines
1991   "a" gnus-article-outlook-repair-attribution
1992   "c" gnus-article-outlook-rearrange-citation
1993   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1994
1995 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1996   "a" gnus-article-hide
1997   "h" gnus-article-hide-headers
1998   "b" gnus-article-hide-boring-headers
1999   "s" gnus-article-hide-signature
2000   "c" gnus-article-hide-citation
2001   "C" gnus-article-hide-citation-in-followups
2002   "l" gnus-article-hide-list-identifiers
2003   "B" gnus-article-strip-banner
2004   "P" gnus-article-hide-pem
2005   "\C-c" gnus-article-hide-citation-maybe)
2006
2007 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2008   "a" gnus-article-highlight
2009   "h" gnus-article-highlight-headers
2010   "c" gnus-article-highlight-citation
2011   "s" gnus-article-highlight-signature)
2012
2013 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2014   "f" gnus-article-treat-fold-headers
2015   "u" gnus-article-treat-unfold-headers
2016   "n" gnus-article-treat-fold-newsgroups)
2017
2018 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2019   "x" gnus-article-display-x-face
2020   "d" gnus-article-display-face
2021   "s" gnus-treat-smiley
2022   "D" gnus-article-remove-images
2023   "f" gnus-treat-from-picon
2024   "m" gnus-treat-mail-picon
2025   "n" gnus-treat-newsgroups-picon)
2026
2027 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2028   "z" gnus-article-date-ut
2029   "u" gnus-article-date-ut
2030   "l" gnus-article-date-local
2031   "p" gnus-article-date-english
2032   "e" gnus-article-date-lapsed
2033   "o" gnus-article-date-original
2034   "i" gnus-article-date-iso8601
2035   "s" gnus-article-date-user)
2036
2037 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2038   "t" gnus-article-remove-trailing-blank-lines
2039   "l" gnus-article-strip-leading-blank-lines
2040   "m" gnus-article-strip-multiple-blank-lines
2041   "a" gnus-article-strip-blank-lines
2042   "A" gnus-article-strip-all-blank-lines
2043   "s" gnus-article-strip-leading-space
2044   "e" gnus-article-strip-trailing-space
2045   "w" gnus-article-remove-leading-whitespace)
2046
2047 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2048   "v" gnus-version
2049   "f" gnus-summary-fetch-faq
2050   "d" gnus-summary-describe-group
2051   "h" gnus-summary-describe-briefly
2052   "i" gnus-info-find-node
2053   "c" gnus-group-fetch-charter
2054   "C" gnus-group-fetch-control)
2055
2056 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2057   "e" gnus-summary-expire-articles
2058   "\M-\C-e" gnus-summary-expire-articles-now
2059   "\177" gnus-summary-delete-article
2060   [delete] gnus-summary-delete-article
2061   [backspace] gnus-summary-delete-article
2062   "m" gnus-summary-move-article
2063   "r" gnus-summary-respool-article
2064   "w" gnus-summary-edit-article
2065   "c" gnus-summary-copy-article
2066   "B" gnus-summary-crosspost-article
2067   "q" gnus-summary-respool-query
2068   "t" gnus-summary-respool-trace
2069   "i" gnus-summary-import-article
2070   "I" gnus-summary-create-article
2071   "p" gnus-summary-article-posted-p)
2072
2073 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2074   "o" gnus-summary-save-article
2075   "m" gnus-summary-save-article-mail
2076   "F" gnus-summary-write-article-file
2077   "r" gnus-summary-save-article-rmail
2078   "f" gnus-summary-save-article-file
2079   "b" gnus-summary-save-article-body-file
2080   "h" gnus-summary-save-article-folder
2081   "v" gnus-summary-save-article-vm
2082   "p" gnus-summary-pipe-output
2083   "P" gnus-summary-muttprint
2084   "s" gnus-soup-add-article)
2085
2086 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2087   "b" gnus-summary-display-buttonized
2088   "m" gnus-summary-repair-multipart
2089   "v" gnus-article-view-part
2090   "o" gnus-article-save-part
2091   "O" gnus-article-save-part-and-strip
2092   "r" gnus-article-replace-part
2093   "d" gnus-article-delete-part
2094   "j" gnus-article-jump-to-part
2095   "c" gnus-article-copy-part
2096   "C" gnus-article-view-part-as-charset
2097   "e" gnus-article-view-part-externally
2098   "E" gnus-article-encrypt-body
2099   "i" gnus-article-inline-part
2100   "|" gnus-article-pipe-part)
2101
2102 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2103   "p" gnus-summary-mark-as-processable
2104   "u" gnus-summary-unmark-as-processable
2105   "U" gnus-summary-unmark-all-processable
2106   "v" gnus-uu-mark-over
2107   "s" gnus-uu-mark-series
2108   "r" gnus-uu-mark-region
2109   "g" gnus-uu-unmark-region
2110   "R" gnus-uu-mark-by-regexp
2111   "G" gnus-uu-unmark-by-regexp
2112   "t" gnus-uu-mark-thread
2113   "T" gnus-uu-unmark-thread
2114   "a" gnus-uu-mark-all
2115   "b" gnus-uu-mark-buffer
2116   "S" gnus-uu-mark-sparse
2117   "k" gnus-summary-kill-process-mark
2118   "y" gnus-summary-yank-process-mark
2119   "w" gnus-summary-save-process-mark
2120   "i" gnus-uu-invert-processable)
2121
2122 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2123   ;;"x" gnus-uu-extract-any
2124   "m" gnus-summary-save-parts
2125   "u" gnus-uu-decode-uu
2126   "U" gnus-uu-decode-uu-and-save
2127   "s" gnus-uu-decode-unshar
2128   "S" gnus-uu-decode-unshar-and-save
2129   "o" gnus-uu-decode-save
2130   "O" gnus-uu-decode-save
2131   "b" gnus-uu-decode-binhex
2132   "B" gnus-uu-decode-binhex
2133   "p" gnus-uu-decode-postscript
2134   "P" gnus-uu-decode-postscript-and-save)
2135
2136 (gnus-define-keys
2137     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2138   "u" gnus-uu-decode-uu-view
2139   "U" gnus-uu-decode-uu-and-save-view
2140   "s" gnus-uu-decode-unshar-view
2141   "S" gnus-uu-decode-unshar-and-save-view
2142   "o" gnus-uu-decode-save-view
2143   "O" gnus-uu-decode-save-view
2144   "b" gnus-uu-decode-binhex-view
2145   "B" gnus-uu-decode-binhex-view
2146   "p" gnus-uu-decode-postscript-view
2147   "P" gnus-uu-decode-postscript-and-save-view)
2148
2149 (defvar gnus-article-post-menu nil)
2150
2151 (defconst gnus-summary-menu-maxlen 20)
2152
2153 (defun gnus-summary-menu-split (menu)
2154   ;; If we have lots of elements, divide them into groups of 20
2155   ;; and make a pane (or submenu) for each one.
2156   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2157       (let ((menu menu) sublists next
2158             (i 1))
2159         (while menu
2160           ;; Pull off the next gnus-summary-menu-maxlen elements
2161           ;; and make them the next element of sublist.
2162           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2163           (if next
2164               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2165                       nil))
2166           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2167                                              (aref (car (last menu)) 0)) menu)
2168                                sublists))
2169           (setq i (1+ i))
2170           (setq menu next))
2171         (nreverse sublists))
2172     ;; Few elements--put them all in one pane.
2173     menu))
2174
2175 (defun gnus-summary-make-menu-bar ()
2176   (gnus-turn-off-edit-menu 'summary)
2177
2178   (unless (boundp 'gnus-summary-misc-menu)
2179
2180     (easy-menu-define
2181       gnus-summary-kill-menu gnus-summary-mode-map ""
2182       (cons
2183        "Score"
2184        (nconc
2185         (list
2186          ["Customize" gnus-score-customize t])
2187         (gnus-make-score-map 'increase)
2188         (gnus-make-score-map 'lower)
2189         '(("Mark"
2190            ["Kill below" gnus-summary-kill-below t]
2191            ["Mark above" gnus-summary-mark-above t]
2192            ["Tick above" gnus-summary-tick-above t]
2193            ["Clear above" gnus-summary-clear-above t])
2194           ["Current score" gnus-summary-current-score t]
2195           ["Set score" gnus-summary-set-score t]
2196           ["Switch current score file..." gnus-score-change-score-file t]
2197           ["Set mark below..." gnus-score-set-mark-below t]
2198           ["Set expunge below..." gnus-score-set-expunge-below t]
2199           ["Edit current score file" gnus-score-edit-current-scores t]
2200           ["Edit score file" gnus-score-edit-file t]
2201           ["Trace score" gnus-score-find-trace t]
2202           ["Find words" gnus-score-find-favourite-words t]
2203           ["Rescore buffer" gnus-summary-rescore t]
2204           ["Increase score..." gnus-summary-increase-score t]
2205           ["Lower score..." gnus-summary-lower-score t]))))
2206
2207     ;; Define both the Article menu in the summary buffer and the
2208     ;; equivalent Commands menu in the article buffer here for
2209     ;; consistency.
2210     (let ((innards
2211            `(("Hide"
2212               ["All" gnus-article-hide t]
2213               ["Headers" gnus-article-hide-headers t]
2214               ["Signature" gnus-article-hide-signature t]
2215               ["Citation" gnus-article-hide-citation t]
2216               ["List identifiers" gnus-article-hide-list-identifiers t]
2217               ["Banner" gnus-article-strip-banner t]
2218               ["Boring headers" gnus-article-hide-boring-headers t])
2219              ("Highlight"
2220               ["All" gnus-article-highlight t]
2221               ["Headers" gnus-article-highlight-headers t]
2222               ["Signature" gnus-article-highlight-signature t]
2223               ["Citation" gnus-article-highlight-citation t])
2224              ("Date"
2225               ["Local" gnus-article-date-local t]
2226               ["ISO8601" gnus-article-date-iso8601 t]
2227               ["UT" gnus-article-date-ut t]
2228               ["Original" gnus-article-date-original t]
2229               ["Lapsed" gnus-article-date-lapsed t]
2230               ["User-defined" gnus-article-date-user t])
2231              ("Display"
2232               ["Remove images" gnus-article-remove-images t]
2233               ["Toggle smiley" gnus-treat-smiley t]
2234               ["Show X-Face" gnus-article-display-x-face t]
2235               ["Show picons in From" gnus-treat-from-picon t]
2236               ["Show picons in mail headers" gnus-treat-mail-picon t]
2237               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2238               ("View as different encoding"
2239                ,@(gnus-summary-menu-split
2240                   (mapcar
2241                    (lambda (cs)
2242                      ;; Since easymenu under Emacs doesn't allow
2243                      ;; lambda forms for menu commands, we should
2244                      ;; provide intern'ed function symbols.
2245                      (let ((command (intern (format "\
2246 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2247                        (fset command
2248                              `(lambda ()
2249                                 (interactive)
2250                                 (let ((gnus-summary-show-article-charset-alist
2251                                        '((1 . ,cs))))
2252                                   (gnus-summary-show-article 1))))
2253                        `[,(symbol-name cs) ,command t]))
2254                    (sort (if (fboundp 'coding-system-list)
2255                              (coding-system-list)
2256                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2257                            )
2258                          'string<)))))
2259              ("Washing"
2260               ("Remove Blanks"
2261                ["Leading" gnus-article-strip-leading-blank-lines t]
2262                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2263                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2264                ["All of the above" gnus-article-strip-blank-lines t]
2265                ["All" gnus-article-strip-all-blank-lines t]
2266                ["Leading space" gnus-article-strip-leading-space t]
2267                ["Trailing space" gnus-article-strip-trailing-space t]
2268                ["Leading space in headers"
2269                 gnus-article-remove-leading-whitespace t])
2270               ["Overstrike" gnus-article-treat-overstrike t]
2271               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2272               ["Emphasis" gnus-article-emphasize t]
2273               ["Word wrap" gnus-article-fill-cited-article t]
2274               ["Fill long lines" gnus-article-fill-long-lines t]
2275               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2276               ["Remove CR" gnus-article-remove-cr t]
2277               ["Rot 13" gnus-summary-caesar-message
2278                ,@(if (featurep 'xemacs) '(t)
2279                    '(:help "\"Caesar rotate\" article by 13"))]
2280               ["De-IDNA" gnus-summary-idna-message t]
2281               ["Morse decode" gnus-summary-morse-message t]
2282               ["Unix pipe..." gnus-summary-pipe-message t]
2283               ["Add buttons" gnus-article-add-buttons t]
2284               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2285               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2286               ["Toggle MIME" gnus-summary-toggle-mime t]
2287               ["Verbose header" gnus-summary-verbose-headers t]
2288               ["Toggle header" gnus-summary-toggle-header t]
2289               ["Unfold headers" gnus-article-treat-unfold-headers t]
2290               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2291               ["Html" gnus-article-wash-html t]
2292               ["Unsplit URLs" gnus-article-unsplit-urls t]
2293               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2294               ["Decode HZ" gnus-article-decode-HZ t]
2295               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2296               ("(Outlook) Deuglify"
2297                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2298                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2299                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2300                ["Full (Outlook) deuglify"
2301                 gnus-article-outlook-deuglify-article t])
2302               )
2303              ("Output"
2304               ["Save in default format..." gnus-summary-save-article
2305                ,@(if (featurep 'xemacs) '(t)
2306                    '(:help "Save article using default method"))]
2307               ["Save in file..." gnus-summary-save-article-file
2308                ,@(if (featurep 'xemacs) '(t)
2309                    '(:help "Save article in file"))]
2310               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2311               ["Save in MH folder..." gnus-summary-save-article-folder t]
2312               ["Save in VM folder..." gnus-summary-save-article-vm t]
2313               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2314               ["Save body in file..." gnus-summary-save-article-body-file t]
2315               ["Pipe through a filter..." gnus-summary-pipe-output t]
2316               ["Add to SOUP packet" gnus-soup-add-article t]
2317               ["Print with Muttprint..." gnus-summary-muttprint t]
2318               ["Print" gnus-summary-print-article
2319                ,@(if (featurep 'xemacs) '(t)
2320                    '(:help "Generate and print a PostScript image"))])
2321              ("Copy, move,... (Backend)"
2322               ,@(if (featurep 'xemacs) nil
2323                   '(:help "Copying, moving, expiring articles..."))
2324               ["Respool article..." gnus-summary-respool-article t]
2325               ["Move article..." gnus-summary-move-article
2326                (gnus-check-backend-function
2327                 'request-move-article gnus-newsgroup-name)]
2328               ["Copy article..." gnus-summary-copy-article t]
2329               ["Crosspost article..." gnus-summary-crosspost-article
2330                (gnus-check-backend-function
2331                 'request-replace-article gnus-newsgroup-name)]
2332               ["Import file..." gnus-summary-import-article
2333                (gnus-check-backend-function
2334                 'request-accept-article gnus-newsgroup-name)]
2335               ["Create article..." gnus-summary-create-article
2336                (gnus-check-backend-function
2337                 'request-accept-article gnus-newsgroup-name)]
2338               ["Check if posted" gnus-summary-article-posted-p t]
2339               ["Edit article" gnus-summary-edit-article
2340                (not (gnus-group-read-only-p))]
2341               ["Delete article" gnus-summary-delete-article
2342                (gnus-check-backend-function
2343                 'request-expire-articles gnus-newsgroup-name)]
2344               ["Query respool" gnus-summary-respool-query t]
2345               ["Trace respool" gnus-summary-respool-trace t]
2346               ["Delete expirable articles" gnus-summary-expire-articles-now
2347                (gnus-check-backend-function
2348                 'request-expire-articles gnus-newsgroup-name)])
2349              ("Extract"
2350               ["Uudecode" gnus-uu-decode-uu
2351                ,@(if (featurep 'xemacs) '(t)
2352                    '(:help "Decode uuencoded article(s)"))]
2353               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2354               ["Unshar" gnus-uu-decode-unshar t]
2355               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2356               ["Save" gnus-uu-decode-save t]
2357               ["Binhex" gnus-uu-decode-binhex t]
2358               ["Postscript" gnus-uu-decode-postscript t])
2359              ("Cache"
2360               ["Enter article" gnus-cache-enter-article t]
2361               ["Remove article" gnus-cache-remove-article t])
2362              ["Translate" gnus-article-babel t]
2363              ["Select article buffer" gnus-summary-select-article-buffer t]
2364              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2365              ["Isearch article..." gnus-summary-isearch-article t]
2366              ["Beginning of the article" gnus-summary-beginning-of-article t]
2367              ["End of the article" gnus-summary-end-of-article t]
2368              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2369              ["Fetch referenced articles" gnus-summary-refer-references t]
2370              ["Fetch current thread" gnus-summary-refer-thread t]
2371              ["Fetch article with id..." gnus-summary-refer-article t]
2372              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2373              ["Redisplay" gnus-summary-show-article t]
2374              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2375       (easy-menu-define
2376         gnus-summary-article-menu gnus-summary-mode-map ""
2377         (cons "Article" innards))
2378
2379       (if (not (keymapp gnus-summary-article-menu))
2380           (easy-menu-define
2381             gnus-article-commands-menu gnus-article-mode-map ""
2382             (cons "Commands" innards))
2383         ;; in Emacs, don't share menu.
2384         (setq gnus-article-commands-menu
2385               (copy-keymap gnus-summary-article-menu))
2386         (define-key gnus-article-mode-map [menu-bar commands]
2387           (cons "Commands" gnus-article-commands-menu))))
2388
2389     (easy-menu-define
2390       gnus-summary-thread-menu gnus-summary-mode-map ""
2391       '("Threads"
2392         ["Find all messages in thread" gnus-summary-refer-thread t]
2393         ["Toggle threading" gnus-summary-toggle-threads t]
2394         ["Hide threads" gnus-summary-hide-all-threads t]
2395         ["Show threads" gnus-summary-show-all-threads t]
2396         ["Hide thread" gnus-summary-hide-thread t]
2397         ["Show thread" gnus-summary-show-thread t]
2398         ["Go to next thread" gnus-summary-next-thread t]
2399         ["Go to previous thread" gnus-summary-prev-thread t]
2400         ["Go down thread" gnus-summary-down-thread t]
2401         ["Go up thread" gnus-summary-up-thread t]
2402         ["Top of thread" gnus-summary-top-thread t]
2403         ["Mark thread as read" gnus-summary-kill-thread t]
2404         ["Lower thread score" gnus-summary-lower-thread t]
2405         ["Raise thread score" gnus-summary-raise-thread t]
2406         ["Rethread current" gnus-summary-rethread-current t]))
2407
2408     (easy-menu-define
2409       gnus-summary-post-menu gnus-summary-mode-map ""
2410       `("Post"
2411         ["Send a message (mail or news)" gnus-summary-post-news
2412          ,@(if (featurep 'xemacs) '(t)
2413              '(:help "Compose a new message (mail or news)"))]
2414         ["Followup" gnus-summary-followup
2415          ,@(if (featurep 'xemacs) '(t)
2416              '(:help "Post followup to this article"))]
2417         ["Followup and yank" gnus-summary-followup-with-original
2418          ,@(if (featurep 'xemacs) '(t)
2419              '(:help "Post followup to this article, quoting its contents"))]
2420         ["Supersede article" gnus-summary-supersede-article t]
2421         ["Cancel article" gnus-summary-cancel-article
2422          ,@(if (featurep 'xemacs) '(t)
2423              '(:help "Cancel an article you posted"))]
2424         ["Reply" gnus-summary-reply t]
2425         ["Reply and yank" gnus-summary-reply-with-original t]
2426         ["Wide reply" gnus-summary-wide-reply t]
2427         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2428          ,@(if (featurep 'xemacs) '(t)
2429              '(:help "Mail a reply, quoting this article"))]
2430         ["Very wide reply" gnus-summary-very-wide-reply t]
2431         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2432          ,@(if (featurep 'xemacs) '(t)
2433              '(:help "Mail a very wide reply, quoting this article"))]
2434         ["Mail forward" gnus-summary-mail-forward t]
2435         ["Post forward" gnus-summary-post-forward t]
2436         ["Digest and mail" gnus-summary-digest-mail-forward t]
2437         ["Digest and post" gnus-summary-digest-post-forward t]
2438         ["Resend message" gnus-summary-resend-message t]
2439         ["Resend message edit" gnus-summary-resend-message-edit t]
2440         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2441         ["Send a mail" gnus-summary-mail-other-window t]
2442         ["Create a local message" gnus-summary-news-other-window t]
2443         ["Uuencode and post" gnus-uu-post-news
2444          ,@(if (featurep 'xemacs) '(t)
2445              '(:help "Post a uuencoded article"))]
2446         ["Followup via news" gnus-summary-followup-to-mail t]
2447         ["Followup via news and yank"
2448          gnus-summary-followup-to-mail-with-original t]
2449         ;;("Draft"
2450         ;;["Send" gnus-summary-send-draft t]
2451         ;;["Send bounced" gnus-resend-bounced-mail t])
2452         ))
2453
2454     (cond
2455      ((not (keymapp gnus-summary-post-menu))
2456       (setq gnus-article-post-menu gnus-summary-post-menu))
2457      ((not gnus-article-post-menu)
2458       ;; Don't share post menu.
2459       (setq gnus-article-post-menu
2460             (copy-keymap gnus-summary-post-menu))))
2461     (define-key gnus-article-mode-map [menu-bar post]
2462       (cons "Post" gnus-article-post-menu))
2463
2464     (easy-menu-define
2465       gnus-summary-misc-menu gnus-summary-mode-map ""
2466       `("Gnus"
2467         ("Mark Read"
2468          ["Mark as read" gnus-summary-mark-as-read-forward t]
2469          ["Mark same subject and select"
2470           gnus-summary-kill-same-subject-and-select t]
2471          ["Mark same subject" gnus-summary-kill-same-subject t]
2472          ["Catchup" gnus-summary-catchup
2473           ,@(if (featurep 'xemacs) '(t)
2474               '(:help "Mark unread articles in this group as read"))]
2475          ["Catchup all" gnus-summary-catchup-all t]
2476          ["Catchup to here" gnus-summary-catchup-to-here t]
2477          ["Catchup from here" gnus-summary-catchup-from-here t]
2478          ["Catchup region" gnus-summary-mark-region-as-read
2479           (gnus-mark-active-p)]
2480          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2481         ("Mark Various"
2482          ["Tick" gnus-summary-tick-article-forward t]
2483          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2484          ["Remove marks" gnus-summary-clear-mark-forward t]
2485          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2486          ["Set bookmark" gnus-summary-set-bookmark t]
2487          ["Remove bookmark" gnus-summary-remove-bookmark t])
2488         ("Limit to"
2489          ["Marks..." gnus-summary-limit-to-marks t]
2490          ["Subject..." gnus-summary-limit-to-subject t]
2491          ["Author..." gnus-summary-limit-to-author t]
2492          ["Recipient..." gnus-summary-limit-to-recipient t]
2493          ["Age..." gnus-summary-limit-to-age t]
2494          ["Extra..." gnus-summary-limit-to-extra t]
2495          ["Score..." gnus-summary-limit-to-score t]
2496          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2497          ["Unread" gnus-summary-limit-to-unread t]
2498          ["Unseen" gnus-summary-limit-to-unseen t]
2499          ["Replied" gnus-summary-limit-to-replied t]
2500          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2501          ["Next articles" gnus-summary-limit-to-articles t]
2502          ["Pop limit" gnus-summary-pop-limit t]
2503          ["Show dormant" gnus-summary-limit-include-dormant t]
2504          ["Hide childless dormant"
2505           gnus-summary-limit-exclude-childless-dormant t]
2506          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2507          ["Hide marked" gnus-summary-limit-exclude-marks t]
2508          ["Show expunged" gnus-summary-limit-include-expunged t])
2509         ("Process Mark"
2510          ["Set mark" gnus-summary-mark-as-processable t]
2511          ["Remove mark" gnus-summary-unmark-as-processable t]
2512          ["Remove all marks" gnus-summary-unmark-all-processable t]
2513          ["Invert marks" gnus-uu-invert-processable t]
2514          ["Mark above" gnus-uu-mark-over t]
2515          ["Mark series" gnus-uu-mark-series t]
2516          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2517          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2518          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2519          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2520          ["Mark all" gnus-uu-mark-all t]
2521          ["Mark buffer" gnus-uu-mark-buffer t]
2522          ["Mark sparse" gnus-uu-mark-sparse t]
2523          ["Mark thread" gnus-uu-mark-thread t]
2524          ["Unmark thread" gnus-uu-unmark-thread t]
2525          ("Process Mark Sets"
2526           ["Kill" gnus-summary-kill-process-mark t]
2527           ["Yank" gnus-summary-yank-process-mark
2528            gnus-newsgroup-process-stack]
2529           ["Save" gnus-summary-save-process-mark t]
2530           ["Run command on marked..." gnus-summary-universal-argument t]))
2531         ("Scroll article"
2532          ["Page forward" gnus-summary-next-page
2533           ,@(if (featurep 'xemacs) '(t)
2534               '(:help "Show next page of article"))]
2535          ["Page backward" gnus-summary-prev-page
2536           ,@(if (featurep 'xemacs) '(t)
2537               '(:help "Show previous page of article"))]
2538          ["Line forward" gnus-summary-scroll-up t])
2539         ("Move"
2540          ["Next unread article" gnus-summary-next-unread-article t]
2541          ["Previous unread article" gnus-summary-prev-unread-article t]
2542          ["Next article" gnus-summary-next-article t]
2543          ["Previous article" gnus-summary-prev-article t]
2544          ["Next unread subject" gnus-summary-next-unread-subject t]
2545          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2546          ["Next article same subject" gnus-summary-next-same-subject t]
2547          ["Previous article same subject" gnus-summary-prev-same-subject t]
2548          ["First unread article" gnus-summary-first-unread-article t]
2549          ["Best unread article" gnus-summary-best-unread-article t]
2550          ["Go to subject number..." gnus-summary-goto-subject t]
2551          ["Go to article number..." gnus-summary-goto-article t]
2552          ["Go to the last article" gnus-summary-goto-last-article t]
2553          ["Pop article off history" gnus-summary-pop-article t])
2554         ("Sort"
2555          ["Sort by number" gnus-summary-sort-by-number t]
2556          ["Sort by author" gnus-summary-sort-by-author t]
2557          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2558          ["Sort by subject" gnus-summary-sort-by-subject t]
2559          ["Sort by date" gnus-summary-sort-by-date t]
2560          ["Sort by score" gnus-summary-sort-by-score t]
2561          ["Sort by lines" gnus-summary-sort-by-lines t]
2562          ["Sort by characters" gnus-summary-sort-by-chars t]
2563          ["Randomize" gnus-summary-sort-by-random t]
2564          ["Original sort" gnus-summary-sort-by-original t])
2565         ("Help"
2566          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2567          ["Describe group" gnus-summary-describe-group t]
2568          ["Fetch charter" gnus-group-fetch-charter
2569           ,@(if (featurep 'xemacs) nil
2570               '(:help "Display the charter of the current group"))]
2571          ["Fetch control message" gnus-group-fetch-control
2572           ,@(if (featurep 'xemacs) nil
2573               '(:help "Display the archived control message for the current group"))]
2574          ["Read manual" gnus-info-find-node t])
2575         ("Modes"
2576          ["Pick and read" gnus-pick-mode t]
2577          ["Binary" gnus-binary-mode t])
2578         ("Regeneration"
2579          ["Regenerate" gnus-summary-prepare t]
2580          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2581          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2582          ["Toggle threading" gnus-summary-toggle-threads t])
2583         ["See old articles" gnus-summary-insert-old-articles t]
2584         ["See new articles" gnus-summary-insert-new-articles t]
2585         ["Filter articles..." gnus-summary-execute-command t]
2586         ["Run command on articles..." gnus-summary-universal-argument t]
2587         ["Search articles forward..." gnus-summary-search-article-forward t]
2588         ["Search articles backward..." gnus-summary-search-article-backward t]
2589         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2590         ["Expand window" gnus-summary-expand-window t]
2591         ["Expire expirable articles" gnus-summary-expire-articles
2592          (gnus-check-backend-function
2593           'request-expire-articles gnus-newsgroup-name)]
2594         ["Edit local kill file" gnus-summary-edit-local-kill t]
2595         ["Edit main kill file" gnus-summary-edit-global-kill t]
2596         ["Edit group parameters" gnus-summary-edit-parameters t]
2597         ["Customize group parameters" gnus-summary-customize-parameters t]
2598         ["Send a bug report" gnus-bug t]
2599         ("Exit"
2600          ["Catchup and exit" gnus-summary-catchup-and-exit
2601           ,@(if (featurep 'xemacs) '(t)
2602               '(:help "Mark unread articles in this group as read, then exit"))]
2603          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2604          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2605          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2606          ["Exit group" gnus-summary-exit
2607           ,@(if (featurep 'xemacs) '(t)
2608               '(:help "Exit current group, return to group selection mode"))]
2609          ["Exit group without updating" gnus-summary-exit-no-update t]
2610          ["Exit and goto next group" gnus-summary-next-group t]
2611          ["Exit and goto prev group" gnus-summary-prev-group t]
2612          ["Reselect group" gnus-summary-reselect-current-group t]
2613          ["Rescan group" gnus-summary-rescan-group t]
2614          ["Update dribble" gnus-summary-save-newsrc t])))
2615
2616     (gnus-run-hooks 'gnus-summary-menu-hook)))
2617
2618 (defvar gnus-summary-tool-bar-map nil)
2619
2620 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2621 ;; affect _new_ message buffers.  We might add a function that walks thru all
2622 ;; summary-mode buffers and force the update.
2623 (defun gnus-summary-tool-bar-update (&optional symbol value)
2624   "Update summary mode toolbar.
2625 Setter function for custom variables."
2626   (setq-default gnus-summary-tool-bar-map nil)
2627   (when symbol
2628     ;; When used as ":set" function:
2629     (set-default symbol value))
2630   (when (gnus-buffer-live-p gnus-summary-buffer)
2631     (with-current-buffer gnus-summary-buffer
2632       (gnus-summary-make-tool-bar))))
2633
2634 ;; The default will be changed when the new icons have been checked in:
2635 (defcustom gnus-summary-tool-bar 'gnus-summary-tool-bar-retro
2636   "Specifies the Gnus summary tool bar.
2637
2638 It can be either a list or a symbol refering to a list.  See
2639 `gmm-tool-bar-from-list' for the format of the list.  The
2640 default key map is `gnus-summary-mode-map'.
2641
2642 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2643 `gnus-summary-tool-bar-retro'."
2644   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2645                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2646                  (repeat :tag "User defined list" gmm-tool-bar-item)
2647                  (symbol))
2648   :version "23.0" ;; No Gnus
2649   :initialize 'custom-initialize-default
2650   :set 'gnus-summary-tool-bar-update
2651   :group 'gnus-summary)
2652
2653 (defcustom gnus-summary-tool-bar-gnome
2654   '((gnus-summary-post-news "compose" nil)
2655     (gnus-summary-reply-with-original "reply-author")
2656     (gnus-summary-reply "reply-author" nil :visible nil)
2657     (gnus-summary-followup-with-original "reply-all")
2658     (gnus-summary-followup "reply-all" nil :visible nil)
2659     (gnus-summary-mail-forward "forward")
2660     (gnus-summary-save-article "save") ;;  stock_mail-copy
2661     (gnus-summary-search-article-forward "search")
2662     (gnus-summary-print-article "print")
2663     (gnus-summary-mark-as-expirable
2664      "delete" nil
2665      :visible (gnus-check-backend-function 'request-expire-articles
2666                                            gnus-newsgroup-name))
2667     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2668     (gnus-summary-mark-as-spam
2669      "spam" t :visible (spam-group-ham-contents-p gnus-newsgroup-name)
2670      :help "Mark as spam")
2671     (gnus-summary-mark-as-read-forward
2672      "not-spam" nil :visible (spam-group-spam-contents-p gnus-newsgroup-name))
2673     ;; Some new commands that may need more suitable icons:
2674     (gnus-summary-save-newsrc "save" nil :visible nil)
2675     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2676     (gnus-summary-prev-article "left-arrow" nil :visible nil)  ;; Emacs 22
2677     (gnus-summary-next-article "right-arrow" nil :visible nil) ;; Emacs 22
2678     (gnus-summary-prev-unread-article "prev-node") ;; Emacs 22
2679     (gnus-summary-next-unread-article "next-node") ;; Emacs 22
2680     (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2681     ;;
2682     ;; Maybe some sort-by-... could be added:
2683     (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2684     (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2685     ;;
2686     (gnus-summary-insert-new-articles "inbox")
2687     ;;
2688     (gnus-summary-exit "exit-mode")
2689     ;;
2690     (gnus-info-find-node "help"))
2691   "List of functions for the summary tool bar (GNOME style).
2692
2693 See `gmm-tool-bar-from-list' for the format of the list."
2694   :type '(repeat gmm-tool-bar-item)
2695   :version "23.0" ;; No Gnus
2696   :initialize 'custom-initialize-default
2697   :set 'gnus-summary-tool-bar-update
2698   :group 'gnus-summary)
2699
2700 (defcustom gnus-summary-tool-bar-retro
2701   '((gnus-summary-prev-unread-article "prev-ur")
2702     (gnus-summary-next-unread-article "next-ur")
2703     (gnus-summary-post-news "post")
2704     (gnus-summary-followup-with-original "fuwo")
2705     (gnus-summary-followup "followup")
2706     (gnus-summary-reply-with-original "reply-wo")
2707     (gnus-summary-reply "reply")
2708     (gnus-summary-caesar-message "rot13")
2709     (gnus-uu-decode-uu "uu-decode")
2710     (gnus-summary-save-article-file "save-aif")
2711     (gnus-summary-save-article "save-art")
2712     (gnus-uu-post-news "uu-post")
2713     (gnus-summary-catchup "catchup")
2714     (gnus-summary-catchup-and-exit "cu-exit")
2715     (gnus-summary-exit "exit-summ")
2716     ;; Some new command that may need more suitable icons:
2717     (gnus-summary-print-article "print" nil :visible nil)
2718     (gnus-summary-mark-as-expirable "close" nil :visible nil)
2719     (gnus-summary-save-newsrc "save" nil :visible nil)
2720     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2721     (gnus-summary-search-article-forward "search" nil :visible nil)
2722     ;; (gnus-summary-insert-new-articles "paste" nil :visible nil)
2723     ;; (gnus-summary-toggle-threads "open" nil :visible nil)
2724     ;;
2725     (gnus-info-find-node "help" nil :visible nil))
2726   "List of functions for the summary tool bar (retro look).
2727
2728 See `gmm-tool-bar-from-list' for the format of the list."
2729   :type '(repeat gmm-tool-bar-item)
2730   :version "23.0" ;; No Gnus
2731   :initialize 'custom-initialize-default
2732   :set 'gnus-summary-tool-bar-update
2733   :group 'gnus-summary)
2734
2735 (defcustom gnus-summary-tool-bar-zap-list t
2736   "List of icon items from the global tool bar.
2737 These items are not displayed in the Gnus summary mode tool bar.
2738
2739 See `gmm-tool-bar-from-list' for the format of the list."
2740   :type 'gmm-tool-bar-zap-list
2741   :version "23.0" ;; No Gnus
2742   :initialize 'custom-initialize-default
2743   :set 'gnus-summary-tool-bar-update
2744   :group 'gnus-summary)
2745
2746 (defun gnus-summary-make-tool-bar (&optional force)
2747   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2748 When FORCE, rebuild the tool bar."
2749   (when (and (not (featurep 'xemacs))
2750              (boundp 'tool-bar-mode)
2751              tool-bar-mode
2752              (or (not gnus-summary-tool-bar-map) force))
2753     (let ((map (when (default-value 'tool-bar-mode)
2754                  (let ((load-path (mm-image-load-path)))
2755                    (gmm-tool-bar-from-list gnus-summary-tool-bar
2756                                                gnus-summary-tool-bar-zap-list
2757                                                'gnus-summary-mode-map)))))
2758       (when map
2759         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2760         ;; uses it's value.
2761         (setq gnus-summary-tool-bar-map map))))
2762   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2763
2764 (defun gnus-score-set-default (var value)
2765   "A version of set that updates the GNU Emacs menu-bar."
2766   (set var value)
2767   ;; It is the message that forces the active status to be updated.
2768   (message ""))
2769
2770 (defun gnus-make-score-map (type)
2771   "Make a summary score map of type TYPE."
2772   (if t
2773       nil
2774     (let ((headers '(("author" "from" string)
2775                      ("subject" "subject" string)
2776                      ("article body" "body" string)
2777                      ("article head" "head" string)
2778                      ("xref" "xref" string)
2779                      ("extra header" "extra" string)
2780                      ("lines" "lines" number)
2781                      ("followups to author" "followup" string)))
2782           (types '((number ("less than" <)
2783                            ("greater than" >)
2784                            ("equal" =))
2785                    (string ("substring" s)
2786                            ("exact string" e)
2787                            ("fuzzy string" f)
2788                            ("regexp" r))))
2789           (perms '(("temporary" (current-time-string))
2790                    ("permanent" nil)
2791                    ("immediate" now)))
2792           header)
2793       (list
2794        (apply
2795         'nconc
2796         (list
2797          (if (eq type 'lower)
2798              "Lower score"
2799            "Increase score"))
2800         (let (outh)
2801           (while headers
2802             (setq header (car headers))
2803             (setq outh
2804                   (cons
2805                    (apply
2806                     'nconc
2807                     (list (car header))
2808                     (let ((ts (cdr (assoc (nth 2 header) types)))
2809                           outt)
2810                       (while ts
2811                         (setq outt
2812                               (cons
2813                                (apply
2814                                 'nconc
2815                                 (list (caar ts))
2816                                 (let ((ps perms)
2817                                       outp)
2818                                   (while ps
2819                                     (setq outp
2820                                           (cons
2821                                            (vector
2822                                             (caar ps)
2823                                             (list
2824                                              'gnus-summary-score-entry
2825                                              (nth 1 header)
2826                                              (if (or (string= (nth 1 header)
2827                                                               "head")
2828                                                      (string= (nth 1 header)
2829                                                               "body"))
2830                                                  ""
2831                                                (list 'gnus-summary-header
2832                                                      (nth 1 header)))
2833                                              (list 'quote (nth 1 (car ts)))
2834                                              (list 'gnus-score-delta-default
2835                                                    nil)
2836                                              (nth 1 (car ps))
2837                                              t)
2838                                             t)
2839                                            outp))
2840                                     (setq ps (cdr ps)))
2841                                   (list (nreverse outp))))
2842                                outt))
2843                         (setq ts (cdr ts)))
2844                       (list (nreverse outt))))
2845                    outh))
2846             (setq headers (cdr headers)))
2847           (list (nreverse outh))))))))
2848
2849 \f
2850
2851 (defun gnus-summary-mode (&optional group)
2852   "Major mode for reading articles.
2853
2854 All normal editing commands are switched off.
2855 \\<gnus-summary-mode-map>
2856 Each line in this buffer represents one article.  To read an
2857 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2858 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2859 respectively.
2860
2861 You can also post articles and send mail from this buffer.  To
2862 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2863 of an article, type `\\[gnus-summary-reply]'.
2864
2865 There are approx. one gazillion commands you can execute in this
2866 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2867
2868 The following commands are available:
2869
2870 \\{gnus-summary-mode-map}"
2871   (interactive)
2872   (kill-all-local-variables)
2873   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2874     (gnus-summary-make-local-variables))
2875   (gnus-summary-make-local-variables)
2876   (setq gnus-newsgroup-name group)
2877   (when (gnus-visual-p 'summary-menu 'menu)
2878     (gnus-summary-make-menu-bar)
2879     (gnus-summary-make-tool-bar))
2880   (gnus-make-thread-indent-array)
2881   (gnus-simplify-mode-line)
2882   (setq major-mode 'gnus-summary-mode)
2883   (setq mode-name "Summary")
2884   (make-local-variable 'minor-mode-alist)
2885   (use-local-map gnus-summary-mode-map)
2886   (buffer-disable-undo)
2887   (setq buffer-read-only t              ;Disable modification
2888         show-trailing-whitespace nil)
2889   (setq truncate-lines t)
2890   (setq selective-display t)
2891   (setq selective-display-ellipses t)   ;Display `...'
2892   (gnus-summary-set-display-table)
2893   (gnus-set-default-directory)
2894   (unless (gnus-news-group-p group)
2895     (setq gnus-newsgroup-incorporated
2896           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2897   (make-local-variable 'gnus-summary-line-format)
2898   (make-local-variable 'gnus-summary-line-format-spec)
2899   (make-local-variable 'gnus-summary-dummy-line-format)
2900   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2901   (make-local-variable 'gnus-summary-mark-positions)
2902   (gnus-make-local-hook 'pre-command-hook)
2903   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2904   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2905   (turn-on-gnus-mailing-list-mode)
2906   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2907   (gnus-update-summary-mark-positions))
2908
2909 (defun gnus-summary-make-local-variables ()
2910   "Make all the local summary buffer variables."
2911   (let (global)
2912     (dolist (local gnus-summary-local-variables)
2913       (if (consp local)
2914           (progn
2915             (if (eq (cdr local) 'global)
2916                 ;; Copy the global value of the variable.
2917                 (setq global (symbol-value (car local)))
2918               ;; Use the value from the list.
2919               (setq global (eval (cdr local))))
2920             (set (make-local-variable (car local)) global))
2921         ;; Simple nil-valued local variable.
2922         (set (make-local-variable local) nil)))))
2923
2924 (defun gnus-summary-clear-local-variables ()
2925   (let ((locals gnus-summary-local-variables))
2926     (while locals
2927       (if (consp (car locals))
2928           (and (symbolp (caar locals))
2929                (set (caar locals) nil))
2930         (and (symbolp (car locals))
2931              (set (car locals) nil)))
2932       (setq locals (cdr locals)))))
2933
2934 ;; Summary data functions.
2935
2936 (defmacro gnus-data-number (data)
2937   `(car ,data))
2938
2939 (defmacro gnus-data-set-number (data number)
2940   `(setcar ,data ,number))
2941
2942 (defmacro gnus-data-mark (data)
2943   `(nth 1 ,data))
2944
2945 (defmacro gnus-data-set-mark (data mark)
2946   `(setcar (nthcdr 1 ,data) ,mark))
2947
2948 (defmacro gnus-data-pos (data)
2949   `(nth 2 ,data))
2950
2951 (defmacro gnus-data-set-pos (data pos)
2952   `(setcar (nthcdr 2 ,data) ,pos))
2953
2954 (defmacro gnus-data-header (data)
2955   `(nth 3 ,data))
2956
2957 (defmacro gnus-data-set-header (data header)
2958   `(setcar (nthcdr 3 ,data) ,header))
2959
2960 (defmacro gnus-data-level (data)
2961   `(nth 4 ,data))
2962
2963 (defmacro gnus-data-unread-p (data)
2964   `(= (nth 1 ,data) gnus-unread-mark))
2965
2966 (defmacro gnus-data-read-p (data)
2967   `(/= (nth 1 ,data) gnus-unread-mark))
2968
2969 (defmacro gnus-data-pseudo-p (data)
2970   `(consp (nth 3 ,data)))
2971
2972 (defmacro gnus-data-find (number)
2973   `(assq ,number gnus-newsgroup-data))
2974
2975 (defmacro gnus-data-find-list (number &optional data)
2976   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2977      (memq (assq ,number bdata)
2978            bdata)))
2979
2980 (defmacro gnus-data-make (number mark pos header level)
2981   `(list ,number ,mark ,pos ,header ,level))
2982
2983 (defun gnus-data-enter (after-article number mark pos header level offset)
2984   (let ((data (gnus-data-find-list after-article)))
2985     (unless data
2986       (error "No such article: %d" after-article))
2987     (setcdr data (cons (gnus-data-make number mark pos header level)
2988                        (cdr data)))
2989     (setq gnus-newsgroup-data-reverse nil)
2990     (gnus-data-update-list (cddr data) offset)))
2991
2992 (defun gnus-data-enter-list (after-article list &optional offset)
2993   (when list
2994     (let ((data (and after-article (gnus-data-find-list after-article)))
2995           (ilist list))
2996       (if (not (or data
2997                    after-article))
2998           (let ((odata gnus-newsgroup-data))
2999             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3000             (when offset
3001               (gnus-data-update-list odata offset)))
3002         ;; Find the last element in the list to be spliced into the main
3003         ;; list.
3004         (setq list (last list))
3005         (if (not data)
3006             (progn
3007               (setcdr list gnus-newsgroup-data)
3008               (setq gnus-newsgroup-data ilist)
3009               (when offset
3010                 (gnus-data-update-list (cdr list) offset)))
3011           (setcdr list (cdr data))
3012           (setcdr data ilist)
3013           (when offset
3014             (gnus-data-update-list (cdr list) offset))))
3015       (setq gnus-newsgroup-data-reverse nil))))
3016
3017 (defun gnus-data-remove (article &optional offset)
3018   (let ((data gnus-newsgroup-data))
3019     (if (= (gnus-data-number (car data)) article)
3020         (progn
3021           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3022                 gnus-newsgroup-data-reverse nil)
3023           (when offset
3024             (gnus-data-update-list gnus-newsgroup-data offset)))
3025       (while (cdr data)
3026         (when (= (gnus-data-number (cadr data)) article)
3027           (setcdr data (cddr data))
3028           (when offset
3029             (gnus-data-update-list (cdr data) offset))
3030           (setq data nil
3031                 gnus-newsgroup-data-reverse nil))
3032         (setq data (cdr data))))))
3033
3034 (defmacro gnus-data-list (backward)
3035   `(if ,backward
3036        (or gnus-newsgroup-data-reverse
3037            (setq gnus-newsgroup-data-reverse
3038                  (reverse gnus-newsgroup-data)))
3039      gnus-newsgroup-data))
3040
3041 (defun gnus-data-update-list (data offset)
3042   "Add OFFSET to the POS of all data entries in DATA."
3043   (setq gnus-newsgroup-data-reverse nil)
3044   (while data
3045     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3046     (setq data (cdr data))))
3047
3048 (defun gnus-summary-article-pseudo-p (article)
3049   "Say whether this article is a pseudo article or not."
3050   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3051
3052 (defmacro gnus-summary-article-sparse-p (article)
3053   "Say whether this article is a sparse article or not."
3054   `(memq ,article gnus-newsgroup-sparse))
3055
3056 (defmacro gnus-summary-article-ancient-p (article)
3057   "Say whether this article is a sparse article or not."
3058   `(memq ,article gnus-newsgroup-ancient))
3059
3060 (defun gnus-article-parent-p (number)
3061   "Say whether this article is a parent or not."
3062   (let ((data (gnus-data-find-list number)))
3063     (and (cdr data)                     ; There has to be an article after...
3064          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3065             (gnus-data-level (nth 1 data))))))
3066
3067 (defun gnus-article-children (number)
3068   "Return a list of all children to NUMBER."
3069   (let* ((data (gnus-data-find-list number))
3070          (level (gnus-data-level (car data)))
3071          children)
3072     (setq data (cdr data))
3073     (while (and data
3074                 (= (gnus-data-level (car data)) (1+ level)))
3075       (push (gnus-data-number (car data)) children)
3076       (setq data (cdr data)))
3077     children))
3078
3079 (defmacro gnus-summary-skip-intangible ()
3080   "If the current article is intangible, then jump to a different article."
3081   '(let ((to (get-text-property (point) 'gnus-intangible)))
3082      (and to (gnus-summary-goto-subject to))))
3083
3084 (defmacro gnus-summary-article-intangible-p ()
3085   "Say whether this article is intangible or not."
3086   '(get-text-property (point) 'gnus-intangible))
3087
3088 (defun gnus-article-read-p (article)
3089   "Say whether ARTICLE is read or not."
3090   (not (or (memq article gnus-newsgroup-marked)
3091            (memq article gnus-newsgroup-spam-marked)
3092            (memq article gnus-newsgroup-unreads)
3093            (memq article gnus-newsgroup-unselected)
3094            (memq article gnus-newsgroup-dormant))))
3095
3096 ;; Some summary mode macros.
3097
3098 (defmacro gnus-summary-article-number ()
3099   "The article number of the article on the current line.
3100 If there isn't an article number here, then we return the current
3101 article number."
3102   '(progn
3103      (gnus-summary-skip-intangible)
3104      (or (get-text-property (point) 'gnus-number)
3105          (gnus-summary-last-subject))))
3106
3107 (defmacro gnus-summary-article-header (&optional number)
3108   "Return the header of article NUMBER."
3109   `(gnus-data-header (gnus-data-find
3110                       ,(or number '(gnus-summary-article-number)))))
3111
3112 (defmacro gnus-summary-thread-level (&optional number)
3113   "Return the level of thread that starts with article NUMBER."
3114   `(if (and (eq gnus-summary-make-false-root 'dummy)
3115             (get-text-property (point) 'gnus-intangible))
3116        0
3117      (gnus-data-level (gnus-data-find
3118                        ,(or number '(gnus-summary-article-number))))))
3119
3120 (defmacro gnus-summary-article-mark (&optional number)
3121   "Return the mark of article NUMBER."
3122   `(gnus-data-mark (gnus-data-find
3123                     ,(or number '(gnus-summary-article-number)))))
3124
3125 (defmacro gnus-summary-article-pos (&optional number)
3126   "Return the position of the line of article NUMBER."
3127   `(gnus-data-pos (gnus-data-find
3128                    ,(or number '(gnus-summary-article-number)))))
3129
3130 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3131 (defmacro gnus-summary-article-subject (&optional number)
3132   "Return current subject string or nil if nothing."
3133   `(let ((headers
3134           ,(if number
3135                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3136              '(gnus-data-header (assq (gnus-summary-article-number)
3137                                       gnus-newsgroup-data)))))
3138      (and headers
3139           (vectorp headers)
3140           (mail-header-subject headers))))
3141
3142 (defmacro gnus-summary-article-score (&optional number)
3143   "Return current article score."
3144   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3145                   gnus-newsgroup-scored))
3146        gnus-summary-default-score 0))
3147
3148 (defun gnus-summary-article-children (&optional number)
3149   "Return a list of article numbers that are children of article NUMBER."
3150   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3151          (level (gnus-data-level (car data)))
3152          l children)
3153     (while (and (setq data (cdr data))
3154                 (> (setq l (gnus-data-level (car data))) level))
3155       (and (= (1+ level) l)
3156            (push (gnus-data-number (car data))
3157                  children)))
3158     (nreverse children)))
3159
3160 (defun gnus-summary-article-parent (&optional number)
3161   "Return the article number of the parent of article NUMBER."
3162   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3163                                     (gnus-data-list t)))
3164          (level (gnus-data-level (car data))))
3165     (if (zerop level)
3166         ()                              ; This is a root.
3167       ;; We search until we find an article with a level less than
3168       ;; this one.  That function has to be the parent.
3169       (while (and (setq data (cdr data))
3170                   (not (< (gnus-data-level (car data)) level))))
3171       (and data (gnus-data-number (car data))))))
3172
3173 (defun gnus-unread-mark-p (mark)
3174   "Say whether MARK is the unread mark."
3175   (= mark gnus-unread-mark))
3176
3177 (defun gnus-read-mark-p (mark)
3178   "Say whether MARK is one of the marks that mark as read.
3179 This is all marks except unread, ticked, dormant, and expirable."
3180   (not (or (= mark gnus-unread-mark)
3181            (= mark gnus-ticked-mark)
3182            (= mark gnus-spam-mark)
3183            (= mark gnus-dormant-mark)
3184            (= mark gnus-expirable-mark))))
3185
3186 (defmacro gnus-article-mark (number)
3187   "Return the MARK of article NUMBER.
3188 This macro should only be used when computing the mark the \"first\"
3189 time; i.e., when generating the summary lines.  After that,
3190 `gnus-summary-article-mark' should be used to examine the
3191 marks of articles."
3192   `(cond
3193     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3194     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3195     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3196     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3197     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3198     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3199     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3200     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3201            gnus-ancient-mark))))
3202
3203 ;; Saving hidden threads.
3204
3205 (defmacro gnus-save-hidden-threads (&rest forms)
3206   "Save hidden threads, eval FORMS, and restore the hidden threads."
3207   (let ((config (make-symbol "config")))
3208     `(let ((,config (gnus-hidden-threads-configuration)))
3209        (unwind-protect
3210            (save-excursion
3211              ,@forms)
3212          (gnus-restore-hidden-threads-configuration ,config)))))
3213 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3214 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3215
3216 (defun gnus-data-compute-positions ()
3217   "Compute the positions of all articles."
3218   (setq gnus-newsgroup-data-reverse nil)
3219   (let ((data gnus-newsgroup-data))
3220     (save-excursion
3221       (gnus-save-hidden-threads
3222         (gnus-summary-show-all-threads)
3223         (goto-char (point-min))
3224         (while data
3225           (while (get-text-property (point) 'gnus-intangible)
3226             (forward-line 1))
3227           (gnus-data-set-pos (car data) (+ (point) 3))
3228           (setq data (cdr data))
3229           (forward-line 1))))))
3230
3231 (defun gnus-hidden-threads-configuration ()
3232   "Return the current hidden threads configuration."
3233   (save-excursion
3234     (let (config)
3235       (goto-char (point-min))
3236       (while (search-forward "\r" nil t)
3237         (push (1- (point)) config))
3238       config)))
3239
3240 (defun gnus-restore-hidden-threads-configuration (config)
3241   "Restore hidden threads configuration from CONFIG."
3242   (save-excursion
3243     (let (point buffer-read-only)
3244       (while (setq point (pop config))
3245         (when (and (< point (point-max))
3246                    (goto-char point)
3247                    (eq (char-after) ?\n))
3248           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3249
3250 ;; Various summary mode internalish functions.
3251
3252 (defun gnus-mouse-pick-article (e)
3253   (interactive "e")
3254   (mouse-set-point e)
3255   (gnus-summary-next-page nil t))
3256
3257 (defun gnus-summary-set-display-table ()
3258   "Change the display table.
3259 Odd characters have a tendency to mess
3260 up nicely formatted displays - we make all possible glyphs
3261 display only a single character."
3262
3263   ;; We start from the standard display table, if any.
3264   (let ((table (or (copy-sequence standard-display-table)
3265                    (make-display-table)))
3266         (i 32))
3267     ;; Nix out all the control chars...
3268     (while (>= (setq i (1- i)) 0)
3269       (aset table i [??]))
3270     ;; ... but not newline and cr, of course.  (cr is necessary for the
3271     ;; selective display).
3272     (aset table ?\n nil)
3273     (aset table ?\r nil)
3274     ;; We keep TAB as well.
3275     (aset table ?\t nil)
3276     ;; We nix out any glyphs over 126 that are not set already.
3277     (let ((i 256))
3278       (while (>= (setq i (1- i)) 127)
3279         ;; Only modify if the entry is nil.
3280         (unless (aref table i)
3281           (aset table i [??]))))
3282     (setq buffer-display-table table)))
3283
3284 (defun gnus-summary-set-article-display-arrow (pos)
3285   "Update the overlay arrow to point to line at position POS."
3286   (when (and gnus-summary-display-arrow
3287              (boundp 'overlay-arrow-position)
3288              (boundp 'overlay-arrow-string))
3289     (save-excursion
3290       (goto-char pos)
3291       (beginning-of-line)
3292       (unless overlay-arrow-position
3293         (setq overlay-arrow-position (make-marker)))
3294       (setq overlay-arrow-string "=>"
3295             overlay-arrow-position (set-marker overlay-arrow-position
3296                                                (point)
3297                                                (current-buffer))))))
3298
3299 (defun gnus-summary-setup-buffer (group)
3300   "Initialize summary buffer."
3301   (let ((buffer (gnus-summary-buffer-name group))
3302         (dead-name (concat "*Dead Summary "
3303                            (gnus-group-decoded-name group) "*")))
3304     ;; If a dead summary buffer exists, we kill it.
3305     (when (gnus-buffer-live-p dead-name)
3306       (gnus-kill-buffer dead-name))
3307     (if (get-buffer buffer)
3308         (progn
3309           (set-buffer buffer)
3310           (setq gnus-summary-buffer (current-buffer))
3311           (not gnus-newsgroup-prepared))
3312       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3313       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3314       (gnus-summary-mode group)
3315       (when gnus-carpal
3316         (gnus-carpal-setup-buffer 'summary))
3317       (unless gnus-single-article-buffer
3318         (make-local-variable 'gnus-article-buffer)
3319         (make-local-variable 'gnus-article-current)
3320         (make-local-variable 'gnus-original-article-buffer))
3321       (setq gnus-newsgroup-name group)
3322       ;; Set any local variables in the group parameters.
3323       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3324       t)))
3325
3326 (defun gnus-set-global-variables ()
3327   "Set the global equivalents of the buffer-local variables.
3328 They are set to the latest values they had.  These reflect the summary
3329 buffer that was in action when the last article was fetched."
3330   (when (eq major-mode 'gnus-summary-mode)
3331     (setq gnus-summary-buffer (current-buffer))
3332     (let ((name gnus-newsgroup-name)
3333           (marked gnus-newsgroup-marked)
3334           (spam gnus-newsgroup-spam-marked)
3335           (unread gnus-newsgroup-unreads)
3336           (headers gnus-current-headers)
3337           (data gnus-newsgroup-data)
3338           (summary gnus-summary-buffer)
3339           (article-buffer gnus-article-buffer)
3340           (original gnus-original-article-buffer)
3341           (gac gnus-article-current)
3342           (reffed gnus-reffed-article-number)
3343           (score-file gnus-current-score-file)
3344           (default-charset gnus-newsgroup-charset)
3345           vlist)
3346       (let ((locals gnus-newsgroup-variables))
3347         (while locals
3348           (if (consp (car locals))
3349               (push (eval (caar locals)) vlist)
3350             (push (eval (car locals)) vlist))
3351           (setq locals (cdr locals)))
3352         (setq vlist (nreverse vlist)))
3353       (with-current-buffer gnus-group-buffer
3354         (setq gnus-newsgroup-name name
3355               gnus-newsgroup-marked marked
3356               gnus-newsgroup-spam-marked spam
3357               gnus-newsgroup-unreads unread
3358               gnus-current-headers headers
3359               gnus-newsgroup-data data
3360               gnus-article-current gac
3361               gnus-summary-buffer summary
3362               gnus-article-buffer article-buffer
3363               gnus-original-article-buffer original
3364               gnus-reffed-article-number reffed
3365               gnus-current-score-file score-file
3366               gnus-newsgroup-charset default-charset)
3367         (let ((locals gnus-newsgroup-variables))
3368           (while locals
3369             (if (consp (car locals))
3370                 (set (caar locals) (pop vlist))
3371               (set (car locals) (pop vlist)))
3372             (setq locals (cdr locals))))
3373         ;; The article buffer also has local variables.
3374         (when (gnus-buffer-live-p gnus-article-buffer)
3375           (set-buffer gnus-article-buffer)
3376           (setq gnus-summary-buffer summary))))))
3377
3378 (defun gnus-summary-article-unread-p (article)
3379   "Say whether ARTICLE is unread or not."
3380   (memq article gnus-newsgroup-unreads))
3381
3382 (defun gnus-summary-first-article-p (&optional article)
3383   "Return whether ARTICLE is the first article in the buffer."
3384   (if (not (setq article (or article (gnus-summary-article-number))))
3385       nil
3386     (eq article (caar gnus-newsgroup-data))))
3387
3388 (defun gnus-summary-last-article-p (&optional article)
3389   "Return whether ARTICLE is the last article in the buffer."
3390   (if (not (setq article (or article (gnus-summary-article-number))))
3391       ;; All non-existent numbers are the last article.  :-)
3392       t
3393     (not (cdr (gnus-data-find-list article)))))
3394
3395 (defun gnus-make-thread-indent-array ()
3396   (let ((n 200))
3397     (unless (and gnus-thread-indent-array
3398                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3399       (setq gnus-thread-indent-array (make-vector 201 "")
3400             gnus-thread-indent-array-level gnus-thread-indent-level)
3401       (while (>= n 0)
3402         (aset gnus-thread-indent-array n
3403               (make-string (* n gnus-thread-indent-level) ? ))
3404         (setq n (1- n))))))
3405
3406 (defun gnus-update-summary-mark-positions ()
3407   "Compute where the summary marks are to go."
3408   (save-excursion
3409     (when (gnus-buffer-exists-p gnus-summary-buffer)
3410       (set-buffer gnus-summary-buffer))
3411     (let ((spec gnus-summary-line-format-spec)
3412           pos)
3413       (save-excursion
3414         (gnus-set-work-buffer)
3415         (let ((gnus-tmp-unread ?Z)
3416               (gnus-replied-mark ?Z)
3417               (gnus-score-below-mark ?Z)
3418               (gnus-score-over-mark ?Z)
3419               (gnus-undownloaded-mark ?Z)
3420               (gnus-summary-line-format-spec spec)
3421               (gnus-newsgroup-downloadable '(0))
3422               (header
3423                (make-full-mail-header
3424                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3425               case-fold-search ignores)
3426           ;; Here, all marks are bound to Z.
3427           (gnus-summary-insert-line header
3428                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3429           (goto-char (point-min))
3430           ;; Memorize the positions of the same characters as dummy marks.
3431           (while (re-search-forward "[A-D]" nil t)
3432             (push (point) ignores))
3433           (erase-buffer)
3434           ;; We use A-D as dummy marks in order to know column positions
3435           ;; where marks should be inserted.
3436           (setq gnus-tmp-unread ?A
3437                 gnus-replied-mark ?B
3438                 gnus-score-below-mark ?C
3439                 gnus-score-over-mark ?C
3440                 gnus-undownloaded-mark ?D)
3441           (gnus-summary-insert-line header
3442                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3443           ;; Ignore characters which aren't dummy marks.
3444           (dolist (p ignores)
3445             (delete-region (goto-char (1- p)) p)
3446             (insert ?Z))
3447           (goto-char (point-min))
3448           (setq pos (list (cons 'unread
3449                                 (and (search-forward "A" nil t)
3450                                      (- (point) (point-min) 1)))))
3451           (goto-char (point-min))
3452           (push (cons 'replied (and (search-forward "B" nil t)
3453                                     (- (point) (point-min) 1)))
3454                 pos)
3455           (goto-char (point-min))
3456           (push (cons 'score (and (search-forward "C" nil t)
3457                                   (- (point) (point-min) 1)))
3458                 pos)
3459           (goto-char (point-min))
3460           (push (cons 'download (and (search-forward "D" nil t)
3461                                      (- (point) (point-min) 1)))
3462                 pos)))
3463       (setq gnus-summary-mark-positions pos))))
3464
3465 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3466   "Insert a dummy root in the summary buffer."
3467   (beginning-of-line)
3468   (gnus-add-text-properties
3469    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3470    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3471
3472 (defun gnus-summary-extract-address-component (from)
3473   (or (car (funcall gnus-extract-address-components from))
3474       from))
3475
3476 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3477   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3478                                 default-mime-charset)))
3479     ;; Is it really necessary to do this next part for each summary line?
3480     ;; Luckily, doesn't seem to slow things down much.
3481     (or
3482      (and gnus-ignored-from-addresses
3483           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3484           (let ((extra-headers (mail-header-extra header))
3485                 to
3486                 newsgroups)
3487             (cond
3488              ((setq to (cdr (assq 'To extra-headers)))
3489               (concat gnus-summary-to-prefix
3490                       (inline
3491                         (gnus-summary-extract-address-component
3492                          (funcall gnus-decode-encoded-word-function to)))))
3493              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3494               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3495      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3496
3497 (defun gnus-summary-insert-line (gnus-tmp-header
3498                                  gnus-tmp-level gnus-tmp-current
3499                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3500                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3501                                  &optional gnus-tmp-dummy gnus-tmp-score
3502                                  gnus-tmp-process)
3503   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3504          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3505          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3506          (gnus-tmp-score-char
3507           (if (or (null gnus-summary-default-score)
3508                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3509                       gnus-summary-zcore-fuzz))
3510               ?\ ;;;Whitespace
3511             (if (< gnus-tmp-score gnus-summary-default-score)
3512                 gnus-score-below-mark gnus-score-over-mark)))
3513          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3514          (gnus-tmp-replied
3515           (cond (gnus-tmp-process gnus-process-mark)
3516                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3517                  gnus-cached-mark)
3518                 (gnus-tmp-replied gnus-replied-mark)
3519                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3520                  gnus-forwarded-mark)
3521                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3522                  gnus-saved-mark)
3523                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3524                  gnus-recent-mark)
3525                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3526                  gnus-unseen-mark)
3527                 (t gnus-no-mark)))
3528          (gnus-tmp-downloaded
3529           (cond (undownloaded
3530                  gnus-undownloaded-mark)
3531                 (gnus-newsgroup-agentized
3532                  gnus-downloaded-mark)
3533                 (t
3534                  gnus-no-mark)))
3535          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3536          (gnus-tmp-name
3537           (cond
3538            ((string-match "<[^>]+> *$" gnus-tmp-from)
3539             (let ((beg (match-beginning 0)))
3540               (or (and (string-match "^\".+\"" gnus-tmp-from)
3541                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3542                   (substring gnus-tmp-from 0 beg))))
3543            ((string-match "(.+)" gnus-tmp-from)
3544             (substring gnus-tmp-from
3545                        (1+ (match-beginning 0)) (1- (match-end 0))))
3546            (t gnus-tmp-from)))
3547          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3548          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3549          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3550          (buffer-read-only nil))
3551     (when (string= gnus-tmp-name "")
3552       (setq gnus-tmp-name gnus-tmp-from))
3553     (unless (numberp gnus-tmp-lines)
3554       (setq gnus-tmp-lines -1))
3555     (if (= gnus-tmp-lines -1)
3556         (setq gnus-tmp-lines "?")
3557       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3558     (gnus-put-text-property-excluding-characters-with-faces
3559      (point)
3560      (progn (eval gnus-summary-line-format-spec) (point))
3561      'gnus-number gnus-tmp-number)
3562     (when (gnus-visual-p 'summary-highlight 'highlight)
3563       (forward-line -1)
3564       (gnus-run-hooks 'gnus-summary-update-hook)
3565       (forward-line 1))))
3566
3567 (defun gnus-summary-update-line (&optional dont-update)
3568   "Update summary line after change."
3569   (when (and gnus-summary-default-score
3570              (not gnus-summary-inhibit-highlight))
3571     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3572            (article (gnus-summary-article-number))
3573            (score (gnus-summary-article-score article)))
3574       (unless dont-update
3575         (if (and gnus-summary-mark-below
3576                  (< (gnus-summary-article-score)
3577                     gnus-summary-mark-below))
3578             ;; This article has a low score, so we mark it as read.
3579             (when (memq article gnus-newsgroup-unreads)
3580               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3581           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3582             ;; This article was previously marked as read on account
3583             ;; of a low score, but now it has risen, so we mark it as
3584             ;; unread.
3585             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3586         (gnus-summary-update-mark
3587          (if (or (null gnus-summary-default-score)
3588                  (<= (abs (- score gnus-summary-default-score))
3589                      gnus-summary-zcore-fuzz))
3590              ?\ ;;;Whitespace
3591            (if (< score gnus-summary-default-score)
3592                gnus-score-below-mark gnus-score-over-mark))
3593          'score))
3594       ;; Do visual highlighting.
3595       (when (gnus-visual-p 'summary-highlight 'highlight)
3596         (gnus-run-hooks 'gnus-summary-update-hook)))))
3597
3598 (defvar gnus-tmp-new-adopts nil)
3599
3600 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3601   "Return the number of articles in THREAD.
3602 This may be 0 in some cases -- if none of the articles in
3603 the thread are to be displayed."
3604   (let* ((number
3605           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3606           (cond
3607            ((not (listp thread))
3608             1)
3609            ((and (consp thread) (cdr thread))
3610             (apply
3611              '+ 1 (mapcar
3612                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3613            ((null thread)
3614             1)
3615            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3616             1)
3617            (t 0))))
3618     (when (and level (zerop level) gnus-tmp-new-adopts)
3619       (incf number
3620             (apply '+ (mapcar
3621                        'gnus-summary-number-of-articles-in-thread
3622                        gnus-tmp-new-adopts))))
3623     (if char
3624         (if (> number 1) gnus-not-empty-thread-mark
3625           gnus-empty-thread-mark)
3626       number)))
3627
3628 (defsubst gnus-summary-line-message-size (head)
3629   "Return pretty-printed version of message size.
3630 This function is intended to be used in
3631 `gnus-summary-line-format-alist'."
3632   (let ((c (or (mail-header-chars head) -1)))
3633     (cond ((< c 0) "n/a")               ; chars not available
3634           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3635           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3636           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3637           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3638
3639
3640 (defun gnus-summary-set-local-parameters (group)
3641   "Go through the local params of GROUP and set all variable specs in that list."
3642   (let ((vars '(quit-config)))          ; Ignore quit-config.
3643     (dolist (elem (gnus-group-find-parameter group))
3644       (and (consp elem)                 ; Has to be a cons.
3645            (consp (cdr elem))           ; The cdr has to be a list.
3646            (symbolp (car elem))         ; Has to be a symbol in there.
3647            (not (memq (car elem) vars))
3648            (ignore-errors               ; So we set it.
3649              (push (car elem) vars)
3650              (make-local-variable (car elem))
3651              (set (car elem) (eval (nth 1 elem))))))))
3652
3653 (defun gnus-summary-read-group (group &optional show-all no-article
3654                                       kill-buffer no-display backward
3655                                       select-articles)
3656   "Start reading news in newsgroup GROUP.
3657 If SHOW-ALL is non-nil, already read articles are also listed.
3658 If NO-ARTICLE is non-nil, no article is selected initially.
3659 If NO-DISPLAY, don't generate a summary buffer."
3660   (let (result)
3661     (while (and group
3662                 (null (setq result
3663                             (let ((gnus-auto-select-next nil))
3664                               (or (gnus-summary-read-group-1
3665                                    group show-all no-article
3666                                    kill-buffer no-display
3667                                    select-articles)
3668                                   (setq show-all nil
3669                                         select-articles nil)))))
3670                 (eq gnus-auto-select-next 'quietly))
3671       (set-buffer gnus-group-buffer)
3672       ;; The entry function called above goes to the next
3673       ;; group automatically, so we go two groups back
3674       ;; if we are searching for the previous group.
3675       (when backward
3676         (gnus-group-prev-unread-group 2))
3677       (if (not (equal group (gnus-group-group-name)))
3678           (setq group (gnus-group-group-name))
3679         (setq group nil)))
3680     result))
3681
3682 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3683   "Directly jump to the other GROUP from summary buffer.
3684 If SHOW-ALL is non-nil, already read articles are also listed."
3685   (interactive
3686    (if (eq gnus-summary-buffer (current-buffer))
3687        (list (completing-read
3688               "Group: " gnus-active-hashtb nil t
3689               (when (and gnus-newsgroup-name
3690                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3691                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3692               'gnus-group-history)
3693              current-prefix-arg)
3694      (error "%s must be invoked from a gnus summary buffer." this-command)))
3695   (unless (or (zerop (length group))
3696               (and gnus-newsgroup-name
3697                    (string-equal gnus-newsgroup-name group)))
3698     (gnus-summary-exit)
3699     (gnus-summary-read-group group show-all
3700                              gnus-dont-select-after-jump-to-other-group)))
3701
3702 (defun gnus-summary-read-group-1 (group show-all no-article
3703                                         kill-buffer no-display
3704                                         &optional select-articles)
3705   ;; Killed foreign groups can't be entered.
3706   ;;  (when (and (not (gnus-group-native-p group))
3707   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3708   ;;    (error "Dead non-native groups can't be entered"))
3709   (gnus-message 5 "Retrieving newsgroup: %s..."
3710                 (gnus-group-decoded-name group))
3711   (let* ((new-group (gnus-summary-setup-buffer group))
3712          (quit-config (gnus-group-quit-config group))
3713          (did-select (and new-group (gnus-select-newsgroup
3714                                      group show-all select-articles))))
3715     (cond
3716      ;; This summary buffer exists already, so we just select it.
3717      ((not new-group)
3718       (gnus-set-global-variables)
3719       (when kill-buffer
3720         (gnus-kill-or-deaden-summary kill-buffer))
3721       (gnus-configure-windows 'summary 'force)
3722       (gnus-set-mode-line 'summary)
3723       (gnus-summary-position-point)
3724       (message "")
3725       t)
3726      ;; We couldn't select this group.
3727      ((null did-select)
3728       (when (and (eq major-mode 'gnus-summary-mode)
3729                  (not (equal (current-buffer) kill-buffer)))
3730         (kill-buffer (current-buffer))
3731         (if (not quit-config)
3732             (progn
3733               ;; Update the info -- marks might need to be removed,
3734               ;; for instance.
3735               (gnus-summary-update-info)
3736               (set-buffer gnus-group-buffer)
3737               (gnus-group-jump-to-group group)
3738               (gnus-group-next-unread-group 1))
3739           (gnus-handle-ephemeral-exit quit-config)))
3740       (let ((grpinfo (gnus-get-info group)))
3741         (if (null (gnus-info-read grpinfo))
3742             (gnus-message 3 "Group %s contains no messages"
3743                           (gnus-group-decoded-name group))
3744           (gnus-message 3 "Can't select group")))
3745       nil)
3746      ;; The user did a `C-g' while prompting for number of articles,
3747      ;; so we exit this group.
3748      ((eq did-select 'quit)
3749       (and (eq major-mode 'gnus-summary-mode)
3750            (not (equal (current-buffer) kill-buffer))
3751            (kill-buffer (current-buffer)))
3752       (when kill-buffer
3753         (gnus-kill-or-deaden-summary kill-buffer))
3754       (if (not quit-config)
3755           (progn
3756             (set-buffer gnus-group-buffer)
3757             (gnus-group-jump-to-group group)
3758             (gnus-group-next-unread-group 1)
3759             (gnus-configure-windows 'group 'force))
3760         (gnus-handle-ephemeral-exit quit-config))
3761       ;; Finally signal the quit.
3762       (signal 'quit nil))
3763      ;; The group was successfully selected.
3764      (t
3765       (gnus-set-global-variables)
3766       ;; Save the active value in effect when the group was entered.
3767       (setq gnus-newsgroup-active
3768             (gnus-copy-sequence
3769              (gnus-active gnus-newsgroup-name)))
3770       ;; You can change the summary buffer in some way with this hook.
3771       (gnus-run-hooks 'gnus-select-group-hook)
3772       (when (memq 'summary (gnus-update-format-specifications
3773                             nil 'summary 'summary-mode 'summary-dummy))
3774         ;; The format specification for the summary line was updated,
3775         ;; so we need to update the mark positions as well.
3776         (gnus-update-summary-mark-positions))
3777       ;; Do score processing.
3778       (when gnus-use-scoring
3779         (gnus-possibly-score-headers))
3780       ;; Check whether to fill in the gaps in the threads.
3781       (when gnus-build-sparse-threads
3782         (gnus-build-sparse-threads))
3783       ;; Find the initial limit.
3784       (if show-all
3785           (let ((gnus-newsgroup-dormant nil))
3786             (gnus-summary-initial-limit show-all))
3787         (gnus-summary-initial-limit show-all))
3788       ;; Generate the summary buffer.
3789       (unless no-display
3790         (gnus-summary-prepare))
3791       (when gnus-use-trees
3792         (gnus-tree-open group)
3793         (setq gnus-summary-highlight-line-function
3794               'gnus-tree-highlight-article))
3795       ;; If the summary buffer is empty, but there are some low-scored
3796       ;; articles or some excluded dormants, we include these in the
3797       ;; buffer.
3798       (when (and (zerop (buffer-size))
3799                  (not no-display))
3800         (cond (gnus-newsgroup-dormant
3801                (gnus-summary-limit-include-dormant))
3802               ((and gnus-newsgroup-scored show-all)
3803                (gnus-summary-limit-include-expunged t))))
3804       ;; Function `gnus-apply-kill-file' must be called in this hook.
3805       (gnus-run-hooks 'gnus-apply-kill-hook)
3806       (if (and (zerop (buffer-size))
3807                (not no-display))
3808           (progn
3809             ;; This newsgroup is empty.
3810             (gnus-summary-catchup-and-exit nil t)
3811             (gnus-message 6 "No unread news")
3812             (when kill-buffer
3813               (gnus-kill-or-deaden-summary kill-buffer))
3814             ;; Return nil from this function.
3815             nil)
3816         ;; Hide conversation thread subtrees.  We cannot do this in
3817         ;; gnus-summary-prepare-hook since kill processing may not
3818         ;; work with hidden articles.
3819         (gnus-summary-maybe-hide-threads)
3820         (when kill-buffer
3821           (gnus-kill-or-deaden-summary kill-buffer))
3822         (gnus-summary-auto-select-subject)
3823         ;; Show first unread article if requested.
3824         (if (and (not no-article)
3825                  (not no-display)
3826                  gnus-newsgroup-unreads
3827                  gnus-auto-select-first)
3828             (progn
3829               (gnus-configure-windows 'summary)
3830               (let ((art (gnus-summary-article-number)))
3831                 (unless (and (not gnus-plugged)
3832                              (or (memq art gnus-newsgroup-undownloaded)
3833                                  (memq art gnus-newsgroup-downloadable)))
3834                   (gnus-summary-goto-article art))))
3835           ;; Don't select any articles.
3836           (gnus-summary-position-point)
3837           (gnus-configure-windows 'summary 'force)
3838           (gnus-set-mode-line 'summary))
3839         (when (and gnus-auto-center-group
3840                    (get-buffer-window gnus-group-buffer t))
3841           ;; Gotta use windows, because recenter does weird stuff if
3842           ;; the current buffer ain't the displayed window.
3843           (let ((owin (selected-window)))
3844             (select-window (get-buffer-window gnus-group-buffer t))
3845             (when (gnus-group-goto-group group)
3846               (recenter))
3847             (select-window owin)))
3848         ;; Mark this buffer as "prepared".
3849         (setq gnus-newsgroup-prepared t)
3850         (gnus-run-hooks 'gnus-summary-prepared-hook)
3851         (unless (gnus-ephemeral-group-p group)
3852           (gnus-group-update-group group))
3853         t)))))
3854
3855 (defun gnus-summary-auto-select-subject ()
3856   "Select the subject line on initial group entry."
3857   (goto-char (point-min))
3858   (cond
3859    ((eq gnus-auto-select-subject 'best)
3860     (gnus-summary-best-unread-subject))
3861    ((eq gnus-auto-select-subject 'unread)
3862     (gnus-summary-first-unread-subject))
3863    ((eq gnus-auto-select-subject 'unseen)
3864     (gnus-summary-first-unseen-subject))
3865    ((eq gnus-auto-select-subject 'unseen-or-unread)
3866     (gnus-summary-first-unseen-or-unread-subject))
3867    ((eq gnus-auto-select-subject 'first)
3868     ;; Do nothing.
3869     )
3870    ((functionp gnus-auto-select-subject)
3871     (funcall gnus-auto-select-subject))))
3872
3873 (defun gnus-summary-prepare ()
3874   "Generate the summary buffer."
3875   (interactive)
3876   (let ((buffer-read-only nil))
3877     (erase-buffer)
3878     (setq gnus-newsgroup-data nil
3879           gnus-newsgroup-data-reverse nil)
3880     (gnus-run-hooks 'gnus-summary-generate-hook)
3881     ;; Generate the buffer, either with threads or without.
3882     (when gnus-newsgroup-headers
3883       (gnus-summary-prepare-threads
3884        (if gnus-show-threads
3885            (gnus-sort-gathered-threads
3886             (funcall gnus-summary-thread-gathering-function
3887                      (gnus-sort-threads
3888                       (gnus-cut-threads (gnus-make-threads)))))
3889          ;; Unthreaded display.
3890          (gnus-sort-articles gnus-newsgroup-headers))))
3891     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3892     ;; Call hooks for modifying summary buffer.
3893     (goto-char (point-min))
3894     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3895
3896 (defsubst gnus-general-simplify-subject (subject)
3897   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3898   (setq subject
3899         (cond
3900          ;; Truncate the subject.
3901          (gnus-simplify-subject-functions
3902           (gnus-map-function gnus-simplify-subject-functions subject))
3903          ((numberp gnus-summary-gather-subject-limit)
3904           (setq subject (gnus-simplify-subject-re subject))
3905           (if (> (length subject) gnus-summary-gather-subject-limit)
3906               (substring subject 0 gnus-summary-gather-subject-limit)
3907             subject))
3908          ;; Fuzzily simplify it.
3909          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3910           (gnus-simplify-subject-fuzzy subject))
3911          ;; Just remove the leading "Re:".
3912          (t
3913           (gnus-simplify-subject-re subject))))
3914
3915   (if (and gnus-summary-gather-exclude-subject
3916            (string-match gnus-summary-gather-exclude-subject subject))
3917       nil                               ; This article shouldn't be gathered
3918     subject))
3919
3920 (defun gnus-summary-simplify-subject-query ()
3921   "Query where the respool algorithm would put this article."
3922   (interactive)
3923   (gnus-summary-select-article)
3924   (message "%s"
3925            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3926
3927 (defun gnus-gather-threads-by-subject (threads)
3928   "Gather threads by looking at Subject headers."
3929   (if (not gnus-summary-make-false-root)
3930       threads
3931     (let ((hashtb (gnus-make-hashtable 1024))
3932           (prev threads)
3933           (result threads)
3934           subject hthread whole-subject)
3935       (while threads
3936         (setq subject (gnus-general-simplify-subject
3937                        (setq whole-subject (mail-header-subject
3938                                             (caar threads)))))
3939         (when subject
3940           (if (setq hthread (gnus-gethash subject hashtb))
3941               (progn
3942                 ;; We enter a dummy root into the thread, if we
3943                 ;; haven't done that already.
3944                 (unless (stringp (caar hthread))
3945                   (setcar hthread (list whole-subject (car hthread))))
3946                 ;; We add this new gathered thread to this gathered
3947                 ;; thread.
3948                 (setcdr (car hthread)
3949                         (nconc (cdar hthread) (list (car threads))))
3950                 ;; Remove it from the list of threads.
3951                 (setcdr prev (cdr threads))
3952                 (setq threads prev))
3953             ;; Enter this thread into the hash table.
3954             (gnus-sethash subject
3955                           (if gnus-summary-make-false-root-always
3956                               (progn
3957                                 ;; If you want a dummy root above all
3958                                 ;; threads...
3959                                 (setcar threads (list whole-subject
3960                                                       (car threads)))
3961                                 threads)
3962                             threads)
3963                           hashtb)))
3964         (setq prev threads)
3965         (setq threads (cdr threads)))
3966       result)))
3967
3968 (defun gnus-gather-threads-by-references (threads)
3969   "Gather threads by looking at References headers."
3970   (let ((idhashtb (gnus-make-hashtable 1024))
3971         (thhashtb (gnus-make-hashtable 1024))
3972         (prev threads)
3973         (result threads)
3974         ids references id gthread gid entered ref)
3975     (while threads
3976       (when (setq references (mail-header-references (caar threads)))
3977         (setq id (mail-header-id (caar threads))
3978               ids (inline (gnus-split-references references))
3979               entered nil)
3980         (while (setq ref (pop ids))
3981           (setq ids (delete ref ids))
3982           (if (not (setq gid (gnus-gethash ref idhashtb)))
3983               (progn
3984                 (gnus-sethash ref id idhashtb)
3985                 (gnus-sethash id threads thhashtb))
3986             (setq gthread (gnus-gethash gid thhashtb))
3987             (unless entered
3988               ;; We enter a dummy root into the thread, if we
3989               ;; haven't done that already.
3990               (unless (stringp (caar gthread))
3991                 (setcar gthread (list (mail-header-subject (caar gthread))
3992                                       (car gthread))))
3993               ;; We add this new gathered thread to this gathered
3994               ;; thread.
3995               (setcdr (car gthread)
3996                       (nconc (cdar gthread) (list (car threads)))))
3997             ;; Add it into the thread hash table.
3998             (gnus-sethash id gthread thhashtb)
3999             (setq entered t)
4000             ;; Remove it from the list of threads.
4001             (setcdr prev (cdr threads))
4002             (setq threads prev))))
4003       (setq prev threads)
4004       (setq threads (cdr threads)))
4005     result))
4006
4007 (defun gnus-sort-gathered-threads (threads)
4008   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4009   (let ((result threads))
4010     (while threads
4011       (when (stringp (caar threads))
4012         (setcdr (car threads)
4013                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4014       (setq threads (cdr threads)))
4015     result))
4016
4017 (defun gnus-thread-loop-p (root thread)
4018   "Say whether ROOT is in THREAD."
4019   (let ((stack (list thread))
4020         (infloop 0)
4021         th)
4022     (while (setq thread (pop stack))
4023       (setq th (cdr thread))
4024       (while (and th
4025                   (not (eq (caar th) root)))
4026         (pop th))
4027       (if th
4028           ;; We have found a loop.
4029           (let (ref-dep)
4030             (setcdr thread (delq (car th) (cdr thread)))
4031             (if (boundp (setq ref-dep (intern "none"
4032                                               gnus-newsgroup-dependencies)))
4033                 (setcdr (symbol-value ref-dep)
4034                         (nconc (cdr (symbol-value ref-dep))
4035                                (list (car th))))
4036               (set ref-dep (list nil (car th))))
4037             (setq infloop 1
4038                   stack nil))
4039         ;; Push all the subthreads onto the stack.
4040         (push (cdr thread) stack)))
4041     infloop))
4042
4043 (defun gnus-make-threads ()
4044   "Go through the dependency hashtb and find the roots.  Return all threads."
4045   (let (threads)
4046     (while (catch 'infloop
4047              (mapatoms
4048               (lambda (refs)
4049                 ;; Deal with self-referencing References loops.
4050                 (when (and (car (symbol-value refs))
4051                            (not (zerop
4052                                  (apply
4053                                   '+
4054                                   (mapcar
4055                                    (lambda (thread)
4056                                      (gnus-thread-loop-p
4057                                       (car (symbol-value refs)) thread))
4058                                    (cdr (symbol-value refs)))))))
4059                   (setq threads nil)
4060                   (throw 'infloop t))
4061                 (unless (car (symbol-value refs))
4062                   ;; These threads do not refer back to any other articles,
4063                   ;; so they're roots.
4064                   (setq threads (append (cdr (symbol-value refs)) threads))))
4065               gnus-newsgroup-dependencies)))
4066     threads))
4067
4068 ;; Build the thread tree.
4069 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4070   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4071
4072 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4073 if it was already present.
4074
4075 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4076 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4077 Message-IDs will be renamed to a unique Message-ID before being
4078 entered.
4079
4080 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4081   (let* ((id (mail-header-id header))
4082          (id-dep (and id (intern id dependencies)))
4083          parent-id ref ref-dep ref-header replaced)
4084     ;; Enter this `header' in the `dependencies' table.
4085     (cond
4086      ((not id-dep)
4087       (setq header nil))
4088      ;; The first two cases do the normal part: enter a new `header'
4089      ;; in the `dependencies' table.
4090      ((not (boundp id-dep))
4091       (set id-dep (list header)))
4092      ((null (car (symbol-value id-dep)))
4093       (setcar (symbol-value id-dep) header))
4094
4095      ;; From here the `header' was already present in the
4096      ;; `dependencies' table.
4097      (force-new
4098       ;; Overrides an existing entry;
4099       ;; just set the header part of the entry.
4100       (setcar (symbol-value id-dep) header)
4101       (setq replaced t))
4102
4103      ;; Renames the existing `header' to a unique Message-ID.
4104      ((not gnus-summary-ignore-duplicates)
4105       ;; An article with this Message-ID has already been seen.
4106       ;; We rename the Message-ID.
4107       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4108            (list header))
4109       (mail-header-set-id header id))
4110
4111      ;; The last case ignores an existing entry, except it adds any
4112      ;; additional Xrefs (in case the two articles came from different
4113      ;; servers.
4114      ;; Also sets `header' to `nil' meaning that the `dependencies'
4115      ;; table was *not* modified.
4116      (t
4117       (mail-header-set-xref
4118        (car (symbol-value id-dep))
4119        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4120                    "")
4121                (or (mail-header-xref header) "")))
4122       (setq header nil)))
4123
4124     (when (and header (not replaced))
4125       ;; First check that we are not creating a References loop.
4126       (setq parent-id (gnus-parent-id (mail-header-references header)))
4127       (setq ref parent-id)
4128       (while (and ref
4129                   (setq ref-dep (intern-soft ref dependencies))
4130                   (boundp ref-dep)
4131                   (setq ref-header (car (symbol-value ref-dep))))
4132         (if (string= id ref)
4133             ;; Yuk!  This is a reference loop.  Make the article be a
4134             ;; root article.
4135             (progn
4136               (mail-header-set-references (car (symbol-value id-dep)) "none")
4137               (setq ref nil)
4138               (setq parent-id nil))
4139           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4140       (setq ref-dep (intern (or parent-id "none") dependencies))
4141       (if (boundp ref-dep)
4142           (setcdr (symbol-value ref-dep)
4143                   (nconc (cdr (symbol-value ref-dep))
4144                          (list (symbol-value id-dep))))
4145         (set ref-dep (list nil (symbol-value id-dep)))))
4146     header))
4147
4148 (defun gnus-extract-message-id-from-in-reply-to (string)
4149   (if (string-match "<[^>]+>" string)
4150       (substring string (match-beginning 0) (match-end 0))
4151     nil))
4152
4153 (defun gnus-build-sparse-threads ()
4154   (let ((headers gnus-newsgroup-headers)
4155         (mail-parse-charset gnus-newsgroup-charset)
4156         (gnus-summary-ignore-duplicates t)
4157         header references generation relations
4158         subject child end new-child date)
4159     ;; First we create an alist of generations/relations, where
4160     ;; generations is how much we trust the relation, and the relation
4161     ;; is parent/child.
4162     (gnus-message 7 "Making sparse threads...")
4163     (save-excursion
4164       (nnheader-set-temp-buffer " *gnus sparse threads*")
4165       (while (setq header (pop headers))
4166         (when (and (setq references (mail-header-references header))
4167                    (not (string= references "")))
4168           (insert references)
4169           (setq child (mail-header-id header)
4170                 subject (mail-header-subject header)
4171                 date (mail-header-date header)
4172                 generation 0)
4173           (while (search-backward ">" nil t)
4174             (setq end (1+ (point)))
4175             (when (search-backward "<" nil t)
4176               (setq new-child (buffer-substring (point) end))
4177               (push (list (incf generation)
4178                           child (setq child new-child)
4179                           subject date)
4180                     relations)))
4181           (when child
4182             (push (list (1+ generation) child nil subject) relations))
4183           (erase-buffer)))
4184       (kill-buffer (current-buffer)))
4185     ;; Sort over trustworthiness.
4186     (mapcar
4187      (lambda (relation)
4188        (when (gnus-dependencies-add-header
4189               (make-full-mail-header-from-decoded-header
4190                gnus-reffed-article-number
4191                (nth 3 relation) "" (or (nth 4 relation) "")
4192                (nth 1 relation)
4193                (or (nth 2 relation) "") 0 0 "")
4194               gnus-newsgroup-dependencies nil)
4195          (push gnus-reffed-article-number gnus-newsgroup-limit)
4196          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4197          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4198                gnus-newsgroup-reads)
4199          (decf gnus-reffed-article-number)))
4200      (sort relations 'car-less-than-car))
4201     (gnus-message 7 "Making sparse threads...done")))
4202
4203 (defun gnus-build-old-threads ()
4204   ;; Look at all the articles that refer back to old articles, and
4205   ;; fetch the headers for the articles that aren't there.  This will
4206   ;; build complete threads - if the roots haven't been expired by the
4207   ;; server, that is.
4208   (let ((mail-parse-charset gnus-newsgroup-charset)
4209         id heads)
4210     (mapatoms
4211      (lambda (refs)
4212        (when (not (car (symbol-value refs)))
4213          (setq heads (cdr (symbol-value refs)))
4214          (while heads
4215            (if (memq (mail-header-number (caar heads))
4216                      gnus-newsgroup-dormant)
4217                (setq heads (cdr heads))
4218              (setq id (symbol-name refs))
4219              (while (and (setq id (gnus-build-get-header id))
4220                          (not (car (gnus-id-to-thread id)))))
4221              (setq heads nil)))))
4222      gnus-newsgroup-dependencies)))
4223
4224 (defsubst gnus-remove-odd-characters (string)
4225   "Translate STRING into something that doesn't contain weird characters."
4226   (mm-subst-char-in-string
4227    ?\r ?\-
4228    (mm-subst-char-in-string ?\n ?\- string t) t))
4229
4230 ;; This function has to be called with point after the article number
4231 ;; on the beginning of the line.
4232 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4233   (let ((eol (point-at-eol))
4234         (buffer (current-buffer))
4235         header references in-reply-to)
4236
4237     ;; overview: [num subject from date id refs chars lines misc]
4238     (unwind-protect
4239         (progn
4240           (narrow-to-region (point) eol)
4241           (unless (eobp)
4242             (forward-char))
4243
4244           (setq header
4245                 (make-full-mail-header
4246                  number                         ; number
4247                  (nnheader-nov-field)           ; subject
4248                  (nnheader-nov-field)           ; from
4249                  (nnheader-nov-field)           ; date
4250                  (nnheader-nov-read-message-id number)  ; id
4251                  (setq references (nnheader-nov-field)) ; refs
4252                  (nnheader-nov-read-integer)    ; chars
4253                  (nnheader-nov-read-integer)    ; lines
4254                  (unless (eobp)
4255                    (if (looking-at "Xref: ")
4256                        (goto-char (match-end 0)))
4257                    (nnheader-nov-field))        ; Xref
4258                  (nnheader-nov-parse-extra))))  ; extra
4259
4260       (widen))
4261
4262     (when (and (string= references "")
4263                (setq in-reply-to (mail-header-extra header))
4264                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4265       (mail-header-set-references
4266        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4267
4268     (when gnus-alter-header-function
4269       (funcall gnus-alter-header-function header))
4270     (gnus-dependencies-add-header header dependencies force-new)))
4271
4272 (defun gnus-build-get-header (id)
4273   "Look through the buffer of NOV lines and find the header to ID.
4274 Enter this line into the dependencies hash table, and return
4275 the id of the parent article (if any)."
4276   (let ((deps gnus-newsgroup-dependencies)
4277         found header)
4278     (prog1
4279         (save-excursion
4280           (set-buffer nntp-server-buffer)
4281           (let ((case-fold-search nil))
4282             (goto-char (point-min))
4283             (while (and (not found)
4284                         (search-forward id nil t))
4285               (beginning-of-line)
4286               (setq found (looking-at
4287                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4288                                    (regexp-quote id))))
4289               (or found (beginning-of-line 2)))
4290             (when found
4291               (beginning-of-line)
4292               (and
4293                (setq header (gnus-nov-parse-line
4294                              (read (current-buffer)) deps))
4295                (gnus-parent-id (mail-header-references header))))))
4296       (when header
4297         (let ((number (mail-header-number header)))
4298           (push number gnus-newsgroup-limit)
4299           (push header gnus-newsgroup-headers)
4300           (if (memq number gnus-newsgroup-unselected)
4301               (progn
4302                 (setq gnus-newsgroup-unreads
4303                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4304                                                number))
4305                 (setq gnus-newsgroup-unselected
4306                       (delq number gnus-newsgroup-unselected)))
4307             (push number gnus-newsgroup-ancient)))))))
4308
4309 (defun gnus-build-all-threads ()
4310   "Read all the headers."
4311   (let ((gnus-summary-ignore-duplicates t)
4312         (mail-parse-charset gnus-newsgroup-charset)
4313         (dependencies gnus-newsgroup-dependencies)
4314         header article)
4315     (save-excursion
4316       (set-buffer nntp-server-buffer)
4317       (let ((case-fold-search nil))
4318         (goto-char (point-min))
4319         (while (not (eobp))
4320           (ignore-errors
4321             (setq article (read (current-buffer))
4322                   header (gnus-nov-parse-line article dependencies)))
4323           (when header
4324             (with-current-buffer gnus-summary-buffer
4325               (push header gnus-newsgroup-headers)
4326               (if (memq (setq article (mail-header-number header))
4327                         gnus-newsgroup-unselected)
4328                   (progn
4329                     (setq gnus-newsgroup-unreads
4330                           (gnus-add-to-sorted-list
4331                            gnus-newsgroup-unreads article))
4332                     (setq gnus-newsgroup-unselected
4333                           (delq article gnus-newsgroup-unselected)))
4334                 (push article gnus-newsgroup-ancient)))
4335             (forward-line 1)))))))
4336
4337 (defun gnus-summary-update-article-line (article header)
4338   "Update the line for ARTICLE using HEADER."
4339   (let* ((id (mail-header-id header))
4340          (thread (gnus-id-to-thread id)))
4341     (unless thread
4342       (error "Article in no thread"))
4343     ;; Update the thread.
4344     (setcar thread header)
4345     (gnus-summary-goto-subject article)
4346     (let* ((datal (gnus-data-find-list article))
4347            (data (car datal))
4348            (buffer-read-only nil)
4349            (level (gnus-summary-thread-level)))
4350       (gnus-delete-line)
4351       (let ((inserted (- (point)
4352                          (progn
4353                            (gnus-summary-insert-line
4354                             header level nil
4355                             (memq article gnus-newsgroup-undownloaded)
4356                             (gnus-article-mark article)
4357                             (memq article gnus-newsgroup-replied)
4358                             (memq article gnus-newsgroup-expirable)
4359                             ;; Only insert the Subject string when it's different
4360                             ;; from the previous Subject string.
4361                             (if (and
4362                                  gnus-show-threads
4363                                  (gnus-subject-equal
4364                                   (condition-case ()
4365                                       (mail-header-subject
4366                                        (gnus-data-header
4367                                         (cadr
4368                                          (gnus-data-find-list
4369                                           article
4370                                           (gnus-data-list t)))))
4371                                     ;; Error on the side of excessive subjects.
4372                                     (error ""))
4373                                   (mail-header-subject header)))
4374                                 ""
4375                               (mail-header-subject header))
4376                             nil (cdr (assq article gnus-newsgroup-scored))
4377                             (memq article gnus-newsgroup-processable))
4378                            (point)))))
4379         (when (cdr datal)
4380           (gnus-data-update-list
4381            (cdr datal)
4382            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4383
4384 (defun gnus-summary-update-article (article &optional iheader)
4385   "Update ARTICLE in the summary buffer."
4386   (set-buffer gnus-summary-buffer)
4387   (let* ((header (gnus-summary-article-header article))
4388          (id (mail-header-id header))
4389          (data (gnus-data-find article))
4390          (thread (gnus-id-to-thread id))
4391          (references (mail-header-references header))
4392          (parent
4393           (gnus-id-to-thread
4394            (or (gnus-parent-id
4395                 (when (and references
4396                            (not (equal "" references)))
4397                   references))
4398                "none")))
4399          (buffer-read-only nil)
4400          (old (car thread)))
4401     (when thread
4402       (unless iheader
4403         (setcar thread nil)
4404         (when parent
4405           (delq thread parent)))
4406       (if (gnus-summary-insert-subject id header)
4407           ;; Set the (possibly) new article number in the data structure.
4408           (gnus-data-set-number data (gnus-id-to-article id))
4409         (setcar thread old)
4410         nil))))
4411
4412 (defun gnus-rebuild-thread (id &optional line)
4413   "Rebuild the thread containing ID.
4414 If LINE, insert the rebuilt thread starting on line LINE."
4415   (let ((buffer-read-only nil)
4416         old-pos current thread data)
4417     (if (not gnus-show-threads)
4418         (setq thread (list (car (gnus-id-to-thread id))))
4419       ;; Get the thread this article is part of.
4420       (setq thread (gnus-remove-thread id)))
4421     (setq old-pos (point-at-bol))
4422     (setq current (save-excursion
4423                     (and (re-search-backward "[\r\n]" nil t)
4424                          (gnus-summary-article-number))))
4425     ;; If this is a gathered thread, we have to go some re-gathering.
4426     (when (stringp (car thread))
4427       (let ((subject (car thread))
4428             roots thr)
4429         (setq thread (cdr thread))
4430         (while thread
4431           (unless (memq (setq thr (gnus-id-to-thread
4432                                    (gnus-root-id
4433                                     (mail-header-id (caar thread)))))
4434                         roots)
4435             (push thr roots))
4436           (setq thread (cdr thread)))
4437         ;; We now have all (unique) roots.
4438         (if (= (length roots) 1)
4439             ;; All the loose roots are now one solid root.
4440             (setq thread (car roots))
4441           (setq thread (cons subject (gnus-sort-threads roots))))))
4442     (let (threads)
4443       ;; We then insert this thread into the summary buffer.
4444       (when line
4445         (goto-char (point-min))
4446         (forward-line (1- line)))
4447       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4448         (if gnus-show-threads
4449             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4450           (gnus-summary-prepare-unthreaded thread))
4451         (setq data (nreverse gnus-newsgroup-data))
4452         (setq threads gnus-newsgroup-threads))
4453       ;; We splice the new data into the data structure.
4454       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4455       ;;!!! then we want to insert at the beginning of the buffer.
4456       ;;!!! That happens to be true with Gnus now, but that may
4457       ;;!!! change in the future.  Perhaps.
4458       (gnus-data-enter-list
4459        (if line nil current) data (- (point) old-pos))
4460       (setq gnus-newsgroup-threads
4461             (nconc threads gnus-newsgroup-threads))
4462       (gnus-data-compute-positions))))
4463
4464 (defun gnus-number-to-header (number)
4465   "Return the header for article NUMBER."
4466   (let ((headers gnus-newsgroup-headers))
4467     (while (and headers
4468                 (not (= number (mail-header-number (car headers)))))
4469       (pop headers))
4470     (when headers
4471       (car headers))))
4472
4473 (defun gnus-parent-headers (in-headers &optional generation)
4474   "Return the headers of the GENERATIONeth parent of HEADERS."
4475   (unless generation
4476     (setq generation 1))
4477   (let ((parent t)
4478         (headers in-headers)
4479         references)
4480     (while (and parent
4481                 (not (zerop generation))
4482                 (setq references (mail-header-references headers)))
4483       (setq headers (if (and references
4484                              (setq parent (gnus-parent-id references)))
4485                         (car (gnus-id-to-thread parent))
4486                       nil))
4487       (decf generation))
4488     (and (not (eq headers in-headers))
4489          headers)))
4490
4491 (defun gnus-id-to-thread (id)
4492   "Return the (sub-)thread where ID appears."
4493   (gnus-gethash id gnus-newsgroup-dependencies))
4494
4495 (defun gnus-id-to-article (id)
4496   "Return the article number of ID."
4497   (let ((thread (gnus-id-to-thread id)))
4498     (when (and thread
4499                (car thread))
4500       (mail-header-number (car thread)))))
4501
4502 (defun gnus-id-to-header (id)
4503   "Return the article headers of ID."
4504   (car (gnus-id-to-thread id)))
4505
4506 (defun gnus-article-displayed-root-p (article)
4507   "Say whether ARTICLE is a root(ish) article."
4508   (let ((level (gnus-summary-thread-level article))
4509         (refs (mail-header-references  (gnus-summary-article-header article)))
4510         particle)
4511     (cond
4512      ((null level) nil)
4513      ((zerop level) t)
4514      ((null refs) t)
4515      ((null (gnus-parent-id refs)) t)
4516      ((and (= 1 level)
4517            (null (setq particle (gnus-id-to-article
4518                                  (gnus-parent-id refs))))
4519            (null (gnus-summary-thread-level particle)))))))
4520
4521 (defun gnus-root-id (id)
4522   "Return the id of the root of the thread where ID appears."
4523   (let (last-id prev)
4524     (while (and id (setq prev (car (gnus-id-to-thread id))))
4525       (setq last-id id
4526             id (gnus-parent-id (mail-header-references prev))))
4527     last-id))
4528
4529 (defun gnus-articles-in-thread (thread)
4530   "Return the list of articles in THREAD."
4531   (cons (mail-header-number (car thread))
4532         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4533
4534 (defun gnus-remove-thread (id &optional dont-remove)
4535   "Remove the thread that has ID in it."
4536   (let (headers thread last-id)
4537     ;; First go up in this thread until we find the root.
4538     (setq last-id (gnus-root-id id)
4539           headers (message-flatten-list (gnus-id-to-thread last-id)))
4540     ;; We have now found the real root of this thread.  It might have
4541     ;; been gathered into some loose thread, so we have to search
4542     ;; through the threads to find the thread we wanted.
4543     (let ((threads gnus-newsgroup-threads)
4544           sub)
4545       (while threads
4546         (setq sub (car threads))
4547         (if (stringp (car sub))
4548             ;; This is a gathered thread, so we look at the roots
4549             ;; below it to find whether this article is in this
4550             ;; gathered root.
4551             (progn
4552               (setq sub (cdr sub))
4553               (while sub
4554                 (when (member (caar sub) headers)
4555                   (setq thread (car threads)
4556                         threads nil
4557                         sub nil))
4558                 (setq sub (cdr sub))))
4559           ;; It's an ordinary thread, so we check it.
4560           (when (eq (car sub) (car headers))
4561             (setq thread sub
4562                   threads nil)))
4563         (setq threads (cdr threads)))
4564       ;; If this article is in no thread, then it's a root.
4565       (if thread
4566           (unless dont-remove
4567             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4568         (setq thread (gnus-id-to-thread last-id)))
4569       (when thread
4570         (prog1
4571             thread                      ; We return this thread.
4572           (unless dont-remove
4573             (if (stringp (car thread))
4574                 (progn
4575                   ;; If we use dummy roots, then we have to remove the
4576                   ;; dummy root as well.
4577                   (when (eq gnus-summary-make-false-root 'dummy)
4578                     ;; We go to the dummy root by going to
4579                     ;; the first sub-"thread", and then one line up.
4580                     (gnus-summary-goto-article
4581                      (mail-header-number (caadr thread)))
4582                     (forward-line -1)
4583                     (gnus-delete-line)
4584                     (gnus-data-compute-positions))
4585                   (setq thread (cdr thread))
4586                   (while thread
4587                     (gnus-remove-thread-1 (car thread))
4588                     (setq thread (cdr thread))))
4589               (gnus-remove-thread-1 thread))))))))
4590
4591 (defun gnus-remove-thread-1 (thread)
4592   "Remove the thread THREAD recursively."
4593   (let ((number (mail-header-number (pop thread)))
4594         d)
4595     (setq thread (reverse thread))
4596     (while thread
4597       (gnus-remove-thread-1 (pop thread)))
4598     (when (setq d (gnus-data-find number))
4599       (goto-char (gnus-data-pos d))
4600       (gnus-summary-show-thread)
4601       (gnus-data-remove
4602        number
4603        (- (point-at-bol)
4604           (prog1
4605               (1+ (point-at-eol))
4606             (gnus-delete-line)))))))
4607
4608 (defun gnus-sort-threads-1 (threads func)
4609   (sort (mapcar (lambda (thread)
4610                   (cons (car thread)
4611                         (and (cdr thread)
4612                              (gnus-sort-threads-1 (cdr thread) func))))
4613                 threads) func))
4614
4615 (defun gnus-sort-threads (threads)
4616   "Sort THREADS."
4617   (if (not gnus-thread-sort-functions)
4618       threads
4619     (gnus-message 8 "Sorting threads...")
4620     (let ((max-lisp-eval-depth 5000))
4621       (prog1 (gnus-sort-threads-1
4622          threads
4623          (gnus-make-sort-function gnus-thread-sort-functions))
4624         (gnus-message 8 "Sorting threads...done")))))
4625
4626 (defun gnus-sort-articles (articles)
4627   "Sort ARTICLES."
4628   (when gnus-article-sort-functions
4629     (gnus-message 7 "Sorting articles...")
4630     (prog1
4631         (setq gnus-newsgroup-headers
4632               (sort articles (gnus-make-sort-function
4633                               gnus-article-sort-functions)))
4634       (gnus-message 7 "Sorting articles...done"))))
4635
4636 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4637 (defmacro gnus-thread-header (thread)
4638   "Return header of first article in THREAD.
4639 Note that THREAD must never, ever be anything else than a variable -
4640 using some other form will lead to serious barfage."
4641   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4642   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4643   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4644         (vector thread) 2))
4645
4646 (defsubst gnus-article-sort-by-number (h1 h2)
4647   "Sort articles by article number."
4648   (< (mail-header-number h1)
4649      (mail-header-number h2)))
4650
4651 (defun gnus-thread-sort-by-number (h1 h2)
4652   "Sort threads by root article number."
4653   (gnus-article-sort-by-number
4654    (gnus-thread-header h1) (gnus-thread-header h2)))
4655
4656 (defsubst gnus-article-sort-by-random (h1 h2)
4657   "Sort articles by article number."
4658   (zerop (random 2)))
4659
4660 (defun gnus-thread-sort-by-random (h1 h2)
4661   "Sort threads by root article number."
4662   (gnus-article-sort-by-random
4663    (gnus-thread-header h1) (gnus-thread-header h2)))
4664
4665 (defsubst gnus-article-sort-by-lines (h1 h2)
4666   "Sort articles by article Lines header."
4667   (< (mail-header-lines h1)
4668      (mail-header-lines h2)))
4669
4670 (defun gnus-thread-sort-by-lines (h1 h2)
4671   "Sort threads by root article Lines header."
4672   (gnus-article-sort-by-lines
4673    (gnus-thread-header h1) (gnus-thread-header h2)))
4674
4675 (defsubst gnus-article-sort-by-chars (h1 h2)
4676   "Sort articles by octet length."
4677   (< (mail-header-chars h1)
4678      (mail-header-chars h2)))
4679
4680 (defun gnus-thread-sort-by-chars (h1 h2)
4681   "Sort threads by root article octet length."
4682   (gnus-article-sort-by-chars
4683    (gnus-thread-header h1) (gnus-thread-header h2)))
4684
4685 (defsubst gnus-article-sort-by-author (h1 h2)
4686   "Sort articles by root author."
4687   (string-lessp
4688    (let ((addr (car (mime-entity-read-field h1 'From))))
4689      (or (std11-full-name-string addr)
4690          (std11-address-string addr)
4691          ""))
4692    (let ((addr (car (mime-entity-read-field h2 'From))))
4693      (or (std11-full-name-string addr)
4694          (std11-address-string addr)
4695          ""))
4696    ))
4697
4698 (defun gnus-thread-sort-by-author (h1 h2)
4699   "Sort threads by root author."
4700   (gnus-article-sort-by-author
4701    (gnus-thread-header h1)  (gnus-thread-header h2)))
4702
4703 (defsubst gnus-article-sort-by-recipient (h1 h2)
4704   "Sort articles by recipient."
4705   (string-lessp
4706    (let ((extract (funcall
4707                    gnus-extract-address-components
4708                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4709      (or (car extract) (cadr extract)))
4710    (let ((extract (funcall
4711                    gnus-extract-address-components
4712                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4713      (or (car extract) (cadr extract)))))
4714
4715 (defun gnus-thread-sort-by-recipient (h1 h2)
4716   "Sort threads by root recipient."
4717   (gnus-article-sort-by-recipient
4718    (gnus-thread-header h1) (gnus-thread-header h2)))
4719
4720 (defsubst gnus-article-sort-by-subject (h1 h2)
4721   "Sort articles by root subject."
4722   (string-lessp
4723    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4724    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4725
4726 (defun gnus-thread-sort-by-subject (h1 h2)
4727   "Sort threads by root subject."
4728   (gnus-article-sort-by-subject
4729    (gnus-thread-header h1) (gnus-thread-header h2)))
4730
4731 (defsubst gnus-article-sort-by-date (h1 h2)
4732   "Sort articles by root article date."
4733   (time-less-p
4734    (gnus-date-get-time (mail-header-date h1))
4735    (gnus-date-get-time (mail-header-date h2))))
4736
4737 (defun gnus-thread-sort-by-date (h1 h2)
4738   "Sort threads by root article date."
4739   (gnus-article-sort-by-date
4740    (gnus-thread-header h1) (gnus-thread-header h2)))
4741
4742 (defsubst gnus-article-sort-by-score (h1 h2)
4743   "Sort articles by root article score.
4744 Unscored articles will be counted as having a score of zero."
4745   (> (or (cdr (assq (mail-header-number h1)
4746                     gnus-newsgroup-scored))
4747          gnus-summary-default-score 0)
4748      (or (cdr (assq (mail-header-number h2)
4749                     gnus-newsgroup-scored))
4750          gnus-summary-default-score 0)))
4751
4752 (defun gnus-thread-sort-by-score (h1 h2)
4753   "Sort threads by root article score."
4754   (gnus-article-sort-by-score
4755    (gnus-thread-header h1) (gnus-thread-header h2)))
4756
4757 (defun gnus-thread-sort-by-total-score (h1 h2)
4758   "Sort threads by the sum of all scores in the thread.
4759 Unscored articles will be counted as having a score of zero."
4760   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4761
4762 (defun gnus-thread-total-score (thread)
4763   ;; This function find the total score of THREAD.
4764   (cond
4765    ((null thread)
4766     0)
4767    ((consp thread)
4768     (if (stringp (car thread))
4769         (apply gnus-thread-score-function 0
4770                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4771       (gnus-thread-total-score-1 thread)))
4772    (t
4773     (gnus-thread-total-score-1 (list thread)))))
4774
4775 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4776   "Sort threads such that the thread with the most recently arrived article comes first."
4777   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4778
4779 (defun gnus-thread-highest-number (thread)
4780   "Return the highest article number in THREAD."
4781   (apply 'max (mapcar (lambda (header)
4782                         (mail-header-number header))
4783                       (message-flatten-list thread))))
4784
4785 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4786   "Sort threads such that the thread with the most recently dated article comes first."
4787   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4788
4789 (defun gnus-thread-latest-date (thread)
4790   "Return the highest article date in THREAD."
4791   (let ((previous-time 0))
4792     (apply 'max
4793            (mapcar
4794             (lambda (header)
4795               (setq previous-time
4796                     (condition-case ()
4797                         (time-to-seconds (mail-header-parse-date
4798                                           (mail-header-date header)))
4799                       (error previous-time))))
4800             (sort
4801              (message-flatten-list thread)
4802              (lambda (h1 h2)
4803                (< (mail-header-number h1)
4804                   (mail-header-number h2))))))))
4805
4806 (defun gnus-thread-total-score-1 (root)
4807   ;; This function find the total score of the thread below ROOT.
4808   (setq root (car root))
4809   (apply gnus-thread-score-function
4810          (or (append
4811               (mapcar 'gnus-thread-total-score
4812                       (cdr (gnus-id-to-thread (mail-header-id root))))
4813               (when (> (mail-header-number root) 0)
4814                 (list (or (cdr (assq (mail-header-number root)
4815                                      gnus-newsgroup-scored))
4816                           gnus-summary-default-score 0))))
4817              (list gnus-summary-default-score)
4818              '(0))))
4819
4820 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4821 (defvar gnus-tmp-prev-subject nil)
4822 (defvar gnus-tmp-false-parent nil)
4823 (defvar gnus-tmp-root-expunged nil)
4824 (defvar gnus-tmp-dummy-line nil)
4825
4826 (eval-when-compile (defvar gnus-tmp-header))
4827 (defun gnus-extra-header (type &optional header)
4828   "Return the extra header of TYPE."
4829   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4830       ""))
4831
4832 (defvar gnus-tmp-thread-tree-header-string "")
4833
4834 (defcustom gnus-sum-thread-tree-root "> "
4835   "With %B spec, used for the root of a thread.
4836 If nil, use subject instead."
4837   :version "22.1"
4838   :type '(radio (const :format "%v  " nil) string)
4839   :group 'gnus-thread)
4840
4841 (defcustom gnus-sum-thread-tree-false-root "> "
4842   "With %B spec, used for a false root of a thread.
4843 If nil, use subject instead."
4844   :version "22.1"
4845   :type '(radio (const :format "%v  " nil) string)
4846   :group 'gnus-thread)
4847
4848 (defcustom gnus-sum-thread-tree-single-indent ""
4849   "With %B spec, used for a thread with just one message.
4850 If nil, use subject instead."
4851   :version "22.1"
4852   :type '(radio (const :format "%v  " nil) string)
4853   :group 'gnus-thread)
4854
4855 (defcustom gnus-sum-thread-tree-vertical "| "
4856   "With %B spec, used for drawing a vertical line."
4857   :version "22.1"
4858   :type 'string
4859   :group 'gnus-thread)
4860
4861 (defcustom gnus-sum-thread-tree-indent "  "
4862   "With %B spec, used for indenting."
4863   :version "22.1"
4864   :type 'string
4865   :group 'gnus-thread)
4866
4867 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4868   "With %B spec, used for a leaf with brothers."
4869   :version "22.1"
4870   :type 'string
4871   :group 'gnus-thread)
4872
4873 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4874   "With %B spec, used for a leaf without brothers."
4875   :version "22.1"
4876   :type 'string
4877   :group 'gnus-thread)
4878
4879 (defun gnus-summary-prepare-threads (threads)
4880   "Prepare summary buffer from THREADS and indentation LEVEL.
4881 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4882 or a straight list of headers."
4883   (gnus-message 7 "Generating summary...")
4884
4885   (setq gnus-newsgroup-threads threads)
4886   (beginning-of-line)
4887
4888   (let ((gnus-tmp-level 0)
4889         (default-score (or gnus-summary-default-score 0))
4890         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4891         (building-line-count gnus-summary-display-while-building)
4892         (building-count (integerp gnus-summary-display-while-building))
4893         thread number subject stack state gnus-tmp-gathered beg-match
4894         new-roots gnus-tmp-new-adopts thread-end simp-subject
4895         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4896         gnus-tmp-replied gnus-tmp-subject-or-nil
4897         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4898         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4899         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4900         tree-stack)
4901
4902     (setq gnus-tmp-prev-subject nil
4903           gnus-tmp-thread-tree-header-string "")
4904
4905     (if (vectorp (car threads))
4906         ;; If this is a straight (sic) list of headers, then a
4907         ;; threaded summary display isn't required, so we just create
4908         ;; an unthreaded one.
4909         (gnus-summary-prepare-unthreaded threads)
4910
4911       ;; Do the threaded display.
4912
4913       (if gnus-summary-display-while-building
4914           (switch-to-buffer (buffer-name)))
4915       (while (or threads stack gnus-tmp-new-adopts new-roots)
4916
4917         (if (and (= gnus-tmp-level 0)
4918                  (or (not stack)
4919                      (= (caar stack) 0))
4920                  (not gnus-tmp-false-parent)
4921                  (or gnus-tmp-new-adopts new-roots))
4922             (if gnus-tmp-new-adopts
4923                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4924                       thread (list (car gnus-tmp-new-adopts))
4925                       gnus-tmp-header (caar thread)
4926                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4927               (when new-roots
4928                 (setq thread (list (car new-roots))
4929                       gnus-tmp-header (caar thread)
4930                       new-roots (cdr new-roots))))
4931
4932           (if threads
4933               ;; If there are some threads, we do them before the
4934               ;; threads on the stack.
4935               (setq thread threads
4936                     gnus-tmp-header (caar thread))
4937             ;; There were no current threads, so we pop something off
4938             ;; the stack.
4939             (setq state (car stack)
4940                   gnus-tmp-level (car state)
4941                   tree-stack (cadr state)
4942                   thread (caddr state)
4943                   stack (cdr stack)
4944                   gnus-tmp-header (caar thread))))
4945
4946         (setq gnus-tmp-false-parent nil)
4947         (setq gnus-tmp-root-expunged nil)
4948         (setq thread-end nil)
4949
4950         (if (stringp gnus-tmp-header)
4951             ;; The header is a dummy root.
4952             (cond
4953              ((eq gnus-summary-make-false-root 'adopt)
4954               ;; We let the first article adopt the rest.
4955               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4956                                                (cddar thread)))
4957               (setq gnus-tmp-gathered
4958                     (nconc (mapcar
4959                             (lambda (h) (mail-header-number (car h)))
4960                             (cddar thread))
4961                            gnus-tmp-gathered))
4962               (setq thread (cons (list (caar thread)
4963                                        (cadar thread))
4964                                  (cdr thread)))
4965               (setq gnus-tmp-level -1
4966                     gnus-tmp-false-parent t))
4967              ((eq gnus-summary-make-false-root 'empty)
4968               ;; We print adopted articles with empty subject fields.
4969               (setq gnus-tmp-gathered
4970                     (nconc (mapcar
4971                             (lambda (h) (mail-header-number (car h)))
4972                             (cddar thread))
4973                            gnus-tmp-gathered))
4974               (setq gnus-tmp-level -1))
4975              ((eq gnus-summary-make-false-root 'dummy)
4976               ;; We remember that we probably want to output a dummy
4977               ;; root.
4978               (setq gnus-tmp-dummy-line gnus-tmp-header)
4979               (setq gnus-tmp-prev-subject gnus-tmp-header))
4980              (t
4981               ;; We do not make a root for the gathered
4982               ;; sub-threads at all.
4983               (setq gnus-tmp-level -1)))
4984
4985           (setq number (mail-header-number gnus-tmp-header)
4986                 subject (mail-header-subject gnus-tmp-header)
4987                 simp-subject (gnus-simplify-subject-fully subject))
4988
4989           (cond
4990            ;; If the thread has changed subject, we might want to make
4991            ;; this subthread into a root.
4992            ((and (null gnus-thread-ignore-subject)
4993                  (not (zerop gnus-tmp-level))
4994                  gnus-tmp-prev-subject
4995                  (not (string= gnus-tmp-prev-subject simp-subject)))
4996             (setq new-roots (nconc new-roots (list (car thread)))
4997                   thread-end t
4998                   gnus-tmp-header nil))
4999            ;; If the article lies outside the current limit,
5000            ;; then we do not display it.
5001            ((not (memq number gnus-newsgroup-limit))
5002             (setq gnus-tmp-gathered
5003                   (nconc (mapcar
5004                           (lambda (h) (mail-header-number (car h)))
5005                           (cdar thread))
5006                          gnus-tmp-gathered))
5007             (setq gnus-tmp-new-adopts (if (cdar thread)
5008                                           (append gnus-tmp-new-adopts
5009                                                   (cdar thread))
5010                                         gnus-tmp-new-adopts)
5011                   thread-end t
5012                   gnus-tmp-header nil)
5013             (when (zerop gnus-tmp-level)
5014               (setq gnus-tmp-root-expunged t)))
5015            ;; Perhaps this article is to be marked as read?
5016            ((and gnus-summary-mark-below
5017                  (< (or (cdr (assq number gnus-newsgroup-scored))
5018                         default-score)
5019                     gnus-summary-mark-below)
5020                  ;; Don't touch sparse articles.
5021                  (not (gnus-summary-article-sparse-p number))
5022                  (not (gnus-summary-article-ancient-p number)))
5023             (setq gnus-newsgroup-unreads
5024                   (delq number gnus-newsgroup-unreads))
5025             (if gnus-newsgroup-auto-expire
5026                 (setq gnus-newsgroup-expirable
5027                       (gnus-add-to-sorted-list
5028                        gnus-newsgroup-expirable number))
5029               (push (cons number gnus-low-score-mark)
5030                     gnus-newsgroup-reads))))
5031
5032           (when gnus-tmp-header
5033             ;; We may have an old dummy line to output before this
5034             ;; article.
5035             (when (and gnus-tmp-dummy-line
5036                        (gnus-subject-equal
5037                         gnus-tmp-dummy-line
5038                         (mail-header-subject gnus-tmp-header)))
5039               (gnus-summary-insert-dummy-line
5040                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5041               (setq gnus-tmp-dummy-line nil))
5042
5043             ;; Compute the mark.
5044             (setq gnus-tmp-unread (gnus-article-mark number))
5045
5046             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5047                                   gnus-tmp-header gnus-tmp-level)
5048                   gnus-newsgroup-data)
5049
5050             ;; Actually insert the line.
5051             (setq
5052              gnus-tmp-subject-or-nil
5053              (cond
5054               ((and gnus-thread-ignore-subject
5055                     gnus-tmp-prev-subject
5056                     (not (string= gnus-tmp-prev-subject simp-subject)))
5057                subject)
5058               ((zerop gnus-tmp-level)
5059                (if (and (eq gnus-summary-make-false-root 'empty)
5060                         (memq number gnus-tmp-gathered)
5061                         gnus-tmp-prev-subject
5062                         (string= gnus-tmp-prev-subject simp-subject))
5063                    gnus-summary-same-subject
5064                  subject))
5065               (t gnus-summary-same-subject)))
5066             (if (and (eq gnus-summary-make-false-root 'adopt)
5067                      (= gnus-tmp-level 1)
5068                      (memq number gnus-tmp-gathered))
5069                 (setq gnus-tmp-opening-bracket ?\<
5070                       gnus-tmp-closing-bracket ?\>)
5071               (setq gnus-tmp-opening-bracket ?\[
5072                     gnus-tmp-closing-bracket ?\]))
5073             (setq
5074              gnus-tmp-indentation
5075              (aref gnus-thread-indent-array gnus-tmp-level)
5076              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5077              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5078                                 gnus-summary-default-score 0)
5079              gnus-tmp-score-char
5080              (if (or (null gnus-summary-default-score)
5081                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5082                          gnus-summary-zcore-fuzz))
5083                  ?\ ;;;Whitespace
5084                (if (< gnus-tmp-score gnus-summary-default-score)
5085                    gnus-score-below-mark gnus-score-over-mark))
5086              gnus-tmp-replied
5087              (cond ((memq number gnus-newsgroup-processable)
5088                     gnus-process-mark)
5089                    ((memq number gnus-newsgroup-cached)
5090                     gnus-cached-mark)
5091                    ((memq number gnus-newsgroup-replied)
5092                     gnus-replied-mark)
5093                    ((memq number gnus-newsgroup-forwarded)
5094                     gnus-forwarded-mark)
5095                    ((memq number gnus-newsgroup-saved)
5096                     gnus-saved-mark)
5097                    ((memq number gnus-newsgroup-recent)
5098                     gnus-recent-mark)
5099                    ((memq number gnus-newsgroup-unseen)
5100                     gnus-unseen-mark)
5101                    (t gnus-no-mark))
5102              gnus-tmp-downloaded
5103              (cond ((memq number gnus-newsgroup-undownloaded)
5104                     gnus-undownloaded-mark)
5105                    (gnus-newsgroup-agentized
5106                     gnus-downloaded-mark)
5107                    (t
5108                     gnus-no-mark))
5109              gnus-tmp-from (mail-header-from gnus-tmp-header)
5110              gnus-tmp-name
5111              (cond
5112               ((string-match "<[^>]+> *$" gnus-tmp-from)
5113                (setq beg-match (match-beginning 0))
5114                (or (and (string-match "^\".+\"" gnus-tmp-from)
5115                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5116                    (substring gnus-tmp-from 0 beg-match)))
5117               ((string-match "(.+)" gnus-tmp-from)
5118                (substring gnus-tmp-from
5119                           (1+ (match-beginning 0)) (1- (match-end 0))))
5120               (t gnus-tmp-from))
5121
5122              ;; Do the %B string
5123              gnus-tmp-thread-tree-header-string
5124              (cond
5125               ((not gnus-show-threads) "")
5126               ((zerop gnus-tmp-level)
5127                (cond ((cdar thread)
5128                       (or gnus-sum-thread-tree-root subject))
5129                      (gnus-tmp-new-adopts
5130                       (or gnus-sum-thread-tree-false-root subject))
5131                      (t
5132                       (or gnus-sum-thread-tree-single-indent subject))))
5133               (t
5134                (concat (apply 'concat
5135                               (mapcar (lambda (item)
5136                                         (if (= item 1)
5137                                             gnus-sum-thread-tree-vertical
5138                                           gnus-sum-thread-tree-indent))
5139                                       (cdr (reverse tree-stack))))
5140                        (if (nth 1 thread)
5141                            gnus-sum-thread-tree-leaf-with-other
5142                          gnus-sum-thread-tree-single-leaf)))))
5143             (when (string= gnus-tmp-name "")
5144               (setq gnus-tmp-name gnus-tmp-from))
5145             (unless (numberp gnus-tmp-lines)
5146               (setq gnus-tmp-lines -1))
5147             (if (= gnus-tmp-lines -1)
5148                 (setq gnus-tmp-lines "?")
5149               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5150               (gnus-put-text-property
5151              (point)
5152              (progn (eval gnus-summary-line-format-spec) (point))
5153                'gnus-number number)
5154             (when gnus-visual-p
5155               (forward-line -1)
5156               (gnus-run-hooks 'gnus-summary-update-hook)
5157               (forward-line 1))
5158
5159             (setq gnus-tmp-prev-subject simp-subject)))
5160
5161         (when (nth 1 thread)
5162           (push (list (max 0 gnus-tmp-level)
5163                       (copy-sequence tree-stack)
5164                       (nthcdr 1 thread))
5165                 stack))
5166         (push (if (nth 1 thread) 1 0) tree-stack)
5167         (incf gnus-tmp-level)
5168         (setq threads (if thread-end nil (cdar thread)))
5169         (if gnus-summary-display-while-building
5170             (if building-count
5171                 (progn
5172                   ;; use a set frequency
5173                   (setq building-line-count (1- building-line-count))
5174                   (when (= building-line-count 0)
5175                     (sit-for 0)
5176                     (setq building-line-count
5177                           gnus-summary-display-while-building)))
5178               ;; always
5179               (sit-for 0)))
5180         (unless threads
5181           (setq gnus-tmp-level 0)))))
5182   (gnus-message 7 "Generating summary...done"))
5183
5184 (defun gnus-summary-prepare-unthreaded (headers)
5185   "Generate an unthreaded summary buffer based on HEADERS."
5186   (let (header number mark)
5187
5188     (beginning-of-line)
5189
5190     (while headers
5191       ;; We may have to root out some bad articles...
5192       (when (memq (setq number (mail-header-number
5193                                 (setq header (pop headers))))
5194                   gnus-newsgroup-limit)
5195         ;; Mark article as read when it has a low score.
5196         (when (and gnus-summary-mark-below
5197                    (< (or (cdr (assq number gnus-newsgroup-scored))
5198                           gnus-summary-default-score 0)
5199                       gnus-summary-mark-below)
5200                    (not (gnus-summary-article-ancient-p number)))
5201           (setq gnus-newsgroup-unreads
5202                 (delq number gnus-newsgroup-unreads))
5203           (if gnus-newsgroup-auto-expire
5204               (push number gnus-newsgroup-expirable)
5205             (push (cons number gnus-low-score-mark)
5206                   gnus-newsgroup-reads)))
5207
5208         (setq mark (gnus-article-mark number))
5209         (push (gnus-data-make number mark (1+ (point)) header 0)
5210               gnus-newsgroup-data)
5211         (gnus-summary-insert-line
5212          header 0 number
5213          (memq number gnus-newsgroup-undownloaded)
5214          mark (memq number gnus-newsgroup-replied)
5215          (memq number gnus-newsgroup-expirable)
5216          (mail-header-subject header) nil
5217          (cdr (assq number gnus-newsgroup-scored))
5218          (memq number gnus-newsgroup-processable))))))
5219
5220 (defun gnus-summary-remove-list-identifiers ()
5221   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5222   (let ((regexp (if (consp gnus-list-identifiers)
5223                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5224                   gnus-list-identifiers))
5225         changed subject)
5226     (when regexp
5227       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5228       (dolist (header gnus-newsgroup-headers)
5229         (setq subject (mail-header-subject header)
5230               changed nil)
5231         (while (string-match regexp subject)
5232           (setq subject
5233                 (concat (substring subject 0 (match-beginning 1))
5234                         (substring subject (match-end 0)))
5235                 changed t))
5236         (when changed
5237           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5238             (setq subject
5239                   (concat (substring subject 0 (match-beginning 1))
5240                           (substring subject (match-end 1)))))
5241           (mail-header-set-subject header subject))))))
5242
5243 (defun gnus-fetch-headers (articles)
5244   "Fetch headers of ARTICLES."
5245   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5246     (gnus-message 5 "Fetching headers for %s..." name)
5247     (prog1
5248         (if (eq 'nov
5249                 (setq gnus-headers-retrieved-by
5250                       (gnus-retrieve-headers
5251                        articles gnus-newsgroup-name
5252                        ;; We might want to fetch old headers, but
5253                        ;; not if there is only 1 article.
5254                        (and (or (and
5255                                  (not (eq gnus-fetch-old-headers 'some))
5256                                  (not (numberp gnus-fetch-old-headers)))
5257                                 (> (length articles) 1))
5258                             gnus-fetch-old-headers))))
5259             (gnus-get-newsgroup-headers-xover
5260              articles nil nil gnus-newsgroup-name t)
5261           (gnus-get-newsgroup-headers))
5262       (gnus-message 5 "Fetching headers for %s...done" name))))
5263
5264 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5265   "Select newsgroup GROUP.
5266 If READ-ALL is non-nil, all articles in the group are selected.
5267 If SELECT-ARTICLES, only select those articles from GROUP."
5268   (let* ((entry (gnus-group-entry group))
5269          ;;!!! Dirty hack; should be removed.
5270          (gnus-summary-ignore-duplicates
5271           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5272               t
5273             gnus-summary-ignore-duplicates))
5274          (info (nth 2 entry))
5275          articles fetched-articles cached)
5276
5277     (unless (gnus-check-server
5278              (set (make-local-variable 'gnus-current-select-method)
5279                   (gnus-find-method-for-group group)))
5280       (error "Couldn't open server"))
5281
5282     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5283         (gnus-activate-group group)     ; Or we can activate it...
5284         (progn                          ; Or we bug out.
5285           (when (equal major-mode 'gnus-summary-mode)
5286             (gnus-kill-buffer (current-buffer)))
5287           (error "Couldn't activate group %s: %s"
5288                  group (gnus-status-message group))))
5289
5290     (unless (gnus-request-group group t)
5291       (when (equal major-mode 'gnus-summary-mode)
5292         (gnus-kill-buffer (current-buffer)))
5293       (error "Couldn't request group %s: %s"
5294              group (gnus-status-message group)))
5295
5296     (when gnus-agent
5297       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5298
5299       (setq gnus-summary-use-undownloaded-faces
5300             (gnus-agent-find-parameter
5301              group
5302              'agent-enable-undownloaded-faces)))
5303
5304     (setq gnus-newsgroup-name group
5305           gnus-newsgroup-unselected nil
5306           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5307
5308     (let ((display (gnus-group-find-parameter group 'display)))
5309       (setq gnus-newsgroup-display
5310             (cond
5311              ((not (zerop (or (car-safe read-all) 0)))
5312               ;; The user entered the group with C-u SPC/RET, let's show
5313               ;; all articles.
5314               'gnus-not-ignore)
5315              ((eq display 'all)
5316               'gnus-not-ignore)
5317              ((arrayp display)
5318               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5319              ((numberp display)
5320               ;; The following is probably the "correct" solution, but
5321               ;; it makes Gnus fetch all headers and then limit the
5322               ;; articles (which is slow), so instead we hack the
5323               ;; select-articles parameter instead. -- Simon Josefsson
5324               ;; <jas@kth.se>
5325               ;;
5326               ;; (gnus-byte-compile
5327               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5328               ;;                         display)))))
5329               (setq select-articles
5330                     (gnus-uncompress-range
5331                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5332                              (if (> tmp 0)
5333                                  tmp
5334                                1))
5335                            (cdr (gnus-active group)))))
5336               nil)
5337              (t
5338               nil))))
5339
5340     (gnus-summary-setup-default-charset)
5341
5342     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5343     (when (gnus-virtual-group-p group)
5344       (setq cached gnus-newsgroup-cached))
5345
5346     (setq gnus-newsgroup-unreads
5347           (gnus-sorted-ndifference
5348            (gnus-sorted-ndifference gnus-newsgroup-unreads
5349                                     gnus-newsgroup-marked)
5350            gnus-newsgroup-dormant))
5351
5352     (setq gnus-newsgroup-processable nil)
5353
5354     (gnus-update-read-articles group gnus-newsgroup-unreads)
5355
5356     ;; Adjust and set lists of article marks.
5357     (when info
5358       (gnus-adjust-marked-articles info))
5359     (if (setq articles select-articles)
5360         (setq gnus-newsgroup-unselected
5361               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5362       (setq articles (gnus-articles-to-read group read-all)))
5363
5364     (cond
5365      ((null articles)
5366       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5367       'quit)
5368      ((eq articles 0) nil)
5369      (t
5370       ;; Init the dependencies hash table.
5371       (setq gnus-newsgroup-dependencies
5372             (gnus-make-hashtable (length articles)))
5373       (gnus-set-global-variables)
5374       ;; Retrieve the headers and read them in.
5375
5376       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5377
5378       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5379       (when cached
5380         (setq gnus-newsgroup-cached cached))
5381
5382       ;; Suppress duplicates?
5383       (when gnus-suppress-duplicates
5384         (gnus-dup-suppress-articles))
5385
5386       ;; Set the initial limit.
5387       (setq gnus-newsgroup-limit (copy-sequence articles))
5388       ;; Remove canceled articles from the list of unread articles.
5389       (setq fetched-articles
5390             (mapcar (lambda (headers) (mail-header-number headers))
5391                     gnus-newsgroup-headers))
5392       (setq gnus-newsgroup-articles fetched-articles)
5393       (setq gnus-newsgroup-unreads
5394             (gnus-sorted-nintersection
5395              gnus-newsgroup-unreads fetched-articles))
5396       (gnus-compute-unseen-list)
5397
5398       ;; Removed marked articles that do not exist.
5399       (gnus-update-missing-marks
5400        (gnus-sorted-difference articles fetched-articles))
5401       ;; We might want to build some more threads first.
5402       (when (and gnus-fetch-old-headers
5403                  (eq gnus-headers-retrieved-by 'nov))
5404         (if (eq gnus-fetch-old-headers 'invisible)
5405             (gnus-build-all-threads)
5406           (gnus-build-old-threads)))
5407       ;; Let the Gnus agent mark articles as read.
5408       (when gnus-agent
5409         (gnus-agent-get-undownloaded-list))
5410       ;; Remove list identifiers from subject
5411       (when gnus-list-identifiers
5412         (gnus-summary-remove-list-identifiers))
5413       ;; Check whether auto-expire is to be done in this group.
5414       (setq gnus-newsgroup-auto-expire
5415             (gnus-group-auto-expirable-p group))
5416       ;; Set up the article buffer now, if necessary.
5417       (unless gnus-single-article-buffer
5418         (gnus-article-setup-buffer))
5419       ;; First and last article in this newsgroup.
5420       (when gnus-newsgroup-headers
5421         (setq gnus-newsgroup-begin
5422               (mail-header-number (car gnus-newsgroup-headers))
5423               gnus-newsgroup-end
5424               (mail-header-number
5425                (gnus-last-element gnus-newsgroup-headers))))
5426       ;; GROUP is successfully selected.
5427       (or gnus-newsgroup-headers t)))))
5428
5429 (defun gnus-compute-unseen-list ()
5430   ;; The `seen' marks are treated specially.
5431   (if (not gnus-newsgroup-seen)
5432       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5433     (setq gnus-newsgroup-unseen
5434           (gnus-inverse-list-range-intersection
5435            gnus-newsgroup-articles gnus-newsgroup-seen))))
5436
5437 (defun gnus-summary-display-make-predicate (display)
5438   (require 'gnus-agent)
5439   (when (= (length display) 1)
5440     (setq display (car display)))
5441   (unless gnus-summary-display-cache
5442     (dolist (elem (append '((unread . unread)
5443                             (read . read)
5444                             (unseen . unseen))
5445                           gnus-article-mark-lists))
5446       (push (cons (cdr elem)
5447                   (gnus-byte-compile
5448                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5449             gnus-summary-display-cache)))
5450   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5451         (gnus-category-predicate-cache gnus-summary-display-cache))
5452     (gnus-get-predicate display)))
5453
5454 ;; Uses the dynamically bound `number' variable.
5455 (eval-when-compile
5456   (defvar number))
5457 (defun gnus-article-marked-p (type &optional article)
5458   (let ((article (or article number)))
5459     (cond
5460      ((eq type 'tick)
5461       (memq article gnus-newsgroup-marked))
5462      ((eq type 'spam)
5463       (memq article gnus-newsgroup-spam-marked))
5464      ((eq type 'unsend)
5465       (memq article gnus-newsgroup-unsendable))
5466      ((eq type 'undownload)
5467       (memq article gnus-newsgroup-undownloaded))
5468      ((eq type 'download)
5469       (memq article gnus-newsgroup-downloadable))
5470      ((eq type 'unread)
5471       (memq article gnus-newsgroup-unreads))
5472      ((eq type 'read)
5473       (memq article gnus-newsgroup-reads))
5474      ((eq type 'dormant)
5475       (memq article gnus-newsgroup-dormant) )
5476      ((eq type 'expire)
5477       (memq article gnus-newsgroup-expirable))
5478      ((eq type 'reply)
5479       (memq article gnus-newsgroup-replied))
5480      ((eq type 'killed)
5481       (memq article gnus-newsgroup-killed))
5482      ((eq type 'bookmark)
5483       (assq article gnus-newsgroup-bookmarks))
5484      ((eq type 'score)
5485       (assq article gnus-newsgroup-scored))
5486      ((eq type 'save)
5487       (memq article gnus-newsgroup-saved))
5488      ((eq type 'cache)
5489       (memq article gnus-newsgroup-cached))
5490      ((eq type 'forward)
5491       (memq article gnus-newsgroup-forwarded))
5492      ((eq type 'seen)
5493       (not (memq article gnus-newsgroup-unseen)))
5494      ((eq type 'recent)
5495       (memq article gnus-newsgroup-recent))
5496      (t t))))
5497
5498 (defun gnus-articles-to-read (group &optional read-all)
5499   "Find out what articles the user wants to read."
5500   (let* ((articles
5501           ;; Select all articles if `read-all' is non-nil, or if there
5502           ;; are no unread articles.
5503           (if (or read-all
5504                   (and (zerop (length gnus-newsgroup-marked))
5505                        (zerop (length gnus-newsgroup-unreads)))
5506                   ;; Fetch all if the predicate is non-nil.
5507                   gnus-newsgroup-display)
5508               ;; We want to select the headers for all the articles in
5509               ;; the group, so we select either all the active
5510               ;; articles in the group, or (if that's nil), the
5511               ;; articles in the cache.
5512               (or
5513                (gnus-uncompress-range (gnus-active group))
5514                (gnus-cache-articles-in-group group))
5515             ;; Select only the "normal" subset of articles.
5516             (gnus-sorted-nunion
5517              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5518              gnus-newsgroup-unreads)))
5519          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5520          (scored (length scored-list))
5521          (number (length articles))
5522          (marked (+ (length gnus-newsgroup-marked)
5523                     (length gnus-newsgroup-dormant)))
5524          (select
5525           (cond
5526            ((numberp read-all)
5527             read-all)
5528            ((numberp gnus-newsgroup-display)
5529             gnus-newsgroup-display)
5530            (t
5531             (condition-case ()
5532                 (cond
5533                  ((and (or (<= scored marked) (= scored number))
5534                        (numberp gnus-large-newsgroup)
5535                        (> number gnus-large-newsgroup))
5536                   (let* ((cursor-in-echo-area nil)
5537                          (initial (gnus-parameter-large-newsgroup-initial
5538                                    gnus-newsgroup-name))
5539                          (input
5540                           (read-string
5541                            (format
5542                             "How many articles from %s (%s %d): "
5543                             (gnus-limit-string
5544                              (gnus-group-decoded-name gnus-newsgroup-name)
5545                              35)
5546                             (if initial "max" "default")
5547                             number)
5548                            (if initial
5549                                (cons (number-to-string initial)
5550                                      0)))))
5551                     (if (string-match "^[ \t]*$" input) number input)))
5552                  ((and (> scored marked) (< scored number)
5553                        (> (- scored number) 20))
5554                   (let ((input
5555                          (read-string
5556                           (format "%s %s (%d scored, %d total): "
5557                                   "How many articles from"
5558                                   (gnus-group-decoded-name group)
5559                                   scored number))))
5560                     (if (string-match "^[ \t]*$" input)
5561                         number input)))
5562                  (t number))
5563               (quit
5564                (message "Quit getting the articles to read")
5565                nil))))))
5566     (setq select (if (stringp select) (string-to-number select) select))
5567     (if (or (null select) (zerop select))
5568         select
5569       (if (and (not (zerop scored)) (<= (abs select) scored))
5570           (progn
5571             (setq articles (sort scored-list '<))
5572             (setq number (length articles)))
5573         (setq articles (copy-sequence articles)))
5574
5575       (when (< (abs select) number)
5576         (if (< select 0)
5577             ;; Select the N oldest articles.
5578             (setcdr (nthcdr (1- (abs select)) articles) nil)
5579           ;; Select the N most recent articles.
5580           (setq articles (nthcdr (- number select) articles))))
5581       (setq gnus-newsgroup-unselected
5582             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5583       (when gnus-alter-articles-to-read-function
5584         (setq articles
5585               (sort
5586                (funcall gnus-alter-articles-to-read-function
5587                         gnus-newsgroup-name articles)
5588                '<)))
5589       articles)))
5590
5591 (defun gnus-killed-articles (killed articles)
5592   (let (out)
5593     (while articles
5594       (when (inline (gnus-member-of-range (car articles) killed))
5595         (push (car articles) out))
5596       (setq articles (cdr articles)))
5597     out))
5598
5599 (defun gnus-uncompress-marks (marks)
5600   "Uncompress the mark ranges in MARKS."
5601   (let ((uncompressed '(score bookmark))
5602         out)
5603     (while marks
5604       (if (memq (caar marks) uncompressed)
5605           (push (car marks) out)
5606         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5607       (setq marks (cdr marks)))
5608     out))
5609
5610 (defun gnus-article-mark-to-type (mark)
5611   "Return the type of MARK."
5612   (or (cadr (assq mark gnus-article-special-mark-lists))
5613       'list))
5614
5615 (defun gnus-article-unpropagatable-p (mark)
5616   "Return whether MARK should be propagated to back end."
5617   (memq mark gnus-article-unpropagated-mark-lists))
5618
5619 (defun gnus-adjust-marked-articles (info)
5620   "Set all article lists and remove all marks that are no longer valid."
5621   (let* ((marked-lists (gnus-info-marks info))
5622          (active (gnus-active (gnus-info-group info)))
5623          (min (car active))
5624          (max (cdr active))
5625          (types gnus-article-mark-lists)
5626          marks var articles article mark mark-type
5627          bgn end)
5628
5629     (dolist (marks marked-lists)
5630       (setq mark (car marks)
5631             mark-type (gnus-article-mark-to-type mark)
5632             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5633
5634       ;; We set the variable according to the type of the marks list,
5635       ;; and then adjust the marks to a subset of the active articles.
5636       (cond
5637        ;; Adjust "simple" lists - compressed yet unsorted
5638        ((eq mark-type 'list)
5639         ;; Simultaneously uncompress and clip to active range
5640         ;; See gnus-uncompress-range for a description of possible marks
5641         (let (l lh)
5642           (if (not (cadr marks))
5643               (set var nil)
5644             (setq articles (if (numberp (cddr marks))
5645                                (list (cdr marks))
5646                              (cdr marks))
5647                   lh (cons nil nil)
5648                   l lh)
5649
5650             (while (setq article (pop articles))
5651               (cond ((consp article)
5652                      (setq bgn (max (car article) min)
5653                            end (min (cdr article) max))
5654                      (while (<= bgn end)
5655                        (setq l (setcdr l (cons bgn nil))
5656                              bgn (1+ bgn))))
5657                     ((and (<= min article)
5658                           (>= max article))
5659                      (setq l (setcdr l (cons article nil))))))
5660             (set var (cdr lh)))))
5661        ;; Adjust assocs.
5662        ((eq mark-type 'tuple)
5663         (set var (setq articles (cdr marks)))
5664         (when (not (listp (cdr (symbol-value var))))
5665           (set var (list (symbol-value var))))
5666         (when (not (listp (cdr articles)))
5667           (setq articles (list articles)))
5668         (while articles
5669           (when (or (not (consp (setq article (pop articles))))
5670                     (< (car article) min)
5671                     (> (car article) max))
5672             (set var (delq article (symbol-value var))))))
5673        ;; Adjust ranges (sloppily).
5674        ((eq mark-type 'range)
5675         (cond
5676          ((eq mark 'seen)
5677           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5678           ;; It should be (seen (NUM1 . NUM2)).
5679           (when (numberp (cddr marks))
5680             (setcdr marks (list (cdr marks))))
5681           (setq articles (cdr marks))
5682           (while (and articles
5683                       (or (and (consp (car articles))
5684                                (> min (cdar articles)))
5685                           (and (numberp (car articles))
5686                                (> min (car articles)))))
5687             (pop articles))
5688           (set var articles))))))))
5689
5690 (defun gnus-update-missing-marks (missing)
5691   "Go through the list of MISSING articles and remove them from the mark lists."
5692   (when missing
5693     (let (var m)
5694       ;; Go through all types.
5695       (dolist (elem gnus-article-mark-lists)
5696         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5697           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5698           (when (symbol-value var)
5699             ;; This list has articles.  So we delete all missing
5700             ;; articles from it.
5701             (setq m missing)
5702             (while m
5703               (set var (delq (pop m) (symbol-value var))))))))))
5704
5705 (defun gnus-update-marks ()
5706   "Enter the various lists of marked articles into the newsgroup info list."
5707   (let ((types gnus-article-mark-lists)
5708         (info (gnus-get-info gnus-newsgroup-name))
5709         type list newmarked symbol delta-marks)
5710     (when info
5711       ;; Add all marks lists to the list of marks lists.
5712       (while (setq type (pop types))
5713         (setq list (symbol-value
5714                     (setq symbol
5715                           (intern (format "gnus-newsgroup-%s" (car type))))))
5716
5717         (when list
5718           ;; Get rid of the entries of the articles that have the
5719           ;; default score.
5720           (when (and (eq (cdr type) 'score)
5721                      gnus-save-score
5722                      list)
5723             (let* ((arts list)
5724                    (prev (cons nil list))
5725                    (all prev))
5726               (while arts
5727                 (if (or (not (consp (car arts)))
5728                         (= (cdar arts) gnus-summary-default-score))
5729                     (setcdr prev (cdr arts))
5730                   (setq prev arts))
5731                 (setq arts (cdr arts)))
5732               (setq list (cdr all)))))
5733
5734         (when (eq (cdr type) 'seen)
5735           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5736
5737         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5738           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5739
5740         (when (and (gnus-check-backend-function
5741                     'request-set-mark gnus-newsgroup-name)
5742                    (not (gnus-article-unpropagatable-p (cdr type))))
5743           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5744                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5745                  (add (gnus-remove-from-range
5746                        (gnus-copy-sequence list) old)))
5747             (when add
5748               (push (list add 'add (list (cdr type))) delta-marks))
5749             (when del
5750               (push (list del 'del (list (cdr type))) delta-marks))))
5751
5752         (when list
5753           (push (cons (cdr type) list) newmarked)))
5754
5755       (when delta-marks
5756         (unless (gnus-check-group gnus-newsgroup-name)
5757           (error "Can't open server for %s" gnus-newsgroup-name))
5758         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5759
5760       ;; Enter these new marks into the info of the group.
5761       (if (nthcdr 3 info)
5762           (setcar (nthcdr 3 info) newmarked)
5763         ;; Add the marks lists to the end of the info.
5764         (when newmarked
5765           (setcdr (nthcdr 2 info) (list newmarked))))
5766
5767       ;; Cut off the end of the info if there's nothing else there.
5768       (let ((i 5))
5769         (while (and (> i 2)
5770                     (not (nth i info)))
5771           (when (nthcdr (decf i) info)
5772             (setcdr (nthcdr i info) nil)))))))
5773
5774 (defun gnus-set-mode-line (where)
5775   "Set the mode line of the article or summary buffers.
5776 If WHERE is `summary', the summary mode line format will be used."
5777   ;; Is this mode line one we keep updated?
5778   (when (and (memq where gnus-updated-mode-lines)
5779              (symbol-value
5780               (intern (format "gnus-%s-mode-line-format-spec" where))))
5781     (let (mode-string)
5782       (save-excursion
5783         ;; We evaluate this in the summary buffer since these
5784         ;; variables are buffer-local to that buffer.
5785         (set-buffer gnus-summary-buffer)
5786         ;; We bind all these variables that are used in the `eval' form
5787         ;; below.
5788         (let* ((mformat (symbol-value
5789                          (intern
5790                           (format "gnus-%s-mode-line-format-spec" where))))
5791                (gnus-tmp-group-name (gnus-group-decoded-name
5792                                      gnus-newsgroup-name))
5793                (gnus-tmp-article-number (or gnus-current-article 0))
5794                (gnus-tmp-unread gnus-newsgroup-unreads)
5795                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5796                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5797                (gnus-tmp-unread-and-unselected
5798                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5799                             (zerop gnus-tmp-unselected))
5800                        "")
5801                       ((zerop gnus-tmp-unselected)
5802                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5803                       (t (format "{%d(+%d) more}"
5804                                  gnus-tmp-unread-and-unticked
5805                                  gnus-tmp-unselected))))
5806                (gnus-tmp-subject
5807                 (if (and gnus-current-headers
5808                          (vectorp gnus-current-headers))
5809                     (gnus-mode-string-quote
5810                      (mail-header-subject gnus-current-headers))
5811                   ""))
5812                bufname-length max-len
5813                gnus-tmp-header);; passed as argument to any user-format-funcs
5814           (setq mode-string (eval mformat))
5815           (setq bufname-length (if (string-match "%b" mode-string)
5816                                    (- (length
5817                                        (buffer-name
5818                                         (if (eq where 'summary)
5819                                             nil
5820                                           (get-buffer gnus-article-buffer))))
5821                                       2)
5822                                  0))
5823           (setq max-len (max 4 (if gnus-mode-non-string-length
5824                                    (- (window-width)
5825                                       gnus-mode-non-string-length
5826                                       bufname-length)
5827                                  (length mode-string))))
5828           ;; We might have to chop a bit of the string off...
5829           (when (> (length mode-string) max-len)
5830             (setq mode-string
5831                   (concat (gnus-truncate-string mode-string (- max-len 3))
5832                           "...")))
5833           ;; Pad the mode string a bit.
5834           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5835       ;; Update the mode line.
5836       (setq mode-line-buffer-identification
5837             (gnus-mode-line-buffer-identification (list mode-string)))
5838       (set-buffer-modified-p t))))
5839
5840 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5841   "Go through the HEADERS list and add all Xrefs to a hash table.
5842 The resulting hash table is returned, or nil if no Xrefs were found."
5843   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5844          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5845          (xref-hashtb (gnus-make-hashtable))
5846          start group entry number xrefs header)
5847     (while headers
5848       (setq header (pop headers))
5849       (when (and (setq xrefs (mail-header-xref header))
5850                  (not (memq (setq number (mail-header-number header))
5851                             unreads)))
5852         (setq start 0)
5853         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5854           (setq start (match-end 0))
5855           (setq group (if prefix
5856                           (concat prefix (substring xrefs (match-beginning 1)
5857                                                     (match-end 1)))
5858                         (substring xrefs (match-beginning 1) (match-end 1))))
5859           (setq number
5860                 (string-to-number (substring xrefs (match-beginning 2)
5861                                           (match-end 2))))
5862           (if (setq entry (gnus-gethash group xref-hashtb))
5863               (setcdr entry (cons number (cdr entry)))
5864             (gnus-sethash group (cons number nil) xref-hashtb)))))
5865     (and start xref-hashtb)))
5866
5867 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5868   "Look through all the headers and mark the Xrefs as read."
5869   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5870         name info xref-hashtb idlist method nth4)
5871     (save-excursion
5872       (set-buffer gnus-group-buffer)
5873       (when (setq xref-hashtb
5874                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5875         (mapatoms
5876          (lambda (group)
5877            (unless (string= from-newsgroup (setq name (symbol-name group)))
5878              (setq idlist (symbol-value group))
5879              ;; Dead groups are not updated.
5880              (and (prog1
5881                       (setq info (gnus-get-info name))
5882                     (when (stringp (setq nth4 (gnus-info-method info)))
5883                       (setq nth4 (gnus-server-to-method nth4))))
5884                   ;; Only do the xrefs if the group has the same
5885                   ;; select method as the group we have just read.
5886                   (or (gnus-methods-equal-p
5887                        nth4 (gnus-find-method-for-group from-newsgroup))
5888                       virtual
5889                       (equal nth4 (setq method (gnus-find-method-for-group
5890                                                 from-newsgroup)))
5891                       (and (equal (car nth4) (car method))
5892                            (equal (nth 1 nth4) (nth 1 method))))
5893                   gnus-use-cross-reference
5894                   (or (not (eq gnus-use-cross-reference t))
5895                       virtual
5896                       ;; Only do cross-references on subscribed
5897                       ;; groups, if that is what is wanted.
5898                       (<= (gnus-info-level info) gnus-level-subscribed))
5899                   (gnus-group-make-articles-read name idlist))))
5900          xref-hashtb)))))
5901
5902 (defun gnus-compute-read-articles (group articles)
5903   (let* ((entry (gnus-group-entry group))
5904          (info (nth 2 entry))
5905          (active (gnus-active group))
5906          ninfo)
5907     (when entry
5908       ;; First peel off all invalid article numbers.
5909       (when active
5910         (let ((ids articles)
5911               id first)
5912           (while (setq id (pop ids))
5913             (when (and first (> id (cdr active)))
5914               ;; We'll end up in this situation in one particular
5915               ;; obscure situation.  If you re-scan a group and get
5916               ;; a new article that is cross-posted to a different
5917               ;; group that has not been re-scanned, you might get
5918               ;; crossposted article that has a higher number than
5919               ;; Gnus believes possible.  So we re-activate this
5920               ;; group as well.  This might mean doing the
5921               ;; crossposting thingy will *increase* the number
5922               ;; of articles in some groups.  Tsk, tsk.
5923               (setq active (or (gnus-activate-group group) active)))
5924             (when (or (> id (cdr active))
5925                       (< id (car active)))
5926               (setq articles (delq id articles))))))
5927       ;; If the read list is nil, we init it.
5928       (if (and active
5929                (null (gnus-info-read info))
5930                (> (car active) 1))
5931           (setq ninfo (cons 1 (1- (car active))))
5932         (setq ninfo (gnus-info-read info)))
5933       ;; Then we add the read articles to the range.
5934       (gnus-add-to-range
5935        ninfo (setq articles (sort articles '<))))))
5936
5937 (defun gnus-group-make-articles-read (group articles)
5938   "Update the info of GROUP to say that ARTICLES are read."
5939   (let* ((num 0)
5940          (entry (gnus-group-entry group))
5941          (info (nth 2 entry))
5942          (active (gnus-active group))
5943          range)
5944     (when entry
5945       (setq range (gnus-compute-read-articles group articles))
5946       (with-current-buffer gnus-group-buffer
5947         (gnus-undo-register
5948           `(progn
5949              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5950              (gnus-info-set-read ',info ',(gnus-info-read info))
5951              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5952              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5953              (gnus-group-update-group ,group t))))
5954       ;; Add the read articles to the range.
5955       (gnus-info-set-read info range)
5956       (gnus-request-set-mark group (list (list range 'add '(read))))
5957       ;; Then we have to re-compute how many unread
5958       ;; articles there are in this group.
5959       (when active
5960         (cond
5961          ((not range)
5962           (setq num (- (1+ (cdr active)) (car active))))
5963          ((not (listp (cdr range)))
5964           (setq num (- (cdr active) (- (1+ (cdr range))
5965                                        (car range)))))
5966          (t
5967           (while range
5968             (if (numberp (car range))
5969                 (setq num (1+ num))
5970               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5971             (setq range (cdr range)))
5972           (setq num (- (cdr active) num))))
5973         ;; Update the number of unread articles.
5974         (setcar entry num)
5975         ;; Update the group buffer.
5976         (unless (gnus-ephemeral-group-p group)
5977           (gnus-group-update-group group t))))))
5978
5979 (defvar gnus-newsgroup-none-id 0)
5980
5981 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5982   (let ((cur nntp-server-buffer)
5983         (dependencies
5984          (or dependencies
5985              (with-current-buffer gnus-summary-buffer
5986                gnus-newsgroup-dependencies)))
5987         headers id end ref number
5988         (mail-parse-charset gnus-newsgroup-charset)
5989         (mail-parse-ignored-charsets
5990          (save-excursion (condition-case nil
5991                              (set-buffer gnus-summary-buffer)
5992                            (error))
5993                          gnus-newsgroup-ignored-charsets)))
5994     (save-excursion
5995       (set-buffer nntp-server-buffer)
5996       ;; Translate all TAB characters into SPACE characters.
5997       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5998       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5999       (ietf-drums-unfold-fws)
6000       (gnus-run-hooks 'gnus-parse-headers-hook)
6001       (let ((case-fold-search t)
6002             in-reply-to header p lines chars ctype)
6003         (goto-char (point-min))
6004         ;; Search to the beginning of the next header.  Error messages
6005         ;; do not begin with 2 or 3.
6006         (while (re-search-forward "^[23][0-9]+ " nil t)
6007           (setq id nil
6008                 ref nil)
6009           ;; This implementation of this function, with nine
6010           ;; search-forwards instead of the one re-search-forward and
6011           ;; a case (which basically was the old function) is actually
6012           ;; about twice as fast, even though it looks messier.  You
6013           ;; can't have everything, I guess.  Speed and elegance
6014           ;; doesn't always go hand in hand.
6015           (setq
6016            header
6017            (make-full-mail-header
6018             ;; Number.
6019             (prog1
6020                 (setq number (read cur))
6021               (end-of-line)
6022               (setq p (point))
6023               (narrow-to-region (point)
6024                                 (or (and (search-forward "\n.\n" nil t)
6025                                          (- (point) 2))
6026                                     (point))))
6027             ;; Subject.
6028             (progn
6029               (goto-char p)
6030               (if (search-forward "\nsubject:" nil t)
6031                   (nnheader-header-value)
6032                 "(none)"))
6033             ;; From.
6034             (progn
6035               (goto-char p)
6036               (if (search-forward "\nfrom:" nil t)
6037                   (nnheader-header-value)
6038                 "(nobody)"))
6039             ;; Date.
6040             (progn
6041               (goto-char p)
6042               (if (search-forward "\ndate:" nil t)
6043                   (nnheader-header-value) ""))
6044             ;; Message-ID.
6045             (progn
6046               (goto-char p)
6047               (setq id (if (re-search-forward
6048                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6049                            ;; We do it this way to make sure the Message-ID
6050                            ;; is (somewhat) syntactically valid.
6051                            (buffer-substring (match-beginning 1)
6052                                              (match-end 1))
6053                          ;; If there was no message-id, we just fake one
6054                          ;; to make subsequent routines simpler.
6055                          (nnheader-generate-fake-message-id number))))
6056             ;; References.
6057             (progn
6058               (goto-char p)
6059               (if (search-forward "\nreferences:" nil t)
6060                   (progn
6061                     (setq end (point))
6062                     (prog1
6063                         (nnheader-header-value)
6064                       (setq ref
6065                             (buffer-substring
6066                              (progn
6067                                ;; (end-of-line)
6068                                (search-backward ">" end t)
6069                                (1+ (point)))
6070                              (progn
6071                                (search-backward "<" end t)
6072                                (point))))))
6073                 ;; Get the references from the in-reply-to header if there
6074                 ;; were no references and the in-reply-to header looks
6075                 ;; promising.
6076                 (if (and (search-forward "\nin-reply-to:" nil t)
6077                          (setq in-reply-to (nnheader-header-value))
6078                          (string-match "<[^>]+>" in-reply-to))
6079                     (let (ref2)
6080                       (setq ref (substring in-reply-to (match-beginning 0)
6081                                            (match-end 0)))
6082                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6083                         (setq ref2 (substring in-reply-to (match-beginning 0)
6084                                               (match-end 0)))
6085                         (when (> (length ref2) (length ref))
6086                           (setq ref ref2)))
6087                       ref)
6088                   (setq ref nil))))
6089             ;; Chars.
6090             (progn
6091               (goto-char p)
6092               (if (search-forward "\nchars: " nil t)
6093                   (if (numberp (setq chars (ignore-errors (read cur))))
6094                       chars -1)
6095                 -1))
6096             ;; Lines.
6097             (progn
6098               (goto-char p)
6099               (if (search-forward "\nlines: " nil t)
6100                   (if (numberp (setq lines (ignore-errors (read cur))))
6101                       lines -1)
6102                 -1))
6103             ;; Xref.
6104             (progn
6105               (goto-char p)
6106               (and (search-forward "\nxref:" nil t)
6107                    (nnheader-header-value)))
6108             ;; Extra.
6109             (when gnus-extra-headers
6110               (let ((extra gnus-extra-headers)
6111                     out)
6112                 (while extra
6113                   (goto-char p)
6114                   (when (search-forward
6115                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6116                     (push (cons (car extra) (nnheader-header-value)) out))
6117                   (pop extra))
6118                 out))))
6119           (goto-char p)
6120           (if (and (search-forward "\ncontent-type: " nil t)
6121                    (setq ctype (nnheader-header-value)))
6122               (mime-entity-set-content-type-internal
6123                header (mime-parse-Content-Type ctype)))
6124           (when (equal id ref)
6125             (setq ref nil))
6126
6127           (when gnus-alter-header-function
6128             (funcall gnus-alter-header-function header)
6129             (setq id (mail-header-id header)
6130                   ref (gnus-parent-id (mail-header-references header))))
6131
6132           (when (setq header
6133                       (gnus-dependencies-add-header
6134                        header dependencies force-new))
6135             (push header headers))
6136           (goto-char (point-max))
6137           (widen))
6138         (nreverse headers)))))
6139
6140 ;; Goes through the xover lines and returns a list of vectors
6141 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6142                                                   force-new dependencies
6143                                                   group also-fetch-heads)
6144   "Parse the news overview data in the server buffer.
6145 Return a list of headers that match SEQUENCE (see
6146 `nntp-retrieve-headers')."
6147   ;; Get the Xref when the users reads the articles since most/some
6148   ;; NNTP servers do not include Xrefs when using XOVER.
6149   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6150   (let ((mail-parse-charset gnus-newsgroup-charset)
6151         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6152         (cur nntp-server-buffer)
6153         (dependencies (or dependencies gnus-newsgroup-dependencies))
6154         (allp (cond
6155                ((eq gnus-read-all-available-headers t)
6156                 t)
6157                ((stringp gnus-read-all-available-headers)
6158                 (string-match gnus-read-all-available-headers group))
6159                (t
6160                 nil)))
6161         number headers header)
6162     (save-excursion
6163       (set-buffer nntp-server-buffer)
6164       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6165       ;; Allow the user to mangle the headers before parsing them.
6166       (gnus-run-hooks 'gnus-parse-headers-hook)
6167       (goto-char (point-min))
6168       (gnus-parse-without-error
6169         (while (and (or sequence allp)
6170                     (not (eobp)))
6171           (setq number (read cur))
6172           (when (not allp)
6173             (while (and sequence
6174                         (< (car sequence) number))
6175               (setq sequence (cdr sequence))))
6176           (when (and (or allp
6177                          (and sequence
6178                               (eq number (car sequence))))
6179                      (progn
6180                        (setq sequence (cdr sequence))
6181                        (setq header (inline
6182                                       (gnus-nov-parse-line
6183                                        number dependencies force-new)))))
6184             (push header headers))
6185           (forward-line 1)))
6186       ;; A common bug in inn is that if you have posted an article and
6187       ;; then retrieves the active file, it will answer correctly --
6188       ;; the new article is included.  However, a NOV entry for the
6189       ;; article may not have been generated yet, so this may fail.
6190       ;; We work around this problem by retrieving the last few
6191       ;; headers using HEAD.
6192       (if (or (not also-fetch-heads)
6193               (not sequence))
6194           ;; We (probably) got all the headers.
6195           (nreverse headers)
6196         (let ((gnus-nov-is-evil t))
6197           (nconc
6198            (nreverse headers)
6199            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6200              (gnus-get-newsgroup-headers))))))))
6201
6202 (defun gnus-article-get-xrefs ()
6203   "Fill in the Xref value in `gnus-current-headers', if necessary.
6204 This is meant to be called in `gnus-article-internal-prepare-hook'."
6205   (let ((headers (with-current-buffer gnus-summary-buffer
6206                    gnus-current-headers)))
6207     (or (not gnus-use-cross-reference)
6208         (not headers)
6209         (and (mail-header-xref headers)
6210              (not (string= (mail-header-xref headers) "")))
6211         (let ((case-fold-search t)
6212               xref)
6213           (save-restriction
6214             (nnheader-narrow-to-headers)
6215             (goto-char (point-min))
6216             (when (or (and (not (eobp))
6217                            (eq (downcase (char-after)) ?x)
6218                            (looking-at "Xref:"))
6219                       (search-forward "\nXref:" nil t))
6220               (goto-char (1+ (match-end 0)))
6221               (setq xref (buffer-substring (point) (point-at-eol)))
6222               (mail-header-set-xref headers xref)))))))
6223
6224 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6225   "Find article ID and insert the summary line for that article.
6226 OLD-HEADER can either be a header or a line number to insert
6227 the subject line on."
6228   (let* ((line (and (numberp old-header) old-header))
6229          (old-header (and (vectorp old-header) old-header))
6230          (header (cond ((and old-header use-old-header)
6231                         old-header)
6232                        ((and (numberp id)
6233                              (gnus-number-to-header id))
6234                         (gnus-number-to-header id))
6235                        (t
6236                         (gnus-read-header id))))
6237          (number (and (numberp id) id))
6238          d)
6239     (when header
6240       ;; Rebuild the thread that this article is part of and go to the
6241       ;; article we have fetched.
6242       (when (and (not gnus-show-threads)
6243                  old-header)
6244         (when (and number
6245                    (setq d (gnus-data-find (mail-header-number old-header))))
6246           (goto-char (gnus-data-pos d))
6247           (gnus-data-remove
6248            number
6249            (- (point-at-bol)
6250               (prog1
6251                   (1+ (point-at-eol))
6252                 (gnus-delete-line))))))
6253       ;; Remove list identifiers from subject.
6254       (when gnus-list-identifiers
6255         (let ((gnus-newsgroup-headers (list header)))
6256           (gnus-summary-remove-list-identifiers)))
6257       (when old-header
6258         (mail-header-set-number header (mail-header-number old-header)))
6259       (setq gnus-newsgroup-sparse
6260             (delq (setq number (mail-header-number header))
6261                   gnus-newsgroup-sparse))
6262       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6263       (push number gnus-newsgroup-limit)
6264       (gnus-rebuild-thread (mail-header-id header) line)
6265       (gnus-summary-goto-subject number nil t))
6266     (when (and (numberp number)
6267                (> number 0))
6268       ;; We have to update the boundaries even if we can't fetch the
6269       ;; article if ID is a number -- so that the next `P' or `N'
6270       ;; command will fetch the previous (or next) article even
6271       ;; if the one we tried to fetch this time has been canceled.
6272       (when (> number gnus-newsgroup-end)
6273         (setq gnus-newsgroup-end number))
6274       (when (< number gnus-newsgroup-begin)
6275         (setq gnus-newsgroup-begin number))
6276       (setq gnus-newsgroup-unselected
6277             (delq number gnus-newsgroup-unselected)))
6278     ;; Report back a success?
6279     (and header (mail-header-number header))))
6280
6281 ;;; Process/prefix in the summary buffer
6282
6283 (defun gnus-summary-work-articles (n)
6284   "Return a list of articles to be worked upon.
6285 The prefix argument, the list of process marked articles, and the
6286 current article will be taken into consideration."
6287   (save-excursion
6288     (set-buffer gnus-summary-buffer)
6289     (cond
6290      (n
6291       ;; A numerical prefix has been given.
6292       (setq n (prefix-numeric-value n))
6293       (let ((backward (< n 0))
6294             (n (abs (prefix-numeric-value n)))
6295             articles article)
6296         (save-excursion
6297           (while
6298               (and (> n 0)
6299                    (push (setq article (gnus-summary-article-number))
6300                          articles)
6301                    (if backward
6302                        (gnus-summary-find-prev nil article)
6303                      (gnus-summary-find-next nil article)))
6304             (decf n)))
6305         (nreverse articles)))
6306      ((and (gnus-region-active-p) (mark))
6307       (message "region active")
6308       ;; Work on the region between point and mark.
6309       (let ((max (max (point) (mark)))
6310             articles article)
6311         (save-excursion
6312           (goto-char (min (point) (mark)))
6313           (while
6314               (and
6315                (push (setq article (gnus-summary-article-number)) articles)
6316                (gnus-summary-find-next nil article)
6317                (< (point) max)))
6318           (nreverse articles))))
6319      (gnus-newsgroup-processable
6320       ;; There are process-marked articles present.
6321       ;; Save current state.
6322       (gnus-summary-save-process-mark)
6323       ;; Return the list.
6324       (reverse gnus-newsgroup-processable))
6325      (t
6326       ;; Just return the current article.
6327       (list (gnus-summary-article-number))))))
6328
6329 (defmacro gnus-summary-iterate (arg &rest forms)
6330   "Iterate over the process/prefixed articles and do FORMS.
6331 ARG is the interactive prefix given to the command.  FORMS will be
6332 executed with point over the summary line of the articles."
6333   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6334     `(let ((,articles (gnus-summary-work-articles ,arg)))
6335        (while ,articles
6336          (gnus-summary-goto-subject (car ,articles))
6337          ,@forms
6338          (pop ,articles)))))
6339
6340 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6341 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6342
6343 (defun gnus-summary-save-process-mark ()
6344   "Push the current set of process marked articles on the stack."
6345   (interactive)
6346   (push (copy-sequence gnus-newsgroup-processable)
6347         gnus-newsgroup-process-stack))
6348
6349 (defun gnus-summary-kill-process-mark ()
6350   "Push the current set of process marked articles on the stack and unmark."
6351   (interactive)
6352   (gnus-summary-save-process-mark)
6353   (gnus-summary-unmark-all-processable))
6354
6355 (defun gnus-summary-yank-process-mark ()
6356   "Pop the last process mark state off the stack and restore it."
6357   (interactive)
6358   (unless gnus-newsgroup-process-stack
6359     (error "Empty mark stack"))
6360   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6361
6362 (defun gnus-summary-process-mark-set (set)
6363   "Make SET into the current process marked articles."
6364   (gnus-summary-unmark-all-processable)
6365   (mapc 'gnus-summary-set-process-mark set))
6366
6367 ;;; Searching and stuff
6368
6369 (defun gnus-summary-search-group (&optional backward use-level)
6370   "Search for next unread newsgroup.
6371 If optional argument BACKWARD is non-nil, search backward instead."
6372   (save-excursion
6373     (set-buffer gnus-group-buffer)
6374     (when (gnus-group-search-forward
6375            backward nil (if use-level (gnus-group-group-level) nil))
6376       (gnus-group-group-name))))
6377
6378 (defun gnus-summary-best-group (&optional exclude-group)
6379   "Find the name of the best unread group.
6380 If EXCLUDE-GROUP, do not go to this group."
6381   (with-current-buffer gnus-group-buffer
6382     (save-excursion
6383       (gnus-group-best-unread-group exclude-group))))
6384
6385 (defun gnus-summary-find-next (&optional unread article backward)
6386   (if backward
6387       (gnus-summary-find-prev unread article)
6388     (let* ((dummy (gnus-summary-article-intangible-p))
6389            (article (or article (gnus-summary-article-number)))
6390            (data (gnus-data-find-list article))
6391            result)
6392       (when (and (not dummy)
6393                  (or (not gnus-summary-check-current)
6394                      (not unread)
6395                      (not (gnus-data-unread-p (car data)))))
6396         (setq data (cdr data)))
6397       (when (setq result
6398                   (if unread
6399                       (progn
6400                         (while data
6401                           (unless (memq (gnus-data-number (car data))
6402                                         (cond
6403                                          ((eq gnus-auto-goto-ignores
6404                                               'always-undownloaded)
6405                                           gnus-newsgroup-undownloaded)
6406                                          (gnus-plugged
6407                                           nil)
6408                                          ((eq gnus-auto-goto-ignores
6409                                               'unfetched)
6410                                           gnus-newsgroup-unfetched)
6411                                          ((eq gnus-auto-goto-ignores
6412                                               'undownloaded)
6413                                           gnus-newsgroup-undownloaded)))
6414                             (when (gnus-data-unread-p (car data))
6415                               (setq result (car data)
6416                                     data nil)))
6417                           (setq data (cdr data)))
6418                         result)
6419                     (car data)))
6420         (goto-char (gnus-data-pos result))
6421         (gnus-data-number result)))))
6422
6423 (defun gnus-summary-find-prev (&optional unread article)
6424   (let* ((eobp (eobp))
6425          (article (or article (gnus-summary-article-number)))
6426          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6427          result)
6428     (when (and (not eobp)
6429                (or (not gnus-summary-check-current)
6430                    (not unread)
6431                    (not (gnus-data-unread-p (car data)))))
6432       (setq data (cdr data)))
6433     (when (setq result
6434                 (if unread
6435                     (progn
6436                       (while data
6437                         (unless (memq (gnus-data-number (car data))
6438                                       (cond
6439                                        ((eq gnus-auto-goto-ignores
6440                                             'always-undownloaded)
6441                                         gnus-newsgroup-undownloaded)
6442                                        (gnus-plugged
6443                                         nil)
6444                                        ((eq gnus-auto-goto-ignores
6445                                             'unfetched)
6446                                         gnus-newsgroup-unfetched)
6447                                        ((eq gnus-auto-goto-ignores
6448                                             'undownloaded)
6449                                         gnus-newsgroup-undownloaded)))
6450                           (when (gnus-data-unread-p (car data))
6451                             (setq result (car data)
6452                                   data nil)))
6453                         (setq data (cdr data)))
6454                       result)
6455                   (car data)))
6456       (goto-char (gnus-data-pos result))
6457       (gnus-data-number result))))
6458
6459 (defun gnus-summary-find-subject (subject &optional unread backward article)
6460   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6461          (article (or article (gnus-summary-article-number)))
6462          (articles (gnus-data-list backward))
6463          (arts (gnus-data-find-list article articles))
6464          result)
6465     (when (or (not gnus-summary-check-current)
6466               (not unread)
6467               (not (gnus-data-unread-p (car arts))))
6468       (setq arts (cdr arts)))
6469     (while arts
6470       (and (or (not unread)
6471                (gnus-data-unread-p (car arts)))
6472            (vectorp (gnus-data-header (car arts)))
6473            (gnus-subject-equal
6474             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6475            (setq result (car arts)
6476                  arts nil))
6477       (setq arts (cdr arts)))
6478     (and result
6479          (goto-char (gnus-data-pos result))
6480          (gnus-data-number result))))
6481
6482 (defun gnus-summary-search-forward (&optional unread subject backward)
6483   "Search forward for an article.
6484 If UNREAD, look for unread articles.  If SUBJECT, look for
6485 articles with that subject.  If BACKWARD, search backward instead."
6486   (cond (subject (gnus-summary-find-subject subject unread backward))
6487         (backward (gnus-summary-find-prev unread))
6488         (t (gnus-summary-find-next unread))))
6489
6490 (defun gnus-recenter (&optional n)
6491   "Center point in window and redisplay frame.
6492 Also do horizontal recentering."
6493   (interactive "P")
6494   (when (and gnus-auto-center-summary
6495              (not (eq gnus-auto-center-summary 'vertical)))
6496     (gnus-horizontal-recenter))
6497   (recenter n))
6498
6499 (defun gnus-summary-recenter ()
6500   "Center point in the summary window.
6501 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6502 displayed, no centering will be performed."
6503   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6504   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6505   (interactive)
6506   ;; The user has to want it.
6507   (when gnus-auto-center-summary
6508     (let* ((top (cond ((< (window-height) 4) 0)
6509                       ((< (window-height) 7) 1)
6510                       (t (if (numberp gnus-auto-center-summary)
6511                              gnus-auto-center-summary
6512                            (/ (1- (window-height)) 2)))))
6513            (height (1- (window-height)))
6514            (bottom (save-excursion (goto-char (point-max))
6515                                    (forward-line (- height))
6516                                    (point)))
6517            (window (get-buffer-window (current-buffer))))
6518       (when (get-buffer-window gnus-article-buffer)
6519         ;; Only do recentering when the article buffer is displayed,
6520         ;; Set the window start to either `bottom', which is the biggest
6521         ;; possible valid number, or the second line from the top,
6522         ;; whichever is the least.
6523         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6524           (if (> bottom top-pos)
6525               ;; Keep the second line from the top visible
6526               (set-window-start window top-pos t)
6527             ;; Try to keep the bottom line visible; if it's partially
6528             ;; obscured, either scroll one more line to make it fully
6529             ;; visible, or revert to using TOP-POS.
6530             (save-excursion
6531               (goto-char (point-max))
6532               (forward-line -1)
6533               (let ((last-line-start (point)))
6534                 (goto-char bottom)
6535                 (set-window-start window (point) t)
6536                 (when (not (pos-visible-in-window-p last-line-start window))
6537                   (forward-line 1)
6538                   (set-window-start window (min (point) top-pos) t)))))))
6539       ;; Do horizontal recentering while we're at it.
6540       (when (and (get-buffer-window (current-buffer) t)
6541                  (not (eq gnus-auto-center-summary 'vertical)))
6542         (let ((selected (selected-window)))
6543           (select-window (get-buffer-window (current-buffer) t))
6544           (gnus-summary-position-point)
6545           (gnus-horizontal-recenter)
6546           (select-window selected))))))
6547
6548 (defun gnus-summary-jump-to-group (newsgroup)
6549   "Move point to NEWSGROUP in group mode buffer."
6550   ;; Keep update point of group mode buffer if visible.
6551   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6552       (save-window-excursion
6553         ;; Take care of tree window mode.
6554         (when (get-buffer-window gnus-group-buffer)
6555           (pop-to-buffer gnus-group-buffer))
6556         (gnus-group-jump-to-group newsgroup))
6557     (save-excursion
6558       ;; Take care of tree window mode.
6559       (if (get-buffer-window gnus-group-buffer)
6560           (pop-to-buffer gnus-group-buffer)
6561         (set-buffer gnus-group-buffer))
6562       (gnus-group-jump-to-group newsgroup))))
6563
6564 ;; This function returns a list of article numbers based on the
6565 ;; difference between the ranges of read articles in this group and
6566 ;; the range of active articles.
6567 (defun gnus-list-of-unread-articles (group)
6568   (let* ((read (gnus-info-read (gnus-get-info group)))
6569          (active (or (gnus-active group) (gnus-activate-group group)))
6570          (last (or (cdr active)
6571                    (error "Group %s couldn't be activated " group)))
6572          first nlast unread)
6573     ;; If none are read, then all are unread.
6574     (if (not read)
6575         (setq first (car active))
6576       ;; If the range of read articles is a single range, then the
6577       ;; first unread article is the article after the last read
6578       ;; article.  Sounds logical, doesn't it?
6579       (if (and (not (listp (cdr read)))
6580                (or (< (car read) (car active))
6581                    (progn (setq read (list read))
6582                           nil)))
6583           (setq first (max (car active) (1+ (cdr read))))
6584         ;; `read' is a list of ranges.
6585         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6586                                   (caar read)))
6587                   1)
6588           (setq first (car active)))
6589         (while read
6590           (when first
6591             (while (< first nlast)
6592               (setq unread (cons first unread)
6593                     first (1+ first))))
6594           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6595           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6596           (setq read (cdr read)))))
6597     ;; And add the last unread articles.
6598     (while (<= first last)
6599       (setq unread (cons first unread)
6600             first (1+ first)))
6601     ;; Return the list of unread articles.
6602     (delq 0 (nreverse unread))))
6603
6604 (defun gnus-list-of-read-articles (group)
6605   "Return a list of unread, unticked and non-dormant articles."
6606   (let* ((info (gnus-get-info group))
6607          (marked (gnus-info-marks info))
6608          (active (gnus-active group)))
6609     (and info active
6610          (gnus-list-range-difference
6611           (gnus-list-range-difference
6612            (gnus-sorted-complement
6613             (gnus-uncompress-range active)
6614             (gnus-list-of-unread-articles group))
6615            (cdr (assq 'dormant marked)))
6616           (cdr (assq 'tick marked))))))
6617
6618 ;; This function returns a sequence of article numbers based on the
6619 ;; difference between the ranges of read articles in this group and
6620 ;; the range of active articles.
6621 (defun gnus-sequence-of-unread-articles (group)
6622   (let* ((read (gnus-info-read (gnus-get-info group)))
6623          (active (or (gnus-active group) (gnus-activate-group group)))
6624          (last (cdr active))
6625          first nlast unread)
6626     ;; If none are read, then all are unread.
6627     (if (not read)
6628         (setq first (car active))
6629       ;; If the range of read articles is a single range, then the
6630       ;; first unread article is the article after the last read
6631       ;; article.  Sounds logical, doesn't it?
6632       (if (and (not (listp (cdr read)))
6633                (or (< (car read) (car active))
6634                    (progn (setq read (list read))
6635                           nil)))
6636           (setq first (max (car active) (1+ (cdr read))))
6637         ;; `read' is a list of ranges.
6638         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6639                                   (caar read)))
6640                   1)
6641           (setq first (car active)))
6642         (while read
6643           (when first
6644             (push (cons first nlast) unread))
6645           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6646           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6647           (setq read (cdr read)))))
6648     ;; And add the last unread articles.
6649     (cond ((< first last)
6650            (push (cons first last) unread))
6651           ((= first last)
6652            (push first unread)))
6653     ;; Return the sequence of unread articles.
6654     (delq 0 (nreverse unread))))
6655
6656 ;; Various summary commands
6657
6658 (defun gnus-summary-select-article-buffer ()
6659   "Reconfigure windows to show article buffer."
6660   (interactive)
6661   (if (not (gnus-buffer-live-p gnus-article-buffer))
6662       (error "There is no article buffer for this summary buffer")
6663     (gnus-configure-windows 'article)
6664     (select-window (get-buffer-window gnus-article-buffer))))
6665
6666 (defun gnus-summary-universal-argument (arg)
6667   "Perform any operation on all articles that are process/prefixed."
6668   (interactive "P")
6669   (let ((articles (gnus-summary-work-articles arg))
6670         func article)
6671     (if (eq
6672          (setq
6673           func
6674           (key-binding
6675            (read-key-sequence
6676             (substitute-command-keys
6677              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6678          'undefined)
6679         (gnus-error 1 "Undefined key")
6680       (save-excursion
6681         (while articles
6682           (gnus-summary-goto-subject (setq article (pop articles)))
6683           (let (gnus-newsgroup-processable)
6684             (command-execute func))
6685           (gnus-summary-remove-process-mark article)))))
6686   (gnus-summary-position-point))
6687
6688 (defun gnus-summary-toggle-truncation (&optional arg)
6689   "Toggle truncation of summary lines.
6690 With ARG, turn line truncation on if ARG is positive."
6691   (interactive "P")
6692   (setq truncate-lines
6693         (if (null arg) (not truncate-lines)
6694           (> (prefix-numeric-value arg) 0)))
6695   (redraw-display))
6696
6697 (defun gnus-summary-find-for-reselect ()
6698   "Return the number of an article to stay on across a reselect.
6699 The current article is considered, then following articles, then previous
6700 articles.  An article is sought which is not cancelled and isn't a temporary
6701 insertion from another group.  If there's no such then return a dummy 0."
6702   (let (found)
6703     (dolist (rev '(nil t))
6704       (unless found      ; don't demand the reverse list if we don't need it
6705         (let ((data (gnus-data-find-list
6706                      (gnus-summary-article-number) (gnus-data-list rev))))
6707           (while (and data (not found))
6708             (if (and (< 0 (gnus-data-number (car data)))
6709                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6710                 (setq found (gnus-data-number (car data))))
6711             (setq data (cdr data))))))
6712     (or found 0)))
6713
6714 (defun gnus-summary-reselect-current-group (&optional all rescan)
6715   "Exit and then reselect the current newsgroup.
6716 The prefix argument ALL means to select all articles."
6717   (interactive "P")
6718   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6719     (error "Ephemeral groups can't be reselected"))
6720   (let ((current-subject (gnus-summary-find-for-reselect))
6721         (group gnus-newsgroup-name))
6722     (setq gnus-newsgroup-begin nil)
6723     (gnus-summary-exit nil 'leave-hidden)
6724     ;; We have to adjust the point of group mode buffer because
6725     ;; point was moved to the next unread newsgroup by exiting.
6726     (gnus-summary-jump-to-group group)
6727     (when rescan
6728       (save-excursion
6729         (save-window-excursion
6730           ;; Don't show group contents.
6731           (set-window-start (selected-window) (point-max))
6732           (gnus-group-get-new-news-this-group 1))))
6733     (gnus-group-read-group all t)
6734     (gnus-summary-goto-subject current-subject nil t)))
6735
6736 (defun gnus-summary-rescan-group (&optional all)
6737   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6738   (interactive "P")
6739   (gnus-summary-reselect-current-group all t))
6740
6741 (defun gnus-summary-update-info (&optional non-destructive)
6742   (save-excursion
6743     (let ((group gnus-newsgroup-name))
6744       (when group
6745         (when gnus-newsgroup-kill-headers
6746           (setq gnus-newsgroup-killed
6747                 (gnus-compress-sequence
6748                  (gnus-sorted-union
6749                   (gnus-list-range-intersection
6750                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6751                   gnus-newsgroup-unreads)
6752                  t)))
6753         (unless (listp (cdr gnus-newsgroup-killed))
6754           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6755         (let ((headers gnus-newsgroup-headers))
6756           ;; Set the new ranges of read articles.
6757           (with-current-buffer gnus-group-buffer
6758             (gnus-undo-force-boundary))
6759           (gnus-update-read-articles
6760            group (gnus-sorted-union
6761                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6762           ;; Set the current article marks.
6763           (let ((gnus-newsgroup-scored
6764                  (if (and (not gnus-save-score)
6765                           (not non-destructive))
6766                      nil
6767                    gnus-newsgroup-scored)))
6768             (save-excursion
6769               (gnus-update-marks)))
6770           ;; Do the cross-ref thing.
6771           (when gnus-use-cross-reference
6772             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6773           ;; Do not switch windows but change the buffer to work.
6774           (set-buffer gnus-group-buffer)
6775           (unless (gnus-ephemeral-group-p group)
6776             (gnus-group-update-group group)))))))
6777
6778 (defun gnus-summary-save-newsrc (&optional force)
6779   "Save the current number of read/marked articles in the dribble buffer.
6780 The dribble buffer will then be saved.
6781 If FORCE (the prefix), also save the .newsrc file(s)."
6782   (interactive "P")
6783   (gnus-summary-update-info t)
6784   (if force
6785       (gnus-save-newsrc-file)
6786     (gnus-dribble-save)))
6787
6788 (defun gnus-summary-exit (&optional temporary leave-hidden)
6789   "Exit reading current newsgroup, and then return to group selection mode.
6790 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6791   (interactive)
6792   (gnus-set-global-variables)
6793   (gnus-kill-save-kill-buffer)
6794   (gnus-async-halt-prefetch)
6795   (let* ((group gnus-newsgroup-name)
6796          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6797          (gnus-group-is-exiting-p t)
6798          (mode major-mode)
6799          (group-point nil)
6800          (buf (current-buffer)))
6801     (unless quit-config
6802       ;; Do adaptive scoring, and possibly save score files.
6803       (when gnus-newsgroup-adaptive
6804         (gnus-score-adaptive))
6805       (when gnus-use-scoring
6806         (gnus-score-save)))
6807     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6808     ;; If we have several article buffers, we kill them at exit.
6809     (unless gnus-single-article-buffer
6810       (gnus-kill-buffer gnus-original-article-buffer)
6811       (setq gnus-article-current nil))
6812     (when gnus-use-cache
6813       (gnus-cache-possibly-remove-articles)
6814       (gnus-cache-save-buffers))
6815     (gnus-async-prefetch-remove-group group)
6816     (when gnus-suppress-duplicates
6817       (gnus-dup-enter-articles))
6818     (when gnus-use-trees
6819       (gnus-tree-close group))
6820     (when gnus-use-cache
6821       (gnus-cache-write-active))
6822     ;; Remove entries for this group.
6823     (nnmail-purge-split-history (gnus-group-real-name group))
6824     ;; Make all changes in this group permanent.
6825     (unless quit-config
6826       (gnus-run-hooks 'gnus-exit-group-hook)
6827       (gnus-summary-update-info))
6828     (gnus-close-group group)
6829     ;; Make sure where we were, and go to next newsgroup.
6830     (set-buffer gnus-group-buffer)
6831     (unless quit-config
6832       (gnus-group-jump-to-group group))
6833     (gnus-run-hooks 'gnus-summary-exit-hook)
6834     (unless (or quit-config
6835                 ;; If this group has disappeared from the summary
6836                 ;; buffer, don't skip forwards.
6837                 (not (string= group (gnus-group-group-name))))
6838       (gnus-group-next-unread-group 1))
6839     (setq group-point (point))
6840     (if temporary
6841         nil                             ;Nothing to do.
6842       ;; If we have several article buffers, we kill them at exit.
6843       (unless gnus-single-article-buffer
6844         (gnus-kill-buffer gnus-article-buffer)
6845         (gnus-kill-buffer gnus-original-article-buffer)
6846         (setq gnus-article-current nil))
6847       (set-buffer buf)
6848       (if (not gnus-kill-summary-on-exit)
6849           (progn
6850             (gnus-deaden-summary)
6851             (setq mode nil))
6852         ;; We set all buffer-local variables to nil.  It is unclear why
6853         ;; this is needed, but if we don't, buffer-local variables are
6854         ;; not garbage-collected, it seems.  This would the lead to en
6855         ;; ever-growing Emacs.
6856         (gnus-summary-clear-local-variables)
6857         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6858           (gnus-summary-clear-local-variables))
6859         (when (get-buffer gnus-article-buffer)
6860           (bury-buffer gnus-article-buffer))
6861         ;; Return to group mode buffer.
6862         (when (eq mode 'gnus-summary-mode)
6863           (gnus-kill-buffer buf)))
6864       (setq gnus-current-select-method gnus-select-method)
6865       (set-buffer gnus-group-buffer)
6866       (if quit-config
6867           (gnus-handle-ephemeral-exit quit-config)
6868         (goto-char group-point)
6869         ;; If gnus-group-buffer is already displayed, make sure we also move
6870         ;; the cursor in the window that displays it.
6871         (let ((win (get-buffer-window (current-buffer) 0)))
6872           (if win (set-window-point win (point))))
6873         (unless leave-hidden
6874           (gnus-configure-windows 'group 'force))
6875         (unless (pos-visible-in-window-p)
6876           (forward-line (/ (static-if (featurep 'xemacs)
6877                                (window-displayed-height)
6878                              (1- (window-height)))
6879                            -2))
6880           (set-window-start (selected-window) (point))
6881           (goto-char group-point)))
6882       ;; Clear the current group name.
6883       (unless quit-config
6884         (setq gnus-newsgroup-name nil)))))
6885
6886 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6887 (defun gnus-summary-exit-no-update (&optional no-questions)
6888   "Quit reading current newsgroup without updating read article info."
6889   (interactive)
6890   (let* ((group gnus-newsgroup-name)
6891          (gnus-group-is-exiting-p t)
6892          (gnus-group-is-exiting-without-update-p t)
6893          (quit-config (gnus-group-quit-config group)))
6894     (when (or no-questions
6895               gnus-expert-user
6896               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6897       (gnus-async-halt-prefetch)
6898       (run-hooks 'gnus-summary-prepare-exit-hook)
6899       ;; If we have several article buffers, we kill them at exit.
6900       (unless gnus-single-article-buffer
6901         (gnus-kill-buffer gnus-article-buffer)
6902         (gnus-kill-buffer gnus-original-article-buffer)
6903         (setq gnus-article-current nil))
6904       (if (not gnus-kill-summary-on-exit)
6905           (gnus-deaden-summary)
6906         (gnus-close-group group)
6907         (gnus-summary-clear-local-variables)
6908         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6909           (gnus-summary-clear-local-variables))
6910         (gnus-kill-buffer gnus-summary-buffer))
6911       (unless gnus-single-article-buffer
6912         (setq gnus-article-current nil))
6913       (when gnus-use-trees
6914         (gnus-tree-close group))
6915       (gnus-async-prefetch-remove-group group)
6916       (when (get-buffer gnus-article-buffer)
6917         (bury-buffer gnus-article-buffer))
6918       ;; Return to the group buffer.
6919       (gnus-configure-windows 'group 'force)
6920       ;; Clear the current group name.
6921       (setq gnus-newsgroup-name nil)
6922       (unless (gnus-ephemeral-group-p group)
6923         (gnus-group-update-group group))
6924       (when (equal (gnus-group-group-name) group)
6925         (gnus-group-next-unread-group 1))
6926       (when quit-config
6927         (gnus-handle-ephemeral-exit quit-config)))))
6928
6929 (defun gnus-handle-ephemeral-exit (quit-config)
6930   "Handle movement when leaving an ephemeral group.
6931 The state which existed when entering the ephemeral is reset."
6932   (if (not (buffer-name (car quit-config)))
6933       (gnus-configure-windows 'group 'force)
6934     (set-buffer (car quit-config))
6935     (cond ((eq major-mode 'gnus-summary-mode)
6936            (gnus-set-global-variables))
6937           ((eq major-mode 'gnus-article-mode)
6938            (save-excursion
6939              ;; The `gnus-summary-buffer' variable may point
6940              ;; to the old summary buffer when using a single
6941              ;; article buffer.
6942              (unless (gnus-buffer-live-p gnus-summary-buffer)
6943                (set-buffer gnus-group-buffer))
6944              (set-buffer gnus-summary-buffer)
6945              (gnus-set-global-variables))))
6946     (if (or (eq (cdr quit-config) 'article)
6947             (eq (cdr quit-config) 'pick))
6948         (progn
6949           ;; The current article may be from the ephemeral group
6950           ;; thus it is best that we reload this article
6951           ;;
6952           ;; If we're exiting from a large digest, this can be
6953           ;; extremely slow.  So, it's better not to reload it. -- jh.
6954           ;;(gnus-summary-show-article)
6955           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6956               (gnus-configure-windows 'pick 'force)
6957             (gnus-configure-windows (cdr quit-config) 'force)))
6958       (gnus-configure-windows (cdr quit-config) 'force))
6959     (when (eq major-mode 'gnus-summary-mode)
6960       (gnus-summary-next-subject 1 nil t)
6961       (gnus-summary-recenter)
6962       (gnus-summary-position-point))))
6963
6964 (defun gnus-summary-preview-mime-message ()
6965   "MIME decode and play this message."
6966   (interactive)
6967   (let ((gnus-break-pages nil)
6968         (gnus-show-mime t))
6969     (gnus-summary-select-article gnus-show-all-headers t))
6970   (let ((w (get-buffer-window gnus-article-buffer)))
6971     (when w
6972       (select-window (get-buffer-window gnus-article-buffer)))))
6973
6974 ;;; Dead summaries.
6975
6976 (defvar gnus-dead-summary-mode-map nil)
6977
6978 (unless gnus-dead-summary-mode-map
6979   (setq gnus-dead-summary-mode-map (make-keymap))
6980   (suppress-keymap gnus-dead-summary-mode-map)
6981   (substitute-key-definition
6982    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6983   (dolist (key '("\C-d" "\r" "\177" [delete]))
6984     (define-key gnus-dead-summary-mode-map
6985       key 'gnus-summary-wake-up-the-dead))
6986   (dolist (key '("q" "Q"))
6987     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6988
6989 (defvar gnus-dead-summary-mode nil
6990   "Minor mode for Gnus summary buffers.")
6991
6992 (defun gnus-dead-summary-mode (&optional arg)
6993   "Minor mode for Gnus summary buffers."
6994   (interactive "P")
6995   (when (eq major-mode 'gnus-summary-mode)
6996     (make-local-variable 'gnus-dead-summary-mode)
6997     (setq gnus-dead-summary-mode
6998           (if (null arg) (not gnus-dead-summary-mode)
6999             (> (prefix-numeric-value arg) 0)))
7000     (when gnus-dead-summary-mode
7001       (add-minor-mode
7002        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7003
7004 (defun gnus-deaden-summary ()
7005   "Make the current summary buffer into a dead summary buffer."
7006   ;; Kill any previous dead summary buffer.
7007   (when (and gnus-dead-summary
7008              (buffer-name gnus-dead-summary))
7009     (with-current-buffer gnus-dead-summary
7010       (when gnus-dead-summary-mode
7011         (kill-buffer (current-buffer)))))
7012   ;; Make this the current dead summary.
7013   (setq gnus-dead-summary (current-buffer))
7014   (gnus-dead-summary-mode 1)
7015   (let ((name (buffer-name)))
7016     (when (string-match "Summary" name)
7017       (rename-buffer
7018        (concat (substring name 0 (match-beginning 0)) "Dead "
7019                (substring name (match-beginning 0)))
7020        t)
7021       (bury-buffer))))
7022
7023 (defun gnus-kill-or-deaden-summary (buffer)
7024   "Kill or deaden the summary BUFFER."
7025   (save-excursion
7026     (when (and (buffer-name buffer)
7027                (not gnus-single-article-buffer))
7028       (with-current-buffer buffer
7029         (gnus-kill-buffer gnus-article-buffer)
7030         (gnus-kill-buffer gnus-original-article-buffer)))
7031     (cond
7032      ;; Kill the buffer.
7033      (gnus-kill-summary-on-exit
7034       (when (and gnus-use-trees
7035                  (gnus-buffer-exists-p buffer))
7036         (save-excursion
7037           (set-buffer buffer)
7038           (gnus-tree-close gnus-newsgroup-name)))
7039       (gnus-kill-buffer buffer))
7040      ;; Deaden the buffer.
7041      ((gnus-buffer-exists-p buffer)
7042       (save-excursion
7043         (set-buffer buffer)
7044         (gnus-deaden-summary))))))
7045
7046 (defun gnus-summary-wake-up-the-dead (&rest args)
7047   "Wake up the dead summary buffer."
7048   (interactive)
7049   (gnus-dead-summary-mode -1)
7050   (let ((name (buffer-name)))
7051     (when (string-match "Dead " name)
7052       (rename-buffer
7053        (concat (substring name 0 (match-beginning 0))
7054                (substring name (match-end 0)))
7055        t)))
7056   (gnus-message 3 "This dead summary is now alive again"))
7057
7058 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7059 (defun gnus-summary-fetch-faq (&optional faq-dir)
7060   "Fetch the FAQ for the current group.
7061 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7062 in."
7063   (interactive
7064    (list
7065     (when current-prefix-arg
7066       (completing-read
7067        "FAQ dir: " (and (listp gnus-group-faq-directory)
7068                         (mapcar 'list
7069                                 gnus-group-faq-directory))))))
7070   (let (gnus-faq-buffer)
7071     (when (setq gnus-faq-buffer
7072                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7073       (gnus-configure-windows 'summary-faq))))
7074
7075 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7076 (defun gnus-summary-describe-group (&optional force)
7077   "Describe the current newsgroup."
7078   (interactive "P")
7079   (gnus-group-describe-group force gnus-newsgroup-name))
7080
7081 (defun gnus-summary-describe-briefly ()
7082   "Describe summary mode commands briefly."
7083   (interactive)
7084   (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")))
7085
7086 ;; Walking around group mode buffer from summary mode.
7087
7088 (defun gnus-summary-next-group (&optional no-article target-group backward)
7089   "Exit current newsgroup and then select next unread newsgroup.
7090 If prefix argument NO-ARTICLE is non-nil, no article is selected
7091 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7092 previous group instead."
7093   (interactive "P")
7094   ;; Stop pre-fetching.
7095   (gnus-async-halt-prefetch)
7096   (let ((current-group gnus-newsgroup-name)
7097         (current-buffer (current-buffer))
7098         entered)
7099     ;; First we semi-exit this group to update Xrefs and all variables.
7100     ;; We can't do a real exit, because the window conf must remain
7101     ;; the same in case the user is prompted for info, and we don't
7102     ;; want the window conf to change before that...
7103     (gnus-summary-exit t)
7104     (while (not entered)
7105       ;; Then we find what group we are supposed to enter.
7106       (set-buffer gnus-group-buffer)
7107       (gnus-group-jump-to-group current-group)
7108       (setq target-group
7109             (or target-group
7110                 (if (eq gnus-keep-same-level 'best)
7111                     (gnus-summary-best-group gnus-newsgroup-name)
7112                   (gnus-summary-search-group backward gnus-keep-same-level))))
7113       (if (not target-group)
7114           ;; There are no further groups, so we return to the group
7115           ;; buffer.
7116           (progn
7117             (gnus-message 5 "Returning to the group buffer")
7118             (setq entered t)
7119             (when (gnus-buffer-live-p current-buffer)
7120               (set-buffer current-buffer)
7121               (gnus-summary-exit))
7122             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7123         ;; We try to enter the target group.
7124         (gnus-group-jump-to-group target-group)
7125         (let ((unreads (gnus-group-group-unread)))
7126           (if (and (or (eq t unreads)
7127                        (and unreads (not (zerop unreads))))
7128                    (gnus-summary-read-group
7129                     target-group nil no-article
7130                     (and (buffer-name current-buffer) current-buffer)
7131                     nil backward))
7132               (setq entered t)
7133             (setq current-group target-group
7134                   target-group nil)))))))
7135
7136 (defun gnus-summary-prev-group (&optional no-article)
7137   "Exit current newsgroup and then select previous unread newsgroup.
7138 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7139   (interactive "P")
7140   (gnus-summary-next-group no-article nil t))
7141
7142 ;; Walking around summary lines.
7143
7144 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7145   "Go to the first subject satisfying any non-nil constraint.
7146 If UNREAD is non-nil, the article should be unread.
7147 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7148 If UNSEEN is non-nil, the article should be unseen.
7149 Returns the article selected or nil if there are no matching articles."
7150   (interactive "P")
7151   (cond
7152    ;; Empty summary.
7153    ((null gnus-newsgroup-data)
7154     (gnus-message 3 "No articles in the group")
7155     nil)
7156    ;; Pick the first article.
7157    ((not (or unread undownloaded unseen))
7158     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7159     (gnus-data-number (car gnus-newsgroup-data)))
7160    ;; Find the first unread article.
7161    (t
7162     (let ((data gnus-newsgroup-data))
7163       (while (and data
7164                   (let ((num (gnus-data-number (car data))))
7165                     (or (memq num gnus-newsgroup-unfetched)
7166                         (not (or (and unread
7167                                       (memq num gnus-newsgroup-unreads))
7168                                  (and undownloaded
7169                                       (memq num gnus-newsgroup-undownloaded))
7170                                  (and unseen
7171                                       (memq num gnus-newsgroup-unseen)))))))
7172         (setq data (cdr data)))
7173       (prog1
7174           (if data
7175               (progn
7176                 (goto-char (gnus-data-pos (car data)))
7177                 (gnus-data-number (car data)))
7178             (gnus-message 3 "No more%s articles"
7179                           (let* ((r (when unread " unread"))
7180                                  (d (when undownloaded " undownloaded"))
7181                                  (s (when unseen " unseen"))
7182                                  (l (delq nil (list r d s))))
7183                             (cond ((= 3 (length l))
7184                                    (concat r "," d ", or" s))
7185                                   ((= 2 (length l))
7186                                    (concat (car l) ", or" (cadr l)))
7187                                   ((= 1 (length l))
7188                                    (car l))
7189                                   (t
7190                                    ""))))
7191             nil
7192             )
7193         (gnus-summary-position-point))))))
7194
7195 (defun gnus-summary-next-subject (n &optional unread dont-display)
7196   "Go to next N'th summary line.
7197 If N is negative, go to the previous N'th subject line.
7198 If UNREAD is non-nil, only unread articles are selected.
7199 The difference between N and the actual number of steps taken is
7200 returned."
7201   (interactive "p")
7202   (let ((backward (< n 0))
7203         (n (abs n)))
7204     (while (and (> n 0)
7205                 (if backward
7206                     (gnus-summary-find-prev unread)
7207                   (gnus-summary-find-next unread)))
7208       (unless (zerop (setq n (1- n)))
7209         (gnus-summary-show-thread)))
7210     (when (/= 0 n)
7211       (gnus-message 7 "No more%s articles"
7212                     (if unread " unread" "")))
7213     (unless dont-display
7214       (gnus-summary-recenter)
7215       (gnus-summary-position-point))
7216     n))
7217
7218 (defun gnus-summary-next-unread-subject (n)
7219   "Go to next N'th unread summary line."
7220   (interactive "p")
7221   (gnus-summary-next-subject n t))
7222
7223 (defun gnus-summary-prev-subject (n &optional unread)
7224   "Go to previous N'th summary line.
7225 If optional argument UNREAD is non-nil, only unread article is selected."
7226   (interactive "p")
7227   (gnus-summary-next-subject (- n) unread))
7228
7229 (defun gnus-summary-prev-unread-subject (n)
7230   "Go to previous N'th unread summary line."
7231   (interactive "p")
7232   (gnus-summary-next-subject (- n) t))
7233
7234 (defun gnus-summary-goto-subjects (articles)
7235   "Insert the subject header for ARTICLES in the current buffer."
7236   (save-excursion
7237     (dolist (article articles)
7238       (gnus-summary-goto-subject article t)))
7239   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7240   (gnus-summary-position-point))
7241
7242 (defun gnus-summary-goto-subject (article &optional force silent)
7243   "Go the subject line of ARTICLE.
7244 If FORCE, also allow jumping to articles not currently shown."
7245   (interactive "nArticle number: ")
7246   (unless (numberp article)
7247     (error "Article %s is not a number" article))
7248   (let ((b (point))
7249         (data (gnus-data-find article)))
7250     ;; We read in the article if we have to.
7251     (and (not data)
7252          force
7253          (gnus-summary-insert-subject
7254           article
7255           (if (or (numberp force) (vectorp force)) force)
7256           t)
7257          (setq data (gnus-data-find article)))
7258     (goto-char b)
7259     (if (not data)
7260         (progn
7261           (unless silent
7262             (gnus-message 3 "Can't find article %d" article))
7263           nil)
7264       (let ((pt (gnus-data-pos data)))
7265         (goto-char pt)
7266         (gnus-summary-set-article-display-arrow pt))
7267       (gnus-summary-position-point)
7268       article)))
7269
7270 ;; Walking around summary lines with displaying articles.
7271
7272 (defun gnus-summary-expand-window (&optional arg)
7273   "Make the summary buffer take up the entire Emacs frame.
7274 Given a prefix, will force an `article' buffer configuration."
7275   (interactive "P")
7276   (if arg
7277       (gnus-configure-windows 'article 'force)
7278     (gnus-configure-windows 'summary 'force)))
7279
7280 (defun gnus-summary-display-article (article &optional all-header)
7281   "Display ARTICLE in article buffer."
7282   (when (gnus-buffer-live-p gnus-article-buffer)
7283     (with-current-buffer gnus-article-buffer
7284       (set-buffer-multibyte t)))
7285   (gnus-set-global-variables)
7286   (when (gnus-buffer-live-p gnus-article-buffer)
7287     (with-current-buffer gnus-article-buffer
7288       (setq gnus-article-charset gnus-newsgroup-charset)
7289       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7290       (set-buffer-multibyte t)))
7291   (if (null article)
7292       nil
7293     (prog1
7294         (if gnus-summary-display-article-function
7295             (funcall gnus-summary-display-article-function article all-header)
7296           (gnus-article-prepare article all-header))
7297       (with-current-buffer gnus-article-buffer
7298         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7299              nil))
7300       (gnus-run-hooks 'gnus-select-article-hook)
7301       (when (and gnus-current-article
7302                  (not (zerop gnus-current-article)))
7303         (gnus-summary-goto-subject gnus-current-article))
7304       (gnus-summary-recenter)
7305       (when (and gnus-use-trees gnus-show-threads)
7306         (gnus-possibly-generate-tree article)
7307         (gnus-highlight-selected-tree article))
7308       ;; Successfully display article.
7309       (gnus-article-set-window-start
7310        (cdr (assq article gnus-newsgroup-bookmarks))))))
7311
7312 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7313   "Select the current article.
7314 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7315 non-nil, the article will be re-fetched even if it already present in
7316 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7317 be displayed."
7318   ;; Make sure we are in the summary buffer to work around bbdb bug.
7319   (unless (eq major-mode 'gnus-summary-mode)
7320     (set-buffer gnus-summary-buffer))
7321   (let ((article (or article (gnus-summary-article-number)))
7322         (all-headers (not (not all-headers))) ;Must be T or NIL.
7323         gnus-summary-display-article-function)
7324     (and (not pseudo)
7325          (gnus-summary-article-pseudo-p article)
7326          (error "This is a pseudo-article"))
7327     (save-excursion
7328       (set-buffer gnus-summary-buffer)
7329       (if (or (and gnus-single-article-buffer
7330                    (or (null gnus-current-article)
7331                        (null gnus-article-current)
7332                        (null (get-buffer gnus-article-buffer))
7333                        (not (eq article (cdr gnus-article-current)))
7334                        (not (equal (car gnus-article-current)
7335                                    gnus-newsgroup-name))))
7336               (and (not gnus-single-article-buffer)
7337                    (or (null gnus-current-article)
7338                        (not (eq gnus-current-article article))))
7339               force)
7340           ;; The requested article is different from the current article.
7341           (progn
7342             (gnus-summary-display-article article all-headers)
7343             (gnus-article-set-window-start
7344              (cdr (assq article gnus-newsgroup-bookmarks)))
7345             article)
7346         'old))))
7347
7348 (defun gnus-summary-force-verify-and-decrypt ()
7349   "Display buttons for signed/encrypted parts and verify/decrypt them."
7350   (interactive)
7351   (let ((mm-verify-option 'known)
7352         (mm-decrypt-option 'known)
7353         (gnus-article-emulate-mime t)
7354         (gnus-buttonized-mime-types (append (list "multipart/signed"
7355                                                   "multipart/encrypted")
7356                                             gnus-buttonized-mime-types)))
7357     (gnus-summary-select-article nil 'force)))
7358
7359 (defun gnus-summary-set-current-mark (&optional current-mark)
7360   "Obsolete function."
7361   nil)
7362
7363 (defun gnus-summary-next-article (&optional unread subject backward push)
7364   "Select the next article.
7365 If UNREAD, only unread articles are selected.
7366 If SUBJECT, only articles with SUBJECT are selected.
7367 If BACKWARD, the previous article is selected instead of the next."
7368   (interactive "P")
7369   (cond
7370    ;; Is there such an article?
7371    ((and (gnus-summary-search-forward unread subject backward)
7372          (or (gnus-summary-display-article (gnus-summary-article-number))
7373              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7374     (gnus-summary-position-point))
7375    ;; If not, we try the first unread, if that is wanted.
7376    ((and subject
7377          gnus-auto-select-same
7378          (gnus-summary-first-unread-article))
7379     (gnus-summary-position-point)
7380     (gnus-message 6 "Wrapped"))
7381    ;; Try to get next/previous article not displayed in this group.
7382    ((and gnus-auto-extend-newsgroup
7383          (not unread) (not subject))
7384     (gnus-summary-goto-article
7385      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7386      nil (count-lines (point-min) (point))))
7387    ;; Go to next/previous group.
7388    (t
7389     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7390       (gnus-summary-jump-to-group gnus-newsgroup-name))
7391     (let ((cmd last-command-char)
7392           (point
7393            (with-current-buffer gnus-group-buffer
7394              (point)))
7395           (group
7396            (if (eq gnus-keep-same-level 'best)
7397                (gnus-summary-best-group gnus-newsgroup-name)
7398              (gnus-summary-search-group backward gnus-keep-same-level))))
7399       ;; For some reason, the group window gets selected.  We change
7400       ;; it back.
7401       (select-window (get-buffer-window (current-buffer)))
7402       ;; Select next unread newsgroup automagically.
7403       (cond
7404        ((or (not gnus-auto-select-next)
7405             (not cmd))
7406         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7407        ((or (eq gnus-auto-select-next 'quietly)
7408             (and (eq gnus-auto-select-next 'slightly-quietly)
7409                  push)
7410             (and (eq gnus-auto-select-next 'almost-quietly)
7411                  (gnus-summary-last-article-p)))
7412         ;; Select quietly.
7413         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7414             (gnus-summary-exit)
7415           (gnus-message 7 "No more%s articles (%s)..."
7416                         (if unread " unread" "")
7417                         (if group (concat "selecting " group)
7418                           "exiting"))
7419           (gnus-summary-next-group nil group backward)))
7420        (t
7421         (when (gnus-key-press-event-p last-input-event)
7422           (gnus-summary-walk-group-buffer
7423            gnus-newsgroup-name cmd unread backward point))))))))
7424
7425 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7426   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7427                       (?\C-p (gnus-group-prev-unread-group 1))))
7428         (cursor-in-echo-area t)
7429         keve key group ended prompt)
7430     (save-excursion
7431       (set-buffer gnus-group-buffer)
7432       (goto-char start)
7433       (setq group
7434             (if (eq gnus-keep-same-level 'best)
7435                 (gnus-summary-best-group gnus-newsgroup-name)
7436               (gnus-summary-search-group backward gnus-keep-same-level))))
7437     (while (not ended)
7438       (setq prompt
7439             (format
7440              "No more%s articles%s " (if unread " unread" "")
7441              (if (and group
7442                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7443                  (format " (Type %s for %s [%s])"
7444                          (single-key-description cmd)
7445                          (gnus-group-decoded-name group)
7446                          (gnus-group-unread group))
7447                (format " (Type %s to exit %s)"
7448                        (single-key-description cmd)
7449                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7450       ;; Confirm auto selection.
7451       (setq key (car (setq keve (gnus-read-event-char prompt)))
7452             ended t)
7453       (cond
7454        ((assq key keystrokes)
7455         (let ((obuf (current-buffer)))
7456           (switch-to-buffer gnus-group-buffer)
7457           (when group
7458             (gnus-group-jump-to-group group))
7459           (eval (cadr (assq key keystrokes)))
7460           (setq group (gnus-group-group-name))
7461           (switch-to-buffer obuf))
7462         (setq ended nil))
7463        ((equal key cmd)
7464         (if (or (not group)
7465                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7466             (gnus-summary-exit)
7467           (gnus-summary-next-group nil group backward)))
7468        (t
7469         (push (cdr keve) unread-command-events))))))
7470
7471 (defun gnus-summary-next-unread-article ()
7472   "Select unread article after current one."
7473   (interactive)
7474   (gnus-summary-next-article
7475    (or (not (eq gnus-summary-goto-unread 'never))
7476        (gnus-summary-last-article-p (gnus-summary-article-number)))
7477    (and gnus-auto-select-same
7478         (gnus-summary-article-subject))))
7479
7480 (defun gnus-summary-prev-article (&optional unread subject)
7481   "Select the article after the current one.
7482 If UNREAD is non-nil, only unread articles are selected."
7483   (interactive "P")
7484   (gnus-summary-next-article unread subject t))
7485
7486 (defun gnus-summary-prev-unread-article ()
7487   "Select unread article before current one."
7488   (interactive)
7489   (gnus-summary-prev-article
7490    (or (not (eq gnus-summary-goto-unread 'never))
7491        (gnus-summary-first-article-p (gnus-summary-article-number)))
7492    (and gnus-auto-select-same
7493         (gnus-summary-article-subject))))
7494
7495 (defun gnus-summary-next-page (&optional lines circular stop)
7496   "Show next page of the selected article.
7497 If at the end of the current article, select the next article.
7498 LINES says how many lines should be scrolled up.
7499
7500 If CIRCULAR is non-nil, go to the start of the article instead of
7501 selecting the next article when reaching the end of the current
7502 article.
7503
7504 If STOP is non-nil, just stop when reaching the end of the message.
7505
7506 Also see the variable `gnus-article-skip-boring'."
7507   (interactive "P")
7508   (setq gnus-summary-buffer (current-buffer))
7509   (gnus-set-global-variables)
7510   (let ((article (gnus-summary-article-number))
7511         (article-window (get-buffer-window gnus-article-buffer t))
7512         endp)
7513     ;; If the buffer is empty, we have no article.
7514     (unless article
7515       (error "No article to select"))
7516     (gnus-configure-windows 'article)
7517     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7518         (if (and (eq gnus-summary-goto-unread 'never)
7519                  (not (gnus-summary-last-article-p article)))
7520             (gnus-summary-next-article)
7521           (gnus-summary-next-unread-article))
7522       (if (or (null gnus-current-article)
7523               (null gnus-article-current)
7524               (/= article (cdr gnus-article-current))
7525               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7526           ;; Selected subject is different from current article's.
7527           (gnus-summary-display-article article)
7528         (when article-window
7529           (gnus-eval-in-buffer-window gnus-article-buffer
7530             (setq endp (or (gnus-article-next-page lines)
7531                            (gnus-article-only-boring-p))))
7532           (when endp
7533             (cond (stop
7534                    (gnus-message 3 "End of message"))
7535                   (circular
7536                    (gnus-summary-beginning-of-article))
7537                   (lines
7538                    (gnus-message 3 "End of message"))
7539                   ((null lines)
7540                    (if (and (eq gnus-summary-goto-unread 'never)
7541                             (not (gnus-summary-last-article-p article)))
7542                        (gnus-summary-next-article)
7543                      (gnus-summary-next-unread-article))))))))
7544     (gnus-summary-recenter)
7545     (gnus-summary-position-point)))
7546
7547 (defun gnus-summary-prev-page (&optional lines move)
7548   "Show previous page of selected article.
7549 Argument LINES specifies lines to be scrolled down.
7550 If MOVE, move to the previous unread article if point is at
7551 the beginning of the buffer."
7552   (interactive "P")
7553   (let ((article (gnus-summary-article-number))
7554         (article-window (get-buffer-window gnus-article-buffer t))
7555         endp)
7556     (gnus-configure-windows 'article)
7557     (if (or (null gnus-current-article)
7558             (null gnus-article-current)
7559             (/= article (cdr gnus-article-current))
7560             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7561         ;; Selected subject is different from current article's.
7562         (gnus-summary-display-article article)
7563       (gnus-summary-recenter)
7564       (when article-window
7565         (gnus-eval-in-buffer-window gnus-article-buffer
7566           (setq endp (gnus-article-prev-page lines)))
7567         (when (and move endp)
7568           (cond (lines
7569                  (gnus-message 3 "Beginning of message"))
7570                 ((null lines)
7571                  (if (and (eq gnus-summary-goto-unread 'never)
7572                           (not (gnus-summary-first-article-p article)))
7573                      (gnus-summary-prev-article)
7574                    (gnus-summary-prev-unread-article))))))))
7575   (gnus-summary-position-point))
7576
7577 (defun gnus-summary-prev-page-or-article (&optional lines)
7578   "Show previous page of selected article.
7579 Argument LINES specifies lines to be scrolled down.
7580 If at the beginning of the article, go to the next article."
7581   (interactive "P")
7582   (gnus-summary-prev-page lines t))
7583
7584 (defun gnus-summary-scroll-up (lines)
7585   "Scroll up (or down) one line current article.
7586 Argument LINES specifies lines to be scrolled up (or down if negative)."
7587   (interactive "p")
7588   (gnus-configure-windows 'article)
7589   (gnus-summary-show-thread)
7590   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7591     (gnus-eval-in-buffer-window gnus-article-buffer
7592       (cond ((> lines 0)
7593              (when (gnus-article-next-page lines)
7594                (gnus-message 3 "End of message")))
7595             ((< lines 0)
7596              (gnus-article-prev-page (- lines))))))
7597   (gnus-summary-recenter)
7598   (gnus-summary-position-point))
7599
7600 (defun gnus-summary-scroll-down (lines)
7601   "Scroll down (or up) one line current article.
7602 Argument LINES specifies lines to be scrolled down (or up if negative)."
7603   (interactive "p")
7604   (gnus-summary-scroll-up (- lines)))
7605
7606 (defun gnus-summary-next-same-subject ()
7607   "Select next article which has the same subject as current one."
7608   (interactive)
7609   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7610
7611 (defun gnus-summary-prev-same-subject ()
7612   "Select previous article which has the same subject as current one."
7613   (interactive)
7614   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7615
7616 (defun gnus-summary-next-unread-same-subject ()
7617   "Select next unread article which has the same subject as current one."
7618   (interactive)
7619   (gnus-summary-next-article t (gnus-summary-article-subject)))
7620
7621 (defun gnus-summary-prev-unread-same-subject ()
7622   "Select previous unread article which has the same subject as current one."
7623   (interactive)
7624   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7625
7626 (defun gnus-summary-first-unread-article ()
7627   "Select the first unread article.
7628 Return nil if there are no unread articles."
7629   (interactive)
7630   (prog1
7631       (when (gnus-summary-first-subject t)
7632         (gnus-summary-show-thread)
7633         (gnus-summary-first-subject t)
7634         (gnus-summary-display-article (gnus-summary-article-number)))
7635     (gnus-summary-position-point)))
7636
7637 (defun gnus-summary-first-unread-subject ()
7638   "Place the point on the subject line of the first unread article.
7639 Return nil if there are no unread articles."
7640   (interactive)
7641   (prog1
7642       (when (gnus-summary-first-subject t)
7643         (gnus-summary-show-thread)
7644         (gnus-summary-first-subject t))
7645     (gnus-summary-position-point)))
7646
7647 (defun gnus-summary-first-unseen-subject ()
7648   "Place the point on the subject line of the first unseen article.
7649 Return nil if there are no unseen articles."
7650   (interactive)
7651   (prog1
7652       (when (gnus-summary-first-subject nil nil t)
7653         (gnus-summary-show-thread)
7654         (gnus-summary-first-subject nil nil t))
7655     (gnus-summary-position-point)))
7656
7657 (defun gnus-summary-first-unseen-or-unread-subject ()
7658   "Place the point on the subject line of the first unseen article or,
7659 if all article have been seen, on the subject line of the first unread
7660 article."
7661   (interactive)
7662   (prog1
7663       (unless (when (gnus-summary-first-subject nil nil t)
7664                 (gnus-summary-show-thread)
7665                 (gnus-summary-first-subject nil nil t))
7666         (when (gnus-summary-first-subject t)
7667           (gnus-summary-show-thread)
7668           (gnus-summary-first-subject t)))
7669     (gnus-summary-position-point)))
7670
7671 (defun gnus-summary-first-article ()
7672   "Select the first article.
7673 Return nil if there are no articles."
7674   (interactive)
7675   (prog1
7676       (when (gnus-summary-first-subject)
7677         (gnus-summary-show-thread)
7678         (gnus-summary-first-subject)
7679         (gnus-summary-display-article (gnus-summary-article-number)))
7680     (gnus-summary-position-point)))
7681
7682 (defun gnus-summary-best-unread-article (&optional arg)
7683   "Select the unread article with the highest score.
7684 If given a prefix argument, select the next unread article that has a
7685 score higher than the default score."
7686   (interactive "P")
7687   (let ((article (if arg
7688                      (gnus-summary-better-unread-subject)
7689                    (gnus-summary-best-unread-subject))))
7690     (if article
7691         (gnus-summary-goto-article article)
7692       (error "No unread articles"))))
7693
7694 (defun gnus-summary-best-unread-subject ()
7695   "Select the unread subject with the highest score."
7696   (interactive)
7697   (let ((best -1000000)
7698         (data gnus-newsgroup-data)
7699         article score)
7700     (while data
7701       (and (gnus-data-unread-p (car data))
7702            (> (setq score
7703                     (gnus-summary-article-score (gnus-data-number (car data))))
7704               best)
7705            (setq best score
7706                  article (gnus-data-number (car data))))
7707       (setq data (cdr data)))
7708     (when article
7709       (gnus-summary-goto-subject article))
7710     (gnus-summary-position-point)
7711     article))
7712
7713 (defun gnus-summary-better-unread-subject ()
7714   "Select the first unread subject that has a score over the default score."
7715   (interactive)
7716   (let ((data gnus-newsgroup-data)
7717         article score)
7718     (while (and (setq article (gnus-data-number (car data)))
7719                 (or (gnus-data-read-p (car data))
7720                     (not (> (gnus-summary-article-score article)
7721                             gnus-summary-default-score))))
7722       (setq data (cdr data)))
7723     (when article
7724       (gnus-summary-goto-subject article))
7725     (gnus-summary-position-point)
7726     article))
7727
7728 (defun gnus-summary-last-subject ()
7729   "Go to the last displayed subject line in the group."
7730   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7731     (when article
7732       (gnus-summary-goto-subject article))))
7733
7734 (defun gnus-summary-goto-article (article &optional all-headers force)
7735   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7736 If ALL-HEADERS is non-nil, no header lines are hidden.
7737 If FORCE, go to the article even if it isn't displayed.  If FORCE
7738 is a number, it is the line the article is to be displayed on."
7739   (interactive
7740    (list
7741     (completing-read
7742      "Article number or Message-ID: "
7743      (mapcar (lambda (number) (list (int-to-string number)))
7744              gnus-newsgroup-limit))
7745     current-prefix-arg
7746     t))
7747   (prog1
7748       (if (and (stringp article)
7749                (string-match "@\\|%40" article))
7750           (gnus-summary-refer-article article)
7751         (when (stringp article)
7752           (setq article (string-to-number article)))
7753         (if (gnus-summary-goto-subject article force)
7754             (gnus-summary-display-article article all-headers)
7755           (gnus-message 4 "Couldn't go to article %s" article) nil))
7756     (gnus-summary-position-point)))
7757
7758 (defun gnus-summary-goto-last-article ()
7759   "Go to the previously read article."
7760   (interactive)
7761   (prog1
7762       (when gnus-last-article
7763         (gnus-summary-goto-article gnus-last-article nil t))
7764     (gnus-summary-position-point)))
7765
7766 (defun gnus-summary-pop-article (number)
7767   "Pop one article off the history and go to the previous.
7768 NUMBER articles will be popped off."
7769   (interactive "p")
7770   (let (to)
7771     (setq gnus-newsgroup-history
7772           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7773     (if to
7774         (gnus-summary-goto-article (car to) nil t)
7775       (error "Article history empty")))
7776   (gnus-summary-position-point))
7777
7778 ;; Summary commands and functions for limiting the summary buffer.
7779
7780 (defun gnus-summary-limit-to-articles (n)
7781   "Limit the summary buffer to the next N articles.
7782 If not given a prefix, use the process marked articles instead."
7783   (interactive "P")
7784   (prog1
7785       (let ((articles (gnus-summary-work-articles n)))
7786         (setq gnus-newsgroup-processable nil)
7787         (gnus-summary-limit articles))
7788     (gnus-summary-position-point)))
7789
7790 (defun gnus-summary-pop-limit (&optional total)
7791   "Restore the previous limit.
7792 If given a prefix, remove all limits."
7793   (interactive "P")
7794   (when total
7795     (setq gnus-newsgroup-limits
7796           (list (mapcar (lambda (h) (mail-header-number h))
7797                         gnus-newsgroup-headers))))
7798   (unless gnus-newsgroup-limits
7799     (error "No limit to pop"))
7800   (prog1
7801       (gnus-summary-limit nil 'pop)
7802     (gnus-summary-position-point)))
7803
7804 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7805   "Limit the summary buffer to articles that have subjects that match a regexp.
7806 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7807   (interactive
7808    (list (read-string (if current-prefix-arg
7809                           "Exclude subject (regexp): "
7810                         "Limit to subject (regexp): "))
7811          nil current-prefix-arg))
7812   (unless header
7813     (setq header "subject"))
7814   (when (not (equal "" subject))
7815     (prog1
7816         (let ((articles (gnus-summary-find-matching
7817                          (or header "subject") subject 'all nil nil
7818                          not-matching)))
7819           (unless articles
7820             (error "Found no matches for \"%s\"" subject))
7821           (gnus-summary-limit articles))
7822       (gnus-summary-position-point))))
7823
7824 (defun gnus-summary-limit-to-author (from &optional not-matching)
7825   "Limit the summary buffer to articles that have authors that match a regexp.
7826 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7827   (interactive
7828    (list (read-string (if current-prefix-arg
7829                           "Exclude author (regexp): "
7830                         "Limit to author (regexp): "))
7831          current-prefix-arg))
7832   (gnus-summary-limit-to-subject from "from" not-matching))
7833
7834 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7835   "Limit the summary buffer to articles with the given RECIPIENT.
7836
7837 If NOT-MATCHING, exclude RECIPIENT.
7838
7839 To and Cc headers are checked.  You need to include them in
7840 `nnmail-extra-headers'."
7841   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7842   (interactive
7843    (list (read-string (format "%s recipient (regexp): "
7844                               (if current-prefix-arg "Exclude" "Limit to")))
7845          current-prefix-arg))
7846   (when (not (equal "" recipient))
7847     (prog1 (let* ((to
7848                    (if (memq 'To nnmail-extra-headers)
7849                        (gnus-summary-find-matching
7850                         (cons 'extra 'To) recipient 'all nil nil
7851                         not-matching)
7852                      (gnus-message
7853                       1 "`To' isn't present in `nnmail-extra-headers'")
7854                      (sit-for 1)
7855                      nil))
7856                   (cc
7857                    (if (memq 'Cc nnmail-extra-headers)
7858                        (gnus-summary-find-matching
7859                         (cons 'extra 'Cc) recipient 'all nil nil
7860                         not-matching)
7861                      (gnus-message
7862                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7863                      (sit-for 1)
7864                      nil))
7865                   (articles
7866                    (if not-matching
7867                        ;; We need the numbers that are in both lists:
7868                        (mapcar (lambda (a)
7869                                  (and (memq a to) a))
7870                                cc)
7871                      (nconc to cc))))
7872              (unless articles
7873                (error "Found no matches for \"%s\"" recipient))
7874              (gnus-summary-limit articles))
7875       (gnus-summary-position-point))))
7876
7877 (defun gnus-summary-limit-to-age (age &optional younger-p)
7878   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7879 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7880 articles that are younger than AGE days."
7881   (interactive
7882    (let ((younger current-prefix-arg)
7883          (days-got nil)
7884          days)
7885      (while (not days-got)
7886        (setq days (if younger
7887                       (read-string "Limit to articles younger than (in days, older when negative): ")
7888                     (read-string
7889                      "Limit to articles older than (in days, younger when negative): ")))
7890        (when (> (length days) 0)
7891          (setq days (read days)))
7892        (if (numberp days)
7893            (progn
7894              (setq days-got t)
7895              (when (< days 0)
7896                (setq younger (not younger))
7897                (setq days (* days -1))))
7898          (message "Please enter a number.")
7899          (sleep-for 1)))
7900      (list days younger)))
7901   (prog1
7902       (let ((data gnus-newsgroup-data)
7903             (cutoff (days-to-time age))
7904             articles d date is-younger)
7905         (while (setq d (pop data))
7906           (when (and (vectorp (gnus-data-header d))
7907                      (setq date (mail-header-date (gnus-data-header d))))
7908             (setq is-younger (time-less-p
7909                               (time-since (condition-case ()
7910                                               (date-to-time date)
7911                                             (error '(0 0))))
7912                               cutoff))
7913             (when (if younger-p
7914                       is-younger
7915                     (not is-younger))
7916               (push (gnus-data-number d) articles))))
7917         (gnus-summary-limit (nreverse articles)))
7918     (gnus-summary-position-point)))
7919
7920 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7921   "Limit the summary buffer to articles that match an 'extra' header."
7922   (interactive
7923    (let ((header
7924           (intern
7925            (gnus-completing-read-with-default
7926             (symbol-name (car gnus-extra-headers))
7927             (if current-prefix-arg
7928                 "Exclude extra header"
7929               "Limit extra header")
7930             (mapcar (lambda (x)
7931                       (cons (symbol-name x) x))
7932                     gnus-extra-headers)
7933             nil
7934             t))))
7935      (list header
7936            (read-string (format "%s header %s (regexp): "
7937                                 (if current-prefix-arg "Exclude" "Limit to")
7938                                 header))
7939            current-prefix-arg)))
7940   (when (not (equal "" regexp))
7941     (prog1
7942         (let ((articles (gnus-summary-find-matching
7943                          (cons 'extra header) regexp 'all nil nil
7944                          not-matching)))
7945           (unless articles
7946             (error "Found no matches for \"%s\"" regexp))
7947           (gnus-summary-limit articles))
7948       (gnus-summary-position-point))))
7949
7950 (defun gnus-summary-limit-to-display-predicate ()
7951   "Limit the summary buffer to the predicated in the `display' group parameter."
7952   (interactive)
7953   (unless gnus-newsgroup-display
7954     (error "There is no `display' group parameter"))
7955   (let (articles)
7956     (dolist (number gnus-newsgroup-articles)
7957       (when (funcall gnus-newsgroup-display)
7958         (push number articles)))
7959     (gnus-summary-limit articles))
7960   (gnus-summary-position-point))
7961
7962 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7963 (make-obsolete
7964  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7965
7966 (defun gnus-summary-limit-to-unread (&optional all)
7967   "Limit the summary buffer to articles that are not marked as read.
7968 If ALL is non-nil, limit strictly to unread articles."
7969   (interactive "P")
7970   (if all
7971       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7972     (gnus-summary-limit-to-marks
7973      ;; Concat all the marks that say that an article is read and have
7974      ;; those removed.
7975      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7976            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7977            gnus-low-score-mark gnus-expirable-mark
7978            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7979            gnus-duplicate-mark gnus-souped-mark)
7980      'reverse)))
7981
7982 (defun gnus-summary-limit-to-replied (&optional unreplied)
7983   "Limit the summary buffer to replied articles.
7984 If UNREPLIED (the prefix), limit to unreplied articles."
7985   (interactive "P")
7986   (if unreplied
7987       (gnus-summary-limit
7988        (gnus-set-difference gnus-newsgroup-articles
7989         gnus-newsgroup-replied))
7990     (gnus-summary-limit gnus-newsgroup-replied))
7991   (gnus-summary-position-point))
7992
7993 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7994 (make-obsolete 'gnus-summary-delete-marked-with
7995                'gnus-summary-limit-exclude-marks)
7996
7997 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7998   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7999 If REVERSE, limit the summary buffer to articles that are marked
8000 with MARKS.  MARKS can either be a string of marks or a list of marks.
8001 Returns how many articles were removed."
8002   (interactive "sMarks: ")
8003   (gnus-summary-limit-to-marks marks t))
8004
8005 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8006   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8007 If REVERSE (the prefix), limit the summary buffer to articles that are
8008 not marked with MARKS.  MARKS can either be a string of marks or a
8009 list of marks.
8010 Returns how many articles were removed."
8011   (interactive "sMarks: \nP")
8012   (prog1
8013       (let ((data gnus-newsgroup-data)
8014             (marks (if (listp marks) marks
8015                      (append marks nil))) ; Transform to list.
8016             articles)
8017         (while data
8018           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8019                   (memq (gnus-data-mark (car data)) marks))
8020             (push (gnus-data-number (car data)) articles))
8021           (setq data (cdr data)))
8022         (gnus-summary-limit articles))
8023     (gnus-summary-position-point)))
8024
8025 (defun gnus-summary-limit-to-score (score)
8026   "Limit to articles with score at or above SCORE."
8027   (interactive "NLimit to articles with score of at least: ")
8028   (let ((data gnus-newsgroup-data)
8029         articles)
8030     (while data
8031       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8032                 score)
8033         (push (gnus-data-number (car data)) articles))
8034       (setq data (cdr data)))
8035     (prog1
8036         (gnus-summary-limit articles)
8037       (gnus-summary-position-point))))
8038
8039 (defun gnus-summary-limit-to-unseen ()
8040   "Limit to unseen articles."
8041   (interactive)
8042   (prog1
8043       (gnus-summary-limit gnus-newsgroup-unseen)
8044     (gnus-summary-position-point)))
8045
8046 (defun gnus-summary-limit-include-thread (id)
8047   "Display all the hidden articles that is in the thread with ID in it.
8048 When called interactively, ID is the Message-ID of the current
8049 article."
8050   (interactive (list (mail-header-id (gnus-summary-article-header))))
8051   (let ((articles (gnus-articles-in-thread
8052                    (gnus-id-to-thread (gnus-root-id id)))))
8053     (prog1
8054         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8055       (gnus-summary-limit-include-matching-articles
8056        "subject"
8057        (regexp-quote (gnus-simplify-subject-re
8058                       (mail-header-subject (gnus-id-to-header id)))))
8059       (gnus-summary-position-point))))
8060
8061 (defun gnus-summary-limit-include-matching-articles (header regexp)
8062   "Display all the hidden articles that have HEADERs that match REGEXP."
8063   (interactive (list (read-string "Match on header: ")
8064                      (read-string "Regexp: ")))
8065   (let ((articles (gnus-find-matching-articles header regexp)))
8066     (prog1
8067         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8068       (gnus-summary-position-point))))
8069
8070 (defun gnus-summary-insert-dormant-articles ()
8071   "Insert all the dormant articles for this group into the current buffer."
8072   (interactive)
8073   (let ((gnus-verbose (max 6 gnus-verbose)))
8074     (if (not gnus-newsgroup-dormant)
8075         (gnus-message 3 "No cached articles for this group")
8076       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8077
8078 (defun gnus-summary-limit-include-dormant ()
8079   "Display all the hidden articles that are marked as dormant.
8080 Note that this command only works on a subset of the articles currently
8081 fetched for this group."
8082   (interactive)
8083   (unless gnus-newsgroup-dormant
8084     (error "There are no dormant articles in this group"))
8085   (prog1
8086       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8087     (gnus-summary-position-point)))
8088
8089 (defun gnus-summary-limit-exclude-dormant ()
8090   "Hide all dormant articles."
8091   (interactive)
8092   (prog1
8093       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8094     (gnus-summary-position-point)))
8095
8096 (defun gnus-summary-limit-exclude-childless-dormant ()
8097   "Hide all dormant articles that have no children."
8098   (interactive)
8099   (let ((data (gnus-data-list t))
8100         articles d children)
8101     ;; Find all articles that are either not dormant or have
8102     ;; children.
8103     (while (setq d (pop data))
8104       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8105                 (and (setq children
8106                            (gnus-article-children (gnus-data-number d)))
8107                      (let (found)
8108                        (while children
8109                          (when (memq (car children) articles)
8110                            (setq children nil
8111                                  found t))
8112                          (pop children))
8113                        found)))
8114         (push (gnus-data-number d) articles)))
8115     ;; Do the limiting.
8116     (prog1
8117         (gnus-summary-limit articles)
8118       (gnus-summary-position-point))))
8119
8120 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8121   "Mark all unread excluded articles as read.
8122 If ALL, mark even excluded ticked and dormants as read."
8123   (interactive "P")
8124   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8125   (let ((articles (gnus-sorted-ndifference
8126                    (sort
8127                     (mapcar (lambda (h) (mail-header-number h))
8128                             gnus-newsgroup-headers)
8129                     '<)
8130                    gnus-newsgroup-limit))
8131         article)
8132     (setq gnus-newsgroup-unreads
8133           (gnus-sorted-intersection gnus-newsgroup-unreads
8134                                     gnus-newsgroup-limit))
8135     (if all
8136         (setq gnus-newsgroup-dormant nil
8137               gnus-newsgroup-marked nil
8138               gnus-newsgroup-reads
8139               (nconc
8140                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8141                gnus-newsgroup-reads))
8142       (while (setq article (pop articles))
8143         (unless (or (memq article gnus-newsgroup-dormant)
8144                     (memq article gnus-newsgroup-marked))
8145           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8146
8147 (defun gnus-summary-limit (articles &optional pop)
8148   (if pop
8149       ;; We pop the previous limit off the stack and use that.
8150       (setq articles (car gnus-newsgroup-limits)
8151             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8152     ;; We use the new limit, so we push the old limit on the stack.
8153     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8154   ;; Set the limit.
8155   (setq gnus-newsgroup-limit articles)
8156   (let ((total (length gnus-newsgroup-data))
8157         (data (gnus-data-find-list (gnus-summary-article-number)))
8158         (gnus-summary-mark-below nil)   ; Inhibit this.
8159         found)
8160     ;; This will do all the work of generating the new summary buffer
8161     ;; according to the new limit.
8162     (gnus-summary-prepare)
8163     ;; Hide any threads, possibly.
8164     (gnus-summary-maybe-hide-threads)
8165     ;; Try to return to the article you were at, or one in the
8166     ;; neighborhood.
8167     (when data
8168       ;; We try to find some article after the current one.
8169       (while data
8170         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8171           (setq data nil
8172                 found t))
8173         (setq data (cdr data))))
8174     (unless found
8175       ;; If there is no data, that means that we were after the last
8176       ;; article.  The same goes when we can't find any articles
8177       ;; after the current one.
8178       (goto-char (point-max))
8179       (gnus-summary-find-prev))
8180     (gnus-set-mode-line 'summary)
8181     ;; We return how many articles were removed from the summary
8182     ;; buffer as a result of the new limit.
8183     (- total (length gnus-newsgroup-data))))
8184
8185 (defsubst gnus-invisible-cut-children (threads)
8186   (let ((num 0))
8187     (while threads
8188       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8189         (incf num))
8190       (pop threads))
8191     (< num 2)))
8192
8193 (defsubst gnus-cut-thread (thread)
8194   "Go forwards in the thread until we find an article that we want to display."
8195   (when (or (eq gnus-fetch-old-headers 'some)
8196             (eq gnus-fetch-old-headers 'invisible)
8197             (numberp gnus-fetch-old-headers)
8198             (eq gnus-build-sparse-threads 'some)
8199             (eq gnus-build-sparse-threads 'more))
8200     ;; Deal with old-fetched headers and sparse threads.
8201     (while (and
8202             thread
8203             (or
8204              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8205              (gnus-summary-article-ancient-p
8206               (mail-header-number (car thread))))
8207             (if (or (<= (length (cdr thread)) 1)
8208                     (eq gnus-fetch-old-headers 'invisible))
8209                 (setq gnus-newsgroup-limit
8210                       (delq (mail-header-number (car thread))
8211                             gnus-newsgroup-limit)
8212                       thread (cadr thread))
8213               (when (gnus-invisible-cut-children (cdr thread))
8214                 (let ((th (cdr thread)))
8215                   (while th
8216                     (if (memq (mail-header-number (caar th))
8217                               gnus-newsgroup-limit)
8218                         (setq thread (car th)
8219                               th nil)
8220                       (setq th (cdr th))))))))))
8221   thread)
8222
8223 (defun gnus-cut-threads (threads)
8224   "Cut off all uninteresting articles from the beginning of THREADS."
8225   (when (or (eq gnus-fetch-old-headers 'some)
8226             (eq gnus-fetch-old-headers 'invisible)
8227             (numberp gnus-fetch-old-headers)
8228             (eq gnus-build-sparse-threads 'some)
8229             (eq gnus-build-sparse-threads 'more))
8230     (let ((th threads))
8231       (while th
8232         (setcar th (gnus-cut-thread (car th)))
8233         (setq th (cdr th)))))
8234   ;; Remove nixed out threads.
8235   (delq nil threads))
8236
8237 (defun gnus-summary-initial-limit (&optional show-if-empty)
8238   "Figure out what the initial limit is supposed to be on group entry.
8239 This entails weeding out unwanted dormants, low-scored articles,
8240 fetch-old-headers verbiage, and so on."
8241   ;; Most groups have nothing to remove.
8242   (if (or gnus-inhibit-limiting
8243           (and (null gnus-newsgroup-dormant)
8244                (eq gnus-newsgroup-display 'gnus-not-ignore)
8245                (not (eq gnus-fetch-old-headers 'some))
8246                (not (numberp gnus-fetch-old-headers))
8247                (not (eq gnus-fetch-old-headers 'invisible))
8248                (null gnus-summary-expunge-below)
8249                (not (eq gnus-build-sparse-threads 'some))
8250                (not (eq gnus-build-sparse-threads 'more))
8251                (null gnus-thread-expunge-below)
8252                (not gnus-use-nocem)))
8253       ()                                ; Do nothing.
8254     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8255     (setq gnus-newsgroup-limit nil)
8256     (mapatoms
8257      (lambda (node)
8258        (unless (car (symbol-value node))
8259          ;; These threads have no parents -- they are roots.
8260          (let ((nodes (cdr (symbol-value node)))
8261                thread)
8262            (while nodes
8263              (if (and gnus-thread-expunge-below
8264                       (< (gnus-thread-total-score (car nodes))
8265                          gnus-thread-expunge-below))
8266                  (gnus-expunge-thread (pop nodes))
8267                (setq thread (pop nodes))
8268                (gnus-summary-limit-children thread))))))
8269      gnus-newsgroup-dependencies)
8270     ;; If this limitation resulted in an empty group, we might
8271     ;; pop the previous limit and use it instead.
8272     (when (and (not gnus-newsgroup-limit)
8273                show-if-empty)
8274       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8275     gnus-newsgroup-limit))
8276
8277 (defun gnus-summary-limit-children (thread)
8278   "Return 1 if this subthread is visible and 0 if it is not."
8279   ;; First we get the number of visible children to this thread.  This
8280   ;; is done by recursing down the thread using this function, so this
8281   ;; will really go down to a leaf article first, before slowly
8282   ;; working its way up towards the root.
8283   (when thread
8284     (let* ((max-lisp-eval-depth 5000)
8285            (children
8286            (if (cdr thread)
8287                (apply '+ (mapcar 'gnus-summary-limit-children
8288                                  (cdr thread)))
8289              0))
8290           (number (mail-header-number (car thread)))
8291           score)
8292       (if (and
8293            (not (memq number gnus-newsgroup-marked))
8294            (or
8295             ;; If this article is dormant and has absolutely no visible
8296             ;; children, then this article isn't visible.
8297             (and (memq number gnus-newsgroup-dormant)
8298                  (zerop children))
8299             ;; If this is "fetch-old-headered" and there is no
8300             ;; visible children, then we don't want this article.
8301             (and (or (eq gnus-fetch-old-headers 'some)
8302                      (numberp gnus-fetch-old-headers))
8303                  (gnus-summary-article-ancient-p number)
8304                  (zerop children))
8305             ;; If this is "fetch-old-headered" and `invisible', then
8306             ;; we don't want this article.
8307             (and (eq gnus-fetch-old-headers 'invisible)
8308                  (gnus-summary-article-ancient-p number))
8309             ;; If this is a sparsely inserted article with no children,
8310             ;; we don't want it.
8311             (and (eq gnus-build-sparse-threads 'some)
8312                  (gnus-summary-article-sparse-p number)
8313                  (zerop children))
8314             ;; If we use expunging, and this article is really
8315             ;; low-scored, then we don't want this article.
8316             (when (and gnus-summary-expunge-below
8317                        (< (setq score
8318                                 (or (cdr (assq number gnus-newsgroup-scored))
8319                                     gnus-summary-default-score))
8320                           gnus-summary-expunge-below))
8321               ;; We increase the expunge-tally here, but that has
8322               ;; nothing to do with the limits, really.
8323               (incf gnus-newsgroup-expunged-tally)
8324               ;; We also mark as read here, if that's wanted.
8325               (when (and gnus-summary-mark-below
8326                          (< score gnus-summary-mark-below))
8327                 (setq gnus-newsgroup-unreads
8328                       (delq number gnus-newsgroup-unreads))
8329                 (if gnus-newsgroup-auto-expire
8330                     (push number gnus-newsgroup-expirable)
8331                   (push (cons number gnus-low-score-mark)
8332                         gnus-newsgroup-reads)))
8333               t)
8334             ;; Do the `display' group parameter.
8335             (and gnus-newsgroup-display
8336                  (not (funcall gnus-newsgroup-display)))
8337             ;; Check NoCeM things.
8338             (when (and gnus-use-nocem
8339                        (gnus-nocem-unwanted-article-p
8340                         (mail-header-id (car thread))))
8341               (setq gnus-newsgroup-unreads
8342                     (delq number gnus-newsgroup-unreads))
8343               t)))
8344           ;; Nope, invisible article.
8345           0
8346         ;; Ok, this article is to be visible, so we add it to the limit
8347         ;; and return 1.
8348         (push number gnus-newsgroup-limit)
8349         1))))
8350
8351 (defun gnus-expunge-thread (thread)
8352   "Mark all articles in THREAD as read."
8353   (let* ((number (mail-header-number (car thread))))
8354     (incf gnus-newsgroup-expunged-tally)
8355     ;; We also mark as read here, if that's wanted.
8356     (setq gnus-newsgroup-unreads
8357           (delq number gnus-newsgroup-unreads))
8358     (if gnus-newsgroup-auto-expire
8359         (push number gnus-newsgroup-expirable)
8360       (push (cons number gnus-low-score-mark)
8361             gnus-newsgroup-reads)))
8362   ;; Go recursively through all subthreads.
8363   (mapcar 'gnus-expunge-thread (cdr thread)))
8364
8365 ;; Summary article oriented commands
8366
8367 (defun gnus-summary-refer-parent-article (n)
8368   "Refer parent article N times.
8369 If N is negative, go to ancestor -N instead.
8370 The difference between N and the number of articles fetched is returned."
8371   (interactive "p")
8372   (let ((skip 1)
8373         error header ref)
8374     (when (not (natnump n))
8375       (setq skip (abs n)
8376             n 1))
8377     (while (and (> n 0)
8378                 (not error))
8379       (setq header (gnus-summary-article-header))
8380       (if (and (eq (mail-header-number header)
8381                    (cdr gnus-article-current))
8382                (equal gnus-newsgroup-name
8383                       (car gnus-article-current)))
8384           ;; If we try to find the parent of the currently
8385           ;; displayed article, then we take a look at the actual
8386           ;; References header, since this is slightly more
8387           ;; reliable than the References field we got from the
8388           ;; server.
8389           (save-excursion
8390             (set-buffer gnus-original-article-buffer)
8391             (nnheader-narrow-to-headers)
8392             (unless (setq ref (message-fetch-field "references"))
8393               (when (setq ref (message-fetch-field "in-reply-to"))
8394                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8395             (widen))
8396         (setq ref
8397               ;; It's not the current article, so we take a bet on
8398               ;; the value we got from the server.
8399               (mail-header-references header)))
8400       (if (and ref
8401                (not (equal ref "")))
8402           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8403             (gnus-message 1 "Couldn't find parent"))
8404         (gnus-message 1 "No references in article %d"
8405                       (gnus-summary-article-number))
8406         (setq error t))
8407       (decf n))
8408     (gnus-summary-position-point)
8409     n))
8410
8411 (defun gnus-summary-refer-references ()
8412   "Fetch all articles mentioned in the References header.
8413 Return the number of articles fetched."
8414   (interactive)
8415   (let ((ref (mail-header-references (gnus-summary-article-header)))
8416         (current (gnus-summary-article-number))
8417         (n 0))
8418     (if (or (not ref)
8419             (equal ref ""))
8420         (error "No References in the current article")
8421       ;; For each Message-ID in the References header...
8422       (while (string-match "<[^>]*>" ref)
8423         (incf n)
8424         ;; ... fetch that article.
8425         (gnus-summary-refer-article
8426          (prog1 (match-string 0 ref)
8427            (setq ref (substring ref (match-end 0))))))
8428       (gnus-summary-goto-subject current)
8429       (gnus-summary-position-point)
8430       n)))
8431
8432 (defun gnus-summary-refer-thread (&optional limit)
8433   "Fetch all articles in the current thread.
8434 If LIMIT (the numerical prefix), fetch that many old headers instead
8435 of what's specified by the `gnus-refer-thread-limit' variable."
8436   (interactive "P")
8437   (let ((id (mail-header-id (gnus-summary-article-header)))
8438         (limit (if limit (prefix-numeric-value limit)
8439                  gnus-refer-thread-limit)))
8440     (unless (eq gnus-fetch-old-headers 'invisible)
8441       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8442       ;; Retrieve the headers and read them in.
8443       (if (eq (if (numberp limit)
8444                   (gnus-retrieve-headers
8445                    (list (min
8446                           (+ (mail-header-number
8447                               (gnus-summary-article-header))
8448                              limit)
8449                           gnus-newsgroup-end))
8450                    gnus-newsgroup-name (* limit 2))
8451                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8452                 ;; headers.
8453                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8454                                        gnus-newsgroup-name limit))
8455               'nov)
8456           (gnus-build-all-threads)
8457         (error "Can't fetch thread from back ends that don't support NOV"))
8458       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8459     (gnus-summary-limit-include-thread id)))
8460
8461 (defun gnus-summary-refer-article (message-id)
8462   "Fetch an article specified by MESSAGE-ID."
8463   (interactive "sMessage-ID: ")
8464   (when (and (stringp message-id)
8465              (not (zerop (length message-id))))
8466     (setq message-id (gnus-replace-in-string message-id " " ""))
8467     ;; Construct the correct Message-ID if necessary.
8468     ;; Suggested by tale@pawl.rpi.edu.
8469     (unless (string-match "^<" message-id)
8470       (setq message-id (concat "<" message-id)))
8471     (unless (string-match ">$" message-id)
8472       (setq message-id (concat message-id ">")))
8473     ;; People often post MIDs from URLs, so unhex it:
8474     (unless (string-match "@" message-id)
8475       (setq message-id (gnus-url-unhex-string message-id)))
8476     (let* ((header (gnus-id-to-header message-id))
8477            (sparse (and header
8478                         (gnus-summary-article-sparse-p
8479                          (mail-header-number header))
8480                         (memq (mail-header-number header)
8481                               gnus-newsgroup-limit)))
8482            number)
8483       (cond
8484        ;; If the article is present in the buffer we just go to it.
8485        ((and header
8486              (or (not (gnus-summary-article-sparse-p
8487                        (mail-header-number header)))
8488                  sparse))
8489         (prog1
8490             (gnus-summary-goto-article
8491              (mail-header-number header) nil t)
8492           (when sparse
8493             (gnus-summary-update-article (mail-header-number header)))))
8494        (t
8495         ;; We fetch the article.
8496         (catch 'found
8497           (dolist (gnus-override-method (gnus-refer-article-methods))
8498             (when (and (gnus-check-server gnus-override-method)
8499                        ;; Fetch the header,
8500                        (setq number (gnus-summary-insert-subject message-id)))
8501               ;; and display the article.
8502               (gnus-summary-select-article nil nil nil number)
8503               (throw 'found t)))
8504           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8505
8506 (defun gnus-refer-article-methods ()
8507   "Return a list of referable methods."
8508   (cond
8509    ;; No method, so we default to current and native.
8510    ((null gnus-refer-article-method)
8511     (list gnus-current-select-method gnus-select-method))
8512    ;; Current.
8513    ((eq 'current gnus-refer-article-method)
8514     (list gnus-current-select-method))
8515    ;; List of select methods.
8516    ((not (and (symbolp (car gnus-refer-article-method))
8517               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8518     (let (out)
8519       (dolist (method gnus-refer-article-method)
8520         (push (if (eq 'current method)
8521                   gnus-current-select-method
8522                 method)
8523               out))
8524       (nreverse out)))
8525    ;; One single select method.
8526    (t
8527     (list gnus-refer-article-method))))
8528
8529 (defun gnus-summary-edit-parameters ()
8530   "Edit the group parameters of the current group."
8531   (interactive)
8532   (gnus-group-edit-group gnus-newsgroup-name 'params))
8533
8534 (defun gnus-summary-customize-parameters ()
8535   "Customize the group parameters of the current group."
8536   (interactive)
8537   (gnus-group-customize gnus-newsgroup-name))
8538
8539 (defun gnus-summary-enter-digest-group (&optional force)
8540   "Enter an nndoc group based on the current article.
8541 If FORCE, force a digest interpretation.  If not, try
8542 to guess what the document format is."
8543   (interactive "P")
8544   (let ((conf gnus-current-window-configuration))
8545     (save-window-excursion
8546       (save-excursion
8547         (let (gnus-article-prepare-hook
8548               gnus-display-mime-function
8549               gnus-break-pages)
8550           (gnus-summary-select-article))))
8551     (setq gnus-current-window-configuration conf)
8552     (let* ((name (format "%s-%d"
8553                          (gnus-group-prefixed-name
8554                           gnus-newsgroup-name (list 'nndoc ""))
8555                          (with-current-buffer gnus-summary-buffer
8556                            gnus-current-article)))
8557            (ogroup gnus-newsgroup-name)
8558            (params (append (gnus-info-params (gnus-get-info ogroup))
8559                            (list (cons 'to-group ogroup))
8560                            (list (cons 'parent-group ogroup))
8561                            (list (cons 'save-article-group ogroup))))
8562            (case-fold-search t)
8563            (buf (current-buffer))
8564            dig to-address)
8565       (save-excursion
8566         (set-buffer gnus-original-article-buffer)
8567         ;; Have the digest group inherit the main mail address of
8568         ;; the parent article.
8569         (when (setq to-address (or (gnus-fetch-field "reply-to")
8570                                    (gnus-fetch-field "from")))
8571           (setq params (append
8572                         (list (cons 'to-address
8573                                     (funcall gnus-decode-encoded-word-function
8574                                              to-address))))))
8575         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8576         (insert-buffer-substring gnus-original-article-buffer)
8577         ;; Remove lines that may lead nndoc to misinterpret the
8578         ;; document type.
8579         (narrow-to-region
8580          (goto-char (point-min))
8581          (or (search-forward "\n\n" nil t) (point)))
8582         (goto-char (point-min))
8583         (delete-matching-lines "^Path:\\|^From ")
8584         (widen))
8585       (unwind-protect
8586           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8587                     (gnus-newsgroup-ephemeral-ignored-charsets
8588                      gnus-newsgroup-ignored-charsets))
8589                 (gnus-group-read-ephemeral-group
8590                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8591                               (nndoc-article-type
8592                                ,(if force 'mbox 'guess)))
8593                  t nil nil nil
8594                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8595                                                         "ADAPT")))))
8596               ;; Make all postings to this group go to the parent group.
8597               (nconc (gnus-info-params (gnus-get-info name))
8598                      params)
8599             ;; Couldn't select this doc group.
8600             (switch-to-buffer buf)
8601             (gnus-set-global-variables)
8602             (gnus-configure-windows 'summary)
8603             (gnus-message 3 "Article couldn't be entered?"))
8604         (kill-buffer dig)))))
8605
8606 (defun gnus-summary-read-document (n)
8607   "Open a new group based on the current article(s).
8608 This will allow you to read digests and other similar
8609 documents as newsgroups.
8610 Obeys the standard process/prefix convention."
8611   (interactive "P")
8612   (let* ((ogroup gnus-newsgroup-name)
8613          (params (append (gnus-info-params (gnus-get-info ogroup))
8614                          (list (cons 'to-group ogroup))))
8615          group egroup groups vgroup)
8616     (dolist (article (gnus-summary-work-articles n))
8617       (setq group (format "%s-%d" gnus-newsgroup-name article))
8618       (gnus-summary-remove-process-mark article)
8619       (when (gnus-summary-display-article article)
8620         (save-excursion
8621           (with-temp-buffer
8622             (insert-buffer-substring gnus-original-article-buffer)
8623             ;; Remove some headers that may lead nndoc to make
8624             ;; the wrong guess.
8625             (message-narrow-to-head)
8626             (goto-char (point-min))
8627             (delete-matching-lines "^Path:\\|^From ")
8628             (widen)
8629             (if (setq egroup
8630                       (gnus-group-read-ephemeral-group
8631                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8632                                      (nndoc-article-type guess))
8633                        t nil t))
8634                 (progn
8635                   ;; Make all postings to this group go to the parent group.
8636                   (nconc (gnus-info-params (gnus-get-info egroup))
8637                          params)
8638                   (push egroup groups))
8639               ;; Couldn't select this doc group.
8640               (gnus-error 3 "Article couldn't be entered"))))))
8641     ;; Now we have selected all the documents.
8642     (cond
8643      ((not groups)
8644       (error "None of the articles could be interpreted as documents"))
8645      ((gnus-group-read-ephemeral-group
8646        (setq vgroup (format
8647                      "nnvirtual:%s-%s" gnus-newsgroup-name
8648                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8649        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8650        t
8651        (cons (current-buffer) 'summary)))
8652      (t
8653       (error "Couldn't select virtual nndoc group")))))
8654
8655 (defun gnus-summary-isearch-article (&optional regexp-p)
8656   "Do incremental search forward on the current article.
8657 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8658   (interactive "P")
8659   (let* ((gnus-inhibit-treatment t)
8660          (old (gnus-summary-select-article)))
8661     (gnus-configure-windows 'article)
8662     (gnus-eval-in-buffer-window gnus-article-buffer
8663       (save-restriction
8664         (widen)
8665         (when (eq 'old old)
8666           (gnus-article-show-all-headers))
8667         (goto-char (point-min))
8668         (isearch-forward regexp-p)))))
8669
8670 (defun gnus-summary-search-article-forward (regexp &optional backward)
8671   "Search for an article containing REGEXP forward.
8672 If BACKWARD, search backward instead."
8673   (interactive
8674    (list (read-string
8675           (format "Search article %s (regexp%s): "
8676                   (if current-prefix-arg "backward" "forward")
8677                   (if gnus-last-search-regexp
8678                       (concat ", default " gnus-last-search-regexp)
8679                     "")))
8680          current-prefix-arg))
8681   (if (string-equal regexp "")
8682       (setq regexp (or gnus-last-search-regexp ""))
8683     (setq gnus-last-search-regexp regexp)
8684     (setq gnus-article-before-search gnus-current-article))
8685   ;; Intentionally set gnus-last-article.
8686   (setq gnus-last-article gnus-article-before-search)
8687   (let ((gnus-last-article gnus-last-article))
8688     (if (gnus-summary-search-article regexp backward)
8689         (gnus-summary-show-thread)
8690       (signal 'search-failed (list regexp)))))
8691
8692 (defun gnus-summary-search-article-backward (regexp)
8693   "Search for an article containing REGEXP backward."
8694   (interactive
8695    (list (read-string
8696           (format "Search article backward (regexp%s): "
8697                   (if gnus-last-search-regexp
8698                       (concat ", default " gnus-last-search-regexp)
8699                     "")))))
8700   (gnus-summary-search-article-forward regexp 'backward))
8701
8702 (eval-when-compile
8703   (defmacro gnus-summary-search-article-position-point (regexp backward)
8704     "Dehighlight the last matched text and goto the beginning position."
8705     (` (if (and gnus-summary-search-article-matched-data
8706                 (let ((text (caddr gnus-summary-search-article-matched-data))
8707                       (inhibit-read-only t)
8708                       buffer-read-only)
8709                   (delete-region
8710                    (goto-char (car gnus-summary-search-article-matched-data))
8711                    (cadr gnus-summary-search-article-matched-data))
8712                   (insert text)
8713                   (string-match (, regexp) text)))
8714            (if (, backward) (beginning-of-line) (end-of-line))
8715          (goto-char (if (, backward) (point-max) (point-min))))))
8716
8717   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8718     "Place point where X-Face image is displayed."
8719     (if (featurep 'xemacs)
8720         (` (let ((end (if (search-forward "\n\n" nil t)
8721                           (goto-char (1- (point)))
8722                         (point-min)))
8723                  extent)
8724              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8725              (unless (and (re-search-forward "^From:" end t)
8726                           (setq extent (extent-at (point)))
8727                           (extent-begin-glyph extent))
8728                (goto-char (, opoint)))))
8729       (` (let ((end (if (search-forward "\n\n" nil t)
8730                         (goto-char (1- (point)))
8731                       (point-min)))
8732                (start (or (search-backward "\n\n" nil t) (point-min))))
8733            (goto-char
8734             (or (text-property-any start end 'x-face-image t);; x-face-e21
8735                 (, opoint)))))))
8736
8737   (defmacro gnus-summary-search-article-highlight-matched-text
8738     (backward treated x-face)
8739     "Highlight matched text in the function `gnus-summary-search-article'."
8740     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8741              (end (set-marker (make-marker) (match-end 0)))
8742              (inhibit-read-only t)
8743              buffer-read-only)
8744          (unless treated
8745            (let ((,@
8746                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8747                     (mapcar
8748                      (lambda (item) (setq items (delq item items)))
8749                      '(gnus-treat-buttonize
8750                        gnus-treat-fill-article
8751                        gnus-treat-fill-long-lines
8752                        gnus-treat-emphasize
8753                        gnus-treat-highlight-headers
8754                        gnus-treat-highlight-citation
8755                        gnus-treat-highlight-signature
8756                        gnus-treat-overstrike
8757                        gnus-treat-display-x-face
8758                        gnus-treat-buttonize-head
8759                        gnus-treat-decode-article-as-default-mime-charset))
8760                     items))
8761                  (gnus-treat-display-x-face
8762                   (when (, x-face) gnus-treat-display-x-face)))
8763              (gnus-article-prepare-mime-display)))
8764          (goto-char (if (, backward) start end))
8765          (when (, x-face)
8766            (gnus-summary-search-article-highlight-goto-x-face (point)))
8767          (setq gnus-summary-search-article-matched-data
8768                (list start end (buffer-substring start end)))
8769          (unless (eq start end);; matched text has been deleted. :-<
8770            (put-text-property start end 'face
8771                               (or (find-face 'isearch)
8772                                   'secondary-selection))))))
8773   )
8774
8775 (defun gnus-summary-search-article (regexp &optional backward)
8776   "Search for an article containing REGEXP.
8777 Optional argument BACKWARD means do search for backward.
8778 `gnus-select-article-hook' is not called during the search."
8779   ;; We have to require this here to make sure that the following
8780   ;; dynamic binding isn't shadowed by autoloading.
8781   (require 'gnus-async)
8782   (require 'gnus-art)
8783   (let ((gnus-select-article-hook nil)  ;Disable hook.
8784         (gnus-article-prepare-hook nil)
8785         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8786         (gnus-use-article-prefetch nil)
8787         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8788         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8789         (gnus-visual nil)
8790         (gnus-keep-backlog nil)
8791         (gnus-break-pages nil)
8792         (gnus-summary-display-arrow nil)
8793         (gnus-updated-mode-lines nil)
8794         (gnus-auto-center-summary nil)
8795         (sum (current-buffer))
8796         (found nil)
8797         point treated)
8798     (gnus-save-hidden-threads
8799       (static-if (featurep 'xemacs)
8800           (let ((gnus-inhibit-treatment t))
8801             (setq treated (eq 'old (gnus-summary-select-article)))
8802             (when (and treated
8803                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8804                                  (window-live-p (get-buffer-window
8805                                                  gnus-article-buffer t)))))
8806               (gnus-summary-select-article nil t)
8807               (setq treated nil)))
8808         (let ((gnus-inhibit-treatment t))
8809           (setq treated (eq 'old (gnus-summary-select-article)))
8810           (when (and treated
8811                      (not
8812                       (and (gnus-buffer-live-p gnus-article-buffer)
8813                            (window-live-p (get-buffer-window
8814                                            gnus-article-buffer t))
8815                            (or (not (string-match "^\\^X-Face:" regexp))
8816                                (with-current-buffer gnus-article-buffer
8817                                  gnus-summary-search-article-matched-data)))))
8818             (gnus-summary-select-article nil t)
8819             (setq treated nil))))
8820       (set-buffer gnus-article-buffer)
8821       (widen)
8822       (if treated
8823           (progn
8824             (gnus-article-show-all-headers)
8825             (gnus-summary-search-article-position-point regexp backward))
8826         (goto-char (if backward (point-max) (point-min))))
8827       (while (not found)
8828         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8829         (if (if backward
8830                 (re-search-backward regexp nil t)
8831               (re-search-forward regexp nil t))
8832             ;; We found the regexp.
8833             (progn
8834               (gnus-summary-search-article-highlight-matched-text
8835                backward treated (string-match "^\\^X-Face:" regexp))
8836               (setq found 'found)
8837               (forward-line
8838                (/ (- 2 (window-height
8839                         (get-buffer-window gnus-article-buffer t)))
8840                   2))
8841               (set-window-start
8842                (get-buffer-window (current-buffer))
8843                (point))
8844               (set-buffer sum)
8845               (setq point (point)))
8846           ;; We didn't find it, so we go to the next article.
8847           (set-buffer sum)
8848           (setq found 'not)
8849           (while (eq found 'not)
8850             (if (not (if backward (gnus-summary-find-prev)
8851                        (gnus-summary-find-next)))
8852                 ;; No more articles.
8853                 (setq found t)
8854               ;; Select the next article and adjust point.
8855               (unless (gnus-summary-article-sparse-p
8856                        (gnus-summary-article-number))
8857                 (setq found nil)
8858                 (let ((gnus-inhibit-treatment t))
8859                   (gnus-summary-select-article))
8860                 (setq treated nil)
8861                 (set-buffer gnus-article-buffer)
8862                 (widen)
8863                 (goto-char (if backward (point-max) (point-min))))))))
8864       (gnus-message 7 ""))
8865     ;; Return whether we found the regexp.
8866     (when (eq found 'found)
8867       (goto-char point)
8868       (gnus-summary-show-thread)
8869       (gnus-summary-goto-subject gnus-current-article)
8870       (gnus-summary-position-point)
8871       t)))
8872
8873 (defun gnus-find-matching-articles (header regexp)
8874   "Return a list of all articles that match REGEXP on HEADER.
8875 This search includes all articles in the current group that Gnus has
8876 fetched headers for, whether they are displayed or not."
8877   (let ((articles nil)
8878         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8879         (case-fold-search t))
8880     (dolist (header gnus-newsgroup-headers)
8881       (when (string-match regexp (funcall func header))
8882         (push (mail-header-number header) articles)))
8883     (nreverse articles)))
8884
8885 (defun gnus-summary-find-matching (header regexp &optional backward unread
8886                                           not-case-fold not-matching)
8887   "Return a list of all articles that match REGEXP on HEADER.
8888 The search stars on the current article and goes forwards unless
8889 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8890 If UNREAD is non-nil, only unread articles will
8891 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8892 in the comparisons. If NOT-MATCHING, return a list of all articles that
8893 not match REGEXP on HEADER."
8894   (let ((case-fold-search (not not-case-fold))
8895         articles d func)
8896     (if (consp header)
8897         (if (eq (car header) 'extra)
8898             (setq func
8899                   `(lambda (h)
8900                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8901                          "")))
8902           (error "%s is an invalid header" header))
8903       (unless (fboundp (intern (concat "mail-header-" header)))
8904         (error "%s is not a valid header" header))
8905       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8906     (dolist (d (if (eq backward 'all)
8907                    gnus-newsgroup-data
8908                  (gnus-data-find-list
8909                   (gnus-summary-article-number)
8910                   (gnus-data-list backward))))
8911       (when (and (or (not unread)       ; We want all articles...
8912                      (gnus-data-unread-p d)) ; Or just unreads.
8913                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8914                  (if not-matching
8915                      (not (string-match
8916                            regexp
8917                            (funcall func (gnus-data-header d))))
8918                    (string-match regexp
8919                                  (funcall func (gnus-data-header d)))))
8920         (push (gnus-data-number d) articles))) ; Success!
8921     (nreverse articles)))
8922
8923 (defun gnus-summary-execute-command (header regexp command &optional backward)
8924   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8925 If HEADER is an empty string (or nil), the match is done on the entire
8926 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8927   (interactive
8928    (list (let ((completion-ignore-case t))
8929            (completing-read
8930             "Header name: "
8931             (mapcar (lambda (header) (list (format "%s" header)))
8932                     (append
8933                      '("Number" "Subject" "From" "Lines" "Date"
8934                        "Message-ID" "Xref" "References" "Body")
8935                      gnus-extra-headers))
8936             nil 'require-match))
8937          (read-string "Regexp: ")
8938          (read-key-sequence "Command: ")
8939          current-prefix-arg))
8940   (when (equal header "Body")
8941     (setq header ""))
8942   ;; Hidden thread subtrees must be searched as well.
8943   (gnus-summary-show-all-threads)
8944   ;; We don't want to change current point nor window configuration.
8945   (save-excursion
8946     (save-window-excursion
8947       (let (gnus-visual
8948             gnus-treat-strip-trailing-blank-lines
8949             gnus-treat-strip-leading-blank-lines
8950             gnus-treat-strip-multiple-blank-lines
8951             gnus-treat-hide-boring-headers
8952             gnus-treat-fold-newsgroups
8953             gnus-article-prepare-hook)
8954         (gnus-message 6 "Executing %s..." (key-description command))
8955         ;; We'd like to execute COMMAND interactively so as to give arguments.
8956         (gnus-execute header regexp
8957                       `(call-interactively ',(key-binding command))
8958                       backward)
8959         (gnus-message 6 "Executing %s...done" (key-description command))))))
8960
8961 (defun gnus-summary-beginning-of-article ()
8962   "Scroll the article back to the beginning."
8963   (interactive)
8964   (gnus-summary-select-article)
8965   (gnus-configure-windows 'article)
8966   (gnus-eval-in-buffer-window gnus-article-buffer
8967     (widen)
8968     (goto-char (point-min))
8969     (when gnus-break-pages
8970       (gnus-narrow-to-page))))
8971
8972 (defun gnus-summary-end-of-article ()
8973   "Scroll to the end of the article."
8974   (interactive)
8975   (gnus-summary-select-article)
8976   (gnus-configure-windows 'article)
8977   (gnus-eval-in-buffer-window gnus-article-buffer
8978     (widen)
8979     (goto-char (point-max))
8980     (recenter -3)
8981     (when gnus-break-pages
8982       (when (re-search-backward page-delimiter nil t)
8983         (narrow-to-region (match-end 0) (point-max)))
8984       (gnus-narrow-to-page))))
8985
8986 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8987   "Truncate to LEN and quote all \"(\"'s in STRING."
8988   (gnus-replace-in-string (if (and len (> (length string) len))
8989                               (substring string 0 len)
8990                             string)
8991                           "[()]" "\\\\\\&"))
8992
8993 (defun gnus-summary-print-article (&optional filename n)
8994   "Generate and print a PostScript image of the process-marked (mail) articles.
8995
8996 If used interactively, print the current article if none are
8997 process-marked.  With prefix arg, prompt the user for the name of the
8998 file to save in.
8999
9000 When used from Lisp, accept two optional args FILENAME and N.  N means
9001 to print the next N articles.  If N is negative, print the N previous
9002 articles.  If N is nil and articles have been marked with the process
9003 mark, print these instead.
9004
9005 If the optional first argument FILENAME is nil, send the image to the
9006 printer.  If FILENAME is a string, save the PostScript image in a file with
9007 that name.  If FILENAME is a number, prompt the user for the name of the file
9008 to save in."
9009   (interactive (list (ps-print-preprint current-prefix-arg)))
9010   (dolist (article (gnus-summary-work-articles n))
9011     (gnus-summary-select-article nil nil 'pseudo article)
9012     (gnus-eval-in-buffer-window gnus-article-buffer
9013       (gnus-print-buffer))
9014     (gnus-summary-remove-process-mark article))
9015   (ps-despool filename))
9016
9017 (defun gnus-print-buffer ()
9018   (let ((buffer (generate-new-buffer " *print*")))
9019     (unwind-protect
9020         (progn
9021           (copy-to-buffer buffer (point-min) (point-max))
9022           (set-buffer buffer)
9023           (gnus-remove-text-with-property 'gnus-decoration)
9024           (when (gnus-visual-p 'article-highlight 'highlight)
9025             ;; Copy-to-buffer doesn't copy overlay.  So redo
9026             ;; highlight.
9027             (let ((gnus-article-buffer buffer))
9028               (gnus-article-highlight-citation t)
9029               (gnus-article-highlight-signature)
9030               (gnus-article-emphasize)
9031               (gnus-article-delete-invisible-text)))
9032           (let ((ps-left-header
9033                  (list
9034                   (concat "("
9035                           (gnus-summary-print-truncate-and-quote
9036                            (mail-header-subject gnus-current-headers)
9037                            66) ")")
9038                   (concat "("
9039                           (gnus-summary-print-truncate-and-quote
9040                            (mail-header-from gnus-current-headers)
9041                            45) ")")))
9042                 (ps-right-header
9043                  (list
9044                   "/pagenumberstring load"
9045                   (concat "("
9046                           (mail-header-date gnus-current-headers) ")"))))
9047             (gnus-run-hooks 'gnus-ps-print-hook)
9048             (save-excursion
9049               (if window-system
9050                   (ps-spool-buffer-with-faces)
9051                 (ps-spool-buffer)))))
9052       (kill-buffer buffer))))
9053
9054 (defun gnus-summary-show-article (&optional arg)
9055   "Force redisplaying of the current article.
9056 If ARG (the prefix) is a number, show the article with the charset
9057 defined in `gnus-summary-show-article-charset-alist', or the charset
9058 input.
9059 If ARG (the prefix) is non-nil and not a number, show the raw article
9060 without any article massaging functions being run.  Normally, the key
9061 strokes are `C-u g'."
9062   (interactive "P")
9063   (cond
9064    ((numberp arg)
9065     (gnus-summary-show-article t)
9066     (let* ((gnus-newsgroup-charset
9067             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9068                 (mm-read-coding-system
9069                  "View as charset: " ;; actually it is coding system.
9070                  (with-current-buffer gnus-article-buffer
9071                    (mm-detect-coding-region (point) (point-max))))))
9072            (default-mime-charset gnus-newsgroup-charset)
9073            (gnus-newsgroup-ignored-charsets 'gnus-all))
9074       (gnus-summary-select-article nil 'force)
9075       (let ((deps gnus-newsgroup-dependencies)
9076             head header lines)
9077         (save-excursion
9078           (set-buffer gnus-original-article-buffer)
9079           (save-restriction
9080             (message-narrow-to-head)
9081             (setq head (buffer-string))
9082             (goto-char (point-min))
9083             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9084               (goto-char (point-max))
9085               (widen)
9086               (setq lines (1- (count-lines (point) (point-max))))))
9087           (with-temp-buffer
9088             (insert (format "211 %d Article retrieved.\n"
9089                             (cdr gnus-article-current)))
9090             (insert head)
9091             (if lines (insert (format "Lines: %d\n" lines)))
9092             (insert ".\n")
9093             (let ((nntp-server-buffer (current-buffer)))
9094               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9095         (gnus-data-set-header
9096          (gnus-data-find (cdr gnus-article-current))
9097          header)
9098         (gnus-summary-update-article-line
9099          (cdr gnus-article-current) header)
9100         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9101           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9102    ((not arg)
9103     ;; Select the article the normal way.
9104     (gnus-summary-select-article nil 'force))
9105    (t
9106     ;; We have to require this here to make sure that the following
9107     ;; dynamic binding isn't shadowed by autoloading.
9108     (require 'gnus-async)
9109     (require 'gnus-art)
9110     ;; Bind the article treatment functions to nil.
9111     (let ((gnus-have-all-headers t)
9112           gnus-article-prepare-hook
9113           gnus-article-decode-hook
9114           gnus-break-pages
9115           gnus-show-mime
9116           (gnus-inhibit-treatment t))
9117       (gnus-summary-select-article nil 'force))))
9118   (gnus-summary-goto-subject gnus-current-article)
9119   (gnus-summary-position-point))
9120
9121 (defun gnus-summary-show-raw-article ()
9122   "Show the raw article without any article massaging functions being run."
9123   (interactive)
9124   (gnus-summary-show-article t))
9125
9126 (defun gnus-summary-verbose-headers (&optional arg)
9127   "Toggle permanent full header display.
9128 If ARG is a positive number, turn header display on.
9129 If ARG is a negative number, turn header display off."
9130   (interactive "P")
9131   (setq gnus-show-all-headers
9132         (cond ((or (not (numberp arg))
9133                    (zerop arg))
9134                (not gnus-show-all-headers))
9135               ((natnump arg)
9136                t)))
9137   (gnus-summary-show-article))
9138
9139 (defun gnus-summary-toggle-header (&optional arg)
9140   "Show the headers if they are hidden, or hide them if they are shown.
9141 If ARG is a positive number, show the entire header.
9142 If ARG is a negative number, hide the unwanted header lines."
9143   (interactive "P")
9144   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9145                      (get-buffer-window gnus-article-buffer t))))
9146     (with-current-buffer gnus-article-buffer
9147       (widen)
9148       (article-narrow-to-head)
9149       (let* ((buffer-read-only nil)
9150              (inhibit-point-motion-hooks t)
9151              (hidden (if (numberp arg)
9152                          (>= arg 0)
9153                        (or (not (looking-at "[^ \t\n]+:"))
9154                            (gnus-article-hidden-text-p 'headers))))
9155              s e)
9156         (delete-region (point-min) (point-max))
9157         (with-current-buffer gnus-original-article-buffer
9158           (goto-char (setq s (point-min)))
9159           (setq e (if (search-forward "\n\n" nil t)
9160                       (1- (point))
9161                     (point-max))))
9162         (insert-buffer-substring gnus-original-article-buffer s e)
9163         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9164         ;; article-decode-encoded-words by default.
9165         (article-decode-encoded-words)
9166         (run-hooks 'gnus-article-decode-hook)
9167         (if hidden
9168             (let ((gnus-treat-hide-headers nil)
9169                   (gnus-treat-hide-boring-headers nil))
9170               (gnus-delete-wash-type 'headers)
9171               (gnus-treat-article 'head))
9172           (gnus-treat-article 'head))
9173         (widen)
9174         (if window
9175             (set-window-start window (goto-char (point-min))))
9176         (if gnus-break-pages
9177             (gnus-narrow-to-page)
9178           (when (gnus-visual-p 'page-marker)
9179             (let ((buffer-read-only nil))
9180               (gnus-remove-text-with-property 'gnus-prev)
9181               (gnus-remove-text-with-property 'gnus-next))))
9182         (gnus-set-mode-line 'article)))))
9183
9184 (defun gnus-summary-show-all-headers ()
9185   "Make all header lines visible."
9186   (interactive)
9187   (gnus-summary-toggle-header 1))
9188
9189 (defun gnus-summary-toggle-mime (&optional arg)
9190   "Toggle MIME processing.
9191 If ARG is a positive number, turn MIME processing on."
9192   (interactive "P")
9193   (setq gnus-show-mime
9194         (if (null arg)
9195             (not gnus-show-mime)
9196           (> (prefix-numeric-value arg) 0)))
9197   (gnus-summary-select-article t 'force))
9198
9199 (defun gnus-summary-caesar-message (&optional arg)
9200   "Caesar rotate the current article by 13.
9201 The numerical prefix specifies how many places to rotate each letter
9202 forward."
9203   (interactive "P")
9204   (gnus-summary-select-article)
9205   (let ((mail-header-separator ""))
9206     (gnus-eval-in-buffer-window gnus-article-buffer
9207       (save-restriction
9208         (widen)
9209         (let ((start (window-start))
9210               buffer-read-only)
9211           (message-caesar-buffer-body arg)
9212           (set-window-start (get-buffer-window (current-buffer)) start)))))
9213   ;; Create buttons and stuff...
9214   (gnus-treat-article nil))
9215
9216 (defun gnus-summary-idna-message (&optional arg)
9217   "Decode IDNA encoded domain names in the current articles.
9218 IDNA encoded domain names looks like `xn--bar'.  If a string
9219 remain unencoded after running this function, it is likely an
9220 invalid IDNA string (`xn--bar' is invalid).
9221
9222 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9223 installed for this command to work."
9224   (interactive "P")
9225   (if (not (and (condition-case nil (require 'idna)
9226                   (file-error))
9227                 (mm-coding-system-p 'utf-8)
9228                 (executable-find (symbol-value 'idna-program))))
9229       (gnus-message
9230        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9231     (gnus-summary-select-article)
9232     (let ((mail-header-separator ""))
9233       (gnus-eval-in-buffer-window gnus-article-buffer
9234         (save-restriction
9235           (widen)
9236           (let ((start (window-start))
9237                 buffer-read-only)
9238             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9239               (replace-match (idna-to-unicode (match-string 1))))
9240             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9241
9242 (autoload 'unmorse-region "morse"
9243   "Convert morse coded text in region to ordinary ASCII text."
9244   t)
9245
9246 (defun gnus-summary-morse-message (&optional arg)
9247   "Morse decode the current article."
9248   (interactive "P")
9249   (gnus-summary-select-article)
9250   (let ((mail-header-separator ""))
9251     (gnus-eval-in-buffer-window gnus-article-buffer
9252       (save-excursion
9253         (save-restriction
9254           (widen)
9255           (let ((pos (window-start))
9256                 buffer-read-only)
9257             (goto-char (point-min))
9258             (when (message-goto-body)
9259               (gnus-narrow-to-body))
9260             (goto-char (point-min))
9261             (while (search-forward "·" (point-max) t)
9262               (replace-match "."))
9263             (unmorse-region (point-min) (point-max))
9264             (widen)
9265             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9266
9267 (defun gnus-summary-stop-page-breaking ()
9268   "Stop page breaking in the current article."
9269   (interactive)
9270   (gnus-summary-select-article)
9271   (gnus-eval-in-buffer-window gnus-article-buffer
9272     (widen)
9273     (when (gnus-visual-p 'page-marker)
9274       (let ((buffer-read-only nil))
9275         (gnus-remove-text-with-property 'gnus-prev)
9276         (gnus-remove-text-with-property 'gnus-next))
9277       (setq gnus-page-broken nil))))
9278
9279 (defun gnus-summary-move-article (&optional n to-newsgroup
9280                                             select-method action)
9281   "Move the current article to a different newsgroup.
9282 If N is a positive number, move the N next articles.
9283 If N is a negative number, move the N previous articles.
9284 If N is nil and any articles have been marked with the process mark,
9285 move those articles instead.
9286 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9287 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9288 re-spool using this method.
9289
9290 When called interactively with TO-NEWSGROUP being nil, the value of
9291 the variable `gnus-move-split-methods' is used for finding a default
9292 for the target newsgroup.
9293
9294 For this function to work, both the current newsgroup and the
9295 newsgroup that you want to move to have to support the `request-move'
9296 and `request-accept' functions.
9297
9298 ACTION can be either `move' (the default), `crosspost' or `copy'."
9299   (interactive "P")
9300   (unless action
9301     (setq action 'move))
9302   ;; Check whether the source group supports the required functions.
9303   (cond ((and (eq action 'move)
9304               (not (gnus-check-backend-function
9305                     'request-move-article gnus-newsgroup-name)))
9306          (error "The current group does not support article moving"))
9307         ((and (eq action 'crosspost)
9308               (not (gnus-check-backend-function
9309                     'request-replace-article gnus-newsgroup-name)))
9310          (error "The current group does not support article editing")))
9311   (let ((articles (gnus-summary-work-articles n))
9312         (prefix (if (gnus-check-backend-function
9313                      'request-move-article gnus-newsgroup-name)
9314                     (funcall gnus-move-group-prefix-function
9315                              gnus-newsgroup-name)
9316                   ""))
9317         (names '((move "Move" "Moving")
9318                  (copy "Copy" "Copying")
9319                  (crosspost "Crosspost" "Crossposting")))
9320         (copy-buf (save-excursion
9321                     (nnheader-set-temp-buffer " *copy article*")))
9322         art-group to-method new-xref article to-groups articles-to-update-marks)
9323     (unless (assq action names)
9324       (error "Unknown action %s" action))
9325     ;; Read the newsgroup name.
9326     (when (and (not to-newsgroup)
9327                (not select-method))
9328       (if (and gnus-move-split-methods
9329                (not
9330                 (and (memq gnus-current-article articles)
9331                      (gnus-buffer-live-p gnus-original-article-buffer))))
9332           ;; When `gnus-move-split-methods' is non-nil, we have to
9333           ;; select an article to give `gnus-read-move-group-name' an
9334           ;; opportunity to suggest an appropriate default.  However,
9335           ;; we needn't render or mark the article.
9336           (let ((gnus-display-mime-function nil)
9337                 (gnus-article-prepare-hook nil)
9338                 (gnus-mark-article-hook nil))
9339             (gnus-summary-select-article nil nil nil (car articles))))
9340       (setq to-newsgroup
9341             (gnus-read-move-group-name
9342              (cadr (assq action names))
9343              (symbol-value (intern (format "gnus-current-%s-group" action)))
9344              articles prefix))
9345       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9346     (setq to-method (or select-method
9347                         (gnus-server-to-method
9348                          (gnus-group-method to-newsgroup))))
9349     ;; Check the method we are to move this article to...
9350     (unless (gnus-check-backend-function
9351              'request-accept-article (car to-method))
9352       (error "%s does not support article copying" (car to-method)))
9353     (unless (gnus-check-server to-method)
9354       (error "Can't open server %s" (car to-method)))
9355     (gnus-message 6 "%s to %s: %s..."
9356                   (caddr (assq action names))
9357                   (or (car select-method) to-newsgroup) articles)
9358     (while articles
9359       (setq article (pop articles))
9360       (setq
9361        art-group
9362        (cond
9363         ;; Move the article.
9364         ((eq action 'move)
9365          ;; Remove this article from future suppression.
9366          (gnus-dup-unsuppress-article article)
9367          (let* ((from-method (gnus-find-method-for-group
9368                               gnus-newsgroup-name))
9369                 (to-method (gnus-find-method-for-group
9370                             to-newsgroup))
9371                 (move-is-internal (gnus-method-equal from-method to-method)))
9372          (gnus-request-move-article
9373           article                       ; Article to move
9374           gnus-newsgroup-name           ; From newsgroup
9375           (nth 1 (gnus-find-method-for-group
9376                   gnus-newsgroup-name)) ; Server
9377           (list 'gnus-request-accept-article
9378                 to-newsgroup (list 'quote select-method)
9379                 (not articles) t)       ; Accept form
9380           (not articles)                ; Only save nov last time
9381           move-is-internal)))           ; is this move internal?
9382         ;; Copy the article.
9383         ((eq action 'copy)
9384          (save-excursion
9385            (set-buffer copy-buf)
9386            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9387              (save-restriction
9388                (nnheader-narrow-to-headers)
9389                (dolist (hdr gnus-copy-article-ignored-headers)
9390                  (message-remove-header hdr t)))
9391              (gnus-request-accept-article
9392               to-newsgroup select-method (not articles) t))))
9393         ;; Crosspost the article.
9394         ((eq action 'crosspost)
9395          (let ((xref (message-tokenize-header
9396                       (mail-header-xref (gnus-summary-article-header article))
9397                       " ")))
9398            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9399                                   ":" (number-to-string article)))
9400            (unless xref
9401              (setq xref (list (system-name))))
9402            (setq new-xref
9403                  (concat
9404                   (mapconcat 'identity
9405                              (delete "Xref:" (delete new-xref xref))
9406                              " ")
9407                   " " new-xref))
9408            (save-excursion
9409              (set-buffer copy-buf)
9410              ;; First put the article in the destination group.
9411              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9412              (when (consp (setq art-group
9413                                 (gnus-request-accept-article
9414                                  to-newsgroup select-method (not articles))))
9415                (setq new-xref (concat new-xref " " (car art-group)
9416                                       ":"
9417                                       (number-to-string (cdr art-group))))
9418                ;; Now we have the new Xrefs header, so we insert
9419                ;; it and replace the new article.
9420                (nnheader-replace-header "Xref" new-xref)
9421                (gnus-request-replace-article
9422                 (cdr art-group) to-newsgroup (current-buffer))
9423                art-group))))))
9424       (cond
9425        ((not art-group)
9426         (gnus-message 1 "Couldn't %s article %s: %s"
9427                       (cadr (assq action names)) article
9428                       (nnheader-get-report (car to-method))))
9429        ((eq art-group 'junk)
9430         (when (eq action 'move)
9431           (gnus-summary-mark-article article gnus-canceled-mark)
9432           (gnus-message 4 "Deleted article %s" article)
9433           ;; run the delete hook
9434           (run-hook-with-args 'gnus-summary-article-delete-hook
9435                               action
9436                               (gnus-data-header
9437                                (assoc article (gnus-data-list nil)))
9438                               gnus-newsgroup-name nil
9439                               select-method)))
9440        (t
9441         (let* ((pto-group (gnus-group-prefixed-name
9442                            (car art-group) to-method))
9443                (info (gnus-get-info pto-group))
9444                (to-group (gnus-info-group info))
9445                to-marks)
9446           ;; Update the group that has been moved to.
9447           (when (and info
9448                      (memq action '(move copy)))
9449             (unless (member to-group to-groups)
9450               (push to-group to-groups))
9451
9452             (unless (memq article gnus-newsgroup-unreads)
9453               (push 'read to-marks)
9454               (gnus-info-set-read
9455                info (gnus-add-to-range (gnus-info-read info)
9456                                        (list (cdr art-group)))))
9457
9458             ;; See whether the article is to be put in the cache.
9459             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9460                              gnus-article-mark-lists
9461                            (delete '(expirable . expire)
9462                                    (copy-sequence gnus-article-mark-lists))))
9463                   (to-article (cdr art-group)))
9464
9465               ;; Enter the article into the cache in the new group,
9466               ;; if that is required.
9467               (when gnus-use-cache
9468                 (gnus-cache-possibly-enter-article
9469                  to-group to-article
9470                  (let ((header (copy-sequence
9471                                 (gnus-summary-article-header article))))
9472                    (mail-header-set-number header to-article)
9473                    header)
9474                  (memq article gnus-newsgroup-marked)
9475                  (memq article gnus-newsgroup-dormant)
9476                  (memq article gnus-newsgroup-unreads)))
9477
9478               (when gnus-preserve-marks
9479                 ;; Copy any marks over to the new group.
9480                 (when (and (equal to-group gnus-newsgroup-name)
9481                            (not (memq article gnus-newsgroup-unreads)))
9482                   ;; Mark this article as read in this group.
9483                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9484                   (setcdr (gnus-active to-group) to-article)
9485                   (setcdr gnus-newsgroup-active to-article))
9486
9487                 (while marks
9488                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9489                     (when (memq article (symbol-value
9490                                          (intern (format "gnus-newsgroup-%s"
9491                                                          (caar marks)))))
9492                       (push (cdar marks) to-marks)
9493                       ;; If the other group is the same as this group,
9494                       ;; then we have to add the mark to the list.
9495                       (when (equal to-group gnus-newsgroup-name)
9496                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9497                              (cons to-article
9498                                    (symbol-value
9499                                     (intern (format "gnus-newsgroup-%s"
9500                                                     (caar marks)))))))
9501                       ;; Copy the marks to other group.
9502                       (gnus-add-marked-articles
9503                        to-group (cdar marks) (list to-article) info)))
9504                   (setq marks (cdr marks)))
9505
9506                 (gnus-request-set-mark
9507                  to-group (list (list (list to-article) 'add to-marks))))
9508
9509               (gnus-dribble-enter
9510                (concat "(gnus-group-set-info '"
9511                        (gnus-prin1-to-string (gnus-get-info to-group))
9512                        ")"))))
9513
9514           ;; Update the Xref header in this article to point to
9515           ;; the new crossposted article we have just created.
9516           (when (eq action 'crosspost)
9517             (save-excursion
9518               (set-buffer copy-buf)
9519               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9520               (nnheader-replace-header "Xref" new-xref)
9521               (gnus-request-replace-article
9522                article gnus-newsgroup-name (current-buffer))))
9523
9524           ;; run the move/copy/crosspost/respool hook
9525           (run-hook-with-args 'gnus-summary-article-move-hook
9526                               action
9527                               (gnus-data-header
9528                                (assoc article (gnus-data-list nil)))
9529                               gnus-newsgroup-name
9530                               to-newsgroup
9531                               select-method))
9532
9533         ;;;!!!Why is this necessary?
9534         (set-buffer gnus-summary-buffer)
9535         
9536         (gnus-summary-goto-subject article)
9537         (when (eq action 'move)
9538           (gnus-summary-mark-article article gnus-canceled-mark))))
9539       (push article articles-to-update-marks))
9540
9541     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9542     ;; Re-activate all groups that have been moved to.
9543     (save-excursion
9544       (set-buffer gnus-group-buffer)
9545       (let ((gnus-group-marked to-groups))
9546         (gnus-group-get-new-news-this-group nil t)))
9547     
9548     (gnus-kill-buffer copy-buf)
9549     (gnus-summary-position-point)
9550     (gnus-set-mode-line 'summary)))
9551
9552 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9553   "Copy the current article to some other group.
9554 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9555 When called interactively, if TO-NEWSGROUP is nil, use the value of
9556 the variable `gnus-move-split-methods' for finding a default target
9557 newsgroup.
9558 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9559 re-spool using this method."
9560   (interactive "P")
9561   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9562
9563 (defun gnus-summary-crosspost-article (&optional n)
9564   "Crosspost the current article to some other group."
9565   (interactive "P")
9566   (gnus-summary-move-article n nil nil 'crosspost))
9567
9568 (defcustom gnus-summary-respool-default-method nil
9569   "Default method type for respooling an article.
9570 If nil, use to the current newsgroup method."
9571   :type 'symbol
9572   :group 'gnus-summary-mail)
9573
9574 (defcustom gnus-summary-display-while-building nil
9575   "If non-nil, show and update the summary buffer as it's being built.
9576 If the value is t, update the buffer after every line is inserted.  If
9577 the value is an integer (N), update the display every N lines."
9578   :version "22.1"
9579   :group 'gnus-thread
9580   :type '(choice (const :tag "off" nil)
9581                  number
9582                  (const :tag "frequently" t)))
9583
9584 (defun gnus-summary-respool-article (&optional n method)
9585   "Respool the current article.
9586 The article will be squeezed through the mail spooling process again,
9587 which means that it will be put in some mail newsgroup or other
9588 depending on `nnmail-split-methods'.
9589 If N is a positive number, respool the N next articles.
9590 If N is a negative number, respool the N previous articles.
9591 If N is nil and any articles have been marked with the process mark,
9592 respool those articles instead.
9593
9594 Respooling can be done both from mail groups and \"real\" newsgroups.
9595 In the former case, the articles in question will be moved from the
9596 current group into whatever groups they are destined to.  In the
9597 latter case, they will be copied into the relevant groups."
9598   (interactive
9599    (list current-prefix-arg
9600          (let* ((methods (gnus-methods-using 'respool))
9601                 (methname
9602                  (symbol-name (or gnus-summary-respool-default-method
9603                                   (car (gnus-find-method-for-group
9604                                         gnus-newsgroup-name)))))
9605                 (method
9606                  (gnus-completing-read-with-default
9607                   methname "Backend to use when respooling"
9608                   methods nil t nil 'gnus-mail-method-history))
9609                 ms)
9610            (cond
9611             ((zerop (length (setq ms (gnus-servers-using-backend
9612                                       (intern method)))))
9613              (list (intern method) ""))
9614             ((= 1 (length ms))
9615              (car ms))
9616             (t
9617              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9618                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9619                            ms-alist))))))))
9620   (unless method
9621     (error "No method given for respooling"))
9622   (if (assoc (symbol-name
9623               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9624              (gnus-methods-using 'respool))
9625       (gnus-summary-move-article n nil method)
9626     (gnus-summary-copy-article n nil method)))
9627
9628 (defun gnus-summary-import-article (file &optional edit)
9629   "Import an arbitrary file into a mail newsgroup."
9630   (interactive "fImport file: \nP")
9631   (let ((group gnus-newsgroup-name)
9632         (now (current-time))
9633         atts lines group-art)
9634     (unless (gnus-check-backend-function 'request-accept-article group)
9635       (error "%s does not support article importing" group))
9636     (or (file-readable-p file)
9637         (not (file-regular-p file))
9638         (error "Can't read %s" file))
9639     (save-excursion
9640       (set-buffer (gnus-get-buffer-create " *import file*"))
9641       (erase-buffer)
9642       (nnheader-insert-file-contents file)
9643       (goto-char (point-min))
9644       (if (nnheader-article-p)
9645           (save-restriction
9646             (goto-char (point-min))
9647             (search-forward "\n\n" nil t)
9648             (narrow-to-region (point-min) (1- (point)))
9649             (goto-char (point-min))
9650             (unless (re-search-forward "^date:" nil t)
9651               (goto-char (point-max))
9652               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9653         ;; This doesn't look like an article, so we fudge some headers.
9654         (setq atts (file-attributes file)
9655               lines (count-lines (point-min) (point-max)))
9656         (insert "From: " (read-string "From: ") "\n"
9657                 "Subject: " (read-string "Subject: ") "\n"
9658                 "Date: " (message-make-date (nth 5 atts)) "\n"
9659                 "Message-ID: " (message-make-message-id) "\n"
9660                 "Lines: " (int-to-string lines) "\n"
9661                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9662       (setq group-art (gnus-request-accept-article group nil t))
9663       (kill-buffer (current-buffer)))
9664     (setq gnus-newsgroup-active (gnus-activate-group group))
9665     (forward-line 1)
9666     (gnus-summary-goto-article (cdr group-art) nil t)
9667     (when edit
9668       (gnus-summary-edit-article))))
9669
9670 (defun gnus-summary-create-article ()
9671   "Create an article in a mail newsgroup."
9672   (interactive)
9673   (let ((group gnus-newsgroup-name)
9674         (now (current-time))
9675         group-art)
9676     (unless (gnus-check-backend-function 'request-accept-article group)
9677       (error "%s does not support article importing" group))
9678     (save-excursion
9679       (set-buffer (gnus-get-buffer-create " *import file*"))
9680       (erase-buffer)
9681       (goto-char (point-min))
9682       ;; This doesn't look like an article, so we fudge some headers.
9683       (insert "From: " (read-string "From: ") "\n"
9684               "Subject: " (read-string "Subject: ") "\n"
9685               "Date: " (message-make-date now) "\n"
9686               "Message-ID: " (message-make-message-id) "\n")
9687       (setq group-art (gnus-request-accept-article group nil t))
9688       (kill-buffer (current-buffer)))
9689     (setq gnus-newsgroup-active (gnus-activate-group group))
9690     (forward-line 1)
9691     (gnus-summary-goto-article (cdr group-art) nil t)
9692     (gnus-summary-edit-article)))
9693
9694 (defun gnus-summary-article-posted-p ()
9695   "Say whether the current (mail) article is available from news as well.
9696 This will be the case if the article has both been mailed and posted."
9697   (interactive)
9698   (let ((id (mail-header-references (gnus-summary-article-header)))
9699         (gnus-override-method (car (gnus-refer-article-methods))))
9700     (if (gnus-request-head id "")
9701         (gnus-message 2 "The current message was found on %s"
9702                       gnus-override-method)
9703       (gnus-message 2 "The current message couldn't be found on %s"
9704                     gnus-override-method)
9705       nil)))
9706
9707 (defun gnus-summary-expire-articles (&optional now)
9708   "Expire all articles that are marked as expirable in the current group."
9709   (interactive)
9710   (when (and (not gnus-group-is-exiting-without-update-p)
9711              (gnus-check-backend-function
9712               'request-expire-articles gnus-newsgroup-name))
9713     ;; This backend supports expiry.
9714     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9715            (expirable (if total
9716                           (progn
9717                             ;; We need to update the info for
9718                             ;; this group for `gnus-list-of-read-articles'
9719                             ;; to give us the right answer.
9720                             (gnus-run-hooks 'gnus-exit-group-hook)
9721                             (gnus-summary-update-info)
9722                             (gnus-list-of-read-articles gnus-newsgroup-name))
9723                         (setq gnus-newsgroup-expirable
9724                               (sort gnus-newsgroup-expirable '<))))
9725            (expiry-wait (if now 'immediate
9726                           (gnus-group-find-parameter
9727                            gnus-newsgroup-name 'expiry-wait)))
9728            (nnmail-expiry-target
9729             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9730                 nnmail-expiry-target))
9731            es)
9732       (when expirable
9733         ;; There are expirable articles in this group, so we run them
9734         ;; through the expiry process.
9735         (gnus-message 6 "Expiring articles...")
9736         (unless (gnus-check-group gnus-newsgroup-name)
9737           (error "Can't open server for %s" gnus-newsgroup-name))
9738         ;; The list of articles that weren't expired is returned.
9739         (save-excursion
9740           (if expiry-wait
9741               (let ((nnmail-expiry-wait-function nil)
9742                     (nnmail-expiry-wait expiry-wait))
9743                 (setq es (gnus-request-expire-articles
9744                           expirable gnus-newsgroup-name)))
9745             (setq es (gnus-request-expire-articles
9746                       expirable gnus-newsgroup-name)))
9747           (unless total
9748             (setq gnus-newsgroup-expirable es))
9749           ;; We go through the old list of expirable, and mark all
9750           ;; really expired articles as nonexistent.
9751           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9752             (let ((gnus-use-cache nil))
9753               (dolist (article expirable)
9754                 (when (and (not (memq article es))
9755                            (gnus-data-find article))
9756                   (gnus-summary-mark-article article gnus-canceled-mark)
9757                   (run-hook-with-args 'gnus-summary-article-expire-hook
9758                                       'delete
9759                                       (gnus-data-header
9760                                        (assoc article (gnus-data-list nil)))
9761                                       gnus-newsgroup-name
9762                                       nil
9763                                       nil))))))
9764         (gnus-message 6 "Expiring articles...done")))))
9765
9766 (defun gnus-summary-expire-articles-now ()
9767   "Expunge all expirable articles in the current group.
9768 This means that *all* articles that are marked as expirable will be
9769 deleted forever, right now."
9770   (interactive)
9771   (or gnus-expert-user
9772       (gnus-yes-or-no-p
9773        "Are you really, really, really sure you want to delete all these messages? ")
9774       (error "Phew!"))
9775   (gnus-summary-expire-articles t))
9776
9777 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9778 (defun gnus-summary-delete-article (&optional n)
9779   "Delete the N next (mail) articles.
9780 This command actually deletes articles.  This is not a marking
9781 command.  The article will disappear forever from your life, never to
9782 return.
9783
9784 If N is negative, delete backwards.
9785 If N is nil and articles have been marked with the process mark,
9786 delete these instead.
9787
9788 If `gnus-novice-user' is non-nil you will be asked for
9789 confirmation before the articles are deleted."
9790   (interactive "P")
9791   (unless (gnus-check-backend-function 'request-expire-articles
9792                                        gnus-newsgroup-name)
9793     (error "The current newsgroup does not support article deletion"))
9794   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9795     (error "Couldn't open server"))
9796   ;; Compute the list of articles to delete.
9797   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9798         (nnmail-expiry-target 'delete)
9799         not-deleted)
9800     (if (and gnus-novice-user
9801              (not (gnus-yes-or-no-p
9802                    (format "Do you really want to delete %s forever? "
9803                            (if (> (length articles) 1)
9804                                (format "these %s articles" (length articles))
9805                              "this article")))))
9806         ()
9807       ;; Delete the articles.
9808       (setq not-deleted (gnus-request-expire-articles
9809                          articles gnus-newsgroup-name 'force))
9810       (while articles
9811         (gnus-summary-remove-process-mark (car articles))
9812         ;; The backend might not have been able to delete the article
9813         ;; after all.
9814         (unless (memq (car articles) not-deleted)
9815           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9816         (let* ((article (car articles))
9817                (ghead  (gnus-data-header
9818                                     (assoc article (gnus-data-list nil)))))
9819           (run-hook-with-args 'gnus-summary-article-delete-hook
9820                               'delete ghead gnus-newsgroup-name nil
9821                               nil))
9822         (setq articles (cdr articles)))
9823       (when not-deleted
9824         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9825     (gnus-summary-position-point)
9826     (gnus-set-mode-line 'summary)
9827     not-deleted))
9828
9829 (defun gnus-summary-edit-article (&optional force)
9830   "Edit the current article.
9831 This will have permanent effect only in mail groups.
9832 If FORCE is non-nil, allow editing of articles even in read-only
9833 groups."
9834   (interactive "P")
9835   (save-excursion
9836     (set-buffer gnus-summary-buffer)
9837     (let ((mail-parse-charset gnus-newsgroup-charset)
9838           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9839       (gnus-set-global-variables)
9840       (when (and (not force)
9841                  (gnus-group-read-only-p))
9842         (error "The current newsgroup does not support article editing"))
9843       (gnus-summary-show-article t)
9844       (gnus-article-edit-article
9845        'ignore
9846        `(lambda (no-highlight)
9847           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9848                 (message-options message-options)
9849                 (message-options-set-recipient)
9850                 (mail-parse-ignored-charsets
9851                  ',gnus-newsgroup-ignored-charsets))
9852             (gnus-summary-edit-article-done
9853              ,(or (mail-header-references gnus-current-headers) "")
9854              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9855
9856 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9857
9858 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9859                                                  no-highlight)
9860   "Make edits to the current article permanent."
9861   (interactive)
9862   (save-excursion
9863     ;; The buffer restriction contains the entire article if it exists.
9864     (when (article-goto-body)
9865       (let ((lines (count-lines (point) (point-max)))
9866             (length (- (point-max) (point)))
9867             (case-fold-search t)
9868             (body (copy-marker (point))))
9869         (goto-char (point-min))
9870         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9871           (delete-region (match-beginning 1) (match-end 1))
9872           (insert (number-to-string length)))
9873         (goto-char (point-min))
9874         (when (re-search-forward
9875                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9876           (delete-region (match-beginning 1) (match-end 1))
9877           (insert (number-to-string length)))
9878         (goto-char (point-min))
9879         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9880           (delete-region (match-beginning 1) (match-end 1))
9881           (insert (number-to-string lines))))))
9882   ;; Replace the article.
9883   (let ((buf (current-buffer)))
9884     (with-temp-buffer
9885       (insert-buffer-substring buf)
9886
9887       (if (and (not read-only)
9888                (not (gnus-request-replace-article
9889                      (cdr gnus-article-current) (car gnus-article-current)
9890                      (current-buffer) t)))
9891           (error "Couldn't replace article")
9892         ;; Update the summary buffer.
9893         (if (and references
9894                  (equal (message-tokenize-header references " ")
9895                         (message-tokenize-header
9896                          (or (message-fetch-field "references") "") " ")))
9897             ;; We only have to update this line.
9898             (save-excursion
9899               (save-restriction
9900                 (message-narrow-to-head)
9901                 (let ((head (buffer-substring-no-properties
9902                              (point-min) (point-max)))
9903                       header)
9904                   (with-temp-buffer
9905                     (insert (format "211 %d Article retrieved.\n"
9906                                     (cdr gnus-article-current)))
9907                     (insert head)
9908                     (insert ".\n")
9909                     (let ((nntp-server-buffer (current-buffer)))
9910                       (setq header (car (gnus-get-newsgroup-headers
9911                                          nil t))))
9912                     (save-excursion
9913                       (set-buffer gnus-summary-buffer)
9914                       (gnus-data-set-header
9915                        (gnus-data-find (cdr gnus-article-current))
9916                        header)
9917                       (gnus-summary-update-article-line
9918                        (cdr gnus-article-current) header)
9919                       (if (gnus-summary-goto-subject
9920                            (cdr gnus-article-current) nil t)
9921                           (gnus-summary-update-secondary-mark
9922                            (cdr gnus-article-current))))))))
9923           ;; Update threads.
9924           (set-buffer (or buffer gnus-summary-buffer))
9925           (gnus-summary-update-article (cdr gnus-article-current))
9926           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9927               (gnus-summary-update-secondary-mark
9928                (cdr gnus-article-current))))
9929         ;; Prettify the article buffer again.
9930         (unless no-highlight
9931           (save-excursion
9932             (set-buffer gnus-article-buffer)
9933             ;;;!!! Fix this -- article should be rehighlighted.
9934             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9935             (set-buffer gnus-original-article-buffer)
9936             (gnus-request-article
9937              (cdr gnus-article-current)
9938              (car gnus-article-current) (current-buffer))))
9939         ;; Prettify the summary buffer line.
9940         (when (gnus-visual-p 'summary-highlight 'highlight)
9941           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9942
9943 (defun gnus-summary-edit-wash (key)
9944   "Perform editing command KEY in the article buffer."
9945   (interactive
9946    (list
9947     (progn
9948       (message "%s" (concat (this-command-keys) "- "))
9949       (read-char))))
9950   (message "")
9951   (gnus-summary-edit-article)
9952   (execute-kbd-macro (concat (this-command-keys) key))
9953   (gnus-article-edit-done))
9954
9955 ;;; Respooling
9956
9957 (defun gnus-summary-respool-query (&optional silent trace)
9958   "Query where the respool algorithm would put this article."
9959   (interactive)
9960   (let (gnus-mark-article-hook)
9961     (gnus-summary-select-article)
9962     (save-excursion
9963       (set-buffer gnus-original-article-buffer)
9964       (let ((groups (nnmail-article-group 'identity trace)))
9965         (unless silent
9966           (if groups
9967               (message "This message would go to %s"
9968                        (mapconcat 'car groups ", "))
9969             (message "This message would go to no groups"))
9970           groups)))))
9971
9972 (defun gnus-summary-respool-trace ()
9973   "Trace where the respool algorithm would put this article.
9974 Display a buffer showing all fancy splitting patterns which matched."
9975   (interactive)
9976   (gnus-summary-respool-query nil t))
9977
9978 ;; Summary marking commands.
9979
9980 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9981   "Mark articles which has the same subject as read, and then select the next.
9982 If UNMARK is positive, remove any kind of mark.
9983 If UNMARK is negative, tick articles."
9984   (interactive "P")
9985   (when unmark
9986     (setq unmark (prefix-numeric-value unmark)))
9987   (let ((count
9988          (gnus-summary-mark-same-subject
9989           (gnus-summary-article-subject) unmark)))
9990     ;; Select next unread article.  If auto-select-same mode, should
9991     ;; select the first unread article.
9992     (gnus-summary-next-article t (and gnus-auto-select-same
9993                                       (gnus-summary-article-subject)))
9994     (gnus-message 7 "%d article%s marked as %s"
9995                   count (if (= count 1) " is" "s are")
9996                   (if unmark "unread" "read"))))
9997
9998 (defun gnus-summary-kill-same-subject (&optional unmark)
9999   "Mark articles which has the same subject as read.
10000 If UNMARK is positive, remove any kind of mark.
10001 If UNMARK is negative, tick articles."
10002   (interactive "P")
10003   (when unmark
10004     (setq unmark (prefix-numeric-value unmark)))
10005   (let ((count
10006          (gnus-summary-mark-same-subject
10007           (gnus-summary-article-subject) unmark)))
10008     ;; If marked as read, go to next unread subject.
10009     (when (null unmark)
10010       ;; Go to next unread subject.
10011       (gnus-summary-next-subject 1 t))
10012     (gnus-message 7 "%d articles are marked as %s"
10013                   count (if unmark "unread" "read"))))
10014
10015 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10016   "Mark articles with same SUBJECT as read, and return marked number.
10017 If optional argument UNMARK is positive, remove any kinds of marks.
10018 If optional argument UNMARK is negative, mark articles as unread instead."
10019   (let ((count 1))
10020     (save-excursion
10021       (cond
10022        ((null unmark)                   ; Mark as read.
10023         (while (and
10024                 (progn
10025                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10026                   (gnus-summary-show-thread) t)
10027                 (gnus-summary-find-subject subject))
10028           (setq count (1+ count))))
10029        ((> unmark 0)                    ; Tick.
10030         (while (and
10031                 (progn
10032                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10033                   (gnus-summary-show-thread) t)
10034                 (gnus-summary-find-subject subject))
10035           (setq count (1+ count))))
10036        (t                               ; Mark as unread.
10037         (while (and
10038                 (progn
10039                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10040                   (gnus-summary-show-thread) t)
10041                 (gnus-summary-find-subject subject))
10042           (setq count (1+ count)))))
10043       (gnus-set-mode-line 'summary)
10044       ;; Return the number of marked articles.
10045       count)))
10046
10047 (defun gnus-summary-mark-as-processable (n &optional unmark)
10048   "Set the process mark on the next N articles.
10049 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10050 the process mark instead.  The difference between N and the actual
10051 number of articles marked is returned."
10052   (interactive "P")
10053   (if (and (null n) (gnus-region-active-p))
10054       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10055     (setq n (prefix-numeric-value n))
10056     (let ((backward (< n 0))
10057           (n (abs n)))
10058       (while (and
10059               (> n 0)
10060               (if unmark
10061                   (gnus-summary-remove-process-mark
10062                    (gnus-summary-article-number))
10063                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10064               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10065         (setq n (1- n)))
10066       (when (/= 0 n)
10067         (gnus-message 7 "No more articles"))
10068       (gnus-summary-recenter)
10069       (gnus-summary-position-point)
10070       n)))
10071
10072 (defun gnus-summary-unmark-as-processable (n)
10073   "Remove the process mark from the next N articles.
10074 If N is negative, unmark backward instead.  The difference between N and
10075 the actual number of articles unmarked is returned."
10076   (interactive "P")
10077   (gnus-summary-mark-as-processable n t))
10078
10079 (defun gnus-summary-unmark-all-processable ()
10080   "Remove the process mark from all articles."
10081   (interactive)
10082   (save-excursion
10083     (while gnus-newsgroup-processable
10084       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10085   (gnus-summary-position-point))
10086
10087 (defun gnus-summary-add-mark (article type)
10088   "Mark ARTICLE with a mark of TYPE."
10089   (let ((vtype (car (assq type gnus-article-mark-lists)))
10090         var)
10091     (if (not vtype)
10092         (error "No such mark type: %s" type)
10093       (setq var (intern (format "gnus-newsgroup-%s" type)))
10094       (set var (cons article (symbol-value var)))
10095       (if (memq type '(processable cached replied forwarded recent saved))
10096           (gnus-summary-update-secondary-mark article)
10097         ;;; !!! This is bogus.  We should find out what primary
10098         ;;; !!! mark we want to set.
10099         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10100
10101 (defun gnus-summary-mark-as-expirable (n)
10102   "Mark N articles forward as expirable.
10103 If N is negative, mark backward instead.  The difference between N and
10104 the actual number of articles marked is returned."
10105   (interactive "p")
10106   (gnus-summary-mark-forward n gnus-expirable-mark))
10107
10108 (defun gnus-summary-mark-as-spam (n)
10109   "Mark N articles forward as spam.
10110 If N is negative, mark backward instead.  The difference between N and
10111 the actual number of articles marked is returned."
10112   (interactive "p")
10113   (gnus-summary-mark-forward n gnus-spam-mark))
10114
10115 (defun gnus-summary-mark-article-as-replied (article)
10116   "Mark ARTICLE as replied to and update the summary line.
10117 ARTICLE can also be a list of articles."
10118   (interactive (list (gnus-summary-article-number)))
10119   (let ((articles (if (listp article) article (list article))))
10120     (dolist (article articles)
10121       (unless (numberp article)
10122         (error "%s is not a number" article))
10123       (push article gnus-newsgroup-replied)
10124       (let ((buffer-read-only nil))
10125         (when (gnus-summary-goto-subject article nil t)
10126           (gnus-summary-update-secondary-mark article))))))
10127
10128 (defun gnus-summary-mark-article-as-forwarded (article)
10129   "Mark ARTICLE as forwarded and update the summary line.
10130 ARTICLE can also be a list of articles."
10131   (let ((articles (if (listp article) article (list article))))
10132     (dolist (article articles)
10133       (push article gnus-newsgroup-forwarded)
10134       (let ((buffer-read-only nil))
10135         (when (gnus-summary-goto-subject article nil t)
10136           (gnus-summary-update-secondary-mark article))))))
10137
10138 (defun gnus-summary-set-bookmark (article)
10139   "Set a bookmark in current article."
10140   (interactive (list (gnus-summary-article-number)))
10141   (when (or (not (get-buffer gnus-article-buffer))
10142             (not gnus-current-article)
10143             (not gnus-article-current)
10144             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10145     (error "No current article selected"))
10146   ;; Remove old bookmark, if one exists.
10147   (gnus-pull article gnus-newsgroup-bookmarks)
10148   ;; Set the new bookmark, which is on the form
10149   ;; (article-number . line-number-in-body).
10150   (push
10151    (cons article
10152          (with-current-buffer gnus-article-buffer
10153            (count-lines
10154             (min (point)
10155                  (save-excursion
10156                    (article-goto-body)
10157                    (point)))
10158             (point))))
10159    gnus-newsgroup-bookmarks)
10160   (gnus-message 6 "A bookmark has been added to the current article."))
10161
10162 (defun gnus-summary-remove-bookmark (article)
10163   "Remove the bookmark from the current article."
10164   (interactive (list (gnus-summary-article-number)))
10165   ;; Remove old bookmark, if one exists.
10166   (if (not (assq article gnus-newsgroup-bookmarks))
10167       (gnus-message 6 "No bookmark in current article.")
10168     (gnus-pull article gnus-newsgroup-bookmarks)
10169     (gnus-message 6 "Removed bookmark.")))
10170
10171 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10172 (defun gnus-summary-mark-as-dormant (n)
10173   "Mark N articles forward as dormant.
10174 If N is negative, mark backward instead.  The difference between N and
10175 the actual number of articles marked is returned."
10176   (interactive "p")
10177   (gnus-summary-mark-forward n gnus-dormant-mark))
10178
10179 (defun gnus-summary-set-process-mark (article)
10180   "Set the process mark on ARTICLE and update the summary line."
10181   (setq gnus-newsgroup-processable
10182         (cons article
10183               (delq article gnus-newsgroup-processable)))
10184   (when (gnus-summary-goto-subject article)
10185     (gnus-summary-show-thread)
10186     (gnus-summary-goto-subject article)
10187     (gnus-summary-update-secondary-mark article)))
10188
10189 (defun gnus-summary-remove-process-mark (&rest articles)
10190   "Remove the process mark from ARTICLES and update the summary line."
10191   (dolist (article articles)
10192     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10193     (when (gnus-summary-goto-subject article)
10194       (gnus-summary-show-thread)
10195       (gnus-summary-goto-subject article)
10196       (gnus-summary-update-secondary-mark article)))
10197   t)
10198
10199 (defun gnus-summary-set-saved-mark (article)
10200   "Set the process mark on ARTICLE and update the summary line."
10201   (push article gnus-newsgroup-saved)
10202   (when (gnus-summary-goto-subject article)
10203     (gnus-summary-update-secondary-mark article)))
10204
10205 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10206   "Mark N articles as read forwards.
10207 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10208 The difference between N and the actual number of articles marked is
10209 returned.
10210 If NO-EXPIRE, auto-expiry will be inhibited."
10211   (interactive "p")
10212   (gnus-summary-show-thread)
10213   (let ((backward (< n 0))
10214         (gnus-summary-goto-unread
10215          (and gnus-summary-goto-unread
10216               (not (eq gnus-summary-goto-unread 'never))
10217               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10218                                     gnus-ticked-mark gnus-dormant-mark)))))
10219         (n (abs n))
10220         (mark (or mark gnus-del-mark)))
10221     (while (and (> n 0)
10222                 (gnus-summary-mark-article nil mark no-expire)
10223                 (zerop (gnus-summary-next-subject
10224                         (if backward -1 1)
10225                         (and gnus-summary-goto-unread
10226                              (not (eq gnus-summary-goto-unread 'never)))
10227                         t)))
10228       (setq n (1- n)))
10229     (when (/= 0 n)
10230       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10231     (gnus-summary-recenter)
10232     (gnus-summary-position-point)
10233     (gnus-set-mode-line 'summary)
10234     n))
10235
10236 (defun gnus-summary-mark-article-as-read (mark)
10237   "Mark the current article quickly as read with MARK."
10238   (let ((article (gnus-summary-article-number)))
10239     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10240     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10241     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10242     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10243     (push (cons article mark) gnus-newsgroup-reads)
10244     ;; Possibly remove from cache, if that is used.
10245     (when gnus-use-cache
10246       (gnus-cache-enter-remove-article article))
10247     ;; Allow the backend to change the mark.
10248     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10249     ;; Check for auto-expiry.
10250     (when (and gnus-newsgroup-auto-expire
10251                (memq mark gnus-auto-expirable-marks))
10252       (setq mark gnus-expirable-mark)
10253       ;; Let the backend know about the mark change.
10254       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10255       (push article gnus-newsgroup-expirable))
10256     ;; Set the mark in the buffer.
10257     (gnus-summary-update-mark mark 'unread)
10258     t))
10259
10260 (defun gnus-summary-mark-article-as-unread (mark)
10261   "Mark the current article quickly as unread with MARK."
10262   (let* ((article (gnus-summary-article-number))
10263          (old-mark (gnus-summary-article-mark article)))
10264     ;; Allow the backend to change the mark.
10265     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10266     (if (eq mark old-mark)
10267         t
10268       (if (<= article 0)
10269           (progn
10270             (gnus-error 1 "Can't mark negative article numbers")
10271             nil)
10272         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10273         (setq gnus-newsgroup-spam-marked
10274               (delq article gnus-newsgroup-spam-marked))
10275         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10276         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10277         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10278         (cond ((= mark gnus-ticked-mark)
10279                (setq gnus-newsgroup-marked
10280                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10281                                               article)))
10282               ((= mark gnus-spam-mark)
10283                (setq gnus-newsgroup-spam-marked
10284                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10285                                               article)))
10286               ((= mark gnus-dormant-mark)
10287                (setq gnus-newsgroup-dormant
10288                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10289                                               article)))
10290               (t
10291                (setq gnus-newsgroup-unreads
10292                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10293                                               article))))
10294         (gnus-pull article gnus-newsgroup-reads)
10295
10296         ;; See whether the article is to be put in the cache.
10297         (and gnus-use-cache
10298              (vectorp (gnus-summary-article-header article))
10299              (save-excursion
10300                (gnus-cache-possibly-enter-article
10301                 gnus-newsgroup-name article
10302                 (gnus-summary-article-header article)
10303                 (= mark gnus-ticked-mark)
10304                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10305
10306         ;; Fix the mark.
10307         (gnus-summary-update-mark mark 'unread)
10308         t))))
10309
10310 (defun gnus-summary-mark-article (&optional article mark no-expire)
10311   "Mark ARTICLE with MARK.  MARK can be any character.
10312 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10313 `??' (dormant) and `?E' (expirable).
10314 If MARK is nil, then the default character `?r' is used.
10315 If ARTICLE is nil, then the article on the current line will be
10316 marked.
10317 If NO-EXPIRE, auto-expiry will be inhibited."
10318   ;; The mark might be a string.
10319   (when (stringp mark)
10320     (setq mark (aref mark 0)))
10321   ;; If no mark is given, then we check auto-expiring.
10322   (when (null mark)
10323     (setq mark gnus-del-mark))
10324   (when (and (not no-expire)
10325              gnus-newsgroup-auto-expire
10326              (memq mark gnus-auto-expirable-marks))
10327     (setq mark gnus-expirable-mark))
10328   (let ((article (or article (gnus-summary-article-number)))
10329         (old-mark (gnus-summary-article-mark article)))
10330     ;; Allow the backend to change the mark.
10331     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10332     (if (eq mark old-mark)
10333         t
10334       (unless article
10335         (error "No article on current line"))
10336       (if (not (if (or (= mark gnus-unread-mark)
10337                        (= mark gnus-ticked-mark)
10338                        (= mark gnus-spam-mark)
10339                        (= mark gnus-dormant-mark))
10340                    (gnus-mark-article-as-unread article mark)
10341                  (gnus-mark-article-as-read article mark)))
10342           t
10343         ;; See whether the article is to be put in the cache.
10344         (and gnus-use-cache
10345              (not (= mark gnus-canceled-mark))
10346              (vectorp (gnus-summary-article-header article))
10347              (save-excursion
10348                (gnus-cache-possibly-enter-article
10349                 gnus-newsgroup-name article
10350                 (gnus-summary-article-header article)
10351                 (= mark gnus-ticked-mark)
10352                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10353
10354         (when (gnus-summary-goto-subject article nil t)
10355           (let ((buffer-read-only nil))
10356             (gnus-summary-show-thread)
10357             ;; Fix the mark.
10358             (gnus-summary-update-mark mark 'unread)
10359             t))))))
10360
10361 (defun gnus-summary-update-secondary-mark (article)
10362   "Update the secondary (read, process, cache) mark."
10363   (gnus-summary-update-mark
10364    (cond ((memq article gnus-newsgroup-processable)
10365           gnus-process-mark)
10366          ((memq article gnus-newsgroup-cached)
10367           gnus-cached-mark)
10368          ((memq article gnus-newsgroup-replied)
10369           gnus-replied-mark)
10370          ((memq article gnus-newsgroup-forwarded)
10371           gnus-forwarded-mark)
10372          ((memq article gnus-newsgroup-saved)
10373           gnus-saved-mark)
10374          ((memq article gnus-newsgroup-recent)
10375           gnus-recent-mark)
10376          ((memq article gnus-newsgroup-unseen)
10377           gnus-unseen-mark)
10378          (t gnus-no-mark))
10379    'replied)
10380   (when (gnus-visual-p 'summary-highlight 'highlight)
10381     (gnus-run-hooks 'gnus-summary-update-hook))
10382   t)
10383
10384 (defun gnus-summary-update-download-mark (article)
10385   "Update the download mark."
10386   (gnus-summary-update-mark
10387    (cond ((memq article gnus-newsgroup-undownloaded)
10388           gnus-undownloaded-mark)
10389          (gnus-newsgroup-agentized
10390           gnus-downloaded-mark)
10391          (t
10392           gnus-no-mark))
10393    'download)
10394   (gnus-summary-update-line t)
10395   t)
10396
10397 (defun gnus-summary-update-mark (mark type)
10398   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10399         (buffer-read-only nil))
10400     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10401     (when forward
10402       (when (looking-at "\r")
10403         (incf forward))
10404       (when (<= (+ forward (point)) (point-max))
10405         ;; Go to the right position on the line.
10406         (goto-char (+ forward (point)))
10407         ;; Replace the old mark with the new mark.
10408         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10409         ;; Optionally update the marks by some user rule.
10410         (when (eq type 'unread)
10411           (gnus-data-set-mark
10412            (gnus-data-find (gnus-summary-article-number)) mark)
10413           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10414
10415 (defun gnus-mark-article-as-read (article &optional mark)
10416   "Enter ARTICLE in the pertinent lists and remove it from others."
10417   ;; Make the article expirable.
10418   (let ((mark (or mark gnus-del-mark)))
10419     (setq gnus-newsgroup-expirable
10420           (if (= mark gnus-expirable-mark)
10421               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10422             (delq article gnus-newsgroup-expirable)))
10423     ;; Remove from unread and marked lists.
10424     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10425     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10426     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10427     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10428     (push (cons article mark) gnus-newsgroup-reads)
10429     ;; Possibly remove from cache, if that is used.
10430     (when gnus-use-cache
10431       (gnus-cache-enter-remove-article article))
10432     t))
10433
10434 (defun gnus-mark-article-as-unread (article &optional mark)
10435   "Enter ARTICLE in the pertinent lists and remove it from others."
10436   (let ((mark (or mark gnus-ticked-mark)))
10437     (if (<= article 0)
10438         (progn
10439           (gnus-error 1 "Can't mark negative article numbers")
10440           nil)
10441       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10442             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10443             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10444             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10445             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10446
10447       ;; Unsuppress duplicates?
10448       (when gnus-suppress-duplicates
10449         (gnus-dup-unsuppress-article article))
10450
10451       (cond ((= mark gnus-ticked-mark)
10452              (setq gnus-newsgroup-marked
10453                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10454             ((= mark gnus-spam-mark)
10455              (setq gnus-newsgroup-spam-marked
10456                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10457                                             article)))
10458             ((= mark gnus-dormant-mark)
10459              (setq gnus-newsgroup-dormant
10460                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10461             (t
10462              (setq gnus-newsgroup-unreads
10463                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10464       (gnus-pull article gnus-newsgroup-reads)
10465       t)))
10466
10467 (defalias 'gnus-summary-mark-as-unread-forward
10468   'gnus-summary-tick-article-forward)
10469 (make-obsolete 'gnus-summary-mark-as-unread-forward
10470                'gnus-summary-tick-article-forward)
10471 (defun gnus-summary-tick-article-forward (n)
10472   "Tick N articles forwards.
10473 If N is negative, tick backwards instead.
10474 The difference between N and the number of articles ticked is returned."
10475   (interactive "p")
10476   (gnus-summary-mark-forward n gnus-ticked-mark))
10477
10478 (defalias 'gnus-summary-mark-as-unread-backward
10479   'gnus-summary-tick-article-backward)
10480 (make-obsolete 'gnus-summary-mark-as-unread-backward
10481                'gnus-summary-tick-article-backward)
10482 (defun gnus-summary-tick-article-backward (n)
10483   "Tick N articles backwards.
10484 The difference between N and the number of articles ticked is returned."
10485   (interactive "p")
10486   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10487
10488 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10489 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10490 (defun gnus-summary-tick-article (&optional article clear-mark)
10491   "Mark current article as unread.
10492 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10493 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10494   (interactive)
10495   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10496                                        gnus-ticked-mark)))
10497
10498 (defun gnus-summary-mark-as-read-forward (n)
10499   "Mark N articles as read forwards.
10500 If N is negative, mark backwards instead.
10501 The difference between N and the actual number of articles marked is
10502 returned."
10503   (interactive "p")
10504   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10505
10506 (defun gnus-summary-mark-as-read-backward (n)
10507   "Mark the N articles as read backwards.
10508 The difference between N and the actual number of articles marked is
10509 returned."
10510   (interactive "p")
10511   (gnus-summary-mark-forward
10512    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10513
10514 (defun gnus-summary-mark-as-read (&optional article mark)
10515   "Mark current article as read.
10516 ARTICLE specifies the article to be marked as read.
10517 MARK specifies a string to be inserted at the beginning of the line."
10518   (gnus-summary-mark-article article mark))
10519
10520 (defun gnus-summary-clear-mark-forward (n)
10521   "Clear marks from N articles forward.
10522 If N is negative, clear backward instead.
10523 The difference between N and the number of marks cleared is returned."
10524   (interactive "p")
10525   (gnus-summary-mark-forward n gnus-unread-mark))
10526
10527 (defun gnus-summary-clear-mark-backward (n)
10528   "Clear marks from N articles backward.
10529 The difference between N and the number of marks cleared is returned."
10530   (interactive "p")
10531   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10532
10533 (defun gnus-summary-mark-unread-as-read ()
10534   "Intended to be used by `gnus-summary-mark-article-hook'."
10535   (when (memq gnus-current-article gnus-newsgroup-unreads)
10536     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10537
10538 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10539   "Intended to be used by `gnus-summary-mark-article-hook'."
10540   (let ((mark (gnus-summary-article-mark)))
10541     (when (or (gnus-unread-mark-p mark)
10542               (gnus-read-mark-p mark))
10543       (gnus-summary-mark-article gnus-current-article
10544                                  (or new-mark gnus-read-mark)))))
10545
10546 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10547   "Intended to be used by `gnus-summary-mark-article-hook'."
10548   (let ((mark (gnus-summary-article-mark)))
10549     (when (or (gnus-unread-mark-p mark)
10550               (gnus-read-mark-p mark))
10551       (gnus-summary-mark-article (gnus-summary-article-number)
10552                                  (or new-mark gnus-read-mark)))))
10553
10554 (defun gnus-summary-mark-unread-as-ticked ()
10555   "Intended to be used by `gnus-summary-mark-article-hook'."
10556   (when (memq gnus-current-article gnus-newsgroup-unreads)
10557     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10558
10559 (defun gnus-summary-mark-region-as-read (point mark all)
10560   "Mark all unread articles between point and mark as read.
10561 If given a prefix, mark all articles between point and mark as read,
10562 even ticked and dormant ones."
10563   (interactive "r\nP")
10564   (save-excursion
10565     (let (article)
10566       (goto-char point)
10567       (beginning-of-line)
10568       (while (and
10569               (< (point) mark)
10570               (progn
10571                 (when (or all
10572                           (memq (setq article (gnus-summary-article-number))
10573                                 gnus-newsgroup-unreads))
10574                   (gnus-summary-mark-article article gnus-del-mark))
10575                 t)
10576               (gnus-summary-find-next))))))
10577
10578 (defun gnus-summary-mark-below (score mark)
10579   "Mark articles with score less than SCORE with MARK."
10580   (interactive "P\ncMark: ")
10581   (setq score (if score
10582                   (prefix-numeric-value score)
10583                 (or gnus-summary-default-score 0)))
10584   (save-excursion
10585     (set-buffer gnus-summary-buffer)
10586     (goto-char (point-min))
10587     (while
10588         (progn
10589           (and (< (gnus-summary-article-score) score)
10590                (gnus-summary-mark-article nil mark))
10591           (gnus-summary-find-next)))))
10592
10593 (defun gnus-summary-kill-below (&optional score)
10594   "Mark articles with score below SCORE as read."
10595   (interactive "P")
10596   (gnus-summary-mark-below score gnus-killed-mark))
10597
10598 (defun gnus-summary-clear-above (&optional score)
10599   "Clear all marks from articles with score above SCORE."
10600   (interactive "P")
10601   (gnus-summary-mark-above score gnus-unread-mark))
10602
10603 (defun gnus-summary-tick-above (&optional score)
10604   "Tick all articles with score above SCORE."
10605   (interactive "P")
10606   (gnus-summary-mark-above score gnus-ticked-mark))
10607
10608 (defun gnus-summary-mark-above (score mark)
10609   "Mark articles with score over SCORE with MARK."
10610   (interactive "P\ncMark: ")
10611   (setq score (if score
10612                   (prefix-numeric-value score)
10613                 (or gnus-summary-default-score 0)))
10614   (save-excursion
10615     (set-buffer gnus-summary-buffer)
10616     (goto-char (point-min))
10617     (while (and (progn
10618                   (when (> (gnus-summary-article-score) score)
10619                     (gnus-summary-mark-article nil mark))
10620                   t)
10621                 (gnus-summary-find-next)))))
10622
10623 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10624 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10625 (defun gnus-summary-limit-include-expunged (&optional no-error)
10626   "Display all the hidden articles that were expunged for low scores."
10627   (interactive)
10628   (let ((buffer-read-only nil))
10629     (let ((scored gnus-newsgroup-scored)
10630           headers h)
10631       (while scored
10632         (unless (gnus-summary-article-header (caar scored))
10633           (and (setq h (gnus-number-to-header (caar scored)))
10634                (< (cdar scored) gnus-summary-expunge-below)
10635                (push h headers)))
10636         (setq scored (cdr scored)))
10637       (if (not headers)
10638           (when (not no-error)
10639             (error "No expunged articles hidden"))
10640         (goto-char (point-min))
10641         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10642         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10643         (mapcar (lambda (x) (push (mail-header-number x)
10644                                   gnus-newsgroup-limit))
10645                 headers)
10646         (gnus-summary-prepare-unthreaded (nreverse headers))
10647         (goto-char (point-min))
10648         (gnus-summary-position-point)
10649         t))))
10650
10651 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10652   "Mark all unread articles in this newsgroup as read.
10653 If prefix argument ALL is non-nil, ticked and dormant articles will
10654 also be marked as read.
10655 If QUIETLY is non-nil, no questions will be asked.
10656
10657 If TO-HERE is non-nil, it should be a point in the buffer.  All
10658 articles before (after, if REVERSE is set) this point will be marked
10659 as read.
10660
10661 Note that this function will only catch up the unread article
10662 in the current summary buffer limitation.
10663
10664 The number of articles marked as read is returned."
10665   (interactive "P")
10666   (prog1
10667       (save-excursion
10668         (when (or quietly
10669                   (not gnus-interactive-catchup) ;Without confirmation?
10670                   gnus-expert-user
10671                   (gnus-y-or-n-p
10672                    (if all
10673                        "Mark absolutely all articles as read? "
10674                      "Mark all unread articles as read? ")))
10675           (if (and not-mark
10676                    (not gnus-newsgroup-adaptive)
10677                    (not gnus-newsgroup-auto-expire)
10678                    (not gnus-suppress-duplicates)
10679                    (or (not gnus-use-cache)
10680                        (eq gnus-use-cache 'passive)))
10681               (progn
10682                 (when all
10683                   (setq gnus-newsgroup-marked nil
10684                         gnus-newsgroup-spam-marked nil
10685                         gnus-newsgroup-dormant nil))
10686                 (setq gnus-newsgroup-unreads
10687                       (gnus-sorted-nunion
10688                        (gnus-intersection gnus-newsgroup-unreads
10689                                           gnus-newsgroup-downloadable)
10690                        gnus-newsgroup-unfetched)))
10691             ;; We actually mark all articles as canceled, which we
10692             ;; have to do when using auto-expiry or adaptive scoring.
10693             (gnus-summary-show-all-threads)
10694             (if (and to-here reverse)
10695                 (progn
10696                   (goto-char to-here)
10697                   (gnus-summary-mark-current-read-and-unread-as-read
10698                    gnus-catchup-mark)
10699                   (while (gnus-summary-find-next (not all))
10700                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10701               (when (gnus-summary-first-subject (not all))
10702                 (while (and
10703                         (if to-here (< (point) to-here) t)
10704                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10705                         (gnus-summary-find-next (not all))))))
10706             (gnus-set-mode-line 'summary))
10707           t))
10708     (gnus-summary-position-point)))
10709
10710 (defun gnus-summary-catchup-to-here (&optional all)
10711   "Mark all unticked articles before the current one as read.
10712 If ALL is non-nil, also mark ticked and dormant articles as read."
10713   (interactive "P")
10714   (save-excursion
10715     (gnus-save-hidden-threads
10716       (let ((beg (point)))
10717         ;; We check that there are unread articles.
10718         (when (or all (gnus-summary-find-prev))
10719           (gnus-summary-catchup all t beg)))))
10720   (gnus-summary-position-point))
10721
10722 (defun gnus-summary-catchup-from-here (&optional all)
10723   "Mark all unticked articles after (and including) the current one as read.
10724 If ALL is non-nil, also mark ticked and dormant articles as read."
10725   (interactive "P")
10726   (save-excursion
10727     (gnus-save-hidden-threads
10728       (let ((beg (point)))
10729         ;; We check that there are unread articles.
10730         (when (or all (gnus-summary-find-next))
10731           (gnus-summary-catchup all t beg nil t)))))
10732   (gnus-summary-position-point))
10733
10734 (defun gnus-summary-catchup-all (&optional quietly)
10735   "Mark all articles in this newsgroup as read.
10736 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10737 instead, which marks only unread articles as read."
10738   (interactive "P")
10739   (gnus-summary-catchup t quietly))
10740
10741 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10742   "Mark all unread articles in this group as read, then exit.
10743 If prefix argument ALL is non-nil, all articles are marked as read.
10744 If QUIETLY is non-nil, no questions will be asked."
10745   (interactive "P")
10746   (when (gnus-summary-catchup all quietly nil 'fast)
10747     ;; Select next newsgroup or exit.
10748     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10749              (eq gnus-auto-select-next 'quietly))
10750         (gnus-summary-next-group nil)
10751       (gnus-summary-exit))))
10752
10753 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10754   "Mark all articles in this newsgroup as read, and then exit.
10755 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10756 instead, which marks only unread articles as read."
10757   (interactive "P")
10758   (gnus-summary-catchup-and-exit t quietly))
10759
10760 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10761   "Mark all articles in this group as read and select the next group.
10762 If given a prefix, mark all articles, unread as well as ticked, as
10763 read."
10764   (interactive "P")
10765   (save-excursion
10766     (gnus-summary-catchup all))
10767   (gnus-summary-next-group))
10768
10769 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10770   "Mark all articles in this group as read and select the previous group.
10771 If given a prefix, mark all articles, unread as well as ticked, as
10772 read."
10773   (interactive "P")
10774   (save-excursion
10775     (gnus-summary-catchup all))
10776   (gnus-summary-next-group nil nil t))
10777
10778 ;;;
10779 ;;; with article
10780 ;;;
10781
10782 (defmacro gnus-with-article (article &rest forms)
10783   "Select ARTICLE and perform FORMS in the original article buffer.
10784 Then replace the article with the result."
10785   `(progn
10786      ;; We don't want the article to be marked as read.
10787      (let (gnus-mark-article-hook)
10788        (gnus-summary-select-article t t nil ,article))
10789      (set-buffer gnus-original-article-buffer)
10790      ,@forms
10791      (if (not (gnus-check-backend-function
10792                'request-replace-article (car gnus-article-current)))
10793          (gnus-message 5 "Read-only group; not replacing")
10794        (unless (gnus-request-replace-article
10795                 ,article (car gnus-article-current)
10796                 (current-buffer) t)
10797          (error "Couldn't replace article")))
10798      ;; The cache and backlog have to be flushed somewhat.
10799      (when gnus-keep-backlog
10800        (gnus-backlog-remove-article
10801         (car gnus-article-current) (cdr gnus-article-current)))
10802      (when gnus-use-cache
10803        (gnus-cache-update-article
10804         (car gnus-article-current) (cdr gnus-article-current)))))
10805
10806 (put 'gnus-with-article 'lisp-indent-function 1)
10807 (put 'gnus-with-article 'edebug-form-spec '(form body))
10808
10809 ;; Thread-based commands.
10810
10811 (defun gnus-summary-articles-in-thread (&optional article)
10812   "Return a list of all articles in the current thread.
10813 If ARTICLE is non-nil, return all articles in the thread that starts
10814 with that article."
10815   (let* ((article (or article (gnus-summary-article-number)))
10816          (data (gnus-data-find-list article))
10817          (top-level (gnus-data-level (car data)))
10818          (top-subject
10819           (cond ((null gnus-thread-operation-ignore-subject)
10820                  (gnus-simplify-subject-re
10821                   (mail-header-subject (gnus-data-header (car data)))))
10822                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10823                  (gnus-simplify-subject-fuzzy
10824                   (mail-header-subject (gnus-data-header (car data)))))
10825                 (t nil)))
10826          (end-point (save-excursion
10827                       (if (gnus-summary-go-to-next-thread)
10828                           (point) (point-max))))
10829          articles)
10830     (while (and data
10831                 (< (gnus-data-pos (car data)) end-point))
10832       (when (or (not top-subject)
10833                 (string= top-subject
10834                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10835                              (gnus-simplify-subject-fuzzy
10836                               (mail-header-subject
10837                                (gnus-data-header (car data))))
10838                            (gnus-simplify-subject-re
10839                             (mail-header-subject
10840                              (gnus-data-header (car data)))))))
10841         (push (gnus-data-number (car data)) articles))
10842       (unless (and (setq data (cdr data))
10843                    (> (gnus-data-level (car data)) top-level))
10844         (setq data nil)))
10845     ;; Return the list of articles.
10846     (nreverse articles)))
10847
10848 (defun gnus-summary-rethread-current ()
10849   "Rethread the thread the current article is part of."
10850   (interactive)
10851   (let* ((gnus-show-threads t)
10852          (article (gnus-summary-article-number))
10853          (id (mail-header-id (gnus-summary-article-header)))
10854          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10855     (unless id
10856       (error "No article on the current line"))
10857     (gnus-rebuild-thread id)
10858     (gnus-summary-goto-subject article)))
10859
10860 (defun gnus-summary-reparent-thread ()
10861   "Make the current article child of the marked (or previous) article.
10862
10863 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10864 is non-nil or the Subject: of both articles are the same."
10865   (interactive)
10866   (unless (not (gnus-group-read-only-p))
10867     (error "The current newsgroup does not support article editing"))
10868   (unless (<= (length gnus-newsgroup-processable) 1)
10869     (error "No more than one article may be marked"))
10870   (save-window-excursion
10871     (let ((gnus-article-buffer " *reparent*")
10872           (current-article (gnus-summary-article-number))
10873           ;; First grab the marked article, otherwise one line up.
10874           (parent-article (if (not (null gnus-newsgroup-processable))
10875                               (car gnus-newsgroup-processable)
10876                             (save-excursion
10877                               (if (eq (forward-line -1) 0)
10878                                   (gnus-summary-article-number)
10879                                 (error "Beginning of summary buffer"))))))
10880       (unless (not (eq current-article parent-article))
10881         (error "An article may not be self-referential"))
10882       (let ((message-id (mail-header-id
10883                          (gnus-summary-article-header parent-article))))
10884         (unless (and message-id (not (equal message-id "")))
10885           (error "No message-id in desired parent"))
10886         (gnus-with-article current-article
10887           (save-restriction
10888             (goto-char (point-min))
10889             (message-narrow-to-head)
10890             (if (re-search-forward "^References: " nil t)
10891                 (progn
10892                   (re-search-forward "^[^ \t]" nil t)
10893                   (forward-line -1)
10894                   (end-of-line)
10895                   (insert " " message-id))
10896               (insert "References: " message-id "\n"))))
10897         (set-buffer gnus-summary-buffer)
10898         (gnus-summary-unmark-all-processable)
10899         (gnus-summary-update-article current-article)
10900         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10901             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10902         (gnus-summary-rethread-current)
10903         (gnus-message 3 "Article %d is now the child of article %d"
10904                       current-article parent-article)))))
10905
10906 (defun gnus-summary-toggle-threads (&optional arg)
10907   "Toggle showing conversation threads.
10908 If ARG is positive number, turn showing conversation threads on."
10909   (interactive "P")
10910   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10911     (setq gnus-show-threads
10912           (if (null arg) (not gnus-show-threads)
10913             (> (prefix-numeric-value arg) 0)))
10914     (gnus-summary-prepare)
10915     (gnus-summary-goto-subject current)
10916     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10917     (gnus-summary-position-point)))
10918
10919 (defun gnus-summary-show-all-threads ()
10920   "Show all threads."
10921   (interactive)
10922   (save-excursion
10923     (let ((buffer-read-only nil))
10924       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10925   (gnus-summary-position-point))
10926
10927 (defun gnus-summary-show-thread ()
10928   "Show thread subtrees.
10929 Returns nil if no thread was there to be shown."
10930   (interactive)
10931   (let ((buffer-read-only nil)
10932         (orig (point))
10933         (end (point-at-eol))
10934         ;; Leave point at bol
10935         (beg (progn (beginning-of-line) (point))))
10936     (prog1
10937         ;; Any hidden lines here?
10938         (search-forward "\r" end t)
10939       (subst-char-in-region beg end ?\^M ?\n t)
10940       (goto-char orig)
10941       (gnus-summary-position-point))))
10942
10943 (defun gnus-summary-maybe-hide-threads ()
10944   "If requested, hide the threads that should be hidden."
10945   (when (and gnus-show-threads
10946              gnus-thread-hide-subtree)
10947     (gnus-summary-hide-all-threads
10948      (if (or (consp gnus-thread-hide-subtree)
10949              (functionp gnus-thread-hide-subtree))
10950          (gnus-make-predicate gnus-thread-hide-subtree)
10951        nil))))
10952
10953 ;;; Hiding predicates.
10954
10955 (defun gnus-article-unread-p (header)
10956   (memq (mail-header-number header) gnus-newsgroup-unreads))
10957
10958 (defun gnus-article-unseen-p (header)
10959   (memq (mail-header-number header) gnus-newsgroup-unseen))
10960
10961 (defun gnus-map-articles (predicate articles)
10962   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10963   (apply 'gnus-or (mapcar predicate
10964                           (mapcar 'gnus-summary-article-header articles))))
10965
10966 (defun gnus-summary-hide-all-threads (&optional predicate)
10967   "Hide all thread subtrees.
10968 If PREDICATE is supplied, threads that satisfy this predicate
10969 will not be hidden."
10970   (interactive)
10971   (save-excursion
10972     (goto-char (point-min))
10973     (let ((end nil))
10974       (while (not end)
10975         (when (or (not predicate)
10976                   (gnus-map-articles
10977                    predicate (gnus-summary-article-children)))
10978             (gnus-summary-hide-thread))
10979         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10980   (gnus-summary-position-point))
10981
10982 (defun gnus-summary-hide-thread ()
10983   "Hide thread subtrees.
10984 If PREDICATE is supplied, threads that satisfy this predicate
10985 will not be hidden.
10986 Returns nil if no threads were there to be hidden."
10987   (interactive)
10988   (let ((buffer-read-only nil)
10989         (start (point))
10990         (article (gnus-summary-article-number)))
10991     (goto-char start)
10992     ;; Go forward until either the buffer ends or the subthread
10993     ;; ends.
10994     (when (and (not (eobp))
10995                (or (zerop (gnus-summary-next-thread 1 t))
10996                    (goto-char (point-max))))
10997       (prog1
10998           (if (and (> (point) start)
10999                    (search-backward "\n" start t))
11000               (progn
11001                 (subst-char-in-region start (point) ?\n ?\^M)
11002                 (gnus-summary-goto-subject article))
11003             (goto-char start)
11004             nil)))))
11005
11006 (defun gnus-summary-go-to-next-thread (&optional previous)
11007   "Go to the same level (or less) next thread.
11008 If PREVIOUS is non-nil, go to previous thread instead.
11009 Return the article number moved to, or nil if moving was impossible."
11010   (let ((level (gnus-summary-thread-level))
11011         (way (if previous -1 1))
11012         (beg (point)))
11013     (forward-line way)
11014     (while (and (not (eobp))
11015                 (< level (gnus-summary-thread-level)))
11016       (forward-line way))
11017     (if (eobp)
11018         (progn
11019           (goto-char beg)
11020           nil)
11021       (setq beg (point))
11022       (prog1
11023           (gnus-summary-article-number)
11024         (goto-char beg)))))
11025
11026 (defun gnus-summary-next-thread (n &optional silent)
11027   "Go to the same level next N'th thread.
11028 If N is negative, search backward instead.
11029 Returns the difference between N and the number of skips actually
11030 done.
11031
11032 If SILENT, don't output messages."
11033   (interactive "p")
11034   (let ((backward (< n 0))
11035         (n (abs n)))
11036     (while (and (> n 0)
11037                 (gnus-summary-go-to-next-thread backward))
11038       (decf n))
11039     (unless silent
11040       (gnus-summary-position-point))
11041     (when (and (not silent) (/= 0 n))
11042       (gnus-message 7 "No more threads"))
11043     n))
11044
11045 (defun gnus-summary-prev-thread (n)
11046   "Go to the same level previous N'th thread.
11047 Returns the difference between N and the number of skips actually
11048 done."
11049   (interactive "p")
11050   (gnus-summary-next-thread (- n)))
11051
11052 (defun gnus-summary-go-down-thread ()
11053   "Go down one level in the current thread."
11054   (let ((children (gnus-summary-article-children)))
11055     (when children
11056       (gnus-summary-goto-subject (car children)))))
11057
11058 (defun gnus-summary-go-up-thread ()
11059   "Go up one level in the current thread."
11060   (let ((parent (gnus-summary-article-parent)))
11061     (when parent
11062       (gnus-summary-goto-subject parent))))
11063
11064 (defun gnus-summary-down-thread (n)
11065   "Go down thread N steps.
11066 If N is negative, go up instead.
11067 Returns the difference between N and how many steps down that were
11068 taken."
11069   (interactive "p")
11070   (let ((up (< n 0))
11071         (n (abs n)))
11072     (while (and (> n 0)
11073                 (if up (gnus-summary-go-up-thread)
11074                   (gnus-summary-go-down-thread)))
11075       (setq n (1- n)))
11076     (gnus-summary-position-point)
11077     (when (/= 0 n)
11078       (gnus-message 7 "Can't go further"))
11079     n))
11080
11081 (defun gnus-summary-up-thread (n)
11082   "Go up thread N steps.
11083 If N is negative, go down instead.
11084 Returns the difference between N and how many steps down that were
11085 taken."
11086   (interactive "p")
11087   (gnus-summary-down-thread (- n)))
11088
11089 (defun gnus-summary-top-thread ()
11090   "Go to the top of the thread."
11091   (interactive)
11092   (while (gnus-summary-go-up-thread))
11093   (gnus-summary-article-number))
11094
11095 (defun gnus-summary-kill-thread (&optional unmark)
11096   "Mark articles under current thread as read.
11097 If the prefix argument is positive, remove any kinds of marks.
11098 If the prefix argument is negative, tick articles instead."
11099   (interactive "P")
11100   (when unmark
11101     (setq unmark (prefix-numeric-value unmark)))
11102   (let ((articles (gnus-summary-articles-in-thread)))
11103     (save-excursion
11104       ;; Expand the thread.
11105       (gnus-summary-show-thread)
11106       ;; Mark all the articles.
11107       (while articles
11108         (gnus-summary-goto-subject (car articles))
11109         (cond ((null unmark)
11110                (gnus-summary-mark-article-as-read gnus-killed-mark))
11111               ((> unmark 0)
11112                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11113               (t
11114                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11115         (setq articles (cdr articles))))
11116     ;; Hide killed subtrees.
11117     (and (null unmark)
11118          gnus-thread-hide-killed
11119          (gnus-summary-hide-thread))
11120     ;; If marked as read, go to next unread subject.
11121     (when (null unmark)
11122       ;; Go to next unread subject.
11123       (gnus-summary-next-subject 1 t)))
11124   (gnus-set-mode-line 'summary))
11125
11126 ;; Summary sorting commands
11127
11128 (defun gnus-summary-sort-by-number (&optional reverse)
11129   "Sort the summary buffer by article number.
11130 Argument REVERSE means reverse order."
11131   (interactive "P")
11132   (gnus-summary-sort 'number reverse))
11133
11134 (defun gnus-summary-sort-by-random (&optional reverse)
11135   "Randomize the order in the summary buffer.
11136 Argument REVERSE means to randomize in reverse order."
11137   (interactive "P")
11138   (gnus-summary-sort 'random reverse))
11139
11140 (defun gnus-summary-sort-by-author (&optional reverse)
11141   "Sort the summary buffer by author name alphabetically.
11142 If `case-fold-search' is non-nil, case of letters is ignored.
11143 Argument REVERSE means reverse order."
11144   (interactive "P")
11145   (gnus-summary-sort 'author reverse))
11146
11147 (defun gnus-summary-sort-by-recipient (&optional reverse)
11148   "Sort the summary buffer by recipient name alphabetically.
11149 If `case-fold-search' is non-nil, case of letters is ignored.
11150 Argument REVERSE means reverse order."
11151   (interactive "P")
11152   (gnus-summary-sort 'recipient reverse))
11153
11154 (defun gnus-summary-sort-by-subject (&optional reverse)
11155   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11156 If `case-fold-search' is non-nil, case of letters is ignored.
11157 Argument REVERSE means reverse order."
11158   (interactive "P")
11159   (gnus-summary-sort 'subject reverse))
11160
11161 (defun gnus-summary-sort-by-date (&optional reverse)
11162   "Sort the summary buffer by date.
11163 Argument REVERSE means reverse order."
11164   (interactive "P")
11165   (gnus-summary-sort 'date reverse))
11166
11167 (defun gnus-summary-sort-by-score (&optional reverse)
11168   "Sort the summary buffer by score.
11169 Argument REVERSE means reverse order."
11170   (interactive "P")
11171   (gnus-summary-sort 'score reverse))
11172
11173 (defun gnus-summary-sort-by-lines (&optional reverse)
11174   "Sort the summary buffer by the number of lines.
11175 Argument REVERSE means reverse order."
11176   (interactive "P")
11177   (gnus-summary-sort 'lines reverse))
11178
11179 (defun gnus-summary-sort-by-chars (&optional reverse)
11180   "Sort the summary buffer by article length.
11181 Argument REVERSE means reverse order."
11182   (interactive "P")
11183   (gnus-summary-sort 'chars reverse))
11184
11185 (defun gnus-summary-sort-by-original (&optional reverse)
11186   "Sort the summary buffer using the default sorting method.
11187 Argument REVERSE means reverse order."
11188   (interactive "P")
11189   (let* ((buffer-read-only)
11190          (gnus-summary-prepare-hook nil))
11191     ;; We do the sorting by regenerating the threads.
11192     (gnus-summary-prepare)
11193     ;; Hide subthreads if needed.
11194     (gnus-summary-maybe-hide-threads)))
11195
11196 (defun gnus-summary-sort (predicate reverse)
11197   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11198   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11199          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11200          (gnus-thread-sort-functions
11201           (if (not reverse)
11202               thread
11203             `(lambda (t1 t2)
11204                (,thread t2 t1))))
11205          (gnus-sort-gathered-threads-function
11206           gnus-thread-sort-functions)
11207          (gnus-article-sort-functions
11208           (if (not reverse)
11209               article
11210             `(lambda (t1 t2)
11211                (,article t2 t1))))
11212          (buffer-read-only)
11213          (gnus-summary-prepare-hook nil))
11214     ;; We do the sorting by regenerating the threads.
11215     (gnus-summary-prepare)
11216     ;; Hide subthreads if needed.
11217     (gnus-summary-maybe-hide-threads)))
11218
11219 ;; Summary saving commands.
11220
11221 (defun gnus-summary-save-article (&optional n not-saved)
11222   "Save the current article using the default saver function.
11223 If N is a positive number, save the N next articles.
11224 If N is a negative number, save the N previous articles.
11225 If N is nil and any articles have been marked with the process mark,
11226 save those articles instead.
11227 The variable `gnus-default-article-saver' specifies the saver function."
11228   (interactive "P")
11229   (let* ((articles (gnus-summary-work-articles n))
11230          (save-buffer (save-excursion
11231                         (nnheader-set-temp-buffer " *Gnus Save*")))
11232          (num (length articles))
11233          header file)
11234     (dolist (article articles)
11235       (setq header (gnus-summary-article-header article))
11236       (if (not (vectorp header))
11237           ;; This is a pseudo-article.
11238           (if (assq 'name header)
11239               (gnus-copy-file (cdr (assq 'name header)))
11240             (gnus-message 1 "Article %d is unsaveable" article))
11241         ;; This is a real article.
11242         (save-window-excursion
11243           (let ((gnus-display-mime-function nil)
11244                 (gnus-article-prepare-hook nil))
11245             (gnus-summary-select-article t nil nil article)))
11246         (save-excursion
11247           (set-buffer save-buffer)
11248           (erase-buffer)
11249           (insert-buffer-substring gnus-original-article-buffer))
11250         (setq file (gnus-article-save save-buffer file num))
11251         (gnus-summary-remove-process-mark article)
11252         (unless not-saved
11253           (gnus-summary-set-saved-mark article))))
11254     (gnus-kill-buffer save-buffer)
11255     (gnus-summary-position-point)
11256     (gnus-set-mode-line 'summary)
11257     n))
11258
11259 (defun gnus-summary-pipe-output (&optional arg headers)
11260   "Pipe the current article to a subprocess.
11261 If N is a positive number, pipe the N next articles.
11262 If N is a negative number, pipe the N previous articles.
11263 If N is nil and any articles have been marked with the process mark,
11264 pipe those articles instead.
11265 If HEADERS (the symbolic prefix), include the headers, too."
11266   (interactive (gnus-interactive "P\ny"))
11267   (require 'gnus-art)
11268   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11269         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11270     (gnus-summary-save-article arg t))
11271   (let ((buffer (get-buffer "*Shell Command Output*")))
11272     (when (and buffer
11273                (not (zerop (buffer-size buffer))))
11274       (gnus-configure-windows 'pipe))))
11275
11276 (defun gnus-summary-save-article-mail (&optional arg)
11277   "Append the current article to an mail file.
11278 If N is a positive number, save the N next articles.
11279 If N is a negative number, save the N previous articles.
11280 If N is nil and any articles have been marked with the process mark,
11281 save those articles instead."
11282   (interactive "P")
11283   (require 'gnus-art)
11284   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11285     (gnus-summary-save-article arg)))
11286
11287 (defun gnus-summary-save-article-rmail (&optional arg)
11288   "Append the current article to an rmail file.
11289 If N is a positive number, save the N next articles.
11290 If N is a negative number, save the N previous articles.
11291 If N is nil and any articles have been marked with the process mark,
11292 save those articles instead."
11293   (interactive "P")
11294   (require 'gnus-art)
11295   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11296     (gnus-summary-save-article arg)))
11297
11298 (defun gnus-summary-save-article-file (&optional arg)
11299   "Append the current article to a file.
11300 If N is a positive number, save the N next articles.
11301 If N is a negative number, save the N previous articles.
11302 If N is nil and any articles have been marked with the process mark,
11303 save those articles instead."
11304   (interactive "P")
11305   (require 'gnus-art)
11306   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11307     (gnus-summary-save-article arg)))
11308
11309 (defun gnus-summary-write-article-file (&optional arg)
11310   "Write the current article to a file, deleting the previous file.
11311 If N is a positive number, save the N next articles.
11312 If N is a negative number, save the N previous articles.
11313 If N is nil and any articles have been marked with the process mark,
11314 save those articles instead."
11315   (interactive "P")
11316   (require 'gnus-art)
11317   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11318     (gnus-summary-save-article arg)))
11319
11320 (defun gnus-summary-save-article-body-file (&optional arg)
11321   "Append the current article body to a file.
11322 If N is a positive number, save the N next articles.
11323 If N is a negative number, save the N previous articles.
11324 If N is nil and any articles have been marked with the process mark,
11325 save those articles instead."
11326   (interactive "P")
11327   (require 'gnus-art)
11328   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11329     (gnus-summary-save-article arg)))
11330
11331 (defun gnus-summary-muttprint (&optional arg)
11332   "Print the current article using Muttprint.
11333 If N is a positive number, save the N next articles.
11334 If N is a negative number, save the N previous articles.
11335 If N is nil and any articles have been marked with the process mark,
11336 save those articles instead."
11337   (interactive "P")
11338   (require 'gnus-art)
11339   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11340     (gnus-summary-save-article arg t)))
11341
11342 (defun gnus-summary-pipe-message (program)
11343   "Pipe the current article through PROGRAM."
11344   (interactive "sProgram: ")
11345   (gnus-summary-select-article)
11346   (let ((mail-header-separator ""))
11347     (gnus-eval-in-buffer-window gnus-article-buffer
11348       (save-restriction
11349         (widen)
11350         (let ((start (window-start))
11351               buffer-read-only)
11352           (message-pipe-buffer-body program)
11353           (set-window-start (get-buffer-window (current-buffer)) start))))))
11354
11355 (defun gnus-get-split-value (methods)
11356   "Return a value based on the split METHODS."
11357   (let (split-name method result match)
11358     (when methods
11359       (save-excursion
11360         (set-buffer gnus-original-article-buffer)
11361         (save-restriction
11362           (nnheader-narrow-to-headers)
11363           (while (and methods (not split-name))
11364             (goto-char (point-min))
11365             (setq method (pop methods))
11366             (setq match (car method))
11367             (when (cond
11368                    ((stringp match)
11369                     ;; Regular expression.
11370                     (ignore-errors
11371                       (re-search-forward match nil t)))
11372                    ((functionp match)
11373                     ;; Function.
11374                     (save-restriction
11375                       (widen)
11376                       (setq result (funcall match gnus-newsgroup-name))))
11377                    ((consp match)
11378                     ;; Form.
11379                     (save-restriction
11380                       (widen)
11381                       (setq result (eval match)))))
11382               (setq split-name (cdr method))
11383               (cond ((stringp result)
11384                      (push (expand-file-name
11385                             result gnus-article-save-directory)
11386                            split-name))
11387                     ((consp result)
11388                      (setq split-name (append result split-name)))))))))
11389     (nreverse split-name)))
11390
11391 (defun gnus-valid-move-group-p (group)
11392   (and (boundp group)
11393        (symbol-name group)
11394        (symbol-value group)
11395        (gnus-get-function (gnus-find-method-for-group
11396                            (symbol-name group)) 'request-accept-article t)))
11397
11398 (defun gnus-read-move-group-name (prompt default articles prefix)
11399   "Read a group name."
11400   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11401          (minibuffer-confirm-incomplete nil) ; XEmacs
11402          (prom
11403           (format "%s %s to"
11404                   prompt
11405                   (if (> (length articles) 1)
11406                       (format "these %d articles" (length articles))
11407                     "this article")))
11408          (to-newsgroup
11409           (cond
11410            ((null split-name)
11411             (gnus-completing-read-with-default
11412              default prom
11413              gnus-active-hashtb
11414              'gnus-valid-move-group-p
11415              nil prefix
11416              'gnus-group-history))
11417            ((= 1 (length split-name))
11418             (gnus-completing-read-with-default
11419              (car split-name) prom
11420              gnus-active-hashtb
11421              'gnus-valid-move-group-p
11422              nil nil
11423              'gnus-group-history))
11424            (t
11425             (gnus-completing-read-with-default
11426              nil prom
11427              (mapcar 'list (nreverse split-name))
11428              nil nil nil
11429              'gnus-group-history))))
11430          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11431     (when to-newsgroup
11432       (if (or (string= to-newsgroup "")
11433               (string= to-newsgroup prefix))
11434           (setq to-newsgroup default))
11435       (unless to-newsgroup
11436         (error "No group name entered"))
11437       (or (gnus-active to-newsgroup)
11438           (gnus-activate-group to-newsgroup nil nil to-method)
11439           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11440                                      to-newsgroup))
11441               (or (and (gnus-request-create-group to-newsgroup to-method)
11442                        (gnus-activate-group
11443                         to-newsgroup nil nil to-method)
11444                        (gnus-subscribe-group to-newsgroup))
11445                   (error "Couldn't create group %s" to-newsgroup)))
11446           (error "No such group: %s" to-newsgroup)))
11447     to-newsgroup))
11448
11449 (defun gnus-summary-save-parts (type dir n &optional reverse)
11450   "Save parts matching TYPE to DIR.
11451 If REVERSE, save parts that do not match TYPE."
11452   (interactive
11453    (list (read-string "Save parts of type: "
11454                       (or (car gnus-summary-save-parts-type-history)
11455                           gnus-summary-save-parts-default-mime)
11456                       'gnus-summary-save-parts-type-history)
11457          (setq gnus-summary-save-parts-last-directory
11458                (read-file-name "Save to directory: "
11459                                gnus-summary-save-parts-last-directory
11460                                nil t))
11461          current-prefix-arg))
11462   (gnus-summary-iterate n
11463     (let ((gnus-display-mime-function nil)
11464           (gnus-inhibit-treatment t))
11465       (gnus-summary-select-article))
11466     (save-excursion
11467       (set-buffer gnus-article-buffer)
11468       (let ((handles (or gnus-article-mime-handles
11469                          (mm-dissect-buffer nil gnus-article-loose-mime)
11470                          (and gnus-article-emulate-mime
11471                               (mm-uu-dissect)))))
11472         (when handles
11473           (gnus-summary-save-parts-1 type dir handles reverse)
11474           (unless gnus-article-mime-handles ;; Don't destroy this case.
11475             (mm-destroy-parts handles)))))))
11476
11477 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11478   (if (stringp (car handle))
11479       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11480               (cdr handle))
11481     (when (if reverse
11482               (not (string-match type (mm-handle-media-type handle)))
11483             (string-match type (mm-handle-media-type handle)))
11484       (let ((file (expand-file-name
11485                    (gnus-map-function
11486                     mm-file-name-rewrite-functions
11487                     (file-name-nondirectory
11488                      (or
11489                       (mail-content-type-get
11490                        (mm-handle-disposition handle) 'filename)
11491                       (mail-content-type-get
11492                        (mm-handle-type handle) 'name)
11493                       (concat gnus-newsgroup-name
11494                               "." (number-to-string
11495                                    (cdr gnus-article-current))))))
11496                    dir)))
11497         (unless (file-exists-p file)
11498           (mm-save-part-to-file handle file))))))
11499
11500 ;; Summary extract commands
11501
11502 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11503   (let ((buffer-read-only nil)
11504         (article (gnus-summary-article-number))
11505         after-article b e)
11506     (unless (gnus-summary-goto-subject article)
11507       (error "No such article: %d" article))
11508     (gnus-summary-position-point)
11509     ;; If all commands are to be bunched up on one line, we collect
11510     ;; them here.
11511     (unless gnus-view-pseudos-separately
11512       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11513             files action)
11514         (while ps
11515           (setq action (cdr (assq 'action (car ps))))
11516           (setq files (list (cdr (assq 'name (car ps)))))
11517           (while (and ps (cdr ps)
11518                       (string= (or action "1")
11519                                (or (cdr (assq 'action (cadr ps))) "2")))
11520             (push (cdr (assq 'name (cadr ps))) files)
11521             (setcdr ps (cddr ps)))
11522           (when files
11523             (when (not (string-match "%s" action))
11524               (push " " files))
11525             (push " " files)
11526             (when (assq 'execute (car ps))
11527               (setcdr (assq 'execute (car ps))
11528                       (funcall (if (string-match "%s" action)
11529                                    'format 'concat)
11530                                action
11531                                (mapconcat
11532                                 (lambda (f)
11533                                   (if (equal f " ")
11534                                       f
11535                                     (shell-quote-argument f)))
11536                                 files " ")))))
11537           (setq ps (cdr ps)))))
11538     (if (and gnus-view-pseudos (not not-view))
11539         (while pslist
11540           (when (assq 'execute (car pslist))
11541             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11542                                   (eq gnus-view-pseudos 'not-confirm)))
11543           (setq pslist (cdr pslist)))
11544       (save-excursion
11545         (while pslist
11546           (setq after-article (or (cdr (assq 'article (car pslist)))
11547                                   (gnus-summary-article-number)))
11548           (gnus-summary-goto-subject after-article)
11549           (forward-line 1)
11550           (setq b (point))
11551           (insert "    " (file-name-nondirectory
11552                           (cdr (assq 'name (car pslist))))
11553                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11554           (setq e (point))
11555           (forward-line -1)             ; back to `b'
11556           (gnus-add-text-properties
11557            b (1- e) (list 'gnus-number gnus-reffed-article-number
11558                           gnus-mouse-face-prop gnus-mouse-face))
11559           (gnus-data-enter
11560            after-article gnus-reffed-article-number
11561            gnus-unread-mark b (car pslist) 0 (- e b))
11562           (setq gnus-newsgroup-unreads
11563                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11564                                          gnus-reffed-article-number))
11565           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11566           (setq pslist (cdr pslist)))))))
11567
11568 (defun gnus-pseudos< (p1 p2)
11569   (let ((c1 (cdr (assq 'action p1)))
11570         (c2 (cdr (assq 'action p2))))
11571     (and c1 c2 (string< c1 c2))))
11572
11573 (defun gnus-request-pseudo-article (props)
11574   (cond ((assq 'execute props)
11575          (gnus-execute-command (cdr (assq 'execute props)))))
11576   (let ((gnus-current-article (gnus-summary-article-number)))
11577     (gnus-run-hooks 'gnus-mark-article-hook)))
11578
11579 (defun gnus-execute-command (command &optional automatic)
11580   (save-excursion
11581     (gnus-article-setup-buffer)
11582     (set-buffer gnus-article-buffer)
11583     (setq buffer-read-only nil)
11584     (let ((command (if automatic command
11585                      (read-string "Command: " (cons command 0)))))
11586       (erase-buffer)
11587       (insert "$ " command "\n\n")
11588       (if gnus-view-pseudo-asynchronously
11589           (start-process "gnus-execute" (current-buffer) shell-file-name
11590                          shell-command-switch command)
11591         (call-process shell-file-name nil t nil
11592                       shell-command-switch command)))))
11593
11594 ;; Summary kill commands.
11595
11596 (defun gnus-summary-edit-global-kill (article)
11597   "Edit the \"global\" kill file."
11598   (interactive (list (gnus-summary-article-number)))
11599   (gnus-group-edit-global-kill article))
11600
11601 (defun gnus-summary-edit-local-kill ()
11602   "Edit a local kill file applied to the current newsgroup."
11603   (interactive)
11604   (setq gnus-current-headers (gnus-summary-article-header))
11605   (gnus-group-edit-local-kill
11606    (gnus-summary-article-number) gnus-newsgroup-name))
11607
11608 ;;; Header reading.
11609
11610 (defun gnus-read-header (id &optional header)
11611   "Read the headers of article ID and enter them into the Gnus system."
11612   (let ((group gnus-newsgroup-name)
11613         (gnus-override-method
11614          (or
11615           gnus-override-method
11616           (and (gnus-news-group-p gnus-newsgroup-name)
11617                (car (gnus-refer-article-methods)))))
11618         where)
11619     ;; First we check to see whether the header in question is already
11620     ;; fetched.
11621     (if (stringp id)
11622         ;; This is a Message-ID.
11623         (setq header (or header (gnus-id-to-header id)))
11624       ;; This is an article number.
11625       (setq header (or header (gnus-summary-article-header id))))
11626     (if (and header
11627              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11628         ;; We have found the header.
11629         header
11630       ;; We have to really fetch the header to this article.
11631       (save-excursion
11632         (set-buffer nntp-server-buffer)
11633         (when (setq where (gnus-request-head id group))
11634           (nnheader-fold-continuation-lines)
11635           (goto-char (point-max))
11636           (insert ".\n")
11637           (goto-char (point-min))
11638           (insert "211 ")
11639           (princ (cond
11640                   ((numberp id) id)
11641                   ((cdr where) (cdr where))
11642                   (header (mail-header-number header))
11643                   (t gnus-reffed-article-number))
11644                  (current-buffer))
11645           (insert " Article retrieved.\n"))
11646         (if (or (not where)
11647                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11648             ()                          ; Malformed head.
11649           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11650             (when (and (stringp id)
11651                        (not (string= (gnus-group-real-name group)
11652                                      (car where))))
11653               ;; If we fetched by Message-ID and the article came
11654               ;; from a different group, we fudge some bogus article
11655               ;; numbers for this article.
11656               (mail-header-set-number header gnus-reffed-article-number))
11657             (save-excursion
11658               (set-buffer gnus-summary-buffer)
11659               (decf gnus-reffed-article-number)
11660               (gnus-remove-header (mail-header-number header))
11661               (push header gnus-newsgroup-headers)
11662               (setq gnus-current-headers header)
11663               (push (mail-header-number header) gnus-newsgroup-limit)))
11664           header)))))
11665
11666 (defun gnus-remove-header (number)
11667   "Remove header NUMBER from `gnus-newsgroup-headers'."
11668   (if (and gnus-newsgroup-headers
11669            (= number (mail-header-number (car gnus-newsgroup-headers))))
11670       (pop gnus-newsgroup-headers)
11671     (let ((headers gnus-newsgroup-headers))
11672       (while (and (cdr headers)
11673                   (not (= number (mail-header-number (cadr headers)))))
11674         (pop headers))
11675       (when (cdr headers)
11676         (setcdr headers (cddr headers))))))
11677
11678 ;;;
11679 ;;; summary highlights
11680 ;;;
11681
11682 (defun gnus-highlight-selected-summary ()
11683   "Highlight selected article in summary buffer."
11684   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11685   (when gnus-summary-selected-face
11686     (save-excursion
11687       (let* ((beg (point-at-bol))
11688              (end (point-at-eol))
11689              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11690              (from (if (get-text-property beg gnus-mouse-face-prop)
11691                        beg
11692                      (or (next-single-property-change
11693                           beg gnus-mouse-face-prop nil end)
11694                          beg)))
11695              (to
11696               (if (= from end)
11697                   (- from 2)
11698                 (or (next-single-property-change
11699                      from gnus-mouse-face-prop nil end)
11700                     end))))
11701         ;; If no mouse-face prop on line we will have to = from = end,
11702         ;; so we highlight the entire line instead.
11703         (when (= (+ to 2) from)
11704           (setq from beg)
11705           (setq to end))
11706         (if gnus-newsgroup-selected-overlay
11707             ;; Move old overlay.
11708             (gnus-move-overlay
11709              gnus-newsgroup-selected-overlay from to (current-buffer))
11710           ;; Create new overlay.
11711           (gnus-overlay-put
11712            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11713            'face gnus-summary-selected-face))))))
11714
11715 (defvar gnus-summary-highlight-line-cached nil)
11716 (defvar gnus-summary-highlight-line-trigger nil)
11717
11718 (defun gnus-summary-highlight-line-0 ()
11719   (if (and (eq gnus-summary-highlight-line-trigger
11720                gnus-summary-highlight)
11721            gnus-summary-highlight-line-cached)
11722       gnus-summary-highlight-line-cached
11723     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11724           gnus-summary-highlight-line-cached
11725           (let* ((cond (list 'cond))
11726                  (c cond)
11727                  (list gnus-summary-highlight))
11728             (while list
11729               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11730                               nil))
11731               (setq c (cdr c)
11732                     list (cdr list)))
11733             (gnus-byte-compile (list 'lambda nil cond))))))
11734
11735 (defun gnus-summary-highlight-line ()
11736   "Highlight current line according to `gnus-summary-highlight'."
11737   (let* ((beg (point-at-bol))
11738          (article (or (gnus-summary-article-number) gnus-current-article))
11739          (score (or (cdr (assq article
11740                                gnus-newsgroup-scored))
11741                     gnus-summary-default-score 0))
11742          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11743          (inhibit-read-only t)
11744          (default gnus-summary-default-score)
11745          (default-high gnus-summary-default-high-score)
11746          (default-low gnus-summary-default-low-score)
11747          (uncached (and gnus-summary-use-undownloaded-faces
11748                         (memq article gnus-newsgroup-undownloaded)
11749                         (not (memq article gnus-newsgroup-cached)))))
11750     (let ((face (funcall (gnus-summary-highlight-line-0))))
11751       (unless (eq face (get-text-property beg 'face))
11752         (gnus-put-text-property-excluding-characters-with-faces
11753          beg (point-at-eol) 'face
11754          (setq face (if (boundp face) (symbol-value face) face)))
11755         (when gnus-summary-highlight-line-function
11756           (funcall gnus-summary-highlight-line-function article face))))))
11757
11758 (defun gnus-update-read-articles (group unread &optional compute)
11759   "Update the list of read articles in GROUP.
11760 UNREAD is a sorted list."
11761   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11762         (info (gnus-get-info group))
11763         (prev 1)
11764         read)
11765     (if (or (not info) (not active))
11766         ;; There is no info on this group if it was, in fact,
11767         ;; killed.  Gnus stores no information on killed groups, so
11768         ;; there's nothing to be done.
11769         ;; One could store the information somewhere temporarily,
11770         ;; perhaps...  Hmmm...
11771         ()
11772       ;; Remove any negative articles numbers.
11773       (while (and unread (< (car unread) 0))
11774         (setq unread (cdr unread)))
11775       ;; Remove any expired article numbers
11776       (while (and unread (< (car unread) (car active)))
11777         (setq unread (cdr unread)))
11778       ;; Compute the ranges of read articles by looking at the list of
11779       ;; unread articles.
11780       (while unread
11781         (when (/= (car unread) prev)
11782           (push (if (= prev (1- (car unread))) prev
11783                   (cons prev (1- (car unread))))
11784                 read))
11785         (setq prev (1+ (car unread)))
11786         (setq unread (cdr unread)))
11787       (when (<= prev (cdr active))
11788         (push (cons prev (cdr active)) read))
11789       (setq read (if (> (length read) 1) (nreverse read) read))
11790       (if compute
11791           read
11792         (save-excursion
11793           (let (setmarkundo)
11794             ;; Propagate the read marks to the backend.
11795             (when (gnus-check-backend-function 'request-set-mark group)
11796               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11797                     (add (gnus-remove-from-range read (gnus-info-read info))))
11798                 (when (or add del)
11799                   (unless (gnus-check-group group)
11800                     (error "Can't open server for %s" group))
11801                   (gnus-request-set-mark
11802                    group (delq nil (list (if add (list add 'add '(read)))
11803                                          (if del (list del 'del '(read))))))
11804                   (setq setmarkundo
11805                         `(gnus-request-set-mark
11806                           ,group
11807                           ',(delq nil (list
11808                                        (if del (list del 'add '(read)))
11809                                        (if add (list add 'del '(read))))))))))
11810             (set-buffer gnus-group-buffer)
11811             (gnus-undo-register
11812               `(progn
11813                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11814                  (gnus-info-set-read ',info ',(gnus-info-read info))
11815                  (gnus-get-unread-articles-in-group ',info
11816                                                     (gnus-active ,group))
11817                  (gnus-group-update-group ,group t)
11818                  ,setmarkundo))))
11819         ;; Enter this list into the group info.
11820         (gnus-info-set-read info read)
11821         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11822         (gnus-get-unread-articles-in-group info (gnus-active group))
11823         t))))
11824
11825 (defun gnus-offer-save-summaries ()
11826   "Offer to save all active summary buffers."
11827   (let (buffers)
11828     ;; Go through all buffers and find all summaries.
11829     (dolist (buffer (buffer-list))
11830       (when (and (setq buffer (buffer-name buffer))
11831                  (string-match "Summary" buffer)
11832                  (with-current-buffer buffer
11833                    ;; We check that this is, indeed, a summary buffer.
11834                    (and (eq major-mode 'gnus-summary-mode)
11835                         ;; Also make sure this isn't bogus.
11836                         gnus-newsgroup-prepared
11837                         ;; Also make sure that this isn't a
11838                         ;; dead summary buffer.
11839                         (not gnus-dead-summary-mode))))
11840         (push buffer buffers)))
11841     ;; Go through all these summary buffers and offer to save them.
11842     (when buffers
11843       (save-excursion
11844         (map-y-or-n-p
11845          "Update summary buffer %s? "
11846          (lambda (buf)
11847            (switch-to-buffer buf)
11848            (gnus-summary-exit))
11849          buffers)))))
11850
11851
11852 ;;; @ for mime-partial
11853 ;;;
11854
11855 (defun gnus-request-partial-message ()
11856   (save-excursion
11857     (let ((number (gnus-summary-article-number))
11858           (group gnus-newsgroup-name)
11859           (mother gnus-article-buffer))
11860       (set-buffer (get-buffer-create " *Partial Article*"))
11861       (erase-buffer)
11862       (setq mime-preview-buffer mother)
11863       (gnus-request-article-this-buffer number group)
11864       (mime-parse-buffer)
11865       )))
11866
11867 (autoload 'mime-combine-message/partial-pieces-automatically
11868   "mime-partial"
11869   "Internal method to combine message/partial messages automatically.")
11870
11871 (mime-add-condition
11872  'action '((type . message)(subtype . partial)
11873            (major-mode . gnus-original-article-mode)
11874            (method . mime-combine-message/partial-pieces-automatically)
11875            (summary-buffer-exp . gnus-summary-buffer)
11876            (request-partial-message-method . gnus-request-partial-message)
11877            ))
11878
11879
11880 ;;; @ for message/rfc822
11881 ;;;
11882
11883 (defun gnus-mime-extract-message/rfc822 (entity situation)
11884   "Burst a forwarded article."
11885   (save-excursion
11886     (set-buffer gnus-summary-buffer)
11887     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11888                                    gnus-newsgroup-name 'gnus-group-history))
11889            (gnus-group-marked (list group))
11890            article info)
11891       (with-temp-buffer
11892         (mime-insert-entity-content entity)
11893         (setq article (gnus-request-accept-article group)))
11894       (when (and (consp article)
11895                  (numberp (setq article (cdr article))))
11896         (setq info (gnus-get-info group))
11897         (gnus-info-set-read info
11898                             (gnus-remove-from-range (gnus-info-read info)
11899                                                     (list article)))
11900         (when (string-equal group gnus-newsgroup-name)
11901           (forward-line 1)
11902           (let (gnus-show-threads)
11903             (gnus-summary-goto-subject article t))
11904           (gnus-summary-clear-mark-forward 1))
11905         (set-buffer gnus-group-buffer)
11906         (gnus-group-get-new-news-this-group nil t)))))
11907
11908 (mime-add-condition
11909  'action '((type . message)(subtype . rfc822)
11910            (major-mode . gnus-original-article-mode)
11911            (method . gnus-mime-extract-message/rfc822)
11912            (mode . "extract")
11913            ))
11914
11915 (mime-add-condition
11916  'action '((type . message)(subtype . news)
11917            (major-mode . gnus-original-article-mode)
11918            (method . gnus-mime-extract-message/rfc822)
11919            (mode . "extract")
11920            ))
11921
11922 (defun gnus-mime-extract-multipart (entity situation)
11923   (let ((children (mime-entity-children entity))
11924         mime-acting-situation-to-override
11925         f)
11926     (while children
11927       (mime-play-entity (car children)
11928                         (cons (assq 'mode situation)
11929                               mime-acting-situation-to-override))
11930       (setq children (cdr children)))
11931     (if (setq f (cdr (assq 'after-method
11932                            mime-acting-situation-to-override)))
11933         (eval f)
11934       )))
11935
11936 (mime-add-condition
11937  'action '((type . multipart)
11938            (method . gnus-mime-extract-multipart)
11939            (mode . "extract")
11940            )
11941  'with-default)
11942
11943
11944 ;;; @ end
11945 ;;;
11946
11947 (defun gnus-summary-inherit-default-charset ()
11948   "Import `default-mime-charset' from summary buffer.
11949 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11950 of FLIM is used."
11951   (if (buffer-live-p gnus-summary-buffer)
11952       (let (d-m-c d-m-c-u)
11953         (with-current-buffer gnus-summary-buffer
11954           (setq d-m-c (if (local-variable-p 'default-mime-charset
11955                                             gnus-summary-buffer)
11956                           default-mime-charset
11957                         t)
11958                 ;; LIMIT
11959                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11960                                               gnus-summary-buffer)
11961                             (symbol-value 'default-mime-charset-unlimited)
11962                           t)))
11963         (if (eq t d-m-c)
11964             (kill-local-variable 'default-mime-charset)
11965           (set (make-local-variable 'default-mime-charset) d-m-c))
11966         (if (eq t d-m-c-u)
11967             (kill-local-variable 'default-mime-charset-unlimited)
11968           (set (make-local-variable 'default-mime-charset-unlimited)
11969                d-m-c-u)))))
11970
11971 (defun gnus-summary-setup-default-charset ()
11972   "Setup newsgroup default charset."
11973   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11974       (progn
11975         (setq gnus-newsgroup-charset nil)
11976         (set (make-local-variable 'default-mime-charset) nil)
11977         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11978           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11979     (let ((ignored-charsets
11980            (or gnus-newsgroup-ephemeral-ignored-charsets
11981                (append
11982                 (and gnus-newsgroup-name
11983                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11984                 gnus-newsgroup-ignored-charsets)))
11985           charset)
11986       (setq gnus-newsgroup-charset
11987             (or gnus-newsgroup-ephemeral-charset
11988                 (when (and gnus-newsgroup-name
11989                            (setq charset (gnus-parameter-charset
11990                                           gnus-newsgroup-name)))
11991                   (make-local-variable 'default-mime-charset)
11992                   (setq default-mime-charset charset))
11993                 gnus-default-charset))
11994       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11995            ignored-charsets))))
11996
11997 ;;;
11998 ;;; Mime Commands
11999 ;;;
12000
12001 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12002   "Display the current article buffer fully MIME-buttonized.
12003 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12004 treated as multipart/mixed."
12005   (interactive "P")
12006   (require 'gnus-art)
12007   (let ((gnus-unbuttonized-mime-types nil)
12008         (gnus-mime-display-multipart-as-mixed show-all-parts))
12009     (gnus-summary-show-article)))
12010
12011 (defun gnus-summary-repair-multipart (article)
12012   "Add a Content-Type header to a multipart article without one."
12013   (interactive (list (gnus-summary-article-number)))
12014   (gnus-with-article article
12015     (message-narrow-to-head)
12016     (message-remove-header "Mime-Version")
12017     (goto-char (point-max))
12018     (insert "Mime-Version: 1.0\n")
12019     (widen)
12020     (when (search-forward "\n--" nil t)
12021       (let ((separator (buffer-substring (point) (point-at-eol))))
12022         (message-narrow-to-head)
12023         (message-remove-header "Content-Type")
12024         (goto-char (point-max))
12025         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12026                         separator))
12027         (widen))))
12028   (let (gnus-mark-article-hook)
12029     (gnus-summary-select-article t t nil article)))
12030
12031 (defun gnus-summary-toggle-display-buttonized ()
12032   "Toggle the buttonizing of the article buffer."
12033   (interactive)
12034   (require 'gnus-art)
12035   (if (setq gnus-inhibit-mime-unbuttonizing
12036             (not gnus-inhibit-mime-unbuttonizing))
12037       (let ((gnus-unbuttonized-mime-types nil))
12038         (gnus-summary-show-article))
12039     (gnus-summary-show-article)))
12040
12041 ;;;
12042 ;;; Intelli-mouse commmands
12043 ;;;
12044
12045 (defun gnus-wheel-summary-scroll (event)
12046   (interactive "e")
12047   (let ((amount (if (memq 'shift (event-modifiers event))
12048                     (car gnus-wheel-scroll-amount)
12049                   (cdr gnus-wheel-scroll-amount)))
12050         (direction (- (* (static-if (featurep 'xemacs)
12051                              (event-button event)
12052                            (cond ((eq 'mouse-4 (event-basic-type event))
12053                                   4)
12054                                  ((eq 'mouse-5 (event-basic-type event))
12055                                   5)))
12056                          2) 9))
12057         edge)
12058     (gnus-summary-scroll-up (* amount direction))
12059     (when (gnus-eval-in-buffer-window gnus-article-buffer
12060             (save-restriction
12061               (widen)
12062               (and (if (< 0 direction)
12063                        (gnus-article-next-page 0)
12064                      (gnus-article-prev-page 0)
12065                      (bobp))
12066                    (if (setq edge (get-text-property
12067                                    (point-min) 'gnus-wheel-edge))
12068                        (setq edge (* edge direction))
12069                      (setq edge -1))
12070                    (or (plusp edge)
12071                        (let ((buffer-read-only nil)
12072                              (inhibit-read-only t))
12073                          (put-text-property (point-min) (point-max)
12074                                             'gnus-wheel-edge direction)
12075                          nil))
12076                    (or (> edge gnus-wheel-edge-resistance)
12077                        (let ((buffer-read-only nil)
12078                              (inhibit-read-only t))
12079                          (put-text-property (point-min) (point-max)
12080                                             'gnus-wheel-edge
12081                                             (* (1+ edge) direction))
12082                          nil))
12083                    (eq last-command 'gnus-wheel-summary-scroll))))
12084       (gnus-summary-next-article nil nil (minusp direction)))))
12085
12086 (defun gnus-wheel-install ()
12087   "Enable mouse wheel support on summary window."
12088   (when gnus-use-wheel
12089     (let ((keys
12090            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
12091       (dolist (key keys)
12092         (define-key gnus-summary-mode-map key
12093           'gnus-wheel-summary-scroll)))))
12094
12095 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
12096
12097 ;;;
12098 ;;; Traditional PGP commmands
12099 ;;;
12100
12101 (defun gnus-summary-decrypt-article (&optional force)
12102   "Decrypt the current article in traditional PGP way.
12103 This will have permanent effect only in mail groups.
12104 If FORCE is non-nil, allow editing of articles even in read-only
12105 groups."
12106   (interactive "P")
12107   (gnus-summary-select-article t)
12108   (gnus-eval-in-buffer-window gnus-article-buffer
12109     (save-excursion
12110       (save-restriction
12111         (widen)
12112         (goto-char (point-min))
12113         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
12114           (error "Not a traditional PGP message!"))
12115         (let ((armor-start (match-beginning 0)))
12116           (if (and (pgg-decrypt-region armor-start (point-max))
12117                    (or force (not (gnus-group-read-only-p))))
12118               (let ((inhibit-read-only t)
12119                     buffer-read-only)
12120                 (delete-region armor-start
12121                                (progn
12122                                  (re-search-forward "^-+END PGP" nil t)
12123                                  (beginning-of-line 2)
12124                                  (point)))
12125                 (insert-buffer-substring pgg-output-buffer))))))))
12126
12127 (defun gnus-summary-verify-article ()
12128   "Verify the current article in traditional PGP way."
12129   (interactive)
12130   (save-excursion
12131     (set-buffer gnus-original-article-buffer)
12132     (goto-char (point-min))
12133     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
12134       (error "Not a traditional PGP message!"))
12135     (re-search-forward "^-+END PGP" nil t)
12136     (beginning-of-line 2)
12137     (call-interactively (function pgg-verify-region))))
12138
12139 ;;;
12140 ;;; Generic summary marking commands
12141 ;;;
12142
12143 (defvar gnus-summary-marking-alist
12144   '((read gnus-del-mark "d")
12145     (unread gnus-unread-mark "u")
12146     (ticked gnus-ticked-mark "!")
12147     (dormant gnus-dormant-mark "?")
12148     (expirable gnus-expirable-mark "e"))
12149   "An alist of names/marks/keystrokes.")
12150
12151 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12152 (defvar gnus-summary-mark-map)
12153
12154 (defun gnus-summary-make-all-marking-commands ()
12155   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12156   (dolist (elem gnus-summary-marking-alist)
12157     (apply 'gnus-summary-make-marking-command elem)))
12158
12159 (defun gnus-summary-make-marking-command (name mark keystroke)
12160   (let ((map (make-sparse-keymap)))
12161     (define-key gnus-summary-generic-mark-map keystroke map)
12162     (dolist (lway `((next "next" next nil "n")
12163                     (next-unread "next unread" next t "N")
12164                     (prev "previous" prev nil "p")
12165                     (prev-unread "previous unread" prev t "P")
12166                     (nomove "" nil nil ,keystroke)))
12167       (let ((func (gnus-summary-make-marking-command-1
12168                    mark (car lway) lway name)))
12169         (setq func (eval func))
12170         (define-key map (nth 4 lway) func)))))
12171
12172 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12173   `(defun ,(intern
12174             (format "gnus-summary-put-mark-as-%s%s"
12175                     name (if (eq way 'nomove)
12176                              ""
12177                            (concat "-" (symbol-name way)))))
12178      (n)
12179      ,(format
12180        "Mark the current article as %s%s.
12181 If N, the prefix, then repeat N times.
12182 If N is negative, move in reverse order.
12183 The difference between N and the actual number of articles marked is
12184 returned."
12185        name (car (cdr lway)))
12186      (interactive "p")
12187      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12188
12189 (defun gnus-summary-generic-mark (n mark move unread)
12190   "Mark N articles with MARK."
12191   (unless (eq major-mode 'gnus-summary-mode)
12192     (error "This command can only be used in the summary buffer"))
12193   (gnus-summary-show-thread)
12194   (let ((nummove
12195          (cond
12196           ((eq move 'next) 1)
12197           ((eq move 'prev) -1)
12198           (t 0))))
12199     (if (zerop nummove)
12200         (setq n 1)
12201       (when (< n 0)
12202         (setq n (abs n)
12203               nummove (* -1 nummove))))
12204     (while (and (> n 0)
12205                 (gnus-summary-mark-article nil mark)
12206                 (zerop (gnus-summary-next-subject nummove unread t)))
12207       (setq n (1- n)))
12208     (when (/= 0 n)
12209       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12210     (gnus-summary-recenter)
12211     (gnus-summary-position-point)
12212     (gnus-set-mode-line 'summary)
12213     n))
12214
12215 (defun gnus-summary-insert-articles (articles)
12216   (when (setq articles
12217               (gnus-sorted-difference articles
12218                                       (mapcar (lambda (h)
12219                                                 (mail-header-number h))
12220                                               gnus-newsgroup-headers)))
12221     (setq gnus-newsgroup-headers
12222           (gnus-merge 'list
12223                       gnus-newsgroup-headers
12224                       (gnus-fetch-headers articles)
12225                       'gnus-article-sort-by-number))
12226     ;; Suppress duplicates?
12227     (when gnus-suppress-duplicates
12228       (gnus-dup-suppress-articles))
12229
12230     ;; We might want to build some more threads first.
12231     (when (and gnus-fetch-old-headers
12232                (eq gnus-headers-retrieved-by 'nov))
12233       (if (eq gnus-fetch-old-headers 'invisible)
12234           (gnus-build-all-threads)
12235         (gnus-build-old-threads)))
12236     ;; Let the Gnus agent mark articles as read.
12237     (when gnus-agent
12238       (gnus-agent-get-undownloaded-list))
12239     ;; Remove list identifiers from subject
12240     (when gnus-list-identifiers
12241       (gnus-summary-remove-list-identifiers))
12242     ;; First and last article in this newsgroup.
12243     (when gnus-newsgroup-headers
12244       (setq gnus-newsgroup-begin
12245             (mail-header-number (car gnus-newsgroup-headers))
12246             gnus-newsgroup-end
12247             (mail-header-number
12248              (gnus-last-element gnus-newsgroup-headers))))
12249     (when gnus-use-scoring
12250       (gnus-possibly-score-headers))))
12251
12252 (defun gnus-summary-insert-old-articles (&optional all)
12253   "Insert all old articles in this group.
12254 If ALL is non-nil, already read articles become readable.
12255 If ALL is a number, fetch this number of articles."
12256   (interactive "P")
12257   (prog1
12258       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12259             older len)
12260         (setq older
12261               ;; Some nntp servers lie about their active range.  When
12262               ;; this happens, the active range can be in the millions.
12263               ;; Use a compressed range to avoid creating a huge list.
12264               (gnus-range-difference (list gnus-newsgroup-active) old))
12265         (setq len (gnus-range-length older))
12266         (cond
12267          ((null older) nil)
12268          ((numberp all)
12269           (if (< all len)
12270               (let ((older-range (nreverse older)))
12271                 (setq older nil)
12272
12273                 (while (> all 0)
12274                   (let* ((r (pop older-range))
12275                          (min (if (numberp r) r (car r)))
12276                          (max (if (numberp r) r (cdr r))))
12277                     (while (and (<= min max)
12278                                 (> all 0))
12279                       (push max older)
12280                       (setq all (1- all)
12281                             max (1- max))))))
12282             (setq older (gnus-uncompress-range older))))
12283          (all
12284           (setq older (gnus-uncompress-range older)))
12285          (t
12286           (when (and (numberp gnus-large-newsgroup)
12287                    (> len gnus-large-newsgroup))
12288               (let* ((cursor-in-echo-area nil)
12289                      (initial (gnus-parameter-large-newsgroup-initial
12290                                gnus-newsgroup-name))
12291                      (input
12292                       (read-string
12293                        (format
12294                         "How many articles from %s (%s %d): "
12295                         (gnus-limit-string
12296                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12297                         (if initial "max" "default")
12298                         len)
12299                        (if initial
12300                            (cons (number-to-string initial)
12301                                  0)))))
12302                 (unless (string-match "^[ \t]*$" input)
12303                   (setq all (string-to-number input))
12304                   (if (< all len)
12305                       (let ((older-range (nreverse older)))
12306                         (setq older nil)
12307
12308                         (while (> all 0)
12309                           (let* ((r (pop older-range))
12310                                  (min (if (numberp r) r (car r)))
12311                                  (max (if (numberp r) r (cdr r))))
12312                             (while (and (<= min max)
12313                                         (> all 0))
12314                               (push max older)
12315                               (setq all (1- all)
12316                                     max (1- max))))))))))
12317           (setq older (gnus-uncompress-range older))))
12318         (if (not older)
12319             (message "No old news.")
12320           (gnus-summary-insert-articles older)
12321           (gnus-summary-limit (gnus-sorted-nunion old older))))
12322     (gnus-summary-position-point)))
12323
12324 (defun gnus-summary-insert-new-articles ()
12325   "Insert all new articles in this group."
12326   (interactive)
12327   (prog1
12328       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12329             (old-active gnus-newsgroup-active)
12330             (nnmail-fetched-sources (list t))
12331             i new)
12332         (setq gnus-newsgroup-active
12333               (gnus-activate-group gnus-newsgroup-name 'scan))
12334         (setq i (cdr gnus-newsgroup-active))
12335         (while (> i (cdr old-active))
12336           (push i new)
12337           (decf i))
12338         (if (not new)
12339             (message "No gnus is bad news")
12340           (gnus-summary-insert-articles new)
12341           (setq gnus-newsgroup-unreads
12342                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12343           (gnus-summary-limit (gnus-sorted-nunion old new))))
12344     (gnus-summary-position-point)))
12345
12346 (gnus-summary-make-all-marking-commands)
12347
12348 (gnus-ems-redefine)
12349
12350 (provide 'gnus-sum)
12351
12352 (run-hooks 'gnus-sum-load-hook)
12353
12354 ;; Local Variables:
12355 ;; coding: iso-8859-1
12356 ;; End:
12357
12358 ;;; gnus-sum.el ends here