(gnus-summary-wash-map): Remove gnus-summary-toggle-mime.
[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 (regexp-quote user-mail-address))
1085   "*Regexp of From headers that may be suppressed in favor of To headers."
1086   :version "21.1"
1087   :group 'gnus-summary
1088   :type 'regexp)
1089
1090 (defcustom gnus-summary-to-prefix "-> "
1091   "*String prefixed to the To field in the summary line when
1092 using `gnus-ignored-from-addresses'."
1093   :version "22.1"
1094   :group 'gnus-summary
1095   :type 'string)
1096
1097 (defcustom gnus-summary-newsgroup-prefix "=> "
1098   "*String prefixed to the Newsgroup field in the summary
1099 line when using `gnus-ignored-from-addresses'."
1100   :version "22.1"
1101   :group 'gnus-summary
1102   :type 'string)
1103
1104 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1105   "List of charsets that should be ignored.
1106 When these charsets are used in the \"charset\" parameter, the
1107 default charset will be used instead."
1108   :version "21.1"
1109   :type '(repeat symbol)
1110   :group 'gnus-charset)
1111
1112 (gnus-define-group-parameter
1113  ignored-charsets
1114  :type list
1115  :function-document
1116  "Return the ignored charsets of GROUP."
1117  :variable gnus-group-ignored-charsets-alist
1118  :variable-default
1119  '(("alt\\.chinese\\.text" iso-8859-1))
1120  :variable-document
1121  "Alist of regexps (to match group names) and charsets that should be ignored.
1122 When these charsets are used in the \"charset\" parameter, the
1123 default charset will be used instead."
1124  :variable-group gnus-charset
1125  :variable-type '(repeat (cons (regexp :tag "Group")
1126                                (repeat symbol)))
1127  :parameter-type '(choice :tag "Ignored charsets"
1128                           :value nil
1129                           (repeat (symbol)))
1130  :parameter-document       "\
1131 List of charsets that should be ignored.
1132
1133 When these charsets are used in the \"charset\" parameter, the
1134 default charset will be used instead.")
1135
1136 (defcustom gnus-group-highlight-words-alist nil
1137   "Alist of group regexps and highlight regexps.
1138 This variable uses the same syntax as `gnus-emphasis-alist'."
1139   :version "21.1"
1140   :type '(repeat (cons (regexp :tag "Group")
1141                        (repeat (list (regexp :tag "Highlight regexp")
1142                                      (number :tag "Group for entire word" 0)
1143                                      (number :tag "Group for displayed part" 0)
1144                                      (symbol :tag "Face"
1145                                              gnus-emphasis-highlight-words)))))
1146   :group 'gnus-summary-visual)
1147
1148 (defcustom gnus-use-wheel nil
1149   "Use Intelli-mouse on summary movement"
1150   :type 'boolean
1151   :group 'gnus-summary-maneuvering)
1152
1153 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1154   "Amount to scroll messages by spinning the mouse wheel.
1155 This is actually a cons cell, where the first item is the amount to scroll
1156 on a normal wheel event, and the second is the amount to scroll when the
1157 wheel is moved with the shift key depressed."
1158   :type '(cons (integer :tag "Shift") integer)
1159   :group 'gnus-summary-maneuvering)
1160
1161 (defcustom gnus-wheel-edge-resistance 2
1162   "How hard it should be to change the current article
1163 by moving the mouse over the edge of the article window."
1164   :type 'integer
1165   :group 'gnus-summary-maneuvering)
1166
1167 (defcustom gnus-summary-show-article-charset-alist
1168   nil
1169   "Alist of number and charset.
1170 The article will be shown with the charset corresponding to the
1171 numbered argument.
1172 For example: ((1 . cn-gb-2312) (2 . big5))."
1173   :version "21.1"
1174   :type '(repeat (cons (number :tag "Argument" 1)
1175                        (symbol :tag "Charset")))
1176   :group 'gnus-charset)
1177
1178 (defcustom gnus-preserve-marks t
1179   "Whether marks are preserved when moving, copying and respooling messages."
1180   :version "21.1"
1181   :type 'boolean
1182   :group 'gnus-summary-marks)
1183
1184 (defcustom gnus-alter-articles-to-read-function nil
1185   "Function to be called to alter the list of articles to be selected."
1186   :type '(choice (const nil) function)
1187   :group 'gnus-summary)
1188
1189 (defcustom gnus-orphan-score nil
1190   "*All orphans get this score added.  Set in the score file."
1191   :group 'gnus-score-default
1192   :type '(choice (const nil)
1193                  integer))
1194
1195 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1196   "*A regexp to match MIME parts when saving multiple parts of a
1197 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1198 This regexp will be used by default when prompting the user for which
1199 type of files to save."
1200   :group 'gnus-summary
1201   :type 'regexp)
1202
1203 (defcustom gnus-read-all-available-headers nil
1204   "Whether Gnus should parse all headers made available to it.
1205 This is mostly relevant for slow back ends where the user may
1206 wish to widen the summary buffer to include all headers
1207 that were fetched.  Say, for nnultimate groups."
1208   :version "22.1"
1209   :group 'gnus-summary
1210   :type '(choice boolean regexp))
1211
1212 (defcustom gnus-summary-muttprint-program "muttprint"
1213   "Command (and optional arguments) used to run Muttprint."
1214   :version "22.1"
1215   :group 'gnus-summary
1216   :type 'string)
1217
1218 (defcustom gnus-article-loose-mime t
1219   "If non-nil, don't require MIME-Version header.
1220 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1221 supply the MIME-Version header or deliberately strip it from the mail.
1222 If non-nil (the default), Gnus will treat some articles as MIME
1223 even if the MIME-Version header is missing."
1224   :version "22.1"
1225   :type 'boolean
1226   :group 'gnus-article-mime)
1227
1228 (defcustom gnus-article-emulate-mime t
1229   "If non-nil, use MIME emulation for uuencode and the like.
1230 This means that Gnus will search message bodies for text that look
1231 like uuencoded bits, yEncoded bits, and so on, and present that using
1232 the normal Gnus MIME machinery."
1233   :version "22.1"
1234   :type 'boolean
1235   :group 'gnus-article-mime)
1236
1237 ;;; Internal variables
1238
1239 (defvar gnus-summary-display-cache nil)
1240 (defvar gnus-article-mime-handles nil)
1241 (defvar gnus-article-decoded-p nil)
1242 (defvar gnus-article-charset nil)
1243 (defvar gnus-article-ignored-charsets nil)
1244 (defvar gnus-scores-exclude-files nil)
1245 (defvar gnus-page-broken nil)
1246
1247 (defvar gnus-original-article nil)
1248 (defvar gnus-article-internal-prepare-hook nil)
1249 (defvar gnus-newsgroup-process-stack nil)
1250
1251 (defvar gnus-thread-indent-array nil)
1252 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1253 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1254   "Function called to sort the articles within a thread after it has been gathered together.")
1255
1256 (defvar gnus-summary-save-parts-type-history nil)
1257 (defvar gnus-summary-save-parts-last-directory nil)
1258
1259 ;; Avoid highlighting in kill files.
1260 (defvar gnus-summary-inhibit-highlight nil)
1261 (defvar gnus-newsgroup-selected-overlay nil)
1262 (defvar gnus-inhibit-limiting nil)
1263 (defvar gnus-newsgroup-adaptive-score-file nil)
1264 (defvar gnus-current-score-file nil)
1265 (defvar gnus-current-move-group nil)
1266 (defvar gnus-current-copy-group nil)
1267 (defvar gnus-current-crosspost-group nil)
1268 (defvar gnus-newsgroup-display nil)
1269
1270 (defvar gnus-newsgroup-dependencies nil)
1271 (defvar gnus-newsgroup-adaptive nil)
1272 (defvar gnus-summary-display-article-function nil)
1273 (defvar gnus-summary-highlight-line-function nil
1274   "Function called after highlighting a summary line.")
1275
1276 (defvar gnus-summary-line-format-alist
1277   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1278     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1279     (?s gnus-tmp-subject-or-nil ?s)
1280     (?n gnus-tmp-name ?s)
1281     (?A (std11-address-string
1282          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1283     (?a (or (std11-full-name-string
1284              (car (mime-entity-read-field gnus-tmp-header 'From)))
1285             gnus-tmp-from) ?s)
1286     (?F gnus-tmp-from ?s)
1287     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1288     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1289     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1290     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1291     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1292     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1293     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1294     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1295     (?L gnus-tmp-lines ?s)
1296     (?O gnus-tmp-downloaded ?c)
1297     (?I gnus-tmp-indentation ?s)
1298     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1299     (?R gnus-tmp-replied ?c)
1300     (?\[ gnus-tmp-opening-bracket ?c)
1301     (?\] gnus-tmp-closing-bracket ?c)
1302     (?\> (make-string gnus-tmp-level ? ) ?s)
1303     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1304     (?i gnus-tmp-score ?d)
1305     (?z gnus-tmp-score-char ?c)
1306     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1307     (?U gnus-tmp-unread ?c)
1308     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1309         ?s)
1310     (?t (gnus-summary-number-of-articles-in-thread
1311          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1312         ?d)
1313     (?e (gnus-summary-number-of-articles-in-thread
1314          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1315         ?c)
1316     (?u gnus-tmp-user-defined ?s)
1317     (?P (gnus-pick-line-number) ?d)
1318     (?B gnus-tmp-thread-tree-header-string ?s)
1319     (user-date (gnus-user-date
1320                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1321   "An alist of format specifications that can appear in summary lines.
1322 These are paired with what variables they correspond with, along with
1323 the type of the variable (string, integer, character, etc).")
1324
1325 (defvar gnus-summary-dummy-line-format-alist
1326   `((?S gnus-tmp-subject ?s)
1327     (?N gnus-tmp-number ?d)
1328     (?u gnus-tmp-user-defined ?s)))
1329
1330 (defvar gnus-summary-mode-line-format-alist
1331   `((?G gnus-tmp-group-name ?s)
1332     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1333     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1334     (?A gnus-tmp-article-number ?d)
1335     (?Z gnus-tmp-unread-and-unselected ?s)
1336     (?V gnus-version ?s)
1337     (?U gnus-tmp-unread-and-unticked ?d)
1338     (?S gnus-tmp-subject ?s)
1339     (?e gnus-tmp-unselected ?d)
1340     (?u gnus-tmp-user-defined ?s)
1341     (?d (length gnus-newsgroup-dormant) ?d)
1342     (?t (length gnus-newsgroup-marked) ?d)
1343     (?h (length gnus-newsgroup-spam-marked) ?d)
1344     (?r (length gnus-newsgroup-reads) ?d)
1345     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1346     (?E gnus-newsgroup-expunged-tally ?d)
1347     (?s (gnus-current-score-file-nondirectory) ?s)))
1348
1349 (defvar gnus-last-search-regexp nil
1350   "Default regexp for article search command.")
1351
1352 (defvar gnus-summary-search-article-matched-data nil
1353   "Last matched data of article search command.  It is the local variable
1354 in `gnus-article-buffer' which consists of the list of start position,
1355 end position and text.")
1356
1357 (defvar gnus-last-shell-command nil
1358   "Default shell command on article.")
1359
1360 (defvar gnus-newsgroup-agentized nil
1361   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1362 (defvar gnus-newsgroup-begin nil)
1363 (defvar gnus-newsgroup-end nil)
1364 (defvar gnus-newsgroup-last-rmail nil)
1365 (defvar gnus-newsgroup-last-mail nil)
1366 (defvar gnus-newsgroup-last-folder nil)
1367 (defvar gnus-newsgroup-last-file nil)
1368 (defvar gnus-newsgroup-auto-expire nil)
1369 (defvar gnus-newsgroup-active nil)
1370
1371 (defvar gnus-newsgroup-data nil)
1372 (defvar gnus-newsgroup-data-reverse nil)
1373 (defvar gnus-newsgroup-limit nil)
1374 (defvar gnus-newsgroup-limits nil)
1375 (defvar gnus-summary-use-undownloaded-faces nil)
1376
1377 (defvar gnus-newsgroup-unreads nil
1378   "Sorted list of unread articles in the current newsgroup.")
1379
1380 (defvar gnus-newsgroup-unselected nil
1381   "Sorted list of unselected unread articles in the current newsgroup.")
1382
1383 (defvar gnus-newsgroup-reads nil
1384   "Alist of read articles and article marks in the current newsgroup.")
1385
1386 (defvar gnus-newsgroup-expunged-tally nil)
1387
1388 (defvar gnus-newsgroup-marked nil
1389   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1390
1391 (defvar gnus-newsgroup-spam-marked nil
1392   "List of ranges of articles that have been marked as spam.")
1393
1394 (defvar gnus-newsgroup-killed nil
1395   "List of ranges of articles that have been through the scoring process.")
1396
1397 (defvar gnus-newsgroup-cached nil
1398   "Sorted list of articles that come from the article cache.")
1399
1400 (defvar gnus-newsgroup-saved nil
1401   "List of articles that have been saved.")
1402
1403 (defvar gnus-newsgroup-kill-headers nil)
1404
1405 (defvar gnus-newsgroup-replied nil
1406   "List of articles that have been replied to in the current newsgroup.")
1407
1408 (defvar gnus-newsgroup-forwarded nil
1409   "List of articles that have been forwarded in the current newsgroup.")
1410
1411 (defvar gnus-newsgroup-recent nil
1412   "List of articles that have are recent in the current newsgroup.")
1413
1414 (defvar gnus-newsgroup-expirable nil
1415   "Sorted list of articles in the current newsgroup that can be expired.")
1416
1417 (defvar gnus-newsgroup-processable nil
1418   "List of articles in the current newsgroup that can be processed.")
1419
1420 (defvar gnus-newsgroup-downloadable nil
1421   "Sorted list of articles in the current newsgroup that can be processed.")
1422
1423 (defvar gnus-newsgroup-unfetched nil
1424   "Sorted list of articles in the current newsgroup whose headers have
1425 not been fetched into the agent.
1426
1427 This list will always be a subset of gnus-newsgroup-undownloaded.")
1428
1429 (defvar gnus-newsgroup-undownloaded nil
1430   "List of articles in the current newsgroup that haven't been downloaded.")
1431
1432 (defvar gnus-newsgroup-unsendable nil
1433   "List of articles in the current newsgroup that won't be sent.")
1434
1435 (defvar gnus-newsgroup-bookmarks nil
1436   "List of articles in the current newsgroup that have bookmarks.")
1437
1438 (defvar gnus-newsgroup-dormant nil
1439   "Sorted list of dormant articles in the current newsgroup.")
1440
1441 (defvar gnus-newsgroup-unseen nil
1442   "List of unseen articles in the current newsgroup.")
1443
1444 (defvar gnus-newsgroup-seen nil
1445   "Range of seen articles in the current newsgroup.")
1446
1447 (defvar gnus-newsgroup-articles nil
1448   "List of articles in the current newsgroup.")
1449
1450 (defvar gnus-newsgroup-scored nil
1451   "List of scored articles in the current newsgroup.")
1452
1453 (defvar gnus-newsgroup-incorporated nil
1454   "List of incorporated articles in the current newsgroup.")
1455
1456 (defvar gnus-newsgroup-headers nil
1457   "List of article headers in the current newsgroup.")
1458
1459 (defvar gnus-newsgroup-threads nil)
1460
1461 (defvar gnus-newsgroup-prepared nil
1462   "Whether the current group has been prepared properly.")
1463
1464 (defvar gnus-newsgroup-ancient nil
1465   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1466
1467 (defvar gnus-newsgroup-sparse nil)
1468
1469 (defvar gnus-current-article nil)
1470 (defvar gnus-article-current nil)
1471 (defvar gnus-current-headers nil)
1472 (defvar gnus-have-all-headers nil)
1473 (defvar gnus-last-article nil)
1474 (defvar gnus-newsgroup-history nil)
1475 (defvar gnus-newsgroup-charset nil)
1476 (defvar gnus-newsgroup-ephemeral-charset nil)
1477 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1478
1479 (defvar gnus-article-before-search nil)
1480
1481 (defvar gnus-summary-local-variables
1482   '(gnus-newsgroup-name
1483     gnus-newsgroup-begin gnus-newsgroup-end
1484     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1485     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1486     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1487     gnus-newsgroup-unselected gnus-newsgroup-marked
1488     gnus-newsgroup-spam-marked
1489     gnus-newsgroup-reads gnus-newsgroup-saved
1490     gnus-newsgroup-replied gnus-newsgroup-forwarded
1491     gnus-newsgroup-recent
1492     gnus-newsgroup-expirable
1493     gnus-newsgroup-processable gnus-newsgroup-killed
1494     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1495     gnus-newsgroup-unfetched
1496     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1497     gnus-newsgroup-seen gnus-newsgroup-articles
1498     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1499     gnus-newsgroup-headers gnus-newsgroup-threads
1500     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1501     gnus-current-article gnus-current-headers gnus-have-all-headers
1502     gnus-last-article gnus-article-internal-prepare-hook
1503     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1504     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1505     gnus-thread-expunge-below
1506     gnus-score-alist gnus-current-score-file
1507     (gnus-summary-expunge-below . global)
1508     (gnus-summary-mark-below . global)
1509     (gnus-orphan-score . global)
1510     gnus-newsgroup-active gnus-scores-exclude-files
1511     gnus-newsgroup-history gnus-newsgroup-ancient
1512     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1513     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1514     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1515     (gnus-newsgroup-expunged-tally . 0)
1516     gnus-cache-removable-articles gnus-newsgroup-cached
1517     gnus-newsgroup-data gnus-newsgroup-data-reverse
1518     gnus-newsgroup-limit gnus-newsgroup-limits
1519     gnus-newsgroup-charset gnus-newsgroup-display
1520     gnus-summary-use-undownloaded-faces
1521     gnus-newsgroup-incorporated)
1522   "Variables that are buffer-local to the summary buffers.")
1523
1524 (defvar gnus-newsgroup-variables nil
1525   "A list of variables that have separate values in different newsgroups.
1526 A list of newsgroup (summary buffer) local variables, or cons of
1527 variables and their default expressions to be evalled (when the default
1528 values are not nil), that should be made global while the summary buffer
1529 is active.
1530
1531 Note: The default expressions will be evaluated (using function `eval')
1532 before assignment to the local variable rather than just assigned to it.
1533 If the default expression is the symbol `global', that symbol will not
1534 be evaluated but the global value of the local variable will be used
1535 instead.
1536
1537 These variables can be used to set variables in the group parameters
1538 while still allowing them to affect operations done in other buffers.
1539 For example:
1540
1541 \(setq gnus-newsgroup-variables
1542      '(message-use-followup-to
1543        (gnus-visible-headers .
1544          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1545 ")
1546
1547 ;; Byte-compiler warning.
1548 (eval-when-compile
1549   ;; Bind features so that require will believe that gnus-sum has
1550   ;; already been loaded (avoids infinite recursion)
1551   (let ((features (cons 'gnus-sum features)))
1552     ;; Several of the declarations in gnus-sum are needed to load the
1553     ;; following files. Right now, these definitions have been
1554     ;; compiled but not defined (evaluated).  We could either do a
1555     ;; eval-and-compile about all of the declarations or evaluate the
1556     ;; source file.
1557     (if (boundp 'gnus-newsgroup-variables)
1558         nil
1559       (load "gnus-sum.el" t t t))
1560     (require 'gnus)
1561     (require 'gnus-art)))
1562
1563 ;; Subject simplification.
1564
1565 (defun gnus-simplify-whitespace (str)
1566   "Remove excessive whitespace from STR."
1567   ;; Multiple spaces.
1568   (while (string-match "[ \t][ \t]+" str)
1569     (setq str (concat (substring str 0 (match-beginning 0))
1570                         " "
1571                         (substring str (match-end 0)))))
1572   ;; Leading spaces.
1573   (when (string-match "^[ \t]+" str)
1574     (setq str (substring str (match-end 0))))
1575   ;; Trailing spaces.
1576   (when (string-match "[ \t]+$" str)
1577     (setq str (substring str 0 (match-beginning 0))))
1578   str)
1579
1580 (defun gnus-simplify-all-whitespace (str)
1581   "Remove all whitespace from STR."
1582   (while (string-match "[ \t\n]+" str)
1583     (setq str (replace-match "" nil nil str)))
1584   str)
1585
1586 (defsubst gnus-simplify-subject-re (subject)
1587   "Remove \"Re:\" from subject lines."
1588   (if (string-match message-subject-re-regexp subject)
1589       (substring subject (match-end 0))
1590     subject))
1591
1592 (defun gnus-simplify-subject (subject &optional re-only)
1593   "Remove `Re:' and words in parentheses.
1594 If RE-ONLY is non-nil, strip leading `Re:'s only."
1595   (let ((case-fold-search t))           ;Ignore case.
1596     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1597     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1598       (setq subject (substring subject (match-end 0))))
1599     ;; Remove uninteresting prefixes.
1600     (when (and (not re-only)
1601                gnus-simplify-ignored-prefixes
1602                (string-match gnus-simplify-ignored-prefixes subject))
1603       (setq subject (substring subject (match-end 0))))
1604     ;; Remove words in parentheses from end.
1605     (unless re-only
1606       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1607         (setq subject (substring subject 0 (match-beginning 0)))))
1608     ;; Return subject string.
1609     subject))
1610
1611 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1612 ;; all whitespace.
1613 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1614   (goto-char (point-min))
1615   (while (re-search-forward regexp nil t)
1616     (replace-match (or newtext ""))))
1617
1618 (defun gnus-simplify-buffer-fuzzy ()
1619   "Simplify string in the buffer fuzzily.
1620 The string in the accessible portion of the current buffer is simplified.
1621 It is assumed to be a single-line subject.
1622 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1623 matter is removed.  Additional things can be deleted by setting
1624 `gnus-simplify-subject-fuzzy-regexp'."
1625   (let ((case-fold-search t)
1626         (modified-tick))
1627     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1628
1629     (while (not (eq modified-tick (buffer-modified-tick)))
1630       (setq modified-tick (buffer-modified-tick))
1631       (cond
1632        ((listp gnus-simplify-subject-fuzzy-regexp)
1633         (mapcar 'gnus-simplify-buffer-fuzzy-step
1634                 gnus-simplify-subject-fuzzy-regexp))
1635        (gnus-simplify-subject-fuzzy-regexp
1636         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1637       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1638       (gnus-simplify-buffer-fuzzy-step
1639        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1640       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1641
1642     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1643     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1644     (gnus-simplify-buffer-fuzzy-step " $")
1645     (gnus-simplify-buffer-fuzzy-step "^ +")))
1646
1647 (defun gnus-simplify-subject-fuzzy (subject)
1648   "Simplify a subject string fuzzily.
1649 See `gnus-simplify-buffer-fuzzy' for details."
1650   (save-excursion
1651     (gnus-set-work-buffer)
1652     (let ((case-fold-search t))
1653       ;; Remove uninteresting prefixes.
1654       (when (and gnus-simplify-ignored-prefixes
1655                  (string-match gnus-simplify-ignored-prefixes subject))
1656         (setq subject (substring subject (match-end 0))))
1657       (insert subject)
1658       (inline (gnus-simplify-buffer-fuzzy))
1659       (buffer-string))))
1660
1661 (defsubst gnus-simplify-subject-fully (subject)
1662   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1663   (cond
1664    (gnus-simplify-subject-functions
1665     (gnus-map-function gnus-simplify-subject-functions subject))
1666    ((null gnus-summary-gather-subject-limit)
1667     (gnus-simplify-subject-re subject))
1668    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1669     (gnus-simplify-subject-fuzzy subject))
1670    ((numberp gnus-summary-gather-subject-limit)
1671     (gnus-limit-string (gnus-simplify-subject-re subject)
1672                        gnus-summary-gather-subject-limit))
1673    (t
1674     subject)))
1675
1676 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1677   "Check whether two subjects are equal.
1678 If optional argument SIMPLE-FIRST is t, first argument is already
1679 simplified."
1680   (cond
1681    ((null simple-first)
1682     (equal (gnus-simplify-subject-fully s1)
1683            (gnus-simplify-subject-fully s2)))
1684    (t
1685     (equal s1
1686            (gnus-simplify-subject-fully s2)))))
1687
1688 (defun gnus-summary-bubble-group ()
1689   "Increase the score of the current group.
1690 This is a handy function to add to `gnus-summary-exit-hook' to
1691 increase the score of each group you read."
1692   (gnus-group-add-score gnus-newsgroup-name))
1693
1694 \f
1695 ;;;
1696 ;;; Gnus summary mode
1697 ;;;
1698
1699 (put 'gnus-summary-mode 'mode-class 'special)
1700
1701 (defvar gnus-article-commands-menu)
1702
1703 ;; Non-orthogonal keys
1704
1705 (gnus-define-keys gnus-summary-mode-map
1706   " " gnus-summary-next-page
1707   "\177" gnus-summary-prev-page
1708   [delete] gnus-summary-prev-page
1709   [backspace] gnus-summary-prev-page
1710   "\r" gnus-summary-scroll-up
1711   "\M-\r" gnus-summary-scroll-down
1712   "n" gnus-summary-next-unread-article
1713   "p" gnus-summary-prev-unread-article
1714   "N" gnus-summary-next-article
1715   "P" gnus-summary-prev-article
1716   "\M-\C-n" gnus-summary-next-same-subject
1717   "\M-\C-p" gnus-summary-prev-same-subject
1718   "\M-n" gnus-summary-next-unread-subject
1719   "\M-p" gnus-summary-prev-unread-subject
1720   "." gnus-summary-first-unread-article
1721   "," gnus-summary-best-unread-article
1722   "\M-s" gnus-summary-search-article-forward
1723   "\M-r" gnus-summary-search-article-backward
1724   "<" gnus-summary-beginning-of-article
1725   ">" gnus-summary-end-of-article
1726   "j" gnus-summary-goto-article
1727   "^" gnus-summary-refer-parent-article
1728   "\M-^" gnus-summary-refer-article
1729   "u" gnus-summary-tick-article-forward
1730   "!" gnus-summary-tick-article-forward
1731   "U" gnus-summary-tick-article-backward
1732   "d" gnus-summary-mark-as-read-forward
1733   "D" gnus-summary-mark-as-read-backward
1734   "E" gnus-summary-mark-as-expirable
1735   "\M-u" gnus-summary-clear-mark-forward
1736   "\M-U" gnus-summary-clear-mark-backward
1737   "k" gnus-summary-kill-same-subject-and-select
1738   "\C-k" gnus-summary-kill-same-subject
1739   "\M-\C-k" gnus-summary-kill-thread
1740   "\M-\C-l" gnus-summary-lower-thread
1741   "e" gnus-summary-edit-article
1742   "#" gnus-summary-mark-as-processable
1743   "\M-#" gnus-summary-unmark-as-processable
1744   "\M-\C-t" gnus-summary-toggle-threads
1745   "\M-\C-s" gnus-summary-show-thread
1746   "\M-\C-h" gnus-summary-hide-thread
1747   "\M-\C-f" gnus-summary-next-thread
1748   "\M-\C-b" gnus-summary-prev-thread
1749   [(meta down)] gnus-summary-next-thread
1750   [(meta up)] gnus-summary-prev-thread
1751   "\M-\C-u" gnus-summary-up-thread
1752   "\M-\C-d" gnus-summary-down-thread
1753   "&" gnus-summary-execute-command
1754   "c" gnus-summary-catchup-and-exit
1755   "\C-w" gnus-summary-mark-region-as-read
1756   "\C-t" gnus-summary-toggle-truncation
1757   "?" gnus-summary-mark-as-dormant
1758   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1759   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1760   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1761   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1762   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1763   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1764   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1765   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1766   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1767   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1768   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1769   "=" gnus-summary-expand-window
1770   "\C-x\C-s" gnus-summary-reselect-current-group
1771   "\M-g" gnus-summary-rescan-group
1772   "w" gnus-summary-stop-page-breaking
1773   "\C-c\C-r" gnus-summary-caesar-message
1774   "\M-t" gnus-summary-toggle-mime
1775   "f" gnus-summary-followup
1776   "F" gnus-summary-followup-with-original
1777   "C" gnus-summary-cancel-article
1778   "r" gnus-summary-reply
1779   "R" gnus-summary-reply-with-original
1780   "\C-c\C-f" gnus-summary-mail-forward
1781   "o" gnus-summary-save-article
1782   "\C-o" gnus-summary-save-article-mail
1783   "|" gnus-summary-pipe-output
1784   "\M-k" gnus-summary-edit-local-kill
1785   "\M-K" gnus-summary-edit-global-kill
1786   ;; "V" gnus-version
1787   "\C-c\C-d" gnus-summary-describe-group
1788   "q" gnus-summary-exit
1789   "Q" gnus-summary-exit-no-update
1790   "\C-c\C-i" gnus-info-find-node
1791   gnus-mouse-2 gnus-mouse-pick-article
1792   [follow-link] mouse-face
1793   "m" gnus-summary-mail-other-window
1794   "a" gnus-summary-post-news
1795   "i" gnus-summary-news-other-window
1796   "x" gnus-summary-limit-to-unread
1797   "s" gnus-summary-isearch-article
1798   "t" gnus-summary-toggle-header
1799   "g" gnus-summary-show-article
1800   "l" gnus-summary-goto-last-article
1801   "v" gnus-summary-preview-mime-message
1802   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1803   "\C-d" gnus-summary-enter-digest-group
1804   "\M-\C-d" gnus-summary-read-document
1805   "\M-\C-e" gnus-summary-edit-parameters
1806   "\M-\C-a" gnus-summary-customize-parameters
1807   "\C-c\C-b" gnus-bug
1808   "\C-c\C-n" gnus-namazu-search
1809   "*" gnus-cache-enter-article
1810   "\M-*" gnus-cache-remove-article
1811   "\M-&" gnus-summary-universal-argument
1812   "\C-l" gnus-recenter
1813   "I" gnus-summary-increase-score
1814   "L" gnus-summary-lower-score
1815   "\M-i" gnus-symbolic-argument
1816   "h" gnus-summary-select-article-buffer
1817
1818   "V" gnus-summary-score-map
1819   "X" gnus-uu-extract-map
1820   "S" gnus-summary-send-map)
1821
1822   ;; Sort of orthogonal keymap
1823 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1824   "t" gnus-summary-tick-article-forward
1825   "!" gnus-summary-tick-article-forward
1826   "d" gnus-summary-mark-as-read-forward
1827   "r" gnus-summary-mark-as-read-forward
1828   "c" gnus-summary-clear-mark-forward
1829   " " gnus-summary-clear-mark-forward
1830   "e" gnus-summary-mark-as-expirable
1831   "x" gnus-summary-mark-as-expirable
1832   "?" gnus-summary-mark-as-dormant
1833   "b" gnus-summary-set-bookmark
1834   "B" gnus-summary-remove-bookmark
1835   "#" gnus-summary-mark-as-processable
1836   "\M-#" gnus-summary-unmark-as-processable
1837   "S" gnus-summary-limit-include-expunged
1838   "C" gnus-summary-catchup
1839   "H" gnus-summary-catchup-to-here
1840   "h" gnus-summary-catchup-from-here
1841   "\C-c" gnus-summary-catchup-all
1842   "k" gnus-summary-kill-same-subject-and-select
1843   "K" gnus-summary-kill-same-subject
1844   "P" gnus-uu-mark-map)
1845
1846 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1847   "c" gnus-summary-clear-above
1848   "u" gnus-summary-tick-above
1849   "m" gnus-summary-mark-above
1850   "k" gnus-summary-kill-below)
1851
1852 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1853   "/" gnus-summary-limit-to-subject
1854   "n" gnus-summary-limit-to-articles
1855   "w" gnus-summary-pop-limit
1856   "s" gnus-summary-limit-to-subject
1857   "a" gnus-summary-limit-to-author
1858   "u" gnus-summary-limit-to-unread
1859   "m" gnus-summary-limit-to-marks
1860   "M" gnus-summary-limit-exclude-marks
1861   "v" gnus-summary-limit-to-score
1862   "*" gnus-summary-limit-include-cached
1863   "D" gnus-summary-limit-include-dormant
1864   "T" gnus-summary-limit-include-thread
1865   "d" gnus-summary-limit-exclude-dormant
1866   "t" gnus-summary-limit-to-age
1867   "." gnus-summary-limit-to-unseen
1868   "x" gnus-summary-limit-to-extra
1869   "p" gnus-summary-limit-to-display-predicate
1870   "E" gnus-summary-limit-include-expunged
1871   "c" gnus-summary-limit-exclude-childless-dormant
1872   "C" gnus-summary-limit-mark-excluded-as-read
1873   "o" gnus-summary-insert-old-articles
1874   "N" gnus-summary-insert-new-articles
1875   "r" gnus-summary-limit-to-replied
1876   "R" gnus-summary-limit-to-recipient)
1877
1878 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1879   "n" gnus-summary-next-unread-article
1880   "p" gnus-summary-prev-unread-article
1881   "N" gnus-summary-next-article
1882   "P" gnus-summary-prev-article
1883   "\C-n" gnus-summary-next-same-subject
1884   "\C-p" gnus-summary-prev-same-subject
1885   "\M-n" gnus-summary-next-unread-subject
1886   "\M-p" gnus-summary-prev-unread-subject
1887   "f" gnus-summary-first-unread-article
1888   "b" gnus-summary-best-unread-article
1889   "j" gnus-summary-goto-article
1890   "g" gnus-summary-goto-subject
1891   "l" gnus-summary-goto-last-article
1892   "o" gnus-summary-pop-article)
1893
1894 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1895   "k" gnus-summary-kill-thread
1896   "l" gnus-summary-lower-thread
1897   "i" gnus-summary-raise-thread
1898   "T" gnus-summary-toggle-threads
1899   "t" gnus-summary-rethread-current
1900   "^" gnus-summary-reparent-thread
1901   "s" gnus-summary-show-thread
1902   "S" gnus-summary-show-all-threads
1903   "h" gnus-summary-hide-thread
1904   "H" gnus-summary-hide-all-threads
1905   "n" gnus-summary-next-thread
1906   "p" gnus-summary-prev-thread
1907   "u" gnus-summary-up-thread
1908   "o" gnus-summary-top-thread
1909   "d" gnus-summary-down-thread
1910   "#" gnus-uu-mark-thread
1911   "\M-#" gnus-uu-unmark-thread)
1912
1913 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1914   "g" gnus-summary-prepare
1915   "c" gnus-summary-insert-cached-articles
1916   "d" gnus-summary-insert-dormant-articles)
1917
1918 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1919   "c" gnus-summary-catchup-and-exit
1920   "C" gnus-summary-catchup-all-and-exit
1921   "E" gnus-summary-exit-no-update
1922   "J" gnus-summary-jump-to-other-group
1923   "Q" gnus-summary-exit
1924   "Z" gnus-summary-exit
1925   "n" gnus-summary-catchup-and-goto-next-group
1926   "R" gnus-summary-reselect-current-group
1927   "G" gnus-summary-rescan-group
1928   "N" gnus-summary-next-group
1929   "s" gnus-summary-save-newsrc
1930   "P" gnus-summary-prev-group)
1931
1932 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1933   " " gnus-summary-next-page
1934   "n" gnus-summary-next-page
1935   "\177" gnus-summary-prev-page
1936   [delete] gnus-summary-prev-page
1937   "p" gnus-summary-prev-page
1938   "\r" gnus-summary-scroll-up
1939   "\M-\r" gnus-summary-scroll-down
1940   "<" gnus-summary-beginning-of-article
1941   ">" gnus-summary-end-of-article
1942   "b" gnus-summary-beginning-of-article
1943   "e" gnus-summary-end-of-article
1944   "^" gnus-summary-refer-parent-article
1945   "r" gnus-summary-refer-parent-article
1946   "D" gnus-summary-enter-digest-group
1947   "R" gnus-summary-refer-references
1948   "T" gnus-summary-refer-thread
1949   "g" gnus-summary-show-article
1950   "s" gnus-summary-isearch-article
1951   "P" gnus-summary-print-article
1952   "M" gnus-mailing-list-insinuate
1953   "t" gnus-article-babel)
1954
1955 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1956   "b" gnus-article-add-buttons
1957   "B" gnus-article-add-buttons-to-head
1958   "o" gnus-article-treat-overstrike
1959   "e" gnus-article-emphasize
1960   "w" gnus-article-fill-cited-article
1961   "Q" gnus-article-fill-long-lines
1962   "C" gnus-article-capitalize-sentences
1963   "c" gnus-article-remove-cr
1964   "Z" gnus-article-decode-HZ
1965   "A" gnus-article-treat-ansi-sequences
1966   "h" gnus-article-wash-html
1967   "u" gnus-article-unsplit-urls
1968   "f" gnus-article-display-x-face
1969   "l" gnus-summary-stop-page-breaking
1970   "r" gnus-summary-caesar-message
1971   "m" gnus-summary-morse-message
1972   "t" gnus-summary-toggle-header
1973   "g" gnus-treat-smiley
1974   "v" gnus-summary-verbose-headers
1975   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1976   "p" gnus-article-verify-x-pgp-sig
1977   "d" gnus-article-treat-dumbquotes
1978   "i" gnus-summary-idna-message)
1979
1980 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1981   ;; mnemonic: deuglif*Y*
1982   "u" gnus-article-outlook-unwrap-lines
1983   "a" gnus-article-outlook-repair-attribution
1984   "c" gnus-article-outlook-rearrange-citation
1985   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1986
1987 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1988   "a" gnus-article-hide
1989   "h" gnus-article-hide-headers
1990   "b" gnus-article-hide-boring-headers
1991   "s" gnus-article-hide-signature
1992   "c" gnus-article-hide-citation
1993   "C" gnus-article-hide-citation-in-followups
1994   "l" gnus-article-hide-list-identifiers
1995   "B" gnus-article-strip-banner
1996   "P" gnus-article-hide-pem
1997   "\C-c" gnus-article-hide-citation-maybe)
1998
1999 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2000   "a" gnus-article-highlight
2001   "h" gnus-article-highlight-headers
2002   "c" gnus-article-highlight-citation
2003   "s" gnus-article-highlight-signature)
2004
2005 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2006   "f" gnus-article-treat-fold-headers
2007   "u" gnus-article-treat-unfold-headers
2008   "n" gnus-article-treat-fold-newsgroups)
2009
2010 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2011   "x" gnus-article-display-x-face
2012   "d" gnus-article-display-face
2013   "s" gnus-treat-smiley
2014   "D" gnus-article-remove-images
2015   "f" gnus-treat-from-picon
2016   "m" gnus-treat-mail-picon
2017   "n" gnus-treat-newsgroups-picon)
2018
2019 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2020   "z" gnus-article-date-ut
2021   "u" gnus-article-date-ut
2022   "l" gnus-article-date-local
2023   "p" gnus-article-date-english
2024   "e" gnus-article-date-lapsed
2025   "o" gnus-article-date-original
2026   "i" gnus-article-date-iso8601
2027   "s" gnus-article-date-user)
2028
2029 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2030   "t" gnus-article-remove-trailing-blank-lines
2031   "l" gnus-article-strip-leading-blank-lines
2032   "m" gnus-article-strip-multiple-blank-lines
2033   "a" gnus-article-strip-blank-lines
2034   "A" gnus-article-strip-all-blank-lines
2035   "s" gnus-article-strip-leading-space
2036   "e" gnus-article-strip-trailing-space
2037   "w" gnus-article-remove-leading-whitespace)
2038
2039 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2040   "v" gnus-version
2041   "f" gnus-summary-fetch-faq
2042   "d" gnus-summary-describe-group
2043   "h" gnus-summary-describe-briefly
2044   "i" gnus-info-find-node
2045   "c" gnus-group-fetch-charter
2046   "C" gnus-group-fetch-control)
2047
2048 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2049   "e" gnus-summary-expire-articles
2050   "\M-\C-e" gnus-summary-expire-articles-now
2051   "\177" gnus-summary-delete-article
2052   [delete] gnus-summary-delete-article
2053   [backspace] gnus-summary-delete-article
2054   "m" gnus-summary-move-article
2055   "r" gnus-summary-respool-article
2056   "w" gnus-summary-edit-article
2057   "c" gnus-summary-copy-article
2058   "B" gnus-summary-crosspost-article
2059   "q" gnus-summary-respool-query
2060   "t" gnus-summary-respool-trace
2061   "i" gnus-summary-import-article
2062   "I" gnus-summary-create-article
2063   "p" gnus-summary-article-posted-p)
2064
2065 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2066   "o" gnus-summary-save-article
2067   "m" gnus-summary-save-article-mail
2068   "F" gnus-summary-write-article-file
2069   "r" gnus-summary-save-article-rmail
2070   "f" gnus-summary-save-article-file
2071   "b" gnus-summary-save-article-body-file
2072   "h" gnus-summary-save-article-folder
2073   "v" gnus-summary-save-article-vm
2074   "p" gnus-summary-pipe-output
2075   "P" gnus-summary-muttprint
2076   "s" gnus-soup-add-article)
2077
2078 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2079   "b" gnus-summary-display-buttonized
2080   "m" gnus-summary-repair-multipart
2081   "v" gnus-article-view-part
2082   "o" gnus-article-save-part
2083   "O" gnus-article-save-part-and-strip
2084   "d" gnus-article-delete-part
2085   "j" gnus-article-jump-to-part
2086   "c" gnus-article-copy-part
2087   "C" gnus-article-view-part-as-charset
2088   "e" gnus-article-view-part-externally
2089   "E" gnus-article-encrypt-body
2090   "i" gnus-article-inline-part
2091   "|" gnus-article-pipe-part)
2092
2093 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2094   "p" gnus-summary-mark-as-processable
2095   "u" gnus-summary-unmark-as-processable
2096   "U" gnus-summary-unmark-all-processable
2097   "v" gnus-uu-mark-over
2098   "s" gnus-uu-mark-series
2099   "r" gnus-uu-mark-region
2100   "g" gnus-uu-unmark-region
2101   "R" gnus-uu-mark-by-regexp
2102   "G" gnus-uu-unmark-by-regexp
2103   "t" gnus-uu-mark-thread
2104   "T" gnus-uu-unmark-thread
2105   "a" gnus-uu-mark-all
2106   "b" gnus-uu-mark-buffer
2107   "S" gnus-uu-mark-sparse
2108   "k" gnus-summary-kill-process-mark
2109   "y" gnus-summary-yank-process-mark
2110   "w" gnus-summary-save-process-mark
2111   "i" gnus-uu-invert-processable)
2112
2113 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2114   ;;"x" gnus-uu-extract-any
2115   "m" gnus-summary-save-parts
2116   "u" gnus-uu-decode-uu
2117   "U" gnus-uu-decode-uu-and-save
2118   "s" gnus-uu-decode-unshar
2119   "S" gnus-uu-decode-unshar-and-save
2120   "o" gnus-uu-decode-save
2121   "O" gnus-uu-decode-save
2122   "b" gnus-uu-decode-binhex
2123   "B" gnus-uu-decode-binhex
2124   "p" gnus-uu-decode-postscript
2125   "P" gnus-uu-decode-postscript-and-save)
2126
2127 (gnus-define-keys
2128     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2129   "u" gnus-uu-decode-uu-view
2130   "U" gnus-uu-decode-uu-and-save-view
2131   "s" gnus-uu-decode-unshar-view
2132   "S" gnus-uu-decode-unshar-and-save-view
2133   "o" gnus-uu-decode-save-view
2134   "O" gnus-uu-decode-save-view
2135   "b" gnus-uu-decode-binhex-view
2136   "B" gnus-uu-decode-binhex-view
2137   "p" gnus-uu-decode-postscript-view
2138   "P" gnus-uu-decode-postscript-and-save-view)
2139
2140 (defvar gnus-article-post-menu nil)
2141
2142 (defconst gnus-summary-menu-maxlen 20)
2143
2144 (defun gnus-summary-menu-split (menu)
2145   ;; If we have lots of elements, divide them into groups of 20
2146   ;; and make a pane (or submenu) for each one.
2147   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2148       (let ((menu menu) sublists next
2149             (i 1))
2150         (while menu
2151           ;; Pull off the next gnus-summary-menu-maxlen elements
2152           ;; and make them the next element of sublist.
2153           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2154           (if next
2155               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2156                       nil))
2157           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2158                                              (aref (car (last menu)) 0)) menu)
2159                                sublists))
2160           (setq i (1+ i))
2161           (setq menu next))
2162         (nreverse sublists))
2163     ;; Few elements--put them all in one pane.
2164     menu))
2165
2166 (defun gnus-summary-make-menu-bar ()
2167   (gnus-turn-off-edit-menu 'summary)
2168
2169   (unless (boundp 'gnus-summary-misc-menu)
2170
2171     (easy-menu-define
2172       gnus-summary-kill-menu gnus-summary-mode-map ""
2173       (cons
2174        "Score"
2175        (nconc
2176         (list
2177          ["Customize" gnus-score-customize t])
2178         (gnus-make-score-map 'increase)
2179         (gnus-make-score-map 'lower)
2180         '(("Mark"
2181            ["Kill below" gnus-summary-kill-below t]
2182            ["Mark above" gnus-summary-mark-above t]
2183            ["Tick above" gnus-summary-tick-above t]
2184            ["Clear above" gnus-summary-clear-above t])
2185           ["Current score" gnus-summary-current-score t]
2186           ["Set score" gnus-summary-set-score t]
2187           ["Switch current score file..." gnus-score-change-score-file t]
2188           ["Set mark below..." gnus-score-set-mark-below t]
2189           ["Set expunge below..." gnus-score-set-expunge-below t]
2190           ["Edit current score file" gnus-score-edit-current-scores t]
2191           ["Edit score file" gnus-score-edit-file t]
2192           ["Trace score" gnus-score-find-trace t]
2193           ["Find words" gnus-score-find-favourite-words t]
2194           ["Rescore buffer" gnus-summary-rescore t]
2195           ["Increase score..." gnus-summary-increase-score t]
2196           ["Lower score..." gnus-summary-lower-score t]))))
2197
2198     ;; Define both the Article menu in the summary buffer and the
2199     ;; equivalent Commands menu in the article buffer here for
2200     ;; consistency.
2201     (let ((innards
2202            `(("Hide"
2203               ["All" gnus-article-hide t]
2204               ["Headers" gnus-article-hide-headers t]
2205               ["Signature" gnus-article-hide-signature t]
2206               ["Citation" gnus-article-hide-citation t]
2207               ["List identifiers" gnus-article-hide-list-identifiers t]
2208               ["Banner" gnus-article-strip-banner t]
2209               ["Boring headers" gnus-article-hide-boring-headers t])
2210              ("Highlight"
2211               ["All" gnus-article-highlight t]
2212               ["Headers" gnus-article-highlight-headers t]
2213               ["Signature" gnus-article-highlight-signature t]
2214               ["Citation" gnus-article-highlight-citation t])
2215              ("Date"
2216               ["Local" gnus-article-date-local t]
2217               ["ISO8601" gnus-article-date-iso8601 t]
2218               ["UT" gnus-article-date-ut t]
2219               ["Original" gnus-article-date-original t]
2220               ["Lapsed" gnus-article-date-lapsed t]
2221               ["User-defined" gnus-article-date-user t])
2222              ("Display"
2223               ["Remove images" gnus-article-remove-images t]
2224               ["Toggle smiley" gnus-treat-smiley t]
2225               ["Show X-Face" gnus-article-display-x-face t]
2226               ["Show picons in From" gnus-treat-from-picon t]
2227               ["Show picons in mail headers" gnus-treat-mail-picon t]
2228               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2229               ("View as different encoding"
2230                ,@(gnus-summary-menu-split
2231                   (mapcar
2232                    (lambda (cs)
2233                      ;; Since easymenu under Emacs doesn't allow
2234                      ;; lambda forms for menu commands, we should
2235                      ;; provide intern'ed function symbols.
2236                      (let ((command (intern (format "\
2237 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2238                        (fset command
2239                              `(lambda ()
2240                                 (interactive)
2241                                 (let ((gnus-summary-show-article-charset-alist
2242                                        '((1 . ,cs))))
2243                                   (gnus-summary-show-article 1))))
2244                        `[,(symbol-name cs) ,command t]))
2245                    (sort (if (fboundp 'coding-system-list)
2246                              (coding-system-list)
2247                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2248                            )
2249                          'string<)))))
2250              ("Washing"
2251               ("Remove Blanks"
2252                ["Leading" gnus-article-strip-leading-blank-lines t]
2253                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2254                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2255                ["All of the above" gnus-article-strip-blank-lines t]
2256                ["All" gnus-article-strip-all-blank-lines t]
2257                ["Leading space" gnus-article-strip-leading-space t]
2258                ["Trailing space" gnus-article-strip-trailing-space t]
2259                ["Leading space in headers"
2260                 gnus-article-remove-leading-whitespace t])
2261               ["Overstrike" gnus-article-treat-overstrike t]
2262               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2263               ["Emphasis" gnus-article-emphasize t]
2264               ["Word wrap" gnus-article-fill-cited-article t]
2265               ["Fill long lines" gnus-article-fill-long-lines t]
2266               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2267               ["Remove CR" gnus-article-remove-cr t]
2268               ["Rot 13" gnus-summary-caesar-message
2269                ,@(if (featurep 'xemacs) '(t)
2270                    '(:help "\"Caesar rotate\" article by 13"))]
2271               ["De-IDNA" gnus-summary-idna-message t]
2272               ["Morse decode" gnus-summary-morse-message t]
2273               ["Unix pipe..." gnus-summary-pipe-message t]
2274               ["Add buttons" gnus-article-add-buttons t]
2275               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2276               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2277               ["Toggle MIME" gnus-summary-toggle-mime t]
2278               ["Verbose header" gnus-summary-verbose-headers t]
2279               ["Toggle header" gnus-summary-toggle-header t]
2280               ["Unfold headers" gnus-article-treat-unfold-headers t]
2281               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2282               ["Html" gnus-article-wash-html t]
2283               ["Unsplit URLs" gnus-article-unsplit-urls t]
2284               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2285               ["Decode HZ" gnus-article-decode-HZ t]
2286               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2287               ("(Outlook) Deuglify"
2288                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2289                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2290                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2291                ["Full (Outlook) deuglify"
2292                 gnus-article-outlook-deuglify-article t])
2293               )
2294              ("Output"
2295               ["Save in default format..." gnus-summary-save-article
2296                ,@(if (featurep 'xemacs) '(t)
2297                    '(:help "Save article using default method"))]
2298               ["Save in file..." gnus-summary-save-article-file
2299                ,@(if (featurep 'xemacs) '(t)
2300                    '(:help "Save article in file"))]
2301               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2302               ["Save in MH folder..." gnus-summary-save-article-folder t]
2303               ["Save in VM folder..." gnus-summary-save-article-vm t]
2304               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2305               ["Save body in file..." gnus-summary-save-article-body-file t]
2306               ["Pipe through a filter..." gnus-summary-pipe-output t]
2307               ["Add to SOUP packet" gnus-soup-add-article t]
2308               ["Print with Muttprint..." gnus-summary-muttprint t]
2309               ["Print" gnus-summary-print-article
2310                ,@(if (featurep 'xemacs) '(t)
2311                    '(:help "Generate and print a PostScript image"))])
2312              ("Copy, move,... (Backend)"
2313               ,@(if (featurep 'xemacs) nil
2314                   '(:help "Copying, moving, expiring articles..."))
2315               ["Respool article..." gnus-summary-respool-article t]
2316               ["Move article..." gnus-summary-move-article
2317                (gnus-check-backend-function
2318                 'request-move-article gnus-newsgroup-name)]
2319               ["Copy article..." gnus-summary-copy-article t]
2320               ["Crosspost article..." gnus-summary-crosspost-article
2321                (gnus-check-backend-function
2322                 'request-replace-article gnus-newsgroup-name)]
2323               ["Import file..." gnus-summary-import-article
2324                (gnus-check-backend-function
2325                 'request-accept-article gnus-newsgroup-name)]
2326               ["Create article..." gnus-summary-create-article
2327                (gnus-check-backend-function
2328                 'request-accept-article gnus-newsgroup-name)]
2329               ["Check if posted" gnus-summary-article-posted-p t]
2330               ["Edit article" gnus-summary-edit-article
2331                (not (gnus-group-read-only-p))]
2332               ["Delete article" gnus-summary-delete-article
2333                (gnus-check-backend-function
2334                 'request-expire-articles gnus-newsgroup-name)]
2335               ["Query respool" gnus-summary-respool-query t]
2336               ["Trace respool" gnus-summary-respool-trace t]
2337               ["Delete expirable articles" gnus-summary-expire-articles-now
2338                (gnus-check-backend-function
2339                 'request-expire-articles gnus-newsgroup-name)])
2340              ("Extract"
2341               ["Uudecode" gnus-uu-decode-uu
2342                ,@(if (featurep 'xemacs) '(t)
2343                    '(:help "Decode uuencoded article(s)"))]
2344               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2345               ["Unshar" gnus-uu-decode-unshar t]
2346               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2347               ["Save" gnus-uu-decode-save t]
2348               ["Binhex" gnus-uu-decode-binhex t]
2349               ["Postscript" gnus-uu-decode-postscript t])
2350              ("Cache"
2351               ["Enter article" gnus-cache-enter-article t]
2352               ["Remove article" gnus-cache-remove-article t])
2353              ["Translate" gnus-article-babel t]
2354              ["Select article buffer" gnus-summary-select-article-buffer t]
2355              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2356              ["Isearch article..." gnus-summary-isearch-article t]
2357              ["Beginning of the article" gnus-summary-beginning-of-article t]
2358              ["End of the article" gnus-summary-end-of-article t]
2359              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2360              ["Fetch referenced articles" gnus-summary-refer-references t]
2361              ["Fetch current thread" gnus-summary-refer-thread t]
2362              ["Fetch article with id..." gnus-summary-refer-article t]
2363              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2364              ["Redisplay" gnus-summary-show-article t]
2365              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2366       (easy-menu-define
2367         gnus-summary-article-menu gnus-summary-mode-map ""
2368         (cons "Article" innards))
2369
2370       (if (not (keymapp gnus-summary-article-menu))
2371           (easy-menu-define
2372             gnus-article-commands-menu gnus-article-mode-map ""
2373             (cons "Commands" innards))
2374         ;; in Emacs, don't share menu.
2375         (setq gnus-article-commands-menu
2376               (copy-keymap gnus-summary-article-menu))
2377         (define-key gnus-article-mode-map [menu-bar commands]
2378           (cons "Commands" gnus-article-commands-menu))))
2379
2380     (easy-menu-define
2381       gnus-summary-thread-menu gnus-summary-mode-map ""
2382       '("Threads"
2383         ["Find all messages in thread" gnus-summary-refer-thread t]
2384         ["Toggle threading" gnus-summary-toggle-threads t]
2385         ["Hide threads" gnus-summary-hide-all-threads t]
2386         ["Show threads" gnus-summary-show-all-threads t]
2387         ["Hide thread" gnus-summary-hide-thread t]
2388         ["Show thread" gnus-summary-show-thread t]
2389         ["Go to next thread" gnus-summary-next-thread t]
2390         ["Go to previous thread" gnus-summary-prev-thread t]
2391         ["Go down thread" gnus-summary-down-thread t]
2392         ["Go up thread" gnus-summary-up-thread t]
2393         ["Top of thread" gnus-summary-top-thread t]
2394         ["Mark thread as read" gnus-summary-kill-thread t]
2395         ["Lower thread score" gnus-summary-lower-thread t]
2396         ["Raise thread score" gnus-summary-raise-thread t]
2397         ["Rethread current" gnus-summary-rethread-current t]))
2398
2399     (easy-menu-define
2400       gnus-summary-post-menu gnus-summary-mode-map ""
2401       `("Post"
2402         ["Send a message (mail or news)" gnus-summary-post-news
2403          ,@(if (featurep 'xemacs) '(t)
2404              '(:help "Compose a new message (mail or news)"))]
2405         ["Followup" gnus-summary-followup
2406          ,@(if (featurep 'xemacs) '(t)
2407              '(:help "Post followup to this article"))]
2408         ["Followup and yank" gnus-summary-followup-with-original
2409          ,@(if (featurep 'xemacs) '(t)
2410              '(:help "Post followup to this article, quoting its contents"))]
2411         ["Supersede article" gnus-summary-supersede-article t]
2412         ["Cancel article" gnus-summary-cancel-article
2413          ,@(if (featurep 'xemacs) '(t)
2414              '(:help "Cancel an article you posted"))]
2415         ["Reply" gnus-summary-reply t]
2416         ["Reply and yank" gnus-summary-reply-with-original t]
2417         ["Wide reply" gnus-summary-wide-reply t]
2418         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2419          ,@(if (featurep 'xemacs) '(t)
2420              '(:help "Mail a reply, quoting this article"))]
2421         ["Very wide reply" gnus-summary-very-wide-reply t]
2422         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2423          ,@(if (featurep 'xemacs) '(t)
2424              '(:help "Mail a very wide reply, quoting this article"))]
2425         ["Mail forward" gnus-summary-mail-forward t]
2426         ["Post forward" gnus-summary-post-forward t]
2427         ["Digest and mail" gnus-summary-digest-mail-forward t]
2428         ["Digest and post" gnus-summary-digest-post-forward t]
2429         ["Resend message" gnus-summary-resend-message t]
2430         ["Resend message edit" gnus-summary-resend-message-edit t]
2431         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2432         ["Send a mail" gnus-summary-mail-other-window t]
2433         ["Create a local message" gnus-summary-news-other-window t]
2434         ["Uuencode and post" gnus-uu-post-news
2435          ,@(if (featurep 'xemacs) '(t)
2436              '(:help "Post a uuencoded article"))]
2437         ["Followup via news" gnus-summary-followup-to-mail t]
2438         ["Followup via news and yank"
2439          gnus-summary-followup-to-mail-with-original t]
2440         ;;("Draft"
2441         ;;["Send" gnus-summary-send-draft t]
2442         ;;["Send bounced" gnus-resend-bounced-mail t])
2443         ))
2444
2445     (cond
2446      ((not (keymapp gnus-summary-post-menu))
2447       (setq gnus-article-post-menu gnus-summary-post-menu))
2448      ((not gnus-article-post-menu)
2449       ;; Don't share post menu.
2450       (setq gnus-article-post-menu
2451             (copy-keymap gnus-summary-post-menu))))
2452     (define-key gnus-article-mode-map [menu-bar post]
2453       (cons "Post" gnus-article-post-menu))
2454
2455     (easy-menu-define
2456       gnus-summary-misc-menu gnus-summary-mode-map ""
2457       `("Gnus"
2458         ("Mark Read"
2459          ["Mark as read" gnus-summary-mark-as-read-forward t]
2460          ["Mark same subject and select"
2461           gnus-summary-kill-same-subject-and-select t]
2462          ["Mark same subject" gnus-summary-kill-same-subject t]
2463          ["Catchup" gnus-summary-catchup
2464           ,@(if (featurep 'xemacs) '(t)
2465               '(:help "Mark unread articles in this group as read"))]
2466          ["Catchup all" gnus-summary-catchup-all t]
2467          ["Catchup to here" gnus-summary-catchup-to-here t]
2468          ["Catchup from here" gnus-summary-catchup-from-here t]
2469          ["Catchup region" gnus-summary-mark-region-as-read
2470           (gnus-mark-active-p)]
2471          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2472         ("Mark Various"
2473          ["Tick" gnus-summary-tick-article-forward t]
2474          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2475          ["Remove marks" gnus-summary-clear-mark-forward t]
2476          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2477          ["Set bookmark" gnus-summary-set-bookmark t]
2478          ["Remove bookmark" gnus-summary-remove-bookmark t])
2479         ("Limit to"
2480          ["Marks..." gnus-summary-limit-to-marks t]
2481          ["Subject..." gnus-summary-limit-to-subject t]
2482          ["Author..." gnus-summary-limit-to-author t]
2483          ["Recipient..." gnus-summary-limit-to-recipient t]
2484          ["Age..." gnus-summary-limit-to-age t]
2485          ["Extra..." gnus-summary-limit-to-extra t]
2486          ["Score..." gnus-summary-limit-to-score t]
2487          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2488          ["Unread" gnus-summary-limit-to-unread t]
2489          ["Unseen" gnus-summary-limit-to-unseen t]
2490          ["Replied" gnus-summary-limit-to-replied t]
2491          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2492          ["Next articles" gnus-summary-limit-to-articles t]
2493          ["Pop limit" gnus-summary-pop-limit t]
2494          ["Show dormant" gnus-summary-limit-include-dormant t]
2495          ["Hide childless dormant"
2496           gnus-summary-limit-exclude-childless-dormant t]
2497          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2498          ["Hide marked" gnus-summary-limit-exclude-marks t]
2499          ["Show expunged" gnus-summary-limit-include-expunged t])
2500         ("Process Mark"
2501          ["Set mark" gnus-summary-mark-as-processable t]
2502          ["Remove mark" gnus-summary-unmark-as-processable t]
2503          ["Remove all marks" gnus-summary-unmark-all-processable t]
2504          ["Invert marks" gnus-uu-invert-processable t]
2505          ["Mark above" gnus-uu-mark-over t]
2506          ["Mark series" gnus-uu-mark-series t]
2507          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2508          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2509          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2510          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2511          ["Mark all" gnus-uu-mark-all t]
2512          ["Mark buffer" gnus-uu-mark-buffer t]
2513          ["Mark sparse" gnus-uu-mark-sparse t]
2514          ["Mark thread" gnus-uu-mark-thread t]
2515          ["Unmark thread" gnus-uu-unmark-thread t]
2516          ("Process Mark Sets"
2517           ["Kill" gnus-summary-kill-process-mark t]
2518           ["Yank" gnus-summary-yank-process-mark
2519            gnus-newsgroup-process-stack]
2520           ["Save" gnus-summary-save-process-mark t]
2521           ["Run command on marked..." gnus-summary-universal-argument t]))
2522         ("Scroll article"
2523          ["Page forward" gnus-summary-next-page
2524           ,@(if (featurep 'xemacs) '(t)
2525               '(:help "Show next page of article"))]
2526          ["Page backward" gnus-summary-prev-page
2527           ,@(if (featurep 'xemacs) '(t)
2528               '(:help "Show previous page of article"))]
2529          ["Line forward" gnus-summary-scroll-up t])
2530         ("Move"
2531          ["Next unread article" gnus-summary-next-unread-article t]
2532          ["Previous unread article" gnus-summary-prev-unread-article t]
2533          ["Next article" gnus-summary-next-article t]
2534          ["Previous article" gnus-summary-prev-article t]
2535          ["Next unread subject" gnus-summary-next-unread-subject t]
2536          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2537          ["Next article same subject" gnus-summary-next-same-subject t]
2538          ["Previous article same subject" gnus-summary-prev-same-subject t]
2539          ["First unread article" gnus-summary-first-unread-article t]
2540          ["Best unread article" gnus-summary-best-unread-article t]
2541          ["Go to subject number..." gnus-summary-goto-subject t]
2542          ["Go to article number..." gnus-summary-goto-article t]
2543          ["Go to the last article" gnus-summary-goto-last-article t]
2544          ["Pop article off history" gnus-summary-pop-article t])
2545         ("Sort"
2546          ["Sort by number" gnus-summary-sort-by-number t]
2547          ["Sort by author" gnus-summary-sort-by-author t]
2548          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2549          ["Sort by subject" gnus-summary-sort-by-subject t]
2550          ["Sort by date" gnus-summary-sort-by-date t]
2551          ["Sort by score" gnus-summary-sort-by-score t]
2552          ["Sort by lines" gnus-summary-sort-by-lines t]
2553          ["Sort by characters" gnus-summary-sort-by-chars t]
2554          ["Randomize" gnus-summary-sort-by-random t]
2555          ["Original sort" gnus-summary-sort-by-original t])
2556         ("Help"
2557          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2558          ["Describe group" gnus-summary-describe-group t]
2559          ["Fetch charter" gnus-group-fetch-charter
2560           ,@(if (featurep 'xemacs) nil
2561               '(:help "Display the charter of the current group"))]
2562          ["Fetch control message" gnus-group-fetch-control
2563           ,@(if (featurep 'xemacs) nil
2564               '(:help "Display the archived control message for the current group"))]
2565          ["Read manual" gnus-info-find-node t])
2566         ("Modes"
2567          ["Pick and read" gnus-pick-mode t]
2568          ["Binary" gnus-binary-mode t])
2569         ("Regeneration"
2570          ["Regenerate" gnus-summary-prepare t]
2571          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2572          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2573          ["Toggle threading" gnus-summary-toggle-threads t])
2574         ["See old articles" gnus-summary-insert-old-articles t]
2575         ["See new articles" gnus-summary-insert-new-articles t]
2576         ["Filter articles..." gnus-summary-execute-command t]
2577         ["Run command on articles..." gnus-summary-universal-argument t]
2578         ["Search articles forward..." gnus-summary-search-article-forward t]
2579         ["Search articles backward..." gnus-summary-search-article-backward t]
2580         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2581         ["Expand window" gnus-summary-expand-window t]
2582         ["Expire expirable articles" gnus-summary-expire-articles
2583          (gnus-check-backend-function
2584           'request-expire-articles gnus-newsgroup-name)]
2585         ["Edit local kill file" gnus-summary-edit-local-kill t]
2586         ["Edit main kill file" gnus-summary-edit-global-kill t]
2587         ["Edit group parameters" gnus-summary-edit-parameters t]
2588         ["Customize group parameters" gnus-summary-customize-parameters t]
2589         ["Send a bug report" gnus-bug t]
2590         ("Exit"
2591          ["Catchup and exit" gnus-summary-catchup-and-exit
2592           ,@(if (featurep 'xemacs) '(t)
2593               '(:help "Mark unread articles in this group as read, then exit"))]
2594          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2595          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2596          ["Exit group" gnus-summary-exit
2597           ,@(if (featurep 'xemacs) '(t)
2598               '(:help "Exit current group, return to group selection mode"))]
2599          ["Exit group without updating" gnus-summary-exit-no-update t]
2600          ["Exit and goto next group" gnus-summary-next-group t]
2601          ["Exit and goto prev group" gnus-summary-prev-group t]
2602          ["Reselect group" gnus-summary-reselect-current-group t]
2603          ["Rescan group" gnus-summary-rescan-group t]
2604          ["Update dribble" gnus-summary-save-newsrc t])))
2605
2606     (gnus-run-hooks 'gnus-summary-menu-hook)))
2607
2608 (defvar gnus-summary-tool-bar-map nil)
2609
2610 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2611 (defun gnus-summary-make-tool-bar ()
2612   (if (and (fboundp 'tool-bar-add-item-from-menu)
2613            (default-value 'tool-bar-mode)
2614            (not gnus-summary-tool-bar-map))
2615       (setq gnus-summary-tool-bar-map
2616             (let ((tool-bar-map (make-sparse-keymap))
2617                   (load-path (mm-image-load-path)))
2618               (tool-bar-add-item-from-menu
2619                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2620               (tool-bar-add-item-from-menu
2621                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2622               (tool-bar-add-item-from-menu
2623                'gnus-summary-post-news "post" gnus-summary-mode-map)
2624               (tool-bar-add-item-from-menu
2625                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2626               (tool-bar-add-item-from-menu
2627                'gnus-summary-followup "followup" gnus-summary-mode-map)
2628               (tool-bar-add-item-from-menu
2629                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2630               (tool-bar-add-item-from-menu
2631                'gnus-summary-reply "reply" gnus-summary-mode-map)
2632               (tool-bar-add-item-from-menu
2633                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2634               (tool-bar-add-item-from-menu
2635                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2636               (tool-bar-add-item-from-menu
2637                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2638               (tool-bar-add-item-from-menu
2639                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2640               (tool-bar-add-item-from-menu
2641                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2642               (tool-bar-add-item-from-menu
2643                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2644               (tool-bar-add-item-from-menu
2645                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2646               (tool-bar-add-item-from-menu
2647                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2648               (tool-bar-add-item-from-menu
2649                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2650               tool-bar-map)))
2651   (if gnus-summary-tool-bar-map
2652       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2653
2654 (defun gnus-score-set-default (var value)
2655   "A version of set that updates the GNU Emacs menu-bar."
2656   (set var value)
2657   ;; It is the message that forces the active status to be updated.
2658   (message ""))
2659
2660 (defun gnus-make-score-map (type)
2661   "Make a summary score map of type TYPE."
2662   (if t
2663       nil
2664     (let ((headers '(("author" "from" string)
2665                      ("subject" "subject" string)
2666                      ("article body" "body" string)
2667                      ("article head" "head" string)
2668                      ("xref" "xref" string)
2669                      ("extra header" "extra" string)
2670                      ("lines" "lines" number)
2671                      ("followups to author" "followup" string)))
2672           (types '((number ("less than" <)
2673                            ("greater than" >)
2674                            ("equal" =))
2675                    (string ("substring" s)
2676                            ("exact string" e)
2677                            ("fuzzy string" f)
2678                            ("regexp" r))))
2679           (perms '(("temporary" (current-time-string))
2680                    ("permanent" nil)
2681                    ("immediate" now)))
2682           header)
2683       (list
2684        (apply
2685         'nconc
2686         (list
2687          (if (eq type 'lower)
2688              "Lower score"
2689            "Increase score"))
2690         (let (outh)
2691           (while headers
2692             (setq header (car headers))
2693             (setq outh
2694                   (cons
2695                    (apply
2696                     'nconc
2697                     (list (car header))
2698                     (let ((ts (cdr (assoc (nth 2 header) types)))
2699                           outt)
2700                       (while ts
2701                         (setq outt
2702                               (cons
2703                                (apply
2704                                 'nconc
2705                                 (list (caar ts))
2706                                 (let ((ps perms)
2707                                       outp)
2708                                   (while ps
2709                                     (setq outp
2710                                           (cons
2711                                            (vector
2712                                             (caar ps)
2713                                             (list
2714                                              'gnus-summary-score-entry
2715                                              (nth 1 header)
2716                                              (if (or (string= (nth 1 header)
2717                                                               "head")
2718                                                      (string= (nth 1 header)
2719                                                               "body"))
2720                                                  ""
2721                                                (list 'gnus-summary-header
2722                                                      (nth 1 header)))
2723                                              (list 'quote (nth 1 (car ts)))
2724                                              (list 'gnus-score-delta-default
2725                                                    nil)
2726                                              (nth 1 (car ps))
2727                                              t)
2728                                             t)
2729                                            outp))
2730                                     (setq ps (cdr ps)))
2731                                   (list (nreverse outp))))
2732                                outt))
2733                         (setq ts (cdr ts)))
2734                       (list (nreverse outt))))
2735                    outh))
2736             (setq headers (cdr headers)))
2737           (list (nreverse outh))))))))
2738
2739 \f
2740
2741 (defun gnus-summary-mode (&optional group)
2742   "Major mode for reading articles.
2743
2744 All normal editing commands are switched off.
2745 \\<gnus-summary-mode-map>
2746 Each line in this buffer represents one article.  To read an
2747 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2748 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2749 respectively.
2750
2751 You can also post articles and send mail from this buffer.  To
2752 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2753 of an article, type `\\[gnus-summary-reply]'.
2754
2755 There are approx. one gazillion commands you can execute in this
2756 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2757
2758 The following commands are available:
2759
2760 \\{gnus-summary-mode-map}"
2761   (interactive)
2762   (kill-all-local-variables)
2763   (when (gnus-visual-p 'summary-menu 'menu)
2764     (gnus-summary-make-menu-bar)
2765     (gnus-summary-make-tool-bar))
2766   (gnus-summary-make-local-variables)
2767   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2768     (gnus-summary-make-local-variables))
2769   (gnus-make-thread-indent-array)
2770   (gnus-simplify-mode-line)
2771   (setq major-mode 'gnus-summary-mode)
2772   (setq mode-name "Summary")
2773   (make-local-variable 'minor-mode-alist)
2774   (use-local-map gnus-summary-mode-map)
2775   (buffer-disable-undo)
2776   (setq buffer-read-only t              ;Disable modification
2777         show-trailing-whitespace nil)
2778   (setq truncate-lines t)
2779   (setq selective-display t)
2780   (setq selective-display-ellipses t)   ;Display `...'
2781   (gnus-summary-set-display-table)
2782   (gnus-set-default-directory)
2783   (setq gnus-newsgroup-name group)
2784   (unless (gnus-news-group-p group)
2785     (setq gnus-newsgroup-incorporated
2786           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2787   (make-local-variable 'gnus-summary-line-format)
2788   (make-local-variable 'gnus-summary-line-format-spec)
2789   (make-local-variable 'gnus-summary-dummy-line-format)
2790   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2791   (make-local-variable 'gnus-summary-mark-positions)
2792   (gnus-make-local-hook 'pre-command-hook)
2793   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2794   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2795   (turn-on-gnus-mailing-list-mode)
2796   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2797   (gnus-update-summary-mark-positions))
2798
2799 (defun gnus-summary-make-local-variables ()
2800   "Make all the local summary buffer variables."
2801   (let (global)
2802     (dolist (local gnus-summary-local-variables)
2803       (if (consp local)
2804           (progn
2805             (if (eq (cdr local) 'global)
2806                 ;; Copy the global value of the variable.
2807                 (setq global (symbol-value (car local)))
2808               ;; Use the value from the list.
2809               (setq global (eval (cdr local))))
2810             (set (make-local-variable (car local)) global))
2811         ;; Simple nil-valued local variable.
2812         (set (make-local-variable local) nil)))))
2813
2814 (defun gnus-summary-clear-local-variables ()
2815   (let ((locals gnus-summary-local-variables))
2816     (while locals
2817       (if (consp (car locals))
2818           (and (symbolp (caar locals))
2819                (set (caar locals) nil))
2820         (and (symbolp (car locals))
2821              (set (car locals) nil)))
2822       (setq locals (cdr locals)))))
2823
2824 ;; Summary data functions.
2825
2826 (defmacro gnus-data-number (data)
2827   `(car ,data))
2828
2829 (defmacro gnus-data-set-number (data number)
2830   `(setcar ,data ,number))
2831
2832 (defmacro gnus-data-mark (data)
2833   `(nth 1 ,data))
2834
2835 (defmacro gnus-data-set-mark (data mark)
2836   `(setcar (nthcdr 1 ,data) ,mark))
2837
2838 (defmacro gnus-data-pos (data)
2839   `(nth 2 ,data))
2840
2841 (defmacro gnus-data-set-pos (data pos)
2842   `(setcar (nthcdr 2 ,data) ,pos))
2843
2844 (defmacro gnus-data-header (data)
2845   `(nth 3 ,data))
2846
2847 (defmacro gnus-data-set-header (data header)
2848   `(setcar (nthcdr 3 ,data) ,header))
2849
2850 (defmacro gnus-data-level (data)
2851   `(nth 4 ,data))
2852
2853 (defmacro gnus-data-unread-p (data)
2854   `(= (nth 1 ,data) gnus-unread-mark))
2855
2856 (defmacro gnus-data-read-p (data)
2857   `(/= (nth 1 ,data) gnus-unread-mark))
2858
2859 (defmacro gnus-data-pseudo-p (data)
2860   `(consp (nth 3 ,data)))
2861
2862 (defmacro gnus-data-find (number)
2863   `(assq ,number gnus-newsgroup-data))
2864
2865 (defmacro gnus-data-find-list (number &optional data)
2866   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2867      (memq (assq ,number bdata)
2868            bdata)))
2869
2870 (defmacro gnus-data-make (number mark pos header level)
2871   `(list ,number ,mark ,pos ,header ,level))
2872
2873 (defun gnus-data-enter (after-article number mark pos header level offset)
2874   (let ((data (gnus-data-find-list after-article)))
2875     (unless data
2876       (error "No such article: %d" after-article))
2877     (setcdr data (cons (gnus-data-make number mark pos header level)
2878                        (cdr data)))
2879     (setq gnus-newsgroup-data-reverse nil)
2880     (gnus-data-update-list (cddr data) offset)))
2881
2882 (defun gnus-data-enter-list (after-article list &optional offset)
2883   (when list
2884     (let ((data (and after-article (gnus-data-find-list after-article)))
2885           (ilist list))
2886       (if (not (or data
2887                    after-article))
2888           (let ((odata gnus-newsgroup-data))
2889             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2890             (when offset
2891               (gnus-data-update-list odata offset)))
2892         ;; Find the last element in the list to be spliced into the main
2893         ;; list.
2894         (setq list (last list))
2895         (if (not data)
2896             (progn
2897               (setcdr list gnus-newsgroup-data)
2898               (setq gnus-newsgroup-data ilist)
2899               (when offset
2900                 (gnus-data-update-list (cdr list) offset)))
2901           (setcdr list (cdr data))
2902           (setcdr data ilist)
2903           (when offset
2904             (gnus-data-update-list (cdr list) offset))))
2905       (setq gnus-newsgroup-data-reverse nil))))
2906
2907 (defun gnus-data-remove (article &optional offset)
2908   (let ((data gnus-newsgroup-data))
2909     (if (= (gnus-data-number (car data)) article)
2910         (progn
2911           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2912                 gnus-newsgroup-data-reverse nil)
2913           (when offset
2914             (gnus-data-update-list gnus-newsgroup-data offset)))
2915       (while (cdr data)
2916         (when (= (gnus-data-number (cadr data)) article)
2917           (setcdr data (cddr data))
2918           (when offset
2919             (gnus-data-update-list (cdr data) offset))
2920           (setq data nil
2921                 gnus-newsgroup-data-reverse nil))
2922         (setq data (cdr data))))))
2923
2924 (defmacro gnus-data-list (backward)
2925   `(if ,backward
2926        (or gnus-newsgroup-data-reverse
2927            (setq gnus-newsgroup-data-reverse
2928                  (reverse gnus-newsgroup-data)))
2929      gnus-newsgroup-data))
2930
2931 (defun gnus-data-update-list (data offset)
2932   "Add OFFSET to the POS of all data entries in DATA."
2933   (setq gnus-newsgroup-data-reverse nil)
2934   (while data
2935     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2936     (setq data (cdr data))))
2937
2938 (defun gnus-summary-article-pseudo-p (article)
2939   "Say whether this article is a pseudo article or not."
2940   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2941
2942 (defmacro gnus-summary-article-sparse-p (article)
2943   "Say whether this article is a sparse article or not."
2944   `(memq ,article gnus-newsgroup-sparse))
2945
2946 (defmacro gnus-summary-article-ancient-p (article)
2947   "Say whether this article is a sparse article or not."
2948   `(memq ,article gnus-newsgroup-ancient))
2949
2950 (defun gnus-article-parent-p (number)
2951   "Say whether this article is a parent or not."
2952   (let ((data (gnus-data-find-list number)))
2953     (and (cdr data)                     ; There has to be an article after...
2954          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2955             (gnus-data-level (nth 1 data))))))
2956
2957 (defun gnus-article-children (number)
2958   "Return a list of all children to NUMBER."
2959   (let* ((data (gnus-data-find-list number))
2960          (level (gnus-data-level (car data)))
2961          children)
2962     (setq data (cdr data))
2963     (while (and data
2964                 (= (gnus-data-level (car data)) (1+ level)))
2965       (push (gnus-data-number (car data)) children)
2966       (setq data (cdr data)))
2967     children))
2968
2969 (defmacro gnus-summary-skip-intangible ()
2970   "If the current article is intangible, then jump to a different article."
2971   '(let ((to (get-text-property (point) 'gnus-intangible)))
2972      (and to (gnus-summary-goto-subject to))))
2973
2974 (defmacro gnus-summary-article-intangible-p ()
2975   "Say whether this article is intangible or not."
2976   '(get-text-property (point) 'gnus-intangible))
2977
2978 (defun gnus-article-read-p (article)
2979   "Say whether ARTICLE is read or not."
2980   (not (or (memq article gnus-newsgroup-marked)
2981            (memq article gnus-newsgroup-spam-marked)
2982            (memq article gnus-newsgroup-unreads)
2983            (memq article gnus-newsgroup-unselected)
2984            (memq article gnus-newsgroup-dormant))))
2985
2986 ;; Some summary mode macros.
2987
2988 (defmacro gnus-summary-article-number ()
2989   "The article number of the article on the current line.
2990 If there isn't an article number here, then we return the current
2991 article number."
2992   '(progn
2993      (gnus-summary-skip-intangible)
2994      (or (get-text-property (point) 'gnus-number)
2995          (gnus-summary-last-subject))))
2996
2997 (defmacro gnus-summary-article-header (&optional number)
2998   "Return the header of article NUMBER."
2999   `(gnus-data-header (gnus-data-find
3000                       ,(or number '(gnus-summary-article-number)))))
3001
3002 (defmacro gnus-summary-thread-level (&optional number)
3003   "Return the level of thread that starts with article NUMBER."
3004   `(if (and (eq gnus-summary-make-false-root 'dummy)
3005             (get-text-property (point) 'gnus-intangible))
3006        0
3007      (gnus-data-level (gnus-data-find
3008                        ,(or number '(gnus-summary-article-number))))))
3009
3010 (defmacro gnus-summary-article-mark (&optional number)
3011   "Return the mark of article NUMBER."
3012   `(gnus-data-mark (gnus-data-find
3013                     ,(or number '(gnus-summary-article-number)))))
3014
3015 (defmacro gnus-summary-article-pos (&optional number)
3016   "Return the position of the line of article NUMBER."
3017   `(gnus-data-pos (gnus-data-find
3018                    ,(or number '(gnus-summary-article-number)))))
3019
3020 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3021 (defmacro gnus-summary-article-subject (&optional number)
3022   "Return current subject string or nil if nothing."
3023   `(let ((headers
3024           ,(if number
3025                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3026              '(gnus-data-header (assq (gnus-summary-article-number)
3027                                       gnus-newsgroup-data)))))
3028      (and headers
3029           (vectorp headers)
3030           (mail-header-subject headers))))
3031
3032 (defmacro gnus-summary-article-score (&optional number)
3033   "Return current article score."
3034   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3035                   gnus-newsgroup-scored))
3036        gnus-summary-default-score 0))
3037
3038 (defun gnus-summary-article-children (&optional number)
3039   "Return a list of article numbers that are children of article NUMBER."
3040   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3041          (level (gnus-data-level (car data)))
3042          l children)
3043     (while (and (setq data (cdr data))
3044                 (> (setq l (gnus-data-level (car data))) level))
3045       (and (= (1+ level) l)
3046            (push (gnus-data-number (car data))
3047                  children)))
3048     (nreverse children)))
3049
3050 (defun gnus-summary-article-parent (&optional number)
3051   "Return the article number of the parent of article NUMBER."
3052   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3053                                     (gnus-data-list t)))
3054          (level (gnus-data-level (car data))))
3055     (if (zerop level)
3056         ()                              ; This is a root.
3057       ;; We search until we find an article with a level less than
3058       ;; this one.  That function has to be the parent.
3059       (while (and (setq data (cdr data))
3060                   (not (< (gnus-data-level (car data)) level))))
3061       (and data (gnus-data-number (car data))))))
3062
3063 (defun gnus-unread-mark-p (mark)
3064   "Say whether MARK is the unread mark."
3065   (= mark gnus-unread-mark))
3066
3067 (defun gnus-read-mark-p (mark)
3068   "Say whether MARK is one of the marks that mark as read.
3069 This is all marks except unread, ticked, dormant, and expirable."
3070   (not (or (= mark gnus-unread-mark)
3071            (= mark gnus-ticked-mark)
3072            (= mark gnus-spam-mark)
3073            (= mark gnus-dormant-mark)
3074            (= mark gnus-expirable-mark))))
3075
3076 (defmacro gnus-article-mark (number)
3077   "Return the MARK of article NUMBER.
3078 This macro should only be used when computing the mark the \"first\"
3079 time; i.e., when generating the summary lines.  After that,
3080 `gnus-summary-article-mark' should be used to examine the
3081 marks of articles."
3082   `(cond
3083     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3084     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3085     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3086     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3087     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3088     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3089     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3090     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3091            gnus-ancient-mark))))
3092
3093 ;; Saving hidden threads.
3094
3095 (defmacro gnus-save-hidden-threads (&rest forms)
3096   "Save hidden threads, eval FORMS, and restore the hidden threads."
3097   (let ((config (make-symbol "config")))
3098     `(let ((,config (gnus-hidden-threads-configuration)))
3099        (unwind-protect
3100            (save-excursion
3101              ,@forms)
3102          (gnus-restore-hidden-threads-configuration ,config)))))
3103 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3104 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3105
3106 (defun gnus-data-compute-positions ()
3107   "Compute the positions of all articles."
3108   (setq gnus-newsgroup-data-reverse nil)
3109   (let ((data gnus-newsgroup-data))
3110     (save-excursion
3111       (gnus-save-hidden-threads
3112         (gnus-summary-show-all-threads)
3113         (goto-char (point-min))
3114         (while data
3115           (while (get-text-property (point) 'gnus-intangible)
3116             (forward-line 1))
3117           (gnus-data-set-pos (car data) (+ (point) 3))
3118           (setq data (cdr data))
3119           (forward-line 1))))))
3120
3121 (defun gnus-hidden-threads-configuration ()
3122   "Return the current hidden threads configuration."
3123   (save-excursion
3124     (let (config)
3125       (goto-char (point-min))
3126       (while (search-forward "\r" nil t)
3127         (push (1- (point)) config))
3128       config)))
3129
3130 (defun gnus-restore-hidden-threads-configuration (config)
3131   "Restore hidden threads configuration from CONFIG."
3132   (save-excursion
3133     (let (point buffer-read-only)
3134       (while (setq point (pop config))
3135         (when (and (< point (point-max))
3136                    (goto-char point)
3137                    (eq (char-after) ?\n))
3138           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3139
3140 ;; Various summary mode internalish functions.
3141
3142 (defun gnus-mouse-pick-article (e)
3143   (interactive "e")
3144   (mouse-set-point e)
3145   (gnus-summary-next-page nil t))
3146
3147 (defun gnus-summary-set-display-table ()
3148   "Change the display table.
3149 Odd characters have a tendency to mess
3150 up nicely formatted displays - we make all possible glyphs
3151 display only a single character."
3152
3153   ;; We start from the standard display table, if any.
3154   (let ((table (or (copy-sequence standard-display-table)
3155                    (make-display-table)))
3156         (i 32))
3157     ;; Nix out all the control chars...
3158     (while (>= (setq i (1- i)) 0)
3159       (aset table i [??]))
3160     ;; ... but not newline and cr, of course.  (cr is necessary for the
3161     ;; selective display).
3162     (aset table ?\n nil)
3163     (aset table ?\r nil)
3164     ;; We keep TAB as well.
3165     (aset table ?\t nil)
3166     ;; We nix out any glyphs over 126 that are not set already.
3167     (let ((i 256))
3168       (while (>= (setq i (1- i)) 127)
3169         ;; Only modify if the entry is nil.
3170         (unless (aref table i)
3171           (aset table i [??]))))
3172     (setq buffer-display-table table)))
3173
3174 (defun gnus-summary-set-article-display-arrow (pos)
3175   "Update the overlay arrow to point to line at position POS."
3176   (when (and gnus-summary-display-arrow
3177              (boundp 'overlay-arrow-position)
3178              (boundp 'overlay-arrow-string))
3179     (save-excursion
3180       (goto-char pos)
3181       (beginning-of-line)
3182       (unless overlay-arrow-position
3183         (setq overlay-arrow-position (make-marker)))
3184       (setq overlay-arrow-string "=>"
3185             overlay-arrow-position (set-marker overlay-arrow-position
3186                                                (point)
3187                                                (current-buffer))))))
3188
3189 (defun gnus-summary-setup-buffer (group)
3190   "Initialize summary buffer."
3191   (let ((buffer (gnus-summary-buffer-name group))
3192         (dead-name (concat "*Dead Summary "
3193                            (gnus-group-decoded-name group) "*")))
3194     ;; If a dead summary buffer exists, we kill it.
3195     (when (gnus-buffer-live-p dead-name)
3196       (gnus-kill-buffer dead-name))
3197     (if (get-buffer buffer)
3198         (progn
3199           (set-buffer buffer)
3200           (setq gnus-summary-buffer (current-buffer))
3201           (not gnus-newsgroup-prepared))
3202       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3203       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3204       (gnus-summary-mode group)
3205       (when gnus-carpal
3206         (gnus-carpal-setup-buffer 'summary))
3207       (unless gnus-single-article-buffer
3208         (make-local-variable 'gnus-article-buffer)
3209         (make-local-variable 'gnus-article-current)
3210         (make-local-variable 'gnus-original-article-buffer))
3211       (setq gnus-newsgroup-name group)
3212       ;; Set any local variables in the group parameters.
3213       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3214       t)))
3215
3216 (defun gnus-set-global-variables ()
3217   "Set the global equivalents of the buffer-local variables.
3218 They are set to the latest values they had.  These reflect the summary
3219 buffer that was in action when the last article was fetched."
3220   (when (eq major-mode 'gnus-summary-mode)
3221     (setq gnus-summary-buffer (current-buffer))
3222     (let ((name gnus-newsgroup-name)
3223           (marked gnus-newsgroup-marked)
3224           (spam gnus-newsgroup-spam-marked)
3225           (unread gnus-newsgroup-unreads)
3226           (headers gnus-current-headers)
3227           (data gnus-newsgroup-data)
3228           (summary gnus-summary-buffer)
3229           (article-buffer gnus-article-buffer)
3230           (original gnus-original-article-buffer)
3231           (gac gnus-article-current)
3232           (reffed gnus-reffed-article-number)
3233           (score-file gnus-current-score-file)
3234           (default-charset gnus-newsgroup-charset)
3235           vlist)
3236       (let ((locals gnus-newsgroup-variables))
3237         (while locals
3238           (if (consp (car locals))
3239               (push (eval (caar locals)) vlist)
3240             (push (eval (car locals)) vlist))
3241           (setq locals (cdr locals)))
3242         (setq vlist (nreverse vlist)))
3243       (with-current-buffer gnus-group-buffer
3244         (setq gnus-newsgroup-name name
3245               gnus-newsgroup-marked marked
3246               gnus-newsgroup-spam-marked spam
3247               gnus-newsgroup-unreads unread
3248               gnus-current-headers headers
3249               gnus-newsgroup-data data
3250               gnus-article-current gac
3251               gnus-summary-buffer summary
3252               gnus-article-buffer article-buffer
3253               gnus-original-article-buffer original
3254               gnus-reffed-article-number reffed
3255               gnus-current-score-file score-file
3256               gnus-newsgroup-charset default-charset)
3257         (let ((locals gnus-newsgroup-variables))
3258           (while locals
3259             (if (consp (car locals))
3260                 (set (caar locals) (pop vlist))
3261               (set (car locals) (pop vlist)))
3262             (setq locals (cdr locals))))
3263         ;; The article buffer also has local variables.
3264         (when (gnus-buffer-live-p gnus-article-buffer)
3265           (set-buffer gnus-article-buffer)
3266           (setq gnus-summary-buffer summary))))))
3267
3268 (defun gnus-summary-article-unread-p (article)
3269   "Say whether ARTICLE is unread or not."
3270   (memq article gnus-newsgroup-unreads))
3271
3272 (defun gnus-summary-first-article-p (&optional article)
3273   "Return whether ARTICLE is the first article in the buffer."
3274   (if (not (setq article (or article (gnus-summary-article-number))))
3275       nil
3276     (eq article (caar gnus-newsgroup-data))))
3277
3278 (defun gnus-summary-last-article-p (&optional article)
3279   "Return whether ARTICLE is the last article in the buffer."
3280   (if (not (setq article (or article (gnus-summary-article-number))))
3281       ;; All non-existent numbers are the last article.  :-)
3282       t
3283     (not (cdr (gnus-data-find-list article)))))
3284
3285 (defun gnus-make-thread-indent-array ()
3286   (let ((n 200))
3287     (unless (and gnus-thread-indent-array
3288                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3289       (setq gnus-thread-indent-array (make-vector 201 "")
3290             gnus-thread-indent-array-level gnus-thread-indent-level)
3291       (while (>= n 0)
3292         (aset gnus-thread-indent-array n
3293               (make-string (* n gnus-thread-indent-level) ? ))
3294         (setq n (1- n))))))
3295
3296 (defun gnus-update-summary-mark-positions ()
3297   "Compute where the summary marks are to go."
3298   (save-excursion
3299     (when (gnus-buffer-exists-p gnus-summary-buffer)
3300       (set-buffer gnus-summary-buffer))
3301     (let ((spec gnus-summary-line-format-spec)
3302           pos)
3303       (save-excursion
3304         (gnus-set-work-buffer)
3305         (let ((gnus-tmp-unread ?Z)
3306               (gnus-replied-mark ?Z)
3307               (gnus-score-below-mark ?Z)
3308               (gnus-score-over-mark ?Z)
3309               (gnus-undownloaded-mark ?Z)
3310               (gnus-summary-line-format-spec spec)
3311               (gnus-newsgroup-downloadable '(0))
3312               (header
3313                (make-full-mail-header
3314                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3315               case-fold-search ignores)
3316           ;; Here, all marks are bound to Z.
3317           (gnus-summary-insert-line header
3318                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3319           (goto-char (point-min))
3320           ;; Memorize the positions of the same characters as dummy marks.
3321           (while (re-search-forward "[A-D]" nil t)
3322             (push (point) ignores))
3323           (erase-buffer)
3324           ;; We use A-D as dummy marks in order to know column positions
3325           ;; where marks should be inserted.
3326           (setq gnus-tmp-unread ?A
3327                 gnus-replied-mark ?B
3328                 gnus-score-below-mark ?C
3329                 gnus-score-over-mark ?C
3330                 gnus-undownloaded-mark ?D)
3331           (gnus-summary-insert-line header
3332                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3333           ;; Ignore characters which aren't dummy marks.
3334           (dolist (p ignores)
3335             (delete-region (goto-char (1- p)) p)
3336             (insert ?Z))
3337           (goto-char (point-min))
3338           (setq pos (list (cons 'unread
3339                                 (and (search-forward "A" nil t)
3340                                      (- (point) (point-min) 1)))))
3341           (goto-char (point-min))
3342           (push (cons 'replied (and (search-forward "B" nil t)
3343                                     (- (point) (point-min) 1)))
3344                 pos)
3345           (goto-char (point-min))
3346           (push (cons 'score (and (search-forward "C" nil t)
3347                                   (- (point) (point-min) 1)))
3348                 pos)
3349           (goto-char (point-min))
3350           (push (cons 'download (and (search-forward "D" nil t)
3351                                      (- (point) (point-min) 1)))
3352                 pos)))
3353       (setq gnus-summary-mark-positions pos))))
3354
3355 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3356   "Insert a dummy root in the summary buffer."
3357   (beginning-of-line)
3358   (gnus-add-text-properties
3359    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3360    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3361
3362 (defun gnus-summary-extract-address-component (from)
3363   (or (car (funcall gnus-extract-address-components from))
3364       from))
3365
3366 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3367   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3368                                 default-mime-charset)))
3369     ;; Is it really necessary to do this next part for each summary line?
3370     ;; Luckily, doesn't seem to slow things down much.
3371     (or
3372      (and gnus-ignored-from-addresses
3373           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3374           (let ((extra-headers (mail-header-extra header))
3375                 to
3376                 newsgroups)
3377             (cond
3378              ((setq to (cdr (assq 'To extra-headers)))
3379               (concat gnus-summary-to-prefix
3380                       (inline
3381                         (gnus-summary-extract-address-component
3382                          (funcall gnus-decode-encoded-word-function to)))))
3383              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3384               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3385      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3386
3387 (defun gnus-summary-insert-line (gnus-tmp-header
3388                                  gnus-tmp-level gnus-tmp-current
3389                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3390                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3391                                  &optional gnus-tmp-dummy gnus-tmp-score
3392                                  gnus-tmp-process)
3393   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3394          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3395          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3396          (gnus-tmp-score-char
3397           (if (or (null gnus-summary-default-score)
3398                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3399                       gnus-summary-zcore-fuzz))
3400               ?\ ;;;Whitespace
3401             (if (< gnus-tmp-score gnus-summary-default-score)
3402                 gnus-score-below-mark gnus-score-over-mark)))
3403          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3404          (gnus-tmp-replied
3405           (cond (gnus-tmp-process gnus-process-mark)
3406                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3407                  gnus-cached-mark)
3408                 (gnus-tmp-replied gnus-replied-mark)
3409                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3410                  gnus-forwarded-mark)
3411                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3412                  gnus-saved-mark)
3413                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3414                  gnus-recent-mark)
3415                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3416                  gnus-unseen-mark)
3417                 (t gnus-no-mark)))
3418          (gnus-tmp-downloaded
3419           (cond (undownloaded
3420                  gnus-undownloaded-mark)
3421                 (gnus-newsgroup-agentized
3422                  gnus-downloaded-mark)
3423                 (t
3424                  gnus-no-mark)))
3425          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3426          (gnus-tmp-name
3427           (cond
3428            ((string-match "<[^>]+> *$" gnus-tmp-from)
3429             (let ((beg (match-beginning 0)))
3430               (or (and (string-match "^\".+\"" gnus-tmp-from)
3431                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3432                   (substring gnus-tmp-from 0 beg))))
3433            ((string-match "(.+)" gnus-tmp-from)
3434             (substring gnus-tmp-from
3435                        (1+ (match-beginning 0)) (1- (match-end 0))))
3436            (t gnus-tmp-from)))
3437          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3438          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3439          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3440          (buffer-read-only nil))
3441     (when (string= gnus-tmp-name "")
3442       (setq gnus-tmp-name gnus-tmp-from))
3443     (unless (numberp gnus-tmp-lines)
3444       (setq gnus-tmp-lines -1))
3445     (if (= gnus-tmp-lines -1)
3446         (setq gnus-tmp-lines "?")
3447       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3448     (gnus-put-text-property-excluding-characters-with-faces
3449      (point)
3450      (progn (eval gnus-summary-line-format-spec) (point))
3451      'gnus-number gnus-tmp-number)
3452     (when (gnus-visual-p 'summary-highlight 'highlight)
3453       (forward-line -1)
3454       (gnus-run-hooks 'gnus-summary-update-hook)
3455       (forward-line 1))))
3456
3457 (defun gnus-summary-update-line (&optional dont-update)
3458   "Update summary line after change."
3459   (when (and gnus-summary-default-score
3460              (not gnus-summary-inhibit-highlight))
3461     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3462            (article (gnus-summary-article-number))
3463            (score (gnus-summary-article-score article)))
3464       (unless dont-update
3465         (if (and gnus-summary-mark-below
3466                  (< (gnus-summary-article-score)
3467                     gnus-summary-mark-below))
3468             ;; This article has a low score, so we mark it as read.
3469             (when (memq article gnus-newsgroup-unreads)
3470               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3471           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3472             ;; This article was previously marked as read on account
3473             ;; of a low score, but now it has risen, so we mark it as
3474             ;; unread.
3475             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3476         (gnus-summary-update-mark
3477          (if (or (null gnus-summary-default-score)
3478                  (<= (abs (- score gnus-summary-default-score))
3479                      gnus-summary-zcore-fuzz))
3480              ?\ ;;;Whitespace
3481            (if (< score gnus-summary-default-score)
3482                gnus-score-below-mark gnus-score-over-mark))
3483          'score))
3484       ;; Do visual highlighting.
3485       (when (gnus-visual-p 'summary-highlight 'highlight)
3486         (gnus-run-hooks 'gnus-summary-update-hook)))))
3487
3488 (defvar gnus-tmp-new-adopts nil)
3489
3490 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3491   "Return the number of articles in THREAD.
3492 This may be 0 in some cases -- if none of the articles in
3493 the thread are to be displayed."
3494   (let* ((number
3495           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3496           (cond
3497            ((not (listp thread))
3498             1)
3499            ((and (consp thread) (cdr thread))
3500             (apply
3501              '+ 1 (mapcar
3502                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3503            ((null thread)
3504             1)
3505            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3506             1)
3507            (t 0))))
3508     (when (and level (zerop level) gnus-tmp-new-adopts)
3509       (incf number
3510             (apply '+ (mapcar
3511                        'gnus-summary-number-of-articles-in-thread
3512                        gnus-tmp-new-adopts))))
3513     (if char
3514         (if (> number 1) gnus-not-empty-thread-mark
3515           gnus-empty-thread-mark)
3516       number)))
3517
3518 (defsubst gnus-summary-line-message-size (head)
3519   "Return pretty-printed version of message size.
3520 This function is intended to be used in
3521 `gnus-summary-line-format-alist'."
3522   (let ((c (or (mail-header-chars head) -1)))
3523     (cond ((< c 0) "n/a")               ; chars not available
3524           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3525           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3526           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3527           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3528
3529
3530 (defun gnus-summary-set-local-parameters (group)
3531   "Go through the local params of GROUP and set all variable specs in that list."
3532   (let ((vars '(quit-config)))          ; Ignore quit-config.
3533     (dolist (elem (gnus-group-find-parameter group))
3534       (and (consp elem)                 ; Has to be a cons.
3535            (consp (cdr elem))           ; The cdr has to be a list.
3536            (symbolp (car elem))         ; Has to be a symbol in there.
3537            (not (memq (car elem) vars))
3538            (ignore-errors               ; So we set it.
3539              (push (car elem) vars)
3540              (make-local-variable (car elem))
3541              (set (car elem) (eval (nth 1 elem))))))))
3542
3543 (defun gnus-summary-read-group (group &optional show-all no-article
3544                                       kill-buffer no-display backward
3545                                       select-articles)
3546   "Start reading news in newsgroup GROUP.
3547 If SHOW-ALL is non-nil, already read articles are also listed.
3548 If NO-ARTICLE is non-nil, no article is selected initially.
3549 If NO-DISPLAY, don't generate a summary buffer."
3550   (let (result)
3551     (while (and group
3552                 (null (setq result
3553                             (let ((gnus-auto-select-next nil))
3554                               (or (gnus-summary-read-group-1
3555                                    group show-all no-article
3556                                    kill-buffer no-display
3557                                    select-articles)
3558                                   (setq show-all nil
3559                                         select-articles nil)))))
3560                 (eq gnus-auto-select-next 'quietly))
3561       (set-buffer gnus-group-buffer)
3562       ;; The entry function called above goes to the next
3563       ;; group automatically, so we go two groups back
3564       ;; if we are searching for the previous group.
3565       (when backward
3566         (gnus-group-prev-unread-group 2))
3567       (if (not (equal group (gnus-group-group-name)))
3568           (setq group (gnus-group-group-name))
3569         (setq group nil)))
3570     result))
3571
3572 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3573   "Directly jump to the other GROUP from summary buffer.
3574 If SHOW-ALL is non-nil, already read articles are also listed."
3575   (interactive
3576    (if (eq gnus-summary-buffer (current-buffer))
3577        (list (completing-read
3578               "Group: " gnus-active-hashtb nil t
3579               (when (and gnus-newsgroup-name
3580                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3581                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3582               'gnus-group-history)
3583              current-prefix-arg)
3584      (error "%s must be invoked from a gnus summary buffer." this-command)))
3585   (unless (or (zerop (length group))
3586               (and gnus-newsgroup-name
3587                    (string-equal gnus-newsgroup-name group)))
3588     (gnus-summary-exit)
3589     (gnus-summary-read-group group show-all
3590                              gnus-dont-select-after-jump-to-other-group)))
3591
3592 (defun gnus-summary-read-group-1 (group show-all no-article
3593                                         kill-buffer no-display
3594                                         &optional select-articles)
3595   ;; Killed foreign groups can't be entered.
3596   ;;  (when (and (not (gnus-group-native-p group))
3597   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3598   ;;    (error "Dead non-native groups can't be entered"))
3599   (gnus-message 5 "Retrieving newsgroup: %s..."
3600                 (gnus-group-decoded-name group))
3601   (let* ((new-group (gnus-summary-setup-buffer group))
3602          (quit-config (gnus-group-quit-config group))
3603          (did-select (and new-group (gnus-select-newsgroup
3604                                      group show-all select-articles))))
3605     (cond
3606      ;; This summary buffer exists already, so we just select it.
3607      ((not new-group)
3608       (gnus-set-global-variables)
3609       (when kill-buffer
3610         (gnus-kill-or-deaden-summary kill-buffer))
3611       (gnus-configure-windows 'summary 'force)
3612       (gnus-set-mode-line 'summary)
3613       (gnus-summary-position-point)
3614       (message "")
3615       t)
3616      ;; We couldn't select this group.
3617      ((null did-select)
3618       (when (and (eq major-mode 'gnus-summary-mode)
3619                  (not (equal (current-buffer) kill-buffer)))
3620         (kill-buffer (current-buffer))
3621         (if (not quit-config)
3622             (progn
3623               ;; Update the info -- marks might need to be removed,
3624               ;; for instance.
3625               (gnus-summary-update-info)
3626               (set-buffer gnus-group-buffer)
3627               (gnus-group-jump-to-group group)
3628               (gnus-group-next-unread-group 1))
3629           (gnus-handle-ephemeral-exit quit-config)))
3630       (let ((grpinfo (gnus-get-info group)))
3631         (if (null (gnus-info-read grpinfo))
3632             (gnus-message 3 "Group %s contains no messages"
3633                           (gnus-group-decoded-name group))
3634           (gnus-message 3 "Can't select group")))
3635       nil)
3636      ;; The user did a `C-g' while prompting for number of articles,
3637      ;; so we exit this group.
3638      ((eq did-select 'quit)
3639       (and (eq major-mode 'gnus-summary-mode)
3640            (not (equal (current-buffer) kill-buffer))
3641            (kill-buffer (current-buffer)))
3642       (when kill-buffer
3643         (gnus-kill-or-deaden-summary kill-buffer))
3644       (if (not quit-config)
3645           (progn
3646             (set-buffer gnus-group-buffer)
3647             (gnus-group-jump-to-group group)
3648             (gnus-group-next-unread-group 1)
3649             (gnus-configure-windows 'group 'force))
3650         (gnus-handle-ephemeral-exit quit-config))
3651       ;; Finally signal the quit.
3652       (signal 'quit nil))
3653      ;; The group was successfully selected.
3654      (t
3655       (gnus-set-global-variables)
3656       ;; Save the active value in effect when the group was entered.
3657       (setq gnus-newsgroup-active
3658             (gnus-copy-sequence
3659              (gnus-active gnus-newsgroup-name)))
3660       ;; You can change the summary buffer in some way with this hook.
3661       (gnus-run-hooks 'gnus-select-group-hook)
3662       (when (memq 'summary (gnus-update-format-specifications
3663                             nil 'summary 'summary-mode 'summary-dummy))
3664         ;; The format specification for the summary line was updated,
3665         ;; so we need to update the mark positions as well.
3666         (gnus-update-summary-mark-positions))
3667       ;; Do score processing.
3668       (when gnus-use-scoring
3669         (gnus-possibly-score-headers))
3670       ;; Check whether to fill in the gaps in the threads.
3671       (when gnus-build-sparse-threads
3672         (gnus-build-sparse-threads))
3673       ;; Find the initial limit.
3674       (if show-all
3675           (let ((gnus-newsgroup-dormant nil))
3676             (gnus-summary-initial-limit show-all))
3677         (gnus-summary-initial-limit show-all))
3678       ;; Generate the summary buffer.
3679       (unless no-display
3680         (gnus-summary-prepare))
3681       (when gnus-use-trees
3682         (gnus-tree-open group)
3683         (setq gnus-summary-highlight-line-function
3684               'gnus-tree-highlight-article))
3685       ;; If the summary buffer is empty, but there are some low-scored
3686       ;; articles or some excluded dormants, we include these in the
3687       ;; buffer.
3688       (when (and (zerop (buffer-size))
3689                  (not no-display))
3690         (cond (gnus-newsgroup-dormant
3691                (gnus-summary-limit-include-dormant))
3692               ((and gnus-newsgroup-scored show-all)
3693                (gnus-summary-limit-include-expunged t))))
3694       ;; Function `gnus-apply-kill-file' must be called in this hook.
3695       (gnus-run-hooks 'gnus-apply-kill-hook)
3696       (if (and (zerop (buffer-size))
3697                (not no-display))
3698           (progn
3699             ;; This newsgroup is empty.
3700             (gnus-summary-catchup-and-exit nil t)
3701             (gnus-message 6 "No unread news")
3702             (when kill-buffer
3703               (gnus-kill-or-deaden-summary kill-buffer))
3704             ;; Return nil from this function.
3705             nil)
3706         ;; Hide conversation thread subtrees.  We cannot do this in
3707         ;; gnus-summary-prepare-hook since kill processing may not
3708         ;; work with hidden articles.
3709         (gnus-summary-maybe-hide-threads)
3710         (when kill-buffer
3711           (gnus-kill-or-deaden-summary kill-buffer))
3712         (gnus-summary-auto-select-subject)
3713         ;; Show first unread article if requested.
3714         (if (and (not no-article)
3715                  (not no-display)
3716                  gnus-newsgroup-unreads
3717                  gnus-auto-select-first)
3718             (progn
3719               (gnus-configure-windows 'summary)
3720               (let ((art (gnus-summary-article-number)))
3721                 (unless (and (not gnus-plugged)
3722                              (or (memq art gnus-newsgroup-undownloaded)
3723                                  (memq art gnus-newsgroup-downloadable)))
3724                   (gnus-summary-goto-article art))))
3725           ;; Don't select any articles.
3726           (gnus-summary-position-point)
3727           (gnus-configure-windows 'summary 'force)
3728           (gnus-set-mode-line 'summary))
3729         (when (and gnus-auto-center-group
3730                    (get-buffer-window gnus-group-buffer t))
3731           ;; Gotta use windows, because recenter does weird stuff if
3732           ;; the current buffer ain't the displayed window.
3733           (let ((owin (selected-window)))
3734             (select-window (get-buffer-window gnus-group-buffer t))
3735             (when (gnus-group-goto-group group)
3736               (recenter))
3737             (select-window owin)))
3738         ;; Mark this buffer as "prepared".
3739         (setq gnus-newsgroup-prepared t)
3740         (gnus-run-hooks 'gnus-summary-prepared-hook)
3741         (unless (gnus-ephemeral-group-p group)
3742           (gnus-group-update-group group))
3743         t)))))
3744
3745 (defun gnus-summary-auto-select-subject ()
3746   "Select the subject line on initial group entry."
3747   (goto-char (point-min))
3748   (cond
3749    ((eq gnus-auto-select-subject 'best)
3750     (gnus-summary-best-unread-subject))
3751    ((eq gnus-auto-select-subject 'unread)
3752     (gnus-summary-first-unread-subject))
3753    ((eq gnus-auto-select-subject 'unseen)
3754     (gnus-summary-first-unseen-subject))
3755    ((eq gnus-auto-select-subject 'unseen-or-unread)
3756     (gnus-summary-first-unseen-or-unread-subject))
3757    ((eq gnus-auto-select-subject 'first)
3758     ;; Do nothing.
3759     )
3760    ((functionp gnus-auto-select-subject)
3761     (funcall gnus-auto-select-subject))))
3762
3763 (defun gnus-summary-prepare ()
3764   "Generate the summary buffer."
3765   (interactive)
3766   (let ((buffer-read-only nil))
3767     (erase-buffer)
3768     (setq gnus-newsgroup-data nil
3769           gnus-newsgroup-data-reverse nil)
3770     (gnus-run-hooks 'gnus-summary-generate-hook)
3771     ;; Generate the buffer, either with threads or without.
3772     (when gnus-newsgroup-headers
3773       (gnus-summary-prepare-threads
3774        (if gnus-show-threads
3775            (gnus-sort-gathered-threads
3776             (funcall gnus-summary-thread-gathering-function
3777                      (gnus-sort-threads
3778                       (gnus-cut-threads (gnus-make-threads)))))
3779          ;; Unthreaded display.
3780          (gnus-sort-articles gnus-newsgroup-headers))))
3781     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3782     ;; Call hooks for modifying summary buffer.
3783     (goto-char (point-min))
3784     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3785
3786 (defsubst gnus-general-simplify-subject (subject)
3787   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3788   (setq subject
3789         (cond
3790          ;; Truncate the subject.
3791          (gnus-simplify-subject-functions
3792           (gnus-map-function gnus-simplify-subject-functions subject))
3793          ((numberp gnus-summary-gather-subject-limit)
3794           (setq subject (gnus-simplify-subject-re subject))
3795           (if (> (length subject) gnus-summary-gather-subject-limit)
3796               (substring subject 0 gnus-summary-gather-subject-limit)
3797             subject))
3798          ;; Fuzzily simplify it.
3799          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3800           (gnus-simplify-subject-fuzzy subject))
3801          ;; Just remove the leading "Re:".
3802          (t
3803           (gnus-simplify-subject-re subject))))
3804
3805   (if (and gnus-summary-gather-exclude-subject
3806            (string-match gnus-summary-gather-exclude-subject subject))
3807       nil                               ; This article shouldn't be gathered
3808     subject))
3809
3810 (defun gnus-summary-simplify-subject-query ()
3811   "Query where the respool algorithm would put this article."
3812   (interactive)
3813   (gnus-summary-select-article)
3814   (message "%s"
3815            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3816
3817 (defun gnus-gather-threads-by-subject (threads)
3818   "Gather threads by looking at Subject headers."
3819   (if (not gnus-summary-make-false-root)
3820       threads
3821     (let ((hashtb (gnus-make-hashtable 1024))
3822           (prev threads)
3823           (result threads)
3824           subject hthread whole-subject)
3825       (while threads
3826         (setq subject (gnus-general-simplify-subject
3827                        (setq whole-subject (mail-header-subject
3828                                             (caar threads)))))
3829         (when subject
3830           (if (setq hthread (gnus-gethash subject hashtb))
3831               (progn
3832                 ;; We enter a dummy root into the thread, if we
3833                 ;; haven't done that already.
3834                 (unless (stringp (caar hthread))
3835                   (setcar hthread (list whole-subject (car hthread))))
3836                 ;; We add this new gathered thread to this gathered
3837                 ;; thread.
3838                 (setcdr (car hthread)
3839                         (nconc (cdar hthread) (list (car threads))))
3840                 ;; Remove it from the list of threads.
3841                 (setcdr prev (cdr threads))
3842                 (setq threads prev))
3843             ;; Enter this thread into the hash table.
3844             (gnus-sethash subject
3845                           (if gnus-summary-make-false-root-always
3846                               (progn
3847                                 ;; If you want a dummy root above all
3848                                 ;; threads...
3849                                 (setcar threads (list whole-subject
3850                                                       (car threads)))
3851                                 threads)
3852                             threads)
3853                           hashtb)))
3854         (setq prev threads)
3855         (setq threads (cdr threads)))
3856       result)))
3857
3858 (defun gnus-gather-threads-by-references (threads)
3859   "Gather threads by looking at References headers."
3860   (let ((idhashtb (gnus-make-hashtable 1024))
3861         (thhashtb (gnus-make-hashtable 1024))
3862         (prev threads)
3863         (result threads)
3864         ids references id gthread gid entered ref)
3865     (while threads
3866       (when (setq references (mail-header-references (caar threads)))
3867         (setq id (mail-header-id (caar threads))
3868               ids (inline (gnus-split-references references))
3869               entered nil)
3870         (while (setq ref (pop ids))
3871           (setq ids (delete ref ids))
3872           (if (not (setq gid (gnus-gethash ref idhashtb)))
3873               (progn
3874                 (gnus-sethash ref id idhashtb)
3875                 (gnus-sethash id threads thhashtb))
3876             (setq gthread (gnus-gethash gid thhashtb))
3877             (unless entered
3878               ;; We enter a dummy root into the thread, if we
3879               ;; haven't done that already.
3880               (unless (stringp (caar gthread))
3881                 (setcar gthread (list (mail-header-subject (caar gthread))
3882                                       (car gthread))))
3883               ;; We add this new gathered thread to this gathered
3884               ;; thread.
3885               (setcdr (car gthread)
3886                       (nconc (cdar gthread) (list (car threads)))))
3887             ;; Add it into the thread hash table.
3888             (gnus-sethash id gthread thhashtb)
3889             (setq entered t)
3890             ;; Remove it from the list of threads.
3891             (setcdr prev (cdr threads))
3892             (setq threads prev))))
3893       (setq prev threads)
3894       (setq threads (cdr threads)))
3895     result))
3896
3897 (defun gnus-sort-gathered-threads (threads)
3898   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3899   (let ((result threads))
3900     (while threads
3901       (when (stringp (caar threads))
3902         (setcdr (car threads)
3903                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3904       (setq threads (cdr threads)))
3905     result))
3906
3907 (defun gnus-thread-loop-p (root thread)
3908   "Say whether ROOT is in THREAD."
3909   (let ((stack (list thread))
3910         (infloop 0)
3911         th)
3912     (while (setq thread (pop stack))
3913       (setq th (cdr thread))
3914       (while (and th
3915                   (not (eq (caar th) root)))
3916         (pop th))
3917       (if th
3918           ;; We have found a loop.
3919           (let (ref-dep)
3920             (setcdr thread (delq (car th) (cdr thread)))
3921             (if (boundp (setq ref-dep (intern "none"
3922                                               gnus-newsgroup-dependencies)))
3923                 (setcdr (symbol-value ref-dep)
3924                         (nconc (cdr (symbol-value ref-dep))
3925                                (list (car th))))
3926               (set ref-dep (list nil (car th))))
3927             (setq infloop 1
3928                   stack nil))
3929         ;; Push all the subthreads onto the stack.
3930         (push (cdr thread) stack)))
3931     infloop))
3932
3933 (defun gnus-make-threads ()
3934   "Go through the dependency hashtb and find the roots.  Return all threads."
3935   (let (threads)
3936     (while (catch 'infloop
3937              (mapatoms
3938               (lambda (refs)
3939                 ;; Deal with self-referencing References loops.
3940                 (when (and (car (symbol-value refs))
3941                            (not (zerop
3942                                  (apply
3943                                   '+
3944                                   (mapcar
3945                                    (lambda (thread)
3946                                      (gnus-thread-loop-p
3947                                       (car (symbol-value refs)) thread))
3948                                    (cdr (symbol-value refs)))))))
3949                   (setq threads nil)
3950                   (throw 'infloop t))
3951                 (unless (car (symbol-value refs))
3952                   ;; These threads do not refer back to any other articles,
3953                   ;; so they're roots.
3954                   (setq threads (append (cdr (symbol-value refs)) threads))))
3955               gnus-newsgroup-dependencies)))
3956     threads))
3957
3958 ;; Build the thread tree.
3959 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3960   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3961
3962 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3963 if it was already present.
3964
3965 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3966 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3967 Message-IDs will be renamed to a unique Message-ID before being
3968 entered.
3969
3970 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3971   (let* ((id (mail-header-id header))
3972          (id-dep (and id (intern id dependencies)))
3973          parent-id ref ref-dep ref-header replaced)
3974     ;; Enter this `header' in the `dependencies' table.
3975     (cond
3976      ((not id-dep)
3977       (setq header nil))
3978      ;; The first two cases do the normal part: enter a new `header'
3979      ;; in the `dependencies' table.
3980      ((not (boundp id-dep))
3981       (set id-dep (list header)))
3982      ((null (car (symbol-value id-dep)))
3983       (setcar (symbol-value id-dep) header))
3984
3985      ;; From here the `header' was already present in the
3986      ;; `dependencies' table.
3987      (force-new
3988       ;; Overrides an existing entry;
3989       ;; just set the header part of the entry.
3990       (setcar (symbol-value id-dep) header)
3991       (setq replaced t))
3992
3993      ;; Renames the existing `header' to a unique Message-ID.
3994      ((not gnus-summary-ignore-duplicates)
3995       ;; An article with this Message-ID has already been seen.
3996       ;; We rename the Message-ID.
3997       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3998            (list header))
3999       (mail-header-set-id header id))
4000
4001      ;; The last case ignores an existing entry, except it adds any
4002      ;; additional Xrefs (in case the two articles came from different
4003      ;; servers.
4004      ;; Also sets `header' to `nil' meaning that the `dependencies'
4005      ;; table was *not* modified.
4006      (t
4007       (mail-header-set-xref
4008        (car (symbol-value id-dep))
4009        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4010                    "")
4011                (or (mail-header-xref header) "")))
4012       (setq header nil)))
4013
4014     (when (and header (not replaced))
4015       ;; First check that we are not creating a References loop.
4016       (setq parent-id (gnus-parent-id (mail-header-references header)))
4017       (setq ref parent-id)
4018       (while (and ref
4019                   (setq ref-dep (intern-soft ref dependencies))
4020                   (boundp ref-dep)
4021                   (setq ref-header (car (symbol-value ref-dep))))
4022         (if (string= id ref)
4023             ;; Yuk!  This is a reference loop.  Make the article be a
4024             ;; root article.
4025             (progn
4026               (mail-header-set-references (car (symbol-value id-dep)) "none")
4027               (setq ref nil)
4028               (setq parent-id nil))
4029           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4030       (setq ref-dep (intern (or parent-id "none") dependencies))
4031       (if (boundp ref-dep)
4032           (setcdr (symbol-value ref-dep)
4033                   (nconc (cdr (symbol-value ref-dep))
4034                          (list (symbol-value id-dep))))
4035         (set ref-dep (list nil (symbol-value id-dep)))))
4036     header))
4037
4038 (defun gnus-extract-message-id-from-in-reply-to (string)
4039   (if (string-match "<[^>]+>" string)
4040       (substring string (match-beginning 0) (match-end 0))
4041     nil))
4042
4043 (defun gnus-build-sparse-threads ()
4044   (let ((headers gnus-newsgroup-headers)
4045         (mail-parse-charset gnus-newsgroup-charset)
4046         (gnus-summary-ignore-duplicates t)
4047         header references generation relations
4048         subject child end new-child date)
4049     ;; First we create an alist of generations/relations, where
4050     ;; generations is how much we trust the relation, and the relation
4051     ;; is parent/child.
4052     (gnus-message 7 "Making sparse threads...")
4053     (save-excursion
4054       (nnheader-set-temp-buffer " *gnus sparse threads*")
4055       (while (setq header (pop headers))
4056         (when (and (setq references (mail-header-references header))
4057                    (not (string= references "")))
4058           (insert references)
4059           (setq child (mail-header-id header)
4060                 subject (mail-header-subject header)
4061                 date (mail-header-date header)
4062                 generation 0)
4063           (while (search-backward ">" nil t)
4064             (setq end (1+ (point)))
4065             (when (search-backward "<" nil t)
4066               (setq new-child (buffer-substring (point) end))
4067               (push (list (incf generation)
4068                           child (setq child new-child)
4069                           subject date)
4070                     relations)))
4071           (when child
4072             (push (list (1+ generation) child nil subject) relations))
4073           (erase-buffer)))
4074       (kill-buffer (current-buffer)))
4075     ;; Sort over trustworthiness.
4076     (mapcar
4077      (lambda (relation)
4078        (when (gnus-dependencies-add-header
4079               (make-full-mail-header-from-decoded-header
4080                gnus-reffed-article-number
4081                (nth 3 relation) "" (or (nth 4 relation) "")
4082                (nth 1 relation)
4083                (or (nth 2 relation) "") 0 0 "")
4084               gnus-newsgroup-dependencies nil)
4085          (push gnus-reffed-article-number gnus-newsgroup-limit)
4086          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4087          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4088                gnus-newsgroup-reads)
4089          (decf gnus-reffed-article-number)))
4090      (sort relations 'car-less-than-car))
4091     (gnus-message 7 "Making sparse threads...done")))
4092
4093 (defun gnus-build-old-threads ()
4094   ;; Look at all the articles that refer back to old articles, and
4095   ;; fetch the headers for the articles that aren't there.  This will
4096   ;; build complete threads - if the roots haven't been expired by the
4097   ;; server, that is.
4098   (let ((mail-parse-charset gnus-newsgroup-charset)
4099         id heads)
4100     (mapatoms
4101      (lambda (refs)
4102        (when (not (car (symbol-value refs)))
4103          (setq heads (cdr (symbol-value refs)))
4104          (while heads
4105            (if (memq (mail-header-number (caar heads))
4106                      gnus-newsgroup-dormant)
4107                (setq heads (cdr heads))
4108              (setq id (symbol-name refs))
4109              (while (and (setq id (gnus-build-get-header id))
4110                          (not (car (gnus-id-to-thread id)))))
4111              (setq heads nil)))))
4112      gnus-newsgroup-dependencies)))
4113
4114 (defsubst gnus-remove-odd-characters (string)
4115   "Translate STRING into something that doesn't contain weird characters."
4116   (mm-subst-char-in-string
4117    ?\r ?\-
4118    (mm-subst-char-in-string ?\n ?\- string t) t))
4119
4120 ;; This function has to be called with point after the article number
4121 ;; on the beginning of the line.
4122 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4123   (let ((eol (point-at-eol))
4124         (buffer (current-buffer))
4125         header references in-reply-to)
4126
4127     ;; overview: [num subject from date id refs chars lines misc]
4128     (unwind-protect
4129         (progn
4130           (narrow-to-region (point) eol)
4131           (unless (eobp)
4132             (forward-char))
4133
4134           (setq header
4135                 (make-full-mail-header
4136                  number                         ; number
4137                  (nnheader-nov-field)           ; subject
4138                  (nnheader-nov-field)           ; from
4139                  (nnheader-nov-field)           ; date
4140                  (nnheader-nov-read-message-id number)  ; id
4141                  (setq references (nnheader-nov-field)) ; refs
4142                  (nnheader-nov-read-integer)    ; chars
4143                  (nnheader-nov-read-integer)    ; lines
4144                  (unless (eobp)
4145                    (if (looking-at "Xref: ")
4146                        (goto-char (match-end 0)))
4147                    (nnheader-nov-field))        ; Xref
4148                  (nnheader-nov-parse-extra))))  ; extra
4149
4150       (widen))
4151
4152     (when (and (string= references "")
4153                (setq in-reply-to (mail-header-extra header))
4154                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4155       (mail-header-set-references
4156        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4157
4158     (when gnus-alter-header-function
4159       (funcall gnus-alter-header-function header))
4160     (gnus-dependencies-add-header header dependencies force-new)))
4161
4162 (defun gnus-build-get-header (id)
4163   "Look through the buffer of NOV lines and find the header to ID.
4164 Enter this line into the dependencies hash table, and return
4165 the id of the parent article (if any)."
4166   (let ((deps gnus-newsgroup-dependencies)
4167         found header)
4168     (prog1
4169         (save-excursion
4170           (set-buffer nntp-server-buffer)
4171           (let ((case-fold-search nil))
4172             (goto-char (point-min))
4173             (while (and (not found)
4174                         (search-forward id nil t))
4175               (beginning-of-line)
4176               (setq found (looking-at
4177                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4178                                    (regexp-quote id))))
4179               (or found (beginning-of-line 2)))
4180             (when found
4181               (beginning-of-line)
4182               (and
4183                (setq header (gnus-nov-parse-line
4184                              (read (current-buffer)) deps))
4185                (gnus-parent-id (mail-header-references header))))))
4186       (when header
4187         (let ((number (mail-header-number header)))
4188           (push number gnus-newsgroup-limit)
4189           (push header gnus-newsgroup-headers)
4190           (if (memq number gnus-newsgroup-unselected)
4191               (progn
4192                 (setq gnus-newsgroup-unreads
4193                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4194                                                number))
4195                 (setq gnus-newsgroup-unselected
4196                       (delq number gnus-newsgroup-unselected)))
4197             (push number gnus-newsgroup-ancient)))))))
4198
4199 (defun gnus-build-all-threads ()
4200   "Read all the headers."
4201   (let ((gnus-summary-ignore-duplicates t)
4202         (mail-parse-charset gnus-newsgroup-charset)
4203         (dependencies gnus-newsgroup-dependencies)
4204         header article)
4205     (save-excursion
4206       (set-buffer nntp-server-buffer)
4207       (let ((case-fold-search nil))
4208         (goto-char (point-min))
4209         (while (not (eobp))
4210           (ignore-errors
4211             (setq article (read (current-buffer))
4212                   header (gnus-nov-parse-line article dependencies)))
4213           (when header
4214             (with-current-buffer gnus-summary-buffer
4215               (push header gnus-newsgroup-headers)
4216               (if (memq (setq article (mail-header-number header))
4217                         gnus-newsgroup-unselected)
4218                   (progn
4219                     (setq gnus-newsgroup-unreads
4220                           (gnus-add-to-sorted-list
4221                            gnus-newsgroup-unreads article))
4222                     (setq gnus-newsgroup-unselected
4223                           (delq article gnus-newsgroup-unselected)))
4224                 (push article gnus-newsgroup-ancient)))
4225             (forward-line 1)))))))
4226
4227 (defun gnus-summary-update-article-line (article header)
4228   "Update the line for ARTICLE using HEADER."
4229   (let* ((id (mail-header-id header))
4230          (thread (gnus-id-to-thread id)))
4231     (unless thread
4232       (error "Article in no thread"))
4233     ;; Update the thread.
4234     (setcar thread header)
4235     (gnus-summary-goto-subject article)
4236     (let* ((datal (gnus-data-find-list article))
4237            (data (car datal))
4238            (buffer-read-only nil)
4239            (level (gnus-summary-thread-level)))
4240       (gnus-delete-line)
4241       (let ((inserted (- (point)
4242                          (progn
4243                            (gnus-summary-insert-line
4244                             header level nil
4245                             (memq article gnus-newsgroup-undownloaded)
4246                             (gnus-article-mark article)
4247                             (memq article gnus-newsgroup-replied)
4248                             (memq article gnus-newsgroup-expirable)
4249                             ;; Only insert the Subject string when it's different
4250                             ;; from the previous Subject string.
4251                             (if (and
4252                                  gnus-show-threads
4253                                  (gnus-subject-equal
4254                                   (condition-case ()
4255                                       (mail-header-subject
4256                                        (gnus-data-header
4257                                         (cadr
4258                                          (gnus-data-find-list
4259                                           article
4260                                           (gnus-data-list t)))))
4261                                     ;; Error on the side of excessive subjects.
4262                                     (error ""))
4263                                   (mail-header-subject header)))
4264                                 ""
4265                               (mail-header-subject header))
4266                             nil (cdr (assq article gnus-newsgroup-scored))
4267                             (memq article gnus-newsgroup-processable))
4268                            (point)))))
4269         (when (cdr datal)
4270           (gnus-data-update-list
4271            (cdr datal)
4272            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4273
4274 (defun gnus-summary-update-article (article &optional iheader)
4275   "Update ARTICLE in the summary buffer."
4276   (set-buffer gnus-summary-buffer)
4277   (let* ((header (gnus-summary-article-header article))
4278          (id (mail-header-id header))
4279          (data (gnus-data-find article))
4280          (thread (gnus-id-to-thread id))
4281          (references (mail-header-references header))
4282          (parent
4283           (gnus-id-to-thread
4284            (or (gnus-parent-id
4285                 (when (and references
4286                            (not (equal "" references)))
4287                   references))
4288                "none")))
4289          (buffer-read-only nil)
4290          (old (car thread)))
4291     (when thread
4292       (unless iheader
4293         (setcar thread nil)
4294         (when parent
4295           (delq thread parent)))
4296       (if (gnus-summary-insert-subject id header)
4297           ;; Set the (possibly) new article number in the data structure.
4298           (gnus-data-set-number data (gnus-id-to-article id))
4299         (setcar thread old)
4300         nil))))
4301
4302 (defun gnus-rebuild-thread (id &optional line)
4303   "Rebuild the thread containing ID.
4304 If LINE, insert the rebuilt thread starting on line LINE."
4305   (let ((buffer-read-only nil)
4306         old-pos current thread data)
4307     (if (not gnus-show-threads)
4308         (setq thread (list (car (gnus-id-to-thread id))))
4309       ;; Get the thread this article is part of.
4310       (setq thread (gnus-remove-thread id)))
4311     (setq old-pos (point-at-bol))
4312     (setq current (save-excursion
4313                     (and (re-search-backward "[\r\n]" nil t)
4314                          (gnus-summary-article-number))))
4315     ;; If this is a gathered thread, we have to go some re-gathering.
4316     (when (stringp (car thread))
4317       (let ((subject (car thread))
4318             roots thr)
4319         (setq thread (cdr thread))
4320         (while thread
4321           (unless (memq (setq thr (gnus-id-to-thread
4322                                    (gnus-root-id
4323                                     (mail-header-id (caar thread)))))
4324                         roots)
4325             (push thr roots))
4326           (setq thread (cdr thread)))
4327         ;; We now have all (unique) roots.
4328         (if (= (length roots) 1)
4329             ;; All the loose roots are now one solid root.
4330             (setq thread (car roots))
4331           (setq thread (cons subject (gnus-sort-threads roots))))))
4332     (let (threads)
4333       ;; We then insert this thread into the summary buffer.
4334       (when line
4335         (goto-char (point-min))
4336         (forward-line (1- line)))
4337       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4338         (if gnus-show-threads
4339             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4340           (gnus-summary-prepare-unthreaded thread))
4341         (setq data (nreverse gnus-newsgroup-data))
4342         (setq threads gnus-newsgroup-threads))
4343       ;; We splice the new data into the data structure.
4344       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4345       ;;!!! then we want to insert at the beginning of the buffer.
4346       ;;!!! That happens to be true with Gnus now, but that may
4347       ;;!!! change in the future.  Perhaps.
4348       (gnus-data-enter-list
4349        (if line nil current) data (- (point) old-pos))
4350       (setq gnus-newsgroup-threads
4351             (nconc threads gnus-newsgroup-threads))
4352       (gnus-data-compute-positions))))
4353
4354 (defun gnus-number-to-header (number)
4355   "Return the header for article NUMBER."
4356   (let ((headers gnus-newsgroup-headers))
4357     (while (and headers
4358                 (not (= number (mail-header-number (car headers)))))
4359       (pop headers))
4360     (when headers
4361       (car headers))))
4362
4363 (defun gnus-parent-headers (in-headers &optional generation)
4364   "Return the headers of the GENERATIONeth parent of HEADERS."
4365   (unless generation
4366     (setq generation 1))
4367   (let ((parent t)
4368         (headers in-headers)
4369         references)
4370     (while (and parent
4371                 (not (zerop generation))
4372                 (setq references (mail-header-references headers)))
4373       (setq headers (if (and references
4374                              (setq parent (gnus-parent-id references)))
4375                         (car (gnus-id-to-thread parent))
4376                       nil))
4377       (decf generation))
4378     (and (not (eq headers in-headers))
4379          headers)))
4380
4381 (defun gnus-id-to-thread (id)
4382   "Return the (sub-)thread where ID appears."
4383   (gnus-gethash id gnus-newsgroup-dependencies))
4384
4385 (defun gnus-id-to-article (id)
4386   "Return the article number of ID."
4387   (let ((thread (gnus-id-to-thread id)))
4388     (when (and thread
4389                (car thread))
4390       (mail-header-number (car thread)))))
4391
4392 (defun gnus-id-to-header (id)
4393   "Return the article headers of ID."
4394   (car (gnus-id-to-thread id)))
4395
4396 (defun gnus-article-displayed-root-p (article)
4397   "Say whether ARTICLE is a root(ish) article."
4398   (let ((level (gnus-summary-thread-level article))
4399         (refs (mail-header-references  (gnus-summary-article-header article)))
4400         particle)
4401     (cond
4402      ((null level) nil)
4403      ((zerop level) t)
4404      ((null refs) t)
4405      ((null (gnus-parent-id refs)) t)
4406      ((and (= 1 level)
4407            (null (setq particle (gnus-id-to-article
4408                                  (gnus-parent-id refs))))
4409            (null (gnus-summary-thread-level particle)))))))
4410
4411 (defun gnus-root-id (id)
4412   "Return the id of the root of the thread where ID appears."
4413   (let (last-id prev)
4414     (while (and id (setq prev (car (gnus-id-to-thread id))))
4415       (setq last-id id
4416             id (gnus-parent-id (mail-header-references prev))))
4417     last-id))
4418
4419 (defun gnus-articles-in-thread (thread)
4420   "Return the list of articles in THREAD."
4421   (cons (mail-header-number (car thread))
4422         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4423
4424 (defun gnus-remove-thread (id &optional dont-remove)
4425   "Remove the thread that has ID in it."
4426   (let (headers thread last-id)
4427     ;; First go up in this thread until we find the root.
4428     (setq last-id (gnus-root-id id)
4429           headers (message-flatten-list (gnus-id-to-thread last-id)))
4430     ;; We have now found the real root of this thread.  It might have
4431     ;; been gathered into some loose thread, so we have to search
4432     ;; through the threads to find the thread we wanted.
4433     (let ((threads gnus-newsgroup-threads)
4434           sub)
4435       (while threads
4436         (setq sub (car threads))
4437         (if (stringp (car sub))
4438             ;; This is a gathered thread, so we look at the roots
4439             ;; below it to find whether this article is in this
4440             ;; gathered root.
4441             (progn
4442               (setq sub (cdr sub))
4443               (while sub
4444                 (when (member (caar sub) headers)
4445                   (setq thread (car threads)
4446                         threads nil
4447                         sub nil))
4448                 (setq sub (cdr sub))))
4449           ;; It's an ordinary thread, so we check it.
4450           (when (eq (car sub) (car headers))
4451             (setq thread sub
4452                   threads nil)))
4453         (setq threads (cdr threads)))
4454       ;; If this article is in no thread, then it's a root.
4455       (if thread
4456           (unless dont-remove
4457             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4458         (setq thread (gnus-id-to-thread last-id)))
4459       (when thread
4460         (prog1
4461             thread                      ; We return this thread.
4462           (unless dont-remove
4463             (if (stringp (car thread))
4464                 (progn
4465                   ;; If we use dummy roots, then we have to remove the
4466                   ;; dummy root as well.
4467                   (when (eq gnus-summary-make-false-root 'dummy)
4468                     ;; We go to the dummy root by going to
4469                     ;; the first sub-"thread", and then one line up.
4470                     (gnus-summary-goto-article
4471                      (mail-header-number (caadr thread)))
4472                     (forward-line -1)
4473                     (gnus-delete-line)
4474                     (gnus-data-compute-positions))
4475                   (setq thread (cdr thread))
4476                   (while thread
4477                     (gnus-remove-thread-1 (car thread))
4478                     (setq thread (cdr thread))))
4479               (gnus-remove-thread-1 thread))))))))
4480
4481 (defun gnus-remove-thread-1 (thread)
4482   "Remove the thread THREAD recursively."
4483   (let ((number (mail-header-number (pop thread)))
4484         d)
4485     (setq thread (reverse thread))
4486     (while thread
4487       (gnus-remove-thread-1 (pop thread)))
4488     (when (setq d (gnus-data-find number))
4489       (goto-char (gnus-data-pos d))
4490       (gnus-summary-show-thread)
4491       (gnus-data-remove
4492        number
4493        (- (point-at-bol)
4494           (prog1
4495               (1+ (point-at-eol))
4496             (gnus-delete-line)))))))
4497
4498 (defun gnus-sort-threads-1 (threads func)
4499   (sort (mapcar (lambda (thread)
4500                   (cons (car thread)
4501                         (and (cdr thread)
4502                              (gnus-sort-threads-1 (cdr thread) func))))
4503                 threads) func))
4504
4505 (defun gnus-sort-threads (threads)
4506   "Sort THREADS."
4507   (if (not gnus-thread-sort-functions)
4508       threads
4509     (gnus-message 8 "Sorting threads...")
4510     (let ((max-lisp-eval-depth 5000))
4511       (prog1 (gnus-sort-threads-1
4512          threads
4513          (gnus-make-sort-function gnus-thread-sort-functions))
4514         (gnus-message 8 "Sorting threads...done")))))
4515
4516 (defun gnus-sort-articles (articles)
4517   "Sort ARTICLES."
4518   (when gnus-article-sort-functions
4519     (gnus-message 7 "Sorting articles...")
4520     (prog1
4521         (setq gnus-newsgroup-headers
4522               (sort articles (gnus-make-sort-function
4523                               gnus-article-sort-functions)))
4524       (gnus-message 7 "Sorting articles...done"))))
4525
4526 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4527 (defmacro gnus-thread-header (thread)
4528   "Return header of first article in THREAD.
4529 Note that THREAD must never, ever be anything else than a variable -
4530 using some other form will lead to serious barfage."
4531   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4532   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4533   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4534         (vector thread) 2))
4535
4536 (defsubst gnus-article-sort-by-number (h1 h2)
4537   "Sort articles by article number."
4538   (< (mail-header-number h1)
4539      (mail-header-number h2)))
4540
4541 (defun gnus-thread-sort-by-number (h1 h2)
4542   "Sort threads by root article number."
4543   (gnus-article-sort-by-number
4544    (gnus-thread-header h1) (gnus-thread-header h2)))
4545
4546 (defsubst gnus-article-sort-by-random (h1 h2)
4547   "Sort articles by article number."
4548   (zerop (random 2)))
4549
4550 (defun gnus-thread-sort-by-random (h1 h2)
4551   "Sort threads by root article number."
4552   (gnus-article-sort-by-random
4553    (gnus-thread-header h1) (gnus-thread-header h2)))
4554
4555 (defsubst gnus-article-sort-by-lines (h1 h2)
4556   "Sort articles by article Lines header."
4557   (< (mail-header-lines h1)
4558      (mail-header-lines h2)))
4559
4560 (defun gnus-thread-sort-by-lines (h1 h2)
4561   "Sort threads by root article Lines header."
4562   (gnus-article-sort-by-lines
4563    (gnus-thread-header h1) (gnus-thread-header h2)))
4564
4565 (defsubst gnus-article-sort-by-chars (h1 h2)
4566   "Sort articles by octet length."
4567   (< (mail-header-chars h1)
4568      (mail-header-chars h2)))
4569
4570 (defun gnus-thread-sort-by-chars (h1 h2)
4571   "Sort threads by root article octet length."
4572   (gnus-article-sort-by-chars
4573    (gnus-thread-header h1) (gnus-thread-header h2)))
4574
4575 (defsubst gnus-article-sort-by-author (h1 h2)
4576   "Sort articles by root author."
4577   (string-lessp
4578    (let ((addr (car (mime-entity-read-field h1 'From))))
4579      (or (std11-full-name-string addr)
4580          (std11-address-string addr)
4581          ""))
4582    (let ((addr (car (mime-entity-read-field h2 'From))))
4583      (or (std11-full-name-string addr)
4584          (std11-address-string addr)
4585          ""))
4586    ))
4587
4588 (defun gnus-thread-sort-by-author (h1 h2)
4589   "Sort threads by root author."
4590   (gnus-article-sort-by-author
4591    (gnus-thread-header h1)  (gnus-thread-header h2)))
4592
4593 (defsubst gnus-article-sort-by-recipient (h1 h2)
4594   "Sort articles by recipient."
4595   (string-lessp
4596    (let ((extract (funcall
4597                    gnus-extract-address-components
4598                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4599      (or (car extract) (cadr extract)))
4600    (let ((extract (funcall
4601                    gnus-extract-address-components
4602                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4603      (or (car extract) (cadr extract)))))
4604
4605 (defun gnus-thread-sort-by-recipient (h1 h2)
4606   "Sort threads by root recipient."
4607   (gnus-article-sort-by-recipient
4608    (gnus-thread-header h1) (gnus-thread-header h2)))
4609
4610 (defsubst gnus-article-sort-by-subject (h1 h2)
4611   "Sort articles by root subject."
4612   (string-lessp
4613    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4614    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4615
4616 (defun gnus-thread-sort-by-subject (h1 h2)
4617   "Sort threads by root subject."
4618   (gnus-article-sort-by-subject
4619    (gnus-thread-header h1) (gnus-thread-header h2)))
4620
4621 (defsubst gnus-article-sort-by-date (h1 h2)
4622   "Sort articles by root article date."
4623   (time-less-p
4624    (gnus-date-get-time (mail-header-date h1))
4625    (gnus-date-get-time (mail-header-date h2))))
4626
4627 (defun gnus-thread-sort-by-date (h1 h2)
4628   "Sort threads by root article date."
4629   (gnus-article-sort-by-date
4630    (gnus-thread-header h1) (gnus-thread-header h2)))
4631
4632 (defsubst gnus-article-sort-by-score (h1 h2)
4633   "Sort articles by root article score.
4634 Unscored articles will be counted as having a score of zero."
4635   (> (or (cdr (assq (mail-header-number h1)
4636                     gnus-newsgroup-scored))
4637          gnus-summary-default-score 0)
4638      (or (cdr (assq (mail-header-number h2)
4639                     gnus-newsgroup-scored))
4640          gnus-summary-default-score 0)))
4641
4642 (defun gnus-thread-sort-by-score (h1 h2)
4643   "Sort threads by root article score."
4644   (gnus-article-sort-by-score
4645    (gnus-thread-header h1) (gnus-thread-header h2)))
4646
4647 (defun gnus-thread-sort-by-total-score (h1 h2)
4648   "Sort threads by the sum of all scores in the thread.
4649 Unscored articles will be counted as having a score of zero."
4650   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4651
4652 (defun gnus-thread-total-score (thread)
4653   ;; This function find the total score of THREAD.
4654   (cond
4655    ((null thread)
4656     0)
4657    ((consp thread)
4658     (if (stringp (car thread))
4659         (apply gnus-thread-score-function 0
4660                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4661       (gnus-thread-total-score-1 thread)))
4662    (t
4663     (gnus-thread-total-score-1 (list thread)))))
4664
4665 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4666   "Sort threads such that the thread with the most recently arrived article comes first."
4667   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4668
4669 (defun gnus-thread-highest-number (thread)
4670   "Return the highest article number in THREAD."
4671   (apply 'max (mapcar (lambda (header)
4672                         (mail-header-number header))
4673                       (message-flatten-list thread))))
4674
4675 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4676   "Sort threads such that the thread with the most recently dated article comes first."
4677   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4678
4679 (defun gnus-thread-latest-date (thread)
4680   "Return the highest article date in THREAD."
4681   (let ((previous-time 0))
4682     (apply 'max
4683            (mapcar
4684             (lambda (header)
4685               (setq previous-time
4686                     (condition-case ()
4687                         (time-to-seconds (mail-header-parse-date
4688                                           (mail-header-date header)))
4689                       (error previous-time))))
4690             (sort
4691              (message-flatten-list thread)
4692              (lambda (h1 h2)
4693                (< (mail-header-number h1)
4694                   (mail-header-number h2))))))))
4695
4696 (defun gnus-thread-total-score-1 (root)
4697   ;; This function find the total score of the thread below ROOT.
4698   (setq root (car root))
4699   (apply gnus-thread-score-function
4700          (or (append
4701               (mapcar 'gnus-thread-total-score
4702                       (cdr (gnus-id-to-thread (mail-header-id root))))
4703               (when (> (mail-header-number root) 0)
4704                 (list (or (cdr (assq (mail-header-number root)
4705                                      gnus-newsgroup-scored))
4706                           gnus-summary-default-score 0))))
4707              (list gnus-summary-default-score)
4708              '(0))))
4709
4710 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4711 (defvar gnus-tmp-prev-subject nil)
4712 (defvar gnus-tmp-false-parent nil)
4713 (defvar gnus-tmp-root-expunged nil)
4714 (defvar gnus-tmp-dummy-line nil)
4715
4716 (eval-when-compile (defvar gnus-tmp-header))
4717 (defun gnus-extra-header (type &optional header)
4718   "Return the extra header of TYPE."
4719   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4720       ""))
4721
4722 (defvar gnus-tmp-thread-tree-header-string "")
4723
4724 (defcustom gnus-sum-thread-tree-root "> "
4725   "With %B spec, used for the root of a thread.
4726 If nil, use subject instead."
4727   :version "22.1"
4728   :type '(radio (const :format "%v  " nil) string)
4729   :group 'gnus-thread)
4730 (defcustom gnus-sum-thread-tree-false-root "> "
4731   "With %B spec, used for a false root of a thread.
4732 If nil, use subject instead."
4733   :version "22.1"
4734   :type '(radio (const :format "%v  " nil) string)
4735   :group 'gnus-thread)
4736 (defcustom gnus-sum-thread-tree-single-indent ""
4737   "With %B spec, used for a thread with just one message.
4738 If nil, use subject instead."
4739   :version "22.1"
4740   :type '(radio (const :format "%v  " nil) string)
4741   :group 'gnus-thread)
4742 (defcustom gnus-sum-thread-tree-vertical "| "
4743   "With %B spec, used for drawing a vertical line."
4744   :version "22.1"
4745   :type 'string
4746   :group 'gnus-thread)
4747 (defcustom gnus-sum-thread-tree-indent "  "
4748   "With %B spec, used for indenting."
4749   :version "22.1"
4750   :type 'string
4751   :group 'gnus-thread)
4752 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4753   "With %B spec, used for a leaf with brothers."
4754   :version "22.1"
4755   :type 'string
4756   :group 'gnus-thread)
4757 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4758   "With %B spec, used for a leaf without brothers."
4759   :version "22.1"
4760   :type 'string
4761   :group 'gnus-thread)
4762
4763 (defun gnus-summary-prepare-threads (threads)
4764   "Prepare summary buffer from THREADS and indentation LEVEL.
4765 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4766 or a straight list of headers."
4767   (gnus-message 7 "Generating summary...")
4768
4769   (setq gnus-newsgroup-threads threads)
4770   (beginning-of-line)
4771
4772   (let ((gnus-tmp-level 0)
4773         (default-score (or gnus-summary-default-score 0))
4774         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4775         (building-line-count gnus-summary-display-while-building)
4776         (building-count (integerp gnus-summary-display-while-building))
4777         thread number subject stack state gnus-tmp-gathered beg-match
4778         new-roots gnus-tmp-new-adopts thread-end simp-subject
4779         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4780         gnus-tmp-replied gnus-tmp-subject-or-nil
4781         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4782         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4783         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4784         tree-stack)
4785
4786     (setq gnus-tmp-prev-subject nil
4787           gnus-tmp-thread-tree-header-string "")
4788
4789     (if (vectorp (car threads))
4790         ;; If this is a straight (sic) list of headers, then a
4791         ;; threaded summary display isn't required, so we just create
4792         ;; an unthreaded one.
4793         (gnus-summary-prepare-unthreaded threads)
4794
4795       ;; Do the threaded display.
4796
4797       (if gnus-summary-display-while-building
4798           (switch-to-buffer (buffer-name)))
4799       (while (or threads stack gnus-tmp-new-adopts new-roots)
4800
4801         (if (and (= gnus-tmp-level 0)
4802                  (or (not stack)
4803                      (= (caar stack) 0))
4804                  (not gnus-tmp-false-parent)
4805                  (or gnus-tmp-new-adopts new-roots))
4806             (if gnus-tmp-new-adopts
4807                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4808                       thread (list (car gnus-tmp-new-adopts))
4809                       gnus-tmp-header (caar thread)
4810                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4811               (when new-roots
4812                 (setq thread (list (car new-roots))
4813                       gnus-tmp-header (caar thread)
4814                       new-roots (cdr new-roots))))
4815
4816           (if threads
4817               ;; If there are some threads, we do them before the
4818               ;; threads on the stack.
4819               (setq thread threads
4820                     gnus-tmp-header (caar thread))
4821             ;; There were no current threads, so we pop something off
4822             ;; the stack.
4823             (setq state (car stack)
4824                   gnus-tmp-level (car state)
4825                   tree-stack (cadr state)
4826                   thread (caddr state)
4827                   stack (cdr stack)
4828                   gnus-tmp-header (caar thread))))
4829
4830         (setq gnus-tmp-false-parent nil)
4831         (setq gnus-tmp-root-expunged nil)
4832         (setq thread-end nil)
4833
4834         (if (stringp gnus-tmp-header)
4835             ;; The header is a dummy root.
4836             (cond
4837              ((eq gnus-summary-make-false-root 'adopt)
4838               ;; We let the first article adopt the rest.
4839               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4840                                                (cddar thread)))
4841               (setq gnus-tmp-gathered
4842                     (nconc (mapcar
4843                             (lambda (h) (mail-header-number (car h)))
4844                             (cddar thread))
4845                            gnus-tmp-gathered))
4846               (setq thread (cons (list (caar thread)
4847                                        (cadar thread))
4848                                  (cdr thread)))
4849               (setq gnus-tmp-level -1
4850                     gnus-tmp-false-parent t))
4851              ((eq gnus-summary-make-false-root 'empty)
4852               ;; We print adopted articles with empty subject fields.
4853               (setq gnus-tmp-gathered
4854                     (nconc (mapcar
4855                             (lambda (h) (mail-header-number (car h)))
4856                             (cddar thread))
4857                            gnus-tmp-gathered))
4858               (setq gnus-tmp-level -1))
4859              ((eq gnus-summary-make-false-root 'dummy)
4860               ;; We remember that we probably want to output a dummy
4861               ;; root.
4862               (setq gnus-tmp-dummy-line gnus-tmp-header)
4863               (setq gnus-tmp-prev-subject gnus-tmp-header))
4864              (t
4865               ;; We do not make a root for the gathered
4866               ;; sub-threads at all.
4867               (setq gnus-tmp-level -1)))
4868
4869           (setq number (mail-header-number gnus-tmp-header)
4870                 subject (mail-header-subject gnus-tmp-header)
4871                 simp-subject (gnus-simplify-subject-fully subject))
4872
4873           (cond
4874            ;; If the thread has changed subject, we might want to make
4875            ;; this subthread into a root.
4876            ((and (null gnus-thread-ignore-subject)
4877                  (not (zerop gnus-tmp-level))
4878                  gnus-tmp-prev-subject
4879                  (not (string= gnus-tmp-prev-subject simp-subject)))
4880             (setq new-roots (nconc new-roots (list (car thread)))
4881                   thread-end t
4882                   gnus-tmp-header nil))
4883            ;; If the article lies outside the current limit,
4884            ;; then we do not display it.
4885            ((not (memq number gnus-newsgroup-limit))
4886             (setq gnus-tmp-gathered
4887                   (nconc (mapcar
4888                           (lambda (h) (mail-header-number (car h)))
4889                           (cdar thread))
4890                          gnus-tmp-gathered))
4891             (setq gnus-tmp-new-adopts (if (cdar thread)
4892                                           (append gnus-tmp-new-adopts
4893                                                   (cdar thread))
4894                                         gnus-tmp-new-adopts)
4895                   thread-end t
4896                   gnus-tmp-header nil)
4897             (when (zerop gnus-tmp-level)
4898               (setq gnus-tmp-root-expunged t)))
4899            ;; Perhaps this article is to be marked as read?
4900            ((and gnus-summary-mark-below
4901                  (< (or (cdr (assq number gnus-newsgroup-scored))
4902                         default-score)
4903                     gnus-summary-mark-below)
4904                  ;; Don't touch sparse articles.
4905                  (not (gnus-summary-article-sparse-p number))
4906                  (not (gnus-summary-article-ancient-p number)))
4907             (setq gnus-newsgroup-unreads
4908                   (delq number gnus-newsgroup-unreads))
4909             (if gnus-newsgroup-auto-expire
4910                 (setq gnus-newsgroup-expirable
4911                       (gnus-add-to-sorted-list
4912                        gnus-newsgroup-expirable number))
4913               (push (cons number gnus-low-score-mark)
4914                     gnus-newsgroup-reads))))
4915
4916           (when gnus-tmp-header
4917             ;; We may have an old dummy line to output before this
4918             ;; article.
4919             (when (and gnus-tmp-dummy-line
4920                        (gnus-subject-equal
4921                         gnus-tmp-dummy-line
4922                         (mail-header-subject gnus-tmp-header)))
4923               (gnus-summary-insert-dummy-line
4924                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4925               (setq gnus-tmp-dummy-line nil))
4926
4927             ;; Compute the mark.
4928             (setq gnus-tmp-unread (gnus-article-mark number))
4929
4930             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4931                                   gnus-tmp-header gnus-tmp-level)
4932                   gnus-newsgroup-data)
4933
4934             ;; Actually insert the line.
4935             (setq
4936              gnus-tmp-subject-or-nil
4937              (cond
4938               ((and gnus-thread-ignore-subject
4939                     gnus-tmp-prev-subject
4940                     (not (string= gnus-tmp-prev-subject simp-subject)))
4941                subject)
4942               ((zerop gnus-tmp-level)
4943                (if (and (eq gnus-summary-make-false-root 'empty)
4944                         (memq number gnus-tmp-gathered)
4945                         gnus-tmp-prev-subject
4946                         (string= gnus-tmp-prev-subject simp-subject))
4947                    gnus-summary-same-subject
4948                  subject))
4949               (t gnus-summary-same-subject)))
4950             (if (and (eq gnus-summary-make-false-root 'adopt)
4951                      (= gnus-tmp-level 1)
4952                      (memq number gnus-tmp-gathered))
4953                 (setq gnus-tmp-opening-bracket ?\<
4954                       gnus-tmp-closing-bracket ?\>)
4955               (setq gnus-tmp-opening-bracket ?\[
4956                     gnus-tmp-closing-bracket ?\]))
4957             (setq
4958              gnus-tmp-indentation
4959              (aref gnus-thread-indent-array gnus-tmp-level)
4960              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4961              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4962                                 gnus-summary-default-score 0)
4963              gnus-tmp-score-char
4964              (if (or (null gnus-summary-default-score)
4965                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4966                          gnus-summary-zcore-fuzz))
4967                  ?\ ;;;Whitespace
4968                (if (< gnus-tmp-score gnus-summary-default-score)
4969                    gnus-score-below-mark gnus-score-over-mark))
4970              gnus-tmp-replied
4971              (cond ((memq number gnus-newsgroup-processable)
4972                     gnus-process-mark)
4973                    ((memq number gnus-newsgroup-cached)
4974                     gnus-cached-mark)
4975                    ((memq number gnus-newsgroup-replied)
4976                     gnus-replied-mark)
4977                    ((memq number gnus-newsgroup-forwarded)
4978                     gnus-forwarded-mark)
4979                    ((memq number gnus-newsgroup-saved)
4980                     gnus-saved-mark)
4981                    ((memq number gnus-newsgroup-recent)
4982                     gnus-recent-mark)
4983                    ((memq number gnus-newsgroup-unseen)
4984                     gnus-unseen-mark)
4985                    (t gnus-no-mark))
4986              gnus-tmp-downloaded
4987              (cond ((memq number gnus-newsgroup-undownloaded)
4988                     gnus-undownloaded-mark)
4989                    (gnus-newsgroup-agentized
4990                     gnus-downloaded-mark)
4991                    (t
4992                     gnus-no-mark))
4993              gnus-tmp-from (mail-header-from gnus-tmp-header)
4994              gnus-tmp-name
4995              (cond
4996               ((string-match "<[^>]+> *$" gnus-tmp-from)
4997                (setq beg-match (match-beginning 0))
4998                (or (and (string-match "^\".+\"" gnus-tmp-from)
4999                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5000                    (substring gnus-tmp-from 0 beg-match)))
5001               ((string-match "(.+)" gnus-tmp-from)
5002                (substring gnus-tmp-from
5003                           (1+ (match-beginning 0)) (1- (match-end 0))))
5004               (t gnus-tmp-from))
5005
5006              ;; Do the %B string
5007              gnus-tmp-thread-tree-header-string
5008              (cond
5009               ((not gnus-show-threads) "")
5010               ((zerop gnus-tmp-level)
5011                (cond ((cdar thread)
5012                       (or gnus-sum-thread-tree-root subject))
5013                      (gnus-tmp-new-adopts
5014                       (or gnus-sum-thread-tree-false-root subject))
5015                      (t
5016                       (or gnus-sum-thread-tree-single-indent subject))))
5017               (t
5018                (concat (apply 'concat
5019                               (mapcar (lambda (item)
5020                                         (if (= item 1)
5021                                             gnus-sum-thread-tree-vertical
5022                                           gnus-sum-thread-tree-indent))
5023                                       (cdr (reverse tree-stack))))
5024                        (if (nth 1 thread)
5025                            gnus-sum-thread-tree-leaf-with-other
5026                          gnus-sum-thread-tree-single-leaf)))))
5027             (when (string= gnus-tmp-name "")
5028               (setq gnus-tmp-name gnus-tmp-from))
5029             (unless (numberp gnus-tmp-lines)
5030               (setq gnus-tmp-lines -1))
5031             (if (= gnus-tmp-lines -1)
5032                 (setq gnus-tmp-lines "?")
5033               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5034               (gnus-put-text-property
5035              (point)
5036              (progn (eval gnus-summary-line-format-spec) (point))
5037                'gnus-number number)
5038             (when gnus-visual-p
5039               (forward-line -1)
5040               (gnus-run-hooks 'gnus-summary-update-hook)
5041               (forward-line 1))
5042
5043             (setq gnus-tmp-prev-subject simp-subject)))
5044
5045         (when (nth 1 thread)
5046           (push (list (max 0 gnus-tmp-level)
5047                       (copy-sequence tree-stack)
5048                       (nthcdr 1 thread))
5049                 stack))
5050         (push (if (nth 1 thread) 1 0) tree-stack)
5051         (incf gnus-tmp-level)
5052         (setq threads (if thread-end nil (cdar thread)))
5053         (if gnus-summary-display-while-building
5054             (if building-count
5055                 (progn
5056                   ;; use a set frequency
5057                   (setq building-line-count (1- building-line-count))
5058                   (when (= building-line-count 0)
5059                     (sit-for 0)
5060                     (setq building-line-count
5061                           gnus-summary-display-while-building)))
5062               ;; always
5063               (sit-for 0)))
5064         (unless threads
5065           (setq gnus-tmp-level 0)))))
5066   (gnus-message 7 "Generating summary...done"))
5067
5068 (defun gnus-summary-prepare-unthreaded (headers)
5069   "Generate an unthreaded summary buffer based on HEADERS."
5070   (let (header number mark)
5071
5072     (beginning-of-line)
5073
5074     (while headers
5075       ;; We may have to root out some bad articles...
5076       (when (memq (setq number (mail-header-number
5077                                 (setq header (pop headers))))
5078                   gnus-newsgroup-limit)
5079         ;; Mark article as read when it has a low score.
5080         (when (and gnus-summary-mark-below
5081                    (< (or (cdr (assq number gnus-newsgroup-scored))
5082                           gnus-summary-default-score 0)
5083                       gnus-summary-mark-below)
5084                    (not (gnus-summary-article-ancient-p number)))
5085           (setq gnus-newsgroup-unreads
5086                 (delq number gnus-newsgroup-unreads))
5087           (if gnus-newsgroup-auto-expire
5088               (push number gnus-newsgroup-expirable)
5089             (push (cons number gnus-low-score-mark)
5090                   gnus-newsgroup-reads)))
5091
5092         (setq mark (gnus-article-mark number))
5093         (push (gnus-data-make number mark (1+ (point)) header 0)
5094               gnus-newsgroup-data)
5095         (gnus-summary-insert-line
5096          header 0 number
5097          (memq number gnus-newsgroup-undownloaded)
5098          mark (memq number gnus-newsgroup-replied)
5099          (memq number gnus-newsgroup-expirable)
5100          (mail-header-subject header) nil
5101          (cdr (assq number gnus-newsgroup-scored))
5102          (memq number gnus-newsgroup-processable))))))
5103
5104 (defun gnus-summary-remove-list-identifiers ()
5105   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5106   (let ((regexp (if (consp gnus-list-identifiers)
5107                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5108                   gnus-list-identifiers))
5109         changed subject)
5110     (when regexp
5111       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5112       (dolist (header gnus-newsgroup-headers)
5113         (setq subject (mail-header-subject header)
5114               changed nil)
5115         (while (string-match regexp subject)
5116           (setq subject
5117                 (concat (substring subject 0 (match-beginning 1))
5118                         (substring subject (match-end 0)))
5119                 changed t))
5120         (when changed
5121           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5122             (setq subject
5123                   (concat (substring subject 0 (match-beginning 1))
5124                           (substring subject (match-end 1)))))
5125           (mail-header-set-subject header subject))))))
5126
5127 (defun gnus-fetch-headers (articles)
5128   "Fetch headers of ARTICLES."
5129   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5130     (gnus-message 5 "Fetching headers for %s..." name)
5131     (prog1
5132         (if (eq 'nov
5133                 (setq gnus-headers-retrieved-by
5134                       (gnus-retrieve-headers
5135                        articles gnus-newsgroup-name
5136                        ;; We might want to fetch old headers, but
5137                        ;; not if there is only 1 article.
5138                        (and (or (and
5139                                  (not (eq gnus-fetch-old-headers 'some))
5140                                  (not (numberp gnus-fetch-old-headers)))
5141                                 (> (length articles) 1))
5142                             gnus-fetch-old-headers))))
5143             (gnus-get-newsgroup-headers-xover
5144              articles nil nil gnus-newsgroup-name t)
5145           (gnus-get-newsgroup-headers))
5146       (gnus-message 5 "Fetching headers for %s...done" name))))
5147
5148 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5149   "Select newsgroup GROUP.
5150 If READ-ALL is non-nil, all articles in the group are selected.
5151 If SELECT-ARTICLES, only select those articles from GROUP."
5152   (let* ((entry (gnus-group-entry group))
5153          ;;!!! Dirty hack; should be removed.
5154          (gnus-summary-ignore-duplicates
5155           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5156               t
5157             gnus-summary-ignore-duplicates))
5158          (info (nth 2 entry))
5159          articles fetched-articles cached)
5160
5161     (unless (gnus-check-server
5162              (set (make-local-variable 'gnus-current-select-method)
5163                   (gnus-find-method-for-group group)))
5164       (error "Couldn't open server"))
5165
5166     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5167         (gnus-activate-group group)     ; Or we can activate it...
5168         (progn                          ; Or we bug out.
5169           (when (equal major-mode 'gnus-summary-mode)
5170             (gnus-kill-buffer (current-buffer)))
5171           (error "Couldn't activate group %s: %s"
5172                  group (gnus-status-message group))))
5173
5174     (unless (gnus-request-group group t)
5175       (when (equal major-mode 'gnus-summary-mode)
5176         (gnus-kill-buffer (current-buffer)))
5177       (error "Couldn't request group %s: %s"
5178              group (gnus-status-message group)))
5179
5180     (when gnus-agent
5181       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5182
5183       (setq gnus-summary-use-undownloaded-faces
5184             (gnus-agent-find-parameter
5185              group
5186              'agent-enable-undownloaded-faces)))
5187
5188     (setq gnus-newsgroup-name group
5189           gnus-newsgroup-unselected nil
5190           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5191
5192     (let ((display (gnus-group-find-parameter group 'display)))
5193       (setq gnus-newsgroup-display
5194             (cond
5195              ((not (zerop (or (car-safe read-all) 0)))
5196               ;; The user entered the group with C-u SPC/RET, let's show
5197               ;; all articles.
5198               'gnus-not-ignore)
5199              ((eq display 'all)
5200               'gnus-not-ignore)
5201              ((arrayp display)
5202               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5203              ((numberp display)
5204               ;; The following is probably the "correct" solution, but
5205               ;; it makes Gnus fetch all headers and then limit the
5206               ;; articles (which is slow), so instead we hack the
5207               ;; select-articles parameter instead. -- Simon Josefsson
5208               ;; <jas@kth.se>
5209               ;;
5210               ;; (gnus-byte-compile
5211               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5212               ;;                         display)))))
5213               (setq select-articles
5214                     (gnus-uncompress-range
5215                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5216                              (if (> tmp 0)
5217                                  tmp
5218                                1))
5219                            (cdr (gnus-active group)))))
5220               nil)
5221              (t
5222               nil))))
5223
5224     (gnus-summary-setup-default-charset)
5225
5226     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5227     (when (gnus-virtual-group-p group)
5228       (setq cached gnus-newsgroup-cached))
5229
5230     (setq gnus-newsgroup-unreads
5231           (gnus-sorted-ndifference
5232            (gnus-sorted-ndifference gnus-newsgroup-unreads
5233                                     gnus-newsgroup-marked)
5234            gnus-newsgroup-dormant))
5235
5236     (setq gnus-newsgroup-processable nil)
5237
5238     (gnus-update-read-articles group gnus-newsgroup-unreads)
5239
5240     ;; Adjust and set lists of article marks.
5241     (when info
5242       (gnus-adjust-marked-articles info))
5243     (if (setq articles select-articles)
5244         (setq gnus-newsgroup-unselected
5245               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5246       (setq articles (gnus-articles-to-read group read-all)))
5247
5248     (cond
5249      ((null articles)
5250       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5251       'quit)
5252      ((eq articles 0) nil)
5253      (t
5254       ;; Init the dependencies hash table.
5255       (setq gnus-newsgroup-dependencies
5256             (gnus-make-hashtable (length articles)))
5257       (gnus-set-global-variables)
5258       ;; Retrieve the headers and read them in.
5259
5260       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5261
5262       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5263       (when cached
5264         (setq gnus-newsgroup-cached cached))
5265
5266       ;; Suppress duplicates?
5267       (when gnus-suppress-duplicates
5268         (gnus-dup-suppress-articles))
5269
5270       ;; Set the initial limit.
5271       (setq gnus-newsgroup-limit (copy-sequence articles))
5272       ;; Remove canceled articles from the list of unread articles.
5273       (setq fetched-articles
5274             (mapcar (lambda (headers) (mail-header-number headers))
5275                     gnus-newsgroup-headers))
5276       (setq gnus-newsgroup-articles fetched-articles)
5277       (setq gnus-newsgroup-unreads
5278             (gnus-sorted-nintersection
5279              gnus-newsgroup-unreads fetched-articles))
5280       (gnus-compute-unseen-list)
5281
5282       ;; Removed marked articles that do not exist.
5283       (gnus-update-missing-marks
5284        (gnus-sorted-difference articles fetched-articles))
5285       ;; We might want to build some more threads first.
5286       (when (and gnus-fetch-old-headers
5287                  (eq gnus-headers-retrieved-by 'nov))
5288         (if (eq gnus-fetch-old-headers 'invisible)
5289             (gnus-build-all-threads)
5290           (gnus-build-old-threads)))
5291       ;; Let the Gnus agent mark articles as read.
5292       (when gnus-agent
5293         (gnus-agent-get-undownloaded-list))
5294       ;; Remove list identifiers from subject
5295       (when gnus-list-identifiers
5296         (gnus-summary-remove-list-identifiers))
5297       ;; Check whether auto-expire is to be done in this group.
5298       (setq gnus-newsgroup-auto-expire
5299             (gnus-group-auto-expirable-p group))
5300       ;; Set up the article buffer now, if necessary.
5301       (unless gnus-single-article-buffer
5302         (gnus-article-setup-buffer))
5303       ;; First and last article in this newsgroup.
5304       (when gnus-newsgroup-headers
5305         (setq gnus-newsgroup-begin
5306               (mail-header-number (car gnus-newsgroup-headers))
5307               gnus-newsgroup-end
5308               (mail-header-number
5309                (gnus-last-element gnus-newsgroup-headers))))
5310       ;; GROUP is successfully selected.
5311       (or gnus-newsgroup-headers t)))))
5312
5313 (defun gnus-compute-unseen-list ()
5314   ;; The `seen' marks are treated specially.
5315   (if (not gnus-newsgroup-seen)
5316       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5317     (setq gnus-newsgroup-unseen
5318           (gnus-inverse-list-range-intersection
5319            gnus-newsgroup-articles gnus-newsgroup-seen))))
5320
5321 (defun gnus-summary-display-make-predicate (display)
5322   (require 'gnus-agent)
5323   (when (= (length display) 1)
5324     (setq display (car display)))
5325   (unless gnus-summary-display-cache
5326     (dolist (elem (append '((unread . unread)
5327                             (read . read)
5328                             (unseen . unseen))
5329                           gnus-article-mark-lists))
5330       (push (cons (cdr elem)
5331                   (gnus-byte-compile
5332                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5333             gnus-summary-display-cache)))
5334   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5335         (gnus-category-predicate-cache gnus-summary-display-cache))
5336     (gnus-get-predicate display)))
5337
5338 ;; Uses the dynamically bound `number' variable.
5339 (eval-when-compile
5340   (defvar number))
5341 (defun gnus-article-marked-p (type &optional article)
5342   (let ((article (or article number)))
5343     (cond
5344      ((eq type 'tick)
5345       (memq article gnus-newsgroup-marked))
5346      ((eq type 'spam)
5347       (memq article gnus-newsgroup-spam-marked))
5348      ((eq type 'unsend)
5349       (memq article gnus-newsgroup-unsendable))
5350      ((eq type 'undownload)
5351       (memq article gnus-newsgroup-undownloaded))
5352      ((eq type 'download)
5353       (memq article gnus-newsgroup-downloadable))
5354      ((eq type 'unread)
5355       (memq article gnus-newsgroup-unreads))
5356      ((eq type 'read)
5357       (memq article gnus-newsgroup-reads))
5358      ((eq type 'dormant)
5359       (memq article gnus-newsgroup-dormant) )
5360      ((eq type 'expire)
5361       (memq article gnus-newsgroup-expirable))
5362      ((eq type 'reply)
5363       (memq article gnus-newsgroup-replied))
5364      ((eq type 'killed)
5365       (memq article gnus-newsgroup-killed))
5366      ((eq type 'bookmark)
5367       (assq article gnus-newsgroup-bookmarks))
5368      ((eq type 'score)
5369       (assq article gnus-newsgroup-scored))
5370      ((eq type 'save)
5371       (memq article gnus-newsgroup-saved))
5372      ((eq type 'cache)
5373       (memq article gnus-newsgroup-cached))
5374      ((eq type 'forward)
5375       (memq article gnus-newsgroup-forwarded))
5376      ((eq type 'seen)
5377       (not (memq article gnus-newsgroup-unseen)))
5378      ((eq type 'recent)
5379       (memq article gnus-newsgroup-recent))
5380      (t t))))
5381
5382 (defun gnus-articles-to-read (group &optional read-all)
5383   "Find out what articles the user wants to read."
5384   (let* ((articles
5385           ;; Select all articles if `read-all' is non-nil, or if there
5386           ;; are no unread articles.
5387           (if (or read-all
5388                   (and (zerop (length gnus-newsgroup-marked))
5389                        (zerop (length gnus-newsgroup-unreads)))
5390                   ;; Fetch all if the predicate is non-nil.
5391                   gnus-newsgroup-display)
5392               ;; We want to select the headers for all the articles in
5393               ;; the group, so we select either all the active
5394               ;; articles in the group, or (if that's nil), the
5395               ;; articles in the cache.
5396               (or
5397                (gnus-uncompress-range (gnus-active group))
5398                (gnus-cache-articles-in-group group))
5399             ;; Select only the "normal" subset of articles.
5400             (gnus-sorted-nunion
5401              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5402              gnus-newsgroup-unreads)))
5403          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5404          (scored (length scored-list))
5405          (number (length articles))
5406          (marked (+ (length gnus-newsgroup-marked)
5407                     (length gnus-newsgroup-dormant)))
5408          (select
5409           (cond
5410            ((numberp read-all)
5411             read-all)
5412            ((numberp gnus-newsgroup-display)
5413             gnus-newsgroup-display)
5414            (t
5415             (condition-case ()
5416                 (cond
5417                  ((and (or (<= scored marked) (= scored number))
5418                        (numberp gnus-large-newsgroup)
5419                        (> number gnus-large-newsgroup))
5420                   (let* ((cursor-in-echo-area nil)
5421                          (initial (gnus-parameter-large-newsgroup-initial
5422                                    gnus-newsgroup-name))
5423                          (input
5424                           (read-string
5425                            (format
5426                             "How many articles from %s (%s %d): "
5427                             (gnus-limit-string
5428                              (gnus-group-decoded-name gnus-newsgroup-name)
5429                              35)
5430                             (if initial "max" "default")
5431                             number)
5432                            (if initial
5433                                (cons (number-to-string initial)
5434                                      0)))))
5435                     (if (string-match "^[ \t]*$" input) number input)))
5436                  ((and (> scored marked) (< scored number)
5437                        (> (- scored number) 20))
5438                   (let ((input
5439                          (read-string
5440                           (format "%s %s (%d scored, %d total): "
5441                                   "How many articles from"
5442                                   (gnus-group-decoded-name group)
5443                                   scored number))))
5444                     (if (string-match "^[ \t]*$" input)
5445                         number input)))
5446                  (t number))
5447               (quit
5448                (message "Quit getting the articles to read")
5449                nil))))))
5450     (setq select (if (stringp select) (string-to-number select) select))
5451     (if (or (null select) (zerop select))
5452         select
5453       (if (and (not (zerop scored)) (<= (abs select) scored))
5454           (progn
5455             (setq articles (sort scored-list '<))
5456             (setq number (length articles)))
5457         (setq articles (copy-sequence articles)))
5458
5459       (when (< (abs select) number)
5460         (if (< select 0)
5461             ;; Select the N oldest articles.
5462             (setcdr (nthcdr (1- (abs select)) articles) nil)
5463           ;; Select the N most recent articles.
5464           (setq articles (nthcdr (- number select) articles))))
5465       (setq gnus-newsgroup-unselected
5466             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5467       (when gnus-alter-articles-to-read-function
5468         (setq articles
5469               (sort
5470                (funcall gnus-alter-articles-to-read-function
5471                         gnus-newsgroup-name articles)
5472                '<)))
5473       articles)))
5474
5475 (defun gnus-killed-articles (killed articles)
5476   (let (out)
5477     (while articles
5478       (when (inline (gnus-member-of-range (car articles) killed))
5479         (push (car articles) out))
5480       (setq articles (cdr articles)))
5481     out))
5482
5483 (defun gnus-uncompress-marks (marks)
5484   "Uncompress the mark ranges in MARKS."
5485   (let ((uncompressed '(score bookmark))
5486         out)
5487     (while marks
5488       (if (memq (caar marks) uncompressed)
5489           (push (car marks) out)
5490         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5491       (setq marks (cdr marks)))
5492     out))
5493
5494 (defun gnus-article-mark-to-type (mark)
5495   "Return the type of MARK."
5496   (or (cadr (assq mark gnus-article-special-mark-lists))
5497       'list))
5498
5499 (defun gnus-article-unpropagatable-p (mark)
5500   "Return whether MARK should be propagated to back end."
5501   (memq mark gnus-article-unpropagated-mark-lists))
5502
5503 (defun gnus-adjust-marked-articles (info)
5504   "Set all article lists and remove all marks that are no longer valid."
5505   (let* ((marked-lists (gnus-info-marks info))
5506          (active (gnus-active (gnus-info-group info)))
5507          (min (car active))
5508          (max (cdr active))
5509          (types gnus-article-mark-lists)
5510          marks var articles article mark mark-type
5511          bgn end)
5512
5513     (dolist (marks marked-lists)
5514       (setq mark (car marks)
5515             mark-type (gnus-article-mark-to-type mark)
5516             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5517
5518       ;; We set the variable according to the type of the marks list,
5519       ;; and then adjust the marks to a subset of the active articles.
5520       (cond
5521        ;; Adjust "simple" lists - compressed yet unsorted
5522        ((eq mark-type 'list)
5523         ;; Simultaneously uncompress and clip to active range
5524         ;; See gnus-uncompress-range for a description of possible marks
5525         (let (l lh)
5526           (if (not (cadr marks))
5527               (set var nil)
5528             (setq articles (if (numberp (cddr marks))
5529                                (list (cdr marks))
5530                              (cdr marks))
5531                   lh (cons nil nil)
5532                   l lh)
5533
5534             (while (setq article (pop articles))
5535               (cond ((consp article)
5536                      (setq bgn (max (car article) min)
5537                            end (min (cdr article) max))
5538                      (while (<= bgn end)
5539                        (setq l (setcdr l (cons bgn nil))
5540                              bgn (1+ bgn))))
5541                     ((and (<= min article)
5542                           (>= max article))
5543                      (setq l (setcdr l (cons article nil))))))
5544             (set var (cdr lh)))))
5545        ;; Adjust assocs.
5546        ((eq mark-type 'tuple)
5547         (set var (setq articles (cdr marks)))
5548         (when (not (listp (cdr (symbol-value var))))
5549           (set var (list (symbol-value var))))
5550         (when (not (listp (cdr articles)))
5551           (setq articles (list articles)))
5552         (while articles
5553           (when (or (not (consp (setq article (pop articles))))
5554                     (< (car article) min)
5555                     (> (car article) max))
5556             (set var (delq article (symbol-value var))))))
5557        ;; Adjust ranges (sloppily).
5558        ((eq mark-type 'range)
5559         (cond
5560          ((eq mark 'seen)
5561           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5562           ;; It should be (seen (NUM1 . NUM2)).
5563           (when (numberp (cddr marks))
5564             (setcdr marks (list (cdr marks))))
5565           (setq articles (cdr marks))
5566           (while (and articles
5567                       (or (and (consp (car articles))
5568                                (> min (cdar articles)))
5569                           (and (numberp (car articles))
5570                                (> min (car articles)))))
5571             (pop articles))
5572           (set var articles))))))))
5573
5574 (defun gnus-update-missing-marks (missing)
5575   "Go through the list of MISSING articles and remove them from the mark lists."
5576   (when missing
5577     (let (var m)
5578       ;; Go through all types.
5579       (dolist (elem gnus-article-mark-lists)
5580         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5581           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5582           (when (symbol-value var)
5583             ;; This list has articles.  So we delete all missing
5584             ;; articles from it.
5585             (setq m missing)
5586             (while m
5587               (set var (delq (pop m) (symbol-value var))))))))))
5588
5589 (defun gnus-update-marks ()
5590   "Enter the various lists of marked articles into the newsgroup info list."
5591   (let ((types gnus-article-mark-lists)
5592         (info (gnus-get-info gnus-newsgroup-name))
5593         type list newmarked symbol delta-marks)
5594     (when info
5595       ;; Add all marks lists to the list of marks lists.
5596       (while (setq type (pop types))
5597         (setq list (symbol-value
5598                     (setq symbol
5599                           (intern (format "gnus-newsgroup-%s" (car type))))))
5600
5601         (when list
5602           ;; Get rid of the entries of the articles that have the
5603           ;; default score.
5604           (when (and (eq (cdr type) 'score)
5605                      gnus-save-score
5606                      list)
5607             (let* ((arts list)
5608                    (prev (cons nil list))
5609                    (all prev))
5610               (while arts
5611                 (if (or (not (consp (car arts)))
5612                         (= (cdar arts) gnus-summary-default-score))
5613                     (setcdr prev (cdr arts))
5614                   (setq prev arts))
5615                 (setq arts (cdr arts)))
5616               (setq list (cdr all)))))
5617
5618         (when (eq (cdr type) 'seen)
5619           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5620
5621         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5622           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5623
5624         (when (and (gnus-check-backend-function
5625                     'request-set-mark gnus-newsgroup-name)
5626                    (not (gnus-article-unpropagatable-p (cdr type))))
5627           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5628                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5629                  (add (gnus-remove-from-range
5630                        (gnus-copy-sequence list) old)))
5631             (when add
5632               (push (list add 'add (list (cdr type))) delta-marks))
5633             (when del
5634               (push (list del 'del (list (cdr type))) delta-marks))))
5635
5636         (when list
5637           (push (cons (cdr type) list) newmarked)))
5638
5639       (when delta-marks
5640         (unless (gnus-check-group gnus-newsgroup-name)
5641           (error "Can't open server for %s" gnus-newsgroup-name))
5642         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5643
5644       ;; Enter these new marks into the info of the group.
5645       (if (nthcdr 3 info)
5646           (setcar (nthcdr 3 info) newmarked)
5647         ;; Add the marks lists to the end of the info.
5648         (when newmarked
5649           (setcdr (nthcdr 2 info) (list newmarked))))
5650
5651       ;; Cut off the end of the info if there's nothing else there.
5652       (let ((i 5))
5653         (while (and (> i 2)
5654                     (not (nth i info)))
5655           (when (nthcdr (decf i) info)
5656             (setcdr (nthcdr i info) nil)))))))
5657
5658 (defun gnus-set-mode-line (where)
5659   "Set the mode line of the article or summary buffers.
5660 If WHERE is `summary', the summary mode line format will be used."
5661   ;; Is this mode line one we keep updated?
5662   (when (and (memq where gnus-updated-mode-lines)
5663              (symbol-value
5664               (intern (format "gnus-%s-mode-line-format-spec" where))))
5665     (let (mode-string)
5666       (save-excursion
5667         ;; We evaluate this in the summary buffer since these
5668         ;; variables are buffer-local to that buffer.
5669         (set-buffer gnus-summary-buffer)
5670         ;; We bind all these variables that are used in the `eval' form
5671         ;; below.
5672         (let* ((mformat (symbol-value
5673                          (intern
5674                           (format "gnus-%s-mode-line-format-spec" where))))
5675                (gnus-tmp-group-name (gnus-group-decoded-name
5676                                      gnus-newsgroup-name))
5677                (gnus-tmp-article-number (or gnus-current-article 0))
5678                (gnus-tmp-unread gnus-newsgroup-unreads)
5679                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5680                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5681                (gnus-tmp-unread-and-unselected
5682                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5683                             (zerop gnus-tmp-unselected))
5684                        "")
5685                       ((zerop gnus-tmp-unselected)
5686                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5687                       (t (format "{%d(+%d) more}"
5688                                  gnus-tmp-unread-and-unticked
5689                                  gnus-tmp-unselected))))
5690                (gnus-tmp-subject
5691                 (if (and gnus-current-headers
5692                          (vectorp gnus-current-headers))
5693                     (gnus-mode-string-quote
5694                      (mail-header-subject gnus-current-headers))
5695                   ""))
5696                bufname-length max-len
5697                gnus-tmp-header);; passed as argument to any user-format-funcs
5698           (setq mode-string (eval mformat))
5699           (setq bufname-length (if (string-match "%b" mode-string)
5700                                    (- (length
5701                                        (buffer-name
5702                                         (if (eq where 'summary)
5703                                             nil
5704                                           (get-buffer gnus-article-buffer))))
5705                                       2)
5706                                  0))
5707           (setq max-len (max 4 (if gnus-mode-non-string-length
5708                                    (- (window-width)
5709                                       gnus-mode-non-string-length
5710                                       bufname-length)
5711                                  (length mode-string))))
5712           ;; We might have to chop a bit of the string off...
5713           (when (> (length mode-string) max-len)
5714             (setq mode-string
5715                   (concat (gnus-truncate-string mode-string (- max-len 3))
5716                           "...")))
5717           ;; Pad the mode string a bit.
5718           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5719       ;; Update the mode line.
5720       (setq mode-line-buffer-identification
5721             (gnus-mode-line-buffer-identification (list mode-string)))
5722       (set-buffer-modified-p t))))
5723
5724 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5725   "Go through the HEADERS list and add all Xrefs to a hash table.
5726 The resulting hash table is returned, or nil if no Xrefs were found."
5727   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5728          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5729          (xref-hashtb (gnus-make-hashtable))
5730          start group entry number xrefs header)
5731     (while headers
5732       (setq header (pop headers))
5733       (when (and (setq xrefs (mail-header-xref header))
5734                  (not (memq (setq number (mail-header-number header))
5735                             unreads)))
5736         (setq start 0)
5737         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5738           (setq start (match-end 0))
5739           (setq group (if prefix
5740                           (concat prefix (substring xrefs (match-beginning 1)
5741                                                     (match-end 1)))
5742                         (substring xrefs (match-beginning 1) (match-end 1))))
5743           (setq number
5744                 (string-to-number (substring xrefs (match-beginning 2)
5745                                           (match-end 2))))
5746           (if (setq entry (gnus-gethash group xref-hashtb))
5747               (setcdr entry (cons number (cdr entry)))
5748             (gnus-sethash group (cons number nil) xref-hashtb)))))
5749     (and start xref-hashtb)))
5750
5751 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5752   "Look through all the headers and mark the Xrefs as read."
5753   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5754         name info xref-hashtb idlist method nth4)
5755     (save-excursion
5756       (set-buffer gnus-group-buffer)
5757       (when (setq xref-hashtb
5758                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5759         (mapatoms
5760          (lambda (group)
5761            (unless (string= from-newsgroup (setq name (symbol-name group)))
5762              (setq idlist (symbol-value group))
5763              ;; Dead groups are not updated.
5764              (and (prog1
5765                       (setq info (gnus-get-info name))
5766                     (when (stringp (setq nth4 (gnus-info-method info)))
5767                       (setq nth4 (gnus-server-to-method nth4))))
5768                   ;; Only do the xrefs if the group has the same
5769                   ;; select method as the group we have just read.
5770                   (or (gnus-methods-equal-p
5771                        nth4 (gnus-find-method-for-group from-newsgroup))
5772                       virtual
5773                       (equal nth4 (setq method (gnus-find-method-for-group
5774                                                 from-newsgroup)))
5775                       (and (equal (car nth4) (car method))
5776                            (equal (nth 1 nth4) (nth 1 method))))
5777                   gnus-use-cross-reference
5778                   (or (not (eq gnus-use-cross-reference t))
5779                       virtual
5780                       ;; Only do cross-references on subscribed
5781                       ;; groups, if that is what is wanted.
5782                       (<= (gnus-info-level info) gnus-level-subscribed))
5783                   (gnus-group-make-articles-read name idlist))))
5784          xref-hashtb)))))
5785
5786 (defun gnus-compute-read-articles (group articles)
5787   (let* ((entry (gnus-group-entry group))
5788          (info (nth 2 entry))
5789          (active (gnus-active group))
5790          ninfo)
5791     (when entry
5792       ;; First peel off all invalid article numbers.
5793       (when active
5794         (let ((ids articles)
5795               id first)
5796           (while (setq id (pop ids))
5797             (when (and first (> id (cdr active)))
5798               ;; We'll end up in this situation in one particular
5799               ;; obscure situation.  If you re-scan a group and get
5800               ;; a new article that is cross-posted to a different
5801               ;; group that has not been re-scanned, you might get
5802               ;; crossposted article that has a higher number than
5803               ;; Gnus believes possible.  So we re-activate this
5804               ;; group as well.  This might mean doing the
5805               ;; crossposting thingy will *increase* the number
5806               ;; of articles in some groups.  Tsk, tsk.
5807               (setq active (or (gnus-activate-group group) active)))
5808             (when (or (> id (cdr active))
5809                       (< id (car active)))
5810               (setq articles (delq id articles))))))
5811       ;; If the read list is nil, we init it.
5812       (if (and active
5813                (null (gnus-info-read info))
5814                (> (car active) 1))
5815           (setq ninfo (cons 1 (1- (car active))))
5816         (setq ninfo (gnus-info-read info)))
5817       ;; Then we add the read articles to the range.
5818       (gnus-add-to-range
5819        ninfo (setq articles (sort articles '<))))))
5820
5821 (defun gnus-group-make-articles-read (group articles)
5822   "Update the info of GROUP to say that ARTICLES are read."
5823   (let* ((num 0)
5824          (entry (gnus-group-entry group))
5825          (info (nth 2 entry))
5826          (active (gnus-active group))
5827          range)
5828     (when entry
5829       (setq range (gnus-compute-read-articles group articles))
5830       (with-current-buffer gnus-group-buffer
5831         (gnus-undo-register
5832           `(progn
5833              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5834              (gnus-info-set-read ',info ',(gnus-info-read info))
5835              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5836              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5837              (gnus-group-update-group ,group t))))
5838       ;; Add the read articles to the range.
5839       (gnus-info-set-read info range)
5840       (gnus-request-set-mark group (list (list range 'add '(read))))
5841       ;; Then we have to re-compute how many unread
5842       ;; articles there are in this group.
5843       (when active
5844         (cond
5845          ((not range)
5846           (setq num (- (1+ (cdr active)) (car active))))
5847          ((not (listp (cdr range)))
5848           (setq num (- (cdr active) (- (1+ (cdr range))
5849                                        (car range)))))
5850          (t
5851           (while range
5852             (if (numberp (car range))
5853                 (setq num (1+ num))
5854               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5855             (setq range (cdr range)))
5856           (setq num (- (cdr active) num))))
5857         ;; Update the number of unread articles.
5858         (setcar entry num)
5859         ;; Update the group buffer.
5860         (unless (gnus-ephemeral-group-p group)
5861           (gnus-group-update-group group t))))))
5862
5863 (defvar gnus-newsgroup-none-id 0)
5864
5865 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5866   (let ((cur nntp-server-buffer)
5867         (dependencies
5868          (or dependencies
5869              (with-current-buffer gnus-summary-buffer
5870                gnus-newsgroup-dependencies)))
5871         headers id end ref number
5872         (mail-parse-charset gnus-newsgroup-charset)
5873         (mail-parse-ignored-charsets
5874          (save-excursion (condition-case nil
5875                              (set-buffer gnus-summary-buffer)
5876                            (error))
5877                          gnus-newsgroup-ignored-charsets)))
5878     (save-excursion
5879       (set-buffer nntp-server-buffer)
5880       ;; Translate all TAB characters into SPACE characters.
5881       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5882       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5883       (ietf-drums-unfold-fws)
5884       (gnus-run-hooks 'gnus-parse-headers-hook)
5885       (let ((case-fold-search t)
5886             in-reply-to header p lines chars ctype)
5887         (goto-char (point-min))
5888         ;; Search to the beginning of the next header.  Error messages
5889         ;; do not begin with 2 or 3.
5890         (while (re-search-forward "^[23][0-9]+ " nil t)
5891           (setq id nil
5892                 ref nil)
5893           ;; This implementation of this function, with nine
5894           ;; search-forwards instead of the one re-search-forward and
5895           ;; a case (which basically was the old function) is actually
5896           ;; about twice as fast, even though it looks messier.  You
5897           ;; can't have everything, I guess.  Speed and elegance
5898           ;; doesn't always go hand in hand.
5899           (setq
5900            header
5901            (make-full-mail-header
5902             ;; Number.
5903             (prog1
5904                 (setq number (read cur))
5905               (end-of-line)
5906               (setq p (point))
5907               (narrow-to-region (point)
5908                                 (or (and (search-forward "\n.\n" nil t)
5909                                          (- (point) 2))
5910                                     (point))))
5911             ;; Subject.
5912             (progn
5913               (goto-char p)
5914               (if (search-forward "\nsubject:" nil t)
5915                   (nnheader-header-value)
5916                 "(none)"))
5917             ;; From.
5918             (progn
5919               (goto-char p)
5920               (if (search-forward "\nfrom:" nil t)
5921                   (nnheader-header-value)
5922                 "(nobody)"))
5923             ;; Date.
5924             (progn
5925               (goto-char p)
5926               (if (search-forward "\ndate:" nil t)
5927                   (nnheader-header-value) ""))
5928             ;; Message-ID.
5929             (progn
5930               (goto-char p)
5931               (setq id (if (re-search-forward
5932                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5933                            ;; We do it this way to make sure the Message-ID
5934                            ;; is (somewhat) syntactically valid.
5935                            (buffer-substring (match-beginning 1)
5936                                              (match-end 1))
5937                          ;; If there was no message-id, we just fake one
5938                          ;; to make subsequent routines simpler.
5939                          (nnheader-generate-fake-message-id number))))
5940             ;; References.
5941             (progn
5942               (goto-char p)
5943               (if (search-forward "\nreferences:" nil t)
5944                   (progn
5945                     (setq end (point))
5946                     (prog1
5947                         (nnheader-header-value)
5948                       (setq ref
5949                             (buffer-substring
5950                              (progn
5951                                ;; (end-of-line)
5952                                (search-backward ">" end t)
5953                                (1+ (point)))
5954                              (progn
5955                                (search-backward "<" end t)
5956                                (point))))))
5957                 ;; Get the references from the in-reply-to header if there
5958                 ;; were no references and the in-reply-to header looks
5959                 ;; promising.
5960                 (if (and (search-forward "\nin-reply-to:" nil t)
5961                          (setq in-reply-to (nnheader-header-value))
5962                          (string-match "<[^>]+>" in-reply-to))
5963                     (let (ref2)
5964                       (setq ref (substring in-reply-to (match-beginning 0)
5965                                            (match-end 0)))
5966                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5967                         (setq ref2 (substring in-reply-to (match-beginning 0)
5968                                               (match-end 0)))
5969                         (when (> (length ref2) (length ref))
5970                           (setq ref ref2)))
5971                       ref)
5972                   (setq ref nil))))
5973             ;; Chars.
5974             (progn
5975               (goto-char p)
5976               (if (search-forward "\nchars: " nil t)
5977                   (if (numberp (setq chars (ignore-errors (read cur))))
5978                       chars -1)
5979                 -1))
5980             ;; Lines.
5981             (progn
5982               (goto-char p)
5983               (if (search-forward "\nlines: " nil t)
5984                   (if (numberp (setq lines (ignore-errors (read cur))))
5985                       lines -1)
5986                 -1))
5987             ;; Xref.
5988             (progn
5989               (goto-char p)
5990               (and (search-forward "\nxref:" nil t)
5991                    (nnheader-header-value)))
5992             ;; Extra.
5993             (when gnus-extra-headers
5994               (let ((extra gnus-extra-headers)
5995                     out)
5996                 (while extra
5997                   (goto-char p)
5998                   (when (search-forward
5999                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6000                     (push (cons (car extra) (nnheader-header-value)) out))
6001                   (pop extra))
6002                 out))))
6003           (goto-char p)
6004           (if (and (search-forward "\ncontent-type: " nil t)
6005                    (setq ctype (nnheader-header-value)))
6006               (mime-entity-set-content-type-internal
6007                header (mime-parse-Content-Type ctype)))
6008           (when (equal id ref)
6009             (setq ref nil))
6010
6011           (when gnus-alter-header-function
6012             (funcall gnus-alter-header-function header)
6013             (setq id (mail-header-id header)
6014                   ref (gnus-parent-id (mail-header-references header))))
6015
6016           (when (setq header
6017                       (gnus-dependencies-add-header
6018                        header dependencies force-new))
6019             (push header headers))
6020           (goto-char (point-max))
6021           (widen))
6022         (nreverse headers)))))
6023
6024 ;; Goes through the xover lines and returns a list of vectors
6025 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6026                                                   force-new dependencies
6027                                                   group also-fetch-heads)
6028   "Parse the news overview data in the server buffer.
6029 Return a list of headers that match SEQUENCE (see
6030 `nntp-retrieve-headers')."
6031   ;; Get the Xref when the users reads the articles since most/some
6032   ;; NNTP servers do not include Xrefs when using XOVER.
6033   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6034   (let ((mail-parse-charset gnus-newsgroup-charset)
6035         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6036         (cur nntp-server-buffer)
6037         (dependencies (or dependencies gnus-newsgroup-dependencies))
6038         (allp (cond
6039                ((eq gnus-read-all-available-headers t)
6040                 t)
6041                ((stringp gnus-read-all-available-headers)
6042                 (string-match gnus-read-all-available-headers group))
6043                (t
6044                 nil)))
6045         number headers header)
6046     (save-excursion
6047       (set-buffer nntp-server-buffer)
6048       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6049       ;; Allow the user to mangle the headers before parsing them.
6050       (gnus-run-hooks 'gnus-parse-headers-hook)
6051       (goto-char (point-min))
6052       (gnus-parse-without-error
6053         (while (and (or sequence allp)
6054                     (not (eobp)))
6055           (setq number (read cur))
6056           (when (not allp)
6057             (while (and sequence
6058                         (< (car sequence) number))
6059               (setq sequence (cdr sequence))))
6060           (when (and (or allp
6061                          (and sequence
6062                               (eq number (car sequence))))
6063                      (progn
6064                        (setq sequence (cdr sequence))
6065                        (setq header (inline
6066                                       (gnus-nov-parse-line
6067                                        number dependencies force-new)))))
6068             (push header headers))
6069           (forward-line 1)))
6070       ;; A common bug in inn is that if you have posted an article and
6071       ;; then retrieves the active file, it will answer correctly --
6072       ;; the new article is included.  However, a NOV entry for the
6073       ;; article may not have been generated yet, so this may fail.
6074       ;; We work around this problem by retrieving the last few
6075       ;; headers using HEAD.
6076       (if (or (not also-fetch-heads)
6077               (not sequence))
6078           ;; We (probably) got all the headers.
6079           (nreverse headers)
6080         (let ((gnus-nov-is-evil t))
6081           (nconc
6082            (nreverse headers)
6083            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6084              (gnus-get-newsgroup-headers))))))))
6085
6086 (defun gnus-article-get-xrefs ()
6087   "Fill in the Xref value in `gnus-current-headers', if necessary.
6088 This is meant to be called in `gnus-article-internal-prepare-hook'."
6089   (let ((headers (with-current-buffer gnus-summary-buffer
6090                    gnus-current-headers)))
6091     (or (not gnus-use-cross-reference)
6092         (not headers)
6093         (and (mail-header-xref headers)
6094              (not (string= (mail-header-xref headers) "")))
6095         (let ((case-fold-search t)
6096               xref)
6097           (save-restriction
6098             (nnheader-narrow-to-headers)
6099             (goto-char (point-min))
6100             (when (or (and (not (eobp))
6101                            (eq (downcase (char-after)) ?x)
6102                            (looking-at "Xref:"))
6103                       (search-forward "\nXref:" nil t))
6104               (goto-char (1+ (match-end 0)))
6105               (setq xref (buffer-substring (point) (point-at-eol)))
6106               (mail-header-set-xref headers xref)))))))
6107
6108 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6109   "Find article ID and insert the summary line for that article.
6110 OLD-HEADER can either be a header or a line number to insert
6111 the subject line on."
6112   (let* ((line (and (numberp old-header) old-header))
6113          (old-header (and (vectorp old-header) old-header))
6114          (header (cond ((and old-header use-old-header)
6115                         old-header)
6116                        ((and (numberp id)
6117                              (gnus-number-to-header id))
6118                         (gnus-number-to-header id))
6119                        (t
6120                         (gnus-read-header id))))
6121          (number (and (numberp id) id))
6122          d)
6123     (when header
6124       ;; Rebuild the thread that this article is part of and go to the
6125       ;; article we have fetched.
6126       (when (and (not gnus-show-threads)
6127                  old-header)
6128         (when (and number
6129                    (setq d (gnus-data-find (mail-header-number old-header))))
6130           (goto-char (gnus-data-pos d))
6131           (gnus-data-remove
6132            number
6133            (- (point-at-bol)
6134               (prog1
6135                   (1+ (point-at-eol))
6136                 (gnus-delete-line))))))
6137       ;; Remove list identifiers from subject.
6138       (when gnus-list-identifiers
6139         (let ((gnus-newsgroup-headers (list header)))
6140           (gnus-summary-remove-list-identifiers)))
6141       (when old-header
6142         (mail-header-set-number header (mail-header-number old-header)))
6143       (setq gnus-newsgroup-sparse
6144             (delq (setq number (mail-header-number header))
6145                   gnus-newsgroup-sparse))
6146       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6147       (push number gnus-newsgroup-limit)
6148       (gnus-rebuild-thread (mail-header-id header) line)
6149       (gnus-summary-goto-subject number nil t))
6150     (when (and (numberp number)
6151                (> number 0))
6152       ;; We have to update the boundaries even if we can't fetch the
6153       ;; article if ID is a number -- so that the next `P' or `N'
6154       ;; command will fetch the previous (or next) article even
6155       ;; if the one we tried to fetch this time has been canceled.
6156       (when (> number gnus-newsgroup-end)
6157         (setq gnus-newsgroup-end number))
6158       (when (< number gnus-newsgroup-begin)
6159         (setq gnus-newsgroup-begin number))
6160       (setq gnus-newsgroup-unselected
6161             (delq number gnus-newsgroup-unselected)))
6162     ;; Report back a success?
6163     (and header (mail-header-number header))))
6164
6165 ;;; Process/prefix in the summary buffer
6166
6167 (defun gnus-summary-work-articles (n)
6168   "Return a list of articles to be worked upon.
6169 The prefix argument, the list of process marked articles, and the
6170 current article will be taken into consideration."
6171   (save-excursion
6172     (set-buffer gnus-summary-buffer)
6173     (cond
6174      (n
6175       ;; A numerical prefix has been given.
6176       (setq n (prefix-numeric-value n))
6177       (let ((backward (< n 0))
6178             (n (abs (prefix-numeric-value n)))
6179             articles article)
6180         (save-excursion
6181           (while
6182               (and (> n 0)
6183                    (push (setq article (gnus-summary-article-number))
6184                          articles)
6185                    (if backward
6186                        (gnus-summary-find-prev nil article)
6187                      (gnus-summary-find-next nil article)))
6188             (decf n)))
6189         (nreverse articles)))
6190      ((and (gnus-region-active-p) (mark))
6191       (message "region active")
6192       ;; Work on the region between point and mark.
6193       (let ((max (max (point) (mark)))
6194             articles article)
6195         (save-excursion
6196           (goto-char (min (point) (mark)))
6197           (while
6198               (and
6199                (push (setq article (gnus-summary-article-number)) articles)
6200                (gnus-summary-find-next nil article)
6201                (< (point) max)))
6202           (nreverse articles))))
6203      (gnus-newsgroup-processable
6204       ;; There are process-marked articles present.
6205       ;; Save current state.
6206       (gnus-summary-save-process-mark)
6207       ;; Return the list.
6208       (reverse gnus-newsgroup-processable))
6209      (t
6210       ;; Just return the current article.
6211       (list (gnus-summary-article-number))))))
6212
6213 (defmacro gnus-summary-iterate (arg &rest forms)
6214   "Iterate over the process/prefixed articles and do FORMS.
6215 ARG is the interactive prefix given to the command.  FORMS will be
6216 executed with point over the summary line of the articles."
6217   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6218     `(let ((,articles (gnus-summary-work-articles ,arg)))
6219        (while ,articles
6220          (gnus-summary-goto-subject (car ,articles))
6221          ,@forms
6222          (pop ,articles)))))
6223
6224 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6225 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6226
6227 (defun gnus-summary-save-process-mark ()
6228   "Push the current set of process marked articles on the stack."
6229   (interactive)
6230   (push (copy-sequence gnus-newsgroup-processable)
6231         gnus-newsgroup-process-stack))
6232
6233 (defun gnus-summary-kill-process-mark ()
6234   "Push the current set of process marked articles on the stack and unmark."
6235   (interactive)
6236   (gnus-summary-save-process-mark)
6237   (gnus-summary-unmark-all-processable))
6238
6239 (defun gnus-summary-yank-process-mark ()
6240   "Pop the last process mark state off the stack and restore it."
6241   (interactive)
6242   (unless gnus-newsgroup-process-stack
6243     (error "Empty mark stack"))
6244   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6245
6246 (defun gnus-summary-process-mark-set (set)
6247   "Make SET into the current process marked articles."
6248   (gnus-summary-unmark-all-processable)
6249   (mapc 'gnus-summary-set-process-mark set))
6250
6251 ;;; Searching and stuff
6252
6253 (defun gnus-summary-search-group (&optional backward use-level)
6254   "Search for next unread newsgroup.
6255 If optional argument BACKWARD is non-nil, search backward instead."
6256   (save-excursion
6257     (set-buffer gnus-group-buffer)
6258     (when (gnus-group-search-forward
6259            backward nil (if use-level (gnus-group-group-level) nil))
6260       (gnus-group-group-name))))
6261
6262 (defun gnus-summary-best-group (&optional exclude-group)
6263   "Find the name of the best unread group.
6264 If EXCLUDE-GROUP, do not go to this group."
6265   (with-current-buffer gnus-group-buffer
6266     (save-excursion
6267       (gnus-group-best-unread-group exclude-group))))
6268
6269 (defun gnus-summary-find-next (&optional unread article backward)
6270   (if backward
6271       (gnus-summary-find-prev unread article)
6272     (let* ((dummy (gnus-summary-article-intangible-p))
6273            (article (or article (gnus-summary-article-number)))
6274            (data (gnus-data-find-list article))
6275            result)
6276       (when (and (not dummy)
6277                  (or (not gnus-summary-check-current)
6278                      (not unread)
6279                      (not (gnus-data-unread-p (car data)))))
6280         (setq data (cdr data)))
6281       (when (setq result
6282                   (if unread
6283                       (progn
6284                         (while data
6285                           (unless (memq (gnus-data-number (car data))
6286                                         (cond
6287                                          ((eq gnus-auto-goto-ignores
6288                                               'always-undownloaded)
6289                                           gnus-newsgroup-undownloaded)
6290                                          (gnus-plugged
6291                                           nil)
6292                                          ((eq gnus-auto-goto-ignores
6293                                               'unfetched)
6294                                           gnus-newsgroup-unfetched)
6295                                          ((eq gnus-auto-goto-ignores
6296                                               'undownloaded)
6297                                           gnus-newsgroup-undownloaded)))
6298                             (when (gnus-data-unread-p (car data))
6299                               (setq result (car data)
6300                                     data nil)))
6301                           (setq data (cdr data)))
6302                         result)
6303                     (car data)))
6304         (goto-char (gnus-data-pos result))
6305         (gnus-data-number result)))))
6306
6307 (defun gnus-summary-find-prev (&optional unread article)
6308   (let* ((eobp (eobp))
6309          (article (or article (gnus-summary-article-number)))
6310          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6311          result)
6312     (when (and (not eobp)
6313                (or (not gnus-summary-check-current)
6314                    (not unread)
6315                    (not (gnus-data-unread-p (car data)))))
6316       (setq data (cdr data)))
6317     (when (setq result
6318                 (if unread
6319                     (progn
6320                       (while data
6321                         (unless (memq (gnus-data-number (car data))
6322                                       (cond
6323                                        ((eq gnus-auto-goto-ignores
6324                                             'always-undownloaded)
6325                                         gnus-newsgroup-undownloaded)
6326                                        (gnus-plugged
6327                                         nil)
6328                                        ((eq gnus-auto-goto-ignores
6329                                             'unfetched)
6330                                         gnus-newsgroup-unfetched)
6331                                        ((eq gnus-auto-goto-ignores
6332                                             'undownloaded)
6333                                         gnus-newsgroup-undownloaded)))
6334                           (when (gnus-data-unread-p (car data))
6335                             (setq result (car data)
6336                                   data nil)))
6337                         (setq data (cdr data)))
6338                       result)
6339                   (car data)))
6340       (goto-char (gnus-data-pos result))
6341       (gnus-data-number result))))
6342
6343 (defun gnus-summary-find-subject (subject &optional unread backward article)
6344   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6345          (article (or article (gnus-summary-article-number)))
6346          (articles (gnus-data-list backward))
6347          (arts (gnus-data-find-list article articles))
6348          result)
6349     (when (or (not gnus-summary-check-current)
6350               (not unread)
6351               (not (gnus-data-unread-p (car arts))))
6352       (setq arts (cdr arts)))
6353     (while arts
6354       (and (or (not unread)
6355                (gnus-data-unread-p (car arts)))
6356            (vectorp (gnus-data-header (car arts)))
6357            (gnus-subject-equal
6358             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6359            (setq result (car arts)
6360                  arts nil))
6361       (setq arts (cdr arts)))
6362     (and result
6363          (goto-char (gnus-data-pos result))
6364          (gnus-data-number result))))
6365
6366 (defun gnus-summary-search-forward (&optional unread subject backward)
6367   "Search forward for an article.
6368 If UNREAD, look for unread articles.  If SUBJECT, look for
6369 articles with that subject.  If BACKWARD, search backward instead."
6370   (cond (subject (gnus-summary-find-subject subject unread backward))
6371         (backward (gnus-summary-find-prev unread))
6372         (t (gnus-summary-find-next unread))))
6373
6374 (defun gnus-recenter (&optional n)
6375   "Center point in window and redisplay frame.
6376 Also do horizontal recentering."
6377   (interactive "P")
6378   (when (and gnus-auto-center-summary
6379              (not (eq gnus-auto-center-summary 'vertical)))
6380     (gnus-horizontal-recenter))
6381   (recenter n))
6382
6383 (defun gnus-summary-recenter ()
6384   "Center point in the summary window.
6385 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6386 displayed, no centering will be performed."
6387   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6388   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6389   (interactive)
6390   ;; The user has to want it.
6391   (when gnus-auto-center-summary
6392     (let* ((top (cond ((< (window-height) 4) 0)
6393                       ((< (window-height) 7) 1)
6394                       (t (if (numberp gnus-auto-center-summary)
6395                              gnus-auto-center-summary
6396                            (/ (1- (window-height)) 2)))))
6397            (height (1- (window-height)))
6398            (bottom (save-excursion (goto-char (point-max))
6399                                    (forward-line (- height))
6400                                    (point)))
6401            (window (get-buffer-window (current-buffer))))
6402       (when (get-buffer-window gnus-article-buffer)
6403         ;; Only do recentering when the article buffer is displayed,
6404         ;; Set the window start to either `bottom', which is the biggest
6405         ;; possible valid number, or the second line from the top,
6406         ;; whichever is the least.
6407         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6408           (if (> bottom top-pos)
6409               ;; Keep the second line from the top visible
6410               (set-window-start window top-pos t)
6411             ;; Try to keep the bottom line visible; if it's partially
6412             ;; obscured, either scroll one more line to make it fully
6413             ;; visible, or revert to using TOP-POS.
6414             (save-excursion
6415               (goto-char (point-max))
6416               (forward-line -1)
6417               (let ((last-line-start (point)))
6418                 (goto-char bottom)
6419                 (set-window-start window (point) t)
6420                 (when (not (pos-visible-in-window-p last-line-start window))
6421                   (forward-line 1)
6422                   (set-window-start window (min (point) top-pos) t)))))))
6423       ;; Do horizontal recentering while we're at it.
6424       (when (and (get-buffer-window (current-buffer) t)
6425                  (not (eq gnus-auto-center-summary 'vertical)))
6426         (let ((selected (selected-window)))
6427           (select-window (get-buffer-window (current-buffer) t))
6428           (gnus-summary-position-point)
6429           (gnus-horizontal-recenter)
6430           (select-window selected))))))
6431
6432 (defun gnus-summary-jump-to-group (newsgroup)
6433   "Move point to NEWSGROUP in group mode buffer."
6434   ;; Keep update point of group mode buffer if visible.
6435   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6436       (save-window-excursion
6437         ;; Take care of tree window mode.
6438         (when (get-buffer-window gnus-group-buffer)
6439           (pop-to-buffer gnus-group-buffer))
6440         (gnus-group-jump-to-group newsgroup))
6441     (save-excursion
6442       ;; Take care of tree window mode.
6443       (if (get-buffer-window gnus-group-buffer)
6444           (pop-to-buffer gnus-group-buffer)
6445         (set-buffer gnus-group-buffer))
6446       (gnus-group-jump-to-group newsgroup))))
6447
6448 ;; This function returns a list of article numbers based on the
6449 ;; difference between the ranges of read articles in this group and
6450 ;; the range of active articles.
6451 (defun gnus-list-of-unread-articles (group)
6452   (let* ((read (gnus-info-read (gnus-get-info group)))
6453          (active (or (gnus-active group) (gnus-activate-group group)))
6454          (last (or (cdr active)
6455                    (error "Group %s couldn't be activated " group)))
6456          first nlast unread)
6457     ;; If none are read, then all are unread.
6458     (if (not read)
6459         (setq first (car active))
6460       ;; If the range of read articles is a single range, then the
6461       ;; first unread article is the article after the last read
6462       ;; article.  Sounds logical, doesn't it?
6463       (if (and (not (listp (cdr read)))
6464                (or (< (car read) (car active))
6465                    (progn (setq read (list read))
6466                           nil)))
6467           (setq first (max (car active) (1+ (cdr read))))
6468         ;; `read' is a list of ranges.
6469         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6470                                   (caar read)))
6471                   1)
6472           (setq first (car active)))
6473         (while read
6474           (when first
6475             (while (< first nlast)
6476               (setq unread (cons first unread)
6477                     first (1+ first))))
6478           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6479           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6480           (setq read (cdr read)))))
6481     ;; And add the last unread articles.
6482     (while (<= first last)
6483       (setq unread (cons first unread)
6484             first (1+ first)))
6485     ;; Return the list of unread articles.
6486     (delq 0 (nreverse unread))))
6487
6488 (defun gnus-list-of-read-articles (group)
6489   "Return a list of unread, unticked and non-dormant articles."
6490   (let* ((info (gnus-get-info group))
6491          (marked (gnus-info-marks info))
6492          (active (gnus-active group)))
6493     (and info active
6494          (gnus-list-range-difference
6495           (gnus-list-range-difference
6496            (gnus-sorted-complement
6497             (gnus-uncompress-range active)
6498             (gnus-list-of-unread-articles group))
6499            (cdr (assq 'dormant marked)))
6500           (cdr (assq 'tick marked))))))
6501
6502 ;; This function returns a sequence of article numbers based on the
6503 ;; difference between the ranges of read articles in this group and
6504 ;; the range of active articles.
6505 (defun gnus-sequence-of-unread-articles (group)
6506   (let* ((read (gnus-info-read (gnus-get-info group)))
6507          (active (or (gnus-active group) (gnus-activate-group group)))
6508          (last (cdr active))
6509          first nlast unread)
6510     ;; If none are read, then all are unread.
6511     (if (not read)
6512         (setq first (car active))
6513       ;; If the range of read articles is a single range, then the
6514       ;; first unread article is the article after the last read
6515       ;; article.  Sounds logical, doesn't it?
6516       (if (and (not (listp (cdr read)))
6517                (or (< (car read) (car active))
6518                    (progn (setq read (list read))
6519                           nil)))
6520           (setq first (max (car active) (1+ (cdr read))))
6521         ;; `read' is a list of ranges.
6522         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6523                                   (caar read)))
6524                   1)
6525           (setq first (car active)))
6526         (while read
6527           (when first
6528             (push (cons first nlast) unread))
6529           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6530           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6531           (setq read (cdr read)))))
6532     ;; And add the last unread articles.
6533     (cond ((< first last)
6534            (push (cons first last) unread))
6535           ((= first last)
6536            (push first unread)))
6537     ;; Return the sequence of unread articles.
6538     (delq 0 (nreverse unread))))
6539
6540 ;; Various summary commands
6541
6542 (defun gnus-summary-select-article-buffer ()
6543   "Reconfigure windows to show article buffer."
6544   (interactive)
6545   (if (not (gnus-buffer-live-p gnus-article-buffer))
6546       (error "There is no article buffer for this summary buffer")
6547     (gnus-configure-windows 'article)
6548     (select-window (get-buffer-window gnus-article-buffer))))
6549
6550 (defun gnus-summary-universal-argument (arg)
6551   "Perform any operation on all articles that are process/prefixed."
6552   (interactive "P")
6553   (let ((articles (gnus-summary-work-articles arg))
6554         func article)
6555     (if (eq
6556          (setq
6557           func
6558           (key-binding
6559            (read-key-sequence
6560             (substitute-command-keys
6561              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6562          'undefined)
6563         (gnus-error 1 "Undefined key")
6564       (save-excursion
6565         (while articles
6566           (gnus-summary-goto-subject (setq article (pop articles)))
6567           (let (gnus-newsgroup-processable)
6568             (command-execute func))
6569           (gnus-summary-remove-process-mark article)))))
6570   (gnus-summary-position-point))
6571
6572 (defun gnus-summary-toggle-truncation (&optional arg)
6573   "Toggle truncation of summary lines.
6574 With ARG, turn line truncation on if ARG is positive."
6575   (interactive "P")
6576   (setq truncate-lines
6577         (if (null arg) (not truncate-lines)
6578           (> (prefix-numeric-value arg) 0)))
6579   (redraw-display))
6580
6581 (defun gnus-summary-find-for-reselect ()
6582   "Return the number of an article to stay on across a reselect.
6583 The current article is considered, then following articles, then previous
6584 articles.  An article is sought which is not cancelled and isn't a temporary
6585 insertion from another group.  If there's no such then return a dummy 0."
6586   (let (found)
6587     (dolist (rev '(nil t))
6588       (unless found      ; don't demand the reverse list if we don't need it
6589         (let ((data (gnus-data-find-list
6590                      (gnus-summary-article-number) (gnus-data-list rev))))
6591           (while (and data (not found))
6592             (if (and (< 0 (gnus-data-number (car data)))
6593                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6594                 (setq found (gnus-data-number (car data))))
6595             (setq data (cdr data))))))
6596     (or found 0)))
6597
6598 (defun gnus-summary-reselect-current-group (&optional all rescan)
6599   "Exit and then reselect the current newsgroup.
6600 The prefix argument ALL means to select all articles."
6601   (interactive "P")
6602   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6603     (error "Ephemeral groups can't be reselected"))
6604   (let ((current-subject (gnus-summary-find-for-reselect))
6605         (group gnus-newsgroup-name))
6606     (setq gnus-newsgroup-begin nil)
6607     (gnus-summary-exit nil 'leave-hidden)
6608     ;; We have to adjust the point of group mode buffer because
6609     ;; point was moved to the next unread newsgroup by exiting.
6610     (gnus-summary-jump-to-group group)
6611     (when rescan
6612       (save-excursion
6613         (save-window-excursion
6614           ;; Don't show group contents.
6615           (set-window-start (selected-window) (point-max))
6616           (gnus-group-get-new-news-this-group 1))))
6617     (gnus-group-read-group all t)
6618     (gnus-summary-goto-subject current-subject nil t)))
6619
6620 (defun gnus-summary-rescan-group (&optional all)
6621   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6622   (interactive "P")
6623   (gnus-summary-reselect-current-group all t))
6624
6625 (defun gnus-summary-update-info (&optional non-destructive)
6626   (save-excursion
6627     (let ((group gnus-newsgroup-name))
6628       (when group
6629         (when gnus-newsgroup-kill-headers
6630           (setq gnus-newsgroup-killed
6631                 (gnus-compress-sequence
6632                  (gnus-sorted-union
6633                   (gnus-list-range-intersection
6634                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6635                   gnus-newsgroup-unreads)
6636                  t)))
6637         (unless (listp (cdr gnus-newsgroup-killed))
6638           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6639         (let ((headers gnus-newsgroup-headers))
6640           ;; Set the new ranges of read articles.
6641           (with-current-buffer gnus-group-buffer
6642             (gnus-undo-force-boundary))
6643           (gnus-update-read-articles
6644            group (gnus-sorted-union
6645                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6646           ;; Set the current article marks.
6647           (let ((gnus-newsgroup-scored
6648                  (if (and (not gnus-save-score)
6649                           (not non-destructive))
6650                      nil
6651                    gnus-newsgroup-scored)))
6652             (save-excursion
6653               (gnus-update-marks)))
6654           ;; Do the cross-ref thing.
6655           (when gnus-use-cross-reference
6656             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6657           ;; Do not switch windows but change the buffer to work.
6658           (set-buffer gnus-group-buffer)
6659           (unless (gnus-ephemeral-group-p group)
6660             (gnus-group-update-group group)))))))
6661
6662 (defun gnus-summary-save-newsrc (&optional force)
6663   "Save the current number of read/marked articles in the dribble buffer.
6664 The dribble buffer will then be saved.
6665 If FORCE (the prefix), also save the .newsrc file(s)."
6666   (interactive "P")
6667   (gnus-summary-update-info t)
6668   (if force
6669       (gnus-save-newsrc-file)
6670     (gnus-dribble-save)))
6671
6672 (defun gnus-summary-exit (&optional temporary leave-hidden)
6673   "Exit reading current newsgroup, and then return to group selection mode.
6674 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6675   (interactive)
6676   (gnus-set-global-variables)
6677   (gnus-kill-save-kill-buffer)
6678   (gnus-async-halt-prefetch)
6679   (let* ((group gnus-newsgroup-name)
6680          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6681          (gnus-group-is-exiting-p t)
6682          (mode major-mode)
6683          (group-point nil)
6684          (buf (current-buffer)))
6685     (unless quit-config
6686       ;; Do adaptive scoring, and possibly save score files.
6687       (when gnus-newsgroup-adaptive
6688         (gnus-score-adaptive))
6689       (when gnus-use-scoring
6690         (gnus-score-save)))
6691     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6692     ;; If we have several article buffers, we kill them at exit.
6693     (unless gnus-single-article-buffer
6694       (gnus-kill-buffer gnus-original-article-buffer)
6695       (setq gnus-article-current nil))
6696     (when gnus-use-cache
6697       (gnus-cache-possibly-remove-articles)
6698       (gnus-cache-save-buffers))
6699     (gnus-async-prefetch-remove-group group)
6700     (when gnus-suppress-duplicates
6701       (gnus-dup-enter-articles))
6702     (when gnus-use-trees
6703       (gnus-tree-close group))
6704     (when gnus-use-cache
6705       (gnus-cache-write-active))
6706     ;; Remove entries for this group.
6707     (nnmail-purge-split-history (gnus-group-real-name group))
6708     ;; Make all changes in this group permanent.
6709     (unless quit-config
6710       (gnus-run-hooks 'gnus-exit-group-hook)
6711       (gnus-summary-update-info))
6712     (gnus-close-group group)
6713     ;; Make sure where we were, and go to next newsgroup.
6714     (set-buffer gnus-group-buffer)
6715     (unless quit-config
6716       (gnus-group-jump-to-group group))
6717     (gnus-run-hooks 'gnus-summary-exit-hook)
6718     (unless (or quit-config
6719                 ;; If this group has disappeared from the summary
6720                 ;; buffer, don't skip forwards.
6721                 (not (string= group (gnus-group-group-name))))
6722       (gnus-group-next-unread-group 1))
6723     (setq group-point (point))
6724     (if temporary
6725         nil                             ;Nothing to do.
6726       ;; If we have several article buffers, we kill them at exit.
6727       (unless gnus-single-article-buffer
6728         (gnus-kill-buffer gnus-article-buffer)
6729         (gnus-kill-buffer gnus-original-article-buffer)
6730         (setq gnus-article-current nil))
6731       (set-buffer buf)
6732       (if (not gnus-kill-summary-on-exit)
6733           (progn
6734             (gnus-deaden-summary)
6735             (setq mode nil))
6736         ;; We set all buffer-local variables to nil.  It is unclear why
6737         ;; this is needed, but if we don't, buffer-local variables are
6738         ;; not garbage-collected, it seems.  This would the lead to en
6739         ;; ever-growing Emacs.
6740         (gnus-summary-clear-local-variables)
6741         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6742           (gnus-summary-clear-local-variables))
6743         (when (get-buffer gnus-article-buffer)
6744           (bury-buffer gnus-article-buffer))
6745         ;; Return to group mode buffer.
6746         (when (eq mode 'gnus-summary-mode)
6747           (gnus-kill-buffer buf)))
6748       (setq gnus-current-select-method gnus-select-method)
6749       (set-buffer gnus-group-buffer)
6750       (if quit-config
6751           (gnus-handle-ephemeral-exit quit-config)
6752         (goto-char group-point)
6753         ;; If gnus-group-buffer is already displayed, make sure we also move
6754         ;; the cursor in the window that displays it.
6755         (let ((win (get-buffer-window (current-buffer) 0)))
6756           (if win (set-window-point win (point))))
6757         (unless leave-hidden
6758           (gnus-configure-windows 'group 'force))
6759         (unless (pos-visible-in-window-p)
6760           (forward-line (/ (static-if (featurep 'xemacs)
6761                                (window-displayed-height)
6762                              (1- (window-height)))
6763                            -2))
6764           (set-window-start (selected-window) (point))
6765           (goto-char group-point)))
6766       ;; Clear the current group name.
6767       (unless quit-config
6768         (setq gnus-newsgroup-name nil)))))
6769
6770 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6771 (defun gnus-summary-exit-no-update (&optional no-questions)
6772   "Quit reading current newsgroup without updating read article info."
6773   (interactive)
6774   (let* ((group gnus-newsgroup-name)
6775          (gnus-group-is-exiting-p t)
6776          (gnus-group-is-exiting-without-update-p t)
6777          (quit-config (gnus-group-quit-config group)))
6778     (when (or no-questions
6779               gnus-expert-user
6780               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6781       (gnus-async-halt-prefetch)
6782       (run-hooks 'gnus-summary-prepare-exit-hook)
6783       ;; If we have several article buffers, we kill them at exit.
6784       (unless gnus-single-article-buffer
6785         (gnus-kill-buffer gnus-article-buffer)
6786         (gnus-kill-buffer gnus-original-article-buffer)
6787         (setq gnus-article-current nil))
6788       (if (not gnus-kill-summary-on-exit)
6789           (gnus-deaden-summary)
6790         (gnus-close-group group)
6791         (gnus-summary-clear-local-variables)
6792         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6793           (gnus-summary-clear-local-variables))
6794         (gnus-kill-buffer gnus-summary-buffer))
6795       (unless gnus-single-article-buffer
6796         (setq gnus-article-current nil))
6797       (when gnus-use-trees
6798         (gnus-tree-close group))
6799       (gnus-async-prefetch-remove-group group)
6800       (when (get-buffer gnus-article-buffer)
6801         (bury-buffer gnus-article-buffer))
6802       ;; Return to the group buffer.
6803       (gnus-configure-windows 'group 'force)
6804       ;; Clear the current group name.
6805       (setq gnus-newsgroup-name nil)
6806       (unless (gnus-ephemeral-group-p group)
6807         (gnus-group-update-group group))
6808       (when (equal (gnus-group-group-name) group)
6809         (gnus-group-next-unread-group 1))
6810       (when quit-config
6811         (gnus-handle-ephemeral-exit quit-config)))))
6812
6813 (defun gnus-handle-ephemeral-exit (quit-config)
6814   "Handle movement when leaving an ephemeral group.
6815 The state which existed when entering the ephemeral is reset."
6816   (if (not (buffer-name (car quit-config)))
6817       (gnus-configure-windows 'group 'force)
6818     (set-buffer (car quit-config))
6819     (cond ((eq major-mode 'gnus-summary-mode)
6820            (gnus-set-global-variables))
6821           ((eq major-mode 'gnus-article-mode)
6822            (save-excursion
6823              ;; The `gnus-summary-buffer' variable may point
6824              ;; to the old summary buffer when using a single
6825              ;; article buffer.
6826              (unless (gnus-buffer-live-p gnus-summary-buffer)
6827                (set-buffer gnus-group-buffer))
6828              (set-buffer gnus-summary-buffer)
6829              (gnus-set-global-variables))))
6830     (if (or (eq (cdr quit-config) 'article)
6831             (eq (cdr quit-config) 'pick))
6832         (progn
6833           ;; The current article may be from the ephemeral group
6834           ;; thus it is best that we reload this article
6835           ;;
6836           ;; If we're exiting from a large digest, this can be
6837           ;; extremely slow.  So, it's better not to reload it. -- jh.
6838           ;;(gnus-summary-show-article)
6839           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6840               (gnus-configure-windows 'pick 'force)
6841             (gnus-configure-windows (cdr quit-config) 'force)))
6842       (gnus-configure-windows (cdr quit-config) 'force))
6843     (when (eq major-mode 'gnus-summary-mode)
6844       (gnus-summary-next-subject 1 nil t)
6845       (gnus-summary-recenter)
6846       (gnus-summary-position-point))))
6847
6848 (defun gnus-summary-preview-mime-message ()
6849   "MIME decode and play this message."
6850   (interactive)
6851   (let ((gnus-break-pages nil)
6852         (gnus-show-mime t))
6853     (gnus-summary-select-article gnus-show-all-headers t))
6854   (let ((w (get-buffer-window gnus-article-buffer)))
6855     (when w
6856       (select-window (get-buffer-window gnus-article-buffer)))))
6857
6858 ;;; Dead summaries.
6859
6860 (defvar gnus-dead-summary-mode-map nil)
6861
6862 (unless gnus-dead-summary-mode-map
6863   (setq gnus-dead-summary-mode-map (make-keymap))
6864   (suppress-keymap gnus-dead-summary-mode-map)
6865   (substitute-key-definition
6866    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6867   (dolist (key '("\C-d" "\r" "\177" [delete]))
6868     (define-key gnus-dead-summary-mode-map
6869       key 'gnus-summary-wake-up-the-dead))
6870   (dolist (key '("q" "Q"))
6871     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6872
6873 (defvar gnus-dead-summary-mode nil
6874   "Minor mode for Gnus summary buffers.")
6875
6876 (defun gnus-dead-summary-mode (&optional arg)
6877   "Minor mode for Gnus summary buffers."
6878   (interactive "P")
6879   (when (eq major-mode 'gnus-summary-mode)
6880     (make-local-variable 'gnus-dead-summary-mode)
6881     (setq gnus-dead-summary-mode
6882           (if (null arg) (not gnus-dead-summary-mode)
6883             (> (prefix-numeric-value arg) 0)))
6884     (when gnus-dead-summary-mode
6885       (add-minor-mode
6886        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6887
6888 (defun gnus-deaden-summary ()
6889   "Make the current summary buffer into a dead summary buffer."
6890   ;; Kill any previous dead summary buffer.
6891   (when (and gnus-dead-summary
6892              (buffer-name gnus-dead-summary))
6893     (with-current-buffer gnus-dead-summary
6894       (when gnus-dead-summary-mode
6895         (kill-buffer (current-buffer)))))
6896   ;; Make this the current dead summary.
6897   (setq gnus-dead-summary (current-buffer))
6898   (gnus-dead-summary-mode 1)
6899   (let ((name (buffer-name)))
6900     (when (string-match "Summary" name)
6901       (rename-buffer
6902        (concat (substring name 0 (match-beginning 0)) "Dead "
6903                (substring name (match-beginning 0)))
6904        t)
6905       (bury-buffer))))
6906
6907 (defun gnus-kill-or-deaden-summary (buffer)
6908   "Kill or deaden the summary BUFFER."
6909   (save-excursion
6910     (when (and (buffer-name buffer)
6911                (not gnus-single-article-buffer))
6912       (with-current-buffer buffer
6913         (gnus-kill-buffer gnus-article-buffer)
6914         (gnus-kill-buffer gnus-original-article-buffer)))
6915     (cond
6916      ;; Kill the buffer.
6917      (gnus-kill-summary-on-exit
6918       (when (and gnus-use-trees
6919                  (gnus-buffer-exists-p buffer))
6920         (save-excursion
6921           (set-buffer buffer)
6922           (gnus-tree-close gnus-newsgroup-name)))
6923       (gnus-kill-buffer buffer))
6924      ;; Deaden the buffer.
6925      ((gnus-buffer-exists-p buffer)
6926       (save-excursion
6927         (set-buffer buffer)
6928         (gnus-deaden-summary))))))
6929
6930 (defun gnus-summary-wake-up-the-dead (&rest args)
6931   "Wake up the dead summary buffer."
6932   (interactive)
6933   (gnus-dead-summary-mode -1)
6934   (let ((name (buffer-name)))
6935     (when (string-match "Dead " name)
6936       (rename-buffer
6937        (concat (substring name 0 (match-beginning 0))
6938                (substring name (match-end 0)))
6939        t)))
6940   (gnus-message 3 "This dead summary is now alive again"))
6941
6942 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6943 (defun gnus-summary-fetch-faq (&optional faq-dir)
6944   "Fetch the FAQ for the current group.
6945 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6946 in."
6947   (interactive
6948    (list
6949     (when current-prefix-arg
6950       (completing-read
6951        "FAQ dir: " (and (listp gnus-group-faq-directory)
6952                         (mapcar 'list
6953                                 gnus-group-faq-directory))))))
6954   (let (gnus-faq-buffer)
6955     (when (setq gnus-faq-buffer
6956                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6957       (gnus-configure-windows 'summary-faq))))
6958
6959 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6960 (defun gnus-summary-describe-group (&optional force)
6961   "Describe the current newsgroup."
6962   (interactive "P")
6963   (gnus-group-describe-group force gnus-newsgroup-name))
6964
6965 (defun gnus-summary-describe-briefly ()
6966   "Describe summary mode commands briefly."
6967   (interactive)
6968   (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")))
6969
6970 ;; Walking around group mode buffer from summary mode.
6971
6972 (defun gnus-summary-next-group (&optional no-article target-group backward)
6973   "Exit current newsgroup and then select next unread newsgroup.
6974 If prefix argument NO-ARTICLE is non-nil, no article is selected
6975 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6976 previous group instead."
6977   (interactive "P")
6978   ;; Stop pre-fetching.
6979   (gnus-async-halt-prefetch)
6980   (let ((current-group gnus-newsgroup-name)
6981         (current-buffer (current-buffer))
6982         entered)
6983     ;; First we semi-exit this group to update Xrefs and all variables.
6984     ;; We can't do a real exit, because the window conf must remain
6985     ;; the same in case the user is prompted for info, and we don't
6986     ;; want the window conf to change before that...
6987     (gnus-summary-exit t)
6988     (while (not entered)
6989       ;; Then we find what group we are supposed to enter.
6990       (set-buffer gnus-group-buffer)
6991       (gnus-group-jump-to-group current-group)
6992       (setq target-group
6993             (or target-group
6994                 (if (eq gnus-keep-same-level 'best)
6995                     (gnus-summary-best-group gnus-newsgroup-name)
6996                   (gnus-summary-search-group backward gnus-keep-same-level))))
6997       (if (not target-group)
6998           ;; There are no further groups, so we return to the group
6999           ;; buffer.
7000           (progn
7001             (gnus-message 5 "Returning to the group buffer")
7002             (setq entered t)
7003             (when (gnus-buffer-live-p current-buffer)
7004               (set-buffer current-buffer)
7005               (gnus-summary-exit))
7006             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7007         ;; We try to enter the target group.
7008         (gnus-group-jump-to-group target-group)
7009         (let ((unreads (gnus-group-group-unread)))
7010           (if (and (or (eq t unreads)
7011                        (and unreads (not (zerop unreads))))
7012                    (gnus-summary-read-group
7013                     target-group nil no-article
7014                     (and (buffer-name current-buffer) current-buffer)
7015                     nil backward))
7016               (setq entered t)
7017             (setq current-group target-group
7018                   target-group nil)))))))
7019
7020 (defun gnus-summary-prev-group (&optional no-article)
7021   "Exit current newsgroup and then select previous unread newsgroup.
7022 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7023   (interactive "P")
7024   (gnus-summary-next-group no-article nil t))
7025
7026 ;; Walking around summary lines.
7027
7028 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7029   "Go to the first subject satisfying any non-nil constraint.
7030 If UNREAD is non-nil, the article should be unread.
7031 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7032 If UNSEEN is non-nil, the article should be unseen.
7033 Returns the article selected or nil if there are no matching articles."
7034   (interactive "P")
7035   (cond
7036    ;; Empty summary.
7037    ((null gnus-newsgroup-data)
7038     (gnus-message 3 "No articles in the group")
7039     nil)
7040    ;; Pick the first article.
7041    ((not (or unread undownloaded unseen))
7042     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7043     (gnus-data-number (car gnus-newsgroup-data)))
7044    ;; Find the first unread article.
7045    (t
7046     (let ((data gnus-newsgroup-data))
7047       (while (and data
7048                   (let ((num (gnus-data-number (car data))))
7049                     (or (memq num gnus-newsgroup-unfetched)
7050                         (not (or (and unread
7051                                       (memq num gnus-newsgroup-unreads))
7052                                  (and undownloaded
7053                                       (memq num gnus-newsgroup-undownloaded))
7054                                  (and unseen
7055                                       (memq num gnus-newsgroup-unseen)))))))
7056         (setq data (cdr data)))
7057       (prog1
7058           (if data
7059               (progn
7060                 (goto-char (gnus-data-pos (car data)))
7061                 (gnus-data-number (car data)))
7062             (gnus-message 3 "No more%s articles"
7063                           (let* ((r (when unread " unread"))
7064                                  (d (when undownloaded " undownloaded"))
7065                                  (s (when unseen " unseen"))
7066                                  (l (delq nil (list r d s))))
7067                             (cond ((= 3 (length l))
7068                                    (concat r "," d ", or" s))
7069                                   ((= 2 (length l))
7070                                    (concat (car l) ", or" (cadr l)))
7071                                   ((= 1 (length l))
7072                                    (car l))
7073                                   (t
7074                                    ""))))
7075             nil
7076             )
7077         (gnus-summary-position-point))))))
7078
7079 (defun gnus-summary-next-subject (n &optional unread dont-display)
7080   "Go to next N'th summary line.
7081 If N is negative, go to the previous N'th subject line.
7082 If UNREAD is non-nil, only unread articles are selected.
7083 The difference between N and the actual number of steps taken is
7084 returned."
7085   (interactive "p")
7086   (let ((backward (< n 0))
7087         (n (abs n)))
7088     (while (and (> n 0)
7089                 (if backward
7090                     (gnus-summary-find-prev unread)
7091                   (gnus-summary-find-next unread)))
7092       (unless (zerop (setq n (1- n)))
7093         (gnus-summary-show-thread)))
7094     (when (/= 0 n)
7095       (gnus-message 7 "No more%s articles"
7096                     (if unread " unread" "")))
7097     (unless dont-display
7098       (gnus-summary-recenter)
7099       (gnus-summary-position-point))
7100     n))
7101
7102 (defun gnus-summary-next-unread-subject (n)
7103   "Go to next N'th unread summary line."
7104   (interactive "p")
7105   (gnus-summary-next-subject n t))
7106
7107 (defun gnus-summary-prev-subject (n &optional unread)
7108   "Go to previous N'th summary line.
7109 If optional argument UNREAD is non-nil, only unread article is selected."
7110   (interactive "p")
7111   (gnus-summary-next-subject (- n) unread))
7112
7113 (defun gnus-summary-prev-unread-subject (n)
7114   "Go to previous N'th unread summary line."
7115   (interactive "p")
7116   (gnus-summary-next-subject (- n) t))
7117
7118 (defun gnus-summary-goto-subjects (articles)
7119   "Insert the subject header for ARTICLES in the current buffer."
7120   (save-excursion
7121     (dolist (article articles)
7122       (gnus-summary-goto-subject article t)))
7123   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7124   (gnus-summary-position-point))
7125
7126 (defun gnus-summary-goto-subject (article &optional force silent)
7127   "Go the subject line of ARTICLE.
7128 If FORCE, also allow jumping to articles not currently shown."
7129   (interactive "nArticle number: ")
7130   (unless (numberp article)
7131     (error "Article %s is not a number" article))
7132   (let ((b (point))
7133         (data (gnus-data-find article)))
7134     ;; We read in the article if we have to.
7135     (and (not data)
7136          force
7137          (gnus-summary-insert-subject
7138           article
7139           (if (or (numberp force) (vectorp force)) force)
7140           t)
7141          (setq data (gnus-data-find article)))
7142     (goto-char b)
7143     (if (not data)
7144         (progn
7145           (unless silent
7146             (gnus-message 3 "Can't find article %d" article))
7147           nil)
7148       (let ((pt (gnus-data-pos data)))
7149         (goto-char pt)
7150         (gnus-summary-set-article-display-arrow pt))
7151       (gnus-summary-position-point)
7152       article)))
7153
7154 ;; Walking around summary lines with displaying articles.
7155
7156 (defun gnus-summary-expand-window (&optional arg)
7157   "Make the summary buffer take up the entire Emacs frame.
7158 Given a prefix, will force an `article' buffer configuration."
7159   (interactive "P")
7160   (if arg
7161       (gnus-configure-windows 'article 'force)
7162     (gnus-configure-windows 'summary 'force)))
7163
7164 (defun gnus-summary-display-article (article &optional all-header)
7165   "Display ARTICLE in article buffer."
7166   (when (gnus-buffer-live-p gnus-article-buffer)
7167     (with-current-buffer gnus-article-buffer
7168       (set-buffer-multibyte t)))
7169   (gnus-set-global-variables)
7170   (when (gnus-buffer-live-p gnus-article-buffer)
7171     (with-current-buffer gnus-article-buffer
7172       (setq gnus-article-charset gnus-newsgroup-charset)
7173       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7174       (set-buffer-multibyte t)))
7175   (if (null article)
7176       nil
7177     (prog1
7178         (if gnus-summary-display-article-function
7179             (funcall gnus-summary-display-article-function article all-header)
7180           (gnus-article-prepare article all-header))
7181       (with-current-buffer gnus-article-buffer
7182         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7183              nil))
7184       (gnus-run-hooks 'gnus-select-article-hook)
7185       (when (and gnus-current-article
7186                  (not (zerop gnus-current-article)))
7187         (gnus-summary-goto-subject gnus-current-article))
7188       (gnus-summary-recenter)
7189       (when (and gnus-use-trees gnus-show-threads)
7190         (gnus-possibly-generate-tree article)
7191         (gnus-highlight-selected-tree article))
7192       ;; Successfully display article.
7193       (gnus-article-set-window-start
7194        (cdr (assq article gnus-newsgroup-bookmarks))))))
7195
7196 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7197   "Select the current article.
7198 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7199 non-nil, the article will be re-fetched even if it already present in
7200 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7201 be displayed."
7202   ;; Make sure we are in the summary buffer to work around bbdb bug.
7203   (unless (eq major-mode 'gnus-summary-mode)
7204     (set-buffer gnus-summary-buffer))
7205   (let ((article (or article (gnus-summary-article-number)))
7206         (all-headers (not (not all-headers))) ;Must be T or NIL.
7207         gnus-summary-display-article-function)
7208     (and (not pseudo)
7209          (gnus-summary-article-pseudo-p article)
7210          (error "This is a pseudo-article"))
7211     (save-excursion
7212       (set-buffer gnus-summary-buffer)
7213       (if (or (and gnus-single-article-buffer
7214                    (or (null gnus-current-article)
7215                        (null gnus-article-current)
7216                        (null (get-buffer gnus-article-buffer))
7217                        (not (eq article (cdr gnus-article-current)))
7218                        (not (equal (car gnus-article-current)
7219                                    gnus-newsgroup-name))))
7220               (and (not gnus-single-article-buffer)
7221                    (or (null gnus-current-article)
7222                        (not (eq gnus-current-article article))))
7223               force)
7224           ;; The requested article is different from the current article.
7225           (progn
7226             (gnus-summary-display-article article all-headers)
7227             (gnus-article-set-window-start
7228              (cdr (assq article gnus-newsgroup-bookmarks)))
7229             article)
7230         'old))))
7231
7232 (defun gnus-summary-force-verify-and-decrypt ()
7233   "Display buttons for signed/encrypted parts and verify/decrypt them."
7234   (interactive)
7235   (let ((mm-verify-option 'known)
7236         (mm-decrypt-option 'known)
7237         (gnus-article-emulate-mime t)
7238         (gnus-buttonized-mime-types (append (list "multipart/signed"
7239                                                   "multipart/encrypted")
7240                                             gnus-buttonized-mime-types)))
7241     (gnus-summary-select-article nil 'force)))
7242
7243 (defun gnus-summary-set-current-mark (&optional current-mark)
7244   "Obsolete function."
7245   nil)
7246
7247 (defun gnus-summary-next-article (&optional unread subject backward push)
7248   "Select the next article.
7249 If UNREAD, only unread articles are selected.
7250 If SUBJECT, only articles with SUBJECT are selected.
7251 If BACKWARD, the previous article is selected instead of the next."
7252   (interactive "P")
7253   (cond
7254    ;; Is there such an article?
7255    ((and (gnus-summary-search-forward unread subject backward)
7256          (or (gnus-summary-display-article (gnus-summary-article-number))
7257              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7258     (gnus-summary-position-point))
7259    ;; If not, we try the first unread, if that is wanted.
7260    ((and subject
7261          gnus-auto-select-same
7262          (gnus-summary-first-unread-article))
7263     (gnus-summary-position-point)
7264     (gnus-message 6 "Wrapped"))
7265    ;; Try to get next/previous article not displayed in this group.
7266    ((and gnus-auto-extend-newsgroup
7267          (not unread) (not subject))
7268     (gnus-summary-goto-article
7269      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7270      nil (count-lines (point-min) (point))))
7271    ;; Go to next/previous group.
7272    (t
7273     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7274       (gnus-summary-jump-to-group gnus-newsgroup-name))
7275     (let ((cmd last-command-char)
7276           (point
7277            (with-current-buffer gnus-group-buffer
7278              (point)))
7279           (group
7280            (if (eq gnus-keep-same-level 'best)
7281                (gnus-summary-best-group gnus-newsgroup-name)
7282              (gnus-summary-search-group backward gnus-keep-same-level))))
7283       ;; For some reason, the group window gets selected.  We change
7284       ;; it back.
7285       (select-window (get-buffer-window (current-buffer)))
7286       ;; Select next unread newsgroup automagically.
7287       (cond
7288        ((or (not gnus-auto-select-next)
7289             (not cmd))
7290         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7291        ((or (eq gnus-auto-select-next 'quietly)
7292             (and (eq gnus-auto-select-next 'slightly-quietly)
7293                  push)
7294             (and (eq gnus-auto-select-next 'almost-quietly)
7295                  (gnus-summary-last-article-p)))
7296         ;; Select quietly.
7297         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7298             (gnus-summary-exit)
7299           (gnus-message 7 "No more%s articles (%s)..."
7300                         (if unread " unread" "")
7301                         (if group (concat "selecting " group)
7302                           "exiting"))
7303           (gnus-summary-next-group nil group backward)))
7304        (t
7305         (when (gnus-key-press-event-p last-input-event)
7306           (gnus-summary-walk-group-buffer
7307            gnus-newsgroup-name cmd unread backward point))))))))
7308
7309 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7310   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7311                       (?\C-p (gnus-group-prev-unread-group 1))))
7312         (cursor-in-echo-area t)
7313         keve key group ended prompt)
7314     (save-excursion
7315       (set-buffer gnus-group-buffer)
7316       (goto-char start)
7317       (setq group
7318             (if (eq gnus-keep-same-level 'best)
7319                 (gnus-summary-best-group gnus-newsgroup-name)
7320               (gnus-summary-search-group backward gnus-keep-same-level))))
7321     (while (not ended)
7322       (setq prompt
7323             (format
7324              "No more%s articles%s " (if unread " unread" "")
7325              (if (and group
7326                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7327                  (format " (Type %s for %s [%s])"
7328                          (single-key-description cmd)
7329                          (gnus-group-decoded-name group)
7330                          (gnus-group-unread group))
7331                (format " (Type %s to exit %s)"
7332                        (single-key-description cmd)
7333                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7334       ;; Confirm auto selection.
7335       (setq key (car (setq keve (gnus-read-event-char prompt)))
7336             ended t)
7337       (cond
7338        ((assq key keystrokes)
7339         (let ((obuf (current-buffer)))
7340           (switch-to-buffer gnus-group-buffer)
7341           (when group
7342             (gnus-group-jump-to-group group))
7343           (eval (cadr (assq key keystrokes)))
7344           (setq group (gnus-group-group-name))
7345           (switch-to-buffer obuf))
7346         (setq ended nil))
7347        ((equal key cmd)
7348         (if (or (not group)
7349                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7350             (gnus-summary-exit)
7351           (gnus-summary-next-group nil group backward)))
7352        (t
7353         (push (cdr keve) unread-command-events))))))
7354
7355 (defun gnus-summary-next-unread-article ()
7356   "Select unread article after current one."
7357   (interactive)
7358   (gnus-summary-next-article
7359    (or (not (eq gnus-summary-goto-unread 'never))
7360        (gnus-summary-last-article-p (gnus-summary-article-number)))
7361    (and gnus-auto-select-same
7362         (gnus-summary-article-subject))))
7363
7364 (defun gnus-summary-prev-article (&optional unread subject)
7365   "Select the article after the current one.
7366 If UNREAD is non-nil, only unread articles are selected."
7367   (interactive "P")
7368   (gnus-summary-next-article unread subject t))
7369
7370 (defun gnus-summary-prev-unread-article ()
7371   "Select unread article before current one."
7372   (interactive)
7373   (gnus-summary-prev-article
7374    (or (not (eq gnus-summary-goto-unread 'never))
7375        (gnus-summary-first-article-p (gnus-summary-article-number)))
7376    (and gnus-auto-select-same
7377         (gnus-summary-article-subject))))
7378
7379 (defun gnus-summary-next-page (&optional lines circular stop)
7380   "Show next page of the selected article.
7381 If at the end of the current article, select the next article.
7382 LINES says how many lines should be scrolled up.
7383
7384 If CIRCULAR is non-nil, go to the start of the article instead of
7385 selecting the next article when reaching the end of the current
7386 article.
7387
7388 If STOP is non-nil, just stop when reaching the end of the message.
7389
7390 Also see the variable `gnus-article-skip-boring'."
7391   (interactive "P")
7392   (setq gnus-summary-buffer (current-buffer))
7393   (gnus-set-global-variables)
7394   (let ((article (gnus-summary-article-number))
7395         (article-window (get-buffer-window gnus-article-buffer t))
7396         endp)
7397     ;; If the buffer is empty, we have no article.
7398     (unless article
7399       (error "No article to select"))
7400     (gnus-configure-windows 'article)
7401     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7402         (if (and (eq gnus-summary-goto-unread 'never)
7403                  (not (gnus-summary-last-article-p article)))
7404             (gnus-summary-next-article)
7405           (gnus-summary-next-unread-article))
7406       (if (or (null gnus-current-article)
7407               (null gnus-article-current)
7408               (/= article (cdr gnus-article-current))
7409               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7410           ;; Selected subject is different from current article's.
7411           (gnus-summary-display-article article)
7412         (when article-window
7413           (gnus-eval-in-buffer-window gnus-article-buffer
7414             (setq endp (or (gnus-article-next-page lines)
7415                            (gnus-article-only-boring-p))))
7416           (when endp
7417             (cond (stop
7418                    (gnus-message 3 "End of message"))
7419                   (circular
7420                    (gnus-summary-beginning-of-article))
7421                   (lines
7422                    (gnus-message 3 "End of message"))
7423                   ((null lines)
7424                    (if (and (eq gnus-summary-goto-unread 'never)
7425                             (not (gnus-summary-last-article-p article)))
7426                        (gnus-summary-next-article)
7427                      (gnus-summary-next-unread-article))))))))
7428     (gnus-summary-recenter)
7429     (gnus-summary-position-point)))
7430
7431 (defun gnus-summary-prev-page (&optional lines move)
7432   "Show previous page of selected article.
7433 Argument LINES specifies lines to be scrolled down.
7434 If MOVE, move to the previous unread article if point is at
7435 the beginning of the buffer."
7436   (interactive "P")
7437   (let ((article (gnus-summary-article-number))
7438         (article-window (get-buffer-window gnus-article-buffer t))
7439         endp)
7440     (gnus-configure-windows 'article)
7441     (if (or (null gnus-current-article)
7442             (null gnus-article-current)
7443             (/= article (cdr gnus-article-current))
7444             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7445         ;; Selected subject is different from current article's.
7446         (gnus-summary-display-article article)
7447       (gnus-summary-recenter)
7448       (when article-window
7449         (gnus-eval-in-buffer-window gnus-article-buffer
7450           (setq endp (gnus-article-prev-page lines)))
7451         (when (and move endp)
7452           (cond (lines
7453                  (gnus-message 3 "Beginning of message"))
7454                 ((null lines)
7455                  (if (and (eq gnus-summary-goto-unread 'never)
7456                           (not (gnus-summary-first-article-p article)))
7457                      (gnus-summary-prev-article)
7458                    (gnus-summary-prev-unread-article))))))))
7459   (gnus-summary-position-point))
7460
7461 (defun gnus-summary-prev-page-or-article (&optional lines)
7462   "Show previous page of selected article.
7463 Argument LINES specifies lines to be scrolled down.
7464 If at the beginning of the article, go to the next article."
7465   (interactive "P")
7466   (gnus-summary-prev-page lines t))
7467
7468 (defun gnus-summary-scroll-up (lines)
7469   "Scroll up (or down) one line current article.
7470 Argument LINES specifies lines to be scrolled up (or down if negative)."
7471   (interactive "p")
7472   (gnus-configure-windows 'article)
7473   (gnus-summary-show-thread)
7474   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7475     (gnus-eval-in-buffer-window gnus-article-buffer
7476       (cond ((> lines 0)
7477              (when (gnus-article-next-page lines)
7478                (gnus-message 3 "End of message")))
7479             ((< lines 0)
7480              (gnus-article-prev-page (- lines))))))
7481   (gnus-summary-recenter)
7482   (gnus-summary-position-point))
7483
7484 (defun gnus-summary-scroll-down (lines)
7485   "Scroll down (or up) one line current article.
7486 Argument LINES specifies lines to be scrolled down (or up if negative)."
7487   (interactive "p")
7488   (gnus-summary-scroll-up (- lines)))
7489
7490 (defun gnus-summary-next-same-subject ()
7491   "Select next article which has the same subject as current one."
7492   (interactive)
7493   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7494
7495 (defun gnus-summary-prev-same-subject ()
7496   "Select previous article which has the same subject as current one."
7497   (interactive)
7498   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7499
7500 (defun gnus-summary-next-unread-same-subject ()
7501   "Select next unread article which has the same subject as current one."
7502   (interactive)
7503   (gnus-summary-next-article t (gnus-summary-article-subject)))
7504
7505 (defun gnus-summary-prev-unread-same-subject ()
7506   "Select previous unread article which has the same subject as current one."
7507   (interactive)
7508   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7509
7510 (defun gnus-summary-first-unread-article ()
7511   "Select the first unread article.
7512 Return nil if there are no unread articles."
7513   (interactive)
7514   (prog1
7515       (when (gnus-summary-first-subject t)
7516         (gnus-summary-show-thread)
7517         (gnus-summary-first-subject t)
7518         (gnus-summary-display-article (gnus-summary-article-number)))
7519     (gnus-summary-position-point)))
7520
7521 (defun gnus-summary-first-unread-subject ()
7522   "Place the point on the subject line of 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-position-point)))
7530
7531 (defun gnus-summary-first-unseen-subject ()
7532   "Place the point on the subject line of the first unseen article.
7533 Return nil if there are no unseen articles."
7534   (interactive)
7535   (prog1
7536       (when (gnus-summary-first-subject nil nil t)
7537         (gnus-summary-show-thread)
7538         (gnus-summary-first-subject nil nil t))
7539     (gnus-summary-position-point)))
7540
7541 (defun gnus-summary-first-unseen-or-unread-subject ()
7542   "Place the point on the subject line of the first unseen article or,
7543 if all article have been seen, on the subject line of the first unread
7544 article."
7545   (interactive)
7546   (prog1
7547       (unless (when (gnus-summary-first-subject nil nil t)
7548                 (gnus-summary-show-thread)
7549                 (gnus-summary-first-subject nil nil t))
7550         (when (gnus-summary-first-subject t)
7551           (gnus-summary-show-thread)
7552           (gnus-summary-first-subject t)))
7553     (gnus-summary-position-point)))
7554
7555 (defun gnus-summary-first-article ()
7556   "Select the first article.
7557 Return nil if there are no articles."
7558   (interactive)
7559   (prog1
7560       (when (gnus-summary-first-subject)
7561         (gnus-summary-show-thread)
7562         (gnus-summary-first-subject)
7563         (gnus-summary-display-article (gnus-summary-article-number)))
7564     (gnus-summary-position-point)))
7565
7566 (defun gnus-summary-best-unread-article (&optional arg)
7567   "Select the unread article with the highest score.
7568 If given a prefix argument, select the next unread article that has a
7569 score higher than the default score."
7570   (interactive "P")
7571   (let ((article (if arg
7572                      (gnus-summary-better-unread-subject)
7573                    (gnus-summary-best-unread-subject))))
7574     (if article
7575         (gnus-summary-goto-article article)
7576       (error "No unread articles"))))
7577
7578 (defun gnus-summary-best-unread-subject ()
7579   "Select the unread subject with the highest score."
7580   (interactive)
7581   (let ((best -1000000)
7582         (data gnus-newsgroup-data)
7583         article score)
7584     (while data
7585       (and (gnus-data-unread-p (car data))
7586            (> (setq score
7587                     (gnus-summary-article-score (gnus-data-number (car data))))
7588               best)
7589            (setq best score
7590                  article (gnus-data-number (car data))))
7591       (setq data (cdr data)))
7592     (when article
7593       (gnus-summary-goto-subject article))
7594     (gnus-summary-position-point)
7595     article))
7596
7597 (defun gnus-summary-better-unread-subject ()
7598   "Select the first unread subject that has a score over the default score."
7599   (interactive)
7600   (let ((data gnus-newsgroup-data)
7601         article score)
7602     (while (and (setq article (gnus-data-number (car data)))
7603                 (or (gnus-data-read-p (car data))
7604                     (not (> (gnus-summary-article-score article)
7605                             gnus-summary-default-score))))
7606       (setq data (cdr data)))
7607     (when article
7608       (gnus-summary-goto-subject article))
7609     (gnus-summary-position-point)
7610     article))
7611
7612 (defun gnus-summary-last-subject ()
7613   "Go to the last displayed subject line in the group."
7614   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7615     (when article
7616       (gnus-summary-goto-subject article))))
7617
7618 (defun gnus-summary-goto-article (article &optional all-headers force)
7619   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7620 If ALL-HEADERS is non-nil, no header lines are hidden.
7621 If FORCE, go to the article even if it isn't displayed.  If FORCE
7622 is a number, it is the line the article is to be displayed on."
7623   (interactive
7624    (list
7625     (completing-read
7626      "Article number or Message-ID: "
7627      (mapcar (lambda (number) (list (int-to-string number)))
7628              gnus-newsgroup-limit))
7629     current-prefix-arg
7630     t))
7631   (prog1
7632       (if (and (stringp article)
7633                (string-match "@\\|%40" article))
7634           (gnus-summary-refer-article article)
7635         (when (stringp article)
7636           (setq article (string-to-number article)))
7637         (if (gnus-summary-goto-subject article force)
7638             (gnus-summary-display-article article all-headers)
7639           (gnus-message 4 "Couldn't go to article %s" article) nil))
7640     (gnus-summary-position-point)))
7641
7642 (defun gnus-summary-goto-last-article ()
7643   "Go to the previously read article."
7644   (interactive)
7645   (prog1
7646       (when gnus-last-article
7647         (gnus-summary-goto-article gnus-last-article nil t))
7648     (gnus-summary-position-point)))
7649
7650 (defun gnus-summary-pop-article (number)
7651   "Pop one article off the history and go to the previous.
7652 NUMBER articles will be popped off."
7653   (interactive "p")
7654   (let (to)
7655     (setq gnus-newsgroup-history
7656           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7657     (if to
7658         (gnus-summary-goto-article (car to) nil t)
7659       (error "Article history empty")))
7660   (gnus-summary-position-point))
7661
7662 ;; Summary commands and functions for limiting the summary buffer.
7663
7664 (defun gnus-summary-limit-to-articles (n)
7665   "Limit the summary buffer to the next N articles.
7666 If not given a prefix, use the process marked articles instead."
7667   (interactive "P")
7668   (prog1
7669       (let ((articles (gnus-summary-work-articles n)))
7670         (setq gnus-newsgroup-processable nil)
7671         (gnus-summary-limit articles))
7672     (gnus-summary-position-point)))
7673
7674 (defun gnus-summary-pop-limit (&optional total)
7675   "Restore the previous limit.
7676 If given a prefix, remove all limits."
7677   (interactive "P")
7678   (when total
7679     (setq gnus-newsgroup-limits
7680           (list (mapcar (lambda (h) (mail-header-number h))
7681                         gnus-newsgroup-headers))))
7682   (unless gnus-newsgroup-limits
7683     (error "No limit to pop"))
7684   (prog1
7685       (gnus-summary-limit nil 'pop)
7686     (gnus-summary-position-point)))
7687
7688 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7689   "Limit the summary buffer to articles that have subjects that match a regexp.
7690 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7691   (interactive
7692    (list (read-string (if current-prefix-arg
7693                           "Exclude subject (regexp): "
7694                         "Limit to subject (regexp): "))
7695          nil current-prefix-arg))
7696   (unless header
7697     (setq header "subject"))
7698   (when (not (equal "" subject))
7699     (prog1
7700         (let ((articles (gnus-summary-find-matching
7701                          (or header "subject") subject 'all nil nil
7702                          not-matching)))
7703           (unless articles
7704             (error "Found no matches for \"%s\"" subject))
7705           (gnus-summary-limit articles))
7706       (gnus-summary-position-point))))
7707
7708 (defun gnus-summary-limit-to-author (from &optional not-matching)
7709   "Limit the summary buffer to articles that have authors that match a regexp.
7710 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7711   (interactive
7712    (list (read-string (if current-prefix-arg
7713                           "Exclude author (regexp): "
7714                         "Limit to author (regexp): "))
7715          current-prefix-arg))
7716   (gnus-summary-limit-to-subject from "from" not-matching))
7717
7718 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7719   "Limit the summary buffer to articles with the given RECIPIENT.
7720
7721 If NOT-MATCHING, exclude RECIPIENT.
7722
7723 To and Cc headers are checked.  You need to include them in
7724 `nnmail-extra-headers'."
7725   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7726   (interactive
7727    (list (read-string (format "%s recipient (regexp): "
7728                               (if current-prefix-arg "Exclude" "Limit to")))
7729          current-prefix-arg))
7730   (when (not (equal "" recipient))
7731     (prog1 (let* ((to
7732                    (if (memq 'To nnmail-extra-headers)
7733                        (gnus-summary-find-matching
7734                         (cons 'extra 'To) recipient 'all nil nil
7735                         not-matching)
7736                      (gnus-message
7737                       1 "`To' isn't present in `nnmail-extra-headers'")
7738                      (sit-for 1)
7739                      nil))
7740                   (cc
7741                    (if (memq 'Cc nnmail-extra-headers)
7742                        (gnus-summary-find-matching
7743                         (cons 'extra 'Cc) recipient 'all nil nil
7744                         not-matching)
7745                      (gnus-message
7746                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7747                      (sit-for 1)
7748                      nil))
7749                   (articles
7750                    (if not-matching
7751                        ;; We need the numbers that are in both lists:
7752                        (mapcar (lambda (a)
7753                                  (and (memq a to) a))
7754                                cc)
7755                      (nconc to cc))))
7756              (unless articles
7757                (error "Found no matches for \"%s\"" recipient))
7758              (gnus-summary-limit articles))
7759       (gnus-summary-position-point))))
7760
7761 (defun gnus-summary-limit-to-age (age &optional younger-p)
7762   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7763 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7764 articles that are younger than AGE days."
7765   (interactive
7766    (let ((younger current-prefix-arg)
7767          (days-got nil)
7768          days)
7769      (while (not days-got)
7770        (setq days (if younger
7771                       (read-string "Limit to articles younger than (in days, older when negative): ")
7772                     (read-string
7773                      "Limit to articles older than (in days, younger when negative): ")))
7774        (when (> (length days) 0)
7775          (setq days (read days)))
7776        (if (numberp days)
7777            (progn
7778              (setq days-got t)
7779              (when (< days 0)
7780                (setq younger (not younger))
7781                (setq days (* days -1))))
7782          (message "Please enter a number.")
7783          (sleep-for 1)))
7784      (list days younger)))
7785   (prog1
7786       (let ((data gnus-newsgroup-data)
7787             (cutoff (days-to-time age))
7788             articles d date is-younger)
7789         (while (setq d (pop data))
7790           (when (and (vectorp (gnus-data-header d))
7791                      (setq date (mail-header-date (gnus-data-header d))))
7792             (setq is-younger (time-less-p
7793                               (time-since (condition-case ()
7794                                               (date-to-time date)
7795                                             (error '(0 0))))
7796                               cutoff))
7797             (when (if younger-p
7798                       is-younger
7799                     (not is-younger))
7800               (push (gnus-data-number d) articles))))
7801         (gnus-summary-limit (nreverse articles)))
7802     (gnus-summary-position-point)))
7803
7804 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7805   "Limit the summary buffer to articles that match an 'extra' header."
7806   (interactive
7807    (let ((header
7808           (intern
7809            (gnus-completing-read-with-default
7810             (symbol-name (car gnus-extra-headers))
7811             (if current-prefix-arg
7812                 "Exclude extra header:"
7813               "Limit extra header:")
7814             (mapcar (lambda (x)
7815                       (cons (symbol-name x) x))
7816                     gnus-extra-headers)
7817             nil
7818             t))))
7819      (list header
7820            (read-string (format "%s header %s (regexp): "
7821                                 (if current-prefix-arg "Exclude" "Limit to")
7822                                 header))
7823            current-prefix-arg)))
7824   (when (not (equal "" regexp))
7825     (prog1
7826         (let ((articles (gnus-summary-find-matching
7827                          (cons 'extra header) regexp 'all nil nil
7828                          not-matching)))
7829           (unless articles
7830             (error "Found no matches for \"%s\"" regexp))
7831           (gnus-summary-limit articles))
7832       (gnus-summary-position-point))))
7833
7834 (defun gnus-summary-limit-to-display-predicate ()
7835   "Limit the summary buffer to the predicated in the `display' group parameter."
7836   (interactive)
7837   (unless gnus-newsgroup-display
7838     (error "There is no `display' group parameter"))
7839   (let (articles)
7840     (dolist (number gnus-newsgroup-articles)
7841       (when (funcall gnus-newsgroup-display)
7842         (push number articles)))
7843     (gnus-summary-limit articles))
7844   (gnus-summary-position-point))
7845
7846 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7847 (make-obsolete
7848  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7849
7850 (defun gnus-summary-limit-to-unread (&optional all)
7851   "Limit the summary buffer to articles that are not marked as read.
7852 If ALL is non-nil, limit strictly to unread articles."
7853   (interactive "P")
7854   (if all
7855       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7856     (gnus-summary-limit-to-marks
7857      ;; Concat all the marks that say that an article is read and have
7858      ;; those removed.
7859      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7860            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7861            gnus-low-score-mark gnus-expirable-mark
7862            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7863            gnus-duplicate-mark gnus-souped-mark)
7864      'reverse)))
7865
7866 (defun gnus-summary-limit-to-replied (&optional unreplied)
7867   "Limit the summary buffer to replied articles.
7868 If UNREPLIED (the prefix), limit to unreplied articles."
7869   (interactive "P")
7870   (if unreplied
7871       (gnus-summary-limit
7872        (gnus-set-difference gnus-newsgroup-articles
7873         gnus-newsgroup-replied))
7874     (gnus-summary-limit gnus-newsgroup-replied))
7875   (gnus-summary-position-point))
7876
7877 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7878 (make-obsolete 'gnus-summary-delete-marked-with
7879                'gnus-summary-limit-exclude-marks)
7880
7881 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7882   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7883 If REVERSE, limit the summary buffer to articles that are marked
7884 with MARKS.  MARKS can either be a string of marks or a list of marks.
7885 Returns how many articles were removed."
7886   (interactive "sMarks: ")
7887   (gnus-summary-limit-to-marks marks t))
7888
7889 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7890   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7891 If REVERSE (the prefix), limit the summary buffer to articles that are
7892 not marked with MARKS.  MARKS can either be a string of marks or a
7893 list of marks.
7894 Returns how many articles were removed."
7895   (interactive "sMarks: \nP")
7896   (prog1
7897       (let ((data gnus-newsgroup-data)
7898             (marks (if (listp marks) marks
7899                      (append marks nil))) ; Transform to list.
7900             articles)
7901         (while data
7902           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7903                   (memq (gnus-data-mark (car data)) marks))
7904             (push (gnus-data-number (car data)) articles))
7905           (setq data (cdr data)))
7906         (gnus-summary-limit articles))
7907     (gnus-summary-position-point)))
7908
7909 (defun gnus-summary-limit-to-score (score)
7910   "Limit to articles with score at or above SCORE."
7911   (interactive "NLimit to articles with score of at least: ")
7912   (let ((data gnus-newsgroup-data)
7913         articles)
7914     (while data
7915       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7916                 score)
7917         (push (gnus-data-number (car data)) articles))
7918       (setq data (cdr data)))
7919     (prog1
7920         (gnus-summary-limit articles)
7921       (gnus-summary-position-point))))
7922
7923 (defun gnus-summary-limit-to-unseen ()
7924   "Limit to unseen articles."
7925   (interactive)
7926   (prog1
7927       (gnus-summary-limit gnus-newsgroup-unseen)
7928     (gnus-summary-position-point)))
7929
7930 (defun gnus-summary-limit-include-thread (id)
7931   "Display all the hidden articles that is in the thread with ID in it.
7932 When called interactively, ID is the Message-ID of the current
7933 article."
7934   (interactive (list (mail-header-id (gnus-summary-article-header))))
7935   (let ((articles (gnus-articles-in-thread
7936                    (gnus-id-to-thread (gnus-root-id id)))))
7937     (prog1
7938         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7939       (gnus-summary-limit-include-matching-articles
7940        "subject"
7941        (regexp-quote (gnus-simplify-subject-re
7942                       (mail-header-subject (gnus-id-to-header id)))))
7943       (gnus-summary-position-point))))
7944
7945 (defun gnus-summary-limit-include-matching-articles (header regexp)
7946   "Display all the hidden articles that have HEADERs that match REGEXP."
7947   (interactive (list (read-string "Match on header: ")
7948                      (read-string "Regexp: ")))
7949   (let ((articles (gnus-find-matching-articles header regexp)))
7950     (prog1
7951         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7952       (gnus-summary-position-point))))
7953
7954 (defun gnus-summary-insert-dormant-articles ()
7955   "Insert all the dormant articles for this group into the current buffer."
7956   (interactive)
7957   (let ((gnus-verbose (max 6 gnus-verbose)))
7958     (if (not gnus-newsgroup-dormant)
7959         (gnus-message 3 "No cached articles for this group")
7960       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7961
7962 (defun gnus-summary-limit-include-dormant ()
7963   "Display all the hidden articles that are marked as dormant.
7964 Note that this command only works on a subset of the articles currently
7965 fetched for this group."
7966   (interactive)
7967   (unless gnus-newsgroup-dormant
7968     (error "There are no dormant articles in this group"))
7969   (prog1
7970       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7971     (gnus-summary-position-point)))
7972
7973 (defun gnus-summary-limit-exclude-dormant ()
7974   "Hide all dormant articles."
7975   (interactive)
7976   (prog1
7977       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7978     (gnus-summary-position-point)))
7979
7980 (defun gnus-summary-limit-exclude-childless-dormant ()
7981   "Hide all dormant articles that have no children."
7982   (interactive)
7983   (let ((data (gnus-data-list t))
7984         articles d children)
7985     ;; Find all articles that are either not dormant or have
7986     ;; children.
7987     (while (setq d (pop data))
7988       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7989                 (and (setq children
7990                            (gnus-article-children (gnus-data-number d)))
7991                      (let (found)
7992                        (while children
7993                          (when (memq (car children) articles)
7994                            (setq children nil
7995                                  found t))
7996                          (pop children))
7997                        found)))
7998         (push (gnus-data-number d) articles)))
7999     ;; Do the limiting.
8000     (prog1
8001         (gnus-summary-limit articles)
8002       (gnus-summary-position-point))))
8003
8004 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8005   "Mark all unread excluded articles as read.
8006 If ALL, mark even excluded ticked and dormants as read."
8007   (interactive "P")
8008   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8009   (let ((articles (gnus-sorted-ndifference
8010                    (sort
8011                     (mapcar (lambda (h) (mail-header-number h))
8012                             gnus-newsgroup-headers)
8013                     '<)
8014                    gnus-newsgroup-limit))
8015         article)
8016     (setq gnus-newsgroup-unreads
8017           (gnus-sorted-intersection gnus-newsgroup-unreads
8018                                     gnus-newsgroup-limit))
8019     (if all
8020         (setq gnus-newsgroup-dormant nil
8021               gnus-newsgroup-marked nil
8022               gnus-newsgroup-reads
8023               (nconc
8024                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8025                gnus-newsgroup-reads))
8026       (while (setq article (pop articles))
8027         (unless (or (memq article gnus-newsgroup-dormant)
8028                     (memq article gnus-newsgroup-marked))
8029           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8030
8031 (defun gnus-summary-limit (articles &optional pop)
8032   (if pop
8033       ;; We pop the previous limit off the stack and use that.
8034       (setq articles (car gnus-newsgroup-limits)
8035             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8036     ;; We use the new limit, so we push the old limit on the stack.
8037     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8038   ;; Set the limit.
8039   (setq gnus-newsgroup-limit articles)
8040   (let ((total (length gnus-newsgroup-data))
8041         (data (gnus-data-find-list (gnus-summary-article-number)))
8042         (gnus-summary-mark-below nil)   ; Inhibit this.
8043         found)
8044     ;; This will do all the work of generating the new summary buffer
8045     ;; according to the new limit.
8046     (gnus-summary-prepare)
8047     ;; Hide any threads, possibly.
8048     (gnus-summary-maybe-hide-threads)
8049     ;; Try to return to the article you were at, or one in the
8050     ;; neighborhood.
8051     (when data
8052       ;; We try to find some article after the current one.
8053       (while data
8054         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8055           (setq data nil
8056                 found t))
8057         (setq data (cdr data))))
8058     (unless found
8059       ;; If there is no data, that means that we were after the last
8060       ;; article.  The same goes when we can't find any articles
8061       ;; after the current one.
8062       (goto-char (point-max))
8063       (gnus-summary-find-prev))
8064     (gnus-set-mode-line 'summary)
8065     ;; We return how many articles were removed from the summary
8066     ;; buffer as a result of the new limit.
8067     (- total (length gnus-newsgroup-data))))
8068
8069 (defsubst gnus-invisible-cut-children (threads)
8070   (let ((num 0))
8071     (while threads
8072       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8073         (incf num))
8074       (pop threads))
8075     (< num 2)))
8076
8077 (defsubst gnus-cut-thread (thread)
8078   "Go forwards in the thread until we find an article that we want to display."
8079   (when (or (eq gnus-fetch-old-headers 'some)
8080             (eq gnus-fetch-old-headers 'invisible)
8081             (numberp gnus-fetch-old-headers)
8082             (eq gnus-build-sparse-threads 'some)
8083             (eq gnus-build-sparse-threads 'more))
8084     ;; Deal with old-fetched headers and sparse threads.
8085     (while (and
8086             thread
8087             (or
8088              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8089              (gnus-summary-article-ancient-p
8090               (mail-header-number (car thread))))
8091             (if (or (<= (length (cdr thread)) 1)
8092                     (eq gnus-fetch-old-headers 'invisible))
8093                 (setq gnus-newsgroup-limit
8094                       (delq (mail-header-number (car thread))
8095                             gnus-newsgroup-limit)
8096                       thread (cadr thread))
8097               (when (gnus-invisible-cut-children (cdr thread))
8098                 (let ((th (cdr thread)))
8099                   (while th
8100                     (if (memq (mail-header-number (caar th))
8101                               gnus-newsgroup-limit)
8102                         (setq thread (car th)
8103                               th nil)
8104                       (setq th (cdr th))))))))))
8105   thread)
8106
8107 (defun gnus-cut-threads (threads)
8108   "Cut off all uninteresting articles from the beginning of THREADS."
8109   (when (or (eq gnus-fetch-old-headers 'some)
8110             (eq gnus-fetch-old-headers 'invisible)
8111             (numberp gnus-fetch-old-headers)
8112             (eq gnus-build-sparse-threads 'some)
8113             (eq gnus-build-sparse-threads 'more))
8114     (let ((th threads))
8115       (while th
8116         (setcar th (gnus-cut-thread (car th)))
8117         (setq th (cdr th)))))
8118   ;; Remove nixed out threads.
8119   (delq nil threads))
8120
8121 (defun gnus-summary-initial-limit (&optional show-if-empty)
8122   "Figure out what the initial limit is supposed to be on group entry.
8123 This entails weeding out unwanted dormants, low-scored articles,
8124 fetch-old-headers verbiage, and so on."
8125   ;; Most groups have nothing to remove.
8126   (if (or gnus-inhibit-limiting
8127           (and (null gnus-newsgroup-dormant)
8128                (eq gnus-newsgroup-display 'gnus-not-ignore)
8129                (not (eq gnus-fetch-old-headers 'some))
8130                (not (numberp gnus-fetch-old-headers))
8131                (not (eq gnus-fetch-old-headers 'invisible))
8132                (null gnus-summary-expunge-below)
8133                (not (eq gnus-build-sparse-threads 'some))
8134                (not (eq gnus-build-sparse-threads 'more))
8135                (null gnus-thread-expunge-below)
8136                (not gnus-use-nocem)))
8137       ()                                ; Do nothing.
8138     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8139     (setq gnus-newsgroup-limit nil)
8140     (mapatoms
8141      (lambda (node)
8142        (unless (car (symbol-value node))
8143          ;; These threads have no parents -- they are roots.
8144          (let ((nodes (cdr (symbol-value node)))
8145                thread)
8146            (while nodes
8147              (if (and gnus-thread-expunge-below
8148                       (< (gnus-thread-total-score (car nodes))
8149                          gnus-thread-expunge-below))
8150                  (gnus-expunge-thread (pop nodes))
8151                (setq thread (pop nodes))
8152                (gnus-summary-limit-children thread))))))
8153      gnus-newsgroup-dependencies)
8154     ;; If this limitation resulted in an empty group, we might
8155     ;; pop the previous limit and use it instead.
8156     (when (and (not gnus-newsgroup-limit)
8157                show-if-empty)
8158       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8159     gnus-newsgroup-limit))
8160
8161 (defun gnus-summary-limit-children (thread)
8162   "Return 1 if this subthread is visible and 0 if it is not."
8163   ;; First we get the number of visible children to this thread.  This
8164   ;; is done by recursing down the thread using this function, so this
8165   ;; will really go down to a leaf article first, before slowly
8166   ;; working its way up towards the root.
8167   (when thread
8168     (let* ((max-lisp-eval-depth 5000)
8169            (children
8170            (if (cdr thread)
8171                (apply '+ (mapcar 'gnus-summary-limit-children
8172                                  (cdr thread)))
8173              0))
8174           (number (mail-header-number (car thread)))
8175           score)
8176       (if (and
8177            (not (memq number gnus-newsgroup-marked))
8178            (or
8179             ;; If this article is dormant and has absolutely no visible
8180             ;; children, then this article isn't visible.
8181             (and (memq number gnus-newsgroup-dormant)
8182                  (zerop children))
8183             ;; If this is "fetch-old-headered" and there is no
8184             ;; visible children, then we don't want this article.
8185             (and (or (eq gnus-fetch-old-headers 'some)
8186                      (numberp gnus-fetch-old-headers))
8187                  (gnus-summary-article-ancient-p number)
8188                  (zerop children))
8189             ;; If this is "fetch-old-headered" and `invisible', then
8190             ;; we don't want this article.
8191             (and (eq gnus-fetch-old-headers 'invisible)
8192                  (gnus-summary-article-ancient-p number))
8193             ;; If this is a sparsely inserted article with no children,
8194             ;; we don't want it.
8195             (and (eq gnus-build-sparse-threads 'some)
8196                  (gnus-summary-article-sparse-p number)
8197                  (zerop children))
8198             ;; If we use expunging, and this article is really
8199             ;; low-scored, then we don't want this article.
8200             (when (and gnus-summary-expunge-below
8201                        (< (setq score
8202                                 (or (cdr (assq number gnus-newsgroup-scored))
8203                                     gnus-summary-default-score))
8204                           gnus-summary-expunge-below))
8205               ;; We increase the expunge-tally here, but that has
8206               ;; nothing to do with the limits, really.
8207               (incf gnus-newsgroup-expunged-tally)
8208               ;; We also mark as read here, if that's wanted.
8209               (when (and gnus-summary-mark-below
8210                          (< score gnus-summary-mark-below))
8211                 (setq gnus-newsgroup-unreads
8212                       (delq number gnus-newsgroup-unreads))
8213                 (if gnus-newsgroup-auto-expire
8214                     (push number gnus-newsgroup-expirable)
8215                   (push (cons number gnus-low-score-mark)
8216                         gnus-newsgroup-reads)))
8217               t)
8218             ;; Do the `display' group parameter.
8219             (and gnus-newsgroup-display
8220                  (not (funcall gnus-newsgroup-display)))
8221             ;; Check NoCeM things.
8222             (when (and gnus-use-nocem
8223                        (gnus-nocem-unwanted-article-p
8224                         (mail-header-id (car thread))))
8225               (setq gnus-newsgroup-unreads
8226                     (delq number gnus-newsgroup-unreads))
8227               t)))
8228           ;; Nope, invisible article.
8229           0
8230         ;; Ok, this article is to be visible, so we add it to the limit
8231         ;; and return 1.
8232         (push number gnus-newsgroup-limit)
8233         1))))
8234
8235 (defun gnus-expunge-thread (thread)
8236   "Mark all articles in THREAD as read."
8237   (let* ((number (mail-header-number (car thread))))
8238     (incf gnus-newsgroup-expunged-tally)
8239     ;; We also mark as read here, if that's wanted.
8240     (setq gnus-newsgroup-unreads
8241           (delq number gnus-newsgroup-unreads))
8242     (if gnus-newsgroup-auto-expire
8243         (push number gnus-newsgroup-expirable)
8244       (push (cons number gnus-low-score-mark)
8245             gnus-newsgroup-reads)))
8246   ;; Go recursively through all subthreads.
8247   (mapcar 'gnus-expunge-thread (cdr thread)))
8248
8249 ;; Summary article oriented commands
8250
8251 (defun gnus-summary-refer-parent-article (n)
8252   "Refer parent article N times.
8253 If N is negative, go to ancestor -N instead.
8254 The difference between N and the number of articles fetched is returned."
8255   (interactive "p")
8256   (let ((skip 1)
8257         error header ref)
8258     (when (not (natnump n))
8259       (setq skip (abs n)
8260             n 1))
8261     (while (and (> n 0)
8262                 (not error))
8263       (setq header (gnus-summary-article-header))
8264       (if (and (eq (mail-header-number header)
8265                    (cdr gnus-article-current))
8266                (equal gnus-newsgroup-name
8267                       (car gnus-article-current)))
8268           ;; If we try to find the parent of the currently
8269           ;; displayed article, then we take a look at the actual
8270           ;; References header, since this is slightly more
8271           ;; reliable than the References field we got from the
8272           ;; server.
8273           (save-excursion
8274             (set-buffer gnus-original-article-buffer)
8275             (nnheader-narrow-to-headers)
8276             (unless (setq ref (message-fetch-field "references"))
8277               (when (setq ref (message-fetch-field "in-reply-to"))
8278                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8279             (widen))
8280         (setq ref
8281               ;; It's not the current article, so we take a bet on
8282               ;; the value we got from the server.
8283               (mail-header-references header)))
8284       (if (and ref
8285                (not (equal ref "")))
8286           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8287             (gnus-message 1 "Couldn't find parent"))
8288         (gnus-message 1 "No references in article %d"
8289                       (gnus-summary-article-number))
8290         (setq error t))
8291       (decf n))
8292     (gnus-summary-position-point)
8293     n))
8294
8295 (defun gnus-summary-refer-references ()
8296   "Fetch all articles mentioned in the References header.
8297 Return the number of articles fetched."
8298   (interactive)
8299   (let ((ref (mail-header-references (gnus-summary-article-header)))
8300         (current (gnus-summary-article-number))
8301         (n 0))
8302     (if (or (not ref)
8303             (equal ref ""))
8304         (error "No References in the current article")
8305       ;; For each Message-ID in the References header...
8306       (while (string-match "<[^>]*>" ref)
8307         (incf n)
8308         ;; ... fetch that article.
8309         (gnus-summary-refer-article
8310          (prog1 (match-string 0 ref)
8311            (setq ref (substring ref (match-end 0))))))
8312       (gnus-summary-goto-subject current)
8313       (gnus-summary-position-point)
8314       n)))
8315
8316 (defun gnus-summary-refer-thread (&optional limit)
8317   "Fetch all articles in the current thread.
8318 If LIMIT (the numerical prefix), fetch that many old headers instead
8319 of what's specified by the `gnus-refer-thread-limit' variable."
8320   (interactive "P")
8321   (let ((id (mail-header-id (gnus-summary-article-header)))
8322         (limit (if limit (prefix-numeric-value limit)
8323                  gnus-refer-thread-limit)))
8324     (unless (eq gnus-fetch-old-headers 'invisible)
8325       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8326       ;; Retrieve the headers and read them in.
8327       (if (eq (if (numberp limit)
8328                   (gnus-retrieve-headers
8329                    (list (min
8330                           (+ (mail-header-number
8331                               (gnus-summary-article-header))
8332                              limit)
8333                           gnus-newsgroup-end))
8334                    gnus-newsgroup-name (* limit 2))
8335                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8336                 ;; headers.
8337                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8338                                        gnus-newsgroup-name limit))
8339               'nov)
8340           (gnus-build-all-threads)
8341         (error "Can't fetch thread from back ends that don't support NOV"))
8342       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8343     (gnus-summary-limit-include-thread id)))
8344
8345 (defun gnus-summary-refer-article (message-id)
8346   "Fetch an article specified by MESSAGE-ID."
8347   (interactive "sMessage-ID: ")
8348   (when (and (stringp message-id)
8349              (not (zerop (length message-id))))
8350     (setq message-id (gnus-replace-in-string message-id " " ""))
8351     ;; Construct the correct Message-ID if necessary.
8352     ;; Suggested by tale@pawl.rpi.edu.
8353     (unless (string-match "^<" message-id)
8354       (setq message-id (concat "<" message-id)))
8355     (unless (string-match ">$" message-id)
8356       (setq message-id (concat message-id ">")))
8357     ;; People often post MIDs from URLs, so unhex it:
8358     (unless (string-match "@" message-id)
8359       (setq message-id (gnus-url-unhex-string message-id)))
8360     (let* ((header (gnus-id-to-header message-id))
8361            (sparse (and header
8362                         (gnus-summary-article-sparse-p
8363                          (mail-header-number header))
8364                         (memq (mail-header-number header)
8365                               gnus-newsgroup-limit)))
8366            number)
8367       (cond
8368        ;; If the article is present in the buffer we just go to it.
8369        ((and header
8370              (or (not (gnus-summary-article-sparse-p
8371                        (mail-header-number header)))
8372                  sparse))
8373         (prog1
8374             (gnus-summary-goto-article
8375              (mail-header-number header) nil t)
8376           (when sparse
8377             (gnus-summary-update-article (mail-header-number header)))))
8378        (t
8379         ;; We fetch the article.
8380         (catch 'found
8381           (dolist (gnus-override-method (gnus-refer-article-methods))
8382             (when (and (gnus-check-server gnus-override-method)
8383                        ;; Fetch the header,
8384                        (setq number (gnus-summary-insert-subject message-id)))
8385               ;; and display the article.
8386               (gnus-summary-select-article nil nil nil number)
8387               (throw 'found t)))
8388           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8389
8390 (defun gnus-refer-article-methods ()
8391   "Return a list of referable methods."
8392   (cond
8393    ;; No method, so we default to current and native.
8394    ((null gnus-refer-article-method)
8395     (list gnus-current-select-method gnus-select-method))
8396    ;; Current.
8397    ((eq 'current gnus-refer-article-method)
8398     (list gnus-current-select-method))
8399    ;; List of select methods.
8400    ((not (and (symbolp (car gnus-refer-article-method))
8401               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8402     (let (out)
8403       (dolist (method gnus-refer-article-method)
8404         (push (if (eq 'current method)
8405                   gnus-current-select-method
8406                 method)
8407               out))
8408       (nreverse out)))
8409    ;; One single select method.
8410    (t
8411     (list gnus-refer-article-method))))
8412
8413 (defun gnus-summary-edit-parameters ()
8414   "Edit the group parameters of the current group."
8415   (interactive)
8416   (gnus-group-edit-group gnus-newsgroup-name 'params))
8417
8418 (defun gnus-summary-customize-parameters ()
8419   "Customize the group parameters of the current group."
8420   (interactive)
8421   (gnus-group-customize gnus-newsgroup-name))
8422
8423 (defun gnus-summary-enter-digest-group (&optional force)
8424   "Enter an nndoc group based on the current article.
8425 If FORCE, force a digest interpretation.  If not, try
8426 to guess what the document format is."
8427   (interactive "P")
8428   (let ((conf gnus-current-window-configuration))
8429     (save-window-excursion
8430       (save-excursion
8431         (let (gnus-article-prepare-hook
8432               gnus-display-mime-function
8433               gnus-break-pages)
8434           (gnus-summary-select-article))))
8435     (setq gnus-current-window-configuration conf)
8436     (let* ((name (format "%s-%d"
8437                          (gnus-group-prefixed-name
8438                           gnus-newsgroup-name (list 'nndoc ""))
8439                          (with-current-buffer gnus-summary-buffer
8440                            gnus-current-article)))
8441            (ogroup gnus-newsgroup-name)
8442            (params (append (gnus-info-params (gnus-get-info ogroup))
8443                            (list (cons 'to-group ogroup))
8444                            (list (cons 'parent-group ogroup))
8445                            (list (cons 'save-article-group ogroup))))
8446            (case-fold-search t)
8447            (buf (current-buffer))
8448            dig to-address)
8449       (save-excursion
8450         (set-buffer gnus-original-article-buffer)
8451         ;; Have the digest group inherit the main mail address of
8452         ;; the parent article.
8453         (when (setq to-address (or (gnus-fetch-field "reply-to")
8454                                    (gnus-fetch-field "from")))
8455           (setq params (append
8456                         (list (cons 'to-address
8457                                     (funcall gnus-decode-encoded-word-function
8458                                              to-address))))))
8459         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8460         (insert-buffer-substring gnus-original-article-buffer)
8461         ;; Remove lines that may lead nndoc to misinterpret the
8462         ;; document type.
8463         (narrow-to-region
8464          (goto-char (point-min))
8465          (or (search-forward "\n\n" nil t) (point)))
8466         (goto-char (point-min))
8467         (delete-matching-lines "^Path:\\|^From ")
8468         (widen))
8469       (unwind-protect
8470           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8471                     (gnus-newsgroup-ephemeral-ignored-charsets
8472                      gnus-newsgroup-ignored-charsets))
8473                 (gnus-group-read-ephemeral-group
8474                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8475                               (nndoc-article-type
8476                                ,(if force 'mbox 'guess)))
8477                  t nil nil nil
8478                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8479                                                         "ADAPT")))))
8480               ;; Make all postings to this group go to the parent group.
8481               (nconc (gnus-info-params (gnus-get-info name))
8482                      params)
8483             ;; Couldn't select this doc group.
8484             (switch-to-buffer buf)
8485             (gnus-set-global-variables)
8486             (gnus-configure-windows 'summary)
8487             (gnus-message 3 "Article couldn't be entered?"))
8488         (kill-buffer dig)))))
8489
8490 (defun gnus-summary-read-document (n)
8491   "Open a new group based on the current article(s).
8492 This will allow you to read digests and other similar
8493 documents as newsgroups.
8494 Obeys the standard process/prefix convention."
8495   (interactive "P")
8496   (let* ((ogroup gnus-newsgroup-name)
8497          (params (append (gnus-info-params (gnus-get-info ogroup))
8498                          (list (cons 'to-group ogroup))))
8499          group egroup groups vgroup)
8500     (dolist (article (gnus-summary-work-articles n))
8501       (setq group (format "%s-%d" gnus-newsgroup-name article))
8502       (gnus-summary-remove-process-mark article)
8503       (when (gnus-summary-display-article article)
8504         (save-excursion
8505           (with-temp-buffer
8506             (insert-buffer-substring gnus-original-article-buffer)
8507             ;; Remove some headers that may lead nndoc to make
8508             ;; the wrong guess.
8509             (message-narrow-to-head)
8510             (goto-char (point-min))
8511             (delete-matching-lines "^Path:\\|^From ")
8512             (widen)
8513             (if (setq egroup
8514                       (gnus-group-read-ephemeral-group
8515                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8516                                      (nndoc-article-type guess))
8517                        t nil t))
8518                 (progn
8519                   ;; Make all postings to this group go to the parent group.
8520                   (nconc (gnus-info-params (gnus-get-info egroup))
8521                          params)
8522                   (push egroup groups))
8523               ;; Couldn't select this doc group.
8524               (gnus-error 3 "Article couldn't be entered"))))))
8525     ;; Now we have selected all the documents.
8526     (cond
8527      ((not groups)
8528       (error "None of the articles could be interpreted as documents"))
8529      ((gnus-group-read-ephemeral-group
8530        (setq vgroup (format
8531                      "nnvirtual:%s-%s" gnus-newsgroup-name
8532                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8533        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8534        t
8535        (cons (current-buffer) 'summary)))
8536      (t
8537       (error "Couldn't select virtual nndoc group")))))
8538
8539 (defun gnus-summary-isearch-article (&optional regexp-p)
8540   "Do incremental search forward on the current article.
8541 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8542   (interactive "P")
8543   (let* ((gnus-inhibit-treatment t)
8544          (old (gnus-summary-select-article)))
8545     (gnus-configure-windows 'article)
8546     (gnus-eval-in-buffer-window gnus-article-buffer
8547       (save-restriction
8548         (widen)
8549         (when (eq 'old old)
8550           (gnus-article-show-all-headers))
8551         (goto-char (point-min))
8552         (isearch-forward regexp-p)))))
8553
8554 (defun gnus-summary-search-article-forward (regexp &optional backward)
8555   "Search for an article containing REGEXP forward.
8556 If BACKWARD, search backward instead."
8557   (interactive
8558    (list (read-string
8559           (format "Search article %s (regexp%s): "
8560                   (if current-prefix-arg "backward" "forward")
8561                   (if gnus-last-search-regexp
8562                       (concat ", default " gnus-last-search-regexp)
8563                     "")))
8564          current-prefix-arg))
8565   (if (string-equal regexp "")
8566       (setq regexp (or gnus-last-search-regexp ""))
8567     (setq gnus-last-search-regexp regexp)
8568     (setq gnus-article-before-search gnus-current-article))
8569   ;; Intentionally set gnus-last-article.
8570   (setq gnus-last-article gnus-article-before-search)
8571   (let ((gnus-last-article gnus-last-article))
8572     (if (gnus-summary-search-article regexp backward)
8573         (gnus-summary-show-thread)
8574       (signal 'search-failed (list regexp)))))
8575
8576 (defun gnus-summary-search-article-backward (regexp)
8577   "Search for an article containing REGEXP backward."
8578   (interactive
8579    (list (read-string
8580           (format "Search article backward (regexp%s): "
8581                   (if gnus-last-search-regexp
8582                       (concat ", default " gnus-last-search-regexp)
8583                     "")))))
8584   (gnus-summary-search-article-forward regexp 'backward))
8585
8586 (eval-when-compile
8587   (defmacro gnus-summary-search-article-position-point (regexp backward)
8588     "Dehighlight the last matched text and goto the beginning position."
8589     (` (if (and gnus-summary-search-article-matched-data
8590                 (let ((text (caddr gnus-summary-search-article-matched-data))
8591                       (inhibit-read-only t)
8592                       buffer-read-only)
8593                   (delete-region
8594                    (goto-char (car gnus-summary-search-article-matched-data))
8595                    (cadr gnus-summary-search-article-matched-data))
8596                   (insert text)
8597                   (string-match (, regexp) text)))
8598            (if (, backward) (beginning-of-line) (end-of-line))
8599          (goto-char (if (, backward) (point-max) (point-min))))))
8600
8601   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8602     "Place point where X-Face image is displayed."
8603     (if (featurep 'xemacs)
8604         (` (let ((end (if (search-forward "\n\n" nil t)
8605                           (goto-char (1- (point)))
8606                         (point-min)))
8607                  extent)
8608              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8609              (unless (and (re-search-forward "^From:" end t)
8610                           (setq extent (extent-at (point)))
8611                           (extent-begin-glyph extent))
8612                (goto-char (, opoint)))))
8613       (` (let ((end (if (search-forward "\n\n" nil t)
8614                         (goto-char (1- (point)))
8615                       (point-min)))
8616                (start (or (search-backward "\n\n" nil t) (point-min))))
8617            (goto-char
8618             (or (text-property-any start end 'x-face-image t);; x-face-e21
8619                 (, opoint)))))))
8620
8621   (defmacro gnus-summary-search-article-highlight-matched-text
8622     (backward treated x-face)
8623     "Highlight matched text in the function `gnus-summary-search-article'."
8624     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8625              (end (set-marker (make-marker) (match-end 0)))
8626              (inhibit-read-only t)
8627              buffer-read-only)
8628          (unless treated
8629            (let ((,@
8630                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8631                     (mapcar
8632                      (lambda (item) (setq items (delq item items)))
8633                      '(gnus-treat-buttonize
8634                        gnus-treat-fill-article
8635                        gnus-treat-fill-long-lines
8636                        gnus-treat-emphasize
8637                        gnus-treat-highlight-headers
8638                        gnus-treat-highlight-citation
8639                        gnus-treat-highlight-signature
8640                        gnus-treat-overstrike
8641                        gnus-treat-display-x-face
8642                        gnus-treat-buttonize-head
8643                        gnus-treat-decode-article-as-default-mime-charset))
8644                     items))
8645                  (gnus-treat-display-x-face
8646                   (when (, x-face) gnus-treat-display-x-face)))
8647              (gnus-article-prepare-mime-display)))
8648          (goto-char (if (, backward) start end))
8649          (when (, x-face)
8650            (gnus-summary-search-article-highlight-goto-x-face (point)))
8651          (setq gnus-summary-search-article-matched-data
8652                (list start end (buffer-substring start end)))
8653          (unless (eq start end);; matched text has been deleted. :-<
8654            (put-text-property start end 'face
8655                               (or (find-face 'isearch)
8656                                   'secondary-selection))))))
8657   )
8658
8659 (defun gnus-summary-search-article (regexp &optional backward)
8660   "Search for an article containing REGEXP.
8661 Optional argument BACKWARD means do search for backward.
8662 `gnus-select-article-hook' is not called during the search."
8663   ;; We have to require this here to make sure that the following
8664   ;; dynamic binding isn't shadowed by autoloading.
8665   (require 'gnus-async)
8666   (require 'gnus-art)
8667   (let ((gnus-select-article-hook nil)  ;Disable hook.
8668         (gnus-article-prepare-hook nil)
8669         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8670         (gnus-use-article-prefetch nil)
8671         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8672         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8673         (gnus-visual nil)
8674         (gnus-keep-backlog nil)
8675         (gnus-break-pages nil)
8676         (gnus-summary-display-arrow nil)
8677         (gnus-updated-mode-lines nil)
8678         (gnus-auto-center-summary nil)
8679         (sum (current-buffer))
8680         (found nil)
8681         point treated)
8682     (gnus-save-hidden-threads
8683       (static-if (featurep 'xemacs)
8684           (let ((gnus-inhibit-treatment t))
8685             (setq treated (eq 'old (gnus-summary-select-article)))
8686             (when (and treated
8687                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8688                                  (window-live-p (get-buffer-window
8689                                                  gnus-article-buffer t)))))
8690               (gnus-summary-select-article nil t)
8691               (setq treated nil)))
8692         (let ((gnus-inhibit-treatment t))
8693           (setq treated (eq 'old (gnus-summary-select-article)))
8694           (when (and treated
8695                      (not
8696                       (and (gnus-buffer-live-p gnus-article-buffer)
8697                            (window-live-p (get-buffer-window
8698                                            gnus-article-buffer t))
8699                            (or (not (string-match "^\\^X-Face:" regexp))
8700                                (with-current-buffer gnus-article-buffer
8701                                  gnus-summary-search-article-matched-data)))))
8702             (gnus-summary-select-article nil t)
8703             (setq treated nil))))
8704       (set-buffer gnus-article-buffer)
8705       (widen)
8706       (if treated
8707           (progn
8708             (gnus-article-show-all-headers)
8709             (gnus-summary-search-article-position-point regexp backward))
8710         (goto-char (if backward (point-max) (point-min))))
8711       (while (not found)
8712         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8713         (if (if backward
8714                 (re-search-backward regexp nil t)
8715               (re-search-forward regexp nil t))
8716             ;; We found the regexp.
8717             (progn
8718               (gnus-summary-search-article-highlight-matched-text
8719                backward treated (string-match "^\\^X-Face:" regexp))
8720               (setq found 'found)
8721               (forward-line
8722                (/ (- 2 (window-height
8723                         (get-buffer-window gnus-article-buffer t)))
8724                   2))
8725               (set-window-start
8726                (get-buffer-window (current-buffer))
8727                (point))
8728               (set-buffer sum)
8729               (setq point (point)))
8730           ;; We didn't find it, so we go to the next article.
8731           (set-buffer sum)
8732           (setq found 'not)
8733           (while (eq found 'not)
8734             (if (not (if backward (gnus-summary-find-prev)
8735                        (gnus-summary-find-next)))
8736                 ;; No more articles.
8737                 (setq found t)
8738               ;; Select the next article and adjust point.
8739               (unless (gnus-summary-article-sparse-p
8740                        (gnus-summary-article-number))
8741                 (setq found nil)
8742                 (let ((gnus-inhibit-treatment t))
8743                   (gnus-summary-select-article))
8744                 (setq treated nil)
8745                 (set-buffer gnus-article-buffer)
8746                 (widen)
8747                 (goto-char (if backward (point-max) (point-min))))))))
8748       (gnus-message 7 ""))
8749     ;; Return whether we found the regexp.
8750     (when (eq found 'found)
8751       (goto-char point)
8752       (gnus-summary-show-thread)
8753       (gnus-summary-goto-subject gnus-current-article)
8754       (gnus-summary-position-point)
8755       t)))
8756
8757 (defun gnus-find-matching-articles (header regexp)
8758   "Return a list of all articles that match REGEXP on HEADER.
8759 This search includes all articles in the current group that Gnus has
8760 fetched headers for, whether they are displayed or not."
8761   (let ((articles nil)
8762         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8763         (case-fold-search t))
8764     (dolist (header gnus-newsgroup-headers)
8765       (when (string-match regexp (funcall func header))
8766         (push (mail-header-number header) articles)))
8767     (nreverse articles)))
8768
8769 (defun gnus-summary-find-matching (header regexp &optional backward unread
8770                                           not-case-fold not-matching)
8771   "Return a list of all articles that match REGEXP on HEADER.
8772 The search stars on the current article and goes forwards unless
8773 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8774 If UNREAD is non-nil, only unread articles will
8775 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8776 in the comparisons. If NOT-MATCHING, return a list of all articles that
8777 not match REGEXP on HEADER."
8778   (let ((case-fold-search (not not-case-fold))
8779         articles d func)
8780     (if (consp header)
8781         (if (eq (car header) 'extra)
8782             (setq func
8783                   `(lambda (h)
8784                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8785                          "")))
8786           (error "%s is an invalid header" header))
8787       (unless (fboundp (intern (concat "mail-header-" header)))
8788         (error "%s is not a valid header" header))
8789       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8790     (dolist (d (if (eq backward 'all)
8791                    gnus-newsgroup-data
8792                  (gnus-data-find-list
8793                   (gnus-summary-article-number)
8794                   (gnus-data-list backward))))
8795       (when (and (or (not unread)       ; We want all articles...
8796                      (gnus-data-unread-p d)) ; Or just unreads.
8797                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8798                  (if not-matching
8799                      (not (string-match
8800                            regexp
8801                            (funcall func (gnus-data-header d))))
8802                    (string-match regexp
8803                                  (funcall func (gnus-data-header d)))))
8804         (push (gnus-data-number d) articles))) ; Success!
8805     (nreverse articles)))
8806
8807 (defun gnus-summary-execute-command (header regexp command &optional backward)
8808   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8809 If HEADER is an empty string (or nil), the match is done on the entire
8810 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8811   (interactive
8812    (list (let ((completion-ignore-case t))
8813            (completing-read
8814             "Header name: "
8815             (mapcar (lambda (header) (list (format "%s" header)))
8816                     (append
8817                      '("Number" "Subject" "From" "Lines" "Date"
8818                        "Message-ID" "Xref" "References" "Body")
8819                      gnus-extra-headers))
8820             nil 'require-match))
8821          (read-string "Regexp: ")
8822          (read-key-sequence "Command: ")
8823          current-prefix-arg))
8824   (when (equal header "Body")
8825     (setq header ""))
8826   ;; Hidden thread subtrees must be searched as well.
8827   (gnus-summary-show-all-threads)
8828   ;; We don't want to change current point nor window configuration.
8829   (save-excursion
8830     (save-window-excursion
8831       (let (gnus-visual
8832             gnus-treat-strip-trailing-blank-lines
8833             gnus-treat-strip-leading-blank-lines
8834             gnus-treat-strip-multiple-blank-lines
8835             gnus-treat-hide-boring-headers
8836             gnus-treat-fold-newsgroups
8837             gnus-article-prepare-hook)
8838         (gnus-message 6 "Executing %s..." (key-description command))
8839         ;; We'd like to execute COMMAND interactively so as to give arguments.
8840         (gnus-execute header regexp
8841                       `(call-interactively ',(key-binding command))
8842                       backward)
8843         (gnus-message 6 "Executing %s...done" (key-description command))))))
8844
8845 (defun gnus-summary-beginning-of-article ()
8846   "Scroll the article back to the beginning."
8847   (interactive)
8848   (gnus-summary-select-article)
8849   (gnus-configure-windows 'article)
8850   (gnus-eval-in-buffer-window gnus-article-buffer
8851     (widen)
8852     (goto-char (point-min))
8853     (when gnus-break-pages
8854       (gnus-narrow-to-page))))
8855
8856 (defun gnus-summary-end-of-article ()
8857   "Scroll to the end of the article."
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-max))
8864     (recenter -3)
8865     (when gnus-break-pages
8866       (when (re-search-backward page-delimiter nil t)
8867         (narrow-to-region (match-end 0) (point-max)))
8868       (gnus-narrow-to-page))))
8869
8870 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8871   "Truncate to LEN and quote all \"(\"'s in STRING."
8872   (gnus-replace-in-string (if (and len (> (length string) len))
8873                               (substring string 0 len)
8874                             string)
8875                           "[()]" "\\\\\\&"))
8876
8877 (defun gnus-summary-print-article (&optional filename n)
8878   "Generate and print a PostScript image of the process-marked (mail) articles.
8879
8880 If used interactively, print the current article if none are
8881 process-marked.  With prefix arg, prompt the user for the name of the
8882 file to save in.
8883
8884 When used from Lisp, accept two optional args FILENAME and N.  N means
8885 to print the next N articles.  If N is negative, print the N previous
8886 articles.  If N is nil and articles have been marked with the process
8887 mark, print these instead.
8888
8889 If the optional first argument FILENAME is nil, send the image to the
8890 printer.  If FILENAME is a string, save the PostScript image in a file with
8891 that name.  If FILENAME is a number, prompt the user for the name of the file
8892 to save in."
8893   (interactive (list (ps-print-preprint current-prefix-arg)))
8894   (dolist (article (gnus-summary-work-articles n))
8895     (gnus-summary-select-article nil nil 'pseudo article)
8896     (gnus-eval-in-buffer-window gnus-article-buffer
8897       (gnus-print-buffer))
8898     (gnus-summary-remove-process-mark article))
8899   (ps-despool filename))
8900
8901 (defun gnus-print-buffer ()
8902   (let ((buffer (generate-new-buffer " *print*")))
8903     (unwind-protect
8904         (progn
8905           (copy-to-buffer buffer (point-min) (point-max))
8906           (set-buffer buffer)
8907           (gnus-remove-text-with-property 'gnus-decoration)
8908           (when (gnus-visual-p 'article-highlight 'highlight)
8909             ;; Copy-to-buffer doesn't copy overlay.  So redo
8910             ;; highlight.
8911             (let ((gnus-article-buffer buffer))
8912               (gnus-article-highlight-citation t)
8913               (gnus-article-highlight-signature)
8914               (gnus-article-emphasize)
8915               (gnus-article-delete-invisible-text)))
8916           (let ((ps-left-header
8917                  (list
8918                   (concat "("
8919                           (gnus-summary-print-truncate-and-quote
8920                            (mail-header-subject gnus-current-headers)
8921                            66) ")")
8922                   (concat "("
8923                           (gnus-summary-print-truncate-and-quote
8924                            (mail-header-from gnus-current-headers)
8925                            45) ")")))
8926                 (ps-right-header
8927                  (list
8928                   "/pagenumberstring load"
8929                   (concat "("
8930                           (mail-header-date gnus-current-headers) ")"))))
8931             (gnus-run-hooks 'gnus-ps-print-hook)
8932             (save-excursion
8933               (if window-system
8934                   (ps-spool-buffer-with-faces)
8935                 (ps-spool-buffer)))))
8936       (kill-buffer buffer))))
8937
8938 (defun gnus-summary-show-article (&optional arg)
8939   "Force redisplaying of the current article.
8940 If ARG (the prefix) is a number, show the article with the charset
8941 defined in `gnus-summary-show-article-charset-alist', or the charset
8942 input.
8943 If ARG (the prefix) is non-nil and not a number, show the raw article
8944 without any article massaging functions being run.  Normally, the key
8945 strokes are `C-u g'."
8946   (interactive "P")
8947   (cond
8948    ((numberp arg)
8949     (gnus-summary-show-article t)
8950     (let* ((gnus-newsgroup-charset
8951             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8952                 (mm-read-coding-system
8953                  "View as charset: " ;; actually it is coding system.
8954                  (with-current-buffer gnus-article-buffer
8955                    (mm-detect-coding-region (point) (point-max))))))
8956            (default-mime-charset gnus-newsgroup-charset)
8957            (gnus-newsgroup-ignored-charsets 'gnus-all))
8958       (gnus-summary-select-article nil 'force)
8959       (let ((deps gnus-newsgroup-dependencies)
8960             head header lines)
8961         (save-excursion
8962           (set-buffer gnus-original-article-buffer)
8963           (save-restriction
8964             (message-narrow-to-head)
8965             (setq head (buffer-string))
8966             (goto-char (point-min))
8967             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8968               (goto-char (point-max))
8969               (widen)
8970               (setq lines (1- (count-lines (point) (point-max))))))
8971           (with-temp-buffer
8972             (insert (format "211 %d Article retrieved.\n"
8973                             (cdr gnus-article-current)))
8974             (insert head)
8975             (if lines (insert (format "Lines: %d\n" lines)))
8976             (insert ".\n")
8977             (let ((nntp-server-buffer (current-buffer)))
8978               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8979         (gnus-data-set-header
8980          (gnus-data-find (cdr gnus-article-current))
8981          header)
8982         (gnus-summary-update-article-line
8983          (cdr gnus-article-current) header)
8984         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8985           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8986    ((not arg)
8987     ;; Select the article the normal way.
8988     (gnus-summary-select-article nil 'force))
8989    (t
8990     ;; We have to require this here to make sure that the following
8991     ;; dynamic binding isn't shadowed by autoloading.
8992     (require 'gnus-async)
8993     (require 'gnus-art)
8994     ;; Bind the article treatment functions to nil.
8995     (let ((gnus-have-all-headers t)
8996           gnus-article-prepare-hook
8997           gnus-article-decode-hook
8998           gnus-break-pages
8999           gnus-show-mime
9000           (gnus-inhibit-treatment t))
9001       (gnus-summary-select-article nil 'force))))
9002   (gnus-summary-goto-subject gnus-current-article)
9003   (gnus-summary-position-point))
9004
9005 (defun gnus-summary-show-raw-article ()
9006   "Show the raw article without any article massaging functions being run."
9007   (interactive)
9008   (gnus-summary-show-article t))
9009
9010 (defun gnus-summary-verbose-headers (&optional arg)
9011   "Toggle permanent full header display.
9012 If ARG is a positive number, turn header display on.
9013 If ARG is a negative number, turn header display off."
9014   (interactive "P")
9015   (setq gnus-show-all-headers
9016         (cond ((or (not (numberp arg))
9017                    (zerop arg))
9018                (not gnus-show-all-headers))
9019               ((natnump arg)
9020                t)))
9021   (gnus-summary-show-article))
9022
9023 (defun gnus-summary-toggle-header (&optional arg)
9024   "Show the headers if they are hidden, or hide them if they are shown.
9025 If ARG is a positive number, show the entire header.
9026 If ARG is a negative number, hide the unwanted header lines."
9027   (interactive "P")
9028   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9029                      (get-buffer-window gnus-article-buffer t))))
9030     (with-current-buffer gnus-article-buffer
9031       (widen)
9032       (article-narrow-to-head)
9033       (let* ((buffer-read-only nil)
9034              (inhibit-point-motion-hooks t)
9035              (hidden (if (numberp arg)
9036                          (>= arg 0)
9037                        (or (not (looking-at "[^ \t\n]+:"))
9038                            (gnus-article-hidden-text-p 'headers))))
9039              s e)
9040         (delete-region (point-min) (point-max))
9041         (with-current-buffer gnus-original-article-buffer
9042           (goto-char (setq s (point-min)))
9043           (setq e (if (search-forward "\n\n" nil t)
9044                       (1- (point))
9045                     (point-max))))
9046         (insert-buffer-substring gnus-original-article-buffer s e)
9047         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9048         ;; article-decode-encoded-words by default.
9049         (article-decode-encoded-words)
9050         (run-hooks 'gnus-article-decode-hook)
9051         (if hidden
9052             (let ((gnus-treat-hide-headers nil)
9053                   (gnus-treat-hide-boring-headers nil))
9054               (gnus-delete-wash-type 'headers)
9055               (gnus-treat-article 'head))
9056           (gnus-treat-article 'head))
9057         (widen)
9058         (if window
9059             (set-window-start window (goto-char (point-min))))
9060         (if gnus-break-pages
9061             (gnus-narrow-to-page)
9062           (when (gnus-visual-p 'page-marker)
9063             (let ((buffer-read-only nil))
9064               (gnus-remove-text-with-property 'gnus-prev)
9065               (gnus-remove-text-with-property 'gnus-next))))
9066         (gnus-set-mode-line 'article)))))
9067
9068 (defun gnus-summary-show-all-headers ()
9069   "Make all header lines visible."
9070   (interactive)
9071   (gnus-summary-toggle-header 1))
9072
9073 (defun gnus-summary-toggle-mime (&optional arg)
9074   "Toggle MIME processing.
9075 If ARG is a positive number, turn MIME processing on."
9076   (interactive "P")
9077   (setq gnus-show-mime
9078         (if (null arg)
9079             (not gnus-show-mime)
9080           (> (prefix-numeric-value arg) 0)))
9081   (gnus-summary-select-article t 'force))
9082
9083 (defun gnus-summary-caesar-message (&optional arg)
9084   "Caesar rotate the current article by 13.
9085 The numerical prefix specifies how many places to rotate each letter
9086 forward."
9087   (interactive "P")
9088   (gnus-summary-select-article)
9089   (let ((mail-header-separator ""))
9090     (gnus-eval-in-buffer-window gnus-article-buffer
9091       (save-restriction
9092         (widen)
9093         (let ((start (window-start))
9094               buffer-read-only)
9095           (message-caesar-buffer-body arg)
9096           (set-window-start (get-buffer-window (current-buffer)) start)))))
9097   ;; Create buttons and stuff...
9098   (gnus-treat-article nil))
9099
9100 (defun gnus-summary-idna-message (&optional arg)
9101   "Decode IDNA encoded domain names in the current articles.
9102 IDNA encoded domain names looks like `xn--bar'.  If a string
9103 remain unencoded after running this function, it is likely an
9104 invalid IDNA string (`xn--bar' is invalid).
9105
9106 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9107 installed for this command to work."
9108   (interactive "P")
9109   (if (not (and (condition-case nil (require 'idna)
9110                   (file-error))
9111                 (mm-coding-system-p 'utf-8)
9112                 (executable-find (symbol-value 'idna-program))))
9113       (gnus-message
9114        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9115     (gnus-summary-select-article)
9116     (let ((mail-header-separator ""))
9117       (gnus-eval-in-buffer-window gnus-article-buffer
9118         (save-restriction
9119           (widen)
9120           (let ((start (window-start))
9121                 buffer-read-only)
9122             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9123               (replace-match (idna-to-unicode (match-string 1))))
9124             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9125
9126 (autoload 'unmorse-region "morse"
9127   "Convert morse coded text in region to ordinary ASCII text."
9128   t)
9129
9130 (defun gnus-summary-morse-message (&optional arg)
9131   "Morse decode the current article."
9132   (interactive "P")
9133   (gnus-summary-select-article)
9134   (let ((mail-header-separator ""))
9135     (gnus-eval-in-buffer-window gnus-article-buffer
9136       (save-excursion
9137         (save-restriction
9138           (widen)
9139           (let ((pos (window-start))
9140                 buffer-read-only)
9141             (goto-char (point-min))
9142             (when (message-goto-body)
9143               (gnus-narrow-to-body))
9144             (goto-char (point-min))
9145             (while (search-forward "·" (point-max) t)
9146               (replace-match "."))
9147             (unmorse-region (point-min) (point-max))
9148             (widen)
9149             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9150
9151 (defun gnus-summary-stop-page-breaking ()
9152   "Stop page breaking in the current article."
9153   (interactive)
9154   (gnus-summary-select-article)
9155   (gnus-eval-in-buffer-window gnus-article-buffer
9156     (widen)
9157     (when (gnus-visual-p 'page-marker)
9158       (let ((buffer-read-only nil))
9159         (gnus-remove-text-with-property 'gnus-prev)
9160         (gnus-remove-text-with-property 'gnus-next))
9161       (setq gnus-page-broken nil))))
9162
9163 (defun gnus-summary-move-article (&optional n to-newsgroup
9164                                             select-method action)
9165   "Move the current article to a different newsgroup.
9166 If N is a positive number, move the N next articles.
9167 If N is a negative number, move the N previous articles.
9168 If N is nil and any articles have been marked with the process mark,
9169 move those articles instead.
9170 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9171 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9172 re-spool using this method.
9173
9174 When called interactively with TO-NEWSGROUP being nil, the value of
9175 the variable `gnus-move-split-methods' is used for finding a default
9176 for the target newsgroup.
9177
9178 For this function to work, both the current newsgroup and the
9179 newsgroup that you want to move to have to support the `request-move'
9180 and `request-accept' functions.
9181
9182 ACTION can be either `move' (the default), `crosspost' or `copy'."
9183   (interactive "P")
9184   (unless action
9185     (setq action 'move))
9186   ;; Check whether the source group supports the required functions.
9187   (cond ((and (eq action 'move)
9188               (not (gnus-check-backend-function
9189                     'request-move-article gnus-newsgroup-name)))
9190          (error "The current group does not support article moving"))
9191         ((and (eq action 'crosspost)
9192               (not (gnus-check-backend-function
9193                     'request-replace-article gnus-newsgroup-name)))
9194          (error "The current group does not support article editing")))
9195   (let ((articles (gnus-summary-work-articles n))
9196         (prefix (if (gnus-check-backend-function
9197                      'request-move-article gnus-newsgroup-name)
9198                     (funcall gnus-move-group-prefix-function
9199                              gnus-newsgroup-name)
9200                   ""))
9201         (names '((move "Move" "Moving")
9202                  (copy "Copy" "Copying")
9203                  (crosspost "Crosspost" "Crossposting")))
9204         (copy-buf (save-excursion
9205                     (nnheader-set-temp-buffer " *copy article*")))
9206         art-group to-method new-xref article to-groups articles-to-update-marks)
9207     (unless (assq action names)
9208       (error "Unknown action %s" action))
9209     ;; Read the newsgroup name.
9210     (when (and (not to-newsgroup)
9211                (not select-method))
9212       (if (and gnus-move-split-methods
9213                (not
9214                 (and (memq gnus-current-article articles)
9215                      (gnus-buffer-live-p gnus-original-article-buffer))))
9216           ;; When `gnus-move-split-methods' is non-nil, we have to
9217           ;; select an article to give `gnus-read-move-group-name' an
9218           ;; opportunity to suggest an appropriate default.  However,
9219           ;; we needn't render or mark the article.
9220           (let ((gnus-display-mime-function nil)
9221                 (gnus-article-prepare-hook nil)
9222                 (gnus-mark-article-hook nil))
9223             (gnus-summary-select-article nil nil nil (car articles))))
9224       (setq to-newsgroup
9225             (gnus-read-move-group-name
9226              (cadr (assq action names))
9227              (symbol-value (intern (format "gnus-current-%s-group" action)))
9228              articles prefix))
9229       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9230     (setq to-method (or select-method
9231                         (gnus-server-to-method
9232                          (gnus-group-method to-newsgroup))))
9233     ;; Check the method we are to move this article to...
9234     (unless (gnus-check-backend-function
9235              'request-accept-article (car to-method))
9236       (error "%s does not support article copying" (car to-method)))
9237     (unless (gnus-check-server to-method)
9238       (error "Can't open server %s" (car to-method)))
9239     (gnus-message 6 "%s to %s: %s..."
9240                   (caddr (assq action names))
9241                   (or (car select-method) to-newsgroup) articles)
9242     (while articles
9243       (setq article (pop articles))
9244       (setq
9245        art-group
9246        (cond
9247         ;; Move the article.
9248         ((eq action 'move)
9249          ;; Remove this article from future suppression.
9250          (gnus-dup-unsuppress-article article)
9251          (let* ((from-method (gnus-find-method-for-group
9252                               gnus-newsgroup-name))
9253                 (to-method (gnus-find-method-for-group
9254                             to-newsgroup))
9255                 (move-is-internal (gnus-method-equal from-method to-method)))
9256          (gnus-request-move-article
9257           article                       ; Article to move
9258           gnus-newsgroup-name           ; From newsgroup
9259           (nth 1 (gnus-find-method-for-group
9260                   gnus-newsgroup-name)) ; Server
9261           (list 'gnus-request-accept-article
9262                 to-newsgroup (list 'quote select-method)
9263                 (not articles) t)       ; Accept form
9264           (not articles)                ; Only save nov last time
9265           move-is-internal)))           ; is this move internal?
9266         ;; Copy the article.
9267         ((eq action 'copy)
9268          (save-excursion
9269            (set-buffer copy-buf)
9270            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9271              (save-restriction
9272                (nnheader-narrow-to-headers)
9273                (dolist (hdr gnus-copy-article-ignored-headers)
9274                  (message-remove-header hdr t)))
9275              (gnus-request-accept-article
9276               to-newsgroup select-method (not articles) t))))
9277         ;; Crosspost the article.
9278         ((eq action 'crosspost)
9279          (let ((xref (message-tokenize-header
9280                       (mail-header-xref (gnus-summary-article-header article))
9281                       " ")))
9282            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9283                                   ":" (number-to-string article)))
9284            (unless xref
9285              (setq xref (list (system-name))))
9286            (setq new-xref
9287                  (concat
9288                   (mapconcat 'identity
9289                              (delete "Xref:" (delete new-xref xref))
9290                              " ")
9291                   " " new-xref))
9292            (save-excursion
9293              (set-buffer copy-buf)
9294              ;; First put the article in the destination group.
9295              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9296              (when (consp (setq art-group
9297                                 (gnus-request-accept-article
9298                                  to-newsgroup select-method (not articles))))
9299                (setq new-xref (concat new-xref " " (car art-group)
9300                                       ":"
9301                                       (number-to-string (cdr art-group))))
9302                ;; Now we have the new Xrefs header, so we insert
9303                ;; it and replace the new article.
9304                (nnheader-replace-header "Xref" new-xref)
9305                (gnus-request-replace-article
9306                 (cdr art-group) to-newsgroup (current-buffer))
9307                art-group))))))
9308       (cond
9309        ((not art-group)
9310         (gnus-message 1 "Couldn't %s article %s: %s"
9311                       (cadr (assq action names)) article
9312                       (nnheader-get-report (car to-method))))
9313        ((eq art-group 'junk)
9314         (when (eq action 'move)
9315           (gnus-summary-mark-article article gnus-canceled-mark)
9316           (gnus-message 4 "Deleted article %s" article)
9317           ;; run the delete hook
9318           (run-hook-with-args 'gnus-summary-article-delete-hook
9319                               action
9320                               (gnus-data-header
9321                                (assoc article (gnus-data-list nil)))
9322                               gnus-newsgroup-name nil
9323                               select-method)))
9324        (t
9325         (let* ((pto-group (gnus-group-prefixed-name
9326                            (car art-group) to-method))
9327                (info (gnus-get-info pto-group))
9328                (to-group (gnus-info-group info))
9329                to-marks)
9330           ;; Update the group that has been moved to.
9331           (when (and info
9332                      (memq action '(move copy)))
9333             (unless (member to-group to-groups)
9334               (push to-group to-groups))
9335
9336             (unless (memq article gnus-newsgroup-unreads)
9337               (push 'read to-marks)
9338               (gnus-info-set-read
9339                info (gnus-add-to-range (gnus-info-read info)
9340                                        (list (cdr art-group)))))
9341
9342             ;; See whether the article is to be put in the cache.
9343             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9344                              gnus-article-mark-lists
9345                            (delete '(expirable . expire)
9346                                    (copy-sequence gnus-article-mark-lists))))
9347                   (to-article (cdr art-group)))
9348
9349               ;; Enter the article into the cache in the new group,
9350               ;; if that is required.
9351               (when gnus-use-cache
9352                 (gnus-cache-possibly-enter-article
9353                  to-group to-article
9354                  (let ((header (copy-sequence
9355                                 (gnus-summary-article-header article))))
9356                    (mail-header-set-number header to-article)
9357                    header)
9358                  (memq article gnus-newsgroup-marked)
9359                  (memq article gnus-newsgroup-dormant)
9360                  (memq article gnus-newsgroup-unreads)))
9361
9362               (when gnus-preserve-marks
9363                 ;; Copy any marks over to the new group.
9364                 (when (and (equal to-group gnus-newsgroup-name)
9365                            (not (memq article gnus-newsgroup-unreads)))
9366                   ;; Mark this article as read in this group.
9367                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9368                   (setcdr (gnus-active to-group) to-article)
9369                   (setcdr gnus-newsgroup-active to-article))
9370
9371                 (while marks
9372                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9373                     (when (memq article (symbol-value
9374                                          (intern (format "gnus-newsgroup-%s"
9375                                                          (caar marks)))))
9376                       (push (cdar marks) to-marks)
9377                       ;; If the other group is the same as this group,
9378                       ;; then we have to add the mark to the list.
9379                       (when (equal to-group gnus-newsgroup-name)
9380                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9381                              (cons to-article
9382                                    (symbol-value
9383                                     (intern (format "gnus-newsgroup-%s"
9384                                                     (caar marks)))))))
9385                       ;; Copy the marks to other group.
9386                       (gnus-add-marked-articles
9387                        to-group (cdar marks) (list to-article) info)))
9388                   (setq marks (cdr marks)))
9389
9390                 (gnus-request-set-mark
9391                  to-group (list (list (list to-article) 'add to-marks))))
9392
9393               (gnus-dribble-enter
9394                (concat "(gnus-group-set-info '"
9395                        (gnus-prin1-to-string (gnus-get-info to-group))
9396                        ")"))))
9397
9398           ;; Update the Xref header in this article to point to
9399           ;; the new crossposted article we have just created.
9400           (when (eq action 'crosspost)
9401             (save-excursion
9402               (set-buffer copy-buf)
9403               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9404               (nnheader-replace-header "Xref" new-xref)
9405               (gnus-request-replace-article
9406                article gnus-newsgroup-name (current-buffer))))
9407
9408           ;; run the move/copy/crosspost/respool hook
9409           (run-hook-with-args 'gnus-summary-article-move-hook
9410                               action
9411                               (gnus-data-header
9412                                (assoc article (gnus-data-list nil)))
9413                               gnus-newsgroup-name
9414                               to-newsgroup
9415                               select-method))
9416
9417         ;;;!!!Why is this necessary?
9418         (set-buffer gnus-summary-buffer)
9419         
9420         (gnus-summary-goto-subject article)
9421         (when (eq action 'move)
9422           (gnus-summary-mark-article article gnus-canceled-mark))))
9423       (push article articles-to-update-marks))
9424
9425     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9426     ;; Re-activate all groups that have been moved to.
9427     (save-excursion
9428       (set-buffer gnus-group-buffer)
9429       (let ((gnus-group-marked to-groups))
9430         (gnus-group-get-new-news-this-group nil t)))
9431     
9432     (gnus-kill-buffer copy-buf)
9433     (gnus-summary-position-point)
9434     (gnus-set-mode-line 'summary)))
9435
9436 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9437   "Copy the current article to some other group.
9438 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9439 When called interactively, if TO-NEWSGROUP is nil, use the value of
9440 the variable `gnus-move-split-methods' for finding a default target
9441 newsgroup.
9442 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9443 re-spool using this method."
9444   (interactive "P")
9445   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9446
9447 (defun gnus-summary-crosspost-article (&optional n)
9448   "Crosspost the current article to some other group."
9449   (interactive "P")
9450   (gnus-summary-move-article n nil nil 'crosspost))
9451
9452 (defcustom gnus-summary-respool-default-method nil
9453   "Default method type for respooling an article.
9454 If nil, use to the current newsgroup method."
9455   :type 'symbol
9456   :group 'gnus-summary-mail)
9457
9458 (defcustom gnus-summary-display-while-building nil
9459   "If non-nil, show and update the summary buffer as it's being built.
9460 If the value is t, update the buffer after every line is inserted.  If
9461 the value is an integer (N), update the display every N lines."
9462   :version "22.1"
9463   :group 'gnus-thread
9464   :type '(choice (const :tag "off" nil)
9465                  number
9466                  (const :tag "frequently" t)))
9467
9468 (defun gnus-summary-respool-article (&optional n method)
9469   "Respool the current article.
9470 The article will be squeezed through the mail spooling process again,
9471 which means that it will be put in some mail newsgroup or other
9472 depending on `nnmail-split-methods'.
9473 If N is a positive number, respool the N next articles.
9474 If N is a negative number, respool the N previous articles.
9475 If N is nil and any articles have been marked with the process mark,
9476 respool those articles instead.
9477
9478 Respooling can be done both from mail groups and \"real\" newsgroups.
9479 In the former case, the articles in question will be moved from the
9480 current group into whatever groups they are destined to.  In the
9481 latter case, they will be copied into the relevant groups."
9482   (interactive
9483    (list current-prefix-arg
9484          (let* ((methods (gnus-methods-using 'respool))
9485                 (methname
9486                  (symbol-name (or gnus-summary-respool-default-method
9487                                   (car (gnus-find-method-for-group
9488                                         gnus-newsgroup-name)))))
9489                 (method
9490                  (gnus-completing-read-with-default
9491                   methname "What backend do you want to use when respooling?"
9492                   methods nil t nil 'gnus-mail-method-history))
9493                 ms)
9494            (cond
9495             ((zerop (length (setq ms (gnus-servers-using-backend
9496                                       (intern method)))))
9497              (list (intern method) ""))
9498             ((= 1 (length ms))
9499              (car ms))
9500             (t
9501              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9502                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9503                            ms-alist))))))))
9504   (unless method
9505     (error "No method given for respooling"))
9506   (if (assoc (symbol-name
9507               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9508              (gnus-methods-using 'respool))
9509       (gnus-summary-move-article n nil method)
9510     (gnus-summary-copy-article n nil method)))
9511
9512 (defun gnus-summary-import-article (file &optional edit)
9513   "Import an arbitrary file into a mail newsgroup."
9514   (interactive "fImport file: \nP")
9515   (let ((group gnus-newsgroup-name)
9516         (now (current-time))
9517         atts lines group-art)
9518     (unless (gnus-check-backend-function 'request-accept-article group)
9519       (error "%s does not support article importing" group))
9520     (or (file-readable-p file)
9521         (not (file-regular-p file))
9522         (error "Can't read %s" file))
9523     (save-excursion
9524       (set-buffer (gnus-get-buffer-create " *import file*"))
9525       (erase-buffer)
9526       (nnheader-insert-file-contents file)
9527       (goto-char (point-min))
9528       (if (nnheader-article-p)
9529           (save-restriction
9530             (goto-char (point-min))
9531             (search-forward "\n\n" nil t)
9532             (narrow-to-region (point-min) (1- (point)))
9533             (goto-char (point-min))
9534             (unless (re-search-forward "^date:" nil t)
9535               (goto-char (point-max))
9536               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9537         ;; This doesn't look like an article, so we fudge some headers.
9538         (setq atts (file-attributes file)
9539               lines (count-lines (point-min) (point-max)))
9540         (insert "From: " (read-string "From: ") "\n"
9541                 "Subject: " (read-string "Subject: ") "\n"
9542                 "Date: " (message-make-date (nth 5 atts)) "\n"
9543                 "Message-ID: " (message-make-message-id) "\n"
9544                 "Lines: " (int-to-string lines) "\n"
9545                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9546       (setq group-art (gnus-request-accept-article group nil t))
9547       (kill-buffer (current-buffer)))
9548     (setq gnus-newsgroup-active (gnus-activate-group group))
9549     (forward-line 1)
9550     (gnus-summary-goto-article (cdr group-art) nil t)
9551     (when edit
9552       (gnus-summary-edit-article))))
9553
9554 (defun gnus-summary-create-article ()
9555   "Create an article in a mail newsgroup."
9556   (interactive)
9557   (let ((group gnus-newsgroup-name)
9558         (now (current-time))
9559         group-art)
9560     (unless (gnus-check-backend-function 'request-accept-article group)
9561       (error "%s does not support article importing" group))
9562     (save-excursion
9563       (set-buffer (gnus-get-buffer-create " *import file*"))
9564       (erase-buffer)
9565       (goto-char (point-min))
9566       ;; This doesn't look like an article, so we fudge some headers.
9567       (insert "From: " (read-string "From: ") "\n"
9568               "Subject: " (read-string "Subject: ") "\n"
9569               "Date: " (message-make-date now) "\n"
9570               "Message-ID: " (message-make-message-id) "\n")
9571       (setq group-art (gnus-request-accept-article group nil t))
9572       (kill-buffer (current-buffer)))
9573     (setq gnus-newsgroup-active (gnus-activate-group group))
9574     (forward-line 1)
9575     (gnus-summary-goto-article (cdr group-art) nil t)
9576     (gnus-summary-edit-article)))
9577
9578 (defun gnus-summary-article-posted-p ()
9579   "Say whether the current (mail) article is available from news as well.
9580 This will be the case if the article has both been mailed and posted."
9581   (interactive)
9582   (let ((id (mail-header-references (gnus-summary-article-header)))
9583         (gnus-override-method (car (gnus-refer-article-methods))))
9584     (if (gnus-request-head id "")
9585         (gnus-message 2 "The current message was found on %s"
9586                       gnus-override-method)
9587       (gnus-message 2 "The current message couldn't be found on %s"
9588                     gnus-override-method)
9589       nil)))
9590
9591 (defun gnus-summary-expire-articles (&optional now)
9592   "Expire all articles that are marked as expirable in the current group."
9593   (interactive)
9594   (when (and (not gnus-group-is-exiting-without-update-p)
9595              (gnus-check-backend-function
9596               'request-expire-articles gnus-newsgroup-name))
9597     ;; This backend supports expiry.
9598     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9599            (expirable (if total
9600                           (progn
9601                             ;; We need to update the info for
9602                             ;; this group for `gnus-list-of-read-articles'
9603                             ;; to give us the right answer.
9604                             (gnus-run-hooks 'gnus-exit-group-hook)
9605                             (gnus-summary-update-info)
9606                             (gnus-list-of-read-articles gnus-newsgroup-name))
9607                         (setq gnus-newsgroup-expirable
9608                               (sort gnus-newsgroup-expirable '<))))
9609            (expiry-wait (if now 'immediate
9610                           (gnus-group-find-parameter
9611                            gnus-newsgroup-name 'expiry-wait)))
9612            (nnmail-expiry-target
9613             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9614                 nnmail-expiry-target))
9615            es)
9616       (when expirable
9617         ;; There are expirable articles in this group, so we run them
9618         ;; through the expiry process.
9619         (gnus-message 6 "Expiring articles...")
9620         (unless (gnus-check-group gnus-newsgroup-name)
9621           (error "Can't open server for %s" gnus-newsgroup-name))
9622         ;; The list of articles that weren't expired is returned.
9623         (save-excursion
9624           (if expiry-wait
9625               (let ((nnmail-expiry-wait-function nil)
9626                     (nnmail-expiry-wait expiry-wait))
9627                 (setq es (gnus-request-expire-articles
9628                           expirable gnus-newsgroup-name)))
9629             (setq es (gnus-request-expire-articles
9630                       expirable gnus-newsgroup-name)))
9631           (unless total
9632             (setq gnus-newsgroup-expirable es))
9633           ;; We go through the old list of expirable, and mark all
9634           ;; really expired articles as nonexistent.
9635           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9636             (let ((gnus-use-cache nil))
9637               (dolist (article expirable)
9638                 (when (and (not (memq article es))
9639                            (gnus-data-find article))
9640                   (gnus-summary-mark-article article gnus-canceled-mark)
9641                   (run-hook-with-args 'gnus-summary-article-expire-hook
9642                                       'delete
9643                                       (gnus-data-header
9644                                        (assoc article (gnus-data-list nil)))
9645                                       gnus-newsgroup-name
9646                                       nil
9647                                       nil))))))
9648         (gnus-message 6 "Expiring articles...done")))))
9649
9650 (defun gnus-summary-expire-articles-now ()
9651   "Expunge all expirable articles in the current group.
9652 This means that *all* articles that are marked as expirable will be
9653 deleted forever, right now."
9654   (interactive)
9655   (or gnus-expert-user
9656       (gnus-yes-or-no-p
9657        "Are you really, really, really sure you want to delete all these messages? ")
9658       (error "Phew!"))
9659   (gnus-summary-expire-articles t))
9660
9661 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9662 (defun gnus-summary-delete-article (&optional n)
9663   "Delete the N next (mail) articles.
9664 This command actually deletes articles.  This is not a marking
9665 command.  The article will disappear forever from your life, never to
9666 return.
9667
9668 If N is negative, delete backwards.
9669 If N is nil and articles have been marked with the process mark,
9670 delete these instead.
9671
9672 If `gnus-novice-user' is non-nil you will be asked for
9673 confirmation before the articles are deleted."
9674   (interactive "P")
9675   (unless (gnus-check-backend-function 'request-expire-articles
9676                                        gnus-newsgroup-name)
9677     (error "The current newsgroup does not support article deletion"))
9678   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9679     (error "Couldn't open server"))
9680   ;; Compute the list of articles to delete.
9681   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9682         (nnmail-expiry-target 'delete)
9683         not-deleted)
9684     (if (and gnus-novice-user
9685              (not (gnus-yes-or-no-p
9686                    (format "Do you really want to delete %s forever? "
9687                            (if (> (length articles) 1)
9688                                (format "these %s articles" (length articles))
9689                              "this article")))))
9690         ()
9691       ;; Delete the articles.
9692       (setq not-deleted (gnus-request-expire-articles
9693                          articles gnus-newsgroup-name 'force))
9694       (while articles
9695         (gnus-summary-remove-process-mark (car articles))
9696         ;; The backend might not have been able to delete the article
9697         ;; after all.
9698         (unless (memq (car articles) not-deleted)
9699           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9700         (let* ((article (car articles))
9701                (ghead  (gnus-data-header
9702                                     (assoc article (gnus-data-list nil)))))
9703           (run-hook-with-args 'gnus-summary-article-delete-hook
9704                               'delete ghead gnus-newsgroup-name nil
9705                               nil))
9706         (setq articles (cdr articles)))
9707       (when not-deleted
9708         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9709     (gnus-summary-position-point)
9710     (gnus-set-mode-line 'summary)
9711     not-deleted))
9712
9713 (defun gnus-summary-edit-article (&optional force)
9714   "Edit the current article.
9715 This will have permanent effect only in mail groups.
9716 If FORCE is non-nil, allow editing of articles even in read-only
9717 groups."
9718   (interactive "P")
9719   (save-excursion
9720     (set-buffer gnus-summary-buffer)
9721     (let ((mail-parse-charset gnus-newsgroup-charset)
9722           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9723       (gnus-set-global-variables)
9724       (when (and (not force)
9725                  (gnus-group-read-only-p))
9726         (error "The current newsgroup does not support article editing"))
9727       (gnus-summary-show-article t)
9728       (gnus-article-edit-article
9729        'ignore
9730        `(lambda (no-highlight)
9731           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9732                 (message-options message-options)
9733                 (message-options-set-recipient)
9734                 (mail-parse-ignored-charsets
9735                  ',gnus-newsgroup-ignored-charsets))
9736             (gnus-summary-edit-article-done
9737              ,(or (mail-header-references gnus-current-headers) "")
9738              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9739
9740 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9741
9742 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9743                                                  no-highlight)
9744   "Make edits to the current article permanent."
9745   (interactive)
9746   (save-excursion
9747     ;; The buffer restriction contains the entire article if it exists.
9748     (when (article-goto-body)
9749       (let ((lines (count-lines (point) (point-max)))
9750             (length (- (point-max) (point)))
9751             (case-fold-search t)
9752             (body (copy-marker (point))))
9753         (goto-char (point-min))
9754         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9755           (delete-region (match-beginning 1) (match-end 1))
9756           (insert (number-to-string length)))
9757         (goto-char (point-min))
9758         (when (re-search-forward
9759                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9760           (delete-region (match-beginning 1) (match-end 1))
9761           (insert (number-to-string length)))
9762         (goto-char (point-min))
9763         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9764           (delete-region (match-beginning 1) (match-end 1))
9765           (insert (number-to-string lines))))))
9766   ;; Replace the article.
9767   (let ((buf (current-buffer)))
9768     (with-temp-buffer
9769       (insert-buffer-substring buf)
9770
9771       (if (and (not read-only)
9772                (not (gnus-request-replace-article
9773                      (cdr gnus-article-current) (car gnus-article-current)
9774                      (current-buffer) t)))
9775           (error "Couldn't replace article")
9776         ;; Update the summary buffer.
9777         (if (and references
9778                  (equal (message-tokenize-header references " ")
9779                         (message-tokenize-header
9780                          (or (message-fetch-field "references") "") " ")))
9781             ;; We only have to update this line.
9782             (save-excursion
9783               (save-restriction
9784                 (message-narrow-to-head)
9785                 (let ((head (buffer-string))
9786                       header)
9787                   (with-temp-buffer
9788                     (insert (format "211 %d Article retrieved.\n"
9789                                     (cdr gnus-article-current)))
9790                     (insert head)
9791                     (insert ".\n")
9792                     (let ((nntp-server-buffer (current-buffer)))
9793                       (setq header (car (gnus-get-newsgroup-headers
9794                                          nil t))))
9795                     (save-excursion
9796                       (set-buffer gnus-summary-buffer)
9797                       (gnus-data-set-header
9798                        (gnus-data-find (cdr gnus-article-current))
9799                        header)
9800                       (gnus-summary-update-article-line
9801                        (cdr gnus-article-current) header)
9802                       (if (gnus-summary-goto-subject
9803                            (cdr gnus-article-current) nil t)
9804                           (gnus-summary-update-secondary-mark
9805                            (cdr gnus-article-current))))))))
9806           ;; Update threads.
9807           (set-buffer (or buffer gnus-summary-buffer))
9808           (gnus-summary-update-article (cdr gnus-article-current))
9809           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9810               (gnus-summary-update-secondary-mark
9811                (cdr gnus-article-current))))
9812         ;; Prettify the article buffer again.
9813         (unless no-highlight
9814           (save-excursion
9815             (set-buffer gnus-article-buffer)
9816             ;;;!!! Fix this -- article should be rehighlighted.
9817             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9818             (set-buffer gnus-original-article-buffer)
9819             (gnus-request-article
9820              (cdr gnus-article-current)
9821              (car gnus-article-current) (current-buffer))))
9822         ;; Prettify the summary buffer line.
9823         (when (gnus-visual-p 'summary-highlight 'highlight)
9824           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9825
9826 (defun gnus-summary-edit-wash (key)
9827   "Perform editing command KEY in the article buffer."
9828   (interactive
9829    (list
9830     (progn
9831       (message "%s" (concat (this-command-keys) "- "))
9832       (read-char))))
9833   (message "")
9834   (gnus-summary-edit-article)
9835   (execute-kbd-macro (concat (this-command-keys) key))
9836   (gnus-article-edit-done))
9837
9838 ;;; Respooling
9839
9840 (defun gnus-summary-respool-query (&optional silent trace)
9841   "Query where the respool algorithm would put this article."
9842   (interactive)
9843   (let (gnus-mark-article-hook)
9844     (gnus-summary-select-article)
9845     (save-excursion
9846       (set-buffer gnus-original-article-buffer)
9847       (let ((groups (nnmail-article-group 'identity trace)))
9848         (unless silent
9849           (if groups
9850               (message "This message would go to %s"
9851                        (mapconcat 'car groups ", "))
9852             (message "This message would go to no groups"))
9853           groups)))))
9854
9855 (defun gnus-summary-respool-trace ()
9856   "Trace where the respool algorithm would put this article.
9857 Display a buffer showing all fancy splitting patterns which matched."
9858   (interactive)
9859   (gnus-summary-respool-query nil t))
9860
9861 ;; Summary marking commands.
9862
9863 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9864   "Mark articles which has the same subject as read, and then select the next.
9865 If UNMARK is positive, remove any kind of mark.
9866 If UNMARK is negative, tick articles."
9867   (interactive "P")
9868   (when unmark
9869     (setq unmark (prefix-numeric-value unmark)))
9870   (let ((count
9871          (gnus-summary-mark-same-subject
9872           (gnus-summary-article-subject) unmark)))
9873     ;; Select next unread article.  If auto-select-same mode, should
9874     ;; select the first unread article.
9875     (gnus-summary-next-article t (and gnus-auto-select-same
9876                                       (gnus-summary-article-subject)))
9877     (gnus-message 7 "%d article%s marked as %s"
9878                   count (if (= count 1) " is" "s are")
9879                   (if unmark "unread" "read"))))
9880
9881 (defun gnus-summary-kill-same-subject (&optional unmark)
9882   "Mark articles which has the same subject as read.
9883 If UNMARK is positive, remove any kind of mark.
9884 If UNMARK is negative, tick articles."
9885   (interactive "P")
9886   (when unmark
9887     (setq unmark (prefix-numeric-value unmark)))
9888   (let ((count
9889          (gnus-summary-mark-same-subject
9890           (gnus-summary-article-subject) unmark)))
9891     ;; If marked as read, go to next unread subject.
9892     (when (null unmark)
9893       ;; Go to next unread subject.
9894       (gnus-summary-next-subject 1 t))
9895     (gnus-message 7 "%d articles are marked as %s"
9896                   count (if unmark "unread" "read"))))
9897
9898 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9899   "Mark articles with same SUBJECT as read, and return marked number.
9900 If optional argument UNMARK is positive, remove any kinds of marks.
9901 If optional argument UNMARK is negative, mark articles as unread instead."
9902   (let ((count 1))
9903     (save-excursion
9904       (cond
9905        ((null unmark)                   ; Mark as read.
9906         (while (and
9907                 (progn
9908                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9909                   (gnus-summary-show-thread) t)
9910                 (gnus-summary-find-subject subject))
9911           (setq count (1+ count))))
9912        ((> unmark 0)                    ; Tick.
9913         (while (and
9914                 (progn
9915                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9916                   (gnus-summary-show-thread) t)
9917                 (gnus-summary-find-subject subject))
9918           (setq count (1+ count))))
9919        (t                               ; Mark as unread.
9920         (while (and
9921                 (progn
9922                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9923                   (gnus-summary-show-thread) t)
9924                 (gnus-summary-find-subject subject))
9925           (setq count (1+ count)))))
9926       (gnus-set-mode-line 'summary)
9927       ;; Return the number of marked articles.
9928       count)))
9929
9930 (defun gnus-summary-mark-as-processable (n &optional unmark)
9931   "Set the process mark on the next N articles.
9932 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9933 the process mark instead.  The difference between N and the actual
9934 number of articles marked is returned."
9935   (interactive "P")
9936   (if (and (null n) (gnus-region-active-p))
9937       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9938     (setq n (prefix-numeric-value n))
9939     (let ((backward (< n 0))
9940           (n (abs n)))
9941       (while (and
9942               (> n 0)
9943               (if unmark
9944                   (gnus-summary-remove-process-mark
9945                    (gnus-summary-article-number))
9946                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9947               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9948         (setq n (1- n)))
9949       (when (/= 0 n)
9950         (gnus-message 7 "No more articles"))
9951       (gnus-summary-recenter)
9952       (gnus-summary-position-point)
9953       n)))
9954
9955 (defun gnus-summary-unmark-as-processable (n)
9956   "Remove the process mark from the next N articles.
9957 If N is negative, unmark backward instead.  The difference between N and
9958 the actual number of articles unmarked is returned."
9959   (interactive "P")
9960   (gnus-summary-mark-as-processable n t))
9961
9962 (defun gnus-summary-unmark-all-processable ()
9963   "Remove the process mark from all articles."
9964   (interactive)
9965   (save-excursion
9966     (while gnus-newsgroup-processable
9967       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9968   (gnus-summary-position-point))
9969
9970 (defun gnus-summary-add-mark (article type)
9971   "Mark ARTICLE with a mark of TYPE."
9972   (let ((vtype (car (assq type gnus-article-mark-lists)))
9973         var)
9974     (if (not vtype)
9975         (error "No such mark type: %s" type)
9976       (setq var (intern (format "gnus-newsgroup-%s" type)))
9977       (set var (cons article (symbol-value var)))
9978       (if (memq type '(processable cached replied forwarded recent saved))
9979           (gnus-summary-update-secondary-mark article)
9980         ;;; !!! This is bogus.  We should find out what primary
9981         ;;; !!! mark we want to set.
9982         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9983
9984 (defun gnus-summary-mark-as-expirable (n)
9985   "Mark N articles forward as expirable.
9986 If N is negative, mark backward instead.  The difference between N and
9987 the actual number of articles marked is returned."
9988   (interactive "p")
9989   (gnus-summary-mark-forward n gnus-expirable-mark))
9990
9991 (defun gnus-summary-mark-as-spam (n)
9992   "Mark N articles forward as spam.
9993 If N is negative, mark backward instead.  The difference between N and
9994 the actual number of articles marked is returned."
9995   (interactive "p")
9996   (gnus-summary-mark-forward n gnus-spam-mark))
9997
9998 (defun gnus-summary-mark-article-as-replied (article)
9999   "Mark ARTICLE as replied to and update the summary line.
10000 ARTICLE can also be a list of articles."
10001   (interactive (list (gnus-summary-article-number)))
10002   (let ((articles (if (listp article) article (list article))))
10003     (dolist (article articles)
10004       (unless (numberp article)
10005         (error "%s is not a number" article))
10006       (push article gnus-newsgroup-replied)
10007       (let ((buffer-read-only nil))
10008         (when (gnus-summary-goto-subject article nil t)
10009           (gnus-summary-update-secondary-mark article))))))
10010
10011 (defun gnus-summary-mark-article-as-forwarded (article)
10012   "Mark ARTICLE as forwarded and update the summary line.
10013 ARTICLE can also be a list of articles."
10014   (let ((articles (if (listp article) article (list article))))
10015     (dolist (article articles)
10016       (push article gnus-newsgroup-forwarded)
10017       (let ((buffer-read-only nil))
10018         (when (gnus-summary-goto-subject article nil t)
10019           (gnus-summary-update-secondary-mark article))))))
10020
10021 (defun gnus-summary-set-bookmark (article)
10022   "Set a bookmark in current article."
10023   (interactive (list (gnus-summary-article-number)))
10024   (when (or (not (get-buffer gnus-article-buffer))
10025             (not gnus-current-article)
10026             (not gnus-article-current)
10027             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10028     (error "No current article selected"))
10029   ;; Remove old bookmark, if one exists.
10030   (gnus-pull article gnus-newsgroup-bookmarks)
10031   ;; Set the new bookmark, which is on the form
10032   ;; (article-number . line-number-in-body).
10033   (push
10034    (cons article
10035          (with-current-buffer gnus-article-buffer
10036            (count-lines
10037             (min (point)
10038                  (save-excursion
10039                    (article-goto-body)
10040                    (point)))
10041             (point))))
10042    gnus-newsgroup-bookmarks)
10043   (gnus-message 6 "A bookmark has been added to the current article."))
10044
10045 (defun gnus-summary-remove-bookmark (article)
10046   "Remove the bookmark from the current article."
10047   (interactive (list (gnus-summary-article-number)))
10048   ;; Remove old bookmark, if one exists.
10049   (if (not (assq article gnus-newsgroup-bookmarks))
10050       (gnus-message 6 "No bookmark in current article.")
10051     (gnus-pull article gnus-newsgroup-bookmarks)
10052     (gnus-message 6 "Removed bookmark.")))
10053
10054 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10055 (defun gnus-summary-mark-as-dormant (n)
10056   "Mark N articles forward as dormant.
10057 If N is negative, mark backward instead.  The difference between N and
10058 the actual number of articles marked is returned."
10059   (interactive "p")
10060   (gnus-summary-mark-forward n gnus-dormant-mark))
10061
10062 (defun gnus-summary-set-process-mark (article)
10063   "Set the process mark on ARTICLE and update the summary line."
10064   (setq gnus-newsgroup-processable
10065         (cons article
10066               (delq article gnus-newsgroup-processable)))
10067   (when (gnus-summary-goto-subject article)
10068     (gnus-summary-show-thread)
10069     (gnus-summary-goto-subject article)
10070     (gnus-summary-update-secondary-mark article)))
10071
10072 (defun gnus-summary-remove-process-mark (&rest articles)
10073   "Remove the process mark from ARTICLES and update the summary line."
10074   (dolist (article articles)
10075     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10076     (when (gnus-summary-goto-subject article)
10077       (gnus-summary-show-thread)
10078       (gnus-summary-goto-subject article)
10079       (gnus-summary-update-secondary-mark article))))
10080
10081 (defun gnus-summary-set-saved-mark (article)
10082   "Set the process mark on ARTICLE and update the summary line."
10083   (push article gnus-newsgroup-saved)
10084   (when (gnus-summary-goto-subject article)
10085     (gnus-summary-update-secondary-mark article)))
10086
10087 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10088   "Mark N articles as read forwards.
10089 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10090 The difference between N and the actual number of articles marked is
10091 returned.
10092 If NO-EXPIRE, auto-expiry will be inhibited."
10093   (interactive "p")
10094   (gnus-summary-show-thread)
10095   (let ((backward (< n 0))
10096         (gnus-summary-goto-unread
10097          (and gnus-summary-goto-unread
10098               (not (eq gnus-summary-goto-unread 'never))
10099               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10100                                     gnus-ticked-mark gnus-dormant-mark)))))
10101         (n (abs n))
10102         (mark (or mark gnus-del-mark)))
10103     (while (and (> n 0)
10104                 (gnus-summary-mark-article nil mark no-expire)
10105                 (zerop (gnus-summary-next-subject
10106                         (if backward -1 1)
10107                         (and gnus-summary-goto-unread
10108                              (not (eq gnus-summary-goto-unread 'never)))
10109                         t)))
10110       (setq n (1- n)))
10111     (when (/= 0 n)
10112       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10113     (gnus-summary-recenter)
10114     (gnus-summary-position-point)
10115     (gnus-set-mode-line 'summary)
10116     n))
10117
10118 (defun gnus-summary-mark-article-as-read (mark)
10119   "Mark the current article quickly as read with MARK."
10120   (let ((article (gnus-summary-article-number)))
10121     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10122     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10123     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10124     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10125     (push (cons article mark) gnus-newsgroup-reads)
10126     ;; Possibly remove from cache, if that is used.
10127     (when gnus-use-cache
10128       (gnus-cache-enter-remove-article article))
10129     ;; Allow the backend to change the mark.
10130     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10131     ;; Check for auto-expiry.
10132     (when (and gnus-newsgroup-auto-expire
10133                (memq mark gnus-auto-expirable-marks))
10134       (setq mark gnus-expirable-mark)
10135       ;; Let the backend know about the mark change.
10136       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10137       (push article gnus-newsgroup-expirable))
10138     ;; Set the mark in the buffer.
10139     (gnus-summary-update-mark mark 'unread)
10140     t))
10141
10142 (defun gnus-summary-mark-article-as-unread (mark)
10143   "Mark the current article quickly as unread with MARK."
10144   (let* ((article (gnus-summary-article-number))
10145          (old-mark (gnus-summary-article-mark article)))
10146     ;; Allow the backend to change the mark.
10147     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10148     (if (eq mark old-mark)
10149         t
10150       (if (<= article 0)
10151           (progn
10152             (gnus-error 1 "Can't mark negative article numbers")
10153             nil)
10154         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10155         (setq gnus-newsgroup-spam-marked
10156               (delq article gnus-newsgroup-spam-marked))
10157         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10158         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10159         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10160         (cond ((= mark gnus-ticked-mark)
10161                (setq gnus-newsgroup-marked
10162                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10163                                               article)))
10164               ((= mark gnus-spam-mark)
10165                (setq gnus-newsgroup-spam-marked
10166                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10167                                               article)))
10168               ((= mark gnus-dormant-mark)
10169                (setq gnus-newsgroup-dormant
10170                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10171                                               article)))
10172               (t
10173                (setq gnus-newsgroup-unreads
10174                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10175                                               article))))
10176         (gnus-pull article gnus-newsgroup-reads)
10177
10178         ;; See whether the article is to be put in the cache.
10179         (and gnus-use-cache
10180              (vectorp (gnus-summary-article-header article))
10181              (save-excursion
10182                (gnus-cache-possibly-enter-article
10183                 gnus-newsgroup-name article
10184                 (gnus-summary-article-header article)
10185                 (= mark gnus-ticked-mark)
10186                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10187
10188         ;; Fix the mark.
10189         (gnus-summary-update-mark mark 'unread)
10190         t))))
10191
10192 (defun gnus-summary-mark-article (&optional article mark no-expire)
10193   "Mark ARTICLE with MARK.  MARK can be any character.
10194 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10195 `??' (dormant) and `?E' (expirable).
10196 If MARK is nil, then the default character `?r' is used.
10197 If ARTICLE is nil, then the article on the current line will be
10198 marked.
10199 If NO-EXPIRE, auto-expiry will be inhibited."
10200   ;; The mark might be a string.
10201   (when (stringp mark)
10202     (setq mark (aref mark 0)))
10203   ;; If no mark is given, then we check auto-expiring.
10204   (when (null mark)
10205     (setq mark gnus-del-mark))
10206   (when (and (not no-expire)
10207              gnus-newsgroup-auto-expire
10208              (memq mark gnus-auto-expirable-marks))
10209     (setq mark gnus-expirable-mark))
10210   (let ((article (or article (gnus-summary-article-number)))
10211         (old-mark (gnus-summary-article-mark article)))
10212     ;; Allow the backend to change the mark.
10213     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10214     (if (eq mark old-mark)
10215         t
10216       (unless article
10217         (error "No article on current line"))
10218       (if (not (if (or (= mark gnus-unread-mark)
10219                        (= mark gnus-ticked-mark)
10220                        (= mark gnus-spam-mark)
10221                        (= mark gnus-dormant-mark))
10222                    (gnus-mark-article-as-unread article mark)
10223                  (gnus-mark-article-as-read article mark)))
10224           t
10225         ;; See whether the article is to be put in the cache.
10226         (and gnus-use-cache
10227              (not (= mark gnus-canceled-mark))
10228              (vectorp (gnus-summary-article-header article))
10229              (save-excursion
10230                (gnus-cache-possibly-enter-article
10231                 gnus-newsgroup-name article
10232                 (gnus-summary-article-header article)
10233                 (= mark gnus-ticked-mark)
10234                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10235
10236         (when (gnus-summary-goto-subject article nil t)
10237           (let ((buffer-read-only nil))
10238             (gnus-summary-show-thread)
10239             ;; Fix the mark.
10240             (gnus-summary-update-mark mark 'unread)
10241             t))))))
10242
10243 (defun gnus-summary-update-secondary-mark (article)
10244   "Update the secondary (read, process, cache) mark."
10245   (gnus-summary-update-mark
10246    (cond ((memq article gnus-newsgroup-processable)
10247           gnus-process-mark)
10248          ((memq article gnus-newsgroup-cached)
10249           gnus-cached-mark)
10250          ((memq article gnus-newsgroup-replied)
10251           gnus-replied-mark)
10252          ((memq article gnus-newsgroup-forwarded)
10253           gnus-forwarded-mark)
10254          ((memq article gnus-newsgroup-saved)
10255           gnus-saved-mark)
10256          ((memq article gnus-newsgroup-recent)
10257           gnus-recent-mark)
10258          ((memq article gnus-newsgroup-unseen)
10259           gnus-unseen-mark)
10260          (t gnus-no-mark))
10261    'replied)
10262   (when (gnus-visual-p 'summary-highlight 'highlight)
10263     (gnus-run-hooks 'gnus-summary-update-hook))
10264   t)
10265
10266 (defun gnus-summary-update-download-mark (article)
10267   "Update the download mark."
10268   (gnus-summary-update-mark
10269    (cond ((memq article gnus-newsgroup-undownloaded)
10270           gnus-undownloaded-mark)
10271          (gnus-newsgroup-agentized
10272           gnus-downloaded-mark)
10273          (t
10274           gnus-no-mark))
10275    'download)
10276   (gnus-summary-update-line t)
10277   t)
10278
10279 (defun gnus-summary-update-mark (mark type)
10280   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10281         (buffer-read-only nil))
10282     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10283     (when forward
10284       (when (looking-at "\r")
10285         (incf forward))
10286       (when (<= (+ forward (point)) (point-max))
10287         ;; Go to the right position on the line.
10288         (goto-char (+ forward (point)))
10289         ;; Replace the old mark with the new mark.
10290         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10291         ;; Optionally update the marks by some user rule.
10292         (when (eq type 'unread)
10293           (gnus-data-set-mark
10294            (gnus-data-find (gnus-summary-article-number)) mark)
10295           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10296
10297 (defun gnus-mark-article-as-read (article &optional mark)
10298   "Enter ARTICLE in the pertinent lists and remove it from others."
10299   ;; Make the article expirable.
10300   (let ((mark (or mark gnus-del-mark)))
10301     (setq gnus-newsgroup-expirable
10302           (if (= mark gnus-expirable-mark)
10303               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10304             (delq article gnus-newsgroup-expirable)))
10305     ;; Remove from unread and marked lists.
10306     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10307     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10308     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10309     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10310     (push (cons article mark) gnus-newsgroup-reads)
10311     ;; Possibly remove from cache, if that is used.
10312     (when gnus-use-cache
10313       (gnus-cache-enter-remove-article article))
10314     t))
10315
10316 (defun gnus-mark-article-as-unread (article &optional mark)
10317   "Enter ARTICLE in the pertinent lists and remove it from others."
10318   (let ((mark (or mark gnus-ticked-mark)))
10319     (if (<= article 0)
10320         (progn
10321           (gnus-error 1 "Can't mark negative article numbers")
10322           nil)
10323       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10324             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10325             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10326             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10327             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10328
10329       ;; Unsuppress duplicates?
10330       (when gnus-suppress-duplicates
10331         (gnus-dup-unsuppress-article article))
10332
10333       (cond ((= mark gnus-ticked-mark)
10334              (setq gnus-newsgroup-marked
10335                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10336             ((= mark gnus-spam-mark)
10337              (setq gnus-newsgroup-spam-marked
10338                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10339                                             article)))
10340             ((= mark gnus-dormant-mark)
10341              (setq gnus-newsgroup-dormant
10342                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10343             (t
10344              (setq gnus-newsgroup-unreads
10345                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10346       (gnus-pull article gnus-newsgroup-reads)
10347       t)))
10348
10349 (defalias 'gnus-summary-mark-as-unread-forward
10350   'gnus-summary-tick-article-forward)
10351 (make-obsolete 'gnus-summary-mark-as-unread-forward
10352                'gnus-summary-tick-article-forward)
10353 (defun gnus-summary-tick-article-forward (n)
10354   "Tick N articles forwards.
10355 If N is negative, tick backwards instead.
10356 The difference between N and the number of articles ticked is returned."
10357   (interactive "p")
10358   (gnus-summary-mark-forward n gnus-ticked-mark))
10359
10360 (defalias 'gnus-summary-mark-as-unread-backward
10361   'gnus-summary-tick-article-backward)
10362 (make-obsolete 'gnus-summary-mark-as-unread-backward
10363                'gnus-summary-tick-article-backward)
10364 (defun gnus-summary-tick-article-backward (n)
10365   "Tick N articles backwards.
10366 The difference between N and the number of articles ticked is returned."
10367   (interactive "p")
10368   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10369
10370 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10371 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10372 (defun gnus-summary-tick-article (&optional article clear-mark)
10373   "Mark current article as unread.
10374 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10375 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10376   (interactive)
10377   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10378                                        gnus-ticked-mark)))
10379
10380 (defun gnus-summary-mark-as-read-forward (n)
10381   "Mark N articles as read forwards.
10382 If N is negative, mark backwards instead.
10383 The difference between N and the actual number of articles marked is
10384 returned."
10385   (interactive "p")
10386   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10387
10388 (defun gnus-summary-mark-as-read-backward (n)
10389   "Mark the N articles as read backwards.
10390 The difference between N and the actual number of articles marked is
10391 returned."
10392   (interactive "p")
10393   (gnus-summary-mark-forward
10394    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10395
10396 (defun gnus-summary-mark-as-read (&optional article mark)
10397   "Mark current article as read.
10398 ARTICLE specifies the article to be marked as read.
10399 MARK specifies a string to be inserted at the beginning of the line."
10400   (gnus-summary-mark-article article mark))
10401
10402 (defun gnus-summary-clear-mark-forward (n)
10403   "Clear marks from N articles forward.
10404 If N is negative, clear backward instead.
10405 The difference between N and the number of marks cleared is returned."
10406   (interactive "p")
10407   (gnus-summary-mark-forward n gnus-unread-mark))
10408
10409 (defun gnus-summary-clear-mark-backward (n)
10410   "Clear marks from N articles backward.
10411 The difference between N and the number of marks cleared is returned."
10412   (interactive "p")
10413   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10414
10415 (defun gnus-summary-mark-unread-as-read ()
10416   "Intended to be used by `gnus-summary-mark-article-hook'."
10417   (when (memq gnus-current-article gnus-newsgroup-unreads)
10418     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10419
10420 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10421   "Intended to be used by `gnus-summary-mark-article-hook'."
10422   (let ((mark (gnus-summary-article-mark)))
10423     (when (or (gnus-unread-mark-p mark)
10424               (gnus-read-mark-p mark))
10425       (gnus-summary-mark-article gnus-current-article
10426                                  (or new-mark gnus-read-mark)))))
10427
10428 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10429   "Intended to be used by `gnus-summary-mark-article-hook'."
10430   (let ((mark (gnus-summary-article-mark)))
10431     (when (or (gnus-unread-mark-p mark)
10432               (gnus-read-mark-p mark))
10433       (gnus-summary-mark-article (gnus-summary-article-number)
10434                                  (or new-mark gnus-read-mark)))))
10435
10436 (defun gnus-summary-mark-unread-as-ticked ()
10437   "Intended to be used by `gnus-summary-mark-article-hook'."
10438   (when (memq gnus-current-article gnus-newsgroup-unreads)
10439     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10440
10441 (defun gnus-summary-mark-region-as-read (point mark all)
10442   "Mark all unread articles between point and mark as read.
10443 If given a prefix, mark all articles between point and mark as read,
10444 even ticked and dormant ones."
10445   (interactive "r\nP")
10446   (save-excursion
10447     (let (article)
10448       (goto-char point)
10449       (beginning-of-line)
10450       (while (and
10451               (< (point) mark)
10452               (progn
10453                 (when (or all
10454                           (memq (setq article (gnus-summary-article-number))
10455                                 gnus-newsgroup-unreads))
10456                   (gnus-summary-mark-article article gnus-del-mark))
10457                 t)
10458               (gnus-summary-find-next))))))
10459
10460 (defun gnus-summary-mark-below (score mark)
10461   "Mark articles with score less than SCORE with MARK."
10462   (interactive "P\ncMark: ")
10463   (setq score (if score
10464                   (prefix-numeric-value score)
10465                 (or gnus-summary-default-score 0)))
10466   (save-excursion
10467     (set-buffer gnus-summary-buffer)
10468     (goto-char (point-min))
10469     (while
10470         (progn
10471           (and (< (gnus-summary-article-score) score)
10472                (gnus-summary-mark-article nil mark))
10473           (gnus-summary-find-next)))))
10474
10475 (defun gnus-summary-kill-below (&optional score)
10476   "Mark articles with score below SCORE as read."
10477   (interactive "P")
10478   (gnus-summary-mark-below score gnus-killed-mark))
10479
10480 (defun gnus-summary-clear-above (&optional score)
10481   "Clear all marks from articles with score above SCORE."
10482   (interactive "P")
10483   (gnus-summary-mark-above score gnus-unread-mark))
10484
10485 (defun gnus-summary-tick-above (&optional score)
10486   "Tick all articles with score above SCORE."
10487   (interactive "P")
10488   (gnus-summary-mark-above score gnus-ticked-mark))
10489
10490 (defun gnus-summary-mark-above (score mark)
10491   "Mark articles with score over SCORE with MARK."
10492   (interactive "P\ncMark: ")
10493   (setq score (if score
10494                   (prefix-numeric-value score)
10495                 (or gnus-summary-default-score 0)))
10496   (save-excursion
10497     (set-buffer gnus-summary-buffer)
10498     (goto-char (point-min))
10499     (while (and (progn
10500                   (when (> (gnus-summary-article-score) score)
10501                     (gnus-summary-mark-article nil mark))
10502                   t)
10503                 (gnus-summary-find-next)))))
10504
10505 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10506 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10507 (defun gnus-summary-limit-include-expunged (&optional no-error)
10508   "Display all the hidden articles that were expunged for low scores."
10509   (interactive)
10510   (let ((buffer-read-only nil))
10511     (let ((scored gnus-newsgroup-scored)
10512           headers h)
10513       (while scored
10514         (unless (gnus-summary-article-header (caar scored))
10515           (and (setq h (gnus-number-to-header (caar scored)))
10516                (< (cdar scored) gnus-summary-expunge-below)
10517                (push h headers)))
10518         (setq scored (cdr scored)))
10519       (if (not headers)
10520           (when (not no-error)
10521             (error "No expunged articles hidden"))
10522         (goto-char (point-min))
10523         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10524         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10525         (mapcar (lambda (x) (push (mail-header-number x)
10526                                   gnus-newsgroup-limit))
10527                 headers)
10528         (gnus-summary-prepare-unthreaded (nreverse headers))
10529         (goto-char (point-min))
10530         (gnus-summary-position-point)
10531         t))))
10532
10533 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10534   "Mark all unread articles in this newsgroup as read.
10535 If prefix argument ALL is non-nil, ticked and dormant articles will
10536 also be marked as read.
10537 If QUIETLY is non-nil, no questions will be asked.
10538
10539 If TO-HERE is non-nil, it should be a point in the buffer.  All
10540 articles before (after, if REVERSE is set) this point will be marked
10541 as read.
10542
10543 Note that this function will only catch up the unread article
10544 in the current summary buffer limitation.
10545
10546 The number of articles marked as read is returned."
10547   (interactive "P")
10548   (prog1
10549       (save-excursion
10550         (when (or quietly
10551                   (not gnus-interactive-catchup) ;Without confirmation?
10552                   gnus-expert-user
10553                   (gnus-y-or-n-p
10554                    (if all
10555                        "Mark absolutely all articles as read? "
10556                      "Mark all unread articles as read? ")))
10557           (if (and not-mark
10558                    (not gnus-newsgroup-adaptive)
10559                    (not gnus-newsgroup-auto-expire)
10560                    (not gnus-suppress-duplicates)
10561                    (or (not gnus-use-cache)
10562                        (eq gnus-use-cache 'passive)))
10563               (progn
10564                 (when all
10565                   (setq gnus-newsgroup-marked nil
10566                         gnus-newsgroup-spam-marked nil
10567                         gnus-newsgroup-dormant nil))
10568                 (setq gnus-newsgroup-unreads
10569                       (gnus-sorted-nunion
10570                        (gnus-intersection gnus-newsgroup-unreads
10571                                           gnus-newsgroup-downloadable)
10572                        gnus-newsgroup-unfetched)))
10573             ;; We actually mark all articles as canceled, which we
10574             ;; have to do when using auto-expiry or adaptive scoring.
10575             (gnus-summary-show-all-threads)
10576             (if (and to-here reverse)
10577                 (progn
10578                   (goto-char to-here)
10579                   (gnus-summary-mark-current-read-and-unread-as-read
10580                    gnus-catchup-mark)
10581                   (while (gnus-summary-find-next (not all))
10582                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10583               (when (gnus-summary-first-subject (not all))
10584                 (while (and
10585                         (if to-here (< (point) to-here) t)
10586                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10587                         (gnus-summary-find-next (not all))))))
10588             (gnus-set-mode-line 'summary))
10589           t))
10590     (gnus-summary-position-point)))
10591
10592 (defun gnus-summary-catchup-to-here (&optional all)
10593   "Mark all unticked articles before the current one as read.
10594 If ALL is non-nil, also mark ticked and dormant articles as read."
10595   (interactive "P")
10596   (save-excursion
10597     (gnus-save-hidden-threads
10598       (let ((beg (point)))
10599         ;; We check that there are unread articles.
10600         (when (or all (gnus-summary-find-prev))
10601           (gnus-summary-catchup all t beg)))))
10602   (gnus-summary-position-point))
10603
10604 (defun gnus-summary-catchup-from-here (&optional all)
10605   "Mark all unticked articles after (and including) 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-next))
10613           (gnus-summary-catchup all t beg nil t)))))
10614   (gnus-summary-position-point))
10615
10616 (defun gnus-summary-catchup-all (&optional quietly)
10617   "Mark all articles in this newsgroup as read.
10618 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10619 instead, which marks only unread articles as read."
10620   (interactive "P")
10621   (gnus-summary-catchup t quietly))
10622
10623 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10624   "Mark all unread articles in this group as read, then exit.
10625 If prefix argument ALL is non-nil, all articles are marked as read.
10626 If QUIETLY is non-nil, no questions will be asked."
10627   (interactive "P")
10628   (when (gnus-summary-catchup all quietly nil 'fast)
10629     ;; Select next newsgroup or exit.
10630     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10631              (eq gnus-auto-select-next 'quietly))
10632         (gnus-summary-next-group nil)
10633       (gnus-summary-exit))))
10634
10635 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10636   "Mark all articles in this newsgroup as read, and then exit.
10637 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10638 instead, which marks only unread articles as read."
10639   (interactive "P")
10640   (gnus-summary-catchup-and-exit t quietly))
10641
10642 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10643   "Mark all articles in this group as read and select the next group.
10644 If given a prefix, mark all articles, unread as well as ticked, as
10645 read."
10646   (interactive "P")
10647   (save-excursion
10648     (gnus-summary-catchup all))
10649   (gnus-summary-next-group))
10650
10651 ;;;
10652 ;;; with article
10653 ;;;
10654
10655 (defmacro gnus-with-article (article &rest forms)
10656   "Select ARTICLE and perform FORMS in the original article buffer.
10657 Then replace the article with the result."
10658   `(progn
10659      ;; We don't want the article to be marked as read.
10660      (let (gnus-mark-article-hook)
10661        (gnus-summary-select-article t t nil ,article))
10662      (set-buffer gnus-original-article-buffer)
10663      ,@forms
10664      (if (not (gnus-check-backend-function
10665                'request-replace-article (car gnus-article-current)))
10666          (gnus-message 5 "Read-only group; not replacing")
10667        (unless (gnus-request-replace-article
10668                 ,article (car gnus-article-current)
10669                 (current-buffer) t)
10670          (error "Couldn't replace article")))
10671      ;; The cache and backlog have to be flushed somewhat.
10672      (when gnus-keep-backlog
10673        (gnus-backlog-remove-article
10674         (car gnus-article-current) (cdr gnus-article-current)))
10675      (when gnus-use-cache
10676        (gnus-cache-update-article
10677         (car gnus-article-current) (cdr gnus-article-current)))))
10678
10679 (put 'gnus-with-article 'lisp-indent-function 1)
10680 (put 'gnus-with-article 'edebug-form-spec '(form body))
10681
10682 ;; Thread-based commands.
10683
10684 (defun gnus-summary-articles-in-thread (&optional article)
10685   "Return a list of all articles in the current thread.
10686 If ARTICLE is non-nil, return all articles in the thread that starts
10687 with that article."
10688   (let* ((article (or article (gnus-summary-article-number)))
10689          (data (gnus-data-find-list article))
10690          (top-level (gnus-data-level (car data)))
10691          (top-subject
10692           (cond ((null gnus-thread-operation-ignore-subject)
10693                  (gnus-simplify-subject-re
10694                   (mail-header-subject (gnus-data-header (car data)))))
10695                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10696                  (gnus-simplify-subject-fuzzy
10697                   (mail-header-subject (gnus-data-header (car data)))))
10698                 (t nil)))
10699          (end-point (save-excursion
10700                       (if (gnus-summary-go-to-next-thread)
10701                           (point) (point-max))))
10702          articles)
10703     (while (and data
10704                 (< (gnus-data-pos (car data)) end-point))
10705       (when (or (not top-subject)
10706                 (string= top-subject
10707                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10708                              (gnus-simplify-subject-fuzzy
10709                               (mail-header-subject
10710                                (gnus-data-header (car data))))
10711                            (gnus-simplify-subject-re
10712                             (mail-header-subject
10713                              (gnus-data-header (car data)))))))
10714         (push (gnus-data-number (car data)) articles))
10715       (unless (and (setq data (cdr data))
10716                    (> (gnus-data-level (car data)) top-level))
10717         (setq data nil)))
10718     ;; Return the list of articles.
10719     (nreverse articles)))
10720
10721 (defun gnus-summary-rethread-current ()
10722   "Rethread the thread the current article is part of."
10723   (interactive)
10724   (let* ((gnus-show-threads t)
10725          (article (gnus-summary-article-number))
10726          (id (mail-header-id (gnus-summary-article-header)))
10727          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10728     (unless id
10729       (error "No article on the current line"))
10730     (gnus-rebuild-thread id)
10731     (gnus-summary-goto-subject article)))
10732
10733 (defun gnus-summary-reparent-thread ()
10734   "Make the current article child of the marked (or previous) article.
10735
10736 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10737 is non-nil or the Subject: of both articles are the same."
10738   (interactive)
10739   (unless (not (gnus-group-read-only-p))
10740     (error "The current newsgroup does not support article editing"))
10741   (unless (<= (length gnus-newsgroup-processable) 1)
10742     (error "No more than one article may be marked"))
10743   (save-window-excursion
10744     (let ((gnus-article-buffer " *reparent*")
10745           (current-article (gnus-summary-article-number))
10746           ;; First grab the marked article, otherwise one line up.
10747           (parent-article (if (not (null gnus-newsgroup-processable))
10748                               (car gnus-newsgroup-processable)
10749                             (save-excursion
10750                               (if (eq (forward-line -1) 0)
10751                                   (gnus-summary-article-number)
10752                                 (error "Beginning of summary buffer"))))))
10753       (unless (not (eq current-article parent-article))
10754         (error "An article may not be self-referential"))
10755       (let ((message-id (mail-header-id
10756                          (gnus-summary-article-header parent-article))))
10757         (unless (and message-id (not (equal message-id "")))
10758           (error "No message-id in desired parent"))
10759         (gnus-with-article current-article
10760           (save-restriction
10761             (goto-char (point-min))
10762             (message-narrow-to-head)
10763             (if (re-search-forward "^References: " nil t)
10764                 (progn
10765                   (re-search-forward "^[^ \t]" nil t)
10766                   (forward-line -1)
10767                   (end-of-line)
10768                   (insert " " message-id))
10769               (insert "References: " message-id "\n"))))
10770         (set-buffer gnus-summary-buffer)
10771         (gnus-summary-unmark-all-processable)
10772         (gnus-summary-update-article current-article)
10773         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10774             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10775         (gnus-summary-rethread-current)
10776         (gnus-message 3 "Article %d is now the child of article %d"
10777                       current-article parent-article)))))
10778
10779 (defun gnus-summary-toggle-threads (&optional arg)
10780   "Toggle showing conversation threads.
10781 If ARG is positive number, turn showing conversation threads on."
10782   (interactive "P")
10783   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10784     (setq gnus-show-threads
10785           (if (null arg) (not gnus-show-threads)
10786             (> (prefix-numeric-value arg) 0)))
10787     (gnus-summary-prepare)
10788     (gnus-summary-goto-subject current)
10789     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10790     (gnus-summary-position-point)))
10791
10792 (defun gnus-summary-show-all-threads ()
10793   "Show all threads."
10794   (interactive)
10795   (save-excursion
10796     (let ((buffer-read-only nil))
10797       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10798   (gnus-summary-position-point))
10799
10800 (defun gnus-summary-show-thread ()
10801   "Show thread subtrees.
10802 Returns nil if no thread was there to be shown."
10803   (interactive)
10804   (let ((buffer-read-only nil)
10805         (orig (point))
10806         (end (point-at-eol))
10807         ;; Leave point at bol
10808         (beg (progn (beginning-of-line) (point))))
10809     (prog1
10810         ;; Any hidden lines here?
10811         (search-forward "\r" end t)
10812       (subst-char-in-region beg end ?\^M ?\n t)
10813       (goto-char orig)
10814       (gnus-summary-position-point))))
10815
10816 (defun gnus-summary-maybe-hide-threads ()
10817   "If requested, hide the threads that should be hidden."
10818   (when (and gnus-show-threads
10819              gnus-thread-hide-subtree)
10820     (gnus-summary-hide-all-threads
10821      (if (or (consp gnus-thread-hide-subtree)
10822              (functionp gnus-thread-hide-subtree))
10823          (gnus-make-predicate gnus-thread-hide-subtree)
10824        nil))))
10825
10826 ;;; Hiding predicates.
10827
10828 (defun gnus-article-unread-p (header)
10829   (memq (mail-header-number header) gnus-newsgroup-unreads))
10830
10831 (defun gnus-article-unseen-p (header)
10832   (memq (mail-header-number header) gnus-newsgroup-unseen))
10833
10834 (defun gnus-map-articles (predicate articles)
10835   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10836   (apply 'gnus-or (mapcar predicate
10837                           (mapcar 'gnus-summary-article-header articles))))
10838
10839 (defun gnus-summary-hide-all-threads (&optional predicate)
10840   "Hide all thread subtrees.
10841 If PREDICATE is supplied, threads that satisfy this predicate
10842 will not be hidden."
10843   (interactive)
10844   (save-excursion
10845     (goto-char (point-min))
10846     (let ((end nil))
10847       (while (not end)
10848         (when (or (not predicate)
10849                   (gnus-map-articles
10850                    predicate (gnus-summary-article-children)))
10851             (gnus-summary-hide-thread))
10852         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10853   (gnus-summary-position-point))
10854
10855 (defun gnus-summary-hide-thread ()
10856   "Hide thread subtrees.
10857 If PREDICATE is supplied, threads that satisfy this predicate
10858 will not be hidden.
10859 Returns nil if no threads were there to be hidden."
10860   (interactive)
10861   (let ((buffer-read-only nil)
10862         (start (point))
10863         (article (gnus-summary-article-number)))
10864     (goto-char start)
10865     ;; Go forward until either the buffer ends or the subthread
10866     ;; ends.
10867     (when (and (not (eobp))
10868                (or (zerop (gnus-summary-next-thread 1 t))
10869                    (goto-char (point-max))))
10870       (prog1
10871           (if (and (> (point) start)
10872                    (search-backward "\n" start t))
10873               (progn
10874                 (subst-char-in-region start (point) ?\n ?\^M)
10875                 (gnus-summary-goto-subject article))
10876             (goto-char start)
10877             nil)))))
10878
10879 (defun gnus-summary-go-to-next-thread (&optional previous)
10880   "Go to the same level (or less) next thread.
10881 If PREVIOUS is non-nil, go to previous thread instead.
10882 Return the article number moved to, or nil if moving was impossible."
10883   (let ((level (gnus-summary-thread-level))
10884         (way (if previous -1 1))
10885         (beg (point)))
10886     (forward-line way)
10887     (while (and (not (eobp))
10888                 (< level (gnus-summary-thread-level)))
10889       (forward-line way))
10890     (if (eobp)
10891         (progn
10892           (goto-char beg)
10893           nil)
10894       (setq beg (point))
10895       (prog1
10896           (gnus-summary-article-number)
10897         (goto-char beg)))))
10898
10899 (defun gnus-summary-next-thread (n &optional silent)
10900   "Go to the same level next N'th thread.
10901 If N is negative, search backward instead.
10902 Returns the difference between N and the number of skips actually
10903 done.
10904
10905 If SILENT, don't output messages."
10906   (interactive "p")
10907   (let ((backward (< n 0))
10908         (n (abs n)))
10909     (while (and (> n 0)
10910                 (gnus-summary-go-to-next-thread backward))
10911       (decf n))
10912     (unless silent
10913       (gnus-summary-position-point))
10914     (when (and (not silent) (/= 0 n))
10915       (gnus-message 7 "No more threads"))
10916     n))
10917
10918 (defun gnus-summary-prev-thread (n)
10919   "Go to the same level previous N'th thread.
10920 Returns the difference between N and the number of skips actually
10921 done."
10922   (interactive "p")
10923   (gnus-summary-next-thread (- n)))
10924
10925 (defun gnus-summary-go-down-thread ()
10926   "Go down one level in the current thread."
10927   (let ((children (gnus-summary-article-children)))
10928     (when children
10929       (gnus-summary-goto-subject (car children)))))
10930
10931 (defun gnus-summary-go-up-thread ()
10932   "Go up one level in the current thread."
10933   (let ((parent (gnus-summary-article-parent)))
10934     (when parent
10935       (gnus-summary-goto-subject parent))))
10936
10937 (defun gnus-summary-down-thread (n)
10938   "Go down thread N steps.
10939 If N is negative, go up instead.
10940 Returns the difference between N and how many steps down that were
10941 taken."
10942   (interactive "p")
10943   (let ((up (< n 0))
10944         (n (abs n)))
10945     (while (and (> n 0)
10946                 (if up (gnus-summary-go-up-thread)
10947                   (gnus-summary-go-down-thread)))
10948       (setq n (1- n)))
10949     (gnus-summary-position-point)
10950     (when (/= 0 n)
10951       (gnus-message 7 "Can't go further"))
10952     n))
10953
10954 (defun gnus-summary-up-thread (n)
10955   "Go up thread N steps.
10956 If N is negative, go down instead.
10957 Returns the difference between N and how many steps down that were
10958 taken."
10959   (interactive "p")
10960   (gnus-summary-down-thread (- n)))
10961
10962 (defun gnus-summary-top-thread ()
10963   "Go to the top of the thread."
10964   (interactive)
10965   (while (gnus-summary-go-up-thread))
10966   (gnus-summary-article-number))
10967
10968 (defun gnus-summary-kill-thread (&optional unmark)
10969   "Mark articles under current thread as read.
10970 If the prefix argument is positive, remove any kinds of marks.
10971 If the prefix argument is negative, tick articles instead."
10972   (interactive "P")
10973   (when unmark
10974     (setq unmark (prefix-numeric-value unmark)))
10975   (let ((articles (gnus-summary-articles-in-thread)))
10976     (save-excursion
10977       ;; Expand the thread.
10978       (gnus-summary-show-thread)
10979       ;; Mark all the articles.
10980       (while articles
10981         (gnus-summary-goto-subject (car articles))
10982         (cond ((null unmark)
10983                (gnus-summary-mark-article-as-read gnus-killed-mark))
10984               ((> unmark 0)
10985                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10986               (t
10987                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10988         (setq articles (cdr articles))))
10989     ;; Hide killed subtrees.
10990     (and (null unmark)
10991          gnus-thread-hide-killed
10992          (gnus-summary-hide-thread))
10993     ;; If marked as read, go to next unread subject.
10994     (when (null unmark)
10995       ;; Go to next unread subject.
10996       (gnus-summary-next-subject 1 t)))
10997   (gnus-set-mode-line 'summary))
10998
10999 ;; Summary sorting commands
11000
11001 (defun gnus-summary-sort-by-number (&optional reverse)
11002   "Sort the summary buffer by article number.
11003 Argument REVERSE means reverse order."
11004   (interactive "P")
11005   (gnus-summary-sort 'number reverse))
11006
11007 (defun gnus-summary-sort-by-random (&optional reverse)
11008   "Randomize the order in the summary buffer.
11009 Argument REVERSE means to randomize in reverse order."
11010   (interactive "P")
11011   (gnus-summary-sort 'random reverse))
11012
11013 (defun gnus-summary-sort-by-author (&optional reverse)
11014   "Sort the summary buffer by author name alphabetically.
11015 If `case-fold-search' is non-nil, case of letters is ignored.
11016 Argument REVERSE means reverse order."
11017   (interactive "P")
11018   (gnus-summary-sort 'author reverse))
11019
11020 (defun gnus-summary-sort-by-recipient (&optional reverse)
11021   "Sort the summary buffer by recipient name alphabetically.
11022 If `case-fold-search' is non-nil, case of letters is ignored.
11023 Argument REVERSE means reverse order."
11024   (interactive "P")
11025   (gnus-summary-sort 'recipient reverse))
11026
11027 (defun gnus-summary-sort-by-subject (&optional reverse)
11028   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11029 If `case-fold-search' is non-nil, case of letters is ignored.
11030 Argument REVERSE means reverse order."
11031   (interactive "P")
11032   (gnus-summary-sort 'subject reverse))
11033
11034 (defun gnus-summary-sort-by-date (&optional reverse)
11035   "Sort the summary buffer by date.
11036 Argument REVERSE means reverse order."
11037   (interactive "P")
11038   (gnus-summary-sort 'date reverse))
11039
11040 (defun gnus-summary-sort-by-score (&optional reverse)
11041   "Sort the summary buffer by score.
11042 Argument REVERSE means reverse order."
11043   (interactive "P")
11044   (gnus-summary-sort 'score reverse))
11045
11046 (defun gnus-summary-sort-by-lines (&optional reverse)
11047   "Sort the summary buffer by the number of lines.
11048 Argument REVERSE means reverse order."
11049   (interactive "P")
11050   (gnus-summary-sort 'lines reverse))
11051
11052 (defun gnus-summary-sort-by-chars (&optional reverse)
11053   "Sort the summary buffer by article length.
11054 Argument REVERSE means reverse order."
11055   (interactive "P")
11056   (gnus-summary-sort 'chars reverse))
11057
11058 (defun gnus-summary-sort-by-original (&optional reverse)
11059   "Sort the summary buffer using the default sorting method.
11060 Argument REVERSE means reverse order."
11061   (interactive "P")
11062   (let* ((buffer-read-only)
11063          (gnus-summary-prepare-hook nil))
11064     ;; We do the sorting by regenerating the threads.
11065     (gnus-summary-prepare)
11066     ;; Hide subthreads if needed.
11067     (gnus-summary-maybe-hide-threads)))
11068
11069 (defun gnus-summary-sort (predicate reverse)
11070   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11071   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11072          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11073          (gnus-thread-sort-functions
11074           (if (not reverse)
11075               thread
11076             `(lambda (t1 t2)
11077                (,thread t2 t1))))
11078          (gnus-sort-gathered-threads-function
11079           gnus-thread-sort-functions)
11080          (gnus-article-sort-functions
11081           (if (not reverse)
11082               article
11083             `(lambda (t1 t2)
11084                (,article t2 t1))))
11085          (buffer-read-only)
11086          (gnus-summary-prepare-hook nil))
11087     ;; We do the sorting by regenerating the threads.
11088     (gnus-summary-prepare)
11089     ;; Hide subthreads if needed.
11090     (gnus-summary-maybe-hide-threads)))
11091
11092 ;; Summary saving commands.
11093
11094 (defun gnus-summary-save-article (&optional n not-saved)
11095   "Save the current article using the default saver function.
11096 If N is a positive number, save the N next articles.
11097 If N is a negative number, save the N previous articles.
11098 If N is nil and any articles have been marked with the process mark,
11099 save those articles instead.
11100 The variable `gnus-default-article-saver' specifies the saver function."
11101   (interactive "P")
11102   (let* ((articles (gnus-summary-work-articles n))
11103          (save-buffer (save-excursion
11104                         (nnheader-set-temp-buffer " *Gnus Save*")))
11105          (num (length articles))
11106          header file)
11107     (dolist (article articles)
11108       (setq header (gnus-summary-article-header article))
11109       (if (not (vectorp header))
11110           ;; This is a pseudo-article.
11111           (if (assq 'name header)
11112               (gnus-copy-file (cdr (assq 'name header)))
11113             (gnus-message 1 "Article %d is unsaveable" article))
11114         ;; This is a real article.
11115         (save-window-excursion
11116           (let ((gnus-display-mime-function nil)
11117                 (gnus-article-prepare-hook nil))
11118             (gnus-summary-select-article t nil nil article)))
11119         (save-excursion
11120           (set-buffer save-buffer)
11121           (erase-buffer)
11122           (insert-buffer-substring gnus-original-article-buffer))
11123         (setq file (gnus-article-save save-buffer file num))
11124         (gnus-summary-remove-process-mark article)
11125         (unless not-saved
11126           (gnus-summary-set-saved-mark article))))
11127     (gnus-kill-buffer save-buffer)
11128     (gnus-summary-position-point)
11129     (gnus-set-mode-line 'summary)
11130     n))
11131
11132 (defun gnus-summary-pipe-output (&optional arg headers)
11133   "Pipe the current article to a subprocess.
11134 If N is a positive number, pipe the N next articles.
11135 If N is a negative number, pipe the N previous articles.
11136 If N is nil and any articles have been marked with the process mark,
11137 pipe those articles instead.
11138 If HEADERS (the symbolic prefix), include the headers, too."
11139   (interactive (gnus-interactive "P\ny"))
11140   (require 'gnus-art)
11141   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11142         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11143     (gnus-summary-save-article arg t))
11144   (let ((buffer (get-buffer "*Shell Command Output*")))
11145     (when (and buffer
11146                (not (zerop (buffer-size buffer))))
11147       (gnus-configure-windows 'pipe))))
11148
11149 (defun gnus-summary-save-article-mail (&optional arg)
11150   "Append the current article to an mail file.
11151 If N is a positive number, save the N next articles.
11152 If N is a negative number, save the N previous articles.
11153 If N is nil and any articles have been marked with the process mark,
11154 save those articles instead."
11155   (interactive "P")
11156   (require 'gnus-art)
11157   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11158     (gnus-summary-save-article arg)))
11159
11160 (defun gnus-summary-save-article-rmail (&optional arg)
11161   "Append the current article to an rmail file.
11162 If N is a positive number, save the N next articles.
11163 If N is a negative number, save the N previous articles.
11164 If N is nil and any articles have been marked with the process mark,
11165 save those articles instead."
11166   (interactive "P")
11167   (require 'gnus-art)
11168   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11169     (gnus-summary-save-article arg)))
11170
11171 (defun gnus-summary-save-article-file (&optional arg)
11172   "Append the current article to a file.
11173 If N is a positive number, save the N next articles.
11174 If N is a negative number, save the N previous articles.
11175 If N is nil and any articles have been marked with the process mark,
11176 save those articles instead."
11177   (interactive "P")
11178   (require 'gnus-art)
11179   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11180     (gnus-summary-save-article arg)))
11181
11182 (defun gnus-summary-write-article-file (&optional arg)
11183   "Write the current article to a file, deleting the previous file.
11184 If N is a positive number, save the N next articles.
11185 If N is a negative number, save the N previous articles.
11186 If N is nil and any articles have been marked with the process mark,
11187 save those articles instead."
11188   (interactive "P")
11189   (require 'gnus-art)
11190   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11191     (gnus-summary-save-article arg)))
11192
11193 (defun gnus-summary-save-article-body-file (&optional arg)
11194   "Append the current article body to a file.
11195 If N is a positive number, save the N next articles.
11196 If N is a negative number, save the N previous articles.
11197 If N is nil and any articles have been marked with the process mark,
11198 save those articles instead."
11199   (interactive "P")
11200   (require 'gnus-art)
11201   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11202     (gnus-summary-save-article arg)))
11203
11204 (defun gnus-summary-muttprint (&optional arg)
11205   "Print the current article using Muttprint.
11206 If N is a positive number, save the N next articles.
11207 If N is a negative number, save the N previous articles.
11208 If N is nil and any articles have been marked with the process mark,
11209 save those articles instead."
11210   (interactive "P")
11211   (require 'gnus-art)
11212   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11213     (gnus-summary-save-article arg t)))
11214
11215 (defun gnus-summary-pipe-message (program)
11216   "Pipe the current article through PROGRAM."
11217   (interactive "sProgram: ")
11218   (gnus-summary-select-article)
11219   (let ((mail-header-separator ""))
11220     (gnus-eval-in-buffer-window gnus-article-buffer
11221       (save-restriction
11222         (widen)
11223         (let ((start (window-start))
11224               buffer-read-only)
11225           (message-pipe-buffer-body program)
11226           (set-window-start (get-buffer-window (current-buffer)) start))))))
11227
11228 (defun gnus-get-split-value (methods)
11229   "Return a value based on the split METHODS."
11230   (let (split-name method result match)
11231     (when methods
11232       (save-excursion
11233         (set-buffer gnus-original-article-buffer)
11234         (save-restriction
11235           (nnheader-narrow-to-headers)
11236           (while (and methods (not split-name))
11237             (goto-char (point-min))
11238             (setq method (pop methods))
11239             (setq match (car method))
11240             (when (cond
11241                    ((stringp match)
11242                     ;; Regular expression.
11243                     (ignore-errors
11244                       (re-search-forward match nil t)))
11245                    ((functionp match)
11246                     ;; Function.
11247                     (save-restriction
11248                       (widen)
11249                       (setq result (funcall match gnus-newsgroup-name))))
11250                    ((consp match)
11251                     ;; Form.
11252                     (save-restriction
11253                       (widen)
11254                       (setq result (eval match)))))
11255               (setq split-name (cdr method))
11256               (cond ((stringp result)
11257                      (push (expand-file-name
11258                             result gnus-article-save-directory)
11259                            split-name))
11260                     ((consp result)
11261                      (setq split-name (append result split-name)))))))))
11262     (nreverse split-name)))
11263
11264 (defun gnus-valid-move-group-p (group)
11265   (and (boundp group)
11266        (symbol-name group)
11267        (symbol-value group)
11268        (gnus-get-function (gnus-find-method-for-group
11269                            (symbol-name group)) 'request-accept-article t)))
11270
11271 (defun gnus-read-move-group-name (prompt default articles prefix)
11272   "Read a group name."
11273   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11274          (minibuffer-confirm-incomplete nil) ; XEmacs
11275          (prom
11276           (format "%s %s to:"
11277                   prompt
11278                   (if (> (length articles) 1)
11279                       (format "these %d articles" (length articles))
11280                     "this article")))
11281          (to-newsgroup
11282           (cond
11283            ((null split-name)
11284             (gnus-completing-read-with-default
11285              default prom
11286              gnus-active-hashtb
11287              'gnus-valid-move-group-p
11288              nil prefix
11289              'gnus-group-history))
11290            ((= 1 (length split-name))
11291             (gnus-completing-read-with-default
11292              (car split-name) prom
11293              gnus-active-hashtb
11294              'gnus-valid-move-group-p
11295              nil nil
11296              'gnus-group-history))
11297            (t
11298             (gnus-completing-read-with-default
11299              nil prom
11300              (mapcar 'list (nreverse split-name))
11301              nil nil nil
11302              'gnus-group-history))))
11303          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11304     (when to-newsgroup
11305       (if (or (string= to-newsgroup "")
11306               (string= to-newsgroup prefix))
11307           (setq to-newsgroup default))
11308       (unless to-newsgroup
11309         (error "No group name entered"))
11310       (or (gnus-active to-newsgroup)
11311           (gnus-activate-group to-newsgroup nil nil to-method)
11312           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11313                                      to-newsgroup))
11314               (or (and (gnus-request-create-group to-newsgroup to-method)
11315                        (gnus-activate-group
11316                         to-newsgroup nil nil to-method)
11317                        (gnus-subscribe-group to-newsgroup))
11318                   (error "Couldn't create group %s" to-newsgroup)))
11319           (error "No such group: %s" to-newsgroup)))
11320     to-newsgroup))
11321
11322 (defun gnus-summary-save-parts (type dir n &optional reverse)
11323   "Save parts matching TYPE to DIR.
11324 If REVERSE, save parts that do not match TYPE."
11325   (interactive
11326    (list (read-string "Save parts of type: "
11327                       (or (car gnus-summary-save-parts-type-history)
11328                           gnus-summary-save-parts-default-mime)
11329                       'gnus-summary-save-parts-type-history)
11330          (setq gnus-summary-save-parts-last-directory
11331                (read-file-name "Save to directory: "
11332                                gnus-summary-save-parts-last-directory
11333                                nil t))
11334          current-prefix-arg))
11335   (gnus-summary-iterate n
11336     (let ((gnus-display-mime-function nil)
11337           (gnus-inhibit-treatment t))
11338       (gnus-summary-select-article))
11339     (save-excursion
11340       (set-buffer gnus-article-buffer)
11341       (let ((handles (or gnus-article-mime-handles
11342                          (mm-dissect-buffer nil gnus-article-loose-mime)
11343                          (and gnus-article-emulate-mime
11344                               (mm-uu-dissect)))))
11345         (when handles
11346           (gnus-summary-save-parts-1 type dir handles reverse)
11347           (unless gnus-article-mime-handles ;; Don't destroy this case.
11348             (mm-destroy-parts handles)))))))
11349
11350 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11351   (if (stringp (car handle))
11352       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11353               (cdr handle))
11354     (when (if reverse
11355               (not (string-match type (mm-handle-media-type handle)))
11356             (string-match type (mm-handle-media-type handle)))
11357       (let ((file (expand-file-name
11358                    (gnus-map-function
11359                     mm-file-name-rewrite-functions
11360                     (file-name-nondirectory
11361                      (or
11362                       (mail-content-type-get
11363                        (mm-handle-disposition handle) 'filename)
11364                       (mail-content-type-get
11365                        (mm-handle-type handle) 'name)
11366                       (concat gnus-newsgroup-name
11367                               "." (number-to-string
11368                                    (cdr gnus-article-current))))))
11369                    dir)))
11370         (unless (file-exists-p file)
11371           (mm-save-part-to-file handle file))))))
11372
11373 ;; Summary extract commands
11374
11375 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11376   (let ((buffer-read-only nil)
11377         (article (gnus-summary-article-number))
11378         after-article b e)
11379     (unless (gnus-summary-goto-subject article)
11380       (error "No such article: %d" article))
11381     (gnus-summary-position-point)
11382     ;; If all commands are to be bunched up on one line, we collect
11383     ;; them here.
11384     (unless gnus-view-pseudos-separately
11385       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11386             files action)
11387         (while ps
11388           (setq action (cdr (assq 'action (car ps))))
11389           (setq files (list (cdr (assq 'name (car ps)))))
11390           (while (and ps (cdr ps)
11391                       (string= (or action "1")
11392                                (or (cdr (assq 'action (cadr ps))) "2")))
11393             (push (cdr (assq 'name (cadr ps))) files)
11394             (setcdr ps (cddr ps)))
11395           (when files
11396             (when (not (string-match "%s" action))
11397               (push " " files))
11398             (push " " files)
11399             (when (assq 'execute (car ps))
11400               (setcdr (assq 'execute (car ps))
11401                       (funcall (if (string-match "%s" action)
11402                                    'format 'concat)
11403                                action
11404                                (mapconcat
11405                                 (lambda (f)
11406                                   (if (equal f " ")
11407                                       f
11408                                     (shell-quote-argument f)))
11409                                 files " ")))))
11410           (setq ps (cdr ps)))))
11411     (if (and gnus-view-pseudos (not not-view))
11412         (while pslist
11413           (when (assq 'execute (car pslist))
11414             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11415                                   (eq gnus-view-pseudos 'not-confirm)))
11416           (setq pslist (cdr pslist)))
11417       (save-excursion
11418         (while pslist
11419           (setq after-article (or (cdr (assq 'article (car pslist)))
11420                                   (gnus-summary-article-number)))
11421           (gnus-summary-goto-subject after-article)
11422           (forward-line 1)
11423           (setq b (point))
11424           (insert "    " (file-name-nondirectory
11425                           (cdr (assq 'name (car pslist))))
11426                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11427           (setq e (point))
11428           (forward-line -1)             ; back to `b'
11429           (gnus-add-text-properties
11430            b (1- e) (list 'gnus-number gnus-reffed-article-number
11431                           gnus-mouse-face-prop gnus-mouse-face))
11432           (gnus-data-enter
11433            after-article gnus-reffed-article-number
11434            gnus-unread-mark b (car pslist) 0 (- e b))
11435           (setq gnus-newsgroup-unreads
11436                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11437                                          gnus-reffed-article-number))
11438           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11439           (setq pslist (cdr pslist)))))))
11440
11441 (defun gnus-pseudos< (p1 p2)
11442   (let ((c1 (cdr (assq 'action p1)))
11443         (c2 (cdr (assq 'action p2))))
11444     (and c1 c2 (string< c1 c2))))
11445
11446 (defun gnus-request-pseudo-article (props)
11447   (cond ((assq 'execute props)
11448          (gnus-execute-command (cdr (assq 'execute props)))))
11449   (let ((gnus-current-article (gnus-summary-article-number)))
11450     (gnus-run-hooks 'gnus-mark-article-hook)))
11451
11452 (defun gnus-execute-command (command &optional automatic)
11453   (save-excursion
11454     (gnus-article-setup-buffer)
11455     (set-buffer gnus-article-buffer)
11456     (setq buffer-read-only nil)
11457     (let ((command (if automatic command
11458                      (read-string "Command: " (cons command 0)))))
11459       (erase-buffer)
11460       (insert "$ " command "\n\n")
11461       (if gnus-view-pseudo-asynchronously
11462           (start-process "gnus-execute" (current-buffer) shell-file-name
11463                          shell-command-switch command)
11464         (call-process shell-file-name nil t nil
11465                       shell-command-switch command)))))
11466
11467 ;; Summary kill commands.
11468
11469 (defun gnus-summary-edit-global-kill (article)
11470   "Edit the \"global\" kill file."
11471   (interactive (list (gnus-summary-article-number)))
11472   (gnus-group-edit-global-kill article))
11473
11474 (defun gnus-summary-edit-local-kill ()
11475   "Edit a local kill file applied to the current newsgroup."
11476   (interactive)
11477   (setq gnus-current-headers (gnus-summary-article-header))
11478   (gnus-group-edit-local-kill
11479    (gnus-summary-article-number) gnus-newsgroup-name))
11480
11481 ;;; Header reading.
11482
11483 (defun gnus-read-header (id &optional header)
11484   "Read the headers of article ID and enter them into the Gnus system."
11485   (let ((group gnus-newsgroup-name)
11486         (gnus-override-method
11487          (or
11488           gnus-override-method
11489           (and (gnus-news-group-p gnus-newsgroup-name)
11490                (car (gnus-refer-article-methods)))))
11491         where)
11492     ;; First we check to see whether the header in question is already
11493     ;; fetched.
11494     (if (stringp id)
11495         ;; This is a Message-ID.
11496         (setq header (or header (gnus-id-to-header id)))
11497       ;; This is an article number.
11498       (setq header (or header (gnus-summary-article-header id))))
11499     (if (and header
11500              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11501         ;; We have found the header.
11502         header
11503       ;; We have to really fetch the header to this article.
11504       (save-excursion
11505         (set-buffer nntp-server-buffer)
11506         (when (setq where (gnus-request-head id group))
11507           (nnheader-fold-continuation-lines)
11508           (goto-char (point-max))
11509           (insert ".\n")
11510           (goto-char (point-min))
11511           (insert "211 ")
11512           (princ (cond
11513                   ((numberp id) id)
11514                   ((cdr where) (cdr where))
11515                   (header (mail-header-number header))
11516                   (t gnus-reffed-article-number))
11517                  (current-buffer))
11518           (insert " Article retrieved.\n"))
11519         (if (or (not where)
11520                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11521             ()                          ; Malformed head.
11522           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11523             (when (and (stringp id)
11524                        (not (string= (gnus-group-real-name group)
11525                                      (car where))))
11526               ;; If we fetched by Message-ID and the article came
11527               ;; from a different group, we fudge some bogus article
11528               ;; numbers for this article.
11529               (mail-header-set-number header gnus-reffed-article-number))
11530             (save-excursion
11531               (set-buffer gnus-summary-buffer)
11532               (decf gnus-reffed-article-number)
11533               (gnus-remove-header (mail-header-number header))
11534               (push header gnus-newsgroup-headers)
11535               (setq gnus-current-headers header)
11536               (push (mail-header-number header) gnus-newsgroup-limit)))
11537           header)))))
11538
11539 (defun gnus-remove-header (number)
11540   "Remove header NUMBER from `gnus-newsgroup-headers'."
11541   (if (and gnus-newsgroup-headers
11542            (= number (mail-header-number (car gnus-newsgroup-headers))))
11543       (pop gnus-newsgroup-headers)
11544     (let ((headers gnus-newsgroup-headers))
11545       (while (and (cdr headers)
11546                   (not (= number (mail-header-number (cadr headers)))))
11547         (pop headers))
11548       (when (cdr headers)
11549         (setcdr headers (cddr headers))))))
11550
11551 ;;;
11552 ;;; summary highlights
11553 ;;;
11554
11555 (defun gnus-highlight-selected-summary ()
11556   "Highlight selected article in summary buffer."
11557   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11558   (when gnus-summary-selected-face
11559     (save-excursion
11560       (let* ((beg (point-at-bol))
11561              (end (point-at-eol))
11562              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11563              (from (if (get-text-property beg gnus-mouse-face-prop)
11564                        beg
11565                      (or (next-single-property-change
11566                           beg gnus-mouse-face-prop nil end)
11567                          beg)))
11568              (to
11569               (if (= from end)
11570                   (- from 2)
11571                 (or (next-single-property-change
11572                      from gnus-mouse-face-prop nil end)
11573                     end))))
11574         ;; If no mouse-face prop on line we will have to = from = end,
11575         ;; so we highlight the entire line instead.
11576         (when (= (+ to 2) from)
11577           (setq from beg)
11578           (setq to end))
11579         (if gnus-newsgroup-selected-overlay
11580             ;; Move old overlay.
11581             (gnus-move-overlay
11582              gnus-newsgroup-selected-overlay from to (current-buffer))
11583           ;; Create new overlay.
11584           (gnus-overlay-put
11585            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11586            'face gnus-summary-selected-face))))))
11587
11588 (defvar gnus-summary-highlight-line-cached nil)
11589 (defvar gnus-summary-highlight-line-trigger nil)
11590
11591 (defun gnus-summary-highlight-line-0 ()
11592   (if (and (eq gnus-summary-highlight-line-trigger
11593                gnus-summary-highlight)
11594            gnus-summary-highlight-line-cached)
11595       gnus-summary-highlight-line-cached
11596     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11597           gnus-summary-highlight-line-cached
11598           (let* ((cond (list 'cond))
11599                  (c cond)
11600                  (list gnus-summary-highlight))
11601             (while list
11602               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11603                               nil))
11604               (setq c (cdr c)
11605                     list (cdr list)))
11606             (gnus-byte-compile (list 'lambda nil cond))))))
11607
11608 (defun gnus-summary-highlight-line ()
11609   "Highlight current line according to `gnus-summary-highlight'."
11610   (let* ((beg (point-at-bol))
11611          (article (or (gnus-summary-article-number) gnus-current-article))
11612          (score (or (cdr (assq article
11613                                gnus-newsgroup-scored))
11614                     gnus-summary-default-score 0))
11615          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11616          (inhibit-read-only t)
11617          (default gnus-summary-default-score)
11618          (default-high gnus-summary-default-high-score)
11619          (default-low gnus-summary-default-low-score)
11620          (uncached (and gnus-summary-use-undownloaded-faces
11621                         (memq article gnus-newsgroup-undownloaded)
11622                         (not (memq article gnus-newsgroup-cached)))))
11623     (let ((face (funcall (gnus-summary-highlight-line-0))))
11624       (unless (eq face (get-text-property beg 'face))
11625         (gnus-put-text-property-excluding-characters-with-faces
11626          beg (point-at-eol) 'face
11627          (setq face (if (boundp face) (symbol-value face) face)))
11628         (when gnus-summary-highlight-line-function
11629           (funcall gnus-summary-highlight-line-function article face))))))
11630
11631 (defun gnus-update-read-articles (group unread &optional compute)
11632   "Update the list of read articles in GROUP.
11633 UNREAD is a sorted list."
11634   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11635         (info (gnus-get-info group))
11636         (prev 1)
11637         read)
11638     (if (or (not info) (not active))
11639         ;; There is no info on this group if it was, in fact,
11640         ;; killed.  Gnus stores no information on killed groups, so
11641         ;; there's nothing to be done.
11642         ;; One could store the information somewhere temporarily,
11643         ;; perhaps...  Hmmm...
11644         ()
11645       ;; Remove any negative articles numbers.
11646       (while (and unread (< (car unread) 0))
11647         (setq unread (cdr unread)))
11648       ;; Remove any expired article numbers
11649       (while (and unread (< (car unread) (car active)))
11650         (setq unread (cdr unread)))
11651       ;; Compute the ranges of read articles by looking at the list of
11652       ;; unread articles.
11653       (while unread
11654         (when (/= (car unread) prev)
11655           (push (if (= prev (1- (car unread))) prev
11656                   (cons prev (1- (car unread))))
11657                 read))
11658         (setq prev (1+ (car unread)))
11659         (setq unread (cdr unread)))
11660       (when (<= prev (cdr active))
11661         (push (cons prev (cdr active)) read))
11662       (setq read (if (> (length read) 1) (nreverse read) read))
11663       (if compute
11664           read
11665         (save-excursion
11666           (let (setmarkundo)
11667             ;; Propagate the read marks to the backend.
11668             (when (gnus-check-backend-function 'request-set-mark group)
11669               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11670                     (add (gnus-remove-from-range read (gnus-info-read info))))
11671                 (when (or add del)
11672                   (unless (gnus-check-group group)
11673                     (error "Can't open server for %s" group))
11674                   (gnus-request-set-mark
11675                    group (delq nil (list (if add (list add 'add '(read)))
11676                                          (if del (list del 'del '(read))))))
11677                   (setq setmarkundo
11678                         `(gnus-request-set-mark
11679                           ,group
11680                           ',(delq nil (list
11681                                        (if del (list del 'add '(read)))
11682                                        (if add (list add 'del '(read))))))))))
11683             (set-buffer gnus-group-buffer)
11684             (gnus-undo-register
11685               `(progn
11686                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11687                  (gnus-info-set-read ',info ',(gnus-info-read info))
11688                  (gnus-get-unread-articles-in-group ',info
11689                                                     (gnus-active ,group))
11690                  (gnus-group-update-group ,group t)
11691                  ,setmarkundo))))
11692         ;; Enter this list into the group info.
11693         (gnus-info-set-read info read)
11694         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11695         (gnus-get-unread-articles-in-group info (gnus-active group))
11696         t))))
11697
11698 (defun gnus-offer-save-summaries ()
11699   "Offer to save all active summary buffers."
11700   (let (buffers)
11701     ;; Go through all buffers and find all summaries.
11702     (dolist (buffer (buffer-list))
11703       (when (and (setq buffer (buffer-name buffer))
11704                  (string-match "Summary" buffer)
11705                  (with-current-buffer buffer
11706                    ;; We check that this is, indeed, a summary buffer.
11707                    (and (eq major-mode 'gnus-summary-mode)
11708                         ;; Also make sure this isn't bogus.
11709                         gnus-newsgroup-prepared
11710                         ;; Also make sure that this isn't a
11711                         ;; dead summary buffer.
11712                         (not gnus-dead-summary-mode))))
11713         (push buffer buffers)))
11714     ;; Go through all these summary buffers and offer to save them.
11715     (when buffers
11716       (save-excursion
11717         (map-y-or-n-p
11718          "Update summary buffer %s? "
11719          (lambda (buf)
11720            (switch-to-buffer buf)
11721            (gnus-summary-exit))
11722          buffers)))))
11723
11724
11725 ;;; @ for mime-partial
11726 ;;;
11727
11728 (defun gnus-request-partial-message ()
11729   (save-excursion
11730     (let ((number (gnus-summary-article-number))
11731           (group gnus-newsgroup-name)
11732           (mother gnus-article-buffer))
11733       (set-buffer (get-buffer-create " *Partial Article*"))
11734       (erase-buffer)
11735       (setq mime-preview-buffer mother)
11736       (gnus-request-article-this-buffer number group)
11737       (mime-parse-buffer)
11738       )))
11739
11740 (autoload 'mime-combine-message/partial-pieces-automatically
11741   "mime-partial"
11742   "Internal method to combine message/partial messages automatically.")
11743
11744 (mime-add-condition
11745  'action '((type . message)(subtype . partial)
11746            (major-mode . gnus-original-article-mode)
11747            (method . mime-combine-message/partial-pieces-automatically)
11748            (summary-buffer-exp . gnus-summary-buffer)
11749            (request-partial-message-method . gnus-request-partial-message)
11750            ))
11751
11752
11753 ;;; @ for message/rfc822
11754 ;;;
11755
11756 (defun gnus-mime-extract-message/rfc822 (entity situation)
11757   "Burst a forwarded article."
11758   (save-excursion
11759     (set-buffer gnus-summary-buffer)
11760     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11761                                    gnus-newsgroup-name 'gnus-group-history))
11762            (gnus-group-marked (list group))
11763            article info)
11764       (with-temp-buffer
11765         (mime-insert-entity-content entity)
11766         (setq article (gnus-request-accept-article group)))
11767       (when (and (consp article)
11768                  (numberp (setq article (cdr article))))
11769         (setq info (gnus-get-info group))
11770         (gnus-info-set-read info
11771                             (gnus-remove-from-range (gnus-info-read info)
11772                                                     (list article)))
11773         (when (string-equal group gnus-newsgroup-name)
11774           (forward-line 1)
11775           (let (gnus-show-threads)
11776             (gnus-summary-goto-subject article t))
11777           (gnus-summary-clear-mark-forward 1))
11778         (set-buffer gnus-group-buffer)
11779         (gnus-group-get-new-news-this-group nil t)))))
11780
11781 (mime-add-condition
11782  'action '((type . message)(subtype . rfc822)
11783            (major-mode . gnus-original-article-mode)
11784            (method . gnus-mime-extract-message/rfc822)
11785            (mode . "extract")
11786            ))
11787
11788 (mime-add-condition
11789  'action '((type . message)(subtype . news)
11790            (major-mode . gnus-original-article-mode)
11791            (method . gnus-mime-extract-message/rfc822)
11792            (mode . "extract")
11793            ))
11794
11795 (defun gnus-mime-extract-multipart (entity situation)
11796   (let ((children (mime-entity-children entity))
11797         mime-acting-situation-to-override
11798         f)
11799     (while children
11800       (mime-play-entity (car children)
11801                         (cons (assq 'mode situation)
11802                               mime-acting-situation-to-override))
11803       (setq children (cdr children)))
11804     (if (setq f (cdr (assq 'after-method
11805                            mime-acting-situation-to-override)))
11806         (eval f)
11807       )))
11808
11809 (mime-add-condition
11810  'action '((type . multipart)
11811            (method . gnus-mime-extract-multipart)
11812            (mode . "extract")
11813            )
11814  'with-default)
11815
11816
11817 ;;; @ end
11818 ;;;
11819
11820 (defun gnus-summary-inherit-default-charset ()
11821   "Import `default-mime-charset' from summary buffer.
11822 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11823 of FLIM is used."
11824   (if (buffer-live-p gnus-summary-buffer)
11825       (let (d-m-c d-m-c-u)
11826         (with-current-buffer gnus-summary-buffer
11827           (setq d-m-c (if (local-variable-p 'default-mime-charset
11828                                             gnus-summary-buffer)
11829                           default-mime-charset
11830                         t)
11831                 ;; LIMIT
11832                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11833                                               gnus-summary-buffer)
11834                             (symbol-value 'default-mime-charset-unlimited)
11835                           t)))
11836         (if (eq t d-m-c)
11837             (kill-local-variable 'default-mime-charset)
11838           (set (make-local-variable 'default-mime-charset) d-m-c))
11839         (if (eq t d-m-c-u)
11840             (kill-local-variable 'default-mime-charset-unlimited)
11841           (set (make-local-variable 'default-mime-charset-unlimited)
11842                d-m-c-u)))))
11843
11844 (defun gnus-summary-setup-default-charset ()
11845   "Setup newsgroup default charset."
11846   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11847       (progn
11848         (setq gnus-newsgroup-charset nil)
11849         (set (make-local-variable 'default-mime-charset) nil)
11850         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11851           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11852     (let ((ignored-charsets
11853            (or gnus-newsgroup-ephemeral-ignored-charsets
11854                (append
11855                 (and gnus-newsgroup-name
11856                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11857                 gnus-newsgroup-ignored-charsets)))
11858           charset)
11859       (setq gnus-newsgroup-charset
11860             (or gnus-newsgroup-ephemeral-charset
11861                 (when (and gnus-newsgroup-name
11862                            (setq charset (gnus-parameter-charset
11863                                           gnus-newsgroup-name)))
11864                   (make-local-variable 'default-mime-charset)
11865                   (setq default-mime-charset charset))
11866                 gnus-default-charset))
11867       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11868            ignored-charsets))))
11869
11870 ;;;
11871 ;;; Mime Commands
11872 ;;;
11873
11874 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11875   "Display the current article buffer fully MIME-buttonized.
11876 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11877 treated as multipart/mixed."
11878   (interactive "P")
11879   (require 'gnus-art)
11880   (let ((gnus-unbuttonized-mime-types nil)
11881         (gnus-mime-display-multipart-as-mixed show-all-parts))
11882     (gnus-summary-show-article)))
11883
11884 (defun gnus-summary-repair-multipart (article)
11885   "Add a Content-Type header to a multipart article without one."
11886   (interactive (list (gnus-summary-article-number)))
11887   (gnus-with-article article
11888     (message-narrow-to-head)
11889     (message-remove-header "Mime-Version")
11890     (goto-char (point-max))
11891     (insert "Mime-Version: 1.0\n")
11892     (widen)
11893     (when (search-forward "\n--" nil t)
11894       (let ((separator (buffer-substring (point) (point-at-eol))))
11895         (message-narrow-to-head)
11896         (message-remove-header "Content-Type")
11897         (goto-char (point-max))
11898         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11899                         separator))
11900         (widen))))
11901   (let (gnus-mark-article-hook)
11902     (gnus-summary-select-article t t nil article)))
11903
11904 (defun gnus-summary-toggle-display-buttonized ()
11905   "Toggle the buttonizing of the article buffer."
11906   (interactive)
11907   (require 'gnus-art)
11908   (if (setq gnus-inhibit-mime-unbuttonizing
11909             (not gnus-inhibit-mime-unbuttonizing))
11910       (let ((gnus-unbuttonized-mime-types nil))
11911         (gnus-summary-show-article))
11912     (gnus-summary-show-article)))
11913
11914 ;;;
11915 ;;; Intelli-mouse commmands
11916 ;;;
11917
11918 (defun gnus-wheel-summary-scroll (event)
11919   (interactive "e")
11920   (let ((amount (if (memq 'shift (event-modifiers event))
11921                     (car gnus-wheel-scroll-amount)
11922                   (cdr gnus-wheel-scroll-amount)))
11923         (direction (- (* (static-if (featurep 'xemacs)
11924                              (event-button event)
11925                            (cond ((eq 'mouse-4 (event-basic-type event))
11926                                   4)
11927                                  ((eq 'mouse-5 (event-basic-type event))
11928                                   5)))
11929                          2) 9))
11930         edge)
11931     (gnus-summary-scroll-up (* amount direction))
11932     (when (gnus-eval-in-buffer-window gnus-article-buffer
11933             (save-restriction
11934               (widen)
11935               (and (if (< 0 direction)
11936                        (gnus-article-next-page 0)
11937                      (gnus-article-prev-page 0)
11938                      (bobp))
11939                    (if (setq edge (get-text-property
11940                                    (point-min) 'gnus-wheel-edge))
11941                        (setq edge (* edge direction))
11942                      (setq edge -1))
11943                    (or (plusp edge)
11944                        (let ((buffer-read-only nil)
11945                              (inhibit-read-only t))
11946                          (put-text-property (point-min) (point-max)
11947                                             'gnus-wheel-edge direction)
11948                          nil))
11949                    (or (> edge gnus-wheel-edge-resistance)
11950                        (let ((buffer-read-only nil)
11951                              (inhibit-read-only t))
11952                          (put-text-property (point-min) (point-max)
11953                                             'gnus-wheel-edge
11954                                             (* (1+ edge) direction))
11955                          nil))
11956                    (eq last-command 'gnus-wheel-summary-scroll))))
11957       (gnus-summary-next-article nil nil (minusp direction)))))
11958
11959 (defun gnus-wheel-install ()
11960   "Enable mouse wheel support on summary window."
11961   (when gnus-use-wheel
11962     (let ((keys
11963            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11964       (dolist (key keys)
11965         (define-key gnus-summary-mode-map key
11966           'gnus-wheel-summary-scroll)))))
11967
11968 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11969
11970 ;;;
11971 ;;; Traditional PGP commmands
11972 ;;;
11973
11974 (defun gnus-summary-decrypt-article (&optional force)
11975   "Decrypt the current article in traditional PGP way.
11976 This will have permanent effect only in mail groups.
11977 If FORCE is non-nil, allow editing of articles even in read-only
11978 groups."
11979   (interactive "P")
11980   (gnus-summary-select-article t)
11981   (gnus-eval-in-buffer-window gnus-article-buffer
11982     (save-excursion
11983       (save-restriction
11984         (widen)
11985         (goto-char (point-min))
11986         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11987           (error "Not a traditional PGP message!"))
11988         (let ((armor-start (match-beginning 0)))
11989           (if (and (pgg-decrypt-region armor-start (point-max))
11990                    (or force (not (gnus-group-read-only-p))))
11991               (let ((inhibit-read-only t)
11992                     buffer-read-only)
11993                 (delete-region armor-start
11994                                (progn
11995                                  (re-search-forward "^-+END PGP" nil t)
11996                                  (beginning-of-line 2)
11997                                  (point)))
11998                 (insert-buffer-substring pgg-output-buffer))))))))
11999
12000 (defun gnus-summary-verify-article ()
12001   "Verify the current article in traditional PGP way."
12002   (interactive)
12003   (save-excursion
12004     (set-buffer gnus-original-article-buffer)
12005     (goto-char (point-min))
12006     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
12007       (error "Not a traditional PGP message!"))
12008     (re-search-forward "^-+END PGP" nil t)
12009     (beginning-of-line 2)
12010     (call-interactively (function pgg-verify-region))))
12011
12012 ;;;
12013 ;;; Generic summary marking commands
12014 ;;;
12015
12016 (defvar gnus-summary-marking-alist
12017   '((read gnus-del-mark "d")
12018     (unread gnus-unread-mark "u")
12019     (ticked gnus-ticked-mark "!")
12020     (dormant gnus-dormant-mark "?")
12021     (expirable gnus-expirable-mark "e"))
12022   "An alist of names/marks/keystrokes.")
12023
12024 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12025 (defvar gnus-summary-mark-map)
12026
12027 (defun gnus-summary-make-all-marking-commands ()
12028   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12029   (dolist (elem gnus-summary-marking-alist)
12030     (apply 'gnus-summary-make-marking-command elem)))
12031
12032 (defun gnus-summary-make-marking-command (name mark keystroke)
12033   (let ((map (make-sparse-keymap)))
12034     (define-key gnus-summary-generic-mark-map keystroke map)
12035     (dolist (lway `((next "next" next nil "n")
12036                     (next-unread "next unread" next t "N")
12037                     (prev "previous" prev nil "p")
12038                     (prev-unread "previous unread" prev t "P")
12039                     (nomove "" nil nil ,keystroke)))
12040       (let ((func (gnus-summary-make-marking-command-1
12041                    mark (car lway) lway name)))
12042         (setq func (eval func))
12043         (define-key map (nth 4 lway) func)))))
12044
12045 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12046   `(defun ,(intern
12047             (format "gnus-summary-put-mark-as-%s%s"
12048                     name (if (eq way 'nomove)
12049                              ""
12050                            (concat "-" (symbol-name way)))))
12051      (n)
12052      ,(format
12053        "Mark the current article as %s%s.
12054 If N, the prefix, then repeat N times.
12055 If N is negative, move in reverse order.
12056 The difference between N and the actual number of articles marked is
12057 returned."
12058        name (car (cdr lway)))
12059      (interactive "p")
12060      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12061
12062 (defun gnus-summary-generic-mark (n mark move unread)
12063   "Mark N articles with MARK."
12064   (unless (eq major-mode 'gnus-summary-mode)
12065     (error "This command can only be used in the summary buffer"))
12066   (gnus-summary-show-thread)
12067   (let ((nummove
12068          (cond
12069           ((eq move 'next) 1)
12070           ((eq move 'prev) -1)
12071           (t 0))))
12072     (if (zerop nummove)
12073         (setq n 1)
12074       (when (< n 0)
12075         (setq n (abs n)
12076               nummove (* -1 nummove))))
12077     (while (and (> n 0)
12078                 (gnus-summary-mark-article nil mark)
12079                 (zerop (gnus-summary-next-subject nummove unread t)))
12080       (setq n (1- n)))
12081     (when (/= 0 n)
12082       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12083     (gnus-summary-recenter)
12084     (gnus-summary-position-point)
12085     (gnus-set-mode-line 'summary)
12086     n))
12087
12088 (defun gnus-summary-insert-articles (articles)
12089   (when (setq articles
12090               (gnus-sorted-difference articles
12091                                       (mapcar (lambda (h)
12092                                                 (mail-header-number h))
12093                                               gnus-newsgroup-headers)))
12094     (setq gnus-newsgroup-headers
12095           (gnus-merge 'list
12096                       gnus-newsgroup-headers
12097                       (gnus-fetch-headers articles)
12098                       'gnus-article-sort-by-number))
12099     ;; Suppress duplicates?
12100     (when gnus-suppress-duplicates
12101       (gnus-dup-suppress-articles))
12102
12103     ;; We might want to build some more threads first.
12104     (when (and gnus-fetch-old-headers
12105                (eq gnus-headers-retrieved-by 'nov))
12106       (if (eq gnus-fetch-old-headers 'invisible)
12107           (gnus-build-all-threads)
12108         (gnus-build-old-threads)))
12109     ;; Let the Gnus agent mark articles as read.
12110     (when gnus-agent
12111       (gnus-agent-get-undownloaded-list))
12112     ;; Remove list identifiers from subject
12113     (when gnus-list-identifiers
12114       (gnus-summary-remove-list-identifiers))
12115     ;; First and last article in this newsgroup.
12116     (when gnus-newsgroup-headers
12117       (setq gnus-newsgroup-begin
12118             (mail-header-number (car gnus-newsgroup-headers))
12119             gnus-newsgroup-end
12120             (mail-header-number
12121              (gnus-last-element gnus-newsgroup-headers))))
12122     (when gnus-use-scoring
12123       (gnus-possibly-score-headers))))
12124
12125 (defun gnus-summary-insert-old-articles (&optional all)
12126   "Insert all old articles in this group.
12127 If ALL is non-nil, already read articles become readable.
12128 If ALL is a number, fetch this number of articles."
12129   (interactive "P")
12130   (prog1
12131       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12132             older len)
12133         (setq older
12134               ;; Some nntp servers lie about their active range.  When
12135               ;; this happens, the active range can be in the millions.
12136               ;; Use a compressed range to avoid creating a huge list.
12137               (gnus-range-difference (list gnus-newsgroup-active) old))
12138         (setq len (gnus-range-length older))
12139         (cond
12140          ((null older) nil)
12141          ((numberp all)
12142           (if (< all len)
12143               (let ((older-range (nreverse older)))
12144                 (setq older nil)
12145
12146                 (while (> all 0)
12147                   (let* ((r (pop older-range))
12148                          (min (if (numberp r) r (car r)))
12149                          (max (if (numberp r) r (cdr r))))
12150                     (while (and (<= min max)
12151                                 (> all 0))
12152                       (push max older)
12153                       (setq all (1- all)
12154                             max (1- max))))))
12155             (setq older (gnus-uncompress-range older))))
12156          (all
12157           (setq older (gnus-uncompress-range older)))
12158          (t
12159           (when (and (numberp gnus-large-newsgroup)
12160                    (> len gnus-large-newsgroup))
12161               (let* ((cursor-in-echo-area nil)
12162                      (initial (gnus-parameter-large-newsgroup-initial
12163                                gnus-newsgroup-name))
12164                      (input
12165                       (read-string
12166                        (format
12167                         "How many articles from %s (%s %d): "
12168                         (gnus-limit-string
12169                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12170                         (if initial "max" "default")
12171                         len)
12172                        (if initial
12173                            (cons (number-to-string initial)
12174                                  0)))))
12175                 (unless (string-match "^[ \t]*$" input)
12176                   (setq all (string-to-number input))
12177                   (if (< all len)
12178                       (let ((older-range (nreverse older)))
12179                         (setq older nil)
12180
12181                         (while (> all 0)
12182                           (let* ((r (pop older-range))
12183                                  (min (if (numberp r) r (car r)))
12184                                  (max (if (numberp r) r (cdr r))))
12185                             (while (and (<= min max)
12186                                         (> all 0))
12187                               (push max older)
12188                               (setq all (1- all)
12189                                     max (1- max))))))))))
12190           (setq older (gnus-uncompress-range older))))
12191         (if (not older)
12192             (message "No old news.")
12193           (gnus-summary-insert-articles older)
12194           (gnus-summary-limit (gnus-sorted-nunion old older))))
12195     (gnus-summary-position-point)))
12196
12197 (defun gnus-summary-insert-new-articles ()
12198   "Insert all new articles in this group."
12199   (interactive)
12200   (prog1
12201       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12202             (old-active gnus-newsgroup-active)
12203             (nnmail-fetched-sources (list t))
12204             i new)
12205         (setq gnus-newsgroup-active
12206               (gnus-activate-group gnus-newsgroup-name 'scan))
12207         (setq i (cdr gnus-newsgroup-active))
12208         (while (> i (cdr old-active))
12209           (push i new)
12210           (decf i))
12211         (if (not new)
12212             (message "No gnus is bad news")
12213           (gnus-summary-insert-articles new)
12214           (setq gnus-newsgroup-unreads
12215                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12216           (gnus-summary-limit (gnus-sorted-nunion old new))))
12217     (gnus-summary-position-point)))
12218
12219 (gnus-summary-make-all-marking-commands)
12220
12221 (gnus-ems-redefine)
12222
12223 (provide 'gnus-sum)
12224
12225 (run-hooks 'gnus-sum-load-hook)
12226
12227 ;; Local Variables:
12228 ;; coding: iso-8859-1
12229 ;; End:
12230
12231 ;;; gnus-sum.el ends here