(mml2015-epg-sign): Save the signing keys in
[gnus] / 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, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-fetch-old-headers nil
66   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
67 If an unread article in the group refers to an older, already
68 read (or just marked as read) article, the old article will not
69 normally be displayed in the Summary buffer.  If this variable is
70 t, Gnus will attempt to grab the headers to the old articles, and
71 thereby build complete threads.  If it has the value `some', all
72 old headers will be fetched but only enough headers to connect
73 otherwise loose threads will be displayed.  This variable can
74 also be a number.  In that case, no more than that number of old
75 headers will be fetched.  If it has the value `invisible', all
76 old headers will be fetched, but none will be displayed.
77
78 The server has to support NOV for any of this to work.
79
80 This feature can seriously impact performance it ignores all
81 locally cached header entries."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const :tag "on" t)
85                  (const some)
86                  (const invisible)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 500
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :version "22.1"
129   :group 'gnus-thread
130   :type 'boolean)
131
132 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
133   "*A regexp to match subjects to be excluded from loose thread gathering.
134 As loose thread gathering is done on subjects only, that means that
135 there can be many false gatherings performed.  By rooting out certain
136 common subjects, gathering might become saner."
137   :group 'gnus-thread
138   :type 'regexp)
139
140 (defcustom gnus-summary-gather-subject-limit nil
141   "*Maximum length of subject comparisons when gathering loose threads.
142 Use nil to compare full subjects.  Setting this variable to a low
143 number will help gather threads that have been corrupted by
144 newsreaders chopping off subject lines, but it might also mean that
145 unrelated articles that have subject that happen to begin with the
146 same few characters will be incorrectly gathered.
147
148 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
149 comparing subjects."
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const fuzzy)
153                  (sexp :menu-tag "on" t)))
154
155 (defcustom gnus-simplify-subject-functions nil
156   "List of functions taking a string argument that simplify subjects.
157 The functions are applied recursively.
158
159 Useful functions to put in this list include:
160 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
161 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
162   :group 'gnus-thread
163   :type '(repeat function))
164
165 (defcustom gnus-simplify-ignored-prefixes nil
166   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  regexp))
170
171 (defcustom gnus-build-sparse-threads nil
172   "*If non-nil, fill in the gaps in threads.
173 If `some', only fill in the gaps that are needed to tie loose threads
174 together.  If `more', fill in all leaf nodes that Gnus can find.  If
175 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  (const some)
179                  (const more)
180                  (sexp :menu-tag "all" t)))
181
182 (defcustom gnus-summary-thread-gathering-function
183   'gnus-gather-threads-by-subject
184   "*Function used for gathering loose threads.
185 There are two pre-defined functions: `gnus-gather-threads-by-subject',
186 which only takes Subjects into consideration; and
187 `gnus-gather-threads-by-references', which compared the References
188 headers of the articles to find matches."
189   :group 'gnus-thread
190   :type '(radio (function-item gnus-gather-threads-by-subject)
191                 (function-item gnus-gather-threads-by-references)
192                 (function :tag "other")))
193
194 (defcustom gnus-summary-same-subject ""
195   "*String indicating that the current article has the same subject as the previous.
196 This variable will only be used if the value of
197 `gnus-summary-make-false-root' is `empty'."
198   :group 'gnus-summary-format
199   :type 'string)
200
201 (defcustom gnus-summary-goto-unread t
202   "*If t, many commands will go to the next unread article.
203 This applies to marking commands as well as other commands that
204 \"naturally\" select the next article, like, for instance, `SPC' at
205 the end of an article.
206
207 If nil, the marking commands do NOT go to the next unread article
208 \(they go to the next article instead).  If `never', commands that
209 usually go to the next unread article, will go to the next article,
210 whether it is read or not."
211   :group 'gnus-summary-marks
212   :link '(custom-manual "(gnus)Setting Marks")
213   :type '(choice (const :tag "off" nil)
214                  (const never)
215                  (sexp :menu-tag "on" t)))
216
217 (defcustom gnus-summary-default-score 0
218   "*Default article score level.
219 All scores generated by the score files will be added to this score.
220 If this variable is nil, scoring will be disabled."
221   :group 'gnus-score-default
222   :type '(choice (const :tag "disable")
223                  integer))
224
225 (defcustom gnus-summary-default-high-score 0
226   "*Default threshold for a high scored article.
227 An article will be highlighted as high scored if its score is greater
228 than this score."
229   :version "22.1"
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-zcore-fuzz 0
242   "*Fuzziness factor for the zcore in the summary buffer.
243 Articles with scores closer than this to `gnus-summary-default-score'
244 will not be marked."
245   :group 'gnus-summary-format
246   :type 'integer)
247
248 (defcustom gnus-simplify-subject-fuzzy-regexp nil
249   "*Strings to be removed when doing fuzzy matches.
250 This can either be a regular expression or list of regular expressions
251 that will be removed from subject strings if fuzzy subject
252 simplification is selected."
253   :group 'gnus-thread
254   :type '(repeat regexp))
255
256 (defcustom gnus-show-threads t
257   "*If non-nil, display threads in summary mode."
258   :group 'gnus-thread
259   :type 'boolean)
260
261 (defcustom gnus-thread-hide-subtree nil
262   "*If non-nil, hide all threads initially.
263 This can be a predicate specifier which says which threads to hide.
264 If threads are hidden, you have to run the command
265 `gnus-summary-show-thread' by hand or select an article."
266   :group 'gnus-thread
267   :type '(radio (sexp :format "Non-nil\n"
268                       :match (lambda (widget value)
269                                (not (or (consp value) (functionp value))))
270                       :value t)
271                 (const nil)
272                 (sexp :tag "Predicate specifier")))
273
274 (defcustom gnus-thread-hide-killed t
275   "*If non-nil, hide killed threads automatically."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-ignore-subject t
280   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
281 If nil, articles that have different subjects from their parents will
282 start separate threads."
283   :group 'gnus-thread
284   :type 'boolean)
285
286 (defcustom gnus-thread-operation-ignore-subject t
287   "*If non-nil, subjects will be ignored when doing thread commands.
288 This affects commands like `gnus-summary-kill-thread' and
289 `gnus-summary-lower-thread'.
290
291 If this variable is nil, articles in the same thread with different
292 subjects will not be included in the operation in question.  If this
293 variable is `fuzzy', only articles that have subjects that are fuzzily
294 equal will be included."
295   :group 'gnus-thread
296   :type '(choice (const :tag "off" nil)
297                  (const fuzzy)
298                  (sexp :tag "on" t)))
299
300 (defcustom gnus-thread-indent-level 4
301   "*Number that says how much each sub-thread should be indented."
302   :group 'gnus-thread
303   :type 'integer)
304
305 (defcustom gnus-auto-extend-newsgroup t
306   "*If non-nil, extend newsgroup forward and backward when requested."
307   :group 'gnus-summary-choose
308   :type 'boolean)
309
310 (defcustom gnus-auto-select-first t
311   "*If non-nil, select the article under point.
312 Which article this is is controlled by the `gnus-auto-select-subject'
313 variable.
314
315 If you want to prevent automatic selection of articles in some
316 newsgroups, set the variable to nil in `gnus-select-group-hook'."
317   :group 'gnus-group-select
318   :type '(choice (const :tag "none" nil)
319                  (sexp :menu-tag "first" t)))
320
321 (defcustom gnus-auto-select-subject 'unread
322   "*Says what subject to place under point when entering a group.
323
324 This variable can either be the symbols `first' (place point on the
325 first subject), `unread' (place point on the subject line of the first
326 unread article), `best' (place point on the subject line of the
327 higest-scored article), `unseen' (place point on the subject line of
328 the first unseen article), `unseen-or-unread' (place point on the subject
329 line of the first unseen article or, if all article have been seen, on the
330 subject line of the first unread article), or a function to be called to
331 place point on some subject line."
332   :version "22.1"
333   :group 'gnus-group-select
334   :type '(choice (const best)
335                  (const unread)
336                  (const first)
337                  (const unseen)
338                  (const unseen-or-unread)))
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
364
365 (defcustom gnus-auto-goto-ignores 'unfetched
366   "*Says how to handle unfetched articles when maneuvering.
367
368 This variable can either be the symbols nil (maneuver to any
369 article), `undownloaded' (maneuvering while unplugged ignores articles
370 that have not been fetched), `always-undownloaded' (maneuvering always
371 ignores articles that have not been fetched), `unfetched' (maneuvering
372 ignores articles whose headers have not been fetched).
373
374 NOTE: The list of unfetched articles will always be nil when plugged
375 and, when unplugged, a subset of the undownloaded article list."
376   :version "22.1"
377   :group 'gnus-summary-maneuvering
378   :type '(choice (const :tag "None" nil)
379                  (const :tag "Undownloaded when unplugged" undownloaded)
380                  (const :tag "Undownloaded" always-undownloaded)
381                  (const :tag "Unfetched" unfetched)))
382
383 (defcustom gnus-summary-check-current nil
384   "*If non-nil, consider the current article when moving.
385 The \"unread\" movement commands will stay on the same line if the
386 current article is unread."
387   :group 'gnus-summary-maneuvering
388   :type 'boolean)
389
390 (defcustom gnus-auto-center-summary 2
391   "*If non-nil, always center the current summary buffer.
392 In particular, if `vertical' do only vertical recentering.  If non-nil
393 and non-`vertical', do both horizontal and vertical recentering."
394   :group 'gnus-summary-maneuvering
395   :type '(choice (const :tag "none" nil)
396                  (const vertical)
397                  (integer :tag "height")
398                  (sexp :menu-tag "both" t)))
399
400 (defvar gnus-auto-center-group t
401   "*If non-nil, always center the group buffer.")
402
403 (defcustom gnus-show-all-headers nil
404   "*If non-nil, don't hide any headers."
405   :group 'gnus-article-hiding
406   :group 'gnus-article-headers
407   :type 'boolean)
408
409 (defcustom gnus-summary-ignore-duplicates nil
410   "*If non-nil, ignore articles with identical Message-ID headers."
411   :group 'gnus-summary
412   :type 'boolean)
413
414 (defcustom gnus-single-article-buffer t
415   "*If non-nil, display all articles in the same buffer.
416 If nil, each group will get its own article buffer."
417   :group 'gnus-article-various
418   :type 'boolean)
419
420 (defcustom gnus-break-pages t
421   "*If non-nil, do page breaking on articles.
422 The page delimiter is specified by the `gnus-page-delimiter'
423 variable."
424   :group 'gnus-article-various
425   :type 'boolean)
426
427 (defcustom gnus-move-split-methods nil
428   "*Variable used to suggest where articles are to be moved to.
429 It uses the same syntax as the `gnus-split-methods' variable.
430 However, whereas `gnus-split-methods' specifies file names as targets,
431 this variable specifies group names."
432   :group 'gnus-summary-mail
433   :type '(repeat (choice (list :value (fun) function)
434                          (cons :value ("" "") regexp (repeat string))
435                          (sexp :value nil))))
436
437 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
438   "Function used to compute default prefix for article move/copy/etc prompts.
439 The function should take one argument, a group name, and return a
440 string with the suggested prefix."
441   :group 'gnus-summary-mail
442   :type 'function)
443
444 ;; FIXME: Although the custom type is `character' for the following variables,
445 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
446
447 (defcustom gnus-unread-mark ?           ;Whitespace
448   "*Mark used for unread articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-ticked-mark ?!
453   "*Mark used for ticked articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-dormant-mark ??
458   "*Mark used for dormant articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-del-mark ?r
463   "*Mark used for del'd articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-read-mark ?R
468   "*Mark used for read articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-expirable-mark ?E
473   "*Mark used for expirable articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-killed-mark ?K
478   "*Mark used for killed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-spam-mark ?$
483   "*Mark used for spam articles."
484   :version "22.1"
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-souped-mark ?F
489   "*Mark used for souped articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-kill-file-mark ?X
494   "*Mark used for articles killed by kill files."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-low-score-mark ?Y
499   "*Mark used for articles with a low score."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-catchup-mark ?C
504   "*Mark used for articles that are caught up."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-replied-mark ?A
509   "*Mark used for articles that have been replied to."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-forwarded-mark ?F
514   "*Mark used for articles that have been forwarded."
515   :version "22.1"
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-recent-mark ?N
520   "*Mark used for articles that are recent."
521   :version "22.1"
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-cached-mark ?*
526   "*Mark used for articles that are in the cache."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-saved-mark ?S
531   "*Mark used for articles that have been saved."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unseen-mark ?.
536   "*Mark used for articles that haven't been seen."
537   :version "22.1"
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-no-mark ?               ;Whitespace
542   "*Mark used for articles that have no other secondary mark."
543   :version "22.1"
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-ancient-mark ?O
548   "*Mark used for ancient articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-sparse-mark ?Q
553   "*Mark used for sparsely reffed articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-canceled-mark ?G
558   "*Mark used for canceled articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-duplicate-mark ?M
563   "*Mark used for duplicate articles."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-undownloaded-mark ?-
568   "*Mark used for articles that weren't downloaded."
569   :version "22.1"
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloaded-mark ?+
574   "*Mark used for articles that were downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-downloadable-mark ?%
579   "*Mark used for articles that are to be downloaded."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-unsendable-mark ?=
584   "*Mark used for articles that won't be sent."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-over-mark ?+
589   "*Score mark used for articles with high scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-score-below-mark ?-
594   "*Score mark used for articles with low scores."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-empty-thread-mark ?     ;Whitespace
599   "*There is no thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-not-empty-thread-mark ?=
604   "*There is a thread under the article."
605   :group 'gnus-summary-marks
606   :type 'character)
607
608 (defcustom gnus-view-pseudo-asynchronously nil
609   "*If non-nil, Gnus will view pseudo-articles asynchronously."
610   :group 'gnus-extract-view
611   :type 'boolean)
612
613 (defcustom gnus-auto-expirable-marks
614   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
615         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
616         gnus-souped-mark gnus-duplicate-mark)
617   "*The list of marks converted into expiration if a group is auto-expirable."
618   :version "21.1"
619   :group 'gnus-summary
620   :type '(repeat character))
621
622 (defcustom gnus-inhibit-user-auto-expire t
623   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
624   :version "21.1"
625   :group 'gnus-summary
626   :type 'boolean)
627
628 (defcustom gnus-view-pseudos nil
629   "*If `automatic', pseudo-articles will be viewed automatically.
630 If `not-confirm', pseudos will be viewed automatically, and the user
631 will not be asked to confirm the command."
632   :group 'gnus-extract-view
633   :type '(choice (const :tag "off" nil)
634                  (const automatic)
635                  (const not-confirm)))
636
637 (defcustom gnus-view-pseudos-separately t
638   "*If non-nil, one pseudo-article will be created for each file to be viewed.
639 If nil, all files that use the same viewing command will be given as a
640 list of parameters to that command."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-insert-pseudo-articles t
645   "*If non-nil, insert pseudo-articles when decoding articles."
646   :group 'gnus-extract-view
647   :type 'boolean)
648
649 (defcustom gnus-summary-dummy-line-format
650   "   %(:                             :%) %S\n"
651   "*The format specification for the dummy roots in the summary buffer.
652 It works along the same lines as a normal formatting string,
653 with some simple extensions.
654
655 %S  The subject
656
657 General format specifiers can also be used.
658 See `(gnus)Formatting Variables'."
659   :link '(custom-manual "(gnus)Formatting Variables")
660   :group 'gnus-threading
661   :type 'string)
662
663 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
664   "*The format specification for the summary mode line.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions:
667
668 %G  Group name
669 %p  Unprefixed group name
670 %A  Current article number
671 %z  Current article score
672 %V  Gnus version
673 %U  Number of unread articles in the group
674 %e  Number of unselected articles in the group
675 %Z  A string with unread/unselected article counts
676 %g  Shortish group name
677 %S  Subject of the current article
678 %u  User-defined spec
679 %s  Current score file name
680 %d  Number of dormant articles
681 %r  Number of articles that have been marked as read in this session
682 %E  Number of articles expunged by the score files"
683   :group 'gnus-summary-format
684   :type 'string)
685
686 (defcustom gnus-list-identifiers nil
687   "Regexp that matches list identifiers to be removed from subject.
688 This can also be a list of regexps."
689   :version "21.1"
690   :group 'gnus-summary-format
691   :group 'gnus-article-hiding
692   :type '(choice (const :tag "none" nil)
693                  (regexp :value ".*")
694                  (repeat :value (".*") regexp)))
695
696 (defcustom gnus-summary-mark-below 0
697   "*Mark all articles with a score below this variable as read.
698 This variable is local to each summary buffer and usually set by the
699 score file."
700   :group 'gnus-score-default
701   :type 'integer)
702
703 (defun gnus-widget-reversible-match (widget value)
704   "Ignoring WIDGET, convert VALUE to internal form.
705 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
706   ;; (debug value)
707   (or (symbolp value)
708       (and (listp value)
709            (eq (length value) 2)
710            (eq (nth 0 value) 'not)
711            (symbolp (nth 1 value)))))
712
713 (defun gnus-widget-reversible-to-internal (widget value)
714   "Ignoring WIDGET, convert VALUE to internal form.
715 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
716 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
717   ;; (debug value)
718   (if (atom value)
719       (list value nil)
720     (list (nth 1 value) t)))
721
722 (defun gnus-widget-reversible-to-external (widget value)
723   "Ignoring WIDGET, convert VALUE to external form.
724 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
725 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
726   ;; (debug value)
727   (if (nth 1 value)
728       (list 'not (nth 0 value))
729     (nth 0 value)))
730
731 (define-widget 'gnus-widget-reversible 'group
732   "A `group' that convert values."
733   :match 'gnus-widget-reversible-match
734   :value-to-internal 'gnus-widget-reversible-to-internal
735   :value-to-external 'gnus-widget-reversible-to-external)
736
737 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
738   "*List of functions used for sorting articles in the summary buffer.
739
740 Each function takes two articles and returns non-nil if the first
741 article should be sorted before the other.  If you use more than one
742 function, the primary sort function should be the last.  You should
743 probably always include `gnus-article-sort-by-number' in the list of
744 sorting functions -- preferably first.  Also note that sorting by date
745 is often much slower than sorting by number, and the sorting order is
746 very similar.  (Sorting by date means sorting by the time the message
747 was sent, sorting by number means sorting by arrival time.)
748
749 Each item can also be a list `(not F)' where F is a function;
750 this reverses the sort order.
751
752 Ready-made functions include `gnus-article-sort-by-number',
753 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
754 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
755 and `gnus-article-sort-by-score'.
756
757 When threading is turned on, the variable `gnus-thread-sort-functions'
758 controls how articles are sorted."
759   :group 'gnus-summary-sort
760   :type '(repeat (gnus-widget-reversible
761                   (choice (function-item gnus-article-sort-by-number)
762                           (function-item gnus-article-sort-by-author)
763                           (function-item gnus-article-sort-by-subject)
764                           (function-item gnus-article-sort-by-date)
765                           (function-item gnus-article-sort-by-score)
766                           (function-item gnus-article-sort-by-random)
767                           (function :tag "other"))
768                   (boolean :tag "Reverse order"))))
769
770
771 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
772   "*List of functions used for sorting threads in the summary buffer.
773 By default, threads are sorted by article number.
774
775 Each function takes two threads and returns non-nil if the first
776 thread should be sorted before the other.  If you use more than one
777 function, the primary sort function should be the last.  You should
778 probably always include `gnus-thread-sort-by-number' in the list of
779 sorting functions -- preferably first.  Also note that sorting by date
780 is often much slower than sorting by number, and the sorting order is
781 very similar.  (Sorting by date means sorting by the time the message
782 was sent, sorting by number means sorting by arrival time.)
783
784 Each list item can also be a list `(not F)' where F is a
785 function; this specifies reversed sort order.
786
787 Ready-made functions include `gnus-thread-sort-by-number',
788 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
789 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
790 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
791 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
792 and `gnus-thread-sort-by-total-score' (see
793 `gnus-thread-score-function').
794
795 When threading is turned off, the variable
796 `gnus-article-sort-functions' controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat
799           (gnus-widget-reversible
800            (choice (function-item gnus-thread-sort-by-number)
801                    (function-item gnus-thread-sort-by-author)
802                    (function-item gnus-thread-sort-by-recipient)
803                    (function-item gnus-thread-sort-by-subject)
804                    (function-item gnus-thread-sort-by-date)
805                    (function-item gnus-thread-sort-by-score)
806                    (function-item gnus-thread-sort-by-most-recent-number)
807                    (function-item gnus-thread-sort-by-most-recent-date)
808                    (function-item gnus-thread-sort-by-random)
809                    (function-item gnus-thread-sort-by-total-score)
810                    (function :tag "other"))
811            (boolean :tag "Reverse order"))))
812
813 (defcustom gnus-thread-score-function '+
814   "*Function used for calculating the total score of a thread.
815
816 The function is called with the scores of the article and each
817 subthread and should then return the score of the thread.
818
819 Some functions you can use are `+', `max', or `min'."
820   :group 'gnus-summary-sort
821   :type 'function)
822
823 (defcustom gnus-summary-expunge-below nil
824   "All articles that have a score less than this variable will be expunged.
825 This variable is local to the summary buffers."
826   :group 'gnus-score-default
827   :type '(choice (const :tag "off" nil)
828                  integer))
829
830 (defcustom gnus-thread-expunge-below nil
831   "All threads that have a total score less than this variable will be expunged.
832 See `gnus-thread-score-function' for en explanation of what a
833 \"thread score\" is.
834
835 This variable is local to the summary buffers."
836   :group 'gnus-threading
837   :group 'gnus-score-default
838   :type '(choice (const :tag "off" nil)
839                  integer))
840
841 (defcustom gnus-summary-mode-hook nil
842   "*A hook for Gnus summary mode.
843 This hook is run before any variables are set in the summary buffer."
844   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
845   :group 'gnus-summary-various
846   :type 'hook)
847
848 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
849 (when (featurep 'xemacs)
850   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
851   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
852   (add-hook 'gnus-summary-mode-hook
853             'gnus-xmas-switch-horizontal-scrollbar-off))
854
855 (defcustom gnus-summary-menu-hook nil
856   "*Hook run after the creation of the summary mode menu."
857   :group 'gnus-summary-visual
858   :type 'hook)
859
860 (defcustom gnus-summary-exit-hook nil
861   "*A hook called on exit from the summary buffer.
862 It will be called with point in the group buffer."
863   :group 'gnus-summary-exit
864   :type 'hook)
865
866 (defcustom gnus-summary-prepare-hook nil
867   "*A hook called after the summary buffer has been generated.
868 If you want to modify the summary buffer, you can use this hook."
869   :group 'gnus-summary-various
870   :type 'hook)
871
872 (defcustom gnus-summary-prepared-hook nil
873   "*A hook called as the last thing after the summary buffer has been generated."
874   :group 'gnus-summary-various
875   :type 'hook)
876
877 (defcustom gnus-summary-generate-hook nil
878   "*A hook run just before generating the summary buffer.
879 This hook is commonly used to customize threading variables and the
880 like."
881   :group 'gnus-summary-various
882   :type 'hook)
883
884 (defcustom gnus-select-group-hook nil
885   "*A hook called when a newsgroup is selected.
886
887 If you'd like to simplify subjects like the
888 `gnus-summary-next-same-subject' command does, you can use the
889 following hook:
890
891  (add-hook gnus-select-group-hook
892            (lambda ()
893              (mapcar (lambda (header)
894                        (mail-header-set-subject
895                         header
896                         (gnus-simplify-subject
897                          (mail-header-subject header) 're-only)))
898                      gnus-newsgroup-headers)))"
899   :group 'gnus-group-select
900   :type 'hook)
901
902 (defcustom gnus-select-article-hook nil
903   "*A hook called when an article is selected."
904   :group 'gnus-summary-choose
905   :options '(gnus-agent-fetch-selected-article)
906   :type 'hook)
907
908 (defcustom gnus-visual-mark-article-hook
909   (list 'gnus-highlight-selected-summary)
910   "*Hook run after selecting an article in the summary buffer.
911 It is meant to be used for highlighting the article in some way.  It
912 is not run if `gnus-visual' is nil."
913   :group 'gnus-summary-visual
914   :type 'hook)
915
916 (defcustom gnus-parse-headers-hook nil
917   "*A hook called before parsing the headers."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-exit-group-hook nil
922   "*A hook called when exiting summary mode.
923 This hook is not called from the non-updating exit commands like `Q'."
924   :group 'gnus-various
925   :type 'hook)
926
927 (defcustom gnus-summary-update-hook
928   (list 'gnus-summary-highlight-line)
929   "*A hook called when a summary line is changed.
930 The hook will not be called if `gnus-visual' is nil.
931
932 The default function `gnus-summary-highlight-line' will
933 highlight the line according to the `gnus-summary-highlight'
934 variable."
935   :group 'gnus-summary-visual
936   :type 'hook)
937
938 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
939   "*A hook called when an article is selected for the first time.
940 The hook is intended to mark an article as read (or unread)
941 automatically when it is selected."
942   :group 'gnus-summary-choose
943   :type 'hook)
944
945 (defcustom gnus-group-no-more-groups-hook nil
946   "*A hook run when returning to group mode having no more (unread) groups."
947   :group 'gnus-group-select
948   :type 'hook)
949
950 (defcustom gnus-ps-print-hook nil
951   "*A hook run before ps-printing something from Gnus."
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-move-hook nil
956   "*A hook called after an article is moved, copied, respooled, or crossposted."
957   :version "22.1"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-delete-hook nil
962   "*A hook called after an article is deleted."
963   :version "22.1"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-article-expire-hook nil
968   "*A hook called after an article is expired."
969   :version "22.1"
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-display-arrow
974   (and (fboundp 'display-graphic-p)
975        (display-graphic-p))
976   "*If non-nil, display an arrow highlighting the current article."
977   :version "22.1"
978   :group 'gnus-summary
979   :type 'boolean)
980
981 (defcustom gnus-summary-selected-face 'gnus-summary-selected
982   "Face used for highlighting the current article in the summary buffer."
983   :group 'gnus-summary-visual
984   :type 'face)
985
986 (defvar gnus-tmp-downloaded nil)
987
988 (defcustom gnus-summary-highlight
989   '(((eq mark gnus-canceled-mark)
990      . gnus-summary-cancelled)
991     ((and uncached (> score default-high))
992      . gnus-summary-high-undownloaded)
993     ((and uncached (< score default-low))
994      . gnus-summary-low-undownloaded)
995     (uncached
996      . gnus-summary-normal-undownloaded)
997     ((and (> score default-high)
998           (or (eq mark gnus-dormant-mark)
999               (eq mark gnus-ticked-mark)))
1000      . gnus-summary-high-ticked)
1001     ((and (< score default-low)
1002           (or (eq mark gnus-dormant-mark)
1003               (eq mark gnus-ticked-mark)))
1004      . gnus-summary-low-ticked)
1005     ((or (eq mark gnus-dormant-mark)
1006          (eq mark gnus-ticked-mark))
1007      . gnus-summary-normal-ticked)
1008     ((and (> score default-high) (eq mark gnus-ancient-mark))
1009      . gnus-summary-high-ancient)
1010     ((and (< score default-low) (eq mark gnus-ancient-mark))
1011      . gnus-summary-low-ancient)
1012     ((eq mark gnus-ancient-mark)
1013      . gnus-summary-normal-ancient)
1014     ((and (> score default-high) (eq mark gnus-unread-mark))
1015      . gnus-summary-high-unread)
1016     ((and (< score default-low) (eq mark gnus-unread-mark))
1017      . gnus-summary-low-unread)
1018     ((eq mark gnus-unread-mark)
1019      . gnus-summary-normal-unread)
1020     ((> score default-high)
1021      . gnus-summary-high-read)
1022     ((< score default-low)
1023      . gnus-summary-low-read)
1024     (t
1025      . gnus-summary-normal-read))
1026   "*Controls the highlighting of summary buffer lines.
1027
1028 A list of (FORM . FACE) pairs.  When deciding how a a particular
1029 summary line should be displayed, each form is evaluated.  The content
1030 of the face field after the first true form is used.  You can change
1031 how those summary lines are displayed, by editing the face field.
1032
1033 You can use the following variables in the FORM field.
1034
1035 score:        The article's score
1036 default:      The default article score.
1037 default-high: The default score for high scored articles.
1038 default-low:  The default score for low scored articles.
1039 below:        The score below which articles are automatically marked as read.
1040 mark:         The article's mark.
1041 uncached:     Non-nil if the article is uncached."
1042   :group 'gnus-summary-visual
1043   :type '(repeat (cons (sexp :tag "Form" nil)
1044                        face)))
1045
1046 (defcustom gnus-alter-header-function nil
1047   "Function called to allow alteration of article header structures.
1048 The function is called with one parameter, the article header vector,
1049 which it may alter in any way."
1050   :type '(choice (const :tag "None" nil)
1051                  function)
1052   :group 'gnus-summary)
1053
1054 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1055   "Function used to decode a string with encoded words.")
1056
1057 (defvar gnus-decode-encoded-address-function
1058   'mail-decode-encoded-address-string
1059   "Function used to decode addresses with encoded words.")
1060
1061 (defcustom gnus-extra-headers '(To Newsgroups)
1062   "*Extra headers to parse."
1063   :version "21.1"
1064   :group 'gnus-summary
1065   :type '(repeat symbol))
1066
1067 (defcustom gnus-ignored-from-addresses
1068   (and user-mail-address
1069        (not (string= user-mail-address ""))
1070        (regexp-quote user-mail-address))
1071   "*Regexp of From headers that may be suppressed in favor of To headers."
1072   :version "21.1"
1073   :group 'gnus-summary
1074   :type 'regexp)
1075
1076 (defcustom gnus-summary-to-prefix "-> "
1077   "*String prefixed to the To field in the summary line when
1078 using `gnus-ignored-from-addresses'."
1079   :version "22.1"
1080   :group 'gnus-summary
1081   :type 'string)
1082
1083 (defcustom gnus-summary-newsgroup-prefix "=> "
1084   "*String prefixed to the Newsgroup field in the summary
1085 line when using `gnus-ignored-from-addresses'."
1086   :version "22.1"
1087   :group 'gnus-summary
1088   :type 'string)
1089
1090 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1091   "List of charsets that should be ignored.
1092 When these charsets are used in the \"charset\" parameter, the
1093 default charset will be used instead."
1094   :version "21.1"
1095   :type '(repeat symbol)
1096   :group 'gnus-charset)
1097
1098 (gnus-define-group-parameter
1099  ignored-charsets
1100  :type list
1101  :function-document
1102  "Return the ignored charsets of GROUP."
1103  :variable gnus-group-ignored-charsets-alist
1104  :variable-default
1105  '(("alt\\.chinese\\.text" iso-8859-1))
1106  :variable-document
1107  "Alist of regexps (to match group names) and charsets that should be ignored.
1108 When these charsets are used in the \"charset\" parameter, the
1109 default charset will be used instead."
1110  :variable-group gnus-charset
1111  :variable-type '(repeat (cons (regexp :tag "Group")
1112                                (repeat symbol)))
1113  :parameter-type '(choice :tag "Ignored charsets"
1114                           :value nil
1115                           (repeat (symbol)))
1116  :parameter-document       "\
1117 List of charsets that should be ignored.
1118
1119 When these charsets are used in the \"charset\" parameter, the
1120 default charset will be used instead.")
1121
1122 (defcustom gnus-group-highlight-words-alist nil
1123   "Alist of group regexps and highlight regexps.
1124 This variable uses the same syntax as `gnus-emphasis-alist'."
1125   :version "21.1"
1126   :type '(repeat (cons (regexp :tag "Group")
1127                        (repeat (list (regexp :tag "Highlight regexp")
1128                                      (number :tag "Group for entire word" 0)
1129                                      (number :tag "Group for displayed part" 0)
1130                                      (symbol :tag "Face"
1131                                              gnus-emphasis-highlight-words)))))
1132   :group 'gnus-summary-visual)
1133
1134 (defcustom gnus-summary-show-article-charset-alist
1135   nil
1136   "Alist of number and charset.
1137 The article will be shown with the charset corresponding to the
1138 numbered argument.
1139 For example: ((1 . cn-gb-2312) (2 . big5))."
1140   :version "21.1"
1141   :type '(repeat (cons (number :tag "Argument" 1)
1142                        (symbol :tag "Charset")))
1143   :group 'gnus-charset)
1144
1145 (defcustom gnus-preserve-marks t
1146   "Whether marks are preserved when moving, copying and respooling messages."
1147   :version "21.1"
1148   :type 'boolean
1149   :group 'gnus-summary-marks)
1150
1151 (defcustom gnus-alter-articles-to-read-function nil
1152   "Function to be called to alter the list of articles to be selected."
1153   :type '(choice (const nil) function)
1154   :group 'gnus-summary)
1155
1156 (defcustom gnus-orphan-score nil
1157   "*All orphans get this score added.  Set in the score file."
1158   :group 'gnus-score-default
1159   :type '(choice (const nil)
1160                  integer))
1161
1162 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1163   "*A regexp to match MIME parts when saving multiple parts of a
1164 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1165 This regexp will be used by default when prompting the user for which
1166 type of files to save."
1167   :group 'gnus-summary
1168   :type 'regexp)
1169
1170 (defcustom gnus-read-all-available-headers nil
1171   "Whether Gnus should parse all headers made available to it.
1172 This is mostly relevant for slow back ends where the user may
1173 wish to widen the summary buffer to include all headers
1174 that were fetched.  Say, for nnultimate groups."
1175   :version "22.1"
1176   :group 'gnus-summary
1177   :type '(choice boolean regexp))
1178
1179 (defcustom gnus-summary-muttprint-program "muttprint"
1180   "Command (and optional arguments) used to run Muttprint."
1181   :version "22.1"
1182   :group 'gnus-summary
1183   :type 'string)
1184
1185 (defcustom gnus-article-loose-mime t
1186   "If non-nil, don't require MIME-Version header.
1187 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1188 supply the MIME-Version header or deliberately strip it from the mail.
1189 If non-nil (the default), Gnus will treat some articles as MIME
1190 even if the MIME-Version header is missing."
1191   :version "22.1"
1192   :type 'boolean
1193   :group 'gnus-article-mime)
1194
1195 (defcustom gnus-article-emulate-mime t
1196   "If non-nil, use MIME emulation for uuencode and the like.
1197 This means that Gnus will search message bodies for text that look
1198 like uuencoded bits, yEncoded bits, and so on, and present that using
1199 the normal Gnus MIME machinery."
1200   :version "22.1"
1201   :type 'boolean
1202   :group 'gnus-article-mime)
1203
1204 ;;; Internal variables
1205
1206 (defvar gnus-summary-display-cache nil)
1207 (defvar gnus-article-mime-handles nil)
1208 (defvar gnus-article-decoded-p nil)
1209 (defvar gnus-article-charset nil)
1210 (defvar gnus-article-ignored-charsets nil)
1211 (defvar gnus-scores-exclude-files nil)
1212 (defvar gnus-page-broken nil)
1213
1214 (defvar gnus-original-article nil)
1215 (defvar gnus-article-internal-prepare-hook nil)
1216 (defvar gnus-newsgroup-process-stack nil)
1217
1218 (defvar gnus-thread-indent-array nil)
1219 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1220 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1221   "Function called to sort the articles within a thread after it has been gathered together.")
1222
1223 (defvar gnus-summary-save-parts-type-history nil)
1224 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1225
1226 ;; Avoid highlighting in kill files.
1227 (defvar gnus-summary-inhibit-highlight nil)
1228 (defvar gnus-newsgroup-selected-overlay nil)
1229 (defvar gnus-inhibit-limiting nil)
1230 (defvar gnus-newsgroup-adaptive-score-file nil)
1231 (defvar gnus-current-score-file nil)
1232 (defvar gnus-current-move-group nil)
1233 (defvar gnus-current-copy-group nil)
1234 (defvar gnus-current-crosspost-group nil)
1235 (defvar gnus-newsgroup-display nil)
1236
1237 (defvar gnus-newsgroup-dependencies nil)
1238 (defvar gnus-newsgroup-adaptive nil)
1239 (defvar gnus-summary-display-article-function nil)
1240 (defvar gnus-summary-highlight-line-function nil
1241   "Function called after highlighting a summary line.")
1242
1243 (defvar gnus-summary-line-format-alist
1244   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1245     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1246     (?s gnus-tmp-subject-or-nil ?s)
1247     (?n gnus-tmp-name ?s)
1248     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1249         ?s)
1250     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1251             gnus-tmp-from) ?s)
1252     (?F gnus-tmp-from ?s)
1253     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1254     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1255     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1256     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1257     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1258     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1259     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1260     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1261     (?L gnus-tmp-lines ?s)
1262     (?O gnus-tmp-downloaded ?c)
1263     (?I gnus-tmp-indentation ?s)
1264     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1265     (?R gnus-tmp-replied ?c)
1266     (?\[ gnus-tmp-opening-bracket ?c)
1267     (?\] gnus-tmp-closing-bracket ?c)
1268     (?\> (make-string gnus-tmp-level ? ) ?s)
1269     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1270     (?i gnus-tmp-score ?d)
1271     (?z gnus-tmp-score-char ?c)
1272     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1273     (?U gnus-tmp-unread ?c)
1274     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1275         ?s)
1276     (?t (gnus-summary-number-of-articles-in-thread
1277          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1278         ?d)
1279     (?e (gnus-summary-number-of-articles-in-thread
1280          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1281         ?c)
1282     (?u gnus-tmp-user-defined ?s)
1283     (?P (gnus-pick-line-number) ?d)
1284     (?B gnus-tmp-thread-tree-header-string ?s)
1285     (user-date (gnus-user-date
1286                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1287   "An alist of format specifications that can appear in summary lines.
1288 These are paired with what variables they correspond with, along with
1289 the type of the variable (string, integer, character, etc).")
1290
1291 (defvar gnus-summary-dummy-line-format-alist
1292   `((?S gnus-tmp-subject ?s)
1293     (?N gnus-tmp-number ?d)
1294     (?u gnus-tmp-user-defined ?s)))
1295
1296 (defvar gnus-summary-mode-line-format-alist
1297   `((?G gnus-tmp-group-name ?s)
1298     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1299     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1300     (?A gnus-tmp-article-number ?d)
1301     (?Z gnus-tmp-unread-and-unselected ?s)
1302     (?V gnus-version ?s)
1303     (?U gnus-tmp-unread-and-unticked ?d)
1304     (?S gnus-tmp-subject ?s)
1305     (?e gnus-tmp-unselected ?d)
1306     (?u gnus-tmp-user-defined ?s)
1307     (?d (length gnus-newsgroup-dormant) ?d)
1308     (?t (length gnus-newsgroup-marked) ?d)
1309     (?h (length gnus-newsgroup-spam-marked) ?d)
1310     (?r (length gnus-newsgroup-reads) ?d)
1311     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1312     (?E gnus-newsgroup-expunged-tally ?d)
1313     (?s (gnus-current-score-file-nondirectory) ?s)))
1314
1315 (defvar gnus-last-search-regexp nil
1316   "Default regexp for article search command.")
1317
1318 (defvar gnus-last-shell-command nil
1319   "Default shell command on article.")
1320
1321 (defvar gnus-newsgroup-agentized nil
1322   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1323 (defvar gnus-newsgroup-begin nil)
1324 (defvar gnus-newsgroup-end nil)
1325 (defvar gnus-newsgroup-last-rmail nil)
1326 (defvar gnus-newsgroup-last-mail nil)
1327 (defvar gnus-newsgroup-last-folder nil)
1328 (defvar gnus-newsgroup-last-file nil)
1329 (defvar gnus-newsgroup-last-directory nil)
1330 (defvar gnus-newsgroup-auto-expire nil)
1331 (defvar gnus-newsgroup-active nil)
1332
1333 (defvar gnus-newsgroup-data nil)
1334 (defvar gnus-newsgroup-data-reverse nil)
1335 (defvar gnus-newsgroup-limit nil)
1336 (defvar gnus-newsgroup-limits nil)
1337 (defvar gnus-summary-use-undownloaded-faces nil)
1338
1339 (defvar gnus-newsgroup-unreads nil
1340   "Sorted list of unread articles in the current newsgroup.")
1341
1342 (defvar gnus-newsgroup-unselected nil
1343   "Sorted list of unselected unread articles in the current newsgroup.")
1344
1345 (defvar gnus-newsgroup-reads nil
1346   "Alist of read articles and article marks in the current newsgroup.")
1347
1348 (defvar gnus-newsgroup-expunged-tally nil)
1349
1350 (defvar gnus-newsgroup-marked nil
1351   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1352
1353 (defvar gnus-newsgroup-spam-marked nil
1354   "List of ranges of articles that have been marked as spam.")
1355
1356 (defvar gnus-newsgroup-killed nil
1357   "List of ranges of articles that have been through the scoring process.")
1358
1359 (defvar gnus-newsgroup-cached nil
1360   "Sorted list of articles that come from the article cache.")
1361
1362 (defvar gnus-newsgroup-saved nil
1363   "List of articles that have been saved.")
1364
1365 (defvar gnus-newsgroup-kill-headers nil)
1366
1367 (defvar gnus-newsgroup-replied nil
1368   "List of articles that have been replied to in the current newsgroup.")
1369
1370 (defvar gnus-newsgroup-forwarded nil
1371   "List of articles that have been forwarded in the current newsgroup.")
1372
1373 (defvar gnus-newsgroup-recent nil
1374   "List of articles that have are recent in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-expirable nil
1377   "Sorted list of articles in the current newsgroup that can be expired.")
1378
1379 (defvar gnus-newsgroup-processable nil
1380   "List of articles in the current newsgroup that can be processed.")
1381
1382 (defvar gnus-newsgroup-downloadable nil
1383   "Sorted list of articles in the current newsgroup that can be processed.")
1384
1385 (defvar gnus-newsgroup-unfetched nil
1386   "Sorted list of articles in the current newsgroup whose headers have
1387 not been fetched into the agent.
1388
1389 This list will always be a subset of gnus-newsgroup-undownloaded.")
1390
1391 (defvar gnus-newsgroup-undownloaded nil
1392   "List of articles in the current newsgroup that haven't been downloaded.")
1393
1394 (defvar gnus-newsgroup-unsendable nil
1395   "List of articles in the current newsgroup that won't be sent.")
1396
1397 (defvar gnus-newsgroup-bookmarks nil
1398   "List of articles in the current newsgroup that have bookmarks.")
1399
1400 (defvar gnus-newsgroup-dormant nil
1401   "Sorted list of dormant articles in the current newsgroup.")
1402
1403 (defvar gnus-newsgroup-unseen nil
1404   "List of unseen articles in the current newsgroup.")
1405
1406 (defvar gnus-newsgroup-seen nil
1407   "Range of seen articles in the current newsgroup.")
1408
1409 (defvar gnus-newsgroup-articles nil
1410   "List of articles in the current newsgroup.")
1411
1412 (defvar gnus-newsgroup-scored nil
1413   "List of scored articles in the current newsgroup.")
1414
1415 (defvar gnus-newsgroup-headers nil
1416   "List of article headers in the current newsgroup.")
1417
1418 (defvar gnus-newsgroup-threads nil)
1419
1420 (defvar gnus-newsgroup-prepared nil
1421   "Whether the current group has been prepared properly.")
1422
1423 (defvar gnus-newsgroup-ancient nil
1424   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1425
1426 (defvar gnus-newsgroup-sparse nil)
1427
1428 (defvar gnus-current-article nil)
1429 (defvar gnus-article-current nil)
1430 (defvar gnus-current-headers nil)
1431 (defvar gnus-have-all-headers nil)
1432 (defvar gnus-last-article nil)
1433 (defvar gnus-newsgroup-history nil)
1434 (defvar gnus-newsgroup-charset nil)
1435 (defvar gnus-newsgroup-ephemeral-charset nil)
1436 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1437
1438 (defvar gnus-article-before-search nil)
1439
1440 (defvar gnus-summary-local-variables
1441   '(gnus-newsgroup-name
1442     gnus-newsgroup-begin gnus-newsgroup-end
1443     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1444     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1445     gnus-newsgroup-last-directory
1446     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1447     gnus-newsgroup-unselected gnus-newsgroup-marked
1448     gnus-newsgroup-spam-marked
1449     gnus-newsgroup-reads gnus-newsgroup-saved
1450     gnus-newsgroup-replied gnus-newsgroup-forwarded
1451     gnus-newsgroup-recent
1452     gnus-newsgroup-expirable
1453     gnus-newsgroup-processable gnus-newsgroup-killed
1454     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1455     gnus-newsgroup-unfetched
1456     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1457     gnus-newsgroup-seen gnus-newsgroup-articles
1458     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1459     gnus-newsgroup-headers gnus-newsgroup-threads
1460     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1461     gnus-current-article gnus-current-headers gnus-have-all-headers
1462     gnus-last-article gnus-article-internal-prepare-hook
1463     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1464     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1465     gnus-thread-expunge-below
1466     gnus-score-alist gnus-current-score-file
1467     (gnus-summary-expunge-below . global)
1468     (gnus-summary-mark-below . global)
1469     (gnus-orphan-score . global)
1470     gnus-newsgroup-active gnus-scores-exclude-files
1471     gnus-newsgroup-history gnus-newsgroup-ancient
1472     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1473     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1474     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1475     (gnus-newsgroup-expunged-tally . 0)
1476     gnus-cache-removable-articles gnus-newsgroup-cached
1477     gnus-newsgroup-data gnus-newsgroup-data-reverse
1478     gnus-newsgroup-limit gnus-newsgroup-limits
1479     gnus-newsgroup-charset gnus-newsgroup-display
1480     gnus-summary-use-undownloaded-faces)
1481   "Variables that are buffer-local to the summary buffers.")
1482
1483 (defvar gnus-newsgroup-variables nil
1484   "A list of variables that have separate values in different newsgroups.
1485 A list of newsgroup (summary buffer) local variables, or cons of
1486 variables and their default expressions to be evalled (when the default
1487 values are not nil), that should be made global while the summary buffer
1488 is active.
1489
1490 Note: The default expressions will be evaluated (using function `eval')
1491 before assignment to the local variable rather than just assigned to it.
1492 If the default expression is the symbol `global', that symbol will not
1493 be evaluated but the global value of the local variable will be used
1494 instead.
1495
1496 These variables can be used to set variables in the group parameters
1497 while still allowing them to affect operations done in other buffers.
1498 For example:
1499
1500 \(setq gnus-newsgroup-variables
1501      '(message-use-followup-to
1502        (gnus-visible-headers .
1503          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1504 ")
1505
1506 ;; Byte-compiler warning.
1507 (eval-when-compile
1508   ;; Bind features so that require will believe that gnus-sum has
1509   ;; already been loaded (avoids infinite recursion)
1510   (let ((features (cons 'gnus-sum features)))
1511     ;; Several of the declarations in gnus-sum are needed to load the
1512     ;; following files. Right now, these definitions have been
1513     ;; compiled but not defined (evaluated).  We could either do a
1514     ;; eval-and-compile about all of the declarations or evaluate the
1515     ;; source file.
1516     (if (boundp 'gnus-newsgroup-variables)
1517         nil
1518       (load "gnus-sum.el" t t t))
1519     (require 'gnus)
1520     (require 'gnus-art)))
1521
1522 ;; MIME stuff.
1523
1524 (defvar gnus-decode-encoded-word-methods
1525   '(mail-decode-encoded-word-string)
1526   "List of methods used to decode encoded words.
1527
1528 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1529 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1530 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1531 whose names match REGEXP.
1532
1533 For example:
1534 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1535  mail-decode-encoded-word-string
1536  (\"chinese\" . rfc1843-decode-string))")
1537
1538 (defvar gnus-decode-encoded-word-methods-cache nil)
1539
1540 (defun gnus-multi-decode-encoded-word-string (string)
1541   "Apply the functions from `gnus-encoded-word-methods' that match."
1542   (unless (and gnus-decode-encoded-word-methods-cache
1543                (eq gnus-newsgroup-name
1544                    (car gnus-decode-encoded-word-methods-cache)))
1545     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1546     (mapcar (lambda (x)
1547               (if (symbolp x)
1548                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1549                 (if (and gnus-newsgroup-name
1550                          (string-match (car x) gnus-newsgroup-name))
1551                     (nconc gnus-decode-encoded-word-methods-cache
1552                            (list (cdr x))))))
1553             gnus-decode-encoded-word-methods))
1554   (let ((xlist gnus-decode-encoded-word-methods-cache))
1555     (pop xlist)
1556     (while xlist
1557       (setq string (funcall (pop xlist) string))))
1558   string)
1559
1560 ;; Subject simplification.
1561
1562 (defun gnus-simplify-whitespace (str)
1563   "Remove excessive whitespace from STR."
1564   ;; Multiple spaces.
1565   (while (string-match "[ \t][ \t]+" str)
1566     (setq str (concat (substring str 0 (match-beginning 0))
1567                         " "
1568                         (substring str (match-end 0)))))
1569   ;; Leading spaces.
1570   (when (string-match "^[ \t]+" str)
1571     (setq str (substring str (match-end 0))))
1572   ;; Trailing spaces.
1573   (when (string-match "[ \t]+$" str)
1574     (setq str (substring str 0 (match-beginning 0))))
1575   str)
1576
1577 (defun gnus-simplify-all-whitespace (str)
1578   "Remove all whitespace from STR."
1579   (while (string-match "[ \t\n]+" str)
1580     (setq str (replace-match "" nil nil str)))
1581   str)
1582
1583 (defsubst gnus-simplify-subject-re (subject)
1584   "Remove \"Re:\" from subject lines."
1585   (if (string-match message-subject-re-regexp subject)
1586       (substring subject (match-end 0))
1587     subject))
1588
1589 (defun gnus-simplify-subject (subject &optional re-only)
1590   "Remove `Re:' and words in parentheses.
1591 If RE-ONLY is non-nil, strip leading `Re:'s only."
1592   (let ((case-fold-search t))           ;Ignore case.
1593     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1594     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1595       (setq subject (substring subject (match-end 0))))
1596     ;; Remove uninteresting prefixes.
1597     (when (and (not re-only)
1598                gnus-simplify-ignored-prefixes
1599                (string-match gnus-simplify-ignored-prefixes subject))
1600       (setq subject (substring subject (match-end 0))))
1601     ;; Remove words in parentheses from end.
1602     (unless re-only
1603       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1604         (setq subject (substring subject 0 (match-beginning 0)))))
1605     ;; Return subject string.
1606     subject))
1607
1608 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1609 ;; all whitespace.
1610 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1611   (goto-char (point-min))
1612   (while (re-search-forward regexp nil t)
1613     (replace-match (or newtext ""))))
1614
1615 (defun gnus-simplify-buffer-fuzzy ()
1616   "Simplify string in the buffer fuzzily.
1617 The string in the accessible portion of the current buffer is simplified.
1618 It is assumed to be a single-line subject.
1619 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1620 matter is removed.  Additional things can be deleted by setting
1621 `gnus-simplify-subject-fuzzy-regexp'."
1622   (let ((case-fold-search t)
1623         (modified-tick))
1624     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1625
1626     (while (not (eq modified-tick (buffer-modified-tick)))
1627       (setq modified-tick (buffer-modified-tick))
1628       (cond
1629        ((listp gnus-simplify-subject-fuzzy-regexp)
1630         (mapcar 'gnus-simplify-buffer-fuzzy-step
1631                 gnus-simplify-subject-fuzzy-regexp))
1632        (gnus-simplify-subject-fuzzy-regexp
1633         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1634       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1635       (gnus-simplify-buffer-fuzzy-step
1636        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1637       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1638
1639     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1640     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1641     (gnus-simplify-buffer-fuzzy-step " $")
1642     (gnus-simplify-buffer-fuzzy-step "^ +")))
1643
1644 (defun gnus-simplify-subject-fuzzy (subject)
1645   "Simplify a subject string fuzzily.
1646 See `gnus-simplify-buffer-fuzzy' for details."
1647   (save-excursion
1648     (gnus-set-work-buffer)
1649     (let ((case-fold-search t))
1650       ;; Remove uninteresting prefixes.
1651       (when (and gnus-simplify-ignored-prefixes
1652                  (string-match gnus-simplify-ignored-prefixes subject))
1653         (setq subject (substring subject (match-end 0))))
1654       (insert subject)
1655       (inline (gnus-simplify-buffer-fuzzy))
1656       (buffer-string))))
1657
1658 (defsubst gnus-simplify-subject-fully (subject)
1659   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1660   (cond
1661    (gnus-simplify-subject-functions
1662     (gnus-map-function gnus-simplify-subject-functions subject))
1663    ((null gnus-summary-gather-subject-limit)
1664     (gnus-simplify-subject-re subject))
1665    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1666     (gnus-simplify-subject-fuzzy subject))
1667    ((numberp gnus-summary-gather-subject-limit)
1668     (gnus-limit-string (gnus-simplify-subject-re subject)
1669                        gnus-summary-gather-subject-limit))
1670    (t
1671     subject)))
1672
1673 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1674   "Check whether two subjects are equal.
1675 If optional argument SIMPLE-FIRST is t, first argument is already
1676 simplified."
1677   (cond
1678    ((null simple-first)
1679     (equal (gnus-simplify-subject-fully s1)
1680            (gnus-simplify-subject-fully s2)))
1681    (t
1682     (equal s1
1683            (gnus-simplify-subject-fully s2)))))
1684
1685 (defun gnus-summary-bubble-group ()
1686   "Increase the score of the current group.
1687 This is a handy function to add to `gnus-summary-exit-hook' to
1688 increase the score of each group you read."
1689   (gnus-group-add-score gnus-newsgroup-name))
1690
1691 \f
1692 ;;;
1693 ;;; Gnus summary mode
1694 ;;;
1695
1696 (put 'gnus-summary-mode 'mode-class 'special)
1697
1698 (defvar gnus-article-commands-menu)
1699
1700 ;; Non-orthogonal keys
1701
1702 (gnus-define-keys gnus-summary-mode-map
1703   " " gnus-summary-next-page
1704   "\177" gnus-summary-prev-page
1705   [delete] gnus-summary-prev-page
1706   [backspace] gnus-summary-prev-page
1707   "\r" gnus-summary-scroll-up
1708   "\M-\r" gnus-summary-scroll-down
1709   "n" gnus-summary-next-unread-article
1710   "p" gnus-summary-prev-unread-article
1711   "N" gnus-summary-next-article
1712   "P" gnus-summary-prev-article
1713   "\M-\C-n" gnus-summary-next-same-subject
1714   "\M-\C-p" gnus-summary-prev-same-subject
1715   "\M-n" gnus-summary-next-unread-subject
1716   "\M-p" gnus-summary-prev-unread-subject
1717   "." gnus-summary-first-unread-article
1718   "," gnus-summary-best-unread-article
1719   "\M-s" gnus-summary-search-article-forward
1720   "\M-r" gnus-summary-search-article-backward
1721   "\M-S" gnus-summary-repeat-search-article-forward
1722   "\M-R" gnus-summary-repeat-search-article-backward
1723   "<" gnus-summary-beginning-of-article
1724   ">" gnus-summary-end-of-article
1725   "j" gnus-summary-goto-article
1726   "^" gnus-summary-refer-parent-article
1727   "\M-^" gnus-summary-refer-article
1728   "u" gnus-summary-tick-article-forward
1729   "!" gnus-summary-tick-article-forward
1730   "U" gnus-summary-tick-article-backward
1731   "d" gnus-summary-mark-as-read-forward
1732   "D" gnus-summary-mark-as-read-backward
1733   "E" gnus-summary-mark-as-expirable
1734   "\M-u" gnus-summary-clear-mark-forward
1735   "\M-U" gnus-summary-clear-mark-backward
1736   "k" gnus-summary-kill-same-subject-and-select
1737   "\C-k" gnus-summary-kill-same-subject
1738   "\M-\C-k" gnus-summary-kill-thread
1739   "\M-\C-l" gnus-summary-lower-thread
1740   "e" gnus-summary-edit-article
1741   "#" gnus-summary-mark-as-processable
1742   "\M-#" gnus-summary-unmark-as-processable
1743   "\M-\C-t" gnus-summary-toggle-threads
1744   "\M-\C-s" gnus-summary-show-thread
1745   "\M-\C-h" gnus-summary-hide-thread
1746   "\M-\C-f" gnus-summary-next-thread
1747   "\M-\C-b" gnus-summary-prev-thread
1748   [(meta down)] gnus-summary-next-thread
1749   [(meta up)] gnus-summary-prev-thread
1750   "\M-\C-u" gnus-summary-up-thread
1751   "\M-\C-d" gnus-summary-down-thread
1752   "&" gnus-summary-execute-command
1753   "c" gnus-summary-catchup-and-exit
1754   "\C-w" gnus-summary-mark-region-as-read
1755   "\C-t" gnus-summary-toggle-truncation
1756   "?" gnus-summary-mark-as-dormant
1757   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1758   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1759   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1760   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1761   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1762   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1763   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1764   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1765   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1766   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1767   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1768   "=" gnus-summary-expand-window
1769   "\C-x\C-s" gnus-summary-reselect-current-group
1770   "\M-g" gnus-summary-rescan-group
1771   "w" gnus-summary-stop-page-breaking
1772   "\C-c\C-r" gnus-summary-caesar-message
1773   "f" gnus-summary-followup
1774   "F" gnus-summary-followup-with-original
1775   "C" gnus-summary-cancel-article
1776   "r" gnus-summary-reply
1777   "R" gnus-summary-reply-with-original
1778   "\C-c\C-f" gnus-summary-mail-forward
1779   "o" gnus-summary-save-article
1780   "\C-o" gnus-summary-save-article-mail
1781   "|" gnus-summary-pipe-output
1782   "\M-k" gnus-summary-edit-local-kill
1783   "\M-K" gnus-summary-edit-global-kill
1784   ;; "V" gnus-version
1785   "\C-c\C-d" gnus-summary-describe-group
1786   "q" gnus-summary-exit
1787   "Q" gnus-summary-exit-no-update
1788   "\C-c\C-i" gnus-info-find-node
1789   gnus-mouse-2 gnus-mouse-pick-article
1790   [follow-link] mouse-face
1791   "m" gnus-summary-mail-other-window
1792   "a" gnus-summary-post-news
1793   "i" gnus-summary-news-other-window
1794   "x" gnus-summary-limit-to-unread
1795   "s" gnus-summary-isearch-article
1796   "t" gnus-summary-toggle-header
1797   "g" gnus-summary-show-article
1798   "l" gnus-summary-goto-last-article
1799   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1800   "\C-d" gnus-summary-enter-digest-group
1801   "\M-\C-d" gnus-summary-read-document
1802   "\M-\C-e" gnus-summary-edit-parameters
1803   "\M-\C-a" gnus-summary-customize-parameters
1804   "\C-c\C-b" gnus-bug
1805   "*" gnus-cache-enter-article
1806   "\M-*" gnus-cache-remove-article
1807   "\M-&" gnus-summary-universal-argument
1808   "\C-l" gnus-recenter
1809   "I" gnus-summary-increase-score
1810   "L" gnus-summary-lower-score
1811   "\M-i" gnus-symbolic-argument
1812   "h" gnus-summary-select-article-buffer
1813
1814   "b" gnus-article-view-part
1815   "\M-t" gnus-summary-toggle-display-buttonized
1816
1817   "V" gnus-summary-score-map
1818   "X" gnus-uu-extract-map
1819   "S" gnus-summary-send-map)
1820
1821 ;; Sort of orthogonal keymap
1822 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1823   "t" gnus-summary-tick-article-forward
1824   "!" gnus-summary-tick-article-forward
1825   "d" gnus-summary-mark-as-read-forward
1826   "r" gnus-summary-mark-as-read-forward
1827   "c" gnus-summary-clear-mark-forward
1828   " " gnus-summary-clear-mark-forward
1829   "e" gnus-summary-mark-as-expirable
1830   "x" gnus-summary-mark-as-expirable
1831   "?" gnus-summary-mark-as-dormant
1832   "b" gnus-summary-set-bookmark
1833   "B" gnus-summary-remove-bookmark
1834   "#" gnus-summary-mark-as-processable
1835   "\M-#" gnus-summary-unmark-as-processable
1836   "S" gnus-summary-limit-include-expunged
1837   "C" gnus-summary-catchup
1838   "H" gnus-summary-catchup-to-here
1839   "h" gnus-summary-catchup-from-here
1840   "\C-c" gnus-summary-catchup-all
1841   "k" gnus-summary-kill-same-subject-and-select
1842   "K" gnus-summary-kill-same-subject
1843   "P" gnus-uu-mark-map)
1844
1845 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1846   "c" gnus-summary-clear-above
1847   "u" gnus-summary-tick-above
1848   "m" gnus-summary-mark-above
1849   "k" gnus-summary-kill-below)
1850
1851 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1852   "/" gnus-summary-limit-to-subject
1853   "n" gnus-summary-limit-to-articles
1854   "b" gnus-summary-limit-to-bodies
1855   "w" gnus-summary-pop-limit
1856   "s" gnus-summary-limit-to-subject
1857   "a" gnus-summary-limit-to-author
1858   "u" gnus-summary-limit-to-unread
1859   "m" gnus-summary-limit-to-marks
1860   "M" gnus-summary-limit-exclude-marks
1861   "v" gnus-summary-limit-to-score
1862   "*" gnus-summary-limit-include-cached
1863   "D" gnus-summary-limit-include-dormant
1864   "T" gnus-summary-limit-include-thread
1865   "d" gnus-summary-limit-exclude-dormant
1866   "t" gnus-summary-limit-to-age
1867   "." gnus-summary-limit-to-unseen
1868   "x" gnus-summary-limit-to-extra
1869   "p" gnus-summary-limit-to-display-predicate
1870   "E" gnus-summary-limit-include-expunged
1871   "c" gnus-summary-limit-exclude-childless-dormant
1872   "C" gnus-summary-limit-mark-excluded-as-read
1873   "o" gnus-summary-insert-old-articles
1874   "N" gnus-summary-insert-new-articles
1875   "r" gnus-summary-limit-to-replied
1876   "R" gnus-summary-limit-to-recipient)
1877
1878 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1879   "n" gnus-summary-next-unread-article
1880   "p" gnus-summary-prev-unread-article
1881   "N" gnus-summary-next-article
1882   "P" gnus-summary-prev-article
1883   "\C-n" gnus-summary-next-same-subject
1884   "\C-p" gnus-summary-prev-same-subject
1885   "\M-n" gnus-summary-next-unread-subject
1886   "\M-p" gnus-summary-prev-unread-subject
1887   "f" gnus-summary-first-unread-article
1888   "b" gnus-summary-best-unread-article
1889   "j" gnus-summary-goto-article
1890   "g" gnus-summary-goto-subject
1891   "l" gnus-summary-goto-last-article
1892   "o" gnus-summary-pop-article)
1893
1894 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1895   "k" gnus-summary-kill-thread
1896   "l" gnus-summary-lower-thread
1897   "i" gnus-summary-raise-thread
1898   "T" gnus-summary-toggle-threads
1899   "t" gnus-summary-rethread-current
1900   "^" gnus-summary-reparent-thread
1901   "\M-^" gnus-summary-reparent-children
1902   "s" gnus-summary-show-thread
1903   "S" gnus-summary-show-all-threads
1904   "h" gnus-summary-hide-thread
1905   "H" gnus-summary-hide-all-threads
1906   "n" gnus-summary-next-thread
1907   "p" gnus-summary-prev-thread
1908   "u" gnus-summary-up-thread
1909   "o" gnus-summary-top-thread
1910   "d" gnus-summary-down-thread
1911   "#" gnus-uu-mark-thread
1912   "\M-#" gnus-uu-unmark-thread)
1913
1914 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1915   "g" gnus-summary-prepare
1916   "c" gnus-summary-insert-cached-articles
1917   "d" gnus-summary-insert-dormant-articles)
1918
1919 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1920   "c" gnus-summary-catchup-and-exit
1921   "C" gnus-summary-catchup-all-and-exit
1922   "E" gnus-summary-exit-no-update
1923   "Q" gnus-summary-exit
1924   "Z" gnus-summary-exit
1925   "n" gnus-summary-catchup-and-goto-next-group
1926   "p" gnus-summary-catchup-and-goto-prev-group
1927   "R" gnus-summary-reselect-current-group
1928   "G" gnus-summary-rescan-group
1929   "N" gnus-summary-next-group
1930   "s" gnus-summary-save-newsrc
1931   "P" gnus-summary-prev-group)
1932
1933 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1934   " " gnus-summary-next-page
1935   "n" gnus-summary-next-page
1936   "\177" gnus-summary-prev-page
1937   [delete] gnus-summary-prev-page
1938   "p" gnus-summary-prev-page
1939   "\r" gnus-summary-scroll-up
1940   "\M-\r" gnus-summary-scroll-down
1941   "<" gnus-summary-beginning-of-article
1942   ">" gnus-summary-end-of-article
1943   "b" gnus-summary-beginning-of-article
1944   "e" gnus-summary-end-of-article
1945   "^" gnus-summary-refer-parent-article
1946   "r" gnus-summary-refer-parent-article
1947   "D" gnus-summary-enter-digest-group
1948   "R" gnus-summary-refer-references
1949   "T" gnus-summary-refer-thread
1950   "g" gnus-summary-show-article
1951   "s" gnus-summary-isearch-article
1952   "P" gnus-summary-print-article
1953   "M" gnus-mailing-list-insinuate
1954   "t" gnus-article-babel)
1955
1956 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1957   "b" gnus-article-add-buttons
1958   "B" gnus-article-add-buttons-to-head
1959   "o" gnus-article-treat-overstrike
1960   "e" gnus-article-emphasize
1961   "w" gnus-article-fill-cited-article
1962   "Q" gnus-article-fill-long-lines
1963   "L" gnus-article-toggle-truncate-lines
1964   "C" gnus-article-capitalize-sentences
1965   "c" gnus-article-remove-cr
1966   "q" gnus-article-de-quoted-unreadable
1967   "6" gnus-article-de-base64-unreadable
1968   "Z" gnus-article-decode-HZ
1969   "A" gnus-article-treat-ansi-sequences
1970   "h" gnus-article-wash-html
1971   "u" gnus-article-unsplit-urls
1972   "s" gnus-summary-force-verify-and-decrypt
1973   "f" gnus-article-display-x-face
1974   "l" gnus-summary-stop-page-breaking
1975   "r" gnus-summary-caesar-message
1976   "m" gnus-summary-morse-message
1977   "t" gnus-summary-toggle-header
1978   "g" gnus-treat-smiley
1979   "v" gnus-summary-verbose-headers
1980   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1981   "p" gnus-article-verify-x-pgp-sig
1982   "d" gnus-article-treat-dumbquotes
1983   "i" gnus-summary-idna-message)
1984
1985 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1986   ;; mnemonic: deuglif*Y*
1987   "u" gnus-article-outlook-unwrap-lines
1988   "a" gnus-article-outlook-repair-attribution
1989   "c" gnus-article-outlook-rearrange-citation
1990   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1991
1992 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1993   "a" gnus-article-hide
1994   "h" gnus-article-hide-headers
1995   "b" gnus-article-hide-boring-headers
1996   "s" gnus-article-hide-signature
1997   "c" gnus-article-hide-citation
1998   "C" gnus-article-hide-citation-in-followups
1999   "l" gnus-article-hide-list-identifiers
2000   "B" gnus-article-strip-banner
2001   "P" gnus-article-hide-pem
2002   "\C-c" gnus-article-hide-citation-maybe)
2003
2004 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2005   "a" gnus-article-highlight
2006   "h" gnus-article-highlight-headers
2007   "c" gnus-article-highlight-citation
2008   "s" gnus-article-highlight-signature)
2009
2010 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2011   "f" gnus-article-treat-fold-headers
2012   "u" gnus-article-treat-unfold-headers
2013   "n" gnus-article-treat-fold-newsgroups)
2014
2015 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2016   "x" gnus-article-display-x-face
2017   "d" gnus-article-display-face
2018   "s" gnus-treat-smiley
2019   "D" gnus-article-remove-images
2020   "f" gnus-treat-from-picon
2021   "m" gnus-treat-mail-picon
2022   "n" gnus-treat-newsgroups-picon)
2023
2024 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2025   "w" gnus-article-decode-mime-words
2026   "c" gnus-article-decode-charset
2027   "v" gnus-mime-view-all-parts
2028   "b" gnus-article-view-part)
2029
2030 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2031   "z" gnus-article-date-ut
2032   "u" gnus-article-date-ut
2033   "l" gnus-article-date-local
2034   "p" gnus-article-date-english
2035   "e" gnus-article-date-lapsed
2036   "o" gnus-article-date-original
2037   "i" gnus-article-date-iso8601
2038   "s" gnus-article-date-user)
2039
2040 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2041   "t" gnus-article-remove-trailing-blank-lines
2042   "l" gnus-article-strip-leading-blank-lines
2043   "m" gnus-article-strip-multiple-blank-lines
2044   "a" gnus-article-strip-blank-lines
2045   "A" gnus-article-strip-all-blank-lines
2046   "s" gnus-article-strip-leading-space
2047   "e" gnus-article-strip-trailing-space
2048   "w" gnus-article-remove-leading-whitespace)
2049
2050 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2051   "v" gnus-version
2052   "f" gnus-summary-fetch-faq
2053   "d" gnus-summary-describe-group
2054   "h" gnus-summary-describe-briefly
2055   "i" gnus-info-find-node
2056   "c" gnus-group-fetch-charter
2057   "C" gnus-group-fetch-control)
2058
2059 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2060   "e" gnus-summary-expire-articles
2061   "\M-\C-e" gnus-summary-expire-articles-now
2062   "\177" gnus-summary-delete-article
2063   [delete] gnus-summary-delete-article
2064   [backspace] gnus-summary-delete-article
2065   "m" gnus-summary-move-article
2066   "r" gnus-summary-respool-article
2067   "w" gnus-summary-edit-article
2068   "c" gnus-summary-copy-article
2069   "B" gnus-summary-crosspost-article
2070   "q" gnus-summary-respool-query
2071   "t" gnus-summary-respool-trace
2072   "i" gnus-summary-import-article
2073   "I" gnus-summary-create-article
2074   "p" gnus-summary-article-posted-p)
2075
2076 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2077   "o" gnus-summary-save-article
2078   "m" gnus-summary-save-article-mail
2079   "F" gnus-summary-write-article-file
2080   "r" gnus-summary-save-article-rmail
2081   "f" gnus-summary-save-article-file
2082   "b" gnus-summary-save-article-body-file
2083   "B" gnus-summary-write-article-body-file
2084   "h" gnus-summary-save-article-folder
2085   "v" gnus-summary-save-article-vm
2086   "p" gnus-summary-pipe-output
2087   "P" gnus-summary-muttprint
2088   "s" gnus-soup-add-article)
2089
2090 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2091   "b" gnus-summary-display-buttonized
2092   "m" gnus-summary-repair-multipart
2093   "v" gnus-article-view-part
2094   "o" gnus-article-save-part
2095   "O" gnus-article-save-part-and-strip
2096   "r" gnus-article-replace-part
2097   "d" gnus-article-delete-part
2098   "t" gnus-article-view-part-as-type
2099   "j" gnus-article-jump-to-part
2100   "c" gnus-article-copy-part
2101   "C" gnus-article-view-part-as-charset
2102   "e" gnus-article-view-part-externally
2103   "H" gnus-article-browse-html-article
2104   "E" gnus-article-encrypt-body
2105   "i" gnus-article-inline-part
2106   "|" gnus-article-pipe-part)
2107
2108 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2109   "p" gnus-summary-mark-as-processable
2110   "u" gnus-summary-unmark-as-processable
2111   "U" gnus-summary-unmark-all-processable
2112   "v" gnus-uu-mark-over
2113   "s" gnus-uu-mark-series
2114   "r" gnus-uu-mark-region
2115   "g" gnus-uu-unmark-region
2116   "R" gnus-uu-mark-by-regexp
2117   "G" gnus-uu-unmark-by-regexp
2118   "t" gnus-uu-mark-thread
2119   "T" gnus-uu-unmark-thread
2120   "a" gnus-uu-mark-all
2121   "b" gnus-uu-mark-buffer
2122   "S" gnus-uu-mark-sparse
2123   "k" gnus-summary-kill-process-mark
2124   "y" gnus-summary-yank-process-mark
2125   "w" gnus-summary-save-process-mark
2126   "i" gnus-uu-invert-processable)
2127
2128 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2129   ;;"x" gnus-uu-extract-any
2130   "m" gnus-summary-save-parts
2131   "u" gnus-uu-decode-uu
2132   "U" gnus-uu-decode-uu-and-save
2133   "s" gnus-uu-decode-unshar
2134   "S" gnus-uu-decode-unshar-and-save
2135   "o" gnus-uu-decode-save
2136   "O" gnus-uu-decode-save
2137   "b" gnus-uu-decode-binhex
2138   "B" gnus-uu-decode-binhex
2139   "p" gnus-uu-decode-postscript
2140   "P" gnus-uu-decode-postscript-and-save)
2141
2142 (gnus-define-keys
2143     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2144   "u" gnus-uu-decode-uu-view
2145   "U" gnus-uu-decode-uu-and-save-view
2146   "s" gnus-uu-decode-unshar-view
2147   "S" gnus-uu-decode-unshar-and-save-view
2148   "o" gnus-uu-decode-save-view
2149   "O" gnus-uu-decode-save-view
2150   "b" gnus-uu-decode-binhex-view
2151   "B" gnus-uu-decode-binhex-view
2152   "p" gnus-uu-decode-postscript-view
2153   "P" gnus-uu-decode-postscript-and-save-view)
2154
2155 (defvar gnus-article-post-menu nil)
2156
2157 (defconst gnus-summary-menu-maxlen 20)
2158
2159 (defun gnus-summary-menu-split (menu)
2160   ;; If we have lots of elements, divide them into groups of 20
2161   ;; and make a pane (or submenu) for each one.
2162   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2163       (let ((menu menu) sublists next
2164             (i 1))
2165         (while menu
2166           ;; Pull off the next gnus-summary-menu-maxlen elements
2167           ;; and make them the next element of sublist.
2168           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2169           (if next
2170               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2171                       nil))
2172           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2173                                              (aref (car (last menu)) 0)) menu)
2174                                sublists))
2175           (setq i (1+ i))
2176           (setq menu next))
2177         (nreverse sublists))
2178     ;; Few elements--put them all in one pane.
2179     menu))
2180
2181 (defun gnus-summary-make-menu-bar ()
2182   (gnus-turn-off-edit-menu 'summary)
2183
2184   (unless (boundp 'gnus-summary-misc-menu)
2185
2186     (easy-menu-define
2187       gnus-summary-kill-menu gnus-summary-mode-map ""
2188       (cons
2189        "Score"
2190        (nconc
2191         (list
2192          ["Customize" gnus-score-customize t])
2193         (gnus-make-score-map 'increase)
2194         (gnus-make-score-map 'lower)
2195         '(("Mark"
2196            ["Kill below" gnus-summary-kill-below t]
2197            ["Mark above" gnus-summary-mark-above t]
2198            ["Tick above" gnus-summary-tick-above t]
2199            ["Clear above" gnus-summary-clear-above t])
2200           ["Current score" gnus-summary-current-score t]
2201           ["Set score" gnus-summary-set-score t]
2202           ["Switch current score file..." gnus-score-change-score-file t]
2203           ["Set mark below..." gnus-score-set-mark-below t]
2204           ["Set expunge below..." gnus-score-set-expunge-below t]
2205           ["Edit current score file" gnus-score-edit-current-scores t]
2206           ["Edit score file" gnus-score-edit-file t]
2207           ["Trace score" gnus-score-find-trace t]
2208           ["Find words" gnus-score-find-favourite-words t]
2209           ["Rescore buffer" gnus-summary-rescore t]
2210           ["Increase score..." gnus-summary-increase-score t]
2211           ["Lower score..." gnus-summary-lower-score t]))))
2212
2213     ;; Define both the Article menu in the summary buffer and the
2214     ;; equivalent Commands menu in the article buffer here for
2215     ;; consistency.
2216     (let ((innards
2217            `(("Hide"
2218               ["All" gnus-article-hide t]
2219               ["Headers" gnus-article-hide-headers t]
2220               ["Signature" gnus-article-hide-signature t]
2221               ["Citation" gnus-article-hide-citation t]
2222               ["List identifiers" gnus-article-hide-list-identifiers t]
2223               ["Banner" gnus-article-strip-banner t]
2224               ["Boring headers" gnus-article-hide-boring-headers t])
2225              ("Highlight"
2226               ["All" gnus-article-highlight t]
2227               ["Headers" gnus-article-highlight-headers t]
2228               ["Signature" gnus-article-highlight-signature t]
2229               ["Citation" gnus-article-highlight-citation t])
2230              ("MIME"
2231               ["Words" gnus-article-decode-mime-words t]
2232               ["Charset" gnus-article-decode-charset t]
2233               ["QP" gnus-article-de-quoted-unreadable t]
2234               ["Base64" gnus-article-de-base64-unreadable t]
2235               ["View MIME buttons" gnus-summary-display-buttonized t]
2236               ["View all" gnus-mime-view-all-parts t]
2237               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2238               ["Encrypt body" gnus-article-encrypt-body
2239                :active (not (gnus-group-read-only-p))
2240                ,@(if (featurep 'xemacs) nil
2241                    '(:help "Encrypt the message body on disk"))]
2242               ["Extract all parts..." gnus-summary-save-parts t]
2243               ("Multipart"
2244                ["Repair multipart" gnus-summary-repair-multipart t]
2245                ["Pipe part..." gnus-article-pipe-part t]
2246                ["Inline part" gnus-article-inline-part t]
2247                ["View part as type..." gnus-article-view-part-as-type t]
2248                ["Encrypt body" gnus-article-encrypt-body
2249                 :active (not (gnus-group-read-only-p))
2250                ,@(if (featurep 'xemacs) nil
2251                    '(:help "Encrypt the message body on disk"))]
2252                ["View part externally" gnus-article-view-part-externally t]
2253                ["View HTML parts in browser" gnus-article-browse-html-article t]
2254                ["View part with charset..." gnus-article-view-part-as-charset t]
2255                ["Copy part" gnus-article-copy-part t]
2256                ["Save part..." gnus-article-save-part t]
2257                ["View part" gnus-article-view-part t]))
2258              ("Date"
2259               ["Local" gnus-article-date-local t]
2260               ["ISO8601" gnus-article-date-iso8601 t]
2261               ["UT" gnus-article-date-ut t]
2262               ["Original" gnus-article-date-original t]
2263               ["Lapsed" gnus-article-date-lapsed t]
2264               ["User-defined" gnus-article-date-user t])
2265              ("Display"
2266               ["Remove images" gnus-article-remove-images t]
2267               ["Toggle smiley" gnus-treat-smiley t]
2268               ["Show X-Face" gnus-article-display-x-face t]
2269               ["Show picons in From" gnus-treat-from-picon t]
2270               ["Show picons in mail headers" gnus-treat-mail-picon t]
2271               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2272               ("View as different encoding"
2273                ,@(gnus-summary-menu-split
2274                   (mapcar
2275                    (lambda (cs)
2276                      ;; Since easymenu under Emacs doesn't allow
2277                      ;; lambda forms for menu commands, we should
2278                      ;; provide intern'ed function symbols.
2279                      (let ((command (intern (format "\
2280 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2281                        (fset command
2282                              `(lambda ()
2283                                 (interactive)
2284                                 (let ((gnus-summary-show-article-charset-alist
2285                                        '((1 . ,cs))))
2286                                   (gnus-summary-show-article 1))))
2287                        `[,(symbol-name cs) ,command t]))
2288                    (sort (if (fboundp 'coding-system-list)
2289                              (coding-system-list)
2290                            (mapcar 'car mm-mime-mule-charset-alist))
2291                          'string<)))))
2292              ("Washing"
2293               ("Remove Blanks"
2294                ["Leading" gnus-article-strip-leading-blank-lines t]
2295                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2296                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2297                ["All of the above" gnus-article-strip-blank-lines t]
2298                ["All" gnus-article-strip-all-blank-lines t]
2299                ["Leading space" gnus-article-strip-leading-space t]
2300                ["Trailing space" gnus-article-strip-trailing-space t]
2301                ["Leading space in headers"
2302                 gnus-article-remove-leading-whitespace t])
2303               ["Overstrike" gnus-article-treat-overstrike t]
2304               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2305               ["Emphasis" gnus-article-emphasize t]
2306               ["Word wrap" gnus-article-fill-cited-article t]
2307               ["Fill long lines" gnus-article-fill-long-lines t]
2308               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2309               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2310               ["Remove CR" gnus-article-remove-cr t]
2311               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2312               ["Base64" gnus-article-de-base64-unreadable t]
2313               ["Rot 13" gnus-summary-caesar-message
2314                ,@(if (featurep 'xemacs) '(t)
2315                    '(:help "\"Caesar rotate\" article by 13"))]
2316               ["De-IDNA" gnus-summary-idna-message t]
2317               ["Morse decode" gnus-summary-morse-message t]
2318               ["Unix pipe..." gnus-summary-pipe-message t]
2319               ["Add buttons" gnus-article-add-buttons t]
2320               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2321               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2322               ["Verbose header" gnus-summary-verbose-headers t]
2323               ["Toggle header" gnus-summary-toggle-header t]
2324               ["Unfold headers" gnus-article-treat-unfold-headers t]
2325               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2326               ["Html" gnus-article-wash-html t]
2327               ["Unsplit URLs" gnus-article-unsplit-urls t]
2328               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2329               ["Decode HZ" gnus-article-decode-HZ t]
2330               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2331               ("(Outlook) Deuglify"
2332                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2333                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2334                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2335                ["Full (Outlook) deuglify"
2336                 gnus-article-outlook-deuglify-article t])
2337               )
2338              ("Output"
2339               ["Save in default format..." gnus-summary-save-article
2340                ,@(if (featurep 'xemacs) '(t)
2341                    '(:help "Save article using default method"))]
2342               ["Save in file..." gnus-summary-save-article-file
2343                ,@(if (featurep 'xemacs) '(t)
2344                    '(:help "Save article in file"))]
2345               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2346               ["Save in MH folder..." gnus-summary-save-article-folder t]
2347               ["Save in VM folder..." gnus-summary-save-article-vm t]
2348               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2349               ["Save body in file..." gnus-summary-save-article-body-file t]
2350               ["Pipe through a filter..." gnus-summary-pipe-output t]
2351               ["Add to SOUP packet" gnus-soup-add-article t]
2352               ["Print with Muttprint..." gnus-summary-muttprint t]
2353               ["Print" gnus-summary-print-article
2354                ,@(if (featurep 'xemacs) '(t)
2355                    '(:help "Generate and print a PostScript image"))])
2356              ("Copy, move,... (Backend)"
2357               ,@(if (featurep 'xemacs) nil
2358                   '(:help "Copying, moving, expiring articles..."))
2359               ["Respool article..." gnus-summary-respool-article t]
2360               ["Move article..." gnus-summary-move-article
2361                (gnus-check-backend-function
2362                 'request-move-article gnus-newsgroup-name)]
2363               ["Copy article..." gnus-summary-copy-article t]
2364               ["Crosspost article..." gnus-summary-crosspost-article
2365                (gnus-check-backend-function
2366                 'request-replace-article gnus-newsgroup-name)]
2367               ["Import file..." gnus-summary-import-article
2368                (gnus-check-backend-function
2369                 'request-accept-article gnus-newsgroup-name)]
2370               ["Create article..." gnus-summary-create-article
2371                (gnus-check-backend-function
2372                 'request-accept-article gnus-newsgroup-name)]
2373               ["Check if posted" gnus-summary-article-posted-p t]
2374               ["Edit article" gnus-summary-edit-article
2375                (not (gnus-group-read-only-p))]
2376               ["Delete article" gnus-summary-delete-article
2377                (gnus-check-backend-function
2378                 'request-expire-articles gnus-newsgroup-name)]
2379               ["Query respool" gnus-summary-respool-query t]
2380               ["Trace respool" gnus-summary-respool-trace t]
2381               ["Delete expirable articles" gnus-summary-expire-articles-now
2382                (gnus-check-backend-function
2383                 'request-expire-articles gnus-newsgroup-name)])
2384              ("Extract"
2385               ["Uudecode" gnus-uu-decode-uu
2386                ,@(if (featurep 'xemacs) '(t)
2387                    '(:help "Decode uuencoded article(s)"))]
2388               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2389               ["Unshar" gnus-uu-decode-unshar t]
2390               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2391               ["Save" gnus-uu-decode-save t]
2392               ["Binhex" gnus-uu-decode-binhex t]
2393               ["Postscript" gnus-uu-decode-postscript t]
2394               ["All MIME parts" gnus-summary-save-parts t])
2395              ("Cache"
2396               ["Enter article" gnus-cache-enter-article t]
2397               ["Remove article" gnus-cache-remove-article t])
2398              ["Translate" gnus-article-babel t]
2399              ["Select article buffer" gnus-summary-select-article-buffer t]
2400              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2401              ["Isearch article..." gnus-summary-isearch-article t]
2402              ["Beginning of the article" gnus-summary-beginning-of-article t]
2403              ["End of the article" gnus-summary-end-of-article t]
2404              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2405              ["Fetch referenced articles" gnus-summary-refer-references t]
2406              ["Fetch current thread" gnus-summary-refer-thread t]
2407              ["Fetch article with id..." gnus-summary-refer-article t]
2408              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2409              ["Redisplay" gnus-summary-show-article t]
2410              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2411       (easy-menu-define
2412         gnus-summary-article-menu gnus-summary-mode-map ""
2413         (cons "Article" innards))
2414
2415       (if (not (keymapp gnus-summary-article-menu))
2416           (easy-menu-define
2417             gnus-article-commands-menu gnus-article-mode-map ""
2418             (cons "Commands" innards))
2419         ;; in Emacs, don't share menu.
2420         (setq gnus-article-commands-menu
2421               (copy-keymap gnus-summary-article-menu))
2422         (define-key gnus-article-mode-map [menu-bar commands]
2423           (cons "Commands" gnus-article-commands-menu))))
2424
2425     (easy-menu-define
2426       gnus-summary-thread-menu gnus-summary-mode-map ""
2427       '("Threads"
2428         ["Find all messages in thread" gnus-summary-refer-thread t]
2429         ["Toggle threading" gnus-summary-toggle-threads t]
2430         ["Hide threads" gnus-summary-hide-all-threads t]
2431         ["Show threads" gnus-summary-show-all-threads t]
2432         ["Hide thread" gnus-summary-hide-thread t]
2433         ["Show thread" gnus-summary-show-thread t]
2434         ["Go to next thread" gnus-summary-next-thread t]
2435         ["Go to previous thread" gnus-summary-prev-thread t]
2436         ["Go down thread" gnus-summary-down-thread t]
2437         ["Go up thread" gnus-summary-up-thread t]
2438         ["Top of thread" gnus-summary-top-thread t]
2439         ["Mark thread as read" gnus-summary-kill-thread t]
2440         ["Lower thread score" gnus-summary-lower-thread t]
2441         ["Raise thread score" gnus-summary-raise-thread t]
2442         ["Rethread current" gnus-summary-rethread-current t]))
2443
2444     (easy-menu-define
2445       gnus-summary-post-menu gnus-summary-mode-map ""
2446       `("Post"
2447         ["Send a message (mail or news)" gnus-summary-post-news
2448          ,@(if (featurep 'xemacs) '(t)
2449              '(:help "Compose a new message (mail or news)"))]
2450         ["Followup" gnus-summary-followup
2451          ,@(if (featurep 'xemacs) '(t)
2452              '(:help "Post followup to this article"))]
2453         ["Followup and yank" gnus-summary-followup-with-original
2454          ,@(if (featurep 'xemacs) '(t)
2455              '(:help "Post followup to this article, quoting its contents"))]
2456         ["Supersede article" gnus-summary-supersede-article t]
2457         ["Cancel article" gnus-summary-cancel-article
2458          ,@(if (featurep 'xemacs) '(t)
2459              '(:help "Cancel an article you posted"))]
2460         ["Reply" gnus-summary-reply t]
2461         ["Reply and yank" gnus-summary-reply-with-original t]
2462         ["Wide reply" gnus-summary-wide-reply t]
2463         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2464          ,@(if (featurep 'xemacs) '(t)
2465              '(:help "Mail a reply, quoting this article"))]
2466         ["Very wide reply" gnus-summary-very-wide-reply t]
2467         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2468          ,@(if (featurep 'xemacs) '(t)
2469              '(:help "Mail a very wide reply, quoting this article"))]
2470         ["Mail forward" gnus-summary-mail-forward t]
2471         ["Post forward" gnus-summary-post-forward t]
2472         ["Digest and mail" gnus-uu-digest-mail-forward t]
2473         ["Digest and post" gnus-uu-digest-post-forward t]
2474         ["Resend message" gnus-summary-resend-message t]
2475         ["Resend message edit" gnus-summary-resend-message-edit t]
2476         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2477         ["Send a mail" gnus-summary-mail-other-window t]
2478         ["Create a local message" gnus-summary-news-other-window t]
2479         ["Uuencode and post" gnus-uu-post-news
2480          ,@(if (featurep 'xemacs) '(t)
2481              '(:help "Post a uuencoded article"))]
2482         ["Followup via news" gnus-summary-followup-to-mail t]
2483         ["Followup via news and yank"
2484          gnus-summary-followup-to-mail-with-original t]
2485         ;;("Draft"
2486         ;;["Send" gnus-summary-send-draft t]
2487         ;;["Send bounced" gnus-resend-bounced-mail t])
2488         ))
2489
2490     (cond
2491      ((not (keymapp gnus-summary-post-menu))
2492       (setq gnus-article-post-menu gnus-summary-post-menu))
2493      ((not gnus-article-post-menu)
2494       ;; Don't share post menu.
2495       (setq gnus-article-post-menu
2496             (copy-keymap gnus-summary-post-menu))))
2497     (define-key gnus-article-mode-map [menu-bar post]
2498       (cons "Post" gnus-article-post-menu))
2499
2500     (easy-menu-define
2501       gnus-summary-misc-menu gnus-summary-mode-map ""
2502       `("Gnus"
2503         ("Mark Read"
2504          ["Mark as read" gnus-summary-mark-as-read-forward t]
2505          ["Mark same subject and select"
2506           gnus-summary-kill-same-subject-and-select t]
2507          ["Mark same subject" gnus-summary-kill-same-subject t]
2508          ["Catchup" gnus-summary-catchup
2509           ,@(if (featurep 'xemacs) '(t)
2510               '(:help "Mark unread articles in this group as read"))]
2511          ["Catchup all" gnus-summary-catchup-all t]
2512          ["Catchup to here" gnus-summary-catchup-to-here t]
2513          ["Catchup from here" gnus-summary-catchup-from-here t]
2514          ["Catchup region" gnus-summary-mark-region-as-read
2515           (gnus-mark-active-p)]
2516          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2517         ("Mark Various"
2518          ["Tick" gnus-summary-tick-article-forward t]
2519          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2520          ["Remove marks" gnus-summary-clear-mark-forward t]
2521          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2522          ["Set bookmark" gnus-summary-set-bookmark t]
2523          ["Remove bookmark" gnus-summary-remove-bookmark t])
2524         ("Limit to"
2525          ["Marks..." gnus-summary-limit-to-marks t]
2526          ["Subject..." gnus-summary-limit-to-subject t]
2527          ["Author..." gnus-summary-limit-to-author t]
2528          ["Recipient..." gnus-summary-limit-to-recipient t]
2529          ["Age..." gnus-summary-limit-to-age t]
2530          ["Extra..." gnus-summary-limit-to-extra t]
2531          ["Score..." gnus-summary-limit-to-score t]
2532          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2533          ["Unread" gnus-summary-limit-to-unread t]
2534          ["Unseen" gnus-summary-limit-to-unseen t]
2535          ["Replied" gnus-summary-limit-to-replied t]
2536          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2537          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2538          ["Pop limit" gnus-summary-pop-limit t]
2539          ["Show dormant" gnus-summary-limit-include-dormant t]
2540          ["Hide childless dormant"
2541           gnus-summary-limit-exclude-childless-dormant t]
2542          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2543          ["Hide marked" gnus-summary-limit-exclude-marks t]
2544          ["Show expunged" gnus-summary-limit-include-expunged t])
2545         ("Process Mark"
2546          ["Set mark" gnus-summary-mark-as-processable t]
2547          ["Remove mark" gnus-summary-unmark-as-processable t]
2548          ["Remove all marks" gnus-summary-unmark-all-processable t]
2549          ["Invert marks" gnus-uu-invert-processable t]
2550          ["Mark above" gnus-uu-mark-over t]
2551          ["Mark series" gnus-uu-mark-series t]
2552          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2553          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2554          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2555          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2556          ["Mark all" gnus-uu-mark-all t]
2557          ["Mark buffer" gnus-uu-mark-buffer t]
2558          ["Mark sparse" gnus-uu-mark-sparse t]
2559          ["Mark thread" gnus-uu-mark-thread t]
2560          ["Unmark thread" gnus-uu-unmark-thread t]
2561          ("Process Mark Sets"
2562           ["Kill" gnus-summary-kill-process-mark t]
2563           ["Yank" gnus-summary-yank-process-mark
2564            gnus-newsgroup-process-stack]
2565           ["Save" gnus-summary-save-process-mark t]
2566           ["Run command on marked..." gnus-summary-universal-argument t]))
2567         ("Scroll article"
2568          ["Page forward" gnus-summary-next-page
2569           ,@(if (featurep 'xemacs) '(t)
2570               '(:help "Show next page of article"))]
2571          ["Page backward" gnus-summary-prev-page
2572           ,@(if (featurep 'xemacs) '(t)
2573               '(:help "Show previous page of article"))]
2574          ["Line forward" gnus-summary-scroll-up t])
2575         ("Move"
2576          ["Next unread article" gnus-summary-next-unread-article t]
2577          ["Previous unread article" gnus-summary-prev-unread-article t]
2578          ["Next article" gnus-summary-next-article t]
2579          ["Previous article" gnus-summary-prev-article t]
2580          ["Next unread subject" gnus-summary-next-unread-subject t]
2581          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2582          ["Next article same subject" gnus-summary-next-same-subject t]
2583          ["Previous article same subject" gnus-summary-prev-same-subject t]
2584          ["First unread article" gnus-summary-first-unread-article t]
2585          ["Best unread article" gnus-summary-best-unread-article t]
2586          ["Go to subject number..." gnus-summary-goto-subject t]
2587          ["Go to article number..." gnus-summary-goto-article t]
2588          ["Go to the last article" gnus-summary-goto-last-article t]
2589          ["Pop article off history" gnus-summary-pop-article t])
2590         ("Sort"
2591          ["Sort by number" gnus-summary-sort-by-number t]
2592          ["Sort by author" gnus-summary-sort-by-author t]
2593          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2594          ["Sort by subject" gnus-summary-sort-by-subject t]
2595          ["Sort by date" gnus-summary-sort-by-date t]
2596          ["Sort by score" gnus-summary-sort-by-score t]
2597          ["Sort by lines" gnus-summary-sort-by-lines t]
2598          ["Sort by characters" gnus-summary-sort-by-chars t]
2599          ["Randomize" gnus-summary-sort-by-random t]
2600          ["Original sort" gnus-summary-sort-by-original t])
2601         ("Help"
2602          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2603          ["Describe group" gnus-summary-describe-group t]
2604          ["Fetch charter" gnus-group-fetch-charter
2605           ,@(if (featurep 'xemacs) nil
2606               '(:help "Display the charter of the current group"))]
2607          ["Fetch control message" gnus-group-fetch-control
2608           ,@(if (featurep 'xemacs) nil
2609               '(:help "Display the archived control message for the current group"))]
2610          ["Read manual" gnus-info-find-node t])
2611         ("Modes"
2612          ["Pick and read" gnus-pick-mode t]
2613          ["Binary" gnus-binary-mode t])
2614         ("Regeneration"
2615          ["Regenerate" gnus-summary-prepare t]
2616          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2617          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2618          ["Toggle threading" gnus-summary-toggle-threads t])
2619         ["See old articles" gnus-summary-insert-old-articles t]
2620         ["See new articles" gnus-summary-insert-new-articles t]
2621         ["Filter articles..." gnus-summary-execute-command t]
2622         ["Run command on articles..." gnus-summary-universal-argument t]
2623         ["Search articles forward..." gnus-summary-search-article-forward t]
2624         ["Search articles backward..." gnus-summary-search-article-backward t]
2625         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2626         ["Expand window" gnus-summary-expand-window t]
2627         ["Expire expirable articles" gnus-summary-expire-articles
2628          (gnus-check-backend-function
2629           'request-expire-articles gnus-newsgroup-name)]
2630         ["Edit local kill file" gnus-summary-edit-local-kill t]
2631         ["Edit main kill file" gnus-summary-edit-global-kill t]
2632         ["Edit group parameters" gnus-summary-edit-parameters t]
2633         ["Customize group parameters" gnus-summary-customize-parameters t]
2634         ["Send a bug report" gnus-bug t]
2635         ("Exit"
2636          ["Catchup and exit" gnus-summary-catchup-and-exit
2637           ,@(if (featurep 'xemacs) '(t)
2638               '(:help "Mark unread articles in this group as read, then exit"))]
2639          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2640          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2641          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2642          ["Exit group" gnus-summary-exit
2643           ,@(if (featurep 'xemacs) '(t)
2644               '(:help "Exit current group, return to group selection mode"))]
2645          ["Exit group without updating" gnus-summary-exit-no-update t]
2646          ["Exit and goto next group" gnus-summary-next-group t]
2647          ["Exit and goto prev group" gnus-summary-prev-group t]
2648          ["Reselect group" gnus-summary-reselect-current-group t]
2649          ["Rescan group" gnus-summary-rescan-group t]
2650          ["Update dribble" gnus-summary-save-newsrc t])))
2651
2652     (gnus-run-hooks 'gnus-summary-menu-hook)))
2653
2654 (defvar gnus-summary-tool-bar-map nil)
2655
2656 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2657 ;; affect _new_ message buffers.  We might add a function that walks thru all
2658 ;; summary-mode buffers and force the update.
2659 (defun gnus-summary-tool-bar-update (&optional symbol value)
2660   "Update summary mode toolbar.
2661 Setter function for custom variables."
2662   (setq-default gnus-summary-tool-bar-map nil)
2663   (when symbol
2664     ;; When used as ":set" function:
2665     (set-default symbol value))
2666   (when (gnus-buffer-live-p gnus-summary-buffer)
2667     (with-current-buffer gnus-summary-buffer
2668       (gnus-summary-make-tool-bar))))
2669
2670 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2671                                      'gnus-summary-tool-bar-gnome
2672                                    'gnus-summary-tool-bar-retro)
2673   "Specifies the Gnus summary tool bar.
2674
2675 It can be either a list or a symbol refering to a list.  See
2676 `gmm-tool-bar-from-list' for the format of the list.  The
2677 default key map is `gnus-summary-mode-map'.
2678
2679 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2680 `gnus-summary-tool-bar-retro'."
2681   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2682                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2683                  (repeat :tag "User defined list" gmm-tool-bar-item)
2684                  (symbol))
2685   :version "23.0" ;; No Gnus
2686   :initialize 'custom-initialize-default
2687   :set 'gnus-summary-tool-bar-update
2688   :group 'gnus-summary)
2689
2690 (defcustom gnus-summary-tool-bar-gnome
2691   '((gnus-summary-post-news "mail/compose" nil)
2692     (gnus-summary-insert-new-articles "mail/inbox" nil
2693                                       :visible (or (not gnus-agent)
2694                                                    gnus-plugged))
2695     (gnus-summary-reply-with-original "mail/reply")
2696     (gnus-summary-reply "mail/reply" nil :visible nil)
2697     (gnus-summary-followup-with-original "mail/reply-all")
2698     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2699     (gnus-summary-mail-forward "mail/forward")
2700     (gnus-summary-save-article "mail/save")
2701     (gnus-summary-search-article-forward "search" nil :visible nil)
2702     (gnus-summary-print-article "print")
2703     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2704     ;; Some new commands that may need more suitable icons:
2705     (gnus-summary-save-newsrc "save" nil :visible nil)
2706     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2707     (gnus-summary-prev-article "left-arrow")
2708     (gnus-summary-next-article "right-arrow")
2709     (gnus-summary-next-page "next-page")
2710     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2711     ;;
2712     ;; Maybe some sort-by-... could be added:
2713     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2714     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2715     (gnus-summary-mark-as-expirable
2716      "delete" nil
2717      :visible (gnus-check-backend-function 'request-expire-articles
2718                                            gnus-newsgroup-name))
2719     (gnus-summary-mark-as-spam
2720      "mail/spam" t
2721      :visible (and (fboundp 'spam-group-ham-contents-p)
2722                    (spam-group-ham-contents-p gnus-newsgroup-name))
2723      :help "Mark as spam")
2724     (gnus-summary-mark-as-read-forward
2725      "mail/not-spam" nil
2726      :visible (and (fboundp 'spam-group-spam-contents-p)
2727                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2728     ;;
2729     (gnus-summary-exit "exit")
2730     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2731     (gnus-info-find-node "help"))
2732   "List of functions for the summary tool bar (GNOME style).
2733
2734 See `gmm-tool-bar-from-list' for the format of the list."
2735   :type '(repeat gmm-tool-bar-item)
2736   :version "23.0" ;; No Gnus
2737   :initialize 'custom-initialize-default
2738   :set 'gnus-summary-tool-bar-update
2739   :group 'gnus-summary)
2740
2741 (defcustom gnus-summary-tool-bar-retro
2742   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2743     (gnus-summary-next-unread-article "gnus/next-ur")
2744     (gnus-summary-post-news "gnus/post")
2745     (gnus-summary-followup-with-original "gnus/fuwo")
2746     (gnus-summary-followup "gnus/followup")
2747     (gnus-summary-reply-with-original "gnus/reply-wo")
2748     (gnus-summary-reply "gnus/reply")
2749     (gnus-summary-caesar-message "gnus/rot13")
2750     (gnus-uu-decode-uu "gnus/uu-decode")
2751     (gnus-summary-save-article-file "gnus/save-aif")
2752     (gnus-summary-save-article "gnus/save-art")
2753     (gnus-uu-post-news "gnus/uu-post")
2754     (gnus-summary-catchup "gnus/catchup")
2755     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2756     (gnus-summary-exit "gnus/exit-summ")
2757     ;; Some new command that may need more suitable icons:
2758     (gnus-summary-print-article "gnus/print" nil :visible nil)
2759     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2760     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2761     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2762     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2763     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2764     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2765     ;;
2766     (gnus-info-find-node "gnus/help" nil :visible nil))
2767   "List of functions for the summary tool bar (retro look).
2768
2769 See `gmm-tool-bar-from-list' for the format of the list."
2770   :type '(repeat gmm-tool-bar-item)
2771   :version "23.0" ;; No Gnus
2772   :initialize 'custom-initialize-default
2773   :set 'gnus-summary-tool-bar-update
2774   :group 'gnus-summary)
2775
2776 (defcustom gnus-summary-tool-bar-zap-list t
2777   "List of icon items from the global tool bar.
2778 These items are not displayed in the Gnus summary mode tool bar.
2779
2780 See `gmm-tool-bar-from-list' for the format of the list."
2781   :type 'gmm-tool-bar-zap-list
2782   :version "23.0" ;; No Gnus
2783   :initialize 'custom-initialize-default
2784   :set 'gnus-summary-tool-bar-update
2785   :group 'gnus-summary)
2786
2787 (defvar image-load-path)
2788
2789 (defun gnus-summary-make-tool-bar (&optional force)
2790   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2791 When FORCE, rebuild the tool bar."
2792   (when (and (not (featurep 'xemacs))
2793              (boundp 'tool-bar-mode)
2794              tool-bar-mode
2795              (or (not gnus-summary-tool-bar-map) force))
2796     (let* ((load-path
2797             (gmm-image-load-path-for-library "gnus"
2798                                              "mail/save.xpm"
2799                                              nil t))
2800            (image-load-path (cons (car load-path)
2801                                   (when (boundp 'image-load-path)
2802                                     image-load-path)))
2803            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2804                                         gnus-summary-tool-bar-zap-list
2805                                         'gnus-summary-mode-map)))
2806       (when map
2807         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2808         ;; uses it's value.
2809         (setq gnus-summary-tool-bar-map map))))
2810   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2811
2812 (defun gnus-score-set-default (var value)
2813   "A version of set that updates the GNU Emacs menu-bar."
2814   (set var value)
2815   ;; It is the message that forces the active status to be updated.
2816   (message ""))
2817
2818 (defun gnus-make-score-map (type)
2819   "Make a summary score map of type TYPE."
2820   (if t
2821       nil
2822     (let ((headers '(("author" "from" string)
2823                      ("subject" "subject" string)
2824                      ("article body" "body" string)
2825                      ("article head" "head" string)
2826                      ("xref" "xref" string)
2827                      ("extra header" "extra" string)
2828                      ("lines" "lines" number)
2829                      ("followups to author" "followup" string)))
2830           (types '((number ("less than" <)
2831                            ("greater than" >)
2832                            ("equal" =))
2833                    (string ("substring" s)
2834                            ("exact string" e)
2835                            ("fuzzy string" f)
2836                            ("regexp" r))))
2837           (perms '(("temporary" (current-time-string))
2838                    ("permanent" nil)
2839                    ("immediate" now)))
2840           header)
2841       (list
2842        (apply
2843         'nconc
2844         (list
2845          (if (eq type 'lower)
2846              "Lower score"
2847            "Increase score"))
2848         (let (outh)
2849           (while headers
2850             (setq header (car headers))
2851             (setq outh
2852                   (cons
2853                    (apply
2854                     'nconc
2855                     (list (car header))
2856                     (let ((ts (cdr (assoc (nth 2 header) types)))
2857                           outt)
2858                       (while ts
2859                         (setq outt
2860                               (cons
2861                                (apply
2862                                 'nconc
2863                                 (list (caar ts))
2864                                 (let ((ps perms)
2865                                       outp)
2866                                   (while ps
2867                                     (setq outp
2868                                           (cons
2869                                            (vector
2870                                             (caar ps)
2871                                             (list
2872                                              'gnus-summary-score-entry
2873                                              (nth 1 header)
2874                                              (if (or (string= (nth 1 header)
2875                                                               "head")
2876                                                      (string= (nth 1 header)
2877                                                               "body"))
2878                                                  ""
2879                                                (list 'gnus-summary-header
2880                                                      (nth 1 header)))
2881                                              (list 'quote (nth 1 (car ts)))
2882                                              (list 'gnus-score-delta-default
2883                                                    nil)
2884                                              (nth 1 (car ps))
2885                                              t)
2886                                             t)
2887                                            outp))
2888                                     (setq ps (cdr ps)))
2889                                   (list (nreverse outp))))
2890                                outt))
2891                         (setq ts (cdr ts)))
2892                       (list (nreverse outt))))
2893                    outh))
2894             (setq headers (cdr headers)))
2895           (list (nreverse outh))))))))
2896
2897 \f
2898
2899 (defun gnus-summary-mode (&optional group)
2900   "Major mode for reading articles.
2901
2902 All normal editing commands are switched off.
2903 \\<gnus-summary-mode-map>
2904 Each line in this buffer represents one article.  To read an
2905 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2906 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2907 respectively.
2908
2909 You can also post articles and send mail from this buffer.  To
2910 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2911 of an article, type `\\[gnus-summary-reply]'.
2912
2913 There are approx. one gazillion commands you can execute in this
2914 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2915
2916 The following commands are available:
2917
2918 \\{gnus-summary-mode-map}"
2919   (interactive)
2920   (kill-all-local-variables)
2921   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2922     (gnus-summary-make-local-variables))
2923   (gnus-summary-make-local-variables)
2924   (setq gnus-newsgroup-name group)
2925   (when (gnus-visual-p 'summary-menu 'menu)
2926     (gnus-summary-make-menu-bar)
2927     (gnus-summary-make-tool-bar))
2928   (gnus-make-thread-indent-array)
2929   (gnus-simplify-mode-line)
2930   (setq major-mode 'gnus-summary-mode)
2931   (setq mode-name "Summary")
2932   (make-local-variable 'minor-mode-alist)
2933   (use-local-map gnus-summary-mode-map)
2934   (buffer-disable-undo)
2935   (setq buffer-read-only t              ;Disable modification
2936         show-trailing-whitespace nil)
2937   (setq truncate-lines t)
2938   (setq selective-display t)
2939   (setq selective-display-ellipses t)   ;Display `...'
2940   (gnus-summary-set-display-table)
2941   (gnus-set-default-directory)
2942   (make-local-variable 'gnus-summary-line-format)
2943   (make-local-variable 'gnus-summary-line-format-spec)
2944   (make-local-variable 'gnus-summary-dummy-line-format)
2945   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2946   (make-local-variable 'gnus-summary-mark-positions)
2947   (gnus-make-local-hook 'pre-command-hook)
2948   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2949   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2950   (turn-on-gnus-mailing-list-mode)
2951   (mm-enable-multibyte)
2952   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2953   (gnus-update-summary-mark-positions))
2954
2955 (defun gnus-summary-make-local-variables ()
2956   "Make all the local summary buffer variables."
2957   (let (global)
2958     (dolist (local gnus-summary-local-variables)
2959       (if (consp local)
2960           (progn
2961             (if (eq (cdr local) 'global)
2962                 ;; Copy the global value of the variable.
2963                 (setq global (symbol-value (car local)))
2964               ;; Use the value from the list.
2965               (setq global (eval (cdr local))))
2966             (set (make-local-variable (car local)) global))
2967         ;; Simple nil-valued local variable.
2968         (set (make-local-variable local) nil)))))
2969
2970 (defun gnus-summary-clear-local-variables ()
2971   (let ((locals gnus-summary-local-variables))
2972     (while locals
2973       (if (consp (car locals))
2974           (and (symbolp (caar locals))
2975                (set (caar locals) nil))
2976         (and (symbolp (car locals))
2977              (set (car locals) nil)))
2978       (setq locals (cdr locals)))))
2979
2980 ;; Summary data functions.
2981
2982 (defmacro gnus-data-number (data)
2983   `(car ,data))
2984
2985 (defmacro gnus-data-set-number (data number)
2986   `(setcar ,data ,number))
2987
2988 (defmacro gnus-data-mark (data)
2989   `(nth 1 ,data))
2990
2991 (defmacro gnus-data-set-mark (data mark)
2992   `(setcar (nthcdr 1 ,data) ,mark))
2993
2994 (defmacro gnus-data-pos (data)
2995   `(nth 2 ,data))
2996
2997 (defmacro gnus-data-set-pos (data pos)
2998   `(setcar (nthcdr 2 ,data) ,pos))
2999
3000 (defmacro gnus-data-header (data)
3001   `(nth 3 ,data))
3002
3003 (defmacro gnus-data-set-header (data header)
3004   `(setf (nth 3 ,data) ,header))
3005
3006 (defmacro gnus-data-level (data)
3007   `(nth 4 ,data))
3008
3009 (defmacro gnus-data-unread-p (data)
3010   `(= (nth 1 ,data) gnus-unread-mark))
3011
3012 (defmacro gnus-data-read-p (data)
3013   `(/= (nth 1 ,data) gnus-unread-mark))
3014
3015 (defmacro gnus-data-pseudo-p (data)
3016   `(consp (nth 3 ,data)))
3017
3018 (defmacro gnus-data-find (number)
3019   `(assq ,number gnus-newsgroup-data))
3020
3021 (defmacro gnus-data-find-list (number &optional data)
3022   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3023      (memq (assq ,number bdata)
3024            bdata)))
3025
3026 (defmacro gnus-data-make (number mark pos header level)
3027   `(list ,number ,mark ,pos ,header ,level))
3028
3029 (defun gnus-data-enter (after-article number mark pos header level offset)
3030   (let ((data (gnus-data-find-list after-article)))
3031     (unless data
3032       (error "No such article: %d" after-article))
3033     (setcdr data (cons (gnus-data-make number mark pos header level)
3034                        (cdr data)))
3035     (setq gnus-newsgroup-data-reverse nil)
3036     (gnus-data-update-list (cddr data) offset)))
3037
3038 (defun gnus-data-enter-list (after-article list &optional offset)
3039   (when list
3040     (let ((data (and after-article (gnus-data-find-list after-article)))
3041           (ilist list))
3042       (if (not (or data
3043                    after-article))
3044           (let ((odata gnus-newsgroup-data))
3045             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3046             (when offset
3047               (gnus-data-update-list odata offset)))
3048         ;; Find the last element in the list to be spliced into the main
3049         ;; list.
3050         (setq list (last list))
3051         (if (not data)
3052             (progn
3053               (setcdr list gnus-newsgroup-data)
3054               (setq gnus-newsgroup-data ilist)
3055               (when offset
3056                 (gnus-data-update-list (cdr list) offset)))
3057           (setcdr list (cdr data))
3058           (setcdr data ilist)
3059           (when offset
3060             (gnus-data-update-list (cdr list) offset))))
3061       (setq gnus-newsgroup-data-reverse nil))))
3062
3063 (defun gnus-data-remove (article &optional offset)
3064   (let ((data gnus-newsgroup-data))
3065     (if (= (gnus-data-number (car data)) article)
3066         (progn
3067           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3068                 gnus-newsgroup-data-reverse nil)
3069           (when offset
3070             (gnus-data-update-list gnus-newsgroup-data offset)))
3071       (while (cdr data)
3072         (when (= (gnus-data-number (cadr data)) article)
3073           (setcdr data (cddr data))
3074           (when offset
3075             (gnus-data-update-list (cdr data) offset))
3076           (setq data nil
3077                 gnus-newsgroup-data-reverse nil))
3078         (setq data (cdr data))))))
3079
3080 (defmacro gnus-data-list (backward)
3081   `(if ,backward
3082        (or gnus-newsgroup-data-reverse
3083            (setq gnus-newsgroup-data-reverse
3084                  (reverse gnus-newsgroup-data)))
3085      gnus-newsgroup-data))
3086
3087 (defun gnus-data-update-list (data offset)
3088   "Add OFFSET to the POS of all data entries in DATA."
3089   (setq gnus-newsgroup-data-reverse nil)
3090   (while data
3091     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3092     (setq data (cdr data))))
3093
3094 (defun gnus-summary-article-pseudo-p (article)
3095   "Say whether this article is a pseudo article or not."
3096   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3097
3098 (defmacro gnus-summary-article-sparse-p (article)
3099   "Say whether this article is a sparse article or not."
3100   `(memq ,article gnus-newsgroup-sparse))
3101
3102 (defmacro gnus-summary-article-ancient-p (article)
3103   "Say whether this article is a sparse article or not."
3104   `(memq ,article gnus-newsgroup-ancient))
3105
3106 (defun gnus-article-parent-p (number)
3107   "Say whether this article is a parent or not."
3108   (let ((data (gnus-data-find-list number)))
3109     (and (cdr data)              ; There has to be an article after...
3110          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3111             (gnus-data-level (nth 1 data))))))
3112
3113 (defun gnus-article-children (number)
3114   "Return a list of all children to NUMBER."
3115   (let* ((data (gnus-data-find-list number))
3116          (level (gnus-data-level (car data)))
3117          children)
3118     (setq data (cdr data))
3119     (while (and data
3120                 (= (gnus-data-level (car data)) (1+ level)))
3121       (push (gnus-data-number (car data)) children)
3122       (setq data (cdr data)))
3123     children))
3124
3125 (defmacro gnus-summary-skip-intangible ()
3126   "If the current article is intangible, then jump to a different article."
3127   '(let ((to (get-text-property (point) 'gnus-intangible)))
3128      (and to (gnus-summary-goto-subject to))))
3129
3130 (defmacro gnus-summary-article-intangible-p ()
3131   "Say whether this article is intangible or not."
3132   '(get-text-property (point) 'gnus-intangible))
3133
3134 (defun gnus-article-read-p (article)
3135   "Say whether ARTICLE is read or not."
3136   (not (or (memq article gnus-newsgroup-marked)
3137            (memq article gnus-newsgroup-spam-marked)
3138            (memq article gnus-newsgroup-unreads)
3139            (memq article gnus-newsgroup-unselected)
3140            (memq article gnus-newsgroup-dormant))))
3141
3142 ;; Some summary mode macros.
3143
3144 (defmacro gnus-summary-article-number ()
3145   "The article number of the article on the current line.
3146 If there isn't an article number here, then we return the current
3147 article number."
3148   '(progn
3149      (gnus-summary-skip-intangible)
3150      (or (get-text-property (point) 'gnus-number)
3151          (gnus-summary-last-subject))))
3152
3153 (defmacro gnus-summary-article-header (&optional number)
3154   "Return the header of article NUMBER."
3155   `(gnus-data-header (gnus-data-find
3156                       ,(or number '(gnus-summary-article-number)))))
3157
3158 (defmacro gnus-summary-thread-level (&optional number)
3159   "Return the level of thread that starts with article NUMBER."
3160   `(if (and (eq gnus-summary-make-false-root 'dummy)
3161             (get-text-property (point) 'gnus-intangible))
3162        0
3163      (gnus-data-level (gnus-data-find
3164                        ,(or number '(gnus-summary-article-number))))))
3165
3166 (defmacro gnus-summary-article-mark (&optional number)
3167   "Return the mark of article NUMBER."
3168   `(gnus-data-mark (gnus-data-find
3169                     ,(or number '(gnus-summary-article-number)))))
3170
3171 (defmacro gnus-summary-article-pos (&optional number)
3172   "Return the position of the line of article NUMBER."
3173   `(gnus-data-pos (gnus-data-find
3174                    ,(or number '(gnus-summary-article-number)))))
3175
3176 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3177 (defmacro gnus-summary-article-subject (&optional number)
3178   "Return current subject string or nil if nothing."
3179   `(let ((headers
3180           ,(if number
3181                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3182              '(gnus-data-header (assq (gnus-summary-article-number)
3183                                       gnus-newsgroup-data)))))
3184      (and headers
3185           (vectorp headers)
3186           (mail-header-subject headers))))
3187
3188 (defmacro gnus-summary-article-score (&optional number)
3189   "Return current article score."
3190   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3191                   gnus-newsgroup-scored))
3192        gnus-summary-default-score 0))
3193
3194 (defun gnus-summary-article-children (&optional number)
3195   "Return a list of article numbers that are children of article NUMBER."
3196   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3197          (level (gnus-data-level (car data)))
3198          l children)
3199     (while (and (setq data (cdr data))
3200                 (> (setq l (gnus-data-level (car data))) level))
3201       (and (= (1+ level) l)
3202            (push (gnus-data-number (car data))
3203                  children)))
3204     (nreverse children)))
3205
3206 (defun gnus-summary-article-parent (&optional number)
3207   "Return the article number of the parent of article NUMBER."
3208   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3209                                     (gnus-data-list t)))
3210          (level (gnus-data-level (car data))))
3211     (if (zerop level)
3212         ()                              ; This is a root.
3213       ;; We search until we find an article with a level less than
3214       ;; this one.  That function has to be the parent.
3215       (while (and (setq data (cdr data))
3216                   (not (< (gnus-data-level (car data)) level))))
3217       (and data (gnus-data-number (car data))))))
3218
3219 (defun gnus-unread-mark-p (mark)
3220   "Say whether MARK is the unread mark."
3221   (= mark gnus-unread-mark))
3222
3223 (defun gnus-read-mark-p (mark)
3224   "Say whether MARK is one of the marks that mark as read.
3225 This is all marks except unread, ticked, dormant, and expirable."
3226   (not (or (= mark gnus-unread-mark)
3227            (= mark gnus-ticked-mark)
3228            (= mark gnus-spam-mark)
3229            (= mark gnus-dormant-mark)
3230            (= mark gnus-expirable-mark))))
3231
3232 (defmacro gnus-article-mark (number)
3233   "Return the MARK of article NUMBER.
3234 This macro should only be used when computing the mark the \"first\"
3235 time; i.e., when generating the summary lines.  After that,
3236 `gnus-summary-article-mark' should be used to examine the
3237 marks of articles."
3238   `(cond
3239     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3240     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3241     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3242     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3243     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3244     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3245     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3246     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3247            gnus-ancient-mark))))
3248
3249 ;; Saving hidden threads.
3250
3251 (defmacro gnus-save-hidden-threads (&rest forms)
3252   "Save hidden threads, eval FORMS, and restore the hidden threads."
3253   (let ((config (make-symbol "config")))
3254     `(let ((,config (gnus-hidden-threads-configuration)))
3255        (unwind-protect
3256            (save-excursion
3257              ,@forms)
3258          (gnus-restore-hidden-threads-configuration ,config)))))
3259 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3260 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3261
3262 (defun gnus-data-compute-positions ()
3263   "Compute the positions of all articles."
3264   (setq gnus-newsgroup-data-reverse nil)
3265   (let ((data gnus-newsgroup-data))
3266     (save-excursion
3267       (gnus-save-hidden-threads
3268         (gnus-summary-show-all-threads)
3269         (goto-char (point-min))
3270         (while data
3271           (while (get-text-property (point) 'gnus-intangible)
3272             (forward-line 1))
3273           (gnus-data-set-pos (car data) (+ (point) 3))
3274           (setq data (cdr data))
3275           (forward-line 1))))))
3276
3277 (defun gnus-hidden-threads-configuration ()
3278   "Return the current hidden threads configuration."
3279   (save-excursion
3280     (let (config)
3281       (goto-char (point-min))
3282       (while (search-forward "\r" nil t)
3283         (push (1- (point)) config))
3284       config)))
3285
3286 (defun gnus-restore-hidden-threads-configuration (config)
3287   "Restore hidden threads configuration from CONFIG."
3288   (save-excursion
3289     (let (point buffer-read-only)
3290       (while (setq point (pop config))
3291         (when (and (< point (point-max))
3292                    (goto-char point)
3293                    (eq (char-after) ?\n))
3294           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3295
3296 ;; Various summary mode internalish functions.
3297
3298 (defun gnus-mouse-pick-article (e)
3299   (interactive "e")
3300   (mouse-set-point e)
3301   (gnus-summary-next-page nil t))
3302
3303 (defun gnus-summary-set-display-table ()
3304   "Change the display table.
3305 Odd characters have a tendency to mess
3306 up nicely formatted displays - we make all possible glyphs
3307 display only a single character."
3308
3309   ;; We start from the standard display table, if any.
3310   (let ((table (or (copy-sequence standard-display-table)
3311                    (make-display-table)))
3312         (i 32))
3313     ;; Nix out all the control chars...
3314     (while (>= (setq i (1- i)) 0)
3315       (aset table i [??]))
3316    ;; ... but not newline and cr, of course.  (cr is necessary for the
3317     ;; selective display).
3318     (aset table ?\n nil)
3319     (aset table ?\r nil)
3320     ;; We keep TAB as well.
3321     (aset table ?\t nil)
3322     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3323     ;; Emacs 23 (unicode), that are not set already.
3324     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3325                  160
3326                256)))
3327       (while (>= (setq i (1- i)) 127)
3328         ;; Only modify if the entry is nil.
3329         (unless (aref table i)
3330           (aset table i [??]))))
3331     (setq buffer-display-table table)))
3332
3333 (defun gnus-summary-set-article-display-arrow (pos)
3334   "Update the overlay arrow to point to line at position POS."
3335   (when (and gnus-summary-display-arrow
3336              (boundp 'overlay-arrow-position)
3337              (boundp 'overlay-arrow-string))
3338     (save-excursion
3339       (goto-char pos)
3340       (beginning-of-line)
3341       (unless overlay-arrow-position
3342         (setq overlay-arrow-position (make-marker)))
3343       (setq overlay-arrow-string "=>"
3344             overlay-arrow-position (set-marker overlay-arrow-position
3345                                                (point)
3346                                                (current-buffer))))))
3347
3348 (defun gnus-summary-setup-buffer (group)
3349   "Initialize summary buffer."
3350   (let ((buffer (gnus-summary-buffer-name group))
3351         (dead-name (concat "*Dead Summary "
3352                            (gnus-group-decoded-name group) "*")))
3353     ;; If a dead summary buffer exists, we kill it.
3354     (when (gnus-buffer-live-p dead-name)
3355       (gnus-kill-buffer dead-name))
3356     (if (get-buffer buffer)
3357         (progn
3358           (set-buffer buffer)
3359           (setq gnus-summary-buffer (current-buffer))
3360           (not gnus-newsgroup-prepared))
3361       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3362       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3363       (gnus-summary-mode group)
3364       (when gnus-carpal
3365         (gnus-carpal-setup-buffer 'summary))
3366       (when (gnus-group-quit-config group)
3367         (set (make-local-variable 'gnus-single-article-buffer) nil))
3368       (make-local-variable 'gnus-article-buffer)
3369       (make-local-variable 'gnus-article-current)
3370       (make-local-variable 'gnus-original-article-buffer)
3371       (setq gnus-newsgroup-name group)
3372       ;; Set any local variables in the group parameters.
3373       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3374       t)))
3375
3376 (defun gnus-set-global-variables ()
3377   "Set the global equivalents of the buffer-local variables.
3378 They are set to the latest values they had.  These reflect the summary
3379 buffer that was in action when the last article was fetched."
3380   (when (eq major-mode 'gnus-summary-mode)
3381     (setq gnus-summary-buffer (current-buffer))
3382     (let ((name gnus-newsgroup-name)
3383           (marked gnus-newsgroup-marked)
3384           (spam gnus-newsgroup-spam-marked)
3385           (unread gnus-newsgroup-unreads)
3386           (headers gnus-current-headers)
3387           (data gnus-newsgroup-data)
3388           (summary gnus-summary-buffer)
3389           (article-buffer gnus-article-buffer)
3390           (original gnus-original-article-buffer)
3391           (gac gnus-article-current)
3392           (reffed gnus-reffed-article-number)
3393           (score-file gnus-current-score-file)
3394           (default-charset gnus-newsgroup-charset)
3395           vlist)
3396       (let ((locals gnus-newsgroup-variables))
3397         (while locals
3398           (if (consp (car locals))
3399               (push (eval (caar locals)) vlist)
3400             (push (eval (car locals)) vlist))
3401           (setq locals (cdr locals)))
3402         (setq vlist (nreverse vlist)))
3403       (with-current-buffer gnus-group-buffer
3404         (setq gnus-newsgroup-name name
3405               gnus-newsgroup-marked marked
3406               gnus-newsgroup-spam-marked spam
3407               gnus-newsgroup-unreads unread
3408               gnus-current-headers headers
3409               gnus-newsgroup-data data
3410               gnus-article-current gac
3411               gnus-summary-buffer summary
3412               gnus-article-buffer article-buffer
3413               gnus-original-article-buffer original
3414               gnus-reffed-article-number reffed
3415               gnus-current-score-file score-file
3416               gnus-newsgroup-charset default-charset)
3417         (let ((locals gnus-newsgroup-variables))
3418           (while locals
3419             (if (consp (car locals))
3420                 (set (caar locals) (pop vlist))
3421               (set (car locals) (pop vlist)))
3422             (setq locals (cdr locals))))
3423         ;; The article buffer also has local variables.
3424         (when (gnus-buffer-live-p gnus-article-buffer)
3425           (set-buffer gnus-article-buffer)
3426           (setq gnus-summary-buffer summary))))))
3427
3428 (defun gnus-summary-article-unread-p (article)
3429   "Say whether ARTICLE is unread or not."
3430   (memq article gnus-newsgroup-unreads))
3431
3432 (defun gnus-summary-first-article-p (&optional article)
3433   "Return whether ARTICLE is the first article in the buffer."
3434   (if (not (setq article (or article (gnus-summary-article-number))))
3435       nil
3436     (eq article (caar gnus-newsgroup-data))))
3437
3438 (defun gnus-summary-last-article-p (&optional article)
3439   "Return whether ARTICLE is the last article in the buffer."
3440   (if (not (setq article (or article (gnus-summary-article-number))))
3441       ;; All non-existent numbers are the last article.  :-)
3442       t
3443     (not (cdr (gnus-data-find-list article)))))
3444
3445 (defun gnus-make-thread-indent-array ()
3446   (let ((n 200))
3447     (unless (and gnus-thread-indent-array
3448                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3449       (setq gnus-thread-indent-array (make-vector 201 "")
3450             gnus-thread-indent-array-level gnus-thread-indent-level)
3451       (while (>= n 0)
3452         (aset gnus-thread-indent-array n
3453               (make-string (* n gnus-thread-indent-level) ? ))
3454         (setq n (1- n))))))
3455
3456 (defun gnus-update-summary-mark-positions ()
3457   "Compute where the summary marks are to go."
3458   (save-excursion
3459     (when (gnus-buffer-exists-p gnus-summary-buffer)
3460       (set-buffer gnus-summary-buffer))
3461     (let ((spec gnus-summary-line-format-spec)
3462           pos)
3463       (save-excursion
3464         (gnus-set-work-buffer)
3465         (let ((gnus-tmp-unread ?Z)
3466               (gnus-replied-mark ?Z)
3467               (gnus-score-below-mark ?Z)
3468               (gnus-score-over-mark ?Z)
3469               (gnus-undownloaded-mark ?Z)
3470               (gnus-summary-line-format-spec spec)
3471               (gnus-newsgroup-downloadable '(0))
3472               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3473               case-fold-search ignores)
3474           ;; Here, all marks are bound to Z.
3475           (gnus-summary-insert-line header
3476                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3477           (goto-char (point-min))
3478           ;; Memorize the positions of the same characters as dummy marks.
3479           (while (re-search-forward "[A-D]" nil t)
3480             (push (point) ignores))
3481           (erase-buffer)
3482           ;; We use A-D as dummy marks in order to know column positions
3483           ;; where marks should be inserted.
3484           (setq gnus-tmp-unread ?A
3485                 gnus-replied-mark ?B
3486                 gnus-score-below-mark ?C
3487                 gnus-score-over-mark ?C
3488                 gnus-undownloaded-mark ?D)
3489           (gnus-summary-insert-line header
3490                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3491           ;; Ignore characters which aren't dummy marks.
3492           (dolist (p ignores)
3493             (delete-region (goto-char (1- p)) p)
3494             (insert ?Z))
3495           (goto-char (point-min))
3496           (setq pos (list (cons 'unread
3497                                 (and (search-forward "A" nil t)
3498                                      (- (point) (point-min) 1)))))
3499           (goto-char (point-min))
3500           (push (cons 'replied (and (search-forward "B" nil t)
3501                                     (- (point) (point-min) 1)))
3502                 pos)
3503           (goto-char (point-min))
3504           (push (cons 'score (and (search-forward "C" nil t)
3505                                   (- (point) (point-min) 1)))
3506                 pos)
3507           (goto-char (point-min))
3508           (push (cons 'download (and (search-forward "D" nil t)
3509                                      (- (point) (point-min) 1)))
3510                 pos)))
3511       (setq gnus-summary-mark-positions pos))))
3512
3513 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3514   "Insert a dummy root in the summary buffer."
3515   (beginning-of-line)
3516   (gnus-add-text-properties
3517    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3518    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3519
3520 (defun gnus-summary-extract-address-component (from)
3521   (or (car (funcall gnus-extract-address-components from))
3522       from))
3523
3524 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3525   (let ((mail-parse-charset gnus-newsgroup-charset)
3526         ; Is it really necessary to do this next part for each summary line?
3527         ; Luckily, doesn't seem to slow things down much.
3528         (mail-parse-ignored-charsets
3529          (with-current-buffer gnus-summary-buffer
3530            gnus-newsgroup-ignored-charsets)))
3531     (or
3532      (and gnus-ignored-from-addresses
3533           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3534           (let ((extra-headers (mail-header-extra header))
3535                 to
3536                 newsgroups)
3537             (cond
3538              ((setq to (cdr (assq 'To extra-headers)))
3539               (concat gnus-summary-to-prefix
3540                       (inline
3541                         (gnus-summary-extract-address-component
3542                          (funcall gnus-decode-encoded-address-function to)))))
3543              ((setq newsgroups
3544                     (or
3545                      (cdr (assq 'Newsgroups extra-headers))
3546                      (and
3547                       (memq 'Newsgroups gnus-extra-headers)
3548                       (eq (car (gnus-find-method-for-group
3549                                 gnus-newsgroup-name)) 'nntp)
3550                       (gnus-group-real-name gnus-newsgroup-name))))
3551               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3552      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3553
3554 (defun gnus-summary-insert-line (gnus-tmp-header
3555                                  gnus-tmp-level gnus-tmp-current
3556                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3557                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3558                                  &optional gnus-tmp-dummy gnus-tmp-score
3559                                  gnus-tmp-process)
3560   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3561          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3562          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3563          (gnus-tmp-score-char
3564           (if (or (null gnus-summary-default-score)
3565                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3566                       gnus-summary-zcore-fuzz))
3567               ?                         ;Whitespace
3568             (if (< gnus-tmp-score gnus-summary-default-score)
3569                 gnus-score-below-mark gnus-score-over-mark)))
3570          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3571          (gnus-tmp-replied
3572           (cond (gnus-tmp-process gnus-process-mark)
3573                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3574                  gnus-cached-mark)
3575                 (gnus-tmp-replied gnus-replied-mark)
3576                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3577                  gnus-forwarded-mark)
3578                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3579                  gnus-saved-mark)
3580                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3581                  gnus-recent-mark)
3582                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3583                  gnus-unseen-mark)
3584                 (t gnus-no-mark)))
3585          (gnus-tmp-downloaded
3586           (cond (undownloaded
3587                  gnus-undownloaded-mark)
3588                 (gnus-newsgroup-agentized
3589                  gnus-downloaded-mark)
3590                 (t
3591                  gnus-no-mark)))
3592          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3593          (gnus-tmp-name
3594           (cond
3595            ((string-match "<[^>]+> *$" gnus-tmp-from)
3596             (let ((beg (match-beginning 0)))
3597               (or (and (string-match "^\".+\"" gnus-tmp-from)
3598                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3599                   (substring gnus-tmp-from 0 beg))))
3600            ((string-match "(.+)" gnus-tmp-from)
3601             (substring gnus-tmp-from
3602                        (1+ (match-beginning 0)) (1- (match-end 0))))
3603            (t gnus-tmp-from)))
3604          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3605          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3606          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3607          (buffer-read-only nil))
3608     (when (string= gnus-tmp-name "")
3609       (setq gnus-tmp-name gnus-tmp-from))
3610     (unless (numberp gnus-tmp-lines)
3611       (setq gnus-tmp-lines -1))
3612     (if (= gnus-tmp-lines -1)
3613         (setq gnus-tmp-lines "?")
3614       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3615       (gnus-put-text-property
3616      (point)
3617      (progn (eval gnus-summary-line-format-spec) (point))
3618        'gnus-number gnus-tmp-number)
3619     (when (gnus-visual-p 'summary-highlight 'highlight)
3620       (forward-line -1)
3621       (gnus-run-hooks 'gnus-summary-update-hook)
3622       (forward-line 1))))
3623
3624 (defun gnus-summary-update-line (&optional dont-update)
3625   "Update summary line after change."
3626   (when (and gnus-summary-default-score
3627              (not gnus-summary-inhibit-highlight))
3628     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3629            (article (gnus-summary-article-number))
3630            (score (gnus-summary-article-score article)))
3631       (unless dont-update
3632         (if (and gnus-summary-mark-below
3633                  (< (gnus-summary-article-score)
3634                     gnus-summary-mark-below))
3635             ;; This article has a low score, so we mark it as read.
3636             (when (memq article gnus-newsgroup-unreads)
3637               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3638           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3639             ;; This article was previously marked as read on account
3640             ;; of a low score, but now it has risen, so we mark it as
3641             ;; unread.
3642             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3643         (gnus-summary-update-mark
3644          (if (or (null gnus-summary-default-score)
3645                  (<= (abs (- score gnus-summary-default-score))
3646                      gnus-summary-zcore-fuzz))
3647              ?                          ;Whitespace
3648            (if (< score gnus-summary-default-score)
3649                gnus-score-below-mark gnus-score-over-mark))
3650          'score))
3651       ;; Do visual highlighting.
3652       (when (gnus-visual-p 'summary-highlight 'highlight)
3653         (gnus-run-hooks 'gnus-summary-update-hook)))))
3654
3655 (defvar gnus-tmp-new-adopts nil)
3656
3657 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3658   "Return the number of articles in THREAD.
3659 This may be 0 in some cases -- if none of the articles in
3660 the thread are to be displayed."
3661   (let* ((number
3662          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3663           (cond
3664            ((not (listp thread))
3665             1)
3666            ((and (consp thread) (cdr thread))
3667             (apply
3668              '+ 1 (mapcar
3669                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3670            ((null thread)
3671             1)
3672            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3673             1)
3674            (t 0))))
3675     (when (and level (zerop level) gnus-tmp-new-adopts)
3676       (incf number
3677             (apply '+ (mapcar
3678                        'gnus-summary-number-of-articles-in-thread
3679                        gnus-tmp-new-adopts))))
3680     (if char
3681         (if (> number 1) gnus-not-empty-thread-mark
3682           gnus-empty-thread-mark)
3683       number)))
3684
3685 (defsubst gnus-summary-line-message-size (head)
3686   "Return pretty-printed version of message size.
3687 This function is intended to be used in
3688 `gnus-summary-line-format-alist'."
3689   (let ((c (or (mail-header-chars head) -1)))
3690     (cond ((< c 0) "n/a")               ; chars not available
3691           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3692           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3693           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3694           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3695
3696
3697 (defun gnus-summary-set-local-parameters (group)
3698   "Go through the local params of GROUP and set all variable specs in that list."
3699   (let ((vars '(quit-config)))          ; Ignore quit-config.
3700     (dolist (elem (gnus-group-find-parameter group))
3701       (and (consp elem)                 ; Has to be a cons.
3702            (consp (cdr elem))           ; The cdr has to be a list.
3703            (symbolp (car elem))         ; Has to be a symbol in there.
3704            (not (memq (car elem) vars))
3705            (ignore-errors               ; So we set it.
3706              (push (car elem) vars)
3707              (make-local-variable (car elem))
3708              (set (car elem) (eval (nth 1 elem))))))))
3709
3710 (defun gnus-summary-read-group (group &optional show-all no-article
3711                                       kill-buffer no-display backward
3712                                       select-articles)
3713   "Start reading news in newsgroup GROUP.
3714 If SHOW-ALL is non-nil, already read articles are also listed.
3715 If NO-ARTICLE is non-nil, no article is selected initially.
3716 If NO-DISPLAY, don't generate a summary buffer."
3717   (let (result)
3718     (while (and group
3719                 (null (setq result
3720                             (let ((gnus-auto-select-next nil))
3721                               (or (gnus-summary-read-group-1
3722                                    group show-all no-article
3723                                    kill-buffer no-display
3724                                    select-articles)
3725                                   (setq show-all nil
3726                                         select-articles nil)))))
3727                 (eq gnus-auto-select-next 'quietly))
3728       (set-buffer gnus-group-buffer)
3729       ;; The entry function called above goes to the next
3730       ;; group automatically, so we go two groups back
3731       ;; if we are searching for the previous group.
3732       (when backward
3733         (gnus-group-prev-unread-group 2))
3734       (if (not (equal group (gnus-group-group-name)))
3735           (setq group (gnus-group-group-name))
3736         (setq group nil)))
3737     result))
3738
3739 (defun gnus-summary-read-group-1 (group show-all no-article
3740                                         kill-buffer no-display
3741                                         &optional select-articles)
3742   ;; Killed foreign groups can't be entered.
3743   ;;  (when (and (not (gnus-group-native-p group))
3744   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3745   ;;    (error "Dead non-native groups can't be entered"))
3746   (gnus-message 5 "Retrieving newsgroup: %s..."
3747                 (gnus-group-decoded-name group))
3748   (let* ((new-group (gnus-summary-setup-buffer group))
3749          (quit-config (gnus-group-quit-config group))
3750          (did-select (and new-group (gnus-select-newsgroup
3751                                      group show-all select-articles))))
3752     (cond
3753      ;; This summary buffer exists already, so we just select it.
3754      ((not new-group)
3755       (gnus-set-global-variables)
3756       (when kill-buffer
3757         (gnus-kill-or-deaden-summary kill-buffer))
3758       (gnus-configure-windows 'summary 'force)
3759       (gnus-set-mode-line 'summary)
3760       (gnus-summary-position-point)
3761       (message "")
3762       t)
3763      ;; We couldn't select this group.
3764      ((null did-select)
3765       (when (and (eq major-mode 'gnus-summary-mode)
3766                  (not (equal (current-buffer) kill-buffer)))
3767         (kill-buffer (current-buffer))
3768         (if (not quit-config)
3769             (progn
3770               ;; Update the info -- marks might need to be removed,
3771               ;; for instance.
3772               (gnus-summary-update-info)
3773               (set-buffer gnus-group-buffer)
3774               (gnus-group-jump-to-group group)
3775               (gnus-group-next-unread-group 1))
3776           (gnus-handle-ephemeral-exit quit-config)))
3777       (let ((grpinfo (gnus-get-info group)))
3778         (if (null (gnus-info-read grpinfo))
3779             (gnus-message 3 "Group %s contains no messages"
3780                           (gnus-group-decoded-name group))
3781           (gnus-message 3 "Can't select group")))
3782       nil)
3783      ;; The user did a `C-g' while prompting for number of articles,
3784      ;; so we exit this group.
3785      ((eq did-select 'quit)
3786       (and (eq major-mode 'gnus-summary-mode)
3787            (not (equal (current-buffer) kill-buffer))
3788            (kill-buffer (current-buffer)))
3789       (when kill-buffer
3790         (gnus-kill-or-deaden-summary kill-buffer))
3791       (if (not quit-config)
3792           (progn
3793             (set-buffer gnus-group-buffer)
3794             (gnus-group-jump-to-group group)
3795             (gnus-group-next-unread-group 1)
3796             (gnus-configure-windows 'group 'force))
3797         (gnus-handle-ephemeral-exit quit-config))
3798       ;; Finally signal the quit.
3799       (signal 'quit nil))
3800      ;; The group was successfully selected.
3801      (t
3802       (gnus-set-global-variables)
3803       ;; Save the active value in effect when the group was entered.
3804       (setq gnus-newsgroup-active
3805             (gnus-copy-sequence
3806              (gnus-active gnus-newsgroup-name)))
3807       ;; You can change the summary buffer in some way with this hook.
3808       (gnus-run-hooks 'gnus-select-group-hook)
3809       (when (memq 'summary (gnus-update-format-specifications
3810                             nil 'summary 'summary-mode 'summary-dummy))
3811         ;; The format specification for the summary line was updated,
3812         ;; so we need to update the mark positions as well.
3813         (gnus-update-summary-mark-positions))
3814       ;; Do score processing.
3815       (when gnus-use-scoring
3816         (gnus-possibly-score-headers))
3817       ;; Check whether to fill in the gaps in the threads.
3818       (when gnus-build-sparse-threads
3819         (gnus-build-sparse-threads))
3820       ;; Find the initial limit.
3821       (if show-all
3822           (let ((gnus-newsgroup-dormant nil))
3823             (gnus-summary-initial-limit show-all))
3824         (gnus-summary-initial-limit show-all))
3825       ;; Generate the summary buffer.
3826       (unless no-display
3827         (gnus-summary-prepare))
3828       (when gnus-use-trees
3829         (gnus-tree-open group)
3830         (setq gnus-summary-highlight-line-function
3831               'gnus-tree-highlight-article))
3832       ;; If the summary buffer is empty, but there are some low-scored
3833       ;; articles or some excluded dormants, we include these in the
3834       ;; buffer.
3835       (when (and (zerop (buffer-size))
3836                  (not no-display))
3837         (cond (gnus-newsgroup-dormant
3838                (gnus-summary-limit-include-dormant))
3839               ((and gnus-newsgroup-scored show-all)
3840                (gnus-summary-limit-include-expunged t))))
3841       ;; Function `gnus-apply-kill-file' must be called in this hook.
3842       (gnus-run-hooks 'gnus-apply-kill-hook)
3843       (if (and (zerop (buffer-size))
3844                (not no-display))
3845           (progn
3846             ;; This newsgroup is empty.
3847             (gnus-summary-catchup-and-exit nil t)
3848             (gnus-message 6 "No unread news")
3849             (when kill-buffer
3850               (gnus-kill-or-deaden-summary kill-buffer))
3851             ;; Return nil from this function.
3852             nil)
3853         ;; Hide conversation thread subtrees.  We cannot do this in
3854         ;; gnus-summary-prepare-hook since kill processing may not
3855         ;; work with hidden articles.
3856         (gnus-summary-maybe-hide-threads)
3857         (when kill-buffer
3858           (gnus-kill-or-deaden-summary kill-buffer))
3859         (gnus-summary-auto-select-subject)
3860         ;; Show first unread article if requested.
3861         (if (and (not no-article)
3862                  (not no-display)
3863                  gnus-newsgroup-unreads
3864                  gnus-auto-select-first)
3865             (progn
3866               (gnus-configure-windows 'summary)
3867               (let ((art (gnus-summary-article-number)))
3868                 (unless (and (not gnus-plugged)
3869                              (or (memq art gnus-newsgroup-undownloaded)
3870                                  (memq art gnus-newsgroup-downloadable)))
3871                   (gnus-summary-goto-article art))))
3872           ;; Don't select any articles.
3873           (gnus-summary-position-point)
3874           (gnus-configure-windows 'summary 'force)
3875           (gnus-set-mode-line 'summary))
3876         (when (and gnus-auto-center-group
3877                    (get-buffer-window gnus-group-buffer t))
3878           ;; Gotta use windows, because recenter does weird stuff if
3879           ;; the current buffer ain't the displayed window.
3880           (let ((owin (selected-window)))
3881             (select-window (get-buffer-window gnus-group-buffer t))
3882             (when (gnus-group-goto-group group)
3883               (recenter))
3884             (select-window owin)))
3885         ;; Mark this buffer as "prepared".
3886         (setq gnus-newsgroup-prepared t)
3887         (gnus-run-hooks 'gnus-summary-prepared-hook)
3888         (unless (gnus-ephemeral-group-p group)
3889           (gnus-group-update-group group))
3890         t)))))
3891
3892 (defun gnus-summary-auto-select-subject ()
3893   "Select the subject line on initial group entry."
3894   (goto-char (point-min))
3895   (cond
3896    ((eq gnus-auto-select-subject 'best)
3897     (gnus-summary-best-unread-subject))
3898    ((eq gnus-auto-select-subject 'unread)
3899     (gnus-summary-first-unread-subject))
3900    ((eq gnus-auto-select-subject 'unseen)
3901     (gnus-summary-first-unseen-subject))
3902    ((eq gnus-auto-select-subject 'unseen-or-unread)
3903     (gnus-summary-first-unseen-or-unread-subject))
3904    ((eq gnus-auto-select-subject 'first)
3905     ;; Do nothing.
3906     )
3907    ((functionp gnus-auto-select-subject)
3908     (funcall gnus-auto-select-subject))))
3909
3910 (defun gnus-summary-prepare ()
3911   "Generate the summary buffer."
3912   (interactive)
3913   (let ((buffer-read-only nil))
3914     (erase-buffer)
3915     (setq gnus-newsgroup-data nil
3916           gnus-newsgroup-data-reverse nil)
3917     (gnus-run-hooks 'gnus-summary-generate-hook)
3918     ;; Generate the buffer, either with threads or without.
3919     (when gnus-newsgroup-headers
3920       (gnus-summary-prepare-threads
3921        (if gnus-show-threads
3922            (gnus-sort-gathered-threads
3923             (funcall gnus-summary-thread-gathering-function
3924                      (gnus-sort-threads
3925                       (gnus-cut-threads (gnus-make-threads)))))
3926          ;; Unthreaded display.
3927          (gnus-sort-articles gnus-newsgroup-headers))))
3928     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3929     ;; Call hooks for modifying summary buffer.
3930     (goto-char (point-min))
3931     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3932
3933 (defsubst gnus-general-simplify-subject (subject)
3934   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3935   (setq subject
3936         (cond
3937          ;; Truncate the subject.
3938          (gnus-simplify-subject-functions
3939           (gnus-map-function gnus-simplify-subject-functions subject))
3940          ((numberp gnus-summary-gather-subject-limit)
3941           (setq subject (gnus-simplify-subject-re subject))
3942           (if (> (length subject) gnus-summary-gather-subject-limit)
3943               (substring subject 0 gnus-summary-gather-subject-limit)
3944             subject))
3945          ;; Fuzzily simplify it.
3946          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3947           (gnus-simplify-subject-fuzzy subject))
3948          ;; Just remove the leading "Re:".
3949          (t
3950           (gnus-simplify-subject-re subject))))
3951
3952   (if (and gnus-summary-gather-exclude-subject
3953            (string-match gnus-summary-gather-exclude-subject subject))
3954       nil                         ; This article shouldn't be gathered
3955     subject))
3956
3957 (defun gnus-summary-simplify-subject-query ()
3958   "Query where the respool algorithm would put this article."
3959   (interactive)
3960   (gnus-summary-select-article)
3961   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3962
3963 (defun gnus-gather-threads-by-subject (threads)
3964   "Gather threads by looking at Subject headers."
3965   (if (not gnus-summary-make-false-root)
3966       threads
3967     (let ((hashtb (gnus-make-hashtable 1024))
3968           (prev threads)
3969           (result threads)
3970           subject hthread whole-subject)
3971       (while threads
3972         (setq subject (gnus-general-simplify-subject
3973                        (setq whole-subject (mail-header-subject
3974                                             (caar threads)))))
3975         (when subject
3976           (if (setq hthread (gnus-gethash subject hashtb))
3977               (progn
3978                 ;; We enter a dummy root into the thread, if we
3979                 ;; haven't done that already.
3980                 (unless (stringp (caar hthread))
3981                   (setcar hthread (list whole-subject (car hthread))))
3982                 ;; We add this new gathered thread to this gathered
3983                 ;; thread.
3984                 (setcdr (car hthread)
3985                         (nconc (cdar hthread) (list (car threads))))
3986                 ;; Remove it from the list of threads.
3987                 (setcdr prev (cdr threads))
3988                 (setq threads prev))
3989             ;; Enter this thread into the hash table.
3990             (gnus-sethash subject
3991                           (if gnus-summary-make-false-root-always
3992                               (progn
3993                                 ;; If you want a dummy root above all
3994                                 ;; threads...
3995                                 (setcar threads (list whole-subject
3996                                                       (car threads)))
3997                                 threads)
3998                             threads)
3999                           hashtb)))
4000         (setq prev threads)
4001         (setq threads (cdr threads)))
4002       result)))
4003
4004 (defun gnus-gather-threads-by-references (threads)
4005   "Gather threads by looking at References headers."
4006   (let ((idhashtb (gnus-make-hashtable 1024))
4007         (thhashtb (gnus-make-hashtable 1024))
4008         (prev threads)
4009         (result threads)
4010         ids references id gthread gid entered ref)
4011     (while threads
4012       (when (setq references (mail-header-references (caar threads)))
4013         (setq id (mail-header-id (caar threads))
4014               ids (inline (gnus-split-references references))
4015               entered nil)
4016         (while (setq ref (pop ids))
4017           (setq ids (delete ref ids))
4018           (if (not (setq gid (gnus-gethash ref idhashtb)))
4019               (progn
4020                 (gnus-sethash ref id idhashtb)
4021                 (gnus-sethash id threads thhashtb))
4022             (setq gthread (gnus-gethash gid thhashtb))
4023             (unless entered
4024               ;; We enter a dummy root into the thread, if we
4025               ;; haven't done that already.
4026               (unless (stringp (caar gthread))
4027                 (setcar gthread (list (mail-header-subject (caar gthread))
4028                                       (car gthread))))
4029               ;; We add this new gathered thread to this gathered
4030               ;; thread.
4031               (setcdr (car gthread)
4032                       (nconc (cdar gthread) (list (car threads)))))
4033             ;; Add it into the thread hash table.
4034             (gnus-sethash id gthread thhashtb)
4035             (setq entered t)
4036             ;; Remove it from the list of threads.
4037             (setcdr prev (cdr threads))
4038             (setq threads prev))))
4039       (setq prev threads)
4040       (setq threads (cdr threads)))
4041     result))
4042
4043 (defun gnus-sort-gathered-threads (threads)
4044   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4045   (let ((result threads))
4046     (while threads
4047       (when (stringp (caar threads))
4048         (setcdr (car threads)
4049                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4050       (setq threads (cdr threads)))
4051     result))
4052
4053 (defun gnus-thread-loop-p (root thread)
4054   "Say whether ROOT is in THREAD."
4055   (let ((stack (list thread))
4056         (infloop 0)
4057         th)
4058     (while (setq thread (pop stack))
4059       (setq th (cdr thread))
4060       (while (and th
4061                   (not (eq (caar th) root)))
4062         (pop th))
4063       (if th
4064           ;; We have found a loop.
4065           (let (ref-dep)
4066             (setcdr thread (delq (car th) (cdr thread)))
4067             (if (boundp (setq ref-dep (intern "none"
4068                                               gnus-newsgroup-dependencies)))
4069                 (setcdr (symbol-value ref-dep)
4070                         (nconc (cdr (symbol-value ref-dep))
4071                                (list (car th))))
4072               (set ref-dep (list nil (car th))))
4073             (setq infloop 1
4074                   stack nil))
4075         ;; Push all the subthreads onto the stack.
4076         (push (cdr thread) stack)))
4077     infloop))
4078
4079 (defun gnus-make-threads ()
4080   "Go through the dependency hashtb and find the roots.  Return all threads."
4081   (let (threads)
4082     (while (catch 'infloop
4083              (mapatoms
4084               (lambda (refs)
4085                 ;; Deal with self-referencing References loops.
4086                 (when (and (car (symbol-value refs))
4087                            (not (zerop
4088                                  (apply
4089                                   '+
4090                                   (mapcar
4091                                    (lambda (thread)
4092                                      (gnus-thread-loop-p
4093                                       (car (symbol-value refs)) thread))
4094                                    (cdr (symbol-value refs)))))))
4095                   (setq threads nil)
4096                   (throw 'infloop t))
4097                 (unless (car (symbol-value refs))
4098                   ;; These threads do not refer back to any other
4099                   ;; articles, so they're roots.
4100                   (setq threads (append (cdr (symbol-value refs)) threads))))
4101               gnus-newsgroup-dependencies)))
4102     threads))
4103
4104 ;; Build the thread tree.
4105 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4106   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4107
4108 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4109 if it was already present.
4110
4111 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4112 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4113 Message-IDs will be renamed to a unique Message-ID before being
4114 entered.
4115
4116 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4117   (let* ((id (mail-header-id header))
4118          (id-dep (and id (intern id dependencies)))
4119          parent-id ref ref-dep ref-header replaced)
4120     ;; Enter this `header' in the `dependencies' table.
4121     (cond
4122      ((not id-dep)
4123       (setq header nil))
4124      ;; The first two cases do the normal part: enter a new `header'
4125      ;; in the `dependencies' table.
4126      ((not (boundp id-dep))
4127       (set id-dep (list header)))
4128      ((null (car (symbol-value id-dep)))
4129       (setcar (symbol-value id-dep) header))
4130
4131      ;; From here the `header' was already present in the
4132      ;; `dependencies' table.
4133      (force-new
4134       ;; Overrides an existing entry;
4135       ;; just set the header part of the entry.
4136       (setcar (symbol-value id-dep) header)
4137       (setq replaced t))
4138
4139      ;; Renames the existing `header' to a unique Message-ID.
4140      ((not gnus-summary-ignore-duplicates)
4141       ;; An article with this Message-ID has already been seen.
4142       ;; We rename the Message-ID.
4143       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4144            (list header))
4145       (mail-header-set-id header id))
4146
4147      ;; The last case ignores an existing entry, except it adds any
4148      ;; additional Xrefs (in case the two articles came from different
4149      ;; servers.
4150      ;; Also sets `header' to `nil' meaning that the `dependencies'
4151      ;; table was *not* modified.
4152      (t
4153       (mail-header-set-xref
4154        (car (symbol-value id-dep))
4155        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4156                    "")
4157                (or (mail-header-xref header) "")))
4158       (setq header nil)))
4159
4160     (when (and header (not replaced))
4161       ;; First check that we are not creating a References loop.
4162       (setq parent-id (gnus-parent-id (mail-header-references header)))
4163       (setq ref parent-id)
4164       (while (and ref
4165                   (setq ref-dep (intern-soft ref dependencies))
4166                   (boundp ref-dep)
4167                   (setq ref-header (car (symbol-value ref-dep))))
4168         (if (string= id ref)
4169             ;; Yuk!  This is a reference loop.  Make the article be a
4170             ;; root article.
4171             (progn
4172               (mail-header-set-references (car (symbol-value id-dep)) "none")
4173               (setq ref nil)
4174               (setq parent-id nil))
4175           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4176       (setq ref-dep (intern (or parent-id "none") dependencies))
4177       (if (boundp ref-dep)
4178           (setcdr (symbol-value ref-dep)
4179                   (nconc (cdr (symbol-value ref-dep))
4180                          (list (symbol-value id-dep))))
4181         (set ref-dep (list nil (symbol-value id-dep)))))
4182     header))
4183
4184 (defun gnus-extract-message-id-from-in-reply-to (string)
4185   (if (string-match "<[^>]+>" string)
4186       (substring string (match-beginning 0) (match-end 0))
4187     nil))
4188
4189 (defun gnus-build-sparse-threads ()
4190   (let ((headers gnus-newsgroup-headers)
4191         (mail-parse-charset gnus-newsgroup-charset)
4192         (gnus-summary-ignore-duplicates t)
4193         header references generation relations
4194         subject child end new-child date)
4195     ;; First we create an alist of generations/relations, where
4196     ;; generations is how much we trust the relation, and the relation
4197     ;; is parent/child.
4198     (gnus-message 7 "Making sparse threads...")
4199     (save-excursion
4200       (nnheader-set-temp-buffer " *gnus sparse threads*")
4201       (while (setq header (pop headers))
4202         (when (and (setq references (mail-header-references header))
4203                    (not (string= references "")))
4204           (insert references)
4205           (setq child (mail-header-id header)
4206                 subject (mail-header-subject header)
4207                 date (mail-header-date header)
4208                 generation 0)
4209           (while (search-backward ">" nil t)
4210             (setq end (1+ (point)))
4211             (when (search-backward "<" nil t)
4212               (setq new-child (buffer-substring (point) end))
4213               (push (list (incf generation)
4214                           child (setq child new-child)
4215                           subject date)
4216                     relations)))
4217           (when child
4218             (push (list (1+ generation) child nil subject) relations))
4219           (erase-buffer)))
4220       (kill-buffer (current-buffer)))
4221     ;; Sort over trustworthiness.
4222     (mapcar
4223      (lambda (relation)
4224        (when (gnus-dependencies-add-header
4225               (make-full-mail-header
4226                gnus-reffed-article-number
4227                (nth 3 relation) "" (or (nth 4 relation) "")
4228                (nth 1 relation)
4229                (or (nth 2 relation) "") 0 0 "")
4230               gnus-newsgroup-dependencies nil)
4231          (push gnus-reffed-article-number gnus-newsgroup-limit)
4232          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4233          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4234                gnus-newsgroup-reads)
4235          (decf gnus-reffed-article-number)))
4236      (sort relations 'car-less-than-car))
4237     (gnus-message 7 "Making sparse threads...done")))
4238
4239 (defun gnus-build-old-threads ()
4240   ;; Look at all the articles that refer back to old articles, and
4241   ;; fetch the headers for the articles that aren't there.  This will
4242   ;; build complete threads - if the roots haven't been expired by the
4243   ;; server, that is.
4244   (let ((mail-parse-charset gnus-newsgroup-charset)
4245         id heads)
4246     (mapatoms
4247      (lambda (refs)
4248        (when (not (car (symbol-value refs)))
4249          (setq heads (cdr (symbol-value refs)))
4250          (while heads
4251            (if (memq (mail-header-number (caar heads))
4252                      gnus-newsgroup-dormant)
4253                (setq heads (cdr heads))
4254              (setq id (symbol-name refs))
4255              (while (and (setq id (gnus-build-get-header id))
4256                          (not (car (gnus-id-to-thread id)))))
4257              (setq heads nil)))))
4258      gnus-newsgroup-dependencies)))
4259
4260 (defsubst gnus-remove-odd-characters (string)
4261   "Translate STRING into something that doesn't contain weird characters."
4262   (mm-subst-char-in-string
4263    ?\r ?\-
4264    (mm-subst-char-in-string ?\n ?\- string t) t))
4265
4266 ;; This function has to be called with point after the article number
4267 ;; on the beginning of the line.
4268 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4269   (let ((eol (point-at-eol))
4270         (buffer (current-buffer))
4271         header references in-reply-to)
4272
4273     ;; overview: [num subject from date id refs chars lines misc]
4274     (unwind-protect
4275         (let (x)
4276           (narrow-to-region (point) eol)
4277           (unless (eobp)
4278             (forward-char))
4279
4280           (setq header
4281                 (make-full-mail-header
4282                  number                 ; number
4283                  (condition-case ()     ; subject
4284                      (gnus-remove-odd-characters
4285                       (funcall gnus-decode-encoded-word-function
4286                                (setq x (nnheader-nov-field))))
4287                    (error x))
4288                  (condition-case ()     ; from
4289                      (gnus-remove-odd-characters
4290                       (funcall gnus-decode-encoded-address-function
4291                                (setq x (nnheader-nov-field))))
4292                    (error x))
4293                  (nnheader-nov-field)   ; date
4294                  (nnheader-nov-read-message-id number)  ; id
4295                  (setq references (nnheader-nov-field)) ; refs
4296                  (nnheader-nov-read-integer) ; chars
4297                  (nnheader-nov-read-integer) ; lines
4298                  (unless (eobp)
4299                    (if (looking-at "Xref: ")
4300                        (goto-char (match-end 0)))
4301                    (nnheader-nov-field)) ; Xref
4302                  (nnheader-nov-parse-extra)))) ; extra
4303
4304       (widen))
4305
4306     (when (and (string= references "")
4307                (setq in-reply-to (mail-header-extra header))
4308                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4309       (mail-header-set-references
4310        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4311
4312     (when gnus-alter-header-function
4313       (funcall gnus-alter-header-function header))
4314     (gnus-dependencies-add-header header dependencies force-new)))
4315
4316 (defun gnus-build-get-header (id)
4317   "Look through the buffer of NOV lines and find the header to ID.
4318 Enter this line into the dependencies hash table, and return
4319 the id of the parent article (if any)."
4320   (let ((deps gnus-newsgroup-dependencies)
4321         found header)
4322     (prog1
4323         (save-excursion
4324           (set-buffer nntp-server-buffer)
4325           (let ((case-fold-search nil))
4326             (goto-char (point-min))
4327             (while (and (not found)
4328                         (search-forward id nil t))
4329               (beginning-of-line)
4330               (setq found (looking-at
4331                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4332                                    (regexp-quote id))))
4333               (or found (beginning-of-line 2)))
4334             (when found
4335               (beginning-of-line)
4336               (and
4337                (setq header (gnus-nov-parse-line
4338                              (read (current-buffer)) deps))
4339                (gnus-parent-id (mail-header-references header))))))
4340       (when header
4341         (let ((number (mail-header-number header)))
4342           (push number gnus-newsgroup-limit)
4343           (push header gnus-newsgroup-headers)
4344           (if (memq number gnus-newsgroup-unselected)
4345               (progn
4346                 (setq gnus-newsgroup-unreads
4347                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4348                                                number))
4349                 (setq gnus-newsgroup-unselected
4350                       (delq number gnus-newsgroup-unselected)))
4351             (push number gnus-newsgroup-ancient)))))))
4352
4353 (defun gnus-build-all-threads ()
4354   "Read all the headers."
4355   (let ((gnus-summary-ignore-duplicates t)
4356         (mail-parse-charset gnus-newsgroup-charset)
4357         (dependencies gnus-newsgroup-dependencies)
4358         header article)
4359     (save-excursion
4360       (set-buffer nntp-server-buffer)
4361       (let ((case-fold-search nil))
4362         (goto-char (point-min))
4363         (while (not (eobp))
4364           (ignore-errors
4365             (setq article (read (current-buffer))
4366                   header (gnus-nov-parse-line article dependencies)))
4367           (when header
4368             (with-current-buffer gnus-summary-buffer
4369               (push header gnus-newsgroup-headers)
4370               (if (memq (setq article (mail-header-number header))
4371                         gnus-newsgroup-unselected)
4372                   (progn
4373                     (setq gnus-newsgroup-unreads
4374                           (gnus-add-to-sorted-list
4375                            gnus-newsgroup-unreads article))
4376                     (setq gnus-newsgroup-unselected
4377                           (delq article gnus-newsgroup-unselected)))
4378                 (push article gnus-newsgroup-ancient)))
4379             (forward-line 1)))))))
4380
4381 (defun gnus-summary-update-article-line (article header)
4382   "Update the line for ARTICLE using HEADER."
4383   (let* ((id (mail-header-id header))
4384          (thread (gnus-id-to-thread id)))
4385     (unless thread
4386       (error "Article in no thread"))
4387     ;; Update the thread.
4388     (setcar thread header)
4389     (gnus-summary-goto-subject article)
4390     (let* ((datal (gnus-data-find-list article))
4391            (data (car datal))
4392            (buffer-read-only nil)
4393            (level (gnus-summary-thread-level)))
4394       (gnus-delete-line)
4395       (let ((inserted (- (point)
4396                          (progn
4397                            (gnus-summary-insert-line
4398                             header level nil
4399                             (memq article gnus-newsgroup-undownloaded)
4400                             (gnus-article-mark article)
4401                             (memq article gnus-newsgroup-replied)
4402                             (memq article gnus-newsgroup-expirable)
4403                             ;; Only insert the Subject string when it's different
4404                             ;; from the previous Subject string.
4405                             (if (and
4406                                  gnus-show-threads
4407                                  (gnus-subject-equal
4408                                   (condition-case ()
4409                                       (mail-header-subject
4410                                        (gnus-data-header
4411                                         (cadr
4412                                          (gnus-data-find-list
4413                                           article
4414                                           (gnus-data-list t)))))
4415                                     ;; Error on the side of excessive subjects.
4416                                     (error ""))
4417                                   (mail-header-subject header)))
4418                                 ""
4419                               (mail-header-subject header))
4420                             nil (cdr (assq article gnus-newsgroup-scored))
4421                             (memq article gnus-newsgroup-processable))
4422                            (point)))))
4423         (when (cdr datal)
4424           (gnus-data-update-list
4425            (cdr datal)
4426            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4427
4428 (defun gnus-summary-update-article (article &optional iheader)
4429   "Update ARTICLE in the summary buffer."
4430   (set-buffer gnus-summary-buffer)
4431   (let* ((header (gnus-summary-article-header article))
4432          (id (mail-header-id header))
4433          (data (gnus-data-find article))
4434          (thread (gnus-id-to-thread id))
4435          (references (mail-header-references header))
4436          (parent
4437           (gnus-id-to-thread
4438            (or (gnus-parent-id
4439                 (when (and references
4440                            (not (equal "" references)))
4441                   references))
4442                "none")))
4443          (buffer-read-only nil)
4444          (old (car thread)))
4445     (when thread
4446       (unless iheader
4447         (setcar thread nil)
4448         (when parent
4449           (delq thread parent)))
4450       (if (gnus-summary-insert-subject id header)
4451           ;; Set the (possibly) new article number in the data structure.
4452           (gnus-data-set-number data (gnus-id-to-article id))
4453         (setcar thread old)
4454         nil))))
4455
4456 (defun gnus-rebuild-thread (id &optional line)
4457   "Rebuild the thread containing ID.
4458 If LINE, insert the rebuilt thread starting on line LINE."
4459   (let ((buffer-read-only nil)
4460         old-pos current thread data)
4461     (if (not gnus-show-threads)
4462         (setq thread (list (car (gnus-id-to-thread id))))
4463       ;; Get the thread this article is part of.
4464       (setq thread (gnus-remove-thread id)))
4465     (setq old-pos (point-at-bol))
4466     (setq current (save-excursion
4467                     (and (re-search-backward "[\r\n]" nil t)
4468                          (gnus-summary-article-number))))
4469     ;; If this is a gathered thread, we have to go some re-gathering.
4470     (when (stringp (car thread))
4471       (let ((subject (car thread))
4472             roots thr)
4473         (setq thread (cdr thread))
4474         (while thread
4475           (unless (memq (setq thr (gnus-id-to-thread
4476                                    (gnus-root-id
4477                                     (mail-header-id (caar thread)))))
4478                         roots)
4479             (push thr roots))
4480           (setq thread (cdr thread)))
4481         ;; We now have all (unique) roots.
4482         (if (= (length roots) 1)
4483             ;; All the loose roots are now one solid root.
4484             (setq thread (car roots))
4485           (setq thread (cons subject (gnus-sort-threads roots))))))
4486     (let (threads)
4487       ;; We then insert this thread into the summary buffer.
4488       (when line
4489         (goto-char (point-min))
4490         (forward-line (1- line)))
4491       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4492         (if gnus-show-threads
4493             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4494           (gnus-summary-prepare-unthreaded thread))
4495         (setq data (nreverse gnus-newsgroup-data))
4496         (setq threads gnus-newsgroup-threads))
4497       ;; We splice the new data into the data structure.
4498       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4499       ;;!!! then we want to insert at the beginning of the buffer.
4500       ;;!!! That happens to be true with Gnus now, but that may
4501       ;;!!! change in the future.  Perhaps.
4502       (gnus-data-enter-list
4503        (if line nil current) data (- (point) old-pos))
4504       (setq gnus-newsgroup-threads
4505             (nconc threads gnus-newsgroup-threads))
4506       (gnus-data-compute-positions))))
4507
4508 (defun gnus-number-to-header (number)
4509   "Return the header for article NUMBER."
4510   (let ((headers gnus-newsgroup-headers))
4511     (while (and headers
4512                 (not (= number (mail-header-number (car headers)))))
4513       (pop headers))
4514     (when headers
4515       (car headers))))
4516
4517 (defun gnus-parent-headers (in-headers &optional generation)
4518   "Return the headers of the GENERATIONeth parent of HEADERS."
4519   (unless generation
4520     (setq generation 1))
4521   (let ((parent t)
4522         (headers in-headers)
4523         references)
4524     (while (and parent
4525                 (not (zerop generation))
4526                 (setq references (mail-header-references headers)))
4527       (setq headers (if (and references
4528                              (setq parent (gnus-parent-id references)))
4529                         (car (gnus-id-to-thread parent))
4530                       nil))
4531       (decf generation))
4532     (and (not (eq headers in-headers))
4533          headers)))
4534
4535 (defun gnus-id-to-thread (id)
4536   "Return the (sub-)thread where ID appears."
4537   (gnus-gethash id gnus-newsgroup-dependencies))
4538
4539 (defun gnus-id-to-article (id)
4540   "Return the article number of ID."
4541   (let ((thread (gnus-id-to-thread id)))
4542     (when (and thread
4543                (car thread))
4544       (mail-header-number (car thread)))))
4545
4546 (defun gnus-id-to-header (id)
4547   "Return the article headers of ID."
4548   (car (gnus-id-to-thread id)))
4549
4550 (defun gnus-article-displayed-root-p (article)
4551   "Say whether ARTICLE is a root(ish) article."
4552   (let ((level (gnus-summary-thread-level article))
4553         (refs (mail-header-references  (gnus-summary-article-header article)))
4554         particle)
4555     (cond
4556      ((null level) nil)
4557      ((zerop level) t)
4558      ((null refs) t)
4559      ((null (gnus-parent-id refs)) t)
4560      ((and (= 1 level)
4561            (null (setq particle (gnus-id-to-article
4562                                  (gnus-parent-id refs))))
4563            (null (gnus-summary-thread-level particle)))))))
4564
4565 (defun gnus-root-id (id)
4566   "Return the id of the root of the thread where ID appears."
4567   (let (last-id prev)
4568     (while (and id (setq prev (car (gnus-id-to-thread id))))
4569       (setq last-id id
4570             id (gnus-parent-id (mail-header-references prev))))
4571     last-id))
4572
4573 (defun gnus-articles-in-thread (thread)
4574   "Return the list of articles in THREAD."
4575   (cons (mail-header-number (car thread))
4576         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4577
4578 (defun gnus-remove-thread (id &optional dont-remove)
4579   "Remove the thread that has ID in it."
4580   (let (headers thread last-id)
4581     ;; First go up in this thread until we find the root.
4582     (setq last-id (gnus-root-id id)
4583           headers (message-flatten-list (gnus-id-to-thread last-id)))
4584     ;; We have now found the real root of this thread.  It might have
4585     ;; been gathered into some loose thread, so we have to search
4586     ;; through the threads to find the thread we wanted.
4587     (let ((threads gnus-newsgroup-threads)
4588           sub)
4589       (while threads
4590         (setq sub (car threads))
4591         (if (stringp (car sub))
4592             ;; This is a gathered thread, so we look at the roots
4593             ;; below it to find whether this article is in this
4594             ;; gathered root.
4595             (progn
4596               (setq sub (cdr sub))
4597               (while sub
4598                 (when (member (caar sub) headers)
4599                   (setq thread (car threads)
4600                         threads nil
4601                         sub nil))
4602                 (setq sub (cdr sub))))
4603           ;; It's an ordinary thread, so we check it.
4604           (when (eq (car sub) (car headers))
4605             (setq thread sub
4606                   threads nil)))
4607         (setq threads (cdr threads)))
4608       ;; If this article is in no thread, then it's a root.
4609       (if thread
4610           (unless dont-remove
4611             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4612         (setq thread (gnus-id-to-thread last-id)))
4613       (when thread
4614         (prog1
4615             thread                      ; We return this thread.
4616           (unless dont-remove
4617             (if (stringp (car thread))
4618                 (progn
4619                   ;; If we use dummy roots, then we have to remove the
4620                   ;; dummy root as well.
4621                   (when (eq gnus-summary-make-false-root 'dummy)
4622                     ;; We go to the dummy root by going to
4623                     ;; the first sub-"thread", and then one line up.
4624                     (gnus-summary-goto-article
4625                      (mail-header-number (caadr thread)))
4626                     (forward-line -1)
4627                     (gnus-delete-line)
4628                     (gnus-data-compute-positions))
4629                   (setq thread (cdr thread))
4630                   (while thread
4631                     (gnus-remove-thread-1 (car thread))
4632                     (setq thread (cdr thread))))
4633               (gnus-remove-thread-1 thread))))))))
4634
4635 (defun gnus-remove-thread-1 (thread)
4636   "Remove the thread THREAD recursively."
4637   (let ((number (mail-header-number (pop thread)))
4638         d)
4639     (setq thread (reverse thread))
4640     (while thread
4641       (gnus-remove-thread-1 (pop thread)))
4642     (when (setq d (gnus-data-find number))
4643       (goto-char (gnus-data-pos d))
4644       (gnus-summary-show-thread)
4645       (gnus-data-remove
4646        number
4647        (- (point-at-bol)
4648           (prog1
4649               (1+ (point-at-eol))
4650             (gnus-delete-line)))))))
4651
4652 (defun gnus-sort-threads-1 (threads func)
4653   (sort (mapcar (lambda (thread)
4654                   (cons (car thread)
4655                         (and (cdr thread)
4656                              (gnus-sort-threads-1 (cdr thread) func))))
4657                 threads) func))
4658
4659 (defun gnus-sort-threads (threads)
4660   "Sort THREADS."
4661   (if (not gnus-thread-sort-functions)
4662       threads
4663     (gnus-message 8 "Sorting threads...")
4664     (let ((max-lisp-eval-depth 5000))
4665       (prog1 (gnus-sort-threads-1
4666          threads
4667          (gnus-make-sort-function gnus-thread-sort-functions))
4668         (gnus-message 8 "Sorting threads...done")))))
4669
4670 (defun gnus-sort-articles (articles)
4671   "Sort ARTICLES."
4672   (when gnus-article-sort-functions
4673     (gnus-message 7 "Sorting articles...")
4674     (prog1
4675         (setq gnus-newsgroup-headers
4676               (sort articles (gnus-make-sort-function
4677                               gnus-article-sort-functions)))
4678       (gnus-message 7 "Sorting articles...done"))))
4679
4680 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4681 (defmacro gnus-thread-header (thread)
4682   "Return header of first article in THREAD.
4683 Note that THREAD must never, ever be anything else than a variable -
4684 using some other form will lead to serious barfage."
4685   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4686   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4687   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4688         (vector thread) 2))
4689
4690 (defsubst gnus-article-sort-by-number (h1 h2)
4691   "Sort articles by article number."
4692   (< (mail-header-number h1)
4693      (mail-header-number h2)))
4694
4695 (defun gnus-thread-sort-by-number (h1 h2)
4696   "Sort threads by root article number."
4697   (gnus-article-sort-by-number
4698    (gnus-thread-header h1) (gnus-thread-header h2)))
4699
4700 (defsubst gnus-article-sort-by-random (h1 h2)
4701   "Sort articles by article number."
4702   (zerop (random 2)))
4703
4704 (defun gnus-thread-sort-by-random (h1 h2)
4705   "Sort threads by root article number."
4706   (gnus-article-sort-by-random
4707    (gnus-thread-header h1) (gnus-thread-header h2)))
4708
4709 (defsubst gnus-article-sort-by-lines (h1 h2)
4710   "Sort articles by article Lines header."
4711   (< (mail-header-lines h1)
4712      (mail-header-lines h2)))
4713
4714 (defun gnus-thread-sort-by-lines (h1 h2)
4715   "Sort threads by root article Lines header."
4716   (gnus-article-sort-by-lines
4717    (gnus-thread-header h1) (gnus-thread-header h2)))
4718
4719 (defsubst gnus-article-sort-by-chars (h1 h2)
4720   "Sort articles by octet length."
4721   (< (mail-header-chars h1)
4722      (mail-header-chars h2)))
4723
4724 (defun gnus-thread-sort-by-chars (h1 h2)
4725   "Sort threads by root article octet length."
4726   (gnus-article-sort-by-chars
4727    (gnus-thread-header h1) (gnus-thread-header h2)))
4728
4729 (defsubst gnus-article-sort-by-author (h1 h2)
4730   "Sort articles by root author."
4731   (string-lessp
4732    (let ((extract (funcall
4733                    gnus-extract-address-components
4734                    (mail-header-from h1))))
4735      (or (car extract) (cadr extract) ""))
4736    (let ((extract (funcall
4737                    gnus-extract-address-components
4738                    (mail-header-from h2))))
4739      (or (car extract) (cadr extract) ""))))
4740
4741 (defun gnus-thread-sort-by-author (h1 h2)
4742   "Sort threads by root author."
4743   (gnus-article-sort-by-author
4744    (gnus-thread-header h1)  (gnus-thread-header h2)))
4745
4746 (defsubst gnus-article-sort-by-recipient (h1 h2)
4747   "Sort articles by recipient."
4748   (string-lessp
4749    (let ((extract (funcall
4750                    gnus-extract-address-components
4751                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4752      (or (car extract) (cadr extract)))
4753    (let ((extract (funcall
4754                    gnus-extract-address-components
4755                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4756      (or (car extract) (cadr extract)))))
4757
4758 (defun gnus-thread-sort-by-recipient (h1 h2)
4759   "Sort threads by root recipient."
4760   (gnus-article-sort-by-recipient
4761    (gnus-thread-header h1) (gnus-thread-header h2)))
4762
4763 (defsubst gnus-article-sort-by-subject (h1 h2)
4764   "Sort articles by root subject."
4765   (string-lessp
4766    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4767    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4768
4769 (defun gnus-thread-sort-by-subject (h1 h2)
4770   "Sort threads by root subject."
4771   (gnus-article-sort-by-subject
4772    (gnus-thread-header h1) (gnus-thread-header h2)))
4773
4774 (defsubst gnus-article-sort-by-date (h1 h2)
4775   "Sort articles by root article date."
4776   (time-less-p
4777    (gnus-date-get-time (mail-header-date h1))
4778    (gnus-date-get-time (mail-header-date h2))))
4779
4780 (defun gnus-thread-sort-by-date (h1 h2)
4781   "Sort threads by root article date."
4782   (gnus-article-sort-by-date
4783    (gnus-thread-header h1) (gnus-thread-header h2)))
4784
4785 (defsubst gnus-article-sort-by-score (h1 h2)
4786   "Sort articles by root article score.
4787 Unscored articles will be counted as having a score of zero."
4788   (> (or (cdr (assq (mail-header-number h1)
4789                     gnus-newsgroup-scored))
4790          gnus-summary-default-score 0)
4791      (or (cdr (assq (mail-header-number h2)
4792                     gnus-newsgroup-scored))
4793          gnus-summary-default-score 0)))
4794
4795 (defun gnus-thread-sort-by-score (h1 h2)
4796   "Sort threads by root article score."
4797   (gnus-article-sort-by-score
4798    (gnus-thread-header h1) (gnus-thread-header h2)))
4799
4800 (defun gnus-thread-sort-by-total-score (h1 h2)
4801   "Sort threads by the sum of all scores in the thread.
4802 Unscored articles will be counted as having a score of zero."
4803   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4804
4805 (defun gnus-thread-total-score (thread)
4806   ;; This function find the total score of THREAD.
4807   (cond
4808    ((null thread)
4809     0)
4810    ((consp thread)
4811     (if (stringp (car thread))
4812         (apply gnus-thread-score-function 0
4813                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4814       (gnus-thread-total-score-1 thread)))
4815    (t
4816     (gnus-thread-total-score-1 (list thread)))))
4817
4818 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4819   "Sort threads such that the thread with the most recently arrived article comes first."
4820   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4821
4822 (defun gnus-thread-highest-number (thread)
4823   "Return the highest article number in THREAD."
4824   (apply 'max (mapcar (lambda (header)
4825                         (mail-header-number header))
4826                       (message-flatten-list thread))))
4827
4828 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4829   "Sort threads such that the thread with the most recently dated article comes first."
4830   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4831
4832 (defun gnus-thread-latest-date (thread)
4833   "Return the highest article date in THREAD."
4834   (let ((previous-time 0))
4835     (apply 'max
4836            (mapcar
4837             (lambda (header)
4838               (setq previous-time
4839                     (condition-case ()
4840                         (time-to-seconds (mail-header-parse-date
4841                                           (mail-header-date header)))
4842                       (error previous-time))))
4843             (sort
4844              (message-flatten-list thread)
4845              (lambda (h1 h2)
4846                (< (mail-header-number h1)
4847                   (mail-header-number h2))))))))
4848
4849 (defun gnus-thread-total-score-1 (root)
4850   ;; This function find the total score of the thread below ROOT.
4851   (setq root (car root))
4852   (apply gnus-thread-score-function
4853          (or (append
4854               (mapcar 'gnus-thread-total-score
4855                       (cdr (gnus-id-to-thread (mail-header-id root))))
4856               (when (> (mail-header-number root) 0)
4857                 (list (or (cdr (assq (mail-header-number root)
4858                                      gnus-newsgroup-scored))
4859                           gnus-summary-default-score 0))))
4860              (list gnus-summary-default-score)
4861              '(0))))
4862
4863 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4864 (defvar gnus-tmp-prev-subject nil)
4865 (defvar gnus-tmp-false-parent nil)
4866 (defvar gnus-tmp-root-expunged nil)
4867 (defvar gnus-tmp-dummy-line nil)
4868
4869 (eval-when-compile (defvar gnus-tmp-header))
4870 (defun gnus-extra-header (type &optional header)
4871   "Return the extra header of TYPE."
4872   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4873       ""))
4874
4875 (defvar gnus-tmp-thread-tree-header-string "")
4876
4877 (defcustom gnus-sum-thread-tree-root "> "
4878   "With %B spec, used for the root of a thread.
4879 If nil, use subject instead."
4880   :version "22.1"
4881   :type '(radio (const :format "%v  " nil) string)
4882   :group 'gnus-thread)
4883
4884 (defcustom gnus-sum-thread-tree-false-root "> "
4885   "With %B spec, used for a false root of a thread.
4886 If nil, use subject instead."
4887   :version "22.1"
4888   :type '(radio (const :format "%v  " nil) string)
4889   :group 'gnus-thread)
4890
4891 (defcustom gnus-sum-thread-tree-single-indent ""
4892   "With %B spec, used for a thread with just one message.
4893 If nil, use subject instead."
4894   :version "22.1"
4895   :type '(radio (const :format "%v  " nil) string)
4896   :group 'gnus-thread)
4897
4898 (defcustom gnus-sum-thread-tree-vertical "| "
4899   "With %B spec, used for drawing a vertical line."
4900   :version "22.1"
4901   :type 'string
4902   :group 'gnus-thread)
4903
4904 (defcustom gnus-sum-thread-tree-indent "  "
4905   "With %B spec, used for indenting."
4906   :version "22.1"
4907   :type 'string
4908   :group 'gnus-thread)
4909
4910 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4911   "With %B spec, used for a leaf with brothers."
4912   :version "22.1"
4913   :type 'string
4914   :group 'gnus-thread)
4915
4916 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4917   "With %B spec, used for a leaf without brothers."
4918   :version "22.1"
4919   :type 'string
4920   :group 'gnus-thread)
4921
4922 (defun gnus-summary-prepare-threads (threads)
4923   "Prepare summary buffer from THREADS and indentation LEVEL.
4924 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4925 or a straight list of headers."
4926   (gnus-message 7 "Generating summary...")
4927
4928   (setq gnus-newsgroup-threads threads)
4929   (beginning-of-line)
4930
4931   (let ((gnus-tmp-level 0)
4932         (default-score (or gnus-summary-default-score 0))
4933         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4934         (building-line-count gnus-summary-display-while-building)
4935         (building-count (integerp gnus-summary-display-while-building))
4936         thread number subject stack state gnus-tmp-gathered beg-match
4937         new-roots gnus-tmp-new-adopts thread-end simp-subject
4938         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4939         gnus-tmp-replied gnus-tmp-subject-or-nil
4940         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4941         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4942         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4943         tree-stack)
4944
4945     (setq gnus-tmp-prev-subject nil
4946           gnus-tmp-thread-tree-header-string "")
4947
4948     (if (vectorp (car threads))
4949         ;; If this is a straight (sic) list of headers, then a
4950         ;; threaded summary display isn't required, so we just create
4951         ;; an unthreaded one.
4952         (gnus-summary-prepare-unthreaded threads)
4953
4954       ;; Do the threaded display.
4955
4956       (if gnus-summary-display-while-building
4957           (switch-to-buffer (buffer-name)))
4958       (while (or threads stack gnus-tmp-new-adopts new-roots)
4959
4960         (if (and (= gnus-tmp-level 0)
4961                  (or (not stack)
4962                      (= (caar stack) 0))
4963                  (not gnus-tmp-false-parent)
4964                  (or gnus-tmp-new-adopts new-roots))
4965             (if gnus-tmp-new-adopts
4966                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4967                       thread (list (car gnus-tmp-new-adopts))
4968                       gnus-tmp-header (caar thread)
4969                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4970               (when new-roots
4971                 (setq thread (list (car new-roots))
4972                       gnus-tmp-header (caar thread)
4973                       new-roots (cdr new-roots))))
4974
4975           (if threads
4976               ;; If there are some threads, we do them before the
4977               ;; threads on the stack.
4978               (setq thread threads
4979                     gnus-tmp-header (caar thread))
4980             ;; There were no current threads, so we pop something off
4981             ;; the stack.
4982             (setq state (car stack)
4983                   gnus-tmp-level (car state)
4984                   tree-stack (cadr state)
4985                   thread (caddr state)
4986                   stack (cdr stack)
4987                   gnus-tmp-header (caar thread))))
4988
4989         (setq gnus-tmp-false-parent nil)
4990         (setq gnus-tmp-root-expunged nil)
4991         (setq thread-end nil)
4992
4993         (if (stringp gnus-tmp-header)
4994             ;; The header is a dummy root.
4995             (cond
4996              ((eq gnus-summary-make-false-root 'adopt)
4997               ;; We let the first article adopt the rest.
4998               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4999                                                (cddar thread)))
5000               (setq gnus-tmp-gathered
5001                     (nconc (mapcar
5002                             (lambda (h) (mail-header-number (car h)))
5003                             (cddar thread))
5004                            gnus-tmp-gathered))
5005               (setq thread (cons (list (caar thread)
5006                                        (cadar thread))
5007                                  (cdr thread)))
5008               (setq gnus-tmp-level -1
5009                     gnus-tmp-false-parent t))
5010              ((eq gnus-summary-make-false-root 'empty)
5011               ;; We print adopted articles with empty subject fields.
5012               (setq gnus-tmp-gathered
5013                     (nconc (mapcar
5014                             (lambda (h) (mail-header-number (car h)))
5015                             (cddar thread))
5016                            gnus-tmp-gathered))
5017               (setq gnus-tmp-level -1))
5018              ((eq gnus-summary-make-false-root 'dummy)
5019               ;; We remember that we probably want to output a dummy
5020               ;; root.
5021               (setq gnus-tmp-dummy-line gnus-tmp-header)
5022               (setq gnus-tmp-prev-subject gnus-tmp-header))
5023              (t
5024               ;; We do not make a root for the gathered
5025               ;; sub-threads at all.
5026               (setq gnus-tmp-level -1)))
5027
5028           (setq number (mail-header-number gnus-tmp-header)
5029                 subject (mail-header-subject gnus-tmp-header)
5030                 simp-subject (gnus-simplify-subject-fully subject))
5031
5032           (cond
5033            ;; If the thread has changed subject, we might want to make
5034            ;; this subthread into a root.
5035            ((and (null gnus-thread-ignore-subject)
5036                  (not (zerop gnus-tmp-level))
5037                  gnus-tmp-prev-subject
5038                  (not (string= gnus-tmp-prev-subject simp-subject)))
5039             (setq new-roots (nconc new-roots (list (car thread)))
5040                   thread-end t
5041                   gnus-tmp-header nil))
5042            ;; If the article lies outside the current limit,
5043            ;; then we do not display it.
5044            ((not (memq number gnus-newsgroup-limit))
5045             (setq gnus-tmp-gathered
5046                   (nconc (mapcar
5047                           (lambda (h) (mail-header-number (car h)))
5048                           (cdar thread))
5049                          gnus-tmp-gathered))
5050             (setq gnus-tmp-new-adopts (if (cdar thread)
5051                                           (append gnus-tmp-new-adopts
5052                                                   (cdar thread))
5053                                         gnus-tmp-new-adopts)
5054                   thread-end t
5055                   gnus-tmp-header nil)
5056             (when (zerop gnus-tmp-level)
5057               (setq gnus-tmp-root-expunged t)))
5058            ;; Perhaps this article is to be marked as read?
5059            ((and gnus-summary-mark-below
5060                  (< (or (cdr (assq number gnus-newsgroup-scored))
5061                         default-score)
5062                     gnus-summary-mark-below)
5063                  ;; Don't touch sparse articles.
5064                  (not (gnus-summary-article-sparse-p number))
5065                  (not (gnus-summary-article-ancient-p number)))
5066             (setq gnus-newsgroup-unreads
5067                   (delq number gnus-newsgroup-unreads))
5068             (if gnus-newsgroup-auto-expire
5069                 (setq gnus-newsgroup-expirable
5070                       (gnus-add-to-sorted-list
5071                        gnus-newsgroup-expirable number))
5072               (push (cons number gnus-low-score-mark)
5073                     gnus-newsgroup-reads))))
5074
5075           (when gnus-tmp-header
5076             ;; We may have an old dummy line to output before this
5077             ;; article.
5078             (when (and gnus-tmp-dummy-line
5079                        (gnus-subject-equal
5080                         gnus-tmp-dummy-line
5081                         (mail-header-subject gnus-tmp-header)))
5082               (gnus-summary-insert-dummy-line
5083                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5084               (setq gnus-tmp-dummy-line nil))
5085
5086             ;; Compute the mark.
5087             (setq gnus-tmp-unread (gnus-article-mark number))
5088
5089             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5090                                   gnus-tmp-header gnus-tmp-level)
5091                   gnus-newsgroup-data)
5092
5093             ;; Actually insert the line.
5094             (setq
5095              gnus-tmp-subject-or-nil
5096              (cond
5097               ((and gnus-thread-ignore-subject
5098                     gnus-tmp-prev-subject
5099                     (not (string= gnus-tmp-prev-subject simp-subject)))
5100                subject)
5101               ((zerop gnus-tmp-level)
5102                (if (and (eq gnus-summary-make-false-root 'empty)
5103                         (memq number gnus-tmp-gathered)
5104                         gnus-tmp-prev-subject
5105                         (string= gnus-tmp-prev-subject simp-subject))
5106                    gnus-summary-same-subject
5107                  subject))
5108               (t gnus-summary-same-subject)))
5109             (if (and (eq gnus-summary-make-false-root 'adopt)
5110                      (= gnus-tmp-level 1)
5111                      (memq number gnus-tmp-gathered))
5112                 (setq gnus-tmp-opening-bracket ?\<
5113                       gnus-tmp-closing-bracket ?\>)
5114               (setq gnus-tmp-opening-bracket ?\[
5115                     gnus-tmp-closing-bracket ?\]))
5116             (setq
5117              gnus-tmp-indentation
5118              (aref gnus-thread-indent-array gnus-tmp-level)
5119              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5120              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5121                                 gnus-summary-default-score 0)
5122              gnus-tmp-score-char
5123              (if (or (null gnus-summary-default-score)
5124                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5125                          gnus-summary-zcore-fuzz))
5126                  ?                      ;Whitespace
5127                (if (< gnus-tmp-score gnus-summary-default-score)
5128                    gnus-score-below-mark gnus-score-over-mark))
5129              gnus-tmp-replied
5130              (cond ((memq number gnus-newsgroup-processable)
5131                     gnus-process-mark)
5132                    ((memq number gnus-newsgroup-cached)
5133                     gnus-cached-mark)
5134                    ((memq number gnus-newsgroup-replied)
5135                     gnus-replied-mark)
5136                    ((memq number gnus-newsgroup-forwarded)
5137                     gnus-forwarded-mark)
5138                    ((memq number gnus-newsgroup-saved)
5139                     gnus-saved-mark)
5140                    ((memq number gnus-newsgroup-recent)
5141                     gnus-recent-mark)
5142                    ((memq number gnus-newsgroup-unseen)
5143                     gnus-unseen-mark)
5144                    (t gnus-no-mark))
5145              gnus-tmp-downloaded
5146              (cond ((memq number gnus-newsgroup-undownloaded)
5147                     gnus-undownloaded-mark)
5148                    (gnus-newsgroup-agentized
5149                     gnus-downloaded-mark)
5150                    (t
5151                     gnus-no-mark))
5152              gnus-tmp-from (mail-header-from gnus-tmp-header)
5153              gnus-tmp-name
5154              (cond
5155               ((string-match "<[^>]+> *$" gnus-tmp-from)
5156                (setq beg-match (match-beginning 0))
5157                (or (and (string-match "^\".+\"" gnus-tmp-from)
5158                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5159                    (substring gnus-tmp-from 0 beg-match)))
5160               ((string-match "(.+)" gnus-tmp-from)
5161                (substring gnus-tmp-from
5162                           (1+ (match-beginning 0)) (1- (match-end 0))))
5163               (t gnus-tmp-from))
5164
5165              ;; Do the %B string
5166              gnus-tmp-thread-tree-header-string
5167              (cond
5168               ((not gnus-show-threads) "")
5169               ((zerop gnus-tmp-level)
5170                (cond ((cdar thread)
5171                       (or gnus-sum-thread-tree-root subject))
5172                      (gnus-tmp-new-adopts
5173                       (or gnus-sum-thread-tree-false-root subject))
5174                      (t
5175                       (or gnus-sum-thread-tree-single-indent subject))))
5176               (t
5177                (concat (apply 'concat
5178                               (mapcar (lambda (item)
5179                                         (if (= item 1)
5180                                             gnus-sum-thread-tree-vertical
5181                                           gnus-sum-thread-tree-indent))
5182                                       (cdr (reverse tree-stack))))
5183                        (if (nth 1 thread)
5184                            gnus-sum-thread-tree-leaf-with-other
5185                          gnus-sum-thread-tree-single-leaf)))))
5186             (when (string= gnus-tmp-name "")
5187               (setq gnus-tmp-name gnus-tmp-from))
5188             (unless (numberp gnus-tmp-lines)
5189               (setq gnus-tmp-lines -1))
5190             (if (= gnus-tmp-lines -1)
5191                 (setq gnus-tmp-lines "?")
5192               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5193               (gnus-put-text-property
5194              (point)
5195              (progn (eval gnus-summary-line-format-spec) (point))
5196                'gnus-number number)
5197             (when gnus-visual-p
5198               (forward-line -1)
5199               (gnus-run-hooks 'gnus-summary-update-hook)
5200               (forward-line 1))
5201
5202             (setq gnus-tmp-prev-subject simp-subject)))
5203
5204         (when (nth 1 thread)
5205           (push (list (max 0 gnus-tmp-level)
5206                       (copy-sequence tree-stack)
5207                       (nthcdr 1 thread))
5208                 stack))
5209         (push (if (nth 1 thread) 1 0) tree-stack)
5210         (incf gnus-tmp-level)
5211         (setq threads (if thread-end nil (cdar thread)))
5212         (if gnus-summary-display-while-building
5213             (if building-count
5214                 (progn
5215                   ;; use a set frequency
5216                   (setq building-line-count (1- building-line-count))
5217                   (when (= building-line-count 0)
5218                     (sit-for 0)
5219                     (setq building-line-count
5220                           gnus-summary-display-while-building)))
5221               ;; always
5222               (sit-for 0)))
5223         (unless threads
5224           (setq gnus-tmp-level 0)))))
5225   (gnus-message 7 "Generating summary...done"))
5226
5227 (defun gnus-summary-prepare-unthreaded (headers)
5228   "Generate an unthreaded summary buffer based on HEADERS."
5229   (let (header number mark)
5230
5231     (beginning-of-line)
5232
5233     (while headers
5234       ;; We may have to root out some bad articles...
5235       (when (memq (setq number (mail-header-number
5236                                 (setq header (pop headers))))
5237                   gnus-newsgroup-limit)
5238         ;; Mark article as read when it has a low score.
5239         (when (and gnus-summary-mark-below
5240                    (< (or (cdr (assq number gnus-newsgroup-scored))
5241                           gnus-summary-default-score 0)
5242                       gnus-summary-mark-below)
5243                    (not (gnus-summary-article-ancient-p number)))
5244           (setq gnus-newsgroup-unreads
5245                 (delq number gnus-newsgroup-unreads))
5246           (if gnus-newsgroup-auto-expire
5247               (push number gnus-newsgroup-expirable)
5248             (push (cons number gnus-low-score-mark)
5249                   gnus-newsgroup-reads)))
5250
5251         (setq mark (gnus-article-mark number))
5252         (push (gnus-data-make number mark (1+ (point)) header 0)
5253               gnus-newsgroup-data)
5254         (gnus-summary-insert-line
5255          header 0 number
5256          (memq number gnus-newsgroup-undownloaded)
5257          mark (memq number gnus-newsgroup-replied)
5258          (memq number gnus-newsgroup-expirable)
5259          (mail-header-subject header) nil
5260          (cdr (assq number gnus-newsgroup-scored))
5261          (memq number gnus-newsgroup-processable))))))
5262
5263 (defun gnus-summary-remove-list-identifiers ()
5264   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5265   (let ((regexp (if (consp gnus-list-identifiers)
5266                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5267                   gnus-list-identifiers))
5268         changed subject)
5269     (when regexp
5270       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5271       (dolist (header gnus-newsgroup-headers)
5272         (setq subject (mail-header-subject header)
5273               changed nil)
5274         (while (string-match regexp subject)
5275           (setq subject
5276                 (concat (substring subject 0 (match-beginning 1))
5277                         (substring subject (match-end 0)))
5278                 changed t))
5279         (when changed
5280           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5281             (setq subject
5282                   (concat (substring subject 0 (match-beginning 1))
5283                           (substring subject (match-end 1)))))
5284           (mail-header-set-subject header subject))))))
5285
5286 (defun gnus-fetch-headers (articles)
5287   "Fetch headers of ARTICLES."
5288   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5289     (gnus-message 5 "Fetching headers for %s..." name)
5290     (prog1
5291         (if (eq 'nov
5292                 (setq gnus-headers-retrieved-by
5293                       (gnus-retrieve-headers
5294                        articles gnus-newsgroup-name
5295                        ;; We might want to fetch old headers, but
5296                        ;; not if there is only 1 article.
5297                        (and (or (and
5298                                  (not (eq gnus-fetch-old-headers 'some))
5299                                  (not (numberp gnus-fetch-old-headers)))
5300                                 (> (length articles) 1))
5301                             gnus-fetch-old-headers))))
5302             (gnus-get-newsgroup-headers-xover
5303              articles nil nil gnus-newsgroup-name t)
5304           (gnus-get-newsgroup-headers))
5305       (gnus-message 5 "Fetching headers for %s...done" name))))
5306
5307 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5308   "Select newsgroup GROUP.
5309 If READ-ALL is non-nil, all articles in the group are selected.
5310 If SELECT-ARTICLES, only select those articles from GROUP."
5311   (let* ((entry (gnus-group-entry group))
5312          ;;!!! Dirty hack; should be removed.
5313          (gnus-summary-ignore-duplicates
5314           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5315               t
5316             gnus-summary-ignore-duplicates))
5317          (info (nth 2 entry))
5318          articles fetched-articles cached)
5319
5320     (unless (gnus-check-server
5321              (set (make-local-variable 'gnus-current-select-method)
5322                   (gnus-find-method-for-group group)))
5323       (error "Couldn't open server"))
5324
5325     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5326         (gnus-activate-group group)     ; Or we can activate it...
5327         (progn                          ; Or we bug out.
5328           (when (equal major-mode 'gnus-summary-mode)
5329             (gnus-kill-buffer (current-buffer)))
5330           (error "Couldn't activate group %s: %s"
5331                  (gnus-group-decoded-name group) (gnus-status-message group))))
5332
5333     (unless (gnus-request-group group t)
5334       (when (equal major-mode 'gnus-summary-mode)
5335         (gnus-kill-buffer (current-buffer)))
5336       (error "Couldn't request group %s: %s"
5337              (gnus-group-decoded-name group) (gnus-status-message group)))
5338
5339     (when gnus-agent
5340       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5341
5342       (setq gnus-summary-use-undownloaded-faces
5343             (gnus-agent-find-parameter
5344              group
5345              'agent-enable-undownloaded-faces)))
5346
5347     (setq gnus-newsgroup-name group
5348           gnus-newsgroup-unselected nil
5349           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5350
5351     (let ((display (gnus-group-find-parameter group 'display)))
5352       (setq gnus-newsgroup-display
5353             (cond
5354              ((not (zerop (or (car-safe read-all) 0)))
5355               ;; The user entered the group with C-u SPC/RET, let's show
5356               ;; all articles.
5357               'gnus-not-ignore)
5358              ((eq display 'all)
5359               'gnus-not-ignore)
5360              ((arrayp display)
5361               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5362              ((numberp display)
5363               ;; The following is probably the "correct" solution, but
5364               ;; it makes Gnus fetch all headers and then limit the
5365               ;; articles (which is slow), so instead we hack the
5366               ;; select-articles parameter instead. -- Simon Josefsson
5367               ;; <jas@kth.se>
5368               ;;
5369               ;; (gnus-byte-compile
5370               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5371               ;;                         display)))))
5372               (setq select-articles
5373                     (gnus-uncompress-range
5374                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5375                              (if (> tmp 0)
5376                                  tmp
5377                                1))
5378                            (cdr (gnus-active group)))))
5379               nil)
5380              (t
5381               nil))))
5382
5383     (gnus-summary-setup-default-charset)
5384
5385     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5386     (when (gnus-virtual-group-p group)
5387       (setq cached gnus-newsgroup-cached))
5388
5389     (setq gnus-newsgroup-unreads
5390           (gnus-sorted-ndifference
5391            (gnus-sorted-ndifference gnus-newsgroup-unreads
5392                                     gnus-newsgroup-marked)
5393            gnus-newsgroup-dormant))
5394
5395     (setq gnus-newsgroup-processable nil)
5396
5397     (gnus-update-read-articles group gnus-newsgroup-unreads)
5398
5399     ;; Adjust and set lists of article marks.
5400     (when info
5401       (gnus-adjust-marked-articles info))
5402     (if (setq articles select-articles)
5403         (setq gnus-newsgroup-unselected
5404               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5405       (setq articles (gnus-articles-to-read group read-all)))
5406
5407     (cond
5408      ((null articles)
5409       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5410       'quit)
5411      ((eq articles 0) nil)
5412      (t
5413       ;; Init the dependencies hash table.
5414       (setq gnus-newsgroup-dependencies
5415             (gnus-make-hashtable (length articles)))
5416       (gnus-set-global-variables)
5417       ;; Retrieve the headers and read them in.
5418
5419       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5420
5421       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5422       (when cached
5423         (setq gnus-newsgroup-cached cached))
5424
5425       ;; Suppress duplicates?
5426       (when gnus-suppress-duplicates
5427         (gnus-dup-suppress-articles))
5428
5429       ;; Set the initial limit.
5430       (setq gnus-newsgroup-limit (copy-sequence articles))
5431       ;; Remove canceled articles from the list of unread articles.
5432       (setq fetched-articles
5433             (mapcar (lambda (headers) (mail-header-number headers))
5434                     gnus-newsgroup-headers))
5435       (setq gnus-newsgroup-articles fetched-articles)
5436       (setq gnus-newsgroup-unreads
5437             (gnus-sorted-nintersection
5438              gnus-newsgroup-unreads fetched-articles))
5439       (gnus-compute-unseen-list)
5440
5441       ;; Removed marked articles that do not exist.
5442       (gnus-update-missing-marks
5443        (gnus-sorted-difference articles fetched-articles))
5444       ;; We might want to build some more threads first.
5445       (when (and gnus-fetch-old-headers
5446                  (eq gnus-headers-retrieved-by 'nov))
5447         (if (eq gnus-fetch-old-headers 'invisible)
5448             (gnus-build-all-threads)
5449           (gnus-build-old-threads)))
5450       ;; Let the Gnus agent mark articles as read.
5451       (when gnus-agent
5452         (gnus-agent-get-undownloaded-list))
5453       ;; Remove list identifiers from subject
5454       (when gnus-list-identifiers
5455         (gnus-summary-remove-list-identifiers))
5456       ;; Check whether auto-expire is to be done in this group.
5457       (setq gnus-newsgroup-auto-expire
5458             (gnus-group-auto-expirable-p group))
5459       ;; Set up the article buffer now, if necessary.
5460       (unless (and gnus-single-article-buffer
5461                    (equal gnus-article-buffer "*Article*"))
5462         (gnus-article-setup-buffer))
5463       ;; First and last article in this newsgroup.
5464       (when gnus-newsgroup-headers
5465         (setq gnus-newsgroup-begin
5466               (mail-header-number (car gnus-newsgroup-headers))
5467               gnus-newsgroup-end
5468               (mail-header-number
5469                (gnus-last-element gnus-newsgroup-headers))))
5470       ;; GROUP is successfully selected.
5471       (or gnus-newsgroup-headers t)))))
5472
5473 (defun gnus-compute-unseen-list ()
5474   ;; The `seen' marks are treated specially.
5475   (if (not gnus-newsgroup-seen)
5476       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5477     (setq gnus-newsgroup-unseen
5478           (gnus-inverse-list-range-intersection
5479            gnus-newsgroup-articles gnus-newsgroup-seen))))
5480
5481 (defun gnus-summary-display-make-predicate (display)
5482   (require 'gnus-agent)
5483   (when (= (length display) 1)
5484     (setq display (car display)))
5485   (unless gnus-summary-display-cache
5486     (dolist (elem (append '((unread . unread)
5487                             (read . read)
5488                             (unseen . unseen))
5489                           gnus-article-mark-lists))
5490       (push (cons (cdr elem)
5491                   (gnus-byte-compile
5492                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5493             gnus-summary-display-cache)))
5494   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5495         (gnus-category-predicate-cache gnus-summary-display-cache))
5496     (gnus-get-predicate display)))
5497
5498 ;; Uses the dynamically bound `number' variable.
5499 (eval-when-compile
5500   (defvar number))
5501 (defun gnus-article-marked-p (type &optional article)
5502   (let ((article (or article number)))
5503     (cond
5504      ((eq type 'tick)
5505       (memq article gnus-newsgroup-marked))
5506      ((eq type 'spam)
5507       (memq article gnus-newsgroup-spam-marked))
5508      ((eq type 'unsend)
5509       (memq article gnus-newsgroup-unsendable))
5510      ((eq type 'undownload)
5511       (memq article gnus-newsgroup-undownloaded))
5512      ((eq type 'download)
5513       (memq article gnus-newsgroup-downloadable))
5514      ((eq type 'unread)
5515       (memq article gnus-newsgroup-unreads))
5516      ((eq type 'read)
5517       (memq article gnus-newsgroup-reads))
5518      ((eq type 'dormant)
5519       (memq article gnus-newsgroup-dormant) )
5520      ((eq type 'expire)
5521       (memq article gnus-newsgroup-expirable))
5522      ((eq type 'reply)
5523       (memq article gnus-newsgroup-replied))
5524      ((eq type 'killed)
5525       (memq article gnus-newsgroup-killed))
5526      ((eq type 'bookmark)
5527       (assq article gnus-newsgroup-bookmarks))
5528      ((eq type 'score)
5529       (assq article gnus-newsgroup-scored))
5530      ((eq type 'save)
5531       (memq article gnus-newsgroup-saved))
5532      ((eq type 'cache)
5533       (memq article gnus-newsgroup-cached))
5534      ((eq type 'forward)
5535       (memq article gnus-newsgroup-forwarded))
5536      ((eq type 'seen)
5537       (not (memq article gnus-newsgroup-unseen)))
5538      ((eq type 'recent)
5539       (memq article gnus-newsgroup-recent))
5540      (t t))))
5541
5542 (defun gnus-articles-to-read (group &optional read-all)
5543   "Find out what articles the user wants to read."
5544   (let* ((articles
5545           ;; Select all articles if `read-all' is non-nil, or if there
5546           ;; are no unread articles.
5547           (if (or read-all
5548                   (and (zerop (length gnus-newsgroup-marked))
5549                        (zerop (length gnus-newsgroup-unreads)))
5550                   ;; Fetch all if the predicate is non-nil.
5551                   gnus-newsgroup-display)
5552               ;; We want to select the headers for all the articles in
5553               ;; the group, so we select either all the active
5554               ;; articles in the group, or (if that's nil), the
5555               ;; articles in the cache.
5556               (or
5557                (gnus-uncompress-range (gnus-active group))
5558                (gnus-cache-articles-in-group group))
5559             ;; Select only the "normal" subset of articles.
5560             (gnus-sorted-nunion
5561              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5562              gnus-newsgroup-unreads)))
5563          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5564          (scored (length scored-list))
5565          (number (length articles))
5566          (marked (+ (length gnus-newsgroup-marked)
5567                     (length gnus-newsgroup-dormant)))
5568          (select
5569           (cond
5570            ((numberp read-all)
5571             read-all)
5572            ((numberp gnus-newsgroup-display)
5573             gnus-newsgroup-display)
5574            (t
5575             (condition-case ()
5576                 (cond
5577                  ((and (or (<= scored marked) (= scored number))
5578                        (numberp gnus-large-newsgroup)
5579                        (> number gnus-large-newsgroup))
5580                   (let* ((cursor-in-echo-area nil)
5581                          (initial (gnus-parameter-large-newsgroup-initial
5582                                    gnus-newsgroup-name))
5583                          (input
5584                           (read-string
5585                            (format
5586                             "How many articles from %s (%s %d): "
5587                             (gnus-limit-string
5588                              (gnus-group-decoded-name gnus-newsgroup-name)
5589                              35)
5590                             (if initial "max" "default")
5591                             number)
5592                            (if initial
5593                                (cons (number-to-string initial)
5594                                      0)))))
5595                     (if (string-match "^[ \t]*$" input) number input)))
5596                  ((and (> scored marked) (< scored number)
5597                        (> (- scored number) 20))
5598                   (let ((input
5599                          (read-string
5600                           (format "%s %s (%d scored, %d total): "
5601                                   "How many articles from"
5602                                   (gnus-group-decoded-name group)
5603                                   scored number))))
5604                     (if (string-match "^[ \t]*$" input)
5605                         number input)))
5606                  (t number))
5607               (quit
5608                (message "Quit getting the articles to read")
5609                nil))))))
5610     (setq select (if (stringp select) (string-to-number select) select))
5611     (if (or (null select) (zerop select))
5612         select
5613       (if (and (not (zerop scored)) (<= (abs select) scored))
5614           (progn
5615             (setq articles (sort scored-list '<))
5616             (setq number (length articles)))
5617         (setq articles (copy-sequence articles)))
5618
5619       (when (< (abs select) number)
5620         (if (< select 0)
5621             ;; Select the N oldest articles.
5622             (setcdr (nthcdr (1- (abs select)) articles) nil)
5623           ;; Select the N most recent articles.
5624           (setq articles (nthcdr (- number select) articles))))
5625       (setq gnus-newsgroup-unselected
5626             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5627       (when gnus-alter-articles-to-read-function
5628         (setq articles
5629               (sort
5630                (funcall gnus-alter-articles-to-read-function
5631                         gnus-newsgroup-name articles)
5632                '<)))
5633       articles)))
5634
5635 (defun gnus-killed-articles (killed articles)
5636   (let (out)
5637     (while articles
5638       (when (inline (gnus-member-of-range (car articles) killed))
5639         (push (car articles) out))
5640       (setq articles (cdr articles)))
5641     out))
5642
5643 (defun gnus-uncompress-marks (marks)
5644   "Uncompress the mark ranges in MARKS."
5645   (let ((uncompressed '(score bookmark))
5646         out)
5647     (while marks
5648       (if (memq (caar marks) uncompressed)
5649           (push (car marks) out)
5650         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5651       (setq marks (cdr marks)))
5652     out))
5653
5654 (defun gnus-article-mark-to-type (mark)
5655   "Return the type of MARK."
5656   (or (cadr (assq mark gnus-article-special-mark-lists))
5657       'list))
5658
5659 (defun gnus-article-unpropagatable-p (mark)
5660   "Return whether MARK should be propagated to back end."
5661   (memq mark gnus-article-unpropagated-mark-lists))
5662
5663 (defun gnus-adjust-marked-articles (info)
5664   "Set all article lists and remove all marks that are no longer valid."
5665   (let* ((marked-lists (gnus-info-marks info))
5666          (active (gnus-active (gnus-info-group info)))
5667          (min (car active))
5668          (max (cdr active))
5669          (types gnus-article-mark-lists)
5670          marks var articles article mark mark-type
5671          bgn end)
5672
5673     (dolist (marks marked-lists)
5674       (setq mark (car marks)
5675             mark-type (gnus-article-mark-to-type mark)
5676             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5677
5678       ;; We set the variable according to the type of the marks list,
5679       ;; and then adjust the marks to a subset of the active articles.
5680       (cond
5681        ;; Adjust "simple" lists - compressed yet unsorted
5682        ((eq mark-type 'list)
5683         ;; Simultaneously uncompress and clip to active range
5684         ;; See gnus-uncompress-range for a description of possible marks
5685         (let (l lh)
5686           (if (not (cadr marks))
5687               (set var nil)
5688             (setq articles (if (numberp (cddr marks))
5689                                (list (cdr marks))
5690                              (cdr marks))
5691                   lh (cons nil nil)
5692                   l lh)
5693
5694             (while (setq article (pop articles))
5695               (cond ((consp article)
5696                      (setq bgn (max (car article) min)
5697                            end (min (cdr article) max))
5698                      (while (<= bgn end)
5699                        (setq l (setcdr l (cons bgn nil))
5700                              bgn (1+ bgn))))
5701                     ((and (<= min article)
5702                           (>= max article))
5703                      (setq l (setcdr l (cons article nil))))))
5704             (set var (cdr lh)))))
5705        ;; Adjust assocs.
5706        ((eq mark-type 'tuple)
5707         (set var (setq articles (cdr marks)))
5708         (when (not (listp (cdr (symbol-value var))))
5709           (set var (list (symbol-value var))))
5710         (when (not (listp (cdr articles)))
5711           (setq articles (list articles)))
5712         (while articles
5713           (when (or (not (consp (setq article (pop articles))))
5714                     (< (car article) min)
5715                     (> (car article) max))
5716             (set var (delq article (symbol-value var))))))
5717        ;; Adjust ranges (sloppily).
5718        ((eq mark-type 'range)
5719         (cond
5720          ((eq mark 'seen)
5721           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5722           ;; It should be (seen (NUM1 . NUM2)).
5723           (when (numberp (cddr marks))
5724             (setcdr marks (list (cdr marks))))
5725           (setq articles (cdr marks))
5726           (while (and articles
5727                       (or (and (consp (car articles))
5728                                (> min (cdar articles)))
5729                           (and (numberp (car articles))
5730                                (> min (car articles)))))
5731             (pop articles))
5732           (set var articles))))))))
5733
5734 (defun gnus-update-missing-marks (missing)
5735   "Go through the list of MISSING articles and remove them from the mark lists."
5736   (when missing
5737     (let (var m)
5738       ;; Go through all types.
5739       (dolist (elem gnus-article-mark-lists)
5740         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5741           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5742           (when (symbol-value var)
5743             ;; This list has articles.  So we delete all missing
5744             ;; articles from it.
5745             (setq m missing)
5746             (while m
5747               (set var (delq (pop m) (symbol-value var))))))))))
5748
5749 (defun gnus-update-marks ()
5750   "Enter the various lists of marked articles into the newsgroup info list."
5751   (let ((types gnus-article-mark-lists)
5752         (info (gnus-get-info gnus-newsgroup-name))
5753         type list newmarked symbol delta-marks)
5754     (when info
5755       ;; Add all marks lists to the list of marks lists.
5756       (while (setq type (pop types))
5757         (setq list (symbol-value
5758                     (setq symbol
5759                           (intern (format "gnus-newsgroup-%s" (car type))))))
5760
5761         (when list
5762           ;; Get rid of the entries of the articles that have the
5763           ;; default score.
5764           (when (and (eq (cdr type) 'score)
5765                      gnus-save-score
5766                      list)
5767             (let* ((arts list)
5768                    (prev (cons nil list))
5769                    (all prev))
5770               (while arts
5771                 (if (or (not (consp (car arts)))
5772                         (= (cdar arts) gnus-summary-default-score))
5773                     (setcdr prev (cdr arts))
5774                   (setq prev arts))
5775                 (setq arts (cdr arts)))
5776               (setq list (cdr all)))))
5777
5778         (when (eq (cdr type) 'seen)
5779           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5780
5781         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5782           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5783
5784         (when (and (gnus-check-backend-function
5785                     'request-set-mark gnus-newsgroup-name)
5786                    (not (gnus-article-unpropagatable-p (cdr type))))
5787           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5788                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5789                  (add (gnus-remove-from-range
5790                        (gnus-copy-sequence list) old)))
5791             (when add
5792               (push (list add 'add (list (cdr type))) delta-marks))
5793             (when del
5794               (push (list del 'del (list (cdr type))) delta-marks))))
5795
5796         (when list
5797           (push (cons (cdr type) list) newmarked)))
5798
5799       (when delta-marks
5800         (unless (gnus-check-group gnus-newsgroup-name)
5801           (error "Can't open server for %s" gnus-newsgroup-name))
5802         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5803
5804       ;; Enter these new marks into the info of the group.
5805       (if (nthcdr 3 info)
5806           (setcar (nthcdr 3 info) newmarked)
5807         ;; Add the marks lists to the end of the info.
5808         (when newmarked
5809           (setcdr (nthcdr 2 info) (list newmarked))))
5810
5811       ;; Cut off the end of the info if there's nothing else there.
5812       (let ((i 5))
5813         (while (and (> i 2)
5814                     (not (nth i info)))
5815           (when (nthcdr (decf i) info)
5816             (setcdr (nthcdr i info) nil)))))))
5817
5818 (defun gnus-set-mode-line (where)
5819   "Set the mode line of the article or summary buffers.
5820 If WHERE is `summary', the summary mode line format will be used."
5821   ;; Is this mode line one we keep updated?
5822   (when (and (memq where gnus-updated-mode-lines)
5823              (symbol-value
5824               (intern (format "gnus-%s-mode-line-format-spec" where))))
5825     (let (mode-string)
5826       (save-excursion
5827         ;; We evaluate this in the summary buffer since these
5828         ;; variables are buffer-local to that buffer.
5829         (set-buffer gnus-summary-buffer)
5830        ;; We bind all these variables that are used in the `eval' form
5831         ;; below.
5832         (let* ((mformat (symbol-value
5833                          (intern
5834                           (format "gnus-%s-mode-line-format-spec" where))))
5835                (gnus-tmp-group-name (gnus-mode-string-quote
5836                                      (gnus-group-decoded-name
5837                                       gnus-newsgroup-name)))
5838                (gnus-tmp-article-number (or gnus-current-article 0))
5839                (gnus-tmp-unread gnus-newsgroup-unreads)
5840                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5841                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5842                (gnus-tmp-unread-and-unselected
5843                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5844                             (zerop gnus-tmp-unselected))
5845                        "")
5846                       ((zerop gnus-tmp-unselected)
5847                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5848                       (t (format "{%d(+%d) more}"
5849                                  gnus-tmp-unread-and-unticked
5850                                  gnus-tmp-unselected))))
5851                (gnus-tmp-subject
5852                 (if (and gnus-current-headers
5853                          (vectorp gnus-current-headers))
5854                     (gnus-mode-string-quote
5855                      (mail-header-subject gnus-current-headers))
5856                   ""))
5857                bufname-length max-len
5858                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5859           (setq mode-string (eval mformat))
5860           (setq bufname-length (if (string-match "%b" mode-string)
5861                                    (- (length
5862                                        (buffer-name
5863                                         (if (eq where 'summary)
5864                                             nil
5865                                           (get-buffer gnus-article-buffer))))
5866                                       2)
5867                                  0))
5868           (setq max-len (max 4 (if gnus-mode-non-string-length
5869                                    (- (window-width)
5870                                       gnus-mode-non-string-length
5871                                       bufname-length)
5872                                  (length mode-string))))
5873           ;; We might have to chop a bit of the string off...
5874           (when (> (length mode-string) max-len)
5875             (setq mode-string
5876                   (concat (truncate-string-to-width mode-string (- max-len 3))
5877                           "...")))
5878           ;; Pad the mode string a bit.
5879           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5880       ;; Update the mode line.
5881       (setq mode-line-buffer-identification
5882             (gnus-mode-line-buffer-identification (list mode-string)))
5883       (set-buffer-modified-p t))))
5884
5885 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5886   "Go through the HEADERS list and add all Xrefs to a hash table.
5887 The resulting hash table is returned, or nil if no Xrefs were found."
5888   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5889          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5890          (xref-hashtb (gnus-make-hashtable))
5891          start group entry number xrefs header)
5892     (while headers
5893       (setq header (pop headers))
5894       (when (and (setq xrefs (mail-header-xref header))
5895                  (not (memq (setq number (mail-header-number header))
5896                             unreads)))
5897         (setq start 0)
5898         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5899           (setq start (match-end 0))
5900           (setq group (if prefix
5901                           (concat prefix (substring xrefs (match-beginning 1)
5902                                                     (match-end 1)))
5903                         (substring xrefs (match-beginning 1) (match-end 1))))
5904           (setq number
5905                 (string-to-number (substring xrefs (match-beginning 2)
5906                                           (match-end 2))))
5907           (if (setq entry (gnus-gethash group xref-hashtb))
5908               (setcdr entry (cons number (cdr entry)))
5909             (gnus-sethash group (cons number nil) xref-hashtb)))))
5910     (and start xref-hashtb)))
5911
5912 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5913   "Look through all the headers and mark the Xrefs as read."
5914   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5915         name info xref-hashtb idlist method nth4)
5916     (save-excursion
5917       (set-buffer gnus-group-buffer)
5918       (when (setq xref-hashtb
5919                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5920         (mapatoms
5921          (lambda (group)
5922            (unless (string= from-newsgroup (setq name (symbol-name group)))
5923              (setq idlist (symbol-value group))
5924              ;; Dead groups are not updated.
5925              (and (prog1
5926                       (setq info (gnus-get-info name))
5927                     (when (stringp (setq nth4 (gnus-info-method info)))
5928                       (setq nth4 (gnus-server-to-method nth4))))
5929                   ;; Only do the xrefs if the group has the same
5930                   ;; select method as the group we have just read.
5931                   (or (gnus-methods-equal-p
5932                        nth4 (gnus-find-method-for-group from-newsgroup))
5933                       virtual
5934                       (equal nth4 (setq method (gnus-find-method-for-group
5935                                                 from-newsgroup)))
5936                       (and (equal (car nth4) (car method))
5937                            (equal (nth 1 nth4) (nth 1 method))))
5938                   gnus-use-cross-reference
5939                   (or (not (eq gnus-use-cross-reference t))
5940                       virtual
5941                       ;; Only do cross-references on subscribed
5942                       ;; groups, if that is what is wanted.
5943                       (<= (gnus-info-level info) gnus-level-subscribed))
5944                   (gnus-group-make-articles-read name idlist))))
5945          xref-hashtb)))))
5946
5947 (defun gnus-compute-read-articles (group articles)
5948   (let* ((entry (gnus-group-entry group))
5949          (info (nth 2 entry))
5950          (active (gnus-active group))
5951          ninfo)
5952     (when entry
5953       ;; First peel off all invalid article numbers.
5954       (when active
5955         (let ((ids articles)
5956               id first)
5957           (while (setq id (pop ids))
5958             (when (and first (> id (cdr active)))
5959               ;; We'll end up in this situation in one particular
5960               ;; obscure situation.  If you re-scan a group and get
5961               ;; a new article that is cross-posted to a different
5962               ;; group that has not been re-scanned, you might get
5963               ;; crossposted article that has a higher number than
5964               ;; Gnus believes possible.  So we re-activate this
5965               ;; group as well.  This might mean doing the
5966               ;; crossposting thingy will *increase* the number
5967               ;; of articles in some groups.  Tsk, tsk.
5968               (setq active (or (gnus-activate-group group) active)))
5969             (when (or (> id (cdr active))
5970                       (< id (car active)))
5971               (setq articles (delq id articles))))))
5972       ;; If the read list is nil, we init it.
5973       (if (and active
5974                (null (gnus-info-read info))
5975                (> (car active) 1))
5976           (setq ninfo (cons 1 (1- (car active))))
5977         (setq ninfo (gnus-info-read info)))
5978       ;; Then we add the read articles to the range.
5979       (gnus-add-to-range
5980        ninfo (setq articles (sort articles '<))))))
5981
5982 (defun gnus-group-make-articles-read (group articles)
5983   "Update the info of GROUP to say that ARTICLES are read."
5984   (let* ((num 0)
5985          (entry (gnus-group-entry group))
5986          (info (nth 2 entry))
5987          (active (gnus-active group))
5988          range)
5989     (when entry
5990       (setq range (gnus-compute-read-articles group articles))
5991       (with-current-buffer gnus-group-buffer
5992         (gnus-undo-register
5993           `(progn
5994              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5995              (gnus-info-set-read ',info ',(gnus-info-read info))
5996              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5997              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5998              (gnus-group-update-group ,group t))))
5999       ;; Add the read articles to the range.
6000       (gnus-info-set-read info range)
6001       (gnus-request-set-mark group (list (list range 'add '(read))))
6002       ;; Then we have to re-compute how many unread
6003       ;; articles there are in this group.
6004       (when active
6005         (cond
6006          ((not range)
6007           (setq num (- (1+ (cdr active)) (car active))))
6008          ((not (listp (cdr range)))
6009           (setq num (- (cdr active) (- (1+ (cdr range))
6010                                        (car range)))))
6011          (t
6012           (while range
6013             (if (numberp (car range))
6014                 (setq num (1+ num))
6015               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6016             (setq range (cdr range)))
6017           (setq num (- (cdr active) num))))
6018         ;; Update the number of unread articles.
6019         (setcar entry num)
6020         ;; Update the group buffer.
6021         (unless (gnus-ephemeral-group-p group)
6022           (gnus-group-update-group group t))))))
6023
6024 (defvar gnus-newsgroup-none-id 0)
6025
6026 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6027   (let ((cur nntp-server-buffer)
6028         (dependencies
6029          (or dependencies
6030              (with-current-buffer gnus-summary-buffer
6031                gnus-newsgroup-dependencies)))
6032         headers id end ref number
6033         (mail-parse-charset gnus-newsgroup-charset)
6034         (mail-parse-ignored-charsets
6035          (save-excursion (condition-case nil
6036                              (set-buffer gnus-summary-buffer)
6037                            (error))
6038                          gnus-newsgroup-ignored-charsets)))
6039     (save-excursion
6040       (set-buffer nntp-server-buffer)
6041       ;; Translate all TAB characters into SPACE characters.
6042       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6043       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6044       (ietf-drums-unfold-fws)
6045       (gnus-run-hooks 'gnus-parse-headers-hook)
6046       (let ((case-fold-search t)
6047             in-reply-to header p lines chars)
6048         (goto-char (point-min))
6049         ;; Search to the beginning of the next header.  Error messages
6050         ;; do not begin with 2 or 3.
6051         (while (re-search-forward "^[23][0-9]+ " nil t)
6052           (setq id nil
6053                 ref nil)
6054           ;; This implementation of this function, with nine
6055           ;; search-forwards instead of the one re-search-forward and
6056           ;; a case (which basically was the old function) is actually
6057           ;; about twice as fast, even though it looks messier.  You
6058           ;; can't have everything, I guess.  Speed and elegance
6059           ;; doesn't always go hand in hand.
6060           (setq
6061            header
6062            (vector
6063             ;; Number.
6064             (prog1
6065                 (setq number (read cur))
6066               (end-of-line)
6067               (setq p (point))
6068               (narrow-to-region (point)
6069                                 (or (and (search-forward "\n.\n" nil t)
6070                                          (- (point) 2))
6071                                     (point))))
6072             ;; Subject.
6073             (progn
6074               (goto-char p)
6075               (if (search-forward "\nsubject:" nil t)
6076                   (funcall gnus-decode-encoded-word-function
6077                            (nnheader-header-value))
6078                 "(none)"))
6079             ;; From.
6080             (progn
6081               (goto-char p)
6082               (if (search-forward "\nfrom:" nil t)
6083                   (funcall gnus-decode-encoded-address-function
6084                            (nnheader-header-value))
6085                 "(nobody)"))
6086             ;; Date.
6087             (progn
6088               (goto-char p)
6089               (if (search-forward "\ndate:" nil t)
6090                   (nnheader-header-value) ""))
6091             ;; Message-ID.
6092             (progn
6093               (goto-char p)
6094               (setq id (if (re-search-forward
6095                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6096                            ;; We do it this way to make sure the Message-ID
6097                            ;; is (somewhat) syntactically valid.
6098                            (buffer-substring (match-beginning 1)
6099                                              (match-end 1))
6100                          ;; If there was no message-id, we just fake one
6101                          ;; to make subsequent routines simpler.
6102                          (nnheader-generate-fake-message-id number))))
6103             ;; References.
6104             (progn
6105               (goto-char p)
6106               (if (search-forward "\nreferences:" nil t)
6107                   (progn
6108                     (setq end (point))
6109                     (prog1
6110                         (nnheader-header-value)
6111                       (setq ref
6112                             (buffer-substring
6113                              (progn
6114                                (end-of-line)
6115                                (search-backward ">" end t)
6116                                (1+ (point)))
6117                              (progn
6118                                (search-backward "<" end t)
6119                                (point))))))
6120                 ;; Get the references from the in-reply-to header if there
6121                 ;; were no references and the in-reply-to header looks
6122                 ;; promising.
6123                 (if (and (search-forward "\nin-reply-to:" nil t)
6124                          (setq in-reply-to (nnheader-header-value))
6125                          (string-match "<[^>]+>" in-reply-to))
6126                     (let (ref2)
6127                       (setq ref (substring in-reply-to (match-beginning 0)
6128                                            (match-end 0)))
6129                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6130                         (setq ref2 (substring in-reply-to (match-beginning 0)
6131                                               (match-end 0)))
6132                         (when (> (length ref2) (length ref))
6133                           (setq ref ref2)))
6134                       ref)
6135                   (setq ref nil))))
6136             ;; Chars.
6137             (progn
6138               (goto-char p)
6139               (if (search-forward "\nchars: " nil t)
6140                   (if (numberp (setq chars (ignore-errors (read cur))))
6141                       chars -1)
6142                 -1))
6143             ;; Lines.
6144             (progn
6145               (goto-char p)
6146               (if (search-forward "\nlines: " nil t)
6147                   (if (numberp (setq lines (ignore-errors (read cur))))
6148                       lines -1)
6149                 -1))
6150             ;; Xref.
6151             (progn
6152               (goto-char p)
6153               (and (search-forward "\nxref:" nil t)
6154                    (nnheader-header-value)))
6155             ;; Extra.
6156             (when gnus-extra-headers
6157               (let ((extra gnus-extra-headers)
6158                     out)
6159                 (while extra
6160                   (goto-char p)
6161                   (when (search-forward
6162                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6163                     (push (cons (car extra) (nnheader-header-value))
6164                           out))
6165                   (pop extra))
6166                 out))))
6167           (when (equal id ref)
6168             (setq ref nil))
6169
6170           (when gnus-alter-header-function
6171             (funcall gnus-alter-header-function header)
6172             (setq id (mail-header-id header)
6173                   ref (gnus-parent-id (mail-header-references header))))
6174
6175           (when (setq header
6176                       (gnus-dependencies-add-header
6177                        header dependencies force-new))
6178             (push header headers))
6179           (goto-char (point-max))
6180           (widen))
6181         (nreverse headers)))))
6182
6183 ;; Goes through the xover lines and returns a list of vectors
6184 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6185                                                   force-new dependencies
6186                                                   group also-fetch-heads)
6187   "Parse the news overview data in the server buffer.
6188 Return a list of headers that match SEQUENCE (see
6189 `nntp-retrieve-headers')."
6190   ;; Get the Xref when the users reads the articles since most/some
6191   ;; NNTP servers do not include Xrefs when using XOVER.
6192   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6193   (let ((mail-parse-charset gnus-newsgroup-charset)
6194         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6195         (cur nntp-server-buffer)
6196         (dependencies (or dependencies gnus-newsgroup-dependencies))
6197         (allp (cond
6198                ((eq gnus-read-all-available-headers t)
6199                 t)
6200                ((and (stringp gnus-read-all-available-headers)
6201                      group)
6202                 (string-match gnus-read-all-available-headers group))
6203                (t
6204                 nil)))
6205         number headers header)
6206     (save-excursion
6207       (set-buffer nntp-server-buffer)
6208       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6209       ;; Allow the user to mangle the headers before parsing them.
6210       (gnus-run-hooks 'gnus-parse-headers-hook)
6211       (goto-char (point-min))
6212       (gnus-parse-without-error
6213         (while (and (or sequence allp)
6214                     (not (eobp)))
6215           (setq number (read cur))
6216           (when (not allp)
6217             (while (and sequence
6218                         (< (car sequence) number))
6219               (setq sequence (cdr sequence))))
6220           (when (and (or allp
6221                          (and sequence
6222                               (eq number (car sequence))))
6223                      (progn
6224                        (setq sequence (cdr sequence))
6225                        (setq header (inline
6226                                       (gnus-nov-parse-line
6227                                        number dependencies force-new)))))
6228             (push header headers))
6229           (forward-line 1)))
6230       ;; A common bug in inn is that if you have posted an article and
6231       ;; then retrieves the active file, it will answer correctly --
6232       ;; the new article is included.  However, a NOV entry for the
6233       ;; article may not have been generated yet, so this may fail.
6234       ;; We work around this problem by retrieving the last few
6235       ;; headers using HEAD.
6236       (if (or (not also-fetch-heads)
6237               (not sequence))
6238           ;; We (probably) got all the headers.
6239           (nreverse headers)
6240         (let ((gnus-nov-is-evil t))
6241           (nconc
6242            (nreverse headers)
6243            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6244              (gnus-get-newsgroup-headers))))))))
6245
6246 (defun gnus-article-get-xrefs ()
6247   "Fill in the Xref value in `gnus-current-headers', if necessary.
6248 This is meant to be called in `gnus-article-internal-prepare-hook'."
6249   (let ((headers (with-current-buffer gnus-summary-buffer
6250                    gnus-current-headers)))
6251     (or (not gnus-use-cross-reference)
6252         (not headers)
6253         (and (mail-header-xref headers)
6254              (not (string= (mail-header-xref headers) "")))
6255         (let ((case-fold-search t)
6256               xref)
6257           (save-restriction
6258             (nnheader-narrow-to-headers)
6259             (goto-char (point-min))
6260             (when (or (and (not (eobp))
6261                            (eq (downcase (char-after)) ?x)
6262                            (looking-at "Xref:"))
6263                       (search-forward "\nXref:" nil t))
6264               (goto-char (1+ (match-end 0)))
6265               (setq xref (buffer-substring (point) (point-at-eol)))
6266               (mail-header-set-xref headers xref)))))))
6267
6268 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6269   "Find article ID and insert the summary line for that article.
6270 OLD-HEADER can either be a header or a line number to insert
6271 the subject line on."
6272   (let* ((line (and (numberp old-header) old-header))
6273          (old-header (and (vectorp old-header) old-header))
6274          (header (cond ((and old-header use-old-header)
6275                         old-header)
6276                        ((and (numberp id)
6277                              (gnus-number-to-header id))
6278                         (gnus-number-to-header id))
6279                        (t
6280                         (gnus-read-header id))))
6281          (number (and (numberp id) id))
6282          d)
6283     (when header
6284       ;; Rebuild the thread that this article is part of and go to the
6285       ;; article we have fetched.
6286       (when (and (not gnus-show-threads)
6287                  old-header)
6288         (when (and number
6289                    (setq d (gnus-data-find (mail-header-number old-header))))
6290           (goto-char (gnus-data-pos d))
6291           (gnus-data-remove
6292            number
6293            (- (point-at-bol)
6294               (prog1
6295                   (1+ (point-at-eol))
6296                 (gnus-delete-line))))))
6297       ;; Remove list identifiers from subject.
6298       (when gnus-list-identifiers
6299         (let ((gnus-newsgroup-headers (list header)))
6300           (gnus-summary-remove-list-identifiers)))
6301       (when old-header
6302         (mail-header-set-number header (mail-header-number old-header)))
6303       (setq gnus-newsgroup-sparse
6304             (delq (setq number (mail-header-number header))
6305                   gnus-newsgroup-sparse))
6306       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6307       (push number gnus-newsgroup-limit)
6308       (gnus-rebuild-thread (mail-header-id header) line)
6309       (gnus-summary-goto-subject number nil t))
6310     (when (and (numberp number)
6311                (> number 0))
6312       ;; We have to update the boundaries even if we can't fetch the
6313       ;; article if ID is a number -- so that the next `P' or `N'
6314       ;; command will fetch the previous (or next) article even
6315       ;; if the one we tried to fetch this time has been canceled.
6316       (when (> number gnus-newsgroup-end)
6317         (setq gnus-newsgroup-end number))
6318       (when (< number gnus-newsgroup-begin)
6319         (setq gnus-newsgroup-begin number))
6320       (setq gnus-newsgroup-unselected
6321             (delq number gnus-newsgroup-unselected)))
6322     ;; Report back a success?
6323     (and header (mail-header-number header))))
6324
6325 ;;; Process/prefix in the summary buffer
6326
6327 (defun gnus-summary-work-articles (n)
6328   "Return a list of articles to be worked upon.
6329 The prefix argument, the list of process marked articles, and the
6330 current article will be taken into consideration."
6331   (save-excursion
6332     (set-buffer gnus-summary-buffer)
6333     (cond
6334      (n
6335       ;; A numerical prefix has been given.
6336       (setq n (prefix-numeric-value n))
6337       (let ((backward (< n 0))
6338             (n (abs (prefix-numeric-value n)))
6339             articles article)
6340         (save-excursion
6341           (while
6342               (and (> n 0)
6343                    (push (setq article (gnus-summary-article-number))
6344                          articles)
6345                    (if backward
6346                        (gnus-summary-find-prev nil article)
6347                      (gnus-summary-find-next nil article)))
6348             (decf n)))
6349         (nreverse articles)))
6350      ((and (gnus-region-active-p) (mark))
6351       (message "region active")
6352       ;; Work on the region between point and mark.
6353       (let ((max (max (point) (mark)))
6354             articles article)
6355         (save-excursion
6356           (goto-char (min (point) (mark)))
6357           (while
6358               (and
6359                (push (setq article (gnus-summary-article-number)) articles)
6360                (gnus-summary-find-next nil article)
6361                (< (point) max)))
6362           (nreverse articles))))
6363      (gnus-newsgroup-processable
6364       ;; There are process-marked articles present.
6365       ;; Save current state.
6366       (gnus-summary-save-process-mark)
6367       ;; Return the list.
6368       (reverse gnus-newsgroup-processable))
6369      (t
6370       ;; Just return the current article.
6371       (list (gnus-summary-article-number))))))
6372
6373 (defmacro gnus-summary-iterate (arg &rest forms)
6374   "Iterate over the process/prefixed articles and do FORMS.
6375 ARG is the interactive prefix given to the command.  FORMS will be
6376 executed with point over the summary line of the articles."
6377   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6378     `(let ((,articles (gnus-summary-work-articles ,arg)))
6379        (while ,articles
6380          (gnus-summary-goto-subject (car ,articles))
6381          ,@forms
6382          (pop ,articles)))))
6383
6384 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6385 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6386
6387 (defun gnus-summary-save-process-mark ()
6388   "Push the current set of process marked articles on the stack."
6389   (interactive)
6390   (push (copy-sequence gnus-newsgroup-processable)
6391         gnus-newsgroup-process-stack))
6392
6393 (defun gnus-summary-kill-process-mark ()
6394   "Push the current set of process marked articles on the stack and unmark."
6395   (interactive)
6396   (gnus-summary-save-process-mark)
6397   (gnus-summary-unmark-all-processable))
6398
6399 (defun gnus-summary-yank-process-mark ()
6400   "Pop the last process mark state off the stack and restore it."
6401   (interactive)
6402   (unless gnus-newsgroup-process-stack
6403     (error "Empty mark stack"))
6404   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6405
6406 (defun gnus-summary-process-mark-set (set)
6407   "Make SET into the current process marked articles."
6408   (gnus-summary-unmark-all-processable)
6409   (mapc 'gnus-summary-set-process-mark set))
6410
6411 ;;; Searching and stuff
6412
6413 (defun gnus-summary-search-group (&optional backward use-level)
6414   "Search for next unread newsgroup.
6415 If optional argument BACKWARD is non-nil, search backward instead."
6416   (save-excursion
6417     (set-buffer gnus-group-buffer)
6418     (when (gnus-group-search-forward
6419            backward nil (if use-level (gnus-group-group-level) nil))
6420       (gnus-group-group-name))))
6421
6422 (defun gnus-summary-best-group (&optional exclude-group)
6423   "Find the name of the best unread group.
6424 If EXCLUDE-GROUP, do not go to this group."
6425   (with-current-buffer gnus-group-buffer
6426     (save-excursion
6427       (gnus-group-best-unread-group exclude-group))))
6428
6429 (defun gnus-summary-find-next (&optional unread article backward)
6430   (if backward
6431       (gnus-summary-find-prev unread article)
6432     (let* ((dummy (gnus-summary-article-intangible-p))
6433            (article (or article (gnus-summary-article-number)))
6434            (data (gnus-data-find-list article))
6435            result)
6436       (when (and (not dummy)
6437                  (or (not gnus-summary-check-current)
6438                      (not unread)
6439                      (not (gnus-data-unread-p (car data)))))
6440         (setq data (cdr data)))
6441       (when (setq result
6442                   (if unread
6443                       (progn
6444                         (while data
6445                           (unless (memq (gnus-data-number (car data))
6446                                         (cond
6447                                          ((eq gnus-auto-goto-ignores
6448                                               'always-undownloaded)
6449                                           gnus-newsgroup-undownloaded)
6450                                          (gnus-plugged
6451                                           nil)
6452                                          ((eq gnus-auto-goto-ignores
6453                                               'unfetched)
6454                                           gnus-newsgroup-unfetched)
6455                                          ((eq gnus-auto-goto-ignores
6456                                               'undownloaded)
6457                                           gnus-newsgroup-undownloaded)))
6458                             (when (gnus-data-unread-p (car data))
6459                               (setq result (car data)
6460                                     data nil)))
6461                           (setq data (cdr data)))
6462                         result)
6463                     (car data)))
6464         (goto-char (gnus-data-pos result))
6465         (gnus-data-number result)))))
6466
6467 (defun gnus-summary-find-prev (&optional unread article)
6468   (let* ((eobp (eobp))
6469          (article (or article (gnus-summary-article-number)))
6470          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6471          result)
6472     (when (and (not eobp)
6473                (or (not gnus-summary-check-current)
6474                    (not unread)
6475                    (not (gnus-data-unread-p (car data)))))
6476       (setq data (cdr data)))
6477     (when (setq result
6478                 (if unread
6479                     (progn
6480                       (while data
6481                         (unless (memq (gnus-data-number (car data))
6482                                       (cond
6483                                        ((eq gnus-auto-goto-ignores
6484                                             'always-undownloaded)
6485                                         gnus-newsgroup-undownloaded)
6486                                        (gnus-plugged
6487                                         nil)
6488                                        ((eq gnus-auto-goto-ignores
6489                                             'unfetched)
6490                                         gnus-newsgroup-unfetched)
6491                                        ((eq gnus-auto-goto-ignores
6492                                             'undownloaded)
6493                                         gnus-newsgroup-undownloaded)))
6494                           (when (gnus-data-unread-p (car data))
6495                             (setq result (car data)
6496                                   data nil)))
6497                         (setq data (cdr data)))
6498                       result)
6499                   (car data)))
6500       (goto-char (gnus-data-pos result))
6501       (gnus-data-number result))))
6502
6503 (defun gnus-summary-find-subject (subject &optional unread backward article)
6504   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6505          (article (or article (gnus-summary-article-number)))
6506          (articles (gnus-data-list backward))
6507          (arts (gnus-data-find-list article articles))
6508          result)
6509     (when (or (not gnus-summary-check-current)
6510               (not unread)
6511               (not (gnus-data-unread-p (car arts))))
6512       (setq arts (cdr arts)))
6513     (while arts
6514       (and (or (not unread)
6515                (gnus-data-unread-p (car arts)))
6516            (vectorp (gnus-data-header (car arts)))
6517            (gnus-subject-equal
6518             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6519            (setq result (car arts)
6520                  arts nil))
6521       (setq arts (cdr arts)))
6522     (and result
6523          (goto-char (gnus-data-pos result))
6524          (gnus-data-number result))))
6525
6526 (defun gnus-summary-search-forward (&optional unread subject backward)
6527   "Search forward for an article.
6528 If UNREAD, look for unread articles.  If SUBJECT, look for
6529 articles with that subject.  If BACKWARD, search backward instead."
6530   (cond (subject (gnus-summary-find-subject subject unread backward))
6531         (backward (gnus-summary-find-prev unread))
6532         (t (gnus-summary-find-next unread))))
6533
6534 (defun gnus-recenter (&optional n)
6535   "Center point in window and redisplay frame.
6536 Also do horizontal recentering."
6537   (interactive "P")
6538   (when (and gnus-auto-center-summary
6539              (not (eq gnus-auto-center-summary 'vertical)))
6540     (gnus-horizontal-recenter))
6541   (recenter n))
6542
6543 (defun gnus-summary-recenter ()
6544   "Center point in the summary window.
6545 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6546 displayed, no centering will be performed."
6547   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6548   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6549   (interactive)
6550   ;; The user has to want it.
6551   (when gnus-auto-center-summary
6552     (let* ((top (cond ((< (window-height) 4) 0)
6553                       ((< (window-height) 7) 1)
6554                       (t (if (numberp gnus-auto-center-summary)
6555                              gnus-auto-center-summary
6556                            (/ (1- (window-height)) 2)))))
6557            (height (1- (window-height)))
6558            (bottom (save-excursion (goto-char (point-max))
6559                                    (forward-line (- height))
6560                                    (point)))
6561            (window (get-buffer-window (current-buffer))))
6562       (when (get-buffer-window gnus-article-buffer)
6563         ;; Only do recentering when the article buffer is displayed,
6564         ;; Set the window start to either `bottom', which is the biggest
6565         ;; possible valid number, or the second line from the top,
6566         ;; whichever is the least.
6567         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6568           (if (> bottom top-pos)
6569               ;; Keep the second line from the top visible
6570               (set-window-start window top-pos t)
6571             ;; Try to keep the bottom line visible; if it's partially
6572             ;; obscured, either scroll one more line to make it fully
6573             ;; visible, or revert to using TOP-POS.
6574             (save-excursion
6575               (goto-char (point-max))
6576               (forward-line -1)
6577               (let ((last-line-start (point)))
6578                 (goto-char bottom)
6579                 (set-window-start window (point) t)
6580                 (when (not (pos-visible-in-window-p last-line-start window))
6581                   (forward-line 1)
6582                   (set-window-start window (min (point) top-pos) t)))))))
6583       ;; Do horizontal recentering while we're at it.
6584       (when (and (get-buffer-window (current-buffer) t)
6585                  (not (eq gnus-auto-center-summary 'vertical)))
6586         (let ((selected (selected-window)))
6587           (select-window (get-buffer-window (current-buffer) t))
6588           (gnus-summary-position-point)
6589           (gnus-horizontal-recenter)
6590           (select-window selected))))))
6591
6592 (defun gnus-summary-jump-to-group (newsgroup)
6593   "Move point to NEWSGROUP in group mode buffer."
6594   ;; Keep update point of group mode buffer if visible.
6595   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6596       (save-window-excursion
6597         ;; Take care of tree window mode.
6598         (when (get-buffer-window gnus-group-buffer)
6599           (pop-to-buffer gnus-group-buffer))
6600         (gnus-group-jump-to-group newsgroup))
6601     (save-excursion
6602       ;; Take care of tree window mode.
6603       (if (get-buffer-window gnus-group-buffer)
6604           (pop-to-buffer gnus-group-buffer)
6605         (set-buffer gnus-group-buffer))
6606       (gnus-group-jump-to-group newsgroup))))
6607
6608 ;; This function returns a list of article numbers based on the
6609 ;; difference between the ranges of read articles in this group and
6610 ;; the range of active articles.
6611 (defun gnus-list-of-unread-articles (group)
6612   (let* ((read (gnus-info-read (gnus-get-info group)))
6613          (active (or (gnus-active group) (gnus-activate-group group)))
6614          (last (or (cdr active)
6615                    (error "Group %s couldn't be activated " group)))
6616          first nlast unread)
6617     ;; If none are read, then all are unread.
6618     (if (not read)
6619         (setq first (car active))
6620       ;; If the range of read articles is a single range, then the
6621       ;; first unread article is the article after the last read
6622       ;; article.  Sounds logical, doesn't it?
6623       (if (and (not (listp (cdr read)))
6624                (or (< (car read) (car active))
6625                    (progn (setq read (list read))
6626                           nil)))
6627           (setq first (max (car active) (1+ (cdr read))))
6628         ;; `read' is a list of ranges.
6629         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6630                                   (caar read)))
6631                   1)
6632           (setq first (car active)))
6633         (while read
6634           (when first
6635             (while (< first nlast)
6636               (setq unread (cons first unread)
6637                     first (1+ first))))
6638           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6639           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6640           (setq read (cdr read)))))
6641     ;; And add the last unread articles.
6642     (while (<= first last)
6643       (setq unread (cons first unread)
6644             first (1+ first)))
6645     ;; Return the list of unread articles.
6646     (delq 0 (nreverse unread))))
6647
6648 (defun gnus-list-of-read-articles (group)
6649   "Return a list of unread, unticked and non-dormant articles."
6650   (let* ((info (gnus-get-info group))
6651          (marked (gnus-info-marks info))
6652          (active (gnus-active group)))
6653     (and info active
6654          (gnus-list-range-difference
6655           (gnus-list-range-difference
6656            (gnus-sorted-complement
6657             (gnus-uncompress-range active)
6658             (gnus-list-of-unread-articles group))
6659            (cdr (assq 'dormant marked)))
6660           (cdr (assq 'tick marked))))))
6661
6662 ;; This function returns a sequence of article numbers based on the
6663 ;; difference between the ranges of read articles in this group and
6664 ;; the range of active articles.
6665 (defun gnus-sequence-of-unread-articles (group)
6666   (let* ((read (gnus-info-read (gnus-get-info group)))
6667          (active (or (gnus-active group) (gnus-activate-group group)))
6668          (last (cdr active))
6669          first nlast unread)
6670     ;; If none are read, then all are unread.
6671     (if (not read)
6672         (setq first (car active))
6673       ;; If the range of read articles is a single range, then the
6674       ;; first unread article is the article after the last read
6675       ;; article.  Sounds logical, doesn't it?
6676       (if (and (not (listp (cdr read)))
6677                (or (< (car read) (car active))
6678                    (progn (setq read (list read))
6679                           nil)))
6680           (setq first (max (car active) (1+ (cdr read))))
6681         ;; `read' is a list of ranges.
6682         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6683                                   (caar read)))
6684                   1)
6685           (setq first (car active)))
6686         (while read
6687           (when first
6688             (push (cons first nlast) unread))
6689           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6690           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6691           (setq read (cdr read)))))
6692     ;; And add the last unread articles.
6693     (cond ((not (and first last))
6694            nil)
6695           ((< first last)
6696            (push (cons first last) unread))
6697           ((= first last)
6698            (push first unread)))
6699     ;; Return the sequence of unread articles.
6700     (delq 0 (nreverse unread))))
6701
6702 ;; Various summary commands
6703
6704 (defun gnus-summary-select-article-buffer ()
6705   "Reconfigure windows to show article buffer."
6706   (interactive)
6707   (if (not (gnus-buffer-live-p gnus-article-buffer))
6708       (error "There is no article buffer for this summary buffer")
6709     (gnus-configure-windows 'article)
6710     (select-window (get-buffer-window gnus-article-buffer))))
6711
6712 (defun gnus-summary-universal-argument (arg)
6713   "Perform any operation on all articles that are process/prefixed."
6714   (interactive "P")
6715   (let ((articles (gnus-summary-work-articles arg))
6716         func article)
6717     (if (eq
6718          (setq
6719           func
6720           (key-binding
6721            (read-key-sequence
6722             (substitute-command-keys
6723              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6724          'undefined)
6725         (gnus-error 1 "Undefined key")
6726       (save-excursion
6727         (while articles
6728           (gnus-summary-goto-subject (setq article (pop articles)))
6729           (let (gnus-newsgroup-processable)
6730             (command-execute func))
6731           (gnus-summary-remove-process-mark article)))))
6732   (gnus-summary-position-point))
6733
6734 (defun gnus-summary-toggle-truncation (&optional arg)
6735   "Toggle truncation of summary lines.
6736 With ARG, turn line truncation on if ARG is positive."
6737   (interactive "P")
6738   (setq truncate-lines
6739         (if (null arg) (not truncate-lines)
6740           (> (prefix-numeric-value arg) 0)))
6741   (redraw-display))
6742
6743 (defun gnus-summary-find-for-reselect ()
6744   "Return the number of an article to stay on across a reselect.
6745 The current article is considered, then following articles, then previous
6746 articles.  An article is sought which is not cancelled and isn't a temporary
6747 insertion from another group.  If there's no such then return a dummy 0."
6748   (let (found)
6749     (dolist (rev '(nil t))
6750       (unless found      ; don't demand the reverse list if we don't need it
6751         (let ((data (gnus-data-find-list
6752                      (gnus-summary-article-number) (gnus-data-list rev))))
6753           (while (and data (not found))
6754             (if (and (< 0 (gnus-data-number (car data)))
6755                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6756                 (setq found (gnus-data-number (car data))))
6757             (setq data (cdr data))))))
6758     (or found 0)))
6759
6760 (defun gnus-summary-reselect-current-group (&optional all rescan)
6761   "Exit and then reselect the current newsgroup.
6762 The prefix argument ALL means to select all articles."
6763   (interactive "P")
6764   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6765     (error "Ephemeral groups can't be reselected"))
6766   (let ((current-subject (gnus-summary-find-for-reselect))
6767         (group gnus-newsgroup-name))
6768     (setq gnus-newsgroup-begin nil)
6769     (gnus-summary-exit nil 'leave-hidden)
6770     ;; We have to adjust the point of group mode buffer because
6771     ;; point was moved to the next unread newsgroup by exiting.
6772     (gnus-summary-jump-to-group group)
6773     (when rescan
6774       (save-excursion
6775         (gnus-group-get-new-news-this-group 1)))
6776     (gnus-group-read-group all t)
6777     (gnus-summary-goto-subject current-subject nil t)))
6778
6779 (defun gnus-summary-rescan-group (&optional all)
6780   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6781   (interactive "P")
6782   (gnus-summary-reselect-current-group all t))
6783
6784 (defun gnus-summary-update-info (&optional non-destructive)
6785   (save-excursion
6786     (let ((group gnus-newsgroup-name))
6787       (when group
6788         (when gnus-newsgroup-kill-headers
6789           (setq gnus-newsgroup-killed
6790                 (gnus-compress-sequence
6791                  (gnus-sorted-union
6792                   (gnus-list-range-intersection
6793                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6794                   gnus-newsgroup-unreads)
6795                  t)))
6796         (unless (listp (cdr gnus-newsgroup-killed))
6797           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6798         (let ((headers gnus-newsgroup-headers))
6799           ;; Set the new ranges of read articles.
6800           (with-current-buffer gnus-group-buffer
6801             (gnus-undo-force-boundary))
6802           (gnus-update-read-articles
6803            group (gnus-sorted-union
6804                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6805           ;; Set the current article marks.
6806           (let ((gnus-newsgroup-scored
6807                  (if (and (not gnus-save-score)
6808                           (not non-destructive))
6809                      nil
6810                    gnus-newsgroup-scored)))
6811             (save-excursion
6812               (gnus-update-marks)))
6813           ;; Do the cross-ref thing.
6814           (when gnus-use-cross-reference
6815             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6816           ;; Do not switch windows but change the buffer to work.
6817           (set-buffer gnus-group-buffer)
6818           (unless (gnus-ephemeral-group-p group)
6819             (gnus-group-update-group group)))))))
6820
6821 (defun gnus-summary-save-newsrc (&optional force)
6822   "Save the current number of read/marked articles in the dribble buffer.
6823 The dribble buffer will then be saved.
6824 If FORCE (the prefix), also save the .newsrc file(s)."
6825   (interactive "P")
6826   (gnus-summary-update-info t)
6827   (if force
6828       (gnus-save-newsrc-file)
6829     (gnus-dribble-save)))
6830
6831 (defun gnus-summary-exit (&optional temporary leave-hidden)
6832   "Exit reading current newsgroup, and then return to group selection mode.
6833 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6834   (interactive)
6835   (gnus-set-global-variables)
6836   (when (gnus-buffer-live-p gnus-article-buffer)
6837     (save-excursion
6838       (set-buffer gnus-article-buffer)
6839       (mm-destroy-parts gnus-article-mime-handles)
6840       ;; Set it to nil for safety reason.
6841       (setq gnus-article-mime-handle-alist nil)
6842       (setq gnus-article-mime-handles nil)))
6843   (gnus-kill-save-kill-buffer)
6844   (gnus-async-halt-prefetch)
6845   (let* ((group gnus-newsgroup-name)
6846          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6847          (gnus-group-is-exiting-p t)
6848          (mode major-mode)
6849          (group-point nil)
6850          (buf (current-buffer)))
6851     (unless quit-config
6852       ;; Do adaptive scoring, and possibly save score files.
6853       (when gnus-newsgroup-adaptive
6854         (gnus-score-adaptive))
6855       (when gnus-use-scoring
6856         (gnus-score-save)))
6857     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6858     ;; If we have several article buffers, we kill them at exit.
6859     (unless gnus-single-article-buffer
6860       (gnus-kill-buffer gnus-article-buffer)
6861       (gnus-kill-buffer gnus-original-article-buffer)
6862       (setq gnus-article-current nil))
6863     (when gnus-use-cache
6864       (gnus-cache-possibly-remove-articles)
6865       (gnus-cache-save-buffers))
6866     (gnus-async-prefetch-remove-group group)
6867     (when gnus-suppress-duplicates
6868       (gnus-dup-enter-articles))
6869     (when gnus-use-trees
6870       (gnus-tree-close group))
6871     (when gnus-use-cache
6872       (gnus-cache-write-active))
6873     ;; Remove entries for this group.
6874     (nnmail-purge-split-history (gnus-group-real-name group))
6875     ;; Make all changes in this group permanent.
6876     (unless quit-config
6877       (gnus-run-hooks 'gnus-exit-group-hook)
6878       (gnus-summary-update-info))
6879     (gnus-close-group group)
6880     ;; Make sure where we were, and go to next newsgroup.
6881     (set-buffer gnus-group-buffer)
6882     (unless quit-config
6883       (gnus-group-jump-to-group group))
6884     (gnus-run-hooks 'gnus-summary-exit-hook)
6885     (unless (or quit-config
6886                 ;; If this group has disappeared from the summary
6887                 ;; buffer, don't skip forwards.
6888                 (not (string= group (gnus-group-group-name))))
6889       (gnus-group-next-unread-group 1))
6890     (setq group-point (point))
6891     (if temporary
6892         nil                             ;Nothing to do.
6893       ;; If we have several article buffers, we kill them at exit.
6894       (unless gnus-single-article-buffer
6895         (gnus-kill-buffer gnus-article-buffer)
6896         (gnus-kill-buffer gnus-original-article-buffer)
6897         (setq gnus-article-current nil))
6898       (set-buffer buf)
6899       (if (not gnus-kill-summary-on-exit)
6900           (progn
6901             (gnus-deaden-summary)
6902             (setq mode nil))
6903         ;; We set all buffer-local variables to nil.  It is unclear why
6904         ;; this is needed, but if we don't, buffer-local variables are
6905         ;; not garbage-collected, it seems.  This would the lead to en
6906         ;; ever-growing Emacs.
6907         (gnus-summary-clear-local-variables)
6908         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6909           (gnus-summary-clear-local-variables))
6910         (when (get-buffer gnus-article-buffer)
6911           (bury-buffer gnus-article-buffer))
6912         ;; Return to group mode buffer.
6913         (when (eq mode 'gnus-summary-mode)
6914           (gnus-kill-buffer buf)))
6915       (setq gnus-current-select-method gnus-select-method)
6916       (set-buffer gnus-group-buffer)
6917       (if quit-config
6918           (gnus-handle-ephemeral-exit quit-config)
6919         (goto-char group-point)
6920         ;; If gnus-group-buffer is already displayed, make sure we also move
6921         ;; the cursor in the window that displays it.
6922         (let ((win (get-buffer-window (current-buffer) 0)))
6923           (if win (set-window-point win (point))))
6924         (unless leave-hidden
6925           (gnus-configure-windows 'group 'force)))
6926       ;; Clear the current group name.
6927       (unless quit-config
6928         (setq gnus-newsgroup-name nil)))))
6929
6930 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6931 (defun gnus-summary-exit-no-update (&optional no-questions)
6932   "Quit reading current newsgroup without updating read article info."
6933   (interactive)
6934   (let* ((group gnus-newsgroup-name)
6935          (gnus-group-is-exiting-p t)
6936          (gnus-group-is-exiting-without-update-p t)
6937          (quit-config (gnus-group-quit-config group)))
6938     (when (or no-questions
6939               gnus-expert-user
6940               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6941       (gnus-async-halt-prefetch)
6942       (run-hooks 'gnus-summary-prepare-exit-hook)
6943       (when (gnus-buffer-live-p gnus-article-buffer)
6944         (save-excursion
6945           (set-buffer gnus-article-buffer)
6946           (mm-destroy-parts gnus-article-mime-handles)
6947           ;; Set it to nil for safety reason.
6948           (setq gnus-article-mime-handle-alist nil)
6949           (setq gnus-article-mime-handles nil)))
6950       ;; If we have several article buffers, we kill them at exit.
6951       (unless gnus-single-article-buffer
6952         (gnus-kill-buffer gnus-article-buffer)
6953         (gnus-kill-buffer gnus-original-article-buffer)
6954         (setq gnus-article-current nil))
6955       (if (not gnus-kill-summary-on-exit)
6956           (gnus-deaden-summary)
6957         (gnus-close-group group)
6958         (gnus-summary-clear-local-variables)
6959         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6960           (gnus-summary-clear-local-variables))
6961         (gnus-kill-buffer gnus-summary-buffer))
6962       (unless gnus-single-article-buffer
6963         (setq gnus-article-current nil))
6964       (when gnus-use-trees
6965         (gnus-tree-close group))
6966       (gnus-async-prefetch-remove-group group)
6967       (when (get-buffer gnus-article-buffer)
6968         (bury-buffer gnus-article-buffer))
6969       ;; Return to the group buffer.
6970       (gnus-configure-windows 'group 'force)
6971       ;; Clear the current group name.
6972       (setq gnus-newsgroup-name nil)
6973       (unless (gnus-ephemeral-group-p group)
6974         (gnus-group-update-group group))
6975       (when (equal (gnus-group-group-name) group)
6976         (gnus-group-next-unread-group 1))
6977       (when quit-config
6978         (gnus-handle-ephemeral-exit quit-config)))))
6979
6980 (defun gnus-handle-ephemeral-exit (quit-config)
6981   "Handle movement when leaving an ephemeral group.
6982 The state which existed when entering the ephemeral is reset."
6983   (if (not (buffer-name (car quit-config)))
6984       (gnus-configure-windows 'group 'force)
6985     (set-buffer (car quit-config))
6986     (cond ((eq major-mode 'gnus-summary-mode)
6987            (gnus-set-global-variables))
6988           ((eq major-mode 'gnus-article-mode)
6989            (save-excursion
6990              ;; The `gnus-summary-buffer' variable may point
6991              ;; to the old summary buffer when using a single
6992              ;; article buffer.
6993              (unless (gnus-buffer-live-p gnus-summary-buffer)
6994                (set-buffer gnus-group-buffer))
6995              (set-buffer gnus-summary-buffer)
6996              (gnus-set-global-variables))))
6997     (if (or (eq (cdr quit-config) 'article)
6998             (eq (cdr quit-config) 'pick))
6999         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7000             (gnus-configure-windows 'pick 'force)
7001           (gnus-configure-windows (cdr quit-config) 'force))
7002       (gnus-configure-windows (cdr quit-config) 'force))
7003     (when (eq major-mode 'gnus-summary-mode)
7004       (gnus-summary-recenter)
7005       (gnus-summary-position-point))))
7006
7007 ;;; Dead summaries.
7008
7009 (defvar gnus-dead-summary-mode-map nil)
7010
7011 (unless gnus-dead-summary-mode-map
7012   (setq gnus-dead-summary-mode-map (make-keymap))
7013   (suppress-keymap gnus-dead-summary-mode-map)
7014   (substitute-key-definition
7015    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7016   (dolist (key '("\C-d" "\r" "\177" [delete]))
7017     (define-key gnus-dead-summary-mode-map
7018       key 'gnus-summary-wake-up-the-dead))
7019   (dolist (key '("q" "Q"))
7020     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7021
7022 (defvar gnus-dead-summary-mode nil
7023   "Minor mode for Gnus summary buffers.")
7024
7025 (defun gnus-dead-summary-mode (&optional arg)
7026   "Minor mode for Gnus summary buffers."
7027   (interactive "P")
7028   (when (eq major-mode 'gnus-summary-mode)
7029     (make-local-variable 'gnus-dead-summary-mode)
7030     (setq gnus-dead-summary-mode
7031           (if (null arg) (not gnus-dead-summary-mode)
7032             (> (prefix-numeric-value arg) 0)))
7033     (when gnus-dead-summary-mode
7034       (add-minor-mode
7035        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7036
7037 (defun gnus-deaden-summary ()
7038   "Make the current summary buffer into a dead summary buffer."
7039   ;; Kill any previous dead summary buffer.
7040   (when (and gnus-dead-summary
7041              (buffer-name gnus-dead-summary))
7042     (with-current-buffer gnus-dead-summary
7043       (when gnus-dead-summary-mode
7044         (kill-buffer (current-buffer)))))
7045   ;; Make this the current dead summary.
7046   (setq gnus-dead-summary (current-buffer))
7047   (gnus-dead-summary-mode 1)
7048   (let ((name (buffer-name)))
7049     (when (string-match "Summary" name)
7050       (rename-buffer
7051        (concat (substring name 0 (match-beginning 0)) "Dead "
7052                (substring name (match-beginning 0)))
7053        t)
7054       (bury-buffer))))
7055
7056 (defun gnus-kill-or-deaden-summary (buffer)
7057   "Kill or deaden the summary BUFFER."
7058   (save-excursion
7059     (when (and (buffer-name buffer)
7060                (not gnus-single-article-buffer))
7061       (with-current-buffer buffer
7062         (gnus-kill-buffer gnus-article-buffer)
7063         (gnus-kill-buffer gnus-original-article-buffer)))
7064     (cond
7065      ;; Kill the buffer.
7066      (gnus-kill-summary-on-exit
7067       (when (and gnus-use-trees
7068                  (gnus-buffer-exists-p buffer))
7069         (save-excursion
7070           (set-buffer buffer)
7071           (gnus-tree-close gnus-newsgroup-name)))
7072       (gnus-kill-buffer buffer))
7073      ;; Deaden the buffer.
7074      ((gnus-buffer-exists-p buffer)
7075       (save-excursion
7076         (set-buffer buffer)
7077         (gnus-deaden-summary))))))
7078
7079 (defun gnus-summary-wake-up-the-dead (&rest args)
7080   "Wake up the dead summary buffer."
7081   (interactive)
7082   (gnus-dead-summary-mode -1)
7083   (let ((name (buffer-name)))
7084     (when (string-match "Dead " name)
7085       (rename-buffer
7086        (concat (substring name 0 (match-beginning 0))
7087                (substring name (match-end 0)))
7088        t)))
7089   (gnus-message 3 "This dead summary is now alive again"))
7090
7091 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7092 (defun gnus-summary-fetch-faq (&optional faq-dir)
7093   "Fetch the FAQ for the current group.
7094 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7095 in."
7096   (interactive
7097    (list
7098     (when current-prefix-arg
7099       (completing-read
7100        "FAQ dir: " (and (listp gnus-group-faq-directory)
7101                         (mapcar 'list
7102                                 gnus-group-faq-directory))))))
7103   (let (gnus-faq-buffer)
7104     (when (setq gnus-faq-buffer
7105                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7106       (gnus-configure-windows 'summary-faq))))
7107
7108 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7109 (defun gnus-summary-describe-group (&optional force)
7110   "Describe the current newsgroup."
7111   (interactive "P")
7112   (gnus-group-describe-group force gnus-newsgroup-name))
7113
7114 (defun gnus-summary-describe-briefly ()
7115   "Describe summary mode commands briefly."
7116   (interactive)
7117   (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")))
7118
7119 ;; Walking around group mode buffer from summary mode.
7120
7121 (defun gnus-summary-next-group (&optional no-article target-group backward)
7122   "Exit current newsgroup and then select next unread newsgroup.
7123 If prefix argument NO-ARTICLE is non-nil, no article is selected
7124 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7125 previous group instead."
7126   (interactive "P")
7127   ;; Stop pre-fetching.
7128   (gnus-async-halt-prefetch)
7129   (let ((current-group gnus-newsgroup-name)
7130         (current-buffer (current-buffer))
7131         entered)
7132     ;; First we semi-exit this group to update Xrefs and all variables.
7133     ;; We can't do a real exit, because the window conf must remain
7134     ;; the same in case the user is prompted for info, and we don't
7135     ;; want the window conf to change before that...
7136     (gnus-summary-exit t)
7137     (while (not entered)
7138       ;; Then we find what group we are supposed to enter.
7139       (set-buffer gnus-group-buffer)
7140       (gnus-group-jump-to-group current-group)
7141       (setq target-group
7142             (or target-group
7143                 (if (eq gnus-keep-same-level 'best)
7144                     (gnus-summary-best-group gnus-newsgroup-name)
7145                   (gnus-summary-search-group backward gnus-keep-same-level))))
7146       (if (not target-group)
7147           ;; There are no further groups, so we return to the group
7148           ;; buffer.
7149           (progn
7150             (gnus-message 5 "Returning to the group buffer")
7151             (setq entered t)
7152             (when (gnus-buffer-live-p current-buffer)
7153               (set-buffer current-buffer)
7154               (gnus-summary-exit))
7155             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7156         ;; We try to enter the target group.
7157         (gnus-group-jump-to-group target-group)
7158         (let ((unreads (gnus-group-group-unread)))
7159           (if (and (or (eq t unreads)
7160                        (and unreads (not (zerop unreads))))
7161                    (gnus-summary-read-group
7162                     target-group nil no-article
7163                     (and (buffer-name current-buffer) current-buffer)
7164                     nil backward))
7165               (setq entered t)
7166             (setq current-group target-group
7167                   target-group nil)))))))
7168
7169 (defun gnus-summary-prev-group (&optional no-article)
7170   "Exit current newsgroup and then select previous unread newsgroup.
7171 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7172   (interactive "P")
7173   (gnus-summary-next-group no-article nil t))
7174
7175 ;; Walking around summary lines.
7176
7177 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7178   "Go to the first subject satisfying any non-nil constraint.
7179 If UNREAD is non-nil, the article should be unread.
7180 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7181 If UNSEEN is non-nil, the article should be unseen.
7182 Returns the article selected or nil if there are no matching articles."
7183   (interactive "P")
7184   (cond
7185    ;; Empty summary.
7186    ((null gnus-newsgroup-data)
7187     (gnus-message 3 "No articles in the group")
7188     nil)
7189    ;; Pick the first article.
7190    ((not (or unread undownloaded unseen))
7191     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7192     (gnus-data-number (car gnus-newsgroup-data)))
7193    ;; Find the first unread article.
7194    (t
7195     (let ((data gnus-newsgroup-data))
7196       (while (and data
7197                   (let ((num (gnus-data-number (car data))))
7198                     (or (memq num gnus-newsgroup-unfetched)
7199                         (not (or (and unread
7200                                       (memq num gnus-newsgroup-unreads))
7201                                  (and undownloaded
7202                                       (memq num gnus-newsgroup-undownloaded))
7203                                  (and unseen
7204                                       (memq num gnus-newsgroup-unseen)))))))
7205         (setq data (cdr data)))
7206       (prog1
7207           (if data
7208               (progn
7209                 (goto-char (gnus-data-pos (car data)))
7210                 (gnus-data-number (car data)))
7211             (gnus-message 3 "No more%s articles"
7212                           (let* ((r (when unread " unread"))
7213                                  (d (when undownloaded " undownloaded"))
7214                                  (s (when unseen " unseen"))
7215                                  (l (delq nil (list r d s))))
7216                             (cond ((= 3 (length l))
7217                                    (concat r "," d ", or" s))
7218                                   ((= 2 (length l))
7219                                    (concat (car l) ", or" (cadr l)))
7220                                   ((= 1 (length l))
7221                                    (car l))
7222                                   (t
7223                                    ""))))
7224             nil
7225             )
7226         (gnus-summary-position-point))))))
7227
7228 (defun gnus-summary-next-subject (n &optional unread dont-display)
7229   "Go to next N'th summary line.
7230 If N is negative, go to the previous N'th subject line.
7231 If UNREAD is non-nil, only unread articles are selected.
7232 The difference between N and the actual number of steps taken is
7233 returned."
7234   (interactive "p")
7235   (let ((backward (< n 0))
7236         (n (abs n)))
7237     (while (and (> n 0)
7238                 (if backward
7239                     (gnus-summary-find-prev unread)
7240                   (gnus-summary-find-next unread)))
7241       (unless (zerop (setq n (1- n)))
7242         (gnus-summary-show-thread)))
7243     (when (/= 0 n)
7244       (gnus-message 7 "No more%s articles"
7245                     (if unread " unread" "")))
7246     (unless dont-display
7247       (gnus-summary-recenter)
7248       (gnus-summary-position-point))
7249     n))
7250
7251 (defun gnus-summary-next-unread-subject (n)
7252   "Go to next N'th unread summary line."
7253   (interactive "p")
7254   (gnus-summary-next-subject n t))
7255
7256 (defun gnus-summary-prev-subject (n &optional unread)
7257   "Go to previous N'th summary line.
7258 If optional argument UNREAD is non-nil, only unread article is selected."
7259   (interactive "p")
7260   (gnus-summary-next-subject (- n) unread))
7261
7262 (defun gnus-summary-prev-unread-subject (n)
7263   "Go to previous N'th unread summary line."
7264   (interactive "p")
7265   (gnus-summary-next-subject (- n) t))
7266
7267 (defun gnus-summary-goto-subjects (articles)
7268   "Insert the subject header for ARTICLES in the current buffer."
7269   (save-excursion
7270     (dolist (article articles)
7271       (gnus-summary-goto-subject article t)))
7272   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7273   (gnus-summary-position-point))
7274
7275 (defun gnus-summary-goto-subject (article &optional force silent)
7276   "Go the subject line of ARTICLE.
7277 If FORCE, also allow jumping to articles not currently shown."
7278   (interactive "nArticle number: ")
7279   (unless (numberp article)
7280     (error "Article %s is not a number" article))
7281   (let ((b (point))
7282         (data (gnus-data-find article)))
7283     ;; We read in the article if we have to.
7284     (and (not data)
7285          force
7286          (gnus-summary-insert-subject
7287           article
7288           (if (or (numberp force) (vectorp force)) force)
7289           t)
7290          (setq data (gnus-data-find article)))
7291     (goto-char b)
7292     (if (not data)
7293         (progn
7294           (unless silent
7295             (gnus-message 3 "Can't find article %d" article))
7296           nil)
7297       (let ((pt (gnus-data-pos data)))
7298         (goto-char pt)
7299         (gnus-summary-set-article-display-arrow pt))
7300       (gnus-summary-position-point)
7301       article)))
7302
7303 ;; Walking around summary lines with displaying articles.
7304
7305 (defun gnus-summary-expand-window (&optional arg)
7306   "Make the summary buffer take up the entire Emacs frame.
7307 Given a prefix, will force an `article' buffer configuration."
7308   (interactive "P")
7309   (if arg
7310       (gnus-configure-windows 'article 'force)
7311     (gnus-configure-windows 'summary 'force)))
7312
7313 (defun gnus-summary-display-article (article &optional all-header)
7314   "Display ARTICLE in article buffer."
7315   (when (gnus-buffer-live-p gnus-article-buffer)
7316     (with-current-buffer gnus-article-buffer
7317       (mm-enable-multibyte)))
7318   (gnus-set-global-variables)
7319   (when (gnus-buffer-live-p gnus-article-buffer)
7320     (with-current-buffer gnus-article-buffer
7321       (setq gnus-article-charset gnus-newsgroup-charset)
7322       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7323       (mm-enable-multibyte)))
7324   (if (null article)
7325       nil
7326     (prog1
7327         (if gnus-summary-display-article-function
7328             (funcall gnus-summary-display-article-function article all-header)
7329           (gnus-article-prepare article all-header))
7330       (gnus-run-hooks 'gnus-select-article-hook)
7331       (when (and gnus-current-article
7332                  (not (zerop gnus-current-article)))
7333         (gnus-summary-goto-subject gnus-current-article))
7334       (gnus-summary-recenter)
7335       (when (and gnus-use-trees gnus-show-threads)
7336         (gnus-possibly-generate-tree article)
7337         (gnus-highlight-selected-tree article))
7338       ;; Successfully display article.
7339       (gnus-article-set-window-start
7340        (cdr (assq article gnus-newsgroup-bookmarks))))))
7341
7342 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7343   "Select the current article.
7344 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7345 non-nil, the article will be re-fetched even if it already present in
7346 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7347 be displayed."
7348   ;; Make sure we are in the summary buffer to work around bbdb bug.
7349   (unless (eq major-mode 'gnus-summary-mode)
7350     (set-buffer gnus-summary-buffer))
7351   (let ((article (or article (gnus-summary-article-number)))
7352         (all-headers (not (not all-headers))) ;Must be t or nil.
7353         gnus-summary-display-article-function)
7354     (and (not pseudo)
7355          (gnus-summary-article-pseudo-p article)
7356          (error "This is a pseudo-article"))
7357     (save-excursion
7358       (set-buffer gnus-summary-buffer)
7359       (if (or (and gnus-single-article-buffer
7360                    (or (null gnus-current-article)
7361                        (null gnus-article-current)
7362                        (null (get-buffer gnus-article-buffer))
7363                        (not (eq article (cdr gnus-article-current)))
7364                        (not (equal (car gnus-article-current)
7365                                    gnus-newsgroup-name))))
7366               (and (not gnus-single-article-buffer)
7367                    (or (null gnus-current-article)
7368                        (not (eq gnus-current-article article))))
7369               force)
7370           ;; The requested article is different from the current article.
7371           (progn
7372             (gnus-summary-display-article article all-headers)
7373             (when (gnus-buffer-live-p gnus-article-buffer)
7374               (with-current-buffer gnus-article-buffer
7375                 (if (not gnus-article-decoded-p) ;; a local variable
7376                     (mm-disable-multibyte))))
7377             (gnus-article-set-window-start
7378              (cdr (assq article gnus-newsgroup-bookmarks)))
7379             article)
7380         'old))))
7381
7382 (defun gnus-summary-force-verify-and-decrypt ()
7383   "Display buttons for signed/encrypted parts and verify/decrypt them."
7384   (interactive)
7385   (let ((mm-verify-option 'known)
7386         (mm-decrypt-option 'known)
7387         (gnus-article-emulate-mime t)
7388         (gnus-buttonized-mime-types (append (list "multipart/signed"
7389                                                   "multipart/encrypted")
7390                                             gnus-buttonized-mime-types)))
7391     (gnus-summary-select-article nil 'force)))
7392
7393 (defun gnus-summary-set-current-mark (&optional current-mark)
7394   "Obsolete function."
7395   nil)
7396
7397 (defun gnus-summary-next-article (&optional unread subject backward push)
7398   "Select the next article.
7399 If UNREAD, only unread articles are selected.
7400 If SUBJECT, only articles with SUBJECT are selected.
7401 If BACKWARD, the previous article is selected instead of the next."
7402   (interactive "P")
7403   (cond
7404    ;; Is there such an article?
7405    ((and (gnus-summary-search-forward unread subject backward)
7406          (or (gnus-summary-display-article (gnus-summary-article-number))
7407              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7408     (gnus-summary-position-point))
7409    ;; If not, we try the first unread, if that is wanted.
7410    ((and subject
7411          gnus-auto-select-same
7412          (gnus-summary-first-unread-article))
7413     (gnus-summary-position-point)
7414     (gnus-message 6 "Wrapped"))
7415    ;; Try to get next/previous article not displayed in this group.
7416    ((and gnus-auto-extend-newsgroup
7417          (not unread) (not subject))
7418     (gnus-summary-goto-article
7419      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7420      nil (count-lines (point-min) (point))))
7421    ;; Go to next/previous group.
7422    (t
7423     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7424       (gnus-summary-jump-to-group gnus-newsgroup-name))
7425     (let ((cmd last-command-char)
7426           (point
7427            (with-current-buffer gnus-group-buffer
7428              (point)))
7429           (group
7430            (if (eq gnus-keep-same-level 'best)
7431                (gnus-summary-best-group gnus-newsgroup-name)
7432              (gnus-summary-search-group backward gnus-keep-same-level))))
7433       ;; For some reason, the group window gets selected.  We change
7434       ;; it back.
7435       (select-window (get-buffer-window (current-buffer)))
7436       ;; Select next unread newsgroup automagically.
7437       (cond
7438        ((or (not gnus-auto-select-next)
7439             (not cmd))
7440         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7441        ((or (eq gnus-auto-select-next 'quietly)
7442             (and (eq gnus-auto-select-next 'slightly-quietly)
7443                  push)
7444             (and (eq gnus-auto-select-next 'almost-quietly)
7445                  (gnus-summary-last-article-p)))
7446         ;; Select quietly.
7447         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7448             (gnus-summary-exit)
7449           (gnus-message 7 "No more%s articles (%s)..."
7450                         (if unread " unread" "")
7451                         (if group (concat "selecting " group)
7452                           "exiting"))
7453           (gnus-summary-next-group nil group backward)))
7454        (t
7455         (when (gnus-key-press-event-p last-input-event)
7456           (gnus-summary-walk-group-buffer
7457            gnus-newsgroup-name cmd unread backward point))))))))
7458
7459 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7460   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7461                       (?\C-p (gnus-group-prev-unread-group 1))))
7462         (cursor-in-echo-area t)
7463         keve key group ended prompt)
7464     (save-excursion
7465       (set-buffer gnus-group-buffer)
7466       (goto-char start)
7467       (setq group
7468             (if (eq gnus-keep-same-level 'best)
7469                 (gnus-summary-best-group gnus-newsgroup-name)
7470               (gnus-summary-search-group backward gnus-keep-same-level))))
7471     (while (not ended)
7472       (setq prompt
7473             (format
7474              "No more%s articles%s " (if unread " unread" "")
7475              (if (and group
7476                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7477                  (format " (Type %s for %s [%s])"
7478                          (single-key-description cmd)
7479                          (gnus-group-decoded-name group)
7480                          (gnus-group-unread group))
7481                (format " (Type %s to exit %s)"
7482                        (single-key-description cmd)
7483                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7484       ;; Confirm auto selection.
7485       (setq key (car (setq keve (gnus-read-event-char prompt)))
7486             ended t)
7487       (cond
7488        ((assq key keystrokes)
7489         (let ((obuf (current-buffer)))
7490           (switch-to-buffer gnus-group-buffer)
7491           (when group
7492             (gnus-group-jump-to-group group))
7493           (eval (cadr (assq key keystrokes)))
7494           (setq group (gnus-group-group-name))
7495           (switch-to-buffer obuf))
7496         (setq ended nil))
7497        ((equal key cmd)
7498         (if (or (not group)
7499                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7500             (gnus-summary-exit)
7501           (gnus-summary-next-group nil group backward)))
7502        (t
7503         (push (cdr keve) unread-command-events))))))
7504
7505 (defun gnus-summary-next-unread-article ()
7506   "Select unread article after current one."
7507   (interactive)
7508   (gnus-summary-next-article
7509    (or (not (eq gnus-summary-goto-unread 'never))
7510        (gnus-summary-last-article-p (gnus-summary-article-number)))
7511    (and gnus-auto-select-same
7512         (gnus-summary-article-subject))))
7513
7514 (defun gnus-summary-prev-article (&optional unread subject)
7515   "Select the article after the current one.
7516 If UNREAD is non-nil, only unread articles are selected."
7517   (interactive "P")
7518   (gnus-summary-next-article unread subject t))
7519
7520 (defun gnus-summary-prev-unread-article ()
7521   "Select unread article before current one."
7522   (interactive)
7523   (gnus-summary-prev-article
7524    (or (not (eq gnus-summary-goto-unread 'never))
7525        (gnus-summary-first-article-p (gnus-summary-article-number)))
7526    (and gnus-auto-select-same
7527         (gnus-summary-article-subject))))
7528
7529 (defun gnus-summary-next-page (&optional lines circular stop)
7530   "Show next page of the selected article.
7531 If at the end of the current article, select the next article.
7532 LINES says how many lines should be scrolled up.
7533
7534 If CIRCULAR is non-nil, go to the start of the article instead of
7535 selecting the next article when reaching the end of the current
7536 article.
7537
7538 If STOP is non-nil, just stop when reaching the end of the message.
7539
7540 Also see the variable `gnus-article-skip-boring'."
7541   (interactive "P")
7542   (setq gnus-summary-buffer (current-buffer))
7543   (gnus-set-global-variables)
7544   (let ((article (gnus-summary-article-number))
7545         (article-window (get-buffer-window gnus-article-buffer t))
7546         endp)
7547     ;; If the buffer is empty, we have no article.
7548     (unless article
7549       (error "No article to select"))
7550     (gnus-configure-windows 'article)
7551     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7552         (if (and (eq gnus-summary-goto-unread 'never)
7553                  (not (gnus-summary-last-article-p article)))
7554             (gnus-summary-next-article)
7555           (gnus-summary-next-unread-article))
7556       (if (or (null gnus-current-article)
7557               (null gnus-article-current)
7558               (/= article (cdr gnus-article-current))
7559               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7560           ;; Selected subject is different from current article's.
7561           (gnus-summary-display-article article)
7562         (when article-window
7563           (gnus-eval-in-buffer-window gnus-article-buffer
7564             (setq endp (or (gnus-article-next-page lines)
7565                            (gnus-article-only-boring-p))))
7566           (when endp
7567             (cond (stop
7568                    (gnus-message 3 "End of message"))
7569                   (circular
7570                    (gnus-summary-beginning-of-article))
7571                   (lines
7572                    (gnus-message 3 "End of message"))
7573                   ((null lines)
7574                    (if (and (eq gnus-summary-goto-unread 'never)
7575                             (not (gnus-summary-last-article-p article)))
7576                        (gnus-summary-next-article)
7577                      (gnus-summary-next-unread-article))))))))
7578     (gnus-summary-recenter)
7579     (gnus-summary-position-point)))
7580
7581 (defun gnus-summary-prev-page (&optional lines move)
7582   "Show previous page of selected article.
7583 Argument LINES specifies lines to be scrolled down.
7584 If MOVE, move to the previous unread article if point is at
7585 the beginning of the buffer."
7586   (interactive "P")
7587   (let ((article (gnus-summary-article-number))
7588         (article-window (get-buffer-window gnus-article-buffer t))
7589         endp)
7590     (gnus-configure-windows 'article)
7591     (if (or (null gnus-current-article)
7592             (null gnus-article-current)
7593             (/= article (cdr gnus-article-current))
7594             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7595         ;; Selected subject is different from current article's.
7596         (gnus-summary-display-article article)
7597       (gnus-summary-recenter)
7598       (when article-window
7599         (gnus-eval-in-buffer-window gnus-article-buffer
7600           (setq endp (gnus-article-prev-page lines)))
7601         (when (and move endp)
7602           (cond (lines
7603                  (gnus-message 3 "Beginning of message"))
7604                 ((null lines)
7605                  (if (and (eq gnus-summary-goto-unread 'never)
7606                           (not (gnus-summary-first-article-p article)))
7607                      (gnus-summary-prev-article)
7608                    (gnus-summary-prev-unread-article))))))))
7609   (gnus-summary-position-point))
7610
7611 (defun gnus-summary-prev-page-or-article (&optional lines)
7612   "Show previous page of selected article.
7613 Argument LINES specifies lines to be scrolled down.
7614 If at the beginning of the article, go to the next article."
7615   (interactive "P")
7616   (gnus-summary-prev-page lines t))
7617
7618 (defun gnus-summary-scroll-up (lines)
7619   "Scroll up (or down) one line current article.
7620 Argument LINES specifies lines to be scrolled up (or down if negative)."
7621   (interactive "p")
7622   (gnus-configure-windows 'article)
7623   (gnus-summary-show-thread)
7624   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7625     (gnus-eval-in-buffer-window gnus-article-buffer
7626       (cond ((> lines 0)
7627              (when (gnus-article-next-page lines)
7628                (gnus-message 3 "End of message")))
7629             ((< lines 0)
7630              (gnus-article-prev-page (- lines))))))
7631   (gnus-summary-recenter)
7632   (gnus-summary-position-point))
7633
7634 (defun gnus-summary-scroll-down (lines)
7635   "Scroll down (or up) one line current article.
7636 Argument LINES specifies lines to be scrolled down (or up if negative)."
7637   (interactive "p")
7638   (gnus-summary-scroll-up (- lines)))
7639
7640 (defun gnus-summary-next-same-subject ()
7641   "Select next article which has the same subject as current one."
7642   (interactive)
7643   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7644
7645 (defun gnus-summary-prev-same-subject ()
7646   "Select previous article which has the same subject as current one."
7647   (interactive)
7648   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7649
7650 (defun gnus-summary-next-unread-same-subject ()
7651   "Select next unread article which has the same subject as current one."
7652   (interactive)
7653   (gnus-summary-next-article t (gnus-summary-article-subject)))
7654
7655 (defun gnus-summary-prev-unread-same-subject ()
7656   "Select previous unread article which has the same subject as current one."
7657   (interactive)
7658   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7659
7660 (defun gnus-summary-first-unread-article ()
7661   "Select the first unread article.
7662 Return nil if there are no unread articles."
7663   (interactive)
7664   (prog1
7665       (when (gnus-summary-first-subject t)
7666         (gnus-summary-show-thread)
7667         (gnus-summary-first-subject t)
7668         (gnus-summary-display-article (gnus-summary-article-number)))
7669     (gnus-summary-position-point)))
7670
7671 (defun gnus-summary-first-unread-subject ()
7672   "Place the point on the subject line of the first unread article.
7673 Return nil if there are no unread articles."
7674   (interactive)
7675   (prog1
7676       (when (gnus-summary-first-subject t)
7677         (gnus-summary-show-thread)
7678         (gnus-summary-first-subject t))
7679     (gnus-summary-position-point)))
7680
7681 (defun gnus-summary-first-unseen-subject ()
7682   "Place the point on the subject line of the first unseen article.
7683 Return nil if there are no unseen articles."
7684   (interactive)
7685   (prog1
7686       (when (gnus-summary-first-subject nil nil t)
7687         (gnus-summary-show-thread)
7688         (gnus-summary-first-subject nil nil t))
7689     (gnus-summary-position-point)))
7690
7691 (defun gnus-summary-first-unseen-or-unread-subject ()
7692   "Place the point on the subject line of the first unseen article or,
7693 if all article have been seen, on the subject line of the first unread
7694 article."
7695   (interactive)
7696   (prog1
7697       (unless (when (gnus-summary-first-subject nil nil t)
7698                 (gnus-summary-show-thread)
7699                 (gnus-summary-first-subject nil nil t))
7700         (when (gnus-summary-first-subject t)
7701           (gnus-summary-show-thread)
7702           (gnus-summary-first-subject t)))
7703     (gnus-summary-position-point)))
7704
7705 (defun gnus-summary-first-article ()
7706   "Select the first article.
7707 Return nil if there are no articles."
7708   (interactive)
7709   (prog1
7710       (when (gnus-summary-first-subject)
7711         (gnus-summary-show-thread)
7712         (gnus-summary-first-subject)
7713         (gnus-summary-display-article (gnus-summary-article-number)))
7714     (gnus-summary-position-point)))
7715
7716 (defun gnus-summary-best-unread-article (&optional arg)
7717   "Select the unread article with the highest score.
7718 If given a prefix argument, select the next unread article that has a
7719 score higher than the default score."
7720   (interactive "P")
7721   (let ((article (if arg
7722                      (gnus-summary-better-unread-subject)
7723                    (gnus-summary-best-unread-subject))))
7724     (if article
7725         (gnus-summary-goto-article article)
7726       (error "No unread articles"))))
7727
7728 (defun gnus-summary-best-unread-subject ()
7729   "Select the unread subject with the highest score."
7730   (interactive)
7731   (let ((best -1000000)
7732         (data gnus-newsgroup-data)
7733         article score)
7734     (while data
7735       (and (gnus-data-unread-p (car data))
7736            (> (setq score
7737                     (gnus-summary-article-score (gnus-data-number (car data))))
7738               best)
7739            (setq best score
7740                  article (gnus-data-number (car data))))
7741       (setq data (cdr data)))
7742     (when article
7743       (gnus-summary-goto-subject article))
7744     (gnus-summary-position-point)
7745     article))
7746
7747 (defun gnus-summary-better-unread-subject ()
7748   "Select the first unread subject that has a score over the default score."
7749   (interactive)
7750   (let ((data gnus-newsgroup-data)
7751         article score)
7752     (while (and (setq article (gnus-data-number (car data)))
7753                 (or (gnus-data-read-p (car data))
7754                     (not (> (gnus-summary-article-score article)
7755                             gnus-summary-default-score))))
7756       (setq data (cdr data)))
7757     (when article
7758       (gnus-summary-goto-subject article))
7759     (gnus-summary-position-point)
7760     article))
7761
7762 (defun gnus-summary-last-subject ()
7763   "Go to the last displayed subject line in the group."
7764   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7765     (when article
7766       (gnus-summary-goto-subject article))))
7767
7768 (defun gnus-summary-goto-article (article &optional all-headers force)
7769   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7770 If ALL-HEADERS is non-nil, no header lines are hidden.
7771 If FORCE, go to the article even if it isn't displayed.  If FORCE
7772 is a number, it is the line the article is to be displayed on."
7773   (interactive
7774    (list
7775     (completing-read
7776      "Article number or Message-ID: "
7777      (mapcar (lambda (number) (list (int-to-string number)))
7778              gnus-newsgroup-limit))
7779     current-prefix-arg
7780     t))
7781   (prog1
7782       (if (and (stringp article)
7783                (string-match "@\\|%40" article))
7784           (gnus-summary-refer-article article)
7785         (when (stringp article)
7786           (setq article (string-to-number article)))
7787         (if (gnus-summary-goto-subject article force)
7788             (gnus-summary-display-article article all-headers)
7789           (gnus-message 4 "Couldn't go to article %s" article) nil))
7790     (gnus-summary-position-point)))
7791
7792 (defun gnus-summary-goto-last-article ()
7793   "Go to the previously read article."
7794   (interactive)
7795   (prog1
7796       (when gnus-last-article
7797         (gnus-summary-goto-article gnus-last-article nil t))
7798     (gnus-summary-position-point)))
7799
7800 (defun gnus-summary-pop-article (number)
7801   "Pop one article off the history and go to the previous.
7802 NUMBER articles will be popped off."
7803   (interactive "p")
7804   (let (to)
7805     (setq gnus-newsgroup-history
7806           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7807     (if to
7808         (gnus-summary-goto-article (car to) nil t)
7809       (error "Article history empty")))
7810   (gnus-summary-position-point))
7811
7812 ;; Summary commands and functions for limiting the summary buffer.
7813
7814 (defun gnus-summary-limit-to-articles (n)
7815   "Limit the summary buffer to the next N articles.
7816 If not given a prefix, use the process marked articles instead."
7817   (interactive "P")
7818   (prog1
7819       (let ((articles (gnus-summary-work-articles n)))
7820         (setq gnus-newsgroup-processable nil)
7821         (gnus-summary-limit articles))
7822     (gnus-summary-position-point)))
7823
7824 (defun gnus-summary-pop-limit (&optional total)
7825   "Restore the previous limit.
7826 If given a prefix, remove all limits."
7827   (interactive "P")
7828   (when total
7829     (setq gnus-newsgroup-limits
7830           (list (mapcar (lambda (h) (mail-header-number h))
7831                         gnus-newsgroup-headers))))
7832   (unless gnus-newsgroup-limits
7833     (error "No limit to pop"))
7834   (prog1
7835       (gnus-summary-limit nil 'pop)
7836     (gnus-summary-position-point)))
7837
7838 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7839   "Limit the summary buffer to articles that have subjects that match a regexp.
7840 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7841   (interactive
7842    (list (read-string (if current-prefix-arg
7843                           "Exclude subject (regexp): "
7844                         "Limit to subject (regexp): "))
7845          nil current-prefix-arg))
7846   (unless header
7847     (setq header "subject"))
7848   (when (not (equal "" subject))
7849     (prog1
7850         (let ((articles (gnus-summary-find-matching
7851                          (or header "subject") subject 'all nil nil
7852                          not-matching)))
7853           (unless articles
7854             (error "Found no matches for \"%s\"" subject))
7855           (gnus-summary-limit articles))
7856       (gnus-summary-position-point))))
7857
7858 (defun gnus-summary-limit-to-author (from &optional not-matching)
7859   "Limit the summary buffer to articles that have authors that match a regexp.
7860 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7861   (interactive
7862    (list (read-string (if current-prefix-arg
7863                           "Exclude author (regexp): "
7864                         "Limit to author (regexp): "))
7865          current-prefix-arg))
7866   (gnus-summary-limit-to-subject from "from" not-matching))
7867
7868 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7869   "Limit the summary buffer to articles with the given RECIPIENT.
7870
7871 If NOT-MATCHING, exclude RECIPIENT.
7872
7873 To and Cc headers are checked.  You need to include them in
7874 `nnmail-extra-headers'."
7875   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7876   (interactive
7877    (list (read-string (format "%s recipient (regexp): "
7878                               (if current-prefix-arg "Exclude" "Limit to")))
7879          current-prefix-arg))
7880   (when (not (equal "" recipient))
7881     (prog1 (let* ((to
7882                    (if (memq 'To nnmail-extra-headers)
7883                        (gnus-summary-find-matching
7884                         (cons 'extra 'To) recipient 'all nil nil
7885                         not-matching)
7886                      (gnus-message
7887                       1 "`To' isn't present in `nnmail-extra-headers'")
7888                      (sit-for 1)
7889                      nil))
7890                   (cc
7891                    (if (memq 'Cc nnmail-extra-headers)
7892                        (gnus-summary-find-matching
7893                         (cons 'extra 'Cc) recipient 'all nil nil
7894                         not-matching)
7895                      (gnus-message
7896                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7897                      (sit-for 1)
7898                      nil))
7899                   (articles
7900                    (if not-matching
7901                        ;; We need the numbers that are in both lists:
7902                        (mapcar (lambda (a)
7903                                  (and (memq a to) a))
7904                                cc)
7905                      (nconc to cc))))
7906              (unless articles
7907                (error "Found no matches for \"%s\"" recipient))
7908              (gnus-summary-limit articles))
7909       (gnus-summary-position-point))))
7910
7911 (defun gnus-summary-limit-to-age (age &optional younger-p)
7912   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7913 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7914 articles that are younger than AGE days."
7915   (interactive
7916    (let ((younger current-prefix-arg)
7917          (days-got nil)
7918          days)
7919      (while (not days-got)
7920        (setq days (if younger
7921                       (read-string "Limit to articles younger than (in days, older when negative): ")
7922                     (read-string
7923                      "Limit to articles older than (in days, younger when negative): ")))
7924        (when (> (length days) 0)
7925          (setq days (read days)))
7926        (if (numberp days)
7927            (progn
7928              (setq days-got t)
7929              (when (< days 0)
7930                (setq younger (not younger))
7931                (setq days (* days -1))))
7932          (message "Please enter a number.")
7933          (sleep-for 1)))
7934      (list days younger)))
7935   (prog1
7936       (let ((data gnus-newsgroup-data)
7937             (cutoff (days-to-time age))
7938             articles d date is-younger)
7939         (while (setq d (pop data))
7940           (when (and (vectorp (gnus-data-header d))
7941                      (setq date (mail-header-date (gnus-data-header d))))
7942             (setq is-younger (time-less-p
7943                               (time-since (condition-case ()
7944                                               (date-to-time date)
7945                                             (error '(0 0))))
7946                               cutoff))
7947             (when (if younger-p
7948                       is-younger
7949                     (not is-younger))
7950               (push (gnus-data-number d) articles))))
7951         (gnus-summary-limit (nreverse articles)))
7952     (gnus-summary-position-point)))
7953
7954 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7955   "Limit the summary buffer to articles that match an 'extra' header."
7956   (interactive
7957    (let ((header
7958           (intern
7959            (gnus-completing-read-with-default
7960             (symbol-name (car gnus-extra-headers))
7961             (if current-prefix-arg
7962                 "Exclude extra header"
7963               "Limit extra header")
7964             (mapcar (lambda (x)
7965                       (cons (symbol-name x) x))
7966                     gnus-extra-headers)
7967             nil
7968             t))))
7969      (list header
7970            (read-string (format "%s header %s (regexp): "
7971                                 (if current-prefix-arg "Exclude" "Limit to")
7972                                 header))
7973            current-prefix-arg)))
7974   (when (not (equal "" regexp))
7975     (prog1
7976         (let ((articles (gnus-summary-find-matching
7977                          (cons 'extra header) regexp 'all nil nil
7978                          not-matching)))
7979           (unless articles
7980             (error "Found no matches for \"%s\"" regexp))
7981           (gnus-summary-limit articles))
7982       (gnus-summary-position-point))))
7983
7984 (defun gnus-summary-limit-to-display-predicate ()
7985   "Limit the summary buffer to the predicated in the `display' group parameter."
7986   (interactive)
7987   (unless gnus-newsgroup-display
7988     (error "There is no `display' group parameter"))
7989   (let (articles)
7990     (dolist (number gnus-newsgroup-articles)
7991       (when (funcall gnus-newsgroup-display)
7992         (push number articles)))
7993     (gnus-summary-limit articles))
7994   (gnus-summary-position-point))
7995
7996 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7997 (make-obsolete
7998  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7999
8000 (defun gnus-summary-limit-to-unread (&optional all)
8001   "Limit the summary buffer to articles that are not marked as read.
8002 If ALL is non-nil, limit strictly to unread articles."
8003   (interactive "P")
8004   (if all
8005       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8006     (gnus-summary-limit-to-marks
8007      ;; Concat all the marks that say that an article is read and have
8008      ;; those removed.
8009      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8010            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8011            gnus-low-score-mark gnus-expirable-mark
8012            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8013            gnus-duplicate-mark gnus-souped-mark)
8014      'reverse)))
8015
8016 (defun gnus-summary-limit-to-bodies (match &optional reverse)
8017   "Limit the summary buffer to articles that have bodies that match MATCH.
8018 If REVERSE (the prefix), limit to articles that don't match."
8019   (interactive "sMatch body (regexp): \nP")
8020   (let ((articles nil)
8021         (gnus-select-article-hook nil)  ;Disable hook.
8022         (gnus-article-prepare-hook nil)
8023         (gnus-use-article-prefetch nil)
8024         (gnus-keep-backlog nil)
8025         (gnus-break-pages nil)
8026         (gnus-summary-display-arrow nil)
8027         (gnus-updated-mode-lines nil)
8028         (gnus-auto-center-summary nil)
8029         (gnus-display-mime-function nil))
8030     (dolist (data gnus-newsgroup-data)
8031       (let (gnus-mark-article-hook)
8032         (gnus-summary-select-article t t nil (gnus-data-number data)))
8033       (save-excursion
8034         (set-buffer gnus-article-buffer)
8035         (article-goto-body)
8036         (let* ((case-fold-search t)
8037                (found (re-search-forward match nil t)))
8038           (when (or (and found
8039                          (not reverse))
8040                     (and (not found)
8041                          reverse))
8042             (push (gnus-data-number data) articles)))))
8043     (if (not articles)
8044         (message "No messages matched")
8045       (gnus-summary-limit articles)))
8046   (gnus-summary-position-point))
8047
8048 (defun gnus-summary-limit-to-replied (&optional unreplied)
8049   "Limit the summary buffer to replied articles.
8050 If UNREPLIED (the prefix), limit to unreplied articles."
8051   (interactive "P")
8052   (if unreplied
8053       (gnus-summary-limit
8054        (gnus-set-difference gnus-newsgroup-articles
8055         gnus-newsgroup-replied))
8056     (gnus-summary-limit gnus-newsgroup-replied))
8057   (gnus-summary-position-point))
8058
8059 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8060 (make-obsolete 'gnus-summary-delete-marked-with
8061                'gnus-summary-limit-exclude-marks)
8062
8063 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8064   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8065 If REVERSE, limit the summary buffer to articles that are marked
8066 with MARKS.  MARKS can either be a string of marks or a list of marks.
8067 Returns how many articles were removed."
8068   (interactive "sMarks: ")
8069   (gnus-summary-limit-to-marks marks t))
8070
8071 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8072   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8073 If REVERSE (the prefix), limit the summary buffer to articles that are
8074 not marked with MARKS.  MARKS can either be a string of marks or a
8075 list of marks.
8076 Returns how many articles were removed."
8077   (interactive "sMarks: \nP")
8078   (prog1
8079       (let ((data gnus-newsgroup-data)
8080             (marks (if (listp marks) marks
8081                      (append marks nil))) ; Transform to list.
8082             articles)
8083         (while data
8084           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8085                   (memq (gnus-data-mark (car data)) marks))
8086             (push (gnus-data-number (car data)) articles))
8087           (setq data (cdr data)))
8088         (gnus-summary-limit articles))
8089     (gnus-summary-position-point)))
8090
8091 (defun gnus-summary-limit-to-score (score)
8092   "Limit to articles with score at or above SCORE."
8093   (interactive "NLimit to articles with score of at least: ")
8094   (let ((data gnus-newsgroup-data)
8095         articles)
8096     (while data
8097       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8098                 score)
8099         (push (gnus-data-number (car data)) articles))
8100       (setq data (cdr data)))
8101     (prog1
8102         (gnus-summary-limit articles)
8103       (gnus-summary-position-point))))
8104
8105 (defun gnus-summary-limit-to-unseen ()
8106   "Limit to unseen articles."
8107   (interactive)
8108   (prog1
8109       (gnus-summary-limit gnus-newsgroup-unseen)
8110     (gnus-summary-position-point)))
8111
8112 (defun gnus-summary-limit-include-thread (id)
8113   "Display all the hidden articles that is in the thread with ID in it.
8114 When called interactively, ID is the Message-ID of the current
8115 article."
8116   (interactive (list (mail-header-id (gnus-summary-article-header))))
8117   (let ((articles (gnus-articles-in-thread
8118                    (gnus-id-to-thread (gnus-root-id id)))))
8119     (prog1
8120         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8121       (gnus-summary-limit-include-matching-articles
8122        "subject"
8123        (regexp-quote (gnus-simplify-subject-re
8124                       (mail-header-subject (gnus-id-to-header id)))))
8125       (gnus-summary-position-point))))
8126
8127 (defun gnus-summary-limit-include-matching-articles (header regexp)
8128   "Display all the hidden articles that have HEADERs that match REGEXP."
8129   (interactive (list (read-string "Match on header: ")
8130                      (read-string "Regexp: ")))
8131   (let ((articles (gnus-find-matching-articles header regexp)))
8132     (prog1
8133         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8134       (gnus-summary-position-point))))
8135
8136 (defun gnus-summary-insert-dormant-articles ()
8137   "Insert all the dormant articles for this group into the current buffer."
8138   (interactive)
8139   (let ((gnus-verbose (max 6 gnus-verbose)))
8140     (if (not gnus-newsgroup-dormant)
8141         (gnus-message 3 "No cached articles for this group")
8142       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8143
8144 (defun gnus-summary-limit-include-dormant ()
8145   "Display all the hidden articles that are marked as dormant.
8146 Note that this command only works on a subset of the articles currently
8147 fetched for this group."
8148   (interactive)
8149   (unless gnus-newsgroup-dormant
8150     (error "There are no dormant articles in this group"))
8151   (prog1
8152       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8153     (gnus-summary-position-point)))
8154
8155 (defun gnus-summary-limit-exclude-dormant ()
8156   "Hide all dormant articles."
8157   (interactive)
8158   (prog1
8159       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8160     (gnus-summary-position-point)))
8161
8162 (defun gnus-summary-limit-exclude-childless-dormant ()
8163   "Hide all dormant articles that have no children."
8164   (interactive)
8165   (let ((data (gnus-data-list t))
8166         articles d children)
8167     ;; Find all articles that are either not dormant or have
8168     ;; children.
8169     (while (setq d (pop data))
8170       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8171                 (and (setq children
8172                            (gnus-article-children (gnus-data-number d)))
8173                      (let (found)
8174                        (while children
8175                          (when (memq (car children) articles)
8176                            (setq children nil
8177                                  found t))
8178                          (pop children))
8179                        found)))
8180         (push (gnus-data-number d) articles)))
8181     ;; Do the limiting.
8182     (prog1
8183         (gnus-summary-limit articles)
8184       (gnus-summary-position-point))))
8185
8186 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8187   "Mark all unread excluded articles as read.
8188 If ALL, mark even excluded ticked and dormants as read."
8189   (interactive "P")
8190   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8191   (let ((articles (gnus-sorted-ndifference
8192                    (sort
8193                     (mapcar (lambda (h) (mail-header-number h))
8194                             gnus-newsgroup-headers)
8195                     '<)
8196                    gnus-newsgroup-limit))
8197         article)
8198     (setq gnus-newsgroup-unreads
8199           (gnus-sorted-intersection gnus-newsgroup-unreads
8200                                     gnus-newsgroup-limit))
8201     (if all
8202         (setq gnus-newsgroup-dormant nil
8203               gnus-newsgroup-marked nil
8204               gnus-newsgroup-reads
8205               (nconc
8206                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8207                gnus-newsgroup-reads))
8208       (while (setq article (pop articles))
8209         (unless (or (memq article gnus-newsgroup-dormant)
8210                     (memq article gnus-newsgroup-marked))
8211           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8212
8213 (defun gnus-summary-limit (articles &optional pop)
8214   (if pop
8215       ;; We pop the previous limit off the stack and use that.
8216       (setq articles (car gnus-newsgroup-limits)
8217             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8218     ;; We use the new limit, so we push the old limit on the stack.
8219     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8220   ;; Set the limit.
8221   (setq gnus-newsgroup-limit articles)
8222   (let ((total (length gnus-newsgroup-data))
8223         (data (gnus-data-find-list (gnus-summary-article-number)))
8224         (gnus-summary-mark-below nil)   ; Inhibit this.
8225         found)
8226     ;; This will do all the work of generating the new summary buffer
8227     ;; according to the new limit.
8228     (gnus-summary-prepare)
8229     ;; Hide any threads, possibly.
8230     (gnus-summary-maybe-hide-threads)
8231     ;; Try to return to the article you were at, or one in the
8232     ;; neighborhood.
8233     (when data
8234       ;; We try to find some article after the current one.
8235       (while data
8236         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8237           (setq data nil
8238                 found t))
8239         (setq data (cdr data))))
8240     (unless found
8241       ;; If there is no data, that means that we were after the last
8242       ;; article.  The same goes when we can't find any articles
8243       ;; after the current one.
8244       (goto-char (point-max))
8245       (gnus-summary-find-prev))
8246     (gnus-set-mode-line 'summary)
8247     ;; We return how many articles were removed from the summary
8248     ;; buffer as a result of the new limit.
8249     (- total (length gnus-newsgroup-data))))
8250
8251 (defsubst gnus-invisible-cut-children (threads)
8252   (let ((num 0))
8253     (while threads
8254       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8255         (incf num))
8256       (pop threads))
8257     (< num 2)))
8258
8259 (defsubst gnus-cut-thread (thread)
8260   "Go forwards in the thread until we find an article that we want to display."
8261   (when (or (eq gnus-fetch-old-headers 'some)
8262             (eq gnus-fetch-old-headers 'invisible)
8263             (numberp gnus-fetch-old-headers)
8264             (eq gnus-build-sparse-threads 'some)
8265             (eq gnus-build-sparse-threads 'more))
8266     ;; Deal with old-fetched headers and sparse threads.
8267     (while (and
8268             thread
8269             (or
8270              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8271              (gnus-summary-article-ancient-p
8272               (mail-header-number (car thread))))
8273             (if (or (<= (length (cdr thread)) 1)
8274                     (eq gnus-fetch-old-headers 'invisible))
8275                 (setq gnus-newsgroup-limit
8276                       (delq (mail-header-number (car thread))
8277                             gnus-newsgroup-limit)
8278                       thread (cadr thread))
8279               (when (gnus-invisible-cut-children (cdr thread))
8280                 (let ((th (cdr thread)))
8281                   (while th
8282                     (if (memq (mail-header-number (caar th))
8283                               gnus-newsgroup-limit)
8284                         (setq thread (car th)
8285                               th nil)
8286                       (setq th (cdr th))))))))))
8287   thread)
8288
8289 (defun gnus-cut-threads (threads)
8290   "Cut off all uninteresting articles from the beginning of THREADS."
8291   (when (or (eq gnus-fetch-old-headers 'some)
8292             (eq gnus-fetch-old-headers 'invisible)
8293             (numberp gnus-fetch-old-headers)
8294             (eq gnus-build-sparse-threads 'some)
8295             (eq gnus-build-sparse-threads 'more))
8296     (let ((th threads))
8297       (while th
8298         (setcar th (gnus-cut-thread (car th)))
8299         (setq th (cdr th)))))
8300   ;; Remove nixed out threads.
8301   (delq nil threads))
8302
8303 (defun gnus-summary-initial-limit (&optional show-if-empty)
8304   "Figure out what the initial limit is supposed to be on group entry.
8305 This entails weeding out unwanted dormants, low-scored articles,
8306 fetch-old-headers verbiage, and so on."
8307   ;; Most groups have nothing to remove.
8308   (if (or gnus-inhibit-limiting
8309           (and (null gnus-newsgroup-dormant)
8310                (eq gnus-newsgroup-display 'gnus-not-ignore)
8311                (not (eq gnus-fetch-old-headers 'some))
8312                (not (numberp gnus-fetch-old-headers))
8313                (not (eq gnus-fetch-old-headers 'invisible))
8314                (null gnus-summary-expunge-below)
8315                (not (eq gnus-build-sparse-threads 'some))
8316                (not (eq gnus-build-sparse-threads 'more))
8317                (null gnus-thread-expunge-below)
8318                (not gnus-use-nocem)))
8319       ()                                ; Do nothing.
8320     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8321     (setq gnus-newsgroup-limit nil)
8322     (mapatoms
8323      (lambda (node)
8324        (unless (car (symbol-value node))
8325          ;; These threads have no parents -- they are roots.
8326          (let ((nodes (cdr (symbol-value node)))
8327                thread)
8328            (while nodes
8329              (if (and gnus-thread-expunge-below
8330                       (< (gnus-thread-total-score (car nodes))
8331                          gnus-thread-expunge-below))
8332                  (gnus-expunge-thread (pop nodes))
8333                (setq thread (pop nodes))
8334                (gnus-summary-limit-children thread))))))
8335      gnus-newsgroup-dependencies)
8336     ;; If this limitation resulted in an empty group, we might
8337     ;; pop the previous limit and use it instead.
8338     (when (and (not gnus-newsgroup-limit)
8339                show-if-empty)
8340       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8341     gnus-newsgroup-limit))
8342
8343 (defun gnus-summary-limit-children (thread)
8344   "Return 1 if this subthread is visible and 0 if it is not."
8345   ;; First we get the number of visible children to this thread.  This
8346   ;; is done by recursing down the thread using this function, so this
8347   ;; will really go down to a leaf article first, before slowly
8348   ;; working its way up towards the root.
8349   (when thread
8350     (let* ((max-lisp-eval-depth 5000)
8351            (children
8352            (if (cdr thread)
8353                (apply '+ (mapcar 'gnus-summary-limit-children
8354                                  (cdr thread)))
8355              0))
8356           (number (mail-header-number (car thread)))
8357           score)
8358       (if (and
8359            (not (memq number gnus-newsgroup-marked))
8360            (or
8361             ;; If this article is dormant and has absolutely no visible
8362             ;; children, then this article isn't visible.
8363             (and (memq number gnus-newsgroup-dormant)
8364                  (zerop children))
8365             ;; If this is "fetch-old-headered" and there is no
8366             ;; visible children, then we don't want this article.
8367             (and (or (eq gnus-fetch-old-headers 'some)
8368                      (numberp gnus-fetch-old-headers))
8369                  (gnus-summary-article-ancient-p number)
8370                  (zerop children))
8371             ;; If this is "fetch-old-headered" and `invisible', then
8372             ;; we don't want this article.
8373             (and (eq gnus-fetch-old-headers 'invisible)
8374                  (gnus-summary-article-ancient-p number))
8375             ;; If this is a sparsely inserted article with no children,
8376             ;; we don't want it.
8377             (and (eq gnus-build-sparse-threads 'some)
8378                  (gnus-summary-article-sparse-p number)
8379                  (zerop children))
8380             ;; If we use expunging, and this article is really
8381             ;; low-scored, then we don't want this article.
8382             (when (and gnus-summary-expunge-below
8383                        (< (setq score
8384                                 (or (cdr (assq number gnus-newsgroup-scored))
8385                                     gnus-summary-default-score))
8386                           gnus-summary-expunge-below))
8387               ;; We increase the expunge-tally here, but that has
8388               ;; nothing to do with the limits, really.
8389               (incf gnus-newsgroup-expunged-tally)
8390               ;; We also mark as read here, if that's wanted.
8391               (when (and gnus-summary-mark-below
8392                          (< score gnus-summary-mark-below))
8393                 (setq gnus-newsgroup-unreads
8394                       (delq number gnus-newsgroup-unreads))
8395                 (if gnus-newsgroup-auto-expire
8396                     (push number gnus-newsgroup-expirable)
8397                   (push (cons number gnus-low-score-mark)
8398                         gnus-newsgroup-reads)))
8399               t)
8400             ;; Do the `display' group parameter.
8401             (and gnus-newsgroup-display
8402                  (not (funcall gnus-newsgroup-display)))
8403             ;; Check NoCeM things.
8404             (when (and gnus-use-nocem
8405                        (gnus-nocem-unwanted-article-p
8406                         (mail-header-id (car thread))))
8407               (setq gnus-newsgroup-unreads
8408                     (delq number gnus-newsgroup-unreads))
8409               t)))
8410           ;; Nope, invisible article.
8411           0
8412         ;; Ok, this article is to be visible, so we add it to the limit
8413         ;; and return 1.
8414         (push number gnus-newsgroup-limit)
8415         1))))
8416
8417 (defun gnus-expunge-thread (thread)
8418   "Mark all articles in THREAD as read."
8419   (let* ((number (mail-header-number (car thread))))
8420     (incf gnus-newsgroup-expunged-tally)
8421     ;; We also mark as read here, if that's wanted.
8422     (setq gnus-newsgroup-unreads
8423           (delq number gnus-newsgroup-unreads))
8424     (if gnus-newsgroup-auto-expire
8425         (push number gnus-newsgroup-expirable)
8426       (push (cons number gnus-low-score-mark)
8427             gnus-newsgroup-reads)))
8428   ;; Go recursively through all subthreads.
8429   (mapcar 'gnus-expunge-thread (cdr thread)))
8430
8431 ;; Summary article oriented commands
8432
8433 (defun gnus-summary-refer-parent-article (n)
8434   "Refer parent article N times.
8435 If N is negative, go to ancestor -N instead.
8436 The difference between N and the number of articles fetched is returned."
8437   (interactive "p")
8438   (let ((skip 1)
8439         error header ref)
8440     (when (not (natnump n))
8441       (setq skip (abs n)
8442             n 1))
8443     (while (and (> n 0)
8444                 (not error))
8445       (setq header (gnus-summary-article-header))
8446       (if (and (eq (mail-header-number header)
8447                    (cdr gnus-article-current))
8448                (equal gnus-newsgroup-name
8449                       (car gnus-article-current)))
8450           ;; If we try to find the parent of the currently
8451           ;; displayed article, then we take a look at the actual
8452           ;; References header, since this is slightly more
8453           ;; reliable than the References field we got from the
8454           ;; server.
8455           (save-excursion
8456             (set-buffer gnus-original-article-buffer)
8457             (nnheader-narrow-to-headers)
8458             (unless (setq ref (message-fetch-field "references"))
8459               (when (setq ref (message-fetch-field "in-reply-to"))
8460                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8461             (widen))
8462         (setq ref
8463               ;; It's not the current article, so we take a bet on
8464               ;; the value we got from the server.
8465               (mail-header-references header)))
8466       (if (and ref
8467                (not (equal ref "")))
8468           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8469             (gnus-message 1 "Couldn't find parent"))
8470         (gnus-message 1 "No references in article %d"
8471                       (gnus-summary-article-number))
8472         (setq error t))
8473       (decf n))
8474     (gnus-summary-position-point)
8475     n))
8476
8477 (defun gnus-summary-refer-references ()
8478   "Fetch all articles mentioned in the References header.
8479 Return the number of articles fetched."
8480   (interactive)
8481   (let ((ref (mail-header-references (gnus-summary-article-header)))
8482         (current (gnus-summary-article-number))
8483         (n 0))
8484     (if (or (not ref)
8485             (equal ref ""))
8486         (error "No References in the current article")
8487       ;; For each Message-ID in the References header...
8488       (while (string-match "<[^>]*>" ref)
8489         (incf n)
8490         ;; ... fetch that article.
8491         (gnus-summary-refer-article
8492          (prog1 (match-string 0 ref)
8493            (setq ref (substring ref (match-end 0))))))
8494       (gnus-summary-goto-subject current)
8495       (gnus-summary-position-point)
8496       n)))
8497
8498 (defun gnus-summary-refer-thread (&optional limit)
8499   "Fetch all articles in the current thread.
8500 If LIMIT (the numerical prefix), fetch that many old headers instead
8501 of what's specified by the `gnus-refer-thread-limit' variable."
8502   (interactive "P")
8503   (let ((id (mail-header-id (gnus-summary-article-header)))
8504         (limit (if limit (prefix-numeric-value limit)
8505                  gnus-refer-thread-limit)))
8506     (unless (eq gnus-fetch-old-headers 'invisible)
8507       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8508       ;; Retrieve the headers and read them in.
8509       (if (eq (if (numberp limit)
8510                   (gnus-retrieve-headers
8511                    (list (min
8512                           (+ (mail-header-number
8513                               (gnus-summary-article-header))
8514                              limit)
8515                           gnus-newsgroup-end))
8516                    gnus-newsgroup-name (* limit 2))
8517                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8518                 ;; headers.
8519                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8520                                        gnus-newsgroup-name limit))
8521               'nov)
8522           (gnus-build-all-threads)
8523         (error "Can't fetch thread from back ends that don't support NOV"))
8524       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8525     (gnus-summary-limit-include-thread id)))
8526
8527 (defun gnus-summary-refer-article (message-id)
8528   "Fetch an article specified by MESSAGE-ID."
8529   (interactive "sMessage-ID: ")
8530   (when (and (stringp message-id)
8531              (not (zerop (length message-id))))
8532     (setq message-id (gnus-replace-in-string message-id " " ""))
8533     ;; Construct the correct Message-ID if necessary.
8534     ;; Suggested by tale@pawl.rpi.edu.
8535     (unless (string-match "^<" message-id)
8536       (setq message-id (concat "<" message-id)))
8537     (unless (string-match ">$" message-id)
8538       (setq message-id (concat message-id ">")))
8539     ;; People often post MIDs from URLs, so unhex it:
8540     (unless (string-match "@" message-id)
8541       (setq message-id (gnus-url-unhex-string message-id)))
8542     (let* ((header (gnus-id-to-header message-id))
8543            (sparse (and header
8544                         (gnus-summary-article-sparse-p
8545                          (mail-header-number header))
8546                         (memq (mail-header-number header)
8547                               gnus-newsgroup-limit)))
8548            number)
8549       (cond
8550        ;; If the article is present in the buffer we just go to it.
8551        ((and header
8552              (or (not (gnus-summary-article-sparse-p
8553                        (mail-header-number header)))
8554                  sparse))
8555         (prog1
8556             (gnus-summary-goto-article
8557              (mail-header-number header) nil t)
8558           (when sparse
8559             (gnus-summary-update-article (mail-header-number header)))))
8560        (t
8561         ;; We fetch the article.
8562         (catch 'found
8563           (dolist (gnus-override-method (gnus-refer-article-methods))
8564             (when (and (gnus-check-server gnus-override-method)
8565                        ;; Fetch the header,
8566                        (setq number (gnus-summary-insert-subject message-id)))
8567               ;; and display the article.
8568               (gnus-summary-select-article nil nil nil number)
8569               (throw 'found t)))
8570           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8571
8572 (defun gnus-refer-article-methods ()
8573   "Return a list of referable methods."
8574   (cond
8575    ;; No method, so we default to current and native.
8576    ((null gnus-refer-article-method)
8577     (list gnus-current-select-method gnus-select-method))
8578    ;; Current.
8579    ((eq 'current gnus-refer-article-method)
8580     (list gnus-current-select-method))
8581    ;; List of select methods.
8582    ((not (and (symbolp (car gnus-refer-article-method))
8583               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8584     (let (out)
8585       (dolist (method gnus-refer-article-method)
8586         (push (if (eq 'current method)
8587                   gnus-current-select-method
8588                 method)
8589               out))
8590       (nreverse out)))
8591    ;; One single select method.
8592    (t
8593     (list gnus-refer-article-method))))
8594
8595 (defun gnus-summary-edit-parameters ()
8596   "Edit the group parameters of the current group."
8597   (interactive)
8598   (gnus-group-edit-group gnus-newsgroup-name 'params))
8599
8600 (defun gnus-summary-customize-parameters ()
8601   "Customize the group parameters of the current group."
8602   (interactive)
8603   (gnus-group-customize gnus-newsgroup-name))
8604
8605 (defun gnus-summary-enter-digest-group (&optional force)
8606   "Enter an nndoc group based on the current article.
8607 If FORCE, force a digest interpretation.  If not, try
8608 to guess what the document format is."
8609   (interactive "P")
8610   (let ((conf gnus-current-window-configuration))
8611     (save-window-excursion
8612       (save-excursion
8613         (let (gnus-article-prepare-hook
8614               gnus-display-mime-function
8615               gnus-break-pages)
8616           (gnus-summary-select-article))))
8617     (setq gnus-current-window-configuration conf)
8618     (let* ((name (format "%s-%d"
8619                          (gnus-group-prefixed-name
8620                           gnus-newsgroup-name (list 'nndoc ""))
8621                          (with-current-buffer gnus-summary-buffer
8622                            gnus-current-article)))
8623            (ogroup gnus-newsgroup-name)
8624            (params (append (gnus-info-params (gnus-get-info ogroup))
8625                            (list (cons 'to-group ogroup))
8626                            (list (cons 'parent-group ogroup))
8627                            (list (cons 'save-article-group ogroup))))
8628            (case-fold-search t)
8629            (buf (current-buffer))
8630            dig to-address)
8631       (save-excursion
8632         (set-buffer gnus-original-article-buffer)
8633         ;; Have the digest group inherit the main mail address of
8634         ;; the parent article.
8635         (when (setq to-address (or (gnus-fetch-field "reply-to")
8636                                    (gnus-fetch-field "from")))
8637           (setq params
8638                 (append
8639                  (list (cons 'to-address
8640                              (funcall gnus-decode-encoded-address-function
8641                                       to-address))))))
8642         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8643         (insert-buffer-substring gnus-original-article-buffer)
8644         ;; Remove lines that may lead nndoc to misinterpret the
8645         ;; document type.
8646         (narrow-to-region
8647          (goto-char (point-min))
8648          (or (search-forward "\n\n" nil t) (point)))
8649         (goto-char (point-min))
8650         (delete-matching-lines "^Path:\\|^From ")
8651         (widen))
8652       (unwind-protect
8653           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8654                     (gnus-newsgroup-ephemeral-ignored-charsets
8655                      gnus-newsgroup-ignored-charsets))
8656                 (gnus-group-read-ephemeral-group
8657                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8658                               (nndoc-article-type
8659                                ,(if force 'mbox 'guess)))
8660                  t nil nil nil
8661                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8662                                                         "ADAPT")))))
8663               ;; Make all postings to this group go to the parent group.
8664               (nconc (gnus-info-params (gnus-get-info name))
8665                      params)
8666             ;; Couldn't select this doc group.
8667             (switch-to-buffer buf)
8668             (gnus-set-global-variables)
8669             (gnus-configure-windows 'summary)
8670             (gnus-message 3 "Article couldn't be entered?"))
8671         (kill-buffer dig)))))
8672
8673 (defun gnus-summary-read-document (n)
8674   "Open a new group based on the current article(s).
8675 This will allow you to read digests and other similar
8676 documents as newsgroups.
8677 Obeys the standard process/prefix convention."
8678   (interactive "P")
8679   (let* ((ogroup gnus-newsgroup-name)
8680          (params (append (gnus-info-params (gnus-get-info ogroup))
8681                          (list (cons 'to-group ogroup))))
8682          group egroup groups vgroup)
8683     (dolist (article (gnus-summary-work-articles n))
8684       (setq group (format "%s-%d" gnus-newsgroup-name article))
8685       (gnus-summary-remove-process-mark article)
8686       (when (gnus-summary-display-article article)
8687         (save-excursion
8688           (with-temp-buffer
8689             (insert-buffer-substring gnus-original-article-buffer)
8690             ;; Remove some headers that may lead nndoc to make
8691             ;; the wrong guess.
8692             (message-narrow-to-head)
8693             (goto-char (point-min))
8694             (delete-matching-lines "^Path:\\|^From ")
8695             (widen)
8696             (if (setq egroup
8697                       (gnus-group-read-ephemeral-group
8698                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8699                                      (nndoc-article-type guess))
8700                        t nil t))
8701                 (progn
8702             ;; Make all postings to this group go to the parent group.
8703                   (nconc (gnus-info-params (gnus-get-info egroup))
8704                          params)
8705                   (push egroup groups))
8706               ;; Couldn't select this doc group.
8707               (gnus-error 3 "Article couldn't be entered"))))))
8708     ;; Now we have selected all the documents.
8709     (cond
8710      ((not groups)
8711       (error "None of the articles could be interpreted as documents"))
8712      ((gnus-group-read-ephemeral-group
8713        (setq vgroup (format
8714                      "nnvirtual:%s-%s" gnus-newsgroup-name
8715                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8716        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8717        t
8718        (cons (current-buffer) 'summary)))
8719      (t
8720       (error "Couldn't select virtual nndoc group")))))
8721
8722 (defun gnus-summary-isearch-article (&optional regexp-p)
8723   "Do incremental search forward on the current article.
8724 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8725   (interactive "P")
8726   (gnus-summary-select-article)
8727   (gnus-configure-windows 'article)
8728   (gnus-eval-in-buffer-window gnus-article-buffer
8729     (save-restriction
8730       (widen)
8731       (isearch-forward regexp-p))))
8732
8733 (defun gnus-summary-repeat-search-article-forward ()
8734   "Repeat the previous search forwards."
8735   (interactive)
8736   (unless gnus-last-search-regexp
8737     (error "No previous search"))
8738   (gnus-summary-search-article-forward gnus-last-search-regexp))
8739
8740 (defun gnus-summary-repeat-search-article-backward ()
8741   "Repeat the previous search backwards."
8742   (interactive)
8743   (unless gnus-last-search-regexp
8744     (error "No previous search"))
8745   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8746
8747 (defun gnus-summary-search-article-forward (regexp &optional backward)
8748   "Search for an article containing REGEXP forward.
8749 If BACKWARD, search backward instead."
8750   (interactive
8751    (list (read-string
8752           (format "Search article %s (regexp%s): "
8753                   (if current-prefix-arg "backward" "forward")
8754                   (if gnus-last-search-regexp
8755                       (concat ", default " gnus-last-search-regexp)
8756                     "")))
8757          current-prefix-arg))
8758   (if (string-equal regexp "")
8759       (setq regexp (or gnus-last-search-regexp ""))
8760     (setq gnus-last-search-regexp regexp)
8761     (setq gnus-article-before-search gnus-current-article))
8762   ;; Intentionally set gnus-last-article.
8763   (setq gnus-last-article gnus-article-before-search)
8764   (let ((gnus-last-article gnus-last-article))
8765     (if (gnus-summary-search-article regexp backward)
8766         (gnus-summary-show-thread)
8767       (signal 'search-failed (list regexp)))))
8768
8769 (defun gnus-summary-search-article-backward (regexp)
8770   "Search for an article containing REGEXP backward."
8771   (interactive
8772    (list (read-string
8773           (format "Search article backward (regexp%s): "
8774                   (if gnus-last-search-regexp
8775                       (concat ", default " gnus-last-search-regexp)
8776                     "")))))
8777   (gnus-summary-search-article-forward regexp 'backward))
8778
8779 (defun gnus-summary-search-article (regexp &optional backward)
8780   "Search for an article containing REGEXP.
8781 Optional argument BACKWARD means do search for backward.
8782 `gnus-select-article-hook' is not called during the search."
8783   ;; We have to require this here to make sure that the following
8784   ;; dynamic binding isn't shadowed by autoloading.
8785   (require 'gnus-async)
8786   (require 'gnus-art)
8787   (let ((gnus-select-article-hook nil)  ;Disable hook.
8788         (gnus-article-prepare-hook nil)
8789         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8790         (gnus-use-article-prefetch nil)
8791         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8792         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8793         (gnus-visual nil)
8794         (gnus-keep-backlog nil)
8795         (gnus-break-pages nil)
8796         (gnus-summary-display-arrow nil)
8797         (gnus-updated-mode-lines nil)
8798         (gnus-auto-center-summary nil)
8799         (sum (current-buffer))
8800         (gnus-display-mime-function nil)
8801         (found nil)
8802         point)
8803     (gnus-save-hidden-threads
8804       (gnus-summary-select-article)
8805       (set-buffer gnus-article-buffer)
8806       (goto-char (window-point (get-buffer-window (current-buffer))))
8807       (when backward
8808         (forward-line -1))
8809       (while (not found)
8810         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8811         (if (if backward
8812                 (re-search-backward regexp nil t)
8813               (re-search-forward regexp nil t))
8814             ;; We found the regexp.
8815             (progn
8816               (setq found 'found)
8817               (beginning-of-line)
8818               (set-window-start
8819                (get-buffer-window (current-buffer))
8820                (point))
8821               (forward-line 1)
8822               (set-window-point
8823                (get-buffer-window (current-buffer))
8824                (point))
8825               (set-buffer sum)
8826               (setq point (point)))
8827           ;; We didn't find it, so we go to the next article.
8828           (set-buffer sum)
8829           (setq found 'not)
8830           (while (eq found 'not)
8831             (if (not (if backward (gnus-summary-find-prev)
8832                        (gnus-summary-find-next)))
8833                 ;; No more articles.
8834                 (setq found t)
8835               ;; Select the next article and adjust point.
8836               (unless (gnus-summary-article-sparse-p
8837                        (gnus-summary-article-number))
8838                 (setq found nil)
8839                 (gnus-summary-select-article)
8840                 (set-buffer gnus-article-buffer)
8841                 (widen)
8842                 (goto-char (if backward (point-max) (point-min))))))))
8843       (gnus-message 7 ""))
8844     ;; Return whether we found the regexp.
8845     (when (eq found 'found)
8846       (goto-char point)
8847       (gnus-summary-show-thread)
8848       (gnus-summary-goto-subject gnus-current-article)
8849       (gnus-summary-position-point)
8850       t)))
8851
8852 (defun gnus-find-matching-articles (header regexp)
8853   "Return a list of all articles that match REGEXP on HEADER.
8854 This search includes all articles in the current group that Gnus has
8855 fetched headers for, whether they are displayed or not."
8856   (let ((articles nil)
8857         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8858         (case-fold-search t))
8859     (dolist (header gnus-newsgroup-headers)
8860       (when (string-match regexp (funcall func header))
8861         (push (mail-header-number header) articles)))
8862     (nreverse articles)))
8863
8864 (defun gnus-summary-find-matching (header regexp &optional backward unread
8865                                           not-case-fold not-matching)
8866   "Return a list of all articles that match REGEXP on HEADER.
8867 The search stars on the current article and goes forwards unless
8868 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8869 If UNREAD is non-nil, only unread articles will
8870 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8871 in the comparisons. If NOT-MATCHING, return a list of all articles that
8872 not match REGEXP on HEADER."
8873   (let ((case-fold-search (not not-case-fold))
8874         articles d func)
8875     (if (consp header)
8876         (if (eq (car header) 'extra)
8877             (setq func
8878                   `(lambda (h)
8879                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8880                          "")))
8881           (error "%s is an invalid header" header))
8882       (unless (fboundp (intern (concat "mail-header-" header)))
8883         (error "%s is not a valid header" header))
8884       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8885     (dolist (d (if (eq backward 'all)
8886                    gnus-newsgroup-data
8887                  (gnus-data-find-list
8888                   (gnus-summary-article-number)
8889                   (gnus-data-list backward))))
8890       (when (and (or (not unread)       ; We want all articles...
8891                      (gnus-data-unread-p d)) ; Or just unreads.
8892                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8893                  (if not-matching
8894                      (not (string-match
8895                            regexp
8896                            (funcall func (gnus-data-header d))))
8897                    (string-match regexp
8898                                  (funcall func (gnus-data-header d)))))
8899         (push (gnus-data-number d) articles))) ; Success!
8900     (nreverse articles)))
8901
8902 (defun gnus-summary-execute-command (header regexp command &optional backward)
8903   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8904 If HEADER is an empty string (or nil), the match is done on the entire
8905 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8906   (interactive
8907    (list (let ((completion-ignore-case t))
8908            (completing-read
8909             "Header name: "
8910             (mapcar (lambda (header) (list (format "%s" header)))
8911                     (append
8912                      '("Number" "Subject" "From" "Lines" "Date"
8913                        "Message-ID" "Xref" "References" "Body")
8914                      gnus-extra-headers))
8915             nil 'require-match))
8916          (read-string "Regexp: ")
8917          (read-key-sequence "Command: ")
8918          current-prefix-arg))
8919   (when (equal header "Body")
8920     (setq header ""))
8921   ;; Hidden thread subtrees must be searched as well.
8922   (gnus-summary-show-all-threads)
8923   ;; We don't want to change current point nor window configuration.
8924   (save-excursion
8925     (save-window-excursion
8926       (let (gnus-visual
8927             gnus-treat-strip-trailing-blank-lines
8928             gnus-treat-strip-leading-blank-lines
8929             gnus-treat-strip-multiple-blank-lines
8930             gnus-treat-hide-boring-headers
8931             gnus-treat-fold-newsgroups
8932             gnus-article-prepare-hook)
8933         (gnus-message 6 "Executing %s..." (key-description command))
8934         ;; We'd like to execute COMMAND interactively so as to give arguments.
8935         (gnus-execute header regexp
8936                       `(call-interactively ',(key-binding command))
8937                       backward)
8938         (gnus-message 6 "Executing %s...done" (key-description command))))))
8939
8940 (defun gnus-summary-beginning-of-article ()
8941   "Scroll the article back to the beginning."
8942   (interactive)
8943   (gnus-summary-select-article)
8944   (gnus-configure-windows 'article)
8945   (gnus-eval-in-buffer-window gnus-article-buffer
8946     (widen)
8947     (goto-char (point-min))
8948     (when gnus-break-pages
8949       (gnus-narrow-to-page))))
8950
8951 (defun gnus-summary-end-of-article ()
8952   "Scroll to the end of the article."
8953   (interactive)
8954   (gnus-summary-select-article)
8955   (gnus-configure-windows 'article)
8956   (gnus-eval-in-buffer-window gnus-article-buffer
8957     (widen)
8958     (goto-char (point-max))
8959     (recenter -3)
8960     (when gnus-break-pages
8961       (when (re-search-backward page-delimiter nil t)
8962         (narrow-to-region (match-end 0) (point-max)))
8963       (gnus-narrow-to-page))))
8964
8965 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8966   "Truncate to LEN and quote all \"(\"'s in STRING."
8967   (gnus-replace-in-string (if (and len (> (length string) len))
8968                               (substring string 0 len)
8969                             string)
8970                           "[()]" "\\\\\\&"))
8971
8972 (defun gnus-summary-print-article (&optional filename n)
8973   "Generate and print a PostScript image of the process-marked (mail) articles.
8974
8975 If used interactively, print the current article if none are
8976 process-marked.  With prefix arg, prompt the user for the name of the
8977 file to save in.
8978
8979 When used from Lisp, accept two optional args FILENAME and N.  N means
8980 to print the next N articles.  If N is negative, print the N previous
8981 articles.  If N is nil and articles have been marked with the process
8982 mark, print these instead.
8983
8984 If the optional first argument FILENAME is nil, send the image to the
8985 printer.  If FILENAME is a string, save the PostScript image in a file with
8986 that name.  If FILENAME is a number, prompt the user for the name of the file
8987 to save in."
8988   (interactive (list (ps-print-preprint current-prefix-arg)))
8989   (dolist (article (gnus-summary-work-articles n))
8990     (gnus-summary-select-article nil nil 'pseudo article)
8991     (gnus-eval-in-buffer-window gnus-article-buffer
8992       (gnus-print-buffer))
8993     (gnus-summary-remove-process-mark article))
8994   (ps-despool filename))
8995
8996 (defun gnus-print-buffer ()
8997   (let ((buffer (generate-new-buffer " *print*")))
8998     (unwind-protect
8999         (progn
9000           (copy-to-buffer buffer (point-min) (point-max))
9001           (set-buffer buffer)
9002           (gnus-remove-text-with-property 'gnus-decoration)
9003           (when (gnus-visual-p 'article-highlight 'highlight)
9004             ;; Copy-to-buffer doesn't copy overlay.  So redo
9005             ;; highlight.
9006             (let ((gnus-article-buffer buffer))
9007               (gnus-article-highlight-citation t)
9008               (gnus-article-highlight-signature)
9009               (gnus-article-emphasize)
9010               (gnus-article-delete-invisible-text)))
9011           (let ((ps-left-header
9012                  (list
9013                   (concat "("
9014                           (gnus-summary-print-truncate-and-quote
9015                            (mail-header-subject gnus-current-headers)
9016                            66) ")")
9017                   (concat "("
9018                           (gnus-summary-print-truncate-and-quote
9019                            (mail-header-from gnus-current-headers)
9020                            45) ")")))
9021                 (ps-right-header
9022                  (list
9023                   "/pagenumberstring load"
9024                   (concat "("
9025                           (mail-header-date gnus-current-headers) ")"))))
9026             (gnus-run-hooks 'gnus-ps-print-hook)
9027             (save-excursion
9028               (if window-system
9029                   (ps-spool-buffer-with-faces)
9030                 (ps-spool-buffer)))))
9031       (kill-buffer buffer))))
9032
9033 (defun gnus-summary-show-article (&optional arg)
9034   "Force redisplaying of the current article.
9035 If ARG (the prefix) is a number, show the article with the charset
9036 defined in `gnus-summary-show-article-charset-alist', or the charset
9037 input.
9038 If ARG (the prefix) is non-nil and not a number, show the raw article
9039 without any article massaging functions being run.  Normally, the key
9040 strokes are `C-u g'."
9041   (interactive "P")
9042   (cond
9043    ((numberp arg)
9044     (gnus-summary-show-article t)
9045     (let ((gnus-newsgroup-charset
9046            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9047                (mm-read-coding-system
9048                 "View as charset: " ;; actually it is coding system.
9049                 (with-current-buffer gnus-article-buffer
9050                   (mm-detect-coding-region (point) (point-max))))))
9051           (gnus-newsgroup-ignored-charsets 'gnus-all))
9052       (gnus-summary-select-article nil 'force)
9053       (let ((deps gnus-newsgroup-dependencies)
9054             head header lines)
9055         (save-excursion
9056           (set-buffer gnus-original-article-buffer)
9057           (save-restriction
9058             (message-narrow-to-head)
9059             (setq head (buffer-string))
9060             (goto-char (point-min))
9061             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9062               (goto-char (point-max))
9063               (widen)
9064               (setq lines (1- (count-lines (point) (point-max))))))
9065           (with-temp-buffer
9066             (insert (format "211 %d Article retrieved.\n"
9067                             (cdr gnus-article-current)))
9068             (insert head)
9069             (if lines (insert (format "Lines: %d\n" lines)))
9070             (insert ".\n")
9071             (let ((nntp-server-buffer (current-buffer)))
9072               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9073         (gnus-data-set-header
9074          (gnus-data-find (cdr gnus-article-current))
9075          header)
9076         (gnus-summary-update-article-line
9077          (cdr gnus-article-current) header)
9078         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9079           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9080    ((not arg)
9081     ;; Select the article the normal way.
9082     (gnus-summary-select-article nil 'force))
9083    (t
9084     ;; We have to require this here to make sure that the following
9085     ;; dynamic binding isn't shadowed by autoloading.
9086     (require 'gnus-async)
9087     (require 'gnus-art)
9088     ;; Bind the article treatment functions to nil.
9089     (let ((gnus-have-all-headers t)
9090           gnus-article-prepare-hook
9091           gnus-article-decode-hook
9092           gnus-display-mime-function
9093           gnus-break-pages)
9094       ;; Destroy any MIME parts.
9095       (when (gnus-buffer-live-p gnus-article-buffer)
9096         (save-excursion
9097           (set-buffer gnus-article-buffer)
9098           (mm-destroy-parts gnus-article-mime-handles)
9099           ;; Set it to nil for safety reason.
9100           (setq gnus-article-mime-handle-alist nil)
9101           (setq gnus-article-mime-handles nil)))
9102       (gnus-summary-select-article nil 'force))))
9103   (gnus-summary-goto-subject gnus-current-article)
9104   (gnus-summary-position-point))
9105
9106 (defun gnus-summary-show-raw-article ()
9107   "Show the raw article without any article massaging functions being run."
9108   (interactive)
9109   (gnus-summary-show-article t))
9110
9111 (defun gnus-summary-verbose-headers (&optional arg)
9112   "Toggle permanent full header display.
9113 If ARG is a positive number, turn header display on.
9114 If ARG is a negative number, turn header display off."
9115   (interactive "P")
9116   (setq gnus-show-all-headers
9117         (cond ((or (not (numberp arg))
9118                    (zerop arg))
9119                (not gnus-show-all-headers))
9120               ((natnump arg)
9121                t)))
9122   (gnus-summary-show-article))
9123
9124 (defun gnus-summary-toggle-header (&optional arg)
9125   "Show the headers if they are hidden, or hide them if they are shown.
9126 If ARG is a positive number, show the entire header.
9127 If ARG is a negative number, hide the unwanted header lines."
9128   (interactive "P")
9129   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9130                      (get-buffer-window gnus-article-buffer t))))
9131     (with-current-buffer gnus-article-buffer
9132       (widen)
9133       (article-narrow-to-head)
9134       (let* ((buffer-read-only nil)
9135              (inhibit-point-motion-hooks t)
9136              (hidden (if (numberp arg)
9137                          (>= arg 0)
9138                        (or (not (looking-at "[^ \t\n]+:"))
9139                            (gnus-article-hidden-text-p 'headers))))
9140              s e)
9141         (delete-region (point-min) (point-max))
9142         (with-current-buffer gnus-original-article-buffer
9143           (goto-char (setq s (point-min)))
9144           (setq e (if (search-forward "\n\n" nil t)
9145                       (1- (point))
9146                     (point-max))))
9147         (insert-buffer-substring gnus-original-article-buffer s e)
9148         (run-hooks 'gnus-article-decode-hook)
9149         (if hidden
9150             (let ((gnus-treat-hide-headers nil)
9151                   (gnus-treat-hide-boring-headers nil))
9152               (gnus-delete-wash-type 'headers)
9153               (gnus-treat-article 'head))
9154           (gnus-treat-article 'head))
9155         (widen)
9156         (if window
9157             (set-window-start window (goto-char (point-min))))
9158         (if gnus-break-pages
9159             (gnus-narrow-to-page)
9160           (when (gnus-visual-p 'page-marker)
9161             (let ((buffer-read-only nil))
9162               (gnus-remove-text-with-property 'gnus-prev)
9163               (gnus-remove-text-with-property 'gnus-next))))
9164         (gnus-set-mode-line 'article)))))
9165
9166 (defun gnus-summary-show-all-headers ()
9167   "Make all header lines visible."
9168   (interactive)
9169   (gnus-summary-toggle-header 1))
9170
9171 (defun gnus-summary-caesar-message (&optional arg)
9172   "Caesar rotate the current article by 13.
9173 With a non-numerical prefix, also rotate headers.  A numerical
9174 prefix specifies how many places to rotate each letter forward."
9175   (interactive "P")
9176   (gnus-summary-select-article)
9177   (let ((mail-header-separator ""))
9178     (gnus-eval-in-buffer-window gnus-article-buffer
9179       (save-restriction
9180         (widen)
9181         (let ((start (window-start))
9182               buffer-read-only)
9183           (if (equal arg '(4))
9184               (message-caesar-buffer-body nil t)
9185             (message-caesar-buffer-body arg))
9186           (set-window-start (get-buffer-window (current-buffer)) start)))))
9187   ;; Create buttons and stuff...
9188   (gnus-treat-article nil))
9189
9190 (defun gnus-summary-idna-message (&optional arg)
9191   "Decode IDNA encoded domain names in the current articles.
9192 IDNA encoded domain names looks like `xn--bar'.  If a string
9193 remain unencoded after running this function, it is likely an
9194 invalid IDNA string (`xn--bar' is invalid).
9195
9196 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9197 installed for this command to work."
9198   (interactive "P")
9199   (if (not (and (condition-case nil (require 'idna)
9200                   (file-error))
9201                 (mm-coding-system-p 'utf-8)
9202                 (executable-find (symbol-value 'idna-program))))
9203       (gnus-message
9204        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9205     (gnus-summary-select-article)
9206     (let ((mail-header-separator ""))
9207       (gnus-eval-in-buffer-window gnus-article-buffer
9208         (save-restriction
9209           (widen)
9210           (let ((start (window-start))
9211                 buffer-read-only)
9212             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9213               (replace-match (idna-to-unicode (match-string 1))))
9214             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9215
9216 (defun gnus-summary-morse-message (&optional arg)
9217   "Morse decode the current article."
9218   (interactive "P")
9219   (gnus-summary-select-article)
9220   (let ((mail-header-separator ""))
9221     (gnus-eval-in-buffer-window gnus-article-buffer
9222       (save-excursion
9223         (save-restriction
9224           (widen)
9225           (let ((pos (window-start))
9226                 buffer-read-only)
9227             (goto-char (point-min))
9228             (when (message-goto-body)
9229               (gnus-narrow-to-body))
9230             (goto-char (point-min))
9231             (while (search-forward "·" (point-max) t)
9232               (replace-match "."))
9233             (unmorse-region (point-min) (point-max))
9234             (widen)
9235             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9236
9237 (defun gnus-summary-stop-page-breaking ()
9238   "Stop page breaking in the current article."
9239   (interactive)
9240   (gnus-summary-select-article)
9241   (gnus-eval-in-buffer-window gnus-article-buffer
9242     (widen)
9243     (when (gnus-visual-p 'page-marker)
9244       (let ((buffer-read-only nil))
9245         (gnus-remove-text-with-property 'gnus-prev)
9246         (gnus-remove-text-with-property 'gnus-next))
9247       (setq gnus-page-broken nil))))
9248
9249 (defun gnus-summary-move-article (&optional n to-newsgroup
9250                                             select-method action)
9251   "Move the current article to a different newsgroup.
9252 If N is a positive number, move the N next articles.
9253 If N is a negative number, move the N previous articles.
9254 If N is nil and any articles have been marked with the process mark,
9255 move those articles instead.
9256 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9257 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9258 re-spool using this method.
9259
9260 When called interactively with TO-NEWSGROUP being nil, the value of
9261 the variable `gnus-move-split-methods' is used for finding a default
9262 for the target newsgroup.
9263
9264 For this function to work, both the current newsgroup and the
9265 newsgroup that you want to move to have to support the `request-move'
9266 and `request-accept' functions.
9267
9268 ACTION can be either `move' (the default), `crosspost' or `copy'."
9269   (interactive "P")
9270   (unless action
9271     (setq action 'move))
9272   ;; Check whether the source group supports the required functions.
9273   (cond ((and (eq action 'move)
9274               (not (gnus-check-backend-function
9275                     'request-move-article gnus-newsgroup-name)))
9276          (error "The current group does not support article moving"))
9277         ((and (eq action 'crosspost)
9278               (not (gnus-check-backend-function
9279                     'request-replace-article gnus-newsgroup-name)))
9280          (error "The current group does not support article editing")))
9281   (let ((articles (gnus-summary-work-articles n))
9282         (prefix (if (gnus-check-backend-function
9283                      'request-move-article gnus-newsgroup-name)
9284                     (funcall gnus-move-group-prefix-function
9285                              gnus-newsgroup-name)
9286                   ""))
9287         (names '((move "Move" "Moving")
9288                  (copy "Copy" "Copying")
9289                  (crosspost "Crosspost" "Crossposting")))
9290         (copy-buf (save-excursion
9291                     (nnheader-set-temp-buffer " *copy article*")))
9292         art-group to-method new-xref article to-groups articles-to-update-marks)
9293     (unless (assq action names)
9294       (error "Unknown action %s" action))
9295     ;; Read the newsgroup name.
9296     (when (and (not to-newsgroup)
9297                (not select-method))
9298       (if (and gnus-move-split-methods
9299                (not
9300                 (and (memq gnus-current-article articles)
9301                      (gnus-buffer-live-p gnus-original-article-buffer))))
9302           ;; When `gnus-move-split-methods' is non-nil, we have to
9303           ;; select an article to give `gnus-read-move-group-name' an
9304           ;; opportunity to suggest an appropriate default.  However,
9305           ;; we needn't render or mark the article.
9306           (let ((gnus-display-mime-function nil)
9307                 (gnus-article-prepare-hook nil)
9308                 (gnus-mark-article-hook nil))
9309             (gnus-summary-select-article nil nil nil (car articles))))
9310       (setq to-newsgroup
9311             (gnus-read-move-group-name
9312              (cadr (assq action names))
9313              (symbol-value (intern (format "gnus-current-%s-group" action)))
9314              articles prefix))
9315       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9316     (setq to-method (or select-method
9317                         (gnus-server-to-method
9318                          (gnus-group-method to-newsgroup))))
9319     ;; Check the method we are to move this article to...
9320     (unless (gnus-check-backend-function
9321              'request-accept-article (car to-method))
9322       (error "%s does not support article copying" (car to-method)))
9323     (unless (gnus-check-server to-method)
9324       (error "Can't open server %s" (car to-method)))
9325     (gnus-message 6 "%s to %s: %s..."
9326                   (caddr (assq action names))
9327                   (or (car select-method) to-newsgroup) articles)
9328     (while articles
9329       (setq article (pop articles))
9330       (setq
9331        art-group
9332        (cond
9333         ;; Move the article.
9334         ((eq action 'move)
9335          ;; Remove this article from future suppression.
9336          (gnus-dup-unsuppress-article article)
9337          (let* ((from-method (gnus-find-method-for-group
9338                               gnus-newsgroup-name))
9339                 (to-method (gnus-find-method-for-group
9340                             to-newsgroup))
9341                 (move-is-internal (gnus-method-equal from-method to-method)))
9342            (gnus-request-move-article
9343             article                     ; Article to move
9344             gnus-newsgroup-name         ; From newsgroup
9345             (nth 1 (gnus-find-method-for-group
9346                     gnus-newsgroup-name)) ; Server
9347             (list 'gnus-request-accept-article
9348                   to-newsgroup (list 'quote select-method)
9349                   (not articles) t)     ; Accept form
9350             (not articles)              ; Only save nov last time
9351             move-is-internal)))         ; is this move internal?
9352         ;; Copy the article.
9353         ((eq action 'copy)
9354          (save-excursion
9355            (set-buffer copy-buf)
9356            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9357              (save-restriction
9358                (nnheader-narrow-to-headers)
9359                (dolist (hdr gnus-copy-article-ignored-headers)
9360                  (message-remove-header hdr t)))
9361              (gnus-request-accept-article
9362               to-newsgroup select-method (not articles) t))))
9363         ;; Crosspost the article.
9364         ((eq action 'crosspost)
9365          (let ((xref (message-tokenize-header
9366                       (mail-header-xref (gnus-summary-article-header article))
9367                       " ")))
9368            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9369                                   ":" (number-to-string article)))
9370            (unless xref
9371              (setq xref (list (system-name))))
9372            (setq new-xref
9373                  (concat
9374                   (mapconcat 'identity
9375                              (delete "Xref:" (delete new-xref xref))
9376                              " ")
9377                   " " new-xref))
9378            (save-excursion
9379              (set-buffer copy-buf)
9380              ;; First put the article in the destination group.
9381              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9382              (when (consp (setq art-group
9383                                 (gnus-request-accept-article
9384                                  to-newsgroup select-method (not articles) t)))
9385                (setq new-xref (concat new-xref " " (car art-group)
9386                                       ":"
9387                                       (number-to-string (cdr art-group))))
9388                ;; Now we have the new Xrefs header, so we insert
9389                ;; it and replace the new article.
9390                (nnheader-replace-header "Xref" new-xref)
9391                (gnus-request-replace-article
9392                 (cdr art-group) to-newsgroup (current-buffer) t)
9393                art-group))))))
9394       (cond
9395        ((not art-group)
9396         (gnus-message 1 "Couldn't %s article %s: %s"
9397                       (cadr (assq action names)) article
9398                       (nnheader-get-report (car to-method))))
9399        ((eq art-group 'junk)
9400         (when (eq action 'move)
9401           (gnus-summary-mark-article article gnus-canceled-mark)
9402           (gnus-message 4 "Deleted article %s" article)
9403           ;; run the delete hook
9404           (run-hook-with-args 'gnus-summary-article-delete-hook
9405                               action
9406                               (gnus-data-header
9407                                (assoc article (gnus-data-list nil)))
9408                               gnus-newsgroup-name nil
9409                               select-method)))
9410        (t
9411         (let* ((pto-group (gnus-group-prefixed-name
9412                            (car art-group) to-method))
9413                (info (gnus-get-info pto-group))
9414                (to-group (gnus-info-group info))
9415                to-marks)
9416           ;; Update the group that has been moved to.
9417           (when (and info
9418                      (memq action '(move copy)))
9419             (unless (member to-group to-groups)
9420               (push to-group to-groups))
9421
9422             (unless (memq article gnus-newsgroup-unreads)
9423               (push 'read to-marks)
9424               (gnus-info-set-read
9425                info (gnus-add-to-range (gnus-info-read info)
9426                                        (list (cdr art-group)))))
9427
9428             ;; See whether the article is to be put in the cache.
9429             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9430                              gnus-article-mark-lists
9431                            (delete '(expirable . expire)
9432                                    (copy-sequence gnus-article-mark-lists))))
9433                   (to-article (cdr art-group)))
9434
9435               ;; Enter the article into the cache in the new group,
9436               ;; if that is required.
9437               (when gnus-use-cache
9438                 (gnus-cache-possibly-enter-article
9439                  to-group to-article
9440                  (memq article gnus-newsgroup-marked)
9441                  (memq article gnus-newsgroup-dormant)
9442                  (memq article gnus-newsgroup-unreads)))
9443
9444               (when gnus-preserve-marks
9445                 ;; Copy any marks over to the new group.
9446                 (when (and (equal to-group gnus-newsgroup-name)
9447                            (not (memq article gnus-newsgroup-unreads)))
9448                   ;; Mark this article as read in this group.
9449                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9450                   (setcdr (gnus-active to-group) to-article)
9451                   (setcdr gnus-newsgroup-active to-article))
9452
9453                 (while marks
9454                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9455                     (when (memq article (symbol-value
9456                                          (intern (format "gnus-newsgroup-%s"
9457                                                          (caar marks)))))
9458                       (push (cdar marks) to-marks)
9459                       ;; If the other group is the same as this group,
9460                       ;; then we have to add the mark to the list.
9461                       (when (equal to-group gnus-newsgroup-name)
9462                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9463                              (cons to-article
9464                                    (symbol-value
9465                                     (intern (format "gnus-newsgroup-%s"
9466                                                     (caar marks)))))))
9467                       ;; Copy the marks to other group.
9468                       (gnus-add-marked-articles
9469                        to-group (cdar marks) (list to-article) info)))
9470                   (setq marks (cdr marks)))
9471
9472                 (gnus-request-set-mark
9473                  to-group (list (list (list to-article) 'add to-marks))))
9474
9475               (gnus-dribble-enter
9476                (concat "(gnus-group-set-info '"
9477                        (gnus-prin1-to-string (gnus-get-info to-group))
9478                        ")"))))
9479
9480           ;; Update the Xref header in this article to point to
9481           ;; the new crossposted article we have just created.
9482           (when (eq action 'crosspost)
9483             (save-excursion
9484               (set-buffer copy-buf)
9485               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9486               (nnheader-replace-header "Xref" new-xref)
9487               (gnus-request-replace-article
9488                article gnus-newsgroup-name (current-buffer) t)))
9489
9490           ;; run the move/copy/crosspost/respool hook
9491           (run-hook-with-args 'gnus-summary-article-move-hook
9492                               action
9493                               (gnus-data-header
9494                                (assoc article (gnus-data-list nil)))
9495                               gnus-newsgroup-name
9496                               to-newsgroup
9497                               select-method))
9498
9499         ;;;!!!Why is this necessary?
9500         (set-buffer gnus-summary-buffer)
9501
9502         (gnus-summary-goto-subject article)
9503         (when (eq action 'move)
9504           (gnus-summary-mark-article article gnus-canceled-mark))))
9505       (push article articles-to-update-marks))
9506
9507     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9508     ;; Re-activate all groups that have been moved to.
9509     (save-excursion
9510       (set-buffer gnus-group-buffer)
9511       (let ((gnus-group-marked to-groups))
9512         (gnus-group-get-new-news-this-group nil t)))
9513
9514     (gnus-kill-buffer copy-buf)
9515     (gnus-summary-position-point)
9516     (gnus-set-mode-line 'summary)))
9517
9518 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9519   "Copy the current article to some other group.
9520 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9521 When called interactively, if TO-NEWSGROUP is nil, use the value of
9522 the variable `gnus-move-split-methods' for finding a default target
9523 newsgroup.
9524 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9525 re-spool using this method."
9526   (interactive "P")
9527   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9528
9529 (defun gnus-summary-crosspost-article (&optional n)
9530   "Crosspost the current article to some other group."
9531   (interactive "P")
9532   (gnus-summary-move-article n nil nil 'crosspost))
9533
9534 (defcustom gnus-summary-respool-default-method nil
9535   "Default method type for respooling an article.
9536 If nil, use to the current newsgroup method."
9537   :type 'symbol
9538   :group 'gnus-summary-mail)
9539
9540 (defcustom gnus-summary-display-while-building nil
9541   "If non-nil, show and update the summary buffer as it's being built.
9542 If the value is t, update the buffer after every line is inserted.  If
9543 the value is an integer (N), update the display every N lines."
9544   :version "22.1"
9545   :group 'gnus-thread
9546   :type '(choice (const :tag "off" nil)
9547                  number
9548                  (const :tag "frequently" t)))
9549
9550 (defun gnus-summary-respool-article (&optional n method)
9551   "Respool the current article.
9552 The article will be squeezed through the mail spooling process again,
9553 which means that it will be put in some mail newsgroup or other
9554 depending on `nnmail-split-methods'.
9555 If N is a positive number, respool the N next articles.
9556 If N is a negative number, respool the N previous articles.
9557 If N is nil and any articles have been marked with the process mark,
9558 respool those articles instead.
9559
9560 Respooling can be done both from mail groups and \"real\" newsgroups.
9561 In the former case, the articles in question will be moved from the
9562 current group into whatever groups they are destined to.  In the
9563 latter case, they will be copied into the relevant groups."
9564   (interactive
9565    (list current-prefix-arg
9566          (let* ((methods (gnus-methods-using 'respool))
9567                 (methname
9568                  (symbol-name (or gnus-summary-respool-default-method
9569                                   (car (gnus-find-method-for-group
9570                                         gnus-newsgroup-name)))))
9571                 (method
9572                  (gnus-completing-read-with-default
9573                   methname "Backend to use when respooling"
9574                   methods nil t nil 'gnus-mail-method-history))
9575                 ms)
9576            (cond
9577             ((zerop (length (setq ms (gnus-servers-using-backend
9578                                       (intern method)))))
9579              (list (intern method) ""))
9580             ((= 1 (length ms))
9581              (car ms))
9582             (t
9583              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9584                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9585                            ms-alist))))))))
9586   (unless method
9587     (error "No method given for respooling"))
9588   (if (assoc (symbol-name
9589               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9590              (gnus-methods-using 'respool))
9591       (gnus-summary-move-article n nil method)
9592     (gnus-summary-copy-article n nil method)))
9593
9594 (defun gnus-summary-import-article (file &optional edit)
9595   "Import an arbitrary file into a mail newsgroup."
9596   (interactive "fImport file: \nP")
9597   (let ((group gnus-newsgroup-name)
9598         (now (current-time))
9599         atts lines group-art)
9600     (unless (gnus-check-backend-function 'request-accept-article group)
9601       (error "%s does not support article importing" group))
9602     (or (file-readable-p file)
9603         (not (file-regular-p file))
9604         (error "Can't read %s" file))
9605     (save-excursion
9606       (set-buffer (gnus-get-buffer-create " *import file*"))
9607       (erase-buffer)
9608       (nnheader-insert-file-contents file)
9609       (goto-char (point-min))
9610       (if (nnheader-article-p)
9611           (save-restriction
9612             (goto-char (point-min))
9613             (search-forward "\n\n" nil t)
9614             (narrow-to-region (point-min) (1- (point)))
9615             (goto-char (point-min))
9616             (unless (re-search-forward "^date:" nil t)
9617               (goto-char (point-max))
9618               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9619        ;; This doesn't look like an article, so we fudge some headers.
9620         (setq atts (file-attributes file)
9621               lines (count-lines (point-min) (point-max)))
9622         (insert "From: " (read-string "From: ") "\n"
9623                 "Subject: " (read-string "Subject: ") "\n"
9624                 "Date: " (message-make-date (nth 5 atts)) "\n"
9625                 "Message-ID: " (message-make-message-id) "\n"
9626                 "Lines: " (int-to-string lines) "\n"
9627                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9628       (setq group-art (gnus-request-accept-article group nil t))
9629       (kill-buffer (current-buffer)))
9630     (setq gnus-newsgroup-active (gnus-activate-group group))
9631     (forward-line 1)
9632     (gnus-summary-goto-article (cdr group-art) nil t)
9633     (when edit
9634       (gnus-summary-edit-article))))
9635
9636 (defun gnus-summary-create-article ()
9637   "Create an article in a mail newsgroup."
9638   (interactive)
9639   (let ((group gnus-newsgroup-name)
9640         (now (current-time))
9641         group-art)
9642     (unless (gnus-check-backend-function 'request-accept-article group)
9643       (error "%s does not support article importing" group))
9644     (save-excursion
9645       (set-buffer (gnus-get-buffer-create " *import file*"))
9646       (erase-buffer)
9647       (goto-char (point-min))
9648       ;; This doesn't look like an article, so we fudge some headers.
9649       (insert "From: " (read-string "From: ") "\n"
9650               "Subject: " (read-string "Subject: ") "\n"
9651               "Date: " (message-make-date now) "\n"
9652               "Message-ID: " (message-make-message-id) "\n")
9653       (setq group-art (gnus-request-accept-article group nil t))
9654       (kill-buffer (current-buffer)))
9655     (setq gnus-newsgroup-active (gnus-activate-group group))
9656     (forward-line 1)
9657     (gnus-summary-goto-article (cdr group-art) nil t)
9658     (gnus-summary-edit-article)))
9659
9660 (defun gnus-summary-article-posted-p ()
9661   "Say whether the current (mail) article is available from news as well.
9662 This will be the case if the article has both been mailed and posted."
9663   (interactive)
9664   (let ((id (mail-header-references (gnus-summary-article-header)))
9665         (gnus-override-method (car (gnus-refer-article-methods))))
9666     (if (gnus-request-head id "")
9667         (gnus-message 2 "The current message was found on %s"
9668                       gnus-override-method)
9669       (gnus-message 2 "The current message couldn't be found on %s"
9670                     gnus-override-method)
9671       nil)))
9672
9673 (defun gnus-summary-expire-articles (&optional now)
9674   "Expire all articles that are marked as expirable in the current group."
9675   (interactive)
9676   (when (and (not gnus-group-is-exiting-without-update-p)
9677              (gnus-check-backend-function
9678               'request-expire-articles gnus-newsgroup-name))
9679     ;; This backend supports expiry.
9680     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9681            (expirable (if total
9682                           (progn
9683                             ;; We need to update the info for
9684                             ;; this group for `gnus-list-of-read-articles'
9685                             ;; to give us the right answer.
9686                             (gnus-run-hooks 'gnus-exit-group-hook)
9687                             (gnus-summary-update-info)
9688                             (gnus-list-of-read-articles gnus-newsgroup-name))
9689                         (setq gnus-newsgroup-expirable
9690                               (sort gnus-newsgroup-expirable '<))))
9691            (expiry-wait (if now 'immediate
9692                           (gnus-group-find-parameter
9693                            gnus-newsgroup-name 'expiry-wait)))
9694            (nnmail-expiry-target
9695             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9696                 nnmail-expiry-target))
9697            es)
9698       (when expirable
9699         ;; There are expirable articles in this group, so we run them
9700         ;; through the expiry process.
9701         (gnus-message 6 "Expiring articles...")
9702         (unless (gnus-check-group gnus-newsgroup-name)
9703           (error "Can't open server for %s" gnus-newsgroup-name))
9704         ;; The list of articles that weren't expired is returned.
9705         (save-excursion
9706           (if expiry-wait
9707               (let ((nnmail-expiry-wait-function nil)
9708                     (nnmail-expiry-wait expiry-wait))
9709                 (setq es (gnus-request-expire-articles
9710                           expirable gnus-newsgroup-name)))
9711             (setq es (gnus-request-expire-articles
9712                       expirable gnus-newsgroup-name)))
9713           (unless total
9714             (setq gnus-newsgroup-expirable es))
9715           ;; We go through the old list of expirable, and mark all
9716           ;; really expired articles as nonexistent.
9717           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9718             (let ((gnus-use-cache nil))
9719               (dolist (article expirable)
9720                 (when (and (not (memq article es))
9721                            (gnus-data-find article))
9722                   (gnus-summary-mark-article article gnus-canceled-mark)
9723                   (run-hook-with-args 'gnus-summary-article-expire-hook
9724                                       'delete
9725                                       (gnus-data-header
9726                                        (assoc article (gnus-data-list nil)))
9727                                       gnus-newsgroup-name
9728                                       nil
9729                                       nil))))))
9730         (gnus-message 6 "Expiring articles...done")))))
9731
9732 (defun gnus-summary-expire-articles-now ()
9733   "Expunge all expirable articles in the current group.
9734 This means that *all* articles that are marked as expirable will be
9735 deleted forever, right now."
9736   (interactive)
9737   (or gnus-expert-user
9738       (gnus-yes-or-no-p
9739        "Are you really, really sure you want to delete all expirable messages? ")
9740       (error "Phew!"))
9741   (gnus-summary-expire-articles t))
9742
9743 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9744 (defun gnus-summary-delete-article (&optional n)
9745   "Delete the N next (mail) articles.
9746 This command actually deletes articles.  This is not a marking
9747 command.  The article will disappear forever from your life, never to
9748 return.
9749
9750 If N is negative, delete backwards.
9751 If N is nil and articles have been marked with the process mark,
9752 delete these instead.
9753
9754 If `gnus-novice-user' is non-nil you will be asked for
9755 confirmation before the articles are deleted."
9756   (interactive "P")
9757   (unless (gnus-check-backend-function 'request-expire-articles
9758                                        gnus-newsgroup-name)
9759     (error "The current newsgroup does not support article deletion"))
9760   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9761     (error "Couldn't open server"))
9762   ;; Compute the list of articles to delete.
9763   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9764         (nnmail-expiry-target 'delete)
9765         not-deleted)
9766     (if (and gnus-novice-user
9767              (not (gnus-yes-or-no-p
9768                    (format "Do you really want to delete %s forever? "
9769                            (if (> (length articles) 1)
9770                                (format "these %s articles" (length articles))
9771                              "this article")))))
9772         ()
9773       ;; Delete the articles.
9774       (setq not-deleted (gnus-request-expire-articles
9775                          articles gnus-newsgroup-name 'force))
9776       (while articles
9777         (gnus-summary-remove-process-mark (car articles))
9778         ;; The backend might not have been able to delete the article
9779         ;; after all.
9780         (unless (memq (car articles) not-deleted)
9781           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9782         (let* ((article (car articles))
9783                (ghead  (gnus-data-header
9784                                     (assoc article (gnus-data-list nil)))))
9785           (run-hook-with-args 'gnus-summary-article-delete-hook
9786                               'delete ghead gnus-newsgroup-name nil
9787                               nil))
9788         (setq articles (cdr articles)))
9789       (when not-deleted
9790         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9791     (gnus-summary-position-point)
9792     (gnus-set-mode-line 'summary)
9793     not-deleted))
9794
9795 (defun gnus-summary-edit-article (&optional arg)
9796   "Edit the current article.
9797 This will have permanent effect only in mail groups.
9798 If ARG is nil, edit the decoded articles.
9799 If ARG is 1, edit the raw articles.
9800 If ARG is 2, edit the raw articles even in read-only groups.
9801 If ARG is 3, edit the articles with the current handles.
9802 Otherwise, allow editing of articles even in read-only
9803 groups."
9804   (interactive "P")
9805   (let (force raw current-handles)
9806     (cond
9807      ((null arg))
9808      ((eq arg 1)
9809       (setq raw t))
9810      ((eq arg 2)
9811       (setq raw t
9812             force t))
9813      ((eq arg 3)
9814       (setq current-handles
9815             (and (gnus-buffer-live-p gnus-article-buffer)
9816                  (with-current-buffer gnus-article-buffer
9817                    (prog1
9818                        gnus-article-mime-handles
9819                      (setq gnus-article-mime-handles nil))))))
9820      (t
9821       (setq force t)))
9822     (when (and raw (not force)
9823                (member gnus-newsgroup-name '("nndraft:delayed"
9824                                              "nndraft:drafts"
9825                                              "nndraft:queue")))
9826       (error "Can't edit the raw article in group %s"
9827              gnus-newsgroup-name))
9828     (save-excursion
9829       (set-buffer gnus-summary-buffer)
9830       (let ((mail-parse-charset gnus-newsgroup-charset)
9831             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9832         (gnus-set-global-variables)
9833         (when (and (not force)
9834                    (gnus-group-read-only-p))
9835           (error "The current newsgroup does not support article editing"))
9836         (gnus-summary-show-article t)
9837         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9838           (with-current-buffer gnus-article-buffer
9839             (mm-enable-multibyte)))
9840         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9841             (setq raw t))
9842         (gnus-article-edit-article
9843          (if raw 'ignore
9844            `(lambda ()
9845               (let ((mbl mml-buffer-list))
9846                 (setq mml-buffer-list nil)
9847                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9848                   (mime-to-mml ,'current-handles))
9849                 (let ((mbl1 mml-buffer-list))
9850                   (setq mml-buffer-list mbl)
9851                   (set (make-local-variable 'mml-buffer-list) mbl1))
9852                 (gnus-make-local-hook 'kill-buffer-hook)
9853                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9854          `(lambda (no-highlight)
9855             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9856                   (message-options message-options)
9857                   (message-options-set-recipient)
9858                   (mail-parse-ignored-charsets
9859                    ',gnus-newsgroup-ignored-charsets))
9860               ,(if (not raw) '(progn
9861                                 (mml-to-mime)
9862                                 (mml-destroy-buffers)
9863                                 (remove-hook 'kill-buffer-hook
9864                                              'mml-destroy-buffers t)
9865                                 (kill-local-variable 'mml-buffer-list)))
9866               (gnus-summary-edit-article-done
9867                ,(or (mail-header-references gnus-current-headers) "")
9868                ,(gnus-group-read-only-p)
9869                ,gnus-summary-buffer no-highlight))))))))
9870
9871 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9872
9873 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9874                                                  no-highlight)
9875   "Make edits to the current article permanent."
9876   (interactive)
9877   (save-excursion
9878    ;; The buffer restriction contains the entire article if it exists.
9879     (when (article-goto-body)
9880       (let ((lines (count-lines (point) (point-max)))
9881             (length (- (point-max) (point)))
9882             (case-fold-search t)
9883             (body (copy-marker (point))))
9884         (goto-char (point-min))
9885         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9886           (delete-region (match-beginning 1) (match-end 1))
9887           (insert (number-to-string length)))
9888         (goto-char (point-min))
9889         (when (re-search-forward
9890                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9891           (delete-region (match-beginning 1) (match-end 1))
9892           (insert (number-to-string length)))
9893         (goto-char (point-min))
9894         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9895           (delete-region (match-beginning 1) (match-end 1))
9896           (insert (number-to-string lines))))))
9897   ;; Replace the article.
9898   (let ((buf (current-buffer)))
9899     (with-temp-buffer
9900       (insert-buffer-substring buf)
9901
9902       (if (and (not read-only)
9903                (not (gnus-request-replace-article
9904                      (cdr gnus-article-current) (car gnus-article-current)
9905                      (current-buffer) t)))
9906           (error "Couldn't replace article")
9907         ;; Update the summary buffer.
9908         (if (and references
9909                  (equal (message-tokenize-header references " ")
9910                         (message-tokenize-header
9911                          (or (message-fetch-field "references") "") " ")))
9912             ;; We only have to update this line.
9913             (save-excursion
9914               (save-restriction
9915                 (message-narrow-to-head)
9916                 (let ((head (buffer-substring-no-properties
9917                              (point-min) (point-max)))
9918                       header)
9919                   (with-temp-buffer
9920                     (insert (format "211 %d Article retrieved.\n"
9921                                     (cdr gnus-article-current)))
9922                     (insert head)
9923                     (insert ".\n")
9924                     (let ((nntp-server-buffer (current-buffer)))
9925                       (setq header (car (gnus-get-newsgroup-headers
9926                                          nil t))))
9927                     (save-excursion
9928                       (set-buffer gnus-summary-buffer)
9929                       (gnus-data-set-header
9930                        (gnus-data-find (cdr gnus-article-current))
9931                        header)
9932                       (gnus-summary-update-article-line
9933                        (cdr gnus-article-current) header)
9934                       (if (gnus-summary-goto-subject
9935                            (cdr gnus-article-current) nil t)
9936                           (gnus-summary-update-secondary-mark
9937                            (cdr gnus-article-current))))))))
9938           ;; Update threads.
9939           (set-buffer (or buffer gnus-summary-buffer))
9940           (gnus-summary-update-article (cdr gnus-article-current))
9941           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9942               (gnus-summary-update-secondary-mark
9943                (cdr gnus-article-current))))
9944         ;; Prettify the article buffer again.
9945         (unless no-highlight
9946           (save-excursion
9947             (set-buffer gnus-article-buffer)
9948             ;;;!!! Fix this -- article should be rehighlighted.
9949             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9950             (set-buffer gnus-original-article-buffer)
9951             (gnus-request-article
9952              (cdr gnus-article-current)
9953              (car gnus-article-current) (current-buffer))))
9954         ;; Prettify the summary buffer line.
9955         (when (gnus-visual-p 'summary-highlight 'highlight)
9956           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9957
9958 (defun gnus-summary-edit-wash (key)
9959   "Perform editing command KEY in the article buffer."
9960   (interactive
9961    (list
9962     (progn
9963       (message "%s" (concat (this-command-keys) "- "))
9964       (read-char))))
9965   (message "")
9966   (gnus-summary-edit-article)
9967   (execute-kbd-macro (concat (this-command-keys) key))
9968   (gnus-article-edit-done))
9969
9970 ;;; Respooling
9971
9972 (defun gnus-summary-respool-query (&optional silent trace)
9973   "Query where the respool algorithm would put this article."
9974   (interactive)
9975   (let (gnus-mark-article-hook)
9976     (gnus-summary-select-article)
9977     (save-excursion
9978       (set-buffer gnus-original-article-buffer)
9979       (let ((groups (nnmail-article-group 'identity trace)))
9980         (unless silent
9981           (if groups
9982               (message "This message would go to %s"
9983                        (mapconcat 'car groups ", "))
9984             (message "This message would go to no groups"))
9985           groups)))))
9986
9987 (defun gnus-summary-respool-trace ()
9988   "Trace where the respool algorithm would put this article.
9989 Display a buffer showing all fancy splitting patterns which matched."
9990   (interactive)
9991   (gnus-summary-respool-query nil t))
9992
9993 ;; Summary marking commands.
9994
9995 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9996   "Mark articles which has the same subject as read, and then select the next.
9997 If UNMARK is positive, remove any kind of mark.
9998 If UNMARK is negative, tick articles."
9999   (interactive "P")
10000   (when unmark
10001     (setq unmark (prefix-numeric-value unmark)))
10002   (let ((count
10003          (gnus-summary-mark-same-subject
10004           (gnus-summary-article-subject) unmark)))
10005     ;; Select next unread article.  If auto-select-same mode, should
10006     ;; select the first unread article.
10007     (gnus-summary-next-article t (and gnus-auto-select-same
10008                                       (gnus-summary-article-subject)))
10009     (gnus-message 7 "%d article%s marked as %s"
10010                   count (if (= count 1) " is" "s are")
10011                   (if unmark "unread" "read"))))
10012
10013 (defun gnus-summary-kill-same-subject (&optional unmark)
10014   "Mark articles which has the same subject as read.
10015 If UNMARK is positive, remove any kind of mark.
10016 If UNMARK is negative, tick articles."
10017   (interactive "P")
10018   (when unmark
10019     (setq unmark (prefix-numeric-value unmark)))
10020   (let ((count
10021          (gnus-summary-mark-same-subject
10022           (gnus-summary-article-subject) unmark)))
10023     ;; If marked as read, go to next unread subject.
10024     (when (null unmark)
10025       ;; Go to next unread subject.
10026       (gnus-summary-next-subject 1 t))
10027     (gnus-message 7 "%d articles are marked as %s"
10028                   count (if unmark "unread" "read"))))
10029
10030 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10031   "Mark articles with same SUBJECT as read, and return marked number.
10032 If optional argument UNMARK is positive, remove any kinds of marks.
10033 If optional argument UNMARK is negative, mark articles as unread instead."
10034   (let ((count 1))
10035     (save-excursion
10036       (cond
10037        ((null unmark)                   ; Mark as read.
10038         (while (and
10039                 (progn
10040                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10041                   (gnus-summary-show-thread) t)
10042                 (gnus-summary-find-subject subject))
10043           (setq count (1+ count))))
10044        ((> unmark 0)                    ; Tick.
10045         (while (and
10046                 (progn
10047                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10048                   (gnus-summary-show-thread) t)
10049                 (gnus-summary-find-subject subject))
10050           (setq count (1+ count))))
10051        (t                               ; Mark as unread.
10052         (while (and
10053                 (progn
10054                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10055                   (gnus-summary-show-thread) t)
10056                 (gnus-summary-find-subject subject))
10057           (setq count (1+ count)))))
10058       (gnus-set-mode-line 'summary)
10059       ;; Return the number of marked articles.
10060       count)))
10061
10062 (defun gnus-summary-mark-as-processable (n &optional unmark)
10063   "Set the process mark on the next N articles.
10064 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10065 the process mark instead.  The difference between N and the actual
10066 number of articles marked is returned."
10067   (interactive "P")
10068   (if (and (null n) (gnus-region-active-p))
10069       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10070     (setq n (prefix-numeric-value n))
10071     (let ((backward (< n 0))
10072           (n (abs n)))
10073       (while (and
10074               (> n 0)
10075               (if unmark
10076                   (gnus-summary-remove-process-mark
10077                    (gnus-summary-article-number))
10078                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10079               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10080         (setq n (1- n)))
10081       (when (/= 0 n)
10082         (gnus-message 7 "No more articles"))
10083       (gnus-summary-recenter)
10084       (gnus-summary-position-point)
10085       n)))
10086
10087 (defun gnus-summary-unmark-as-processable (n)
10088   "Remove the process mark from the next N articles.
10089 If N is negative, unmark backward instead.  The difference between N and
10090 the actual number of articles unmarked is returned."
10091   (interactive "P")
10092   (gnus-summary-mark-as-processable n t))
10093
10094 (defun gnus-summary-unmark-all-processable ()
10095   "Remove the process mark from all articles."
10096   (interactive)
10097   (save-excursion
10098     (while gnus-newsgroup-processable
10099       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10100   (gnus-summary-position-point))
10101
10102 (defun gnus-summary-add-mark (article type)
10103   "Mark ARTICLE with a mark of TYPE."
10104   (let ((vtype (car (assq type gnus-article-mark-lists)))
10105         var)
10106     (if (not vtype)
10107         (error "No such mark type: %s" type)
10108       (setq var (intern (format "gnus-newsgroup-%s" type)))
10109       (set var (cons article (symbol-value var)))
10110       (if (memq type '(processable cached replied forwarded recent saved))
10111           (gnus-summary-update-secondary-mark article)
10112         ;;; !!! This is bogus.  We should find out what primary
10113         ;;; !!! mark we want to set.
10114         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10115
10116 (defun gnus-summary-mark-as-expirable (n)
10117   "Mark N articles forward as expirable.
10118 If N is negative, mark backward instead.  The difference between N and
10119 the actual number of articles marked is returned."
10120   (interactive "p")
10121   (gnus-summary-mark-forward n gnus-expirable-mark))
10122
10123 (defun gnus-summary-mark-as-spam (n)
10124   "Mark N articles forward as spam.
10125 If N is negative, mark backward instead.  The difference between N and
10126 the actual number of articles marked is returned."
10127   (interactive "p")
10128   (gnus-summary-mark-forward n gnus-spam-mark))
10129
10130 (defun gnus-summary-mark-article-as-replied (article)
10131   "Mark ARTICLE as replied to and update the summary line.
10132 ARTICLE can also be a list of articles."
10133   (interactive (list (gnus-summary-article-number)))
10134   (let ((articles (if (listp article) article (list article))))
10135     (dolist (article articles)
10136       (unless (numberp article)
10137         (error "%s is not a number" article))
10138       (push article gnus-newsgroup-replied)
10139       (let ((buffer-read-only nil))
10140         (when (gnus-summary-goto-subject article nil t)
10141           (gnus-summary-update-secondary-mark article))))))
10142
10143 (defun gnus-summary-mark-article-as-forwarded (article)
10144   "Mark ARTICLE as forwarded and update the summary line.
10145 ARTICLE can also be a list of articles."
10146   (let ((articles (if (listp article) article (list article))))
10147     (dolist (article articles)
10148       (push article gnus-newsgroup-forwarded)
10149       (let ((buffer-read-only nil))
10150         (when (gnus-summary-goto-subject article nil t)
10151           (gnus-summary-update-secondary-mark article))))))
10152
10153 (defun gnus-summary-set-bookmark (article)
10154   "Set a bookmark in current article."
10155   (interactive (list (gnus-summary-article-number)))
10156   (when (or (not (get-buffer gnus-article-buffer))
10157             (not gnus-current-article)
10158             (not gnus-article-current)
10159             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10160     (error "No current article selected"))
10161   ;; Remove old bookmark, if one exists.
10162   (gnus-pull article gnus-newsgroup-bookmarks)
10163   ;; Set the new bookmark, which is on the form
10164   ;; (article-number . line-number-in-body).
10165   (push
10166    (cons article
10167          (with-current-buffer gnus-article-buffer
10168            (count-lines
10169             (min (point)
10170                  (save-excursion
10171                    (article-goto-body)
10172                    (point)))
10173             (point))))
10174    gnus-newsgroup-bookmarks)
10175   (gnus-message 6 "A bookmark has been added to the current article."))
10176
10177 (defun gnus-summary-remove-bookmark (article)
10178   "Remove the bookmark from the current article."
10179   (interactive (list (gnus-summary-article-number)))
10180   ;; Remove old bookmark, if one exists.
10181   (if (not (assq article gnus-newsgroup-bookmarks))
10182       (gnus-message 6 "No bookmark in current article.")
10183     (gnus-pull article gnus-newsgroup-bookmarks)
10184     (gnus-message 6 "Removed bookmark.")))
10185
10186 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10187 (defun gnus-summary-mark-as-dormant (n)
10188   "Mark N articles forward as dormant.
10189 If N is negative, mark backward instead.  The difference between N and
10190 the actual number of articles marked is returned."
10191   (interactive "p")
10192   (gnus-summary-mark-forward n gnus-dormant-mark))
10193
10194 (defun gnus-summary-set-process-mark (article)
10195   "Set the process mark on ARTICLE and update the summary line."
10196   (setq gnus-newsgroup-processable
10197         (cons article
10198               (delq article gnus-newsgroup-processable)))
10199   (when (gnus-summary-goto-subject article)
10200     (gnus-summary-show-thread)
10201     (gnus-summary-goto-subject article)
10202     (gnus-summary-update-secondary-mark article)))
10203
10204 (defun gnus-summary-remove-process-mark (&rest articles)
10205   "Remove the process mark from ARTICLES and update the summary line."
10206   (dolist (article articles)
10207     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10208     (when (gnus-summary-goto-subject article)
10209       (gnus-summary-show-thread)
10210       (gnus-summary-goto-subject article)
10211       (gnus-summary-update-secondary-mark article)))
10212   t)
10213
10214 (defun gnus-summary-set-saved-mark (article)
10215   "Set the process mark on ARTICLE and update the summary line."
10216   (push article gnus-newsgroup-saved)
10217   (when (gnus-summary-goto-subject article)
10218     (gnus-summary-update-secondary-mark article)))
10219
10220 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10221   "Mark N articles as read forwards.
10222 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10223 The difference between N and the actual number of articles marked is
10224 returned.
10225 If NO-EXPIRE, auto-expiry will be inhibited."
10226   (interactive "p")
10227   (gnus-summary-show-thread)
10228   (let ((backward (< n 0))
10229         (gnus-summary-goto-unread
10230          (and gnus-summary-goto-unread
10231               (not (eq gnus-summary-goto-unread 'never))
10232               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10233                                     gnus-ticked-mark gnus-dormant-mark)))))
10234         (n (abs n))
10235         (mark (or mark gnus-del-mark)))
10236     (while (and (> n 0)
10237                 (gnus-summary-mark-article nil mark no-expire)
10238                 (zerop (gnus-summary-next-subject
10239                         (if backward -1 1)
10240                         (and gnus-summary-goto-unread
10241                              (not (eq gnus-summary-goto-unread 'never)))
10242                         t)))
10243       (setq n (1- n)))
10244     (when (/= 0 n)
10245       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10246     (gnus-summary-recenter)
10247     (gnus-summary-position-point)
10248     (gnus-set-mode-line 'summary)
10249     n))
10250
10251 (defun gnus-summary-mark-article-as-read (mark)
10252   "Mark the current article quickly as read with MARK."
10253   (let ((article (gnus-summary-article-number)))
10254     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10255     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10256     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10257     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10258     (push (cons article mark) gnus-newsgroup-reads)
10259     ;; Possibly remove from cache, if that is used.
10260     (when gnus-use-cache
10261       (gnus-cache-enter-remove-article article))
10262     ;; Allow the backend to change the mark.
10263     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10264     ;; Check for auto-expiry.
10265     (when (and gnus-newsgroup-auto-expire
10266                (memq mark gnus-auto-expirable-marks))
10267       (setq mark gnus-expirable-mark)
10268       ;; Let the backend know about the mark change.
10269       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10270       (push article gnus-newsgroup-expirable))
10271     ;; Set the mark in the buffer.
10272     (gnus-summary-update-mark mark 'unread)
10273     t))
10274
10275 (defun gnus-summary-mark-article-as-unread (mark)
10276   "Mark the current article quickly as unread with MARK."
10277   (let* ((article (gnus-summary-article-number))
10278          (old-mark (gnus-summary-article-mark article)))
10279     ;; Allow the backend to change the mark.
10280     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10281     (if (eq mark old-mark)
10282         t
10283       (if (<= article 0)
10284           (progn
10285             (gnus-error 1 "Can't mark negative article numbers")
10286             nil)
10287         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10288         (setq gnus-newsgroup-spam-marked
10289               (delq article gnus-newsgroup-spam-marked))
10290         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10291         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10292         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10293         (cond ((= mark gnus-ticked-mark)
10294                (setq gnus-newsgroup-marked
10295                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10296                                               article)))
10297               ((= mark gnus-spam-mark)
10298                (setq gnus-newsgroup-spam-marked
10299                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10300                                               article)))
10301               ((= mark gnus-dormant-mark)
10302                (setq gnus-newsgroup-dormant
10303                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10304                                               article)))
10305               (t
10306                (setq gnus-newsgroup-unreads
10307                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10308                                               article))))
10309         (gnus-pull article gnus-newsgroup-reads)
10310
10311         ;; See whether the article is to be put in the cache.
10312         (and gnus-use-cache
10313              (vectorp (gnus-summary-article-header article))
10314              (save-excursion
10315                (gnus-cache-possibly-enter-article
10316                 gnus-newsgroup-name article
10317                 (= mark gnus-ticked-mark)
10318                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10319
10320         ;; Fix the mark.
10321         (gnus-summary-update-mark mark 'unread)
10322         t))))
10323
10324 (defun gnus-summary-mark-article (&optional article mark no-expire)
10325   "Mark ARTICLE with MARK.  MARK can be any character.
10326 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10327 `??' (dormant) and `?E' (expirable).
10328 If MARK is nil, then the default character `?r' is used.
10329 If ARTICLE is nil, then the article on the current line will be
10330 marked.
10331 If NO-EXPIRE, auto-expiry will be inhibited."
10332   ;; The mark might be a string.
10333   (when (stringp mark)
10334     (setq mark (aref mark 0)))
10335   ;; If no mark is given, then we check auto-expiring.
10336   (when (null mark)
10337     (setq mark gnus-del-mark))
10338   (when (and (not no-expire)
10339              gnus-newsgroup-auto-expire
10340              (memq mark gnus-auto-expirable-marks))
10341     (setq mark gnus-expirable-mark))
10342   (let ((article (or article (gnus-summary-article-number)))
10343         (old-mark (gnus-summary-article-mark article)))
10344     ;; Allow the backend to change the mark.
10345     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10346     (if (eq mark old-mark)
10347         t
10348       (unless article
10349         (error "No article on current line"))
10350       (if (not (if (or (= mark gnus-unread-mark)
10351                        (= mark gnus-ticked-mark)
10352                        (= mark gnus-spam-mark)
10353                        (= mark gnus-dormant-mark))
10354                    (gnus-mark-article-as-unread article mark)
10355                  (gnus-mark-article-as-read article mark)))
10356           t
10357         ;; See whether the article is to be put in the cache.
10358         (and gnus-use-cache
10359              (not (= mark gnus-canceled-mark))
10360              (vectorp (gnus-summary-article-header article))
10361              (save-excursion
10362                (gnus-cache-possibly-enter-article
10363                 gnus-newsgroup-name article
10364                 (= mark gnus-ticked-mark)
10365                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10366
10367         (when (gnus-summary-goto-subject article nil t)
10368           (let ((buffer-read-only nil))
10369             (gnus-summary-show-thread)
10370             ;; Fix the mark.
10371             (gnus-summary-update-mark mark 'unread)
10372             t))))))
10373
10374 (defun gnus-summary-update-secondary-mark (article)
10375   "Update the secondary (read, process, cache) mark."
10376   (gnus-summary-update-mark
10377    (cond ((memq article gnus-newsgroup-processable)
10378           gnus-process-mark)
10379          ((memq article gnus-newsgroup-cached)
10380           gnus-cached-mark)
10381          ((memq article gnus-newsgroup-replied)
10382           gnus-replied-mark)
10383          ((memq article gnus-newsgroup-forwarded)
10384           gnus-forwarded-mark)
10385          ((memq article gnus-newsgroup-saved)
10386           gnus-saved-mark)
10387          ((memq article gnus-newsgroup-recent)
10388           gnus-recent-mark)
10389          ((memq article gnus-newsgroup-unseen)
10390           gnus-unseen-mark)
10391          (t gnus-no-mark))
10392    'replied)
10393   (when (gnus-visual-p 'summary-highlight 'highlight)
10394     (gnus-run-hooks 'gnus-summary-update-hook))
10395   t)
10396
10397 (defun gnus-summary-update-download-mark (article)
10398   "Update the download mark."
10399   (gnus-summary-update-mark
10400    (cond ((memq article gnus-newsgroup-undownloaded)
10401           gnus-undownloaded-mark)
10402          (gnus-newsgroup-agentized
10403           gnus-downloaded-mark)
10404          (t
10405           gnus-no-mark))
10406    'download)
10407   (gnus-summary-update-line t)
10408   t)
10409
10410 (defun gnus-summary-update-mark (mark type)
10411   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10412         (buffer-read-only nil))
10413     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10414     (when forward
10415       (when (looking-at "\r")
10416         (incf forward))
10417       (when (<= (+ forward (point)) (point-max))
10418         ;; Go to the right position on the line.
10419         (goto-char (+ forward (point)))
10420         ;; Replace the old mark with the new mark.
10421         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10422         ;; Optionally update the marks by some user rule.
10423         (when (eq type 'unread)
10424           (gnus-data-set-mark
10425            (gnus-data-find (gnus-summary-article-number)) mark)
10426           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10427
10428 (defun gnus-mark-article-as-read (article &optional mark)
10429   "Enter ARTICLE in the pertinent lists and remove it from others."
10430   ;; Make the article expirable.
10431   (let ((mark (or mark gnus-del-mark)))
10432     (setq gnus-newsgroup-expirable
10433           (if (= mark gnus-expirable-mark)
10434               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10435             (delq article gnus-newsgroup-expirable)))
10436     ;; Remove from unread and marked lists.
10437     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10438     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10439     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10440     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10441     (push (cons article mark) gnus-newsgroup-reads)
10442     ;; Possibly remove from cache, if that is used.
10443     (when gnus-use-cache
10444       (gnus-cache-enter-remove-article article))
10445     t))
10446
10447 (defun gnus-mark-article-as-unread (article &optional mark)
10448   "Enter ARTICLE in the pertinent lists and remove it from others."
10449   (let ((mark (or mark gnus-ticked-mark)))
10450     (if (<= article 0)
10451         (progn
10452           (gnus-error 1 "Can't mark negative article numbers")
10453           nil)
10454       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10455             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10456             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10457             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10458             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10459
10460       ;; Unsuppress duplicates?
10461       (when gnus-suppress-duplicates
10462         (gnus-dup-unsuppress-article article))
10463
10464       (cond ((= mark gnus-ticked-mark)
10465              (setq gnus-newsgroup-marked
10466                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10467             ((= mark gnus-spam-mark)
10468              (setq gnus-newsgroup-spam-marked
10469                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10470                                             article)))
10471             ((= mark gnus-dormant-mark)
10472              (setq gnus-newsgroup-dormant
10473                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10474             (t
10475              (setq gnus-newsgroup-unreads
10476                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10477       (gnus-pull article gnus-newsgroup-reads)
10478       t)))
10479
10480 (defalias 'gnus-summary-mark-as-unread-forward
10481   'gnus-summary-tick-article-forward)
10482 (make-obsolete 'gnus-summary-mark-as-unread-forward
10483                'gnus-summary-tick-article-forward)
10484 (defun gnus-summary-tick-article-forward (n)
10485   "Tick N articles forwards.
10486 If N is negative, tick backwards instead.
10487 The difference between N and the number of articles ticked is returned."
10488   (interactive "p")
10489   (gnus-summary-mark-forward n gnus-ticked-mark))
10490
10491 (defalias 'gnus-summary-mark-as-unread-backward
10492   'gnus-summary-tick-article-backward)
10493 (make-obsolete 'gnus-summary-mark-as-unread-backward
10494                'gnus-summary-tick-article-backward)
10495 (defun gnus-summary-tick-article-backward (n)
10496   "Tick N articles backwards.
10497 The difference between N and the number of articles ticked is returned."
10498   (interactive "p")
10499   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10500
10501 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10502 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10503 (defun gnus-summary-tick-article (&optional article clear-mark)
10504   "Mark current article as unread.
10505 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10506 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10507   (interactive)
10508   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10509                                        gnus-ticked-mark)))
10510
10511 (defun gnus-summary-mark-as-read-forward (n)
10512   "Mark N articles as read forwards.
10513 If N is negative, mark backwards instead.
10514 The difference between N and the actual number of articles marked is
10515 returned."
10516   (interactive "p")
10517   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10518
10519 (defun gnus-summary-mark-as-read-backward (n)
10520   "Mark the N articles as read backwards.
10521 The difference between N and the actual number of articles marked is
10522 returned."
10523   (interactive "p")
10524   (gnus-summary-mark-forward
10525    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10526
10527 (defun gnus-summary-mark-as-read (&optional article mark)
10528   "Mark current article as read.
10529 ARTICLE specifies the article to be marked as read.
10530 MARK specifies a string to be inserted at the beginning of the line."
10531   (gnus-summary-mark-article article mark))
10532
10533 (defun gnus-summary-clear-mark-forward (n)
10534   "Clear marks from N articles forward.
10535 If N is negative, clear backward instead.
10536 The difference between N and the number of marks cleared is returned."
10537   (interactive "p")
10538   (gnus-summary-mark-forward n gnus-unread-mark))
10539
10540 (defun gnus-summary-clear-mark-backward (n)
10541   "Clear marks from N articles backward.
10542 The difference between N and the number of marks cleared is returned."
10543   (interactive "p")
10544   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10545
10546 (defun gnus-summary-mark-unread-as-read ()
10547   "Intended to be used by `gnus-summary-mark-article-hook'."
10548   (when (memq gnus-current-article gnus-newsgroup-unreads)
10549     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10550
10551 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10552   "Intended to be used by `gnus-summary-mark-article-hook'."
10553   (let ((mark (gnus-summary-article-mark)))
10554     (when (or (gnus-unread-mark-p mark)
10555               (gnus-read-mark-p mark))
10556       (gnus-summary-mark-article gnus-current-article
10557                                  (or new-mark gnus-read-mark)))))
10558
10559 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10560   "Intended to be used by `gnus-summary-mark-article-hook'."
10561   (let ((mark (gnus-summary-article-mark)))
10562     (when (or (gnus-unread-mark-p mark)
10563               (gnus-read-mark-p mark))
10564       (gnus-summary-mark-article (gnus-summary-article-number)
10565                                  (or new-mark gnus-read-mark)))))
10566
10567 (defun gnus-summary-mark-unread-as-ticked ()
10568   "Intended to be used by `gnus-summary-mark-article-hook'."
10569   (when (memq gnus-current-article gnus-newsgroup-unreads)
10570     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10571
10572 (defun gnus-summary-mark-region-as-read (point mark all)
10573   "Mark all unread articles between point and mark as read.
10574 If given a prefix, mark all articles between point and mark as read,
10575 even ticked and dormant ones."
10576   (interactive "r\nP")
10577   (save-excursion
10578     (let (article)
10579       (goto-char point)
10580       (beginning-of-line)
10581       (while (and
10582               (< (point) mark)
10583               (progn
10584                 (when (or all
10585                           (memq (setq article (gnus-summary-article-number))
10586                                 gnus-newsgroup-unreads))
10587                   (gnus-summary-mark-article article gnus-del-mark))
10588                 t)
10589               (gnus-summary-find-next))))))
10590
10591 (defun gnus-summary-mark-below (score mark)
10592   "Mark articles with score less than SCORE with MARK."
10593   (interactive "P\ncMark: ")
10594   (setq score (if score
10595                   (prefix-numeric-value score)
10596                 (or gnus-summary-default-score 0)))
10597   (save-excursion
10598     (set-buffer gnus-summary-buffer)
10599     (goto-char (point-min))
10600     (while
10601         (progn
10602           (and (< (gnus-summary-article-score) score)
10603                (gnus-summary-mark-article nil mark))
10604           (gnus-summary-find-next)))))
10605
10606 (defun gnus-summary-kill-below (&optional score)
10607   "Mark articles with score below SCORE as read."
10608   (interactive "P")
10609   (gnus-summary-mark-below score gnus-killed-mark))
10610
10611 (defun gnus-summary-clear-above (&optional score)
10612   "Clear all marks from articles with score above SCORE."
10613   (interactive "P")
10614   (gnus-summary-mark-above score gnus-unread-mark))
10615
10616 (defun gnus-summary-tick-above (&optional score)
10617   "Tick all articles with score above SCORE."
10618   (interactive "P")
10619   (gnus-summary-mark-above score gnus-ticked-mark))
10620
10621 (defun gnus-summary-mark-above (score mark)
10622   "Mark articles with score over SCORE with MARK."
10623   (interactive "P\ncMark: ")
10624   (setq score (if score
10625                   (prefix-numeric-value score)
10626                 (or gnus-summary-default-score 0)))
10627   (save-excursion
10628     (set-buffer gnus-summary-buffer)
10629     (goto-char (point-min))
10630     (while (and (progn
10631                   (when (> (gnus-summary-article-score) score)
10632                     (gnus-summary-mark-article nil mark))
10633                   t)
10634                 (gnus-summary-find-next)))))
10635
10636 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10637 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10638 (defun gnus-summary-limit-include-expunged (&optional no-error)
10639   "Display all the hidden articles that were expunged for low scores."
10640   (interactive)
10641   (let ((buffer-read-only nil))
10642     (let ((scored gnus-newsgroup-scored)
10643           headers h)
10644       (while scored
10645         (unless (gnus-summary-article-header (caar scored))
10646           (and (setq h (gnus-number-to-header (caar scored)))
10647                (< (cdar scored) gnus-summary-expunge-below)
10648                (push h headers)))
10649         (setq scored (cdr scored)))
10650       (if (not headers)
10651           (when (not no-error)
10652             (error "No expunged articles hidden"))
10653         (goto-char (point-min))
10654         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10655         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10656         (mapcar (lambda (x) (push (mail-header-number x)
10657                                   gnus-newsgroup-limit))
10658                 headers)
10659         (gnus-summary-prepare-unthreaded (nreverse headers))
10660         (goto-char (point-min))
10661         (gnus-summary-position-point)
10662         t))))
10663
10664 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10665   "Mark all unread articles in this newsgroup as read.
10666 If prefix argument ALL is non-nil, ticked and dormant articles will
10667 also be marked as read.
10668 If QUIETLY is non-nil, no questions will be asked.
10669
10670 If TO-HERE is non-nil, it should be a point in the buffer.  All
10671 articles before (after, if REVERSE is set) this point will be marked
10672 as read.
10673
10674 Note that this function will only catch up the unread article
10675 in the current summary buffer limitation.
10676
10677 The number of articles marked as read is returned."
10678   (interactive "P")
10679   (prog1
10680       (save-excursion
10681         (when (or quietly
10682                   (not gnus-interactive-catchup) ;Without confirmation?
10683                   gnus-expert-user
10684                   (gnus-y-or-n-p
10685                    (if all
10686                        "Mark absolutely all articles as read? "
10687                      "Mark all unread articles as read? ")))
10688           (if (and not-mark
10689                    (not gnus-newsgroup-adaptive)
10690                    (not gnus-newsgroup-auto-expire)
10691                    (not gnus-suppress-duplicates)
10692                    (or (not gnus-use-cache)
10693                        (eq gnus-use-cache 'passive)))
10694               (progn
10695                 (when all
10696                   (setq gnus-newsgroup-marked nil
10697                         gnus-newsgroup-spam-marked nil
10698                         gnus-newsgroup-dormant nil))
10699                 (setq gnus-newsgroup-unreads
10700                       (gnus-sorted-nunion
10701                        (gnus-sorted-intersection gnus-newsgroup-unreads
10702                                                  gnus-newsgroup-downloadable)
10703                        gnus-newsgroup-unfetched)))
10704             ;; We actually mark all articles as canceled, which we
10705             ;; have to do when using auto-expiry or adaptive scoring.
10706             (gnus-summary-show-all-threads)
10707             (if (and to-here reverse)
10708                 (progn
10709                   (goto-char to-here)
10710                   (gnus-summary-mark-current-read-and-unread-as-read
10711                    gnus-catchup-mark)
10712                   (while (gnus-summary-find-next (not all))
10713                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10714               (when (gnus-summary-first-subject (not all))
10715                 (while (and
10716                         (if to-here (< (point) to-here) t)
10717                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10718                         (gnus-summary-find-next (not all))))))
10719             (gnus-set-mode-line 'summary))
10720           t))
10721     (gnus-summary-position-point)))
10722
10723 (defun gnus-summary-catchup-to-here (&optional all)
10724   "Mark all unticked articles before the current one as read.
10725 If ALL is non-nil, also mark ticked and dormant articles as read."
10726   (interactive "P")
10727   (save-excursion
10728     (gnus-save-hidden-threads
10729       (let ((beg (point)))
10730         ;; We check that there are unread articles.
10731         (when (or all (gnus-summary-find-prev))
10732           (gnus-summary-catchup all t beg)))))
10733   (gnus-summary-position-point))
10734
10735 (defun gnus-summary-catchup-from-here (&optional all)
10736   "Mark all unticked articles after (and including) the current one as read.
10737 If ALL is non-nil, also mark ticked and dormant articles as read."
10738   (interactive "P")
10739   (save-excursion
10740     (gnus-save-hidden-threads
10741       (let ((beg (point)))
10742         ;; We check that there are unread articles.
10743         (when (or all (gnus-summary-find-next))
10744           (gnus-summary-catchup all t beg nil t)))))
10745   (gnus-summary-position-point))
10746
10747 (defun gnus-summary-catchup-all (&optional quietly)
10748   "Mark all articles in this newsgroup as read.
10749 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10750 instead, which marks only unread articles as read."
10751   (interactive "P")
10752   (gnus-summary-catchup t quietly))
10753
10754 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10755   "Mark all unread articles in this group as read, then exit.
10756 If prefix argument ALL is non-nil, all articles are marked as read.
10757 If QUIETLY is non-nil, no questions will be asked."
10758   (interactive "P")
10759   (when (gnus-summary-catchup all quietly nil 'fast)
10760     ;; Select next newsgroup or exit.
10761     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10762              (eq gnus-auto-select-next 'quietly))
10763         (gnus-summary-next-group nil)
10764       (gnus-summary-exit))))
10765
10766 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10767   "Mark all articles in this newsgroup as read, and then exit.
10768 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10769 instead, which marks only unread articles as read."
10770   (interactive "P")
10771   (gnus-summary-catchup-and-exit t quietly))
10772
10773 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10774   "Mark all articles in this group as read and select the next group.
10775 If given a prefix, mark all articles, unread as well as ticked, as
10776 read."
10777   (interactive "P")
10778   (save-excursion
10779     (gnus-summary-catchup all))
10780   (gnus-summary-next-group))
10781
10782 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10783   "Mark all articles in this group as read and select the previous group.
10784 If given a prefix, mark all articles, unread as well as ticked, as
10785 read."
10786   (interactive "P")
10787   (save-excursion
10788     (gnus-summary-catchup all))
10789   (gnus-summary-next-group nil nil t))
10790
10791 ;;;
10792 ;;; with article
10793 ;;;
10794
10795 (defmacro gnus-with-article (article &rest forms)
10796   "Select ARTICLE and perform FORMS in the original article buffer.
10797 Then replace the article with the result."
10798   `(progn
10799      ;; We don't want the article to be marked as read.
10800      (let (gnus-mark-article-hook)
10801        (gnus-summary-select-article t t nil ,article))
10802      (set-buffer gnus-original-article-buffer)
10803      ,@forms
10804      (if (not (gnus-check-backend-function
10805                'request-replace-article (car gnus-article-current)))
10806          (gnus-message 5 "Read-only group; not replacing")
10807        (unless (gnus-request-replace-article
10808                 ,article (car gnus-article-current)
10809                 (current-buffer) t)
10810          (error "Couldn't replace article")))
10811      ;; The cache and backlog have to be flushed somewhat.
10812      (when gnus-keep-backlog
10813        (gnus-backlog-remove-article
10814         (car gnus-article-current) (cdr gnus-article-current)))
10815      (when gnus-use-cache
10816        (gnus-cache-update-article
10817         (car gnus-article-current) (cdr gnus-article-current)))))
10818
10819 (put 'gnus-with-article 'lisp-indent-function 1)
10820 (put 'gnus-with-article 'edebug-form-spec '(form body))
10821
10822 ;; Thread-based commands.
10823
10824 (defun gnus-summary-articles-in-thread (&optional article)
10825   "Return a list of all articles in the current thread.
10826 If ARTICLE is non-nil, return all articles in the thread that starts
10827 with that article."
10828   (let* ((article (or article (gnus-summary-article-number)))
10829          (data (gnus-data-find-list article))
10830          (top-level (gnus-data-level (car data)))
10831          (top-subject
10832           (cond ((null gnus-thread-operation-ignore-subject)
10833                  (gnus-simplify-subject-re
10834                   (mail-header-subject (gnus-data-header (car data)))))
10835                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10836                  (gnus-simplify-subject-fuzzy
10837                   (mail-header-subject (gnus-data-header (car data)))))
10838                 (t nil)))
10839          (end-point (save-excursion
10840                       (if (gnus-summary-go-to-next-thread)
10841                           (point) (point-max))))
10842          articles)
10843     (while (and data
10844                 (< (gnus-data-pos (car data)) end-point))
10845       (when (or (not top-subject)
10846                 (string= top-subject
10847                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10848                              (gnus-simplify-subject-fuzzy
10849                               (mail-header-subject
10850                                (gnus-data-header (car data))))
10851                            (gnus-simplify-subject-re
10852                             (mail-header-subject
10853                              (gnus-data-header (car data)))))))
10854         (push (gnus-data-number (car data)) articles))
10855       (unless (and (setq data (cdr data))
10856                    (> (gnus-data-level (car data)) top-level))
10857         (setq data nil)))
10858     ;; Return the list of articles.
10859     (nreverse articles)))
10860
10861 (defun gnus-summary-rethread-current ()
10862   "Rethread the thread the current article is part of."
10863   (interactive)
10864   (let* ((gnus-show-threads t)
10865          (article (gnus-summary-article-number))
10866          (id (mail-header-id (gnus-summary-article-header)))
10867          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10868     (unless id
10869       (error "No article on the current line"))
10870     (gnus-rebuild-thread id)
10871     (gnus-summary-goto-subject article)))
10872
10873 (defun gnus-summary-reparent-thread ()
10874   "Make the current article child of the marked (or previous) article.
10875
10876 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10877 is non-nil or the Subject: of both articles are the same."
10878   (interactive)
10879   (unless (not (gnus-group-read-only-p))
10880     (error "The current newsgroup does not support article editing"))
10881   (unless (<= (length gnus-newsgroup-processable) 1)
10882     (error "No more than one article may be marked"))
10883   (let ((child (gnus-summary-article-number))
10884         ;; First grab the marked article, otherwise one line up.
10885         (parent (if (not (null gnus-newsgroup-processable))
10886                     (car gnus-newsgroup-processable)
10887                   (save-excursion
10888                     (if (eq (forward-line -1) 0)
10889                         (gnus-summary-article-number)
10890                       (error "Beginning of summary buffer"))))))
10891     (gnus-summary-reparent-children parent (list child))))
10892
10893 (defun gnus-summary-reparent-children (parent children)
10894   "Make PARENT the parent of CHILDREN.
10895 When called interactively, PARENT is is current article and
10896 CHILDREN are the process-marked articles."
10897   (interactive
10898    (list (gnus-summary-article-number)
10899          (gnus-summary-work-articles nil)))
10900   (dolist (child children)
10901     (save-window-excursion
10902       (let ((gnus-article-buffer " *reparent*"))
10903         (unless (not (eq parent child))
10904           (error "An article may not be self-referential"))
10905         (let ((message-id (mail-header-id
10906                            (gnus-summary-article-header parent))))
10907           (unless (and message-id (not (equal message-id "")))
10908             (error "No message-id in desired parent"))
10909           (gnus-with-article child
10910             (save-restriction
10911               (goto-char (point-min))
10912               (message-narrow-to-head)
10913               (if (re-search-forward "^References: " nil t)
10914                   (progn
10915                     (re-search-forward "^[^ \t]" nil t)
10916                     (forward-line -1)
10917                     (end-of-line)
10918                     (insert " " message-id))
10919                 (insert "References: " message-id "\n"))))
10920           (set-buffer gnus-summary-buffer)
10921           (gnus-summary-unmark-all-processable)
10922           (gnus-summary-update-article child)
10923           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10924             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10925           (gnus-summary-rethread-current)
10926           (gnus-message 3 "Article %d is now the child of article %d"
10927                         child parent))))))
10928
10929 (defun gnus-summary-toggle-threads (&optional arg)
10930   "Toggle showing conversation threads.
10931 If ARG is positive number, turn showing conversation threads on."
10932   (interactive "P")
10933   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10934     (setq gnus-show-threads
10935           (if (null arg) (not gnus-show-threads)
10936             (> (prefix-numeric-value arg) 0)))
10937     (gnus-summary-prepare)
10938     (gnus-summary-goto-subject current)
10939     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10940     (gnus-summary-position-point)))
10941
10942 (defun gnus-summary-show-all-threads ()
10943   "Show all threads."
10944   (interactive)
10945   (save-excursion
10946     (let ((buffer-read-only nil))
10947       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10948   (gnus-summary-position-point))
10949
10950 (defun gnus-summary-show-thread ()
10951   "Show thread subtrees.
10952 Returns nil if no thread was there to be shown."
10953   (interactive)
10954   (let ((buffer-read-only nil)
10955         (orig (point))
10956         (end (point-at-eol))
10957         ;; Leave point at bol
10958         (beg (progn (beginning-of-line) (point))))
10959     (prog1
10960         ;; Any hidden lines here?
10961         (search-forward "\r" end t)
10962       (subst-char-in-region beg end ?\^M ?\n t)
10963       (goto-char orig)
10964       (gnus-summary-position-point))))
10965
10966 (defun gnus-summary-maybe-hide-threads ()
10967   "If requested, hide the threads that should be hidden."
10968   (when (and gnus-show-threads
10969              gnus-thread-hide-subtree)
10970     (gnus-summary-hide-all-threads
10971      (if (or (consp gnus-thread-hide-subtree)
10972              (functionp gnus-thread-hide-subtree))
10973          (gnus-make-predicate gnus-thread-hide-subtree)
10974        nil))))
10975
10976 ;;; Hiding predicates.
10977
10978 (defun gnus-article-unread-p (header)
10979   (memq (mail-header-number header) gnus-newsgroup-unreads))
10980
10981 (defun gnus-article-unseen-p (header)
10982   (memq (mail-header-number header) gnus-newsgroup-unseen))
10983
10984 (defun gnus-map-articles (predicate articles)
10985   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10986   (apply 'gnus-or (mapcar predicate
10987                           (mapcar (lambda (number)
10988                                     (gnus-summary-article-header number))
10989                                   articles))))
10990
10991 (defun gnus-summary-hide-all-threads (&optional predicate)
10992   "Hide all thread subtrees.
10993 If PREDICATE is supplied, threads that satisfy this predicate
10994 will not be hidden."
10995   (interactive)
10996   (save-excursion
10997     (goto-char (point-min))
10998     (let ((end nil))
10999       (while (not end)
11000         (when (or (not predicate)
11001                   (gnus-map-articles
11002                    predicate (gnus-summary-article-children)))
11003             (gnus-summary-hide-thread))
11004         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11005   (gnus-summary-position-point))
11006
11007 (defun gnus-summary-hide-thread ()
11008   "Hide thread subtrees.
11009 If PREDICATE is supplied, threads that satisfy this predicate
11010 will not be hidden.
11011 Returns nil if no threads were there to be hidden."
11012   (interactive)
11013   (let ((buffer-read-only nil)
11014         (start (point))
11015         (article (gnus-summary-article-number)))
11016     (goto-char start)
11017     ;; Go forward until either the buffer ends or the subthread
11018     ;; ends.
11019     (when (and (not (eobp))
11020                (or (zerop (gnus-summary-next-thread 1 t))
11021                    (goto-char (point-max))))
11022       (prog1
11023           (if (and (> (point) start)
11024                    (search-backward "\n" start t))
11025               (progn
11026                 (subst-char-in-region start (point) ?\n ?\^M)
11027                 (gnus-summary-goto-subject article))
11028             (goto-char start)
11029             nil)))))
11030
11031 (defun gnus-summary-go-to-next-thread (&optional previous)
11032   "Go to the same level (or less) next thread.
11033 If PREVIOUS is non-nil, go to previous thread instead.
11034 Return the article number moved to, or nil if moving was impossible."
11035   (let ((level (gnus-summary-thread-level))
11036         (way (if previous -1 1))
11037         (beg (point)))
11038     (forward-line way)
11039     (while (and (not (eobp))
11040                 (< level (gnus-summary-thread-level)))
11041       (forward-line way))
11042     (if (eobp)
11043         (progn
11044           (goto-char beg)
11045           nil)
11046       (setq beg (point))
11047       (prog1
11048           (gnus-summary-article-number)
11049         (goto-char beg)))))
11050
11051 (defun gnus-summary-next-thread (n &optional silent)
11052   "Go to the same level next N'th thread.
11053 If N is negative, search backward instead.
11054 Returns the difference between N and the number of skips actually
11055 done.
11056
11057 If SILENT, don't output messages."
11058   (interactive "p")
11059   (let ((backward (< n 0))
11060         (n (abs n)))
11061     (while (and (> n 0)
11062                 (gnus-summary-go-to-next-thread backward))
11063       (decf n))
11064     (unless silent
11065       (gnus-summary-position-point))
11066     (when (and (not silent) (/= 0 n))
11067       (gnus-message 7 "No more threads"))
11068     n))
11069
11070 (defun gnus-summary-prev-thread (n)
11071   "Go to the same level previous N'th thread.
11072 Returns the difference between N and the number of skips actually
11073 done."
11074   (interactive "p")
11075   (gnus-summary-next-thread (- n)))
11076
11077 (defun gnus-summary-go-down-thread ()
11078   "Go down one level in the current thread."
11079   (let ((children (gnus-summary-article-children)))
11080     (when children
11081       (gnus-summary-goto-subject (car children)))))
11082
11083 (defun gnus-summary-go-up-thread ()
11084   "Go up one level in the current thread."
11085   (let ((parent (gnus-summary-article-parent)))
11086     (when parent
11087       (gnus-summary-goto-subject parent))))
11088
11089 (defun gnus-summary-down-thread (n)
11090   "Go down thread N steps.
11091 If N is negative, go up instead.
11092 Returns the difference between N and how many steps down that were
11093 taken."
11094   (interactive "p")
11095   (let ((up (< n 0))
11096         (n (abs n)))
11097     (while (and (> n 0)
11098                 (if up (gnus-summary-go-up-thread)
11099                   (gnus-summary-go-down-thread)))
11100       (setq n (1- n)))
11101     (gnus-summary-position-point)
11102     (when (/= 0 n)
11103       (gnus-message 7 "Can't go further"))
11104     n))
11105
11106 (defun gnus-summary-up-thread (n)
11107   "Go up thread N steps.
11108 If N is negative, go down instead.
11109 Returns the difference between N and how many steps down that were
11110 taken."
11111   (interactive "p")
11112   (gnus-summary-down-thread (- n)))
11113
11114 (defun gnus-summary-top-thread ()
11115   "Go to the top of the thread."
11116   (interactive)
11117   (while (gnus-summary-go-up-thread))
11118   (gnus-summary-article-number))
11119
11120 (defun gnus-summary-kill-thread (&optional unmark)
11121   "Mark articles under current thread as read.
11122 If the prefix argument is positive, remove any kinds of marks.
11123 If the prefix argument is negative, tick articles instead."
11124   (interactive "P")
11125   (when unmark
11126     (setq unmark (prefix-numeric-value unmark)))
11127   (let ((articles (gnus-summary-articles-in-thread)))
11128     (save-excursion
11129       ;; Expand the thread.
11130       (gnus-summary-show-thread)
11131       ;; Mark all the articles.
11132       (while articles
11133         (gnus-summary-goto-subject (car articles))
11134         (cond ((null unmark)
11135                (gnus-summary-mark-article-as-read gnus-killed-mark))
11136               ((> unmark 0)
11137                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11138               (t
11139                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11140         (setq articles (cdr articles))))
11141     ;; Hide killed subtrees.
11142     (and (null unmark)
11143          gnus-thread-hide-killed
11144          (gnus-summary-hide-thread))
11145     ;; If marked as read, go to next unread subject.
11146     (when (null unmark)
11147       ;; Go to next unread subject.
11148       (gnus-summary-next-subject 1 t)))
11149   (gnus-set-mode-line 'summary))
11150
11151 ;; Summary sorting commands
11152
11153 (defun gnus-summary-sort-by-number (&optional reverse)
11154   "Sort the summary buffer by article number.
11155 Argument REVERSE means reverse order."
11156   (interactive "P")
11157   (gnus-summary-sort 'number reverse))
11158
11159 (defun gnus-summary-sort-by-random (&optional reverse)
11160   "Randomize the order in the summary buffer.
11161 Argument REVERSE means to randomize in reverse order."
11162   (interactive "P")
11163   (gnus-summary-sort 'random reverse))
11164
11165 (defun gnus-summary-sort-by-author (&optional reverse)
11166   "Sort the summary buffer by author name alphabetically.
11167 If `case-fold-search' is non-nil, case of letters is ignored.
11168 Argument REVERSE means reverse order."
11169   (interactive "P")
11170   (gnus-summary-sort 'author reverse))
11171
11172 (defun gnus-summary-sort-by-recipient (&optional reverse)
11173   "Sort the summary buffer by recipient name alphabetically.
11174 If `case-fold-search' is non-nil, case of letters is ignored.
11175 Argument REVERSE means reverse order."
11176   (interactive "P")
11177   (gnus-summary-sort 'recipient reverse))
11178
11179 (defun gnus-summary-sort-by-subject (&optional reverse)
11180   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11181 If `case-fold-search' is non-nil, case of letters is ignored.
11182 Argument REVERSE means reverse order."
11183   (interactive "P")
11184   (gnus-summary-sort 'subject reverse))
11185
11186 (defun gnus-summary-sort-by-date (&optional reverse)
11187   "Sort the summary buffer by date.
11188 Argument REVERSE means reverse order."
11189   (interactive "P")
11190   (gnus-summary-sort 'date reverse))
11191
11192 (defun gnus-summary-sort-by-score (&optional reverse)
11193   "Sort the summary buffer by score.
11194 Argument REVERSE means reverse order."
11195   (interactive "P")
11196   (gnus-summary-sort 'score reverse))
11197
11198 (defun gnus-summary-sort-by-lines (&optional reverse)
11199   "Sort the summary buffer by the number of lines.
11200 Argument REVERSE means reverse order."
11201   (interactive "P")
11202   (gnus-summary-sort 'lines reverse))
11203
11204 (defun gnus-summary-sort-by-chars (&optional reverse)
11205   "Sort the summary buffer by article length.
11206 Argument REVERSE means reverse order."
11207   (interactive "P")
11208   (gnus-summary-sort 'chars reverse))
11209
11210 (defun gnus-summary-sort-by-original (&optional reverse)
11211   "Sort the summary buffer using the default sorting method.
11212 Argument REVERSE means reverse order."
11213   (interactive "P")
11214   (let* ((buffer-read-only)
11215          (gnus-summary-prepare-hook nil))
11216     ;; We do the sorting by regenerating the threads.
11217     (gnus-summary-prepare)
11218     ;; Hide subthreads if needed.
11219     (gnus-summary-maybe-hide-threads)))
11220
11221 (defun gnus-summary-sort (predicate reverse)
11222   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11223   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11224          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11225          (gnus-thread-sort-functions
11226           (if (not reverse)
11227               thread
11228             `(lambda (t1 t2)
11229                (,thread t2 t1))))
11230          (gnus-sort-gathered-threads-function
11231           gnus-thread-sort-functions)
11232          (gnus-article-sort-functions
11233           (if (not reverse)
11234               article
11235             `(lambda (t1 t2)
11236                (,article t2 t1))))
11237          (buffer-read-only)
11238          (gnus-summary-prepare-hook nil))
11239     ;; We do the sorting by regenerating the threads.
11240     (gnus-summary-prepare)
11241     ;; Hide subthreads if needed.
11242     (gnus-summary-maybe-hide-threads)))
11243
11244 ;; Summary saving commands.
11245
11246 (defun gnus-summary-save-article (&optional n not-saved)
11247   "Save the current article using the default saver function.
11248 If N is a positive number, save the N next articles.
11249 If N is a negative number, save the N previous articles.
11250 If N is nil and any articles have been marked with the process mark,
11251 save those articles instead.
11252 The variable `gnus-default-article-saver' specifies the saver function.
11253
11254 If the optional second argument NOT-SAVED is non-nil, articles saved
11255 will not be marked as saved."
11256   (interactive "P")
11257   (require 'gnus-art)
11258   (let* ((articles (gnus-summary-work-articles n))
11259          (save-buffer (save-excursion
11260                         (nnheader-set-temp-buffer " *Gnus Save*")))
11261          (num (length articles))
11262          ;; Whether to save decoded articles or raw articles.
11263          (decode (when gnus-article-save-coding-system
11264                    (get gnus-default-article-saver :decode)))
11265          ;; When saving many articles in a single file, use the other
11266          ;; function to save articles other than the first one.
11267          (saver2 (get gnus-default-article-saver :function))
11268          (gnus-prompt-before-saving (if saver2
11269                                         t
11270                                       gnus-prompt-before-saving))
11271          (gnus-default-article-saver gnus-default-article-saver)
11272          header file)
11273     (dolist (article articles)
11274       (setq header (gnus-summary-article-header article))
11275       (if (not (vectorp header))
11276           ;; This is a pseudo-article.
11277           (if (assq 'name header)
11278               (gnus-copy-file (cdr (assq 'name header)))
11279             (gnus-message 1 "Article %d is unsaveable" article))
11280         ;; This is a real article.
11281         (save-window-excursion
11282           (let ((gnus-display-mime-function (when decode
11283                                               gnus-display-mime-function))
11284                 (gnus-article-prepare-hook (when decode
11285                                              gnus-article-prepare-hook)))
11286             (gnus-summary-select-article t nil nil article)
11287             (gnus-summary-goto-subject article)))
11288         (save-excursion
11289           (set-buffer save-buffer)
11290           (erase-buffer)
11291           (insert-buffer-substring (if decode
11292                                        gnus-article-buffer
11293                                      gnus-original-article-buffer)))
11294         (setq file (gnus-article-save save-buffer file num))
11295         (gnus-summary-remove-process-mark article)
11296         (unless not-saved
11297           (gnus-summary-set-saved-mark article)))
11298       (when saver2
11299         (setq gnus-default-article-saver saver2
11300               saver2 nil)))
11301     (gnus-kill-buffer save-buffer)
11302     (gnus-summary-position-point)
11303     (gnus-set-mode-line 'summary)
11304     n))
11305
11306 (defun gnus-summary-pipe-output (&optional arg headers)
11307   "Pipe the current article to a subprocess.
11308 If N is a positive number, pipe the N next articles.
11309 If N is a negative number, pipe the N previous articles.
11310 If N is nil and any articles have been marked with the process mark,
11311 pipe those articles instead.
11312 If HEADERS (the symbolic prefix), include the headers, too."
11313   (interactive (gnus-interactive "P\ny"))
11314   (require 'gnus-art)
11315   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11316         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11317     (gnus-summary-save-article arg t))
11318   (let ((buffer (get-buffer "*Shell Command Output*")))
11319     (when (and buffer
11320                (not (zerop (buffer-size buffer))))
11321       (gnus-configure-windows 'pipe))))
11322
11323 (defun gnus-summary-save-article-mail (&optional arg)
11324   "Append the current article to a Unix mail box file.
11325 If N is a positive number, save the N next articles.
11326 If N is a negative number, save the N previous articles.
11327 If N is nil and any articles have been marked with the process mark,
11328 save those articles instead."
11329   (interactive "P")
11330   (require 'gnus-art)
11331   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11332     (gnus-summary-save-article arg)))
11333
11334 (defun gnus-summary-save-article-rmail (&optional arg)
11335   "Append the current article to an rmail file.
11336 If N is a positive number, save the N next articles.
11337 If N is a negative number, save the N previous articles.
11338 If N is nil and any articles have been marked with the process mark,
11339 save those articles instead."
11340   (interactive "P")
11341   (require 'gnus-art)
11342   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11343     (gnus-summary-save-article arg)))
11344
11345 (defun gnus-summary-save-article-file (&optional arg)
11346   "Append the current article to a file.
11347 If N is a positive number, save the N next articles.
11348 If N is a negative number, save the N previous articles.
11349 If N is nil and any articles have been marked with the process mark,
11350 save those articles instead."
11351   (interactive "P")
11352   (require 'gnus-art)
11353   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11354     (gnus-summary-save-article arg)))
11355
11356 (defun gnus-summary-write-article-file (&optional arg)
11357   "Write the current article to a file, deleting the previous file.
11358 If N is a positive number, save the N next articles.
11359 If N is a negative number, save the N previous articles.
11360 If N is nil and any articles have been marked with the process mark,
11361 save those articles instead."
11362   (interactive "P")
11363   (require 'gnus-art)
11364   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11365     (gnus-summary-save-article arg)))
11366
11367 (defun gnus-summary-save-article-body-file (&optional arg)
11368   "Append the current article body to a file.
11369 If N is a positive number, save the N next articles.
11370 If N is a negative number, save the N previous articles.
11371 If N is nil and any articles have been marked with the process mark,
11372 save those articles instead."
11373   (interactive "P")
11374   (require 'gnus-art)
11375   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11376     (gnus-summary-save-article arg)))
11377
11378 (defun gnus-summary-write-article-body-file (&optional arg)
11379   "Write the current article body to a file, deleting the previous file.
11380 If N is a positive number, save the N next articles.
11381 If N is a negative number, save the N previous articles.
11382 If N is nil and any articles have been marked with the process mark,
11383 save those articles instead."
11384   (interactive "P")
11385   (require 'gnus-art)
11386   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11387     (gnus-summary-save-article arg)))
11388
11389 (defun gnus-summary-muttprint (&optional arg)
11390   "Print the current article using Muttprint.
11391 If N is a positive number, save the N next articles.
11392 If N is a negative number, save the N previous articles.
11393 If N is nil and any articles have been marked with the process mark,
11394 save those articles instead."
11395   (interactive "P")
11396   (require 'gnus-art)
11397   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11398     (gnus-summary-save-article arg t)))
11399
11400 (defun gnus-summary-pipe-message (program)
11401   "Pipe the current article through PROGRAM."
11402   (interactive "sProgram: ")
11403   (gnus-summary-select-article)
11404   (let ((mail-header-separator ""))
11405     (gnus-eval-in-buffer-window gnus-article-buffer
11406       (save-restriction
11407         (widen)
11408         (let ((start (window-start))
11409               buffer-read-only)
11410           (message-pipe-buffer-body program)
11411           (set-window-start (get-buffer-window (current-buffer)) start))))))
11412
11413 (defun gnus-get-split-value (methods)
11414   "Return a value based on the split METHODS."
11415   (let (split-name method result match)
11416     (when methods
11417       (save-excursion
11418         (set-buffer gnus-original-article-buffer)
11419         (save-restriction
11420           (nnheader-narrow-to-headers)
11421           (while (and methods (not split-name))
11422             (goto-char (point-min))
11423             (setq method (pop methods))
11424             (setq match (car method))
11425             (when (cond
11426                    ((stringp match)
11427                     ;; Regular expression.
11428                     (ignore-errors
11429                       (re-search-forward match nil t)))
11430                    ((functionp match)
11431                     ;; Function.
11432                     (save-restriction
11433                       (widen)
11434                       (setq result (funcall match gnus-newsgroup-name))))
11435                    ((consp match)
11436                     ;; Form.
11437                     (save-restriction
11438                       (widen)
11439                       (setq result (eval match)))))
11440               (setq split-name (cdr method))
11441               (cond ((stringp result)
11442                      (push (expand-file-name
11443                             result gnus-article-save-directory)
11444                            split-name))
11445                     ((consp result)
11446                      (setq split-name (append result split-name)))))))))
11447     (nreverse split-name)))
11448
11449 (defun gnus-valid-move-group-p (group)
11450   (and (boundp group)
11451        (symbol-name group)
11452        (symbol-value group)
11453        (gnus-get-function (gnus-find-method-for-group
11454                            (symbol-name group)) 'request-accept-article t)))
11455
11456 (defun gnus-read-move-group-name (prompt default articles prefix)
11457   "Read a group name."
11458   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11459          (minibuffer-confirm-incomplete nil) ; XEmacs
11460          (prom
11461           (format "%s %s to"
11462                   prompt
11463                   (if (> (length articles) 1)
11464                       (format "these %d articles" (length articles))
11465                     "this article")))
11466          (to-newsgroup
11467           (cond
11468            ((null split-name)
11469             (gnus-completing-read-with-default
11470              default prom
11471              gnus-active-hashtb
11472              'gnus-valid-move-group-p
11473              nil prefix
11474              'gnus-group-history))
11475            ((= 1 (length split-name))
11476             (gnus-completing-read-with-default
11477              (car split-name) prom
11478              gnus-active-hashtb
11479              'gnus-valid-move-group-p
11480              nil nil
11481              'gnus-group-history))
11482            (t
11483             (gnus-completing-read-with-default
11484              nil prom
11485              (mapcar 'list (nreverse split-name))
11486              nil nil nil
11487              'gnus-group-history))))
11488          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11489     (when to-newsgroup
11490       (if (or (string= to-newsgroup "")
11491               (string= to-newsgroup prefix))
11492           (setq to-newsgroup default))
11493       (unless to-newsgroup
11494         (error "No group name entered"))
11495       (or (gnus-active to-newsgroup)
11496           (gnus-activate-group to-newsgroup nil nil to-method)
11497           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11498                                      to-newsgroup))
11499               (or (and (gnus-request-create-group to-newsgroup to-method)
11500                        (gnus-activate-group
11501                         to-newsgroup nil nil to-method)
11502                        (gnus-subscribe-group to-newsgroup))
11503                   (error "Couldn't create group %s" to-newsgroup)))
11504           (error "No such group: %s" to-newsgroup)))
11505     to-newsgroup))
11506
11507 (defvar gnus-summary-save-parts-counter)
11508
11509 (defun gnus-summary-save-parts (type dir n &optional reverse)
11510   "Save parts matching TYPE to DIR.
11511 If REVERSE, save parts that do not match TYPE."
11512   (interactive
11513    (list (read-string "Save parts of type: "
11514                       (or (car gnus-summary-save-parts-type-history)
11515                           gnus-summary-save-parts-default-mime)
11516                       'gnus-summary-save-parts-type-history)
11517          (setq gnus-summary-save-parts-last-directory
11518                (read-file-name "Save to directory: "
11519                                gnus-summary-save-parts-last-directory
11520                                nil t))
11521          current-prefix-arg))
11522   (gnus-summary-iterate n
11523     (let ((gnus-display-mime-function nil)
11524           (gnus-inhibit-treatment t))
11525       (gnus-summary-select-article))
11526     (save-excursion
11527       (set-buffer gnus-article-buffer)
11528       (let ((handles (or gnus-article-mime-handles
11529                          (mm-dissect-buffer nil gnus-article-loose-mime)
11530                          (and gnus-article-emulate-mime
11531                               (mm-uu-dissect))))
11532             (gnus-summary-save-parts-counter 1))
11533         (when handles
11534           (gnus-summary-save-parts-1 type dir handles reverse)
11535           (unless gnus-article-mime-handles ;; Don't destroy this case.
11536             (mm-destroy-parts handles)))))))
11537
11538 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11539   (if (stringp (car handle))
11540       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11541               (cdr handle))
11542     (when (if reverse
11543               (not (string-match type (mm-handle-media-type handle)))
11544             (string-match type (mm-handle-media-type handle)))
11545       (let ((file (expand-file-name
11546                    (gnus-map-function
11547                     mm-file-name-rewrite-functions
11548                     (file-name-nondirectory
11549                      (or
11550                       (mail-content-type-get
11551                        (mm-handle-disposition handle) 'filename)
11552                       (mail-content-type-get
11553                        (mm-handle-type handle) 'name)
11554                       (format "%s.%d.%d" gnus-newsgroup-name
11555                               (cdr gnus-article-current)
11556                               gnus-summary-save-parts-counter))))
11557                    dir)))
11558         (incf gnus-summary-save-parts-counter)
11559         (unless (file-exists-p file)
11560           (mm-save-part-to-file handle file))))))
11561
11562 ;; Summary extract commands
11563
11564 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11565   (let ((buffer-read-only nil)
11566         (article (gnus-summary-article-number))
11567         after-article b e)
11568     (unless (gnus-summary-goto-subject article)
11569       (error "No such article: %d" article))
11570     (gnus-summary-position-point)
11571     ;; If all commands are to be bunched up on one line, we collect
11572     ;; them here.
11573     (unless gnus-view-pseudos-separately
11574       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11575             files action)
11576         (while ps
11577           (setq action (cdr (assq 'action (car ps))))
11578           (setq files (list (cdr (assq 'name (car ps)))))
11579           (while (and ps (cdr ps)
11580                       (string= (or action "1")
11581                                (or (cdr (assq 'action (cadr ps))) "2")))
11582             (push (cdr (assq 'name (cadr ps))) files)
11583             (setcdr ps (cddr ps)))
11584           (when files
11585             (when (not (string-match "%s" action))
11586               (push " " files))
11587             (push " " files)
11588             (when (assq 'execute (car ps))
11589               (setcdr (assq 'execute (car ps))
11590                       (funcall (if (string-match "%s" action)
11591                                    'format 'concat)
11592                                action
11593                                (mapconcat
11594                                 (lambda (f)
11595                                   (if (equal f " ")
11596                                       f
11597                                     (shell-quote-argument f)))
11598                                 files " ")))))
11599           (setq ps (cdr ps)))))
11600     (if (and gnus-view-pseudos (not not-view))
11601         (while pslist
11602           (when (assq 'execute (car pslist))
11603             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11604                                   (eq gnus-view-pseudos 'not-confirm)))
11605           (setq pslist (cdr pslist)))
11606       (save-excursion
11607         (while pslist
11608           (setq after-article (or (cdr (assq 'article (car pslist)))
11609                                   (gnus-summary-article-number)))
11610           (gnus-summary-goto-subject after-article)
11611           (forward-line 1)
11612           (setq b (point))
11613           (insert "    " (file-name-nondirectory
11614                           (cdr (assq 'name (car pslist))))
11615                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11616           (setq e (point))
11617           (forward-line -1)             ; back to `b'
11618           (gnus-add-text-properties
11619            b (1- e) (list 'gnus-number gnus-reffed-article-number
11620                           gnus-mouse-face-prop gnus-mouse-face))
11621           (gnus-data-enter
11622            after-article gnus-reffed-article-number
11623            gnus-unread-mark b (car pslist) 0 (- e b))
11624           (setq gnus-newsgroup-unreads
11625                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11626                                          gnus-reffed-article-number))
11627           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11628           (setq pslist (cdr pslist)))))))
11629
11630 (defun gnus-pseudos< (p1 p2)
11631   (let ((c1 (cdr (assq 'action p1)))
11632         (c2 (cdr (assq 'action p2))))
11633     (and c1 c2 (string< c1 c2))))
11634
11635 (defun gnus-request-pseudo-article (props)
11636   (cond ((assq 'execute props)
11637          (gnus-execute-command (cdr (assq 'execute props)))))
11638   (let ((gnus-current-article (gnus-summary-article-number)))
11639     (gnus-run-hooks 'gnus-mark-article-hook)))
11640
11641 (defun gnus-execute-command (command &optional automatic)
11642   (save-excursion
11643     (gnus-article-setup-buffer)
11644     (set-buffer gnus-article-buffer)
11645     (setq buffer-read-only nil)
11646     (let ((command (if automatic command
11647                      (read-string "Command: " (cons command 0)))))
11648       (erase-buffer)
11649       (insert "$ " command "\n\n")
11650       (if gnus-view-pseudo-asynchronously
11651           (start-process "gnus-execute" (current-buffer) shell-file-name
11652                          shell-command-switch command)
11653         (call-process shell-file-name nil t nil
11654                       shell-command-switch command)))))
11655
11656 ;; Summary kill commands.
11657
11658 (defun gnus-summary-edit-global-kill (article)
11659   "Edit the \"global\" kill file."
11660   (interactive (list (gnus-summary-article-number)))
11661   (gnus-group-edit-global-kill article))
11662
11663 (defun gnus-summary-edit-local-kill ()
11664   "Edit a local kill file applied to the current newsgroup."
11665   (interactive)
11666   (setq gnus-current-headers (gnus-summary-article-header))
11667   (gnus-group-edit-local-kill
11668    (gnus-summary-article-number) gnus-newsgroup-name))
11669
11670 ;;; Header reading.
11671
11672 (defun gnus-read-header (id &optional header)
11673   "Read the headers of article ID and enter them into the Gnus system."
11674   (let ((group gnus-newsgroup-name)
11675         (gnus-override-method
11676          (or
11677           gnus-override-method
11678           (and (gnus-news-group-p gnus-newsgroup-name)
11679                (car (gnus-refer-article-methods)))))
11680         where)
11681     ;; First we check to see whether the header in question is already
11682     ;; fetched.
11683     (if (stringp id)
11684         ;; This is a Message-ID.
11685         (setq header (or header (gnus-id-to-header id)))
11686       ;; This is an article number.
11687       (setq header (or header (gnus-summary-article-header id))))
11688     (if (and header
11689              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11690         ;; We have found the header.
11691         header
11692       ;; We have to really fetch the header to this article.
11693       (save-excursion
11694         (set-buffer nntp-server-buffer)
11695         (when (setq where (gnus-request-head id group))
11696           (nnheader-fold-continuation-lines)
11697           (goto-char (point-max))
11698           (insert ".\n")
11699           (goto-char (point-min))
11700           (insert "211 ")
11701           (princ (cond
11702                   ((numberp id) id)
11703                   ((cdr where) (cdr where))
11704                   (header (mail-header-number header))
11705                   (t gnus-reffed-article-number))
11706                  (current-buffer))
11707           (insert " Article retrieved.\n"))
11708         (if (or (not where)
11709                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11710             ()                          ; Malformed head.
11711           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11712             (when (and (stringp id)
11713                        (or
11714                         (not (string= (gnus-group-real-name group)
11715                                       (car where)))
11716                         (not (gnus-server-equal gnus-override-method
11717                                                 (gnus-group-method group)))))
11718               ;; If we fetched by Message-ID and the article came from
11719               ;; a different group (or server), we fudge some bogus
11720               ;; article numbers for this article.
11721               (mail-header-set-number header gnus-reffed-article-number))
11722             (save-excursion
11723               (set-buffer gnus-summary-buffer)
11724               (decf gnus-reffed-article-number)
11725               (gnus-remove-header (mail-header-number header))
11726               (push header gnus-newsgroup-headers)
11727               (setq gnus-current-headers header)
11728               (push (mail-header-number header) gnus-newsgroup-limit)))
11729           header)))))
11730
11731 (defun gnus-remove-header (number)
11732   "Remove header NUMBER from `gnus-newsgroup-headers'."
11733   (if (and gnus-newsgroup-headers
11734            (= number (mail-header-number (car gnus-newsgroup-headers))))
11735       (pop gnus-newsgroup-headers)
11736     (let ((headers gnus-newsgroup-headers))
11737       (while (and (cdr headers)
11738                   (not (= number (mail-header-number (cadr headers)))))
11739         (pop headers))
11740       (when (cdr headers)
11741         (setcdr headers (cddr headers))))))
11742
11743 ;;;
11744 ;;; summary highlights
11745 ;;;
11746
11747 (defun gnus-highlight-selected-summary ()
11748   "Highlight selected article in summary buffer."
11749   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11750   (when gnus-summary-selected-face
11751     (save-excursion
11752       (let* ((beg (point-at-bol))
11753              (end (point-at-eol))
11754              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11755              (from (if (get-text-property beg gnus-mouse-face-prop)
11756                        beg
11757                      (or (next-single-property-change
11758                           beg gnus-mouse-face-prop nil end)
11759                          beg)))
11760              (to
11761               (if (= from end)
11762                   (- from 2)
11763                 (or (next-single-property-change
11764                      from gnus-mouse-face-prop nil end)
11765                     end))))
11766         ;; If no mouse-face prop on line we will have to = from = end,
11767         ;; so we highlight the entire line instead.
11768         (when (= (+ to 2) from)
11769           (setq from beg)
11770           (setq to end))
11771         (if gnus-newsgroup-selected-overlay
11772             ;; Move old overlay.
11773             (gnus-move-overlay
11774              gnus-newsgroup-selected-overlay from to (current-buffer))
11775           ;; Create new overlay.
11776           (gnus-overlay-put
11777            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11778            'face gnus-summary-selected-face))))))
11779
11780 (defvar gnus-summary-highlight-line-cached nil)
11781 (defvar gnus-summary-highlight-line-trigger nil)
11782
11783 (defun gnus-summary-highlight-line-0 ()
11784   (if (and (eq gnus-summary-highlight-line-trigger
11785                gnus-summary-highlight)
11786            gnus-summary-highlight-line-cached)
11787       gnus-summary-highlight-line-cached
11788     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11789           gnus-summary-highlight-line-cached
11790           (let* ((cond (list 'cond))
11791                  (c cond)
11792                  (list gnus-summary-highlight))
11793             (while list
11794               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11795                               nil))
11796               (setq c (cdr c)
11797                     list (cdr list)))
11798             (gnus-byte-compile (list 'lambda nil cond))))))
11799
11800 (defun gnus-summary-highlight-line ()
11801   "Highlight current line according to `gnus-summary-highlight'."
11802   (let* ((beg (point-at-bol))
11803          (article (or (gnus-summary-article-number) gnus-current-article))
11804          (score (or (cdr (assq article
11805                                gnus-newsgroup-scored))
11806                     gnus-summary-default-score 0))
11807          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11808          (inhibit-read-only t)
11809          (default gnus-summary-default-score)
11810          (default-high gnus-summary-default-high-score)
11811          (default-low gnus-summary-default-low-score)
11812          (uncached (and gnus-summary-use-undownloaded-faces
11813                         (memq article gnus-newsgroup-undownloaded)
11814                         (not (memq article gnus-newsgroup-cached)))))
11815     (let ((face (funcall (gnus-summary-highlight-line-0))))
11816       (unless (eq face (get-text-property beg 'face))
11817         (gnus-put-text-property-excluding-characters-with-faces
11818          beg (point-at-eol) 'face
11819          (setq face (if (boundp face) (symbol-value face) face)))
11820         (when gnus-summary-highlight-line-function
11821           (funcall gnus-summary-highlight-line-function article face))))))
11822
11823 (defun gnus-update-read-articles (group unread &optional compute)
11824   "Update the list of read articles in GROUP.
11825 UNREAD is a sorted list."
11826   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11827         (info (gnus-get-info group))
11828         (prev 1)
11829         read)
11830     (if (or (not info) (not active))
11831         ;; There is no info on this group if it was, in fact,
11832         ;; killed.  Gnus stores no information on killed groups, so
11833         ;; there's nothing to be done.
11834         ;; One could store the information somewhere temporarily,
11835         ;; perhaps...  Hmmm...
11836         ()
11837       ;; Remove any negative articles numbers.
11838       (while (and unread (< (car unread) 0))
11839         (setq unread (cdr unread)))
11840       ;; Remove any expired article numbers
11841       (while (and unread (< (car unread) (car active)))
11842         (setq unread (cdr unread)))
11843       ;; Compute the ranges of read articles by looking at the list of
11844       ;; unread articles.
11845       (while unread
11846         (when (/= (car unread) prev)
11847           (push (if (= prev (1- (car unread))) prev
11848                   (cons prev (1- (car unread))))
11849                 read))
11850         (setq prev (1+ (car unread)))
11851         (setq unread (cdr unread)))
11852       (when (<= prev (cdr active))
11853         (push (cons prev (cdr active)) read))
11854       (setq read (if (> (length read) 1) (nreverse read) read))
11855       (if compute
11856           read
11857         (save-excursion
11858           (let (setmarkundo)
11859             ;; Propagate the read marks to the backend.
11860             (when (gnus-check-backend-function 'request-set-mark group)
11861               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11862                     (add (gnus-remove-from-range read (gnus-info-read info))))
11863                 (when (or add del)
11864                   (unless (gnus-check-group group)
11865                     (error "Can't open server for %s" group))
11866                   (gnus-request-set-mark
11867                    group (delq nil (list (if add (list add 'add '(read)))
11868                                          (if del (list del 'del '(read))))))
11869                   (setq setmarkundo
11870                         `(gnus-request-set-mark
11871                           ,group
11872                           ',(delq nil (list
11873                                        (if del (list del 'add '(read)))
11874                                        (if add (list add 'del '(read))))))))))
11875             (set-buffer gnus-group-buffer)
11876             (gnus-undo-register
11877               `(progn
11878                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11879                  (gnus-info-set-read ',info ',(gnus-info-read info))
11880                  (gnus-get-unread-articles-in-group ',info
11881                                                     (gnus-active ,group))
11882                  (gnus-group-update-group ,group t)
11883                  ,setmarkundo))))
11884         ;; Enter this list into the group info.
11885         (gnus-info-set-read info read)
11886         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11887         (gnus-get-unread-articles-in-group info (gnus-active group))
11888         t))))
11889
11890 (defun gnus-offer-save-summaries ()
11891   "Offer to save all active summary buffers."
11892   (let (buffers)
11893     ;; Go through all buffers and find all summaries.
11894     (dolist (buffer (buffer-list))
11895       (when (and (setq buffer (buffer-name buffer))
11896                  (string-match "Summary" buffer)
11897                  (with-current-buffer buffer
11898                    ;; We check that this is, indeed, a summary buffer.
11899                    (and (eq major-mode 'gnus-summary-mode)
11900                         ;; Also make sure this isn't bogus.
11901                         gnus-newsgroup-prepared
11902                         ;; Also make sure that this isn't a
11903                         ;; dead summary buffer.
11904                         (not gnus-dead-summary-mode))))
11905         (push buffer buffers)))
11906     ;; Go through all these summary buffers and offer to save them.
11907     (when buffers
11908       (save-excursion
11909         (map-y-or-n-p
11910          "Update summary buffer %s? "
11911          (lambda (buf)
11912            (switch-to-buffer buf)
11913            (gnus-summary-exit))
11914          buffers)))))
11915
11916 (defun gnus-summary-setup-default-charset ()
11917   "Setup newsgroup default charset."
11918   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11919       (setq gnus-newsgroup-charset nil)
11920     (let* ((ignored-charsets
11921             (or gnus-newsgroup-ephemeral-ignored-charsets
11922                 (append
11923                  (and gnus-newsgroup-name
11924                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11925                  gnus-newsgroup-ignored-charsets))))
11926       (setq gnus-newsgroup-charset
11927             (or gnus-newsgroup-ephemeral-charset
11928                 (and gnus-newsgroup-name
11929                      (gnus-parameter-charset gnus-newsgroup-name))
11930                 gnus-default-charset))
11931       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11932            ignored-charsets))))
11933
11934 ;;;
11935 ;;; Mime Commands
11936 ;;;
11937
11938 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11939   "Display the current article buffer fully MIME-buttonized.
11940 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11941 treated as multipart/mixed."
11942   (interactive "P")
11943   (require 'gnus-art)
11944   (let ((gnus-unbuttonized-mime-types nil)
11945         (gnus-mime-display-multipart-as-mixed show-all-parts))
11946     (gnus-summary-show-article)))
11947
11948 (defun gnus-summary-repair-multipart (article)
11949   "Add a Content-Type header to a multipart article without one."
11950   (interactive (list (gnus-summary-article-number)))
11951   (gnus-with-article article
11952     (message-narrow-to-head)
11953     (message-remove-header "Mime-Version")
11954     (goto-char (point-max))
11955     (insert "Mime-Version: 1.0\n")
11956     (widen)
11957     (when (search-forward "\n--" nil t)
11958       (let ((separator (buffer-substring (point) (point-at-eol))))
11959         (message-narrow-to-head)
11960         (message-remove-header "Content-Type")
11961         (goto-char (point-max))
11962         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11963                         separator))
11964         (widen))))
11965   (let (gnus-mark-article-hook)
11966     (gnus-summary-select-article t t nil article)))
11967
11968 (defun gnus-summary-toggle-display-buttonized ()
11969   "Toggle the buttonizing of the article buffer."
11970   (interactive)
11971   (require 'gnus-art)
11972   (if (setq gnus-inhibit-mime-unbuttonizing
11973             (not gnus-inhibit-mime-unbuttonizing))
11974       (let ((gnus-unbuttonized-mime-types nil))
11975         (gnus-summary-show-article))
11976     (gnus-summary-show-article)))
11977
11978 ;;;
11979 ;;; Generic summary marking commands
11980 ;;;
11981
11982 (defvar gnus-summary-marking-alist
11983   '((read gnus-del-mark "d")
11984     (unread gnus-unread-mark "u")
11985     (ticked gnus-ticked-mark "!")
11986     (dormant gnus-dormant-mark "?")
11987     (expirable gnus-expirable-mark "e"))
11988   "An alist of names/marks/keystrokes.")
11989
11990 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11991 (defvar gnus-summary-mark-map)
11992
11993 (defun gnus-summary-make-all-marking-commands ()
11994   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11995   (dolist (elem gnus-summary-marking-alist)
11996     (apply 'gnus-summary-make-marking-command elem)))
11997
11998 (defun gnus-summary-make-marking-command (name mark keystroke)
11999   (let ((map (make-sparse-keymap)))
12000     (define-key gnus-summary-generic-mark-map keystroke map)
12001     (dolist (lway `((next "next" next nil "n")
12002                     (next-unread "next unread" next t "N")
12003                     (prev "previous" prev nil "p")
12004                     (prev-unread "previous unread" prev t "P")
12005                     (nomove "" nil nil ,keystroke)))
12006       (let ((func (gnus-summary-make-marking-command-1
12007                    mark (car lway) lway name)))
12008         (setq func (eval func))
12009         (define-key map (nth 4 lway) func)))))
12010
12011 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12012   `(defun ,(intern
12013             (format "gnus-summary-put-mark-as-%s%s"
12014                     name (if (eq way 'nomove)
12015                              ""
12016                            (concat "-" (symbol-name way)))))
12017      (n)
12018      ,(format
12019        "Mark the current article as %s%s.
12020 If N, the prefix, then repeat N times.
12021 If N is negative, move in reverse order.
12022 The difference between N and the actual number of articles marked is
12023 returned."
12024        name (cadr lway))
12025      (interactive "p")
12026      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12027
12028 (defun gnus-summary-generic-mark (n mark move unread)
12029   "Mark N articles with MARK."
12030   (unless (eq major-mode 'gnus-summary-mode)
12031     (error "This command can only be used in the summary buffer"))
12032   (gnus-summary-show-thread)
12033   (let ((nummove
12034          (cond
12035           ((eq move 'next) 1)
12036           ((eq move 'prev) -1)
12037           (t 0))))
12038     (if (zerop nummove)
12039         (setq n 1)
12040       (when (< n 0)
12041         (setq n (abs n)
12042               nummove (* -1 nummove))))
12043     (while (and (> n 0)
12044                 (gnus-summary-mark-article nil mark)
12045                 (zerop (gnus-summary-next-subject nummove unread t)))
12046       (setq n (1- n)))
12047     (when (/= 0 n)
12048       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12049     (gnus-summary-recenter)
12050     (gnus-summary-position-point)
12051     (gnus-set-mode-line 'summary)
12052     n))
12053
12054 (defun gnus-summary-insert-articles (articles)
12055   (when (setq articles
12056               (gnus-sorted-difference articles
12057                                       (mapcar (lambda (h)
12058                                                 (mail-header-number h))
12059                                               gnus-newsgroup-headers)))
12060     (setq gnus-newsgroup-headers
12061           (gnus-merge 'list
12062                       gnus-newsgroup-headers
12063                       (gnus-fetch-headers articles)
12064                       'gnus-article-sort-by-number))
12065     ;; Suppress duplicates?
12066     (when gnus-suppress-duplicates
12067       (gnus-dup-suppress-articles))
12068
12069     ;; We might want to build some more threads first.
12070     (when (and gnus-fetch-old-headers
12071                (eq gnus-headers-retrieved-by 'nov))
12072       (if (eq gnus-fetch-old-headers 'invisible)
12073           (gnus-build-all-threads)
12074         (gnus-build-old-threads)))
12075     ;; Let the Gnus agent mark articles as read.
12076     (when gnus-agent
12077       (gnus-agent-get-undownloaded-list))
12078     ;; Remove list identifiers from subject
12079     (when gnus-list-identifiers
12080       (gnus-summary-remove-list-identifiers))
12081     ;; First and last article in this newsgroup.
12082     (when gnus-newsgroup-headers
12083       (setq gnus-newsgroup-begin
12084             (mail-header-number (car gnus-newsgroup-headers))
12085             gnus-newsgroup-end
12086             (mail-header-number
12087              (gnus-last-element gnus-newsgroup-headers))))
12088     (when gnus-use-scoring
12089       (gnus-possibly-score-headers))))
12090
12091 (defun gnus-summary-insert-old-articles (&optional all)
12092   "Insert all old articles in this group.
12093 If ALL is non-nil, already read articles become readable.
12094 If ALL is a number, fetch this number of articles."
12095   (interactive "P")
12096   (prog1
12097       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12098             older len)
12099         (setq older
12100               ;; Some nntp servers lie about their active range.  When
12101               ;; this happens, the active range can be in the millions.
12102               ;; Use a compressed range to avoid creating a huge list.
12103               (gnus-range-difference (list gnus-newsgroup-active) old))
12104         (setq len (gnus-range-length older))
12105         (cond
12106          ((null older) nil)
12107          ((numberp all)
12108           (if (< all len)
12109               (let ((older-range (nreverse older)))
12110                 (setq older nil)
12111
12112                 (while (> all 0)
12113                   (let* ((r (pop older-range))
12114                          (min (if (numberp r) r (car r)))
12115                          (max (if (numberp r) r (cdr r))))
12116                     (while (and (<= min max)
12117                                 (> all 0))
12118                       (push max older)
12119                       (setq all (1- all)
12120                             max (1- max))))))
12121             (setq older (gnus-uncompress-range older))))
12122          (all
12123           (setq older (gnus-uncompress-range older)))
12124          (t
12125           (when (and (numberp gnus-large-newsgroup)
12126                    (> len gnus-large-newsgroup))
12127               (let* ((cursor-in-echo-area nil)
12128                      (initial (gnus-parameter-large-newsgroup-initial
12129                                gnus-newsgroup-name))
12130                      (input
12131                       (read-string
12132                        (format
12133                         "How many articles from %s (%s %d): "
12134                         (gnus-limit-string
12135                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12136                         (if initial "max" "default")
12137                         len)
12138                        (if initial
12139                            (cons (number-to-string initial)
12140                                  0)))))
12141                 (unless (string-match "^[ \t]*$" input)
12142                   (setq all (string-to-number input))
12143                   (if (< all len)
12144                       (let ((older-range (nreverse older)))
12145                         (setq older nil)
12146
12147                         (while (> all 0)
12148                           (let* ((r (pop older-range))
12149                                  (min (if (numberp r) r (car r)))
12150                                  (max (if (numberp r) r (cdr r))))
12151                             (while (and (<= min max)
12152                                         (> all 0))
12153                               (push max older)
12154                               (setq all (1- all)
12155                                     max (1- max))))))))))
12156           (setq older (gnus-uncompress-range older))))
12157         (if (not older)
12158             (message "No old news.")
12159           (gnus-summary-insert-articles older)
12160           (gnus-summary-limit (gnus-sorted-nunion old older))))
12161     (gnus-summary-position-point)))
12162
12163 (defun gnus-summary-insert-new-articles ()
12164   "Insert all new articles in this group."
12165   (interactive)
12166   (prog1
12167       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12168             (old-active gnus-newsgroup-active)
12169             (nnmail-fetched-sources (list t))
12170             i new)
12171         (setq gnus-newsgroup-active
12172               (gnus-activate-group gnus-newsgroup-name 'scan))
12173         (setq i (cdr gnus-newsgroup-active))
12174         (while (> i (cdr old-active))
12175           (push i new)
12176           (decf i))
12177         (if (not new)
12178             (message "No gnus is bad news")
12179           (gnus-summary-insert-articles new)
12180           (setq gnus-newsgroup-unreads
12181                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12182           (gnus-summary-limit (gnus-sorted-nunion old new))))
12183     (gnus-summary-position-point)))
12184
12185 (gnus-summary-make-all-marking-commands)
12186
12187 (gnus-ems-redefine)
12188
12189 (provide 'gnus-sum)
12190
12191 (run-hooks 'gnus-sum-load-hook)
12192
12193 ;; Local Variables:
12194 ;; coding: iso-8859-1
12195 ;; End:
12196
12197 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12198 ;;; gnus-sum.el ends here