f6669fe5b639edc1e9cb38125875852cf341f25b
[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" :size 0)))
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 (defcustom gnus-unread-mark ?\ ;;;Whitespace
464   "*Mark used for unread articles."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-ticked-mark ?!
469   "*Mark used for ticked articles."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-dormant-mark ??
474   "*Mark used for dormant articles."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-del-mark ?r
479   "*Mark used for del'd articles."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-read-mark ?R
484   "*Mark used for read articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-expirable-mark ?E
489   "*Mark used for expirable articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-killed-mark ?K
494   "*Mark used for killed articles."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-spam-mark ?$
499   "*Mark used for spam articles."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-souped-mark ?F
504   "*Mark used for souped articles."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-kill-file-mark ?X
509   "*Mark used for articles killed by kill files."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-low-score-mark ?Y
514   "*Mark used for articles with a low score."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-catchup-mark ?C
519   "*Mark used for articles that are caught up."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-replied-mark ?A
524   "*Mark used for articles that have been replied to."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-forwarded-mark ?F
529   "*Mark used for articles that have been forwarded."
530   :version "21.4"
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-recent-mark ?N
535   "*Mark used for articles that are recent."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-cached-mark ?*
540   "*Mark used for articles that are in the cache."
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-saved-mark ?S
545   "*Mark used for articles that have been saved."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-unseen-mark ?.
550   "*Mark used for articles that haven't been seen."
551   :version "21.4"
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-no-mark ?\ ;;;Whitespace
556   "*Mark used for articles that have no other secondary mark."
557   :version "21.4"
558   :group 'gnus-summary-marks
559   :type 'character)
560
561 (defcustom gnus-ancient-mark ?O
562   "*Mark used for ancient articles."
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-sparse-mark ?Q
567   "*Mark used for sparsely reffed articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-canceled-mark ?G
572   "*Mark used for canceled articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-duplicate-mark ?M
577   "*Mark used for duplicate articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-undownloaded-mark ?-
582   "*Mark used for articles that weren't downloaded."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-downloaded-mark ?+
587   "*Mark used for articles that were downloaded."
588   :group 'gnus-summary-marks
589   :type 'character)
590
591 (defcustom gnus-downloadable-mark ?%
592   "*Mark used for articles that are to be downloaded."
593   :group 'gnus-summary-marks
594   :type 'character)
595
596 (defcustom gnus-unsendable-mark ?=
597   "*Mark used for articles that won't be sent."
598   :group 'gnus-summary-marks
599   :type 'character)
600
601 (defcustom gnus-score-over-mark ?+
602   "*Score mark used for articles with high scores."
603   :group 'gnus-summary-marks
604   :type 'character)
605
606 (defcustom gnus-score-below-mark ?-
607   "*Score mark used for articles with low scores."
608   :group 'gnus-summary-marks
609   :type 'character)
610
611 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
612   "*There is no thread under the article."
613   :group 'gnus-summary-marks
614   :type 'character)
615
616 (defcustom gnus-not-empty-thread-mark ?=
617   "*There is a thread under the article."
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-view-pseudo-asynchronously nil
622   "*If non-nil, Gnus will view pseudo-articles asynchronously."
623   :group 'gnus-extract-view
624   :type 'boolean)
625
626 (defcustom gnus-auto-expirable-marks
627   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
628         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
629         gnus-souped-mark gnus-duplicate-mark)
630   "*The list of marks converted into expiration if a group is auto-expirable."
631   :version "21.1"
632   :group 'gnus-summary
633   :type '(repeat character))
634
635 (defcustom gnus-inhibit-user-auto-expire t
636   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
637   :version "21.1"
638   :group 'gnus-summary
639   :type 'boolean)
640
641 (defcustom gnus-view-pseudos nil
642   "*If `automatic', pseudo-articles will be viewed automatically.
643 If `not-confirm', pseudos will be viewed automatically, and the user
644 will not be asked to confirm the command."
645   :group 'gnus-extract-view
646   :type '(choice (const :tag "off" nil)
647                  (const automatic)
648                  (const not-confirm)))
649
650 (defcustom gnus-view-pseudos-separately t
651   "*If non-nil, one pseudo-article will be created for each file to be viewed.
652 If nil, all files that use the same viewing command will be given as a
653 list of parameters to that command."
654   :group 'gnus-extract-view
655   :type 'boolean)
656
657 (defcustom gnus-insert-pseudo-articles t
658   "*If non-nil, insert pseudo-articles when decoding articles."
659   :group 'gnus-extract-view
660   :type 'boolean)
661
662 (defcustom gnus-summary-dummy-line-format
663   "   %(:                             :%) %S\n"
664   "*The format specification for the dummy roots in the summary buffer.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions.
667
668 %S  The subject
669
670 General format specifiers can also be used.
671 See `(gnus)Formatting Variables'."
672   :link '(custom-manual "(gnus)Formatting Variables")
673   :group 'gnus-threading
674   :type 'string)
675
676 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
677   "*The format specification for the summary mode line.
678 It works along the same lines as a normal formatting string,
679 with some simple extensions:
680
681 %G  Group name
682 %p  Unprefixed group name
683 %A  Current article number
684 %z  Current article score
685 %V  Gnus version
686 %U  Number of unread articles in the group
687 %e  Number of unselected articles in the group
688 %Z  A string with unread/unselected article counts
689 %g  Shortish group name
690 %S  Subject of the current article
691 %u  User-defined spec
692 %s  Current score file name
693 %d  Number of dormant articles
694 %r  Number of articles that have been marked as read in this session
695 %E  Number of articles expunged by the score files"
696   :group 'gnus-summary-format
697   :type 'string)
698
699 (defcustom gnus-list-identifiers nil
700   "Regexp that matches list identifiers to be removed from subject.
701 This can also be a list of regexps."
702   :version "21.1"
703   :group 'gnus-summary-format
704   :group 'gnus-article-hiding
705   :type '(choice (const :tag "none" nil)
706                  (regexp :value ".*")
707                  (repeat :value (".*") regexp)))
708
709 (defcustom gnus-summary-mark-below 0
710   "*Mark all articles with a score below this variable as read.
711 This variable is local to each summary buffer and usually set by the
712 score file."
713   :group 'gnus-score-default
714   :type 'integer)
715
716 (defun gnus-widget-reversible-match (widget value)
717   "Ignoring WIDGET, convert VALUE to internal form.
718 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
719   ;; (debug value)
720   (or (symbolp value)
721       (and (listp value)
722            (eq (length value) 2)
723            (eq (nth 0 value) 'not)
724            (symbolp (nth 1 value)))))
725
726 (defun gnus-widget-reversible-to-internal (widget value)
727   "Ignoring WIDGET, convert VALUE to internal form.
728 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
729 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
730   ;; (debug value)
731   (if (atom value)
732       (list value nil)
733     (list (nth 1 value) t)))
734
735 (defun gnus-widget-reversible-to-external (widget value)
736   "Ignoring WIDGET, convert VALUE to external form.
737 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
738 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
739   ;; (debug value)
740   (if (nth 1 value)
741       (list 'not (nth 0 value))
742     (nth 0 value)))
743
744 (define-widget 'gnus-widget-reversible 'group
745   "A `group' that convert values."
746   :match 'gnus-widget-reversible-match
747   :value-to-internal 'gnus-widget-reversible-to-internal
748   :value-to-external 'gnus-widget-reversible-to-external)
749
750 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
751   "*List of functions used for sorting articles in the summary buffer.
752
753 Each function takes two articles and returns non-nil if the first
754 article should be sorted before the other.  If you use more than one
755 function, the primary sort function should be the last.  You should
756 probably always include `gnus-article-sort-by-number' in the list of
757 sorting functions -- preferably first.  Also note that sorting by date
758 is often much slower than sorting by number, and the sorting order is
759 very similar.  (Sorting by date means sorting by the time the message
760 was sent, sorting by number means sorting by arrival time.)
761
762 Each item can also be a list `(not F)' where F is a function;
763 this reverses the sort order.
764
765 Ready-made functions include `gnus-article-sort-by-number',
766 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
767 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
768 and `gnus-article-sort-by-score'.
769
770 When threading is turned on, the variable `gnus-thread-sort-functions'
771 controls how articles are sorted."
772   :group 'gnus-summary-sort
773   :type '(repeat (gnus-widget-reversible
774                   (choice (function-item gnus-article-sort-by-number)
775                           (function-item gnus-article-sort-by-author)
776                           (function-item gnus-article-sort-by-subject)
777                           (function-item gnus-article-sort-by-date)
778                           (function-item gnus-article-sort-by-score)
779                           (function-item gnus-article-sort-by-random)
780                           (function :tag "other"))
781                   (boolean :tag "Reverse order"))))
782
783
784 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
785   "*List of functions used for sorting threads in the summary buffer.
786 By default, threads are sorted by article number.
787
788 Each function takes two threads and returns non-nil if the first
789 thread should be sorted before the other.  If you use more than one
790 function, the primary sort function should be the last.  You should
791 probably always include `gnus-thread-sort-by-number' in the list of
792 sorting functions -- preferably first.  Also note that sorting by date
793 is often much slower than sorting by number, and the sorting order is
794 very similar.  (Sorting by date means sorting by the time the message
795 was sent, sorting by number means sorting by arrival time.)
796
797 Each list item can also be a list `(not F)' where F is a
798 function; this specifies reversed sort order.
799
800 Ready-made functions include `gnus-thread-sort-by-number',
801 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
802 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
803 `gnus-thread-sort-by-most-recent-number',
804 `gnus-thread-sort-by-most-recent-date',
805 `gnus-thread-sort-by-random', and
806 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
807
808 When threading is turned off, the variable
809 `gnus-article-sort-functions' controls how articles are sorted."
810   :group 'gnus-summary-sort
811   :type '(repeat 
812           (gnus-widget-reversible
813            (choice (function-item gnus-thread-sort-by-number)
814                    (function-item gnus-thread-sort-by-author)
815                    (function-item gnus-thread-sort-by-subject)
816                    (function-item gnus-thread-sort-by-date)
817                    (function-item gnus-thread-sort-by-score)
818                    (function-item gnus-thread-sort-by-most-recent-number)
819                    (function-item gnus-thread-sort-by-most-recent-date)
820                    (function-item gnus-thread-sort-by-random)
821                    (function-item gnus-thread-sort-by-total-score)
822                    (function :tag "other"))
823            (boolean :tag "Reverse order"))))
824
825 (defcustom gnus-thread-score-function '+
826   "*Function used for calculating the total score of a thread.
827
828 The function is called with the scores of the article and each
829 subthread and should then return the score of the thread.
830
831 Some functions you can use are `+', `max', or `min'."
832   :group 'gnus-summary-sort
833   :type 'function)
834
835 (defcustom gnus-summary-expunge-below nil
836   "All articles that have a score less than this variable will be expunged.
837 This variable is local to the summary buffers."
838   :group 'gnus-score-default
839   :type '(choice (const :tag "off" nil)
840                  integer))
841
842 (defcustom gnus-thread-expunge-below nil
843   "All threads that have a total score less than this variable will be expunged.
844 See `gnus-thread-score-function' for en explanation of what a
845 \"thread score\" is.
846
847 This variable is local to the summary buffers."
848   :group 'gnus-threading
849   :group 'gnus-score-default
850   :type '(choice (const :tag "off" nil)
851                  integer))
852
853 (defcustom gnus-summary-mode-hook nil
854   "*A hook for Gnus summary mode.
855 This hook is run before any variables are set in the summary buffer."
856   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
857   :group 'gnus-summary-various
858   :type 'hook)
859
860 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
861 (when (featurep 'xemacs)
862   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
863   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
864   (add-hook 'gnus-summary-mode-hook
865             'gnus-xmas-switch-horizontal-scrollbar-off))
866
867 (defcustom gnus-summary-menu-hook nil
868   "*Hook run after the creation of the summary mode menu."
869   :group 'gnus-summary-visual
870   :type 'hook)
871
872 (defcustom gnus-summary-exit-hook nil
873   "*A hook called on exit from the summary buffer.
874 It will be called with point in the group buffer."
875   :group 'gnus-summary-exit
876   :type 'hook)
877
878 (defcustom gnus-summary-prepare-hook nil
879   "*A hook called after the summary buffer has been generated.
880 If you want to modify the summary buffer, you can use this hook."
881   :group 'gnus-summary-various
882   :type 'hook)
883
884 (defcustom gnus-summary-prepared-hook nil
885   "*A hook called as the last thing after the summary buffer has been generated."
886   :group 'gnus-summary-various
887   :type 'hook)
888
889 (defcustom gnus-summary-generate-hook nil
890   "*A hook run just before generating the summary buffer.
891 This hook is commonly used to customize threading variables and the
892 like."
893   :group 'gnus-summary-various
894   :type 'hook)
895
896 (defcustom gnus-select-group-hook nil
897   "*A hook called when a newsgroup is selected.
898
899 If you'd like to simplify subjects like the
900 `gnus-summary-next-same-subject' command does, you can use the
901 following hook:
902
903  (add-hook gnus-select-group-hook
904            (lambda ()
905              (mapcar (lambda (header)
906                        (mail-header-set-subject
907                         header
908                         (gnus-simplify-subject
909                          (mail-header-subject header) 're-only)))
910                      gnus-newsgroup-headers)))"
911   :group 'gnus-group-select
912   :type 'hook)
913
914 (defcustom gnus-select-article-hook nil
915   "*A hook called when an article is selected."
916   :group 'gnus-summary-choose
917   :options '(gnus-agent-fetch-selected-article)
918   :type 'hook)
919
920 (defcustom gnus-visual-mark-article-hook
921   (list 'gnus-highlight-selected-summary)
922   "*Hook run after selecting an article in the summary buffer.
923 It is meant to be used for highlighting the article in some way.  It
924 is not run if `gnus-visual' is nil."
925   :group 'gnus-summary-visual
926   :type 'hook)
927
928 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
929   "*A hook called before parsing the headers."
930   :group 'gnus-various
931   :type 'hook)
932
933 (defcustom gnus-exit-group-hook nil
934   "*A hook called when exiting summary mode.
935 This hook is not called from the non-updating exit commands like `Q'."
936   :group 'gnus-various
937   :type 'hook)
938
939 (defcustom gnus-summary-update-hook
940   (list 'gnus-summary-highlight-line)
941   "*A hook called when a summary line is changed.
942 The hook will not be called if `gnus-visual' is nil.
943
944 The default function `gnus-summary-highlight-line' will
945 highlight the line according to the `gnus-summary-highlight'
946 variable."
947   :group 'gnus-summary-visual
948   :type 'hook)
949
950 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
951   "*A hook called when an article is selected for the first time.
952 The hook is intended to mark an article as read (or unread)
953 automatically when it is selected."
954   :group 'gnus-summary-choose
955   :type 'hook)
956
957 (defcustom gnus-group-no-more-groups-hook nil
958   "*A hook run when returning to group mode having no more (unread) groups."
959   :group 'gnus-group-select
960   :type 'hook)
961
962 (defcustom gnus-ps-print-hook nil
963   "*A hook run before ps-printing something from Gnus."
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-article-move-hook nil
968   "*A hook called after an article is moved, copied, respooled, or crossposted."
969   :group 'gnus-summary
970   :type 'hook)
971
972 (defcustom gnus-summary-article-delete-hook nil
973   "*A hook called after an article is deleted."
974   :group 'gnus-summary
975   :type 'hook)
976
977 (defcustom gnus-summary-article-expire-hook nil
978   "*A hook called after an article is expired."
979   :group 'gnus-summary
980   :type 'hook)
981
982 (defcustom gnus-summary-display-arrow
983   (and (fboundp 'display-graphic-p)
984        (display-graphic-p))
985   "*If non-nil, display an arrow highlighting the current article."
986   :version "21.4"
987   :group 'gnus-summary
988   :type 'boolean)
989
990 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
991   "Face used for highlighting the current article in the summary buffer."
992   :group 'gnus-summary-visual
993   :type 'face)
994
995 (defvar gnus-tmp-downloaded nil)
996
997 (defcustom gnus-summary-highlight
998   '(((eq mark gnus-canceled-mark)
999      . gnus-summary-cancelled-face)
1000     ((and uncached (> score default-high))
1001      . gnus-summary-high-undownloaded-face)
1002     ((and uncached (< score default-low))
1003      . gnus-summary-low-undownloaded-face)
1004     (uncached
1005      . gnus-summary-normal-undownloaded-face)
1006     ((and (> score default-high)
1007           (or (eq mark gnus-dormant-mark)
1008               (eq mark gnus-ticked-mark)))
1009      . gnus-summary-high-ticked-face)
1010     ((and (< score default-low)
1011           (or (eq mark gnus-dormant-mark)
1012               (eq mark gnus-ticked-mark)))
1013      . gnus-summary-low-ticked-face)
1014     ((or (eq mark gnus-dormant-mark)
1015          (eq mark gnus-ticked-mark))
1016      . gnus-summary-normal-ticked-face)
1017     ((and (> score default-high) (eq mark gnus-ancient-mark))
1018      . gnus-summary-high-ancient-face)
1019     ((and (< score default-low) (eq mark gnus-ancient-mark))
1020      . gnus-summary-low-ancient-face)
1021     ((eq mark gnus-ancient-mark)
1022      . gnus-summary-normal-ancient-face)
1023     ((and (> score default-high) (eq mark gnus-unread-mark))
1024      . gnus-summary-high-unread-face)
1025     ((and (< score default-low) (eq mark gnus-unread-mark))
1026      . gnus-summary-low-unread-face)
1027     ((eq mark gnus-unread-mark)
1028      . gnus-summary-normal-unread-face)
1029     ((> score default-high)
1030      . gnus-summary-high-read-face)
1031     ((< score default-low)
1032      . gnus-summary-low-read-face)
1033     (t
1034      . gnus-summary-normal-read-face))
1035   "*Controls the highlighting of summary buffer lines.
1036
1037 A list of (FORM . FACE) pairs.  When deciding how a a particular
1038 summary line should be displayed, each form is evaluated.  The content
1039 of the face field after the first true form is used.  You can change
1040 how those summary lines are displayed, by editing the face field.
1041
1042 You can use the following variables in the FORM field.
1043
1044 score:        The article's score
1045 default:      The default article score.
1046 default-high: The default score for high scored articles.
1047 default-low:  The default score for low scored articles.
1048 below:        The score below which articles are automatically marked as read.
1049 mark:         The article's mark.
1050 uncached:     Non-nil if the article is uncached."
1051   :group 'gnus-summary-visual
1052   :type '(repeat (cons (sexp :tag "Form" nil)
1053                        face)))
1054
1055 (defcustom gnus-alter-header-function nil
1056   "Function called to allow alteration of article header structures.
1057 The function is called with one parameter, the article header vector,
1058 which it may alter in any way."
1059   :type '(choice (const :tag "None" nil)
1060                  function)
1061   :group 'gnus-summary)
1062
1063 (defvar gnus-decode-encoded-word-function
1064   (mime-find-field-decoder 'From 'nov)
1065   "Variable that says which function should be used to decode a string with encoded words.")
1066
1067 (defcustom gnus-extra-headers '(To Newsgroups)
1068   "*Extra headers to parse."
1069   :version "21.1"
1070   :group 'gnus-summary
1071   :type '(repeat symbol))
1072
1073 (defcustom gnus-ignored-from-addresses
1074   (and user-mail-address (regexp-quote user-mail-address))
1075   "*Regexp of From headers that may be suppressed in favor of To headers."
1076   :version "21.1"
1077   :group 'gnus-summary
1078   :type 'regexp)
1079
1080 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1081   "List of charsets that should be ignored.
1082 When these charsets are used in the \"charset\" parameter, the
1083 default charset will be used instead."
1084   :version "21.1"
1085   :type '(repeat symbol)
1086   :group 'gnus-charset)
1087
1088 (gnus-define-group-parameter
1089  ignored-charsets
1090  :type list
1091  :function-document
1092  "Return the ignored charsets of GROUP."
1093  :variable gnus-group-ignored-charsets-alist
1094  :variable-default
1095  '(("alt\\.chinese\\.text" iso-8859-1))
1096  :variable-document
1097  "Alist of regexps (to match group names) and charsets that should be ignored.
1098 When these charsets are used in the \"charset\" parameter, the
1099 default charset will be used instead."
1100  :variable-group gnus-charset
1101  :variable-type '(repeat (cons (regexp :tag "Group")
1102                                (repeat symbol)))
1103  :parameter-type '(choice :tag "Ignored charsets"
1104                           :value nil
1105                           (repeat (symbol)))
1106  :parameter-document       "\
1107 List of charsets that should be ignored.
1108
1109 When these charsets are used in the \"charset\" parameter, the
1110 default charset will be used instead.")
1111
1112 (defcustom gnus-group-highlight-words-alist nil
1113   "Alist of group regexps and highlight regexps.
1114 This variable uses the same syntax as `gnus-emphasis-alist'."
1115   :version "21.1"
1116   :type '(repeat (cons (regexp :tag "Group")
1117                        (repeat (list (regexp :tag "Highlight regexp")
1118                                      (number :tag "Group for entire word" 0)
1119                                      (number :tag "Group for displayed part" 0)
1120                                      (symbol :tag "Face"
1121                                              gnus-emphasis-highlight-words)))))
1122   :group 'gnus-summary-visual)
1123
1124 (defcustom gnus-use-wheel nil
1125   "Use Intelli-mouse on summary movement"
1126   :type 'boolean
1127   :group 'gnus-summary-maneuvering)
1128
1129 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1130   "Amount to scroll messages by spinning the mouse wheel.
1131 This is actually a cons cell, where the first item is the amount to scroll
1132 on a normal wheel event, and the second is the amount to scroll when the
1133 wheel is moved with the shift key depressed."
1134   :type '(cons (integer :tag "Shift") integer)
1135   :group 'gnus-summary-maneuvering)
1136
1137 (defcustom gnus-wheel-edge-resistance 2
1138   "How hard it should be to change the current article
1139 by moving the mouse over the edge of the article window."
1140   :type 'integer
1141   :group 'gnus-summary-maneuvering)
1142
1143 (defcustom gnus-summary-show-article-charset-alist
1144   nil
1145   "Alist of number and charset.
1146 The article will be shown with the charset corresponding to the
1147 numbered argument.
1148 For example: ((1 . cn-gb-2312) (2 . big5))."
1149   :version "21.1"
1150   :type '(repeat (cons (number :tag "Argument" 1)
1151                        (symbol :tag "Charset")))
1152   :group 'gnus-charset)
1153
1154 (defcustom gnus-preserve-marks t
1155   "Whether marks are preserved when moving, copying and respooling messages."
1156   :version "21.1"
1157   :type 'boolean
1158   :group 'gnus-summary-marks)
1159
1160 (defcustom gnus-alter-articles-to-read-function nil
1161   "Function to be called to alter the list of articles to be selected."
1162   :type '(choice (const nil) function)
1163   :group 'gnus-summary)
1164
1165 (defcustom gnus-orphan-score nil
1166   "*All orphans get this score added.  Set in the score file."
1167   :group 'gnus-score-default
1168   :type '(choice (const nil)
1169                  integer))
1170
1171 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1172   "*A regexp to match MIME parts when saving multiple parts of a
1173 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1174 This regexp will be used by default when prompting the user for which
1175 type of files to save."
1176   :group 'gnus-summary
1177   :type 'regexp)
1178
1179 (defcustom gnus-read-all-available-headers nil
1180   "Whether Gnus should parse all headers made available to it.
1181 This is mostly relevant for slow back ends where the user may
1182 wish to widen the summary buffer to include all headers
1183 that were fetched.  Say, for nnultimate groups."
1184   :version "21.4"
1185   :group 'gnus-summary
1186   :type '(choice boolean regexp))
1187
1188 (defcustom gnus-summary-muttprint-program "muttprint"
1189   "Command (and optional arguments) used to run Muttprint."
1190   :version "21.4"
1191   :group 'gnus-summary
1192   :type 'string)
1193
1194 (defcustom gnus-article-loose-mime t
1195   "If non-nil, don't require MIME-Version header.
1196 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1197 supply the MIME-Version header or deliberately strip it from the mail.
1198 If non-nil (the default), Gnus will treat some articles as MIME
1199 even if the MIME-Version header is missing."
1200   :version "21.4"
1201   :type 'boolean
1202   :group 'gnus-article-mime)
1203
1204 (defcustom gnus-article-emulate-mime t
1205   "If non-nil, use MIME emulation for uuencode and the like.
1206 This means that Gnus will search message bodies for text that look
1207 like uuencoded bits, yEncoded bits, and so on, and present that using
1208 the normal Gnus MIME machinery."
1209   :version "21.4"
1210   :type 'boolean
1211   :group 'gnus-article-mime)
1212
1213 ;;; Internal variables
1214
1215 (defvar gnus-summary-display-cache nil)
1216 (defvar gnus-article-mime-handles nil)
1217 (defvar gnus-article-decoded-p nil)
1218 (defvar gnus-article-charset nil)
1219 (defvar gnus-article-ignored-charsets nil)
1220 (defvar gnus-scores-exclude-files nil)
1221 (defvar gnus-page-broken nil)
1222
1223 (defvar gnus-original-article nil)
1224 (defvar gnus-article-internal-prepare-hook nil)
1225 (defvar gnus-newsgroup-process-stack nil)
1226
1227 (defvar gnus-thread-indent-array nil)
1228 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1229 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1230   "Function called to sort the articles within a thread after it has been gathered together.")
1231
1232 (defvar gnus-summary-save-parts-type-history nil)
1233 (defvar gnus-summary-save-parts-last-directory nil)
1234
1235 ;; Avoid highlighting in kill files.
1236 (defvar gnus-summary-inhibit-highlight nil)
1237 (defvar gnus-newsgroup-selected-overlay nil)
1238 (defvar gnus-inhibit-limiting nil)
1239 (defvar gnus-newsgroup-adaptive-score-file nil)
1240 (defvar gnus-current-score-file nil)
1241 (defvar gnus-current-move-group nil)
1242 (defvar gnus-current-copy-group nil)
1243 (defvar gnus-current-crosspost-group nil)
1244 (defvar gnus-newsgroup-display nil)
1245
1246 (defvar gnus-newsgroup-dependencies nil)
1247 (defvar gnus-newsgroup-adaptive nil)
1248 (defvar gnus-summary-display-article-function nil)
1249 (defvar gnus-summary-highlight-line-function nil
1250   "Function called after highlighting a summary line.")
1251
1252 (defvar gnus-summary-line-format-alist
1253   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1254     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1255     (?s gnus-tmp-subject-or-nil ?s)
1256     (?n gnus-tmp-name ?s)
1257     (?A (std11-address-string
1258          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1259     (?a (or (std11-full-name-string
1260              (car (mime-entity-read-field gnus-tmp-header 'From)))
1261             gnus-tmp-from) ?s)
1262     (?F gnus-tmp-from ?s)
1263     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1264     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1265     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1266     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1267     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1268     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1269     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1270     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1271     (?L gnus-tmp-lines ?s)
1272     (?O gnus-tmp-downloaded ?c)
1273     (?I gnus-tmp-indentation ?s)
1274     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1275     (?R gnus-tmp-replied ?c)
1276     (?\[ gnus-tmp-opening-bracket ?c)
1277     (?\] gnus-tmp-closing-bracket ?c)
1278     (?\> (make-string gnus-tmp-level ? ) ?s)
1279     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1280     (?i gnus-tmp-score ?d)
1281     (?z gnus-tmp-score-char ?c)
1282     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1283     (?U gnus-tmp-unread ?c)
1284     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1285         ?s)
1286     (?t (gnus-summary-number-of-articles-in-thread
1287          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1288         ?d)
1289     (?e (gnus-summary-number-of-articles-in-thread
1290          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1291         ?c)
1292     (?u gnus-tmp-user-defined ?s)
1293     (?P (gnus-pick-line-number) ?d)
1294     (?B gnus-tmp-thread-tree-header-string ?s)
1295     (user-date (gnus-user-date
1296                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1297   "An alist of format specifications that can appear in summary lines.
1298 These are paired with what variables they correspond with, along with
1299 the type of the variable (string, integer, character, etc).")
1300
1301 (defvar gnus-summary-dummy-line-format-alist
1302   `((?S gnus-tmp-subject ?s)
1303     (?N gnus-tmp-number ?d)
1304     (?u gnus-tmp-user-defined ?s)))
1305
1306 (defvar gnus-summary-mode-line-format-alist
1307   `((?G gnus-tmp-group-name ?s)
1308     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1309     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1310     (?A gnus-tmp-article-number ?d)
1311     (?Z gnus-tmp-unread-and-unselected ?s)
1312     (?V gnus-version ?s)
1313     (?U gnus-tmp-unread-and-unticked ?d)
1314     (?S gnus-tmp-subject ?s)
1315     (?e gnus-tmp-unselected ?d)
1316     (?u gnus-tmp-user-defined ?s)
1317     (?d (length gnus-newsgroup-dormant) ?d)
1318     (?t (length gnus-newsgroup-marked) ?d)
1319     (?h (length gnus-newsgroup-spam-marked) ?d)
1320     (?r (length gnus-newsgroup-reads) ?d)
1321     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1322     (?E gnus-newsgroup-expunged-tally ?d)
1323     (?s (gnus-current-score-file-nondirectory) ?s)))
1324
1325 (defvar gnus-last-search-regexp nil
1326   "Default regexp for article search command.")
1327
1328 (defvar gnus-summary-search-article-matched-data nil
1329   "Last matched data of article search command.  It is the local variable
1330 in `gnus-article-buffer' which consists of the list of start position,
1331 end position and text.")
1332
1333 (defvar gnus-last-shell-command nil
1334   "Default shell command on article.")
1335
1336 (defvar gnus-newsgroup-agentized nil
1337   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1338 (defvar gnus-newsgroup-begin nil)
1339 (defvar gnus-newsgroup-end nil)
1340 (defvar gnus-newsgroup-last-rmail nil)
1341 (defvar gnus-newsgroup-last-mail nil)
1342 (defvar gnus-newsgroup-last-folder nil)
1343 (defvar gnus-newsgroup-last-file nil)
1344 (defvar gnus-newsgroup-auto-expire nil)
1345 (defvar gnus-newsgroup-active nil)
1346
1347 (defvar gnus-newsgroup-data nil)
1348 (defvar gnus-newsgroup-data-reverse nil)
1349 (defvar gnus-newsgroup-limit nil)
1350 (defvar gnus-newsgroup-limits nil)
1351 (defvar gnus-summary-use-undownloaded-faces nil)
1352
1353 (defvar gnus-newsgroup-unreads nil
1354   "Sorted list of unread articles in the current newsgroup.")
1355
1356 (defvar gnus-newsgroup-unselected nil
1357   "Sorted list of unselected unread articles in the current newsgroup.")
1358
1359 (defvar gnus-newsgroup-reads nil
1360   "Alist of read articles and article marks in the current newsgroup.")
1361
1362 (defvar gnus-newsgroup-expunged-tally nil)
1363
1364 (defvar gnus-newsgroup-marked nil
1365   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1366
1367 (defvar gnus-newsgroup-spam-marked nil
1368   "List of ranges of articles that have been marked as spam.")
1369
1370 (defvar gnus-newsgroup-killed nil
1371   "List of ranges of articles that have been through the scoring process.")
1372
1373 (defvar gnus-newsgroup-cached nil
1374   "Sorted list of articles that come from the article cache.")
1375
1376 (defvar gnus-newsgroup-saved nil
1377   "List of articles that have been saved.")
1378
1379 (defvar gnus-newsgroup-kill-headers nil)
1380
1381 (defvar gnus-newsgroup-replied nil
1382   "List of articles that have been replied to in the current newsgroup.")
1383
1384 (defvar gnus-newsgroup-forwarded nil
1385   "List of articles that have been forwarded in the current newsgroup.")
1386
1387 (defvar gnus-newsgroup-recent nil
1388   "List of articles that have are recent in the current newsgroup.")
1389
1390 (defvar gnus-newsgroup-expirable nil
1391   "Sorted list of articles in the current newsgroup that can be expired.")
1392
1393 (defvar gnus-newsgroup-processable nil
1394   "List of articles in the current newsgroup that can be processed.")
1395
1396 (defvar gnus-newsgroup-downloadable nil
1397   "Sorted list of articles in the current newsgroup that can be processed.")
1398
1399 (defvar gnus-newsgroup-unfetched nil
1400   "Sorted list of articles in the current newsgroup whose headers have
1401 not been fetched into the agent.
1402
1403 This list will always be a subset of gnus-newsgroup-undownloaded.")
1404
1405 (defvar gnus-newsgroup-undownloaded nil
1406   "List of articles in the current newsgroup that haven't been downloaded.")
1407
1408 (defvar gnus-newsgroup-unsendable nil
1409   "List of articles in the current newsgroup that won't be sent.")
1410
1411 (defvar gnus-newsgroup-bookmarks nil
1412   "List of articles in the current newsgroup that have bookmarks.")
1413
1414 (defvar gnus-newsgroup-dormant nil
1415   "Sorted list of dormant articles in the current newsgroup.")
1416
1417 (defvar gnus-newsgroup-unseen nil
1418   "List of unseen articles in the current newsgroup.")
1419
1420 (defvar gnus-newsgroup-seen nil
1421   "Range of seen articles in the current newsgroup.")
1422
1423 (defvar gnus-newsgroup-articles nil
1424   "List of articles in the current newsgroup.")
1425
1426 (defvar gnus-newsgroup-scored nil
1427   "List of scored articles in the current newsgroup.")
1428
1429 (defvar gnus-newsgroup-incorporated nil
1430   "List of incorporated articles in the current newsgroup.")
1431
1432 (defvar gnus-newsgroup-headers nil
1433   "List of article headers in the current newsgroup.")
1434
1435 (defvar gnus-newsgroup-threads nil)
1436
1437 (defvar gnus-newsgroup-prepared nil
1438   "Whether the current group has been prepared properly.")
1439
1440 (defvar gnus-newsgroup-ancient nil
1441   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1442
1443 (defvar gnus-newsgroup-sparse nil)
1444
1445 (defvar gnus-current-article nil)
1446 (defvar gnus-article-current nil)
1447 (defvar gnus-current-headers nil)
1448 (defvar gnus-have-all-headers nil)
1449 (defvar gnus-last-article nil)
1450 (defvar gnus-newsgroup-history nil)
1451 (defvar gnus-newsgroup-charset nil)
1452 (defvar gnus-newsgroup-ephemeral-charset nil)
1453 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1454
1455 (defvar gnus-article-before-search nil)
1456
1457 (defvar gnus-summary-local-variables
1458   '(gnus-newsgroup-name
1459     gnus-newsgroup-begin gnus-newsgroup-end
1460     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1461     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1462     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1463     gnus-newsgroup-unselected gnus-newsgroup-marked
1464     gnus-newsgroup-spam-marked
1465     gnus-newsgroup-reads gnus-newsgroup-saved
1466     gnus-newsgroup-replied gnus-newsgroup-forwarded
1467     gnus-newsgroup-recent
1468     gnus-newsgroup-expirable
1469     gnus-newsgroup-processable gnus-newsgroup-killed
1470     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1471     gnus-newsgroup-unfetched
1472     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1473     gnus-newsgroup-seen gnus-newsgroup-articles
1474     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1475     gnus-newsgroup-headers gnus-newsgroup-threads
1476     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1477     gnus-current-article gnus-current-headers gnus-have-all-headers
1478     gnus-last-article gnus-article-internal-prepare-hook
1479     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1480     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1481     gnus-thread-expunge-below
1482     gnus-score-alist gnus-current-score-file
1483     (gnus-summary-expunge-below . global)
1484     (gnus-summary-mark-below . global)
1485     (gnus-orphan-score . global)
1486     gnus-newsgroup-active gnus-scores-exclude-files
1487     gnus-newsgroup-history gnus-newsgroup-ancient
1488     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1489     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1490     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1491     (gnus-newsgroup-expunged-tally . 0)
1492     gnus-cache-removable-articles gnus-newsgroup-cached
1493     gnus-newsgroup-data gnus-newsgroup-data-reverse
1494     gnus-newsgroup-limit gnus-newsgroup-limits
1495     gnus-newsgroup-charset gnus-newsgroup-display
1496     gnus-summary-use-undownloaded-faces
1497     gnus-newsgroup-incorporated)
1498   "Variables that are buffer-local to the summary buffers.")
1499
1500 (defvar gnus-newsgroup-variables nil
1501   "A list of variables that have separate values in different newsgroups.
1502 A list of newsgroup (summary buffer) local variables, or cons of
1503 variables and their default expressions to be evalled (when the default
1504 values are not nil), that should be made global while the summary buffer
1505 is active.
1506
1507 Note: The default expressions will be evaluated (using function `eval')
1508 before assignment to the local variable rather than just assigned to it.
1509 If the default expression is the symbol `global', that symbol will not
1510 be evaluated but the global value of the local variable will be used
1511 instead.
1512
1513 These variables can be used to set variables in the group parameters
1514 while still allowing them to affect operations done in other buffers.
1515 For example:
1516
1517 \(setq gnus-newsgroup-variables
1518      '(message-use-followup-to
1519        (gnus-visible-headers .
1520          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1521 ")
1522
1523 ;; Byte-compiler warning.
1524 (eval-when-compile
1525   ;; Bind features so that require will believe that gnus-sum has
1526   ;; already been loaded (avoids infinite recursion)
1527   (let ((features (cons 'gnus-sum features)))
1528     ;; Several of the declarations in gnus-sum are needed to load the
1529     ;; following files. Right now, these definitions have been
1530     ;; compiled but not defined (evaluated).  We could either do a
1531     ;; eval-and-compile about all of the declarations or evaluate the
1532     ;; source file.
1533     (if (boundp 'gnus-newsgroup-variables)
1534         nil
1535       (load "gnus-sum.el" t t t))
1536     (require 'gnus)
1537     (require 'gnus-art)))
1538
1539 ;; Subject simplification.
1540
1541 (defun gnus-simplify-whitespace (str)
1542   "Remove excessive whitespace from STR."
1543   ;; Multiple spaces.
1544   (while (string-match "[ \t][ \t]+" str)
1545     (setq str (concat (substring str 0 (match-beginning 0))
1546                         " "
1547                         (substring str (match-end 0)))))
1548   ;; Leading spaces.
1549   (when (string-match "^[ \t]+" str)
1550     (setq str (substring str (match-end 0))))
1551   ;; Trailing spaces.
1552   (when (string-match "[ \t]+$" str)
1553     (setq str (substring str 0 (match-beginning 0))))
1554   str)
1555
1556 (defun gnus-simplify-all-whitespace (str)
1557   "Remove all whitespace from STR."
1558   (while (string-match "[ \t\n]+" str)
1559     (setq str (replace-match "" nil nil str)))
1560   str)
1561
1562 (defsubst gnus-simplify-subject-re (subject)
1563   "Remove \"Re:\" from subject lines."
1564   (if (string-match message-subject-re-regexp subject)
1565       (substring subject (match-end 0))
1566     subject))
1567
1568 (defun gnus-simplify-subject (subject &optional re-only)
1569   "Remove `Re:' and words in parentheses.
1570 If RE-ONLY is non-nil, strip leading `Re:'s only."
1571   (let ((case-fold-search t))           ;Ignore case.
1572     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1573     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1574       (setq subject (substring subject (match-end 0))))
1575     ;; Remove uninteresting prefixes.
1576     (when (and (not re-only)
1577                gnus-simplify-ignored-prefixes
1578                (string-match gnus-simplify-ignored-prefixes subject))
1579       (setq subject (substring subject (match-end 0))))
1580     ;; Remove words in parentheses from end.
1581     (unless re-only
1582       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1583         (setq subject (substring subject 0 (match-beginning 0)))))
1584     ;; Return subject string.
1585     subject))
1586
1587 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1588 ;; all whitespace.
1589 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1590   (goto-char (point-min))
1591   (while (re-search-forward regexp nil t)
1592     (replace-match (or newtext ""))))
1593
1594 (defun gnus-simplify-buffer-fuzzy ()
1595   "Simplify string in the buffer fuzzily.
1596 The string in the accessible portion of the current buffer is simplified.
1597 It is assumed to be a single-line subject.
1598 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1599 matter is removed.  Additional things can be deleted by setting
1600 `gnus-simplify-subject-fuzzy-regexp'."
1601   (let ((case-fold-search t)
1602         (modified-tick))
1603     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1604
1605     (while (not (eq modified-tick (buffer-modified-tick)))
1606       (setq modified-tick (buffer-modified-tick))
1607       (cond
1608        ((listp gnus-simplify-subject-fuzzy-regexp)
1609         (mapcar 'gnus-simplify-buffer-fuzzy-step
1610                 gnus-simplify-subject-fuzzy-regexp))
1611        (gnus-simplify-subject-fuzzy-regexp
1612         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1613       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1614       (gnus-simplify-buffer-fuzzy-step
1615        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1616       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1617
1618     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1619     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1620     (gnus-simplify-buffer-fuzzy-step " $")
1621     (gnus-simplify-buffer-fuzzy-step "^ +")))
1622
1623 (defun gnus-simplify-subject-fuzzy (subject)
1624   "Simplify a subject string fuzzily.
1625 See `gnus-simplify-buffer-fuzzy' for details."
1626   (save-excursion
1627     (gnus-set-work-buffer)
1628     (let ((case-fold-search t))
1629       ;; Remove uninteresting prefixes.
1630       (when (and gnus-simplify-ignored-prefixes
1631                  (string-match gnus-simplify-ignored-prefixes subject))
1632         (setq subject (substring subject (match-end 0))))
1633       (insert subject)
1634       (inline (gnus-simplify-buffer-fuzzy))
1635       (buffer-string))))
1636
1637 (defsubst gnus-simplify-subject-fully (subject)
1638   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1639   (cond
1640    (gnus-simplify-subject-functions
1641     (gnus-map-function gnus-simplify-subject-functions subject))
1642    ((null gnus-summary-gather-subject-limit)
1643     (gnus-simplify-subject-re subject))
1644    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1645     (gnus-simplify-subject-fuzzy subject))
1646    ((numberp gnus-summary-gather-subject-limit)
1647     (gnus-limit-string (gnus-simplify-subject-re subject)
1648                        gnus-summary-gather-subject-limit))
1649    (t
1650     subject)))
1651
1652 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1653   "Check whether two subjects are equal.
1654 If optional argument SIMPLE-FIRST is t, first argument is already
1655 simplified."
1656   (cond
1657    ((null simple-first)
1658     (equal (gnus-simplify-subject-fully s1)
1659            (gnus-simplify-subject-fully s2)))
1660    (t
1661     (equal s1
1662            (gnus-simplify-subject-fully s2)))))
1663
1664 (defun gnus-summary-bubble-group ()
1665   "Increase the score of the current group.
1666 This is a handy function to add to `gnus-summary-exit-hook' to
1667 increase the score of each group you read."
1668   (gnus-group-add-score gnus-newsgroup-name))
1669
1670 \f
1671 ;;;
1672 ;;; Gnus summary mode
1673 ;;;
1674
1675 (put 'gnus-summary-mode 'mode-class 'special)
1676
1677 (defvar gnus-article-commands-menu)
1678
1679 ;; Non-orthogonal keys
1680
1681 (gnus-define-keys gnus-summary-mode-map
1682   " " gnus-summary-next-page
1683   "\177" gnus-summary-prev-page
1684   [delete] gnus-summary-prev-page
1685   [backspace] gnus-summary-prev-page
1686   "\r" gnus-summary-scroll-up
1687   "\M-\r" gnus-summary-scroll-down
1688   "n" gnus-summary-next-unread-article
1689   "p" gnus-summary-prev-unread-article
1690   "N" gnus-summary-next-article
1691   "P" gnus-summary-prev-article
1692   "\M-\C-n" gnus-summary-next-same-subject
1693   "\M-\C-p" gnus-summary-prev-same-subject
1694   "\M-n" gnus-summary-next-unread-subject
1695   "\M-p" gnus-summary-prev-unread-subject
1696   "." gnus-summary-first-unread-article
1697   "," gnus-summary-best-unread-article
1698   "\M-s" gnus-summary-search-article-forward
1699   "\M-r" gnus-summary-search-article-backward
1700   "<" gnus-summary-beginning-of-article
1701   ">" gnus-summary-end-of-article
1702   "j" gnus-summary-goto-article
1703   "^" gnus-summary-refer-parent-article
1704   "\M-^" gnus-summary-refer-article
1705   "u" gnus-summary-tick-article-forward
1706   "!" gnus-summary-tick-article-forward
1707   "U" gnus-summary-tick-article-backward
1708   "d" gnus-summary-mark-as-read-forward
1709   "D" gnus-summary-mark-as-read-backward
1710   "E" gnus-summary-mark-as-expirable
1711   "\M-u" gnus-summary-clear-mark-forward
1712   "\M-U" gnus-summary-clear-mark-backward
1713   "k" gnus-summary-kill-same-subject-and-select
1714   "\C-k" gnus-summary-kill-same-subject
1715   "\M-\C-k" gnus-summary-kill-thread
1716   "\M-\C-l" gnus-summary-lower-thread
1717   "e" gnus-summary-edit-article
1718   "#" gnus-summary-mark-as-processable
1719   "\M-#" gnus-summary-unmark-as-processable
1720   "\M-\C-t" gnus-summary-toggle-threads
1721   "\M-\C-s" gnus-summary-show-thread
1722   "\M-\C-h" gnus-summary-hide-thread
1723   "\M-\C-f" gnus-summary-next-thread
1724   "\M-\C-b" gnus-summary-prev-thread
1725   [(meta down)] gnus-summary-next-thread
1726   [(meta up)] gnus-summary-prev-thread
1727   "\M-\C-u" gnus-summary-up-thread
1728   "\M-\C-d" gnus-summary-down-thread
1729   "&" gnus-summary-execute-command
1730   "c" gnus-summary-catchup-and-exit
1731   "\C-w" gnus-summary-mark-region-as-read
1732   "\C-t" gnus-summary-toggle-truncation
1733   "?" gnus-summary-mark-as-dormant
1734   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1735   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1736   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1737   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1738   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1739   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1740   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1741   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1742   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1743   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1744   "=" gnus-summary-expand-window
1745   "\C-x\C-s" gnus-summary-reselect-current-group
1746   "\M-g" gnus-summary-rescan-group
1747   "w" gnus-summary-stop-page-breaking
1748   "\C-c\C-r" gnus-summary-caesar-message
1749   "\M-t" gnus-summary-toggle-mime
1750   "f" gnus-summary-followup
1751   "F" gnus-summary-followup-with-original
1752   "C" gnus-summary-cancel-article
1753   "r" gnus-summary-reply
1754   "R" gnus-summary-reply-with-original
1755   "\C-c\C-f" gnus-summary-mail-forward
1756   "o" gnus-summary-save-article
1757   "\C-o" gnus-summary-save-article-mail
1758   "|" gnus-summary-pipe-output
1759   "\M-k" gnus-summary-edit-local-kill
1760   "\M-K" gnus-summary-edit-global-kill
1761   ;; "V" gnus-version
1762   "\C-c\C-d" gnus-summary-describe-group
1763   "q" gnus-summary-exit
1764   "Q" gnus-summary-exit-no-update
1765   "\C-c\C-i" gnus-info-find-node
1766   gnus-mouse-2 gnus-mouse-pick-article
1767   "m" gnus-summary-mail-other-window
1768   "a" gnus-summary-post-news
1769   "i" gnus-summary-news-other-window
1770   "x" gnus-summary-limit-to-unread
1771   "s" gnus-summary-isearch-article
1772   "t" gnus-summary-toggle-header
1773   "g" gnus-summary-show-article
1774   "l" gnus-summary-goto-last-article
1775   "v" gnus-summary-preview-mime-message
1776   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1777   "\C-d" gnus-summary-enter-digest-group
1778   "\M-\C-d" gnus-summary-read-document
1779   "\M-\C-e" gnus-summary-edit-parameters
1780   "\M-\C-a" gnus-summary-customize-parameters
1781   "\C-c\C-b" gnus-bug
1782   "\C-c\C-n" gnus-namazu-search
1783   "*" gnus-cache-enter-article
1784   "\M-*" gnus-cache-remove-article
1785   "\M-&" gnus-summary-universal-argument
1786   "\C-l" gnus-recenter
1787   "I" gnus-summary-increase-score
1788   "L" gnus-summary-lower-score
1789   "\M-i" gnus-symbolic-argument
1790   "h" gnus-summary-select-article-buffer
1791
1792   "V" gnus-summary-score-map
1793   "X" gnus-uu-extract-map
1794   "S" gnus-summary-send-map)
1795
1796   ;; Sort of orthogonal keymap
1797 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1798   "t" gnus-summary-tick-article-forward
1799   "!" gnus-summary-tick-article-forward
1800   "d" gnus-summary-mark-as-read-forward
1801   "r" gnus-summary-mark-as-read-forward
1802   "c" gnus-summary-clear-mark-forward
1803   " " gnus-summary-clear-mark-forward
1804   "e" gnus-summary-mark-as-expirable
1805   "x" gnus-summary-mark-as-expirable
1806   "?" gnus-summary-mark-as-dormant
1807   "b" gnus-summary-set-bookmark
1808   "B" gnus-summary-remove-bookmark
1809   "#" gnus-summary-mark-as-processable
1810   "\M-#" gnus-summary-unmark-as-processable
1811   "S" gnus-summary-limit-include-expunged
1812   "C" gnus-summary-catchup
1813   "H" gnus-summary-catchup-to-here
1814   "h" gnus-summary-catchup-from-here
1815   "\C-c" gnus-summary-catchup-all
1816   "k" gnus-summary-kill-same-subject-and-select
1817   "K" gnus-summary-kill-same-subject
1818   "P" gnus-uu-mark-map)
1819
1820 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1821   "c" gnus-summary-clear-above
1822   "u" gnus-summary-tick-above
1823   "m" gnus-summary-mark-above
1824   "k" gnus-summary-kill-below)
1825
1826 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1827   "/" gnus-summary-limit-to-subject
1828   "n" gnus-summary-limit-to-articles
1829   "w" gnus-summary-pop-limit
1830   "s" gnus-summary-limit-to-subject
1831   "a" gnus-summary-limit-to-author
1832   "u" gnus-summary-limit-to-unread
1833   "m" gnus-summary-limit-to-marks
1834   "M" gnus-summary-limit-exclude-marks
1835   "v" gnus-summary-limit-to-score
1836   "*" gnus-summary-limit-include-cached
1837   "D" gnus-summary-limit-include-dormant
1838   "T" gnus-summary-limit-include-thread
1839   "d" gnus-summary-limit-exclude-dormant
1840   "t" gnus-summary-limit-to-age
1841   "." gnus-summary-limit-to-unseen
1842   "x" gnus-summary-limit-to-extra
1843   "p" gnus-summary-limit-to-display-predicate
1844   "E" gnus-summary-limit-include-expunged
1845   "c" gnus-summary-limit-exclude-childless-dormant
1846   "C" gnus-summary-limit-mark-excluded-as-read
1847   "o" gnus-summary-insert-old-articles
1848   "N" gnus-summary-insert-new-articles
1849   "r" gnus-summary-limit-to-replied)
1850
1851 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1852   "n" gnus-summary-next-unread-article
1853   "p" gnus-summary-prev-unread-article
1854   "N" gnus-summary-next-article
1855   "P" gnus-summary-prev-article
1856   "\C-n" gnus-summary-next-same-subject
1857   "\C-p" gnus-summary-prev-same-subject
1858   "\M-n" gnus-summary-next-unread-subject
1859   "\M-p" gnus-summary-prev-unread-subject
1860   "f" gnus-summary-first-unread-article
1861   "b" gnus-summary-best-unread-article
1862   "j" gnus-summary-goto-article
1863   "g" gnus-summary-goto-subject
1864   "l" gnus-summary-goto-last-article
1865   "o" gnus-summary-pop-article)
1866
1867 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1868   "k" gnus-summary-kill-thread
1869   "l" gnus-summary-lower-thread
1870   "i" gnus-summary-raise-thread
1871   "T" gnus-summary-toggle-threads
1872   "t" gnus-summary-rethread-current
1873   "^" gnus-summary-reparent-thread
1874   "s" gnus-summary-show-thread
1875   "S" gnus-summary-show-all-threads
1876   "h" gnus-summary-hide-thread
1877   "H" gnus-summary-hide-all-threads
1878   "n" gnus-summary-next-thread
1879   "p" gnus-summary-prev-thread
1880   "u" gnus-summary-up-thread
1881   "o" gnus-summary-top-thread
1882   "d" gnus-summary-down-thread
1883   "#" gnus-uu-mark-thread
1884   "\M-#" gnus-uu-unmark-thread)
1885
1886 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1887   "g" gnus-summary-prepare
1888   "c" gnus-summary-insert-cached-articles
1889   "d" gnus-summary-insert-dormant-articles)
1890
1891 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1892   "c" gnus-summary-catchup-and-exit
1893   "C" gnus-summary-catchup-all-and-exit
1894   "E" gnus-summary-exit-no-update
1895   "J" gnus-summary-jump-to-other-group
1896   "Q" gnus-summary-exit
1897   "Z" gnus-summary-exit
1898   "n" gnus-summary-catchup-and-goto-next-group
1899   "R" gnus-summary-reselect-current-group
1900   "G" gnus-summary-rescan-group
1901   "N" gnus-summary-next-group
1902   "s" gnus-summary-save-newsrc
1903   "P" gnus-summary-prev-group)
1904
1905 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1906   " " gnus-summary-next-page
1907   "n" gnus-summary-next-page
1908   "\177" gnus-summary-prev-page
1909   [delete] gnus-summary-prev-page
1910   "p" gnus-summary-prev-page
1911   "\r" gnus-summary-scroll-up
1912   "\M-\r" gnus-summary-scroll-down
1913   "<" gnus-summary-beginning-of-article
1914   ">" gnus-summary-end-of-article
1915   "b" gnus-summary-beginning-of-article
1916   "e" gnus-summary-end-of-article
1917   "^" gnus-summary-refer-parent-article
1918   "r" gnus-summary-refer-parent-article
1919   "D" gnus-summary-enter-digest-group
1920   "R" gnus-summary-refer-references
1921   "T" gnus-summary-refer-thread
1922   "g" gnus-summary-show-article
1923   "s" gnus-summary-isearch-article
1924   "P" gnus-summary-print-article
1925   "M" gnus-mailing-list-insinuate
1926   "t" gnus-article-babel)
1927
1928 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1929   "b" gnus-article-add-buttons
1930   "B" gnus-article-add-buttons-to-head
1931   "o" gnus-article-treat-overstrike
1932   "e" gnus-article-emphasize
1933   "w" gnus-article-fill-cited-article
1934   "Q" gnus-article-fill-long-lines
1935   "C" gnus-article-capitalize-sentences
1936   "c" gnus-article-remove-cr
1937   "Z" gnus-article-decode-HZ
1938   "A" gnus-article-treat-ansi-sequences
1939   "h" gnus-article-wash-html
1940   "u" gnus-article-unsplit-urls
1941   "f" gnus-article-display-x-face
1942   "l" gnus-summary-stop-page-breaking
1943   "r" gnus-summary-caesar-message
1944   "m" gnus-summary-morse-message
1945   "t" gnus-summary-toggle-header
1946   "g" gnus-treat-smiley
1947   "v" gnus-summary-verbose-headers
1948   "m" gnus-summary-toggle-mime
1949   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1950   "p" gnus-article-verify-x-pgp-sig
1951   "d" gnus-article-treat-dumbquotes)
1952
1953 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1954   ;; mnemonic: deuglif*Y*
1955   "u" gnus-article-outlook-unwrap-lines
1956   "a" gnus-article-outlook-repair-attribution
1957   "c" gnus-article-outlook-rearrange-citation
1958   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1959
1960 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1961   "a" gnus-article-hide
1962   "h" gnus-article-hide-headers
1963   "b" gnus-article-hide-boring-headers
1964   "s" gnus-article-hide-signature
1965   "c" gnus-article-hide-citation
1966   "C" gnus-article-hide-citation-in-followups
1967   "l" gnus-article-hide-list-identifiers
1968   "B" gnus-article-strip-banner
1969   "P" gnus-article-hide-pem
1970   "\C-c" gnus-article-hide-citation-maybe)
1971
1972 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1973   "a" gnus-article-highlight
1974   "h" gnus-article-highlight-headers
1975   "c" gnus-article-highlight-citation
1976   "s" gnus-article-highlight-signature)
1977
1978 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1979   "f" gnus-article-treat-fold-headers
1980   "u" gnus-article-treat-unfold-headers
1981   "n" gnus-article-treat-fold-newsgroups)
1982
1983 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1984   "x" gnus-article-display-x-face
1985   "d" gnus-article-display-face
1986   "s" gnus-treat-smiley
1987   "D" gnus-article-remove-images
1988   "f" gnus-treat-from-picon
1989   "m" gnus-treat-mail-picon
1990   "n" gnus-treat-newsgroups-picon)
1991
1992 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1993   "z" gnus-article-date-ut
1994   "u" gnus-article-date-ut
1995   "l" gnus-article-date-local
1996   "p" gnus-article-date-english
1997   "e" gnus-article-date-lapsed
1998   "o" gnus-article-date-original
1999   "i" gnus-article-date-iso8601
2000   "s" gnus-article-date-user)
2001
2002 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2003   "t" gnus-article-remove-trailing-blank-lines
2004   "l" gnus-article-strip-leading-blank-lines
2005   "m" gnus-article-strip-multiple-blank-lines
2006   "a" gnus-article-strip-blank-lines
2007   "A" gnus-article-strip-all-blank-lines
2008   "s" gnus-article-strip-leading-space
2009   "e" gnus-article-strip-trailing-space
2010   "w" gnus-article-remove-leading-whitespace)
2011
2012 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2013   "v" gnus-version
2014   "f" gnus-summary-fetch-faq
2015   "d" gnus-summary-describe-group
2016   "h" gnus-summary-describe-briefly
2017   "i" gnus-info-find-node
2018   "c" gnus-group-fetch-charter
2019   "C" gnus-group-fetch-control)
2020
2021 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2022   "e" gnus-summary-expire-articles
2023   "\M-\C-e" gnus-summary-expire-articles-now
2024   "\177" gnus-summary-delete-article
2025   [delete] gnus-summary-delete-article
2026   [backspace] gnus-summary-delete-article
2027   "m" gnus-summary-move-article
2028   "r" gnus-summary-respool-article
2029   "w" gnus-summary-edit-article
2030   "c" gnus-summary-copy-article
2031   "B" gnus-summary-crosspost-article
2032   "q" gnus-summary-respool-query
2033   "t" gnus-summary-respool-trace
2034   "i" gnus-summary-import-article
2035   "I" gnus-summary-create-article
2036   "p" gnus-summary-article-posted-p)
2037
2038 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2039   "o" gnus-summary-save-article
2040   "m" gnus-summary-save-article-mail
2041   "F" gnus-summary-write-article-file
2042   "r" gnus-summary-save-article-rmail
2043   "f" gnus-summary-save-article-file
2044   "b" gnus-summary-save-article-body-file
2045   "h" gnus-summary-save-article-folder
2046   "v" gnus-summary-save-article-vm
2047   "p" gnus-summary-pipe-output
2048   "P" gnus-summary-muttprint
2049   "s" gnus-soup-add-article)
2050
2051 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2052   "b" gnus-summary-display-buttonized
2053   "m" gnus-summary-repair-multipart
2054   "v" gnus-article-view-part
2055   "o" gnus-article-save-part
2056   "c" gnus-article-copy-part
2057   "C" gnus-article-view-part-as-charset
2058   "e" gnus-article-view-part-externally
2059   "E" gnus-article-encrypt-body
2060   "i" gnus-article-inline-part
2061   "|" gnus-article-pipe-part)
2062
2063 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2064   "p" gnus-summary-mark-as-processable
2065   "u" gnus-summary-unmark-as-processable
2066   "U" gnus-summary-unmark-all-processable
2067   "v" gnus-uu-mark-over
2068   "s" gnus-uu-mark-series
2069   "r" gnus-uu-mark-region
2070   "g" gnus-uu-unmark-region
2071   "R" gnus-uu-mark-by-regexp
2072   "G" gnus-uu-unmark-by-regexp
2073   "t" gnus-uu-mark-thread
2074   "T" gnus-uu-unmark-thread
2075   "a" gnus-uu-mark-all
2076   "b" gnus-uu-mark-buffer
2077   "S" gnus-uu-mark-sparse
2078   "k" gnus-summary-kill-process-mark
2079   "y" gnus-summary-yank-process-mark
2080   "w" gnus-summary-save-process-mark
2081   "i" gnus-uu-invert-processable)
2082
2083 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2084   ;;"x" gnus-uu-extract-any
2085   "m" gnus-summary-save-parts
2086   "u" gnus-uu-decode-uu
2087   "U" gnus-uu-decode-uu-and-save
2088   "s" gnus-uu-decode-unshar
2089   "S" gnus-uu-decode-unshar-and-save
2090   "o" gnus-uu-decode-save
2091   "O" gnus-uu-decode-save
2092   "b" gnus-uu-decode-binhex
2093   "B" gnus-uu-decode-binhex
2094   "p" gnus-uu-decode-postscript
2095   "P" gnus-uu-decode-postscript-and-save)
2096
2097 (gnus-define-keys
2098     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2099   "u" gnus-uu-decode-uu-view
2100   "U" gnus-uu-decode-uu-and-save-view
2101   "s" gnus-uu-decode-unshar-view
2102   "S" gnus-uu-decode-unshar-and-save-view
2103   "o" gnus-uu-decode-save-view
2104   "O" gnus-uu-decode-save-view
2105   "b" gnus-uu-decode-binhex-view
2106   "B" gnus-uu-decode-binhex-view
2107   "p" gnus-uu-decode-postscript-view
2108   "P" gnus-uu-decode-postscript-and-save-view)
2109
2110 (defvar gnus-article-post-menu nil)
2111
2112 (defconst gnus-summary-menu-maxlen 20)
2113
2114 (defun gnus-summary-menu-split (menu)
2115   ;; If we have lots of elements, divide them into groups of 20
2116   ;; and make a pane (or submenu) for each one.
2117   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2118       (let ((menu menu) sublists next
2119             (i 1))
2120         (while menu
2121           ;; Pull off the next gnus-summary-menu-maxlen elements
2122           ;; and make them the next element of sublist.
2123           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2124           (if next
2125               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2126                       nil))
2127           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2128                                              (aref (car (last menu)) 0)) menu)
2129                                sublists))
2130           (setq i (1+ i))
2131           (setq menu next))
2132         (nreverse sublists))
2133     ;; Few elements--put them all in one pane.
2134     menu))
2135
2136 (defun gnus-summary-make-menu-bar ()
2137   (gnus-turn-off-edit-menu 'summary)
2138
2139   (unless (boundp 'gnus-summary-misc-menu)
2140
2141     (easy-menu-define
2142       gnus-summary-kill-menu gnus-summary-mode-map ""
2143       (cons
2144        "Score"
2145        (nconc
2146         (list
2147          ["Customize" gnus-score-customize t])
2148         (gnus-make-score-map 'increase)
2149         (gnus-make-score-map 'lower)
2150         '(("Mark"
2151            ["Kill below" gnus-summary-kill-below t]
2152            ["Mark above" gnus-summary-mark-above t]
2153            ["Tick above" gnus-summary-tick-above t]
2154            ["Clear above" gnus-summary-clear-above t])
2155           ["Current score" gnus-summary-current-score t]
2156           ["Set score" gnus-summary-set-score t]
2157           ["Switch current score file..." gnus-score-change-score-file t]
2158           ["Set mark below..." gnus-score-set-mark-below t]
2159           ["Set expunge below..." gnus-score-set-expunge-below t]
2160           ["Edit current score file" gnus-score-edit-current-scores t]
2161           ["Edit score file" gnus-score-edit-file t]
2162           ["Trace score" gnus-score-find-trace t]
2163           ["Find words" gnus-score-find-favourite-words t]
2164           ["Rescore buffer" gnus-summary-rescore t]
2165           ["Increase score..." gnus-summary-increase-score t]
2166           ["Lower score..." gnus-summary-lower-score t]))))
2167
2168     ;; Define both the Article menu in the summary buffer and the
2169     ;; equivalent Commands menu in the article buffer here for
2170     ;; consistency.
2171     (let ((innards
2172            `(("Hide"
2173               ["All" gnus-article-hide t]
2174               ["Headers" gnus-article-hide-headers t]
2175               ["Signature" gnus-article-hide-signature t]
2176               ["Citation" gnus-article-hide-citation t]
2177               ["List identifiers" gnus-article-hide-list-identifiers t]
2178               ["Banner" gnus-article-strip-banner t]
2179               ["Boring headers" gnus-article-hide-boring-headers t])
2180              ("Highlight"
2181               ["All" gnus-article-highlight t]
2182               ["Headers" gnus-article-highlight-headers t]
2183               ["Signature" gnus-article-highlight-signature t]
2184               ["Citation" gnus-article-highlight-citation t])
2185              ("Date"
2186               ["Local" gnus-article-date-local t]
2187               ["ISO8601" gnus-article-date-iso8601 t]
2188               ["UT" gnus-article-date-ut t]
2189               ["Original" gnus-article-date-original t]
2190               ["Lapsed" gnus-article-date-lapsed t]
2191               ["User-defined" gnus-article-date-user t])
2192              ("Display"
2193               ["Remove images" gnus-article-remove-images t]
2194               ["Toggle smiley" gnus-treat-smiley t]
2195               ["Show X-Face" gnus-article-display-x-face t]
2196               ["Show picons in From" gnus-treat-from-picon t]
2197               ["Show picons in mail headers" gnus-treat-mail-picon t]
2198               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2199               ("View as different encoding"
2200                ,@(gnus-summary-menu-split
2201                   (mapcar
2202                    (lambda (cs)
2203                      ;; Since easymenu under Emacs doesn't allow
2204                      ;; lambda forms for menu commands, we should
2205                      ;; provide intern'ed function symbols.
2206                      (let ((command (intern (format "\
2207 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2208                        (fset command
2209                              `(lambda ()
2210                                 (interactive)
2211                                 (let ((gnus-summary-show-article-charset-alist
2212                                        '((1 . ,cs))))
2213                                   (gnus-summary-show-article 1))))
2214                        `[,(symbol-name cs) ,command t]))
2215                    (sort (if (fboundp 'coding-system-list)
2216                              (coding-system-list)
2217                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2218                            )
2219                          'string<)))))
2220              ("Washing"
2221               ("Remove Blanks"
2222                ["Leading" gnus-article-strip-leading-blank-lines t]
2223                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2224                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2225                ["All of the above" gnus-article-strip-blank-lines t]
2226                ["All" gnus-article-strip-all-blank-lines t]
2227                ["Leading space" gnus-article-strip-leading-space t]
2228                ["Trailing space" gnus-article-strip-trailing-space t]
2229                ["Leading space in headers"
2230                 gnus-article-remove-leading-whitespace t])
2231               ["Overstrike" gnus-article-treat-overstrike t]
2232               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2233               ["Emphasis" gnus-article-emphasize t]
2234               ["Word wrap" gnus-article-fill-cited-article t]
2235               ["Fill long lines" gnus-article-fill-long-lines t]
2236               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2237               ["Remove CR" gnus-article-remove-cr t]
2238               ["Rot 13" gnus-summary-caesar-message
2239                ,@(if (featurep 'xemacs) '(t)
2240                    '(:help "\"Caesar rotate\" article by 13"))]
2241               ["Morse decode" gnus-summary-morse-message t]
2242               ["Unix pipe..." gnus-summary-pipe-message t]
2243               ["Add buttons" gnus-article-add-buttons t]
2244               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2245               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2246               ["Toggle MIME" gnus-summary-toggle-mime t]
2247               ["Verbose header" gnus-summary-verbose-headers t]
2248               ["Toggle header" gnus-summary-toggle-header t]
2249               ["Unfold headers" gnus-article-treat-unfold-headers t]
2250               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2251               ["Html" gnus-article-wash-html t]
2252               ["Unsplit URLs" gnus-article-unsplit-urls t]
2253               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2254               ["Decode HZ" gnus-article-decode-HZ t]
2255               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2256               ("(Outlook) Deuglify"
2257                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2258                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2259                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2260                ["Full (Outlook) deuglify"
2261                 gnus-article-outlook-deuglify-article t])
2262               )
2263              ("Output"
2264               ["Save in default format..." gnus-summary-save-article
2265                ,@(if (featurep 'xemacs) '(t)
2266                    '(:help "Save article using default method"))]
2267               ["Save in file..." gnus-summary-save-article-file
2268                ,@(if (featurep 'xemacs) '(t)
2269                    '(:help "Save article in file"))]
2270               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2271               ["Save in MH folder..." gnus-summary-save-article-folder t]
2272               ["Save in VM folder..." gnus-summary-save-article-vm t]
2273               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2274               ["Save body in file..." gnus-summary-save-article-body-file t]
2275               ["Pipe through a filter..." gnus-summary-pipe-output t]
2276               ["Add to SOUP packet" gnus-soup-add-article t]
2277               ["Print with Muttprint..." gnus-summary-muttprint t]
2278               ["Print" gnus-summary-print-article
2279                ,@(if (featurep 'xemacs) '(t)
2280                    '(:help "Generate and print a PostScript image"))])
2281              ("Copy, move,... (Backend)"
2282               ,@(if (featurep 'xemacs) nil
2283                   '(:help "Copying, moving, expiring articles..."))
2284               ["Respool article..." gnus-summary-respool-article t]
2285               ["Move article..." gnus-summary-move-article
2286                (gnus-check-backend-function
2287                 'request-move-article gnus-newsgroup-name)]
2288               ["Copy article..." gnus-summary-copy-article t]
2289               ["Crosspost article..." gnus-summary-crosspost-article
2290                (gnus-check-backend-function
2291                 'request-replace-article gnus-newsgroup-name)]
2292               ["Import file..." gnus-summary-import-article
2293                (gnus-check-backend-function
2294                 'request-accept-article gnus-newsgroup-name)]
2295               ["Create article..." gnus-summary-create-article
2296                (gnus-check-backend-function
2297                 'request-accept-article gnus-newsgroup-name)]
2298               ["Check if posted" gnus-summary-article-posted-p t]
2299               ["Edit article" gnus-summary-edit-article
2300                (not (gnus-group-read-only-p))]
2301               ["Delete article" gnus-summary-delete-article
2302                (gnus-check-backend-function
2303                 'request-expire-articles gnus-newsgroup-name)]
2304               ["Query respool" gnus-summary-respool-query t]
2305               ["Trace respool" gnus-summary-respool-trace t]
2306               ["Delete expirable articles" gnus-summary-expire-articles-now
2307                (gnus-check-backend-function
2308                 'request-expire-articles gnus-newsgroup-name)])
2309              ("Extract"
2310               ["Uudecode" gnus-uu-decode-uu
2311                ,@(if (featurep 'xemacs) '(t)
2312                    '(:help "Decode uuencoded article(s)"))]
2313               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2314               ["Unshar" gnus-uu-decode-unshar t]
2315               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2316               ["Save" gnus-uu-decode-save t]
2317               ["Binhex" gnus-uu-decode-binhex t]
2318               ["Postscript" gnus-uu-decode-postscript t])
2319              ("Cache"
2320               ["Enter article" gnus-cache-enter-article t]
2321               ["Remove article" gnus-cache-remove-article t])
2322              ["Translate" gnus-article-babel t]
2323              ["Select article buffer" gnus-summary-select-article-buffer t]
2324              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2325              ["Isearch article..." gnus-summary-isearch-article t]
2326              ["Beginning of the article" gnus-summary-beginning-of-article t]
2327              ["End of the article" gnus-summary-end-of-article t]
2328              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2329              ["Fetch referenced articles" gnus-summary-refer-references t]
2330              ["Fetch current thread" gnus-summary-refer-thread t]
2331              ["Fetch article with id..." gnus-summary-refer-article t]
2332              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2333              ["Redisplay" gnus-summary-show-article t]
2334              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2335       (easy-menu-define
2336         gnus-summary-article-menu gnus-summary-mode-map ""
2337         (cons "Article" innards))
2338
2339       (if (not (keymapp gnus-summary-article-menu))
2340           (easy-menu-define
2341             gnus-article-commands-menu gnus-article-mode-map ""
2342             (cons "Commands" innards))
2343         ;; in Emacs, don't share menu.
2344         (setq gnus-article-commands-menu
2345               (copy-keymap gnus-summary-article-menu))
2346         (define-key gnus-article-mode-map [menu-bar commands]
2347           (cons "Commands" gnus-article-commands-menu))))
2348
2349     (easy-menu-define
2350       gnus-summary-thread-menu gnus-summary-mode-map ""
2351       '("Threads"
2352         ["Find all messages in thread" gnus-summary-refer-thread t]
2353         ["Toggle threading" gnus-summary-toggle-threads t]
2354         ["Hide threads" gnus-summary-hide-all-threads t]
2355         ["Show threads" gnus-summary-show-all-threads t]
2356         ["Hide thread" gnus-summary-hide-thread t]
2357         ["Show thread" gnus-summary-show-thread t]
2358         ["Go to next thread" gnus-summary-next-thread t]
2359         ["Go to previous thread" gnus-summary-prev-thread t]
2360         ["Go down thread" gnus-summary-down-thread t]
2361         ["Go up thread" gnus-summary-up-thread t]
2362         ["Top of thread" gnus-summary-top-thread t]
2363         ["Mark thread as read" gnus-summary-kill-thread t]
2364         ["Lower thread score" gnus-summary-lower-thread t]
2365         ["Raise thread score" gnus-summary-raise-thread t]
2366         ["Rethread current" gnus-summary-rethread-current t]))
2367
2368     (easy-menu-define
2369       gnus-summary-post-menu gnus-summary-mode-map ""
2370       `("Post"
2371         ["Send a message (mail or news)" gnus-summary-post-news
2372          ,@(if (featurep 'xemacs) '(t)
2373              '(:help "Compose a new message (mail or news)"))]
2374         ["Followup" gnus-summary-followup
2375          ,@(if (featurep 'xemacs) '(t)
2376              '(:help "Post followup to this article"))]
2377         ["Followup and yank" gnus-summary-followup-with-original
2378          ,@(if (featurep 'xemacs) '(t)
2379              '(:help "Post followup to this article, quoting its contents"))]
2380         ["Supersede article" gnus-summary-supersede-article t]
2381         ["Cancel article" gnus-summary-cancel-article
2382          ,@(if (featurep 'xemacs) '(t)
2383              '(:help "Cancel an article you posted"))]
2384         ["Reply" gnus-summary-reply t]
2385         ["Reply and yank" gnus-summary-reply-with-original t]
2386         ["Wide reply" gnus-summary-wide-reply t]
2387         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2388          ,@(if (featurep 'xemacs) '(t)
2389              '(:help "Mail a reply, quoting this article"))]
2390         ["Very wide reply" gnus-summary-very-wide-reply t]
2391         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2392          ,@(if (featurep 'xemacs) '(t)
2393              '(:help "Mail a very wide reply, quoting this article"))]
2394         ["Mail forward" gnus-summary-mail-forward t]
2395         ["Post forward" gnus-summary-post-forward t]
2396         ["Digest and mail" gnus-summary-digest-mail-forward t]
2397         ["Digest and post" gnus-summary-digest-post-forward t]
2398         ["Resend message" gnus-summary-resend-message t]
2399         ["Resend message edit" gnus-summary-resend-message-edit t]
2400         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2401         ["Send a mail" gnus-summary-mail-other-window t]
2402         ["Create a local message" gnus-summary-news-other-window t]
2403         ["Uuencode and post" gnus-uu-post-news
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Post a uuencoded article"))]
2406         ["Followup via news" gnus-summary-followup-to-mail t]
2407         ["Followup via news and yank"
2408          gnus-summary-followup-to-mail-with-original t]
2409         ;;("Draft"
2410         ;;["Send" gnus-summary-send-draft t]
2411         ;;["Send bounced" gnus-resend-bounced-mail t])
2412         ))
2413
2414     (cond
2415      ((not (keymapp gnus-summary-post-menu))
2416       (setq gnus-article-post-menu gnus-summary-post-menu))
2417      ((not gnus-article-post-menu)
2418       ;; Don't share post menu.
2419       (setq gnus-article-post-menu
2420             (copy-keymap gnus-summary-post-menu))))
2421     (define-key gnus-article-mode-map [menu-bar post]
2422       (cons "Post" gnus-article-post-menu))
2423
2424     (easy-menu-define
2425       gnus-summary-misc-menu gnus-summary-mode-map ""
2426       `("Gnus"
2427         ("Mark Read"
2428          ["Mark as read" gnus-summary-mark-as-read-forward t]
2429          ["Mark same subject and select"
2430           gnus-summary-kill-same-subject-and-select t]
2431          ["Mark same subject" gnus-summary-kill-same-subject t]
2432          ["Catchup" gnus-summary-catchup
2433           ,@(if (featurep 'xemacs) '(t)
2434               '(:help "Mark unread articles in this group as read"))]
2435          ["Catchup all" gnus-summary-catchup-all t]
2436          ["Catchup to here" gnus-summary-catchup-to-here t]
2437          ["Catchup from here" gnus-summary-catchup-from-here t]
2438          ["Catchup region" gnus-summary-mark-region-as-read
2439           (gnus-mark-active-p)]
2440          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2441         ("Mark Various"
2442          ["Tick" gnus-summary-tick-article-forward t]
2443          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2444          ["Remove marks" gnus-summary-clear-mark-forward t]
2445          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2446          ["Set bookmark" gnus-summary-set-bookmark t]
2447          ["Remove bookmark" gnus-summary-remove-bookmark t])
2448         ("Limit to"
2449          ["Marks..." gnus-summary-limit-to-marks t]
2450          ["Subject..." gnus-summary-limit-to-subject t]
2451          ["Author..." gnus-summary-limit-to-author t]
2452          ["Age..." gnus-summary-limit-to-age t]
2453          ["Extra..." gnus-summary-limit-to-extra t]
2454          ["Score..." gnus-summary-limit-to-score t]
2455          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2456          ["Unread" gnus-summary-limit-to-unread t]
2457          ["Unseen" gnus-summary-limit-to-unseen t]
2458          ["Replied" gnus-summary-limit-to-replied t]
2459          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2460          ["Next articles" gnus-summary-limit-to-articles t]
2461          ["Pop limit" gnus-summary-pop-limit t]
2462          ["Show dormant" gnus-summary-limit-include-dormant t]
2463          ["Hide childless dormant"
2464           gnus-summary-limit-exclude-childless-dormant t]
2465          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2466          ["Hide marked" gnus-summary-limit-exclude-marks t]
2467          ["Show expunged" gnus-summary-limit-include-expunged t])
2468         ("Process Mark"
2469          ["Set mark" gnus-summary-mark-as-processable t]
2470          ["Remove mark" gnus-summary-unmark-as-processable t]
2471          ["Remove all marks" gnus-summary-unmark-all-processable t]
2472          ["Invert marks" gnus-uu-invert-processable t]
2473          ["Mark above" gnus-uu-mark-over t]
2474          ["Mark series" gnus-uu-mark-series t]
2475          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2476          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2477          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2478          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2479          ["Mark all" gnus-uu-mark-all t]
2480          ["Mark buffer" gnus-uu-mark-buffer t]
2481          ["Mark sparse" gnus-uu-mark-sparse t]
2482          ["Mark thread" gnus-uu-mark-thread t]
2483          ["Unmark thread" gnus-uu-unmark-thread t]
2484          ("Process Mark Sets"
2485           ["Kill" gnus-summary-kill-process-mark t]
2486           ["Yank" gnus-summary-yank-process-mark
2487            gnus-newsgroup-process-stack]
2488           ["Save" gnus-summary-save-process-mark t]
2489           ["Run command on marked..." gnus-summary-universal-argument t]))
2490         ("Scroll article"
2491          ["Page forward" gnus-summary-next-page
2492           ,@(if (featurep 'xemacs) '(t)
2493               '(:help "Show next page of article"))]
2494          ["Page backward" gnus-summary-prev-page
2495           ,@(if (featurep 'xemacs) '(t)
2496               '(:help "Show previous page of article"))]
2497          ["Line forward" gnus-summary-scroll-up t])
2498         ("Move"
2499          ["Next unread article" gnus-summary-next-unread-article t]
2500          ["Previous unread article" gnus-summary-prev-unread-article t]
2501          ["Next article" gnus-summary-next-article t]
2502          ["Previous article" gnus-summary-prev-article t]
2503          ["Next unread subject" gnus-summary-next-unread-subject t]
2504          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2505          ["Next article same subject" gnus-summary-next-same-subject t]
2506          ["Previous article same subject" gnus-summary-prev-same-subject t]
2507          ["First unread article" gnus-summary-first-unread-article t]
2508          ["Best unread article" gnus-summary-best-unread-article t]
2509          ["Go to subject number..." gnus-summary-goto-subject t]
2510          ["Go to article number..." gnus-summary-goto-article t]
2511          ["Go to the last article" gnus-summary-goto-last-article t]
2512          ["Pop article off history" gnus-summary-pop-article t])
2513         ("Sort"
2514          ["Sort by number" gnus-summary-sort-by-number t]
2515          ["Sort by author" gnus-summary-sort-by-author t]
2516          ["Sort by subject" gnus-summary-sort-by-subject t]
2517          ["Sort by date" gnus-summary-sort-by-date t]
2518          ["Sort by score" gnus-summary-sort-by-score t]
2519          ["Sort by lines" gnus-summary-sort-by-lines t]
2520          ["Sort by characters" gnus-summary-sort-by-chars t]
2521          ["Randomize" gnus-summary-sort-by-random t]
2522          ["Original sort" gnus-summary-sort-by-original t])
2523         ("Help"
2524          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2525          ["Describe group" gnus-summary-describe-group t]
2526          ["Fetch charter" gnus-group-fetch-charter
2527           ,@(if (featurep 'xemacs) nil
2528               '(:help "Display the charter of the current group"))]
2529          ["Fetch control message" gnus-group-fetch-control
2530           ,@(if (featurep 'xemacs) nil
2531               '(:help "Display the archived control message for the current group"))]
2532          ["Read manual" gnus-info-find-node t])
2533         ("Modes"
2534          ["Pick and read" gnus-pick-mode t]
2535          ["Binary" gnus-binary-mode t])
2536         ("Regeneration"
2537          ["Regenerate" gnus-summary-prepare t]
2538          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2539          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2540          ["Toggle threading" gnus-summary-toggle-threads t])
2541         ["See old articles" gnus-summary-insert-old-articles t]
2542         ["See new articles" gnus-summary-insert-new-articles t]
2543         ["Filter articles..." gnus-summary-execute-command t]
2544         ["Run command on articles..." gnus-summary-universal-argument t]
2545         ["Search articles forward..." gnus-summary-search-article-forward t]
2546         ["Search articles backward..." gnus-summary-search-article-backward t]
2547         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2548         ["Expand window" gnus-summary-expand-window t]
2549         ["Expire expirable articles" gnus-summary-expire-articles
2550          (gnus-check-backend-function
2551           'request-expire-articles gnus-newsgroup-name)]
2552         ["Edit local kill file" gnus-summary-edit-local-kill t]
2553         ["Edit main kill file" gnus-summary-edit-global-kill t]
2554         ["Edit group parameters" gnus-summary-edit-parameters t]
2555         ["Customize group parameters" gnus-summary-customize-parameters t]
2556         ["Send a bug report" gnus-bug t]
2557         ("Exit"
2558          ["Catchup and exit" gnus-summary-catchup-and-exit
2559           ,@(if (featurep 'xemacs) '(t)
2560               '(:help "Mark unread articles in this group as read, then exit"))]
2561          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2562          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2563          ["Exit group" gnus-summary-exit
2564           ,@(if (featurep 'xemacs) '(t)
2565               '(:help "Exit current group, return to group selection mode"))]
2566          ["Exit group without updating" gnus-summary-exit-no-update t]
2567          ["Exit and goto next group" gnus-summary-next-group t]
2568          ["Exit and goto prev group" gnus-summary-prev-group t]
2569          ["Reselect group" gnus-summary-reselect-current-group t]
2570          ["Rescan group" gnus-summary-rescan-group t]
2571          ["Update dribble" gnus-summary-save-newsrc t])))
2572
2573     (gnus-run-hooks 'gnus-summary-menu-hook)))
2574
2575 (defvar gnus-summary-tool-bar-map nil)
2576
2577 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2578 (defun gnus-summary-make-tool-bar ()
2579   (if (and (fboundp 'tool-bar-add-item-from-menu)
2580            (default-value 'tool-bar-mode)
2581            (not gnus-summary-tool-bar-map))
2582       (setq gnus-summary-tool-bar-map
2583             (let ((tool-bar-map (make-sparse-keymap))
2584                   (load-path (mm-image-load-path)))
2585               (tool-bar-add-item-from-menu
2586                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2587               (tool-bar-add-item-from-menu
2588                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2589               (tool-bar-add-item-from-menu
2590                'gnus-summary-post-news "post" gnus-summary-mode-map)
2591               (tool-bar-add-item-from-menu
2592                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2593               (tool-bar-add-item-from-menu
2594                'gnus-summary-followup "followup" gnus-summary-mode-map)
2595               (tool-bar-add-item-from-menu
2596                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2597               (tool-bar-add-item-from-menu
2598                'gnus-summary-reply "reply" gnus-summary-mode-map)
2599               (tool-bar-add-item-from-menu
2600                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2601               (tool-bar-add-item-from-menu
2602                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2603               (tool-bar-add-item-from-menu
2604                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2605               (tool-bar-add-item-from-menu
2606                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2607               (tool-bar-add-item-from-menu
2608                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2609               (tool-bar-add-item-from-menu
2610                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2611               (tool-bar-add-item-from-menu
2612                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2613               (tool-bar-add-item-from-menu
2614                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2615               (tool-bar-add-item-from-menu
2616                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2617               tool-bar-map)))
2618   (if gnus-summary-tool-bar-map
2619       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2620
2621 (defun gnus-score-set-default (var value)
2622   "A version of set that updates the GNU Emacs menu-bar."
2623   (set var value)
2624   ;; It is the message that forces the active status to be updated.
2625   (message ""))
2626
2627 (defun gnus-make-score-map (type)
2628   "Make a summary score map of type TYPE."
2629   (if t
2630       nil
2631     (let ((headers '(("author" "from" string)
2632                      ("subject" "subject" string)
2633                      ("article body" "body" string)
2634                      ("article head" "head" string)
2635                      ("xref" "xref" string)
2636                      ("extra header" "extra" string)
2637                      ("lines" "lines" number)
2638                      ("followups to author" "followup" string)))
2639           (types '((number ("less than" <)
2640                            ("greater than" >)
2641                            ("equal" =))
2642                    (string ("substring" s)
2643                            ("exact string" e)
2644                            ("fuzzy string" f)
2645                            ("regexp" r))))
2646           (perms '(("temporary" (current-time-string))
2647                    ("permanent" nil)
2648                    ("immediate" now)))
2649           header)
2650       (list
2651        (apply
2652         'nconc
2653         (list
2654          (if (eq type 'lower)
2655              "Lower score"
2656            "Increase score"))
2657         (let (outh)
2658           (while headers
2659             (setq header (car headers))
2660             (setq outh
2661                   (cons
2662                    (apply
2663                     'nconc
2664                     (list (car header))
2665                     (let ((ts (cdr (assoc (nth 2 header) types)))
2666                           outt)
2667                       (while ts
2668                         (setq outt
2669                               (cons
2670                                (apply
2671                                 'nconc
2672                                 (list (caar ts))
2673                                 (let ((ps perms)
2674                                       outp)
2675                                   (while ps
2676                                     (setq outp
2677                                           (cons
2678                                            (vector
2679                                             (caar ps)
2680                                             (list
2681                                              'gnus-summary-score-entry
2682                                              (nth 1 header)
2683                                              (if (or (string= (nth 1 header)
2684                                                               "head")
2685                                                      (string= (nth 1 header)
2686                                                               "body"))
2687                                                  ""
2688                                                (list 'gnus-summary-header
2689                                                      (nth 1 header)))
2690                                              (list 'quote (nth 1 (car ts)))
2691                                              (list 'gnus-score-delta-default
2692                                                    nil)
2693                                              (nth 1 (car ps))
2694                                              t)
2695                                             t)
2696                                            outp))
2697                                     (setq ps (cdr ps)))
2698                                   (list (nreverse outp))))
2699                                outt))
2700                         (setq ts (cdr ts)))
2701                       (list (nreverse outt))))
2702                    outh))
2703             (setq headers (cdr headers)))
2704           (list (nreverse outh))))))))
2705
2706 \f
2707
2708 (defun gnus-summary-mode (&optional group)
2709   "Major mode for reading articles.
2710
2711 All normal editing commands are switched off.
2712 \\<gnus-summary-mode-map>
2713 Each line in this buffer represents one article.  To read an
2714 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2715 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2716 respectively.
2717
2718 You can also post articles and send mail from this buffer.  To
2719 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2720 of an article, type `\\[gnus-summary-reply]'.
2721
2722 There are approx. one gazillion commands you can execute in this
2723 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2724
2725 The following commands are available:
2726
2727 \\{gnus-summary-mode-map}"
2728   (interactive)
2729   (kill-all-local-variables)
2730   (when (gnus-visual-p 'summary-menu 'menu)
2731     (gnus-summary-make-menu-bar)
2732     (gnus-summary-make-tool-bar))
2733   (gnus-summary-make-local-variables)
2734   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2735     (gnus-summary-make-local-variables))
2736   (gnus-make-thread-indent-array)
2737   (gnus-simplify-mode-line)
2738   (setq major-mode 'gnus-summary-mode)
2739   (setq mode-name "Summary")
2740   (make-local-variable 'minor-mode-alist)
2741   (use-local-map gnus-summary-mode-map)
2742   (buffer-disable-undo)
2743   (setq buffer-read-only t              ;Disable modification
2744         show-trailing-whitespace nil)
2745   (setq truncate-lines t)
2746   (setq selective-display t)
2747   (setq selective-display-ellipses t)   ;Display `...'
2748   (gnus-summary-set-display-table)
2749   (gnus-set-default-directory)
2750   (setq gnus-newsgroup-name group)
2751   (unless (gnus-news-group-p group)
2752     (setq gnus-newsgroup-incorporated
2753           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2754   (make-local-variable 'gnus-summary-line-format)
2755   (make-local-variable 'gnus-summary-line-format-spec)
2756   (make-local-variable 'gnus-summary-dummy-line-format)
2757   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2758   (make-local-variable 'gnus-summary-mark-positions)
2759   (gnus-make-local-hook 'pre-command-hook)
2760   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2761   (gnus-run-hooks 'gnus-summary-mode-hook)
2762   (turn-on-gnus-mailing-list-mode)
2763   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2764   (gnus-update-summary-mark-positions))
2765
2766 (defun gnus-summary-make-local-variables ()
2767   "Make all the local summary buffer variables."
2768   (let (global)
2769     (dolist (local gnus-summary-local-variables)
2770       (if (consp local)
2771           (progn
2772             (if (eq (cdr local) 'global)
2773                 ;; Copy the global value of the variable.
2774                 (setq global (symbol-value (car local)))
2775               ;; Use the value from the list.
2776               (setq global (eval (cdr local))))
2777             (set (make-local-variable (car local)) global))
2778         ;; Simple nil-valued local variable.
2779         (set (make-local-variable local) nil)))))
2780
2781 (defun gnus-summary-clear-local-variables ()
2782   (let ((locals gnus-summary-local-variables))
2783     (while locals
2784       (if (consp (car locals))
2785           (and (vectorp (caar locals))
2786                (set (caar locals) nil))
2787         (and (vectorp (car locals))
2788              (set (car locals) nil)))
2789       (setq locals (cdr locals)))))
2790
2791 ;; Summary data functions.
2792
2793 (defmacro gnus-data-number (data)
2794   `(car ,data))
2795
2796 (defmacro gnus-data-set-number (data number)
2797   `(setcar ,data ,number))
2798
2799 (defmacro gnus-data-mark (data)
2800   `(nth 1 ,data))
2801
2802 (defmacro gnus-data-set-mark (data mark)
2803   `(setcar (nthcdr 1 ,data) ,mark))
2804
2805 (defmacro gnus-data-pos (data)
2806   `(nth 2 ,data))
2807
2808 (defmacro gnus-data-set-pos (data pos)
2809   `(setcar (nthcdr 2 ,data) ,pos))
2810
2811 (defmacro gnus-data-header (data)
2812   `(nth 3 ,data))
2813
2814 (defmacro gnus-data-set-header (data header)
2815   `(setcar (nthcdr 3 ,data) ,header))
2816
2817 (defmacro gnus-data-level (data)
2818   `(nth 4 ,data))
2819
2820 (defmacro gnus-data-unread-p (data)
2821   `(= (nth 1 ,data) gnus-unread-mark))
2822
2823 (defmacro gnus-data-read-p (data)
2824   `(/= (nth 1 ,data) gnus-unread-mark))
2825
2826 (defmacro gnus-data-pseudo-p (data)
2827   `(consp (nth 3 ,data)))
2828
2829 (defmacro gnus-data-find (number)
2830   `(assq ,number gnus-newsgroup-data))
2831
2832 (defmacro gnus-data-find-list (number &optional data)
2833   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2834      (memq (assq ,number bdata)
2835            bdata)))
2836
2837 (defmacro gnus-data-make (number mark pos header level)
2838   `(list ,number ,mark ,pos ,header ,level))
2839
2840 (defun gnus-data-enter (after-article number mark pos header level offset)
2841   (let ((data (gnus-data-find-list after-article)))
2842     (unless data
2843       (error "No such article: %d" after-article))
2844     (setcdr data (cons (gnus-data-make number mark pos header level)
2845                        (cdr data)))
2846     (setq gnus-newsgroup-data-reverse nil)
2847     (gnus-data-update-list (cddr data) offset)))
2848
2849 (defun gnus-data-enter-list (after-article list &optional offset)
2850   (when list
2851     (let ((data (and after-article (gnus-data-find-list after-article)))
2852           (ilist list))
2853       (if (not (or data
2854                    after-article))
2855           (let ((odata gnus-newsgroup-data))
2856             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2857             (when offset
2858               (gnus-data-update-list odata offset)))
2859         ;; Find the last element in the list to be spliced into the main
2860         ;; list.
2861         (setq list (last list))
2862         (if (not data)
2863             (progn
2864               (setcdr list gnus-newsgroup-data)
2865               (setq gnus-newsgroup-data ilist)
2866               (when offset
2867                 (gnus-data-update-list (cdr list) offset)))
2868           (setcdr list (cdr data))
2869           (setcdr data ilist)
2870           (when offset
2871             (gnus-data-update-list (cdr list) offset))))
2872       (setq gnus-newsgroup-data-reverse nil))))
2873
2874 (defun gnus-data-remove (article &optional offset)
2875   (let ((data gnus-newsgroup-data))
2876     (if (= (gnus-data-number (car data)) article)
2877         (progn
2878           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2879                 gnus-newsgroup-data-reverse nil)
2880           (when offset
2881             (gnus-data-update-list gnus-newsgroup-data offset)))
2882       (while (cdr data)
2883         (when (= (gnus-data-number (cadr data)) article)
2884           (setcdr data (cddr data))
2885           (when offset
2886             (gnus-data-update-list (cdr data) offset))
2887           (setq data nil
2888                 gnus-newsgroup-data-reverse nil))
2889         (setq data (cdr data))))))
2890
2891 (defmacro gnus-data-list (backward)
2892   `(if ,backward
2893        (or gnus-newsgroup-data-reverse
2894            (setq gnus-newsgroup-data-reverse
2895                  (reverse gnus-newsgroup-data)))
2896      gnus-newsgroup-data))
2897
2898 (defun gnus-data-update-list (data offset)
2899   "Add OFFSET to the POS of all data entries in DATA."
2900   (setq gnus-newsgroup-data-reverse nil)
2901   (while data
2902     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2903     (setq data (cdr data))))
2904
2905 (defun gnus-summary-article-pseudo-p (article)
2906   "Say whether this article is a pseudo article or not."
2907   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2908
2909 (defmacro gnus-summary-article-sparse-p (article)
2910   "Say whether this article is a sparse article or not."
2911   `(memq ,article gnus-newsgroup-sparse))
2912
2913 (defmacro gnus-summary-article-ancient-p (article)
2914   "Say whether this article is a sparse article or not."
2915   `(memq ,article gnus-newsgroup-ancient))
2916
2917 (defun gnus-article-parent-p (number)
2918   "Say whether this article is a parent or not."
2919   (let ((data (gnus-data-find-list number)))
2920     (and (cdr data)                     ; There has to be an article after...
2921          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2922             (gnus-data-level (nth 1 data))))))
2923
2924 (defun gnus-article-children (number)
2925   "Return a list of all children to NUMBER."
2926   (let* ((data (gnus-data-find-list number))
2927          (level (gnus-data-level (car data)))
2928          children)
2929     (setq data (cdr data))
2930     (while (and data
2931                 (= (gnus-data-level (car data)) (1+ level)))
2932       (push (gnus-data-number (car data)) children)
2933       (setq data (cdr data)))
2934     children))
2935
2936 (defmacro gnus-summary-skip-intangible ()
2937   "If the current article is intangible, then jump to a different article."
2938   '(let ((to (get-text-property (point) 'gnus-intangible)))
2939      (and to (gnus-summary-goto-subject to))))
2940
2941 (defmacro gnus-summary-article-intangible-p ()
2942   "Say whether this article is intangible or not."
2943   '(get-text-property (point) 'gnus-intangible))
2944
2945 (defun gnus-article-read-p (article)
2946   "Say whether ARTICLE is read or not."
2947   (not (or (memq article gnus-newsgroup-marked)
2948            (memq article gnus-newsgroup-spam-marked)
2949            (memq article gnus-newsgroup-unreads)
2950            (memq article gnus-newsgroup-unselected)
2951            (memq article gnus-newsgroup-dormant))))
2952
2953 ;; Some summary mode macros.
2954
2955 (defmacro gnus-summary-article-number ()
2956   "The article number of the article on the current line.
2957 If there isn't an article number here, then we return the current
2958 article number."
2959   '(progn
2960      (gnus-summary-skip-intangible)
2961      (or (get-text-property (point) 'gnus-number)
2962          (gnus-summary-last-subject))))
2963
2964 (defmacro gnus-summary-article-header (&optional number)
2965   "Return the header of article NUMBER."
2966   `(gnus-data-header (gnus-data-find
2967                       ,(or number '(gnus-summary-article-number)))))
2968
2969 (defmacro gnus-summary-thread-level (&optional number)
2970   "Return the level of thread that starts with article NUMBER."
2971   `(if (and (eq gnus-summary-make-false-root 'dummy)
2972             (get-text-property (point) 'gnus-intangible))
2973        0
2974      (gnus-data-level (gnus-data-find
2975                        ,(or number '(gnus-summary-article-number))))))
2976
2977 (defmacro gnus-summary-article-mark (&optional number)
2978   "Return the mark of article NUMBER."
2979   `(gnus-data-mark (gnus-data-find
2980                     ,(or number '(gnus-summary-article-number)))))
2981
2982 (defmacro gnus-summary-article-pos (&optional number)
2983   "Return the position of the line of article NUMBER."
2984   `(gnus-data-pos (gnus-data-find
2985                    ,(or number '(gnus-summary-article-number)))))
2986
2987 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2988 (defmacro gnus-summary-article-subject (&optional number)
2989   "Return current subject string or nil if nothing."
2990   `(let ((headers
2991           ,(if number
2992                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2993              '(gnus-data-header (assq (gnus-summary-article-number)
2994                                       gnus-newsgroup-data)))))
2995      (and headers
2996           (vectorp headers)
2997           (mail-header-subject headers))))
2998
2999 (defmacro gnus-summary-article-score (&optional number)
3000   "Return current article score."
3001   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3002                   gnus-newsgroup-scored))
3003        gnus-summary-default-score 0))
3004
3005 (defun gnus-summary-article-children (&optional number)
3006   "Return a list of article numbers that are children of article NUMBER."
3007   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3008          (level (gnus-data-level (car data)))
3009          l children)
3010     (while (and (setq data (cdr data))
3011                 (> (setq l (gnus-data-level (car data))) level))
3012       (and (= (1+ level) l)
3013            (push (gnus-data-number (car data))
3014                  children)))
3015     (nreverse children)))
3016
3017 (defun gnus-summary-article-parent (&optional number)
3018   "Return the article number of the parent of article NUMBER."
3019   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3020                                     (gnus-data-list t)))
3021          (level (gnus-data-level (car data))))
3022     (if (zerop level)
3023         ()                              ; This is a root.
3024       ;; We search until we find an article with a level less than
3025       ;; this one.  That function has to be the parent.
3026       (while (and (setq data (cdr data))
3027                   (not (< (gnus-data-level (car data)) level))))
3028       (and data (gnus-data-number (car data))))))
3029
3030 (defun gnus-unread-mark-p (mark)
3031   "Say whether MARK is the unread mark."
3032   (= mark gnus-unread-mark))
3033
3034 (defun gnus-read-mark-p (mark)
3035   "Say whether MARK is one of the marks that mark as read.
3036 This is all marks except unread, ticked, dormant, and expirable."
3037   (not (or (= mark gnus-unread-mark)
3038            (= mark gnus-ticked-mark)
3039            (= mark gnus-spam-mark)
3040            (= mark gnus-dormant-mark)
3041            (= mark gnus-expirable-mark))))
3042
3043 (defmacro gnus-article-mark (number)
3044   "Return the MARK of article NUMBER.
3045 This macro should only be used when computing the mark the \"first\"
3046 time; i.e., when generating the summary lines.  After that,
3047 `gnus-summary-article-mark' should be used to examine the
3048 marks of articles."
3049   `(cond
3050     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3051     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3052     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3053     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3054     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3055     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3056     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3057     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3058            gnus-ancient-mark))))
3059
3060 ;; Saving hidden threads.
3061
3062 (defmacro gnus-save-hidden-threads (&rest forms)
3063   "Save hidden threads, eval FORMS, and restore the hidden threads."
3064   (let ((config (make-symbol "config")))
3065     `(let ((,config (gnus-hidden-threads-configuration)))
3066        (unwind-protect
3067            (save-excursion
3068              ,@forms)
3069          (gnus-restore-hidden-threads-configuration ,config)))))
3070 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3071 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3072
3073 (defun gnus-data-compute-positions ()
3074   "Compute the positions of all articles."
3075   (setq gnus-newsgroup-data-reverse nil)
3076   (let ((data gnus-newsgroup-data))
3077     (save-excursion
3078       (gnus-save-hidden-threads
3079         (gnus-summary-show-all-threads)
3080         (goto-char (point-min))
3081         (while data
3082           (while (get-text-property (point) 'gnus-intangible)
3083             (forward-line 1))
3084           (gnus-data-set-pos (car data) (+ (point) 3))
3085           (setq data (cdr data))
3086           (forward-line 1))))))
3087
3088 (defun gnus-hidden-threads-configuration ()
3089   "Return the current hidden threads configuration."
3090   (save-excursion
3091     (let (config)
3092       (goto-char (point-min))
3093       (while (search-forward "\r" nil t)
3094         (push (1- (point)) config))
3095       config)))
3096
3097 (defun gnus-restore-hidden-threads-configuration (config)
3098   "Restore hidden threads configuration from CONFIG."
3099   (save-excursion
3100     (let (point buffer-read-only)
3101       (while (setq point (pop config))
3102         (when (and (< point (point-max))
3103                    (goto-char point)
3104                    (eq (char-after) ?\n))
3105           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3106
3107 ;; Various summary mode internalish functions.
3108
3109 (defun gnus-mouse-pick-article (e)
3110   (interactive "e")
3111   (mouse-set-point e)
3112   (gnus-summary-next-page nil t))
3113
3114 (defun gnus-summary-set-display-table ()
3115   "Change the display table.
3116 Odd characters have a tendency to mess
3117 up nicely formatted displays - we make all possible glyphs
3118 display only a single character."
3119
3120   ;; We start from the standard display table, if any.
3121   (let ((table (or (copy-sequence standard-display-table)
3122                    (make-display-table)))
3123         (i 32))
3124     ;; Nix out all the control chars...
3125     (while (>= (setq i (1- i)) 0)
3126       (aset table i [??]))
3127     ;; ... but not newline and cr, of course.  (cr is necessary for the
3128     ;; selective display).
3129     (aset table ?\n nil)
3130     (aset table ?\r nil)
3131     ;; We keep TAB as well.
3132     (aset table ?\t nil)
3133     ;; We nix out any glyphs over 126 that are not set already.
3134     (let ((i 256))
3135       (while (>= (setq i (1- i)) 127)
3136         ;; Only modify if the entry is nil.
3137         (unless (aref table i)
3138           (aset table i [??]))))
3139     (setq buffer-display-table table)))
3140
3141 (defun gnus-summary-set-article-display-arrow (pos)
3142   "Update the overlay arrow to point to line at position POS."
3143   (when (and gnus-summary-display-arrow
3144              (boundp 'overlay-arrow-position)
3145              (boundp 'overlay-arrow-string))
3146     (save-excursion
3147       (goto-char pos)
3148       (beginning-of-line)
3149       (unless overlay-arrow-position
3150         (setq overlay-arrow-position (make-marker)))
3151       (setq overlay-arrow-string "=>"
3152             overlay-arrow-position (set-marker overlay-arrow-position
3153                                                (point)
3154                                                (current-buffer))))))
3155
3156 (defun gnus-summary-setup-buffer (group)
3157   "Initialize summary buffer."
3158   (let ((buffer (gnus-summary-buffer-name group))
3159         (dead-name (concat "*Dead Summary "
3160                            (gnus-group-decoded-name group) "*")))
3161     ;; If a dead summary buffer exists, we kill it.
3162     (when (gnus-buffer-live-p dead-name)
3163       (gnus-kill-buffer dead-name))
3164     (if (get-buffer buffer)
3165         (progn
3166           (set-buffer buffer)
3167           (setq gnus-summary-buffer (current-buffer))
3168           (not gnus-newsgroup-prepared))
3169       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3170       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3171       (gnus-summary-mode group)
3172       (when gnus-carpal
3173         (gnus-carpal-setup-buffer 'summary))
3174       (unless gnus-single-article-buffer
3175         (make-local-variable 'gnus-article-buffer)
3176         (make-local-variable 'gnus-article-current)
3177         (make-local-variable 'gnus-original-article-buffer))
3178       (setq gnus-newsgroup-name group)
3179       ;; Set any local variables in the group parameters.
3180       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3181       t)))
3182
3183 (defun gnus-set-global-variables ()
3184   "Set the global equivalents of the buffer-local variables.
3185 They are set to the latest values they had.  These reflect the summary
3186 buffer that was in action when the last article was fetched."
3187   (when (eq major-mode 'gnus-summary-mode)
3188     (setq gnus-summary-buffer (current-buffer))
3189     (let ((name gnus-newsgroup-name)
3190           (marked gnus-newsgroup-marked)
3191           (spam gnus-newsgroup-spam-marked)
3192           (unread gnus-newsgroup-unreads)
3193           (headers gnus-current-headers)
3194           (data gnus-newsgroup-data)
3195           (summary gnus-summary-buffer)
3196           (article-buffer gnus-article-buffer)
3197           (original gnus-original-article-buffer)
3198           (gac gnus-article-current)
3199           (reffed gnus-reffed-article-number)
3200           (score-file gnus-current-score-file)
3201           (default-charset gnus-newsgroup-charset)
3202           vlist)
3203       (let ((locals gnus-newsgroup-variables))
3204         (while locals
3205           (if (consp (car locals))
3206               (push (eval (caar locals)) vlist)
3207             (push (eval (car locals)) vlist))
3208           (setq locals (cdr locals)))
3209         (setq vlist (nreverse vlist)))
3210       (with-current-buffer gnus-group-buffer
3211         (setq gnus-newsgroup-name name
3212               gnus-newsgroup-marked marked
3213               gnus-newsgroup-spam-marked spam
3214               gnus-newsgroup-unreads unread
3215               gnus-current-headers headers
3216               gnus-newsgroup-data data
3217               gnus-article-current gac
3218               gnus-summary-buffer summary
3219               gnus-article-buffer article-buffer
3220               gnus-original-article-buffer original
3221               gnus-reffed-article-number reffed
3222               gnus-current-score-file score-file
3223               gnus-newsgroup-charset default-charset)
3224         (let ((locals gnus-newsgroup-variables))
3225           (while locals
3226             (if (consp (car locals))
3227                 (set (caar locals) (pop vlist))
3228               (set (car locals) (pop vlist)))
3229             (setq locals (cdr locals))))
3230         ;; The article buffer also has local variables.
3231         (when (gnus-buffer-live-p gnus-article-buffer)
3232           (set-buffer gnus-article-buffer)
3233           (setq gnus-summary-buffer summary))))))
3234
3235 (defun gnus-summary-article-unread-p (article)
3236   "Say whether ARTICLE is unread or not."
3237   (memq article gnus-newsgroup-unreads))
3238
3239 (defun gnus-summary-first-article-p (&optional article)
3240   "Return whether ARTICLE is the first article in the buffer."
3241   (if (not (setq article (or article (gnus-summary-article-number))))
3242       nil
3243     (eq article (caar gnus-newsgroup-data))))
3244
3245 (defun gnus-summary-last-article-p (&optional article)
3246   "Return whether ARTICLE is the last article in the buffer."
3247   (if (not (setq article (or article (gnus-summary-article-number))))
3248       ;; All non-existent numbers are the last article.  :-)
3249       t
3250     (not (cdr (gnus-data-find-list article)))))
3251
3252 (defun gnus-make-thread-indent-array ()
3253   (let ((n 200))
3254     (unless (and gnus-thread-indent-array
3255                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3256       (setq gnus-thread-indent-array (make-vector 201 "")
3257             gnus-thread-indent-array-level gnus-thread-indent-level)
3258       (while (>= n 0)
3259         (aset gnus-thread-indent-array n
3260               (make-string (* n gnus-thread-indent-level) ? ))
3261         (setq n (1- n))))))
3262
3263 (defun gnus-update-summary-mark-positions ()
3264   "Compute where the summary marks are to go."
3265   (save-excursion
3266     (when (gnus-buffer-exists-p gnus-summary-buffer)
3267       (set-buffer gnus-summary-buffer))
3268     (let ((gnus-replied-mark 129)
3269           (gnus-score-below-mark 130)
3270           (gnus-score-over-mark 130)
3271           (gnus-undownloaded-mark 131)
3272           (spec gnus-summary-line-format-spec)
3273           gnus-visual pos)
3274       (save-excursion
3275         (gnus-set-work-buffer)
3276         (let ((gnus-summary-line-format-spec spec)
3277               (gnus-newsgroup-downloadable '(0)))
3278           (gnus-summary-insert-line
3279            (make-full-mail-header 0 "" "nobody"
3280                                   "05 Apr 2001 23:33:09 +0400"
3281                                   "" "" 0 0 "" nil)
3282            0 nil t 128 t nil "" nil 1)
3283           (goto-char (point-min))
3284           (setq pos (list (cons 'unread
3285                                 (and (search-forward
3286                                       (string-as-multibyte "\200") nil t)
3287                                      (- (point) (point-min) 1)))))
3288           (goto-char (point-min))
3289           (push (cons 'replied (and (search-forward
3290                                      (string-as-multibyte "\201") nil t)
3291                                     (- (point) (point-min) 1)))
3292                 pos)
3293           (goto-char (point-min))
3294           (push (cons 'score (and (search-forward
3295                                    (string-as-multibyte "\202") nil t)
3296                                   (- (point) (point-min) 1)))
3297                 pos)
3298           (goto-char (point-min))
3299           (push (cons 'download (and (search-forward
3300                                       (string-as-multibyte "\203") nil t)
3301                                      (- (point) (point-min) 1)))
3302                 pos)))
3303       (setq gnus-summary-mark-positions pos))))
3304
3305 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3306   "Insert a dummy root in the summary buffer."
3307   (beginning-of-line)
3308   (gnus-add-text-properties
3309    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3310    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3311
3312 (defun gnus-summary-extract-address-component (from)
3313   (or (car (funcall gnus-extract-address-components from))
3314       from))
3315
3316 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3317   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3318                                 default-mime-charset)))
3319     ;; Is it really necessary to do this next part for each summary line?
3320     ;; Luckily, doesn't seem to slow things down much.
3321     (or
3322      (and gnus-ignored-from-addresses
3323           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3324           (let ((extra-headers (mail-header-extra header))
3325                 to
3326                 newsgroups)
3327             (cond
3328              ((setq to (cdr (assq 'To extra-headers)))
3329               (concat "-> "
3330                       (inline
3331                         (gnus-summary-extract-address-component
3332                          (funcall gnus-decode-encoded-word-function to)))))
3333              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3334               (concat "=> " newsgroups)))))
3335      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3336
3337 (defun gnus-summary-insert-line (gnus-tmp-header
3338                                  gnus-tmp-level gnus-tmp-current
3339                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3340                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3341                                  &optional gnus-tmp-dummy gnus-tmp-score
3342                                  gnus-tmp-process)
3343   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3344          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3345          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3346          (gnus-tmp-score-char
3347           (if (or (null gnus-summary-default-score)
3348                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3349                       gnus-summary-zcore-fuzz))
3350               ?\ ;;;Whitespace
3351             (if (< gnus-tmp-score gnus-summary-default-score)
3352                 gnus-score-below-mark gnus-score-over-mark)))
3353          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3354          (gnus-tmp-replied
3355           (cond (gnus-tmp-process gnus-process-mark)
3356                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3357                  gnus-cached-mark)
3358                 (gnus-tmp-replied gnus-replied-mark)
3359                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3360                  gnus-forwarded-mark)
3361                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3362                  gnus-saved-mark)
3363                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3364                  gnus-recent-mark)
3365                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3366                  gnus-unseen-mark)
3367                 (t gnus-no-mark)))
3368          (gnus-tmp-downloaded
3369           (cond (undownloaded
3370                  gnus-undownloaded-mark)
3371                 (gnus-newsgroup-agentized
3372                  gnus-downloaded-mark)
3373                 (t
3374                  gnus-no-mark)))
3375          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3376          (gnus-tmp-name
3377           (cond
3378            ((string-match "<[^>]+> *$" gnus-tmp-from)
3379             (let ((beg (match-beginning 0)))
3380               (or (and (string-match "^\".+\"" gnus-tmp-from)
3381                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3382                   (substring gnus-tmp-from 0 beg))))
3383            ((string-match "(.+)" gnus-tmp-from)
3384             (substring gnus-tmp-from
3385                        (1+ (match-beginning 0)) (1- (match-end 0))))
3386            (t gnus-tmp-from)))
3387          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3388          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3389          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3390          (buffer-read-only nil))
3391     (when (string= gnus-tmp-name "")
3392       (setq gnus-tmp-name gnus-tmp-from))
3393     (unless (numberp gnus-tmp-lines)
3394       (setq gnus-tmp-lines -1))
3395     (if (= gnus-tmp-lines -1)
3396         (setq gnus-tmp-lines "?")
3397       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3398     (gnus-put-text-property-excluding-characters-with-faces
3399      (point)
3400      (progn (eval gnus-summary-line-format-spec) (point))
3401      'gnus-number gnus-tmp-number)
3402     (when (gnus-visual-p 'summary-highlight 'highlight)
3403       (forward-line -1)
3404       (gnus-run-hooks 'gnus-summary-update-hook)
3405       (forward-line 1))))
3406
3407 (defun gnus-summary-update-line (&optional dont-update)
3408   "Update summary line after change."
3409   (when (and gnus-summary-default-score
3410              (not gnus-summary-inhibit-highlight))
3411     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3412            (article (gnus-summary-article-number))
3413            (score (gnus-summary-article-score article)))
3414       (unless dont-update
3415         (if (and gnus-summary-mark-below
3416                  (< (gnus-summary-article-score)
3417                     gnus-summary-mark-below))
3418             ;; This article has a low score, so we mark it as read.
3419             (when (memq article gnus-newsgroup-unreads)
3420               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3421           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3422             ;; This article was previously marked as read on account
3423             ;; of a low score, but now it has risen, so we mark it as
3424             ;; unread.
3425             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3426         (gnus-summary-update-mark
3427          (if (or (null gnus-summary-default-score)
3428                  (<= (abs (- score gnus-summary-default-score))
3429                      gnus-summary-zcore-fuzz))
3430              ?\ ;;;Whitespace
3431            (if (< score gnus-summary-default-score)
3432                gnus-score-below-mark gnus-score-over-mark))
3433          'score))
3434       ;; Do visual highlighting.
3435       (when (gnus-visual-p 'summary-highlight 'highlight)
3436         (gnus-run-hooks 'gnus-summary-update-hook)))))
3437
3438 (defvar gnus-tmp-new-adopts nil)
3439
3440 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3441   "Return the number of articles in THREAD.
3442 This may be 0 in some cases -- if none of the articles in
3443 the thread are to be displayed."
3444   (let* ((number
3445           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3446           (cond
3447            ((not (listp thread))
3448             1)
3449            ((and (consp thread) (cdr thread))
3450             (apply
3451              '+ 1 (mapcar
3452                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3453            ((null thread)
3454             1)
3455            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3456             1)
3457            (t 0))))
3458     (when (and level (zerop level) gnus-tmp-new-adopts)
3459       (incf number
3460             (apply '+ (mapcar
3461                        'gnus-summary-number-of-articles-in-thread
3462                        gnus-tmp-new-adopts))))
3463     (if char
3464         (if (> number 1) gnus-not-empty-thread-mark
3465           gnus-empty-thread-mark)
3466       number)))
3467
3468 (defsubst gnus-summary-line-message-size (head)
3469   "Return pretty-printed version of message size.
3470 This function is intended to be used in
3471 `gnus-summary-line-format-alist'."
3472   (let ((c (or (mail-header-chars head) -1)))
3473     (cond ((< c 0) "n/a")               ; chars not available
3474           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3475           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3476           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3477           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3478
3479
3480 (defun gnus-summary-set-local-parameters (group)
3481   "Go through the local params of GROUP and set all variable specs in that list."
3482   (let ((vars '(quit-config)))          ; Ignore quit-config.
3483     (dolist (elem (gnus-group-find-parameter group))
3484       (and (consp elem)                 ; Has to be a cons.
3485            (consp (cdr elem))           ; The cdr has to be a list.
3486            (symbolp (car elem))         ; Has to be a symbol in there.
3487            (not (memq (car elem) vars))
3488            (ignore-errors               ; So we set it.
3489              (push (car elem) vars)
3490              (make-local-variable (car elem))
3491              (set (car elem) (eval (nth 1 elem))))))))
3492
3493 (defun gnus-summary-read-group (group &optional show-all no-article
3494                                       kill-buffer no-display backward
3495                                       select-articles)
3496   "Start reading news in newsgroup GROUP.
3497 If SHOW-ALL is non-nil, already read articles are also listed.
3498 If NO-ARTICLE is non-nil, no article is selected initially.
3499 If NO-DISPLAY, don't generate a summary buffer."
3500   (let (result)
3501     (while (and group
3502                 (null (setq result
3503                             (let ((gnus-auto-select-next nil))
3504                               (or (gnus-summary-read-group-1
3505                                    group show-all no-article
3506                                    kill-buffer no-display
3507                                    select-articles)
3508                                   (setq show-all nil
3509                                         select-articles nil)))))
3510                 (eq gnus-auto-select-next 'quietly))
3511       (set-buffer gnus-group-buffer)
3512       ;; The entry function called above goes to the next
3513       ;; group automatically, so we go two groups back
3514       ;; if we are searching for the previous group.
3515       (when backward
3516         (gnus-group-prev-unread-group 2))
3517       (if (not (equal group (gnus-group-group-name)))
3518           (setq group (gnus-group-group-name))
3519         (setq group nil)))
3520     result))
3521
3522 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3523   "Directly jump to the other GROUP from summary buffer.
3524 If SHOW-ALL is non-nil, already read articles are also listed."
3525   (interactive
3526    (if (eq gnus-summary-buffer (current-buffer))
3527        (list (completing-read
3528               "Group: " gnus-active-hashtb nil t
3529               (when (and gnus-newsgroup-name
3530                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3531                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3532               'gnus-group-history)
3533              current-prefix-arg)
3534      (error "%s must be invoked from a gnus summary buffer." this-command)))
3535   (unless (or (zerop (length group))
3536               (and gnus-newsgroup-name
3537                    (string-equal gnus-newsgroup-name group)))
3538     (gnus-summary-exit)
3539     (gnus-summary-read-group group show-all
3540                              gnus-dont-select-after-jump-to-other-group)))
3541
3542 (defun gnus-summary-read-group-1 (group show-all no-article
3543                                         kill-buffer no-display
3544                                         &optional select-articles)
3545   ;; Killed foreign groups can't be entered.
3546   ;;  (when (and (not (gnus-group-native-p group))
3547   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3548   ;;    (error "Dead non-native groups can't be entered"))
3549   (gnus-message 5 "Retrieving newsgroup: %s..."
3550                 (gnus-group-decoded-name group))
3551   (let* ((new-group (gnus-summary-setup-buffer group))
3552          (quit-config (gnus-group-quit-config group))
3553          (did-select (and new-group (gnus-select-newsgroup
3554                                      group show-all select-articles))))
3555     (cond
3556      ;; This summary buffer exists already, so we just select it.
3557      ((not new-group)
3558       (gnus-set-global-variables)
3559       (when kill-buffer
3560         (gnus-kill-or-deaden-summary kill-buffer))
3561       (gnus-configure-windows 'summary 'force)
3562       (gnus-set-mode-line 'summary)
3563       (gnus-summary-position-point)
3564       (message "")
3565       t)
3566      ;; We couldn't select this group.
3567      ((null did-select)
3568       (when (and (eq major-mode 'gnus-summary-mode)
3569                  (not (equal (current-buffer) kill-buffer)))
3570         (kill-buffer (current-buffer))
3571         (if (not quit-config)
3572             (progn
3573               ;; Update the info -- marks might need to be removed,
3574               ;; for instance.
3575               (gnus-summary-update-info)
3576               (set-buffer gnus-group-buffer)
3577               (gnus-group-jump-to-group group)
3578               (gnus-group-next-unread-group 1))
3579           (gnus-handle-ephemeral-exit quit-config)))
3580       (let ((grpinfo (gnus-get-info group)))
3581         (if (null (gnus-info-read grpinfo))
3582             (gnus-message 3 "Group %s contains no messages"
3583                           (gnus-group-decoded-name group))
3584           (gnus-message 3 "Can't select group")))
3585       nil)
3586      ;; The user did a `C-g' while prompting for number of articles,
3587      ;; so we exit this group.
3588      ((eq did-select 'quit)
3589       (and (eq major-mode 'gnus-summary-mode)
3590            (not (equal (current-buffer) kill-buffer))
3591            (kill-buffer (current-buffer)))
3592       (when kill-buffer
3593         (gnus-kill-or-deaden-summary kill-buffer))
3594       (if (not quit-config)
3595           (progn
3596             (set-buffer gnus-group-buffer)
3597             (gnus-group-jump-to-group group)
3598             (gnus-group-next-unread-group 1)
3599             (gnus-configure-windows 'group 'force))
3600         (gnus-handle-ephemeral-exit quit-config))
3601       ;; Finally signal the quit.
3602       (signal 'quit nil))
3603      ;; The group was successfully selected.
3604      (t
3605       (gnus-set-global-variables)
3606       ;; Save the active value in effect when the group was entered.
3607       (setq gnus-newsgroup-active
3608             (gnus-copy-sequence
3609              (gnus-active gnus-newsgroup-name)))
3610       ;; You can change the summary buffer in some way with this hook.
3611       (gnus-run-hooks 'gnus-select-group-hook)
3612       (gnus-update-format-specifications
3613        nil 'summary 'summary-mode 'summary-dummy)
3614       (gnus-update-summary-mark-positions)
3615       ;; Do score processing.
3616       (when gnus-use-scoring
3617         (gnus-possibly-score-headers))
3618       ;; Check whether to fill in the gaps in the threads.
3619       (when gnus-build-sparse-threads
3620         (gnus-build-sparse-threads))
3621       ;; Find the initial limit.
3622       (if show-all
3623           (let ((gnus-newsgroup-dormant nil))
3624             (gnus-summary-initial-limit show-all))
3625         (gnus-summary-initial-limit show-all))
3626       ;; Generate the summary buffer.
3627       (unless no-display
3628         (gnus-summary-prepare))
3629       (when gnus-use-trees
3630         (gnus-tree-open group)
3631         (setq gnus-summary-highlight-line-function
3632               'gnus-tree-highlight-article))
3633       ;; If the summary buffer is empty, but there are some low-scored
3634       ;; articles or some excluded dormants, we include these in the
3635       ;; buffer.
3636       (when (and (zerop (buffer-size))
3637                  (not no-display))
3638         (cond (gnus-newsgroup-dormant
3639                (gnus-summary-limit-include-dormant))
3640               ((and gnus-newsgroup-scored show-all)
3641                (gnus-summary-limit-include-expunged t))))
3642       ;; Function `gnus-apply-kill-file' must be called in this hook.
3643       (gnus-run-hooks 'gnus-apply-kill-hook)
3644       (if (and (zerop (buffer-size))
3645                (not no-display))
3646           (progn
3647             ;; This newsgroup is empty.
3648             (gnus-summary-catchup-and-exit nil t)
3649             (gnus-message 6 "No unread news")
3650             (when kill-buffer
3651               (gnus-kill-or-deaden-summary kill-buffer))
3652             ;; Return nil from this function.
3653             nil)
3654         ;; Hide conversation thread subtrees.  We cannot do this in
3655         ;; gnus-summary-prepare-hook since kill processing may not
3656         ;; work with hidden articles.
3657         (gnus-summary-maybe-hide-threads)
3658         (when kill-buffer
3659           (gnus-kill-or-deaden-summary kill-buffer))
3660         (gnus-summary-auto-select-subject)
3661         ;; Show first unread article if requested.
3662         (if (and (not no-article)
3663                  (not no-display)
3664                  gnus-newsgroup-unreads
3665                  gnus-auto-select-first)
3666             (progn
3667               (gnus-configure-windows 'summary)
3668               (let ((art (gnus-summary-article-number)))
3669                 (unless (and (not gnus-plugged)
3670                              (or (memq art gnus-newsgroup-undownloaded)
3671                                  (memq art gnus-newsgroup-downloadable)))
3672                   (gnus-summary-goto-article art))))
3673           ;; Don't select any articles.
3674           (gnus-summary-position-point)
3675           (gnus-configure-windows 'summary 'force)
3676           (gnus-set-mode-line 'summary))
3677         (when (and gnus-auto-center-group
3678                    (get-buffer-window gnus-group-buffer t))
3679           ;; Gotta use windows, because recenter does weird stuff if
3680           ;; the current buffer ain't the displayed window.
3681           (let ((owin (selected-window)))
3682             (select-window (get-buffer-window gnus-group-buffer t))
3683             (when (gnus-group-goto-group group)
3684               (recenter))
3685             (select-window owin)))
3686         ;; Mark this buffer as "prepared".
3687         (setq gnus-newsgroup-prepared t)
3688         (gnus-run-hooks 'gnus-summary-prepared-hook)
3689         (unless (gnus-ephemeral-group-p group)
3690           (gnus-group-update-group group))
3691         t)))))
3692
3693 (defun gnus-summary-auto-select-subject ()
3694   "Select the subject line on initial group entry."
3695   (goto-char (point-min))
3696   (cond
3697    ((eq gnus-auto-select-subject 'best)
3698     (gnus-summary-best-unread-subject))
3699    ((eq gnus-auto-select-subject 'unread)
3700     (gnus-summary-first-unread-subject))
3701    ((eq gnus-auto-select-subject 'unseen)
3702     (gnus-summary-first-unseen-subject))
3703    ((eq gnus-auto-select-subject 'unseen-or-unread)
3704     (gnus-summary-first-unseen-or-unread-subject))
3705    ((eq gnus-auto-select-subject 'first)
3706     ;; Do nothing.
3707     )
3708    ((functionp gnus-auto-select-subject)
3709     (funcall gnus-auto-select-subject))))
3710
3711 (defun gnus-summary-prepare ()
3712   "Generate the summary buffer."
3713   (interactive)
3714   (let ((buffer-read-only nil))
3715     (erase-buffer)
3716     (setq gnus-newsgroup-data nil
3717           gnus-newsgroup-data-reverse nil)
3718     (gnus-run-hooks 'gnus-summary-generate-hook)
3719     ;; Generate the buffer, either with threads or without.
3720     (when gnus-newsgroup-headers
3721       (gnus-summary-prepare-threads
3722        (if gnus-show-threads
3723            (gnus-sort-gathered-threads
3724             (funcall gnus-summary-thread-gathering-function
3725                      (gnus-sort-threads
3726                       (gnus-cut-threads (gnus-make-threads)))))
3727          ;; Unthreaded display.
3728          (gnus-sort-articles gnus-newsgroup-headers))))
3729     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3730     ;; Call hooks for modifying summary buffer.
3731     (goto-char (point-min))
3732     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3733
3734 (defsubst gnus-general-simplify-subject (subject)
3735   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3736   (setq subject
3737         (cond
3738          ;; Truncate the subject.
3739          (gnus-simplify-subject-functions
3740           (gnus-map-function gnus-simplify-subject-functions subject))
3741          ((numberp gnus-summary-gather-subject-limit)
3742           (setq subject (gnus-simplify-subject-re subject))
3743           (if (> (length subject) gnus-summary-gather-subject-limit)
3744               (substring subject 0 gnus-summary-gather-subject-limit)
3745             subject))
3746          ;; Fuzzily simplify it.
3747          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3748           (gnus-simplify-subject-fuzzy subject))
3749          ;; Just remove the leading "Re:".
3750          (t
3751           (gnus-simplify-subject-re subject))))
3752
3753   (if (and gnus-summary-gather-exclude-subject
3754            (string-match gnus-summary-gather-exclude-subject subject))
3755       nil                               ; This article shouldn't be gathered
3756     subject))
3757
3758 (defun gnus-summary-simplify-subject-query ()
3759   "Query where the respool algorithm would put this article."
3760   (interactive)
3761   (gnus-summary-select-article)
3762   (message "%s"
3763            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3764
3765 (defun gnus-gather-threads-by-subject (threads)
3766   "Gather threads by looking at Subject headers."
3767   (if (not gnus-summary-make-false-root)
3768       threads
3769     (let ((hashtb (gnus-make-hashtable 1024))
3770           (prev threads)
3771           (result threads)
3772           subject hthread whole-subject)
3773       (while threads
3774         (setq subject (gnus-general-simplify-subject
3775                        (setq whole-subject (mail-header-subject
3776                                             (caar threads)))))
3777         (when subject
3778           (if (setq hthread (gnus-gethash subject hashtb))
3779               (progn
3780                 ;; We enter a dummy root into the thread, if we
3781                 ;; haven't done that already.
3782                 (unless (stringp (caar hthread))
3783                   (setcar hthread (list whole-subject (car hthread))))
3784                 ;; We add this new gathered thread to this gathered
3785                 ;; thread.
3786                 (setcdr (car hthread)
3787                         (nconc (cdar hthread) (list (car threads))))
3788                 ;; Remove it from the list of threads.
3789                 (setcdr prev (cdr threads))
3790                 (setq threads prev))
3791             ;; Enter this thread into the hash table.
3792             (gnus-sethash subject
3793                           (if gnus-summary-make-false-root-always
3794                               (progn
3795                                 ;; If you want a dummy root above all
3796                                 ;; threads...
3797                                 (setcar threads (list whole-subject
3798                                                       (car threads)))
3799                                 threads)
3800                             threads)
3801                           hashtb)))
3802         (setq prev threads)
3803         (setq threads (cdr threads)))
3804       result)))
3805
3806 (defun gnus-gather-threads-by-references (threads)
3807   "Gather threads by looking at References headers."
3808   (let ((idhashtb (gnus-make-hashtable 1024))
3809         (thhashtb (gnus-make-hashtable 1024))
3810         (prev threads)
3811         (result threads)
3812         ids references id gthread gid entered ref)
3813     (while threads
3814       (when (setq references (mail-header-references (caar threads)))
3815         (setq id (mail-header-id (caar threads))
3816               ids (inline (gnus-split-references references))
3817               entered nil)
3818         (while (setq ref (pop ids))
3819           (setq ids (delete ref ids))
3820           (if (not (setq gid (gnus-gethash ref idhashtb)))
3821               (progn
3822                 (gnus-sethash ref id idhashtb)
3823                 (gnus-sethash id threads thhashtb))
3824             (setq gthread (gnus-gethash gid thhashtb))
3825             (unless entered
3826               ;; We enter a dummy root into the thread, if we
3827               ;; haven't done that already.
3828               (unless (stringp (caar gthread))
3829                 (setcar gthread (list (mail-header-subject (caar gthread))
3830                                       (car gthread))))
3831               ;; We add this new gathered thread to this gathered
3832               ;; thread.
3833               (setcdr (car gthread)
3834                       (nconc (cdar gthread) (list (car threads)))))
3835             ;; Add it into the thread hash table.
3836             (gnus-sethash id gthread thhashtb)
3837             (setq entered t)
3838             ;; Remove it from the list of threads.
3839             (setcdr prev (cdr threads))
3840             (setq threads prev))))
3841       (setq prev threads)
3842       (setq threads (cdr threads)))
3843     result))
3844
3845 (defun gnus-sort-gathered-threads (threads)
3846   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3847   (let ((result threads))
3848     (while threads
3849       (when (stringp (caar threads))
3850         (setcdr (car threads)
3851                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3852       (setq threads (cdr threads)))
3853     result))
3854
3855 (defun gnus-thread-loop-p (root thread)
3856   "Say whether ROOT is in THREAD."
3857   (let ((stack (list thread))
3858         (infloop 0)
3859         th)
3860     (while (setq thread (pop stack))
3861       (setq th (cdr thread))
3862       (while (and th
3863                   (not (eq (caar th) root)))
3864         (pop th))
3865       (if th
3866           ;; We have found a loop.
3867           (let (ref-dep)
3868             (setcdr thread (delq (car th) (cdr thread)))
3869             (if (boundp (setq ref-dep (intern "none"
3870                                               gnus-newsgroup-dependencies)))
3871                 (setcdr (symbol-value ref-dep)
3872                         (nconc (cdr (symbol-value ref-dep))
3873                                (list (car th))))
3874               (set ref-dep (list nil (car th))))
3875             (setq infloop 1
3876                   stack nil))
3877         ;; Push all the subthreads onto the stack.
3878         (push (cdr thread) stack)))
3879     infloop))
3880
3881 (defun gnus-make-threads ()
3882   "Go through the dependency hashtb and find the roots.  Return all threads."
3883   (let (threads)
3884     (while (catch 'infloop
3885              (mapatoms
3886               (lambda (refs)
3887                 ;; Deal with self-referencing References loops.
3888                 (when (and (car (symbol-value refs))
3889                            (not (zerop
3890                                  (apply
3891                                   '+
3892                                   (mapcar
3893                                    (lambda (thread)
3894                                      (gnus-thread-loop-p
3895                                       (car (symbol-value refs)) thread))
3896                                    (cdr (symbol-value refs)))))))
3897                   (setq threads nil)
3898                   (throw 'infloop t))
3899                 (unless (car (symbol-value refs))
3900                   ;; These threads do not refer back to any other articles,
3901                   ;; so they're roots.
3902                   (setq threads (append (cdr (symbol-value refs)) threads))))
3903               gnus-newsgroup-dependencies)))
3904     threads))
3905
3906 ;; Build the thread tree.
3907 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3908   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3909
3910 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3911 if it was already present.
3912
3913 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3914 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3915 Message-IDs will be renamed to a unique Message-ID before being
3916 entered.
3917
3918 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3919   (let* ((id (mail-header-id header))
3920          (id-dep (and id (intern id dependencies)))
3921          parent-id ref ref-dep ref-header replaced)
3922     ;; Enter this `header' in the `dependencies' table.
3923     (cond
3924      ((not id-dep)
3925       (setq header nil))
3926      ;; The first two cases do the normal part: enter a new `header'
3927      ;; in the `dependencies' table.
3928      ((not (boundp id-dep))
3929       (set id-dep (list header)))
3930      ((null (car (symbol-value id-dep)))
3931       (setcar (symbol-value id-dep) header))
3932
3933      ;; From here the `header' was already present in the
3934      ;; `dependencies' table.
3935      (force-new
3936       ;; Overrides an existing entry;
3937       ;; just set the header part of the entry.
3938       (setcar (symbol-value id-dep) header)
3939       (setq replaced t))
3940
3941      ;; Renames the existing `header' to a unique Message-ID.
3942      ((not gnus-summary-ignore-duplicates)
3943       ;; An article with this Message-ID has already been seen.
3944       ;; We rename the Message-ID.
3945       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3946            (list header))
3947       (mail-header-set-id header id))
3948
3949      ;; The last case ignores an existing entry, except it adds any
3950      ;; additional Xrefs (in case the two articles came from different
3951      ;; servers.
3952      ;; Also sets `header' to `nil' meaning that the `dependencies'
3953      ;; table was *not* modified.
3954      (t
3955       (mail-header-set-xref
3956        (car (symbol-value id-dep))
3957        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3958                    "")
3959                (or (mail-header-xref header) "")))
3960       (setq header nil)))
3961
3962     (when (and header (not replaced))
3963       ;; First check that we are not creating a References loop.
3964       (setq parent-id (gnus-parent-id (mail-header-references header)))
3965       (setq ref parent-id)
3966       (while (and ref
3967                   (setq ref-dep (intern-soft ref dependencies))
3968                   (boundp ref-dep)
3969                   (setq ref-header (car (symbol-value ref-dep))))
3970         (if (string= id ref)
3971             ;; Yuk!  This is a reference loop.  Make the article be a
3972             ;; root article.
3973             (progn
3974               (mail-header-set-references (car (symbol-value id-dep)) "none")
3975               (setq ref nil)
3976               (setq parent-id nil))
3977           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3978       (setq ref-dep (intern (or parent-id "none") dependencies))
3979       (if (boundp ref-dep)
3980           (setcdr (symbol-value ref-dep)
3981                   (nconc (cdr (symbol-value ref-dep))
3982                          (list (symbol-value id-dep))))
3983         (set ref-dep (list nil (symbol-value id-dep)))))
3984     header))
3985
3986 (defun gnus-extract-message-id-from-in-reply-to (string)
3987   (if (string-match "<[^>]+>" string)
3988       (substring string (match-beginning 0) (match-end 0))
3989     nil))
3990
3991 (defun gnus-build-sparse-threads ()
3992   (let ((headers gnus-newsgroup-headers)
3993         (mail-parse-charset gnus-newsgroup-charset)
3994         (gnus-summary-ignore-duplicates t)
3995         header references generation relations
3996         subject child end new-child date)
3997     ;; First we create an alist of generations/relations, where
3998     ;; generations is how much we trust the relation, and the relation
3999     ;; is parent/child.
4000     (gnus-message 7 "Making sparse threads...")
4001     (save-excursion
4002       (nnheader-set-temp-buffer " *gnus sparse threads*")
4003       (while (setq header (pop headers))
4004         (when (and (setq references (mail-header-references header))
4005                    (not (string= references "")))
4006           (insert references)
4007           (setq child (mail-header-id header)
4008                 subject (mail-header-subject header)
4009                 date (mail-header-date header)
4010                 generation 0)
4011           (while (search-backward ">" nil t)
4012             (setq end (1+ (point)))
4013             (when (search-backward "<" nil t)
4014               (setq new-child (buffer-substring (point) end))
4015               (push (list (incf generation)
4016                           child (setq child new-child)
4017                           subject date)
4018                     relations)))
4019           (when child
4020             (push (list (1+ generation) child nil subject) relations))
4021           (erase-buffer)))
4022       (kill-buffer (current-buffer)))
4023     ;; Sort over trustworthiness.
4024     (mapcar
4025      (lambda (relation)
4026        (when (gnus-dependencies-add-header
4027               (make-full-mail-header-from-decoded-header
4028                gnus-reffed-article-number
4029                (nth 3 relation) "" (or (nth 4 relation) "")
4030                (nth 1 relation)
4031                (or (nth 2 relation) "") 0 0 "")
4032               gnus-newsgroup-dependencies nil)
4033          (push gnus-reffed-article-number gnus-newsgroup-limit)
4034          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4035          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4036                gnus-newsgroup-reads)
4037          (decf gnus-reffed-article-number)))
4038      (sort relations 'car-less-than-car))
4039     (gnus-message 7 "Making sparse threads...done")))
4040
4041 (defun gnus-build-old-threads ()
4042   ;; Look at all the articles that refer back to old articles, and
4043   ;; fetch the headers for the articles that aren't there.  This will
4044   ;; build complete threads - if the roots haven't been expired by the
4045   ;; server, that is.
4046   (let ((mail-parse-charset gnus-newsgroup-charset)
4047         id heads)
4048     (mapatoms
4049      (lambda (refs)
4050        (when (not (car (symbol-value refs)))
4051          (setq heads (cdr (symbol-value refs)))
4052          (while heads
4053            (if (memq (mail-header-number (caar heads))
4054                      gnus-newsgroup-dormant)
4055                (setq heads (cdr heads))
4056              (setq id (symbol-name refs))
4057              (while (and (setq id (gnus-build-get-header id))
4058                          (not (car (gnus-id-to-thread id)))))
4059              (setq heads nil)))))
4060      gnus-newsgroup-dependencies)))
4061
4062 (defsubst gnus-remove-odd-characters (string)
4063   "Translate STRING into something that doesn't contain weird characters."
4064   (mm-subst-char-in-string
4065    ?\r ?\-
4066    (mm-subst-char-in-string ?\n ?\- string t) t))
4067
4068 ;; This function has to be called with point after the article number
4069 ;; on the beginning of the line.
4070 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4071   (let ((eol (point-at-eol))
4072         (buffer (current-buffer))
4073         header references in-reply-to)
4074
4075     ;; overview: [num subject from date id refs chars lines misc]
4076     (unwind-protect
4077         (progn
4078           (narrow-to-region (point) eol)
4079           (unless (eobp)
4080             (forward-char))
4081
4082           (setq header
4083                 (make-full-mail-header
4084                  number                         ; number
4085                  (nnheader-nov-field)           ; subject
4086                  (nnheader-nov-field)           ; from
4087                  (nnheader-nov-field)           ; date
4088                  (nnheader-nov-read-message-id number)  ; id
4089                  (setq references (nnheader-nov-field)) ; refs
4090                  (nnheader-nov-read-integer)    ; chars
4091                  (nnheader-nov-read-integer)    ; lines
4092                  (unless (eobp)
4093                    (if (looking-at "Xref: ")
4094                        (goto-char (match-end 0)))
4095                    (nnheader-nov-field))        ; Xref
4096                  (nnheader-nov-parse-extra))))  ; extra
4097
4098       (widen))
4099
4100     (when (and (string= references "")
4101                (setq in-reply-to (mail-header-extra header))
4102                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4103       (mail-header-set-references
4104        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4105
4106     (when gnus-alter-header-function
4107       (funcall gnus-alter-header-function header))
4108     (gnus-dependencies-add-header header dependencies force-new)))
4109
4110 (defun gnus-build-get-header (id)
4111   "Look through the buffer of NOV lines and find the header to ID.
4112 Enter this line into the dependencies hash table, and return
4113 the id of the parent article (if any)."
4114   (let ((deps gnus-newsgroup-dependencies)
4115         found header)
4116     (prog1
4117         (save-excursion
4118           (set-buffer nntp-server-buffer)
4119           (let ((case-fold-search nil))
4120             (goto-char (point-min))
4121             (while (and (not found)
4122                         (search-forward id nil t))
4123               (beginning-of-line)
4124               (setq found (looking-at
4125                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4126                                    (regexp-quote id))))
4127               (or found (beginning-of-line 2)))
4128             (when found
4129               (beginning-of-line)
4130               (and
4131                (setq header (gnus-nov-parse-line
4132                              (read (current-buffer)) deps))
4133                (gnus-parent-id (mail-header-references header))))))
4134       (when header
4135         (let ((number (mail-header-number header)))
4136           (push number gnus-newsgroup-limit)
4137           (push header gnus-newsgroup-headers)
4138           (if (memq number gnus-newsgroup-unselected)
4139               (progn
4140                 (setq gnus-newsgroup-unreads
4141                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4142                                                number))
4143                 (setq gnus-newsgroup-unselected
4144                       (delq number gnus-newsgroup-unselected)))
4145             (push number gnus-newsgroup-ancient)))))))
4146
4147 (defun gnus-build-all-threads ()
4148   "Read all the headers."
4149   (let ((gnus-summary-ignore-duplicates t)
4150         (mail-parse-charset gnus-newsgroup-charset)
4151         (dependencies gnus-newsgroup-dependencies)
4152         header article)
4153     (save-excursion
4154       (set-buffer nntp-server-buffer)
4155       (let ((case-fold-search nil))
4156         (goto-char (point-min))
4157         (while (not (eobp))
4158           (ignore-errors
4159             (setq article (read (current-buffer))
4160                   header (gnus-nov-parse-line article dependencies)))
4161           (when header
4162             (with-current-buffer gnus-summary-buffer
4163               (push header gnus-newsgroup-headers)
4164               (if (memq (setq article (mail-header-number header))
4165                         gnus-newsgroup-unselected)
4166                   (progn
4167                     (setq gnus-newsgroup-unreads
4168                           (gnus-add-to-sorted-list
4169                            gnus-newsgroup-unreads article))
4170                     (setq gnus-newsgroup-unselected
4171                           (delq article gnus-newsgroup-unselected)))
4172                 (push article gnus-newsgroup-ancient)))
4173             (forward-line 1)))))))
4174
4175 (defun gnus-summary-update-article-line (article header)
4176   "Update the line for ARTICLE using HEADER."
4177   (let* ((id (mail-header-id header))
4178          (thread (gnus-id-to-thread id)))
4179     (unless thread
4180       (error "Article in no thread"))
4181     ;; Update the thread.
4182     (setcar thread header)
4183     (gnus-summary-goto-subject article)
4184     (let* ((datal (gnus-data-find-list article))
4185            (data (car datal))
4186            (buffer-read-only nil)
4187            (level (gnus-summary-thread-level)))
4188       (gnus-delete-line)
4189       (let ((inserted (- (point)
4190                          (progn
4191                            (gnus-summary-insert-line
4192                             header level nil
4193                             (memq article gnus-newsgroup-undownloaded)
4194                             (gnus-article-mark article)
4195                             (memq article gnus-newsgroup-replied)
4196                             (memq article gnus-newsgroup-expirable)
4197                             ;; Only insert the Subject string when it's different
4198                             ;; from the previous Subject string.
4199                             (if (and
4200                                  gnus-show-threads
4201                                  (gnus-subject-equal
4202                                   (condition-case ()
4203                                       (mail-header-subject
4204                                        (gnus-data-header
4205                                         (cadr
4206                                          (gnus-data-find-list
4207                                           article
4208                                           (gnus-data-list t)))))
4209                                     ;; Error on the side of excessive subjects.
4210                                     (error ""))
4211                                   (mail-header-subject header)))
4212                                 ""
4213                               (mail-header-subject header))
4214                             nil (cdr (assq article gnus-newsgroup-scored))
4215                             (memq article gnus-newsgroup-processable))
4216                            (point)))))
4217         (when (cdr datal)
4218           (gnus-data-update-list
4219            (cdr datal)
4220            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4221
4222 (defun gnus-summary-update-article (article &optional iheader)
4223   "Update ARTICLE in the summary buffer."
4224   (set-buffer gnus-summary-buffer)
4225   (let* ((header (gnus-summary-article-header article))
4226          (id (mail-header-id header))
4227          (data (gnus-data-find article))
4228          (thread (gnus-id-to-thread id))
4229          (references (mail-header-references header))
4230          (parent
4231           (gnus-id-to-thread
4232            (or (gnus-parent-id
4233                 (when (and references
4234                            (not (equal "" references)))
4235                   references))
4236                "none")))
4237          (buffer-read-only nil)
4238          (old (car thread)))
4239     (when thread
4240       (unless iheader
4241         (setcar thread nil)
4242         (when parent
4243           (delq thread parent)))
4244       (if (gnus-summary-insert-subject id header)
4245           ;; Set the (possibly) new article number in the data structure.
4246           (gnus-data-set-number data (gnus-id-to-article id))
4247         (setcar thread old)
4248         nil))))
4249
4250 (defun gnus-rebuild-thread (id &optional line)
4251   "Rebuild the thread containing ID.
4252 If LINE, insert the rebuilt thread starting on line LINE."
4253   (let ((buffer-read-only nil)
4254         old-pos current thread data)
4255     (if (not gnus-show-threads)
4256         (setq thread (list (car (gnus-id-to-thread id))))
4257       ;; Get the thread this article is part of.
4258       (setq thread (gnus-remove-thread id)))
4259     (setq old-pos (point-at-bol))
4260     (setq current (save-excursion
4261                     (and (re-search-backward "[\r\n]" nil t)
4262                          (gnus-summary-article-number))))
4263     ;; If this is a gathered thread, we have to go some re-gathering.
4264     (when (stringp (car thread))
4265       (let ((subject (car thread))
4266             roots thr)
4267         (setq thread (cdr thread))
4268         (while thread
4269           (unless (memq (setq thr (gnus-id-to-thread
4270                                    (gnus-root-id
4271                                     (mail-header-id (caar thread)))))
4272                         roots)
4273             (push thr roots))
4274           (setq thread (cdr thread)))
4275         ;; We now have all (unique) roots.
4276         (if (= (length roots) 1)
4277             ;; All the loose roots are now one solid root.
4278             (setq thread (car roots))
4279           (setq thread (cons subject (gnus-sort-threads roots))))))
4280     (let (threads)
4281       ;; We then insert this thread into the summary buffer.
4282       (when line
4283         (goto-char (point-min))
4284         (forward-line (1- line)))
4285       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4286         (if gnus-show-threads
4287             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4288           (gnus-summary-prepare-unthreaded thread))
4289         (setq data (nreverse gnus-newsgroup-data))
4290         (setq threads gnus-newsgroup-threads))
4291       ;; We splice the new data into the data structure.
4292       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4293       ;;!!! then we want to insert at the beginning of the buffer.
4294       ;;!!! That happens to be true with Gnus now, but that may
4295       ;;!!! change in the future.  Perhaps.
4296       (gnus-data-enter-list
4297        (if line nil current) data (- (point) old-pos))
4298       (setq gnus-newsgroup-threads
4299             (nconc threads gnus-newsgroup-threads))
4300       (gnus-data-compute-positions))))
4301
4302 (defun gnus-number-to-header (number)
4303   "Return the header for article NUMBER."
4304   (let ((headers gnus-newsgroup-headers))
4305     (while (and headers
4306                 (not (= number (mail-header-number (car headers)))))
4307       (pop headers))
4308     (when headers
4309       (car headers))))
4310
4311 (defun gnus-parent-headers (in-headers &optional generation)
4312   "Return the headers of the GENERATIONeth parent of HEADERS."
4313   (unless generation
4314     (setq generation 1))
4315   (let ((parent t)
4316         (headers in-headers)
4317         references)
4318     (while (and parent
4319                 (not (zerop generation))
4320                 (setq references (mail-header-references headers)))
4321       (setq headers (if (and references
4322                              (setq parent (gnus-parent-id references)))
4323                         (car (gnus-id-to-thread parent))
4324                       nil))
4325       (decf generation))
4326     (and (not (eq headers in-headers))
4327          headers)))
4328
4329 (defun gnus-id-to-thread (id)
4330   "Return the (sub-)thread where ID appears."
4331   (gnus-gethash id gnus-newsgroup-dependencies))
4332
4333 (defun gnus-id-to-article (id)
4334   "Return the article number of ID."
4335   (let ((thread (gnus-id-to-thread id)))
4336     (when (and thread
4337                (car thread))
4338       (mail-header-number (car thread)))))
4339
4340 (defun gnus-id-to-header (id)
4341   "Return the article headers of ID."
4342   (car (gnus-id-to-thread id)))
4343
4344 (defun gnus-article-displayed-root-p (article)
4345   "Say whether ARTICLE is a root(ish) article."
4346   (let ((level (gnus-summary-thread-level article))
4347         (refs (mail-header-references  (gnus-summary-article-header article)))
4348         particle)
4349     (cond
4350      ((null level) nil)
4351      ((zerop level) t)
4352      ((null refs) t)
4353      ((null (gnus-parent-id refs)) t)
4354      ((and (= 1 level)
4355            (null (setq particle (gnus-id-to-article
4356                                  (gnus-parent-id refs))))
4357            (null (gnus-summary-thread-level particle)))))))
4358
4359 (defun gnus-root-id (id)
4360   "Return the id of the root of the thread where ID appears."
4361   (let (last-id prev)
4362     (while (and id (setq prev (car (gnus-id-to-thread id))))
4363       (setq last-id id
4364             id (gnus-parent-id (mail-header-references prev))))
4365     last-id))
4366
4367 (defun gnus-articles-in-thread (thread)
4368   "Return the list of articles in THREAD."
4369   (cons (mail-header-number (car thread))
4370         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4371
4372 (defun gnus-remove-thread (id &optional dont-remove)
4373   "Remove the thread that has ID in it."
4374   (let (headers thread last-id)
4375     ;; First go up in this thread until we find the root.
4376     (setq last-id (gnus-root-id id)
4377           headers (message-flatten-list (gnus-id-to-thread last-id)))
4378     ;; We have now found the real root of this thread.  It might have
4379     ;; been gathered into some loose thread, so we have to search
4380     ;; through the threads to find the thread we wanted.
4381     (let ((threads gnus-newsgroup-threads)
4382           sub)
4383       (while threads
4384         (setq sub (car threads))
4385         (if (stringp (car sub))
4386             ;; This is a gathered thread, so we look at the roots
4387             ;; below it to find whether this article is in this
4388             ;; gathered root.
4389             (progn
4390               (setq sub (cdr sub))
4391               (while sub
4392                 (when (member (caar sub) headers)
4393                   (setq thread (car threads)
4394                         threads nil
4395                         sub nil))
4396                 (setq sub (cdr sub))))
4397           ;; It's an ordinary thread, so we check it.
4398           (when (eq (car sub) (car headers))
4399             (setq thread sub
4400                   threads nil)))
4401         (setq threads (cdr threads)))
4402       ;; If this article is in no thread, then it's a root.
4403       (if thread
4404           (unless dont-remove
4405             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4406         (setq thread (gnus-id-to-thread last-id)))
4407       (when thread
4408         (prog1
4409             thread                      ; We return this thread.
4410           (unless dont-remove
4411             (if (stringp (car thread))
4412                 (progn
4413                   ;; If we use dummy roots, then we have to remove the
4414                   ;; dummy root as well.
4415                   (when (eq gnus-summary-make-false-root 'dummy)
4416                     ;; We go to the dummy root by going to
4417                     ;; the first sub-"thread", and then one line up.
4418                     (gnus-summary-goto-article
4419                      (mail-header-number (caadr thread)))
4420                     (forward-line -1)
4421                     (gnus-delete-line)
4422                     (gnus-data-compute-positions))
4423                   (setq thread (cdr thread))
4424                   (while thread
4425                     (gnus-remove-thread-1 (car thread))
4426                     (setq thread (cdr thread))))
4427               (gnus-remove-thread-1 thread))))))))
4428
4429 (defun gnus-remove-thread-1 (thread)
4430   "Remove the thread THREAD recursively."
4431   (let ((number (mail-header-number (pop thread)))
4432         d)
4433     (setq thread (reverse thread))
4434     (while thread
4435       (gnus-remove-thread-1 (pop thread)))
4436     (when (setq d (gnus-data-find number))
4437       (goto-char (gnus-data-pos d))
4438       (gnus-summary-show-thread)
4439       (gnus-data-remove
4440        number
4441        (- (point-at-bol)
4442           (prog1
4443               (1+ (point-at-eol))
4444             (gnus-delete-line)))))))
4445
4446 (defun gnus-sort-threads-1 (threads func)
4447   (sort (mapcar (lambda (thread)
4448                   (cons (car thread)
4449                         (and (cdr thread)
4450                              (gnus-sort-threads-1 (cdr thread) func))))
4451                 threads) func))
4452
4453 (defun gnus-sort-threads (threads)
4454   "Sort THREADS."
4455   (if (not gnus-thread-sort-functions)
4456       threads
4457     (gnus-message 8 "Sorting threads...")
4458     (let ((max-lisp-eval-depth 5000))
4459       (prog1 (gnus-sort-threads-1
4460          threads
4461          (gnus-make-sort-function gnus-thread-sort-functions))
4462         (gnus-message 8 "Sorting threads...done")))))
4463
4464 (defun gnus-sort-articles (articles)
4465   "Sort ARTICLES."
4466   (when gnus-article-sort-functions
4467     (gnus-message 7 "Sorting articles...")
4468     (prog1
4469         (setq gnus-newsgroup-headers
4470               (sort articles (gnus-make-sort-function
4471                               gnus-article-sort-functions)))
4472       (gnus-message 7 "Sorting articles...done"))))
4473
4474 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4475 (defmacro gnus-thread-header (thread)
4476   "Return header of first article in THREAD.
4477 Note that THREAD must never, ever be anything else than a variable -
4478 using some other form will lead to serious barfage."
4479   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4480   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4481   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4482         (vector thread) 2))
4483
4484 (defsubst gnus-article-sort-by-number (h1 h2)
4485   "Sort articles by article number."
4486   (< (mail-header-number h1)
4487      (mail-header-number h2)))
4488
4489 (defun gnus-thread-sort-by-number (h1 h2)
4490   "Sort threads by root article number."
4491   (gnus-article-sort-by-number
4492    (gnus-thread-header h1) (gnus-thread-header h2)))
4493
4494 (defsubst gnus-article-sort-by-random (h1 h2)
4495   "Sort articles by article number."
4496   (zerop (random 2)))
4497
4498 (defun gnus-thread-sort-by-random (h1 h2)
4499   "Sort threads by root article number."
4500   (gnus-article-sort-by-random
4501    (gnus-thread-header h1) (gnus-thread-header h2)))
4502
4503 (defsubst gnus-article-sort-by-lines (h1 h2)
4504   "Sort articles by article Lines header."
4505   (< (mail-header-lines h1)
4506      (mail-header-lines h2)))
4507
4508 (defun gnus-thread-sort-by-lines (h1 h2)
4509   "Sort threads by root article Lines header."
4510   (gnus-article-sort-by-lines
4511    (gnus-thread-header h1) (gnus-thread-header h2)))
4512
4513 (defsubst gnus-article-sort-by-chars (h1 h2)
4514   "Sort articles by octet length."
4515   (< (mail-header-chars h1)
4516      (mail-header-chars h2)))
4517
4518 (defun gnus-thread-sort-by-chars (h1 h2)
4519   "Sort threads by root article octet length."
4520   (gnus-article-sort-by-chars
4521    (gnus-thread-header h1) (gnus-thread-header h2)))
4522
4523 (defsubst gnus-article-sort-by-author (h1 h2)
4524   "Sort articles by root author."
4525   (string-lessp
4526    (let ((addr (car (mime-entity-read-field h1 'From))))
4527      (or (std11-full-name-string addr)
4528          (std11-address-string addr)
4529          ""))
4530    (let ((addr (car (mime-entity-read-field h2 'From))))
4531      (or (std11-full-name-string addr)
4532          (std11-address-string addr)
4533          ""))
4534    ))
4535
4536 (defun gnus-thread-sort-by-author (h1 h2)
4537   "Sort threads by root author."
4538   (gnus-article-sort-by-author
4539    (gnus-thread-header h1)  (gnus-thread-header h2)))
4540
4541 (defsubst gnus-article-sort-by-subject (h1 h2)
4542   "Sort articles by root subject."
4543   (string-lessp
4544    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4545    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4546
4547 (defun gnus-thread-sort-by-subject (h1 h2)
4548   "Sort threads by root subject."
4549   (gnus-article-sort-by-subject
4550    (gnus-thread-header h1) (gnus-thread-header h2)))
4551
4552 (defsubst gnus-article-sort-by-date (h1 h2)
4553   "Sort articles by root article date."
4554   (time-less-p
4555    (gnus-date-get-time (mail-header-date h1))
4556    (gnus-date-get-time (mail-header-date h2))))
4557
4558 (defun gnus-thread-sort-by-date (h1 h2)
4559   "Sort threads by root article date."
4560   (gnus-article-sort-by-date
4561    (gnus-thread-header h1) (gnus-thread-header h2)))
4562
4563 (defsubst gnus-article-sort-by-score (h1 h2)
4564   "Sort articles by root article score.
4565 Unscored articles will be counted as having a score of zero."
4566   (> (or (cdr (assq (mail-header-number h1)
4567                     gnus-newsgroup-scored))
4568          gnus-summary-default-score 0)
4569      (or (cdr (assq (mail-header-number h2)
4570                     gnus-newsgroup-scored))
4571          gnus-summary-default-score 0)))
4572
4573 (defun gnus-thread-sort-by-score (h1 h2)
4574   "Sort threads by root article score."
4575   (gnus-article-sort-by-score
4576    (gnus-thread-header h1) (gnus-thread-header h2)))
4577
4578 (defun gnus-thread-sort-by-total-score (h1 h2)
4579   "Sort threads by the sum of all scores in the thread.
4580 Unscored articles will be counted as having a score of zero."
4581   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4582
4583 (defun gnus-thread-total-score (thread)
4584   ;; This function find the total score of THREAD.
4585   (cond
4586    ((null thread)
4587     0)
4588    ((consp thread)
4589     (if (stringp (car thread))
4590         (apply gnus-thread-score-function 0
4591                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4592       (gnus-thread-total-score-1 thread)))
4593    (t
4594     (gnus-thread-total-score-1 (list thread)))))
4595
4596 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4597   "Sort threads such that the thread with the most recently arrived article comes first."
4598   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4599
4600 (defun gnus-thread-highest-number (thread)
4601   "Return the highest article number in THREAD."
4602   (apply 'max (mapcar (lambda (header)
4603                         (mail-header-number header))
4604                       (message-flatten-list thread))))
4605
4606 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4607   "Sort threads such that the thread with the most recently dated article comes first."
4608   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4609
4610 (defun gnus-thread-latest-date (thread)
4611   "Return the highest article date in THREAD."
4612   (let ((previous-time 0))
4613     (apply 'max
4614            (mapcar
4615             (lambda (header)
4616               (setq previous-time
4617                     (condition-case ()
4618                         (time-to-seconds (mail-header-parse-date
4619                                           (mail-header-date header)))
4620                       (error previous-time))))
4621             (sort
4622              (message-flatten-list thread)
4623              (lambda (h1 h2)
4624                (< (mail-header-number h1)
4625                   (mail-header-number h2))))))))
4626
4627 (defun gnus-thread-total-score-1 (root)
4628   ;; This function find the total score of the thread below ROOT.
4629   (setq root (car root))
4630   (apply gnus-thread-score-function
4631          (or (append
4632               (mapcar 'gnus-thread-total-score
4633                       (cdr (gnus-id-to-thread (mail-header-id root))))
4634               (when (> (mail-header-number root) 0)
4635                 (list (or (cdr (assq (mail-header-number root)
4636                                      gnus-newsgroup-scored))
4637                           gnus-summary-default-score 0))))
4638              (list gnus-summary-default-score)
4639              '(0))))
4640
4641 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4642 (defvar gnus-tmp-prev-subject nil)
4643 (defvar gnus-tmp-false-parent nil)
4644 (defvar gnus-tmp-root-expunged nil)
4645 (defvar gnus-tmp-dummy-line nil)
4646
4647 (eval-when-compile (defvar gnus-tmp-header))
4648 (defun gnus-extra-header (type &optional header)
4649   "Return the extra header of TYPE."
4650   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4651       ""))
4652
4653 (defvar gnus-tmp-thread-tree-header-string "")
4654
4655 (defcustom gnus-sum-thread-tree-root "> "
4656   "With %B spec, used for the root of a thread.
4657 If nil, use subject instead."
4658   :version "21.4"
4659   :type '(radio (const :format "%v  " nil) (string :size 0))
4660   :group 'gnus-thread)
4661 (defcustom gnus-sum-thread-tree-false-root "> "
4662   "With %B spec, used for a false root of a thread.
4663 If nil, use subject instead."
4664   :version "21.4"
4665   :type '(radio (const :format "%v  " nil) (string :size 0))
4666   :group 'gnus-thread)
4667 (defcustom gnus-sum-thread-tree-single-indent ""
4668   "With %B spec, used for a thread with just one message.
4669 If nil, use subject instead."
4670   :version "21.4"
4671   :type '(radio (const :format "%v  " nil) (string :size 0))
4672   :group 'gnus-thread)
4673 (defcustom gnus-sum-thread-tree-vertical "| "
4674   "With %B spec, used for drawing a vertical line."
4675   :version "21.4"
4676   :type 'string
4677   :group 'gnus-thread)
4678 (defcustom gnus-sum-thread-tree-indent "  "
4679   "With %B spec, used for indenting."
4680   :version "21.4"
4681   :type 'string
4682   :group 'gnus-thread)
4683 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4684   "With %B spec, used for a leaf with brothers."
4685   :version "21.4"
4686   :type 'string
4687   :group 'gnus-thread)
4688 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4689   "With %B spec, used for a leaf without brothers."
4690   :version "21.4"
4691   :type 'string
4692   :group 'gnus-thread)
4693
4694 (defun gnus-summary-prepare-threads (threads)
4695   "Prepare summary buffer from THREADS and indentation LEVEL.
4696 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4697 or a straight list of headers."
4698   (gnus-message 7 "Generating summary...")
4699
4700   (setq gnus-newsgroup-threads threads)
4701   (beginning-of-line)
4702
4703   (let ((gnus-tmp-level 0)
4704         (default-score (or gnus-summary-default-score 0))
4705         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4706         (building-line-count gnus-summary-display-while-building)
4707         (building-count (integerp gnus-summary-display-while-building))
4708         thread number subject stack state gnus-tmp-gathered beg-match
4709         new-roots gnus-tmp-new-adopts thread-end simp-subject
4710         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4711         gnus-tmp-replied gnus-tmp-subject-or-nil
4712         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4713         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4714         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4715         tree-stack)
4716
4717     (setq gnus-tmp-prev-subject nil
4718           gnus-tmp-thread-tree-header-string "")
4719
4720     (if (vectorp (car threads))
4721         ;; If this is a straight (sic) list of headers, then a
4722         ;; threaded summary display isn't required, so we just create
4723         ;; an unthreaded one.
4724         (gnus-summary-prepare-unthreaded threads)
4725
4726       ;; Do the threaded display.
4727
4728       (if gnus-summary-display-while-building
4729           (switch-to-buffer (buffer-name)))
4730       (while (or threads stack gnus-tmp-new-adopts new-roots)
4731
4732         (if (and (= gnus-tmp-level 0)
4733                  (or (not stack)
4734                      (= (caar stack) 0))
4735                  (not gnus-tmp-false-parent)
4736                  (or gnus-tmp-new-adopts new-roots))
4737             (if gnus-tmp-new-adopts
4738                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4739                       thread (list (car gnus-tmp-new-adopts))
4740                       gnus-tmp-header (caar thread)
4741                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4742               (when new-roots
4743                 (setq thread (list (car new-roots))
4744                       gnus-tmp-header (caar thread)
4745                       new-roots (cdr new-roots))))
4746
4747           (if threads
4748               ;; If there are some threads, we do them before the
4749               ;; threads on the stack.
4750               (setq thread threads
4751                     gnus-tmp-header (caar thread))
4752             ;; There were no current threads, so we pop something off
4753             ;; the stack.
4754             (setq state (car stack)
4755                   gnus-tmp-level (car state)
4756                   tree-stack (cadr state)
4757                   thread (caddr state)
4758                   stack (cdr stack)
4759                   gnus-tmp-header (caar thread))))
4760
4761         (setq gnus-tmp-false-parent nil)
4762         (setq gnus-tmp-root-expunged nil)
4763         (setq thread-end nil)
4764
4765         (if (stringp gnus-tmp-header)
4766             ;; The header is a dummy root.
4767             (cond
4768              ((eq gnus-summary-make-false-root 'adopt)
4769               ;; We let the first article adopt the rest.
4770               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4771                                                (cddar thread)))
4772               (setq gnus-tmp-gathered
4773                     (nconc (mapcar
4774                             (lambda (h) (mail-header-number (car h)))
4775                             (cddar thread))
4776                            gnus-tmp-gathered))
4777               (setq thread (cons (list (caar thread)
4778                                        (cadar thread))
4779                                  (cdr thread)))
4780               (setq gnus-tmp-level -1
4781                     gnus-tmp-false-parent t))
4782              ((eq gnus-summary-make-false-root 'empty)
4783               ;; We print adopted articles with empty subject fields.
4784               (setq gnus-tmp-gathered
4785                     (nconc (mapcar
4786                             (lambda (h) (mail-header-number (car h)))
4787                             (cddar thread))
4788                            gnus-tmp-gathered))
4789               (setq gnus-tmp-level -1))
4790              ((eq gnus-summary-make-false-root 'dummy)
4791               ;; We remember that we probably want to output a dummy
4792               ;; root.
4793               (setq gnus-tmp-dummy-line gnus-tmp-header)
4794               (setq gnus-tmp-prev-subject gnus-tmp-header))
4795              (t
4796               ;; We do not make a root for the gathered
4797               ;; sub-threads at all.
4798               (setq gnus-tmp-level -1)))
4799
4800           (setq number (mail-header-number gnus-tmp-header)
4801                 subject (mail-header-subject gnus-tmp-header)
4802                 simp-subject (gnus-simplify-subject-fully subject))
4803
4804           (cond
4805            ;; If the thread has changed subject, we might want to make
4806            ;; this subthread into a root.
4807            ((and (null gnus-thread-ignore-subject)
4808                  (not (zerop gnus-tmp-level))
4809                  gnus-tmp-prev-subject
4810                  (not (string= gnus-tmp-prev-subject simp-subject)))
4811             (setq new-roots (nconc new-roots (list (car thread)))
4812                   thread-end t
4813                   gnus-tmp-header nil))
4814            ;; If the article lies outside the current limit,
4815            ;; then we do not display it.
4816            ((not (memq number gnus-newsgroup-limit))
4817             (setq gnus-tmp-gathered
4818                   (nconc (mapcar
4819                           (lambda (h) (mail-header-number (car h)))
4820                           (cdar thread))
4821                          gnus-tmp-gathered))
4822             (setq gnus-tmp-new-adopts (if (cdar thread)
4823                                           (append gnus-tmp-new-adopts
4824                                                   (cdar thread))
4825                                         gnus-tmp-new-adopts)
4826                   thread-end t
4827                   gnus-tmp-header nil)
4828             (when (zerop gnus-tmp-level)
4829               (setq gnus-tmp-root-expunged t)))
4830            ;; Perhaps this article is to be marked as read?
4831            ((and gnus-summary-mark-below
4832                  (< (or (cdr (assq number gnus-newsgroup-scored))
4833                         default-score)
4834                     gnus-summary-mark-below)
4835                  ;; Don't touch sparse articles.
4836                  (not (gnus-summary-article-sparse-p number))
4837                  (not (gnus-summary-article-ancient-p number)))
4838             (setq gnus-newsgroup-unreads
4839                   (delq number gnus-newsgroup-unreads))
4840             (if gnus-newsgroup-auto-expire
4841                 (setq gnus-newsgroup-expirable
4842                       (gnus-add-to-sorted-list
4843                        gnus-newsgroup-expirable number))
4844               (push (cons number gnus-low-score-mark)
4845                     gnus-newsgroup-reads))))
4846
4847           (when gnus-tmp-header
4848             ;; We may have an old dummy line to output before this
4849             ;; article.
4850             (when (and gnus-tmp-dummy-line
4851                        (gnus-subject-equal
4852                         gnus-tmp-dummy-line
4853                         (mail-header-subject gnus-tmp-header)))
4854               (gnus-summary-insert-dummy-line
4855                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4856               (setq gnus-tmp-dummy-line nil))
4857
4858             ;; Compute the mark.
4859             (setq gnus-tmp-unread (gnus-article-mark number))
4860
4861             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4862                                   gnus-tmp-header gnus-tmp-level)
4863                   gnus-newsgroup-data)
4864
4865             ;; Actually insert the line.
4866             (setq
4867              gnus-tmp-subject-or-nil
4868              (cond
4869               ((and gnus-thread-ignore-subject
4870                     gnus-tmp-prev-subject
4871                     (not (string= gnus-tmp-prev-subject simp-subject)))
4872                subject)
4873               ((zerop gnus-tmp-level)
4874                (if (and (eq gnus-summary-make-false-root 'empty)
4875                         (memq number gnus-tmp-gathered)
4876                         gnus-tmp-prev-subject
4877                         (string= gnus-tmp-prev-subject simp-subject))
4878                    gnus-summary-same-subject
4879                  subject))
4880               (t gnus-summary-same-subject)))
4881             (if (and (eq gnus-summary-make-false-root 'adopt)
4882                      (= gnus-tmp-level 1)
4883                      (memq number gnus-tmp-gathered))
4884                 (setq gnus-tmp-opening-bracket ?\<
4885                       gnus-tmp-closing-bracket ?\>)
4886               (setq gnus-tmp-opening-bracket ?\[
4887                     gnus-tmp-closing-bracket ?\]))
4888             (setq
4889              gnus-tmp-indentation
4890              (aref gnus-thread-indent-array gnus-tmp-level)
4891              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4892              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4893                                 gnus-summary-default-score 0)
4894              gnus-tmp-score-char
4895              (if (or (null gnus-summary-default-score)
4896                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4897                          gnus-summary-zcore-fuzz))
4898                  ?\ ;;;Whitespace
4899                (if (< gnus-tmp-score gnus-summary-default-score)
4900                    gnus-score-below-mark gnus-score-over-mark))
4901              gnus-tmp-replied
4902              (cond ((memq number gnus-newsgroup-processable)
4903                     gnus-process-mark)
4904                    ((memq number gnus-newsgroup-cached)
4905                     gnus-cached-mark)
4906                    ((memq number gnus-newsgroup-replied)
4907                     gnus-replied-mark)
4908                    ((memq number gnus-newsgroup-forwarded)
4909                     gnus-forwarded-mark)
4910                    ((memq number gnus-newsgroup-saved)
4911                     gnus-saved-mark)
4912                    ((memq number gnus-newsgroup-recent)
4913                     gnus-recent-mark)
4914                    ((memq number gnus-newsgroup-unseen)
4915                     gnus-unseen-mark)
4916                    (t gnus-no-mark))
4917              gnus-tmp-downloaded
4918              (cond ((memq number gnus-newsgroup-undownloaded)
4919                     gnus-undownloaded-mark)
4920                    (gnus-newsgroup-agentized
4921                     gnus-downloaded-mark)
4922                    (t
4923                     gnus-no-mark))
4924              gnus-tmp-from (mail-header-from gnus-tmp-header)
4925              gnus-tmp-name
4926              (cond
4927               ((string-match "<[^>]+> *$" gnus-tmp-from)
4928                (setq beg-match (match-beginning 0))
4929                (or (and (string-match "^\".+\"" gnus-tmp-from)
4930                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4931                    (substring gnus-tmp-from 0 beg-match)))
4932               ((string-match "(.+)" gnus-tmp-from)
4933                (substring gnus-tmp-from
4934                           (1+ (match-beginning 0)) (1- (match-end 0))))
4935               (t gnus-tmp-from))
4936
4937              ;; Do the %B string
4938              gnus-tmp-thread-tree-header-string
4939              (cond
4940               ((not gnus-show-threads) "")
4941               ((zerop gnus-tmp-level)
4942                (cond ((cdar thread)
4943                       (or gnus-sum-thread-tree-root subject))
4944                      (gnus-tmp-new-adopts
4945                       (or gnus-sum-thread-tree-false-root subject))
4946                      (t
4947                       (or gnus-sum-thread-tree-single-indent subject))))
4948               (t
4949                (concat (apply 'concat
4950                               (mapcar (lambda (item)
4951                                         (if (= item 1)
4952                                             gnus-sum-thread-tree-vertical
4953                                           gnus-sum-thread-tree-indent))
4954                                       (cdr (reverse tree-stack))))
4955                        (if (nth 1 thread)
4956                            gnus-sum-thread-tree-leaf-with-other
4957                          gnus-sum-thread-tree-single-leaf)))))
4958             (when (string= gnus-tmp-name "")
4959               (setq gnus-tmp-name gnus-tmp-from))
4960             (unless (numberp gnus-tmp-lines)
4961               (setq gnus-tmp-lines -1))
4962             (if (= gnus-tmp-lines -1)
4963                 (setq gnus-tmp-lines "?")
4964               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4965               (gnus-put-text-property
4966              (point)
4967              (progn (eval gnus-summary-line-format-spec) (point))
4968                'gnus-number number)
4969             (when gnus-visual-p
4970               (forward-line -1)
4971               (gnus-run-hooks 'gnus-summary-update-hook)
4972               (forward-line 1))
4973
4974             (setq gnus-tmp-prev-subject simp-subject)))
4975
4976         (when (nth 1 thread)
4977           (push (list (max 0 gnus-tmp-level)
4978                       (copy-sequence tree-stack)
4979                       (nthcdr 1 thread))
4980                 stack))
4981         (push (if (nth 1 thread) 1 0) tree-stack)
4982         (incf gnus-tmp-level)
4983         (setq threads (if thread-end nil (cdar thread)))
4984         (if gnus-summary-display-while-building
4985             (if building-count
4986                 (progn
4987                   ;; use a set frequency
4988                   (setq building-line-count (1- building-line-count))
4989                   (when (= building-line-count 0)
4990                     (sit-for 0)
4991                     (setq building-line-count
4992                           gnus-summary-display-while-building)))
4993               ;; always
4994               (sit-for 0)))
4995         (unless threads
4996           (setq gnus-tmp-level 0)))))
4997   (gnus-message 7 "Generating summary...done"))
4998
4999 (defun gnus-summary-prepare-unthreaded (headers)
5000   "Generate an unthreaded summary buffer based on HEADERS."
5001   (let (header number mark)
5002
5003     (beginning-of-line)
5004
5005     (while headers
5006       ;; We may have to root out some bad articles...
5007       (when (memq (setq number (mail-header-number
5008                                 (setq header (pop headers))))
5009                   gnus-newsgroup-limit)
5010         ;; Mark article as read when it has a low score.
5011         (when (and gnus-summary-mark-below
5012                    (< (or (cdr (assq number gnus-newsgroup-scored))
5013                           gnus-summary-default-score 0)
5014                       gnus-summary-mark-below)
5015                    (not (gnus-summary-article-ancient-p number)))
5016           (setq gnus-newsgroup-unreads
5017                 (delq number gnus-newsgroup-unreads))
5018           (if gnus-newsgroup-auto-expire
5019               (push number gnus-newsgroup-expirable)
5020             (push (cons number gnus-low-score-mark)
5021                   gnus-newsgroup-reads)))
5022
5023         (setq mark (gnus-article-mark number))
5024         (push (gnus-data-make number mark (1+ (point)) header 0)
5025               gnus-newsgroup-data)
5026         (gnus-summary-insert-line
5027          header 0 number
5028          (memq number gnus-newsgroup-undownloaded)
5029          mark (memq number gnus-newsgroup-replied)
5030          (memq number gnus-newsgroup-expirable)
5031          (mail-header-subject header) nil
5032          (cdr (assq number gnus-newsgroup-scored))
5033          (memq number gnus-newsgroup-processable))))))
5034
5035 (defun gnus-summary-remove-list-identifiers ()
5036   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5037   (let ((regexp (if (consp gnus-list-identifiers)
5038                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5039                   gnus-list-identifiers))
5040         changed subject)
5041     (when regexp
5042       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5043       (dolist (header gnus-newsgroup-headers)
5044         (setq subject (mail-header-subject header)
5045               changed nil)
5046         (while (string-match regexp subject)
5047           (setq subject
5048                 (concat (substring subject 0 (match-beginning 1))
5049                         (substring subject (match-end 0)))
5050                 changed t))
5051         (when changed
5052           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5053             (setq subject
5054                   (concat (substring subject 0 (match-beginning 1))
5055                           (substring subject (match-end 1)))))
5056           (mail-header-set-subject header subject))))))
5057
5058 (defun gnus-fetch-headers (articles)
5059   "Fetch headers of ARTICLES."
5060   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5061     (gnus-message 5 "Fetching headers for %s..." name)
5062     (prog1
5063         (if (eq 'nov
5064                 (setq gnus-headers-retrieved-by
5065                       (gnus-retrieve-headers
5066                        articles gnus-newsgroup-name
5067                        ;; We might want to fetch old headers, but
5068                        ;; not if there is only 1 article.
5069                        (and (or (and
5070                                  (not (eq gnus-fetch-old-headers 'some))
5071                                  (not (numberp gnus-fetch-old-headers)))
5072                                 (> (length articles) 1))
5073                             gnus-fetch-old-headers))))
5074             (gnus-get-newsgroup-headers-xover
5075              articles nil nil gnus-newsgroup-name t)
5076           (gnus-get-newsgroup-headers))
5077       (gnus-message 5 "Fetching headers for %s...done" name))))
5078
5079 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5080   "Select newsgroup GROUP.
5081 If READ-ALL is non-nil, all articles in the group are selected.
5082 If SELECT-ARTICLES, only select those articles from GROUP."
5083   (let* ((entry (gnus-group-entry group))
5084          ;;!!! Dirty hack; should be removed.
5085          (gnus-summary-ignore-duplicates
5086           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5087               t
5088             gnus-summary-ignore-duplicates))
5089          (info (nth 2 entry))
5090          articles fetched-articles cached)
5091
5092     (unless (gnus-check-server
5093              (set (make-local-variable 'gnus-current-select-method)
5094                   (gnus-find-method-for-group group)))
5095       (error "Couldn't open server"))
5096
5097     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5098         (gnus-activate-group group)     ; Or we can activate it...
5099         (progn                          ; Or we bug out.
5100           (when (equal major-mode 'gnus-summary-mode)
5101             (gnus-kill-buffer (current-buffer)))
5102           (error "Couldn't activate group %s: %s"
5103                  group (gnus-status-message group))))
5104
5105     (unless (gnus-request-group group t)
5106       (when (equal major-mode 'gnus-summary-mode)
5107         (gnus-kill-buffer (current-buffer)))
5108       (error "Couldn't request group %s: %s"
5109              group (gnus-status-message group)))
5110
5111     (when gnus-agent
5112       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5113       
5114       (setq gnus-summary-use-undownloaded-faces
5115             (gnus-agent-find-parameter
5116              group
5117              'agent-enable-undownloaded-faces)))
5118
5119     (setq gnus-newsgroup-name group
5120           gnus-newsgroup-unselected nil
5121           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5122
5123     (let ((display (gnus-group-find-parameter group 'display)))
5124       (setq gnus-newsgroup-display
5125             (cond
5126              ((not (zerop (or (car-safe read-all) 0)))
5127               ;; The user entered the group with C-u SPC/RET, let's show
5128               ;; all articles.
5129               'gnus-not-ignore)
5130              ((eq display 'all)
5131               'gnus-not-ignore)
5132              ((arrayp display)
5133               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5134              ((numberp display)
5135               ;; The following is probably the "correct" solution, but
5136               ;; it makes Gnus fetch all headers and then limit the
5137               ;; articles (which is slow), so instead we hack the
5138               ;; select-articles parameter instead. -- Simon Josefsson
5139               ;; <jas@kth.se>
5140               ;;
5141               ;; (gnus-byte-compile
5142               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5143               ;;                         display)))))
5144               (setq select-articles
5145                     (gnus-uncompress-range
5146                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5147                              (if (> tmp 0)
5148                                  tmp
5149                                1))
5150                            (cdr (gnus-active group)))))
5151               nil)
5152              (t
5153               nil))))
5154
5155     (gnus-summary-setup-default-charset)
5156
5157     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5158     (when (gnus-virtual-group-p group)
5159       (setq cached gnus-newsgroup-cached))
5160
5161     (setq gnus-newsgroup-unreads
5162           (gnus-sorted-ndifference
5163            (gnus-sorted-ndifference gnus-newsgroup-unreads
5164                                     gnus-newsgroup-marked)
5165            gnus-newsgroup-dormant))
5166
5167     (setq gnus-newsgroup-processable nil)
5168
5169     (gnus-update-read-articles group gnus-newsgroup-unreads)
5170
5171     ;; Adjust and set lists of article marks.
5172     (when info
5173       (gnus-adjust-marked-articles info))
5174     (if (setq articles select-articles)
5175         (setq gnus-newsgroup-unselected
5176               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5177       (setq articles (gnus-articles-to-read group read-all)))
5178
5179     (cond
5180      ((null articles)
5181       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5182       'quit)
5183      ((eq articles 0) nil)
5184      (t
5185       ;; Init the dependencies hash table.
5186       (setq gnus-newsgroup-dependencies
5187             (gnus-make-hashtable (length articles)))
5188       (gnus-set-global-variables)
5189       ;; Retrieve the headers and read them in.
5190
5191       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5192
5193       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5194       (when cached
5195         (setq gnus-newsgroup-cached cached))
5196
5197       ;; Suppress duplicates?
5198       (when gnus-suppress-duplicates
5199         (gnus-dup-suppress-articles))
5200
5201       ;; Set the initial limit.
5202       (setq gnus-newsgroup-limit (copy-sequence articles))
5203       ;; Remove canceled articles from the list of unread articles.
5204       (setq fetched-articles
5205             (mapcar (lambda (headers) (mail-header-number headers))
5206                     gnus-newsgroup-headers))
5207       (setq gnus-newsgroup-articles fetched-articles)
5208       (setq gnus-newsgroup-unreads
5209             (gnus-sorted-nintersection
5210              gnus-newsgroup-unreads fetched-articles))
5211       (gnus-compute-unseen-list)
5212
5213       ;; Removed marked articles that do not exist.
5214       (gnus-update-missing-marks
5215        (gnus-sorted-difference articles fetched-articles))
5216       ;; We might want to build some more threads first.
5217       (when (and gnus-fetch-old-headers
5218                  (eq gnus-headers-retrieved-by 'nov))
5219         (if (eq gnus-fetch-old-headers 'invisible)
5220             (gnus-build-all-threads)
5221           (gnus-build-old-threads)))
5222       ;; Let the Gnus agent mark articles as read.
5223       (when gnus-agent
5224         (gnus-agent-get-undownloaded-list))
5225       ;; Remove list identifiers from subject
5226       (when gnus-list-identifiers
5227         (gnus-summary-remove-list-identifiers))
5228       ;; Check whether auto-expire is to be done in this group.
5229       (setq gnus-newsgroup-auto-expire
5230             (gnus-group-auto-expirable-p group))
5231       ;; Set up the article buffer now, if necessary.
5232       (unless gnus-single-article-buffer
5233         (gnus-article-setup-buffer))
5234       ;; First and last article in this newsgroup.
5235       (when gnus-newsgroup-headers
5236         (setq gnus-newsgroup-begin
5237               (mail-header-number (car gnus-newsgroup-headers))
5238               gnus-newsgroup-end
5239               (mail-header-number
5240                (gnus-last-element gnus-newsgroup-headers))))
5241       ;; GROUP is successfully selected.
5242       (or gnus-newsgroup-headers t)))))
5243
5244 (defun gnus-compute-unseen-list ()
5245   ;; The `seen' marks are treated specially.
5246   (if (not gnus-newsgroup-seen)
5247       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5248     (setq gnus-newsgroup-unseen
5249           (gnus-inverse-list-range-intersection
5250            gnus-newsgroup-articles gnus-newsgroup-seen))))
5251
5252 (defun gnus-summary-display-make-predicate (display)
5253   (require 'gnus-agent)
5254   (when (= (length display) 1)
5255     (setq display (car display)))
5256   (unless gnus-summary-display-cache
5257     (dolist (elem (append '((unread . unread)
5258                             (read . read)
5259                             (unseen . unseen))
5260                           gnus-article-mark-lists))
5261       (push (cons (cdr elem)
5262                   (gnus-byte-compile
5263                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5264             gnus-summary-display-cache)))
5265   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5266         (gnus-category-predicate-cache gnus-summary-display-cache))
5267     (gnus-get-predicate display)))
5268
5269 ;; Uses the dynamically bound `number' variable.
5270 (eval-when-compile
5271   (defvar number))
5272 (defun gnus-article-marked-p (type &optional article)
5273   (let ((article (or article number)))
5274     (cond
5275      ((eq type 'tick)
5276       (memq article gnus-newsgroup-marked))
5277      ((eq type 'spam)
5278       (memq article gnus-newsgroup-spam-marked))
5279      ((eq type 'unsend)
5280       (memq article gnus-newsgroup-unsendable))
5281      ((eq type 'undownload)
5282       (memq article gnus-newsgroup-undownloaded))
5283      ((eq type 'download)
5284       (memq article gnus-newsgroup-downloadable))
5285      ((eq type 'unread)
5286       (memq article gnus-newsgroup-unreads))
5287      ((eq type 'read)
5288       (memq article gnus-newsgroup-reads))
5289      ((eq type 'dormant)
5290       (memq article gnus-newsgroup-dormant) )
5291      ((eq type 'expire)
5292       (memq article gnus-newsgroup-expirable))
5293      ((eq type 'reply)
5294       (memq article gnus-newsgroup-replied))
5295      ((eq type 'killed)
5296       (memq article gnus-newsgroup-killed))
5297      ((eq type 'bookmark)
5298       (assq article gnus-newsgroup-bookmarks))
5299      ((eq type 'score)
5300       (assq article gnus-newsgroup-scored))
5301      ((eq type 'save)
5302       (memq article gnus-newsgroup-saved))
5303      ((eq type 'cache)
5304       (memq article gnus-newsgroup-cached))
5305      ((eq type 'forward)
5306       (memq article gnus-newsgroup-forwarded))
5307      ((eq type 'seen)
5308       (not (memq article gnus-newsgroup-unseen)))
5309      ((eq type 'recent)
5310       (memq article gnus-newsgroup-recent))
5311      (t t))))
5312
5313 (defun gnus-articles-to-read (group &optional read-all)
5314   "Find out what articles the user wants to read."
5315   (let* ((articles
5316           ;; Select all articles if `read-all' is non-nil, or if there
5317           ;; are no unread articles.
5318           (if (or read-all
5319                   (and (zerop (length gnus-newsgroup-marked))
5320                        (zerop (length gnus-newsgroup-unreads)))
5321                   ;; Fetch all if the predicate is non-nil.
5322                   gnus-newsgroup-display)
5323               ;; We want to select the headers for all the articles in
5324               ;; the group, so we select either all the active
5325               ;; articles in the group, or (if that's nil), the
5326               ;; articles in the cache.
5327               (or
5328                (gnus-uncompress-range (gnus-active group))
5329                (gnus-cache-articles-in-group group))
5330             ;; Select only the "normal" subset of articles.
5331             (gnus-sorted-nunion
5332              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5333              gnus-newsgroup-unreads)))
5334          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5335          (scored (length scored-list))
5336          (number (length articles))
5337          (marked (+ (length gnus-newsgroup-marked)
5338                     (length gnus-newsgroup-dormant)))
5339          (select
5340           (cond
5341            ((numberp read-all)
5342             read-all)
5343            ((numberp gnus-newsgroup-display)
5344             gnus-newsgroup-display)
5345            (t
5346             (condition-case ()
5347                 (cond
5348                  ((and (or (<= scored marked) (= scored number))
5349                        (numberp gnus-large-newsgroup)
5350                        (> number gnus-large-newsgroup))
5351                   (let* ((cursor-in-echo-area nil)
5352                          (initial (gnus-parameter-large-newsgroup-initial
5353                                    gnus-newsgroup-name))
5354                          (input
5355                           (read-string
5356                            (format
5357                             "How many articles from %s (%s %d): "
5358                             (gnus-limit-string
5359                              (gnus-group-decoded-name gnus-newsgroup-name)
5360                              35)
5361                             (if initial "max" "default")
5362                             number)
5363                            (if initial
5364                                (cons (number-to-string initial)
5365                                      0)))))
5366                     (if (string-match "^[ \t]*$" input) number input)))
5367                  ((and (> scored marked) (< scored number)
5368                        (> (- scored number) 20))
5369                   (let ((input
5370                          (read-string
5371                           (format "%s %s (%d scored, %d total): "
5372                                   "How many articles from"
5373                                   (gnus-group-decoded-name group)
5374                                   scored number))))
5375                     (if (string-match "^[ \t]*$" input)
5376                         number input)))
5377                  (t number))
5378               (quit
5379                (message "Quit getting the articles to read")
5380                nil))))))
5381     (setq select (if (stringp select) (string-to-number select) select))
5382     (if (or (null select) (zerop select))
5383         select
5384       (if (and (not (zerop scored)) (<= (abs select) scored))
5385           (progn
5386             (setq articles (sort scored-list '<))
5387             (setq number (length articles)))
5388         (setq articles (copy-sequence articles)))
5389
5390       (when (< (abs select) number)
5391         (if (< select 0)
5392             ;; Select the N oldest articles.
5393             (setcdr (nthcdr (1- (abs select)) articles) nil)
5394           ;; Select the N most recent articles.
5395           (setq articles (nthcdr (- number select) articles))))
5396       (setq gnus-newsgroup-unselected
5397             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5398       (when gnus-alter-articles-to-read-function
5399         (setq articles
5400               (sort
5401                (funcall gnus-alter-articles-to-read-function
5402                         gnus-newsgroup-name articles)
5403                '<)))
5404       articles)))
5405
5406 (defun gnus-killed-articles (killed articles)
5407   (let (out)
5408     (while articles
5409       (when (inline (gnus-member-of-range (car articles) killed))
5410         (push (car articles) out))
5411       (setq articles (cdr articles)))
5412     out))
5413
5414 (defun gnus-uncompress-marks (marks)
5415   "Uncompress the mark ranges in MARKS."
5416   (let ((uncompressed '(score bookmark))
5417         out)
5418     (while marks
5419       (if (memq (caar marks) uncompressed)
5420           (push (car marks) out)
5421         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5422       (setq marks (cdr marks)))
5423     out))
5424
5425 (defun gnus-article-mark-to-type (mark)
5426   "Return the type of MARK."
5427   (or (cadr (assq mark gnus-article-special-mark-lists))
5428       'list))
5429
5430 (defun gnus-article-unpropagatable-p (mark)
5431   "Return whether MARK should be propagated to back end."
5432   (memq mark gnus-article-unpropagated-mark-lists))
5433
5434 (defun gnus-adjust-marked-articles (info)
5435   "Set all article lists and remove all marks that are no longer valid."
5436   (let* ((marked-lists (gnus-info-marks info))
5437          (active (gnus-active (gnus-info-group info)))
5438          (min (car active))
5439          (max (cdr active))
5440          (types gnus-article-mark-lists)
5441          marks var articles article mark mark-type
5442          bgn end)
5443
5444     (dolist (marks marked-lists)
5445       (setq mark (car marks)
5446             mark-type (gnus-article-mark-to-type mark)
5447             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5448
5449       ;; We set the variable according to the type of the marks list,
5450       ;; and then adjust the marks to a subset of the active articles.
5451       (cond
5452        ;; Adjust "simple" lists - compressed yet unsorted
5453        ((eq mark-type 'list)
5454         ;; Simultaneously uncompress and clip to active range
5455         ;; See gnus-uncompress-range for a description of possible marks
5456         (let (l lh)
5457           (if (not (cadr marks))
5458               (set var nil)
5459             (setq articles (if (numberp (cddr marks))
5460                                (list (cdr marks))
5461                              (cdr marks))
5462                   lh (cons nil nil)
5463                   l lh)
5464
5465             (while (setq article (pop articles))
5466               (cond ((consp article)
5467                      (setq bgn (max (car article) min)
5468                            end (min (cdr article) max))
5469                      (while (<= bgn end)
5470                        (setq l (setcdr l (cons bgn nil))
5471                              bgn (1+ bgn))))
5472                     ((and (<= min article)
5473                           (>= max article))
5474                      (setq l (setcdr l (cons article nil))))))
5475             (set var (cdr lh)))))
5476        ;; Adjust assocs.
5477        ((eq mark-type 'tuple)
5478         (set var (setq articles (cdr marks)))
5479         (when (not (listp (cdr (symbol-value var))))
5480           (set var (list (symbol-value var))))
5481         (when (not (listp (cdr articles)))
5482           (setq articles (list articles)))
5483         (while articles
5484           (when (or (not (consp (setq article (pop articles))))
5485                     (< (car article) min)
5486                     (> (car article) max))
5487             (set var (delq article (symbol-value var))))))
5488        ;; Adjust ranges (sloppily).
5489        ((eq mark-type 'range)
5490         (cond
5491          ((eq mark 'seen)
5492           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5493           ;; It should be (seen (NUM1 . NUM2)).
5494           (when (numberp (cddr marks))
5495             (setcdr marks (list (cdr marks))))
5496           (setq articles (cdr marks))
5497           (while (and articles
5498                       (or (and (consp (car articles))
5499                                (> min (cdar articles)))
5500                           (and (numberp (car articles))
5501                                (> min (car articles)))))
5502             (pop articles))
5503           (set var articles))))))))
5504
5505 (defun gnus-update-missing-marks (missing)
5506   "Go through the list of MISSING articles and remove them from the mark lists."
5507   (when missing
5508     (let (var m)
5509       ;; Go through all types.
5510       (dolist (elem gnus-article-mark-lists)
5511         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5512           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5513           (when (symbol-value var)
5514             ;; This list has articles.  So we delete all missing
5515             ;; articles from it.
5516             (setq m missing)
5517             (while m
5518               (set var (delq (pop m) (symbol-value var))))))))))
5519
5520 (defun gnus-update-marks ()
5521   "Enter the various lists of marked articles into the newsgroup info list."
5522   (let ((types gnus-article-mark-lists)
5523         (info (gnus-get-info gnus-newsgroup-name))
5524         type list newmarked symbol delta-marks)
5525     (when info
5526       ;; Add all marks lists to the list of marks lists.
5527       (while (setq type (pop types))
5528         (setq list (symbol-value
5529                     (setq symbol
5530                           (intern (format "gnus-newsgroup-%s" (car type))))))
5531
5532         (when list
5533           ;; Get rid of the entries of the articles that have the
5534           ;; default score.
5535           (when (and (eq (cdr type) 'score)
5536                      gnus-save-score
5537                      list)
5538             (let* ((arts list)
5539                    (prev (cons nil list))
5540                    (all prev))
5541               (while arts
5542                 (if (or (not (consp (car arts)))
5543                         (= (cdar arts) gnus-summary-default-score))
5544                     (setcdr prev (cdr arts))
5545                   (setq prev arts))
5546                 (setq arts (cdr arts)))
5547               (setq list (cdr all)))))
5548
5549         (when (eq (cdr type) 'seen)
5550           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5551
5552         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5553           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5554
5555         (when (and (gnus-check-backend-function
5556                     'request-set-mark gnus-newsgroup-name)
5557                    (not (gnus-article-unpropagatable-p (cdr type))))
5558           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5559                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5560                  (add (gnus-remove-from-range
5561                        (gnus-copy-sequence list) old)))
5562             (when add
5563               (push (list add 'add (list (cdr type))) delta-marks))
5564             (when del
5565               (push (list del 'del (list (cdr type))) delta-marks))))
5566
5567         (when list
5568           (push (cons (cdr type) list) newmarked)))
5569
5570       (when delta-marks
5571         (unless (gnus-check-group gnus-newsgroup-name)
5572           (error "Can't open server for %s" gnus-newsgroup-name))
5573         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5574
5575       ;; Enter these new marks into the info of the group.
5576       (if (nthcdr 3 info)
5577           (setcar (nthcdr 3 info) newmarked)
5578         ;; Add the marks lists to the end of the info.
5579         (when newmarked
5580           (setcdr (nthcdr 2 info) (list newmarked))))
5581
5582       ;; Cut off the end of the info if there's nothing else there.
5583       (let ((i 5))
5584         (while (and (> i 2)
5585                     (not (nth i info)))
5586           (when (nthcdr (decf i) info)
5587             (setcdr (nthcdr i info) nil)))))))
5588
5589 (defun gnus-set-mode-line (where)
5590   "Set the mode line of the article or summary buffers.
5591 If WHERE is `summary', the summary mode line format will be used."
5592   ;; Is this mode line one we keep updated?
5593   (when (and (memq where gnus-updated-mode-lines)
5594              (symbol-value
5595               (intern (format "gnus-%s-mode-line-format-spec" where))))
5596     (let (mode-string)
5597       (save-excursion
5598         ;; We evaluate this in the summary buffer since these
5599         ;; variables are buffer-local to that buffer.
5600         (set-buffer gnus-summary-buffer)
5601         ;; We bind all these variables that are used in the `eval' form
5602         ;; below.
5603         (let* ((mformat (symbol-value
5604                          (intern
5605                           (format "gnus-%s-mode-line-format-spec" where))))
5606                (gnus-tmp-group-name (gnus-group-decoded-name
5607                                      gnus-newsgroup-name))
5608                (gnus-tmp-article-number (or gnus-current-article 0))
5609                (gnus-tmp-unread gnus-newsgroup-unreads)
5610                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5611                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5612                (gnus-tmp-unread-and-unselected
5613                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5614                             (zerop gnus-tmp-unselected))
5615                        "")
5616                       ((zerop gnus-tmp-unselected)
5617                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5618                       (t (format "{%d(+%d) more}"
5619                                  gnus-tmp-unread-and-unticked
5620                                  gnus-tmp-unselected))))
5621                (gnus-tmp-subject
5622                 (if (and gnus-current-headers
5623                          (vectorp gnus-current-headers))
5624                     (gnus-mode-string-quote
5625                      (mail-header-subject gnus-current-headers))
5626                   ""))
5627                bufname-length max-len
5628                gnus-tmp-header);; passed as argument to any user-format-funcs
5629           (setq mode-string (eval mformat))
5630           (setq bufname-length (if (string-match "%b" mode-string)
5631                                    (- (length
5632                                        (buffer-name
5633                                         (if (eq where 'summary)
5634                                             nil
5635                                           (get-buffer gnus-article-buffer))))
5636                                       2)
5637                                  0))
5638           (setq max-len (max 4 (if gnus-mode-non-string-length
5639                                    (- (window-width)
5640                                       gnus-mode-non-string-length
5641                                       bufname-length)
5642                                  (length mode-string))))
5643           ;; We might have to chop a bit of the string off...
5644           (when (> (length mode-string) max-len)
5645             (setq mode-string
5646                   (concat (gnus-truncate-string mode-string (- max-len 3))
5647                           "...")))
5648           ;; Pad the mode string a bit.
5649           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5650       ;; Update the mode line.
5651       (setq mode-line-buffer-identification
5652             (gnus-mode-line-buffer-identification (list mode-string)))
5653       (set-buffer-modified-p t))))
5654
5655 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5656   "Go through the HEADERS list and add all Xrefs to a hash table.
5657 The resulting hash table is returned, or nil if no Xrefs were found."
5658   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5659          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5660          (xref-hashtb (gnus-make-hashtable))
5661          start group entry number xrefs header)
5662     (while headers
5663       (setq header (pop headers))
5664       (when (and (setq xrefs (mail-header-xref header))
5665                  (not (memq (setq number (mail-header-number header))
5666                             unreads)))
5667         (setq start 0)
5668         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5669           (setq start (match-end 0))
5670           (setq group (if prefix
5671                           (concat prefix (substring xrefs (match-beginning 1)
5672                                                     (match-end 1)))
5673                         (substring xrefs (match-beginning 1) (match-end 1))))
5674           (setq number
5675                 (string-to-int (substring xrefs (match-beginning 2)
5676                                           (match-end 2))))
5677           (if (setq entry (gnus-gethash group xref-hashtb))
5678               (setcdr entry (cons number (cdr entry)))
5679             (gnus-sethash group (cons number nil) xref-hashtb)))))
5680     (and start xref-hashtb)))
5681
5682 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5683   "Look through all the headers and mark the Xrefs as read."
5684   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5685         name info xref-hashtb idlist method nth4)
5686     (save-excursion
5687       (set-buffer gnus-group-buffer)
5688       (when (setq xref-hashtb
5689                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5690         (mapatoms
5691          (lambda (group)
5692            (unless (string= from-newsgroup (setq name (symbol-name group)))
5693              (setq idlist (symbol-value group))
5694              ;; Dead groups are not updated.
5695              (and (prog1
5696                       (setq info (gnus-get-info name))
5697                     (when (stringp (setq nth4 (gnus-info-method info)))
5698                       (setq nth4 (gnus-server-to-method nth4))))
5699                   ;; Only do the xrefs if the group has the same
5700                   ;; select method as the group we have just read.
5701                   (or (gnus-methods-equal-p
5702                        nth4 (gnus-find-method-for-group from-newsgroup))
5703                       virtual
5704                       (equal nth4 (setq method (gnus-find-method-for-group
5705                                                 from-newsgroup)))
5706                       (and (equal (car nth4) (car method))
5707                            (equal (nth 1 nth4) (nth 1 method))))
5708                   gnus-use-cross-reference
5709                   (or (not (eq gnus-use-cross-reference t))
5710                       virtual
5711                       ;; Only do cross-references on subscribed
5712                       ;; groups, if that is what is wanted.
5713                       (<= (gnus-info-level info) gnus-level-subscribed))
5714                   (gnus-group-make-articles-read name idlist))))
5715          xref-hashtb)))))
5716
5717 (defun gnus-compute-read-articles (group articles)
5718   (let* ((entry (gnus-group-entry group))
5719          (info (nth 2 entry))
5720          (active (gnus-active group))
5721          ninfo)
5722     (when entry
5723       ;; First peel off all invalid article numbers.
5724       (when active
5725         (let ((ids articles)
5726               id first)
5727           (while (setq id (pop ids))
5728             (when (and first (> id (cdr active)))
5729               ;; We'll end up in this situation in one particular
5730               ;; obscure situation.  If you re-scan a group and get
5731               ;; a new article that is cross-posted to a different
5732               ;; group that has not been re-scanned, you might get
5733               ;; crossposted article that has a higher number than
5734               ;; Gnus believes possible.  So we re-activate this
5735               ;; group as well.  This might mean doing the
5736               ;; crossposting thingy will *increase* the number
5737               ;; of articles in some groups.  Tsk, tsk.
5738               (setq active (or (gnus-activate-group group) active)))
5739             (when (or (> id (cdr active))
5740                       (< id (car active)))
5741               (setq articles (delq id articles))))))
5742       ;; If the read list is nil, we init it.
5743       (if (and active
5744                (null (gnus-info-read info))
5745                (> (car active) 1))
5746           (setq ninfo (cons 1 (1- (car active))))
5747         (setq ninfo (gnus-info-read info)))
5748       ;; Then we add the read articles to the range.
5749       (gnus-add-to-range
5750        ninfo (setq articles (sort articles '<))))))
5751
5752 (defun gnus-group-make-articles-read (group articles)
5753   "Update the info of GROUP to say that ARTICLES are read."
5754   (let* ((num 0)
5755          (entry (gnus-group-entry group))
5756          (info (nth 2 entry))
5757          (active (gnus-active group))
5758          range)
5759     (when entry
5760       (setq range (gnus-compute-read-articles group articles))
5761       (with-current-buffer gnus-group-buffer
5762         (gnus-undo-register
5763           `(progn
5764              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5765              (gnus-info-set-read ',info ',(gnus-info-read info))
5766              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5767              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5768              (gnus-group-update-group ,group t))))
5769       ;; Add the read articles to the range.
5770       (gnus-info-set-read info range)
5771       (gnus-request-set-mark group (list (list range 'add '(read))))
5772       ;; Then we have to re-compute how many unread
5773       ;; articles there are in this group.
5774       (when active
5775         (cond
5776          ((not range)
5777           (setq num (- (1+ (cdr active)) (car active))))
5778          ((not (listp (cdr range)))
5779           (setq num (- (cdr active) (- (1+ (cdr range))
5780                                        (car range)))))
5781          (t
5782           (while range
5783             (if (numberp (car range))
5784                 (setq num (1+ num))
5785               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5786             (setq range (cdr range)))
5787           (setq num (- (cdr active) num))))
5788         ;; Update the number of unread articles.
5789         (setcar entry num)
5790         ;; Update the group buffer.
5791         (unless (gnus-ephemeral-group-p group)
5792           (gnus-group-update-group group t))))))
5793
5794 (defvar gnus-newsgroup-none-id 0)
5795
5796 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5797   (let ((cur nntp-server-buffer)
5798         (dependencies
5799          (or dependencies
5800              (with-current-buffer gnus-summary-buffer
5801                gnus-newsgroup-dependencies)))
5802         headers id end ref number
5803         (mail-parse-charset gnus-newsgroup-charset)
5804         (mail-parse-ignored-charsets
5805          (save-excursion (condition-case nil
5806                              (set-buffer gnus-summary-buffer)
5807                            (error))
5808                          gnus-newsgroup-ignored-charsets)))
5809     (save-excursion
5810       (set-buffer nntp-server-buffer)
5811       ;; Translate all TAB characters into SPACE characters.
5812       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5813       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5814       (ietf-drums-unfold-fws)
5815       (gnus-run-hooks 'gnus-parse-headers-hook)
5816       (let ((case-fold-search t)
5817             in-reply-to header p lines chars ctype)
5818         (goto-char (point-min))
5819         ;; Search to the beginning of the next header.  Error messages
5820         ;; do not begin with 2 or 3.
5821         (while (re-search-forward "^[23][0-9]+ " nil t)
5822           (setq id nil
5823                 ref nil)
5824           ;; This implementation of this function, with nine
5825           ;; search-forwards instead of the one re-search-forward and
5826           ;; a case (which basically was the old function) is actually
5827           ;; about twice as fast, even though it looks messier.  You
5828           ;; can't have everything, I guess.  Speed and elegance
5829           ;; doesn't always go hand in hand.
5830           (setq
5831            header
5832            (make-full-mail-header
5833             ;; Number.
5834             (prog1
5835                 (setq number (read cur))
5836               (end-of-line)
5837               (setq p (point))
5838               (narrow-to-region (point)
5839                                 (or (and (search-forward "\n.\n" nil t)
5840                                          (- (point) 2))
5841                                     (point))))
5842             ;; Subject.
5843             (progn
5844               (goto-char p)
5845               (if (search-forward "\nsubject:" nil t)
5846                   (nnheader-header-value)
5847                 "(none)"))
5848             ;; From.
5849             (progn
5850               (goto-char p)
5851               (if (search-forward "\nfrom:" nil t)
5852                   (nnheader-header-value)
5853                 "(nobody)"))
5854             ;; Date.
5855             (progn
5856               (goto-char p)
5857               (if (search-forward "\ndate:" nil t)
5858                   (nnheader-header-value) ""))
5859             ;; Message-ID.
5860             (progn
5861               (goto-char p)
5862               (setq id (if (re-search-forward
5863                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5864                            ;; We do it this way to make sure the Message-ID
5865                            ;; is (somewhat) syntactically valid.
5866                            (buffer-substring (match-beginning 1)
5867                                              (match-end 1))
5868                          ;; If there was no message-id, we just fake one
5869                          ;; to make subsequent routines simpler.
5870                          (nnheader-generate-fake-message-id number))))
5871             ;; References.
5872             (progn
5873               (goto-char p)
5874               (if (search-forward "\nreferences:" nil t)
5875                   (progn
5876                     (setq end (point))
5877                     (prog1
5878                         (nnheader-header-value)
5879                       (setq ref
5880                             (buffer-substring
5881                              (progn
5882                                ;; (end-of-line)
5883                                (search-backward ">" end t)
5884                                (1+ (point)))
5885                              (progn
5886                                (search-backward "<" end t)
5887                                (point))))))
5888                 ;; Get the references from the in-reply-to header if there
5889                 ;; were no references and the in-reply-to header looks
5890                 ;; promising.
5891                 (if (and (search-forward "\nin-reply-to:" nil t)
5892                          (setq in-reply-to (nnheader-header-value))
5893                          (string-match "<[^>]+>" in-reply-to))
5894                     (let (ref2)
5895                       (setq ref (substring in-reply-to (match-beginning 0)
5896                                            (match-end 0)))
5897                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5898                         (setq ref2 (substring in-reply-to (match-beginning 0)
5899                                               (match-end 0)))
5900                         (when (> (length ref2) (length ref))
5901                           (setq ref ref2)))
5902                       ref)
5903                   (setq ref nil))))
5904             ;; Chars.
5905             (progn
5906               (goto-char p)
5907               (if (search-forward "\nchars: " nil t)
5908                   (if (numberp (setq chars (ignore-errors (read cur))))
5909                       chars -1)
5910                 -1))
5911             ;; Lines.
5912             (progn
5913               (goto-char p)
5914               (if (search-forward "\nlines: " nil t)
5915                   (if (numberp (setq lines (ignore-errors (read cur))))
5916                       lines -1)
5917                 -1))
5918             ;; Xref.
5919             (progn
5920               (goto-char p)
5921               (and (search-forward "\nxref:" nil t)
5922                    (nnheader-header-value)))
5923             ;; Extra.
5924             (when gnus-extra-headers
5925               (let ((extra gnus-extra-headers)
5926                     out)
5927                 (while extra
5928                   (goto-char p)
5929                   (when (search-forward
5930                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5931                     (push (cons (car extra) (nnheader-header-value)) out))
5932                   (pop extra))
5933                 out))))
5934           (goto-char p)
5935           (if (and (search-forward "\ncontent-type: " nil t)
5936                    (setq ctype (nnheader-header-value)))
5937               (mime-entity-set-content-type-internal
5938                header (mime-parse-Content-Type ctype)))
5939           (when (equal id ref)
5940             (setq ref nil))
5941
5942           (when gnus-alter-header-function
5943             (funcall gnus-alter-header-function header)
5944             (setq id (mail-header-id header)
5945                   ref (gnus-parent-id (mail-header-references header))))
5946
5947           (when (setq header
5948                       (gnus-dependencies-add-header
5949                        header dependencies force-new))
5950             (push header headers))
5951           (goto-char (point-max))
5952           (widen))
5953         (nreverse headers)))))
5954
5955 ;; Goes through the xover lines and returns a list of vectors
5956 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5957                                                   force-new dependencies
5958                                                   group also-fetch-heads)
5959   "Parse the news overview data in the server buffer.
5960 Return a list of headers that match SEQUENCE (see
5961 `nntp-retrieve-headers')."
5962   ;; Get the Xref when the users reads the articles since most/some
5963   ;; NNTP servers do not include Xrefs when using XOVER.
5964   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5965   (let ((mail-parse-charset gnus-newsgroup-charset)
5966         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5967         (cur nntp-server-buffer)
5968         (dependencies (or dependencies gnus-newsgroup-dependencies))
5969         (allp (cond
5970                ((eq gnus-read-all-available-headers t)
5971                 t)
5972                ((stringp gnus-read-all-available-headers)
5973                 (string-match gnus-read-all-available-headers group))
5974                (t
5975                 nil)))
5976         number headers header)
5977     (save-excursion
5978       (set-buffer nntp-server-buffer)
5979       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5980       ;; Allow the user to mangle the headers before parsing them.
5981       (gnus-run-hooks 'gnus-parse-headers-hook)
5982       (goto-char (point-min))
5983       (gnus-parse-without-error
5984         (while (and (or sequence allp)
5985                     (not (eobp)))
5986           (setq number (read cur))
5987           (when (not allp)
5988             (while (and sequence
5989                         (< (car sequence) number))
5990               (setq sequence (cdr sequence))))
5991           (when (and (or allp
5992                          (and sequence
5993                               (eq number (car sequence))))
5994                      (progn
5995                        (setq sequence (cdr sequence))
5996                        (setq header (inline
5997                                       (gnus-nov-parse-line
5998                                        number dependencies force-new)))))
5999             (push header headers))
6000           (forward-line 1)))
6001       ;; A common bug in inn is that if you have posted an article and
6002       ;; then retrieves the active file, it will answer correctly --
6003       ;; the new article is included.  However, a NOV entry for the
6004       ;; article may not have been generated yet, so this may fail.
6005       ;; We work around this problem by retrieving the last few
6006       ;; headers using HEAD.
6007       (if (or (not also-fetch-heads)
6008               (not sequence))
6009           ;; We (probably) got all the headers.
6010           (nreverse headers)
6011         (let ((gnus-nov-is-evil t))
6012           (nconc
6013            (nreverse headers)
6014            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6015              (gnus-get-newsgroup-headers))))))))
6016
6017 (defun gnus-article-get-xrefs ()
6018   "Fill in the Xref value in `gnus-current-headers', if necessary.
6019 This is meant to be called in `gnus-article-internal-prepare-hook'."
6020   (let ((headers (with-current-buffer gnus-summary-buffer
6021                    gnus-current-headers)))
6022     (or (not gnus-use-cross-reference)
6023         (not headers)
6024         (and (mail-header-xref headers)
6025              (not (string= (mail-header-xref headers) "")))
6026         (let ((case-fold-search t)
6027               xref)
6028           (save-restriction
6029             (nnheader-narrow-to-headers)
6030             (goto-char (point-min))
6031             (when (or (and (not (eobp))
6032                            (eq (downcase (char-after)) ?x)
6033                            (looking-at "Xref:"))
6034                       (search-forward "\nXref:" nil t))
6035               (goto-char (1+ (match-end 0)))
6036               (setq xref (buffer-substring (point) (point-at-eol)))
6037               (mail-header-set-xref headers xref)))))))
6038
6039 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6040   "Find article ID and insert the summary line for that article.
6041 OLD-HEADER can either be a header or a line number to insert
6042 the subject line on."
6043   (let* ((line (and (numberp old-header) old-header))
6044          (old-header (and (vectorp old-header) old-header))
6045          (header (cond ((and old-header use-old-header)
6046                         old-header)
6047                        ((and (numberp id)
6048                              (gnus-number-to-header id))
6049                         (gnus-number-to-header id))
6050                        (t
6051                         (gnus-read-header id))))
6052          (number (and (numberp id) id))
6053          d)
6054     (when header
6055       ;; Rebuild the thread that this article is part of and go to the
6056       ;; article we have fetched.
6057       (when (and (not gnus-show-threads)
6058                  old-header)
6059         (when (and number
6060                    (setq d (gnus-data-find (mail-header-number old-header))))
6061           (goto-char (gnus-data-pos d))
6062           (gnus-data-remove
6063            number
6064            (- (point-at-bol)
6065               (prog1
6066                   (1+ (point-at-eol))
6067                 (gnus-delete-line))))))
6068       ;; Remove list identifiers from subject.
6069       (when gnus-list-identifiers
6070         (let ((gnus-newsgroup-headers (list header)))
6071           (gnus-summary-remove-list-identifiers)))
6072       (when old-header
6073         (mail-header-set-number header (mail-header-number old-header)))
6074       (setq gnus-newsgroup-sparse
6075             (delq (setq number (mail-header-number header))
6076                   gnus-newsgroup-sparse))
6077       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6078       (push number gnus-newsgroup-limit)
6079       (gnus-rebuild-thread (mail-header-id header) line)
6080       (gnus-summary-goto-subject number nil t))
6081     (when (and (numberp number)
6082                (> number 0))
6083       ;; We have to update the boundaries even if we can't fetch the
6084       ;; article if ID is a number -- so that the next `P' or `N'
6085       ;; command will fetch the previous (or next) article even
6086       ;; if the one we tried to fetch this time has been canceled.
6087       (when (> number gnus-newsgroup-end)
6088         (setq gnus-newsgroup-end number))
6089       (when (< number gnus-newsgroup-begin)
6090         (setq gnus-newsgroup-begin number))
6091       (setq gnus-newsgroup-unselected
6092             (delq number gnus-newsgroup-unselected)))
6093     ;; Report back a success?
6094     (and header (mail-header-number header))))
6095
6096 ;;; Process/prefix in the summary buffer
6097
6098 (defun gnus-summary-work-articles (n)
6099   "Return a list of articles to be worked upon.
6100 The prefix argument, the list of process marked articles, and the
6101 current article will be taken into consideration."
6102   (save-excursion
6103     (set-buffer gnus-summary-buffer)
6104     (cond
6105      (n
6106       ;; A numerical prefix has been given.
6107       (setq n (prefix-numeric-value n))
6108       (let ((backward (< n 0))
6109             (n (abs (prefix-numeric-value n)))
6110             articles article)
6111         (save-excursion
6112           (while
6113               (and (> n 0)
6114                    (push (setq article (gnus-summary-article-number))
6115                          articles)
6116                    (if backward
6117                        (gnus-summary-find-prev nil article)
6118                      (gnus-summary-find-next nil article)))
6119             (decf n)))
6120         (nreverse articles)))
6121      ((and (gnus-region-active-p) (mark))
6122       (message "region active")
6123       ;; Work on the region between point and mark.
6124       (let ((max (max (point) (mark)))
6125             articles article)
6126         (save-excursion
6127           (goto-char (min (point) (mark)))
6128           (while
6129               (and
6130                (push (setq article (gnus-summary-article-number)) articles)
6131                (gnus-summary-find-next nil article)
6132                (< (point) max)))
6133           (nreverse articles))))
6134      (gnus-newsgroup-processable
6135       ;; There are process-marked articles present.
6136       ;; Save current state.
6137       (gnus-summary-save-process-mark)
6138       ;; Return the list.
6139       (reverse gnus-newsgroup-processable))
6140      (t
6141       ;; Just return the current article.
6142       (list (gnus-summary-article-number))))))
6143
6144 (defmacro gnus-summary-iterate (arg &rest forms)
6145   "Iterate over the process/prefixed articles and do FORMS.
6146 ARG is the interactive prefix given to the command.  FORMS will be
6147 executed with point over the summary line of the articles."
6148   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6149     `(let ((,articles (gnus-summary-work-articles ,arg)))
6150        (while ,articles
6151          (gnus-summary-goto-subject (car ,articles))
6152          ,@forms
6153          (pop ,articles)))))
6154
6155 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6156 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6157
6158 (defun gnus-summary-save-process-mark ()
6159   "Push the current set of process marked articles on the stack."
6160   (interactive)
6161   (push (copy-sequence gnus-newsgroup-processable)
6162         gnus-newsgroup-process-stack))
6163
6164 (defun gnus-summary-kill-process-mark ()
6165   "Push the current set of process marked articles on the stack and unmark."
6166   (interactive)
6167   (gnus-summary-save-process-mark)
6168   (gnus-summary-unmark-all-processable))
6169
6170 (defun gnus-summary-yank-process-mark ()
6171   "Pop the last process mark state off the stack and restore it."
6172   (interactive)
6173   (unless gnus-newsgroup-process-stack
6174     (error "Empty mark stack"))
6175   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6176
6177 (defun gnus-summary-process-mark-set (set)
6178   "Make SET into the current process marked articles."
6179   (gnus-summary-unmark-all-processable)
6180   (mapc 'gnus-summary-set-process-mark set))
6181
6182 ;;; Searching and stuff
6183
6184 (defun gnus-summary-search-group (&optional backward use-level)
6185   "Search for next unread newsgroup.
6186 If optional argument BACKWARD is non-nil, search backward instead."
6187   (save-excursion
6188     (set-buffer gnus-group-buffer)
6189     (when (gnus-group-search-forward
6190            backward nil (if use-level (gnus-group-group-level) nil))
6191       (gnus-group-group-name))))
6192
6193 (defun gnus-summary-best-group (&optional exclude-group)
6194   "Find the name of the best unread group.
6195 If EXCLUDE-GROUP, do not go to this group."
6196   (with-current-buffer gnus-group-buffer
6197     (save-excursion
6198       (gnus-group-best-unread-group exclude-group))))
6199
6200 (defun gnus-summary-find-next (&optional unread article backward)
6201   (if backward
6202       (gnus-summary-find-prev unread article)
6203     (let* ((dummy (gnus-summary-article-intangible-p))
6204            (article (or article (gnus-summary-article-number)))
6205            (data (gnus-data-find-list article))
6206            result)
6207       (when (and (not dummy)
6208                  (or (not gnus-summary-check-current)
6209                      (not unread)
6210                      (not (gnus-data-unread-p (car data)))))
6211         (setq data (cdr data)))
6212       (when (setq result
6213                   (if unread
6214                       (progn
6215                         (while data
6216                           (unless (memq (gnus-data-number (car data))
6217                                         (cond
6218                                          ((eq gnus-auto-goto-ignores
6219                                               'always-undownloaded)
6220                                           gnus-newsgroup-undownloaded)
6221                                          (gnus-plugged
6222                                           nil)
6223                                          ((eq gnus-auto-goto-ignores
6224                                               'unfetched)
6225                                           gnus-newsgroup-unfetched)
6226                                          ((eq gnus-auto-goto-ignores
6227                                               'undownloaded)
6228                                           gnus-newsgroup-undownloaded)))
6229                             (when (gnus-data-unread-p (car data))
6230                               (setq result (car data)
6231                                     data nil)))
6232                           (setq data (cdr data)))
6233                         result)
6234                     (car data)))
6235         (goto-char (gnus-data-pos result))
6236         (gnus-data-number result)))))
6237
6238 (defun gnus-summary-find-prev (&optional unread article)
6239   (let* ((eobp (eobp))
6240          (article (or article (gnus-summary-article-number)))
6241          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6242          result)
6243     (when (and (not eobp)
6244                (or (not gnus-summary-check-current)
6245                    (not unread)
6246                    (not (gnus-data-unread-p (car data)))))
6247       (setq data (cdr data)))
6248     (when (setq result
6249                 (if unread
6250                     (progn
6251                       (while data
6252                         (unless (memq (gnus-data-number (car data))
6253                                       (cond
6254                                        ((eq gnus-auto-goto-ignores
6255                                             'always-undownloaded)
6256                                         gnus-newsgroup-undownloaded)
6257                                        (gnus-plugged
6258                                         nil)
6259                                        ((eq gnus-auto-goto-ignores
6260                                             'unfetched)
6261                                         gnus-newsgroup-unfetched)
6262                                        ((eq gnus-auto-goto-ignores
6263                                             'undownloaded)
6264                                         gnus-newsgroup-undownloaded)))
6265                           (when (gnus-data-unread-p (car data))
6266                             (setq result (car data)
6267                                   data nil)))
6268                         (setq data (cdr data)))
6269                       result)
6270                   (car data)))
6271       (goto-char (gnus-data-pos result))
6272       (gnus-data-number result))))
6273
6274 (defun gnus-summary-find-subject (subject &optional unread backward article)
6275   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6276          (article (or article (gnus-summary-article-number)))
6277          (articles (gnus-data-list backward))
6278          (arts (gnus-data-find-list article articles))
6279          result)
6280     (when (or (not gnus-summary-check-current)
6281               (not unread)
6282               (not (gnus-data-unread-p (car arts))))
6283       (setq arts (cdr arts)))
6284     (while arts
6285       (and (or (not unread)
6286                (gnus-data-unread-p (car arts)))
6287            (vectorp (gnus-data-header (car arts)))
6288            (gnus-subject-equal
6289             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6290            (setq result (car arts)
6291                  arts nil))
6292       (setq arts (cdr arts)))
6293     (and result
6294          (goto-char (gnus-data-pos result))
6295          (gnus-data-number result))))
6296
6297 (defun gnus-summary-search-forward (&optional unread subject backward)
6298   "Search forward for an article.
6299 If UNREAD, look for unread articles.  If SUBJECT, look for
6300 articles with that subject.  If BACKWARD, search backward instead."
6301   (cond (subject (gnus-summary-find-subject subject unread backward))
6302         (backward (gnus-summary-find-prev unread))
6303         (t (gnus-summary-find-next unread))))
6304
6305 (defun gnus-recenter (&optional n)
6306   "Center point in window and redisplay frame.
6307 Also do horizontal recentering."
6308   (interactive "P")
6309   (when (and gnus-auto-center-summary
6310              (not (eq gnus-auto-center-summary 'vertical)))
6311     (gnus-horizontal-recenter))
6312   (recenter n))
6313
6314 (defun gnus-summary-recenter ()
6315   "Center point in the summary window.
6316 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6317 displayed, no centering will be performed."
6318   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6319   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6320   (interactive)
6321   ;; The user has to want it.
6322   (when gnus-auto-center-summary
6323     (let* ((top (cond ((< (window-height) 4) 0)
6324                       ((< (window-height) 7) 1)
6325                       (t (if (numberp gnus-auto-center-summary)
6326                              gnus-auto-center-summary
6327                            (/ (1- (window-height)) 2)))))
6328            (height (1- (window-height)))
6329            (bottom (save-excursion (goto-char (point-max))
6330                                    (forward-line (- height))
6331                                    (point)))
6332            (window (get-buffer-window (current-buffer))))
6333       (when (get-buffer-window gnus-article-buffer)
6334         ;; Only do recentering when the article buffer is displayed,
6335         ;; Set the window start to either `bottom', which is the biggest
6336         ;; possible valid number, or the second line from the top,
6337         ;; whichever is the least.
6338         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6339           (if (> bottom top-pos)
6340               ;; Keep the second line from the top visible
6341               (set-window-start window top-pos t)
6342             ;; Try to keep the bottom line visible; if it's partially
6343             ;; obscured, either scroll one more line to make it fully
6344             ;; visible, or revert to using TOP-POS.
6345             (save-excursion
6346               (goto-char (point-max))
6347               (forward-line -1)
6348               (let ((last-line-start (point)))
6349                 (goto-char bottom)
6350                 (set-window-start window (point) t)
6351                 (when (not (pos-visible-in-window-p last-line-start window))
6352                   (forward-line 1)
6353                   (set-window-start window (min (point) top-pos) t)))))))
6354       ;; Do horizontal recentering while we're at it.
6355       (when (and (get-buffer-window (current-buffer) t)
6356                  (not (eq gnus-auto-center-summary 'vertical)))
6357         (let ((selected (selected-window)))
6358           (select-window (get-buffer-window (current-buffer) t))
6359           (gnus-summary-position-point)
6360           (gnus-horizontal-recenter)
6361           (select-window selected))))))
6362
6363 (defun gnus-summary-jump-to-group (newsgroup)
6364   "Move point to NEWSGROUP in group mode buffer."
6365   ;; Keep update point of group mode buffer if visible.
6366   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6367       (save-window-excursion
6368         ;; Take care of tree window mode.
6369         (when (get-buffer-window gnus-group-buffer)
6370           (pop-to-buffer gnus-group-buffer))
6371         (gnus-group-jump-to-group newsgroup))
6372     (save-excursion
6373       ;; Take care of tree window mode.
6374       (if (get-buffer-window gnus-group-buffer)
6375           (pop-to-buffer gnus-group-buffer)
6376         (set-buffer gnus-group-buffer))
6377       (gnus-group-jump-to-group newsgroup))))
6378
6379 ;; This function returns a list of article numbers based on the
6380 ;; difference between the ranges of read articles in this group and
6381 ;; the range of active articles.
6382 (defun gnus-list-of-unread-articles (group)
6383   (let* ((read (gnus-info-read (gnus-get-info group)))
6384          (active (or (gnus-active group) (gnus-activate-group group)))
6385          (last (cdr active))
6386          first nlast unread)
6387     ;; If none are read, then all are unread.
6388     (if (not read)
6389         (setq first (car active))
6390       ;; If the range of read articles is a single range, then the
6391       ;; first unread article is the article after the last read
6392       ;; article.  Sounds logical, doesn't it?
6393       (if (and (not (listp (cdr read)))
6394                (or (< (car read) (car active))
6395                    (progn (setq read (list read))
6396                           nil)))
6397           (setq first (max (car active) (1+ (cdr read))))
6398         ;; `read' is a list of ranges.
6399         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6400                                   (caar read)))
6401                   1)
6402           (setq first (car active)))
6403         (while read
6404           (when first
6405             (while (< first nlast)
6406               (setq unread (cons first unread)
6407                     first (1+ first))))
6408           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6409           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6410           (setq read (cdr read)))))
6411     ;; And add the last unread articles.
6412     (while (<= first last)
6413       (setq unread (cons first unread)
6414             first (1+ first)))
6415     ;; Return the list of unread articles.
6416     (delq 0 (nreverse unread))))
6417
6418 (defun gnus-list-of-read-articles (group)
6419   "Return a list of unread, unticked and non-dormant articles."
6420   (let* ((info (gnus-get-info group))
6421          (marked (gnus-info-marks info))
6422          (active (gnus-active group)))
6423     (and info active
6424          (gnus-list-range-difference
6425           (gnus-list-range-difference
6426            (gnus-sorted-complement
6427             (gnus-uncompress-range active)
6428             (gnus-list-of-unread-articles group))
6429            (cdr (assq 'dormant marked)))
6430           (cdr (assq 'tick marked))))))
6431
6432 ;; This function returns a sequence of article numbers based on the
6433 ;; difference between the ranges of read articles in this group and
6434 ;; the range of active articles.
6435 (defun gnus-sequence-of-unread-articles (group)
6436   (let* ((read (gnus-info-read (gnus-get-info group)))
6437          (active (or (gnus-active group) (gnus-activate-group group)))
6438          (last (cdr active))
6439          first nlast unread)
6440     ;; If none are read, then all are unread.
6441     (if (not read)
6442         (setq first (car active))
6443       ;; If the range of read articles is a single range, then the
6444       ;; first unread article is the article after the last read
6445       ;; article.  Sounds logical, doesn't it?
6446       (if (and (not (listp (cdr read)))
6447                (or (< (car read) (car active))
6448                    (progn (setq read (list read))
6449                           nil)))
6450           (setq first (max (car active) (1+ (cdr read))))
6451         ;; `read' is a list of ranges.
6452         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6453                                   (caar read)))
6454                   1)
6455           (setq first (car active)))
6456         (while read
6457           (when first
6458             (push (cons first nlast) unread))
6459           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6460           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6461           (setq read (cdr read)))))
6462     ;; And add the last unread articles.
6463     (cond ((< first last)
6464            (push (cons first last) unread))
6465           ((= first last)
6466            (push first unread)))
6467     ;; Return the sequence of unread articles.
6468     (delq 0 (nreverse unread))))
6469
6470 ;; Various summary commands
6471
6472 (defun gnus-summary-select-article-buffer ()
6473   "Reconfigure windows to show article buffer."
6474   (interactive)
6475   (if (not (gnus-buffer-live-p gnus-article-buffer))
6476       (error "There is no article buffer for this summary buffer")
6477     (gnus-configure-windows 'article)
6478     (select-window (get-buffer-window gnus-article-buffer))))
6479
6480 (defun gnus-summary-universal-argument (arg)
6481   "Perform any operation on all articles that are process/prefixed."
6482   (interactive "P")
6483   (let ((articles (gnus-summary-work-articles arg))
6484         func article)
6485     (if (eq
6486          (setq
6487           func
6488           (key-binding
6489            (read-key-sequence
6490             (substitute-command-keys
6491              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6492          'undefined)
6493         (gnus-error 1 "Undefined key")
6494       (save-excursion
6495         (while articles
6496           (gnus-summary-goto-subject (setq article (pop articles)))
6497           (let (gnus-newsgroup-processable)
6498             (command-execute func))
6499           (gnus-summary-remove-process-mark article)))))
6500   (gnus-summary-position-point))
6501
6502 (defun gnus-summary-toggle-truncation (&optional arg)
6503   "Toggle truncation of summary lines.
6504 With ARG, turn line truncation on if ARG is positive."
6505   (interactive "P")
6506   (setq truncate-lines
6507         (if (null arg) (not truncate-lines)
6508           (> (prefix-numeric-value arg) 0)))
6509   (redraw-display))
6510
6511 (defun gnus-summary-find-for-reselect ()
6512   "Return the number of an article to stay on across a reselect.
6513 The current article is considered, then following articles, then previous
6514 articles.  An article is sought which is not cancelled and isn't a temporary
6515 insertion from another group.  If there's no such then return a dummy 0."
6516   (let (found)
6517     (dolist (rev '(nil t))
6518       (unless found      ; don't demand the reverse list if we don't need it
6519         (let ((data (gnus-data-find-list
6520                      (gnus-summary-article-number) (gnus-data-list rev))))
6521           (while (and data (not found))
6522             (if (and (< 0 (gnus-data-number (car data)))
6523                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6524                 (setq found (gnus-data-number (car data))))
6525             (setq data (cdr data))))))
6526     (or found 0)))
6527
6528 (defun gnus-summary-reselect-current-group (&optional all rescan)
6529   "Exit and then reselect the current newsgroup.
6530 The prefix argument ALL means to select all articles."
6531   (interactive "P")
6532   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6533     (error "Ephemeral groups can't be reselected"))
6534   (let ((current-subject (gnus-summary-find-for-reselect))
6535         (group gnus-newsgroup-name))
6536     (setq gnus-newsgroup-begin nil)
6537     (gnus-summary-exit nil 'leave-hidden)
6538     ;; We have to adjust the point of group mode buffer because
6539     ;; point was moved to the next unread newsgroup by exiting.
6540     (gnus-summary-jump-to-group group)
6541     (when rescan
6542       (save-excursion
6543         (save-window-excursion
6544           ;; Don't show group contents.
6545           (set-window-start (selected-window) (point-max))
6546           (gnus-group-get-new-news-this-group 1))))
6547     (gnus-group-read-group all t)
6548     (gnus-summary-goto-subject current-subject nil t)))
6549
6550 (defun gnus-summary-rescan-group (&optional all)
6551   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6552   (interactive "P")
6553   (gnus-summary-reselect-current-group all t))
6554
6555 (defun gnus-summary-update-info (&optional non-destructive)
6556   (save-excursion
6557     (let ((group gnus-newsgroup-name))
6558       (when group
6559         (when gnus-newsgroup-kill-headers
6560           (setq gnus-newsgroup-killed
6561                 (gnus-compress-sequence
6562                  (gnus-sorted-union
6563                   (gnus-list-range-intersection
6564                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6565                   gnus-newsgroup-unreads)
6566                  t)))
6567         (unless (listp (cdr gnus-newsgroup-killed))
6568           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6569         (let ((headers gnus-newsgroup-headers))
6570           ;; Set the new ranges of read articles.
6571           (with-current-buffer gnus-group-buffer
6572             (gnus-undo-force-boundary))
6573           (gnus-update-read-articles
6574            group (gnus-sorted-union
6575                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6576           ;; Set the current article marks.
6577           (let ((gnus-newsgroup-scored
6578                  (if (and (not gnus-save-score)
6579                           (not non-destructive))
6580                      nil
6581                    gnus-newsgroup-scored)))
6582             (save-excursion
6583               (gnus-update-marks)))
6584           ;; Do the cross-ref thing.
6585           (when gnus-use-cross-reference
6586             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6587           ;; Do not switch windows but change the buffer to work.
6588           (set-buffer gnus-group-buffer)
6589           (unless (gnus-ephemeral-group-p group)
6590             (gnus-group-update-group group)))))))
6591
6592 (defun gnus-summary-save-newsrc (&optional force)
6593   "Save the current number of read/marked articles in the dribble buffer.
6594 The dribble buffer will then be saved.
6595 If FORCE (the prefix), also save the .newsrc file(s)."
6596   (interactive "P")
6597   (gnus-summary-update-info t)
6598   (if force
6599       (gnus-save-newsrc-file)
6600     (gnus-dribble-save)))
6601
6602 (defun gnus-summary-exit (&optional temporary leave-hidden)
6603   "Exit reading current newsgroup, and then return to group selection mode.
6604 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6605   (interactive)
6606   (gnus-set-global-variables)
6607   (gnus-kill-save-kill-buffer)
6608   (gnus-async-halt-prefetch)
6609   (let* ((group gnus-newsgroup-name)
6610          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6611          (gnus-group-is-exiting-p t)
6612          (mode major-mode)
6613          (group-point nil)
6614          (buf (current-buffer)))
6615     (unless quit-config
6616       ;; Do adaptive scoring, and possibly save score files.
6617       (when gnus-newsgroup-adaptive
6618         (gnus-score-adaptive))
6619       (when gnus-use-scoring
6620         (gnus-score-save)))
6621     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6622     ;; If we have several article buffers, we kill them at exit.
6623     (unless gnus-single-article-buffer
6624       (gnus-kill-buffer gnus-original-article-buffer)
6625       (setq gnus-article-current nil))
6626     (when gnus-use-cache
6627       (gnus-cache-possibly-remove-articles)
6628       (gnus-cache-save-buffers))
6629     (gnus-async-prefetch-remove-group group)
6630     (when gnus-suppress-duplicates
6631       (gnus-dup-enter-articles))
6632     (when gnus-use-trees
6633       (gnus-tree-close group))
6634     (when gnus-use-cache
6635       (gnus-cache-write-active))
6636     ;; Remove entries for this group.
6637     (nnmail-purge-split-history (gnus-group-real-name group))
6638     ;; Make all changes in this group permanent.
6639     (unless quit-config
6640       (gnus-run-hooks 'gnus-exit-group-hook)
6641       (gnus-summary-update-info))
6642     (gnus-close-group group)
6643     ;; Make sure where we were, and go to next newsgroup.
6644     (set-buffer gnus-group-buffer)
6645     (unless quit-config
6646       (gnus-group-jump-to-group group))
6647     (gnus-run-hooks 'gnus-summary-exit-hook)
6648     (unless (or quit-config
6649                 ;; If this group has disappeared from the summary
6650                 ;; buffer, don't skip forwards.
6651                 (not (string= group (gnus-group-group-name))))
6652       (gnus-group-next-unread-group 1))
6653     (setq group-point (point))
6654     (if temporary
6655         nil                             ;Nothing to do.
6656       ;; If we have several article buffers, we kill them at exit.
6657       (unless gnus-single-article-buffer
6658         (gnus-kill-buffer gnus-article-buffer)
6659         (gnus-kill-buffer gnus-original-article-buffer)
6660         (setq gnus-article-current nil))
6661       (set-buffer buf)
6662       (if (not gnus-kill-summary-on-exit)
6663           (progn
6664             (gnus-deaden-summary)
6665             (setq mode nil))
6666         ;; We set all buffer-local variables to nil.  It is unclear why
6667         ;; this is needed, but if we don't, buffer-local variables are
6668         ;; not garbage-collected, it seems.  This would the lead to en
6669         ;; ever-growing Emacs.
6670         (gnus-summary-clear-local-variables)
6671         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6672           (gnus-summary-clear-local-variables))
6673         (when (get-buffer gnus-article-buffer)
6674           (bury-buffer gnus-article-buffer))
6675         ;; We clear the global counterparts of the buffer-local
6676         ;; variables as well, just to be on the safe side.
6677         (set-buffer gnus-group-buffer)
6678         (gnus-summary-clear-local-variables)
6679         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6680           (gnus-summary-clear-local-variables))
6681         ;; Return to group mode buffer.
6682         (when (eq mode 'gnus-summary-mode)
6683           (gnus-kill-buffer buf)))
6684       (setq gnus-current-select-method gnus-select-method)
6685       (if leave-hidden
6686           (set-buffer gnus-group-buffer)
6687         (pop-to-buffer gnus-group-buffer))
6688       (if (not quit-config)
6689           (progn
6690             (goto-char group-point)
6691             (unless leave-hidden
6692               (gnus-configure-windows 'group 'force))
6693             (unless (pos-visible-in-window-p)
6694               (forward-line (/ (static-if (featurep 'xemacs)
6695                                    (window-displayed-height)
6696                                  (1- (window-height)))
6697                                -2))
6698               (set-window-start (selected-window) (point))
6699               (goto-char group-point)))
6700         (gnus-handle-ephemeral-exit quit-config))
6701       ;; Clear the current group name.
6702       (unless quit-config
6703         (setq gnus-newsgroup-name nil)))))
6704
6705 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6706 (defun gnus-summary-exit-no-update (&optional no-questions)
6707   "Quit reading current newsgroup without updating read article info."
6708   (interactive)
6709   (let* ((group gnus-newsgroup-name)
6710          (gnus-group-is-exiting-p t)
6711          (gnus-group-is-exiting-without-update-p t)
6712          (quit-config (gnus-group-quit-config group)))
6713     (when (or no-questions
6714               gnus-expert-user
6715               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6716       (gnus-async-halt-prefetch)
6717       (run-hooks 'gnus-summary-prepare-exit-hook)
6718       ;; If we have several article buffers, we kill them at exit.
6719       (unless gnus-single-article-buffer
6720         (gnus-kill-buffer gnus-article-buffer)
6721         (gnus-kill-buffer gnus-original-article-buffer)
6722         (setq gnus-article-current nil))
6723       (if (not gnus-kill-summary-on-exit)
6724           (gnus-deaden-summary)
6725         (gnus-close-group group)
6726         (gnus-summary-clear-local-variables)
6727         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6728           (gnus-summary-clear-local-variables))
6729         (set-buffer gnus-group-buffer)
6730         (gnus-summary-clear-local-variables)
6731         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6732           (gnus-summary-clear-local-variables))
6733         (gnus-kill-buffer gnus-summary-buffer))
6734       (unless gnus-single-article-buffer
6735         (setq gnus-article-current nil))
6736       (when gnus-use-trees
6737         (gnus-tree-close group))
6738       (gnus-async-prefetch-remove-group group)
6739       (when (get-buffer gnus-article-buffer)
6740         (bury-buffer gnus-article-buffer))
6741       ;; Return to the group buffer.
6742       (gnus-configure-windows 'group 'force)
6743       ;; Clear the current group name.
6744       (setq gnus-newsgroup-name nil)
6745       (unless (gnus-ephemeral-group-p group)
6746         (gnus-group-update-group group))
6747       (when (equal (gnus-group-group-name) group)
6748         (gnus-group-next-unread-group 1))
6749       (when quit-config
6750         (gnus-handle-ephemeral-exit quit-config)))))
6751
6752 (defun gnus-handle-ephemeral-exit (quit-config)
6753   "Handle movement when leaving an ephemeral group.
6754 The state which existed when entering the ephemeral is reset."
6755   (if (not (buffer-name (car quit-config)))
6756       (gnus-configure-windows 'group 'force)
6757     (set-buffer (car quit-config))
6758     (cond ((eq major-mode 'gnus-summary-mode)
6759            (gnus-set-global-variables))
6760           ((eq major-mode 'gnus-article-mode)
6761            (save-excursion
6762              ;; The `gnus-summary-buffer' variable may point
6763              ;; to the old summary buffer when using a single
6764              ;; article buffer.
6765              (unless (gnus-buffer-live-p gnus-summary-buffer)
6766                (set-buffer gnus-group-buffer))
6767              (set-buffer gnus-summary-buffer)
6768              (gnus-set-global-variables))))
6769     (if (or (eq (cdr quit-config) 'article)
6770             (eq (cdr quit-config) 'pick))
6771         (progn
6772           ;; The current article may be from the ephemeral group
6773           ;; thus it is best that we reload this article
6774           ;;
6775           ;; If we're exiting from a large digest, this can be
6776           ;; extremely slow.  So, it's better not to reload it. -- jh.
6777           ;;(gnus-summary-show-article)
6778           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6779               (gnus-configure-windows 'pick 'force)
6780             (gnus-configure-windows (cdr quit-config) 'force)))
6781       (gnus-configure-windows (cdr quit-config) 'force))
6782     (when (eq major-mode 'gnus-summary-mode)
6783       (gnus-summary-next-subject 1 nil t)
6784       (gnus-summary-recenter)
6785       (gnus-summary-position-point))))
6786
6787 (defun gnus-summary-preview-mime-message ()
6788   "MIME decode and play this message."
6789   (interactive)
6790   (let ((gnus-break-pages nil)
6791         (gnus-show-mime t))
6792     (gnus-summary-select-article gnus-show-all-headers t))
6793   (let ((w (get-buffer-window gnus-article-buffer)))
6794     (when w
6795       (select-window (get-buffer-window gnus-article-buffer)))))
6796
6797 ;;; Dead summaries.
6798
6799 (defvar gnus-dead-summary-mode-map nil)
6800
6801 (unless gnus-dead-summary-mode-map
6802   (setq gnus-dead-summary-mode-map (make-keymap))
6803   (suppress-keymap gnus-dead-summary-mode-map)
6804   (substitute-key-definition
6805    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6806   (dolist (key '("\C-d" "\r" "\177" [delete]))
6807     (define-key gnus-dead-summary-mode-map
6808       key 'gnus-summary-wake-up-the-dead))
6809   (dolist (key '("q" "Q"))
6810     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6811
6812 (defvar gnus-dead-summary-mode nil
6813   "Minor mode for Gnus summary buffers.")
6814
6815 (defun gnus-dead-summary-mode (&optional arg)
6816   "Minor mode for Gnus summary buffers."
6817   (interactive "P")
6818   (when (eq major-mode 'gnus-summary-mode)
6819     (make-local-variable 'gnus-dead-summary-mode)
6820     (setq gnus-dead-summary-mode
6821           (if (null arg) (not gnus-dead-summary-mode)
6822             (> (prefix-numeric-value arg) 0)))
6823     (when gnus-dead-summary-mode
6824       (add-minor-mode
6825        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6826
6827 (defun gnus-deaden-summary ()
6828   "Make the current summary buffer into a dead summary buffer."
6829   ;; Kill any previous dead summary buffer.
6830   (when (and gnus-dead-summary
6831              (buffer-name gnus-dead-summary))
6832     (with-current-buffer gnus-dead-summary
6833       (when gnus-dead-summary-mode
6834         (kill-buffer (current-buffer)))))
6835   ;; Make this the current dead summary.
6836   (setq gnus-dead-summary (current-buffer))
6837   (gnus-dead-summary-mode 1)
6838   (let ((name (buffer-name)))
6839     (when (string-match "Summary" name)
6840       (rename-buffer
6841        (concat (substring name 0 (match-beginning 0)) "Dead "
6842                (substring name (match-beginning 0)))
6843        t)
6844       (bury-buffer))))
6845
6846 (defun gnus-kill-or-deaden-summary (buffer)
6847   "Kill or deaden the summary BUFFER."
6848   (save-excursion
6849     (when (and (buffer-name buffer)
6850                (not gnus-single-article-buffer))
6851       (with-current-buffer buffer
6852         (gnus-kill-buffer gnus-article-buffer)
6853         (gnus-kill-buffer gnus-original-article-buffer)))
6854     (cond
6855      ;; Kill the buffer.
6856      (gnus-kill-summary-on-exit
6857       (when (and gnus-use-trees
6858                  (gnus-buffer-exists-p buffer))
6859         (save-excursion
6860           (set-buffer buffer)
6861           (gnus-tree-close gnus-newsgroup-name)))
6862       (gnus-kill-buffer buffer))
6863      ;; Deaden the buffer.
6864      ((gnus-buffer-exists-p buffer)
6865       (save-excursion
6866         (set-buffer buffer)
6867         (gnus-deaden-summary))))))
6868
6869 (defun gnus-summary-wake-up-the-dead (&rest args)
6870   "Wake up the dead summary buffer."
6871   (interactive)
6872   (gnus-dead-summary-mode -1)
6873   (let ((name (buffer-name)))
6874     (when (string-match "Dead " name)
6875       (rename-buffer
6876        (concat (substring name 0 (match-beginning 0))
6877                (substring name (match-end 0)))
6878        t)))
6879   (gnus-message 3 "This dead summary is now alive again"))
6880
6881 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6882 (defun gnus-summary-fetch-faq (&optional faq-dir)
6883   "Fetch the FAQ for the current group.
6884 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6885 in."
6886   (interactive
6887    (list
6888     (when current-prefix-arg
6889       (completing-read
6890        "FAQ dir: " (and (listp gnus-group-faq-directory)
6891                         (mapcar 'list
6892                                 gnus-group-faq-directory))))))
6893   (let (gnus-faq-buffer)
6894     (when (setq gnus-faq-buffer
6895                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6896       (gnus-configure-windows 'summary-faq))))
6897
6898 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6899 (defun gnus-summary-describe-group (&optional force)
6900   "Describe the current newsgroup."
6901   (interactive "P")
6902   (gnus-group-describe-group force gnus-newsgroup-name))
6903
6904 (defun gnus-summary-describe-briefly ()
6905   "Describe summary mode commands briefly."
6906   (interactive)
6907   (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")))
6908
6909 ;; Walking around group mode buffer from summary mode.
6910
6911 (defun gnus-summary-next-group (&optional no-article target-group backward)
6912   "Exit current newsgroup and then select next unread newsgroup.
6913 If prefix argument NO-ARTICLE is non-nil, no article is selected
6914 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6915 previous group instead."
6916   (interactive "P")
6917   ;; Stop pre-fetching.
6918   (gnus-async-halt-prefetch)
6919   (let ((current-group gnus-newsgroup-name)
6920         (current-buffer (current-buffer))
6921         entered)
6922     ;; First we semi-exit this group to update Xrefs and all variables.
6923     ;; We can't do a real exit, because the window conf must remain
6924     ;; the same in case the user is prompted for info, and we don't
6925     ;; want the window conf to change before that...
6926     (gnus-summary-exit t)
6927     (while (not entered)
6928       ;; Then we find what group we are supposed to enter.
6929       (set-buffer gnus-group-buffer)
6930       (gnus-group-jump-to-group current-group)
6931       (setq target-group
6932             (or target-group
6933                 (if (eq gnus-keep-same-level 'best)
6934                     (gnus-summary-best-group gnus-newsgroup-name)
6935                   (gnus-summary-search-group backward gnus-keep-same-level))))
6936       (if (not target-group)
6937           ;; There are no further groups, so we return to the group
6938           ;; buffer.
6939           (progn
6940             (gnus-message 5 "Returning to the group buffer")
6941             (setq entered t)
6942             (when (gnus-buffer-live-p current-buffer)
6943               (set-buffer current-buffer)
6944               (gnus-summary-exit))
6945             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6946         ;; We try to enter the target group.
6947         (gnus-group-jump-to-group target-group)
6948         (let ((unreads (gnus-group-group-unread)))
6949           (if (and (or (eq t unreads)
6950                        (and unreads (not (zerop unreads))))
6951                    (gnus-summary-read-group
6952                     target-group nil no-article
6953                     (and (buffer-name current-buffer) current-buffer)
6954                     nil backward))
6955               (setq entered t)
6956             (setq current-group target-group
6957                   target-group nil)))))))
6958
6959 (defun gnus-summary-prev-group (&optional no-article)
6960   "Exit current newsgroup and then select previous unread newsgroup.
6961 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6962   (interactive "P")
6963   (gnus-summary-next-group no-article nil t))
6964
6965 ;; Walking around summary lines.
6966
6967 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6968   "Go to the first subject satisfying any non-nil constraint.
6969 If UNREAD is non-nil, the article should be unread.
6970 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6971 If UNSEEN is non-nil, the article should be unseen.
6972 Returns the article selected or nil if there are no matching articles."
6973   (interactive "P")
6974   (cond
6975    ;; Empty summary.
6976    ((null gnus-newsgroup-data)
6977     (gnus-message 3 "No articles in the group")
6978     nil)
6979    ;; Pick the first article.
6980    ((not (or unread undownloaded unseen))
6981     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6982     (gnus-data-number (car gnus-newsgroup-data)))
6983    ;; Find the first unread article.
6984    (t
6985     (let ((data gnus-newsgroup-data))
6986       (while (and data
6987                   (let ((num (gnus-data-number (car data))))
6988                     (or (memq num gnus-newsgroup-unfetched)
6989                         (not (or (and unread
6990                                       (memq num gnus-newsgroup-unreads))
6991                                  (and undownloaded
6992                                       (memq num gnus-newsgroup-undownloaded))
6993                                  (and unseen
6994                                       (memq num gnus-newsgroup-unseen)))))))
6995         (setq data (cdr data)))
6996       (prog1
6997           (if data
6998               (progn
6999                 (goto-char (gnus-data-pos (car data)))
7000                 (gnus-data-number (car data)))
7001             (gnus-message 3 "No more%s articles"
7002                           (let* ((r (when unread " unread"))
7003                                  (d (when undownloaded " undownloaded"))
7004                                  (s (when unseen " unseen"))
7005                                  (l (delq nil (list r d s))))
7006                             (cond ((= 3 (length l))
7007                                    (concat r "," d ", or" s))
7008                                   ((= 2 (length l))
7009                                    (concat (car l) ", or" (cadr l)))
7010                                   ((= 1 (length l))
7011                                    (car l))
7012                                   (t
7013                                    ""))))
7014             nil
7015             )
7016         (gnus-summary-position-point))))))
7017
7018 (defun gnus-summary-next-subject (n &optional unread dont-display)
7019   "Go to next N'th summary line.
7020 If N is negative, go to the previous N'th subject line.
7021 If UNREAD is non-nil, only unread articles are selected.
7022 The difference between N and the actual number of steps taken is
7023 returned."
7024   (interactive "p")
7025   (let ((backward (< n 0))
7026         (n (abs n)))
7027     (while (and (> n 0)
7028                 (if backward
7029                     (gnus-summary-find-prev unread)
7030                   (gnus-summary-find-next unread)))
7031       (unless (zerop (setq n (1- n)))
7032         (gnus-summary-show-thread)))
7033     (when (/= 0 n)
7034       (gnus-message 7 "No more%s articles"
7035                     (if unread " unread" "")))
7036     (unless dont-display
7037       (gnus-summary-recenter)
7038       (gnus-summary-position-point))
7039     n))
7040
7041 (defun gnus-summary-next-unread-subject (n)
7042   "Go to next N'th unread summary line."
7043   (interactive "p")
7044   (gnus-summary-next-subject n t))
7045
7046 (defun gnus-summary-prev-subject (n &optional unread)
7047   "Go to previous N'th summary line.
7048 If optional argument UNREAD is non-nil, only unread article is selected."
7049   (interactive "p")
7050   (gnus-summary-next-subject (- n) unread))
7051
7052 (defun gnus-summary-prev-unread-subject (n)
7053   "Go to previous N'th unread summary line."
7054   (interactive "p")
7055   (gnus-summary-next-subject (- n) t))
7056
7057 (defun gnus-summary-goto-subjects (articles)
7058   "Insert the subject header for ARTICLES in the current buffer."
7059   (save-excursion
7060     (dolist (article articles)
7061       (gnus-summary-goto-subject article t)))
7062   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7063   (gnus-summary-position-point))
7064  
7065 (defun gnus-summary-goto-subject (article &optional force silent)
7066   "Go the subject line of ARTICLE.
7067 If FORCE, also allow jumping to articles not currently shown."
7068   (interactive "nArticle number: ")
7069   (unless (numberp article)
7070     (error "Article %s is not a number" article))
7071   (let ((b (point))
7072         (data (gnus-data-find article)))
7073     ;; We read in the article if we have to.
7074     (and (not data)
7075          force
7076          (gnus-summary-insert-subject
7077           article
7078           (if (or (numberp force) (vectorp force)) force)
7079           t)
7080          (setq data (gnus-data-find article)))
7081     (goto-char b)
7082     (if (not data)
7083         (progn
7084           (unless silent
7085             (gnus-message 3 "Can't find article %d" article))
7086           nil)
7087       (let ((pt (gnus-data-pos data)))
7088         (goto-char pt)
7089         (gnus-summary-set-article-display-arrow pt))
7090       (gnus-summary-position-point)
7091       article)))
7092
7093 ;; Walking around summary lines with displaying articles.
7094
7095 (defun gnus-summary-expand-window (&optional arg)
7096   "Make the summary buffer take up the entire Emacs frame.
7097 Given a prefix, will force an `article' buffer configuration."
7098   (interactive "P")
7099   (if arg
7100       (gnus-configure-windows 'article 'force)
7101     (gnus-configure-windows 'summary 'force)))
7102
7103 (defun gnus-summary-display-article (article &optional all-header)
7104   "Display ARTICLE in article buffer."
7105   (when (gnus-buffer-live-p gnus-article-buffer)
7106     (with-current-buffer gnus-article-buffer
7107       (set-buffer-multibyte t)))
7108   (gnus-set-global-variables)
7109   (when (gnus-buffer-live-p gnus-article-buffer)
7110     (with-current-buffer gnus-article-buffer
7111       (setq gnus-article-charset gnus-newsgroup-charset)
7112       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7113       (set-buffer-multibyte t)))
7114   (if (null article)
7115       nil
7116     (prog1
7117         (if gnus-summary-display-article-function
7118             (funcall gnus-summary-display-article-function article all-header)
7119           (gnus-article-prepare article all-header))
7120       (with-current-buffer gnus-article-buffer
7121         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7122              nil))
7123       (gnus-run-hooks 'gnus-select-article-hook)
7124       (when (and gnus-current-article
7125                  (not (zerop gnus-current-article)))
7126         (gnus-summary-goto-subject gnus-current-article))
7127       (gnus-summary-recenter)
7128       (when (and gnus-use-trees gnus-show-threads)
7129         (gnus-possibly-generate-tree article)
7130         (gnus-highlight-selected-tree article))
7131       ;; Successfully display article.
7132       (gnus-article-set-window-start
7133        (cdr (assq article gnus-newsgroup-bookmarks))))))
7134
7135 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7136   "Select the current article.
7137 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7138 non-nil, the article will be re-fetched even if it already present in
7139 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7140 be displayed."
7141   ;; Make sure we are in the summary buffer to work around bbdb bug.
7142   (unless (eq major-mode 'gnus-summary-mode)
7143     (set-buffer gnus-summary-buffer))
7144   (let ((article (or article (gnus-summary-article-number)))
7145         (all-headers (not (not all-headers))) ;Must be T or NIL.
7146         gnus-summary-display-article-function)
7147     (and (not pseudo)
7148          (gnus-summary-article-pseudo-p article)
7149          (error "This is a pseudo-article"))
7150     (save-excursion
7151       (set-buffer gnus-summary-buffer)
7152       (if (or (and gnus-single-article-buffer
7153                    (or (null gnus-current-article)
7154                        (null gnus-article-current)
7155                        (null (get-buffer gnus-article-buffer))
7156                        (not (eq article (cdr gnus-article-current)))
7157                        (not (equal (car gnus-article-current)
7158                                    gnus-newsgroup-name))))
7159               (and (not gnus-single-article-buffer)
7160                    (or (null gnus-current-article)
7161                        (not (eq gnus-current-article article))))
7162               force)
7163           ;; The requested article is different from the current article.
7164           (progn
7165             (gnus-summary-display-article article all-headers)
7166             (gnus-article-set-window-start
7167              (cdr (assq article gnus-newsgroup-bookmarks)))
7168             article)
7169         'old))))
7170
7171 (defun gnus-summary-force-verify-and-decrypt ()
7172   "Display buttons for signed/encrypted parts and verify/decrypt them."
7173   (interactive)
7174   (let ((mm-verify-option 'known)
7175         (mm-decrypt-option 'known)
7176         (gnus-article-emulate-mime t)
7177         (gnus-buttonized-mime-types (append (list "multipart/signed"
7178                                                   "multipart/encrypted")
7179                                             gnus-buttonized-mime-types)))
7180     (gnus-summary-select-article nil 'force)))
7181
7182 (defun gnus-summary-set-current-mark (&optional current-mark)
7183   "Obsolete function."
7184   nil)
7185
7186 (defun gnus-summary-next-article (&optional unread subject backward push)
7187   "Select the next article.
7188 If UNREAD, only unread articles are selected.
7189 If SUBJECT, only articles with SUBJECT are selected.
7190 If BACKWARD, the previous article is selected instead of the next."
7191   (interactive "P")
7192   (cond
7193    ;; Is there such an article?
7194    ((and (gnus-summary-search-forward unread subject backward)
7195          (or (gnus-summary-display-article (gnus-summary-article-number))
7196              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7197     (gnus-summary-position-point))
7198    ;; If not, we try the first unread, if that is wanted.
7199    ((and subject
7200          gnus-auto-select-same
7201          (gnus-summary-first-unread-article))
7202     (gnus-summary-position-point)
7203     (gnus-message 6 "Wrapped"))
7204    ;; Try to get next/previous article not displayed in this group.
7205    ((and gnus-auto-extend-newsgroup
7206          (not unread) (not subject))
7207     (gnus-summary-goto-article
7208      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7209      nil (count-lines (point-min) (point))))
7210    ;; Go to next/previous group.
7211    (t
7212     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7213       (gnus-summary-jump-to-group gnus-newsgroup-name))
7214     (let ((cmd last-command-char)
7215           (point
7216            (with-current-buffer gnus-group-buffer
7217              (point)))
7218           (group
7219            (if (eq gnus-keep-same-level 'best)
7220                (gnus-summary-best-group gnus-newsgroup-name)
7221              (gnus-summary-search-group backward gnus-keep-same-level))))
7222       ;; For some reason, the group window gets selected.  We change
7223       ;; it back.
7224       (select-window (get-buffer-window (current-buffer)))
7225       ;; Select next unread newsgroup automagically.
7226       (cond
7227        ((or (not gnus-auto-select-next)
7228             (not cmd))
7229         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7230        ((or (eq gnus-auto-select-next 'quietly)
7231             (and (eq gnus-auto-select-next 'slightly-quietly)
7232                  push)
7233             (and (eq gnus-auto-select-next 'almost-quietly)
7234                  (gnus-summary-last-article-p)))
7235         ;; Select quietly.
7236         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7237             (gnus-summary-exit)
7238           (gnus-message 7 "No more%s articles (%s)..."
7239                         (if unread " unread" "")
7240                         (if group (concat "selecting " group)
7241                           "exiting"))
7242           (gnus-summary-next-group nil group backward)))
7243        (t
7244         (when (gnus-key-press-event-p last-input-event)
7245           (gnus-summary-walk-group-buffer
7246            gnus-newsgroup-name cmd unread backward point))))))))
7247
7248 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7249   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7250                       (?\C-p (gnus-group-prev-unread-group 1))))
7251         (cursor-in-echo-area t)
7252         keve key group ended prompt)
7253     (save-excursion
7254       (set-buffer gnus-group-buffer)
7255       (goto-char start)
7256       (setq group
7257             (if (eq gnus-keep-same-level 'best)
7258                 (gnus-summary-best-group gnus-newsgroup-name)
7259               (gnus-summary-search-group backward gnus-keep-same-level))))
7260     (while (not ended)
7261       (setq prompt
7262             (format
7263              "No more%s articles%s " (if unread " unread" "")
7264              (if (and group
7265                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7266                  (format " (Type %s for %s [%s])"
7267                          (single-key-description cmd) group
7268                          (gnus-group-unread group))
7269                (format " (Type %s to exit %s)"
7270                        (single-key-description cmd)
7271                        gnus-newsgroup-name))))
7272       ;; Confirm auto selection.
7273       (setq key (car (setq keve (gnus-read-event-char prompt)))
7274             ended t)
7275       (cond
7276        ((assq key keystrokes)
7277         (let ((obuf (current-buffer)))
7278           (switch-to-buffer gnus-group-buffer)
7279           (when group
7280             (gnus-group-jump-to-group group))
7281           (eval (cadr (assq key keystrokes)))
7282           (setq group (gnus-group-group-name))
7283           (switch-to-buffer obuf))
7284         (setq ended nil))
7285        ((equal key cmd)
7286         (if (or (not group)
7287                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7288             (gnus-summary-exit)
7289           (gnus-summary-next-group nil group backward)))
7290        (t
7291         (push (cdr keve) unread-command-events))))))
7292
7293 (defun gnus-summary-next-unread-article ()
7294   "Select unread article after current one."
7295   (interactive)
7296   (gnus-summary-next-article
7297    (or (not (eq gnus-summary-goto-unread 'never))
7298        (gnus-summary-last-article-p (gnus-summary-article-number)))
7299    (and gnus-auto-select-same
7300         (gnus-summary-article-subject))))
7301
7302 (defun gnus-summary-prev-article (&optional unread subject)
7303   "Select the article after the current one.
7304 If UNREAD is non-nil, only unread articles are selected."
7305   (interactive "P")
7306   (gnus-summary-next-article unread subject t))
7307
7308 (defun gnus-summary-prev-unread-article ()
7309   "Select unread article before current one."
7310   (interactive)
7311   (gnus-summary-prev-article
7312    (or (not (eq gnus-summary-goto-unread 'never))
7313        (gnus-summary-first-article-p (gnus-summary-article-number)))
7314    (and gnus-auto-select-same
7315         (gnus-summary-article-subject))))
7316
7317 (defun gnus-summary-next-page (&optional lines circular stop)
7318   "Show next page of the selected article.
7319 If at the end of the current article, select the next article.
7320 LINES says how many lines should be scrolled up.
7321
7322 If CIRCULAR is non-nil, go to the start of the article instead of
7323 selecting the next article when reaching the end of the current
7324 article.
7325
7326 If STOP is non-nil, just stop when reaching the end of the message.
7327
7328 Also see the variable `gnus-article-skip-boring'."
7329   (interactive "P")
7330   (setq gnus-summary-buffer (current-buffer))
7331   (gnus-set-global-variables)
7332   (let ((article (gnus-summary-article-number))
7333         (article-window (get-buffer-window gnus-article-buffer t))
7334         endp)
7335     ;; If the buffer is empty, we have no article.
7336     (unless article
7337       (error "No article to select"))
7338     (gnus-configure-windows 'article)
7339     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7340         (if (and (eq gnus-summary-goto-unread 'never)
7341                  (not (gnus-summary-last-article-p article)))
7342             (gnus-summary-next-article)
7343           (gnus-summary-next-unread-article))
7344       (if (or (null gnus-current-article)
7345               (null gnus-article-current)
7346               (/= article (cdr gnus-article-current))
7347               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7348           ;; Selected subject is different from current article's.
7349           (gnus-summary-display-article article)
7350         (when article-window
7351           (gnus-eval-in-buffer-window gnus-article-buffer
7352             (setq endp (or (gnus-article-next-page lines)
7353                            (gnus-article-only-boring-p))))
7354           (when endp
7355             (cond (stop
7356                    (gnus-message 3 "End of message"))
7357                   (circular
7358                    (gnus-summary-beginning-of-article))
7359                   (lines
7360                    (gnus-message 3 "End of message"))
7361                   ((null lines)
7362                    (if (and (eq gnus-summary-goto-unread 'never)
7363                             (not (gnus-summary-last-article-p article)))
7364                        (gnus-summary-next-article)
7365                      (gnus-summary-next-unread-article))))))))
7366     (gnus-summary-recenter)
7367     (gnus-summary-position-point)))
7368
7369 (defun gnus-summary-prev-page (&optional lines move)
7370   "Show previous page of selected article.
7371 Argument LINES specifies lines to be scrolled down.
7372 If MOVE, move to the previous unread article if point is at
7373 the beginning of the buffer."
7374   (interactive "P")
7375   (let ((article (gnus-summary-article-number))
7376         (article-window (get-buffer-window gnus-article-buffer t))
7377         endp)
7378     (gnus-configure-windows 'article)
7379     (if (or (null gnus-current-article)
7380             (null gnus-article-current)
7381             (/= article (cdr gnus-article-current))
7382             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7383         ;; Selected subject is different from current article's.
7384         (gnus-summary-display-article article)
7385       (gnus-summary-recenter)
7386       (when article-window
7387         (gnus-eval-in-buffer-window gnus-article-buffer
7388           (setq endp (gnus-article-prev-page lines)))
7389         (when (and move endp)
7390           (cond (lines
7391                  (gnus-message 3 "Beginning of message"))
7392                 ((null lines)
7393                  (if (and (eq gnus-summary-goto-unread 'never)
7394                           (not (gnus-summary-first-article-p article)))
7395                      (gnus-summary-prev-article)
7396                    (gnus-summary-prev-unread-article))))))))
7397   (gnus-summary-position-point))
7398
7399 (defun gnus-summary-prev-page-or-article (&optional lines)
7400   "Show previous page of selected article.
7401 Argument LINES specifies lines to be scrolled down.
7402 If at the beginning of the article, go to the next article."
7403   (interactive "P")
7404   (gnus-summary-prev-page lines t))
7405
7406 (defun gnus-summary-scroll-up (lines)
7407   "Scroll up (or down) one line current article.
7408 Argument LINES specifies lines to be scrolled up (or down if negative)."
7409   (interactive "p")
7410   (gnus-configure-windows 'article)
7411   (gnus-summary-show-thread)
7412   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7413     (gnus-eval-in-buffer-window gnus-article-buffer
7414       (cond ((> lines 0)
7415              (when (gnus-article-next-page lines)
7416                (gnus-message 3 "End of message")))
7417             ((< lines 0)
7418              (gnus-article-prev-page (- lines))))))
7419   (gnus-summary-recenter)
7420   (gnus-summary-position-point))
7421
7422 (defun gnus-summary-scroll-down (lines)
7423   "Scroll down (or up) one line current article.
7424 Argument LINES specifies lines to be scrolled down (or up if negative)."
7425   (interactive "p")
7426   (gnus-summary-scroll-up (- lines)))
7427
7428 (defun gnus-summary-next-same-subject ()
7429   "Select next article which has the same subject as current one."
7430   (interactive)
7431   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7432
7433 (defun gnus-summary-prev-same-subject ()
7434   "Select previous article which has the same subject as current one."
7435   (interactive)
7436   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7437
7438 (defun gnus-summary-next-unread-same-subject ()
7439   "Select next unread article which has the same subject as current one."
7440   (interactive)
7441   (gnus-summary-next-article t (gnus-summary-article-subject)))
7442
7443 (defun gnus-summary-prev-unread-same-subject ()
7444   "Select previous unread article which has the same subject as current one."
7445   (interactive)
7446   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7447
7448 (defun gnus-summary-first-unread-article ()
7449   "Select the first unread article.
7450 Return nil if there are no unread articles."
7451   (interactive)
7452   (prog1
7453       (when (gnus-summary-first-subject t)
7454         (gnus-summary-show-thread)
7455         (gnus-summary-first-subject t)
7456         (gnus-summary-display-article (gnus-summary-article-number)))
7457     (gnus-summary-position-point)))
7458
7459 (defun gnus-summary-first-unread-subject ()
7460   "Place the point on the subject line of the first unread article.
7461 Return nil if there are no unread articles."
7462   (interactive)
7463   (prog1
7464       (when (gnus-summary-first-subject t)
7465         (gnus-summary-show-thread)
7466         (gnus-summary-first-subject t))
7467     (gnus-summary-position-point)))
7468
7469 (defun gnus-summary-first-unseen-subject ()
7470   "Place the point on the subject line of the first unseen article.
7471 Return nil if there are no unseen articles."
7472   (interactive)
7473   (prog1
7474       (when (gnus-summary-first-subject nil nil t)
7475         (gnus-summary-show-thread)
7476         (gnus-summary-first-subject nil nil t))
7477     (gnus-summary-position-point)))
7478
7479 (defun gnus-summary-first-unseen-or-unread-subject ()
7480   "Place the point on the subject line of the first unseen article or,
7481 if all article have been seen, on the subject line of the first unread
7482 article."
7483   (interactive)
7484   (prog1
7485       (unless (when (gnus-summary-first-subject nil nil t)
7486                 (gnus-summary-show-thread)
7487                 (gnus-summary-first-subject nil nil t))
7488         (when (gnus-summary-first-subject t)
7489           (gnus-summary-show-thread)
7490           (gnus-summary-first-subject t)))
7491     (gnus-summary-position-point)))
7492
7493 (defun gnus-summary-first-article ()
7494   "Select the first article.
7495 Return nil if there are no articles."
7496   (interactive)
7497   (prog1
7498       (when (gnus-summary-first-subject)
7499         (gnus-summary-show-thread)
7500         (gnus-summary-first-subject)
7501         (gnus-summary-display-article (gnus-summary-article-number)))
7502     (gnus-summary-position-point)))
7503
7504 (defun gnus-summary-best-unread-article (&optional arg)
7505   "Select the unread article with the highest score.
7506 If given a prefix argument, select the next unread article that has a
7507 score higher than the default score."
7508   (interactive "P")
7509   (let ((article (if arg
7510                      (gnus-summary-better-unread-subject)
7511                    (gnus-summary-best-unread-subject))))
7512     (if article
7513         (gnus-summary-goto-article article)
7514       (error "No unread articles"))))
7515
7516 (defun gnus-summary-best-unread-subject ()
7517   "Select the unread subject with the highest score."
7518   (interactive)
7519   (let ((best -1000000)
7520         (data gnus-newsgroup-data)
7521         article score)
7522     (while data
7523       (and (gnus-data-unread-p (car data))
7524            (> (setq score
7525                     (gnus-summary-article-score (gnus-data-number (car data))))
7526               best)
7527            (setq best score
7528                  article (gnus-data-number (car data))))
7529       (setq data (cdr data)))
7530     (when article
7531       (gnus-summary-goto-subject article))
7532     (gnus-summary-position-point)
7533     article))
7534
7535 (defun gnus-summary-better-unread-subject ()
7536   "Select the first unread subject that has a score over the default score."
7537   (interactive)
7538   (let ((data gnus-newsgroup-data)
7539         article score)
7540     (while (and (setq article (gnus-data-number (car data)))
7541                 (or (gnus-data-read-p (car data))
7542                     (not (> (gnus-summary-article-score article)
7543                             gnus-summary-default-score))))
7544       (setq data (cdr data)))
7545     (when article
7546       (gnus-summary-goto-subject article))
7547     (gnus-summary-position-point)
7548     article))
7549
7550 (defun gnus-summary-last-subject ()
7551   "Go to the last displayed subject line in the group."
7552   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7553     (when article
7554       (gnus-summary-goto-subject article))))
7555
7556 (defun gnus-summary-goto-article (article &optional all-headers force)
7557   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7558 If ALL-HEADERS is non-nil, no header lines are hidden.
7559 If FORCE, go to the article even if it isn't displayed.  If FORCE
7560 is a number, it is the line the article is to be displayed on."
7561   (interactive
7562    (list
7563     (completing-read
7564      "Article number or Message-ID: "
7565      (mapcar (lambda (number) (list (int-to-string number)))
7566              gnus-newsgroup-limit))
7567     current-prefix-arg
7568     t))
7569   (prog1
7570       (if (and (stringp article)
7571                (string-match "@\\|%40" article))
7572           (gnus-summary-refer-article article)
7573         (when (stringp article)
7574           (setq article (string-to-number article)))
7575         (if (gnus-summary-goto-subject article force)
7576             (gnus-summary-display-article article all-headers)
7577           (gnus-message 4 "Couldn't go to article %s" article) nil))
7578     (gnus-summary-position-point)))
7579
7580 (defun gnus-summary-goto-last-article ()
7581   "Go to the previously read article."
7582   (interactive)
7583   (prog1
7584       (when gnus-last-article
7585         (gnus-summary-goto-article gnus-last-article nil t))
7586     (gnus-summary-position-point)))
7587
7588 (defun gnus-summary-pop-article (number)
7589   "Pop one article off the history and go to the previous.
7590 NUMBER articles will be popped off."
7591   (interactive "p")
7592   (let (to)
7593     (setq gnus-newsgroup-history
7594           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7595     (if to
7596         (gnus-summary-goto-article (car to) nil t)
7597       (error "Article history empty")))
7598   (gnus-summary-position-point))
7599
7600 ;; Summary commands and functions for limiting the summary buffer.
7601
7602 (defun gnus-summary-limit-to-articles (n)
7603   "Limit the summary buffer to the next N articles.
7604 If not given a prefix, use the process marked articles instead."
7605   (interactive "P")
7606   (prog1
7607       (let ((articles (gnus-summary-work-articles n)))
7608         (setq gnus-newsgroup-processable nil)
7609         (gnus-summary-limit articles))
7610     (gnus-summary-position-point)))
7611
7612 (defun gnus-summary-pop-limit (&optional total)
7613   "Restore the previous limit.
7614 If given a prefix, remove all limits."
7615   (interactive "P")
7616   (when total
7617     (setq gnus-newsgroup-limits
7618           (list (mapcar (lambda (h) (mail-header-number h))
7619                         gnus-newsgroup-headers))))
7620   (unless gnus-newsgroup-limits
7621     (error "No limit to pop"))
7622   (prog1
7623       (gnus-summary-limit nil 'pop)
7624     (gnus-summary-position-point)))
7625
7626 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7627   "Limit the summary buffer to articles that have subjects that match a regexp.
7628 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7629   (interactive
7630    (list (read-string (if current-prefix-arg
7631                           "Exclude subject (regexp): "
7632                         "Limit to subject (regexp): "))
7633          nil current-prefix-arg))
7634   (unless header
7635     (setq header "subject"))
7636   (when (not (equal "" subject))
7637     (prog1
7638         (let ((articles (gnus-summary-find-matching
7639                          (or header "subject") subject 'all nil nil
7640                          not-matching)))
7641           (unless articles
7642             (error "Found no matches for \"%s\"" subject))
7643           (gnus-summary-limit articles))
7644       (gnus-summary-position-point))))
7645
7646 (defun gnus-summary-limit-to-author (from &optional not-matching)
7647   "Limit the summary buffer to articles that have authors that match a regexp.
7648 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7649   (interactive
7650    (list (read-string (if current-prefix-arg
7651                           "Exclude author (regexp): "
7652                         "Limit to author (regexp): "))
7653          current-prefix-arg))
7654   (gnus-summary-limit-to-subject from "from" not-matching))
7655
7656 (defun gnus-summary-limit-to-age (age &optional younger-p)
7657   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7658 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7659 articles that are younger than AGE days."
7660   (interactive
7661    (let ((younger current-prefix-arg)
7662          (days-got nil)
7663          days)
7664      (while (not days-got)
7665        (setq days (if younger
7666                       (read-string "Limit to articles younger than (in days, older when negative): ")
7667                     (read-string
7668                      "Limit to articles older than (in days, younger when negative): ")))
7669        (when (> (length days) 0)
7670          (setq days (read days)))
7671        (if (numberp days)
7672            (progn
7673              (setq days-got t)
7674              (when (< days 0)
7675                (setq younger (not younger))
7676                (setq days (* days -1))))
7677          (message "Please enter a number.")
7678          (sleep-for 1)))
7679      (list days younger)))
7680   (prog1
7681       (let ((data gnus-newsgroup-data)
7682             (cutoff (days-to-time age))
7683             articles d date is-younger)
7684         (while (setq d (pop data))
7685           (when (and (vectorp (gnus-data-header d))
7686                      (setq date (mail-header-date (gnus-data-header d))))
7687             (setq is-younger (time-less-p
7688                               (time-since (condition-case ()
7689                                               (date-to-time date)
7690                                             (error '(0 0))))
7691                               cutoff))
7692             (when (if younger-p
7693                       is-younger
7694                     (not is-younger))
7695               (push (gnus-data-number d) articles))))
7696         (gnus-summary-limit (nreverse articles)))
7697     (gnus-summary-position-point)))
7698
7699 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7700   "Limit the summary buffer to articles that match an 'extra' header."
7701   (interactive
7702    (let ((header
7703           (intern
7704            (gnus-completing-read-with-default
7705             (symbol-name (car gnus-extra-headers))
7706             (if current-prefix-arg
7707                 "Exclude extra header:"
7708               "Limit extra header:")
7709             (mapcar (lambda (x)
7710                       (cons (symbol-name x) x))
7711                     gnus-extra-headers)
7712             nil
7713             t))))
7714      (list header
7715            (read-string (format "%s header %s (regexp): "
7716                                 (if current-prefix-arg "Exclude" "Limit to")
7717                                 header))
7718            current-prefix-arg)))
7719   (when (not (equal "" regexp))
7720     (prog1
7721         (let ((articles (gnus-summary-find-matching
7722                          (cons 'extra header) regexp 'all nil nil
7723                          not-matching)))
7724           (unless articles
7725             (error "Found no matches for \"%s\"" regexp))
7726           (gnus-summary-limit articles))
7727       (gnus-summary-position-point))))
7728
7729 (defun gnus-summary-limit-to-display-predicate ()
7730   "Limit the summary buffer to the predicated in the `display' group parameter."
7731   (interactive)
7732   (unless gnus-newsgroup-display
7733     (error "There is no `display' group parameter"))
7734   (let (articles)
7735     (dolist (number gnus-newsgroup-articles)
7736       (when (funcall gnus-newsgroup-display)
7737         (push number articles)))
7738     (gnus-summary-limit articles))
7739   (gnus-summary-position-point))
7740
7741 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7742 (make-obsolete
7743  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7744
7745 (defun gnus-summary-limit-to-unread (&optional all)
7746   "Limit the summary buffer to articles that are not marked as read.
7747 If ALL is non-nil, limit strictly to unread articles."
7748   (interactive "P")
7749   (if all
7750       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7751     (gnus-summary-limit-to-marks
7752      ;; Concat all the marks that say that an article is read and have
7753      ;; those removed.
7754      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7755            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7756            gnus-low-score-mark gnus-expirable-mark
7757            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7758            gnus-duplicate-mark gnus-souped-mark)
7759      'reverse)))
7760
7761 (defun gnus-summary-limit-to-replied (&optional unreplied)
7762   "Limit the summary buffer to replied articles.
7763 If UNREPLIED (the prefix), limit to unreplied articles."
7764   (interactive "P")
7765   (if unreplied
7766       (gnus-summary-limit
7767        (gnus-set-difference gnus-newsgroup-articles
7768         gnus-newsgroup-replied))
7769     (gnus-summary-limit gnus-newsgroup-replied))
7770   (gnus-summary-position-point))
7771
7772 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7773 (make-obsolete 'gnus-summary-delete-marked-with
7774                'gnus-summary-limit-exclude-marks)
7775
7776 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7777   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7778 If REVERSE, limit the summary buffer to articles that are marked
7779 with MARKS.  MARKS can either be a string of marks or a list of marks.
7780 Returns how many articles were removed."
7781   (interactive "sMarks: ")
7782   (gnus-summary-limit-to-marks marks t))
7783
7784 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7785   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7786 If REVERSE (the prefix), limit the summary buffer to articles that are
7787 not marked with MARKS.  MARKS can either be a string of marks or a
7788 list of marks.
7789 Returns how many articles were removed."
7790   (interactive "sMarks: \nP")
7791   (prog1
7792       (let ((data gnus-newsgroup-data)
7793             (marks (if (listp marks) marks
7794                      (append marks nil))) ; Transform to list.
7795             articles)
7796         (while data
7797           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7798                   (memq (gnus-data-mark (car data)) marks))
7799             (push (gnus-data-number (car data)) articles))
7800           (setq data (cdr data)))
7801         (gnus-summary-limit articles))
7802     (gnus-summary-position-point)))
7803
7804 (defun gnus-summary-limit-to-score (score)
7805   "Limit to articles with score at or above SCORE."
7806   (interactive "NLimit to articles with score of at least: ")
7807   (let ((data gnus-newsgroup-data)
7808         articles)
7809     (while data
7810       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7811                 score)
7812         (push (gnus-data-number (car data)) articles))
7813       (setq data (cdr data)))
7814     (prog1
7815         (gnus-summary-limit articles)
7816       (gnus-summary-position-point))))
7817
7818 (defun gnus-summary-limit-to-unseen ()
7819   "Limit to unseen articles."
7820   (interactive)
7821   (prog1
7822       (gnus-summary-limit gnus-newsgroup-unseen)
7823     (gnus-summary-position-point)))
7824
7825 (defun gnus-summary-limit-include-thread (id)
7826   "Display all the hidden articles that is in the thread with ID in it.
7827 When called interactively, ID is the Message-ID of the current
7828 article."
7829   (interactive (list (mail-header-id (gnus-summary-article-header))))
7830   (let ((articles (gnus-articles-in-thread
7831                    (gnus-id-to-thread (gnus-root-id id)))))
7832     (prog1
7833         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7834       (gnus-summary-limit-include-matching-articles
7835        "subject"
7836        (regexp-quote (gnus-simplify-subject-re
7837                       (mail-header-subject (gnus-id-to-header id)))))
7838       (gnus-summary-position-point))))
7839
7840 (defun gnus-summary-limit-include-matching-articles (header regexp)
7841   "Display all the hidden articles that have HEADERs that match REGEXP."
7842   (interactive (list (read-string "Match on header: ")
7843                      (read-string "Regexp: ")))
7844   (let ((articles (gnus-find-matching-articles header regexp)))
7845     (prog1
7846         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7847       (gnus-summary-position-point))))
7848
7849 (defun gnus-summary-insert-dormant-articles ()
7850   "Insert all the dormant articles for this group into the current buffer."
7851   (interactive)
7852   (let ((gnus-verbose (max 6 gnus-verbose)))
7853     (if (not gnus-newsgroup-dormant)
7854         (gnus-message 3 "No cached articles for this group")
7855       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7856
7857 (defun gnus-summary-limit-include-dormant ()
7858   "Display all the hidden articles that are marked as dormant.
7859 Note that this command only works on a subset of the articles currently
7860 fetched for this group."
7861   (interactive)
7862   (unless gnus-newsgroup-dormant
7863     (error "There are no dormant articles in this group"))
7864   (prog1
7865       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7866     (gnus-summary-position-point)))
7867
7868 (defun gnus-summary-limit-exclude-dormant ()
7869   "Hide all dormant articles."
7870   (interactive)
7871   (prog1
7872       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7873     (gnus-summary-position-point)))
7874
7875 (defun gnus-summary-limit-exclude-childless-dormant ()
7876   "Hide all dormant articles that have no children."
7877   (interactive)
7878   (let ((data (gnus-data-list t))
7879         articles d children)
7880     ;; Find all articles that are either not dormant or have
7881     ;; children.
7882     (while (setq d (pop data))
7883       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7884                 (and (setq children
7885                            (gnus-article-children (gnus-data-number d)))
7886                      (let (found)
7887                        (while children
7888                          (when (memq (car children) articles)
7889                            (setq children nil
7890                                  found t))
7891                          (pop children))
7892                        found)))
7893         (push (gnus-data-number d) articles)))
7894     ;; Do the limiting.
7895     (prog1
7896         (gnus-summary-limit articles)
7897       (gnus-summary-position-point))))
7898
7899 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7900   "Mark all unread excluded articles as read.
7901 If ALL, mark even excluded ticked and dormants as read."
7902   (interactive "P")
7903   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7904   (let ((articles (gnus-sorted-ndifference
7905                    (sort
7906                     (mapcar (lambda (h) (mail-header-number h))
7907                             gnus-newsgroup-headers)
7908                     '<)
7909                    gnus-newsgroup-limit))
7910         article)
7911     (setq gnus-newsgroup-unreads
7912           (gnus-sorted-intersection gnus-newsgroup-unreads
7913                                     gnus-newsgroup-limit))
7914     (if all
7915         (setq gnus-newsgroup-dormant nil
7916               gnus-newsgroup-marked nil
7917               gnus-newsgroup-reads
7918               (nconc
7919                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7920                gnus-newsgroup-reads))
7921       (while (setq article (pop articles))
7922         (unless (or (memq article gnus-newsgroup-dormant)
7923                     (memq article gnus-newsgroup-marked))
7924           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7925
7926 (defun gnus-summary-limit (articles &optional pop)
7927   (if pop
7928       ;; We pop the previous limit off the stack and use that.
7929       (setq articles (car gnus-newsgroup-limits)
7930             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7931     ;; We use the new limit, so we push the old limit on the stack.
7932     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7933   ;; Set the limit.
7934   (setq gnus-newsgroup-limit articles)
7935   (let ((total (length gnus-newsgroup-data))
7936         (data (gnus-data-find-list (gnus-summary-article-number)))
7937         (gnus-summary-mark-below nil)   ; Inhibit this.
7938         found)
7939     ;; This will do all the work of generating the new summary buffer
7940     ;; according to the new limit.
7941     (gnus-summary-prepare)
7942     ;; Hide any threads, possibly.
7943     (gnus-summary-maybe-hide-threads)
7944     ;; Try to return to the article you were at, or one in the
7945     ;; neighborhood.
7946     (when data
7947       ;; We try to find some article after the current one.
7948       (while data
7949         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7950           (setq data nil
7951                 found t))
7952         (setq data (cdr data))))
7953     (unless found
7954       ;; If there is no data, that means that we were after the last
7955       ;; article.  The same goes when we can't find any articles
7956       ;; after the current one.
7957       (goto-char (point-max))
7958       (gnus-summary-find-prev))
7959     (gnus-set-mode-line 'summary)
7960     ;; We return how many articles were removed from the summary
7961     ;; buffer as a result of the new limit.
7962     (- total (length gnus-newsgroup-data))))
7963
7964 (defsubst gnus-invisible-cut-children (threads)
7965   (let ((num 0))
7966     (while threads
7967       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7968         (incf num))
7969       (pop threads))
7970     (< num 2)))
7971
7972 (defsubst gnus-cut-thread (thread)
7973   "Go forwards in the thread until we find an article that we want to display."
7974   (when (or (eq gnus-fetch-old-headers 'some)
7975             (eq gnus-fetch-old-headers 'invisible)
7976             (numberp gnus-fetch-old-headers)
7977             (eq gnus-build-sparse-threads 'some)
7978             (eq gnus-build-sparse-threads 'more))
7979     ;; Deal with old-fetched headers and sparse threads.
7980     (while (and
7981             thread
7982             (or
7983              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7984              (gnus-summary-article-ancient-p
7985               (mail-header-number (car thread))))
7986             (if (or (<= (length (cdr thread)) 1)
7987                     (eq gnus-fetch-old-headers 'invisible))
7988                 (setq gnus-newsgroup-limit
7989                       (delq (mail-header-number (car thread))
7990                             gnus-newsgroup-limit)
7991                       thread (cadr thread))
7992               (when (gnus-invisible-cut-children (cdr thread))
7993                 (let ((th (cdr thread)))
7994                   (while th
7995                     (if (memq (mail-header-number (caar th))
7996                               gnus-newsgroup-limit)
7997                         (setq thread (car th)
7998                               th nil)
7999                       (setq th (cdr th))))))))))
8000   thread)
8001
8002 (defun gnus-cut-threads (threads)
8003   "Cut off all uninteresting articles from the beginning of THREADS."
8004   (when (or (eq gnus-fetch-old-headers 'some)
8005             (eq gnus-fetch-old-headers 'invisible)
8006             (numberp gnus-fetch-old-headers)
8007             (eq gnus-build-sparse-threads 'some)
8008             (eq gnus-build-sparse-threads 'more))
8009     (let ((th threads))
8010       (while th
8011         (setcar th (gnus-cut-thread (car th)))
8012         (setq th (cdr th)))))
8013   ;; Remove nixed out threads.
8014   (delq nil threads))
8015
8016 (defun gnus-summary-initial-limit (&optional show-if-empty)
8017   "Figure out what the initial limit is supposed to be on group entry.
8018 This entails weeding out unwanted dormants, low-scored articles,
8019 fetch-old-headers verbiage, and so on."
8020   ;; Most groups have nothing to remove.
8021   (if (or gnus-inhibit-limiting
8022           (and (null gnus-newsgroup-dormant)
8023                (eq gnus-newsgroup-display 'gnus-not-ignore)
8024                (not (eq gnus-fetch-old-headers 'some))
8025                (not (numberp gnus-fetch-old-headers))
8026                (not (eq gnus-fetch-old-headers 'invisible))
8027                (null gnus-summary-expunge-below)
8028                (not (eq gnus-build-sparse-threads 'some))
8029                (not (eq gnus-build-sparse-threads 'more))
8030                (null gnus-thread-expunge-below)
8031                (not gnus-use-nocem)))
8032       ()                                ; Do nothing.
8033     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8034     (setq gnus-newsgroup-limit nil)
8035     (mapatoms
8036      (lambda (node)
8037        (unless (car (symbol-value node))
8038          ;; These threads have no parents -- they are roots.
8039          (let ((nodes (cdr (symbol-value node)))
8040                thread)
8041            (while nodes
8042              (if (and gnus-thread-expunge-below
8043                       (< (gnus-thread-total-score (car nodes))
8044                          gnus-thread-expunge-below))
8045                  (gnus-expunge-thread (pop nodes))
8046                (setq thread (pop nodes))
8047                (gnus-summary-limit-children thread))))))
8048      gnus-newsgroup-dependencies)
8049     ;; If this limitation resulted in an empty group, we might
8050     ;; pop the previous limit and use it instead.
8051     (when (and (not gnus-newsgroup-limit)
8052                show-if-empty)
8053       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8054     gnus-newsgroup-limit))
8055
8056 (defun gnus-summary-limit-children (thread)
8057   "Return 1 if this subthread is visible and 0 if it is not."
8058   ;; First we get the number of visible children to this thread.  This
8059   ;; is done by recursing down the thread using this function, so this
8060   ;; will really go down to a leaf article first, before slowly
8061   ;; working its way up towards the root.
8062   (when thread
8063     (let* ((max-lisp-eval-depth 5000)
8064            (children
8065            (if (cdr thread)
8066                (apply '+ (mapcar 'gnus-summary-limit-children
8067                                  (cdr thread)))
8068              0))
8069           (number (mail-header-number (car thread)))
8070           score)
8071       (if (and
8072            (not (memq number gnus-newsgroup-marked))
8073            (or
8074             ;; If this article is dormant and has absolutely no visible
8075             ;; children, then this article isn't visible.
8076             (and (memq number gnus-newsgroup-dormant)
8077                  (zerop children))
8078             ;; If this is "fetch-old-headered" and there is no
8079             ;; visible children, then we don't want this article.
8080             (and (or (eq gnus-fetch-old-headers 'some)
8081                      (numberp gnus-fetch-old-headers))
8082                  (gnus-summary-article-ancient-p number)
8083                  (zerop children))
8084             ;; If this is "fetch-old-headered" and `invisible', then
8085             ;; we don't want this article.
8086             (and (eq gnus-fetch-old-headers 'invisible)
8087                  (gnus-summary-article-ancient-p number))
8088             ;; If this is a sparsely inserted article with no children,
8089             ;; we don't want it.
8090             (and (eq gnus-build-sparse-threads 'some)
8091                  (gnus-summary-article-sparse-p number)
8092                  (zerop children))
8093             ;; If we use expunging, and this article is really
8094             ;; low-scored, then we don't want this article.
8095             (when (and gnus-summary-expunge-below
8096                        (< (setq score
8097                                 (or (cdr (assq number gnus-newsgroup-scored))
8098                                     gnus-summary-default-score))
8099                           gnus-summary-expunge-below))
8100               ;; We increase the expunge-tally here, but that has
8101               ;; nothing to do with the limits, really.
8102               (incf gnus-newsgroup-expunged-tally)
8103               ;; We also mark as read here, if that's wanted.
8104               (when (and gnus-summary-mark-below
8105                          (< score gnus-summary-mark-below))
8106                 (setq gnus-newsgroup-unreads
8107                       (delq number gnus-newsgroup-unreads))
8108                 (if gnus-newsgroup-auto-expire
8109                     (push number gnus-newsgroup-expirable)
8110                   (push (cons number gnus-low-score-mark)
8111                         gnus-newsgroup-reads)))
8112               t)
8113             ;; Do the `display' group parameter.
8114             (and gnus-newsgroup-display
8115                  (not (funcall gnus-newsgroup-display)))
8116             ;; Check NoCeM things.
8117             (when (and gnus-use-nocem
8118                        (gnus-nocem-unwanted-article-p
8119                         (mail-header-id (car thread))))
8120               (setq gnus-newsgroup-unreads
8121                     (delq number gnus-newsgroup-unreads))
8122               t)))
8123           ;; Nope, invisible article.
8124           0
8125         ;; Ok, this article is to be visible, so we add it to the limit
8126         ;; and return 1.
8127         (push number gnus-newsgroup-limit)
8128         1))))
8129
8130 (defun gnus-expunge-thread (thread)
8131   "Mark all articles in THREAD as read."
8132   (let* ((number (mail-header-number (car thread))))
8133     (incf gnus-newsgroup-expunged-tally)
8134     ;; We also mark as read here, if that's wanted.
8135     (setq gnus-newsgroup-unreads
8136           (delq number gnus-newsgroup-unreads))
8137     (if gnus-newsgroup-auto-expire
8138         (push number gnus-newsgroup-expirable)
8139       (push (cons number gnus-low-score-mark)
8140             gnus-newsgroup-reads)))
8141   ;; Go recursively through all subthreads.
8142   (mapcar 'gnus-expunge-thread (cdr thread)))
8143
8144 ;; Summary article oriented commands
8145
8146 (defun gnus-summary-refer-parent-article (n)
8147   "Refer parent article N times.
8148 If N is negative, go to ancestor -N instead.
8149 The difference between N and the number of articles fetched is returned."
8150   (interactive "p")
8151   (let ((skip 1)
8152         error header ref)
8153     (when (not (natnump n))
8154       (setq skip (abs n)
8155             n 1))
8156     (while (and (> n 0)
8157                 (not error))
8158       (setq header (gnus-summary-article-header))
8159       (if (and (eq (mail-header-number header)
8160                    (cdr gnus-article-current))
8161                (equal gnus-newsgroup-name
8162                       (car gnus-article-current)))
8163           ;; If we try to find the parent of the currently
8164           ;; displayed article, then we take a look at the actual
8165           ;; References header, since this is slightly more
8166           ;; reliable than the References field we got from the
8167           ;; server.
8168           (save-excursion
8169             (set-buffer gnus-original-article-buffer)
8170             (nnheader-narrow-to-headers)
8171             (unless (setq ref (message-fetch-field "references"))
8172               (when (setq ref (message-fetch-field "in-reply-to"))
8173                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8174             (widen))
8175         (setq ref
8176               ;; It's not the current article, so we take a bet on
8177               ;; the value we got from the server.
8178               (mail-header-references header)))
8179       (if (and ref
8180                (not (equal ref "")))
8181           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8182             (gnus-message 1 "Couldn't find parent"))
8183         (gnus-message 1 "No references in article %d"
8184                       (gnus-summary-article-number))
8185         (setq error t))
8186       (decf n))
8187     (gnus-summary-position-point)
8188     n))
8189
8190 (defun gnus-summary-refer-references ()
8191   "Fetch all articles mentioned in the References header.
8192 Return the number of articles fetched."
8193   (interactive)
8194   (let ((ref (mail-header-references (gnus-summary-article-header)))
8195         (current (gnus-summary-article-number))
8196         (n 0))
8197     (if (or (not ref)
8198             (equal ref ""))
8199         (error "No References in the current article")
8200       ;; For each Message-ID in the References header...
8201       (while (string-match "<[^>]*>" ref)
8202         (incf n)
8203         ;; ... fetch that article.
8204         (gnus-summary-refer-article
8205          (prog1 (match-string 0 ref)
8206            (setq ref (substring ref (match-end 0))))))
8207       (gnus-summary-goto-subject current)
8208       (gnus-summary-position-point)
8209       n)))
8210
8211 (defun gnus-summary-refer-thread (&optional limit)
8212   "Fetch all articles in the current thread.
8213 If LIMIT (the numerical prefix), fetch that many old headers instead
8214 of what's specified by the `gnus-refer-thread-limit' variable."
8215   (interactive "P")
8216   (let ((id (mail-header-id (gnus-summary-article-header)))
8217         (limit (if limit (prefix-numeric-value limit)
8218                  gnus-refer-thread-limit)))
8219     (unless (eq gnus-fetch-old-headers 'invisible)
8220       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8221       ;; Retrieve the headers and read them in.
8222       (if (eq (if (numberp limit)
8223                   (gnus-retrieve-headers
8224                    (list (min
8225                           (+ (mail-header-number
8226                               (gnus-summary-article-header))
8227                              limit)
8228                           gnus-newsgroup-end))
8229                    gnus-newsgroup-name (* limit 2))
8230                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8231                 ;; headers.
8232                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8233                                        gnus-newsgroup-name limit))
8234               'nov)
8235           (gnus-build-all-threads)
8236         (error "Can't fetch thread from back ends that don't support NOV"))
8237       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8238     (gnus-summary-limit-include-thread id)))
8239
8240 (defun gnus-summary-refer-article (message-id)
8241   "Fetch an article specified by MESSAGE-ID."
8242   (interactive "sMessage-ID: ")
8243   (when (and (stringp message-id)
8244              (not (zerop (length message-id))))
8245     (setq message-id (gnus-replace-in-string message-id " " ""))
8246     ;; Construct the correct Message-ID if necessary.
8247     ;; Suggested by tale@pawl.rpi.edu.
8248     (unless (string-match "^<" message-id)
8249       (setq message-id (concat "<" message-id)))
8250     (unless (string-match ">$" message-id)
8251       (setq message-id (concat message-id ">")))
8252     ;; People often post MIDs from URLs, so unhex it:
8253     (unless (string-match "@" message-id)
8254       (setq message-id (gnus-url-unhex-string message-id)))
8255     (let* ((header (gnus-id-to-header message-id))
8256            (sparse (and header
8257                         (gnus-summary-article-sparse-p
8258                          (mail-header-number header))
8259                         (memq (mail-header-number header)
8260                               gnus-newsgroup-limit)))
8261            number)
8262       (cond
8263        ;; If the article is present in the buffer we just go to it.
8264        ((and header
8265              (or (not (gnus-summary-article-sparse-p
8266                        (mail-header-number header)))
8267                  sparse))
8268         (prog1
8269             (gnus-summary-goto-article
8270              (mail-header-number header) nil t)
8271           (when sparse
8272             (gnus-summary-update-article (mail-header-number header)))))
8273        (t
8274         ;; We fetch the article.
8275         (catch 'found
8276           (dolist (gnus-override-method (gnus-refer-article-methods))
8277             (when (and (gnus-check-server gnus-override-method)
8278                        ;; Fetch the header,
8279                        (setq number (gnus-summary-insert-subject message-id)))
8280               ;; and display the article.
8281               (gnus-summary-select-article nil nil nil number)
8282               (throw 'found t)))
8283           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8284
8285 (defun gnus-refer-article-methods ()
8286   "Return a list of referable methods."
8287   (cond
8288    ;; No method, so we default to current and native.
8289    ((null gnus-refer-article-method)
8290     (list gnus-current-select-method gnus-select-method))
8291    ;; Current.
8292    ((eq 'current gnus-refer-article-method)
8293     (list gnus-current-select-method))
8294    ;; List of select methods.
8295    ((not (and (symbolp (car gnus-refer-article-method))
8296               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8297     (let (out)
8298       (dolist (method gnus-refer-article-method)
8299         (push (if (eq 'current method)
8300                   gnus-current-select-method
8301                 method)
8302               out))
8303       (nreverse out)))
8304    ;; One single select method.
8305    (t
8306     (list gnus-refer-article-method))))
8307
8308 (defun gnus-summary-edit-parameters ()
8309   "Edit the group parameters of the current group."
8310   (interactive)
8311   (gnus-group-edit-group gnus-newsgroup-name 'params))
8312
8313 (defun gnus-summary-customize-parameters ()
8314   "Customize the group parameters of the current group."
8315   (interactive)
8316   (gnus-group-customize gnus-newsgroup-name))
8317
8318 (defun gnus-summary-enter-digest-group (&optional force)
8319   "Enter an nndoc group based on the current article.
8320 If FORCE, force a digest interpretation.  If not, try
8321 to guess what the document format is."
8322   (interactive "P")
8323   (let ((conf gnus-current-window-configuration))
8324     (save-window-excursion
8325       (save-excursion
8326         (let (gnus-article-prepare-hook
8327               gnus-display-mime-function
8328               gnus-break-pages)
8329           (gnus-summary-select-article))))
8330     (setq gnus-current-window-configuration conf)
8331     (let* ((name (format "%s-%d"
8332                          (gnus-group-prefixed-name
8333                           gnus-newsgroup-name (list 'nndoc ""))
8334                          (with-current-buffer gnus-summary-buffer
8335                            gnus-current-article)))
8336            (ogroup gnus-newsgroup-name)
8337            (params (append (gnus-info-params (gnus-get-info ogroup))
8338                            (list (cons 'to-group ogroup))
8339                            (list (cons 'parent-group ogroup))
8340                            (list (cons 'save-article-group ogroup))))
8341            (case-fold-search t)
8342            (buf (current-buffer))
8343            dig to-address)
8344       (save-excursion
8345         (set-buffer gnus-original-article-buffer)
8346         ;; Have the digest group inherit the main mail address of
8347         ;; the parent article.
8348         (when (setq to-address (or (gnus-fetch-field "reply-to")
8349                                    (gnus-fetch-field "from")))
8350           (setq params (append
8351                         (list (cons 'to-address
8352                                     (funcall gnus-decode-encoded-word-function
8353                                              to-address))))))
8354         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8355         (insert-buffer-substring gnus-original-article-buffer)
8356         ;; Remove lines that may lead nndoc to misinterpret the
8357         ;; document type.
8358         (narrow-to-region
8359          (goto-char (point-min))
8360          (or (search-forward "\n\n" nil t) (point)))
8361         (goto-char (point-min))
8362         (delete-matching-lines "^Path:\\|^From ")
8363         (widen))
8364       (unwind-protect
8365           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8366                     (gnus-newsgroup-ephemeral-ignored-charsets
8367                      gnus-newsgroup-ignored-charsets))
8368                 (gnus-group-read-ephemeral-group
8369                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8370                               (nndoc-article-type
8371                                ,(if force 'mbox 'guess)))
8372                  t nil nil nil
8373                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8374                                                         "ADAPT")))))
8375               ;; Make all postings to this group go to the parent group.
8376               (nconc (gnus-info-params (gnus-get-info name))
8377                      params)
8378             ;; Couldn't select this doc group.
8379             (switch-to-buffer buf)
8380             (gnus-set-global-variables)
8381             (gnus-configure-windows 'summary)
8382             (gnus-message 3 "Article couldn't be entered?"))
8383         (kill-buffer dig)))))
8384
8385 (defun gnus-summary-read-document (n)
8386   "Open a new group based on the current article(s).
8387 This will allow you to read digests and other similar
8388 documents as newsgroups.
8389 Obeys the standard process/prefix convention."
8390   (interactive "P")
8391   (let* ((ogroup gnus-newsgroup-name)
8392          (params (append (gnus-info-params (gnus-get-info ogroup))
8393                          (list (cons 'to-group ogroup))))
8394          group egroup groups vgroup)
8395     (dolist (article (gnus-summary-work-articles n))
8396       (setq group (format "%s-%d" gnus-newsgroup-name article))
8397       (gnus-summary-remove-process-mark article)
8398       (when (gnus-summary-display-article article)
8399         (save-excursion
8400           (with-temp-buffer
8401             (insert-buffer-substring gnus-original-article-buffer)
8402             ;; Remove some headers that may lead nndoc to make
8403             ;; the wrong guess.
8404             (message-narrow-to-head)
8405             (goto-char (point-min))
8406             (delete-matching-lines "^Path:\\|^From ")
8407             (widen)
8408             (if (setq egroup
8409                       (gnus-group-read-ephemeral-group
8410                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8411                                      (nndoc-article-type guess))
8412                        t nil t))
8413                 (progn
8414                   ;; Make all postings to this group go to the parent group.
8415                   (nconc (gnus-info-params (gnus-get-info egroup))
8416                          params)
8417                   (push egroup groups))
8418               ;; Couldn't select this doc group.
8419               (gnus-error 3 "Article couldn't be entered"))))))
8420     ;; Now we have selected all the documents.
8421     (cond
8422      ((not groups)
8423       (error "None of the articles could be interpreted as documents"))
8424      ((gnus-group-read-ephemeral-group
8425        (setq vgroup (format
8426                      "nnvirtual:%s-%s" gnus-newsgroup-name
8427                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8428        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8429        t
8430        (cons (current-buffer) 'summary)))
8431      (t
8432       (error "Couldn't select virtual nndoc group")))))
8433
8434 (defun gnus-summary-isearch-article (&optional regexp-p)
8435   "Do incremental search forward on the current article.
8436 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8437   (interactive "P")
8438   (let* ((gnus-inhibit-treatment t)
8439          (old (gnus-summary-select-article)))
8440     (gnus-configure-windows 'article)
8441     (gnus-eval-in-buffer-window gnus-article-buffer
8442       (save-restriction
8443         (widen)
8444         (when (eq 'old old)
8445           (gnus-article-show-all-headers))
8446         (goto-char (point-min))
8447         (isearch-forward regexp-p)))))
8448
8449 (defun gnus-summary-search-article-forward (regexp &optional backward)
8450   "Search for an article containing REGEXP forward.
8451 If BACKWARD, search backward instead."
8452   (interactive
8453    (list (read-string
8454           (format "Search article %s (regexp%s): "
8455                   (if current-prefix-arg "backward" "forward")
8456                   (if gnus-last-search-regexp
8457                       (concat ", default " gnus-last-search-regexp)
8458                     "")))
8459          current-prefix-arg))
8460   (if (string-equal regexp "")
8461       (setq regexp (or gnus-last-search-regexp ""))
8462     (setq gnus-last-search-regexp regexp)
8463     (setq gnus-article-before-search gnus-current-article))
8464   ;; Intentionally set gnus-last-article.
8465   (setq gnus-last-article gnus-article-before-search)
8466   (let ((gnus-last-article gnus-last-article))
8467     (if (gnus-summary-search-article regexp backward)
8468         (gnus-summary-show-thread)
8469       (signal 'search-failed (list regexp)))))
8470
8471 (defun gnus-summary-search-article-backward (regexp)
8472   "Search for an article containing REGEXP backward."
8473   (interactive
8474    (list (read-string
8475           (format "Search article backward (regexp%s): "
8476                   (if gnus-last-search-regexp
8477                       (concat ", default " gnus-last-search-regexp)
8478                     "")))))
8479   (gnus-summary-search-article-forward regexp 'backward))
8480
8481 (eval-when-compile
8482   (defmacro gnus-summary-search-article-position-point (regexp backward)
8483     "Dehighlight the last matched text and goto the beginning position."
8484     (` (if (and gnus-summary-search-article-matched-data
8485                 (let ((text (caddr gnus-summary-search-article-matched-data))
8486                       (inhibit-read-only t)
8487                       buffer-read-only)
8488                   (delete-region
8489                    (goto-char (car gnus-summary-search-article-matched-data))
8490                    (cadr gnus-summary-search-article-matched-data))
8491                   (insert text)
8492                   (string-match (, regexp) text)))
8493            (if (, backward) (beginning-of-line) (end-of-line))
8494          (goto-char (if (, backward) (point-max) (point-min))))))
8495
8496   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8497     "Place point where X-Face image is displayed."
8498     (if (featurep 'xemacs)
8499         (` (let ((end (if (search-forward "\n\n" nil t)
8500                           (goto-char (1- (point)))
8501                         (point-min)))
8502                  extent)
8503              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8504              (unless (and (re-search-forward "^From:" end t)
8505                           (setq extent (extent-at (point)))
8506                           (extent-begin-glyph extent))
8507                (goto-char (, opoint)))))
8508       (` (let ((end (if (search-forward "\n\n" nil t)
8509                         (goto-char (1- (point)))
8510                       (point-min)))
8511                (start (or (search-backward "\n\n" nil t) (point-min))))
8512            (goto-char
8513             (or (text-property-any start end 'x-face-image t);; x-face-e21
8514                 (text-property-any start end 'x-face-mule-bitmap-image t)
8515                 (, opoint)))))))
8516
8517   (defmacro gnus-summary-search-article-highlight-matched-text
8518     (backward treated x-face)
8519     "Highlight matched text in the function `gnus-summary-search-article'."
8520     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8521              (end (set-marker (make-marker) (match-end 0)))
8522              (inhibit-read-only t)
8523              buffer-read-only)
8524          (unless treated
8525            (let ((,@
8526                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8527                     (mapcar
8528                      (lambda (item) (setq items (delq item items)))
8529                      '(gnus-treat-buttonize
8530                        gnus-treat-fill-article
8531                        gnus-treat-fill-long-lines
8532                        gnus-treat-emphasize
8533                        gnus-treat-highlight-headers
8534                        gnus-treat-highlight-citation
8535                        gnus-treat-highlight-signature
8536                        gnus-treat-overstrike
8537                        gnus-treat-display-x-face
8538                        gnus-treat-buttonize-head
8539                        gnus-treat-decode-article-as-default-mime-charset))
8540                     (static-if (featurep 'xemacs)
8541                         items
8542                       (cons '(x-face-mule-delete-x-face-field
8543                               (quote never))
8544                             items))))
8545                  (gnus-treat-display-x-face
8546                   (when (, x-face) gnus-treat-display-x-face)))
8547              (gnus-article-prepare-mime-display)))
8548          (goto-char (if (, backward) start end))
8549          (when (, x-face)
8550            (gnus-summary-search-article-highlight-goto-x-face (point)))
8551          (setq gnus-summary-search-article-matched-data
8552                (list start end (buffer-substring start end)))
8553          (unless (eq start end);; matched text has been deleted. :-<
8554            (put-text-property start end 'face
8555                               (or (find-face 'isearch)
8556                                   'secondary-selection))))))
8557   )
8558
8559 (defun gnus-summary-search-article (regexp &optional backward)
8560   "Search for an article containing REGEXP.
8561 Optional argument BACKWARD means do search for backward.
8562 `gnus-select-article-hook' is not called during the search."
8563   ;; We have to require this here to make sure that the following
8564   ;; dynamic binding isn't shadowed by autoloading.
8565   (require 'gnus-async)
8566   (require 'gnus-art)
8567   (let ((gnus-select-article-hook nil)  ;Disable hook.
8568         (gnus-article-prepare-hook nil)
8569         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8570         (gnus-use-article-prefetch nil)
8571         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8572         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8573         (gnus-visual nil)
8574         (gnus-keep-backlog nil)
8575         (gnus-break-pages nil)
8576         (gnus-summary-display-arrow nil)
8577         (gnus-updated-mode-lines nil)
8578         (gnus-auto-center-summary nil)
8579         (sum (current-buffer))
8580         (found nil)
8581         point treated)
8582     (gnus-save-hidden-threads
8583       (static-if (featurep 'xemacs)
8584           (let ((gnus-inhibit-treatment t))
8585             (setq treated (eq 'old (gnus-summary-select-article)))
8586             (when (and treated
8587                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8588                                  (window-live-p (get-buffer-window
8589                                                  gnus-article-buffer t)))))
8590               (gnus-summary-select-article nil t)
8591               (setq treated nil)))
8592         (let ((gnus-inhibit-treatment t)
8593               (x-face-mule-delete-x-face-field 'never))
8594           (setq treated (eq 'old (gnus-summary-select-article)))
8595           (when (and treated
8596                      (not
8597                       (and (gnus-buffer-live-p gnus-article-buffer)
8598                            (window-live-p (get-buffer-window
8599                                            gnus-article-buffer t))
8600                            (or (not (string-match "^\\^X-Face:" regexp))
8601                                (with-current-buffer gnus-article-buffer
8602                                  gnus-summary-search-article-matched-data)))))
8603             (gnus-summary-select-article nil t)
8604             (setq treated nil))))
8605       (set-buffer gnus-article-buffer)
8606       (widen)
8607       (if treated
8608           (progn
8609             (gnus-article-show-all-headers)
8610             (gnus-summary-search-article-position-point regexp backward))
8611         (goto-char (if backward (point-max) (point-min))))
8612       (while (not found)
8613         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8614         (if (if backward
8615                 (re-search-backward regexp nil t)
8616               (re-search-forward regexp nil t))
8617             ;; We found the regexp.
8618             (progn
8619               (gnus-summary-search-article-highlight-matched-text
8620                backward treated (string-match "^\\^X-Face:" regexp))
8621               (setq found 'found)
8622               (forward-line
8623                (/ (- 2 (window-height
8624                         (get-buffer-window gnus-article-buffer t)))
8625                   2))
8626               (set-window-start
8627                (get-buffer-window (current-buffer))
8628                (point))
8629               (set-buffer sum)
8630               (setq point (point)))
8631           ;; We didn't find it, so we go to the next article.
8632           (set-buffer sum)
8633           (setq found 'not)
8634           (while (eq found 'not)
8635             (if (not (if backward (gnus-summary-find-prev)
8636                        (gnus-summary-find-next)))
8637                 ;; No more articles.
8638                 (setq found t)
8639               ;; Select the next article and adjust point.
8640               (unless (gnus-summary-article-sparse-p
8641                        (gnus-summary-article-number))
8642                 (setq found nil)
8643                 (let ((gnus-inhibit-treatment t))
8644                   (gnus-summary-select-article))
8645                 (setq treated nil)
8646                 (set-buffer gnus-article-buffer)
8647                 (widen)
8648                 (goto-char (if backward (point-max) (point-min))))))))
8649       (gnus-message 7 ""))
8650     ;; Return whether we found the regexp.
8651     (when (eq found 'found)
8652       (goto-char point)
8653       (gnus-summary-show-thread)
8654       (gnus-summary-goto-subject gnus-current-article)
8655       (gnus-summary-position-point)
8656       t)))
8657
8658 (defun gnus-find-matching-articles (header regexp)
8659   "Return a list of all articles that match REGEXP on HEADER.
8660 This search includes all articles in the current group that Gnus has
8661 fetched headers for, whether they are displayed or not."
8662   (let ((articles nil)
8663         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8664         (case-fold-search t))
8665     (dolist (header gnus-newsgroup-headers)
8666       (when (string-match regexp (funcall func header))
8667         (push (mail-header-number header) articles)))
8668     (nreverse articles)))
8669
8670 (defun gnus-summary-find-matching (header regexp &optional backward unread
8671                                           not-case-fold not-matching)
8672   "Return a list of all articles that match REGEXP on HEADER.
8673 The search stars on the current article and goes forwards unless
8674 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8675 If UNREAD is non-nil, only unread articles will
8676 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8677 in the comparisons. If NOT-MATCHING, return a list of all articles that
8678 not match REGEXP on HEADER."
8679   (let ((case-fold-search (not not-case-fold))
8680         articles d func)
8681     (if (consp header)
8682         (if (eq (car header) 'extra)
8683             (setq func
8684                   `(lambda (h)
8685                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8686                          "")))
8687           (error "%s is an invalid header" header))
8688       (unless (fboundp (intern (concat "mail-header-" header)))
8689         (error "%s is not a valid header" header))
8690       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8691     (dolist (d (if (eq backward 'all)
8692                    gnus-newsgroup-data
8693                  (gnus-data-find-list
8694                   (gnus-summary-article-number)
8695                   (gnus-data-list backward))))
8696       (when (and (or (not unread)       ; We want all articles...
8697                      (gnus-data-unread-p d)) ; Or just unreads.
8698                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8699                  (if not-matching
8700                      (not (string-match
8701                            regexp
8702                            (funcall func (gnus-data-header d))))
8703                    (string-match regexp
8704                                  (funcall func (gnus-data-header d)))))
8705         (push (gnus-data-number d) articles))) ; Success!
8706     (nreverse articles)))
8707
8708 (defun gnus-summary-execute-command (header regexp command &optional backward)
8709   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8710 If HEADER is an empty string (or nil), the match is done on the entire
8711 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8712   (interactive
8713    (list (let ((completion-ignore-case t))
8714            (completing-read
8715             "Header name: "
8716             (mapcar (lambda (header) (list (format "%s" header)))
8717                     (append
8718                      '("Number" "Subject" "From" "Lines" "Date"
8719                        "Message-ID" "Xref" "References" "Body")
8720                      gnus-extra-headers))
8721             nil 'require-match))
8722          (read-string "Regexp: ")
8723          (read-key-sequence "Command: ")
8724          current-prefix-arg))
8725   (when (equal header "Body")
8726     (setq header ""))
8727   ;; Hidden thread subtrees must be searched as well.
8728   (gnus-summary-show-all-threads)
8729   ;; We don't want to change current point nor window configuration.
8730   (save-excursion
8731     (save-window-excursion
8732       (let (gnus-visual
8733             gnus-treat-strip-trailing-blank-lines
8734             gnus-treat-strip-leading-blank-lines
8735             gnus-treat-strip-multiple-blank-lines
8736             gnus-treat-hide-boring-headers
8737             gnus-treat-fold-newsgroups
8738             gnus-article-prepare-hook)
8739         (gnus-message 6 "Executing %s..." (key-description command))
8740         ;; We'd like to execute COMMAND interactively so as to give arguments.
8741         (gnus-execute header regexp
8742                       `(call-interactively ',(key-binding command))
8743                       backward)
8744         (gnus-message 6 "Executing %s...done" (key-description command))))))
8745
8746 (defun gnus-summary-beginning-of-article ()
8747   "Scroll the article back to the beginning."
8748   (interactive)
8749   (gnus-summary-select-article)
8750   (gnus-configure-windows 'article)
8751   (gnus-eval-in-buffer-window gnus-article-buffer
8752     (widen)
8753     (goto-char (point-min))
8754     (when gnus-break-pages
8755       (gnus-narrow-to-page))))
8756
8757 (defun gnus-summary-end-of-article ()
8758   "Scroll to the end of the article."
8759   (interactive)
8760   (gnus-summary-select-article)
8761   (gnus-configure-windows 'article)
8762   (gnus-eval-in-buffer-window gnus-article-buffer
8763     (widen)
8764     (goto-char (point-max))
8765     (recenter -3)
8766     (when gnus-break-pages
8767       (when (re-search-backward page-delimiter nil t)
8768         (narrow-to-region (match-end 0) (point-max)))
8769       (gnus-narrow-to-page))))
8770
8771 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8772   "Truncate to LEN and quote all \"(\"'s in STRING."
8773   (gnus-replace-in-string (if (and len (> (length string) len))
8774                               (substring string 0 len)
8775                             string)
8776                           "[()]" "\\\\\\&"))
8777
8778 (defun gnus-summary-print-article (&optional filename n)
8779   "Generate and print a PostScript image of the process-marked (mail) articles.
8780
8781 If used interactively, print the current article if none are
8782 process-marked.  With prefix arg, prompt the user for the name of the
8783 file to save in.
8784
8785 When used from Lisp, accept two optional args FILENAME and N.  N means
8786 to print the next N articles.  If N is negative, print the N previous
8787 articles.  If N is nil and articles have been marked with the process
8788 mark, print these instead.
8789
8790 If the optional first argument FILENAME is nil, send the image to the
8791 printer.  If FILENAME is a string, save the PostScript image in a file with
8792 that name.  If FILENAME is a number, prompt the user for the name of the file
8793 to save in."
8794   (interactive (list (ps-print-preprint current-prefix-arg)))
8795   (dolist (article (gnus-summary-work-articles n))
8796     (gnus-summary-select-article nil nil 'pseudo article)
8797     (gnus-eval-in-buffer-window gnus-article-buffer
8798       (gnus-print-buffer))
8799     (gnus-summary-remove-process-mark article))
8800   (ps-despool filename))
8801
8802 (defun gnus-print-buffer ()
8803   (let ((buffer (generate-new-buffer " *print*")))
8804     (unwind-protect
8805         (progn
8806           (copy-to-buffer buffer (point-min) (point-max))
8807           (set-buffer buffer)
8808           (gnus-remove-text-with-property 'gnus-decoration)
8809           (when (gnus-visual-p 'article-highlight 'highlight)
8810             ;; Copy-to-buffer doesn't copy overlay.  So redo
8811             ;; highlight.
8812             (let ((gnus-article-buffer buffer))
8813               (gnus-article-highlight-citation t)
8814               (gnus-article-highlight-signature)
8815               (gnus-article-emphasize)
8816               (gnus-article-delete-invisible-text)))
8817           (let ((ps-left-header
8818                  (list
8819                   (concat "("
8820                           (gnus-summary-print-truncate-and-quote
8821                            (mail-header-subject gnus-current-headers)
8822                            66) ")")
8823                   (concat "("
8824                           (gnus-summary-print-truncate-and-quote
8825                            (mail-header-from gnus-current-headers)
8826                            45) ")")))
8827                 (ps-right-header
8828                  (list
8829                   "/pagenumberstring load"
8830                   (concat "("
8831                           (mail-header-date gnus-current-headers) ")"))))
8832             (gnus-run-hooks 'gnus-ps-print-hook)
8833             (save-excursion
8834               (if window-system
8835                   (ps-spool-buffer-with-faces)
8836                 (ps-spool-buffer)))))
8837       (kill-buffer buffer))))
8838
8839 (defun gnus-summary-show-article (&optional arg)
8840   "Force redisplaying of the current article.
8841 If ARG (the prefix) is a number, show the article with the charset
8842 defined in `gnus-summary-show-article-charset-alist', or the charset
8843 input.
8844 If ARG (the prefix) is non-nil and not a number, show the raw article
8845 without any article massaging functions being run.  Normally, the key
8846 strokes are `C-u g'."
8847   (interactive "P")
8848   (cond
8849    ((numberp arg)
8850     (gnus-summary-show-article t)
8851     (let* ((gnus-newsgroup-charset
8852             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8853                 (mm-read-coding-system
8854                  "View as charset: " ;; actually it is coding system.
8855                  (with-current-buffer gnus-article-buffer
8856                    (mm-detect-coding-region (point) (point-max))))))
8857            (default-mime-charset gnus-newsgroup-charset)
8858            (gnus-newsgroup-ignored-charsets 'gnus-all))
8859       (gnus-summary-select-article nil 'force)
8860       (let ((deps gnus-newsgroup-dependencies)
8861             head header lines)
8862         (save-excursion
8863           (set-buffer gnus-original-article-buffer)
8864           (save-restriction
8865             (message-narrow-to-head)
8866             (setq head (buffer-string))
8867             (goto-char (point-min))
8868             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8869               (goto-char (point-max))
8870               (widen)
8871               (setq lines (1- (count-lines (point) (point-max))))))
8872           (with-temp-buffer
8873             (insert (format "211 %d Article retrieved.\n"
8874                             (cdr gnus-article-current)))
8875             (insert head)
8876             (if lines (insert (format "Lines: %d\n" lines)))
8877             (insert ".\n")
8878             (let ((nntp-server-buffer (current-buffer)))
8879               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8880         (gnus-data-set-header
8881          (gnus-data-find (cdr gnus-article-current))
8882          header)
8883         (gnus-summary-update-article-line
8884          (cdr gnus-article-current) header)
8885         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8886           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8887    ((not arg)
8888     ;; Select the article the normal way.
8889     (gnus-summary-select-article nil 'force))
8890    (t
8891     ;; We have to require this here to make sure that the following
8892     ;; dynamic binding isn't shadowed by autoloading.
8893     (require 'gnus-async)
8894     (require 'gnus-art)
8895     ;; Bind the article treatment functions to nil.
8896     (let ((gnus-have-all-headers t)
8897           gnus-article-prepare-hook
8898           gnus-article-decode-hook
8899           gnus-break-pages
8900           gnus-show-mime
8901           (gnus-inhibit-treatment t))
8902       (gnus-summary-select-article nil 'force))))
8903   (gnus-summary-goto-subject gnus-current-article)
8904   (gnus-summary-position-point))
8905
8906 (defun gnus-summary-show-raw-article ()
8907   "Show the raw article without any article massaging functions being run."
8908   (interactive)
8909   (gnus-summary-show-article t))
8910
8911 (defun gnus-summary-verbose-headers (&optional arg)
8912   "Toggle permanent full header display.
8913 If ARG is a positive number, turn header display on.
8914 If ARG is a negative number, turn header display off."
8915   (interactive "P")
8916   (setq gnus-show-all-headers
8917         (cond ((or (not (numberp arg))
8918                    (zerop arg))
8919                (not gnus-show-all-headers))
8920               ((natnump arg)
8921                t)))
8922   (gnus-summary-show-article))
8923
8924 (defun gnus-summary-toggle-header (&optional arg)
8925   "Show the headers if they are hidden, or hide them if they are shown.
8926 If ARG is a positive number, show the entire header.
8927 If ARG is a negative number, hide the unwanted header lines."
8928   (interactive "P")
8929   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8930                      (get-buffer-window gnus-article-buffer t))))
8931     (with-current-buffer gnus-article-buffer
8932       (widen)
8933       (article-narrow-to-head)
8934       (let* ((buffer-read-only nil)
8935              (inhibit-point-motion-hooks t)
8936              (hidden (if (numberp arg)
8937                          (>= arg 0)
8938                        (or (not (looking-at "[^ \t\n]+:"))
8939                            (gnus-article-hidden-text-p 'headers))))
8940              s e)
8941         (delete-region (point-min) (point-max))
8942         (with-current-buffer gnus-original-article-buffer
8943           (goto-char (setq s (point-min)))
8944           (setq e (if (search-forward "\n\n" nil t)
8945                       (1- (point))
8946                     (point-max))))
8947         (insert-buffer-substring gnus-original-article-buffer s e)
8948         ;; In T-gnus, gnus-article-decode-hook doesn't contain
8949         ;; article-decode-encoded-words by default.
8950         (article-decode-encoded-words)
8951         (run-hooks 'gnus-article-decode-hook)
8952         (if hidden
8953             (let ((gnus-treat-hide-headers nil)
8954                   (gnus-treat-hide-boring-headers nil))
8955               (gnus-delete-wash-type 'headers)
8956               (gnus-treat-article 'head))
8957           (gnus-treat-article 'head))
8958         (widen)
8959         (if window
8960             (set-window-start window (goto-char (point-min))))
8961         (if gnus-break-pages
8962             (gnus-narrow-to-page)
8963           (when (gnus-visual-p 'page-marker)
8964             (let ((buffer-read-only nil))
8965               (gnus-remove-text-with-property 'gnus-prev)
8966               (gnus-remove-text-with-property 'gnus-next))))
8967         (gnus-set-mode-line 'article)))))
8968
8969 (defun gnus-summary-show-all-headers ()
8970   "Make all header lines visible."
8971   (interactive)
8972   (gnus-summary-toggle-header 1))
8973
8974 (defun gnus-summary-toggle-mime (&optional arg)
8975   "Toggle MIME processing.
8976 If ARG is a positive number, turn MIME processing on."
8977   (interactive "P")
8978   (setq gnus-show-mime
8979         (if (null arg)
8980             (not gnus-show-mime)
8981           (> (prefix-numeric-value arg) 0)))
8982   (gnus-summary-select-article t 'force))
8983
8984 (defun gnus-summary-caesar-message (&optional arg)
8985   "Caesar rotate the current article by 13.
8986 The numerical prefix specifies how many places to rotate each letter
8987 forward."
8988   (interactive "P")
8989   (gnus-summary-select-article)
8990   (let ((mail-header-separator ""))
8991     (gnus-eval-in-buffer-window gnus-article-buffer
8992       (save-restriction
8993         (widen)
8994         (let ((start (window-start))
8995               buffer-read-only)
8996           (message-caesar-buffer-body arg)
8997           (set-window-start (get-buffer-window (current-buffer)) start))))))
8998
8999 (autoload 'unmorse-region "morse"
9000   "Convert morse coded text in region to ordinary ASCII text."
9001   t)
9002
9003 (defun gnus-summary-morse-message (&optional arg)
9004   "Morse decode the current article."
9005   (interactive "P")
9006   (gnus-summary-select-article)
9007   (let ((mail-header-separator ""))
9008     (gnus-eval-in-buffer-window gnus-article-buffer
9009       (save-excursion
9010         (save-restriction
9011           (widen)
9012           (let ((pos (window-start))
9013                 buffer-read-only)
9014             (goto-char (point-min))
9015             (when (message-goto-body)
9016               (gnus-narrow-to-body))
9017             (goto-char (point-min))
9018             (while (search-forward "·" (point-max) t)
9019               (replace-match "."))
9020             (unmorse-region (point-min) (point-max))
9021             (widen)
9022             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9023
9024 (defun gnus-summary-stop-page-breaking ()
9025   "Stop page breaking in the current article."
9026   (interactive)
9027   (gnus-summary-select-article)
9028   (gnus-eval-in-buffer-window gnus-article-buffer
9029     (widen)
9030     (when (gnus-visual-p 'page-marker)
9031       (let ((buffer-read-only nil))
9032         (gnus-remove-text-with-property 'gnus-prev)
9033         (gnus-remove-text-with-property 'gnus-next))
9034       (setq gnus-page-broken nil))))
9035
9036 (defun gnus-summary-move-article (&optional n to-newsgroup
9037                                             select-method action)
9038   "Move the current article to a different newsgroup.
9039 If N is a positive number, move the N next articles.
9040 If N is a negative number, move the N previous articles.
9041 If N is nil and any articles have been marked with the process mark,
9042 move those articles instead.
9043 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9044 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9045 re-spool using this method.
9046
9047 When called interactively with TO-NEWSGROUP being nil, the value of
9048 the variable `gnus-move-split-methods' is used for finding a default
9049 for the target newsgroup.
9050
9051 For this function to work, both the current newsgroup and the
9052 newsgroup that you want to move to have to support the `request-move'
9053 and `request-accept' functions.
9054
9055 ACTION can be either `move' (the default), `crosspost' or `copy'."
9056   (interactive "P")
9057   (unless action
9058     (setq action 'move))
9059   ;; Check whether the source group supports the required functions.
9060   (cond ((and (eq action 'move)
9061               (not (gnus-check-backend-function
9062                     'request-move-article gnus-newsgroup-name)))
9063          (error "The current group does not support article moving"))
9064         ((and (eq action 'crosspost)
9065               (not (gnus-check-backend-function
9066                     'request-replace-article gnus-newsgroup-name)))
9067          (error "The current group does not support article editing")))
9068   (let ((articles (gnus-summary-work-articles n))
9069         (prefix (if (gnus-check-backend-function
9070                      'request-move-article gnus-newsgroup-name)
9071                     (funcall gnus-move-group-prefix-function
9072                              gnus-newsgroup-name)
9073                   ""))
9074         (names '((move "Move" "Moving")
9075                  (copy "Copy" "Copying")
9076                  (crosspost "Crosspost" "Crossposting")))
9077         (copy-buf (save-excursion
9078                     (nnheader-set-temp-buffer " *copy article*")))
9079         art-group to-method new-xref article to-groups)
9080     (unless (assq action names)
9081       (error "Unknown action %s" action))
9082     ;; Read the newsgroup name.
9083     (when (and (not to-newsgroup)
9084                (not select-method))
9085       (if (and gnus-move-split-methods
9086                (not
9087                 (and (memq gnus-current-article articles)
9088                      (gnus-buffer-live-p gnus-original-article-buffer))))
9089           ;; When `gnus-move-split-methods' is non-nil, we have to
9090           ;; select an article to give `gnus-read-move-group-name' an
9091           ;; opportunity to suggest an appropriate default.  However,
9092           ;; we needn't render or mark the article.
9093           (let ((gnus-display-mime-function nil)
9094                 (gnus-article-prepare-hook nil)
9095                 (gnus-mark-article-hook nil))
9096             (gnus-summary-select-article nil nil nil (car articles))))
9097       (setq to-newsgroup
9098             (gnus-read-move-group-name
9099              (cadr (assq action names))
9100              (symbol-value (intern (format "gnus-current-%s-group" action)))
9101              articles prefix))
9102       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9103     (setq to-method (or select-method
9104                         (gnus-server-to-method
9105                          (gnus-group-method to-newsgroup))))
9106     ;; Check the method we are to move this article to...
9107     (unless (gnus-check-backend-function
9108              'request-accept-article (car to-method))
9109       (error "%s does not support article copying" (car to-method)))
9110     (unless (gnus-check-server to-method)
9111       (error "Can't open server %s" (car to-method)))
9112     (gnus-message 6 "%s to %s: %s..."
9113                   (caddr (assq action names))
9114                   (or (car select-method) to-newsgroup) articles)
9115     (while articles
9116       (setq article (pop articles))
9117       (setq
9118        art-group
9119        (cond
9120         ;; Move the article.
9121         ((eq action 'move)
9122          ;; Remove this article from future suppression.
9123          (gnus-dup-unsuppress-article article)
9124          (gnus-request-move-article
9125           article                       ; Article to move
9126           gnus-newsgroup-name           ; From newsgroup
9127           (nth 1 (gnus-find-method-for-group
9128                   gnus-newsgroup-name)) ; Server
9129           (list 'gnus-request-accept-article
9130                 to-newsgroup (list 'quote select-method)
9131                 (not articles) t)       ; Accept form
9132           (not articles)))              ; Only save nov last time
9133         ;; Copy the article.
9134         ((eq action 'copy)
9135          (save-excursion
9136            (set-buffer copy-buf)
9137            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9138              (gnus-request-accept-article
9139               to-newsgroup select-method (not articles) t))))
9140         ;; Crosspost the article.
9141         ((eq action 'crosspost)
9142          (let ((xref (message-tokenize-header
9143                       (mail-header-xref (gnus-summary-article-header article))
9144                       " ")))
9145            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9146                                   ":" (number-to-string article)))
9147            (unless xref
9148              (setq xref (list (system-name))))
9149            (setq new-xref
9150                  (concat
9151                   (mapconcat 'identity
9152                              (delete "Xref:" (delete new-xref xref))
9153                              " ")
9154                   " " new-xref))
9155            (save-excursion
9156              (set-buffer copy-buf)
9157              ;; First put the article in the destination group.
9158              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9159              (when (consp (setq art-group
9160                                 (gnus-request-accept-article
9161                                  to-newsgroup select-method (not articles))))
9162                (setq new-xref (concat new-xref " " (car art-group)
9163                                       ":"
9164                                       (number-to-string (cdr art-group))))
9165                ;; Now we have the new Xrefs header, so we insert
9166                ;; it and replace the new article.
9167                (nnheader-replace-header "Xref" new-xref)
9168                (gnus-request-replace-article
9169                 (cdr art-group) to-newsgroup (current-buffer))
9170                art-group))))))
9171       (cond
9172        ((not art-group)
9173         (gnus-message 1 "Couldn't %s article %s: %s"
9174                       (cadr (assq action names)) article
9175                       (nnheader-get-report (car to-method))))
9176        ((eq art-group 'junk)
9177         (when (eq action 'move)
9178           (gnus-summary-mark-article article gnus-canceled-mark)
9179           (gnus-message 4 "Deleted article %s" article)
9180           ;; run the delete hook
9181           (run-hook-with-args 'gnus-summary-article-delete-hook
9182                               action
9183                               (gnus-data-header
9184                                (assoc article (gnus-data-list nil)))
9185                               gnus-newsgroup-name nil
9186                               select-method)))
9187        (t
9188         (let* ((pto-group (gnus-group-prefixed-name
9189                            (car art-group) to-method))
9190                (info (gnus-get-info pto-group))
9191                (to-group (gnus-info-group info))
9192                to-marks)
9193           ;; Update the group that has been moved to.
9194           (when (and info
9195                      (memq action '(move copy)))
9196             (unless (member to-group to-groups)
9197               (push to-group to-groups))
9198
9199             (unless (memq article gnus-newsgroup-unreads)
9200               (push 'read to-marks)
9201               (gnus-info-set-read
9202                info (gnus-add-to-range (gnus-info-read info)
9203                                        (list (cdr art-group)))))
9204
9205             ;; See whether the article is to be put in the cache.
9206             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9207                              gnus-article-mark-lists
9208                            (delete '(expirable . expire)
9209                                    (copy-sequence gnus-article-mark-lists))))
9210                   (to-article (cdr art-group)))
9211
9212               ;; Enter the article into the cache in the new group,
9213               ;; if that is required.
9214               (when gnus-use-cache
9215                 (gnus-cache-possibly-enter-article
9216                  to-group to-article
9217                  (let ((header (copy-sequence
9218                                 (gnus-summary-article-header article))))
9219                    (mail-header-set-number header to-article)
9220                    header)
9221                  (memq article gnus-newsgroup-marked)
9222                  (memq article gnus-newsgroup-dormant)
9223                  (memq article gnus-newsgroup-unreads)))
9224
9225               (when gnus-preserve-marks
9226                 ;; Copy any marks over to the new group.
9227                 (when (and (equal to-group gnus-newsgroup-name)
9228                            (not (memq article gnus-newsgroup-unreads)))
9229                   ;; Mark this article as read in this group.
9230                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9231                   (setcdr (gnus-active to-group) to-article)
9232                   (setcdr gnus-newsgroup-active to-article))
9233
9234                 (while marks
9235                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9236                     (when (memq article (symbol-value
9237                                          (intern (format "gnus-newsgroup-%s"
9238                                                          (caar marks)))))
9239                       (push (cdar marks) to-marks)
9240                       ;; If the other group is the same as this group,
9241                       ;; then we have to add the mark to the list.
9242                       (when (equal to-group gnus-newsgroup-name)
9243                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9244                              (cons to-article
9245                                    (symbol-value
9246                                     (intern (format "gnus-newsgroup-%s"
9247                                                     (caar marks)))))))
9248                       ;; Copy the marks to other group.
9249                       (gnus-add-marked-articles
9250                        to-group (cdar marks) (list to-article) info)))
9251                   (setq marks (cdr marks)))
9252
9253                 (gnus-request-set-mark
9254                  to-group (list (list (list to-article) 'add to-marks))))
9255
9256               (gnus-dribble-enter
9257                (concat "(gnus-group-set-info '"
9258                        (gnus-prin1-to-string (gnus-get-info to-group))
9259                        ")"))))
9260
9261           ;; Update the Xref header in this article to point to
9262           ;; the new crossposted article we have just created.
9263           (when (eq action 'crosspost)
9264             (save-excursion
9265               (set-buffer copy-buf)
9266               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9267               (nnheader-replace-header "Xref" new-xref)
9268               (gnus-request-replace-article
9269                article gnus-newsgroup-name (current-buffer))))
9270
9271           ;; run the move/copy/crosspost/respool hook
9272           (run-hook-with-args 'gnus-summary-article-move-hook
9273                               action
9274                               (gnus-data-header
9275                                (assoc article (gnus-data-list nil)))
9276                               gnus-newsgroup-name
9277                               to-newsgroup
9278                               select-method))
9279
9280         ;;;!!!Why is this necessary?
9281         (set-buffer gnus-summary-buffer)
9282         
9283         (gnus-summary-goto-subject article)
9284         (when (eq action 'move)
9285           (gnus-summary-mark-article article gnus-canceled-mark))))
9286       (gnus-summary-remove-process-mark article))
9287     ;; Re-activate all groups that have been moved to.
9288     (save-excursion
9289       (set-buffer gnus-group-buffer)
9290       (let ((gnus-group-marked to-groups))
9291         (gnus-group-get-new-news-this-group nil t)))
9292
9293     (gnus-kill-buffer copy-buf)
9294     (gnus-summary-position-point)
9295     (gnus-set-mode-line 'summary)))
9296
9297 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9298   "Copy the current article to some other group.
9299 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9300 When called interactively, if TO-NEWSGROUP is nil, use the value of
9301 the variable `gnus-move-split-methods' for finding a default target
9302 newsgroup.
9303 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9304 re-spool using this method."
9305   (interactive "P")
9306   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9307
9308 (defun gnus-summary-crosspost-article (&optional n)
9309   "Crosspost the current article to some other group."
9310   (interactive "P")
9311   (gnus-summary-move-article n nil nil 'crosspost))
9312
9313 (defcustom gnus-summary-respool-default-method nil
9314   "Default method type for respooling an article.
9315 If nil, use to the current newsgroup method."
9316   :type 'symbol
9317   :group 'gnus-summary-mail)
9318
9319 (defcustom gnus-summary-display-while-building nil
9320   "If non-nil, show and update the summary buffer as it's being built.
9321 If the value is t, update the buffer after every line is inserted.  If
9322 the value is an integer (N), update the display every N lines."
9323   :group 'gnus-thread
9324   :type '(choice (const :tag "off" nil)
9325                  number
9326                  (const :tag "frequently" t)))
9327
9328 (defun gnus-summary-respool-article (&optional n method)
9329   "Respool the current article.
9330 The article will be squeezed through the mail spooling process again,
9331 which means that it will be put in some mail newsgroup or other
9332 depending on `nnmail-split-methods'.
9333 If N is a positive number, respool the N next articles.
9334 If N is a negative number, respool the N previous articles.
9335 If N is nil and any articles have been marked with the process mark,
9336 respool those articles instead.
9337
9338 Respooling can be done both from mail groups and \"real\" newsgroups.
9339 In the former case, the articles in question will be moved from the
9340 current group into whatever groups they are destined to.  In the
9341 latter case, they will be copied into the relevant groups."
9342   (interactive
9343    (list current-prefix-arg
9344          (let* ((methods (gnus-methods-using 'respool))
9345                 (methname
9346                  (symbol-name (or gnus-summary-respool-default-method
9347                                   (car (gnus-find-method-for-group
9348                                         gnus-newsgroup-name)))))
9349                 (method
9350                  (gnus-completing-read-with-default
9351                   methname "What backend do you want to use when respooling?"
9352                   methods nil t nil 'gnus-mail-method-history))
9353                 ms)
9354            (cond
9355             ((zerop (length (setq ms (gnus-servers-using-backend
9356                                       (intern method)))))
9357              (list (intern method) ""))
9358             ((= 1 (length ms))
9359              (car ms))
9360             (t
9361              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9362                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9363                            ms-alist))))))))
9364   (unless method
9365     (error "No method given for respooling"))
9366   (if (assoc (symbol-name
9367               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9368              (gnus-methods-using 'respool))
9369       (gnus-summary-move-article n nil method)
9370     (gnus-summary-copy-article n nil method)))
9371
9372 (defun gnus-summary-import-article (file &optional edit)
9373   "Import an arbitrary file into a mail newsgroup."
9374   (interactive "fImport file: \nP")
9375   (let ((group gnus-newsgroup-name)
9376         (now (current-time))
9377         atts lines group-art)
9378     (unless (gnus-check-backend-function 'request-accept-article group)
9379       (error "%s does not support article importing" group))
9380     (or (file-readable-p file)
9381         (not (file-regular-p file))
9382         (error "Can't read %s" file))
9383     (save-excursion
9384       (set-buffer (gnus-get-buffer-create " *import file*"))
9385       (erase-buffer)
9386       (nnheader-insert-file-contents file)
9387       (goto-char (point-min))
9388       (if (nnheader-article-p)
9389           (save-restriction
9390             (goto-char (point-min))
9391             (search-forward "\n\n" nil t)
9392             (narrow-to-region (point-min) (1- (point)))
9393             (goto-char (point-min))
9394             (unless (re-search-forward "^date:" nil t)
9395               (goto-char (point-max))
9396               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9397         ;; This doesn't look like an article, so we fudge some headers.
9398         (setq atts (file-attributes file)
9399               lines (count-lines (point-min) (point-max)))
9400         (insert "From: " (read-string "From: ") "\n"
9401                 "Subject: " (read-string "Subject: ") "\n"
9402                 "Date: " (message-make-date (nth 5 atts)) "\n"
9403                 "Message-ID: " (message-make-message-id) "\n"
9404                 "Lines: " (int-to-string lines) "\n"
9405                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9406       (setq group-art (gnus-request-accept-article group nil t))
9407       (kill-buffer (current-buffer)))
9408     (setq gnus-newsgroup-active (gnus-activate-group group))
9409     (forward-line 1)
9410     (gnus-summary-goto-article (cdr group-art) nil t)
9411     (when edit
9412       (gnus-summary-edit-article))))
9413
9414 (defun gnus-summary-create-article ()
9415   "Create an article in a mail newsgroup."
9416   (interactive)
9417   (let ((group gnus-newsgroup-name)
9418         (now (current-time))
9419         group-art)
9420     (unless (gnus-check-backend-function 'request-accept-article group)
9421       (error "%s does not support article importing" group))
9422     (save-excursion
9423       (set-buffer (gnus-get-buffer-create " *import file*"))
9424       (erase-buffer)
9425       (goto-char (point-min))
9426       ;; This doesn't look like an article, so we fudge some headers.
9427       (insert "From: " (read-string "From: ") "\n"
9428               "Subject: " (read-string "Subject: ") "\n"
9429               "Date: " (message-make-date now) "\n"
9430               "Message-ID: " (message-make-message-id) "\n")
9431       (setq group-art (gnus-request-accept-article group nil t))
9432       (kill-buffer (current-buffer)))
9433     (setq gnus-newsgroup-active (gnus-activate-group group))
9434     (forward-line 1)
9435     (gnus-summary-goto-article (cdr group-art) nil t)
9436     (gnus-summary-edit-article)))
9437
9438 (defun gnus-summary-article-posted-p ()
9439   "Say whether the current (mail) article is available from news as well.
9440 This will be the case if the article has both been mailed and posted."
9441   (interactive)
9442   (let ((id (mail-header-references (gnus-summary-article-header)))
9443         (gnus-override-method (car (gnus-refer-article-methods))))
9444     (if (gnus-request-head id "")
9445         (gnus-message 2 "The current message was found on %s"
9446                       gnus-override-method)
9447       (gnus-message 2 "The current message couldn't be found on %s"
9448                     gnus-override-method)
9449       nil)))
9450
9451 (defun gnus-summary-expire-articles (&optional now)
9452   "Expire all articles that are marked as expirable in the current group."
9453   (interactive)
9454   (when (and (not gnus-group-is-exiting-without-update-p)
9455              (gnus-check-backend-function
9456               'request-expire-articles gnus-newsgroup-name))
9457     ;; This backend supports expiry.
9458     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9459            (expirable (if total
9460                           (progn
9461                             ;; We need to update the info for
9462                             ;; this group for `gnus-list-of-read-articles'
9463                             ;; to give us the right answer.
9464                             (gnus-run-hooks 'gnus-exit-group-hook)
9465                             (gnus-summary-update-info)
9466                             (gnus-list-of-read-articles gnus-newsgroup-name))
9467                         (setq gnus-newsgroup-expirable
9468                               (sort gnus-newsgroup-expirable '<))))
9469            (expiry-wait (if now 'immediate
9470                           (gnus-group-find-parameter
9471                            gnus-newsgroup-name 'expiry-wait)))
9472            (nnmail-expiry-target
9473             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9474                 nnmail-expiry-target))
9475            es)
9476       (when expirable
9477         ;; There are expirable articles in this group, so we run them
9478         ;; through the expiry process.
9479         (gnus-message 6 "Expiring articles...")
9480         (unless (gnus-check-group gnus-newsgroup-name)
9481           (error "Can't open server for %s" gnus-newsgroup-name))
9482         ;; The list of articles that weren't expired is returned.
9483         (save-excursion
9484           (if expiry-wait
9485               (let ((nnmail-expiry-wait-function nil)
9486                     (nnmail-expiry-wait expiry-wait))
9487                 (setq es (gnus-request-expire-articles
9488                           expirable gnus-newsgroup-name)))
9489             (setq es (gnus-request-expire-articles
9490                       expirable gnus-newsgroup-name)))
9491           (unless total
9492             (setq gnus-newsgroup-expirable es))
9493           ;; We go through the old list of expirable, and mark all
9494           ;; really expired articles as nonexistent.
9495           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9496             (let ((gnus-use-cache nil))
9497               (dolist (article expirable)
9498                 (when (and (not (memq article es))
9499                            (gnus-data-find article))
9500                   (gnus-summary-mark-article article gnus-canceled-mark)
9501                   (run-hook-with-args 'gnus-summary-article-expire-hook
9502                                       'delete
9503                                       (gnus-data-header
9504                                        (assoc article (gnus-data-list nil)))
9505                                       gnus-newsgroup-name
9506                                       nil
9507                                       nil))))))
9508         (gnus-message 6 "Expiring articles...done")))))
9509
9510 (defun gnus-summary-expire-articles-now ()
9511   "Expunge all expirable articles in the current group.
9512 This means that *all* articles that are marked as expirable will be
9513 deleted forever, right now."
9514   (interactive)
9515   (or gnus-expert-user
9516       (gnus-yes-or-no-p
9517        "Are you really, really, really sure you want to delete all these messages? ")
9518       (error "Phew!"))
9519   (gnus-summary-expire-articles t))
9520
9521 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9522 (defun gnus-summary-delete-article (&optional n)
9523   "Delete the N next (mail) articles.
9524 This command actually deletes articles.  This is not a marking
9525 command.  The article will disappear forever from your life, never to
9526 return.
9527
9528 If N is negative, delete backwards.
9529 If N is nil and articles have been marked with the process mark,
9530 delete these instead.
9531
9532 If `gnus-novice-user' is non-nil you will be asked for
9533 confirmation before the articles are deleted."
9534   (interactive "P")
9535   (unless (gnus-check-backend-function 'request-expire-articles
9536                                        gnus-newsgroup-name)
9537     (error "The current newsgroup does not support article deletion"))
9538   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9539     (error "Couldn't open server"))
9540   ;; Compute the list of articles to delete.
9541   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9542         (nnmail-expiry-target 'delete)
9543         not-deleted)
9544     (if (and gnus-novice-user
9545              (not (gnus-yes-or-no-p
9546                    (format "Do you really want to delete %s forever? "
9547                            (if (> (length articles) 1)
9548                                (format "these %s articles" (length articles))
9549                              "this article")))))
9550         ()
9551       ;; Delete the articles.
9552       (setq not-deleted (gnus-request-expire-articles
9553                          articles gnus-newsgroup-name 'force))
9554       (while articles
9555         (gnus-summary-remove-process-mark (car articles))
9556         ;; The backend might not have been able to delete the article
9557         ;; after all.
9558         (unless (memq (car articles) not-deleted)
9559           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9560         (let* ((article (car articles))
9561                (ghead  (gnus-data-header
9562                                     (assoc article (gnus-data-list nil)))))
9563           (run-hook-with-args 'gnus-summary-article-delete-hook
9564                               'delete ghead gnus-newsgroup-name nil
9565                               nil))
9566         (setq articles (cdr articles)))
9567       (when not-deleted
9568         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9569     (gnus-summary-position-point)
9570     (gnus-set-mode-line 'summary)
9571     not-deleted))
9572
9573 (defun gnus-summary-edit-article (&optional force)
9574   "Edit the current article.
9575 This will have permanent effect only in mail groups.
9576 If FORCE is non-nil, allow editing of articles even in read-only
9577 groups."
9578   (interactive "P")
9579   (save-excursion
9580     (set-buffer gnus-summary-buffer)
9581     (let ((mail-parse-charset gnus-newsgroup-charset)
9582           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9583       (gnus-set-global-variables)
9584       (when (and (not force)
9585                  (gnus-group-read-only-p))
9586         (error "The current newsgroup does not support article editing"))
9587       (gnus-summary-show-article t)
9588       (gnus-article-edit-article
9589        'ignore
9590        `(lambda (no-highlight)
9591           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9592                 (message-options message-options)
9593                 (message-options-set-recipient)
9594                 (mail-parse-ignored-charsets
9595                  ',gnus-newsgroup-ignored-charsets))
9596             (gnus-summary-edit-article-done
9597              ,(or (mail-header-references gnus-current-headers) "")
9598              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9599
9600 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9601
9602 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9603                                                  no-highlight)
9604   "Make edits to the current article permanent."
9605   (interactive)
9606   (save-excursion
9607     ;; The buffer restriction contains the entire article if it exists.
9608     (when (article-goto-body)
9609       (let ((lines (count-lines (point) (point-max)))
9610             (length (- (point-max) (point)))
9611             (case-fold-search t)
9612             (body (copy-marker (point))))
9613         (goto-char (point-min))
9614         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9615           (delete-region (match-beginning 1) (match-end 1))
9616           (insert (number-to-string length)))
9617         (goto-char (point-min))
9618         (when (re-search-forward
9619                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9620           (delete-region (match-beginning 1) (match-end 1))
9621           (insert (number-to-string length)))
9622         (goto-char (point-min))
9623         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9624           (delete-region (match-beginning 1) (match-end 1))
9625           (insert (number-to-string lines))))))
9626   ;; Replace the article.
9627   (let ((buf (current-buffer)))
9628     (with-temp-buffer
9629       (insert-buffer-substring buf)
9630
9631       (if (and (not read-only)
9632                (not (gnus-request-replace-article
9633                      (cdr gnus-article-current) (car gnus-article-current)
9634                      (current-buffer) t)))
9635           (error "Couldn't replace article")
9636         ;; Update the summary buffer.
9637         (if (and references
9638                  (equal (message-tokenize-header references " ")
9639                         (message-tokenize-header
9640                          (or (message-fetch-field "references") "") " ")))
9641             ;; We only have to update this line.
9642             (save-excursion
9643               (save-restriction
9644                 (message-narrow-to-head)
9645                 (let ((head (buffer-string))
9646                       header)
9647                   (with-temp-buffer
9648                     (insert (format "211 %d Article retrieved.\n"
9649                                     (cdr gnus-article-current)))
9650                     (insert head)
9651                     (insert ".\n")
9652                     (let ((nntp-server-buffer (current-buffer)))
9653                       (setq header (car (gnus-get-newsgroup-headers
9654                                          nil t))))
9655                     (save-excursion
9656                       (set-buffer gnus-summary-buffer)
9657                       (gnus-data-set-header
9658                        (gnus-data-find (cdr gnus-article-current))
9659                        header)
9660                       (gnus-summary-update-article-line
9661                        (cdr gnus-article-current) header)
9662                       (if (gnus-summary-goto-subject
9663                            (cdr gnus-article-current) nil t)
9664                           (gnus-summary-update-secondary-mark
9665                            (cdr gnus-article-current))))))))
9666           ;; Update threads.
9667           (set-buffer (or buffer gnus-summary-buffer))
9668           (gnus-summary-update-article (cdr gnus-article-current))
9669           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9670               (gnus-summary-update-secondary-mark
9671                (cdr gnus-article-current))))
9672         ;; Prettify the article buffer again.
9673         (unless no-highlight
9674           (save-excursion
9675             (set-buffer gnus-article-buffer)
9676             ;;;!!! Fix this -- article should be rehighlighted.
9677             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9678             (set-buffer gnus-original-article-buffer)
9679             (gnus-request-article
9680              (cdr gnus-article-current)
9681              (car gnus-article-current) (current-buffer))))
9682         ;; Prettify the summary buffer line.
9683         (when (gnus-visual-p 'summary-highlight 'highlight)
9684           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9685
9686 (defun gnus-summary-edit-wash (key)
9687   "Perform editing command KEY in the article buffer."
9688   (interactive
9689    (list
9690     (progn
9691       (message "%s" (concat (this-command-keys) "- "))
9692       (read-char))))
9693   (message "")
9694   (gnus-summary-edit-article)
9695   (execute-kbd-macro (concat (this-command-keys) key))
9696   (gnus-article-edit-done))
9697
9698 ;;; Respooling
9699
9700 (defun gnus-summary-respool-query (&optional silent trace)
9701   "Query where the respool algorithm would put this article."
9702   (interactive)
9703   (let (gnus-mark-article-hook)
9704     (gnus-summary-select-article)
9705     (save-excursion
9706       (set-buffer gnus-original-article-buffer)
9707       (let ((groups (nnmail-article-group 'identity trace)))
9708         (unless silent
9709           (if groups
9710               (message "This message would go to %s"
9711                        (mapconcat 'car groups ", "))
9712             (message "This message would go to no groups"))
9713           groups)))))
9714
9715 (defun gnus-summary-respool-trace ()
9716   "Trace where the respool algorithm would put this article.
9717 Display a buffer showing all fancy splitting patterns which matched."
9718   (interactive)
9719   (gnus-summary-respool-query nil t))
9720
9721 ;; Summary marking commands.
9722
9723 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9724   "Mark articles which has the same subject as read, and then select the next.
9725 If UNMARK is positive, remove any kind of mark.
9726 If UNMARK is negative, tick articles."
9727   (interactive "P")
9728   (when unmark
9729     (setq unmark (prefix-numeric-value unmark)))
9730   (let ((count
9731          (gnus-summary-mark-same-subject
9732           (gnus-summary-article-subject) unmark)))
9733     ;; Select next unread article.  If auto-select-same mode, should
9734     ;; select the first unread article.
9735     (gnus-summary-next-article t (and gnus-auto-select-same
9736                                       (gnus-summary-article-subject)))
9737     (gnus-message 7 "%d article%s marked as %s"
9738                   count (if (= count 1) " is" "s are")
9739                   (if unmark "unread" "read"))))
9740
9741 (defun gnus-summary-kill-same-subject (&optional unmark)
9742   "Mark articles which has the same subject as read.
9743 If UNMARK is positive, remove any kind of mark.
9744 If UNMARK is negative, tick articles."
9745   (interactive "P")
9746   (when unmark
9747     (setq unmark (prefix-numeric-value unmark)))
9748   (let ((count
9749          (gnus-summary-mark-same-subject
9750           (gnus-summary-article-subject) unmark)))
9751     ;; If marked as read, go to next unread subject.
9752     (when (null unmark)
9753       ;; Go to next unread subject.
9754       (gnus-summary-next-subject 1 t))
9755     (gnus-message 7 "%d articles are marked as %s"
9756                   count (if unmark "unread" "read"))))
9757
9758 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9759   "Mark articles with same SUBJECT as read, and return marked number.
9760 If optional argument UNMARK is positive, remove any kinds of marks.
9761 If optional argument UNMARK is negative, mark articles as unread instead."
9762   (let ((count 1))
9763     (save-excursion
9764       (cond
9765        ((null unmark)                   ; Mark as read.
9766         (while (and
9767                 (progn
9768                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9769                   (gnus-summary-show-thread) t)
9770                 (gnus-summary-find-subject subject))
9771           (setq count (1+ count))))
9772        ((> unmark 0)                    ; Tick.
9773         (while (and
9774                 (progn
9775                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9776                   (gnus-summary-show-thread) t)
9777                 (gnus-summary-find-subject subject))
9778           (setq count (1+ count))))
9779        (t                               ; Mark as unread.
9780         (while (and
9781                 (progn
9782                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9783                   (gnus-summary-show-thread) t)
9784                 (gnus-summary-find-subject subject))
9785           (setq count (1+ count)))))
9786       (gnus-set-mode-line 'summary)
9787       ;; Return the number of marked articles.
9788       count)))
9789
9790 (defun gnus-summary-mark-as-processable (n &optional unmark)
9791   "Set the process mark on the next N articles.
9792 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9793 the process mark instead.  The difference between N and the actual
9794 number of articles marked is returned."
9795   (interactive "P")
9796   (if (and (null n) (gnus-region-active-p))
9797       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9798     (setq n (prefix-numeric-value n))
9799     (let ((backward (< n 0))
9800           (n (abs n)))
9801       (while (and
9802               (> n 0)
9803               (if unmark
9804                   (gnus-summary-remove-process-mark
9805                    (gnus-summary-article-number))
9806                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9807               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9808         (setq n (1- n)))
9809       (when (/= 0 n)
9810         (gnus-message 7 "No more articles"))
9811       (gnus-summary-recenter)
9812       (gnus-summary-position-point)
9813       n)))
9814
9815 (defun gnus-summary-unmark-as-processable (n)
9816   "Remove the process mark from the next N articles.
9817 If N is negative, unmark backward instead.  The difference between N and
9818 the actual number of articles unmarked is returned."
9819   (interactive "P")
9820   (gnus-summary-mark-as-processable n t))
9821
9822 (defun gnus-summary-unmark-all-processable ()
9823   "Remove the process mark from all articles."
9824   (interactive)
9825   (save-excursion
9826     (while gnus-newsgroup-processable
9827       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9828   (gnus-summary-position-point))
9829
9830 (defun gnus-summary-add-mark (article type)
9831   "Mark ARTICLE with a mark of TYPE."
9832   (let ((vtype (car (assq type gnus-article-mark-lists)))
9833         var)
9834     (if (not vtype)
9835         (error "No such mark type: %s" type)
9836       (setq var (intern (format "gnus-newsgroup-%s" type)))
9837       (set var (cons article (symbol-value var)))
9838       (if (memq type '(processable cached replied forwarded recent saved))
9839           (gnus-summary-update-secondary-mark article)
9840         ;;; !!! This is bogus.  We should find out what primary
9841         ;;; !!! mark we want to set.
9842         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9843
9844 (defun gnus-summary-mark-as-expirable (n)
9845   "Mark N articles forward as expirable.
9846 If N is negative, mark backward instead.  The difference between N and
9847 the actual number of articles marked is returned."
9848   (interactive "p")
9849   (gnus-summary-mark-forward n gnus-expirable-mark))
9850
9851 (defun gnus-summary-mark-as-spam (n)
9852   "Mark N articles forward as spam.
9853 If N is negative, mark backward instead.  The difference between N and
9854 the actual number of articles marked is returned."
9855   (interactive "p")
9856   (gnus-summary-mark-forward n gnus-spam-mark))
9857
9858 (defun gnus-summary-mark-article-as-replied (article)
9859   "Mark ARTICLE as replied to and update the summary line.
9860 ARTICLE can also be a list of articles."
9861   (interactive (list (gnus-summary-article-number)))
9862   (let ((articles (if (listp article) article (list article))))
9863     (dolist (article articles)
9864       (unless (numberp article)
9865         (error "%s is not a number" article))
9866       (push article gnus-newsgroup-replied)
9867       (let ((buffer-read-only nil))
9868         (when (gnus-summary-goto-subject article nil t)
9869           (gnus-summary-update-secondary-mark article))))))
9870
9871 (defun gnus-summary-mark-article-as-forwarded (article)
9872   "Mark ARTICLE as forwarded and update the summary line.
9873 ARTICLE can also be a list of articles."
9874   (let ((articles (if (listp article) article (list article))))
9875     (dolist (article articles)
9876       (push article gnus-newsgroup-forwarded)
9877       (let ((buffer-read-only nil))
9878         (when (gnus-summary-goto-subject article nil t)
9879           (gnus-summary-update-secondary-mark article))))))
9880
9881 (defun gnus-summary-set-bookmark (article)
9882   "Set a bookmark in current article."
9883   (interactive (list (gnus-summary-article-number)))
9884   (when (or (not (get-buffer gnus-article-buffer))
9885             (not gnus-current-article)
9886             (not gnus-article-current)
9887             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9888     (error "No current article selected"))
9889   ;; Remove old bookmark, if one exists.
9890   (gnus-pull article gnus-newsgroup-bookmarks)
9891   ;; Set the new bookmark, which is on the form
9892   ;; (article-number . line-number-in-body).
9893   (push
9894    (cons article
9895          (with-current-buffer gnus-article-buffer
9896            (count-lines
9897             (min (point)
9898                  (save-excursion
9899                    (article-goto-body)
9900                    (point)))
9901             (point))))
9902    gnus-newsgroup-bookmarks)
9903   (gnus-message 6 "A bookmark has been added to the current article."))
9904
9905 (defun gnus-summary-remove-bookmark (article)
9906   "Remove the bookmark from the current article."
9907   (interactive (list (gnus-summary-article-number)))
9908   ;; Remove old bookmark, if one exists.
9909   (if (not (assq article gnus-newsgroup-bookmarks))
9910       (gnus-message 6 "No bookmark in current article.")
9911     (gnus-pull article gnus-newsgroup-bookmarks)
9912     (gnus-message 6 "Removed bookmark.")))
9913
9914 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9915 (defun gnus-summary-mark-as-dormant (n)
9916   "Mark N articles forward as dormant.
9917 If N is negative, mark backward instead.  The difference between N and
9918 the actual number of articles marked is returned."
9919   (interactive "p")
9920   (gnus-summary-mark-forward n gnus-dormant-mark))
9921
9922 (defun gnus-summary-set-process-mark (article)
9923   "Set the process mark on ARTICLE and update the summary line."
9924   (setq gnus-newsgroup-processable
9925         (cons article
9926               (delq article gnus-newsgroup-processable)))
9927   (when (gnus-summary-goto-subject article)
9928     (gnus-summary-show-thread)
9929     (gnus-summary-goto-subject article)
9930     (gnus-summary-update-secondary-mark article)))
9931
9932 (defun gnus-summary-remove-process-mark (article)
9933   "Remove the process mark from ARTICLE and update the summary line."
9934   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9935   (when (gnus-summary-goto-subject article)
9936     (gnus-summary-show-thread)
9937     (gnus-summary-goto-subject article)
9938     (gnus-summary-update-secondary-mark article)))
9939
9940 (defun gnus-summary-set-saved-mark (article)
9941   "Set the process mark on ARTICLE and update the summary line."
9942   (push article gnus-newsgroup-saved)
9943   (when (gnus-summary-goto-subject article)
9944     (gnus-summary-update-secondary-mark article)))
9945
9946 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9947   "Mark N articles as read forwards.
9948 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9949 The difference between N and the actual number of articles marked is
9950 returned.
9951 If NO-EXPIRE, auto-expiry will be inhibited."
9952   (interactive "p")
9953   (gnus-summary-show-thread)
9954   (let ((backward (< n 0))
9955         (gnus-summary-goto-unread
9956          (and gnus-summary-goto-unread
9957               (not (eq gnus-summary-goto-unread 'never))
9958               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9959                                     gnus-ticked-mark gnus-dormant-mark)))))
9960         (n (abs n))
9961         (mark (or mark gnus-del-mark)))
9962     (while (and (> n 0)
9963                 (gnus-summary-mark-article nil mark no-expire)
9964                 (zerop (gnus-summary-next-subject
9965                         (if backward -1 1)
9966                         (and gnus-summary-goto-unread
9967                              (not (eq gnus-summary-goto-unread 'never)))
9968                         t)))
9969       (setq n (1- n)))
9970     (when (/= 0 n)
9971       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9972     (gnus-summary-recenter)
9973     (gnus-summary-position-point)
9974     (gnus-set-mode-line 'summary)
9975     n))
9976
9977 (defun gnus-summary-mark-article-as-read (mark)
9978   "Mark the current article quickly as read with MARK."
9979   (let ((article (gnus-summary-article-number)))
9980     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9981     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9982     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9983     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9984     (push (cons article mark) gnus-newsgroup-reads)
9985     ;; Possibly remove from cache, if that is used.
9986     (when gnus-use-cache
9987       (gnus-cache-enter-remove-article article))
9988     ;; Allow the backend to change the mark.
9989     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9990     ;; Check for auto-expiry.
9991     (when (and gnus-newsgroup-auto-expire
9992                (memq mark gnus-auto-expirable-marks))
9993       (setq mark gnus-expirable-mark)
9994       ;; Let the backend know about the mark change.
9995       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9996       (push article gnus-newsgroup-expirable))
9997     ;; Set the mark in the buffer.
9998     (gnus-summary-update-mark mark 'unread)
9999     t))
10000
10001 (defun gnus-summary-mark-article-as-unread (mark)
10002   "Mark the current article quickly as unread with MARK."
10003   (let* ((article (gnus-summary-article-number))
10004          (old-mark (gnus-summary-article-mark article)))
10005     ;; Allow the backend to change the mark.
10006     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10007     (if (eq mark old-mark)
10008         t
10009       (if (<= article 0)
10010           (progn
10011             (gnus-error 1 "Can't mark negative article numbers")
10012             nil)
10013         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10014         (setq gnus-newsgroup-spam-marked
10015               (delq article gnus-newsgroup-spam-marked))
10016         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10017         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10018         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10019         (cond ((= mark gnus-ticked-mark)
10020                (setq gnus-newsgroup-marked
10021                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10022                                               article)))
10023               ((= mark gnus-spam-mark)
10024                (setq gnus-newsgroup-spam-marked
10025                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10026                                               article)))
10027               ((= mark gnus-dormant-mark)
10028                (setq gnus-newsgroup-dormant
10029                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10030                                               article)))
10031               (t
10032                (setq gnus-newsgroup-unreads
10033                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10034                                               article))))
10035         (gnus-pull article gnus-newsgroup-reads)
10036
10037         ;; See whether the article is to be put in the cache.
10038         (and gnus-use-cache
10039              (vectorp (gnus-summary-article-header article))
10040              (save-excursion
10041                (gnus-cache-possibly-enter-article
10042                 gnus-newsgroup-name article
10043                 (gnus-summary-article-header article)
10044                 (= mark gnus-ticked-mark)
10045                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10046
10047         ;; Fix the mark.
10048         (gnus-summary-update-mark mark 'unread)
10049         t))))
10050
10051 (defun gnus-summary-mark-article (&optional article mark no-expire)
10052   "Mark ARTICLE with MARK.  MARK can be any character.
10053 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10054 `??' (dormant) and `?E' (expirable).
10055 If MARK is nil, then the default character `?r' is used.
10056 If ARTICLE is nil, then the article on the current line will be
10057 marked.
10058 If NO-EXPIRE, auto-expiry will be inhibited."
10059   ;; The mark might be a string.
10060   (when (stringp mark)
10061     (setq mark (aref mark 0)))
10062   ;; If no mark is given, then we check auto-expiring.
10063   (when (null mark)
10064     (setq mark gnus-del-mark))
10065   (when (and (not no-expire)
10066              gnus-newsgroup-auto-expire
10067              (memq mark gnus-auto-expirable-marks))
10068     (setq mark gnus-expirable-mark))
10069   (let ((article (or article (gnus-summary-article-number)))
10070         (old-mark (gnus-summary-article-mark article)))
10071     ;; Allow the backend to change the mark.
10072     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10073     (if (eq mark old-mark)
10074         t
10075       (unless article
10076         (error "No article on current line"))
10077       (if (not (if (or (= mark gnus-unread-mark)
10078                        (= mark gnus-ticked-mark)
10079                        (= mark gnus-spam-mark)
10080                        (= mark gnus-dormant-mark))
10081                    (gnus-mark-article-as-unread article mark)
10082                  (gnus-mark-article-as-read article mark)))
10083           t
10084         ;; See whether the article is to be put in the cache.
10085         (and gnus-use-cache
10086              (not (= mark gnus-canceled-mark))
10087              (vectorp (gnus-summary-article-header article))
10088              (save-excursion
10089                (gnus-cache-possibly-enter-article
10090                 gnus-newsgroup-name article
10091                 (gnus-summary-article-header article)
10092                 (= mark gnus-ticked-mark)
10093                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10094
10095         (when (gnus-summary-goto-subject article nil t)
10096           (let ((buffer-read-only nil))
10097             (gnus-summary-show-thread)
10098             ;; Fix the mark.
10099             (gnus-summary-update-mark mark 'unread)
10100             t))))))
10101
10102 (defun gnus-summary-update-secondary-mark (article)
10103   "Update the secondary (read, process, cache) mark."
10104   (gnus-summary-update-mark
10105    (cond ((memq article gnus-newsgroup-processable)
10106           gnus-process-mark)
10107          ((memq article gnus-newsgroup-cached)
10108           gnus-cached-mark)
10109          ((memq article gnus-newsgroup-replied)
10110           gnus-replied-mark)
10111          ((memq article gnus-newsgroup-forwarded)
10112           gnus-forwarded-mark)
10113          ((memq article gnus-newsgroup-saved)
10114           gnus-saved-mark)
10115          ((memq article gnus-newsgroup-recent)
10116           gnus-recent-mark)
10117          ((memq article gnus-newsgroup-unseen)
10118           gnus-unseen-mark)
10119          (t gnus-no-mark))
10120    'replied)
10121   (when (gnus-visual-p 'summary-highlight 'highlight)
10122     (gnus-run-hooks 'gnus-summary-update-hook))
10123   t)
10124
10125 (defun gnus-summary-update-download-mark (article)
10126   "Update the download mark."
10127   (gnus-summary-update-mark
10128    (cond ((memq article gnus-newsgroup-undownloaded)
10129           gnus-undownloaded-mark)
10130          (gnus-newsgroup-agentized
10131           gnus-downloaded-mark)
10132          (t
10133           gnus-no-mark))
10134    'download)
10135   (gnus-summary-update-line t)
10136   t)
10137
10138 (defun gnus-summary-update-mark (mark type)
10139   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10140         (buffer-read-only nil))
10141     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10142     (when forward
10143       (when (looking-at "\r")
10144         (incf forward))
10145       (when (<= (+ forward (point)) (point-max))
10146         ;; Go to the right position on the line.
10147         (goto-char (+ forward (point)))
10148         ;; Replace the old mark with the new mark.
10149         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10150         ;; Optionally update the marks by some user rule.
10151         (when (eq type 'unread)
10152           (gnus-data-set-mark
10153            (gnus-data-find (gnus-summary-article-number)) mark)
10154           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10155
10156 (defun gnus-mark-article-as-read (article &optional mark)
10157   "Enter ARTICLE in the pertinent lists and remove it from others."
10158   ;; Make the article expirable.
10159   (let ((mark (or mark gnus-del-mark)))
10160     (setq gnus-newsgroup-expirable
10161           (if (= mark gnus-expirable-mark)
10162               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10163             (delq article gnus-newsgroup-expirable)))
10164     ;; Remove from unread and marked lists.
10165     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10166     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10167     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10168     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10169     (push (cons article mark) gnus-newsgroup-reads)
10170     ;; Possibly remove from cache, if that is used.
10171     (when gnus-use-cache
10172       (gnus-cache-enter-remove-article article))
10173     t))
10174
10175 (defun gnus-mark-article-as-unread (article &optional mark)
10176   "Enter ARTICLE in the pertinent lists and remove it from others."
10177   (let ((mark (or mark gnus-ticked-mark)))
10178     (if (<= article 0)
10179         (progn
10180           (gnus-error 1 "Can't mark negative article numbers")
10181           nil)
10182       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10183             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10184             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10185             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10186             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10187
10188       ;; Unsuppress duplicates?
10189       (when gnus-suppress-duplicates
10190         (gnus-dup-unsuppress-article article))
10191
10192       (cond ((= mark gnus-ticked-mark)
10193              (setq gnus-newsgroup-marked
10194                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10195             ((= mark gnus-spam-mark)
10196              (setq gnus-newsgroup-spam-marked
10197                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10198                                             article)))
10199             ((= mark gnus-dormant-mark)
10200              (setq gnus-newsgroup-dormant
10201                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10202             (t
10203              (setq gnus-newsgroup-unreads
10204                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10205       (gnus-pull article gnus-newsgroup-reads)
10206       t)))
10207
10208 (defalias 'gnus-summary-mark-as-unread-forward
10209   'gnus-summary-tick-article-forward)
10210 (make-obsolete 'gnus-summary-mark-as-unread-forward
10211                'gnus-summary-tick-article-forward)
10212 (defun gnus-summary-tick-article-forward (n)
10213   "Tick N articles forwards.
10214 If N is negative, tick backwards instead.
10215 The difference between N and the number of articles ticked is returned."
10216   (interactive "p")
10217   (gnus-summary-mark-forward n gnus-ticked-mark))
10218
10219 (defalias 'gnus-summary-mark-as-unread-backward
10220   'gnus-summary-tick-article-backward)
10221 (make-obsolete 'gnus-summary-mark-as-unread-backward
10222                'gnus-summary-tick-article-backward)
10223 (defun gnus-summary-tick-article-backward (n)
10224   "Tick N articles backwards.
10225 The difference between N and the number of articles ticked is returned."
10226   (interactive "p")
10227   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10228
10229 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10230 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10231 (defun gnus-summary-tick-article (&optional article clear-mark)
10232   "Mark current article as unread.
10233 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10234 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10235   (interactive)
10236   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10237                                        gnus-ticked-mark)))
10238
10239 (defun gnus-summary-mark-as-read-forward (n)
10240   "Mark N articles as read forwards.
10241 If N is negative, mark backwards instead.
10242 The difference between N and the actual number of articles marked is
10243 returned."
10244   (interactive "p")
10245   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10246
10247 (defun gnus-summary-mark-as-read-backward (n)
10248   "Mark the N articles as read backwards.
10249 The difference between N and the actual number of articles marked is
10250 returned."
10251   (interactive "p")
10252   (gnus-summary-mark-forward
10253    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10254
10255 (defun gnus-summary-mark-as-read (&optional article mark)
10256   "Mark current article as read.
10257 ARTICLE specifies the article to be marked as read.
10258 MARK specifies a string to be inserted at the beginning of the line."
10259   (gnus-summary-mark-article article mark))
10260
10261 (defun gnus-summary-clear-mark-forward (n)
10262   "Clear marks from N articles forward.
10263 If N is negative, clear backward instead.
10264 The difference between N and the number of marks cleared is returned."
10265   (interactive "p")
10266   (gnus-summary-mark-forward n gnus-unread-mark))
10267
10268 (defun gnus-summary-clear-mark-backward (n)
10269   "Clear marks from N articles backward.
10270 The difference between N and the number of marks cleared is returned."
10271   (interactive "p")
10272   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10273
10274 (defun gnus-summary-mark-unread-as-read ()
10275   "Intended to be used by `gnus-summary-mark-article-hook'."
10276   (when (memq gnus-current-article gnus-newsgroup-unreads)
10277     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10278
10279 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10280   "Intended to be used by `gnus-summary-mark-article-hook'."
10281   (let ((mark (gnus-summary-article-mark)))
10282     (when (or (gnus-unread-mark-p mark)
10283               (gnus-read-mark-p mark))
10284       (gnus-summary-mark-article gnus-current-article
10285                                  (or new-mark gnus-read-mark)))))
10286
10287 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10288   "Intended to be used by `gnus-summary-mark-article-hook'."
10289   (let ((mark (gnus-summary-article-mark)))
10290     (when (or (gnus-unread-mark-p mark)
10291               (gnus-read-mark-p mark))
10292       (gnus-summary-mark-article (gnus-summary-article-number)
10293                                  (or new-mark gnus-read-mark)))))
10294
10295 (defun gnus-summary-mark-unread-as-ticked ()
10296   "Intended to be used by `gnus-summary-mark-article-hook'."
10297   (when (memq gnus-current-article gnus-newsgroup-unreads)
10298     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10299
10300 (defun gnus-summary-mark-region-as-read (point mark all)
10301   "Mark all unread articles between point and mark as read.
10302 If given a prefix, mark all articles between point and mark as read,
10303 even ticked and dormant ones."
10304   (interactive "r\nP")
10305   (save-excursion
10306     (let (article)
10307       (goto-char point)
10308       (beginning-of-line)
10309       (while (and
10310               (< (point) mark)
10311               (progn
10312                 (when (or all
10313                           (memq (setq article (gnus-summary-article-number))
10314                                 gnus-newsgroup-unreads))
10315                   (gnus-summary-mark-article article gnus-del-mark))
10316                 t)
10317               (gnus-summary-find-next))))))
10318
10319 (defun gnus-summary-mark-below (score mark)
10320   "Mark articles with score less than SCORE with MARK."
10321   (interactive "P\ncMark: ")
10322   (setq score (if score
10323                   (prefix-numeric-value score)
10324                 (or gnus-summary-default-score 0)))
10325   (save-excursion
10326     (set-buffer gnus-summary-buffer)
10327     (goto-char (point-min))
10328     (while
10329         (progn
10330           (and (< (gnus-summary-article-score) score)
10331                (gnus-summary-mark-article nil mark))
10332           (gnus-summary-find-next)))))
10333
10334 (defun gnus-summary-kill-below (&optional score)
10335   "Mark articles with score below SCORE as read."
10336   (interactive "P")
10337   (gnus-summary-mark-below score gnus-killed-mark))
10338
10339 (defun gnus-summary-clear-above (&optional score)
10340   "Clear all marks from articles with score above SCORE."
10341   (interactive "P")
10342   (gnus-summary-mark-above score gnus-unread-mark))
10343
10344 (defun gnus-summary-tick-above (&optional score)
10345   "Tick all articles with score above SCORE."
10346   (interactive "P")
10347   (gnus-summary-mark-above score gnus-ticked-mark))
10348
10349 (defun gnus-summary-mark-above (score mark)
10350   "Mark articles with score over SCORE with MARK."
10351   (interactive "P\ncMark: ")
10352   (setq score (if score
10353                   (prefix-numeric-value score)
10354                 (or gnus-summary-default-score 0)))
10355   (save-excursion
10356     (set-buffer gnus-summary-buffer)
10357     (goto-char (point-min))
10358     (while (and (progn
10359                   (when (> (gnus-summary-article-score) score)
10360                     (gnus-summary-mark-article nil mark))
10361                   t)
10362                 (gnus-summary-find-next)))))
10363
10364 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10365 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10366 (defun gnus-summary-limit-include-expunged (&optional no-error)
10367   "Display all the hidden articles that were expunged for low scores."
10368   (interactive)
10369   (let ((buffer-read-only nil))
10370     (let ((scored gnus-newsgroup-scored)
10371           headers h)
10372       (while scored
10373         (unless (gnus-summary-article-header (caar scored))
10374           (and (setq h (gnus-number-to-header (caar scored)))
10375                (< (cdar scored) gnus-summary-expunge-below)
10376                (push h headers)))
10377         (setq scored (cdr scored)))
10378       (if (not headers)
10379           (when (not no-error)
10380             (error "No expunged articles hidden"))
10381         (goto-char (point-min))
10382         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10383         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10384         (mapcar (lambda (x) (push (mail-header-number x)
10385                                   gnus-newsgroup-limit))
10386                 headers)
10387         (gnus-summary-prepare-unthreaded (nreverse headers))
10388         (goto-char (point-min))
10389         (gnus-summary-position-point)
10390         t))))
10391
10392 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10393   "Mark all unread articles in this newsgroup as read.
10394 If prefix argument ALL is non-nil, ticked and dormant articles will
10395 also be marked as read.
10396 If QUIETLY is non-nil, no questions will be asked.
10397
10398 If TO-HERE is non-nil, it should be a point in the buffer.  All
10399 articles before (after, if REVERSE is set) this point will be marked
10400 as read.
10401
10402 Note that this function will only catch up the unread article
10403 in the current summary buffer limitation.
10404
10405 The number of articles marked as read is returned."
10406   (interactive "P")
10407   (prog1
10408       (save-excursion
10409         (when (or quietly
10410                   (not gnus-interactive-catchup) ;Without confirmation?
10411                   gnus-expert-user
10412                   (gnus-y-or-n-p
10413                    (if all
10414                        "Mark absolutely all articles as read? "
10415                      "Mark all unread articles as read? ")))
10416           (if (and not-mark
10417                    (not gnus-newsgroup-adaptive)
10418                    (not gnus-newsgroup-auto-expire)
10419                    (not gnus-suppress-duplicates)
10420                    (or (not gnus-use-cache)
10421                        (eq gnus-use-cache 'passive)))
10422               (progn
10423                 (when all
10424                   (setq gnus-newsgroup-marked nil
10425                         gnus-newsgroup-spam-marked nil
10426                         gnus-newsgroup-dormant nil))
10427                 (setq gnus-newsgroup-unreads
10428                       (gnus-sorted-nunion
10429                        (gnus-intersection gnus-newsgroup-unreads
10430                                           gnus-newsgroup-downloadable)
10431                        gnus-newsgroup-unfetched)))
10432             ;; We actually mark all articles as canceled, which we
10433             ;; have to do when using auto-expiry or adaptive scoring.
10434             (gnus-summary-show-all-threads)
10435             (if (and to-here reverse)
10436                 (progn
10437                   (goto-char to-here)
10438                   (gnus-summary-mark-current-read-and-unread-as-read
10439                    gnus-catchup-mark)
10440                   (while (gnus-summary-find-next (not all))
10441                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10442               (when (gnus-summary-first-subject (not all))
10443                 (while (and
10444                         (if to-here (< (point) to-here) t)
10445                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10446                         (gnus-summary-find-next (not all))))))
10447             (gnus-set-mode-line 'summary))
10448           t))
10449     (gnus-summary-position-point)))
10450
10451 (defun gnus-summary-catchup-to-here (&optional all)
10452   "Mark all unticked articles before the current one as read.
10453 If ALL is non-nil, also mark ticked and dormant articles as read."
10454   (interactive "P")
10455   (save-excursion
10456     (gnus-save-hidden-threads
10457       (let ((beg (point)))
10458         ;; We check that there are unread articles.
10459         (when (or all (gnus-summary-find-prev))
10460           (gnus-summary-catchup all t beg)))))
10461   (gnus-summary-position-point))
10462
10463 (defun gnus-summary-catchup-from-here (&optional all)
10464   "Mark all unticked articles after (and including) the current one as read.
10465 If ALL is non-nil, also mark ticked and dormant articles as read."
10466   (interactive "P")
10467   (save-excursion
10468     (gnus-save-hidden-threads
10469       (let ((beg (point)))
10470         ;; We check that there are unread articles.
10471         (when (or all (gnus-summary-find-next))
10472           (gnus-summary-catchup all t beg nil t)))))
10473   (gnus-summary-position-point))
10474
10475 (defun gnus-summary-catchup-all (&optional quietly)
10476   "Mark all articles in this newsgroup as read.
10477 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10478 instead, which marks only unread articles as read."
10479   (interactive "P")
10480   (gnus-summary-catchup t quietly))
10481
10482 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10483   "Mark all unread articles in this group as read, then exit.
10484 If prefix argument ALL is non-nil, all articles are marked as read.
10485 If QUIETLY is non-nil, no questions will be asked."
10486   (interactive "P")
10487   (when (gnus-summary-catchup all quietly nil 'fast)
10488     ;; Select next newsgroup or exit.
10489     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10490              (eq gnus-auto-select-next 'quietly))
10491         (gnus-summary-next-group nil)
10492       (gnus-summary-exit))))
10493
10494 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10495   "Mark all articles in this newsgroup as read, and then exit.
10496 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10497 instead, which marks only unread articles as read."
10498   (interactive "P")
10499   (gnus-summary-catchup-and-exit t quietly))
10500
10501 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10502   "Mark all articles in this group as read and select the next group.
10503 If given a prefix, mark all articles, unread as well as ticked, as
10504 read."
10505   (interactive "P")
10506   (save-excursion
10507     (gnus-summary-catchup all))
10508   (gnus-summary-next-group))
10509
10510 ;;;
10511 ;;; with article
10512 ;;;
10513
10514 (defmacro gnus-with-article (article &rest forms)
10515   "Select ARTICLE and perform FORMS in the original article buffer.
10516 Then replace the article with the result."
10517   `(progn
10518      ;; We don't want the article to be marked as read.
10519      (let (gnus-mark-article-hook)
10520        (gnus-summary-select-article t t nil ,article))
10521      (set-buffer gnus-original-article-buffer)
10522      ,@forms
10523      (if (not (gnus-check-backend-function
10524                'request-replace-article (car gnus-article-current)))
10525          (gnus-message 5 "Read-only group; not replacing")
10526        (unless (gnus-request-replace-article
10527                 ,article (car gnus-article-current)
10528                 (current-buffer) t)
10529          (error "Couldn't replace article")))
10530      ;; The cache and backlog have to be flushed somewhat.
10531      (when gnus-keep-backlog
10532        (gnus-backlog-remove-article
10533         (car gnus-article-current) (cdr gnus-article-current)))
10534      (when gnus-use-cache
10535        (gnus-cache-update-article
10536         (car gnus-article-current) (cdr gnus-article-current)))))
10537
10538 (put 'gnus-with-article 'lisp-indent-function 1)
10539 (put 'gnus-with-article 'edebug-form-spec '(form body))
10540
10541 ;; Thread-based commands.
10542
10543 (defun gnus-summary-articles-in-thread (&optional article)
10544   "Return a list of all articles in the current thread.
10545 If ARTICLE is non-nil, return all articles in the thread that starts
10546 with that article."
10547   (let* ((article (or article (gnus-summary-article-number)))
10548          (data (gnus-data-find-list article))
10549          (top-level (gnus-data-level (car data)))
10550          (top-subject
10551           (cond ((null gnus-thread-operation-ignore-subject)
10552                  (gnus-simplify-subject-re
10553                   (mail-header-subject (gnus-data-header (car data)))))
10554                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10555                  (gnus-simplify-subject-fuzzy
10556                   (mail-header-subject (gnus-data-header (car data)))))
10557                 (t nil)))
10558          (end-point (save-excursion
10559                       (if (gnus-summary-go-to-next-thread)
10560                           (point) (point-max))))
10561          articles)
10562     (while (and data
10563                 (< (gnus-data-pos (car data)) end-point))
10564       (when (or (not top-subject)
10565                 (string= top-subject
10566                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10567                              (gnus-simplify-subject-fuzzy
10568                               (mail-header-subject
10569                                (gnus-data-header (car data))))
10570                            (gnus-simplify-subject-re
10571                             (mail-header-subject
10572                              (gnus-data-header (car data)))))))
10573         (push (gnus-data-number (car data)) articles))
10574       (unless (and (setq data (cdr data))
10575                    (> (gnus-data-level (car data)) top-level))
10576         (setq data nil)))
10577     ;; Return the list of articles.
10578     (nreverse articles)))
10579
10580 (defun gnus-summary-rethread-current ()
10581   "Rethread the thread the current article is part of."
10582   (interactive)
10583   (let* ((gnus-show-threads t)
10584          (article (gnus-summary-article-number))
10585          (id (mail-header-id (gnus-summary-article-header)))
10586          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10587     (unless id
10588       (error "No article on the current line"))
10589     (gnus-rebuild-thread id)
10590     (gnus-summary-goto-subject article)))
10591
10592 (defun gnus-summary-reparent-thread ()
10593   "Make the current article child of the marked (or previous) article.
10594
10595 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10596 is non-nil or the Subject: of both articles are the same."
10597   (interactive)
10598   (unless (not (gnus-group-read-only-p))
10599     (error "The current newsgroup does not support article editing"))
10600   (unless (<= (length gnus-newsgroup-processable) 1)
10601     (error "No more than one article may be marked"))
10602   (save-window-excursion
10603     (let ((gnus-article-buffer " *reparent*")
10604           (current-article (gnus-summary-article-number))
10605           ;; First grab the marked article, otherwise one line up.
10606           (parent-article (if (not (null gnus-newsgroup-processable))
10607                               (car gnus-newsgroup-processable)
10608                             (save-excursion
10609                               (if (eq (forward-line -1) 0)
10610                                   (gnus-summary-article-number)
10611                                 (error "Beginning of summary buffer"))))))
10612       (unless (not (eq current-article parent-article))
10613         (error "An article may not be self-referential"))
10614       (let ((message-id (mail-header-id
10615                          (gnus-summary-article-header parent-article))))
10616         (unless (and message-id (not (equal message-id "")))
10617           (error "No message-id in desired parent"))
10618         (gnus-with-article current-article
10619           (save-restriction
10620             (goto-char (point-min))
10621             (message-narrow-to-head)
10622             (if (re-search-forward "^References: " nil t)
10623                 (progn
10624                   (re-search-forward "^[^ \t]" nil t)
10625                   (forward-line -1)
10626                   (end-of-line)
10627                   (insert " " message-id))
10628               (insert "References: " message-id "\n"))))
10629         (set-buffer gnus-summary-buffer)
10630         (gnus-summary-unmark-all-processable)
10631         (gnus-summary-update-article current-article)
10632         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10633             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10634         (gnus-summary-rethread-current)
10635         (gnus-message 3 "Article %d is now the child of article %d"
10636                       current-article parent-article)))))
10637
10638 (defun gnus-summary-toggle-threads (&optional arg)
10639   "Toggle showing conversation threads.
10640 If ARG is positive number, turn showing conversation threads on."
10641   (interactive "P")
10642   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10643     (setq gnus-show-threads
10644           (if (null arg) (not gnus-show-threads)
10645             (> (prefix-numeric-value arg) 0)))
10646     (gnus-summary-prepare)
10647     (gnus-summary-goto-subject current)
10648     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10649     (gnus-summary-position-point)))
10650
10651 (defun gnus-summary-show-all-threads ()
10652   "Show all threads."
10653   (interactive)
10654   (save-excursion
10655     (let ((buffer-read-only nil))
10656       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10657   (gnus-summary-position-point))
10658
10659 (defun gnus-summary-show-thread ()
10660   "Show thread subtrees.
10661 Returns nil if no thread was there to be shown."
10662   (interactive)
10663   (let ((buffer-read-only nil)
10664         (orig (point))
10665         (end (point-at-eol))
10666         ;; Leave point at bol
10667         (beg (progn (beginning-of-line) (point))))
10668     (prog1
10669         ;; Any hidden lines here?
10670         (search-forward "\r" end t)
10671       (subst-char-in-region beg end ?\^M ?\n t)
10672       (goto-char orig)
10673       (gnus-summary-position-point))))
10674
10675 (defun gnus-summary-maybe-hide-threads ()
10676   "If requested, hide the threads that should be hidden."
10677   (when (and gnus-show-threads
10678              gnus-thread-hide-subtree)
10679     (gnus-summary-hide-all-threads
10680      (if (or (consp gnus-thread-hide-subtree)
10681              (functionp gnus-thread-hide-subtree))
10682          (gnus-make-predicate gnus-thread-hide-subtree)
10683        nil))))
10684
10685 ;;; Hiding predicates.
10686
10687 (defun gnus-article-unread-p (header)
10688   (memq (mail-header-number header) gnus-newsgroup-unreads))
10689
10690 (defun gnus-article-unseen-p (header)
10691   (memq (mail-header-number header) gnus-newsgroup-unseen))
10692
10693 (defun gnus-map-articles (predicate articles)
10694   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10695   (apply 'gnus-or (mapcar predicate
10696                           (mapcar 'gnus-summary-article-header articles))))
10697
10698 (defun gnus-summary-hide-all-threads (&optional predicate)
10699   "Hide all thread subtrees.
10700 If PREDICATE is supplied, threads that satisfy this predicate
10701 will not be hidden."
10702   (interactive)
10703   (save-excursion
10704     (goto-char (point-min))
10705     (let ((end nil))
10706       (while (not end)
10707         (when (or (not predicate)
10708                   (gnus-map-articles
10709                    predicate (gnus-summary-article-children)))
10710             (gnus-summary-hide-thread))
10711         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10712   (gnus-summary-position-point))
10713
10714 (defun gnus-summary-hide-thread ()
10715   "Hide thread subtrees.
10716 If PREDICATE is supplied, threads that satisfy this predicate
10717 will not be hidden.
10718 Returns nil if no threads were there to be hidden."
10719   (interactive)
10720   (let ((buffer-read-only nil)
10721         (start (point))
10722         (article (gnus-summary-article-number)))
10723     (goto-char start)
10724     ;; Go forward until either the buffer ends or the subthread
10725     ;; ends.
10726     (when (and (not (eobp))
10727                (or (zerop (gnus-summary-next-thread 1 t))
10728                    (goto-char (point-max))))
10729       (prog1
10730           (if (and (> (point) start)
10731                    (search-backward "\n" start t))
10732               (progn
10733                 (subst-char-in-region start (point) ?\n ?\^M)
10734                 (gnus-summary-goto-subject article))
10735             (goto-char start)
10736             nil)))))
10737
10738 (defun gnus-summary-go-to-next-thread (&optional previous)
10739   "Go to the same level (or less) next thread.
10740 If PREVIOUS is non-nil, go to previous thread instead.
10741 Return the article number moved to, or nil if moving was impossible."
10742   (let ((level (gnus-summary-thread-level))
10743         (way (if previous -1 1))
10744         (beg (point)))
10745     (forward-line way)
10746     (while (and (not (eobp))
10747                 (< level (gnus-summary-thread-level)))
10748       (forward-line way))
10749     (if (eobp)
10750         (progn
10751           (goto-char beg)
10752           nil)
10753       (setq beg (point))
10754       (prog1
10755           (gnus-summary-article-number)
10756         (goto-char beg)))))
10757
10758 (defun gnus-summary-next-thread (n &optional silent)
10759   "Go to the same level next N'th thread.
10760 If N is negative, search backward instead.
10761 Returns the difference between N and the number of skips actually
10762 done.
10763
10764 If SILENT, don't output messages."
10765   (interactive "p")
10766   (let ((backward (< n 0))
10767         (n (abs n)))
10768     (while (and (> n 0)
10769                 (gnus-summary-go-to-next-thread backward))
10770       (decf n))
10771     (unless silent
10772       (gnus-summary-position-point))
10773     (when (and (not silent) (/= 0 n))
10774       (gnus-message 7 "No more threads"))
10775     n))
10776
10777 (defun gnus-summary-prev-thread (n)
10778   "Go to the same level previous N'th thread.
10779 Returns the difference between N and the number of skips actually
10780 done."
10781   (interactive "p")
10782   (gnus-summary-next-thread (- n)))
10783
10784 (defun gnus-summary-go-down-thread ()
10785   "Go down one level in the current thread."
10786   (let ((children (gnus-summary-article-children)))
10787     (when children
10788       (gnus-summary-goto-subject (car children)))))
10789
10790 (defun gnus-summary-go-up-thread ()
10791   "Go up one level in the current thread."
10792   (let ((parent (gnus-summary-article-parent)))
10793     (when parent
10794       (gnus-summary-goto-subject parent))))
10795
10796 (defun gnus-summary-down-thread (n)
10797   "Go down thread N steps.
10798 If N is negative, go up instead.
10799 Returns the difference between N and how many steps down that were
10800 taken."
10801   (interactive "p")
10802   (let ((up (< n 0))
10803         (n (abs n)))
10804     (while (and (> n 0)
10805                 (if up (gnus-summary-go-up-thread)
10806                   (gnus-summary-go-down-thread)))
10807       (setq n (1- n)))
10808     (gnus-summary-position-point)
10809     (when (/= 0 n)
10810       (gnus-message 7 "Can't go further"))
10811     n))
10812
10813 (defun gnus-summary-up-thread (n)
10814   "Go up thread N steps.
10815 If N is negative, go down instead.
10816 Returns the difference between N and how many steps down that were
10817 taken."
10818   (interactive "p")
10819   (gnus-summary-down-thread (- n)))
10820
10821 (defun gnus-summary-top-thread ()
10822   "Go to the top of the thread."
10823   (interactive)
10824   (while (gnus-summary-go-up-thread))
10825   (gnus-summary-article-number))
10826
10827 (defun gnus-summary-kill-thread (&optional unmark)
10828   "Mark articles under current thread as read.
10829 If the prefix argument is positive, remove any kinds of marks.
10830 If the prefix argument is negative, tick articles instead."
10831   (interactive "P")
10832   (when unmark
10833     (setq unmark (prefix-numeric-value unmark)))
10834   (let ((articles (gnus-summary-articles-in-thread)))
10835     (save-excursion
10836       ;; Expand the thread.
10837       (gnus-summary-show-thread)
10838       ;; Mark all the articles.
10839       (while articles
10840         (gnus-summary-goto-subject (car articles))
10841         (cond ((null unmark)
10842                (gnus-summary-mark-article-as-read gnus-killed-mark))
10843               ((> unmark 0)
10844                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10845               (t
10846                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10847         (setq articles (cdr articles))))
10848     ;; Hide killed subtrees.
10849     (and (null unmark)
10850          gnus-thread-hide-killed
10851          (gnus-summary-hide-thread))
10852     ;; If marked as read, go to next unread subject.
10853     (when (null unmark)
10854       ;; Go to next unread subject.
10855       (gnus-summary-next-subject 1 t)))
10856   (gnus-set-mode-line 'summary))
10857
10858 ;; Summary sorting commands
10859
10860 (defun gnus-summary-sort-by-number (&optional reverse)
10861   "Sort the summary buffer by article number.
10862 Argument REVERSE means reverse order."
10863   (interactive "P")
10864   (gnus-summary-sort 'number reverse))
10865
10866 (defun gnus-summary-sort-by-random (&optional reverse)
10867   "Randomize the order in the summary buffer.
10868 Argument REVERSE means to randomize in reverse order."
10869   (interactive "P")
10870   (gnus-summary-sort 'random reverse))
10871
10872 (defun gnus-summary-sort-by-author (&optional reverse)
10873   "Sort the summary buffer by author name alphabetically.
10874 If `case-fold-search' is non-nil, case of letters is ignored.
10875 Argument REVERSE means reverse order."
10876   (interactive "P")
10877   (gnus-summary-sort 'author reverse))
10878
10879 (defun gnus-summary-sort-by-subject (&optional reverse)
10880   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10881 If `case-fold-search' is non-nil, case of letters is ignored.
10882 Argument REVERSE means reverse order."
10883   (interactive "P")
10884   (gnus-summary-sort 'subject reverse))
10885
10886 (defun gnus-summary-sort-by-date (&optional reverse)
10887   "Sort the summary buffer by date.
10888 Argument REVERSE means reverse order."
10889   (interactive "P")
10890   (gnus-summary-sort 'date reverse))
10891
10892 (defun gnus-summary-sort-by-score (&optional reverse)
10893   "Sort the summary buffer by score.
10894 Argument REVERSE means reverse order."
10895   (interactive "P")
10896   (gnus-summary-sort 'score reverse))
10897
10898 (defun gnus-summary-sort-by-lines (&optional reverse)
10899   "Sort the summary buffer by the number of lines.
10900 Argument REVERSE means reverse order."
10901   (interactive "P")
10902   (gnus-summary-sort 'lines reverse))
10903
10904 (defun gnus-summary-sort-by-chars (&optional reverse)
10905   "Sort the summary buffer by article length.
10906 Argument REVERSE means reverse order."
10907   (interactive "P")
10908   (gnus-summary-sort 'chars reverse))
10909
10910 (defun gnus-summary-sort-by-original (&optional reverse)
10911   "Sort the summary buffer using the default sorting method.
10912 Argument REVERSE means reverse order."
10913   (interactive "P")
10914   (let* ((buffer-read-only)
10915          (gnus-summary-prepare-hook nil))
10916     ;; We do the sorting by regenerating the threads.
10917     (gnus-summary-prepare)
10918     ;; Hide subthreads if needed.
10919     (gnus-summary-maybe-hide-threads)))
10920
10921 (defun gnus-summary-sort (predicate reverse)
10922   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10923   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10924          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10925          (gnus-thread-sort-functions
10926           (if (not reverse)
10927               thread
10928             `(lambda (t1 t2)
10929                (,thread t2 t1))))
10930          (gnus-sort-gathered-threads-function
10931           gnus-thread-sort-functions)
10932          (gnus-article-sort-functions
10933           (if (not reverse)
10934               article
10935             `(lambda (t1 t2)
10936                (,article t2 t1))))
10937          (buffer-read-only)
10938          (gnus-summary-prepare-hook nil))
10939     ;; We do the sorting by regenerating the threads.
10940     (gnus-summary-prepare)
10941     ;; Hide subthreads if needed.
10942     (gnus-summary-maybe-hide-threads)))
10943
10944 ;; Summary saving commands.
10945
10946 (defun gnus-summary-save-article (&optional n not-saved)
10947   "Save the current article using the default saver function.
10948 If N is a positive number, save the N next articles.
10949 If N is a negative number, save the N previous articles.
10950 If N is nil and any articles have been marked with the process mark,
10951 save those articles instead.
10952 The variable `gnus-default-article-saver' specifies the saver function."
10953   (interactive "P")
10954   (let* ((articles (gnus-summary-work-articles n))
10955          (save-buffer (save-excursion
10956                         (nnheader-set-temp-buffer " *Gnus Save*")))
10957          (num (length articles))
10958          header file)
10959     (dolist (article articles)
10960       (setq header (gnus-summary-article-header article))
10961       (if (not (vectorp header))
10962           ;; This is a pseudo-article.
10963           (if (assq 'name header)
10964               (gnus-copy-file (cdr (assq 'name header)))
10965             (gnus-message 1 "Article %d is unsaveable" article))
10966         ;; This is a real article.
10967         (save-window-excursion
10968           (let ((gnus-display-mime-function nil)
10969                 (gnus-article-prepare-hook nil))
10970             (gnus-summary-select-article t nil nil article)))
10971         (save-excursion
10972           (set-buffer save-buffer)
10973           (erase-buffer)
10974           (insert-buffer-substring gnus-original-article-buffer))
10975         (setq file (gnus-article-save save-buffer file num))
10976         (gnus-summary-remove-process-mark article)
10977         (unless not-saved
10978           (gnus-summary-set-saved-mark article))))
10979     (gnus-kill-buffer save-buffer)
10980     (gnus-summary-position-point)
10981     (gnus-set-mode-line 'summary)
10982     n))
10983
10984 (defun gnus-summary-pipe-output (&optional arg headers)
10985   "Pipe the current article to a subprocess.
10986 If N is a positive number, pipe the N next articles.
10987 If N is a negative number, pipe the N previous articles.
10988 If N is nil and any articles have been marked with the process mark,
10989 pipe those articles instead.
10990 If HEADERS (the symbolic prefix), include the headers, too."
10991   (interactive (gnus-interactive "P\ny"))
10992   (require 'gnus-art)
10993   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10994         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10995     (gnus-summary-save-article arg t))
10996   (let ((buffer (get-buffer "*Shell Command Output*")))
10997     (when (and buffer
10998                (not (zerop (buffer-size buffer))))
10999       (gnus-configure-windows 'pipe))))
11000
11001 (defun gnus-summary-save-article-mail (&optional arg)
11002   "Append the current article to an mail file.
11003 If N is a positive number, save the N next articles.
11004 If N is a negative number, save the N previous articles.
11005 If N is nil and any articles have been marked with the process mark,
11006 save those articles instead."
11007   (interactive "P")
11008   (require 'gnus-art)
11009   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11010     (gnus-summary-save-article arg)))
11011
11012 (defun gnus-summary-save-article-rmail (&optional arg)
11013   "Append the current article to an rmail file.
11014 If N is a positive number, save the N next articles.
11015 If N is a negative number, save the N previous articles.
11016 If N is nil and any articles have been marked with the process mark,
11017 save those articles instead."
11018   (interactive "P")
11019   (require 'gnus-art)
11020   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11021     (gnus-summary-save-article arg)))
11022
11023 (defun gnus-summary-save-article-file (&optional arg)
11024   "Append the current article to a file.
11025 If N is a positive number, save the N next articles.
11026 If N is a negative number, save the N previous articles.
11027 If N is nil and any articles have been marked with the process mark,
11028 save those articles instead."
11029   (interactive "P")
11030   (require 'gnus-art)
11031   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11032     (gnus-summary-save-article arg)))
11033
11034 (defun gnus-summary-write-article-file (&optional arg)
11035   "Write the current article to a file, deleting the previous file.
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   (interactive "P")
11041   (require 'gnus-art)
11042   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11043     (gnus-summary-save-article arg)))
11044
11045 (defun gnus-summary-save-article-body-file (&optional arg)
11046   "Append the current article body to a file.
11047 If N is a positive number, save the N next articles.
11048 If N is a negative number, save the N previous articles.
11049 If N is nil and any articles have been marked with the process mark,
11050 save those articles instead."
11051   (interactive "P")
11052   (require 'gnus-art)
11053   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11054     (gnus-summary-save-article arg)))
11055
11056 (defun gnus-summary-muttprint (&optional arg)
11057   "Print the current article using Muttprint.
11058 If N is a positive number, save the N next articles.
11059 If N is a negative number, save the N previous articles.
11060 If N is nil and any articles have been marked with the process mark,
11061 save those articles instead."
11062   (interactive "P")
11063   (require 'gnus-art)
11064   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11065     (gnus-summary-save-article arg t)))
11066
11067 (defun gnus-summary-pipe-message (program)
11068   "Pipe the current article through PROGRAM."
11069   (interactive "sProgram: ")
11070   (gnus-summary-select-article)
11071   (let ((mail-header-separator ""))
11072     (gnus-eval-in-buffer-window gnus-article-buffer
11073       (save-restriction
11074         (widen)
11075         (let ((start (window-start))
11076               buffer-read-only)
11077           (message-pipe-buffer-body program)
11078           (set-window-start (get-buffer-window (current-buffer)) start))))))
11079
11080 (defun gnus-get-split-value (methods)
11081   "Return a value based on the split METHODS."
11082   (let (split-name method result match)
11083     (when methods
11084       (save-excursion
11085         (set-buffer gnus-original-article-buffer)
11086         (save-restriction
11087           (nnheader-narrow-to-headers)
11088           (while (and methods (not split-name))
11089             (goto-char (point-min))
11090             (setq method (pop methods))
11091             (setq match (car method))
11092             (when (cond
11093                    ((stringp match)
11094                     ;; Regular expression.
11095                     (ignore-errors
11096                       (re-search-forward match nil t)))
11097                    ((functionp match)
11098                     ;; Function.
11099                     (save-restriction
11100                       (widen)
11101                       (setq result (funcall match gnus-newsgroup-name))))
11102                    ((consp match)
11103                     ;; Form.
11104                     (save-restriction
11105                       (widen)
11106                       (setq result (eval match)))))
11107               (setq split-name (cdr method))
11108               (cond ((stringp result)
11109                      (push (expand-file-name
11110                             result gnus-article-save-directory)
11111                            split-name))
11112                     ((consp result)
11113                      (setq split-name (append result split-name)))))))))
11114     (nreverse split-name)))
11115
11116 (defun gnus-valid-move-group-p (group)
11117   (and (boundp group)
11118        (symbol-name group)
11119        (symbol-value group)
11120        (gnus-get-function (gnus-find-method-for-group
11121                            (symbol-name group)) 'request-accept-article t)))
11122
11123 (defun gnus-read-move-group-name (prompt default articles prefix)
11124   "Read a group name."
11125   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11126          (minibuffer-confirm-incomplete nil) ; XEmacs
11127          (prom
11128           (format "%s %s to:"
11129                   prompt
11130                   (if (> (length articles) 1)
11131                       (format "these %d articles" (length articles))
11132                     "this article")))
11133          (to-newsgroup
11134           (cond
11135            ((null split-name)
11136             (gnus-completing-read-with-default
11137              default prom
11138              gnus-active-hashtb
11139              'gnus-valid-move-group-p
11140              nil prefix
11141              'gnus-group-history))
11142            ((= 1 (length split-name))
11143             (gnus-completing-read-with-default
11144              (car split-name) prom
11145              gnus-active-hashtb
11146              'gnus-valid-move-group-p
11147              nil nil
11148              'gnus-group-history))
11149            (t
11150             (gnus-completing-read-with-default
11151              nil prom
11152              (mapcar 'list (nreverse split-name))
11153              nil nil nil
11154              'gnus-group-history))))
11155          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11156     (when to-newsgroup
11157       (if (or (string= to-newsgroup "")
11158               (string= to-newsgroup prefix))
11159           (setq to-newsgroup default))
11160       (unless to-newsgroup
11161         (error "No group name entered"))
11162       (or (gnus-active to-newsgroup)
11163           (gnus-activate-group to-newsgroup nil nil to-method)
11164           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11165                                      to-newsgroup))
11166               (or (and (gnus-request-create-group to-newsgroup to-method)
11167                        (gnus-activate-group
11168                         to-newsgroup nil nil to-method)
11169                        (gnus-subscribe-group to-newsgroup))
11170                   (error "Couldn't create group %s" to-newsgroup)))
11171           (error "No such group: %s" to-newsgroup)))
11172     to-newsgroup))
11173
11174 (defun gnus-summary-save-parts (type dir n &optional reverse)
11175   "Save parts matching TYPE to DIR.
11176 If REVERSE, save parts that do not match TYPE."
11177   (interactive
11178    (list (read-string "Save parts of type: "
11179                       (or (car gnus-summary-save-parts-type-history)
11180                           gnus-summary-save-parts-default-mime)
11181                       'gnus-summary-save-parts-type-history)
11182          (setq gnus-summary-save-parts-last-directory
11183                (read-file-name "Save to directory: "
11184                                gnus-summary-save-parts-last-directory
11185                                nil t))
11186          current-prefix-arg))
11187   (gnus-summary-iterate n
11188     (let ((gnus-display-mime-function nil)
11189           (gnus-inhibit-treatment t))
11190       (gnus-summary-select-article))
11191     (save-excursion
11192       (set-buffer gnus-article-buffer)
11193       (let ((handles (or gnus-article-mime-handles
11194                          (mm-dissect-buffer nil gnus-article-loose-mime)
11195                          (and gnus-article-emulate-mime
11196                               (mm-uu-dissect)))))
11197         (when handles
11198           (gnus-summary-save-parts-1 type dir handles reverse)
11199           (unless gnus-article-mime-handles ;; Don't destroy this case.
11200             (mm-destroy-parts handles)))))))
11201
11202 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11203   (if (stringp (car handle))
11204       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11205               (cdr handle))
11206     (when (if reverse
11207               (not (string-match type (mm-handle-media-type handle)))
11208             (string-match type (mm-handle-media-type handle)))
11209       (let ((file (expand-file-name
11210                    (gnus-map-function
11211                     mm-file-name-rewrite-functions
11212                     (file-name-nondirectory
11213                      (or
11214                       (mail-content-type-get
11215                        (mm-handle-disposition handle) 'filename)
11216                       (mail-content-type-get
11217                        (mm-handle-type handle) 'name)
11218                       (concat gnus-newsgroup-name
11219                               "." (number-to-string
11220                                    (cdr gnus-article-current))))))
11221                    dir)))
11222         (unless (file-exists-p file)
11223           (mm-save-part-to-file handle file))))))
11224
11225 ;; Summary extract commands
11226
11227 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11228   (let ((buffer-read-only nil)
11229         (article (gnus-summary-article-number))
11230         after-article b e)
11231     (unless (gnus-summary-goto-subject article)
11232       (error "No such article: %d" article))
11233     (gnus-summary-position-point)
11234     ;; If all commands are to be bunched up on one line, we collect
11235     ;; them here.
11236     (unless gnus-view-pseudos-separately
11237       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11238             files action)
11239         (while ps
11240           (setq action (cdr (assq 'action (car ps))))
11241           (setq files (list (cdr (assq 'name (car ps)))))
11242           (while (and ps (cdr ps)
11243                       (string= (or action "1")
11244                                (or (cdr (assq 'action (cadr ps))) "2")))
11245             (push (cdr (assq 'name (cadr ps))) files)
11246             (setcdr ps (cddr ps)))
11247           (when files
11248             (when (not (string-match "%s" action))
11249               (push " " files))
11250             (push " " files)
11251             (when (assq 'execute (car ps))
11252               (setcdr (assq 'execute (car ps))
11253                       (funcall (if (string-match "%s" action)
11254                                    'format 'concat)
11255                                action
11256                                (mapconcat
11257                                 (lambda (f)
11258                                   (if (equal f " ")
11259                                       f
11260                                     (shell-quote-argument f)))
11261                                 files " ")))))
11262           (setq ps (cdr ps)))))
11263     (if (and gnus-view-pseudos (not not-view))
11264         (while pslist
11265           (when (assq 'execute (car pslist))
11266             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11267                                   (eq gnus-view-pseudos 'not-confirm)))
11268           (setq pslist (cdr pslist)))
11269       (save-excursion
11270         (while pslist
11271           (setq after-article (or (cdr (assq 'article (car pslist)))
11272                                   (gnus-summary-article-number)))
11273           (gnus-summary-goto-subject after-article)
11274           (forward-line 1)
11275           (setq b (point))
11276           (insert "    " (file-name-nondirectory
11277                           (cdr (assq 'name (car pslist))))
11278                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11279           (setq e (point))
11280           (forward-line -1)             ; back to `b'
11281           (gnus-add-text-properties
11282            b (1- e) (list 'gnus-number gnus-reffed-article-number
11283                           gnus-mouse-face-prop gnus-mouse-face))
11284           (gnus-data-enter
11285            after-article gnus-reffed-article-number
11286            gnus-unread-mark b (car pslist) 0 (- e b))
11287           (setq gnus-newsgroup-unreads
11288                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11289                                          gnus-reffed-article-number))
11290           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11291           (setq pslist (cdr pslist)))))))
11292
11293 (defun gnus-pseudos< (p1 p2)
11294   (let ((c1 (cdr (assq 'action p1)))
11295         (c2 (cdr (assq 'action p2))))
11296     (and c1 c2 (string< c1 c2))))
11297
11298 (defun gnus-request-pseudo-article (props)
11299   (cond ((assq 'execute props)
11300          (gnus-execute-command (cdr (assq 'execute props)))))
11301   (let ((gnus-current-article (gnus-summary-article-number)))
11302     (gnus-run-hooks 'gnus-mark-article-hook)))
11303
11304 (defun gnus-execute-command (command &optional automatic)
11305   (save-excursion
11306     (gnus-article-setup-buffer)
11307     (set-buffer gnus-article-buffer)
11308     (setq buffer-read-only nil)
11309     (let ((command (if automatic command
11310                      (read-string "Command: " (cons command 0)))))
11311       (erase-buffer)
11312       (insert "$ " command "\n\n")
11313       (if gnus-view-pseudo-asynchronously
11314           (start-process "gnus-execute" (current-buffer) shell-file-name
11315                          shell-command-switch command)
11316         (call-process shell-file-name nil t nil
11317                       shell-command-switch command)))))
11318
11319 ;; Summary kill commands.
11320
11321 (defun gnus-summary-edit-global-kill (article)
11322   "Edit the \"global\" kill file."
11323   (interactive (list (gnus-summary-article-number)))
11324   (gnus-group-edit-global-kill article))
11325
11326 (defun gnus-summary-edit-local-kill ()
11327   "Edit a local kill file applied to the current newsgroup."
11328   (interactive)
11329   (setq gnus-current-headers (gnus-summary-article-header))
11330   (gnus-group-edit-local-kill
11331    (gnus-summary-article-number) gnus-newsgroup-name))
11332
11333 ;;; Header reading.
11334
11335 (defun gnus-read-header (id &optional header)
11336   "Read the headers of article ID and enter them into the Gnus system."
11337   (let ((group gnus-newsgroup-name)
11338         (gnus-override-method
11339          (or
11340           gnus-override-method
11341           (and (gnus-news-group-p gnus-newsgroup-name)
11342                (car (gnus-refer-article-methods)))))
11343         where)
11344     ;; First we check to see whether the header in question is already
11345     ;; fetched.
11346     (if (stringp id)
11347         ;; This is a Message-ID.
11348         (setq header (or header (gnus-id-to-header id)))
11349       ;; This is an article number.
11350       (setq header (or header (gnus-summary-article-header id))))
11351     (if (and header
11352              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11353         ;; We have found the header.
11354         header
11355       ;; We have to really fetch the header to this article.
11356       (save-excursion
11357         (set-buffer nntp-server-buffer)
11358         (when (setq where (gnus-request-head id group))
11359           (nnheader-fold-continuation-lines)
11360           (goto-char (point-max))
11361           (insert ".\n")
11362           (goto-char (point-min))
11363           (insert "211 ")
11364           (princ (cond
11365                   ((numberp id) id)
11366                   ((cdr where) (cdr where))
11367                   (header (mail-header-number header))
11368                   (t gnus-reffed-article-number))
11369                  (current-buffer))
11370           (insert " Article retrieved.\n"))
11371         (if (or (not where)
11372                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11373             ()                          ; Malformed head.
11374           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11375             (when (and (stringp id)
11376                        (not (string= (gnus-group-real-name group)
11377                                      (car where))))
11378               ;; If we fetched by Message-ID and the article came
11379               ;; from a different group, we fudge some bogus article
11380               ;; numbers for this article.
11381               (mail-header-set-number header gnus-reffed-article-number))
11382             (save-excursion
11383               (set-buffer gnus-summary-buffer)
11384               (decf gnus-reffed-article-number)
11385               (gnus-remove-header (mail-header-number header))
11386               (push header gnus-newsgroup-headers)
11387               (setq gnus-current-headers header)
11388               (push (mail-header-number header) gnus-newsgroup-limit)))
11389           header)))))
11390
11391 (defun gnus-remove-header (number)
11392   "Remove header NUMBER from `gnus-newsgroup-headers'."
11393   (if (and gnus-newsgroup-headers
11394            (= number (mail-header-number (car gnus-newsgroup-headers))))
11395       (pop gnus-newsgroup-headers)
11396     (let ((headers gnus-newsgroup-headers))
11397       (while (and (cdr headers)
11398                   (not (= number (mail-header-number (cadr headers)))))
11399         (pop headers))
11400       (when (cdr headers)
11401         (setcdr headers (cddr headers))))))
11402
11403 ;;;
11404 ;;; summary highlights
11405 ;;;
11406
11407 (defun gnus-highlight-selected-summary ()
11408   "Highlight selected article in summary buffer."
11409   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11410   (when gnus-summary-selected-face
11411     (save-excursion
11412       (let* ((beg (point-at-bol))
11413              (end (point-at-eol))
11414              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11415              (from (if (get-text-property beg gnus-mouse-face-prop)
11416                        beg
11417                      (or (next-single-property-change
11418                           beg gnus-mouse-face-prop nil end)
11419                          beg)))
11420              (to
11421               (if (= from end)
11422                   (- from 2)
11423                 (or (next-single-property-change
11424                      from gnus-mouse-face-prop nil end)
11425                     end))))
11426         ;; If no mouse-face prop on line we will have to = from = end,
11427         ;; so we highlight the entire line instead.
11428         (when (= (+ to 2) from)
11429           (setq from beg)
11430           (setq to end))
11431         (if gnus-newsgroup-selected-overlay
11432             ;; Move old overlay.
11433             (gnus-move-overlay
11434              gnus-newsgroup-selected-overlay from to (current-buffer))
11435           ;; Create new overlay.
11436           (gnus-overlay-put
11437            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11438            'face gnus-summary-selected-face))))))
11439
11440 (defvar gnus-summary-highlight-line-cached nil)
11441 (defvar gnus-summary-highlight-line-trigger nil)
11442
11443 (defun gnus-summary-highlight-line-0 ()
11444   (if (and (eq gnus-summary-highlight-line-trigger
11445                gnus-summary-highlight)
11446            gnus-summary-highlight-line-cached)
11447       gnus-summary-highlight-line-cached
11448     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11449           gnus-summary-highlight-line-cached
11450           (let* ((cond (list 'cond))
11451                  (c cond)
11452                  (list gnus-summary-highlight))
11453             (while list
11454               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11455                               nil))
11456               (setq c (cdr c)
11457                     list (cdr list)))
11458             (gnus-byte-compile (list 'lambda nil cond))))))
11459
11460 (defun gnus-summary-highlight-line ()
11461   "Highlight current line according to `gnus-summary-highlight'."
11462   (let* ((beg (point-at-bol))
11463          (article (or (gnus-summary-article-number) gnus-current-article))
11464          (score (or (cdr (assq article
11465                                gnus-newsgroup-scored))
11466                     gnus-summary-default-score 0))
11467          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11468          (inhibit-read-only t)
11469          (default gnus-summary-default-score)
11470          (default-high gnus-summary-default-high-score)
11471          (default-low gnus-summary-default-low-score)
11472          (uncached (and gnus-summary-use-undownloaded-faces
11473                         (memq article gnus-newsgroup-undownloaded)
11474                         (not (memq article gnus-newsgroup-cached)))))
11475     (let ((face (funcall (gnus-summary-highlight-line-0))))
11476       (unless (eq face (get-text-property beg 'face))
11477         (gnus-put-text-property-excluding-characters-with-faces
11478          beg (point-at-eol) 'face
11479          (setq face (if (boundp face) (symbol-value face) face)))
11480         (when gnus-summary-highlight-line-function
11481           (funcall gnus-summary-highlight-line-function article face))))))
11482
11483 (defun gnus-update-read-articles (group unread &optional compute)
11484   "Update the list of read articles in GROUP.
11485 UNREAD is a sorted list."
11486   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11487         (info (gnus-get-info group))
11488         (prev 1)
11489         read)
11490     (if (or (not info) (not active))
11491         ;; There is no info on this group if it was, in fact,
11492         ;; killed.  Gnus stores no information on killed groups, so
11493         ;; there's nothing to be done.
11494         ;; One could store the information somewhere temporarily,
11495         ;; perhaps...  Hmmm...
11496         ()
11497       ;; Remove any negative articles numbers.
11498       (while (and unread (< (car unread) 0))
11499         (setq unread (cdr unread)))
11500       ;; Remove any expired article numbers
11501       (while (and unread (< (car unread) (car active)))
11502         (setq unread (cdr unread)))
11503       ;; Compute the ranges of read articles by looking at the list of
11504       ;; unread articles.
11505       (while unread
11506         (when (/= (car unread) prev)
11507           (push (if (= prev (1- (car unread))) prev
11508                   (cons prev (1- (car unread))))
11509                 read))
11510         (setq prev (1+ (car unread)))
11511         (setq unread (cdr unread)))
11512       (when (<= prev (cdr active))
11513         (push (cons prev (cdr active)) read))
11514       (setq read (if (> (length read) 1) (nreverse read) read))
11515       (if compute
11516           read
11517         (save-excursion
11518           (let (setmarkundo)
11519             ;; Propagate the read marks to the backend.
11520             (when (gnus-check-backend-function 'request-set-mark group)
11521               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11522                     (add (gnus-remove-from-range read (gnus-info-read info))))
11523                 (when (or add del)
11524                   (unless (gnus-check-group group)
11525                     (error "Can't open server for %s" group))
11526                   (gnus-request-set-mark
11527                    group (delq nil (list (if add (list add 'add '(read)))
11528                                          (if del (list del 'del '(read))))))
11529                   (setq setmarkundo
11530                         `(gnus-request-set-mark
11531                           ,group
11532                           ',(delq nil (list
11533                                        (if del (list del 'add '(read)))
11534                                        (if add (list add 'del '(read))))))))))
11535             (set-buffer gnus-group-buffer)
11536             (gnus-undo-register
11537               `(progn
11538                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11539                  (gnus-info-set-read ',info ',(gnus-info-read info))
11540                  (gnus-get-unread-articles-in-group ',info
11541                                                     (gnus-active ,group))
11542                  (gnus-group-update-group ,group t)
11543                  ,setmarkundo))))
11544         ;; Enter this list into the group info.
11545         (gnus-info-set-read info read)
11546         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11547         (gnus-get-unread-articles-in-group info (gnus-active group))
11548         t))))
11549
11550 (defun gnus-offer-save-summaries ()
11551   "Offer to save all active summary buffers."
11552   (let (buffers)
11553     ;; Go through all buffers and find all summaries.
11554     (dolist (buffer (buffer-list))
11555       (when (and (setq buffer (buffer-name buffer))
11556                  (string-match "Summary" buffer)
11557                  (with-current-buffer buffer
11558                    ;; We check that this is, indeed, a summary buffer.
11559                    (and (eq major-mode 'gnus-summary-mode)
11560                         ;; Also make sure this isn't bogus.
11561                         gnus-newsgroup-prepared
11562                         ;; Also make sure that this isn't a
11563                         ;; dead summary buffer.
11564                         (not gnus-dead-summary-mode))))
11565         (push buffer buffers)))
11566     ;; Go through all these summary buffers and offer to save them.
11567     (when buffers
11568       (save-excursion
11569         (map-y-or-n-p
11570          "Update summary buffer %s? "
11571          (lambda (buf)
11572            (switch-to-buffer buf)
11573            (gnus-summary-exit))
11574          buffers)))))
11575
11576
11577 ;;; @ for mime-partial
11578 ;;;
11579
11580 (defun gnus-request-partial-message ()
11581   (save-excursion
11582     (let ((number (gnus-summary-article-number))
11583           (group gnus-newsgroup-name)
11584           (mother gnus-article-buffer))
11585       (set-buffer (get-buffer-create " *Partial Article*"))
11586       (erase-buffer)
11587       (setq mime-preview-buffer mother)
11588       (gnus-request-article-this-buffer number group)
11589       (mime-parse-buffer)
11590       )))
11591
11592 (autoload 'mime-combine-message/partial-pieces-automatically
11593   "mime-partial"
11594   "Internal method to combine message/partial messages automatically.")
11595
11596 (mime-add-condition
11597  'action '((type . message)(subtype . partial)
11598            (major-mode . gnus-original-article-mode)
11599            (method . mime-combine-message/partial-pieces-automatically)
11600            (summary-buffer-exp . gnus-summary-buffer)
11601            (request-partial-message-method . gnus-request-partial-message)
11602            ))
11603
11604
11605 ;;; @ for message/rfc822
11606 ;;;
11607
11608 (defun gnus-mime-extract-message/rfc822 (entity situation)
11609   "Burst a forwarded article."
11610   (save-excursion
11611     (set-buffer gnus-summary-buffer)
11612     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11613                                    gnus-newsgroup-name 'gnus-group-history))
11614            (gnus-group-marked (list group))
11615            article info)
11616       (with-temp-buffer
11617         (mime-insert-entity-content entity)
11618         (setq article (gnus-request-accept-article group)))
11619       (when (and (consp article)
11620                  (numberp (setq article (cdr article))))
11621         (setq info (gnus-get-info group))
11622         (gnus-info-set-read info
11623                             (gnus-remove-from-range (gnus-info-read info)
11624                                                     (list article)))
11625         (when (string-equal group gnus-newsgroup-name)
11626           (forward-line 1)
11627           (let (gnus-show-threads)
11628             (gnus-summary-goto-subject article t))
11629           (gnus-summary-clear-mark-forward 1))
11630         (set-buffer gnus-group-buffer)
11631         (gnus-group-get-new-news-this-group nil t)))))
11632
11633 (mime-add-condition
11634  'action '((type . message)(subtype . rfc822)
11635            (major-mode . gnus-original-article-mode)
11636            (method . gnus-mime-extract-message/rfc822)
11637            (mode . "extract")
11638            ))
11639
11640 (mime-add-condition
11641  'action '((type . message)(subtype . news)
11642            (major-mode . gnus-original-article-mode)
11643            (method . gnus-mime-extract-message/rfc822)
11644            (mode . "extract")
11645            ))
11646
11647 (defun gnus-mime-extract-multipart (entity situation)
11648   (let ((children (mime-entity-children entity))
11649         mime-acting-situation-to-override
11650         f)
11651     (while children
11652       (mime-play-entity (car children)
11653                         (cons (assq 'mode situation)
11654                               mime-acting-situation-to-override))
11655       (setq children (cdr children)))
11656     (if (setq f (cdr (assq 'after-method
11657                            mime-acting-situation-to-override)))
11658         (eval f)
11659       )))
11660
11661 (mime-add-condition
11662  'action '((type . multipart)
11663            (method . gnus-mime-extract-multipart)
11664            (mode . "extract")
11665            )
11666  'with-default)
11667
11668
11669 ;;; @ end
11670 ;;;
11671
11672 (defun gnus-summary-inherit-default-charset ()
11673   "Import `default-mime-charset' from summary buffer.
11674 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11675 of FLIM is used."
11676   (if (buffer-live-p gnus-summary-buffer)
11677       (let (d-m-c d-m-c-u)
11678         (with-current-buffer gnus-summary-buffer
11679           (setq d-m-c (if (local-variable-p 'default-mime-charset
11680                                             gnus-summary-buffer)
11681                           default-mime-charset
11682                         t)
11683                 ;; LIMIT
11684                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11685                                               gnus-summary-buffer)
11686                             (symbol-value 'default-mime-charset-unlimited)
11687                           t)))
11688         (if (eq t d-m-c)
11689             (kill-local-variable 'default-mime-charset)
11690           (set (make-local-variable 'default-mime-charset) d-m-c))
11691         (if (eq t d-m-c-u)
11692             (kill-local-variable 'default-mime-charset-unlimited)
11693           (set (make-local-variable 'default-mime-charset-unlimited)
11694                d-m-c-u)))))
11695
11696 (defun gnus-summary-setup-default-charset ()
11697   "Setup newsgroup default charset."
11698   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11699       (progn
11700         (setq gnus-newsgroup-charset nil)
11701         (set (make-local-variable 'default-mime-charset) nil)
11702         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11703           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11704     (let ((ignored-charsets
11705            (or gnus-newsgroup-ephemeral-ignored-charsets
11706                (append
11707                 (and gnus-newsgroup-name
11708                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11709                 gnus-newsgroup-ignored-charsets)))
11710           charset)
11711       (setq gnus-newsgroup-charset
11712             (or gnus-newsgroup-ephemeral-charset
11713                 (when (and gnus-newsgroup-name
11714                            (setq charset (gnus-parameter-charset
11715                                           gnus-newsgroup-name)))
11716                   (make-local-variable 'default-mime-charset)
11717                   (setq default-mime-charset charset))
11718                 gnus-default-charset))
11719       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11720            ignored-charsets))))
11721
11722 ;;;
11723 ;;; Mime Commands
11724 ;;;
11725
11726 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11727   "Display the current article buffer fully MIME-buttonized.
11728 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11729 treated as multipart/mixed."
11730   (interactive "P")
11731   (require 'gnus-art)
11732   (let ((gnus-unbuttonized-mime-types nil)
11733         (gnus-mime-display-multipart-as-mixed show-all-parts))
11734     (gnus-summary-show-article)))
11735
11736 (defun gnus-summary-repair-multipart (article)
11737   "Add a Content-Type header to a multipart article without one."
11738   (interactive (list (gnus-summary-article-number)))
11739   (gnus-with-article article
11740     (message-narrow-to-head)
11741     (message-remove-header "Mime-Version")
11742     (goto-char (point-max))
11743     (insert "Mime-Version: 1.0\n")
11744     (widen)
11745     (when (search-forward "\n--" nil t)
11746       (let ((separator (buffer-substring (point) (point-at-eol))))
11747         (message-narrow-to-head)
11748         (message-remove-header "Content-Type")
11749         (goto-char (point-max))
11750         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11751                         separator))
11752         (widen))))
11753   (let (gnus-mark-article-hook)
11754     (gnus-summary-select-article t t nil article)))
11755
11756 (defun gnus-summary-toggle-display-buttonized ()
11757   "Toggle the buttonizing of the article buffer."
11758   (interactive)
11759   (require 'gnus-art)
11760   (if (setq gnus-inhibit-mime-unbuttonizing
11761             (not gnus-inhibit-mime-unbuttonizing))
11762       (let ((gnus-unbuttonized-mime-types nil))
11763         (gnus-summary-show-article))
11764     (gnus-summary-show-article)))
11765
11766 ;;;
11767 ;;; Intelli-mouse commmands
11768 ;;;
11769
11770 (defun gnus-wheel-summary-scroll (event)
11771   (interactive "e")
11772   (let ((amount (if (memq 'shift (event-modifiers event))
11773                     (car gnus-wheel-scroll-amount)
11774                   (cdr gnus-wheel-scroll-amount)))
11775         (direction (- (* (static-if (featurep 'xemacs)
11776                              (event-button event)
11777                            (cond ((eq 'mouse-4 (event-basic-type event))
11778                                   4)
11779                                  ((eq 'mouse-5 (event-basic-type event))
11780                                   5)))
11781                          2) 9))
11782         edge)
11783     (gnus-summary-scroll-up (* amount direction))
11784     (when (gnus-eval-in-buffer-window gnus-article-buffer
11785             (save-restriction
11786               (widen)
11787               (and (if (< 0 direction)
11788                        (gnus-article-next-page 0)
11789                      (gnus-article-prev-page 0)
11790                      (bobp))
11791                    (if (setq edge (get-text-property
11792                                    (point-min) 'gnus-wheel-edge))
11793                        (setq edge (* edge direction))
11794                      (setq edge -1))
11795                    (or (plusp edge)
11796                        (let ((buffer-read-only nil)
11797                              (inhibit-read-only t))
11798                          (put-text-property (point-min) (point-max)
11799                                             'gnus-wheel-edge direction)
11800                          nil))
11801                    (or (> edge gnus-wheel-edge-resistance)
11802                        (let ((buffer-read-only nil)
11803                              (inhibit-read-only t))
11804                          (put-text-property (point-min) (point-max)
11805                                             'gnus-wheel-edge
11806                                             (* (1+ edge) direction))
11807                          nil))
11808                    (eq last-command 'gnus-wheel-summary-scroll))))
11809       (gnus-summary-next-article nil nil (minusp direction)))))
11810
11811 (defun gnus-wheel-install ()
11812   "Enable mouse wheel support on summary window."
11813   (when gnus-use-wheel
11814     (let ((keys
11815            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11816       (dolist (key keys)
11817         (define-key gnus-summary-mode-map key
11818           'gnus-wheel-summary-scroll)))))
11819
11820 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11821
11822 ;;;
11823 ;;; Traditional PGP commmands
11824 ;;;
11825
11826 (defun gnus-summary-decrypt-article (&optional force)
11827   "Decrypt the current article in traditional PGP way.
11828 This will have permanent effect only in mail groups.
11829 If FORCE is non-nil, allow editing of articles even in read-only
11830 groups."
11831   (interactive "P")
11832   (gnus-summary-select-article t)
11833   (gnus-eval-in-buffer-window gnus-article-buffer
11834     (save-excursion
11835       (save-restriction
11836         (widen)
11837         (goto-char (point-min))
11838         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11839           (error "Not a traditional PGP message!"))
11840         (let ((armor-start (match-beginning 0)))
11841           (if (and (pgg-decrypt-region armor-start (point-max))
11842                    (or force (not (gnus-group-read-only-p))))
11843               (let ((inhibit-read-only t)
11844                     buffer-read-only)
11845                 (delete-region armor-start
11846                                (progn
11847                                  (re-search-forward "^-+END PGP" nil t)
11848                                  (beginning-of-line 2)
11849                                  (point)))
11850                 (insert-buffer-substring pgg-output-buffer))))))))
11851
11852 (defun gnus-summary-verify-article ()
11853   "Verify the current article in traditional PGP way."
11854   (interactive)
11855   (save-excursion
11856     (set-buffer gnus-original-article-buffer)
11857     (goto-char (point-min))
11858     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11859       (error "Not a traditional PGP message!"))
11860     (re-search-forward "^-+END PGP" nil t)
11861     (beginning-of-line 2)
11862     (call-interactively (function pgg-verify-region))))
11863
11864 ;;;
11865 ;;; Generic summary marking commands
11866 ;;;
11867
11868 (defvar gnus-summary-marking-alist
11869   '((read gnus-del-mark "d")
11870     (unread gnus-unread-mark "u")
11871     (ticked gnus-ticked-mark "!")
11872     (dormant gnus-dormant-mark "?")
11873     (expirable gnus-expirable-mark "e"))
11874   "An alist of names/marks/keystrokes.")
11875
11876 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11877 (defvar gnus-summary-mark-map)
11878
11879 (defun gnus-summary-make-all-marking-commands ()
11880   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11881   (dolist (elem gnus-summary-marking-alist)
11882     (apply 'gnus-summary-make-marking-command elem)))
11883
11884 (defun gnus-summary-make-marking-command (name mark keystroke)
11885   (let ((map (make-sparse-keymap)))
11886     (define-key gnus-summary-generic-mark-map keystroke map)
11887     (dolist (lway `((next "next" next nil "n")
11888                     (next-unread "next unread" next t "N")
11889                     (prev "previous" prev nil "p")
11890                     (prev-unread "previous unread" prev t "P")
11891                     (nomove "" nil nil ,keystroke)))
11892       (let ((func (gnus-summary-make-marking-command-1
11893                    mark (car lway) lway name)))
11894         (setq func (eval func))
11895         (define-key map (nth 4 lway) func)))))
11896
11897 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11898   `(defun ,(intern
11899             (format "gnus-summary-put-mark-as-%s%s"
11900                     name (if (eq way 'nomove)
11901                              ""
11902                            (concat "-" (symbol-name way)))))
11903      (n)
11904      ,(format
11905        "Mark the current article as %s%s.
11906 If N, the prefix, then repeat N times.
11907 If N is negative, move in reverse order.
11908 The difference between N and the actual number of articles marked is
11909 returned."
11910        name (car (cdr lway)))
11911      (interactive "p")
11912      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11913
11914 (defun gnus-summary-generic-mark (n mark move unread)
11915   "Mark N articles with MARK."
11916   (unless (eq major-mode 'gnus-summary-mode)
11917     (error "This command can only be used in the summary buffer"))
11918   (gnus-summary-show-thread)
11919   (let ((nummove
11920          (cond
11921           ((eq move 'next) 1)
11922           ((eq move 'prev) -1)
11923           (t 0))))
11924     (if (zerop nummove)
11925         (setq n 1)
11926       (when (< n 0)
11927         (setq n (abs n)
11928               nummove (* -1 nummove))))
11929     (while (and (> n 0)
11930                 (gnus-summary-mark-article nil mark)
11931                 (zerop (gnus-summary-next-subject nummove unread t)))
11932       (setq n (1- n)))
11933     (when (/= 0 n)
11934       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11935     (gnus-summary-recenter)
11936     (gnus-summary-position-point)
11937     (gnus-set-mode-line 'summary)
11938     n))
11939
11940 (defun gnus-summary-insert-articles (articles)
11941   (when (setq articles
11942               (gnus-sorted-difference articles
11943                                       (mapcar (lambda (h)
11944                                                 (mail-header-number h))
11945                                               gnus-newsgroup-headers)))
11946     (setq gnus-newsgroup-headers
11947           (gnus-merge 'list
11948                       gnus-newsgroup-headers
11949                       (gnus-fetch-headers articles)
11950                       'gnus-article-sort-by-number))
11951     ;; Suppress duplicates?
11952     (when gnus-suppress-duplicates
11953       (gnus-dup-suppress-articles))
11954
11955     ;; We might want to build some more threads first.
11956     (when (and gnus-fetch-old-headers
11957                (eq gnus-headers-retrieved-by 'nov))
11958       (if (eq gnus-fetch-old-headers 'invisible)
11959           (gnus-build-all-threads)
11960         (gnus-build-old-threads)))
11961     ;; Let the Gnus agent mark articles as read.
11962     (when gnus-agent
11963       (gnus-agent-get-undownloaded-list))
11964     ;; Remove list identifiers from subject
11965     (when gnus-list-identifiers
11966       (gnus-summary-remove-list-identifiers))
11967     ;; First and last article in this newsgroup.
11968     (when gnus-newsgroup-headers
11969       (setq gnus-newsgroup-begin
11970             (mail-header-number (car gnus-newsgroup-headers))
11971             gnus-newsgroup-end
11972             (mail-header-number
11973              (gnus-last-element gnus-newsgroup-headers))))
11974     (when gnus-use-scoring
11975       (gnus-possibly-score-headers))))
11976
11977 (defun gnus-summary-insert-old-articles (&optional all)
11978   "Insert all old articles in this group.
11979 If ALL is non-nil, already read articles become readable.
11980 If ALL is a number, fetch this number of articles."
11981   (interactive "P")
11982   (prog1
11983       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11984             older len)
11985         (setq older
11986               ;; Some nntp servers lie about their active range.  When
11987               ;; this happens, the active range can be in the millions.
11988               ;; Use a compressed range to avoid creating a huge list.
11989               (gnus-range-difference (list gnus-newsgroup-active) old))
11990         (setq len (gnus-range-length older))
11991         (cond
11992          ((null older) nil)
11993          ((numberp all)
11994           (if (< all len)
11995               (let ((older-range (nreverse older)))
11996                 (setq older nil)
11997
11998                 (while (> all 0)
11999                   (let* ((r (pop older-range))
12000                          (min (if (numberp r) r (car r)))
12001                          (max (if (numberp r) r (cdr r))))
12002                     (while (and (<= min max)
12003                                 (> all 0))
12004                       (push max older)
12005                       (setq all (1- all)
12006                             max (1- max))))))
12007             (setq older (gnus-uncompress-range older))))
12008          (all
12009           (setq older (gnus-uncompress-range older)))
12010          (t
12011           (when (and (numberp gnus-large-newsgroup)
12012                    (> len gnus-large-newsgroup))
12013               (let* ((cursor-in-echo-area nil)
12014                      (initial (gnus-parameter-large-newsgroup-initial
12015                                gnus-newsgroup-name))
12016                      (input
12017                       (read-string
12018                        (format
12019                         "How many articles from %s (%s %d): "
12020                         (gnus-limit-string
12021                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12022                         (if initial "max" "default")
12023                         len)
12024                        (if initial
12025                            (cons (number-to-string initial)
12026                                  0)))))
12027                 (unless (string-match "^[ \t]*$" input)
12028                   (setq all (string-to-number input))
12029                   (if (< all len)
12030                       (let ((older-range (nreverse older)))
12031                         (setq older nil)
12032
12033                         (while (> all 0)
12034                           (let* ((r (pop older-range))
12035                                  (min (if (numberp r) r (car r)))
12036                                  (max (if (numberp r) r (cdr r))))
12037                             (while (and (<= min max)
12038                                         (> all 0))
12039                               (push max older)
12040                               (setq all (1- all)
12041                                     max (1- max))))))))))
12042           (setq older (gnus-uncompress-range older))))
12043         (if (not older)
12044             (message "No old news.")
12045           (gnus-summary-insert-articles older)
12046           (gnus-summary-limit (gnus-sorted-nunion old older))))
12047     (gnus-summary-position-point)))
12048
12049 (defun gnus-summary-insert-new-articles ()
12050   "Insert all new articles in this group."
12051   (interactive)
12052   (prog1
12053       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12054             (old-active gnus-newsgroup-active)
12055             (nnmail-fetched-sources (list t))
12056             i new)
12057         (setq gnus-newsgroup-active
12058               (gnus-activate-group gnus-newsgroup-name 'scan))
12059         (setq i (cdr gnus-newsgroup-active))
12060         (while (> i (cdr old-active))
12061           (push i new)
12062           (decf i))
12063         (if (not new)
12064             (message "No gnus is bad news")
12065           (gnus-summary-insert-articles new)
12066           (setq gnus-newsgroup-unreads
12067                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12068           (gnus-summary-limit (gnus-sorted-nunion old new))))
12069     (gnus-summary-position-point)))
12070
12071 (gnus-summary-make-all-marking-commands)
12072
12073 (gnus-ems-redefine)
12074
12075 (provide 'gnus-sum)
12076
12077 (run-hooks 'gnus-sum-load-hook)
12078
12079 ;; Local Variables:
12080 ;; coding: iso-8859-1
12081 ;; End:
12082
12083 ;;; gnus-sum.el ends here