Synch to No Gnus 200510290912.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
9 ;; Keywords: mail, news, MIME
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
27
28 ;;; Commentary:
29
30 ;;; Code:
31
32 (eval-when-compile
33   (require 'cl)
34   (defvar tool-bar-map))
35
36 (require 'gnus)
37 (require 'gnus-group)
38 (require 'gnus-spec)
39 (require 'gnus-range)
40 (require 'gnus-int)
41 (require 'gnus-undo)
42 (require 'gnus-util)
43 (require 'nnoo)
44
45 (eval-when-compile
46   (require 'mime-play)
47   (require 'static))
48
49 (eval-and-compile
50   (autoload 'pgg-decrypt-region "pgg" nil t)
51   (autoload 'pgg-verify-region "pgg" nil t))
52
53 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
54 (autoload 'gnus-cache-write-active "gnus-cache")
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
58 (autoload 'mm-uu-dissect "mm-uu")
59 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
60   "Deuglify broken Outlook (Express) articles and redisplay."
61   t)
62 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
63 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
64 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
65
66 (defcustom gnus-kill-summary-on-exit t
67   "*If non-nil, kill the summary buffer when you exit from it.
68 If nil, the summary will become a \"*Dead Summary*\" buffer, and
69 it will be killed sometime later."
70   :group 'gnus-summary-exit
71   :type 'boolean)
72
73 (defcustom gnus-fetch-old-headers nil
74   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
75 If an unread article in the group refers to an older, already read (or
76 just marked as read) article, the old article will not normally be
77 displayed in the Summary buffer.  If this variable is t, Gnus
78 will attempt to grab the headers to the old articles, and thereby
79 build complete threads.  If it has the value `some', only enough
80 headers to connect otherwise loose threads will be displayed.  This
81 variable can also be a number.  In that case, no more than that number
82 of old headers will be fetched.  If it has the value `invisible', all
83 old headers will be fetched, but none will be displayed.
84
85 The server has to support NOV for any of this to work."
86   :group 'gnus-thread
87   :type '(choice (const :tag "off" nil)
88                  (const :tag "on" t)
89                  (const some)
90                  (const invisible)
91                  number
92                  (sexp :menu-tag "other" t)))
93
94 (defcustom gnus-refer-thread-limit 200
95   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
96 If t, fetch all the available old headers."
97   :group 'gnus-thread
98   :type '(choice number
99                  (sexp :menu-tag "other" t)))
100
101 (defcustom gnus-summary-make-false-root 'adopt
102   "*nil means that Gnus won't gather loose threads.
103 If the root of a thread has expired or been read in a previous
104 session, the information necessary to build a complete thread has been
105 lost.  Instead of having many small sub-threads from this original thread
106 scattered all over the summary buffer, Gnus can gather them.
107
108 If non-nil, Gnus will try to gather all loose sub-threads from an
109 original thread into one large thread.
110
111 If this variable is non-nil, it should be one of `none', `adopt',
112 `dummy' or `empty'.
113
114 If this variable is `none', Gnus will not make a false root, but just
115 present the sub-threads after another.
116 If this variable is `dummy', Gnus will create a dummy root that will
117 have all the sub-threads as children.
118 If this variable is `adopt', Gnus will make one of the \"children\"
119 the parent and mark all the step-children as such.
120 If this variable is `empty', the \"children\" are printed with empty
121 subject fields.  (Or rather, they will be printed with a string
122 given by the `gnus-summary-same-subject' variable.)"
123   :group 'gnus-thread
124   :type '(choice (const :tag "off" nil)
125                  (const none)
126                  (const dummy)
127                  (const adopt)
128                  (const empty)))
129
130 (defcustom gnus-summary-make-false-root-always nil
131   "Always make a false dummy root."
132   :version "22.1"
133   :group 'gnus-thread
134   :type 'boolean)
135
136 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
137   "*A regexp to match subjects to be excluded from loose thread gathering.
138 As loose thread gathering is done on subjects only, that means that
139 there can be many false gatherings performed.  By rooting out certain
140 common subjects, gathering might become saner."
141   :group 'gnus-thread
142   :type 'regexp)
143
144 (defcustom gnus-summary-gather-subject-limit nil
145   "*Maximum length of subject comparisons when gathering loose threads.
146 Use nil to compare full subjects.  Setting this variable to a low
147 number will help gather threads that have been corrupted by
148 newsreaders chopping off subject lines, but it might also mean that
149 unrelated articles that have subject that happen to begin with the
150 same few characters will be incorrectly gathered.
151
152 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
153 comparing subjects."
154   :group 'gnus-thread
155   :type '(choice (const :tag "off" nil)
156                  (const fuzzy)
157                  (sexp :menu-tag "on" t)))
158
159 (defcustom gnus-simplify-subject-functions nil
160   "List of functions taking a string argument that simplify subjects.
161 The functions are applied recursively.
162
163 Useful functions to put in this list include:
164 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
165 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
166   :group 'gnus-thread
167   :type '(repeat function))
168
169 (defcustom gnus-simplify-ignored-prefixes nil
170   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
171   :group 'gnus-thread
172   :type '(choice (const :tag "off" nil)
173                  regexp))
174
175 (defcustom gnus-build-sparse-threads nil
176   "*If non-nil, fill in the gaps in threads.
177 If `some', only fill in the gaps that are needed to tie loose threads
178 together.  If `more', fill in all leaf nodes that Gnus can find.  If
179 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
180   :group 'gnus-thread
181   :type '(choice (const :tag "off" nil)
182                  (const some)
183                  (const more)
184                  (sexp :menu-tag "all" t)))
185
186 (defcustom gnus-summary-thread-gathering-function
187   'gnus-gather-threads-by-subject
188   "*Function used for gathering loose threads.
189 There are two pre-defined functions: `gnus-gather-threads-by-subject',
190 which only takes Subjects into consideration; and
191 `gnus-gather-threads-by-references', which compared the References
192 headers of the articles to find matches."
193   :group 'gnus-thread
194   :type '(radio (function-item gnus-gather-threads-by-subject)
195                 (function-item gnus-gather-threads-by-references)
196                 (function :tag "other")))
197
198 (defcustom gnus-summary-same-subject ""
199   "*String indicating that the current article has the same subject as the previous.
200 This variable will only be used if the value of
201 `gnus-summary-make-false-root' is `empty'."
202   :group 'gnus-summary-format
203   :type 'string)
204
205 (defcustom gnus-summary-goto-unread t
206   "*If t, many commands will go to the next unread article.
207 This applies to marking commands as well as other commands that
208 \"naturally\" select the next article, like, for instance, `SPC' at
209 the end of an article.
210
211 If nil, the marking commands do NOT go to the next unread article
212 \(they go to the next article instead).  If `never', commands that
213 usually go to the next unread article, will go to the next article,
214 whether it is read or not."
215   :group 'gnus-summary-marks
216   :link '(custom-manual "(gnus)Setting Marks")
217   :type '(choice (const :tag "off" nil)
218                  (const never)
219                  (sexp :menu-tag "on" t)))
220
221 (defcustom gnus-summary-default-score 0
222   "*Default article score level.
223 All scores generated by the score files will be added to this score.
224 If this variable is nil, scoring will be disabled."
225   :group 'gnus-score-default
226   :type '(choice (const :tag "disable")
227                  integer))
228
229 (defcustom gnus-summary-default-high-score 0
230   "*Default threshold for a high scored article.
231 An article will be highlighted as high scored if its score is greater
232 than this score."
233   :version "22.1"
234   :group 'gnus-score-default
235   :type 'integer)
236
237 (defcustom gnus-summary-default-low-score 0
238   "*Default threshold for a low scored article.
239 An article will be highlighted as low scored if its score is smaller
240 than this score."
241   :version "22.1"
242   :group 'gnus-score-default
243   :type 'integer)
244
245 (defcustom gnus-summary-zcore-fuzz 0
246   "*Fuzziness factor for the zcore in the summary buffer.
247 Articles with scores closer than this to `gnus-summary-default-score'
248 will not be marked."
249   :group 'gnus-summary-format
250   :type 'integer)
251
252 (defcustom gnus-simplify-subject-fuzzy-regexp nil
253   "*Strings to be removed when doing fuzzy matches.
254 This can either be a regular expression or list of regular expressions
255 that will be removed from subject strings if fuzzy subject
256 simplification is selected."
257   :group 'gnus-thread
258   :type '(repeat regexp))
259
260 (defcustom gnus-show-threads t
261   "*If non-nil, display threads in summary mode."
262   :group 'gnus-thread
263   :type 'boolean)
264
265 (defcustom gnus-thread-hide-subtree nil
266   "*If non-nil, hide all threads initially.
267 This can be a predicate specifier which says which threads to hide.
268 If threads are hidden, you have to run the command
269 `gnus-summary-show-thread' by hand or or select an article."
270   :group 'gnus-thread
271   :type '(radio (sexp :format "Non-nil\n"
272                       :match (lambda (widget value)
273                                (not (or (consp value) (functionp value))))
274                       :value t)
275                 (const nil)
276                 (sexp :tag "Predicate specifier")))
277
278 (defcustom gnus-thread-hide-killed t
279   "*If non-nil, hide killed threads automatically."
280   :group 'gnus-thread
281   :type 'boolean)
282
283 (defcustom gnus-thread-ignore-subject t
284   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
285 If nil, articles that have different subjects from their parents will
286 start separate threads."
287   :group 'gnus-thread
288   :type 'boolean)
289
290 (defcustom gnus-thread-operation-ignore-subject t
291   "*If non-nil, subjects will be ignored when doing thread commands.
292 This affects commands like `gnus-summary-kill-thread' and
293 `gnus-summary-lower-thread'.
294
295 If this variable is nil, articles in the same thread with different
296 subjects will not be included in the operation in question.  If this
297 variable is `fuzzy', only articles that have subjects that are fuzzily
298 equal will be included."
299   :group 'gnus-thread
300   :type '(choice (const :tag "off" nil)
301                  (const fuzzy)
302                  (sexp :tag "on" t)))
303
304 (defcustom gnus-thread-indent-level 4
305   "*Number that says how much each sub-thread should be indented."
306   :group 'gnus-thread
307   :type 'integer)
308
309 (defcustom gnus-auto-extend-newsgroup t
310   "*If non-nil, extend newsgroup forward and backward when requested."
311   :group 'gnus-summary-choose
312   :type 'boolean)
313
314 (defcustom gnus-auto-select-first t
315   "*If non-nil, select the article under point.
316 Which article this is is controlled by the `gnus-auto-select-subject'
317 variable.
318
319 If you want to prevent automatic selection of articles in some
320 newsgroups, set the variable to nil in `gnus-select-group-hook'."
321   :group 'gnus-group-select
322   :type '(choice (const :tag "none" nil)
323                  (sexp :menu-tag "first" t)))
324
325 (defcustom gnus-auto-select-subject 'unread
326   "*Says what subject to place under point when entering a group.
327
328 This variable can either be the symbols `first' (place point on the
329 first subject), `unread' (place point on the subject line of the first
330 unread article), `best' (place point on the subject line of the
331 higest-scored article), `unseen' (place point on the subject line of
332 the first unseen article), `unseen-or-unread' (place point on the subject
333 line of the first unseen article or, if all article have been seen, on the
334 subject line of the first unread article), or a function to be called to
335 place point on some subject line."
336   :version "22.1"
337   :group 'gnus-group-select
338   :type '(choice (const best)
339                  (const unread)
340                  (const first)
341                  (const unseen)
342                  (const unseen-or-unread)))
343
344 (defcustom gnus-dont-select-after-jump-to-other-group nil
345   "If non-nil, don't select the first unread article after entering the
346 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
347 it is depend on the value of `gnus-auto-select-first' whether to select
348 or not."
349   :group 'gnus-group-select
350   :type 'boolean)
351
352 (defcustom gnus-auto-select-next t
353   "*If non-nil, offer to go to the next group from the end of the previous.
354 If the value is t and the next newsgroup is empty, Gnus will exit
355 summary mode and go back to group mode.  If the value is neither nil
356 nor t, Gnus will select the following unread newsgroup.  In
357 particular, if the value is the symbol `quietly', the next unread
358 newsgroup will be selected without any confirmation, and if it is
359 `almost-quietly', the next group will be selected without any
360 confirmation if you are located on the last article in the group.
361 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
362 will go to the next group without confirmation."
363   :group 'gnus-summary-maneuvering
364   :type '(choice (const :tag "off" nil)
365                  (const quietly)
366                  (const almost-quietly)
367                  (const slightly-quietly)
368                  (sexp :menu-tag "on" t)))
369
370 (defcustom gnus-auto-select-same nil
371   "*If non-nil, select the next article with the same subject.
372 If there are no more articles with the same subject, go to
373 the first unread article."
374   :group 'gnus-summary-maneuvering
375   :type 'boolean)
376
377 (defcustom gnus-auto-goto-ignores 'unfetched
378   "*Says how to handle unfetched articles when maneuvering.
379
380 This variable can either be the symbols nil (maneuver to any
381 article), `undownloaded' (maneuvering while unplugged ignores articles
382 that have not been fetched), `always-undownloaded' (maneuvering always
383 ignores articles that have not been fetched), `unfetched' (maneuvering
384 ignores articles whose headers have not been fetched).
385
386 NOTE: The list of unfetched articles will always be nil when plugged
387 and, when unplugged, a subset of the undownloaded article list."
388   :version "22.1"
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "None" nil)
391                  (const :tag "Undownloaded when unplugged" undownloaded)
392                  (const :tag "Undownloaded" always-undownloaded)
393                  (const :tag "Unfetched" unfetched)))
394
395 (defcustom gnus-summary-check-current nil
396   "*If non-nil, consider the current article when moving.
397 The \"unread\" movement commands will stay on the same line if the
398 current article is unread."
399   :group 'gnus-summary-maneuvering
400   :type 'boolean)
401
402 (defcustom gnus-auto-center-summary 2
403   "*If non-nil, always center the current summary buffer.
404 In particular, if `vertical' do only vertical recentering.  If non-nil
405 and non-`vertical', do both horizontal and vertical recentering."
406   :group 'gnus-summary-maneuvering
407   :type '(choice (const :tag "none" nil)
408                  (const vertical)
409                  (integer :tag "height")
410                  (sexp :menu-tag "both" t)))
411
412 (defvar gnus-auto-center-group t
413   "*If non-nil, always center the group buffer.")
414
415 (defcustom gnus-show-all-headers nil
416   "*If non-nil, don't hide any headers."
417   :group 'gnus-article-hiding
418   :group 'gnus-article-headers
419   :type 'boolean)
420
421 (defcustom gnus-summary-ignore-duplicates nil
422   "*If non-nil, ignore articles with identical Message-ID headers."
423   :group 'gnus-summary
424   :type 'boolean)
425
426 (defcustom gnus-single-article-buffer t
427   "*If non-nil, display all articles in the same buffer.
428 If nil, each group will get its own article buffer."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-break-pages t
433   "*If non-nil, do page breaking on articles.
434 The page delimiter is specified by the `gnus-page-delimiter'
435 variable."
436   :group 'gnus-article-various
437   :type 'boolean)
438
439 (defcustom gnus-show-mime t
440   "*If non-nil, do mime processing of articles.
441 The articles will simply be fed to the function given by
442 `gnus-article-display-method-for-mime'."
443   :group 'gnus-article-mime
444   :type 'boolean)
445
446 (defcustom gnus-move-split-methods nil
447   "*Variable used to suggest where articles are to be moved to.
448 It uses the same syntax as the `gnus-split-methods' variable.
449 However, whereas `gnus-split-methods' specifies file names as targets,
450 this variable specifies group names."
451   :group 'gnus-summary-mail
452   :type '(repeat (choice (list :value (fun) function)
453                          (cons :value ("" "") regexp (repeat string))
454                          (sexp :value nil))))
455
456 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
457   "Function used to compute default prefix for article move/copy/etc prompts.
458 The function should take one argument, a group name, and return a
459 string with the suggested prefix."
460   :group 'gnus-summary-mail
461   :type 'function)
462
463 ;; FIXME: Although the custom type is `character' for the following variables,
464 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
465
466 (defcustom gnus-unread-mark ?\ ;;;Whitespace
467   "*Mark used for unread articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ticked-mark ?!
472   "*Mark used for ticked articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-dormant-mark ??
477   "*Mark used for dormant articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-del-mark ?r
482   "*Mark used for del'd articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-read-mark ?R
487   "*Mark used for read articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-expirable-mark ?E
492   "*Mark used for expirable articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-killed-mark ?K
497   "*Mark used for killed articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-spam-mark ?$
502   "*Mark used for spam articles."
503   :version "22.1"
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-souped-mark ?F
508   "*Mark used for souped articles."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-kill-file-mark ?X
513   "*Mark used for articles killed by kill files."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-low-score-mark ?Y
518   "*Mark used for articles with a low score."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-catchup-mark ?C
523   "*Mark used for articles that are caught up."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-replied-mark ?A
528   "*Mark used for articles that have been replied to."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-forwarded-mark ?F
533   "*Mark used for articles that have been forwarded."
534   :version "22.1"
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-recent-mark ?N
539   "*Mark used for articles that are recent."
540   :version "22.1"
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-cached-mark ?*
545   "*Mark used for articles that are in the cache."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-saved-mark ?S
550   "*Mark used for articles that have been saved."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-unseen-mark ?.
555   "*Mark used for articles that haven't been seen."
556   :version "22.1"
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-no-mark ?\ ;;;Whitespace
561   "*Mark used for articles that have no other secondary mark."
562   :version "22.1"
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-ancient-mark ?O
567   "*Mark used for ancient articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-sparse-mark ?Q
572   "*Mark used for sparsely reffed articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-canceled-mark ?G
577   "*Mark used for canceled articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-duplicate-mark ?M
582   "*Mark used for duplicate articles."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-undownloaded-mark ?-
587   "*Mark used for articles that weren't downloaded."
588   :version "22.1"
589   :group 'gnus-summary-marks
590   :type 'character)
591
592 (defcustom gnus-downloaded-mark ?+
593   "*Mark used for articles that were downloaded."
594   :group 'gnus-summary-marks
595   :type 'character)
596
597 (defcustom gnus-downloadable-mark ?%
598   "*Mark used for articles that are to be downloaded."
599   :group 'gnus-summary-marks
600   :type 'character)
601
602 (defcustom gnus-unsendable-mark ?=
603   "*Mark used for articles that won't be sent."
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-score-over-mark ?+
608   "*Score mark used for articles with high scores."
609   :group 'gnus-summary-marks
610   :type 'character)
611
612 (defcustom gnus-score-below-mark ?-
613   "*Score mark used for articles with low scores."
614   :group 'gnus-summary-marks
615   :type 'character)
616
617 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
618   "*There is no thread under the article."
619   :group 'gnus-summary-marks
620   :type 'character)
621
622 (defcustom gnus-not-empty-thread-mark ?=
623   "*There is a thread under the article."
624   :group 'gnus-summary-marks
625   :type 'character)
626
627 (defcustom gnus-view-pseudo-asynchronously nil
628   "*If non-nil, Gnus will view pseudo-articles asynchronously."
629   :group 'gnus-extract-view
630   :type 'boolean)
631
632 (defcustom gnus-auto-expirable-marks
633   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
634         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
635         gnus-souped-mark gnus-duplicate-mark)
636   "*The list of marks converted into expiration if a group is auto-expirable."
637   :version "21.1"
638   :group 'gnus-summary
639   :type '(repeat character))
640
641 (defcustom gnus-inhibit-user-auto-expire t
642   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
643   :version "21.1"
644   :group 'gnus-summary
645   :type 'boolean)
646
647 (defcustom gnus-view-pseudos nil
648   "*If `automatic', pseudo-articles will be viewed automatically.
649 If `not-confirm', pseudos will be viewed automatically, and the user
650 will not be asked to confirm the command."
651   :group 'gnus-extract-view
652   :type '(choice (const :tag "off" nil)
653                  (const automatic)
654                  (const not-confirm)))
655
656 (defcustom gnus-view-pseudos-separately t
657   "*If non-nil, one pseudo-article will be created for each file to be viewed.
658 If nil, all files that use the same viewing command will be given as a
659 list of parameters to that command."
660   :group 'gnus-extract-view
661   :type 'boolean)
662
663 (defcustom gnus-insert-pseudo-articles t
664   "*If non-nil, insert pseudo-articles when decoding articles."
665   :group 'gnus-extract-view
666   :type 'boolean)
667
668 (defcustom gnus-summary-dummy-line-format
669   "   %(:                             :%) %S\n"
670   "*The format specification for the dummy roots in the summary buffer.
671 It works along the same lines as a normal formatting string,
672 with some simple extensions.
673
674 %S  The subject
675
676 General format specifiers can also be used.
677 See `(gnus)Formatting Variables'."
678   :link '(custom-manual "(gnus)Formatting Variables")
679   :group 'gnus-threading
680   :type 'string)
681
682 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
683   "*The format specification for the summary mode line.
684 It works along the same lines as a normal formatting string,
685 with some simple extensions:
686
687 %G  Group name
688 %p  Unprefixed group name
689 %A  Current article number
690 %z  Current article score
691 %V  Gnus version
692 %U  Number of unread articles in the group
693 %e  Number of unselected articles in the group
694 %Z  A string with unread/unselected article counts
695 %g  Shortish group name
696 %S  Subject of the current article
697 %u  User-defined spec
698 %s  Current score file name
699 %d  Number of dormant articles
700 %r  Number of articles that have been marked as read in this session
701 %E  Number of articles expunged by the score files"
702   :group 'gnus-summary-format
703   :type 'string)
704
705 (defcustom gnus-list-identifiers nil
706   "Regexp that matches list identifiers to be removed from subject.
707 This can also be a list of regexps."
708   :version "21.1"
709   :group 'gnus-summary-format
710   :group 'gnus-article-hiding
711   :type '(choice (const :tag "none" nil)
712                  (regexp :value ".*")
713                  (repeat :value (".*") regexp)))
714
715 (defcustom gnus-summary-mark-below 0
716   "*Mark all articles with a score below this variable as read.
717 This variable is local to each summary buffer and usually set by the
718 score file."
719   :group 'gnus-score-default
720   :type 'integer)
721
722 (defun gnus-widget-reversible-match (widget value)
723   "Ignoring WIDGET, convert VALUE to internal form.
724 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
725   ;; (debug value)
726   (or (symbolp value)
727       (and (listp value)
728            (eq (length value) 2)
729            (eq (nth 0 value) 'not)
730            (symbolp (nth 1 value)))))
731
732 (defun gnus-widget-reversible-to-internal (widget value)
733   "Ignoring WIDGET, convert VALUE to internal form.
734 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
735 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
736   ;; (debug value)
737   (if (atom value)
738       (list value nil)
739     (list (nth 1 value) t)))
740
741 (defun gnus-widget-reversible-to-external (widget value)
742   "Ignoring WIDGET, convert VALUE to external form.
743 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
744 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
745   ;; (debug value)
746   (if (nth 1 value)
747       (list 'not (nth 0 value))
748     (nth 0 value)))
749
750 (define-widget 'gnus-widget-reversible 'group
751   "A `group' that convert values."
752   :match 'gnus-widget-reversible-match
753   :value-to-internal 'gnus-widget-reversible-to-internal
754   :value-to-external 'gnus-widget-reversible-to-external)
755
756 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
757   "*List of functions used for sorting articles in the summary buffer.
758
759 Each function takes two articles and returns non-nil if the first
760 article should be sorted before the other.  If you use more than one
761 function, the primary sort function should be the last.  You should
762 probably always include `gnus-article-sort-by-number' in the list of
763 sorting functions -- preferably first.  Also note that sorting by date
764 is often much slower than sorting by number, and the sorting order is
765 very similar.  (Sorting by date means sorting by the time the message
766 was sent, sorting by number means sorting by arrival time.)
767
768 Each item can also be a list `(not F)' where F is a function;
769 this reverses the sort order.
770
771 Ready-made functions include `gnus-article-sort-by-number',
772 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
773 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
774 and `gnus-article-sort-by-score'.
775
776 When threading is turned on, the variable `gnus-thread-sort-functions'
777 controls how articles are sorted."
778   :group 'gnus-summary-sort
779   :type '(repeat (gnus-widget-reversible
780                   (choice (function-item gnus-article-sort-by-number)
781                           (function-item gnus-article-sort-by-author)
782                           (function-item gnus-article-sort-by-subject)
783                           (function-item gnus-article-sort-by-date)
784                           (function-item gnus-article-sort-by-score)
785                           (function-item gnus-article-sort-by-random)
786                           (function :tag "other"))
787                   (boolean :tag "Reverse order"))))
788
789
790 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
791   "*List of functions used for sorting threads in the summary buffer.
792 By default, threads are sorted by article number.
793
794 Each function takes two threads and returns non-nil if the first
795 thread should be sorted before the other.  If you use more than one
796 function, the primary sort function should be the last.  You should
797 probably always include `gnus-thread-sort-by-number' in the list of
798 sorting functions -- preferably first.  Also note that sorting by date
799 is often much slower than sorting by number, and the sorting order is
800 very similar.  (Sorting by date means sorting by the time the message
801 was sent, sorting by number means sorting by arrival time.)
802
803 Each list item can also be a list `(not F)' where F is a
804 function; this specifies reversed sort order.
805
806 Ready-made functions include `gnus-thread-sort-by-number',
807 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
808 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
809 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
810 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
811 and `gnus-thread-sort-by-total-score' (see
812 `gnus-thread-score-function').
813
814 When threading is turned off, the variable
815 `gnus-article-sort-functions' controls how articles are sorted."
816   :group 'gnus-summary-sort
817   :type '(repeat
818           (gnus-widget-reversible
819            (choice (function-item gnus-thread-sort-by-number)
820                    (function-item gnus-thread-sort-by-author)
821                    (function-item gnus-thread-sort-by-recipient)
822                    (function-item gnus-thread-sort-by-subject)
823                    (function-item gnus-thread-sort-by-date)
824                    (function-item gnus-thread-sort-by-score)
825                    (function-item gnus-thread-sort-by-most-recent-number)
826                    (function-item gnus-thread-sort-by-most-recent-date)
827                    (function-item gnus-thread-sort-by-random)
828                    (function-item gnus-thread-sort-by-total-score)
829                    (function :tag "other"))
830            (boolean :tag "Reverse order"))))
831
832 (defcustom gnus-thread-score-function '+
833   "*Function used for calculating the total score of a thread.
834
835 The function is called with the scores of the article and each
836 subthread and should then return the score of the thread.
837
838 Some functions you can use are `+', `max', or `min'."
839   :group 'gnus-summary-sort
840   :type 'function)
841
842 (defcustom gnus-summary-expunge-below nil
843   "All articles that have a score less than this variable will be expunged.
844 This variable is local to the summary buffers."
845   :group 'gnus-score-default
846   :type '(choice (const :tag "off" nil)
847                  integer))
848
849 (defcustom gnus-thread-expunge-below nil
850   "All threads that have a total score less than this variable will be expunged.
851 See `gnus-thread-score-function' for en explanation of what a
852 \"thread score\" is.
853
854 This variable is local to the summary buffers."
855   :group 'gnus-threading
856   :group 'gnus-score-default
857   :type '(choice (const :tag "off" nil)
858                  integer))
859
860 (defcustom gnus-summary-mode-hook nil
861   "*A hook for Gnus summary mode.
862 This hook is run before any variables are set in the summary buffer."
863   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
864   :group 'gnus-summary-various
865   :type 'hook)
866
867 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
868 (when (featurep 'xemacs)
869   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
870   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
871   (add-hook 'gnus-summary-mode-hook
872             'gnus-xmas-switch-horizontal-scrollbar-off))
873
874 (defcustom gnus-summary-menu-hook nil
875   "*Hook run after the creation of the summary mode menu."
876   :group 'gnus-summary-visual
877   :type 'hook)
878
879 (defcustom gnus-summary-exit-hook nil
880   "*A hook called on exit from the summary buffer.
881 It will be called with point in the group buffer."
882   :group 'gnus-summary-exit
883   :type 'hook)
884
885 (defcustom gnus-summary-prepare-hook nil
886   "*A hook called after the summary buffer has been generated.
887 If you want to modify the summary buffer, you can use this hook."
888   :group 'gnus-summary-various
889   :type 'hook)
890
891 (defcustom gnus-summary-prepared-hook nil
892   "*A hook called as the last thing after the summary buffer has been generated."
893   :group 'gnus-summary-various
894   :type 'hook)
895
896 (defcustom gnus-summary-generate-hook nil
897   "*A hook run just before generating the summary buffer.
898 This hook is commonly used to customize threading variables and the
899 like."
900   :group 'gnus-summary-various
901   :type 'hook)
902
903 (defcustom gnus-select-group-hook nil
904   "*A hook called when a newsgroup is selected.
905
906 If you'd like to simplify subjects like the
907 `gnus-summary-next-same-subject' command does, you can use the
908 following hook:
909
910  (add-hook gnus-select-group-hook
911            (lambda ()
912              (mapcar (lambda (header)
913                        (mail-header-set-subject
914                         header
915                         (gnus-simplify-subject
916                          (mail-header-subject header) 're-only)))
917                      gnus-newsgroup-headers)))"
918   :group 'gnus-group-select
919   :type 'hook)
920
921 (defcustom gnus-select-article-hook nil
922   "*A hook called when an article is selected."
923   :group 'gnus-summary-choose
924   :options '(gnus-agent-fetch-selected-article)
925   :type 'hook)
926
927 (defcustom gnus-visual-mark-article-hook
928   (list 'gnus-highlight-selected-summary)
929   "*Hook run after selecting an article in the summary buffer.
930 It is meant to be used for highlighting the article in some way.  It
931 is not run if `gnus-visual' is nil."
932   :group 'gnus-summary-visual
933   :type 'hook)
934
935 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
936   "*A hook called before parsing the headers."
937   :group 'gnus-various
938   :type 'hook)
939
940 (defcustom gnus-exit-group-hook nil
941   "*A hook called when exiting summary mode.
942 This hook is not called from the non-updating exit commands like `Q'."
943   :group 'gnus-various
944   :type 'hook)
945
946 (defcustom gnus-summary-update-hook
947   (list 'gnus-summary-highlight-line)
948   "*A hook called when a summary line is changed.
949 The hook will not be called if `gnus-visual' is nil.
950
951 The default function `gnus-summary-highlight-line' will
952 highlight the line according to the `gnus-summary-highlight'
953 variable."
954   :group 'gnus-summary-visual
955   :type 'hook)
956
957 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
958   "*A hook called when an article is selected for the first time.
959 The hook is intended to mark an article as read (or unread)
960 automatically when it is selected."
961   :group 'gnus-summary-choose
962   :type 'hook)
963
964 (defcustom gnus-group-no-more-groups-hook nil
965   "*A hook run when returning to group mode having no more (unread) groups."
966   :group 'gnus-group-select
967   :type 'hook)
968
969 (defcustom gnus-ps-print-hook nil
970   "*A hook run before ps-printing something from Gnus."
971   :group 'gnus-summary
972   :type 'hook)
973
974 (defcustom gnus-summary-article-move-hook nil
975   "*A hook called after an article is moved, copied, respooled, or crossposted."
976   :version "22.1"
977   :group 'gnus-summary
978   :type 'hook)
979
980 (defcustom gnus-summary-article-delete-hook nil
981   "*A hook called after an article is deleted."
982   :version "22.1"
983   :group 'gnus-summary
984   :type 'hook)
985
986 (defcustom gnus-summary-article-expire-hook nil
987   "*A hook called after an article is expired."
988   :version "22.1"
989   :group 'gnus-summary
990   :type 'hook)
991
992 (defcustom gnus-summary-display-arrow
993   (and (fboundp 'display-graphic-p)
994        (display-graphic-p))
995   "*If non-nil, display an arrow highlighting the current article."
996   :version "22.1"
997   :group 'gnus-summary
998   :type 'boolean)
999
1000 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1001   "Face used for highlighting the current article in the summary buffer."
1002   :group 'gnus-summary-visual
1003   :type 'face)
1004
1005 (defvar gnus-tmp-downloaded nil)
1006
1007 (defcustom gnus-summary-highlight
1008   '(((eq mark gnus-canceled-mark)
1009      . gnus-summary-cancelled)
1010     ((and uncached (> score default-high))
1011      . gnus-summary-high-undownloaded)
1012     ((and uncached (< score default-low))
1013      . gnus-summary-low-undownloaded)
1014     (uncached
1015      . gnus-summary-normal-undownloaded)
1016     ((and (> score default-high)
1017           (or (eq mark gnus-dormant-mark)
1018               (eq mark gnus-ticked-mark)))
1019      . gnus-summary-high-ticked)
1020     ((and (< score default-low)
1021           (or (eq mark gnus-dormant-mark)
1022               (eq mark gnus-ticked-mark)))
1023      . gnus-summary-low-ticked)
1024     ((or (eq mark gnus-dormant-mark)
1025          (eq mark gnus-ticked-mark))
1026      . gnus-summary-normal-ticked)
1027     ((and (> score default-high) (eq mark gnus-ancient-mark))
1028      . gnus-summary-high-ancient)
1029     ((and (< score default-low) (eq mark gnus-ancient-mark))
1030      . gnus-summary-low-ancient)
1031     ((eq mark gnus-ancient-mark)
1032      . gnus-summary-normal-ancient)
1033     ((and (> score default-high) (eq mark gnus-unread-mark))
1034      . gnus-summary-high-unread)
1035     ((and (< score default-low) (eq mark gnus-unread-mark))
1036      . gnus-summary-low-unread)
1037     ((eq mark gnus-unread-mark)
1038      . gnus-summary-normal-unread)
1039     ((> score default-high)
1040      . gnus-summary-high-read)
1041     ((< score default-low)
1042      . gnus-summary-low-read)
1043     (t
1044      . gnus-summary-normal-read))
1045   "*Controls the highlighting of summary buffer lines.
1046
1047 A list of (FORM . FACE) pairs.  When deciding how a a particular
1048 summary line should be displayed, each form is evaluated.  The content
1049 of the face field after the first true form is used.  You can change
1050 how those summary lines are displayed, by editing the face field.
1051
1052 You can use the following variables in the FORM field.
1053
1054 score:        The article's score
1055 default:      The default article score.
1056 default-high: The default score for high scored articles.
1057 default-low:  The default score for low scored articles.
1058 below:        The score below which articles are automatically marked as read.
1059 mark:         The article's mark.
1060 uncached:     Non-nil if the article is uncached."
1061   :group 'gnus-summary-visual
1062   :type '(repeat (cons (sexp :tag "Form" nil)
1063                        face)))
1064
1065 (defcustom gnus-alter-header-function nil
1066   "Function called to allow alteration of article header structures.
1067 The function is called with one parameter, the article header vector,
1068 which it may alter in any way."
1069   :type '(choice (const :tag "None" nil)
1070                  function)
1071   :group 'gnus-summary)
1072
1073 (defvar gnus-decode-encoded-word-function
1074   (mime-find-field-decoder 'From 'nov)
1075   "Variable that says which function should be used to decode a string with encoded words.")
1076
1077 (defcustom gnus-extra-headers '(To Newsgroups)
1078   "*Extra headers to parse."
1079   :version "21.1"
1080   :group 'gnus-summary
1081   :type '(repeat symbol))
1082
1083 (defcustom gnus-ignored-from-addresses
1084   (and user-mail-address  
1085        (not (string= user-mail-address ""))
1086        (regexp-quote user-mail-address))
1087   "*Regexp of From headers that may be suppressed in favor of To headers."
1088   :version "21.1"
1089   :group 'gnus-summary
1090   :type 'regexp)
1091
1092 (defcustom gnus-summary-to-prefix "-> "
1093   "*String prefixed to the To field in the summary line when
1094 using `gnus-ignored-from-addresses'."
1095   :version "22.1"
1096   :group 'gnus-summary
1097   :type 'string)
1098
1099 (defcustom gnus-summary-newsgroup-prefix "=> "
1100   "*String prefixed to the Newsgroup field in the summary
1101 line when using `gnus-ignored-from-addresses'."
1102   :version "22.1"
1103   :group 'gnus-summary
1104   :type 'string)
1105
1106 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1107   "List of charsets that should be ignored.
1108 When these charsets are used in the \"charset\" parameter, the
1109 default charset will be used instead."
1110   :version "21.1"
1111   :type '(repeat symbol)
1112   :group 'gnus-charset)
1113
1114 (gnus-define-group-parameter
1115  ignored-charsets
1116  :type list
1117  :function-document
1118  "Return the ignored charsets of GROUP."
1119  :variable gnus-group-ignored-charsets-alist
1120  :variable-default
1121  '(("alt\\.chinese\\.text" iso-8859-1))
1122  :variable-document
1123  "Alist of regexps (to match group names) and charsets that should be ignored.
1124 When these charsets are used in the \"charset\" parameter, the
1125 default charset will be used instead."
1126  :variable-group gnus-charset
1127  :variable-type '(repeat (cons (regexp :tag "Group")
1128                                (repeat symbol)))
1129  :parameter-type '(choice :tag "Ignored charsets"
1130                           :value nil
1131                           (repeat (symbol)))
1132  :parameter-document       "\
1133 List of charsets that should be ignored.
1134
1135 When these charsets are used in the \"charset\" parameter, the
1136 default charset will be used instead.")
1137
1138 (defcustom gnus-group-highlight-words-alist nil
1139   "Alist of group regexps and highlight regexps.
1140 This variable uses the same syntax as `gnus-emphasis-alist'."
1141   :version "21.1"
1142   :type '(repeat (cons (regexp :tag "Group")
1143                        (repeat (list (regexp :tag "Highlight regexp")
1144                                      (number :tag "Group for entire word" 0)
1145                                      (number :tag "Group for displayed part" 0)
1146                                      (symbol :tag "Face"
1147                                              gnus-emphasis-highlight-words)))))
1148   :group 'gnus-summary-visual)
1149
1150 (defcustom gnus-use-wheel nil
1151   "Use Intelli-mouse on summary movement"
1152   :type 'boolean
1153   :group 'gnus-summary-maneuvering)
1154
1155 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1156   "Amount to scroll messages by spinning the mouse wheel.
1157 This is actually a cons cell, where the first item is the amount to scroll
1158 on a normal wheel event, and the second is the amount to scroll when the
1159 wheel is moved with the shift key depressed."
1160   :type '(cons (integer :tag "Shift") integer)
1161   :group 'gnus-summary-maneuvering)
1162
1163 (defcustom gnus-wheel-edge-resistance 2
1164   "How hard it should be to change the current article
1165 by moving the mouse over the edge of the article window."
1166   :type 'integer
1167   :group 'gnus-summary-maneuvering)
1168
1169 (defcustom gnus-summary-show-article-charset-alist
1170   nil
1171   "Alist of number and charset.
1172 The article will be shown with the charset corresponding to the
1173 numbered argument.
1174 For example: ((1 . cn-gb-2312) (2 . big5))."
1175   :version "21.1"
1176   :type '(repeat (cons (number :tag "Argument" 1)
1177                        (symbol :tag "Charset")))
1178   :group 'gnus-charset)
1179
1180 (defcustom gnus-preserve-marks t
1181   "Whether marks are preserved when moving, copying and respooling messages."
1182   :version "21.1"
1183   :type 'boolean
1184   :group 'gnus-summary-marks)
1185
1186 (defcustom gnus-alter-articles-to-read-function nil
1187   "Function to be called to alter the list of articles to be selected."
1188   :type '(choice (const nil) function)
1189   :group 'gnus-summary)
1190
1191 (defcustom gnus-orphan-score nil
1192   "*All orphans get this score added.  Set in the score file."
1193   :group 'gnus-score-default
1194   :type '(choice (const nil)
1195                  integer))
1196
1197 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1198   "*A regexp to match MIME parts when saving multiple parts of a
1199 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1200 This regexp will be used by default when prompting the user for which
1201 type of files to save."
1202   :group 'gnus-summary
1203   :type 'regexp)
1204
1205 (defcustom gnus-read-all-available-headers nil
1206   "Whether Gnus should parse all headers made available to it.
1207 This is mostly relevant for slow back ends where the user may
1208 wish to widen the summary buffer to include all headers
1209 that were fetched.  Say, for nnultimate groups."
1210   :version "22.1"
1211   :group 'gnus-summary
1212   :type '(choice boolean regexp))
1213
1214 (defcustom gnus-summary-muttprint-program "muttprint"
1215   "Command (and optional arguments) used to run Muttprint."
1216   :version "22.1"
1217   :group 'gnus-summary
1218   :type 'string)
1219
1220 (defcustom gnus-article-loose-mime t
1221   "If non-nil, don't require MIME-Version header.
1222 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1223 supply the MIME-Version header or deliberately strip it from the mail.
1224 If non-nil (the default), Gnus will treat some articles as MIME
1225 even if the MIME-Version header is missing."
1226   :version "22.1"
1227   :type 'boolean
1228   :group 'gnus-article-mime)
1229
1230 (defcustom gnus-article-emulate-mime t
1231   "If non-nil, use MIME emulation for uuencode and the like.
1232 This means that Gnus will search message bodies for text that look
1233 like uuencoded bits, yEncoded bits, and so on, and present that using
1234 the normal Gnus MIME machinery."
1235   :version "22.1"
1236   :type 'boolean
1237   :group 'gnus-article-mime)
1238
1239 ;;; Internal variables
1240
1241 (defvar gnus-summary-display-cache nil)
1242 (defvar gnus-article-mime-handles nil)
1243 (defvar gnus-article-decoded-p nil)
1244 (defvar gnus-article-charset nil)
1245 (defvar gnus-article-ignored-charsets nil)
1246 (defvar gnus-scores-exclude-files nil)
1247 (defvar gnus-page-broken nil)
1248
1249 (defvar gnus-original-article nil)
1250 (defvar gnus-article-internal-prepare-hook nil)
1251 (defvar gnus-newsgroup-process-stack nil)
1252
1253 (defvar gnus-thread-indent-array nil)
1254 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1255 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1256   "Function called to sort the articles within a thread after it has been gathered together.")
1257
1258 (defvar gnus-summary-save-parts-type-history nil)
1259 (defvar gnus-summary-save-parts-last-directory nil)
1260
1261 ;; Avoid highlighting in kill files.
1262 (defvar gnus-summary-inhibit-highlight nil)
1263 (defvar gnus-newsgroup-selected-overlay nil)
1264 (defvar gnus-inhibit-limiting nil)
1265 (defvar gnus-newsgroup-adaptive-score-file nil)
1266 (defvar gnus-current-score-file nil)
1267 (defvar gnus-current-move-group nil)
1268 (defvar gnus-current-copy-group nil)
1269 (defvar gnus-current-crosspost-group nil)
1270 (defvar gnus-newsgroup-display nil)
1271
1272 (defvar gnus-newsgroup-dependencies nil)
1273 (defvar gnus-newsgroup-adaptive nil)
1274 (defvar gnus-summary-display-article-function nil)
1275 (defvar gnus-summary-highlight-line-function nil
1276   "Function called after highlighting a summary line.")
1277
1278 (defvar gnus-summary-line-format-alist
1279   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1280     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1281     (?s gnus-tmp-subject-or-nil ?s)
1282     (?n gnus-tmp-name ?s)
1283     (?A (std11-address-string
1284          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1285     (?a (or (std11-full-name-string
1286              (car (mime-entity-read-field gnus-tmp-header 'From)))
1287             gnus-tmp-from) ?s)
1288     (?F gnus-tmp-from ?s)
1289     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1290     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1291     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1292     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1293     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1294     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1295     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1296     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1297     (?L gnus-tmp-lines ?s)
1298     (?O gnus-tmp-downloaded ?c)
1299     (?I gnus-tmp-indentation ?s)
1300     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1301     (?R gnus-tmp-replied ?c)
1302     (?\[ gnus-tmp-opening-bracket ?c)
1303     (?\] gnus-tmp-closing-bracket ?c)
1304     (?\> (make-string gnus-tmp-level ? ) ?s)
1305     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1306     (?i gnus-tmp-score ?d)
1307     (?z gnus-tmp-score-char ?c)
1308     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1309     (?U gnus-tmp-unread ?c)
1310     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1311         ?s)
1312     (?t (gnus-summary-number-of-articles-in-thread
1313          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1314         ?d)
1315     (?e (gnus-summary-number-of-articles-in-thread
1316          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1317         ?c)
1318     (?u gnus-tmp-user-defined ?s)
1319     (?P (gnus-pick-line-number) ?d)
1320     (?B gnus-tmp-thread-tree-header-string ?s)
1321     (user-date (gnus-user-date
1322                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1323   "An alist of format specifications that can appear in summary lines.
1324 These are paired with what variables they correspond with, along with
1325 the type of the variable (string, integer, character, etc).")
1326
1327 (defvar gnus-summary-dummy-line-format-alist
1328   `((?S gnus-tmp-subject ?s)
1329     (?N gnus-tmp-number ?d)
1330     (?u gnus-tmp-user-defined ?s)))
1331
1332 (defvar gnus-summary-mode-line-format-alist
1333   `((?G gnus-tmp-group-name ?s)
1334     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1335     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1336     (?A gnus-tmp-article-number ?d)
1337     (?Z gnus-tmp-unread-and-unselected ?s)
1338     (?V gnus-version ?s)
1339     (?U gnus-tmp-unread-and-unticked ?d)
1340     (?S gnus-tmp-subject ?s)
1341     (?e gnus-tmp-unselected ?d)
1342     (?u gnus-tmp-user-defined ?s)
1343     (?d (length gnus-newsgroup-dormant) ?d)
1344     (?t (length gnus-newsgroup-marked) ?d)
1345     (?h (length gnus-newsgroup-spam-marked) ?d)
1346     (?r (length gnus-newsgroup-reads) ?d)
1347     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1348     (?E gnus-newsgroup-expunged-tally ?d)
1349     (?s (gnus-current-score-file-nondirectory) ?s)))
1350
1351 (defvar gnus-last-search-regexp nil
1352   "Default regexp for article search command.")
1353
1354 (defvar gnus-summary-search-article-matched-data nil
1355   "Last matched data of article search command.  It is the local variable
1356 in `gnus-article-buffer' which consists of the list of start position,
1357 end position and text.")
1358
1359 (defvar gnus-last-shell-command nil
1360   "Default shell command on article.")
1361
1362 (defvar gnus-newsgroup-agentized nil
1363   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1364 (defvar gnus-newsgroup-begin nil)
1365 (defvar gnus-newsgroup-end nil)
1366 (defvar gnus-newsgroup-last-rmail nil)
1367 (defvar gnus-newsgroup-last-mail nil)
1368 (defvar gnus-newsgroup-last-folder nil)
1369 (defvar gnus-newsgroup-last-file nil)
1370 (defvar gnus-newsgroup-auto-expire nil)
1371 (defvar gnus-newsgroup-active nil)
1372
1373 (defvar gnus-newsgroup-data nil)
1374 (defvar gnus-newsgroup-data-reverse nil)
1375 (defvar gnus-newsgroup-limit nil)
1376 (defvar gnus-newsgroup-limits nil)
1377 (defvar gnus-summary-use-undownloaded-faces nil)
1378
1379 (defvar gnus-newsgroup-unreads nil
1380   "Sorted list of unread articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-unselected nil
1383   "Sorted list of unselected unread articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-reads nil
1386   "Alist of read articles and article marks in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-expunged-tally nil)
1389
1390 (defvar gnus-newsgroup-marked nil
1391   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1392
1393 (defvar gnus-newsgroup-spam-marked nil
1394   "List of ranges of articles that have been marked as spam.")
1395
1396 (defvar gnus-newsgroup-killed nil
1397   "List of ranges of articles that have been through the scoring process.")
1398
1399 (defvar gnus-newsgroup-cached nil
1400   "Sorted list of articles that come from the article cache.")
1401
1402 (defvar gnus-newsgroup-saved nil
1403   "List of articles that have been saved.")
1404
1405 (defvar gnus-newsgroup-kill-headers nil)
1406
1407 (defvar gnus-newsgroup-replied nil
1408   "List of articles that have been replied to in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-forwarded nil
1411   "List of articles that have been forwarded in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-recent nil
1414   "List of articles that have are recent in the current newsgroup.")
1415
1416 (defvar gnus-newsgroup-expirable nil
1417   "Sorted list of articles in the current newsgroup that can be expired.")
1418
1419 (defvar gnus-newsgroup-processable nil
1420   "List of articles in the current newsgroup that can be processed.")
1421
1422 (defvar gnus-newsgroup-downloadable nil
1423   "Sorted list of articles in the current newsgroup that can be processed.")
1424
1425 (defvar gnus-newsgroup-unfetched nil
1426   "Sorted list of articles in the current newsgroup whose headers have
1427 not been fetched into the agent.
1428
1429 This list will always be a subset of gnus-newsgroup-undownloaded.")
1430
1431 (defvar gnus-newsgroup-undownloaded nil
1432   "List of articles in the current newsgroup that haven't been downloaded.")
1433
1434 (defvar gnus-newsgroup-unsendable nil
1435   "List of articles in the current newsgroup that won't be sent.")
1436
1437 (defvar gnus-newsgroup-bookmarks nil
1438   "List of articles in the current newsgroup that have bookmarks.")
1439
1440 (defvar gnus-newsgroup-dormant nil
1441   "Sorted list of dormant articles in the current newsgroup.")
1442
1443 (defvar gnus-newsgroup-unseen nil
1444   "List of unseen articles in the current newsgroup.")
1445
1446 (defvar gnus-newsgroup-seen nil
1447   "Range of seen articles in the current newsgroup.")
1448
1449 (defvar gnus-newsgroup-articles nil
1450   "List of articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-scored nil
1453   "List of scored articles in the current newsgroup.")
1454
1455 (defvar gnus-newsgroup-incorporated nil
1456   "List of incorporated articles in the current newsgroup.")
1457
1458 (defvar gnus-newsgroup-headers nil
1459   "List of article headers in the current newsgroup.")
1460
1461 (defvar gnus-newsgroup-threads nil)
1462
1463 (defvar gnus-newsgroup-prepared nil
1464   "Whether the current group has been prepared properly.")
1465
1466 (defvar gnus-newsgroup-ancient nil
1467   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-sparse nil)
1470
1471 (defvar gnus-current-article nil)
1472 (defvar gnus-article-current nil)
1473 (defvar gnus-current-headers nil)
1474 (defvar gnus-have-all-headers nil)
1475 (defvar gnus-last-article nil)
1476 (defvar gnus-newsgroup-history nil)
1477 (defvar gnus-newsgroup-charset nil)
1478 (defvar gnus-newsgroup-ephemeral-charset nil)
1479 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1480
1481 (defvar gnus-article-before-search nil)
1482
1483 (defvar gnus-summary-local-variables
1484   '(gnus-newsgroup-name
1485     gnus-newsgroup-begin gnus-newsgroup-end
1486     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1487     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1488     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1489     gnus-newsgroup-unselected gnus-newsgroup-marked
1490     gnus-newsgroup-spam-marked
1491     gnus-newsgroup-reads gnus-newsgroup-saved
1492     gnus-newsgroup-replied gnus-newsgroup-forwarded
1493     gnus-newsgroup-recent
1494     gnus-newsgroup-expirable
1495     gnus-newsgroup-processable gnus-newsgroup-killed
1496     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1497     gnus-newsgroup-unfetched
1498     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1499     gnus-newsgroup-seen gnus-newsgroup-articles
1500     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1501     gnus-newsgroup-headers gnus-newsgroup-threads
1502     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1503     gnus-current-article gnus-current-headers gnus-have-all-headers
1504     gnus-last-article gnus-article-internal-prepare-hook
1505     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1506     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1507     gnus-thread-expunge-below
1508     gnus-score-alist gnus-current-score-file
1509     (gnus-summary-expunge-below . global)
1510     (gnus-summary-mark-below . global)
1511     (gnus-orphan-score . global)
1512     gnus-newsgroup-active gnus-scores-exclude-files
1513     gnus-newsgroup-history gnus-newsgroup-ancient
1514     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1515     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1516     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1517     (gnus-newsgroup-expunged-tally . 0)
1518     gnus-cache-removable-articles gnus-newsgroup-cached
1519     gnus-newsgroup-data gnus-newsgroup-data-reverse
1520     gnus-newsgroup-limit gnus-newsgroup-limits
1521     gnus-newsgroup-charset gnus-newsgroup-display
1522     gnus-summary-use-undownloaded-faces
1523     gnus-newsgroup-incorporated)
1524   "Variables that are buffer-local to the summary buffers.")
1525
1526 (defvar gnus-newsgroup-variables nil
1527   "A list of variables that have separate values in different newsgroups.
1528 A list of newsgroup (summary buffer) local variables, or cons of
1529 variables and their default expressions to be evalled (when the default
1530 values are not nil), that should be made global while the summary buffer
1531 is active.
1532
1533 Note: The default expressions will be evaluated (using function `eval')
1534 before assignment to the local variable rather than just assigned to it.
1535 If the default expression is the symbol `global', that symbol will not
1536 be evaluated but the global value of the local variable will be used
1537 instead.
1538
1539 These variables can be used to set variables in the group parameters
1540 while still allowing them to affect operations done in other buffers.
1541 For example:
1542
1543 \(setq gnus-newsgroup-variables
1544      '(message-use-followup-to
1545        (gnus-visible-headers .
1546          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1547 ")
1548
1549 ;; Byte-compiler warning.
1550 (eval-when-compile
1551   ;; Bind features so that require will believe that gnus-sum has
1552   ;; already been loaded (avoids infinite recursion)
1553   (let ((features (cons 'gnus-sum features)))
1554     ;; Several of the declarations in gnus-sum are needed to load the
1555     ;; following files. Right now, these definitions have been
1556     ;; compiled but not defined (evaluated).  We could either do a
1557     ;; eval-and-compile about all of the declarations or evaluate the
1558     ;; source file.
1559     (if (boundp 'gnus-newsgroup-variables)
1560         nil
1561       (load "gnus-sum.el" t t t))
1562     (require 'gnus)
1563     (require 'gnus-art)))
1564
1565 ;; Subject simplification.
1566
1567 (defun gnus-simplify-whitespace (str)
1568   "Remove excessive whitespace from STR."
1569   ;; Multiple spaces.
1570   (while (string-match "[ \t][ \t]+" str)
1571     (setq str (concat (substring str 0 (match-beginning 0))
1572                         " "
1573                         (substring str (match-end 0)))))
1574   ;; Leading spaces.
1575   (when (string-match "^[ \t]+" str)
1576     (setq str (substring str (match-end 0))))
1577   ;; Trailing spaces.
1578   (when (string-match "[ \t]+$" str)
1579     (setq str (substring str 0 (match-beginning 0))))
1580   str)
1581
1582 (defun gnus-simplify-all-whitespace (str)
1583   "Remove all whitespace from STR."
1584   (while (string-match "[ \t\n]+" str)
1585     (setq str (replace-match "" nil nil str)))
1586   str)
1587
1588 (defsubst gnus-simplify-subject-re (subject)
1589   "Remove \"Re:\" from subject lines."
1590   (if (string-match message-subject-re-regexp subject)
1591       (substring subject (match-end 0))
1592     subject))
1593
1594 (defun gnus-simplify-subject (subject &optional re-only)
1595   "Remove `Re:' and words in parentheses.
1596 If RE-ONLY is non-nil, strip leading `Re:'s only."
1597   (let ((case-fold-search t))           ;Ignore case.
1598     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1599     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1600       (setq subject (substring subject (match-end 0))))
1601     ;; Remove uninteresting prefixes.
1602     (when (and (not re-only)
1603                gnus-simplify-ignored-prefixes
1604                (string-match gnus-simplify-ignored-prefixes subject))
1605       (setq subject (substring subject (match-end 0))))
1606     ;; Remove words in parentheses from end.
1607     (unless re-only
1608       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1609         (setq subject (substring subject 0 (match-beginning 0)))))
1610     ;; Return subject string.
1611     subject))
1612
1613 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1614 ;; all whitespace.
1615 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1616   (goto-char (point-min))
1617   (while (re-search-forward regexp nil t)
1618     (replace-match (or newtext ""))))
1619
1620 (defun gnus-simplify-buffer-fuzzy ()
1621   "Simplify string in the buffer fuzzily.
1622 The string in the accessible portion of the current buffer is simplified.
1623 It is assumed to be a single-line subject.
1624 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1625 matter is removed.  Additional things can be deleted by setting
1626 `gnus-simplify-subject-fuzzy-regexp'."
1627   (let ((case-fold-search t)
1628         (modified-tick))
1629     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1630
1631     (while (not (eq modified-tick (buffer-modified-tick)))
1632       (setq modified-tick (buffer-modified-tick))
1633       (cond
1634        ((listp gnus-simplify-subject-fuzzy-regexp)
1635         (mapcar 'gnus-simplify-buffer-fuzzy-step
1636                 gnus-simplify-subject-fuzzy-regexp))
1637        (gnus-simplify-subject-fuzzy-regexp
1638         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1639       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1640       (gnus-simplify-buffer-fuzzy-step
1641        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1642       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1643
1644     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1645     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1646     (gnus-simplify-buffer-fuzzy-step " $")
1647     (gnus-simplify-buffer-fuzzy-step "^ +")))
1648
1649 (defun gnus-simplify-subject-fuzzy (subject)
1650   "Simplify a subject string fuzzily.
1651 See `gnus-simplify-buffer-fuzzy' for details."
1652   (save-excursion
1653     (gnus-set-work-buffer)
1654     (let ((case-fold-search t))
1655       ;; Remove uninteresting prefixes.
1656       (when (and gnus-simplify-ignored-prefixes
1657                  (string-match gnus-simplify-ignored-prefixes subject))
1658         (setq subject (substring subject (match-end 0))))
1659       (insert subject)
1660       (inline (gnus-simplify-buffer-fuzzy))
1661       (buffer-string))))
1662
1663 (defsubst gnus-simplify-subject-fully (subject)
1664   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1665   (cond
1666    (gnus-simplify-subject-functions
1667     (gnus-map-function gnus-simplify-subject-functions subject))
1668    ((null gnus-summary-gather-subject-limit)
1669     (gnus-simplify-subject-re subject))
1670    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1671     (gnus-simplify-subject-fuzzy subject))
1672    ((numberp gnus-summary-gather-subject-limit)
1673     (gnus-limit-string (gnus-simplify-subject-re subject)
1674                        gnus-summary-gather-subject-limit))
1675    (t
1676     subject)))
1677
1678 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1679   "Check whether two subjects are equal.
1680 If optional argument SIMPLE-FIRST is t, first argument is already
1681 simplified."
1682   (cond
1683    ((null simple-first)
1684     (equal (gnus-simplify-subject-fully s1)
1685            (gnus-simplify-subject-fully s2)))
1686    (t
1687     (equal s1
1688            (gnus-simplify-subject-fully s2)))))
1689
1690 (defun gnus-summary-bubble-group ()
1691   "Increase the score of the current group.
1692 This is a handy function to add to `gnus-summary-exit-hook' to
1693 increase the score of each group you read."
1694   (gnus-group-add-score gnus-newsgroup-name))
1695
1696 \f
1697 ;;;
1698 ;;; Gnus summary mode
1699 ;;;
1700
1701 (put 'gnus-summary-mode 'mode-class 'special)
1702
1703 (defvar gnus-article-commands-menu)
1704
1705 ;; Non-orthogonal keys
1706
1707 (gnus-define-keys gnus-summary-mode-map
1708   " " gnus-summary-next-page
1709   "\177" gnus-summary-prev-page
1710   [delete] gnus-summary-prev-page
1711   [backspace] gnus-summary-prev-page
1712   "\r" gnus-summary-scroll-up
1713   "\M-\r" gnus-summary-scroll-down
1714   "n" gnus-summary-next-unread-article
1715   "p" gnus-summary-prev-unread-article
1716   "N" gnus-summary-next-article
1717   "P" gnus-summary-prev-article
1718   "\M-\C-n" gnus-summary-next-same-subject
1719   "\M-\C-p" gnus-summary-prev-same-subject
1720   "\M-n" gnus-summary-next-unread-subject
1721   "\M-p" gnus-summary-prev-unread-subject
1722   "." gnus-summary-first-unread-article
1723   "," gnus-summary-best-unread-article
1724   "\M-s" gnus-summary-search-article-forward
1725   "\M-r" gnus-summary-search-article-backward
1726   "<" gnus-summary-beginning-of-article
1727   ">" gnus-summary-end-of-article
1728   "j" gnus-summary-goto-article
1729   "^" gnus-summary-refer-parent-article
1730   "\M-^" gnus-summary-refer-article
1731   "u" gnus-summary-tick-article-forward
1732   "!" gnus-summary-tick-article-forward
1733   "U" gnus-summary-tick-article-backward
1734   "d" gnus-summary-mark-as-read-forward
1735   "D" gnus-summary-mark-as-read-backward
1736   "E" gnus-summary-mark-as-expirable
1737   "\M-u" gnus-summary-clear-mark-forward
1738   "\M-U" gnus-summary-clear-mark-backward
1739   "k" gnus-summary-kill-same-subject-and-select
1740   "\C-k" gnus-summary-kill-same-subject
1741   "\M-\C-k" gnus-summary-kill-thread
1742   "\M-\C-l" gnus-summary-lower-thread
1743   "e" gnus-summary-edit-article
1744   "#" gnus-summary-mark-as-processable
1745   "\M-#" gnus-summary-unmark-as-processable
1746   "\M-\C-t" gnus-summary-toggle-threads
1747   "\M-\C-s" gnus-summary-show-thread
1748   "\M-\C-h" gnus-summary-hide-thread
1749   "\M-\C-f" gnus-summary-next-thread
1750   "\M-\C-b" gnus-summary-prev-thread
1751   [(meta down)] gnus-summary-next-thread
1752   [(meta up)] gnus-summary-prev-thread
1753   "\M-\C-u" gnus-summary-up-thread
1754   "\M-\C-d" gnus-summary-down-thread
1755   "&" gnus-summary-execute-command
1756   "c" gnus-summary-catchup-and-exit
1757   "\C-w" gnus-summary-mark-region-as-read
1758   "\C-t" gnus-summary-toggle-truncation
1759   "?" gnus-summary-mark-as-dormant
1760   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1761   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1762   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1763   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1764   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1765   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1766   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1767   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1768   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1769   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1770   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1771   "=" gnus-summary-expand-window
1772   "\C-x\C-s" gnus-summary-reselect-current-group
1773   "\M-g" gnus-summary-rescan-group
1774   "w" gnus-summary-stop-page-breaking
1775   "\C-c\C-r" gnus-summary-caesar-message
1776   "\M-t" gnus-summary-toggle-mime
1777   "f" gnus-summary-followup
1778   "F" gnus-summary-followup-with-original
1779   "C" gnus-summary-cancel-article
1780   "r" gnus-summary-reply
1781   "R" gnus-summary-reply-with-original
1782   "\C-c\C-f" gnus-summary-mail-forward
1783   "o" gnus-summary-save-article
1784   "\C-o" gnus-summary-save-article-mail
1785   "|" gnus-summary-pipe-output
1786   "\M-k" gnus-summary-edit-local-kill
1787   "\M-K" gnus-summary-edit-global-kill
1788   ;; "V" gnus-version
1789   "\C-c\C-d" gnus-summary-describe-group
1790   "q" gnus-summary-exit
1791   "Q" gnus-summary-exit-no-update
1792   "\C-c\C-i" gnus-info-find-node
1793   gnus-mouse-2 gnus-mouse-pick-article
1794   [follow-link] mouse-face
1795   "m" gnus-summary-mail-other-window
1796   "a" gnus-summary-post-news
1797   "i" gnus-summary-news-other-window
1798   "x" gnus-summary-limit-to-unread
1799   "s" gnus-summary-isearch-article
1800   "t" gnus-summary-toggle-header
1801   "g" gnus-summary-show-article
1802   "l" gnus-summary-goto-last-article
1803   "v" gnus-summary-preview-mime-message
1804   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1805   "\C-d" gnus-summary-enter-digest-group
1806   "\M-\C-d" gnus-summary-read-document
1807   "\M-\C-e" gnus-summary-edit-parameters
1808   "\M-\C-a" gnus-summary-customize-parameters
1809   "\C-c\C-b" gnus-bug
1810   "\C-c\C-n" gnus-namazu-search
1811   "*" gnus-cache-enter-article
1812   "\M-*" gnus-cache-remove-article
1813   "\M-&" gnus-summary-universal-argument
1814   "\C-l" gnus-recenter
1815   "I" gnus-summary-increase-score
1816   "L" gnus-summary-lower-score
1817   "\M-i" gnus-symbolic-argument
1818   "h" gnus-summary-select-article-buffer
1819
1820   "V" gnus-summary-score-map
1821   "X" gnus-uu-extract-map
1822   "S" gnus-summary-send-map)
1823
1824   ;; Sort of orthogonal keymap
1825 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1826   "t" gnus-summary-tick-article-forward
1827   "!" gnus-summary-tick-article-forward
1828   "d" gnus-summary-mark-as-read-forward
1829   "r" gnus-summary-mark-as-read-forward
1830   "c" gnus-summary-clear-mark-forward
1831   " " gnus-summary-clear-mark-forward
1832   "e" gnus-summary-mark-as-expirable
1833   "x" gnus-summary-mark-as-expirable
1834   "?" gnus-summary-mark-as-dormant
1835   "b" gnus-summary-set-bookmark
1836   "B" gnus-summary-remove-bookmark
1837   "#" gnus-summary-mark-as-processable
1838   "\M-#" gnus-summary-unmark-as-processable
1839   "S" gnus-summary-limit-include-expunged
1840   "C" gnus-summary-catchup
1841   "H" gnus-summary-catchup-to-here
1842   "h" gnus-summary-catchup-from-here
1843   "\C-c" gnus-summary-catchup-all
1844   "k" gnus-summary-kill-same-subject-and-select
1845   "K" gnus-summary-kill-same-subject
1846   "P" gnus-uu-mark-map)
1847
1848 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1849   "c" gnus-summary-clear-above
1850   "u" gnus-summary-tick-above
1851   "m" gnus-summary-mark-above
1852   "k" gnus-summary-kill-below)
1853
1854 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1855   "/" gnus-summary-limit-to-subject
1856   "n" gnus-summary-limit-to-articles
1857   "w" gnus-summary-pop-limit
1858   "s" gnus-summary-limit-to-subject
1859   "a" gnus-summary-limit-to-author
1860   "u" gnus-summary-limit-to-unread
1861   "m" gnus-summary-limit-to-marks
1862   "M" gnus-summary-limit-exclude-marks
1863   "v" gnus-summary-limit-to-score
1864   "*" gnus-summary-limit-include-cached
1865   "D" gnus-summary-limit-include-dormant
1866   "T" gnus-summary-limit-include-thread
1867   "d" gnus-summary-limit-exclude-dormant
1868   "t" gnus-summary-limit-to-age
1869   "." gnus-summary-limit-to-unseen
1870   "x" gnus-summary-limit-to-extra
1871   "p" gnus-summary-limit-to-display-predicate
1872   "E" gnus-summary-limit-include-expunged
1873   "c" gnus-summary-limit-exclude-childless-dormant
1874   "C" gnus-summary-limit-mark-excluded-as-read
1875   "o" gnus-summary-insert-old-articles
1876   "N" gnus-summary-insert-new-articles
1877   "r" gnus-summary-limit-to-replied
1878   "R" gnus-summary-limit-to-recipient)
1879
1880 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1881   "n" gnus-summary-next-unread-article
1882   "p" gnus-summary-prev-unread-article
1883   "N" gnus-summary-next-article
1884   "P" gnus-summary-prev-article
1885   "\C-n" gnus-summary-next-same-subject
1886   "\C-p" gnus-summary-prev-same-subject
1887   "\M-n" gnus-summary-next-unread-subject
1888   "\M-p" gnus-summary-prev-unread-subject
1889   "f" gnus-summary-first-unread-article
1890   "b" gnus-summary-best-unread-article
1891   "j" gnus-summary-goto-article
1892   "g" gnus-summary-goto-subject
1893   "l" gnus-summary-goto-last-article
1894   "o" gnus-summary-pop-article)
1895
1896 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1897   "k" gnus-summary-kill-thread
1898   "l" gnus-summary-lower-thread
1899   "i" gnus-summary-raise-thread
1900   "T" gnus-summary-toggle-threads
1901   "t" gnus-summary-rethread-current
1902   "^" gnus-summary-reparent-thread
1903   "s" gnus-summary-show-thread
1904   "S" gnus-summary-show-all-threads
1905   "h" gnus-summary-hide-thread
1906   "H" gnus-summary-hide-all-threads
1907   "n" gnus-summary-next-thread
1908   "p" gnus-summary-prev-thread
1909   "u" gnus-summary-up-thread
1910   "o" gnus-summary-top-thread
1911   "d" gnus-summary-down-thread
1912   "#" gnus-uu-mark-thread
1913   "\M-#" gnus-uu-unmark-thread)
1914
1915 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1916   "g" gnus-summary-prepare
1917   "c" gnus-summary-insert-cached-articles
1918   "d" gnus-summary-insert-dormant-articles)
1919
1920 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1921   "c" gnus-summary-catchup-and-exit
1922   "C" gnus-summary-catchup-all-and-exit
1923   "E" gnus-summary-exit-no-update
1924   "J" gnus-summary-jump-to-other-group
1925   "Q" gnus-summary-exit
1926   "Z" gnus-summary-exit
1927   "n" gnus-summary-catchup-and-goto-next-group
1928   "R" gnus-summary-reselect-current-group
1929   "G" gnus-summary-rescan-group
1930   "N" gnus-summary-next-group
1931   "s" gnus-summary-save-newsrc
1932   "P" gnus-summary-prev-group)
1933
1934 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1935   " " gnus-summary-next-page
1936   "n" gnus-summary-next-page
1937   "\177" gnus-summary-prev-page
1938   [delete] gnus-summary-prev-page
1939   "p" gnus-summary-prev-page
1940   "\r" gnus-summary-scroll-up
1941   "\M-\r" gnus-summary-scroll-down
1942   "<" gnus-summary-beginning-of-article
1943   ">" gnus-summary-end-of-article
1944   "b" gnus-summary-beginning-of-article
1945   "e" gnus-summary-end-of-article
1946   "^" gnus-summary-refer-parent-article
1947   "r" gnus-summary-refer-parent-article
1948   "D" gnus-summary-enter-digest-group
1949   "R" gnus-summary-refer-references
1950   "T" gnus-summary-refer-thread
1951   "g" gnus-summary-show-article
1952   "s" gnus-summary-isearch-article
1953   "P" gnus-summary-print-article
1954   "M" gnus-mailing-list-insinuate
1955   "t" gnus-article-babel)
1956
1957 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1958   "b" gnus-article-add-buttons
1959   "B" gnus-article-add-buttons-to-head
1960   "o" gnus-article-treat-overstrike
1961   "e" gnus-article-emphasize
1962   "w" gnus-article-fill-cited-article
1963   "Q" gnus-article-fill-long-lines
1964   "C" gnus-article-capitalize-sentences
1965   "c" gnus-article-remove-cr
1966   "Z" gnus-article-decode-HZ
1967   "A" gnus-article-treat-ansi-sequences
1968   "h" gnus-article-wash-html
1969   "u" gnus-article-unsplit-urls
1970   "f" gnus-article-display-x-face
1971   "l" gnus-summary-stop-page-breaking
1972   "r" gnus-summary-caesar-message
1973   "m" gnus-summary-morse-message
1974   "t" gnus-summary-toggle-header
1975   "g" gnus-treat-smiley
1976   "v" gnus-summary-verbose-headers
1977   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1978   "p" gnus-article-verify-x-pgp-sig
1979   "d" gnus-article-treat-dumbquotes
1980   "i" gnus-summary-idna-message)
1981
1982 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1983   ;; mnemonic: deuglif*Y*
1984   "u" gnus-article-outlook-unwrap-lines
1985   "a" gnus-article-outlook-repair-attribution
1986   "c" gnus-article-outlook-rearrange-citation
1987   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1988
1989 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1990   "a" gnus-article-hide
1991   "h" gnus-article-hide-headers
1992   "b" gnus-article-hide-boring-headers
1993   "s" gnus-article-hide-signature
1994   "c" gnus-article-hide-citation
1995   "C" gnus-article-hide-citation-in-followups
1996   "l" gnus-article-hide-list-identifiers
1997   "B" gnus-article-strip-banner
1998   "P" gnus-article-hide-pem
1999   "\C-c" gnus-article-hide-citation-maybe)
2000
2001 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2002   "a" gnus-article-highlight
2003   "h" gnus-article-highlight-headers
2004   "c" gnus-article-highlight-citation
2005   "s" gnus-article-highlight-signature)
2006
2007 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2008   "f" gnus-article-treat-fold-headers
2009   "u" gnus-article-treat-unfold-headers
2010   "n" gnus-article-treat-fold-newsgroups)
2011
2012 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2013   "x" gnus-article-display-x-face
2014   "d" gnus-article-display-face
2015   "s" gnus-treat-smiley
2016   "D" gnus-article-remove-images
2017   "f" gnus-treat-from-picon
2018   "m" gnus-treat-mail-picon
2019   "n" gnus-treat-newsgroups-picon)
2020
2021 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2022   "z" gnus-article-date-ut
2023   "u" gnus-article-date-ut
2024   "l" gnus-article-date-local
2025   "p" gnus-article-date-english
2026   "e" gnus-article-date-lapsed
2027   "o" gnus-article-date-original
2028   "i" gnus-article-date-iso8601
2029   "s" gnus-article-date-user)
2030
2031 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2032   "t" gnus-article-remove-trailing-blank-lines
2033   "l" gnus-article-strip-leading-blank-lines
2034   "m" gnus-article-strip-multiple-blank-lines
2035   "a" gnus-article-strip-blank-lines
2036   "A" gnus-article-strip-all-blank-lines
2037   "s" gnus-article-strip-leading-space
2038   "e" gnus-article-strip-trailing-space
2039   "w" gnus-article-remove-leading-whitespace)
2040
2041 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2042   "v" gnus-version
2043   "f" gnus-summary-fetch-faq
2044   "d" gnus-summary-describe-group
2045   "h" gnus-summary-describe-briefly
2046   "i" gnus-info-find-node
2047   "c" gnus-group-fetch-charter
2048   "C" gnus-group-fetch-control)
2049
2050 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2051   "e" gnus-summary-expire-articles
2052   "\M-\C-e" gnus-summary-expire-articles-now
2053   "\177" gnus-summary-delete-article
2054   [delete] gnus-summary-delete-article
2055   [backspace] gnus-summary-delete-article
2056   "m" gnus-summary-move-article
2057   "r" gnus-summary-respool-article
2058   "w" gnus-summary-edit-article
2059   "c" gnus-summary-copy-article
2060   "B" gnus-summary-crosspost-article
2061   "q" gnus-summary-respool-query
2062   "t" gnus-summary-respool-trace
2063   "i" gnus-summary-import-article
2064   "I" gnus-summary-create-article
2065   "p" gnus-summary-article-posted-p)
2066
2067 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2068   "o" gnus-summary-save-article
2069   "m" gnus-summary-save-article-mail
2070   "F" gnus-summary-write-article-file
2071   "r" gnus-summary-save-article-rmail
2072   "f" gnus-summary-save-article-file
2073   "b" gnus-summary-save-article-body-file
2074   "h" gnus-summary-save-article-folder
2075   "v" gnus-summary-save-article-vm
2076   "p" gnus-summary-pipe-output
2077   "P" gnus-summary-muttprint
2078   "s" gnus-soup-add-article)
2079
2080 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2081   "b" gnus-summary-display-buttonized
2082   "m" gnus-summary-repair-multipart
2083   "v" gnus-article-view-part
2084   "o" gnus-article-save-part
2085   "O" gnus-article-save-part-and-strip
2086   "r" gnus-article-replace-part
2087   "d" gnus-article-delete-part
2088   "j" gnus-article-jump-to-part
2089   "c" gnus-article-copy-part
2090   "C" gnus-article-view-part-as-charset
2091   "e" gnus-article-view-part-externally
2092   "E" gnus-article-encrypt-body
2093   "i" gnus-article-inline-part
2094   "|" gnus-article-pipe-part)
2095
2096 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2097   "p" gnus-summary-mark-as-processable
2098   "u" gnus-summary-unmark-as-processable
2099   "U" gnus-summary-unmark-all-processable
2100   "v" gnus-uu-mark-over
2101   "s" gnus-uu-mark-series
2102   "r" gnus-uu-mark-region
2103   "g" gnus-uu-unmark-region
2104   "R" gnus-uu-mark-by-regexp
2105   "G" gnus-uu-unmark-by-regexp
2106   "t" gnus-uu-mark-thread
2107   "T" gnus-uu-unmark-thread
2108   "a" gnus-uu-mark-all
2109   "b" gnus-uu-mark-buffer
2110   "S" gnus-uu-mark-sparse
2111   "k" gnus-summary-kill-process-mark
2112   "y" gnus-summary-yank-process-mark
2113   "w" gnus-summary-save-process-mark
2114   "i" gnus-uu-invert-processable)
2115
2116 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2117   ;;"x" gnus-uu-extract-any
2118   "m" gnus-summary-save-parts
2119   "u" gnus-uu-decode-uu
2120   "U" gnus-uu-decode-uu-and-save
2121   "s" gnus-uu-decode-unshar
2122   "S" gnus-uu-decode-unshar-and-save
2123   "o" gnus-uu-decode-save
2124   "O" gnus-uu-decode-save
2125   "b" gnus-uu-decode-binhex
2126   "B" gnus-uu-decode-binhex
2127   "p" gnus-uu-decode-postscript
2128   "P" gnus-uu-decode-postscript-and-save)
2129
2130 (gnus-define-keys
2131     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2132   "u" gnus-uu-decode-uu-view
2133   "U" gnus-uu-decode-uu-and-save-view
2134   "s" gnus-uu-decode-unshar-view
2135   "S" gnus-uu-decode-unshar-and-save-view
2136   "o" gnus-uu-decode-save-view
2137   "O" gnus-uu-decode-save-view
2138   "b" gnus-uu-decode-binhex-view
2139   "B" gnus-uu-decode-binhex-view
2140   "p" gnus-uu-decode-postscript-view
2141   "P" gnus-uu-decode-postscript-and-save-view)
2142
2143 (defvar gnus-article-post-menu nil)
2144
2145 (defconst gnus-summary-menu-maxlen 20)
2146
2147 (defun gnus-summary-menu-split (menu)
2148   ;; If we have lots of elements, divide them into groups of 20
2149   ;; and make a pane (or submenu) for each one.
2150   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2151       (let ((menu menu) sublists next
2152             (i 1))
2153         (while menu
2154           ;; Pull off the next gnus-summary-menu-maxlen elements
2155           ;; and make them the next element of sublist.
2156           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2157           (if next
2158               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2159                       nil))
2160           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2161                                              (aref (car (last menu)) 0)) menu)
2162                                sublists))
2163           (setq i (1+ i))
2164           (setq menu next))
2165         (nreverse sublists))
2166     ;; Few elements--put them all in one pane.
2167     menu))
2168
2169 (defun gnus-summary-make-menu-bar ()
2170   (gnus-turn-off-edit-menu 'summary)
2171
2172   (unless (boundp 'gnus-summary-misc-menu)
2173
2174     (easy-menu-define
2175       gnus-summary-kill-menu gnus-summary-mode-map ""
2176       (cons
2177        "Score"
2178        (nconc
2179         (list
2180          ["Customize" gnus-score-customize t])
2181         (gnus-make-score-map 'increase)
2182         (gnus-make-score-map 'lower)
2183         '(("Mark"
2184            ["Kill below" gnus-summary-kill-below t]
2185            ["Mark above" gnus-summary-mark-above t]
2186            ["Tick above" gnus-summary-tick-above t]
2187            ["Clear above" gnus-summary-clear-above t])
2188           ["Current score" gnus-summary-current-score t]
2189           ["Set score" gnus-summary-set-score t]
2190           ["Switch current score file..." gnus-score-change-score-file t]
2191           ["Set mark below..." gnus-score-set-mark-below t]
2192           ["Set expunge below..." gnus-score-set-expunge-below t]
2193           ["Edit current score file" gnus-score-edit-current-scores t]
2194           ["Edit score file" gnus-score-edit-file t]
2195           ["Trace score" gnus-score-find-trace t]
2196           ["Find words" gnus-score-find-favourite-words t]
2197           ["Rescore buffer" gnus-summary-rescore t]
2198           ["Increase score..." gnus-summary-increase-score t]
2199           ["Lower score..." gnus-summary-lower-score t]))))
2200
2201     ;; Define both the Article menu in the summary buffer and the
2202     ;; equivalent Commands menu in the article buffer here for
2203     ;; consistency.
2204     (let ((innards
2205            `(("Hide"
2206               ["All" gnus-article-hide t]
2207               ["Headers" gnus-article-hide-headers t]
2208               ["Signature" gnus-article-hide-signature t]
2209               ["Citation" gnus-article-hide-citation t]
2210               ["List identifiers" gnus-article-hide-list-identifiers t]
2211               ["Banner" gnus-article-strip-banner t]
2212               ["Boring headers" gnus-article-hide-boring-headers t])
2213              ("Highlight"
2214               ["All" gnus-article-highlight t]
2215               ["Headers" gnus-article-highlight-headers t]
2216               ["Signature" gnus-article-highlight-signature t]
2217               ["Citation" gnus-article-highlight-citation t])
2218              ("Date"
2219               ["Local" gnus-article-date-local t]
2220               ["ISO8601" gnus-article-date-iso8601 t]
2221               ["UT" gnus-article-date-ut t]
2222               ["Original" gnus-article-date-original t]
2223               ["Lapsed" gnus-article-date-lapsed t]
2224               ["User-defined" gnus-article-date-user t])
2225              ("Display"
2226               ["Remove images" gnus-article-remove-images t]
2227               ["Toggle smiley" gnus-treat-smiley t]
2228               ["Show X-Face" gnus-article-display-x-face t]
2229               ["Show picons in From" gnus-treat-from-picon t]
2230               ["Show picons in mail headers" gnus-treat-mail-picon t]
2231               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2232               ("View as different encoding"
2233                ,@(gnus-summary-menu-split
2234                   (mapcar
2235                    (lambda (cs)
2236                      ;; Since easymenu under Emacs doesn't allow
2237                      ;; lambda forms for menu commands, we should
2238                      ;; provide intern'ed function symbols.
2239                      (let ((command (intern (format "\
2240 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2241                        (fset command
2242                              `(lambda ()
2243                                 (interactive)
2244                                 (let ((gnus-summary-show-article-charset-alist
2245                                        '((1 . ,cs))))
2246                                   (gnus-summary-show-article 1))))
2247                        `[,(symbol-name cs) ,command t]))
2248                    (sort (if (fboundp 'coding-system-list)
2249                              (coding-system-list)
2250                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2251                            )
2252                          'string<)))))
2253              ("Washing"
2254               ("Remove Blanks"
2255                ["Leading" gnus-article-strip-leading-blank-lines t]
2256                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2257                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2258                ["All of the above" gnus-article-strip-blank-lines t]
2259                ["All" gnus-article-strip-all-blank-lines t]
2260                ["Leading space" gnus-article-strip-leading-space t]
2261                ["Trailing space" gnus-article-strip-trailing-space t]
2262                ["Leading space in headers"
2263                 gnus-article-remove-leading-whitespace t])
2264               ["Overstrike" gnus-article-treat-overstrike t]
2265               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2266               ["Emphasis" gnus-article-emphasize t]
2267               ["Word wrap" gnus-article-fill-cited-article t]
2268               ["Fill long lines" gnus-article-fill-long-lines t]
2269               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2270               ["Remove CR" gnus-article-remove-cr t]
2271               ["Rot 13" gnus-summary-caesar-message
2272                ,@(if (featurep 'xemacs) '(t)
2273                    '(:help "\"Caesar rotate\" article by 13"))]
2274               ["De-IDNA" gnus-summary-idna-message t]
2275               ["Morse decode" gnus-summary-morse-message t]
2276               ["Unix pipe..." gnus-summary-pipe-message t]
2277               ["Add buttons" gnus-article-add-buttons t]
2278               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2279               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2280               ["Toggle MIME" gnus-summary-toggle-mime t]
2281               ["Verbose header" gnus-summary-verbose-headers t]
2282               ["Toggle header" gnus-summary-toggle-header t]
2283               ["Unfold headers" gnus-article-treat-unfold-headers t]
2284               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2285               ["Html" gnus-article-wash-html t]
2286               ["Unsplit URLs" gnus-article-unsplit-urls t]
2287               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2288               ["Decode HZ" gnus-article-decode-HZ t]
2289               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2290               ("(Outlook) Deuglify"
2291                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2292                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2293                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2294                ["Full (Outlook) deuglify"
2295                 gnus-article-outlook-deuglify-article t])
2296               )
2297              ("Output"
2298               ["Save in default format..." gnus-summary-save-article
2299                ,@(if (featurep 'xemacs) '(t)
2300                    '(:help "Save article using default method"))]
2301               ["Save in file..." gnus-summary-save-article-file
2302                ,@(if (featurep 'xemacs) '(t)
2303                    '(:help "Save article in file"))]
2304               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2305               ["Save in MH folder..." gnus-summary-save-article-folder t]
2306               ["Save in VM folder..." gnus-summary-save-article-vm t]
2307               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2308               ["Save body in file..." gnus-summary-save-article-body-file t]
2309               ["Pipe through a filter..." gnus-summary-pipe-output t]
2310               ["Add to SOUP packet" gnus-soup-add-article t]
2311               ["Print with Muttprint..." gnus-summary-muttprint t]
2312               ["Print" gnus-summary-print-article
2313                ,@(if (featurep 'xemacs) '(t)
2314                    '(:help "Generate and print a PostScript image"))])
2315              ("Copy, move,... (Backend)"
2316               ,@(if (featurep 'xemacs) nil
2317                   '(:help "Copying, moving, expiring articles..."))
2318               ["Respool article..." gnus-summary-respool-article t]
2319               ["Move article..." gnus-summary-move-article
2320                (gnus-check-backend-function
2321                 'request-move-article gnus-newsgroup-name)]
2322               ["Copy article..." gnus-summary-copy-article t]
2323               ["Crosspost article..." gnus-summary-crosspost-article
2324                (gnus-check-backend-function
2325                 'request-replace-article gnus-newsgroup-name)]
2326               ["Import file..." gnus-summary-import-article
2327                (gnus-check-backend-function
2328                 'request-accept-article gnus-newsgroup-name)]
2329               ["Create article..." gnus-summary-create-article
2330                (gnus-check-backend-function
2331                 'request-accept-article gnus-newsgroup-name)]
2332               ["Check if posted" gnus-summary-article-posted-p t]
2333               ["Edit article" gnus-summary-edit-article
2334                (not (gnus-group-read-only-p))]
2335               ["Delete article" gnus-summary-delete-article
2336                (gnus-check-backend-function
2337                 'request-expire-articles gnus-newsgroup-name)]
2338               ["Query respool" gnus-summary-respool-query t]
2339               ["Trace respool" gnus-summary-respool-trace t]
2340               ["Delete expirable articles" gnus-summary-expire-articles-now
2341                (gnus-check-backend-function
2342                 'request-expire-articles gnus-newsgroup-name)])
2343              ("Extract"
2344               ["Uudecode" gnus-uu-decode-uu
2345                ,@(if (featurep 'xemacs) '(t)
2346                    '(:help "Decode uuencoded article(s)"))]
2347               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2348               ["Unshar" gnus-uu-decode-unshar t]
2349               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2350               ["Save" gnus-uu-decode-save t]
2351               ["Binhex" gnus-uu-decode-binhex t]
2352               ["Postscript" gnus-uu-decode-postscript t])
2353              ("Cache"
2354               ["Enter article" gnus-cache-enter-article t]
2355               ["Remove article" gnus-cache-remove-article t])
2356              ["Translate" gnus-article-babel t]
2357              ["Select article buffer" gnus-summary-select-article-buffer t]
2358              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2359              ["Isearch article..." gnus-summary-isearch-article t]
2360              ["Beginning of the article" gnus-summary-beginning-of-article t]
2361              ["End of the article" gnus-summary-end-of-article t]
2362              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2363              ["Fetch referenced articles" gnus-summary-refer-references t]
2364              ["Fetch current thread" gnus-summary-refer-thread t]
2365              ["Fetch article with id..." gnus-summary-refer-article t]
2366              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2367              ["Redisplay" gnus-summary-show-article t]
2368              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2369       (easy-menu-define
2370         gnus-summary-article-menu gnus-summary-mode-map ""
2371         (cons "Article" innards))
2372
2373       (if (not (keymapp gnus-summary-article-menu))
2374           (easy-menu-define
2375             gnus-article-commands-menu gnus-article-mode-map ""
2376             (cons "Commands" innards))
2377         ;; in Emacs, don't share menu.
2378         (setq gnus-article-commands-menu
2379               (copy-keymap gnus-summary-article-menu))
2380         (define-key gnus-article-mode-map [menu-bar commands]
2381           (cons "Commands" gnus-article-commands-menu))))
2382
2383     (easy-menu-define
2384       gnus-summary-thread-menu gnus-summary-mode-map ""
2385       '("Threads"
2386         ["Find all messages in thread" gnus-summary-refer-thread t]
2387         ["Toggle threading" gnus-summary-toggle-threads t]
2388         ["Hide threads" gnus-summary-hide-all-threads t]
2389         ["Show threads" gnus-summary-show-all-threads t]
2390         ["Hide thread" gnus-summary-hide-thread t]
2391         ["Show thread" gnus-summary-show-thread t]
2392         ["Go to next thread" gnus-summary-next-thread t]
2393         ["Go to previous thread" gnus-summary-prev-thread t]
2394         ["Go down thread" gnus-summary-down-thread t]
2395         ["Go up thread" gnus-summary-up-thread t]
2396         ["Top of thread" gnus-summary-top-thread t]
2397         ["Mark thread as read" gnus-summary-kill-thread t]
2398         ["Lower thread score" gnus-summary-lower-thread t]
2399         ["Raise thread score" gnus-summary-raise-thread t]
2400         ["Rethread current" gnus-summary-rethread-current t]))
2401
2402     (easy-menu-define
2403       gnus-summary-post-menu gnus-summary-mode-map ""
2404       `("Post"
2405         ["Send a message (mail or news)" gnus-summary-post-news
2406          ,@(if (featurep 'xemacs) '(t)
2407              '(:help "Compose a new message (mail or news)"))]
2408         ["Followup" gnus-summary-followup
2409          ,@(if (featurep 'xemacs) '(t)
2410              '(:help "Post followup to this article"))]
2411         ["Followup and yank" gnus-summary-followup-with-original
2412          ,@(if (featurep 'xemacs) '(t)
2413              '(:help "Post followup to this article, quoting its contents"))]
2414         ["Supersede article" gnus-summary-supersede-article t]
2415         ["Cancel article" gnus-summary-cancel-article
2416          ,@(if (featurep 'xemacs) '(t)
2417              '(:help "Cancel an article you posted"))]
2418         ["Reply" gnus-summary-reply t]
2419         ["Reply and yank" gnus-summary-reply-with-original t]
2420         ["Wide reply" gnus-summary-wide-reply t]
2421         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2422          ,@(if (featurep 'xemacs) '(t)
2423              '(:help "Mail a reply, quoting this article"))]
2424         ["Very wide reply" gnus-summary-very-wide-reply t]
2425         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2426          ,@(if (featurep 'xemacs) '(t)
2427              '(:help "Mail a very wide reply, quoting this article"))]
2428         ["Mail forward" gnus-summary-mail-forward t]
2429         ["Post forward" gnus-summary-post-forward t]
2430         ["Digest and mail" gnus-summary-digest-mail-forward t]
2431         ["Digest and post" gnus-summary-digest-post-forward t]
2432         ["Resend message" gnus-summary-resend-message t]
2433         ["Resend message edit" gnus-summary-resend-message-edit t]
2434         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2435         ["Send a mail" gnus-summary-mail-other-window t]
2436         ["Create a local message" gnus-summary-news-other-window t]
2437         ["Uuencode and post" gnus-uu-post-news
2438          ,@(if (featurep 'xemacs) '(t)
2439              '(:help "Post a uuencoded article"))]
2440         ["Followup via news" gnus-summary-followup-to-mail t]
2441         ["Followup via news and yank"
2442          gnus-summary-followup-to-mail-with-original t]
2443         ;;("Draft"
2444         ;;["Send" gnus-summary-send-draft t]
2445         ;;["Send bounced" gnus-resend-bounced-mail t])
2446         ))
2447
2448     (cond
2449      ((not (keymapp gnus-summary-post-menu))
2450       (setq gnus-article-post-menu gnus-summary-post-menu))
2451      ((not gnus-article-post-menu)
2452       ;; Don't share post menu.
2453       (setq gnus-article-post-menu
2454             (copy-keymap gnus-summary-post-menu))))
2455     (define-key gnus-article-mode-map [menu-bar post]
2456       (cons "Post" gnus-article-post-menu))
2457
2458     (easy-menu-define
2459       gnus-summary-misc-menu gnus-summary-mode-map ""
2460       `("Gnus"
2461         ("Mark Read"
2462          ["Mark as read" gnus-summary-mark-as-read-forward t]
2463          ["Mark same subject and select"
2464           gnus-summary-kill-same-subject-and-select t]
2465          ["Mark same subject" gnus-summary-kill-same-subject t]
2466          ["Catchup" gnus-summary-catchup
2467           ,@(if (featurep 'xemacs) '(t)
2468               '(:help "Mark unread articles in this group as read"))]
2469          ["Catchup all" gnus-summary-catchup-all t]
2470          ["Catchup to here" gnus-summary-catchup-to-here t]
2471          ["Catchup from here" gnus-summary-catchup-from-here t]
2472          ["Catchup region" gnus-summary-mark-region-as-read
2473           (gnus-mark-active-p)]
2474          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2475         ("Mark Various"
2476          ["Tick" gnus-summary-tick-article-forward t]
2477          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2478          ["Remove marks" gnus-summary-clear-mark-forward t]
2479          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2480          ["Set bookmark" gnus-summary-set-bookmark t]
2481          ["Remove bookmark" gnus-summary-remove-bookmark t])
2482         ("Limit to"
2483          ["Marks..." gnus-summary-limit-to-marks t]
2484          ["Subject..." gnus-summary-limit-to-subject t]
2485          ["Author..." gnus-summary-limit-to-author t]
2486          ["Recipient..." gnus-summary-limit-to-recipient t]
2487          ["Age..." gnus-summary-limit-to-age t]
2488          ["Extra..." gnus-summary-limit-to-extra t]
2489          ["Score..." gnus-summary-limit-to-score t]
2490          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2491          ["Unread" gnus-summary-limit-to-unread t]
2492          ["Unseen" gnus-summary-limit-to-unseen t]
2493          ["Replied" gnus-summary-limit-to-replied t]
2494          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2495          ["Next articles" gnus-summary-limit-to-articles t]
2496          ["Pop limit" gnus-summary-pop-limit t]
2497          ["Show dormant" gnus-summary-limit-include-dormant t]
2498          ["Hide childless dormant"
2499           gnus-summary-limit-exclude-childless-dormant t]
2500          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2501          ["Hide marked" gnus-summary-limit-exclude-marks t]
2502          ["Show expunged" gnus-summary-limit-include-expunged t])
2503         ("Process Mark"
2504          ["Set mark" gnus-summary-mark-as-processable t]
2505          ["Remove mark" gnus-summary-unmark-as-processable t]
2506          ["Remove all marks" gnus-summary-unmark-all-processable t]
2507          ["Invert marks" gnus-uu-invert-processable t]
2508          ["Mark above" gnus-uu-mark-over t]
2509          ["Mark series" gnus-uu-mark-series t]
2510          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2511          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2512          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2513          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2514          ["Mark all" gnus-uu-mark-all t]
2515          ["Mark buffer" gnus-uu-mark-buffer t]
2516          ["Mark sparse" gnus-uu-mark-sparse t]
2517          ["Mark thread" gnus-uu-mark-thread t]
2518          ["Unmark thread" gnus-uu-unmark-thread t]
2519          ("Process Mark Sets"
2520           ["Kill" gnus-summary-kill-process-mark t]
2521           ["Yank" gnus-summary-yank-process-mark
2522            gnus-newsgroup-process-stack]
2523           ["Save" gnus-summary-save-process-mark t]
2524           ["Run command on marked..." gnus-summary-universal-argument t]))
2525         ("Scroll article"
2526          ["Page forward" gnus-summary-next-page
2527           ,@(if (featurep 'xemacs) '(t)
2528               '(:help "Show next page of article"))]
2529          ["Page backward" gnus-summary-prev-page
2530           ,@(if (featurep 'xemacs) '(t)
2531               '(:help "Show previous page of article"))]
2532          ["Line forward" gnus-summary-scroll-up t])
2533         ("Move"
2534          ["Next unread article" gnus-summary-next-unread-article t]
2535          ["Previous unread article" gnus-summary-prev-unread-article t]
2536          ["Next article" gnus-summary-next-article t]
2537          ["Previous article" gnus-summary-prev-article t]
2538          ["Next unread subject" gnus-summary-next-unread-subject t]
2539          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2540          ["Next article same subject" gnus-summary-next-same-subject t]
2541          ["Previous article same subject" gnus-summary-prev-same-subject t]
2542          ["First unread article" gnus-summary-first-unread-article t]
2543          ["Best unread article" gnus-summary-best-unread-article t]
2544          ["Go to subject number..." gnus-summary-goto-subject t]
2545          ["Go to article number..." gnus-summary-goto-article t]
2546          ["Go to the last article" gnus-summary-goto-last-article t]
2547          ["Pop article off history" gnus-summary-pop-article t])
2548         ("Sort"
2549          ["Sort by number" gnus-summary-sort-by-number t]
2550          ["Sort by author" gnus-summary-sort-by-author t]
2551          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2552          ["Sort by subject" gnus-summary-sort-by-subject t]
2553          ["Sort by date" gnus-summary-sort-by-date t]
2554          ["Sort by score" gnus-summary-sort-by-score t]
2555          ["Sort by lines" gnus-summary-sort-by-lines t]
2556          ["Sort by characters" gnus-summary-sort-by-chars t]
2557          ["Randomize" gnus-summary-sort-by-random t]
2558          ["Original sort" gnus-summary-sort-by-original t])
2559         ("Help"
2560          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2561          ["Describe group" gnus-summary-describe-group t]
2562          ["Fetch charter" gnus-group-fetch-charter
2563           ,@(if (featurep 'xemacs) nil
2564               '(:help "Display the charter of the current group"))]
2565          ["Fetch control message" gnus-group-fetch-control
2566           ,@(if (featurep 'xemacs) nil
2567               '(:help "Display the archived control message for the current group"))]
2568          ["Read manual" gnus-info-find-node t])
2569         ("Modes"
2570          ["Pick and read" gnus-pick-mode t]
2571          ["Binary" gnus-binary-mode t])
2572         ("Regeneration"
2573          ["Regenerate" gnus-summary-prepare t]
2574          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2575          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2576          ["Toggle threading" gnus-summary-toggle-threads t])
2577         ["See old articles" gnus-summary-insert-old-articles t]
2578         ["See new articles" gnus-summary-insert-new-articles t]
2579         ["Filter articles..." gnus-summary-execute-command t]
2580         ["Run command on articles..." gnus-summary-universal-argument t]
2581         ["Search articles forward..." gnus-summary-search-article-forward t]
2582         ["Search articles backward..." gnus-summary-search-article-backward t]
2583         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2584         ["Expand window" gnus-summary-expand-window t]
2585         ["Expire expirable articles" gnus-summary-expire-articles
2586          (gnus-check-backend-function
2587           'request-expire-articles gnus-newsgroup-name)]
2588         ["Edit local kill file" gnus-summary-edit-local-kill t]
2589         ["Edit main kill file" gnus-summary-edit-global-kill t]
2590         ["Edit group parameters" gnus-summary-edit-parameters t]
2591         ["Customize group parameters" gnus-summary-customize-parameters t]
2592         ["Send a bug report" gnus-bug t]
2593         ("Exit"
2594          ["Catchup and exit" gnus-summary-catchup-and-exit
2595           ,@(if (featurep 'xemacs) '(t)
2596               '(:help "Mark unread articles in this group as read, then exit"))]
2597          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2598          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2599          ["Exit group" gnus-summary-exit
2600           ,@(if (featurep 'xemacs) '(t)
2601               '(:help "Exit current group, return to group selection mode"))]
2602          ["Exit group without updating" gnus-summary-exit-no-update t]
2603          ["Exit and goto next group" gnus-summary-next-group t]
2604          ["Exit and goto prev group" gnus-summary-prev-group t]
2605          ["Reselect group" gnus-summary-reselect-current-group t]
2606          ["Rescan group" gnus-summary-rescan-group t]
2607          ["Update dribble" gnus-summary-save-newsrc t])))
2608
2609     (gnus-run-hooks 'gnus-summary-menu-hook)))
2610
2611 (defvar gnus-summary-tool-bar-map nil)
2612
2613 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2614 (defun gnus-summary-make-tool-bar ()
2615   (if (and (fboundp 'tool-bar-add-item-from-menu)
2616            (default-value 'tool-bar-mode)
2617            (not gnus-summary-tool-bar-map))
2618       (setq gnus-summary-tool-bar-map
2619             (let ((tool-bar-map (make-sparse-keymap))
2620                   (load-path (mm-image-load-path)))
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-post-news "post" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-followup "followup" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-summary-reply "reply" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2649               (tool-bar-add-item-from-menu
2650                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2651               (tool-bar-add-item-from-menu
2652                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2653               tool-bar-map)))
2654   (if gnus-summary-tool-bar-map
2655       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2656
2657 (defun gnus-score-set-default (var value)
2658   "A version of set that updates the GNU Emacs menu-bar."
2659   (set var value)
2660   ;; It is the message that forces the active status to be updated.
2661   (message ""))
2662
2663 (defun gnus-make-score-map (type)
2664   "Make a summary score map of type TYPE."
2665   (if t
2666       nil
2667     (let ((headers '(("author" "from" string)
2668                      ("subject" "subject" string)
2669                      ("article body" "body" string)
2670                      ("article head" "head" string)
2671                      ("xref" "xref" string)
2672                      ("extra header" "extra" string)
2673                      ("lines" "lines" number)
2674                      ("followups to author" "followup" string)))
2675           (types '((number ("less than" <)
2676                            ("greater than" >)
2677                            ("equal" =))
2678                    (string ("substring" s)
2679                            ("exact string" e)
2680                            ("fuzzy string" f)
2681                            ("regexp" r))))
2682           (perms '(("temporary" (current-time-string))
2683                    ("permanent" nil)
2684                    ("immediate" now)))
2685           header)
2686       (list
2687        (apply
2688         'nconc
2689         (list
2690          (if (eq type 'lower)
2691              "Lower score"
2692            "Increase score"))
2693         (let (outh)
2694           (while headers
2695             (setq header (car headers))
2696             (setq outh
2697                   (cons
2698                    (apply
2699                     'nconc
2700                     (list (car header))
2701                     (let ((ts (cdr (assoc (nth 2 header) types)))
2702                           outt)
2703                       (while ts
2704                         (setq outt
2705                               (cons
2706                                (apply
2707                                 'nconc
2708                                 (list (caar ts))
2709                                 (let ((ps perms)
2710                                       outp)
2711                                   (while ps
2712                                     (setq outp
2713                                           (cons
2714                                            (vector
2715                                             (caar ps)
2716                                             (list
2717                                              'gnus-summary-score-entry
2718                                              (nth 1 header)
2719                                              (if (or (string= (nth 1 header)
2720                                                               "head")
2721                                                      (string= (nth 1 header)
2722                                                               "body"))
2723                                                  ""
2724                                                (list 'gnus-summary-header
2725                                                      (nth 1 header)))
2726                                              (list 'quote (nth 1 (car ts)))
2727                                              (list 'gnus-score-delta-default
2728                                                    nil)
2729                                              (nth 1 (car ps))
2730                                              t)
2731                                             t)
2732                                            outp))
2733                                     (setq ps (cdr ps)))
2734                                   (list (nreverse outp))))
2735                                outt))
2736                         (setq ts (cdr ts)))
2737                       (list (nreverse outt))))
2738                    outh))
2739             (setq headers (cdr headers)))
2740           (list (nreverse outh))))))))
2741
2742 \f
2743
2744 (defun gnus-summary-mode (&optional group)
2745   "Major mode for reading articles.
2746
2747 All normal editing commands are switched off.
2748 \\<gnus-summary-mode-map>
2749 Each line in this buffer represents one article.  To read an
2750 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2751 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2752 respectively.
2753
2754 You can also post articles and send mail from this buffer.  To
2755 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2756 of an article, type `\\[gnus-summary-reply]'.
2757
2758 There are approx. one gazillion commands you can execute in this
2759 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2760
2761 The following commands are available:
2762
2763 \\{gnus-summary-mode-map}"
2764   (interactive)
2765   (kill-all-local-variables)
2766   (when (gnus-visual-p 'summary-menu 'menu)
2767     (gnus-summary-make-menu-bar)
2768     (gnus-summary-make-tool-bar))
2769   (gnus-summary-make-local-variables)
2770   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2771     (gnus-summary-make-local-variables))
2772   (gnus-make-thread-indent-array)
2773   (gnus-simplify-mode-line)
2774   (setq major-mode 'gnus-summary-mode)
2775   (setq mode-name "Summary")
2776   (make-local-variable 'minor-mode-alist)
2777   (use-local-map gnus-summary-mode-map)
2778   (buffer-disable-undo)
2779   (setq buffer-read-only t              ;Disable modification
2780         show-trailing-whitespace nil)
2781   (setq truncate-lines t)
2782   (setq selective-display t)
2783   (setq selective-display-ellipses t)   ;Display `...'
2784   (gnus-summary-set-display-table)
2785   (gnus-set-default-directory)
2786   (setq gnus-newsgroup-name group)
2787   (unless (gnus-news-group-p group)
2788     (setq gnus-newsgroup-incorporated
2789           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2790   (make-local-variable 'gnus-summary-line-format)
2791   (make-local-variable 'gnus-summary-line-format-spec)
2792   (make-local-variable 'gnus-summary-dummy-line-format)
2793   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2794   (make-local-variable 'gnus-summary-mark-positions)
2795   (gnus-make-local-hook 'pre-command-hook)
2796   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2797   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2798   (turn-on-gnus-mailing-list-mode)
2799   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2800   (gnus-update-summary-mark-positions))
2801
2802 (defun gnus-summary-make-local-variables ()
2803   "Make all the local summary buffer variables."
2804   (let (global)
2805     (dolist (local gnus-summary-local-variables)
2806       (if (consp local)
2807           (progn
2808             (if (eq (cdr local) 'global)
2809                 ;; Copy the global value of the variable.
2810                 (setq global (symbol-value (car local)))
2811               ;; Use the value from the list.
2812               (setq global (eval (cdr local))))
2813             (set (make-local-variable (car local)) global))
2814         ;; Simple nil-valued local variable.
2815         (set (make-local-variable local) nil)))))
2816
2817 (defun gnus-summary-clear-local-variables ()
2818   (let ((locals gnus-summary-local-variables))
2819     (while locals
2820       (if (consp (car locals))
2821           (and (symbolp (caar locals))
2822                (set (caar locals) nil))
2823         (and (symbolp (car locals))
2824              (set (car locals) nil)))
2825       (setq locals (cdr locals)))))
2826
2827 ;; Summary data functions.
2828
2829 (defmacro gnus-data-number (data)
2830   `(car ,data))
2831
2832 (defmacro gnus-data-set-number (data number)
2833   `(setcar ,data ,number))
2834
2835 (defmacro gnus-data-mark (data)
2836   `(nth 1 ,data))
2837
2838 (defmacro gnus-data-set-mark (data mark)
2839   `(setcar (nthcdr 1 ,data) ,mark))
2840
2841 (defmacro gnus-data-pos (data)
2842   `(nth 2 ,data))
2843
2844 (defmacro gnus-data-set-pos (data pos)
2845   `(setcar (nthcdr 2 ,data) ,pos))
2846
2847 (defmacro gnus-data-header (data)
2848   `(nth 3 ,data))
2849
2850 (defmacro gnus-data-set-header (data header)
2851   `(setcar (nthcdr 3 ,data) ,header))
2852
2853 (defmacro gnus-data-level (data)
2854   `(nth 4 ,data))
2855
2856 (defmacro gnus-data-unread-p (data)
2857   `(= (nth 1 ,data) gnus-unread-mark))
2858
2859 (defmacro gnus-data-read-p (data)
2860   `(/= (nth 1 ,data) gnus-unread-mark))
2861
2862 (defmacro gnus-data-pseudo-p (data)
2863   `(consp (nth 3 ,data)))
2864
2865 (defmacro gnus-data-find (number)
2866   `(assq ,number gnus-newsgroup-data))
2867
2868 (defmacro gnus-data-find-list (number &optional data)
2869   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2870      (memq (assq ,number bdata)
2871            bdata)))
2872
2873 (defmacro gnus-data-make (number mark pos header level)
2874   `(list ,number ,mark ,pos ,header ,level))
2875
2876 (defun gnus-data-enter (after-article number mark pos header level offset)
2877   (let ((data (gnus-data-find-list after-article)))
2878     (unless data
2879       (error "No such article: %d" after-article))
2880     (setcdr data (cons (gnus-data-make number mark pos header level)
2881                        (cdr data)))
2882     (setq gnus-newsgroup-data-reverse nil)
2883     (gnus-data-update-list (cddr data) offset)))
2884
2885 (defun gnus-data-enter-list (after-article list &optional offset)
2886   (when list
2887     (let ((data (and after-article (gnus-data-find-list after-article)))
2888           (ilist list))
2889       (if (not (or data
2890                    after-article))
2891           (let ((odata gnus-newsgroup-data))
2892             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2893             (when offset
2894               (gnus-data-update-list odata offset)))
2895         ;; Find the last element in the list to be spliced into the main
2896         ;; list.
2897         (setq list (last list))
2898         (if (not data)
2899             (progn
2900               (setcdr list gnus-newsgroup-data)
2901               (setq gnus-newsgroup-data ilist)
2902               (when offset
2903                 (gnus-data-update-list (cdr list) offset)))
2904           (setcdr list (cdr data))
2905           (setcdr data ilist)
2906           (when offset
2907             (gnus-data-update-list (cdr list) offset))))
2908       (setq gnus-newsgroup-data-reverse nil))))
2909
2910 (defun gnus-data-remove (article &optional offset)
2911   (let ((data gnus-newsgroup-data))
2912     (if (= (gnus-data-number (car data)) article)
2913         (progn
2914           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2915                 gnus-newsgroup-data-reverse nil)
2916           (when offset
2917             (gnus-data-update-list gnus-newsgroup-data offset)))
2918       (while (cdr data)
2919         (when (= (gnus-data-number (cadr data)) article)
2920           (setcdr data (cddr data))
2921           (when offset
2922             (gnus-data-update-list (cdr data) offset))
2923           (setq data nil
2924                 gnus-newsgroup-data-reverse nil))
2925         (setq data (cdr data))))))
2926
2927 (defmacro gnus-data-list (backward)
2928   `(if ,backward
2929        (or gnus-newsgroup-data-reverse
2930            (setq gnus-newsgroup-data-reverse
2931                  (reverse gnus-newsgroup-data)))
2932      gnus-newsgroup-data))
2933
2934 (defun gnus-data-update-list (data offset)
2935   "Add OFFSET to the POS of all data entries in DATA."
2936   (setq gnus-newsgroup-data-reverse nil)
2937   (while data
2938     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2939     (setq data (cdr data))))
2940
2941 (defun gnus-summary-article-pseudo-p (article)
2942   "Say whether this article is a pseudo article or not."
2943   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2944
2945 (defmacro gnus-summary-article-sparse-p (article)
2946   "Say whether this article is a sparse article or not."
2947   `(memq ,article gnus-newsgroup-sparse))
2948
2949 (defmacro gnus-summary-article-ancient-p (article)
2950   "Say whether this article is a sparse article or not."
2951   `(memq ,article gnus-newsgroup-ancient))
2952
2953 (defun gnus-article-parent-p (number)
2954   "Say whether this article is a parent or not."
2955   (let ((data (gnus-data-find-list number)))
2956     (and (cdr data)                     ; There has to be an article after...
2957          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2958             (gnus-data-level (nth 1 data))))))
2959
2960 (defun gnus-article-children (number)
2961   "Return a list of all children to NUMBER."
2962   (let* ((data (gnus-data-find-list number))
2963          (level (gnus-data-level (car data)))
2964          children)
2965     (setq data (cdr data))
2966     (while (and data
2967                 (= (gnus-data-level (car data)) (1+ level)))
2968       (push (gnus-data-number (car data)) children)
2969       (setq data (cdr data)))
2970     children))
2971
2972 (defmacro gnus-summary-skip-intangible ()
2973   "If the current article is intangible, then jump to a different article."
2974   '(let ((to (get-text-property (point) 'gnus-intangible)))
2975      (and to (gnus-summary-goto-subject to))))
2976
2977 (defmacro gnus-summary-article-intangible-p ()
2978   "Say whether this article is intangible or not."
2979   '(get-text-property (point) 'gnus-intangible))
2980
2981 (defun gnus-article-read-p (article)
2982   "Say whether ARTICLE is read or not."
2983   (not (or (memq article gnus-newsgroup-marked)
2984            (memq article gnus-newsgroup-spam-marked)
2985            (memq article gnus-newsgroup-unreads)
2986            (memq article gnus-newsgroup-unselected)
2987            (memq article gnus-newsgroup-dormant))))
2988
2989 ;; Some summary mode macros.
2990
2991 (defmacro gnus-summary-article-number ()
2992   "The article number of the article on the current line.
2993 If there isn't an article number here, then we return the current
2994 article number."
2995   '(progn
2996      (gnus-summary-skip-intangible)
2997      (or (get-text-property (point) 'gnus-number)
2998          (gnus-summary-last-subject))))
2999
3000 (defmacro gnus-summary-article-header (&optional number)
3001   "Return the header of article NUMBER."
3002   `(gnus-data-header (gnus-data-find
3003                       ,(or number '(gnus-summary-article-number)))))
3004
3005 (defmacro gnus-summary-thread-level (&optional number)
3006   "Return the level of thread that starts with article NUMBER."
3007   `(if (and (eq gnus-summary-make-false-root 'dummy)
3008             (get-text-property (point) 'gnus-intangible))
3009        0
3010      (gnus-data-level (gnus-data-find
3011                        ,(or number '(gnus-summary-article-number))))))
3012
3013 (defmacro gnus-summary-article-mark (&optional number)
3014   "Return the mark of article NUMBER."
3015   `(gnus-data-mark (gnus-data-find
3016                     ,(or number '(gnus-summary-article-number)))))
3017
3018 (defmacro gnus-summary-article-pos (&optional number)
3019   "Return the position of the line of article NUMBER."
3020   `(gnus-data-pos (gnus-data-find
3021                    ,(or number '(gnus-summary-article-number)))))
3022
3023 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3024 (defmacro gnus-summary-article-subject (&optional number)
3025   "Return current subject string or nil if nothing."
3026   `(let ((headers
3027           ,(if number
3028                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3029              '(gnus-data-header (assq (gnus-summary-article-number)
3030                                       gnus-newsgroup-data)))))
3031      (and headers
3032           (vectorp headers)
3033           (mail-header-subject headers))))
3034
3035 (defmacro gnus-summary-article-score (&optional number)
3036   "Return current article score."
3037   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3038                   gnus-newsgroup-scored))
3039        gnus-summary-default-score 0))
3040
3041 (defun gnus-summary-article-children (&optional number)
3042   "Return a list of article numbers that are children of article NUMBER."
3043   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3044          (level (gnus-data-level (car data)))
3045          l children)
3046     (while (and (setq data (cdr data))
3047                 (> (setq l (gnus-data-level (car data))) level))
3048       (and (= (1+ level) l)
3049            (push (gnus-data-number (car data))
3050                  children)))
3051     (nreverse children)))
3052
3053 (defun gnus-summary-article-parent (&optional number)
3054   "Return the article number of the parent of article NUMBER."
3055   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3056                                     (gnus-data-list t)))
3057          (level (gnus-data-level (car data))))
3058     (if (zerop level)
3059         ()                              ; This is a root.
3060       ;; We search until we find an article with a level less than
3061       ;; this one.  That function has to be the parent.
3062       (while (and (setq data (cdr data))
3063                   (not (< (gnus-data-level (car data)) level))))
3064       (and data (gnus-data-number (car data))))))
3065
3066 (defun gnus-unread-mark-p (mark)
3067   "Say whether MARK is the unread mark."
3068   (= mark gnus-unread-mark))
3069
3070 (defun gnus-read-mark-p (mark)
3071   "Say whether MARK is one of the marks that mark as read.
3072 This is all marks except unread, ticked, dormant, and expirable."
3073   (not (or (= mark gnus-unread-mark)
3074            (= mark gnus-ticked-mark)
3075            (= mark gnus-spam-mark)
3076            (= mark gnus-dormant-mark)
3077            (= mark gnus-expirable-mark))))
3078
3079 (defmacro gnus-article-mark (number)
3080   "Return the MARK of article NUMBER.
3081 This macro should only be used when computing the mark the \"first\"
3082 time; i.e., when generating the summary lines.  After that,
3083 `gnus-summary-article-mark' should be used to examine the
3084 marks of articles."
3085   `(cond
3086     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3087     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3088     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3089     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3090     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3091     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3092     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3093     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3094            gnus-ancient-mark))))
3095
3096 ;; Saving hidden threads.
3097
3098 (defmacro gnus-save-hidden-threads (&rest forms)
3099   "Save hidden threads, eval FORMS, and restore the hidden threads."
3100   (let ((config (make-symbol "config")))
3101     `(let ((,config (gnus-hidden-threads-configuration)))
3102        (unwind-protect
3103            (save-excursion
3104              ,@forms)
3105          (gnus-restore-hidden-threads-configuration ,config)))))
3106 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3107 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3108
3109 (defun gnus-data-compute-positions ()
3110   "Compute the positions of all articles."
3111   (setq gnus-newsgroup-data-reverse nil)
3112   (let ((data gnus-newsgroup-data))
3113     (save-excursion
3114       (gnus-save-hidden-threads
3115         (gnus-summary-show-all-threads)
3116         (goto-char (point-min))
3117         (while data
3118           (while (get-text-property (point) 'gnus-intangible)
3119             (forward-line 1))
3120           (gnus-data-set-pos (car data) (+ (point) 3))
3121           (setq data (cdr data))
3122           (forward-line 1))))))
3123
3124 (defun gnus-hidden-threads-configuration ()
3125   "Return the current hidden threads configuration."
3126   (save-excursion
3127     (let (config)
3128       (goto-char (point-min))
3129       (while (search-forward "\r" nil t)
3130         (push (1- (point)) config))
3131       config)))
3132
3133 (defun gnus-restore-hidden-threads-configuration (config)
3134   "Restore hidden threads configuration from CONFIG."
3135   (save-excursion
3136     (let (point buffer-read-only)
3137       (while (setq point (pop config))
3138         (when (and (< point (point-max))
3139                    (goto-char point)
3140                    (eq (char-after) ?\n))
3141           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3142
3143 ;; Various summary mode internalish functions.
3144
3145 (defun gnus-mouse-pick-article (e)
3146   (interactive "e")
3147   (mouse-set-point e)
3148   (gnus-summary-next-page nil t))
3149
3150 (defun gnus-summary-set-display-table ()
3151   "Change the display table.
3152 Odd characters have a tendency to mess
3153 up nicely formatted displays - we make all possible glyphs
3154 display only a single character."
3155
3156   ;; We start from the standard display table, if any.
3157   (let ((table (or (copy-sequence standard-display-table)
3158                    (make-display-table)))
3159         (i 32))
3160     ;; Nix out all the control chars...
3161     (while (>= (setq i (1- i)) 0)
3162       (aset table i [??]))
3163     ;; ... but not newline and cr, of course.  (cr is necessary for the
3164     ;; selective display).
3165     (aset table ?\n nil)
3166     (aset table ?\r nil)
3167     ;; We keep TAB as well.
3168     (aset table ?\t nil)
3169     ;; We nix out any glyphs over 126 that are not set already.
3170     (let ((i 256))
3171       (while (>= (setq i (1- i)) 127)
3172         ;; Only modify if the entry is nil.
3173         (unless (aref table i)
3174           (aset table i [??]))))
3175     (setq buffer-display-table table)))
3176
3177 (defun gnus-summary-set-article-display-arrow (pos)
3178   "Update the overlay arrow to point to line at position POS."
3179   (when (and gnus-summary-display-arrow
3180              (boundp 'overlay-arrow-position)
3181              (boundp 'overlay-arrow-string))
3182     (save-excursion
3183       (goto-char pos)
3184       (beginning-of-line)
3185       (unless overlay-arrow-position
3186         (setq overlay-arrow-position (make-marker)))
3187       (setq overlay-arrow-string "=>"
3188             overlay-arrow-position (set-marker overlay-arrow-position
3189                                                (point)
3190                                                (current-buffer))))))
3191
3192 (defun gnus-summary-setup-buffer (group)
3193   "Initialize summary buffer."
3194   (let ((buffer (gnus-summary-buffer-name group))
3195         (dead-name (concat "*Dead Summary "
3196                            (gnus-group-decoded-name group) "*")))
3197     ;; If a dead summary buffer exists, we kill it.
3198     (when (gnus-buffer-live-p dead-name)
3199       (gnus-kill-buffer dead-name))
3200     (if (get-buffer buffer)
3201         (progn
3202           (set-buffer buffer)
3203           (setq gnus-summary-buffer (current-buffer))
3204           (not gnus-newsgroup-prepared))
3205       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3206       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3207       (gnus-summary-mode group)
3208       (when gnus-carpal
3209         (gnus-carpal-setup-buffer 'summary))
3210       (unless gnus-single-article-buffer
3211         (make-local-variable 'gnus-article-buffer)
3212         (make-local-variable 'gnus-article-current)
3213         (make-local-variable 'gnus-original-article-buffer))
3214       (setq gnus-newsgroup-name group)
3215       ;; Set any local variables in the group parameters.
3216       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3217       t)))
3218
3219 (defun gnus-set-global-variables ()
3220   "Set the global equivalents of the buffer-local variables.
3221 They are set to the latest values they had.  These reflect the summary
3222 buffer that was in action when the last article was fetched."
3223   (when (eq major-mode 'gnus-summary-mode)
3224     (setq gnus-summary-buffer (current-buffer))
3225     (let ((name gnus-newsgroup-name)
3226           (marked gnus-newsgroup-marked)
3227           (spam gnus-newsgroup-spam-marked)
3228           (unread gnus-newsgroup-unreads)
3229           (headers gnus-current-headers)
3230           (data gnus-newsgroup-data)
3231           (summary gnus-summary-buffer)
3232           (article-buffer gnus-article-buffer)
3233           (original gnus-original-article-buffer)
3234           (gac gnus-article-current)
3235           (reffed gnus-reffed-article-number)
3236           (score-file gnus-current-score-file)
3237           (default-charset gnus-newsgroup-charset)
3238           vlist)
3239       (let ((locals gnus-newsgroup-variables))
3240         (while locals
3241           (if (consp (car locals))
3242               (push (eval (caar locals)) vlist)
3243             (push (eval (car locals)) vlist))
3244           (setq locals (cdr locals)))
3245         (setq vlist (nreverse vlist)))
3246       (with-current-buffer gnus-group-buffer
3247         (setq gnus-newsgroup-name name
3248               gnus-newsgroup-marked marked
3249               gnus-newsgroup-spam-marked spam
3250               gnus-newsgroup-unreads unread
3251               gnus-current-headers headers
3252               gnus-newsgroup-data data
3253               gnus-article-current gac
3254               gnus-summary-buffer summary
3255               gnus-article-buffer article-buffer
3256               gnus-original-article-buffer original
3257               gnus-reffed-article-number reffed
3258               gnus-current-score-file score-file
3259               gnus-newsgroup-charset default-charset)
3260         (let ((locals gnus-newsgroup-variables))
3261           (while locals
3262             (if (consp (car locals))
3263                 (set (caar locals) (pop vlist))
3264               (set (car locals) (pop vlist)))
3265             (setq locals (cdr locals))))
3266         ;; The article buffer also has local variables.
3267         (when (gnus-buffer-live-p gnus-article-buffer)
3268           (set-buffer gnus-article-buffer)
3269           (setq gnus-summary-buffer summary))))))
3270
3271 (defun gnus-summary-article-unread-p (article)
3272   "Say whether ARTICLE is unread or not."
3273   (memq article gnus-newsgroup-unreads))
3274
3275 (defun gnus-summary-first-article-p (&optional article)
3276   "Return whether ARTICLE is the first article in the buffer."
3277   (if (not (setq article (or article (gnus-summary-article-number))))
3278       nil
3279     (eq article (caar gnus-newsgroup-data))))
3280
3281 (defun gnus-summary-last-article-p (&optional article)
3282   "Return whether ARTICLE is the last article in the buffer."
3283   (if (not (setq article (or article (gnus-summary-article-number))))
3284       ;; All non-existent numbers are the last article.  :-)
3285       t
3286     (not (cdr (gnus-data-find-list article)))))
3287
3288 (defun gnus-make-thread-indent-array ()
3289   (let ((n 200))
3290     (unless (and gnus-thread-indent-array
3291                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3292       (setq gnus-thread-indent-array (make-vector 201 "")
3293             gnus-thread-indent-array-level gnus-thread-indent-level)
3294       (while (>= n 0)
3295         (aset gnus-thread-indent-array n
3296               (make-string (* n gnus-thread-indent-level) ? ))
3297         (setq n (1- n))))))
3298
3299 (defun gnus-update-summary-mark-positions ()
3300   "Compute where the summary marks are to go."
3301   (save-excursion
3302     (when (gnus-buffer-exists-p gnus-summary-buffer)
3303       (set-buffer gnus-summary-buffer))
3304     (let ((spec gnus-summary-line-format-spec)
3305           pos)
3306       (save-excursion
3307         (gnus-set-work-buffer)
3308         (let ((gnus-tmp-unread ?Z)
3309               (gnus-replied-mark ?Z)
3310               (gnus-score-below-mark ?Z)
3311               (gnus-score-over-mark ?Z)
3312               (gnus-undownloaded-mark ?Z)
3313               (gnus-summary-line-format-spec spec)
3314               (gnus-newsgroup-downloadable '(0))
3315               (header
3316                (make-full-mail-header
3317                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3318               case-fold-search ignores)
3319           ;; Here, all marks are bound to Z.
3320           (gnus-summary-insert-line header
3321                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3322           (goto-char (point-min))
3323           ;; Memorize the positions of the same characters as dummy marks.
3324           (while (re-search-forward "[A-D]" nil t)
3325             (push (point) ignores))
3326           (erase-buffer)
3327           ;; We use A-D as dummy marks in order to know column positions
3328           ;; where marks should be inserted.
3329           (setq gnus-tmp-unread ?A
3330                 gnus-replied-mark ?B
3331                 gnus-score-below-mark ?C
3332                 gnus-score-over-mark ?C
3333                 gnus-undownloaded-mark ?D)
3334           (gnus-summary-insert-line header
3335                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3336           ;; Ignore characters which aren't dummy marks.
3337           (dolist (p ignores)
3338             (delete-region (goto-char (1- p)) p)
3339             (insert ?Z))
3340           (goto-char (point-min))
3341           (setq pos (list (cons 'unread
3342                                 (and (search-forward "A" nil t)
3343                                      (- (point) (point-min) 1)))))
3344           (goto-char (point-min))
3345           (push (cons 'replied (and (search-forward "B" nil t)
3346                                     (- (point) (point-min) 1)))
3347                 pos)
3348           (goto-char (point-min))
3349           (push (cons 'score (and (search-forward "C" nil t)
3350                                   (- (point) (point-min) 1)))
3351                 pos)
3352           (goto-char (point-min))
3353           (push (cons 'download (and (search-forward "D" nil t)
3354                                      (- (point) (point-min) 1)))
3355                 pos)))
3356       (setq gnus-summary-mark-positions pos))))
3357
3358 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3359   "Insert a dummy root in the summary buffer."
3360   (beginning-of-line)
3361   (gnus-add-text-properties
3362    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3363    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3364
3365 (defun gnus-summary-extract-address-component (from)
3366   (or (car (funcall gnus-extract-address-components from))
3367       from))
3368
3369 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3370   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3371                                 default-mime-charset)))
3372     ;; Is it really necessary to do this next part for each summary line?
3373     ;; Luckily, doesn't seem to slow things down much.
3374     (or
3375      (and gnus-ignored-from-addresses
3376           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3377           (let ((extra-headers (mail-header-extra header))
3378                 to
3379                 newsgroups)
3380             (cond
3381              ((setq to (cdr (assq 'To extra-headers)))
3382               (concat gnus-summary-to-prefix
3383                       (inline
3384                         (gnus-summary-extract-address-component
3385                          (funcall gnus-decode-encoded-word-function to)))))
3386              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3387               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3388      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3389
3390 (defun gnus-summary-insert-line (gnus-tmp-header
3391                                  gnus-tmp-level gnus-tmp-current
3392                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3393                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3394                                  &optional gnus-tmp-dummy gnus-tmp-score
3395                                  gnus-tmp-process)
3396   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3397          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3398          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3399          (gnus-tmp-score-char
3400           (if (or (null gnus-summary-default-score)
3401                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3402                       gnus-summary-zcore-fuzz))
3403               ?\ ;;;Whitespace
3404             (if (< gnus-tmp-score gnus-summary-default-score)
3405                 gnus-score-below-mark gnus-score-over-mark)))
3406          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3407          (gnus-tmp-replied
3408           (cond (gnus-tmp-process gnus-process-mark)
3409                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3410                  gnus-cached-mark)
3411                 (gnus-tmp-replied gnus-replied-mark)
3412                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3413                  gnus-forwarded-mark)
3414                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3415                  gnus-saved-mark)
3416                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3417                  gnus-recent-mark)
3418                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3419                  gnus-unseen-mark)
3420                 (t gnus-no-mark)))
3421          (gnus-tmp-downloaded
3422           (cond (undownloaded
3423                  gnus-undownloaded-mark)
3424                 (gnus-newsgroup-agentized
3425                  gnus-downloaded-mark)
3426                 (t
3427                  gnus-no-mark)))
3428          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3429          (gnus-tmp-name
3430           (cond
3431            ((string-match "<[^>]+> *$" gnus-tmp-from)
3432             (let ((beg (match-beginning 0)))
3433               (or (and (string-match "^\".+\"" gnus-tmp-from)
3434                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3435                   (substring gnus-tmp-from 0 beg))))
3436            ((string-match "(.+)" gnus-tmp-from)
3437             (substring gnus-tmp-from
3438                        (1+ (match-beginning 0)) (1- (match-end 0))))
3439            (t gnus-tmp-from)))
3440          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3441          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3442          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3443          (buffer-read-only nil))
3444     (when (string= gnus-tmp-name "")
3445       (setq gnus-tmp-name gnus-tmp-from))
3446     (unless (numberp gnus-tmp-lines)
3447       (setq gnus-tmp-lines -1))
3448     (if (= gnus-tmp-lines -1)
3449         (setq gnus-tmp-lines "?")
3450       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3451     (gnus-put-text-property-excluding-characters-with-faces
3452      (point)
3453      (progn (eval gnus-summary-line-format-spec) (point))
3454      'gnus-number gnus-tmp-number)
3455     (when (gnus-visual-p 'summary-highlight 'highlight)
3456       (forward-line -1)
3457       (gnus-run-hooks 'gnus-summary-update-hook)
3458       (forward-line 1))))
3459
3460 (defun gnus-summary-update-line (&optional dont-update)
3461   "Update summary line after change."
3462   (when (and gnus-summary-default-score
3463              (not gnus-summary-inhibit-highlight))
3464     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3465            (article (gnus-summary-article-number))
3466            (score (gnus-summary-article-score article)))
3467       (unless dont-update
3468         (if (and gnus-summary-mark-below
3469                  (< (gnus-summary-article-score)
3470                     gnus-summary-mark-below))
3471             ;; This article has a low score, so we mark it as read.
3472             (when (memq article gnus-newsgroup-unreads)
3473               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3474           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3475             ;; This article was previously marked as read on account
3476             ;; of a low score, but now it has risen, so we mark it as
3477             ;; unread.
3478             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3479         (gnus-summary-update-mark
3480          (if (or (null gnus-summary-default-score)
3481                  (<= (abs (- score gnus-summary-default-score))
3482                      gnus-summary-zcore-fuzz))
3483              ?\ ;;;Whitespace
3484            (if (< score gnus-summary-default-score)
3485                gnus-score-below-mark gnus-score-over-mark))
3486          'score))
3487       ;; Do visual highlighting.
3488       (when (gnus-visual-p 'summary-highlight 'highlight)
3489         (gnus-run-hooks 'gnus-summary-update-hook)))))
3490
3491 (defvar gnus-tmp-new-adopts nil)
3492
3493 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3494   "Return the number of articles in THREAD.
3495 This may be 0 in some cases -- if none of the articles in
3496 the thread are to be displayed."
3497   (let* ((number
3498           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3499           (cond
3500            ((not (listp thread))
3501             1)
3502            ((and (consp thread) (cdr thread))
3503             (apply
3504              '+ 1 (mapcar
3505                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3506            ((null thread)
3507             1)
3508            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3509             1)
3510            (t 0))))
3511     (when (and level (zerop level) gnus-tmp-new-adopts)
3512       (incf number
3513             (apply '+ (mapcar
3514                        'gnus-summary-number-of-articles-in-thread
3515                        gnus-tmp-new-adopts))))
3516     (if char
3517         (if (> number 1) gnus-not-empty-thread-mark
3518           gnus-empty-thread-mark)
3519       number)))
3520
3521 (defsubst gnus-summary-line-message-size (head)
3522   "Return pretty-printed version of message size.
3523 This function is intended to be used in
3524 `gnus-summary-line-format-alist'."
3525   (let ((c (or (mail-header-chars head) -1)))
3526     (cond ((< c 0) "n/a")               ; chars not available
3527           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3528           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3529           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3530           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3531
3532
3533 (defun gnus-summary-set-local-parameters (group)
3534   "Go through the local params of GROUP and set all variable specs in that list."
3535   (let ((vars '(quit-config)))          ; Ignore quit-config.
3536     (dolist (elem (gnus-group-find-parameter group))
3537       (and (consp elem)                 ; Has to be a cons.
3538            (consp (cdr elem))           ; The cdr has to be a list.
3539            (symbolp (car elem))         ; Has to be a symbol in there.
3540            (not (memq (car elem) vars))
3541            (ignore-errors               ; So we set it.
3542              (push (car elem) vars)
3543              (make-local-variable (car elem))
3544              (set (car elem) (eval (nth 1 elem))))))))
3545
3546 (defun gnus-summary-read-group (group &optional show-all no-article
3547                                       kill-buffer no-display backward
3548                                       select-articles)
3549   "Start reading news in newsgroup GROUP.
3550 If SHOW-ALL is non-nil, already read articles are also listed.
3551 If NO-ARTICLE is non-nil, no article is selected initially.
3552 If NO-DISPLAY, don't generate a summary buffer."
3553   (let (result)
3554     (while (and group
3555                 (null (setq result
3556                             (let ((gnus-auto-select-next nil))
3557                               (or (gnus-summary-read-group-1
3558                                    group show-all no-article
3559                                    kill-buffer no-display
3560                                    select-articles)
3561                                   (setq show-all nil
3562                                         select-articles nil)))))
3563                 (eq gnus-auto-select-next 'quietly))
3564       (set-buffer gnus-group-buffer)
3565       ;; The entry function called above goes to the next
3566       ;; group automatically, so we go two groups back
3567       ;; if we are searching for the previous group.
3568       (when backward
3569         (gnus-group-prev-unread-group 2))
3570       (if (not (equal group (gnus-group-group-name)))
3571           (setq group (gnus-group-group-name))
3572         (setq group nil)))
3573     result))
3574
3575 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3576   "Directly jump to the other GROUP from summary buffer.
3577 If SHOW-ALL is non-nil, already read articles are also listed."
3578   (interactive
3579    (if (eq gnus-summary-buffer (current-buffer))
3580        (list (completing-read
3581               "Group: " gnus-active-hashtb nil t
3582               (when (and gnus-newsgroup-name
3583                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3584                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3585               'gnus-group-history)
3586              current-prefix-arg)
3587      (error "%s must be invoked from a gnus summary buffer." this-command)))
3588   (unless (or (zerop (length group))
3589               (and gnus-newsgroup-name
3590                    (string-equal gnus-newsgroup-name group)))
3591     (gnus-summary-exit)
3592     (gnus-summary-read-group group show-all
3593                              gnus-dont-select-after-jump-to-other-group)))
3594
3595 (defun gnus-summary-read-group-1 (group show-all no-article
3596                                         kill-buffer no-display
3597                                         &optional select-articles)
3598   ;; Killed foreign groups can't be entered.
3599   ;;  (when (and (not (gnus-group-native-p group))
3600   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3601   ;;    (error "Dead non-native groups can't be entered"))
3602   (gnus-message 5 "Retrieving newsgroup: %s..."
3603                 (gnus-group-decoded-name group))
3604   (let* ((new-group (gnus-summary-setup-buffer group))
3605          (quit-config (gnus-group-quit-config group))
3606          (did-select (and new-group (gnus-select-newsgroup
3607                                      group show-all select-articles))))
3608     (cond
3609      ;; This summary buffer exists already, so we just select it.
3610      ((not new-group)
3611       (gnus-set-global-variables)
3612       (when kill-buffer
3613         (gnus-kill-or-deaden-summary kill-buffer))
3614       (gnus-configure-windows 'summary 'force)
3615       (gnus-set-mode-line 'summary)
3616       (gnus-summary-position-point)
3617       (message "")
3618       t)
3619      ;; We couldn't select this group.
3620      ((null did-select)
3621       (when (and (eq major-mode 'gnus-summary-mode)
3622                  (not (equal (current-buffer) kill-buffer)))
3623         (kill-buffer (current-buffer))
3624         (if (not quit-config)
3625             (progn
3626               ;; Update the info -- marks might need to be removed,
3627               ;; for instance.
3628               (gnus-summary-update-info)
3629               (set-buffer gnus-group-buffer)
3630               (gnus-group-jump-to-group group)
3631               (gnus-group-next-unread-group 1))
3632           (gnus-handle-ephemeral-exit quit-config)))
3633       (let ((grpinfo (gnus-get-info group)))
3634         (if (null (gnus-info-read grpinfo))
3635             (gnus-message 3 "Group %s contains no messages"
3636                           (gnus-group-decoded-name group))
3637           (gnus-message 3 "Can't select group")))
3638       nil)
3639      ;; The user did a `C-g' while prompting for number of articles,
3640      ;; so we exit this group.
3641      ((eq did-select 'quit)
3642       (and (eq major-mode 'gnus-summary-mode)
3643            (not (equal (current-buffer) kill-buffer))
3644            (kill-buffer (current-buffer)))
3645       (when kill-buffer
3646         (gnus-kill-or-deaden-summary kill-buffer))
3647       (if (not quit-config)
3648           (progn
3649             (set-buffer gnus-group-buffer)
3650             (gnus-group-jump-to-group group)
3651             (gnus-group-next-unread-group 1)
3652             (gnus-configure-windows 'group 'force))
3653         (gnus-handle-ephemeral-exit quit-config))
3654       ;; Finally signal the quit.
3655       (signal 'quit nil))
3656      ;; The group was successfully selected.
3657      (t
3658       (gnus-set-global-variables)
3659       ;; Save the active value in effect when the group was entered.
3660       (setq gnus-newsgroup-active
3661             (gnus-copy-sequence
3662              (gnus-active gnus-newsgroup-name)))
3663       ;; You can change the summary buffer in some way with this hook.
3664       (gnus-run-hooks 'gnus-select-group-hook)
3665       (when (memq 'summary (gnus-update-format-specifications
3666                             nil 'summary 'summary-mode 'summary-dummy))
3667         ;; The format specification for the summary line was updated,
3668         ;; so we need to update the mark positions as well.
3669         (gnus-update-summary-mark-positions))
3670       ;; Do score processing.
3671       (when gnus-use-scoring
3672         (gnus-possibly-score-headers))
3673       ;; Check whether to fill in the gaps in the threads.
3674       (when gnus-build-sparse-threads
3675         (gnus-build-sparse-threads))
3676       ;; Find the initial limit.
3677       (if show-all
3678           (let ((gnus-newsgroup-dormant nil))
3679             (gnus-summary-initial-limit show-all))
3680         (gnus-summary-initial-limit show-all))
3681       ;; Generate the summary buffer.
3682       (unless no-display
3683         (gnus-summary-prepare))
3684       (when gnus-use-trees
3685         (gnus-tree-open group)
3686         (setq gnus-summary-highlight-line-function
3687               'gnus-tree-highlight-article))
3688       ;; If the summary buffer is empty, but there are some low-scored
3689       ;; articles or some excluded dormants, we include these in the
3690       ;; buffer.
3691       (when (and (zerop (buffer-size))
3692                  (not no-display))
3693         (cond (gnus-newsgroup-dormant
3694                (gnus-summary-limit-include-dormant))
3695               ((and gnus-newsgroup-scored show-all)
3696                (gnus-summary-limit-include-expunged t))))
3697       ;; Function `gnus-apply-kill-file' must be called in this hook.
3698       (gnus-run-hooks 'gnus-apply-kill-hook)
3699       (if (and (zerop (buffer-size))
3700                (not no-display))
3701           (progn
3702             ;; This newsgroup is empty.
3703             (gnus-summary-catchup-and-exit nil t)
3704             (gnus-message 6 "No unread news")
3705             (when kill-buffer
3706               (gnus-kill-or-deaden-summary kill-buffer))
3707             ;; Return nil from this function.
3708             nil)
3709         ;; Hide conversation thread subtrees.  We cannot do this in
3710         ;; gnus-summary-prepare-hook since kill processing may not
3711         ;; work with hidden articles.
3712         (gnus-summary-maybe-hide-threads)
3713         (when kill-buffer
3714           (gnus-kill-or-deaden-summary kill-buffer))
3715         (gnus-summary-auto-select-subject)
3716         ;; Show first unread article if requested.
3717         (if (and (not no-article)
3718                  (not no-display)
3719                  gnus-newsgroup-unreads
3720                  gnus-auto-select-first)
3721             (progn
3722               (gnus-configure-windows 'summary)
3723               (let ((art (gnus-summary-article-number)))
3724                 (unless (and (not gnus-plugged)
3725                              (or (memq art gnus-newsgroup-undownloaded)
3726                                  (memq art gnus-newsgroup-downloadable)))
3727                   (gnus-summary-goto-article art))))
3728           ;; Don't select any articles.
3729           (gnus-summary-position-point)
3730           (gnus-configure-windows 'summary 'force)
3731           (gnus-set-mode-line 'summary))
3732         (when (and gnus-auto-center-group
3733                    (get-buffer-window gnus-group-buffer t))
3734           ;; Gotta use windows, because recenter does weird stuff if
3735           ;; the current buffer ain't the displayed window.
3736           (let ((owin (selected-window)))
3737             (select-window (get-buffer-window gnus-group-buffer t))
3738             (when (gnus-group-goto-group group)
3739               (recenter))
3740             (select-window owin)))
3741         ;; Mark this buffer as "prepared".
3742         (setq gnus-newsgroup-prepared t)
3743         (gnus-run-hooks 'gnus-summary-prepared-hook)
3744         (unless (gnus-ephemeral-group-p group)
3745           (gnus-group-update-group group))
3746         t)))))
3747
3748 (defun gnus-summary-auto-select-subject ()
3749   "Select the subject line on initial group entry."
3750   (goto-char (point-min))
3751   (cond
3752    ((eq gnus-auto-select-subject 'best)
3753     (gnus-summary-best-unread-subject))
3754    ((eq gnus-auto-select-subject 'unread)
3755     (gnus-summary-first-unread-subject))
3756    ((eq gnus-auto-select-subject 'unseen)
3757     (gnus-summary-first-unseen-subject))
3758    ((eq gnus-auto-select-subject 'unseen-or-unread)
3759     (gnus-summary-first-unseen-or-unread-subject))
3760    ((eq gnus-auto-select-subject 'first)
3761     ;; Do nothing.
3762     )
3763    ((functionp gnus-auto-select-subject)
3764     (funcall gnus-auto-select-subject))))
3765
3766 (defun gnus-summary-prepare ()
3767   "Generate the summary buffer."
3768   (interactive)
3769   (let ((buffer-read-only nil))
3770     (erase-buffer)
3771     (setq gnus-newsgroup-data nil
3772           gnus-newsgroup-data-reverse nil)
3773     (gnus-run-hooks 'gnus-summary-generate-hook)
3774     ;; Generate the buffer, either with threads or without.
3775     (when gnus-newsgroup-headers
3776       (gnus-summary-prepare-threads
3777        (if gnus-show-threads
3778            (gnus-sort-gathered-threads
3779             (funcall gnus-summary-thread-gathering-function
3780                      (gnus-sort-threads
3781                       (gnus-cut-threads (gnus-make-threads)))))
3782          ;; Unthreaded display.
3783          (gnus-sort-articles gnus-newsgroup-headers))))
3784     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3785     ;; Call hooks for modifying summary buffer.
3786     (goto-char (point-min))
3787     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3788
3789 (defsubst gnus-general-simplify-subject (subject)
3790   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3791   (setq subject
3792         (cond
3793          ;; Truncate the subject.
3794          (gnus-simplify-subject-functions
3795           (gnus-map-function gnus-simplify-subject-functions subject))
3796          ((numberp gnus-summary-gather-subject-limit)
3797           (setq subject (gnus-simplify-subject-re subject))
3798           (if (> (length subject) gnus-summary-gather-subject-limit)
3799               (substring subject 0 gnus-summary-gather-subject-limit)
3800             subject))
3801          ;; Fuzzily simplify it.
3802          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3803           (gnus-simplify-subject-fuzzy subject))
3804          ;; Just remove the leading "Re:".
3805          (t
3806           (gnus-simplify-subject-re subject))))
3807
3808   (if (and gnus-summary-gather-exclude-subject
3809            (string-match gnus-summary-gather-exclude-subject subject))
3810       nil                               ; This article shouldn't be gathered
3811     subject))
3812
3813 (defun gnus-summary-simplify-subject-query ()
3814   "Query where the respool algorithm would put this article."
3815   (interactive)
3816   (gnus-summary-select-article)
3817   (message "%s"
3818            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3819
3820 (defun gnus-gather-threads-by-subject (threads)
3821   "Gather threads by looking at Subject headers."
3822   (if (not gnus-summary-make-false-root)
3823       threads
3824     (let ((hashtb (gnus-make-hashtable 1024))
3825           (prev threads)
3826           (result threads)
3827           subject hthread whole-subject)
3828       (while threads
3829         (setq subject (gnus-general-simplify-subject
3830                        (setq whole-subject (mail-header-subject
3831                                             (caar threads)))))
3832         (when subject
3833           (if (setq hthread (gnus-gethash subject hashtb))
3834               (progn
3835                 ;; We enter a dummy root into the thread, if we
3836                 ;; haven't done that already.
3837                 (unless (stringp (caar hthread))
3838                   (setcar hthread (list whole-subject (car hthread))))
3839                 ;; We add this new gathered thread to this gathered
3840                 ;; thread.
3841                 (setcdr (car hthread)
3842                         (nconc (cdar hthread) (list (car threads))))
3843                 ;; Remove it from the list of threads.
3844                 (setcdr prev (cdr threads))
3845                 (setq threads prev))
3846             ;; Enter this thread into the hash table.
3847             (gnus-sethash subject
3848                           (if gnus-summary-make-false-root-always
3849                               (progn
3850                                 ;; If you want a dummy root above all
3851                                 ;; threads...
3852                                 (setcar threads (list whole-subject
3853                                                       (car threads)))
3854                                 threads)
3855                             threads)
3856                           hashtb)))
3857         (setq prev threads)
3858         (setq threads (cdr threads)))
3859       result)))
3860
3861 (defun gnus-gather-threads-by-references (threads)
3862   "Gather threads by looking at References headers."
3863   (let ((idhashtb (gnus-make-hashtable 1024))
3864         (thhashtb (gnus-make-hashtable 1024))
3865         (prev threads)
3866         (result threads)
3867         ids references id gthread gid entered ref)
3868     (while threads
3869       (when (setq references (mail-header-references (caar threads)))
3870         (setq id (mail-header-id (caar threads))
3871               ids (inline (gnus-split-references references))
3872               entered nil)
3873         (while (setq ref (pop ids))
3874           (setq ids (delete ref ids))
3875           (if (not (setq gid (gnus-gethash ref idhashtb)))
3876               (progn
3877                 (gnus-sethash ref id idhashtb)
3878                 (gnus-sethash id threads thhashtb))
3879             (setq gthread (gnus-gethash gid thhashtb))
3880             (unless entered
3881               ;; We enter a dummy root into the thread, if we
3882               ;; haven't done that already.
3883               (unless (stringp (caar gthread))
3884                 (setcar gthread (list (mail-header-subject (caar gthread))
3885                                       (car gthread))))
3886               ;; We add this new gathered thread to this gathered
3887               ;; thread.
3888               (setcdr (car gthread)
3889                       (nconc (cdar gthread) (list (car threads)))))
3890             ;; Add it into the thread hash table.
3891             (gnus-sethash id gthread thhashtb)
3892             (setq entered t)
3893             ;; Remove it from the list of threads.
3894             (setcdr prev (cdr threads))
3895             (setq threads prev))))
3896       (setq prev threads)
3897       (setq threads (cdr threads)))
3898     result))
3899
3900 (defun gnus-sort-gathered-threads (threads)
3901   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3902   (let ((result threads))
3903     (while threads
3904       (when (stringp (caar threads))
3905         (setcdr (car threads)
3906                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3907       (setq threads (cdr threads)))
3908     result))
3909
3910 (defun gnus-thread-loop-p (root thread)
3911   "Say whether ROOT is in THREAD."
3912   (let ((stack (list thread))
3913         (infloop 0)
3914         th)
3915     (while (setq thread (pop stack))
3916       (setq th (cdr thread))
3917       (while (and th
3918                   (not (eq (caar th) root)))
3919         (pop th))
3920       (if th
3921           ;; We have found a loop.
3922           (let (ref-dep)
3923             (setcdr thread (delq (car th) (cdr thread)))
3924             (if (boundp (setq ref-dep (intern "none"
3925                                               gnus-newsgroup-dependencies)))
3926                 (setcdr (symbol-value ref-dep)
3927                         (nconc (cdr (symbol-value ref-dep))
3928                                (list (car th))))
3929               (set ref-dep (list nil (car th))))
3930             (setq infloop 1
3931                   stack nil))
3932         ;; Push all the subthreads onto the stack.
3933         (push (cdr thread) stack)))
3934     infloop))
3935
3936 (defun gnus-make-threads ()
3937   "Go through the dependency hashtb and find the roots.  Return all threads."
3938   (let (threads)
3939     (while (catch 'infloop
3940              (mapatoms
3941               (lambda (refs)
3942                 ;; Deal with self-referencing References loops.
3943                 (when (and (car (symbol-value refs))
3944                            (not (zerop
3945                                  (apply
3946                                   '+
3947                                   (mapcar
3948                                    (lambda (thread)
3949                                      (gnus-thread-loop-p
3950                                       (car (symbol-value refs)) thread))
3951                                    (cdr (symbol-value refs)))))))
3952                   (setq threads nil)
3953                   (throw 'infloop t))
3954                 (unless (car (symbol-value refs))
3955                   ;; These threads do not refer back to any other articles,
3956                   ;; so they're roots.
3957                   (setq threads (append (cdr (symbol-value refs)) threads))))
3958               gnus-newsgroup-dependencies)))
3959     threads))
3960
3961 ;; Build the thread tree.
3962 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3963   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3964
3965 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3966 if it was already present.
3967
3968 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3969 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3970 Message-IDs will be renamed to a unique Message-ID before being
3971 entered.
3972
3973 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3974   (let* ((id (mail-header-id header))
3975          (id-dep (and id (intern id dependencies)))
3976          parent-id ref ref-dep ref-header replaced)
3977     ;; Enter this `header' in the `dependencies' table.
3978     (cond
3979      ((not id-dep)
3980       (setq header nil))
3981      ;; The first two cases do the normal part: enter a new `header'
3982      ;; in the `dependencies' table.
3983      ((not (boundp id-dep))
3984       (set id-dep (list header)))
3985      ((null (car (symbol-value id-dep)))
3986       (setcar (symbol-value id-dep) header))
3987
3988      ;; From here the `header' was already present in the
3989      ;; `dependencies' table.
3990      (force-new
3991       ;; Overrides an existing entry;
3992       ;; just set the header part of the entry.
3993       (setcar (symbol-value id-dep) header)
3994       (setq replaced t))
3995
3996      ;; Renames the existing `header' to a unique Message-ID.
3997      ((not gnus-summary-ignore-duplicates)
3998       ;; An article with this Message-ID has already been seen.
3999       ;; We rename the Message-ID.
4000       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4001            (list header))
4002       (mail-header-set-id header id))
4003
4004      ;; The last case ignores an existing entry, except it adds any
4005      ;; additional Xrefs (in case the two articles came from different
4006      ;; servers.
4007      ;; Also sets `header' to `nil' meaning that the `dependencies'
4008      ;; table was *not* modified.
4009      (t
4010       (mail-header-set-xref
4011        (car (symbol-value id-dep))
4012        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4013                    "")
4014                (or (mail-header-xref header) "")))
4015       (setq header nil)))
4016
4017     (when (and header (not replaced))
4018       ;; First check that we are not creating a References loop.
4019       (setq parent-id (gnus-parent-id (mail-header-references header)))
4020       (setq ref parent-id)
4021       (while (and ref
4022                   (setq ref-dep (intern-soft ref dependencies))
4023                   (boundp ref-dep)
4024                   (setq ref-header (car (symbol-value ref-dep))))
4025         (if (string= id ref)
4026             ;; Yuk!  This is a reference loop.  Make the article be a
4027             ;; root article.
4028             (progn
4029               (mail-header-set-references (car (symbol-value id-dep)) "none")
4030               (setq ref nil)
4031               (setq parent-id nil))
4032           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4033       (setq ref-dep (intern (or parent-id "none") dependencies))
4034       (if (boundp ref-dep)
4035           (setcdr (symbol-value ref-dep)
4036                   (nconc (cdr (symbol-value ref-dep))
4037                          (list (symbol-value id-dep))))
4038         (set ref-dep (list nil (symbol-value id-dep)))))
4039     header))
4040
4041 (defun gnus-extract-message-id-from-in-reply-to (string)
4042   (if (string-match "<[^>]+>" string)
4043       (substring string (match-beginning 0) (match-end 0))
4044     nil))
4045
4046 (defun gnus-build-sparse-threads ()
4047   (let ((headers gnus-newsgroup-headers)
4048         (mail-parse-charset gnus-newsgroup-charset)
4049         (gnus-summary-ignore-duplicates t)
4050         header references generation relations
4051         subject child end new-child date)
4052     ;; First we create an alist of generations/relations, where
4053     ;; generations is how much we trust the relation, and the relation
4054     ;; is parent/child.
4055     (gnus-message 7 "Making sparse threads...")
4056     (save-excursion
4057       (nnheader-set-temp-buffer " *gnus sparse threads*")
4058       (while (setq header (pop headers))
4059         (when (and (setq references (mail-header-references header))
4060                    (not (string= references "")))
4061           (insert references)
4062           (setq child (mail-header-id header)
4063                 subject (mail-header-subject header)
4064                 date (mail-header-date header)
4065                 generation 0)
4066           (while (search-backward ">" nil t)
4067             (setq end (1+ (point)))
4068             (when (search-backward "<" nil t)
4069               (setq new-child (buffer-substring (point) end))
4070               (push (list (incf generation)
4071                           child (setq child new-child)
4072                           subject date)
4073                     relations)))
4074           (when child
4075             (push (list (1+ generation) child nil subject) relations))
4076           (erase-buffer)))
4077       (kill-buffer (current-buffer)))
4078     ;; Sort over trustworthiness.
4079     (mapcar
4080      (lambda (relation)
4081        (when (gnus-dependencies-add-header
4082               (make-full-mail-header-from-decoded-header
4083                gnus-reffed-article-number
4084                (nth 3 relation) "" (or (nth 4 relation) "")
4085                (nth 1 relation)
4086                (or (nth 2 relation) "") 0 0 "")
4087               gnus-newsgroup-dependencies nil)
4088          (push gnus-reffed-article-number gnus-newsgroup-limit)
4089          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4090          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4091                gnus-newsgroup-reads)
4092          (decf gnus-reffed-article-number)))
4093      (sort relations 'car-less-than-car))
4094     (gnus-message 7 "Making sparse threads...done")))
4095
4096 (defun gnus-build-old-threads ()
4097   ;; Look at all the articles that refer back to old articles, and
4098   ;; fetch the headers for the articles that aren't there.  This will
4099   ;; build complete threads - if the roots haven't been expired by the
4100   ;; server, that is.
4101   (let ((mail-parse-charset gnus-newsgroup-charset)
4102         id heads)
4103     (mapatoms
4104      (lambda (refs)
4105        (when (not (car (symbol-value refs)))
4106          (setq heads (cdr (symbol-value refs)))
4107          (while heads
4108            (if (memq (mail-header-number (caar heads))
4109                      gnus-newsgroup-dormant)
4110                (setq heads (cdr heads))
4111              (setq id (symbol-name refs))
4112              (while (and (setq id (gnus-build-get-header id))
4113                          (not (car (gnus-id-to-thread id)))))
4114              (setq heads nil)))))
4115      gnus-newsgroup-dependencies)))
4116
4117 (defsubst gnus-remove-odd-characters (string)
4118   "Translate STRING into something that doesn't contain weird characters."
4119   (mm-subst-char-in-string
4120    ?\r ?\-
4121    (mm-subst-char-in-string ?\n ?\- string t) t))
4122
4123 ;; This function has to be called with point after the article number
4124 ;; on the beginning of the line.
4125 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4126   (let ((eol (point-at-eol))
4127         (buffer (current-buffer))
4128         header references in-reply-to)
4129
4130     ;; overview: [num subject from date id refs chars lines misc]
4131     (unwind-protect
4132         (progn
4133           (narrow-to-region (point) eol)
4134           (unless (eobp)
4135             (forward-char))
4136
4137           (setq header
4138                 (make-full-mail-header
4139                  number                         ; number
4140                  (nnheader-nov-field)           ; subject
4141                  (nnheader-nov-field)           ; from
4142                  (nnheader-nov-field)           ; date
4143                  (nnheader-nov-read-message-id number)  ; id
4144                  (setq references (nnheader-nov-field)) ; refs
4145                  (nnheader-nov-read-integer)    ; chars
4146                  (nnheader-nov-read-integer)    ; lines
4147                  (unless (eobp)
4148                    (if (looking-at "Xref: ")
4149                        (goto-char (match-end 0)))
4150                    (nnheader-nov-field))        ; Xref
4151                  (nnheader-nov-parse-extra))))  ; extra
4152
4153       (widen))
4154
4155     (when (and (string= references "")
4156                (setq in-reply-to (mail-header-extra header))
4157                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4158       (mail-header-set-references
4159        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4160
4161     (when gnus-alter-header-function
4162       (funcall gnus-alter-header-function header))
4163     (gnus-dependencies-add-header header dependencies force-new)))
4164
4165 (defun gnus-build-get-header (id)
4166   "Look through the buffer of NOV lines and find the header to ID.
4167 Enter this line into the dependencies hash table, and return
4168 the id of the parent article (if any)."
4169   (let ((deps gnus-newsgroup-dependencies)
4170         found header)
4171     (prog1
4172         (save-excursion
4173           (set-buffer nntp-server-buffer)
4174           (let ((case-fold-search nil))
4175             (goto-char (point-min))
4176             (while (and (not found)
4177                         (search-forward id nil t))
4178               (beginning-of-line)
4179               (setq found (looking-at
4180                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4181                                    (regexp-quote id))))
4182               (or found (beginning-of-line 2)))
4183             (when found
4184               (beginning-of-line)
4185               (and
4186                (setq header (gnus-nov-parse-line
4187                              (read (current-buffer)) deps))
4188                (gnus-parent-id (mail-header-references header))))))
4189       (when header
4190         (let ((number (mail-header-number header)))
4191           (push number gnus-newsgroup-limit)
4192           (push header gnus-newsgroup-headers)
4193           (if (memq number gnus-newsgroup-unselected)
4194               (progn
4195                 (setq gnus-newsgroup-unreads
4196                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4197                                                number))
4198                 (setq gnus-newsgroup-unselected
4199                       (delq number gnus-newsgroup-unselected)))
4200             (push number gnus-newsgroup-ancient)))))))
4201
4202 (defun gnus-build-all-threads ()
4203   "Read all the headers."
4204   (let ((gnus-summary-ignore-duplicates t)
4205         (mail-parse-charset gnus-newsgroup-charset)
4206         (dependencies gnus-newsgroup-dependencies)
4207         header article)
4208     (save-excursion
4209       (set-buffer nntp-server-buffer)
4210       (let ((case-fold-search nil))
4211         (goto-char (point-min))
4212         (while (not (eobp))
4213           (ignore-errors
4214             (setq article (read (current-buffer))
4215                   header (gnus-nov-parse-line article dependencies)))
4216           (when header
4217             (with-current-buffer gnus-summary-buffer
4218               (push header gnus-newsgroup-headers)
4219               (if (memq (setq article (mail-header-number header))
4220                         gnus-newsgroup-unselected)
4221                   (progn
4222                     (setq gnus-newsgroup-unreads
4223                           (gnus-add-to-sorted-list
4224                            gnus-newsgroup-unreads article))
4225                     (setq gnus-newsgroup-unselected
4226                           (delq article gnus-newsgroup-unselected)))
4227                 (push article gnus-newsgroup-ancient)))
4228             (forward-line 1)))))))
4229
4230 (defun gnus-summary-update-article-line (article header)
4231   "Update the line for ARTICLE using HEADER."
4232   (let* ((id (mail-header-id header))
4233          (thread (gnus-id-to-thread id)))
4234     (unless thread
4235       (error "Article in no thread"))
4236     ;; Update the thread.
4237     (setcar thread header)
4238     (gnus-summary-goto-subject article)
4239     (let* ((datal (gnus-data-find-list article))
4240            (data (car datal))
4241            (buffer-read-only nil)
4242            (level (gnus-summary-thread-level)))
4243       (gnus-delete-line)
4244       (let ((inserted (- (point)
4245                          (progn
4246                            (gnus-summary-insert-line
4247                             header level nil
4248                             (memq article gnus-newsgroup-undownloaded)
4249                             (gnus-article-mark article)
4250                             (memq article gnus-newsgroup-replied)
4251                             (memq article gnus-newsgroup-expirable)
4252                             ;; Only insert the Subject string when it's different
4253                             ;; from the previous Subject string.
4254                             (if (and
4255                                  gnus-show-threads
4256                                  (gnus-subject-equal
4257                                   (condition-case ()
4258                                       (mail-header-subject
4259                                        (gnus-data-header
4260                                         (cadr
4261                                          (gnus-data-find-list
4262                                           article
4263                                           (gnus-data-list t)))))
4264                                     ;; Error on the side of excessive subjects.
4265                                     (error ""))
4266                                   (mail-header-subject header)))
4267                                 ""
4268                               (mail-header-subject header))
4269                             nil (cdr (assq article gnus-newsgroup-scored))
4270                             (memq article gnus-newsgroup-processable))
4271                            (point)))))
4272         (when (cdr datal)
4273           (gnus-data-update-list
4274            (cdr datal)
4275            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4276
4277 (defun gnus-summary-update-article (article &optional iheader)
4278   "Update ARTICLE in the summary buffer."
4279   (set-buffer gnus-summary-buffer)
4280   (let* ((header (gnus-summary-article-header article))
4281          (id (mail-header-id header))
4282          (data (gnus-data-find article))
4283          (thread (gnus-id-to-thread id))
4284          (references (mail-header-references header))
4285          (parent
4286           (gnus-id-to-thread
4287            (or (gnus-parent-id
4288                 (when (and references
4289                            (not (equal "" references)))
4290                   references))
4291                "none")))
4292          (buffer-read-only nil)
4293          (old (car thread)))
4294     (when thread
4295       (unless iheader
4296         (setcar thread nil)
4297         (when parent
4298           (delq thread parent)))
4299       (if (gnus-summary-insert-subject id header)
4300           ;; Set the (possibly) new article number in the data structure.
4301           (gnus-data-set-number data (gnus-id-to-article id))
4302         (setcar thread old)
4303         nil))))
4304
4305 (defun gnus-rebuild-thread (id &optional line)
4306   "Rebuild the thread containing ID.
4307 If LINE, insert the rebuilt thread starting on line LINE."
4308   (let ((buffer-read-only nil)
4309         old-pos current thread data)
4310     (if (not gnus-show-threads)
4311         (setq thread (list (car (gnus-id-to-thread id))))
4312       ;; Get the thread this article is part of.
4313       (setq thread (gnus-remove-thread id)))
4314     (setq old-pos (point-at-bol))
4315     (setq current (save-excursion
4316                     (and (re-search-backward "[\r\n]" nil t)
4317                          (gnus-summary-article-number))))
4318     ;; If this is a gathered thread, we have to go some re-gathering.
4319     (when (stringp (car thread))
4320       (let ((subject (car thread))
4321             roots thr)
4322         (setq thread (cdr thread))
4323         (while thread
4324           (unless (memq (setq thr (gnus-id-to-thread
4325                                    (gnus-root-id
4326                                     (mail-header-id (caar thread)))))
4327                         roots)
4328             (push thr roots))
4329           (setq thread (cdr thread)))
4330         ;; We now have all (unique) roots.
4331         (if (= (length roots) 1)
4332             ;; All the loose roots are now one solid root.
4333             (setq thread (car roots))
4334           (setq thread (cons subject (gnus-sort-threads roots))))))
4335     (let (threads)
4336       ;; We then insert this thread into the summary buffer.
4337       (when line
4338         (goto-char (point-min))
4339         (forward-line (1- line)))
4340       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4341         (if gnus-show-threads
4342             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4343           (gnus-summary-prepare-unthreaded thread))
4344         (setq data (nreverse gnus-newsgroup-data))
4345         (setq threads gnus-newsgroup-threads))
4346       ;; We splice the new data into the data structure.
4347       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4348       ;;!!! then we want to insert at the beginning of the buffer.
4349       ;;!!! That happens to be true with Gnus now, but that may
4350       ;;!!! change in the future.  Perhaps.
4351       (gnus-data-enter-list
4352        (if line nil current) data (- (point) old-pos))
4353       (setq gnus-newsgroup-threads
4354             (nconc threads gnus-newsgroup-threads))
4355       (gnus-data-compute-positions))))
4356
4357 (defun gnus-number-to-header (number)
4358   "Return the header for article NUMBER."
4359   (let ((headers gnus-newsgroup-headers))
4360     (while (and headers
4361                 (not (= number (mail-header-number (car headers)))))
4362       (pop headers))
4363     (when headers
4364       (car headers))))
4365
4366 (defun gnus-parent-headers (in-headers &optional generation)
4367   "Return the headers of the GENERATIONeth parent of HEADERS."
4368   (unless generation
4369     (setq generation 1))
4370   (let ((parent t)
4371         (headers in-headers)
4372         references)
4373     (while (and parent
4374                 (not (zerop generation))
4375                 (setq references (mail-header-references headers)))
4376       (setq headers (if (and references
4377                              (setq parent (gnus-parent-id references)))
4378                         (car (gnus-id-to-thread parent))
4379                       nil))
4380       (decf generation))
4381     (and (not (eq headers in-headers))
4382          headers)))
4383
4384 (defun gnus-id-to-thread (id)
4385   "Return the (sub-)thread where ID appears."
4386   (gnus-gethash id gnus-newsgroup-dependencies))
4387
4388 (defun gnus-id-to-article (id)
4389   "Return the article number of ID."
4390   (let ((thread (gnus-id-to-thread id)))
4391     (when (and thread
4392                (car thread))
4393       (mail-header-number (car thread)))))
4394
4395 (defun gnus-id-to-header (id)
4396   "Return the article headers of ID."
4397   (car (gnus-id-to-thread id)))
4398
4399 (defun gnus-article-displayed-root-p (article)
4400   "Say whether ARTICLE is a root(ish) article."
4401   (let ((level (gnus-summary-thread-level article))
4402         (refs (mail-header-references  (gnus-summary-article-header article)))
4403         particle)
4404     (cond
4405      ((null level) nil)
4406      ((zerop level) t)
4407      ((null refs) t)
4408      ((null (gnus-parent-id refs)) t)
4409      ((and (= 1 level)
4410            (null (setq particle (gnus-id-to-article
4411                                  (gnus-parent-id refs))))
4412            (null (gnus-summary-thread-level particle)))))))
4413
4414 (defun gnus-root-id (id)
4415   "Return the id of the root of the thread where ID appears."
4416   (let (last-id prev)
4417     (while (and id (setq prev (car (gnus-id-to-thread id))))
4418       (setq last-id id
4419             id (gnus-parent-id (mail-header-references prev))))
4420     last-id))
4421
4422 (defun gnus-articles-in-thread (thread)
4423   "Return the list of articles in THREAD."
4424   (cons (mail-header-number (car thread))
4425         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4426
4427 (defun gnus-remove-thread (id &optional dont-remove)
4428   "Remove the thread that has ID in it."
4429   (let (headers thread last-id)
4430     ;; First go up in this thread until we find the root.
4431     (setq last-id (gnus-root-id id)
4432           headers (message-flatten-list (gnus-id-to-thread last-id)))
4433     ;; We have now found the real root of this thread.  It might have
4434     ;; been gathered into some loose thread, so we have to search
4435     ;; through the threads to find the thread we wanted.
4436     (let ((threads gnus-newsgroup-threads)
4437           sub)
4438       (while threads
4439         (setq sub (car threads))
4440         (if (stringp (car sub))
4441             ;; This is a gathered thread, so we look at the roots
4442             ;; below it to find whether this article is in this
4443             ;; gathered root.
4444             (progn
4445               (setq sub (cdr sub))
4446               (while sub
4447                 (when (member (caar sub) headers)
4448                   (setq thread (car threads)
4449                         threads nil
4450                         sub nil))
4451                 (setq sub (cdr sub))))
4452           ;; It's an ordinary thread, so we check it.
4453           (when (eq (car sub) (car headers))
4454             (setq thread sub
4455                   threads nil)))
4456         (setq threads (cdr threads)))
4457       ;; If this article is in no thread, then it's a root.
4458       (if thread
4459           (unless dont-remove
4460             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4461         (setq thread (gnus-id-to-thread last-id)))
4462       (when thread
4463         (prog1
4464             thread                      ; We return this thread.
4465           (unless dont-remove
4466             (if (stringp (car thread))
4467                 (progn
4468                   ;; If we use dummy roots, then we have to remove the
4469                   ;; dummy root as well.
4470                   (when (eq gnus-summary-make-false-root 'dummy)
4471                     ;; We go to the dummy root by going to
4472                     ;; the first sub-"thread", and then one line up.
4473                     (gnus-summary-goto-article
4474                      (mail-header-number (caadr thread)))
4475                     (forward-line -1)
4476                     (gnus-delete-line)
4477                     (gnus-data-compute-positions))
4478                   (setq thread (cdr thread))
4479                   (while thread
4480                     (gnus-remove-thread-1 (car thread))
4481                     (setq thread (cdr thread))))
4482               (gnus-remove-thread-1 thread))))))))
4483
4484 (defun gnus-remove-thread-1 (thread)
4485   "Remove the thread THREAD recursively."
4486   (let ((number (mail-header-number (pop thread)))
4487         d)
4488     (setq thread (reverse thread))
4489     (while thread
4490       (gnus-remove-thread-1 (pop thread)))
4491     (when (setq d (gnus-data-find number))
4492       (goto-char (gnus-data-pos d))
4493       (gnus-summary-show-thread)
4494       (gnus-data-remove
4495        number
4496        (- (point-at-bol)
4497           (prog1
4498               (1+ (point-at-eol))
4499             (gnus-delete-line)))))))
4500
4501 (defun gnus-sort-threads-1 (threads func)
4502   (sort (mapcar (lambda (thread)
4503                   (cons (car thread)
4504                         (and (cdr thread)
4505                              (gnus-sort-threads-1 (cdr thread) func))))
4506                 threads) func))
4507
4508 (defun gnus-sort-threads (threads)
4509   "Sort THREADS."
4510   (if (not gnus-thread-sort-functions)
4511       threads
4512     (gnus-message 8 "Sorting threads...")
4513     (let ((max-lisp-eval-depth 5000))
4514       (prog1 (gnus-sort-threads-1
4515          threads
4516          (gnus-make-sort-function gnus-thread-sort-functions))
4517         (gnus-message 8 "Sorting threads...done")))))
4518
4519 (defun gnus-sort-articles (articles)
4520   "Sort ARTICLES."
4521   (when gnus-article-sort-functions
4522     (gnus-message 7 "Sorting articles...")
4523     (prog1
4524         (setq gnus-newsgroup-headers
4525               (sort articles (gnus-make-sort-function
4526                               gnus-article-sort-functions)))
4527       (gnus-message 7 "Sorting articles...done"))))
4528
4529 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4530 (defmacro gnus-thread-header (thread)
4531   "Return header of first article in THREAD.
4532 Note that THREAD must never, ever be anything else than a variable -
4533 using some other form will lead to serious barfage."
4534   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4535   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4536   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4537         (vector thread) 2))
4538
4539 (defsubst gnus-article-sort-by-number (h1 h2)
4540   "Sort articles by article number."
4541   (< (mail-header-number h1)
4542      (mail-header-number h2)))
4543
4544 (defun gnus-thread-sort-by-number (h1 h2)
4545   "Sort threads by root article number."
4546   (gnus-article-sort-by-number
4547    (gnus-thread-header h1) (gnus-thread-header h2)))
4548
4549 (defsubst gnus-article-sort-by-random (h1 h2)
4550   "Sort articles by article number."
4551   (zerop (random 2)))
4552
4553 (defun gnus-thread-sort-by-random (h1 h2)
4554   "Sort threads by root article number."
4555   (gnus-article-sort-by-random
4556    (gnus-thread-header h1) (gnus-thread-header h2)))
4557
4558 (defsubst gnus-article-sort-by-lines (h1 h2)
4559   "Sort articles by article Lines header."
4560   (< (mail-header-lines h1)
4561      (mail-header-lines h2)))
4562
4563 (defun gnus-thread-sort-by-lines (h1 h2)
4564   "Sort threads by root article Lines header."
4565   (gnus-article-sort-by-lines
4566    (gnus-thread-header h1) (gnus-thread-header h2)))
4567
4568 (defsubst gnus-article-sort-by-chars (h1 h2)
4569   "Sort articles by octet length."
4570   (< (mail-header-chars h1)
4571      (mail-header-chars h2)))
4572
4573 (defun gnus-thread-sort-by-chars (h1 h2)
4574   "Sort threads by root article octet length."
4575   (gnus-article-sort-by-chars
4576    (gnus-thread-header h1) (gnus-thread-header h2)))
4577
4578 (defsubst gnus-article-sort-by-author (h1 h2)
4579   "Sort articles by root author."
4580   (string-lessp
4581    (let ((addr (car (mime-entity-read-field h1 'From))))
4582      (or (std11-full-name-string addr)
4583          (std11-address-string addr)
4584          ""))
4585    (let ((addr (car (mime-entity-read-field h2 'From))))
4586      (or (std11-full-name-string addr)
4587          (std11-address-string addr)
4588          ""))
4589    ))
4590
4591 (defun gnus-thread-sort-by-author (h1 h2)
4592   "Sort threads by root author."
4593   (gnus-article-sort-by-author
4594    (gnus-thread-header h1)  (gnus-thread-header h2)))
4595
4596 (defsubst gnus-article-sort-by-recipient (h1 h2)
4597   "Sort articles by recipient."
4598   (string-lessp
4599    (let ((extract (funcall
4600                    gnus-extract-address-components
4601                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4602      (or (car extract) (cadr extract)))
4603    (let ((extract (funcall
4604                    gnus-extract-address-components
4605                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4606      (or (car extract) (cadr extract)))))
4607
4608 (defun gnus-thread-sort-by-recipient (h1 h2)
4609   "Sort threads by root recipient."
4610   (gnus-article-sort-by-recipient
4611    (gnus-thread-header h1) (gnus-thread-header h2)))
4612
4613 (defsubst gnus-article-sort-by-subject (h1 h2)
4614   "Sort articles by root subject."
4615   (string-lessp
4616    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4617    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4618
4619 (defun gnus-thread-sort-by-subject (h1 h2)
4620   "Sort threads by root subject."
4621   (gnus-article-sort-by-subject
4622    (gnus-thread-header h1) (gnus-thread-header h2)))
4623
4624 (defsubst gnus-article-sort-by-date (h1 h2)
4625   "Sort articles by root article date."
4626   (time-less-p
4627    (gnus-date-get-time (mail-header-date h1))
4628    (gnus-date-get-time (mail-header-date h2))))
4629
4630 (defsubst gnus-article-sort-by-date-reverse (h1 h2)
4631   "Sort articles in reverse order by root article date."
4632   (gnus-article-sort-by-date h2 h1))
4633
4634 (defun gnus-thread-sort-by-date (h1 h2)
4635   "Sort threads by root article date."
4636   (gnus-article-sort-by-date
4637    (gnus-thread-header h1) (gnus-thread-header h2)))
4638
4639 (defsubst gnus-article-sort-by-score (h1 h2)
4640   "Sort articles by root article score.
4641 Unscored articles will be counted as having a score of zero."
4642   (> (or (cdr (assq (mail-header-number h1)
4643                     gnus-newsgroup-scored))
4644          gnus-summary-default-score 0)
4645      (or (cdr (assq (mail-header-number h2)
4646                     gnus-newsgroup-scored))
4647          gnus-summary-default-score 0)))
4648
4649 (defun gnus-thread-sort-by-score (h1 h2)
4650   "Sort threads by root article score."
4651   (gnus-article-sort-by-score
4652    (gnus-thread-header h1) (gnus-thread-header h2)))
4653
4654 (defun gnus-thread-sort-by-total-score (h1 h2)
4655   "Sort threads by the sum of all scores in the thread.
4656 Unscored articles will be counted as having a score of zero."
4657   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4658
4659 (defun gnus-thread-total-score (thread)
4660   ;; This function find the total score of THREAD.
4661   (cond
4662    ((null thread)
4663     0)
4664    ((consp thread)
4665     (if (stringp (car thread))
4666         (apply gnus-thread-score-function 0
4667                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4668       (gnus-thread-total-score-1 thread)))
4669    (t
4670     (gnus-thread-total-score-1 (list thread)))))
4671
4672 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4673   "Sort threads such that the thread with the most recently arrived article comes first."
4674   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4675
4676 (defun gnus-thread-highest-number (thread)
4677   "Return the highest article number in THREAD."
4678   (apply 'max (mapcar (lambda (header)
4679                         (mail-header-number header))
4680                       (message-flatten-list thread))))
4681
4682 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4683   "Sort threads such that the thread with the most recently dated article comes first."
4684   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4685
4686 (defun gnus-thread-latest-date (thread)
4687   "Return the highest article date in THREAD."
4688   (let ((previous-time 0))
4689     (apply 'max
4690            (mapcar
4691             (lambda (header)
4692               (setq previous-time
4693                     (condition-case ()
4694                         (time-to-seconds (mail-header-parse-date
4695                                           (mail-header-date header)))
4696                       (error previous-time))))
4697             (sort
4698              (message-flatten-list thread)
4699              (lambda (h1 h2)
4700                (< (mail-header-number h1)
4701                   (mail-header-number h2))))))))
4702
4703 (defun gnus-thread-total-score-1 (root)
4704   ;; This function find the total score of the thread below ROOT.
4705   (setq root (car root))
4706   (apply gnus-thread-score-function
4707          (or (append
4708               (mapcar 'gnus-thread-total-score
4709                       (cdr (gnus-id-to-thread (mail-header-id root))))
4710               (when (> (mail-header-number root) 0)
4711                 (list (or (cdr (assq (mail-header-number root)
4712                                      gnus-newsgroup-scored))
4713                           gnus-summary-default-score 0))))
4714              (list gnus-summary-default-score)
4715              '(0))))
4716
4717 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4718 (defvar gnus-tmp-prev-subject nil)
4719 (defvar gnus-tmp-false-parent nil)
4720 (defvar gnus-tmp-root-expunged nil)
4721 (defvar gnus-tmp-dummy-line nil)
4722
4723 (eval-when-compile (defvar gnus-tmp-header))
4724 (defun gnus-extra-header (type &optional header)
4725   "Return the extra header of TYPE."
4726   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4727       ""))
4728
4729 (defvar gnus-tmp-thread-tree-header-string "")
4730
4731 (defcustom gnus-sum-thread-tree-root "> "
4732   "With %B spec, used for the root of a thread.
4733 If nil, use subject instead."
4734   :version "22.1"
4735   :type '(radio (const :format "%v  " nil) string)
4736   :group 'gnus-thread)
4737
4738 (defcustom gnus-sum-thread-tree-false-root "> "
4739   "With %B spec, used for a false root of a thread.
4740 If nil, use subject instead."
4741   :version "22.1"
4742   :type '(radio (const :format "%v  " nil) string)
4743   :group 'gnus-thread)
4744
4745 (defcustom gnus-sum-thread-tree-single-indent ""
4746   "With %B spec, used for a thread with just one message.
4747 If nil, use subject instead."
4748   :version "22.1"
4749   :type '(radio (const :format "%v  " nil) string)
4750   :group 'gnus-thread)
4751
4752 (defcustom gnus-sum-thread-tree-vertical "| "
4753   "With %B spec, used for drawing a vertical line."
4754   :version "22.1"
4755   :type 'string
4756   :group 'gnus-thread)
4757
4758 (defcustom gnus-sum-thread-tree-indent "  "
4759   "With %B spec, used for indenting."
4760   :version "22.1"
4761   :type 'string
4762   :group 'gnus-thread)
4763
4764 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4765   "With %B spec, used for a leaf with brothers."
4766   :version "22.1"
4767   :type 'string
4768   :group 'gnus-thread)
4769
4770 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4771   "With %B spec, used for a leaf without brothers."
4772   :version "22.1"
4773   :type 'string
4774   :group 'gnus-thread)
4775
4776 (defun gnus-summary-prepare-threads (threads)
4777   "Prepare summary buffer from THREADS and indentation LEVEL.
4778 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4779 or a straight list of headers."
4780   (gnus-message 7 "Generating summary...")
4781
4782   (setq gnus-newsgroup-threads threads)
4783   (beginning-of-line)
4784
4785   (let ((gnus-tmp-level 0)
4786         (default-score (or gnus-summary-default-score 0))
4787         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4788         (building-line-count gnus-summary-display-while-building)
4789         (building-count (integerp gnus-summary-display-while-building))
4790         thread number subject stack state gnus-tmp-gathered beg-match
4791         new-roots gnus-tmp-new-adopts thread-end simp-subject
4792         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4793         gnus-tmp-replied gnus-tmp-subject-or-nil
4794         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4795         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4796         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4797         tree-stack)
4798
4799     (setq gnus-tmp-prev-subject nil
4800           gnus-tmp-thread-tree-header-string "")
4801
4802     (if (vectorp (car threads))
4803         ;; If this is a straight (sic) list of headers, then a
4804         ;; threaded summary display isn't required, so we just create
4805         ;; an unthreaded one.
4806         (gnus-summary-prepare-unthreaded threads)
4807
4808       ;; Do the threaded display.
4809
4810       (if gnus-summary-display-while-building
4811           (switch-to-buffer (buffer-name)))
4812       (while (or threads stack gnus-tmp-new-adopts new-roots)
4813
4814         (if (and (= gnus-tmp-level 0)
4815                  (or (not stack)
4816                      (= (caar stack) 0))
4817                  (not gnus-tmp-false-parent)
4818                  (or gnus-tmp-new-adopts new-roots))
4819             (if gnus-tmp-new-adopts
4820                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4821                       thread (list (car gnus-tmp-new-adopts))
4822                       gnus-tmp-header (caar thread)
4823                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4824               (when new-roots
4825                 (setq thread (list (car new-roots))
4826                       gnus-tmp-header (caar thread)
4827                       new-roots (cdr new-roots))))
4828
4829           (if threads
4830               ;; If there are some threads, we do them before the
4831               ;; threads on the stack.
4832               (setq thread threads
4833                     gnus-tmp-header (caar thread))
4834             ;; There were no current threads, so we pop something off
4835             ;; the stack.
4836             (setq state (car stack)
4837                   gnus-tmp-level (car state)
4838                   tree-stack (cadr state)
4839                   thread (caddr state)
4840                   stack (cdr stack)
4841                   gnus-tmp-header (caar thread))))
4842
4843         (setq gnus-tmp-false-parent nil)
4844         (setq gnus-tmp-root-expunged nil)
4845         (setq thread-end nil)
4846
4847         (if (stringp gnus-tmp-header)
4848             ;; The header is a dummy root.
4849             (cond
4850              ((eq gnus-summary-make-false-root 'adopt)
4851               ;; We let the first article adopt the rest.
4852               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4853                                                (cddar thread)))
4854               (setq gnus-tmp-gathered
4855                     (nconc (mapcar
4856                             (lambda (h) (mail-header-number (car h)))
4857                             (cddar thread))
4858                            gnus-tmp-gathered))
4859               (setq thread (cons (list (caar thread)
4860                                        (cadar thread))
4861                                  (cdr thread)))
4862               (setq gnus-tmp-level -1
4863                     gnus-tmp-false-parent t))
4864              ((eq gnus-summary-make-false-root 'empty)
4865               ;; We print adopted articles with empty subject fields.
4866               (setq gnus-tmp-gathered
4867                     (nconc (mapcar
4868                             (lambda (h) (mail-header-number (car h)))
4869                             (cddar thread))
4870                            gnus-tmp-gathered))
4871               (setq gnus-tmp-level -1))
4872              ((eq gnus-summary-make-false-root 'dummy)
4873               ;; We remember that we probably want to output a dummy
4874               ;; root.
4875               (setq gnus-tmp-dummy-line gnus-tmp-header)
4876               (setq gnus-tmp-prev-subject gnus-tmp-header))
4877              (t
4878               ;; We do not make a root for the gathered
4879               ;; sub-threads at all.
4880               (setq gnus-tmp-level -1)))
4881
4882           (setq number (mail-header-number gnus-tmp-header)
4883                 subject (mail-header-subject gnus-tmp-header)
4884                 simp-subject (gnus-simplify-subject-fully subject))
4885
4886           (cond
4887            ;; If the thread has changed subject, we might want to make
4888            ;; this subthread into a root.
4889            ((and (null gnus-thread-ignore-subject)
4890                  (not (zerop gnus-tmp-level))
4891                  gnus-tmp-prev-subject
4892                  (not (string= gnus-tmp-prev-subject simp-subject)))
4893             (setq new-roots (nconc new-roots (list (car thread)))
4894                   thread-end t
4895                   gnus-tmp-header nil))
4896            ;; If the article lies outside the current limit,
4897            ;; then we do not display it.
4898            ((not (memq number gnus-newsgroup-limit))
4899             (setq gnus-tmp-gathered
4900                   (nconc (mapcar
4901                           (lambda (h) (mail-header-number (car h)))
4902                           (cdar thread))
4903                          gnus-tmp-gathered))
4904             (setq gnus-tmp-new-adopts (if (cdar thread)
4905                                           (append gnus-tmp-new-adopts
4906                                                   (cdar thread))
4907                                         gnus-tmp-new-adopts)
4908                   thread-end t
4909                   gnus-tmp-header nil)
4910             (when (zerop gnus-tmp-level)
4911               (setq gnus-tmp-root-expunged t)))
4912            ;; Perhaps this article is to be marked as read?
4913            ((and gnus-summary-mark-below
4914                  (< (or (cdr (assq number gnus-newsgroup-scored))
4915                         default-score)
4916                     gnus-summary-mark-below)
4917                  ;; Don't touch sparse articles.
4918                  (not (gnus-summary-article-sparse-p number))
4919                  (not (gnus-summary-article-ancient-p number)))
4920             (setq gnus-newsgroup-unreads
4921                   (delq number gnus-newsgroup-unreads))
4922             (if gnus-newsgroup-auto-expire
4923                 (setq gnus-newsgroup-expirable
4924                       (gnus-add-to-sorted-list
4925                        gnus-newsgroup-expirable number))
4926               (push (cons number gnus-low-score-mark)
4927                     gnus-newsgroup-reads))))
4928
4929           (when gnus-tmp-header
4930             ;; We may have an old dummy line to output before this
4931             ;; article.
4932             (when (and gnus-tmp-dummy-line
4933                        (gnus-subject-equal
4934                         gnus-tmp-dummy-line
4935                         (mail-header-subject gnus-tmp-header)))
4936               (gnus-summary-insert-dummy-line
4937                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4938               (setq gnus-tmp-dummy-line nil))
4939
4940             ;; Compute the mark.
4941             (setq gnus-tmp-unread (gnus-article-mark number))
4942
4943             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4944                                   gnus-tmp-header gnus-tmp-level)
4945                   gnus-newsgroup-data)
4946
4947             ;; Actually insert the line.
4948             (setq
4949              gnus-tmp-subject-or-nil
4950              (cond
4951               ((and gnus-thread-ignore-subject
4952                     gnus-tmp-prev-subject
4953                     (not (string= gnus-tmp-prev-subject simp-subject)))
4954                subject)
4955               ((zerop gnus-tmp-level)
4956                (if (and (eq gnus-summary-make-false-root 'empty)
4957                         (memq number gnus-tmp-gathered)
4958                         gnus-tmp-prev-subject
4959                         (string= gnus-tmp-prev-subject simp-subject))
4960                    gnus-summary-same-subject
4961                  subject))
4962               (t gnus-summary-same-subject)))
4963             (if (and (eq gnus-summary-make-false-root 'adopt)
4964                      (= gnus-tmp-level 1)
4965                      (memq number gnus-tmp-gathered))
4966                 (setq gnus-tmp-opening-bracket ?\<
4967                       gnus-tmp-closing-bracket ?\>)
4968               (setq gnus-tmp-opening-bracket ?\[
4969                     gnus-tmp-closing-bracket ?\]))
4970             (setq
4971              gnus-tmp-indentation
4972              (aref gnus-thread-indent-array gnus-tmp-level)
4973              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4974              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4975                                 gnus-summary-default-score 0)
4976              gnus-tmp-score-char
4977              (if (or (null gnus-summary-default-score)
4978                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4979                          gnus-summary-zcore-fuzz))
4980                  ?\ ;;;Whitespace
4981                (if (< gnus-tmp-score gnus-summary-default-score)
4982                    gnus-score-below-mark gnus-score-over-mark))
4983              gnus-tmp-replied
4984              (cond ((memq number gnus-newsgroup-processable)
4985                     gnus-process-mark)
4986                    ((memq number gnus-newsgroup-cached)
4987                     gnus-cached-mark)
4988                    ((memq number gnus-newsgroup-replied)
4989                     gnus-replied-mark)
4990                    ((memq number gnus-newsgroup-forwarded)
4991                     gnus-forwarded-mark)
4992                    ((memq number gnus-newsgroup-saved)
4993                     gnus-saved-mark)
4994                    ((memq number gnus-newsgroup-recent)
4995                     gnus-recent-mark)
4996                    ((memq number gnus-newsgroup-unseen)
4997                     gnus-unseen-mark)
4998                    (t gnus-no-mark))
4999              gnus-tmp-downloaded
5000              (cond ((memq number gnus-newsgroup-undownloaded)
5001                     gnus-undownloaded-mark)
5002                    (gnus-newsgroup-agentized
5003                     gnus-downloaded-mark)
5004                    (t
5005                     gnus-no-mark))
5006              gnus-tmp-from (mail-header-from gnus-tmp-header)
5007              gnus-tmp-name
5008              (cond
5009               ((string-match "<[^>]+> *$" gnus-tmp-from)
5010                (setq beg-match (match-beginning 0))
5011                (or (and (string-match "^\".+\"" gnus-tmp-from)
5012                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5013                    (substring gnus-tmp-from 0 beg-match)))
5014               ((string-match "(.+)" gnus-tmp-from)
5015                (substring gnus-tmp-from
5016                           (1+ (match-beginning 0)) (1- (match-end 0))))
5017               (t gnus-tmp-from))
5018
5019              ;; Do the %B string
5020              gnus-tmp-thread-tree-header-string
5021              (cond
5022               ((not gnus-show-threads) "")
5023               ((zerop gnus-tmp-level)
5024                (cond ((cdar thread)
5025                       (or gnus-sum-thread-tree-root subject))
5026                      (gnus-tmp-new-adopts
5027                       (or gnus-sum-thread-tree-false-root subject))
5028                      (t
5029                       (or gnus-sum-thread-tree-single-indent subject))))
5030               (t
5031                (concat (apply 'concat
5032                               (mapcar (lambda (item)
5033                                         (if (= item 1)
5034                                             gnus-sum-thread-tree-vertical
5035                                           gnus-sum-thread-tree-indent))
5036                                       (cdr (reverse tree-stack))))
5037                        (if (nth 1 thread)
5038                            gnus-sum-thread-tree-leaf-with-other
5039                          gnus-sum-thread-tree-single-leaf)))))
5040             (when (string= gnus-tmp-name "")
5041               (setq gnus-tmp-name gnus-tmp-from))
5042             (unless (numberp gnus-tmp-lines)
5043               (setq gnus-tmp-lines -1))
5044             (if (= gnus-tmp-lines -1)
5045                 (setq gnus-tmp-lines "?")
5046               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5047               (gnus-put-text-property
5048              (point)
5049              (progn (eval gnus-summary-line-format-spec) (point))
5050                'gnus-number number)
5051             (when gnus-visual-p
5052               (forward-line -1)
5053               (gnus-run-hooks 'gnus-summary-update-hook)
5054               (forward-line 1))
5055
5056             (setq gnus-tmp-prev-subject simp-subject)))
5057
5058         (when (nth 1 thread)
5059           (push (list (max 0 gnus-tmp-level)
5060                       (copy-sequence tree-stack)
5061                       (nthcdr 1 thread))
5062                 stack))
5063         (push (if (nth 1 thread) 1 0) tree-stack)
5064         (incf gnus-tmp-level)
5065         (setq threads (if thread-end nil (cdar thread)))
5066         (if gnus-summary-display-while-building
5067             (if building-count
5068                 (progn
5069                   ;; use a set frequency
5070                   (setq building-line-count (1- building-line-count))
5071                   (when (= building-line-count 0)
5072                     (sit-for 0)
5073                     (setq building-line-count
5074                           gnus-summary-display-while-building)))
5075               ;; always
5076               (sit-for 0)))
5077         (unless threads
5078           (setq gnus-tmp-level 0)))))
5079   (gnus-message 7 "Generating summary...done"))
5080
5081 (defun gnus-summary-prepare-unthreaded (headers)
5082   "Generate an unthreaded summary buffer based on HEADERS."
5083   (let (header number mark)
5084
5085     (beginning-of-line)
5086
5087     (while headers
5088       ;; We may have to root out some bad articles...
5089       (when (memq (setq number (mail-header-number
5090                                 (setq header (pop headers))))
5091                   gnus-newsgroup-limit)
5092         ;; Mark article as read when it has a low score.
5093         (when (and gnus-summary-mark-below
5094                    (< (or (cdr (assq number gnus-newsgroup-scored))
5095                           gnus-summary-default-score 0)
5096                       gnus-summary-mark-below)
5097                    (not (gnus-summary-article-ancient-p number)))
5098           (setq gnus-newsgroup-unreads
5099                 (delq number gnus-newsgroup-unreads))
5100           (if gnus-newsgroup-auto-expire
5101               (push number gnus-newsgroup-expirable)
5102             (push (cons number gnus-low-score-mark)
5103                   gnus-newsgroup-reads)))
5104
5105         (setq mark (gnus-article-mark number))
5106         (push (gnus-data-make number mark (1+ (point)) header 0)
5107               gnus-newsgroup-data)
5108         (gnus-summary-insert-line
5109          header 0 number
5110          (memq number gnus-newsgroup-undownloaded)
5111          mark (memq number gnus-newsgroup-replied)
5112          (memq number gnus-newsgroup-expirable)
5113          (mail-header-subject header) nil
5114          (cdr (assq number gnus-newsgroup-scored))
5115          (memq number gnus-newsgroup-processable))))))
5116
5117 (defun gnus-summary-remove-list-identifiers ()
5118   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5119   (let ((regexp (if (consp gnus-list-identifiers)
5120                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5121                   gnus-list-identifiers))
5122         changed subject)
5123     (when regexp
5124       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5125       (dolist (header gnus-newsgroup-headers)
5126         (setq subject (mail-header-subject header)
5127               changed nil)
5128         (while (string-match regexp subject)
5129           (setq subject
5130                 (concat (substring subject 0 (match-beginning 1))
5131                         (substring subject (match-end 0)))
5132                 changed t))
5133         (when changed
5134           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5135             (setq subject
5136                   (concat (substring subject 0 (match-beginning 1))
5137                           (substring subject (match-end 1)))))
5138           (mail-header-set-subject header subject))))))
5139
5140 (defun gnus-fetch-headers (articles)
5141   "Fetch headers of ARTICLES."
5142   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5143     (gnus-message 5 "Fetching headers for %s..." name)
5144     (prog1
5145         (if (eq 'nov
5146                 (setq gnus-headers-retrieved-by
5147                       (gnus-retrieve-headers
5148                        articles gnus-newsgroup-name
5149                        ;; We might want to fetch old headers, but
5150                        ;; not if there is only 1 article.
5151                        (and (or (and
5152                                  (not (eq gnus-fetch-old-headers 'some))
5153                                  (not (numberp gnus-fetch-old-headers)))
5154                                 (> (length articles) 1))
5155                             gnus-fetch-old-headers))))
5156             (gnus-get-newsgroup-headers-xover
5157              articles nil nil gnus-newsgroup-name t)
5158           (gnus-get-newsgroup-headers))
5159       (gnus-message 5 "Fetching headers for %s...done" name))))
5160
5161 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5162   "Select newsgroup GROUP.
5163 If READ-ALL is non-nil, all articles in the group are selected.
5164 If SELECT-ARTICLES, only select those articles from GROUP."
5165   (let* ((entry (gnus-group-entry group))
5166          ;;!!! Dirty hack; should be removed.
5167          (gnus-summary-ignore-duplicates
5168           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5169               t
5170             gnus-summary-ignore-duplicates))
5171          (info (nth 2 entry))
5172          articles fetched-articles cached)
5173
5174     (unless (gnus-check-server
5175              (set (make-local-variable 'gnus-current-select-method)
5176                   (gnus-find-method-for-group group)))
5177       (error "Couldn't open server"))
5178
5179     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5180         (gnus-activate-group group)     ; Or we can activate it...
5181         (progn                          ; Or we bug out.
5182           (when (equal major-mode 'gnus-summary-mode)
5183             (gnus-kill-buffer (current-buffer)))
5184           (error "Couldn't activate group %s: %s"
5185                  group (gnus-status-message group))))
5186
5187     (unless (gnus-request-group group t)
5188       (when (equal major-mode 'gnus-summary-mode)
5189         (gnus-kill-buffer (current-buffer)))
5190       (error "Couldn't request group %s: %s"
5191              group (gnus-status-message group)))
5192
5193     (when gnus-agent
5194       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5195
5196       (setq gnus-summary-use-undownloaded-faces
5197             (gnus-agent-find-parameter
5198              group
5199              'agent-enable-undownloaded-faces)))
5200
5201     (setq gnus-newsgroup-name group
5202           gnus-newsgroup-unselected nil
5203           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5204
5205     (let ((display (gnus-group-find-parameter group 'display)))
5206       (setq gnus-newsgroup-display
5207             (cond
5208              ((not (zerop (or (car-safe read-all) 0)))
5209               ;; The user entered the group with C-u SPC/RET, let's show
5210               ;; all articles.
5211               'gnus-not-ignore)
5212              ((eq display 'all)
5213               'gnus-not-ignore)
5214              ((arrayp display)
5215               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5216              ((numberp display)
5217               ;; The following is probably the "correct" solution, but
5218               ;; it makes Gnus fetch all headers and then limit the
5219               ;; articles (which is slow), so instead we hack the
5220               ;; select-articles parameter instead. -- Simon Josefsson
5221               ;; <jas@kth.se>
5222               ;;
5223               ;; (gnus-byte-compile
5224               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5225               ;;                         display)))))
5226               (setq select-articles
5227                     (gnus-uncompress-range
5228                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5229                              (if (> tmp 0)
5230                                  tmp
5231                                1))
5232                            (cdr (gnus-active group)))))
5233               nil)
5234              (t
5235               nil))))
5236
5237     (gnus-summary-setup-default-charset)
5238
5239     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5240     (when (gnus-virtual-group-p group)
5241       (setq cached gnus-newsgroup-cached))
5242
5243     (setq gnus-newsgroup-unreads
5244           (gnus-sorted-ndifference
5245            (gnus-sorted-ndifference gnus-newsgroup-unreads
5246                                     gnus-newsgroup-marked)
5247            gnus-newsgroup-dormant))
5248
5249     (setq gnus-newsgroup-processable nil)
5250
5251     (gnus-update-read-articles group gnus-newsgroup-unreads)
5252
5253     ;; Adjust and set lists of article marks.
5254     (when info
5255       (gnus-adjust-marked-articles info))
5256     (if (setq articles select-articles)
5257         (setq gnus-newsgroup-unselected
5258               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5259       (setq articles (gnus-articles-to-read group read-all)))
5260
5261     (cond
5262      ((null articles)
5263       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5264       'quit)
5265      ((eq articles 0) nil)
5266      (t
5267       ;; Init the dependencies hash table.
5268       (setq gnus-newsgroup-dependencies
5269             (gnus-make-hashtable (length articles)))
5270       (gnus-set-global-variables)
5271       ;; Retrieve the headers and read them in.
5272
5273       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5274
5275       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5276       (when cached
5277         (setq gnus-newsgroup-cached cached))
5278
5279       ;; Suppress duplicates?
5280       (when gnus-suppress-duplicates
5281         (gnus-dup-suppress-articles))
5282
5283       ;; Set the initial limit.
5284       (setq gnus-newsgroup-limit (copy-sequence articles))
5285       ;; Remove canceled articles from the list of unread articles.
5286       (setq fetched-articles
5287             (mapcar (lambda (headers) (mail-header-number headers))
5288                     gnus-newsgroup-headers))
5289       (setq gnus-newsgroup-articles fetched-articles)
5290       (setq gnus-newsgroup-unreads
5291             (gnus-sorted-nintersection
5292              gnus-newsgroup-unreads fetched-articles))
5293       (gnus-compute-unseen-list)
5294
5295       ;; Removed marked articles that do not exist.
5296       (gnus-update-missing-marks
5297        (gnus-sorted-difference articles fetched-articles))
5298       ;; We might want to build some more threads first.
5299       (when (and gnus-fetch-old-headers
5300                  (eq gnus-headers-retrieved-by 'nov))
5301         (if (eq gnus-fetch-old-headers 'invisible)
5302             (gnus-build-all-threads)
5303           (gnus-build-old-threads)))
5304       ;; Let the Gnus agent mark articles as read.
5305       (when gnus-agent
5306         (gnus-agent-get-undownloaded-list))
5307       ;; Remove list identifiers from subject
5308       (when gnus-list-identifiers
5309         (gnus-summary-remove-list-identifiers))
5310       ;; Check whether auto-expire is to be done in this group.
5311       (setq gnus-newsgroup-auto-expire
5312             (gnus-group-auto-expirable-p group))
5313       ;; Set up the article buffer now, if necessary.
5314       (unless gnus-single-article-buffer
5315         (gnus-article-setup-buffer))
5316       ;; First and last article in this newsgroup.
5317       (when gnus-newsgroup-headers
5318         (setq gnus-newsgroup-begin
5319               (mail-header-number (car gnus-newsgroup-headers))
5320               gnus-newsgroup-end
5321               (mail-header-number
5322                (gnus-last-element gnus-newsgroup-headers))))
5323       ;; GROUP is successfully selected.
5324       (or gnus-newsgroup-headers t)))))
5325
5326 (defun gnus-compute-unseen-list ()
5327   ;; The `seen' marks are treated specially.
5328   (if (not gnus-newsgroup-seen)
5329       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5330     (setq gnus-newsgroup-unseen
5331           (gnus-inverse-list-range-intersection
5332            gnus-newsgroup-articles gnus-newsgroup-seen))))
5333
5334 (defun gnus-summary-display-make-predicate (display)
5335   (require 'gnus-agent)
5336   (when (= (length display) 1)
5337     (setq display (car display)))
5338   (unless gnus-summary-display-cache
5339     (dolist (elem (append '((unread . unread)
5340                             (read . read)
5341                             (unseen . unseen))
5342                           gnus-article-mark-lists))
5343       (push (cons (cdr elem)
5344                   (gnus-byte-compile
5345                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5346             gnus-summary-display-cache)))
5347   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5348         (gnus-category-predicate-cache gnus-summary-display-cache))
5349     (gnus-get-predicate display)))
5350
5351 ;; Uses the dynamically bound `number' variable.
5352 (eval-when-compile
5353   (defvar number))
5354 (defun gnus-article-marked-p (type &optional article)
5355   (let ((article (or article number)))
5356     (cond
5357      ((eq type 'tick)
5358       (memq article gnus-newsgroup-marked))
5359      ((eq type 'spam)
5360       (memq article gnus-newsgroup-spam-marked))
5361      ((eq type 'unsend)
5362       (memq article gnus-newsgroup-unsendable))
5363      ((eq type 'undownload)
5364       (memq article gnus-newsgroup-undownloaded))
5365      ((eq type 'download)
5366       (memq article gnus-newsgroup-downloadable))
5367      ((eq type 'unread)
5368       (memq article gnus-newsgroup-unreads))
5369      ((eq type 'read)
5370       (memq article gnus-newsgroup-reads))
5371      ((eq type 'dormant)
5372       (memq article gnus-newsgroup-dormant) )
5373      ((eq type 'expire)
5374       (memq article gnus-newsgroup-expirable))
5375      ((eq type 'reply)
5376       (memq article gnus-newsgroup-replied))
5377      ((eq type 'killed)
5378       (memq article gnus-newsgroup-killed))
5379      ((eq type 'bookmark)
5380       (assq article gnus-newsgroup-bookmarks))
5381      ((eq type 'score)
5382       (assq article gnus-newsgroup-scored))
5383      ((eq type 'save)
5384       (memq article gnus-newsgroup-saved))
5385      ((eq type 'cache)
5386       (memq article gnus-newsgroup-cached))
5387      ((eq type 'forward)
5388       (memq article gnus-newsgroup-forwarded))
5389      ((eq type 'seen)
5390       (not (memq article gnus-newsgroup-unseen)))
5391      ((eq type 'recent)
5392       (memq article gnus-newsgroup-recent))
5393      (t t))))
5394
5395 (defun gnus-articles-to-read (group &optional read-all)
5396   "Find out what articles the user wants to read."
5397   (let* ((articles
5398           ;; Select all articles if `read-all' is non-nil, or if there
5399           ;; are no unread articles.
5400           (if (or read-all
5401                   (and (zerop (length gnus-newsgroup-marked))
5402                        (zerop (length gnus-newsgroup-unreads)))
5403                   ;; Fetch all if the predicate is non-nil.
5404                   gnus-newsgroup-display)
5405               ;; We want to select the headers for all the articles in
5406               ;; the group, so we select either all the active
5407               ;; articles in the group, or (if that's nil), the
5408               ;; articles in the cache.
5409               (or
5410                (gnus-uncompress-range (gnus-active group))
5411                (gnus-cache-articles-in-group group))
5412             ;; Select only the "normal" subset of articles.
5413             (gnus-sorted-nunion
5414              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5415              gnus-newsgroup-unreads)))
5416          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5417          (scored (length scored-list))
5418          (number (length articles))
5419          (marked (+ (length gnus-newsgroup-marked)
5420                     (length gnus-newsgroup-dormant)))
5421          (select
5422           (cond
5423            ((numberp read-all)
5424             read-all)
5425            ((numberp gnus-newsgroup-display)
5426             gnus-newsgroup-display)
5427            (t
5428             (condition-case ()
5429                 (cond
5430                  ((and (or (<= scored marked) (= scored number))
5431                        (numberp gnus-large-newsgroup)
5432                        (> number gnus-large-newsgroup))
5433                   (let* ((cursor-in-echo-area nil)
5434                          (initial (gnus-parameter-large-newsgroup-initial
5435                                    gnus-newsgroup-name))
5436                          (input
5437                           (read-string
5438                            (format
5439                             "How many articles from %s (%s %d): "
5440                             (gnus-limit-string
5441                              (gnus-group-decoded-name gnus-newsgroup-name)
5442                              35)
5443                             (if initial "max" "default")
5444                             number)
5445                            (if initial
5446                                (cons (number-to-string initial)
5447                                      0)))))
5448                     (if (string-match "^[ \t]*$" input) number input)))
5449                  ((and (> scored marked) (< scored number)
5450                        (> (- scored number) 20))
5451                   (let ((input
5452                          (read-string
5453                           (format "%s %s (%d scored, %d total): "
5454                                   "How many articles from"
5455                                   (gnus-group-decoded-name group)
5456                                   scored number))))
5457                     (if (string-match "^[ \t]*$" input)
5458                         number input)))
5459                  (t number))
5460               (quit
5461                (message "Quit getting the articles to read")
5462                nil))))))
5463     (setq select (if (stringp select) (string-to-number select) select))
5464     (if (or (null select) (zerop select))
5465         select
5466       (if (and (not (zerop scored)) (<= (abs select) scored))
5467           (progn
5468             (setq articles (sort scored-list '<))
5469             (setq number (length articles)))
5470         (setq articles (copy-sequence articles)))
5471
5472       (when (< (abs select) number)
5473         (if (< select 0)
5474             ;; Select the N oldest articles.
5475             (setcdr (nthcdr (1- (abs select)) articles) nil)
5476           ;; Select the N most recent articles.
5477           (setq articles (nthcdr (- number select) articles))))
5478       (setq gnus-newsgroup-unselected
5479             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5480       (when gnus-alter-articles-to-read-function
5481         (setq articles
5482               (sort
5483                (funcall gnus-alter-articles-to-read-function
5484                         gnus-newsgroup-name articles)
5485                '<)))
5486       articles)))
5487
5488 (defun gnus-killed-articles (killed articles)
5489   (let (out)
5490     (while articles
5491       (when (inline (gnus-member-of-range (car articles) killed))
5492         (push (car articles) out))
5493       (setq articles (cdr articles)))
5494     out))
5495
5496 (defun gnus-uncompress-marks (marks)
5497   "Uncompress the mark ranges in MARKS."
5498   (let ((uncompressed '(score bookmark))
5499         out)
5500     (while marks
5501       (if (memq (caar marks) uncompressed)
5502           (push (car marks) out)
5503         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5504       (setq marks (cdr marks)))
5505     out))
5506
5507 (defun gnus-article-mark-to-type (mark)
5508   "Return the type of MARK."
5509   (or (cadr (assq mark gnus-article-special-mark-lists))
5510       'list))
5511
5512 (defun gnus-article-unpropagatable-p (mark)
5513   "Return whether MARK should be propagated to back end."
5514   (memq mark gnus-article-unpropagated-mark-lists))
5515
5516 (defun gnus-adjust-marked-articles (info)
5517   "Set all article lists and remove all marks that are no longer valid."
5518   (let* ((marked-lists (gnus-info-marks info))
5519          (active (gnus-active (gnus-info-group info)))
5520          (min (car active))
5521          (max (cdr active))
5522          (types gnus-article-mark-lists)
5523          marks var articles article mark mark-type
5524          bgn end)
5525
5526     (dolist (marks marked-lists)
5527       (setq mark (car marks)
5528             mark-type (gnus-article-mark-to-type mark)
5529             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5530
5531       ;; We set the variable according to the type of the marks list,
5532       ;; and then adjust the marks to a subset of the active articles.
5533       (cond
5534        ;; Adjust "simple" lists - compressed yet unsorted
5535        ((eq mark-type 'list)
5536         ;; Simultaneously uncompress and clip to active range
5537         ;; See gnus-uncompress-range for a description of possible marks
5538         (let (l lh)
5539           (if (not (cadr marks))
5540               (set var nil)
5541             (setq articles (if (numberp (cddr marks))
5542                                (list (cdr marks))
5543                              (cdr marks))
5544                   lh (cons nil nil)
5545                   l lh)
5546
5547             (while (setq article (pop articles))
5548               (cond ((consp article)
5549                      (setq bgn (max (car article) min)
5550                            end (min (cdr article) max))
5551                      (while (<= bgn end)
5552                        (setq l (setcdr l (cons bgn nil))
5553                              bgn (1+ bgn))))
5554                     ((and (<= min article)
5555                           (>= max article))
5556                      (setq l (setcdr l (cons article nil))))))
5557             (set var (cdr lh)))))
5558        ;; Adjust assocs.
5559        ((eq mark-type 'tuple)
5560         (set var (setq articles (cdr marks)))
5561         (when (not (listp (cdr (symbol-value var))))
5562           (set var (list (symbol-value var))))
5563         (when (not (listp (cdr articles)))
5564           (setq articles (list articles)))
5565         (while articles
5566           (when (or (not (consp (setq article (pop articles))))
5567                     (< (car article) min)
5568                     (> (car article) max))
5569             (set var (delq article (symbol-value var))))))
5570        ;; Adjust ranges (sloppily).
5571        ((eq mark-type 'range)
5572         (cond
5573          ((eq mark 'seen)
5574           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5575           ;; It should be (seen (NUM1 . NUM2)).
5576           (when (numberp (cddr marks))
5577             (setcdr marks (list (cdr marks))))
5578           (setq articles (cdr marks))
5579           (while (and articles
5580                       (or (and (consp (car articles))
5581                                (> min (cdar articles)))
5582                           (and (numberp (car articles))
5583                                (> min (car articles)))))
5584             (pop articles))
5585           (set var articles))))))))
5586
5587 (defun gnus-update-missing-marks (missing)
5588   "Go through the list of MISSING articles and remove them from the mark lists."
5589   (when missing
5590     (let (var m)
5591       ;; Go through all types.
5592       (dolist (elem gnus-article-mark-lists)
5593         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5594           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5595           (when (symbol-value var)
5596             ;; This list has articles.  So we delete all missing
5597             ;; articles from it.
5598             (setq m missing)
5599             (while m
5600               (set var (delq (pop m) (symbol-value var))))))))))
5601
5602 (defun gnus-update-marks ()
5603   "Enter the various lists of marked articles into the newsgroup info list."
5604   (let ((types gnus-article-mark-lists)
5605         (info (gnus-get-info gnus-newsgroup-name))
5606         type list newmarked symbol delta-marks)
5607     (when info
5608       ;; Add all marks lists to the list of marks lists.
5609       (while (setq type (pop types))
5610         (setq list (symbol-value
5611                     (setq symbol
5612                           (intern (format "gnus-newsgroup-%s" (car type))))))
5613
5614         (when list
5615           ;; Get rid of the entries of the articles that have the
5616           ;; default score.
5617           (when (and (eq (cdr type) 'score)
5618                      gnus-save-score
5619                      list)
5620             (let* ((arts list)
5621                    (prev (cons nil list))
5622                    (all prev))
5623               (while arts
5624                 (if (or (not (consp (car arts)))
5625                         (= (cdar arts) gnus-summary-default-score))
5626                     (setcdr prev (cdr arts))
5627                   (setq prev arts))
5628                 (setq arts (cdr arts)))
5629               (setq list (cdr all)))))
5630
5631         (when (eq (cdr type) 'seen)
5632           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5633
5634         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5635           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5636
5637         (when (and (gnus-check-backend-function
5638                     'request-set-mark gnus-newsgroup-name)
5639                    (not (gnus-article-unpropagatable-p (cdr type))))
5640           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5641                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5642                  (add (gnus-remove-from-range
5643                        (gnus-copy-sequence list) old)))
5644             (when add
5645               (push (list add 'add (list (cdr type))) delta-marks))
5646             (when del
5647               (push (list del 'del (list (cdr type))) delta-marks))))
5648
5649         (when list
5650           (push (cons (cdr type) list) newmarked)))
5651
5652       (when delta-marks
5653         (unless (gnus-check-group gnus-newsgroup-name)
5654           (error "Can't open server for %s" gnus-newsgroup-name))
5655         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5656
5657       ;; Enter these new marks into the info of the group.
5658       (if (nthcdr 3 info)
5659           (setcar (nthcdr 3 info) newmarked)
5660         ;; Add the marks lists to the end of the info.
5661         (when newmarked
5662           (setcdr (nthcdr 2 info) (list newmarked))))
5663
5664       ;; Cut off the end of the info if there's nothing else there.
5665       (let ((i 5))
5666         (while (and (> i 2)
5667                     (not (nth i info)))
5668           (when (nthcdr (decf i) info)
5669             (setcdr (nthcdr i info) nil)))))))
5670
5671 (defun gnus-set-mode-line (where)
5672   "Set the mode line of the article or summary buffers.
5673 If WHERE is `summary', the summary mode line format will be used."
5674   ;; Is this mode line one we keep updated?
5675   (when (and (memq where gnus-updated-mode-lines)
5676              (symbol-value
5677               (intern (format "gnus-%s-mode-line-format-spec" where))))
5678     (let (mode-string)
5679       (save-excursion
5680         ;; We evaluate this in the summary buffer since these
5681         ;; variables are buffer-local to that buffer.
5682         (set-buffer gnus-summary-buffer)
5683         ;; We bind all these variables that are used in the `eval' form
5684         ;; below.
5685         (let* ((mformat (symbol-value
5686                          (intern
5687                           (format "gnus-%s-mode-line-format-spec" where))))
5688                (gnus-tmp-group-name (gnus-group-decoded-name
5689                                      gnus-newsgroup-name))
5690                (gnus-tmp-article-number (or gnus-current-article 0))
5691                (gnus-tmp-unread gnus-newsgroup-unreads)
5692                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5693                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5694                (gnus-tmp-unread-and-unselected
5695                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5696                             (zerop gnus-tmp-unselected))
5697                        "")
5698                       ((zerop gnus-tmp-unselected)
5699                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5700                       (t (format "{%d(+%d) more}"
5701                                  gnus-tmp-unread-and-unticked
5702                                  gnus-tmp-unselected))))
5703                (gnus-tmp-subject
5704                 (if (and gnus-current-headers
5705                          (vectorp gnus-current-headers))
5706                     (gnus-mode-string-quote
5707                      (mail-header-subject gnus-current-headers))
5708                   ""))
5709                bufname-length max-len
5710                gnus-tmp-header);; passed as argument to any user-format-funcs
5711           (setq mode-string (eval mformat))
5712           (setq bufname-length (if (string-match "%b" mode-string)
5713                                    (- (length
5714                                        (buffer-name
5715                                         (if (eq where 'summary)
5716                                             nil
5717                                           (get-buffer gnus-article-buffer))))
5718                                       2)
5719                                  0))
5720           (setq max-len (max 4 (if gnus-mode-non-string-length
5721                                    (- (window-width)
5722                                       gnus-mode-non-string-length
5723                                       bufname-length)
5724                                  (length mode-string))))
5725           ;; We might have to chop a bit of the string off...
5726           (when (> (length mode-string) max-len)
5727             (setq mode-string
5728                   (concat (gnus-truncate-string mode-string (- max-len 3))
5729                           "...")))
5730           ;; Pad the mode string a bit.
5731           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5732       ;; Update the mode line.
5733       (setq mode-line-buffer-identification
5734             (gnus-mode-line-buffer-identification (list mode-string)))
5735       (set-buffer-modified-p t))))
5736
5737 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5738   "Go through the HEADERS list and add all Xrefs to a hash table.
5739 The resulting hash table is returned, or nil if no Xrefs were found."
5740   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5741          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5742          (xref-hashtb (gnus-make-hashtable))
5743          start group entry number xrefs header)
5744     (while headers
5745       (setq header (pop headers))
5746       (when (and (setq xrefs (mail-header-xref header))
5747                  (not (memq (setq number (mail-header-number header))
5748                             unreads)))
5749         (setq start 0)
5750         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5751           (setq start (match-end 0))
5752           (setq group (if prefix
5753                           (concat prefix (substring xrefs (match-beginning 1)
5754                                                     (match-end 1)))
5755                         (substring xrefs (match-beginning 1) (match-end 1))))
5756           (setq number
5757                 (string-to-number (substring xrefs (match-beginning 2)
5758                                           (match-end 2))))
5759           (if (setq entry (gnus-gethash group xref-hashtb))
5760               (setcdr entry (cons number (cdr entry)))
5761             (gnus-sethash group (cons number nil) xref-hashtb)))))
5762     (and start xref-hashtb)))
5763
5764 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5765   "Look through all the headers and mark the Xrefs as read."
5766   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5767         name info xref-hashtb idlist method nth4)
5768     (save-excursion
5769       (set-buffer gnus-group-buffer)
5770       (when (setq xref-hashtb
5771                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5772         (mapatoms
5773          (lambda (group)
5774            (unless (string= from-newsgroup (setq name (symbol-name group)))
5775              (setq idlist (symbol-value group))
5776              ;; Dead groups are not updated.
5777              (and (prog1
5778                       (setq info (gnus-get-info name))
5779                     (when (stringp (setq nth4 (gnus-info-method info)))
5780                       (setq nth4 (gnus-server-to-method nth4))))
5781                   ;; Only do the xrefs if the group has the same
5782                   ;; select method as the group we have just read.
5783                   (or (gnus-methods-equal-p
5784                        nth4 (gnus-find-method-for-group from-newsgroup))
5785                       virtual
5786                       (equal nth4 (setq method (gnus-find-method-for-group
5787                                                 from-newsgroup)))
5788                       (and (equal (car nth4) (car method))
5789                            (equal (nth 1 nth4) (nth 1 method))))
5790                   gnus-use-cross-reference
5791                   (or (not (eq gnus-use-cross-reference t))
5792                       virtual
5793                       ;; Only do cross-references on subscribed
5794                       ;; groups, if that is what is wanted.
5795                       (<= (gnus-info-level info) gnus-level-subscribed))
5796                   (gnus-group-make-articles-read name idlist))))
5797          xref-hashtb)))))
5798
5799 (defun gnus-compute-read-articles (group articles)
5800   (let* ((entry (gnus-group-entry group))
5801          (info (nth 2 entry))
5802          (active (gnus-active group))
5803          ninfo)
5804     (when entry
5805       ;; First peel off all invalid article numbers.
5806       (when active
5807         (let ((ids articles)
5808               id first)
5809           (while (setq id (pop ids))
5810             (when (and first (> id (cdr active)))
5811               ;; We'll end up in this situation in one particular
5812               ;; obscure situation.  If you re-scan a group and get
5813               ;; a new article that is cross-posted to a different
5814               ;; group that has not been re-scanned, you might get
5815               ;; crossposted article that has a higher number than
5816               ;; Gnus believes possible.  So we re-activate this
5817               ;; group as well.  This might mean doing the
5818               ;; crossposting thingy will *increase* the number
5819               ;; of articles in some groups.  Tsk, tsk.
5820               (setq active (or (gnus-activate-group group) active)))
5821             (when (or (> id (cdr active))
5822                       (< id (car active)))
5823               (setq articles (delq id articles))))))
5824       ;; If the read list is nil, we init it.
5825       (if (and active
5826                (null (gnus-info-read info))
5827                (> (car active) 1))
5828           (setq ninfo (cons 1 (1- (car active))))
5829         (setq ninfo (gnus-info-read info)))
5830       ;; Then we add the read articles to the range.
5831       (gnus-add-to-range
5832        ninfo (setq articles (sort articles '<))))))
5833
5834 (defun gnus-group-make-articles-read (group articles)
5835   "Update the info of GROUP to say that ARTICLES are read."
5836   (let* ((num 0)
5837          (entry (gnus-group-entry group))
5838          (info (nth 2 entry))
5839          (active (gnus-active group))
5840          range)
5841     (when entry
5842       (setq range (gnus-compute-read-articles group articles))
5843       (with-current-buffer gnus-group-buffer
5844         (gnus-undo-register
5845           `(progn
5846              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5847              (gnus-info-set-read ',info ',(gnus-info-read info))
5848              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5849              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5850              (gnus-group-update-group ,group t))))
5851       ;; Add the read articles to the range.
5852       (gnus-info-set-read info range)
5853       (gnus-request-set-mark group (list (list range 'add '(read))))
5854       ;; Then we have to re-compute how many unread
5855       ;; articles there are in this group.
5856       (when active
5857         (cond
5858          ((not range)
5859           (setq num (- (1+ (cdr active)) (car active))))
5860          ((not (listp (cdr range)))
5861           (setq num (- (cdr active) (- (1+ (cdr range))
5862                                        (car range)))))
5863          (t
5864           (while range
5865             (if (numberp (car range))
5866                 (setq num (1+ num))
5867               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5868             (setq range (cdr range)))
5869           (setq num (- (cdr active) num))))
5870         ;; Update the number of unread articles.
5871         (setcar entry num)
5872         ;; Update the group buffer.
5873         (unless (gnus-ephemeral-group-p group)
5874           (gnus-group-update-group group t))))))
5875
5876 (defvar gnus-newsgroup-none-id 0)
5877
5878 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5879   (let ((cur nntp-server-buffer)
5880         (dependencies
5881          (or dependencies
5882              (with-current-buffer gnus-summary-buffer
5883                gnus-newsgroup-dependencies)))
5884         headers id end ref number
5885         (mail-parse-charset gnus-newsgroup-charset)
5886         (mail-parse-ignored-charsets
5887          (save-excursion (condition-case nil
5888                              (set-buffer gnus-summary-buffer)
5889                            (error))
5890                          gnus-newsgroup-ignored-charsets)))
5891     (save-excursion
5892       (set-buffer nntp-server-buffer)
5893       ;; Translate all TAB characters into SPACE characters.
5894       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5895       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5896       (ietf-drums-unfold-fws)
5897       (gnus-run-hooks 'gnus-parse-headers-hook)
5898       (let ((case-fold-search t)
5899             in-reply-to header p lines chars ctype)
5900         (goto-char (point-min))
5901         ;; Search to the beginning of the next header.  Error messages
5902         ;; do not begin with 2 or 3.
5903         (while (re-search-forward "^[23][0-9]+ " nil t)
5904           (setq id nil
5905                 ref nil)
5906           ;; This implementation of this function, with nine
5907           ;; search-forwards instead of the one re-search-forward and
5908           ;; a case (which basically was the old function) is actually
5909           ;; about twice as fast, even though it looks messier.  You
5910           ;; can't have everything, I guess.  Speed and elegance
5911           ;; doesn't always go hand in hand.
5912           (setq
5913            header
5914            (make-full-mail-header
5915             ;; Number.
5916             (prog1
5917                 (setq number (read cur))
5918               (end-of-line)
5919               (setq p (point))
5920               (narrow-to-region (point)
5921                                 (or (and (search-forward "\n.\n" nil t)
5922                                          (- (point) 2))
5923                                     (point))))
5924             ;; Subject.
5925             (progn
5926               (goto-char p)
5927               (if (search-forward "\nsubject:" nil t)
5928                   (nnheader-header-value)
5929                 "(none)"))
5930             ;; From.
5931             (progn
5932               (goto-char p)
5933               (if (search-forward "\nfrom:" nil t)
5934                   (nnheader-header-value)
5935                 "(nobody)"))
5936             ;; Date.
5937             (progn
5938               (goto-char p)
5939               (if (search-forward "\ndate:" nil t)
5940                   (nnheader-header-value) ""))
5941             ;; Message-ID.
5942             (progn
5943               (goto-char p)
5944               (setq id (if (re-search-forward
5945                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5946                            ;; We do it this way to make sure the Message-ID
5947                            ;; is (somewhat) syntactically valid.
5948                            (buffer-substring (match-beginning 1)
5949                                              (match-end 1))
5950                          ;; If there was no message-id, we just fake one
5951                          ;; to make subsequent routines simpler.
5952                          (nnheader-generate-fake-message-id number))))
5953             ;; References.
5954             (progn
5955               (goto-char p)
5956               (if (search-forward "\nreferences:" nil t)
5957                   (progn
5958                     (setq end (point))
5959                     (prog1
5960                         (nnheader-header-value)
5961                       (setq ref
5962                             (buffer-substring
5963                              (progn
5964                                ;; (end-of-line)
5965                                (search-backward ">" end t)
5966                                (1+ (point)))
5967                              (progn
5968                                (search-backward "<" end t)
5969                                (point))))))
5970                 ;; Get the references from the in-reply-to header if there
5971                 ;; were no references and the in-reply-to header looks
5972                 ;; promising.
5973                 (if (and (search-forward "\nin-reply-to:" nil t)
5974                          (setq in-reply-to (nnheader-header-value))
5975                          (string-match "<[^>]+>" in-reply-to))
5976                     (let (ref2)
5977                       (setq ref (substring in-reply-to (match-beginning 0)
5978                                            (match-end 0)))
5979                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5980                         (setq ref2 (substring in-reply-to (match-beginning 0)
5981                                               (match-end 0)))
5982                         (when (> (length ref2) (length ref))
5983                           (setq ref ref2)))
5984                       ref)
5985                   (setq ref nil))))
5986             ;; Chars.
5987             (progn
5988               (goto-char p)
5989               (if (search-forward "\nchars: " nil t)
5990                   (if (numberp (setq chars (ignore-errors (read cur))))
5991                       chars -1)
5992                 -1))
5993             ;; Lines.
5994             (progn
5995               (goto-char p)
5996               (if (search-forward "\nlines: " nil t)
5997                   (if (numberp (setq lines (ignore-errors (read cur))))
5998                       lines -1)
5999                 -1))
6000             ;; Xref.
6001             (progn
6002               (goto-char p)
6003               (and (search-forward "\nxref:" nil t)
6004                    (nnheader-header-value)))
6005             ;; Extra.
6006             (when gnus-extra-headers
6007               (let ((extra gnus-extra-headers)
6008                     out)
6009                 (while extra
6010                   (goto-char p)
6011                   (when (search-forward
6012                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6013                     (push (cons (car extra) (nnheader-header-value)) out))
6014                   (pop extra))
6015                 out))))
6016           (goto-char p)
6017           (if (and (search-forward "\ncontent-type: " nil t)
6018                    (setq ctype (nnheader-header-value)))
6019               (mime-entity-set-content-type-internal
6020                header (mime-parse-Content-Type ctype)))
6021           (when (equal id ref)
6022             (setq ref nil))
6023
6024           (when gnus-alter-header-function
6025             (funcall gnus-alter-header-function header)
6026             (setq id (mail-header-id header)
6027                   ref (gnus-parent-id (mail-header-references header))))
6028
6029           (when (setq header
6030                       (gnus-dependencies-add-header
6031                        header dependencies force-new))
6032             (push header headers))
6033           (goto-char (point-max))
6034           (widen))
6035         (nreverse headers)))))
6036
6037 ;; Goes through the xover lines and returns a list of vectors
6038 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6039                                                   force-new dependencies
6040                                                   group also-fetch-heads)
6041   "Parse the news overview data in the server buffer.
6042 Return a list of headers that match SEQUENCE (see
6043 `nntp-retrieve-headers')."
6044   ;; Get the Xref when the users reads the articles since most/some
6045   ;; NNTP servers do not include Xrefs when using XOVER.
6046   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6047   (let ((mail-parse-charset gnus-newsgroup-charset)
6048         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6049         (cur nntp-server-buffer)
6050         (dependencies (or dependencies gnus-newsgroup-dependencies))
6051         (allp (cond
6052                ((eq gnus-read-all-available-headers t)
6053                 t)
6054                ((stringp gnus-read-all-available-headers)
6055                 (string-match gnus-read-all-available-headers group))
6056                (t
6057                 nil)))
6058         number headers header)
6059     (save-excursion
6060       (set-buffer nntp-server-buffer)
6061       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6062       ;; Allow the user to mangle the headers before parsing them.
6063       (gnus-run-hooks 'gnus-parse-headers-hook)
6064       (goto-char (point-min))
6065       (gnus-parse-without-error
6066         (while (and (or sequence allp)
6067                     (not (eobp)))
6068           (setq number (read cur))
6069           (when (not allp)
6070             (while (and sequence
6071                         (< (car sequence) number))
6072               (setq sequence (cdr sequence))))
6073           (when (and (or allp
6074                          (and sequence
6075                               (eq number (car sequence))))
6076                      (progn
6077                        (setq sequence (cdr sequence))
6078                        (setq header (inline
6079                                       (gnus-nov-parse-line
6080                                        number dependencies force-new)))))
6081             (push header headers))
6082           (forward-line 1)))
6083       ;; A common bug in inn is that if you have posted an article and
6084       ;; then retrieves the active file, it will answer correctly --
6085       ;; the new article is included.  However, a NOV entry for the
6086       ;; article may not have been generated yet, so this may fail.
6087       ;; We work around this problem by retrieving the last few
6088       ;; headers using HEAD.
6089       (if (or (not also-fetch-heads)
6090               (not sequence))
6091           ;; We (probably) got all the headers.
6092           (nreverse headers)
6093         (let ((gnus-nov-is-evil t))
6094           (nconc
6095            (nreverse headers)
6096            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6097              (gnus-get-newsgroup-headers))))))))
6098
6099 (defun gnus-article-get-xrefs ()
6100   "Fill in the Xref value in `gnus-current-headers', if necessary.
6101 This is meant to be called in `gnus-article-internal-prepare-hook'."
6102   (let ((headers (with-current-buffer gnus-summary-buffer
6103                    gnus-current-headers)))
6104     (or (not gnus-use-cross-reference)
6105         (not headers)
6106         (and (mail-header-xref headers)
6107              (not (string= (mail-header-xref headers) "")))
6108         (let ((case-fold-search t)
6109               xref)
6110           (save-restriction
6111             (nnheader-narrow-to-headers)
6112             (goto-char (point-min))
6113             (when (or (and (not (eobp))
6114                            (eq (downcase (char-after)) ?x)
6115                            (looking-at "Xref:"))
6116                       (search-forward "\nXref:" nil t))
6117               (goto-char (1+ (match-end 0)))
6118               (setq xref (buffer-substring (point) (point-at-eol)))
6119               (mail-header-set-xref headers xref)))))))
6120
6121 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6122   "Find article ID and insert the summary line for that article.
6123 OLD-HEADER can either be a header or a line number to insert
6124 the subject line on."
6125   (let* ((line (and (numberp old-header) old-header))
6126          (old-header (and (vectorp old-header) old-header))
6127          (header (cond ((and old-header use-old-header)
6128                         old-header)
6129                        ((and (numberp id)
6130                              (gnus-number-to-header id))
6131                         (gnus-number-to-header id))
6132                        (t
6133                         (gnus-read-header id))))
6134          (number (and (numberp id) id))
6135          d)
6136     (when header
6137       ;; Rebuild the thread that this article is part of and go to the
6138       ;; article we have fetched.
6139       (when (and (not gnus-show-threads)
6140                  old-header)
6141         (when (and number
6142                    (setq d (gnus-data-find (mail-header-number old-header))))
6143           (goto-char (gnus-data-pos d))
6144           (gnus-data-remove
6145            number
6146            (- (point-at-bol)
6147               (prog1
6148                   (1+ (point-at-eol))
6149                 (gnus-delete-line))))))
6150       ;; Remove list identifiers from subject.
6151       (when gnus-list-identifiers
6152         (let ((gnus-newsgroup-headers (list header)))
6153           (gnus-summary-remove-list-identifiers)))
6154       (when old-header
6155         (mail-header-set-number header (mail-header-number old-header)))
6156       (setq gnus-newsgroup-sparse
6157             (delq (setq number (mail-header-number header))
6158                   gnus-newsgroup-sparse))
6159       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6160       (push number gnus-newsgroup-limit)
6161       (gnus-rebuild-thread (mail-header-id header) line)
6162       (gnus-summary-goto-subject number nil t))
6163     (when (and (numberp number)
6164                (> number 0))
6165       ;; We have to update the boundaries even if we can't fetch the
6166       ;; article if ID is a number -- so that the next `P' or `N'
6167       ;; command will fetch the previous (or next) article even
6168       ;; if the one we tried to fetch this time has been canceled.
6169       (when (> number gnus-newsgroup-end)
6170         (setq gnus-newsgroup-end number))
6171       (when (< number gnus-newsgroup-begin)
6172         (setq gnus-newsgroup-begin number))
6173       (setq gnus-newsgroup-unselected
6174             (delq number gnus-newsgroup-unselected)))
6175     ;; Report back a success?
6176     (and header (mail-header-number header))))
6177
6178 ;;; Process/prefix in the summary buffer
6179
6180 (defun gnus-summary-work-articles (n)
6181   "Return a list of articles to be worked upon.
6182 The prefix argument, the list of process marked articles, and the
6183 current article will be taken into consideration."
6184   (save-excursion
6185     (set-buffer gnus-summary-buffer)
6186     (cond
6187      (n
6188       ;; A numerical prefix has been given.
6189       (setq n (prefix-numeric-value n))
6190       (let ((backward (< n 0))
6191             (n (abs (prefix-numeric-value n)))
6192             articles article)
6193         (save-excursion
6194           (while
6195               (and (> n 0)
6196                    (push (setq article (gnus-summary-article-number))
6197                          articles)
6198                    (if backward
6199                        (gnus-summary-find-prev nil article)
6200                      (gnus-summary-find-next nil article)))
6201             (decf n)))
6202         (nreverse articles)))
6203      ((and (gnus-region-active-p) (mark))
6204       (message "region active")
6205       ;; Work on the region between point and mark.
6206       (let ((max (max (point) (mark)))
6207             articles article)
6208         (save-excursion
6209           (goto-char (min (point) (mark)))
6210           (while
6211               (and
6212                (push (setq article (gnus-summary-article-number)) articles)
6213                (gnus-summary-find-next nil article)
6214                (< (point) max)))
6215           (nreverse articles))))
6216      (gnus-newsgroup-processable
6217       ;; There are process-marked articles present.
6218       ;; Save current state.
6219       (gnus-summary-save-process-mark)
6220       ;; Return the list.
6221       (reverse gnus-newsgroup-processable))
6222      (t
6223       ;; Just return the current article.
6224       (list (gnus-summary-article-number))))))
6225
6226 (defmacro gnus-summary-iterate (arg &rest forms)
6227   "Iterate over the process/prefixed articles and do FORMS.
6228 ARG is the interactive prefix given to the command.  FORMS will be
6229 executed with point over the summary line of the articles."
6230   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6231     `(let ((,articles (gnus-summary-work-articles ,arg)))
6232        (while ,articles
6233          (gnus-summary-goto-subject (car ,articles))
6234          ,@forms
6235          (pop ,articles)))))
6236
6237 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6238 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6239
6240 (defun gnus-summary-save-process-mark ()
6241   "Push the current set of process marked articles on the stack."
6242   (interactive)
6243   (push (copy-sequence gnus-newsgroup-processable)
6244         gnus-newsgroup-process-stack))
6245
6246 (defun gnus-summary-kill-process-mark ()
6247   "Push the current set of process marked articles on the stack and unmark."
6248   (interactive)
6249   (gnus-summary-save-process-mark)
6250   (gnus-summary-unmark-all-processable))
6251
6252 (defun gnus-summary-yank-process-mark ()
6253   "Pop the last process mark state off the stack and restore it."
6254   (interactive)
6255   (unless gnus-newsgroup-process-stack
6256     (error "Empty mark stack"))
6257   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6258
6259 (defun gnus-summary-process-mark-set (set)
6260   "Make SET into the current process marked articles."
6261   (gnus-summary-unmark-all-processable)
6262   (mapc 'gnus-summary-set-process-mark set))
6263
6264 ;;; Searching and stuff
6265
6266 (defun gnus-summary-search-group (&optional backward use-level)
6267   "Search for next unread newsgroup.
6268 If optional argument BACKWARD is non-nil, search backward instead."
6269   (save-excursion
6270     (set-buffer gnus-group-buffer)
6271     (when (gnus-group-search-forward
6272            backward nil (if use-level (gnus-group-group-level) nil))
6273       (gnus-group-group-name))))
6274
6275 (defun gnus-summary-best-group (&optional exclude-group)
6276   "Find the name of the best unread group.
6277 If EXCLUDE-GROUP, do not go to this group."
6278   (with-current-buffer gnus-group-buffer
6279     (save-excursion
6280       (gnus-group-best-unread-group exclude-group))))
6281
6282 (defun gnus-summary-find-next (&optional unread article backward)
6283   (if backward
6284       (gnus-summary-find-prev unread article)
6285     (let* ((dummy (gnus-summary-article-intangible-p))
6286            (article (or article (gnus-summary-article-number)))
6287            (data (gnus-data-find-list article))
6288            result)
6289       (when (and (not dummy)
6290                  (or (not gnus-summary-check-current)
6291                      (not unread)
6292                      (not (gnus-data-unread-p (car data)))))
6293         (setq data (cdr data)))
6294       (when (setq result
6295                   (if unread
6296                       (progn
6297                         (while data
6298                           (unless (memq (gnus-data-number (car data))
6299                                         (cond
6300                                          ((eq gnus-auto-goto-ignores
6301                                               'always-undownloaded)
6302                                           gnus-newsgroup-undownloaded)
6303                                          (gnus-plugged
6304                                           nil)
6305                                          ((eq gnus-auto-goto-ignores
6306                                               'unfetched)
6307                                           gnus-newsgroup-unfetched)
6308                                          ((eq gnus-auto-goto-ignores
6309                                               'undownloaded)
6310                                           gnus-newsgroup-undownloaded)))
6311                             (when (gnus-data-unread-p (car data))
6312                               (setq result (car data)
6313                                     data nil)))
6314                           (setq data (cdr data)))
6315                         result)
6316                     (car data)))
6317         (goto-char (gnus-data-pos result))
6318         (gnus-data-number result)))))
6319
6320 (defun gnus-summary-find-prev (&optional unread article)
6321   (let* ((eobp (eobp))
6322          (article (or article (gnus-summary-article-number)))
6323          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6324          result)
6325     (when (and (not eobp)
6326                (or (not gnus-summary-check-current)
6327                    (not unread)
6328                    (not (gnus-data-unread-p (car data)))))
6329       (setq data (cdr data)))
6330     (when (setq result
6331                 (if unread
6332                     (progn
6333                       (while data
6334                         (unless (memq (gnus-data-number (car data))
6335                                       (cond
6336                                        ((eq gnus-auto-goto-ignores
6337                                             'always-undownloaded)
6338                                         gnus-newsgroup-undownloaded)
6339                                        (gnus-plugged
6340                                         nil)
6341                                        ((eq gnus-auto-goto-ignores
6342                                             'unfetched)
6343                                         gnus-newsgroup-unfetched)
6344                                        ((eq gnus-auto-goto-ignores
6345                                             'undownloaded)
6346                                         gnus-newsgroup-undownloaded)))
6347                           (when (gnus-data-unread-p (car data))
6348                             (setq result (car data)
6349                                   data nil)))
6350                         (setq data (cdr data)))
6351                       result)
6352                   (car data)))
6353       (goto-char (gnus-data-pos result))
6354       (gnus-data-number result))))
6355
6356 (defun gnus-summary-find-subject (subject &optional unread backward article)
6357   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6358          (article (or article (gnus-summary-article-number)))
6359          (articles (gnus-data-list backward))
6360          (arts (gnus-data-find-list article articles))
6361          result)
6362     (when (or (not gnus-summary-check-current)
6363               (not unread)
6364               (not (gnus-data-unread-p (car arts))))
6365       (setq arts (cdr arts)))
6366     (while arts
6367       (and (or (not unread)
6368                (gnus-data-unread-p (car arts)))
6369            (vectorp (gnus-data-header (car arts)))
6370            (gnus-subject-equal
6371             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6372            (setq result (car arts)
6373                  arts nil))
6374       (setq arts (cdr arts)))
6375     (and result
6376          (goto-char (gnus-data-pos result))
6377          (gnus-data-number result))))
6378
6379 (defun gnus-summary-search-forward (&optional unread subject backward)
6380   "Search forward for an article.
6381 If UNREAD, look for unread articles.  If SUBJECT, look for
6382 articles with that subject.  If BACKWARD, search backward instead."
6383   (cond (subject (gnus-summary-find-subject subject unread backward))
6384         (backward (gnus-summary-find-prev unread))
6385         (t (gnus-summary-find-next unread))))
6386
6387 (defun gnus-recenter (&optional n)
6388   "Center point in window and redisplay frame.
6389 Also do horizontal recentering."
6390   (interactive "P")
6391   (when (and gnus-auto-center-summary
6392              (not (eq gnus-auto-center-summary 'vertical)))
6393     (gnus-horizontal-recenter))
6394   (recenter n))
6395
6396 (defun gnus-summary-recenter ()
6397   "Center point in the summary window.
6398 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6399 displayed, no centering will be performed."
6400   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6401   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6402   (interactive)
6403   ;; The user has to want it.
6404   (when gnus-auto-center-summary
6405     (let* ((top (cond ((< (window-height) 4) 0)
6406                       ((< (window-height) 7) 1)
6407                       (t (if (numberp gnus-auto-center-summary)
6408                              gnus-auto-center-summary
6409                            (/ (1- (window-height)) 2)))))
6410            (height (1- (window-height)))
6411            (bottom (save-excursion (goto-char (point-max))
6412                                    (forward-line (- height))
6413                                    (point)))
6414            (window (get-buffer-window (current-buffer))))
6415       (when (get-buffer-window gnus-article-buffer)
6416         ;; Only do recentering when the article buffer is displayed,
6417         ;; Set the window start to either `bottom', which is the biggest
6418         ;; possible valid number, or the second line from the top,
6419         ;; whichever is the least.
6420         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6421           (if (> bottom top-pos)
6422               ;; Keep the second line from the top visible
6423               (set-window-start window top-pos t)
6424             ;; Try to keep the bottom line visible; if it's partially
6425             ;; obscured, either scroll one more line to make it fully
6426             ;; visible, or revert to using TOP-POS.
6427             (save-excursion
6428               (goto-char (point-max))
6429               (forward-line -1)
6430               (let ((last-line-start (point)))
6431                 (goto-char bottom)
6432                 (set-window-start window (point) t)
6433                 (when (not (pos-visible-in-window-p last-line-start window))
6434                   (forward-line 1)
6435                   (set-window-start window (min (point) top-pos) t)))))))
6436       ;; Do horizontal recentering while we're at it.
6437       (when (and (get-buffer-window (current-buffer) t)
6438                  (not (eq gnus-auto-center-summary 'vertical)))
6439         (let ((selected (selected-window)))
6440           (select-window (get-buffer-window (current-buffer) t))
6441           (gnus-summary-position-point)
6442           (gnus-horizontal-recenter)
6443           (select-window selected))))))
6444
6445 (defun gnus-summary-jump-to-group (newsgroup)
6446   "Move point to NEWSGROUP in group mode buffer."
6447   ;; Keep update point of group mode buffer if visible.
6448   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6449       (save-window-excursion
6450         ;; Take care of tree window mode.
6451         (when (get-buffer-window gnus-group-buffer)
6452           (pop-to-buffer gnus-group-buffer))
6453         (gnus-group-jump-to-group newsgroup))
6454     (save-excursion
6455       ;; Take care of tree window mode.
6456       (if (get-buffer-window gnus-group-buffer)
6457           (pop-to-buffer gnus-group-buffer)
6458         (set-buffer gnus-group-buffer))
6459       (gnus-group-jump-to-group newsgroup))))
6460
6461 ;; This function returns a list of article numbers based on the
6462 ;; difference between the ranges of read articles in this group and
6463 ;; the range of active articles.
6464 (defun gnus-list-of-unread-articles (group)
6465   (let* ((read (gnus-info-read (gnus-get-info group)))
6466          (active (or (gnus-active group) (gnus-activate-group group)))
6467          (last (or (cdr active)
6468                    (error "Group %s couldn't be activated " group)))
6469          first nlast unread)
6470     ;; If none are read, then all are unread.
6471     (if (not read)
6472         (setq first (car active))
6473       ;; If the range of read articles is a single range, then the
6474       ;; first unread article is the article after the last read
6475       ;; article.  Sounds logical, doesn't it?
6476       (if (and (not (listp (cdr read)))
6477                (or (< (car read) (car active))
6478                    (progn (setq read (list read))
6479                           nil)))
6480           (setq first (max (car active) (1+ (cdr read))))
6481         ;; `read' is a list of ranges.
6482         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6483                                   (caar read)))
6484                   1)
6485           (setq first (car active)))
6486         (while read
6487           (when first
6488             (while (< first nlast)
6489               (setq unread (cons first unread)
6490                     first (1+ first))))
6491           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6492           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6493           (setq read (cdr read)))))
6494     ;; And add the last unread articles.
6495     (while (<= first last)
6496       (setq unread (cons first unread)
6497             first (1+ first)))
6498     ;; Return the list of unread articles.
6499     (delq 0 (nreverse unread))))
6500
6501 (defun gnus-list-of-read-articles (group)
6502   "Return a list of unread, unticked and non-dormant articles."
6503   (let* ((info (gnus-get-info group))
6504          (marked (gnus-info-marks info))
6505          (active (gnus-active group)))
6506     (and info active
6507          (gnus-list-range-difference
6508           (gnus-list-range-difference
6509            (gnus-sorted-complement
6510             (gnus-uncompress-range active)
6511             (gnus-list-of-unread-articles group))
6512            (cdr (assq 'dormant marked)))
6513           (cdr (assq 'tick marked))))))
6514
6515 ;; This function returns a sequence of article numbers based on the
6516 ;; difference between the ranges of read articles in this group and
6517 ;; the range of active articles.
6518 (defun gnus-sequence-of-unread-articles (group)
6519   (let* ((read (gnus-info-read (gnus-get-info group)))
6520          (active (or (gnus-active group) (gnus-activate-group group)))
6521          (last (cdr active))
6522          first nlast unread)
6523     ;; If none are read, then all are unread.
6524     (if (not read)
6525         (setq first (car active))
6526       ;; If the range of read articles is a single range, then the
6527       ;; first unread article is the article after the last read
6528       ;; article.  Sounds logical, doesn't it?
6529       (if (and (not (listp (cdr read)))
6530                (or (< (car read) (car active))
6531                    (progn (setq read (list read))
6532                           nil)))
6533           (setq first (max (car active) (1+ (cdr read))))
6534         ;; `read' is a list of ranges.
6535         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6536                                   (caar read)))
6537                   1)
6538           (setq first (car active)))
6539         (while read
6540           (when first
6541             (push (cons first nlast) unread))
6542           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6543           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6544           (setq read (cdr read)))))
6545     ;; And add the last unread articles.
6546     (cond ((< first last)
6547            (push (cons first last) unread))
6548           ((= first last)
6549            (push first unread)))
6550     ;; Return the sequence of unread articles.
6551     (delq 0 (nreverse unread))))
6552
6553 ;; Various summary commands
6554
6555 (defun gnus-summary-select-article-buffer ()
6556   "Reconfigure windows to show article buffer."
6557   (interactive)
6558   (if (not (gnus-buffer-live-p gnus-article-buffer))
6559       (error "There is no article buffer for this summary buffer")
6560     (gnus-configure-windows 'article)
6561     (select-window (get-buffer-window gnus-article-buffer))))
6562
6563 (defun gnus-summary-universal-argument (arg)
6564   "Perform any operation on all articles that are process/prefixed."
6565   (interactive "P")
6566   (let ((articles (gnus-summary-work-articles arg))
6567         func article)
6568     (if (eq
6569          (setq
6570           func
6571           (key-binding
6572            (read-key-sequence
6573             (substitute-command-keys
6574              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6575          'undefined)
6576         (gnus-error 1 "Undefined key")
6577       (save-excursion
6578         (while articles
6579           (gnus-summary-goto-subject (setq article (pop articles)))
6580           (let (gnus-newsgroup-processable)
6581             (command-execute func))
6582           (gnus-summary-remove-process-mark article)))))
6583   (gnus-summary-position-point))
6584
6585 (defun gnus-summary-toggle-truncation (&optional arg)
6586   "Toggle truncation of summary lines.
6587 With ARG, turn line truncation on if ARG is positive."
6588   (interactive "P")
6589   (setq truncate-lines
6590         (if (null arg) (not truncate-lines)
6591           (> (prefix-numeric-value arg) 0)))
6592   (redraw-display))
6593
6594 (defun gnus-summary-find-for-reselect ()
6595   "Return the number of an article to stay on across a reselect.
6596 The current article is considered, then following articles, then previous
6597 articles.  An article is sought which is not cancelled and isn't a temporary
6598 insertion from another group.  If there's no such then return a dummy 0."
6599   (let (found)
6600     (dolist (rev '(nil t))
6601       (unless found      ; don't demand the reverse list if we don't need it
6602         (let ((data (gnus-data-find-list
6603                      (gnus-summary-article-number) (gnus-data-list rev))))
6604           (while (and data (not found))
6605             (if (and (< 0 (gnus-data-number (car data)))
6606                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6607                 (setq found (gnus-data-number (car data))))
6608             (setq data (cdr data))))))
6609     (or found 0)))
6610
6611 (defun gnus-summary-reselect-current-group (&optional all rescan)
6612   "Exit and then reselect the current newsgroup.
6613 The prefix argument ALL means to select all articles."
6614   (interactive "P")
6615   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6616     (error "Ephemeral groups can't be reselected"))
6617   (let ((current-subject (gnus-summary-find-for-reselect))
6618         (group gnus-newsgroup-name))
6619     (setq gnus-newsgroup-begin nil)
6620     (gnus-summary-exit nil 'leave-hidden)
6621     ;; We have to adjust the point of group mode buffer because
6622     ;; point was moved to the next unread newsgroup by exiting.
6623     (gnus-summary-jump-to-group group)
6624     (when rescan
6625       (save-excursion
6626         (save-window-excursion
6627           ;; Don't show group contents.
6628           (set-window-start (selected-window) (point-max))
6629           (gnus-group-get-new-news-this-group 1))))
6630     (gnus-group-read-group all t)
6631     (gnus-summary-goto-subject current-subject nil t)))
6632
6633 (defun gnus-summary-rescan-group (&optional all)
6634   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6635   (interactive "P")
6636   (gnus-summary-reselect-current-group all t))
6637
6638 (defun gnus-summary-update-info (&optional non-destructive)
6639   (save-excursion
6640     (let ((group gnus-newsgroup-name))
6641       (when group
6642         (when gnus-newsgroup-kill-headers
6643           (setq gnus-newsgroup-killed
6644                 (gnus-compress-sequence
6645                  (gnus-sorted-union
6646                   (gnus-list-range-intersection
6647                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6648                   gnus-newsgroup-unreads)
6649                  t)))
6650         (unless (listp (cdr gnus-newsgroup-killed))
6651           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6652         (let ((headers gnus-newsgroup-headers))
6653           ;; Set the new ranges of read articles.
6654           (with-current-buffer gnus-group-buffer
6655             (gnus-undo-force-boundary))
6656           (gnus-update-read-articles
6657            group (gnus-sorted-union
6658                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6659           ;; Set the current article marks.
6660           (let ((gnus-newsgroup-scored
6661                  (if (and (not gnus-save-score)
6662                           (not non-destructive))
6663                      nil
6664                    gnus-newsgroup-scored)))
6665             (save-excursion
6666               (gnus-update-marks)))
6667           ;; Do the cross-ref thing.
6668           (when gnus-use-cross-reference
6669             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6670           ;; Do not switch windows but change the buffer to work.
6671           (set-buffer gnus-group-buffer)
6672           (unless (gnus-ephemeral-group-p group)
6673             (gnus-group-update-group group)))))))
6674
6675 (defun gnus-summary-save-newsrc (&optional force)
6676   "Save the current number of read/marked articles in the dribble buffer.
6677 The dribble buffer will then be saved.
6678 If FORCE (the prefix), also save the .newsrc file(s)."
6679   (interactive "P")
6680   (gnus-summary-update-info t)
6681   (if force
6682       (gnus-save-newsrc-file)
6683     (gnus-dribble-save)))
6684
6685 (defun gnus-summary-exit (&optional temporary leave-hidden)
6686   "Exit reading current newsgroup, and then return to group selection mode.
6687 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6688   (interactive)
6689   (gnus-set-global-variables)
6690   (gnus-kill-save-kill-buffer)
6691   (gnus-async-halt-prefetch)
6692   (let* ((group gnus-newsgroup-name)
6693          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6694          (gnus-group-is-exiting-p t)
6695          (mode major-mode)
6696          (group-point nil)
6697          (buf (current-buffer)))
6698     (unless quit-config
6699       ;; Do adaptive scoring, and possibly save score files.
6700       (when gnus-newsgroup-adaptive
6701         (gnus-score-adaptive))
6702       (when gnus-use-scoring
6703         (gnus-score-save)))
6704     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6705     ;; If we have several article buffers, we kill them at exit.
6706     (unless gnus-single-article-buffer
6707       (gnus-kill-buffer gnus-original-article-buffer)
6708       (setq gnus-article-current nil))
6709     (when gnus-use-cache
6710       (gnus-cache-possibly-remove-articles)
6711       (gnus-cache-save-buffers))
6712     (gnus-async-prefetch-remove-group group)
6713     (when gnus-suppress-duplicates
6714       (gnus-dup-enter-articles))
6715     (when gnus-use-trees
6716       (gnus-tree-close group))
6717     (when gnus-use-cache
6718       (gnus-cache-write-active))
6719     ;; Remove entries for this group.
6720     (nnmail-purge-split-history (gnus-group-real-name group))
6721     ;; Make all changes in this group permanent.
6722     (unless quit-config
6723       (gnus-run-hooks 'gnus-exit-group-hook)
6724       (gnus-summary-update-info))
6725     (gnus-close-group group)
6726     ;; Make sure where we were, and go to next newsgroup.
6727     (set-buffer gnus-group-buffer)
6728     (unless quit-config
6729       (gnus-group-jump-to-group group))
6730     (gnus-run-hooks 'gnus-summary-exit-hook)
6731     (unless (or quit-config
6732                 ;; If this group has disappeared from the summary
6733                 ;; buffer, don't skip forwards.
6734                 (not (string= group (gnus-group-group-name))))
6735       (gnus-group-next-unread-group 1))
6736     (setq group-point (point))
6737     (if temporary
6738         nil                             ;Nothing to do.
6739       ;; If we have several article buffers, we kill them at exit.
6740       (unless gnus-single-article-buffer
6741         (gnus-kill-buffer gnus-article-buffer)
6742         (gnus-kill-buffer gnus-original-article-buffer)
6743         (setq gnus-article-current nil))
6744       (set-buffer buf)
6745       (if (not gnus-kill-summary-on-exit)
6746           (progn
6747             (gnus-deaden-summary)
6748             (setq mode nil))
6749         ;; We set all buffer-local variables to nil.  It is unclear why
6750         ;; this is needed, but if we don't, buffer-local variables are
6751         ;; not garbage-collected, it seems.  This would the lead to en
6752         ;; ever-growing Emacs.
6753         (gnus-summary-clear-local-variables)
6754         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6755           (gnus-summary-clear-local-variables))
6756         (when (get-buffer gnus-article-buffer)
6757           (bury-buffer gnus-article-buffer))
6758         ;; Return to group mode buffer.
6759         (when (eq mode 'gnus-summary-mode)
6760           (gnus-kill-buffer buf)))
6761       (setq gnus-current-select-method gnus-select-method)
6762       (set-buffer gnus-group-buffer)
6763       (if quit-config
6764           (gnus-handle-ephemeral-exit quit-config)
6765         (goto-char group-point)
6766         ;; If gnus-group-buffer is already displayed, make sure we also move
6767         ;; the cursor in the window that displays it.
6768         (let ((win (get-buffer-window (current-buffer) 0)))
6769           (if win (set-window-point win (point))))
6770         (unless leave-hidden
6771           (gnus-configure-windows 'group 'force))
6772         (unless (pos-visible-in-window-p)
6773           (forward-line (/ (static-if (featurep 'xemacs)
6774                                (window-displayed-height)
6775                              (1- (window-height)))
6776                            -2))
6777           (set-window-start (selected-window) (point))
6778           (goto-char group-point)))
6779       ;; Clear the current group name.
6780       (unless quit-config
6781         (setq gnus-newsgroup-name nil)))))
6782
6783 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6784 (defun gnus-summary-exit-no-update (&optional no-questions)
6785   "Quit reading current newsgroup without updating read article info."
6786   (interactive)
6787   (let* ((group gnus-newsgroup-name)
6788          (gnus-group-is-exiting-p t)
6789          (gnus-group-is-exiting-without-update-p t)
6790          (quit-config (gnus-group-quit-config group)))
6791     (when (or no-questions
6792               gnus-expert-user
6793               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6794       (gnus-async-halt-prefetch)
6795       (run-hooks 'gnus-summary-prepare-exit-hook)
6796       ;; If we have several article buffers, we kill them at exit.
6797       (unless gnus-single-article-buffer
6798         (gnus-kill-buffer gnus-article-buffer)
6799         (gnus-kill-buffer gnus-original-article-buffer)
6800         (setq gnus-article-current nil))
6801       (if (not gnus-kill-summary-on-exit)
6802           (gnus-deaden-summary)
6803         (gnus-close-group group)
6804         (gnus-summary-clear-local-variables)
6805         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6806           (gnus-summary-clear-local-variables))
6807         (gnus-kill-buffer gnus-summary-buffer))
6808       (unless gnus-single-article-buffer
6809         (setq gnus-article-current nil))
6810       (when gnus-use-trees
6811         (gnus-tree-close group))
6812       (gnus-async-prefetch-remove-group group)
6813       (when (get-buffer gnus-article-buffer)
6814         (bury-buffer gnus-article-buffer))
6815       ;; Return to the group buffer.
6816       (gnus-configure-windows 'group 'force)
6817       ;; Clear the current group name.
6818       (setq gnus-newsgroup-name nil)
6819       (unless (gnus-ephemeral-group-p group)
6820         (gnus-group-update-group group))
6821       (when (equal (gnus-group-group-name) group)
6822         (gnus-group-next-unread-group 1))
6823       (when quit-config
6824         (gnus-handle-ephemeral-exit quit-config)))))
6825
6826 (defun gnus-handle-ephemeral-exit (quit-config)
6827   "Handle movement when leaving an ephemeral group.
6828 The state which existed when entering the ephemeral is reset."
6829   (if (not (buffer-name (car quit-config)))
6830       (gnus-configure-windows 'group 'force)
6831     (set-buffer (car quit-config))
6832     (cond ((eq major-mode 'gnus-summary-mode)
6833            (gnus-set-global-variables))
6834           ((eq major-mode 'gnus-article-mode)
6835            (save-excursion
6836              ;; The `gnus-summary-buffer' variable may point
6837              ;; to the old summary buffer when using a single
6838              ;; article buffer.
6839              (unless (gnus-buffer-live-p gnus-summary-buffer)
6840                (set-buffer gnus-group-buffer))
6841              (set-buffer gnus-summary-buffer)
6842              (gnus-set-global-variables))))
6843     (if (or (eq (cdr quit-config) 'article)
6844             (eq (cdr quit-config) 'pick))
6845         (progn
6846           ;; The current article may be from the ephemeral group
6847           ;; thus it is best that we reload this article
6848           ;;
6849           ;; If we're exiting from a large digest, this can be
6850           ;; extremely slow.  So, it's better not to reload it. -- jh.
6851           ;;(gnus-summary-show-article)
6852           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6853               (gnus-configure-windows 'pick 'force)
6854             (gnus-configure-windows (cdr quit-config) 'force)))
6855       (gnus-configure-windows (cdr quit-config) 'force))
6856     (when (eq major-mode 'gnus-summary-mode)
6857       (gnus-summary-next-subject 1 nil t)
6858       (gnus-summary-recenter)
6859       (gnus-summary-position-point))))
6860
6861 (defun gnus-summary-preview-mime-message ()
6862   "MIME decode and play this message."
6863   (interactive)
6864   (let ((gnus-break-pages nil)
6865         (gnus-show-mime t))
6866     (gnus-summary-select-article gnus-show-all-headers t))
6867   (let ((w (get-buffer-window gnus-article-buffer)))
6868     (when w
6869       (select-window (get-buffer-window gnus-article-buffer)))))
6870
6871 ;;; Dead summaries.
6872
6873 (defvar gnus-dead-summary-mode-map nil)
6874
6875 (unless gnus-dead-summary-mode-map
6876   (setq gnus-dead-summary-mode-map (make-keymap))
6877   (suppress-keymap gnus-dead-summary-mode-map)
6878   (substitute-key-definition
6879    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6880   (dolist (key '("\C-d" "\r" "\177" [delete]))
6881     (define-key gnus-dead-summary-mode-map
6882       key 'gnus-summary-wake-up-the-dead))
6883   (dolist (key '("q" "Q"))
6884     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6885
6886 (defvar gnus-dead-summary-mode nil
6887   "Minor mode for Gnus summary buffers.")
6888
6889 (defun gnus-dead-summary-mode (&optional arg)
6890   "Minor mode for Gnus summary buffers."
6891   (interactive "P")
6892   (when (eq major-mode 'gnus-summary-mode)
6893     (make-local-variable 'gnus-dead-summary-mode)
6894     (setq gnus-dead-summary-mode
6895           (if (null arg) (not gnus-dead-summary-mode)
6896             (> (prefix-numeric-value arg) 0)))
6897     (when gnus-dead-summary-mode
6898       (add-minor-mode
6899        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6900
6901 (defun gnus-deaden-summary ()
6902   "Make the current summary buffer into a dead summary buffer."
6903   ;; Kill any previous dead summary buffer.
6904   (when (and gnus-dead-summary
6905              (buffer-name gnus-dead-summary))
6906     (with-current-buffer gnus-dead-summary
6907       (when gnus-dead-summary-mode
6908         (kill-buffer (current-buffer)))))
6909   ;; Make this the current dead summary.
6910   (setq gnus-dead-summary (current-buffer))
6911   (gnus-dead-summary-mode 1)
6912   (let ((name (buffer-name)))
6913     (when (string-match "Summary" name)
6914       (rename-buffer
6915        (concat (substring name 0 (match-beginning 0)) "Dead "
6916                (substring name (match-beginning 0)))
6917        t)
6918       (bury-buffer))))
6919
6920 (defun gnus-kill-or-deaden-summary (buffer)
6921   "Kill or deaden the summary BUFFER."
6922   (save-excursion
6923     (when (and (buffer-name buffer)
6924                (not gnus-single-article-buffer))
6925       (with-current-buffer buffer
6926         (gnus-kill-buffer gnus-article-buffer)
6927         (gnus-kill-buffer gnus-original-article-buffer)))
6928     (cond
6929      ;; Kill the buffer.
6930      (gnus-kill-summary-on-exit
6931       (when (and gnus-use-trees
6932                  (gnus-buffer-exists-p buffer))
6933         (save-excursion
6934           (set-buffer buffer)
6935           (gnus-tree-close gnus-newsgroup-name)))
6936       (gnus-kill-buffer buffer))
6937      ;; Deaden the buffer.
6938      ((gnus-buffer-exists-p buffer)
6939       (save-excursion
6940         (set-buffer buffer)
6941         (gnus-deaden-summary))))))
6942
6943 (defun gnus-summary-wake-up-the-dead (&rest args)
6944   "Wake up the dead summary buffer."
6945   (interactive)
6946   (gnus-dead-summary-mode -1)
6947   (let ((name (buffer-name)))
6948     (when (string-match "Dead " name)
6949       (rename-buffer
6950        (concat (substring name 0 (match-beginning 0))
6951                (substring name (match-end 0)))
6952        t)))
6953   (gnus-message 3 "This dead summary is now alive again"))
6954
6955 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6956 (defun gnus-summary-fetch-faq (&optional faq-dir)
6957   "Fetch the FAQ for the current group.
6958 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6959 in."
6960   (interactive
6961    (list
6962     (when current-prefix-arg
6963       (completing-read
6964        "FAQ dir: " (and (listp gnus-group-faq-directory)
6965                         (mapcar 'list
6966                                 gnus-group-faq-directory))))))
6967   (let (gnus-faq-buffer)
6968     (when (setq gnus-faq-buffer
6969                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6970       (gnus-configure-windows 'summary-faq))))
6971
6972 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6973 (defun gnus-summary-describe-group (&optional force)
6974   "Describe the current newsgroup."
6975   (interactive "P")
6976   (gnus-group-describe-group force gnus-newsgroup-name))
6977
6978 (defun gnus-summary-describe-briefly ()
6979   "Describe summary mode commands briefly."
6980   (interactive)
6981   (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")))
6982
6983 ;; Walking around group mode buffer from summary mode.
6984
6985 (defun gnus-summary-next-group (&optional no-article target-group backward)
6986   "Exit current newsgroup and then select next unread newsgroup.
6987 If prefix argument NO-ARTICLE is non-nil, no article is selected
6988 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6989 previous group instead."
6990   (interactive "P")
6991   ;; Stop pre-fetching.
6992   (gnus-async-halt-prefetch)
6993   (let ((current-group gnus-newsgroup-name)
6994         (current-buffer (current-buffer))
6995         entered)
6996     ;; First we semi-exit this group to update Xrefs and all variables.
6997     ;; We can't do a real exit, because the window conf must remain
6998     ;; the same in case the user is prompted for info, and we don't
6999     ;; want the window conf to change before that...
7000     (gnus-summary-exit t)
7001     (while (not entered)
7002       ;; Then we find what group we are supposed to enter.
7003       (set-buffer gnus-group-buffer)
7004       (gnus-group-jump-to-group current-group)
7005       (setq target-group
7006             (or target-group
7007                 (if (eq gnus-keep-same-level 'best)
7008                     (gnus-summary-best-group gnus-newsgroup-name)
7009                   (gnus-summary-search-group backward gnus-keep-same-level))))
7010       (if (not target-group)
7011           ;; There are no further groups, so we return to the group
7012           ;; buffer.
7013           (progn
7014             (gnus-message 5 "Returning to the group buffer")
7015             (setq entered t)
7016             (when (gnus-buffer-live-p current-buffer)
7017               (set-buffer current-buffer)
7018               (gnus-summary-exit))
7019             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7020         ;; We try to enter the target group.
7021         (gnus-group-jump-to-group target-group)
7022         (let ((unreads (gnus-group-group-unread)))
7023           (if (and (or (eq t unreads)
7024                        (and unreads (not (zerop unreads))))
7025                    (gnus-summary-read-group
7026                     target-group nil no-article
7027                     (and (buffer-name current-buffer) current-buffer)
7028                     nil backward))
7029               (setq entered t)
7030             (setq current-group target-group
7031                   target-group nil)))))))
7032
7033 (defun gnus-summary-prev-group (&optional no-article)
7034   "Exit current newsgroup and then select previous unread newsgroup.
7035 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7036   (interactive "P")
7037   (gnus-summary-next-group no-article nil t))
7038
7039 ;; Walking around summary lines.
7040
7041 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7042   "Go to the first subject satisfying any non-nil constraint.
7043 If UNREAD is non-nil, the article should be unread.
7044 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7045 If UNSEEN is non-nil, the article should be unseen.
7046 Returns the article selected or nil if there are no matching articles."
7047   (interactive "P")
7048   (cond
7049    ;; Empty summary.
7050    ((null gnus-newsgroup-data)
7051     (gnus-message 3 "No articles in the group")
7052     nil)
7053    ;; Pick the first article.
7054    ((not (or unread undownloaded unseen))
7055     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7056     (gnus-data-number (car gnus-newsgroup-data)))
7057    ;; Find the first unread article.
7058    (t
7059     (let ((data gnus-newsgroup-data))
7060       (while (and data
7061                   (let ((num (gnus-data-number (car data))))
7062                     (or (memq num gnus-newsgroup-unfetched)
7063                         (not (or (and unread
7064                                       (memq num gnus-newsgroup-unreads))
7065                                  (and undownloaded
7066                                       (memq num gnus-newsgroup-undownloaded))
7067                                  (and unseen
7068                                       (memq num gnus-newsgroup-unseen)))))))
7069         (setq data (cdr data)))
7070       (prog1
7071           (if data
7072               (progn
7073                 (goto-char (gnus-data-pos (car data)))
7074                 (gnus-data-number (car data)))
7075             (gnus-message 3 "No more%s articles"
7076                           (let* ((r (when unread " unread"))
7077                                  (d (when undownloaded " undownloaded"))
7078                                  (s (when unseen " unseen"))
7079                                  (l (delq nil (list r d s))))
7080                             (cond ((= 3 (length l))
7081                                    (concat r "," d ", or" s))
7082                                   ((= 2 (length l))
7083                                    (concat (car l) ", or" (cadr l)))
7084                                   ((= 1 (length l))
7085                                    (car l))
7086                                   (t
7087                                    ""))))
7088             nil
7089             )
7090         (gnus-summary-position-point))))))
7091
7092 (defun gnus-summary-next-subject (n &optional unread dont-display)
7093   "Go to next N'th summary line.
7094 If N is negative, go to the previous N'th subject line.
7095 If UNREAD is non-nil, only unread articles are selected.
7096 The difference between N and the actual number of steps taken is
7097 returned."
7098   (interactive "p")
7099   (let ((backward (< n 0))
7100         (n (abs n)))
7101     (while (and (> n 0)
7102                 (if backward
7103                     (gnus-summary-find-prev unread)
7104                   (gnus-summary-find-next unread)))
7105       (unless (zerop (setq n (1- n)))
7106         (gnus-summary-show-thread)))
7107     (when (/= 0 n)
7108       (gnus-message 7 "No more%s articles"
7109                     (if unread " unread" "")))
7110     (unless dont-display
7111       (gnus-summary-recenter)
7112       (gnus-summary-position-point))
7113     n))
7114
7115 (defun gnus-summary-next-unread-subject (n)
7116   "Go to next N'th unread summary line."
7117   (interactive "p")
7118   (gnus-summary-next-subject n t))
7119
7120 (defun gnus-summary-prev-subject (n &optional unread)
7121   "Go to previous N'th summary line.
7122 If optional argument UNREAD is non-nil, only unread article is selected."
7123   (interactive "p")
7124   (gnus-summary-next-subject (- n) unread))
7125
7126 (defun gnus-summary-prev-unread-subject (n)
7127   "Go to previous N'th unread summary line."
7128   (interactive "p")
7129   (gnus-summary-next-subject (- n) t))
7130
7131 (defun gnus-summary-goto-subjects (articles)
7132   "Insert the subject header for ARTICLES in the current buffer."
7133   (save-excursion
7134     (dolist (article articles)
7135       (gnus-summary-goto-subject article t)))
7136   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7137   (gnus-summary-position-point))
7138
7139 (defun gnus-summary-goto-subject (article &optional force silent)
7140   "Go the subject line of ARTICLE.
7141 If FORCE, also allow jumping to articles not currently shown."
7142   (interactive "nArticle number: ")
7143   (unless (numberp article)
7144     (error "Article %s is not a number" article))
7145   (let ((b (point))
7146         (data (gnus-data-find article)))
7147     ;; We read in the article if we have to.
7148     (and (not data)
7149          force
7150          (gnus-summary-insert-subject
7151           article
7152           (if (or (numberp force) (vectorp force)) force)
7153           t)
7154          (setq data (gnus-data-find article)))
7155     (goto-char b)
7156     (if (not data)
7157         (progn
7158           (unless silent
7159             (gnus-message 3 "Can't find article %d" article))
7160           nil)
7161       (let ((pt (gnus-data-pos data)))
7162         (goto-char pt)
7163         (gnus-summary-set-article-display-arrow pt))
7164       (gnus-summary-position-point)
7165       article)))
7166
7167 ;; Walking around summary lines with displaying articles.
7168
7169 (defun gnus-summary-expand-window (&optional arg)
7170   "Make the summary buffer take up the entire Emacs frame.
7171 Given a prefix, will force an `article' buffer configuration."
7172   (interactive "P")
7173   (if arg
7174       (gnus-configure-windows 'article 'force)
7175     (gnus-configure-windows 'summary 'force)))
7176
7177 (defun gnus-summary-display-article (article &optional all-header)
7178   "Display ARTICLE in article buffer."
7179   (when (gnus-buffer-live-p gnus-article-buffer)
7180     (with-current-buffer gnus-article-buffer
7181       (set-buffer-multibyte t)))
7182   (gnus-set-global-variables)
7183   (when (gnus-buffer-live-p gnus-article-buffer)
7184     (with-current-buffer gnus-article-buffer
7185       (setq gnus-article-charset gnus-newsgroup-charset)
7186       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7187       (set-buffer-multibyte t)))
7188   (if (null article)
7189       nil
7190     (prog1
7191         (if gnus-summary-display-article-function
7192             (funcall gnus-summary-display-article-function article all-header)
7193           (gnus-article-prepare article all-header))
7194       (with-current-buffer gnus-article-buffer
7195         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7196              nil))
7197       (gnus-run-hooks 'gnus-select-article-hook)
7198       (when (and gnus-current-article
7199                  (not (zerop gnus-current-article)))
7200         (gnus-summary-goto-subject gnus-current-article))
7201       (gnus-summary-recenter)
7202       (when (and gnus-use-trees gnus-show-threads)
7203         (gnus-possibly-generate-tree article)
7204         (gnus-highlight-selected-tree article))
7205       ;; Successfully display article.
7206       (gnus-article-set-window-start
7207        (cdr (assq article gnus-newsgroup-bookmarks))))))
7208
7209 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7210   "Select the current article.
7211 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7212 non-nil, the article will be re-fetched even if it already present in
7213 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7214 be displayed."
7215   ;; Make sure we are in the summary buffer to work around bbdb bug.
7216   (unless (eq major-mode 'gnus-summary-mode)
7217     (set-buffer gnus-summary-buffer))
7218   (let ((article (or article (gnus-summary-article-number)))
7219         (all-headers (not (not all-headers))) ;Must be T or NIL.
7220         gnus-summary-display-article-function)
7221     (and (not pseudo)
7222          (gnus-summary-article-pseudo-p article)
7223          (error "This is a pseudo-article"))
7224     (save-excursion
7225       (set-buffer gnus-summary-buffer)
7226       (if (or (and gnus-single-article-buffer
7227                    (or (null gnus-current-article)
7228                        (null gnus-article-current)
7229                        (null (get-buffer gnus-article-buffer))
7230                        (not (eq article (cdr gnus-article-current)))
7231                        (not (equal (car gnus-article-current)
7232                                    gnus-newsgroup-name))))
7233               (and (not gnus-single-article-buffer)
7234                    (or (null gnus-current-article)
7235                        (not (eq gnus-current-article article))))
7236               force)
7237           ;; The requested article is different from the current article.
7238           (progn
7239             (gnus-summary-display-article article all-headers)
7240             (gnus-article-set-window-start
7241              (cdr (assq article gnus-newsgroup-bookmarks)))
7242             article)
7243         'old))))
7244
7245 (defun gnus-summary-force-verify-and-decrypt ()
7246   "Display buttons for signed/encrypted parts and verify/decrypt them."
7247   (interactive)
7248   (let ((mm-verify-option 'known)
7249         (mm-decrypt-option 'known)
7250         (gnus-article-emulate-mime t)
7251         (gnus-buttonized-mime-types (append (list "multipart/signed"
7252                                                   "multipart/encrypted")
7253                                             gnus-buttonized-mime-types)))
7254     (gnus-summary-select-article nil 'force)))
7255
7256 (defun gnus-summary-set-current-mark (&optional current-mark)
7257   "Obsolete function."
7258   nil)
7259
7260 (defun gnus-summary-next-article (&optional unread subject backward push)
7261   "Select the next article.
7262 If UNREAD, only unread articles are selected.
7263 If SUBJECT, only articles with SUBJECT are selected.
7264 If BACKWARD, the previous article is selected instead of the next."
7265   (interactive "P")
7266   (cond
7267    ;; Is there such an article?
7268    ((and (gnus-summary-search-forward unread subject backward)
7269          (or (gnus-summary-display-article (gnus-summary-article-number))
7270              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7271     (gnus-summary-position-point))
7272    ;; If not, we try the first unread, if that is wanted.
7273    ((and subject
7274          gnus-auto-select-same
7275          (gnus-summary-first-unread-article))
7276     (gnus-summary-position-point)
7277     (gnus-message 6 "Wrapped"))
7278    ;; Try to get next/previous article not displayed in this group.
7279    ((and gnus-auto-extend-newsgroup
7280          (not unread) (not subject))
7281     (gnus-summary-goto-article
7282      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7283      nil (count-lines (point-min) (point))))
7284    ;; Go to next/previous group.
7285    (t
7286     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7287       (gnus-summary-jump-to-group gnus-newsgroup-name))
7288     (let ((cmd last-command-char)
7289           (point
7290            (with-current-buffer gnus-group-buffer
7291              (point)))
7292           (group
7293            (if (eq gnus-keep-same-level 'best)
7294                (gnus-summary-best-group gnus-newsgroup-name)
7295              (gnus-summary-search-group backward gnus-keep-same-level))))
7296       ;; For some reason, the group window gets selected.  We change
7297       ;; it back.
7298       (select-window (get-buffer-window (current-buffer)))
7299       ;; Select next unread newsgroup automagically.
7300       (cond
7301        ((or (not gnus-auto-select-next)
7302             (not cmd))
7303         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7304        ((or (eq gnus-auto-select-next 'quietly)
7305             (and (eq gnus-auto-select-next 'slightly-quietly)
7306                  push)
7307             (and (eq gnus-auto-select-next 'almost-quietly)
7308                  (gnus-summary-last-article-p)))
7309         ;; Select quietly.
7310         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7311             (gnus-summary-exit)
7312           (gnus-message 7 "No more%s articles (%s)..."
7313                         (if unread " unread" "")
7314                         (if group (concat "selecting " group)
7315                           "exiting"))
7316           (gnus-summary-next-group nil group backward)))
7317        (t
7318         (when (gnus-key-press-event-p last-input-event)
7319           (gnus-summary-walk-group-buffer
7320            gnus-newsgroup-name cmd unread backward point))))))))
7321
7322 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7323   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7324                       (?\C-p (gnus-group-prev-unread-group 1))))
7325         (cursor-in-echo-area t)
7326         keve key group ended prompt)
7327     (save-excursion
7328       (set-buffer gnus-group-buffer)
7329       (goto-char start)
7330       (setq group
7331             (if (eq gnus-keep-same-level 'best)
7332                 (gnus-summary-best-group gnus-newsgroup-name)
7333               (gnus-summary-search-group backward gnus-keep-same-level))))
7334     (while (not ended)
7335       (setq prompt
7336             (format
7337              "No more%s articles%s " (if unread " unread" "")
7338              (if (and group
7339                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7340                  (format " (Type %s for %s [%s])"
7341                          (single-key-description cmd)
7342                          (gnus-group-decoded-name group)
7343                          (gnus-group-unread group))
7344                (format " (Type %s to exit %s)"
7345                        (single-key-description cmd)
7346                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7347       ;; Confirm auto selection.
7348       (setq key (car (setq keve (gnus-read-event-char prompt)))
7349             ended t)
7350       (cond
7351        ((assq key keystrokes)
7352         (let ((obuf (current-buffer)))
7353           (switch-to-buffer gnus-group-buffer)
7354           (when group
7355             (gnus-group-jump-to-group group))
7356           (eval (cadr (assq key keystrokes)))
7357           (setq group (gnus-group-group-name))
7358           (switch-to-buffer obuf))
7359         (setq ended nil))
7360        ((equal key cmd)
7361         (if (or (not group)
7362                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7363             (gnus-summary-exit)
7364           (gnus-summary-next-group nil group backward)))
7365        (t
7366         (push (cdr keve) unread-command-events))))))
7367
7368 (defun gnus-summary-next-unread-article ()
7369   "Select unread article after current one."
7370   (interactive)
7371   (gnus-summary-next-article
7372    (or (not (eq gnus-summary-goto-unread 'never))
7373        (gnus-summary-last-article-p (gnus-summary-article-number)))
7374    (and gnus-auto-select-same
7375         (gnus-summary-article-subject))))
7376
7377 (defun gnus-summary-prev-article (&optional unread subject)
7378   "Select the article after the current one.
7379 If UNREAD is non-nil, only unread articles are selected."
7380   (interactive "P")
7381   (gnus-summary-next-article unread subject t))
7382
7383 (defun gnus-summary-prev-unread-article ()
7384   "Select unread article before current one."
7385   (interactive)
7386   (gnus-summary-prev-article
7387    (or (not (eq gnus-summary-goto-unread 'never))
7388        (gnus-summary-first-article-p (gnus-summary-article-number)))
7389    (and gnus-auto-select-same
7390         (gnus-summary-article-subject))))
7391
7392 (defun gnus-summary-next-page (&optional lines circular stop)
7393   "Show next page of the selected article.
7394 If at the end of the current article, select the next article.
7395 LINES says how many lines should be scrolled up.
7396
7397 If CIRCULAR is non-nil, go to the start of the article instead of
7398 selecting the next article when reaching the end of the current
7399 article.
7400
7401 If STOP is non-nil, just stop when reaching the end of the message.
7402
7403 Also see the variable `gnus-article-skip-boring'."
7404   (interactive "P")
7405   (setq gnus-summary-buffer (current-buffer))
7406   (gnus-set-global-variables)
7407   (let ((article (gnus-summary-article-number))
7408         (article-window (get-buffer-window gnus-article-buffer t))
7409         endp)
7410     ;; If the buffer is empty, we have no article.
7411     (unless article
7412       (error "No article to select"))
7413     (gnus-configure-windows 'article)
7414     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7415         (if (and (eq gnus-summary-goto-unread 'never)
7416                  (not (gnus-summary-last-article-p article)))
7417             (gnus-summary-next-article)
7418           (gnus-summary-next-unread-article))
7419       (if (or (null gnus-current-article)
7420               (null gnus-article-current)
7421               (/= article (cdr gnus-article-current))
7422               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7423           ;; Selected subject is different from current article's.
7424           (gnus-summary-display-article article)
7425         (when article-window
7426           (gnus-eval-in-buffer-window gnus-article-buffer
7427             (setq endp (or (gnus-article-next-page lines)
7428                            (gnus-article-only-boring-p))))
7429           (when endp
7430             (cond (stop
7431                    (gnus-message 3 "End of message"))
7432                   (circular
7433                    (gnus-summary-beginning-of-article))
7434                   (lines
7435                    (gnus-message 3 "End of message"))
7436                   ((null lines)
7437                    (if (and (eq gnus-summary-goto-unread 'never)
7438                             (not (gnus-summary-last-article-p article)))
7439                        (gnus-summary-next-article)
7440                      (gnus-summary-next-unread-article))))))))
7441     (gnus-summary-recenter)
7442     (gnus-summary-position-point)))
7443
7444 (defun gnus-summary-prev-page (&optional lines move)
7445   "Show previous page of selected article.
7446 Argument LINES specifies lines to be scrolled down.
7447 If MOVE, move to the previous unread article if point is at
7448 the beginning of the buffer."
7449   (interactive "P")
7450   (let ((article (gnus-summary-article-number))
7451         (article-window (get-buffer-window gnus-article-buffer t))
7452         endp)
7453     (gnus-configure-windows 'article)
7454     (if (or (null gnus-current-article)
7455             (null gnus-article-current)
7456             (/= article (cdr gnus-article-current))
7457             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7458         ;; Selected subject is different from current article's.
7459         (gnus-summary-display-article article)
7460       (gnus-summary-recenter)
7461       (when article-window
7462         (gnus-eval-in-buffer-window gnus-article-buffer
7463           (setq endp (gnus-article-prev-page lines)))
7464         (when (and move endp)
7465           (cond (lines
7466                  (gnus-message 3 "Beginning of message"))
7467                 ((null lines)
7468                  (if (and (eq gnus-summary-goto-unread 'never)
7469                           (not (gnus-summary-first-article-p article)))
7470                      (gnus-summary-prev-article)
7471                    (gnus-summary-prev-unread-article))))))))
7472   (gnus-summary-position-point))
7473
7474 (defun gnus-summary-prev-page-or-article (&optional lines)
7475   "Show previous page of selected article.
7476 Argument LINES specifies lines to be scrolled down.
7477 If at the beginning of the article, go to the next article."
7478   (interactive "P")
7479   (gnus-summary-prev-page lines t))
7480
7481 (defun gnus-summary-scroll-up (lines)
7482   "Scroll up (or down) one line current article.
7483 Argument LINES specifies lines to be scrolled up (or down if negative)."
7484   (interactive "p")
7485   (gnus-configure-windows 'article)
7486   (gnus-summary-show-thread)
7487   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7488     (gnus-eval-in-buffer-window gnus-article-buffer
7489       (cond ((> lines 0)
7490              (when (gnus-article-next-page lines)
7491                (gnus-message 3 "End of message")))
7492             ((< lines 0)
7493              (gnus-article-prev-page (- lines))))))
7494   (gnus-summary-recenter)
7495   (gnus-summary-position-point))
7496
7497 (defun gnus-summary-scroll-down (lines)
7498   "Scroll down (or up) one line current article.
7499 Argument LINES specifies lines to be scrolled down (or up if negative)."
7500   (interactive "p")
7501   (gnus-summary-scroll-up (- lines)))
7502
7503 (defun gnus-summary-next-same-subject ()
7504   "Select next article which has the same subject as current one."
7505   (interactive)
7506   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7507
7508 (defun gnus-summary-prev-same-subject ()
7509   "Select previous article which has the same subject as current one."
7510   (interactive)
7511   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7512
7513 (defun gnus-summary-next-unread-same-subject ()
7514   "Select next unread article which has the same subject as current one."
7515   (interactive)
7516   (gnus-summary-next-article t (gnus-summary-article-subject)))
7517
7518 (defun gnus-summary-prev-unread-same-subject ()
7519   "Select previous unread article which has the same subject as current one."
7520   (interactive)
7521   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7522
7523 (defun gnus-summary-first-unread-article ()
7524   "Select the first unread article.
7525 Return nil if there are no unread articles."
7526   (interactive)
7527   (prog1
7528       (when (gnus-summary-first-subject t)
7529         (gnus-summary-show-thread)
7530         (gnus-summary-first-subject t)
7531         (gnus-summary-display-article (gnus-summary-article-number)))
7532     (gnus-summary-position-point)))
7533
7534 (defun gnus-summary-first-unread-subject ()
7535   "Place the point on the subject line of the first unread article.
7536 Return nil if there are no unread articles."
7537   (interactive)
7538   (prog1
7539       (when (gnus-summary-first-subject t)
7540         (gnus-summary-show-thread)
7541         (gnus-summary-first-subject t))
7542     (gnus-summary-position-point)))
7543
7544 (defun gnus-summary-first-unseen-subject ()
7545   "Place the point on the subject line of the first unseen article.
7546 Return nil if there are no unseen articles."
7547   (interactive)
7548   (prog1
7549       (when (gnus-summary-first-subject nil nil t)
7550         (gnus-summary-show-thread)
7551         (gnus-summary-first-subject nil nil t))
7552     (gnus-summary-position-point)))
7553
7554 (defun gnus-summary-first-unseen-or-unread-subject ()
7555   "Place the point on the subject line of the first unseen article or,
7556 if all article have been seen, on the subject line of the first unread
7557 article."
7558   (interactive)
7559   (prog1
7560       (unless (when (gnus-summary-first-subject nil nil t)
7561                 (gnus-summary-show-thread)
7562                 (gnus-summary-first-subject nil nil t))
7563         (when (gnus-summary-first-subject t)
7564           (gnus-summary-show-thread)
7565           (gnus-summary-first-subject t)))
7566     (gnus-summary-position-point)))
7567
7568 (defun gnus-summary-first-article ()
7569   "Select the first article.
7570 Return nil if there are no articles."
7571   (interactive)
7572   (prog1
7573       (when (gnus-summary-first-subject)
7574         (gnus-summary-show-thread)
7575         (gnus-summary-first-subject)
7576         (gnus-summary-display-article (gnus-summary-article-number)))
7577     (gnus-summary-position-point)))
7578
7579 (defun gnus-summary-best-unread-article (&optional arg)
7580   "Select the unread article with the highest score.
7581 If given a prefix argument, select the next unread article that has a
7582 score higher than the default score."
7583   (interactive "P")
7584   (let ((article (if arg
7585                      (gnus-summary-better-unread-subject)
7586                    (gnus-summary-best-unread-subject))))
7587     (if article
7588         (gnus-summary-goto-article article)
7589       (error "No unread articles"))))
7590
7591 (defun gnus-summary-best-unread-subject ()
7592   "Select the unread subject with the highest score."
7593   (interactive)
7594   (let ((best -1000000)
7595         (data gnus-newsgroup-data)
7596         article score)
7597     (while data
7598       (and (gnus-data-unread-p (car data))
7599            (> (setq score
7600                     (gnus-summary-article-score (gnus-data-number (car data))))
7601               best)
7602            (setq best score
7603                  article (gnus-data-number (car data))))
7604       (setq data (cdr data)))
7605     (when article
7606       (gnus-summary-goto-subject article))
7607     (gnus-summary-position-point)
7608     article))
7609
7610 (defun gnus-summary-better-unread-subject ()
7611   "Select the first unread subject that has a score over the default score."
7612   (interactive)
7613   (let ((data gnus-newsgroup-data)
7614         article score)
7615     (while (and (setq article (gnus-data-number (car data)))
7616                 (or (gnus-data-read-p (car data))
7617                     (not (> (gnus-summary-article-score article)
7618                             gnus-summary-default-score))))
7619       (setq data (cdr data)))
7620     (when article
7621       (gnus-summary-goto-subject article))
7622     (gnus-summary-position-point)
7623     article))
7624
7625 (defun gnus-summary-last-subject ()
7626   "Go to the last displayed subject line in the group."
7627   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7628     (when article
7629       (gnus-summary-goto-subject article))))
7630
7631 (defun gnus-summary-goto-article (article &optional all-headers force)
7632   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7633 If ALL-HEADERS is non-nil, no header lines are hidden.
7634 If FORCE, go to the article even if it isn't displayed.  If FORCE
7635 is a number, it is the line the article is to be displayed on."
7636   (interactive
7637    (list
7638     (completing-read
7639      "Article number or Message-ID: "
7640      (mapcar (lambda (number) (list (int-to-string number)))
7641              gnus-newsgroup-limit))
7642     current-prefix-arg
7643     t))
7644   (prog1
7645       (if (and (stringp article)
7646                (string-match "@\\|%40" article))
7647           (gnus-summary-refer-article article)
7648         (when (stringp article)
7649           (setq article (string-to-number article)))
7650         (if (gnus-summary-goto-subject article force)
7651             (gnus-summary-display-article article all-headers)
7652           (gnus-message 4 "Couldn't go to article %s" article) nil))
7653     (gnus-summary-position-point)))
7654
7655 (defun gnus-summary-goto-last-article ()
7656   "Go to the previously read article."
7657   (interactive)
7658   (prog1
7659       (when gnus-last-article
7660         (gnus-summary-goto-article gnus-last-article nil t))
7661     (gnus-summary-position-point)))
7662
7663 (defun gnus-summary-pop-article (number)
7664   "Pop one article off the history and go to the previous.
7665 NUMBER articles will be popped off."
7666   (interactive "p")
7667   (let (to)
7668     (setq gnus-newsgroup-history
7669           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7670     (if to
7671         (gnus-summary-goto-article (car to) nil t)
7672       (error "Article history empty")))
7673   (gnus-summary-position-point))
7674
7675 ;; Summary commands and functions for limiting the summary buffer.
7676
7677 (defun gnus-summary-limit-to-articles (n)
7678   "Limit the summary buffer to the next N articles.
7679 If not given a prefix, use the process marked articles instead."
7680   (interactive "P")
7681   (prog1
7682       (let ((articles (gnus-summary-work-articles n)))
7683         (setq gnus-newsgroup-processable nil)
7684         (gnus-summary-limit articles))
7685     (gnus-summary-position-point)))
7686
7687 (defun gnus-summary-pop-limit (&optional total)
7688   "Restore the previous limit.
7689 If given a prefix, remove all limits."
7690   (interactive "P")
7691   (when total
7692     (setq gnus-newsgroup-limits
7693           (list (mapcar (lambda (h) (mail-header-number h))
7694                         gnus-newsgroup-headers))))
7695   (unless gnus-newsgroup-limits
7696     (error "No limit to pop"))
7697   (prog1
7698       (gnus-summary-limit nil 'pop)
7699     (gnus-summary-position-point)))
7700
7701 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7702   "Limit the summary buffer to articles that have subjects that match a regexp.
7703 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7704   (interactive
7705    (list (read-string (if current-prefix-arg
7706                           "Exclude subject (regexp): "
7707                         "Limit to subject (regexp): "))
7708          nil current-prefix-arg))
7709   (unless header
7710     (setq header "subject"))
7711   (when (not (equal "" subject))
7712     (prog1
7713         (let ((articles (gnus-summary-find-matching
7714                          (or header "subject") subject 'all nil nil
7715                          not-matching)))
7716           (unless articles
7717             (error "Found no matches for \"%s\"" subject))
7718           (gnus-summary-limit articles))
7719       (gnus-summary-position-point))))
7720
7721 (defun gnus-summary-limit-to-author (from &optional not-matching)
7722   "Limit the summary buffer to articles that have authors that match a regexp.
7723 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7724   (interactive
7725    (list (read-string (if current-prefix-arg
7726                           "Exclude author (regexp): "
7727                         "Limit to author (regexp): "))
7728          current-prefix-arg))
7729   (gnus-summary-limit-to-subject from "from" not-matching))
7730
7731 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7732   "Limit the summary buffer to articles with the given RECIPIENT.
7733
7734 If NOT-MATCHING, exclude RECIPIENT.
7735
7736 To and Cc headers are checked.  You need to include them in
7737 `nnmail-extra-headers'."
7738   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7739   (interactive
7740    (list (read-string (format "%s recipient (regexp): "
7741                               (if current-prefix-arg "Exclude" "Limit to")))
7742          current-prefix-arg))
7743   (when (not (equal "" recipient))
7744     (prog1 (let* ((to
7745                    (if (memq 'To nnmail-extra-headers)
7746                        (gnus-summary-find-matching
7747                         (cons 'extra 'To) recipient 'all nil nil
7748                         not-matching)
7749                      (gnus-message
7750                       1 "`To' isn't present in `nnmail-extra-headers'")
7751                      (sit-for 1)
7752                      nil))
7753                   (cc
7754                    (if (memq 'Cc nnmail-extra-headers)
7755                        (gnus-summary-find-matching
7756                         (cons 'extra 'Cc) recipient 'all nil nil
7757                         not-matching)
7758                      (gnus-message
7759                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7760                      (sit-for 1)
7761                      nil))
7762                   (articles
7763                    (if not-matching
7764                        ;; We need the numbers that are in both lists:
7765                        (mapcar (lambda (a)
7766                                  (and (memq a to) a))
7767                                cc)
7768                      (nconc to cc))))
7769              (unless articles
7770                (error "Found no matches for \"%s\"" recipient))
7771              (gnus-summary-limit articles))
7772       (gnus-summary-position-point))))
7773
7774 (defun gnus-summary-limit-to-age (age &optional younger-p)
7775   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7776 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7777 articles that are younger than AGE days."
7778   (interactive
7779    (let ((younger current-prefix-arg)
7780          (days-got nil)
7781          days)
7782      (while (not days-got)
7783        (setq days (if younger
7784                       (read-string "Limit to articles younger than (in days, older when negative): ")
7785                     (read-string
7786                      "Limit to articles older than (in days, younger when negative): ")))
7787        (when (> (length days) 0)
7788          (setq days (read days)))
7789        (if (numberp days)
7790            (progn
7791              (setq days-got t)
7792              (when (< days 0)
7793                (setq younger (not younger))
7794                (setq days (* days -1))))
7795          (message "Please enter a number.")
7796          (sleep-for 1)))
7797      (list days younger)))
7798   (prog1
7799       (let ((data gnus-newsgroup-data)
7800             (cutoff (days-to-time age))
7801             articles d date is-younger)
7802         (while (setq d (pop data))
7803           (when (and (vectorp (gnus-data-header d))
7804                      (setq date (mail-header-date (gnus-data-header d))))
7805             (setq is-younger (time-less-p
7806                               (time-since (condition-case ()
7807                                               (date-to-time date)
7808                                             (error '(0 0))))
7809                               cutoff))
7810             (when (if younger-p
7811                       is-younger
7812                     (not is-younger))
7813               (push (gnus-data-number d) articles))))
7814         (gnus-summary-limit (nreverse articles)))
7815     (gnus-summary-position-point)))
7816
7817 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7818   "Limit the summary buffer to articles that match an 'extra' header."
7819   (interactive
7820    (let ((header
7821           (intern
7822            (gnus-completing-read-with-default
7823             (symbol-name (car gnus-extra-headers))
7824             (if current-prefix-arg
7825                 "Exclude extra header"
7826               "Limit extra header")
7827             (mapcar (lambda (x)
7828                       (cons (symbol-name x) x))
7829                     gnus-extra-headers)
7830             nil
7831             t))))
7832      (list header
7833            (read-string (format "%s header %s (regexp): "
7834                                 (if current-prefix-arg "Exclude" "Limit to")
7835                                 header))
7836            current-prefix-arg)))
7837   (when (not (equal "" regexp))
7838     (prog1
7839         (let ((articles (gnus-summary-find-matching
7840                          (cons 'extra header) regexp 'all nil nil
7841                          not-matching)))
7842           (unless articles
7843             (error "Found no matches for \"%s\"" regexp))
7844           (gnus-summary-limit articles))
7845       (gnus-summary-position-point))))
7846
7847 (defun gnus-summary-limit-to-display-predicate ()
7848   "Limit the summary buffer to the predicated in the `display' group parameter."
7849   (interactive)
7850   (unless gnus-newsgroup-display
7851     (error "There is no `display' group parameter"))
7852   (let (articles)
7853     (dolist (number gnus-newsgroup-articles)
7854       (when (funcall gnus-newsgroup-display)
7855         (push number articles)))
7856     (gnus-summary-limit articles))
7857   (gnus-summary-position-point))
7858
7859 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7860 (make-obsolete
7861  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7862
7863 (defun gnus-summary-limit-to-unread (&optional all)
7864   "Limit the summary buffer to articles that are not marked as read.
7865 If ALL is non-nil, limit strictly to unread articles."
7866   (interactive "P")
7867   (if all
7868       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7869     (gnus-summary-limit-to-marks
7870      ;; Concat all the marks that say that an article is read and have
7871      ;; those removed.
7872      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7873            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7874            gnus-low-score-mark gnus-expirable-mark
7875            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7876            gnus-duplicate-mark gnus-souped-mark)
7877      'reverse)))
7878
7879 (defun gnus-summary-limit-to-replied (&optional unreplied)
7880   "Limit the summary buffer to replied articles.
7881 If UNREPLIED (the prefix), limit to unreplied articles."
7882   (interactive "P")
7883   (if unreplied
7884       (gnus-summary-limit
7885        (gnus-set-difference gnus-newsgroup-articles
7886         gnus-newsgroup-replied))
7887     (gnus-summary-limit gnus-newsgroup-replied))
7888   (gnus-summary-position-point))
7889
7890 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7891 (make-obsolete 'gnus-summary-delete-marked-with
7892                'gnus-summary-limit-exclude-marks)
7893
7894 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7895   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7896 If REVERSE, limit the summary buffer to articles that are marked
7897 with MARKS.  MARKS can either be a string of marks or a list of marks.
7898 Returns how many articles were removed."
7899   (interactive "sMarks: ")
7900   (gnus-summary-limit-to-marks marks t))
7901
7902 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7903   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7904 If REVERSE (the prefix), limit the summary buffer to articles that are
7905 not marked with MARKS.  MARKS can either be a string of marks or a
7906 list of marks.
7907 Returns how many articles were removed."
7908   (interactive "sMarks: \nP")
7909   (prog1
7910       (let ((data gnus-newsgroup-data)
7911             (marks (if (listp marks) marks
7912                      (append marks nil))) ; Transform to list.
7913             articles)
7914         (while data
7915           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7916                   (memq (gnus-data-mark (car data)) marks))
7917             (push (gnus-data-number (car data)) articles))
7918           (setq data (cdr data)))
7919         (gnus-summary-limit articles))
7920     (gnus-summary-position-point)))
7921
7922 (defun gnus-summary-limit-to-score (score)
7923   "Limit to articles with score at or above SCORE."
7924   (interactive "NLimit to articles with score of at least: ")
7925   (let ((data gnus-newsgroup-data)
7926         articles)
7927     (while data
7928       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7929                 score)
7930         (push (gnus-data-number (car data)) articles))
7931       (setq data (cdr data)))
7932     (prog1
7933         (gnus-summary-limit articles)
7934       (gnus-summary-position-point))))
7935
7936 (defun gnus-summary-limit-to-unseen ()
7937   "Limit to unseen articles."
7938   (interactive)
7939   (prog1
7940       (gnus-summary-limit gnus-newsgroup-unseen)
7941     (gnus-summary-position-point)))
7942
7943 (defun gnus-summary-limit-include-thread (id)
7944   "Display all the hidden articles that is in the thread with ID in it.
7945 When called interactively, ID is the Message-ID of the current
7946 article."
7947   (interactive (list (mail-header-id (gnus-summary-article-header))))
7948   (let ((articles (gnus-articles-in-thread
7949                    (gnus-id-to-thread (gnus-root-id id)))))
7950     (prog1
7951         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7952       (gnus-summary-limit-include-matching-articles
7953        "subject"
7954        (regexp-quote (gnus-simplify-subject-re
7955                       (mail-header-subject (gnus-id-to-header id)))))
7956       (gnus-summary-position-point))))
7957
7958 (defun gnus-summary-limit-include-matching-articles (header regexp)
7959   "Display all the hidden articles that have HEADERs that match REGEXP."
7960   (interactive (list (read-string "Match on header: ")
7961                      (read-string "Regexp: ")))
7962   (let ((articles (gnus-find-matching-articles header regexp)))
7963     (prog1
7964         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7965       (gnus-summary-position-point))))
7966
7967 (defun gnus-summary-insert-dormant-articles ()
7968   "Insert all the dormant articles for this group into the current buffer."
7969   (interactive)
7970   (let ((gnus-verbose (max 6 gnus-verbose)))
7971     (if (not gnus-newsgroup-dormant)
7972         (gnus-message 3 "No cached articles for this group")
7973       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7974
7975 (defun gnus-summary-limit-include-dormant ()
7976   "Display all the hidden articles that are marked as dormant.
7977 Note that this command only works on a subset of the articles currently
7978 fetched for this group."
7979   (interactive)
7980   (unless gnus-newsgroup-dormant
7981     (error "There are no dormant articles in this group"))
7982   (prog1
7983       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7984     (gnus-summary-position-point)))
7985
7986 (defun gnus-summary-limit-exclude-dormant ()
7987   "Hide all dormant articles."
7988   (interactive)
7989   (prog1
7990       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7991     (gnus-summary-position-point)))
7992
7993 (defun gnus-summary-limit-exclude-childless-dormant ()
7994   "Hide all dormant articles that have no children."
7995   (interactive)
7996   (let ((data (gnus-data-list t))
7997         articles d children)
7998     ;; Find all articles that are either not dormant or have
7999     ;; children.
8000     (while (setq d (pop data))
8001       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8002                 (and (setq children
8003                            (gnus-article-children (gnus-data-number d)))
8004                      (let (found)
8005                        (while children
8006                          (when (memq (car children) articles)
8007                            (setq children nil
8008                                  found t))
8009                          (pop children))
8010                        found)))
8011         (push (gnus-data-number d) articles)))
8012     ;; Do the limiting.
8013     (prog1
8014         (gnus-summary-limit articles)
8015       (gnus-summary-position-point))))
8016
8017 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8018   "Mark all unread excluded articles as read.
8019 If ALL, mark even excluded ticked and dormants as read."
8020   (interactive "P")
8021   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8022   (let ((articles (gnus-sorted-ndifference
8023                    (sort
8024                     (mapcar (lambda (h) (mail-header-number h))
8025                             gnus-newsgroup-headers)
8026                     '<)
8027                    gnus-newsgroup-limit))
8028         article)
8029     (setq gnus-newsgroup-unreads
8030           (gnus-sorted-intersection gnus-newsgroup-unreads
8031                                     gnus-newsgroup-limit))
8032     (if all
8033         (setq gnus-newsgroup-dormant nil
8034               gnus-newsgroup-marked nil
8035               gnus-newsgroup-reads
8036               (nconc
8037                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8038                gnus-newsgroup-reads))
8039       (while (setq article (pop articles))
8040         (unless (or (memq article gnus-newsgroup-dormant)
8041                     (memq article gnus-newsgroup-marked))
8042           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8043
8044 (defun gnus-summary-limit (articles &optional pop)
8045   (if pop
8046       ;; We pop the previous limit off the stack and use that.
8047       (setq articles (car gnus-newsgroup-limits)
8048             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8049     ;; We use the new limit, so we push the old limit on the stack.
8050     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8051   ;; Set the limit.
8052   (setq gnus-newsgroup-limit articles)
8053   (let ((total (length gnus-newsgroup-data))
8054         (data (gnus-data-find-list (gnus-summary-article-number)))
8055         (gnus-summary-mark-below nil)   ; Inhibit this.
8056         found)
8057     ;; This will do all the work of generating the new summary buffer
8058     ;; according to the new limit.
8059     (gnus-summary-prepare)
8060     ;; Hide any threads, possibly.
8061     (gnus-summary-maybe-hide-threads)
8062     ;; Try to return to the article you were at, or one in the
8063     ;; neighborhood.
8064     (when data
8065       ;; We try to find some article after the current one.
8066       (while data
8067         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8068           (setq data nil
8069                 found t))
8070         (setq data (cdr data))))
8071     (unless found
8072       ;; If there is no data, that means that we were after the last
8073       ;; article.  The same goes when we can't find any articles
8074       ;; after the current one.
8075       (goto-char (point-max))
8076       (gnus-summary-find-prev))
8077     (gnus-set-mode-line 'summary)
8078     ;; We return how many articles were removed from the summary
8079     ;; buffer as a result of the new limit.
8080     (- total (length gnus-newsgroup-data))))
8081
8082 (defsubst gnus-invisible-cut-children (threads)
8083   (let ((num 0))
8084     (while threads
8085       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8086         (incf num))
8087       (pop threads))
8088     (< num 2)))
8089
8090 (defsubst gnus-cut-thread (thread)
8091   "Go forwards in the thread until we find an article that we want to display."
8092   (when (or (eq gnus-fetch-old-headers 'some)
8093             (eq gnus-fetch-old-headers 'invisible)
8094             (numberp gnus-fetch-old-headers)
8095             (eq gnus-build-sparse-threads 'some)
8096             (eq gnus-build-sparse-threads 'more))
8097     ;; Deal with old-fetched headers and sparse threads.
8098     (while (and
8099             thread
8100             (or
8101              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8102              (gnus-summary-article-ancient-p
8103               (mail-header-number (car thread))))
8104             (if (or (<= (length (cdr thread)) 1)
8105                     (eq gnus-fetch-old-headers 'invisible))
8106                 (setq gnus-newsgroup-limit
8107                       (delq (mail-header-number (car thread))
8108                             gnus-newsgroup-limit)
8109                       thread (cadr thread))
8110               (when (gnus-invisible-cut-children (cdr thread))
8111                 (let ((th (cdr thread)))
8112                   (while th
8113                     (if (memq (mail-header-number (caar th))
8114                               gnus-newsgroup-limit)
8115                         (setq thread (car th)
8116                               th nil)
8117                       (setq th (cdr th))))))))))
8118   thread)
8119
8120 (defun gnus-cut-threads (threads)
8121   "Cut off all uninteresting articles from the beginning of THREADS."
8122   (when (or (eq gnus-fetch-old-headers 'some)
8123             (eq gnus-fetch-old-headers 'invisible)
8124             (numberp gnus-fetch-old-headers)
8125             (eq gnus-build-sparse-threads 'some)
8126             (eq gnus-build-sparse-threads 'more))
8127     (let ((th threads))
8128       (while th
8129         (setcar th (gnus-cut-thread (car th)))
8130         (setq th (cdr th)))))
8131   ;; Remove nixed out threads.
8132   (delq nil threads))
8133
8134 (defun gnus-summary-initial-limit (&optional show-if-empty)
8135   "Figure out what the initial limit is supposed to be on group entry.
8136 This entails weeding out unwanted dormants, low-scored articles,
8137 fetch-old-headers verbiage, and so on."
8138   ;; Most groups have nothing to remove.
8139   (if (or gnus-inhibit-limiting
8140           (and (null gnus-newsgroup-dormant)
8141                (eq gnus-newsgroup-display 'gnus-not-ignore)
8142                (not (eq gnus-fetch-old-headers 'some))
8143                (not (numberp gnus-fetch-old-headers))
8144                (not (eq gnus-fetch-old-headers 'invisible))
8145                (null gnus-summary-expunge-below)
8146                (not (eq gnus-build-sparse-threads 'some))
8147                (not (eq gnus-build-sparse-threads 'more))
8148                (null gnus-thread-expunge-below)
8149                (not gnus-use-nocem)))
8150       ()                                ; Do nothing.
8151     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8152     (setq gnus-newsgroup-limit nil)
8153     (mapatoms
8154      (lambda (node)
8155        (unless (car (symbol-value node))
8156          ;; These threads have no parents -- they are roots.
8157          (let ((nodes (cdr (symbol-value node)))
8158                thread)
8159            (while nodes
8160              (if (and gnus-thread-expunge-below
8161                       (< (gnus-thread-total-score (car nodes))
8162                          gnus-thread-expunge-below))
8163                  (gnus-expunge-thread (pop nodes))
8164                (setq thread (pop nodes))
8165                (gnus-summary-limit-children thread))))))
8166      gnus-newsgroup-dependencies)
8167     ;; If this limitation resulted in an empty group, we might
8168     ;; pop the previous limit and use it instead.
8169     (when (and (not gnus-newsgroup-limit)
8170                show-if-empty)
8171       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8172     gnus-newsgroup-limit))
8173
8174 (defun gnus-summary-limit-children (thread)
8175   "Return 1 if this subthread is visible and 0 if it is not."
8176   ;; First we get the number of visible children to this thread.  This
8177   ;; is done by recursing down the thread using this function, so this
8178   ;; will really go down to a leaf article first, before slowly
8179   ;; working its way up towards the root.
8180   (when thread
8181     (let* ((max-lisp-eval-depth 5000)
8182            (children
8183            (if (cdr thread)
8184                (apply '+ (mapcar 'gnus-summary-limit-children
8185                                  (cdr thread)))
8186              0))
8187           (number (mail-header-number (car thread)))
8188           score)
8189       (if (and
8190            (not (memq number gnus-newsgroup-marked))
8191            (or
8192             ;; If this article is dormant and has absolutely no visible
8193             ;; children, then this article isn't visible.
8194             (and (memq number gnus-newsgroup-dormant)
8195                  (zerop children))
8196             ;; If this is "fetch-old-headered" and there is no
8197             ;; visible children, then we don't want this article.
8198             (and (or (eq gnus-fetch-old-headers 'some)
8199                      (numberp gnus-fetch-old-headers))
8200                  (gnus-summary-article-ancient-p number)
8201                  (zerop children))
8202             ;; If this is "fetch-old-headered" and `invisible', then
8203             ;; we don't want this article.
8204             (and (eq gnus-fetch-old-headers 'invisible)
8205                  (gnus-summary-article-ancient-p number))
8206             ;; If this is a sparsely inserted article with no children,
8207             ;; we don't want it.
8208             (and (eq gnus-build-sparse-threads 'some)
8209                  (gnus-summary-article-sparse-p number)
8210                  (zerop children))
8211             ;; If we use expunging, and this article is really
8212             ;; low-scored, then we don't want this article.
8213             (when (and gnus-summary-expunge-below
8214                        (< (setq score
8215                                 (or (cdr (assq number gnus-newsgroup-scored))
8216                                     gnus-summary-default-score))
8217                           gnus-summary-expunge-below))
8218               ;; We increase the expunge-tally here, but that has
8219               ;; nothing to do with the limits, really.
8220               (incf gnus-newsgroup-expunged-tally)
8221               ;; We also mark as read here, if that's wanted.
8222               (when (and gnus-summary-mark-below
8223                          (< score gnus-summary-mark-below))
8224                 (setq gnus-newsgroup-unreads
8225                       (delq number gnus-newsgroup-unreads))
8226                 (if gnus-newsgroup-auto-expire
8227                     (push number gnus-newsgroup-expirable)
8228                   (push (cons number gnus-low-score-mark)
8229                         gnus-newsgroup-reads)))
8230               t)
8231             ;; Do the `display' group parameter.
8232             (and gnus-newsgroup-display
8233                  (not (funcall gnus-newsgroup-display)))
8234             ;; Check NoCeM things.
8235             (when (and gnus-use-nocem
8236                        (gnus-nocem-unwanted-article-p
8237                         (mail-header-id (car thread))))
8238               (setq gnus-newsgroup-unreads
8239                     (delq number gnus-newsgroup-unreads))
8240               t)))
8241           ;; Nope, invisible article.
8242           0
8243         ;; Ok, this article is to be visible, so we add it to the limit
8244         ;; and return 1.
8245         (push number gnus-newsgroup-limit)
8246         1))))
8247
8248 (defun gnus-expunge-thread (thread)
8249   "Mark all articles in THREAD as read."
8250   (let* ((number (mail-header-number (car thread))))
8251     (incf gnus-newsgroup-expunged-tally)
8252     ;; We also mark as read here, if that's wanted.
8253     (setq gnus-newsgroup-unreads
8254           (delq number gnus-newsgroup-unreads))
8255     (if gnus-newsgroup-auto-expire
8256         (push number gnus-newsgroup-expirable)
8257       (push (cons number gnus-low-score-mark)
8258             gnus-newsgroup-reads)))
8259   ;; Go recursively through all subthreads.
8260   (mapcar 'gnus-expunge-thread (cdr thread)))
8261
8262 ;; Summary article oriented commands
8263
8264 (defun gnus-summary-refer-parent-article (n)
8265   "Refer parent article N times.
8266 If N is negative, go to ancestor -N instead.
8267 The difference between N and the number of articles fetched is returned."
8268   (interactive "p")
8269   (let ((skip 1)
8270         error header ref)
8271     (when (not (natnump n))
8272       (setq skip (abs n)
8273             n 1))
8274     (while (and (> n 0)
8275                 (not error))
8276       (setq header (gnus-summary-article-header))
8277       (if (and (eq (mail-header-number header)
8278                    (cdr gnus-article-current))
8279                (equal gnus-newsgroup-name
8280                       (car gnus-article-current)))
8281           ;; If we try to find the parent of the currently
8282           ;; displayed article, then we take a look at the actual
8283           ;; References header, since this is slightly more
8284           ;; reliable than the References field we got from the
8285           ;; server.
8286           (save-excursion
8287             (set-buffer gnus-original-article-buffer)
8288             (nnheader-narrow-to-headers)
8289             (unless (setq ref (message-fetch-field "references"))
8290               (when (setq ref (message-fetch-field "in-reply-to"))
8291                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8292             (widen))
8293         (setq ref
8294               ;; It's not the current article, so we take a bet on
8295               ;; the value we got from the server.
8296               (mail-header-references header)))
8297       (if (and ref
8298                (not (equal ref "")))
8299           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8300             (gnus-message 1 "Couldn't find parent"))
8301         (gnus-message 1 "No references in article %d"
8302                       (gnus-summary-article-number))
8303         (setq error t))
8304       (decf n))
8305     (gnus-summary-position-point)
8306     n))
8307
8308 (defun gnus-summary-refer-references ()
8309   "Fetch all articles mentioned in the References header.
8310 Return the number of articles fetched."
8311   (interactive)
8312   (let ((ref (mail-header-references (gnus-summary-article-header)))
8313         (current (gnus-summary-article-number))
8314         (n 0))
8315     (if (or (not ref)
8316             (equal ref ""))
8317         (error "No References in the current article")
8318       ;; For each Message-ID in the References header...
8319       (while (string-match "<[^>]*>" ref)
8320         (incf n)
8321         ;; ... fetch that article.
8322         (gnus-summary-refer-article
8323          (prog1 (match-string 0 ref)
8324            (setq ref (substring ref (match-end 0))))))
8325       (gnus-summary-goto-subject current)
8326       (gnus-summary-position-point)
8327       n)))
8328
8329 (defun gnus-summary-refer-thread (&optional limit)
8330   "Fetch all articles in the current thread.
8331 If LIMIT (the numerical prefix), fetch that many old headers instead
8332 of what's specified by the `gnus-refer-thread-limit' variable."
8333   (interactive "P")
8334   (let ((id (mail-header-id (gnus-summary-article-header)))
8335         (limit (if limit (prefix-numeric-value limit)
8336                  gnus-refer-thread-limit)))
8337     (unless (eq gnus-fetch-old-headers 'invisible)
8338       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8339       ;; Retrieve the headers and read them in.
8340       (if (eq (if (numberp limit)
8341                   (gnus-retrieve-headers
8342                    (list (min
8343                           (+ (mail-header-number
8344                               (gnus-summary-article-header))
8345                              limit)
8346                           gnus-newsgroup-end))
8347                    gnus-newsgroup-name (* limit 2))
8348                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8349                 ;; headers.
8350                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8351                                        gnus-newsgroup-name limit))
8352               'nov)
8353           (gnus-build-all-threads)
8354         (error "Can't fetch thread from back ends that don't support NOV"))
8355       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8356     (gnus-summary-limit-include-thread id)))
8357
8358 (defun gnus-summary-refer-article (message-id)
8359   "Fetch an article specified by MESSAGE-ID."
8360   (interactive "sMessage-ID: ")
8361   (when (and (stringp message-id)
8362              (not (zerop (length message-id))))
8363     (setq message-id (gnus-replace-in-string message-id " " ""))
8364     ;; Construct the correct Message-ID if necessary.
8365     ;; Suggested by tale@pawl.rpi.edu.
8366     (unless (string-match "^<" message-id)
8367       (setq message-id (concat "<" message-id)))
8368     (unless (string-match ">$" message-id)
8369       (setq message-id (concat message-id ">")))
8370     ;; People often post MIDs from URLs, so unhex it:
8371     (unless (string-match "@" message-id)
8372       (setq message-id (gnus-url-unhex-string message-id)))
8373     (let* ((header (gnus-id-to-header message-id))
8374            (sparse (and header
8375                         (gnus-summary-article-sparse-p
8376                          (mail-header-number header))
8377                         (memq (mail-header-number header)
8378                               gnus-newsgroup-limit)))
8379            number)
8380       (cond
8381        ;; If the article is present in the buffer we just go to it.
8382        ((and header
8383              (or (not (gnus-summary-article-sparse-p
8384                        (mail-header-number header)))
8385                  sparse))
8386         (prog1
8387             (gnus-summary-goto-article
8388              (mail-header-number header) nil t)
8389           (when sparse
8390             (gnus-summary-update-article (mail-header-number header)))))
8391        (t
8392         ;; We fetch the article.
8393         (catch 'found
8394           (dolist (gnus-override-method (gnus-refer-article-methods))
8395             (when (and (gnus-check-server gnus-override-method)
8396                        ;; Fetch the header,
8397                        (setq number (gnus-summary-insert-subject message-id)))
8398               ;; and display the article.
8399               (gnus-summary-select-article nil nil nil number)
8400               (throw 'found t)))
8401           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8402
8403 (defun gnus-refer-article-methods ()
8404   "Return a list of referable methods."
8405   (cond
8406    ;; No method, so we default to current and native.
8407    ((null gnus-refer-article-method)
8408     (list gnus-current-select-method gnus-select-method))
8409    ;; Current.
8410    ((eq 'current gnus-refer-article-method)
8411     (list gnus-current-select-method))
8412    ;; List of select methods.
8413    ((not (and (symbolp (car gnus-refer-article-method))
8414               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8415     (let (out)
8416       (dolist (method gnus-refer-article-method)
8417         (push (if (eq 'current method)
8418                   gnus-current-select-method
8419                 method)
8420               out))
8421       (nreverse out)))
8422    ;; One single select method.
8423    (t
8424     (list gnus-refer-article-method))))
8425
8426 (defun gnus-summary-edit-parameters ()
8427   "Edit the group parameters of the current group."
8428   (interactive)
8429   (gnus-group-edit-group gnus-newsgroup-name 'params))
8430
8431 (defun gnus-summary-customize-parameters ()
8432   "Customize the group parameters of the current group."
8433   (interactive)
8434   (gnus-group-customize gnus-newsgroup-name))
8435
8436 (defun gnus-summary-enter-digest-group (&optional force)
8437   "Enter an nndoc group based on the current article.
8438 If FORCE, force a digest interpretation.  If not, try
8439 to guess what the document format is."
8440   (interactive "P")
8441   (let ((conf gnus-current-window-configuration))
8442     (save-window-excursion
8443       (save-excursion
8444         (let (gnus-article-prepare-hook
8445               gnus-display-mime-function
8446               gnus-break-pages)
8447           (gnus-summary-select-article))))
8448     (setq gnus-current-window-configuration conf)
8449     (let* ((name (format "%s-%d"
8450                          (gnus-group-prefixed-name
8451                           gnus-newsgroup-name (list 'nndoc ""))
8452                          (with-current-buffer gnus-summary-buffer
8453                            gnus-current-article)))
8454            (ogroup gnus-newsgroup-name)
8455            (params (append (gnus-info-params (gnus-get-info ogroup))
8456                            (list (cons 'to-group ogroup))
8457                            (list (cons 'parent-group ogroup))
8458                            (list (cons 'save-article-group ogroup))))
8459            (case-fold-search t)
8460            (buf (current-buffer))
8461            dig to-address)
8462       (save-excursion
8463         (set-buffer gnus-original-article-buffer)
8464         ;; Have the digest group inherit the main mail address of
8465         ;; the parent article.
8466         (when (setq to-address (or (gnus-fetch-field "reply-to")
8467                                    (gnus-fetch-field "from")))
8468           (setq params (append
8469                         (list (cons 'to-address
8470                                     (funcall gnus-decode-encoded-word-function
8471                                              to-address))))))
8472         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8473         (insert-buffer-substring gnus-original-article-buffer)
8474         ;; Remove lines that may lead nndoc to misinterpret the
8475         ;; document type.
8476         (narrow-to-region
8477          (goto-char (point-min))
8478          (or (search-forward "\n\n" nil t) (point)))
8479         (goto-char (point-min))
8480         (delete-matching-lines "^Path:\\|^From ")
8481         (widen))
8482       (unwind-protect
8483           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8484                     (gnus-newsgroup-ephemeral-ignored-charsets
8485                      gnus-newsgroup-ignored-charsets))
8486                 (gnus-group-read-ephemeral-group
8487                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8488                               (nndoc-article-type
8489                                ,(if force 'mbox 'guess)))
8490                  t nil nil nil
8491                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8492                                                         "ADAPT")))))
8493               ;; Make all postings to this group go to the parent group.
8494               (nconc (gnus-info-params (gnus-get-info name))
8495                      params)
8496             ;; Couldn't select this doc group.
8497             (switch-to-buffer buf)
8498             (gnus-set-global-variables)
8499             (gnus-configure-windows 'summary)
8500             (gnus-message 3 "Article couldn't be entered?"))
8501         (kill-buffer dig)))))
8502
8503 (defun gnus-summary-read-document (n)
8504   "Open a new group based on the current article(s).
8505 This will allow you to read digests and other similar
8506 documents as newsgroups.
8507 Obeys the standard process/prefix convention."
8508   (interactive "P")
8509   (let* ((ogroup gnus-newsgroup-name)
8510          (params (append (gnus-info-params (gnus-get-info ogroup))
8511                          (list (cons 'to-group ogroup))))
8512          group egroup groups vgroup)
8513     (dolist (article (gnus-summary-work-articles n))
8514       (setq group (format "%s-%d" gnus-newsgroup-name article))
8515       (gnus-summary-remove-process-mark article)
8516       (when (gnus-summary-display-article article)
8517         (save-excursion
8518           (with-temp-buffer
8519             (insert-buffer-substring gnus-original-article-buffer)
8520             ;; Remove some headers that may lead nndoc to make
8521             ;; the wrong guess.
8522             (message-narrow-to-head)
8523             (goto-char (point-min))
8524             (delete-matching-lines "^Path:\\|^From ")
8525             (widen)
8526             (if (setq egroup
8527                       (gnus-group-read-ephemeral-group
8528                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8529                                      (nndoc-article-type guess))
8530                        t nil t))
8531                 (progn
8532                   ;; Make all postings to this group go to the parent group.
8533                   (nconc (gnus-info-params (gnus-get-info egroup))
8534                          params)
8535                   (push egroup groups))
8536               ;; Couldn't select this doc group.
8537               (gnus-error 3 "Article couldn't be entered"))))))
8538     ;; Now we have selected all the documents.
8539     (cond
8540      ((not groups)
8541       (error "None of the articles could be interpreted as documents"))
8542      ((gnus-group-read-ephemeral-group
8543        (setq vgroup (format
8544                      "nnvirtual:%s-%s" gnus-newsgroup-name
8545                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8546        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8547        t
8548        (cons (current-buffer) 'summary)))
8549      (t
8550       (error "Couldn't select virtual nndoc group")))))
8551
8552 (defun gnus-summary-isearch-article (&optional regexp-p)
8553   "Do incremental search forward on the current article.
8554 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8555   (interactive "P")
8556   (let* ((gnus-inhibit-treatment t)
8557          (old (gnus-summary-select-article)))
8558     (gnus-configure-windows 'article)
8559     (gnus-eval-in-buffer-window gnus-article-buffer
8560       (save-restriction
8561         (widen)
8562         (when (eq 'old old)
8563           (gnus-article-show-all-headers))
8564         (goto-char (point-min))
8565         (isearch-forward regexp-p)))))
8566
8567 (defun gnus-summary-search-article-forward (regexp &optional backward)
8568   "Search for an article containing REGEXP forward.
8569 If BACKWARD, search backward instead."
8570   (interactive
8571    (list (read-string
8572           (format "Search article %s (regexp%s): "
8573                   (if current-prefix-arg "backward" "forward")
8574                   (if gnus-last-search-regexp
8575                       (concat ", default " gnus-last-search-regexp)
8576                     "")))
8577          current-prefix-arg))
8578   (if (string-equal regexp "")
8579       (setq regexp (or gnus-last-search-regexp ""))
8580     (setq gnus-last-search-regexp regexp)
8581     (setq gnus-article-before-search gnus-current-article))
8582   ;; Intentionally set gnus-last-article.
8583   (setq gnus-last-article gnus-article-before-search)
8584   (let ((gnus-last-article gnus-last-article))
8585     (if (gnus-summary-search-article regexp backward)
8586         (gnus-summary-show-thread)
8587       (signal 'search-failed (list regexp)))))
8588
8589 (defun gnus-summary-search-article-backward (regexp)
8590   "Search for an article containing REGEXP backward."
8591   (interactive
8592    (list (read-string
8593           (format "Search article backward (regexp%s): "
8594                   (if gnus-last-search-regexp
8595                       (concat ", default " gnus-last-search-regexp)
8596                     "")))))
8597   (gnus-summary-search-article-forward regexp 'backward))
8598
8599 (eval-when-compile
8600   (defmacro gnus-summary-search-article-position-point (regexp backward)
8601     "Dehighlight the last matched text and goto the beginning position."
8602     (` (if (and gnus-summary-search-article-matched-data
8603                 (let ((text (caddr gnus-summary-search-article-matched-data))
8604                       (inhibit-read-only t)
8605                       buffer-read-only)
8606                   (delete-region
8607                    (goto-char (car gnus-summary-search-article-matched-data))
8608                    (cadr gnus-summary-search-article-matched-data))
8609                   (insert text)
8610                   (string-match (, regexp) text)))
8611            (if (, backward) (beginning-of-line) (end-of-line))
8612          (goto-char (if (, backward) (point-max) (point-min))))))
8613
8614   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8615     "Place point where X-Face image is displayed."
8616     (if (featurep 'xemacs)
8617         (` (let ((end (if (search-forward "\n\n" nil t)
8618                           (goto-char (1- (point)))
8619                         (point-min)))
8620                  extent)
8621              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8622              (unless (and (re-search-forward "^From:" end t)
8623                           (setq extent (extent-at (point)))
8624                           (extent-begin-glyph extent))
8625                (goto-char (, opoint)))))
8626       (` (let ((end (if (search-forward "\n\n" nil t)
8627                         (goto-char (1- (point)))
8628                       (point-min)))
8629                (start (or (search-backward "\n\n" nil t) (point-min))))
8630            (goto-char
8631             (or (text-property-any start end 'x-face-image t);; x-face-e21
8632                 (, opoint)))))))
8633
8634   (defmacro gnus-summary-search-article-highlight-matched-text
8635     (backward treated x-face)
8636     "Highlight matched text in the function `gnus-summary-search-article'."
8637     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8638              (end (set-marker (make-marker) (match-end 0)))
8639              (inhibit-read-only t)
8640              buffer-read-only)
8641          (unless treated
8642            (let ((,@
8643                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8644                     (mapcar
8645                      (lambda (item) (setq items (delq item items)))
8646                      '(gnus-treat-buttonize
8647                        gnus-treat-fill-article
8648                        gnus-treat-fill-long-lines
8649                        gnus-treat-emphasize
8650                        gnus-treat-highlight-headers
8651                        gnus-treat-highlight-citation
8652                        gnus-treat-highlight-signature
8653                        gnus-treat-overstrike
8654                        gnus-treat-display-x-face
8655                        gnus-treat-buttonize-head
8656                        gnus-treat-decode-article-as-default-mime-charset))
8657                     items))
8658                  (gnus-treat-display-x-face
8659                   (when (, x-face) gnus-treat-display-x-face)))
8660              (gnus-article-prepare-mime-display)))
8661          (goto-char (if (, backward) start end))
8662          (when (, x-face)
8663            (gnus-summary-search-article-highlight-goto-x-face (point)))
8664          (setq gnus-summary-search-article-matched-data
8665                (list start end (buffer-substring start end)))
8666          (unless (eq start end);; matched text has been deleted. :-<
8667            (put-text-property start end 'face
8668                               (or (find-face 'isearch)
8669                                   'secondary-selection))))))
8670   )
8671
8672 (defun gnus-summary-search-article (regexp &optional backward)
8673   "Search for an article containing REGEXP.
8674 Optional argument BACKWARD means do search for backward.
8675 `gnus-select-article-hook' is not called during the search."
8676   ;; We have to require this here to make sure that the following
8677   ;; dynamic binding isn't shadowed by autoloading.
8678   (require 'gnus-async)
8679   (require 'gnus-art)
8680   (let ((gnus-select-article-hook nil)  ;Disable hook.
8681         (gnus-article-prepare-hook nil)
8682         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8683         (gnus-use-article-prefetch nil)
8684         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8685         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8686         (gnus-visual nil)
8687         (gnus-keep-backlog nil)
8688         (gnus-break-pages nil)
8689         (gnus-summary-display-arrow nil)
8690         (gnus-updated-mode-lines nil)
8691         (gnus-auto-center-summary nil)
8692         (sum (current-buffer))
8693         (found nil)
8694         point treated)
8695     (gnus-save-hidden-threads
8696       (static-if (featurep 'xemacs)
8697           (let ((gnus-inhibit-treatment t))
8698             (setq treated (eq 'old (gnus-summary-select-article)))
8699             (when (and treated
8700                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8701                                  (window-live-p (get-buffer-window
8702                                                  gnus-article-buffer t)))))
8703               (gnus-summary-select-article nil t)
8704               (setq treated nil)))
8705         (let ((gnus-inhibit-treatment t))
8706           (setq treated (eq 'old (gnus-summary-select-article)))
8707           (when (and treated
8708                      (not
8709                       (and (gnus-buffer-live-p gnus-article-buffer)
8710                            (window-live-p (get-buffer-window
8711                                            gnus-article-buffer t))
8712                            (or (not (string-match "^\\^X-Face:" regexp))
8713                                (with-current-buffer gnus-article-buffer
8714                                  gnus-summary-search-article-matched-data)))))
8715             (gnus-summary-select-article nil t)
8716             (setq treated nil))))
8717       (set-buffer gnus-article-buffer)
8718       (widen)
8719       (if treated
8720           (progn
8721             (gnus-article-show-all-headers)
8722             (gnus-summary-search-article-position-point regexp backward))
8723         (goto-char (if backward (point-max) (point-min))))
8724       (while (not found)
8725         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8726         (if (if backward
8727                 (re-search-backward regexp nil t)
8728               (re-search-forward regexp nil t))
8729             ;; We found the regexp.
8730             (progn
8731               (gnus-summary-search-article-highlight-matched-text
8732                backward treated (string-match "^\\^X-Face:" regexp))
8733               (setq found 'found)
8734               (forward-line
8735                (/ (- 2 (window-height
8736                         (get-buffer-window gnus-article-buffer t)))
8737                   2))
8738               (set-window-start
8739                (get-buffer-window (current-buffer))
8740                (point))
8741               (set-buffer sum)
8742               (setq point (point)))
8743           ;; We didn't find it, so we go to the next article.
8744           (set-buffer sum)
8745           (setq found 'not)
8746           (while (eq found 'not)
8747             (if (not (if backward (gnus-summary-find-prev)
8748                        (gnus-summary-find-next)))
8749                 ;; No more articles.
8750                 (setq found t)
8751               ;; Select the next article and adjust point.
8752               (unless (gnus-summary-article-sparse-p
8753                        (gnus-summary-article-number))
8754                 (setq found nil)
8755                 (let ((gnus-inhibit-treatment t))
8756                   (gnus-summary-select-article))
8757                 (setq treated nil)
8758                 (set-buffer gnus-article-buffer)
8759                 (widen)
8760                 (goto-char (if backward (point-max) (point-min))))))))
8761       (gnus-message 7 ""))
8762     ;; Return whether we found the regexp.
8763     (when (eq found 'found)
8764       (goto-char point)
8765       (gnus-summary-show-thread)
8766       (gnus-summary-goto-subject gnus-current-article)
8767       (gnus-summary-position-point)
8768       t)))
8769
8770 (defun gnus-find-matching-articles (header regexp)
8771   "Return a list of all articles that match REGEXP on HEADER.
8772 This search includes all articles in the current group that Gnus has
8773 fetched headers for, whether they are displayed or not."
8774   (let ((articles nil)
8775         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8776         (case-fold-search t))
8777     (dolist (header gnus-newsgroup-headers)
8778       (when (string-match regexp (funcall func header))
8779         (push (mail-header-number header) articles)))
8780     (nreverse articles)))
8781
8782 (defun gnus-summary-find-matching (header regexp &optional backward unread
8783                                           not-case-fold not-matching)
8784   "Return a list of all articles that match REGEXP on HEADER.
8785 The search stars on the current article and goes forwards unless
8786 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8787 If UNREAD is non-nil, only unread articles will
8788 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8789 in the comparisons. If NOT-MATCHING, return a list of all articles that
8790 not match REGEXP on HEADER."
8791   (let ((case-fold-search (not not-case-fold))
8792         articles d func)
8793     (if (consp header)
8794         (if (eq (car header) 'extra)
8795             (setq func
8796                   `(lambda (h)
8797                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8798                          "")))
8799           (error "%s is an invalid header" header))
8800       (unless (fboundp (intern (concat "mail-header-" header)))
8801         (error "%s is not a valid header" header))
8802       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8803     (dolist (d (if (eq backward 'all)
8804                    gnus-newsgroup-data
8805                  (gnus-data-find-list
8806                   (gnus-summary-article-number)
8807                   (gnus-data-list backward))))
8808       (when (and (or (not unread)       ; We want all articles...
8809                      (gnus-data-unread-p d)) ; Or just unreads.
8810                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8811                  (if not-matching
8812                      (not (string-match
8813                            regexp
8814                            (funcall func (gnus-data-header d))))
8815                    (string-match regexp
8816                                  (funcall func (gnus-data-header d)))))
8817         (push (gnus-data-number d) articles))) ; Success!
8818     (nreverse articles)))
8819
8820 (defun gnus-summary-execute-command (header regexp command &optional backward)
8821   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8822 If HEADER is an empty string (or nil), the match is done on the entire
8823 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8824   (interactive
8825    (list (let ((completion-ignore-case t))
8826            (completing-read
8827             "Header name: "
8828             (mapcar (lambda (header) (list (format "%s" header)))
8829                     (append
8830                      '("Number" "Subject" "From" "Lines" "Date"
8831                        "Message-ID" "Xref" "References" "Body")
8832                      gnus-extra-headers))
8833             nil 'require-match))
8834          (read-string "Regexp: ")
8835          (read-key-sequence "Command: ")
8836          current-prefix-arg))
8837   (when (equal header "Body")
8838     (setq header ""))
8839   ;; Hidden thread subtrees must be searched as well.
8840   (gnus-summary-show-all-threads)
8841   ;; We don't want to change current point nor window configuration.
8842   (save-excursion
8843     (save-window-excursion
8844       (let (gnus-visual
8845             gnus-treat-strip-trailing-blank-lines
8846             gnus-treat-strip-leading-blank-lines
8847             gnus-treat-strip-multiple-blank-lines
8848             gnus-treat-hide-boring-headers
8849             gnus-treat-fold-newsgroups
8850             gnus-article-prepare-hook)
8851         (gnus-message 6 "Executing %s..." (key-description command))
8852         ;; We'd like to execute COMMAND interactively so as to give arguments.
8853         (gnus-execute header regexp
8854                       `(call-interactively ',(key-binding command))
8855                       backward)
8856         (gnus-message 6 "Executing %s...done" (key-description command))))))
8857
8858 (defun gnus-summary-beginning-of-article ()
8859   "Scroll the article back to the beginning."
8860   (interactive)
8861   (gnus-summary-select-article)
8862   (gnus-configure-windows 'article)
8863   (gnus-eval-in-buffer-window gnus-article-buffer
8864     (widen)
8865     (goto-char (point-min))
8866     (when gnus-break-pages
8867       (gnus-narrow-to-page))))
8868
8869 (defun gnus-summary-end-of-article ()
8870   "Scroll to the end of the article."
8871   (interactive)
8872   (gnus-summary-select-article)
8873   (gnus-configure-windows 'article)
8874   (gnus-eval-in-buffer-window gnus-article-buffer
8875     (widen)
8876     (goto-char (point-max))
8877     (recenter -3)
8878     (when gnus-break-pages
8879       (when (re-search-backward page-delimiter nil t)
8880         (narrow-to-region (match-end 0) (point-max)))
8881       (gnus-narrow-to-page))))
8882
8883 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8884   "Truncate to LEN and quote all \"(\"'s in STRING."
8885   (gnus-replace-in-string (if (and len (> (length string) len))
8886                               (substring string 0 len)
8887                             string)
8888                           "[()]" "\\\\\\&"))
8889
8890 (defun gnus-summary-print-article (&optional filename n)
8891   "Generate and print a PostScript image of the process-marked (mail) articles.
8892
8893 If used interactively, print the current article if none are
8894 process-marked.  With prefix arg, prompt the user for the name of the
8895 file to save in.
8896
8897 When used from Lisp, accept two optional args FILENAME and N.  N means
8898 to print the next N articles.  If N is negative, print the N previous
8899 articles.  If N is nil and articles have been marked with the process
8900 mark, print these instead.
8901
8902 If the optional first argument FILENAME is nil, send the image to the
8903 printer.  If FILENAME is a string, save the PostScript image in a file with
8904 that name.  If FILENAME is a number, prompt the user for the name of the file
8905 to save in."
8906   (interactive (list (ps-print-preprint current-prefix-arg)))
8907   (dolist (article (gnus-summary-work-articles n))
8908     (gnus-summary-select-article nil nil 'pseudo article)
8909     (gnus-eval-in-buffer-window gnus-article-buffer
8910       (gnus-print-buffer))
8911     (gnus-summary-remove-process-mark article))
8912   (ps-despool filename))
8913
8914 (defun gnus-print-buffer ()
8915   (let ((buffer (generate-new-buffer " *print*")))
8916     (unwind-protect
8917         (progn
8918           (copy-to-buffer buffer (point-min) (point-max))
8919           (set-buffer buffer)
8920           (gnus-remove-text-with-property 'gnus-decoration)
8921           (when (gnus-visual-p 'article-highlight 'highlight)
8922             ;; Copy-to-buffer doesn't copy overlay.  So redo
8923             ;; highlight.
8924             (let ((gnus-article-buffer buffer))
8925               (gnus-article-highlight-citation t)
8926               (gnus-article-highlight-signature)
8927               (gnus-article-emphasize)
8928               (gnus-article-delete-invisible-text)))
8929           (let ((ps-left-header
8930                  (list
8931                   (concat "("
8932                           (gnus-summary-print-truncate-and-quote
8933                            (mail-header-subject gnus-current-headers)
8934                            66) ")")
8935                   (concat "("
8936                           (gnus-summary-print-truncate-and-quote
8937                            (mail-header-from gnus-current-headers)
8938                            45) ")")))
8939                 (ps-right-header
8940                  (list
8941                   "/pagenumberstring load"
8942                   (concat "("
8943                           (mail-header-date gnus-current-headers) ")"))))
8944             (gnus-run-hooks 'gnus-ps-print-hook)
8945             (save-excursion
8946               (if window-system
8947                   (ps-spool-buffer-with-faces)
8948                 (ps-spool-buffer)))))
8949       (kill-buffer buffer))))
8950
8951 (defun gnus-summary-show-article (&optional arg)
8952   "Force redisplaying of the current article.
8953 If ARG (the prefix) is a number, show the article with the charset
8954 defined in `gnus-summary-show-article-charset-alist', or the charset
8955 input.
8956 If ARG (the prefix) is non-nil and not a number, show the raw article
8957 without any article massaging functions being run.  Normally, the key
8958 strokes are `C-u g'."
8959   (interactive "P")
8960   (cond
8961    ((numberp arg)
8962     (gnus-summary-show-article t)
8963     (let* ((gnus-newsgroup-charset
8964             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8965                 (mm-read-coding-system
8966                  "View as charset: " ;; actually it is coding system.
8967                  (with-current-buffer gnus-article-buffer
8968                    (mm-detect-coding-region (point) (point-max))))))
8969            (default-mime-charset gnus-newsgroup-charset)
8970            (gnus-newsgroup-ignored-charsets 'gnus-all))
8971       (gnus-summary-select-article nil 'force)
8972       (let ((deps gnus-newsgroup-dependencies)
8973             head header lines)
8974         (save-excursion
8975           (set-buffer gnus-original-article-buffer)
8976           (save-restriction
8977             (message-narrow-to-head)
8978             (setq head (buffer-string))
8979             (goto-char (point-min))
8980             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8981               (goto-char (point-max))
8982               (widen)
8983               (setq lines (1- (count-lines (point) (point-max))))))
8984           (with-temp-buffer
8985             (insert (format "211 %d Article retrieved.\n"
8986                             (cdr gnus-article-current)))
8987             (insert head)
8988             (if lines (insert (format "Lines: %d\n" lines)))
8989             (insert ".\n")
8990             (let ((nntp-server-buffer (current-buffer)))
8991               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8992         (gnus-data-set-header
8993          (gnus-data-find (cdr gnus-article-current))
8994          header)
8995         (gnus-summary-update-article-line
8996          (cdr gnus-article-current) header)
8997         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8998           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8999    ((not arg)
9000     ;; Select the article the normal way.
9001     (gnus-summary-select-article nil 'force))
9002    (t
9003     ;; We have to require this here to make sure that the following
9004     ;; dynamic binding isn't shadowed by autoloading.
9005     (require 'gnus-async)
9006     (require 'gnus-art)
9007     ;; Bind the article treatment functions to nil.
9008     (let ((gnus-have-all-headers t)
9009           gnus-article-prepare-hook
9010           gnus-article-decode-hook
9011           gnus-break-pages
9012           gnus-show-mime
9013           (gnus-inhibit-treatment t))
9014       (gnus-summary-select-article nil 'force))))
9015   (gnus-summary-goto-subject gnus-current-article)
9016   (gnus-summary-position-point))
9017
9018 (defun gnus-summary-show-raw-article ()
9019   "Show the raw article without any article massaging functions being run."
9020   (interactive)
9021   (gnus-summary-show-article t))
9022
9023 (defun gnus-summary-verbose-headers (&optional arg)
9024   "Toggle permanent full header display.
9025 If ARG is a positive number, turn header display on.
9026 If ARG is a negative number, turn header display off."
9027   (interactive "P")
9028   (setq gnus-show-all-headers
9029         (cond ((or (not (numberp arg))
9030                    (zerop arg))
9031                (not gnus-show-all-headers))
9032               ((natnump arg)
9033                t)))
9034   (gnus-summary-show-article))
9035
9036 (defun gnus-summary-toggle-header (&optional arg)
9037   "Show the headers if they are hidden, or hide them if they are shown.
9038 If ARG is a positive number, show the entire header.
9039 If ARG is a negative number, hide the unwanted header lines."
9040   (interactive "P")
9041   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9042                      (get-buffer-window gnus-article-buffer t))))
9043     (with-current-buffer gnus-article-buffer
9044       (widen)
9045       (article-narrow-to-head)
9046       (let* ((buffer-read-only nil)
9047              (inhibit-point-motion-hooks t)
9048              (hidden (if (numberp arg)
9049                          (>= arg 0)
9050                        (or (not (looking-at "[^ \t\n]+:"))
9051                            (gnus-article-hidden-text-p 'headers))))
9052              s e)
9053         (delete-region (point-min) (point-max))
9054         (with-current-buffer gnus-original-article-buffer
9055           (goto-char (setq s (point-min)))
9056           (setq e (if (search-forward "\n\n" nil t)
9057                       (1- (point))
9058                     (point-max))))
9059         (insert-buffer-substring gnus-original-article-buffer s e)
9060         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9061         ;; article-decode-encoded-words by default.
9062         (article-decode-encoded-words)
9063         (run-hooks 'gnus-article-decode-hook)
9064         (if hidden
9065             (let ((gnus-treat-hide-headers nil)
9066                   (gnus-treat-hide-boring-headers nil))
9067               (gnus-delete-wash-type 'headers)
9068               (gnus-treat-article 'head))
9069           (gnus-treat-article 'head))
9070         (widen)
9071         (if window
9072             (set-window-start window (goto-char (point-min))))
9073         (if gnus-break-pages
9074             (gnus-narrow-to-page)
9075           (when (gnus-visual-p 'page-marker)
9076             (let ((buffer-read-only nil))
9077               (gnus-remove-text-with-property 'gnus-prev)
9078               (gnus-remove-text-with-property 'gnus-next))))
9079         (gnus-set-mode-line 'article)))))
9080
9081 (defun gnus-summary-show-all-headers ()
9082   "Make all header lines visible."
9083   (interactive)
9084   (gnus-summary-toggle-header 1))
9085
9086 (defun gnus-summary-toggle-mime (&optional arg)
9087   "Toggle MIME processing.
9088 If ARG is a positive number, turn MIME processing on."
9089   (interactive "P")
9090   (setq gnus-show-mime
9091         (if (null arg)
9092             (not gnus-show-mime)
9093           (> (prefix-numeric-value arg) 0)))
9094   (gnus-summary-select-article t 'force))
9095
9096 (defun gnus-summary-caesar-message (&optional arg)
9097   "Caesar rotate the current article by 13.
9098 The numerical prefix specifies how many places to rotate each letter
9099 forward."
9100   (interactive "P")
9101   (gnus-summary-select-article)
9102   (let ((mail-header-separator ""))
9103     (gnus-eval-in-buffer-window gnus-article-buffer
9104       (save-restriction
9105         (widen)
9106         (let ((start (window-start))
9107               buffer-read-only)
9108           (message-caesar-buffer-body arg)
9109           (set-window-start (get-buffer-window (current-buffer)) start)))))
9110   ;; Create buttons and stuff...
9111   (gnus-treat-article nil))
9112
9113 (defun gnus-summary-idna-message (&optional arg)
9114   "Decode IDNA encoded domain names in the current articles.
9115 IDNA encoded domain names looks like `xn--bar'.  If a string
9116 remain unencoded after running this function, it is likely an
9117 invalid IDNA string (`xn--bar' is invalid).
9118
9119 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9120 installed for this command to work."
9121   (interactive "P")
9122   (if (not (and (condition-case nil (require 'idna)
9123                   (file-error))
9124                 (mm-coding-system-p 'utf-8)
9125                 (executable-find (symbol-value 'idna-program))))
9126       (gnus-message
9127        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9128     (gnus-summary-select-article)
9129     (let ((mail-header-separator ""))
9130       (gnus-eval-in-buffer-window gnus-article-buffer
9131         (save-restriction
9132           (widen)
9133           (let ((start (window-start))
9134                 buffer-read-only)
9135             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9136               (replace-match (idna-to-unicode (match-string 1))))
9137             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9138
9139 (autoload 'unmorse-region "morse"
9140   "Convert morse coded text in region to ordinary ASCII text."
9141   t)
9142
9143 (defun gnus-summary-morse-message (&optional arg)
9144   "Morse decode the current article."
9145   (interactive "P")
9146   (gnus-summary-select-article)
9147   (let ((mail-header-separator ""))
9148     (gnus-eval-in-buffer-window gnus-article-buffer
9149       (save-excursion
9150         (save-restriction
9151           (widen)
9152           (let ((pos (window-start))
9153                 buffer-read-only)
9154             (goto-char (point-min))
9155             (when (message-goto-body)
9156               (gnus-narrow-to-body))
9157             (goto-char (point-min))
9158             (while (search-forward "·" (point-max) t)
9159               (replace-match "."))
9160             (unmorse-region (point-min) (point-max))
9161             (widen)
9162             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9163
9164 (defun gnus-summary-stop-page-breaking ()
9165   "Stop page breaking in the current article."
9166   (interactive)
9167   (gnus-summary-select-article)
9168   (gnus-eval-in-buffer-window gnus-article-buffer
9169     (widen)
9170     (when (gnus-visual-p 'page-marker)
9171       (let ((buffer-read-only nil))
9172         (gnus-remove-text-with-property 'gnus-prev)
9173         (gnus-remove-text-with-property 'gnus-next))
9174       (setq gnus-page-broken nil))))
9175
9176 (defun gnus-summary-move-article (&optional n to-newsgroup
9177                                             select-method action)
9178   "Move the current article to a different newsgroup.
9179 If N is a positive number, move the N next articles.
9180 If N is a negative number, move the N previous articles.
9181 If N is nil and any articles have been marked with the process mark,
9182 move those articles instead.
9183 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9184 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9185 re-spool using this method.
9186
9187 When called interactively with TO-NEWSGROUP being nil, the value of
9188 the variable `gnus-move-split-methods' is used for finding a default
9189 for the target newsgroup.
9190
9191 For this function to work, both the current newsgroup and the
9192 newsgroup that you want to move to have to support the `request-move'
9193 and `request-accept' functions.
9194
9195 ACTION can be either `move' (the default), `crosspost' or `copy'."
9196   (interactive "P")
9197   (unless action
9198     (setq action 'move))
9199   ;; Check whether the source group supports the required functions.
9200   (cond ((and (eq action 'move)
9201               (not (gnus-check-backend-function
9202                     'request-move-article gnus-newsgroup-name)))
9203          (error "The current group does not support article moving"))
9204         ((and (eq action 'crosspost)
9205               (not (gnus-check-backend-function
9206                     'request-replace-article gnus-newsgroup-name)))
9207          (error "The current group does not support article editing")))
9208   (let ((articles (gnus-summary-work-articles n))
9209         (prefix (if (gnus-check-backend-function
9210                      'request-move-article gnus-newsgroup-name)
9211                     (funcall gnus-move-group-prefix-function
9212                              gnus-newsgroup-name)
9213                   ""))
9214         (names '((move "Move" "Moving")
9215                  (copy "Copy" "Copying")
9216                  (crosspost "Crosspost" "Crossposting")))
9217         (copy-buf (save-excursion
9218                     (nnheader-set-temp-buffer " *copy article*")))
9219         art-group to-method new-xref article to-groups articles-to-update-marks)
9220     (unless (assq action names)
9221       (error "Unknown action %s" action))
9222     ;; Read the newsgroup name.
9223     (when (and (not to-newsgroup)
9224                (not select-method))
9225       (if (and gnus-move-split-methods
9226                (not
9227                 (and (memq gnus-current-article articles)
9228                      (gnus-buffer-live-p gnus-original-article-buffer))))
9229           ;; When `gnus-move-split-methods' is non-nil, we have to
9230           ;; select an article to give `gnus-read-move-group-name' an
9231           ;; opportunity to suggest an appropriate default.  However,
9232           ;; we needn't render or mark the article.
9233           (let ((gnus-display-mime-function nil)
9234                 (gnus-article-prepare-hook nil)
9235                 (gnus-mark-article-hook nil))
9236             (gnus-summary-select-article nil nil nil (car articles))))
9237       (setq to-newsgroup
9238             (gnus-read-move-group-name
9239              (cadr (assq action names))
9240              (symbol-value (intern (format "gnus-current-%s-group" action)))
9241              articles prefix))
9242       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9243     (setq to-method (or select-method
9244                         (gnus-server-to-method
9245                          (gnus-group-method to-newsgroup))))
9246     ;; Check the method we are to move this article to...
9247     (unless (gnus-check-backend-function
9248              'request-accept-article (car to-method))
9249       (error "%s does not support article copying" (car to-method)))
9250     (unless (gnus-check-server to-method)
9251       (error "Can't open server %s" (car to-method)))
9252     (gnus-message 6 "%s to %s: %s..."
9253                   (caddr (assq action names))
9254                   (or (car select-method) to-newsgroup) articles)
9255     (while articles
9256       (setq article (pop articles))
9257       (setq
9258        art-group
9259        (cond
9260         ;; Move the article.
9261         ((eq action 'move)
9262          ;; Remove this article from future suppression.
9263          (gnus-dup-unsuppress-article article)
9264          (let* ((from-method (gnus-find-method-for-group
9265                               gnus-newsgroup-name))
9266                 (to-method (gnus-find-method-for-group
9267                             to-newsgroup))
9268                 (move-is-internal (gnus-method-equal from-method to-method)))
9269          (gnus-request-move-article
9270           article                       ; Article to move
9271           gnus-newsgroup-name           ; From newsgroup
9272           (nth 1 (gnus-find-method-for-group
9273                   gnus-newsgroup-name)) ; Server
9274           (list 'gnus-request-accept-article
9275                 to-newsgroup (list 'quote select-method)
9276                 (not articles) t)       ; Accept form
9277           (not articles)                ; Only save nov last time
9278           move-is-internal)))           ; is this move internal?
9279         ;; Copy the article.
9280         ((eq action 'copy)
9281          (save-excursion
9282            (set-buffer copy-buf)
9283            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9284              (save-restriction
9285                (nnheader-narrow-to-headers)
9286                (dolist (hdr gnus-copy-article-ignored-headers)
9287                  (message-remove-header hdr t)))
9288              (gnus-request-accept-article
9289               to-newsgroup select-method (not articles) t))))
9290         ;; Crosspost the article.
9291         ((eq action 'crosspost)
9292          (let ((xref (message-tokenize-header
9293                       (mail-header-xref (gnus-summary-article-header article))
9294                       " ")))
9295            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9296                                   ":" (number-to-string article)))
9297            (unless xref
9298              (setq xref (list (system-name))))
9299            (setq new-xref
9300                  (concat
9301                   (mapconcat 'identity
9302                              (delete "Xref:" (delete new-xref xref))
9303                              " ")
9304                   " " new-xref))
9305            (save-excursion
9306              (set-buffer copy-buf)
9307              ;; First put the article in the destination group.
9308              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9309              (when (consp (setq art-group
9310                                 (gnus-request-accept-article
9311                                  to-newsgroup select-method (not articles))))
9312                (setq new-xref (concat new-xref " " (car art-group)
9313                                       ":"
9314                                       (number-to-string (cdr art-group))))
9315                ;; Now we have the new Xrefs header, so we insert
9316                ;; it and replace the new article.
9317                (nnheader-replace-header "Xref" new-xref)
9318                (gnus-request-replace-article
9319                 (cdr art-group) to-newsgroup (current-buffer))
9320                art-group))))))
9321       (cond
9322        ((not art-group)
9323         (gnus-message 1 "Couldn't %s article %s: %s"
9324                       (cadr (assq action names)) article
9325                       (nnheader-get-report (car to-method))))
9326        ((eq art-group 'junk)
9327         (when (eq action 'move)
9328           (gnus-summary-mark-article article gnus-canceled-mark)
9329           (gnus-message 4 "Deleted article %s" article)
9330           ;; run the delete hook
9331           (run-hook-with-args 'gnus-summary-article-delete-hook
9332                               action
9333                               (gnus-data-header
9334                                (assoc article (gnus-data-list nil)))
9335                               gnus-newsgroup-name nil
9336                               select-method)))
9337        (t
9338         (let* ((pto-group (gnus-group-prefixed-name
9339                            (car art-group) to-method))
9340                (info (gnus-get-info pto-group))
9341                (to-group (gnus-info-group info))
9342                to-marks)
9343           ;; Update the group that has been moved to.
9344           (when (and info
9345                      (memq action '(move copy)))
9346             (unless (member to-group to-groups)
9347               (push to-group to-groups))
9348
9349             (unless (memq article gnus-newsgroup-unreads)
9350               (push 'read to-marks)
9351               (gnus-info-set-read
9352                info (gnus-add-to-range (gnus-info-read info)
9353                                        (list (cdr art-group)))))
9354
9355             ;; See whether the article is to be put in the cache.
9356             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9357                              gnus-article-mark-lists
9358                            (delete '(expirable . expire)
9359                                    (copy-sequence gnus-article-mark-lists))))
9360                   (to-article (cdr art-group)))
9361
9362               ;; Enter the article into the cache in the new group,
9363               ;; if that is required.
9364               (when gnus-use-cache
9365                 (gnus-cache-possibly-enter-article
9366                  to-group to-article
9367                  (let ((header (copy-sequence
9368                                 (gnus-summary-article-header article))))
9369                    (mail-header-set-number header to-article)
9370                    header)
9371                  (memq article gnus-newsgroup-marked)
9372                  (memq article gnus-newsgroup-dormant)
9373                  (memq article gnus-newsgroup-unreads)))
9374
9375               (when gnus-preserve-marks
9376                 ;; Copy any marks over to the new group.
9377                 (when (and (equal to-group gnus-newsgroup-name)
9378                            (not (memq article gnus-newsgroup-unreads)))
9379                   ;; Mark this article as read in this group.
9380                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9381                   (setcdr (gnus-active to-group) to-article)
9382                   (setcdr gnus-newsgroup-active to-article))
9383
9384                 (while marks
9385                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9386                     (when (memq article (symbol-value
9387                                          (intern (format "gnus-newsgroup-%s"
9388                                                          (caar marks)))))
9389                       (push (cdar marks) to-marks)
9390                       ;; If the other group is the same as this group,
9391                       ;; then we have to add the mark to the list.
9392                       (when (equal to-group gnus-newsgroup-name)
9393                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9394                              (cons to-article
9395                                    (symbol-value
9396                                     (intern (format "gnus-newsgroup-%s"
9397                                                     (caar marks)))))))
9398                       ;; Copy the marks to other group.
9399                       (gnus-add-marked-articles
9400                        to-group (cdar marks) (list to-article) info)))
9401                   (setq marks (cdr marks)))
9402
9403                 (gnus-request-set-mark
9404                  to-group (list (list (list to-article) 'add to-marks))))
9405
9406               (gnus-dribble-enter
9407                (concat "(gnus-group-set-info '"
9408                        (gnus-prin1-to-string (gnus-get-info to-group))
9409                        ")"))))
9410
9411           ;; Update the Xref header in this article to point to
9412           ;; the new crossposted article we have just created.
9413           (when (eq action 'crosspost)
9414             (save-excursion
9415               (set-buffer copy-buf)
9416               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9417               (nnheader-replace-header "Xref" new-xref)
9418               (gnus-request-replace-article
9419                article gnus-newsgroup-name (current-buffer))))
9420
9421           ;; run the move/copy/crosspost/respool hook
9422           (run-hook-with-args 'gnus-summary-article-move-hook
9423                               action
9424                               (gnus-data-header
9425                                (assoc article (gnus-data-list nil)))
9426                               gnus-newsgroup-name
9427                               to-newsgroup
9428                               select-method))
9429
9430         ;;;!!!Why is this necessary?
9431         (set-buffer gnus-summary-buffer)
9432         
9433         (gnus-summary-goto-subject article)
9434         (when (eq action 'move)
9435           (gnus-summary-mark-article article gnus-canceled-mark))))
9436       (push article articles-to-update-marks))
9437
9438     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9439     ;; Re-activate all groups that have been moved to.
9440     (save-excursion
9441       (set-buffer gnus-group-buffer)
9442       (let ((gnus-group-marked to-groups))
9443         (gnus-group-get-new-news-this-group nil t)))
9444     
9445     (gnus-kill-buffer copy-buf)
9446     (gnus-summary-position-point)
9447     (gnus-set-mode-line 'summary)))
9448
9449 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9450   "Copy the current article to some other group.
9451 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9452 When called interactively, if TO-NEWSGROUP is nil, use the value of
9453 the variable `gnus-move-split-methods' for finding a default target
9454 newsgroup.
9455 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9456 re-spool using this method."
9457   (interactive "P")
9458   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9459
9460 (defun gnus-summary-crosspost-article (&optional n)
9461   "Crosspost the current article to some other group."
9462   (interactive "P")
9463   (gnus-summary-move-article n nil nil 'crosspost))
9464
9465 (defcustom gnus-summary-respool-default-method nil
9466   "Default method type for respooling an article.
9467 If nil, use to the current newsgroup method."
9468   :type 'symbol
9469   :group 'gnus-summary-mail)
9470
9471 (defcustom gnus-summary-display-while-building nil
9472   "If non-nil, show and update the summary buffer as it's being built.
9473 If the value is t, update the buffer after every line is inserted.  If
9474 the value is an integer (N), update the display every N lines."
9475   :version "22.1"
9476   :group 'gnus-thread
9477   :type '(choice (const :tag "off" nil)
9478                  number
9479                  (const :tag "frequently" t)))
9480
9481 (defun gnus-summary-respool-article (&optional n method)
9482   "Respool the current article.
9483 The article will be squeezed through the mail spooling process again,
9484 which means that it will be put in some mail newsgroup or other
9485 depending on `nnmail-split-methods'.
9486 If N is a positive number, respool the N next articles.
9487 If N is a negative number, respool the N previous articles.
9488 If N is nil and any articles have been marked with the process mark,
9489 respool those articles instead.
9490
9491 Respooling can be done both from mail groups and \"real\" newsgroups.
9492 In the former case, the articles in question will be moved from the
9493 current group into whatever groups they are destined to.  In the
9494 latter case, they will be copied into the relevant groups."
9495   (interactive
9496    (list current-prefix-arg
9497          (let* ((methods (gnus-methods-using 'respool))
9498                 (methname
9499                  (symbol-name (or gnus-summary-respool-default-method
9500                                   (car (gnus-find-method-for-group
9501                                         gnus-newsgroup-name)))))
9502                 (method
9503                  (gnus-completing-read-with-default
9504                   methname "Backend to use when respooling"
9505                   methods nil t nil 'gnus-mail-method-history))
9506                 ms)
9507            (cond
9508             ((zerop (length (setq ms (gnus-servers-using-backend
9509                                       (intern method)))))
9510              (list (intern method) ""))
9511             ((= 1 (length ms))
9512              (car ms))
9513             (t
9514              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9515                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9516                            ms-alist))))))))
9517   (unless method
9518     (error "No method given for respooling"))
9519   (if (assoc (symbol-name
9520               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9521              (gnus-methods-using 'respool))
9522       (gnus-summary-move-article n nil method)
9523     (gnus-summary-copy-article n nil method)))
9524
9525 (defun gnus-summary-import-article (file &optional edit)
9526   "Import an arbitrary file into a mail newsgroup."
9527   (interactive "fImport file: \nP")
9528   (let ((group gnus-newsgroup-name)
9529         (now (current-time))
9530         atts lines group-art)
9531     (unless (gnus-check-backend-function 'request-accept-article group)
9532       (error "%s does not support article importing" group))
9533     (or (file-readable-p file)
9534         (not (file-regular-p file))
9535         (error "Can't read %s" file))
9536     (save-excursion
9537       (set-buffer (gnus-get-buffer-create " *import file*"))
9538       (erase-buffer)
9539       (nnheader-insert-file-contents file)
9540       (goto-char (point-min))
9541       (if (nnheader-article-p)
9542           (save-restriction
9543             (goto-char (point-min))
9544             (search-forward "\n\n" nil t)
9545             (narrow-to-region (point-min) (1- (point)))
9546             (goto-char (point-min))
9547             (unless (re-search-forward "^date:" nil t)
9548               (goto-char (point-max))
9549               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9550         ;; This doesn't look like an article, so we fudge some headers.
9551         (setq atts (file-attributes file)
9552               lines (count-lines (point-min) (point-max)))
9553         (insert "From: " (read-string "From: ") "\n"
9554                 "Subject: " (read-string "Subject: ") "\n"
9555                 "Date: " (message-make-date (nth 5 atts)) "\n"
9556                 "Message-ID: " (message-make-message-id) "\n"
9557                 "Lines: " (int-to-string lines) "\n"
9558                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9559       (setq group-art (gnus-request-accept-article group nil t))
9560       (kill-buffer (current-buffer)))
9561     (setq gnus-newsgroup-active (gnus-activate-group group))
9562     (forward-line 1)
9563     (gnus-summary-goto-article (cdr group-art) nil t)
9564     (when edit
9565       (gnus-summary-edit-article))))
9566
9567 (defun gnus-summary-create-article ()
9568   "Create an article in a mail newsgroup."
9569   (interactive)
9570   (let ((group gnus-newsgroup-name)
9571         (now (current-time))
9572         group-art)
9573     (unless (gnus-check-backend-function 'request-accept-article group)
9574       (error "%s does not support article importing" group))
9575     (save-excursion
9576       (set-buffer (gnus-get-buffer-create " *import file*"))
9577       (erase-buffer)
9578       (goto-char (point-min))
9579       ;; This doesn't look like an article, so we fudge some headers.
9580       (insert "From: " (read-string "From: ") "\n"
9581               "Subject: " (read-string "Subject: ") "\n"
9582               "Date: " (message-make-date now) "\n"
9583               "Message-ID: " (message-make-message-id) "\n")
9584       (setq group-art (gnus-request-accept-article group nil t))
9585       (kill-buffer (current-buffer)))
9586     (setq gnus-newsgroup-active (gnus-activate-group group))
9587     (forward-line 1)
9588     (gnus-summary-goto-article (cdr group-art) nil t)
9589     (gnus-summary-edit-article)))
9590
9591 (defun gnus-summary-article-posted-p ()
9592   "Say whether the current (mail) article is available from news as well.
9593 This will be the case if the article has both been mailed and posted."
9594   (interactive)
9595   (let ((id (mail-header-references (gnus-summary-article-header)))
9596         (gnus-override-method (car (gnus-refer-article-methods))))
9597     (if (gnus-request-head id "")
9598         (gnus-message 2 "The current message was found on %s"
9599                       gnus-override-method)
9600       (gnus-message 2 "The current message couldn't be found on %s"
9601                     gnus-override-method)
9602       nil)))
9603
9604 (defun gnus-summary-expire-articles (&optional now)
9605   "Expire all articles that are marked as expirable in the current group."
9606   (interactive)
9607   (when (and (not gnus-group-is-exiting-without-update-p)
9608              (gnus-check-backend-function
9609               'request-expire-articles gnus-newsgroup-name))
9610     ;; This backend supports expiry.
9611     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9612            (expirable (if total
9613                           (progn
9614                             ;; We need to update the info for
9615                             ;; this group for `gnus-list-of-read-articles'
9616                             ;; to give us the right answer.
9617                             (gnus-run-hooks 'gnus-exit-group-hook)
9618                             (gnus-summary-update-info)
9619                             (gnus-list-of-read-articles gnus-newsgroup-name))
9620                         (setq gnus-newsgroup-expirable
9621                               (sort gnus-newsgroup-expirable '<))))
9622            (expiry-wait (if now 'immediate
9623                           (gnus-group-find-parameter
9624                            gnus-newsgroup-name 'expiry-wait)))
9625            (nnmail-expiry-target
9626             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9627                 nnmail-expiry-target))
9628            es)
9629       (when expirable
9630         ;; There are expirable articles in this group, so we run them
9631         ;; through the expiry process.
9632         (gnus-message 6 "Expiring articles...")
9633         (unless (gnus-check-group gnus-newsgroup-name)
9634           (error "Can't open server for %s" gnus-newsgroup-name))
9635         ;; The list of articles that weren't expired is returned.
9636         (save-excursion
9637           (if expiry-wait
9638               (let ((nnmail-expiry-wait-function nil)
9639                     (nnmail-expiry-wait expiry-wait))
9640                 (setq es (gnus-request-expire-articles
9641                           expirable gnus-newsgroup-name)))
9642             (setq es (gnus-request-expire-articles
9643                       expirable gnus-newsgroup-name)))
9644           (unless total
9645             (setq gnus-newsgroup-expirable es))
9646           ;; We go through the old list of expirable, and mark all
9647           ;; really expired articles as nonexistent.
9648           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9649             (let ((gnus-use-cache nil))
9650               (dolist (article expirable)
9651                 (when (and (not (memq article es))
9652                            (gnus-data-find article))
9653                   (gnus-summary-mark-article article gnus-canceled-mark)
9654                   (run-hook-with-args 'gnus-summary-article-expire-hook
9655                                       'delete
9656                                       (gnus-data-header
9657                                        (assoc article (gnus-data-list nil)))
9658                                       gnus-newsgroup-name
9659                                       nil
9660                                       nil))))))
9661         (gnus-message 6 "Expiring articles...done")))))
9662
9663 (defun gnus-summary-expire-articles-now ()
9664   "Expunge all expirable articles in the current group.
9665 This means that *all* articles that are marked as expirable will be
9666 deleted forever, right now."
9667   (interactive)
9668   (or gnus-expert-user
9669       (gnus-yes-or-no-p
9670        "Are you really, really, really sure you want to delete all these messages? ")
9671       (error "Phew!"))
9672   (gnus-summary-expire-articles t))
9673
9674 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9675 (defun gnus-summary-delete-article (&optional n)
9676   "Delete the N next (mail) articles.
9677 This command actually deletes articles.  This is not a marking
9678 command.  The article will disappear forever from your life, never to
9679 return.
9680
9681 If N is negative, delete backwards.
9682 If N is nil and articles have been marked with the process mark,
9683 delete these instead.
9684
9685 If `gnus-novice-user' is non-nil you will be asked for
9686 confirmation before the articles are deleted."
9687   (interactive "P")
9688   (unless (gnus-check-backend-function 'request-expire-articles
9689                                        gnus-newsgroup-name)
9690     (error "The current newsgroup does not support article deletion"))
9691   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9692     (error "Couldn't open server"))
9693   ;; Compute the list of articles to delete.
9694   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9695         (nnmail-expiry-target 'delete)
9696         not-deleted)
9697     (if (and gnus-novice-user
9698              (not (gnus-yes-or-no-p
9699                    (format "Do you really want to delete %s forever? "
9700                            (if (> (length articles) 1)
9701                                (format "these %s articles" (length articles))
9702                              "this article")))))
9703         ()
9704       ;; Delete the articles.
9705       (setq not-deleted (gnus-request-expire-articles
9706                          articles gnus-newsgroup-name 'force))
9707       (while articles
9708         (gnus-summary-remove-process-mark (car articles))
9709         ;; The backend might not have been able to delete the article
9710         ;; after all.
9711         (unless (memq (car articles) not-deleted)
9712           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9713         (let* ((article (car articles))
9714                (ghead  (gnus-data-header
9715                                     (assoc article (gnus-data-list nil)))))
9716           (run-hook-with-args 'gnus-summary-article-delete-hook
9717                               'delete ghead gnus-newsgroup-name nil
9718                               nil))
9719         (setq articles (cdr articles)))
9720       (when not-deleted
9721         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9722     (gnus-summary-position-point)
9723     (gnus-set-mode-line 'summary)
9724     not-deleted))
9725
9726 (defun gnus-summary-edit-article (&optional force)
9727   "Edit the current article.
9728 This will have permanent effect only in mail groups.
9729 If FORCE is non-nil, allow editing of articles even in read-only
9730 groups."
9731   (interactive "P")
9732   (save-excursion
9733     (set-buffer gnus-summary-buffer)
9734     (let ((mail-parse-charset gnus-newsgroup-charset)
9735           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9736       (gnus-set-global-variables)
9737       (when (and (not force)
9738                  (gnus-group-read-only-p))
9739         (error "The current newsgroup does not support article editing"))
9740       (gnus-summary-show-article t)
9741       (gnus-article-edit-article
9742        'ignore
9743        `(lambda (no-highlight)
9744           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9745                 (message-options message-options)
9746                 (message-options-set-recipient)
9747                 (mail-parse-ignored-charsets
9748                  ',gnus-newsgroup-ignored-charsets))
9749             (gnus-summary-edit-article-done
9750              ,(or (mail-header-references gnus-current-headers) "")
9751              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9752
9753 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9754
9755 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9756                                                  no-highlight)
9757   "Make edits to the current article permanent."
9758   (interactive)
9759   (save-excursion
9760     ;; The buffer restriction contains the entire article if it exists.
9761     (when (article-goto-body)
9762       (let ((lines (count-lines (point) (point-max)))
9763             (length (- (point-max) (point)))
9764             (case-fold-search t)
9765             (body (copy-marker (point))))
9766         (goto-char (point-min))
9767         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9768           (delete-region (match-beginning 1) (match-end 1))
9769           (insert (number-to-string length)))
9770         (goto-char (point-min))
9771         (when (re-search-forward
9772                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9773           (delete-region (match-beginning 1) (match-end 1))
9774           (insert (number-to-string length)))
9775         (goto-char (point-min))
9776         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9777           (delete-region (match-beginning 1) (match-end 1))
9778           (insert (number-to-string lines))))))
9779   ;; Replace the article.
9780   (let ((buf (current-buffer)))
9781     (with-temp-buffer
9782       (insert-buffer-substring buf)
9783
9784       (if (and (not read-only)
9785                (not (gnus-request-replace-article
9786                      (cdr gnus-article-current) (car gnus-article-current)
9787                      (current-buffer) t)))
9788           (error "Couldn't replace article")
9789         ;; Update the summary buffer.
9790         (if (and references
9791                  (equal (message-tokenize-header references " ")
9792                         (message-tokenize-header
9793                          (or (message-fetch-field "references") "") " ")))
9794             ;; We only have to update this line.
9795             (save-excursion
9796               (save-restriction
9797                 (message-narrow-to-head)
9798                 (let ((head (buffer-substring-no-properties
9799                              (point-min) (point-max)))
9800                       header)
9801                   (with-temp-buffer
9802                     (insert (format "211 %d Article retrieved.\n"
9803                                     (cdr gnus-article-current)))
9804                     (insert head)
9805                     (insert ".\n")
9806                     (let ((nntp-server-buffer (current-buffer)))
9807                       (setq header (car (gnus-get-newsgroup-headers
9808                                          nil t))))
9809                     (save-excursion
9810                       (set-buffer gnus-summary-buffer)
9811                       (gnus-data-set-header
9812                        (gnus-data-find (cdr gnus-article-current))
9813                        header)
9814                       (gnus-summary-update-article-line
9815                        (cdr gnus-article-current) header)
9816                       (if (gnus-summary-goto-subject
9817                            (cdr gnus-article-current) nil t)
9818                           (gnus-summary-update-secondary-mark
9819                            (cdr gnus-article-current))))))))
9820           ;; Update threads.
9821           (set-buffer (or buffer gnus-summary-buffer))
9822           (gnus-summary-update-article (cdr gnus-article-current))
9823           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9824               (gnus-summary-update-secondary-mark
9825                (cdr gnus-article-current))))
9826         ;; Prettify the article buffer again.
9827         (unless no-highlight
9828           (save-excursion
9829             (set-buffer gnus-article-buffer)
9830             ;;;!!! Fix this -- article should be rehighlighted.
9831             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9832             (set-buffer gnus-original-article-buffer)
9833             (gnus-request-article
9834              (cdr gnus-article-current)
9835              (car gnus-article-current) (current-buffer))))
9836         ;; Prettify the summary buffer line.
9837         (when (gnus-visual-p 'summary-highlight 'highlight)
9838           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9839
9840 (defun gnus-summary-edit-wash (key)
9841   "Perform editing command KEY in the article buffer."
9842   (interactive
9843    (list
9844     (progn
9845       (message "%s" (concat (this-command-keys) "- "))
9846       (read-char))))
9847   (message "")
9848   (gnus-summary-edit-article)
9849   (execute-kbd-macro (concat (this-command-keys) key))
9850   (gnus-article-edit-done))
9851
9852 ;;; Respooling
9853
9854 (defun gnus-summary-respool-query (&optional silent trace)
9855   "Query where the respool algorithm would put this article."
9856   (interactive)
9857   (let (gnus-mark-article-hook)
9858     (gnus-summary-select-article)
9859     (save-excursion
9860       (set-buffer gnus-original-article-buffer)
9861       (let ((groups (nnmail-article-group 'identity trace)))
9862         (unless silent
9863           (if groups
9864               (message "This message would go to %s"
9865                        (mapconcat 'car groups ", "))
9866             (message "This message would go to no groups"))
9867           groups)))))
9868
9869 (defun gnus-summary-respool-trace ()
9870   "Trace where the respool algorithm would put this article.
9871 Display a buffer showing all fancy splitting patterns which matched."
9872   (interactive)
9873   (gnus-summary-respool-query nil t))
9874
9875 ;; Summary marking commands.
9876
9877 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9878   "Mark articles which has the same subject as read, and then select the next.
9879 If UNMARK is positive, remove any kind of mark.
9880 If UNMARK is negative, tick articles."
9881   (interactive "P")
9882   (when unmark
9883     (setq unmark (prefix-numeric-value unmark)))
9884   (let ((count
9885          (gnus-summary-mark-same-subject
9886           (gnus-summary-article-subject) unmark)))
9887     ;; Select next unread article.  If auto-select-same mode, should
9888     ;; select the first unread article.
9889     (gnus-summary-next-article t (and gnus-auto-select-same
9890                                       (gnus-summary-article-subject)))
9891     (gnus-message 7 "%d article%s marked as %s"
9892                   count (if (= count 1) " is" "s are")
9893                   (if unmark "unread" "read"))))
9894
9895 (defun gnus-summary-kill-same-subject (&optional unmark)
9896   "Mark articles which has the same subject as read.
9897 If UNMARK is positive, remove any kind of mark.
9898 If UNMARK is negative, tick articles."
9899   (interactive "P")
9900   (when unmark
9901     (setq unmark (prefix-numeric-value unmark)))
9902   (let ((count
9903          (gnus-summary-mark-same-subject
9904           (gnus-summary-article-subject) unmark)))
9905     ;; If marked as read, go to next unread subject.
9906     (when (null unmark)
9907       ;; Go to next unread subject.
9908       (gnus-summary-next-subject 1 t))
9909     (gnus-message 7 "%d articles are marked as %s"
9910                   count (if unmark "unread" "read"))))
9911
9912 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9913   "Mark articles with same SUBJECT as read, and return marked number.
9914 If optional argument UNMARK is positive, remove any kinds of marks.
9915 If optional argument UNMARK is negative, mark articles as unread instead."
9916   (let ((count 1))
9917     (save-excursion
9918       (cond
9919        ((null unmark)                   ; Mark as read.
9920         (while (and
9921                 (progn
9922                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9923                   (gnus-summary-show-thread) t)
9924                 (gnus-summary-find-subject subject))
9925           (setq count (1+ count))))
9926        ((> unmark 0)                    ; Tick.
9927         (while (and
9928                 (progn
9929                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9930                   (gnus-summary-show-thread) t)
9931                 (gnus-summary-find-subject subject))
9932           (setq count (1+ count))))
9933        (t                               ; Mark as unread.
9934         (while (and
9935                 (progn
9936                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9937                   (gnus-summary-show-thread) t)
9938                 (gnus-summary-find-subject subject))
9939           (setq count (1+ count)))))
9940       (gnus-set-mode-line 'summary)
9941       ;; Return the number of marked articles.
9942       count)))
9943
9944 (defun gnus-summary-mark-as-processable (n &optional unmark)
9945   "Set the process mark on the next N articles.
9946 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9947 the process mark instead.  The difference between N and the actual
9948 number of articles marked is returned."
9949   (interactive "P")
9950   (if (and (null n) (gnus-region-active-p))
9951       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9952     (setq n (prefix-numeric-value n))
9953     (let ((backward (< n 0))
9954           (n (abs n)))
9955       (while (and
9956               (> n 0)
9957               (if unmark
9958                   (gnus-summary-remove-process-mark
9959                    (gnus-summary-article-number))
9960                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9961               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9962         (setq n (1- n)))
9963       (when (/= 0 n)
9964         (gnus-message 7 "No more articles"))
9965       (gnus-summary-recenter)
9966       (gnus-summary-position-point)
9967       n)))
9968
9969 (defun gnus-summary-unmark-as-processable (n)
9970   "Remove the process mark from the next N articles.
9971 If N is negative, unmark backward instead.  The difference between N and
9972 the actual number of articles unmarked is returned."
9973   (interactive "P")
9974   (gnus-summary-mark-as-processable n t))
9975
9976 (defun gnus-summary-unmark-all-processable ()
9977   "Remove the process mark from all articles."
9978   (interactive)
9979   (save-excursion
9980     (while gnus-newsgroup-processable
9981       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9982   (gnus-summary-position-point))
9983
9984 (defun gnus-summary-add-mark (article type)
9985   "Mark ARTICLE with a mark of TYPE."
9986   (let ((vtype (car (assq type gnus-article-mark-lists)))
9987         var)
9988     (if (not vtype)
9989         (error "No such mark type: %s" type)
9990       (setq var (intern (format "gnus-newsgroup-%s" type)))
9991       (set var (cons article (symbol-value var)))
9992       (if (memq type '(processable cached replied forwarded recent saved))
9993           (gnus-summary-update-secondary-mark article)
9994         ;;; !!! This is bogus.  We should find out what primary
9995         ;;; !!! mark we want to set.
9996         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9997
9998 (defun gnus-summary-mark-as-expirable (n)
9999   "Mark N articles forward as expirable.
10000 If N is negative, mark backward instead.  The difference between N and
10001 the actual number of articles marked is returned."
10002   (interactive "p")
10003   (gnus-summary-mark-forward n gnus-expirable-mark))
10004
10005 (defun gnus-summary-mark-as-spam (n)
10006   "Mark N articles forward as spam.
10007 If N is negative, mark backward instead.  The difference between N and
10008 the actual number of articles marked is returned."
10009   (interactive "p")
10010   (gnus-summary-mark-forward n gnus-spam-mark))
10011
10012 (defun gnus-summary-mark-article-as-replied (article)
10013   "Mark ARTICLE as replied to and update the summary line.
10014 ARTICLE can also be a list of articles."
10015   (interactive (list (gnus-summary-article-number)))
10016   (let ((articles (if (listp article) article (list article))))
10017     (dolist (article articles)
10018       (unless (numberp article)
10019         (error "%s is not a number" article))
10020       (push article gnus-newsgroup-replied)
10021       (let ((buffer-read-only nil))
10022         (when (gnus-summary-goto-subject article nil t)
10023           (gnus-summary-update-secondary-mark article))))))
10024
10025 (defun gnus-summary-mark-article-as-forwarded (article)
10026   "Mark ARTICLE as forwarded and update the summary line.
10027 ARTICLE can also be a list of articles."
10028   (let ((articles (if (listp article) article (list article))))
10029     (dolist (article articles)
10030       (push article gnus-newsgroup-forwarded)
10031       (let ((buffer-read-only nil))
10032         (when (gnus-summary-goto-subject article nil t)
10033           (gnus-summary-update-secondary-mark article))))))
10034
10035 (defun gnus-summary-set-bookmark (article)
10036   "Set a bookmark in current article."
10037   (interactive (list (gnus-summary-article-number)))
10038   (when (or (not (get-buffer gnus-article-buffer))
10039             (not gnus-current-article)
10040             (not gnus-article-current)
10041             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10042     (error "No current article selected"))
10043   ;; Remove old bookmark, if one exists.
10044   (gnus-pull article gnus-newsgroup-bookmarks)
10045   ;; Set the new bookmark, which is on the form
10046   ;; (article-number . line-number-in-body).
10047   (push
10048    (cons article
10049          (with-current-buffer gnus-article-buffer
10050            (count-lines
10051             (min (point)
10052                  (save-excursion
10053                    (article-goto-body)
10054                    (point)))
10055             (point))))
10056    gnus-newsgroup-bookmarks)
10057   (gnus-message 6 "A bookmark has been added to the current article."))
10058
10059 (defun gnus-summary-remove-bookmark (article)
10060   "Remove the bookmark from the current article."
10061   (interactive (list (gnus-summary-article-number)))
10062   ;; Remove old bookmark, if one exists.
10063   (if (not (assq article gnus-newsgroup-bookmarks))
10064       (gnus-message 6 "No bookmark in current article.")
10065     (gnus-pull article gnus-newsgroup-bookmarks)
10066     (gnus-message 6 "Removed bookmark.")))
10067
10068 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10069 (defun gnus-summary-mark-as-dormant (n)
10070   "Mark N articles forward as dormant.
10071 If N is negative, mark backward instead.  The difference between N and
10072 the actual number of articles marked is returned."
10073   (interactive "p")
10074   (gnus-summary-mark-forward n gnus-dormant-mark))
10075
10076 (defun gnus-summary-set-process-mark (article)
10077   "Set the process mark on ARTICLE and update the summary line."
10078   (setq gnus-newsgroup-processable
10079         (cons article
10080               (delq article gnus-newsgroup-processable)))
10081   (when (gnus-summary-goto-subject article)
10082     (gnus-summary-show-thread)
10083     (gnus-summary-goto-subject article)
10084     (gnus-summary-update-secondary-mark article)))
10085
10086 (defun gnus-summary-remove-process-mark (&rest articles)
10087   "Remove the process mark from ARTICLES and update the summary line."
10088   (dolist (article articles)
10089     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10090     (when (gnus-summary-goto-subject article)
10091       (gnus-summary-show-thread)
10092       (gnus-summary-goto-subject article)
10093       (gnus-summary-update-secondary-mark article))))
10094
10095 (defun gnus-summary-set-saved-mark (article)
10096   "Set the process mark on ARTICLE and update the summary line."
10097   (push article gnus-newsgroup-saved)
10098   (when (gnus-summary-goto-subject article)
10099     (gnus-summary-update-secondary-mark article)))
10100
10101 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10102   "Mark N articles as read forwards.
10103 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10104 The difference between N and the actual number of articles marked is
10105 returned.
10106 If NO-EXPIRE, auto-expiry will be inhibited."
10107   (interactive "p")
10108   (gnus-summary-show-thread)
10109   (let ((backward (< n 0))
10110         (gnus-summary-goto-unread
10111          (and gnus-summary-goto-unread
10112               (not (eq gnus-summary-goto-unread 'never))
10113               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10114                                     gnus-ticked-mark gnus-dormant-mark)))))
10115         (n (abs n))
10116         (mark (or mark gnus-del-mark)))
10117     (while (and (> n 0)
10118                 (gnus-summary-mark-article nil mark no-expire)
10119                 (zerop (gnus-summary-next-subject
10120                         (if backward -1 1)
10121                         (and gnus-summary-goto-unread
10122                              (not (eq gnus-summary-goto-unread 'never)))
10123                         t)))
10124       (setq n (1- n)))
10125     (when (/= 0 n)
10126       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10127     (gnus-summary-recenter)
10128     (gnus-summary-position-point)
10129     (gnus-set-mode-line 'summary)
10130     n))
10131
10132 (defun gnus-summary-mark-article-as-read (mark)
10133   "Mark the current article quickly as read with MARK."
10134   (let ((article (gnus-summary-article-number)))
10135     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10136     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10137     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10138     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10139     (push (cons article mark) gnus-newsgroup-reads)
10140     ;; Possibly remove from cache, if that is used.
10141     (when gnus-use-cache
10142       (gnus-cache-enter-remove-article article))
10143     ;; Allow the backend to change the mark.
10144     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10145     ;; Check for auto-expiry.
10146     (when (and gnus-newsgroup-auto-expire
10147                (memq mark gnus-auto-expirable-marks))
10148       (setq mark gnus-expirable-mark)
10149       ;; Let the backend know about the mark change.
10150       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10151       (push article gnus-newsgroup-expirable))
10152     ;; Set the mark in the buffer.
10153     (gnus-summary-update-mark mark 'unread)
10154     t))
10155
10156 (defun gnus-summary-mark-article-as-unread (mark)
10157   "Mark the current article quickly as unread with MARK."
10158   (let* ((article (gnus-summary-article-number))
10159          (old-mark (gnus-summary-article-mark article)))
10160     ;; Allow the backend to change the mark.
10161     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10162     (if (eq mark old-mark)
10163         t
10164       (if (<= article 0)
10165           (progn
10166             (gnus-error 1 "Can't mark negative article numbers")
10167             nil)
10168         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10169         (setq gnus-newsgroup-spam-marked
10170               (delq article gnus-newsgroup-spam-marked))
10171         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10172         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10173         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10174         (cond ((= mark gnus-ticked-mark)
10175                (setq gnus-newsgroup-marked
10176                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10177                                               article)))
10178               ((= mark gnus-spam-mark)
10179                (setq gnus-newsgroup-spam-marked
10180                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10181                                               article)))
10182               ((= mark gnus-dormant-mark)
10183                (setq gnus-newsgroup-dormant
10184                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10185                                               article)))
10186               (t
10187                (setq gnus-newsgroup-unreads
10188                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10189                                               article))))
10190         (gnus-pull article gnus-newsgroup-reads)
10191
10192         ;; See whether the article is to be put in the cache.
10193         (and gnus-use-cache
10194              (vectorp (gnus-summary-article-header article))
10195              (save-excursion
10196                (gnus-cache-possibly-enter-article
10197                 gnus-newsgroup-name article
10198                 (gnus-summary-article-header article)
10199                 (= mark gnus-ticked-mark)
10200                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10201
10202         ;; Fix the mark.
10203         (gnus-summary-update-mark mark 'unread)
10204         t))))
10205
10206 (defun gnus-summary-mark-article (&optional article mark no-expire)
10207   "Mark ARTICLE with MARK.  MARK can be any character.
10208 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10209 `??' (dormant) and `?E' (expirable).
10210 If MARK is nil, then the default character `?r' is used.
10211 If ARTICLE is nil, then the article on the current line will be
10212 marked.
10213 If NO-EXPIRE, auto-expiry will be inhibited."
10214   ;; The mark might be a string.
10215   (when (stringp mark)
10216     (setq mark (aref mark 0)))
10217   ;; If no mark is given, then we check auto-expiring.
10218   (when (null mark)
10219     (setq mark gnus-del-mark))
10220   (when (and (not no-expire)
10221              gnus-newsgroup-auto-expire
10222              (memq mark gnus-auto-expirable-marks))
10223     (setq mark gnus-expirable-mark))
10224   (let ((article (or article (gnus-summary-article-number)))
10225         (old-mark (gnus-summary-article-mark article)))
10226     ;; Allow the backend to change the mark.
10227     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10228     (if (eq mark old-mark)
10229         t
10230       (unless article
10231         (error "No article on current line"))
10232       (if (not (if (or (= mark gnus-unread-mark)
10233                        (= mark gnus-ticked-mark)
10234                        (= mark gnus-spam-mark)
10235                        (= mark gnus-dormant-mark))
10236                    (gnus-mark-article-as-unread article mark)
10237                  (gnus-mark-article-as-read article mark)))
10238           t
10239         ;; See whether the article is to be put in the cache.
10240         (and gnus-use-cache
10241              (not (= mark gnus-canceled-mark))
10242              (vectorp (gnus-summary-article-header article))
10243              (save-excursion
10244                (gnus-cache-possibly-enter-article
10245                 gnus-newsgroup-name article
10246                 (gnus-summary-article-header article)
10247                 (= mark gnus-ticked-mark)
10248                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10249
10250         (when (gnus-summary-goto-subject article nil t)
10251           (let ((buffer-read-only nil))
10252             (gnus-summary-show-thread)
10253             ;; Fix the mark.
10254             (gnus-summary-update-mark mark 'unread)
10255             t))))))
10256
10257 (defun gnus-summary-update-secondary-mark (article)
10258   "Update the secondary (read, process, cache) mark."
10259   (gnus-summary-update-mark
10260    (cond ((memq article gnus-newsgroup-processable)
10261           gnus-process-mark)
10262          ((memq article gnus-newsgroup-cached)
10263           gnus-cached-mark)
10264          ((memq article gnus-newsgroup-replied)
10265           gnus-replied-mark)
10266          ((memq article gnus-newsgroup-forwarded)
10267           gnus-forwarded-mark)
10268          ((memq article gnus-newsgroup-saved)
10269           gnus-saved-mark)
10270          ((memq article gnus-newsgroup-recent)
10271           gnus-recent-mark)
10272          ((memq article gnus-newsgroup-unseen)
10273           gnus-unseen-mark)
10274          (t gnus-no-mark))
10275    'replied)
10276   (when (gnus-visual-p 'summary-highlight 'highlight)
10277     (gnus-run-hooks 'gnus-summary-update-hook))
10278   t)
10279
10280 (defun gnus-summary-update-download-mark (article)
10281   "Update the download mark."
10282   (gnus-summary-update-mark
10283    (cond ((memq article gnus-newsgroup-undownloaded)
10284           gnus-undownloaded-mark)
10285          (gnus-newsgroup-agentized
10286           gnus-downloaded-mark)
10287          (t
10288           gnus-no-mark))
10289    'download)
10290   (gnus-summary-update-line t)
10291   t)
10292
10293 (defun gnus-summary-update-mark (mark type)
10294   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10295         (buffer-read-only nil))
10296     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10297     (when forward
10298       (when (looking-at "\r")
10299         (incf forward))
10300       (when (<= (+ forward (point)) (point-max))
10301         ;; Go to the right position on the line.
10302         (goto-char (+ forward (point)))
10303         ;; Replace the old mark with the new mark.
10304         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10305         ;; Optionally update the marks by some user rule.
10306         (when (eq type 'unread)
10307           (gnus-data-set-mark
10308            (gnus-data-find (gnus-summary-article-number)) mark)
10309           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10310
10311 (defun gnus-mark-article-as-read (article &optional mark)
10312   "Enter ARTICLE in the pertinent lists and remove it from others."
10313   ;; Make the article expirable.
10314   (let ((mark (or mark gnus-del-mark)))
10315     (setq gnus-newsgroup-expirable
10316           (if (= mark gnus-expirable-mark)
10317               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10318             (delq article gnus-newsgroup-expirable)))
10319     ;; Remove from unread and marked lists.
10320     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10321     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10322     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10323     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10324     (push (cons article mark) gnus-newsgroup-reads)
10325     ;; Possibly remove from cache, if that is used.
10326     (when gnus-use-cache
10327       (gnus-cache-enter-remove-article article))
10328     t))
10329
10330 (defun gnus-mark-article-as-unread (article &optional mark)
10331   "Enter ARTICLE in the pertinent lists and remove it from others."
10332   (let ((mark (or mark gnus-ticked-mark)))
10333     (if (<= article 0)
10334         (progn
10335           (gnus-error 1 "Can't mark negative article numbers")
10336           nil)
10337       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10338             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10339             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10340             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10341             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10342
10343       ;; Unsuppress duplicates?
10344       (when gnus-suppress-duplicates
10345         (gnus-dup-unsuppress-article article))
10346
10347       (cond ((= mark gnus-ticked-mark)
10348              (setq gnus-newsgroup-marked
10349                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10350             ((= mark gnus-spam-mark)
10351              (setq gnus-newsgroup-spam-marked
10352                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10353                                             article)))
10354             ((= mark gnus-dormant-mark)
10355              (setq gnus-newsgroup-dormant
10356                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10357             (t
10358              (setq gnus-newsgroup-unreads
10359                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10360       (gnus-pull article gnus-newsgroup-reads)
10361       t)))
10362
10363 (defalias 'gnus-summary-mark-as-unread-forward
10364   'gnus-summary-tick-article-forward)
10365 (make-obsolete 'gnus-summary-mark-as-unread-forward
10366                'gnus-summary-tick-article-forward)
10367 (defun gnus-summary-tick-article-forward (n)
10368   "Tick N articles forwards.
10369 If N is negative, tick backwards instead.
10370 The difference between N and the number of articles ticked is returned."
10371   (interactive "p")
10372   (gnus-summary-mark-forward n gnus-ticked-mark))
10373
10374 (defalias 'gnus-summary-mark-as-unread-backward
10375   'gnus-summary-tick-article-backward)
10376 (make-obsolete 'gnus-summary-mark-as-unread-backward
10377                'gnus-summary-tick-article-backward)
10378 (defun gnus-summary-tick-article-backward (n)
10379   "Tick N articles backwards.
10380 The difference between N and the number of articles ticked is returned."
10381   (interactive "p")
10382   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10383
10384 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10385 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10386 (defun gnus-summary-tick-article (&optional article clear-mark)
10387   "Mark current article as unread.
10388 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10389 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10390   (interactive)
10391   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10392                                        gnus-ticked-mark)))
10393
10394 (defun gnus-summary-mark-as-read-forward (n)
10395   "Mark N articles as read forwards.
10396 If N is negative, mark backwards instead.
10397 The difference between N and the actual number of articles marked is
10398 returned."
10399   (interactive "p")
10400   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10401
10402 (defun gnus-summary-mark-as-read-backward (n)
10403   "Mark the N articles as read backwards.
10404 The difference between N and the actual number of articles marked is
10405 returned."
10406   (interactive "p")
10407   (gnus-summary-mark-forward
10408    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10409
10410 (defun gnus-summary-mark-as-read (&optional article mark)
10411   "Mark current article as read.
10412 ARTICLE specifies the article to be marked as read.
10413 MARK specifies a string to be inserted at the beginning of the line."
10414   (gnus-summary-mark-article article mark))
10415
10416 (defun gnus-summary-clear-mark-forward (n)
10417   "Clear marks from N articles forward.
10418 If N is negative, clear backward instead.
10419 The difference between N and the number of marks cleared is returned."
10420   (interactive "p")
10421   (gnus-summary-mark-forward n gnus-unread-mark))
10422
10423 (defun gnus-summary-clear-mark-backward (n)
10424   "Clear marks from N articles backward.
10425 The difference between N and the number of marks cleared is returned."
10426   (interactive "p")
10427   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10428
10429 (defun gnus-summary-mark-unread-as-read ()
10430   "Intended to be used by `gnus-summary-mark-article-hook'."
10431   (when (memq gnus-current-article gnus-newsgroup-unreads)
10432     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10433
10434 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10435   "Intended to be used by `gnus-summary-mark-article-hook'."
10436   (let ((mark (gnus-summary-article-mark)))
10437     (when (or (gnus-unread-mark-p mark)
10438               (gnus-read-mark-p mark))
10439       (gnus-summary-mark-article gnus-current-article
10440                                  (or new-mark gnus-read-mark)))))
10441
10442 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10443   "Intended to be used by `gnus-summary-mark-article-hook'."
10444   (let ((mark (gnus-summary-article-mark)))
10445     (when (or (gnus-unread-mark-p mark)
10446               (gnus-read-mark-p mark))
10447       (gnus-summary-mark-article (gnus-summary-article-number)
10448                                  (or new-mark gnus-read-mark)))))
10449
10450 (defun gnus-summary-mark-unread-as-ticked ()
10451   "Intended to be used by `gnus-summary-mark-article-hook'."
10452   (when (memq gnus-current-article gnus-newsgroup-unreads)
10453     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10454
10455 (defun gnus-summary-mark-region-as-read (point mark all)
10456   "Mark all unread articles between point and mark as read.
10457 If given a prefix, mark all articles between point and mark as read,
10458 even ticked and dormant ones."
10459   (interactive "r\nP")
10460   (save-excursion
10461     (let (article)
10462       (goto-char point)
10463       (beginning-of-line)
10464       (while (and
10465               (< (point) mark)
10466               (progn
10467                 (when (or all
10468                           (memq (setq article (gnus-summary-article-number))
10469                                 gnus-newsgroup-unreads))
10470                   (gnus-summary-mark-article article gnus-del-mark))
10471                 t)
10472               (gnus-summary-find-next))))))
10473
10474 (defun gnus-summary-mark-below (score mark)
10475   "Mark articles with score less than SCORE with MARK."
10476   (interactive "P\ncMark: ")
10477   (setq score (if score
10478                   (prefix-numeric-value score)
10479                 (or gnus-summary-default-score 0)))
10480   (save-excursion
10481     (set-buffer gnus-summary-buffer)
10482     (goto-char (point-min))
10483     (while
10484         (progn
10485           (and (< (gnus-summary-article-score) score)
10486                (gnus-summary-mark-article nil mark))
10487           (gnus-summary-find-next)))))
10488
10489 (defun gnus-summary-kill-below (&optional score)
10490   "Mark articles with score below SCORE as read."
10491   (interactive "P")
10492   (gnus-summary-mark-below score gnus-killed-mark))
10493
10494 (defun gnus-summary-clear-above (&optional score)
10495   "Clear all marks from articles with score above SCORE."
10496   (interactive "P")
10497   (gnus-summary-mark-above score gnus-unread-mark))
10498
10499 (defun gnus-summary-tick-above (&optional score)
10500   "Tick all articles with score above SCORE."
10501   (interactive "P")
10502   (gnus-summary-mark-above score gnus-ticked-mark))
10503
10504 (defun gnus-summary-mark-above (score mark)
10505   "Mark articles with score over SCORE with MARK."
10506   (interactive "P\ncMark: ")
10507   (setq score (if score
10508                   (prefix-numeric-value score)
10509                 (or gnus-summary-default-score 0)))
10510   (save-excursion
10511     (set-buffer gnus-summary-buffer)
10512     (goto-char (point-min))
10513     (while (and (progn
10514                   (when (> (gnus-summary-article-score) score)
10515                     (gnus-summary-mark-article nil mark))
10516                   t)
10517                 (gnus-summary-find-next)))))
10518
10519 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10520 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10521 (defun gnus-summary-limit-include-expunged (&optional no-error)
10522   "Display all the hidden articles that were expunged for low scores."
10523   (interactive)
10524   (let ((buffer-read-only nil))
10525     (let ((scored gnus-newsgroup-scored)
10526           headers h)
10527       (while scored
10528         (unless (gnus-summary-article-header (caar scored))
10529           (and (setq h (gnus-number-to-header (caar scored)))
10530                (< (cdar scored) gnus-summary-expunge-below)
10531                (push h headers)))
10532         (setq scored (cdr scored)))
10533       (if (not headers)
10534           (when (not no-error)
10535             (error "No expunged articles hidden"))
10536         (goto-char (point-min))
10537         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10538         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10539         (mapcar (lambda (x) (push (mail-header-number x)
10540                                   gnus-newsgroup-limit))
10541                 headers)
10542         (gnus-summary-prepare-unthreaded (nreverse headers))
10543         (goto-char (point-min))
10544         (gnus-summary-position-point)
10545         t))))
10546
10547 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10548   "Mark all unread articles in this newsgroup as read.
10549 If prefix argument ALL is non-nil, ticked and dormant articles will
10550 also be marked as read.
10551 If QUIETLY is non-nil, no questions will be asked.
10552
10553 If TO-HERE is non-nil, it should be a point in the buffer.  All
10554 articles before (after, if REVERSE is set) this point will be marked
10555 as read.
10556
10557 Note that this function will only catch up the unread article
10558 in the current summary buffer limitation.
10559
10560 The number of articles marked as read is returned."
10561   (interactive "P")
10562   (prog1
10563       (save-excursion
10564         (when (or quietly
10565                   (not gnus-interactive-catchup) ;Without confirmation?
10566                   gnus-expert-user
10567                   (gnus-y-or-n-p
10568                    (if all
10569                        "Mark absolutely all articles as read? "
10570                      "Mark all unread articles as read? ")))
10571           (if (and not-mark
10572                    (not gnus-newsgroup-adaptive)
10573                    (not gnus-newsgroup-auto-expire)
10574                    (not gnus-suppress-duplicates)
10575                    (or (not gnus-use-cache)
10576                        (eq gnus-use-cache 'passive)))
10577               (progn
10578                 (when all
10579                   (setq gnus-newsgroup-marked nil
10580                         gnus-newsgroup-spam-marked nil
10581                         gnus-newsgroup-dormant nil))
10582                 (setq gnus-newsgroup-unreads
10583                       (gnus-sorted-nunion
10584                        (gnus-intersection gnus-newsgroup-unreads
10585                                           gnus-newsgroup-downloadable)
10586                        gnus-newsgroup-unfetched)))
10587             ;; We actually mark all articles as canceled, which we
10588             ;; have to do when using auto-expiry or adaptive scoring.
10589             (gnus-summary-show-all-threads)
10590             (if (and to-here reverse)
10591                 (progn
10592                   (goto-char to-here)
10593                   (gnus-summary-mark-current-read-and-unread-as-read
10594                    gnus-catchup-mark)
10595                   (while (gnus-summary-find-next (not all))
10596                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10597               (when (gnus-summary-first-subject (not all))
10598                 (while (and
10599                         (if to-here (< (point) to-here) t)
10600                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10601                         (gnus-summary-find-next (not all))))))
10602             (gnus-set-mode-line 'summary))
10603           t))
10604     (gnus-summary-position-point)))
10605
10606 (defun gnus-summary-catchup-to-here (&optional all)
10607   "Mark all unticked articles before the current one as read.
10608 If ALL is non-nil, also mark ticked and dormant articles as read."
10609   (interactive "P")
10610   (save-excursion
10611     (gnus-save-hidden-threads
10612       (let ((beg (point)))
10613         ;; We check that there are unread articles.
10614         (when (or all (gnus-summary-find-prev))
10615           (gnus-summary-catchup all t beg)))))
10616   (gnus-summary-position-point))
10617
10618 (defun gnus-summary-catchup-from-here (&optional all)
10619   "Mark all unticked articles after (and including) the current one as read.
10620 If ALL is non-nil, also mark ticked and dormant articles as read."
10621   (interactive "P")
10622   (save-excursion
10623     (gnus-save-hidden-threads
10624       (let ((beg (point)))
10625         ;; We check that there are unread articles.
10626         (when (or all (gnus-summary-find-next))
10627           (gnus-summary-catchup all t beg nil t)))))
10628   (gnus-summary-position-point))
10629
10630 (defun gnus-summary-catchup-all (&optional quietly)
10631   "Mark all articles in this newsgroup as read.
10632 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10633 instead, which marks only unread articles as read."
10634   (interactive "P")
10635   (gnus-summary-catchup t quietly))
10636
10637 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10638   "Mark all unread articles in this group as read, then exit.
10639 If prefix argument ALL is non-nil, all articles are marked as read.
10640 If QUIETLY is non-nil, no questions will be asked."
10641   (interactive "P")
10642   (when (gnus-summary-catchup all quietly nil 'fast)
10643     ;; Select next newsgroup or exit.
10644     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10645              (eq gnus-auto-select-next 'quietly))
10646         (gnus-summary-next-group nil)
10647       (gnus-summary-exit))))
10648
10649 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10650   "Mark all articles in this newsgroup as read, and then exit.
10651 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10652 instead, which marks only unread articles as read."
10653   (interactive "P")
10654   (gnus-summary-catchup-and-exit t quietly))
10655
10656 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10657   "Mark all articles in this group as read and select the next group.
10658 If given a prefix, mark all articles, unread as well as ticked, as
10659 read."
10660   (interactive "P")
10661   (save-excursion
10662     (gnus-summary-catchup all))
10663   (gnus-summary-next-group))
10664
10665 ;;;
10666 ;;; with article
10667 ;;;
10668
10669 (defmacro gnus-with-article (article &rest forms)
10670   "Select ARTICLE and perform FORMS in the original article buffer.
10671 Then replace the article with the result."
10672   `(progn
10673      ;; We don't want the article to be marked as read.
10674      (let (gnus-mark-article-hook)
10675        (gnus-summary-select-article t t nil ,article))
10676      (set-buffer gnus-original-article-buffer)
10677      ,@forms
10678      (if (not (gnus-check-backend-function
10679                'request-replace-article (car gnus-article-current)))
10680          (gnus-message 5 "Read-only group; not replacing")
10681        (unless (gnus-request-replace-article
10682                 ,article (car gnus-article-current)
10683                 (current-buffer) t)
10684          (error "Couldn't replace article")))
10685      ;; The cache and backlog have to be flushed somewhat.
10686      (when gnus-keep-backlog
10687        (gnus-backlog-remove-article
10688         (car gnus-article-current) (cdr gnus-article-current)))
10689      (when gnus-use-cache
10690        (gnus-cache-update-article
10691         (car gnus-article-current) (cdr gnus-article-current)))))
10692
10693 (put 'gnus-with-article 'lisp-indent-function 1)
10694 (put 'gnus-with-article 'edebug-form-spec '(form body))
10695
10696 ;; Thread-based commands.
10697
10698 (defun gnus-summary-articles-in-thread (&optional article)
10699   "Return a list of all articles in the current thread.
10700 If ARTICLE is non-nil, return all articles in the thread that starts
10701 with that article."
10702   (let* ((article (or article (gnus-summary-article-number)))
10703          (data (gnus-data-find-list article))
10704          (top-level (gnus-data-level (car data)))
10705          (top-subject
10706           (cond ((null gnus-thread-operation-ignore-subject)
10707                  (gnus-simplify-subject-re
10708                   (mail-header-subject (gnus-data-header (car data)))))
10709                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10710                  (gnus-simplify-subject-fuzzy
10711                   (mail-header-subject (gnus-data-header (car data)))))
10712                 (t nil)))
10713          (end-point (save-excursion
10714                       (if (gnus-summary-go-to-next-thread)
10715                           (point) (point-max))))
10716          articles)
10717     (while (and data
10718                 (< (gnus-data-pos (car data)) end-point))
10719       (when (or (not top-subject)
10720                 (string= top-subject
10721                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10722                              (gnus-simplify-subject-fuzzy
10723                               (mail-header-subject
10724                                (gnus-data-header (car data))))
10725                            (gnus-simplify-subject-re
10726                             (mail-header-subject
10727                              (gnus-data-header (car data)))))))
10728         (push (gnus-data-number (car data)) articles))
10729       (unless (and (setq data (cdr data))
10730                    (> (gnus-data-level (car data)) top-level))
10731         (setq data nil)))
10732     ;; Return the list of articles.
10733     (nreverse articles)))
10734
10735 (defun gnus-summary-rethread-current ()
10736   "Rethread the thread the current article is part of."
10737   (interactive)
10738   (let* ((gnus-show-threads t)
10739          (article (gnus-summary-article-number))
10740          (id (mail-header-id (gnus-summary-article-header)))
10741          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10742     (unless id
10743       (error "No article on the current line"))
10744     (gnus-rebuild-thread id)
10745     (gnus-summary-goto-subject article)))
10746
10747 (defun gnus-summary-reparent-thread ()
10748   "Make the current article child of the marked (or previous) article.
10749
10750 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10751 is non-nil or the Subject: of both articles are the same."
10752   (interactive)
10753   (unless (not (gnus-group-read-only-p))
10754     (error "The current newsgroup does not support article editing"))
10755   (unless (<= (length gnus-newsgroup-processable) 1)
10756     (error "No more than one article may be marked"))
10757   (save-window-excursion
10758     (let ((gnus-article-buffer " *reparent*")
10759           (current-article (gnus-summary-article-number))
10760           ;; First grab the marked article, otherwise one line up.
10761           (parent-article (if (not (null gnus-newsgroup-processable))
10762                               (car gnus-newsgroup-processable)
10763                             (save-excursion
10764                               (if (eq (forward-line -1) 0)
10765                                   (gnus-summary-article-number)
10766                                 (error "Beginning of summary buffer"))))))
10767       (unless (not (eq current-article parent-article))
10768         (error "An article may not be self-referential"))
10769       (let ((message-id (mail-header-id
10770                          (gnus-summary-article-header parent-article))))
10771         (unless (and message-id (not (equal message-id "")))
10772           (error "No message-id in desired parent"))
10773         (gnus-with-article current-article
10774           (save-restriction
10775             (goto-char (point-min))
10776             (message-narrow-to-head)
10777             (if (re-search-forward "^References: " nil t)
10778                 (progn
10779                   (re-search-forward "^[^ \t]" nil t)
10780                   (forward-line -1)
10781                   (end-of-line)
10782                   (insert " " message-id))
10783               (insert "References: " message-id "\n"))))
10784         (set-buffer gnus-summary-buffer)
10785         (gnus-summary-unmark-all-processable)
10786         (gnus-summary-update-article current-article)
10787         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10788             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10789         (gnus-summary-rethread-current)
10790         (gnus-message 3 "Article %d is now the child of article %d"
10791                       current-article parent-article)))))
10792
10793 (defun gnus-summary-toggle-threads (&optional arg)
10794   "Toggle showing conversation threads.
10795 If ARG is positive number, turn showing conversation threads on."
10796   (interactive "P")
10797   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10798     (setq gnus-show-threads
10799           (if (null arg) (not gnus-show-threads)
10800             (> (prefix-numeric-value arg) 0)))
10801     (gnus-summary-prepare)
10802     (gnus-summary-goto-subject current)
10803     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10804     (gnus-summary-position-point)))
10805
10806 (defun gnus-summary-show-all-threads ()
10807   "Show all threads."
10808   (interactive)
10809   (save-excursion
10810     (let ((buffer-read-only nil))
10811       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10812   (gnus-summary-position-point))
10813
10814 (defun gnus-summary-show-thread ()
10815   "Show thread subtrees.
10816 Returns nil if no thread was there to be shown."
10817   (interactive)
10818   (let ((buffer-read-only nil)
10819         (orig (point))
10820         (end (point-at-eol))
10821         ;; Leave point at bol
10822         (beg (progn (beginning-of-line) (point))))
10823     (prog1
10824         ;; Any hidden lines here?
10825         (search-forward "\r" end t)
10826       (subst-char-in-region beg end ?\^M ?\n t)
10827       (goto-char orig)
10828       (gnus-summary-position-point))))
10829
10830 (defun gnus-summary-maybe-hide-threads ()
10831   "If requested, hide the threads that should be hidden."
10832   (when (and gnus-show-threads
10833              gnus-thread-hide-subtree)
10834     (gnus-summary-hide-all-threads
10835      (if (or (consp gnus-thread-hide-subtree)
10836              (functionp gnus-thread-hide-subtree))
10837          (gnus-make-predicate gnus-thread-hide-subtree)
10838        nil))))
10839
10840 ;;; Hiding predicates.
10841
10842 (defun gnus-article-unread-p (header)
10843   (memq (mail-header-number header) gnus-newsgroup-unreads))
10844
10845 (defun gnus-article-unseen-p (header)
10846   (memq (mail-header-number header) gnus-newsgroup-unseen))
10847
10848 (defun gnus-map-articles (predicate articles)
10849   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10850   (apply 'gnus-or (mapcar predicate
10851                           (mapcar 'gnus-summary-article-header articles))))
10852
10853 (defun gnus-summary-hide-all-threads (&optional predicate)
10854   "Hide all thread subtrees.
10855 If PREDICATE is supplied, threads that satisfy this predicate
10856 will not be hidden."
10857   (interactive)
10858   (save-excursion
10859     (goto-char (point-min))
10860     (let ((end nil))
10861       (while (not end)
10862         (when (or (not predicate)
10863                   (gnus-map-articles
10864                    predicate (gnus-summary-article-children)))
10865             (gnus-summary-hide-thread))
10866         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10867   (gnus-summary-position-point))
10868
10869 (defun gnus-summary-hide-thread ()
10870   "Hide thread subtrees.
10871 If PREDICATE is supplied, threads that satisfy this predicate
10872 will not be hidden.
10873 Returns nil if no threads were there to be hidden."
10874   (interactive)
10875   (let ((buffer-read-only nil)
10876         (start (point))
10877         (article (gnus-summary-article-number)))
10878     (goto-char start)
10879     ;; Go forward until either the buffer ends or the subthread
10880     ;; ends.
10881     (when (and (not (eobp))
10882                (or (zerop (gnus-summary-next-thread 1 t))
10883                    (goto-char (point-max))))
10884       (prog1
10885           (if (and (> (point) start)
10886                    (search-backward "\n" start t))
10887               (progn
10888                 (subst-char-in-region start (point) ?\n ?\^M)
10889                 (gnus-summary-goto-subject article))
10890             (goto-char start)
10891             nil)))))
10892
10893 (defun gnus-summary-go-to-next-thread (&optional previous)
10894   "Go to the same level (or less) next thread.
10895 If PREVIOUS is non-nil, go to previous thread instead.
10896 Return the article number moved to, or nil if moving was impossible."
10897   (let ((level (gnus-summary-thread-level))
10898         (way (if previous -1 1))
10899         (beg (point)))
10900     (forward-line way)
10901     (while (and (not (eobp))
10902                 (< level (gnus-summary-thread-level)))
10903       (forward-line way))
10904     (if (eobp)
10905         (progn
10906           (goto-char beg)
10907           nil)
10908       (setq beg (point))
10909       (prog1
10910           (gnus-summary-article-number)
10911         (goto-char beg)))))
10912
10913 (defun gnus-summary-next-thread (n &optional silent)
10914   "Go to the same level next N'th thread.
10915 If N is negative, search backward instead.
10916 Returns the difference between N and the number of skips actually
10917 done.
10918
10919 If SILENT, don't output messages."
10920   (interactive "p")
10921   (let ((backward (< n 0))
10922         (n (abs n)))
10923     (while (and (> n 0)
10924                 (gnus-summary-go-to-next-thread backward))
10925       (decf n))
10926     (unless silent
10927       (gnus-summary-position-point))
10928     (when (and (not silent) (/= 0 n))
10929       (gnus-message 7 "No more threads"))
10930     n))
10931
10932 (defun gnus-summary-prev-thread (n)
10933   "Go to the same level previous N'th thread.
10934 Returns the difference between N and the number of skips actually
10935 done."
10936   (interactive "p")
10937   (gnus-summary-next-thread (- n)))
10938
10939 (defun gnus-summary-go-down-thread ()
10940   "Go down one level in the current thread."
10941   (let ((children (gnus-summary-article-children)))
10942     (when children
10943       (gnus-summary-goto-subject (car children)))))
10944
10945 (defun gnus-summary-go-up-thread ()
10946   "Go up one level in the current thread."
10947   (let ((parent (gnus-summary-article-parent)))
10948     (when parent
10949       (gnus-summary-goto-subject parent))))
10950
10951 (defun gnus-summary-down-thread (n)
10952   "Go down thread N steps.
10953 If N is negative, go up instead.
10954 Returns the difference between N and how many steps down that were
10955 taken."
10956   (interactive "p")
10957   (let ((up (< n 0))
10958         (n (abs n)))
10959     (while (and (> n 0)
10960                 (if up (gnus-summary-go-up-thread)
10961                   (gnus-summary-go-down-thread)))
10962       (setq n (1- n)))
10963     (gnus-summary-position-point)
10964     (when (/= 0 n)
10965       (gnus-message 7 "Can't go further"))
10966     n))
10967
10968 (defun gnus-summary-up-thread (n)
10969   "Go up thread N steps.
10970 If N is negative, go down instead.
10971 Returns the difference between N and how many steps down that were
10972 taken."
10973   (interactive "p")
10974   (gnus-summary-down-thread (- n)))
10975
10976 (defun gnus-summary-top-thread ()
10977   "Go to the top of the thread."
10978   (interactive)
10979   (while (gnus-summary-go-up-thread))
10980   (gnus-summary-article-number))
10981
10982 (defun gnus-summary-kill-thread (&optional unmark)
10983   "Mark articles under current thread as read.
10984 If the prefix argument is positive, remove any kinds of marks.
10985 If the prefix argument is negative, tick articles instead."
10986   (interactive "P")
10987   (when unmark
10988     (setq unmark (prefix-numeric-value unmark)))
10989   (let ((articles (gnus-summary-articles-in-thread)))
10990     (save-excursion
10991       ;; Expand the thread.
10992       (gnus-summary-show-thread)
10993       ;; Mark all the articles.
10994       (while articles
10995         (gnus-summary-goto-subject (car articles))
10996         (cond ((null unmark)
10997                (gnus-summary-mark-article-as-read gnus-killed-mark))
10998               ((> unmark 0)
10999                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11000               (t
11001                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11002         (setq articles (cdr articles))))
11003     ;; Hide killed subtrees.
11004     (and (null unmark)
11005          gnus-thread-hide-killed
11006          (gnus-summary-hide-thread))
11007     ;; If marked as read, go to next unread subject.
11008     (when (null unmark)
11009       ;; Go to next unread subject.
11010       (gnus-summary-next-subject 1 t)))
11011   (gnus-set-mode-line 'summary))
11012
11013 ;; Summary sorting commands
11014
11015 (defun gnus-summary-sort-by-number (&optional reverse)
11016   "Sort the summary buffer by article number.
11017 Argument REVERSE means reverse order."
11018   (interactive "P")
11019   (gnus-summary-sort 'number reverse))
11020
11021 (defun gnus-summary-sort-by-random (&optional reverse)
11022   "Randomize the order in the summary buffer.
11023 Argument REVERSE means to randomize in reverse order."
11024   (interactive "P")
11025   (gnus-summary-sort 'random reverse))
11026
11027 (defun gnus-summary-sort-by-author (&optional reverse)
11028   "Sort the summary buffer by author name alphabetically.
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 'author reverse))
11033
11034 (defun gnus-summary-sort-by-recipient (&optional reverse)
11035   "Sort the summary buffer by recipient name alphabetically.
11036 If `case-fold-search' is non-nil, case of letters is ignored.
11037 Argument REVERSE means reverse order."
11038   (interactive "P")
11039   (gnus-summary-sort 'recipient reverse))
11040
11041 (defun gnus-summary-sort-by-subject (&optional reverse)
11042   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11043 If `case-fold-search' is non-nil, case of letters is ignored.
11044 Argument REVERSE means reverse order."
11045   (interactive "P")
11046   (gnus-summary-sort 'subject reverse))
11047
11048 (defun gnus-summary-sort-by-date (&optional reverse)
11049   "Sort the summary buffer by date.
11050 Argument REVERSE means reverse order."
11051   (interactive "P")
11052   (gnus-summary-sort 'date reverse))
11053
11054 (defun gnus-summary-sort-by-score (&optional reverse)
11055   "Sort the summary buffer by score.
11056 Argument REVERSE means reverse order."
11057   (interactive "P")
11058   (gnus-summary-sort 'score reverse))
11059
11060 (defun gnus-summary-sort-by-lines (&optional reverse)
11061   "Sort the summary buffer by the number of lines.
11062 Argument REVERSE means reverse order."
11063   (interactive "P")
11064   (gnus-summary-sort 'lines reverse))
11065
11066 (defun gnus-summary-sort-by-chars (&optional reverse)
11067   "Sort the summary buffer by article length.
11068 Argument REVERSE means reverse order."
11069   (interactive "P")
11070   (gnus-summary-sort 'chars reverse))
11071
11072 (defun gnus-summary-sort-by-original (&optional reverse)
11073   "Sort the summary buffer using the default sorting method.
11074 Argument REVERSE means reverse order."
11075   (interactive "P")
11076   (let* ((buffer-read-only)
11077          (gnus-summary-prepare-hook nil))
11078     ;; We do the sorting by regenerating the threads.
11079     (gnus-summary-prepare)
11080     ;; Hide subthreads if needed.
11081     (gnus-summary-maybe-hide-threads)))
11082
11083 (defun gnus-summary-sort (predicate reverse)
11084   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11085   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11086          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11087          (gnus-thread-sort-functions
11088           (if (not reverse)
11089               thread
11090             `(lambda (t1 t2)
11091                (,thread t2 t1))))
11092          (gnus-sort-gathered-threads-function
11093           gnus-thread-sort-functions)
11094          (gnus-article-sort-functions
11095           (if (not reverse)
11096               article
11097             `(lambda (t1 t2)
11098                (,article t2 t1))))
11099          (buffer-read-only)
11100          (gnus-summary-prepare-hook nil))
11101     ;; We do the sorting by regenerating the threads.
11102     (gnus-summary-prepare)
11103     ;; Hide subthreads if needed.
11104     (gnus-summary-maybe-hide-threads)))
11105
11106 ;; Summary saving commands.
11107
11108 (defun gnus-summary-save-article (&optional n not-saved)
11109   "Save the current article using the default saver function.
11110 If N is a positive number, save the N next articles.
11111 If N is a negative number, save the N previous articles.
11112 If N is nil and any articles have been marked with the process mark,
11113 save those articles instead.
11114 The variable `gnus-default-article-saver' specifies the saver function."
11115   (interactive "P")
11116   (let* ((articles (gnus-summary-work-articles n))
11117          (save-buffer (save-excursion
11118                         (nnheader-set-temp-buffer " *Gnus Save*")))
11119          (num (length articles))
11120          header file)
11121     (dolist (article articles)
11122       (setq header (gnus-summary-article-header article))
11123       (if (not (vectorp header))
11124           ;; This is a pseudo-article.
11125           (if (assq 'name header)
11126               (gnus-copy-file (cdr (assq 'name header)))
11127             (gnus-message 1 "Article %d is unsaveable" article))
11128         ;; This is a real article.
11129         (save-window-excursion
11130           (let ((gnus-display-mime-function nil)
11131                 (gnus-article-prepare-hook nil))
11132             (gnus-summary-select-article t nil nil article)))
11133         (save-excursion
11134           (set-buffer save-buffer)
11135           (erase-buffer)
11136           (insert-buffer-substring gnus-original-article-buffer))
11137         (setq file (gnus-article-save save-buffer file num))
11138         (gnus-summary-remove-process-mark article)
11139         (unless not-saved
11140           (gnus-summary-set-saved-mark article))))
11141     (gnus-kill-buffer save-buffer)
11142     (gnus-summary-position-point)
11143     (gnus-set-mode-line 'summary)
11144     n))
11145
11146 (defun gnus-summary-pipe-output (&optional arg headers)
11147   "Pipe the current article to a subprocess.
11148 If N is a positive number, pipe the N next articles.
11149 If N is a negative number, pipe the N previous articles.
11150 If N is nil and any articles have been marked with the process mark,
11151 pipe those articles instead.
11152 If HEADERS (the symbolic prefix), include the headers, too."
11153   (interactive (gnus-interactive "P\ny"))
11154   (require 'gnus-art)
11155   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11156         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11157     (gnus-summary-save-article arg t))
11158   (let ((buffer (get-buffer "*Shell Command Output*")))
11159     (when (and buffer
11160                (not (zerop (buffer-size buffer))))
11161       (gnus-configure-windows 'pipe))))
11162
11163 (defun gnus-summary-save-article-mail (&optional arg)
11164   "Append the current article to an mail file.
11165 If N is a positive number, save the N next articles.
11166 If N is a negative number, save the N previous articles.
11167 If N is nil and any articles have been marked with the process mark,
11168 save those articles instead."
11169   (interactive "P")
11170   (require 'gnus-art)
11171   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11172     (gnus-summary-save-article arg)))
11173
11174 (defun gnus-summary-save-article-rmail (&optional arg)
11175   "Append the current article to an rmail file.
11176 If N is a positive number, save the N next articles.
11177 If N is a negative number, save the N previous articles.
11178 If N is nil and any articles have been marked with the process mark,
11179 save those articles instead."
11180   (interactive "P")
11181   (require 'gnus-art)
11182   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11183     (gnus-summary-save-article arg)))
11184
11185 (defun gnus-summary-save-article-file (&optional arg)
11186   "Append the current article to a file.
11187 If N is a positive number, save the N next articles.
11188 If N is a negative number, save the N previous articles.
11189 If N is nil and any articles have been marked with the process mark,
11190 save those articles instead."
11191   (interactive "P")
11192   (require 'gnus-art)
11193   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11194     (gnus-summary-save-article arg)))
11195
11196 (defun gnus-summary-write-article-file (&optional arg)
11197   "Write the current article to a file, deleting the previous file.
11198 If N is a positive number, save the N next articles.
11199 If N is a negative number, save the N previous articles.
11200 If N is nil and any articles have been marked with the process mark,
11201 save those articles instead."
11202   (interactive "P")
11203   (require 'gnus-art)
11204   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11205     (gnus-summary-save-article arg)))
11206
11207 (defun gnus-summary-save-article-body-file (&optional arg)
11208   "Append the current article body to a file.
11209 If N is a positive number, save the N next articles.
11210 If N is a negative number, save the N previous articles.
11211 If N is nil and any articles have been marked with the process mark,
11212 save those articles instead."
11213   (interactive "P")
11214   (require 'gnus-art)
11215   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11216     (gnus-summary-save-article arg)))
11217
11218 (defun gnus-summary-muttprint (&optional arg)
11219   "Print the current article using Muttprint.
11220 If N is a positive number, save the N next articles.
11221 If N is a negative number, save the N previous articles.
11222 If N is nil and any articles have been marked with the process mark,
11223 save those articles instead."
11224   (interactive "P")
11225   (require 'gnus-art)
11226   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11227     (gnus-summary-save-article arg t)))
11228
11229 (defun gnus-summary-pipe-message (program)
11230   "Pipe the current article through PROGRAM."
11231   (interactive "sProgram: ")
11232   (gnus-summary-select-article)
11233   (let ((mail-header-separator ""))
11234     (gnus-eval-in-buffer-window gnus-article-buffer
11235       (save-restriction
11236         (widen)
11237         (let ((start (window-start))
11238               buffer-read-only)
11239           (message-pipe-buffer-body program)
11240           (set-window-start (get-buffer-window (current-buffer)) start))))))
11241
11242 (defun gnus-get-split-value (methods)
11243   "Return a value based on the split METHODS."
11244   (let (split-name method result match)
11245     (when methods
11246       (save-excursion
11247         (set-buffer gnus-original-article-buffer)
11248         (save-restriction
11249           (nnheader-narrow-to-headers)
11250           (while (and methods (not split-name))
11251             (goto-char (point-min))
11252             (setq method (pop methods))
11253             (setq match (car method))
11254             (when (cond
11255                    ((stringp match)
11256                     ;; Regular expression.
11257                     (ignore-errors
11258                       (re-search-forward match nil t)))
11259                    ((functionp match)
11260                     ;; Function.
11261                     (save-restriction
11262                       (widen)
11263                       (setq result (funcall match gnus-newsgroup-name))))
11264                    ((consp match)
11265                     ;; Form.
11266                     (save-restriction
11267                       (widen)
11268                       (setq result (eval match)))))
11269               (setq split-name (cdr method))
11270               (cond ((stringp result)
11271                      (push (expand-file-name
11272                             result gnus-article-save-directory)
11273                            split-name))
11274                     ((consp result)
11275                      (setq split-name (append result split-name)))))))))
11276     (nreverse split-name)))
11277
11278 (defun gnus-valid-move-group-p (group)
11279   (and (boundp group)
11280        (symbol-name group)
11281        (symbol-value group)
11282        (gnus-get-function (gnus-find-method-for-group
11283                            (symbol-name group)) 'request-accept-article t)))
11284
11285 (defun gnus-read-move-group-name (prompt default articles prefix)
11286   "Read a group name."
11287   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11288          (minibuffer-confirm-incomplete nil) ; XEmacs
11289          (prom
11290           (format "%s %s to"
11291                   prompt
11292                   (if (> (length articles) 1)
11293                       (format "these %d articles" (length articles))
11294                     "this article")))
11295          (to-newsgroup
11296           (cond
11297            ((null split-name)
11298             (gnus-completing-read-with-default
11299              default prom
11300              gnus-active-hashtb
11301              'gnus-valid-move-group-p
11302              nil prefix
11303              'gnus-group-history))
11304            ((= 1 (length split-name))
11305             (gnus-completing-read-with-default
11306              (car split-name) prom
11307              gnus-active-hashtb
11308              'gnus-valid-move-group-p
11309              nil nil
11310              'gnus-group-history))
11311            (t
11312             (gnus-completing-read-with-default
11313              nil prom
11314              (mapcar 'list (nreverse split-name))
11315              nil nil nil
11316              'gnus-group-history))))
11317          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11318     (when to-newsgroup
11319       (if (or (string= to-newsgroup "")
11320               (string= to-newsgroup prefix))
11321           (setq to-newsgroup default))
11322       (unless to-newsgroup
11323         (error "No group name entered"))
11324       (or (gnus-active to-newsgroup)
11325           (gnus-activate-group to-newsgroup nil nil to-method)
11326           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11327                                      to-newsgroup))
11328               (or (and (gnus-request-create-group to-newsgroup to-method)
11329                        (gnus-activate-group
11330                         to-newsgroup nil nil to-method)
11331                        (gnus-subscribe-group to-newsgroup))
11332                   (error "Couldn't create group %s" to-newsgroup)))
11333           (error "No such group: %s" to-newsgroup)))
11334     to-newsgroup))
11335
11336 (defun gnus-summary-save-parts (type dir n &optional reverse)
11337   "Save parts matching TYPE to DIR.
11338 If REVERSE, save parts that do not match TYPE."
11339   (interactive
11340    (list (read-string "Save parts of type: "
11341                       (or (car gnus-summary-save-parts-type-history)
11342                           gnus-summary-save-parts-default-mime)
11343                       'gnus-summary-save-parts-type-history)
11344          (setq gnus-summary-save-parts-last-directory
11345                (read-file-name "Save to directory: "
11346                                gnus-summary-save-parts-last-directory
11347                                nil t))
11348          current-prefix-arg))
11349   (gnus-summary-iterate n
11350     (let ((gnus-display-mime-function nil)
11351           (gnus-inhibit-treatment t))
11352       (gnus-summary-select-article))
11353     (save-excursion
11354       (set-buffer gnus-article-buffer)
11355       (let ((handles (or gnus-article-mime-handles
11356                          (mm-dissect-buffer nil gnus-article-loose-mime)
11357                          (and gnus-article-emulate-mime
11358                               (mm-uu-dissect)))))
11359         (when handles
11360           (gnus-summary-save-parts-1 type dir handles reverse)
11361           (unless gnus-article-mime-handles ;; Don't destroy this case.
11362             (mm-destroy-parts handles)))))))
11363
11364 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11365   (if (stringp (car handle))
11366       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11367               (cdr handle))
11368     (when (if reverse
11369               (not (string-match type (mm-handle-media-type handle)))
11370             (string-match type (mm-handle-media-type handle)))
11371       (let ((file (expand-file-name
11372                    (gnus-map-function
11373                     mm-file-name-rewrite-functions
11374                     (file-name-nondirectory
11375                      (or
11376                       (mail-content-type-get
11377                        (mm-handle-disposition handle) 'filename)
11378                       (mail-content-type-get
11379                        (mm-handle-type handle) 'name)
11380                       (concat gnus-newsgroup-name
11381                               "." (number-to-string
11382                                    (cdr gnus-article-current))))))
11383                    dir)))
11384         (unless (file-exists-p file)
11385           (mm-save-part-to-file handle file))))))
11386
11387 ;; Summary extract commands
11388
11389 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11390   (let ((buffer-read-only nil)
11391         (article (gnus-summary-article-number))
11392         after-article b e)
11393     (unless (gnus-summary-goto-subject article)
11394       (error "No such article: %d" article))
11395     (gnus-summary-position-point)
11396     ;; If all commands are to be bunched up on one line, we collect
11397     ;; them here.
11398     (unless gnus-view-pseudos-separately
11399       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11400             files action)
11401         (while ps
11402           (setq action (cdr (assq 'action (car ps))))
11403           (setq files (list (cdr (assq 'name (car ps)))))
11404           (while (and ps (cdr ps)
11405                       (string= (or action "1")
11406                                (or (cdr (assq 'action (cadr ps))) "2")))
11407             (push (cdr (assq 'name (cadr ps))) files)
11408             (setcdr ps (cddr ps)))
11409           (when files
11410             (when (not (string-match "%s" action))
11411               (push " " files))
11412             (push " " files)
11413             (when (assq 'execute (car ps))
11414               (setcdr (assq 'execute (car ps))
11415                       (funcall (if (string-match "%s" action)
11416                                    'format 'concat)
11417                                action
11418                                (mapconcat
11419                                 (lambda (f)
11420                                   (if (equal f " ")
11421                                       f
11422                                     (shell-quote-argument f)))
11423                                 files " ")))))
11424           (setq ps (cdr ps)))))
11425     (if (and gnus-view-pseudos (not not-view))
11426         (while pslist
11427           (when (assq 'execute (car pslist))
11428             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11429                                   (eq gnus-view-pseudos 'not-confirm)))
11430           (setq pslist (cdr pslist)))
11431       (save-excursion
11432         (while pslist
11433           (setq after-article (or (cdr (assq 'article (car pslist)))
11434                                   (gnus-summary-article-number)))
11435           (gnus-summary-goto-subject after-article)
11436           (forward-line 1)
11437           (setq b (point))
11438           (insert "    " (file-name-nondirectory
11439                           (cdr (assq 'name (car pslist))))
11440                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11441           (setq e (point))
11442           (forward-line -1)             ; back to `b'
11443           (gnus-add-text-properties
11444            b (1- e) (list 'gnus-number gnus-reffed-article-number
11445                           gnus-mouse-face-prop gnus-mouse-face))
11446           (gnus-data-enter
11447            after-article gnus-reffed-article-number
11448            gnus-unread-mark b (car pslist) 0 (- e b))
11449           (setq gnus-newsgroup-unreads
11450                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11451                                          gnus-reffed-article-number))
11452           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11453           (setq pslist (cdr pslist)))))))
11454
11455 (defun gnus-pseudos< (p1 p2)
11456   (let ((c1 (cdr (assq 'action p1)))
11457         (c2 (cdr (assq 'action p2))))
11458     (and c1 c2 (string< c1 c2))))
11459
11460 (defun gnus-request-pseudo-article (props)
11461   (cond ((assq 'execute props)
11462          (gnus-execute-command (cdr (assq 'execute props)))))
11463   (let ((gnus-current-article (gnus-summary-article-number)))
11464     (gnus-run-hooks 'gnus-mark-article-hook)))
11465
11466 (defun gnus-execute-command (command &optional automatic)
11467   (save-excursion
11468     (gnus-article-setup-buffer)
11469     (set-buffer gnus-article-buffer)
11470     (setq buffer-read-only nil)
11471     (let ((command (if automatic command
11472                      (read-string "Command: " (cons command 0)))))
11473       (erase-buffer)
11474       (insert "$ " command "\n\n")
11475       (if gnus-view-pseudo-asynchronously
11476           (start-process "gnus-execute" (current-buffer) shell-file-name
11477                          shell-command-switch command)
11478         (call-process shell-file-name nil t nil
11479                       shell-command-switch command)))))
11480
11481 ;; Summary kill commands.
11482
11483 (defun gnus-summary-edit-global-kill (article)
11484   "Edit the \"global\" kill file."
11485   (interactive (list (gnus-summary-article-number)))
11486   (gnus-group-edit-global-kill article))
11487
11488 (defun gnus-summary-edit-local-kill ()
11489   "Edit a local kill file applied to the current newsgroup."
11490   (interactive)
11491   (setq gnus-current-headers (gnus-summary-article-header))
11492   (gnus-group-edit-local-kill
11493    (gnus-summary-article-number) gnus-newsgroup-name))
11494
11495 ;;; Header reading.
11496
11497 (defun gnus-read-header (id &optional header)
11498   "Read the headers of article ID and enter them into the Gnus system."
11499   (let ((group gnus-newsgroup-name)
11500         (gnus-override-method
11501          (or
11502           gnus-override-method
11503           (and (gnus-news-group-p gnus-newsgroup-name)
11504                (car (gnus-refer-article-methods)))))
11505         where)
11506     ;; First we check to see whether the header in question is already
11507     ;; fetched.
11508     (if (stringp id)
11509         ;; This is a Message-ID.
11510         (setq header (or header (gnus-id-to-header id)))
11511       ;; This is an article number.
11512       (setq header (or header (gnus-summary-article-header id))))
11513     (if (and header
11514              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11515         ;; We have found the header.
11516         header
11517       ;; We have to really fetch the header to this article.
11518       (save-excursion
11519         (set-buffer nntp-server-buffer)
11520         (when (setq where (gnus-request-head id group))
11521           (nnheader-fold-continuation-lines)
11522           (goto-char (point-max))
11523           (insert ".\n")
11524           (goto-char (point-min))
11525           (insert "211 ")
11526           (princ (cond
11527                   ((numberp id) id)
11528                   ((cdr where) (cdr where))
11529                   (header (mail-header-number header))
11530                   (t gnus-reffed-article-number))
11531                  (current-buffer))
11532           (insert " Article retrieved.\n"))
11533         (if (or (not where)
11534                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11535             ()                          ; Malformed head.
11536           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11537             (when (and (stringp id)
11538                        (not (string= (gnus-group-real-name group)
11539                                      (car where))))
11540               ;; If we fetched by Message-ID and the article came
11541               ;; from a different group, we fudge some bogus article
11542               ;; numbers for this article.
11543               (mail-header-set-number header gnus-reffed-article-number))
11544             (save-excursion
11545               (set-buffer gnus-summary-buffer)
11546               (decf gnus-reffed-article-number)
11547               (gnus-remove-header (mail-header-number header))
11548               (push header gnus-newsgroup-headers)
11549               (setq gnus-current-headers header)
11550               (push (mail-header-number header) gnus-newsgroup-limit)))
11551           header)))))
11552
11553 (defun gnus-remove-header (number)
11554   "Remove header NUMBER from `gnus-newsgroup-headers'."
11555   (if (and gnus-newsgroup-headers
11556            (= number (mail-header-number (car gnus-newsgroup-headers))))
11557       (pop gnus-newsgroup-headers)
11558     (let ((headers gnus-newsgroup-headers))
11559       (while (and (cdr headers)
11560                   (not (= number (mail-header-number (cadr headers)))))
11561         (pop headers))
11562       (when (cdr headers)
11563         (setcdr headers (cddr headers))))))
11564
11565 ;;;
11566 ;;; summary highlights
11567 ;;;
11568
11569 (defun gnus-highlight-selected-summary ()
11570   "Highlight selected article in summary buffer."
11571   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11572   (when gnus-summary-selected-face
11573     (save-excursion
11574       (let* ((beg (point-at-bol))
11575              (end (point-at-eol))
11576              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11577              (from (if (get-text-property beg gnus-mouse-face-prop)
11578                        beg
11579                      (or (next-single-property-change
11580                           beg gnus-mouse-face-prop nil end)
11581                          beg)))
11582              (to
11583               (if (= from end)
11584                   (- from 2)
11585                 (or (next-single-property-change
11586                      from gnus-mouse-face-prop nil end)
11587                     end))))
11588         ;; If no mouse-face prop on line we will have to = from = end,
11589         ;; so we highlight the entire line instead.
11590         (when (= (+ to 2) from)
11591           (setq from beg)
11592           (setq to end))
11593         (if gnus-newsgroup-selected-overlay
11594             ;; Move old overlay.
11595             (gnus-move-overlay
11596              gnus-newsgroup-selected-overlay from to (current-buffer))
11597           ;; Create new overlay.
11598           (gnus-overlay-put
11599            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11600            'face gnus-summary-selected-face))))))
11601
11602 (defvar gnus-summary-highlight-line-cached nil)
11603 (defvar gnus-summary-highlight-line-trigger nil)
11604
11605 (defun gnus-summary-highlight-line-0 ()
11606   (if (and (eq gnus-summary-highlight-line-trigger
11607                gnus-summary-highlight)
11608            gnus-summary-highlight-line-cached)
11609       gnus-summary-highlight-line-cached
11610     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11611           gnus-summary-highlight-line-cached
11612           (let* ((cond (list 'cond))
11613                  (c cond)
11614                  (list gnus-summary-highlight))
11615             (while list
11616               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11617                               nil))
11618               (setq c (cdr c)
11619                     list (cdr list)))
11620             (gnus-byte-compile (list 'lambda nil cond))))))
11621
11622 (defun gnus-summary-highlight-line ()
11623   "Highlight current line according to `gnus-summary-highlight'."
11624   (let* ((beg (point-at-bol))
11625          (article (or (gnus-summary-article-number) gnus-current-article))
11626          (score (or (cdr (assq article
11627                                gnus-newsgroup-scored))
11628                     gnus-summary-default-score 0))
11629          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11630          (inhibit-read-only t)
11631          (default gnus-summary-default-score)
11632          (default-high gnus-summary-default-high-score)
11633          (default-low gnus-summary-default-low-score)
11634          (uncached (and gnus-summary-use-undownloaded-faces
11635                         (memq article gnus-newsgroup-undownloaded)
11636                         (not (memq article gnus-newsgroup-cached)))))
11637     (let ((face (funcall (gnus-summary-highlight-line-0))))
11638       (unless (eq face (get-text-property beg 'face))
11639         (gnus-put-text-property-excluding-characters-with-faces
11640          beg (point-at-eol) 'face
11641          (setq face (if (boundp face) (symbol-value face) face)))
11642         (when gnus-summary-highlight-line-function
11643           (funcall gnus-summary-highlight-line-function article face))))))
11644
11645 (defun gnus-update-read-articles (group unread &optional compute)
11646   "Update the list of read articles in GROUP.
11647 UNREAD is a sorted list."
11648   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11649         (info (gnus-get-info group))
11650         (prev 1)
11651         read)
11652     (if (or (not info) (not active))
11653         ;; There is no info on this group if it was, in fact,
11654         ;; killed.  Gnus stores no information on killed groups, so
11655         ;; there's nothing to be done.
11656         ;; One could store the information somewhere temporarily,
11657         ;; perhaps...  Hmmm...
11658         ()
11659       ;; Remove any negative articles numbers.
11660       (while (and unread (< (car unread) 0))
11661         (setq unread (cdr unread)))
11662       ;; Remove any expired article numbers
11663       (while (and unread (< (car unread) (car active)))
11664         (setq unread (cdr unread)))
11665       ;; Compute the ranges of read articles by looking at the list of
11666       ;; unread articles.
11667       (while unread
11668         (when (/= (car unread) prev)
11669           (push (if (= prev (1- (car unread))) prev
11670                   (cons prev (1- (car unread))))
11671                 read))
11672         (setq prev (1+ (car unread)))
11673         (setq unread (cdr unread)))
11674       (when (<= prev (cdr active))
11675         (push (cons prev (cdr active)) read))
11676       (setq read (if (> (length read) 1) (nreverse read) read))
11677       (if compute
11678           read
11679         (save-excursion
11680           (let (setmarkundo)
11681             ;; Propagate the read marks to the backend.
11682             (when (gnus-check-backend-function 'request-set-mark group)
11683               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11684                     (add (gnus-remove-from-range read (gnus-info-read info))))
11685                 (when (or add del)
11686                   (unless (gnus-check-group group)
11687                     (error "Can't open server for %s" group))
11688                   (gnus-request-set-mark
11689                    group (delq nil (list (if add (list add 'add '(read)))
11690                                          (if del (list del 'del '(read))))))
11691                   (setq setmarkundo
11692                         `(gnus-request-set-mark
11693                           ,group
11694                           ',(delq nil (list
11695                                        (if del (list del 'add '(read)))
11696                                        (if add (list add 'del '(read))))))))))
11697             (set-buffer gnus-group-buffer)
11698             (gnus-undo-register
11699               `(progn
11700                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11701                  (gnus-info-set-read ',info ',(gnus-info-read info))
11702                  (gnus-get-unread-articles-in-group ',info
11703                                                     (gnus-active ,group))
11704                  (gnus-group-update-group ,group t)
11705                  ,setmarkundo))))
11706         ;; Enter this list into the group info.
11707         (gnus-info-set-read info read)
11708         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11709         (gnus-get-unread-articles-in-group info (gnus-active group))
11710         t))))
11711
11712 (defun gnus-offer-save-summaries ()
11713   "Offer to save all active summary buffers."
11714   (let (buffers)
11715     ;; Go through all buffers and find all summaries.
11716     (dolist (buffer (buffer-list))
11717       (when (and (setq buffer (buffer-name buffer))
11718                  (string-match "Summary" buffer)
11719                  (with-current-buffer buffer
11720                    ;; We check that this is, indeed, a summary buffer.
11721                    (and (eq major-mode 'gnus-summary-mode)
11722                         ;; Also make sure this isn't bogus.
11723                         gnus-newsgroup-prepared
11724                         ;; Also make sure that this isn't a
11725                         ;; dead summary buffer.
11726                         (not gnus-dead-summary-mode))))
11727         (push buffer buffers)))
11728     ;; Go through all these summary buffers and offer to save them.
11729     (when buffers
11730       (save-excursion
11731         (map-y-or-n-p
11732          "Update summary buffer %s? "
11733          (lambda (buf)
11734            (switch-to-buffer buf)
11735            (gnus-summary-exit))
11736          buffers)))))
11737
11738
11739 ;;; @ for mime-partial
11740 ;;;
11741
11742 (defun gnus-request-partial-message ()
11743   (save-excursion
11744     (let ((number (gnus-summary-article-number))
11745           (group gnus-newsgroup-name)
11746           (mother gnus-article-buffer))
11747       (set-buffer (get-buffer-create " *Partial Article*"))
11748       (erase-buffer)
11749       (setq mime-preview-buffer mother)
11750       (gnus-request-article-this-buffer number group)
11751       (mime-parse-buffer)
11752       )))
11753
11754 (autoload 'mime-combine-message/partial-pieces-automatically
11755   "mime-partial"
11756   "Internal method to combine message/partial messages automatically.")
11757
11758 (mime-add-condition
11759  'action '((type . message)(subtype . partial)
11760            (major-mode . gnus-original-article-mode)
11761            (method . mime-combine-message/partial-pieces-automatically)
11762            (summary-buffer-exp . gnus-summary-buffer)
11763            (request-partial-message-method . gnus-request-partial-message)
11764            ))
11765
11766
11767 ;;; @ for message/rfc822
11768 ;;;
11769
11770 (defun gnus-mime-extract-message/rfc822 (entity situation)
11771   "Burst a forwarded article."
11772   (save-excursion
11773     (set-buffer gnus-summary-buffer)
11774     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11775                                    gnus-newsgroup-name 'gnus-group-history))
11776            (gnus-group-marked (list group))
11777            article info)
11778       (with-temp-buffer
11779         (mime-insert-entity-content entity)
11780         (setq article (gnus-request-accept-article group)))
11781       (when (and (consp article)
11782                  (numberp (setq article (cdr article))))
11783         (setq info (gnus-get-info group))
11784         (gnus-info-set-read info
11785                             (gnus-remove-from-range (gnus-info-read info)
11786                                                     (list article)))
11787         (when (string-equal group gnus-newsgroup-name)
11788           (forward-line 1)
11789           (let (gnus-show-threads)
11790             (gnus-summary-goto-subject article t))
11791           (gnus-summary-clear-mark-forward 1))
11792         (set-buffer gnus-group-buffer)
11793         (gnus-group-get-new-news-this-group nil t)))))
11794
11795 (mime-add-condition
11796  'action '((type . message)(subtype . rfc822)
11797            (major-mode . gnus-original-article-mode)
11798            (method . gnus-mime-extract-message/rfc822)
11799            (mode . "extract")
11800            ))
11801
11802 (mime-add-condition
11803  'action '((type . message)(subtype . news)
11804            (major-mode . gnus-original-article-mode)
11805            (method . gnus-mime-extract-message/rfc822)
11806            (mode . "extract")
11807            ))
11808
11809 (defun gnus-mime-extract-multipart (entity situation)
11810   (let ((children (mime-entity-children entity))
11811         mime-acting-situation-to-override
11812         f)
11813     (while children
11814       (mime-play-entity (car children)
11815                         (cons (assq 'mode situation)
11816                               mime-acting-situation-to-override))
11817       (setq children (cdr children)))
11818     (if (setq f (cdr (assq 'after-method
11819                            mime-acting-situation-to-override)))
11820         (eval f)
11821       )))
11822
11823 (mime-add-condition
11824  'action '((type . multipart)
11825            (method . gnus-mime-extract-multipart)
11826            (mode . "extract")
11827            )
11828  'with-default)
11829
11830
11831 ;;; @ end
11832 ;;;
11833
11834 (defun gnus-summary-inherit-default-charset ()
11835   "Import `default-mime-charset' from summary buffer.
11836 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11837 of FLIM is used."
11838   (if (buffer-live-p gnus-summary-buffer)
11839       (let (d-m-c d-m-c-u)
11840         (with-current-buffer gnus-summary-buffer
11841           (setq d-m-c (if (local-variable-p 'default-mime-charset
11842                                             gnus-summary-buffer)
11843                           default-mime-charset
11844                         t)
11845                 ;; LIMIT
11846                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11847                                               gnus-summary-buffer)
11848                             (symbol-value 'default-mime-charset-unlimited)
11849                           t)))
11850         (if (eq t d-m-c)
11851             (kill-local-variable 'default-mime-charset)
11852           (set (make-local-variable 'default-mime-charset) d-m-c))
11853         (if (eq t d-m-c-u)
11854             (kill-local-variable 'default-mime-charset-unlimited)
11855           (set (make-local-variable 'default-mime-charset-unlimited)
11856                d-m-c-u)))))
11857
11858 (defun gnus-summary-setup-default-charset ()
11859   "Setup newsgroup default charset."
11860   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11861       (progn
11862         (setq gnus-newsgroup-charset nil)
11863         (set (make-local-variable 'default-mime-charset) nil)
11864         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11865           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11866     (let ((ignored-charsets
11867            (or gnus-newsgroup-ephemeral-ignored-charsets
11868                (append
11869                 (and gnus-newsgroup-name
11870                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11871                 gnus-newsgroup-ignored-charsets)))
11872           charset)
11873       (setq gnus-newsgroup-charset
11874             (or gnus-newsgroup-ephemeral-charset
11875                 (when (and gnus-newsgroup-name
11876                            (setq charset (gnus-parameter-charset
11877                                           gnus-newsgroup-name)))
11878                   (make-local-variable 'default-mime-charset)
11879                   (setq default-mime-charset charset))
11880                 gnus-default-charset))
11881       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11882            ignored-charsets))))
11883
11884 ;;;
11885 ;;; Mime Commands
11886 ;;;
11887
11888 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11889   "Display the current article buffer fully MIME-buttonized.
11890 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11891 treated as multipart/mixed."
11892   (interactive "P")
11893   (require 'gnus-art)
11894   (let ((gnus-unbuttonized-mime-types nil)
11895         (gnus-mime-display-multipart-as-mixed show-all-parts))
11896     (gnus-summary-show-article)))
11897
11898 (defun gnus-summary-repair-multipart (article)
11899   "Add a Content-Type header to a multipart article without one."
11900   (interactive (list (gnus-summary-article-number)))
11901   (gnus-with-article article
11902     (message-narrow-to-head)
11903     (message-remove-header "Mime-Version")
11904     (goto-char (point-max))
11905     (insert "Mime-Version: 1.0\n")
11906     (widen)
11907     (when (search-forward "\n--" nil t)
11908       (let ((separator (buffer-substring (point) (point-at-eol))))
11909         (message-narrow-to-head)
11910         (message-remove-header "Content-Type")
11911         (goto-char (point-max))
11912         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11913                         separator))
11914         (widen))))
11915   (let (gnus-mark-article-hook)
11916     (gnus-summary-select-article t t nil article)))
11917
11918 (defun gnus-summary-toggle-display-buttonized ()
11919   "Toggle the buttonizing of the article buffer."
11920   (interactive)
11921   (require 'gnus-art)
11922   (if (setq gnus-inhibit-mime-unbuttonizing
11923             (not gnus-inhibit-mime-unbuttonizing))
11924       (let ((gnus-unbuttonized-mime-types nil))
11925         (gnus-summary-show-article))
11926     (gnus-summary-show-article)))
11927
11928 ;;;
11929 ;;; Intelli-mouse commmands
11930 ;;;
11931
11932 (defun gnus-wheel-summary-scroll (event)
11933   (interactive "e")
11934   (let ((amount (if (memq 'shift (event-modifiers event))
11935                     (car gnus-wheel-scroll-amount)
11936                   (cdr gnus-wheel-scroll-amount)))
11937         (direction (- (* (static-if (featurep 'xemacs)
11938                              (event-button event)
11939                            (cond ((eq 'mouse-4 (event-basic-type event))
11940                                   4)
11941                                  ((eq 'mouse-5 (event-basic-type event))
11942                                   5)))
11943                          2) 9))
11944         edge)
11945     (gnus-summary-scroll-up (* amount direction))
11946     (when (gnus-eval-in-buffer-window gnus-article-buffer
11947             (save-restriction
11948               (widen)
11949               (and (if (< 0 direction)
11950                        (gnus-article-next-page 0)
11951                      (gnus-article-prev-page 0)
11952                      (bobp))
11953                    (if (setq edge (get-text-property
11954                                    (point-min) 'gnus-wheel-edge))
11955                        (setq edge (* edge direction))
11956                      (setq edge -1))
11957                    (or (plusp edge)
11958                        (let ((buffer-read-only nil)
11959                              (inhibit-read-only t))
11960                          (put-text-property (point-min) (point-max)
11961                                             'gnus-wheel-edge direction)
11962                          nil))
11963                    (or (> edge gnus-wheel-edge-resistance)
11964                        (let ((buffer-read-only nil)
11965                              (inhibit-read-only t))
11966                          (put-text-property (point-min) (point-max)
11967                                             'gnus-wheel-edge
11968                                             (* (1+ edge) direction))
11969                          nil))
11970                    (eq last-command 'gnus-wheel-summary-scroll))))
11971       (gnus-summary-next-article nil nil (minusp direction)))))
11972
11973 (defun gnus-wheel-install ()
11974   "Enable mouse wheel support on summary window."
11975   (when gnus-use-wheel
11976     (let ((keys
11977            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11978       (dolist (key keys)
11979         (define-key gnus-summary-mode-map key
11980           'gnus-wheel-summary-scroll)))))
11981
11982 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11983
11984 ;;;
11985 ;;; Traditional PGP commmands
11986 ;;;
11987
11988 (defun gnus-summary-decrypt-article (&optional force)
11989   "Decrypt the current article in traditional PGP way.
11990 This will have permanent effect only in mail groups.
11991 If FORCE is non-nil, allow editing of articles even in read-only
11992 groups."
11993   (interactive "P")
11994   (gnus-summary-select-article t)
11995   (gnus-eval-in-buffer-window gnus-article-buffer
11996     (save-excursion
11997       (save-restriction
11998         (widen)
11999         (goto-char (point-min))
12000         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
12001           (error "Not a traditional PGP message!"))
12002         (let ((armor-start (match-beginning 0)))
12003           (if (and (pgg-decrypt-region armor-start (point-max))
12004                    (or force (not (gnus-group-read-only-p))))
12005               (let ((inhibit-read-only t)
12006                     buffer-read-only)
12007                 (delete-region armor-start
12008                                (progn
12009                                  (re-search-forward "^-+END PGP" nil t)
12010                                  (beginning-of-line 2)
12011                                  (point)))
12012                 (insert-buffer-substring pgg-output-buffer))))))))
12013
12014 (defun gnus-summary-verify-article ()
12015   "Verify the current article in traditional PGP way."
12016   (interactive)
12017   (save-excursion
12018     (set-buffer gnus-original-article-buffer)
12019     (goto-char (point-min))
12020     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
12021       (error "Not a traditional PGP message!"))
12022     (re-search-forward "^-+END PGP" nil t)
12023     (beginning-of-line 2)
12024     (call-interactively (function pgg-verify-region))))
12025
12026 ;;;
12027 ;;; Generic summary marking commands
12028 ;;;
12029
12030 (defvar gnus-summary-marking-alist
12031   '((read gnus-del-mark "d")
12032     (unread gnus-unread-mark "u")
12033     (ticked gnus-ticked-mark "!")
12034     (dormant gnus-dormant-mark "?")
12035     (expirable gnus-expirable-mark "e"))
12036   "An alist of names/marks/keystrokes.")
12037
12038 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12039 (defvar gnus-summary-mark-map)
12040
12041 (defun gnus-summary-make-all-marking-commands ()
12042   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12043   (dolist (elem gnus-summary-marking-alist)
12044     (apply 'gnus-summary-make-marking-command elem)))
12045
12046 (defun gnus-summary-make-marking-command (name mark keystroke)
12047   (let ((map (make-sparse-keymap)))
12048     (define-key gnus-summary-generic-mark-map keystroke map)
12049     (dolist (lway `((next "next" next nil "n")
12050                     (next-unread "next unread" next t "N")
12051                     (prev "previous" prev nil "p")
12052                     (prev-unread "previous unread" prev t "P")
12053                     (nomove "" nil nil ,keystroke)))
12054       (let ((func (gnus-summary-make-marking-command-1
12055                    mark (car lway) lway name)))
12056         (setq func (eval func))
12057         (define-key map (nth 4 lway) func)))))
12058
12059 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12060   `(defun ,(intern
12061             (format "gnus-summary-put-mark-as-%s%s"
12062                     name (if (eq way 'nomove)
12063                              ""
12064                            (concat "-" (symbol-name way)))))
12065      (n)
12066      ,(format
12067        "Mark the current article as %s%s.
12068 If N, the prefix, then repeat N times.
12069 If N is negative, move in reverse order.
12070 The difference between N and the actual number of articles marked is
12071 returned."
12072        name (car (cdr lway)))
12073      (interactive "p")
12074      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12075
12076 (defun gnus-summary-generic-mark (n mark move unread)
12077   "Mark N articles with MARK."
12078   (unless (eq major-mode 'gnus-summary-mode)
12079     (error "This command can only be used in the summary buffer"))
12080   (gnus-summary-show-thread)
12081   (let ((nummove
12082          (cond
12083           ((eq move 'next) 1)
12084           ((eq move 'prev) -1)
12085           (t 0))))
12086     (if (zerop nummove)
12087         (setq n 1)
12088       (when (< n 0)
12089         (setq n (abs n)
12090               nummove (* -1 nummove))))
12091     (while (and (> n 0)
12092                 (gnus-summary-mark-article nil mark)
12093                 (zerop (gnus-summary-next-subject nummove unread t)))
12094       (setq n (1- n)))
12095     (when (/= 0 n)
12096       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12097     (gnus-summary-recenter)
12098     (gnus-summary-position-point)
12099     (gnus-set-mode-line 'summary)
12100     n))
12101
12102 (defun gnus-summary-insert-articles (articles)
12103   (when (setq articles
12104               (gnus-sorted-difference articles
12105                                       (mapcar (lambda (h)
12106                                                 (mail-header-number h))
12107                                               gnus-newsgroup-headers)))
12108     (setq gnus-newsgroup-headers
12109           (gnus-merge 'list
12110                       gnus-newsgroup-headers
12111                       (gnus-fetch-headers articles)
12112                       'gnus-article-sort-by-number))
12113     ;; Suppress duplicates?
12114     (when gnus-suppress-duplicates
12115       (gnus-dup-suppress-articles))
12116
12117     ;; We might want to build some more threads first.
12118     (when (and gnus-fetch-old-headers
12119                (eq gnus-headers-retrieved-by 'nov))
12120       (if (eq gnus-fetch-old-headers 'invisible)
12121           (gnus-build-all-threads)
12122         (gnus-build-old-threads)))
12123     ;; Let the Gnus agent mark articles as read.
12124     (when gnus-agent
12125       (gnus-agent-get-undownloaded-list))
12126     ;; Remove list identifiers from subject
12127     (when gnus-list-identifiers
12128       (gnus-summary-remove-list-identifiers))
12129     ;; First and last article in this newsgroup.
12130     (when gnus-newsgroup-headers
12131       (setq gnus-newsgroup-begin
12132             (mail-header-number (car gnus-newsgroup-headers))
12133             gnus-newsgroup-end
12134             (mail-header-number
12135              (gnus-last-element gnus-newsgroup-headers))))
12136     (when gnus-use-scoring
12137       (gnus-possibly-score-headers))))
12138
12139 (defun gnus-summary-insert-old-articles (&optional all)
12140   "Insert all old articles in this group.
12141 If ALL is non-nil, already read articles become readable.
12142 If ALL is a number, fetch this number of articles."
12143   (interactive "P")
12144   (prog1
12145       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12146             older len)
12147         (setq older
12148               ;; Some nntp servers lie about their active range.  When
12149               ;; this happens, the active range can be in the millions.
12150               ;; Use a compressed range to avoid creating a huge list.
12151               (gnus-range-difference (list gnus-newsgroup-active) old))
12152         (setq len (gnus-range-length older))
12153         (cond
12154          ((null older) nil)
12155          ((numberp all)
12156           (if (< all len)
12157               (let ((older-range (nreverse older)))
12158                 (setq older nil)
12159
12160                 (while (> all 0)
12161                   (let* ((r (pop older-range))
12162                          (min (if (numberp r) r (car r)))
12163                          (max (if (numberp r) r (cdr r))))
12164                     (while (and (<= min max)
12165                                 (> all 0))
12166                       (push max older)
12167                       (setq all (1- all)
12168                             max (1- max))))))
12169             (setq older (gnus-uncompress-range older))))
12170          (all
12171           (setq older (gnus-uncompress-range older)))
12172          (t
12173           (when (and (numberp gnus-large-newsgroup)
12174                    (> len gnus-large-newsgroup))
12175               (let* ((cursor-in-echo-area nil)
12176                      (initial (gnus-parameter-large-newsgroup-initial
12177                                gnus-newsgroup-name))
12178                      (input
12179                       (read-string
12180                        (format
12181                         "How many articles from %s (%s %d): "
12182                         (gnus-limit-string
12183                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12184                         (if initial "max" "default")
12185                         len)
12186                        (if initial
12187                            (cons (number-to-string initial)
12188                                  0)))))
12189                 (unless (string-match "^[ \t]*$" input)
12190                   (setq all (string-to-number input))
12191                   (if (< all len)
12192                       (let ((older-range (nreverse older)))
12193                         (setq older nil)
12194
12195                         (while (> all 0)
12196                           (let* ((r (pop older-range))
12197                                  (min (if (numberp r) r (car r)))
12198                                  (max (if (numberp r) r (cdr r))))
12199                             (while (and (<= min max)
12200                                         (> all 0))
12201                               (push max older)
12202                               (setq all (1- all)
12203                                     max (1- max))))))))))
12204           (setq older (gnus-uncompress-range older))))
12205         (if (not older)
12206             (message "No old news.")
12207           (gnus-summary-insert-articles older)
12208           (gnus-summary-limit (gnus-sorted-nunion old older))))
12209     (gnus-summary-position-point)))
12210
12211 (defun gnus-summary-insert-new-articles ()
12212   "Insert all new articles in this group."
12213   (interactive)
12214   (prog1
12215       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12216             (old-active gnus-newsgroup-active)
12217             (nnmail-fetched-sources (list t))
12218             i new)
12219         (setq gnus-newsgroup-active
12220               (gnus-activate-group gnus-newsgroup-name 'scan))
12221         (setq i (cdr gnus-newsgroup-active))
12222         (while (> i (cdr old-active))
12223           (push i new)
12224           (decf i))
12225         (if (not new)
12226             (message "No gnus is bad news")
12227           (gnus-summary-insert-articles new)
12228           (setq gnus-newsgroup-unreads
12229                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12230           (gnus-summary-limit (gnus-sorted-nunion old new))))
12231     (gnus-summary-position-point)))
12232
12233 (gnus-summary-make-all-marking-commands)
12234
12235 (gnus-ems-redefine)
12236
12237 (provide 'gnus-sum)
12238
12239 (run-hooks 'gnus-sum-load-hook)
12240
12241 ;; Local Variables:
12242 ;; coding: iso-8859-1
12243 ;; End:
12244
12245 ;;; gnus-sum.el ends here