Synch to No Gnus 200511091726.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
9 ;; Keywords: mail, news, MIME
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;;; Code:
31
32 (eval-when-compile
33   (require 'cl)
34   (defvar tool-bar-map))
35
36 (require 'gnus)
37 (require 'gnus-group)
38 (require 'gnus-spec)
39 (require 'gnus-range)
40 (require 'gnus-int)
41 (require 'gnus-undo)
42 (require 'gnus-util)
43 (require 'nnoo)
44
45 (eval-when-compile
46   (require 'mime-play)
47   (require 'static))
48
49 (eval-and-compile
50   (autoload 'pgg-decrypt-region "pgg" nil t)
51   (autoload 'pgg-verify-region "pgg" nil t))
52
53 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
54 (autoload 'gnus-cache-write-active "gnus-cache")
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
58 (autoload 'mm-uu-dissect "mm-uu")
59 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
60   "Deuglify broken Outlook (Express) articles and redisplay."
61   t)
62 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
63 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
64 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
65
66 (defcustom gnus-kill-summary-on-exit t
67   "*If non-nil, kill the summary buffer when you exit from it.
68 If nil, the summary will become a \"*Dead Summary*\" buffer, and
69 it will be killed sometime later."
70   :group 'gnus-summary-exit
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already read (or
76 just marked as read) article, the old article will not normally be
77 displayed in the Summary buffer.  If this variable is t, Gnus
78 will attempt to grab the headers to the old articles, and thereby
79 build complete threads.  If it has the value `some', only enough
80 headers to connect otherwise loose threads will be displayed.  This
81 variable can also be a number.  In that case, no more than that number
82 of old headers will be fetched.  If it has the value `invisible', all
83 old headers will be fetched, but none will be displayed.
84
85 The server has to support NOV for any of this to work."
86   :group 'gnus-thread
87   :type '(choice (const :tag "off" nil)
88                  (const :tag "on" t)
89                  (const some)
90                  (const invisible)
91                  number
92                  (sexp :menu-tag "other" t)))
93
94 (defcustom gnus-refer-thread-limit 200
95   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
96 If t, fetch all the available old headers."
97   :group 'gnus-thread
98   :type '(choice number
99                  (sexp :menu-tag "other" t)))
100
101 (defcustom gnus-summary-make-false-root 'adopt
102   "*nil means that Gnus won't gather loose threads.
103 If the root of a thread has expired or been read in a previous
104 session, the information necessary to build a complete thread has been
105 lost.  Instead of having many small sub-threads from this original thread
106 scattered all over the summary buffer, Gnus can gather them.
107
108 If non-nil, Gnus will try to gather all loose sub-threads from an
109 original thread into one large thread.
110
111 If this variable is non-nil, it should be one of `none', `adopt',
112 `dummy' or `empty'.
113
114 If this variable is `none', Gnus will not make a false root, but just
115 present the sub-threads after another.
116 If this variable is `dummy', Gnus will create a dummy root that will
117 have all the sub-threads as children.
118 If this variable is `adopt', Gnus will make one of the \"children\"
119 the parent and mark all the step-children as such.
120 If this variable is `empty', the \"children\" are printed with empty
121 subject fields.  (Or rather, they will be printed with a string
122 given by the `gnus-summary-same-subject' variable.)"
123   :group 'gnus-thread
124   :type '(choice (const :tag "off" nil)
125                  (const none)
126                  (const dummy)
127                  (const adopt)
128                  (const empty)))
129
130 (defcustom gnus-summary-make-false-root-always nil
131   "Always make a false dummy root."
132   :version "22.1"
133   :group 'gnus-thread
134   :type 'boolean)
135
136 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
137   "*A regexp to match subjects to be excluded from loose thread gathering.
138 As loose thread gathering is done on subjects only, that means that
139 there can be many false gatherings performed.  By rooting out certain
140 common subjects, gathering might become saner."
141   :group 'gnus-thread
142   :type 'regexp)
143
144 (defcustom gnus-summary-gather-subject-limit nil
145   "*Maximum length of subject comparisons when gathering loose threads.
146 Use nil to compare full subjects.  Setting this variable to a low
147 number will help gather threads that have been corrupted by
148 newsreaders chopping off subject lines, but it might also mean that
149 unrelated articles that have subject that happen to begin with the
150 same few characters will be incorrectly gathered.
151
152 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
153 comparing subjects."
154   :group 'gnus-thread
155   :type '(choice (const :tag "off" nil)
156                  (const fuzzy)
157                  (sexp :menu-tag "on" t)))
158
159 (defcustom gnus-simplify-subject-functions nil
160   "List of functions taking a string argument that simplify subjects.
161 The functions are applied recursively.
162
163 Useful functions to put in this list include:
164 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
165 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
166   :group 'gnus-thread
167   :type '(repeat function))
168
169 (defcustom gnus-simplify-ignored-prefixes nil
170   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
171   :group 'gnus-thread
172   :type '(choice (const :tag "off" nil)
173                  regexp))
174
175 (defcustom gnus-build-sparse-threads nil
176   "*If non-nil, fill in the gaps in threads.
177 If `some', only fill in the gaps that are needed to tie loose threads
178 together.  If `more', fill in all leaf nodes that Gnus can find.  If
179 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
180   :group 'gnus-thread
181   :type '(choice (const :tag "off" nil)
182                  (const some)
183                  (const more)
184                  (sexp :menu-tag "all" t)))
185
186 (defcustom gnus-summary-thread-gathering-function
187   'gnus-gather-threads-by-subject
188   "*Function used for gathering loose threads.
189 There are two pre-defined functions: `gnus-gather-threads-by-subject',
190 which only takes Subjects into consideration; and
191 `gnus-gather-threads-by-references', which compared the References
192 headers of the articles to find matches."
193   :group 'gnus-thread
194   :type '(radio (function-item gnus-gather-threads-by-subject)
195                 (function-item gnus-gather-threads-by-references)
196                 (function :tag "other")))
197
198 (defcustom gnus-summary-same-subject ""
199   "*String indicating that the current article has the same subject as the previous.
200 This variable will only be used if the value of
201 `gnus-summary-make-false-root' is `empty'."
202   :group 'gnus-summary-format
203   :type 'string)
204
205 (defcustom gnus-summary-goto-unread t
206   "*If t, many commands will go to the next unread article.
207 This applies to marking commands as well as other commands that
208 \"naturally\" select the next article, like, for instance, `SPC' at
209 the end of an article.
210
211 If nil, the marking commands do NOT go to the next unread article
212 \(they go to the next article instead).  If `never', commands that
213 usually go to the next unread article, will go to the next article,
214 whether it is read or not."
215   :group 'gnus-summary-marks
216   :link '(custom-manual "(gnus)Setting Marks")
217   :type '(choice (const :tag "off" nil)
218                  (const never)
219                  (sexp :menu-tag "on" t)))
220
221 (defcustom gnus-summary-default-score 0
222   "*Default article score level.
223 All scores generated by the score files will be added to this score.
224 If this variable is nil, scoring will be disabled."
225   :group 'gnus-score-default
226   :type '(choice (const :tag "disable")
227                  integer))
228
229 (defcustom gnus-summary-default-high-score 0
230   "*Default threshold for a high scored article.
231 An article will be highlighted as high scored if its score is greater
232 than this score."
233   :version "22.1"
234   :group 'gnus-score-default
235   :type 'integer)
236
237 (defcustom gnus-summary-default-low-score 0
238   "*Default threshold for a low scored article.
239 An article will be highlighted as low scored if its score is smaller
240 than this score."
241   :version "22.1"
242   :group 'gnus-score-default
243   :type 'integer)
244
245 (defcustom gnus-summary-zcore-fuzz 0
246   "*Fuzziness factor for the zcore in the summary buffer.
247 Articles with scores closer than this to `gnus-summary-default-score'
248 will not be marked."
249   :group 'gnus-summary-format
250   :type 'integer)
251
252 (defcustom gnus-simplify-subject-fuzzy-regexp nil
253   "*Strings to be removed when doing fuzzy matches.
254 This can either be a regular expression or list of regular expressions
255 that will be removed from subject strings if fuzzy subject
256 simplification is selected."
257   :group 'gnus-thread
258   :type '(repeat regexp))
259
260 (defcustom gnus-show-threads t
261   "*If non-nil, display threads in summary mode."
262   :group 'gnus-thread
263   :type 'boolean)
264
265 (defcustom gnus-thread-hide-subtree nil
266   "*If non-nil, hide all threads initially.
267 This can be a predicate specifier which says which threads to hide.
268 If threads are hidden, you have to run the command
269 `gnus-summary-show-thread' by hand or or select an article."
270   :group 'gnus-thread
271   :type '(radio (sexp :format "Non-nil\n"
272                       :match (lambda (widget value)
273                                (not (or (consp value) (functionp value))))
274                       :value t)
275                 (const nil)
276                 (sexp :tag "Predicate specifier")))
277
278 (defcustom gnus-thread-hide-killed t
279   "*If non-nil, hide killed threads automatically."
280   :group 'gnus-thread
281   :type 'boolean)
282
283 (defcustom gnus-thread-ignore-subject t
284   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
285 If nil, articles that have different subjects from their parents will
286 start separate threads."
287   :group 'gnus-thread
288   :type 'boolean)
289
290 (defcustom gnus-thread-operation-ignore-subject t
291   "*If non-nil, subjects will be ignored when doing thread commands.
292 This affects commands like `gnus-summary-kill-thread' and
293 `gnus-summary-lower-thread'.
294
295 If this variable is nil, articles in the same thread with different
296 subjects will not be included in the operation in question.  If this
297 variable is `fuzzy', only articles that have subjects that are fuzzily
298 equal will be included."
299   :group 'gnus-thread
300   :type '(choice (const :tag "off" nil)
301                  (const fuzzy)
302                  (sexp :tag "on" t)))
303
304 (defcustom gnus-thread-indent-level 4
305   "*Number that says how much each sub-thread should be indented."
306   :group 'gnus-thread
307   :type 'integer)
308
309 (defcustom gnus-auto-extend-newsgroup t
310   "*If non-nil, extend newsgroup forward and backward when requested."
311   :group 'gnus-summary-choose
312   :type 'boolean)
313
314 (defcustom gnus-auto-select-first t
315   "*If non-nil, select the article under point.
316 Which article this is is controlled by the `gnus-auto-select-subject'
317 variable.
318
319 If you want to prevent automatic selection of articles in some
320 newsgroups, set the variable to nil in `gnus-select-group-hook'."
321   :group 'gnus-group-select
322   :type '(choice (const :tag "none" nil)
323                  (sexp :menu-tag "first" t)))
324
325 (defcustom gnus-auto-select-subject 'unread
326   "*Says what subject to place under point when entering a group.
327
328 This variable can either be the symbols `first' (place point on the
329 first subject), `unread' (place point on the subject line of the first
330 unread article), `best' (place point on the subject line of the
331 higest-scored article), `unseen' (place point on the subject line of
332 the first unseen article), `unseen-or-unread' (place point on the subject
333 line of the first unseen article or, if all article have been seen, on the
334 subject line of the first unread article), or a function to be called to
335 place point on some subject line."
336   :version "22.1"
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 "22.1"
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "None" nil)
391                  (const :tag "Undownloaded when unplugged" undownloaded)
392                  (const :tag "Undownloaded" always-undownloaded)
393                  (const :tag "Unfetched" unfetched)))
394
395 (defcustom gnus-summary-check-current nil
396   "*If non-nil, consider the current article when moving.
397 The \"unread\" movement commands will stay on the same line if the
398 current article is unread."
399   :group 'gnus-summary-maneuvering
400   :type 'boolean)
401
402 (defcustom gnus-auto-center-summary 2
403   "*If non-nil, always center the current summary buffer.
404 In particular, if `vertical' do only vertical recentering.  If non-nil
405 and non-`vertical', do both horizontal and vertical recentering."
406   :group 'gnus-summary-maneuvering
407   :type '(choice (const :tag "none" nil)
408                  (const vertical)
409                  (integer :tag "height")
410                  (sexp :menu-tag "both" t)))
411
412 (defvar gnus-auto-center-group t
413   "*If non-nil, always center the group buffer.")
414
415 (defcustom gnus-show-all-headers nil
416   "*If non-nil, don't hide any headers."
417   :group 'gnus-article-hiding
418   :group 'gnus-article-headers
419   :type 'boolean)
420
421 (defcustom gnus-summary-ignore-duplicates nil
422   "*If non-nil, ignore articles with identical Message-ID headers."
423   :group 'gnus-summary
424   :type 'boolean)
425
426 (defcustom gnus-single-article-buffer t
427   "*If non-nil, display all articles in the same buffer.
428 If nil, each group will get its own article buffer."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-break-pages t
433   "*If non-nil, do page breaking on articles.
434 The page delimiter is specified by the `gnus-page-delimiter'
435 variable."
436   :group 'gnus-article-various
437   :type 'boolean)
438
439 (defcustom gnus-show-mime t
440   "*If non-nil, do mime processing of articles.
441 The articles will simply be fed to the function given by
442 `gnus-article-display-method-for-mime'."
443   :group 'gnus-article-mime
444   :type 'boolean)
445
446 (defcustom gnus-move-split-methods nil
447   "*Variable used to suggest where articles are to be moved to.
448 It uses the same syntax as the `gnus-split-methods' variable.
449 However, whereas `gnus-split-methods' specifies file names as targets,
450 this variable specifies group names."
451   :group 'gnus-summary-mail
452   :type '(repeat (choice (list :value (fun) function)
453                          (cons :value ("" "") regexp (repeat string))
454                          (sexp :value nil))))
455
456 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
457   "Function used to compute default prefix for article move/copy/etc prompts.
458 The function should take one argument, a group name, and return a
459 string with the suggested prefix."
460   :group 'gnus-summary-mail
461   :type 'function)
462
463 ;; FIXME: Although the custom type is `character' for the following variables,
464 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
465
466 (defcustom gnus-unread-mark ?\ ;;;Whitespace
467   "*Mark used for unread articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ticked-mark ?!
472   "*Mark used for ticked articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-dormant-mark ??
477   "*Mark used for dormant articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-del-mark ?r
482   "*Mark used for del'd articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-read-mark ?R
487   "*Mark used for read articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-expirable-mark ?E
492   "*Mark used for expirable articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-killed-mark ?K
497   "*Mark used for killed articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-spam-mark ?$
502   "*Mark used for spam articles."
503   :version "22.1"
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-souped-mark ?F
508   "*Mark used for souped articles."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-kill-file-mark ?X
513   "*Mark used for articles killed by kill files."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-low-score-mark ?Y
518   "*Mark used for articles with a low score."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-catchup-mark ?C
523   "*Mark used for articles that are caught up."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-replied-mark ?A
528   "*Mark used for articles that have been replied to."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-forwarded-mark ?F
533   "*Mark used for articles that have been forwarded."
534   :version "22.1"
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-recent-mark ?N
539   "*Mark used for articles that are recent."
540   :version "22.1"
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-cached-mark ?*
545   "*Mark used for articles that are in the cache."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-saved-mark ?S
550   "*Mark used for articles that have been saved."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-unseen-mark ?.
555   "*Mark used for articles that haven't been seen."
556   :version "22.1"
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-no-mark ?\ ;;;Whitespace
561   "*Mark used for articles that have no other secondary mark."
562   :version "22.1"
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-ancient-mark ?O
567   "*Mark used for ancient articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-sparse-mark ?Q
572   "*Mark used for sparsely reffed articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-canceled-mark ?G
577   "*Mark used for canceled articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-duplicate-mark ?M
582   "*Mark used for duplicate articles."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-undownloaded-mark ?-
587   "*Mark used for articles that weren't downloaded."
588   :version "22.1"
589   :group 'gnus-summary-marks
590   :type 'character)
591
592 (defcustom gnus-downloaded-mark ?+
593   "*Mark used for articles that were downloaded."
594   :group 'gnus-summary-marks
595   :type 'character)
596
597 (defcustom gnus-downloadable-mark ?%
598   "*Mark used for articles that are to be downloaded."
599   :group 'gnus-summary-marks
600   :type 'character)
601
602 (defcustom gnus-unsendable-mark ?=
603   "*Mark used for articles that won't be sent."
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-score-over-mark ?+
608   "*Score mark used for articles with high scores."
609   :group 'gnus-summary-marks
610   :type 'character)
611
612 (defcustom gnus-score-below-mark ?-
613   "*Score mark used for articles with low scores."
614   :group 'gnus-summary-marks
615   :type 'character)
616
617 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
618   "*There is no thread under the article."
619   :group 'gnus-summary-marks
620   :type 'character)
621
622 (defcustom gnus-not-empty-thread-mark ?=
623   "*There is a thread under the article."
624   :group 'gnus-summary-marks
625   :type 'character)
626
627 (defcustom gnus-view-pseudo-asynchronously nil
628   "*If non-nil, Gnus will view pseudo-articles asynchronously."
629   :group 'gnus-extract-view
630   :type 'boolean)
631
632 (defcustom gnus-auto-expirable-marks
633   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
634         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
635         gnus-souped-mark gnus-duplicate-mark)
636   "*The list of marks converted into expiration if a group is auto-expirable."
637   :version "21.1"
638   :group 'gnus-summary
639   :type '(repeat character))
640
641 (defcustom gnus-inhibit-user-auto-expire t
642   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
643   :version "21.1"
644   :group 'gnus-summary
645   :type 'boolean)
646
647 (defcustom gnus-view-pseudos nil
648   "*If `automatic', pseudo-articles will be viewed automatically.
649 If `not-confirm', pseudos will be viewed automatically, and the user
650 will not be asked to confirm the command."
651   :group 'gnus-extract-view
652   :type '(choice (const :tag "off" nil)
653                  (const automatic)
654                  (const not-confirm)))
655
656 (defcustom gnus-view-pseudos-separately t
657   "*If non-nil, one pseudo-article will be created for each file to be viewed.
658 If nil, all files that use the same viewing command will be given as a
659 list of parameters to that command."
660   :group 'gnus-extract-view
661   :type 'boolean)
662
663 (defcustom gnus-insert-pseudo-articles t
664   "*If non-nil, insert pseudo-articles when decoding articles."
665   :group 'gnus-extract-view
666   :type 'boolean)
667
668 (defcustom gnus-summary-dummy-line-format
669   "   %(:                             :%) %S\n"
670   "*The format specification for the dummy roots in the summary buffer.
671 It works along the same lines as a normal formatting string,
672 with some simple extensions.
673
674 %S  The subject
675
676 General format specifiers can also be used.
677 See `(gnus)Formatting Variables'."
678   :link '(custom-manual "(gnus)Formatting Variables")
679   :group 'gnus-threading
680   :type 'string)
681
682 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
683   "*The format specification for the summary mode line.
684 It works along the same lines as a normal formatting string,
685 with some simple extensions:
686
687 %G  Group name
688 %p  Unprefixed group name
689 %A  Current article number
690 %z  Current article score
691 %V  Gnus version
692 %U  Number of unread articles in the group
693 %e  Number of unselected articles in the group
694 %Z  A string with unread/unselected article counts
695 %g  Shortish group name
696 %S  Subject of the current article
697 %u  User-defined spec
698 %s  Current score file name
699 %d  Number of dormant articles
700 %r  Number of articles that have been marked as read in this session
701 %E  Number of articles expunged by the score files"
702   :group 'gnus-summary-format
703   :type 'string)
704
705 (defcustom gnus-list-identifiers nil
706   "Regexp that matches list identifiers to be removed from subject.
707 This can also be a list of regexps."
708   :version "21.1"
709   :group 'gnus-summary-format
710   :group 'gnus-article-hiding
711   :type '(choice (const :tag "none" nil)
712                  (regexp :value ".*")
713                  (repeat :value (".*") regexp)))
714
715 (defcustom gnus-summary-mark-below 0
716   "*Mark all articles with a score below this variable as read.
717 This variable is local to each summary buffer and usually set by the
718 score file."
719   :group 'gnus-score-default
720   :type 'integer)
721
722 (defun gnus-widget-reversible-match (widget value)
723   "Ignoring WIDGET, convert VALUE to internal form.
724 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
725   ;; (debug value)
726   (or (symbolp value)
727       (and (listp value)
728            (eq (length value) 2)
729            (eq (nth 0 value) 'not)
730            (symbolp (nth 1 value)))))
731
732 (defun gnus-widget-reversible-to-internal (widget value)
733   "Ignoring WIDGET, convert VALUE to internal form.
734 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
735 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
736   ;; (debug value)
737   (if (atom value)
738       (list value nil)
739     (list (nth 1 value) t)))
740
741 (defun gnus-widget-reversible-to-external (widget value)
742   "Ignoring WIDGET, convert VALUE to external form.
743 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
744 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
745   ;; (debug value)
746   (if (nth 1 value)
747       (list 'not (nth 0 value))
748     (nth 0 value)))
749
750 (define-widget 'gnus-widget-reversible 'group
751   "A `group' that convert values."
752   :match 'gnus-widget-reversible-match
753   :value-to-internal 'gnus-widget-reversible-to-internal
754   :value-to-external 'gnus-widget-reversible-to-external)
755
756 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
757   "*List of functions used for sorting articles in the summary buffer.
758
759 Each function takes two articles and returns non-nil if the first
760 article should be sorted before the other.  If you use more than one
761 function, the primary sort function should be the last.  You should
762 probably always include `gnus-article-sort-by-number' in the list of
763 sorting functions -- preferably first.  Also note that sorting by date
764 is often much slower than sorting by number, and the sorting order is
765 very similar.  (Sorting by date means sorting by the time the message
766 was sent, sorting by number means sorting by arrival time.)
767
768 Each item can also be a list `(not F)' where F is a function;
769 this reverses the sort order.
770
771 Ready-made functions include `gnus-article-sort-by-number',
772 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
773 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
774 and `gnus-article-sort-by-score'.
775
776 When threading is turned on, the variable `gnus-thread-sort-functions'
777 controls how articles are sorted."
778   :group 'gnus-summary-sort
779   :type '(repeat (gnus-widget-reversible
780                   (choice (function-item gnus-article-sort-by-number)
781                           (function-item gnus-article-sort-by-author)
782                           (function-item gnus-article-sort-by-subject)
783                           (function-item gnus-article-sort-by-date)
784                           (function-item gnus-article-sort-by-score)
785                           (function-item gnus-article-sort-by-random)
786                           (function :tag "other"))
787                   (boolean :tag "Reverse order"))))
788
789
790 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
791   "*List of functions used for sorting threads in the summary buffer.
792 By default, threads are sorted by article number.
793
794 Each function takes two threads and returns non-nil if the first
795 thread should be sorted before the other.  If you use more than one
796 function, the primary sort function should be the last.  You should
797 probably always include `gnus-thread-sort-by-number' in the list of
798 sorting functions -- preferably first.  Also note that sorting by date
799 is often much slower than sorting by number, and the sorting order is
800 very similar.  (Sorting by date means sorting by the time the message
801 was sent, sorting by number means sorting by arrival time.)
802
803 Each list item can also be a list `(not F)' where F is a
804 function; this specifies reversed sort order.
805
806 Ready-made functions include `gnus-thread-sort-by-number',
807 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
808 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
809 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
810 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
811 and `gnus-thread-sort-by-total-score' (see
812 `gnus-thread-score-function').
813
814 When threading is turned off, the variable
815 `gnus-article-sort-functions' controls how articles are sorted."
816   :group 'gnus-summary-sort
817   :type '(repeat
818           (gnus-widget-reversible
819            (choice (function-item gnus-thread-sort-by-number)
820                    (function-item gnus-thread-sort-by-author)
821                    (function-item gnus-thread-sort-by-recipient)
822                    (function-item gnus-thread-sort-by-subject)
823                    (function-item gnus-thread-sort-by-date)
824                    (function-item gnus-thread-sort-by-score)
825                    (function-item gnus-thread-sort-by-most-recent-number)
826                    (function-item gnus-thread-sort-by-most-recent-date)
827                    (function-item gnus-thread-sort-by-random)
828                    (function-item gnus-thread-sort-by-total-score)
829                    (function :tag "other"))
830            (boolean :tag "Reverse order"))))
831
832 (defcustom gnus-thread-score-function '+
833   "*Function used for calculating the total score of a thread.
834
835 The function is called with the scores of the article and each
836 subthread and should then return the score of the thread.
837
838 Some functions you can use are `+', `max', or `min'."
839   :group 'gnus-summary-sort
840   :type 'function)
841
842 (defcustom gnus-summary-expunge-below nil
843   "All articles that have a score less than this variable will be expunged.
844 This variable is local to the summary buffers."
845   :group 'gnus-score-default
846   :type '(choice (const :tag "off" nil)
847                  integer))
848
849 (defcustom gnus-thread-expunge-below nil
850   "All threads that have a total score less than this variable will be expunged.
851 See `gnus-thread-score-function' for en explanation of what a
852 \"thread score\" is.
853
854 This variable is local to the summary buffers."
855   :group 'gnus-threading
856   :group 'gnus-score-default
857   :type '(choice (const :tag "off" nil)
858                  integer))
859
860 (defcustom gnus-summary-mode-hook nil
861   "*A hook for Gnus summary mode.
862 This hook is run before any variables are set in the summary buffer."
863   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
864   :group 'gnus-summary-various
865   :type 'hook)
866
867 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
868 (when (featurep 'xemacs)
869   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
870   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
871   (add-hook 'gnus-summary-mode-hook
872             'gnus-xmas-switch-horizontal-scrollbar-off))
873
874 (defcustom gnus-summary-menu-hook nil
875   "*Hook run after the creation of the summary mode menu."
876   :group 'gnus-summary-visual
877   :type 'hook)
878
879 (defcustom gnus-summary-exit-hook nil
880   "*A hook called on exit from the summary buffer.
881 It will be called with point in the group buffer."
882   :group 'gnus-summary-exit
883   :type 'hook)
884
885 (defcustom gnus-summary-prepare-hook nil
886   "*A hook called after the summary buffer has been generated.
887 If you want to modify the summary buffer, you can use this hook."
888   :group 'gnus-summary-various
889   :type 'hook)
890
891 (defcustom gnus-summary-prepared-hook nil
892   "*A hook called as the last thing after the summary buffer has been generated."
893   :group 'gnus-summary-various
894   :type 'hook)
895
896 (defcustom gnus-summary-generate-hook nil
897   "*A hook run just before generating the summary buffer.
898 This hook is commonly used to customize threading variables and the
899 like."
900   :group 'gnus-summary-various
901   :type 'hook)
902
903 (defcustom gnus-select-group-hook nil
904   "*A hook called when a newsgroup is selected.
905
906 If you'd like to simplify subjects like the
907 `gnus-summary-next-same-subject' command does, you can use the
908 following hook:
909
910  (add-hook gnus-select-group-hook
911            (lambda ()
912              (mapcar (lambda (header)
913                        (mail-header-set-subject
914                         header
915                         (gnus-simplify-subject
916                          (mail-header-subject header) 're-only)))
917                      gnus-newsgroup-headers)))"
918   :group 'gnus-group-select
919   :type 'hook)
920
921 (defcustom gnus-select-article-hook nil
922   "*A hook called when an article is selected."
923   :group 'gnus-summary-choose
924   :options '(gnus-agent-fetch-selected-article)
925   :type 'hook)
926
927 (defcustom gnus-visual-mark-article-hook
928   (list 'gnus-highlight-selected-summary)
929   "*Hook run after selecting an article in the summary buffer.
930 It is meant to be used for highlighting the article in some way.  It
931 is not run if `gnus-visual' is nil."
932   :group 'gnus-summary-visual
933   :type 'hook)
934
935 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
936   "*A hook called before parsing the headers."
937   :group 'gnus-various
938   :type 'hook)
939
940 (defcustom gnus-exit-group-hook nil
941   "*A hook called when exiting summary mode.
942 This hook is not called from the non-updating exit commands like `Q'."
943   :group 'gnus-various
944   :type 'hook)
945
946 (defcustom gnus-summary-update-hook
947   (list 'gnus-summary-highlight-line)
948   "*A hook called when a summary line is changed.
949 The hook will not be called if `gnus-visual' is nil.
950
951 The default function `gnus-summary-highlight-line' will
952 highlight the line according to the `gnus-summary-highlight'
953 variable."
954   :group 'gnus-summary-visual
955   :type 'hook)
956
957 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
958   "*A hook called when an article is selected for the first time.
959 The hook is intended to mark an article as read (or unread)
960 automatically when it is selected."
961   :group 'gnus-summary-choose
962   :type 'hook)
963
964 (defcustom gnus-group-no-more-groups-hook nil
965   "*A hook run when returning to group mode having no more (unread) groups."
966   :group 'gnus-group-select
967   :type 'hook)
968
969 (defcustom gnus-ps-print-hook nil
970   "*A hook run before ps-printing something from Gnus."
971   :group 'gnus-summary
972   :type 'hook)
973
974 (defcustom gnus-summary-article-move-hook nil
975   "*A hook called after an article is moved, copied, respooled, or crossposted."
976   :version "22.1"
977   :group 'gnus-summary
978   :type 'hook)
979
980 (defcustom gnus-summary-article-delete-hook nil
981   "*A hook called after an article is deleted."
982   :version "22.1"
983   :group 'gnus-summary
984   :type 'hook)
985
986 (defcustom gnus-summary-article-expire-hook nil
987   "*A hook called after an article is expired."
988   :version "22.1"
989   :group 'gnus-summary
990   :type 'hook)
991
992 (defcustom gnus-summary-display-arrow
993   (and (fboundp 'display-graphic-p)
994        (display-graphic-p))
995   "*If non-nil, display an arrow highlighting the current article."
996   :version "22.1"
997   :group 'gnus-summary
998   :type 'boolean)
999
1000 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1001   "Face used for highlighting the current article in the summary buffer."
1002   :group 'gnus-summary-visual
1003   :type 'face)
1004
1005 (defvar gnus-tmp-downloaded nil)
1006
1007 (defcustom gnus-summary-highlight
1008   '(((eq mark gnus-canceled-mark)
1009      . gnus-summary-cancelled)
1010     ((and uncached (> score default-high))
1011      . gnus-summary-high-undownloaded)
1012     ((and uncached (< score default-low))
1013      . gnus-summary-low-undownloaded)
1014     (uncached
1015      . gnus-summary-normal-undownloaded)
1016     ((and (> score default-high)
1017           (or (eq mark gnus-dormant-mark)
1018               (eq mark gnus-ticked-mark)))
1019      . gnus-summary-high-ticked)
1020     ((and (< score default-low)
1021           (or (eq mark gnus-dormant-mark)
1022               (eq mark gnus-ticked-mark)))
1023      . gnus-summary-low-ticked)
1024     ((or (eq mark gnus-dormant-mark)
1025          (eq mark gnus-ticked-mark))
1026      . gnus-summary-normal-ticked)
1027     ((and (> score default-high) (eq mark gnus-ancient-mark))
1028      . gnus-summary-high-ancient)
1029     ((and (< score default-low) (eq mark gnus-ancient-mark))
1030      . gnus-summary-low-ancient)
1031     ((eq mark gnus-ancient-mark)
1032      . gnus-summary-normal-ancient)
1033     ((and (> score default-high) (eq mark gnus-unread-mark))
1034      . gnus-summary-high-unread)
1035     ((and (< score default-low) (eq mark gnus-unread-mark))
1036      . gnus-summary-low-unread)
1037     ((eq mark gnus-unread-mark)
1038      . gnus-summary-normal-unread)
1039     ((> score default-high)
1040      . gnus-summary-high-read)
1041     ((< score default-low)
1042      . gnus-summary-low-read)
1043     (t
1044      . gnus-summary-normal-read))
1045   "*Controls the highlighting of summary buffer lines.
1046
1047 A list of (FORM . FACE) pairs.  When deciding how a a particular
1048 summary line should be displayed, each form is evaluated.  The content
1049 of the face field after the first true form is used.  You can change
1050 how those summary lines are displayed, by editing the face field.
1051
1052 You can use the following variables in the FORM field.
1053
1054 score:        The article's score
1055 default:      The default article score.
1056 default-high: The default score for high scored articles.
1057 default-low:  The default score for low scored articles.
1058 below:        The score below which articles are automatically marked as read.
1059 mark:         The article's mark.
1060 uncached:     Non-nil if the article is uncached."
1061   :group 'gnus-summary-visual
1062   :type '(repeat (cons (sexp :tag "Form" nil)
1063                        face)))
1064
1065 (defcustom gnus-alter-header-function nil
1066   "Function called to allow alteration of article header structures.
1067 The function is called with one parameter, the article header vector,
1068 which it may alter in any way."
1069   :type '(choice (const :tag "None" nil)
1070                  function)
1071   :group 'gnus-summary)
1072
1073 (defvar gnus-decode-encoded-word-function
1074   (mime-find-field-decoder 'From 'nov)
1075   "Variable that says which function should be used to decode a string with encoded words.")
1076
1077 (defcustom gnus-extra-headers '(To Newsgroups)
1078   "*Extra headers to parse."
1079   :version "21.1"
1080   :group 'gnus-summary
1081   :type '(repeat symbol))
1082
1083 (defcustom gnus-ignored-from-addresses
1084   (and user-mail-address  
1085        (not (string= user-mail-address ""))
1086        (regexp-quote user-mail-address))
1087   "*Regexp of From headers that may be suppressed in favor of To headers."
1088   :version "21.1"
1089   :group 'gnus-summary
1090   :type 'regexp)
1091
1092 (defcustom gnus-summary-to-prefix "-> "
1093   "*String prefixed to the To field in the summary line when
1094 using `gnus-ignored-from-addresses'."
1095   :version "22.1"
1096   :group 'gnus-summary
1097   :type 'string)
1098
1099 (defcustom gnus-summary-newsgroup-prefix "=> "
1100   "*String prefixed to the Newsgroup field in the summary
1101 line when using `gnus-ignored-from-addresses'."
1102   :version "22.1"
1103   :group 'gnus-summary
1104   :type 'string)
1105
1106 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1107   "List of charsets that should be ignored.
1108 When these charsets are used in the \"charset\" parameter, the
1109 default charset will be used instead."
1110   :version "21.1"
1111   :type '(repeat symbol)
1112   :group 'gnus-charset)
1113
1114 (gnus-define-group-parameter
1115  ignored-charsets
1116  :type list
1117  :function-document
1118  "Return the ignored charsets of GROUP."
1119  :variable gnus-group-ignored-charsets-alist
1120  :variable-default
1121  '(("alt\\.chinese\\.text" iso-8859-1))
1122  :variable-document
1123  "Alist of regexps (to match group names) and charsets that should be ignored.
1124 When these charsets are used in the \"charset\" parameter, the
1125 default charset will be used instead."
1126  :variable-group gnus-charset
1127  :variable-type '(repeat (cons (regexp :tag "Group")
1128                                (repeat symbol)))
1129  :parameter-type '(choice :tag "Ignored charsets"
1130                           :value nil
1131                           (repeat (symbol)))
1132  :parameter-document       "\
1133 List of charsets that should be ignored.
1134
1135 When these charsets are used in the \"charset\" parameter, the
1136 default charset will be used instead.")
1137
1138 (defcustom gnus-group-highlight-words-alist nil
1139   "Alist of group regexps and highlight regexps.
1140 This variable uses the same syntax as `gnus-emphasis-alist'."
1141   :version "21.1"
1142   :type '(repeat (cons (regexp :tag "Group")
1143                        (repeat (list (regexp :tag "Highlight regexp")
1144                                      (number :tag "Group for entire word" 0)
1145                                      (number :tag "Group for displayed part" 0)
1146                                      (symbol :tag "Face"
1147                                              gnus-emphasis-highlight-words)))))
1148   :group 'gnus-summary-visual)
1149
1150 (defcustom gnus-use-wheel nil
1151   "Use Intelli-mouse on summary movement"
1152   :type 'boolean
1153   :group 'gnus-summary-maneuvering)
1154
1155 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1156   "Amount to scroll messages by spinning the mouse wheel.
1157 This is actually a cons cell, where the first item is the amount to scroll
1158 on a normal wheel event, and the second is the amount to scroll when the
1159 wheel is moved with the shift key depressed."
1160   :type '(cons (integer :tag "Shift") integer)
1161   :group 'gnus-summary-maneuvering)
1162
1163 (defcustom gnus-wheel-edge-resistance 2
1164   "How hard it should be to change the current article
1165 by moving the mouse over the edge of the article window."
1166   :type 'integer
1167   :group 'gnus-summary-maneuvering)
1168
1169 (defcustom gnus-summary-show-article-charset-alist
1170   nil
1171   "Alist of number and charset.
1172 The article will be shown with the charset corresponding to the
1173 numbered argument.
1174 For example: ((1 . cn-gb-2312) (2 . big5))."
1175   :version "21.1"
1176   :type '(repeat (cons (number :tag "Argument" 1)
1177                        (symbol :tag "Charset")))
1178   :group 'gnus-charset)
1179
1180 (defcustom gnus-preserve-marks t
1181   "Whether marks are preserved when moving, copying and respooling messages."
1182   :version "21.1"
1183   :type 'boolean
1184   :group 'gnus-summary-marks)
1185
1186 (defcustom gnus-alter-articles-to-read-function nil
1187   "Function to be called to alter the list of articles to be selected."
1188   :type '(choice (const nil) function)
1189   :group 'gnus-summary)
1190
1191 (defcustom gnus-orphan-score nil
1192   "*All orphans get this score added.  Set in the score file."
1193   :group 'gnus-score-default
1194   :type '(choice (const nil)
1195                  integer))
1196
1197 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1198   "*A regexp to match MIME parts when saving multiple parts of a
1199 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1200 This regexp will be used by default when prompting the user for which
1201 type of files to save."
1202   :group 'gnus-summary
1203   :type 'regexp)
1204
1205 (defcustom gnus-read-all-available-headers nil
1206   "Whether Gnus should parse all headers made available to it.
1207 This is mostly relevant for slow back ends where the user may
1208 wish to widen the summary buffer to include all headers
1209 that were fetched.  Say, for nnultimate groups."
1210   :version "22.1"
1211   :group 'gnus-summary
1212   :type '(choice boolean regexp))
1213
1214 (defcustom gnus-summary-muttprint-program "muttprint"
1215   "Command (and optional arguments) used to run Muttprint."
1216   :version "22.1"
1217   :group 'gnus-summary
1218   :type 'string)
1219
1220 (defcustom gnus-article-loose-mime t
1221   "If non-nil, don't require MIME-Version header.
1222 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1223 supply the MIME-Version header or deliberately strip it from the mail.
1224 If non-nil (the default), Gnus will treat some articles as MIME
1225 even if the MIME-Version header is missing."
1226   :version "22.1"
1227   :type 'boolean
1228   :group 'gnus-article-mime)
1229
1230 (defcustom gnus-article-emulate-mime t
1231   "If non-nil, use MIME emulation for uuencode and the like.
1232 This means that Gnus will search message bodies for text that look
1233 like uuencoded bits, yEncoded bits, and so on, and present that using
1234 the normal Gnus MIME machinery."
1235   :version "22.1"
1236   :type 'boolean
1237   :group 'gnus-article-mime)
1238
1239 ;;; Internal variables
1240
1241 (defvar gnus-summary-display-cache nil)
1242 (defvar gnus-article-mime-handles nil)
1243 (defvar gnus-article-decoded-p nil)
1244 (defvar gnus-article-charset nil)
1245 (defvar gnus-article-ignored-charsets nil)
1246 (defvar gnus-scores-exclude-files nil)
1247 (defvar gnus-page-broken nil)
1248
1249 (defvar gnus-original-article nil)
1250 (defvar gnus-article-internal-prepare-hook nil)
1251 (defvar gnus-newsgroup-process-stack nil)
1252
1253 (defvar gnus-thread-indent-array nil)
1254 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1255 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1256   "Function called to sort the articles within a thread after it has been gathered together.")
1257
1258 (defvar gnus-summary-save-parts-type-history nil)
1259 (defvar gnus-summary-save-parts-last-directory nil)
1260
1261 ;; Avoid highlighting in kill files.
1262 (defvar gnus-summary-inhibit-highlight nil)
1263 (defvar gnus-newsgroup-selected-overlay nil)
1264 (defvar gnus-inhibit-limiting nil)
1265 (defvar gnus-newsgroup-adaptive-score-file nil)
1266 (defvar gnus-current-score-file nil)
1267 (defvar gnus-current-move-group nil)
1268 (defvar gnus-current-copy-group nil)
1269 (defvar gnus-current-crosspost-group nil)
1270 (defvar gnus-newsgroup-display nil)
1271
1272 (defvar gnus-newsgroup-dependencies nil)
1273 (defvar gnus-newsgroup-adaptive nil)
1274 (defvar gnus-summary-display-article-function nil)
1275 (defvar gnus-summary-highlight-line-function nil
1276   "Function called after highlighting a summary line.")
1277
1278 (defvar gnus-summary-line-format-alist
1279   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1280     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1281     (?s gnus-tmp-subject-or-nil ?s)
1282     (?n gnus-tmp-name ?s)
1283     (?A (std11-address-string
1284          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1285     (?a (or (std11-full-name-string
1286              (car (mime-entity-read-field gnus-tmp-header 'From)))
1287             gnus-tmp-from) ?s)
1288     (?F gnus-tmp-from ?s)
1289     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1290     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1291     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1292     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1293     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1294     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1295     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1296     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1297     (?L gnus-tmp-lines ?s)
1298     (?O gnus-tmp-downloaded ?c)
1299     (?I gnus-tmp-indentation ?s)
1300     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1301     (?R gnus-tmp-replied ?c)
1302     (?\[ gnus-tmp-opening-bracket ?c)
1303     (?\] gnus-tmp-closing-bracket ?c)
1304     (?\> (make-string gnus-tmp-level ? ) ?s)
1305     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1306     (?i gnus-tmp-score ?d)
1307     (?z gnus-tmp-score-char ?c)
1308     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1309     (?U gnus-tmp-unread ?c)
1310     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1311         ?s)
1312     (?t (gnus-summary-number-of-articles-in-thread
1313          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1314         ?d)
1315     (?e (gnus-summary-number-of-articles-in-thread
1316          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1317         ?c)
1318     (?u gnus-tmp-user-defined ?s)
1319     (?P (gnus-pick-line-number) ?d)
1320     (?B gnus-tmp-thread-tree-header-string ?s)
1321     (user-date (gnus-user-date
1322                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1323   "An alist of format specifications that can appear in summary lines.
1324 These are paired with what variables they correspond with, along with
1325 the type of the variable (string, integer, character, etc).")
1326
1327 (defvar gnus-summary-dummy-line-format-alist
1328   `((?S gnus-tmp-subject ?s)
1329     (?N gnus-tmp-number ?d)
1330     (?u gnus-tmp-user-defined ?s)))
1331
1332 (defvar gnus-summary-mode-line-format-alist
1333   `((?G gnus-tmp-group-name ?s)
1334     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1335     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1336     (?A gnus-tmp-article-number ?d)
1337     (?Z gnus-tmp-unread-and-unselected ?s)
1338     (?V gnus-version ?s)
1339     (?U gnus-tmp-unread-and-unticked ?d)
1340     (?S gnus-tmp-subject ?s)
1341     (?e gnus-tmp-unselected ?d)
1342     (?u gnus-tmp-user-defined ?s)
1343     (?d (length gnus-newsgroup-dormant) ?d)
1344     (?t (length gnus-newsgroup-marked) ?d)
1345     (?h (length gnus-newsgroup-spam-marked) ?d)
1346     (?r (length gnus-newsgroup-reads) ?d)
1347     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1348     (?E gnus-newsgroup-expunged-tally ?d)
1349     (?s (gnus-current-score-file-nondirectory) ?s)))
1350
1351 (defvar gnus-last-search-regexp nil
1352   "Default regexp for article search command.")
1353
1354 (defvar gnus-summary-search-article-matched-data nil
1355   "Last matched data of article search command.  It is the local variable
1356 in `gnus-article-buffer' which consists of the list of start position,
1357 end position and text.")
1358
1359 (defvar gnus-last-shell-command nil
1360   "Default shell command on article.")
1361
1362 (defvar gnus-newsgroup-agentized nil
1363   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1364 (defvar gnus-newsgroup-begin nil)
1365 (defvar gnus-newsgroup-end nil)
1366 (defvar gnus-newsgroup-last-rmail nil)
1367 (defvar gnus-newsgroup-last-mail nil)
1368 (defvar gnus-newsgroup-last-folder nil)
1369 (defvar gnus-newsgroup-last-file nil)
1370 (defvar gnus-newsgroup-auto-expire nil)
1371 (defvar gnus-newsgroup-active nil)
1372
1373 (defvar gnus-newsgroup-data nil)
1374 (defvar gnus-newsgroup-data-reverse nil)
1375 (defvar gnus-newsgroup-limit nil)
1376 (defvar gnus-newsgroup-limits nil)
1377 (defvar gnus-summary-use-undownloaded-faces nil)
1378
1379 (defvar gnus-newsgroup-unreads nil
1380   "Sorted list of unread articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-unselected nil
1383   "Sorted list of unselected unread articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-reads nil
1386   "Alist of read articles and article marks in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-expunged-tally nil)
1389
1390 (defvar gnus-newsgroup-marked nil
1391   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1392
1393 (defvar gnus-newsgroup-spam-marked nil
1394   "List of ranges of articles that have been marked as spam.")
1395
1396 (defvar gnus-newsgroup-killed nil
1397   "List of ranges of articles that have been through the scoring process.")
1398
1399 (defvar gnus-newsgroup-cached nil
1400   "Sorted list of articles that come from the article cache.")
1401
1402 (defvar gnus-newsgroup-saved nil
1403   "List of articles that have been saved.")
1404
1405 (defvar gnus-newsgroup-kill-headers nil)
1406
1407 (defvar gnus-newsgroup-replied nil
1408   "List of articles that have been replied to in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-forwarded nil
1411   "List of articles that have been forwarded in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-recent nil
1414   "List of articles that have are recent in the current newsgroup.")
1415
1416 (defvar gnus-newsgroup-expirable nil
1417   "Sorted list of articles in the current newsgroup that can be expired.")
1418
1419 (defvar gnus-newsgroup-processable nil
1420   "List of articles in the current newsgroup that can be processed.")
1421
1422 (defvar gnus-newsgroup-downloadable nil
1423   "Sorted list of articles in the current newsgroup that can be processed.")
1424
1425 (defvar gnus-newsgroup-unfetched nil
1426   "Sorted list of articles in the current newsgroup whose headers have
1427 not been fetched into the agent.
1428
1429 This list will always be a subset of gnus-newsgroup-undownloaded.")
1430
1431 (defvar gnus-newsgroup-undownloaded nil
1432   "List of articles in the current newsgroup that haven't been downloaded.")
1433
1434 (defvar gnus-newsgroup-unsendable nil
1435   "List of articles in the current newsgroup that won't be sent.")
1436
1437 (defvar gnus-newsgroup-bookmarks nil
1438   "List of articles in the current newsgroup that have bookmarks.")
1439
1440 (defvar gnus-newsgroup-dormant nil
1441   "Sorted list of dormant articles in the current newsgroup.")
1442
1443 (defvar gnus-newsgroup-unseen nil
1444   "List of unseen articles in the current newsgroup.")
1445
1446 (defvar gnus-newsgroup-seen nil
1447   "Range of seen articles in the current newsgroup.")
1448
1449 (defvar gnus-newsgroup-articles nil
1450   "List of articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-scored nil
1453   "List of scored articles in the current newsgroup.")
1454
1455 (defvar gnus-newsgroup-incorporated nil
1456   "List of incorporated articles in the current newsgroup.")
1457
1458 (defvar gnus-newsgroup-headers nil
1459   "List of article headers in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-threads nil)
1462
1463 (defvar gnus-newsgroup-prepared nil
1464   "Whether the current group has been prepared properly.")
1465
1466 (defvar gnus-newsgroup-ancient nil
1467   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-sparse nil)
1470
1471 (defvar gnus-current-article nil)
1472 (defvar gnus-article-current nil)
1473 (defvar gnus-current-headers nil)
1474 (defvar gnus-have-all-headers nil)
1475 (defvar gnus-last-article nil)
1476 (defvar gnus-newsgroup-history nil)
1477 (defvar gnus-newsgroup-charset nil)
1478 (defvar gnus-newsgroup-ephemeral-charset nil)
1479 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1480
1481 (defvar gnus-article-before-search nil)
1482
1483 (defvar gnus-summary-local-variables
1484   '(gnus-newsgroup-name
1485     gnus-newsgroup-begin gnus-newsgroup-end
1486     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1487     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1488     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1489     gnus-newsgroup-unselected gnus-newsgroup-marked
1490     gnus-newsgroup-spam-marked
1491     gnus-newsgroup-reads gnus-newsgroup-saved
1492     gnus-newsgroup-replied gnus-newsgroup-forwarded
1493     gnus-newsgroup-recent
1494     gnus-newsgroup-expirable
1495     gnus-newsgroup-processable gnus-newsgroup-killed
1496     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1497     gnus-newsgroup-unfetched
1498     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1499     gnus-newsgroup-seen gnus-newsgroup-articles
1500     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1501     gnus-newsgroup-headers gnus-newsgroup-threads
1502     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1503     gnus-current-article gnus-current-headers gnus-have-all-headers
1504     gnus-last-article gnus-article-internal-prepare-hook
1505     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1506     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1507     gnus-thread-expunge-below
1508     gnus-score-alist gnus-current-score-file
1509     (gnus-summary-expunge-below . global)
1510     (gnus-summary-mark-below . global)
1511     (gnus-orphan-score . global)
1512     gnus-newsgroup-active gnus-scores-exclude-files
1513     gnus-newsgroup-history gnus-newsgroup-ancient
1514     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1515     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1516     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1517     (gnus-newsgroup-expunged-tally . 0)
1518     gnus-cache-removable-articles gnus-newsgroup-cached
1519     gnus-newsgroup-data gnus-newsgroup-data-reverse
1520     gnus-newsgroup-limit gnus-newsgroup-limits
1521     gnus-newsgroup-charset gnus-newsgroup-display
1522     gnus-summary-use-undownloaded-faces
1523     gnus-newsgroup-incorporated)
1524   "Variables that are buffer-local to the summary buffers.")
1525
1526 (defvar gnus-newsgroup-variables nil
1527   "A list of variables that have separate values in different newsgroups.
1528 A list of newsgroup (summary buffer) local variables, or cons of
1529 variables and their default expressions to be evalled (when the default
1530 values are not nil), that should be made global while the summary buffer
1531 is active.
1532
1533 Note: The default expressions will be evaluated (using function `eval')
1534 before assignment to the local variable rather than just assigned to it.
1535 If the default expression is the symbol `global', that symbol will not
1536 be evaluated but the global value of the local variable will be used
1537 instead.
1538
1539 These variables can be used to set variables in the group parameters
1540 while still allowing them to affect operations done in other buffers.
1541 For example:
1542
1543 \(setq gnus-newsgroup-variables
1544      '(message-use-followup-to
1545        (gnus-visible-headers .
1546          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1547 ")
1548
1549 ;; Byte-compiler warning.
1550 (eval-when-compile
1551   ;; Bind features so that require will believe that gnus-sum has
1552   ;; already been loaded (avoids infinite recursion)
1553   (let ((features (cons 'gnus-sum features)))
1554     ;; Several of the declarations in gnus-sum are needed to load the
1555     ;; following files. Right now, these definitions have been
1556     ;; compiled but not defined (evaluated).  We could either do a
1557     ;; eval-and-compile about all of the declarations or evaluate the
1558     ;; source file.
1559     (if (boundp 'gnus-newsgroup-variables)
1560         nil
1561       (load "gnus-sum.el" t t t))
1562     (require 'gnus)
1563     (require 'gnus-art)))
1564
1565 ;; Subject simplification.
1566
1567 (defun gnus-simplify-whitespace (str)
1568   "Remove excessive whitespace from STR."
1569   ;; Multiple spaces.
1570   (while (string-match "[ \t][ \t]+" str)
1571     (setq str (concat (substring str 0 (match-beginning 0))
1572                         " "
1573                         (substring str (match-end 0)))))
1574   ;; Leading spaces.
1575   (when (string-match "^[ \t]+" str)
1576     (setq str (substring str (match-end 0))))
1577   ;; Trailing spaces.
1578   (when (string-match "[ \t]+$" str)
1579     (setq str (substring str 0 (match-beginning 0))))
1580   str)
1581
1582 (defun gnus-simplify-all-whitespace (str)
1583   "Remove all whitespace from STR."
1584   (while (string-match "[ \t\n]+" str)
1585     (setq str (replace-match "" nil nil str)))
1586   str)
1587
1588 (defsubst gnus-simplify-subject-re (subject)
1589   "Remove \"Re:\" from subject lines."
1590   (if (string-match message-subject-re-regexp subject)
1591       (substring subject (match-end 0))
1592     subject))
1593
1594 (defun gnus-simplify-subject (subject &optional re-only)
1595   "Remove `Re:' and words in parentheses.
1596 If RE-ONLY is non-nil, strip leading `Re:'s only."
1597   (let ((case-fold-search t))           ;Ignore case.
1598     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1599     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1600       (setq subject (substring subject (match-end 0))))
1601     ;; Remove uninteresting prefixes.
1602     (when (and (not re-only)
1603                gnus-simplify-ignored-prefixes
1604                (string-match gnus-simplify-ignored-prefixes subject))
1605       (setq subject (substring subject (match-end 0))))
1606     ;; Remove words in parentheses from end.
1607     (unless re-only
1608       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1609         (setq subject (substring subject 0 (match-beginning 0)))))
1610     ;; Return subject string.
1611     subject))
1612
1613 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1614 ;; all whitespace.
1615 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1616   (goto-char (point-min))
1617   (while (re-search-forward regexp nil t)
1618     (replace-match (or newtext ""))))
1619
1620 (defun gnus-simplify-buffer-fuzzy ()
1621   "Simplify string in the buffer fuzzily.
1622 The string in the accessible portion of the current buffer is simplified.
1623 It is assumed to be a single-line subject.
1624 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1625 matter is removed.  Additional things can be deleted by setting
1626 `gnus-simplify-subject-fuzzy-regexp'."
1627   (let ((case-fold-search t)
1628         (modified-tick))
1629     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1630
1631     (while (not (eq modified-tick (buffer-modified-tick)))
1632       (setq modified-tick (buffer-modified-tick))
1633       (cond
1634        ((listp gnus-simplify-subject-fuzzy-regexp)
1635         (mapcar 'gnus-simplify-buffer-fuzzy-step
1636                 gnus-simplify-subject-fuzzy-regexp))
1637        (gnus-simplify-subject-fuzzy-regexp
1638         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1639       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1640       (gnus-simplify-buffer-fuzzy-step
1641        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1642       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1643
1644     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1645     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1646     (gnus-simplify-buffer-fuzzy-step " $")
1647     (gnus-simplify-buffer-fuzzy-step "^ +")))
1648
1649 (defun gnus-simplify-subject-fuzzy (subject)
1650   "Simplify a subject string fuzzily.
1651 See `gnus-simplify-buffer-fuzzy' for details."
1652   (save-excursion
1653     (gnus-set-work-buffer)
1654     (let ((case-fold-search t))
1655       ;; Remove uninteresting prefixes.
1656       (when (and gnus-simplify-ignored-prefixes
1657                  (string-match gnus-simplify-ignored-prefixes subject))
1658         (setq subject (substring subject (match-end 0))))
1659       (insert subject)
1660       (inline (gnus-simplify-buffer-fuzzy))
1661       (buffer-string))))
1662
1663 (defsubst gnus-simplify-subject-fully (subject)
1664   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1665   (cond
1666    (gnus-simplify-subject-functions
1667     (gnus-map-function gnus-simplify-subject-functions subject))
1668    ((null gnus-summary-gather-subject-limit)
1669     (gnus-simplify-subject-re subject))
1670    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1671     (gnus-simplify-subject-fuzzy subject))
1672    ((numberp gnus-summary-gather-subject-limit)
1673     (gnus-limit-string (gnus-simplify-subject-re subject)
1674                        gnus-summary-gather-subject-limit))
1675    (t
1676     subject)))
1677
1678 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1679   "Check whether two subjects are equal.
1680 If optional argument SIMPLE-FIRST is t, first argument is already
1681 simplified."
1682   (cond
1683    ((null simple-first)
1684     (equal (gnus-simplify-subject-fully s1)
1685            (gnus-simplify-subject-fully s2)))
1686    (t
1687     (equal s1
1688            (gnus-simplify-subject-fully s2)))))
1689
1690 (defun gnus-summary-bubble-group ()
1691   "Increase the score of the current group.
1692 This is a handy function to add to `gnus-summary-exit-hook' to
1693 increase the score of each group you read."
1694   (gnus-group-add-score gnus-newsgroup-name))
1695
1696 \f
1697 ;;;
1698 ;;; Gnus summary mode
1699 ;;;
1700
1701 (put 'gnus-summary-mode 'mode-class 'special)
1702
1703 (defvar gnus-article-commands-menu)
1704
1705 ;; Non-orthogonal keys
1706
1707 (gnus-define-keys gnus-summary-mode-map
1708   " " gnus-summary-next-page
1709   "\177" gnus-summary-prev-page
1710   [delete] gnus-summary-prev-page
1711   [backspace] gnus-summary-prev-page
1712   "\r" gnus-summary-scroll-up
1713   "\M-\r" gnus-summary-scroll-down
1714   "n" gnus-summary-next-unread-article
1715   "p" gnus-summary-prev-unread-article
1716   "N" gnus-summary-next-article
1717   "P" gnus-summary-prev-article
1718   "\M-\C-n" gnus-summary-next-same-subject
1719   "\M-\C-p" gnus-summary-prev-same-subject
1720   "\M-n" gnus-summary-next-unread-subject
1721   "\M-p" gnus-summary-prev-unread-subject
1722   "." gnus-summary-first-unread-article
1723   "," gnus-summary-best-unread-article
1724   "\M-s" gnus-summary-search-article-forward
1725   "\M-r" gnus-summary-search-article-backward
1726   "<" gnus-summary-beginning-of-article
1727   ">" gnus-summary-end-of-article
1728   "j" gnus-summary-goto-article
1729   "^" gnus-summary-refer-parent-article
1730   "\M-^" gnus-summary-refer-article
1731   "u" gnus-summary-tick-article-forward
1732   "!" gnus-summary-tick-article-forward
1733   "U" gnus-summary-tick-article-backward
1734   "d" gnus-summary-mark-as-read-forward
1735   "D" gnus-summary-mark-as-read-backward
1736   "E" gnus-summary-mark-as-expirable
1737   "\M-u" gnus-summary-clear-mark-forward
1738   "\M-U" gnus-summary-clear-mark-backward
1739   "k" gnus-summary-kill-same-subject-and-select
1740   "\C-k" gnus-summary-kill-same-subject
1741   "\M-\C-k" gnus-summary-kill-thread
1742   "\M-\C-l" gnus-summary-lower-thread
1743   "e" gnus-summary-edit-article
1744   "#" gnus-summary-mark-as-processable
1745   "\M-#" gnus-summary-unmark-as-processable
1746   "\M-\C-t" gnus-summary-toggle-threads
1747   "\M-\C-s" gnus-summary-show-thread
1748   "\M-\C-h" gnus-summary-hide-thread
1749   "\M-\C-f" gnus-summary-next-thread
1750   "\M-\C-b" gnus-summary-prev-thread
1751   [(meta down)] gnus-summary-next-thread
1752   [(meta up)] gnus-summary-prev-thread
1753   "\M-\C-u" gnus-summary-up-thread
1754   "\M-\C-d" gnus-summary-down-thread
1755   "&" gnus-summary-execute-command
1756   "c" gnus-summary-catchup-and-exit
1757   "\C-w" gnus-summary-mark-region-as-read
1758   "\C-t" gnus-summary-toggle-truncation
1759   "?" gnus-summary-mark-as-dormant
1760   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1761   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1762   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1763   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1764   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1765   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1766   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1767   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1768   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1769   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1770   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1771   "=" gnus-summary-expand-window
1772   "\C-x\C-s" gnus-summary-reselect-current-group
1773   "\M-g" gnus-summary-rescan-group
1774   "w" gnus-summary-stop-page-breaking
1775   "\C-c\C-r" gnus-summary-caesar-message
1776   "\M-t" gnus-summary-toggle-mime
1777   "f" gnus-summary-followup
1778   "F" gnus-summary-followup-with-original
1779   "C" gnus-summary-cancel-article
1780   "r" gnus-summary-reply
1781   "R" gnus-summary-reply-with-original
1782   "\C-c\C-f" gnus-summary-mail-forward
1783   "o" gnus-summary-save-article
1784   "\C-o" gnus-summary-save-article-mail
1785   "|" gnus-summary-pipe-output
1786   "\M-k" gnus-summary-edit-local-kill
1787   "\M-K" gnus-summary-edit-global-kill
1788   ;; "V" gnus-version
1789   "\C-c\C-d" gnus-summary-describe-group
1790   "q" gnus-summary-exit
1791   "Q" gnus-summary-exit-no-update
1792   "\C-c\C-i" gnus-info-find-node
1793   gnus-mouse-2 gnus-mouse-pick-article
1794   [follow-link] mouse-face
1795   "m" gnus-summary-mail-other-window
1796   "a" gnus-summary-post-news
1797   "i" gnus-summary-news-other-window
1798   "x" gnus-summary-limit-to-unread
1799   "s" gnus-summary-isearch-article
1800   "t" gnus-summary-toggle-header
1801   "g" gnus-summary-show-article
1802   "l" gnus-summary-goto-last-article
1803   "v" gnus-summary-preview-mime-message
1804   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1805   "\C-d" gnus-summary-enter-digest-group
1806   "\M-\C-d" gnus-summary-read-document
1807   "\M-\C-e" gnus-summary-edit-parameters
1808   "\M-\C-a" gnus-summary-customize-parameters
1809   "\C-c\C-b" gnus-bug
1810   "\C-c\C-n" gnus-namazu-search
1811   "*" gnus-cache-enter-article
1812   "\M-*" gnus-cache-remove-article
1813   "\M-&" gnus-summary-universal-argument
1814   "\C-l" gnus-recenter
1815   "I" gnus-summary-increase-score
1816   "L" gnus-summary-lower-score
1817   "\M-i" gnus-symbolic-argument
1818   "h" gnus-summary-select-article-buffer
1819
1820   "V" gnus-summary-score-map
1821   "X" gnus-uu-extract-map
1822   "S" gnus-summary-send-map)
1823
1824   ;; Sort of orthogonal keymap
1825 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1826   "t" gnus-summary-tick-article-forward
1827   "!" gnus-summary-tick-article-forward
1828   "d" gnus-summary-mark-as-read-forward
1829   "r" gnus-summary-mark-as-read-forward
1830   "c" gnus-summary-clear-mark-forward
1831   " " gnus-summary-clear-mark-forward
1832   "e" gnus-summary-mark-as-expirable
1833   "x" gnus-summary-mark-as-expirable
1834   "?" gnus-summary-mark-as-dormant
1835   "b" gnus-summary-set-bookmark
1836   "B" gnus-summary-remove-bookmark
1837   "#" gnus-summary-mark-as-processable
1838   "\M-#" gnus-summary-unmark-as-processable
1839   "S" gnus-summary-limit-include-expunged
1840   "C" gnus-summary-catchup
1841   "H" gnus-summary-catchup-to-here
1842   "h" gnus-summary-catchup-from-here
1843   "\C-c" gnus-summary-catchup-all
1844   "k" gnus-summary-kill-same-subject-and-select
1845   "K" gnus-summary-kill-same-subject
1846   "P" gnus-uu-mark-map)
1847
1848 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1849   "c" gnus-summary-clear-above
1850   "u" gnus-summary-tick-above
1851   "m" gnus-summary-mark-above
1852   "k" gnus-summary-kill-below)
1853
1854 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1855   "/" gnus-summary-limit-to-subject
1856   "n" gnus-summary-limit-to-articles
1857   "w" gnus-summary-pop-limit
1858   "s" gnus-summary-limit-to-subject
1859   "a" gnus-summary-limit-to-author
1860   "u" gnus-summary-limit-to-unread
1861   "m" gnus-summary-limit-to-marks
1862   "M" gnus-summary-limit-exclude-marks
1863   "v" gnus-summary-limit-to-score
1864   "*" gnus-summary-limit-include-cached
1865   "D" gnus-summary-limit-include-dormant
1866   "T" gnus-summary-limit-include-thread
1867   "d" gnus-summary-limit-exclude-dormant
1868   "t" gnus-summary-limit-to-age
1869   "." gnus-summary-limit-to-unseen
1870   "x" gnus-summary-limit-to-extra
1871   "p" gnus-summary-limit-to-display-predicate
1872   "E" gnus-summary-limit-include-expunged
1873   "c" gnus-summary-limit-exclude-childless-dormant
1874   "C" gnus-summary-limit-mark-excluded-as-read
1875   "o" gnus-summary-insert-old-articles
1876   "N" gnus-summary-insert-new-articles
1877   "r" gnus-summary-limit-to-replied
1878   "R" gnus-summary-limit-to-recipient)
1879
1880 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1881   "n" gnus-summary-next-unread-article
1882   "p" gnus-summary-prev-unread-article
1883   "N" gnus-summary-next-article
1884   "P" gnus-summary-prev-article
1885   "\C-n" gnus-summary-next-same-subject
1886   "\C-p" gnus-summary-prev-same-subject
1887   "\M-n" gnus-summary-next-unread-subject
1888   "\M-p" gnus-summary-prev-unread-subject
1889   "f" gnus-summary-first-unread-article
1890   "b" gnus-summary-best-unread-article
1891   "j" gnus-summary-goto-article
1892   "g" gnus-summary-goto-subject
1893   "l" gnus-summary-goto-last-article
1894   "o" gnus-summary-pop-article)
1895
1896 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1897   "k" gnus-summary-kill-thread
1898   "l" gnus-summary-lower-thread
1899   "i" gnus-summary-raise-thread
1900   "T" gnus-summary-toggle-threads
1901   "t" gnus-summary-rethread-current
1902   "^" gnus-summary-reparent-thread
1903   "s" gnus-summary-show-thread
1904   "S" gnus-summary-show-all-threads
1905   "h" gnus-summary-hide-thread
1906   "H" gnus-summary-hide-all-threads
1907   "n" gnus-summary-next-thread
1908   "p" gnus-summary-prev-thread
1909   "u" gnus-summary-up-thread
1910   "o" gnus-summary-top-thread
1911   "d" gnus-summary-down-thread
1912   "#" gnus-uu-mark-thread
1913   "\M-#" gnus-uu-unmark-thread)
1914
1915 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1916   "g" gnus-summary-prepare
1917   "c" gnus-summary-insert-cached-articles
1918   "d" gnus-summary-insert-dormant-articles)
1919
1920 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1921   "c" gnus-summary-catchup-and-exit
1922   "C" gnus-summary-catchup-all-and-exit
1923   "E" gnus-summary-exit-no-update
1924   "J" gnus-summary-jump-to-other-group
1925   "Q" gnus-summary-exit
1926   "Z" gnus-summary-exit
1927   "n" gnus-summary-catchup-and-goto-next-group
1928   "p" gnus-summary-catchup-and-goto-prev-group
1929   "R" gnus-summary-reselect-current-group
1930   "G" gnus-summary-rescan-group
1931   "N" gnus-summary-next-group
1932   "s" gnus-summary-save-newsrc
1933   "P" gnus-summary-prev-group)
1934
1935 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1936   " " gnus-summary-next-page
1937   "n" gnus-summary-next-page
1938   "\177" gnus-summary-prev-page
1939   [delete] gnus-summary-prev-page
1940   "p" gnus-summary-prev-page
1941   "\r" gnus-summary-scroll-up
1942   "\M-\r" gnus-summary-scroll-down
1943   "<" gnus-summary-beginning-of-article
1944   ">" gnus-summary-end-of-article
1945   "b" gnus-summary-beginning-of-article
1946   "e" gnus-summary-end-of-article
1947   "^" gnus-summary-refer-parent-article
1948   "r" gnus-summary-refer-parent-article
1949   "D" gnus-summary-enter-digest-group
1950   "R" gnus-summary-refer-references
1951   "T" gnus-summary-refer-thread
1952   "g" gnus-summary-show-article
1953   "s" gnus-summary-isearch-article
1954   "P" gnus-summary-print-article
1955   "M" gnus-mailing-list-insinuate
1956   "t" gnus-article-babel)
1957
1958 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1959   "b" gnus-article-add-buttons
1960   "B" gnus-article-add-buttons-to-head
1961   "o" gnus-article-treat-overstrike
1962   "e" gnus-article-emphasize
1963   "w" gnus-article-fill-cited-article
1964   "Q" gnus-article-fill-long-lines
1965   "C" gnus-article-capitalize-sentences
1966   "c" gnus-article-remove-cr
1967   "Z" gnus-article-decode-HZ
1968   "A" gnus-article-treat-ansi-sequences
1969   "h" gnus-article-wash-html
1970   "u" gnus-article-unsplit-urls
1971   "f" gnus-article-display-x-face
1972   "l" gnus-summary-stop-page-breaking
1973   "r" gnus-summary-caesar-message
1974   "m" gnus-summary-morse-message
1975   "t" gnus-summary-toggle-header
1976   "g" gnus-treat-smiley
1977   "v" gnus-summary-verbose-headers
1978   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1979   "p" gnus-article-verify-x-pgp-sig
1980   "d" gnus-article-treat-dumbquotes
1981   "i" gnus-summary-idna-message)
1982
1983 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1984   ;; mnemonic: deuglif*Y*
1985   "u" gnus-article-outlook-unwrap-lines
1986   "a" gnus-article-outlook-repair-attribution
1987   "c" gnus-article-outlook-rearrange-citation
1988   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1989
1990 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1991   "a" gnus-article-hide
1992   "h" gnus-article-hide-headers
1993   "b" gnus-article-hide-boring-headers
1994   "s" gnus-article-hide-signature
1995   "c" gnus-article-hide-citation
1996   "C" gnus-article-hide-citation-in-followups
1997   "l" gnus-article-hide-list-identifiers
1998   "B" gnus-article-strip-banner
1999   "P" gnus-article-hide-pem
2000   "\C-c" gnus-article-hide-citation-maybe)
2001
2002 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2003   "a" gnus-article-highlight
2004   "h" gnus-article-highlight-headers
2005   "c" gnus-article-highlight-citation
2006   "s" gnus-article-highlight-signature)
2007
2008 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2009   "f" gnus-article-treat-fold-headers
2010   "u" gnus-article-treat-unfold-headers
2011   "n" gnus-article-treat-fold-newsgroups)
2012
2013 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2014   "x" gnus-article-display-x-face
2015   "d" gnus-article-display-face
2016   "s" gnus-treat-smiley
2017   "D" gnus-article-remove-images
2018   "f" gnus-treat-from-picon
2019   "m" gnus-treat-mail-picon
2020   "n" gnus-treat-newsgroups-picon)
2021
2022 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2023   "z" gnus-article-date-ut
2024   "u" gnus-article-date-ut
2025   "l" gnus-article-date-local
2026   "p" gnus-article-date-english
2027   "e" gnus-article-date-lapsed
2028   "o" gnus-article-date-original
2029   "i" gnus-article-date-iso8601
2030   "s" gnus-article-date-user)
2031
2032 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2033   "t" gnus-article-remove-trailing-blank-lines
2034   "l" gnus-article-strip-leading-blank-lines
2035   "m" gnus-article-strip-multiple-blank-lines
2036   "a" gnus-article-strip-blank-lines
2037   "A" gnus-article-strip-all-blank-lines
2038   "s" gnus-article-strip-leading-space
2039   "e" gnus-article-strip-trailing-space
2040   "w" gnus-article-remove-leading-whitespace)
2041
2042 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2043   "v" gnus-version
2044   "f" gnus-summary-fetch-faq
2045   "d" gnus-summary-describe-group
2046   "h" gnus-summary-describe-briefly
2047   "i" gnus-info-find-node
2048   "c" gnus-group-fetch-charter
2049   "C" gnus-group-fetch-control)
2050
2051 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2052   "e" gnus-summary-expire-articles
2053   "\M-\C-e" gnus-summary-expire-articles-now
2054   "\177" gnus-summary-delete-article
2055   [delete] gnus-summary-delete-article
2056   [backspace] gnus-summary-delete-article
2057   "m" gnus-summary-move-article
2058   "r" gnus-summary-respool-article
2059   "w" gnus-summary-edit-article
2060   "c" gnus-summary-copy-article
2061   "B" gnus-summary-crosspost-article
2062   "q" gnus-summary-respool-query
2063   "t" gnus-summary-respool-trace
2064   "i" gnus-summary-import-article
2065   "I" gnus-summary-create-article
2066   "p" gnus-summary-article-posted-p)
2067
2068 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2069   "o" gnus-summary-save-article
2070   "m" gnus-summary-save-article-mail
2071   "F" gnus-summary-write-article-file
2072   "r" gnus-summary-save-article-rmail
2073   "f" gnus-summary-save-article-file
2074   "b" gnus-summary-save-article-body-file
2075   "h" gnus-summary-save-article-folder
2076   "v" gnus-summary-save-article-vm
2077   "p" gnus-summary-pipe-output
2078   "P" gnus-summary-muttprint
2079   "s" gnus-soup-add-article)
2080
2081 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2082   "b" gnus-summary-display-buttonized
2083   "m" gnus-summary-repair-multipart
2084   "v" gnus-article-view-part
2085   "o" gnus-article-save-part
2086   "O" gnus-article-save-part-and-strip
2087   "r" gnus-article-replace-part
2088   "d" gnus-article-delete-part
2089   "j" gnus-article-jump-to-part
2090   "c" gnus-article-copy-part
2091   "C" gnus-article-view-part-as-charset
2092   "e" gnus-article-view-part-externally
2093   "E" gnus-article-encrypt-body
2094   "i" gnus-article-inline-part
2095   "|" gnus-article-pipe-part)
2096
2097 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2098   "p" gnus-summary-mark-as-processable
2099   "u" gnus-summary-unmark-as-processable
2100   "U" gnus-summary-unmark-all-processable
2101   "v" gnus-uu-mark-over
2102   "s" gnus-uu-mark-series
2103   "r" gnus-uu-mark-region
2104   "g" gnus-uu-unmark-region
2105   "R" gnus-uu-mark-by-regexp
2106   "G" gnus-uu-unmark-by-regexp
2107   "t" gnus-uu-mark-thread
2108   "T" gnus-uu-unmark-thread
2109   "a" gnus-uu-mark-all
2110   "b" gnus-uu-mark-buffer
2111   "S" gnus-uu-mark-sparse
2112   "k" gnus-summary-kill-process-mark
2113   "y" gnus-summary-yank-process-mark
2114   "w" gnus-summary-save-process-mark
2115   "i" gnus-uu-invert-processable)
2116
2117 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2118   ;;"x" gnus-uu-extract-any
2119   "m" gnus-summary-save-parts
2120   "u" gnus-uu-decode-uu
2121   "U" gnus-uu-decode-uu-and-save
2122   "s" gnus-uu-decode-unshar
2123   "S" gnus-uu-decode-unshar-and-save
2124   "o" gnus-uu-decode-save
2125   "O" gnus-uu-decode-save
2126   "b" gnus-uu-decode-binhex
2127   "B" gnus-uu-decode-binhex
2128   "p" gnus-uu-decode-postscript
2129   "P" gnus-uu-decode-postscript-and-save)
2130
2131 (gnus-define-keys
2132     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2133   "u" gnus-uu-decode-uu-view
2134   "U" gnus-uu-decode-uu-and-save-view
2135   "s" gnus-uu-decode-unshar-view
2136   "S" gnus-uu-decode-unshar-and-save-view
2137   "o" gnus-uu-decode-save-view
2138   "O" gnus-uu-decode-save-view
2139   "b" gnus-uu-decode-binhex-view
2140   "B" gnus-uu-decode-binhex-view
2141   "p" gnus-uu-decode-postscript-view
2142   "P" gnus-uu-decode-postscript-and-save-view)
2143
2144 (defvar gnus-article-post-menu nil)
2145
2146 (defconst gnus-summary-menu-maxlen 20)
2147
2148 (defun gnus-summary-menu-split (menu)
2149   ;; If we have lots of elements, divide them into groups of 20
2150   ;; and make a pane (or submenu) for each one.
2151   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2152       (let ((menu menu) sublists next
2153             (i 1))
2154         (while menu
2155           ;; Pull off the next gnus-summary-menu-maxlen elements
2156           ;; and make them the next element of sublist.
2157           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2158           (if next
2159               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2160                       nil))
2161           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2162                                              (aref (car (last menu)) 0)) menu)
2163                                sublists))
2164           (setq i (1+ i))
2165           (setq menu next))
2166         (nreverse sublists))
2167     ;; Few elements--put them all in one pane.
2168     menu))
2169
2170 (defun gnus-summary-make-menu-bar ()
2171   (gnus-turn-off-edit-menu 'summary)
2172
2173   (unless (boundp 'gnus-summary-misc-menu)
2174
2175     (easy-menu-define
2176       gnus-summary-kill-menu gnus-summary-mode-map ""
2177       (cons
2178        "Score"
2179        (nconc
2180         (list
2181          ["Customize" gnus-score-customize t])
2182         (gnus-make-score-map 'increase)
2183         (gnus-make-score-map 'lower)
2184         '(("Mark"
2185            ["Kill below" gnus-summary-kill-below t]
2186            ["Mark above" gnus-summary-mark-above t]
2187            ["Tick above" gnus-summary-tick-above t]
2188            ["Clear above" gnus-summary-clear-above t])
2189           ["Current score" gnus-summary-current-score t]
2190           ["Set score" gnus-summary-set-score t]
2191           ["Switch current score file..." gnus-score-change-score-file t]
2192           ["Set mark below..." gnus-score-set-mark-below t]
2193           ["Set expunge below..." gnus-score-set-expunge-below t]
2194           ["Edit current score file" gnus-score-edit-current-scores t]
2195           ["Edit score file" gnus-score-edit-file t]
2196           ["Trace score" gnus-score-find-trace t]
2197           ["Find words" gnus-score-find-favourite-words t]
2198           ["Rescore buffer" gnus-summary-rescore t]
2199           ["Increase score..." gnus-summary-increase-score t]
2200           ["Lower score..." gnus-summary-lower-score t]))))
2201
2202     ;; Define both the Article menu in the summary buffer and the
2203     ;; equivalent Commands menu in the article buffer here for
2204     ;; consistency.
2205     (let ((innards
2206            `(("Hide"
2207               ["All" gnus-article-hide t]
2208               ["Headers" gnus-article-hide-headers t]
2209               ["Signature" gnus-article-hide-signature t]
2210               ["Citation" gnus-article-hide-citation t]
2211               ["List identifiers" gnus-article-hide-list-identifiers t]
2212               ["Banner" gnus-article-strip-banner t]
2213               ["Boring headers" gnus-article-hide-boring-headers t])
2214              ("Highlight"
2215               ["All" gnus-article-highlight t]
2216               ["Headers" gnus-article-highlight-headers t]
2217               ["Signature" gnus-article-highlight-signature t]
2218               ["Citation" gnus-article-highlight-citation t])
2219              ("Date"
2220               ["Local" gnus-article-date-local t]
2221               ["ISO8601" gnus-article-date-iso8601 t]
2222               ["UT" gnus-article-date-ut t]
2223               ["Original" gnus-article-date-original t]
2224               ["Lapsed" gnus-article-date-lapsed t]
2225               ["User-defined" gnus-article-date-user t])
2226              ("Display"
2227               ["Remove images" gnus-article-remove-images t]
2228               ["Toggle smiley" gnus-treat-smiley t]
2229               ["Show X-Face" gnus-article-display-x-face t]
2230               ["Show picons in From" gnus-treat-from-picon t]
2231               ["Show picons in mail headers" gnus-treat-mail-picon t]
2232               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2233               ("View as different encoding"
2234                ,@(gnus-summary-menu-split
2235                   (mapcar
2236                    (lambda (cs)
2237                      ;; Since easymenu under Emacs doesn't allow
2238                      ;; lambda forms for menu commands, we should
2239                      ;; provide intern'ed function symbols.
2240                      (let ((command (intern (format "\
2241 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2242                        (fset command
2243                              `(lambda ()
2244                                 (interactive)
2245                                 (let ((gnus-summary-show-article-charset-alist
2246                                        '((1 . ,cs))))
2247                                   (gnus-summary-show-article 1))))
2248                        `[,(symbol-name cs) ,command t]))
2249                    (sort (if (fboundp 'coding-system-list)
2250                              (coding-system-list)
2251                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2252                            )
2253                          'string<)))))
2254              ("Washing"
2255               ("Remove Blanks"
2256                ["Leading" gnus-article-strip-leading-blank-lines t]
2257                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2258                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2259                ["All of the above" gnus-article-strip-blank-lines t]
2260                ["All" gnus-article-strip-all-blank-lines t]
2261                ["Leading space" gnus-article-strip-leading-space t]
2262                ["Trailing space" gnus-article-strip-trailing-space t]
2263                ["Leading space in headers"
2264                 gnus-article-remove-leading-whitespace t])
2265               ["Overstrike" gnus-article-treat-overstrike t]
2266               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2267               ["Emphasis" gnus-article-emphasize t]
2268               ["Word wrap" gnus-article-fill-cited-article t]
2269               ["Fill long lines" gnus-article-fill-long-lines t]
2270               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2271               ["Remove CR" gnus-article-remove-cr t]
2272               ["Rot 13" gnus-summary-caesar-message
2273                ,@(if (featurep 'xemacs) '(t)
2274                    '(:help "\"Caesar rotate\" article by 13"))]
2275               ["De-IDNA" gnus-summary-idna-message t]
2276               ["Morse decode" gnus-summary-morse-message t]
2277               ["Unix pipe..." gnus-summary-pipe-message t]
2278               ["Add buttons" gnus-article-add-buttons t]
2279               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2280               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2281               ["Toggle MIME" gnus-summary-toggle-mime t]
2282               ["Verbose header" gnus-summary-verbose-headers t]
2283               ["Toggle header" gnus-summary-toggle-header t]
2284               ["Unfold headers" gnus-article-treat-unfold-headers t]
2285               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2286               ["Html" gnus-article-wash-html t]
2287               ["Unsplit URLs" gnus-article-unsplit-urls t]
2288               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2289               ["Decode HZ" gnus-article-decode-HZ t]
2290               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2291               ("(Outlook) Deuglify"
2292                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2293                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2294                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2295                ["Full (Outlook) deuglify"
2296                 gnus-article-outlook-deuglify-article t])
2297               )
2298              ("Output"
2299               ["Save in default format..." gnus-summary-save-article
2300                ,@(if (featurep 'xemacs) '(t)
2301                    '(:help "Save article using default method"))]
2302               ["Save in file..." gnus-summary-save-article-file
2303                ,@(if (featurep 'xemacs) '(t)
2304                    '(:help "Save article in file"))]
2305               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2306               ["Save in MH folder..." gnus-summary-save-article-folder t]
2307               ["Save in VM folder..." gnus-summary-save-article-vm t]
2308               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2309               ["Save body in file..." gnus-summary-save-article-body-file t]
2310               ["Pipe through a filter..." gnus-summary-pipe-output t]
2311               ["Add to SOUP packet" gnus-soup-add-article t]
2312               ["Print with Muttprint..." gnus-summary-muttprint t]
2313               ["Print" gnus-summary-print-article
2314                ,@(if (featurep 'xemacs) '(t)
2315                    '(:help "Generate and print a PostScript image"))])
2316              ("Copy, move,... (Backend)"
2317               ,@(if (featurep 'xemacs) nil
2318                   '(:help "Copying, moving, expiring articles..."))
2319               ["Respool article..." gnus-summary-respool-article t]
2320               ["Move article..." gnus-summary-move-article
2321                (gnus-check-backend-function
2322                 'request-move-article gnus-newsgroup-name)]
2323               ["Copy article..." gnus-summary-copy-article t]
2324               ["Crosspost article..." gnus-summary-crosspost-article
2325                (gnus-check-backend-function
2326                 'request-replace-article gnus-newsgroup-name)]
2327               ["Import file..." gnus-summary-import-article
2328                (gnus-check-backend-function
2329                 'request-accept-article gnus-newsgroup-name)]
2330               ["Create article..." gnus-summary-create-article
2331                (gnus-check-backend-function
2332                 'request-accept-article gnus-newsgroup-name)]
2333               ["Check if posted" gnus-summary-article-posted-p t]
2334               ["Edit article" gnus-summary-edit-article
2335                (not (gnus-group-read-only-p))]
2336               ["Delete article" gnus-summary-delete-article
2337                (gnus-check-backend-function
2338                 'request-expire-articles gnus-newsgroup-name)]
2339               ["Query respool" gnus-summary-respool-query t]
2340               ["Trace respool" gnus-summary-respool-trace t]
2341               ["Delete expirable articles" gnus-summary-expire-articles-now
2342                (gnus-check-backend-function
2343                 'request-expire-articles gnus-newsgroup-name)])
2344              ("Extract"
2345               ["Uudecode" gnus-uu-decode-uu
2346                ,@(if (featurep 'xemacs) '(t)
2347                    '(:help "Decode uuencoded article(s)"))]
2348               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2349               ["Unshar" gnus-uu-decode-unshar t]
2350               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2351               ["Save" gnus-uu-decode-save t]
2352               ["Binhex" gnus-uu-decode-binhex t]
2353               ["Postscript" gnus-uu-decode-postscript t])
2354              ("Cache"
2355               ["Enter article" gnus-cache-enter-article t]
2356               ["Remove article" gnus-cache-remove-article t])
2357              ["Translate" gnus-article-babel t]
2358              ["Select article buffer" gnus-summary-select-article-buffer t]
2359              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2360              ["Isearch article..." gnus-summary-isearch-article t]
2361              ["Beginning of the article" gnus-summary-beginning-of-article t]
2362              ["End of the article" gnus-summary-end-of-article t]
2363              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2364              ["Fetch referenced articles" gnus-summary-refer-references t]
2365              ["Fetch current thread" gnus-summary-refer-thread t]
2366              ["Fetch article with id..." gnus-summary-refer-article t]
2367              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2368              ["Redisplay" gnus-summary-show-article t]
2369              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2370       (easy-menu-define
2371         gnus-summary-article-menu gnus-summary-mode-map ""
2372         (cons "Article" innards))
2373
2374       (if (not (keymapp gnus-summary-article-menu))
2375           (easy-menu-define
2376             gnus-article-commands-menu gnus-article-mode-map ""
2377             (cons "Commands" innards))
2378         ;; in Emacs, don't share menu.
2379         (setq gnus-article-commands-menu
2380               (copy-keymap gnus-summary-article-menu))
2381         (define-key gnus-article-mode-map [menu-bar commands]
2382           (cons "Commands" gnus-article-commands-menu))))
2383
2384     (easy-menu-define
2385       gnus-summary-thread-menu gnus-summary-mode-map ""
2386       '("Threads"
2387         ["Find all messages in thread" gnus-summary-refer-thread t]
2388         ["Toggle threading" gnus-summary-toggle-threads t]
2389         ["Hide threads" gnus-summary-hide-all-threads t]
2390         ["Show threads" gnus-summary-show-all-threads t]
2391         ["Hide thread" gnus-summary-hide-thread t]
2392         ["Show thread" gnus-summary-show-thread t]
2393         ["Go to next thread" gnus-summary-next-thread t]
2394         ["Go to previous thread" gnus-summary-prev-thread t]
2395         ["Go down thread" gnus-summary-down-thread t]
2396         ["Go up thread" gnus-summary-up-thread t]
2397         ["Top of thread" gnus-summary-top-thread t]
2398         ["Mark thread as read" gnus-summary-kill-thread t]
2399         ["Lower thread score" gnus-summary-lower-thread t]
2400         ["Raise thread score" gnus-summary-raise-thread t]
2401         ["Rethread current" gnus-summary-rethread-current t]))
2402
2403     (easy-menu-define
2404       gnus-summary-post-menu gnus-summary-mode-map ""
2405       `("Post"
2406         ["Send a message (mail or news)" gnus-summary-post-news
2407          ,@(if (featurep 'xemacs) '(t)
2408              '(:help "Compose a new message (mail or news)"))]
2409         ["Followup" gnus-summary-followup
2410          ,@(if (featurep 'xemacs) '(t)
2411              '(:help "Post followup to this article"))]
2412         ["Followup and yank" gnus-summary-followup-with-original
2413          ,@(if (featurep 'xemacs) '(t)
2414              '(:help "Post followup to this article, quoting its contents"))]
2415         ["Supersede article" gnus-summary-supersede-article t]
2416         ["Cancel article" gnus-summary-cancel-article
2417          ,@(if (featurep 'xemacs) '(t)
2418              '(:help "Cancel an article you posted"))]
2419         ["Reply" gnus-summary-reply t]
2420         ["Reply and yank" gnus-summary-reply-with-original t]
2421         ["Wide reply" gnus-summary-wide-reply t]
2422         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2423          ,@(if (featurep 'xemacs) '(t)
2424              '(:help "Mail a reply, quoting this article"))]
2425         ["Very wide reply" gnus-summary-very-wide-reply t]
2426         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2427          ,@(if (featurep 'xemacs) '(t)
2428              '(:help "Mail a very wide reply, quoting this article"))]
2429         ["Mail forward" gnus-summary-mail-forward t]
2430         ["Post forward" gnus-summary-post-forward t]
2431         ["Digest and mail" gnus-summary-digest-mail-forward t]
2432         ["Digest and post" gnus-summary-digest-post-forward t]
2433         ["Resend message" gnus-summary-resend-message t]
2434         ["Resend message edit" gnus-summary-resend-message-edit t]
2435         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2436         ["Send a mail" gnus-summary-mail-other-window t]
2437         ["Create a local message" gnus-summary-news-other-window t]
2438         ["Uuencode and post" gnus-uu-post-news
2439          ,@(if (featurep 'xemacs) '(t)
2440              '(:help "Post a uuencoded article"))]
2441         ["Followup via news" gnus-summary-followup-to-mail t]
2442         ["Followup via news and yank"
2443          gnus-summary-followup-to-mail-with-original t]
2444         ;;("Draft"
2445         ;;["Send" gnus-summary-send-draft t]
2446         ;;["Send bounced" gnus-resend-bounced-mail t])
2447         ))
2448
2449     (cond
2450      ((not (keymapp gnus-summary-post-menu))
2451       (setq gnus-article-post-menu gnus-summary-post-menu))
2452      ((not gnus-article-post-menu)
2453       ;; Don't share post menu.
2454       (setq gnus-article-post-menu
2455             (copy-keymap gnus-summary-post-menu))))
2456     (define-key gnus-article-mode-map [menu-bar post]
2457       (cons "Post" gnus-article-post-menu))
2458
2459     (easy-menu-define
2460       gnus-summary-misc-menu gnus-summary-mode-map ""
2461       `("Gnus"
2462         ("Mark Read"
2463          ["Mark as read" gnus-summary-mark-as-read-forward t]
2464          ["Mark same subject and select"
2465           gnus-summary-kill-same-subject-and-select t]
2466          ["Mark same subject" gnus-summary-kill-same-subject t]
2467          ["Catchup" gnus-summary-catchup
2468           ,@(if (featurep 'xemacs) '(t)
2469               '(:help "Mark unread articles in this group as read"))]
2470          ["Catchup all" gnus-summary-catchup-all t]
2471          ["Catchup to here" gnus-summary-catchup-to-here t]
2472          ["Catchup from here" gnus-summary-catchup-from-here t]
2473          ["Catchup region" gnus-summary-mark-region-as-read
2474           (gnus-mark-active-p)]
2475          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2476         ("Mark Various"
2477          ["Tick" gnus-summary-tick-article-forward t]
2478          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2479          ["Remove marks" gnus-summary-clear-mark-forward t]
2480          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2481          ["Set bookmark" gnus-summary-set-bookmark t]
2482          ["Remove bookmark" gnus-summary-remove-bookmark t])
2483         ("Limit to"
2484          ["Marks..." gnus-summary-limit-to-marks t]
2485          ["Subject..." gnus-summary-limit-to-subject t]
2486          ["Author..." gnus-summary-limit-to-author t]
2487          ["Recipient..." gnus-summary-limit-to-recipient t]
2488          ["Age..." gnus-summary-limit-to-age t]
2489          ["Extra..." gnus-summary-limit-to-extra t]
2490          ["Score..." gnus-summary-limit-to-score t]
2491          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2492          ["Unread" gnus-summary-limit-to-unread t]
2493          ["Unseen" gnus-summary-limit-to-unseen t]
2494          ["Replied" gnus-summary-limit-to-replied t]
2495          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2496          ["Next articles" gnus-summary-limit-to-articles t]
2497          ["Pop limit" gnus-summary-pop-limit t]
2498          ["Show dormant" gnus-summary-limit-include-dormant t]
2499          ["Hide childless dormant"
2500           gnus-summary-limit-exclude-childless-dormant t]
2501          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2502          ["Hide marked" gnus-summary-limit-exclude-marks t]
2503          ["Show expunged" gnus-summary-limit-include-expunged t])
2504         ("Process Mark"
2505          ["Set mark" gnus-summary-mark-as-processable t]
2506          ["Remove mark" gnus-summary-unmark-as-processable t]
2507          ["Remove all marks" gnus-summary-unmark-all-processable t]
2508          ["Invert marks" gnus-uu-invert-processable t]
2509          ["Mark above" gnus-uu-mark-over t]
2510          ["Mark series" gnus-uu-mark-series t]
2511          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2512          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2513          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2514          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2515          ["Mark all" gnus-uu-mark-all t]
2516          ["Mark buffer" gnus-uu-mark-buffer t]
2517          ["Mark sparse" gnus-uu-mark-sparse t]
2518          ["Mark thread" gnus-uu-mark-thread t]
2519          ["Unmark thread" gnus-uu-unmark-thread t]
2520          ("Process Mark Sets"
2521           ["Kill" gnus-summary-kill-process-mark t]
2522           ["Yank" gnus-summary-yank-process-mark
2523            gnus-newsgroup-process-stack]
2524           ["Save" gnus-summary-save-process-mark t]
2525           ["Run command on marked..." gnus-summary-universal-argument t]))
2526         ("Scroll article"
2527          ["Page forward" gnus-summary-next-page
2528           ,@(if (featurep 'xemacs) '(t)
2529               '(:help "Show next page of article"))]
2530          ["Page backward" gnus-summary-prev-page
2531           ,@(if (featurep 'xemacs) '(t)
2532               '(:help "Show previous page of article"))]
2533          ["Line forward" gnus-summary-scroll-up t])
2534         ("Move"
2535          ["Next unread article" gnus-summary-next-unread-article t]
2536          ["Previous unread article" gnus-summary-prev-unread-article t]
2537          ["Next article" gnus-summary-next-article t]
2538          ["Previous article" gnus-summary-prev-article t]
2539          ["Next unread subject" gnus-summary-next-unread-subject t]
2540          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2541          ["Next article same subject" gnus-summary-next-same-subject t]
2542          ["Previous article same subject" gnus-summary-prev-same-subject t]
2543          ["First unread article" gnus-summary-first-unread-article t]
2544          ["Best unread article" gnus-summary-best-unread-article t]
2545          ["Go to subject number..." gnus-summary-goto-subject t]
2546          ["Go to article number..." gnus-summary-goto-article t]
2547          ["Go to the last article" gnus-summary-goto-last-article t]
2548          ["Pop article off history" gnus-summary-pop-article t])
2549         ("Sort"
2550          ["Sort by number" gnus-summary-sort-by-number t]
2551          ["Sort by author" gnus-summary-sort-by-author t]
2552          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2553          ["Sort by subject" gnus-summary-sort-by-subject t]
2554          ["Sort by date" gnus-summary-sort-by-date t]
2555          ["Sort by score" gnus-summary-sort-by-score t]
2556          ["Sort by lines" gnus-summary-sort-by-lines t]
2557          ["Sort by characters" gnus-summary-sort-by-chars t]
2558          ["Randomize" gnus-summary-sort-by-random t]
2559          ["Original sort" gnus-summary-sort-by-original t])
2560         ("Help"
2561          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2562          ["Describe group" gnus-summary-describe-group t]
2563          ["Fetch charter" gnus-group-fetch-charter
2564           ,@(if (featurep 'xemacs) nil
2565               '(:help "Display the charter of the current group"))]
2566          ["Fetch control message" gnus-group-fetch-control
2567           ,@(if (featurep 'xemacs) nil
2568               '(:help "Display the archived control message for the current group"))]
2569          ["Read manual" gnus-info-find-node t])
2570         ("Modes"
2571          ["Pick and read" gnus-pick-mode t]
2572          ["Binary" gnus-binary-mode t])
2573         ("Regeneration"
2574          ["Regenerate" gnus-summary-prepare t]
2575          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2576          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2577          ["Toggle threading" gnus-summary-toggle-threads t])
2578         ["See old articles" gnus-summary-insert-old-articles t]
2579         ["See new articles" gnus-summary-insert-new-articles t]
2580         ["Filter articles..." gnus-summary-execute-command t]
2581         ["Run command on articles..." gnus-summary-universal-argument t]
2582         ["Search articles forward..." gnus-summary-search-article-forward t]
2583         ["Search articles backward..." gnus-summary-search-article-backward t]
2584         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2585         ["Expand window" gnus-summary-expand-window t]
2586         ["Expire expirable articles" gnus-summary-expire-articles
2587          (gnus-check-backend-function
2588           'request-expire-articles gnus-newsgroup-name)]
2589         ["Edit local kill file" gnus-summary-edit-local-kill t]
2590         ["Edit main kill file" gnus-summary-edit-global-kill t]
2591         ["Edit group parameters" gnus-summary-edit-parameters t]
2592         ["Customize group parameters" gnus-summary-customize-parameters t]
2593         ["Send a bug report" gnus-bug t]
2594         ("Exit"
2595          ["Catchup and exit" gnus-summary-catchup-and-exit
2596           ,@(if (featurep 'xemacs) '(t)
2597               '(:help "Mark unread articles in this group as read, then exit"))]
2598          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2599          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2600          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2601          ["Exit group" gnus-summary-exit
2602           ,@(if (featurep 'xemacs) '(t)
2603               '(:help "Exit current group, return to group selection mode"))]
2604          ["Exit group without updating" gnus-summary-exit-no-update t]
2605          ["Exit and goto next group" gnus-summary-next-group t]
2606          ["Exit and goto prev group" gnus-summary-prev-group t]
2607          ["Reselect group" gnus-summary-reselect-current-group t]
2608          ["Rescan group" gnus-summary-rescan-group t]
2609          ["Update dribble" gnus-summary-save-newsrc t])))
2610
2611     (gnus-run-hooks 'gnus-summary-menu-hook)))
2612
2613 (defvar gnus-summary-tool-bar-map nil)
2614
2615 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2616 (defun gnus-summary-make-tool-bar ()
2617   (if (and (fboundp 'tool-bar-add-item-from-menu)
2618            (default-value 'tool-bar-mode)
2619            (not gnus-summary-tool-bar-map))
2620       (setq gnus-summary-tool-bar-map
2621             (let ((tool-bar-map (make-sparse-keymap))
2622                   (load-path (mm-image-load-path)))
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-post-news "post" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-followup "followup" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-summary-reply "reply" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2649               (tool-bar-add-item-from-menu
2650                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2651               (tool-bar-add-item-from-menu
2652                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2653               (tool-bar-add-item-from-menu
2654                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2655               tool-bar-map)))
2656   (if gnus-summary-tool-bar-map
2657       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2658
2659 (defun gnus-score-set-default (var value)
2660   "A version of set that updates the GNU Emacs menu-bar."
2661   (set var value)
2662   ;; It is the message that forces the active status to be updated.
2663   (message ""))
2664
2665 (defun gnus-make-score-map (type)
2666   "Make a summary score map of type TYPE."
2667   (if t
2668       nil
2669     (let ((headers '(("author" "from" string)
2670                      ("subject" "subject" string)
2671                      ("article body" "body" string)
2672                      ("article head" "head" string)
2673                      ("xref" "xref" string)
2674                      ("extra header" "extra" string)
2675                      ("lines" "lines" number)
2676                      ("followups to author" "followup" string)))
2677           (types '((number ("less than" <)
2678                            ("greater than" >)
2679                            ("equal" =))
2680                    (string ("substring" s)
2681                            ("exact string" e)
2682                            ("fuzzy string" f)
2683                            ("regexp" r))))
2684           (perms '(("temporary" (current-time-string))
2685                    ("permanent" nil)
2686                    ("immediate" now)))
2687           header)
2688       (list
2689        (apply
2690         'nconc
2691         (list
2692          (if (eq type 'lower)
2693              "Lower score"
2694            "Increase score"))
2695         (let (outh)
2696           (while headers
2697             (setq header (car headers))
2698             (setq outh
2699                   (cons
2700                    (apply
2701                     'nconc
2702                     (list (car header))
2703                     (let ((ts (cdr (assoc (nth 2 header) types)))
2704                           outt)
2705                       (while ts
2706                         (setq outt
2707                               (cons
2708                                (apply
2709                                 'nconc
2710                                 (list (caar ts))
2711                                 (let ((ps perms)
2712                                       outp)
2713                                   (while ps
2714                                     (setq outp
2715                                           (cons
2716                                            (vector
2717                                             (caar ps)
2718                                             (list
2719                                              'gnus-summary-score-entry
2720                                              (nth 1 header)
2721                                              (if (or (string= (nth 1 header)
2722                                                               "head")
2723                                                      (string= (nth 1 header)
2724                                                               "body"))
2725                                                  ""
2726                                                (list 'gnus-summary-header
2727                                                      (nth 1 header)))
2728                                              (list 'quote (nth 1 (car ts)))
2729                                              (list 'gnus-score-delta-default
2730                                                    nil)
2731                                              (nth 1 (car ps))
2732                                              t)
2733                                             t)
2734                                            outp))
2735                                     (setq ps (cdr ps)))
2736                                   (list (nreverse outp))))
2737                                outt))
2738                         (setq ts (cdr ts)))
2739                       (list (nreverse outt))))
2740                    outh))
2741             (setq headers (cdr headers)))
2742           (list (nreverse outh))))))))
2743
2744 \f
2745
2746 (defun gnus-summary-mode (&optional group)
2747   "Major mode for reading articles.
2748
2749 All normal editing commands are switched off.
2750 \\<gnus-summary-mode-map>
2751 Each line in this buffer represents one article.  To read an
2752 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2753 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2754 respectively.
2755
2756 You can also post articles and send mail from this buffer.  To
2757 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2758 of an article, type `\\[gnus-summary-reply]'.
2759
2760 There are approx. one gazillion commands you can execute in this
2761 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2762
2763 The following commands are available:
2764
2765 \\{gnus-summary-mode-map}"
2766   (interactive)
2767   (kill-all-local-variables)
2768   (when (gnus-visual-p 'summary-menu 'menu)
2769     (gnus-summary-make-menu-bar)
2770     (gnus-summary-make-tool-bar))
2771   (gnus-summary-make-local-variables)
2772   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2773     (gnus-summary-make-local-variables))
2774   (gnus-make-thread-indent-array)
2775   (gnus-simplify-mode-line)
2776   (setq major-mode 'gnus-summary-mode)
2777   (setq mode-name "Summary")
2778   (make-local-variable 'minor-mode-alist)
2779   (use-local-map gnus-summary-mode-map)
2780   (buffer-disable-undo)
2781   (setq buffer-read-only t              ;Disable modification
2782         show-trailing-whitespace nil)
2783   (setq truncate-lines t)
2784   (setq selective-display t)
2785   (setq selective-display-ellipses t)   ;Display `...'
2786   (gnus-summary-set-display-table)
2787   (gnus-set-default-directory)
2788   (setq gnus-newsgroup-name group)
2789   (unless (gnus-news-group-p group)
2790     (setq gnus-newsgroup-incorporated
2791           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2792   (make-local-variable 'gnus-summary-line-format)
2793   (make-local-variable 'gnus-summary-line-format-spec)
2794   (make-local-variable 'gnus-summary-dummy-line-format)
2795   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2796   (make-local-variable 'gnus-summary-mark-positions)
2797   (gnus-make-local-hook 'pre-command-hook)
2798   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2799   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2800   (turn-on-gnus-mailing-list-mode)
2801   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2802   (gnus-update-summary-mark-positions))
2803
2804 (defun gnus-summary-make-local-variables ()
2805   "Make all the local summary buffer variables."
2806   (let (global)
2807     (dolist (local gnus-summary-local-variables)
2808       (if (consp local)
2809           (progn
2810             (if (eq (cdr local) 'global)
2811                 ;; Copy the global value of the variable.
2812                 (setq global (symbol-value (car local)))
2813               ;; Use the value from the list.
2814               (setq global (eval (cdr local))))
2815             (set (make-local-variable (car local)) global))
2816         ;; Simple nil-valued local variable.
2817         (set (make-local-variable local) nil)))))
2818
2819 (defun gnus-summary-clear-local-variables ()
2820   (let ((locals gnus-summary-local-variables))
2821     (while locals
2822       (if (consp (car locals))
2823           (and (symbolp (caar locals))
2824                (set (caar locals) nil))
2825         (and (symbolp (car locals))
2826              (set (car locals) nil)))
2827       (setq locals (cdr locals)))))
2828
2829 ;; Summary data functions.
2830
2831 (defmacro gnus-data-number (data)
2832   `(car ,data))
2833
2834 (defmacro gnus-data-set-number (data number)
2835   `(setcar ,data ,number))
2836
2837 (defmacro gnus-data-mark (data)
2838   `(nth 1 ,data))
2839
2840 (defmacro gnus-data-set-mark (data mark)
2841   `(setcar (nthcdr 1 ,data) ,mark))
2842
2843 (defmacro gnus-data-pos (data)
2844   `(nth 2 ,data))
2845
2846 (defmacro gnus-data-set-pos (data pos)
2847   `(setcar (nthcdr 2 ,data) ,pos))
2848
2849 (defmacro gnus-data-header (data)
2850   `(nth 3 ,data))
2851
2852 (defmacro gnus-data-set-header (data header)
2853   `(setcar (nthcdr 3 ,data) ,header))
2854
2855 (defmacro gnus-data-level (data)
2856   `(nth 4 ,data))
2857
2858 (defmacro gnus-data-unread-p (data)
2859   `(= (nth 1 ,data) gnus-unread-mark))
2860
2861 (defmacro gnus-data-read-p (data)
2862   `(/= (nth 1 ,data) gnus-unread-mark))
2863
2864 (defmacro gnus-data-pseudo-p (data)
2865   `(consp (nth 3 ,data)))
2866
2867 (defmacro gnus-data-find (number)
2868   `(assq ,number gnus-newsgroup-data))
2869
2870 (defmacro gnus-data-find-list (number &optional data)
2871   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2872      (memq (assq ,number bdata)
2873            bdata)))
2874
2875 (defmacro gnus-data-make (number mark pos header level)
2876   `(list ,number ,mark ,pos ,header ,level))
2877
2878 (defun gnus-data-enter (after-article number mark pos header level offset)
2879   (let ((data (gnus-data-find-list after-article)))
2880     (unless data
2881       (error "No such article: %d" after-article))
2882     (setcdr data (cons (gnus-data-make number mark pos header level)
2883                        (cdr data)))
2884     (setq gnus-newsgroup-data-reverse nil)
2885     (gnus-data-update-list (cddr data) offset)))
2886
2887 (defun gnus-data-enter-list (after-article list &optional offset)
2888   (when list
2889     (let ((data (and after-article (gnus-data-find-list after-article)))
2890           (ilist list))
2891       (if (not (or data
2892                    after-article))
2893           (let ((odata gnus-newsgroup-data))
2894             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2895             (when offset
2896               (gnus-data-update-list odata offset)))
2897         ;; Find the last element in the list to be spliced into the main
2898         ;; list.
2899         (setq list (last list))
2900         (if (not data)
2901             (progn
2902               (setcdr list gnus-newsgroup-data)
2903               (setq gnus-newsgroup-data ilist)
2904               (when offset
2905                 (gnus-data-update-list (cdr list) offset)))
2906           (setcdr list (cdr data))
2907           (setcdr data ilist)
2908           (when offset
2909             (gnus-data-update-list (cdr list) offset))))
2910       (setq gnus-newsgroup-data-reverse nil))))
2911
2912 (defun gnus-data-remove (article &optional offset)
2913   (let ((data gnus-newsgroup-data))
2914     (if (= (gnus-data-number (car data)) article)
2915         (progn
2916           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2917                 gnus-newsgroup-data-reverse nil)
2918           (when offset
2919             (gnus-data-update-list gnus-newsgroup-data offset)))
2920       (while (cdr data)
2921         (when (= (gnus-data-number (cadr data)) article)
2922           (setcdr data (cddr data))
2923           (when offset
2924             (gnus-data-update-list (cdr data) offset))
2925           (setq data nil
2926                 gnus-newsgroup-data-reverse nil))
2927         (setq data (cdr data))))))
2928
2929 (defmacro gnus-data-list (backward)
2930   `(if ,backward
2931        (or gnus-newsgroup-data-reverse
2932            (setq gnus-newsgroup-data-reverse
2933                  (reverse gnus-newsgroup-data)))
2934      gnus-newsgroup-data))
2935
2936 (defun gnus-data-update-list (data offset)
2937   "Add OFFSET to the POS of all data entries in DATA."
2938   (setq gnus-newsgroup-data-reverse nil)
2939   (while data
2940     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2941     (setq data (cdr data))))
2942
2943 (defun gnus-summary-article-pseudo-p (article)
2944   "Say whether this article is a pseudo article or not."
2945   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2946
2947 (defmacro gnus-summary-article-sparse-p (article)
2948   "Say whether this article is a sparse article or not."
2949   `(memq ,article gnus-newsgroup-sparse))
2950
2951 (defmacro gnus-summary-article-ancient-p (article)
2952   "Say whether this article is a sparse article or not."
2953   `(memq ,article gnus-newsgroup-ancient))
2954
2955 (defun gnus-article-parent-p (number)
2956   "Say whether this article is a parent or not."
2957   (let ((data (gnus-data-find-list number)))
2958     (and (cdr data)                     ; There has to be an article after...
2959          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2960             (gnus-data-level (nth 1 data))))))
2961
2962 (defun gnus-article-children (number)
2963   "Return a list of all children to NUMBER."
2964   (let* ((data (gnus-data-find-list number))
2965          (level (gnus-data-level (car data)))
2966          children)
2967     (setq data (cdr data))
2968     (while (and data
2969                 (= (gnus-data-level (car data)) (1+ level)))
2970       (push (gnus-data-number (car data)) children)
2971       (setq data (cdr data)))
2972     children))
2973
2974 (defmacro gnus-summary-skip-intangible ()
2975   "If the current article is intangible, then jump to a different article."
2976   '(let ((to (get-text-property (point) 'gnus-intangible)))
2977      (and to (gnus-summary-goto-subject to))))
2978
2979 (defmacro gnus-summary-article-intangible-p ()
2980   "Say whether this article is intangible or not."
2981   '(get-text-property (point) 'gnus-intangible))
2982
2983 (defun gnus-article-read-p (article)
2984   "Say whether ARTICLE is read or not."
2985   (not (or (memq article gnus-newsgroup-marked)
2986            (memq article gnus-newsgroup-spam-marked)
2987            (memq article gnus-newsgroup-unreads)
2988            (memq article gnus-newsgroup-unselected)
2989            (memq article gnus-newsgroup-dormant))))
2990
2991 ;; Some summary mode macros.
2992
2993 (defmacro gnus-summary-article-number ()
2994   "The article number of the article on the current line.
2995 If there isn't an article number here, then we return the current
2996 article number."
2997   '(progn
2998      (gnus-summary-skip-intangible)
2999      (or (get-text-property (point) 'gnus-number)
3000          (gnus-summary-last-subject))))
3001
3002 (defmacro gnus-summary-article-header (&optional number)
3003   "Return the header of article NUMBER."
3004   `(gnus-data-header (gnus-data-find
3005                       ,(or number '(gnus-summary-article-number)))))
3006
3007 (defmacro gnus-summary-thread-level (&optional number)
3008   "Return the level of thread that starts with article NUMBER."
3009   `(if (and (eq gnus-summary-make-false-root 'dummy)
3010             (get-text-property (point) 'gnus-intangible))
3011        0
3012      (gnus-data-level (gnus-data-find
3013                        ,(or number '(gnus-summary-article-number))))))
3014
3015 (defmacro gnus-summary-article-mark (&optional number)
3016   "Return the mark of article NUMBER."
3017   `(gnus-data-mark (gnus-data-find
3018                     ,(or number '(gnus-summary-article-number)))))
3019
3020 (defmacro gnus-summary-article-pos (&optional number)
3021   "Return the position of the line of article NUMBER."
3022   `(gnus-data-pos (gnus-data-find
3023                    ,(or number '(gnus-summary-article-number)))))
3024
3025 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3026 (defmacro gnus-summary-article-subject (&optional number)
3027   "Return current subject string or nil if nothing."
3028   `(let ((headers
3029           ,(if number
3030                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3031              '(gnus-data-header (assq (gnus-summary-article-number)
3032                                       gnus-newsgroup-data)))))
3033      (and headers
3034           (vectorp headers)
3035           (mail-header-subject headers))))
3036
3037 (defmacro gnus-summary-article-score (&optional number)
3038   "Return current article score."
3039   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3040                   gnus-newsgroup-scored))
3041        gnus-summary-default-score 0))
3042
3043 (defun gnus-summary-article-children (&optional number)
3044   "Return a list of article numbers that are children of article NUMBER."
3045   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3046          (level (gnus-data-level (car data)))
3047          l children)
3048     (while (and (setq data (cdr data))
3049                 (> (setq l (gnus-data-level (car data))) level))
3050       (and (= (1+ level) l)
3051            (push (gnus-data-number (car data))
3052                  children)))
3053     (nreverse children)))
3054
3055 (defun gnus-summary-article-parent (&optional number)
3056   "Return the article number of the parent of article NUMBER."
3057   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3058                                     (gnus-data-list t)))
3059          (level (gnus-data-level (car data))))
3060     (if (zerop level)
3061         ()                              ; This is a root.
3062       ;; We search until we find an article with a level less than
3063       ;; this one.  That function has to be the parent.
3064       (while (and (setq data (cdr data))
3065                   (not (< (gnus-data-level (car data)) level))))
3066       (and data (gnus-data-number (car data))))))
3067
3068 (defun gnus-unread-mark-p (mark)
3069   "Say whether MARK is the unread mark."
3070   (= mark gnus-unread-mark))
3071
3072 (defun gnus-read-mark-p (mark)
3073   "Say whether MARK is one of the marks that mark as read.
3074 This is all marks except unread, ticked, dormant, and expirable."
3075   (not (or (= mark gnus-unread-mark)
3076            (= mark gnus-ticked-mark)
3077            (= mark gnus-spam-mark)
3078            (= mark gnus-dormant-mark)
3079            (= mark gnus-expirable-mark))))
3080
3081 (defmacro gnus-article-mark (number)
3082   "Return the MARK of article NUMBER.
3083 This macro should only be used when computing the mark the \"first\"
3084 time; i.e., when generating the summary lines.  After that,
3085 `gnus-summary-article-mark' should be used to examine the
3086 marks of articles."
3087   `(cond
3088     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3089     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3090     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3091     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3092     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3093     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3094     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3095     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3096            gnus-ancient-mark))))
3097
3098 ;; Saving hidden threads.
3099
3100 (defmacro gnus-save-hidden-threads (&rest forms)
3101   "Save hidden threads, eval FORMS, and restore the hidden threads."
3102   (let ((config (make-symbol "config")))
3103     `(let ((,config (gnus-hidden-threads-configuration)))
3104        (unwind-protect
3105            (save-excursion
3106              ,@forms)
3107          (gnus-restore-hidden-threads-configuration ,config)))))
3108 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3109 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3110
3111 (defun gnus-data-compute-positions ()
3112   "Compute the positions of all articles."
3113   (setq gnus-newsgroup-data-reverse nil)
3114   (let ((data gnus-newsgroup-data))
3115     (save-excursion
3116       (gnus-save-hidden-threads
3117         (gnus-summary-show-all-threads)
3118         (goto-char (point-min))
3119         (while data
3120           (while (get-text-property (point) 'gnus-intangible)
3121             (forward-line 1))
3122           (gnus-data-set-pos (car data) (+ (point) 3))
3123           (setq data (cdr data))
3124           (forward-line 1))))))
3125
3126 (defun gnus-hidden-threads-configuration ()
3127   "Return the current hidden threads configuration."
3128   (save-excursion
3129     (let (config)
3130       (goto-char (point-min))
3131       (while (search-forward "\r" nil t)
3132         (push (1- (point)) config))
3133       config)))
3134
3135 (defun gnus-restore-hidden-threads-configuration (config)
3136   "Restore hidden threads configuration from CONFIG."
3137   (save-excursion
3138     (let (point buffer-read-only)
3139       (while (setq point (pop config))
3140         (when (and (< point (point-max))
3141                    (goto-char point)
3142                    (eq (char-after) ?\n))
3143           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3144
3145 ;; Various summary mode internalish functions.
3146
3147 (defun gnus-mouse-pick-article (e)
3148   (interactive "e")
3149   (mouse-set-point e)
3150   (gnus-summary-next-page nil t))
3151
3152 (defun gnus-summary-set-display-table ()
3153   "Change the display table.
3154 Odd characters have a tendency to mess
3155 up nicely formatted displays - we make all possible glyphs
3156 display only a single character."
3157
3158   ;; We start from the standard display table, if any.
3159   (let ((table (or (copy-sequence standard-display-table)
3160                    (make-display-table)))
3161         (i 32))
3162     ;; Nix out all the control chars...
3163     (while (>= (setq i (1- i)) 0)
3164       (aset table i [??]))
3165     ;; ... but not newline and cr, of course.  (cr is necessary for the
3166     ;; selective display).
3167     (aset table ?\n nil)
3168     (aset table ?\r nil)
3169     ;; We keep TAB as well.
3170     (aset table ?\t nil)
3171     ;; We nix out any glyphs over 126 that are not set already.
3172     (let ((i 256))
3173       (while (>= (setq i (1- i)) 127)
3174         ;; Only modify if the entry is nil.
3175         (unless (aref table i)
3176           (aset table i [??]))))
3177     (setq buffer-display-table table)))
3178
3179 (defun gnus-summary-set-article-display-arrow (pos)
3180   "Update the overlay arrow to point to line at position POS."
3181   (when (and gnus-summary-display-arrow
3182              (boundp 'overlay-arrow-position)
3183              (boundp 'overlay-arrow-string))
3184     (save-excursion
3185       (goto-char pos)
3186       (beginning-of-line)
3187       (unless overlay-arrow-position
3188         (setq overlay-arrow-position (make-marker)))
3189       (setq overlay-arrow-string "=>"
3190             overlay-arrow-position (set-marker overlay-arrow-position
3191                                                (point)
3192                                                (current-buffer))))))
3193
3194 (defun gnus-summary-setup-buffer (group)
3195   "Initialize summary buffer."
3196   (let ((buffer (gnus-summary-buffer-name group))
3197         (dead-name (concat "*Dead Summary "
3198                            (gnus-group-decoded-name group) "*")))
3199     ;; If a dead summary buffer exists, we kill it.
3200     (when (gnus-buffer-live-p dead-name)
3201       (gnus-kill-buffer dead-name))
3202     (if (get-buffer buffer)
3203         (progn
3204           (set-buffer buffer)
3205           (setq gnus-summary-buffer (current-buffer))
3206           (not gnus-newsgroup-prepared))
3207       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3208       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3209       (gnus-summary-mode group)
3210       (when gnus-carpal
3211         (gnus-carpal-setup-buffer 'summary))
3212       (unless gnus-single-article-buffer
3213         (make-local-variable 'gnus-article-buffer)
3214         (make-local-variable 'gnus-article-current)
3215         (make-local-variable 'gnus-original-article-buffer))
3216       (setq gnus-newsgroup-name group)
3217       ;; Set any local variables in the group parameters.
3218       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3219       t)))
3220
3221 (defun gnus-set-global-variables ()
3222   "Set the global equivalents of the buffer-local variables.
3223 They are set to the latest values they had.  These reflect the summary
3224 buffer that was in action when the last article was fetched."
3225   (when (eq major-mode 'gnus-summary-mode)
3226     (setq gnus-summary-buffer (current-buffer))
3227     (let ((name gnus-newsgroup-name)
3228           (marked gnus-newsgroup-marked)
3229           (spam gnus-newsgroup-spam-marked)
3230           (unread gnus-newsgroup-unreads)
3231           (headers gnus-current-headers)
3232           (data gnus-newsgroup-data)
3233           (summary gnus-summary-buffer)
3234           (article-buffer gnus-article-buffer)
3235           (original gnus-original-article-buffer)
3236           (gac gnus-article-current)
3237           (reffed gnus-reffed-article-number)
3238           (score-file gnus-current-score-file)
3239           (default-charset gnus-newsgroup-charset)
3240           vlist)
3241       (let ((locals gnus-newsgroup-variables))
3242         (while locals
3243           (if (consp (car locals))
3244               (push (eval (caar locals)) vlist)
3245             (push (eval (car locals)) vlist))
3246           (setq locals (cdr locals)))
3247         (setq vlist (nreverse vlist)))
3248       (with-current-buffer gnus-group-buffer
3249         (setq gnus-newsgroup-name name
3250               gnus-newsgroup-marked marked
3251               gnus-newsgroup-spam-marked spam
3252               gnus-newsgroup-unreads unread
3253               gnus-current-headers headers
3254               gnus-newsgroup-data data
3255               gnus-article-current gac
3256               gnus-summary-buffer summary
3257               gnus-article-buffer article-buffer
3258               gnus-original-article-buffer original
3259               gnus-reffed-article-number reffed
3260               gnus-current-score-file score-file
3261               gnus-newsgroup-charset default-charset)
3262         (let ((locals gnus-newsgroup-variables))
3263           (while locals
3264             (if (consp (car locals))
3265                 (set (caar locals) (pop vlist))
3266               (set (car locals) (pop vlist)))
3267             (setq locals (cdr locals))))
3268         ;; The article buffer also has local variables.
3269         (when (gnus-buffer-live-p gnus-article-buffer)
3270           (set-buffer gnus-article-buffer)
3271           (setq gnus-summary-buffer summary))))))
3272
3273 (defun gnus-summary-article-unread-p (article)
3274   "Say whether ARTICLE is unread or not."
3275   (memq article gnus-newsgroup-unreads))
3276
3277 (defun gnus-summary-first-article-p (&optional article)
3278   "Return whether ARTICLE is the first article in the buffer."
3279   (if (not (setq article (or article (gnus-summary-article-number))))
3280       nil
3281     (eq article (caar gnus-newsgroup-data))))
3282
3283 (defun gnus-summary-last-article-p (&optional article)
3284   "Return whether ARTICLE is the last article in the buffer."
3285   (if (not (setq article (or article (gnus-summary-article-number))))
3286       ;; All non-existent numbers are the last article.  :-)
3287       t
3288     (not (cdr (gnus-data-find-list article)))))
3289
3290 (defun gnus-make-thread-indent-array ()
3291   (let ((n 200))
3292     (unless (and gnus-thread-indent-array
3293                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3294       (setq gnus-thread-indent-array (make-vector 201 "")
3295             gnus-thread-indent-array-level gnus-thread-indent-level)
3296       (while (>= n 0)
3297         (aset gnus-thread-indent-array n
3298               (make-string (* n gnus-thread-indent-level) ? ))
3299         (setq n (1- n))))))
3300
3301 (defun gnus-update-summary-mark-positions ()
3302   "Compute where the summary marks are to go."
3303   (save-excursion
3304     (when (gnus-buffer-exists-p gnus-summary-buffer)
3305       (set-buffer gnus-summary-buffer))
3306     (let ((spec gnus-summary-line-format-spec)
3307           pos)
3308       (save-excursion
3309         (gnus-set-work-buffer)
3310         (let ((gnus-tmp-unread ?Z)
3311               (gnus-replied-mark ?Z)
3312               (gnus-score-below-mark ?Z)
3313               (gnus-score-over-mark ?Z)
3314               (gnus-undownloaded-mark ?Z)
3315               (gnus-summary-line-format-spec spec)
3316               (gnus-newsgroup-downloadable '(0))
3317               (header
3318                (make-full-mail-header
3319                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3320               case-fold-search ignores)
3321           ;; Here, all marks are bound to Z.
3322           (gnus-summary-insert-line header
3323                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3324           (goto-char (point-min))
3325           ;; Memorize the positions of the same characters as dummy marks.
3326           (while (re-search-forward "[A-D]" nil t)
3327             (push (point) ignores))
3328           (erase-buffer)
3329           ;; We use A-D as dummy marks in order to know column positions
3330           ;; where marks should be inserted.
3331           (setq gnus-tmp-unread ?A
3332                 gnus-replied-mark ?B
3333                 gnus-score-below-mark ?C
3334                 gnus-score-over-mark ?C
3335                 gnus-undownloaded-mark ?D)
3336           (gnus-summary-insert-line header
3337                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3338           ;; Ignore characters which aren't dummy marks.
3339           (dolist (p ignores)
3340             (delete-region (goto-char (1- p)) p)
3341             (insert ?Z))
3342           (goto-char (point-min))
3343           (setq pos (list (cons 'unread
3344                                 (and (search-forward "A" nil t)
3345                                      (- (point) (point-min) 1)))))
3346           (goto-char (point-min))
3347           (push (cons 'replied (and (search-forward "B" nil t)
3348                                     (- (point) (point-min) 1)))
3349                 pos)
3350           (goto-char (point-min))
3351           (push (cons 'score (and (search-forward "C" nil t)
3352                                   (- (point) (point-min) 1)))
3353                 pos)
3354           (goto-char (point-min))
3355           (push (cons 'download (and (search-forward "D" nil t)
3356                                      (- (point) (point-min) 1)))
3357                 pos)))
3358       (setq gnus-summary-mark-positions pos))))
3359
3360 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3361   "Insert a dummy root in the summary buffer."
3362   (beginning-of-line)
3363   (gnus-add-text-properties
3364    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3365    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3366
3367 (defun gnus-summary-extract-address-component (from)
3368   (or (car (funcall gnus-extract-address-components from))
3369       from))
3370
3371 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3372   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3373                                 default-mime-charset)))
3374     ;; Is it really necessary to do this next part for each summary line?
3375     ;; Luckily, doesn't seem to slow things down much.
3376     (or
3377      (and gnus-ignored-from-addresses
3378           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3379           (let ((extra-headers (mail-header-extra header))
3380                 to
3381                 newsgroups)
3382             (cond
3383              ((setq to (cdr (assq 'To extra-headers)))
3384               (concat gnus-summary-to-prefix
3385                       (inline
3386                         (gnus-summary-extract-address-component
3387                          (funcall gnus-decode-encoded-word-function to)))))
3388              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3389               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3390      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3391
3392 (defun gnus-summary-insert-line (gnus-tmp-header
3393                                  gnus-tmp-level gnus-tmp-current
3394                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3395                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3396                                  &optional gnus-tmp-dummy gnus-tmp-score
3397                                  gnus-tmp-process)
3398   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3399          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3400          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3401          (gnus-tmp-score-char
3402           (if (or (null gnus-summary-default-score)
3403                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3404                       gnus-summary-zcore-fuzz))
3405               ?\ ;;;Whitespace
3406             (if (< gnus-tmp-score gnus-summary-default-score)
3407                 gnus-score-below-mark gnus-score-over-mark)))
3408          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3409          (gnus-tmp-replied
3410           (cond (gnus-tmp-process gnus-process-mark)
3411                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3412                  gnus-cached-mark)
3413                 (gnus-tmp-replied gnus-replied-mark)
3414                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3415                  gnus-forwarded-mark)
3416                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3417                  gnus-saved-mark)
3418                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3419                  gnus-recent-mark)
3420                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3421                  gnus-unseen-mark)
3422                 (t gnus-no-mark)))
3423          (gnus-tmp-downloaded
3424           (cond (undownloaded
3425                  gnus-undownloaded-mark)
3426                 (gnus-newsgroup-agentized
3427                  gnus-downloaded-mark)
3428                 (t
3429                  gnus-no-mark)))
3430          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3431          (gnus-tmp-name
3432           (cond
3433            ((string-match "<[^>]+> *$" gnus-tmp-from)
3434             (let ((beg (match-beginning 0)))
3435               (or (and (string-match "^\".+\"" gnus-tmp-from)
3436                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3437                   (substring gnus-tmp-from 0 beg))))
3438            ((string-match "(.+)" gnus-tmp-from)
3439             (substring gnus-tmp-from
3440                        (1+ (match-beginning 0)) (1- (match-end 0))))
3441            (t gnus-tmp-from)))
3442          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3443          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3444          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3445          (buffer-read-only nil))
3446     (when (string= gnus-tmp-name "")
3447       (setq gnus-tmp-name gnus-tmp-from))
3448     (unless (numberp gnus-tmp-lines)
3449       (setq gnus-tmp-lines -1))
3450     (if (= gnus-tmp-lines -1)
3451         (setq gnus-tmp-lines "?")
3452       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3453     (gnus-put-text-property-excluding-characters-with-faces
3454      (point)
3455      (progn (eval gnus-summary-line-format-spec) (point))
3456      'gnus-number gnus-tmp-number)
3457     (when (gnus-visual-p 'summary-highlight 'highlight)
3458       (forward-line -1)
3459       (gnus-run-hooks 'gnus-summary-update-hook)
3460       (forward-line 1))))
3461
3462 (defun gnus-summary-update-line (&optional dont-update)
3463   "Update summary line after change."
3464   (when (and gnus-summary-default-score
3465              (not gnus-summary-inhibit-highlight))
3466     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3467            (article (gnus-summary-article-number))
3468            (score (gnus-summary-article-score article)))
3469       (unless dont-update
3470         (if (and gnus-summary-mark-below
3471                  (< (gnus-summary-article-score)
3472                     gnus-summary-mark-below))
3473             ;; This article has a low score, so we mark it as read.
3474             (when (memq article gnus-newsgroup-unreads)
3475               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3476           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3477             ;; This article was previously marked as read on account
3478             ;; of a low score, but now it has risen, so we mark it as
3479             ;; unread.
3480             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3481         (gnus-summary-update-mark
3482          (if (or (null gnus-summary-default-score)
3483                  (<= (abs (- score gnus-summary-default-score))
3484                      gnus-summary-zcore-fuzz))
3485              ?\ ;;;Whitespace
3486            (if (< score gnus-summary-default-score)
3487                gnus-score-below-mark gnus-score-over-mark))
3488          'score))
3489       ;; Do visual highlighting.
3490       (when (gnus-visual-p 'summary-highlight 'highlight)
3491         (gnus-run-hooks 'gnus-summary-update-hook)))))
3492
3493 (defvar gnus-tmp-new-adopts nil)
3494
3495 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3496   "Return the number of articles in THREAD.
3497 This may be 0 in some cases -- if none of the articles in
3498 the thread are to be displayed."
3499   (let* ((number
3500           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3501           (cond
3502            ((not (listp thread))
3503             1)
3504            ((and (consp thread) (cdr thread))
3505             (apply
3506              '+ 1 (mapcar
3507                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3508            ((null thread)
3509             1)
3510            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3511             1)
3512            (t 0))))
3513     (when (and level (zerop level) gnus-tmp-new-adopts)
3514       (incf number
3515             (apply '+ (mapcar
3516                        'gnus-summary-number-of-articles-in-thread
3517                        gnus-tmp-new-adopts))))
3518     (if char
3519         (if (> number 1) gnus-not-empty-thread-mark
3520           gnus-empty-thread-mark)
3521       number)))
3522
3523 (defsubst gnus-summary-line-message-size (head)
3524   "Return pretty-printed version of message size.
3525 This function is intended to be used in
3526 `gnus-summary-line-format-alist'."
3527   (let ((c (or (mail-header-chars head) -1)))
3528     (cond ((< c 0) "n/a")               ; chars not available
3529           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3530           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3531           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3532           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3533
3534
3535 (defun gnus-summary-set-local-parameters (group)
3536   "Go through the local params of GROUP and set all variable specs in that list."
3537   (let ((vars '(quit-config)))          ; Ignore quit-config.
3538     (dolist (elem (gnus-group-find-parameter group))
3539       (and (consp elem)                 ; Has to be a cons.
3540            (consp (cdr elem))           ; The cdr has to be a list.
3541            (symbolp (car elem))         ; Has to be a symbol in there.
3542            (not (memq (car elem) vars))
3543            (ignore-errors               ; So we set it.
3544              (push (car elem) vars)
3545              (make-local-variable (car elem))
3546              (set (car elem) (eval (nth 1 elem))))))))
3547
3548 (defun gnus-summary-read-group (group &optional show-all no-article
3549                                       kill-buffer no-display backward
3550                                       select-articles)
3551   "Start reading news in newsgroup GROUP.
3552 If SHOW-ALL is non-nil, already read articles are also listed.
3553 If NO-ARTICLE is non-nil, no article is selected initially.
3554 If NO-DISPLAY, don't generate a summary buffer."
3555   (let (result)
3556     (while (and group
3557                 (null (setq result
3558                             (let ((gnus-auto-select-next nil))
3559                               (or (gnus-summary-read-group-1
3560                                    group show-all no-article
3561                                    kill-buffer no-display
3562                                    select-articles)
3563                                   (setq show-all nil
3564                                         select-articles nil)))))
3565                 (eq gnus-auto-select-next 'quietly))
3566       (set-buffer gnus-group-buffer)
3567       ;; The entry function called above goes to the next
3568       ;; group automatically, so we go two groups back
3569       ;; if we are searching for the previous group.
3570       (when backward
3571         (gnus-group-prev-unread-group 2))
3572       (if (not (equal group (gnus-group-group-name)))
3573           (setq group (gnus-group-group-name))
3574         (setq group nil)))
3575     result))
3576
3577 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3578   "Directly jump to the other GROUP from summary buffer.
3579 If SHOW-ALL is non-nil, already read articles are also listed."
3580   (interactive
3581    (if (eq gnus-summary-buffer (current-buffer))
3582        (list (completing-read
3583               "Group: " gnus-active-hashtb nil t
3584               (when (and gnus-newsgroup-name
3585                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3586                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3587               'gnus-group-history)
3588              current-prefix-arg)
3589      (error "%s must be invoked from a gnus summary buffer." this-command)))
3590   (unless (or (zerop (length group))
3591               (and gnus-newsgroup-name
3592                    (string-equal gnus-newsgroup-name group)))
3593     (gnus-summary-exit)
3594     (gnus-summary-read-group group show-all
3595                              gnus-dont-select-after-jump-to-other-group)))
3596
3597 (defun gnus-summary-read-group-1 (group show-all no-article
3598                                         kill-buffer no-display
3599                                         &optional select-articles)
3600   ;; Killed foreign groups can't be entered.
3601   ;;  (when (and (not (gnus-group-native-p group))
3602   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3603   ;;    (error "Dead non-native groups can't be entered"))
3604   (gnus-message 5 "Retrieving newsgroup: %s..."
3605                 (gnus-group-decoded-name group))
3606   (let* ((new-group (gnus-summary-setup-buffer group))
3607          (quit-config (gnus-group-quit-config group))
3608          (did-select (and new-group (gnus-select-newsgroup
3609                                      group show-all select-articles))))
3610     (cond
3611      ;; This summary buffer exists already, so we just select it.
3612      ((not new-group)
3613       (gnus-set-global-variables)
3614       (when kill-buffer
3615         (gnus-kill-or-deaden-summary kill-buffer))
3616       (gnus-configure-windows 'summary 'force)
3617       (gnus-set-mode-line 'summary)
3618       (gnus-summary-position-point)
3619       (message "")
3620       t)
3621      ;; We couldn't select this group.
3622      ((null did-select)
3623       (when (and (eq major-mode 'gnus-summary-mode)
3624                  (not (equal (current-buffer) kill-buffer)))
3625         (kill-buffer (current-buffer))
3626         (if (not quit-config)
3627             (progn
3628               ;; Update the info -- marks might need to be removed,
3629               ;; for instance.
3630               (gnus-summary-update-info)
3631               (set-buffer gnus-group-buffer)
3632               (gnus-group-jump-to-group group)
3633               (gnus-group-next-unread-group 1))
3634           (gnus-handle-ephemeral-exit quit-config)))
3635       (let ((grpinfo (gnus-get-info group)))
3636         (if (null (gnus-info-read grpinfo))
3637             (gnus-message 3 "Group %s contains no messages"
3638                           (gnus-group-decoded-name group))
3639           (gnus-message 3 "Can't select group")))
3640       nil)
3641      ;; The user did a `C-g' while prompting for number of articles,
3642      ;; so we exit this group.
3643      ((eq did-select 'quit)
3644       (and (eq major-mode 'gnus-summary-mode)
3645            (not (equal (current-buffer) kill-buffer))
3646            (kill-buffer (current-buffer)))
3647       (when kill-buffer
3648         (gnus-kill-or-deaden-summary kill-buffer))
3649       (if (not quit-config)
3650           (progn
3651             (set-buffer gnus-group-buffer)
3652             (gnus-group-jump-to-group group)
3653             (gnus-group-next-unread-group 1)
3654             (gnus-configure-windows 'group 'force))
3655         (gnus-handle-ephemeral-exit quit-config))
3656       ;; Finally signal the quit.
3657       (signal 'quit nil))
3658      ;; The group was successfully selected.
3659      (t
3660       (gnus-set-global-variables)
3661       ;; Save the active value in effect when the group was entered.
3662       (setq gnus-newsgroup-active
3663             (gnus-copy-sequence
3664              (gnus-active gnus-newsgroup-name)))
3665       ;; You can change the summary buffer in some way with this hook.
3666       (gnus-run-hooks 'gnus-select-group-hook)
3667       (when (memq 'summary (gnus-update-format-specifications
3668                             nil 'summary 'summary-mode 'summary-dummy))
3669         ;; The format specification for the summary line was updated,
3670         ;; so we need to update the mark positions as well.
3671         (gnus-update-summary-mark-positions))
3672       ;; Do score processing.
3673       (when gnus-use-scoring
3674         (gnus-possibly-score-headers))
3675       ;; Check whether to fill in the gaps in the threads.
3676       (when gnus-build-sparse-threads
3677         (gnus-build-sparse-threads))
3678       ;; Find the initial limit.
3679       (if show-all
3680           (let ((gnus-newsgroup-dormant nil))
3681             (gnus-summary-initial-limit show-all))
3682         (gnus-summary-initial-limit show-all))
3683       ;; Generate the summary buffer.
3684       (unless no-display
3685         (gnus-summary-prepare))
3686       (when gnus-use-trees
3687         (gnus-tree-open group)
3688         (setq gnus-summary-highlight-line-function
3689               'gnus-tree-highlight-article))
3690       ;; If the summary buffer is empty, but there are some low-scored
3691       ;; articles or some excluded dormants, we include these in the
3692       ;; buffer.
3693       (when (and (zerop (buffer-size))
3694                  (not no-display))
3695         (cond (gnus-newsgroup-dormant
3696                (gnus-summary-limit-include-dormant))
3697               ((and gnus-newsgroup-scored show-all)
3698                (gnus-summary-limit-include-expunged t))))
3699       ;; Function `gnus-apply-kill-file' must be called in this hook.
3700       (gnus-run-hooks 'gnus-apply-kill-hook)
3701       (if (and (zerop (buffer-size))
3702                (not no-display))
3703           (progn
3704             ;; This newsgroup is empty.
3705             (gnus-summary-catchup-and-exit nil t)
3706             (gnus-message 6 "No unread news")
3707             (when kill-buffer
3708               (gnus-kill-or-deaden-summary kill-buffer))
3709             ;; Return nil from this function.
3710             nil)
3711         ;; Hide conversation thread subtrees.  We cannot do this in
3712         ;; gnus-summary-prepare-hook since kill processing may not
3713         ;; work with hidden articles.
3714         (gnus-summary-maybe-hide-threads)
3715         (when kill-buffer
3716           (gnus-kill-or-deaden-summary kill-buffer))
3717         (gnus-summary-auto-select-subject)
3718         ;; Show first unread article if requested.
3719         (if (and (not no-article)
3720                  (not no-display)
3721                  gnus-newsgroup-unreads
3722                  gnus-auto-select-first)
3723             (progn
3724               (gnus-configure-windows 'summary)
3725               (let ((art (gnus-summary-article-number)))
3726                 (unless (and (not gnus-plugged)
3727                              (or (memq art gnus-newsgroup-undownloaded)
3728                                  (memq art gnus-newsgroup-downloadable)))
3729                   (gnus-summary-goto-article art))))
3730           ;; Don't select any articles.
3731           (gnus-summary-position-point)
3732           (gnus-configure-windows 'summary 'force)
3733           (gnus-set-mode-line 'summary))
3734         (when (and gnus-auto-center-group
3735                    (get-buffer-window gnus-group-buffer t))
3736           ;; Gotta use windows, because recenter does weird stuff if
3737           ;; the current buffer ain't the displayed window.
3738           (let ((owin (selected-window)))
3739             (select-window (get-buffer-window gnus-group-buffer t))
3740             (when (gnus-group-goto-group group)
3741               (recenter))
3742             (select-window owin)))
3743         ;; Mark this buffer as "prepared".
3744         (setq gnus-newsgroup-prepared t)
3745         (gnus-run-hooks 'gnus-summary-prepared-hook)
3746         (unless (gnus-ephemeral-group-p group)
3747           (gnus-group-update-group group))
3748         t)))))
3749
3750 (defun gnus-summary-auto-select-subject ()
3751   "Select the subject line on initial group entry."
3752   (goto-char (point-min))
3753   (cond
3754    ((eq gnus-auto-select-subject 'best)
3755     (gnus-summary-best-unread-subject))
3756    ((eq gnus-auto-select-subject 'unread)
3757     (gnus-summary-first-unread-subject))
3758    ((eq gnus-auto-select-subject 'unseen)
3759     (gnus-summary-first-unseen-subject))
3760    ((eq gnus-auto-select-subject 'unseen-or-unread)
3761     (gnus-summary-first-unseen-or-unread-subject))
3762    ((eq gnus-auto-select-subject 'first)
3763     ;; Do nothing.
3764     )
3765    ((functionp gnus-auto-select-subject)
3766     (funcall gnus-auto-select-subject))))
3767
3768 (defun gnus-summary-prepare ()
3769   "Generate the summary buffer."
3770   (interactive)
3771   (let ((buffer-read-only nil))
3772     (erase-buffer)
3773     (setq gnus-newsgroup-data nil
3774           gnus-newsgroup-data-reverse nil)
3775     (gnus-run-hooks 'gnus-summary-generate-hook)
3776     ;; Generate the buffer, either with threads or without.
3777     (when gnus-newsgroup-headers
3778       (gnus-summary-prepare-threads
3779        (if gnus-show-threads
3780            (gnus-sort-gathered-threads
3781             (funcall gnus-summary-thread-gathering-function
3782                      (gnus-sort-threads
3783                       (gnus-cut-threads (gnus-make-threads)))))
3784          ;; Unthreaded display.
3785          (gnus-sort-articles gnus-newsgroup-headers))))
3786     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3787     ;; Call hooks for modifying summary buffer.
3788     (goto-char (point-min))
3789     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3790
3791 (defsubst gnus-general-simplify-subject (subject)
3792   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3793   (setq subject
3794         (cond
3795          ;; Truncate the subject.
3796          (gnus-simplify-subject-functions
3797           (gnus-map-function gnus-simplify-subject-functions subject))
3798          ((numberp gnus-summary-gather-subject-limit)
3799           (setq subject (gnus-simplify-subject-re subject))
3800           (if (> (length subject) gnus-summary-gather-subject-limit)
3801               (substring subject 0 gnus-summary-gather-subject-limit)
3802             subject))
3803          ;; Fuzzily simplify it.
3804          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3805           (gnus-simplify-subject-fuzzy subject))
3806          ;; Just remove the leading "Re:".
3807          (t
3808           (gnus-simplify-subject-re subject))))
3809
3810   (if (and gnus-summary-gather-exclude-subject
3811            (string-match gnus-summary-gather-exclude-subject subject))
3812       nil                               ; This article shouldn't be gathered
3813     subject))
3814
3815 (defun gnus-summary-simplify-subject-query ()
3816   "Query where the respool algorithm would put this article."
3817   (interactive)
3818   (gnus-summary-select-article)
3819   (message "%s"
3820            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3821
3822 (defun gnus-gather-threads-by-subject (threads)
3823   "Gather threads by looking at Subject headers."
3824   (if (not gnus-summary-make-false-root)
3825       threads
3826     (let ((hashtb (gnus-make-hashtable 1024))
3827           (prev threads)
3828           (result threads)
3829           subject hthread whole-subject)
3830       (while threads
3831         (setq subject (gnus-general-simplify-subject
3832                        (setq whole-subject (mail-header-subject
3833                                             (caar threads)))))
3834         (when subject
3835           (if (setq hthread (gnus-gethash subject hashtb))
3836               (progn
3837                 ;; We enter a dummy root into the thread, if we
3838                 ;; haven't done that already.
3839                 (unless (stringp (caar hthread))
3840                   (setcar hthread (list whole-subject (car hthread))))
3841                 ;; We add this new gathered thread to this gathered
3842                 ;; thread.
3843                 (setcdr (car hthread)
3844                         (nconc (cdar hthread) (list (car threads))))
3845                 ;; Remove it from the list of threads.
3846                 (setcdr prev (cdr threads))
3847                 (setq threads prev))
3848             ;; Enter this thread into the hash table.
3849             (gnus-sethash subject
3850                           (if gnus-summary-make-false-root-always
3851                               (progn
3852                                 ;; If you want a dummy root above all
3853                                 ;; threads...
3854                                 (setcar threads (list whole-subject
3855                                                       (car threads)))
3856                                 threads)
3857                             threads)
3858                           hashtb)))
3859         (setq prev threads)
3860         (setq threads (cdr threads)))
3861       result)))
3862
3863 (defun gnus-gather-threads-by-references (threads)
3864   "Gather threads by looking at References headers."
3865   (let ((idhashtb (gnus-make-hashtable 1024))
3866         (thhashtb (gnus-make-hashtable 1024))
3867         (prev threads)
3868         (result threads)
3869         ids references id gthread gid entered ref)
3870     (while threads
3871       (when (setq references (mail-header-references (caar threads)))
3872         (setq id (mail-header-id (caar threads))
3873               ids (inline (gnus-split-references references))
3874               entered nil)
3875         (while (setq ref (pop ids))
3876           (setq ids (delete ref ids))
3877           (if (not (setq gid (gnus-gethash ref idhashtb)))
3878               (progn
3879                 (gnus-sethash ref id idhashtb)
3880                 (gnus-sethash id threads thhashtb))
3881             (setq gthread (gnus-gethash gid thhashtb))
3882             (unless entered
3883               ;; We enter a dummy root into the thread, if we
3884               ;; haven't done that already.
3885               (unless (stringp (caar gthread))
3886                 (setcar gthread (list (mail-header-subject (caar gthread))
3887                                       (car gthread))))
3888               ;; We add this new gathered thread to this gathered
3889               ;; thread.
3890               (setcdr (car gthread)
3891                       (nconc (cdar gthread) (list (car threads)))))
3892             ;; Add it into the thread hash table.
3893             (gnus-sethash id gthread thhashtb)
3894             (setq entered t)
3895             ;; Remove it from the list of threads.
3896             (setcdr prev (cdr threads))
3897             (setq threads prev))))
3898       (setq prev threads)
3899       (setq threads (cdr threads)))
3900     result))
3901
3902 (defun gnus-sort-gathered-threads (threads)
3903   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3904   (let ((result threads))
3905     (while threads
3906       (when (stringp (caar threads))
3907         (setcdr (car threads)
3908                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3909       (setq threads (cdr threads)))
3910     result))
3911
3912 (defun gnus-thread-loop-p (root thread)
3913   "Say whether ROOT is in THREAD."
3914   (let ((stack (list thread))
3915         (infloop 0)
3916         th)
3917     (while (setq thread (pop stack))
3918       (setq th (cdr thread))
3919       (while (and th
3920                   (not (eq (caar th) root)))
3921         (pop th))
3922       (if th
3923           ;; We have found a loop.
3924           (let (ref-dep)
3925             (setcdr thread (delq (car th) (cdr thread)))
3926             (if (boundp (setq ref-dep (intern "none"
3927                                               gnus-newsgroup-dependencies)))
3928                 (setcdr (symbol-value ref-dep)
3929                         (nconc (cdr (symbol-value ref-dep))
3930                                (list (car th))))
3931               (set ref-dep (list nil (car th))))
3932             (setq infloop 1
3933                   stack nil))
3934         ;; Push all the subthreads onto the stack.
3935         (push (cdr thread) stack)))
3936     infloop))
3937
3938 (defun gnus-make-threads ()
3939   "Go through the dependency hashtb and find the roots.  Return all threads."
3940   (let (threads)
3941     (while (catch 'infloop
3942              (mapatoms
3943               (lambda (refs)
3944                 ;; Deal with self-referencing References loops.
3945                 (when (and (car (symbol-value refs))
3946                            (not (zerop
3947                                  (apply
3948                                   '+
3949                                   (mapcar
3950                                    (lambda (thread)
3951                                      (gnus-thread-loop-p
3952                                       (car (symbol-value refs)) thread))
3953                                    (cdr (symbol-value refs)))))))
3954                   (setq threads nil)
3955                   (throw 'infloop t))
3956                 (unless (car (symbol-value refs))
3957                   ;; These threads do not refer back to any other articles,
3958                   ;; so they're roots.
3959                   (setq threads (append (cdr (symbol-value refs)) threads))))
3960               gnus-newsgroup-dependencies)))
3961     threads))
3962
3963 ;; Build the thread tree.
3964 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3965   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3966
3967 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3968 if it was already present.
3969
3970 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3971 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3972 Message-IDs will be renamed to a unique Message-ID before being
3973 entered.
3974
3975 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3976   (let* ((id (mail-header-id header))
3977          (id-dep (and id (intern id dependencies)))
3978          parent-id ref ref-dep ref-header replaced)
3979     ;; Enter this `header' in the `dependencies' table.
3980     (cond
3981      ((not id-dep)
3982       (setq header nil))
3983      ;; The first two cases do the normal part: enter a new `header'
3984      ;; in the `dependencies' table.
3985      ((not (boundp id-dep))
3986       (set id-dep (list header)))
3987      ((null (car (symbol-value id-dep)))
3988       (setcar (symbol-value id-dep) header))
3989
3990      ;; From here the `header' was already present in the
3991      ;; `dependencies' table.
3992      (force-new
3993       ;; Overrides an existing entry;
3994       ;; just set the header part of the entry.
3995       (setcar (symbol-value id-dep) header)
3996       (setq replaced t))
3997
3998      ;; Renames the existing `header' to a unique Message-ID.
3999      ((not gnus-summary-ignore-duplicates)
4000       ;; An article with this Message-ID has already been seen.
4001       ;; We rename the Message-ID.
4002       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4003            (list header))
4004       (mail-header-set-id header id))
4005
4006      ;; The last case ignores an existing entry, except it adds any
4007      ;; additional Xrefs (in case the two articles came from different
4008      ;; servers.
4009      ;; Also sets `header' to `nil' meaning that the `dependencies'
4010      ;; table was *not* modified.
4011      (t
4012       (mail-header-set-xref
4013        (car (symbol-value id-dep))
4014        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4015                    "")
4016                (or (mail-header-xref header) "")))
4017       (setq header nil)))
4018
4019     (when (and header (not replaced))
4020       ;; First check that we are not creating a References loop.
4021       (setq parent-id (gnus-parent-id (mail-header-references header)))
4022       (setq ref parent-id)
4023       (while (and ref
4024                   (setq ref-dep (intern-soft ref dependencies))
4025                   (boundp ref-dep)
4026                   (setq ref-header (car (symbol-value ref-dep))))
4027         (if (string= id ref)
4028             ;; Yuk!  This is a reference loop.  Make the article be a
4029             ;; root article.
4030             (progn
4031               (mail-header-set-references (car (symbol-value id-dep)) "none")
4032               (setq ref nil)
4033               (setq parent-id nil))
4034           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4035       (setq ref-dep (intern (or parent-id "none") dependencies))
4036       (if (boundp ref-dep)
4037           (setcdr (symbol-value ref-dep)
4038                   (nconc (cdr (symbol-value ref-dep))
4039                          (list (symbol-value id-dep))))
4040         (set ref-dep (list nil (symbol-value id-dep)))))
4041     header))
4042
4043 (defun gnus-extract-message-id-from-in-reply-to (string)
4044   (if (string-match "<[^>]+>" string)
4045       (substring string (match-beginning 0) (match-end 0))
4046     nil))
4047
4048 (defun gnus-build-sparse-threads ()
4049   (let ((headers gnus-newsgroup-headers)
4050         (mail-parse-charset gnus-newsgroup-charset)
4051         (gnus-summary-ignore-duplicates t)
4052         header references generation relations
4053         subject child end new-child date)
4054     ;; First we create an alist of generations/relations, where
4055     ;; generations is how much we trust the relation, and the relation
4056     ;; is parent/child.
4057     (gnus-message 7 "Making sparse threads...")
4058     (save-excursion
4059       (nnheader-set-temp-buffer " *gnus sparse threads*")
4060       (while (setq header (pop headers))
4061         (when (and (setq references (mail-header-references header))
4062                    (not (string= references "")))
4063           (insert references)
4064           (setq child (mail-header-id header)
4065                 subject (mail-header-subject header)
4066                 date (mail-header-date header)
4067                 generation 0)
4068           (while (search-backward ">" nil t)
4069             (setq end (1+ (point)))
4070             (when (search-backward "<" nil t)
4071               (setq new-child (buffer-substring (point) end))
4072               (push (list (incf generation)
4073                           child (setq child new-child)
4074                           subject date)
4075                     relations)))
4076           (when child
4077             (push (list (1+ generation) child nil subject) relations))
4078           (erase-buffer)))
4079       (kill-buffer (current-buffer)))
4080     ;; Sort over trustworthiness.
4081     (mapcar
4082      (lambda (relation)
4083        (when (gnus-dependencies-add-header
4084               (make-full-mail-header-from-decoded-header
4085                gnus-reffed-article-number
4086                (nth 3 relation) "" (or (nth 4 relation) "")
4087                (nth 1 relation)
4088                (or (nth 2 relation) "") 0 0 "")
4089               gnus-newsgroup-dependencies nil)
4090          (push gnus-reffed-article-number gnus-newsgroup-limit)
4091          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4092          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4093                gnus-newsgroup-reads)
4094          (decf gnus-reffed-article-number)))
4095      (sort relations 'car-less-than-car))
4096     (gnus-message 7 "Making sparse threads...done")))
4097
4098 (defun gnus-build-old-threads ()
4099   ;; Look at all the articles that refer back to old articles, and
4100   ;; fetch the headers for the articles that aren't there.  This will
4101   ;; build complete threads - if the roots haven't been expired by the
4102   ;; server, that is.
4103   (let ((mail-parse-charset gnus-newsgroup-charset)
4104         id heads)
4105     (mapatoms
4106      (lambda (refs)
4107        (when (not (car (symbol-value refs)))
4108          (setq heads (cdr (symbol-value refs)))
4109          (while heads
4110            (if (memq (mail-header-number (caar heads))
4111                      gnus-newsgroup-dormant)
4112                (setq heads (cdr heads))
4113              (setq id (symbol-name refs))
4114              (while (and (setq id (gnus-build-get-header id))
4115                          (not (car (gnus-id-to-thread id)))))
4116              (setq heads nil)))))
4117      gnus-newsgroup-dependencies)))
4118
4119 (defsubst gnus-remove-odd-characters (string)
4120   "Translate STRING into something that doesn't contain weird characters."
4121   (mm-subst-char-in-string
4122    ?\r ?\-
4123    (mm-subst-char-in-string ?\n ?\- string t) t))
4124
4125 ;; This function has to be called with point after the article number
4126 ;; on the beginning of the line.
4127 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4128   (let ((eol (point-at-eol))
4129         (buffer (current-buffer))
4130         header references in-reply-to)
4131
4132     ;; overview: [num subject from date id refs chars lines misc]
4133     (unwind-protect
4134         (progn
4135           (narrow-to-region (point) eol)
4136           (unless (eobp)
4137             (forward-char))
4138
4139           (setq header
4140                 (make-full-mail-header
4141                  number                         ; number
4142                  (nnheader-nov-field)           ; subject
4143                  (nnheader-nov-field)           ; from
4144                  (nnheader-nov-field)           ; date
4145                  (nnheader-nov-read-message-id number)  ; id
4146                  (setq references (nnheader-nov-field)) ; refs
4147                  (nnheader-nov-read-integer)    ; chars
4148                  (nnheader-nov-read-integer)    ; lines
4149                  (unless (eobp)
4150                    (if (looking-at "Xref: ")
4151                        (goto-char (match-end 0)))
4152                    (nnheader-nov-field))        ; Xref
4153                  (nnheader-nov-parse-extra))))  ; extra
4154
4155       (widen))
4156
4157     (when (and (string= references "")
4158                (setq in-reply-to (mail-header-extra header))
4159                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4160       (mail-header-set-references
4161        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4162
4163     (when gnus-alter-header-function
4164       (funcall gnus-alter-header-function header))
4165     (gnus-dependencies-add-header header dependencies force-new)))
4166
4167 (defun gnus-build-get-header (id)
4168   "Look through the buffer of NOV lines and find the header to ID.
4169 Enter this line into the dependencies hash table, and return
4170 the id of the parent article (if any)."
4171   (let ((deps gnus-newsgroup-dependencies)
4172         found header)
4173     (prog1
4174         (save-excursion
4175           (set-buffer nntp-server-buffer)
4176           (let ((case-fold-search nil))
4177             (goto-char (point-min))
4178             (while (and (not found)
4179                         (search-forward id nil t))
4180               (beginning-of-line)
4181               (setq found (looking-at
4182                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4183                                    (regexp-quote id))))
4184               (or found (beginning-of-line 2)))
4185             (when found
4186               (beginning-of-line)
4187               (and
4188                (setq header (gnus-nov-parse-line
4189                              (read (current-buffer)) deps))
4190                (gnus-parent-id (mail-header-references header))))))
4191       (when header
4192         (let ((number (mail-header-number header)))
4193           (push number gnus-newsgroup-limit)
4194           (push header gnus-newsgroup-headers)
4195           (if (memq number gnus-newsgroup-unselected)
4196               (progn
4197                 (setq gnus-newsgroup-unreads
4198                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4199                                                number))
4200                 (setq gnus-newsgroup-unselected
4201                       (delq number gnus-newsgroup-unselected)))
4202             (push number gnus-newsgroup-ancient)))))))
4203
4204 (defun gnus-build-all-threads ()
4205   "Read all the headers."
4206   (let ((gnus-summary-ignore-duplicates t)
4207         (mail-parse-charset gnus-newsgroup-charset)
4208         (dependencies gnus-newsgroup-dependencies)
4209         header article)
4210     (save-excursion
4211       (set-buffer nntp-server-buffer)
4212       (let ((case-fold-search nil))
4213         (goto-char (point-min))
4214         (while (not (eobp))
4215           (ignore-errors
4216             (setq article (read (current-buffer))
4217                   header (gnus-nov-parse-line article dependencies)))
4218           (when header
4219             (with-current-buffer gnus-summary-buffer
4220               (push header gnus-newsgroup-headers)
4221               (if (memq (setq article (mail-header-number header))
4222                         gnus-newsgroup-unselected)
4223                   (progn
4224                     (setq gnus-newsgroup-unreads
4225                           (gnus-add-to-sorted-list
4226                            gnus-newsgroup-unreads article))
4227                     (setq gnus-newsgroup-unselected
4228                           (delq article gnus-newsgroup-unselected)))
4229                 (push article gnus-newsgroup-ancient)))
4230             (forward-line 1)))))))
4231
4232 (defun gnus-summary-update-article-line (article header)
4233   "Update the line for ARTICLE using HEADER."
4234   (let* ((id (mail-header-id header))
4235          (thread (gnus-id-to-thread id)))
4236     (unless thread
4237       (error "Article in no thread"))
4238     ;; Update the thread.
4239     (setcar thread header)
4240     (gnus-summary-goto-subject article)
4241     (let* ((datal (gnus-data-find-list article))
4242            (data (car datal))
4243            (buffer-read-only nil)
4244            (level (gnus-summary-thread-level)))
4245       (gnus-delete-line)
4246       (let ((inserted (- (point)
4247                          (progn
4248                            (gnus-summary-insert-line
4249                             header level nil
4250                             (memq article gnus-newsgroup-undownloaded)
4251                             (gnus-article-mark article)
4252                             (memq article gnus-newsgroup-replied)
4253                             (memq article gnus-newsgroup-expirable)
4254                             ;; Only insert the Subject string when it's different
4255                             ;; from the previous Subject string.
4256                             (if (and
4257                                  gnus-show-threads
4258                                  (gnus-subject-equal
4259                                   (condition-case ()
4260                                       (mail-header-subject
4261                                        (gnus-data-header
4262                                         (cadr
4263                                          (gnus-data-find-list
4264                                           article
4265                                           (gnus-data-list t)))))
4266                                     ;; Error on the side of excessive subjects.
4267                                     (error ""))
4268                                   (mail-header-subject header)))
4269                                 ""
4270                               (mail-header-subject header))
4271                             nil (cdr (assq article gnus-newsgroup-scored))
4272                             (memq article gnus-newsgroup-processable))
4273                            (point)))))
4274         (when (cdr datal)
4275           (gnus-data-update-list
4276            (cdr datal)
4277            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4278
4279 (defun gnus-summary-update-article (article &optional iheader)
4280   "Update ARTICLE in the summary buffer."
4281   (set-buffer gnus-summary-buffer)
4282   (let* ((header (gnus-summary-article-header article))
4283          (id (mail-header-id header))
4284          (data (gnus-data-find article))
4285          (thread (gnus-id-to-thread id))
4286          (references (mail-header-references header))
4287          (parent
4288           (gnus-id-to-thread
4289            (or (gnus-parent-id
4290                 (when (and references
4291                            (not (equal "" references)))
4292                   references))
4293                "none")))
4294          (buffer-read-only nil)
4295          (old (car thread)))
4296     (when thread
4297       (unless iheader
4298         (setcar thread nil)
4299         (when parent
4300           (delq thread parent)))
4301       (if (gnus-summary-insert-subject id header)
4302           ;; Set the (possibly) new article number in the data structure.
4303           (gnus-data-set-number data (gnus-id-to-article id))
4304         (setcar thread old)
4305         nil))))
4306
4307 (defun gnus-rebuild-thread (id &optional line)
4308   "Rebuild the thread containing ID.
4309 If LINE, insert the rebuilt thread starting on line LINE."
4310   (let ((buffer-read-only nil)
4311         old-pos current thread data)
4312     (if (not gnus-show-threads)
4313         (setq thread (list (car (gnus-id-to-thread id))))
4314       ;; Get the thread this article is part of.
4315       (setq thread (gnus-remove-thread id)))
4316     (setq old-pos (point-at-bol))
4317     (setq current (save-excursion
4318                     (and (re-search-backward "[\r\n]" nil t)
4319                          (gnus-summary-article-number))))
4320     ;; If this is a gathered thread, we have to go some re-gathering.
4321     (when (stringp (car thread))
4322       (let ((subject (car thread))
4323             roots thr)
4324         (setq thread (cdr thread))
4325         (while thread
4326           (unless (memq (setq thr (gnus-id-to-thread
4327                                    (gnus-root-id
4328                                     (mail-header-id (caar thread)))))
4329                         roots)
4330             (push thr roots))
4331           (setq thread (cdr thread)))
4332         ;; We now have all (unique) roots.
4333         (if (= (length roots) 1)
4334             ;; All the loose roots are now one solid root.
4335             (setq thread (car roots))
4336           (setq thread (cons subject (gnus-sort-threads roots))))))
4337     (let (threads)
4338       ;; We then insert this thread into the summary buffer.
4339       (when line
4340         (goto-char (point-min))
4341         (forward-line (1- line)))
4342       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4343         (if gnus-show-threads
4344             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4345           (gnus-summary-prepare-unthreaded thread))
4346         (setq data (nreverse gnus-newsgroup-data))
4347         (setq threads gnus-newsgroup-threads))
4348       ;; We splice the new data into the data structure.
4349       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4350       ;;!!! then we want to insert at the beginning of the buffer.
4351       ;;!!! That happens to be true with Gnus now, but that may
4352       ;;!!! change in the future.  Perhaps.
4353       (gnus-data-enter-list
4354        (if line nil current) data (- (point) old-pos))
4355       (setq gnus-newsgroup-threads
4356             (nconc threads gnus-newsgroup-threads))
4357       (gnus-data-compute-positions))))
4358
4359 (defun gnus-number-to-header (number)
4360   "Return the header for article NUMBER."
4361   (let ((headers gnus-newsgroup-headers))
4362     (while (and headers
4363                 (not (= number (mail-header-number (car headers)))))
4364       (pop headers))
4365     (when headers
4366       (car headers))))
4367
4368 (defun gnus-parent-headers (in-headers &optional generation)
4369   "Return the headers of the GENERATIONeth parent of HEADERS."
4370   (unless generation
4371     (setq generation 1))
4372   (let ((parent t)
4373         (headers in-headers)
4374         references)
4375     (while (and parent
4376                 (not (zerop generation))
4377                 (setq references (mail-header-references headers)))
4378       (setq headers (if (and references
4379                              (setq parent (gnus-parent-id references)))
4380                         (car (gnus-id-to-thread parent))
4381                       nil))
4382       (decf generation))
4383     (and (not (eq headers in-headers))
4384          headers)))
4385
4386 (defun gnus-id-to-thread (id)
4387   "Return the (sub-)thread where ID appears."
4388   (gnus-gethash id gnus-newsgroup-dependencies))
4389
4390 (defun gnus-id-to-article (id)
4391   "Return the article number of ID."
4392   (let ((thread (gnus-id-to-thread id)))
4393     (when (and thread
4394                (car thread))
4395       (mail-header-number (car thread)))))
4396
4397 (defun gnus-id-to-header (id)
4398   "Return the article headers of ID."
4399   (car (gnus-id-to-thread id)))
4400
4401 (defun gnus-article-displayed-root-p (article)
4402   "Say whether ARTICLE is a root(ish) article."
4403   (let ((level (gnus-summary-thread-level article))
4404         (refs (mail-header-references  (gnus-summary-article-header article)))
4405         particle)
4406     (cond
4407      ((null level) nil)
4408      ((zerop level) t)
4409      ((null refs) t)
4410      ((null (gnus-parent-id refs)) t)
4411      ((and (= 1 level)
4412            (null (setq particle (gnus-id-to-article
4413                                  (gnus-parent-id refs))))
4414            (null (gnus-summary-thread-level particle)))))))
4415
4416 (defun gnus-root-id (id)
4417   "Return the id of the root of the thread where ID appears."
4418   (let (last-id prev)
4419     (while (and id (setq prev (car (gnus-id-to-thread id))))
4420       (setq last-id id
4421             id (gnus-parent-id (mail-header-references prev))))
4422     last-id))
4423
4424 (defun gnus-articles-in-thread (thread)
4425   "Return the list of articles in THREAD."
4426   (cons (mail-header-number (car thread))
4427         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4428
4429 (defun gnus-remove-thread (id &optional dont-remove)
4430   "Remove the thread that has ID in it."
4431   (let (headers thread last-id)
4432     ;; First go up in this thread until we find the root.
4433     (setq last-id (gnus-root-id id)
4434           headers (message-flatten-list (gnus-id-to-thread last-id)))
4435     ;; We have now found the real root of this thread.  It might have
4436     ;; been gathered into some loose thread, so we have to search
4437     ;; through the threads to find the thread we wanted.
4438     (let ((threads gnus-newsgroup-threads)
4439           sub)
4440       (while threads
4441         (setq sub (car threads))
4442         (if (stringp (car sub))
4443             ;; This is a gathered thread, so we look at the roots
4444             ;; below it to find whether this article is in this
4445             ;; gathered root.
4446             (progn
4447               (setq sub (cdr sub))
4448               (while sub
4449                 (when (member (caar sub) headers)
4450                   (setq thread (car threads)
4451                         threads nil
4452                         sub nil))
4453                 (setq sub (cdr sub))))
4454           ;; It's an ordinary thread, so we check it.
4455           (when (eq (car sub) (car headers))
4456             (setq thread sub
4457                   threads nil)))
4458         (setq threads (cdr threads)))
4459       ;; If this article is in no thread, then it's a root.
4460       (if thread
4461           (unless dont-remove
4462             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4463         (setq thread (gnus-id-to-thread last-id)))
4464       (when thread
4465         (prog1
4466             thread                      ; We return this thread.
4467           (unless dont-remove
4468             (if (stringp (car thread))
4469                 (progn
4470                   ;; If we use dummy roots, then we have to remove the
4471                   ;; dummy root as well.
4472                   (when (eq gnus-summary-make-false-root 'dummy)
4473                     ;; We go to the dummy root by going to
4474                     ;; the first sub-"thread", and then one line up.
4475                     (gnus-summary-goto-article
4476                      (mail-header-number (caadr thread)))
4477                     (forward-line -1)
4478                     (gnus-delete-line)
4479                     (gnus-data-compute-positions))
4480                   (setq thread (cdr thread))
4481                   (while thread
4482                     (gnus-remove-thread-1 (car thread))
4483                     (setq thread (cdr thread))))
4484               (gnus-remove-thread-1 thread))))))))
4485
4486 (defun gnus-remove-thread-1 (thread)
4487   "Remove the thread THREAD recursively."
4488   (let ((number (mail-header-number (pop thread)))
4489         d)
4490     (setq thread (reverse thread))
4491     (while thread
4492       (gnus-remove-thread-1 (pop thread)))
4493     (when (setq d (gnus-data-find number))
4494       (goto-char (gnus-data-pos d))
4495       (gnus-summary-show-thread)
4496       (gnus-data-remove
4497        number
4498        (- (point-at-bol)
4499           (prog1
4500               (1+ (point-at-eol))
4501             (gnus-delete-line)))))))
4502
4503 (defun gnus-sort-threads-1 (threads func)
4504   (sort (mapcar (lambda (thread)
4505                   (cons (car thread)
4506                         (and (cdr thread)
4507                              (gnus-sort-threads-1 (cdr thread) func))))
4508                 threads) func))
4509
4510 (defun gnus-sort-threads (threads)
4511   "Sort THREADS."
4512   (if (not gnus-thread-sort-functions)
4513       threads
4514     (gnus-message 8 "Sorting threads...")
4515     (let ((max-lisp-eval-depth 5000))
4516       (prog1 (gnus-sort-threads-1
4517          threads
4518          (gnus-make-sort-function gnus-thread-sort-functions))
4519         (gnus-message 8 "Sorting threads...done")))))
4520
4521 (defun gnus-sort-articles (articles)
4522   "Sort ARTICLES."
4523   (when gnus-article-sort-functions
4524     (gnus-message 7 "Sorting articles...")
4525     (prog1
4526         (setq gnus-newsgroup-headers
4527               (sort articles (gnus-make-sort-function
4528                               gnus-article-sort-functions)))
4529       (gnus-message 7 "Sorting articles...done"))))
4530
4531 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4532 (defmacro gnus-thread-header (thread)
4533   "Return header of first article in THREAD.
4534 Note that THREAD must never, ever be anything else than a variable -
4535 using some other form will lead to serious barfage."
4536   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4537   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4538   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4539         (vector thread) 2))
4540
4541 (defsubst gnus-article-sort-by-number (h1 h2)
4542   "Sort articles by article number."
4543   (< (mail-header-number h1)
4544      (mail-header-number h2)))
4545
4546 (defun gnus-thread-sort-by-number (h1 h2)
4547   "Sort threads by root article number."
4548   (gnus-article-sort-by-number
4549    (gnus-thread-header h1) (gnus-thread-header h2)))
4550
4551 (defsubst gnus-article-sort-by-random (h1 h2)
4552   "Sort articles by article number."
4553   (zerop (random 2)))
4554
4555 (defun gnus-thread-sort-by-random (h1 h2)
4556   "Sort threads by root article number."
4557   (gnus-article-sort-by-random
4558    (gnus-thread-header h1) (gnus-thread-header h2)))
4559
4560 (defsubst gnus-article-sort-by-lines (h1 h2)
4561   "Sort articles by article Lines header."
4562   (< (mail-header-lines h1)
4563      (mail-header-lines h2)))
4564
4565 (defun gnus-thread-sort-by-lines (h1 h2)
4566   "Sort threads by root article Lines header."
4567   (gnus-article-sort-by-lines
4568    (gnus-thread-header h1) (gnus-thread-header h2)))
4569
4570 (defsubst gnus-article-sort-by-chars (h1 h2)
4571   "Sort articles by octet length."
4572   (< (mail-header-chars h1)
4573      (mail-header-chars h2)))
4574
4575 (defun gnus-thread-sort-by-chars (h1 h2)
4576   "Sort threads by root article octet length."
4577   (gnus-article-sort-by-chars
4578    (gnus-thread-header h1) (gnus-thread-header h2)))
4579
4580 (defsubst gnus-article-sort-by-author (h1 h2)
4581   "Sort articles by root author."
4582   (string-lessp
4583    (let ((addr (car (mime-entity-read-field h1 'From))))
4584      (or (std11-full-name-string addr)
4585          (std11-address-string addr)
4586          ""))
4587    (let ((addr (car (mime-entity-read-field h2 'From))))
4588      (or (std11-full-name-string addr)
4589          (std11-address-string addr)
4590          ""))
4591    ))
4592
4593 (defun gnus-thread-sort-by-author (h1 h2)
4594   "Sort threads by root author."
4595   (gnus-article-sort-by-author
4596    (gnus-thread-header h1)  (gnus-thread-header h2)))
4597
4598 (defsubst gnus-article-sort-by-recipient (h1 h2)
4599   "Sort articles by recipient."
4600   (string-lessp
4601    (let ((extract (funcall
4602                    gnus-extract-address-components
4603                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4604      (or (car extract) (cadr extract)))
4605    (let ((extract (funcall
4606                    gnus-extract-address-components
4607                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4608      (or (car extract) (cadr extract)))))
4609
4610 (defun gnus-thread-sort-by-recipient (h1 h2)
4611   "Sort threads by root recipient."
4612   (gnus-article-sort-by-recipient
4613    (gnus-thread-header h1) (gnus-thread-header h2)))
4614
4615 (defsubst gnus-article-sort-by-subject (h1 h2)
4616   "Sort articles by root subject."
4617   (string-lessp
4618    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4619    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4620
4621 (defun gnus-thread-sort-by-subject (h1 h2)
4622   "Sort threads by root subject."
4623   (gnus-article-sort-by-subject
4624    (gnus-thread-header h1) (gnus-thread-header h2)))
4625
4626 (defsubst gnus-article-sort-by-date (h1 h2)
4627   "Sort articles by root article date."
4628   (time-less-p
4629    (gnus-date-get-time (mail-header-date h1))
4630    (gnus-date-get-time (mail-header-date h2))))
4631
4632 (defun gnus-thread-sort-by-date (h1 h2)
4633   "Sort threads by root article date."
4634   (gnus-article-sort-by-date
4635    (gnus-thread-header h1) (gnus-thread-header h2)))
4636
4637 (defsubst gnus-article-sort-by-score (h1 h2)
4638   "Sort articles by root article score.
4639 Unscored articles will be counted as having a score of zero."
4640   (> (or (cdr (assq (mail-header-number h1)
4641                     gnus-newsgroup-scored))
4642          gnus-summary-default-score 0)
4643      (or (cdr (assq (mail-header-number h2)
4644                     gnus-newsgroup-scored))
4645          gnus-summary-default-score 0)))
4646
4647 (defun gnus-thread-sort-by-score (h1 h2)
4648   "Sort threads by root article score."
4649   (gnus-article-sort-by-score
4650    (gnus-thread-header h1) (gnus-thread-header h2)))
4651
4652 (defun gnus-thread-sort-by-total-score (h1 h2)
4653   "Sort threads by the sum of all scores in the thread.
4654 Unscored articles will be counted as having a score of zero."
4655   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4656
4657 (defun gnus-thread-total-score (thread)
4658   ;; This function find the total score of THREAD.
4659   (cond
4660    ((null thread)
4661     0)
4662    ((consp thread)
4663     (if (stringp (car thread))
4664         (apply gnus-thread-score-function 0
4665                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4666       (gnus-thread-total-score-1 thread)))
4667    (t
4668     (gnus-thread-total-score-1 (list thread)))))
4669
4670 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4671   "Sort threads such that the thread with the most recently arrived article comes first."
4672   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4673
4674 (defun gnus-thread-highest-number (thread)
4675   "Return the highest article number in THREAD."
4676   (apply 'max (mapcar (lambda (header)
4677                         (mail-header-number header))
4678                       (message-flatten-list thread))))
4679
4680 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4681   "Sort threads such that the thread with the most recently dated article comes first."
4682   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4683
4684 (defun gnus-thread-latest-date (thread)
4685   "Return the highest article date in THREAD."
4686   (let ((previous-time 0))
4687     (apply 'max
4688            (mapcar
4689             (lambda (header)
4690               (setq previous-time
4691                     (condition-case ()
4692                         (time-to-seconds (mail-header-parse-date
4693                                           (mail-header-date header)))
4694                       (error previous-time))))
4695             (sort
4696              (message-flatten-list thread)
4697              (lambda (h1 h2)
4698                (< (mail-header-number h1)
4699                   (mail-header-number h2))))))))
4700
4701 (defun gnus-thread-total-score-1 (root)
4702   ;; This function find the total score of the thread below ROOT.
4703   (setq root (car root))
4704   (apply gnus-thread-score-function
4705          (or (append
4706               (mapcar 'gnus-thread-total-score
4707                       (cdr (gnus-id-to-thread (mail-header-id root))))
4708               (when (> (mail-header-number root) 0)
4709                 (list (or (cdr (assq (mail-header-number root)
4710                                      gnus-newsgroup-scored))
4711                           gnus-summary-default-score 0))))
4712              (list gnus-summary-default-score)
4713              '(0))))
4714
4715 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4716 (defvar gnus-tmp-prev-subject nil)
4717 (defvar gnus-tmp-false-parent nil)
4718 (defvar gnus-tmp-root-expunged nil)
4719 (defvar gnus-tmp-dummy-line nil)
4720
4721 (eval-when-compile (defvar gnus-tmp-header))
4722 (defun gnus-extra-header (type &optional header)
4723   "Return the extra header of TYPE."
4724   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4725       ""))
4726
4727 (defvar gnus-tmp-thread-tree-header-string "")
4728
4729 (defcustom gnus-sum-thread-tree-root "> "
4730   "With %B spec, used for the root of a thread.
4731 If nil, use subject instead."
4732   :version "22.1"
4733   :type '(radio (const :format "%v  " nil) string)
4734   :group 'gnus-thread)
4735
4736 (defcustom gnus-sum-thread-tree-false-root "> "
4737   "With %B spec, used for a false root of a thread.
4738 If nil, use subject instead."
4739   :version "22.1"
4740   :type '(radio (const :format "%v  " nil) string)
4741   :group 'gnus-thread)
4742
4743 (defcustom gnus-sum-thread-tree-single-indent ""
4744   "With %B spec, used for a thread with just one message.
4745 If nil, use subject instead."
4746   :version "22.1"
4747   :type '(radio (const :format "%v  " nil) string)
4748   :group 'gnus-thread)
4749
4750 (defcustom gnus-sum-thread-tree-vertical "| "
4751   "With %B spec, used for drawing a vertical line."
4752   :version "22.1"
4753   :type 'string
4754   :group 'gnus-thread)
4755
4756 (defcustom gnus-sum-thread-tree-indent "  "
4757   "With %B spec, used for indenting."
4758   :version "22.1"
4759   :type 'string
4760   :group 'gnus-thread)
4761
4762 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4763   "With %B spec, used for a leaf with brothers."
4764   :version "22.1"
4765   :type 'string
4766   :group 'gnus-thread)
4767
4768 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4769   "With %B spec, used for a leaf without brothers."
4770   :version "22.1"
4771   :type 'string
4772   :group 'gnus-thread)
4773
4774 (defun gnus-summary-prepare-threads (threads)
4775   "Prepare summary buffer from THREADS and indentation LEVEL.
4776 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4777 or a straight list of headers."
4778   (gnus-message 7 "Generating summary...")
4779
4780   (setq gnus-newsgroup-threads threads)
4781   (beginning-of-line)
4782
4783   (let ((gnus-tmp-level 0)
4784         (default-score (or gnus-summary-default-score 0))
4785         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4786         (building-line-count gnus-summary-display-while-building)
4787         (building-count (integerp gnus-summary-display-while-building))
4788         thread number subject stack state gnus-tmp-gathered beg-match
4789         new-roots gnus-tmp-new-adopts thread-end simp-subject
4790         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4791         gnus-tmp-replied gnus-tmp-subject-or-nil
4792         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4793         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4794         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4795         tree-stack)
4796
4797     (setq gnus-tmp-prev-subject nil
4798           gnus-tmp-thread-tree-header-string "")
4799
4800     (if (vectorp (car threads))
4801         ;; If this is a straight (sic) list of headers, then a
4802         ;; threaded summary display isn't required, so we just create
4803         ;; an unthreaded one.
4804         (gnus-summary-prepare-unthreaded threads)
4805
4806       ;; Do the threaded display.
4807
4808       (if gnus-summary-display-while-building
4809           (switch-to-buffer (buffer-name)))
4810       (while (or threads stack gnus-tmp-new-adopts new-roots)
4811
4812         (if (and (= gnus-tmp-level 0)
4813                  (or (not stack)
4814                      (= (caar stack) 0))
4815                  (not gnus-tmp-false-parent)
4816                  (or gnus-tmp-new-adopts new-roots))
4817             (if gnus-tmp-new-adopts
4818                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4819                       thread (list (car gnus-tmp-new-adopts))
4820                       gnus-tmp-header (caar thread)
4821                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4822               (when new-roots
4823                 (setq thread (list (car new-roots))
4824                       gnus-tmp-header (caar thread)
4825                       new-roots (cdr new-roots))))
4826
4827           (if threads
4828               ;; If there are some threads, we do them before the
4829               ;; threads on the stack.
4830               (setq thread threads
4831                     gnus-tmp-header (caar thread))
4832             ;; There were no current threads, so we pop something off
4833             ;; the stack.
4834             (setq state (car stack)
4835                   gnus-tmp-level (car state)
4836                   tree-stack (cadr state)
4837                   thread (caddr state)
4838                   stack (cdr stack)
4839                   gnus-tmp-header (caar thread))))
4840
4841         (setq gnus-tmp-false-parent nil)
4842         (setq gnus-tmp-root-expunged nil)
4843         (setq thread-end nil)
4844
4845         (if (stringp gnus-tmp-header)
4846             ;; The header is a dummy root.
4847             (cond
4848              ((eq gnus-summary-make-false-root 'adopt)
4849               ;; We let the first article adopt the rest.
4850               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4851                                                (cddar thread)))
4852               (setq gnus-tmp-gathered
4853                     (nconc (mapcar
4854                             (lambda (h) (mail-header-number (car h)))
4855                             (cddar thread))
4856                            gnus-tmp-gathered))
4857               (setq thread (cons (list (caar thread)
4858                                        (cadar thread))
4859                                  (cdr thread)))
4860               (setq gnus-tmp-level -1
4861                     gnus-tmp-false-parent t))
4862              ((eq gnus-summary-make-false-root 'empty)
4863               ;; We print adopted articles with empty subject fields.
4864               (setq gnus-tmp-gathered
4865                     (nconc (mapcar
4866                             (lambda (h) (mail-header-number (car h)))
4867                             (cddar thread))
4868                            gnus-tmp-gathered))
4869               (setq gnus-tmp-level -1))
4870              ((eq gnus-summary-make-false-root 'dummy)
4871               ;; We remember that we probably want to output a dummy
4872               ;; root.
4873               (setq gnus-tmp-dummy-line gnus-tmp-header)
4874               (setq gnus-tmp-prev-subject gnus-tmp-header))
4875              (t
4876               ;; We do not make a root for the gathered
4877               ;; sub-threads at all.
4878               (setq gnus-tmp-level -1)))
4879
4880           (setq number (mail-header-number gnus-tmp-header)
4881                 subject (mail-header-subject gnus-tmp-header)
4882                 simp-subject (gnus-simplify-subject-fully subject))
4883
4884           (cond
4885            ;; If the thread has changed subject, we might want to make
4886            ;; this subthread into a root.
4887            ((and (null gnus-thread-ignore-subject)
4888                  (not (zerop gnus-tmp-level))
4889                  gnus-tmp-prev-subject
4890                  (not (string= gnus-tmp-prev-subject simp-subject)))
4891             (setq new-roots (nconc new-roots (list (car thread)))
4892                   thread-end t
4893                   gnus-tmp-header nil))
4894            ;; If the article lies outside the current limit,
4895            ;; then we do not display it.
4896            ((not (memq number gnus-newsgroup-limit))
4897             (setq gnus-tmp-gathered
4898                   (nconc (mapcar
4899                           (lambda (h) (mail-header-number (car h)))
4900                           (cdar thread))
4901                          gnus-tmp-gathered))
4902             (setq gnus-tmp-new-adopts (if (cdar thread)
4903                                           (append gnus-tmp-new-adopts
4904                                                   (cdar thread))
4905                                         gnus-tmp-new-adopts)
4906                   thread-end t
4907                   gnus-tmp-header nil)
4908             (when (zerop gnus-tmp-level)
4909               (setq gnus-tmp-root-expunged t)))
4910            ;; Perhaps this article is to be marked as read?
4911            ((and gnus-summary-mark-below
4912                  (< (or (cdr (assq number gnus-newsgroup-scored))
4913                         default-score)
4914                     gnus-summary-mark-below)
4915                  ;; Don't touch sparse articles.
4916                  (not (gnus-summary-article-sparse-p number))
4917                  (not (gnus-summary-article-ancient-p number)))
4918             (setq gnus-newsgroup-unreads
4919                   (delq number gnus-newsgroup-unreads))
4920             (if gnus-newsgroup-auto-expire
4921                 (setq gnus-newsgroup-expirable
4922                       (gnus-add-to-sorted-list
4923                        gnus-newsgroup-expirable number))
4924               (push (cons number gnus-low-score-mark)
4925                     gnus-newsgroup-reads))))
4926
4927           (when gnus-tmp-header
4928             ;; We may have an old dummy line to output before this
4929             ;; article.
4930             (when (and gnus-tmp-dummy-line
4931                        (gnus-subject-equal
4932                         gnus-tmp-dummy-line
4933                         (mail-header-subject gnus-tmp-header)))
4934               (gnus-summary-insert-dummy-line
4935                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4936               (setq gnus-tmp-dummy-line nil))
4937
4938             ;; Compute the mark.
4939             (setq gnus-tmp-unread (gnus-article-mark number))
4940
4941             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4942                                   gnus-tmp-header gnus-tmp-level)
4943                   gnus-newsgroup-data)
4944
4945             ;; Actually insert the line.
4946             (setq
4947              gnus-tmp-subject-or-nil
4948              (cond
4949               ((and gnus-thread-ignore-subject
4950                     gnus-tmp-prev-subject
4951                     (not (string= gnus-tmp-prev-subject simp-subject)))
4952                subject)
4953               ((zerop gnus-tmp-level)
4954                (if (and (eq gnus-summary-make-false-root 'empty)
4955                         (memq number gnus-tmp-gathered)
4956                         gnus-tmp-prev-subject
4957                         (string= gnus-tmp-prev-subject simp-subject))
4958                    gnus-summary-same-subject
4959                  subject))
4960               (t gnus-summary-same-subject)))
4961             (if (and (eq gnus-summary-make-false-root 'adopt)
4962                      (= gnus-tmp-level 1)
4963                      (memq number gnus-tmp-gathered))
4964                 (setq gnus-tmp-opening-bracket ?\<
4965                       gnus-tmp-closing-bracket ?\>)
4966               (setq gnus-tmp-opening-bracket ?\[
4967                     gnus-tmp-closing-bracket ?\]))
4968             (setq
4969              gnus-tmp-indentation
4970              (aref gnus-thread-indent-array gnus-tmp-level)
4971              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4972              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4973                                 gnus-summary-default-score 0)
4974              gnus-tmp-score-char
4975              (if (or (null gnus-summary-default-score)
4976                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4977                          gnus-summary-zcore-fuzz))
4978                  ?\ ;;;Whitespace
4979                (if (< gnus-tmp-score gnus-summary-default-score)
4980                    gnus-score-below-mark gnus-score-over-mark))
4981              gnus-tmp-replied
4982              (cond ((memq number gnus-newsgroup-processable)
4983                     gnus-process-mark)
4984                    ((memq number gnus-newsgroup-cached)
4985                     gnus-cached-mark)
4986                    ((memq number gnus-newsgroup-replied)
4987                     gnus-replied-mark)
4988                    ((memq number gnus-newsgroup-forwarded)
4989                     gnus-forwarded-mark)
4990                    ((memq number gnus-newsgroup-saved)
4991                     gnus-saved-mark)
4992                    ((memq number gnus-newsgroup-recent)
4993                     gnus-recent-mark)
4994                    ((memq number gnus-newsgroup-unseen)
4995                     gnus-unseen-mark)
4996                    (t gnus-no-mark))
4997              gnus-tmp-downloaded
4998              (cond ((memq number gnus-newsgroup-undownloaded)
4999                     gnus-undownloaded-mark)
5000                    (gnus-newsgroup-agentized
5001                     gnus-downloaded-mark)
5002                    (t
5003                     gnus-no-mark))
5004              gnus-tmp-from (mail-header-from gnus-tmp-header)
5005              gnus-tmp-name
5006              (cond
5007               ((string-match "<[^>]+> *$" gnus-tmp-from)
5008                (setq beg-match (match-beginning 0))
5009                (or (and (string-match "^\".+\"" gnus-tmp-from)
5010                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5011                    (substring gnus-tmp-from 0 beg-match)))
5012               ((string-match "(.+)" gnus-tmp-from)
5013                (substring gnus-tmp-from
5014                           (1+ (match-beginning 0)) (1- (match-end 0))))
5015               (t gnus-tmp-from))
5016
5017              ;; Do the %B string
5018              gnus-tmp-thread-tree-header-string
5019              (cond
5020               ((not gnus-show-threads) "")
5021               ((zerop gnus-tmp-level)
5022                (cond ((cdar thread)
5023                       (or gnus-sum-thread-tree-root subject))
5024                      (gnus-tmp-new-adopts
5025                       (or gnus-sum-thread-tree-false-root subject))
5026                      (t
5027                       (or gnus-sum-thread-tree-single-indent subject))))
5028               (t
5029                (concat (apply 'concat
5030                               (mapcar (lambda (item)
5031                                         (if (= item 1)
5032                                             gnus-sum-thread-tree-vertical
5033                                           gnus-sum-thread-tree-indent))
5034                                       (cdr (reverse tree-stack))))
5035                        (if (nth 1 thread)
5036                            gnus-sum-thread-tree-leaf-with-other
5037                          gnus-sum-thread-tree-single-leaf)))))
5038             (when (string= gnus-tmp-name "")
5039               (setq gnus-tmp-name gnus-tmp-from))
5040             (unless (numberp gnus-tmp-lines)
5041               (setq gnus-tmp-lines -1))
5042             (if (= gnus-tmp-lines -1)
5043                 (setq gnus-tmp-lines "?")
5044               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5045               (gnus-put-text-property
5046              (point)
5047              (progn (eval gnus-summary-line-format-spec) (point))
5048                'gnus-number number)
5049             (when gnus-visual-p
5050               (forward-line -1)
5051               (gnus-run-hooks 'gnus-summary-update-hook)
5052               (forward-line 1))
5053
5054             (setq gnus-tmp-prev-subject simp-subject)))
5055
5056         (when (nth 1 thread)
5057           (push (list (max 0 gnus-tmp-level)
5058                       (copy-sequence tree-stack)
5059                       (nthcdr 1 thread))
5060                 stack))
5061         (push (if (nth 1 thread) 1 0) tree-stack)
5062         (incf gnus-tmp-level)
5063         (setq threads (if thread-end nil (cdar thread)))
5064         (if gnus-summary-display-while-building
5065             (if building-count
5066                 (progn
5067                   ;; use a set frequency
5068                   (setq building-line-count (1- building-line-count))
5069                   (when (= building-line-count 0)
5070                     (sit-for 0)
5071                     (setq building-line-count
5072                           gnus-summary-display-while-building)))
5073               ;; always
5074               (sit-for 0)))
5075         (unless threads
5076           (setq gnus-tmp-level 0)))))
5077   (gnus-message 7 "Generating summary...done"))
5078
5079 (defun gnus-summary-prepare-unthreaded (headers)
5080   "Generate an unthreaded summary buffer based on HEADERS."
5081   (let (header number mark)
5082
5083     (beginning-of-line)
5084
5085     (while headers
5086       ;; We may have to root out some bad articles...
5087       (when (memq (setq number (mail-header-number
5088                                 (setq header (pop headers))))
5089                   gnus-newsgroup-limit)
5090         ;; Mark article as read when it has a low score.
5091         (when (and gnus-summary-mark-below
5092                    (< (or (cdr (assq number gnus-newsgroup-scored))
5093                           gnus-summary-default-score 0)
5094                       gnus-summary-mark-below)
5095                    (not (gnus-summary-article-ancient-p number)))
5096           (setq gnus-newsgroup-unreads
5097                 (delq number gnus-newsgroup-unreads))
5098           (if gnus-newsgroup-auto-expire
5099               (push number gnus-newsgroup-expirable)
5100             (push (cons number gnus-low-score-mark)
5101                   gnus-newsgroup-reads)))
5102
5103         (setq mark (gnus-article-mark number))
5104         (push (gnus-data-make number mark (1+ (point)) header 0)
5105               gnus-newsgroup-data)
5106         (gnus-summary-insert-line
5107          header 0 number
5108          (memq number gnus-newsgroup-undownloaded)
5109          mark (memq number gnus-newsgroup-replied)
5110          (memq number gnus-newsgroup-expirable)
5111          (mail-header-subject header) nil
5112          (cdr (assq number gnus-newsgroup-scored))
5113          (memq number gnus-newsgroup-processable))))))
5114
5115 (defun gnus-summary-remove-list-identifiers ()
5116   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5117   (let ((regexp (if (consp gnus-list-identifiers)
5118                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5119                   gnus-list-identifiers))
5120         changed subject)
5121     (when regexp
5122       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5123       (dolist (header gnus-newsgroup-headers)
5124         (setq subject (mail-header-subject header)
5125               changed nil)
5126         (while (string-match regexp subject)
5127           (setq subject
5128                 (concat (substring subject 0 (match-beginning 1))
5129                         (substring subject (match-end 0)))
5130                 changed t))
5131         (when changed
5132           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5133             (setq subject
5134                   (concat (substring subject 0 (match-beginning 1))
5135                           (substring subject (match-end 1)))))
5136           (mail-header-set-subject header subject))))))
5137
5138 (defun gnus-fetch-headers (articles)
5139   "Fetch headers of ARTICLES."
5140   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5141     (gnus-message 5 "Fetching headers for %s..." name)
5142     (prog1
5143         (if (eq 'nov
5144                 (setq gnus-headers-retrieved-by
5145                       (gnus-retrieve-headers
5146                        articles gnus-newsgroup-name
5147                        ;; We might want to fetch old headers, but
5148                        ;; not if there is only 1 article.
5149                        (and (or (and
5150                                  (not (eq gnus-fetch-old-headers 'some))
5151                                  (not (numberp gnus-fetch-old-headers)))
5152                                 (> (length articles) 1))
5153                             gnus-fetch-old-headers))))
5154             (gnus-get-newsgroup-headers-xover
5155              articles nil nil gnus-newsgroup-name t)
5156           (gnus-get-newsgroup-headers))
5157       (gnus-message 5 "Fetching headers for %s...done" name))))
5158
5159 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5160   "Select newsgroup GROUP.
5161 If READ-ALL is non-nil, all articles in the group are selected.
5162 If SELECT-ARTICLES, only select those articles from GROUP."
5163   (let* ((entry (gnus-group-entry group))
5164          ;;!!! Dirty hack; should be removed.
5165          (gnus-summary-ignore-duplicates
5166           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5167               t
5168             gnus-summary-ignore-duplicates))
5169          (info (nth 2 entry))
5170          articles fetched-articles cached)
5171
5172     (unless (gnus-check-server
5173              (set (make-local-variable 'gnus-current-select-method)
5174                   (gnus-find-method-for-group group)))
5175       (error "Couldn't open server"))
5176
5177     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5178         (gnus-activate-group group)     ; Or we can activate it...
5179         (progn                          ; Or we bug out.
5180           (when (equal major-mode 'gnus-summary-mode)
5181             (gnus-kill-buffer (current-buffer)))
5182           (error "Couldn't activate group %s: %s"
5183                  group (gnus-status-message group))))
5184
5185     (unless (gnus-request-group group t)
5186       (when (equal major-mode 'gnus-summary-mode)
5187         (gnus-kill-buffer (current-buffer)))
5188       (error "Couldn't request group %s: %s"
5189              group (gnus-status-message group)))
5190
5191     (when gnus-agent
5192       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5193
5194       (setq gnus-summary-use-undownloaded-faces
5195             (gnus-agent-find-parameter
5196              group
5197              'agent-enable-undownloaded-faces)))
5198
5199     (setq gnus-newsgroup-name group
5200           gnus-newsgroup-unselected nil
5201           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5202
5203     (let ((display (gnus-group-find-parameter group 'display)))
5204       (setq gnus-newsgroup-display
5205             (cond
5206              ((not (zerop (or (car-safe read-all) 0)))
5207               ;; The user entered the group with C-u SPC/RET, let's show
5208               ;; all articles.
5209               'gnus-not-ignore)
5210              ((eq display 'all)
5211               'gnus-not-ignore)
5212              ((arrayp display)
5213               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5214              ((numberp display)
5215               ;; The following is probably the "correct" solution, but
5216               ;; it makes Gnus fetch all headers and then limit the
5217               ;; articles (which is slow), so instead we hack the
5218               ;; select-articles parameter instead. -- Simon Josefsson
5219               ;; <jas@kth.se>
5220               ;;
5221               ;; (gnus-byte-compile
5222               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5223               ;;                         display)))))
5224               (setq select-articles
5225                     (gnus-uncompress-range
5226                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5227                              (if (> tmp 0)
5228                                  tmp
5229                                1))
5230                            (cdr (gnus-active group)))))
5231               nil)
5232              (t
5233               nil))))
5234
5235     (gnus-summary-setup-default-charset)
5236
5237     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5238     (when (gnus-virtual-group-p group)
5239       (setq cached gnus-newsgroup-cached))
5240
5241     (setq gnus-newsgroup-unreads
5242           (gnus-sorted-ndifference
5243            (gnus-sorted-ndifference gnus-newsgroup-unreads
5244                                     gnus-newsgroup-marked)
5245            gnus-newsgroup-dormant))
5246
5247     (setq gnus-newsgroup-processable nil)
5248
5249     (gnus-update-read-articles group gnus-newsgroup-unreads)
5250
5251     ;; Adjust and set lists of article marks.
5252     (when info
5253       (gnus-adjust-marked-articles info))
5254     (if (setq articles select-articles)
5255         (setq gnus-newsgroup-unselected
5256               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5257       (setq articles (gnus-articles-to-read group read-all)))
5258
5259     (cond
5260      ((null articles)
5261       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5262       'quit)
5263      ((eq articles 0) nil)
5264      (t
5265       ;; Init the dependencies hash table.
5266       (setq gnus-newsgroup-dependencies
5267             (gnus-make-hashtable (length articles)))
5268       (gnus-set-global-variables)
5269       ;; Retrieve the headers and read them in.
5270
5271       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5272
5273       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5274       (when cached
5275         (setq gnus-newsgroup-cached cached))
5276
5277       ;; Suppress duplicates?
5278       (when gnus-suppress-duplicates
5279         (gnus-dup-suppress-articles))
5280
5281       ;; Set the initial limit.
5282       (setq gnus-newsgroup-limit (copy-sequence articles))
5283       ;; Remove canceled articles from the list of unread articles.
5284       (setq fetched-articles
5285             (mapcar (lambda (headers) (mail-header-number headers))
5286                     gnus-newsgroup-headers))
5287       (setq gnus-newsgroup-articles fetched-articles)
5288       (setq gnus-newsgroup-unreads
5289             (gnus-sorted-nintersection
5290              gnus-newsgroup-unreads fetched-articles))
5291       (gnus-compute-unseen-list)
5292
5293       ;; Removed marked articles that do not exist.
5294       (gnus-update-missing-marks
5295        (gnus-sorted-difference articles fetched-articles))
5296       ;; We might want to build some more threads first.
5297       (when (and gnus-fetch-old-headers
5298                  (eq gnus-headers-retrieved-by 'nov))
5299         (if (eq gnus-fetch-old-headers 'invisible)
5300             (gnus-build-all-threads)
5301           (gnus-build-old-threads)))
5302       ;; Let the Gnus agent mark articles as read.
5303       (when gnus-agent
5304         (gnus-agent-get-undownloaded-list))
5305       ;; Remove list identifiers from subject
5306       (when gnus-list-identifiers
5307         (gnus-summary-remove-list-identifiers))
5308       ;; Check whether auto-expire is to be done in this group.
5309       (setq gnus-newsgroup-auto-expire
5310             (gnus-group-auto-expirable-p group))
5311       ;; Set up the article buffer now, if necessary.
5312       (unless gnus-single-article-buffer
5313         (gnus-article-setup-buffer))
5314       ;; First and last article in this newsgroup.
5315       (when gnus-newsgroup-headers
5316         (setq gnus-newsgroup-begin
5317               (mail-header-number (car gnus-newsgroup-headers))
5318               gnus-newsgroup-end
5319               (mail-header-number
5320                (gnus-last-element gnus-newsgroup-headers))))
5321       ;; GROUP is successfully selected.
5322       (or gnus-newsgroup-headers t)))))
5323
5324 (defun gnus-compute-unseen-list ()
5325   ;; The `seen' marks are treated specially.
5326   (if (not gnus-newsgroup-seen)
5327       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5328     (setq gnus-newsgroup-unseen
5329           (gnus-inverse-list-range-intersection
5330            gnus-newsgroup-articles gnus-newsgroup-seen))))
5331
5332 (defun gnus-summary-display-make-predicate (display)
5333   (require 'gnus-agent)
5334   (when (= (length display) 1)
5335     (setq display (car display)))
5336   (unless gnus-summary-display-cache
5337     (dolist (elem (append '((unread . unread)
5338                             (read . read)
5339                             (unseen . unseen))
5340                           gnus-article-mark-lists))
5341       (push (cons (cdr elem)
5342                   (gnus-byte-compile
5343                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5344             gnus-summary-display-cache)))
5345   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5346         (gnus-category-predicate-cache gnus-summary-display-cache))
5347     (gnus-get-predicate display)))
5348
5349 ;; Uses the dynamically bound `number' variable.
5350 (eval-when-compile
5351   (defvar number))
5352 (defun gnus-article-marked-p (type &optional article)
5353   (let ((article (or article number)))
5354     (cond
5355      ((eq type 'tick)
5356       (memq article gnus-newsgroup-marked))
5357      ((eq type 'spam)
5358       (memq article gnus-newsgroup-spam-marked))
5359      ((eq type 'unsend)
5360       (memq article gnus-newsgroup-unsendable))
5361      ((eq type 'undownload)
5362       (memq article gnus-newsgroup-undownloaded))
5363      ((eq type 'download)
5364       (memq article gnus-newsgroup-downloadable))
5365      ((eq type 'unread)
5366       (memq article gnus-newsgroup-unreads))
5367      ((eq type 'read)
5368       (memq article gnus-newsgroup-reads))
5369      ((eq type 'dormant)
5370       (memq article gnus-newsgroup-dormant) )
5371      ((eq type 'expire)
5372       (memq article gnus-newsgroup-expirable))
5373      ((eq type 'reply)
5374       (memq article gnus-newsgroup-replied))
5375      ((eq type 'killed)
5376       (memq article gnus-newsgroup-killed))
5377      ((eq type 'bookmark)
5378       (assq article gnus-newsgroup-bookmarks))
5379      ((eq type 'score)
5380       (assq article gnus-newsgroup-scored))
5381      ((eq type 'save)
5382       (memq article gnus-newsgroup-saved))
5383      ((eq type 'cache)
5384       (memq article gnus-newsgroup-cached))
5385      ((eq type 'forward)
5386       (memq article gnus-newsgroup-forwarded))
5387      ((eq type 'seen)
5388       (not (memq article gnus-newsgroup-unseen)))
5389      ((eq type 'recent)
5390       (memq article gnus-newsgroup-recent))
5391      (t t))))
5392
5393 (defun gnus-articles-to-read (group &optional read-all)
5394   "Find out what articles the user wants to read."
5395   (let* ((articles
5396           ;; Select all articles if `read-all' is non-nil, or if there
5397           ;; are no unread articles.
5398           (if (or read-all
5399                   (and (zerop (length gnus-newsgroup-marked))
5400                        (zerop (length gnus-newsgroup-unreads)))
5401                   ;; Fetch all if the predicate is non-nil.
5402                   gnus-newsgroup-display)
5403               ;; We want to select the headers for all the articles in
5404               ;; the group, so we select either all the active
5405               ;; articles in the group, or (if that's nil), the
5406               ;; articles in the cache.
5407               (or
5408                (gnus-uncompress-range (gnus-active group))
5409                (gnus-cache-articles-in-group group))
5410             ;; Select only the "normal" subset of articles.
5411             (gnus-sorted-nunion
5412              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5413              gnus-newsgroup-unreads)))
5414          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5415          (scored (length scored-list))
5416          (number (length articles))
5417          (marked (+ (length gnus-newsgroup-marked)
5418                     (length gnus-newsgroup-dormant)))
5419          (select
5420           (cond
5421            ((numberp read-all)
5422             read-all)
5423            ((numberp gnus-newsgroup-display)
5424             gnus-newsgroup-display)
5425            (t
5426             (condition-case ()
5427                 (cond
5428                  ((and (or (<= scored marked) (= scored number))
5429                        (numberp gnus-large-newsgroup)
5430                        (> number gnus-large-newsgroup))
5431                   (let* ((cursor-in-echo-area nil)
5432                          (initial (gnus-parameter-large-newsgroup-initial
5433                                    gnus-newsgroup-name))
5434                          (input
5435                           (read-string
5436                            (format
5437                             "How many articles from %s (%s %d): "
5438                             (gnus-limit-string
5439                              (gnus-group-decoded-name gnus-newsgroup-name)
5440                              35)
5441                             (if initial "max" "default")
5442                             number)
5443                            (if initial
5444                                (cons (number-to-string initial)
5445                                      0)))))
5446                     (if (string-match "^[ \t]*$" input) number input)))
5447                  ((and (> scored marked) (< scored number)
5448                        (> (- scored number) 20))
5449                   (let ((input
5450                          (read-string
5451                           (format "%s %s (%d scored, %d total): "
5452                                   "How many articles from"
5453                                   (gnus-group-decoded-name group)
5454                                   scored number))))
5455                     (if (string-match "^[ \t]*$" input)
5456                         number input)))
5457                  (t number))
5458               (quit
5459                (message "Quit getting the articles to read")
5460                nil))))))
5461     (setq select (if (stringp select) (string-to-number select) select))
5462     (if (or (null select) (zerop select))
5463         select
5464       (if (and (not (zerop scored)) (<= (abs select) scored))
5465           (progn
5466             (setq articles (sort scored-list '<))
5467             (setq number (length articles)))
5468         (setq articles (copy-sequence articles)))
5469
5470       (when (< (abs select) number)
5471         (if (< select 0)
5472             ;; Select the N oldest articles.
5473             (setcdr (nthcdr (1- (abs select)) articles) nil)
5474           ;; Select the N most recent articles.
5475           (setq articles (nthcdr (- number select) articles))))
5476       (setq gnus-newsgroup-unselected
5477             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5478       (when gnus-alter-articles-to-read-function
5479         (setq articles
5480               (sort
5481                (funcall gnus-alter-articles-to-read-function
5482                         gnus-newsgroup-name articles)
5483                '<)))
5484       articles)))
5485
5486 (defun gnus-killed-articles (killed articles)
5487   (let (out)
5488     (while articles
5489       (when (inline (gnus-member-of-range (car articles) killed))
5490         (push (car articles) out))
5491       (setq articles (cdr articles)))
5492     out))
5493
5494 (defun gnus-uncompress-marks (marks)
5495   "Uncompress the mark ranges in MARKS."
5496   (let ((uncompressed '(score bookmark))
5497         out)
5498     (while marks
5499       (if (memq (caar marks) uncompressed)
5500           (push (car marks) out)
5501         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5502       (setq marks (cdr marks)))
5503     out))
5504
5505 (defun gnus-article-mark-to-type (mark)
5506   "Return the type of MARK."
5507   (or (cadr (assq mark gnus-article-special-mark-lists))
5508       'list))
5509
5510 (defun gnus-article-unpropagatable-p (mark)
5511   "Return whether MARK should be propagated to back end."
5512   (memq mark gnus-article-unpropagated-mark-lists))
5513
5514 (defun gnus-adjust-marked-articles (info)
5515   "Set all article lists and remove all marks that are no longer valid."
5516   (let* ((marked-lists (gnus-info-marks info))
5517          (active (gnus-active (gnus-info-group info)))
5518          (min (car active))
5519          (max (cdr active))
5520          (types gnus-article-mark-lists)
5521          marks var articles article mark mark-type
5522          bgn end)
5523
5524     (dolist (marks marked-lists)
5525       (setq mark (car marks)
5526             mark-type (gnus-article-mark-to-type mark)
5527             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5528
5529       ;; We set the variable according to the type of the marks list,
5530       ;; and then adjust the marks to a subset of the active articles.
5531       (cond
5532        ;; Adjust "simple" lists - compressed yet unsorted
5533        ((eq mark-type 'list)
5534         ;; Simultaneously uncompress and clip to active range
5535         ;; See gnus-uncompress-range for a description of possible marks
5536         (let (l lh)
5537           (if (not (cadr marks))
5538               (set var nil)
5539             (setq articles (if (numberp (cddr marks))
5540                                (list (cdr marks))
5541                              (cdr marks))
5542                   lh (cons nil nil)
5543                   l lh)
5544
5545             (while (setq article (pop articles))
5546               (cond ((consp article)
5547                      (setq bgn (max (car article) min)
5548                            end (min (cdr article) max))
5549                      (while (<= bgn end)
5550                        (setq l (setcdr l (cons bgn nil))
5551                              bgn (1+ bgn))))
5552                     ((and (<= min article)
5553                           (>= max article))
5554                      (setq l (setcdr l (cons article nil))))))
5555             (set var (cdr lh)))))
5556        ;; Adjust assocs.
5557        ((eq mark-type 'tuple)
5558         (set var (setq articles (cdr marks)))
5559         (when (not (listp (cdr (symbol-value var))))
5560           (set var (list (symbol-value var))))
5561         (when (not (listp (cdr articles)))
5562           (setq articles (list articles)))
5563         (while articles
5564           (when (or (not (consp (setq article (pop articles))))
5565                     (< (car article) min)
5566                     (> (car article) max))
5567             (set var (delq article (symbol-value var))))))
5568        ;; Adjust ranges (sloppily).
5569        ((eq mark-type 'range)
5570         (cond
5571          ((eq mark 'seen)
5572           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5573           ;; It should be (seen (NUM1 . NUM2)).
5574           (when (numberp (cddr marks))
5575             (setcdr marks (list (cdr marks))))
5576           (setq articles (cdr marks))
5577           (while (and articles
5578                       (or (and (consp (car articles))
5579                                (> min (cdar articles)))
5580                           (and (numberp (car articles))
5581                                (> min (car articles)))))
5582             (pop articles))
5583           (set var articles))))))))
5584
5585 (defun gnus-update-missing-marks (missing)
5586   "Go through the list of MISSING articles and remove them from the mark lists."
5587   (when missing
5588     (let (var m)
5589       ;; Go through all types.
5590       (dolist (elem gnus-article-mark-lists)
5591         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5592           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5593           (when (symbol-value var)
5594             ;; This list has articles.  So we delete all missing
5595             ;; articles from it.
5596             (setq m missing)
5597             (while m
5598               (set var (delq (pop m) (symbol-value var))))))))))
5599
5600 (defun gnus-update-marks ()
5601   "Enter the various lists of marked articles into the newsgroup info list."
5602   (let ((types gnus-article-mark-lists)
5603         (info (gnus-get-info gnus-newsgroup-name))
5604         type list newmarked symbol delta-marks)
5605     (when info
5606       ;; Add all marks lists to the list of marks lists.
5607       (while (setq type (pop types))
5608         (setq list (symbol-value
5609                     (setq symbol
5610                           (intern (format "gnus-newsgroup-%s" (car type))))))
5611
5612         (when list
5613           ;; Get rid of the entries of the articles that have the
5614           ;; default score.
5615           (when (and (eq (cdr type) 'score)
5616                      gnus-save-score
5617                      list)
5618             (let* ((arts list)
5619                    (prev (cons nil list))
5620                    (all prev))
5621               (while arts
5622                 (if (or (not (consp (car arts)))
5623                         (= (cdar arts) gnus-summary-default-score))
5624                     (setcdr prev (cdr arts))
5625                   (setq prev arts))
5626                 (setq arts (cdr arts)))
5627               (setq list (cdr all)))))
5628
5629         (when (eq (cdr type) 'seen)
5630           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5631
5632         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5633           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5634
5635         (when (and (gnus-check-backend-function
5636                     'request-set-mark gnus-newsgroup-name)
5637                    (not (gnus-article-unpropagatable-p (cdr type))))
5638           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5639                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5640                  (add (gnus-remove-from-range
5641                        (gnus-copy-sequence list) old)))
5642             (when add
5643               (push (list add 'add (list (cdr type))) delta-marks))
5644             (when del
5645               (push (list del 'del (list (cdr type))) delta-marks))))
5646
5647         (when list
5648           (push (cons (cdr type) list) newmarked)))
5649
5650       (when delta-marks
5651         (unless (gnus-check-group gnus-newsgroup-name)
5652           (error "Can't open server for %s" gnus-newsgroup-name))
5653         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5654
5655       ;; Enter these new marks into the info of the group.
5656       (if (nthcdr 3 info)
5657           (setcar (nthcdr 3 info) newmarked)
5658         ;; Add the marks lists to the end of the info.
5659         (when newmarked
5660           (setcdr (nthcdr 2 info) (list newmarked))))
5661
5662       ;; Cut off the end of the info if there's nothing else there.
5663       (let ((i 5))
5664         (while (and (> i 2)
5665                     (not (nth i info)))
5666           (when (nthcdr (decf i) info)
5667             (setcdr (nthcdr i info) nil)))))))
5668
5669 (defun gnus-set-mode-line (where)
5670   "Set the mode line of the article or summary buffers.
5671 If WHERE is `summary', the summary mode line format will be used."
5672   ;; Is this mode line one we keep updated?
5673   (when (and (memq where gnus-updated-mode-lines)
5674              (symbol-value
5675               (intern (format "gnus-%s-mode-line-format-spec" where))))
5676     (let (mode-string)
5677       (save-excursion
5678         ;; We evaluate this in the summary buffer since these
5679         ;; variables are buffer-local to that buffer.
5680         (set-buffer gnus-summary-buffer)
5681         ;; We bind all these variables that are used in the `eval' form
5682         ;; below.
5683         (let* ((mformat (symbol-value
5684                          (intern
5685                           (format "gnus-%s-mode-line-format-spec" where))))
5686                (gnus-tmp-group-name (gnus-group-decoded-name
5687                                      gnus-newsgroup-name))
5688                (gnus-tmp-article-number (or gnus-current-article 0))
5689                (gnus-tmp-unread gnus-newsgroup-unreads)
5690                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5691                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5692                (gnus-tmp-unread-and-unselected
5693                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5694                             (zerop gnus-tmp-unselected))
5695                        "")
5696                       ((zerop gnus-tmp-unselected)
5697                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5698                       (t (format "{%d(+%d) more}"
5699                                  gnus-tmp-unread-and-unticked
5700                                  gnus-tmp-unselected))))
5701                (gnus-tmp-subject
5702                 (if (and gnus-current-headers
5703                          (vectorp gnus-current-headers))
5704                     (gnus-mode-string-quote
5705                      (mail-header-subject gnus-current-headers))
5706                   ""))
5707                bufname-length max-len
5708                gnus-tmp-header);; passed as argument to any user-format-funcs
5709           (setq mode-string (eval mformat))
5710           (setq bufname-length (if (string-match "%b" mode-string)
5711                                    (- (length
5712                                        (buffer-name
5713                                         (if (eq where 'summary)
5714                                             nil
5715                                           (get-buffer gnus-article-buffer))))
5716                                       2)
5717                                  0))
5718           (setq max-len (max 4 (if gnus-mode-non-string-length
5719                                    (- (window-width)
5720                                       gnus-mode-non-string-length
5721                                       bufname-length)
5722                                  (length mode-string))))
5723           ;; We might have to chop a bit of the string off...
5724           (when (> (length mode-string) max-len)
5725             (setq mode-string
5726                   (concat (gnus-truncate-string mode-string (- max-len 3))
5727                           "...")))
5728           ;; Pad the mode string a bit.
5729           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5730       ;; Update the mode line.
5731       (setq mode-line-buffer-identification
5732             (gnus-mode-line-buffer-identification (list mode-string)))
5733       (set-buffer-modified-p t))))
5734
5735 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5736   "Go through the HEADERS list and add all Xrefs to a hash table.
5737 The resulting hash table is returned, or nil if no Xrefs were found."
5738   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5739          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5740          (xref-hashtb (gnus-make-hashtable))
5741          start group entry number xrefs header)
5742     (while headers
5743       (setq header (pop headers))
5744       (when (and (setq xrefs (mail-header-xref header))
5745                  (not (memq (setq number (mail-header-number header))
5746                             unreads)))
5747         (setq start 0)
5748         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5749           (setq start (match-end 0))
5750           (setq group (if prefix
5751                           (concat prefix (substring xrefs (match-beginning 1)
5752                                                     (match-end 1)))
5753                         (substring xrefs (match-beginning 1) (match-end 1))))
5754           (setq number
5755                 (string-to-number (substring xrefs (match-beginning 2)
5756                                           (match-end 2))))
5757           (if (setq entry (gnus-gethash group xref-hashtb))
5758               (setcdr entry (cons number (cdr entry)))
5759             (gnus-sethash group (cons number nil) xref-hashtb)))))
5760     (and start xref-hashtb)))
5761
5762 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5763   "Look through all the headers and mark the Xrefs as read."
5764   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5765         name info xref-hashtb idlist method nth4)
5766     (save-excursion
5767       (set-buffer gnus-group-buffer)
5768       (when (setq xref-hashtb
5769                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5770         (mapatoms
5771          (lambda (group)
5772            (unless (string= from-newsgroup (setq name (symbol-name group)))
5773              (setq idlist (symbol-value group))
5774              ;; Dead groups are not updated.
5775              (and (prog1
5776                       (setq info (gnus-get-info name))
5777                     (when (stringp (setq nth4 (gnus-info-method info)))
5778                       (setq nth4 (gnus-server-to-method nth4))))
5779                   ;; Only do the xrefs if the group has the same
5780                   ;; select method as the group we have just read.
5781                   (or (gnus-methods-equal-p
5782                        nth4 (gnus-find-method-for-group from-newsgroup))
5783                       virtual
5784                       (equal nth4 (setq method (gnus-find-method-for-group
5785                                                 from-newsgroup)))
5786                       (and (equal (car nth4) (car method))
5787                            (equal (nth 1 nth4) (nth 1 method))))
5788                   gnus-use-cross-reference
5789                   (or (not (eq gnus-use-cross-reference t))
5790                       virtual
5791                       ;; Only do cross-references on subscribed
5792                       ;; groups, if that is what is wanted.
5793                       (<= (gnus-info-level info) gnus-level-subscribed))
5794                   (gnus-group-make-articles-read name idlist))))
5795          xref-hashtb)))))
5796
5797 (defun gnus-compute-read-articles (group articles)
5798   (let* ((entry (gnus-group-entry group))
5799          (info (nth 2 entry))
5800          (active (gnus-active group))
5801          ninfo)
5802     (when entry
5803       ;; First peel off all invalid article numbers.
5804       (when active
5805         (let ((ids articles)
5806               id first)
5807           (while (setq id (pop ids))
5808             (when (and first (> id (cdr active)))
5809               ;; We'll end up in this situation in one particular
5810               ;; obscure situation.  If you re-scan a group and get
5811               ;; a new article that is cross-posted to a different
5812               ;; group that has not been re-scanned, you might get
5813               ;; crossposted article that has a higher number than
5814               ;; Gnus believes possible.  So we re-activate this
5815               ;; group as well.  This might mean doing the
5816               ;; crossposting thingy will *increase* the number
5817               ;; of articles in some groups.  Tsk, tsk.
5818               (setq active (or (gnus-activate-group group) active)))
5819             (when (or (> id (cdr active))
5820                       (< id (car active)))
5821               (setq articles (delq id articles))))))
5822       ;; If the read list is nil, we init it.
5823       (if (and active
5824                (null (gnus-info-read info))
5825                (> (car active) 1))
5826           (setq ninfo (cons 1 (1- (car active))))
5827         (setq ninfo (gnus-info-read info)))
5828       ;; Then we add the read articles to the range.
5829       (gnus-add-to-range
5830        ninfo (setq articles (sort articles '<))))))
5831
5832 (defun gnus-group-make-articles-read (group articles)
5833   "Update the info of GROUP to say that ARTICLES are read."
5834   (let* ((num 0)
5835          (entry (gnus-group-entry group))
5836          (info (nth 2 entry))
5837          (active (gnus-active group))
5838          range)
5839     (when entry
5840       (setq range (gnus-compute-read-articles group articles))
5841       (with-current-buffer gnus-group-buffer
5842         (gnus-undo-register
5843           `(progn
5844              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5845              (gnus-info-set-read ',info ',(gnus-info-read info))
5846              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5847              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5848              (gnus-group-update-group ,group t))))
5849       ;; Add the read articles to the range.
5850       (gnus-info-set-read info range)
5851       (gnus-request-set-mark group (list (list range 'add '(read))))
5852       ;; Then we have to re-compute how many unread
5853       ;; articles there are in this group.
5854       (when active
5855         (cond
5856          ((not range)
5857           (setq num (- (1+ (cdr active)) (car active))))
5858          ((not (listp (cdr range)))
5859           (setq num (- (cdr active) (- (1+ (cdr range))
5860                                        (car range)))))
5861          (t
5862           (while range
5863             (if (numberp (car range))
5864                 (setq num (1+ num))
5865               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5866             (setq range (cdr range)))
5867           (setq num (- (cdr active) num))))
5868         ;; Update the number of unread articles.
5869         (setcar entry num)
5870         ;; Update the group buffer.
5871         (unless (gnus-ephemeral-group-p group)
5872           (gnus-group-update-group group t))))))
5873
5874 (defvar gnus-newsgroup-none-id 0)
5875
5876 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5877   (let ((cur nntp-server-buffer)
5878         (dependencies
5879          (or dependencies
5880              (with-current-buffer gnus-summary-buffer
5881                gnus-newsgroup-dependencies)))
5882         headers id end ref number
5883         (mail-parse-charset gnus-newsgroup-charset)
5884         (mail-parse-ignored-charsets
5885          (save-excursion (condition-case nil
5886                              (set-buffer gnus-summary-buffer)
5887                            (error))
5888                          gnus-newsgroup-ignored-charsets)))
5889     (save-excursion
5890       (set-buffer nntp-server-buffer)
5891       ;; Translate all TAB characters into SPACE characters.
5892       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5893       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5894       (ietf-drums-unfold-fws)
5895       (gnus-run-hooks 'gnus-parse-headers-hook)
5896       (let ((case-fold-search t)
5897             in-reply-to header p lines chars ctype)
5898         (goto-char (point-min))
5899         ;; Search to the beginning of the next header.  Error messages
5900         ;; do not begin with 2 or 3.
5901         (while (re-search-forward "^[23][0-9]+ " nil t)
5902           (setq id nil
5903                 ref nil)
5904           ;; This implementation of this function, with nine
5905           ;; search-forwards instead of the one re-search-forward and
5906           ;; a case (which basically was the old function) is actually
5907           ;; about twice as fast, even though it looks messier.  You
5908           ;; can't have everything, I guess.  Speed and elegance
5909           ;; doesn't always go hand in hand.
5910           (setq
5911            header
5912            (make-full-mail-header
5913             ;; Number.
5914             (prog1
5915                 (setq number (read cur))
5916               (end-of-line)
5917               (setq p (point))
5918               (narrow-to-region (point)
5919                                 (or (and (search-forward "\n.\n" nil t)
5920                                          (- (point) 2))
5921                                     (point))))
5922             ;; Subject.
5923             (progn
5924               (goto-char p)
5925               (if (search-forward "\nsubject:" nil t)
5926                   (nnheader-header-value)
5927                 "(none)"))
5928             ;; From.
5929             (progn
5930               (goto-char p)
5931               (if (search-forward "\nfrom:" nil t)
5932                   (nnheader-header-value)
5933                 "(nobody)"))
5934             ;; Date.
5935             (progn
5936               (goto-char p)
5937               (if (search-forward "\ndate:" nil t)
5938                   (nnheader-header-value) ""))
5939             ;; Message-ID.
5940             (progn
5941               (goto-char p)
5942               (setq id (if (re-search-forward
5943                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5944                            ;; We do it this way to make sure the Message-ID
5945                            ;; is (somewhat) syntactically valid.
5946                            (buffer-substring (match-beginning 1)
5947                                              (match-end 1))
5948                          ;; If there was no message-id, we just fake one
5949                          ;; to make subsequent routines simpler.
5950                          (nnheader-generate-fake-message-id number))))
5951             ;; References.
5952             (progn
5953               (goto-char p)
5954               (if (search-forward "\nreferences:" nil t)
5955                   (progn
5956                     (setq end (point))
5957                     (prog1
5958                         (nnheader-header-value)
5959                       (setq ref
5960                             (buffer-substring
5961                              (progn
5962                                ;; (end-of-line)
5963                                (search-backward ">" end t)
5964                                (1+ (point)))
5965                              (progn
5966                                (search-backward "<" end t)
5967                                (point))))))
5968                 ;; Get the references from the in-reply-to header if there
5969                 ;; were no references and the in-reply-to header looks
5970                 ;; promising.
5971                 (if (and (search-forward "\nin-reply-to:" nil t)
5972                          (setq in-reply-to (nnheader-header-value))
5973                          (string-match "<[^>]+>" in-reply-to))
5974                     (let (ref2)
5975                       (setq ref (substring in-reply-to (match-beginning 0)
5976                                            (match-end 0)))
5977                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5978                         (setq ref2 (substring in-reply-to (match-beginning 0)
5979                                               (match-end 0)))
5980                         (when (> (length ref2) (length ref))
5981                           (setq ref ref2)))
5982                       ref)
5983                   (setq ref nil))))
5984             ;; Chars.
5985             (progn
5986               (goto-char p)
5987               (if (search-forward "\nchars: " nil t)
5988                   (if (numberp (setq chars (ignore-errors (read cur))))
5989                       chars -1)
5990                 -1))
5991             ;; Lines.
5992             (progn
5993               (goto-char p)
5994               (if (search-forward "\nlines: " nil t)
5995                   (if (numberp (setq lines (ignore-errors (read cur))))
5996                       lines -1)
5997                 -1))
5998             ;; Xref.
5999             (progn
6000               (goto-char p)
6001               (and (search-forward "\nxref:" nil t)
6002                    (nnheader-header-value)))
6003             ;; Extra.
6004             (when gnus-extra-headers
6005               (let ((extra gnus-extra-headers)
6006                     out)
6007                 (while extra
6008                   (goto-char p)
6009                   (when (search-forward
6010                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6011                     (push (cons (car extra) (nnheader-header-value)) out))
6012                   (pop extra))
6013                 out))))
6014           (goto-char p)
6015           (if (and (search-forward "\ncontent-type: " nil t)
6016                    (setq ctype (nnheader-header-value)))
6017               (mime-entity-set-content-type-internal
6018                header (mime-parse-Content-Type ctype)))
6019           (when (equal id ref)
6020             (setq ref nil))
6021
6022           (when gnus-alter-header-function
6023             (funcall gnus-alter-header-function header)
6024             (setq id (mail-header-id header)
6025                   ref (gnus-parent-id (mail-header-references header))))
6026
6027           (when (setq header
6028                       (gnus-dependencies-add-header
6029                        header dependencies force-new))
6030             (push header headers))
6031           (goto-char (point-max))
6032           (widen))
6033         (nreverse headers)))))
6034
6035 ;; Goes through the xover lines and returns a list of vectors
6036 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6037                                                   force-new dependencies
6038                                                   group also-fetch-heads)
6039   "Parse the news overview data in the server buffer.
6040 Return a list of headers that match SEQUENCE (see
6041 `nntp-retrieve-headers')."
6042   ;; Get the Xref when the users reads the articles since most/some
6043   ;; NNTP servers do not include Xrefs when using XOVER.
6044   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6045   (let ((mail-parse-charset gnus-newsgroup-charset)
6046         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6047         (cur nntp-server-buffer)
6048         (dependencies (or dependencies gnus-newsgroup-dependencies))
6049         (allp (cond
6050                ((eq gnus-read-all-available-headers t)
6051                 t)
6052                ((stringp gnus-read-all-available-headers)
6053                 (string-match gnus-read-all-available-headers group))
6054                (t
6055                 nil)))
6056         number headers header)
6057     (save-excursion
6058       (set-buffer nntp-server-buffer)
6059       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6060       ;; Allow the user to mangle the headers before parsing them.
6061       (gnus-run-hooks 'gnus-parse-headers-hook)
6062       (goto-char (point-min))
6063       (gnus-parse-without-error
6064         (while (and (or sequence allp)
6065                     (not (eobp)))
6066           (setq number (read cur))
6067           (when (not allp)
6068             (while (and sequence
6069                         (< (car sequence) number))
6070               (setq sequence (cdr sequence))))
6071           (when (and (or allp
6072                          (and sequence
6073                               (eq number (car sequence))))
6074                      (progn
6075                        (setq sequence (cdr sequence))
6076                        (setq header (inline
6077                                       (gnus-nov-parse-line
6078                                        number dependencies force-new)))))
6079             (push header headers))
6080           (forward-line 1)))
6081       ;; A common bug in inn is that if you have posted an article and
6082       ;; then retrieves the active file, it will answer correctly --
6083       ;; the new article is included.  However, a NOV entry for the
6084       ;; article may not have been generated yet, so this may fail.
6085       ;; We work around this problem by retrieving the last few
6086       ;; headers using HEAD.
6087       (if (or (not also-fetch-heads)
6088               (not sequence))
6089           ;; We (probably) got all the headers.
6090           (nreverse headers)
6091         (let ((gnus-nov-is-evil t))
6092           (nconc
6093            (nreverse headers)
6094            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6095              (gnus-get-newsgroup-headers))))))))
6096
6097 (defun gnus-article-get-xrefs ()
6098   "Fill in the Xref value in `gnus-current-headers', if necessary.
6099 This is meant to be called in `gnus-article-internal-prepare-hook'."
6100   (let ((headers (with-current-buffer gnus-summary-buffer
6101                    gnus-current-headers)))
6102     (or (not gnus-use-cross-reference)
6103         (not headers)
6104         (and (mail-header-xref headers)
6105              (not (string= (mail-header-xref headers) "")))
6106         (let ((case-fold-search t)
6107               xref)
6108           (save-restriction
6109             (nnheader-narrow-to-headers)
6110             (goto-char (point-min))
6111             (when (or (and (not (eobp))
6112                            (eq (downcase (char-after)) ?x)
6113                            (looking-at "Xref:"))
6114                       (search-forward "\nXref:" nil t))
6115               (goto-char (1+ (match-end 0)))
6116               (setq xref (buffer-substring (point) (point-at-eol)))
6117               (mail-header-set-xref headers xref)))))))
6118
6119 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6120   "Find article ID and insert the summary line for that article.
6121 OLD-HEADER can either be a header or a line number to insert
6122 the subject line on."
6123   (let* ((line (and (numberp old-header) old-header))
6124          (old-header (and (vectorp old-header) old-header))
6125          (header (cond ((and old-header use-old-header)
6126                         old-header)
6127                        ((and (numberp id)
6128                              (gnus-number-to-header id))
6129                         (gnus-number-to-header id))
6130                        (t
6131                         (gnus-read-header id))))
6132          (number (and (numberp id) id))
6133          d)
6134     (when header
6135       ;; Rebuild the thread that this article is part of and go to the
6136       ;; article we have fetched.
6137       (when (and (not gnus-show-threads)
6138                  old-header)
6139         (when (and number
6140                    (setq d (gnus-data-find (mail-header-number old-header))))
6141           (goto-char (gnus-data-pos d))
6142           (gnus-data-remove
6143            number
6144            (- (point-at-bol)
6145               (prog1
6146                   (1+ (point-at-eol))
6147                 (gnus-delete-line))))))
6148       ;; Remove list identifiers from subject.
6149       (when gnus-list-identifiers
6150         (let ((gnus-newsgroup-headers (list header)))
6151           (gnus-summary-remove-list-identifiers)))
6152       (when old-header
6153         (mail-header-set-number header (mail-header-number old-header)))
6154       (setq gnus-newsgroup-sparse
6155             (delq (setq number (mail-header-number header))
6156                   gnus-newsgroup-sparse))
6157       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6158       (push number gnus-newsgroup-limit)
6159       (gnus-rebuild-thread (mail-header-id header) line)
6160       (gnus-summary-goto-subject number nil t))
6161     (when (and (numberp number)
6162                (> number 0))
6163       ;; We have to update the boundaries even if we can't fetch the
6164       ;; article if ID is a number -- so that the next `P' or `N'
6165       ;; command will fetch the previous (or next) article even
6166       ;; if the one we tried to fetch this time has been canceled.
6167       (when (> number gnus-newsgroup-end)
6168         (setq gnus-newsgroup-end number))
6169       (when (< number gnus-newsgroup-begin)
6170         (setq gnus-newsgroup-begin number))
6171       (setq gnus-newsgroup-unselected
6172             (delq number gnus-newsgroup-unselected)))
6173     ;; Report back a success?
6174     (and header (mail-header-number header))))
6175
6176 ;;; Process/prefix in the summary buffer
6177
6178 (defun gnus-summary-work-articles (n)
6179   "Return a list of articles to be worked upon.
6180 The prefix argument, the list of process marked articles, and the
6181 current article will be taken into consideration."
6182   (save-excursion
6183     (set-buffer gnus-summary-buffer)
6184     (cond
6185      (n
6186       ;; A numerical prefix has been given.
6187       (setq n (prefix-numeric-value n))
6188       (let ((backward (< n 0))
6189             (n (abs (prefix-numeric-value n)))
6190             articles article)
6191         (save-excursion
6192           (while
6193               (and (> n 0)
6194                    (push (setq article (gnus-summary-article-number))
6195                          articles)
6196                    (if backward
6197                        (gnus-summary-find-prev nil article)
6198                      (gnus-summary-find-next nil article)))
6199             (decf n)))
6200         (nreverse articles)))
6201      ((and (gnus-region-active-p) (mark))
6202       (message "region active")
6203       ;; Work on the region between point and mark.
6204       (let ((max (max (point) (mark)))
6205             articles article)
6206         (save-excursion
6207           (goto-char (min (point) (mark)))
6208           (while
6209               (and
6210                (push (setq article (gnus-summary-article-number)) articles)
6211                (gnus-summary-find-next nil article)
6212                (< (point) max)))
6213           (nreverse articles))))
6214      (gnus-newsgroup-processable
6215       ;; There are process-marked articles present.
6216       ;; Save current state.
6217       (gnus-summary-save-process-mark)
6218       ;; Return the list.
6219       (reverse gnus-newsgroup-processable))
6220      (t
6221       ;; Just return the current article.
6222       (list (gnus-summary-article-number))))))
6223
6224 (defmacro gnus-summary-iterate (arg &rest forms)
6225   "Iterate over the process/prefixed articles and do FORMS.
6226 ARG is the interactive prefix given to the command.  FORMS will be
6227 executed with point over the summary line of the articles."
6228   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6229     `(let ((,articles (gnus-summary-work-articles ,arg)))
6230        (while ,articles
6231          (gnus-summary-goto-subject (car ,articles))
6232          ,@forms
6233          (pop ,articles)))))
6234
6235 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6236 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6237
6238 (defun gnus-summary-save-process-mark ()
6239   "Push the current set of process marked articles on the stack."
6240   (interactive)
6241   (push (copy-sequence gnus-newsgroup-processable)
6242         gnus-newsgroup-process-stack))
6243
6244 (defun gnus-summary-kill-process-mark ()
6245   "Push the current set of process marked articles on the stack and unmark."
6246   (interactive)
6247   (gnus-summary-save-process-mark)
6248   (gnus-summary-unmark-all-processable))
6249
6250 (defun gnus-summary-yank-process-mark ()
6251   "Pop the last process mark state off the stack and restore it."
6252   (interactive)
6253   (unless gnus-newsgroup-process-stack
6254     (error "Empty mark stack"))
6255   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6256
6257 (defun gnus-summary-process-mark-set (set)
6258   "Make SET into the current process marked articles."
6259   (gnus-summary-unmark-all-processable)
6260   (mapc 'gnus-summary-set-process-mark set))
6261
6262 ;;; Searching and stuff
6263
6264 (defun gnus-summary-search-group (&optional backward use-level)
6265   "Search for next unread newsgroup.
6266 If optional argument BACKWARD is non-nil, search backward instead."
6267   (save-excursion
6268     (set-buffer gnus-group-buffer)
6269     (when (gnus-group-search-forward
6270            backward nil (if use-level (gnus-group-group-level) nil))
6271       (gnus-group-group-name))))
6272
6273 (defun gnus-summary-best-group (&optional exclude-group)
6274   "Find the name of the best unread group.
6275 If EXCLUDE-GROUP, do not go to this group."
6276   (with-current-buffer gnus-group-buffer
6277     (save-excursion
6278       (gnus-group-best-unread-group exclude-group))))
6279
6280 (defun gnus-summary-find-next (&optional unread article backward)
6281   (if backward
6282       (gnus-summary-find-prev unread article)
6283     (let* ((dummy (gnus-summary-article-intangible-p))
6284            (article (or article (gnus-summary-article-number)))
6285            (data (gnus-data-find-list article))
6286            result)
6287       (when (and (not dummy)
6288                  (or (not gnus-summary-check-current)
6289                      (not unread)
6290                      (not (gnus-data-unread-p (car data)))))
6291         (setq data (cdr data)))
6292       (when (setq result
6293                   (if unread
6294                       (progn
6295                         (while data
6296                           (unless (memq (gnus-data-number (car data))
6297                                         (cond
6298                                          ((eq gnus-auto-goto-ignores
6299                                               'always-undownloaded)
6300                                           gnus-newsgroup-undownloaded)
6301                                          (gnus-plugged
6302                                           nil)
6303                                          ((eq gnus-auto-goto-ignores
6304                                               'unfetched)
6305                                           gnus-newsgroup-unfetched)
6306                                          ((eq gnus-auto-goto-ignores
6307                                               'undownloaded)
6308                                           gnus-newsgroup-undownloaded)))
6309                             (when (gnus-data-unread-p (car data))
6310                               (setq result (car data)
6311                                     data nil)))
6312                           (setq data (cdr data)))
6313                         result)
6314                     (car data)))
6315         (goto-char (gnus-data-pos result))
6316         (gnus-data-number result)))))
6317
6318 (defun gnus-summary-find-prev (&optional unread article)
6319   (let* ((eobp (eobp))
6320          (article (or article (gnus-summary-article-number)))
6321          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6322          result)
6323     (when (and (not eobp)
6324                (or (not gnus-summary-check-current)
6325                    (not unread)
6326                    (not (gnus-data-unread-p (car data)))))
6327       (setq data (cdr data)))
6328     (when (setq result
6329                 (if unread
6330                     (progn
6331                       (while data
6332                         (unless (memq (gnus-data-number (car data))
6333                                       (cond
6334                                        ((eq gnus-auto-goto-ignores
6335                                             'always-undownloaded)
6336                                         gnus-newsgroup-undownloaded)
6337                                        (gnus-plugged
6338                                         nil)
6339                                        ((eq gnus-auto-goto-ignores
6340                                             'unfetched)
6341                                         gnus-newsgroup-unfetched)
6342                                        ((eq gnus-auto-goto-ignores
6343                                             'undownloaded)
6344                                         gnus-newsgroup-undownloaded)))
6345                           (when (gnus-data-unread-p (car data))
6346                             (setq result (car data)
6347                                   data nil)))
6348                         (setq data (cdr data)))
6349                       result)
6350                   (car data)))
6351       (goto-char (gnus-data-pos result))
6352       (gnus-data-number result))))
6353
6354 (defun gnus-summary-find-subject (subject &optional unread backward article)
6355   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6356          (article (or article (gnus-summary-article-number)))
6357          (articles (gnus-data-list backward))
6358          (arts (gnus-data-find-list article articles))
6359          result)
6360     (when (or (not gnus-summary-check-current)
6361               (not unread)
6362               (not (gnus-data-unread-p (car arts))))
6363       (setq arts (cdr arts)))
6364     (while arts
6365       (and (or (not unread)
6366                (gnus-data-unread-p (car arts)))
6367            (vectorp (gnus-data-header (car arts)))
6368            (gnus-subject-equal
6369             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6370            (setq result (car arts)
6371                  arts nil))
6372       (setq arts (cdr arts)))
6373     (and result
6374          (goto-char (gnus-data-pos result))
6375          (gnus-data-number result))))
6376
6377 (defun gnus-summary-search-forward (&optional unread subject backward)
6378   "Search forward for an article.
6379 If UNREAD, look for unread articles.  If SUBJECT, look for
6380 articles with that subject.  If BACKWARD, search backward instead."
6381   (cond (subject (gnus-summary-find-subject subject unread backward))
6382         (backward (gnus-summary-find-prev unread))
6383         (t (gnus-summary-find-next unread))))
6384
6385 (defun gnus-recenter (&optional n)
6386   "Center point in window and redisplay frame.
6387 Also do horizontal recentering."
6388   (interactive "P")
6389   (when (and gnus-auto-center-summary
6390              (not (eq gnus-auto-center-summary 'vertical)))
6391     (gnus-horizontal-recenter))
6392   (recenter n))
6393
6394 (defun gnus-summary-recenter ()
6395   "Center point in the summary window.
6396 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6397 displayed, no centering will be performed."
6398   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6399   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6400   (interactive)
6401   ;; The user has to want it.
6402   (when gnus-auto-center-summary
6403     (let* ((top (cond ((< (window-height) 4) 0)
6404                       ((< (window-height) 7) 1)
6405                       (t (if (numberp gnus-auto-center-summary)
6406                              gnus-auto-center-summary
6407                            (/ (1- (window-height)) 2)))))
6408            (height (1- (window-height)))
6409            (bottom (save-excursion (goto-char (point-max))
6410                                    (forward-line (- height))
6411                                    (point)))
6412            (window (get-buffer-window (current-buffer))))
6413       (when (get-buffer-window gnus-article-buffer)
6414         ;; Only do recentering when the article buffer is displayed,
6415         ;; Set the window start to either `bottom', which is the biggest
6416         ;; possible valid number, or the second line from the top,
6417         ;; whichever is the least.
6418         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6419           (if (> bottom top-pos)
6420               ;; Keep the second line from the top visible
6421               (set-window-start window top-pos t)
6422             ;; Try to keep the bottom line visible; if it's partially
6423             ;; obscured, either scroll one more line to make it fully
6424             ;; visible, or revert to using TOP-POS.
6425             (save-excursion
6426               (goto-char (point-max))
6427               (forward-line -1)
6428               (let ((last-line-start (point)))
6429                 (goto-char bottom)
6430                 (set-window-start window (point) t)
6431                 (when (not (pos-visible-in-window-p last-line-start window))
6432                   (forward-line 1)
6433                   (set-window-start window (min (point) top-pos) t)))))))
6434       ;; Do horizontal recentering while we're at it.
6435       (when (and (get-buffer-window (current-buffer) t)
6436                  (not (eq gnus-auto-center-summary 'vertical)))
6437         (let ((selected (selected-window)))
6438           (select-window (get-buffer-window (current-buffer) t))
6439           (gnus-summary-position-point)
6440           (gnus-horizontal-recenter)
6441           (select-window selected))))))
6442
6443 (defun gnus-summary-jump-to-group (newsgroup)
6444   "Move point to NEWSGROUP in group mode buffer."
6445   ;; Keep update point of group mode buffer if visible.
6446   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6447       (save-window-excursion
6448         ;; Take care of tree window mode.
6449         (when (get-buffer-window gnus-group-buffer)
6450           (pop-to-buffer gnus-group-buffer))
6451         (gnus-group-jump-to-group newsgroup))
6452     (save-excursion
6453       ;; Take care of tree window mode.
6454       (if (get-buffer-window gnus-group-buffer)
6455           (pop-to-buffer gnus-group-buffer)
6456         (set-buffer gnus-group-buffer))
6457       (gnus-group-jump-to-group newsgroup))))
6458
6459 ;; This function returns a list of article numbers based on the
6460 ;; difference between the ranges of read articles in this group and
6461 ;; the range of active articles.
6462 (defun gnus-list-of-unread-articles (group)
6463   (let* ((read (gnus-info-read (gnus-get-info group)))
6464          (active (or (gnus-active group) (gnus-activate-group group)))
6465          (last (or (cdr active)
6466                    (error "Group %s couldn't be activated " group)))
6467          first nlast unread)
6468     ;; If none are read, then all are unread.
6469     (if (not read)
6470         (setq first (car active))
6471       ;; If the range of read articles is a single range, then the
6472       ;; first unread article is the article after the last read
6473       ;; article.  Sounds logical, doesn't it?
6474       (if (and (not (listp (cdr read)))
6475                (or (< (car read) (car active))
6476                    (progn (setq read (list read))
6477                           nil)))
6478           (setq first (max (car active) (1+ (cdr read))))
6479         ;; `read' is a list of ranges.
6480         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6481                                   (caar read)))
6482                   1)
6483           (setq first (car active)))
6484         (while read
6485           (when first
6486             (while (< first nlast)
6487               (setq unread (cons first unread)
6488                     first (1+ first))))
6489           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6490           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6491           (setq read (cdr read)))))
6492     ;; And add the last unread articles.
6493     (while (<= first last)
6494       (setq unread (cons first unread)
6495             first (1+ first)))
6496     ;; Return the list of unread articles.
6497     (delq 0 (nreverse unread))))
6498
6499 (defun gnus-list-of-read-articles (group)
6500   "Return a list of unread, unticked and non-dormant articles."
6501   (let* ((info (gnus-get-info group))
6502          (marked (gnus-info-marks info))
6503          (active (gnus-active group)))
6504     (and info active
6505          (gnus-list-range-difference
6506           (gnus-list-range-difference
6507            (gnus-sorted-complement
6508             (gnus-uncompress-range active)
6509             (gnus-list-of-unread-articles group))
6510            (cdr (assq 'dormant marked)))
6511           (cdr (assq 'tick marked))))))
6512
6513 ;; This function returns a sequence of article numbers based on the
6514 ;; difference between the ranges of read articles in this group and
6515 ;; the range of active articles.
6516 (defun gnus-sequence-of-unread-articles (group)
6517   (let* ((read (gnus-info-read (gnus-get-info group)))
6518          (active (or (gnus-active group) (gnus-activate-group group)))
6519          (last (cdr active))
6520          first nlast unread)
6521     ;; If none are read, then all are unread.
6522     (if (not read)
6523         (setq first (car active))
6524       ;; If the range of read articles is a single range, then the
6525       ;; first unread article is the article after the last read
6526       ;; article.  Sounds logical, doesn't it?
6527       (if (and (not (listp (cdr read)))
6528                (or (< (car read) (car active))
6529                    (progn (setq read (list read))
6530                           nil)))
6531           (setq first (max (car active) (1+ (cdr read))))
6532         ;; `read' is a list of ranges.
6533         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6534                                   (caar read)))
6535                   1)
6536           (setq first (car active)))
6537         (while read
6538           (when first
6539             (push (cons first nlast) unread))
6540           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6541           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6542           (setq read (cdr read)))))
6543     ;; And add the last unread articles.
6544     (cond ((< first last)
6545            (push (cons first last) unread))
6546           ((= first last)
6547            (push first unread)))
6548     ;; Return the sequence of unread articles.
6549     (delq 0 (nreverse unread))))
6550
6551 ;; Various summary commands
6552
6553 (defun gnus-summary-select-article-buffer ()
6554   "Reconfigure windows to show article buffer."
6555   (interactive)
6556   (if (not (gnus-buffer-live-p gnus-article-buffer))
6557       (error "There is no article buffer for this summary buffer")
6558     (gnus-configure-windows 'article)
6559     (select-window (get-buffer-window gnus-article-buffer))))
6560
6561 (defun gnus-summary-universal-argument (arg)
6562   "Perform any operation on all articles that are process/prefixed."
6563   (interactive "P")
6564   (let ((articles (gnus-summary-work-articles arg))
6565         func article)
6566     (if (eq
6567          (setq
6568           func
6569           (key-binding
6570            (read-key-sequence
6571             (substitute-command-keys
6572              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6573          'undefined)
6574         (gnus-error 1 "Undefined key")
6575       (save-excursion
6576         (while articles
6577           (gnus-summary-goto-subject (setq article (pop articles)))
6578           (let (gnus-newsgroup-processable)
6579             (command-execute func))
6580           (gnus-summary-remove-process-mark article)))))
6581   (gnus-summary-position-point))
6582
6583 (defun gnus-summary-toggle-truncation (&optional arg)
6584   "Toggle truncation of summary lines.
6585 With ARG, turn line truncation on if ARG is positive."
6586   (interactive "P")
6587   (setq truncate-lines
6588         (if (null arg) (not truncate-lines)
6589           (> (prefix-numeric-value arg) 0)))
6590   (redraw-display))
6591
6592 (defun gnus-summary-find-for-reselect ()
6593   "Return the number of an article to stay on across a reselect.
6594 The current article is considered, then following articles, then previous
6595 articles.  An article is sought which is not cancelled and isn't a temporary
6596 insertion from another group.  If there's no such then return a dummy 0."
6597   (let (found)
6598     (dolist (rev '(nil t))
6599       (unless found      ; don't demand the reverse list if we don't need it
6600         (let ((data (gnus-data-find-list
6601                      (gnus-summary-article-number) (gnus-data-list rev))))
6602           (while (and data (not found))
6603             (if (and (< 0 (gnus-data-number (car data)))
6604                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6605                 (setq found (gnus-data-number (car data))))
6606             (setq data (cdr data))))))
6607     (or found 0)))
6608
6609 (defun gnus-summary-reselect-current-group (&optional all rescan)
6610   "Exit and then reselect the current newsgroup.
6611 The prefix argument ALL means to select all articles."
6612   (interactive "P")
6613   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6614     (error "Ephemeral groups can't be reselected"))
6615   (let ((current-subject (gnus-summary-find-for-reselect))
6616         (group gnus-newsgroup-name))
6617     (setq gnus-newsgroup-begin nil)
6618     (gnus-summary-exit nil 'leave-hidden)
6619     ;; We have to adjust the point of group mode buffer because
6620     ;; point was moved to the next unread newsgroup by exiting.
6621     (gnus-summary-jump-to-group group)
6622     (when rescan
6623       (save-excursion
6624         (save-window-excursion
6625           ;; Don't show group contents.
6626           (set-window-start (selected-window) (point-max))
6627           (gnus-group-get-new-news-this-group 1))))
6628     (gnus-group-read-group all t)
6629     (gnus-summary-goto-subject current-subject nil t)))
6630
6631 (defun gnus-summary-rescan-group (&optional all)
6632   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6633   (interactive "P")
6634   (gnus-summary-reselect-current-group all t))
6635
6636 (defun gnus-summary-update-info (&optional non-destructive)
6637   (save-excursion
6638     (let ((group gnus-newsgroup-name))
6639       (when group
6640         (when gnus-newsgroup-kill-headers
6641           (setq gnus-newsgroup-killed
6642                 (gnus-compress-sequence
6643                  (gnus-sorted-union
6644                   (gnus-list-range-intersection
6645                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6646                   gnus-newsgroup-unreads)
6647                  t)))
6648         (unless (listp (cdr gnus-newsgroup-killed))
6649           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6650         (let ((headers gnus-newsgroup-headers))
6651           ;; Set the new ranges of read articles.
6652           (with-current-buffer gnus-group-buffer
6653             (gnus-undo-force-boundary))
6654           (gnus-update-read-articles
6655            group (gnus-sorted-union
6656                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6657           ;; Set the current article marks.
6658           (let ((gnus-newsgroup-scored
6659                  (if (and (not gnus-save-score)
6660                           (not non-destructive))
6661                      nil
6662                    gnus-newsgroup-scored)))
6663             (save-excursion
6664               (gnus-update-marks)))
6665           ;; Do the cross-ref thing.
6666           (when gnus-use-cross-reference
6667             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6668           ;; Do not switch windows but change the buffer to work.
6669           (set-buffer gnus-group-buffer)
6670           (unless (gnus-ephemeral-group-p group)
6671             (gnus-group-update-group group)))))))
6672
6673 (defun gnus-summary-save-newsrc (&optional force)
6674   "Save the current number of read/marked articles in the dribble buffer.
6675 The dribble buffer will then be saved.
6676 If FORCE (the prefix), also save the .newsrc file(s)."
6677   (interactive "P")
6678   (gnus-summary-update-info t)
6679   (if force
6680       (gnus-save-newsrc-file)
6681     (gnus-dribble-save)))
6682
6683 (defun gnus-summary-exit (&optional temporary leave-hidden)
6684   "Exit reading current newsgroup, and then return to group selection mode.
6685 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6686   (interactive)
6687   (gnus-set-global-variables)
6688   (gnus-kill-save-kill-buffer)
6689   (gnus-async-halt-prefetch)
6690   (let* ((group gnus-newsgroup-name)
6691          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6692          (gnus-group-is-exiting-p t)
6693          (mode major-mode)
6694          (group-point nil)
6695          (buf (current-buffer)))
6696     (unless quit-config
6697       ;; Do adaptive scoring, and possibly save score files.
6698       (when gnus-newsgroup-adaptive
6699         (gnus-score-adaptive))
6700       (when gnus-use-scoring
6701         (gnus-score-save)))
6702     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6703     ;; If we have several article buffers, we kill them at exit.
6704     (unless gnus-single-article-buffer
6705       (gnus-kill-buffer gnus-original-article-buffer)
6706       (setq gnus-article-current nil))
6707     (when gnus-use-cache
6708       (gnus-cache-possibly-remove-articles)
6709       (gnus-cache-save-buffers))
6710     (gnus-async-prefetch-remove-group group)
6711     (when gnus-suppress-duplicates
6712       (gnus-dup-enter-articles))
6713     (when gnus-use-trees
6714       (gnus-tree-close group))
6715     (when gnus-use-cache
6716       (gnus-cache-write-active))
6717     ;; Remove entries for this group.
6718     (nnmail-purge-split-history (gnus-group-real-name group))
6719     ;; Make all changes in this group permanent.
6720     (unless quit-config
6721       (gnus-run-hooks 'gnus-exit-group-hook)
6722       (gnus-summary-update-info))
6723     (gnus-close-group group)
6724     ;; Make sure where we were, and go to next newsgroup.
6725     (set-buffer gnus-group-buffer)
6726     (unless quit-config
6727       (gnus-group-jump-to-group group))
6728     (gnus-run-hooks 'gnus-summary-exit-hook)
6729     (unless (or quit-config
6730                 ;; If this group has disappeared from the summary
6731                 ;; buffer, don't skip forwards.
6732                 (not (string= group (gnus-group-group-name))))
6733       (gnus-group-next-unread-group 1))
6734     (setq group-point (point))
6735     (if temporary
6736         nil                             ;Nothing to do.
6737       ;; If we have several article buffers, we kill them at exit.
6738       (unless gnus-single-article-buffer
6739         (gnus-kill-buffer gnus-article-buffer)
6740         (gnus-kill-buffer gnus-original-article-buffer)
6741         (setq gnus-article-current nil))
6742       (set-buffer buf)
6743       (if (not gnus-kill-summary-on-exit)
6744           (progn
6745             (gnus-deaden-summary)
6746             (setq mode nil))
6747         ;; We set all buffer-local variables to nil.  It is unclear why
6748         ;; this is needed, but if we don't, buffer-local variables are
6749         ;; not garbage-collected, it seems.  This would the lead to en
6750         ;; ever-growing Emacs.
6751         (gnus-summary-clear-local-variables)
6752         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6753           (gnus-summary-clear-local-variables))
6754         (when (get-buffer gnus-article-buffer)
6755           (bury-buffer gnus-article-buffer))
6756         ;; Return to group mode buffer.
6757         (when (eq mode 'gnus-summary-mode)
6758           (gnus-kill-buffer buf)))
6759       (setq gnus-current-select-method gnus-select-method)
6760       (set-buffer gnus-group-buffer)
6761       (if quit-config
6762           (gnus-handle-ephemeral-exit quit-config)
6763         (goto-char group-point)
6764         ;; If gnus-group-buffer is already displayed, make sure we also move
6765         ;; the cursor in the window that displays it.
6766         (let ((win (get-buffer-window (current-buffer) 0)))
6767           (if win (set-window-point win (point))))
6768         (unless leave-hidden
6769           (gnus-configure-windows 'group 'force))
6770         (unless (pos-visible-in-window-p)
6771           (forward-line (/ (static-if (featurep 'xemacs)
6772                                (window-displayed-height)
6773                              (1- (window-height)))
6774                            -2))
6775           (set-window-start (selected-window) (point))
6776           (goto-char group-point)))
6777       ;; Clear the current group name.
6778       (unless quit-config
6779         (setq gnus-newsgroup-name nil)))))
6780
6781 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6782 (defun gnus-summary-exit-no-update (&optional no-questions)
6783   "Quit reading current newsgroup without updating read article info."
6784   (interactive)
6785   (let* ((group gnus-newsgroup-name)
6786          (gnus-group-is-exiting-p t)
6787          (gnus-group-is-exiting-without-update-p t)
6788          (quit-config (gnus-group-quit-config group)))
6789     (when (or no-questions
6790               gnus-expert-user
6791               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6792       (gnus-async-halt-prefetch)
6793       (run-hooks 'gnus-summary-prepare-exit-hook)
6794       ;; If we have several article buffers, we kill them at exit.
6795       (unless gnus-single-article-buffer
6796         (gnus-kill-buffer gnus-article-buffer)
6797         (gnus-kill-buffer gnus-original-article-buffer)
6798         (setq gnus-article-current nil))
6799       (if (not gnus-kill-summary-on-exit)
6800           (gnus-deaden-summary)
6801         (gnus-close-group group)
6802         (gnus-summary-clear-local-variables)
6803         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6804           (gnus-summary-clear-local-variables))
6805         (gnus-kill-buffer gnus-summary-buffer))
6806       (unless gnus-single-article-buffer
6807         (setq gnus-article-current nil))
6808       (when gnus-use-trees
6809         (gnus-tree-close group))
6810       (gnus-async-prefetch-remove-group group)
6811       (when (get-buffer gnus-article-buffer)
6812         (bury-buffer gnus-article-buffer))
6813       ;; Return to the group buffer.
6814       (gnus-configure-windows 'group 'force)
6815       ;; Clear the current group name.
6816       (setq gnus-newsgroup-name nil)
6817       (unless (gnus-ephemeral-group-p group)
6818         (gnus-group-update-group group))
6819       (when (equal (gnus-group-group-name) group)
6820         (gnus-group-next-unread-group 1))
6821       (when quit-config
6822         (gnus-handle-ephemeral-exit quit-config)))))
6823
6824 (defun gnus-handle-ephemeral-exit (quit-config)
6825   "Handle movement when leaving an ephemeral group.
6826 The state which existed when entering the ephemeral is reset."
6827   (if (not (buffer-name (car quit-config)))
6828       (gnus-configure-windows 'group 'force)
6829     (set-buffer (car quit-config))
6830     (cond ((eq major-mode 'gnus-summary-mode)
6831            (gnus-set-global-variables))
6832           ((eq major-mode 'gnus-article-mode)
6833            (save-excursion
6834              ;; The `gnus-summary-buffer' variable may point
6835              ;; to the old summary buffer when using a single
6836              ;; article buffer.
6837              (unless (gnus-buffer-live-p gnus-summary-buffer)
6838                (set-buffer gnus-group-buffer))
6839              (set-buffer gnus-summary-buffer)
6840              (gnus-set-global-variables))))
6841     (if (or (eq (cdr quit-config) 'article)
6842             (eq (cdr quit-config) 'pick))
6843         (progn
6844           ;; The current article may be from the ephemeral group
6845           ;; thus it is best that we reload this article
6846           ;;
6847           ;; If we're exiting from a large digest, this can be
6848           ;; extremely slow.  So, it's better not to reload it. -- jh.
6849           ;;(gnus-summary-show-article)
6850           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6851               (gnus-configure-windows 'pick 'force)
6852             (gnus-configure-windows (cdr quit-config) 'force)))
6853       (gnus-configure-windows (cdr quit-config) 'force))
6854     (when (eq major-mode 'gnus-summary-mode)
6855       (gnus-summary-next-subject 1 nil t)
6856       (gnus-summary-recenter)
6857       (gnus-summary-position-point))))
6858
6859 (defun gnus-summary-preview-mime-message ()
6860   "MIME decode and play this message."
6861   (interactive)
6862   (let ((gnus-break-pages nil)
6863         (gnus-show-mime t))
6864     (gnus-summary-select-article gnus-show-all-headers t))
6865   (let ((w (get-buffer-window gnus-article-buffer)))
6866     (when w
6867       (select-window (get-buffer-window gnus-article-buffer)))))
6868
6869 ;;; Dead summaries.
6870
6871 (defvar gnus-dead-summary-mode-map nil)
6872
6873 (unless gnus-dead-summary-mode-map
6874   (setq gnus-dead-summary-mode-map (make-keymap))
6875   (suppress-keymap gnus-dead-summary-mode-map)
6876   (substitute-key-definition
6877    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6878   (dolist (key '("\C-d" "\r" "\177" [delete]))
6879     (define-key gnus-dead-summary-mode-map
6880       key 'gnus-summary-wake-up-the-dead))
6881   (dolist (key '("q" "Q"))
6882     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6883
6884 (defvar gnus-dead-summary-mode nil
6885   "Minor mode for Gnus summary buffers.")
6886
6887 (defun gnus-dead-summary-mode (&optional arg)
6888   "Minor mode for Gnus summary buffers."
6889   (interactive "P")
6890   (when (eq major-mode 'gnus-summary-mode)
6891     (make-local-variable 'gnus-dead-summary-mode)
6892     (setq gnus-dead-summary-mode
6893           (if (null arg) (not gnus-dead-summary-mode)
6894             (> (prefix-numeric-value arg) 0)))
6895     (when gnus-dead-summary-mode
6896       (add-minor-mode
6897        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6898
6899 (defun gnus-deaden-summary ()
6900   "Make the current summary buffer into a dead summary buffer."
6901   ;; Kill any previous dead summary buffer.
6902   (when (and gnus-dead-summary
6903              (buffer-name gnus-dead-summary))
6904     (with-current-buffer gnus-dead-summary
6905       (when gnus-dead-summary-mode
6906         (kill-buffer (current-buffer)))))
6907   ;; Make this the current dead summary.
6908   (setq gnus-dead-summary (current-buffer))
6909   (gnus-dead-summary-mode 1)
6910   (let ((name (buffer-name)))
6911     (when (string-match "Summary" name)
6912       (rename-buffer
6913        (concat (substring name 0 (match-beginning 0)) "Dead "
6914                (substring name (match-beginning 0)))
6915        t)
6916       (bury-buffer))))
6917
6918 (defun gnus-kill-or-deaden-summary (buffer)
6919   "Kill or deaden the summary BUFFER."
6920   (save-excursion
6921     (when (and (buffer-name buffer)
6922                (not gnus-single-article-buffer))
6923       (with-current-buffer buffer
6924         (gnus-kill-buffer gnus-article-buffer)
6925         (gnus-kill-buffer gnus-original-article-buffer)))
6926     (cond
6927      ;; Kill the buffer.
6928      (gnus-kill-summary-on-exit
6929       (when (and gnus-use-trees
6930                  (gnus-buffer-exists-p buffer))
6931         (save-excursion
6932           (set-buffer buffer)
6933           (gnus-tree-close gnus-newsgroup-name)))
6934       (gnus-kill-buffer buffer))
6935      ;; Deaden the buffer.
6936      ((gnus-buffer-exists-p buffer)
6937       (save-excursion
6938         (set-buffer buffer)
6939         (gnus-deaden-summary))))))
6940
6941 (defun gnus-summary-wake-up-the-dead (&rest args)
6942   "Wake up the dead summary buffer."
6943   (interactive)
6944   (gnus-dead-summary-mode -1)
6945   (let ((name (buffer-name)))
6946     (when (string-match "Dead " name)
6947       (rename-buffer
6948        (concat (substring name 0 (match-beginning 0))
6949                (substring name (match-end 0)))
6950        t)))
6951   (gnus-message 3 "This dead summary is now alive again"))
6952
6953 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6954 (defun gnus-summary-fetch-faq (&optional faq-dir)
6955   "Fetch the FAQ for the current group.
6956 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6957 in."
6958   (interactive
6959    (list
6960     (when current-prefix-arg
6961       (completing-read
6962        "FAQ dir: " (and (listp gnus-group-faq-directory)
6963                         (mapcar 'list
6964                                 gnus-group-faq-directory))))))
6965   (let (gnus-faq-buffer)
6966     (when (setq gnus-faq-buffer
6967                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6968       (gnus-configure-windows 'summary-faq))))
6969
6970 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6971 (defun gnus-summary-describe-group (&optional force)
6972   "Describe the current newsgroup."
6973   (interactive "P")
6974   (gnus-group-describe-group force gnus-newsgroup-name))
6975
6976 (defun gnus-summary-describe-briefly ()
6977   "Describe summary mode commands briefly."
6978   (interactive)
6979   (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")))
6980
6981 ;; Walking around group mode buffer from summary mode.
6982
6983 (defun gnus-summary-next-group (&optional no-article target-group backward)
6984   "Exit current newsgroup and then select next unread newsgroup.
6985 If prefix argument NO-ARTICLE is non-nil, no article is selected
6986 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6987 previous group instead."
6988   (interactive "P")
6989   ;; Stop pre-fetching.
6990   (gnus-async-halt-prefetch)
6991   (let ((current-group gnus-newsgroup-name)
6992         (current-buffer (current-buffer))
6993         entered)
6994     ;; First we semi-exit this group to update Xrefs and all variables.
6995     ;; We can't do a real exit, because the window conf must remain
6996     ;; the same in case the user is prompted for info, and we don't
6997     ;; want the window conf to change before that...
6998     (gnus-summary-exit t)
6999     (while (not entered)
7000       ;; Then we find what group we are supposed to enter.
7001       (set-buffer gnus-group-buffer)
7002       (gnus-group-jump-to-group current-group)
7003       (setq target-group
7004             (or target-group
7005                 (if (eq gnus-keep-same-level 'best)
7006                     (gnus-summary-best-group gnus-newsgroup-name)
7007                   (gnus-summary-search-group backward gnus-keep-same-level))))
7008       (if (not target-group)
7009           ;; There are no further groups, so we return to the group
7010           ;; buffer.
7011           (progn
7012             (gnus-message 5 "Returning to the group buffer")
7013             (setq entered t)
7014             (when (gnus-buffer-live-p current-buffer)
7015               (set-buffer current-buffer)
7016               (gnus-summary-exit))
7017             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7018         ;; We try to enter the target group.
7019         (gnus-group-jump-to-group target-group)
7020         (let ((unreads (gnus-group-group-unread)))
7021           (if (and (or (eq t unreads)
7022                        (and unreads (not (zerop unreads))))
7023                    (gnus-summary-read-group
7024                     target-group nil no-article
7025                     (and (buffer-name current-buffer) current-buffer)
7026                     nil backward))
7027               (setq entered t)
7028             (setq current-group target-group
7029                   target-group nil)))))))
7030
7031 (defun gnus-summary-prev-group (&optional no-article)
7032   "Exit current newsgroup and then select previous unread newsgroup.
7033 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7034   (interactive "P")
7035   (gnus-summary-next-group no-article nil t))
7036
7037 ;; Walking around summary lines.
7038
7039 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7040   "Go to the first subject satisfying any non-nil constraint.
7041 If UNREAD is non-nil, the article should be unread.
7042 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7043 If UNSEEN is non-nil, the article should be unseen.
7044 Returns the article selected or nil if there are no matching articles."
7045   (interactive "P")
7046   (cond
7047    ;; Empty summary.
7048    ((null gnus-newsgroup-data)
7049     (gnus-message 3 "No articles in the group")
7050     nil)
7051    ;; Pick the first article.
7052    ((not (or unread undownloaded unseen))
7053     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7054     (gnus-data-number (car gnus-newsgroup-data)))
7055    ;; Find the first unread article.
7056    (t
7057     (let ((data gnus-newsgroup-data))
7058       (while (and data
7059                   (let ((num (gnus-data-number (car data))))
7060                     (or (memq num gnus-newsgroup-unfetched)
7061                         (not (or (and unread
7062                                       (memq num gnus-newsgroup-unreads))
7063                                  (and undownloaded
7064                                       (memq num gnus-newsgroup-undownloaded))
7065                                  (and unseen
7066                                       (memq num gnus-newsgroup-unseen)))))))
7067         (setq data (cdr data)))
7068       (prog1
7069           (if data
7070               (progn
7071                 (goto-char (gnus-data-pos (car data)))
7072                 (gnus-data-number (car data)))
7073             (gnus-message 3 "No more%s articles"
7074                           (let* ((r (when unread " unread"))
7075                                  (d (when undownloaded " undownloaded"))
7076                                  (s (when unseen " unseen"))
7077                                  (l (delq nil (list r d s))))
7078                             (cond ((= 3 (length l))
7079                                    (concat r "," d ", or" s))
7080                                   ((= 2 (length l))
7081                                    (concat (car l) ", or" (cadr l)))
7082                                   ((= 1 (length l))
7083                                    (car l))
7084                                   (t
7085                                    ""))))
7086             nil
7087             )
7088         (gnus-summary-position-point))))))
7089
7090 (defun gnus-summary-next-subject (n &optional unread dont-display)
7091   "Go to next N'th summary line.
7092 If N is negative, go to the previous N'th subject line.
7093 If UNREAD is non-nil, only unread articles are selected.
7094 The difference between N and the actual number of steps taken is
7095 returned."
7096   (interactive "p")
7097   (let ((backward (< n 0))
7098         (n (abs n)))
7099     (while (and (> n 0)
7100                 (if backward
7101                     (gnus-summary-find-prev unread)
7102                   (gnus-summary-find-next unread)))
7103       (unless (zerop (setq n (1- n)))
7104         (gnus-summary-show-thread)))
7105     (when (/= 0 n)
7106       (gnus-message 7 "No more%s articles"
7107                     (if unread " unread" "")))
7108     (unless dont-display
7109       (gnus-summary-recenter)
7110       (gnus-summary-position-point))
7111     n))
7112
7113 (defun gnus-summary-next-unread-subject (n)
7114   "Go to next N'th unread summary line."
7115   (interactive "p")
7116   (gnus-summary-next-subject n t))
7117
7118 (defun gnus-summary-prev-subject (n &optional unread)
7119   "Go to previous N'th summary line.
7120 If optional argument UNREAD is non-nil, only unread article is selected."
7121   (interactive "p")
7122   (gnus-summary-next-subject (- n) unread))
7123
7124 (defun gnus-summary-prev-unread-subject (n)
7125   "Go to previous N'th unread summary line."
7126   (interactive "p")
7127   (gnus-summary-next-subject (- n) t))
7128
7129 (defun gnus-summary-goto-subjects (articles)
7130   "Insert the subject header for ARTICLES in the current buffer."
7131   (save-excursion
7132     (dolist (article articles)
7133       (gnus-summary-goto-subject article t)))
7134   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7135   (gnus-summary-position-point))
7136
7137 (defun gnus-summary-goto-subject (article &optional force silent)
7138   "Go the subject line of ARTICLE.
7139 If FORCE, also allow jumping to articles not currently shown."
7140   (interactive "nArticle number: ")
7141   (unless (numberp article)
7142     (error "Article %s is not a number" article))
7143   (let ((b (point))
7144         (data (gnus-data-find article)))
7145     ;; We read in the article if we have to.
7146     (and (not data)
7147          force
7148          (gnus-summary-insert-subject
7149           article
7150           (if (or (numberp force) (vectorp force)) force)
7151           t)
7152          (setq data (gnus-data-find article)))
7153     (goto-char b)
7154     (if (not data)
7155         (progn
7156           (unless silent
7157             (gnus-message 3 "Can't find article %d" article))
7158           nil)
7159       (let ((pt (gnus-data-pos data)))
7160         (goto-char pt)
7161         (gnus-summary-set-article-display-arrow pt))
7162       (gnus-summary-position-point)
7163       article)))
7164
7165 ;; Walking around summary lines with displaying articles.
7166
7167 (defun gnus-summary-expand-window (&optional arg)
7168   "Make the summary buffer take up the entire Emacs frame.
7169 Given a prefix, will force an `article' buffer configuration."
7170   (interactive "P")
7171   (if arg
7172       (gnus-configure-windows 'article 'force)
7173     (gnus-configure-windows 'summary 'force)))
7174
7175 (defun gnus-summary-display-article (article &optional all-header)
7176   "Display ARTICLE in article buffer."
7177   (when (gnus-buffer-live-p gnus-article-buffer)
7178     (with-current-buffer gnus-article-buffer
7179       (set-buffer-multibyte t)))
7180   (gnus-set-global-variables)
7181   (when (gnus-buffer-live-p gnus-article-buffer)
7182     (with-current-buffer gnus-article-buffer
7183       (setq gnus-article-charset gnus-newsgroup-charset)
7184       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7185       (set-buffer-multibyte t)))
7186   (if (null article)
7187       nil
7188     (prog1
7189         (if gnus-summary-display-article-function
7190             (funcall gnus-summary-display-article-function article all-header)
7191           (gnus-article-prepare article all-header))
7192       (with-current-buffer gnus-article-buffer
7193         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7194              nil))
7195       (gnus-run-hooks 'gnus-select-article-hook)
7196       (when (and gnus-current-article
7197                  (not (zerop gnus-current-article)))
7198         (gnus-summary-goto-subject gnus-current-article))
7199       (gnus-summary-recenter)
7200       (when (and gnus-use-trees gnus-show-threads)
7201         (gnus-possibly-generate-tree article)
7202         (gnus-highlight-selected-tree article))
7203       ;; Successfully display article.
7204       (gnus-article-set-window-start
7205        (cdr (assq article gnus-newsgroup-bookmarks))))))
7206
7207 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7208   "Select the current article.
7209 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7210 non-nil, the article will be re-fetched even if it already present in
7211 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7212 be displayed."
7213   ;; Make sure we are in the summary buffer to work around bbdb bug.
7214   (unless (eq major-mode 'gnus-summary-mode)
7215     (set-buffer gnus-summary-buffer))
7216   (let ((article (or article (gnus-summary-article-number)))
7217         (all-headers (not (not all-headers))) ;Must be T or NIL.
7218         gnus-summary-display-article-function)
7219     (and (not pseudo)
7220          (gnus-summary-article-pseudo-p article)
7221          (error "This is a pseudo-article"))
7222     (save-excursion
7223       (set-buffer gnus-summary-buffer)
7224       (if (or (and gnus-single-article-buffer
7225                    (or (null gnus-current-article)
7226                        (null gnus-article-current)
7227                        (null (get-buffer gnus-article-buffer))
7228                        (not (eq article (cdr gnus-article-current)))
7229                        (not (equal (car gnus-article-current)
7230                                    gnus-newsgroup-name))))
7231               (and (not gnus-single-article-buffer)
7232                    (or (null gnus-current-article)
7233                        (not (eq gnus-current-article article))))
7234               force)
7235           ;; The requested article is different from the current article.
7236           (progn
7237             (gnus-summary-display-article article all-headers)
7238             (gnus-article-set-window-start
7239              (cdr (assq article gnus-newsgroup-bookmarks)))
7240             article)
7241         'old))))
7242
7243 (defun gnus-summary-force-verify-and-decrypt ()
7244   "Display buttons for signed/encrypted parts and verify/decrypt them."
7245   (interactive)
7246   (let ((mm-verify-option 'known)
7247         (mm-decrypt-option 'known)
7248         (gnus-article-emulate-mime t)
7249         (gnus-buttonized-mime-types (append (list "multipart/signed"
7250                                                   "multipart/encrypted")
7251                                             gnus-buttonized-mime-types)))
7252     (gnus-summary-select-article nil 'force)))
7253
7254 (defun gnus-summary-set-current-mark (&optional current-mark)
7255   "Obsolete function."
7256   nil)
7257
7258 (defun gnus-summary-next-article (&optional unread subject backward push)
7259   "Select the next article.
7260 If UNREAD, only unread articles are selected.
7261 If SUBJECT, only articles with SUBJECT are selected.
7262 If BACKWARD, the previous article is selected instead of the next."
7263   (interactive "P")
7264   (cond
7265    ;; Is there such an article?
7266    ((and (gnus-summary-search-forward unread subject backward)
7267          (or (gnus-summary-display-article (gnus-summary-article-number))
7268              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7269     (gnus-summary-position-point))
7270    ;; If not, we try the first unread, if that is wanted.
7271    ((and subject
7272          gnus-auto-select-same
7273          (gnus-summary-first-unread-article))
7274     (gnus-summary-position-point)
7275     (gnus-message 6 "Wrapped"))
7276    ;; Try to get next/previous article not displayed in this group.
7277    ((and gnus-auto-extend-newsgroup
7278          (not unread) (not subject))
7279     (gnus-summary-goto-article
7280      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7281      nil (count-lines (point-min) (point))))
7282    ;; Go to next/previous group.
7283    (t
7284     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7285       (gnus-summary-jump-to-group gnus-newsgroup-name))
7286     (let ((cmd last-command-char)
7287           (point
7288            (with-current-buffer gnus-group-buffer
7289              (point)))
7290           (group
7291            (if (eq gnus-keep-same-level 'best)
7292                (gnus-summary-best-group gnus-newsgroup-name)
7293              (gnus-summary-search-group backward gnus-keep-same-level))))
7294       ;; For some reason, the group window gets selected.  We change
7295       ;; it back.
7296       (select-window (get-buffer-window (current-buffer)))
7297       ;; Select next unread newsgroup automagically.
7298       (cond
7299        ((or (not gnus-auto-select-next)
7300             (not cmd))
7301         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7302        ((or (eq gnus-auto-select-next 'quietly)
7303             (and (eq gnus-auto-select-next 'slightly-quietly)
7304                  push)
7305             (and (eq gnus-auto-select-next 'almost-quietly)
7306                  (gnus-summary-last-article-p)))
7307         ;; Select quietly.
7308         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7309             (gnus-summary-exit)
7310           (gnus-message 7 "No more%s articles (%s)..."
7311                         (if unread " unread" "")
7312                         (if group (concat "selecting " group)
7313                           "exiting"))
7314           (gnus-summary-next-group nil group backward)))
7315        (t
7316         (when (gnus-key-press-event-p last-input-event)
7317           (gnus-summary-walk-group-buffer
7318            gnus-newsgroup-name cmd unread backward point))))))))
7319
7320 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7321   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7322                       (?\C-p (gnus-group-prev-unread-group 1))))
7323         (cursor-in-echo-area t)
7324         keve key group ended prompt)
7325     (save-excursion
7326       (set-buffer gnus-group-buffer)
7327       (goto-char start)
7328       (setq group
7329             (if (eq gnus-keep-same-level 'best)
7330                 (gnus-summary-best-group gnus-newsgroup-name)
7331               (gnus-summary-search-group backward gnus-keep-same-level))))
7332     (while (not ended)
7333       (setq prompt
7334             (format
7335              "No more%s articles%s " (if unread " unread" "")
7336              (if (and group
7337                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7338                  (format " (Type %s for %s [%s])"
7339                          (single-key-description cmd)
7340                          (gnus-group-decoded-name group)
7341                          (gnus-group-unread group))
7342                (format " (Type %s to exit %s)"
7343                        (single-key-description cmd)
7344                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7345       ;; Confirm auto selection.
7346       (setq key (car (setq keve (gnus-read-event-char prompt)))
7347             ended t)
7348       (cond
7349        ((assq key keystrokes)
7350         (let ((obuf (current-buffer)))
7351           (switch-to-buffer gnus-group-buffer)
7352           (when group
7353             (gnus-group-jump-to-group group))
7354           (eval (cadr (assq key keystrokes)))
7355           (setq group (gnus-group-group-name))
7356           (switch-to-buffer obuf))
7357         (setq ended nil))
7358        ((equal key cmd)
7359         (if (or (not group)
7360                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7361             (gnus-summary-exit)
7362           (gnus-summary-next-group nil group backward)))
7363        (t
7364         (push (cdr keve) unread-command-events))))))
7365
7366 (defun gnus-summary-next-unread-article ()
7367   "Select unread article after current one."
7368   (interactive)
7369   (gnus-summary-next-article
7370    (or (not (eq gnus-summary-goto-unread 'never))
7371        (gnus-summary-last-article-p (gnus-summary-article-number)))
7372    (and gnus-auto-select-same
7373         (gnus-summary-article-subject))))
7374
7375 (defun gnus-summary-prev-article (&optional unread subject)
7376   "Select the article after the current one.
7377 If UNREAD is non-nil, only unread articles are selected."
7378   (interactive "P")
7379   (gnus-summary-next-article unread subject t))
7380
7381 (defun gnus-summary-prev-unread-article ()
7382   "Select unread article before current one."
7383   (interactive)
7384   (gnus-summary-prev-article
7385    (or (not (eq gnus-summary-goto-unread 'never))
7386        (gnus-summary-first-article-p (gnus-summary-article-number)))
7387    (and gnus-auto-select-same
7388         (gnus-summary-article-subject))))
7389
7390 (defun gnus-summary-next-page (&optional lines circular stop)
7391   "Show next page of the selected article.
7392 If at the end of the current article, select the next article.
7393 LINES says how many lines should be scrolled up.
7394
7395 If CIRCULAR is non-nil, go to the start of the article instead of
7396 selecting the next article when reaching the end of the current
7397 article.
7398
7399 If STOP is non-nil, just stop when reaching the end of the message.
7400
7401 Also see the variable `gnus-article-skip-boring'."
7402   (interactive "P")
7403   (setq gnus-summary-buffer (current-buffer))
7404   (gnus-set-global-variables)
7405   (let ((article (gnus-summary-article-number))
7406         (article-window (get-buffer-window gnus-article-buffer t))
7407         endp)
7408     ;; If the buffer is empty, we have no article.
7409     (unless article
7410       (error "No article to select"))
7411     (gnus-configure-windows 'article)
7412     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7413         (if (and (eq gnus-summary-goto-unread 'never)
7414                  (not (gnus-summary-last-article-p article)))
7415             (gnus-summary-next-article)
7416           (gnus-summary-next-unread-article))
7417       (if (or (null gnus-current-article)
7418               (null gnus-article-current)
7419               (/= article (cdr gnus-article-current))
7420               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7421           ;; Selected subject is different from current article's.
7422           (gnus-summary-display-article article)
7423         (when article-window
7424           (gnus-eval-in-buffer-window gnus-article-buffer
7425             (setq endp (or (gnus-article-next-page lines)
7426                            (gnus-article-only-boring-p))))
7427           (when endp
7428             (cond (stop
7429                    (gnus-message 3 "End of message"))
7430                   (circular
7431                    (gnus-summary-beginning-of-article))
7432                   (lines
7433                    (gnus-message 3 "End of message"))
7434                   ((null lines)
7435                    (if (and (eq gnus-summary-goto-unread 'never)
7436                             (not (gnus-summary-last-article-p article)))
7437                        (gnus-summary-next-article)
7438                      (gnus-summary-next-unread-article))))))))
7439     (gnus-summary-recenter)
7440     (gnus-summary-position-point)))
7441
7442 (defun gnus-summary-prev-page (&optional lines move)
7443   "Show previous page of selected article.
7444 Argument LINES specifies lines to be scrolled down.
7445 If MOVE, move to the previous unread article if point is at
7446 the beginning of the buffer."
7447   (interactive "P")
7448   (let ((article (gnus-summary-article-number))
7449         (article-window (get-buffer-window gnus-article-buffer t))
7450         endp)
7451     (gnus-configure-windows 'article)
7452     (if (or (null gnus-current-article)
7453             (null gnus-article-current)
7454             (/= article (cdr gnus-article-current))
7455             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7456         ;; Selected subject is different from current article's.
7457         (gnus-summary-display-article article)
7458       (gnus-summary-recenter)
7459       (when article-window
7460         (gnus-eval-in-buffer-window gnus-article-buffer
7461           (setq endp (gnus-article-prev-page lines)))
7462         (when (and move endp)
7463           (cond (lines
7464                  (gnus-message 3 "Beginning of message"))
7465                 ((null lines)
7466                  (if (and (eq gnus-summary-goto-unread 'never)
7467                           (not (gnus-summary-first-article-p article)))
7468                      (gnus-summary-prev-article)
7469                    (gnus-summary-prev-unread-article))))))))
7470   (gnus-summary-position-point))
7471
7472 (defun gnus-summary-prev-page-or-article (&optional lines)
7473   "Show previous page of selected article.
7474 Argument LINES specifies lines to be scrolled down.
7475 If at the beginning of the article, go to the next article."
7476   (interactive "P")
7477   (gnus-summary-prev-page lines t))
7478
7479 (defun gnus-summary-scroll-up (lines)
7480   "Scroll up (or down) one line current article.
7481 Argument LINES specifies lines to be scrolled up (or down if negative)."
7482   (interactive "p")
7483   (gnus-configure-windows 'article)
7484   (gnus-summary-show-thread)
7485   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7486     (gnus-eval-in-buffer-window gnus-article-buffer
7487       (cond ((> lines 0)
7488              (when (gnus-article-next-page lines)
7489                (gnus-message 3 "End of message")))
7490             ((< lines 0)
7491              (gnus-article-prev-page (- lines))))))
7492   (gnus-summary-recenter)
7493   (gnus-summary-position-point))
7494
7495 (defun gnus-summary-scroll-down (lines)
7496   "Scroll down (or up) one line current article.
7497 Argument LINES specifies lines to be scrolled down (or up if negative)."
7498   (interactive "p")
7499   (gnus-summary-scroll-up (- lines)))
7500
7501 (defun gnus-summary-next-same-subject ()
7502   "Select next article which has the same subject as current one."
7503   (interactive)
7504   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7505
7506 (defun gnus-summary-prev-same-subject ()
7507   "Select previous article which has the same subject as current one."
7508   (interactive)
7509   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7510
7511 (defun gnus-summary-next-unread-same-subject ()
7512   "Select next unread article which has the same subject as current one."
7513   (interactive)
7514   (gnus-summary-next-article t (gnus-summary-article-subject)))
7515
7516 (defun gnus-summary-prev-unread-same-subject ()
7517   "Select previous unread article which has the same subject as current one."
7518   (interactive)
7519   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7520
7521 (defun gnus-summary-first-unread-article ()
7522   "Select the first unread article.
7523 Return nil if there are no unread articles."
7524   (interactive)
7525   (prog1
7526       (when (gnus-summary-first-subject t)
7527         (gnus-summary-show-thread)
7528         (gnus-summary-first-subject t)
7529         (gnus-summary-display-article (gnus-summary-article-number)))
7530     (gnus-summary-position-point)))
7531
7532 (defun gnus-summary-first-unread-subject ()
7533   "Place the point on the subject line of the first unread article.
7534 Return nil if there are no unread articles."
7535   (interactive)
7536   (prog1
7537       (when (gnus-summary-first-subject t)
7538         (gnus-summary-show-thread)
7539         (gnus-summary-first-subject t))
7540     (gnus-summary-position-point)))
7541
7542 (defun gnus-summary-first-unseen-subject ()
7543   "Place the point on the subject line of the first unseen article.
7544 Return nil if there are no unseen articles."
7545   (interactive)
7546   (prog1
7547       (when (gnus-summary-first-subject nil nil t)
7548         (gnus-summary-show-thread)
7549         (gnus-summary-first-subject nil nil t))
7550     (gnus-summary-position-point)))
7551
7552 (defun gnus-summary-first-unseen-or-unread-subject ()
7553   "Place the point on the subject line of the first unseen article or,
7554 if all article have been seen, on the subject line of the first unread
7555 article."
7556   (interactive)
7557   (prog1
7558       (unless (when (gnus-summary-first-subject nil nil t)
7559                 (gnus-summary-show-thread)
7560                 (gnus-summary-first-subject nil nil t))
7561         (when (gnus-summary-first-subject t)
7562           (gnus-summary-show-thread)
7563           (gnus-summary-first-subject t)))
7564     (gnus-summary-position-point)))
7565
7566 (defun gnus-summary-first-article ()
7567   "Select the first article.
7568 Return nil if there are no articles."
7569   (interactive)
7570   (prog1
7571       (when (gnus-summary-first-subject)
7572         (gnus-summary-show-thread)
7573         (gnus-summary-first-subject)
7574         (gnus-summary-display-article (gnus-summary-article-number)))
7575     (gnus-summary-position-point)))
7576
7577 (defun gnus-summary-best-unread-article (&optional arg)
7578   "Select the unread article with the highest score.
7579 If given a prefix argument, select the next unread article that has a
7580 score higher than the default score."
7581   (interactive "P")
7582   (let ((article (if arg
7583                      (gnus-summary-better-unread-subject)
7584                    (gnus-summary-best-unread-subject))))
7585     (if article
7586         (gnus-summary-goto-article article)
7587       (error "No unread articles"))))
7588
7589 (defun gnus-summary-best-unread-subject ()
7590   "Select the unread subject with the highest score."
7591   (interactive)
7592   (let ((best -1000000)
7593         (data gnus-newsgroup-data)
7594         article score)
7595     (while data
7596       (and (gnus-data-unread-p (car data))
7597            (> (setq score
7598                     (gnus-summary-article-score (gnus-data-number (car data))))
7599               best)
7600            (setq best score
7601                  article (gnus-data-number (car data))))
7602       (setq data (cdr data)))
7603     (when article
7604       (gnus-summary-goto-subject article))
7605     (gnus-summary-position-point)
7606     article))
7607
7608 (defun gnus-summary-better-unread-subject ()
7609   "Select the first unread subject that has a score over the default score."
7610   (interactive)
7611   (let ((data gnus-newsgroup-data)
7612         article score)
7613     (while (and (setq article (gnus-data-number (car data)))
7614                 (or (gnus-data-read-p (car data))
7615                     (not (> (gnus-summary-article-score article)
7616                             gnus-summary-default-score))))
7617       (setq data (cdr data)))
7618     (when article
7619       (gnus-summary-goto-subject article))
7620     (gnus-summary-position-point)
7621     article))
7622
7623 (defun gnus-summary-last-subject ()
7624   "Go to the last displayed subject line in the group."
7625   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7626     (when article
7627       (gnus-summary-goto-subject article))))
7628
7629 (defun gnus-summary-goto-article (article &optional all-headers force)
7630   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7631 If ALL-HEADERS is non-nil, no header lines are hidden.
7632 If FORCE, go to the article even if it isn't displayed.  If FORCE
7633 is a number, it is the line the article is to be displayed on."
7634   (interactive
7635    (list
7636     (completing-read
7637      "Article number or Message-ID: "
7638      (mapcar (lambda (number) (list (int-to-string number)))
7639              gnus-newsgroup-limit))
7640     current-prefix-arg
7641     t))
7642   (prog1
7643       (if (and (stringp article)
7644                (string-match "@\\|%40" article))
7645           (gnus-summary-refer-article article)
7646         (when (stringp article)
7647           (setq article (string-to-number article)))
7648         (if (gnus-summary-goto-subject article force)
7649             (gnus-summary-display-article article all-headers)
7650           (gnus-message 4 "Couldn't go to article %s" article) nil))
7651     (gnus-summary-position-point)))
7652
7653 (defun gnus-summary-goto-last-article ()
7654   "Go to the previously read article."
7655   (interactive)
7656   (prog1
7657       (when gnus-last-article
7658         (gnus-summary-goto-article gnus-last-article nil t))
7659     (gnus-summary-position-point)))
7660
7661 (defun gnus-summary-pop-article (number)
7662   "Pop one article off the history and go to the previous.
7663 NUMBER articles will be popped off."
7664   (interactive "p")
7665   (let (to)
7666     (setq gnus-newsgroup-history
7667           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7668     (if to
7669         (gnus-summary-goto-article (car to) nil t)
7670       (error "Article history empty")))
7671   (gnus-summary-position-point))
7672
7673 ;; Summary commands and functions for limiting the summary buffer.
7674
7675 (defun gnus-summary-limit-to-articles (n)
7676   "Limit the summary buffer to the next N articles.
7677 If not given a prefix, use the process marked articles instead."
7678   (interactive "P")
7679   (prog1
7680       (let ((articles (gnus-summary-work-articles n)))
7681         (setq gnus-newsgroup-processable nil)
7682         (gnus-summary-limit articles))
7683     (gnus-summary-position-point)))
7684
7685 (defun gnus-summary-pop-limit (&optional total)
7686   "Restore the previous limit.
7687 If given a prefix, remove all limits."
7688   (interactive "P")
7689   (when total
7690     (setq gnus-newsgroup-limits
7691           (list (mapcar (lambda (h) (mail-header-number h))
7692                         gnus-newsgroup-headers))))
7693   (unless gnus-newsgroup-limits
7694     (error "No limit to pop"))
7695   (prog1
7696       (gnus-summary-limit nil 'pop)
7697     (gnus-summary-position-point)))
7698
7699 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7700   "Limit the summary buffer to articles that have subjects that match a regexp.
7701 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7702   (interactive
7703    (list (read-string (if current-prefix-arg
7704                           "Exclude subject (regexp): "
7705                         "Limit to subject (regexp): "))
7706          nil current-prefix-arg))
7707   (unless header
7708     (setq header "subject"))
7709   (when (not (equal "" subject))
7710     (prog1
7711         (let ((articles (gnus-summary-find-matching
7712                          (or header "subject") subject 'all nil nil
7713                          not-matching)))
7714           (unless articles
7715             (error "Found no matches for \"%s\"" subject))
7716           (gnus-summary-limit articles))
7717       (gnus-summary-position-point))))
7718
7719 (defun gnus-summary-limit-to-author (from &optional not-matching)
7720   "Limit the summary buffer to articles that have authors that match a regexp.
7721 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7722   (interactive
7723    (list (read-string (if current-prefix-arg
7724                           "Exclude author (regexp): "
7725                         "Limit to author (regexp): "))
7726          current-prefix-arg))
7727   (gnus-summary-limit-to-subject from "from" not-matching))
7728
7729 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7730   "Limit the summary buffer to articles with the given RECIPIENT.
7731
7732 If NOT-MATCHING, exclude RECIPIENT.
7733
7734 To and Cc headers are checked.  You need to include them in
7735 `nnmail-extra-headers'."
7736   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7737   (interactive
7738    (list (read-string (format "%s recipient (regexp): "
7739                               (if current-prefix-arg "Exclude" "Limit to")))
7740          current-prefix-arg))
7741   (when (not (equal "" recipient))
7742     (prog1 (let* ((to
7743                    (if (memq 'To nnmail-extra-headers)
7744                        (gnus-summary-find-matching
7745                         (cons 'extra 'To) recipient 'all nil nil
7746                         not-matching)
7747                      (gnus-message
7748                       1 "`To' isn't present in `nnmail-extra-headers'")
7749                      (sit-for 1)
7750                      nil))
7751                   (cc
7752                    (if (memq 'Cc nnmail-extra-headers)
7753                        (gnus-summary-find-matching
7754                         (cons 'extra 'Cc) recipient 'all nil nil
7755                         not-matching)
7756                      (gnus-message
7757                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7758                      (sit-for 1)
7759                      nil))
7760                   (articles
7761                    (if not-matching
7762                        ;; We need the numbers that are in both lists:
7763                        (mapcar (lambda (a)
7764                                  (and (memq a to) a))
7765                                cc)
7766                      (nconc to cc))))
7767              (unless articles
7768                (error "Found no matches for \"%s\"" recipient))
7769              (gnus-summary-limit articles))
7770       (gnus-summary-position-point))))
7771
7772 (defun gnus-summary-limit-to-age (age &optional younger-p)
7773   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7774 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7775 articles that are younger than AGE days."
7776   (interactive
7777    (let ((younger current-prefix-arg)
7778          (days-got nil)
7779          days)
7780      (while (not days-got)
7781        (setq days (if younger
7782                       (read-string "Limit to articles younger than (in days, older when negative): ")
7783                     (read-string
7784                      "Limit to articles older than (in days, younger when negative): ")))
7785        (when (> (length days) 0)
7786          (setq days (read days)))
7787        (if (numberp days)
7788            (progn
7789              (setq days-got t)
7790              (when (< days 0)
7791                (setq younger (not younger))
7792                (setq days (* days -1))))
7793          (message "Please enter a number.")
7794          (sleep-for 1)))
7795      (list days younger)))
7796   (prog1
7797       (let ((data gnus-newsgroup-data)
7798             (cutoff (days-to-time age))
7799             articles d date is-younger)
7800         (while (setq d (pop data))
7801           (when (and (vectorp (gnus-data-header d))
7802                      (setq date (mail-header-date (gnus-data-header d))))
7803             (setq is-younger (time-less-p
7804                               (time-since (condition-case ()
7805                                               (date-to-time date)
7806                                             (error '(0 0))))
7807                               cutoff))
7808             (when (if younger-p
7809                       is-younger
7810                     (not is-younger))
7811               (push (gnus-data-number d) articles))))
7812         (gnus-summary-limit (nreverse articles)))
7813     (gnus-summary-position-point)))
7814
7815 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7816   "Limit the summary buffer to articles that match an 'extra' header."
7817   (interactive
7818    (let ((header
7819           (intern
7820            (gnus-completing-read-with-default
7821             (symbol-name (car gnus-extra-headers))
7822             (if current-prefix-arg
7823                 "Exclude extra header"
7824               "Limit extra header")
7825             (mapcar (lambda (x)
7826                       (cons (symbol-name x) x))
7827                     gnus-extra-headers)
7828             nil
7829             t))))
7830      (list header
7831            (read-string (format "%s header %s (regexp): "
7832                                 (if current-prefix-arg "Exclude" "Limit to")
7833                                 header))
7834            current-prefix-arg)))
7835   (when (not (equal "" regexp))
7836     (prog1
7837         (let ((articles (gnus-summary-find-matching
7838                          (cons 'extra header) regexp 'all nil nil
7839                          not-matching)))
7840           (unless articles
7841             (error "Found no matches for \"%s\"" regexp))
7842           (gnus-summary-limit articles))
7843       (gnus-summary-position-point))))
7844
7845 (defun gnus-summary-limit-to-display-predicate ()
7846   "Limit the summary buffer to the predicated in the `display' group parameter."
7847   (interactive)
7848   (unless gnus-newsgroup-display
7849     (error "There is no `display' group parameter"))
7850   (let (articles)
7851     (dolist (number gnus-newsgroup-articles)
7852       (when (funcall gnus-newsgroup-display)
7853         (push number articles)))
7854     (gnus-summary-limit articles))
7855   (gnus-summary-position-point))
7856
7857 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7858 (make-obsolete
7859  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7860
7861 (defun gnus-summary-limit-to-unread (&optional all)
7862   "Limit the summary buffer to articles that are not marked as read.
7863 If ALL is non-nil, limit strictly to unread articles."
7864   (interactive "P")
7865   (if all
7866       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7867     (gnus-summary-limit-to-marks
7868      ;; Concat all the marks that say that an article is read and have
7869      ;; those removed.
7870      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7871            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7872            gnus-low-score-mark gnus-expirable-mark
7873            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7874            gnus-duplicate-mark gnus-souped-mark)
7875      'reverse)))
7876
7877 (defun gnus-summary-limit-to-replied (&optional unreplied)
7878   "Limit the summary buffer to replied articles.
7879 If UNREPLIED (the prefix), limit to unreplied articles."
7880   (interactive "P")
7881   (if unreplied
7882       (gnus-summary-limit
7883        (gnus-set-difference gnus-newsgroup-articles
7884         gnus-newsgroup-replied))
7885     (gnus-summary-limit gnus-newsgroup-replied))
7886   (gnus-summary-position-point))
7887
7888 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7889 (make-obsolete 'gnus-summary-delete-marked-with
7890                'gnus-summary-limit-exclude-marks)
7891
7892 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7893   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7894 If REVERSE, limit the summary buffer to articles that are marked
7895 with MARKS.  MARKS can either be a string of marks or a list of marks.
7896 Returns how many articles were removed."
7897   (interactive "sMarks: ")
7898   (gnus-summary-limit-to-marks marks t))
7899
7900 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7901   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7902 If REVERSE (the prefix), limit the summary buffer to articles that are
7903 not marked with MARKS.  MARKS can either be a string of marks or a
7904 list of marks.
7905 Returns how many articles were removed."
7906   (interactive "sMarks: \nP")
7907   (prog1
7908       (let ((data gnus-newsgroup-data)
7909             (marks (if (listp marks) marks
7910                      (append marks nil))) ; Transform to list.
7911             articles)
7912         (while data
7913           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7914                   (memq (gnus-data-mark (car data)) marks))
7915             (push (gnus-data-number (car data)) articles))
7916           (setq data (cdr data)))
7917         (gnus-summary-limit articles))
7918     (gnus-summary-position-point)))
7919
7920 (defun gnus-summary-limit-to-score (score)
7921   "Limit to articles with score at or above SCORE."
7922   (interactive "NLimit to articles with score of at least: ")
7923   (let ((data gnus-newsgroup-data)
7924         articles)
7925     (while data
7926       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7927                 score)
7928         (push (gnus-data-number (car data)) articles))
7929       (setq data (cdr data)))
7930     (prog1
7931         (gnus-summary-limit articles)
7932       (gnus-summary-position-point))))
7933
7934 (defun gnus-summary-limit-to-unseen ()
7935   "Limit to unseen articles."
7936   (interactive)
7937   (prog1
7938       (gnus-summary-limit gnus-newsgroup-unseen)
7939     (gnus-summary-position-point)))
7940
7941 (defun gnus-summary-limit-include-thread (id)
7942   "Display all the hidden articles that is in the thread with ID in it.
7943 When called interactively, ID is the Message-ID of the current
7944 article."
7945   (interactive (list (mail-header-id (gnus-summary-article-header))))
7946   (let ((articles (gnus-articles-in-thread
7947                    (gnus-id-to-thread (gnus-root-id id)))))
7948     (prog1
7949         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7950       (gnus-summary-limit-include-matching-articles
7951        "subject"
7952        (regexp-quote (gnus-simplify-subject-re
7953                       (mail-header-subject (gnus-id-to-header id)))))
7954       (gnus-summary-position-point))))
7955
7956 (defun gnus-summary-limit-include-matching-articles (header regexp)
7957   "Display all the hidden articles that have HEADERs that match REGEXP."
7958   (interactive (list (read-string "Match on header: ")
7959                      (read-string "Regexp: ")))
7960   (let ((articles (gnus-find-matching-articles header regexp)))
7961     (prog1
7962         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7963       (gnus-summary-position-point))))
7964
7965 (defun gnus-summary-insert-dormant-articles ()
7966   "Insert all the dormant articles for this group into the current buffer."
7967   (interactive)
7968   (let ((gnus-verbose (max 6 gnus-verbose)))
7969     (if (not gnus-newsgroup-dormant)
7970         (gnus-message 3 "No cached articles for this group")
7971       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7972
7973 (defun gnus-summary-limit-include-dormant ()
7974   "Display all the hidden articles that are marked as dormant.
7975 Note that this command only works on a subset of the articles currently
7976 fetched for this group."
7977   (interactive)
7978   (unless gnus-newsgroup-dormant
7979     (error "There are no dormant articles in this group"))
7980   (prog1
7981       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7982     (gnus-summary-position-point)))
7983
7984 (defun gnus-summary-limit-exclude-dormant ()
7985   "Hide all dormant articles."
7986   (interactive)
7987   (prog1
7988       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7989     (gnus-summary-position-point)))
7990
7991 (defun gnus-summary-limit-exclude-childless-dormant ()
7992   "Hide all dormant articles that have no children."
7993   (interactive)
7994   (let ((data (gnus-data-list t))
7995         articles d children)
7996     ;; Find all articles that are either not dormant or have
7997     ;; children.
7998     (while (setq d (pop data))
7999       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8000                 (and (setq children
8001                            (gnus-article-children (gnus-data-number d)))
8002                      (let (found)
8003                        (while children
8004                          (when (memq (car children) articles)
8005                            (setq children nil
8006                                  found t))
8007                          (pop children))
8008                        found)))
8009         (push (gnus-data-number d) articles)))
8010     ;; Do the limiting.
8011     (prog1
8012         (gnus-summary-limit articles)
8013       (gnus-summary-position-point))))
8014
8015 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8016   "Mark all unread excluded articles as read.
8017 If ALL, mark even excluded ticked and dormants as read."
8018   (interactive "P")
8019   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8020   (let ((articles (gnus-sorted-ndifference
8021                    (sort
8022                     (mapcar (lambda (h) (mail-header-number h))
8023                             gnus-newsgroup-headers)
8024                     '<)
8025                    gnus-newsgroup-limit))
8026         article)
8027     (setq gnus-newsgroup-unreads
8028           (gnus-sorted-intersection gnus-newsgroup-unreads
8029                                     gnus-newsgroup-limit))
8030     (if all
8031         (setq gnus-newsgroup-dormant nil
8032               gnus-newsgroup-marked nil
8033               gnus-newsgroup-reads
8034               (nconc
8035                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8036                gnus-newsgroup-reads))
8037       (while (setq article (pop articles))
8038         (unless (or (memq article gnus-newsgroup-dormant)
8039                     (memq article gnus-newsgroup-marked))
8040           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8041
8042 (defun gnus-summary-limit (articles &optional pop)
8043   (if pop
8044       ;; We pop the previous limit off the stack and use that.
8045       (setq articles (car gnus-newsgroup-limits)
8046             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8047     ;; We use the new limit, so we push the old limit on the stack.
8048     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8049   ;; Set the limit.
8050   (setq gnus-newsgroup-limit articles)
8051   (let ((total (length gnus-newsgroup-data))
8052         (data (gnus-data-find-list (gnus-summary-article-number)))
8053         (gnus-summary-mark-below nil)   ; Inhibit this.
8054         found)
8055     ;; This will do all the work of generating the new summary buffer
8056     ;; according to the new limit.
8057     (gnus-summary-prepare)
8058     ;; Hide any threads, possibly.
8059     (gnus-summary-maybe-hide-threads)
8060     ;; Try to return to the article you were at, or one in the
8061     ;; neighborhood.
8062     (when data
8063       ;; We try to find some article after the current one.
8064       (while data
8065         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8066           (setq data nil
8067                 found t))
8068         (setq data (cdr data))))
8069     (unless found
8070       ;; If there is no data, that means that we were after the last
8071       ;; article.  The same goes when we can't find any articles
8072       ;; after the current one.
8073       (goto-char (point-max))
8074       (gnus-summary-find-prev))
8075     (gnus-set-mode-line 'summary)
8076     ;; We return how many articles were removed from the summary
8077     ;; buffer as a result of the new limit.
8078     (- total (length gnus-newsgroup-data))))
8079
8080 (defsubst gnus-invisible-cut-children (threads)
8081   (let ((num 0))
8082     (while threads
8083       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8084         (incf num))
8085       (pop threads))
8086     (< num 2)))
8087
8088 (defsubst gnus-cut-thread (thread)
8089   "Go forwards in the thread until we find an article that we want to display."
8090   (when (or (eq gnus-fetch-old-headers 'some)
8091             (eq gnus-fetch-old-headers 'invisible)
8092             (numberp gnus-fetch-old-headers)
8093             (eq gnus-build-sparse-threads 'some)
8094             (eq gnus-build-sparse-threads 'more))
8095     ;; Deal with old-fetched headers and sparse threads.
8096     (while (and
8097             thread
8098             (or
8099              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8100              (gnus-summary-article-ancient-p
8101               (mail-header-number (car thread))))
8102             (if (or (<= (length (cdr thread)) 1)
8103                     (eq gnus-fetch-old-headers 'invisible))
8104                 (setq gnus-newsgroup-limit
8105                       (delq (mail-header-number (car thread))
8106                             gnus-newsgroup-limit)
8107                       thread (cadr thread))
8108               (when (gnus-invisible-cut-children (cdr thread))
8109                 (let ((th (cdr thread)))
8110                   (while th
8111                     (if (memq (mail-header-number (caar th))
8112                               gnus-newsgroup-limit)
8113                         (setq thread (car th)
8114                               th nil)
8115                       (setq th (cdr th))))))))))
8116   thread)
8117
8118 (defun gnus-cut-threads (threads)
8119   "Cut off all uninteresting articles from the beginning of THREADS."
8120   (when (or (eq gnus-fetch-old-headers 'some)
8121             (eq gnus-fetch-old-headers 'invisible)
8122             (numberp gnus-fetch-old-headers)
8123             (eq gnus-build-sparse-threads 'some)
8124             (eq gnus-build-sparse-threads 'more))
8125     (let ((th threads))
8126       (while th
8127         (setcar th (gnus-cut-thread (car th)))
8128         (setq th (cdr th)))))
8129   ;; Remove nixed out threads.
8130   (delq nil threads))
8131
8132 (defun gnus-summary-initial-limit (&optional show-if-empty)
8133   "Figure out what the initial limit is supposed to be on group entry.
8134 This entails weeding out unwanted dormants, low-scored articles,
8135 fetch-old-headers verbiage, and so on."
8136   ;; Most groups have nothing to remove.
8137   (if (or gnus-inhibit-limiting
8138           (and (null gnus-newsgroup-dormant)
8139                (eq gnus-newsgroup-display 'gnus-not-ignore)
8140                (not (eq gnus-fetch-old-headers 'some))
8141                (not (numberp gnus-fetch-old-headers))
8142                (not (eq gnus-fetch-old-headers 'invisible))
8143                (null gnus-summary-expunge-below)
8144                (not (eq gnus-build-sparse-threads 'some))
8145                (not (eq gnus-build-sparse-threads 'more))
8146                (null gnus-thread-expunge-below)
8147                (not gnus-use-nocem)))
8148       ()                                ; Do nothing.
8149     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8150     (setq gnus-newsgroup-limit nil)
8151     (mapatoms
8152      (lambda (node)
8153        (unless (car (symbol-value node))
8154          ;; These threads have no parents -- they are roots.
8155          (let ((nodes (cdr (symbol-value node)))
8156                thread)
8157            (while nodes
8158              (if (and gnus-thread-expunge-below
8159                       (< (gnus-thread-total-score (car nodes))
8160                          gnus-thread-expunge-below))
8161                  (gnus-expunge-thread (pop nodes))
8162                (setq thread (pop nodes))
8163                (gnus-summary-limit-children thread))))))
8164      gnus-newsgroup-dependencies)
8165     ;; If this limitation resulted in an empty group, we might
8166     ;; pop the previous limit and use it instead.
8167     (when (and (not gnus-newsgroup-limit)
8168                show-if-empty)
8169       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8170     gnus-newsgroup-limit))
8171
8172 (defun gnus-summary-limit-children (thread)
8173   "Return 1 if this subthread is visible and 0 if it is not."
8174   ;; First we get the number of visible children to this thread.  This
8175   ;; is done by recursing down the thread using this function, so this
8176   ;; will really go down to a leaf article first, before slowly
8177   ;; working its way up towards the root.
8178   (when thread
8179     (let* ((max-lisp-eval-depth 5000)
8180            (children
8181            (if (cdr thread)
8182                (apply '+ (mapcar 'gnus-summary-limit-children
8183                                  (cdr thread)))
8184              0))
8185           (number (mail-header-number (car thread)))
8186           score)
8187       (if (and
8188            (not (memq number gnus-newsgroup-marked))
8189            (or
8190             ;; If this article is dormant and has absolutely no visible
8191             ;; children, then this article isn't visible.
8192             (and (memq number gnus-newsgroup-dormant)
8193                  (zerop children))
8194             ;; If this is "fetch-old-headered" and there is no
8195             ;; visible children, then we don't want this article.
8196             (and (or (eq gnus-fetch-old-headers 'some)
8197                      (numberp gnus-fetch-old-headers))
8198                  (gnus-summary-article-ancient-p number)
8199                  (zerop children))
8200             ;; If this is "fetch-old-headered" and `invisible', then
8201             ;; we don't want this article.
8202             (and (eq gnus-fetch-old-headers 'invisible)
8203                  (gnus-summary-article-ancient-p number))
8204             ;; If this is a sparsely inserted article with no children,
8205             ;; we don't want it.
8206             (and (eq gnus-build-sparse-threads 'some)
8207                  (gnus-summary-article-sparse-p number)
8208                  (zerop children))
8209             ;; If we use expunging, and this article is really
8210             ;; low-scored, then we don't want this article.
8211             (when (and gnus-summary-expunge-below
8212                        (< (setq score
8213                                 (or (cdr (assq number gnus-newsgroup-scored))
8214                                     gnus-summary-default-score))
8215                           gnus-summary-expunge-below))
8216               ;; We increase the expunge-tally here, but that has
8217               ;; nothing to do with the limits, really.
8218               (incf gnus-newsgroup-expunged-tally)
8219               ;; We also mark as read here, if that's wanted.
8220               (when (and gnus-summary-mark-below
8221                          (< score gnus-summary-mark-below))
8222                 (setq gnus-newsgroup-unreads
8223                       (delq number gnus-newsgroup-unreads))
8224                 (if gnus-newsgroup-auto-expire
8225                     (push number gnus-newsgroup-expirable)
8226                   (push (cons number gnus-low-score-mark)
8227                         gnus-newsgroup-reads)))
8228               t)
8229             ;; Do the `display' group parameter.
8230             (and gnus-newsgroup-display
8231                  (not (funcall gnus-newsgroup-display)))
8232             ;; Check NoCeM things.
8233             (when (and gnus-use-nocem
8234                        (gnus-nocem-unwanted-article-p
8235                         (mail-header-id (car thread))))
8236               (setq gnus-newsgroup-unreads
8237                     (delq number gnus-newsgroup-unreads))
8238               t)))
8239           ;; Nope, invisible article.
8240           0
8241         ;; Ok, this article is to be visible, so we add it to the limit
8242         ;; and return 1.
8243         (push number gnus-newsgroup-limit)
8244         1))))
8245
8246 (defun gnus-expunge-thread (thread)
8247   "Mark all articles in THREAD as read."
8248   (let* ((number (mail-header-number (car thread))))
8249     (incf gnus-newsgroup-expunged-tally)
8250     ;; We also mark as read here, if that's wanted.
8251     (setq gnus-newsgroup-unreads
8252           (delq number gnus-newsgroup-unreads))
8253     (if gnus-newsgroup-auto-expire
8254         (push number gnus-newsgroup-expirable)
8255       (push (cons number gnus-low-score-mark)
8256             gnus-newsgroup-reads)))
8257   ;; Go recursively through all subthreads.
8258   (mapcar 'gnus-expunge-thread (cdr thread)))
8259
8260 ;; Summary article oriented commands
8261
8262 (defun gnus-summary-refer-parent-article (n)
8263   "Refer parent article N times.
8264 If N is negative, go to ancestor -N instead.
8265 The difference between N and the number of articles fetched is returned."
8266   (interactive "p")
8267   (let ((skip 1)
8268         error header ref)
8269     (when (not (natnump n))
8270       (setq skip (abs n)
8271             n 1))
8272     (while (and (> n 0)
8273                 (not error))
8274       (setq header (gnus-summary-article-header))
8275       (if (and (eq (mail-header-number header)
8276                    (cdr gnus-article-current))
8277                (equal gnus-newsgroup-name
8278                       (car gnus-article-current)))
8279           ;; If we try to find the parent of the currently
8280           ;; displayed article, then we take a look at the actual
8281           ;; References header, since this is slightly more
8282           ;; reliable than the References field we got from the
8283           ;; server.
8284           (save-excursion
8285             (set-buffer gnus-original-article-buffer)
8286             (nnheader-narrow-to-headers)
8287             (unless (setq ref (message-fetch-field "references"))
8288               (when (setq ref (message-fetch-field "in-reply-to"))
8289                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8290             (widen))
8291         (setq ref
8292               ;; It's not the current article, so we take a bet on
8293               ;; the value we got from the server.
8294               (mail-header-references header)))
8295       (if (and ref
8296                (not (equal ref "")))
8297           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8298             (gnus-message 1 "Couldn't find parent"))
8299         (gnus-message 1 "No references in article %d"
8300                       (gnus-summary-article-number))
8301         (setq error t))
8302       (decf n))
8303     (gnus-summary-position-point)
8304     n))
8305
8306 (defun gnus-summary-refer-references ()
8307   "Fetch all articles mentioned in the References header.
8308 Return the number of articles fetched."
8309   (interactive)
8310   (let ((ref (mail-header-references (gnus-summary-article-header)))
8311         (current (gnus-summary-article-number))
8312         (n 0))
8313     (if (or (not ref)
8314             (equal ref ""))
8315         (error "No References in the current article")
8316       ;; For each Message-ID in the References header...
8317       (while (string-match "<[^>]*>" ref)
8318         (incf n)
8319         ;; ... fetch that article.
8320         (gnus-summary-refer-article
8321          (prog1 (match-string 0 ref)
8322            (setq ref (substring ref (match-end 0))))))
8323       (gnus-summary-goto-subject current)
8324       (gnus-summary-position-point)
8325       n)))
8326
8327 (defun gnus-summary-refer-thread (&optional limit)
8328   "Fetch all articles in the current thread.
8329 If LIMIT (the numerical prefix), fetch that many old headers instead
8330 of what's specified by the `gnus-refer-thread-limit' variable."
8331   (interactive "P")
8332   (let ((id (mail-header-id (gnus-summary-article-header)))
8333         (limit (if limit (prefix-numeric-value limit)
8334                  gnus-refer-thread-limit)))
8335     (unless (eq gnus-fetch-old-headers 'invisible)
8336       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8337       ;; Retrieve the headers and read them in.
8338       (if (eq (if (numberp limit)
8339                   (gnus-retrieve-headers
8340                    (list (min
8341                           (+ (mail-header-number
8342                               (gnus-summary-article-header))
8343                              limit)
8344                           gnus-newsgroup-end))
8345                    gnus-newsgroup-name (* limit 2))
8346                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8347                 ;; headers.
8348                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8349                                        gnus-newsgroup-name limit))
8350               'nov)
8351           (gnus-build-all-threads)
8352         (error "Can't fetch thread from back ends that don't support NOV"))
8353       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8354     (gnus-summary-limit-include-thread id)))
8355
8356 (defun gnus-summary-refer-article (message-id)
8357   "Fetch an article specified by MESSAGE-ID."
8358   (interactive "sMessage-ID: ")
8359   (when (and (stringp message-id)
8360              (not (zerop (length message-id))))
8361     (setq message-id (gnus-replace-in-string message-id " " ""))
8362     ;; Construct the correct Message-ID if necessary.
8363     ;; Suggested by tale@pawl.rpi.edu.
8364     (unless (string-match "^<" message-id)
8365       (setq message-id (concat "<" message-id)))
8366     (unless (string-match ">$" message-id)
8367       (setq message-id (concat message-id ">")))
8368     ;; People often post MIDs from URLs, so unhex it:
8369     (unless (string-match "@" message-id)
8370       (setq message-id (gnus-url-unhex-string message-id)))
8371     (let* ((header (gnus-id-to-header message-id))
8372            (sparse (and header
8373                         (gnus-summary-article-sparse-p
8374                          (mail-header-number header))
8375                         (memq (mail-header-number header)
8376                               gnus-newsgroup-limit)))
8377            number)
8378       (cond
8379        ;; If the article is present in the buffer we just go to it.
8380        ((and header
8381              (or (not (gnus-summary-article-sparse-p
8382                        (mail-header-number header)))
8383                  sparse))
8384         (prog1
8385             (gnus-summary-goto-article
8386              (mail-header-number header) nil t)
8387           (when sparse
8388             (gnus-summary-update-article (mail-header-number header)))))
8389        (t
8390         ;; We fetch the article.
8391         (catch 'found
8392           (dolist (gnus-override-method (gnus-refer-article-methods))
8393             (when (and (gnus-check-server gnus-override-method)
8394                        ;; Fetch the header,
8395                        (setq number (gnus-summary-insert-subject message-id)))
8396               ;; and display the article.
8397               (gnus-summary-select-article nil nil nil number)
8398               (throw 'found t)))
8399           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8400
8401 (defun gnus-refer-article-methods ()
8402   "Return a list of referable methods."
8403   (cond
8404    ;; No method, so we default to current and native.
8405    ((null gnus-refer-article-method)
8406     (list gnus-current-select-method gnus-select-method))
8407    ;; Current.
8408    ((eq 'current gnus-refer-article-method)
8409     (list gnus-current-select-method))
8410    ;; List of select methods.
8411    ((not (and (symbolp (car gnus-refer-article-method))
8412               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8413     (let (out)
8414       (dolist (method gnus-refer-article-method)
8415         (push (if (eq 'current method)
8416                   gnus-current-select-method
8417                 method)
8418               out))
8419       (nreverse out)))
8420    ;; One single select method.
8421    (t
8422     (list gnus-refer-article-method))))
8423
8424 (defun gnus-summary-edit-parameters ()
8425   "Edit the group parameters of the current group."
8426   (interactive)
8427   (gnus-group-edit-group gnus-newsgroup-name 'params))
8428
8429 (defun gnus-summary-customize-parameters ()
8430   "Customize the group parameters of the current group."
8431   (interactive)
8432   (gnus-group-customize gnus-newsgroup-name))
8433
8434 (defun gnus-summary-enter-digest-group (&optional force)
8435   "Enter an nndoc group based on the current article.
8436 If FORCE, force a digest interpretation.  If not, try
8437 to guess what the document format is."
8438   (interactive "P")
8439   (let ((conf gnus-current-window-configuration))
8440     (save-window-excursion
8441       (save-excursion
8442         (let (gnus-article-prepare-hook
8443               gnus-display-mime-function
8444               gnus-break-pages)
8445           (gnus-summary-select-article))))
8446     (setq gnus-current-window-configuration conf)
8447     (let* ((name (format "%s-%d"
8448                          (gnus-group-prefixed-name
8449                           gnus-newsgroup-name (list 'nndoc ""))
8450                          (with-current-buffer gnus-summary-buffer
8451                            gnus-current-article)))
8452            (ogroup gnus-newsgroup-name)
8453            (params (append (gnus-info-params (gnus-get-info ogroup))
8454                            (list (cons 'to-group ogroup))
8455                            (list (cons 'parent-group ogroup))
8456                            (list (cons 'save-article-group ogroup))))
8457            (case-fold-search t)
8458            (buf (current-buffer))
8459            dig to-address)
8460       (save-excursion
8461         (set-buffer gnus-original-article-buffer)
8462         ;; Have the digest group inherit the main mail address of
8463         ;; the parent article.
8464         (when (setq to-address (or (gnus-fetch-field "reply-to")
8465                                    (gnus-fetch-field "from")))
8466           (setq params (append
8467                         (list (cons 'to-address
8468                                     (funcall gnus-decode-encoded-word-function
8469                                              to-address))))))
8470         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8471         (insert-buffer-substring gnus-original-article-buffer)
8472         ;; Remove lines that may lead nndoc to misinterpret the
8473         ;; document type.
8474         (narrow-to-region
8475          (goto-char (point-min))
8476          (or (search-forward "\n\n" nil t) (point)))
8477         (goto-char (point-min))
8478         (delete-matching-lines "^Path:\\|^From ")
8479         (widen))
8480       (unwind-protect
8481           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8482                     (gnus-newsgroup-ephemeral-ignored-charsets
8483                      gnus-newsgroup-ignored-charsets))
8484                 (gnus-group-read-ephemeral-group
8485                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8486                               (nndoc-article-type
8487                                ,(if force 'mbox 'guess)))
8488                  t nil nil nil
8489                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8490                                                         "ADAPT")))))
8491               ;; Make all postings to this group go to the parent group.
8492               (nconc (gnus-info-params (gnus-get-info name))
8493                      params)
8494             ;; Couldn't select this doc group.
8495             (switch-to-buffer buf)
8496             (gnus-set-global-variables)
8497             (gnus-configure-windows 'summary)
8498             (gnus-message 3 "Article couldn't be entered?"))
8499         (kill-buffer dig)))))
8500
8501 (defun gnus-summary-read-document (n)
8502   "Open a new group based on the current article(s).
8503 This will allow you to read digests and other similar
8504 documents as newsgroups.
8505 Obeys the standard process/prefix convention."
8506   (interactive "P")
8507   (let* ((ogroup gnus-newsgroup-name)
8508          (params (append (gnus-info-params (gnus-get-info ogroup))
8509                          (list (cons 'to-group ogroup))))
8510          group egroup groups vgroup)
8511     (dolist (article (gnus-summary-work-articles n))
8512       (setq group (format "%s-%d" gnus-newsgroup-name article))
8513       (gnus-summary-remove-process-mark article)
8514       (when (gnus-summary-display-article article)
8515         (save-excursion
8516           (with-temp-buffer
8517             (insert-buffer-substring gnus-original-article-buffer)
8518             ;; Remove some headers that may lead nndoc to make
8519             ;; the wrong guess.
8520             (message-narrow-to-head)
8521             (goto-char (point-min))
8522             (delete-matching-lines "^Path:\\|^From ")
8523             (widen)
8524             (if (setq egroup
8525                       (gnus-group-read-ephemeral-group
8526                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8527                                      (nndoc-article-type guess))
8528                        t nil t))
8529                 (progn
8530                   ;; Make all postings to this group go to the parent group.
8531                   (nconc (gnus-info-params (gnus-get-info egroup))
8532                          params)
8533                   (push egroup groups))
8534               ;; Couldn't select this doc group.
8535               (gnus-error 3 "Article couldn't be entered"))))))
8536     ;; Now we have selected all the documents.
8537     (cond
8538      ((not groups)
8539       (error "None of the articles could be interpreted as documents"))
8540      ((gnus-group-read-ephemeral-group
8541        (setq vgroup (format
8542                      "nnvirtual:%s-%s" gnus-newsgroup-name
8543                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8544        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8545        t
8546        (cons (current-buffer) 'summary)))
8547      (t
8548       (error "Couldn't select virtual nndoc group")))))
8549
8550 (defun gnus-summary-isearch-article (&optional regexp-p)
8551   "Do incremental search forward on the current article.
8552 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8553   (interactive "P")
8554   (let* ((gnus-inhibit-treatment t)
8555          (old (gnus-summary-select-article)))
8556     (gnus-configure-windows 'article)
8557     (gnus-eval-in-buffer-window gnus-article-buffer
8558       (save-restriction
8559         (widen)
8560         (when (eq 'old old)
8561           (gnus-article-show-all-headers))
8562         (goto-char (point-min))
8563         (isearch-forward regexp-p)))))
8564
8565 (defun gnus-summary-search-article-forward (regexp &optional backward)
8566   "Search for an article containing REGEXP forward.
8567 If BACKWARD, search backward instead."
8568   (interactive
8569    (list (read-string
8570           (format "Search article %s (regexp%s): "
8571                   (if current-prefix-arg "backward" "forward")
8572                   (if gnus-last-search-regexp
8573                       (concat ", default " gnus-last-search-regexp)
8574                     "")))
8575          current-prefix-arg))
8576   (if (string-equal regexp "")
8577       (setq regexp (or gnus-last-search-regexp ""))
8578     (setq gnus-last-search-regexp regexp)
8579     (setq gnus-article-before-search gnus-current-article))
8580   ;; Intentionally set gnus-last-article.
8581   (setq gnus-last-article gnus-article-before-search)
8582   (let ((gnus-last-article gnus-last-article))
8583     (if (gnus-summary-search-article regexp backward)
8584         (gnus-summary-show-thread)
8585       (signal 'search-failed (list regexp)))))
8586
8587 (defun gnus-summary-search-article-backward (regexp)
8588   "Search for an article containing REGEXP backward."
8589   (interactive
8590    (list (read-string
8591           (format "Search article backward (regexp%s): "
8592                   (if gnus-last-search-regexp
8593                       (concat ", default " gnus-last-search-regexp)
8594                     "")))))
8595   (gnus-summary-search-article-forward regexp 'backward))
8596
8597 (eval-when-compile
8598   (defmacro gnus-summary-search-article-position-point (regexp backward)
8599     "Dehighlight the last matched text and goto the beginning position."
8600     (` (if (and gnus-summary-search-article-matched-data
8601                 (let ((text (caddr gnus-summary-search-article-matched-data))
8602                       (inhibit-read-only t)
8603                       buffer-read-only)
8604                   (delete-region
8605                    (goto-char (car gnus-summary-search-article-matched-data))
8606                    (cadr gnus-summary-search-article-matched-data))
8607                   (insert text)
8608                   (string-match (, regexp) text)))
8609            (if (, backward) (beginning-of-line) (end-of-line))
8610          (goto-char (if (, backward) (point-max) (point-min))))))
8611
8612   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8613     "Place point where X-Face image is displayed."
8614     (if (featurep 'xemacs)
8615         (` (let ((end (if (search-forward "\n\n" nil t)
8616                           (goto-char (1- (point)))
8617                         (point-min)))
8618                  extent)
8619              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8620              (unless (and (re-search-forward "^From:" end t)
8621                           (setq extent (extent-at (point)))
8622                           (extent-begin-glyph extent))
8623                (goto-char (, opoint)))))
8624       (` (let ((end (if (search-forward "\n\n" nil t)
8625                         (goto-char (1- (point)))
8626                       (point-min)))
8627                (start (or (search-backward "\n\n" nil t) (point-min))))
8628            (goto-char
8629             (or (text-property-any start end 'x-face-image t);; x-face-e21
8630                 (, opoint)))))))
8631
8632   (defmacro gnus-summary-search-article-highlight-matched-text
8633     (backward treated x-face)
8634     "Highlight matched text in the function `gnus-summary-search-article'."
8635     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8636              (end (set-marker (make-marker) (match-end 0)))
8637              (inhibit-read-only t)
8638              buffer-read-only)
8639          (unless treated
8640            (let ((,@
8641                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8642                     (mapcar
8643                      (lambda (item) (setq items (delq item items)))
8644                      '(gnus-treat-buttonize
8645                        gnus-treat-fill-article
8646                        gnus-treat-fill-long-lines
8647                        gnus-treat-emphasize
8648                        gnus-treat-highlight-headers
8649                        gnus-treat-highlight-citation
8650                        gnus-treat-highlight-signature
8651                        gnus-treat-overstrike
8652                        gnus-treat-display-x-face
8653                        gnus-treat-buttonize-head
8654                        gnus-treat-decode-article-as-default-mime-charset))
8655                     items))
8656                  (gnus-treat-display-x-face
8657                   (when (, x-face) gnus-treat-display-x-face)))
8658              (gnus-article-prepare-mime-display)))
8659          (goto-char (if (, backward) start end))
8660          (when (, x-face)
8661            (gnus-summary-search-article-highlight-goto-x-face (point)))
8662          (setq gnus-summary-search-article-matched-data
8663                (list start end (buffer-substring start end)))
8664          (unless (eq start end);; matched text has been deleted. :-<
8665            (put-text-property start end 'face
8666                               (or (find-face 'isearch)
8667                                   'secondary-selection))))))
8668   )
8669
8670 (defun gnus-summary-search-article (regexp &optional backward)
8671   "Search for an article containing REGEXP.
8672 Optional argument BACKWARD means do search for backward.
8673 `gnus-select-article-hook' is not called during the search."
8674   ;; We have to require this here to make sure that the following
8675   ;; dynamic binding isn't shadowed by autoloading.
8676   (require 'gnus-async)
8677   (require 'gnus-art)
8678   (let ((gnus-select-article-hook nil)  ;Disable hook.
8679         (gnus-article-prepare-hook nil)
8680         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8681         (gnus-use-article-prefetch nil)
8682         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8683         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8684         (gnus-visual nil)
8685         (gnus-keep-backlog nil)
8686         (gnus-break-pages nil)
8687         (gnus-summary-display-arrow nil)
8688         (gnus-updated-mode-lines nil)
8689         (gnus-auto-center-summary nil)
8690         (sum (current-buffer))
8691         (found nil)
8692         point treated)
8693     (gnus-save-hidden-threads
8694       (static-if (featurep 'xemacs)
8695           (let ((gnus-inhibit-treatment t))
8696             (setq treated (eq 'old (gnus-summary-select-article)))
8697             (when (and treated
8698                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8699                                  (window-live-p (get-buffer-window
8700                                                  gnus-article-buffer t)))))
8701               (gnus-summary-select-article nil t)
8702               (setq treated nil)))
8703         (let ((gnus-inhibit-treatment t))
8704           (setq treated (eq 'old (gnus-summary-select-article)))
8705           (when (and treated
8706                      (not
8707                       (and (gnus-buffer-live-p gnus-article-buffer)
8708                            (window-live-p (get-buffer-window
8709                                            gnus-article-buffer t))
8710                            (or (not (string-match "^\\^X-Face:" regexp))
8711                                (with-current-buffer gnus-article-buffer
8712                                  gnus-summary-search-article-matched-data)))))
8713             (gnus-summary-select-article nil t)
8714             (setq treated nil))))
8715       (set-buffer gnus-article-buffer)
8716       (widen)
8717       (if treated
8718           (progn
8719             (gnus-article-show-all-headers)
8720             (gnus-summary-search-article-position-point regexp backward))
8721         (goto-char (if backward (point-max) (point-min))))
8722       (while (not found)
8723         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8724         (if (if backward
8725                 (re-search-backward regexp nil t)
8726               (re-search-forward regexp nil t))
8727             ;; We found the regexp.
8728             (progn
8729               (gnus-summary-search-article-highlight-matched-text
8730                backward treated (string-match "^\\^X-Face:" regexp))
8731               (setq found 'found)
8732               (forward-line
8733                (/ (- 2 (window-height
8734                         (get-buffer-window gnus-article-buffer t)))
8735                   2))
8736               (set-window-start
8737                (get-buffer-window (current-buffer))
8738                (point))
8739               (set-buffer sum)
8740               (setq point (point)))
8741           ;; We didn't find it, so we go to the next article.
8742           (set-buffer sum)
8743           (setq found 'not)
8744           (while (eq found 'not)
8745             (if (not (if backward (gnus-summary-find-prev)
8746                        (gnus-summary-find-next)))
8747                 ;; No more articles.
8748                 (setq found t)
8749               ;; Select the next article and adjust point.
8750               (unless (gnus-summary-article-sparse-p
8751                        (gnus-summary-article-number))
8752                 (setq found nil)
8753                 (let ((gnus-inhibit-treatment t))
8754                   (gnus-summary-select-article))
8755                 (setq treated nil)
8756                 (set-buffer gnus-article-buffer)
8757                 (widen)
8758                 (goto-char (if backward (point-max) (point-min))))))))
8759       (gnus-message 7 ""))
8760     ;; Return whether we found the regexp.
8761     (when (eq found 'found)
8762       (goto-char point)
8763       (gnus-summary-show-thread)
8764       (gnus-summary-goto-subject gnus-current-article)
8765       (gnus-summary-position-point)
8766       t)))
8767
8768 (defun gnus-find-matching-articles (header regexp)
8769   "Return a list of all articles that match REGEXP on HEADER.
8770 This search includes all articles in the current group that Gnus has
8771 fetched headers for, whether they are displayed or not."
8772   (let ((articles nil)
8773         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8774         (case-fold-search t))
8775     (dolist (header gnus-newsgroup-headers)
8776       (when (string-match regexp (funcall func header))
8777         (push (mail-header-number header) articles)))
8778     (nreverse articles)))
8779
8780 (defun gnus-summary-find-matching (header regexp &optional backward unread
8781                                           not-case-fold not-matching)
8782   "Return a list of all articles that match REGEXP on HEADER.
8783 The search stars on the current article and goes forwards unless
8784 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8785 If UNREAD is non-nil, only unread articles will
8786 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8787 in the comparisons. If NOT-MATCHING, return a list of all articles that
8788 not match REGEXP on HEADER."
8789   (let ((case-fold-search (not not-case-fold))
8790         articles d func)
8791     (if (consp header)
8792         (if (eq (car header) 'extra)
8793             (setq func
8794                   `(lambda (h)
8795                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8796                          "")))
8797           (error "%s is an invalid header" header))
8798       (unless (fboundp (intern (concat "mail-header-" header)))
8799         (error "%s is not a valid header" header))
8800       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8801     (dolist (d (if (eq backward 'all)
8802                    gnus-newsgroup-data
8803                  (gnus-data-find-list
8804                   (gnus-summary-article-number)
8805                   (gnus-data-list backward))))
8806       (when (and (or (not unread)       ; We want all articles...
8807                      (gnus-data-unread-p d)) ; Or just unreads.
8808                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8809                  (if not-matching
8810                      (not (string-match
8811                            regexp
8812                            (funcall func (gnus-data-header d))))
8813                    (string-match regexp
8814                                  (funcall func (gnus-data-header d)))))
8815         (push (gnus-data-number d) articles))) ; Success!
8816     (nreverse articles)))
8817
8818 (defun gnus-summary-execute-command (header regexp command &optional backward)
8819   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8820 If HEADER is an empty string (or nil), the match is done on the entire
8821 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8822   (interactive
8823    (list (let ((completion-ignore-case t))
8824            (completing-read
8825             "Header name: "
8826             (mapcar (lambda (header) (list (format "%s" header)))
8827                     (append
8828                      '("Number" "Subject" "From" "Lines" "Date"
8829                        "Message-ID" "Xref" "References" "Body")
8830                      gnus-extra-headers))
8831             nil 'require-match))
8832          (read-string "Regexp: ")
8833          (read-key-sequence "Command: ")
8834          current-prefix-arg))
8835   (when (equal header "Body")
8836     (setq header ""))
8837   ;; Hidden thread subtrees must be searched as well.
8838   (gnus-summary-show-all-threads)
8839   ;; We don't want to change current point nor window configuration.
8840   (save-excursion
8841     (save-window-excursion
8842       (let (gnus-visual
8843             gnus-treat-strip-trailing-blank-lines
8844             gnus-treat-strip-leading-blank-lines
8845             gnus-treat-strip-multiple-blank-lines
8846             gnus-treat-hide-boring-headers
8847             gnus-treat-fold-newsgroups
8848             gnus-article-prepare-hook)
8849         (gnus-message 6 "Executing %s..." (key-description command))
8850         ;; We'd like to execute COMMAND interactively so as to give arguments.
8851         (gnus-execute header regexp
8852                       `(call-interactively ',(key-binding command))
8853                       backward)
8854         (gnus-message 6 "Executing %s...done" (key-description command))))))
8855
8856 (defun gnus-summary-beginning-of-article ()
8857   "Scroll the article back to the beginning."
8858   (interactive)
8859   (gnus-summary-select-article)
8860   (gnus-configure-windows 'article)
8861   (gnus-eval-in-buffer-window gnus-article-buffer
8862     (widen)
8863     (goto-char (point-min))
8864     (when gnus-break-pages
8865       (gnus-narrow-to-page))))
8866
8867 (defun gnus-summary-end-of-article ()
8868   "Scroll to the end of the article."
8869   (interactive)
8870   (gnus-summary-select-article)
8871   (gnus-configure-windows 'article)
8872   (gnus-eval-in-buffer-window gnus-article-buffer
8873     (widen)
8874     (goto-char (point-max))
8875     (recenter -3)
8876     (when gnus-break-pages
8877       (when (re-search-backward page-delimiter nil t)
8878         (narrow-to-region (match-end 0) (point-max)))
8879       (gnus-narrow-to-page))))
8880
8881 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8882   "Truncate to LEN and quote all \"(\"'s in STRING."
8883   (gnus-replace-in-string (if (and len (> (length string) len))
8884                               (substring string 0 len)
8885                             string)
8886                           "[()]" "\\\\\\&"))
8887
8888 (defun gnus-summary-print-article (&optional filename n)
8889   "Generate and print a PostScript image of the process-marked (mail) articles.
8890
8891 If used interactively, print the current article if none are
8892 process-marked.  With prefix arg, prompt the user for the name of the
8893 file to save in.
8894
8895 When used from Lisp, accept two optional args FILENAME and N.  N means
8896 to print the next N articles.  If N is negative, print the N previous
8897 articles.  If N is nil and articles have been marked with the process
8898 mark, print these instead.
8899
8900 If the optional first argument FILENAME is nil, send the image to the
8901 printer.  If FILENAME is a string, save the PostScript image in a file with
8902 that name.  If FILENAME is a number, prompt the user for the name of the file
8903 to save in."
8904   (interactive (list (ps-print-preprint current-prefix-arg)))
8905   (dolist (article (gnus-summary-work-articles n))
8906     (gnus-summary-select-article nil nil 'pseudo article)
8907     (gnus-eval-in-buffer-window gnus-article-buffer
8908       (gnus-print-buffer))
8909     (gnus-summary-remove-process-mark article))
8910   (ps-despool filename))
8911
8912 (defun gnus-print-buffer ()
8913   (let ((buffer (generate-new-buffer " *print*")))
8914     (unwind-protect
8915         (progn
8916           (copy-to-buffer buffer (point-min) (point-max))
8917           (set-buffer buffer)
8918           (gnus-remove-text-with-property 'gnus-decoration)
8919           (when (gnus-visual-p 'article-highlight 'highlight)
8920             ;; Copy-to-buffer doesn't copy overlay.  So redo
8921             ;; highlight.
8922             (let ((gnus-article-buffer buffer))
8923               (gnus-article-highlight-citation t)
8924               (gnus-article-highlight-signature)
8925               (gnus-article-emphasize)
8926               (gnus-article-delete-invisible-text)))
8927           (let ((ps-left-header
8928                  (list
8929                   (concat "("
8930                           (gnus-summary-print-truncate-and-quote
8931                            (mail-header-subject gnus-current-headers)
8932                            66) ")")
8933                   (concat "("
8934                           (gnus-summary-print-truncate-and-quote
8935                            (mail-header-from gnus-current-headers)
8936                            45) ")")))
8937                 (ps-right-header
8938                  (list
8939                   "/pagenumberstring load"
8940                   (concat "("
8941                           (mail-header-date gnus-current-headers) ")"))))
8942             (gnus-run-hooks 'gnus-ps-print-hook)
8943             (save-excursion
8944               (if window-system
8945                   (ps-spool-buffer-with-faces)
8946                 (ps-spool-buffer)))))
8947       (kill-buffer buffer))))
8948
8949 (defun gnus-summary-show-article (&optional arg)
8950   "Force redisplaying of the current article.
8951 If ARG (the prefix) is a number, show the article with the charset
8952 defined in `gnus-summary-show-article-charset-alist', or the charset
8953 input.
8954 If ARG (the prefix) is non-nil and not a number, show the raw article
8955 without any article massaging functions being run.  Normally, the key
8956 strokes are `C-u g'."
8957   (interactive "P")
8958   (cond
8959    ((numberp arg)
8960     (gnus-summary-show-article t)
8961     (let* ((gnus-newsgroup-charset
8962             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8963                 (mm-read-coding-system
8964                  "View as charset: " ;; actually it is coding system.
8965                  (with-current-buffer gnus-article-buffer
8966                    (mm-detect-coding-region (point) (point-max))))))
8967            (default-mime-charset gnus-newsgroup-charset)
8968            (gnus-newsgroup-ignored-charsets 'gnus-all))
8969       (gnus-summary-select-article nil 'force)
8970       (let ((deps gnus-newsgroup-dependencies)
8971             head header lines)
8972         (save-excursion
8973           (set-buffer gnus-original-article-buffer)
8974           (save-restriction
8975             (message-narrow-to-head)
8976             (setq head (buffer-string))
8977             (goto-char (point-min))
8978             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8979               (goto-char (point-max))
8980               (widen)
8981               (setq lines (1- (count-lines (point) (point-max))))))
8982           (with-temp-buffer
8983             (insert (format "211 %d Article retrieved.\n"
8984                             (cdr gnus-article-current)))
8985             (insert head)
8986             (if lines (insert (format "Lines: %d\n" lines)))
8987             (insert ".\n")
8988             (let ((nntp-server-buffer (current-buffer)))
8989               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8990         (gnus-data-set-header
8991          (gnus-data-find (cdr gnus-article-current))
8992          header)
8993         (gnus-summary-update-article-line
8994          (cdr gnus-article-current) header)
8995         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8996           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8997    ((not arg)
8998     ;; Select the article the normal way.
8999     (gnus-summary-select-article nil 'force))
9000    (t
9001     ;; We have to require this here to make sure that the following
9002     ;; dynamic binding isn't shadowed by autoloading.
9003     (require 'gnus-async)
9004     (require 'gnus-art)
9005     ;; Bind the article treatment functions to nil.
9006     (let ((gnus-have-all-headers t)
9007           gnus-article-prepare-hook
9008           gnus-article-decode-hook
9009           gnus-break-pages
9010           gnus-show-mime
9011           (gnus-inhibit-treatment t))
9012       (gnus-summary-select-article nil 'force))))
9013   (gnus-summary-goto-subject gnus-current-article)
9014   (gnus-summary-position-point))
9015
9016 (defun gnus-summary-show-raw-article ()
9017   "Show the raw article without any article massaging functions being run."
9018   (interactive)
9019   (gnus-summary-show-article t))
9020
9021 (defun gnus-summary-verbose-headers (&optional arg)
9022   "Toggle permanent full header display.
9023 If ARG is a positive number, turn header display on.
9024 If ARG is a negative number, turn header display off."
9025   (interactive "P")
9026   (setq gnus-show-all-headers
9027         (cond ((or (not (numberp arg))
9028                    (zerop arg))
9029                (not gnus-show-all-headers))
9030               ((natnump arg)
9031                t)))
9032   (gnus-summary-show-article))
9033
9034 (defun gnus-summary-toggle-header (&optional arg)
9035   "Show the headers if they are hidden, or hide them if they are shown.
9036 If ARG is a positive number, show the entire header.
9037 If ARG is a negative number, hide the unwanted header lines."
9038   (interactive "P")
9039   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9040                      (get-buffer-window gnus-article-buffer t))))
9041     (with-current-buffer gnus-article-buffer
9042       (widen)
9043       (article-narrow-to-head)
9044       (let* ((buffer-read-only nil)
9045              (inhibit-point-motion-hooks t)
9046              (hidden (if (numberp arg)
9047                          (>= arg 0)
9048                        (or (not (looking-at "[^ \t\n]+:"))
9049                            (gnus-article-hidden-text-p 'headers))))
9050              s e)
9051         (delete-region (point-min) (point-max))
9052         (with-current-buffer gnus-original-article-buffer
9053           (goto-char (setq s (point-min)))
9054           (setq e (if (search-forward "\n\n" nil t)
9055                       (1- (point))
9056                     (point-max))))
9057         (insert-buffer-substring gnus-original-article-buffer s e)
9058         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9059         ;; article-decode-encoded-words by default.
9060         (article-decode-encoded-words)
9061         (run-hooks 'gnus-article-decode-hook)
9062         (if hidden
9063             (let ((gnus-treat-hide-headers nil)
9064                   (gnus-treat-hide-boring-headers nil))
9065               (gnus-delete-wash-type 'headers)
9066               (gnus-treat-article 'head))
9067           (gnus-treat-article 'head))
9068         (widen)
9069         (if window
9070             (set-window-start window (goto-char (point-min))))
9071         (if gnus-break-pages
9072             (gnus-narrow-to-page)
9073           (when (gnus-visual-p 'page-marker)
9074             (let ((buffer-read-only nil))
9075               (gnus-remove-text-with-property 'gnus-prev)
9076               (gnus-remove-text-with-property 'gnus-next))))
9077         (gnus-set-mode-line 'article)))))
9078
9079 (defun gnus-summary-show-all-headers ()
9080   "Make all header lines visible."
9081   (interactive)
9082   (gnus-summary-toggle-header 1))
9083
9084 (defun gnus-summary-toggle-mime (&optional arg)
9085   "Toggle MIME processing.
9086 If ARG is a positive number, turn MIME processing on."
9087   (interactive "P")
9088   (setq gnus-show-mime
9089         (if (null arg)
9090             (not gnus-show-mime)
9091           (> (prefix-numeric-value arg) 0)))
9092   (gnus-summary-select-article t 'force))
9093
9094 (defun gnus-summary-caesar-message (&optional arg)
9095   "Caesar rotate the current article by 13.
9096 The numerical prefix specifies how many places to rotate each letter
9097 forward."
9098   (interactive "P")
9099   (gnus-summary-select-article)
9100   (let ((mail-header-separator ""))
9101     (gnus-eval-in-buffer-window gnus-article-buffer
9102       (save-restriction
9103         (widen)
9104         (let ((start (window-start))
9105               buffer-read-only)
9106           (message-caesar-buffer-body arg)
9107           (set-window-start (get-buffer-window (current-buffer)) start)))))
9108   ;; Create buttons and stuff...
9109   (gnus-treat-article nil))
9110
9111 (defun gnus-summary-idna-message (&optional arg)
9112   "Decode IDNA encoded domain names in the current articles.
9113 IDNA encoded domain names looks like `xn--bar'.  If a string
9114 remain unencoded after running this function, it is likely an
9115 invalid IDNA string (`xn--bar' is invalid).
9116
9117 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9118 installed for this command to work."
9119   (interactive "P")
9120   (if (not (and (condition-case nil (require 'idna)
9121                   (file-error))
9122                 (mm-coding-system-p 'utf-8)
9123                 (executable-find (symbol-value 'idna-program))))
9124       (gnus-message
9125        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9126     (gnus-summary-select-article)
9127     (let ((mail-header-separator ""))
9128       (gnus-eval-in-buffer-window gnus-article-buffer
9129         (save-restriction
9130           (widen)
9131           (let ((start (window-start))
9132                 buffer-read-only)
9133             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9134               (replace-match (idna-to-unicode (match-string 1))))
9135             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9136
9137 (autoload 'unmorse-region "morse"
9138   "Convert morse coded text in region to ordinary ASCII text."
9139   t)
9140
9141 (defun gnus-summary-morse-message (&optional arg)
9142   "Morse decode the current article."
9143   (interactive "P")
9144   (gnus-summary-select-article)
9145   (let ((mail-header-separator ""))
9146     (gnus-eval-in-buffer-window gnus-article-buffer
9147       (save-excursion
9148         (save-restriction
9149           (widen)
9150           (let ((pos (window-start))
9151                 buffer-read-only)
9152             (goto-char (point-min))
9153             (when (message-goto-body)
9154               (gnus-narrow-to-body))
9155             (goto-char (point-min))
9156             (while (search-forward "·" (point-max) t)
9157               (replace-match "."))
9158             (unmorse-region (point-min) (point-max))
9159             (widen)
9160             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9161
9162 (defun gnus-summary-stop-page-breaking ()
9163   "Stop page breaking in the current article."
9164   (interactive)
9165   (gnus-summary-select-article)
9166   (gnus-eval-in-buffer-window gnus-article-buffer
9167     (widen)
9168     (when (gnus-visual-p 'page-marker)
9169       (let ((buffer-read-only nil))
9170         (gnus-remove-text-with-property 'gnus-prev)
9171         (gnus-remove-text-with-property 'gnus-next))
9172       (setq gnus-page-broken nil))))
9173
9174 (defun gnus-summary-move-article (&optional n to-newsgroup
9175                                             select-method action)
9176   "Move the current article to a different newsgroup.
9177 If N is a positive number, move the N next articles.
9178 If N is a negative number, move the N previous articles.
9179 If N is nil and any articles have been marked with the process mark,
9180 move those articles instead.
9181 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9182 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9183 re-spool using this method.
9184
9185 When called interactively with TO-NEWSGROUP being nil, the value of
9186 the variable `gnus-move-split-methods' is used for finding a default
9187 for the target newsgroup.
9188
9189 For this function to work, both the current newsgroup and the
9190 newsgroup that you want to move to have to support the `request-move'
9191 and `request-accept' functions.
9192
9193 ACTION can be either `move' (the default), `crosspost' or `copy'."
9194   (interactive "P")
9195   (unless action
9196     (setq action 'move))
9197   ;; Check whether the source group supports the required functions.
9198   (cond ((and (eq action 'move)
9199               (not (gnus-check-backend-function
9200                     'request-move-article gnus-newsgroup-name)))
9201          (error "The current group does not support article moving"))
9202         ((and (eq action 'crosspost)
9203               (not (gnus-check-backend-function
9204                     'request-replace-article gnus-newsgroup-name)))
9205          (error "The current group does not support article editing")))
9206   (let ((articles (gnus-summary-work-articles n))
9207         (prefix (if (gnus-check-backend-function
9208                      'request-move-article gnus-newsgroup-name)
9209                     (funcall gnus-move-group-prefix-function
9210                              gnus-newsgroup-name)
9211                   ""))
9212         (names '((move "Move" "Moving")
9213                  (copy "Copy" "Copying")
9214                  (crosspost "Crosspost" "Crossposting")))
9215         (copy-buf (save-excursion
9216                     (nnheader-set-temp-buffer " *copy article*")))
9217         art-group to-method new-xref article to-groups articles-to-update-marks)
9218     (unless (assq action names)
9219       (error "Unknown action %s" action))
9220     ;; Read the newsgroup name.
9221     (when (and (not to-newsgroup)
9222                (not select-method))
9223       (if (and gnus-move-split-methods
9224                (not
9225                 (and (memq gnus-current-article articles)
9226                      (gnus-buffer-live-p gnus-original-article-buffer))))
9227           ;; When `gnus-move-split-methods' is non-nil, we have to
9228           ;; select an article to give `gnus-read-move-group-name' an
9229           ;; opportunity to suggest an appropriate default.  However,
9230           ;; we needn't render or mark the article.
9231           (let ((gnus-display-mime-function nil)
9232                 (gnus-article-prepare-hook nil)
9233                 (gnus-mark-article-hook nil))
9234             (gnus-summary-select-article nil nil nil (car articles))))
9235       (setq to-newsgroup
9236             (gnus-read-move-group-name
9237              (cadr (assq action names))
9238              (symbol-value (intern (format "gnus-current-%s-group" action)))
9239              articles prefix))
9240       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9241     (setq to-method (or select-method
9242                         (gnus-server-to-method
9243                          (gnus-group-method to-newsgroup))))
9244     ;; Check the method we are to move this article to...
9245     (unless (gnus-check-backend-function
9246              'request-accept-article (car to-method))
9247       (error "%s does not support article copying" (car to-method)))
9248     (unless (gnus-check-server to-method)
9249       (error "Can't open server %s" (car to-method)))
9250     (gnus-message 6 "%s to %s: %s..."
9251                   (caddr (assq action names))
9252                   (or (car select-method) to-newsgroup) articles)
9253     (while articles
9254       (setq article (pop articles))
9255       (setq
9256        art-group
9257        (cond
9258         ;; Move the article.
9259         ((eq action 'move)
9260          ;; Remove this article from future suppression.
9261          (gnus-dup-unsuppress-article article)
9262          (let* ((from-method (gnus-find-method-for-group
9263                               gnus-newsgroup-name))
9264                 (to-method (gnus-find-method-for-group
9265                             to-newsgroup))
9266                 (move-is-internal (gnus-method-equal from-method to-method)))
9267          (gnus-request-move-article
9268           article                       ; Article to move
9269           gnus-newsgroup-name           ; From newsgroup
9270           (nth 1 (gnus-find-method-for-group
9271                   gnus-newsgroup-name)) ; Server
9272           (list 'gnus-request-accept-article
9273                 to-newsgroup (list 'quote select-method)
9274                 (not articles) t)       ; Accept form
9275           (not articles)                ; Only save nov last time
9276           move-is-internal)))           ; is this move internal?
9277         ;; Copy the article.
9278         ((eq action 'copy)
9279          (save-excursion
9280            (set-buffer copy-buf)
9281            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9282              (save-restriction
9283                (nnheader-narrow-to-headers)
9284                (dolist (hdr gnus-copy-article-ignored-headers)
9285                  (message-remove-header hdr t)))
9286              (gnus-request-accept-article
9287               to-newsgroup select-method (not articles) t))))
9288         ;; Crosspost the article.
9289         ((eq action 'crosspost)
9290          (let ((xref (message-tokenize-header
9291                       (mail-header-xref (gnus-summary-article-header article))
9292                       " ")))
9293            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9294                                   ":" (number-to-string article)))
9295            (unless xref
9296              (setq xref (list (system-name))))
9297            (setq new-xref
9298                  (concat
9299                   (mapconcat 'identity
9300                              (delete "Xref:" (delete new-xref xref))
9301                              " ")
9302                   " " new-xref))
9303            (save-excursion
9304              (set-buffer copy-buf)
9305              ;; First put the article in the destination group.
9306              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9307              (when (consp (setq art-group
9308                                 (gnus-request-accept-article
9309                                  to-newsgroup select-method (not articles))))
9310                (setq new-xref (concat new-xref " " (car art-group)
9311                                       ":"
9312                                       (number-to-string (cdr art-group))))
9313                ;; Now we have the new Xrefs header, so we insert
9314                ;; it and replace the new article.
9315                (nnheader-replace-header "Xref" new-xref)
9316                (gnus-request-replace-article
9317                 (cdr art-group) to-newsgroup (current-buffer))
9318                art-group))))))
9319       (cond
9320        ((not art-group)
9321         (gnus-message 1 "Couldn't %s article %s: %s"
9322                       (cadr (assq action names)) article
9323                       (nnheader-get-report (car to-method))))
9324        ((eq art-group 'junk)
9325         (when (eq action 'move)
9326           (gnus-summary-mark-article article gnus-canceled-mark)
9327           (gnus-message 4 "Deleted article %s" article)
9328           ;; run the delete hook
9329           (run-hook-with-args 'gnus-summary-article-delete-hook
9330                               action
9331                               (gnus-data-header
9332                                (assoc article (gnus-data-list nil)))
9333                               gnus-newsgroup-name nil
9334                               select-method)))
9335        (t
9336         (let* ((pto-group (gnus-group-prefixed-name
9337                            (car art-group) to-method))
9338                (info (gnus-get-info pto-group))
9339                (to-group (gnus-info-group info))
9340                to-marks)
9341           ;; Update the group that has been moved to.
9342           (when (and info
9343                      (memq action '(move copy)))
9344             (unless (member to-group to-groups)
9345               (push to-group to-groups))
9346
9347             (unless (memq article gnus-newsgroup-unreads)
9348               (push 'read to-marks)
9349               (gnus-info-set-read
9350                info (gnus-add-to-range (gnus-info-read info)
9351                                        (list (cdr art-group)))))
9352
9353             ;; See whether the article is to be put in the cache.
9354             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9355                              gnus-article-mark-lists
9356                            (delete '(expirable . expire)
9357                                    (copy-sequence gnus-article-mark-lists))))
9358                   (to-article (cdr art-group)))
9359
9360               ;; Enter the article into the cache in the new group,
9361               ;; if that is required.
9362               (when gnus-use-cache
9363                 (gnus-cache-possibly-enter-article
9364                  to-group to-article
9365                  (let ((header (copy-sequence
9366                                 (gnus-summary-article-header article))))
9367                    (mail-header-set-number header to-article)
9368                    header)
9369                  (memq article gnus-newsgroup-marked)
9370                  (memq article gnus-newsgroup-dormant)
9371                  (memq article gnus-newsgroup-unreads)))
9372
9373               (when gnus-preserve-marks
9374                 ;; Copy any marks over to the new group.
9375                 (when (and (equal to-group gnus-newsgroup-name)
9376                            (not (memq article gnus-newsgroup-unreads)))
9377                   ;; Mark this article as read in this group.
9378                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9379                   (setcdr (gnus-active to-group) to-article)
9380                   (setcdr gnus-newsgroup-active to-article))
9381
9382                 (while marks
9383                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9384                     (when (memq article (symbol-value
9385                                          (intern (format "gnus-newsgroup-%s"
9386                                                          (caar marks)))))
9387                       (push (cdar marks) to-marks)
9388                       ;; If the other group is the same as this group,
9389                       ;; then we have to add the mark to the list.
9390                       (when (equal to-group gnus-newsgroup-name)
9391                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9392                              (cons to-article
9393                                    (symbol-value
9394                                     (intern (format "gnus-newsgroup-%s"
9395                                                     (caar marks)))))))
9396                       ;; Copy the marks to other group.
9397                       (gnus-add-marked-articles
9398                        to-group (cdar marks) (list to-article) info)))
9399                   (setq marks (cdr marks)))
9400
9401                 (gnus-request-set-mark
9402                  to-group (list (list (list to-article) 'add to-marks))))
9403
9404               (gnus-dribble-enter
9405                (concat "(gnus-group-set-info '"
9406                        (gnus-prin1-to-string (gnus-get-info to-group))
9407                        ")"))))
9408
9409           ;; Update the Xref header in this article to point to
9410           ;; the new crossposted article we have just created.
9411           (when (eq action 'crosspost)
9412             (save-excursion
9413               (set-buffer copy-buf)
9414               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9415               (nnheader-replace-header "Xref" new-xref)
9416               (gnus-request-replace-article
9417                article gnus-newsgroup-name (current-buffer))))
9418
9419           ;; run the move/copy/crosspost/respool hook
9420           (run-hook-with-args 'gnus-summary-article-move-hook
9421                               action
9422                               (gnus-data-header
9423                                (assoc article (gnus-data-list nil)))
9424                               gnus-newsgroup-name
9425                               to-newsgroup
9426                               select-method))
9427
9428         ;;;!!!Why is this necessary?
9429         (set-buffer gnus-summary-buffer)
9430         
9431         (gnus-summary-goto-subject article)
9432         (when (eq action 'move)
9433           (gnus-summary-mark-article article gnus-canceled-mark))))
9434       (push article articles-to-update-marks))
9435
9436     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9437     ;; Re-activate all groups that have been moved to.
9438     (save-excursion
9439       (set-buffer gnus-group-buffer)
9440       (let ((gnus-group-marked to-groups))
9441         (gnus-group-get-new-news-this-group nil t)))
9442     
9443     (gnus-kill-buffer copy-buf)
9444     (gnus-summary-position-point)
9445     (gnus-set-mode-line 'summary)))
9446
9447 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9448   "Copy the current article to some other group.
9449 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9450 When called interactively, if TO-NEWSGROUP is nil, use the value of
9451 the variable `gnus-move-split-methods' for finding a default target
9452 newsgroup.
9453 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9454 re-spool using this method."
9455   (interactive "P")
9456   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9457
9458 (defun gnus-summary-crosspost-article (&optional n)
9459   "Crosspost the current article to some other group."
9460   (interactive "P")
9461   (gnus-summary-move-article n nil nil 'crosspost))
9462
9463 (defcustom gnus-summary-respool-default-method nil
9464   "Default method type for respooling an article.
9465 If nil, use to the current newsgroup method."
9466   :type 'symbol
9467   :group 'gnus-summary-mail)
9468
9469 (defcustom gnus-summary-display-while-building nil
9470   "If non-nil, show and update the summary buffer as it's being built.
9471 If the value is t, update the buffer after every line is inserted.  If
9472 the value is an integer (N), update the display every N lines."
9473   :version "22.1"
9474   :group 'gnus-thread
9475   :type '(choice (const :tag "off" nil)
9476                  number
9477                  (const :tag "frequently" t)))
9478
9479 (defun gnus-summary-respool-article (&optional n method)
9480   "Respool the current article.
9481 The article will be squeezed through the mail spooling process again,
9482 which means that it will be put in some mail newsgroup or other
9483 depending on `nnmail-split-methods'.
9484 If N is a positive number, respool the N next articles.
9485 If N is a negative number, respool the N previous articles.
9486 If N is nil and any articles have been marked with the process mark,
9487 respool those articles instead.
9488
9489 Respooling can be done both from mail groups and \"real\" newsgroups.
9490 In the former case, the articles in question will be moved from the
9491 current group into whatever groups they are destined to.  In the
9492 latter case, they will be copied into the relevant groups."
9493   (interactive
9494    (list current-prefix-arg
9495          (let* ((methods (gnus-methods-using 'respool))
9496                 (methname
9497                  (symbol-name (or gnus-summary-respool-default-method
9498                                   (car (gnus-find-method-for-group
9499                                         gnus-newsgroup-name)))))
9500                 (method
9501                  (gnus-completing-read-with-default
9502                   methname "Backend to use when respooling"
9503                   methods nil t nil 'gnus-mail-method-history))
9504                 ms)
9505            (cond
9506             ((zerop (length (setq ms (gnus-servers-using-backend
9507                                       (intern method)))))
9508              (list (intern method) ""))
9509             ((= 1 (length ms))
9510              (car ms))
9511             (t
9512              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9513                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9514                            ms-alist))))))))
9515   (unless method
9516     (error "No method given for respooling"))
9517   (if (assoc (symbol-name
9518               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9519              (gnus-methods-using 'respool))
9520       (gnus-summary-move-article n nil method)
9521     (gnus-summary-copy-article n nil method)))
9522
9523 (defun gnus-summary-import-article (file &optional edit)
9524   "Import an arbitrary file into a mail newsgroup."
9525   (interactive "fImport file: \nP")
9526   (let ((group gnus-newsgroup-name)
9527         (now (current-time))
9528         atts lines group-art)
9529     (unless (gnus-check-backend-function 'request-accept-article group)
9530       (error "%s does not support article importing" group))
9531     (or (file-readable-p file)
9532         (not (file-regular-p file))
9533         (error "Can't read %s" file))
9534     (save-excursion
9535       (set-buffer (gnus-get-buffer-create " *import file*"))
9536       (erase-buffer)
9537       (nnheader-insert-file-contents file)
9538       (goto-char (point-min))
9539       (if (nnheader-article-p)
9540           (save-restriction
9541             (goto-char (point-min))
9542             (search-forward "\n\n" nil t)
9543             (narrow-to-region (point-min) (1- (point)))
9544             (goto-char (point-min))
9545             (unless (re-search-forward "^date:" nil t)
9546               (goto-char (point-max))
9547               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9548         ;; This doesn't look like an article, so we fudge some headers.
9549         (setq atts (file-attributes file)
9550               lines (count-lines (point-min) (point-max)))
9551         (insert "From: " (read-string "From: ") "\n"
9552                 "Subject: " (read-string "Subject: ") "\n"
9553                 "Date: " (message-make-date (nth 5 atts)) "\n"
9554                 "Message-ID: " (message-make-message-id) "\n"
9555                 "Lines: " (int-to-string lines) "\n"
9556                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9557       (setq group-art (gnus-request-accept-article group nil t))
9558       (kill-buffer (current-buffer)))
9559     (setq gnus-newsgroup-active (gnus-activate-group group))
9560     (forward-line 1)
9561     (gnus-summary-goto-article (cdr group-art) nil t)
9562     (when edit
9563       (gnus-summary-edit-article))))
9564
9565 (defun gnus-summary-create-article ()
9566   "Create an article in a mail newsgroup."
9567   (interactive)
9568   (let ((group gnus-newsgroup-name)
9569         (now (current-time))
9570         group-art)
9571     (unless (gnus-check-backend-function 'request-accept-article group)
9572       (error "%s does not support article importing" group))
9573     (save-excursion
9574       (set-buffer (gnus-get-buffer-create " *import file*"))
9575       (erase-buffer)
9576       (goto-char (point-min))
9577       ;; This doesn't look like an article, so we fudge some headers.
9578       (insert "From: " (read-string "From: ") "\n"
9579               "Subject: " (read-string "Subject: ") "\n"
9580               "Date: " (message-make-date now) "\n"
9581               "Message-ID: " (message-make-message-id) "\n")
9582       (setq group-art (gnus-request-accept-article group nil t))
9583       (kill-buffer (current-buffer)))
9584     (setq gnus-newsgroup-active (gnus-activate-group group))
9585     (forward-line 1)
9586     (gnus-summary-goto-article (cdr group-art) nil t)
9587     (gnus-summary-edit-article)))
9588
9589 (defun gnus-summary-article-posted-p ()
9590   "Say whether the current (mail) article is available from news as well.
9591 This will be the case if the article has both been mailed and posted."
9592   (interactive)
9593   (let ((id (mail-header-references (gnus-summary-article-header)))
9594         (gnus-override-method (car (gnus-refer-article-methods))))
9595     (if (gnus-request-head id "")
9596         (gnus-message 2 "The current message was found on %s"
9597                       gnus-override-method)
9598       (gnus-message 2 "The current message couldn't be found on %s"
9599                     gnus-override-method)
9600       nil)))
9601
9602 (defun gnus-summary-expire-articles (&optional now)
9603   "Expire all articles that are marked as expirable in the current group."
9604   (interactive)
9605   (when (and (not gnus-group-is-exiting-without-update-p)
9606              (gnus-check-backend-function
9607               'request-expire-articles gnus-newsgroup-name))
9608     ;; This backend supports expiry.
9609     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9610            (expirable (if total
9611                           (progn
9612                             ;; We need to update the info for
9613                             ;; this group for `gnus-list-of-read-articles'
9614                             ;; to give us the right answer.
9615                             (gnus-run-hooks 'gnus-exit-group-hook)
9616                             (gnus-summary-update-info)
9617                             (gnus-list-of-read-articles gnus-newsgroup-name))
9618                         (setq gnus-newsgroup-expirable
9619                               (sort gnus-newsgroup-expirable '<))))
9620            (expiry-wait (if now 'immediate
9621                           (gnus-group-find-parameter
9622                            gnus-newsgroup-name 'expiry-wait)))
9623            (nnmail-expiry-target
9624             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9625                 nnmail-expiry-target))
9626            es)
9627       (when expirable
9628         ;; There are expirable articles in this group, so we run them
9629         ;; through the expiry process.
9630         (gnus-message 6 "Expiring articles...")
9631         (unless (gnus-check-group gnus-newsgroup-name)
9632           (error "Can't open server for %s" gnus-newsgroup-name))
9633         ;; The list of articles that weren't expired is returned.
9634         (save-excursion
9635           (if expiry-wait
9636               (let ((nnmail-expiry-wait-function nil)
9637                     (nnmail-expiry-wait expiry-wait))
9638                 (setq es (gnus-request-expire-articles
9639                           expirable gnus-newsgroup-name)))
9640             (setq es (gnus-request-expire-articles
9641                       expirable gnus-newsgroup-name)))
9642           (unless total
9643             (setq gnus-newsgroup-expirable es))
9644           ;; We go through the old list of expirable, and mark all
9645           ;; really expired articles as nonexistent.
9646           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9647             (let ((gnus-use-cache nil))
9648               (dolist (article expirable)
9649                 (when (and (not (memq article es))
9650                            (gnus-data-find article))
9651                   (gnus-summary-mark-article article gnus-canceled-mark)
9652                   (run-hook-with-args 'gnus-summary-article-expire-hook
9653                                       'delete
9654                                       (gnus-data-header
9655                                        (assoc article (gnus-data-list nil)))
9656                                       gnus-newsgroup-name
9657                                       nil
9658                                       nil))))))
9659         (gnus-message 6 "Expiring articles...done")))))
9660
9661 (defun gnus-summary-expire-articles-now ()
9662   "Expunge all expirable articles in the current group.
9663 This means that *all* articles that are marked as expirable will be
9664 deleted forever, right now."
9665   (interactive)
9666   (or gnus-expert-user
9667       (gnus-yes-or-no-p
9668        "Are you really, really, really sure you want to delete all these messages? ")
9669       (error "Phew!"))
9670   (gnus-summary-expire-articles t))
9671
9672 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9673 (defun gnus-summary-delete-article (&optional n)
9674   "Delete the N next (mail) articles.
9675 This command actually deletes articles.  This is not a marking
9676 command.  The article will disappear forever from your life, never to
9677 return.
9678
9679 If N is negative, delete backwards.
9680 If N is nil and articles have been marked with the process mark,
9681 delete these instead.
9682
9683 If `gnus-novice-user' is non-nil you will be asked for
9684 confirmation before the articles are deleted."
9685   (interactive "P")
9686   (unless (gnus-check-backend-function 'request-expire-articles
9687                                        gnus-newsgroup-name)
9688     (error "The current newsgroup does not support article deletion"))
9689   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9690     (error "Couldn't open server"))
9691   ;; Compute the list of articles to delete.
9692   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9693         (nnmail-expiry-target 'delete)
9694         not-deleted)
9695     (if (and gnus-novice-user
9696              (not (gnus-yes-or-no-p
9697                    (format "Do you really want to delete %s forever? "
9698                            (if (> (length articles) 1)
9699                                (format "these %s articles" (length articles))
9700                              "this article")))))
9701         ()
9702       ;; Delete the articles.
9703       (setq not-deleted (gnus-request-expire-articles
9704                          articles gnus-newsgroup-name 'force))
9705       (while articles
9706         (gnus-summary-remove-process-mark (car articles))
9707         ;; The backend might not have been able to delete the article
9708         ;; after all.
9709         (unless (memq (car articles) not-deleted)
9710           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9711         (let* ((article (car articles))
9712                (ghead  (gnus-data-header
9713                                     (assoc article (gnus-data-list nil)))))
9714           (run-hook-with-args 'gnus-summary-article-delete-hook
9715                               'delete ghead gnus-newsgroup-name nil
9716                               nil))
9717         (setq articles (cdr articles)))
9718       (when not-deleted
9719         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9720     (gnus-summary-position-point)
9721     (gnus-set-mode-line 'summary)
9722     not-deleted))
9723
9724 (defun gnus-summary-edit-article (&optional force)
9725   "Edit the current article.
9726 This will have permanent effect only in mail groups.
9727 If FORCE is non-nil, allow editing of articles even in read-only
9728 groups."
9729   (interactive "P")
9730   (save-excursion
9731     (set-buffer gnus-summary-buffer)
9732     (let ((mail-parse-charset gnus-newsgroup-charset)
9733           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9734       (gnus-set-global-variables)
9735       (when (and (not force)
9736                  (gnus-group-read-only-p))
9737         (error "The current newsgroup does not support article editing"))
9738       (gnus-summary-show-article t)
9739       (gnus-article-edit-article
9740        'ignore
9741        `(lambda (no-highlight)
9742           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9743                 (message-options message-options)
9744                 (message-options-set-recipient)
9745                 (mail-parse-ignored-charsets
9746                  ',gnus-newsgroup-ignored-charsets))
9747             (gnus-summary-edit-article-done
9748              ,(or (mail-header-references gnus-current-headers) "")
9749              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9750
9751 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9752
9753 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9754                                                  no-highlight)
9755   "Make edits to the current article permanent."
9756   (interactive)
9757   (save-excursion
9758     ;; The buffer restriction contains the entire article if it exists.
9759     (when (article-goto-body)
9760       (let ((lines (count-lines (point) (point-max)))
9761             (length (- (point-max) (point)))
9762             (case-fold-search t)
9763             (body (copy-marker (point))))
9764         (goto-char (point-min))
9765         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9766           (delete-region (match-beginning 1) (match-end 1))
9767           (insert (number-to-string length)))
9768         (goto-char (point-min))
9769         (when (re-search-forward
9770                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9771           (delete-region (match-beginning 1) (match-end 1))
9772           (insert (number-to-string length)))
9773         (goto-char (point-min))
9774         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9775           (delete-region (match-beginning 1) (match-end 1))
9776           (insert (number-to-string lines))))))
9777   ;; Replace the article.
9778   (let ((buf (current-buffer)))
9779     (with-temp-buffer
9780       (insert-buffer-substring buf)
9781
9782       (if (and (not read-only)
9783                (not (gnus-request-replace-article
9784                      (cdr gnus-article-current) (car gnus-article-current)
9785                      (current-buffer) t)))
9786           (error "Couldn't replace article")
9787         ;; Update the summary buffer.
9788         (if (and references
9789                  (equal (message-tokenize-header references " ")
9790                         (message-tokenize-header
9791                          (or (message-fetch-field "references") "") " ")))
9792             ;; We only have to update this line.
9793             (save-excursion
9794               (save-restriction
9795                 (message-narrow-to-head)
9796                 (let ((head (buffer-substring-no-properties
9797                              (point-min) (point-max)))
9798                       header)
9799                   (with-temp-buffer
9800                     (insert (format "211 %d Article retrieved.\n"
9801                                     (cdr gnus-article-current)))
9802                     (insert head)
9803                     (insert ".\n")
9804                     (let ((nntp-server-buffer (current-buffer)))
9805                       (setq header (car (gnus-get-newsgroup-headers
9806                                          nil t))))
9807                     (save-excursion
9808                       (set-buffer gnus-summary-buffer)
9809                       (gnus-data-set-header
9810                        (gnus-data-find (cdr gnus-article-current))
9811                        header)
9812                       (gnus-summary-update-article-line
9813                        (cdr gnus-article-current) header)
9814                       (if (gnus-summary-goto-subject
9815                            (cdr gnus-article-current) nil t)
9816                           (gnus-summary-update-secondary-mark
9817                            (cdr gnus-article-current))))))))
9818           ;; Update threads.
9819           (set-buffer (or buffer gnus-summary-buffer))
9820           (gnus-summary-update-article (cdr gnus-article-current))
9821           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9822               (gnus-summary-update-secondary-mark
9823                (cdr gnus-article-current))))
9824         ;; Prettify the article buffer again.
9825         (unless no-highlight
9826           (save-excursion
9827             (set-buffer gnus-article-buffer)
9828             ;;;!!! Fix this -- article should be rehighlighted.
9829             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9830             (set-buffer gnus-original-article-buffer)
9831             (gnus-request-article
9832              (cdr gnus-article-current)
9833              (car gnus-article-current) (current-buffer))))
9834         ;; Prettify the summary buffer line.
9835         (when (gnus-visual-p 'summary-highlight 'highlight)
9836           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9837
9838 (defun gnus-summary-edit-wash (key)
9839   "Perform editing command KEY in the article buffer."
9840   (interactive
9841    (list
9842     (progn
9843       (message "%s" (concat (this-command-keys) "- "))
9844       (read-char))))
9845   (message "")
9846   (gnus-summary-edit-article)
9847   (execute-kbd-macro (concat (this-command-keys) key))
9848   (gnus-article-edit-done))
9849
9850 ;;; Respooling
9851
9852 (defun gnus-summary-respool-query (&optional silent trace)
9853   "Query where the respool algorithm would put this article."
9854   (interactive)
9855   (let (gnus-mark-article-hook)
9856     (gnus-summary-select-article)
9857     (save-excursion
9858       (set-buffer gnus-original-article-buffer)
9859       (let ((groups (nnmail-article-group 'identity trace)))
9860         (unless silent
9861           (if groups
9862               (message "This message would go to %s"
9863                        (mapconcat 'car groups ", "))
9864             (message "This message would go to no groups"))
9865           groups)))))
9866
9867 (defun gnus-summary-respool-trace ()
9868   "Trace where the respool algorithm would put this article.
9869 Display a buffer showing all fancy splitting patterns which matched."
9870   (interactive)
9871   (gnus-summary-respool-query nil t))
9872
9873 ;; Summary marking commands.
9874
9875 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9876   "Mark articles which has the same subject as read, and then select the next.
9877 If UNMARK is positive, remove any kind of mark.
9878 If UNMARK is negative, tick articles."
9879   (interactive "P")
9880   (when unmark
9881     (setq unmark (prefix-numeric-value unmark)))
9882   (let ((count
9883          (gnus-summary-mark-same-subject
9884           (gnus-summary-article-subject) unmark)))
9885     ;; Select next unread article.  If auto-select-same mode, should
9886     ;; select the first unread article.
9887     (gnus-summary-next-article t (and gnus-auto-select-same
9888                                       (gnus-summary-article-subject)))
9889     (gnus-message 7 "%d article%s marked as %s"
9890                   count (if (= count 1) " is" "s are")
9891                   (if unmark "unread" "read"))))
9892
9893 (defun gnus-summary-kill-same-subject (&optional unmark)
9894   "Mark articles which has the same subject as read.
9895 If UNMARK is positive, remove any kind of mark.
9896 If UNMARK is negative, tick articles."
9897   (interactive "P")
9898   (when unmark
9899     (setq unmark (prefix-numeric-value unmark)))
9900   (let ((count
9901          (gnus-summary-mark-same-subject
9902           (gnus-summary-article-subject) unmark)))
9903     ;; If marked as read, go to next unread subject.
9904     (when (null unmark)
9905       ;; Go to next unread subject.
9906       (gnus-summary-next-subject 1 t))
9907     (gnus-message 7 "%d articles are marked as %s"
9908                   count (if unmark "unread" "read"))))
9909
9910 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9911   "Mark articles with same SUBJECT as read, and return marked number.
9912 If optional argument UNMARK is positive, remove any kinds of marks.
9913 If optional argument UNMARK is negative, mark articles as unread instead."
9914   (let ((count 1))
9915     (save-excursion
9916       (cond
9917        ((null unmark)                   ; Mark as read.
9918         (while (and
9919                 (progn
9920                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9921                   (gnus-summary-show-thread) t)
9922                 (gnus-summary-find-subject subject))
9923           (setq count (1+ count))))
9924        ((> unmark 0)                    ; Tick.
9925         (while (and
9926                 (progn
9927                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9928                   (gnus-summary-show-thread) t)
9929                 (gnus-summary-find-subject subject))
9930           (setq count (1+ count))))
9931        (t                               ; Mark as unread.
9932         (while (and
9933                 (progn
9934                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9935                   (gnus-summary-show-thread) t)
9936                 (gnus-summary-find-subject subject))
9937           (setq count (1+ count)))))
9938       (gnus-set-mode-line 'summary)
9939       ;; Return the number of marked articles.
9940       count)))
9941
9942 (defun gnus-summary-mark-as-processable (n &optional unmark)
9943   "Set the process mark on the next N articles.
9944 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9945 the process mark instead.  The difference between N and the actual
9946 number of articles marked is returned."
9947   (interactive "P")
9948   (if (and (null n) (gnus-region-active-p))
9949       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9950     (setq n (prefix-numeric-value n))
9951     (let ((backward (< n 0))
9952           (n (abs n)))
9953       (while (and
9954               (> n 0)
9955               (if unmark
9956                   (gnus-summary-remove-process-mark
9957                    (gnus-summary-article-number))
9958                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9959               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9960         (setq n (1- n)))
9961       (when (/= 0 n)
9962         (gnus-message 7 "No more articles"))
9963       (gnus-summary-recenter)
9964       (gnus-summary-position-point)
9965       n)))
9966
9967 (defun gnus-summary-unmark-as-processable (n)
9968   "Remove the process mark from the next N articles.
9969 If N is negative, unmark backward instead.  The difference between N and
9970 the actual number of articles unmarked is returned."
9971   (interactive "P")
9972   (gnus-summary-mark-as-processable n t))
9973
9974 (defun gnus-summary-unmark-all-processable ()
9975   "Remove the process mark from all articles."
9976   (interactive)
9977   (save-excursion
9978     (while gnus-newsgroup-processable
9979       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9980   (gnus-summary-position-point))
9981
9982 (defun gnus-summary-add-mark (article type)
9983   "Mark ARTICLE with a mark of TYPE."
9984   (let ((vtype (car (assq type gnus-article-mark-lists)))
9985         var)
9986     (if (not vtype)
9987         (error "No such mark type: %s" type)
9988       (setq var (intern (format "gnus-newsgroup-%s" type)))
9989       (set var (cons article (symbol-value var)))
9990       (if (memq type '(processable cached replied forwarded recent saved))
9991           (gnus-summary-update-secondary-mark article)
9992         ;;; !!! This is bogus.  We should find out what primary
9993         ;;; !!! mark we want to set.
9994         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9995
9996 (defun gnus-summary-mark-as-expirable (n)
9997   "Mark N articles forward as expirable.
9998 If N is negative, mark backward instead.  The difference between N and
9999 the actual number of articles marked is returned."
10000   (interactive "p")
10001   (gnus-summary-mark-forward n gnus-expirable-mark))
10002
10003 (defun gnus-summary-mark-as-spam (n)
10004   "Mark N articles forward as spam.
10005 If N is negative, mark backward instead.  The difference between N and
10006 the actual number of articles marked is returned."
10007   (interactive "p")
10008   (gnus-summary-mark-forward n gnus-spam-mark))
10009
10010 (defun gnus-summary-mark-article-as-replied (article)
10011   "Mark ARTICLE as replied to and update the summary line.
10012 ARTICLE can also be a list of articles."
10013   (interactive (list (gnus-summary-article-number)))
10014   (let ((articles (if (listp article) article (list article))))
10015     (dolist (article articles)
10016       (unless (numberp article)
10017         (error "%s is not a number" article))
10018       (push article gnus-newsgroup-replied)
10019       (let ((buffer-read-only nil))
10020         (when (gnus-summary-goto-subject article nil t)
10021           (gnus-summary-update-secondary-mark article))))))
10022
10023 (defun gnus-summary-mark-article-as-forwarded (article)
10024   "Mark ARTICLE as forwarded and update the summary line.
10025 ARTICLE can also be a list of articles."
10026   (let ((articles (if (listp article) article (list article))))
10027     (dolist (article articles)
10028       (push article gnus-newsgroup-forwarded)
10029       (let ((buffer-read-only nil))
10030         (when (gnus-summary-goto-subject article nil t)
10031           (gnus-summary-update-secondary-mark article))))))
10032
10033 (defun gnus-summary-set-bookmark (article)
10034   "Set a bookmark in current article."
10035   (interactive (list (gnus-summary-article-number)))
10036   (when (or (not (get-buffer gnus-article-buffer))
10037             (not gnus-current-article)
10038             (not gnus-article-current)
10039             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10040     (error "No current article selected"))
10041   ;; Remove old bookmark, if one exists.
10042   (gnus-pull article gnus-newsgroup-bookmarks)
10043   ;; Set the new bookmark, which is on the form
10044   ;; (article-number . line-number-in-body).
10045   (push
10046    (cons article
10047          (with-current-buffer gnus-article-buffer
10048            (count-lines
10049             (min (point)
10050                  (save-excursion
10051                    (article-goto-body)
10052                    (point)))
10053             (point))))
10054    gnus-newsgroup-bookmarks)
10055   (gnus-message 6 "A bookmark has been added to the current article."))
10056
10057 (defun gnus-summary-remove-bookmark (article)
10058   "Remove the bookmark from the current article."
10059   (interactive (list (gnus-summary-article-number)))
10060   ;; Remove old bookmark, if one exists.
10061   (if (not (assq article gnus-newsgroup-bookmarks))
10062       (gnus-message 6 "No bookmark in current article.")
10063     (gnus-pull article gnus-newsgroup-bookmarks)
10064     (gnus-message 6 "Removed bookmark.")))
10065
10066 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10067 (defun gnus-summary-mark-as-dormant (n)
10068   "Mark N articles forward as dormant.
10069 If N is negative, mark backward instead.  The difference between N and
10070 the actual number of articles marked is returned."
10071   (interactive "p")
10072   (gnus-summary-mark-forward n gnus-dormant-mark))
10073
10074 (defun gnus-summary-set-process-mark (article)
10075   "Set the process mark on ARTICLE and update the summary line."
10076   (setq gnus-newsgroup-processable
10077         (cons article
10078               (delq article gnus-newsgroup-processable)))
10079   (when (gnus-summary-goto-subject article)
10080     (gnus-summary-show-thread)
10081     (gnus-summary-goto-subject article)
10082     (gnus-summary-update-secondary-mark article)))
10083
10084 (defun gnus-summary-remove-process-mark (&rest articles)
10085   "Remove the process mark from ARTICLES and update the summary line."
10086   (dolist (article articles)
10087     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10088     (when (gnus-summary-goto-subject article)
10089       (gnus-summary-show-thread)
10090       (gnus-summary-goto-subject article)
10091       (gnus-summary-update-secondary-mark article))))
10092
10093 (defun gnus-summary-set-saved-mark (article)
10094   "Set the process mark on ARTICLE and update the summary line."
10095   (push article gnus-newsgroup-saved)
10096   (when (gnus-summary-goto-subject article)
10097     (gnus-summary-update-secondary-mark article)))
10098
10099 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10100   "Mark N articles as read forwards.
10101 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10102 The difference between N and the actual number of articles marked is
10103 returned.
10104 If NO-EXPIRE, auto-expiry will be inhibited."
10105   (interactive "p")
10106   (gnus-summary-show-thread)
10107   (let ((backward (< n 0))
10108         (gnus-summary-goto-unread
10109          (and gnus-summary-goto-unread
10110               (not (eq gnus-summary-goto-unread 'never))
10111               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10112                                     gnus-ticked-mark gnus-dormant-mark)))))
10113         (n (abs n))
10114         (mark (or mark gnus-del-mark)))
10115     (while (and (> n 0)
10116                 (gnus-summary-mark-article nil mark no-expire)
10117                 (zerop (gnus-summary-next-subject
10118                         (if backward -1 1)
10119                         (and gnus-summary-goto-unread
10120                              (not (eq gnus-summary-goto-unread 'never)))
10121                         t)))
10122       (setq n (1- n)))
10123     (when (/= 0 n)
10124       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10125     (gnus-summary-recenter)
10126     (gnus-summary-position-point)
10127     (gnus-set-mode-line 'summary)
10128     n))
10129
10130 (defun gnus-summary-mark-article-as-read (mark)
10131   "Mark the current article quickly as read with MARK."
10132   (let ((article (gnus-summary-article-number)))
10133     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10134     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10135     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10136     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10137     (push (cons article mark) gnus-newsgroup-reads)
10138     ;; Possibly remove from cache, if that is used.
10139     (when gnus-use-cache
10140       (gnus-cache-enter-remove-article article))
10141     ;; Allow the backend to change the mark.
10142     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10143     ;; Check for auto-expiry.
10144     (when (and gnus-newsgroup-auto-expire
10145                (memq mark gnus-auto-expirable-marks))
10146       (setq mark gnus-expirable-mark)
10147       ;; Let the backend know about the mark change.
10148       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10149       (push article gnus-newsgroup-expirable))
10150     ;; Set the mark in the buffer.
10151     (gnus-summary-update-mark mark 'unread)
10152     t))
10153
10154 (defun gnus-summary-mark-article-as-unread (mark)
10155   "Mark the current article quickly as unread with MARK."
10156   (let* ((article (gnus-summary-article-number))
10157          (old-mark (gnus-summary-article-mark article)))
10158     ;; Allow the backend to change the mark.
10159     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10160     (if (eq mark old-mark)
10161         t
10162       (if (<= article 0)
10163           (progn
10164             (gnus-error 1 "Can't mark negative article numbers")
10165             nil)
10166         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10167         (setq gnus-newsgroup-spam-marked
10168               (delq article gnus-newsgroup-spam-marked))
10169         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10170         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10171         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10172         (cond ((= mark gnus-ticked-mark)
10173                (setq gnus-newsgroup-marked
10174                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10175                                               article)))
10176               ((= mark gnus-spam-mark)
10177                (setq gnus-newsgroup-spam-marked
10178                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10179                                               article)))
10180               ((= mark gnus-dormant-mark)
10181                (setq gnus-newsgroup-dormant
10182                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10183                                               article)))
10184               (t
10185                (setq gnus-newsgroup-unreads
10186                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10187                                               article))))
10188         (gnus-pull article gnus-newsgroup-reads)
10189
10190         ;; See whether the article is to be put in the cache.
10191         (and gnus-use-cache
10192              (vectorp (gnus-summary-article-header article))
10193              (save-excursion
10194                (gnus-cache-possibly-enter-article
10195                 gnus-newsgroup-name article
10196                 (gnus-summary-article-header article)
10197                 (= mark gnus-ticked-mark)
10198                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10199
10200         ;; Fix the mark.
10201         (gnus-summary-update-mark mark 'unread)
10202         t))))
10203
10204 (defun gnus-summary-mark-article (&optional article mark no-expire)
10205   "Mark ARTICLE with MARK.  MARK can be any character.
10206 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10207 `??' (dormant) and `?E' (expirable).
10208 If MARK is nil, then the default character `?r' is used.
10209 If ARTICLE is nil, then the article on the current line will be
10210 marked.
10211 If NO-EXPIRE, auto-expiry will be inhibited."
10212   ;; The mark might be a string.
10213   (when (stringp mark)
10214     (setq mark (aref mark 0)))
10215   ;; If no mark is given, then we check auto-expiring.
10216   (when (null mark)
10217     (setq mark gnus-del-mark))
10218   (when (and (not no-expire)
10219              gnus-newsgroup-auto-expire
10220              (memq mark gnus-auto-expirable-marks))
10221     (setq mark gnus-expirable-mark))
10222   (let ((article (or article (gnus-summary-article-number)))
10223         (old-mark (gnus-summary-article-mark article)))
10224     ;; Allow the backend to change the mark.
10225     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10226     (if (eq mark old-mark)
10227         t
10228       (unless article
10229         (error "No article on current line"))
10230       (if (not (if (or (= mark gnus-unread-mark)
10231                        (= mark gnus-ticked-mark)
10232                        (= mark gnus-spam-mark)
10233                        (= mark gnus-dormant-mark))
10234                    (gnus-mark-article-as-unread article mark)
10235                  (gnus-mark-article-as-read article mark)))
10236           t
10237         ;; See whether the article is to be put in the cache.
10238         (and gnus-use-cache
10239              (not (= mark gnus-canceled-mark))
10240              (vectorp (gnus-summary-article-header article))
10241              (save-excursion
10242                (gnus-cache-possibly-enter-article
10243                 gnus-newsgroup-name article
10244                 (gnus-summary-article-header article)
10245                 (= mark gnus-ticked-mark)
10246                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10247
10248         (when (gnus-summary-goto-subject article nil t)
10249           (let ((buffer-read-only nil))
10250             (gnus-summary-show-thread)
10251             ;; Fix the mark.
10252             (gnus-summary-update-mark mark 'unread)
10253             t))))))
10254
10255 (defun gnus-summary-update-secondary-mark (article)
10256   "Update the secondary (read, process, cache) mark."
10257   (gnus-summary-update-mark
10258    (cond ((memq article gnus-newsgroup-processable)
10259           gnus-process-mark)
10260          ((memq article gnus-newsgroup-cached)
10261           gnus-cached-mark)
10262          ((memq article gnus-newsgroup-replied)
10263           gnus-replied-mark)
10264          ((memq article gnus-newsgroup-forwarded)
10265           gnus-forwarded-mark)
10266          ((memq article gnus-newsgroup-saved)
10267           gnus-saved-mark)
10268          ((memq article gnus-newsgroup-recent)
10269           gnus-recent-mark)
10270          ((memq article gnus-newsgroup-unseen)
10271           gnus-unseen-mark)
10272          (t gnus-no-mark))
10273    'replied)
10274   (when (gnus-visual-p 'summary-highlight 'highlight)
10275     (gnus-run-hooks 'gnus-summary-update-hook))
10276   t)
10277
10278 (defun gnus-summary-update-download-mark (article)
10279   "Update the download mark."
10280   (gnus-summary-update-mark
10281    (cond ((memq article gnus-newsgroup-undownloaded)
10282           gnus-undownloaded-mark)
10283          (gnus-newsgroup-agentized
10284           gnus-downloaded-mark)
10285          (t
10286           gnus-no-mark))
10287    'download)
10288   (gnus-summary-update-line t)
10289   t)
10290
10291 (defun gnus-summary-update-mark (mark type)
10292   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10293         (buffer-read-only nil))
10294     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10295     (when forward
10296       (when (looking-at "\r")
10297         (incf forward))
10298       (when (<= (+ forward (point)) (point-max))
10299         ;; Go to the right position on the line.
10300         (goto-char (+ forward (point)))
10301         ;; Replace the old mark with the new mark.
10302         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10303         ;; Optionally update the marks by some user rule.
10304         (when (eq type 'unread)
10305           (gnus-data-set-mark
10306            (gnus-data-find (gnus-summary-article-number)) mark)
10307           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10308
10309 (defun gnus-mark-article-as-read (article &optional mark)
10310   "Enter ARTICLE in the pertinent lists and remove it from others."
10311   ;; Make the article expirable.
10312   (let ((mark (or mark gnus-del-mark)))
10313     (setq gnus-newsgroup-expirable
10314           (if (= mark gnus-expirable-mark)
10315               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10316             (delq article gnus-newsgroup-expirable)))
10317     ;; Remove from unread and marked lists.
10318     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10319     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10320     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10321     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10322     (push (cons article mark) gnus-newsgroup-reads)
10323     ;; Possibly remove from cache, if that is used.
10324     (when gnus-use-cache
10325       (gnus-cache-enter-remove-article article))
10326     t))
10327
10328 (defun gnus-mark-article-as-unread (article &optional mark)
10329   "Enter ARTICLE in the pertinent lists and remove it from others."
10330   (let ((mark (or mark gnus-ticked-mark)))
10331     (if (<= article 0)
10332         (progn
10333           (gnus-error 1 "Can't mark negative article numbers")
10334           nil)
10335       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10336             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10337             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10338             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10339             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10340
10341       ;; Unsuppress duplicates?
10342       (when gnus-suppress-duplicates
10343         (gnus-dup-unsuppress-article article))
10344
10345       (cond ((= mark gnus-ticked-mark)
10346              (setq gnus-newsgroup-marked
10347                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10348             ((= mark gnus-spam-mark)
10349              (setq gnus-newsgroup-spam-marked
10350                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10351                                             article)))
10352             ((= mark gnus-dormant-mark)
10353              (setq gnus-newsgroup-dormant
10354                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10355             (t
10356              (setq gnus-newsgroup-unreads
10357                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10358       (gnus-pull article gnus-newsgroup-reads)
10359       t)))
10360
10361 (defalias 'gnus-summary-mark-as-unread-forward
10362   'gnus-summary-tick-article-forward)
10363 (make-obsolete 'gnus-summary-mark-as-unread-forward
10364                'gnus-summary-tick-article-forward)
10365 (defun gnus-summary-tick-article-forward (n)
10366   "Tick N articles forwards.
10367 If N is negative, tick backwards instead.
10368 The difference between N and the number of articles ticked is returned."
10369   (interactive "p")
10370   (gnus-summary-mark-forward n gnus-ticked-mark))
10371
10372 (defalias 'gnus-summary-mark-as-unread-backward
10373   'gnus-summary-tick-article-backward)
10374 (make-obsolete 'gnus-summary-mark-as-unread-backward
10375                'gnus-summary-tick-article-backward)
10376 (defun gnus-summary-tick-article-backward (n)
10377   "Tick N articles backwards.
10378 The difference between N and the number of articles ticked is returned."
10379   (interactive "p")
10380   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10381
10382 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10383 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10384 (defun gnus-summary-tick-article (&optional article clear-mark)
10385   "Mark current article as unread.
10386 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10387 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10388   (interactive)
10389   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10390                                        gnus-ticked-mark)))
10391
10392 (defun gnus-summary-mark-as-read-forward (n)
10393   "Mark N articles as read forwards.
10394 If N is negative, mark backwards instead.
10395 The difference between N and the actual number of articles marked is
10396 returned."
10397   (interactive "p")
10398   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10399
10400 (defun gnus-summary-mark-as-read-backward (n)
10401   "Mark the N articles as read backwards.
10402 The difference between N and the actual number of articles marked is
10403 returned."
10404   (interactive "p")
10405   (gnus-summary-mark-forward
10406    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10407
10408 (defun gnus-summary-mark-as-read (&optional article mark)
10409   "Mark current article as read.
10410 ARTICLE specifies the article to be marked as read.
10411 MARK specifies a string to be inserted at the beginning of the line."
10412   (gnus-summary-mark-article article mark))
10413
10414 (defun gnus-summary-clear-mark-forward (n)
10415   "Clear marks from N articles forward.
10416 If N is negative, clear backward instead.
10417 The difference between N and the number of marks cleared is returned."
10418   (interactive "p")
10419   (gnus-summary-mark-forward n gnus-unread-mark))
10420
10421 (defun gnus-summary-clear-mark-backward (n)
10422   "Clear marks from N articles backward.
10423 The difference between N and the number of marks cleared is returned."
10424   (interactive "p")
10425   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10426
10427 (defun gnus-summary-mark-unread-as-read ()
10428   "Intended to be used by `gnus-summary-mark-article-hook'."
10429   (when (memq gnus-current-article gnus-newsgroup-unreads)
10430     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10431
10432 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10433   "Intended to be used by `gnus-summary-mark-article-hook'."
10434   (let ((mark (gnus-summary-article-mark)))
10435     (when (or (gnus-unread-mark-p mark)
10436               (gnus-read-mark-p mark))
10437       (gnus-summary-mark-article gnus-current-article
10438                                  (or new-mark gnus-read-mark)))))
10439
10440 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10441   "Intended to be used by `gnus-summary-mark-article-hook'."
10442   (let ((mark (gnus-summary-article-mark)))
10443     (when (or (gnus-unread-mark-p mark)
10444               (gnus-read-mark-p mark))
10445       (gnus-summary-mark-article (gnus-summary-article-number)
10446                                  (or new-mark gnus-read-mark)))))
10447
10448 (defun gnus-summary-mark-unread-as-ticked ()
10449   "Intended to be used by `gnus-summary-mark-article-hook'."
10450   (when (memq gnus-current-article gnus-newsgroup-unreads)
10451     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10452
10453 (defun gnus-summary-mark-region-as-read (point mark all)
10454   "Mark all unread articles between point and mark as read.
10455 If given a prefix, mark all articles between point and mark as read,
10456 even ticked and dormant ones."
10457   (interactive "r\nP")
10458   (save-excursion
10459     (let (article)
10460       (goto-char point)
10461       (beginning-of-line)
10462       (while (and
10463               (< (point) mark)
10464               (progn
10465                 (when (or all
10466                           (memq (setq article (gnus-summary-article-number))
10467                                 gnus-newsgroup-unreads))
10468                   (gnus-summary-mark-article article gnus-del-mark))
10469                 t)
10470               (gnus-summary-find-next))))))
10471
10472 (defun gnus-summary-mark-below (score mark)
10473   "Mark articles with score less than SCORE with MARK."
10474   (interactive "P\ncMark: ")
10475   (setq score (if score
10476                   (prefix-numeric-value score)
10477                 (or gnus-summary-default-score 0)))
10478   (save-excursion
10479     (set-buffer gnus-summary-buffer)
10480     (goto-char (point-min))
10481     (while
10482         (progn
10483           (and (< (gnus-summary-article-score) score)
10484                (gnus-summary-mark-article nil mark))
10485           (gnus-summary-find-next)))))
10486
10487 (defun gnus-summary-kill-below (&optional score)
10488   "Mark articles with score below SCORE as read."
10489   (interactive "P")
10490   (gnus-summary-mark-below score gnus-killed-mark))
10491
10492 (defun gnus-summary-clear-above (&optional score)
10493   "Clear all marks from articles with score above SCORE."
10494   (interactive "P")
10495   (gnus-summary-mark-above score gnus-unread-mark))
10496
10497 (defun gnus-summary-tick-above (&optional score)
10498   "Tick all articles with score above SCORE."
10499   (interactive "P")
10500   (gnus-summary-mark-above score gnus-ticked-mark))
10501
10502 (defun gnus-summary-mark-above (score mark)
10503   "Mark articles with score over SCORE with MARK."
10504   (interactive "P\ncMark: ")
10505   (setq score (if score
10506                   (prefix-numeric-value score)
10507                 (or gnus-summary-default-score 0)))
10508   (save-excursion
10509     (set-buffer gnus-summary-buffer)
10510     (goto-char (point-min))
10511     (while (and (progn
10512                   (when (> (gnus-summary-article-score) score)
10513                     (gnus-summary-mark-article nil mark))
10514                   t)
10515                 (gnus-summary-find-next)))))
10516
10517 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10518 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10519 (defun gnus-summary-limit-include-expunged (&optional no-error)
10520   "Display all the hidden articles that were expunged for low scores."
10521   (interactive)
10522   (let ((buffer-read-only nil))
10523     (let ((scored gnus-newsgroup-scored)
10524           headers h)
10525       (while scored
10526         (unless (gnus-summary-article-header (caar scored))
10527           (and (setq h (gnus-number-to-header (caar scored)))
10528                (< (cdar scored) gnus-summary-expunge-below)
10529                (push h headers)))
10530         (setq scored (cdr scored)))
10531       (if (not headers)
10532           (when (not no-error)
10533             (error "No expunged articles hidden"))
10534         (goto-char (point-min))
10535         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10536         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10537         (mapcar (lambda (x) (push (mail-header-number x)
10538                                   gnus-newsgroup-limit))
10539                 headers)
10540         (gnus-summary-prepare-unthreaded (nreverse headers))
10541         (goto-char (point-min))
10542         (gnus-summary-position-point)
10543         t))))
10544
10545 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10546   "Mark all unread articles in this newsgroup as read.
10547 If prefix argument ALL is non-nil, ticked and dormant articles will
10548 also be marked as read.
10549 If QUIETLY is non-nil, no questions will be asked.
10550
10551 If TO-HERE is non-nil, it should be a point in the buffer.  All
10552 articles before (after, if REVERSE is set) this point will be marked
10553 as read.
10554
10555 Note that this function will only catch up the unread article
10556 in the current summary buffer limitation.
10557
10558 The number of articles marked as read is returned."
10559   (interactive "P")
10560   (prog1
10561       (save-excursion
10562         (when (or quietly
10563                   (not gnus-interactive-catchup) ;Without confirmation?
10564                   gnus-expert-user
10565                   (gnus-y-or-n-p
10566                    (if all
10567                        "Mark absolutely all articles as read? "
10568                      "Mark all unread articles as read? ")))
10569           (if (and not-mark
10570                    (not gnus-newsgroup-adaptive)
10571                    (not gnus-newsgroup-auto-expire)
10572                    (not gnus-suppress-duplicates)
10573                    (or (not gnus-use-cache)
10574                        (eq gnus-use-cache 'passive)))
10575               (progn
10576                 (when all
10577                   (setq gnus-newsgroup-marked nil
10578                         gnus-newsgroup-spam-marked nil
10579                         gnus-newsgroup-dormant nil))
10580                 (setq gnus-newsgroup-unreads
10581                       (gnus-sorted-nunion
10582                        (gnus-intersection gnus-newsgroup-unreads
10583                                           gnus-newsgroup-downloadable)
10584                        gnus-newsgroup-unfetched)))
10585             ;; We actually mark all articles as canceled, which we
10586             ;; have to do when using auto-expiry or adaptive scoring.
10587             (gnus-summary-show-all-threads)
10588             (if (and to-here reverse)
10589                 (progn
10590                   (goto-char to-here)
10591                   (gnus-summary-mark-current-read-and-unread-as-read
10592                    gnus-catchup-mark)
10593                   (while (gnus-summary-find-next (not all))
10594                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10595               (when (gnus-summary-first-subject (not all))
10596                 (while (and
10597                         (if to-here (< (point) to-here) t)
10598                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10599                         (gnus-summary-find-next (not all))))))
10600             (gnus-set-mode-line 'summary))
10601           t))
10602     (gnus-summary-position-point)))
10603
10604 (defun gnus-summary-catchup-to-here (&optional all)
10605   "Mark all unticked articles before the current one as read.
10606 If ALL is non-nil, also mark ticked and dormant articles as read."
10607   (interactive "P")
10608   (save-excursion
10609     (gnus-save-hidden-threads
10610       (let ((beg (point)))
10611         ;; We check that there are unread articles.
10612         (when (or all (gnus-summary-find-prev))
10613           (gnus-summary-catchup all t beg)))))
10614   (gnus-summary-position-point))
10615
10616 (defun gnus-summary-catchup-from-here (&optional all)
10617   "Mark all unticked articles after (and including) the current one as read.
10618 If ALL is non-nil, also mark ticked and dormant articles as read."
10619   (interactive "P")
10620   (save-excursion
10621     (gnus-save-hidden-threads
10622       (let ((beg (point)))
10623         ;; We check that there are unread articles.
10624         (when (or all (gnus-summary-find-next))
10625           (gnus-summary-catchup all t beg nil t)))))
10626   (gnus-summary-position-point))
10627
10628 (defun gnus-summary-catchup-all (&optional quietly)
10629   "Mark all articles in this newsgroup as read.
10630 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10631 instead, which marks only unread articles as read."
10632   (interactive "P")
10633   (gnus-summary-catchup t quietly))
10634
10635 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10636   "Mark all unread articles in this group as read, then exit.
10637 If prefix argument ALL is non-nil, all articles are marked as read.
10638 If QUIETLY is non-nil, no questions will be asked."
10639   (interactive "P")
10640   (when (gnus-summary-catchup all quietly nil 'fast)
10641     ;; Select next newsgroup or exit.
10642     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10643              (eq gnus-auto-select-next 'quietly))
10644         (gnus-summary-next-group nil)
10645       (gnus-summary-exit))))
10646
10647 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10648   "Mark all articles in this newsgroup as read, and then exit.
10649 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10650 instead, which marks only unread articles as read."
10651   (interactive "P")
10652   (gnus-summary-catchup-and-exit t quietly))
10653
10654 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10655   "Mark all articles in this group as read and select the next group.
10656 If given a prefix, mark all articles, unread as well as ticked, as
10657 read."
10658   (interactive "P")
10659   (save-excursion
10660     (gnus-summary-catchup all))
10661   (gnus-summary-next-group))
10662
10663 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10664   "Mark all articles in this group as read and select the previous group.
10665 If given a prefix, mark all articles, unread as well as ticked, as
10666 read."
10667   (interactive "P")
10668   (save-excursion
10669     (gnus-summary-catchup all))
10670   (gnus-summary-next-group nil nil t))
10671
10672 ;;;
10673 ;;; with article
10674 ;;;
10675
10676 (defmacro gnus-with-article (article &rest forms)
10677   "Select ARTICLE and perform FORMS in the original article buffer.
10678 Then replace the article with the result."
10679   `(progn
10680      ;; We don't want the article to be marked as read.
10681      (let (gnus-mark-article-hook)
10682        (gnus-summary-select-article t t nil ,article))
10683      (set-buffer gnus-original-article-buffer)
10684      ,@forms
10685      (if (not (gnus-check-backend-function
10686                'request-replace-article (car gnus-article-current)))
10687          (gnus-message 5 "Read-only group; not replacing")
10688        (unless (gnus-request-replace-article
10689                 ,article (car gnus-article-current)
10690                 (current-buffer) t)
10691          (error "Couldn't replace article")))
10692      ;; The cache and backlog have to be flushed somewhat.
10693      (when gnus-keep-backlog
10694        (gnus-backlog-remove-article
10695         (car gnus-article-current) (cdr gnus-article-current)))
10696      (when gnus-use-cache
10697        (gnus-cache-update-article
10698         (car gnus-article-current) (cdr gnus-article-current)))))
10699
10700 (put 'gnus-with-article 'lisp-indent-function 1)
10701 (put 'gnus-with-article 'edebug-form-spec '(form body))
10702
10703 ;; Thread-based commands.
10704
10705 (defun gnus-summary-articles-in-thread (&optional article)
10706   "Return a list of all articles in the current thread.
10707 If ARTICLE is non-nil, return all articles in the thread that starts
10708 with that article."
10709   (let* ((article (or article (gnus-summary-article-number)))
10710          (data (gnus-data-find-list article))
10711          (top-level (gnus-data-level (car data)))
10712          (top-subject
10713           (cond ((null gnus-thread-operation-ignore-subject)
10714                  (gnus-simplify-subject-re
10715                   (mail-header-subject (gnus-data-header (car data)))))
10716                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10717                  (gnus-simplify-subject-fuzzy
10718                   (mail-header-subject (gnus-data-header (car data)))))
10719                 (t nil)))
10720          (end-point (save-excursion
10721                       (if (gnus-summary-go-to-next-thread)
10722                           (point) (point-max))))
10723          articles)
10724     (while (and data
10725                 (< (gnus-data-pos (car data)) end-point))
10726       (when (or (not top-subject)
10727                 (string= top-subject
10728                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10729                              (gnus-simplify-subject-fuzzy
10730                               (mail-header-subject
10731                                (gnus-data-header (car data))))
10732                            (gnus-simplify-subject-re
10733                             (mail-header-subject
10734                              (gnus-data-header (car data)))))))
10735         (push (gnus-data-number (car data)) articles))
10736       (unless (and (setq data (cdr data))
10737                    (> (gnus-data-level (car data)) top-level))
10738         (setq data nil)))
10739     ;; Return the list of articles.
10740     (nreverse articles)))
10741
10742 (defun gnus-summary-rethread-current ()
10743   "Rethread the thread the current article is part of."
10744   (interactive)
10745   (let* ((gnus-show-threads t)
10746          (article (gnus-summary-article-number))
10747          (id (mail-header-id (gnus-summary-article-header)))
10748          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10749     (unless id
10750       (error "No article on the current line"))
10751     (gnus-rebuild-thread id)
10752     (gnus-summary-goto-subject article)))
10753
10754 (defun gnus-summary-reparent-thread ()
10755   "Make the current article child of the marked (or previous) article.
10756
10757 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10758 is non-nil or the Subject: of both articles are the same."
10759   (interactive)
10760   (unless (not (gnus-group-read-only-p))
10761     (error "The current newsgroup does not support article editing"))
10762   (unless (<= (length gnus-newsgroup-processable) 1)
10763     (error "No more than one article may be marked"))
10764   (save-window-excursion
10765     (let ((gnus-article-buffer " *reparent*")
10766           (current-article (gnus-summary-article-number))
10767           ;; First grab the marked article, otherwise one line up.
10768           (parent-article (if (not (null gnus-newsgroup-processable))
10769                               (car gnus-newsgroup-processable)
10770                             (save-excursion
10771                               (if (eq (forward-line -1) 0)
10772                                   (gnus-summary-article-number)
10773                                 (error "Beginning of summary buffer"))))))
10774       (unless (not (eq current-article parent-article))
10775         (error "An article may not be self-referential"))
10776       (let ((message-id (mail-header-id
10777                          (gnus-summary-article-header parent-article))))
10778         (unless (and message-id (not (equal message-id "")))
10779           (error "No message-id in desired parent"))
10780         (gnus-with-article current-article
10781           (save-restriction
10782             (goto-char (point-min))
10783             (message-narrow-to-head)
10784             (if (re-search-forward "^References: " nil t)
10785                 (progn
10786                   (re-search-forward "^[^ \t]" nil t)
10787                   (forward-line -1)
10788                   (end-of-line)
10789                   (insert " " message-id))
10790               (insert "References: " message-id "\n"))))
10791         (set-buffer gnus-summary-buffer)
10792         (gnus-summary-unmark-all-processable)
10793         (gnus-summary-update-article current-article)
10794         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10795             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10796         (gnus-summary-rethread-current)
10797         (gnus-message 3 "Article %d is now the child of article %d"
10798                       current-article parent-article)))))
10799
10800 (defun gnus-summary-toggle-threads (&optional arg)
10801   "Toggle showing conversation threads.
10802 If ARG is positive number, turn showing conversation threads on."
10803   (interactive "P")
10804   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10805     (setq gnus-show-threads
10806           (if (null arg) (not gnus-show-threads)
10807             (> (prefix-numeric-value arg) 0)))
10808     (gnus-summary-prepare)
10809     (gnus-summary-goto-subject current)
10810     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10811     (gnus-summary-position-point)))
10812
10813 (defun gnus-summary-show-all-threads ()
10814   "Show all threads."
10815   (interactive)
10816   (save-excursion
10817     (let ((buffer-read-only nil))
10818       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10819   (gnus-summary-position-point))
10820
10821 (defun gnus-summary-show-thread ()
10822   "Show thread subtrees.
10823 Returns nil if no thread was there to be shown."
10824   (interactive)
10825   (let ((buffer-read-only nil)
10826         (orig (point))
10827         (end (point-at-eol))
10828         ;; Leave point at bol
10829         (beg (progn (beginning-of-line) (point))))
10830     (prog1
10831         ;; Any hidden lines here?
10832         (search-forward "\r" end t)
10833       (subst-char-in-region beg end ?\^M ?\n t)
10834       (goto-char orig)
10835       (gnus-summary-position-point))))
10836
10837 (defun gnus-summary-maybe-hide-threads ()
10838   "If requested, hide the threads that should be hidden."
10839   (when (and gnus-show-threads
10840              gnus-thread-hide-subtree)
10841     (gnus-summary-hide-all-threads
10842      (if (or (consp gnus-thread-hide-subtree)
10843              (functionp gnus-thread-hide-subtree))
10844          (gnus-make-predicate gnus-thread-hide-subtree)
10845        nil))))
10846
10847 ;;; Hiding predicates.
10848
10849 (defun gnus-article-unread-p (header)
10850   (memq (mail-header-number header) gnus-newsgroup-unreads))
10851
10852 (defun gnus-article-unseen-p (header)
10853   (memq (mail-header-number header) gnus-newsgroup-unseen))
10854
10855 (defun gnus-map-articles (predicate articles)
10856   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10857   (apply 'gnus-or (mapcar predicate
10858                           (mapcar 'gnus-summary-article-header articles))))
10859
10860 (defun gnus-summary-hide-all-threads (&optional predicate)
10861   "Hide all thread subtrees.
10862 If PREDICATE is supplied, threads that satisfy this predicate
10863 will not be hidden."
10864   (interactive)
10865   (save-excursion
10866     (goto-char (point-min))
10867     (let ((end nil))
10868       (while (not end)
10869         (when (or (not predicate)
10870                   (gnus-map-articles
10871                    predicate (gnus-summary-article-children)))
10872             (gnus-summary-hide-thread))
10873         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10874   (gnus-summary-position-point))
10875
10876 (defun gnus-summary-hide-thread ()
10877   "Hide thread subtrees.
10878 If PREDICATE is supplied, threads that satisfy this predicate
10879 will not be hidden.
10880 Returns nil if no threads were there to be hidden."
10881   (interactive)
10882   (let ((buffer-read-only nil)
10883         (start (point))
10884         (article (gnus-summary-article-number)))
10885     (goto-char start)
10886     ;; Go forward until either the buffer ends or the subthread
10887     ;; ends.
10888     (when (and (not (eobp))
10889                (or (zerop (gnus-summary-next-thread 1 t))
10890                    (goto-char (point-max))))
10891       (prog1
10892           (if (and (> (point) start)
10893                    (search-backward "\n" start t))
10894               (progn
10895                 (subst-char-in-region start (point) ?\n ?\^M)
10896                 (gnus-summary-goto-subject article))
10897             (goto-char start)
10898             nil)))))
10899
10900 (defun gnus-summary-go-to-next-thread (&optional previous)
10901   "Go to the same level (or less) next thread.
10902 If PREVIOUS is non-nil, go to previous thread instead.
10903 Return the article number moved to, or nil if moving was impossible."
10904   (let ((level (gnus-summary-thread-level))
10905         (way (if previous -1 1))
10906         (beg (point)))
10907     (forward-line way)
10908     (while (and (not (eobp))
10909                 (< level (gnus-summary-thread-level)))
10910       (forward-line way))
10911     (if (eobp)
10912         (progn
10913           (goto-char beg)
10914           nil)
10915       (setq beg (point))
10916       (prog1
10917           (gnus-summary-article-number)
10918         (goto-char beg)))))
10919
10920 (defun gnus-summary-next-thread (n &optional silent)
10921   "Go to the same level next N'th thread.
10922 If N is negative, search backward instead.
10923 Returns the difference between N and the number of skips actually
10924 done.
10925
10926 If SILENT, don't output messages."
10927   (interactive "p")
10928   (let ((backward (< n 0))
10929         (n (abs n)))
10930     (while (and (> n 0)
10931                 (gnus-summary-go-to-next-thread backward))
10932       (decf n))
10933     (unless silent
10934       (gnus-summary-position-point))
10935     (when (and (not silent) (/= 0 n))
10936       (gnus-message 7 "No more threads"))
10937     n))
10938
10939 (defun gnus-summary-prev-thread (n)
10940   "Go to the same level previous N'th thread.
10941 Returns the difference between N and the number of skips actually
10942 done."
10943   (interactive "p")
10944   (gnus-summary-next-thread (- n)))
10945
10946 (defun gnus-summary-go-down-thread ()
10947   "Go down one level in the current thread."
10948   (let ((children (gnus-summary-article-children)))
10949     (when children
10950       (gnus-summary-goto-subject (car children)))))
10951
10952 (defun gnus-summary-go-up-thread ()
10953   "Go up one level in the current thread."
10954   (let ((parent (gnus-summary-article-parent)))
10955     (when parent
10956       (gnus-summary-goto-subject parent))))
10957
10958 (defun gnus-summary-down-thread (n)
10959   "Go down thread N steps.
10960 If N is negative, go up instead.
10961 Returns the difference between N and how many steps down that were
10962 taken."
10963   (interactive "p")
10964   (let ((up (< n 0))
10965         (n (abs n)))
10966     (while (and (> n 0)
10967                 (if up (gnus-summary-go-up-thread)
10968                   (gnus-summary-go-down-thread)))
10969       (setq n (1- n)))
10970     (gnus-summary-position-point)
10971     (when (/= 0 n)
10972       (gnus-message 7 "Can't go further"))
10973     n))
10974
10975 (defun gnus-summary-up-thread (n)
10976   "Go up thread N steps.
10977 If N is negative, go down instead.
10978 Returns the difference between N and how many steps down that were
10979 taken."
10980   (interactive "p")
10981   (gnus-summary-down-thread (- n)))
10982
10983 (defun gnus-summary-top-thread ()
10984   "Go to the top of the thread."
10985   (interactive)
10986   (while (gnus-summary-go-up-thread))
10987   (gnus-summary-article-number))
10988
10989 (defun gnus-summary-kill-thread (&optional unmark)
10990   "Mark articles under current thread as read.
10991 If the prefix argument is positive, remove any kinds of marks.
10992 If the prefix argument is negative, tick articles instead."
10993   (interactive "P")
10994   (when unmark
10995     (setq unmark (prefix-numeric-value unmark)))
10996   (let ((articles (gnus-summary-articles-in-thread)))
10997     (save-excursion
10998       ;; Expand the thread.
10999       (gnus-summary-show-thread)
11000       ;; Mark all the articles.
11001       (while articles
11002         (gnus-summary-goto-subject (car articles))
11003         (cond ((null unmark)
11004                (gnus-summary-mark-article-as-read gnus-killed-mark))
11005               ((> unmark 0)
11006                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11007               (t
11008                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11009         (setq articles (cdr articles))))
11010     ;; Hide killed subtrees.
11011     (and (null unmark)
11012          gnus-thread-hide-killed
11013          (gnus-summary-hide-thread))
11014     ;; If marked as read, go to next unread subject.
11015     (when (null unmark)
11016       ;; Go to next unread subject.
11017       (gnus-summary-next-subject 1 t)))
11018   (gnus-set-mode-line 'summary))
11019
11020 ;; Summary sorting commands
11021
11022 (defun gnus-summary-sort-by-number (&optional reverse)
11023   "Sort the summary buffer by article number.
11024 Argument REVERSE means reverse order."
11025   (interactive "P")
11026   (gnus-summary-sort 'number reverse))
11027
11028 (defun gnus-summary-sort-by-random (&optional reverse)
11029   "Randomize the order in the summary buffer.
11030 Argument REVERSE means to randomize in reverse order."
11031   (interactive "P")
11032   (gnus-summary-sort 'random reverse))
11033
11034 (defun gnus-summary-sort-by-author (&optional reverse)
11035   "Sort the summary buffer by author name alphabetically.
11036 If `case-fold-search' is non-nil, case of letters is ignored.
11037 Argument REVERSE means reverse order."
11038   (interactive "P")
11039   (gnus-summary-sort 'author reverse))
11040
11041 (defun gnus-summary-sort-by-recipient (&optional reverse)
11042   "Sort the summary buffer by recipient name alphabetically.
11043 If `case-fold-search' is non-nil, case of letters is ignored.
11044 Argument REVERSE means reverse order."
11045   (interactive "P")
11046   (gnus-summary-sort 'recipient reverse))
11047
11048 (defun gnus-summary-sort-by-subject (&optional reverse)
11049   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11050 If `case-fold-search' is non-nil, case of letters is ignored.
11051 Argument REVERSE means reverse order."
11052   (interactive "P")
11053   (gnus-summary-sort 'subject reverse))
11054
11055 (defun gnus-summary-sort-by-date (&optional reverse)
11056   "Sort the summary buffer by date.
11057 Argument REVERSE means reverse order."
11058   (interactive "P")
11059   (gnus-summary-sort 'date reverse))
11060
11061 (defun gnus-summary-sort-by-score (&optional reverse)
11062   "Sort the summary buffer by score.
11063 Argument REVERSE means reverse order."
11064   (interactive "P")
11065   (gnus-summary-sort 'score reverse))
11066
11067 (defun gnus-summary-sort-by-lines (&optional reverse)
11068   "Sort the summary buffer by the number of lines.
11069 Argument REVERSE means reverse order."
11070   (interactive "P")
11071   (gnus-summary-sort 'lines reverse))
11072
11073 (defun gnus-summary-sort-by-chars (&optional reverse)
11074   "Sort the summary buffer by article length.
11075 Argument REVERSE means reverse order."
11076   (interactive "P")
11077   (gnus-summary-sort 'chars reverse))
11078
11079 (defun gnus-summary-sort-by-original (&optional reverse)
11080   "Sort the summary buffer using the default sorting method.
11081 Argument REVERSE means reverse order."
11082   (interactive "P")
11083   (let* ((buffer-read-only)
11084          (gnus-summary-prepare-hook nil))
11085     ;; We do the sorting by regenerating the threads.
11086     (gnus-summary-prepare)
11087     ;; Hide subthreads if needed.
11088     (gnus-summary-maybe-hide-threads)))
11089
11090 (defun gnus-summary-sort (predicate reverse)
11091   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11092   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11093          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11094          (gnus-thread-sort-functions
11095           (if (not reverse)
11096               thread
11097             `(lambda (t1 t2)
11098                (,thread t2 t1))))
11099          (gnus-sort-gathered-threads-function
11100           gnus-thread-sort-functions)
11101          (gnus-article-sort-functions
11102           (if (not reverse)
11103               article
11104             `(lambda (t1 t2)
11105                (,article t2 t1))))
11106          (buffer-read-only)
11107          (gnus-summary-prepare-hook nil))
11108     ;; We do the sorting by regenerating the threads.
11109     (gnus-summary-prepare)
11110     ;; Hide subthreads if needed.
11111     (gnus-summary-maybe-hide-threads)))
11112
11113 ;; Summary saving commands.
11114
11115 (defun gnus-summary-save-article (&optional n not-saved)
11116   "Save the current article using the default saver function.
11117 If N is a positive number, save the N next articles.
11118 If N is a negative number, save the N previous articles.
11119 If N is nil and any articles have been marked with the process mark,
11120 save those articles instead.
11121 The variable `gnus-default-article-saver' specifies the saver function."
11122   (interactive "P")
11123   (let* ((articles (gnus-summary-work-articles n))
11124          (save-buffer (save-excursion
11125                         (nnheader-set-temp-buffer " *Gnus Save*")))
11126          (num (length articles))
11127          header file)
11128     (dolist (article articles)
11129       (setq header (gnus-summary-article-header article))
11130       (if (not (vectorp header))
11131           ;; This is a pseudo-article.
11132           (if (assq 'name header)
11133               (gnus-copy-file (cdr (assq 'name header)))
11134             (gnus-message 1 "Article %d is unsaveable" article))
11135         ;; This is a real article.
11136         (save-window-excursion
11137           (let ((gnus-display-mime-function nil)
11138                 (gnus-article-prepare-hook nil))
11139             (gnus-summary-select-article t nil nil article)))
11140         (save-excursion
11141           (set-buffer save-buffer)
11142           (erase-buffer)
11143           (insert-buffer-substring gnus-original-article-buffer))
11144         (setq file (gnus-article-save save-buffer file num))
11145         (gnus-summary-remove-process-mark article)
11146         (unless not-saved
11147           (gnus-summary-set-saved-mark article))))
11148     (gnus-kill-buffer save-buffer)
11149     (gnus-summary-position-point)
11150     (gnus-set-mode-line 'summary)
11151     n))
11152
11153 (defun gnus-summary-pipe-output (&optional arg headers)
11154   "Pipe the current article to a subprocess.
11155 If N is a positive number, pipe the N next articles.
11156 If N is a negative number, pipe the N previous articles.
11157 If N is nil and any articles have been marked with the process mark,
11158 pipe those articles instead.
11159 If HEADERS (the symbolic prefix), include the headers, too."
11160   (interactive (gnus-interactive "P\ny"))
11161   (require 'gnus-art)
11162   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11163         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11164     (gnus-summary-save-article arg t))
11165   (let ((buffer (get-buffer "*Shell Command Output*")))
11166     (when (and buffer
11167                (not (zerop (buffer-size buffer))))
11168       (gnus-configure-windows 'pipe))))
11169
11170 (defun gnus-summary-save-article-mail (&optional arg)
11171   "Append the current article to an mail file.
11172 If N is a positive number, save the N next articles.
11173 If N is a negative number, save the N previous articles.
11174 If N is nil and any articles have been marked with the process mark,
11175 save those articles instead."
11176   (interactive "P")
11177   (require 'gnus-art)
11178   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11179     (gnus-summary-save-article arg)))
11180
11181 (defun gnus-summary-save-article-rmail (&optional arg)
11182   "Append the current article to an rmail file.
11183 If N is a positive number, save the N next articles.
11184 If N is a negative number, save the N previous articles.
11185 If N is nil and any articles have been marked with the process mark,
11186 save those articles instead."
11187   (interactive "P")
11188   (require 'gnus-art)
11189   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11190     (gnus-summary-save-article arg)))
11191
11192 (defun gnus-summary-save-article-file (&optional arg)
11193   "Append the current article to a file.
11194 If N is a positive number, save the N next articles.
11195 If N is a negative number, save the N previous articles.
11196 If N is nil and any articles have been marked with the process mark,
11197 save those articles instead."
11198   (interactive "P")
11199   (require 'gnus-art)
11200   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11201     (gnus-summary-save-article arg)))
11202
11203 (defun gnus-summary-write-article-file (&optional arg)
11204   "Write the current article to a file, deleting the previous file.
11205 If N is a positive number, save the N next articles.
11206 If N is a negative number, save the N previous articles.
11207 If N is nil and any articles have been marked with the process mark,
11208 save those articles instead."
11209   (interactive "P")
11210   (require 'gnus-art)
11211   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11212     (gnus-summary-save-article arg)))
11213
11214 (defun gnus-summary-save-article-body-file (&optional arg)
11215   "Append the current article body to a file.
11216 If N is a positive number, save the N next articles.
11217 If N is a negative number, save the N previous articles.
11218 If N is nil and any articles have been marked with the process mark,
11219 save those articles instead."
11220   (interactive "P")
11221   (require 'gnus-art)
11222   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11223     (gnus-summary-save-article arg)))
11224
11225 (defun gnus-summary-muttprint (&optional arg)
11226   "Print the current article using Muttprint.
11227 If N is a positive number, save the N next articles.
11228 If N is a negative number, save the N previous articles.
11229 If N is nil and any articles have been marked with the process mark,
11230 save those articles instead."
11231   (interactive "P")
11232   (require 'gnus-art)
11233   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11234     (gnus-summary-save-article arg t)))
11235
11236 (defun gnus-summary-pipe-message (program)
11237   "Pipe the current article through PROGRAM."
11238   (interactive "sProgram: ")
11239   (gnus-summary-select-article)
11240   (let ((mail-header-separator ""))
11241     (gnus-eval-in-buffer-window gnus-article-buffer
11242       (save-restriction
11243         (widen)
11244         (let ((start (window-start))
11245               buffer-read-only)
11246           (message-pipe-buffer-body program)
11247           (set-window-start (get-buffer-window (current-buffer)) start))))))
11248
11249 (defun gnus-get-split-value (methods)
11250   "Return a value based on the split METHODS."
11251   (let (split-name method result match)
11252     (when methods
11253       (save-excursion
11254         (set-buffer gnus-original-article-buffer)
11255         (save-restriction
11256           (nnheader-narrow-to-headers)
11257           (while (and methods (not split-name))
11258             (goto-char (point-min))
11259             (setq method (pop methods))
11260             (setq match (car method))
11261             (when (cond
11262                    ((stringp match)
11263                     ;; Regular expression.
11264                     (ignore-errors
11265                       (re-search-forward match nil t)))
11266                    ((functionp match)
11267                     ;; Function.
11268                     (save-restriction
11269                       (widen)
11270                       (setq result (funcall match gnus-newsgroup-name))))
11271                    ((consp match)
11272                     ;; Form.
11273                     (save-restriction
11274                       (widen)
11275                       (setq result (eval match)))))
11276               (setq split-name (cdr method))
11277               (cond ((stringp result)
11278                      (push (expand-file-name
11279                             result gnus-article-save-directory)
11280                            split-name))
11281                     ((consp result)
11282                      (setq split-name (append result split-name)))))))))
11283     (nreverse split-name)))
11284
11285 (defun gnus-valid-move-group-p (group)
11286   (and (boundp group)
11287        (symbol-name group)
11288        (symbol-value group)
11289        (gnus-get-function (gnus-find-method-for-group
11290                            (symbol-name group)) 'request-accept-article t)))
11291
11292 (defun gnus-read-move-group-name (prompt default articles prefix)
11293   "Read a group name."
11294   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11295          (minibuffer-confirm-incomplete nil) ; XEmacs
11296          (prom
11297           (format "%s %s to"
11298                   prompt
11299                   (if (> (length articles) 1)
11300                       (format "these %d articles" (length articles))
11301                     "this article")))
11302          (to-newsgroup
11303           (cond
11304            ((null split-name)
11305             (gnus-completing-read-with-default
11306              default prom
11307              gnus-active-hashtb
11308              'gnus-valid-move-group-p
11309              nil prefix
11310              'gnus-group-history))
11311            ((= 1 (length split-name))
11312             (gnus-completing-read-with-default
11313              (car split-name) prom
11314              gnus-active-hashtb
11315              'gnus-valid-move-group-p
11316              nil nil
11317              'gnus-group-history))
11318            (t
11319             (gnus-completing-read-with-default
11320              nil prom
11321              (mapcar 'list (nreverse split-name))
11322              nil nil nil
11323              'gnus-group-history))))
11324          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11325     (when to-newsgroup
11326       (if (or (string= to-newsgroup "")
11327               (string= to-newsgroup prefix))
11328           (setq to-newsgroup default))
11329       (unless to-newsgroup
11330         (error "No group name entered"))
11331       (or (gnus-active to-newsgroup)
11332           (gnus-activate-group to-newsgroup nil nil to-method)
11333           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11334                                      to-newsgroup))
11335               (or (and (gnus-request-create-group to-newsgroup to-method)
11336                        (gnus-activate-group
11337                         to-newsgroup nil nil to-method)
11338                        (gnus-subscribe-group to-newsgroup))
11339                   (error "Couldn't create group %s" to-newsgroup)))
11340           (error "No such group: %s" to-newsgroup)))
11341     to-newsgroup))
11342
11343 (defun gnus-summary-save-parts (type dir n &optional reverse)
11344   "Save parts matching TYPE to DIR.
11345 If REVERSE, save parts that do not match TYPE."
11346   (interactive
11347    (list (read-string "Save parts of type: "
11348                       (or (car gnus-summary-save-parts-type-history)
11349                           gnus-summary-save-parts-default-mime)
11350                       'gnus-summary-save-parts-type-history)
11351          (setq gnus-summary-save-parts-last-directory
11352                (read-file-name "Save to directory: "
11353                                gnus-summary-save-parts-last-directory
11354                                nil t))
11355          current-prefix-arg))
11356   (gnus-summary-iterate n
11357     (let ((gnus-display-mime-function nil)
11358           (gnus-inhibit-treatment t))
11359       (gnus-summary-select-article))
11360     (save-excursion
11361       (set-buffer gnus-article-buffer)
11362       (let ((handles (or gnus-article-mime-handles
11363                          (mm-dissect-buffer nil gnus-article-loose-mime)
11364                          (and gnus-article-emulate-mime
11365                               (mm-uu-dissect)))))
11366         (when handles
11367           (gnus-summary-save-parts-1 type dir handles reverse)
11368           (unless gnus-article-mime-handles ;; Don't destroy this case.
11369             (mm-destroy-parts handles)))))))
11370
11371 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11372   (if (stringp (car handle))
11373       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11374               (cdr handle))
11375     (when (if reverse
11376               (not (string-match type (mm-handle-media-type handle)))
11377             (string-match type (mm-handle-media-type handle)))
11378       (let ((file (expand-file-name
11379                    (gnus-map-function
11380                     mm-file-name-rewrite-functions
11381                     (file-name-nondirectory
11382                      (or
11383                       (mail-content-type-get
11384                        (mm-handle-disposition handle) 'filename)
11385                       (mail-content-type-get
11386                        (mm-handle-type handle) 'name)
11387                       (concat gnus-newsgroup-name
11388                               "." (number-to-string
11389                                    (cdr gnus-article-current))))))
11390                    dir)))
11391         (unless (file-exists-p file)
11392           (mm-save-part-to-file handle file))))))
11393
11394 ;; Summary extract commands
11395
11396 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11397   (let ((buffer-read-only nil)
11398         (article (gnus-summary-article-number))
11399         after-article b e)
11400     (unless (gnus-summary-goto-subject article)
11401       (error "No such article: %d" article))
11402     (gnus-summary-position-point)
11403     ;; If all commands are to be bunched up on one line, we collect
11404     ;; them here.
11405     (unless gnus-view-pseudos-separately
11406       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11407             files action)
11408         (while ps
11409           (setq action (cdr (assq 'action (car ps))))
11410           (setq files (list (cdr (assq 'name (car ps)))))
11411           (while (and ps (cdr ps)
11412                       (string= (or action "1")
11413                                (or (cdr (assq 'action (cadr ps))) "2")))
11414             (push (cdr (assq 'name (cadr ps))) files)
11415             (setcdr ps (cddr ps)))
11416           (when files
11417             (when (not (string-match "%s" action))
11418               (push " " files))
11419             (push " " files)
11420             (when (assq 'execute (car ps))
11421               (setcdr (assq 'execute (car ps))
11422                       (funcall (if (string-match "%s" action)
11423                                    'format 'concat)
11424                                action
11425                                (mapconcat
11426                                 (lambda (f)
11427                                   (if (equal f " ")
11428                                       f
11429                                     (shell-quote-argument f)))
11430                                 files " ")))))
11431           (setq ps (cdr ps)))))
11432     (if (and gnus-view-pseudos (not not-view))
11433         (while pslist
11434           (when (assq 'execute (car pslist))
11435             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11436                                   (eq gnus-view-pseudos 'not-confirm)))
11437           (setq pslist (cdr pslist)))
11438       (save-excursion
11439         (while pslist
11440           (setq after-article (or (cdr (assq 'article (car pslist)))
11441                                   (gnus-summary-article-number)))
11442           (gnus-summary-goto-subject after-article)
11443           (forward-line 1)
11444           (setq b (point))
11445           (insert "    " (file-name-nondirectory
11446                           (cdr (assq 'name (car pslist))))
11447                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11448           (setq e (point))
11449           (forward-line -1)             ; back to `b'
11450           (gnus-add-text-properties
11451            b (1- e) (list 'gnus-number gnus-reffed-article-number
11452                           gnus-mouse-face-prop gnus-mouse-face))
11453           (gnus-data-enter
11454            after-article gnus-reffed-article-number
11455            gnus-unread-mark b (car pslist) 0 (- e b))
11456           (setq gnus-newsgroup-unreads
11457                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11458                                          gnus-reffed-article-number))
11459           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11460           (setq pslist (cdr pslist)))))))
11461
11462 (defun gnus-pseudos< (p1 p2)
11463   (let ((c1 (cdr (assq 'action p1)))
11464         (c2 (cdr (assq 'action p2))))
11465     (and c1 c2 (string< c1 c2))))
11466
11467 (defun gnus-request-pseudo-article (props)
11468   (cond ((assq 'execute props)
11469          (gnus-execute-command (cdr (assq 'execute props)))))
11470   (let ((gnus-current-article (gnus-summary-article-number)))
11471     (gnus-run-hooks 'gnus-mark-article-hook)))
11472
11473 (defun gnus-execute-command (command &optional automatic)
11474   (save-excursion
11475     (gnus-article-setup-buffer)
11476     (set-buffer gnus-article-buffer)
11477     (setq buffer-read-only nil)
11478     (let ((command (if automatic command
11479                      (read-string "Command: " (cons command 0)))))
11480       (erase-buffer)
11481       (insert "$ " command "\n\n")
11482       (if gnus-view-pseudo-asynchronously
11483           (start-process "gnus-execute" (current-buffer) shell-file-name
11484                          shell-command-switch command)
11485         (call-process shell-file-name nil t nil
11486                       shell-command-switch command)))))
11487
11488 ;; Summary kill commands.
11489
11490 (defun gnus-summary-edit-global-kill (article)
11491   "Edit the \"global\" kill file."
11492   (interactive (list (gnus-summary-article-number)))
11493   (gnus-group-edit-global-kill article))
11494
11495 (defun gnus-summary-edit-local-kill ()
11496   "Edit a local kill file applied to the current newsgroup."
11497   (interactive)
11498   (setq gnus-current-headers (gnus-summary-article-header))
11499   (gnus-group-edit-local-kill
11500    (gnus-summary-article-number) gnus-newsgroup-name))
11501
11502 ;;; Header reading.
11503
11504 (defun gnus-read-header (id &optional header)
11505   "Read the headers of article ID and enter them into the Gnus system."
11506   (let ((group gnus-newsgroup-name)
11507         (gnus-override-method
11508          (or
11509           gnus-override-method
11510           (and (gnus-news-group-p gnus-newsgroup-name)
11511                (car (gnus-refer-article-methods)))))
11512         where)
11513     ;; First we check to see whether the header in question is already
11514     ;; fetched.
11515     (if (stringp id)
11516         ;; This is a Message-ID.
11517         (setq header (or header (gnus-id-to-header id)))
11518       ;; This is an article number.
11519       (setq header (or header (gnus-summary-article-header id))))
11520     (if (and header
11521              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11522         ;; We have found the header.
11523         header
11524       ;; We have to really fetch the header to this article.
11525       (save-excursion
11526         (set-buffer nntp-server-buffer)
11527         (when (setq where (gnus-request-head id group))
11528           (nnheader-fold-continuation-lines)
11529           (goto-char (point-max))
11530           (insert ".\n")
11531           (goto-char (point-min))
11532           (insert "211 ")
11533           (princ (cond
11534                   ((numberp id) id)
11535                   ((cdr where) (cdr where))
11536                   (header (mail-header-number header))
11537                   (t gnus-reffed-article-number))
11538                  (current-buffer))
11539           (insert " Article retrieved.\n"))
11540         (if (or (not where)
11541                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11542             ()                          ; Malformed head.
11543           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11544             (when (and (stringp id)
11545                        (not (string= (gnus-group-real-name group)
11546                                      (car where))))
11547               ;; If we fetched by Message-ID and the article came
11548               ;; from a different group, we fudge some bogus article
11549               ;; numbers for this article.
11550               (mail-header-set-number header gnus-reffed-article-number))
11551             (save-excursion
11552               (set-buffer gnus-summary-buffer)
11553               (decf gnus-reffed-article-number)
11554               (gnus-remove-header (mail-header-number header))
11555               (push header gnus-newsgroup-headers)
11556               (setq gnus-current-headers header)
11557               (push (mail-header-number header) gnus-newsgroup-limit)))
11558           header)))))
11559
11560 (defun gnus-remove-header (number)
11561   "Remove header NUMBER from `gnus-newsgroup-headers'."
11562   (if (and gnus-newsgroup-headers
11563            (= number (mail-header-number (car gnus-newsgroup-headers))))
11564       (pop gnus-newsgroup-headers)
11565     (let ((headers gnus-newsgroup-headers))
11566       (while (and (cdr headers)
11567                   (not (= number (mail-header-number (cadr headers)))))
11568         (pop headers))
11569       (when (cdr headers)
11570         (setcdr headers (cddr headers))))))
11571
11572 ;;;
11573 ;;; summary highlights
11574 ;;;
11575
11576 (defun gnus-highlight-selected-summary ()
11577   "Highlight selected article in summary buffer."
11578   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11579   (when gnus-summary-selected-face
11580     (save-excursion
11581       (let* ((beg (point-at-bol))
11582              (end (point-at-eol))
11583              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11584              (from (if (get-text-property beg gnus-mouse-face-prop)
11585                        beg
11586                      (or (next-single-property-change
11587                           beg gnus-mouse-face-prop nil end)
11588                          beg)))
11589              (to
11590               (if (= from end)
11591                   (- from 2)
11592                 (or (next-single-property-change
11593                      from gnus-mouse-face-prop nil end)
11594                     end))))
11595         ;; If no mouse-face prop on line we will have to = from = end,
11596         ;; so we highlight the entire line instead.
11597         (when (= (+ to 2) from)
11598           (setq from beg)
11599           (setq to end))
11600         (if gnus-newsgroup-selected-overlay
11601             ;; Move old overlay.
11602             (gnus-move-overlay
11603              gnus-newsgroup-selected-overlay from to (current-buffer))
11604           ;; Create new overlay.
11605           (gnus-overlay-put
11606            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11607            'face gnus-summary-selected-face))))))
11608
11609 (defvar gnus-summary-highlight-line-cached nil)
11610 (defvar gnus-summary-highlight-line-trigger nil)
11611
11612 (defun gnus-summary-highlight-line-0 ()
11613   (if (and (eq gnus-summary-highlight-line-trigger
11614                gnus-summary-highlight)
11615            gnus-summary-highlight-line-cached)
11616       gnus-summary-highlight-line-cached
11617     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11618           gnus-summary-highlight-line-cached
11619           (let* ((cond (list 'cond))
11620                  (c cond)
11621                  (list gnus-summary-highlight))
11622             (while list
11623               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11624                               nil))
11625               (setq c (cdr c)
11626                     list (cdr list)))
11627             (gnus-byte-compile (list 'lambda nil cond))))))
11628
11629 (defun gnus-summary-highlight-line ()
11630   "Highlight current line according to `gnus-summary-highlight'."
11631   (let* ((beg (point-at-bol))
11632          (article (or (gnus-summary-article-number) gnus-current-article))
11633          (score (or (cdr (assq article
11634                                gnus-newsgroup-scored))
11635                     gnus-summary-default-score 0))
11636          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11637          (inhibit-read-only t)
11638          (default gnus-summary-default-score)
11639          (default-high gnus-summary-default-high-score)
11640          (default-low gnus-summary-default-low-score)
11641          (uncached (and gnus-summary-use-undownloaded-faces
11642                         (memq article gnus-newsgroup-undownloaded)
11643                         (not (memq article gnus-newsgroup-cached)))))
11644     (let ((face (funcall (gnus-summary-highlight-line-0))))
11645       (unless (eq face (get-text-property beg 'face))
11646         (gnus-put-text-property-excluding-characters-with-faces
11647          beg (point-at-eol) 'face
11648          (setq face (if (boundp face) (symbol-value face) face)))
11649         (when gnus-summary-highlight-line-function
11650           (funcall gnus-summary-highlight-line-function article face))))))
11651
11652 (defun gnus-update-read-articles (group unread &optional compute)
11653   "Update the list of read articles in GROUP.
11654 UNREAD is a sorted list."
11655   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11656         (info (gnus-get-info group))
11657         (prev 1)
11658         read)
11659     (if (or (not info) (not active))
11660         ;; There is no info on this group if it was, in fact,
11661         ;; killed.  Gnus stores no information on killed groups, so
11662         ;; there's nothing to be done.
11663         ;; One could store the information somewhere temporarily,
11664         ;; perhaps...  Hmmm...
11665         ()
11666       ;; Remove any negative articles numbers.
11667       (while (and unread (< (car unread) 0))
11668         (setq unread (cdr unread)))
11669       ;; Remove any expired article numbers
11670       (while (and unread (< (car unread) (car active)))
11671         (setq unread (cdr unread)))
11672       ;; Compute the ranges of read articles by looking at the list of
11673       ;; unread articles.
11674       (while unread
11675         (when (/= (car unread) prev)
11676           (push (if (= prev (1- (car unread))) prev
11677                   (cons prev (1- (car unread))))
11678                 read))
11679         (setq prev (1+ (car unread)))
11680         (setq unread (cdr unread)))
11681       (when (<= prev (cdr active))
11682         (push (cons prev (cdr active)) read))
11683       (setq read (if (> (length read) 1) (nreverse read) read))
11684       (if compute
11685           read
11686         (save-excursion
11687           (let (setmarkundo)
11688             ;; Propagate the read marks to the backend.
11689             (when (gnus-check-backend-function 'request-set-mark group)
11690               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11691                     (add (gnus-remove-from-range read (gnus-info-read info))))
11692                 (when (or add del)
11693                   (unless (gnus-check-group group)
11694                     (error "Can't open server for %s" group))
11695                   (gnus-request-set-mark
11696                    group (delq nil (list (if add (list add 'add '(read)))
11697                                          (if del (list del 'del '(read))))))
11698                   (setq setmarkundo
11699                         `(gnus-request-set-mark
11700                           ,group
11701                           ',(delq nil (list
11702                                        (if del (list del 'add '(read)))
11703                                        (if add (list add 'del '(read))))))))))
11704             (set-buffer gnus-group-buffer)
11705             (gnus-undo-register
11706               `(progn
11707                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11708                  (gnus-info-set-read ',info ',(gnus-info-read info))
11709                  (gnus-get-unread-articles-in-group ',info
11710                                                     (gnus-active ,group))
11711                  (gnus-group-update-group ,group t)
11712                  ,setmarkundo))))
11713         ;; Enter this list into the group info.
11714         (gnus-info-set-read info read)
11715         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11716         (gnus-get-unread-articles-in-group info (gnus-active group))
11717         t))))
11718
11719 (defun gnus-offer-save-summaries ()
11720   "Offer to save all active summary buffers."
11721   (let (buffers)
11722     ;; Go through all buffers and find all summaries.
11723     (dolist (buffer (buffer-list))
11724       (when (and (setq buffer (buffer-name buffer))
11725                  (string-match "Summary" buffer)
11726                  (with-current-buffer buffer
11727                    ;; We check that this is, indeed, a summary buffer.
11728                    (and (eq major-mode 'gnus-summary-mode)
11729                         ;; Also make sure this isn't bogus.
11730                         gnus-newsgroup-prepared
11731                         ;; Also make sure that this isn't a
11732                         ;; dead summary buffer.
11733                         (not gnus-dead-summary-mode))))
11734         (push buffer buffers)))
11735     ;; Go through all these summary buffers and offer to save them.
11736     (when buffers
11737       (save-excursion
11738         (map-y-or-n-p
11739          "Update summary buffer %s? "
11740          (lambda (buf)
11741            (switch-to-buffer buf)
11742            (gnus-summary-exit))
11743          buffers)))))
11744
11745
11746 ;;; @ for mime-partial
11747 ;;;
11748
11749 (defun gnus-request-partial-message ()
11750   (save-excursion
11751     (let ((number (gnus-summary-article-number))
11752           (group gnus-newsgroup-name)
11753           (mother gnus-article-buffer))
11754       (set-buffer (get-buffer-create " *Partial Article*"))
11755       (erase-buffer)
11756       (setq mime-preview-buffer mother)
11757       (gnus-request-article-this-buffer number group)
11758       (mime-parse-buffer)
11759       )))
11760
11761 (autoload 'mime-combine-message/partial-pieces-automatically
11762   "mime-partial"
11763   "Internal method to combine message/partial messages automatically.")
11764
11765 (mime-add-condition
11766  'action '((type . message)(subtype . partial)
11767            (major-mode . gnus-original-article-mode)
11768            (method . mime-combine-message/partial-pieces-automatically)
11769            (summary-buffer-exp . gnus-summary-buffer)
11770            (request-partial-message-method . gnus-request-partial-message)
11771            ))
11772
11773
11774 ;;; @ for message/rfc822
11775 ;;;
11776
11777 (defun gnus-mime-extract-message/rfc822 (entity situation)
11778   "Burst a forwarded article."
11779   (save-excursion
11780     (set-buffer gnus-summary-buffer)
11781     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11782                                    gnus-newsgroup-name 'gnus-group-history))
11783            (gnus-group-marked (list group))
11784            article info)
11785       (with-temp-buffer
11786         (mime-insert-entity-content entity)
11787         (setq article (gnus-request-accept-article group)))
11788       (when (and (consp article)
11789                  (numberp (setq article (cdr article))))
11790         (setq info (gnus-get-info group))
11791         (gnus-info-set-read info
11792                             (gnus-remove-from-range (gnus-info-read info)
11793                                                     (list article)))
11794         (when (string-equal group gnus-newsgroup-name)
11795           (forward-line 1)
11796           (let (gnus-show-threads)
11797             (gnus-summary-goto-subject article t))
11798           (gnus-summary-clear-mark-forward 1))
11799         (set-buffer gnus-group-buffer)
11800         (gnus-group-get-new-news-this-group nil t)))))
11801
11802 (mime-add-condition
11803  'action '((type . message)(subtype . rfc822)
11804            (major-mode . gnus-original-article-mode)
11805            (method . gnus-mime-extract-message/rfc822)
11806            (mode . "extract")
11807            ))
11808
11809 (mime-add-condition
11810  'action '((type . message)(subtype . news)
11811            (major-mode . gnus-original-article-mode)
11812            (method . gnus-mime-extract-message/rfc822)
11813            (mode . "extract")
11814            ))
11815
11816 (defun gnus-mime-extract-multipart (entity situation)
11817   (let ((children (mime-entity-children entity))
11818         mime-acting-situation-to-override
11819         f)
11820     (while children
11821       (mime-play-entity (car children)
11822                         (cons (assq 'mode situation)
11823                               mime-acting-situation-to-override))
11824       (setq children (cdr children)))
11825     (if (setq f (cdr (assq 'after-method
11826                            mime-acting-situation-to-override)))
11827         (eval f)
11828       )))
11829
11830 (mime-add-condition
11831  'action '((type . multipart)
11832            (method . gnus-mime-extract-multipart)
11833            (mode . "extract")
11834            )
11835  'with-default)
11836
11837
11838 ;;; @ end
11839 ;;;
11840
11841 (defun gnus-summary-inherit-default-charset ()
11842   "Import `default-mime-charset' from summary buffer.
11843 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11844 of FLIM is used."
11845   (if (buffer-live-p gnus-summary-buffer)
11846       (let (d-m-c d-m-c-u)
11847         (with-current-buffer gnus-summary-buffer
11848           (setq d-m-c (if (local-variable-p 'default-mime-charset
11849                                             gnus-summary-buffer)
11850                           default-mime-charset
11851                         t)
11852                 ;; LIMIT
11853                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11854                                               gnus-summary-buffer)
11855                             (symbol-value 'default-mime-charset-unlimited)
11856                           t)))
11857         (if (eq t d-m-c)
11858             (kill-local-variable 'default-mime-charset)
11859           (set (make-local-variable 'default-mime-charset) d-m-c))
11860         (if (eq t d-m-c-u)
11861             (kill-local-variable 'default-mime-charset-unlimited)
11862           (set (make-local-variable 'default-mime-charset-unlimited)
11863                d-m-c-u)))))
11864
11865 (defun gnus-summary-setup-default-charset ()
11866   "Setup newsgroup default charset."
11867   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11868       (progn
11869         (setq gnus-newsgroup-charset nil)
11870         (set (make-local-variable 'default-mime-charset) nil)
11871         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11872           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11873     (let ((ignored-charsets
11874            (or gnus-newsgroup-ephemeral-ignored-charsets
11875                (append
11876                 (and gnus-newsgroup-name
11877                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11878                 gnus-newsgroup-ignored-charsets)))
11879           charset)
11880       (setq gnus-newsgroup-charset
11881             (or gnus-newsgroup-ephemeral-charset
11882                 (when (and gnus-newsgroup-name
11883                            (setq charset (gnus-parameter-charset
11884                                           gnus-newsgroup-name)))
11885                   (make-local-variable 'default-mime-charset)
11886                   (setq default-mime-charset charset))
11887                 gnus-default-charset))
11888       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11889            ignored-charsets))))
11890
11891 ;;;
11892 ;;; Mime Commands
11893 ;;;
11894
11895 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11896   "Display the current article buffer fully MIME-buttonized.
11897 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11898 treated as multipart/mixed."
11899   (interactive "P")
11900   (require 'gnus-art)
11901   (let ((gnus-unbuttonized-mime-types nil)
11902         (gnus-mime-display-multipart-as-mixed show-all-parts))
11903     (gnus-summary-show-article)))
11904
11905 (defun gnus-summary-repair-multipart (article)
11906   "Add a Content-Type header to a multipart article without one."
11907   (interactive (list (gnus-summary-article-number)))
11908   (gnus-with-article article
11909     (message-narrow-to-head)
11910     (message-remove-header "Mime-Version")
11911     (goto-char (point-max))
11912     (insert "Mime-Version: 1.0\n")
11913     (widen)
11914     (when (search-forward "\n--" nil t)
11915       (let ((separator (buffer-substring (point) (point-at-eol))))
11916         (message-narrow-to-head)
11917         (message-remove-header "Content-Type")
11918         (goto-char (point-max))
11919         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11920                         separator))
11921         (widen))))
11922   (let (gnus-mark-article-hook)
11923     (gnus-summary-select-article t t nil article)))
11924
11925 (defun gnus-summary-toggle-display-buttonized ()
11926   "Toggle the buttonizing of the article buffer."
11927   (interactive)
11928   (require 'gnus-art)
11929   (if (setq gnus-inhibit-mime-unbuttonizing
11930             (not gnus-inhibit-mime-unbuttonizing))
11931       (let ((gnus-unbuttonized-mime-types nil))
11932         (gnus-summary-show-article))
11933     (gnus-summary-show-article)))
11934
11935 ;;;
11936 ;;; Intelli-mouse commmands
11937 ;;;
11938
11939 (defun gnus-wheel-summary-scroll (event)
11940   (interactive "e")
11941   (let ((amount (if (memq 'shift (event-modifiers event))
11942                     (car gnus-wheel-scroll-amount)
11943                   (cdr gnus-wheel-scroll-amount)))
11944         (direction (- (* (static-if (featurep 'xemacs)
11945                              (event-button event)
11946                            (cond ((eq 'mouse-4 (event-basic-type event))
11947                                   4)
11948                                  ((eq 'mouse-5 (event-basic-type event))
11949                                   5)))
11950                          2) 9))
11951         edge)
11952     (gnus-summary-scroll-up (* amount direction))
11953     (when (gnus-eval-in-buffer-window gnus-article-buffer
11954             (save-restriction
11955               (widen)
11956               (and (if (< 0 direction)
11957                        (gnus-article-next-page 0)
11958                      (gnus-article-prev-page 0)
11959                      (bobp))
11960                    (if (setq edge (get-text-property
11961                                    (point-min) 'gnus-wheel-edge))
11962                        (setq edge (* edge direction))
11963                      (setq edge -1))
11964                    (or (plusp edge)
11965                        (let ((buffer-read-only nil)
11966                              (inhibit-read-only t))
11967                          (put-text-property (point-min) (point-max)
11968                                             'gnus-wheel-edge direction)
11969                          nil))
11970                    (or (> edge gnus-wheel-edge-resistance)
11971                        (let ((buffer-read-only nil)
11972                              (inhibit-read-only t))
11973                          (put-text-property (point-min) (point-max)
11974                                             'gnus-wheel-edge
11975                                             (* (1+ edge) direction))
11976                          nil))
11977                    (eq last-command 'gnus-wheel-summary-scroll))))
11978       (gnus-summary-next-article nil nil (minusp direction)))))
11979
11980 (defun gnus-wheel-install ()
11981   "Enable mouse wheel support on summary window."
11982   (when gnus-use-wheel
11983     (let ((keys
11984            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11985       (dolist (key keys)
11986         (define-key gnus-summary-mode-map key
11987           'gnus-wheel-summary-scroll)))))
11988
11989 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11990
11991 ;;;
11992 ;;; Traditional PGP commmands
11993 ;;;
11994
11995 (defun gnus-summary-decrypt-article (&optional force)
11996   "Decrypt the current article in traditional PGP way.
11997 This will have permanent effect only in mail groups.
11998 If FORCE is non-nil, allow editing of articles even in read-only
11999 groups."
12000   (interactive "P")
12001   (gnus-summary-select-article t)
12002   (gnus-eval-in-buffer-window gnus-article-buffer
12003     (save-excursion
12004       (save-restriction
12005         (widen)
12006         (goto-char (point-min))
12007         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
12008           (error "Not a traditional PGP message!"))
12009         (let ((armor-start (match-beginning 0)))
12010           (if (and (pgg-decrypt-region armor-start (point-max))
12011                    (or force (not (gnus-group-read-only-p))))
12012               (let ((inhibit-read-only t)
12013                     buffer-read-only)
12014                 (delete-region armor-start
12015                                (progn
12016                                  (re-search-forward "^-+END PGP" nil t)
12017                                  (beginning-of-line 2)
12018                                  (point)))
12019                 (insert-buffer-substring pgg-output-buffer))))))))
12020
12021 (defun gnus-summary-verify-article ()
12022   "Verify the current article in traditional PGP way."
12023   (interactive)
12024   (save-excursion
12025     (set-buffer gnus-original-article-buffer)
12026     (goto-char (point-min))
12027     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
12028       (error "Not a traditional PGP message!"))
12029     (re-search-forward "^-+END PGP" nil t)
12030     (beginning-of-line 2)
12031     (call-interactively (function pgg-verify-region))))
12032
12033 ;;;
12034 ;;; Generic summary marking commands
12035 ;;;
12036
12037 (defvar gnus-summary-marking-alist
12038   '((read gnus-del-mark "d")
12039     (unread gnus-unread-mark "u")
12040     (ticked gnus-ticked-mark "!")
12041     (dormant gnus-dormant-mark "?")
12042     (expirable gnus-expirable-mark "e"))
12043   "An alist of names/marks/keystrokes.")
12044
12045 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12046 (defvar gnus-summary-mark-map)
12047
12048 (defun gnus-summary-make-all-marking-commands ()
12049   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12050   (dolist (elem gnus-summary-marking-alist)
12051     (apply 'gnus-summary-make-marking-command elem)))
12052
12053 (defun gnus-summary-make-marking-command (name mark keystroke)
12054   (let ((map (make-sparse-keymap)))
12055     (define-key gnus-summary-generic-mark-map keystroke map)
12056     (dolist (lway `((next "next" next nil "n")
12057                     (next-unread "next unread" next t "N")
12058                     (prev "previous" prev nil "p")
12059                     (prev-unread "previous unread" prev t "P")
12060                     (nomove "" nil nil ,keystroke)))
12061       (let ((func (gnus-summary-make-marking-command-1
12062                    mark (car lway) lway name)))
12063         (setq func (eval func))
12064         (define-key map (nth 4 lway) func)))))
12065
12066 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12067   `(defun ,(intern
12068             (format "gnus-summary-put-mark-as-%s%s"
12069                     name (if (eq way 'nomove)
12070                              ""
12071                            (concat "-" (symbol-name way)))))
12072      (n)
12073      ,(format
12074        "Mark the current article as %s%s.
12075 If N, the prefix, then repeat N times.
12076 If N is negative, move in reverse order.
12077 The difference between N and the actual number of articles marked is
12078 returned."
12079        name (car (cdr lway)))
12080      (interactive "p")
12081      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12082
12083 (defun gnus-summary-generic-mark (n mark move unread)
12084   "Mark N articles with MARK."
12085   (unless (eq major-mode 'gnus-summary-mode)
12086     (error "This command can only be used in the summary buffer"))
12087   (gnus-summary-show-thread)
12088   (let ((nummove
12089          (cond
12090           ((eq move 'next) 1)
12091           ((eq move 'prev) -1)
12092           (t 0))))
12093     (if (zerop nummove)
12094         (setq n 1)
12095       (when (< n 0)
12096         (setq n (abs n)
12097               nummove (* -1 nummove))))
12098     (while (and (> n 0)
12099                 (gnus-summary-mark-article nil mark)
12100                 (zerop (gnus-summary-next-subject nummove unread t)))
12101       (setq n (1- n)))
12102     (when (/= 0 n)
12103       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12104     (gnus-summary-recenter)
12105     (gnus-summary-position-point)
12106     (gnus-set-mode-line 'summary)
12107     n))
12108
12109 (defun gnus-summary-insert-articles (articles)
12110   (when (setq articles
12111               (gnus-sorted-difference articles
12112                                       (mapcar (lambda (h)
12113                                                 (mail-header-number h))
12114                                               gnus-newsgroup-headers)))
12115     (setq gnus-newsgroup-headers
12116           (gnus-merge 'list
12117                       gnus-newsgroup-headers
12118                       (gnus-fetch-headers articles)
12119                       'gnus-article-sort-by-number))
12120     ;; Suppress duplicates?
12121     (when gnus-suppress-duplicates
12122       (gnus-dup-suppress-articles))
12123
12124     ;; We might want to build some more threads first.
12125     (when (and gnus-fetch-old-headers
12126                (eq gnus-headers-retrieved-by 'nov))
12127       (if (eq gnus-fetch-old-headers 'invisible)
12128           (gnus-build-all-threads)
12129         (gnus-build-old-threads)))
12130     ;; Let the Gnus agent mark articles as read.
12131     (when gnus-agent
12132       (gnus-agent-get-undownloaded-list))
12133     ;; Remove list identifiers from subject
12134     (when gnus-list-identifiers
12135       (gnus-summary-remove-list-identifiers))
12136     ;; First and last article in this newsgroup.
12137     (when gnus-newsgroup-headers
12138       (setq gnus-newsgroup-begin
12139             (mail-header-number (car gnus-newsgroup-headers))
12140             gnus-newsgroup-end
12141             (mail-header-number
12142              (gnus-last-element gnus-newsgroup-headers))))
12143     (when gnus-use-scoring
12144       (gnus-possibly-score-headers))))
12145
12146 (defun gnus-summary-insert-old-articles (&optional all)
12147   "Insert all old articles in this group.
12148 If ALL is non-nil, already read articles become readable.
12149 If ALL is a number, fetch this number of articles."
12150   (interactive "P")
12151   (prog1
12152       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12153             older len)
12154         (setq older
12155               ;; Some nntp servers lie about their active range.  When
12156               ;; this happens, the active range can be in the millions.
12157               ;; Use a compressed range to avoid creating a huge list.
12158               (gnus-range-difference (list gnus-newsgroup-active) old))
12159         (setq len (gnus-range-length older))
12160         (cond
12161          ((null older) nil)
12162          ((numberp all)
12163           (if (< all len)
12164               (let ((older-range (nreverse older)))
12165                 (setq older nil)
12166
12167                 (while (> all 0)
12168                   (let* ((r (pop older-range))
12169                          (min (if (numberp r) r (car r)))
12170                          (max (if (numberp r) r (cdr r))))
12171                     (while (and (<= min max)
12172                                 (> all 0))
12173                       (push max older)
12174                       (setq all (1- all)
12175                             max (1- max))))))
12176             (setq older (gnus-uncompress-range older))))
12177          (all
12178           (setq older (gnus-uncompress-range older)))
12179          (t
12180           (when (and (numberp gnus-large-newsgroup)
12181                    (> len gnus-large-newsgroup))
12182               (let* ((cursor-in-echo-area nil)
12183                      (initial (gnus-parameter-large-newsgroup-initial
12184                                gnus-newsgroup-name))
12185                      (input
12186                       (read-string
12187                        (format
12188                         "How many articles from %s (%s %d): "
12189                         (gnus-limit-string
12190                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12191                         (if initial "max" "default")
12192                         len)
12193                        (if initial
12194                            (cons (number-to-string initial)
12195                                  0)))))
12196                 (unless (string-match "^[ \t]*$" input)
12197                   (setq all (string-to-number input))
12198                   (if (< all len)
12199                       (let ((older-range (nreverse older)))
12200                         (setq older nil)
12201
12202                         (while (> all 0)
12203                           (let* ((r (pop older-range))
12204                                  (min (if (numberp r) r (car r)))
12205                                  (max (if (numberp r) r (cdr r))))
12206                             (while (and (<= min max)
12207                                         (> all 0))
12208                               (push max older)
12209                               (setq all (1- all)
12210                                     max (1- max))))))))))
12211           (setq older (gnus-uncompress-range older))))
12212         (if (not older)
12213             (message "No old news.")
12214           (gnus-summary-insert-articles older)
12215           (gnus-summary-limit (gnus-sorted-nunion old older))))
12216     (gnus-summary-position-point)))
12217
12218 (defun gnus-summary-insert-new-articles ()
12219   "Insert all new articles in this group."
12220   (interactive)
12221   (prog1
12222       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12223             (old-active gnus-newsgroup-active)
12224             (nnmail-fetched-sources (list t))
12225             i new)
12226         (setq gnus-newsgroup-active
12227               (gnus-activate-group gnus-newsgroup-name 'scan))
12228         (setq i (cdr gnus-newsgroup-active))
12229         (while (> i (cdr old-active))
12230           (push i new)
12231           (decf i))
12232         (if (not new)
12233             (message "No gnus is bad news")
12234           (gnus-summary-insert-articles new)
12235           (setq gnus-newsgroup-unreads
12236                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12237           (gnus-summary-limit (gnus-sorted-nunion old new))))
12238     (gnus-summary-position-point)))
12239
12240 (gnus-summary-make-all-marking-commands)
12241
12242 (gnus-ems-redefine)
12243
12244 (provide 'gnus-sum)
12245
12246 (run-hooks 'gnus-sum-load-hook)
12247
12248 ;; Local Variables:
12249 ;; coding: iso-8859-1
12250 ;; End:
12251
12252 ;;; gnus-sum.el ends here