Synch to No Gnus 200501070617.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (defvar tool-bar-map))
34
35 (require 'gnus)
36 (require 'gnus-group)
37 (require 'gnus-spec)
38 (require 'gnus-range)
39 (require 'gnus-int)
40 (require 'gnus-undo)
41 (require 'gnus-util)
42 (require 'nnoo)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
62 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
63 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
64
65 (defcustom gnus-kill-summary-on-exit t
66   "*If non-nil, kill the summary buffer when you exit from it.
67 If nil, the summary will become a \"*Dead Summary*\" buffer, and
68 it will be killed sometime later."
69   :group 'gnus-summary-exit
70   :type 'boolean)
71
72 (defcustom gnus-fetch-old-headers nil
73   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
74 If an unread article in the group refers to an older, already read (or
75 just marked as read) article, the old article will not normally be
76 displayed in the Summary buffer.  If this variable is t, Gnus
77 will attempt to grab the headers to the old articles, and thereby
78 build complete threads.  If it has the value `some', only enough
79 headers to connect otherwise loose threads will be displayed.  This
80 variable can also be a number.  In that case, no more than that number
81 of old headers will be fetched.  If it has the value `invisible', all
82 old headers will be fetched, but none will be displayed.
83
84 The server has to support NOV for any of this to work."
85   :group 'gnus-thread
86   :type '(choice (const :tag "off" nil)
87                  (const :tag "on" t)
88                  (const some)
89                  (const invisible)
90                  number
91                  (sexp :menu-tag "other" t)))
92
93 (defcustom gnus-refer-thread-limit 200
94   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
95 If t, fetch all the available old headers."
96   :group 'gnus-thread
97   :type '(choice number
98                  (sexp :menu-tag "other" t)))
99
100 (defcustom gnus-summary-make-false-root 'adopt
101   "*nil means that Gnus won't gather loose threads.
102 If the root of a thread has expired or been read in a previous
103 session, the information necessary to build a complete thread has been
104 lost.  Instead of having many small sub-threads from this original thread
105 scattered all over the summary buffer, Gnus can gather them.
106
107 If non-nil, Gnus will try to gather all loose sub-threads from an
108 original thread into one large thread.
109
110 If this variable is non-nil, it should be one of `none', `adopt',
111 `dummy' or `empty'.
112
113 If this variable is `none', Gnus will not make a false root, but just
114 present the sub-threads after another.
115 If this variable is `dummy', Gnus will create a dummy root that will
116 have all the sub-threads as children.
117 If this variable is `adopt', Gnus will make one of the \"children\"
118 the parent and mark all the step-children as such.
119 If this variable is `empty', the \"children\" are printed with empty
120 subject fields.  (Or rather, they will be printed with a string
121 given by the `gnus-summary-same-subject' variable.)"
122   :group 'gnus-thread
123   :type '(choice (const :tag "off" nil)
124                  (const none)
125                  (const dummy)
126                  (const adopt)
127                  (const empty)))
128
129 (defcustom gnus-summary-make-false-root-always nil
130   "Always make a false dummy root."
131   :version "21.4"
132   :group 'gnus-thread
133   :type 'boolean)
134
135 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
136   "*A regexp to match subjects to be excluded from loose thread gathering.
137 As loose thread gathering is done on subjects only, that means that
138 there can be many false gatherings performed.  By rooting out certain
139 common subjects, gathering might become saner."
140   :group 'gnus-thread
141   :type 'regexp)
142
143 (defcustom gnus-summary-gather-subject-limit nil
144   "*Maximum length of subject comparisons when gathering loose threads.
145 Use nil to compare full subjects.  Setting this variable to a low
146 number will help gather threads that have been corrupted by
147 newsreaders chopping off subject lines, but it might also mean that
148 unrelated articles that have subject that happen to begin with the
149 same few characters will be incorrectly gathered.
150
151 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
152 comparing subjects."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const fuzzy)
156                  (sexp :menu-tag "on" t)))
157
158 (defcustom gnus-simplify-subject-functions nil
159   "List of functions taking a string argument that simplify subjects.
160 The functions are applied recursively.
161
162 Useful functions to put in this list include:
163 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
164 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
165   :group 'gnus-thread
166   :type '(repeat function))
167
168 (defcustom gnus-simplify-ignored-prefixes nil
169   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  regexp))
173
174 (defcustom gnus-build-sparse-threads nil
175   "*If non-nil, fill in the gaps in threads.
176 If `some', only fill in the gaps that are needed to tie loose threads
177 together.  If `more', fill in all leaf nodes that Gnus can find.  If
178 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
179   :group 'gnus-thread
180   :type '(choice (const :tag "off" nil)
181                  (const some)
182                  (const more)
183                  (sexp :menu-tag "all" t)))
184
185 (defcustom gnus-summary-thread-gathering-function
186   'gnus-gather-threads-by-subject
187   "*Function used for gathering loose threads.
188 There are two pre-defined functions: `gnus-gather-threads-by-subject',
189 which only takes Subjects into consideration; and
190 `gnus-gather-threads-by-references', which compared the References
191 headers of the articles to find matches."
192   :group 'gnus-thread
193   :type '(radio (function-item gnus-gather-threads-by-subject)
194                 (function-item gnus-gather-threads-by-references)
195                 (function :tag "other")))
196
197 (defcustom gnus-summary-same-subject ""
198   "*String indicating that the current article has the same subject as the previous.
199 This variable will only be used if the value of
200 `gnus-summary-make-false-root' is `empty'."
201   :group 'gnus-summary-format
202   :type 'string)
203
204 (defcustom gnus-summary-goto-unread t
205   "*If t, many commands will go to the next unread article.
206 This applies to marking commands as well as other commands that
207 \"naturally\" select the next article, like, for instance, `SPC' at
208 the end of an article.
209
210 If nil, the marking commands do NOT go to the next unread article
211 \(they go to the next article instead).  If `never', commands that
212 usually go to the next unread article, will go to the next article,
213 whether it is read or not."
214   :group 'gnus-summary-marks
215   :link '(custom-manual "(gnus)Setting Marks")
216   :type '(choice (const :tag "off" nil)
217                  (const never)
218                  (sexp :menu-tag "on" t)))
219
220 (defcustom gnus-summary-default-score 0
221   "*Default article score level.
222 All scores generated by the score files will be added to this score.
223 If this variable is nil, scoring will be disabled."
224   :group 'gnus-score-default
225   :type '(choice (const :tag "disable")
226                  integer))
227
228 (defcustom gnus-summary-default-high-score 0
229   "*Default threshold for a high scored article.
230 An article will be highlighted as high scored if its score is greater
231 than this score."
232   :version "21.4"
233   :group 'gnus-score-default
234   :type 'integer)
235
236 (defcustom gnus-summary-default-low-score 0
237   "*Default threshold for a low scored article.
238 An article will be highlighted as low scored if its score is smaller
239 than this score."
240   :version "21.4"
241   :group 'gnus-score-default
242   :type 'integer)
243
244 (defcustom gnus-summary-zcore-fuzz 0
245   "*Fuzziness factor for the zcore in the summary buffer.
246 Articles with scores closer than this to `gnus-summary-default-score'
247 will not be marked."
248   :group 'gnus-summary-format
249   :type 'integer)
250
251 (defcustom gnus-simplify-subject-fuzzy-regexp nil
252   "*Strings to be removed when doing fuzzy matches.
253 This can either be a regular expression or list of regular expressions
254 that will be removed from subject strings if fuzzy subject
255 simplification is selected."
256   :group 'gnus-thread
257   :type '(repeat regexp))
258
259 (defcustom gnus-show-threads t
260   "*If non-nil, display threads in summary mode."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-hide-subtree nil
265   "*If non-nil, hide all threads initially.
266 This can be a predicate specifier which says which threads to hide.
267 If threads are hidden, you have to run the command
268 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
269 to expose hidden threads."
270   :group 'gnus-thread
271   :type '(radio (sexp :format "Non-nil\n"
272                       :match (lambda (widget value)
273                                (not (or (consp value) (functionp value))))
274                       :value t)
275                 (const nil)
276                 (sexp :tag "Predicate specifier")))
277
278 (defcustom gnus-thread-hide-killed t
279   "*If non-nil, hide killed threads automatically."
280   :group 'gnus-thread
281   :type 'boolean)
282
283 (defcustom gnus-thread-ignore-subject t
284   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
285 If nil, articles that have different subjects from their parents will
286 start separate threads."
287   :group 'gnus-thread
288   :type 'boolean)
289
290 (defcustom gnus-thread-operation-ignore-subject t
291   "*If non-nil, subjects will be ignored when doing thread commands.
292 This affects commands like `gnus-summary-kill-thread' and
293 `gnus-summary-lower-thread'.
294
295 If this variable is nil, articles in the same thread with different
296 subjects will not be included in the operation in question.  If this
297 variable is `fuzzy', only articles that have subjects that are fuzzily
298 equal will be included."
299   :group 'gnus-thread
300   :type '(choice (const :tag "off" nil)
301                  (const fuzzy)
302                  (sexp :tag "on" t)))
303
304 (defcustom gnus-thread-indent-level 4
305   "*Number that says how much each sub-thread should be indented."
306   :group 'gnus-thread
307   :type 'integer)
308
309 (defcustom gnus-auto-extend-newsgroup t
310   "*If non-nil, extend newsgroup forward and backward when requested."
311   :group 'gnus-summary-choose
312   :type 'boolean)
313
314 (defcustom gnus-auto-select-first t
315   "*If non-nil, select the article under point.
316 Which article this is is controlled by the `gnus-auto-select-subject'
317 variable.
318
319 If you want to prevent automatic selection of articles in some
320 newsgroups, set the variable to nil in `gnus-select-group-hook'."
321   :group 'gnus-group-select
322   :type '(choice (const :tag "none" nil)
323                  (sexp :menu-tag "first" t)))
324
325 (defcustom gnus-auto-select-subject 'unread
326   "*Says what subject to place under point when entering a group.
327
328 This variable can either be the symbols `first' (place point on the
329 first subject), `unread' (place point on the subject line of the first
330 unread article), `best' (place point on the subject line of the
331 higest-scored article), `unseen' (place point on the subject line of
332 the first unseen article), 'unseen-or-unread' (place point on the subject
333 line of the first unseen article or, if all article have been seen, on the
334 subject line of the first unread article), or a function to be called to
335 place point on some subject line."
336   :version "21.4"
337   :group 'gnus-group-select
338   :type '(choice (const best)
339                  (const unread)
340                  (const first)
341                  (const unseen)
342                  (const unseen-or-unread)))
343
344 (defcustom gnus-dont-select-after-jump-to-other-group nil
345   "If non-nil, don't select the first unread article after entering the
346 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
347 it is depend on the value of `gnus-auto-select-first' whether to select
348 or not."
349   :group 'gnus-group-select
350   :type 'boolean)
351
352 (defcustom gnus-auto-select-next t
353   "*If non-nil, offer to go to the next group from the end of the previous.
354 If the value is t and the next newsgroup is empty, Gnus will exit
355 summary mode and go back to group mode.  If the value is neither nil
356 nor t, Gnus will select the following unread newsgroup.  In
357 particular, if the value is the symbol `quietly', the next unread
358 newsgroup will be selected without any confirmation, and if it is
359 `almost-quietly', the next group will be selected without any
360 confirmation if you are located on the last article in the group.
361 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
362 will go to the next group without confirmation."
363   :group 'gnus-summary-maneuvering
364   :type '(choice (const :tag "off" nil)
365                  (const quietly)
366                  (const almost-quietly)
367                  (const slightly-quietly)
368                  (sexp :menu-tag "on" t)))
369
370 (defcustom gnus-auto-select-same nil
371   "*If non-nil, select the next article with the same subject.
372 If there are no more articles with the same subject, go to
373 the first unread article."
374   :group 'gnus-summary-maneuvering
375   :type 'boolean)
376
377 (defcustom gnus-auto-goto-ignores 'unfetched
378   "*Says how to handle unfetched articles when maneuvering.
379
380 This variable can either be the symbols nil (maneuver to any
381 article), `undownloaded' (maneuvering while unplugged ignores articles
382 that have not been fetched), `always-undownloaded' (maneuvering always
383 ignores articles that have not been fetched), `unfetched' (maneuvering
384 ignores articles whose headers have not been fetched).
385
386 NOTE: The list of unfetched articles will always be nil when plugged
387 and, when unplugged, a subset of the undownloaded article list."
388   :version "21.4"
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "None" nil)
391                  (const :tag "Undownloaded when unplugged" undownloaded)
392                  (const :tag "Undownloaded" always-undownloaded)
393                  (const :tag "Unfetched" unfetched)))
394
395 (defcustom gnus-summary-check-current nil
396   "*If non-nil, consider the current article when moving.
397 The \"unread\" movement commands will stay on the same line if the
398 current article is unread."
399   :group 'gnus-summary-maneuvering
400   :type 'boolean)
401
402 (defcustom gnus-auto-center-summary 2
403   "*If non-nil, always center the current summary buffer.
404 In particular, if `vertical' do only vertical recentering.  If non-nil
405 and non-`vertical', do both horizontal and vertical recentering."
406   :group 'gnus-summary-maneuvering
407   :type '(choice (const :tag "none" nil)
408                  (const vertical)
409                  (integer :tag "height")
410                  (sexp :menu-tag "both" t)))
411
412 (defvar gnus-auto-center-group t
413   "*If non-nil, always center the group buffer.")
414
415 (defcustom gnus-show-all-headers nil
416   "*If non-nil, don't hide any headers."
417   :group 'gnus-article-hiding
418   :group 'gnus-article-headers
419   :type 'boolean)
420
421 (defcustom gnus-summary-ignore-duplicates nil
422   "*If non-nil, ignore articles with identical Message-ID headers."
423   :group 'gnus-summary
424   :type 'boolean)
425
426 (defcustom gnus-single-article-buffer t
427   "*If non-nil, display all articles in the same buffer.
428 If nil, each group will get its own article buffer."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-break-pages t
433   "*If non-nil, do page breaking on articles.
434 The page delimiter is specified by the `gnus-page-delimiter'
435 variable."
436   :group 'gnus-article-various
437   :type 'boolean)
438
439 (defcustom gnus-show-mime t
440   "*If non-nil, do mime processing of articles.
441 The articles will simply be fed to the function given by
442 `gnus-article-display-method-for-mime'."
443   :group 'gnus-article-mime
444   :type 'boolean)
445
446 (defcustom gnus-move-split-methods nil
447   "*Variable used to suggest where articles are to be moved to.
448 It uses the same syntax as the `gnus-split-methods' variable.
449 However, whereas `gnus-split-methods' specifies file names as targets,
450 this variable specifies group names."
451   :group 'gnus-summary-mail
452   :type '(repeat (choice (list :value (fun) function)
453                          (cons :value ("" "") regexp (repeat string))
454                          (sexp :value nil))))
455
456 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
457   "Function used to compute default prefix for article move/copy/etc prompts.
458 The function should take one argument, a group name, and return a
459 string with the suggested prefix."
460   :group 'gnus-summary-mail
461   :type 'function)
462
463 ;; FIXME: Although the custom type is `character' for the following variables,
464 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
465
466 (defcustom gnus-unread-mark ?\ ;;;Whitespace
467   "*Mark used for unread articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ticked-mark ?!
472   "*Mark used for ticked articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-dormant-mark ??
477   "*Mark used for dormant articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-del-mark ?r
482   "*Mark used for del'd articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-read-mark ?R
487   "*Mark used for read articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-expirable-mark ?E
492   "*Mark used for expirable articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-killed-mark ?K
497   "*Mark used for killed articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-spam-mark ?$
502   "*Mark used for spam articles."
503   :version "21.4"
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-souped-mark ?F
508   "*Mark used for souped articles."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-kill-file-mark ?X
513   "*Mark used for articles killed by kill files."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-low-score-mark ?Y
518   "*Mark used for articles with a low score."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-catchup-mark ?C
523   "*Mark used for articles that are caught up."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-replied-mark ?A
528   "*Mark used for articles that have been replied to."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-forwarded-mark ?F
533   "*Mark used for articles that have been forwarded."
534   :version "21.4"
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-recent-mark ?N
539   "*Mark used for articles that are recent."
540   :version "21.4"
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-cached-mark ?*
545   "*Mark used for articles that are in the cache."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-saved-mark ?S
550   "*Mark used for articles that have been saved."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-unseen-mark ?.
555   "*Mark used for articles that haven't been seen."
556   :version "21.4"
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-no-mark ?\ ;;;Whitespace
561   "*Mark used for articles that have no other secondary mark."
562   :version "21.4"
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-ancient-mark ?O
567   "*Mark used for ancient articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-sparse-mark ?Q
572   "*Mark used for sparsely reffed articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-canceled-mark ?G
577   "*Mark used for canceled articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-duplicate-mark ?M
582   "*Mark used for duplicate articles."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-undownloaded-mark ?-
587   "*Mark used for articles that weren't downloaded."
588   :version "21.4"
589   :group 'gnus-summary-marks
590   :type 'character)
591
592 (defcustom gnus-downloaded-mark ?+
593   "*Mark used for articles that were downloaded."
594   :group 'gnus-summary-marks
595   :type 'character)
596
597 (defcustom gnus-downloadable-mark ?%
598   "*Mark used for articles that are to be downloaded."
599   :group 'gnus-summary-marks
600   :type 'character)
601
602 (defcustom gnus-unsendable-mark ?=
603   "*Mark used for articles that won't be sent."
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-score-over-mark ?+
608   "*Score mark used for articles with high scores."
609   :group 'gnus-summary-marks
610   :type 'character)
611
612 (defcustom gnus-score-below-mark ?-
613   "*Score mark used for articles with low scores."
614   :group 'gnus-summary-marks
615   :type 'character)
616
617 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
618   "*There is no thread under the article."
619   :group 'gnus-summary-marks
620   :type 'character)
621
622 (defcustom gnus-not-empty-thread-mark ?=
623   "*There is a thread under the article."
624   :group 'gnus-summary-marks
625   :type 'character)
626
627 (defcustom gnus-view-pseudo-asynchronously nil
628   "*If non-nil, Gnus will view pseudo-articles asynchronously."
629   :group 'gnus-extract-view
630   :type 'boolean)
631
632 (defcustom gnus-auto-expirable-marks
633   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
634         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
635         gnus-souped-mark gnus-duplicate-mark)
636   "*The list of marks converted into expiration if a group is auto-expirable."
637   :version "21.1"
638   :group 'gnus-summary
639   :type '(repeat character))
640
641 (defcustom gnus-inhibit-user-auto-expire t
642   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
643   :version "21.1"
644   :group 'gnus-summary
645   :type 'boolean)
646
647 (defcustom gnus-view-pseudos nil
648   "*If `automatic', pseudo-articles will be viewed automatically.
649 If `not-confirm', pseudos will be viewed automatically, and the user
650 will not be asked to confirm the command."
651   :group 'gnus-extract-view
652   :type '(choice (const :tag "off" nil)
653                  (const automatic)
654                  (const not-confirm)))
655
656 (defcustom gnus-view-pseudos-separately t
657   "*If non-nil, one pseudo-article will be created for each file to be viewed.
658 If nil, all files that use the same viewing command will be given as a
659 list of parameters to that command."
660   :group 'gnus-extract-view
661   :type 'boolean)
662
663 (defcustom gnus-insert-pseudo-articles t
664   "*If non-nil, insert pseudo-articles when decoding articles."
665   :group 'gnus-extract-view
666   :type 'boolean)
667
668 (defcustom gnus-summary-dummy-line-format
669   "   %(:                             :%) %S\n"
670   "*The format specification for the dummy roots in the summary buffer.
671 It works along the same lines as a normal formatting string,
672 with some simple extensions.
673
674 %S  The subject
675
676 General format specifiers can also be used.
677 See `(gnus)Formatting Variables'."
678   :link '(custom-manual "(gnus)Formatting Variables")
679   :group 'gnus-threading
680   :type 'string)
681
682 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
683   "*The format specification for the summary mode line.
684 It works along the same lines as a normal formatting string,
685 with some simple extensions:
686
687 %G  Group name
688 %p  Unprefixed group name
689 %A  Current article number
690 %z  Current article score
691 %V  Gnus version
692 %U  Number of unread articles in the group
693 %e  Number of unselected articles in the group
694 %Z  A string with unread/unselected article counts
695 %g  Shortish group name
696 %S  Subject of the current article
697 %u  User-defined spec
698 %s  Current score file name
699 %d  Number of dormant articles
700 %r  Number of articles that have been marked as read in this session
701 %E  Number of articles expunged by the score files"
702   :group 'gnus-summary-format
703   :type 'string)
704
705 (defcustom gnus-list-identifiers nil
706   "Regexp that matches list identifiers to be removed from subject.
707 This can also be a list of regexps."
708   :version "21.1"
709   :group 'gnus-summary-format
710   :group 'gnus-article-hiding
711   :type '(choice (const :tag "none" nil)
712                  (regexp :value ".*")
713                  (repeat :value (".*") regexp)))
714
715 (defcustom gnus-summary-mark-below 0
716   "*Mark all articles with a score below this variable as read.
717 This variable is local to each summary buffer and usually set by the
718 score file."
719   :group 'gnus-score-default
720   :type 'integer)
721
722 (defun gnus-widget-reversible-match (widget value)
723   "Ignoring WIDGET, convert VALUE to internal form.
724 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
725   ;; (debug value)
726   (or (symbolp value)
727       (and (listp value)
728            (eq (length value) 2)
729            (eq (nth 0 value) 'not)
730            (symbolp (nth 1 value)))))
731
732 (defun gnus-widget-reversible-to-internal (widget value)
733   "Ignoring WIDGET, convert VALUE to internal form.
734 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
735 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
736   ;; (debug value)
737   (if (atom value)
738       (list value nil)
739     (list (nth 1 value) t)))
740
741 (defun gnus-widget-reversible-to-external (widget value)
742   "Ignoring WIDGET, convert VALUE to external form.
743 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
744 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
745   ;; (debug value)
746   (if (nth 1 value)
747       (list 'not (nth 0 value))
748     (nth 0 value)))
749
750 (define-widget 'gnus-widget-reversible 'group
751   "A `group' that convert values."
752   :match 'gnus-widget-reversible-match
753   :value-to-internal 'gnus-widget-reversible-to-internal
754   :value-to-external 'gnus-widget-reversible-to-external)
755
756 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
757   "*List of functions used for sorting articles in the summary buffer.
758
759 Each function takes two articles and returns non-nil if the first
760 article should be sorted before the other.  If you use more than one
761 function, the primary sort function should be the last.  You should
762 probably always include `gnus-article-sort-by-number' in the list of
763 sorting functions -- preferably first.  Also note that sorting by date
764 is often much slower than sorting by number, and the sorting order is
765 very similar.  (Sorting by date means sorting by the time the message
766 was sent, sorting by number means sorting by arrival time.)
767
768 Each item can also be a list `(not F)' where F is a function;
769 this reverses the sort order.
770
771 Ready-made functions include `gnus-article-sort-by-number',
772 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
773 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
774 and `gnus-article-sort-by-score'.
775
776 When threading is turned on, the variable `gnus-thread-sort-functions'
777 controls how articles are sorted."
778   :group 'gnus-summary-sort
779   :type '(repeat (gnus-widget-reversible
780                   (choice (function-item gnus-article-sort-by-number)
781                           (function-item gnus-article-sort-by-author)
782                           (function-item gnus-article-sort-by-subject)
783                           (function-item gnus-article-sort-by-date)
784                           (function-item gnus-article-sort-by-score)
785                           (function-item gnus-article-sort-by-random)
786                           (function :tag "other"))
787                   (boolean :tag "Reverse order"))))
788
789
790 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
791   "*List of functions used for sorting threads in the summary buffer.
792 By default, threads are sorted by article number.
793
794 Each function takes two threads and returns non-nil if the first
795 thread should be sorted before the other.  If you use more than one
796 function, the primary sort function should be the last.  You should
797 probably always include `gnus-thread-sort-by-number' in the list of
798 sorting functions -- preferably first.  Also note that sorting by date
799 is often much slower than sorting by number, and the sorting order is
800 very similar.  (Sorting by date means sorting by the time the message
801 was sent, sorting by number means sorting by arrival time.)
802
803 Each list item can also be a list `(not F)' where F is a
804 function; this specifies reversed sort order.
805
806 Ready-made functions include `gnus-thread-sort-by-number',
807 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
808 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
809 `gnus-thread-sort-by-most-recent-number',
810 `gnus-thread-sort-by-most-recent-date',
811 `gnus-thread-sort-by-random', and
812 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
813
814 When threading is turned off, the variable
815 `gnus-article-sort-functions' controls how articles are sorted."
816   :group 'gnus-summary-sort
817   :type '(repeat 
818           (gnus-widget-reversible
819            (choice (function-item gnus-thread-sort-by-number)
820                    (function-item gnus-thread-sort-by-author)
821                    (function-item gnus-thread-sort-by-subject)
822                    (function-item gnus-thread-sort-by-date)
823                    (function-item gnus-thread-sort-by-score)
824                    (function-item gnus-thread-sort-by-most-recent-number)
825                    (function-item gnus-thread-sort-by-most-recent-date)
826                    (function-item gnus-thread-sort-by-random)
827                    (function-item gnus-thread-sort-by-total-score)
828                    (function :tag "other"))
829            (boolean :tag "Reverse order"))))
830
831 (defcustom gnus-thread-score-function '+
832   "*Function used for calculating the total score of a thread.
833
834 The function is called with the scores of the article and each
835 subthread and should then return the score of the thread.
836
837 Some functions you can use are `+', `max', or `min'."
838   :group 'gnus-summary-sort
839   :type 'function)
840
841 (defcustom gnus-summary-expunge-below nil
842   "All articles that have a score less than this variable will be expunged.
843 This variable is local to the summary buffers."
844   :group 'gnus-score-default
845   :type '(choice (const :tag "off" nil)
846                  integer))
847
848 (defcustom gnus-thread-expunge-below nil
849   "All threads that have a total score less than this variable will be expunged.
850 See `gnus-thread-score-function' for en explanation of what a
851 \"thread score\" is.
852
853 This variable is local to the summary buffers."
854   :group 'gnus-threading
855   :group 'gnus-score-default
856   :type '(choice (const :tag "off" nil)
857                  integer))
858
859 (defcustom gnus-summary-mode-hook nil
860   "*A hook for Gnus summary mode.
861 This hook is run before any variables are set in the summary buffer."
862   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
867 (when (featurep 'xemacs)
868   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
869   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
870   (add-hook 'gnus-summary-mode-hook
871             'gnus-xmas-switch-horizontal-scrollbar-off))
872
873 (defcustom gnus-summary-menu-hook nil
874   "*Hook run after the creation of the summary mode menu."
875   :group 'gnus-summary-visual
876   :type 'hook)
877
878 (defcustom gnus-summary-exit-hook nil
879   "*A hook called on exit from the summary buffer.
880 It will be called with point in the group buffer."
881   :group 'gnus-summary-exit
882   :type 'hook)
883
884 (defcustom gnus-summary-prepare-hook nil
885   "*A hook called after the summary buffer has been generated.
886 If you want to modify the summary buffer, you can use this hook."
887   :group 'gnus-summary-various
888   :type 'hook)
889
890 (defcustom gnus-summary-prepared-hook nil
891   "*A hook called as the last thing after the summary buffer has been generated."
892   :group 'gnus-summary-various
893   :type 'hook)
894
895 (defcustom gnus-summary-generate-hook nil
896   "*A hook run just before generating the summary buffer.
897 This hook is commonly used to customize threading variables and the
898 like."
899   :group 'gnus-summary-various
900   :type 'hook)
901
902 (defcustom gnus-select-group-hook nil
903   "*A hook called when a newsgroup is selected.
904
905 If you'd like to simplify subjects like the
906 `gnus-summary-next-same-subject' command does, you can use the
907 following hook:
908
909  (add-hook gnus-select-group-hook
910            (lambda ()
911              (mapcar (lambda (header)
912                        (mail-header-set-subject
913                         header
914                         (gnus-simplify-subject
915                          (mail-header-subject header) 're-only)))
916                      gnus-newsgroup-headers)))"
917   :group 'gnus-group-select
918   :type 'hook)
919
920 (defcustom gnus-select-article-hook nil
921   "*A hook called when an article is selected."
922   :group 'gnus-summary-choose
923   :options '(gnus-agent-fetch-selected-article)
924   :type 'hook)
925
926 (defcustom gnus-visual-mark-article-hook
927   (list 'gnus-highlight-selected-summary)
928   "*Hook run after selecting an article in the summary buffer.
929 It is meant to be used for highlighting the article in some way.  It
930 is not run if `gnus-visual' is nil."
931   :group 'gnus-summary-visual
932   :type 'hook)
933
934 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
935   "*A hook called before parsing the headers."
936   :group 'gnus-various
937   :type 'hook)
938
939 (defcustom gnus-exit-group-hook nil
940   "*A hook called when exiting summary mode.
941 This hook is not called from the non-updating exit commands like `Q'."
942   :group 'gnus-various
943   :type 'hook)
944
945 (defcustom gnus-summary-update-hook
946   (list 'gnus-summary-highlight-line)
947   "*A hook called when a summary line is changed.
948 The hook will not be called if `gnus-visual' is nil.
949
950 The default function `gnus-summary-highlight-line' will
951 highlight the line according to the `gnus-summary-highlight'
952 variable."
953   :group 'gnus-summary-visual
954   :type 'hook)
955
956 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
957   "*A hook called when an article is selected for the first time.
958 The hook is intended to mark an article as read (or unread)
959 automatically when it is selected."
960   :group 'gnus-summary-choose
961   :type 'hook)
962
963 (defcustom gnus-group-no-more-groups-hook nil
964   "*A hook run when returning to group mode having no more (unread) groups."
965   :group 'gnus-group-select
966   :type 'hook)
967
968 (defcustom gnus-ps-print-hook nil
969   "*A hook run before ps-printing something from Gnus."
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-article-move-hook nil
974   "*A hook called after an article is moved, copied, respooled, or crossposted."
975   :version "21.4"
976   :group 'gnus-summary
977   :type 'hook)
978
979 (defcustom gnus-summary-article-delete-hook nil
980   "*A hook called after an article is deleted."
981   :version "21.4"
982   :group 'gnus-summary
983   :type 'hook)
984
985 (defcustom gnus-summary-article-expire-hook nil
986   "*A hook called after an article is expired."
987   :version "21.4"
988   :group 'gnus-summary
989   :type 'hook)
990
991 (defcustom gnus-summary-display-arrow
992   (and (fboundp 'display-graphic-p)
993        (display-graphic-p))
994   "*If non-nil, display an arrow highlighting the current article."
995   :version "21.4"
996   :group 'gnus-summary
997   :type 'boolean)
998
999 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
1000   "Face used for highlighting the current article in the summary buffer."
1001   :group 'gnus-summary-visual
1002   :type 'face)
1003
1004 (defvar gnus-tmp-downloaded nil)
1005
1006 (defcustom gnus-summary-highlight
1007   '(((eq mark gnus-canceled-mark)
1008      . gnus-summary-cancelled-face)
1009     ((and uncached (> score default-high))
1010      . gnus-summary-high-undownloaded-face)
1011     ((and uncached (< score default-low))
1012      . gnus-summary-low-undownloaded-face)
1013     (uncached
1014      . gnus-summary-normal-undownloaded-face)
1015     ((and (> score default-high)
1016           (or (eq mark gnus-dormant-mark)
1017               (eq mark gnus-ticked-mark)))
1018      . gnus-summary-high-ticked-face)
1019     ((and (< score default-low)
1020           (or (eq mark gnus-dormant-mark)
1021               (eq mark gnus-ticked-mark)))
1022      . gnus-summary-low-ticked-face)
1023     ((or (eq mark gnus-dormant-mark)
1024          (eq mark gnus-ticked-mark))
1025      . gnus-summary-normal-ticked-face)
1026     ((and (> score default-high) (eq mark gnus-ancient-mark))
1027      . gnus-summary-high-ancient-face)
1028     ((and (< score default-low) (eq mark gnus-ancient-mark))
1029      . gnus-summary-low-ancient-face)
1030     ((eq mark gnus-ancient-mark)
1031      . gnus-summary-normal-ancient-face)
1032     ((and (> score default-high) (eq mark gnus-unread-mark))
1033      . gnus-summary-high-unread-face)
1034     ((and (< score default-low) (eq mark gnus-unread-mark))
1035      . gnus-summary-low-unread-face)
1036     ((eq mark gnus-unread-mark)
1037      . gnus-summary-normal-unread-face)
1038     ((> score default-high)
1039      . gnus-summary-high-read-face)
1040     ((< score default-low)
1041      . gnus-summary-low-read-face)
1042     (t
1043      . gnus-summary-normal-read-face))
1044   "*Controls the highlighting of summary buffer lines.
1045
1046 A list of (FORM . FACE) pairs.  When deciding how a a particular
1047 summary line should be displayed, each form is evaluated.  The content
1048 of the face field after the first true form is used.  You can change
1049 how those summary lines are displayed, by editing the face field.
1050
1051 You can use the following variables in the FORM field.
1052
1053 score:        The article's score
1054 default:      The default article score.
1055 default-high: The default score for high scored articles.
1056 default-low:  The default score for low scored articles.
1057 below:        The score below which articles are automatically marked as read.
1058 mark:         The article's mark.
1059 uncached:     Non-nil if the article is uncached."
1060   :group 'gnus-summary-visual
1061   :type '(repeat (cons (sexp :tag "Form" nil)
1062                        face)))
1063
1064 (defcustom gnus-alter-header-function nil
1065   "Function called to allow alteration of article header structures.
1066 The function is called with one parameter, the article header vector,
1067 which it may alter in any way."
1068   :type '(choice (const :tag "None" nil)
1069                  function)
1070   :group 'gnus-summary)
1071
1072 (defvar gnus-decode-encoded-word-function
1073   (mime-find-field-decoder 'From 'nov)
1074   "Variable that says which function should be used to decode a string with encoded words.")
1075
1076 (defcustom gnus-extra-headers '(To Newsgroups)
1077   "*Extra headers to parse."
1078   :version "21.1"
1079   :group 'gnus-summary
1080   :type '(repeat symbol))
1081
1082 (defcustom gnus-ignored-from-addresses
1083   (and user-mail-address (regexp-quote user-mail-address))
1084   "*Regexp of From headers that may be suppressed in favor of To headers."
1085   :version "21.1"
1086   :group 'gnus-summary
1087   :type 'regexp)
1088
1089 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1090   "List of charsets that should be ignored.
1091 When these charsets are used in the \"charset\" parameter, the
1092 default charset will be used instead."
1093   :version "21.1"
1094   :type '(repeat symbol)
1095   :group 'gnus-charset)
1096
1097 (gnus-define-group-parameter
1098  ignored-charsets
1099  :type list
1100  :function-document
1101  "Return the ignored charsets of GROUP."
1102  :variable gnus-group-ignored-charsets-alist
1103  :variable-default
1104  '(("alt\\.chinese\\.text" iso-8859-1))
1105  :variable-document
1106  "Alist of regexps (to match group names) and charsets that should be ignored.
1107 When these charsets are used in the \"charset\" parameter, the
1108 default charset will be used instead."
1109  :variable-group gnus-charset
1110  :variable-type '(repeat (cons (regexp :tag "Group")
1111                                (repeat symbol)))
1112  :parameter-type '(choice :tag "Ignored charsets"
1113                           :value nil
1114                           (repeat (symbol)))
1115  :parameter-document       "\
1116 List of charsets that should be ignored.
1117
1118 When these charsets are used in the \"charset\" parameter, the
1119 default charset will be used instead.")
1120
1121 (defcustom gnus-group-highlight-words-alist nil
1122   "Alist of group regexps and highlight regexps.
1123 This variable uses the same syntax as `gnus-emphasis-alist'."
1124   :version "21.1"
1125   :type '(repeat (cons (regexp :tag "Group")
1126                        (repeat (list (regexp :tag "Highlight regexp")
1127                                      (number :tag "Group for entire word" 0)
1128                                      (number :tag "Group for displayed part" 0)
1129                                      (symbol :tag "Face"
1130                                              gnus-emphasis-highlight-words)))))
1131   :group 'gnus-summary-visual)
1132
1133 (defcustom gnus-use-wheel nil
1134   "Use Intelli-mouse on summary movement"
1135   :type 'boolean
1136   :group 'gnus-summary-maneuvering)
1137
1138 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1139   "Amount to scroll messages by spinning the mouse wheel.
1140 This is actually a cons cell, where the first item is the amount to scroll
1141 on a normal wheel event, and the second is the amount to scroll when the
1142 wheel is moved with the shift key depressed."
1143   :type '(cons (integer :tag "Shift") integer)
1144   :group 'gnus-summary-maneuvering)
1145
1146 (defcustom gnus-wheel-edge-resistance 2
1147   "How hard it should be to change the current article
1148 by moving the mouse over the edge of the article window."
1149   :type 'integer
1150   :group 'gnus-summary-maneuvering)
1151
1152 (defcustom gnus-summary-show-article-charset-alist
1153   nil
1154   "Alist of number and charset.
1155 The article will be shown with the charset corresponding to the
1156 numbered argument.
1157 For example: ((1 . cn-gb-2312) (2 . big5))."
1158   :version "21.1"
1159   :type '(repeat (cons (number :tag "Argument" 1)
1160                        (symbol :tag "Charset")))
1161   :group 'gnus-charset)
1162
1163 (defcustom gnus-preserve-marks t
1164   "Whether marks are preserved when moving, copying and respooling messages."
1165   :version "21.1"
1166   :type 'boolean
1167   :group 'gnus-summary-marks)
1168
1169 (defcustom gnus-alter-articles-to-read-function nil
1170   "Function to be called to alter the list of articles to be selected."
1171   :type '(choice (const nil) function)
1172   :group 'gnus-summary)
1173
1174 (defcustom gnus-orphan-score nil
1175   "*All orphans get this score added.  Set in the score file."
1176   :group 'gnus-score-default
1177   :type '(choice (const nil)
1178                  integer))
1179
1180 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1181   "*A regexp to match MIME parts when saving multiple parts of a
1182 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1183 This regexp will be used by default when prompting the user for which
1184 type of files to save."
1185   :group 'gnus-summary
1186   :type 'regexp)
1187
1188 (defcustom gnus-read-all-available-headers nil
1189   "Whether Gnus should parse all headers made available to it.
1190 This is mostly relevant for slow back ends where the user may
1191 wish to widen the summary buffer to include all headers
1192 that were fetched.  Say, for nnultimate groups."
1193   :version "21.4"
1194   :group 'gnus-summary
1195   :type '(choice boolean regexp))
1196
1197 (defcustom gnus-summary-muttprint-program "muttprint"
1198   "Command (and optional arguments) used to run Muttprint."
1199   :version "21.4"
1200   :group 'gnus-summary
1201   :type 'string)
1202
1203 (defcustom gnus-article-loose-mime t
1204   "If non-nil, don't require MIME-Version header.
1205 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1206 supply the MIME-Version header or deliberately strip it from the mail.
1207 If non-nil (the default), Gnus will treat some articles as MIME
1208 even if the MIME-Version header is missing."
1209   :version "21.4"
1210   :type 'boolean
1211   :group 'gnus-article-mime)
1212
1213 (defcustom gnus-article-emulate-mime t
1214   "If non-nil, use MIME emulation for uuencode and the like.
1215 This means that Gnus will search message bodies for text that look
1216 like uuencoded bits, yEncoded bits, and so on, and present that using
1217 the normal Gnus MIME machinery."
1218   :version "21.4"
1219   :type 'boolean
1220   :group 'gnus-article-mime)
1221
1222 ;;; Internal variables
1223
1224 (defvar gnus-summary-display-cache nil)
1225 (defvar gnus-article-mime-handles nil)
1226 (defvar gnus-article-decoded-p nil)
1227 (defvar gnus-article-charset nil)
1228 (defvar gnus-article-ignored-charsets nil)
1229 (defvar gnus-scores-exclude-files nil)
1230 (defvar gnus-page-broken nil)
1231
1232 (defvar gnus-original-article nil)
1233 (defvar gnus-article-internal-prepare-hook nil)
1234 (defvar gnus-newsgroup-process-stack nil)
1235
1236 (defvar gnus-thread-indent-array nil)
1237 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1238 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1239   "Function called to sort the articles within a thread after it has been gathered together.")
1240
1241 (defvar gnus-summary-save-parts-type-history nil)
1242 (defvar gnus-summary-save-parts-last-directory nil)
1243
1244 ;; Avoid highlighting in kill files.
1245 (defvar gnus-summary-inhibit-highlight nil)
1246 (defvar gnus-newsgroup-selected-overlay nil)
1247 (defvar gnus-inhibit-limiting nil)
1248 (defvar gnus-newsgroup-adaptive-score-file nil)
1249 (defvar gnus-current-score-file nil)
1250 (defvar gnus-current-move-group nil)
1251 (defvar gnus-current-copy-group nil)
1252 (defvar gnus-current-crosspost-group nil)
1253 (defvar gnus-newsgroup-display nil)
1254
1255 (defvar gnus-newsgroup-dependencies nil)
1256 (defvar gnus-newsgroup-adaptive nil)
1257 (defvar gnus-summary-display-article-function nil)
1258 (defvar gnus-summary-highlight-line-function nil
1259   "Function called after highlighting a summary line.")
1260
1261 (defvar gnus-summary-line-format-alist
1262   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1263     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1264     (?s gnus-tmp-subject-or-nil ?s)
1265     (?n gnus-tmp-name ?s)
1266     (?A (std11-address-string
1267          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1268     (?a (or (std11-full-name-string
1269              (car (mime-entity-read-field gnus-tmp-header 'From)))
1270             gnus-tmp-from) ?s)
1271     (?F gnus-tmp-from ?s)
1272     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1273     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1274     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1275     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1276     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1277     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1278     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1279     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1280     (?L gnus-tmp-lines ?s)
1281     (?O gnus-tmp-downloaded ?c)
1282     (?I gnus-tmp-indentation ?s)
1283     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1284     (?R gnus-tmp-replied ?c)
1285     (?\[ gnus-tmp-opening-bracket ?c)
1286     (?\] gnus-tmp-closing-bracket ?c)
1287     (?\> (make-string gnus-tmp-level ? ) ?s)
1288     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1289     (?i gnus-tmp-score ?d)
1290     (?z gnus-tmp-score-char ?c)
1291     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1292     (?U gnus-tmp-unread ?c)
1293     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1294         ?s)
1295     (?t (gnus-summary-number-of-articles-in-thread
1296          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1297         ?d)
1298     (?e (gnus-summary-number-of-articles-in-thread
1299          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1300         ?c)
1301     (?u gnus-tmp-user-defined ?s)
1302     (?P (gnus-pick-line-number) ?d)
1303     (?B gnus-tmp-thread-tree-header-string ?s)
1304     (user-date (gnus-user-date
1305                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1306   "An alist of format specifications that can appear in summary lines.
1307 These are paired with what variables they correspond with, along with
1308 the type of the variable (string, integer, character, etc).")
1309
1310 (defvar gnus-summary-dummy-line-format-alist
1311   `((?S gnus-tmp-subject ?s)
1312     (?N gnus-tmp-number ?d)
1313     (?u gnus-tmp-user-defined ?s)))
1314
1315 (defvar gnus-summary-mode-line-format-alist
1316   `((?G gnus-tmp-group-name ?s)
1317     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1318     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1319     (?A gnus-tmp-article-number ?d)
1320     (?Z gnus-tmp-unread-and-unselected ?s)
1321     (?V gnus-version ?s)
1322     (?U gnus-tmp-unread-and-unticked ?d)
1323     (?S gnus-tmp-subject ?s)
1324     (?e gnus-tmp-unselected ?d)
1325     (?u gnus-tmp-user-defined ?s)
1326     (?d (length gnus-newsgroup-dormant) ?d)
1327     (?t (length gnus-newsgroup-marked) ?d)
1328     (?h (length gnus-newsgroup-spam-marked) ?d)
1329     (?r (length gnus-newsgroup-reads) ?d)
1330     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1331     (?E gnus-newsgroup-expunged-tally ?d)
1332     (?s (gnus-current-score-file-nondirectory) ?s)))
1333
1334 (defvar gnus-last-search-regexp nil
1335   "Default regexp for article search command.")
1336
1337 (defvar gnus-summary-search-article-matched-data nil
1338   "Last matched data of article search command.  It is the local variable
1339 in `gnus-article-buffer' which consists of the list of start position,
1340 end position and text.")
1341
1342 (defvar gnus-last-shell-command nil
1343   "Default shell command on article.")
1344
1345 (defvar gnus-newsgroup-agentized nil
1346   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1347 (defvar gnus-newsgroup-begin nil)
1348 (defvar gnus-newsgroup-end nil)
1349 (defvar gnus-newsgroup-last-rmail nil)
1350 (defvar gnus-newsgroup-last-mail nil)
1351 (defvar gnus-newsgroup-last-folder nil)
1352 (defvar gnus-newsgroup-last-file nil)
1353 (defvar gnus-newsgroup-auto-expire nil)
1354 (defvar gnus-newsgroup-active nil)
1355
1356 (defvar gnus-newsgroup-data nil)
1357 (defvar gnus-newsgroup-data-reverse nil)
1358 (defvar gnus-newsgroup-limit nil)
1359 (defvar gnus-newsgroup-limits nil)
1360 (defvar gnus-summary-use-undownloaded-faces nil)
1361
1362 (defvar gnus-newsgroup-unreads nil
1363   "Sorted list of unread articles in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-unselected nil
1366   "Sorted list of unselected unread articles in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-reads nil
1369   "Alist of read articles and article marks in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expunged-tally nil)
1372
1373 (defvar gnus-newsgroup-marked nil
1374   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1375
1376 (defvar gnus-newsgroup-spam-marked nil
1377   "List of ranges of articles that have been marked as spam.")
1378
1379 (defvar gnus-newsgroup-killed nil
1380   "List of ranges of articles that have been through the scoring process.")
1381
1382 (defvar gnus-newsgroup-cached nil
1383   "Sorted list of articles that come from the article cache.")
1384
1385 (defvar gnus-newsgroup-saved nil
1386   "List of articles that have been saved.")
1387
1388 (defvar gnus-newsgroup-kill-headers nil)
1389
1390 (defvar gnus-newsgroup-replied nil
1391   "List of articles that have been replied to in the current newsgroup.")
1392
1393 (defvar gnus-newsgroup-forwarded nil
1394   "List of articles that have been forwarded in the current newsgroup.")
1395
1396 (defvar gnus-newsgroup-recent nil
1397   "List of articles that have are recent in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-expirable nil
1400   "Sorted list of articles in the current newsgroup that can be expired.")
1401
1402 (defvar gnus-newsgroup-processable nil
1403   "List of articles in the current newsgroup that can be processed.")
1404
1405 (defvar gnus-newsgroup-downloadable nil
1406   "Sorted list of articles in the current newsgroup that can be processed.")
1407
1408 (defvar gnus-newsgroup-unfetched nil
1409   "Sorted list of articles in the current newsgroup whose headers have
1410 not been fetched into the agent.
1411
1412 This list will always be a subset of gnus-newsgroup-undownloaded.")
1413
1414 (defvar gnus-newsgroup-undownloaded nil
1415   "List of articles in the current newsgroup that haven't been downloaded.")
1416
1417 (defvar gnus-newsgroup-unsendable nil
1418   "List of articles in the current newsgroup that won't be sent.")
1419
1420 (defvar gnus-newsgroup-bookmarks nil
1421   "List of articles in the current newsgroup that have bookmarks.")
1422
1423 (defvar gnus-newsgroup-dormant nil
1424   "Sorted list of dormant articles in the current newsgroup.")
1425
1426 (defvar gnus-newsgroup-unseen nil
1427   "List of unseen articles in the current newsgroup.")
1428
1429 (defvar gnus-newsgroup-seen nil
1430   "Range of seen articles in the current newsgroup.")
1431
1432 (defvar gnus-newsgroup-articles nil
1433   "List of articles in the current newsgroup.")
1434
1435 (defvar gnus-newsgroup-scored nil
1436   "List of scored articles in the current newsgroup.")
1437
1438 (defvar gnus-newsgroup-incorporated nil
1439   "List of incorporated articles in the current newsgroup.")
1440
1441 (defvar gnus-newsgroup-headers nil
1442   "List of article headers in the current newsgroup.")
1443
1444 (defvar gnus-newsgroup-threads nil)
1445
1446 (defvar gnus-newsgroup-prepared nil
1447   "Whether the current group has been prepared properly.")
1448
1449 (defvar gnus-newsgroup-ancient nil
1450   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-sparse nil)
1453
1454 (defvar gnus-current-article nil)
1455 (defvar gnus-article-current nil)
1456 (defvar gnus-current-headers nil)
1457 (defvar gnus-have-all-headers nil)
1458 (defvar gnus-last-article nil)
1459 (defvar gnus-newsgroup-history nil)
1460 (defvar gnus-newsgroup-charset nil)
1461 (defvar gnus-newsgroup-ephemeral-charset nil)
1462 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1463
1464 (defvar gnus-article-before-search nil)
1465
1466 (defvar gnus-summary-local-variables
1467   '(gnus-newsgroup-name
1468     gnus-newsgroup-begin gnus-newsgroup-end
1469     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1470     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1471     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1472     gnus-newsgroup-unselected gnus-newsgroup-marked
1473     gnus-newsgroup-spam-marked
1474     gnus-newsgroup-reads gnus-newsgroup-saved
1475     gnus-newsgroup-replied gnus-newsgroup-forwarded
1476     gnus-newsgroup-recent
1477     gnus-newsgroup-expirable
1478     gnus-newsgroup-processable gnus-newsgroup-killed
1479     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1480     gnus-newsgroup-unfetched
1481     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1482     gnus-newsgroup-seen gnus-newsgroup-articles
1483     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1484     gnus-newsgroup-headers gnus-newsgroup-threads
1485     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1486     gnus-current-article gnus-current-headers gnus-have-all-headers
1487     gnus-last-article gnus-article-internal-prepare-hook
1488     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1489     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1490     gnus-thread-expunge-below
1491     gnus-score-alist gnus-current-score-file
1492     (gnus-summary-expunge-below . global)
1493     (gnus-summary-mark-below . global)
1494     (gnus-orphan-score . global)
1495     gnus-newsgroup-active gnus-scores-exclude-files
1496     gnus-newsgroup-history gnus-newsgroup-ancient
1497     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1498     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1499     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1500     (gnus-newsgroup-expunged-tally . 0)
1501     gnus-cache-removable-articles gnus-newsgroup-cached
1502     gnus-newsgroup-data gnus-newsgroup-data-reverse
1503     gnus-newsgroup-limit gnus-newsgroup-limits
1504     gnus-newsgroup-charset gnus-newsgroup-display
1505     gnus-summary-use-undownloaded-faces
1506     gnus-newsgroup-incorporated)
1507   "Variables that are buffer-local to the summary buffers.")
1508
1509 (defvar gnus-newsgroup-variables nil
1510   "A list of variables that have separate values in different newsgroups.
1511 A list of newsgroup (summary buffer) local variables, or cons of
1512 variables and their default expressions to be evalled (when the default
1513 values are not nil), that should be made global while the summary buffer
1514 is active.
1515
1516 Note: The default expressions will be evaluated (using function `eval')
1517 before assignment to the local variable rather than just assigned to it.
1518 If the default expression is the symbol `global', that symbol will not
1519 be evaluated but the global value of the local variable will be used
1520 instead.
1521
1522 These variables can be used to set variables in the group parameters
1523 while still allowing them to affect operations done in other buffers.
1524 For example:
1525
1526 \(setq gnus-newsgroup-variables
1527      '(message-use-followup-to
1528        (gnus-visible-headers .
1529          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1530 ")
1531
1532 ;; Byte-compiler warning.
1533 (eval-when-compile
1534   ;; Bind features so that require will believe that gnus-sum has
1535   ;; already been loaded (avoids infinite recursion)
1536   (let ((features (cons 'gnus-sum features)))
1537     ;; Several of the declarations in gnus-sum are needed to load the
1538     ;; following files. Right now, these definitions have been
1539     ;; compiled but not defined (evaluated).  We could either do a
1540     ;; eval-and-compile about all of the declarations or evaluate the
1541     ;; source file.
1542     (if (boundp 'gnus-newsgroup-variables)
1543         nil
1544       (load "gnus-sum.el" t t t))
1545     (require 'gnus)
1546     (require 'gnus-art)))
1547
1548 ;; Subject simplification.
1549
1550 (defun gnus-simplify-whitespace (str)
1551   "Remove excessive whitespace from STR."
1552   ;; Multiple spaces.
1553   (while (string-match "[ \t][ \t]+" str)
1554     (setq str (concat (substring str 0 (match-beginning 0))
1555                         " "
1556                         (substring str (match-end 0)))))
1557   ;; Leading spaces.
1558   (when (string-match "^[ \t]+" str)
1559     (setq str (substring str (match-end 0))))
1560   ;; Trailing spaces.
1561   (when (string-match "[ \t]+$" str)
1562     (setq str (substring str 0 (match-beginning 0))))
1563   str)
1564
1565 (defun gnus-simplify-all-whitespace (str)
1566   "Remove all whitespace from STR."
1567   (while (string-match "[ \t\n]+" str)
1568     (setq str (replace-match "" nil nil str)))
1569   str)
1570
1571 (defsubst gnus-simplify-subject-re (subject)
1572   "Remove \"Re:\" from subject lines."
1573   (if (string-match message-subject-re-regexp subject)
1574       (substring subject (match-end 0))
1575     subject))
1576
1577 (defun gnus-simplify-subject (subject &optional re-only)
1578   "Remove `Re:' and words in parentheses.
1579 If RE-ONLY is non-nil, strip leading `Re:'s only."
1580   (let ((case-fold-search t))           ;Ignore case.
1581     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1582     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1583       (setq subject (substring subject (match-end 0))))
1584     ;; Remove uninteresting prefixes.
1585     (when (and (not re-only)
1586                gnus-simplify-ignored-prefixes
1587                (string-match gnus-simplify-ignored-prefixes subject))
1588       (setq subject (substring subject (match-end 0))))
1589     ;; Remove words in parentheses from end.
1590     (unless re-only
1591       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1592         (setq subject (substring subject 0 (match-beginning 0)))))
1593     ;; Return subject string.
1594     subject))
1595
1596 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1597 ;; all whitespace.
1598 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1599   (goto-char (point-min))
1600   (while (re-search-forward regexp nil t)
1601     (replace-match (or newtext ""))))
1602
1603 (defun gnus-simplify-buffer-fuzzy ()
1604   "Simplify string in the buffer fuzzily.
1605 The string in the accessible portion of the current buffer is simplified.
1606 It is assumed to be a single-line subject.
1607 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1608 matter is removed.  Additional things can be deleted by setting
1609 `gnus-simplify-subject-fuzzy-regexp'."
1610   (let ((case-fold-search t)
1611         (modified-tick))
1612     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1613
1614     (while (not (eq modified-tick (buffer-modified-tick)))
1615       (setq modified-tick (buffer-modified-tick))
1616       (cond
1617        ((listp gnus-simplify-subject-fuzzy-regexp)
1618         (mapcar 'gnus-simplify-buffer-fuzzy-step
1619                 gnus-simplify-subject-fuzzy-regexp))
1620        (gnus-simplify-subject-fuzzy-regexp
1621         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1622       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1623       (gnus-simplify-buffer-fuzzy-step
1624        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1625       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1626
1627     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1628     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1629     (gnus-simplify-buffer-fuzzy-step " $")
1630     (gnus-simplify-buffer-fuzzy-step "^ +")))
1631
1632 (defun gnus-simplify-subject-fuzzy (subject)
1633   "Simplify a subject string fuzzily.
1634 See `gnus-simplify-buffer-fuzzy' for details."
1635   (save-excursion
1636     (gnus-set-work-buffer)
1637     (let ((case-fold-search t))
1638       ;; Remove uninteresting prefixes.
1639       (when (and gnus-simplify-ignored-prefixes
1640                  (string-match gnus-simplify-ignored-prefixes subject))
1641         (setq subject (substring subject (match-end 0))))
1642       (insert subject)
1643       (inline (gnus-simplify-buffer-fuzzy))
1644       (buffer-string))))
1645
1646 (defsubst gnus-simplify-subject-fully (subject)
1647   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1648   (cond
1649    (gnus-simplify-subject-functions
1650     (gnus-map-function gnus-simplify-subject-functions subject))
1651    ((null gnus-summary-gather-subject-limit)
1652     (gnus-simplify-subject-re subject))
1653    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1654     (gnus-simplify-subject-fuzzy subject))
1655    ((numberp gnus-summary-gather-subject-limit)
1656     (gnus-limit-string (gnus-simplify-subject-re subject)
1657                        gnus-summary-gather-subject-limit))
1658    (t
1659     subject)))
1660
1661 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1662   "Check whether two subjects are equal.
1663 If optional argument SIMPLE-FIRST is t, first argument is already
1664 simplified."
1665   (cond
1666    ((null simple-first)
1667     (equal (gnus-simplify-subject-fully s1)
1668            (gnus-simplify-subject-fully s2)))
1669    (t
1670     (equal s1
1671            (gnus-simplify-subject-fully s2)))))
1672
1673 (defun gnus-summary-bubble-group ()
1674   "Increase the score of the current group.
1675 This is a handy function to add to `gnus-summary-exit-hook' to
1676 increase the score of each group you read."
1677   (gnus-group-add-score gnus-newsgroup-name))
1678
1679 \f
1680 ;;;
1681 ;;; Gnus summary mode
1682 ;;;
1683
1684 (put 'gnus-summary-mode 'mode-class 'special)
1685
1686 (defvar gnus-article-commands-menu)
1687
1688 ;; Non-orthogonal keys
1689
1690 (gnus-define-keys gnus-summary-mode-map
1691   " " gnus-summary-next-page
1692   "\177" gnus-summary-prev-page
1693   [delete] gnus-summary-prev-page
1694   [backspace] gnus-summary-prev-page
1695   "\r" gnus-summary-scroll-up
1696   "\M-\r" gnus-summary-scroll-down
1697   "n" gnus-summary-next-unread-article
1698   "p" gnus-summary-prev-unread-article
1699   "N" gnus-summary-next-article
1700   "P" gnus-summary-prev-article
1701   "\M-\C-n" gnus-summary-next-same-subject
1702   "\M-\C-p" gnus-summary-prev-same-subject
1703   "\M-n" gnus-summary-next-unread-subject
1704   "\M-p" gnus-summary-prev-unread-subject
1705   "." gnus-summary-first-unread-article
1706   "," gnus-summary-best-unread-article
1707   "\M-s" gnus-summary-search-article-forward
1708   "\M-r" gnus-summary-search-article-backward
1709   "<" gnus-summary-beginning-of-article
1710   ">" gnus-summary-end-of-article
1711   "j" gnus-summary-goto-article
1712   "^" gnus-summary-refer-parent-article
1713   "\M-^" gnus-summary-refer-article
1714   "u" gnus-summary-tick-article-forward
1715   "!" gnus-summary-tick-article-forward
1716   "U" gnus-summary-tick-article-backward
1717   "d" gnus-summary-mark-as-read-forward
1718   "D" gnus-summary-mark-as-read-backward
1719   "E" gnus-summary-mark-as-expirable
1720   "\M-u" gnus-summary-clear-mark-forward
1721   "\M-U" gnus-summary-clear-mark-backward
1722   "k" gnus-summary-kill-same-subject-and-select
1723   "\C-k" gnus-summary-kill-same-subject
1724   "\M-\C-k" gnus-summary-kill-thread
1725   "\M-\C-l" gnus-summary-lower-thread
1726   "e" gnus-summary-edit-article
1727   "#" gnus-summary-mark-as-processable
1728   "\M-#" gnus-summary-unmark-as-processable
1729   "\M-\C-t" gnus-summary-toggle-threads
1730   "\M-\C-s" gnus-summary-show-thread
1731   "\M-\C-h" gnus-summary-hide-thread
1732   "\M-\C-f" gnus-summary-next-thread
1733   "\M-\C-b" gnus-summary-prev-thread
1734   [(meta down)] gnus-summary-next-thread
1735   [(meta up)] gnus-summary-prev-thread
1736   "\M-\C-u" gnus-summary-up-thread
1737   "\M-\C-d" gnus-summary-down-thread
1738   "&" gnus-summary-execute-command
1739   "c" gnus-summary-catchup-and-exit
1740   "\C-w" gnus-summary-mark-region-as-read
1741   "\C-t" gnus-summary-toggle-truncation
1742   "?" gnus-summary-mark-as-dormant
1743   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1744   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1745   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1746   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1747   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1748   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1749   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1750   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1751   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1752   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1753   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1754   "=" gnus-summary-expand-window
1755   "\C-x\C-s" gnus-summary-reselect-current-group
1756   "\M-g" gnus-summary-rescan-group
1757   "w" gnus-summary-stop-page-breaking
1758   "\C-c\C-r" gnus-summary-caesar-message
1759   "\M-t" gnus-summary-toggle-mime
1760   "f" gnus-summary-followup
1761   "F" gnus-summary-followup-with-original
1762   "C" gnus-summary-cancel-article
1763   "r" gnus-summary-reply
1764   "R" gnus-summary-reply-with-original
1765   "\C-c\C-f" gnus-summary-mail-forward
1766   "o" gnus-summary-save-article
1767   "\C-o" gnus-summary-save-article-mail
1768   "|" gnus-summary-pipe-output
1769   "\M-k" gnus-summary-edit-local-kill
1770   "\M-K" gnus-summary-edit-global-kill
1771   ;; "V" gnus-version
1772   "\C-c\C-d" gnus-summary-describe-group
1773   "q" gnus-summary-exit
1774   "Q" gnus-summary-exit-no-update
1775   "\C-c\C-i" gnus-info-find-node
1776   gnus-mouse-2 gnus-mouse-pick-article
1777   [follow-link] mouse-face
1778   "m" gnus-summary-mail-other-window
1779   "a" gnus-summary-post-news
1780   "i" gnus-summary-news-other-window
1781   "x" gnus-summary-limit-to-unread
1782   "s" gnus-summary-isearch-article
1783   "t" gnus-summary-toggle-header
1784   "g" gnus-summary-show-article
1785   "l" gnus-summary-goto-last-article
1786   "v" gnus-summary-preview-mime-message
1787   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1788   "\C-d" gnus-summary-enter-digest-group
1789   "\M-\C-d" gnus-summary-read-document
1790   "\M-\C-e" gnus-summary-edit-parameters
1791   "\M-\C-a" gnus-summary-customize-parameters
1792   "\C-c\C-b" gnus-bug
1793   "\C-c\C-n" gnus-namazu-search
1794   "*" gnus-cache-enter-article
1795   "\M-*" gnus-cache-remove-article
1796   "\M-&" gnus-summary-universal-argument
1797   "\C-l" gnus-recenter
1798   "I" gnus-summary-increase-score
1799   "L" gnus-summary-lower-score
1800   "\M-i" gnus-symbolic-argument
1801   "h" gnus-summary-select-article-buffer
1802
1803   "V" gnus-summary-score-map
1804   "X" gnus-uu-extract-map
1805   "S" gnus-summary-send-map)
1806
1807   ;; Sort of orthogonal keymap
1808 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1809   "t" gnus-summary-tick-article-forward
1810   "!" gnus-summary-tick-article-forward
1811   "d" gnus-summary-mark-as-read-forward
1812   "r" gnus-summary-mark-as-read-forward
1813   "c" gnus-summary-clear-mark-forward
1814   " " gnus-summary-clear-mark-forward
1815   "e" gnus-summary-mark-as-expirable
1816   "x" gnus-summary-mark-as-expirable
1817   "?" gnus-summary-mark-as-dormant
1818   "b" gnus-summary-set-bookmark
1819   "B" gnus-summary-remove-bookmark
1820   "#" gnus-summary-mark-as-processable
1821   "\M-#" gnus-summary-unmark-as-processable
1822   "S" gnus-summary-limit-include-expunged
1823   "C" gnus-summary-catchup
1824   "H" gnus-summary-catchup-to-here
1825   "h" gnus-summary-catchup-from-here
1826   "\C-c" gnus-summary-catchup-all
1827   "k" gnus-summary-kill-same-subject-and-select
1828   "K" gnus-summary-kill-same-subject
1829   "P" gnus-uu-mark-map)
1830
1831 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1832   "c" gnus-summary-clear-above
1833   "u" gnus-summary-tick-above
1834   "m" gnus-summary-mark-above
1835   "k" gnus-summary-kill-below)
1836
1837 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1838   "/" gnus-summary-limit-to-subject
1839   "n" gnus-summary-limit-to-articles
1840   "w" gnus-summary-pop-limit
1841   "s" gnus-summary-limit-to-subject
1842   "a" gnus-summary-limit-to-author
1843   "u" gnus-summary-limit-to-unread
1844   "m" gnus-summary-limit-to-marks
1845   "M" gnus-summary-limit-exclude-marks
1846   "v" gnus-summary-limit-to-score
1847   "*" gnus-summary-limit-include-cached
1848   "D" gnus-summary-limit-include-dormant
1849   "T" gnus-summary-limit-include-thread
1850   "d" gnus-summary-limit-exclude-dormant
1851   "t" gnus-summary-limit-to-age
1852   "." gnus-summary-limit-to-unseen
1853   "x" gnus-summary-limit-to-extra
1854   "p" gnus-summary-limit-to-display-predicate
1855   "E" gnus-summary-limit-include-expunged
1856   "c" gnus-summary-limit-exclude-childless-dormant
1857   "C" gnus-summary-limit-mark-excluded-as-read
1858   "o" gnus-summary-insert-old-articles
1859   "N" gnus-summary-insert-new-articles
1860   "r" gnus-summary-limit-to-replied
1861   "R" gnus-summary-limit-to-recipient)
1862
1863 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1864   "n" gnus-summary-next-unread-article
1865   "p" gnus-summary-prev-unread-article
1866   "N" gnus-summary-next-article
1867   "P" gnus-summary-prev-article
1868   "\C-n" gnus-summary-next-same-subject
1869   "\C-p" gnus-summary-prev-same-subject
1870   "\M-n" gnus-summary-next-unread-subject
1871   "\M-p" gnus-summary-prev-unread-subject
1872   "f" gnus-summary-first-unread-article
1873   "b" gnus-summary-best-unread-article
1874   "j" gnus-summary-goto-article
1875   "g" gnus-summary-goto-subject
1876   "l" gnus-summary-goto-last-article
1877   "o" gnus-summary-pop-article)
1878
1879 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1880   "k" gnus-summary-kill-thread
1881   "l" gnus-summary-lower-thread
1882   "i" gnus-summary-raise-thread
1883   "T" gnus-summary-toggle-threads
1884   "t" gnus-summary-rethread-current
1885   "^" gnus-summary-reparent-thread
1886   "s" gnus-summary-show-thread
1887   "S" gnus-summary-show-all-threads
1888   "h" gnus-summary-hide-thread
1889   "H" gnus-summary-hide-all-threads
1890   "n" gnus-summary-next-thread
1891   "p" gnus-summary-prev-thread
1892   "u" gnus-summary-up-thread
1893   "o" gnus-summary-top-thread
1894   "d" gnus-summary-down-thread
1895   "#" gnus-uu-mark-thread
1896   "\M-#" gnus-uu-unmark-thread)
1897
1898 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1899   "g" gnus-summary-prepare
1900   "c" gnus-summary-insert-cached-articles
1901   "d" gnus-summary-insert-dormant-articles)
1902
1903 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1904   "c" gnus-summary-catchup-and-exit
1905   "C" gnus-summary-catchup-all-and-exit
1906   "E" gnus-summary-exit-no-update
1907   "J" gnus-summary-jump-to-other-group
1908   "Q" gnus-summary-exit
1909   "Z" gnus-summary-exit
1910   "n" gnus-summary-catchup-and-goto-next-group
1911   "R" gnus-summary-reselect-current-group
1912   "G" gnus-summary-rescan-group
1913   "N" gnus-summary-next-group
1914   "s" gnus-summary-save-newsrc
1915   "P" gnus-summary-prev-group)
1916
1917 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1918   " " gnus-summary-next-page
1919   "n" gnus-summary-next-page
1920   "\177" gnus-summary-prev-page
1921   [delete] gnus-summary-prev-page
1922   "p" gnus-summary-prev-page
1923   "\r" gnus-summary-scroll-up
1924   "\M-\r" gnus-summary-scroll-down
1925   "<" gnus-summary-beginning-of-article
1926   ">" gnus-summary-end-of-article
1927   "b" gnus-summary-beginning-of-article
1928   "e" gnus-summary-end-of-article
1929   "^" gnus-summary-refer-parent-article
1930   "r" gnus-summary-refer-parent-article
1931   "D" gnus-summary-enter-digest-group
1932   "R" gnus-summary-refer-references
1933   "T" gnus-summary-refer-thread
1934   "g" gnus-summary-show-article
1935   "s" gnus-summary-isearch-article
1936   "P" gnus-summary-print-article
1937   "M" gnus-mailing-list-insinuate
1938   "t" gnus-article-babel)
1939
1940 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1941   "b" gnus-article-add-buttons
1942   "B" gnus-article-add-buttons-to-head
1943   "o" gnus-article-treat-overstrike
1944   "e" gnus-article-emphasize
1945   "w" gnus-article-fill-cited-article
1946   "Q" gnus-article-fill-long-lines
1947   "C" gnus-article-capitalize-sentences
1948   "c" gnus-article-remove-cr
1949   "Z" gnus-article-decode-HZ
1950   "A" gnus-article-treat-ansi-sequences
1951   "h" gnus-article-wash-html
1952   "u" gnus-article-unsplit-urls
1953   "f" gnus-article-display-x-face
1954   "l" gnus-summary-stop-page-breaking
1955   "r" gnus-summary-caesar-message
1956   "m" gnus-summary-morse-message
1957   "t" gnus-summary-toggle-header
1958   "g" gnus-treat-smiley
1959   "v" gnus-summary-verbose-headers
1960   "m" gnus-summary-toggle-mime
1961   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1962   "p" gnus-article-verify-x-pgp-sig
1963   "d" gnus-article-treat-dumbquotes)
1964
1965 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1966   ;; mnemonic: deuglif*Y*
1967   "u" gnus-article-outlook-unwrap-lines
1968   "a" gnus-article-outlook-repair-attribution
1969   "c" gnus-article-outlook-rearrange-citation
1970   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1971
1972 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1973   "a" gnus-article-hide
1974   "h" gnus-article-hide-headers
1975   "b" gnus-article-hide-boring-headers
1976   "s" gnus-article-hide-signature
1977   "c" gnus-article-hide-citation
1978   "C" gnus-article-hide-citation-in-followups
1979   "l" gnus-article-hide-list-identifiers
1980   "B" gnus-article-strip-banner
1981   "P" gnus-article-hide-pem
1982   "\C-c" gnus-article-hide-citation-maybe)
1983
1984 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1985   "a" gnus-article-highlight
1986   "h" gnus-article-highlight-headers
1987   "c" gnus-article-highlight-citation
1988   "s" gnus-article-highlight-signature)
1989
1990 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1991   "f" gnus-article-treat-fold-headers
1992   "u" gnus-article-treat-unfold-headers
1993   "n" gnus-article-treat-fold-newsgroups)
1994
1995 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1996   "x" gnus-article-display-x-face
1997   "d" gnus-article-display-face
1998   "s" gnus-treat-smiley
1999   "D" gnus-article-remove-images
2000   "f" gnus-treat-from-picon
2001   "m" gnus-treat-mail-picon
2002   "n" gnus-treat-newsgroups-picon)
2003
2004 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2005   "z" gnus-article-date-ut
2006   "u" gnus-article-date-ut
2007   "l" gnus-article-date-local
2008   "p" gnus-article-date-english
2009   "e" gnus-article-date-lapsed
2010   "o" gnus-article-date-original
2011   "i" gnus-article-date-iso8601
2012   "s" gnus-article-date-user)
2013
2014 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2015   "t" gnus-article-remove-trailing-blank-lines
2016   "l" gnus-article-strip-leading-blank-lines
2017   "m" gnus-article-strip-multiple-blank-lines
2018   "a" gnus-article-strip-blank-lines
2019   "A" gnus-article-strip-all-blank-lines
2020   "s" gnus-article-strip-leading-space
2021   "e" gnus-article-strip-trailing-space
2022   "w" gnus-article-remove-leading-whitespace)
2023
2024 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2025   "v" gnus-version
2026   "f" gnus-summary-fetch-faq
2027   "d" gnus-summary-describe-group
2028   "h" gnus-summary-describe-briefly
2029   "i" gnus-info-find-node
2030   "c" gnus-group-fetch-charter
2031   "C" gnus-group-fetch-control)
2032
2033 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2034   "e" gnus-summary-expire-articles
2035   "\M-\C-e" gnus-summary-expire-articles-now
2036   "\177" gnus-summary-delete-article
2037   [delete] gnus-summary-delete-article
2038   [backspace] gnus-summary-delete-article
2039   "m" gnus-summary-move-article
2040   "r" gnus-summary-respool-article
2041   "w" gnus-summary-edit-article
2042   "c" gnus-summary-copy-article
2043   "B" gnus-summary-crosspost-article
2044   "q" gnus-summary-respool-query
2045   "t" gnus-summary-respool-trace
2046   "i" gnus-summary-import-article
2047   "I" gnus-summary-create-article
2048   "p" gnus-summary-article-posted-p)
2049
2050 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2051   "o" gnus-summary-save-article
2052   "m" gnus-summary-save-article-mail
2053   "F" gnus-summary-write-article-file
2054   "r" gnus-summary-save-article-rmail
2055   "f" gnus-summary-save-article-file
2056   "b" gnus-summary-save-article-body-file
2057   "h" gnus-summary-save-article-folder
2058   "v" gnus-summary-save-article-vm
2059   "p" gnus-summary-pipe-output
2060   "P" gnus-summary-muttprint
2061   "s" gnus-soup-add-article)
2062
2063 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2064   "b" gnus-summary-display-buttonized
2065   "m" gnus-summary-repair-multipart
2066   "v" gnus-article-view-part
2067   "o" gnus-article-save-part
2068   "c" gnus-article-copy-part
2069   "C" gnus-article-view-part-as-charset
2070   "e" gnus-article-view-part-externally
2071   "E" gnus-article-encrypt-body
2072   "i" gnus-article-inline-part
2073   "|" gnus-article-pipe-part)
2074
2075 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2076   "p" gnus-summary-mark-as-processable
2077   "u" gnus-summary-unmark-as-processable
2078   "U" gnus-summary-unmark-all-processable
2079   "v" gnus-uu-mark-over
2080   "s" gnus-uu-mark-series
2081   "r" gnus-uu-mark-region
2082   "g" gnus-uu-unmark-region
2083   "R" gnus-uu-mark-by-regexp
2084   "G" gnus-uu-unmark-by-regexp
2085   "t" gnus-uu-mark-thread
2086   "T" gnus-uu-unmark-thread
2087   "a" gnus-uu-mark-all
2088   "b" gnus-uu-mark-buffer
2089   "S" gnus-uu-mark-sparse
2090   "k" gnus-summary-kill-process-mark
2091   "y" gnus-summary-yank-process-mark
2092   "w" gnus-summary-save-process-mark
2093   "i" gnus-uu-invert-processable)
2094
2095 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2096   ;;"x" gnus-uu-extract-any
2097   "m" gnus-summary-save-parts
2098   "u" gnus-uu-decode-uu
2099   "U" gnus-uu-decode-uu-and-save
2100   "s" gnus-uu-decode-unshar
2101   "S" gnus-uu-decode-unshar-and-save
2102   "o" gnus-uu-decode-save
2103   "O" gnus-uu-decode-save
2104   "b" gnus-uu-decode-binhex
2105   "B" gnus-uu-decode-binhex
2106   "p" gnus-uu-decode-postscript
2107   "P" gnus-uu-decode-postscript-and-save)
2108
2109 (gnus-define-keys
2110     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2111   "u" gnus-uu-decode-uu-view
2112   "U" gnus-uu-decode-uu-and-save-view
2113   "s" gnus-uu-decode-unshar-view
2114   "S" gnus-uu-decode-unshar-and-save-view
2115   "o" gnus-uu-decode-save-view
2116   "O" gnus-uu-decode-save-view
2117   "b" gnus-uu-decode-binhex-view
2118   "B" gnus-uu-decode-binhex-view
2119   "p" gnus-uu-decode-postscript-view
2120   "P" gnus-uu-decode-postscript-and-save-view)
2121
2122 (defvar gnus-article-post-menu nil)
2123
2124 (defconst gnus-summary-menu-maxlen 20)
2125
2126 (defun gnus-summary-menu-split (menu)
2127   ;; If we have lots of elements, divide them into groups of 20
2128   ;; and make a pane (or submenu) for each one.
2129   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2130       (let ((menu menu) sublists next
2131             (i 1))
2132         (while menu
2133           ;; Pull off the next gnus-summary-menu-maxlen elements
2134           ;; and make them the next element of sublist.
2135           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2136           (if next
2137               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2138                       nil))
2139           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2140                                              (aref (car (last menu)) 0)) menu)
2141                                sublists))
2142           (setq i (1+ i))
2143           (setq menu next))
2144         (nreverse sublists))
2145     ;; Few elements--put them all in one pane.
2146     menu))
2147
2148 (defun gnus-summary-make-menu-bar ()
2149   (gnus-turn-off-edit-menu 'summary)
2150
2151   (unless (boundp 'gnus-summary-misc-menu)
2152
2153     (easy-menu-define
2154       gnus-summary-kill-menu gnus-summary-mode-map ""
2155       (cons
2156        "Score"
2157        (nconc
2158         (list
2159          ["Customize" gnus-score-customize t])
2160         (gnus-make-score-map 'increase)
2161         (gnus-make-score-map 'lower)
2162         '(("Mark"
2163            ["Kill below" gnus-summary-kill-below t]
2164            ["Mark above" gnus-summary-mark-above t]
2165            ["Tick above" gnus-summary-tick-above t]
2166            ["Clear above" gnus-summary-clear-above t])
2167           ["Current score" gnus-summary-current-score t]
2168           ["Set score" gnus-summary-set-score t]
2169           ["Switch current score file..." gnus-score-change-score-file t]
2170           ["Set mark below..." gnus-score-set-mark-below t]
2171           ["Set expunge below..." gnus-score-set-expunge-below t]
2172           ["Edit current score file" gnus-score-edit-current-scores t]
2173           ["Edit score file" gnus-score-edit-file t]
2174           ["Trace score" gnus-score-find-trace t]
2175           ["Find words" gnus-score-find-favourite-words t]
2176           ["Rescore buffer" gnus-summary-rescore t]
2177           ["Increase score..." gnus-summary-increase-score t]
2178           ["Lower score..." gnus-summary-lower-score t]))))
2179
2180     ;; Define both the Article menu in the summary buffer and the
2181     ;; equivalent Commands menu in the article buffer here for
2182     ;; consistency.
2183     (let ((innards
2184            `(("Hide"
2185               ["All" gnus-article-hide t]
2186               ["Headers" gnus-article-hide-headers t]
2187               ["Signature" gnus-article-hide-signature t]
2188               ["Citation" gnus-article-hide-citation t]
2189               ["List identifiers" gnus-article-hide-list-identifiers t]
2190               ["Banner" gnus-article-strip-banner t]
2191               ["Boring headers" gnus-article-hide-boring-headers t])
2192              ("Highlight"
2193               ["All" gnus-article-highlight t]
2194               ["Headers" gnus-article-highlight-headers t]
2195               ["Signature" gnus-article-highlight-signature t]
2196               ["Citation" gnus-article-highlight-citation t])
2197              ("Date"
2198               ["Local" gnus-article-date-local t]
2199               ["ISO8601" gnus-article-date-iso8601 t]
2200               ["UT" gnus-article-date-ut t]
2201               ["Original" gnus-article-date-original t]
2202               ["Lapsed" gnus-article-date-lapsed t]
2203               ["User-defined" gnus-article-date-user t])
2204              ("Display"
2205               ["Remove images" gnus-article-remove-images t]
2206               ["Toggle smiley" gnus-treat-smiley t]
2207               ["Show X-Face" gnus-article-display-x-face t]
2208               ["Show picons in From" gnus-treat-from-picon t]
2209               ["Show picons in mail headers" gnus-treat-mail-picon t]
2210               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2211               ("View as different encoding"
2212                ,@(gnus-summary-menu-split
2213                   (mapcar
2214                    (lambda (cs)
2215                      ;; Since easymenu under Emacs doesn't allow
2216                      ;; lambda forms for menu commands, we should
2217                      ;; provide intern'ed function symbols.
2218                      (let ((command (intern (format "\
2219 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2220                        (fset command
2221                              `(lambda ()
2222                                 (interactive)
2223                                 (let ((gnus-summary-show-article-charset-alist
2224                                        '((1 . ,cs))))
2225                                   (gnus-summary-show-article 1))))
2226                        `[,(symbol-name cs) ,command t]))
2227                    (sort (if (fboundp 'coding-system-list)
2228                              (coding-system-list)
2229                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2230                            )
2231                          'string<)))))
2232              ("Washing"
2233               ("Remove Blanks"
2234                ["Leading" gnus-article-strip-leading-blank-lines t]
2235                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2236                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2237                ["All of the above" gnus-article-strip-blank-lines t]
2238                ["All" gnus-article-strip-all-blank-lines t]
2239                ["Leading space" gnus-article-strip-leading-space t]
2240                ["Trailing space" gnus-article-strip-trailing-space t]
2241                ["Leading space in headers"
2242                 gnus-article-remove-leading-whitespace t])
2243               ["Overstrike" gnus-article-treat-overstrike t]
2244               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2245               ["Emphasis" gnus-article-emphasize t]
2246               ["Word wrap" gnus-article-fill-cited-article t]
2247               ["Fill long lines" gnus-article-fill-long-lines t]
2248               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2249               ["Remove CR" gnus-article-remove-cr t]
2250               ["Rot 13" gnus-summary-caesar-message
2251                ,@(if (featurep 'xemacs) '(t)
2252                    '(:help "\"Caesar rotate\" article by 13"))]
2253               ["Morse decode" gnus-summary-morse-message t]
2254               ["Unix pipe..." gnus-summary-pipe-message t]
2255               ["Add buttons" gnus-article-add-buttons t]
2256               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2257               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2258               ["Toggle MIME" gnus-summary-toggle-mime t]
2259               ["Verbose header" gnus-summary-verbose-headers t]
2260               ["Toggle header" gnus-summary-toggle-header t]
2261               ["Unfold headers" gnus-article-treat-unfold-headers t]
2262               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2263               ["Html" gnus-article-wash-html t]
2264               ["Unsplit URLs" gnus-article-unsplit-urls t]
2265               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2266               ["Decode HZ" gnus-article-decode-HZ t]
2267               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2268               ("(Outlook) Deuglify"
2269                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2270                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2271                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2272                ["Full (Outlook) deuglify"
2273                 gnus-article-outlook-deuglify-article t])
2274               )
2275              ("Output"
2276               ["Save in default format..." gnus-summary-save-article
2277                ,@(if (featurep 'xemacs) '(t)
2278                    '(:help "Save article using default method"))]
2279               ["Save in file..." gnus-summary-save-article-file
2280                ,@(if (featurep 'xemacs) '(t)
2281                    '(:help "Save article in file"))]
2282               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2283               ["Save in MH folder..." gnus-summary-save-article-folder t]
2284               ["Save in VM folder..." gnus-summary-save-article-vm t]
2285               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2286               ["Save body in file..." gnus-summary-save-article-body-file t]
2287               ["Pipe through a filter..." gnus-summary-pipe-output t]
2288               ["Add to SOUP packet" gnus-soup-add-article t]
2289               ["Print with Muttprint..." gnus-summary-muttprint t]
2290               ["Print" gnus-summary-print-article
2291                ,@(if (featurep 'xemacs) '(t)
2292                    '(:help "Generate and print a PostScript image"))])
2293              ("Copy, move,... (Backend)"
2294               ,@(if (featurep 'xemacs) nil
2295                   '(:help "Copying, moving, expiring articles..."))
2296               ["Respool article..." gnus-summary-respool-article t]
2297               ["Move article..." gnus-summary-move-article
2298                (gnus-check-backend-function
2299                 'request-move-article gnus-newsgroup-name)]
2300               ["Copy article..." gnus-summary-copy-article t]
2301               ["Crosspost article..." gnus-summary-crosspost-article
2302                (gnus-check-backend-function
2303                 'request-replace-article gnus-newsgroup-name)]
2304               ["Import file..." gnus-summary-import-article
2305                (gnus-check-backend-function
2306                 'request-accept-article gnus-newsgroup-name)]
2307               ["Create article..." gnus-summary-create-article
2308                (gnus-check-backend-function
2309                 'request-accept-article gnus-newsgroup-name)]
2310               ["Check if posted" gnus-summary-article-posted-p t]
2311               ["Edit article" gnus-summary-edit-article
2312                (not (gnus-group-read-only-p))]
2313               ["Delete article" gnus-summary-delete-article
2314                (gnus-check-backend-function
2315                 'request-expire-articles gnus-newsgroup-name)]
2316               ["Query respool" gnus-summary-respool-query t]
2317               ["Trace respool" gnus-summary-respool-trace t]
2318               ["Delete expirable articles" gnus-summary-expire-articles-now
2319                (gnus-check-backend-function
2320                 'request-expire-articles gnus-newsgroup-name)])
2321              ("Extract"
2322               ["Uudecode" gnus-uu-decode-uu
2323                ,@(if (featurep 'xemacs) '(t)
2324                    '(:help "Decode uuencoded article(s)"))]
2325               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2326               ["Unshar" gnus-uu-decode-unshar t]
2327               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2328               ["Save" gnus-uu-decode-save t]
2329               ["Binhex" gnus-uu-decode-binhex t]
2330               ["Postscript" gnus-uu-decode-postscript t])
2331              ("Cache"
2332               ["Enter article" gnus-cache-enter-article t]
2333               ["Remove article" gnus-cache-remove-article t])
2334              ["Translate" gnus-article-babel t]
2335              ["Select article buffer" gnus-summary-select-article-buffer t]
2336              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2337              ["Isearch article..." gnus-summary-isearch-article t]
2338              ["Beginning of the article" gnus-summary-beginning-of-article t]
2339              ["End of the article" gnus-summary-end-of-article t]
2340              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2341              ["Fetch referenced articles" gnus-summary-refer-references t]
2342              ["Fetch current thread" gnus-summary-refer-thread t]
2343              ["Fetch article with id..." gnus-summary-refer-article t]
2344              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2345              ["Redisplay" gnus-summary-show-article t]
2346              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2347       (easy-menu-define
2348         gnus-summary-article-menu gnus-summary-mode-map ""
2349         (cons "Article" innards))
2350
2351       (if (not (keymapp gnus-summary-article-menu))
2352           (easy-menu-define
2353             gnus-article-commands-menu gnus-article-mode-map ""
2354             (cons "Commands" innards))
2355         ;; in Emacs, don't share menu.
2356         (setq gnus-article-commands-menu
2357               (copy-keymap gnus-summary-article-menu))
2358         (define-key gnus-article-mode-map [menu-bar commands]
2359           (cons "Commands" gnus-article-commands-menu))))
2360
2361     (easy-menu-define
2362       gnus-summary-thread-menu gnus-summary-mode-map ""
2363       '("Threads"
2364         ["Find all messages in thread" gnus-summary-refer-thread t]
2365         ["Toggle threading" gnus-summary-toggle-threads t]
2366         ["Hide threads" gnus-summary-hide-all-threads t]
2367         ["Show threads" gnus-summary-show-all-threads t]
2368         ["Hide thread" gnus-summary-hide-thread t]
2369         ["Show thread" gnus-summary-show-thread t]
2370         ["Go to next thread" gnus-summary-next-thread t]
2371         ["Go to previous thread" gnus-summary-prev-thread t]
2372         ["Go down thread" gnus-summary-down-thread t]
2373         ["Go up thread" gnus-summary-up-thread t]
2374         ["Top of thread" gnus-summary-top-thread t]
2375         ["Mark thread as read" gnus-summary-kill-thread t]
2376         ["Lower thread score" gnus-summary-lower-thread t]
2377         ["Raise thread score" gnus-summary-raise-thread t]
2378         ["Rethread current" gnus-summary-rethread-current t]))
2379
2380     (easy-menu-define
2381       gnus-summary-post-menu gnus-summary-mode-map ""
2382       `("Post"
2383         ["Send a message (mail or news)" gnus-summary-post-news
2384          ,@(if (featurep 'xemacs) '(t)
2385              '(:help "Compose a new message (mail or news)"))]
2386         ["Followup" gnus-summary-followup
2387          ,@(if (featurep 'xemacs) '(t)
2388              '(:help "Post followup to this article"))]
2389         ["Followup and yank" gnus-summary-followup-with-original
2390          ,@(if (featurep 'xemacs) '(t)
2391              '(:help "Post followup to this article, quoting its contents"))]
2392         ["Supersede article" gnus-summary-supersede-article t]
2393         ["Cancel article" gnus-summary-cancel-article
2394          ,@(if (featurep 'xemacs) '(t)
2395              '(:help "Cancel an article you posted"))]
2396         ["Reply" gnus-summary-reply t]
2397         ["Reply and yank" gnus-summary-reply-with-original t]
2398         ["Wide reply" gnus-summary-wide-reply t]
2399         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2400          ,@(if (featurep 'xemacs) '(t)
2401              '(:help "Mail a reply, quoting this article"))]
2402         ["Very wide reply" gnus-summary-very-wide-reply t]
2403         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Mail a very wide reply, quoting this article"))]
2406         ["Mail forward" gnus-summary-mail-forward t]
2407         ["Post forward" gnus-summary-post-forward t]
2408         ["Digest and mail" gnus-summary-digest-mail-forward t]
2409         ["Digest and post" gnus-summary-digest-post-forward t]
2410         ["Resend message" gnus-summary-resend-message t]
2411         ["Resend message edit" gnus-summary-resend-message-edit t]
2412         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2413         ["Send a mail" gnus-summary-mail-other-window t]
2414         ["Create a local message" gnus-summary-news-other-window t]
2415         ["Uuencode and post" gnus-uu-post-news
2416          ,@(if (featurep 'xemacs) '(t)
2417              '(:help "Post a uuencoded article"))]
2418         ["Followup via news" gnus-summary-followup-to-mail t]
2419         ["Followup via news and yank"
2420          gnus-summary-followup-to-mail-with-original t]
2421         ;;("Draft"
2422         ;;["Send" gnus-summary-send-draft t]
2423         ;;["Send bounced" gnus-resend-bounced-mail t])
2424         ))
2425
2426     (cond
2427      ((not (keymapp gnus-summary-post-menu))
2428       (setq gnus-article-post-menu gnus-summary-post-menu))
2429      ((not gnus-article-post-menu)
2430       ;; Don't share post menu.
2431       (setq gnus-article-post-menu
2432             (copy-keymap gnus-summary-post-menu))))
2433     (define-key gnus-article-mode-map [menu-bar post]
2434       (cons "Post" gnus-article-post-menu))
2435
2436     (easy-menu-define
2437       gnus-summary-misc-menu gnus-summary-mode-map ""
2438       `("Gnus"
2439         ("Mark Read"
2440          ["Mark as read" gnus-summary-mark-as-read-forward t]
2441          ["Mark same subject and select"
2442           gnus-summary-kill-same-subject-and-select t]
2443          ["Mark same subject" gnus-summary-kill-same-subject t]
2444          ["Catchup" gnus-summary-catchup
2445           ,@(if (featurep 'xemacs) '(t)
2446               '(:help "Mark unread articles in this group as read"))]
2447          ["Catchup all" gnus-summary-catchup-all t]
2448          ["Catchup to here" gnus-summary-catchup-to-here t]
2449          ["Catchup from here" gnus-summary-catchup-from-here t]
2450          ["Catchup region" gnus-summary-mark-region-as-read
2451           (gnus-mark-active-p)]
2452          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2453         ("Mark Various"
2454          ["Tick" gnus-summary-tick-article-forward t]
2455          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2456          ["Remove marks" gnus-summary-clear-mark-forward t]
2457          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2458          ["Set bookmark" gnus-summary-set-bookmark t]
2459          ["Remove bookmark" gnus-summary-remove-bookmark t])
2460         ("Limit to"
2461          ["Marks..." gnus-summary-limit-to-marks t]
2462          ["Subject..." gnus-summary-limit-to-subject t]
2463          ["Author..." gnus-summary-limit-to-author t]
2464          ["Recipient..." gnus-summary-limit-to-recipient t]
2465          ["Age..." gnus-summary-limit-to-age t]
2466          ["Extra..." gnus-summary-limit-to-extra t]
2467          ["Score..." gnus-summary-limit-to-score t]
2468          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2469          ["Unread" gnus-summary-limit-to-unread t]
2470          ["Unseen" gnus-summary-limit-to-unseen t]
2471          ["Replied" gnus-summary-limit-to-replied t]
2472          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2473          ["Next articles" gnus-summary-limit-to-articles t]
2474          ["Pop limit" gnus-summary-pop-limit t]
2475          ["Show dormant" gnus-summary-limit-include-dormant t]
2476          ["Hide childless dormant"
2477           gnus-summary-limit-exclude-childless-dormant t]
2478          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2479          ["Hide marked" gnus-summary-limit-exclude-marks t]
2480          ["Show expunged" gnus-summary-limit-include-expunged t])
2481         ("Process Mark"
2482          ["Set mark" gnus-summary-mark-as-processable t]
2483          ["Remove mark" gnus-summary-unmark-as-processable t]
2484          ["Remove all marks" gnus-summary-unmark-all-processable t]
2485          ["Invert marks" gnus-uu-invert-processable t]
2486          ["Mark above" gnus-uu-mark-over t]
2487          ["Mark series" gnus-uu-mark-series t]
2488          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2489          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2490          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2491          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2492          ["Mark all" gnus-uu-mark-all t]
2493          ["Mark buffer" gnus-uu-mark-buffer t]
2494          ["Mark sparse" gnus-uu-mark-sparse t]
2495          ["Mark thread" gnus-uu-mark-thread t]
2496          ["Unmark thread" gnus-uu-unmark-thread t]
2497          ("Process Mark Sets"
2498           ["Kill" gnus-summary-kill-process-mark t]
2499           ["Yank" gnus-summary-yank-process-mark
2500            gnus-newsgroup-process-stack]
2501           ["Save" gnus-summary-save-process-mark t]
2502           ["Run command on marked..." gnus-summary-universal-argument t]))
2503         ("Scroll article"
2504          ["Page forward" gnus-summary-next-page
2505           ,@(if (featurep 'xemacs) '(t)
2506               '(:help "Show next page of article"))]
2507          ["Page backward" gnus-summary-prev-page
2508           ,@(if (featurep 'xemacs) '(t)
2509               '(:help "Show previous page of article"))]
2510          ["Line forward" gnus-summary-scroll-up t])
2511         ("Move"
2512          ["Next unread article" gnus-summary-next-unread-article t]
2513          ["Previous unread article" gnus-summary-prev-unread-article t]
2514          ["Next article" gnus-summary-next-article t]
2515          ["Previous article" gnus-summary-prev-article t]
2516          ["Next unread subject" gnus-summary-next-unread-subject t]
2517          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2518          ["Next article same subject" gnus-summary-next-same-subject t]
2519          ["Previous article same subject" gnus-summary-prev-same-subject t]
2520          ["First unread article" gnus-summary-first-unread-article t]
2521          ["Best unread article" gnus-summary-best-unread-article t]
2522          ["Go to subject number..." gnus-summary-goto-subject t]
2523          ["Go to article number..." gnus-summary-goto-article t]
2524          ["Go to the last article" gnus-summary-goto-last-article t]
2525          ["Pop article off history" gnus-summary-pop-article t])
2526         ("Sort"
2527          ["Sort by number" gnus-summary-sort-by-number t]
2528          ["Sort by author" gnus-summary-sort-by-author t]
2529          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2530          ["Sort by subject" gnus-summary-sort-by-subject t]
2531          ["Sort by date" gnus-summary-sort-by-date t]
2532          ["Sort by score" gnus-summary-sort-by-score t]
2533          ["Sort by lines" gnus-summary-sort-by-lines t]
2534          ["Sort by characters" gnus-summary-sort-by-chars t]
2535          ["Randomize" gnus-summary-sort-by-random t]
2536          ["Original sort" gnus-summary-sort-by-original t])
2537         ("Help"
2538          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2539          ["Describe group" gnus-summary-describe-group t]
2540          ["Fetch charter" gnus-group-fetch-charter
2541           ,@(if (featurep 'xemacs) nil
2542               '(:help "Display the charter of the current group"))]
2543          ["Fetch control message" gnus-group-fetch-control
2544           ,@(if (featurep 'xemacs) nil
2545               '(:help "Display the archived control message for the current group"))]
2546          ["Read manual" gnus-info-find-node t])
2547         ("Modes"
2548          ["Pick and read" gnus-pick-mode t]
2549          ["Binary" gnus-binary-mode t])
2550         ("Regeneration"
2551          ["Regenerate" gnus-summary-prepare t]
2552          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2553          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2554          ["Toggle threading" gnus-summary-toggle-threads t])
2555         ["See old articles" gnus-summary-insert-old-articles t]
2556         ["See new articles" gnus-summary-insert-new-articles t]
2557         ["Filter articles..." gnus-summary-execute-command t]
2558         ["Run command on articles..." gnus-summary-universal-argument t]
2559         ["Search articles forward..." gnus-summary-search-article-forward t]
2560         ["Search articles backward..." gnus-summary-search-article-backward t]
2561         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2562         ["Expand window" gnus-summary-expand-window t]
2563         ["Expire expirable articles" gnus-summary-expire-articles
2564          (gnus-check-backend-function
2565           'request-expire-articles gnus-newsgroup-name)]
2566         ["Edit local kill file" gnus-summary-edit-local-kill t]
2567         ["Edit main kill file" gnus-summary-edit-global-kill t]
2568         ["Edit group parameters" gnus-summary-edit-parameters t]
2569         ["Customize group parameters" gnus-summary-customize-parameters t]
2570         ["Send a bug report" gnus-bug t]
2571         ("Exit"
2572          ["Catchup and exit" gnus-summary-catchup-and-exit
2573           ,@(if (featurep 'xemacs) '(t)
2574               '(:help "Mark unread articles in this group as read, then exit"))]
2575          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2576          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2577          ["Exit group" gnus-summary-exit
2578           ,@(if (featurep 'xemacs) '(t)
2579               '(:help "Exit current group, return to group selection mode"))]
2580          ["Exit group without updating" gnus-summary-exit-no-update t]
2581          ["Exit and goto next group" gnus-summary-next-group t]
2582          ["Exit and goto prev group" gnus-summary-prev-group t]
2583          ["Reselect group" gnus-summary-reselect-current-group t]
2584          ["Rescan group" gnus-summary-rescan-group t]
2585          ["Update dribble" gnus-summary-save-newsrc t])))
2586
2587     (gnus-run-hooks 'gnus-summary-menu-hook)))
2588
2589 (defvar gnus-summary-tool-bar-map nil)
2590
2591 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2592 (defun gnus-summary-make-tool-bar ()
2593   (if (and (fboundp 'tool-bar-add-item-from-menu)
2594            (default-value 'tool-bar-mode)
2595            (not gnus-summary-tool-bar-map))
2596       (setq gnus-summary-tool-bar-map
2597             (let ((tool-bar-map (make-sparse-keymap))
2598                   (load-path (mm-image-load-path)))
2599               (tool-bar-add-item-from-menu
2600                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2601               (tool-bar-add-item-from-menu
2602                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2603               (tool-bar-add-item-from-menu
2604                'gnus-summary-post-news "post" gnus-summary-mode-map)
2605               (tool-bar-add-item-from-menu
2606                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2607               (tool-bar-add-item-from-menu
2608                'gnus-summary-followup "followup" gnus-summary-mode-map)
2609               (tool-bar-add-item-from-menu
2610                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2611               (tool-bar-add-item-from-menu
2612                'gnus-summary-reply "reply" gnus-summary-mode-map)
2613               (tool-bar-add-item-from-menu
2614                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2615               (tool-bar-add-item-from-menu
2616                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2617               (tool-bar-add-item-from-menu
2618                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2631               tool-bar-map)))
2632   (if gnus-summary-tool-bar-map
2633       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2634
2635 (defun gnus-score-set-default (var value)
2636   "A version of set that updates the GNU Emacs menu-bar."
2637   (set var value)
2638   ;; It is the message that forces the active status to be updated.
2639   (message ""))
2640
2641 (defun gnus-make-score-map (type)
2642   "Make a summary score map of type TYPE."
2643   (if t
2644       nil
2645     (let ((headers '(("author" "from" string)
2646                      ("subject" "subject" string)
2647                      ("article body" "body" string)
2648                      ("article head" "head" string)
2649                      ("xref" "xref" string)
2650                      ("extra header" "extra" string)
2651                      ("lines" "lines" number)
2652                      ("followups to author" "followup" string)))
2653           (types '((number ("less than" <)
2654                            ("greater than" >)
2655                            ("equal" =))
2656                    (string ("substring" s)
2657                            ("exact string" e)
2658                            ("fuzzy string" f)
2659                            ("regexp" r))))
2660           (perms '(("temporary" (current-time-string))
2661                    ("permanent" nil)
2662                    ("immediate" now)))
2663           header)
2664       (list
2665        (apply
2666         'nconc
2667         (list
2668          (if (eq type 'lower)
2669              "Lower score"
2670            "Increase score"))
2671         (let (outh)
2672           (while headers
2673             (setq header (car headers))
2674             (setq outh
2675                   (cons
2676                    (apply
2677                     'nconc
2678                     (list (car header))
2679                     (let ((ts (cdr (assoc (nth 2 header) types)))
2680                           outt)
2681                       (while ts
2682                         (setq outt
2683                               (cons
2684                                (apply
2685                                 'nconc
2686                                 (list (caar ts))
2687                                 (let ((ps perms)
2688                                       outp)
2689                                   (while ps
2690                                     (setq outp
2691                                           (cons
2692                                            (vector
2693                                             (caar ps)
2694                                             (list
2695                                              'gnus-summary-score-entry
2696                                              (nth 1 header)
2697                                              (if (or (string= (nth 1 header)
2698                                                               "head")
2699                                                      (string= (nth 1 header)
2700                                                               "body"))
2701                                                  ""
2702                                                (list 'gnus-summary-header
2703                                                      (nth 1 header)))
2704                                              (list 'quote (nth 1 (car ts)))
2705                                              (list 'gnus-score-delta-default
2706                                                    nil)
2707                                              (nth 1 (car ps))
2708                                              t)
2709                                             t)
2710                                            outp))
2711                                     (setq ps (cdr ps)))
2712                                   (list (nreverse outp))))
2713                                outt))
2714                         (setq ts (cdr ts)))
2715                       (list (nreverse outt))))
2716                    outh))
2717             (setq headers (cdr headers)))
2718           (list (nreverse outh))))))))
2719
2720 \f
2721
2722 (defun gnus-summary-mode (&optional group)
2723   "Major mode for reading articles.
2724
2725 All normal editing commands are switched off.
2726 \\<gnus-summary-mode-map>
2727 Each line in this buffer represents one article.  To read an
2728 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2729 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2730 respectively.
2731
2732 You can also post articles and send mail from this buffer.  To
2733 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2734 of an article, type `\\[gnus-summary-reply]'.
2735
2736 There are approx. one gazillion commands you can execute in this
2737 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2738
2739 The following commands are available:
2740
2741 \\{gnus-summary-mode-map}"
2742   (interactive)
2743   (kill-all-local-variables)
2744   (when (gnus-visual-p 'summary-menu 'menu)
2745     (gnus-summary-make-menu-bar)
2746     (gnus-summary-make-tool-bar))
2747   (gnus-summary-make-local-variables)
2748   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2749     (gnus-summary-make-local-variables))
2750   (gnus-make-thread-indent-array)
2751   (gnus-simplify-mode-line)
2752   (setq major-mode 'gnus-summary-mode)
2753   (setq mode-name "Summary")
2754   (make-local-variable 'minor-mode-alist)
2755   (use-local-map gnus-summary-mode-map)
2756   (buffer-disable-undo)
2757   (setq buffer-read-only t              ;Disable modification
2758         show-trailing-whitespace nil)
2759   (setq truncate-lines t)
2760   (setq selective-display t)
2761   (setq selective-display-ellipses t)   ;Display `...'
2762   (gnus-summary-set-display-table)
2763   (gnus-set-default-directory)
2764   (setq gnus-newsgroup-name group)
2765   (unless (gnus-news-group-p group)
2766     (setq gnus-newsgroup-incorporated
2767           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2768   (make-local-variable 'gnus-summary-line-format)
2769   (make-local-variable 'gnus-summary-line-format-spec)
2770   (make-local-variable 'gnus-summary-dummy-line-format)
2771   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2772   (make-local-variable 'gnus-summary-mark-positions)
2773   (gnus-make-local-hook 'pre-command-hook)
2774   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2775   (gnus-run-hooks 'gnus-summary-mode-hook)
2776   (turn-on-gnus-mailing-list-mode)
2777   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2778   (gnus-update-summary-mark-positions))
2779
2780 (defun gnus-summary-make-local-variables ()
2781   "Make all the local summary buffer variables."
2782   (let (global)
2783     (dolist (local gnus-summary-local-variables)
2784       (if (consp local)
2785           (progn
2786             (if (eq (cdr local) 'global)
2787                 ;; Copy the global value of the variable.
2788                 (setq global (symbol-value (car local)))
2789               ;; Use the value from the list.
2790               (setq global (eval (cdr local))))
2791             (set (make-local-variable (car local)) global))
2792         ;; Simple nil-valued local variable.
2793         (set (make-local-variable local) nil)))))
2794
2795 (defun gnus-summary-clear-local-variables ()
2796   (let ((locals gnus-summary-local-variables))
2797     (while locals
2798       (if (consp (car locals))
2799           (and (symbolp (caar locals))
2800                (set (caar locals) nil))
2801         (and (symbolp (car locals))
2802              (set (car locals) nil)))
2803       (setq locals (cdr locals)))))
2804
2805 ;; Summary data functions.
2806
2807 (defmacro gnus-data-number (data)
2808   `(car ,data))
2809
2810 (defmacro gnus-data-set-number (data number)
2811   `(setcar ,data ,number))
2812
2813 (defmacro gnus-data-mark (data)
2814   `(nth 1 ,data))
2815
2816 (defmacro gnus-data-set-mark (data mark)
2817   `(setcar (nthcdr 1 ,data) ,mark))
2818
2819 (defmacro gnus-data-pos (data)
2820   `(nth 2 ,data))
2821
2822 (defmacro gnus-data-set-pos (data pos)
2823   `(setcar (nthcdr 2 ,data) ,pos))
2824
2825 (defmacro gnus-data-header (data)
2826   `(nth 3 ,data))
2827
2828 (defmacro gnus-data-set-header (data header)
2829   `(setcar (nthcdr 3 ,data) ,header))
2830
2831 (defmacro gnus-data-level (data)
2832   `(nth 4 ,data))
2833
2834 (defmacro gnus-data-unread-p (data)
2835   `(= (nth 1 ,data) gnus-unread-mark))
2836
2837 (defmacro gnus-data-read-p (data)
2838   `(/= (nth 1 ,data) gnus-unread-mark))
2839
2840 (defmacro gnus-data-pseudo-p (data)
2841   `(consp (nth 3 ,data)))
2842
2843 (defmacro gnus-data-find (number)
2844   `(assq ,number gnus-newsgroup-data))
2845
2846 (defmacro gnus-data-find-list (number &optional data)
2847   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2848      (memq (assq ,number bdata)
2849            bdata)))
2850
2851 (defmacro gnus-data-make (number mark pos header level)
2852   `(list ,number ,mark ,pos ,header ,level))
2853
2854 (defun gnus-data-enter (after-article number mark pos header level offset)
2855   (let ((data (gnus-data-find-list after-article)))
2856     (unless data
2857       (error "No such article: %d" after-article))
2858     (setcdr data (cons (gnus-data-make number mark pos header level)
2859                        (cdr data)))
2860     (setq gnus-newsgroup-data-reverse nil)
2861     (gnus-data-update-list (cddr data) offset)))
2862
2863 (defun gnus-data-enter-list (after-article list &optional offset)
2864   (when list
2865     (let ((data (and after-article (gnus-data-find-list after-article)))
2866           (ilist list))
2867       (if (not (or data
2868                    after-article))
2869           (let ((odata gnus-newsgroup-data))
2870             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2871             (when offset
2872               (gnus-data-update-list odata offset)))
2873         ;; Find the last element in the list to be spliced into the main
2874         ;; list.
2875         (setq list (last list))
2876         (if (not data)
2877             (progn
2878               (setcdr list gnus-newsgroup-data)
2879               (setq gnus-newsgroup-data ilist)
2880               (when offset
2881                 (gnus-data-update-list (cdr list) offset)))
2882           (setcdr list (cdr data))
2883           (setcdr data ilist)
2884           (when offset
2885             (gnus-data-update-list (cdr list) offset))))
2886       (setq gnus-newsgroup-data-reverse nil))))
2887
2888 (defun gnus-data-remove (article &optional offset)
2889   (let ((data gnus-newsgroup-data))
2890     (if (= (gnus-data-number (car data)) article)
2891         (progn
2892           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2893                 gnus-newsgroup-data-reverse nil)
2894           (when offset
2895             (gnus-data-update-list gnus-newsgroup-data offset)))
2896       (while (cdr data)
2897         (when (= (gnus-data-number (cadr data)) article)
2898           (setcdr data (cddr data))
2899           (when offset
2900             (gnus-data-update-list (cdr data) offset))
2901           (setq data nil
2902                 gnus-newsgroup-data-reverse nil))
2903         (setq data (cdr data))))))
2904
2905 (defmacro gnus-data-list (backward)
2906   `(if ,backward
2907        (or gnus-newsgroup-data-reverse
2908            (setq gnus-newsgroup-data-reverse
2909                  (reverse gnus-newsgroup-data)))
2910      gnus-newsgroup-data))
2911
2912 (defun gnus-data-update-list (data offset)
2913   "Add OFFSET to the POS of all data entries in DATA."
2914   (setq gnus-newsgroup-data-reverse nil)
2915   (while data
2916     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2917     (setq data (cdr data))))
2918
2919 (defun gnus-summary-article-pseudo-p (article)
2920   "Say whether this article is a pseudo article or not."
2921   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2922
2923 (defmacro gnus-summary-article-sparse-p (article)
2924   "Say whether this article is a sparse article or not."
2925   `(memq ,article gnus-newsgroup-sparse))
2926
2927 (defmacro gnus-summary-article-ancient-p (article)
2928   "Say whether this article is a sparse article or not."
2929   `(memq ,article gnus-newsgroup-ancient))
2930
2931 (defun gnus-article-parent-p (number)
2932   "Say whether this article is a parent or not."
2933   (let ((data (gnus-data-find-list number)))
2934     (and (cdr data)                     ; There has to be an article after...
2935          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2936             (gnus-data-level (nth 1 data))))))
2937
2938 (defun gnus-article-children (number)
2939   "Return a list of all children to NUMBER."
2940   (let* ((data (gnus-data-find-list number))
2941          (level (gnus-data-level (car data)))
2942          children)
2943     (setq data (cdr data))
2944     (while (and data
2945                 (= (gnus-data-level (car data)) (1+ level)))
2946       (push (gnus-data-number (car data)) children)
2947       (setq data (cdr data)))
2948     children))
2949
2950 (defmacro gnus-summary-skip-intangible ()
2951   "If the current article is intangible, then jump to a different article."
2952   '(let ((to (get-text-property (point) 'gnus-intangible)))
2953      (and to (gnus-summary-goto-subject to))))
2954
2955 (defmacro gnus-summary-article-intangible-p ()
2956   "Say whether this article is intangible or not."
2957   '(get-text-property (point) 'gnus-intangible))
2958
2959 (defun gnus-article-read-p (article)
2960   "Say whether ARTICLE is read or not."
2961   (not (or (memq article gnus-newsgroup-marked)
2962            (memq article gnus-newsgroup-spam-marked)
2963            (memq article gnus-newsgroup-unreads)
2964            (memq article gnus-newsgroup-unselected)
2965            (memq article gnus-newsgroup-dormant))))
2966
2967 ;; Some summary mode macros.
2968
2969 (defmacro gnus-summary-article-number ()
2970   "The article number of the article on the current line.
2971 If there isn't an article number here, then we return the current
2972 article number."
2973   '(progn
2974      (gnus-summary-skip-intangible)
2975      (or (get-text-property (point) 'gnus-number)
2976          (gnus-summary-last-subject))))
2977
2978 (defmacro gnus-summary-article-header (&optional number)
2979   "Return the header of article NUMBER."
2980   `(gnus-data-header (gnus-data-find
2981                       ,(or number '(gnus-summary-article-number)))))
2982
2983 (defmacro gnus-summary-thread-level (&optional number)
2984   "Return the level of thread that starts with article NUMBER."
2985   `(if (and (eq gnus-summary-make-false-root 'dummy)
2986             (get-text-property (point) 'gnus-intangible))
2987        0
2988      (gnus-data-level (gnus-data-find
2989                        ,(or number '(gnus-summary-article-number))))))
2990
2991 (defmacro gnus-summary-article-mark (&optional number)
2992   "Return the mark of article NUMBER."
2993   `(gnus-data-mark (gnus-data-find
2994                     ,(or number '(gnus-summary-article-number)))))
2995
2996 (defmacro gnus-summary-article-pos (&optional number)
2997   "Return the position of the line of article NUMBER."
2998   `(gnus-data-pos (gnus-data-find
2999                    ,(or number '(gnus-summary-article-number)))))
3000
3001 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3002 (defmacro gnus-summary-article-subject (&optional number)
3003   "Return current subject string or nil if nothing."
3004   `(let ((headers
3005           ,(if number
3006                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3007              '(gnus-data-header (assq (gnus-summary-article-number)
3008                                       gnus-newsgroup-data)))))
3009      (and headers
3010           (vectorp headers)
3011           (mail-header-subject headers))))
3012
3013 (defmacro gnus-summary-article-score (&optional number)
3014   "Return current article score."
3015   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3016                   gnus-newsgroup-scored))
3017        gnus-summary-default-score 0))
3018
3019 (defun gnus-summary-article-children (&optional number)
3020   "Return a list of article numbers that are children of article NUMBER."
3021   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3022          (level (gnus-data-level (car data)))
3023          l children)
3024     (while (and (setq data (cdr data))
3025                 (> (setq l (gnus-data-level (car data))) level))
3026       (and (= (1+ level) l)
3027            (push (gnus-data-number (car data))
3028                  children)))
3029     (nreverse children)))
3030
3031 (defun gnus-summary-article-parent (&optional number)
3032   "Return the article number of the parent of article NUMBER."
3033   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3034                                     (gnus-data-list t)))
3035          (level (gnus-data-level (car data))))
3036     (if (zerop level)
3037         ()                              ; This is a root.
3038       ;; We search until we find an article with a level less than
3039       ;; this one.  That function has to be the parent.
3040       (while (and (setq data (cdr data))
3041                   (not (< (gnus-data-level (car data)) level))))
3042       (and data (gnus-data-number (car data))))))
3043
3044 (defun gnus-unread-mark-p (mark)
3045   "Say whether MARK is the unread mark."
3046   (= mark gnus-unread-mark))
3047
3048 (defun gnus-read-mark-p (mark)
3049   "Say whether MARK is one of the marks that mark as read.
3050 This is all marks except unread, ticked, dormant, and expirable."
3051   (not (or (= mark gnus-unread-mark)
3052            (= mark gnus-ticked-mark)
3053            (= mark gnus-spam-mark)
3054            (= mark gnus-dormant-mark)
3055            (= mark gnus-expirable-mark))))
3056
3057 (defmacro gnus-article-mark (number)
3058   "Return the MARK of article NUMBER.
3059 This macro should only be used when computing the mark the \"first\"
3060 time; i.e., when generating the summary lines.  After that,
3061 `gnus-summary-article-mark' should be used to examine the
3062 marks of articles."
3063   `(cond
3064     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3065     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3066     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3067     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3068     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3069     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3070     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3071     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3072            gnus-ancient-mark))))
3073
3074 ;; Saving hidden threads.
3075
3076 (defmacro gnus-save-hidden-threads (&rest forms)
3077   "Save hidden threads, eval FORMS, and restore the hidden threads."
3078   (let ((config (make-symbol "config")))
3079     `(let ((,config (gnus-hidden-threads-configuration)))
3080        (unwind-protect
3081            (save-excursion
3082              ,@forms)
3083          (gnus-restore-hidden-threads-configuration ,config)))))
3084 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3085 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3086
3087 (defun gnus-data-compute-positions ()
3088   "Compute the positions of all articles."
3089   (setq gnus-newsgroup-data-reverse nil)
3090   (let ((data gnus-newsgroup-data))
3091     (save-excursion
3092       (gnus-save-hidden-threads
3093         (gnus-summary-show-all-threads)
3094         (goto-char (point-min))
3095         (while data
3096           (while (get-text-property (point) 'gnus-intangible)
3097             (forward-line 1))
3098           (gnus-data-set-pos (car data) (+ (point) 3))
3099           (setq data (cdr data))
3100           (forward-line 1))))))
3101
3102 (defun gnus-hidden-threads-configuration ()
3103   "Return the current hidden threads configuration."
3104   (save-excursion
3105     (let (config)
3106       (goto-char (point-min))
3107       (while (search-forward "\r" nil t)
3108         (push (1- (point)) config))
3109       config)))
3110
3111 (defun gnus-restore-hidden-threads-configuration (config)
3112   "Restore hidden threads configuration from CONFIG."
3113   (save-excursion
3114     (let (point buffer-read-only)
3115       (while (setq point (pop config))
3116         (when (and (< point (point-max))
3117                    (goto-char point)
3118                    (eq (char-after) ?\n))
3119           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3120
3121 ;; Various summary mode internalish functions.
3122
3123 (defun gnus-mouse-pick-article (e)
3124   (interactive "e")
3125   (mouse-set-point e)
3126   (gnus-summary-next-page nil t))
3127
3128 (defun gnus-summary-set-display-table ()
3129   "Change the display table.
3130 Odd characters have a tendency to mess
3131 up nicely formatted displays - we make all possible glyphs
3132 display only a single character."
3133
3134   ;; We start from the standard display table, if any.
3135   (let ((table (or (copy-sequence standard-display-table)
3136                    (make-display-table)))
3137         (i 32))
3138     ;; Nix out all the control chars...
3139     (while (>= (setq i (1- i)) 0)
3140       (aset table i [??]))
3141     ;; ... but not newline and cr, of course.  (cr is necessary for the
3142     ;; selective display).
3143     (aset table ?\n nil)
3144     (aset table ?\r nil)
3145     ;; We keep TAB as well.
3146     (aset table ?\t nil)
3147     ;; We nix out any glyphs over 126 that are not set already.
3148     (let ((i 256))
3149       (while (>= (setq i (1- i)) 127)
3150         ;; Only modify if the entry is nil.
3151         (unless (aref table i)
3152           (aset table i [??]))))
3153     (setq buffer-display-table table)))
3154
3155 (defun gnus-summary-set-article-display-arrow (pos)
3156   "Update the overlay arrow to point to line at position POS."
3157   (when (and gnus-summary-display-arrow
3158              (boundp 'overlay-arrow-position)
3159              (boundp 'overlay-arrow-string))
3160     (save-excursion
3161       (goto-char pos)
3162       (beginning-of-line)
3163       (unless overlay-arrow-position
3164         (setq overlay-arrow-position (make-marker)))
3165       (setq overlay-arrow-string "=>"
3166             overlay-arrow-position (set-marker overlay-arrow-position
3167                                                (point)
3168                                                (current-buffer))))))
3169
3170 (defun gnus-summary-setup-buffer (group)
3171   "Initialize summary buffer."
3172   (let ((buffer (gnus-summary-buffer-name group))
3173         (dead-name (concat "*Dead Summary "
3174                            (gnus-group-decoded-name group) "*")))
3175     ;; If a dead summary buffer exists, we kill it.
3176     (when (gnus-buffer-live-p dead-name)
3177       (gnus-kill-buffer dead-name))
3178     (if (get-buffer buffer)
3179         (progn
3180           (set-buffer buffer)
3181           (setq gnus-summary-buffer (current-buffer))
3182           (not gnus-newsgroup-prepared))
3183       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3184       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3185       (gnus-summary-mode group)
3186       (when gnus-carpal
3187         (gnus-carpal-setup-buffer 'summary))
3188       (unless gnus-single-article-buffer
3189         (make-local-variable 'gnus-article-buffer)
3190         (make-local-variable 'gnus-article-current)
3191         (make-local-variable 'gnus-original-article-buffer))
3192       (setq gnus-newsgroup-name group)
3193       ;; Set any local variables in the group parameters.
3194       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3195       t)))
3196
3197 (defun gnus-set-global-variables ()
3198   "Set the global equivalents of the buffer-local variables.
3199 They are set to the latest values they had.  These reflect the summary
3200 buffer that was in action when the last article was fetched."
3201   (when (eq major-mode 'gnus-summary-mode)
3202     (setq gnus-summary-buffer (current-buffer))
3203     (let ((name gnus-newsgroup-name)
3204           (marked gnus-newsgroup-marked)
3205           (spam gnus-newsgroup-spam-marked)
3206           (unread gnus-newsgroup-unreads)
3207           (headers gnus-current-headers)
3208           (data gnus-newsgroup-data)
3209           (summary gnus-summary-buffer)
3210           (article-buffer gnus-article-buffer)
3211           (original gnus-original-article-buffer)
3212           (gac gnus-article-current)
3213           (reffed gnus-reffed-article-number)
3214           (score-file gnus-current-score-file)
3215           (default-charset gnus-newsgroup-charset)
3216           vlist)
3217       (let ((locals gnus-newsgroup-variables))
3218         (while locals
3219           (if (consp (car locals))
3220               (push (eval (caar locals)) vlist)
3221             (push (eval (car locals)) vlist))
3222           (setq locals (cdr locals)))
3223         (setq vlist (nreverse vlist)))
3224       (with-current-buffer gnus-group-buffer
3225         (setq gnus-newsgroup-name name
3226               gnus-newsgroup-marked marked
3227               gnus-newsgroup-spam-marked spam
3228               gnus-newsgroup-unreads unread
3229               gnus-current-headers headers
3230               gnus-newsgroup-data data
3231               gnus-article-current gac
3232               gnus-summary-buffer summary
3233               gnus-article-buffer article-buffer
3234               gnus-original-article-buffer original
3235               gnus-reffed-article-number reffed
3236               gnus-current-score-file score-file
3237               gnus-newsgroup-charset default-charset)
3238         (let ((locals gnus-newsgroup-variables))
3239           (while locals
3240             (if (consp (car locals))
3241                 (set (caar locals) (pop vlist))
3242               (set (car locals) (pop vlist)))
3243             (setq locals (cdr locals))))
3244         ;; The article buffer also has local variables.
3245         (when (gnus-buffer-live-p gnus-article-buffer)
3246           (set-buffer gnus-article-buffer)
3247           (setq gnus-summary-buffer summary))))))
3248
3249 (defun gnus-summary-article-unread-p (article)
3250   "Say whether ARTICLE is unread or not."
3251   (memq article gnus-newsgroup-unreads))
3252
3253 (defun gnus-summary-first-article-p (&optional article)
3254   "Return whether ARTICLE is the first article in the buffer."
3255   (if (not (setq article (or article (gnus-summary-article-number))))
3256       nil
3257     (eq article (caar gnus-newsgroup-data))))
3258
3259 (defun gnus-summary-last-article-p (&optional article)
3260   "Return whether ARTICLE is the last article in the buffer."
3261   (if (not (setq article (or article (gnus-summary-article-number))))
3262       ;; All non-existent numbers are the last article.  :-)
3263       t
3264     (not (cdr (gnus-data-find-list article)))))
3265
3266 (defun gnus-make-thread-indent-array ()
3267   (let ((n 200))
3268     (unless (and gnus-thread-indent-array
3269                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3270       (setq gnus-thread-indent-array (make-vector 201 "")
3271             gnus-thread-indent-array-level gnus-thread-indent-level)
3272       (while (>= n 0)
3273         (aset gnus-thread-indent-array n
3274               (make-string (* n gnus-thread-indent-level) ? ))
3275         (setq n (1- n))))))
3276
3277 (defun gnus-update-summary-mark-positions ()
3278   "Compute where the summary marks are to go."
3279   (save-excursion
3280     (when (gnus-buffer-exists-p gnus-summary-buffer)
3281       (set-buffer gnus-summary-buffer))
3282     (let ((spec gnus-summary-line-format-spec)
3283           pos)
3284       (save-excursion
3285         (gnus-set-work-buffer)
3286         (let ((gnus-tmp-unread ?Z)
3287               (gnus-replied-mark ?Z)
3288               (gnus-score-below-mark ?Z)
3289               (gnus-score-over-mark ?Z)
3290               (gnus-undownloaded-mark ?Z)
3291               (gnus-summary-line-format-spec spec)
3292               (gnus-newsgroup-downloadable '(0))
3293               (header
3294                (make-full-mail-header
3295                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3296               case-fold-search ignores)
3297           ;; Here, all marks are bound to Z.
3298           (gnus-summary-insert-line header
3299                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3300           (goto-char (point-min))
3301           ;; Memorize the positions of the same characters as dummy marks.
3302           (while (re-search-forward "[A-D]" nil t)
3303             (push (point) ignores))
3304           (erase-buffer)
3305           ;; We use A-D as dummy marks in order to know column positions
3306           ;; where marks should be inserted.
3307           (setq gnus-tmp-unread ?A
3308                 gnus-replied-mark ?B
3309                 gnus-score-below-mark ?C
3310                 gnus-score-over-mark ?C
3311                 gnus-undownloaded-mark ?D)
3312           (gnus-summary-insert-line header
3313                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3314           ;; Ignore characters which aren't dummy marks.
3315           (dolist (p ignores)
3316             (delete-region (goto-char (1- p)) p)
3317             (insert ?Z))
3318           (goto-char (point-min))
3319           (setq pos (list (cons 'unread
3320                                 (and (search-forward "A" nil t)
3321                                      (- (point) (point-min) 1)))))
3322           (goto-char (point-min))
3323           (push (cons 'replied (and (search-forward "B" nil t)
3324                                     (- (point) (point-min) 1)))
3325                 pos)
3326           (goto-char (point-min))
3327           (push (cons 'score (and (search-forward "C" nil t)
3328                                   (- (point) (point-min) 1)))
3329                 pos)
3330           (goto-char (point-min))
3331           (push (cons 'download (and (search-forward "D" nil t)
3332                                      (- (point) (point-min) 1)))
3333                 pos)))
3334       (setq gnus-summary-mark-positions pos))))
3335
3336 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3337   "Insert a dummy root in the summary buffer."
3338   (beginning-of-line)
3339   (gnus-add-text-properties
3340    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3341    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3342
3343 (defun gnus-summary-extract-address-component (from)
3344   (or (car (funcall gnus-extract-address-components from))
3345       from))
3346
3347 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3348   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3349                                 default-mime-charset)))
3350     ;; Is it really necessary to do this next part for each summary line?
3351     ;; Luckily, doesn't seem to slow things down much.
3352     (or
3353      (and gnus-ignored-from-addresses
3354           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3355           (let ((extra-headers (mail-header-extra header))
3356                 to
3357                 newsgroups)
3358             (cond
3359              ((setq to (cdr (assq 'To extra-headers)))
3360               (concat "-> "
3361                       (inline
3362                         (gnus-summary-extract-address-component
3363                          (funcall gnus-decode-encoded-word-function to)))))
3364              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3365               (concat "=> " newsgroups)))))
3366      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3367
3368 (defun gnus-summary-insert-line (gnus-tmp-header
3369                                  gnus-tmp-level gnus-tmp-current
3370                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3371                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3372                                  &optional gnus-tmp-dummy gnus-tmp-score
3373                                  gnus-tmp-process)
3374   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3375          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3376          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3377          (gnus-tmp-score-char
3378           (if (or (null gnus-summary-default-score)
3379                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3380                       gnus-summary-zcore-fuzz))
3381               ?\ ;;;Whitespace
3382             (if (< gnus-tmp-score gnus-summary-default-score)
3383                 gnus-score-below-mark gnus-score-over-mark)))
3384          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3385          (gnus-tmp-replied
3386           (cond (gnus-tmp-process gnus-process-mark)
3387                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3388                  gnus-cached-mark)
3389                 (gnus-tmp-replied gnus-replied-mark)
3390                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3391                  gnus-forwarded-mark)
3392                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3393                  gnus-saved-mark)
3394                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3395                  gnus-recent-mark)
3396                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3397                  gnus-unseen-mark)
3398                 (t gnus-no-mark)))
3399          (gnus-tmp-downloaded
3400           (cond (undownloaded
3401                  gnus-undownloaded-mark)
3402                 (gnus-newsgroup-agentized
3403                  gnus-downloaded-mark)
3404                 (t
3405                  gnus-no-mark)))
3406          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3407          (gnus-tmp-name
3408           (cond
3409            ((string-match "<[^>]+> *$" gnus-tmp-from)
3410             (let ((beg (match-beginning 0)))
3411               (or (and (string-match "^\".+\"" gnus-tmp-from)
3412                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3413                   (substring gnus-tmp-from 0 beg))))
3414            ((string-match "(.+)" gnus-tmp-from)
3415             (substring gnus-tmp-from
3416                        (1+ (match-beginning 0)) (1- (match-end 0))))
3417            (t gnus-tmp-from)))
3418          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3419          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3420          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3421          (buffer-read-only nil))
3422     (when (string= gnus-tmp-name "")
3423       (setq gnus-tmp-name gnus-tmp-from))
3424     (unless (numberp gnus-tmp-lines)
3425       (setq gnus-tmp-lines -1))
3426     (if (= gnus-tmp-lines -1)
3427         (setq gnus-tmp-lines "?")
3428       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3429     (gnus-put-text-property-excluding-characters-with-faces
3430      (point)
3431      (progn (eval gnus-summary-line-format-spec) (point))
3432      'gnus-number gnus-tmp-number)
3433     (when (gnus-visual-p 'summary-highlight 'highlight)
3434       (forward-line -1)
3435       (gnus-run-hooks 'gnus-summary-update-hook)
3436       (forward-line 1))))
3437
3438 (defun gnus-summary-update-line (&optional dont-update)
3439   "Update summary line after change."
3440   (when (and gnus-summary-default-score
3441              (not gnus-summary-inhibit-highlight))
3442     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3443            (article (gnus-summary-article-number))
3444            (score (gnus-summary-article-score article)))
3445       (unless dont-update
3446         (if (and gnus-summary-mark-below
3447                  (< (gnus-summary-article-score)
3448                     gnus-summary-mark-below))
3449             ;; This article has a low score, so we mark it as read.
3450             (when (memq article gnus-newsgroup-unreads)
3451               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3452           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3453             ;; This article was previously marked as read on account
3454             ;; of a low score, but now it has risen, so we mark it as
3455             ;; unread.
3456             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3457         (gnus-summary-update-mark
3458          (if (or (null gnus-summary-default-score)
3459                  (<= (abs (- score gnus-summary-default-score))
3460                      gnus-summary-zcore-fuzz))
3461              ?\ ;;;Whitespace
3462            (if (< score gnus-summary-default-score)
3463                gnus-score-below-mark gnus-score-over-mark))
3464          'score))
3465       ;; Do visual highlighting.
3466       (when (gnus-visual-p 'summary-highlight 'highlight)
3467         (gnus-run-hooks 'gnus-summary-update-hook)))))
3468
3469 (defvar gnus-tmp-new-adopts nil)
3470
3471 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3472   "Return the number of articles in THREAD.
3473 This may be 0 in some cases -- if none of the articles in
3474 the thread are to be displayed."
3475   (let* ((number
3476           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3477           (cond
3478            ((not (listp thread))
3479             1)
3480            ((and (consp thread) (cdr thread))
3481             (apply
3482              '+ 1 (mapcar
3483                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3484            ((null thread)
3485             1)
3486            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3487             1)
3488            (t 0))))
3489     (when (and level (zerop level) gnus-tmp-new-adopts)
3490       (incf number
3491             (apply '+ (mapcar
3492                        'gnus-summary-number-of-articles-in-thread
3493                        gnus-tmp-new-adopts))))
3494     (if char
3495         (if (> number 1) gnus-not-empty-thread-mark
3496           gnus-empty-thread-mark)
3497       number)))
3498
3499 (defsubst gnus-summary-line-message-size (head)
3500   "Return pretty-printed version of message size.
3501 This function is intended to be used in
3502 `gnus-summary-line-format-alist'."
3503   (let ((c (or (mail-header-chars head) -1)))
3504     (cond ((< c 0) "n/a")               ; chars not available
3505           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3506           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3507           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3508           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3509
3510
3511 (defun gnus-summary-set-local-parameters (group)
3512   "Go through the local params of GROUP and set all variable specs in that list."
3513   (let ((vars '(quit-config)))          ; Ignore quit-config.
3514     (dolist (elem (gnus-group-find-parameter group))
3515       (and (consp elem)                 ; Has to be a cons.
3516            (consp (cdr elem))           ; The cdr has to be a list.
3517            (symbolp (car elem))         ; Has to be a symbol in there.
3518            (not (memq (car elem) vars))
3519            (ignore-errors               ; So we set it.
3520              (push (car elem) vars)
3521              (make-local-variable (car elem))
3522              (set (car elem) (eval (nth 1 elem))))))))
3523
3524 (defun gnus-summary-read-group (group &optional show-all no-article
3525                                       kill-buffer no-display backward
3526                                       select-articles)
3527   "Start reading news in newsgroup GROUP.
3528 If SHOW-ALL is non-nil, already read articles are also listed.
3529 If NO-ARTICLE is non-nil, no article is selected initially.
3530 If NO-DISPLAY, don't generate a summary buffer."
3531   (let (result)
3532     (while (and group
3533                 (null (setq result
3534                             (let ((gnus-auto-select-next nil))
3535                               (or (gnus-summary-read-group-1
3536                                    group show-all no-article
3537                                    kill-buffer no-display
3538                                    select-articles)
3539                                   (setq show-all nil
3540                                         select-articles nil)))))
3541                 (eq gnus-auto-select-next 'quietly))
3542       (set-buffer gnus-group-buffer)
3543       ;; The entry function called above goes to the next
3544       ;; group automatically, so we go two groups back
3545       ;; if we are searching for the previous group.
3546       (when backward
3547         (gnus-group-prev-unread-group 2))
3548       (if (not (equal group (gnus-group-group-name)))
3549           (setq group (gnus-group-group-name))
3550         (setq group nil)))
3551     result))
3552
3553 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3554   "Directly jump to the other GROUP from summary buffer.
3555 If SHOW-ALL is non-nil, already read articles are also listed."
3556   (interactive
3557    (if (eq gnus-summary-buffer (current-buffer))
3558        (list (completing-read
3559               "Group: " gnus-active-hashtb nil t
3560               (when (and gnus-newsgroup-name
3561                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3562                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3563               'gnus-group-history)
3564              current-prefix-arg)
3565      (error "%s must be invoked from a gnus summary buffer." this-command)))
3566   (unless (or (zerop (length group))
3567               (and gnus-newsgroup-name
3568                    (string-equal gnus-newsgroup-name group)))
3569     (gnus-summary-exit)
3570     (gnus-summary-read-group group show-all
3571                              gnus-dont-select-after-jump-to-other-group)))
3572
3573 (defun gnus-summary-read-group-1 (group show-all no-article
3574                                         kill-buffer no-display
3575                                         &optional select-articles)
3576   ;; Killed foreign groups can't be entered.
3577   ;;  (when (and (not (gnus-group-native-p group))
3578   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3579   ;;    (error "Dead non-native groups can't be entered"))
3580   (gnus-message 5 "Retrieving newsgroup: %s..."
3581                 (gnus-group-decoded-name group))
3582   (let* ((new-group (gnus-summary-setup-buffer group))
3583          (quit-config (gnus-group-quit-config group))
3584          (did-select (and new-group (gnus-select-newsgroup
3585                                      group show-all select-articles))))
3586     (cond
3587      ;; This summary buffer exists already, so we just select it.
3588      ((not new-group)
3589       (gnus-set-global-variables)
3590       (when kill-buffer
3591         (gnus-kill-or-deaden-summary kill-buffer))
3592       (gnus-configure-windows 'summary 'force)
3593       (gnus-set-mode-line 'summary)
3594       (gnus-summary-position-point)
3595       (message "")
3596       t)
3597      ;; We couldn't select this group.
3598      ((null did-select)
3599       (when (and (eq major-mode 'gnus-summary-mode)
3600                  (not (equal (current-buffer) kill-buffer)))
3601         (kill-buffer (current-buffer))
3602         (if (not quit-config)
3603             (progn
3604               ;; Update the info -- marks might need to be removed,
3605               ;; for instance.
3606               (gnus-summary-update-info)
3607               (set-buffer gnus-group-buffer)
3608               (gnus-group-jump-to-group group)
3609               (gnus-group-next-unread-group 1))
3610           (gnus-handle-ephemeral-exit quit-config)))
3611       (let ((grpinfo (gnus-get-info group)))
3612         (if (null (gnus-info-read grpinfo))
3613             (gnus-message 3 "Group %s contains no messages"
3614                           (gnus-group-decoded-name group))
3615           (gnus-message 3 "Can't select group")))
3616       nil)
3617      ;; The user did a `C-g' while prompting for number of articles,
3618      ;; so we exit this group.
3619      ((eq did-select 'quit)
3620       (and (eq major-mode 'gnus-summary-mode)
3621            (not (equal (current-buffer) kill-buffer))
3622            (kill-buffer (current-buffer)))
3623       (when kill-buffer
3624         (gnus-kill-or-deaden-summary kill-buffer))
3625       (if (not quit-config)
3626           (progn
3627             (set-buffer gnus-group-buffer)
3628             (gnus-group-jump-to-group group)
3629             (gnus-group-next-unread-group 1)
3630             (gnus-configure-windows 'group 'force))
3631         (gnus-handle-ephemeral-exit quit-config))
3632       ;; Finally signal the quit.
3633       (signal 'quit nil))
3634      ;; The group was successfully selected.
3635      (t
3636       (gnus-set-global-variables)
3637       ;; Save the active value in effect when the group was entered.
3638       (setq gnus-newsgroup-active
3639             (gnus-copy-sequence
3640              (gnus-active gnus-newsgroup-name)))
3641       ;; You can change the summary buffer in some way with this hook.
3642       (gnus-run-hooks 'gnus-select-group-hook)
3643       (when (memq 'summary (gnus-update-format-specifications
3644                             nil 'summary 'summary-mode 'summary-dummy))
3645         ;; The format specification for the summary line was updated,
3646         ;; so we need to update the mark positions as well.
3647         (gnus-update-summary-mark-positions))
3648       ;; Do score processing.
3649       (when gnus-use-scoring
3650         (gnus-possibly-score-headers))
3651       ;; Check whether to fill in the gaps in the threads.
3652       (when gnus-build-sparse-threads
3653         (gnus-build-sparse-threads))
3654       ;; Find the initial limit.
3655       (if show-all
3656           (let ((gnus-newsgroup-dormant nil))
3657             (gnus-summary-initial-limit show-all))
3658         (gnus-summary-initial-limit show-all))
3659       ;; Generate the summary buffer.
3660       (unless no-display
3661         (gnus-summary-prepare))
3662       (when gnus-use-trees
3663         (gnus-tree-open group)
3664         (setq gnus-summary-highlight-line-function
3665               'gnus-tree-highlight-article))
3666       ;; If the summary buffer is empty, but there are some low-scored
3667       ;; articles or some excluded dormants, we include these in the
3668       ;; buffer.
3669       (when (and (zerop (buffer-size))
3670                  (not no-display))
3671         (cond (gnus-newsgroup-dormant
3672                (gnus-summary-limit-include-dormant))
3673               ((and gnus-newsgroup-scored show-all)
3674                (gnus-summary-limit-include-expunged t))))
3675       ;; Function `gnus-apply-kill-file' must be called in this hook.
3676       (gnus-run-hooks 'gnus-apply-kill-hook)
3677       (if (and (zerop (buffer-size))
3678                (not no-display))
3679           (progn
3680             ;; This newsgroup is empty.
3681             (gnus-summary-catchup-and-exit nil t)
3682             (gnus-message 6 "No unread news")
3683             (when kill-buffer
3684               (gnus-kill-or-deaden-summary kill-buffer))
3685             ;; Return nil from this function.
3686             nil)
3687         ;; Hide conversation thread subtrees.  We cannot do this in
3688         ;; gnus-summary-prepare-hook since kill processing may not
3689         ;; work with hidden articles.
3690         (gnus-summary-maybe-hide-threads)
3691         (when kill-buffer
3692           (gnus-kill-or-deaden-summary kill-buffer))
3693         (gnus-summary-auto-select-subject)
3694         ;; Show first unread article if requested.
3695         (if (and (not no-article)
3696                  (not no-display)
3697                  gnus-newsgroup-unreads
3698                  gnus-auto-select-first)
3699             (progn
3700               (gnus-configure-windows 'summary)
3701               (let ((art (gnus-summary-article-number)))
3702                 (unless (and (not gnus-plugged)
3703                              (or (memq art gnus-newsgroup-undownloaded)
3704                                  (memq art gnus-newsgroup-downloadable)))
3705                   (gnus-summary-goto-article art))))
3706           ;; Don't select any articles.
3707           (gnus-summary-position-point)
3708           (gnus-configure-windows 'summary 'force)
3709           (gnus-set-mode-line 'summary))
3710         (when (and gnus-auto-center-group
3711                    (get-buffer-window gnus-group-buffer t))
3712           ;; Gotta use windows, because recenter does weird stuff if
3713           ;; the current buffer ain't the displayed window.
3714           (let ((owin (selected-window)))
3715             (select-window (get-buffer-window gnus-group-buffer t))
3716             (when (gnus-group-goto-group group)
3717               (recenter))
3718             (select-window owin)))
3719         ;; Mark this buffer as "prepared".
3720         (setq gnus-newsgroup-prepared t)
3721         (gnus-run-hooks 'gnus-summary-prepared-hook)
3722         (unless (gnus-ephemeral-group-p group)
3723           (gnus-group-update-group group))
3724         t)))))
3725
3726 (defun gnus-summary-auto-select-subject ()
3727   "Select the subject line on initial group entry."
3728   (goto-char (point-min))
3729   (cond
3730    ((eq gnus-auto-select-subject 'best)
3731     (gnus-summary-best-unread-subject))
3732    ((eq gnus-auto-select-subject 'unread)
3733     (gnus-summary-first-unread-subject))
3734    ((eq gnus-auto-select-subject 'unseen)
3735     (gnus-summary-first-unseen-subject))
3736    ((eq gnus-auto-select-subject 'unseen-or-unread)
3737     (gnus-summary-first-unseen-or-unread-subject))
3738    ((eq gnus-auto-select-subject 'first)
3739     ;; Do nothing.
3740     )
3741    ((functionp gnus-auto-select-subject)
3742     (funcall gnus-auto-select-subject))))
3743
3744 (defun gnus-summary-prepare ()
3745   "Generate the summary buffer."
3746   (interactive)
3747   (let ((buffer-read-only nil))
3748     (erase-buffer)
3749     (setq gnus-newsgroup-data nil
3750           gnus-newsgroup-data-reverse nil)
3751     (gnus-run-hooks 'gnus-summary-generate-hook)
3752     ;; Generate the buffer, either with threads or without.
3753     (when gnus-newsgroup-headers
3754       (gnus-summary-prepare-threads
3755        (if gnus-show-threads
3756            (gnus-sort-gathered-threads
3757             (funcall gnus-summary-thread-gathering-function
3758                      (gnus-sort-threads
3759                       (gnus-cut-threads (gnus-make-threads)))))
3760          ;; Unthreaded display.
3761          (gnus-sort-articles gnus-newsgroup-headers))))
3762     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3763     ;; Call hooks for modifying summary buffer.
3764     (goto-char (point-min))
3765     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3766
3767 (defsubst gnus-general-simplify-subject (subject)
3768   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3769   (setq subject
3770         (cond
3771          ;; Truncate the subject.
3772          (gnus-simplify-subject-functions
3773           (gnus-map-function gnus-simplify-subject-functions subject))
3774          ((numberp gnus-summary-gather-subject-limit)
3775           (setq subject (gnus-simplify-subject-re subject))
3776           (if (> (length subject) gnus-summary-gather-subject-limit)
3777               (substring subject 0 gnus-summary-gather-subject-limit)
3778             subject))
3779          ;; Fuzzily simplify it.
3780          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3781           (gnus-simplify-subject-fuzzy subject))
3782          ;; Just remove the leading "Re:".
3783          (t
3784           (gnus-simplify-subject-re subject))))
3785
3786   (if (and gnus-summary-gather-exclude-subject
3787            (string-match gnus-summary-gather-exclude-subject subject))
3788       nil                               ; This article shouldn't be gathered
3789     subject))
3790
3791 (defun gnus-summary-simplify-subject-query ()
3792   "Query where the respool algorithm would put this article."
3793   (interactive)
3794   (gnus-summary-select-article)
3795   (message "%s"
3796            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3797
3798 (defun gnus-gather-threads-by-subject (threads)
3799   "Gather threads by looking at Subject headers."
3800   (if (not gnus-summary-make-false-root)
3801       threads
3802     (let ((hashtb (gnus-make-hashtable 1024))
3803           (prev threads)
3804           (result threads)
3805           subject hthread whole-subject)
3806       (while threads
3807         (setq subject (gnus-general-simplify-subject
3808                        (setq whole-subject (mail-header-subject
3809                                             (caar threads)))))
3810         (when subject
3811           (if (setq hthread (gnus-gethash subject hashtb))
3812               (progn
3813                 ;; We enter a dummy root into the thread, if we
3814                 ;; haven't done that already.
3815                 (unless (stringp (caar hthread))
3816                   (setcar hthread (list whole-subject (car hthread))))
3817                 ;; We add this new gathered thread to this gathered
3818                 ;; thread.
3819                 (setcdr (car hthread)
3820                         (nconc (cdar hthread) (list (car threads))))
3821                 ;; Remove it from the list of threads.
3822                 (setcdr prev (cdr threads))
3823                 (setq threads prev))
3824             ;; Enter this thread into the hash table.
3825             (gnus-sethash subject
3826                           (if gnus-summary-make-false-root-always
3827                               (progn
3828                                 ;; If you want a dummy root above all
3829                                 ;; threads...
3830                                 (setcar threads (list whole-subject
3831                                                       (car threads)))
3832                                 threads)
3833                             threads)
3834                           hashtb)))
3835         (setq prev threads)
3836         (setq threads (cdr threads)))
3837       result)))
3838
3839 (defun gnus-gather-threads-by-references (threads)
3840   "Gather threads by looking at References headers."
3841   (let ((idhashtb (gnus-make-hashtable 1024))
3842         (thhashtb (gnus-make-hashtable 1024))
3843         (prev threads)
3844         (result threads)
3845         ids references id gthread gid entered ref)
3846     (while threads
3847       (when (setq references (mail-header-references (caar threads)))
3848         (setq id (mail-header-id (caar threads))
3849               ids (inline (gnus-split-references references))
3850               entered nil)
3851         (while (setq ref (pop ids))
3852           (setq ids (delete ref ids))
3853           (if (not (setq gid (gnus-gethash ref idhashtb)))
3854               (progn
3855                 (gnus-sethash ref id idhashtb)
3856                 (gnus-sethash id threads thhashtb))
3857             (setq gthread (gnus-gethash gid thhashtb))
3858             (unless entered
3859               ;; We enter a dummy root into the thread, if we
3860               ;; haven't done that already.
3861               (unless (stringp (caar gthread))
3862                 (setcar gthread (list (mail-header-subject (caar gthread))
3863                                       (car gthread))))
3864               ;; We add this new gathered thread to this gathered
3865               ;; thread.
3866               (setcdr (car gthread)
3867                       (nconc (cdar gthread) (list (car threads)))))
3868             ;; Add it into the thread hash table.
3869             (gnus-sethash id gthread thhashtb)
3870             (setq entered t)
3871             ;; Remove it from the list of threads.
3872             (setcdr prev (cdr threads))
3873             (setq threads prev))))
3874       (setq prev threads)
3875       (setq threads (cdr threads)))
3876     result))
3877
3878 (defun gnus-sort-gathered-threads (threads)
3879   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3880   (let ((result threads))
3881     (while threads
3882       (when (stringp (caar threads))
3883         (setcdr (car threads)
3884                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3885       (setq threads (cdr threads)))
3886     result))
3887
3888 (defun gnus-thread-loop-p (root thread)
3889   "Say whether ROOT is in THREAD."
3890   (let ((stack (list thread))
3891         (infloop 0)
3892         th)
3893     (while (setq thread (pop stack))
3894       (setq th (cdr thread))
3895       (while (and th
3896                   (not (eq (caar th) root)))
3897         (pop th))
3898       (if th
3899           ;; We have found a loop.
3900           (let (ref-dep)
3901             (setcdr thread (delq (car th) (cdr thread)))
3902             (if (boundp (setq ref-dep (intern "none"
3903                                               gnus-newsgroup-dependencies)))
3904                 (setcdr (symbol-value ref-dep)
3905                         (nconc (cdr (symbol-value ref-dep))
3906                                (list (car th))))
3907               (set ref-dep (list nil (car th))))
3908             (setq infloop 1
3909                   stack nil))
3910         ;; Push all the subthreads onto the stack.
3911         (push (cdr thread) stack)))
3912     infloop))
3913
3914 (defun gnus-make-threads ()
3915   "Go through the dependency hashtb and find the roots.  Return all threads."
3916   (let (threads)
3917     (while (catch 'infloop
3918              (mapatoms
3919               (lambda (refs)
3920                 ;; Deal with self-referencing References loops.
3921                 (when (and (car (symbol-value refs))
3922                            (not (zerop
3923                                  (apply
3924                                   '+
3925                                   (mapcar
3926                                    (lambda (thread)
3927                                      (gnus-thread-loop-p
3928                                       (car (symbol-value refs)) thread))
3929                                    (cdr (symbol-value refs)))))))
3930                   (setq threads nil)
3931                   (throw 'infloop t))
3932                 (unless (car (symbol-value refs))
3933                   ;; These threads do not refer back to any other articles,
3934                   ;; so they're roots.
3935                   (setq threads (append (cdr (symbol-value refs)) threads))))
3936               gnus-newsgroup-dependencies)))
3937     threads))
3938
3939 ;; Build the thread tree.
3940 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3941   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3942
3943 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3944 if it was already present.
3945
3946 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3947 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3948 Message-IDs will be renamed to a unique Message-ID before being
3949 entered.
3950
3951 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3952   (let* ((id (mail-header-id header))
3953          (id-dep (and id (intern id dependencies)))
3954          parent-id ref ref-dep ref-header replaced)
3955     ;; Enter this `header' in the `dependencies' table.
3956     (cond
3957      ((not id-dep)
3958       (setq header nil))
3959      ;; The first two cases do the normal part: enter a new `header'
3960      ;; in the `dependencies' table.
3961      ((not (boundp id-dep))
3962       (set id-dep (list header)))
3963      ((null (car (symbol-value id-dep)))
3964       (setcar (symbol-value id-dep) header))
3965
3966      ;; From here the `header' was already present in the
3967      ;; `dependencies' table.
3968      (force-new
3969       ;; Overrides an existing entry;
3970       ;; just set the header part of the entry.
3971       (setcar (symbol-value id-dep) header)
3972       (setq replaced t))
3973
3974      ;; Renames the existing `header' to a unique Message-ID.
3975      ((not gnus-summary-ignore-duplicates)
3976       ;; An article with this Message-ID has already been seen.
3977       ;; We rename the Message-ID.
3978       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3979            (list header))
3980       (mail-header-set-id header id))
3981
3982      ;; The last case ignores an existing entry, except it adds any
3983      ;; additional Xrefs (in case the two articles came from different
3984      ;; servers.
3985      ;; Also sets `header' to `nil' meaning that the `dependencies'
3986      ;; table was *not* modified.
3987      (t
3988       (mail-header-set-xref
3989        (car (symbol-value id-dep))
3990        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3991                    "")
3992                (or (mail-header-xref header) "")))
3993       (setq header nil)))
3994
3995     (when (and header (not replaced))
3996       ;; First check that we are not creating a References loop.
3997       (setq parent-id (gnus-parent-id (mail-header-references header)))
3998       (setq ref parent-id)
3999       (while (and ref
4000                   (setq ref-dep (intern-soft ref dependencies))
4001                   (boundp ref-dep)
4002                   (setq ref-header (car (symbol-value ref-dep))))
4003         (if (string= id ref)
4004             ;; Yuk!  This is a reference loop.  Make the article be a
4005             ;; root article.
4006             (progn
4007               (mail-header-set-references (car (symbol-value id-dep)) "none")
4008               (setq ref nil)
4009               (setq parent-id nil))
4010           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4011       (setq ref-dep (intern (or parent-id "none") dependencies))
4012       (if (boundp ref-dep)
4013           (setcdr (symbol-value ref-dep)
4014                   (nconc (cdr (symbol-value ref-dep))
4015                          (list (symbol-value id-dep))))
4016         (set ref-dep (list nil (symbol-value id-dep)))))
4017     header))
4018
4019 (defun gnus-extract-message-id-from-in-reply-to (string)
4020   (if (string-match "<[^>]+>" string)
4021       (substring string (match-beginning 0) (match-end 0))
4022     nil))
4023
4024 (defun gnus-build-sparse-threads ()
4025   (let ((headers gnus-newsgroup-headers)
4026         (mail-parse-charset gnus-newsgroup-charset)
4027         (gnus-summary-ignore-duplicates t)
4028         header references generation relations
4029         subject child end new-child date)
4030     ;; First we create an alist of generations/relations, where
4031     ;; generations is how much we trust the relation, and the relation
4032     ;; is parent/child.
4033     (gnus-message 7 "Making sparse threads...")
4034     (save-excursion
4035       (nnheader-set-temp-buffer " *gnus sparse threads*")
4036       (while (setq header (pop headers))
4037         (when (and (setq references (mail-header-references header))
4038                    (not (string= references "")))
4039           (insert references)
4040           (setq child (mail-header-id header)
4041                 subject (mail-header-subject header)
4042                 date (mail-header-date header)
4043                 generation 0)
4044           (while (search-backward ">" nil t)
4045             (setq end (1+ (point)))
4046             (when (search-backward "<" nil t)
4047               (setq new-child (buffer-substring (point) end))
4048               (push (list (incf generation)
4049                           child (setq child new-child)
4050                           subject date)
4051                     relations)))
4052           (when child
4053             (push (list (1+ generation) child nil subject) relations))
4054           (erase-buffer)))
4055       (kill-buffer (current-buffer)))
4056     ;; Sort over trustworthiness.
4057     (mapcar
4058      (lambda (relation)
4059        (when (gnus-dependencies-add-header
4060               (make-full-mail-header-from-decoded-header
4061                gnus-reffed-article-number
4062                (nth 3 relation) "" (or (nth 4 relation) "")
4063                (nth 1 relation)
4064                (or (nth 2 relation) "") 0 0 "")
4065               gnus-newsgroup-dependencies nil)
4066          (push gnus-reffed-article-number gnus-newsgroup-limit)
4067          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4068          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4069                gnus-newsgroup-reads)
4070          (decf gnus-reffed-article-number)))
4071      (sort relations 'car-less-than-car))
4072     (gnus-message 7 "Making sparse threads...done")))
4073
4074 (defun gnus-build-old-threads ()
4075   ;; Look at all the articles that refer back to old articles, and
4076   ;; fetch the headers for the articles that aren't there.  This will
4077   ;; build complete threads - if the roots haven't been expired by the
4078   ;; server, that is.
4079   (let ((mail-parse-charset gnus-newsgroup-charset)
4080         id heads)
4081     (mapatoms
4082      (lambda (refs)
4083        (when (not (car (symbol-value refs)))
4084          (setq heads (cdr (symbol-value refs)))
4085          (while heads
4086            (if (memq (mail-header-number (caar heads))
4087                      gnus-newsgroup-dormant)
4088                (setq heads (cdr heads))
4089              (setq id (symbol-name refs))
4090              (while (and (setq id (gnus-build-get-header id))
4091                          (not (car (gnus-id-to-thread id)))))
4092              (setq heads nil)))))
4093      gnus-newsgroup-dependencies)))
4094
4095 (defsubst gnus-remove-odd-characters (string)
4096   "Translate STRING into something that doesn't contain weird characters."
4097   (mm-subst-char-in-string
4098    ?\r ?\-
4099    (mm-subst-char-in-string ?\n ?\- string t) t))
4100
4101 ;; This function has to be called with point after the article number
4102 ;; on the beginning of the line.
4103 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4104   (let ((eol (point-at-eol))
4105         (buffer (current-buffer))
4106         header references in-reply-to)
4107
4108     ;; overview: [num subject from date id refs chars lines misc]
4109     (unwind-protect
4110         (progn
4111           (narrow-to-region (point) eol)
4112           (unless (eobp)
4113             (forward-char))
4114
4115           (setq header
4116                 (make-full-mail-header
4117                  number                         ; number
4118                  (nnheader-nov-field)           ; subject
4119                  (nnheader-nov-field)           ; from
4120                  (nnheader-nov-field)           ; date
4121                  (nnheader-nov-read-message-id number)  ; id
4122                  (setq references (nnheader-nov-field)) ; refs
4123                  (nnheader-nov-read-integer)    ; chars
4124                  (nnheader-nov-read-integer)    ; lines
4125                  (unless (eobp)
4126                    (if (looking-at "Xref: ")
4127                        (goto-char (match-end 0)))
4128                    (nnheader-nov-field))        ; Xref
4129                  (nnheader-nov-parse-extra))))  ; extra
4130
4131       (widen))
4132
4133     (when (and (string= references "")
4134                (setq in-reply-to (mail-header-extra header))
4135                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4136       (mail-header-set-references
4137        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4138
4139     (when gnus-alter-header-function
4140       (funcall gnus-alter-header-function header))
4141     (gnus-dependencies-add-header header dependencies force-new)))
4142
4143 (defun gnus-build-get-header (id)
4144   "Look through the buffer of NOV lines and find the header to ID.
4145 Enter this line into the dependencies hash table, and return
4146 the id of the parent article (if any)."
4147   (let ((deps gnus-newsgroup-dependencies)
4148         found header)
4149     (prog1
4150         (save-excursion
4151           (set-buffer nntp-server-buffer)
4152           (let ((case-fold-search nil))
4153             (goto-char (point-min))
4154             (while (and (not found)
4155                         (search-forward id nil t))
4156               (beginning-of-line)
4157               (setq found (looking-at
4158                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4159                                    (regexp-quote id))))
4160               (or found (beginning-of-line 2)))
4161             (when found
4162               (beginning-of-line)
4163               (and
4164                (setq header (gnus-nov-parse-line
4165                              (read (current-buffer)) deps))
4166                (gnus-parent-id (mail-header-references header))))))
4167       (when header
4168         (let ((number (mail-header-number header)))
4169           (push number gnus-newsgroup-limit)
4170           (push header gnus-newsgroup-headers)
4171           (if (memq number gnus-newsgroup-unselected)
4172               (progn
4173                 (setq gnus-newsgroup-unreads
4174                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4175                                                number))
4176                 (setq gnus-newsgroup-unselected
4177                       (delq number gnus-newsgroup-unselected)))
4178             (push number gnus-newsgroup-ancient)))))))
4179
4180 (defun gnus-build-all-threads ()
4181   "Read all the headers."
4182   (let ((gnus-summary-ignore-duplicates t)
4183         (mail-parse-charset gnus-newsgroup-charset)
4184         (dependencies gnus-newsgroup-dependencies)
4185         header article)
4186     (save-excursion
4187       (set-buffer nntp-server-buffer)
4188       (let ((case-fold-search nil))
4189         (goto-char (point-min))
4190         (while (not (eobp))
4191           (ignore-errors
4192             (setq article (read (current-buffer))
4193                   header (gnus-nov-parse-line article dependencies)))
4194           (when header
4195             (with-current-buffer gnus-summary-buffer
4196               (push header gnus-newsgroup-headers)
4197               (if (memq (setq article (mail-header-number header))
4198                         gnus-newsgroup-unselected)
4199                   (progn
4200                     (setq gnus-newsgroup-unreads
4201                           (gnus-add-to-sorted-list
4202                            gnus-newsgroup-unreads article))
4203                     (setq gnus-newsgroup-unselected
4204                           (delq article gnus-newsgroup-unselected)))
4205                 (push article gnus-newsgroup-ancient)))
4206             (forward-line 1)))))))
4207
4208 (defun gnus-summary-update-article-line (article header)
4209   "Update the line for ARTICLE using HEADER."
4210   (let* ((id (mail-header-id header))
4211          (thread (gnus-id-to-thread id)))
4212     (unless thread
4213       (error "Article in no thread"))
4214     ;; Update the thread.
4215     (setcar thread header)
4216     (gnus-summary-goto-subject article)
4217     (let* ((datal (gnus-data-find-list article))
4218            (data (car datal))
4219            (buffer-read-only nil)
4220            (level (gnus-summary-thread-level)))
4221       (gnus-delete-line)
4222       (let ((inserted (- (point)
4223                          (progn
4224                            (gnus-summary-insert-line
4225                             header level nil
4226                             (memq article gnus-newsgroup-undownloaded)
4227                             (gnus-article-mark article)
4228                             (memq article gnus-newsgroup-replied)
4229                             (memq article gnus-newsgroup-expirable)
4230                             ;; Only insert the Subject string when it's different
4231                             ;; from the previous Subject string.
4232                             (if (and
4233                                  gnus-show-threads
4234                                  (gnus-subject-equal
4235                                   (condition-case ()
4236                                       (mail-header-subject
4237                                        (gnus-data-header
4238                                         (cadr
4239                                          (gnus-data-find-list
4240                                           article
4241                                           (gnus-data-list t)))))
4242                                     ;; Error on the side of excessive subjects.
4243                                     (error ""))
4244                                   (mail-header-subject header)))
4245                                 ""
4246                               (mail-header-subject header))
4247                             nil (cdr (assq article gnus-newsgroup-scored))
4248                             (memq article gnus-newsgroup-processable))
4249                            (point)))))
4250         (when (cdr datal)
4251           (gnus-data-update-list
4252            (cdr datal)
4253            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4254
4255 (defun gnus-summary-update-article (article &optional iheader)
4256   "Update ARTICLE in the summary buffer."
4257   (set-buffer gnus-summary-buffer)
4258   (let* ((header (gnus-summary-article-header article))
4259          (id (mail-header-id header))
4260          (data (gnus-data-find article))
4261          (thread (gnus-id-to-thread id))
4262          (references (mail-header-references header))
4263          (parent
4264           (gnus-id-to-thread
4265            (or (gnus-parent-id
4266                 (when (and references
4267                            (not (equal "" references)))
4268                   references))
4269                "none")))
4270          (buffer-read-only nil)
4271          (old (car thread)))
4272     (when thread
4273       (unless iheader
4274         (setcar thread nil)
4275         (when parent
4276           (delq thread parent)))
4277       (if (gnus-summary-insert-subject id header)
4278           ;; Set the (possibly) new article number in the data structure.
4279           (gnus-data-set-number data (gnus-id-to-article id))
4280         (setcar thread old)
4281         nil))))
4282
4283 (defun gnus-rebuild-thread (id &optional line)
4284   "Rebuild the thread containing ID.
4285 If LINE, insert the rebuilt thread starting on line LINE."
4286   (let ((buffer-read-only nil)
4287         old-pos current thread data)
4288     (if (not gnus-show-threads)
4289         (setq thread (list (car (gnus-id-to-thread id))))
4290       ;; Get the thread this article is part of.
4291       (setq thread (gnus-remove-thread id)))
4292     (setq old-pos (point-at-bol))
4293     (setq current (save-excursion
4294                     (and (re-search-backward "[\r\n]" nil t)
4295                          (gnus-summary-article-number))))
4296     ;; If this is a gathered thread, we have to go some re-gathering.
4297     (when (stringp (car thread))
4298       (let ((subject (car thread))
4299             roots thr)
4300         (setq thread (cdr thread))
4301         (while thread
4302           (unless (memq (setq thr (gnus-id-to-thread
4303                                    (gnus-root-id
4304                                     (mail-header-id (caar thread)))))
4305                         roots)
4306             (push thr roots))
4307           (setq thread (cdr thread)))
4308         ;; We now have all (unique) roots.
4309         (if (= (length roots) 1)
4310             ;; All the loose roots are now one solid root.
4311             (setq thread (car roots))
4312           (setq thread (cons subject (gnus-sort-threads roots))))))
4313     (let (threads)
4314       ;; We then insert this thread into the summary buffer.
4315       (when line
4316         (goto-char (point-min))
4317         (forward-line (1- line)))
4318       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4319         (if gnus-show-threads
4320             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4321           (gnus-summary-prepare-unthreaded thread))
4322         (setq data (nreverse gnus-newsgroup-data))
4323         (setq threads gnus-newsgroup-threads))
4324       ;; We splice the new data into the data structure.
4325       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4326       ;;!!! then we want to insert at the beginning of the buffer.
4327       ;;!!! That happens to be true with Gnus now, but that may
4328       ;;!!! change in the future.  Perhaps.
4329       (gnus-data-enter-list
4330        (if line nil current) data (- (point) old-pos))
4331       (setq gnus-newsgroup-threads
4332             (nconc threads gnus-newsgroup-threads))
4333       (gnus-data-compute-positions))))
4334
4335 (defun gnus-number-to-header (number)
4336   "Return the header for article NUMBER."
4337   (let ((headers gnus-newsgroup-headers))
4338     (while (and headers
4339                 (not (= number (mail-header-number (car headers)))))
4340       (pop headers))
4341     (when headers
4342       (car headers))))
4343
4344 (defun gnus-parent-headers (in-headers &optional generation)
4345   "Return the headers of the GENERATIONeth parent of HEADERS."
4346   (unless generation
4347     (setq generation 1))
4348   (let ((parent t)
4349         (headers in-headers)
4350         references)
4351     (while (and parent
4352                 (not (zerop generation))
4353                 (setq references (mail-header-references headers)))
4354       (setq headers (if (and references
4355                              (setq parent (gnus-parent-id references)))
4356                         (car (gnus-id-to-thread parent))
4357                       nil))
4358       (decf generation))
4359     (and (not (eq headers in-headers))
4360          headers)))
4361
4362 (defun gnus-id-to-thread (id)
4363   "Return the (sub-)thread where ID appears."
4364   (gnus-gethash id gnus-newsgroup-dependencies))
4365
4366 (defun gnus-id-to-article (id)
4367   "Return the article number of ID."
4368   (let ((thread (gnus-id-to-thread id)))
4369     (when (and thread
4370                (car thread))
4371       (mail-header-number (car thread)))))
4372
4373 (defun gnus-id-to-header (id)
4374   "Return the article headers of ID."
4375   (car (gnus-id-to-thread id)))
4376
4377 (defun gnus-article-displayed-root-p (article)
4378   "Say whether ARTICLE is a root(ish) article."
4379   (let ((level (gnus-summary-thread-level article))
4380         (refs (mail-header-references  (gnus-summary-article-header article)))
4381         particle)
4382     (cond
4383      ((null level) nil)
4384      ((zerop level) t)
4385      ((null refs) t)
4386      ((null (gnus-parent-id refs)) t)
4387      ((and (= 1 level)
4388            (null (setq particle (gnus-id-to-article
4389                                  (gnus-parent-id refs))))
4390            (null (gnus-summary-thread-level particle)))))))
4391
4392 (defun gnus-root-id (id)
4393   "Return the id of the root of the thread where ID appears."
4394   (let (last-id prev)
4395     (while (and id (setq prev (car (gnus-id-to-thread id))))
4396       (setq last-id id
4397             id (gnus-parent-id (mail-header-references prev))))
4398     last-id))
4399
4400 (defun gnus-articles-in-thread (thread)
4401   "Return the list of articles in THREAD."
4402   (cons (mail-header-number (car thread))
4403         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4404
4405 (defun gnus-remove-thread (id &optional dont-remove)
4406   "Remove the thread that has ID in it."
4407   (let (headers thread last-id)
4408     ;; First go up in this thread until we find the root.
4409     (setq last-id (gnus-root-id id)
4410           headers (message-flatten-list (gnus-id-to-thread last-id)))
4411     ;; We have now found the real root of this thread.  It might have
4412     ;; been gathered into some loose thread, so we have to search
4413     ;; through the threads to find the thread we wanted.
4414     (let ((threads gnus-newsgroup-threads)
4415           sub)
4416       (while threads
4417         (setq sub (car threads))
4418         (if (stringp (car sub))
4419             ;; This is a gathered thread, so we look at the roots
4420             ;; below it to find whether this article is in this
4421             ;; gathered root.
4422             (progn
4423               (setq sub (cdr sub))
4424               (while sub
4425                 (when (member (caar sub) headers)
4426                   (setq thread (car threads)
4427                         threads nil
4428                         sub nil))
4429                 (setq sub (cdr sub))))
4430           ;; It's an ordinary thread, so we check it.
4431           (when (eq (car sub) (car headers))
4432             (setq thread sub
4433                   threads nil)))
4434         (setq threads (cdr threads)))
4435       ;; If this article is in no thread, then it's a root.
4436       (if thread
4437           (unless dont-remove
4438             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4439         (setq thread (gnus-id-to-thread last-id)))
4440       (when thread
4441         (prog1
4442             thread                      ; We return this thread.
4443           (unless dont-remove
4444             (if (stringp (car thread))
4445                 (progn
4446                   ;; If we use dummy roots, then we have to remove the
4447                   ;; dummy root as well.
4448                   (when (eq gnus-summary-make-false-root 'dummy)
4449                     ;; We go to the dummy root by going to
4450                     ;; the first sub-"thread", and then one line up.
4451                     (gnus-summary-goto-article
4452                      (mail-header-number (caadr thread)))
4453                     (forward-line -1)
4454                     (gnus-delete-line)
4455                     (gnus-data-compute-positions))
4456                   (setq thread (cdr thread))
4457                   (while thread
4458                     (gnus-remove-thread-1 (car thread))
4459                     (setq thread (cdr thread))))
4460               (gnus-remove-thread-1 thread))))))))
4461
4462 (defun gnus-remove-thread-1 (thread)
4463   "Remove the thread THREAD recursively."
4464   (let ((number (mail-header-number (pop thread)))
4465         d)
4466     (setq thread (reverse thread))
4467     (while thread
4468       (gnus-remove-thread-1 (pop thread)))
4469     (when (setq d (gnus-data-find number))
4470       (goto-char (gnus-data-pos d))
4471       (gnus-summary-show-thread)
4472       (gnus-data-remove
4473        number
4474        (- (point-at-bol)
4475           (prog1
4476               (1+ (point-at-eol))
4477             (gnus-delete-line)))))))
4478
4479 (defun gnus-sort-threads-1 (threads func)
4480   (sort (mapcar (lambda (thread)
4481                   (cons (car thread)
4482                         (and (cdr thread)
4483                              (gnus-sort-threads-1 (cdr thread) func))))
4484                 threads) func))
4485
4486 (defun gnus-sort-threads (threads)
4487   "Sort THREADS."
4488   (if (not gnus-thread-sort-functions)
4489       threads
4490     (gnus-message 8 "Sorting threads...")
4491     (let ((max-lisp-eval-depth 5000))
4492       (prog1 (gnus-sort-threads-1
4493          threads
4494          (gnus-make-sort-function gnus-thread-sort-functions))
4495         (gnus-message 8 "Sorting threads...done")))))
4496
4497 (defun gnus-sort-articles (articles)
4498   "Sort ARTICLES."
4499   (when gnus-article-sort-functions
4500     (gnus-message 7 "Sorting articles...")
4501     (prog1
4502         (setq gnus-newsgroup-headers
4503               (sort articles (gnus-make-sort-function
4504                               gnus-article-sort-functions)))
4505       (gnus-message 7 "Sorting articles...done"))))
4506
4507 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4508 (defmacro gnus-thread-header (thread)
4509   "Return header of first article in THREAD.
4510 Note that THREAD must never, ever be anything else than a variable -
4511 using some other form will lead to serious barfage."
4512   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4513   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4514   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4515         (vector thread) 2))
4516
4517 (defsubst gnus-article-sort-by-number (h1 h2)
4518   "Sort articles by article number."
4519   (< (mail-header-number h1)
4520      (mail-header-number h2)))
4521
4522 (defun gnus-thread-sort-by-number (h1 h2)
4523   "Sort threads by root article number."
4524   (gnus-article-sort-by-number
4525    (gnus-thread-header h1) (gnus-thread-header h2)))
4526
4527 (defsubst gnus-article-sort-by-random (h1 h2)
4528   "Sort articles by article number."
4529   (zerop (random 2)))
4530
4531 (defun gnus-thread-sort-by-random (h1 h2)
4532   "Sort threads by root article number."
4533   (gnus-article-sort-by-random
4534    (gnus-thread-header h1) (gnus-thread-header h2)))
4535
4536 (defsubst gnus-article-sort-by-lines (h1 h2)
4537   "Sort articles by article Lines header."
4538   (< (mail-header-lines h1)
4539      (mail-header-lines h2)))
4540
4541 (defun gnus-thread-sort-by-lines (h1 h2)
4542   "Sort threads by root article Lines header."
4543   (gnus-article-sort-by-lines
4544    (gnus-thread-header h1) (gnus-thread-header h2)))
4545
4546 (defsubst gnus-article-sort-by-chars (h1 h2)
4547   "Sort articles by octet length."
4548   (< (mail-header-chars h1)
4549      (mail-header-chars h2)))
4550
4551 (defun gnus-thread-sort-by-chars (h1 h2)
4552   "Sort threads by root article octet length."
4553   (gnus-article-sort-by-chars
4554    (gnus-thread-header h1) (gnus-thread-header h2)))
4555
4556 (defsubst gnus-article-sort-by-author (h1 h2)
4557   "Sort articles by root author."
4558   (string-lessp
4559    (let ((addr (car (mime-entity-read-field h1 'From))))
4560      (or (std11-full-name-string addr)
4561          (std11-address-string addr)
4562          ""))
4563    (let ((addr (car (mime-entity-read-field h2 'From))))
4564      (or (std11-full-name-string addr)
4565          (std11-address-string addr)
4566          ""))
4567    ))
4568
4569 (defun gnus-thread-sort-by-author (h1 h2)
4570   "Sort threads by root author."
4571   (gnus-article-sort-by-author
4572    (gnus-thread-header h1)  (gnus-thread-header h2)))
4573
4574 (defsubst gnus-article-sort-by-recipient (h1 h2)
4575   "Sort articles by recipient."
4576   (string-lessp
4577    (let ((extract (funcall
4578                    gnus-extract-address-components
4579                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4580      (or (car extract) (cadr extract)))
4581    (let ((extract (funcall
4582                    gnus-extract-address-components
4583                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4584      (or (car extract) (cadr extract)))))
4585
4586 (defsubst gnus-article-sort-by-subject (h1 h2)
4587   "Sort articles by root subject."
4588   (string-lessp
4589    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4590    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4591
4592 (defun gnus-thread-sort-by-subject (h1 h2)
4593   "Sort threads by root subject."
4594   (gnus-article-sort-by-subject
4595    (gnus-thread-header h1) (gnus-thread-header h2)))
4596
4597 (defsubst gnus-article-sort-by-date (h1 h2)
4598   "Sort articles by root article date."
4599   (time-less-p
4600    (gnus-date-get-time (mail-header-date h1))
4601    (gnus-date-get-time (mail-header-date h2))))
4602
4603 (defun gnus-thread-sort-by-date (h1 h2)
4604   "Sort threads by root article date."
4605   (gnus-article-sort-by-date
4606    (gnus-thread-header h1) (gnus-thread-header h2)))
4607
4608 (defsubst gnus-article-sort-by-score (h1 h2)
4609   "Sort articles by root article score.
4610 Unscored articles will be counted as having a score of zero."
4611   (> (or (cdr (assq (mail-header-number h1)
4612                     gnus-newsgroup-scored))
4613          gnus-summary-default-score 0)
4614      (or (cdr (assq (mail-header-number h2)
4615                     gnus-newsgroup-scored))
4616          gnus-summary-default-score 0)))
4617
4618 (defun gnus-thread-sort-by-score (h1 h2)
4619   "Sort threads by root article score."
4620   (gnus-article-sort-by-score
4621    (gnus-thread-header h1) (gnus-thread-header h2)))
4622
4623 (defun gnus-thread-sort-by-total-score (h1 h2)
4624   "Sort threads by the sum of all scores in the thread.
4625 Unscored articles will be counted as having a score of zero."
4626   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4627
4628 (defun gnus-thread-total-score (thread)
4629   ;; This function find the total score of THREAD.
4630   (cond
4631    ((null thread)
4632     0)
4633    ((consp thread)
4634     (if (stringp (car thread))
4635         (apply gnus-thread-score-function 0
4636                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4637       (gnus-thread-total-score-1 thread)))
4638    (t
4639     (gnus-thread-total-score-1 (list thread)))))
4640
4641 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4642   "Sort threads such that the thread with the most recently arrived article comes first."
4643   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4644
4645 (defun gnus-thread-highest-number (thread)
4646   "Return the highest article number in THREAD."
4647   (apply 'max (mapcar (lambda (header)
4648                         (mail-header-number header))
4649                       (message-flatten-list thread))))
4650
4651 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4652   "Sort threads such that the thread with the most recently dated article comes first."
4653   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4654
4655 (defun gnus-thread-latest-date (thread)
4656   "Return the highest article date in THREAD."
4657   (let ((previous-time 0))
4658     (apply 'max
4659            (mapcar
4660             (lambda (header)
4661               (setq previous-time
4662                     (condition-case ()
4663                         (time-to-seconds (mail-header-parse-date
4664                                           (mail-header-date header)))
4665                       (error previous-time))))
4666             (sort
4667              (message-flatten-list thread)
4668              (lambda (h1 h2)
4669                (< (mail-header-number h1)
4670                   (mail-header-number h2))))))))
4671
4672 (defun gnus-thread-total-score-1 (root)
4673   ;; This function find the total score of the thread below ROOT.
4674   (setq root (car root))
4675   (apply gnus-thread-score-function
4676          (or (append
4677               (mapcar 'gnus-thread-total-score
4678                       (cdr (gnus-id-to-thread (mail-header-id root))))
4679               (when (> (mail-header-number root) 0)
4680                 (list (or (cdr (assq (mail-header-number root)
4681                                      gnus-newsgroup-scored))
4682                           gnus-summary-default-score 0))))
4683              (list gnus-summary-default-score)
4684              '(0))))
4685
4686 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4687 (defvar gnus-tmp-prev-subject nil)
4688 (defvar gnus-tmp-false-parent nil)
4689 (defvar gnus-tmp-root-expunged nil)
4690 (defvar gnus-tmp-dummy-line nil)
4691
4692 (eval-when-compile (defvar gnus-tmp-header))
4693 (defun gnus-extra-header (type &optional header)
4694   "Return the extra header of TYPE."
4695   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4696       ""))
4697
4698 (defvar gnus-tmp-thread-tree-header-string "")
4699
4700 (defcustom gnus-sum-thread-tree-root "> "
4701   "With %B spec, used for the root of a thread.
4702 If nil, use subject instead."
4703   :version "21.4"
4704   :type '(radio (const :format "%v  " nil) string)
4705   :group 'gnus-thread)
4706 (defcustom gnus-sum-thread-tree-false-root "> "
4707   "With %B spec, used for a false root of a thread.
4708 If nil, use subject instead."
4709   :version "21.4"
4710   :type '(radio (const :format "%v  " nil) string)
4711   :group 'gnus-thread)
4712 (defcustom gnus-sum-thread-tree-single-indent ""
4713   "With %B spec, used for a thread with just one message.
4714 If nil, use subject instead."
4715   :version "21.4"
4716   :type '(radio (const :format "%v  " nil) string)
4717   :group 'gnus-thread)
4718 (defcustom gnus-sum-thread-tree-vertical "| "
4719   "With %B spec, used for drawing a vertical line."
4720   :version "21.4"
4721   :type 'string
4722   :group 'gnus-thread)
4723 (defcustom gnus-sum-thread-tree-indent "  "
4724   "With %B spec, used for indenting."
4725   :version "21.4"
4726   :type 'string
4727   :group 'gnus-thread)
4728 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4729   "With %B spec, used for a leaf with brothers."
4730   :version "21.4"
4731   :type 'string
4732   :group 'gnus-thread)
4733 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4734   "With %B spec, used for a leaf without brothers."
4735   :version "21.4"
4736   :type 'string
4737   :group 'gnus-thread)
4738
4739 (defun gnus-summary-prepare-threads (threads)
4740   "Prepare summary buffer from THREADS and indentation LEVEL.
4741 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4742 or a straight list of headers."
4743   (gnus-message 7 "Generating summary...")
4744
4745   (setq gnus-newsgroup-threads threads)
4746   (beginning-of-line)
4747
4748   (let ((gnus-tmp-level 0)
4749         (default-score (or gnus-summary-default-score 0))
4750         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4751         (building-line-count gnus-summary-display-while-building)
4752         (building-count (integerp gnus-summary-display-while-building))
4753         thread number subject stack state gnus-tmp-gathered beg-match
4754         new-roots gnus-tmp-new-adopts thread-end simp-subject
4755         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4756         gnus-tmp-replied gnus-tmp-subject-or-nil
4757         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4758         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4759         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4760         tree-stack)
4761
4762     (setq gnus-tmp-prev-subject nil
4763           gnus-tmp-thread-tree-header-string "")
4764
4765     (if (vectorp (car threads))
4766         ;; If this is a straight (sic) list of headers, then a
4767         ;; threaded summary display isn't required, so we just create
4768         ;; an unthreaded one.
4769         (gnus-summary-prepare-unthreaded threads)
4770
4771       ;; Do the threaded display.
4772
4773       (if gnus-summary-display-while-building
4774           (switch-to-buffer (buffer-name)))
4775       (while (or threads stack gnus-tmp-new-adopts new-roots)
4776
4777         (if (and (= gnus-tmp-level 0)
4778                  (or (not stack)
4779                      (= (caar stack) 0))
4780                  (not gnus-tmp-false-parent)
4781                  (or gnus-tmp-new-adopts new-roots))
4782             (if gnus-tmp-new-adopts
4783                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4784                       thread (list (car gnus-tmp-new-adopts))
4785                       gnus-tmp-header (caar thread)
4786                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4787               (when new-roots
4788                 (setq thread (list (car new-roots))
4789                       gnus-tmp-header (caar thread)
4790                       new-roots (cdr new-roots))))
4791
4792           (if threads
4793               ;; If there are some threads, we do them before the
4794               ;; threads on the stack.
4795               (setq thread threads
4796                     gnus-tmp-header (caar thread))
4797             ;; There were no current threads, so we pop something off
4798             ;; the stack.
4799             (setq state (car stack)
4800                   gnus-tmp-level (car state)
4801                   tree-stack (cadr state)
4802                   thread (caddr state)
4803                   stack (cdr stack)
4804                   gnus-tmp-header (caar thread))))
4805
4806         (setq gnus-tmp-false-parent nil)
4807         (setq gnus-tmp-root-expunged nil)
4808         (setq thread-end nil)
4809
4810         (if (stringp gnus-tmp-header)
4811             ;; The header is a dummy root.
4812             (cond
4813              ((eq gnus-summary-make-false-root 'adopt)
4814               ;; We let the first article adopt the rest.
4815               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4816                                                (cddar thread)))
4817               (setq gnus-tmp-gathered
4818                     (nconc (mapcar
4819                             (lambda (h) (mail-header-number (car h)))
4820                             (cddar thread))
4821                            gnus-tmp-gathered))
4822               (setq thread (cons (list (caar thread)
4823                                        (cadar thread))
4824                                  (cdr thread)))
4825               (setq gnus-tmp-level -1
4826                     gnus-tmp-false-parent t))
4827              ((eq gnus-summary-make-false-root 'empty)
4828               ;; We print adopted articles with empty subject fields.
4829               (setq gnus-tmp-gathered
4830                     (nconc (mapcar
4831                             (lambda (h) (mail-header-number (car h)))
4832                             (cddar thread))
4833                            gnus-tmp-gathered))
4834               (setq gnus-tmp-level -1))
4835              ((eq gnus-summary-make-false-root 'dummy)
4836               ;; We remember that we probably want to output a dummy
4837               ;; root.
4838               (setq gnus-tmp-dummy-line gnus-tmp-header)
4839               (setq gnus-tmp-prev-subject gnus-tmp-header))
4840              (t
4841               ;; We do not make a root for the gathered
4842               ;; sub-threads at all.
4843               (setq gnus-tmp-level -1)))
4844
4845           (setq number (mail-header-number gnus-tmp-header)
4846                 subject (mail-header-subject gnus-tmp-header)
4847                 simp-subject (gnus-simplify-subject-fully subject))
4848
4849           (cond
4850            ;; If the thread has changed subject, we might want to make
4851            ;; this subthread into a root.
4852            ((and (null gnus-thread-ignore-subject)
4853                  (not (zerop gnus-tmp-level))
4854                  gnus-tmp-prev-subject
4855                  (not (string= gnus-tmp-prev-subject simp-subject)))
4856             (setq new-roots (nconc new-roots (list (car thread)))
4857                   thread-end t
4858                   gnus-tmp-header nil))
4859            ;; If the article lies outside the current limit,
4860            ;; then we do not display it.
4861            ((not (memq number gnus-newsgroup-limit))
4862             (setq gnus-tmp-gathered
4863                   (nconc (mapcar
4864                           (lambda (h) (mail-header-number (car h)))
4865                           (cdar thread))
4866                          gnus-tmp-gathered))
4867             (setq gnus-tmp-new-adopts (if (cdar thread)
4868                                           (append gnus-tmp-new-adopts
4869                                                   (cdar thread))
4870                                         gnus-tmp-new-adopts)
4871                   thread-end t
4872                   gnus-tmp-header nil)
4873             (when (zerop gnus-tmp-level)
4874               (setq gnus-tmp-root-expunged t)))
4875            ;; Perhaps this article is to be marked as read?
4876            ((and gnus-summary-mark-below
4877                  (< (or (cdr (assq number gnus-newsgroup-scored))
4878                         default-score)
4879                     gnus-summary-mark-below)
4880                  ;; Don't touch sparse articles.
4881                  (not (gnus-summary-article-sparse-p number))
4882                  (not (gnus-summary-article-ancient-p number)))
4883             (setq gnus-newsgroup-unreads
4884                   (delq number gnus-newsgroup-unreads))
4885             (if gnus-newsgroup-auto-expire
4886                 (setq gnus-newsgroup-expirable
4887                       (gnus-add-to-sorted-list
4888                        gnus-newsgroup-expirable number))
4889               (push (cons number gnus-low-score-mark)
4890                     gnus-newsgroup-reads))))
4891
4892           (when gnus-tmp-header
4893             ;; We may have an old dummy line to output before this
4894             ;; article.
4895             (when (and gnus-tmp-dummy-line
4896                        (gnus-subject-equal
4897                         gnus-tmp-dummy-line
4898                         (mail-header-subject gnus-tmp-header)))
4899               (gnus-summary-insert-dummy-line
4900                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4901               (setq gnus-tmp-dummy-line nil))
4902
4903             ;; Compute the mark.
4904             (setq gnus-tmp-unread (gnus-article-mark number))
4905
4906             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4907                                   gnus-tmp-header gnus-tmp-level)
4908                   gnus-newsgroup-data)
4909
4910             ;; Actually insert the line.
4911             (setq
4912              gnus-tmp-subject-or-nil
4913              (cond
4914               ((and gnus-thread-ignore-subject
4915                     gnus-tmp-prev-subject
4916                     (not (string= gnus-tmp-prev-subject simp-subject)))
4917                subject)
4918               ((zerop gnus-tmp-level)
4919                (if (and (eq gnus-summary-make-false-root 'empty)
4920                         (memq number gnus-tmp-gathered)
4921                         gnus-tmp-prev-subject
4922                         (string= gnus-tmp-prev-subject simp-subject))
4923                    gnus-summary-same-subject
4924                  subject))
4925               (t gnus-summary-same-subject)))
4926             (if (and (eq gnus-summary-make-false-root 'adopt)
4927                      (= gnus-tmp-level 1)
4928                      (memq number gnus-tmp-gathered))
4929                 (setq gnus-tmp-opening-bracket ?\<
4930                       gnus-tmp-closing-bracket ?\>)
4931               (setq gnus-tmp-opening-bracket ?\[
4932                     gnus-tmp-closing-bracket ?\]))
4933             (setq
4934              gnus-tmp-indentation
4935              (aref gnus-thread-indent-array gnus-tmp-level)
4936              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4937              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4938                                 gnus-summary-default-score 0)
4939              gnus-tmp-score-char
4940              (if (or (null gnus-summary-default-score)
4941                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4942                          gnus-summary-zcore-fuzz))
4943                  ?\ ;;;Whitespace
4944                (if (< gnus-tmp-score gnus-summary-default-score)
4945                    gnus-score-below-mark gnus-score-over-mark))
4946              gnus-tmp-replied
4947              (cond ((memq number gnus-newsgroup-processable)
4948                     gnus-process-mark)
4949                    ((memq number gnus-newsgroup-cached)
4950                     gnus-cached-mark)
4951                    ((memq number gnus-newsgroup-replied)
4952                     gnus-replied-mark)
4953                    ((memq number gnus-newsgroup-forwarded)
4954                     gnus-forwarded-mark)
4955                    ((memq number gnus-newsgroup-saved)
4956                     gnus-saved-mark)
4957                    ((memq number gnus-newsgroup-recent)
4958                     gnus-recent-mark)
4959                    ((memq number gnus-newsgroup-unseen)
4960                     gnus-unseen-mark)
4961                    (t gnus-no-mark))
4962              gnus-tmp-downloaded
4963              (cond ((memq number gnus-newsgroup-undownloaded)
4964                     gnus-undownloaded-mark)
4965                    (gnus-newsgroup-agentized
4966                     gnus-downloaded-mark)
4967                    (t
4968                     gnus-no-mark))
4969              gnus-tmp-from (mail-header-from gnus-tmp-header)
4970              gnus-tmp-name
4971              (cond
4972               ((string-match "<[^>]+> *$" gnus-tmp-from)
4973                (setq beg-match (match-beginning 0))
4974                (or (and (string-match "^\".+\"" gnus-tmp-from)
4975                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4976                    (substring gnus-tmp-from 0 beg-match)))
4977               ((string-match "(.+)" gnus-tmp-from)
4978                (substring gnus-tmp-from
4979                           (1+ (match-beginning 0)) (1- (match-end 0))))
4980               (t gnus-tmp-from))
4981
4982              ;; Do the %B string
4983              gnus-tmp-thread-tree-header-string
4984              (cond
4985               ((not gnus-show-threads) "")
4986               ((zerop gnus-tmp-level)
4987                (cond ((cdar thread)
4988                       (or gnus-sum-thread-tree-root subject))
4989                      (gnus-tmp-new-adopts
4990                       (or gnus-sum-thread-tree-false-root subject))
4991                      (t
4992                       (or gnus-sum-thread-tree-single-indent subject))))
4993               (t
4994                (concat (apply 'concat
4995                               (mapcar (lambda (item)
4996                                         (if (= item 1)
4997                                             gnus-sum-thread-tree-vertical
4998                                           gnus-sum-thread-tree-indent))
4999                                       (cdr (reverse tree-stack))))
5000                        (if (nth 1 thread)
5001                            gnus-sum-thread-tree-leaf-with-other
5002                          gnus-sum-thread-tree-single-leaf)))))
5003             (when (string= gnus-tmp-name "")
5004               (setq gnus-tmp-name gnus-tmp-from))
5005             (unless (numberp gnus-tmp-lines)
5006               (setq gnus-tmp-lines -1))
5007             (if (= gnus-tmp-lines -1)
5008                 (setq gnus-tmp-lines "?")
5009               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5010               (gnus-put-text-property
5011              (point)
5012              (progn (eval gnus-summary-line-format-spec) (point))
5013                'gnus-number number)
5014             (when gnus-visual-p
5015               (forward-line -1)
5016               (gnus-run-hooks 'gnus-summary-update-hook)
5017               (forward-line 1))
5018
5019             (setq gnus-tmp-prev-subject simp-subject)))
5020
5021         (when (nth 1 thread)
5022           (push (list (max 0 gnus-tmp-level)
5023                       (copy-sequence tree-stack)
5024                       (nthcdr 1 thread))
5025                 stack))
5026         (push (if (nth 1 thread) 1 0) tree-stack)
5027         (incf gnus-tmp-level)
5028         (setq threads (if thread-end nil (cdar thread)))
5029         (if gnus-summary-display-while-building
5030             (if building-count
5031                 (progn
5032                   ;; use a set frequency
5033                   (setq building-line-count (1- building-line-count))
5034                   (when (= building-line-count 0)
5035                     (sit-for 0)
5036                     (setq building-line-count
5037                           gnus-summary-display-while-building)))
5038               ;; always
5039               (sit-for 0)))
5040         (unless threads
5041           (setq gnus-tmp-level 0)))))
5042   (gnus-message 7 "Generating summary...done"))
5043
5044 (defun gnus-summary-prepare-unthreaded (headers)
5045   "Generate an unthreaded summary buffer based on HEADERS."
5046   (let (header number mark)
5047
5048     (beginning-of-line)
5049
5050     (while headers
5051       ;; We may have to root out some bad articles...
5052       (when (memq (setq number (mail-header-number
5053                                 (setq header (pop headers))))
5054                   gnus-newsgroup-limit)
5055         ;; Mark article as read when it has a low score.
5056         (when (and gnus-summary-mark-below
5057                    (< (or (cdr (assq number gnus-newsgroup-scored))
5058                           gnus-summary-default-score 0)
5059                       gnus-summary-mark-below)
5060                    (not (gnus-summary-article-ancient-p number)))
5061           (setq gnus-newsgroup-unreads
5062                 (delq number gnus-newsgroup-unreads))
5063           (if gnus-newsgroup-auto-expire
5064               (push number gnus-newsgroup-expirable)
5065             (push (cons number gnus-low-score-mark)
5066                   gnus-newsgroup-reads)))
5067
5068         (setq mark (gnus-article-mark number))
5069         (push (gnus-data-make number mark (1+ (point)) header 0)
5070               gnus-newsgroup-data)
5071         (gnus-summary-insert-line
5072          header 0 number
5073          (memq number gnus-newsgroup-undownloaded)
5074          mark (memq number gnus-newsgroup-replied)
5075          (memq number gnus-newsgroup-expirable)
5076          (mail-header-subject header) nil
5077          (cdr (assq number gnus-newsgroup-scored))
5078          (memq number gnus-newsgroup-processable))))))
5079
5080 (defun gnus-summary-remove-list-identifiers ()
5081   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5082   (let ((regexp (if (consp gnus-list-identifiers)
5083                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5084                   gnus-list-identifiers))
5085         changed subject)
5086     (when regexp
5087       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5088       (dolist (header gnus-newsgroup-headers)
5089         (setq subject (mail-header-subject header)
5090               changed nil)
5091         (while (string-match regexp subject)
5092           (setq subject
5093                 (concat (substring subject 0 (match-beginning 1))
5094                         (substring subject (match-end 0)))
5095                 changed t))
5096         (when changed
5097           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5098             (setq subject
5099                   (concat (substring subject 0 (match-beginning 1))
5100                           (substring subject (match-end 1)))))
5101           (mail-header-set-subject header subject))))))
5102
5103 (defun gnus-fetch-headers (articles)
5104   "Fetch headers of ARTICLES."
5105   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5106     (gnus-message 5 "Fetching headers for %s..." name)
5107     (prog1
5108         (if (eq 'nov
5109                 (setq gnus-headers-retrieved-by
5110                       (gnus-retrieve-headers
5111                        articles gnus-newsgroup-name
5112                        ;; We might want to fetch old headers, but
5113                        ;; not if there is only 1 article.
5114                        (and (or (and
5115                                  (not (eq gnus-fetch-old-headers 'some))
5116                                  (not (numberp gnus-fetch-old-headers)))
5117                                 (> (length articles) 1))
5118                             gnus-fetch-old-headers))))
5119             (gnus-get-newsgroup-headers-xover
5120              articles nil nil gnus-newsgroup-name t)
5121           (gnus-get-newsgroup-headers))
5122       (gnus-message 5 "Fetching headers for %s...done" name))))
5123
5124 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5125   "Select newsgroup GROUP.
5126 If READ-ALL is non-nil, all articles in the group are selected.
5127 If SELECT-ARTICLES, only select those articles from GROUP."
5128   (let* ((entry (gnus-group-entry group))
5129          ;;!!! Dirty hack; should be removed.
5130          (gnus-summary-ignore-duplicates
5131           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5132               t
5133             gnus-summary-ignore-duplicates))
5134          (info (nth 2 entry))
5135          articles fetched-articles cached)
5136
5137     (unless (gnus-check-server
5138              (set (make-local-variable 'gnus-current-select-method)
5139                   (gnus-find-method-for-group group)))
5140       (error "Couldn't open server"))
5141
5142     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5143         (gnus-activate-group group)     ; Or we can activate it...
5144         (progn                          ; Or we bug out.
5145           (when (equal major-mode 'gnus-summary-mode)
5146             (gnus-kill-buffer (current-buffer)))
5147           (error "Couldn't activate group %s: %s"
5148                  group (gnus-status-message group))))
5149
5150     (unless (gnus-request-group group t)
5151       (when (equal major-mode 'gnus-summary-mode)
5152         (gnus-kill-buffer (current-buffer)))
5153       (error "Couldn't request group %s: %s"
5154              group (gnus-status-message group)))
5155
5156     (when gnus-agent
5157       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5158
5159       (setq gnus-summary-use-undownloaded-faces
5160             (gnus-agent-find-parameter
5161              group
5162              'agent-enable-undownloaded-faces)))
5163
5164     (setq gnus-newsgroup-name group
5165           gnus-newsgroup-unselected nil
5166           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5167
5168     (let ((display (gnus-group-find-parameter group 'display)))
5169       (setq gnus-newsgroup-display
5170             (cond
5171              ((not (zerop (or (car-safe read-all) 0)))
5172               ;; The user entered the group with C-u SPC/RET, let's show
5173               ;; all articles.
5174               'gnus-not-ignore)
5175              ((eq display 'all)
5176               'gnus-not-ignore)
5177              ((arrayp display)
5178               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5179              ((numberp display)
5180               ;; The following is probably the "correct" solution, but
5181               ;; it makes Gnus fetch all headers and then limit the
5182               ;; articles (which is slow), so instead we hack the
5183               ;; select-articles parameter instead. -- Simon Josefsson
5184               ;; <jas@kth.se>
5185               ;;
5186               ;; (gnus-byte-compile
5187               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5188               ;;                         display)))))
5189               (setq select-articles
5190                     (gnus-uncompress-range
5191                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5192                              (if (> tmp 0)
5193                                  tmp
5194                                1))
5195                            (cdr (gnus-active group)))))
5196               nil)
5197              (t
5198               nil))))
5199
5200     (gnus-summary-setup-default-charset)
5201
5202     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5203     (when (gnus-virtual-group-p group)
5204       (setq cached gnus-newsgroup-cached))
5205
5206     (setq gnus-newsgroup-unreads
5207           (gnus-sorted-ndifference
5208            (gnus-sorted-ndifference gnus-newsgroup-unreads
5209                                     gnus-newsgroup-marked)
5210            gnus-newsgroup-dormant))
5211
5212     (setq gnus-newsgroup-processable nil)
5213
5214     (gnus-update-read-articles group gnus-newsgroup-unreads)
5215
5216     ;; Adjust and set lists of article marks.
5217     (when info
5218       (gnus-adjust-marked-articles info))
5219     (if (setq articles select-articles)
5220         (setq gnus-newsgroup-unselected
5221               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5222       (setq articles (gnus-articles-to-read group read-all)))
5223
5224     (cond
5225      ((null articles)
5226       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5227       'quit)
5228      ((eq articles 0) nil)
5229      (t
5230       ;; Init the dependencies hash table.
5231       (setq gnus-newsgroup-dependencies
5232             (gnus-make-hashtable (length articles)))
5233       (gnus-set-global-variables)
5234       ;; Retrieve the headers and read them in.
5235
5236       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5237
5238       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5239       (when cached
5240         (setq gnus-newsgroup-cached cached))
5241
5242       ;; Suppress duplicates?
5243       (when gnus-suppress-duplicates
5244         (gnus-dup-suppress-articles))
5245
5246       ;; Set the initial limit.
5247       (setq gnus-newsgroup-limit (copy-sequence articles))
5248       ;; Remove canceled articles from the list of unread articles.
5249       (setq fetched-articles
5250             (mapcar (lambda (headers) (mail-header-number headers))
5251                     gnus-newsgroup-headers))
5252       (setq gnus-newsgroup-articles fetched-articles)
5253       (setq gnus-newsgroup-unreads
5254             (gnus-sorted-nintersection
5255              gnus-newsgroup-unreads fetched-articles))
5256       (gnus-compute-unseen-list)
5257
5258       ;; Removed marked articles that do not exist.
5259       (gnus-update-missing-marks
5260        (gnus-sorted-difference articles fetched-articles))
5261       ;; We might want to build some more threads first.
5262       (when (and gnus-fetch-old-headers
5263                  (eq gnus-headers-retrieved-by 'nov))
5264         (if (eq gnus-fetch-old-headers 'invisible)
5265             (gnus-build-all-threads)
5266           (gnus-build-old-threads)))
5267       ;; Let the Gnus agent mark articles as read.
5268       (when gnus-agent
5269         (gnus-agent-get-undownloaded-list))
5270       ;; Remove list identifiers from subject
5271       (when gnus-list-identifiers
5272         (gnus-summary-remove-list-identifiers))
5273       ;; Check whether auto-expire is to be done in this group.
5274       (setq gnus-newsgroup-auto-expire
5275             (gnus-group-auto-expirable-p group))
5276       ;; Set up the article buffer now, if necessary.
5277       (unless gnus-single-article-buffer
5278         (gnus-article-setup-buffer))
5279       ;; First and last article in this newsgroup.
5280       (when gnus-newsgroup-headers
5281         (setq gnus-newsgroup-begin
5282               (mail-header-number (car gnus-newsgroup-headers))
5283               gnus-newsgroup-end
5284               (mail-header-number
5285                (gnus-last-element gnus-newsgroup-headers))))
5286       ;; GROUP is successfully selected.
5287       (or gnus-newsgroup-headers t)))))
5288
5289 (defun gnus-compute-unseen-list ()
5290   ;; The `seen' marks are treated specially.
5291   (if (not gnus-newsgroup-seen)
5292       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5293     (setq gnus-newsgroup-unseen
5294           (gnus-inverse-list-range-intersection
5295            gnus-newsgroup-articles gnus-newsgroup-seen))))
5296
5297 (defun gnus-summary-display-make-predicate (display)
5298   (require 'gnus-agent)
5299   (when (= (length display) 1)
5300     (setq display (car display)))
5301   (unless gnus-summary-display-cache
5302     (dolist (elem (append '((unread . unread)
5303                             (read . read)
5304                             (unseen . unseen))
5305                           gnus-article-mark-lists))
5306       (push (cons (cdr elem)
5307                   (gnus-byte-compile
5308                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5309             gnus-summary-display-cache)))
5310   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5311         (gnus-category-predicate-cache gnus-summary-display-cache))
5312     (gnus-get-predicate display)))
5313
5314 ;; Uses the dynamically bound `number' variable.
5315 (eval-when-compile
5316   (defvar number))
5317 (defun gnus-article-marked-p (type &optional article)
5318   (let ((article (or article number)))
5319     (cond
5320      ((eq type 'tick)
5321       (memq article gnus-newsgroup-marked))
5322      ((eq type 'spam)
5323       (memq article gnus-newsgroup-spam-marked))
5324      ((eq type 'unsend)
5325       (memq article gnus-newsgroup-unsendable))
5326      ((eq type 'undownload)
5327       (memq article gnus-newsgroup-undownloaded))
5328      ((eq type 'download)
5329       (memq article gnus-newsgroup-downloadable))
5330      ((eq type 'unread)
5331       (memq article gnus-newsgroup-unreads))
5332      ((eq type 'read)
5333       (memq article gnus-newsgroup-reads))
5334      ((eq type 'dormant)
5335       (memq article gnus-newsgroup-dormant) )
5336      ((eq type 'expire)
5337       (memq article gnus-newsgroup-expirable))
5338      ((eq type 'reply)
5339       (memq article gnus-newsgroup-replied))
5340      ((eq type 'killed)
5341       (memq article gnus-newsgroup-killed))
5342      ((eq type 'bookmark)
5343       (assq article gnus-newsgroup-bookmarks))
5344      ((eq type 'score)
5345       (assq article gnus-newsgroup-scored))
5346      ((eq type 'save)
5347       (memq article gnus-newsgroup-saved))
5348      ((eq type 'cache)
5349       (memq article gnus-newsgroup-cached))
5350      ((eq type 'forward)
5351       (memq article gnus-newsgroup-forwarded))
5352      ((eq type 'seen)
5353       (not (memq article gnus-newsgroup-unseen)))
5354      ((eq type 'recent)
5355       (memq article gnus-newsgroup-recent))
5356      (t t))))
5357
5358 (defun gnus-articles-to-read (group &optional read-all)
5359   "Find out what articles the user wants to read."
5360   (let* ((articles
5361           ;; Select all articles if `read-all' is non-nil, or if there
5362           ;; are no unread articles.
5363           (if (or read-all
5364                   (and (zerop (length gnus-newsgroup-marked))
5365                        (zerop (length gnus-newsgroup-unreads)))
5366                   ;; Fetch all if the predicate is non-nil.
5367                   gnus-newsgroup-display)
5368               ;; We want to select the headers for all the articles in
5369               ;; the group, so we select either all the active
5370               ;; articles in the group, or (if that's nil), the
5371               ;; articles in the cache.
5372               (or
5373                (gnus-uncompress-range (gnus-active group))
5374                (gnus-cache-articles-in-group group))
5375             ;; Select only the "normal" subset of articles.
5376             (gnus-sorted-nunion
5377              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5378              gnus-newsgroup-unreads)))
5379          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5380          (scored (length scored-list))
5381          (number (length articles))
5382          (marked (+ (length gnus-newsgroup-marked)
5383                     (length gnus-newsgroup-dormant)))
5384          (select
5385           (cond
5386            ((numberp read-all)
5387             read-all)
5388            ((numberp gnus-newsgroup-display)
5389             gnus-newsgroup-display)
5390            (t
5391             (condition-case ()
5392                 (cond
5393                  ((and (or (<= scored marked) (= scored number))
5394                        (numberp gnus-large-newsgroup)
5395                        (> number gnus-large-newsgroup))
5396                   (let* ((cursor-in-echo-area nil)
5397                          (initial (gnus-parameter-large-newsgroup-initial
5398                                    gnus-newsgroup-name))
5399                          (input
5400                           (read-string
5401                            (format
5402                             "How many articles from %s (%s %d): "
5403                             (gnus-limit-string
5404                              (gnus-group-decoded-name gnus-newsgroup-name)
5405                              35)
5406                             (if initial "max" "default")
5407                             number)
5408                            (if initial
5409                                (cons (number-to-string initial)
5410                                      0)))))
5411                     (if (string-match "^[ \t]*$" input) number input)))
5412                  ((and (> scored marked) (< scored number)
5413                        (> (- scored number) 20))
5414                   (let ((input
5415                          (read-string
5416                           (format "%s %s (%d scored, %d total): "
5417                                   "How many articles from"
5418                                   (gnus-group-decoded-name group)
5419                                   scored number))))
5420                     (if (string-match "^[ \t]*$" input)
5421                         number input)))
5422                  (t number))
5423               (quit
5424                (message "Quit getting the articles to read")
5425                nil))))))
5426     (setq select (if (stringp select) (string-to-number select) select))
5427     (if (or (null select) (zerop select))
5428         select
5429       (if (and (not (zerop scored)) (<= (abs select) scored))
5430           (progn
5431             (setq articles (sort scored-list '<))
5432             (setq number (length articles)))
5433         (setq articles (copy-sequence articles)))
5434
5435       (when (< (abs select) number)
5436         (if (< select 0)
5437             ;; Select the N oldest articles.
5438             (setcdr (nthcdr (1- (abs select)) articles) nil)
5439           ;; Select the N most recent articles.
5440           (setq articles (nthcdr (- number select) articles))))
5441       (setq gnus-newsgroup-unselected
5442             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5443       (when gnus-alter-articles-to-read-function
5444         (setq articles
5445               (sort
5446                (funcall gnus-alter-articles-to-read-function
5447                         gnus-newsgroup-name articles)
5448                '<)))
5449       articles)))
5450
5451 (defun gnus-killed-articles (killed articles)
5452   (let (out)
5453     (while articles
5454       (when (inline (gnus-member-of-range (car articles) killed))
5455         (push (car articles) out))
5456       (setq articles (cdr articles)))
5457     out))
5458
5459 (defun gnus-uncompress-marks (marks)
5460   "Uncompress the mark ranges in MARKS."
5461   (let ((uncompressed '(score bookmark))
5462         out)
5463     (while marks
5464       (if (memq (caar marks) uncompressed)
5465           (push (car marks) out)
5466         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5467       (setq marks (cdr marks)))
5468     out))
5469
5470 (defun gnus-article-mark-to-type (mark)
5471   "Return the type of MARK."
5472   (or (cadr (assq mark gnus-article-special-mark-lists))
5473       'list))
5474
5475 (defun gnus-article-unpropagatable-p (mark)
5476   "Return whether MARK should be propagated to back end."
5477   (memq mark gnus-article-unpropagated-mark-lists))
5478
5479 (defun gnus-adjust-marked-articles (info)
5480   "Set all article lists and remove all marks that are no longer valid."
5481   (let* ((marked-lists (gnus-info-marks info))
5482          (active (gnus-active (gnus-info-group info)))
5483          (min (car active))
5484          (max (cdr active))
5485          (types gnus-article-mark-lists)
5486          marks var articles article mark mark-type
5487          bgn end)
5488
5489     (dolist (marks marked-lists)
5490       (setq mark (car marks)
5491             mark-type (gnus-article-mark-to-type mark)
5492             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5493
5494       ;; We set the variable according to the type of the marks list,
5495       ;; and then adjust the marks to a subset of the active articles.
5496       (cond
5497        ;; Adjust "simple" lists - compressed yet unsorted
5498        ((eq mark-type 'list)
5499         ;; Simultaneously uncompress and clip to active range
5500         ;; See gnus-uncompress-range for a description of possible marks
5501         (let (l lh)
5502           (if (not (cadr marks))
5503               (set var nil)
5504             (setq articles (if (numberp (cddr marks))
5505                                (list (cdr marks))
5506                              (cdr marks))
5507                   lh (cons nil nil)
5508                   l lh)
5509
5510             (while (setq article (pop articles))
5511               (cond ((consp article)
5512                      (setq bgn (max (car article) min)
5513                            end (min (cdr article) max))
5514                      (while (<= bgn end)
5515                        (setq l (setcdr l (cons bgn nil))
5516                              bgn (1+ bgn))))
5517                     ((and (<= min article)
5518                           (>= max article))
5519                      (setq l (setcdr l (cons article nil))))))
5520             (set var (cdr lh)))))
5521        ;; Adjust assocs.
5522        ((eq mark-type 'tuple)
5523         (set var (setq articles (cdr marks)))
5524         (when (not (listp (cdr (symbol-value var))))
5525           (set var (list (symbol-value var))))
5526         (when (not (listp (cdr articles)))
5527           (setq articles (list articles)))
5528         (while articles
5529           (when (or (not (consp (setq article (pop articles))))
5530                     (< (car article) min)
5531                     (> (car article) max))
5532             (set var (delq article (symbol-value var))))))
5533        ;; Adjust ranges (sloppily).
5534        ((eq mark-type 'range)
5535         (cond
5536          ((eq mark 'seen)
5537           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5538           ;; It should be (seen (NUM1 . NUM2)).
5539           (when (numberp (cddr marks))
5540             (setcdr marks (list (cdr marks))))
5541           (setq articles (cdr marks))
5542           (while (and articles
5543                       (or (and (consp (car articles))
5544                                (> min (cdar articles)))
5545                           (and (numberp (car articles))
5546                                (> min (car articles)))))
5547             (pop articles))
5548           (set var articles))))))))
5549
5550 (defun gnus-update-missing-marks (missing)
5551   "Go through the list of MISSING articles and remove them from the mark lists."
5552   (when missing
5553     (let (var m)
5554       ;; Go through all types.
5555       (dolist (elem gnus-article-mark-lists)
5556         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5557           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5558           (when (symbol-value var)
5559             ;; This list has articles.  So we delete all missing
5560             ;; articles from it.
5561             (setq m missing)
5562             (while m
5563               (set var (delq (pop m) (symbol-value var))))))))))
5564
5565 (defun gnus-update-marks ()
5566   "Enter the various lists of marked articles into the newsgroup info list."
5567   (let ((types gnus-article-mark-lists)
5568         (info (gnus-get-info gnus-newsgroup-name))
5569         type list newmarked symbol delta-marks)
5570     (when info
5571       ;; Add all marks lists to the list of marks lists.
5572       (while (setq type (pop types))
5573         (setq list (symbol-value
5574                     (setq symbol
5575                           (intern (format "gnus-newsgroup-%s" (car type))))))
5576
5577         (when list
5578           ;; Get rid of the entries of the articles that have the
5579           ;; default score.
5580           (when (and (eq (cdr type) 'score)
5581                      gnus-save-score
5582                      list)
5583             (let* ((arts list)
5584                    (prev (cons nil list))
5585                    (all prev))
5586               (while arts
5587                 (if (or (not (consp (car arts)))
5588                         (= (cdar arts) gnus-summary-default-score))
5589                     (setcdr prev (cdr arts))
5590                   (setq prev arts))
5591                 (setq arts (cdr arts)))
5592               (setq list (cdr all)))))
5593
5594         (when (eq (cdr type) 'seen)
5595           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5596
5597         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5598           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5599
5600         (when (and (gnus-check-backend-function
5601                     'request-set-mark gnus-newsgroup-name)
5602                    (not (gnus-article-unpropagatable-p (cdr type))))
5603           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5604                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5605                  (add (gnus-remove-from-range
5606                        (gnus-copy-sequence list) old)))
5607             (when add
5608               (push (list add 'add (list (cdr type))) delta-marks))
5609             (when del
5610               (push (list del 'del (list (cdr type))) delta-marks))))
5611
5612         (when list
5613           (push (cons (cdr type) list) newmarked)))
5614
5615       (when delta-marks
5616         (unless (gnus-check-group gnus-newsgroup-name)
5617           (error "Can't open server for %s" gnus-newsgroup-name))
5618         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5619
5620       ;; Enter these new marks into the info of the group.
5621       (if (nthcdr 3 info)
5622           (setcar (nthcdr 3 info) newmarked)
5623         ;; Add the marks lists to the end of the info.
5624         (when newmarked
5625           (setcdr (nthcdr 2 info) (list newmarked))))
5626
5627       ;; Cut off the end of the info if there's nothing else there.
5628       (let ((i 5))
5629         (while (and (> i 2)
5630                     (not (nth i info)))
5631           (when (nthcdr (decf i) info)
5632             (setcdr (nthcdr i info) nil)))))))
5633
5634 (defun gnus-set-mode-line (where)
5635   "Set the mode line of the article or summary buffers.
5636 If WHERE is `summary', the summary mode line format will be used."
5637   ;; Is this mode line one we keep updated?
5638   (when (and (memq where gnus-updated-mode-lines)
5639              (symbol-value
5640               (intern (format "gnus-%s-mode-line-format-spec" where))))
5641     (let (mode-string)
5642       (save-excursion
5643         ;; We evaluate this in the summary buffer since these
5644         ;; variables are buffer-local to that buffer.
5645         (set-buffer gnus-summary-buffer)
5646         ;; We bind all these variables that are used in the `eval' form
5647         ;; below.
5648         (let* ((mformat (symbol-value
5649                          (intern
5650                           (format "gnus-%s-mode-line-format-spec" where))))
5651                (gnus-tmp-group-name (gnus-group-decoded-name
5652                                      gnus-newsgroup-name))
5653                (gnus-tmp-article-number (or gnus-current-article 0))
5654                (gnus-tmp-unread gnus-newsgroup-unreads)
5655                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5656                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5657                (gnus-tmp-unread-and-unselected
5658                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5659                             (zerop gnus-tmp-unselected))
5660                        "")
5661                       ((zerop gnus-tmp-unselected)
5662                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5663                       (t (format "{%d(+%d) more}"
5664                                  gnus-tmp-unread-and-unticked
5665                                  gnus-tmp-unselected))))
5666                (gnus-tmp-subject
5667                 (if (and gnus-current-headers
5668                          (vectorp gnus-current-headers))
5669                     (gnus-mode-string-quote
5670                      (mail-header-subject gnus-current-headers))
5671                   ""))
5672                bufname-length max-len
5673                gnus-tmp-header);; passed as argument to any user-format-funcs
5674           (setq mode-string (eval mformat))
5675           (setq bufname-length (if (string-match "%b" mode-string)
5676                                    (- (length
5677                                        (buffer-name
5678                                         (if (eq where 'summary)
5679                                             nil
5680                                           (get-buffer gnus-article-buffer))))
5681                                       2)
5682                                  0))
5683           (setq max-len (max 4 (if gnus-mode-non-string-length
5684                                    (- (window-width)
5685                                       gnus-mode-non-string-length
5686                                       bufname-length)
5687                                  (length mode-string))))
5688           ;; We might have to chop a bit of the string off...
5689           (when (> (length mode-string) max-len)
5690             (setq mode-string
5691                   (concat (gnus-truncate-string mode-string (- max-len 3))
5692                           "...")))
5693           ;; Pad the mode string a bit.
5694           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5695       ;; Update the mode line.
5696       (setq mode-line-buffer-identification
5697             (gnus-mode-line-buffer-identification (list mode-string)))
5698       (set-buffer-modified-p t))))
5699
5700 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5701   "Go through the HEADERS list and add all Xrefs to a hash table.
5702 The resulting hash table is returned, or nil if no Xrefs were found."
5703   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5704          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5705          (xref-hashtb (gnus-make-hashtable))
5706          start group entry number xrefs header)
5707     (while headers
5708       (setq header (pop headers))
5709       (when (and (setq xrefs (mail-header-xref header))
5710                  (not (memq (setq number (mail-header-number header))
5711                             unreads)))
5712         (setq start 0)
5713         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5714           (setq start (match-end 0))
5715           (setq group (if prefix
5716                           (concat prefix (substring xrefs (match-beginning 1)
5717                                                     (match-end 1)))
5718                         (substring xrefs (match-beginning 1) (match-end 1))))
5719           (setq number
5720                 (string-to-int (substring xrefs (match-beginning 2)
5721                                           (match-end 2))))
5722           (if (setq entry (gnus-gethash group xref-hashtb))
5723               (setcdr entry (cons number (cdr entry)))
5724             (gnus-sethash group (cons number nil) xref-hashtb)))))
5725     (and start xref-hashtb)))
5726
5727 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5728   "Look through all the headers and mark the Xrefs as read."
5729   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5730         name info xref-hashtb idlist method nth4)
5731     (save-excursion
5732       (set-buffer gnus-group-buffer)
5733       (when (setq xref-hashtb
5734                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5735         (mapatoms
5736          (lambda (group)
5737            (unless (string= from-newsgroup (setq name (symbol-name group)))
5738              (setq idlist (symbol-value group))
5739              ;; Dead groups are not updated.
5740              (and (prog1
5741                       (setq info (gnus-get-info name))
5742                     (when (stringp (setq nth4 (gnus-info-method info)))
5743                       (setq nth4 (gnus-server-to-method nth4))))
5744                   ;; Only do the xrefs if the group has the same
5745                   ;; select method as the group we have just read.
5746                   (or (gnus-methods-equal-p
5747                        nth4 (gnus-find-method-for-group from-newsgroup))
5748                       virtual
5749                       (equal nth4 (setq method (gnus-find-method-for-group
5750                                                 from-newsgroup)))
5751                       (and (equal (car nth4) (car method))
5752                            (equal (nth 1 nth4) (nth 1 method))))
5753                   gnus-use-cross-reference
5754                   (or (not (eq gnus-use-cross-reference t))
5755                       virtual
5756                       ;; Only do cross-references on subscribed
5757                       ;; groups, if that is what is wanted.
5758                       (<= (gnus-info-level info) gnus-level-subscribed))
5759                   (gnus-group-make-articles-read name idlist))))
5760          xref-hashtb)))))
5761
5762 (defun gnus-compute-read-articles (group articles)
5763   (let* ((entry (gnus-group-entry group))
5764          (info (nth 2 entry))
5765          (active (gnus-active group))
5766          ninfo)
5767     (when entry
5768       ;; First peel off all invalid article numbers.
5769       (when active
5770         (let ((ids articles)
5771               id first)
5772           (while (setq id (pop ids))
5773             (when (and first (> id (cdr active)))
5774               ;; We'll end up in this situation in one particular
5775               ;; obscure situation.  If you re-scan a group and get
5776               ;; a new article that is cross-posted to a different
5777               ;; group that has not been re-scanned, you might get
5778               ;; crossposted article that has a higher number than
5779               ;; Gnus believes possible.  So we re-activate this
5780               ;; group as well.  This might mean doing the
5781               ;; crossposting thingy will *increase* the number
5782               ;; of articles in some groups.  Tsk, tsk.
5783               (setq active (or (gnus-activate-group group) active)))
5784             (when (or (> id (cdr active))
5785                       (< id (car active)))
5786               (setq articles (delq id articles))))))
5787       ;; If the read list is nil, we init it.
5788       (if (and active
5789                (null (gnus-info-read info))
5790                (> (car active) 1))
5791           (setq ninfo (cons 1 (1- (car active))))
5792         (setq ninfo (gnus-info-read info)))
5793       ;; Then we add the read articles to the range.
5794       (gnus-add-to-range
5795        ninfo (setq articles (sort articles '<))))))
5796
5797 (defun gnus-group-make-articles-read (group articles)
5798   "Update the info of GROUP to say that ARTICLES are read."
5799   (let* ((num 0)
5800          (entry (gnus-group-entry group))
5801          (info (nth 2 entry))
5802          (active (gnus-active group))
5803          range)
5804     (when entry
5805       (setq range (gnus-compute-read-articles group articles))
5806       (with-current-buffer gnus-group-buffer
5807         (gnus-undo-register
5808           `(progn
5809              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5810              (gnus-info-set-read ',info ',(gnus-info-read info))
5811              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5812              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5813              (gnus-group-update-group ,group t))))
5814       ;; Add the read articles to the range.
5815       (gnus-info-set-read info range)
5816       (gnus-request-set-mark group (list (list range 'add '(read))))
5817       ;; Then we have to re-compute how many unread
5818       ;; articles there are in this group.
5819       (when active
5820         (cond
5821          ((not range)
5822           (setq num (- (1+ (cdr active)) (car active))))
5823          ((not (listp (cdr range)))
5824           (setq num (- (cdr active) (- (1+ (cdr range))
5825                                        (car range)))))
5826          (t
5827           (while range
5828             (if (numberp (car range))
5829                 (setq num (1+ num))
5830               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5831             (setq range (cdr range)))
5832           (setq num (- (cdr active) num))))
5833         ;; Update the number of unread articles.
5834         (setcar entry num)
5835         ;; Update the group buffer.
5836         (unless (gnus-ephemeral-group-p group)
5837           (gnus-group-update-group group t))))))
5838
5839 (defvar gnus-newsgroup-none-id 0)
5840
5841 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5842   (let ((cur nntp-server-buffer)
5843         (dependencies
5844          (or dependencies
5845              (with-current-buffer gnus-summary-buffer
5846                gnus-newsgroup-dependencies)))
5847         headers id end ref number
5848         (mail-parse-charset gnus-newsgroup-charset)
5849         (mail-parse-ignored-charsets
5850          (save-excursion (condition-case nil
5851                              (set-buffer gnus-summary-buffer)
5852                            (error))
5853                          gnus-newsgroup-ignored-charsets)))
5854     (save-excursion
5855       (set-buffer nntp-server-buffer)
5856       ;; Translate all TAB characters into SPACE characters.
5857       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5858       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5859       (ietf-drums-unfold-fws)
5860       (gnus-run-hooks 'gnus-parse-headers-hook)
5861       (let ((case-fold-search t)
5862             in-reply-to header p lines chars ctype)
5863         (goto-char (point-min))
5864         ;; Search to the beginning of the next header.  Error messages
5865         ;; do not begin with 2 or 3.
5866         (while (re-search-forward "^[23][0-9]+ " nil t)
5867           (setq id nil
5868                 ref nil)
5869           ;; This implementation of this function, with nine
5870           ;; search-forwards instead of the one re-search-forward and
5871           ;; a case (which basically was the old function) is actually
5872           ;; about twice as fast, even though it looks messier.  You
5873           ;; can't have everything, I guess.  Speed and elegance
5874           ;; doesn't always go hand in hand.
5875           (setq
5876            header
5877            (make-full-mail-header
5878             ;; Number.
5879             (prog1
5880                 (setq number (read cur))
5881               (end-of-line)
5882               (setq p (point))
5883               (narrow-to-region (point)
5884                                 (or (and (search-forward "\n.\n" nil t)
5885                                          (- (point) 2))
5886                                     (point))))
5887             ;; Subject.
5888             (progn
5889               (goto-char p)
5890               (if (search-forward "\nsubject:" nil t)
5891                   (nnheader-header-value)
5892                 "(none)"))
5893             ;; From.
5894             (progn
5895               (goto-char p)
5896               (if (search-forward "\nfrom:" nil t)
5897                   (nnheader-header-value)
5898                 "(nobody)"))
5899             ;; Date.
5900             (progn
5901               (goto-char p)
5902               (if (search-forward "\ndate:" nil t)
5903                   (nnheader-header-value) ""))
5904             ;; Message-ID.
5905             (progn
5906               (goto-char p)
5907               (setq id (if (re-search-forward
5908                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5909                            ;; We do it this way to make sure the Message-ID
5910                            ;; is (somewhat) syntactically valid.
5911                            (buffer-substring (match-beginning 1)
5912                                              (match-end 1))
5913                          ;; If there was no message-id, we just fake one
5914                          ;; to make subsequent routines simpler.
5915                          (nnheader-generate-fake-message-id number))))
5916             ;; References.
5917             (progn
5918               (goto-char p)
5919               (if (search-forward "\nreferences:" nil t)
5920                   (progn
5921                     (setq end (point))
5922                     (prog1
5923                         (nnheader-header-value)
5924                       (setq ref
5925                             (buffer-substring
5926                              (progn
5927                                ;; (end-of-line)
5928                                (search-backward ">" end t)
5929                                (1+ (point)))
5930                              (progn
5931                                (search-backward "<" end t)
5932                                (point))))))
5933                 ;; Get the references from the in-reply-to header if there
5934                 ;; were no references and the in-reply-to header looks
5935                 ;; promising.
5936                 (if (and (search-forward "\nin-reply-to:" nil t)
5937                          (setq in-reply-to (nnheader-header-value))
5938                          (string-match "<[^>]+>" in-reply-to))
5939                     (let (ref2)
5940                       (setq ref (substring in-reply-to (match-beginning 0)
5941                                            (match-end 0)))
5942                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5943                         (setq ref2 (substring in-reply-to (match-beginning 0)
5944                                               (match-end 0)))
5945                         (when (> (length ref2) (length ref))
5946                           (setq ref ref2)))
5947                       ref)
5948                   (setq ref nil))))
5949             ;; Chars.
5950             (progn
5951               (goto-char p)
5952               (if (search-forward "\nchars: " nil t)
5953                   (if (numberp (setq chars (ignore-errors (read cur))))
5954                       chars -1)
5955                 -1))
5956             ;; Lines.
5957             (progn
5958               (goto-char p)
5959               (if (search-forward "\nlines: " nil t)
5960                   (if (numberp (setq lines (ignore-errors (read cur))))
5961                       lines -1)
5962                 -1))
5963             ;; Xref.
5964             (progn
5965               (goto-char p)
5966               (and (search-forward "\nxref:" nil t)
5967                    (nnheader-header-value)))
5968             ;; Extra.
5969             (when gnus-extra-headers
5970               (let ((extra gnus-extra-headers)
5971                     out)
5972                 (while extra
5973                   (goto-char p)
5974                   (when (search-forward
5975                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5976                     (push (cons (car extra) (nnheader-header-value)) out))
5977                   (pop extra))
5978                 out))))
5979           (goto-char p)
5980           (if (and (search-forward "\ncontent-type: " nil t)
5981                    (setq ctype (nnheader-header-value)))
5982               (mime-entity-set-content-type-internal
5983                header (mime-parse-Content-Type ctype)))
5984           (when (equal id ref)
5985             (setq ref nil))
5986
5987           (when gnus-alter-header-function
5988             (funcall gnus-alter-header-function header)
5989             (setq id (mail-header-id header)
5990                   ref (gnus-parent-id (mail-header-references header))))
5991
5992           (when (setq header
5993                       (gnus-dependencies-add-header
5994                        header dependencies force-new))
5995             (push header headers))
5996           (goto-char (point-max))
5997           (widen))
5998         (nreverse headers)))))
5999
6000 ;; Goes through the xover lines and returns a list of vectors
6001 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6002                                                   force-new dependencies
6003                                                   group also-fetch-heads)
6004   "Parse the news overview data in the server buffer.
6005 Return a list of headers that match SEQUENCE (see
6006 `nntp-retrieve-headers')."
6007   ;; Get the Xref when the users reads the articles since most/some
6008   ;; NNTP servers do not include Xrefs when using XOVER.
6009   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6010   (let ((mail-parse-charset gnus-newsgroup-charset)
6011         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6012         (cur nntp-server-buffer)
6013         (dependencies (or dependencies gnus-newsgroup-dependencies))
6014         (allp (cond
6015                ((eq gnus-read-all-available-headers t)
6016                 t)
6017                ((stringp gnus-read-all-available-headers)
6018                 (string-match gnus-read-all-available-headers group))
6019                (t
6020                 nil)))
6021         number headers header)
6022     (save-excursion
6023       (set-buffer nntp-server-buffer)
6024       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6025       ;; Allow the user to mangle the headers before parsing them.
6026       (gnus-run-hooks 'gnus-parse-headers-hook)
6027       (goto-char (point-min))
6028       (gnus-parse-without-error
6029         (while (and (or sequence allp)
6030                     (not (eobp)))
6031           (setq number (read cur))
6032           (when (not allp)
6033             (while (and sequence
6034                         (< (car sequence) number))
6035               (setq sequence (cdr sequence))))
6036           (when (and (or allp
6037                          (and sequence
6038                               (eq number (car sequence))))
6039                      (progn
6040                        (setq sequence (cdr sequence))
6041                        (setq header (inline
6042                                       (gnus-nov-parse-line
6043                                        number dependencies force-new)))))
6044             (push header headers))
6045           (forward-line 1)))
6046       ;; A common bug in inn is that if you have posted an article and
6047       ;; then retrieves the active file, it will answer correctly --
6048       ;; the new article is included.  However, a NOV entry for the
6049       ;; article may not have been generated yet, so this may fail.
6050       ;; We work around this problem by retrieving the last few
6051       ;; headers using HEAD.
6052       (if (or (not also-fetch-heads)
6053               (not sequence))
6054           ;; We (probably) got all the headers.
6055           (nreverse headers)
6056         (let ((gnus-nov-is-evil t))
6057           (nconc
6058            (nreverse headers)
6059            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6060              (gnus-get-newsgroup-headers))))))))
6061
6062 (defun gnus-article-get-xrefs ()
6063   "Fill in the Xref value in `gnus-current-headers', if necessary.
6064 This is meant to be called in `gnus-article-internal-prepare-hook'."
6065   (let ((headers (with-current-buffer gnus-summary-buffer
6066                    gnus-current-headers)))
6067     (or (not gnus-use-cross-reference)
6068         (not headers)
6069         (and (mail-header-xref headers)
6070              (not (string= (mail-header-xref headers) "")))
6071         (let ((case-fold-search t)
6072               xref)
6073           (save-restriction
6074             (nnheader-narrow-to-headers)
6075             (goto-char (point-min))
6076             (when (or (and (not (eobp))
6077                            (eq (downcase (char-after)) ?x)
6078                            (looking-at "Xref:"))
6079                       (search-forward "\nXref:" nil t))
6080               (goto-char (1+ (match-end 0)))
6081               (setq xref (buffer-substring (point) (point-at-eol)))
6082               (mail-header-set-xref headers xref)))))))
6083
6084 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6085   "Find article ID and insert the summary line for that article.
6086 OLD-HEADER can either be a header or a line number to insert
6087 the subject line on."
6088   (let* ((line (and (numberp old-header) old-header))
6089          (old-header (and (vectorp old-header) old-header))
6090          (header (cond ((and old-header use-old-header)
6091                         old-header)
6092                        ((and (numberp id)
6093                              (gnus-number-to-header id))
6094                         (gnus-number-to-header id))
6095                        (t
6096                         (gnus-read-header id))))
6097          (number (and (numberp id) id))
6098          d)
6099     (when header
6100       ;; Rebuild the thread that this article is part of and go to the
6101       ;; article we have fetched.
6102       (when (and (not gnus-show-threads)
6103                  old-header)
6104         (when (and number
6105                    (setq d (gnus-data-find (mail-header-number old-header))))
6106           (goto-char (gnus-data-pos d))
6107           (gnus-data-remove
6108            number
6109            (- (point-at-bol)
6110               (prog1
6111                   (1+ (point-at-eol))
6112                 (gnus-delete-line))))))
6113       ;; Remove list identifiers from subject.
6114       (when gnus-list-identifiers
6115         (let ((gnus-newsgroup-headers (list header)))
6116           (gnus-summary-remove-list-identifiers)))
6117       (when old-header
6118         (mail-header-set-number header (mail-header-number old-header)))
6119       (setq gnus-newsgroup-sparse
6120             (delq (setq number (mail-header-number header))
6121                   gnus-newsgroup-sparse))
6122       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6123       (push number gnus-newsgroup-limit)
6124       (gnus-rebuild-thread (mail-header-id header) line)
6125       (gnus-summary-goto-subject number nil t))
6126     (when (and (numberp number)
6127                (> number 0))
6128       ;; We have to update the boundaries even if we can't fetch the
6129       ;; article if ID is a number -- so that the next `P' or `N'
6130       ;; command will fetch the previous (or next) article even
6131       ;; if the one we tried to fetch this time has been canceled.
6132       (when (> number gnus-newsgroup-end)
6133         (setq gnus-newsgroup-end number))
6134       (when (< number gnus-newsgroup-begin)
6135         (setq gnus-newsgroup-begin number))
6136       (setq gnus-newsgroup-unselected
6137             (delq number gnus-newsgroup-unselected)))
6138     ;; Report back a success?
6139     (and header (mail-header-number header))))
6140
6141 ;;; Process/prefix in the summary buffer
6142
6143 (defun gnus-summary-work-articles (n)
6144   "Return a list of articles to be worked upon.
6145 The prefix argument, the list of process marked articles, and the
6146 current article will be taken into consideration."
6147   (save-excursion
6148     (set-buffer gnus-summary-buffer)
6149     (cond
6150      (n
6151       ;; A numerical prefix has been given.
6152       (setq n (prefix-numeric-value n))
6153       (let ((backward (< n 0))
6154             (n (abs (prefix-numeric-value n)))
6155             articles article)
6156         (save-excursion
6157           (while
6158               (and (> n 0)
6159                    (push (setq article (gnus-summary-article-number))
6160                          articles)
6161                    (if backward
6162                        (gnus-summary-find-prev nil article)
6163                      (gnus-summary-find-next nil article)))
6164             (decf n)))
6165         (nreverse articles)))
6166      ((and (gnus-region-active-p) (mark))
6167       (message "region active")
6168       ;; Work on the region between point and mark.
6169       (let ((max (max (point) (mark)))
6170             articles article)
6171         (save-excursion
6172           (goto-char (min (point) (mark)))
6173           (while
6174               (and
6175                (push (setq article (gnus-summary-article-number)) articles)
6176                (gnus-summary-find-next nil article)
6177                (< (point) max)))
6178           (nreverse articles))))
6179      (gnus-newsgroup-processable
6180       ;; There are process-marked articles present.
6181       ;; Save current state.
6182       (gnus-summary-save-process-mark)
6183       ;; Return the list.
6184       (reverse gnus-newsgroup-processable))
6185      (t
6186       ;; Just return the current article.
6187       (list (gnus-summary-article-number))))))
6188
6189 (defmacro gnus-summary-iterate (arg &rest forms)
6190   "Iterate over the process/prefixed articles and do FORMS.
6191 ARG is the interactive prefix given to the command.  FORMS will be
6192 executed with point over the summary line of the articles."
6193   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6194     `(let ((,articles (gnus-summary-work-articles ,arg)))
6195        (while ,articles
6196          (gnus-summary-goto-subject (car ,articles))
6197          ,@forms
6198          (pop ,articles)))))
6199
6200 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6201 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6202
6203 (defun gnus-summary-save-process-mark ()
6204   "Push the current set of process marked articles on the stack."
6205   (interactive)
6206   (push (copy-sequence gnus-newsgroup-processable)
6207         gnus-newsgroup-process-stack))
6208
6209 (defun gnus-summary-kill-process-mark ()
6210   "Push the current set of process marked articles on the stack and unmark."
6211   (interactive)
6212   (gnus-summary-save-process-mark)
6213   (gnus-summary-unmark-all-processable))
6214
6215 (defun gnus-summary-yank-process-mark ()
6216   "Pop the last process mark state off the stack and restore it."
6217   (interactive)
6218   (unless gnus-newsgroup-process-stack
6219     (error "Empty mark stack"))
6220   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6221
6222 (defun gnus-summary-process-mark-set (set)
6223   "Make SET into the current process marked articles."
6224   (gnus-summary-unmark-all-processable)
6225   (mapc 'gnus-summary-set-process-mark set))
6226
6227 ;;; Searching and stuff
6228
6229 (defun gnus-summary-search-group (&optional backward use-level)
6230   "Search for next unread newsgroup.
6231 If optional argument BACKWARD is non-nil, search backward instead."
6232   (save-excursion
6233     (set-buffer gnus-group-buffer)
6234     (when (gnus-group-search-forward
6235            backward nil (if use-level (gnus-group-group-level) nil))
6236       (gnus-group-group-name))))
6237
6238 (defun gnus-summary-best-group (&optional exclude-group)
6239   "Find the name of the best unread group.
6240 If EXCLUDE-GROUP, do not go to this group."
6241   (with-current-buffer gnus-group-buffer
6242     (save-excursion
6243       (gnus-group-best-unread-group exclude-group))))
6244
6245 (defun gnus-summary-find-next (&optional unread article backward)
6246   (if backward
6247       (gnus-summary-find-prev unread article)
6248     (let* ((dummy (gnus-summary-article-intangible-p))
6249            (article (or article (gnus-summary-article-number)))
6250            (data (gnus-data-find-list article))
6251            result)
6252       (when (and (not dummy)
6253                  (or (not gnus-summary-check-current)
6254                      (not unread)
6255                      (not (gnus-data-unread-p (car data)))))
6256         (setq data (cdr data)))
6257       (when (setq result
6258                   (if unread
6259                       (progn
6260                         (while data
6261                           (unless (memq (gnus-data-number (car data))
6262                                         (cond
6263                                          ((eq gnus-auto-goto-ignores
6264                                               'always-undownloaded)
6265                                           gnus-newsgroup-undownloaded)
6266                                          (gnus-plugged
6267                                           nil)
6268                                          ((eq gnus-auto-goto-ignores
6269                                               'unfetched)
6270                                           gnus-newsgroup-unfetched)
6271                                          ((eq gnus-auto-goto-ignores
6272                                               'undownloaded)
6273                                           gnus-newsgroup-undownloaded)))
6274                             (when (gnus-data-unread-p (car data))
6275                               (setq result (car data)
6276                                     data nil)))
6277                           (setq data (cdr data)))
6278                         result)
6279                     (car data)))
6280         (goto-char (gnus-data-pos result))
6281         (gnus-data-number result)))))
6282
6283 (defun gnus-summary-find-prev (&optional unread article)
6284   (let* ((eobp (eobp))
6285          (article (or article (gnus-summary-article-number)))
6286          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6287          result)
6288     (when (and (not eobp)
6289                (or (not gnus-summary-check-current)
6290                    (not unread)
6291                    (not (gnus-data-unread-p (car data)))))
6292       (setq data (cdr data)))
6293     (when (setq result
6294                 (if unread
6295                     (progn
6296                       (while data
6297                         (unless (memq (gnus-data-number (car data))
6298                                       (cond
6299                                        ((eq gnus-auto-goto-ignores
6300                                             'always-undownloaded)
6301                                         gnus-newsgroup-undownloaded)
6302                                        (gnus-plugged
6303                                         nil)
6304                                        ((eq gnus-auto-goto-ignores
6305                                             'unfetched)
6306                                         gnus-newsgroup-unfetched)
6307                                        ((eq gnus-auto-goto-ignores
6308                                             'undownloaded)
6309                                         gnus-newsgroup-undownloaded)))
6310                           (when (gnus-data-unread-p (car data))
6311                             (setq result (car data)
6312                                   data nil)))
6313                         (setq data (cdr data)))
6314                       result)
6315                   (car data)))
6316       (goto-char (gnus-data-pos result))
6317       (gnus-data-number result))))
6318
6319 (defun gnus-summary-find-subject (subject &optional unread backward article)
6320   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6321          (article (or article (gnus-summary-article-number)))
6322          (articles (gnus-data-list backward))
6323          (arts (gnus-data-find-list article articles))
6324          result)
6325     (when (or (not gnus-summary-check-current)
6326               (not unread)
6327               (not (gnus-data-unread-p (car arts))))
6328       (setq arts (cdr arts)))
6329     (while arts
6330       (and (or (not unread)
6331                (gnus-data-unread-p (car arts)))
6332            (vectorp (gnus-data-header (car arts)))
6333            (gnus-subject-equal
6334             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6335            (setq result (car arts)
6336                  arts nil))
6337       (setq arts (cdr arts)))
6338     (and result
6339          (goto-char (gnus-data-pos result))
6340          (gnus-data-number result))))
6341
6342 (defun gnus-summary-search-forward (&optional unread subject backward)
6343   "Search forward for an article.
6344 If UNREAD, look for unread articles.  If SUBJECT, look for
6345 articles with that subject.  If BACKWARD, search backward instead."
6346   (cond (subject (gnus-summary-find-subject subject unread backward))
6347         (backward (gnus-summary-find-prev unread))
6348         (t (gnus-summary-find-next unread))))
6349
6350 (defun gnus-recenter (&optional n)
6351   "Center point in window and redisplay frame.
6352 Also do horizontal recentering."
6353   (interactive "P")
6354   (when (and gnus-auto-center-summary
6355              (not (eq gnus-auto-center-summary 'vertical)))
6356     (gnus-horizontal-recenter))
6357   (recenter n))
6358
6359 (defun gnus-summary-recenter ()
6360   "Center point in the summary window.
6361 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6362 displayed, no centering will be performed."
6363   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6364   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6365   (interactive)
6366   ;; The user has to want it.
6367   (when gnus-auto-center-summary
6368     (let* ((top (cond ((< (window-height) 4) 0)
6369                       ((< (window-height) 7) 1)
6370                       (t (if (numberp gnus-auto-center-summary)
6371                              gnus-auto-center-summary
6372                            (/ (1- (window-height)) 2)))))
6373            (height (1- (window-height)))
6374            (bottom (save-excursion (goto-char (point-max))
6375                                    (forward-line (- height))
6376                                    (point)))
6377            (window (get-buffer-window (current-buffer))))
6378       (when (get-buffer-window gnus-article-buffer)
6379         ;; Only do recentering when the article buffer is displayed,
6380         ;; Set the window start to either `bottom', which is the biggest
6381         ;; possible valid number, or the second line from the top,
6382         ;; whichever is the least.
6383         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6384           (if (> bottom top-pos)
6385               ;; Keep the second line from the top visible
6386               (set-window-start window top-pos t)
6387             ;; Try to keep the bottom line visible; if it's partially
6388             ;; obscured, either scroll one more line to make it fully
6389             ;; visible, or revert to using TOP-POS.
6390             (save-excursion
6391               (goto-char (point-max))
6392               (forward-line -1)
6393               (let ((last-line-start (point)))
6394                 (goto-char bottom)
6395                 (set-window-start window (point) t)
6396                 (when (not (pos-visible-in-window-p last-line-start window))
6397                   (forward-line 1)
6398                   (set-window-start window (min (point) top-pos) t)))))))
6399       ;; Do horizontal recentering while we're at it.
6400       (when (and (get-buffer-window (current-buffer) t)
6401                  (not (eq gnus-auto-center-summary 'vertical)))
6402         (let ((selected (selected-window)))
6403           (select-window (get-buffer-window (current-buffer) t))
6404           (gnus-summary-position-point)
6405           (gnus-horizontal-recenter)
6406           (select-window selected))))))
6407
6408 (defun gnus-summary-jump-to-group (newsgroup)
6409   "Move point to NEWSGROUP in group mode buffer."
6410   ;; Keep update point of group mode buffer if visible.
6411   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6412       (save-window-excursion
6413         ;; Take care of tree window mode.
6414         (when (get-buffer-window gnus-group-buffer)
6415           (pop-to-buffer gnus-group-buffer))
6416         (gnus-group-jump-to-group newsgroup))
6417     (save-excursion
6418       ;; Take care of tree window mode.
6419       (if (get-buffer-window gnus-group-buffer)
6420           (pop-to-buffer gnus-group-buffer)
6421         (set-buffer gnus-group-buffer))
6422       (gnus-group-jump-to-group newsgroup))))
6423
6424 ;; This function returns a list of article numbers based on the
6425 ;; difference between the ranges of read articles in this group and
6426 ;; the range of active articles.
6427 (defun gnus-list-of-unread-articles (group)
6428   (let* ((read (gnus-info-read (gnus-get-info group)))
6429          (active (or (gnus-active group) (gnus-activate-group group)))
6430          (last (cdr active))
6431          first nlast unread)
6432     ;; If none are read, then all are unread.
6433     (if (not read)
6434         (setq first (car active))
6435       ;; If the range of read articles is a single range, then the
6436       ;; first unread article is the article after the last read
6437       ;; article.  Sounds logical, doesn't it?
6438       (if (and (not (listp (cdr read)))
6439                (or (< (car read) (car active))
6440                    (progn (setq read (list read))
6441                           nil)))
6442           (setq first (max (car active) (1+ (cdr read))))
6443         ;; `read' is a list of ranges.
6444         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6445                                   (caar read)))
6446                   1)
6447           (setq first (car active)))
6448         (while read
6449           (when first
6450             (while (< first nlast)
6451               (setq unread (cons first unread)
6452                     first (1+ first))))
6453           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6454           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6455           (setq read (cdr read)))))
6456     ;; And add the last unread articles.
6457     (while (<= first last)
6458       (setq unread (cons first unread)
6459             first (1+ first)))
6460     ;; Return the list of unread articles.
6461     (delq 0 (nreverse unread))))
6462
6463 (defun gnus-list-of-read-articles (group)
6464   "Return a list of unread, unticked and non-dormant articles."
6465   (let* ((info (gnus-get-info group))
6466          (marked (gnus-info-marks info))
6467          (active (gnus-active group)))
6468     (and info active
6469          (gnus-list-range-difference
6470           (gnus-list-range-difference
6471            (gnus-sorted-complement
6472             (gnus-uncompress-range active)
6473             (gnus-list-of-unread-articles group))
6474            (cdr (assq 'dormant marked)))
6475           (cdr (assq 'tick marked))))))
6476
6477 ;; This function returns a sequence of article numbers based on the
6478 ;; difference between the ranges of read articles in this group and
6479 ;; the range of active articles.
6480 (defun gnus-sequence-of-unread-articles (group)
6481   (let* ((read (gnus-info-read (gnus-get-info group)))
6482          (active (or (gnus-active group) (gnus-activate-group group)))
6483          (last (cdr active))
6484          first nlast unread)
6485     ;; If none are read, then all are unread.
6486     (if (not read)
6487         (setq first (car active))
6488       ;; If the range of read articles is a single range, then the
6489       ;; first unread article is the article after the last read
6490       ;; article.  Sounds logical, doesn't it?
6491       (if (and (not (listp (cdr read)))
6492                (or (< (car read) (car active))
6493                    (progn (setq read (list read))
6494                           nil)))
6495           (setq first (max (car active) (1+ (cdr read))))
6496         ;; `read' is a list of ranges.
6497         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6498                                   (caar read)))
6499                   1)
6500           (setq first (car active)))
6501         (while read
6502           (when first
6503             (push (cons first nlast) unread))
6504           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6505           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6506           (setq read (cdr read)))))
6507     ;; And add the last unread articles.
6508     (cond ((< first last)
6509            (push (cons first last) unread))
6510           ((= first last)
6511            (push first unread)))
6512     ;; Return the sequence of unread articles.
6513     (delq 0 (nreverse unread))))
6514
6515 ;; Various summary commands
6516
6517 (defun gnus-summary-select-article-buffer ()
6518   "Reconfigure windows to show article buffer."
6519   (interactive)
6520   (if (not (gnus-buffer-live-p gnus-article-buffer))
6521       (error "There is no article buffer for this summary buffer")
6522     (gnus-configure-windows 'article)
6523     (select-window (get-buffer-window gnus-article-buffer))))
6524
6525 (defun gnus-summary-universal-argument (arg)
6526   "Perform any operation on all articles that are process/prefixed."
6527   (interactive "P")
6528   (let ((articles (gnus-summary-work-articles arg))
6529         func article)
6530     (if (eq
6531          (setq
6532           func
6533           (key-binding
6534            (read-key-sequence
6535             (substitute-command-keys
6536              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6537          'undefined)
6538         (gnus-error 1 "Undefined key")
6539       (save-excursion
6540         (while articles
6541           (gnus-summary-goto-subject (setq article (pop articles)))
6542           (let (gnus-newsgroup-processable)
6543             (command-execute func))
6544           (gnus-summary-remove-process-mark article)))))
6545   (gnus-summary-position-point))
6546
6547 (defun gnus-summary-toggle-truncation (&optional arg)
6548   "Toggle truncation of summary lines.
6549 With ARG, turn line truncation on if ARG is positive."
6550   (interactive "P")
6551   (setq truncate-lines
6552         (if (null arg) (not truncate-lines)
6553           (> (prefix-numeric-value arg) 0)))
6554   (redraw-display))
6555
6556 (defun gnus-summary-find-for-reselect ()
6557   "Return the number of an article to stay on across a reselect.
6558 The current article is considered, then following articles, then previous
6559 articles.  An article is sought which is not cancelled and isn't a temporary
6560 insertion from another group.  If there's no such then return a dummy 0."
6561   (let (found)
6562     (dolist (rev '(nil t))
6563       (unless found      ; don't demand the reverse list if we don't need it
6564         (let ((data (gnus-data-find-list
6565                      (gnus-summary-article-number) (gnus-data-list rev))))
6566           (while (and data (not found))
6567             (if (and (< 0 (gnus-data-number (car data)))
6568                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6569                 (setq found (gnus-data-number (car data))))
6570             (setq data (cdr data))))))
6571     (or found 0)))
6572
6573 (defun gnus-summary-reselect-current-group (&optional all rescan)
6574   "Exit and then reselect the current newsgroup.
6575 The prefix argument ALL means to select all articles."
6576   (interactive "P")
6577   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6578     (error "Ephemeral groups can't be reselected"))
6579   (let ((current-subject (gnus-summary-find-for-reselect))
6580         (group gnus-newsgroup-name))
6581     (setq gnus-newsgroup-begin nil)
6582     (gnus-summary-exit nil 'leave-hidden)
6583     ;; We have to adjust the point of group mode buffer because
6584     ;; point was moved to the next unread newsgroup by exiting.
6585     (gnus-summary-jump-to-group group)
6586     (when rescan
6587       (save-excursion
6588         (save-window-excursion
6589           ;; Don't show group contents.
6590           (set-window-start (selected-window) (point-max))
6591           (gnus-group-get-new-news-this-group 1))))
6592     (gnus-group-read-group all t)
6593     (gnus-summary-goto-subject current-subject nil t)))
6594
6595 (defun gnus-summary-rescan-group (&optional all)
6596   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6597   (interactive "P")
6598   (gnus-summary-reselect-current-group all t))
6599
6600 (defun gnus-summary-update-info (&optional non-destructive)
6601   (save-excursion
6602     (let ((group gnus-newsgroup-name))
6603       (when group
6604         (when gnus-newsgroup-kill-headers
6605           (setq gnus-newsgroup-killed
6606                 (gnus-compress-sequence
6607                  (gnus-sorted-union
6608                   (gnus-list-range-intersection
6609                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6610                   gnus-newsgroup-unreads)
6611                  t)))
6612         (unless (listp (cdr gnus-newsgroup-killed))
6613           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6614         (let ((headers gnus-newsgroup-headers))
6615           ;; Set the new ranges of read articles.
6616           (with-current-buffer gnus-group-buffer
6617             (gnus-undo-force-boundary))
6618           (gnus-update-read-articles
6619            group (gnus-sorted-union
6620                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6621           ;; Set the current article marks.
6622           (let ((gnus-newsgroup-scored
6623                  (if (and (not gnus-save-score)
6624                           (not non-destructive))
6625                      nil
6626                    gnus-newsgroup-scored)))
6627             (save-excursion
6628               (gnus-update-marks)))
6629           ;; Do the cross-ref thing.
6630           (when gnus-use-cross-reference
6631             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6632           ;; Do not switch windows but change the buffer to work.
6633           (set-buffer gnus-group-buffer)
6634           (unless (gnus-ephemeral-group-p group)
6635             (gnus-group-update-group group)))))))
6636
6637 (defun gnus-summary-save-newsrc (&optional force)
6638   "Save the current number of read/marked articles in the dribble buffer.
6639 The dribble buffer will then be saved.
6640 If FORCE (the prefix), also save the .newsrc file(s)."
6641   (interactive "P")
6642   (gnus-summary-update-info t)
6643   (if force
6644       (gnus-save-newsrc-file)
6645     (gnus-dribble-save)))
6646
6647 (defun gnus-summary-exit (&optional temporary leave-hidden)
6648   "Exit reading current newsgroup, and then return to group selection mode.
6649 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6650   (interactive)
6651   (gnus-set-global-variables)
6652   (gnus-kill-save-kill-buffer)
6653   (gnus-async-halt-prefetch)
6654   (let* ((group gnus-newsgroup-name)
6655          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6656          (gnus-group-is-exiting-p t)
6657          (mode major-mode)
6658          (group-point nil)
6659          (buf (current-buffer)))
6660     (unless quit-config
6661       ;; Do adaptive scoring, and possibly save score files.
6662       (when gnus-newsgroup-adaptive
6663         (gnus-score-adaptive))
6664       (when gnus-use-scoring
6665         (gnus-score-save)))
6666     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6667     ;; If we have several article buffers, we kill them at exit.
6668     (unless gnus-single-article-buffer
6669       (gnus-kill-buffer gnus-original-article-buffer)
6670       (setq gnus-article-current nil))
6671     (when gnus-use-cache
6672       (gnus-cache-possibly-remove-articles)
6673       (gnus-cache-save-buffers))
6674     (gnus-async-prefetch-remove-group group)
6675     (when gnus-suppress-duplicates
6676       (gnus-dup-enter-articles))
6677     (when gnus-use-trees
6678       (gnus-tree-close group))
6679     (when gnus-use-cache
6680       (gnus-cache-write-active))
6681     ;; Remove entries for this group.
6682     (nnmail-purge-split-history (gnus-group-real-name group))
6683     ;; Make all changes in this group permanent.
6684     (unless quit-config
6685       (gnus-run-hooks 'gnus-exit-group-hook)
6686       (gnus-summary-update-info))
6687     (gnus-close-group group)
6688     ;; Make sure where we were, and go to next newsgroup.
6689     (set-buffer gnus-group-buffer)
6690     (unless quit-config
6691       (gnus-group-jump-to-group group))
6692     (gnus-run-hooks 'gnus-summary-exit-hook)
6693     (unless (or quit-config
6694                 ;; If this group has disappeared from the summary
6695                 ;; buffer, don't skip forwards.
6696                 (not (string= group (gnus-group-group-name))))
6697       (gnus-group-next-unread-group 1))
6698     (setq group-point (point))
6699     (if temporary
6700         nil                             ;Nothing to do.
6701       ;; If we have several article buffers, we kill them at exit.
6702       (unless gnus-single-article-buffer
6703         (gnus-kill-buffer gnus-article-buffer)
6704         (gnus-kill-buffer gnus-original-article-buffer)
6705         (setq gnus-article-current nil))
6706       (set-buffer buf)
6707       (if (not gnus-kill-summary-on-exit)
6708           (progn
6709             (gnus-deaden-summary)
6710             (setq mode nil))
6711         ;; We set all buffer-local variables to nil.  It is unclear why
6712         ;; this is needed, but if we don't, buffer-local variables are
6713         ;; not garbage-collected, it seems.  This would the lead to en
6714         ;; ever-growing Emacs.
6715         (gnus-summary-clear-local-variables)
6716         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6717           (gnus-summary-clear-local-variables))
6718         (when (get-buffer gnus-article-buffer)
6719           (bury-buffer gnus-article-buffer))
6720         ;; Return to group mode buffer.
6721         (when (eq mode 'gnus-summary-mode)
6722           (gnus-kill-buffer buf)))
6723       (setq gnus-current-select-method gnus-select-method)
6724       (set-buffer gnus-group-buffer)
6725       (if quit-config
6726           (gnus-handle-ephemeral-exit quit-config)
6727         (goto-char group-point)
6728         (unless leave-hidden
6729           (gnus-configure-windows 'group 'force))
6730         (unless (pos-visible-in-window-p)
6731           (forward-line (/ (static-if (featurep 'xemacs)
6732                                       (window-displayed-height)
6733                                       (1- (window-height)))
6734                            -2))
6735           (set-window-start (selected-window) (point))
6736           (goto-char group-point)))
6737       ;; Clear the current group name.
6738       (unless quit-config
6739         (setq gnus-newsgroup-name nil)))))
6740
6741 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6742 (defun gnus-summary-exit-no-update (&optional no-questions)
6743   "Quit reading current newsgroup without updating read article info."
6744   (interactive)
6745   (let* ((group gnus-newsgroup-name)
6746          (gnus-group-is-exiting-p t)
6747          (gnus-group-is-exiting-without-update-p t)
6748          (quit-config (gnus-group-quit-config group)))
6749     (when (or no-questions
6750               gnus-expert-user
6751               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6752       (gnus-async-halt-prefetch)
6753       (run-hooks 'gnus-summary-prepare-exit-hook)
6754       ;; If we have several article buffers, we kill them at exit.
6755       (unless gnus-single-article-buffer
6756         (gnus-kill-buffer gnus-article-buffer)
6757         (gnus-kill-buffer gnus-original-article-buffer)
6758         (setq gnus-article-current nil))
6759       (if (not gnus-kill-summary-on-exit)
6760           (gnus-deaden-summary)
6761         (gnus-close-group group)
6762         (gnus-summary-clear-local-variables)
6763         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6764           (gnus-summary-clear-local-variables))
6765         (gnus-kill-buffer gnus-summary-buffer))
6766       (unless gnus-single-article-buffer
6767         (setq gnus-article-current nil))
6768       (when gnus-use-trees
6769         (gnus-tree-close group))
6770       (gnus-async-prefetch-remove-group group)
6771       (when (get-buffer gnus-article-buffer)
6772         (bury-buffer gnus-article-buffer))
6773       ;; Return to the group buffer.
6774       (gnus-configure-windows 'group 'force)
6775       ;; Clear the current group name.
6776       (setq gnus-newsgroup-name nil)
6777       (unless (gnus-ephemeral-group-p group)
6778         (gnus-group-update-group group))
6779       (when (equal (gnus-group-group-name) group)
6780         (gnus-group-next-unread-group 1))
6781       (when quit-config
6782         (gnus-handle-ephemeral-exit quit-config)))))
6783
6784 (defun gnus-handle-ephemeral-exit (quit-config)
6785   "Handle movement when leaving an ephemeral group.
6786 The state which existed when entering the ephemeral is reset."
6787   (if (not (buffer-name (car quit-config)))
6788       (gnus-configure-windows 'group 'force)
6789     (set-buffer (car quit-config))
6790     (cond ((eq major-mode 'gnus-summary-mode)
6791            (gnus-set-global-variables))
6792           ((eq major-mode 'gnus-article-mode)
6793            (save-excursion
6794              ;; The `gnus-summary-buffer' variable may point
6795              ;; to the old summary buffer when using a single
6796              ;; article buffer.
6797              (unless (gnus-buffer-live-p gnus-summary-buffer)
6798                (set-buffer gnus-group-buffer))
6799              (set-buffer gnus-summary-buffer)
6800              (gnus-set-global-variables))))
6801     (if (or (eq (cdr quit-config) 'article)
6802             (eq (cdr quit-config) 'pick))
6803         (progn
6804           ;; The current article may be from the ephemeral group
6805           ;; thus it is best that we reload this article
6806           ;;
6807           ;; If we're exiting from a large digest, this can be
6808           ;; extremely slow.  So, it's better not to reload it. -- jh.
6809           ;;(gnus-summary-show-article)
6810           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6811               (gnus-configure-windows 'pick 'force)
6812             (gnus-configure-windows (cdr quit-config) 'force)))
6813       (gnus-configure-windows (cdr quit-config) 'force))
6814     (when (eq major-mode 'gnus-summary-mode)
6815       (gnus-summary-next-subject 1 nil t)
6816       (gnus-summary-recenter)
6817       (gnus-summary-position-point))))
6818
6819 (defun gnus-summary-preview-mime-message ()
6820   "MIME decode and play this message."
6821   (interactive)
6822   (let ((gnus-break-pages nil)
6823         (gnus-show-mime t))
6824     (gnus-summary-select-article gnus-show-all-headers t))
6825   (let ((w (get-buffer-window gnus-article-buffer)))
6826     (when w
6827       (select-window (get-buffer-window gnus-article-buffer)))))
6828
6829 ;;; Dead summaries.
6830
6831 (defvar gnus-dead-summary-mode-map nil)
6832
6833 (unless gnus-dead-summary-mode-map
6834   (setq gnus-dead-summary-mode-map (make-keymap))
6835   (suppress-keymap gnus-dead-summary-mode-map)
6836   (substitute-key-definition
6837    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6838   (dolist (key '("\C-d" "\r" "\177" [delete]))
6839     (define-key gnus-dead-summary-mode-map
6840       key 'gnus-summary-wake-up-the-dead))
6841   (dolist (key '("q" "Q"))
6842     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6843
6844 (defvar gnus-dead-summary-mode nil
6845   "Minor mode for Gnus summary buffers.")
6846
6847 (defun gnus-dead-summary-mode (&optional arg)
6848   "Minor mode for Gnus summary buffers."
6849   (interactive "P")
6850   (when (eq major-mode 'gnus-summary-mode)
6851     (make-local-variable 'gnus-dead-summary-mode)
6852     (setq gnus-dead-summary-mode
6853           (if (null arg) (not gnus-dead-summary-mode)
6854             (> (prefix-numeric-value arg) 0)))
6855     (when gnus-dead-summary-mode
6856       (add-minor-mode
6857        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6858
6859 (defun gnus-deaden-summary ()
6860   "Make the current summary buffer into a dead summary buffer."
6861   ;; Kill any previous dead summary buffer.
6862   (when (and gnus-dead-summary
6863              (buffer-name gnus-dead-summary))
6864     (with-current-buffer gnus-dead-summary
6865       (when gnus-dead-summary-mode
6866         (kill-buffer (current-buffer)))))
6867   ;; Make this the current dead summary.
6868   (setq gnus-dead-summary (current-buffer))
6869   (gnus-dead-summary-mode 1)
6870   (let ((name (buffer-name)))
6871     (when (string-match "Summary" name)
6872       (rename-buffer
6873        (concat (substring name 0 (match-beginning 0)) "Dead "
6874                (substring name (match-beginning 0)))
6875        t)
6876       (bury-buffer))))
6877
6878 (defun gnus-kill-or-deaden-summary (buffer)
6879   "Kill or deaden the summary BUFFER."
6880   (save-excursion
6881     (when (and (buffer-name buffer)
6882                (not gnus-single-article-buffer))
6883       (with-current-buffer buffer
6884         (gnus-kill-buffer gnus-article-buffer)
6885         (gnus-kill-buffer gnus-original-article-buffer)))
6886     (cond
6887      ;; Kill the buffer.
6888      (gnus-kill-summary-on-exit
6889       (when (and gnus-use-trees
6890                  (gnus-buffer-exists-p buffer))
6891         (save-excursion
6892           (set-buffer buffer)
6893           (gnus-tree-close gnus-newsgroup-name)))
6894       (gnus-kill-buffer buffer))
6895      ;; Deaden the buffer.
6896      ((gnus-buffer-exists-p buffer)
6897       (save-excursion
6898         (set-buffer buffer)
6899         (gnus-deaden-summary))))))
6900
6901 (defun gnus-summary-wake-up-the-dead (&rest args)
6902   "Wake up the dead summary buffer."
6903   (interactive)
6904   (gnus-dead-summary-mode -1)
6905   (let ((name (buffer-name)))
6906     (when (string-match "Dead " name)
6907       (rename-buffer
6908        (concat (substring name 0 (match-beginning 0))
6909                (substring name (match-end 0)))
6910        t)))
6911   (gnus-message 3 "This dead summary is now alive again"))
6912
6913 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6914 (defun gnus-summary-fetch-faq (&optional faq-dir)
6915   "Fetch the FAQ for the current group.
6916 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6917 in."
6918   (interactive
6919    (list
6920     (when current-prefix-arg
6921       (completing-read
6922        "FAQ dir: " (and (listp gnus-group-faq-directory)
6923                         (mapcar 'list
6924                                 gnus-group-faq-directory))))))
6925   (let (gnus-faq-buffer)
6926     (when (setq gnus-faq-buffer
6927                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6928       (gnus-configure-windows 'summary-faq))))
6929
6930 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6931 (defun gnus-summary-describe-group (&optional force)
6932   "Describe the current newsgroup."
6933   (interactive "P")
6934   (gnus-group-describe-group force gnus-newsgroup-name))
6935
6936 (defun gnus-summary-describe-briefly ()
6937   "Describe summary mode commands briefly."
6938   (interactive)
6939   (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")))
6940
6941 ;; Walking around group mode buffer from summary mode.
6942
6943 (defun gnus-summary-next-group (&optional no-article target-group backward)
6944   "Exit current newsgroup and then select next unread newsgroup.
6945 If prefix argument NO-ARTICLE is non-nil, no article is selected
6946 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6947 previous group instead."
6948   (interactive "P")
6949   ;; Stop pre-fetching.
6950   (gnus-async-halt-prefetch)
6951   (let ((current-group gnus-newsgroup-name)
6952         (current-buffer (current-buffer))
6953         entered)
6954     ;; First we semi-exit this group to update Xrefs and all variables.
6955     ;; We can't do a real exit, because the window conf must remain
6956     ;; the same in case the user is prompted for info, and we don't
6957     ;; want the window conf to change before that...
6958     (gnus-summary-exit t)
6959     (while (not entered)
6960       ;; Then we find what group we are supposed to enter.
6961       (set-buffer gnus-group-buffer)
6962       (gnus-group-jump-to-group current-group)
6963       (setq target-group
6964             (or target-group
6965                 (if (eq gnus-keep-same-level 'best)
6966                     (gnus-summary-best-group gnus-newsgroup-name)
6967                   (gnus-summary-search-group backward gnus-keep-same-level))))
6968       (if (not target-group)
6969           ;; There are no further groups, so we return to the group
6970           ;; buffer.
6971           (progn
6972             (gnus-message 5 "Returning to the group buffer")
6973             (setq entered t)
6974             (when (gnus-buffer-live-p current-buffer)
6975               (set-buffer current-buffer)
6976               (gnus-summary-exit))
6977             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6978         ;; We try to enter the target group.
6979         (gnus-group-jump-to-group target-group)
6980         (let ((unreads (gnus-group-group-unread)))
6981           (if (and (or (eq t unreads)
6982                        (and unreads (not (zerop unreads))))
6983                    (gnus-summary-read-group
6984                     target-group nil no-article
6985                     (and (buffer-name current-buffer) current-buffer)
6986                     nil backward))
6987               (setq entered t)
6988             (setq current-group target-group
6989                   target-group nil)))))))
6990
6991 (defun gnus-summary-prev-group (&optional no-article)
6992   "Exit current newsgroup and then select previous unread newsgroup.
6993 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6994   (interactive "P")
6995   (gnus-summary-next-group no-article nil t))
6996
6997 ;; Walking around summary lines.
6998
6999 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7000   "Go to the first subject satisfying any non-nil constraint.
7001 If UNREAD is non-nil, the article should be unread.
7002 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7003 If UNSEEN is non-nil, the article should be unseen.
7004 Returns the article selected or nil if there are no matching articles."
7005   (interactive "P")
7006   (cond
7007    ;; Empty summary.
7008    ((null gnus-newsgroup-data)
7009     (gnus-message 3 "No articles in the group")
7010     nil)
7011    ;; Pick the first article.
7012    ((not (or unread undownloaded unseen))
7013     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7014     (gnus-data-number (car gnus-newsgroup-data)))
7015    ;; Find the first unread article.
7016    (t
7017     (let ((data gnus-newsgroup-data))
7018       (while (and data
7019                   (let ((num (gnus-data-number (car data))))
7020                     (or (memq num gnus-newsgroup-unfetched)
7021                         (not (or (and unread
7022                                       (memq num gnus-newsgroup-unreads))
7023                                  (and undownloaded
7024                                       (memq num gnus-newsgroup-undownloaded))
7025                                  (and unseen
7026                                       (memq num gnus-newsgroup-unseen)))))))
7027         (setq data (cdr data)))
7028       (prog1
7029           (if data
7030               (progn
7031                 (goto-char (gnus-data-pos (car data)))
7032                 (gnus-data-number (car data)))
7033             (gnus-message 3 "No more%s articles"
7034                           (let* ((r (when unread " unread"))
7035                                  (d (when undownloaded " undownloaded"))
7036                                  (s (when unseen " unseen"))
7037                                  (l (delq nil (list r d s))))
7038                             (cond ((= 3 (length l))
7039                                    (concat r "," d ", or" s))
7040                                   ((= 2 (length l))
7041                                    (concat (car l) ", or" (cadr l)))
7042                                   ((= 1 (length l))
7043                                    (car l))
7044                                   (t
7045                                    ""))))
7046             nil
7047             )
7048         (gnus-summary-position-point))))))
7049
7050 (defun gnus-summary-next-subject (n &optional unread dont-display)
7051   "Go to next N'th summary line.
7052 If N is negative, go to the previous N'th subject line.
7053 If UNREAD is non-nil, only unread articles are selected.
7054 The difference between N and the actual number of steps taken is
7055 returned."
7056   (interactive "p")
7057   (let ((backward (< n 0))
7058         (n (abs n)))
7059     (while (and (> n 0)
7060                 (if backward
7061                     (gnus-summary-find-prev unread)
7062                   (gnus-summary-find-next unread)))
7063       (unless (zerop (setq n (1- n)))
7064         (gnus-summary-show-thread)))
7065     (when (/= 0 n)
7066       (gnus-message 7 "No more%s articles"
7067                     (if unread " unread" "")))
7068     (unless dont-display
7069       (gnus-summary-recenter)
7070       (gnus-summary-position-point))
7071     n))
7072
7073 (defun gnus-summary-next-unread-subject (n)
7074   "Go to next N'th unread summary line."
7075   (interactive "p")
7076   (gnus-summary-next-subject n t))
7077
7078 (defun gnus-summary-prev-subject (n &optional unread)
7079   "Go to previous N'th summary line.
7080 If optional argument UNREAD is non-nil, only unread article is selected."
7081   (interactive "p")
7082   (gnus-summary-next-subject (- n) unread))
7083
7084 (defun gnus-summary-prev-unread-subject (n)
7085   "Go to previous N'th unread summary line."
7086   (interactive "p")
7087   (gnus-summary-next-subject (- n) t))
7088
7089 (defun gnus-summary-goto-subjects (articles)
7090   "Insert the subject header for ARTICLES in the current buffer."
7091   (save-excursion
7092     (dolist (article articles)
7093       (gnus-summary-goto-subject article t)))
7094   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7095   (gnus-summary-position-point))
7096
7097 (defun gnus-summary-goto-subject (article &optional force silent)
7098   "Go the subject line of ARTICLE.
7099 If FORCE, also allow jumping to articles not currently shown."
7100   (interactive "nArticle number: ")
7101   (unless (numberp article)
7102     (error "Article %s is not a number" article))
7103   (let ((b (point))
7104         (data (gnus-data-find article)))
7105     ;; We read in the article if we have to.
7106     (and (not data)
7107          force
7108          (gnus-summary-insert-subject
7109           article
7110           (if (or (numberp force) (vectorp force)) force)
7111           t)
7112          (setq data (gnus-data-find article)))
7113     (goto-char b)
7114     (if (not data)
7115         (progn
7116           (unless silent
7117             (gnus-message 3 "Can't find article %d" article))
7118           nil)
7119       (let ((pt (gnus-data-pos data)))
7120         (goto-char pt)
7121         (gnus-summary-set-article-display-arrow pt))
7122       (gnus-summary-position-point)
7123       article)))
7124
7125 ;; Walking around summary lines with displaying articles.
7126
7127 (defun gnus-summary-expand-window (&optional arg)
7128   "Make the summary buffer take up the entire Emacs frame.
7129 Given a prefix, will force an `article' buffer configuration."
7130   (interactive "P")
7131   (if arg
7132       (gnus-configure-windows 'article 'force)
7133     (gnus-configure-windows 'summary 'force)))
7134
7135 (defun gnus-summary-display-article (article &optional all-header)
7136   "Display ARTICLE in article buffer."
7137   (when (gnus-buffer-live-p gnus-article-buffer)
7138     (with-current-buffer gnus-article-buffer
7139       (set-buffer-multibyte t)))
7140   (gnus-set-global-variables)
7141   (when (gnus-buffer-live-p gnus-article-buffer)
7142     (with-current-buffer gnus-article-buffer
7143       (setq gnus-article-charset gnus-newsgroup-charset)
7144       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7145       (set-buffer-multibyte t)))
7146   (if (null article)
7147       nil
7148     (prog1
7149         (if gnus-summary-display-article-function
7150             (funcall gnus-summary-display-article-function article all-header)
7151           (gnus-article-prepare article all-header))
7152       (with-current-buffer gnus-article-buffer
7153         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7154              nil))
7155       (gnus-run-hooks 'gnus-select-article-hook)
7156       (when (and gnus-current-article
7157                  (not (zerop gnus-current-article)))
7158         (gnus-summary-goto-subject gnus-current-article))
7159       (gnus-summary-recenter)
7160       (when (and gnus-use-trees gnus-show-threads)
7161         (gnus-possibly-generate-tree article)
7162         (gnus-highlight-selected-tree article))
7163       ;; Successfully display article.
7164       (gnus-article-set-window-start
7165        (cdr (assq article gnus-newsgroup-bookmarks))))))
7166
7167 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7168   "Select the current article.
7169 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7170 non-nil, the article will be re-fetched even if it already present in
7171 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7172 be displayed."
7173   ;; Make sure we are in the summary buffer to work around bbdb bug.
7174   (unless (eq major-mode 'gnus-summary-mode)
7175     (set-buffer gnus-summary-buffer))
7176   (let ((article (or article (gnus-summary-article-number)))
7177         (all-headers (not (not all-headers))) ;Must be T or NIL.
7178         gnus-summary-display-article-function)
7179     (and (not pseudo)
7180          (gnus-summary-article-pseudo-p article)
7181          (error "This is a pseudo-article"))
7182     (save-excursion
7183       (set-buffer gnus-summary-buffer)
7184       (if (or (and gnus-single-article-buffer
7185                    (or (null gnus-current-article)
7186                        (null gnus-article-current)
7187                        (null (get-buffer gnus-article-buffer))
7188                        (not (eq article (cdr gnus-article-current)))
7189                        (not (equal (car gnus-article-current)
7190                                    gnus-newsgroup-name))))
7191               (and (not gnus-single-article-buffer)
7192                    (or (null gnus-current-article)
7193                        (not (eq gnus-current-article article))))
7194               force)
7195           ;; The requested article is different from the current article.
7196           (progn
7197             (gnus-summary-display-article article all-headers)
7198             (gnus-article-set-window-start
7199              (cdr (assq article gnus-newsgroup-bookmarks)))
7200             article)
7201         'old))))
7202
7203 (defun gnus-summary-force-verify-and-decrypt ()
7204   "Display buttons for signed/encrypted parts and verify/decrypt them."
7205   (interactive)
7206   (let ((mm-verify-option 'known)
7207         (mm-decrypt-option 'known)
7208         (gnus-article-emulate-mime t)
7209         (gnus-buttonized-mime-types (append (list "multipart/signed"
7210                                                   "multipart/encrypted")
7211                                             gnus-buttonized-mime-types)))
7212     (gnus-summary-select-article nil 'force)))
7213
7214 (defun gnus-summary-set-current-mark (&optional current-mark)
7215   "Obsolete function."
7216   nil)
7217
7218 (defun gnus-summary-next-article (&optional unread subject backward push)
7219   "Select the next article.
7220 If UNREAD, only unread articles are selected.
7221 If SUBJECT, only articles with SUBJECT are selected.
7222 If BACKWARD, the previous article is selected instead of the next."
7223   (interactive "P")
7224   (cond
7225    ;; Is there such an article?
7226    ((and (gnus-summary-search-forward unread subject backward)
7227          (or (gnus-summary-display-article (gnus-summary-article-number))
7228              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7229     (gnus-summary-position-point))
7230    ;; If not, we try the first unread, if that is wanted.
7231    ((and subject
7232          gnus-auto-select-same
7233          (gnus-summary-first-unread-article))
7234     (gnus-summary-position-point)
7235     (gnus-message 6 "Wrapped"))
7236    ;; Try to get next/previous article not displayed in this group.
7237    ((and gnus-auto-extend-newsgroup
7238          (not unread) (not subject))
7239     (gnus-summary-goto-article
7240      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7241      nil (count-lines (point-min) (point))))
7242    ;; Go to next/previous group.
7243    (t
7244     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7245       (gnus-summary-jump-to-group gnus-newsgroup-name))
7246     (let ((cmd last-command-char)
7247           (point
7248            (with-current-buffer gnus-group-buffer
7249              (point)))
7250           (group
7251            (if (eq gnus-keep-same-level 'best)
7252                (gnus-summary-best-group gnus-newsgroup-name)
7253              (gnus-summary-search-group backward gnus-keep-same-level))))
7254       ;; For some reason, the group window gets selected.  We change
7255       ;; it back.
7256       (select-window (get-buffer-window (current-buffer)))
7257       ;; Select next unread newsgroup automagically.
7258       (cond
7259        ((or (not gnus-auto-select-next)
7260             (not cmd))
7261         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7262        ((or (eq gnus-auto-select-next 'quietly)
7263             (and (eq gnus-auto-select-next 'slightly-quietly)
7264                  push)
7265             (and (eq gnus-auto-select-next 'almost-quietly)
7266                  (gnus-summary-last-article-p)))
7267         ;; Select quietly.
7268         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7269             (gnus-summary-exit)
7270           (gnus-message 7 "No more%s articles (%s)..."
7271                         (if unread " unread" "")
7272                         (if group (concat "selecting " group)
7273                           "exiting"))
7274           (gnus-summary-next-group nil group backward)))
7275        (t
7276         (when (gnus-key-press-event-p last-input-event)
7277           (gnus-summary-walk-group-buffer
7278            gnus-newsgroup-name cmd unread backward point))))))))
7279
7280 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7281   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7282                       (?\C-p (gnus-group-prev-unread-group 1))))
7283         (cursor-in-echo-area t)
7284         keve key group ended prompt)
7285     (save-excursion
7286       (set-buffer gnus-group-buffer)
7287       (goto-char start)
7288       (setq group
7289             (if (eq gnus-keep-same-level 'best)
7290                 (gnus-summary-best-group gnus-newsgroup-name)
7291               (gnus-summary-search-group backward gnus-keep-same-level))))
7292     (while (not ended)
7293       (setq prompt
7294             (format
7295              "No more%s articles%s " (if unread " unread" "")
7296              (if (and group
7297                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7298                  (format " (Type %s for %s [%s])"
7299                          (single-key-description cmd)
7300                          (gnus-group-decoded-name group)
7301                          (gnus-group-unread group))
7302                (format " (Type %s to exit %s)"
7303                        (single-key-description cmd)
7304                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7305       ;; Confirm auto selection.
7306       (setq key (car (setq keve (gnus-read-event-char prompt)))
7307             ended t)
7308       (cond
7309        ((assq key keystrokes)
7310         (let ((obuf (current-buffer)))
7311           (switch-to-buffer gnus-group-buffer)
7312           (when group
7313             (gnus-group-jump-to-group group))
7314           (eval (cadr (assq key keystrokes)))
7315           (setq group (gnus-group-group-name))
7316           (switch-to-buffer obuf))
7317         (setq ended nil))
7318        ((equal key cmd)
7319         (if (or (not group)
7320                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7321             (gnus-summary-exit)
7322           (gnus-summary-next-group nil group backward)))
7323        (t
7324         (push (cdr keve) unread-command-events))))))
7325
7326 (defun gnus-summary-next-unread-article ()
7327   "Select unread article after current one."
7328   (interactive)
7329   (gnus-summary-next-article
7330    (or (not (eq gnus-summary-goto-unread 'never))
7331        (gnus-summary-last-article-p (gnus-summary-article-number)))
7332    (and gnus-auto-select-same
7333         (gnus-summary-article-subject))))
7334
7335 (defun gnus-summary-prev-article (&optional unread subject)
7336   "Select the article after the current one.
7337 If UNREAD is non-nil, only unread articles are selected."
7338   (interactive "P")
7339   (gnus-summary-next-article unread subject t))
7340
7341 (defun gnus-summary-prev-unread-article ()
7342   "Select unread article before current one."
7343   (interactive)
7344   (gnus-summary-prev-article
7345    (or (not (eq gnus-summary-goto-unread 'never))
7346        (gnus-summary-first-article-p (gnus-summary-article-number)))
7347    (and gnus-auto-select-same
7348         (gnus-summary-article-subject))))
7349
7350 (defun gnus-summary-next-page (&optional lines circular stop)
7351   "Show next page of the selected article.
7352 If at the end of the current article, select the next article.
7353 LINES says how many lines should be scrolled up.
7354
7355 If CIRCULAR is non-nil, go to the start of the article instead of
7356 selecting the next article when reaching the end of the current
7357 article.
7358
7359 If STOP is non-nil, just stop when reaching the end of the message.
7360
7361 Also see the variable `gnus-article-skip-boring'."
7362   (interactive "P")
7363   (setq gnus-summary-buffer (current-buffer))
7364   (gnus-set-global-variables)
7365   (let ((article (gnus-summary-article-number))
7366         (article-window (get-buffer-window gnus-article-buffer t))
7367         endp)
7368     ;; If the buffer is empty, we have no article.
7369     (unless article
7370       (error "No article to select"))
7371     (gnus-configure-windows 'article)
7372     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7373         (if (and (eq gnus-summary-goto-unread 'never)
7374                  (not (gnus-summary-last-article-p article)))
7375             (gnus-summary-next-article)
7376           (gnus-summary-next-unread-article))
7377       (if (or (null gnus-current-article)
7378               (null gnus-article-current)
7379               (/= article (cdr gnus-article-current))
7380               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7381           ;; Selected subject is different from current article's.
7382           (gnus-summary-display-article article)
7383         (when article-window
7384           (gnus-eval-in-buffer-window gnus-article-buffer
7385             (setq endp (or (gnus-article-next-page lines)
7386                            (gnus-article-only-boring-p))))
7387           (when endp
7388             (cond (stop
7389                    (gnus-message 3 "End of message"))
7390                   (circular
7391                    (gnus-summary-beginning-of-article))
7392                   (lines
7393                    (gnus-message 3 "End of message"))
7394                   ((null lines)
7395                    (if (and (eq gnus-summary-goto-unread 'never)
7396                             (not (gnus-summary-last-article-p article)))
7397                        (gnus-summary-next-article)
7398                      (gnus-summary-next-unread-article))))))))
7399     (gnus-summary-recenter)
7400     (gnus-summary-position-point)))
7401
7402 (defun gnus-summary-prev-page (&optional lines move)
7403   "Show previous page of selected article.
7404 Argument LINES specifies lines to be scrolled down.
7405 If MOVE, move to the previous unread article if point is at
7406 the beginning of the buffer."
7407   (interactive "P")
7408   (let ((article (gnus-summary-article-number))
7409         (article-window (get-buffer-window gnus-article-buffer t))
7410         endp)
7411     (gnus-configure-windows 'article)
7412     (if (or (null gnus-current-article)
7413             (null gnus-article-current)
7414             (/= article (cdr gnus-article-current))
7415             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7416         ;; Selected subject is different from current article's.
7417         (gnus-summary-display-article article)
7418       (gnus-summary-recenter)
7419       (when article-window
7420         (gnus-eval-in-buffer-window gnus-article-buffer
7421           (setq endp (gnus-article-prev-page lines)))
7422         (when (and move endp)
7423           (cond (lines
7424                  (gnus-message 3 "Beginning of message"))
7425                 ((null lines)
7426                  (if (and (eq gnus-summary-goto-unread 'never)
7427                           (not (gnus-summary-first-article-p article)))
7428                      (gnus-summary-prev-article)
7429                    (gnus-summary-prev-unread-article))))))))
7430   (gnus-summary-position-point))
7431
7432 (defun gnus-summary-prev-page-or-article (&optional lines)
7433   "Show previous page of selected article.
7434 Argument LINES specifies lines to be scrolled down.
7435 If at the beginning of the article, go to the next article."
7436   (interactive "P")
7437   (gnus-summary-prev-page lines t))
7438
7439 (defun gnus-summary-scroll-up (lines)
7440   "Scroll up (or down) one line current article.
7441 Argument LINES specifies lines to be scrolled up (or down if negative)."
7442   (interactive "p")
7443   (gnus-configure-windows 'article)
7444   (gnus-summary-show-thread)
7445   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7446     (gnus-eval-in-buffer-window gnus-article-buffer
7447       (cond ((> lines 0)
7448              (when (gnus-article-next-page lines)
7449                (gnus-message 3 "End of message")))
7450             ((< lines 0)
7451              (gnus-article-prev-page (- lines))))))
7452   (gnus-summary-recenter)
7453   (gnus-summary-position-point))
7454
7455 (defun gnus-summary-scroll-down (lines)
7456   "Scroll down (or up) one line current article.
7457 Argument LINES specifies lines to be scrolled down (or up if negative)."
7458   (interactive "p")
7459   (gnus-summary-scroll-up (- lines)))
7460
7461 (defun gnus-summary-next-same-subject ()
7462   "Select next article which has the same subject as current one."
7463   (interactive)
7464   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7465
7466 (defun gnus-summary-prev-same-subject ()
7467   "Select previous article which has the same subject as current one."
7468   (interactive)
7469   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7470
7471 (defun gnus-summary-next-unread-same-subject ()
7472   "Select next unread article which has the same subject as current one."
7473   (interactive)
7474   (gnus-summary-next-article t (gnus-summary-article-subject)))
7475
7476 (defun gnus-summary-prev-unread-same-subject ()
7477   "Select previous unread article which has the same subject as current one."
7478   (interactive)
7479   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7480
7481 (defun gnus-summary-first-unread-article ()
7482   "Select the first unread article.
7483 Return nil if there are no unread articles."
7484   (interactive)
7485   (prog1
7486       (when (gnus-summary-first-subject t)
7487         (gnus-summary-show-thread)
7488         (gnus-summary-first-subject t)
7489         (gnus-summary-display-article (gnus-summary-article-number)))
7490     (gnus-summary-position-point)))
7491
7492 (defun gnus-summary-first-unread-subject ()
7493   "Place the point on the subject line of the first unread article.
7494 Return nil if there are no unread articles."
7495   (interactive)
7496   (prog1
7497       (when (gnus-summary-first-subject t)
7498         (gnus-summary-show-thread)
7499         (gnus-summary-first-subject t))
7500     (gnus-summary-position-point)))
7501
7502 (defun gnus-summary-first-unseen-subject ()
7503   "Place the point on the subject line of the first unseen article.
7504 Return nil if there are no unseen articles."
7505   (interactive)
7506   (prog1
7507       (when (gnus-summary-first-subject nil nil t)
7508         (gnus-summary-show-thread)
7509         (gnus-summary-first-subject nil nil t))
7510     (gnus-summary-position-point)))
7511
7512 (defun gnus-summary-first-unseen-or-unread-subject ()
7513   "Place the point on the subject line of the first unseen article or,
7514 if all article have been seen, on the subject line of the first unread
7515 article."
7516   (interactive)
7517   (prog1
7518       (unless (when (gnus-summary-first-subject nil nil t)
7519                 (gnus-summary-show-thread)
7520                 (gnus-summary-first-subject nil nil t))
7521         (when (gnus-summary-first-subject t)
7522           (gnus-summary-show-thread)
7523           (gnus-summary-first-subject t)))
7524     (gnus-summary-position-point)))
7525
7526 (defun gnus-summary-first-article ()
7527   "Select the first article.
7528 Return nil if there are no articles."
7529   (interactive)
7530   (prog1
7531       (when (gnus-summary-first-subject)
7532         (gnus-summary-show-thread)
7533         (gnus-summary-first-subject)
7534         (gnus-summary-display-article (gnus-summary-article-number)))
7535     (gnus-summary-position-point)))
7536
7537 (defun gnus-summary-best-unread-article (&optional arg)
7538   "Select the unread article with the highest score.
7539 If given a prefix argument, select the next unread article that has a
7540 score higher than the default score."
7541   (interactive "P")
7542   (let ((article (if arg
7543                      (gnus-summary-better-unread-subject)
7544                    (gnus-summary-best-unread-subject))))
7545     (if article
7546         (gnus-summary-goto-article article)
7547       (error "No unread articles"))))
7548
7549 (defun gnus-summary-best-unread-subject ()
7550   "Select the unread subject with the highest score."
7551   (interactive)
7552   (let ((best -1000000)
7553         (data gnus-newsgroup-data)
7554         article score)
7555     (while data
7556       (and (gnus-data-unread-p (car data))
7557            (> (setq score
7558                     (gnus-summary-article-score (gnus-data-number (car data))))
7559               best)
7560            (setq best score
7561                  article (gnus-data-number (car data))))
7562       (setq data (cdr data)))
7563     (when article
7564       (gnus-summary-goto-subject article))
7565     (gnus-summary-position-point)
7566     article))
7567
7568 (defun gnus-summary-better-unread-subject ()
7569   "Select the first unread subject that has a score over the default score."
7570   (interactive)
7571   (let ((data gnus-newsgroup-data)
7572         article score)
7573     (while (and (setq article (gnus-data-number (car data)))
7574                 (or (gnus-data-read-p (car data))
7575                     (not (> (gnus-summary-article-score article)
7576                             gnus-summary-default-score))))
7577       (setq data (cdr data)))
7578     (when article
7579       (gnus-summary-goto-subject article))
7580     (gnus-summary-position-point)
7581     article))
7582
7583 (defun gnus-summary-last-subject ()
7584   "Go to the last displayed subject line in the group."
7585   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7586     (when article
7587       (gnus-summary-goto-subject article))))
7588
7589 (defun gnus-summary-goto-article (article &optional all-headers force)
7590   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7591 If ALL-HEADERS is non-nil, no header lines are hidden.
7592 If FORCE, go to the article even if it isn't displayed.  If FORCE
7593 is a number, it is the line the article is to be displayed on."
7594   (interactive
7595    (list
7596     (completing-read
7597      "Article number or Message-ID: "
7598      (mapcar (lambda (number) (list (int-to-string number)))
7599              gnus-newsgroup-limit))
7600     current-prefix-arg
7601     t))
7602   (prog1
7603       (if (and (stringp article)
7604                (string-match "@\\|%40" article))
7605           (gnus-summary-refer-article article)
7606         (when (stringp article)
7607           (setq article (string-to-number article)))
7608         (if (gnus-summary-goto-subject article force)
7609             (gnus-summary-display-article article all-headers)
7610           (gnus-message 4 "Couldn't go to article %s" article) nil))
7611     (gnus-summary-position-point)))
7612
7613 (defun gnus-summary-goto-last-article ()
7614   "Go to the previously read article."
7615   (interactive)
7616   (prog1
7617       (when gnus-last-article
7618         (gnus-summary-goto-article gnus-last-article nil t))
7619     (gnus-summary-position-point)))
7620
7621 (defun gnus-summary-pop-article (number)
7622   "Pop one article off the history and go to the previous.
7623 NUMBER articles will be popped off."
7624   (interactive "p")
7625   (let (to)
7626     (setq gnus-newsgroup-history
7627           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7628     (if to
7629         (gnus-summary-goto-article (car to) nil t)
7630       (error "Article history empty")))
7631   (gnus-summary-position-point))
7632
7633 ;; Summary commands and functions for limiting the summary buffer.
7634
7635 (defun gnus-summary-limit-to-articles (n)
7636   "Limit the summary buffer to the next N articles.
7637 If not given a prefix, use the process marked articles instead."
7638   (interactive "P")
7639   (prog1
7640       (let ((articles (gnus-summary-work-articles n)))
7641         (setq gnus-newsgroup-processable nil)
7642         (gnus-summary-limit articles))
7643     (gnus-summary-position-point)))
7644
7645 (defun gnus-summary-pop-limit (&optional total)
7646   "Restore the previous limit.
7647 If given a prefix, remove all limits."
7648   (interactive "P")
7649   (when total
7650     (setq gnus-newsgroup-limits
7651           (list (mapcar (lambda (h) (mail-header-number h))
7652                         gnus-newsgroup-headers))))
7653   (unless gnus-newsgroup-limits
7654     (error "No limit to pop"))
7655   (prog1
7656       (gnus-summary-limit nil 'pop)
7657     (gnus-summary-position-point)))
7658
7659 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7660   "Limit the summary buffer to articles that have subjects that match a regexp.
7661 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7662   (interactive
7663    (list (read-string (if current-prefix-arg
7664                           "Exclude subject (regexp): "
7665                         "Limit to subject (regexp): "))
7666          nil current-prefix-arg))
7667   (unless header
7668     (setq header "subject"))
7669   (when (not (equal "" subject))
7670     (prog1
7671         (let ((articles (gnus-summary-find-matching
7672                          (or header "subject") subject 'all nil nil
7673                          not-matching)))
7674           (unless articles
7675             (error "Found no matches for \"%s\"" subject))
7676           (gnus-summary-limit articles))
7677       (gnus-summary-position-point))))
7678
7679 (defun gnus-summary-limit-to-author (from &optional not-matching)
7680   "Limit the summary buffer to articles that have authors that match a regexp.
7681 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7682   (interactive
7683    (list (read-string (if current-prefix-arg
7684                           "Exclude author (regexp): "
7685                         "Limit to author (regexp): "))
7686          current-prefix-arg))
7687   (gnus-summary-limit-to-subject from "from" not-matching))
7688
7689 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7690   "Limit the summary buffer to articles with the given RECIPIENT.
7691
7692 If NOT-MATCHING, exclude RECIPIENT.
7693
7694 To and Cc headers are checked.  You need to include them in
7695 `nnmail-extra-headers'."
7696   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7697   (interactive
7698    (list (read-string (format "%s recipient (regexp): "
7699                               (if current-prefix-arg "Exclude" "Limit to")))
7700          current-prefix-arg))
7701   (when (not (equal "" recipient))
7702     (prog1 (let* ((to
7703                    (if (memq 'To nnmail-extra-headers)
7704                        (gnus-summary-find-matching
7705                         (cons 'extra 'To) recipient 'all nil nil
7706                         not-matching)
7707                      (gnus-message
7708                       1 "`To' isn't present in `nnmail-extra-headers'")
7709                      (sit-for 1)
7710                      nil))
7711                   (cc
7712                    (if (memq 'Cc nnmail-extra-headers)
7713                        (gnus-summary-find-matching
7714                         (cons 'extra 'Cc) recipient 'all nil nil
7715                         not-matching)
7716                      (gnus-message
7717                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7718                      (sit-for 1)
7719                      nil))
7720                   (articles
7721                    (if not-matching
7722                        ;; We need the numbers that are in both lists:
7723                        (mapcar (lambda (a)
7724                                  (and (memq a to) a))
7725                                cc)
7726                      (nconc to cc))))
7727              (unless articles
7728                (error "Found no matches for \"%s\"" recipient))
7729              (gnus-summary-limit articles))
7730       (gnus-summary-position-point))))
7731
7732 (defun gnus-summary-limit-to-age (age &optional younger-p)
7733   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7734 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7735 articles that are younger than AGE days."
7736   (interactive
7737    (let ((younger current-prefix-arg)
7738          (days-got nil)
7739          days)
7740      (while (not days-got)
7741        (setq days (if younger
7742                       (read-string "Limit to articles younger than (in days, older when negative): ")
7743                     (read-string
7744                      "Limit to articles older than (in days, younger when negative): ")))
7745        (when (> (length days) 0)
7746          (setq days (read days)))
7747        (if (numberp days)
7748            (progn
7749              (setq days-got t)
7750              (when (< days 0)
7751                (setq younger (not younger))
7752                (setq days (* days -1))))
7753          (message "Please enter a number.")
7754          (sleep-for 1)))
7755      (list days younger)))
7756   (prog1
7757       (let ((data gnus-newsgroup-data)
7758             (cutoff (days-to-time age))
7759             articles d date is-younger)
7760         (while (setq d (pop data))
7761           (when (and (vectorp (gnus-data-header d))
7762                      (setq date (mail-header-date (gnus-data-header d))))
7763             (setq is-younger (time-less-p
7764                               (time-since (condition-case ()
7765                                               (date-to-time date)
7766                                             (error '(0 0))))
7767                               cutoff))
7768             (when (if younger-p
7769                       is-younger
7770                     (not is-younger))
7771               (push (gnus-data-number d) articles))))
7772         (gnus-summary-limit (nreverse articles)))
7773     (gnus-summary-position-point)))
7774
7775 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7776   "Limit the summary buffer to articles that match an 'extra' header."
7777   (interactive
7778    (let ((header
7779           (intern
7780            (gnus-completing-read-with-default
7781             (symbol-name (car gnus-extra-headers))
7782             (if current-prefix-arg
7783                 "Exclude extra header:"
7784               "Limit extra header:")
7785             (mapcar (lambda (x)
7786                       (cons (symbol-name x) x))
7787                     gnus-extra-headers)
7788             nil
7789             t))))
7790      (list header
7791            (read-string (format "%s header %s (regexp): "
7792                                 (if current-prefix-arg "Exclude" "Limit to")
7793                                 header))
7794            current-prefix-arg)))
7795   (when (not (equal "" regexp))
7796     (prog1
7797         (let ((articles (gnus-summary-find-matching
7798                          (cons 'extra header) regexp 'all nil nil
7799                          not-matching)))
7800           (unless articles
7801             (error "Found no matches for \"%s\"" regexp))
7802           (gnus-summary-limit articles))
7803       (gnus-summary-position-point))))
7804
7805 (defun gnus-summary-limit-to-display-predicate ()
7806   "Limit the summary buffer to the predicated in the `display' group parameter."
7807   (interactive)
7808   (unless gnus-newsgroup-display
7809     (error "There is no `display' group parameter"))
7810   (let (articles)
7811     (dolist (number gnus-newsgroup-articles)
7812       (when (funcall gnus-newsgroup-display)
7813         (push number articles)))
7814     (gnus-summary-limit articles))
7815   (gnus-summary-position-point))
7816
7817 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7818 (make-obsolete
7819  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7820
7821 (defun gnus-summary-limit-to-unread (&optional all)
7822   "Limit the summary buffer to articles that are not marked as read.
7823 If ALL is non-nil, limit strictly to unread articles."
7824   (interactive "P")
7825   (if all
7826       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7827     (gnus-summary-limit-to-marks
7828      ;; Concat all the marks that say that an article is read and have
7829      ;; those removed.
7830      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7831            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7832            gnus-low-score-mark gnus-expirable-mark
7833            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7834            gnus-duplicate-mark gnus-souped-mark)
7835      'reverse)))
7836
7837 (defun gnus-summary-limit-to-replied (&optional unreplied)
7838   "Limit the summary buffer to replied articles.
7839 If UNREPLIED (the prefix), limit to unreplied articles."
7840   (interactive "P")
7841   (if unreplied
7842       (gnus-summary-limit
7843        (gnus-set-difference gnus-newsgroup-articles
7844         gnus-newsgroup-replied))
7845     (gnus-summary-limit gnus-newsgroup-replied))
7846   (gnus-summary-position-point))
7847
7848 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7849 (make-obsolete 'gnus-summary-delete-marked-with
7850                'gnus-summary-limit-exclude-marks)
7851
7852 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7853   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7854 If REVERSE, limit the summary buffer to articles that are marked
7855 with MARKS.  MARKS can either be a string of marks or a list of marks.
7856 Returns how many articles were removed."
7857   (interactive "sMarks: ")
7858   (gnus-summary-limit-to-marks marks t))
7859
7860 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7861   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7862 If REVERSE (the prefix), limit the summary buffer to articles that are
7863 not marked with MARKS.  MARKS can either be a string of marks or a
7864 list of marks.
7865 Returns how many articles were removed."
7866   (interactive "sMarks: \nP")
7867   (prog1
7868       (let ((data gnus-newsgroup-data)
7869             (marks (if (listp marks) marks
7870                      (append marks nil))) ; Transform to list.
7871             articles)
7872         (while data
7873           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7874                   (memq (gnus-data-mark (car data)) marks))
7875             (push (gnus-data-number (car data)) articles))
7876           (setq data (cdr data)))
7877         (gnus-summary-limit articles))
7878     (gnus-summary-position-point)))
7879
7880 (defun gnus-summary-limit-to-score (score)
7881   "Limit to articles with score at or above SCORE."
7882   (interactive "NLimit to articles with score of at least: ")
7883   (let ((data gnus-newsgroup-data)
7884         articles)
7885     (while data
7886       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7887                 score)
7888         (push (gnus-data-number (car data)) articles))
7889       (setq data (cdr data)))
7890     (prog1
7891         (gnus-summary-limit articles)
7892       (gnus-summary-position-point))))
7893
7894 (defun gnus-summary-limit-to-unseen ()
7895   "Limit to unseen articles."
7896   (interactive)
7897   (prog1
7898       (gnus-summary-limit gnus-newsgroup-unseen)
7899     (gnus-summary-position-point)))
7900
7901 (defun gnus-summary-limit-include-thread (id)
7902   "Display all the hidden articles that is in the thread with ID in it.
7903 When called interactively, ID is the Message-ID of the current
7904 article."
7905   (interactive (list (mail-header-id (gnus-summary-article-header))))
7906   (let ((articles (gnus-articles-in-thread
7907                    (gnus-id-to-thread (gnus-root-id id)))))
7908     (prog1
7909         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7910       (gnus-summary-limit-include-matching-articles
7911        "subject"
7912        (regexp-quote (gnus-simplify-subject-re
7913                       (mail-header-subject (gnus-id-to-header id)))))
7914       (gnus-summary-position-point))))
7915
7916 (defun gnus-summary-limit-include-matching-articles (header regexp)
7917   "Display all the hidden articles that have HEADERs that match REGEXP."
7918   (interactive (list (read-string "Match on header: ")
7919                      (read-string "Regexp: ")))
7920   (let ((articles (gnus-find-matching-articles header regexp)))
7921     (prog1
7922         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7923       (gnus-summary-position-point))))
7924
7925 (defun gnus-summary-insert-dormant-articles ()
7926   "Insert all the dormant articles for this group into the current buffer."
7927   (interactive)
7928   (let ((gnus-verbose (max 6 gnus-verbose)))
7929     (if (not gnus-newsgroup-dormant)
7930         (gnus-message 3 "No cached articles for this group")
7931       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7932
7933 (defun gnus-summary-limit-include-dormant ()
7934   "Display all the hidden articles that are marked as dormant.
7935 Note that this command only works on a subset of the articles currently
7936 fetched for this group."
7937   (interactive)
7938   (unless gnus-newsgroup-dormant
7939     (error "There are no dormant articles in this group"))
7940   (prog1
7941       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7942     (gnus-summary-position-point)))
7943
7944 (defun gnus-summary-limit-exclude-dormant ()
7945   "Hide all dormant articles."
7946   (interactive)
7947   (prog1
7948       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7949     (gnus-summary-position-point)))
7950
7951 (defun gnus-summary-limit-exclude-childless-dormant ()
7952   "Hide all dormant articles that have no children."
7953   (interactive)
7954   (let ((data (gnus-data-list t))
7955         articles d children)
7956     ;; Find all articles that are either not dormant or have
7957     ;; children.
7958     (while (setq d (pop data))
7959       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7960                 (and (setq children
7961                            (gnus-article-children (gnus-data-number d)))
7962                      (let (found)
7963                        (while children
7964                          (when (memq (car children) articles)
7965                            (setq children nil
7966                                  found t))
7967                          (pop children))
7968                        found)))
7969         (push (gnus-data-number d) articles)))
7970     ;; Do the limiting.
7971     (prog1
7972         (gnus-summary-limit articles)
7973       (gnus-summary-position-point))))
7974
7975 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7976   "Mark all unread excluded articles as read.
7977 If ALL, mark even excluded ticked and dormants as read."
7978   (interactive "P")
7979   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7980   (let ((articles (gnus-sorted-ndifference
7981                    (sort
7982                     (mapcar (lambda (h) (mail-header-number h))
7983                             gnus-newsgroup-headers)
7984                     '<)
7985                    gnus-newsgroup-limit))
7986         article)
7987     (setq gnus-newsgroup-unreads
7988           (gnus-sorted-intersection gnus-newsgroup-unreads
7989                                     gnus-newsgroup-limit))
7990     (if all
7991         (setq gnus-newsgroup-dormant nil
7992               gnus-newsgroup-marked nil
7993               gnus-newsgroup-reads
7994               (nconc
7995                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7996                gnus-newsgroup-reads))
7997       (while (setq article (pop articles))
7998         (unless (or (memq article gnus-newsgroup-dormant)
7999                     (memq article gnus-newsgroup-marked))
8000           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8001
8002 (defun gnus-summary-limit (articles &optional pop)
8003   (if pop
8004       ;; We pop the previous limit off the stack and use that.
8005       (setq articles (car gnus-newsgroup-limits)
8006             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8007     ;; We use the new limit, so we push the old limit on the stack.
8008     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8009   ;; Set the limit.
8010   (setq gnus-newsgroup-limit articles)
8011   (let ((total (length gnus-newsgroup-data))
8012         (data (gnus-data-find-list (gnus-summary-article-number)))
8013         (gnus-summary-mark-below nil)   ; Inhibit this.
8014         found)
8015     ;; This will do all the work of generating the new summary buffer
8016     ;; according to the new limit.
8017     (gnus-summary-prepare)
8018     ;; Hide any threads, possibly.
8019     (gnus-summary-maybe-hide-threads)
8020     ;; Try to return to the article you were at, or one in the
8021     ;; neighborhood.
8022     (when data
8023       ;; We try to find some article after the current one.
8024       (while data
8025         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8026           (setq data nil
8027                 found t))
8028         (setq data (cdr data))))
8029     (unless found
8030       ;; If there is no data, that means that we were after the last
8031       ;; article.  The same goes when we can't find any articles
8032       ;; after the current one.
8033       (goto-char (point-max))
8034       (gnus-summary-find-prev))
8035     (gnus-set-mode-line 'summary)
8036     ;; We return how many articles were removed from the summary
8037     ;; buffer as a result of the new limit.
8038     (- total (length gnus-newsgroup-data))))
8039
8040 (defsubst gnus-invisible-cut-children (threads)
8041   (let ((num 0))
8042     (while threads
8043       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8044         (incf num))
8045       (pop threads))
8046     (< num 2)))
8047
8048 (defsubst gnus-cut-thread (thread)
8049   "Go forwards in the thread until we find an article that we want to display."
8050   (when (or (eq gnus-fetch-old-headers 'some)
8051             (eq gnus-fetch-old-headers 'invisible)
8052             (numberp gnus-fetch-old-headers)
8053             (eq gnus-build-sparse-threads 'some)
8054             (eq gnus-build-sparse-threads 'more))
8055     ;; Deal with old-fetched headers and sparse threads.
8056     (while (and
8057             thread
8058             (or
8059              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8060              (gnus-summary-article-ancient-p
8061               (mail-header-number (car thread))))
8062             (if (or (<= (length (cdr thread)) 1)
8063                     (eq gnus-fetch-old-headers 'invisible))
8064                 (setq gnus-newsgroup-limit
8065                       (delq (mail-header-number (car thread))
8066                             gnus-newsgroup-limit)
8067                       thread (cadr thread))
8068               (when (gnus-invisible-cut-children (cdr thread))
8069                 (let ((th (cdr thread)))
8070                   (while th
8071                     (if (memq (mail-header-number (caar th))
8072                               gnus-newsgroup-limit)
8073                         (setq thread (car th)
8074                               th nil)
8075                       (setq th (cdr th))))))))))
8076   thread)
8077
8078 (defun gnus-cut-threads (threads)
8079   "Cut off all uninteresting articles from the beginning of THREADS."
8080   (when (or (eq gnus-fetch-old-headers 'some)
8081             (eq gnus-fetch-old-headers 'invisible)
8082             (numberp gnus-fetch-old-headers)
8083             (eq gnus-build-sparse-threads 'some)
8084             (eq gnus-build-sparse-threads 'more))
8085     (let ((th threads))
8086       (while th
8087         (setcar th (gnus-cut-thread (car th)))
8088         (setq th (cdr th)))))
8089   ;; Remove nixed out threads.
8090   (delq nil threads))
8091
8092 (defun gnus-summary-initial-limit (&optional show-if-empty)
8093   "Figure out what the initial limit is supposed to be on group entry.
8094 This entails weeding out unwanted dormants, low-scored articles,
8095 fetch-old-headers verbiage, and so on."
8096   ;; Most groups have nothing to remove.
8097   (if (or gnus-inhibit-limiting
8098           (and (null gnus-newsgroup-dormant)
8099                (eq gnus-newsgroup-display 'gnus-not-ignore)
8100                (not (eq gnus-fetch-old-headers 'some))
8101                (not (numberp gnus-fetch-old-headers))
8102                (not (eq gnus-fetch-old-headers 'invisible))
8103                (null gnus-summary-expunge-below)
8104                (not (eq gnus-build-sparse-threads 'some))
8105                (not (eq gnus-build-sparse-threads 'more))
8106                (null gnus-thread-expunge-below)
8107                (not gnus-use-nocem)))
8108       ()                                ; Do nothing.
8109     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8110     (setq gnus-newsgroup-limit nil)
8111     (mapatoms
8112      (lambda (node)
8113        (unless (car (symbol-value node))
8114          ;; These threads have no parents -- they are roots.
8115          (let ((nodes (cdr (symbol-value node)))
8116                thread)
8117            (while nodes
8118              (if (and gnus-thread-expunge-below
8119                       (< (gnus-thread-total-score (car nodes))
8120                          gnus-thread-expunge-below))
8121                  (gnus-expunge-thread (pop nodes))
8122                (setq thread (pop nodes))
8123                (gnus-summary-limit-children thread))))))
8124      gnus-newsgroup-dependencies)
8125     ;; If this limitation resulted in an empty group, we might
8126     ;; pop the previous limit and use it instead.
8127     (when (and (not gnus-newsgroup-limit)
8128                show-if-empty)
8129       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8130     gnus-newsgroup-limit))
8131
8132 (defun gnus-summary-limit-children (thread)
8133   "Return 1 if this subthread is visible and 0 if it is not."
8134   ;; First we get the number of visible children to this thread.  This
8135   ;; is done by recursing down the thread using this function, so this
8136   ;; will really go down to a leaf article first, before slowly
8137   ;; working its way up towards the root.
8138   (when thread
8139     (let* ((max-lisp-eval-depth 5000)
8140            (children
8141            (if (cdr thread)
8142                (apply '+ (mapcar 'gnus-summary-limit-children
8143                                  (cdr thread)))
8144              0))
8145           (number (mail-header-number (car thread)))
8146           score)
8147       (if (and
8148            (not (memq number gnus-newsgroup-marked))
8149            (or
8150             ;; If this article is dormant and has absolutely no visible
8151             ;; children, then this article isn't visible.
8152             (and (memq number gnus-newsgroup-dormant)
8153                  (zerop children))
8154             ;; If this is "fetch-old-headered" and there is no
8155             ;; visible children, then we don't want this article.
8156             (and (or (eq gnus-fetch-old-headers 'some)
8157                      (numberp gnus-fetch-old-headers))
8158                  (gnus-summary-article-ancient-p number)
8159                  (zerop children))
8160             ;; If this is "fetch-old-headered" and `invisible', then
8161             ;; we don't want this article.
8162             (and (eq gnus-fetch-old-headers 'invisible)
8163                  (gnus-summary-article-ancient-p number))
8164             ;; If this is a sparsely inserted article with no children,
8165             ;; we don't want it.
8166             (and (eq gnus-build-sparse-threads 'some)
8167                  (gnus-summary-article-sparse-p number)
8168                  (zerop children))
8169             ;; If we use expunging, and this article is really
8170             ;; low-scored, then we don't want this article.
8171             (when (and gnus-summary-expunge-below
8172                        (< (setq score
8173                                 (or (cdr (assq number gnus-newsgroup-scored))
8174                                     gnus-summary-default-score))
8175                           gnus-summary-expunge-below))
8176               ;; We increase the expunge-tally here, but that has
8177               ;; nothing to do with the limits, really.
8178               (incf gnus-newsgroup-expunged-tally)
8179               ;; We also mark as read here, if that's wanted.
8180               (when (and gnus-summary-mark-below
8181                          (< score gnus-summary-mark-below))
8182                 (setq gnus-newsgroup-unreads
8183                       (delq number gnus-newsgroup-unreads))
8184                 (if gnus-newsgroup-auto-expire
8185                     (push number gnus-newsgroup-expirable)
8186                   (push (cons number gnus-low-score-mark)
8187                         gnus-newsgroup-reads)))
8188               t)
8189             ;; Do the `display' group parameter.
8190             (and gnus-newsgroup-display
8191                  (not (funcall gnus-newsgroup-display)))
8192             ;; Check NoCeM things.
8193             (when (and gnus-use-nocem
8194                        (gnus-nocem-unwanted-article-p
8195                         (mail-header-id (car thread))))
8196               (setq gnus-newsgroup-unreads
8197                     (delq number gnus-newsgroup-unreads))
8198               t)))
8199           ;; Nope, invisible article.
8200           0
8201         ;; Ok, this article is to be visible, so we add it to the limit
8202         ;; and return 1.
8203         (push number gnus-newsgroup-limit)
8204         1))))
8205
8206 (defun gnus-expunge-thread (thread)
8207   "Mark all articles in THREAD as read."
8208   (let* ((number (mail-header-number (car thread))))
8209     (incf gnus-newsgroup-expunged-tally)
8210     ;; We also mark as read here, if that's wanted.
8211     (setq gnus-newsgroup-unreads
8212           (delq number gnus-newsgroup-unreads))
8213     (if gnus-newsgroup-auto-expire
8214         (push number gnus-newsgroup-expirable)
8215       (push (cons number gnus-low-score-mark)
8216             gnus-newsgroup-reads)))
8217   ;; Go recursively through all subthreads.
8218   (mapcar 'gnus-expunge-thread (cdr thread)))
8219
8220 ;; Summary article oriented commands
8221
8222 (defun gnus-summary-refer-parent-article (n)
8223   "Refer parent article N times.
8224 If N is negative, go to ancestor -N instead.
8225 The difference between N and the number of articles fetched is returned."
8226   (interactive "p")
8227   (let ((skip 1)
8228         error header ref)
8229     (when (not (natnump n))
8230       (setq skip (abs n)
8231             n 1))
8232     (while (and (> n 0)
8233                 (not error))
8234       (setq header (gnus-summary-article-header))
8235       (if (and (eq (mail-header-number header)
8236                    (cdr gnus-article-current))
8237                (equal gnus-newsgroup-name
8238                       (car gnus-article-current)))
8239           ;; If we try to find the parent of the currently
8240           ;; displayed article, then we take a look at the actual
8241           ;; References header, since this is slightly more
8242           ;; reliable than the References field we got from the
8243           ;; server.
8244           (save-excursion
8245             (set-buffer gnus-original-article-buffer)
8246             (nnheader-narrow-to-headers)
8247             (unless (setq ref (message-fetch-field "references"))
8248               (when (setq ref (message-fetch-field "in-reply-to"))
8249                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8250             (widen))
8251         (setq ref
8252               ;; It's not the current article, so we take a bet on
8253               ;; the value we got from the server.
8254               (mail-header-references header)))
8255       (if (and ref
8256                (not (equal ref "")))
8257           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8258             (gnus-message 1 "Couldn't find parent"))
8259         (gnus-message 1 "No references in article %d"
8260                       (gnus-summary-article-number))
8261         (setq error t))
8262       (decf n))
8263     (gnus-summary-position-point)
8264     n))
8265
8266 (defun gnus-summary-refer-references ()
8267   "Fetch all articles mentioned in the References header.
8268 Return the number of articles fetched."
8269   (interactive)
8270   (let ((ref (mail-header-references (gnus-summary-article-header)))
8271         (current (gnus-summary-article-number))
8272         (n 0))
8273     (if (or (not ref)
8274             (equal ref ""))
8275         (error "No References in the current article")
8276       ;; For each Message-ID in the References header...
8277       (while (string-match "<[^>]*>" ref)
8278         (incf n)
8279         ;; ... fetch that article.
8280         (gnus-summary-refer-article
8281          (prog1 (match-string 0 ref)
8282            (setq ref (substring ref (match-end 0))))))
8283       (gnus-summary-goto-subject current)
8284       (gnus-summary-position-point)
8285       n)))
8286
8287 (defun gnus-summary-refer-thread (&optional limit)
8288   "Fetch all articles in the current thread.
8289 If LIMIT (the numerical prefix), fetch that many old headers instead
8290 of what's specified by the `gnus-refer-thread-limit' variable."
8291   (interactive "P")
8292   (let ((id (mail-header-id (gnus-summary-article-header)))
8293         (limit (if limit (prefix-numeric-value limit)
8294                  gnus-refer-thread-limit)))
8295     (unless (eq gnus-fetch-old-headers 'invisible)
8296       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8297       ;; Retrieve the headers and read them in.
8298       (if (eq (if (numberp limit)
8299                   (gnus-retrieve-headers
8300                    (list (min
8301                           (+ (mail-header-number
8302                               (gnus-summary-article-header))
8303                              limit)
8304                           gnus-newsgroup-end))
8305                    gnus-newsgroup-name (* limit 2))
8306                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8307                 ;; headers.
8308                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8309                                        gnus-newsgroup-name limit))
8310               'nov)
8311           (gnus-build-all-threads)
8312         (error "Can't fetch thread from back ends that don't support NOV"))
8313       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8314     (gnus-summary-limit-include-thread id)))
8315
8316 (defun gnus-summary-refer-article (message-id)
8317   "Fetch an article specified by MESSAGE-ID."
8318   (interactive "sMessage-ID: ")
8319   (when (and (stringp message-id)
8320              (not (zerop (length message-id))))
8321     (setq message-id (gnus-replace-in-string message-id " " ""))
8322     ;; Construct the correct Message-ID if necessary.
8323     ;; Suggested by tale@pawl.rpi.edu.
8324     (unless (string-match "^<" message-id)
8325       (setq message-id (concat "<" message-id)))
8326     (unless (string-match ">$" message-id)
8327       (setq message-id (concat message-id ">")))
8328     ;; People often post MIDs from URLs, so unhex it:
8329     (unless (string-match "@" message-id)
8330       (setq message-id (gnus-url-unhex-string message-id)))
8331     (let* ((header (gnus-id-to-header message-id))
8332            (sparse (and header
8333                         (gnus-summary-article-sparse-p
8334                          (mail-header-number header))
8335                         (memq (mail-header-number header)
8336                               gnus-newsgroup-limit)))
8337            number)
8338       (cond
8339        ;; If the article is present in the buffer we just go to it.
8340        ((and header
8341              (or (not (gnus-summary-article-sparse-p
8342                        (mail-header-number header)))
8343                  sparse))
8344         (prog1
8345             (gnus-summary-goto-article
8346              (mail-header-number header) nil t)
8347           (when sparse
8348             (gnus-summary-update-article (mail-header-number header)))))
8349        (t
8350         ;; We fetch the article.
8351         (catch 'found
8352           (dolist (gnus-override-method (gnus-refer-article-methods))
8353             (when (and (gnus-check-server gnus-override-method)
8354                        ;; Fetch the header,
8355                        (setq number (gnus-summary-insert-subject message-id)))
8356               ;; and display the article.
8357               (gnus-summary-select-article nil nil nil number)
8358               (throw 'found t)))
8359           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8360
8361 (defun gnus-refer-article-methods ()
8362   "Return a list of referable methods."
8363   (cond
8364    ;; No method, so we default to current and native.
8365    ((null gnus-refer-article-method)
8366     (list gnus-current-select-method gnus-select-method))
8367    ;; Current.
8368    ((eq 'current gnus-refer-article-method)
8369     (list gnus-current-select-method))
8370    ;; List of select methods.
8371    ((not (and (symbolp (car gnus-refer-article-method))
8372               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8373     (let (out)
8374       (dolist (method gnus-refer-article-method)
8375         (push (if (eq 'current method)
8376                   gnus-current-select-method
8377                 method)
8378               out))
8379       (nreverse out)))
8380    ;; One single select method.
8381    (t
8382     (list gnus-refer-article-method))))
8383
8384 (defun gnus-summary-edit-parameters ()
8385   "Edit the group parameters of the current group."
8386   (interactive)
8387   (gnus-group-edit-group gnus-newsgroup-name 'params))
8388
8389 (defun gnus-summary-customize-parameters ()
8390   "Customize the group parameters of the current group."
8391   (interactive)
8392   (gnus-group-customize gnus-newsgroup-name))
8393
8394 (defun gnus-summary-enter-digest-group (&optional force)
8395   "Enter an nndoc group based on the current article.
8396 If FORCE, force a digest interpretation.  If not, try
8397 to guess what the document format is."
8398   (interactive "P")
8399   (let ((conf gnus-current-window-configuration))
8400     (save-window-excursion
8401       (save-excursion
8402         (let (gnus-article-prepare-hook
8403               gnus-display-mime-function
8404               gnus-break-pages)
8405           (gnus-summary-select-article))))
8406     (setq gnus-current-window-configuration conf)
8407     (let* ((name (format "%s-%d"
8408                          (gnus-group-prefixed-name
8409                           gnus-newsgroup-name (list 'nndoc ""))
8410                          (with-current-buffer gnus-summary-buffer
8411                            gnus-current-article)))
8412            (ogroup gnus-newsgroup-name)
8413            (params (append (gnus-info-params (gnus-get-info ogroup))
8414                            (list (cons 'to-group ogroup))
8415                            (list (cons 'parent-group ogroup))
8416                            (list (cons 'save-article-group ogroup))))
8417            (case-fold-search t)
8418            (buf (current-buffer))
8419            dig to-address)
8420       (save-excursion
8421         (set-buffer gnus-original-article-buffer)
8422         ;; Have the digest group inherit the main mail address of
8423         ;; the parent article.
8424         (when (setq to-address (or (gnus-fetch-field "reply-to")
8425                                    (gnus-fetch-field "from")))
8426           (setq params (append
8427                         (list (cons 'to-address
8428                                     (funcall gnus-decode-encoded-word-function
8429                                              to-address))))))
8430         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8431         (insert-buffer-substring gnus-original-article-buffer)
8432         ;; Remove lines that may lead nndoc to misinterpret the
8433         ;; document type.
8434         (narrow-to-region
8435          (goto-char (point-min))
8436          (or (search-forward "\n\n" nil t) (point)))
8437         (goto-char (point-min))
8438         (delete-matching-lines "^Path:\\|^From ")
8439         (widen))
8440       (unwind-protect
8441           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8442                     (gnus-newsgroup-ephemeral-ignored-charsets
8443                      gnus-newsgroup-ignored-charsets))
8444                 (gnus-group-read-ephemeral-group
8445                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8446                               (nndoc-article-type
8447                                ,(if force 'mbox 'guess)))
8448                  t nil nil nil
8449                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8450                                                         "ADAPT")))))
8451               ;; Make all postings to this group go to the parent group.
8452               (nconc (gnus-info-params (gnus-get-info name))
8453                      params)
8454             ;; Couldn't select this doc group.
8455             (switch-to-buffer buf)
8456             (gnus-set-global-variables)
8457             (gnus-configure-windows 'summary)
8458             (gnus-message 3 "Article couldn't be entered?"))
8459         (kill-buffer dig)))))
8460
8461 (defun gnus-summary-read-document (n)
8462   "Open a new group based on the current article(s).
8463 This will allow you to read digests and other similar
8464 documents as newsgroups.
8465 Obeys the standard process/prefix convention."
8466   (interactive "P")
8467   (let* ((ogroup gnus-newsgroup-name)
8468          (params (append (gnus-info-params (gnus-get-info ogroup))
8469                          (list (cons 'to-group ogroup))))
8470          group egroup groups vgroup)
8471     (dolist (article (gnus-summary-work-articles n))
8472       (setq group (format "%s-%d" gnus-newsgroup-name article))
8473       (gnus-summary-remove-process-mark article)
8474       (when (gnus-summary-display-article article)
8475         (save-excursion
8476           (with-temp-buffer
8477             (insert-buffer-substring gnus-original-article-buffer)
8478             ;; Remove some headers that may lead nndoc to make
8479             ;; the wrong guess.
8480             (message-narrow-to-head)
8481             (goto-char (point-min))
8482             (delete-matching-lines "^Path:\\|^From ")
8483             (widen)
8484             (if (setq egroup
8485                       (gnus-group-read-ephemeral-group
8486                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8487                                      (nndoc-article-type guess))
8488                        t nil t))
8489                 (progn
8490                   ;; Make all postings to this group go to the parent group.
8491                   (nconc (gnus-info-params (gnus-get-info egroup))
8492                          params)
8493                   (push egroup groups))
8494               ;; Couldn't select this doc group.
8495               (gnus-error 3 "Article couldn't be entered"))))))
8496     ;; Now we have selected all the documents.
8497     (cond
8498      ((not groups)
8499       (error "None of the articles could be interpreted as documents"))
8500      ((gnus-group-read-ephemeral-group
8501        (setq vgroup (format
8502                      "nnvirtual:%s-%s" gnus-newsgroup-name
8503                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8504        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8505        t
8506        (cons (current-buffer) 'summary)))
8507      (t
8508       (error "Couldn't select virtual nndoc group")))))
8509
8510 (defun gnus-summary-isearch-article (&optional regexp-p)
8511   "Do incremental search forward on the current article.
8512 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8513   (interactive "P")
8514   (let* ((gnus-inhibit-treatment t)
8515          (old (gnus-summary-select-article)))
8516     (gnus-configure-windows 'article)
8517     (gnus-eval-in-buffer-window gnus-article-buffer
8518       (save-restriction
8519         (widen)
8520         (when (eq 'old old)
8521           (gnus-article-show-all-headers))
8522         (goto-char (point-min))
8523         (isearch-forward regexp-p)))))
8524
8525 (defun gnus-summary-search-article-forward (regexp &optional backward)
8526   "Search for an article containing REGEXP forward.
8527 If BACKWARD, search backward instead."
8528   (interactive
8529    (list (read-string
8530           (format "Search article %s (regexp%s): "
8531                   (if current-prefix-arg "backward" "forward")
8532                   (if gnus-last-search-regexp
8533                       (concat ", default " gnus-last-search-regexp)
8534                     "")))
8535          current-prefix-arg))
8536   (if (string-equal regexp "")
8537       (setq regexp (or gnus-last-search-regexp ""))
8538     (setq gnus-last-search-regexp regexp)
8539     (setq gnus-article-before-search gnus-current-article))
8540   ;; Intentionally set gnus-last-article.
8541   (setq gnus-last-article gnus-article-before-search)
8542   (let ((gnus-last-article gnus-last-article))
8543     (if (gnus-summary-search-article regexp backward)
8544         (gnus-summary-show-thread)
8545       (signal 'search-failed (list regexp)))))
8546
8547 (defun gnus-summary-search-article-backward (regexp)
8548   "Search for an article containing REGEXP backward."
8549   (interactive
8550    (list (read-string
8551           (format "Search article backward (regexp%s): "
8552                   (if gnus-last-search-regexp
8553                       (concat ", default " gnus-last-search-regexp)
8554                     "")))))
8555   (gnus-summary-search-article-forward regexp 'backward))
8556
8557 (eval-when-compile
8558   (defmacro gnus-summary-search-article-position-point (regexp backward)
8559     "Dehighlight the last matched text and goto the beginning position."
8560     (` (if (and gnus-summary-search-article-matched-data
8561                 (let ((text (caddr gnus-summary-search-article-matched-data))
8562                       (inhibit-read-only t)
8563                       buffer-read-only)
8564                   (delete-region
8565                    (goto-char (car gnus-summary-search-article-matched-data))
8566                    (cadr gnus-summary-search-article-matched-data))
8567                   (insert text)
8568                   (string-match (, regexp) text)))
8569            (if (, backward) (beginning-of-line) (end-of-line))
8570          (goto-char (if (, backward) (point-max) (point-min))))))
8571
8572   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8573     "Place point where X-Face image is displayed."
8574     (if (featurep 'xemacs)
8575         (` (let ((end (if (search-forward "\n\n" nil t)
8576                           (goto-char (1- (point)))
8577                         (point-min)))
8578                  extent)
8579              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8580              (unless (and (re-search-forward "^From:" end t)
8581                           (setq extent (extent-at (point)))
8582                           (extent-begin-glyph extent))
8583                (goto-char (, opoint)))))
8584       (` (let ((end (if (search-forward "\n\n" nil t)
8585                         (goto-char (1- (point)))
8586                       (point-min)))
8587                (start (or (search-backward "\n\n" nil t) (point-min))))
8588            (goto-char
8589             (or (text-property-any start end 'x-face-image t);; x-face-e21
8590                 (text-property-any start end 'x-face-mule-bitmap-image t)
8591                 (, opoint)))))))
8592
8593   (defmacro gnus-summary-search-article-highlight-matched-text
8594     (backward treated x-face)
8595     "Highlight matched text in the function `gnus-summary-search-article'."
8596     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8597              (end (set-marker (make-marker) (match-end 0)))
8598              (inhibit-read-only t)
8599              buffer-read-only)
8600          (unless treated
8601            (let ((,@
8602                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8603                     (mapcar
8604                      (lambda (item) (setq items (delq item items)))
8605                      '(gnus-treat-buttonize
8606                        gnus-treat-fill-article
8607                        gnus-treat-fill-long-lines
8608                        gnus-treat-emphasize
8609                        gnus-treat-highlight-headers
8610                        gnus-treat-highlight-citation
8611                        gnus-treat-highlight-signature
8612                        gnus-treat-overstrike
8613                        gnus-treat-display-x-face
8614                        gnus-treat-buttonize-head
8615                        gnus-treat-decode-article-as-default-mime-charset))
8616                     (static-if (featurep 'xemacs)
8617                         items
8618                       (cons '(x-face-mule-delete-x-face-field
8619                               (quote never))
8620                             items))))
8621                  (gnus-treat-display-x-face
8622                   (when (, x-face) gnus-treat-display-x-face)))
8623              (gnus-article-prepare-mime-display)))
8624          (goto-char (if (, backward) start end))
8625          (when (, x-face)
8626            (gnus-summary-search-article-highlight-goto-x-face (point)))
8627          (setq gnus-summary-search-article-matched-data
8628                (list start end (buffer-substring start end)))
8629          (unless (eq start end);; matched text has been deleted. :-<
8630            (put-text-property start end 'face
8631                               (or (find-face 'isearch)
8632                                   'secondary-selection))))))
8633   )
8634
8635 (defun gnus-summary-search-article (regexp &optional backward)
8636   "Search for an article containing REGEXP.
8637 Optional argument BACKWARD means do search for backward.
8638 `gnus-select-article-hook' is not called during the search."
8639   ;; We have to require this here to make sure that the following
8640   ;; dynamic binding isn't shadowed by autoloading.
8641   (require 'gnus-async)
8642   (require 'gnus-art)
8643   (let ((gnus-select-article-hook nil)  ;Disable hook.
8644         (gnus-article-prepare-hook nil)
8645         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8646         (gnus-use-article-prefetch nil)
8647         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8648         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8649         (gnus-visual nil)
8650         (gnus-keep-backlog nil)
8651         (gnus-break-pages nil)
8652         (gnus-summary-display-arrow nil)
8653         (gnus-updated-mode-lines nil)
8654         (gnus-auto-center-summary nil)
8655         (sum (current-buffer))
8656         (found nil)
8657         point treated)
8658     (gnus-save-hidden-threads
8659       (static-if (featurep 'xemacs)
8660           (let ((gnus-inhibit-treatment t))
8661             (setq treated (eq 'old (gnus-summary-select-article)))
8662             (when (and treated
8663                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8664                                  (window-live-p (get-buffer-window
8665                                                  gnus-article-buffer t)))))
8666               (gnus-summary-select-article nil t)
8667               (setq treated nil)))
8668         (let ((gnus-inhibit-treatment t)
8669               (x-face-mule-delete-x-face-field 'never))
8670           (setq treated (eq 'old (gnus-summary-select-article)))
8671           (when (and treated
8672                      (not
8673                       (and (gnus-buffer-live-p gnus-article-buffer)
8674                            (window-live-p (get-buffer-window
8675                                            gnus-article-buffer t))
8676                            (or (not (string-match "^\\^X-Face:" regexp))
8677                                (with-current-buffer gnus-article-buffer
8678                                  gnus-summary-search-article-matched-data)))))
8679             (gnus-summary-select-article nil t)
8680             (setq treated nil))))
8681       (set-buffer gnus-article-buffer)
8682       (widen)
8683       (if treated
8684           (progn
8685             (gnus-article-show-all-headers)
8686             (gnus-summary-search-article-position-point regexp backward))
8687         (goto-char (if backward (point-max) (point-min))))
8688       (while (not found)
8689         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8690         (if (if backward
8691                 (re-search-backward regexp nil t)
8692               (re-search-forward regexp nil t))
8693             ;; We found the regexp.
8694             (progn
8695               (gnus-summary-search-article-highlight-matched-text
8696                backward treated (string-match "^\\^X-Face:" regexp))
8697               (setq found 'found)
8698               (forward-line
8699                (/ (- 2 (window-height
8700                         (get-buffer-window gnus-article-buffer t)))
8701                   2))
8702               (set-window-start
8703                (get-buffer-window (current-buffer))
8704                (point))
8705               (set-buffer sum)
8706               (setq point (point)))
8707           ;; We didn't find it, so we go to the next article.
8708           (set-buffer sum)
8709           (setq found 'not)
8710           (while (eq found 'not)
8711             (if (not (if backward (gnus-summary-find-prev)
8712                        (gnus-summary-find-next)))
8713                 ;; No more articles.
8714                 (setq found t)
8715               ;; Select the next article and adjust point.
8716               (unless (gnus-summary-article-sparse-p
8717                        (gnus-summary-article-number))
8718                 (setq found nil)
8719                 (let ((gnus-inhibit-treatment t))
8720                   (gnus-summary-select-article))
8721                 (setq treated nil)
8722                 (set-buffer gnus-article-buffer)
8723                 (widen)
8724                 (goto-char (if backward (point-max) (point-min))))))))
8725       (gnus-message 7 ""))
8726     ;; Return whether we found the regexp.
8727     (when (eq found 'found)
8728       (goto-char point)
8729       (gnus-summary-show-thread)
8730       (gnus-summary-goto-subject gnus-current-article)
8731       (gnus-summary-position-point)
8732       t)))
8733
8734 (defun gnus-find-matching-articles (header regexp)
8735   "Return a list of all articles that match REGEXP on HEADER.
8736 This search includes all articles in the current group that Gnus has
8737 fetched headers for, whether they are displayed or not."
8738   (let ((articles nil)
8739         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8740         (case-fold-search t))
8741     (dolist (header gnus-newsgroup-headers)
8742       (when (string-match regexp (funcall func header))
8743         (push (mail-header-number header) articles)))
8744     (nreverse articles)))
8745
8746 (defun gnus-summary-find-matching (header regexp &optional backward unread
8747                                           not-case-fold not-matching)
8748   "Return a list of all articles that match REGEXP on HEADER.
8749 The search stars on the current article and goes forwards unless
8750 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8751 If UNREAD is non-nil, only unread articles will
8752 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8753 in the comparisons. If NOT-MATCHING, return a list of all articles that
8754 not match REGEXP on HEADER."
8755   (let ((case-fold-search (not not-case-fold))
8756         articles d func)
8757     (if (consp header)
8758         (if (eq (car header) 'extra)
8759             (setq func
8760                   `(lambda (h)
8761                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8762                          "")))
8763           (error "%s is an invalid header" header))
8764       (unless (fboundp (intern (concat "mail-header-" header)))
8765         (error "%s is not a valid header" header))
8766       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8767     (dolist (d (if (eq backward 'all)
8768                    gnus-newsgroup-data
8769                  (gnus-data-find-list
8770                   (gnus-summary-article-number)
8771                   (gnus-data-list backward))))
8772       (when (and (or (not unread)       ; We want all articles...
8773                      (gnus-data-unread-p d)) ; Or just unreads.
8774                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8775                  (if not-matching
8776                      (not (string-match
8777                            regexp
8778                            (funcall func (gnus-data-header d))))
8779                    (string-match regexp
8780                                  (funcall func (gnus-data-header d)))))
8781         (push (gnus-data-number d) articles))) ; Success!
8782     (nreverse articles)))
8783
8784 (defun gnus-summary-execute-command (header regexp command &optional backward)
8785   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8786 If HEADER is an empty string (or nil), the match is done on the entire
8787 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8788   (interactive
8789    (list (let ((completion-ignore-case t))
8790            (completing-read
8791             "Header name: "
8792             (mapcar (lambda (header) (list (format "%s" header)))
8793                     (append
8794                      '("Number" "Subject" "From" "Lines" "Date"
8795                        "Message-ID" "Xref" "References" "Body")
8796                      gnus-extra-headers))
8797             nil 'require-match))
8798          (read-string "Regexp: ")
8799          (read-key-sequence "Command: ")
8800          current-prefix-arg))
8801   (when (equal header "Body")
8802     (setq header ""))
8803   ;; Hidden thread subtrees must be searched as well.
8804   (gnus-summary-show-all-threads)
8805   ;; We don't want to change current point nor window configuration.
8806   (save-excursion
8807     (save-window-excursion
8808       (let (gnus-visual
8809             gnus-treat-strip-trailing-blank-lines
8810             gnus-treat-strip-leading-blank-lines
8811             gnus-treat-strip-multiple-blank-lines
8812             gnus-treat-hide-boring-headers
8813             gnus-treat-fold-newsgroups
8814             gnus-article-prepare-hook)
8815         (gnus-message 6 "Executing %s..." (key-description command))
8816         ;; We'd like to execute COMMAND interactively so as to give arguments.
8817         (gnus-execute header regexp
8818                       `(call-interactively ',(key-binding command))
8819                       backward)
8820         (gnus-message 6 "Executing %s...done" (key-description command))))))
8821
8822 (defun gnus-summary-beginning-of-article ()
8823   "Scroll the article back to the beginning."
8824   (interactive)
8825   (gnus-summary-select-article)
8826   (gnus-configure-windows 'article)
8827   (gnus-eval-in-buffer-window gnus-article-buffer
8828     (widen)
8829     (goto-char (point-min))
8830     (when gnus-break-pages
8831       (gnus-narrow-to-page))))
8832
8833 (defun gnus-summary-end-of-article ()
8834   "Scroll to the end of the article."
8835   (interactive)
8836   (gnus-summary-select-article)
8837   (gnus-configure-windows 'article)
8838   (gnus-eval-in-buffer-window gnus-article-buffer
8839     (widen)
8840     (goto-char (point-max))
8841     (recenter -3)
8842     (when gnus-break-pages
8843       (when (re-search-backward page-delimiter nil t)
8844         (narrow-to-region (match-end 0) (point-max)))
8845       (gnus-narrow-to-page))))
8846
8847 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8848   "Truncate to LEN and quote all \"(\"'s in STRING."
8849   (gnus-replace-in-string (if (and len (> (length string) len))
8850                               (substring string 0 len)
8851                             string)
8852                           "[()]" "\\\\\\&"))
8853
8854 (defun gnus-summary-print-article (&optional filename n)
8855   "Generate and print a PostScript image of the process-marked (mail) articles.
8856
8857 If used interactively, print the current article if none are
8858 process-marked.  With prefix arg, prompt the user for the name of the
8859 file to save in.
8860
8861 When used from Lisp, accept two optional args FILENAME and N.  N means
8862 to print the next N articles.  If N is negative, print the N previous
8863 articles.  If N is nil and articles have been marked with the process
8864 mark, print these instead.
8865
8866 If the optional first argument FILENAME is nil, send the image to the
8867 printer.  If FILENAME is a string, save the PostScript image in a file with
8868 that name.  If FILENAME is a number, prompt the user for the name of the file
8869 to save in."
8870   (interactive (list (ps-print-preprint current-prefix-arg)))
8871   (dolist (article (gnus-summary-work-articles n))
8872     (gnus-summary-select-article nil nil 'pseudo article)
8873     (gnus-eval-in-buffer-window gnus-article-buffer
8874       (gnus-print-buffer))
8875     (gnus-summary-remove-process-mark article))
8876   (ps-despool filename))
8877
8878 (defun gnus-print-buffer ()
8879   (let ((buffer (generate-new-buffer " *print*")))
8880     (unwind-protect
8881         (progn
8882           (copy-to-buffer buffer (point-min) (point-max))
8883           (set-buffer buffer)
8884           (gnus-remove-text-with-property 'gnus-decoration)
8885           (when (gnus-visual-p 'article-highlight 'highlight)
8886             ;; Copy-to-buffer doesn't copy overlay.  So redo
8887             ;; highlight.
8888             (let ((gnus-article-buffer buffer))
8889               (gnus-article-highlight-citation t)
8890               (gnus-article-highlight-signature)
8891               (gnus-article-emphasize)
8892               (gnus-article-delete-invisible-text)))
8893           (let ((ps-left-header
8894                  (list
8895                   (concat "("
8896                           (gnus-summary-print-truncate-and-quote
8897                            (mail-header-subject gnus-current-headers)
8898                            66) ")")
8899                   (concat "("
8900                           (gnus-summary-print-truncate-and-quote
8901                            (mail-header-from gnus-current-headers)
8902                            45) ")")))
8903                 (ps-right-header
8904                  (list
8905                   "/pagenumberstring load"
8906                   (concat "("
8907                           (mail-header-date gnus-current-headers) ")"))))
8908             (gnus-run-hooks 'gnus-ps-print-hook)
8909             (save-excursion
8910               (if window-system
8911                   (ps-spool-buffer-with-faces)
8912                 (ps-spool-buffer)))))
8913       (kill-buffer buffer))))
8914
8915 (defun gnus-summary-show-article (&optional arg)
8916   "Force redisplaying of the current article.
8917 If ARG (the prefix) is a number, show the article with the charset
8918 defined in `gnus-summary-show-article-charset-alist', or the charset
8919 input.
8920 If ARG (the prefix) is non-nil and not a number, show the raw article
8921 without any article massaging functions being run.  Normally, the key
8922 strokes are `C-u g'."
8923   (interactive "P")
8924   (cond
8925    ((numberp arg)
8926     (gnus-summary-show-article t)
8927     (let* ((gnus-newsgroup-charset
8928             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8929                 (mm-read-coding-system
8930                  "View as charset: " ;; actually it is coding system.
8931                  (with-current-buffer gnus-article-buffer
8932                    (mm-detect-coding-region (point) (point-max))))))
8933            (default-mime-charset gnus-newsgroup-charset)
8934            (gnus-newsgroup-ignored-charsets 'gnus-all))
8935       (gnus-summary-select-article nil 'force)
8936       (let ((deps gnus-newsgroup-dependencies)
8937             head header lines)
8938         (save-excursion
8939           (set-buffer gnus-original-article-buffer)
8940           (save-restriction
8941             (message-narrow-to-head)
8942             (setq head (buffer-string))
8943             (goto-char (point-min))
8944             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8945               (goto-char (point-max))
8946               (widen)
8947               (setq lines (1- (count-lines (point) (point-max))))))
8948           (with-temp-buffer
8949             (insert (format "211 %d Article retrieved.\n"
8950                             (cdr gnus-article-current)))
8951             (insert head)
8952             (if lines (insert (format "Lines: %d\n" lines)))
8953             (insert ".\n")
8954             (let ((nntp-server-buffer (current-buffer)))
8955               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8956         (gnus-data-set-header
8957          (gnus-data-find (cdr gnus-article-current))
8958          header)
8959         (gnus-summary-update-article-line
8960          (cdr gnus-article-current) header)
8961         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8962           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8963    ((not arg)
8964     ;; Select the article the normal way.
8965     (gnus-summary-select-article nil 'force))
8966    (t
8967     ;; We have to require this here to make sure that the following
8968     ;; dynamic binding isn't shadowed by autoloading.
8969     (require 'gnus-async)
8970     (require 'gnus-art)
8971     ;; Bind the article treatment functions to nil.
8972     (let ((gnus-have-all-headers t)
8973           gnus-article-prepare-hook
8974           gnus-article-decode-hook
8975           gnus-break-pages
8976           gnus-show-mime
8977           (gnus-inhibit-treatment t))
8978       (gnus-summary-select-article nil 'force))))
8979   (gnus-summary-goto-subject gnus-current-article)
8980   (gnus-summary-position-point))
8981
8982 (defun gnus-summary-show-raw-article ()
8983   "Show the raw article without any article massaging functions being run."
8984   (interactive)
8985   (gnus-summary-show-article t))
8986
8987 (defun gnus-summary-verbose-headers (&optional arg)
8988   "Toggle permanent full header display.
8989 If ARG is a positive number, turn header display on.
8990 If ARG is a negative number, turn header display off."
8991   (interactive "P")
8992   (setq gnus-show-all-headers
8993         (cond ((or (not (numberp arg))
8994                    (zerop arg))
8995                (not gnus-show-all-headers))
8996               ((natnump arg)
8997                t)))
8998   (gnus-summary-show-article))
8999
9000 (defun gnus-summary-toggle-header (&optional arg)
9001   "Show the headers if they are hidden, or hide them if they are shown.
9002 If ARG is a positive number, show the entire header.
9003 If ARG is a negative number, hide the unwanted header lines."
9004   (interactive "P")
9005   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9006                      (get-buffer-window gnus-article-buffer t))))
9007     (with-current-buffer gnus-article-buffer
9008       (widen)
9009       (article-narrow-to-head)
9010       (let* ((buffer-read-only nil)
9011              (inhibit-point-motion-hooks t)
9012              (hidden (if (numberp arg)
9013                          (>= arg 0)
9014                        (or (not (looking-at "[^ \t\n]+:"))
9015                            (gnus-article-hidden-text-p 'headers))))
9016              s e)
9017         (delete-region (point-min) (point-max))
9018         (with-current-buffer gnus-original-article-buffer
9019           (goto-char (setq s (point-min)))
9020           (setq e (if (search-forward "\n\n" nil t)
9021                       (1- (point))
9022                     (point-max))))
9023         (insert-buffer-substring gnus-original-article-buffer s e)
9024         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9025         ;; article-decode-encoded-words by default.
9026         (article-decode-encoded-words)
9027         (run-hooks 'gnus-article-decode-hook)
9028         (if hidden
9029             (let ((gnus-treat-hide-headers nil)
9030                   (gnus-treat-hide-boring-headers nil))
9031               (gnus-delete-wash-type 'headers)
9032               (gnus-treat-article 'head))
9033           (gnus-treat-article 'head))
9034         (widen)
9035         (if window
9036             (set-window-start window (goto-char (point-min))))
9037         (if gnus-break-pages
9038             (gnus-narrow-to-page)
9039           (when (gnus-visual-p 'page-marker)
9040             (let ((buffer-read-only nil))
9041               (gnus-remove-text-with-property 'gnus-prev)
9042               (gnus-remove-text-with-property 'gnus-next))))
9043         (gnus-set-mode-line 'article)))))
9044
9045 (defun gnus-summary-show-all-headers ()
9046   "Make all header lines visible."
9047   (interactive)
9048   (gnus-summary-toggle-header 1))
9049
9050 (defun gnus-summary-toggle-mime (&optional arg)
9051   "Toggle MIME processing.
9052 If ARG is a positive number, turn MIME processing on."
9053   (interactive "P")
9054   (setq gnus-show-mime
9055         (if (null arg)
9056             (not gnus-show-mime)
9057           (> (prefix-numeric-value arg) 0)))
9058   (gnus-summary-select-article t 'force))
9059
9060 (defun gnus-summary-caesar-message (&optional arg)
9061   "Caesar rotate the current article by 13.
9062 The numerical prefix specifies how many places to rotate each letter
9063 forward."
9064   (interactive "P")
9065   (gnus-summary-select-article)
9066   (let ((mail-header-separator ""))
9067     (gnus-eval-in-buffer-window gnus-article-buffer
9068       (save-restriction
9069         (widen)
9070         (let ((start (window-start))
9071               buffer-read-only)
9072           (message-caesar-buffer-body arg)
9073           (set-window-start (get-buffer-window (current-buffer)) start))))))
9074
9075 (autoload 'unmorse-region "morse"
9076   "Convert morse coded text in region to ordinary ASCII text."
9077   t)
9078
9079 (defun gnus-summary-morse-message (&optional arg)
9080   "Morse decode the current article."
9081   (interactive "P")
9082   (gnus-summary-select-article)
9083   (let ((mail-header-separator ""))
9084     (gnus-eval-in-buffer-window gnus-article-buffer
9085       (save-excursion
9086         (save-restriction
9087           (widen)
9088           (let ((pos (window-start))
9089                 buffer-read-only)
9090             (goto-char (point-min))
9091             (when (message-goto-body)
9092               (gnus-narrow-to-body))
9093             (goto-char (point-min))
9094             (while (search-forward "·" (point-max) t)
9095               (replace-match "."))
9096             (unmorse-region (point-min) (point-max))
9097             (widen)
9098             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9099
9100 (defun gnus-summary-stop-page-breaking ()
9101   "Stop page breaking in the current article."
9102   (interactive)
9103   (gnus-summary-select-article)
9104   (gnus-eval-in-buffer-window gnus-article-buffer
9105     (widen)
9106     (when (gnus-visual-p 'page-marker)
9107       (let ((buffer-read-only nil))
9108         (gnus-remove-text-with-property 'gnus-prev)
9109         (gnus-remove-text-with-property 'gnus-next))
9110       (setq gnus-page-broken nil))))
9111
9112 (defun gnus-summary-move-article (&optional n to-newsgroup
9113                                             select-method action)
9114   "Move the current article to a different newsgroup.
9115 If N is a positive number, move the N next articles.
9116 If N is a negative number, move the N previous articles.
9117 If N is nil and any articles have been marked with the process mark,
9118 move those articles instead.
9119 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9120 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9121 re-spool using this method.
9122
9123 When called interactively with TO-NEWSGROUP being nil, the value of
9124 the variable `gnus-move-split-methods' is used for finding a default
9125 for the target newsgroup.
9126
9127 For this function to work, both the current newsgroup and the
9128 newsgroup that you want to move to have to support the `request-move'
9129 and `request-accept' functions.
9130
9131 ACTION can be either `move' (the default), `crosspost' or `copy'."
9132   (interactive "P")
9133   (unless action
9134     (setq action 'move))
9135   ;; Check whether the source group supports the required functions.
9136   (cond ((and (eq action 'move)
9137               (not (gnus-check-backend-function
9138                     'request-move-article gnus-newsgroup-name)))
9139          (error "The current group does not support article moving"))
9140         ((and (eq action 'crosspost)
9141               (not (gnus-check-backend-function
9142                     'request-replace-article gnus-newsgroup-name)))
9143          (error "The current group does not support article editing")))
9144   (let ((articles (gnus-summary-work-articles n))
9145         (prefix (if (gnus-check-backend-function
9146                      'request-move-article gnus-newsgroup-name)
9147                     (funcall gnus-move-group-prefix-function
9148                              gnus-newsgroup-name)
9149                   ""))
9150         (names '((move "Move" "Moving")
9151                  (copy "Copy" "Copying")
9152                  (crosspost "Crosspost" "Crossposting")))
9153         (copy-buf (save-excursion
9154                     (nnheader-set-temp-buffer " *copy article*")))
9155         art-group to-method new-xref article to-groups)
9156     (unless (assq action names)
9157       (error "Unknown action %s" action))
9158     ;; Read the newsgroup name.
9159     (when (and (not to-newsgroup)
9160                (not select-method))
9161       (if (and gnus-move-split-methods
9162                (not
9163                 (and (memq gnus-current-article articles)
9164                      (gnus-buffer-live-p gnus-original-article-buffer))))
9165           ;; When `gnus-move-split-methods' is non-nil, we have to
9166           ;; select an article to give `gnus-read-move-group-name' an
9167           ;; opportunity to suggest an appropriate default.  However,
9168           ;; we needn't render or mark the article.
9169           (let ((gnus-display-mime-function nil)
9170                 (gnus-article-prepare-hook nil)
9171                 (gnus-mark-article-hook nil))
9172             (gnus-summary-select-article nil nil nil (car articles))))
9173       (setq to-newsgroup
9174             (gnus-read-move-group-name
9175              (cadr (assq action names))
9176              (symbol-value (intern (format "gnus-current-%s-group" action)))
9177              articles prefix))
9178       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9179     (setq to-method (or select-method
9180                         (gnus-server-to-method
9181                          (gnus-group-method to-newsgroup))))
9182     ;; Check the method we are to move this article to...
9183     (unless (gnus-check-backend-function
9184              'request-accept-article (car to-method))
9185       (error "%s does not support article copying" (car to-method)))
9186     (unless (gnus-check-server to-method)
9187       (error "Can't open server %s" (car to-method)))
9188     (gnus-message 6 "%s to %s: %s..."
9189                   (caddr (assq action names))
9190                   (or (car select-method) to-newsgroup) articles)
9191     (while articles
9192       (setq article (pop articles))
9193       (setq
9194        art-group
9195        (cond
9196         ;; Move the article.
9197         ((eq action 'move)
9198          ;; Remove this article from future suppression.
9199          (gnus-dup-unsuppress-article article)
9200          (gnus-request-move-article
9201           article                       ; Article to move
9202           gnus-newsgroup-name           ; From newsgroup
9203           (nth 1 (gnus-find-method-for-group
9204                   gnus-newsgroup-name)) ; Server
9205           (list 'gnus-request-accept-article
9206                 to-newsgroup (list 'quote select-method)
9207                 (not articles) t)       ; Accept form
9208           (not articles)))              ; Only save nov last time
9209         ;; Copy the article.
9210         ((eq action 'copy)
9211          (save-excursion
9212            (set-buffer copy-buf)
9213            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9214              (save-restriction
9215                (nnheader-narrow-to-headers)
9216                (dolist (hdr gnus-copy-article-ignored-headers)
9217                  (message-remove-header hdr t)))
9218              (gnus-request-accept-article
9219               to-newsgroup select-method (not articles) t))))
9220         ;; Crosspost the article.
9221         ((eq action 'crosspost)
9222          (let ((xref (message-tokenize-header
9223                       (mail-header-xref (gnus-summary-article-header article))
9224                       " ")))
9225            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9226                                   ":" (number-to-string article)))
9227            (unless xref
9228              (setq xref (list (system-name))))
9229            (setq new-xref
9230                  (concat
9231                   (mapconcat 'identity
9232                              (delete "Xref:" (delete new-xref xref))
9233                              " ")
9234                   " " new-xref))
9235            (save-excursion
9236              (set-buffer copy-buf)
9237              ;; First put the article in the destination group.
9238              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9239              (when (consp (setq art-group
9240                                 (gnus-request-accept-article
9241                                  to-newsgroup select-method (not articles))))
9242                (setq new-xref (concat new-xref " " (car art-group)
9243                                       ":"
9244                                       (number-to-string (cdr art-group))))
9245                ;; Now we have the new Xrefs header, so we insert
9246                ;; it and replace the new article.
9247                (nnheader-replace-header "Xref" new-xref)
9248                (gnus-request-replace-article
9249                 (cdr art-group) to-newsgroup (current-buffer))
9250                art-group))))))
9251       (cond
9252        ((not art-group)
9253         (gnus-message 1 "Couldn't %s article %s: %s"
9254                       (cadr (assq action names)) article
9255                       (nnheader-get-report (car to-method))))
9256        ((eq art-group 'junk)
9257         (when (eq action 'move)
9258           (gnus-summary-mark-article article gnus-canceled-mark)
9259           (gnus-message 4 "Deleted article %s" article)
9260           ;; run the delete hook
9261           (run-hook-with-args 'gnus-summary-article-delete-hook
9262                               action
9263                               (gnus-data-header
9264                                (assoc article (gnus-data-list nil)))
9265                               gnus-newsgroup-name nil
9266                               select-method)))
9267        (t
9268         (let* ((pto-group (gnus-group-prefixed-name
9269                            (car art-group) to-method))
9270                (info (gnus-get-info pto-group))
9271                (to-group (gnus-info-group info))
9272                to-marks)
9273           ;; Update the group that has been moved to.
9274           (when (and info
9275                      (memq action '(move copy)))
9276             (unless (member to-group to-groups)
9277               (push to-group to-groups))
9278
9279             (unless (memq article gnus-newsgroup-unreads)
9280               (push 'read to-marks)
9281               (gnus-info-set-read
9282                info (gnus-add-to-range (gnus-info-read info)
9283                                        (list (cdr art-group)))))
9284
9285             ;; See whether the article is to be put in the cache.
9286             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9287                              gnus-article-mark-lists
9288                            (delete '(expirable . expire)
9289                                    (copy-sequence gnus-article-mark-lists))))
9290                   (to-article (cdr art-group)))
9291
9292               ;; Enter the article into the cache in the new group,
9293               ;; if that is required.
9294               (when gnus-use-cache
9295                 (gnus-cache-possibly-enter-article
9296                  to-group to-article
9297                  (let ((header (copy-sequence
9298                                 (gnus-summary-article-header article))))
9299                    (mail-header-set-number header to-article)
9300                    header)
9301                  (memq article gnus-newsgroup-marked)
9302                  (memq article gnus-newsgroup-dormant)
9303                  (memq article gnus-newsgroup-unreads)))
9304
9305               (when gnus-preserve-marks
9306                 ;; Copy any marks over to the new group.
9307                 (when (and (equal to-group gnus-newsgroup-name)
9308                            (not (memq article gnus-newsgroup-unreads)))
9309                   ;; Mark this article as read in this group.
9310                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9311                   (setcdr (gnus-active to-group) to-article)
9312                   (setcdr gnus-newsgroup-active to-article))
9313
9314                 (while marks
9315                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9316                     (when (memq article (symbol-value
9317                                          (intern (format "gnus-newsgroup-%s"
9318                                                          (caar marks)))))
9319                       (push (cdar marks) to-marks)
9320                       ;; If the other group is the same as this group,
9321                       ;; then we have to add the mark to the list.
9322                       (when (equal to-group gnus-newsgroup-name)
9323                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9324                              (cons to-article
9325                                    (symbol-value
9326                                     (intern (format "gnus-newsgroup-%s"
9327                                                     (caar marks)))))))
9328                       ;; Copy the marks to other group.
9329                       (gnus-add-marked-articles
9330                        to-group (cdar marks) (list to-article) info)))
9331                   (setq marks (cdr marks)))
9332
9333                 (gnus-request-set-mark
9334                  to-group (list (list (list to-article) 'add to-marks))))
9335
9336               (gnus-dribble-enter
9337                (concat "(gnus-group-set-info '"
9338                        (gnus-prin1-to-string (gnus-get-info to-group))
9339                        ")"))))
9340
9341           ;; Update the Xref header in this article to point to
9342           ;; the new crossposted article we have just created.
9343           (when (eq action 'crosspost)
9344             (save-excursion
9345               (set-buffer copy-buf)
9346               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9347               (nnheader-replace-header "Xref" new-xref)
9348               (gnus-request-replace-article
9349                article gnus-newsgroup-name (current-buffer))))
9350
9351           ;; run the move/copy/crosspost/respool hook
9352           (run-hook-with-args 'gnus-summary-article-move-hook
9353                               action
9354                               (gnus-data-header
9355                                (assoc article (gnus-data-list nil)))
9356                               gnus-newsgroup-name
9357                               to-newsgroup
9358                               select-method))
9359
9360         ;;;!!!Why is this necessary?
9361         (set-buffer gnus-summary-buffer)
9362
9363         (gnus-summary-goto-subject article)
9364         (when (eq action 'move)
9365           (gnus-summary-mark-article article gnus-canceled-mark))))
9366       (gnus-summary-remove-process-mark article))
9367     ;; Re-activate all groups that have been moved to.
9368     (save-excursion
9369       (set-buffer gnus-group-buffer)
9370       (let ((gnus-group-marked to-groups))
9371         (gnus-group-get-new-news-this-group nil t)))
9372
9373     (gnus-kill-buffer copy-buf)
9374     (gnus-summary-position-point)
9375     (gnus-set-mode-line 'summary)))
9376
9377 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9378   "Copy the current article to some other group.
9379 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9380 When called interactively, if TO-NEWSGROUP is nil, use the value of
9381 the variable `gnus-move-split-methods' for finding a default target
9382 newsgroup.
9383 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9384 re-spool using this method."
9385   (interactive "P")
9386   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9387
9388 (defun gnus-summary-crosspost-article (&optional n)
9389   "Crosspost the current article to some other group."
9390   (interactive "P")
9391   (gnus-summary-move-article n nil nil 'crosspost))
9392
9393 (defcustom gnus-summary-respool-default-method nil
9394   "Default method type for respooling an article.
9395 If nil, use to the current newsgroup method."
9396   :type 'symbol
9397   :group 'gnus-summary-mail)
9398
9399 (defcustom gnus-summary-display-while-building nil
9400   "If non-nil, show and update the summary buffer as it's being built.
9401 If the value is t, update the buffer after every line is inserted.  If
9402 the value is an integer (N), update the display every N lines."
9403   :version "21.4"
9404   :group 'gnus-thread
9405   :type '(choice (const :tag "off" nil)
9406                  number
9407                  (const :tag "frequently" t)))
9408
9409 (defun gnus-summary-respool-article (&optional n method)
9410   "Respool the current article.
9411 The article will be squeezed through the mail spooling process again,
9412 which means that it will be put in some mail newsgroup or other
9413 depending on `nnmail-split-methods'.
9414 If N is a positive number, respool the N next articles.
9415 If N is a negative number, respool the N previous articles.
9416 If N is nil and any articles have been marked with the process mark,
9417 respool those articles instead.
9418
9419 Respooling can be done both from mail groups and \"real\" newsgroups.
9420 In the former case, the articles in question will be moved from the
9421 current group into whatever groups they are destined to.  In the
9422 latter case, they will be copied into the relevant groups."
9423   (interactive
9424    (list current-prefix-arg
9425          (let* ((methods (gnus-methods-using 'respool))
9426                 (methname
9427                  (symbol-name (or gnus-summary-respool-default-method
9428                                   (car (gnus-find-method-for-group
9429                                         gnus-newsgroup-name)))))
9430                 (method
9431                  (gnus-completing-read-with-default
9432                   methname "What backend do you want to use when respooling?"
9433                   methods nil t nil 'gnus-mail-method-history))
9434                 ms)
9435            (cond
9436             ((zerop (length (setq ms (gnus-servers-using-backend
9437                                       (intern method)))))
9438              (list (intern method) ""))
9439             ((= 1 (length ms))
9440              (car ms))
9441             (t
9442              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9443                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9444                            ms-alist))))))))
9445   (unless method
9446     (error "No method given for respooling"))
9447   (if (assoc (symbol-name
9448               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9449              (gnus-methods-using 'respool))
9450       (gnus-summary-move-article n nil method)
9451     (gnus-summary-copy-article n nil method)))
9452
9453 (defun gnus-summary-import-article (file &optional edit)
9454   "Import an arbitrary file into a mail newsgroup."
9455   (interactive "fImport file: \nP")
9456   (let ((group gnus-newsgroup-name)
9457         (now (current-time))
9458         atts lines group-art)
9459     (unless (gnus-check-backend-function 'request-accept-article group)
9460       (error "%s does not support article importing" group))
9461     (or (file-readable-p file)
9462         (not (file-regular-p file))
9463         (error "Can't read %s" file))
9464     (save-excursion
9465       (set-buffer (gnus-get-buffer-create " *import file*"))
9466       (erase-buffer)
9467       (nnheader-insert-file-contents file)
9468       (goto-char (point-min))
9469       (if (nnheader-article-p)
9470           (save-restriction
9471             (goto-char (point-min))
9472             (search-forward "\n\n" nil t)
9473             (narrow-to-region (point-min) (1- (point)))
9474             (goto-char (point-min))
9475             (unless (re-search-forward "^date:" nil t)
9476               (goto-char (point-max))
9477               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9478         ;; This doesn't look like an article, so we fudge some headers.
9479         (setq atts (file-attributes file)
9480               lines (count-lines (point-min) (point-max)))
9481         (insert "From: " (read-string "From: ") "\n"
9482                 "Subject: " (read-string "Subject: ") "\n"
9483                 "Date: " (message-make-date (nth 5 atts)) "\n"
9484                 "Message-ID: " (message-make-message-id) "\n"
9485                 "Lines: " (int-to-string lines) "\n"
9486                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9487       (setq group-art (gnus-request-accept-article group nil t))
9488       (kill-buffer (current-buffer)))
9489     (setq gnus-newsgroup-active (gnus-activate-group group))
9490     (forward-line 1)
9491     (gnus-summary-goto-article (cdr group-art) nil t)
9492     (when edit
9493       (gnus-summary-edit-article))))
9494
9495 (defun gnus-summary-create-article ()
9496   "Create an article in a mail newsgroup."
9497   (interactive)
9498   (let ((group gnus-newsgroup-name)
9499         (now (current-time))
9500         group-art)
9501     (unless (gnus-check-backend-function 'request-accept-article group)
9502       (error "%s does not support article importing" group))
9503     (save-excursion
9504       (set-buffer (gnus-get-buffer-create " *import file*"))
9505       (erase-buffer)
9506       (goto-char (point-min))
9507       ;; This doesn't look like an article, so we fudge some headers.
9508       (insert "From: " (read-string "From: ") "\n"
9509               "Subject: " (read-string "Subject: ") "\n"
9510               "Date: " (message-make-date now) "\n"
9511               "Message-ID: " (message-make-message-id) "\n")
9512       (setq group-art (gnus-request-accept-article group nil t))
9513       (kill-buffer (current-buffer)))
9514     (setq gnus-newsgroup-active (gnus-activate-group group))
9515     (forward-line 1)
9516     (gnus-summary-goto-article (cdr group-art) nil t)
9517     (gnus-summary-edit-article)))
9518
9519 (defun gnus-summary-article-posted-p ()
9520   "Say whether the current (mail) article is available from news as well.
9521 This will be the case if the article has both been mailed and posted."
9522   (interactive)
9523   (let ((id (mail-header-references (gnus-summary-article-header)))
9524         (gnus-override-method (car (gnus-refer-article-methods))))
9525     (if (gnus-request-head id "")
9526         (gnus-message 2 "The current message was found on %s"
9527                       gnus-override-method)
9528       (gnus-message 2 "The current message couldn't be found on %s"
9529                     gnus-override-method)
9530       nil)))
9531
9532 (defun gnus-summary-expire-articles (&optional now)
9533   "Expire all articles that are marked as expirable in the current group."
9534   (interactive)
9535   (when (and (not gnus-group-is-exiting-without-update-p)
9536              (gnus-check-backend-function
9537               'request-expire-articles gnus-newsgroup-name))
9538     ;; This backend supports expiry.
9539     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9540            (expirable (if total
9541                           (progn
9542                             ;; We need to update the info for
9543                             ;; this group for `gnus-list-of-read-articles'
9544                             ;; to give us the right answer.
9545                             (gnus-run-hooks 'gnus-exit-group-hook)
9546                             (gnus-summary-update-info)
9547                             (gnus-list-of-read-articles gnus-newsgroup-name))
9548                         (setq gnus-newsgroup-expirable
9549                               (sort gnus-newsgroup-expirable '<))))
9550            (expiry-wait (if now 'immediate
9551                           (gnus-group-find-parameter
9552                            gnus-newsgroup-name 'expiry-wait)))
9553            (nnmail-expiry-target
9554             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9555                 nnmail-expiry-target))
9556            es)
9557       (when expirable
9558         ;; There are expirable articles in this group, so we run them
9559         ;; through the expiry process.
9560         (gnus-message 6 "Expiring articles...")
9561         (unless (gnus-check-group gnus-newsgroup-name)
9562           (error "Can't open server for %s" gnus-newsgroup-name))
9563         ;; The list of articles that weren't expired is returned.
9564         (save-excursion
9565           (if expiry-wait
9566               (let ((nnmail-expiry-wait-function nil)
9567                     (nnmail-expiry-wait expiry-wait))
9568                 (setq es (gnus-request-expire-articles
9569                           expirable gnus-newsgroup-name)))
9570             (setq es (gnus-request-expire-articles
9571                       expirable gnus-newsgroup-name)))
9572           (unless total
9573             (setq gnus-newsgroup-expirable es))
9574           ;; We go through the old list of expirable, and mark all
9575           ;; really expired articles as nonexistent.
9576           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9577             (let ((gnus-use-cache nil))
9578               (dolist (article expirable)
9579                 (when (and (not (memq article es))
9580                            (gnus-data-find article))
9581                   (gnus-summary-mark-article article gnus-canceled-mark)
9582                   (run-hook-with-args 'gnus-summary-article-expire-hook
9583                                       'delete
9584                                       (gnus-data-header
9585                                        (assoc article (gnus-data-list nil)))
9586                                       gnus-newsgroup-name
9587                                       nil
9588                                       nil))))))
9589         (gnus-message 6 "Expiring articles...done")))))
9590
9591 (defun gnus-summary-expire-articles-now ()
9592   "Expunge all expirable articles in the current group.
9593 This means that *all* articles that are marked as expirable will be
9594 deleted forever, right now."
9595   (interactive)
9596   (or gnus-expert-user
9597       (gnus-yes-or-no-p
9598        "Are you really, really, really sure you want to delete all these messages? ")
9599       (error "Phew!"))
9600   (gnus-summary-expire-articles t))
9601
9602 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9603 (defun gnus-summary-delete-article (&optional n)
9604   "Delete the N next (mail) articles.
9605 This command actually deletes articles.  This is not a marking
9606 command.  The article will disappear forever from your life, never to
9607 return.
9608
9609 If N is negative, delete backwards.
9610 If N is nil and articles have been marked with the process mark,
9611 delete these instead.
9612
9613 If `gnus-novice-user' is non-nil you will be asked for
9614 confirmation before the articles are deleted."
9615   (interactive "P")
9616   (unless (gnus-check-backend-function 'request-expire-articles
9617                                        gnus-newsgroup-name)
9618     (error "The current newsgroup does not support article deletion"))
9619   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9620     (error "Couldn't open server"))
9621   ;; Compute the list of articles to delete.
9622   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9623         (nnmail-expiry-target 'delete)
9624         not-deleted)
9625     (if (and gnus-novice-user
9626              (not (gnus-yes-or-no-p
9627                    (format "Do you really want to delete %s forever? "
9628                            (if (> (length articles) 1)
9629                                (format "these %s articles" (length articles))
9630                              "this article")))))
9631         ()
9632       ;; Delete the articles.
9633       (setq not-deleted (gnus-request-expire-articles
9634                          articles gnus-newsgroup-name 'force))
9635       (while articles
9636         (gnus-summary-remove-process-mark (car articles))
9637         ;; The backend might not have been able to delete the article
9638         ;; after all.
9639         (unless (memq (car articles) not-deleted)
9640           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9641         (let* ((article (car articles))
9642                (ghead  (gnus-data-header
9643                                     (assoc article (gnus-data-list nil)))))
9644           (run-hook-with-args 'gnus-summary-article-delete-hook
9645                               'delete ghead gnus-newsgroup-name nil
9646                               nil))
9647         (setq articles (cdr articles)))
9648       (when not-deleted
9649         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9650     (gnus-summary-position-point)
9651     (gnus-set-mode-line 'summary)
9652     not-deleted))
9653
9654 (defun gnus-summary-edit-article (&optional force)
9655   "Edit the current article.
9656 This will have permanent effect only in mail groups.
9657 If FORCE is non-nil, allow editing of articles even in read-only
9658 groups."
9659   (interactive "P")
9660   (save-excursion
9661     (set-buffer gnus-summary-buffer)
9662     (let ((mail-parse-charset gnus-newsgroup-charset)
9663           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9664       (gnus-set-global-variables)
9665       (when (and (not force)
9666                  (gnus-group-read-only-p))
9667         (error "The current newsgroup does not support article editing"))
9668       (gnus-summary-show-article t)
9669       (gnus-article-edit-article
9670        'ignore
9671        `(lambda (no-highlight)
9672           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9673                 (message-options message-options)
9674                 (message-options-set-recipient)
9675                 (mail-parse-ignored-charsets
9676                  ',gnus-newsgroup-ignored-charsets))
9677             (gnus-summary-edit-article-done
9678              ,(or (mail-header-references gnus-current-headers) "")
9679              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9680
9681 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9682
9683 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9684                                                  no-highlight)
9685   "Make edits to the current article permanent."
9686   (interactive)
9687   (save-excursion
9688     ;; The buffer restriction contains the entire article if it exists.
9689     (when (article-goto-body)
9690       (let ((lines (count-lines (point) (point-max)))
9691             (length (- (point-max) (point)))
9692             (case-fold-search t)
9693             (body (copy-marker (point))))
9694         (goto-char (point-min))
9695         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9696           (delete-region (match-beginning 1) (match-end 1))
9697           (insert (number-to-string length)))
9698         (goto-char (point-min))
9699         (when (re-search-forward
9700                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9701           (delete-region (match-beginning 1) (match-end 1))
9702           (insert (number-to-string length)))
9703         (goto-char (point-min))
9704         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9705           (delete-region (match-beginning 1) (match-end 1))
9706           (insert (number-to-string lines))))))
9707   ;; Replace the article.
9708   (let ((buf (current-buffer)))
9709     (with-temp-buffer
9710       (insert-buffer-substring buf)
9711
9712       (if (and (not read-only)
9713                (not (gnus-request-replace-article
9714                      (cdr gnus-article-current) (car gnus-article-current)
9715                      (current-buffer) t)))
9716           (error "Couldn't replace article")
9717         ;; Update the summary buffer.
9718         (if (and references
9719                  (equal (message-tokenize-header references " ")
9720                         (message-tokenize-header
9721                          (or (message-fetch-field "references") "") " ")))
9722             ;; We only have to update this line.
9723             (save-excursion
9724               (save-restriction
9725                 (message-narrow-to-head)
9726                 (let ((head (buffer-string))
9727                       header)
9728                   (with-temp-buffer
9729                     (insert (format "211 %d Article retrieved.\n"
9730                                     (cdr gnus-article-current)))
9731                     (insert head)
9732                     (insert ".\n")
9733                     (let ((nntp-server-buffer (current-buffer)))
9734                       (setq header (car (gnus-get-newsgroup-headers
9735                                          nil t))))
9736                     (save-excursion
9737                       (set-buffer gnus-summary-buffer)
9738                       (gnus-data-set-header
9739                        (gnus-data-find (cdr gnus-article-current))
9740                        header)
9741                       (gnus-summary-update-article-line
9742                        (cdr gnus-article-current) header)
9743                       (if (gnus-summary-goto-subject
9744                            (cdr gnus-article-current) nil t)
9745                           (gnus-summary-update-secondary-mark
9746                            (cdr gnus-article-current))))))))
9747           ;; Update threads.
9748           (set-buffer (or buffer gnus-summary-buffer))
9749           (gnus-summary-update-article (cdr gnus-article-current))
9750           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9751               (gnus-summary-update-secondary-mark
9752                (cdr gnus-article-current))))
9753         ;; Prettify the article buffer again.
9754         (unless no-highlight
9755           (save-excursion
9756             (set-buffer gnus-article-buffer)
9757             ;;;!!! Fix this -- article should be rehighlighted.
9758             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9759             (set-buffer gnus-original-article-buffer)
9760             (gnus-request-article
9761              (cdr gnus-article-current)
9762              (car gnus-article-current) (current-buffer))))
9763         ;; Prettify the summary buffer line.
9764         (when (gnus-visual-p 'summary-highlight 'highlight)
9765           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9766
9767 (defun gnus-summary-edit-wash (key)
9768   "Perform editing command KEY in the article buffer."
9769   (interactive
9770    (list
9771     (progn
9772       (message "%s" (concat (this-command-keys) "- "))
9773       (read-char))))
9774   (message "")
9775   (gnus-summary-edit-article)
9776   (execute-kbd-macro (concat (this-command-keys) key))
9777   (gnus-article-edit-done))
9778
9779 ;;; Respooling
9780
9781 (defun gnus-summary-respool-query (&optional silent trace)
9782   "Query where the respool algorithm would put this article."
9783   (interactive)
9784   (let (gnus-mark-article-hook)
9785     (gnus-summary-select-article)
9786     (save-excursion
9787       (set-buffer gnus-original-article-buffer)
9788       (let ((groups (nnmail-article-group 'identity trace)))
9789         (unless silent
9790           (if groups
9791               (message "This message would go to %s"
9792                        (mapconcat 'car groups ", "))
9793             (message "This message would go to no groups"))
9794           groups)))))
9795
9796 (defun gnus-summary-respool-trace ()
9797   "Trace where the respool algorithm would put this article.
9798 Display a buffer showing all fancy splitting patterns which matched."
9799   (interactive)
9800   (gnus-summary-respool-query nil t))
9801
9802 ;; Summary marking commands.
9803
9804 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9805   "Mark articles which has the same subject as read, and then select the next.
9806 If UNMARK is positive, remove any kind of mark.
9807 If UNMARK is negative, tick articles."
9808   (interactive "P")
9809   (when unmark
9810     (setq unmark (prefix-numeric-value unmark)))
9811   (let ((count
9812          (gnus-summary-mark-same-subject
9813           (gnus-summary-article-subject) unmark)))
9814     ;; Select next unread article.  If auto-select-same mode, should
9815     ;; select the first unread article.
9816     (gnus-summary-next-article t (and gnus-auto-select-same
9817                                       (gnus-summary-article-subject)))
9818     (gnus-message 7 "%d article%s marked as %s"
9819                   count (if (= count 1) " is" "s are")
9820                   (if unmark "unread" "read"))))
9821
9822 (defun gnus-summary-kill-same-subject (&optional unmark)
9823   "Mark articles which has the same subject as read.
9824 If UNMARK is positive, remove any kind of mark.
9825 If UNMARK is negative, tick articles."
9826   (interactive "P")
9827   (when unmark
9828     (setq unmark (prefix-numeric-value unmark)))
9829   (let ((count
9830          (gnus-summary-mark-same-subject
9831           (gnus-summary-article-subject) unmark)))
9832     ;; If marked as read, go to next unread subject.
9833     (when (null unmark)
9834       ;; Go to next unread subject.
9835       (gnus-summary-next-subject 1 t))
9836     (gnus-message 7 "%d articles are marked as %s"
9837                   count (if unmark "unread" "read"))))
9838
9839 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9840   "Mark articles with same SUBJECT as read, and return marked number.
9841 If optional argument UNMARK is positive, remove any kinds of marks.
9842 If optional argument UNMARK is negative, mark articles as unread instead."
9843   (let ((count 1))
9844     (save-excursion
9845       (cond
9846        ((null unmark)                   ; Mark as read.
9847         (while (and
9848                 (progn
9849                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9850                   (gnus-summary-show-thread) t)
9851                 (gnus-summary-find-subject subject))
9852           (setq count (1+ count))))
9853        ((> unmark 0)                    ; Tick.
9854         (while (and
9855                 (progn
9856                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9857                   (gnus-summary-show-thread) t)
9858                 (gnus-summary-find-subject subject))
9859           (setq count (1+ count))))
9860        (t                               ; Mark as unread.
9861         (while (and
9862                 (progn
9863                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9864                   (gnus-summary-show-thread) t)
9865                 (gnus-summary-find-subject subject))
9866           (setq count (1+ count)))))
9867       (gnus-set-mode-line 'summary)
9868       ;; Return the number of marked articles.
9869       count)))
9870
9871 (defun gnus-summary-mark-as-processable (n &optional unmark)
9872   "Set the process mark on the next N articles.
9873 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9874 the process mark instead.  The difference between N and the actual
9875 number of articles marked is returned."
9876   (interactive "P")
9877   (if (and (null n) (gnus-region-active-p))
9878       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9879     (setq n (prefix-numeric-value n))
9880     (let ((backward (< n 0))
9881           (n (abs n)))
9882       (while (and
9883               (> n 0)
9884               (if unmark
9885                   (gnus-summary-remove-process-mark
9886                    (gnus-summary-article-number))
9887                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9888               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9889         (setq n (1- n)))
9890       (when (/= 0 n)
9891         (gnus-message 7 "No more articles"))
9892       (gnus-summary-recenter)
9893       (gnus-summary-position-point)
9894       n)))
9895
9896 (defun gnus-summary-unmark-as-processable (n)
9897   "Remove the process mark from the next N articles.
9898 If N is negative, unmark backward instead.  The difference between N and
9899 the actual number of articles unmarked is returned."
9900   (interactive "P")
9901   (gnus-summary-mark-as-processable n t))
9902
9903 (defun gnus-summary-unmark-all-processable ()
9904   "Remove the process mark from all articles."
9905   (interactive)
9906   (save-excursion
9907     (while gnus-newsgroup-processable
9908       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9909   (gnus-summary-position-point))
9910
9911 (defun gnus-summary-add-mark (article type)
9912   "Mark ARTICLE with a mark of TYPE."
9913   (let ((vtype (car (assq type gnus-article-mark-lists)))
9914         var)
9915     (if (not vtype)
9916         (error "No such mark type: %s" type)
9917       (setq var (intern (format "gnus-newsgroup-%s" type)))
9918       (set var (cons article (symbol-value var)))
9919       (if (memq type '(processable cached replied forwarded recent saved))
9920           (gnus-summary-update-secondary-mark article)
9921         ;;; !!! This is bogus.  We should find out what primary
9922         ;;; !!! mark we want to set.
9923         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9924
9925 (defun gnus-summary-mark-as-expirable (n)
9926   "Mark N articles forward as expirable.
9927 If N is negative, mark backward instead.  The difference between N and
9928 the actual number of articles marked is returned."
9929   (interactive "p")
9930   (gnus-summary-mark-forward n gnus-expirable-mark))
9931
9932 (defun gnus-summary-mark-as-spam (n)
9933   "Mark N articles forward as spam.
9934 If N is negative, mark backward instead.  The difference between N and
9935 the actual number of articles marked is returned."
9936   (interactive "p")
9937   (gnus-summary-mark-forward n gnus-spam-mark))
9938
9939 (defun gnus-summary-mark-article-as-replied (article)
9940   "Mark ARTICLE as replied to and update the summary line.
9941 ARTICLE can also be a list of articles."
9942   (interactive (list (gnus-summary-article-number)))
9943   (let ((articles (if (listp article) article (list article))))
9944     (dolist (article articles)
9945       (unless (numberp article)
9946         (error "%s is not a number" article))
9947       (push article gnus-newsgroup-replied)
9948       (let ((buffer-read-only nil))
9949         (when (gnus-summary-goto-subject article nil t)
9950           (gnus-summary-update-secondary-mark article))))))
9951
9952 (defun gnus-summary-mark-article-as-forwarded (article)
9953   "Mark ARTICLE as forwarded and update the summary line.
9954 ARTICLE can also be a list of articles."
9955   (let ((articles (if (listp article) article (list article))))
9956     (dolist (article articles)
9957       (push article gnus-newsgroup-forwarded)
9958       (let ((buffer-read-only nil))
9959         (when (gnus-summary-goto-subject article nil t)
9960           (gnus-summary-update-secondary-mark article))))))
9961
9962 (defun gnus-summary-set-bookmark (article)
9963   "Set a bookmark in current article."
9964   (interactive (list (gnus-summary-article-number)))
9965   (when (or (not (get-buffer gnus-article-buffer))
9966             (not gnus-current-article)
9967             (not gnus-article-current)
9968             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9969     (error "No current article selected"))
9970   ;; Remove old bookmark, if one exists.
9971   (gnus-pull article gnus-newsgroup-bookmarks)
9972   ;; Set the new bookmark, which is on the form
9973   ;; (article-number . line-number-in-body).
9974   (push
9975    (cons article
9976          (with-current-buffer gnus-article-buffer
9977            (count-lines
9978             (min (point)
9979                  (save-excursion
9980                    (article-goto-body)
9981                    (point)))
9982             (point))))
9983    gnus-newsgroup-bookmarks)
9984   (gnus-message 6 "A bookmark has been added to the current article."))
9985
9986 (defun gnus-summary-remove-bookmark (article)
9987   "Remove the bookmark from the current article."
9988   (interactive (list (gnus-summary-article-number)))
9989   ;; Remove old bookmark, if one exists.
9990   (if (not (assq article gnus-newsgroup-bookmarks))
9991       (gnus-message 6 "No bookmark in current article.")
9992     (gnus-pull article gnus-newsgroup-bookmarks)
9993     (gnus-message 6 "Removed bookmark.")))
9994
9995 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9996 (defun gnus-summary-mark-as-dormant (n)
9997   "Mark N articles forward as dormant.
9998 If N is negative, mark backward instead.  The difference between N and
9999 the actual number of articles marked is returned."
10000   (interactive "p")
10001   (gnus-summary-mark-forward n gnus-dormant-mark))
10002
10003 (defun gnus-summary-set-process-mark (article)
10004   "Set the process mark on ARTICLE and update the summary line."
10005   (setq gnus-newsgroup-processable
10006         (cons article
10007               (delq article gnus-newsgroup-processable)))
10008   (when (gnus-summary-goto-subject article)
10009     (gnus-summary-show-thread)
10010     (gnus-summary-goto-subject article)
10011     (gnus-summary-update-secondary-mark article)))
10012
10013 (defun gnus-summary-remove-process-mark (article)
10014   "Remove the process mark from ARTICLE and update the summary line."
10015   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10016   (when (gnus-summary-goto-subject article)
10017     (gnus-summary-show-thread)
10018     (gnus-summary-goto-subject article)
10019     (gnus-summary-update-secondary-mark article)))
10020
10021 (defun gnus-summary-set-saved-mark (article)
10022   "Set the process mark on ARTICLE and update the summary line."
10023   (push article gnus-newsgroup-saved)
10024   (when (gnus-summary-goto-subject article)
10025     (gnus-summary-update-secondary-mark article)))
10026
10027 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10028   "Mark N articles as read forwards.
10029 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10030 The difference between N and the actual number of articles marked is
10031 returned.
10032 If NO-EXPIRE, auto-expiry will be inhibited."
10033   (interactive "p")
10034   (gnus-summary-show-thread)
10035   (let ((backward (< n 0))
10036         (gnus-summary-goto-unread
10037          (and gnus-summary-goto-unread
10038               (not (eq gnus-summary-goto-unread 'never))
10039               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10040                                     gnus-ticked-mark gnus-dormant-mark)))))
10041         (n (abs n))
10042         (mark (or mark gnus-del-mark)))
10043     (while (and (> n 0)
10044                 (gnus-summary-mark-article nil mark no-expire)
10045                 (zerop (gnus-summary-next-subject
10046                         (if backward -1 1)
10047                         (and gnus-summary-goto-unread
10048                              (not (eq gnus-summary-goto-unread 'never)))
10049                         t)))
10050       (setq n (1- n)))
10051     (when (/= 0 n)
10052       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10053     (gnus-summary-recenter)
10054     (gnus-summary-position-point)
10055     (gnus-set-mode-line 'summary)
10056     n))
10057
10058 (defun gnus-summary-mark-article-as-read (mark)
10059   "Mark the current article quickly as read with MARK."
10060   (let ((article (gnus-summary-article-number)))
10061     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10062     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10063     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10064     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10065     (push (cons article mark) gnus-newsgroup-reads)
10066     ;; Possibly remove from cache, if that is used.
10067     (when gnus-use-cache
10068       (gnus-cache-enter-remove-article article))
10069     ;; Allow the backend to change the mark.
10070     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10071     ;; Check for auto-expiry.
10072     (when (and gnus-newsgroup-auto-expire
10073                (memq mark gnus-auto-expirable-marks))
10074       (setq mark gnus-expirable-mark)
10075       ;; Let the backend know about the mark change.
10076       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10077       (push article gnus-newsgroup-expirable))
10078     ;; Set the mark in the buffer.
10079     (gnus-summary-update-mark mark 'unread)
10080     t))
10081
10082 (defun gnus-summary-mark-article-as-unread (mark)
10083   "Mark the current article quickly as unread with MARK."
10084   (let* ((article (gnus-summary-article-number))
10085          (old-mark (gnus-summary-article-mark article)))
10086     ;; Allow the backend to change the mark.
10087     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10088     (if (eq mark old-mark)
10089         t
10090       (if (<= article 0)
10091           (progn
10092             (gnus-error 1 "Can't mark negative article numbers")
10093             nil)
10094         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10095         (setq gnus-newsgroup-spam-marked
10096               (delq article gnus-newsgroup-spam-marked))
10097         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10098         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10099         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10100         (cond ((= mark gnus-ticked-mark)
10101                (setq gnus-newsgroup-marked
10102                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10103                                               article)))
10104               ((= mark gnus-spam-mark)
10105                (setq gnus-newsgroup-spam-marked
10106                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10107                                               article)))
10108               ((= mark gnus-dormant-mark)
10109                (setq gnus-newsgroup-dormant
10110                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10111                                               article)))
10112               (t
10113                (setq gnus-newsgroup-unreads
10114                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10115                                               article))))
10116         (gnus-pull article gnus-newsgroup-reads)
10117
10118         ;; See whether the article is to be put in the cache.
10119         (and gnus-use-cache
10120              (vectorp (gnus-summary-article-header article))
10121              (save-excursion
10122                (gnus-cache-possibly-enter-article
10123                 gnus-newsgroup-name article
10124                 (gnus-summary-article-header article)
10125                 (= mark gnus-ticked-mark)
10126                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10127
10128         ;; Fix the mark.
10129         (gnus-summary-update-mark mark 'unread)
10130         t))))
10131
10132 (defun gnus-summary-mark-article (&optional article mark no-expire)
10133   "Mark ARTICLE with MARK.  MARK can be any character.
10134 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10135 `??' (dormant) and `?E' (expirable).
10136 If MARK is nil, then the default character `?r' is used.
10137 If ARTICLE is nil, then the article on the current line will be
10138 marked.
10139 If NO-EXPIRE, auto-expiry will be inhibited."
10140   ;; The mark might be a string.
10141   (when (stringp mark)
10142     (setq mark (aref mark 0)))
10143   ;; If no mark is given, then we check auto-expiring.
10144   (when (null mark)
10145     (setq mark gnus-del-mark))
10146   (when (and (not no-expire)
10147              gnus-newsgroup-auto-expire
10148              (memq mark gnus-auto-expirable-marks))
10149     (setq mark gnus-expirable-mark))
10150   (let ((article (or article (gnus-summary-article-number)))
10151         (old-mark (gnus-summary-article-mark article)))
10152     ;; Allow the backend to change the mark.
10153     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10154     (if (eq mark old-mark)
10155         t
10156       (unless article
10157         (error "No article on current line"))
10158       (if (not (if (or (= mark gnus-unread-mark)
10159                        (= mark gnus-ticked-mark)
10160                        (= mark gnus-spam-mark)
10161                        (= mark gnus-dormant-mark))
10162                    (gnus-mark-article-as-unread article mark)
10163                  (gnus-mark-article-as-read article mark)))
10164           t
10165         ;; See whether the article is to be put in the cache.
10166         (and gnus-use-cache
10167              (not (= mark gnus-canceled-mark))
10168              (vectorp (gnus-summary-article-header article))
10169              (save-excursion
10170                (gnus-cache-possibly-enter-article
10171                 gnus-newsgroup-name article
10172                 (gnus-summary-article-header article)
10173                 (= mark gnus-ticked-mark)
10174                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10175
10176         (when (gnus-summary-goto-subject article nil t)
10177           (let ((buffer-read-only nil))
10178             (gnus-summary-show-thread)
10179             ;; Fix the mark.
10180             (gnus-summary-update-mark mark 'unread)
10181             t))))))
10182
10183 (defun gnus-summary-update-secondary-mark (article)
10184   "Update the secondary (read, process, cache) mark."
10185   (gnus-summary-update-mark
10186    (cond ((memq article gnus-newsgroup-processable)
10187           gnus-process-mark)
10188          ((memq article gnus-newsgroup-cached)
10189           gnus-cached-mark)
10190          ((memq article gnus-newsgroup-replied)
10191           gnus-replied-mark)
10192          ((memq article gnus-newsgroup-forwarded)
10193           gnus-forwarded-mark)
10194          ((memq article gnus-newsgroup-saved)
10195           gnus-saved-mark)
10196          ((memq article gnus-newsgroup-recent)
10197           gnus-recent-mark)
10198          ((memq article gnus-newsgroup-unseen)
10199           gnus-unseen-mark)
10200          (t gnus-no-mark))
10201    'replied)
10202   (when (gnus-visual-p 'summary-highlight 'highlight)
10203     (gnus-run-hooks 'gnus-summary-update-hook))
10204   t)
10205
10206 (defun gnus-summary-update-download-mark (article)
10207   "Update the download mark."
10208   (gnus-summary-update-mark
10209    (cond ((memq article gnus-newsgroup-undownloaded)
10210           gnus-undownloaded-mark)
10211          (gnus-newsgroup-agentized
10212           gnus-downloaded-mark)
10213          (t
10214           gnus-no-mark))
10215    'download)
10216   (gnus-summary-update-line t)
10217   t)
10218
10219 (defun gnus-summary-update-mark (mark type)
10220   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10221         (buffer-read-only nil))
10222     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10223     (when forward
10224       (when (looking-at "\r")
10225         (incf forward))
10226       (when (<= (+ forward (point)) (point-max))
10227         ;; Go to the right position on the line.
10228         (goto-char (+ forward (point)))
10229         ;; Replace the old mark with the new mark.
10230         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10231         ;; Optionally update the marks by some user rule.
10232         (when (eq type 'unread)
10233           (gnus-data-set-mark
10234            (gnus-data-find (gnus-summary-article-number)) mark)
10235           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10236
10237 (defun gnus-mark-article-as-read (article &optional mark)
10238   "Enter ARTICLE in the pertinent lists and remove it from others."
10239   ;; Make the article expirable.
10240   (let ((mark (or mark gnus-del-mark)))
10241     (setq gnus-newsgroup-expirable
10242           (if (= mark gnus-expirable-mark)
10243               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10244             (delq article gnus-newsgroup-expirable)))
10245     ;; Remove from unread and marked lists.
10246     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10247     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10248     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10249     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10250     (push (cons article mark) gnus-newsgroup-reads)
10251     ;; Possibly remove from cache, if that is used.
10252     (when gnus-use-cache
10253       (gnus-cache-enter-remove-article article))
10254     t))
10255
10256 (defun gnus-mark-article-as-unread (article &optional mark)
10257   "Enter ARTICLE in the pertinent lists and remove it from others."
10258   (let ((mark (or mark gnus-ticked-mark)))
10259     (if (<= article 0)
10260         (progn
10261           (gnus-error 1 "Can't mark negative article numbers")
10262           nil)
10263       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10264             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10265             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10266             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10267             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10268
10269       ;; Unsuppress duplicates?
10270       (when gnus-suppress-duplicates
10271         (gnus-dup-unsuppress-article article))
10272
10273       (cond ((= mark gnus-ticked-mark)
10274              (setq gnus-newsgroup-marked
10275                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10276             ((= mark gnus-spam-mark)
10277              (setq gnus-newsgroup-spam-marked
10278                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10279                                             article)))
10280             ((= mark gnus-dormant-mark)
10281              (setq gnus-newsgroup-dormant
10282                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10283             (t
10284              (setq gnus-newsgroup-unreads
10285                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10286       (gnus-pull article gnus-newsgroup-reads)
10287       t)))
10288
10289 (defalias 'gnus-summary-mark-as-unread-forward
10290   'gnus-summary-tick-article-forward)
10291 (make-obsolete 'gnus-summary-mark-as-unread-forward
10292                'gnus-summary-tick-article-forward)
10293 (defun gnus-summary-tick-article-forward (n)
10294   "Tick N articles forwards.
10295 If N is negative, tick backwards instead.
10296 The difference between N and the number of articles ticked is returned."
10297   (interactive "p")
10298   (gnus-summary-mark-forward n gnus-ticked-mark))
10299
10300 (defalias 'gnus-summary-mark-as-unread-backward
10301   'gnus-summary-tick-article-backward)
10302 (make-obsolete 'gnus-summary-mark-as-unread-backward
10303                'gnus-summary-tick-article-backward)
10304 (defun gnus-summary-tick-article-backward (n)
10305   "Tick N articles backwards.
10306 The difference between N and the number of articles ticked is returned."
10307   (interactive "p")
10308   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10309
10310 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10311 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10312 (defun gnus-summary-tick-article (&optional article clear-mark)
10313   "Mark current article as unread.
10314 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10315 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10316   (interactive)
10317   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10318                                        gnus-ticked-mark)))
10319
10320 (defun gnus-summary-mark-as-read-forward (n)
10321   "Mark N articles as read forwards.
10322 If N is negative, mark backwards instead.
10323 The difference between N and the actual number of articles marked is
10324 returned."
10325   (interactive "p")
10326   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10327
10328 (defun gnus-summary-mark-as-read-backward (n)
10329   "Mark the N articles as read backwards.
10330 The difference between N and the actual number of articles marked is
10331 returned."
10332   (interactive "p")
10333   (gnus-summary-mark-forward
10334    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10335
10336 (defun gnus-summary-mark-as-read (&optional article mark)
10337   "Mark current article as read.
10338 ARTICLE specifies the article to be marked as read.
10339 MARK specifies a string to be inserted at the beginning of the line."
10340   (gnus-summary-mark-article article mark))
10341
10342 (defun gnus-summary-clear-mark-forward (n)
10343   "Clear marks from N articles forward.
10344 If N is negative, clear backward instead.
10345 The difference between N and the number of marks cleared is returned."
10346   (interactive "p")
10347   (gnus-summary-mark-forward n gnus-unread-mark))
10348
10349 (defun gnus-summary-clear-mark-backward (n)
10350   "Clear marks from N articles backward.
10351 The difference between N and the number of marks cleared is returned."
10352   (interactive "p")
10353   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10354
10355 (defun gnus-summary-mark-unread-as-read ()
10356   "Intended to be used by `gnus-summary-mark-article-hook'."
10357   (when (memq gnus-current-article gnus-newsgroup-unreads)
10358     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10359
10360 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10361   "Intended to be used by `gnus-summary-mark-article-hook'."
10362   (let ((mark (gnus-summary-article-mark)))
10363     (when (or (gnus-unread-mark-p mark)
10364               (gnus-read-mark-p mark))
10365       (gnus-summary-mark-article gnus-current-article
10366                                  (or new-mark gnus-read-mark)))))
10367
10368 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10369   "Intended to be used by `gnus-summary-mark-article-hook'."
10370   (let ((mark (gnus-summary-article-mark)))
10371     (when (or (gnus-unread-mark-p mark)
10372               (gnus-read-mark-p mark))
10373       (gnus-summary-mark-article (gnus-summary-article-number)
10374                                  (or new-mark gnus-read-mark)))))
10375
10376 (defun gnus-summary-mark-unread-as-ticked ()
10377   "Intended to be used by `gnus-summary-mark-article-hook'."
10378   (when (memq gnus-current-article gnus-newsgroup-unreads)
10379     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10380
10381 (defun gnus-summary-mark-region-as-read (point mark all)
10382   "Mark all unread articles between point and mark as read.
10383 If given a prefix, mark all articles between point and mark as read,
10384 even ticked and dormant ones."
10385   (interactive "r\nP")
10386   (save-excursion
10387     (let (article)
10388       (goto-char point)
10389       (beginning-of-line)
10390       (while (and
10391               (< (point) mark)
10392               (progn
10393                 (when (or all
10394                           (memq (setq article (gnus-summary-article-number))
10395                                 gnus-newsgroup-unreads))
10396                   (gnus-summary-mark-article article gnus-del-mark))
10397                 t)
10398               (gnus-summary-find-next))))))
10399
10400 (defun gnus-summary-mark-below (score mark)
10401   "Mark articles with score less than SCORE with MARK."
10402   (interactive "P\ncMark: ")
10403   (setq score (if score
10404                   (prefix-numeric-value score)
10405                 (or gnus-summary-default-score 0)))
10406   (save-excursion
10407     (set-buffer gnus-summary-buffer)
10408     (goto-char (point-min))
10409     (while
10410         (progn
10411           (and (< (gnus-summary-article-score) score)
10412                (gnus-summary-mark-article nil mark))
10413           (gnus-summary-find-next)))))
10414
10415 (defun gnus-summary-kill-below (&optional score)
10416   "Mark articles with score below SCORE as read."
10417   (interactive "P")
10418   (gnus-summary-mark-below score gnus-killed-mark))
10419
10420 (defun gnus-summary-clear-above (&optional score)
10421   "Clear all marks from articles with score above SCORE."
10422   (interactive "P")
10423   (gnus-summary-mark-above score gnus-unread-mark))
10424
10425 (defun gnus-summary-tick-above (&optional score)
10426   "Tick all articles with score above SCORE."
10427   (interactive "P")
10428   (gnus-summary-mark-above score gnus-ticked-mark))
10429
10430 (defun gnus-summary-mark-above (score mark)
10431   "Mark articles with score over SCORE with MARK."
10432   (interactive "P\ncMark: ")
10433   (setq score (if score
10434                   (prefix-numeric-value score)
10435                 (or gnus-summary-default-score 0)))
10436   (save-excursion
10437     (set-buffer gnus-summary-buffer)
10438     (goto-char (point-min))
10439     (while (and (progn
10440                   (when (> (gnus-summary-article-score) score)
10441                     (gnus-summary-mark-article nil mark))
10442                   t)
10443                 (gnus-summary-find-next)))))
10444
10445 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10446 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10447 (defun gnus-summary-limit-include-expunged (&optional no-error)
10448   "Display all the hidden articles that were expunged for low scores."
10449   (interactive)
10450   (let ((buffer-read-only nil))
10451     (let ((scored gnus-newsgroup-scored)
10452           headers h)
10453       (while scored
10454         (unless (gnus-summary-article-header (caar scored))
10455           (and (setq h (gnus-number-to-header (caar scored)))
10456                (< (cdar scored) gnus-summary-expunge-below)
10457                (push h headers)))
10458         (setq scored (cdr scored)))
10459       (if (not headers)
10460           (when (not no-error)
10461             (error "No expunged articles hidden"))
10462         (goto-char (point-min))
10463         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10464         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10465         (mapcar (lambda (x) (push (mail-header-number x)
10466                                   gnus-newsgroup-limit))
10467                 headers)
10468         (gnus-summary-prepare-unthreaded (nreverse headers))
10469         (goto-char (point-min))
10470         (gnus-summary-position-point)
10471         t))))
10472
10473 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10474   "Mark all unread articles in this newsgroup as read.
10475 If prefix argument ALL is non-nil, ticked and dormant articles will
10476 also be marked as read.
10477 If QUIETLY is non-nil, no questions will be asked.
10478
10479 If TO-HERE is non-nil, it should be a point in the buffer.  All
10480 articles before (after, if REVERSE is set) this point will be marked
10481 as read.
10482
10483 Note that this function will only catch up the unread article
10484 in the current summary buffer limitation.
10485
10486 The number of articles marked as read is returned."
10487   (interactive "P")
10488   (prog1
10489       (save-excursion
10490         (when (or quietly
10491                   (not gnus-interactive-catchup) ;Without confirmation?
10492                   gnus-expert-user
10493                   (gnus-y-or-n-p
10494                    (if all
10495                        "Mark absolutely all articles as read? "
10496                      "Mark all unread articles as read? ")))
10497           (if (and not-mark
10498                    (not gnus-newsgroup-adaptive)
10499                    (not gnus-newsgroup-auto-expire)
10500                    (not gnus-suppress-duplicates)
10501                    (or (not gnus-use-cache)
10502                        (eq gnus-use-cache 'passive)))
10503               (progn
10504                 (when all
10505                   (setq gnus-newsgroup-marked nil
10506                         gnus-newsgroup-spam-marked nil
10507                         gnus-newsgroup-dormant nil))
10508                 (setq gnus-newsgroup-unreads
10509                       (gnus-sorted-nunion
10510                        (gnus-intersection gnus-newsgroup-unreads
10511                                           gnus-newsgroup-downloadable)
10512                        gnus-newsgroup-unfetched)))
10513             ;; We actually mark all articles as canceled, which we
10514             ;; have to do when using auto-expiry or adaptive scoring.
10515             (gnus-summary-show-all-threads)
10516             (if (and to-here reverse)
10517                 (progn
10518                   (goto-char to-here)
10519                   (gnus-summary-mark-current-read-and-unread-as-read
10520                    gnus-catchup-mark)
10521                   (while (gnus-summary-find-next (not all))
10522                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10523               (when (gnus-summary-first-subject (not all))
10524                 (while (and
10525                         (if to-here (< (point) to-here) t)
10526                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10527                         (gnus-summary-find-next (not all))))))
10528             (gnus-set-mode-line 'summary))
10529           t))
10530     (gnus-summary-position-point)))
10531
10532 (defun gnus-summary-catchup-to-here (&optional all)
10533   "Mark all unticked articles before the current one as read.
10534 If ALL is non-nil, also mark ticked and dormant articles as read."
10535   (interactive "P")
10536   (save-excursion
10537     (gnus-save-hidden-threads
10538       (let ((beg (point)))
10539         ;; We check that there are unread articles.
10540         (when (or all (gnus-summary-find-prev))
10541           (gnus-summary-catchup all t beg)))))
10542   (gnus-summary-position-point))
10543
10544 (defun gnus-summary-catchup-from-here (&optional all)
10545   "Mark all unticked articles after (and including) the current one as read.
10546 If ALL is non-nil, also mark ticked and dormant articles as read."
10547   (interactive "P")
10548   (save-excursion
10549     (gnus-save-hidden-threads
10550       (let ((beg (point)))
10551         ;; We check that there are unread articles.
10552         (when (or all (gnus-summary-find-next))
10553           (gnus-summary-catchup all t beg nil t)))))
10554   (gnus-summary-position-point))
10555
10556 (defun gnus-summary-catchup-all (&optional quietly)
10557   "Mark all articles in this newsgroup as read.
10558 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10559 instead, which marks only unread articles as read."
10560   (interactive "P")
10561   (gnus-summary-catchup t quietly))
10562
10563 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10564   "Mark all unread articles in this group as read, then exit.
10565 If prefix argument ALL is non-nil, all articles are marked as read.
10566 If QUIETLY is non-nil, no questions will be asked."
10567   (interactive "P")
10568   (when (gnus-summary-catchup all quietly nil 'fast)
10569     ;; Select next newsgroup or exit.
10570     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10571              (eq gnus-auto-select-next 'quietly))
10572         (gnus-summary-next-group nil)
10573       (gnus-summary-exit))))
10574
10575 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10576   "Mark all articles in this newsgroup as read, and then exit.
10577 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10578 instead, which marks only unread articles as read."
10579   (interactive "P")
10580   (gnus-summary-catchup-and-exit t quietly))
10581
10582 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10583   "Mark all articles in this group as read and select the next group.
10584 If given a prefix, mark all articles, unread as well as ticked, as
10585 read."
10586   (interactive "P")
10587   (save-excursion
10588     (gnus-summary-catchup all))
10589   (gnus-summary-next-group))
10590
10591 ;;;
10592 ;;; with article
10593 ;;;
10594
10595 (defmacro gnus-with-article (article &rest forms)
10596   "Select ARTICLE and perform FORMS in the original article buffer.
10597 Then replace the article with the result."
10598   `(progn
10599      ;; We don't want the article to be marked as read.
10600      (let (gnus-mark-article-hook)
10601        (gnus-summary-select-article t t nil ,article))
10602      (set-buffer gnus-original-article-buffer)
10603      ,@forms
10604      (if (not (gnus-check-backend-function
10605                'request-replace-article (car gnus-article-current)))
10606          (gnus-message 5 "Read-only group; not replacing")
10607        (unless (gnus-request-replace-article
10608                 ,article (car gnus-article-current)
10609                 (current-buffer) t)
10610          (error "Couldn't replace article")))
10611      ;; The cache and backlog have to be flushed somewhat.
10612      (when gnus-keep-backlog
10613        (gnus-backlog-remove-article
10614         (car gnus-article-current) (cdr gnus-article-current)))
10615      (when gnus-use-cache
10616        (gnus-cache-update-article
10617         (car gnus-article-current) (cdr gnus-article-current)))))
10618
10619 (put 'gnus-with-article 'lisp-indent-function 1)
10620 (put 'gnus-with-article 'edebug-form-spec '(form body))
10621
10622 ;; Thread-based commands.
10623
10624 (defun gnus-summary-articles-in-thread (&optional article)
10625   "Return a list of all articles in the current thread.
10626 If ARTICLE is non-nil, return all articles in the thread that starts
10627 with that article."
10628   (let* ((article (or article (gnus-summary-article-number)))
10629          (data (gnus-data-find-list article))
10630          (top-level (gnus-data-level (car data)))
10631          (top-subject
10632           (cond ((null gnus-thread-operation-ignore-subject)
10633                  (gnus-simplify-subject-re
10634                   (mail-header-subject (gnus-data-header (car data)))))
10635                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10636                  (gnus-simplify-subject-fuzzy
10637                   (mail-header-subject (gnus-data-header (car data)))))
10638                 (t nil)))
10639          (end-point (save-excursion
10640                       (if (gnus-summary-go-to-next-thread)
10641                           (point) (point-max))))
10642          articles)
10643     (while (and data
10644                 (< (gnus-data-pos (car data)) end-point))
10645       (when (or (not top-subject)
10646                 (string= top-subject
10647                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10648                              (gnus-simplify-subject-fuzzy
10649                               (mail-header-subject
10650                                (gnus-data-header (car data))))
10651                            (gnus-simplify-subject-re
10652                             (mail-header-subject
10653                              (gnus-data-header (car data)))))))
10654         (push (gnus-data-number (car data)) articles))
10655       (unless (and (setq data (cdr data))
10656                    (> (gnus-data-level (car data)) top-level))
10657         (setq data nil)))
10658     ;; Return the list of articles.
10659     (nreverse articles)))
10660
10661 (defun gnus-summary-rethread-current ()
10662   "Rethread the thread the current article is part of."
10663   (interactive)
10664   (let* ((gnus-show-threads t)
10665          (article (gnus-summary-article-number))
10666          (id (mail-header-id (gnus-summary-article-header)))
10667          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10668     (unless id
10669       (error "No article on the current line"))
10670     (gnus-rebuild-thread id)
10671     (gnus-summary-goto-subject article)))
10672
10673 (defun gnus-summary-reparent-thread ()
10674   "Make the current article child of the marked (or previous) article.
10675
10676 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10677 is non-nil or the Subject: of both articles are the same."
10678   (interactive)
10679   (unless (not (gnus-group-read-only-p))
10680     (error "The current newsgroup does not support article editing"))
10681   (unless (<= (length gnus-newsgroup-processable) 1)
10682     (error "No more than one article may be marked"))
10683   (save-window-excursion
10684     (let ((gnus-article-buffer " *reparent*")
10685           (current-article (gnus-summary-article-number))
10686           ;; First grab the marked article, otherwise one line up.
10687           (parent-article (if (not (null gnus-newsgroup-processable))
10688                               (car gnus-newsgroup-processable)
10689                             (save-excursion
10690                               (if (eq (forward-line -1) 0)
10691                                   (gnus-summary-article-number)
10692                                 (error "Beginning of summary buffer"))))))
10693       (unless (not (eq current-article parent-article))
10694         (error "An article may not be self-referential"))
10695       (let ((message-id (mail-header-id
10696                          (gnus-summary-article-header parent-article))))
10697         (unless (and message-id (not (equal message-id "")))
10698           (error "No message-id in desired parent"))
10699         (gnus-with-article current-article
10700           (save-restriction
10701             (goto-char (point-min))
10702             (message-narrow-to-head)
10703             (if (re-search-forward "^References: " nil t)
10704                 (progn
10705                   (re-search-forward "^[^ \t]" nil t)
10706                   (forward-line -1)
10707                   (end-of-line)
10708                   (insert " " message-id))
10709               (insert "References: " message-id "\n"))))
10710         (set-buffer gnus-summary-buffer)
10711         (gnus-summary-unmark-all-processable)
10712         (gnus-summary-update-article current-article)
10713         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10714             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10715         (gnus-summary-rethread-current)
10716         (gnus-message 3 "Article %d is now the child of article %d"
10717                       current-article parent-article)))))
10718
10719 (defun gnus-summary-toggle-threads (&optional arg)
10720   "Toggle showing conversation threads.
10721 If ARG is positive number, turn showing conversation threads on."
10722   (interactive "P")
10723   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10724     (setq gnus-show-threads
10725           (if (null arg) (not gnus-show-threads)
10726             (> (prefix-numeric-value arg) 0)))
10727     (gnus-summary-prepare)
10728     (gnus-summary-goto-subject current)
10729     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10730     (gnus-summary-position-point)))
10731
10732 (defun gnus-summary-show-all-threads ()
10733   "Show all threads."
10734   (interactive)
10735   (save-excursion
10736     (let ((buffer-read-only nil))
10737       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10738   (gnus-summary-position-point))
10739
10740 (defun gnus-summary-show-thread ()
10741   "Show thread subtrees.
10742 Returns nil if no thread was there to be shown."
10743   (interactive)
10744   (let ((buffer-read-only nil)
10745         (orig (point))
10746         (end (point-at-eol))
10747         ;; Leave point at bol
10748         (beg (progn (beginning-of-line) (point))))
10749     (prog1
10750         ;; Any hidden lines here?
10751         (search-forward "\r" end t)
10752       (subst-char-in-region beg end ?\^M ?\n t)
10753       (goto-char orig)
10754       (gnus-summary-position-point))))
10755
10756 (defun gnus-summary-maybe-hide-threads ()
10757   "If requested, hide the threads that should be hidden."
10758   (when (and gnus-show-threads
10759              gnus-thread-hide-subtree)
10760     (gnus-summary-hide-all-threads
10761      (if (or (consp gnus-thread-hide-subtree)
10762              (functionp gnus-thread-hide-subtree))
10763          (gnus-make-predicate gnus-thread-hide-subtree)
10764        nil))))
10765
10766 ;;; Hiding predicates.
10767
10768 (defun gnus-article-unread-p (header)
10769   (memq (mail-header-number header) gnus-newsgroup-unreads))
10770
10771 (defun gnus-article-unseen-p (header)
10772   (memq (mail-header-number header) gnus-newsgroup-unseen))
10773
10774 (defun gnus-map-articles (predicate articles)
10775   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10776   (apply 'gnus-or (mapcar predicate
10777                           (mapcar 'gnus-summary-article-header articles))))
10778
10779 (defun gnus-summary-hide-all-threads (&optional predicate)
10780   "Hide all thread subtrees.
10781 If PREDICATE is supplied, threads that satisfy this predicate
10782 will not be hidden."
10783   (interactive)
10784   (save-excursion
10785     (goto-char (point-min))
10786     (let ((end nil))
10787       (while (not end)
10788         (when (or (not predicate)
10789                   (gnus-map-articles
10790                    predicate (gnus-summary-article-children)))
10791             (gnus-summary-hide-thread))
10792         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10793   (gnus-summary-position-point))
10794
10795 (defun gnus-summary-hide-thread ()
10796   "Hide thread subtrees.
10797 If PREDICATE is supplied, threads that satisfy this predicate
10798 will not be hidden.
10799 Returns nil if no threads were there to be hidden."
10800   (interactive)
10801   (let ((buffer-read-only nil)
10802         (start (point))
10803         (article (gnus-summary-article-number)))
10804     (goto-char start)
10805     ;; Go forward until either the buffer ends or the subthread
10806     ;; ends.
10807     (when (and (not (eobp))
10808                (or (zerop (gnus-summary-next-thread 1 t))
10809                    (goto-char (point-max))))
10810       (prog1
10811           (if (and (> (point) start)
10812                    (search-backward "\n" start t))
10813               (progn
10814                 (subst-char-in-region start (point) ?\n ?\^M)
10815                 (gnus-summary-goto-subject article))
10816             (goto-char start)
10817             nil)))))
10818
10819 (defun gnus-summary-go-to-next-thread (&optional previous)
10820   "Go to the same level (or less) next thread.
10821 If PREVIOUS is non-nil, go to previous thread instead.
10822 Return the article number moved to, or nil if moving was impossible."
10823   (let ((level (gnus-summary-thread-level))
10824         (way (if previous -1 1))
10825         (beg (point)))
10826     (forward-line way)
10827     (while (and (not (eobp))
10828                 (< level (gnus-summary-thread-level)))
10829       (forward-line way))
10830     (if (eobp)
10831         (progn
10832           (goto-char beg)
10833           nil)
10834       (setq beg (point))
10835       (prog1
10836           (gnus-summary-article-number)
10837         (goto-char beg)))))
10838
10839 (defun gnus-summary-next-thread (n &optional silent)
10840   "Go to the same level next N'th thread.
10841 If N is negative, search backward instead.
10842 Returns the difference between N and the number of skips actually
10843 done.
10844
10845 If SILENT, don't output messages."
10846   (interactive "p")
10847   (let ((backward (< n 0))
10848         (n (abs n)))
10849     (while (and (> n 0)
10850                 (gnus-summary-go-to-next-thread backward))
10851       (decf n))
10852     (unless silent
10853       (gnus-summary-position-point))
10854     (when (and (not silent) (/= 0 n))
10855       (gnus-message 7 "No more threads"))
10856     n))
10857
10858 (defun gnus-summary-prev-thread (n)
10859   "Go to the same level previous N'th thread.
10860 Returns the difference between N and the number of skips actually
10861 done."
10862   (interactive "p")
10863   (gnus-summary-next-thread (- n)))
10864
10865 (defun gnus-summary-go-down-thread ()
10866   "Go down one level in the current thread."
10867   (let ((children (gnus-summary-article-children)))
10868     (when children
10869       (gnus-summary-goto-subject (car children)))))
10870
10871 (defun gnus-summary-go-up-thread ()
10872   "Go up one level in the current thread."
10873   (let ((parent (gnus-summary-article-parent)))
10874     (when parent
10875       (gnus-summary-goto-subject parent))))
10876
10877 (defun gnus-summary-down-thread (n)
10878   "Go down thread N steps.
10879 If N is negative, go up instead.
10880 Returns the difference between N and how many steps down that were
10881 taken."
10882   (interactive "p")
10883   (let ((up (< n 0))
10884         (n (abs n)))
10885     (while (and (> n 0)
10886                 (if up (gnus-summary-go-up-thread)
10887                   (gnus-summary-go-down-thread)))
10888       (setq n (1- n)))
10889     (gnus-summary-position-point)
10890     (when (/= 0 n)
10891       (gnus-message 7 "Can't go further"))
10892     n))
10893
10894 (defun gnus-summary-up-thread (n)
10895   "Go up thread N steps.
10896 If N is negative, go down instead.
10897 Returns the difference between N and how many steps down that were
10898 taken."
10899   (interactive "p")
10900   (gnus-summary-down-thread (- n)))
10901
10902 (defun gnus-summary-top-thread ()
10903   "Go to the top of the thread."
10904   (interactive)
10905   (while (gnus-summary-go-up-thread))
10906   (gnus-summary-article-number))
10907
10908 (defun gnus-summary-kill-thread (&optional unmark)
10909   "Mark articles under current thread as read.
10910 If the prefix argument is positive, remove any kinds of marks.
10911 If the prefix argument is negative, tick articles instead."
10912   (interactive "P")
10913   (when unmark
10914     (setq unmark (prefix-numeric-value unmark)))
10915   (let ((articles (gnus-summary-articles-in-thread)))
10916     (save-excursion
10917       ;; Expand the thread.
10918       (gnus-summary-show-thread)
10919       ;; Mark all the articles.
10920       (while articles
10921         (gnus-summary-goto-subject (car articles))
10922         (cond ((null unmark)
10923                (gnus-summary-mark-article-as-read gnus-killed-mark))
10924               ((> unmark 0)
10925                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10926               (t
10927                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10928         (setq articles (cdr articles))))
10929     ;; Hide killed subtrees.
10930     (and (null unmark)
10931          gnus-thread-hide-killed
10932          (gnus-summary-hide-thread))
10933     ;; If marked as read, go to next unread subject.
10934     (when (null unmark)
10935       ;; Go to next unread subject.
10936       (gnus-summary-next-subject 1 t)))
10937   (gnus-set-mode-line 'summary))
10938
10939 ;; Summary sorting commands
10940
10941 (defun gnus-summary-sort-by-number (&optional reverse)
10942   "Sort the summary buffer by article number.
10943 Argument REVERSE means reverse order."
10944   (interactive "P")
10945   (gnus-summary-sort 'number reverse))
10946
10947 (defun gnus-summary-sort-by-random (&optional reverse)
10948   "Randomize the order in the summary buffer.
10949 Argument REVERSE means to randomize in reverse order."
10950   (interactive "P")
10951   (gnus-summary-sort 'random reverse))
10952
10953 (defun gnus-summary-sort-by-author (&optional reverse)
10954   "Sort the summary buffer by author name alphabetically.
10955 If `case-fold-search' is non-nil, case of letters is ignored.
10956 Argument REVERSE means reverse order."
10957   (interactive "P")
10958   (gnus-summary-sort 'author reverse))
10959
10960 (defun gnus-summary-sort-by-recipient (&optional reverse)
10961   "Sort the summary buffer by recipient name alphabetically.
10962 If `case-fold-search' is non-nil, case of letters is ignored.
10963 Argument REVERSE means reverse order."
10964   (interactive "P")
10965   (gnus-summary-sort 'recipient reverse))
10966
10967 (defun gnus-summary-sort-by-subject (&optional reverse)
10968   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10969 If `case-fold-search' is non-nil, case of letters is ignored.
10970 Argument REVERSE means reverse order."
10971   (interactive "P")
10972   (gnus-summary-sort 'subject reverse))
10973
10974 (defun gnus-summary-sort-by-date (&optional reverse)
10975   "Sort the summary buffer by date.
10976 Argument REVERSE means reverse order."
10977   (interactive "P")
10978   (gnus-summary-sort 'date reverse))
10979
10980 (defun gnus-summary-sort-by-score (&optional reverse)
10981   "Sort the summary buffer by score.
10982 Argument REVERSE means reverse order."
10983   (interactive "P")
10984   (gnus-summary-sort 'score reverse))
10985
10986 (defun gnus-summary-sort-by-lines (&optional reverse)
10987   "Sort the summary buffer by the number of lines.
10988 Argument REVERSE means reverse order."
10989   (interactive "P")
10990   (gnus-summary-sort 'lines reverse))
10991
10992 (defun gnus-summary-sort-by-chars (&optional reverse)
10993   "Sort the summary buffer by article length.
10994 Argument REVERSE means reverse order."
10995   (interactive "P")
10996   (gnus-summary-sort 'chars reverse))
10997
10998 (defun gnus-summary-sort-by-original (&optional reverse)
10999   "Sort the summary buffer using the default sorting method.
11000 Argument REVERSE means reverse order."
11001   (interactive "P")
11002   (let* ((buffer-read-only)
11003          (gnus-summary-prepare-hook nil))
11004     ;; We do the sorting by regenerating the threads.
11005     (gnus-summary-prepare)
11006     ;; Hide subthreads if needed.
11007     (gnus-summary-maybe-hide-threads)))
11008
11009 (defun gnus-summary-sort (predicate reverse)
11010   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11011   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11012          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11013          (gnus-thread-sort-functions
11014           (if (not reverse)
11015               thread
11016             `(lambda (t1 t2)
11017                (,thread t2 t1))))
11018          (gnus-sort-gathered-threads-function
11019           gnus-thread-sort-functions)
11020          (gnus-article-sort-functions
11021           (if (not reverse)
11022               article
11023             `(lambda (t1 t2)
11024                (,article t2 t1))))
11025          (buffer-read-only)
11026          (gnus-summary-prepare-hook nil))
11027     ;; We do the sorting by regenerating the threads.
11028     (gnus-summary-prepare)
11029     ;; Hide subthreads if needed.
11030     (gnus-summary-maybe-hide-threads)))
11031
11032 ;; Summary saving commands.
11033
11034 (defun gnus-summary-save-article (&optional n not-saved)
11035   "Save the current article using the default saver function.
11036 If N is a positive number, save the N next articles.
11037 If N is a negative number, save the N previous articles.
11038 If N is nil and any articles have been marked with the process mark,
11039 save those articles instead.
11040 The variable `gnus-default-article-saver' specifies the saver function."
11041   (interactive "P")
11042   (let* ((articles (gnus-summary-work-articles n))
11043          (save-buffer (save-excursion
11044                         (nnheader-set-temp-buffer " *Gnus Save*")))
11045          (num (length articles))
11046          header file)
11047     (dolist (article articles)
11048       (setq header (gnus-summary-article-header article))
11049       (if (not (vectorp header))
11050           ;; This is a pseudo-article.
11051           (if (assq 'name header)
11052               (gnus-copy-file (cdr (assq 'name header)))
11053             (gnus-message 1 "Article %d is unsaveable" article))
11054         ;; This is a real article.
11055         (save-window-excursion
11056           (let ((gnus-display-mime-function nil)
11057                 (gnus-article-prepare-hook nil))
11058             (gnus-summary-select-article t nil nil article)))
11059         (save-excursion
11060           (set-buffer save-buffer)
11061           (erase-buffer)
11062           (insert-buffer-substring gnus-original-article-buffer))
11063         (setq file (gnus-article-save save-buffer file num))
11064         (gnus-summary-remove-process-mark article)
11065         (unless not-saved
11066           (gnus-summary-set-saved-mark article))))
11067     (gnus-kill-buffer save-buffer)
11068     (gnus-summary-position-point)
11069     (gnus-set-mode-line 'summary)
11070     n))
11071
11072 (defun gnus-summary-pipe-output (&optional arg headers)
11073   "Pipe the current article to a subprocess.
11074 If N is a positive number, pipe the N next articles.
11075 If N is a negative number, pipe the N previous articles.
11076 If N is nil and any articles have been marked with the process mark,
11077 pipe those articles instead.
11078 If HEADERS (the symbolic prefix), include the headers, too."
11079   (interactive (gnus-interactive "P\ny"))
11080   (require 'gnus-art)
11081   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11082         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11083     (gnus-summary-save-article arg t))
11084   (let ((buffer (get-buffer "*Shell Command Output*")))
11085     (when (and buffer
11086                (not (zerop (buffer-size buffer))))
11087       (gnus-configure-windows 'pipe))))
11088
11089 (defun gnus-summary-save-article-mail (&optional arg)
11090   "Append the current article to an mail file.
11091 If N is a positive number, save the N next articles.
11092 If N is a negative number, save the N previous articles.
11093 If N is nil and any articles have been marked with the process mark,
11094 save those articles instead."
11095   (interactive "P")
11096   (require 'gnus-art)
11097   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11098     (gnus-summary-save-article arg)))
11099
11100 (defun gnus-summary-save-article-rmail (&optional arg)
11101   "Append the current article to an rmail file.
11102 If N is a positive number, save the N next articles.
11103 If N is a negative number, save the N previous articles.
11104 If N is nil and any articles have been marked with the process mark,
11105 save those articles instead."
11106   (interactive "P")
11107   (require 'gnus-art)
11108   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11109     (gnus-summary-save-article arg)))
11110
11111 (defun gnus-summary-save-article-file (&optional arg)
11112   "Append the current article to a file.
11113 If N is a positive number, save the N next articles.
11114 If N is a negative number, save the N previous articles.
11115 If N is nil and any articles have been marked with the process mark,
11116 save those articles instead."
11117   (interactive "P")
11118   (require 'gnus-art)
11119   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11120     (gnus-summary-save-article arg)))
11121
11122 (defun gnus-summary-write-article-file (&optional arg)
11123   "Write the current article to a file, deleting the previous file.
11124 If N is a positive number, save the N next articles.
11125 If N is a negative number, save the N previous articles.
11126 If N is nil and any articles have been marked with the process mark,
11127 save those articles instead."
11128   (interactive "P")
11129   (require 'gnus-art)
11130   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11131     (gnus-summary-save-article arg)))
11132
11133 (defun gnus-summary-save-article-body-file (&optional arg)
11134   "Append the current article body to a file.
11135 If N is a positive number, save the N next articles.
11136 If N is a negative number, save the N previous articles.
11137 If N is nil and any articles have been marked with the process mark,
11138 save those articles instead."
11139   (interactive "P")
11140   (require 'gnus-art)
11141   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11142     (gnus-summary-save-article arg)))
11143
11144 (defun gnus-summary-muttprint (&optional arg)
11145   "Print the current article using Muttprint.
11146 If N is a positive number, save the N next articles.
11147 If N is a negative number, save the N previous articles.
11148 If N is nil and any articles have been marked with the process mark,
11149 save those articles instead."
11150   (interactive "P")
11151   (require 'gnus-art)
11152   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11153     (gnus-summary-save-article arg t)))
11154
11155 (defun gnus-summary-pipe-message (program)
11156   "Pipe the current article through PROGRAM."
11157   (interactive "sProgram: ")
11158   (gnus-summary-select-article)
11159   (let ((mail-header-separator ""))
11160     (gnus-eval-in-buffer-window gnus-article-buffer
11161       (save-restriction
11162         (widen)
11163         (let ((start (window-start))
11164               buffer-read-only)
11165           (message-pipe-buffer-body program)
11166           (set-window-start (get-buffer-window (current-buffer)) start))))))
11167
11168 (defun gnus-get-split-value (methods)
11169   "Return a value based on the split METHODS."
11170   (let (split-name method result match)
11171     (when methods
11172       (save-excursion
11173         (set-buffer gnus-original-article-buffer)
11174         (save-restriction
11175           (nnheader-narrow-to-headers)
11176           (while (and methods (not split-name))
11177             (goto-char (point-min))
11178             (setq method (pop methods))
11179             (setq match (car method))
11180             (when (cond
11181                    ((stringp match)
11182                     ;; Regular expression.
11183                     (ignore-errors
11184                       (re-search-forward match nil t)))
11185                    ((functionp match)
11186                     ;; Function.
11187                     (save-restriction
11188                       (widen)
11189                       (setq result (funcall match gnus-newsgroup-name))))
11190                    ((consp match)
11191                     ;; Form.
11192                     (save-restriction
11193                       (widen)
11194                       (setq result (eval match)))))
11195               (setq split-name (cdr method))
11196               (cond ((stringp result)
11197                      (push (expand-file-name
11198                             result gnus-article-save-directory)
11199                            split-name))
11200                     ((consp result)
11201                      (setq split-name (append result split-name)))))))))
11202     (nreverse split-name)))
11203
11204 (defun gnus-valid-move-group-p (group)
11205   (and (boundp group)
11206        (symbol-name group)
11207        (symbol-value group)
11208        (gnus-get-function (gnus-find-method-for-group
11209                            (symbol-name group)) 'request-accept-article t)))
11210
11211 (defun gnus-read-move-group-name (prompt default articles prefix)
11212   "Read a group name."
11213   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11214          (minibuffer-confirm-incomplete nil) ; XEmacs
11215          (prom
11216           (format "%s %s to:"
11217                   prompt
11218                   (if (> (length articles) 1)
11219                       (format "these %d articles" (length articles))
11220                     "this article")))
11221          (to-newsgroup
11222           (cond
11223            ((null split-name)
11224             (gnus-completing-read-with-default
11225              default prom
11226              gnus-active-hashtb
11227              'gnus-valid-move-group-p
11228              nil prefix
11229              'gnus-group-history))
11230            ((= 1 (length split-name))
11231             (gnus-completing-read-with-default
11232              (car split-name) prom
11233              gnus-active-hashtb
11234              'gnus-valid-move-group-p
11235              nil nil
11236              'gnus-group-history))
11237            (t
11238             (gnus-completing-read-with-default
11239              nil prom
11240              (mapcar 'list (nreverse split-name))
11241              nil nil nil
11242              'gnus-group-history))))
11243          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11244     (when to-newsgroup
11245       (if (or (string= to-newsgroup "")
11246               (string= to-newsgroup prefix))
11247           (setq to-newsgroup default))
11248       (unless to-newsgroup
11249         (error "No group name entered"))
11250       (or (gnus-active to-newsgroup)
11251           (gnus-activate-group to-newsgroup nil nil to-method)
11252           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11253                                      to-newsgroup))
11254               (or (and (gnus-request-create-group to-newsgroup to-method)
11255                        (gnus-activate-group
11256                         to-newsgroup nil nil to-method)
11257                        (gnus-subscribe-group to-newsgroup))
11258                   (error "Couldn't create group %s" to-newsgroup)))
11259           (error "No such group: %s" to-newsgroup)))
11260     to-newsgroup))
11261
11262 (defun gnus-summary-save-parts (type dir n &optional reverse)
11263   "Save parts matching TYPE to DIR.
11264 If REVERSE, save parts that do not match TYPE."
11265   (interactive
11266    (list (read-string "Save parts of type: "
11267                       (or (car gnus-summary-save-parts-type-history)
11268                           gnus-summary-save-parts-default-mime)
11269                       'gnus-summary-save-parts-type-history)
11270          (setq gnus-summary-save-parts-last-directory
11271                (read-file-name "Save to directory: "
11272                                gnus-summary-save-parts-last-directory
11273                                nil t))
11274          current-prefix-arg))
11275   (gnus-summary-iterate n
11276     (let ((gnus-display-mime-function nil)
11277           (gnus-inhibit-treatment t))
11278       (gnus-summary-select-article))
11279     (save-excursion
11280       (set-buffer gnus-article-buffer)
11281       (let ((handles (or gnus-article-mime-handles
11282                          (mm-dissect-buffer nil gnus-article-loose-mime)
11283                          (and gnus-article-emulate-mime
11284                               (mm-uu-dissect)))))
11285         (when handles
11286           (gnus-summary-save-parts-1 type dir handles reverse)
11287           (unless gnus-article-mime-handles ;; Don't destroy this case.
11288             (mm-destroy-parts handles)))))))
11289
11290 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11291   (if (stringp (car handle))
11292       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11293               (cdr handle))
11294     (when (if reverse
11295               (not (string-match type (mm-handle-media-type handle)))
11296             (string-match type (mm-handle-media-type handle)))
11297       (let ((file (expand-file-name
11298                    (gnus-map-function
11299                     mm-file-name-rewrite-functions
11300                     (file-name-nondirectory
11301                      (or
11302                       (mail-content-type-get
11303                        (mm-handle-disposition handle) 'filename)
11304                       (mail-content-type-get
11305                        (mm-handle-type handle) 'name)
11306                       (concat gnus-newsgroup-name
11307                               "." (number-to-string
11308                                    (cdr gnus-article-current))))))
11309                    dir)))
11310         (unless (file-exists-p file)
11311           (mm-save-part-to-file handle file))))))
11312
11313 ;; Summary extract commands
11314
11315 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11316   (let ((buffer-read-only nil)
11317         (article (gnus-summary-article-number))
11318         after-article b e)
11319     (unless (gnus-summary-goto-subject article)
11320       (error "No such article: %d" article))
11321     (gnus-summary-position-point)
11322     ;; If all commands are to be bunched up on one line, we collect
11323     ;; them here.
11324     (unless gnus-view-pseudos-separately
11325       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11326             files action)
11327         (while ps
11328           (setq action (cdr (assq 'action (car ps))))
11329           (setq files (list (cdr (assq 'name (car ps)))))
11330           (while (and ps (cdr ps)
11331                       (string= (or action "1")
11332                                (or (cdr (assq 'action (cadr ps))) "2")))
11333             (push (cdr (assq 'name (cadr ps))) files)
11334             (setcdr ps (cddr ps)))
11335           (when files
11336             (when (not (string-match "%s" action))
11337               (push " " files))
11338             (push " " files)
11339             (when (assq 'execute (car ps))
11340               (setcdr (assq 'execute (car ps))
11341                       (funcall (if (string-match "%s" action)
11342                                    'format 'concat)
11343                                action
11344                                (mapconcat
11345                                 (lambda (f)
11346                                   (if (equal f " ")
11347                                       f
11348                                     (shell-quote-argument f)))
11349                                 files " ")))))
11350           (setq ps (cdr ps)))))
11351     (if (and gnus-view-pseudos (not not-view))
11352         (while pslist
11353           (when (assq 'execute (car pslist))
11354             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11355                                   (eq gnus-view-pseudos 'not-confirm)))
11356           (setq pslist (cdr pslist)))
11357       (save-excursion
11358         (while pslist
11359           (setq after-article (or (cdr (assq 'article (car pslist)))
11360                                   (gnus-summary-article-number)))
11361           (gnus-summary-goto-subject after-article)
11362           (forward-line 1)
11363           (setq b (point))
11364           (insert "    " (file-name-nondirectory
11365                           (cdr (assq 'name (car pslist))))
11366                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11367           (setq e (point))
11368           (forward-line -1)             ; back to `b'
11369           (gnus-add-text-properties
11370            b (1- e) (list 'gnus-number gnus-reffed-article-number
11371                           gnus-mouse-face-prop gnus-mouse-face))
11372           (gnus-data-enter
11373            after-article gnus-reffed-article-number
11374            gnus-unread-mark b (car pslist) 0 (- e b))
11375           (setq gnus-newsgroup-unreads
11376                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11377                                          gnus-reffed-article-number))
11378           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11379           (setq pslist (cdr pslist)))))))
11380
11381 (defun gnus-pseudos< (p1 p2)
11382   (let ((c1 (cdr (assq 'action p1)))
11383         (c2 (cdr (assq 'action p2))))
11384     (and c1 c2 (string< c1 c2))))
11385
11386 (defun gnus-request-pseudo-article (props)
11387   (cond ((assq 'execute props)
11388          (gnus-execute-command (cdr (assq 'execute props)))))
11389   (let ((gnus-current-article (gnus-summary-article-number)))
11390     (gnus-run-hooks 'gnus-mark-article-hook)))
11391
11392 (defun gnus-execute-command (command &optional automatic)
11393   (save-excursion
11394     (gnus-article-setup-buffer)
11395     (set-buffer gnus-article-buffer)
11396     (setq buffer-read-only nil)
11397     (let ((command (if automatic command
11398                      (read-string "Command: " (cons command 0)))))
11399       (erase-buffer)
11400       (insert "$ " command "\n\n")
11401       (if gnus-view-pseudo-asynchronously
11402           (start-process "gnus-execute" (current-buffer) shell-file-name
11403                          shell-command-switch command)
11404         (call-process shell-file-name nil t nil
11405                       shell-command-switch command)))))
11406
11407 ;; Summary kill commands.
11408
11409 (defun gnus-summary-edit-global-kill (article)
11410   "Edit the \"global\" kill file."
11411   (interactive (list (gnus-summary-article-number)))
11412   (gnus-group-edit-global-kill article))
11413
11414 (defun gnus-summary-edit-local-kill ()
11415   "Edit a local kill file applied to the current newsgroup."
11416   (interactive)
11417   (setq gnus-current-headers (gnus-summary-article-header))
11418   (gnus-group-edit-local-kill
11419    (gnus-summary-article-number) gnus-newsgroup-name))
11420
11421 ;;; Header reading.
11422
11423 (defun gnus-read-header (id &optional header)
11424   "Read the headers of article ID and enter them into the Gnus system."
11425   (let ((group gnus-newsgroup-name)
11426         (gnus-override-method
11427          (or
11428           gnus-override-method
11429           (and (gnus-news-group-p gnus-newsgroup-name)
11430                (car (gnus-refer-article-methods)))))
11431         where)
11432     ;; First we check to see whether the header in question is already
11433     ;; fetched.
11434     (if (stringp id)
11435         ;; This is a Message-ID.
11436         (setq header (or header (gnus-id-to-header id)))
11437       ;; This is an article number.
11438       (setq header (or header (gnus-summary-article-header id))))
11439     (if (and header
11440              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11441         ;; We have found the header.
11442         header
11443       ;; We have to really fetch the header to this article.
11444       (save-excursion
11445         (set-buffer nntp-server-buffer)
11446         (when (setq where (gnus-request-head id group))
11447           (nnheader-fold-continuation-lines)
11448           (goto-char (point-max))
11449           (insert ".\n")
11450           (goto-char (point-min))
11451           (insert "211 ")
11452           (princ (cond
11453                   ((numberp id) id)
11454                   ((cdr where) (cdr where))
11455                   (header (mail-header-number header))
11456                   (t gnus-reffed-article-number))
11457                  (current-buffer))
11458           (insert " Article retrieved.\n"))
11459         (if (or (not where)
11460                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11461             ()                          ; Malformed head.
11462           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11463             (when (and (stringp id)
11464                        (not (string= (gnus-group-real-name group)
11465                                      (car where))))
11466               ;; If we fetched by Message-ID and the article came
11467               ;; from a different group, we fudge some bogus article
11468               ;; numbers for this article.
11469               (mail-header-set-number header gnus-reffed-article-number))
11470             (save-excursion
11471               (set-buffer gnus-summary-buffer)
11472               (decf gnus-reffed-article-number)
11473               (gnus-remove-header (mail-header-number header))
11474               (push header gnus-newsgroup-headers)
11475               (setq gnus-current-headers header)
11476               (push (mail-header-number header) gnus-newsgroup-limit)))
11477           header)))))
11478
11479 (defun gnus-remove-header (number)
11480   "Remove header NUMBER from `gnus-newsgroup-headers'."
11481   (if (and gnus-newsgroup-headers
11482            (= number (mail-header-number (car gnus-newsgroup-headers))))
11483       (pop gnus-newsgroup-headers)
11484     (let ((headers gnus-newsgroup-headers))
11485       (while (and (cdr headers)
11486                   (not (= number (mail-header-number (cadr headers)))))
11487         (pop headers))
11488       (when (cdr headers)
11489         (setcdr headers (cddr headers))))))
11490
11491 ;;;
11492 ;;; summary highlights
11493 ;;;
11494
11495 (defun gnus-highlight-selected-summary ()
11496   "Highlight selected article in summary buffer."
11497   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11498   (when gnus-summary-selected-face
11499     (save-excursion
11500       (let* ((beg (point-at-bol))
11501              (end (point-at-eol))
11502              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11503              (from (if (get-text-property beg gnus-mouse-face-prop)
11504                        beg
11505                      (or (next-single-property-change
11506                           beg gnus-mouse-face-prop nil end)
11507                          beg)))
11508              (to
11509               (if (= from end)
11510                   (- from 2)
11511                 (or (next-single-property-change
11512                      from gnus-mouse-face-prop nil end)
11513                     end))))
11514         ;; If no mouse-face prop on line we will have to = from = end,
11515         ;; so we highlight the entire line instead.
11516         (when (= (+ to 2) from)
11517           (setq from beg)
11518           (setq to end))
11519         (if gnus-newsgroup-selected-overlay
11520             ;; Move old overlay.
11521             (gnus-move-overlay
11522              gnus-newsgroup-selected-overlay from to (current-buffer))
11523           ;; Create new overlay.
11524           (gnus-overlay-put
11525            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11526            'face gnus-summary-selected-face))))))
11527
11528 (defvar gnus-summary-highlight-line-cached nil)
11529 (defvar gnus-summary-highlight-line-trigger nil)
11530
11531 (defun gnus-summary-highlight-line-0 ()
11532   (if (and (eq gnus-summary-highlight-line-trigger
11533                gnus-summary-highlight)
11534            gnus-summary-highlight-line-cached)
11535       gnus-summary-highlight-line-cached
11536     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11537           gnus-summary-highlight-line-cached
11538           (let* ((cond (list 'cond))
11539                  (c cond)
11540                  (list gnus-summary-highlight))
11541             (while list
11542               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11543                               nil))
11544               (setq c (cdr c)
11545                     list (cdr list)))
11546             (gnus-byte-compile (list 'lambda nil cond))))))
11547
11548 (defun gnus-summary-highlight-line ()
11549   "Highlight current line according to `gnus-summary-highlight'."
11550   (let* ((beg (point-at-bol))
11551          (article (or (gnus-summary-article-number) gnus-current-article))
11552          (score (or (cdr (assq article
11553                                gnus-newsgroup-scored))
11554                     gnus-summary-default-score 0))
11555          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11556          (inhibit-read-only t)
11557          (default gnus-summary-default-score)
11558          (default-high gnus-summary-default-high-score)
11559          (default-low gnus-summary-default-low-score)
11560          (uncached (and gnus-summary-use-undownloaded-faces
11561                         (memq article gnus-newsgroup-undownloaded)
11562                         (not (memq article gnus-newsgroup-cached)))))
11563     (let ((face (funcall (gnus-summary-highlight-line-0))))
11564       (unless (eq face (get-text-property beg 'face))
11565         (gnus-put-text-property-excluding-characters-with-faces
11566          beg (point-at-eol) 'face
11567          (setq face (if (boundp face) (symbol-value face) face)))
11568         (when gnus-summary-highlight-line-function
11569           (funcall gnus-summary-highlight-line-function article face))))))
11570
11571 (defun gnus-update-read-articles (group unread &optional compute)
11572   "Update the list of read articles in GROUP.
11573 UNREAD is a sorted list."
11574   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11575         (info (gnus-get-info group))
11576         (prev 1)
11577         read)
11578     (if (or (not info) (not active))
11579         ;; There is no info on this group if it was, in fact,
11580         ;; killed.  Gnus stores no information on killed groups, so
11581         ;; there's nothing to be done.
11582         ;; One could store the information somewhere temporarily,
11583         ;; perhaps...  Hmmm...
11584         ()
11585       ;; Remove any negative articles numbers.
11586       (while (and unread (< (car unread) 0))
11587         (setq unread (cdr unread)))
11588       ;; Remove any expired article numbers
11589       (while (and unread (< (car unread) (car active)))
11590         (setq unread (cdr unread)))
11591       ;; Compute the ranges of read articles by looking at the list of
11592       ;; unread articles.
11593       (while unread
11594         (when (/= (car unread) prev)
11595           (push (if (= prev (1- (car unread))) prev
11596                   (cons prev (1- (car unread))))
11597                 read))
11598         (setq prev (1+ (car unread)))
11599         (setq unread (cdr unread)))
11600       (when (<= prev (cdr active))
11601         (push (cons prev (cdr active)) read))
11602       (setq read (if (> (length read) 1) (nreverse read) read))
11603       (if compute
11604           read
11605         (save-excursion
11606           (let (setmarkundo)
11607             ;; Propagate the read marks to the backend.
11608             (when (gnus-check-backend-function 'request-set-mark group)
11609               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11610                     (add (gnus-remove-from-range read (gnus-info-read info))))
11611                 (when (or add del)
11612                   (unless (gnus-check-group group)
11613                     (error "Can't open server for %s" group))
11614                   (gnus-request-set-mark
11615                    group (delq nil (list (if add (list add 'add '(read)))
11616                                          (if del (list del 'del '(read))))))
11617                   (setq setmarkundo
11618                         `(gnus-request-set-mark
11619                           ,group
11620                           ',(delq nil (list
11621                                        (if del (list del 'add '(read)))
11622                                        (if add (list add 'del '(read))))))))))
11623             (set-buffer gnus-group-buffer)
11624             (gnus-undo-register
11625               `(progn
11626                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11627                  (gnus-info-set-read ',info ',(gnus-info-read info))
11628                  (gnus-get-unread-articles-in-group ',info
11629                                                     (gnus-active ,group))
11630                  (gnus-group-update-group ,group t)
11631                  ,setmarkundo))))
11632         ;; Enter this list into the group info.
11633         (gnus-info-set-read info read)
11634         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11635         (gnus-get-unread-articles-in-group info (gnus-active group))
11636         t))))
11637
11638 (defun gnus-offer-save-summaries ()
11639   "Offer to save all active summary buffers."
11640   (let (buffers)
11641     ;; Go through all buffers and find all summaries.
11642     (dolist (buffer (buffer-list))
11643       (when (and (setq buffer (buffer-name buffer))
11644                  (string-match "Summary" buffer)
11645                  (with-current-buffer buffer
11646                    ;; We check that this is, indeed, a summary buffer.
11647                    (and (eq major-mode 'gnus-summary-mode)
11648                         ;; Also make sure this isn't bogus.
11649                         gnus-newsgroup-prepared
11650                         ;; Also make sure that this isn't a
11651                         ;; dead summary buffer.
11652                         (not gnus-dead-summary-mode))))
11653         (push buffer buffers)))
11654     ;; Go through all these summary buffers and offer to save them.
11655     (when buffers
11656       (save-excursion
11657         (map-y-or-n-p
11658          "Update summary buffer %s? "
11659          (lambda (buf)
11660            (switch-to-buffer buf)
11661            (gnus-summary-exit))
11662          buffers)))))
11663
11664
11665 ;;; @ for mime-partial
11666 ;;;
11667
11668 (defun gnus-request-partial-message ()
11669   (save-excursion
11670     (let ((number (gnus-summary-article-number))
11671           (group gnus-newsgroup-name)
11672           (mother gnus-article-buffer))
11673       (set-buffer (get-buffer-create " *Partial Article*"))
11674       (erase-buffer)
11675       (setq mime-preview-buffer mother)
11676       (gnus-request-article-this-buffer number group)
11677       (mime-parse-buffer)
11678       )))
11679
11680 (autoload 'mime-combine-message/partial-pieces-automatically
11681   "mime-partial"
11682   "Internal method to combine message/partial messages automatically.")
11683
11684 (mime-add-condition
11685  'action '((type . message)(subtype . partial)
11686            (major-mode . gnus-original-article-mode)
11687            (method . mime-combine-message/partial-pieces-automatically)
11688            (summary-buffer-exp . gnus-summary-buffer)
11689            (request-partial-message-method . gnus-request-partial-message)
11690            ))
11691
11692
11693 ;;; @ for message/rfc822
11694 ;;;
11695
11696 (defun gnus-mime-extract-message/rfc822 (entity situation)
11697   "Burst a forwarded article."
11698   (save-excursion
11699     (set-buffer gnus-summary-buffer)
11700     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11701                                    gnus-newsgroup-name 'gnus-group-history))
11702            (gnus-group-marked (list group))
11703            article info)
11704       (with-temp-buffer
11705         (mime-insert-entity-content entity)
11706         (setq article (gnus-request-accept-article group)))
11707       (when (and (consp article)
11708                  (numberp (setq article (cdr article))))
11709         (setq info (gnus-get-info group))
11710         (gnus-info-set-read info
11711                             (gnus-remove-from-range (gnus-info-read info)
11712                                                     (list article)))
11713         (when (string-equal group gnus-newsgroup-name)
11714           (forward-line 1)
11715           (let (gnus-show-threads)
11716             (gnus-summary-goto-subject article t))
11717           (gnus-summary-clear-mark-forward 1))
11718         (set-buffer gnus-group-buffer)
11719         (gnus-group-get-new-news-this-group nil t)))))
11720
11721 (mime-add-condition
11722  'action '((type . message)(subtype . rfc822)
11723            (major-mode . gnus-original-article-mode)
11724            (method . gnus-mime-extract-message/rfc822)
11725            (mode . "extract")
11726            ))
11727
11728 (mime-add-condition
11729  'action '((type . message)(subtype . news)
11730            (major-mode . gnus-original-article-mode)
11731            (method . gnus-mime-extract-message/rfc822)
11732            (mode . "extract")
11733            ))
11734
11735 (defun gnus-mime-extract-multipart (entity situation)
11736   (let ((children (mime-entity-children entity))
11737         mime-acting-situation-to-override
11738         f)
11739     (while children
11740       (mime-play-entity (car children)
11741                         (cons (assq 'mode situation)
11742                               mime-acting-situation-to-override))
11743       (setq children (cdr children)))
11744     (if (setq f (cdr (assq 'after-method
11745                            mime-acting-situation-to-override)))
11746         (eval f)
11747       )))
11748
11749 (mime-add-condition
11750  'action '((type . multipart)
11751            (method . gnus-mime-extract-multipart)
11752            (mode . "extract")
11753            )
11754  'with-default)
11755
11756
11757 ;;; @ end
11758 ;;;
11759
11760 (defun gnus-summary-inherit-default-charset ()
11761   "Import `default-mime-charset' from summary buffer.
11762 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11763 of FLIM is used."
11764   (if (buffer-live-p gnus-summary-buffer)
11765       (let (d-m-c d-m-c-u)
11766         (with-current-buffer gnus-summary-buffer
11767           (setq d-m-c (if (local-variable-p 'default-mime-charset
11768                                             gnus-summary-buffer)
11769                           default-mime-charset
11770                         t)
11771                 ;; LIMIT
11772                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11773                                               gnus-summary-buffer)
11774                             (symbol-value 'default-mime-charset-unlimited)
11775                           t)))
11776         (if (eq t d-m-c)
11777             (kill-local-variable 'default-mime-charset)
11778           (set (make-local-variable 'default-mime-charset) d-m-c))
11779         (if (eq t d-m-c-u)
11780             (kill-local-variable 'default-mime-charset-unlimited)
11781           (set (make-local-variable 'default-mime-charset-unlimited)
11782                d-m-c-u)))))
11783
11784 (defun gnus-summary-setup-default-charset ()
11785   "Setup newsgroup default charset."
11786   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11787       (progn
11788         (setq gnus-newsgroup-charset nil)
11789         (set (make-local-variable 'default-mime-charset) nil)
11790         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11791           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11792     (let ((ignored-charsets
11793            (or gnus-newsgroup-ephemeral-ignored-charsets
11794                (append
11795                 (and gnus-newsgroup-name
11796                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11797                 gnus-newsgroup-ignored-charsets)))
11798           charset)
11799       (setq gnus-newsgroup-charset
11800             (or gnus-newsgroup-ephemeral-charset
11801                 (when (and gnus-newsgroup-name
11802                            (setq charset (gnus-parameter-charset
11803                                           gnus-newsgroup-name)))
11804                   (make-local-variable 'default-mime-charset)
11805                   (setq default-mime-charset charset))
11806                 gnus-default-charset))
11807       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11808            ignored-charsets))))
11809
11810 ;;;
11811 ;;; Mime Commands
11812 ;;;
11813
11814 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11815   "Display the current article buffer fully MIME-buttonized.
11816 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11817 treated as multipart/mixed."
11818   (interactive "P")
11819   (require 'gnus-art)
11820   (let ((gnus-unbuttonized-mime-types nil)
11821         (gnus-mime-display-multipart-as-mixed show-all-parts))
11822     (gnus-summary-show-article)))
11823
11824 (defun gnus-summary-repair-multipart (article)
11825   "Add a Content-Type header to a multipart article without one."
11826   (interactive (list (gnus-summary-article-number)))
11827   (gnus-with-article article
11828     (message-narrow-to-head)
11829     (message-remove-header "Mime-Version")
11830     (goto-char (point-max))
11831     (insert "Mime-Version: 1.0\n")
11832     (widen)
11833     (when (search-forward "\n--" nil t)
11834       (let ((separator (buffer-substring (point) (point-at-eol))))
11835         (message-narrow-to-head)
11836         (message-remove-header "Content-Type")
11837         (goto-char (point-max))
11838         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11839                         separator))
11840         (widen))))
11841   (let (gnus-mark-article-hook)
11842     (gnus-summary-select-article t t nil article)))
11843
11844 (defun gnus-summary-toggle-display-buttonized ()
11845   "Toggle the buttonizing of the article buffer."
11846   (interactive)
11847   (require 'gnus-art)
11848   (if (setq gnus-inhibit-mime-unbuttonizing
11849             (not gnus-inhibit-mime-unbuttonizing))
11850       (let ((gnus-unbuttonized-mime-types nil))
11851         (gnus-summary-show-article))
11852     (gnus-summary-show-article)))
11853
11854 ;;;
11855 ;;; Intelli-mouse commmands
11856 ;;;
11857
11858 (defun gnus-wheel-summary-scroll (event)
11859   (interactive "e")
11860   (let ((amount (if (memq 'shift (event-modifiers event))
11861                     (car gnus-wheel-scroll-amount)
11862                   (cdr gnus-wheel-scroll-amount)))
11863         (direction (- (* (static-if (featurep 'xemacs)
11864                              (event-button event)
11865                            (cond ((eq 'mouse-4 (event-basic-type event))
11866                                   4)
11867                                  ((eq 'mouse-5 (event-basic-type event))
11868                                   5)))
11869                          2) 9))
11870         edge)
11871     (gnus-summary-scroll-up (* amount direction))
11872     (when (gnus-eval-in-buffer-window gnus-article-buffer
11873             (save-restriction
11874               (widen)
11875               (and (if (< 0 direction)
11876                        (gnus-article-next-page 0)
11877                      (gnus-article-prev-page 0)
11878                      (bobp))
11879                    (if (setq edge (get-text-property
11880                                    (point-min) 'gnus-wheel-edge))
11881                        (setq edge (* edge direction))
11882                      (setq edge -1))
11883                    (or (plusp edge)
11884                        (let ((buffer-read-only nil)
11885                              (inhibit-read-only t))
11886                          (put-text-property (point-min) (point-max)
11887                                             'gnus-wheel-edge direction)
11888                          nil))
11889                    (or (> edge gnus-wheel-edge-resistance)
11890                        (let ((buffer-read-only nil)
11891                              (inhibit-read-only t))
11892                          (put-text-property (point-min) (point-max)
11893                                             'gnus-wheel-edge
11894                                             (* (1+ edge) direction))
11895                          nil))
11896                    (eq last-command 'gnus-wheel-summary-scroll))))
11897       (gnus-summary-next-article nil nil (minusp direction)))))
11898
11899 (defun gnus-wheel-install ()
11900   "Enable mouse wheel support on summary window."
11901   (when gnus-use-wheel
11902     (let ((keys
11903            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11904       (dolist (key keys)
11905         (define-key gnus-summary-mode-map key
11906           'gnus-wheel-summary-scroll)))))
11907
11908 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11909
11910 ;;;
11911 ;;; Traditional PGP commmands
11912 ;;;
11913
11914 (defun gnus-summary-decrypt-article (&optional force)
11915   "Decrypt the current article in traditional PGP way.
11916 This will have permanent effect only in mail groups.
11917 If FORCE is non-nil, allow editing of articles even in read-only
11918 groups."
11919   (interactive "P")
11920   (gnus-summary-select-article t)
11921   (gnus-eval-in-buffer-window gnus-article-buffer
11922     (save-excursion
11923       (save-restriction
11924         (widen)
11925         (goto-char (point-min))
11926         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11927           (error "Not a traditional PGP message!"))
11928         (let ((armor-start (match-beginning 0)))
11929           (if (and (pgg-decrypt-region armor-start (point-max))
11930                    (or force (not (gnus-group-read-only-p))))
11931               (let ((inhibit-read-only t)
11932                     buffer-read-only)
11933                 (delete-region armor-start
11934                                (progn
11935                                  (re-search-forward "^-+END PGP" nil t)
11936                                  (beginning-of-line 2)
11937                                  (point)))
11938                 (insert-buffer-substring pgg-output-buffer))))))))
11939
11940 (defun gnus-summary-verify-article ()
11941   "Verify the current article in traditional PGP way."
11942   (interactive)
11943   (save-excursion
11944     (set-buffer gnus-original-article-buffer)
11945     (goto-char (point-min))
11946     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11947       (error "Not a traditional PGP message!"))
11948     (re-search-forward "^-+END PGP" nil t)
11949     (beginning-of-line 2)
11950     (call-interactively (function pgg-verify-region))))
11951
11952 ;;;
11953 ;;; Generic summary marking commands
11954 ;;;
11955
11956 (defvar gnus-summary-marking-alist
11957   '((read gnus-del-mark "d")
11958     (unread gnus-unread-mark "u")
11959     (ticked gnus-ticked-mark "!")
11960     (dormant gnus-dormant-mark "?")
11961     (expirable gnus-expirable-mark "e"))
11962   "An alist of names/marks/keystrokes.")
11963
11964 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11965 (defvar gnus-summary-mark-map)
11966
11967 (defun gnus-summary-make-all-marking-commands ()
11968   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11969   (dolist (elem gnus-summary-marking-alist)
11970     (apply 'gnus-summary-make-marking-command elem)))
11971
11972 (defun gnus-summary-make-marking-command (name mark keystroke)
11973   (let ((map (make-sparse-keymap)))
11974     (define-key gnus-summary-generic-mark-map keystroke map)
11975     (dolist (lway `((next "next" next nil "n")
11976                     (next-unread "next unread" next t "N")
11977                     (prev "previous" prev nil "p")
11978                     (prev-unread "previous unread" prev t "P")
11979                     (nomove "" nil nil ,keystroke)))
11980       (let ((func (gnus-summary-make-marking-command-1
11981                    mark (car lway) lway name)))
11982         (setq func (eval func))
11983         (define-key map (nth 4 lway) func)))))
11984
11985 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11986   `(defun ,(intern
11987             (format "gnus-summary-put-mark-as-%s%s"
11988                     name (if (eq way 'nomove)
11989                              ""
11990                            (concat "-" (symbol-name way)))))
11991      (n)
11992      ,(format
11993        "Mark the current article as %s%s.
11994 If N, the prefix, then repeat N times.
11995 If N is negative, move in reverse order.
11996 The difference between N and the actual number of articles marked is
11997 returned."
11998        name (car (cdr lway)))
11999      (interactive "p")
12000      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12001
12002 (defun gnus-summary-generic-mark (n mark move unread)
12003   "Mark N articles with MARK."
12004   (unless (eq major-mode 'gnus-summary-mode)
12005     (error "This command can only be used in the summary buffer"))
12006   (gnus-summary-show-thread)
12007   (let ((nummove
12008          (cond
12009           ((eq move 'next) 1)
12010           ((eq move 'prev) -1)
12011           (t 0))))
12012     (if (zerop nummove)
12013         (setq n 1)
12014       (when (< n 0)
12015         (setq n (abs n)
12016               nummove (* -1 nummove))))
12017     (while (and (> n 0)
12018                 (gnus-summary-mark-article nil mark)
12019                 (zerop (gnus-summary-next-subject nummove unread t)))
12020       (setq n (1- n)))
12021     (when (/= 0 n)
12022       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12023     (gnus-summary-recenter)
12024     (gnus-summary-position-point)
12025     (gnus-set-mode-line 'summary)
12026     n))
12027
12028 (defun gnus-summary-insert-articles (articles)
12029   (when (setq articles
12030               (gnus-sorted-difference articles
12031                                       (mapcar (lambda (h)
12032                                                 (mail-header-number h))
12033                                               gnus-newsgroup-headers)))
12034     (setq gnus-newsgroup-headers
12035           (gnus-merge 'list
12036                       gnus-newsgroup-headers
12037                       (gnus-fetch-headers articles)
12038                       'gnus-article-sort-by-number))
12039     ;; Suppress duplicates?
12040     (when gnus-suppress-duplicates
12041       (gnus-dup-suppress-articles))
12042
12043     ;; We might want to build some more threads first.
12044     (when (and gnus-fetch-old-headers
12045                (eq gnus-headers-retrieved-by 'nov))
12046       (if (eq gnus-fetch-old-headers 'invisible)
12047           (gnus-build-all-threads)
12048         (gnus-build-old-threads)))
12049     ;; Let the Gnus agent mark articles as read.
12050     (when gnus-agent
12051       (gnus-agent-get-undownloaded-list))
12052     ;; Remove list identifiers from subject
12053     (when gnus-list-identifiers
12054       (gnus-summary-remove-list-identifiers))
12055     ;; First and last article in this newsgroup.
12056     (when gnus-newsgroup-headers
12057       (setq gnus-newsgroup-begin
12058             (mail-header-number (car gnus-newsgroup-headers))
12059             gnus-newsgroup-end
12060             (mail-header-number
12061              (gnus-last-element gnus-newsgroup-headers))))
12062     (when gnus-use-scoring
12063       (gnus-possibly-score-headers))))
12064
12065 (defun gnus-summary-insert-old-articles (&optional all)
12066   "Insert all old articles in this group.
12067 If ALL is non-nil, already read articles become readable.
12068 If ALL is a number, fetch this number of articles."
12069   (interactive "P")
12070   (prog1
12071       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12072             older len)
12073         (setq older
12074               ;; Some nntp servers lie about their active range.  When
12075               ;; this happens, the active range can be in the millions.
12076               ;; Use a compressed range to avoid creating a huge list.
12077               (gnus-range-difference (list gnus-newsgroup-active) old))
12078         (setq len (gnus-range-length older))
12079         (cond
12080          ((null older) nil)
12081          ((numberp all)
12082           (if (< all len)
12083               (let ((older-range (nreverse older)))
12084                 (setq older nil)
12085
12086                 (while (> all 0)
12087                   (let* ((r (pop older-range))
12088                          (min (if (numberp r) r (car r)))
12089                          (max (if (numberp r) r (cdr r))))
12090                     (while (and (<= min max)
12091                                 (> all 0))
12092                       (push max older)
12093                       (setq all (1- all)
12094                             max (1- max))))))
12095             (setq older (gnus-uncompress-range older))))
12096          (all
12097           (setq older (gnus-uncompress-range older)))
12098          (t
12099           (when (and (numberp gnus-large-newsgroup)
12100                    (> len gnus-large-newsgroup))
12101               (let* ((cursor-in-echo-area nil)
12102                      (initial (gnus-parameter-large-newsgroup-initial
12103                                gnus-newsgroup-name))
12104                      (input
12105                       (read-string
12106                        (format
12107                         "How many articles from %s (%s %d): "
12108                         (gnus-limit-string
12109                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12110                         (if initial "max" "default")
12111                         len)
12112                        (if initial
12113                            (cons (number-to-string initial)
12114                                  0)))))
12115                 (unless (string-match "^[ \t]*$" input)
12116                   (setq all (string-to-number input))
12117                   (if (< all len)
12118                       (let ((older-range (nreverse older)))
12119                         (setq older nil)
12120
12121                         (while (> all 0)
12122                           (let* ((r (pop older-range))
12123                                  (min (if (numberp r) r (car r)))
12124                                  (max (if (numberp r) r (cdr r))))
12125                             (while (and (<= min max)
12126                                         (> all 0))
12127                               (push max older)
12128                               (setq all (1- all)
12129                                     max (1- max))))))))))
12130           (setq older (gnus-uncompress-range older))))
12131         (if (not older)
12132             (message "No old news.")
12133           (gnus-summary-insert-articles older)
12134           (gnus-summary-limit (gnus-sorted-nunion old older))))
12135     (gnus-summary-position-point)))
12136
12137 (defun gnus-summary-insert-new-articles ()
12138   "Insert all new articles in this group."
12139   (interactive)
12140   (prog1
12141       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12142             (old-active gnus-newsgroup-active)
12143             (nnmail-fetched-sources (list t))
12144             i new)
12145         (setq gnus-newsgroup-active
12146               (gnus-activate-group gnus-newsgroup-name 'scan))
12147         (setq i (cdr gnus-newsgroup-active))
12148         (while (> i (cdr old-active))
12149           (push i new)
12150           (decf i))
12151         (if (not new)
12152             (message "No gnus is bad news")
12153           (gnus-summary-insert-articles new)
12154           (setq gnus-newsgroup-unreads
12155                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12156           (gnus-summary-limit (gnus-sorted-nunion old new))))
12157     (gnus-summary-position-point)))
12158
12159 (gnus-summary-make-all-marking-commands)
12160
12161 (gnus-ems-redefine)
12162
12163 (provide 'gnus-sum)
12164
12165 (run-hooks 'gnus-sum-load-hook)
12166
12167 ;; Local Variables:
12168 ;; coding: iso-8859-1
12169 ;; End:
12170
12171 ;;; gnus-sum.el ends here