* gnus-art.el (gnus-save-all-headers): Mention it might be overridden.
[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   "Variable that says which function should be used to decode a string with encoded words.")
1056
1057 (defcustom gnus-extra-headers '(To Newsgroups)
1058   "*Extra headers to parse."
1059   :version "21.1"
1060   :group 'gnus-summary
1061   :type '(repeat symbol))
1062
1063 (defcustom gnus-ignored-from-addresses
1064   (and user-mail-address  
1065        (not (string= user-mail-address ""))
1066        (regexp-quote user-mail-address))
1067   "*Regexp of From headers that may be suppressed in favor of To headers."
1068   :version "21.1"
1069   :group 'gnus-summary
1070   :type 'regexp)
1071
1072 (defcustom gnus-summary-to-prefix "-> "
1073   "*String prefixed to the To field in the summary line when
1074 using `gnus-ignored-from-addresses'."
1075   :version "22.1"
1076   :group 'gnus-summary
1077   :type 'string)
1078
1079 (defcustom gnus-summary-newsgroup-prefix "=> "
1080   "*String prefixed to the Newsgroup field in the summary
1081 line when using `gnus-ignored-from-addresses'."
1082   :version "22.1"
1083   :group 'gnus-summary
1084   :type 'string)
1085
1086 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1087   "List of charsets that should be ignored.
1088 When these charsets are used in the \"charset\" parameter, the
1089 default charset will be used instead."
1090   :version "21.1"
1091   :type '(repeat symbol)
1092   :group 'gnus-charset)
1093
1094 (gnus-define-group-parameter
1095  ignored-charsets
1096  :type list
1097  :function-document
1098  "Return the ignored charsets of GROUP."
1099  :variable gnus-group-ignored-charsets-alist
1100  :variable-default
1101  '(("alt\\.chinese\\.text" iso-8859-1))
1102  :variable-document
1103  "Alist of regexps (to match group names) and charsets that should be ignored.
1104 When these charsets are used in the \"charset\" parameter, the
1105 default charset will be used instead."
1106  :variable-group gnus-charset
1107  :variable-type '(repeat (cons (regexp :tag "Group")
1108                                (repeat symbol)))
1109  :parameter-type '(choice :tag "Ignored charsets"
1110                           :value nil
1111                           (repeat (symbol)))
1112  :parameter-document       "\
1113 List of charsets that should be ignored.
1114
1115 When these charsets are used in the \"charset\" parameter, the
1116 default charset will be used instead.")
1117
1118 (defcustom gnus-group-highlight-words-alist nil
1119   "Alist of group regexps and highlight regexps.
1120 This variable uses the same syntax as `gnus-emphasis-alist'."
1121   :version "21.1"
1122   :type '(repeat (cons (regexp :tag "Group")
1123                        (repeat (list (regexp :tag "Highlight regexp")
1124                                      (number :tag "Group for entire word" 0)
1125                                      (number :tag "Group for displayed part" 0)
1126                                      (symbol :tag "Face"
1127                                              gnus-emphasis-highlight-words)))))
1128   :group 'gnus-summary-visual)
1129
1130 (defcustom gnus-summary-show-article-charset-alist
1131   nil
1132   "Alist of number and charset.
1133 The article will be shown with the charset corresponding to the
1134 numbered argument.
1135 For example: ((1 . cn-gb-2312) (2 . big5))."
1136   :version "21.1"
1137   :type '(repeat (cons (number :tag "Argument" 1)
1138                        (symbol :tag "Charset")))
1139   :group 'gnus-charset)
1140
1141 (defcustom gnus-preserve-marks t
1142   "Whether marks are preserved when moving, copying and respooling messages."
1143   :version "21.1"
1144   :type 'boolean
1145   :group 'gnus-summary-marks)
1146
1147 (defcustom gnus-alter-articles-to-read-function nil
1148   "Function to be called to alter the list of articles to be selected."
1149   :type '(choice (const nil) function)
1150   :group 'gnus-summary)
1151
1152 (defcustom gnus-orphan-score nil
1153   "*All orphans get this score added.  Set in the score file."
1154   :group 'gnus-score-default
1155   :type '(choice (const nil)
1156                  integer))
1157
1158 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1159   "*A regexp to match MIME parts when saving multiple parts of a
1160 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1161 This regexp will be used by default when prompting the user for which
1162 type of files to save."
1163   :group 'gnus-summary
1164   :type 'regexp)
1165
1166 (defcustom gnus-read-all-available-headers nil
1167   "Whether Gnus should parse all headers made available to it.
1168 This is mostly relevant for slow back ends where the user may
1169 wish to widen the summary buffer to include all headers
1170 that were fetched.  Say, for nnultimate groups."
1171   :version "22.1"
1172   :group 'gnus-summary
1173   :type '(choice boolean regexp))
1174
1175 (defcustom gnus-summary-muttprint-program "muttprint"
1176   "Command (and optional arguments) used to run Muttprint."
1177   :version "22.1"
1178   :group 'gnus-summary
1179   :type 'string)
1180
1181 (defcustom gnus-article-loose-mime t
1182   "If non-nil, don't require MIME-Version header.
1183 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1184 supply the MIME-Version header or deliberately strip it from the mail.
1185 If non-nil (the default), Gnus will treat some articles as MIME
1186 even if the MIME-Version header is missing."
1187   :version "22.1"
1188   :type 'boolean
1189   :group 'gnus-article-mime)
1190
1191 (defcustom gnus-article-emulate-mime t
1192   "If non-nil, use MIME emulation for uuencode and the like.
1193 This means that Gnus will search message bodies for text that look
1194 like uuencoded bits, yEncoded bits, and so on, and present that using
1195 the normal Gnus MIME machinery."
1196   :version "22.1"
1197   :type 'boolean
1198   :group 'gnus-article-mime)
1199
1200 ;;; Internal variables
1201
1202 (defvar gnus-summary-display-cache nil)
1203 (defvar gnus-article-mime-handles nil)
1204 (defvar gnus-article-decoded-p nil)
1205 (defvar gnus-article-charset nil)
1206 (defvar gnus-article-ignored-charsets nil)
1207 (defvar gnus-scores-exclude-files nil)
1208 (defvar gnus-page-broken nil)
1209
1210 (defvar gnus-original-article nil)
1211 (defvar gnus-article-internal-prepare-hook nil)
1212 (defvar gnus-newsgroup-process-stack nil)
1213
1214 (defvar gnus-thread-indent-array nil)
1215 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1216 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1217   "Function called to sort the articles within a thread after it has been gathered together.")
1218
1219 (defvar gnus-summary-save-parts-type-history nil)
1220 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1221
1222 ;; Avoid highlighting in kill files.
1223 (defvar gnus-summary-inhibit-highlight nil)
1224 (defvar gnus-newsgroup-selected-overlay nil)
1225 (defvar gnus-inhibit-limiting nil)
1226 (defvar gnus-newsgroup-adaptive-score-file nil)
1227 (defvar gnus-current-score-file nil)
1228 (defvar gnus-current-move-group nil)
1229 (defvar gnus-current-copy-group nil)
1230 (defvar gnus-current-crosspost-group nil)
1231 (defvar gnus-newsgroup-display nil)
1232
1233 (defvar gnus-newsgroup-dependencies nil)
1234 (defvar gnus-newsgroup-adaptive nil)
1235 (defvar gnus-summary-display-article-function nil)
1236 (defvar gnus-summary-highlight-line-function nil
1237   "Function called after highlighting a summary line.")
1238
1239 (defvar gnus-summary-line-format-alist
1240   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1241     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1242     (?s gnus-tmp-subject-or-nil ?s)
1243     (?n gnus-tmp-name ?s)
1244     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1245         ?s)
1246     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1247             gnus-tmp-from) ?s)
1248     (?F gnus-tmp-from ?s)
1249     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1250     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1251     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1252     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1253     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1254     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1255     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1256     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1257     (?L gnus-tmp-lines ?s)
1258     (?O gnus-tmp-downloaded ?c)
1259     (?I gnus-tmp-indentation ?s)
1260     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1261     (?R gnus-tmp-replied ?c)
1262     (?\[ gnus-tmp-opening-bracket ?c)
1263     (?\] gnus-tmp-closing-bracket ?c)
1264     (?\> (make-string gnus-tmp-level ? ) ?s)
1265     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1266     (?i gnus-tmp-score ?d)
1267     (?z gnus-tmp-score-char ?c)
1268     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1269     (?U gnus-tmp-unread ?c)
1270     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1271         ?s)
1272     (?t (gnus-summary-number-of-articles-in-thread
1273          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1274         ?d)
1275     (?e (gnus-summary-number-of-articles-in-thread
1276          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1277         ?c)
1278     (?u gnus-tmp-user-defined ?s)
1279     (?P (gnus-pick-line-number) ?d)
1280     (?B gnus-tmp-thread-tree-header-string ?s)
1281     (user-date (gnus-user-date
1282                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1283   "An alist of format specifications that can appear in summary lines.
1284 These are paired with what variables they correspond with, along with
1285 the type of the variable (string, integer, character, etc).")
1286
1287 (defvar gnus-summary-dummy-line-format-alist
1288   `((?S gnus-tmp-subject ?s)
1289     (?N gnus-tmp-number ?d)
1290     (?u gnus-tmp-user-defined ?s)))
1291
1292 (defvar gnus-summary-mode-line-format-alist
1293   `((?G gnus-tmp-group-name ?s)
1294     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1295     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1296     (?A gnus-tmp-article-number ?d)
1297     (?Z gnus-tmp-unread-and-unselected ?s)
1298     (?V gnus-version ?s)
1299     (?U gnus-tmp-unread-and-unticked ?d)
1300     (?S gnus-tmp-subject ?s)
1301     (?e gnus-tmp-unselected ?d)
1302     (?u gnus-tmp-user-defined ?s)
1303     (?d (length gnus-newsgroup-dormant) ?d)
1304     (?t (length gnus-newsgroup-marked) ?d)
1305     (?h (length gnus-newsgroup-spam-marked) ?d)
1306     (?r (length gnus-newsgroup-reads) ?d)
1307     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1308     (?E gnus-newsgroup-expunged-tally ?d)
1309     (?s (gnus-current-score-file-nondirectory) ?s)))
1310
1311 (defvar gnus-last-search-regexp nil
1312   "Default regexp for article search command.")
1313
1314 (defvar gnus-last-shell-command nil
1315   "Default shell command on article.")
1316
1317 (defvar gnus-newsgroup-agentized nil
1318   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1319 (defvar gnus-newsgroup-begin nil)
1320 (defvar gnus-newsgroup-end nil)
1321 (defvar gnus-newsgroup-last-rmail nil)
1322 (defvar gnus-newsgroup-last-mail nil)
1323 (defvar gnus-newsgroup-last-folder nil)
1324 (defvar gnus-newsgroup-last-file nil)
1325 (defvar gnus-newsgroup-last-directory nil)
1326 (defvar gnus-newsgroup-auto-expire nil)
1327 (defvar gnus-newsgroup-active nil)
1328
1329 (defvar gnus-newsgroup-data nil)
1330 (defvar gnus-newsgroup-data-reverse nil)
1331 (defvar gnus-newsgroup-limit nil)
1332 (defvar gnus-newsgroup-limits nil)
1333 (defvar gnus-summary-use-undownloaded-faces nil)
1334
1335 (defvar gnus-newsgroup-unreads nil
1336   "Sorted list of unread articles in the current newsgroup.")
1337
1338 (defvar gnus-newsgroup-unselected nil
1339   "Sorted list of unselected unread articles in the current newsgroup.")
1340
1341 (defvar gnus-newsgroup-reads nil
1342   "Alist of read articles and article marks in the current newsgroup.")
1343
1344 (defvar gnus-newsgroup-expunged-tally nil)
1345
1346 (defvar gnus-newsgroup-marked nil
1347   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1348
1349 (defvar gnus-newsgroup-spam-marked nil
1350   "List of ranges of articles that have been marked as spam.")
1351
1352 (defvar gnus-newsgroup-killed nil
1353   "List of ranges of articles that have been through the scoring process.")
1354
1355 (defvar gnus-newsgroup-cached nil
1356   "Sorted list of articles that come from the article cache.")
1357
1358 (defvar gnus-newsgroup-saved nil
1359   "List of articles that have been saved.")
1360
1361 (defvar gnus-newsgroup-kill-headers nil)
1362
1363 (defvar gnus-newsgroup-replied nil
1364   "List of articles that have been replied to in the current newsgroup.")
1365
1366 (defvar gnus-newsgroup-forwarded nil
1367   "List of articles that have been forwarded in the current newsgroup.")
1368
1369 (defvar gnus-newsgroup-recent nil
1370   "List of articles that have are recent in the current newsgroup.")
1371
1372 (defvar gnus-newsgroup-expirable nil
1373   "Sorted list of articles in the current newsgroup that can be expired.")
1374
1375 (defvar gnus-newsgroup-processable nil
1376   "List of articles in the current newsgroup that can be processed.")
1377
1378 (defvar gnus-newsgroup-downloadable nil
1379   "Sorted list of articles in the current newsgroup that can be processed.")
1380
1381 (defvar gnus-newsgroup-unfetched nil
1382   "Sorted list of articles in the current newsgroup whose headers have
1383 not been fetched into the agent.
1384
1385 This list will always be a subset of gnus-newsgroup-undownloaded.")
1386
1387 (defvar gnus-newsgroup-undownloaded nil
1388   "List of articles in the current newsgroup that haven't been downloaded.")
1389
1390 (defvar gnus-newsgroup-unsendable nil
1391   "List of articles in the current newsgroup that won't be sent.")
1392
1393 (defvar gnus-newsgroup-bookmarks nil
1394   "List of articles in the current newsgroup that have bookmarks.")
1395
1396 (defvar gnus-newsgroup-dormant nil
1397   "Sorted list of dormant articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-unseen nil
1400   "List of unseen articles in the current newsgroup.")
1401
1402 (defvar gnus-newsgroup-seen nil
1403   "Range of seen articles in the current newsgroup.")
1404
1405 (defvar gnus-newsgroup-articles nil
1406   "List of articles in the current newsgroup.")
1407
1408 (defvar gnus-newsgroup-scored nil
1409   "List of scored articles in the current newsgroup.")
1410
1411 (defvar gnus-newsgroup-headers nil
1412   "List of article headers in the current newsgroup.")
1413
1414 (defvar gnus-newsgroup-threads nil)
1415
1416 (defvar gnus-newsgroup-prepared nil
1417   "Whether the current group has been prepared properly.")
1418
1419 (defvar gnus-newsgroup-ancient nil
1420   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1421
1422 (defvar gnus-newsgroup-sparse nil)
1423
1424 (defvar gnus-current-article nil)
1425 (defvar gnus-article-current nil)
1426 (defvar gnus-current-headers nil)
1427 (defvar gnus-have-all-headers nil)
1428 (defvar gnus-last-article nil)
1429 (defvar gnus-newsgroup-history nil)
1430 (defvar gnus-newsgroup-charset nil)
1431 (defvar gnus-newsgroup-ephemeral-charset nil)
1432 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1433
1434 (defvar gnus-article-before-search nil)
1435
1436 (defvar gnus-summary-local-variables
1437   '(gnus-newsgroup-name
1438     gnus-newsgroup-begin gnus-newsgroup-end
1439     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1440     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1441     gnus-newsgroup-last-directory
1442     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1443     gnus-newsgroup-unselected gnus-newsgroup-marked
1444     gnus-newsgroup-spam-marked
1445     gnus-newsgroup-reads gnus-newsgroup-saved
1446     gnus-newsgroup-replied gnus-newsgroup-forwarded
1447     gnus-newsgroup-recent
1448     gnus-newsgroup-expirable
1449     gnus-newsgroup-processable gnus-newsgroup-killed
1450     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1451     gnus-newsgroup-unfetched
1452     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1453     gnus-newsgroup-seen gnus-newsgroup-articles
1454     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1455     gnus-newsgroup-headers gnus-newsgroup-threads
1456     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1457     gnus-current-article gnus-current-headers gnus-have-all-headers
1458     gnus-last-article gnus-article-internal-prepare-hook
1459     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1460     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1461     gnus-thread-expunge-below
1462     gnus-score-alist gnus-current-score-file
1463     (gnus-summary-expunge-below . global)
1464     (gnus-summary-mark-below . global)
1465     (gnus-orphan-score . global)
1466     gnus-newsgroup-active gnus-scores-exclude-files
1467     gnus-newsgroup-history gnus-newsgroup-ancient
1468     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1469     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1470     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1471     (gnus-newsgroup-expunged-tally . 0)
1472     gnus-cache-removable-articles gnus-newsgroup-cached
1473     gnus-newsgroup-data gnus-newsgroup-data-reverse
1474     gnus-newsgroup-limit gnus-newsgroup-limits
1475     gnus-newsgroup-charset gnus-newsgroup-display
1476     gnus-summary-use-undownloaded-faces)
1477   "Variables that are buffer-local to the summary buffers.")
1478
1479 (defvar gnus-newsgroup-variables nil
1480   "A list of variables that have separate values in different newsgroups.
1481 A list of newsgroup (summary buffer) local variables, or cons of
1482 variables and their default expressions to be evalled (when the default
1483 values are not nil), that should be made global while the summary buffer
1484 is active.
1485
1486 Note: The default expressions will be evaluated (using function `eval')
1487 before assignment to the local variable rather than just assigned to it.
1488 If the default expression is the symbol `global', that symbol will not
1489 be evaluated but the global value of the local variable will be used
1490 instead.
1491
1492 These variables can be used to set variables in the group parameters
1493 while still allowing them to affect operations done in other buffers.
1494 For example:
1495
1496 \(setq gnus-newsgroup-variables
1497      '(message-use-followup-to
1498        (gnus-visible-headers .
1499          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1500 ")
1501
1502 ;; Byte-compiler warning.
1503 (eval-when-compile
1504   ;; Bind features so that require will believe that gnus-sum has
1505   ;; already been loaded (avoids infinite recursion)
1506   (let ((features (cons 'gnus-sum features)))
1507     ;; Several of the declarations in gnus-sum are needed to load the
1508     ;; following files. Right now, these definitions have been
1509     ;; compiled but not defined (evaluated).  We could either do a
1510     ;; eval-and-compile about all of the declarations or evaluate the
1511     ;; source file.
1512     (if (boundp 'gnus-newsgroup-variables)
1513         nil
1514       (load "gnus-sum.el" t t t))
1515     (require 'gnus)
1516     (require 'gnus-art)))
1517
1518 ;; MIME stuff.
1519
1520 (defvar gnus-decode-encoded-word-methods
1521   '(mail-decode-encoded-word-string)
1522   "List of methods used to decode encoded words.
1523
1524 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1525 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1526 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1527 whose names match REGEXP.
1528
1529 For example:
1530 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1531  mail-decode-encoded-word-string
1532  (\"chinese\" . rfc1843-decode-string))")
1533
1534 (defvar gnus-decode-encoded-word-methods-cache nil)
1535
1536 (defun gnus-multi-decode-encoded-word-string (string)
1537   "Apply the functions from `gnus-encoded-word-methods' that match."
1538   (unless (and gnus-decode-encoded-word-methods-cache
1539                (eq gnus-newsgroup-name
1540                    (car gnus-decode-encoded-word-methods-cache)))
1541     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1542     (mapcar (lambda (x)
1543               (if (symbolp x)
1544                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1545                 (if (and gnus-newsgroup-name
1546                          (string-match (car x) gnus-newsgroup-name))
1547                     (nconc gnus-decode-encoded-word-methods-cache
1548                            (list (cdr x))))))
1549             gnus-decode-encoded-word-methods))
1550   (let ((xlist gnus-decode-encoded-word-methods-cache))
1551     (pop xlist)
1552     (while xlist
1553       (setq string (funcall (pop xlist) string))))
1554   string)
1555
1556 ;; Subject simplification.
1557
1558 (defun gnus-simplify-whitespace (str)
1559   "Remove excessive whitespace from STR."
1560   ;; Multiple spaces.
1561   (while (string-match "[ \t][ \t]+" str)
1562     (setq str (concat (substring str 0 (match-beginning 0))
1563                         " "
1564                         (substring str (match-end 0)))))
1565   ;; Leading spaces.
1566   (when (string-match "^[ \t]+" str)
1567     (setq str (substring str (match-end 0))))
1568   ;; Trailing spaces.
1569   (when (string-match "[ \t]+$" str)
1570     (setq str (substring str 0 (match-beginning 0))))
1571   str)
1572
1573 (defun gnus-simplify-all-whitespace (str)
1574   "Remove all whitespace from STR."
1575   (while (string-match "[ \t\n]+" str)
1576     (setq str (replace-match "" nil nil str)))
1577   str)
1578
1579 (defsubst gnus-simplify-subject-re (subject)
1580   "Remove \"Re:\" from subject lines."
1581   (if (string-match message-subject-re-regexp subject)
1582       (substring subject (match-end 0))
1583     subject))
1584
1585 (defun gnus-simplify-subject (subject &optional re-only)
1586   "Remove `Re:' and words in parentheses.
1587 If RE-ONLY is non-nil, strip leading `Re:'s only."
1588   (let ((case-fold-search t))           ;Ignore case.
1589     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1590     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1591       (setq subject (substring subject (match-end 0))))
1592     ;; Remove uninteresting prefixes.
1593     (when (and (not re-only)
1594                gnus-simplify-ignored-prefixes
1595                (string-match gnus-simplify-ignored-prefixes subject))
1596       (setq subject (substring subject (match-end 0))))
1597     ;; Remove words in parentheses from end.
1598     (unless re-only
1599       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1600         (setq subject (substring subject 0 (match-beginning 0)))))
1601     ;; Return subject string.
1602     subject))
1603
1604 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1605 ;; all whitespace.
1606 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1607   (goto-char (point-min))
1608   (while (re-search-forward regexp nil t)
1609     (replace-match (or newtext ""))))
1610
1611 (defun gnus-simplify-buffer-fuzzy ()
1612   "Simplify string in the buffer fuzzily.
1613 The string in the accessible portion of the current buffer is simplified.
1614 It is assumed to be a single-line subject.
1615 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1616 matter is removed.  Additional things can be deleted by setting
1617 `gnus-simplify-subject-fuzzy-regexp'."
1618   (let ((case-fold-search t)
1619         (modified-tick))
1620     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1621
1622     (while (not (eq modified-tick (buffer-modified-tick)))
1623       (setq modified-tick (buffer-modified-tick))
1624       (cond
1625        ((listp gnus-simplify-subject-fuzzy-regexp)
1626         (mapcar 'gnus-simplify-buffer-fuzzy-step
1627                 gnus-simplify-subject-fuzzy-regexp))
1628        (gnus-simplify-subject-fuzzy-regexp
1629         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1630       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1631       (gnus-simplify-buffer-fuzzy-step
1632        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1633       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1634
1635     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1636     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1637     (gnus-simplify-buffer-fuzzy-step " $")
1638     (gnus-simplify-buffer-fuzzy-step "^ +")))
1639
1640 (defun gnus-simplify-subject-fuzzy (subject)
1641   "Simplify a subject string fuzzily.
1642 See `gnus-simplify-buffer-fuzzy' for details."
1643   (save-excursion
1644     (gnus-set-work-buffer)
1645     (let ((case-fold-search t))
1646       ;; Remove uninteresting prefixes.
1647       (when (and gnus-simplify-ignored-prefixes
1648                  (string-match gnus-simplify-ignored-prefixes subject))
1649         (setq subject (substring subject (match-end 0))))
1650       (insert subject)
1651       (inline (gnus-simplify-buffer-fuzzy))
1652       (buffer-string))))
1653
1654 (defsubst gnus-simplify-subject-fully (subject)
1655   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1656   (cond
1657    (gnus-simplify-subject-functions
1658     (gnus-map-function gnus-simplify-subject-functions subject))
1659    ((null gnus-summary-gather-subject-limit)
1660     (gnus-simplify-subject-re subject))
1661    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1662     (gnus-simplify-subject-fuzzy subject))
1663    ((numberp gnus-summary-gather-subject-limit)
1664     (gnus-limit-string (gnus-simplify-subject-re subject)
1665                        gnus-summary-gather-subject-limit))
1666    (t
1667     subject)))
1668
1669 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1670   "Check whether two subjects are equal.
1671 If optional argument SIMPLE-FIRST is t, first argument is already
1672 simplified."
1673   (cond
1674    ((null simple-first)
1675     (equal (gnus-simplify-subject-fully s1)
1676            (gnus-simplify-subject-fully s2)))
1677    (t
1678     (equal s1
1679            (gnus-simplify-subject-fully s2)))))
1680
1681 (defun gnus-summary-bubble-group ()
1682   "Increase the score of the current group.
1683 This is a handy function to add to `gnus-summary-exit-hook' to
1684 increase the score of each group you read."
1685   (gnus-group-add-score gnus-newsgroup-name))
1686
1687 \f
1688 ;;;
1689 ;;; Gnus summary mode
1690 ;;;
1691
1692 (put 'gnus-summary-mode 'mode-class 'special)
1693
1694 (defvar gnus-article-commands-menu)
1695
1696 ;; Non-orthogonal keys
1697
1698 (gnus-define-keys gnus-summary-mode-map
1699   " " gnus-summary-next-page
1700   "\177" gnus-summary-prev-page
1701   [delete] gnus-summary-prev-page
1702   [backspace] gnus-summary-prev-page
1703   "\r" gnus-summary-scroll-up
1704   "\M-\r" gnus-summary-scroll-down
1705   "n" gnus-summary-next-unread-article
1706   "p" gnus-summary-prev-unread-article
1707   "N" gnus-summary-next-article
1708   "P" gnus-summary-prev-article
1709   "\M-\C-n" gnus-summary-next-same-subject
1710   "\M-\C-p" gnus-summary-prev-same-subject
1711   "\M-n" gnus-summary-next-unread-subject
1712   "\M-p" gnus-summary-prev-unread-subject
1713   "." gnus-summary-first-unread-article
1714   "," gnus-summary-best-unread-article
1715   "\M-s" gnus-summary-search-article-forward
1716   "\M-r" gnus-summary-search-article-backward
1717   "\M-S" gnus-summary-repeat-search-article-forward
1718   "\M-R" gnus-summary-repeat-search-article-backward
1719   "<" gnus-summary-beginning-of-article
1720   ">" gnus-summary-end-of-article
1721   "j" gnus-summary-goto-article
1722   "^" gnus-summary-refer-parent-article
1723   "\M-^" gnus-summary-refer-article
1724   "u" gnus-summary-tick-article-forward
1725   "!" gnus-summary-tick-article-forward
1726   "U" gnus-summary-tick-article-backward
1727   "d" gnus-summary-mark-as-read-forward
1728   "D" gnus-summary-mark-as-read-backward
1729   "E" gnus-summary-mark-as-expirable
1730   "\M-u" gnus-summary-clear-mark-forward
1731   "\M-U" gnus-summary-clear-mark-backward
1732   "k" gnus-summary-kill-same-subject-and-select
1733   "\C-k" gnus-summary-kill-same-subject
1734   "\M-\C-k" gnus-summary-kill-thread
1735   "\M-\C-l" gnus-summary-lower-thread
1736   "e" gnus-summary-edit-article
1737   "#" gnus-summary-mark-as-processable
1738   "\M-#" gnus-summary-unmark-as-processable
1739   "\M-\C-t" gnus-summary-toggle-threads
1740   "\M-\C-s" gnus-summary-show-thread
1741   "\M-\C-h" gnus-summary-hide-thread
1742   "\M-\C-f" gnus-summary-next-thread
1743   "\M-\C-b" gnus-summary-prev-thread
1744   [(meta down)] gnus-summary-next-thread
1745   [(meta up)] gnus-summary-prev-thread
1746   "\M-\C-u" gnus-summary-up-thread
1747   "\M-\C-d" gnus-summary-down-thread
1748   "&" gnus-summary-execute-command
1749   "c" gnus-summary-catchup-and-exit
1750   "\C-w" gnus-summary-mark-region-as-read
1751   "\C-t" gnus-summary-toggle-truncation
1752   "?" gnus-summary-mark-as-dormant
1753   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1754   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1755   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1756   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1757   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1758   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1759   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1760   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1761   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1762   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1763   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1764   "=" gnus-summary-expand-window
1765   "\C-x\C-s" gnus-summary-reselect-current-group
1766   "\M-g" gnus-summary-rescan-group
1767   "w" gnus-summary-stop-page-breaking
1768   "\C-c\C-r" gnus-summary-caesar-message
1769   "f" gnus-summary-followup
1770   "F" gnus-summary-followup-with-original
1771   "C" gnus-summary-cancel-article
1772   "r" gnus-summary-reply
1773   "R" gnus-summary-reply-with-original
1774   "\C-c\C-f" gnus-summary-mail-forward
1775   "o" gnus-summary-save-article
1776   "\C-o" gnus-summary-save-article-mail
1777   "|" gnus-summary-pipe-output
1778   "\M-k" gnus-summary-edit-local-kill
1779   "\M-K" gnus-summary-edit-global-kill
1780   ;; "V" gnus-version
1781   "\C-c\C-d" gnus-summary-describe-group
1782   "q" gnus-summary-exit
1783   "Q" gnus-summary-exit-no-update
1784   "\C-c\C-i" gnus-info-find-node
1785   gnus-mouse-2 gnus-mouse-pick-article
1786   [follow-link] mouse-face
1787   "m" gnus-summary-mail-other-window
1788   "a" gnus-summary-post-news
1789   "i" gnus-summary-news-other-window
1790   "x" gnus-summary-limit-to-unread
1791   "s" gnus-summary-isearch-article
1792   "t" gnus-summary-toggle-header
1793   "g" gnus-summary-show-article
1794   "l" gnus-summary-goto-last-article
1795   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1796   "\C-d" gnus-summary-enter-digest-group
1797   "\M-\C-d" gnus-summary-read-document
1798   "\M-\C-e" gnus-summary-edit-parameters
1799   "\M-\C-a" gnus-summary-customize-parameters
1800   "\C-c\C-b" gnus-bug
1801   "*" gnus-cache-enter-article
1802   "\M-*" gnus-cache-remove-article
1803   "\M-&" gnus-summary-universal-argument
1804   "\C-l" gnus-recenter
1805   "I" gnus-summary-increase-score
1806   "L" gnus-summary-lower-score
1807   "\M-i" gnus-symbolic-argument
1808   "h" gnus-summary-select-article-buffer
1809
1810   "b" gnus-article-view-part
1811   "\M-t" gnus-summary-toggle-display-buttonized
1812
1813   "V" gnus-summary-score-map
1814   "X" gnus-uu-extract-map
1815   "S" gnus-summary-send-map)
1816
1817 ;; Sort of orthogonal keymap
1818 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1819   "t" gnus-summary-tick-article-forward
1820   "!" gnus-summary-tick-article-forward
1821   "d" gnus-summary-mark-as-read-forward
1822   "r" gnus-summary-mark-as-read-forward
1823   "c" gnus-summary-clear-mark-forward
1824   " " gnus-summary-clear-mark-forward
1825   "e" gnus-summary-mark-as-expirable
1826   "x" gnus-summary-mark-as-expirable
1827   "?" gnus-summary-mark-as-dormant
1828   "b" gnus-summary-set-bookmark
1829   "B" gnus-summary-remove-bookmark
1830   "#" gnus-summary-mark-as-processable
1831   "\M-#" gnus-summary-unmark-as-processable
1832   "S" gnus-summary-limit-include-expunged
1833   "C" gnus-summary-catchup
1834   "H" gnus-summary-catchup-to-here
1835   "h" gnus-summary-catchup-from-here
1836   "\C-c" gnus-summary-catchup-all
1837   "k" gnus-summary-kill-same-subject-and-select
1838   "K" gnus-summary-kill-same-subject
1839   "P" gnus-uu-mark-map)
1840
1841 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1842   "c" gnus-summary-clear-above
1843   "u" gnus-summary-tick-above
1844   "m" gnus-summary-mark-above
1845   "k" gnus-summary-kill-below)
1846
1847 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1848   "/" gnus-summary-limit-to-subject
1849   "n" gnus-summary-limit-to-articles
1850   "b" gnus-summary-limit-to-bodies
1851   "w" gnus-summary-pop-limit
1852   "s" gnus-summary-limit-to-subject
1853   "a" gnus-summary-limit-to-author
1854   "u" gnus-summary-limit-to-unread
1855   "m" gnus-summary-limit-to-marks
1856   "M" gnus-summary-limit-exclude-marks
1857   "v" gnus-summary-limit-to-score
1858   "*" gnus-summary-limit-include-cached
1859   "D" gnus-summary-limit-include-dormant
1860   "T" gnus-summary-limit-include-thread
1861   "d" gnus-summary-limit-exclude-dormant
1862   "t" gnus-summary-limit-to-age
1863   "." gnus-summary-limit-to-unseen
1864   "x" gnus-summary-limit-to-extra
1865   "p" gnus-summary-limit-to-display-predicate
1866   "E" gnus-summary-limit-include-expunged
1867   "c" gnus-summary-limit-exclude-childless-dormant
1868   "C" gnus-summary-limit-mark-excluded-as-read
1869   "o" gnus-summary-insert-old-articles
1870   "N" gnus-summary-insert-new-articles
1871   "r" gnus-summary-limit-to-replied
1872   "R" gnus-summary-limit-to-recipient)
1873
1874 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1875   "n" gnus-summary-next-unread-article
1876   "p" gnus-summary-prev-unread-article
1877   "N" gnus-summary-next-article
1878   "P" gnus-summary-prev-article
1879   "\C-n" gnus-summary-next-same-subject
1880   "\C-p" gnus-summary-prev-same-subject
1881   "\M-n" gnus-summary-next-unread-subject
1882   "\M-p" gnus-summary-prev-unread-subject
1883   "f" gnus-summary-first-unread-article
1884   "b" gnus-summary-best-unread-article
1885   "j" gnus-summary-goto-article
1886   "g" gnus-summary-goto-subject
1887   "l" gnus-summary-goto-last-article
1888   "o" gnus-summary-pop-article)
1889
1890 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1891   "k" gnus-summary-kill-thread
1892   "l" gnus-summary-lower-thread
1893   "i" gnus-summary-raise-thread
1894   "T" gnus-summary-toggle-threads
1895   "t" gnus-summary-rethread-current
1896   "^" gnus-summary-reparent-thread
1897   "\M-^" gnus-summary-reparent-children
1898   "s" gnus-summary-show-thread
1899   "S" gnus-summary-show-all-threads
1900   "h" gnus-summary-hide-thread
1901   "H" gnus-summary-hide-all-threads
1902   "n" gnus-summary-next-thread
1903   "p" gnus-summary-prev-thread
1904   "u" gnus-summary-up-thread
1905   "o" gnus-summary-top-thread
1906   "d" gnus-summary-down-thread
1907   "#" gnus-uu-mark-thread
1908   "\M-#" gnus-uu-unmark-thread)
1909
1910 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1911   "g" gnus-summary-prepare
1912   "c" gnus-summary-insert-cached-articles
1913   "d" gnus-summary-insert-dormant-articles)
1914
1915 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1916   "c" gnus-summary-catchup-and-exit
1917   "C" gnus-summary-catchup-all-and-exit
1918   "E" gnus-summary-exit-no-update
1919   "Q" gnus-summary-exit
1920   "Z" gnus-summary-exit
1921   "n" gnus-summary-catchup-and-goto-next-group
1922   "p" gnus-summary-catchup-and-goto-prev-group
1923   "R" gnus-summary-reselect-current-group
1924   "G" gnus-summary-rescan-group
1925   "N" gnus-summary-next-group
1926   "s" gnus-summary-save-newsrc
1927   "P" gnus-summary-prev-group)
1928
1929 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1930   " " gnus-summary-next-page
1931   "n" gnus-summary-next-page
1932   "\177" gnus-summary-prev-page
1933   [delete] gnus-summary-prev-page
1934   "p" gnus-summary-prev-page
1935   "\r" gnus-summary-scroll-up
1936   "\M-\r" gnus-summary-scroll-down
1937   "<" gnus-summary-beginning-of-article
1938   ">" gnus-summary-end-of-article
1939   "b" gnus-summary-beginning-of-article
1940   "e" gnus-summary-end-of-article
1941   "^" gnus-summary-refer-parent-article
1942   "r" gnus-summary-refer-parent-article
1943   "D" gnus-summary-enter-digest-group
1944   "R" gnus-summary-refer-references
1945   "T" gnus-summary-refer-thread
1946   "g" gnus-summary-show-article
1947   "s" gnus-summary-isearch-article
1948   "P" gnus-summary-print-article
1949   "M" gnus-mailing-list-insinuate
1950   "t" gnus-article-babel)
1951
1952 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1953   "b" gnus-article-add-buttons
1954   "B" gnus-article-add-buttons-to-head
1955   "o" gnus-article-treat-overstrike
1956   "e" gnus-article-emphasize
1957   "w" gnus-article-fill-cited-article
1958   "Q" gnus-article-fill-long-lines
1959   "L" gnus-article-toggle-truncate-lines
1960   "C" gnus-article-capitalize-sentences
1961   "c" gnus-article-remove-cr
1962   "q" gnus-article-de-quoted-unreadable
1963   "6" gnus-article-de-base64-unreadable
1964   "Z" gnus-article-decode-HZ
1965   "A" gnus-article-treat-ansi-sequences
1966   "h" gnus-article-wash-html
1967   "u" gnus-article-unsplit-urls
1968   "s" gnus-summary-force-verify-and-decrypt
1969   "f" gnus-article-display-x-face
1970   "l" gnus-summary-stop-page-breaking
1971   "r" gnus-summary-caesar-message
1972   "m" gnus-summary-morse-message
1973   "t" gnus-summary-toggle-header
1974   "g" gnus-treat-smiley
1975   "v" gnus-summary-verbose-headers
1976   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1977   "p" gnus-article-verify-x-pgp-sig
1978   "d" gnus-article-treat-dumbquotes
1979   "i" gnus-summary-idna-message)
1980
1981 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1982   ;; mnemonic: deuglif*Y*
1983   "u" gnus-article-outlook-unwrap-lines
1984   "a" gnus-article-outlook-repair-attribution
1985   "c" gnus-article-outlook-rearrange-citation
1986   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1987
1988 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1989   "a" gnus-article-hide
1990   "h" gnus-article-hide-headers
1991   "b" gnus-article-hide-boring-headers
1992   "s" gnus-article-hide-signature
1993   "c" gnus-article-hide-citation
1994   "C" gnus-article-hide-citation-in-followups
1995   "l" gnus-article-hide-list-identifiers
1996   "B" gnus-article-strip-banner
1997   "P" gnus-article-hide-pem
1998   "\C-c" gnus-article-hide-citation-maybe)
1999
2000 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2001   "a" gnus-article-highlight
2002   "h" gnus-article-highlight-headers
2003   "c" gnus-article-highlight-citation
2004   "s" gnus-article-highlight-signature)
2005
2006 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2007   "f" gnus-article-treat-fold-headers
2008   "u" gnus-article-treat-unfold-headers
2009   "n" gnus-article-treat-fold-newsgroups)
2010
2011 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2012   "x" gnus-article-display-x-face
2013   "d" gnus-article-display-face
2014   "s" gnus-treat-smiley
2015   "D" gnus-article-remove-images
2016   "f" gnus-treat-from-picon
2017   "m" gnus-treat-mail-picon
2018   "n" gnus-treat-newsgroups-picon)
2019
2020 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2021   "w" gnus-article-decode-mime-words
2022   "c" gnus-article-decode-charset
2023   "v" gnus-mime-view-all-parts
2024   "b" gnus-article-view-part)
2025
2026 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2027   "z" gnus-article-date-ut
2028   "u" gnus-article-date-ut
2029   "l" gnus-article-date-local
2030   "p" gnus-article-date-english
2031   "e" gnus-article-date-lapsed
2032   "o" gnus-article-date-original
2033   "i" gnus-article-date-iso8601
2034   "s" gnus-article-date-user)
2035
2036 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2037   "t" gnus-article-remove-trailing-blank-lines
2038   "l" gnus-article-strip-leading-blank-lines
2039   "m" gnus-article-strip-multiple-blank-lines
2040   "a" gnus-article-strip-blank-lines
2041   "A" gnus-article-strip-all-blank-lines
2042   "s" gnus-article-strip-leading-space
2043   "e" gnus-article-strip-trailing-space
2044   "w" gnus-article-remove-leading-whitespace)
2045
2046 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2047   "v" gnus-version
2048   "f" gnus-summary-fetch-faq
2049   "d" gnus-summary-describe-group
2050   "h" gnus-summary-describe-briefly
2051   "i" gnus-info-find-node
2052   "c" gnus-group-fetch-charter
2053   "C" gnus-group-fetch-control)
2054
2055 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2056   "e" gnus-summary-expire-articles
2057   "\M-\C-e" gnus-summary-expire-articles-now
2058   "\177" gnus-summary-delete-article
2059   [delete] gnus-summary-delete-article
2060   [backspace] gnus-summary-delete-article
2061   "m" gnus-summary-move-article
2062   "r" gnus-summary-respool-article
2063   "w" gnus-summary-edit-article
2064   "c" gnus-summary-copy-article
2065   "B" gnus-summary-crosspost-article
2066   "q" gnus-summary-respool-query
2067   "t" gnus-summary-respool-trace
2068   "i" gnus-summary-import-article
2069   "I" gnus-summary-create-article
2070   "p" gnus-summary-article-posted-p)
2071
2072 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2073   "o" gnus-summary-save-article
2074   "m" gnus-summary-save-article-mail
2075   "F" gnus-summary-write-article-file
2076   "r" gnus-summary-save-article-rmail
2077   "f" gnus-summary-save-article-file
2078   "b" gnus-summary-save-article-body-file
2079   "B" gnus-summary-write-article-body-file
2080   "h" gnus-summary-save-article-folder
2081   "v" gnus-summary-save-article-vm
2082   "p" gnus-summary-pipe-output
2083   "P" gnus-summary-muttprint
2084   "s" gnus-soup-add-article)
2085
2086 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2087   "b" gnus-summary-display-buttonized
2088   "m" gnus-summary-repair-multipart
2089   "v" gnus-article-view-part
2090   "o" gnus-article-save-part
2091   "O" gnus-article-save-part-and-strip
2092   "r" gnus-article-replace-part
2093   "d" gnus-article-delete-part
2094   "t" gnus-article-view-part-as-type
2095   "j" gnus-article-jump-to-part
2096   "c" gnus-article-copy-part
2097   "C" gnus-article-view-part-as-charset
2098   "e" gnus-article-view-part-externally
2099   "H" gnus-article-browse-html-article
2100   "E" gnus-article-encrypt-body
2101   "i" gnus-article-inline-part
2102   "|" gnus-article-pipe-part)
2103
2104 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2105   "p" gnus-summary-mark-as-processable
2106   "u" gnus-summary-unmark-as-processable
2107   "U" gnus-summary-unmark-all-processable
2108   "v" gnus-uu-mark-over
2109   "s" gnus-uu-mark-series
2110   "r" gnus-uu-mark-region
2111   "g" gnus-uu-unmark-region
2112   "R" gnus-uu-mark-by-regexp
2113   "G" gnus-uu-unmark-by-regexp
2114   "t" gnus-uu-mark-thread
2115   "T" gnus-uu-unmark-thread
2116   "a" gnus-uu-mark-all
2117   "b" gnus-uu-mark-buffer
2118   "S" gnus-uu-mark-sparse
2119   "k" gnus-summary-kill-process-mark
2120   "y" gnus-summary-yank-process-mark
2121   "w" gnus-summary-save-process-mark
2122   "i" gnus-uu-invert-processable)
2123
2124 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2125   ;;"x" gnus-uu-extract-any
2126   "m" gnus-summary-save-parts
2127   "u" gnus-uu-decode-uu
2128   "U" gnus-uu-decode-uu-and-save
2129   "s" gnus-uu-decode-unshar
2130   "S" gnus-uu-decode-unshar-and-save
2131   "o" gnus-uu-decode-save
2132   "O" gnus-uu-decode-save
2133   "b" gnus-uu-decode-binhex
2134   "B" gnus-uu-decode-binhex
2135   "p" gnus-uu-decode-postscript
2136   "P" gnus-uu-decode-postscript-and-save)
2137
2138 (gnus-define-keys
2139     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2140   "u" gnus-uu-decode-uu-view
2141   "U" gnus-uu-decode-uu-and-save-view
2142   "s" gnus-uu-decode-unshar-view
2143   "S" gnus-uu-decode-unshar-and-save-view
2144   "o" gnus-uu-decode-save-view
2145   "O" gnus-uu-decode-save-view
2146   "b" gnus-uu-decode-binhex-view
2147   "B" gnus-uu-decode-binhex-view
2148   "p" gnus-uu-decode-postscript-view
2149   "P" gnus-uu-decode-postscript-and-save-view)
2150
2151 (defvar gnus-article-post-menu nil)
2152
2153 (defconst gnus-summary-menu-maxlen 20)
2154
2155 (defun gnus-summary-menu-split (menu)
2156   ;; If we have lots of elements, divide them into groups of 20
2157   ;; and make a pane (or submenu) for each one.
2158   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2159       (let ((menu menu) sublists next
2160             (i 1))
2161         (while menu
2162           ;; Pull off the next gnus-summary-menu-maxlen elements
2163           ;; and make them the next element of sublist.
2164           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2165           (if next
2166               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2167                       nil))
2168           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2169                                              (aref (car (last menu)) 0)) menu)
2170                                sublists))
2171           (setq i (1+ i))
2172           (setq menu next))
2173         (nreverse sublists))
2174     ;; Few elements--put them all in one pane.
2175     menu))
2176
2177 (defun gnus-summary-make-menu-bar ()
2178   (gnus-turn-off-edit-menu 'summary)
2179
2180   (unless (boundp 'gnus-summary-misc-menu)
2181
2182     (easy-menu-define
2183       gnus-summary-kill-menu gnus-summary-mode-map ""
2184       (cons
2185        "Score"
2186        (nconc
2187         (list
2188          ["Customize" gnus-score-customize t])
2189         (gnus-make-score-map 'increase)
2190         (gnus-make-score-map 'lower)
2191         '(("Mark"
2192            ["Kill below" gnus-summary-kill-below t]
2193            ["Mark above" gnus-summary-mark-above t]
2194            ["Tick above" gnus-summary-tick-above t]
2195            ["Clear above" gnus-summary-clear-above t])
2196           ["Current score" gnus-summary-current-score t]
2197           ["Set score" gnus-summary-set-score t]
2198           ["Switch current score file..." gnus-score-change-score-file t]
2199           ["Set mark below..." gnus-score-set-mark-below t]
2200           ["Set expunge below..." gnus-score-set-expunge-below t]
2201           ["Edit current score file" gnus-score-edit-current-scores t]
2202           ["Edit score file" gnus-score-edit-file t]
2203           ["Trace score" gnus-score-find-trace t]
2204           ["Find words" gnus-score-find-favourite-words t]
2205           ["Rescore buffer" gnus-summary-rescore t]
2206           ["Increase score..." gnus-summary-increase-score t]
2207           ["Lower score..." gnus-summary-lower-score t]))))
2208
2209     ;; Define both the Article menu in the summary buffer and the
2210     ;; equivalent Commands menu in the article buffer here for
2211     ;; consistency.
2212     (let ((innards
2213            `(("Hide"
2214               ["All" gnus-article-hide t]
2215               ["Headers" gnus-article-hide-headers t]
2216               ["Signature" gnus-article-hide-signature t]
2217               ["Citation" gnus-article-hide-citation t]
2218               ["List identifiers" gnus-article-hide-list-identifiers t]
2219               ["Banner" gnus-article-strip-banner t]
2220               ["Boring headers" gnus-article-hide-boring-headers t])
2221              ("Highlight"
2222               ["All" gnus-article-highlight t]
2223               ["Headers" gnus-article-highlight-headers t]
2224               ["Signature" gnus-article-highlight-signature t]
2225               ["Citation" gnus-article-highlight-citation t])
2226              ("MIME"
2227               ["Words" gnus-article-decode-mime-words t]
2228               ["Charset" gnus-article-decode-charset t]
2229               ["QP" gnus-article-de-quoted-unreadable t]
2230               ["Base64" gnus-article-de-base64-unreadable t]
2231               ["View MIME buttons" gnus-summary-display-buttonized t]
2232               ["View all" gnus-mime-view-all-parts t]
2233               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2234               ["Encrypt body" gnus-article-encrypt-body
2235                :active (not (gnus-group-read-only-p))
2236                ,@(if (featurep 'xemacs) nil
2237                    '(:help "Encrypt the message body on disk"))]
2238               ["Extract all parts..." gnus-summary-save-parts t]
2239               ("Multipart"
2240                ["Repair multipart" gnus-summary-repair-multipart t]
2241                ["Pipe part..." gnus-article-pipe-part t]
2242                ["Inline part" gnus-article-inline-part t]
2243                ["View part as type..." gnus-article-view-part-as-type t]
2244                ["Encrypt body" gnus-article-encrypt-body
2245                 :active (not (gnus-group-read-only-p))
2246                ,@(if (featurep 'xemacs) nil
2247                    '(:help "Encrypt the message body on disk"))]
2248                ["View part externally" gnus-article-view-part-externally t]
2249                ["View HTML parts in browser" gnus-article-browse-html-article t]
2250                ["View part with charset..." gnus-article-view-part-as-charset t]
2251                ["Copy part" gnus-article-copy-part t]
2252                ["Save part..." gnus-article-save-part t]
2253                ["View part" gnus-article-view-part t]))
2254              ("Date"
2255               ["Local" gnus-article-date-local t]
2256               ["ISO8601" gnus-article-date-iso8601 t]
2257               ["UT" gnus-article-date-ut t]
2258               ["Original" gnus-article-date-original t]
2259               ["Lapsed" gnus-article-date-lapsed t]
2260               ["User-defined" gnus-article-date-user t])
2261              ("Display"
2262               ["Remove images" gnus-article-remove-images t]
2263               ["Toggle smiley" gnus-treat-smiley t]
2264               ["Show X-Face" gnus-article-display-x-face t]
2265               ["Show picons in From" gnus-treat-from-picon t]
2266               ["Show picons in mail headers" gnus-treat-mail-picon t]
2267               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2268               ("View as different encoding"
2269                ,@(gnus-summary-menu-split
2270                   (mapcar
2271                    (lambda (cs)
2272                      ;; Since easymenu under Emacs doesn't allow
2273                      ;; lambda forms for menu commands, we should
2274                      ;; provide intern'ed function symbols.
2275                      (let ((command (intern (format "\
2276 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2277                        (fset command
2278                              `(lambda ()
2279                                 (interactive)
2280                                 (let ((gnus-summary-show-article-charset-alist
2281                                        '((1 . ,cs))))
2282                                   (gnus-summary-show-article 1))))
2283                        `[,(symbol-name cs) ,command t]))
2284                    (sort (if (fboundp 'coding-system-list)
2285                              (coding-system-list)
2286                            (mapcar 'car mm-mime-mule-charset-alist))
2287                          'string<)))))
2288              ("Washing"
2289               ("Remove Blanks"
2290                ["Leading" gnus-article-strip-leading-blank-lines t]
2291                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2292                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2293                ["All of the above" gnus-article-strip-blank-lines t]
2294                ["All" gnus-article-strip-all-blank-lines t]
2295                ["Leading space" gnus-article-strip-leading-space t]
2296                ["Trailing space" gnus-article-strip-trailing-space t]
2297                ["Leading space in headers"
2298                 gnus-article-remove-leading-whitespace t])
2299               ["Overstrike" gnus-article-treat-overstrike t]
2300               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2301               ["Emphasis" gnus-article-emphasize t]
2302               ["Word wrap" gnus-article-fill-cited-article t]
2303               ["Fill long lines" gnus-article-fill-long-lines t]
2304               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2305               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2306               ["Remove CR" gnus-article-remove-cr t]
2307               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2308               ["Base64" gnus-article-de-base64-unreadable t]
2309               ["Rot 13" gnus-summary-caesar-message
2310                ,@(if (featurep 'xemacs) '(t)
2311                    '(:help "\"Caesar rotate\" article by 13"))]
2312               ["De-IDNA" gnus-summary-idna-message t]
2313               ["Morse decode" gnus-summary-morse-message t]
2314               ["Unix pipe..." gnus-summary-pipe-message t]
2315               ["Add buttons" gnus-article-add-buttons t]
2316               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2317               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2318               ["Verbose header" gnus-summary-verbose-headers t]
2319               ["Toggle header" gnus-summary-toggle-header t]
2320               ["Unfold headers" gnus-article-treat-unfold-headers t]
2321               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2322               ["Html" gnus-article-wash-html t]
2323               ["Unsplit URLs" gnus-article-unsplit-urls t]
2324               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2325               ["Decode HZ" gnus-article-decode-HZ t]
2326               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2327               ("(Outlook) Deuglify"
2328                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2329                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2330                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2331                ["Full (Outlook) deuglify"
2332                 gnus-article-outlook-deuglify-article t])
2333               )
2334              ("Output"
2335               ["Save in default format..." gnus-summary-save-article
2336                ,@(if (featurep 'xemacs) '(t)
2337                    '(:help "Save article using default method"))]
2338               ["Save in file..." gnus-summary-save-article-file
2339                ,@(if (featurep 'xemacs) '(t)
2340                    '(:help "Save article in file"))]
2341               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2342               ["Save in MH folder..." gnus-summary-save-article-folder t]
2343               ["Save in VM folder..." gnus-summary-save-article-vm t]
2344               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2345               ["Save body in file..." gnus-summary-save-article-body-file t]
2346               ["Pipe through a filter..." gnus-summary-pipe-output t]
2347               ["Add to SOUP packet" gnus-soup-add-article t]
2348               ["Print with Muttprint..." gnus-summary-muttprint t]
2349               ["Print" gnus-summary-print-article
2350                ,@(if (featurep 'xemacs) '(t)
2351                    '(:help "Generate and print a PostScript image"))])
2352              ("Copy, move,... (Backend)"
2353               ,@(if (featurep 'xemacs) nil
2354                   '(:help "Copying, moving, expiring articles..."))
2355               ["Respool article..." gnus-summary-respool-article t]
2356               ["Move article..." gnus-summary-move-article
2357                (gnus-check-backend-function
2358                 'request-move-article gnus-newsgroup-name)]
2359               ["Copy article..." gnus-summary-copy-article t]
2360               ["Crosspost article..." gnus-summary-crosspost-article
2361                (gnus-check-backend-function
2362                 'request-replace-article gnus-newsgroup-name)]
2363               ["Import file..." gnus-summary-import-article
2364                (gnus-check-backend-function
2365                 'request-accept-article gnus-newsgroup-name)]
2366               ["Create article..." gnus-summary-create-article
2367                (gnus-check-backend-function
2368                 'request-accept-article gnus-newsgroup-name)]
2369               ["Check if posted" gnus-summary-article-posted-p t]
2370               ["Edit article" gnus-summary-edit-article
2371                (not (gnus-group-read-only-p))]
2372               ["Delete article" gnus-summary-delete-article
2373                (gnus-check-backend-function
2374                 'request-expire-articles gnus-newsgroup-name)]
2375               ["Query respool" gnus-summary-respool-query t]
2376               ["Trace respool" gnus-summary-respool-trace t]
2377               ["Delete expirable articles" gnus-summary-expire-articles-now
2378                (gnus-check-backend-function
2379                 'request-expire-articles gnus-newsgroup-name)])
2380              ("Extract"
2381               ["Uudecode" gnus-uu-decode-uu
2382                ,@(if (featurep 'xemacs) '(t)
2383                    '(:help "Decode uuencoded article(s)"))]
2384               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2385               ["Unshar" gnus-uu-decode-unshar t]
2386               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2387               ["Save" gnus-uu-decode-save t]
2388               ["Binhex" gnus-uu-decode-binhex t]
2389               ["Postscript" gnus-uu-decode-postscript t]
2390               ["All MIME parts" gnus-summary-save-parts t])
2391              ("Cache"
2392               ["Enter article" gnus-cache-enter-article t]
2393               ["Remove article" gnus-cache-remove-article t])
2394              ["Translate" gnus-article-babel t]
2395              ["Select article buffer" gnus-summary-select-article-buffer t]
2396              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2397              ["Isearch article..." gnus-summary-isearch-article t]
2398              ["Beginning of the article" gnus-summary-beginning-of-article t]
2399              ["End of the article" gnus-summary-end-of-article t]
2400              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2401              ["Fetch referenced articles" gnus-summary-refer-references t]
2402              ["Fetch current thread" gnus-summary-refer-thread t]
2403              ["Fetch article with id..." gnus-summary-refer-article t]
2404              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2405              ["Redisplay" gnus-summary-show-article t]
2406              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2407       (easy-menu-define
2408         gnus-summary-article-menu gnus-summary-mode-map ""
2409         (cons "Article" innards))
2410
2411       (if (not (keymapp gnus-summary-article-menu))
2412           (easy-menu-define
2413             gnus-article-commands-menu gnus-article-mode-map ""
2414             (cons "Commands" innards))
2415         ;; in Emacs, don't share menu.
2416         (setq gnus-article-commands-menu
2417               (copy-keymap gnus-summary-article-menu))
2418         (define-key gnus-article-mode-map [menu-bar commands]
2419           (cons "Commands" gnus-article-commands-menu))))
2420
2421     (easy-menu-define
2422       gnus-summary-thread-menu gnus-summary-mode-map ""
2423       '("Threads"
2424         ["Find all messages in thread" gnus-summary-refer-thread t]
2425         ["Toggle threading" gnus-summary-toggle-threads t]
2426         ["Hide threads" gnus-summary-hide-all-threads t]
2427         ["Show threads" gnus-summary-show-all-threads t]
2428         ["Hide thread" gnus-summary-hide-thread t]
2429         ["Show thread" gnus-summary-show-thread t]
2430         ["Go to next thread" gnus-summary-next-thread t]
2431         ["Go to previous thread" gnus-summary-prev-thread t]
2432         ["Go down thread" gnus-summary-down-thread t]
2433         ["Go up thread" gnus-summary-up-thread t]
2434         ["Top of thread" gnus-summary-top-thread t]
2435         ["Mark thread as read" gnus-summary-kill-thread t]
2436         ["Lower thread score" gnus-summary-lower-thread t]
2437         ["Raise thread score" gnus-summary-raise-thread t]
2438         ["Rethread current" gnus-summary-rethread-current t]))
2439
2440     (easy-menu-define
2441       gnus-summary-post-menu gnus-summary-mode-map ""
2442       `("Post"
2443         ["Send a message (mail or news)" gnus-summary-post-news
2444          ,@(if (featurep 'xemacs) '(t)
2445              '(:help "Compose a new message (mail or news)"))]
2446         ["Followup" gnus-summary-followup
2447          ,@(if (featurep 'xemacs) '(t)
2448              '(:help "Post followup to this article"))]
2449         ["Followup and yank" gnus-summary-followup-with-original
2450          ,@(if (featurep 'xemacs) '(t)
2451              '(:help "Post followup to this article, quoting its contents"))]
2452         ["Supersede article" gnus-summary-supersede-article t]
2453         ["Cancel article" gnus-summary-cancel-article
2454          ,@(if (featurep 'xemacs) '(t)
2455              '(:help "Cancel an article you posted"))]
2456         ["Reply" gnus-summary-reply t]
2457         ["Reply and yank" gnus-summary-reply-with-original t]
2458         ["Wide reply" gnus-summary-wide-reply t]
2459         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2460          ,@(if (featurep 'xemacs) '(t)
2461              '(:help "Mail a reply, quoting this article"))]
2462         ["Very wide reply" gnus-summary-very-wide-reply t]
2463         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2464          ,@(if (featurep 'xemacs) '(t)
2465              '(:help "Mail a very wide reply, quoting this article"))]
2466         ["Mail forward" gnus-summary-mail-forward t]
2467         ["Post forward" gnus-summary-post-forward t]
2468         ["Digest and mail" gnus-uu-digest-mail-forward t]
2469         ["Digest and post" gnus-uu-digest-post-forward t]
2470         ["Resend message" gnus-summary-resend-message t]
2471         ["Resend message edit" gnus-summary-resend-message-edit t]
2472         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2473         ["Send a mail" gnus-summary-mail-other-window t]
2474         ["Create a local message" gnus-summary-news-other-window t]
2475         ["Uuencode and post" gnus-uu-post-news
2476          ,@(if (featurep 'xemacs) '(t)
2477              '(:help "Post a uuencoded article"))]
2478         ["Followup via news" gnus-summary-followup-to-mail t]
2479         ["Followup via news and yank"
2480          gnus-summary-followup-to-mail-with-original t]
2481         ;;("Draft"
2482         ;;["Send" gnus-summary-send-draft t]
2483         ;;["Send bounced" gnus-resend-bounced-mail t])
2484         ))
2485
2486     (cond
2487      ((not (keymapp gnus-summary-post-menu))
2488       (setq gnus-article-post-menu gnus-summary-post-menu))
2489      ((not gnus-article-post-menu)
2490       ;; Don't share post menu.
2491       (setq gnus-article-post-menu
2492             (copy-keymap gnus-summary-post-menu))))
2493     (define-key gnus-article-mode-map [menu-bar post]
2494       (cons "Post" gnus-article-post-menu))
2495
2496     (easy-menu-define
2497       gnus-summary-misc-menu gnus-summary-mode-map ""
2498       `("Gnus"
2499         ("Mark Read"
2500          ["Mark as read" gnus-summary-mark-as-read-forward t]
2501          ["Mark same subject and select"
2502           gnus-summary-kill-same-subject-and-select t]
2503          ["Mark same subject" gnus-summary-kill-same-subject t]
2504          ["Catchup" gnus-summary-catchup
2505           ,@(if (featurep 'xemacs) '(t)
2506               '(:help "Mark unread articles in this group as read"))]
2507          ["Catchup all" gnus-summary-catchup-all t]
2508          ["Catchup to here" gnus-summary-catchup-to-here t]
2509          ["Catchup from here" gnus-summary-catchup-from-here t]
2510          ["Catchup region" gnus-summary-mark-region-as-read
2511           (gnus-mark-active-p)]
2512          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2513         ("Mark Various"
2514          ["Tick" gnus-summary-tick-article-forward t]
2515          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2516          ["Remove marks" gnus-summary-clear-mark-forward t]
2517          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2518          ["Set bookmark" gnus-summary-set-bookmark t]
2519          ["Remove bookmark" gnus-summary-remove-bookmark t])
2520         ("Limit to"
2521          ["Marks..." gnus-summary-limit-to-marks t]
2522          ["Subject..." gnus-summary-limit-to-subject t]
2523          ["Author..." gnus-summary-limit-to-author t]
2524          ["Recipient..." gnus-summary-limit-to-recipient t]
2525          ["Age..." gnus-summary-limit-to-age t]
2526          ["Extra..." gnus-summary-limit-to-extra t]
2527          ["Score..." gnus-summary-limit-to-score t]
2528          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2529          ["Unread" gnus-summary-limit-to-unread t]
2530          ["Unseen" gnus-summary-limit-to-unseen t]
2531          ["Replied" gnus-summary-limit-to-replied t]
2532          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2533          ["Next articles" gnus-summary-limit-to-articles t]
2534          ["Pop limit" gnus-summary-pop-limit t]
2535          ["Show dormant" gnus-summary-limit-include-dormant t]
2536          ["Hide childless dormant"
2537           gnus-summary-limit-exclude-childless-dormant t]
2538          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2539          ["Hide marked" gnus-summary-limit-exclude-marks t]
2540          ["Show expunged" gnus-summary-limit-include-expunged t])
2541         ("Process Mark"
2542          ["Set mark" gnus-summary-mark-as-processable t]
2543          ["Remove mark" gnus-summary-unmark-as-processable t]
2544          ["Remove all marks" gnus-summary-unmark-all-processable t]
2545          ["Invert marks" gnus-uu-invert-processable t]
2546          ["Mark above" gnus-uu-mark-over t]
2547          ["Mark series" gnus-uu-mark-series t]
2548          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2549          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2550          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2551          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2552          ["Mark all" gnus-uu-mark-all t]
2553          ["Mark buffer" gnus-uu-mark-buffer t]
2554          ["Mark sparse" gnus-uu-mark-sparse t]
2555          ["Mark thread" gnus-uu-mark-thread t]
2556          ["Unmark thread" gnus-uu-unmark-thread t]
2557          ("Process Mark Sets"
2558           ["Kill" gnus-summary-kill-process-mark t]
2559           ["Yank" gnus-summary-yank-process-mark
2560            gnus-newsgroup-process-stack]
2561           ["Save" gnus-summary-save-process-mark t]
2562           ["Run command on marked..." gnus-summary-universal-argument t]))
2563         ("Scroll article"
2564          ["Page forward" gnus-summary-next-page
2565           ,@(if (featurep 'xemacs) '(t)
2566               '(:help "Show next page of article"))]
2567          ["Page backward" gnus-summary-prev-page
2568           ,@(if (featurep 'xemacs) '(t)
2569               '(:help "Show previous page of article"))]
2570          ["Line forward" gnus-summary-scroll-up t])
2571         ("Move"
2572          ["Next unread article" gnus-summary-next-unread-article t]
2573          ["Previous unread article" gnus-summary-prev-unread-article t]
2574          ["Next article" gnus-summary-next-article t]
2575          ["Previous article" gnus-summary-prev-article t]
2576          ["Next unread subject" gnus-summary-next-unread-subject t]
2577          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2578          ["Next article same subject" gnus-summary-next-same-subject t]
2579          ["Previous article same subject" gnus-summary-prev-same-subject t]
2580          ["First unread article" gnus-summary-first-unread-article t]
2581          ["Best unread article" gnus-summary-best-unread-article t]
2582          ["Go to subject number..." gnus-summary-goto-subject t]
2583          ["Go to article number..." gnus-summary-goto-article t]
2584          ["Go to the last article" gnus-summary-goto-last-article t]
2585          ["Pop article off history" gnus-summary-pop-article t])
2586         ("Sort"
2587          ["Sort by number" gnus-summary-sort-by-number t]
2588          ["Sort by author" gnus-summary-sort-by-author t]
2589          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2590          ["Sort by subject" gnus-summary-sort-by-subject t]
2591          ["Sort by date" gnus-summary-sort-by-date t]
2592          ["Sort by score" gnus-summary-sort-by-score t]
2593          ["Sort by lines" gnus-summary-sort-by-lines t]
2594          ["Sort by characters" gnus-summary-sort-by-chars t]
2595          ["Randomize" gnus-summary-sort-by-random t]
2596          ["Original sort" gnus-summary-sort-by-original t])
2597         ("Help"
2598          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2599          ["Describe group" gnus-summary-describe-group t]
2600          ["Fetch charter" gnus-group-fetch-charter
2601           ,@(if (featurep 'xemacs) nil
2602               '(:help "Display the charter of the current group"))]
2603          ["Fetch control message" gnus-group-fetch-control
2604           ,@(if (featurep 'xemacs) nil
2605               '(:help "Display the archived control message for the current group"))]
2606          ["Read manual" gnus-info-find-node t])
2607         ("Modes"
2608          ["Pick and read" gnus-pick-mode t]
2609          ["Binary" gnus-binary-mode t])
2610         ("Regeneration"
2611          ["Regenerate" gnus-summary-prepare t]
2612          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2613          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2614          ["Toggle threading" gnus-summary-toggle-threads t])
2615         ["See old articles" gnus-summary-insert-old-articles t]
2616         ["See new articles" gnus-summary-insert-new-articles t]
2617         ["Filter articles..." gnus-summary-execute-command t]
2618         ["Run command on articles..." gnus-summary-universal-argument t]
2619         ["Search articles forward..." gnus-summary-search-article-forward t]
2620         ["Search articles backward..." gnus-summary-search-article-backward t]
2621         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2622         ["Expand window" gnus-summary-expand-window t]
2623         ["Expire expirable articles" gnus-summary-expire-articles
2624          (gnus-check-backend-function
2625           'request-expire-articles gnus-newsgroup-name)]
2626         ["Edit local kill file" gnus-summary-edit-local-kill t]
2627         ["Edit main kill file" gnus-summary-edit-global-kill t]
2628         ["Edit group parameters" gnus-summary-edit-parameters t]
2629         ["Customize group parameters" gnus-summary-customize-parameters t]
2630         ["Send a bug report" gnus-bug t]
2631         ("Exit"
2632          ["Catchup and exit" gnus-summary-catchup-and-exit
2633           ,@(if (featurep 'xemacs) '(t)
2634               '(:help "Mark unread articles in this group as read, then exit"))]
2635          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2636          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2637          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2638          ["Exit group" gnus-summary-exit
2639           ,@(if (featurep 'xemacs) '(t)
2640               '(:help "Exit current group, return to group selection mode"))]
2641          ["Exit group without updating" gnus-summary-exit-no-update t]
2642          ["Exit and goto next group" gnus-summary-next-group t]
2643          ["Exit and goto prev group" gnus-summary-prev-group t]
2644          ["Reselect group" gnus-summary-reselect-current-group t]
2645          ["Rescan group" gnus-summary-rescan-group t]
2646          ["Update dribble" gnus-summary-save-newsrc t])))
2647
2648     (gnus-run-hooks 'gnus-summary-menu-hook)))
2649
2650 (defvar gnus-summary-tool-bar-map nil)
2651
2652 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2653 ;; affect _new_ message buffers.  We might add a function that walks thru all
2654 ;; summary-mode buffers and force the update.
2655 (defun gnus-summary-tool-bar-update (&optional symbol value)
2656   "Update summary mode toolbar.
2657 Setter function for custom variables."
2658   (setq-default gnus-summary-tool-bar-map nil)
2659   (when symbol
2660     ;; When used as ":set" function:
2661     (set-default symbol value))
2662   (when (gnus-buffer-live-p gnus-summary-buffer)
2663     (with-current-buffer gnus-summary-buffer
2664       (gnus-summary-make-tool-bar))))
2665
2666 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2667                                      'gnus-summary-tool-bar-gnome
2668                                    'gnus-summary-tool-bar-retro)
2669   "Specifies the Gnus summary tool bar.
2670
2671 It can be either a list or a symbol refering to a list.  See
2672 `gmm-tool-bar-from-list' for the format of the list.  The
2673 default key map is `gnus-summary-mode-map'.
2674
2675 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2676 `gnus-summary-tool-bar-retro'."
2677   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2678                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2679                  (repeat :tag "User defined list" gmm-tool-bar-item)
2680                  (symbol))
2681   :version "23.0" ;; No Gnus
2682   :initialize 'custom-initialize-default
2683   :set 'gnus-summary-tool-bar-update
2684   :group 'gnus-summary)
2685
2686 (defcustom gnus-summary-tool-bar-gnome
2687   '((gnus-summary-post-news "mail/compose" nil)
2688     (gnus-summary-insert-new-articles "mail/inbox" nil
2689                                       :visible (or (not gnus-agent)
2690                                                    gnus-plugged))
2691     (gnus-summary-reply-with-original "mail/reply")
2692     (gnus-summary-reply "mail/reply" nil :visible nil)
2693     (gnus-summary-followup-with-original "mail/reply-all")
2694     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2695     (gnus-summary-mail-forward "mail/forward")
2696     (gnus-summary-save-article "mail/save")
2697     (gnus-summary-search-article-forward "search" nil :visible nil)
2698     (gnus-summary-print-article "print")
2699     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2700     ;; Some new commands that may need more suitable icons:
2701     (gnus-summary-save-newsrc "save" nil :visible nil)
2702     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2703     (gnus-summary-prev-article "left-arrow")
2704     (gnus-summary-next-article "right-arrow")
2705     (gnus-summary-next-page "next-page")
2706     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2707     ;;
2708     ;; Maybe some sort-by-... could be added:
2709     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2710     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2711     (gnus-summary-mark-as-expirable
2712      "delete" nil
2713      :visible (gnus-check-backend-function 'request-expire-articles
2714                                            gnus-newsgroup-name))
2715     (gnus-summary-mark-as-spam
2716      "mail/spam" t
2717      :visible (and (fboundp 'spam-group-ham-contents-p)
2718                    (spam-group-ham-contents-p gnus-newsgroup-name))
2719      :help "Mark as spam")
2720     (gnus-summary-mark-as-read-forward
2721      "mail/not-spam" nil
2722      :visible (and (fboundp 'spam-group-spam-contents-p)
2723                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2724     ;;
2725     (gnus-summary-exit "exit")
2726     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2727     (gnus-info-find-node "help"))
2728   "List of functions for the summary tool bar (GNOME style).
2729
2730 See `gmm-tool-bar-from-list' for the format of the list."
2731   :type '(repeat gmm-tool-bar-item)
2732   :version "23.0" ;; No Gnus
2733   :initialize 'custom-initialize-default
2734   :set 'gnus-summary-tool-bar-update
2735   :group 'gnus-summary)
2736
2737 (defcustom gnus-summary-tool-bar-retro
2738   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2739     (gnus-summary-next-unread-article "gnus/next-ur")
2740     (gnus-summary-post-news "gnus/post")
2741     (gnus-summary-followup-with-original "gnus/fuwo")
2742     (gnus-summary-followup "gnus/followup")
2743     (gnus-summary-reply-with-original "gnus/reply-wo")
2744     (gnus-summary-reply "gnus/reply")
2745     (gnus-summary-caesar-message "gnus/rot13")
2746     (gnus-uu-decode-uu "gnus/uu-decode")
2747     (gnus-summary-save-article-file "gnus/save-aif")
2748     (gnus-summary-save-article "gnus/save-art")
2749     (gnus-uu-post-news "gnus/uu-post")
2750     (gnus-summary-catchup "gnus/catchup")
2751     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2752     (gnus-summary-exit "gnus/exit-summ")
2753     ;; Some new command that may need more suitable icons:
2754     (gnus-summary-print-article "gnus/print" nil :visible nil)
2755     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2756     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2757     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2758     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2759     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2760     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2761     ;;
2762     (gnus-info-find-node "gnus/help" nil :visible nil))
2763   "List of functions for the summary tool bar (retro look).
2764
2765 See `gmm-tool-bar-from-list' for the format of the list."
2766   :type '(repeat gmm-tool-bar-item)
2767   :version "23.0" ;; No Gnus
2768   :initialize 'custom-initialize-default
2769   :set 'gnus-summary-tool-bar-update
2770   :group 'gnus-summary)
2771
2772 (defcustom gnus-summary-tool-bar-zap-list t
2773   "List of icon items from the global tool bar.
2774 These items are not displayed in the Gnus summary mode tool bar.
2775
2776 See `gmm-tool-bar-from-list' for the format of the list."
2777   :type 'gmm-tool-bar-zap-list
2778   :version "23.0" ;; No Gnus
2779   :initialize 'custom-initialize-default
2780   :set 'gnus-summary-tool-bar-update
2781   :group 'gnus-summary)
2782
2783 (defvar image-load-path)
2784
2785 (defun gnus-summary-make-tool-bar (&optional force)
2786   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2787 When FORCE, rebuild the tool bar."
2788   (when (and (not (featurep 'xemacs))
2789              (boundp 'tool-bar-mode)
2790              tool-bar-mode
2791              (or (not gnus-summary-tool-bar-map) force))
2792     (let* ((load-path
2793             (gmm-image-load-path-for-library "gnus"
2794                                              "mail/save.xpm"
2795                                              nil t))
2796            (image-load-path (cons (car load-path)
2797                                   (when (boundp 'image-load-path)
2798                                     image-load-path)))
2799            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2800                                         gnus-summary-tool-bar-zap-list
2801                                         'gnus-summary-mode-map)))
2802       (when map
2803         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2804         ;; uses it's value.
2805         (setq gnus-summary-tool-bar-map map))))
2806   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2807
2808 (defun gnus-score-set-default (var value)
2809   "A version of set that updates the GNU Emacs menu-bar."
2810   (set var value)
2811   ;; It is the message that forces the active status to be updated.
2812   (message ""))
2813
2814 (defun gnus-make-score-map (type)
2815   "Make a summary score map of type TYPE."
2816   (if t
2817       nil
2818     (let ((headers '(("author" "from" string)
2819                      ("subject" "subject" string)
2820                      ("article body" "body" string)
2821                      ("article head" "head" string)
2822                      ("xref" "xref" string)
2823                      ("extra header" "extra" string)
2824                      ("lines" "lines" number)
2825                      ("followups to author" "followup" string)))
2826           (types '((number ("less than" <)
2827                            ("greater than" >)
2828                            ("equal" =))
2829                    (string ("substring" s)
2830                            ("exact string" e)
2831                            ("fuzzy string" f)
2832                            ("regexp" r))))
2833           (perms '(("temporary" (current-time-string))
2834                    ("permanent" nil)
2835                    ("immediate" now)))
2836           header)
2837       (list
2838        (apply
2839         'nconc
2840         (list
2841          (if (eq type 'lower)
2842              "Lower score"
2843            "Increase score"))
2844         (let (outh)
2845           (while headers
2846             (setq header (car headers))
2847             (setq outh
2848                   (cons
2849                    (apply
2850                     'nconc
2851                     (list (car header))
2852                     (let ((ts (cdr (assoc (nth 2 header) types)))
2853                           outt)
2854                       (while ts
2855                         (setq outt
2856                               (cons
2857                                (apply
2858                                 'nconc
2859                                 (list (caar ts))
2860                                 (let ((ps perms)
2861                                       outp)
2862                                   (while ps
2863                                     (setq outp
2864                                           (cons
2865                                            (vector
2866                                             (caar ps)
2867                                             (list
2868                                              'gnus-summary-score-entry
2869                                              (nth 1 header)
2870                                              (if (or (string= (nth 1 header)
2871                                                               "head")
2872                                                      (string= (nth 1 header)
2873                                                               "body"))
2874                                                  ""
2875                                                (list 'gnus-summary-header
2876                                                      (nth 1 header)))
2877                                              (list 'quote (nth 1 (car ts)))
2878                                              (list 'gnus-score-delta-default
2879                                                    nil)
2880                                              (nth 1 (car ps))
2881                                              t)
2882                                             t)
2883                                            outp))
2884                                     (setq ps (cdr ps)))
2885                                   (list (nreverse outp))))
2886                                outt))
2887                         (setq ts (cdr ts)))
2888                       (list (nreverse outt))))
2889                    outh))
2890             (setq headers (cdr headers)))
2891           (list (nreverse outh))))))))
2892
2893 \f
2894
2895 (defun gnus-summary-mode (&optional group)
2896   "Major mode for reading articles.
2897
2898 All normal editing commands are switched off.
2899 \\<gnus-summary-mode-map>
2900 Each line in this buffer represents one article.  To read an
2901 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2902 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2903 respectively.
2904
2905 You can also post articles and send mail from this buffer.  To
2906 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2907 of an article, type `\\[gnus-summary-reply]'.
2908
2909 There are approx. one gazillion commands you can execute in this
2910 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2911
2912 The following commands are available:
2913
2914 \\{gnus-summary-mode-map}"
2915   (interactive)
2916   (kill-all-local-variables)
2917   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2918     (gnus-summary-make-local-variables))
2919   (gnus-summary-make-local-variables)
2920   (setq gnus-newsgroup-name group)
2921   (when (gnus-visual-p 'summary-menu 'menu)
2922     (gnus-summary-make-menu-bar)
2923     (gnus-summary-make-tool-bar))
2924   (gnus-make-thread-indent-array)
2925   (gnus-simplify-mode-line)
2926   (setq major-mode 'gnus-summary-mode)
2927   (setq mode-name "Summary")
2928   (make-local-variable 'minor-mode-alist)
2929   (use-local-map gnus-summary-mode-map)
2930   (buffer-disable-undo)
2931   (setq buffer-read-only t              ;Disable modification
2932         show-trailing-whitespace nil)
2933   (setq truncate-lines t)
2934   (setq selective-display t)
2935   (setq selective-display-ellipses t)   ;Display `...'
2936   (gnus-summary-set-display-table)
2937   (gnus-set-default-directory)
2938   (make-local-variable 'gnus-summary-line-format)
2939   (make-local-variable 'gnus-summary-line-format-spec)
2940   (make-local-variable 'gnus-summary-dummy-line-format)
2941   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2942   (make-local-variable 'gnus-summary-mark-positions)
2943   (gnus-make-local-hook 'pre-command-hook)
2944   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2945   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2946   (turn-on-gnus-mailing-list-mode)
2947   (mm-enable-multibyte)
2948   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2949   (gnus-update-summary-mark-positions))
2950
2951 (defun gnus-summary-make-local-variables ()
2952   "Make all the local summary buffer variables."
2953   (let (global)
2954     (dolist (local gnus-summary-local-variables)
2955       (if (consp local)
2956           (progn
2957             (if (eq (cdr local) 'global)
2958                 ;; Copy the global value of the variable.
2959                 (setq global (symbol-value (car local)))
2960               ;; Use the value from the list.
2961               (setq global (eval (cdr local))))
2962             (set (make-local-variable (car local)) global))
2963         ;; Simple nil-valued local variable.
2964         (set (make-local-variable local) nil)))))
2965
2966 (defun gnus-summary-clear-local-variables ()
2967   (let ((locals gnus-summary-local-variables))
2968     (while locals
2969       (if (consp (car locals))
2970           (and (symbolp (caar locals))
2971                (set (caar locals) nil))
2972         (and (symbolp (car locals))
2973              (set (car locals) nil)))
2974       (setq locals (cdr locals)))))
2975
2976 ;; Summary data functions.
2977
2978 (defmacro gnus-data-number (data)
2979   `(car ,data))
2980
2981 (defmacro gnus-data-set-number (data number)
2982   `(setcar ,data ,number))
2983
2984 (defmacro gnus-data-mark (data)
2985   `(nth 1 ,data))
2986
2987 (defmacro gnus-data-set-mark (data mark)
2988   `(setcar (nthcdr 1 ,data) ,mark))
2989
2990 (defmacro gnus-data-pos (data)
2991   `(nth 2 ,data))
2992
2993 (defmacro gnus-data-set-pos (data pos)
2994   `(setcar (nthcdr 2 ,data) ,pos))
2995
2996 (defmacro gnus-data-header (data)
2997   `(nth 3 ,data))
2998
2999 (defmacro gnus-data-set-header (data header)
3000   `(setf (nth 3 ,data) ,header))
3001
3002 (defmacro gnus-data-level (data)
3003   `(nth 4 ,data))
3004
3005 (defmacro gnus-data-unread-p (data)
3006   `(= (nth 1 ,data) gnus-unread-mark))
3007
3008 (defmacro gnus-data-read-p (data)
3009   `(/= (nth 1 ,data) gnus-unread-mark))
3010
3011 (defmacro gnus-data-pseudo-p (data)
3012   `(consp (nth 3 ,data)))
3013
3014 (defmacro gnus-data-find (number)
3015   `(assq ,number gnus-newsgroup-data))
3016
3017 (defmacro gnus-data-find-list (number &optional data)
3018   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3019      (memq (assq ,number bdata)
3020            bdata)))
3021
3022 (defmacro gnus-data-make (number mark pos header level)
3023   `(list ,number ,mark ,pos ,header ,level))
3024
3025 (defun gnus-data-enter (after-article number mark pos header level offset)
3026   (let ((data (gnus-data-find-list after-article)))
3027     (unless data
3028       (error "No such article: %d" after-article))
3029     (setcdr data (cons (gnus-data-make number mark pos header level)
3030                        (cdr data)))
3031     (setq gnus-newsgroup-data-reverse nil)
3032     (gnus-data-update-list (cddr data) offset)))
3033
3034 (defun gnus-data-enter-list (after-article list &optional offset)
3035   (when list
3036     (let ((data (and after-article (gnus-data-find-list after-article)))
3037           (ilist list))
3038       (if (not (or data
3039                    after-article))
3040           (let ((odata gnus-newsgroup-data))
3041             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3042             (when offset
3043               (gnus-data-update-list odata offset)))
3044         ;; Find the last element in the list to be spliced into the main
3045         ;; list.
3046         (setq list (last list))
3047         (if (not data)
3048             (progn
3049               (setcdr list gnus-newsgroup-data)
3050               (setq gnus-newsgroup-data ilist)
3051               (when offset
3052                 (gnus-data-update-list (cdr list) offset)))
3053           (setcdr list (cdr data))
3054           (setcdr data ilist)
3055           (when offset
3056             (gnus-data-update-list (cdr list) offset))))
3057       (setq gnus-newsgroup-data-reverse nil))))
3058
3059 (defun gnus-data-remove (article &optional offset)
3060   (let ((data gnus-newsgroup-data))
3061     (if (= (gnus-data-number (car data)) article)
3062         (progn
3063           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3064                 gnus-newsgroup-data-reverse nil)
3065           (when offset
3066             (gnus-data-update-list gnus-newsgroup-data offset)))
3067       (while (cdr data)
3068         (when (= (gnus-data-number (cadr data)) article)
3069           (setcdr data (cddr data))
3070           (when offset
3071             (gnus-data-update-list (cdr data) offset))
3072           (setq data nil
3073                 gnus-newsgroup-data-reverse nil))
3074         (setq data (cdr data))))))
3075
3076 (defmacro gnus-data-list (backward)
3077   `(if ,backward
3078        (or gnus-newsgroup-data-reverse
3079            (setq gnus-newsgroup-data-reverse
3080                  (reverse gnus-newsgroup-data)))
3081      gnus-newsgroup-data))
3082
3083 (defun gnus-data-update-list (data offset)
3084   "Add OFFSET to the POS of all data entries in DATA."
3085   (setq gnus-newsgroup-data-reverse nil)
3086   (while data
3087     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3088     (setq data (cdr data))))
3089
3090 (defun gnus-summary-article-pseudo-p (article)
3091   "Say whether this article is a pseudo article or not."
3092   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3093
3094 (defmacro gnus-summary-article-sparse-p (article)
3095   "Say whether this article is a sparse article or not."
3096   `(memq ,article gnus-newsgroup-sparse))
3097
3098 (defmacro gnus-summary-article-ancient-p (article)
3099   "Say whether this article is a sparse article or not."
3100   `(memq ,article gnus-newsgroup-ancient))
3101
3102 (defun gnus-article-parent-p (number)
3103   "Say whether this article is a parent or not."
3104   (let ((data (gnus-data-find-list number)))
3105     (and (cdr data)              ; There has to be an article after...
3106          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3107             (gnus-data-level (nth 1 data))))))
3108
3109 (defun gnus-article-children (number)
3110   "Return a list of all children to NUMBER."
3111   (let* ((data (gnus-data-find-list number))
3112          (level (gnus-data-level (car data)))
3113          children)
3114     (setq data (cdr data))
3115     (while (and data
3116                 (= (gnus-data-level (car data)) (1+ level)))
3117       (push (gnus-data-number (car data)) children)
3118       (setq data (cdr data)))
3119     children))
3120
3121 (defmacro gnus-summary-skip-intangible ()
3122   "If the current article is intangible, then jump to a different article."
3123   '(let ((to (get-text-property (point) 'gnus-intangible)))
3124      (and to (gnus-summary-goto-subject to))))
3125
3126 (defmacro gnus-summary-article-intangible-p ()
3127   "Say whether this article is intangible or not."
3128   '(get-text-property (point) 'gnus-intangible))
3129
3130 (defun gnus-article-read-p (article)
3131   "Say whether ARTICLE is read or not."
3132   (not (or (memq article gnus-newsgroup-marked)
3133            (memq article gnus-newsgroup-spam-marked)
3134            (memq article gnus-newsgroup-unreads)
3135            (memq article gnus-newsgroup-unselected)
3136            (memq article gnus-newsgroup-dormant))))
3137
3138 ;; Some summary mode macros.
3139
3140 (defmacro gnus-summary-article-number ()
3141   "The article number of the article on the current line.
3142 If there isn't an article number here, then we return the current
3143 article number."
3144   '(progn
3145      (gnus-summary-skip-intangible)
3146      (or (get-text-property (point) 'gnus-number)
3147          (gnus-summary-last-subject))))
3148
3149 (defmacro gnus-summary-article-header (&optional number)
3150   "Return the header of article NUMBER."
3151   `(gnus-data-header (gnus-data-find
3152                       ,(or number '(gnus-summary-article-number)))))
3153
3154 (defmacro gnus-summary-thread-level (&optional number)
3155   "Return the level of thread that starts with article NUMBER."
3156   `(if (and (eq gnus-summary-make-false-root 'dummy)
3157             (get-text-property (point) 'gnus-intangible))
3158        0
3159      (gnus-data-level (gnus-data-find
3160                        ,(or number '(gnus-summary-article-number))))))
3161
3162 (defmacro gnus-summary-article-mark (&optional number)
3163   "Return the mark of article NUMBER."
3164   `(gnus-data-mark (gnus-data-find
3165                     ,(or number '(gnus-summary-article-number)))))
3166
3167 (defmacro gnus-summary-article-pos (&optional number)
3168   "Return the position of the line of article NUMBER."
3169   `(gnus-data-pos (gnus-data-find
3170                    ,(or number '(gnus-summary-article-number)))))
3171
3172 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3173 (defmacro gnus-summary-article-subject (&optional number)
3174   "Return current subject string or nil if nothing."
3175   `(let ((headers
3176           ,(if number
3177                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3178              '(gnus-data-header (assq (gnus-summary-article-number)
3179                                       gnus-newsgroup-data)))))
3180      (and headers
3181           (vectorp headers)
3182           (mail-header-subject headers))))
3183
3184 (defmacro gnus-summary-article-score (&optional number)
3185   "Return current article score."
3186   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3187                   gnus-newsgroup-scored))
3188        gnus-summary-default-score 0))
3189
3190 (defun gnus-summary-article-children (&optional number)
3191   "Return a list of article numbers that are children of article NUMBER."
3192   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3193          (level (gnus-data-level (car data)))
3194          l children)
3195     (while (and (setq data (cdr data))
3196                 (> (setq l (gnus-data-level (car data))) level))
3197       (and (= (1+ level) l)
3198            (push (gnus-data-number (car data))
3199                  children)))
3200     (nreverse children)))
3201
3202 (defun gnus-summary-article-parent (&optional number)
3203   "Return the article number of the parent of article NUMBER."
3204   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3205                                     (gnus-data-list t)))
3206          (level (gnus-data-level (car data))))
3207     (if (zerop level)
3208         ()                              ; This is a root.
3209       ;; We search until we find an article with a level less than
3210       ;; this one.  That function has to be the parent.
3211       (while (and (setq data (cdr data))
3212                   (not (< (gnus-data-level (car data)) level))))
3213       (and data (gnus-data-number (car data))))))
3214
3215 (defun gnus-unread-mark-p (mark)
3216   "Say whether MARK is the unread mark."
3217   (= mark gnus-unread-mark))
3218
3219 (defun gnus-read-mark-p (mark)
3220   "Say whether MARK is one of the marks that mark as read.
3221 This is all marks except unread, ticked, dormant, and expirable."
3222   (not (or (= mark gnus-unread-mark)
3223            (= mark gnus-ticked-mark)
3224            (= mark gnus-spam-mark)
3225            (= mark gnus-dormant-mark)
3226            (= mark gnus-expirable-mark))))
3227
3228 (defmacro gnus-article-mark (number)
3229   "Return the MARK of article NUMBER.
3230 This macro should only be used when computing the mark the \"first\"
3231 time; i.e., when generating the summary lines.  After that,
3232 `gnus-summary-article-mark' should be used to examine the
3233 marks of articles."
3234   `(cond
3235     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3236     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3237     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3238     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3239     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3240     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3241     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3242     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3243            gnus-ancient-mark))))
3244
3245 ;; Saving hidden threads.
3246
3247 (defmacro gnus-save-hidden-threads (&rest forms)
3248   "Save hidden threads, eval FORMS, and restore the hidden threads."
3249   (let ((config (make-symbol "config")))
3250     `(let ((,config (gnus-hidden-threads-configuration)))
3251        (unwind-protect
3252            (save-excursion
3253              ,@forms)
3254          (gnus-restore-hidden-threads-configuration ,config)))))
3255 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3256 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3257
3258 (defun gnus-data-compute-positions ()
3259   "Compute the positions of all articles."
3260   (setq gnus-newsgroup-data-reverse nil)
3261   (let ((data gnus-newsgroup-data))
3262     (save-excursion
3263       (gnus-save-hidden-threads
3264         (gnus-summary-show-all-threads)
3265         (goto-char (point-min))
3266         (while data
3267           (while (get-text-property (point) 'gnus-intangible)
3268             (forward-line 1))
3269           (gnus-data-set-pos (car data) (+ (point) 3))
3270           (setq data (cdr data))
3271           (forward-line 1))))))
3272
3273 (defun gnus-hidden-threads-configuration ()
3274   "Return the current hidden threads configuration."
3275   (save-excursion
3276     (let (config)
3277       (goto-char (point-min))
3278       (while (search-forward "\r" nil t)
3279         (push (1- (point)) config))
3280       config)))
3281
3282 (defun gnus-restore-hidden-threads-configuration (config)
3283   "Restore hidden threads configuration from CONFIG."
3284   (save-excursion
3285     (let (point buffer-read-only)
3286       (while (setq point (pop config))
3287         (when (and (< point (point-max))
3288                    (goto-char point)
3289                    (eq (char-after) ?\n))
3290           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3291
3292 ;; Various summary mode internalish functions.
3293
3294 (defun gnus-mouse-pick-article (e)
3295   (interactive "e")
3296   (mouse-set-point e)
3297   (gnus-summary-next-page nil t))
3298
3299 (defun gnus-summary-set-display-table ()
3300   "Change the display table.
3301 Odd characters have a tendency to mess
3302 up nicely formatted displays - we make all possible glyphs
3303 display only a single character."
3304
3305   ;; We start from the standard display table, if any.
3306   (let ((table (or (copy-sequence standard-display-table)
3307                    (make-display-table)))
3308         (i 32))
3309     ;; Nix out all the control chars...
3310     (while (>= (setq i (1- i)) 0)
3311       (aset table i [??]))
3312    ;; ... but not newline and cr, of course.  (cr is necessary for the
3313     ;; selective display).
3314     (aset table ?\n nil)
3315     (aset table ?\r nil)
3316     ;; We keep TAB as well.
3317     (aset table ?\t nil)
3318     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3319     ;; Emacs 23 (unicode), that are not set already.
3320     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3321                  160
3322                256)))
3323       (while (>= (setq i (1- i)) 127)
3324         ;; Only modify if the entry is nil.
3325         (unless (aref table i)
3326           (aset table i [??]))))
3327     (setq buffer-display-table table)))
3328
3329 (defun gnus-summary-set-article-display-arrow (pos)
3330   "Update the overlay arrow to point to line at position POS."
3331   (when (and gnus-summary-display-arrow
3332              (boundp 'overlay-arrow-position)
3333              (boundp 'overlay-arrow-string))
3334     (save-excursion
3335       (goto-char pos)
3336       (beginning-of-line)
3337       (unless overlay-arrow-position
3338         (setq overlay-arrow-position (make-marker)))
3339       (setq overlay-arrow-string "=>"
3340             overlay-arrow-position (set-marker overlay-arrow-position
3341                                                (point)
3342                                                (current-buffer))))))
3343
3344 (defun gnus-summary-setup-buffer (group)
3345   "Initialize summary buffer."
3346   (let ((buffer (gnus-summary-buffer-name group))
3347         (dead-name (concat "*Dead Summary "
3348                            (gnus-group-decoded-name group) "*")))
3349     ;; If a dead summary buffer exists, we kill it.
3350     (when (gnus-buffer-live-p dead-name)
3351       (gnus-kill-buffer dead-name))
3352     (if (get-buffer buffer)
3353         (progn
3354           (set-buffer buffer)
3355           (setq gnus-summary-buffer (current-buffer))
3356           (not gnus-newsgroup-prepared))
3357       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3358       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3359       (gnus-summary-mode group)
3360       (when gnus-carpal
3361         (gnus-carpal-setup-buffer 'summary))
3362       (when (gnus-group-quit-config group)
3363         (set (make-local-variable 'gnus-single-article-buffer) nil))
3364       (make-local-variable 'gnus-article-buffer)
3365       (make-local-variable 'gnus-article-current)
3366       (make-local-variable 'gnus-original-article-buffer)
3367       (setq gnus-newsgroup-name group)
3368       ;; Set any local variables in the group parameters.
3369       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3370       t)))
3371
3372 (defun gnus-set-global-variables ()
3373   "Set the global equivalents of the buffer-local variables.
3374 They are set to the latest values they had.  These reflect the summary
3375 buffer that was in action when the last article was fetched."
3376   (when (eq major-mode 'gnus-summary-mode)
3377     (setq gnus-summary-buffer (current-buffer))
3378     (let ((name gnus-newsgroup-name)
3379           (marked gnus-newsgroup-marked)
3380           (spam gnus-newsgroup-spam-marked)
3381           (unread gnus-newsgroup-unreads)
3382           (headers gnus-current-headers)
3383           (data gnus-newsgroup-data)
3384           (summary gnus-summary-buffer)
3385           (article-buffer gnus-article-buffer)
3386           (original gnus-original-article-buffer)
3387           (gac gnus-article-current)
3388           (reffed gnus-reffed-article-number)
3389           (score-file gnus-current-score-file)
3390           (default-charset gnus-newsgroup-charset)
3391           vlist)
3392       (let ((locals gnus-newsgroup-variables))
3393         (while locals
3394           (if (consp (car locals))
3395               (push (eval (caar locals)) vlist)
3396             (push (eval (car locals)) vlist))
3397           (setq locals (cdr locals)))
3398         (setq vlist (nreverse vlist)))
3399       (with-current-buffer gnus-group-buffer
3400         (setq gnus-newsgroup-name name
3401               gnus-newsgroup-marked marked
3402               gnus-newsgroup-spam-marked spam
3403               gnus-newsgroup-unreads unread
3404               gnus-current-headers headers
3405               gnus-newsgroup-data data
3406               gnus-article-current gac
3407               gnus-summary-buffer summary
3408               gnus-article-buffer article-buffer
3409               gnus-original-article-buffer original
3410               gnus-reffed-article-number reffed
3411               gnus-current-score-file score-file
3412               gnus-newsgroup-charset default-charset)
3413         (let ((locals gnus-newsgroup-variables))
3414           (while locals
3415             (if (consp (car locals))
3416                 (set (caar locals) (pop vlist))
3417               (set (car locals) (pop vlist)))
3418             (setq locals (cdr locals))))
3419         ;; The article buffer also has local variables.
3420         (when (gnus-buffer-live-p gnus-article-buffer)
3421           (set-buffer gnus-article-buffer)
3422           (setq gnus-summary-buffer summary))))))
3423
3424 (defun gnus-summary-article-unread-p (article)
3425   "Say whether ARTICLE is unread or not."
3426   (memq article gnus-newsgroup-unreads))
3427
3428 (defun gnus-summary-first-article-p (&optional article)
3429   "Return whether ARTICLE is the first article in the buffer."
3430   (if (not (setq article (or article (gnus-summary-article-number))))
3431       nil
3432     (eq article (caar gnus-newsgroup-data))))
3433
3434 (defun gnus-summary-last-article-p (&optional article)
3435   "Return whether ARTICLE is the last article in the buffer."
3436   (if (not (setq article (or article (gnus-summary-article-number))))
3437       ;; All non-existent numbers are the last article.  :-)
3438       t
3439     (not (cdr (gnus-data-find-list article)))))
3440
3441 (defun gnus-make-thread-indent-array ()
3442   (let ((n 200))
3443     (unless (and gnus-thread-indent-array
3444                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3445       (setq gnus-thread-indent-array (make-vector 201 "")
3446             gnus-thread-indent-array-level gnus-thread-indent-level)
3447       (while (>= n 0)
3448         (aset gnus-thread-indent-array n
3449               (make-string (* n gnus-thread-indent-level) ? ))
3450         (setq n (1- n))))))
3451
3452 (defun gnus-update-summary-mark-positions ()
3453   "Compute where the summary marks are to go."
3454   (save-excursion
3455     (when (gnus-buffer-exists-p gnus-summary-buffer)
3456       (set-buffer gnus-summary-buffer))
3457     (let ((spec gnus-summary-line-format-spec)
3458           pos)
3459       (save-excursion
3460         (gnus-set-work-buffer)
3461         (let ((gnus-tmp-unread ?Z)
3462               (gnus-replied-mark ?Z)
3463               (gnus-score-below-mark ?Z)
3464               (gnus-score-over-mark ?Z)
3465               (gnus-undownloaded-mark ?Z)
3466               (gnus-summary-line-format-spec spec)
3467               (gnus-newsgroup-downloadable '(0))
3468               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3469               case-fold-search ignores)
3470           ;; Here, all marks are bound to Z.
3471           (gnus-summary-insert-line header
3472                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3473           (goto-char (point-min))
3474           ;; Memorize the positions of the same characters as dummy marks.
3475           (while (re-search-forward "[A-D]" nil t)
3476             (push (point) ignores))
3477           (erase-buffer)
3478           ;; We use A-D as dummy marks in order to know column positions
3479           ;; where marks should be inserted.
3480           (setq gnus-tmp-unread ?A
3481                 gnus-replied-mark ?B
3482                 gnus-score-below-mark ?C
3483                 gnus-score-over-mark ?C
3484                 gnus-undownloaded-mark ?D)
3485           (gnus-summary-insert-line header
3486                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3487           ;; Ignore characters which aren't dummy marks.
3488           (dolist (p ignores)
3489             (delete-region (goto-char (1- p)) p)
3490             (insert ?Z))
3491           (goto-char (point-min))
3492           (setq pos (list (cons 'unread
3493                                 (and (search-forward "A" nil t)
3494                                      (- (point) (point-min) 1)))))
3495           (goto-char (point-min))
3496           (push (cons 'replied (and (search-forward "B" nil t)
3497                                     (- (point) (point-min) 1)))
3498                 pos)
3499           (goto-char (point-min))
3500           (push (cons 'score (and (search-forward "C" nil t)
3501                                   (- (point) (point-min) 1)))
3502                 pos)
3503           (goto-char (point-min))
3504           (push (cons 'download (and (search-forward "D" nil t)
3505                                      (- (point) (point-min) 1)))
3506                 pos)))
3507       (setq gnus-summary-mark-positions pos))))
3508
3509 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3510   "Insert a dummy root in the summary buffer."
3511   (beginning-of-line)
3512   (gnus-add-text-properties
3513    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3514    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3515
3516 (defun gnus-summary-extract-address-component (from)
3517   (or (car (funcall gnus-extract-address-components from))
3518       from))
3519
3520 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3521   (let ((mail-parse-charset gnus-newsgroup-charset)
3522         ; Is it really necessary to do this next part for each summary line?
3523         ; Luckily, doesn't seem to slow things down much.
3524         (mail-parse-ignored-charsets
3525          (with-current-buffer gnus-summary-buffer
3526            gnus-newsgroup-ignored-charsets)))
3527     (or
3528      (and gnus-ignored-from-addresses
3529           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3530           (let ((extra-headers (mail-header-extra header))
3531                 to
3532                 newsgroups)
3533             (cond
3534              ((setq to (cdr (assq 'To extra-headers)))
3535               (concat gnus-summary-to-prefix
3536                       (inline
3537                         (gnus-summary-extract-address-component
3538                          (funcall gnus-decode-encoded-word-function to)))))
3539              ((setq newsgroups
3540                     (or
3541                      (cdr (assq 'Newsgroups extra-headers))
3542                      (and
3543                       (memq 'Newsgroups gnus-extra-headers)
3544                       (eq (car (gnus-find-method-for-group
3545                                 gnus-newsgroup-name)) 'nntp)
3546                       (gnus-group-real-name gnus-newsgroup-name))))
3547               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3548      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3549
3550 (defun gnus-summary-insert-line (gnus-tmp-header
3551                                  gnus-tmp-level gnus-tmp-current
3552                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3553                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3554                                  &optional gnus-tmp-dummy gnus-tmp-score
3555                                  gnus-tmp-process)
3556   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3557          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3558          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3559          (gnus-tmp-score-char
3560           (if (or (null gnus-summary-default-score)
3561                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3562                       gnus-summary-zcore-fuzz))
3563               ?                         ;Whitespace
3564             (if (< gnus-tmp-score gnus-summary-default-score)
3565                 gnus-score-below-mark gnus-score-over-mark)))
3566          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3567          (gnus-tmp-replied
3568           (cond (gnus-tmp-process gnus-process-mark)
3569                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3570                  gnus-cached-mark)
3571                 (gnus-tmp-replied gnus-replied-mark)
3572                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3573                  gnus-forwarded-mark)
3574                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3575                  gnus-saved-mark)
3576                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3577                  gnus-recent-mark)
3578                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3579                  gnus-unseen-mark)
3580                 (t gnus-no-mark)))
3581          (gnus-tmp-downloaded
3582           (cond (undownloaded
3583                  gnus-undownloaded-mark)
3584                 (gnus-newsgroup-agentized
3585                  gnus-downloaded-mark)
3586                 (t
3587                  gnus-no-mark)))
3588          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3589          (gnus-tmp-name
3590           (cond
3591            ((string-match "<[^>]+> *$" gnus-tmp-from)
3592             (let ((beg (match-beginning 0)))
3593               (or (and (string-match "^\".+\"" gnus-tmp-from)
3594                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3595                   (substring gnus-tmp-from 0 beg))))
3596            ((string-match "(.+)" gnus-tmp-from)
3597             (substring gnus-tmp-from
3598                        (1+ (match-beginning 0)) (1- (match-end 0))))
3599            (t gnus-tmp-from)))
3600          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3601          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3602          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3603          (buffer-read-only nil))
3604     (when (string= gnus-tmp-name "")
3605       (setq gnus-tmp-name gnus-tmp-from))
3606     (unless (numberp gnus-tmp-lines)
3607       (setq gnus-tmp-lines -1))
3608     (if (= gnus-tmp-lines -1)
3609         (setq gnus-tmp-lines "?")
3610       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3611       (gnus-put-text-property
3612      (point)
3613      (progn (eval gnus-summary-line-format-spec) (point))
3614        'gnus-number gnus-tmp-number)
3615     (when (gnus-visual-p 'summary-highlight 'highlight)
3616       (forward-line -1)
3617       (gnus-run-hooks 'gnus-summary-update-hook)
3618       (forward-line 1))))
3619
3620 (defun gnus-summary-update-line (&optional dont-update)
3621   "Update summary line after change."
3622   (when (and gnus-summary-default-score
3623              (not gnus-summary-inhibit-highlight))
3624     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3625            (article (gnus-summary-article-number))
3626            (score (gnus-summary-article-score article)))
3627       (unless dont-update
3628         (if (and gnus-summary-mark-below
3629                  (< (gnus-summary-article-score)
3630                     gnus-summary-mark-below))
3631             ;; This article has a low score, so we mark it as read.
3632             (when (memq article gnus-newsgroup-unreads)
3633               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3634           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3635             ;; This article was previously marked as read on account
3636             ;; of a low score, but now it has risen, so we mark it as
3637             ;; unread.
3638             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3639         (gnus-summary-update-mark
3640          (if (or (null gnus-summary-default-score)
3641                  (<= (abs (- score gnus-summary-default-score))
3642                      gnus-summary-zcore-fuzz))
3643              ?                          ;Whitespace
3644            (if (< score gnus-summary-default-score)
3645                gnus-score-below-mark gnus-score-over-mark))
3646          'score))
3647       ;; Do visual highlighting.
3648       (when (gnus-visual-p 'summary-highlight 'highlight)
3649         (gnus-run-hooks 'gnus-summary-update-hook)))))
3650
3651 (defvar gnus-tmp-new-adopts nil)
3652
3653 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3654   "Return the number of articles in THREAD.
3655 This may be 0 in some cases -- if none of the articles in
3656 the thread are to be displayed."
3657   (let* ((number
3658          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3659           (cond
3660            ((not (listp thread))
3661             1)
3662            ((and (consp thread) (cdr thread))
3663             (apply
3664              '+ 1 (mapcar
3665                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3666            ((null thread)
3667             1)
3668            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3669             1)
3670            (t 0))))
3671     (when (and level (zerop level) gnus-tmp-new-adopts)
3672       (incf number
3673             (apply '+ (mapcar
3674                        'gnus-summary-number-of-articles-in-thread
3675                        gnus-tmp-new-adopts))))
3676     (if char
3677         (if (> number 1) gnus-not-empty-thread-mark
3678           gnus-empty-thread-mark)
3679       number)))
3680
3681 (defsubst gnus-summary-line-message-size (head)
3682   "Return pretty-printed version of message size.
3683 This function is intended to be used in
3684 `gnus-summary-line-format-alist'."
3685   (let ((c (or (mail-header-chars head) -1)))
3686     (cond ((< c 0) "n/a")               ; chars not available
3687           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3688           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3689           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3690           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3691
3692
3693 (defun gnus-summary-set-local-parameters (group)
3694   "Go through the local params of GROUP and set all variable specs in that list."
3695   (let ((vars '(quit-config)))          ; Ignore quit-config.
3696     (dolist (elem (gnus-group-find-parameter group))
3697       (and (consp elem)                 ; Has to be a cons.
3698            (consp (cdr elem))           ; The cdr has to be a list.
3699            (symbolp (car elem))         ; Has to be a symbol in there.
3700            (not (memq (car elem) vars))
3701            (ignore-errors               ; So we set it.
3702              (push (car elem) vars)
3703              (make-local-variable (car elem))
3704              (set (car elem) (eval (nth 1 elem))))))))
3705
3706 (defun gnus-summary-read-group (group &optional show-all no-article
3707                                       kill-buffer no-display backward
3708                                       select-articles)
3709   "Start reading news in newsgroup GROUP.
3710 If SHOW-ALL is non-nil, already read articles are also listed.
3711 If NO-ARTICLE is non-nil, no article is selected initially.
3712 If NO-DISPLAY, don't generate a summary buffer."
3713   (let (result)
3714     (while (and group
3715                 (null (setq result
3716                             (let ((gnus-auto-select-next nil))
3717                               (or (gnus-summary-read-group-1
3718                                    group show-all no-article
3719                                    kill-buffer no-display
3720                                    select-articles)
3721                                   (setq show-all nil
3722                                         select-articles nil)))))
3723                 (eq gnus-auto-select-next 'quietly))
3724       (set-buffer gnus-group-buffer)
3725       ;; The entry function called above goes to the next
3726       ;; group automatically, so we go two groups back
3727       ;; if we are searching for the previous group.
3728       (when backward
3729         (gnus-group-prev-unread-group 2))
3730       (if (not (equal group (gnus-group-group-name)))
3731           (setq group (gnus-group-group-name))
3732         (setq group nil)))
3733     result))
3734
3735 (defun gnus-summary-read-group-1 (group show-all no-article
3736                                         kill-buffer no-display
3737                                         &optional select-articles)
3738   ;; Killed foreign groups can't be entered.
3739   ;;  (when (and (not (gnus-group-native-p group))
3740   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3741   ;;    (error "Dead non-native groups can't be entered"))
3742   (gnus-message 5 "Retrieving newsgroup: %s..."
3743                 (gnus-group-decoded-name group))
3744   (let* ((new-group (gnus-summary-setup-buffer group))
3745          (quit-config (gnus-group-quit-config group))
3746          (did-select (and new-group (gnus-select-newsgroup
3747                                      group show-all select-articles))))
3748     (cond
3749      ;; This summary buffer exists already, so we just select it.
3750      ((not new-group)
3751       (gnus-set-global-variables)
3752       (when kill-buffer
3753         (gnus-kill-or-deaden-summary kill-buffer))
3754       (gnus-configure-windows 'summary 'force)
3755       (gnus-set-mode-line 'summary)
3756       (gnus-summary-position-point)
3757       (message "")
3758       t)
3759      ;; We couldn't select this group.
3760      ((null did-select)
3761       (when (and (eq major-mode 'gnus-summary-mode)
3762                  (not (equal (current-buffer) kill-buffer)))
3763         (kill-buffer (current-buffer))
3764         (if (not quit-config)
3765             (progn
3766               ;; Update the info -- marks might need to be removed,
3767               ;; for instance.
3768               (gnus-summary-update-info)
3769               (set-buffer gnus-group-buffer)
3770               (gnus-group-jump-to-group group)
3771               (gnus-group-next-unread-group 1))
3772           (gnus-handle-ephemeral-exit quit-config)))
3773       (let ((grpinfo (gnus-get-info group)))
3774         (if (null (gnus-info-read grpinfo))
3775             (gnus-message 3 "Group %s contains no messages"
3776                           (gnus-group-decoded-name group))
3777           (gnus-message 3 "Can't select group")))
3778       nil)
3779      ;; The user did a `C-g' while prompting for number of articles,
3780      ;; so we exit this group.
3781      ((eq did-select 'quit)
3782       (and (eq major-mode 'gnus-summary-mode)
3783            (not (equal (current-buffer) kill-buffer))
3784            (kill-buffer (current-buffer)))
3785       (when kill-buffer
3786         (gnus-kill-or-deaden-summary kill-buffer))
3787       (if (not quit-config)
3788           (progn
3789             (set-buffer gnus-group-buffer)
3790             (gnus-group-jump-to-group group)
3791             (gnus-group-next-unread-group 1)
3792             (gnus-configure-windows 'group 'force))
3793         (gnus-handle-ephemeral-exit quit-config))
3794       ;; Finally signal the quit.
3795       (signal 'quit nil))
3796      ;; The group was successfully selected.
3797      (t
3798       (gnus-set-global-variables)
3799       ;; Save the active value in effect when the group was entered.
3800       (setq gnus-newsgroup-active
3801             (gnus-copy-sequence
3802              (gnus-active gnus-newsgroup-name)))
3803       ;; You can change the summary buffer in some way with this hook.
3804       (gnus-run-hooks 'gnus-select-group-hook)
3805       (when (memq 'summary (gnus-update-format-specifications
3806                             nil 'summary 'summary-mode 'summary-dummy))
3807         ;; The format specification for the summary line was updated,
3808         ;; so we need to update the mark positions as well.
3809         (gnus-update-summary-mark-positions))
3810       ;; Do score processing.
3811       (when gnus-use-scoring
3812         (gnus-possibly-score-headers))
3813       ;; Check whether to fill in the gaps in the threads.
3814       (when gnus-build-sparse-threads
3815         (gnus-build-sparse-threads))
3816       ;; Find the initial limit.
3817       (if show-all
3818           (let ((gnus-newsgroup-dormant nil))
3819             (gnus-summary-initial-limit show-all))
3820         (gnus-summary-initial-limit show-all))
3821       ;; Generate the summary buffer.
3822       (unless no-display
3823         (gnus-summary-prepare))
3824       (when gnus-use-trees
3825         (gnus-tree-open group)
3826         (setq gnus-summary-highlight-line-function
3827               'gnus-tree-highlight-article))
3828       ;; If the summary buffer is empty, but there are some low-scored
3829       ;; articles or some excluded dormants, we include these in the
3830       ;; buffer.
3831       (when (and (zerop (buffer-size))
3832                  (not no-display))
3833         (cond (gnus-newsgroup-dormant
3834                (gnus-summary-limit-include-dormant))
3835               ((and gnus-newsgroup-scored show-all)
3836                (gnus-summary-limit-include-expunged t))))
3837       ;; Function `gnus-apply-kill-file' must be called in this hook.
3838       (gnus-run-hooks 'gnus-apply-kill-hook)
3839       (if (and (zerop (buffer-size))
3840                (not no-display))
3841           (progn
3842             ;; This newsgroup is empty.
3843             (gnus-summary-catchup-and-exit nil t)
3844             (gnus-message 6 "No unread news")
3845             (when kill-buffer
3846               (gnus-kill-or-deaden-summary kill-buffer))
3847             ;; Return nil from this function.
3848             nil)
3849         ;; Hide conversation thread subtrees.  We cannot do this in
3850         ;; gnus-summary-prepare-hook since kill processing may not
3851         ;; work with hidden articles.
3852         (gnus-summary-maybe-hide-threads)
3853         (when kill-buffer
3854           (gnus-kill-or-deaden-summary kill-buffer))
3855         (gnus-summary-auto-select-subject)
3856         ;; Show first unread article if requested.
3857         (if (and (not no-article)
3858                  (not no-display)
3859                  gnus-newsgroup-unreads
3860                  gnus-auto-select-first)
3861             (progn
3862               (gnus-configure-windows 'summary)
3863               (let ((art (gnus-summary-article-number)))
3864                 (unless (and (not gnus-plugged)
3865                              (or (memq art gnus-newsgroup-undownloaded)
3866                                  (memq art gnus-newsgroup-downloadable)))
3867                   (gnus-summary-goto-article art))))
3868           ;; Don't select any articles.
3869           (gnus-summary-position-point)
3870           (gnus-configure-windows 'summary 'force)
3871           (gnus-set-mode-line 'summary))
3872         (when (and gnus-auto-center-group
3873                    (get-buffer-window gnus-group-buffer t))
3874           ;; Gotta use windows, because recenter does weird stuff if
3875           ;; the current buffer ain't the displayed window.
3876           (let ((owin (selected-window)))
3877             (select-window (get-buffer-window gnus-group-buffer t))
3878             (when (gnus-group-goto-group group)
3879               (recenter))
3880             (select-window owin)))
3881         ;; Mark this buffer as "prepared".
3882         (setq gnus-newsgroup-prepared t)
3883         (gnus-run-hooks 'gnus-summary-prepared-hook)
3884         (unless (gnus-ephemeral-group-p group)
3885           (gnus-group-update-group group))
3886         t)))))
3887
3888 (defun gnus-summary-auto-select-subject ()
3889   "Select the subject line on initial group entry."
3890   (goto-char (point-min))
3891   (cond
3892    ((eq gnus-auto-select-subject 'best)
3893     (gnus-summary-best-unread-subject))
3894    ((eq gnus-auto-select-subject 'unread)
3895     (gnus-summary-first-unread-subject))
3896    ((eq gnus-auto-select-subject 'unseen)
3897     (gnus-summary-first-unseen-subject))
3898    ((eq gnus-auto-select-subject 'unseen-or-unread)
3899     (gnus-summary-first-unseen-or-unread-subject))
3900    ((eq gnus-auto-select-subject 'first)
3901     ;; Do nothing.
3902     )
3903    ((functionp gnus-auto-select-subject)
3904     (funcall gnus-auto-select-subject))))
3905
3906 (defun gnus-summary-prepare ()
3907   "Generate the summary buffer."
3908   (interactive)
3909   (let ((buffer-read-only nil))
3910     (erase-buffer)
3911     (setq gnus-newsgroup-data nil
3912           gnus-newsgroup-data-reverse nil)
3913     (gnus-run-hooks 'gnus-summary-generate-hook)
3914     ;; Generate the buffer, either with threads or without.
3915     (when gnus-newsgroup-headers
3916       (gnus-summary-prepare-threads
3917        (if gnus-show-threads
3918            (gnus-sort-gathered-threads
3919             (funcall gnus-summary-thread-gathering-function
3920                      (gnus-sort-threads
3921                       (gnus-cut-threads (gnus-make-threads)))))
3922          ;; Unthreaded display.
3923          (gnus-sort-articles gnus-newsgroup-headers))))
3924     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3925     ;; Call hooks for modifying summary buffer.
3926     (goto-char (point-min))
3927     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3928
3929 (defsubst gnus-general-simplify-subject (subject)
3930   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3931   (setq subject
3932         (cond
3933          ;; Truncate the subject.
3934          (gnus-simplify-subject-functions
3935           (gnus-map-function gnus-simplify-subject-functions subject))
3936          ((numberp gnus-summary-gather-subject-limit)
3937           (setq subject (gnus-simplify-subject-re subject))
3938           (if (> (length subject) gnus-summary-gather-subject-limit)
3939               (substring subject 0 gnus-summary-gather-subject-limit)
3940             subject))
3941          ;; Fuzzily simplify it.
3942          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3943           (gnus-simplify-subject-fuzzy subject))
3944          ;; Just remove the leading "Re:".
3945          (t
3946           (gnus-simplify-subject-re subject))))
3947
3948   (if (and gnus-summary-gather-exclude-subject
3949            (string-match gnus-summary-gather-exclude-subject subject))
3950       nil                         ; This article shouldn't be gathered
3951     subject))
3952
3953 (defun gnus-summary-simplify-subject-query ()
3954   "Query where the respool algorithm would put this article."
3955   (interactive)
3956   (gnus-summary-select-article)
3957   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3958
3959 (defun gnus-gather-threads-by-subject (threads)
3960   "Gather threads by looking at Subject headers."
3961   (if (not gnus-summary-make-false-root)
3962       threads
3963     (let ((hashtb (gnus-make-hashtable 1024))
3964           (prev threads)
3965           (result threads)
3966           subject hthread whole-subject)
3967       (while threads
3968         (setq subject (gnus-general-simplify-subject
3969                        (setq whole-subject (mail-header-subject
3970                                             (caar threads)))))
3971         (when subject
3972           (if (setq hthread (gnus-gethash subject hashtb))
3973               (progn
3974                 ;; We enter a dummy root into the thread, if we
3975                 ;; haven't done that already.
3976                 (unless (stringp (caar hthread))
3977                   (setcar hthread (list whole-subject (car hthread))))
3978                 ;; We add this new gathered thread to this gathered
3979                 ;; thread.
3980                 (setcdr (car hthread)
3981                         (nconc (cdar hthread) (list (car threads))))
3982                 ;; Remove it from the list of threads.
3983                 (setcdr prev (cdr threads))
3984                 (setq threads prev))
3985             ;; Enter this thread into the hash table.
3986             (gnus-sethash subject
3987                           (if gnus-summary-make-false-root-always
3988                               (progn
3989                                 ;; If you want a dummy root above all
3990                                 ;; threads...
3991                                 (setcar threads (list whole-subject
3992                                                       (car threads)))
3993                                 threads)
3994                             threads)
3995                           hashtb)))
3996         (setq prev threads)
3997         (setq threads (cdr threads)))
3998       result)))
3999
4000 (defun gnus-gather-threads-by-references (threads)
4001   "Gather threads by looking at References headers."
4002   (let ((idhashtb (gnus-make-hashtable 1024))
4003         (thhashtb (gnus-make-hashtable 1024))
4004         (prev threads)
4005         (result threads)
4006         ids references id gthread gid entered ref)
4007     (while threads
4008       (when (setq references (mail-header-references (caar threads)))
4009         (setq id (mail-header-id (caar threads))
4010               ids (inline (gnus-split-references references))
4011               entered nil)
4012         (while (setq ref (pop ids))
4013           (setq ids (delete ref ids))
4014           (if (not (setq gid (gnus-gethash ref idhashtb)))
4015               (progn
4016                 (gnus-sethash ref id idhashtb)
4017                 (gnus-sethash id threads thhashtb))
4018             (setq gthread (gnus-gethash gid thhashtb))
4019             (unless entered
4020               ;; We enter a dummy root into the thread, if we
4021               ;; haven't done that already.
4022               (unless (stringp (caar gthread))
4023                 (setcar gthread (list (mail-header-subject (caar gthread))
4024                                       (car gthread))))
4025               ;; We add this new gathered thread to this gathered
4026               ;; thread.
4027               (setcdr (car gthread)
4028                       (nconc (cdar gthread) (list (car threads)))))
4029             ;; Add it into the thread hash table.
4030             (gnus-sethash id gthread thhashtb)
4031             (setq entered t)
4032             ;; Remove it from the list of threads.
4033             (setcdr prev (cdr threads))
4034             (setq threads prev))))
4035       (setq prev threads)
4036       (setq threads (cdr threads)))
4037     result))
4038
4039 (defun gnus-sort-gathered-threads (threads)
4040   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4041   (let ((result threads))
4042     (while threads
4043       (when (stringp (caar threads))
4044         (setcdr (car threads)
4045                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4046       (setq threads (cdr threads)))
4047     result))
4048
4049 (defun gnus-thread-loop-p (root thread)
4050   "Say whether ROOT is in THREAD."
4051   (let ((stack (list thread))
4052         (infloop 0)
4053         th)
4054     (while (setq thread (pop stack))
4055       (setq th (cdr thread))
4056       (while (and th
4057                   (not (eq (caar th) root)))
4058         (pop th))
4059       (if th
4060           ;; We have found a loop.
4061           (let (ref-dep)
4062             (setcdr thread (delq (car th) (cdr thread)))
4063             (if (boundp (setq ref-dep (intern "none"
4064                                               gnus-newsgroup-dependencies)))
4065                 (setcdr (symbol-value ref-dep)
4066                         (nconc (cdr (symbol-value ref-dep))
4067                                (list (car th))))
4068               (set ref-dep (list nil (car th))))
4069             (setq infloop 1
4070                   stack nil))
4071         ;; Push all the subthreads onto the stack.
4072         (push (cdr thread) stack)))
4073     infloop))
4074
4075 (defun gnus-make-threads ()
4076   "Go through the dependency hashtb and find the roots.  Return all threads."
4077   (let (threads)
4078     (while (catch 'infloop
4079              (mapatoms
4080               (lambda (refs)
4081                 ;; Deal with self-referencing References loops.
4082                 (when (and (car (symbol-value refs))
4083                            (not (zerop
4084                                  (apply
4085                                   '+
4086                                   (mapcar
4087                                    (lambda (thread)
4088                                      (gnus-thread-loop-p
4089                                       (car (symbol-value refs)) thread))
4090                                    (cdr (symbol-value refs)))))))
4091                   (setq threads nil)
4092                   (throw 'infloop t))
4093                 (unless (car (symbol-value refs))
4094                   ;; These threads do not refer back to any other
4095                   ;; articles, so they're roots.
4096                   (setq threads (append (cdr (symbol-value refs)) threads))))
4097               gnus-newsgroup-dependencies)))
4098     threads))
4099
4100 ;; Build the thread tree.
4101 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4102   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4103
4104 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4105 if it was already present.
4106
4107 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4108 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4109 Message-IDs will be renamed to a unique Message-ID before being
4110 entered.
4111
4112 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4113   (let* ((id (mail-header-id header))
4114          (id-dep (and id (intern id dependencies)))
4115          parent-id ref ref-dep ref-header replaced)
4116     ;; Enter this `header' in the `dependencies' table.
4117     (cond
4118      ((not id-dep)
4119       (setq header nil))
4120      ;; The first two cases do the normal part: enter a new `header'
4121      ;; in the `dependencies' table.
4122      ((not (boundp id-dep))
4123       (set id-dep (list header)))
4124      ((null (car (symbol-value id-dep)))
4125       (setcar (symbol-value id-dep) header))
4126
4127      ;; From here the `header' was already present in the
4128      ;; `dependencies' table.
4129      (force-new
4130       ;; Overrides an existing entry;
4131       ;; just set the header part of the entry.
4132       (setcar (symbol-value id-dep) header)
4133       (setq replaced t))
4134
4135      ;; Renames the existing `header' to a unique Message-ID.
4136      ((not gnus-summary-ignore-duplicates)
4137       ;; An article with this Message-ID has already been seen.
4138       ;; We rename the Message-ID.
4139       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4140            (list header))
4141       (mail-header-set-id header id))
4142
4143      ;; The last case ignores an existing entry, except it adds any
4144      ;; additional Xrefs (in case the two articles came from different
4145      ;; servers.
4146      ;; Also sets `header' to `nil' meaning that the `dependencies'
4147      ;; table was *not* modified.
4148      (t
4149       (mail-header-set-xref
4150        (car (symbol-value id-dep))
4151        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4152                    "")
4153                (or (mail-header-xref header) "")))
4154       (setq header nil)))
4155
4156     (when (and header (not replaced))
4157       ;; First check that we are not creating a References loop.
4158       (setq parent-id (gnus-parent-id (mail-header-references header)))
4159       (setq ref parent-id)
4160       (while (and ref
4161                   (setq ref-dep (intern-soft ref dependencies))
4162                   (boundp ref-dep)
4163                   (setq ref-header (car (symbol-value ref-dep))))
4164         (if (string= id ref)
4165             ;; Yuk!  This is a reference loop.  Make the article be a
4166             ;; root article.
4167             (progn
4168               (mail-header-set-references (car (symbol-value id-dep)) "none")
4169               (setq ref nil)
4170               (setq parent-id nil))
4171           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4172       (setq ref-dep (intern (or parent-id "none") dependencies))
4173       (if (boundp ref-dep)
4174           (setcdr (symbol-value ref-dep)
4175                   (nconc (cdr (symbol-value ref-dep))
4176                          (list (symbol-value id-dep))))
4177         (set ref-dep (list nil (symbol-value id-dep)))))
4178     header))
4179
4180 (defun gnus-extract-message-id-from-in-reply-to (string)
4181   (if (string-match "<[^>]+>" string)
4182       (substring string (match-beginning 0) (match-end 0))
4183     nil))
4184
4185 (defun gnus-build-sparse-threads ()
4186   (let ((headers gnus-newsgroup-headers)
4187         (mail-parse-charset gnus-newsgroup-charset)
4188         (gnus-summary-ignore-duplicates t)
4189         header references generation relations
4190         subject child end new-child date)
4191     ;; First we create an alist of generations/relations, where
4192     ;; generations is how much we trust the relation, and the relation
4193     ;; is parent/child.
4194     (gnus-message 7 "Making sparse threads...")
4195     (save-excursion
4196       (nnheader-set-temp-buffer " *gnus sparse threads*")
4197       (while (setq header (pop headers))
4198         (when (and (setq references (mail-header-references header))
4199                    (not (string= references "")))
4200           (insert references)
4201           (setq child (mail-header-id header)
4202                 subject (mail-header-subject header)
4203                 date (mail-header-date header)
4204                 generation 0)
4205           (while (search-backward ">" nil t)
4206             (setq end (1+ (point)))
4207             (when (search-backward "<" nil t)
4208               (setq new-child (buffer-substring (point) end))
4209               (push (list (incf generation)
4210                           child (setq child new-child)
4211                           subject date)
4212                     relations)))
4213           (when child
4214             (push (list (1+ generation) child nil subject) relations))
4215           (erase-buffer)))
4216       (kill-buffer (current-buffer)))
4217     ;; Sort over trustworthiness.
4218     (mapcar
4219      (lambda (relation)
4220        (when (gnus-dependencies-add-header
4221               (make-full-mail-header
4222                gnus-reffed-article-number
4223                (nth 3 relation) "" (or (nth 4 relation) "")
4224                (nth 1 relation)
4225                (or (nth 2 relation) "") 0 0 "")
4226               gnus-newsgroup-dependencies nil)
4227          (push gnus-reffed-article-number gnus-newsgroup-limit)
4228          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4229          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4230                gnus-newsgroup-reads)
4231          (decf gnus-reffed-article-number)))
4232      (sort relations 'car-less-than-car))
4233     (gnus-message 7 "Making sparse threads...done")))
4234
4235 (defun gnus-build-old-threads ()
4236   ;; Look at all the articles that refer back to old articles, and
4237   ;; fetch the headers for the articles that aren't there.  This will
4238   ;; build complete threads - if the roots haven't been expired by the
4239   ;; server, that is.
4240   (let ((mail-parse-charset gnus-newsgroup-charset)
4241         id heads)
4242     (mapatoms
4243      (lambda (refs)
4244        (when (not (car (symbol-value refs)))
4245          (setq heads (cdr (symbol-value refs)))
4246          (while heads
4247            (if (memq (mail-header-number (caar heads))
4248                      gnus-newsgroup-dormant)
4249                (setq heads (cdr heads))
4250              (setq id (symbol-name refs))
4251              (while (and (setq id (gnus-build-get-header id))
4252                          (not (car (gnus-id-to-thread id)))))
4253              (setq heads nil)))))
4254      gnus-newsgroup-dependencies)))
4255
4256 (defsubst gnus-remove-odd-characters (string)
4257   "Translate STRING into something that doesn't contain weird characters."
4258   (mm-subst-char-in-string
4259    ?\r ?\-
4260    (mm-subst-char-in-string ?\n ?\- string t) t))
4261
4262 ;; This function has to be called with point after the article number
4263 ;; on the beginning of the line.
4264 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4265   (let ((eol (point-at-eol))
4266         (buffer (current-buffer))
4267         header references in-reply-to)
4268
4269     ;; overview: [num subject from date id refs chars lines misc]
4270     (unwind-protect
4271         (let (x)
4272           (narrow-to-region (point) eol)
4273           (unless (eobp)
4274             (forward-char))
4275
4276           (setq header
4277                 (make-full-mail-header
4278                  number                 ; number
4279                  (condition-case ()     ; subject
4280                      (gnus-remove-odd-characters
4281                       (funcall gnus-decode-encoded-word-function
4282                                (setq x (nnheader-nov-field))))
4283                    (error x))
4284                  (condition-case ()     ; from
4285                      (gnus-remove-odd-characters
4286                       (funcall gnus-decode-encoded-word-function
4287                                (setq x (nnheader-nov-field))))
4288                    (error x))
4289                  (nnheader-nov-field)   ; date
4290                  (nnheader-nov-read-message-id number)  ; id
4291                  (setq references (nnheader-nov-field)) ; refs
4292                  (nnheader-nov-read-integer) ; chars
4293                  (nnheader-nov-read-integer) ; lines
4294                  (unless (eobp)
4295                    (if (looking-at "Xref: ")
4296                        (goto-char (match-end 0)))
4297                    (nnheader-nov-field)) ; Xref
4298                  (nnheader-nov-parse-extra)))) ; extra
4299
4300       (widen))
4301
4302     (when (and (string= references "")
4303                (setq in-reply-to (mail-header-extra header))
4304                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4305       (mail-header-set-references
4306        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4307
4308     (when gnus-alter-header-function
4309       (funcall gnus-alter-header-function header))
4310     (gnus-dependencies-add-header header dependencies force-new)))
4311
4312 (defun gnus-build-get-header (id)
4313   "Look through the buffer of NOV lines and find the header to ID.
4314 Enter this line into the dependencies hash table, and return
4315 the id of the parent article (if any)."
4316   (let ((deps gnus-newsgroup-dependencies)
4317         found header)
4318     (prog1
4319         (save-excursion
4320           (set-buffer nntp-server-buffer)
4321           (let ((case-fold-search nil))
4322             (goto-char (point-min))
4323             (while (and (not found)
4324                         (search-forward id nil t))
4325               (beginning-of-line)
4326               (setq found (looking-at
4327                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4328                                    (regexp-quote id))))
4329               (or found (beginning-of-line 2)))
4330             (when found
4331               (beginning-of-line)
4332               (and
4333                (setq header (gnus-nov-parse-line
4334                              (read (current-buffer)) deps))
4335                (gnus-parent-id (mail-header-references header))))))
4336       (when header
4337         (let ((number (mail-header-number header)))
4338           (push number gnus-newsgroup-limit)
4339           (push header gnus-newsgroup-headers)
4340           (if (memq number gnus-newsgroup-unselected)
4341               (progn
4342                 (setq gnus-newsgroup-unreads
4343                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4344                                                number))
4345                 (setq gnus-newsgroup-unselected
4346                       (delq number gnus-newsgroup-unselected)))
4347             (push number gnus-newsgroup-ancient)))))))
4348
4349 (defun gnus-build-all-threads ()
4350   "Read all the headers."
4351   (let ((gnus-summary-ignore-duplicates t)
4352         (mail-parse-charset gnus-newsgroup-charset)
4353         (dependencies gnus-newsgroup-dependencies)
4354         header article)
4355     (save-excursion
4356       (set-buffer nntp-server-buffer)
4357       (let ((case-fold-search nil))
4358         (goto-char (point-min))
4359         (while (not (eobp))
4360           (ignore-errors
4361             (setq article (read (current-buffer))
4362                   header (gnus-nov-parse-line article dependencies)))
4363           (when header
4364             (with-current-buffer gnus-summary-buffer
4365               (push header gnus-newsgroup-headers)
4366               (if (memq (setq article (mail-header-number header))
4367                         gnus-newsgroup-unselected)
4368                   (progn
4369                     (setq gnus-newsgroup-unreads
4370                           (gnus-add-to-sorted-list
4371                            gnus-newsgroup-unreads article))
4372                     (setq gnus-newsgroup-unselected
4373                           (delq article gnus-newsgroup-unselected)))
4374                 (push article gnus-newsgroup-ancient)))
4375             (forward-line 1)))))))
4376
4377 (defun gnus-summary-update-article-line (article header)
4378   "Update the line for ARTICLE using HEADER."
4379   (let* ((id (mail-header-id header))
4380          (thread (gnus-id-to-thread id)))
4381     (unless thread
4382       (error "Article in no thread"))
4383     ;; Update the thread.
4384     (setcar thread header)
4385     (gnus-summary-goto-subject article)
4386     (let* ((datal (gnus-data-find-list article))
4387            (data (car datal))
4388            (buffer-read-only nil)
4389            (level (gnus-summary-thread-level)))
4390       (gnus-delete-line)
4391       (let ((inserted (- (point)
4392                          (progn
4393                            (gnus-summary-insert-line
4394                             header level nil
4395                             (memq article gnus-newsgroup-undownloaded)
4396                             (gnus-article-mark article)
4397                             (memq article gnus-newsgroup-replied)
4398                             (memq article gnus-newsgroup-expirable)
4399                             ;; Only insert the Subject string when it's different
4400                             ;; from the previous Subject string.
4401                             (if (and
4402                                  gnus-show-threads
4403                                  (gnus-subject-equal
4404                                   (condition-case ()
4405                                       (mail-header-subject
4406                                        (gnus-data-header
4407                                         (cadr
4408                                          (gnus-data-find-list
4409                                           article
4410                                           (gnus-data-list t)))))
4411                                     ;; Error on the side of excessive subjects.
4412                                     (error ""))
4413                                   (mail-header-subject header)))
4414                                 ""
4415                               (mail-header-subject header))
4416                             nil (cdr (assq article gnus-newsgroup-scored))
4417                             (memq article gnus-newsgroup-processable))
4418                            (point)))))
4419         (when (cdr datal)
4420           (gnus-data-update-list
4421            (cdr datal)
4422            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4423
4424 (defun gnus-summary-update-article (article &optional iheader)
4425   "Update ARTICLE in the summary buffer."
4426   (set-buffer gnus-summary-buffer)
4427   (let* ((header (gnus-summary-article-header article))
4428          (id (mail-header-id header))
4429          (data (gnus-data-find article))
4430          (thread (gnus-id-to-thread id))
4431          (references (mail-header-references header))
4432          (parent
4433           (gnus-id-to-thread
4434            (or (gnus-parent-id
4435                 (when (and references
4436                            (not (equal "" references)))
4437                   references))
4438                "none")))
4439          (buffer-read-only nil)
4440          (old (car thread)))
4441     (when thread
4442       (unless iheader
4443         (setcar thread nil)
4444         (when parent
4445           (delq thread parent)))
4446       (if (gnus-summary-insert-subject id header)
4447           ;; Set the (possibly) new article number in the data structure.
4448           (gnus-data-set-number data (gnus-id-to-article id))
4449         (setcar thread old)
4450         nil))))
4451
4452 (defun gnus-rebuild-thread (id &optional line)
4453   "Rebuild the thread containing ID.
4454 If LINE, insert the rebuilt thread starting on line LINE."
4455   (let ((buffer-read-only nil)
4456         old-pos current thread data)
4457     (if (not gnus-show-threads)
4458         (setq thread (list (car (gnus-id-to-thread id))))
4459       ;; Get the thread this article is part of.
4460       (setq thread (gnus-remove-thread id)))
4461     (setq old-pos (point-at-bol))
4462     (setq current (save-excursion
4463                     (and (re-search-backward "[\r\n]" nil t)
4464                          (gnus-summary-article-number))))
4465     ;; If this is a gathered thread, we have to go some re-gathering.
4466     (when (stringp (car thread))
4467       (let ((subject (car thread))
4468             roots thr)
4469         (setq thread (cdr thread))
4470         (while thread
4471           (unless (memq (setq thr (gnus-id-to-thread
4472                                    (gnus-root-id
4473                                     (mail-header-id (caar thread)))))
4474                         roots)
4475             (push thr roots))
4476           (setq thread (cdr thread)))
4477         ;; We now have all (unique) roots.
4478         (if (= (length roots) 1)
4479             ;; All the loose roots are now one solid root.
4480             (setq thread (car roots))
4481           (setq thread (cons subject (gnus-sort-threads roots))))))
4482     (let (threads)
4483       ;; We then insert this thread into the summary buffer.
4484       (when line
4485         (goto-char (point-min))
4486         (forward-line (1- line)))
4487       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4488         (if gnus-show-threads
4489             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4490           (gnus-summary-prepare-unthreaded thread))
4491         (setq data (nreverse gnus-newsgroup-data))
4492         (setq threads gnus-newsgroup-threads))
4493       ;; We splice the new data into the data structure.
4494       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4495       ;;!!! then we want to insert at the beginning of the buffer.
4496       ;;!!! That happens to be true with Gnus now, but that may
4497       ;;!!! change in the future.  Perhaps.
4498       (gnus-data-enter-list
4499        (if line nil current) data (- (point) old-pos))
4500       (setq gnus-newsgroup-threads
4501             (nconc threads gnus-newsgroup-threads))
4502       (gnus-data-compute-positions))))
4503
4504 (defun gnus-number-to-header (number)
4505   "Return the header for article NUMBER."
4506   (let ((headers gnus-newsgroup-headers))
4507     (while (and headers
4508                 (not (= number (mail-header-number (car headers)))))
4509       (pop headers))
4510     (when headers
4511       (car headers))))
4512
4513 (defun gnus-parent-headers (in-headers &optional generation)
4514   "Return the headers of the GENERATIONeth parent of HEADERS."
4515   (unless generation
4516     (setq generation 1))
4517   (let ((parent t)
4518         (headers in-headers)
4519         references)
4520     (while (and parent
4521                 (not (zerop generation))
4522                 (setq references (mail-header-references headers)))
4523       (setq headers (if (and references
4524                              (setq parent (gnus-parent-id references)))
4525                         (car (gnus-id-to-thread parent))
4526                       nil))
4527       (decf generation))
4528     (and (not (eq headers in-headers))
4529          headers)))
4530
4531 (defun gnus-id-to-thread (id)
4532   "Return the (sub-)thread where ID appears."
4533   (gnus-gethash id gnus-newsgroup-dependencies))
4534
4535 (defun gnus-id-to-article (id)
4536   "Return the article number of ID."
4537   (let ((thread (gnus-id-to-thread id)))
4538     (when (and thread
4539                (car thread))
4540       (mail-header-number (car thread)))))
4541
4542 (defun gnus-id-to-header (id)
4543   "Return the article headers of ID."
4544   (car (gnus-id-to-thread id)))
4545
4546 (defun gnus-article-displayed-root-p (article)
4547   "Say whether ARTICLE is a root(ish) article."
4548   (let ((level (gnus-summary-thread-level article))
4549         (refs (mail-header-references  (gnus-summary-article-header article)))
4550         particle)
4551     (cond
4552      ((null level) nil)
4553      ((zerop level) t)
4554      ((null refs) t)
4555      ((null (gnus-parent-id refs)) t)
4556      ((and (= 1 level)
4557            (null (setq particle (gnus-id-to-article
4558                                  (gnus-parent-id refs))))
4559            (null (gnus-summary-thread-level particle)))))))
4560
4561 (defun gnus-root-id (id)
4562   "Return the id of the root of the thread where ID appears."
4563   (let (last-id prev)
4564     (while (and id (setq prev (car (gnus-id-to-thread id))))
4565       (setq last-id id
4566             id (gnus-parent-id (mail-header-references prev))))
4567     last-id))
4568
4569 (defun gnus-articles-in-thread (thread)
4570   "Return the list of articles in THREAD."
4571   (cons (mail-header-number (car thread))
4572         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4573
4574 (defun gnus-remove-thread (id &optional dont-remove)
4575   "Remove the thread that has ID in it."
4576   (let (headers thread last-id)
4577     ;; First go up in this thread until we find the root.
4578     (setq last-id (gnus-root-id id)
4579           headers (message-flatten-list (gnus-id-to-thread last-id)))
4580     ;; We have now found the real root of this thread.  It might have
4581     ;; been gathered into some loose thread, so we have to search
4582     ;; through the threads to find the thread we wanted.
4583     (let ((threads gnus-newsgroup-threads)
4584           sub)
4585       (while threads
4586         (setq sub (car threads))
4587         (if (stringp (car sub))
4588             ;; This is a gathered thread, so we look at the roots
4589             ;; below it to find whether this article is in this
4590             ;; gathered root.
4591             (progn
4592               (setq sub (cdr sub))
4593               (while sub
4594                 (when (member (caar sub) headers)
4595                   (setq thread (car threads)
4596                         threads nil
4597                         sub nil))
4598                 (setq sub (cdr sub))))
4599           ;; It's an ordinary thread, so we check it.
4600           (when (eq (car sub) (car headers))
4601             (setq thread sub
4602                   threads nil)))
4603         (setq threads (cdr threads)))
4604       ;; If this article is in no thread, then it's a root.
4605       (if thread
4606           (unless dont-remove
4607             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4608         (setq thread (gnus-id-to-thread last-id)))
4609       (when thread
4610         (prog1
4611             thread                      ; We return this thread.
4612           (unless dont-remove
4613             (if (stringp (car thread))
4614                 (progn
4615                   ;; If we use dummy roots, then we have to remove the
4616                   ;; dummy root as well.
4617                   (when (eq gnus-summary-make-false-root 'dummy)
4618                     ;; We go to the dummy root by going to
4619                     ;; the first sub-"thread", and then one line up.
4620                     (gnus-summary-goto-article
4621                      (mail-header-number (caadr thread)))
4622                     (forward-line -1)
4623                     (gnus-delete-line)
4624                     (gnus-data-compute-positions))
4625                   (setq thread (cdr thread))
4626                   (while thread
4627                     (gnus-remove-thread-1 (car thread))
4628                     (setq thread (cdr thread))))
4629               (gnus-remove-thread-1 thread))))))))
4630
4631 (defun gnus-remove-thread-1 (thread)
4632   "Remove the thread THREAD recursively."
4633   (let ((number (mail-header-number (pop thread)))
4634         d)
4635     (setq thread (reverse thread))
4636     (while thread
4637       (gnus-remove-thread-1 (pop thread)))
4638     (when (setq d (gnus-data-find number))
4639       (goto-char (gnus-data-pos d))
4640       (gnus-summary-show-thread)
4641       (gnus-data-remove
4642        number
4643        (- (point-at-bol)
4644           (prog1
4645               (1+ (point-at-eol))
4646             (gnus-delete-line)))))))
4647
4648 (defun gnus-sort-threads-1 (threads func)
4649   (sort (mapcar (lambda (thread)
4650                   (cons (car thread)
4651                         (and (cdr thread)
4652                              (gnus-sort-threads-1 (cdr thread) func))))
4653                 threads) func))
4654
4655 (defun gnus-sort-threads (threads)
4656   "Sort THREADS."
4657   (if (not gnus-thread-sort-functions)
4658       threads
4659     (gnus-message 8 "Sorting threads...")
4660     (let ((max-lisp-eval-depth 5000))
4661       (prog1 (gnus-sort-threads-1
4662          threads
4663          (gnus-make-sort-function gnus-thread-sort-functions))
4664         (gnus-message 8 "Sorting threads...done")))))
4665
4666 (defun gnus-sort-articles (articles)
4667   "Sort ARTICLES."
4668   (when gnus-article-sort-functions
4669     (gnus-message 7 "Sorting articles...")
4670     (prog1
4671         (setq gnus-newsgroup-headers
4672               (sort articles (gnus-make-sort-function
4673                               gnus-article-sort-functions)))
4674       (gnus-message 7 "Sorting articles...done"))))
4675
4676 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4677 (defmacro gnus-thread-header (thread)
4678   "Return header of first article in THREAD.
4679 Note that THREAD must never, ever be anything else than a variable -
4680 using some other form will lead to serious barfage."
4681   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4682   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4683   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4684         (vector thread) 2))
4685
4686 (defsubst gnus-article-sort-by-number (h1 h2)
4687   "Sort articles by article number."
4688   (< (mail-header-number h1)
4689      (mail-header-number h2)))
4690
4691 (defun gnus-thread-sort-by-number (h1 h2)
4692   "Sort threads by root article number."
4693   (gnus-article-sort-by-number
4694    (gnus-thread-header h1) (gnus-thread-header h2)))
4695
4696 (defsubst gnus-article-sort-by-random (h1 h2)
4697   "Sort articles by article number."
4698   (zerop (random 2)))
4699
4700 (defun gnus-thread-sort-by-random (h1 h2)
4701   "Sort threads by root article number."
4702   (gnus-article-sort-by-random
4703    (gnus-thread-header h1) (gnus-thread-header h2)))
4704
4705 (defsubst gnus-article-sort-by-lines (h1 h2)
4706   "Sort articles by article Lines header."
4707   (< (mail-header-lines h1)
4708      (mail-header-lines h2)))
4709
4710 (defun gnus-thread-sort-by-lines (h1 h2)
4711   "Sort threads by root article Lines header."
4712   (gnus-article-sort-by-lines
4713    (gnus-thread-header h1) (gnus-thread-header h2)))
4714
4715 (defsubst gnus-article-sort-by-chars (h1 h2)
4716   "Sort articles by octet length."
4717   (< (mail-header-chars h1)
4718      (mail-header-chars h2)))
4719
4720 (defun gnus-thread-sort-by-chars (h1 h2)
4721   "Sort threads by root article octet length."
4722   (gnus-article-sort-by-chars
4723    (gnus-thread-header h1) (gnus-thread-header h2)))
4724
4725 (defsubst gnus-article-sort-by-author (h1 h2)
4726   "Sort articles by root author."
4727   (string-lessp
4728    (let ((extract (funcall
4729                    gnus-extract-address-components
4730                    (mail-header-from h1))))
4731      (or (car extract) (cadr extract) ""))
4732    (let ((extract (funcall
4733                    gnus-extract-address-components
4734                    (mail-header-from h2))))
4735      (or (car extract) (cadr extract) ""))))
4736
4737 (defun gnus-thread-sort-by-author (h1 h2)
4738   "Sort threads by root author."
4739   (gnus-article-sort-by-author
4740    (gnus-thread-header h1)  (gnus-thread-header h2)))
4741
4742 (defsubst gnus-article-sort-by-recipient (h1 h2)
4743   "Sort articles by recipient."
4744   (string-lessp
4745    (let ((extract (funcall
4746                    gnus-extract-address-components
4747                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4748      (or (car extract) (cadr extract)))
4749    (let ((extract (funcall
4750                    gnus-extract-address-components
4751                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4752      (or (car extract) (cadr extract)))))
4753
4754 (defun gnus-thread-sort-by-recipient (h1 h2)
4755   "Sort threads by root recipient."
4756   (gnus-article-sort-by-recipient
4757    (gnus-thread-header h1) (gnus-thread-header h2)))
4758
4759 (defsubst gnus-article-sort-by-subject (h1 h2)
4760   "Sort articles by root subject."
4761   (string-lessp
4762    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4763    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4764
4765 (defun gnus-thread-sort-by-subject (h1 h2)
4766   "Sort threads by root subject."
4767   (gnus-article-sort-by-subject
4768    (gnus-thread-header h1) (gnus-thread-header h2)))
4769
4770 (defsubst gnus-article-sort-by-date (h1 h2)
4771   "Sort articles by root article date."
4772   (time-less-p
4773    (gnus-date-get-time (mail-header-date h1))
4774    (gnus-date-get-time (mail-header-date h2))))
4775
4776 (defun gnus-thread-sort-by-date (h1 h2)
4777   "Sort threads by root article date."
4778   (gnus-article-sort-by-date
4779    (gnus-thread-header h1) (gnus-thread-header h2)))
4780
4781 (defsubst gnus-article-sort-by-score (h1 h2)
4782   "Sort articles by root article score.
4783 Unscored articles will be counted as having a score of zero."
4784   (> (or (cdr (assq (mail-header-number h1)
4785                     gnus-newsgroup-scored))
4786          gnus-summary-default-score 0)
4787      (or (cdr (assq (mail-header-number h2)
4788                     gnus-newsgroup-scored))
4789          gnus-summary-default-score 0)))
4790
4791 (defun gnus-thread-sort-by-score (h1 h2)
4792   "Sort threads by root article score."
4793   (gnus-article-sort-by-score
4794    (gnus-thread-header h1) (gnus-thread-header h2)))
4795
4796 (defun gnus-thread-sort-by-total-score (h1 h2)
4797   "Sort threads by the sum of all scores in the thread.
4798 Unscored articles will be counted as having a score of zero."
4799   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4800
4801 (defun gnus-thread-total-score (thread)
4802   ;; This function find the total score of THREAD.
4803   (cond
4804    ((null thread)
4805     0)
4806    ((consp thread)
4807     (if (stringp (car thread))
4808         (apply gnus-thread-score-function 0
4809                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4810       (gnus-thread-total-score-1 thread)))
4811    (t
4812     (gnus-thread-total-score-1 (list thread)))))
4813
4814 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4815   "Sort threads such that the thread with the most recently arrived article comes first."
4816   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4817
4818 (defun gnus-thread-highest-number (thread)
4819   "Return the highest article number in THREAD."
4820   (apply 'max (mapcar (lambda (header)
4821                         (mail-header-number header))
4822                       (message-flatten-list thread))))
4823
4824 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4825   "Sort threads such that the thread with the most recently dated article comes first."
4826   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4827
4828 (defun gnus-thread-latest-date (thread)
4829   "Return the highest article date in THREAD."
4830   (let ((previous-time 0))
4831     (apply 'max
4832            (mapcar
4833             (lambda (header)
4834               (setq previous-time
4835                     (condition-case ()
4836                         (time-to-seconds (mail-header-parse-date
4837                                           (mail-header-date header)))
4838                       (error previous-time))))
4839             (sort
4840              (message-flatten-list thread)
4841              (lambda (h1 h2)
4842                (< (mail-header-number h1)
4843                   (mail-header-number h2))))))))
4844
4845 (defun gnus-thread-total-score-1 (root)
4846   ;; This function find the total score of the thread below ROOT.
4847   (setq root (car root))
4848   (apply gnus-thread-score-function
4849          (or (append
4850               (mapcar 'gnus-thread-total-score
4851                       (cdr (gnus-id-to-thread (mail-header-id root))))
4852               (when (> (mail-header-number root) 0)
4853                 (list (or (cdr (assq (mail-header-number root)
4854                                      gnus-newsgroup-scored))
4855                           gnus-summary-default-score 0))))
4856              (list gnus-summary-default-score)
4857              '(0))))
4858
4859 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4860 (defvar gnus-tmp-prev-subject nil)
4861 (defvar gnus-tmp-false-parent nil)
4862 (defvar gnus-tmp-root-expunged nil)
4863 (defvar gnus-tmp-dummy-line nil)
4864
4865 (eval-when-compile (defvar gnus-tmp-header))
4866 (defun gnus-extra-header (type &optional header)
4867   "Return the extra header of TYPE."
4868   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4869       ""))
4870
4871 (defvar gnus-tmp-thread-tree-header-string "")
4872
4873 (defcustom gnus-sum-thread-tree-root "> "
4874   "With %B spec, used for the root of a thread.
4875 If nil, use subject instead."
4876   :version "22.1"
4877   :type '(radio (const :format "%v  " nil) string)
4878   :group 'gnus-thread)
4879
4880 (defcustom gnus-sum-thread-tree-false-root "> "
4881   "With %B spec, used for a false root of a thread.
4882 If nil, use subject instead."
4883   :version "22.1"
4884   :type '(radio (const :format "%v  " nil) string)
4885   :group 'gnus-thread)
4886
4887 (defcustom gnus-sum-thread-tree-single-indent ""
4888   "With %B spec, used for a thread with just one message.
4889 If nil, use subject instead."
4890   :version "22.1"
4891   :type '(radio (const :format "%v  " nil) string)
4892   :group 'gnus-thread)
4893
4894 (defcustom gnus-sum-thread-tree-vertical "| "
4895   "With %B spec, used for drawing a vertical line."
4896   :version "22.1"
4897   :type 'string
4898   :group 'gnus-thread)
4899
4900 (defcustom gnus-sum-thread-tree-indent "  "
4901   "With %B spec, used for indenting."
4902   :version "22.1"
4903   :type 'string
4904   :group 'gnus-thread)
4905
4906 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4907   "With %B spec, used for a leaf with brothers."
4908   :version "22.1"
4909   :type 'string
4910   :group 'gnus-thread)
4911
4912 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4913   "With %B spec, used for a leaf without brothers."
4914   :version "22.1"
4915   :type 'string
4916   :group 'gnus-thread)
4917
4918 (defun gnus-summary-prepare-threads (threads)
4919   "Prepare summary buffer from THREADS and indentation LEVEL.
4920 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4921 or a straight list of headers."
4922   (gnus-message 7 "Generating summary...")
4923
4924   (setq gnus-newsgroup-threads threads)
4925   (beginning-of-line)
4926
4927   (let ((gnus-tmp-level 0)
4928         (default-score (or gnus-summary-default-score 0))
4929         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4930         (building-line-count gnus-summary-display-while-building)
4931         (building-count (integerp gnus-summary-display-while-building))
4932         thread number subject stack state gnus-tmp-gathered beg-match
4933         new-roots gnus-tmp-new-adopts thread-end simp-subject
4934         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4935         gnus-tmp-replied gnus-tmp-subject-or-nil
4936         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4937         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4938         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4939         tree-stack)
4940
4941     (setq gnus-tmp-prev-subject nil
4942           gnus-tmp-thread-tree-header-string "")
4943
4944     (if (vectorp (car threads))
4945         ;; If this is a straight (sic) list of headers, then a
4946         ;; threaded summary display isn't required, so we just create
4947         ;; an unthreaded one.
4948         (gnus-summary-prepare-unthreaded threads)
4949
4950       ;; Do the threaded display.
4951
4952       (if gnus-summary-display-while-building
4953           (switch-to-buffer (buffer-name)))
4954       (while (or threads stack gnus-tmp-new-adopts new-roots)
4955
4956         (if (and (= gnus-tmp-level 0)
4957                  (or (not stack)
4958                      (= (caar stack) 0))
4959                  (not gnus-tmp-false-parent)
4960                  (or gnus-tmp-new-adopts new-roots))
4961             (if gnus-tmp-new-adopts
4962                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4963                       thread (list (car gnus-tmp-new-adopts))
4964                       gnus-tmp-header (caar thread)
4965                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4966               (when new-roots
4967                 (setq thread (list (car new-roots))
4968                       gnus-tmp-header (caar thread)
4969                       new-roots (cdr new-roots))))
4970
4971           (if threads
4972               ;; If there are some threads, we do them before the
4973               ;; threads on the stack.
4974               (setq thread threads
4975                     gnus-tmp-header (caar thread))
4976             ;; There were no current threads, so we pop something off
4977             ;; the stack.
4978             (setq state (car stack)
4979                   gnus-tmp-level (car state)
4980                   tree-stack (cadr state)
4981                   thread (caddr state)
4982                   stack (cdr stack)
4983                   gnus-tmp-header (caar thread))))
4984
4985         (setq gnus-tmp-false-parent nil)
4986         (setq gnus-tmp-root-expunged nil)
4987         (setq thread-end nil)
4988
4989         (if (stringp gnus-tmp-header)
4990             ;; The header is a dummy root.
4991             (cond
4992              ((eq gnus-summary-make-false-root 'adopt)
4993               ;; We let the first article adopt the rest.
4994               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4995                                                (cddar thread)))
4996               (setq gnus-tmp-gathered
4997                     (nconc (mapcar
4998                             (lambda (h) (mail-header-number (car h)))
4999                             (cddar thread))
5000                            gnus-tmp-gathered))
5001               (setq thread (cons (list (caar thread)
5002                                        (cadar thread))
5003                                  (cdr thread)))
5004               (setq gnus-tmp-level -1
5005                     gnus-tmp-false-parent t))
5006              ((eq gnus-summary-make-false-root 'empty)
5007               ;; We print adopted articles with empty subject fields.
5008               (setq gnus-tmp-gathered
5009                     (nconc (mapcar
5010                             (lambda (h) (mail-header-number (car h)))
5011                             (cddar thread))
5012                            gnus-tmp-gathered))
5013               (setq gnus-tmp-level -1))
5014              ((eq gnus-summary-make-false-root 'dummy)
5015               ;; We remember that we probably want to output a dummy
5016               ;; root.
5017               (setq gnus-tmp-dummy-line gnus-tmp-header)
5018               (setq gnus-tmp-prev-subject gnus-tmp-header))
5019              (t
5020               ;; We do not make a root for the gathered
5021               ;; sub-threads at all.
5022               (setq gnus-tmp-level -1)))
5023
5024           (setq number (mail-header-number gnus-tmp-header)
5025                 subject (mail-header-subject gnus-tmp-header)
5026                 simp-subject (gnus-simplify-subject-fully subject))
5027
5028           (cond
5029            ;; If the thread has changed subject, we might want to make
5030            ;; this subthread into a root.
5031            ((and (null gnus-thread-ignore-subject)
5032                  (not (zerop gnus-tmp-level))
5033                  gnus-tmp-prev-subject
5034                  (not (string= gnus-tmp-prev-subject simp-subject)))
5035             (setq new-roots (nconc new-roots (list (car thread)))
5036                   thread-end t
5037                   gnus-tmp-header nil))
5038            ;; If the article lies outside the current limit,
5039            ;; then we do not display it.
5040            ((not (memq number gnus-newsgroup-limit))
5041             (setq gnus-tmp-gathered
5042                   (nconc (mapcar
5043                           (lambda (h) (mail-header-number (car h)))
5044                           (cdar thread))
5045                          gnus-tmp-gathered))
5046             (setq gnus-tmp-new-adopts (if (cdar thread)
5047                                           (append gnus-tmp-new-adopts
5048                                                   (cdar thread))
5049                                         gnus-tmp-new-adopts)
5050                   thread-end t
5051                   gnus-tmp-header nil)
5052             (when (zerop gnus-tmp-level)
5053               (setq gnus-tmp-root-expunged t)))
5054            ;; Perhaps this article is to be marked as read?
5055            ((and gnus-summary-mark-below
5056                  (< (or (cdr (assq number gnus-newsgroup-scored))
5057                         default-score)
5058                     gnus-summary-mark-below)
5059                  ;; Don't touch sparse articles.
5060                  (not (gnus-summary-article-sparse-p number))
5061                  (not (gnus-summary-article-ancient-p number)))
5062             (setq gnus-newsgroup-unreads
5063                   (delq number gnus-newsgroup-unreads))
5064             (if gnus-newsgroup-auto-expire
5065                 (setq gnus-newsgroup-expirable
5066                       (gnus-add-to-sorted-list
5067                        gnus-newsgroup-expirable number))
5068               (push (cons number gnus-low-score-mark)
5069                     gnus-newsgroup-reads))))
5070
5071           (when gnus-tmp-header
5072             ;; We may have an old dummy line to output before this
5073             ;; article.
5074             (when (and gnus-tmp-dummy-line
5075                        (gnus-subject-equal
5076                         gnus-tmp-dummy-line
5077                         (mail-header-subject gnus-tmp-header)))
5078               (gnus-summary-insert-dummy-line
5079                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5080               (setq gnus-tmp-dummy-line nil))
5081
5082             ;; Compute the mark.
5083             (setq gnus-tmp-unread (gnus-article-mark number))
5084
5085             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5086                                   gnus-tmp-header gnus-tmp-level)
5087                   gnus-newsgroup-data)
5088
5089             ;; Actually insert the line.
5090             (setq
5091              gnus-tmp-subject-or-nil
5092              (cond
5093               ((and gnus-thread-ignore-subject
5094                     gnus-tmp-prev-subject
5095                     (not (string= gnus-tmp-prev-subject simp-subject)))
5096                subject)
5097               ((zerop gnus-tmp-level)
5098                (if (and (eq gnus-summary-make-false-root 'empty)
5099                         (memq number gnus-tmp-gathered)
5100                         gnus-tmp-prev-subject
5101                         (string= gnus-tmp-prev-subject simp-subject))
5102                    gnus-summary-same-subject
5103                  subject))
5104               (t gnus-summary-same-subject)))
5105             (if (and (eq gnus-summary-make-false-root 'adopt)
5106                      (= gnus-tmp-level 1)
5107                      (memq number gnus-tmp-gathered))
5108                 (setq gnus-tmp-opening-bracket ?\<
5109                       gnus-tmp-closing-bracket ?\>)
5110               (setq gnus-tmp-opening-bracket ?\[
5111                     gnus-tmp-closing-bracket ?\]))
5112             (setq
5113              gnus-tmp-indentation
5114              (aref gnus-thread-indent-array gnus-tmp-level)
5115              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5116              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5117                                 gnus-summary-default-score 0)
5118              gnus-tmp-score-char
5119              (if (or (null gnus-summary-default-score)
5120                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5121                          gnus-summary-zcore-fuzz))
5122                  ?                      ;Whitespace
5123                (if (< gnus-tmp-score gnus-summary-default-score)
5124                    gnus-score-below-mark gnus-score-over-mark))
5125              gnus-tmp-replied
5126              (cond ((memq number gnus-newsgroup-processable)
5127                     gnus-process-mark)
5128                    ((memq number gnus-newsgroup-cached)
5129                     gnus-cached-mark)
5130                    ((memq number gnus-newsgroup-replied)
5131                     gnus-replied-mark)
5132                    ((memq number gnus-newsgroup-forwarded)
5133                     gnus-forwarded-mark)
5134                    ((memq number gnus-newsgroup-saved)
5135                     gnus-saved-mark)
5136                    ((memq number gnus-newsgroup-recent)
5137                     gnus-recent-mark)
5138                    ((memq number gnus-newsgroup-unseen)
5139                     gnus-unseen-mark)
5140                    (t gnus-no-mark))
5141              gnus-tmp-downloaded
5142              (cond ((memq number gnus-newsgroup-undownloaded)
5143                     gnus-undownloaded-mark)
5144                    (gnus-newsgroup-agentized
5145                     gnus-downloaded-mark)
5146                    (t
5147                     gnus-no-mark))
5148              gnus-tmp-from (mail-header-from gnus-tmp-header)
5149              gnus-tmp-name
5150              (cond
5151               ((string-match "<[^>]+> *$" gnus-tmp-from)
5152                (setq beg-match (match-beginning 0))
5153                (or (and (string-match "^\".+\"" gnus-tmp-from)
5154                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5155                    (substring gnus-tmp-from 0 beg-match)))
5156               ((string-match "(.+)" gnus-tmp-from)
5157                (substring gnus-tmp-from
5158                           (1+ (match-beginning 0)) (1- (match-end 0))))
5159               (t gnus-tmp-from))
5160
5161              ;; Do the %B string
5162              gnus-tmp-thread-tree-header-string
5163              (cond
5164               ((not gnus-show-threads) "")
5165               ((zerop gnus-tmp-level)
5166                (cond ((cdar thread)
5167                       (or gnus-sum-thread-tree-root subject))
5168                      (gnus-tmp-new-adopts
5169                       (or gnus-sum-thread-tree-false-root subject))
5170                      (t
5171                       (or gnus-sum-thread-tree-single-indent subject))))
5172               (t
5173                (concat (apply 'concat
5174                               (mapcar (lambda (item)
5175                                         (if (= item 1)
5176                                             gnus-sum-thread-tree-vertical
5177                                           gnus-sum-thread-tree-indent))
5178                                       (cdr (reverse tree-stack))))
5179                        (if (nth 1 thread)
5180                            gnus-sum-thread-tree-leaf-with-other
5181                          gnus-sum-thread-tree-single-leaf)))))
5182             (when (string= gnus-tmp-name "")
5183               (setq gnus-tmp-name gnus-tmp-from))
5184             (unless (numberp gnus-tmp-lines)
5185               (setq gnus-tmp-lines -1))
5186             (if (= gnus-tmp-lines -1)
5187                 (setq gnus-tmp-lines "?")
5188               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5189               (gnus-put-text-property
5190              (point)
5191              (progn (eval gnus-summary-line-format-spec) (point))
5192                'gnus-number number)
5193             (when gnus-visual-p
5194               (forward-line -1)
5195               (gnus-run-hooks 'gnus-summary-update-hook)
5196               (forward-line 1))
5197
5198             (setq gnus-tmp-prev-subject simp-subject)))
5199
5200         (when (nth 1 thread)
5201           (push (list (max 0 gnus-tmp-level)
5202                       (copy-sequence tree-stack)
5203                       (nthcdr 1 thread))
5204                 stack))
5205         (push (if (nth 1 thread) 1 0) tree-stack)
5206         (incf gnus-tmp-level)
5207         (setq threads (if thread-end nil (cdar thread)))
5208         (if gnus-summary-display-while-building
5209             (if building-count
5210                 (progn
5211                   ;; use a set frequency
5212                   (setq building-line-count (1- building-line-count))
5213                   (when (= building-line-count 0)
5214                     (sit-for 0)
5215                     (setq building-line-count
5216                           gnus-summary-display-while-building)))
5217               ;; always
5218               (sit-for 0)))
5219         (unless threads
5220           (setq gnus-tmp-level 0)))))
5221   (gnus-message 7 "Generating summary...done"))
5222
5223 (defun gnus-summary-prepare-unthreaded (headers)
5224   "Generate an unthreaded summary buffer based on HEADERS."
5225   (let (header number mark)
5226
5227     (beginning-of-line)
5228
5229     (while headers
5230       ;; We may have to root out some bad articles...
5231       (when (memq (setq number (mail-header-number
5232                                 (setq header (pop headers))))
5233                   gnus-newsgroup-limit)
5234         ;; Mark article as read when it has a low score.
5235         (when (and gnus-summary-mark-below
5236                    (< (or (cdr (assq number gnus-newsgroup-scored))
5237                           gnus-summary-default-score 0)
5238                       gnus-summary-mark-below)
5239                    (not (gnus-summary-article-ancient-p number)))
5240           (setq gnus-newsgroup-unreads
5241                 (delq number gnus-newsgroup-unreads))
5242           (if gnus-newsgroup-auto-expire
5243               (push number gnus-newsgroup-expirable)
5244             (push (cons number gnus-low-score-mark)
5245                   gnus-newsgroup-reads)))
5246
5247         (setq mark (gnus-article-mark number))
5248         (push (gnus-data-make number mark (1+ (point)) header 0)
5249               gnus-newsgroup-data)
5250         (gnus-summary-insert-line
5251          header 0 number
5252          (memq number gnus-newsgroup-undownloaded)
5253          mark (memq number gnus-newsgroup-replied)
5254          (memq number gnus-newsgroup-expirable)
5255          (mail-header-subject header) nil
5256          (cdr (assq number gnus-newsgroup-scored))
5257          (memq number gnus-newsgroup-processable))))))
5258
5259 (defun gnus-summary-remove-list-identifiers ()
5260   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5261   (let ((regexp (if (consp gnus-list-identifiers)
5262                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5263                   gnus-list-identifiers))
5264         changed subject)
5265     (when regexp
5266       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5267       (dolist (header gnus-newsgroup-headers)
5268         (setq subject (mail-header-subject header)
5269               changed nil)
5270         (while (string-match regexp subject)
5271           (setq subject
5272                 (concat (substring subject 0 (match-beginning 1))
5273                         (substring subject (match-end 0)))
5274                 changed t))
5275         (when changed
5276           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5277             (setq subject
5278                   (concat (substring subject 0 (match-beginning 1))
5279                           (substring subject (match-end 1)))))
5280           (mail-header-set-subject header subject))))))
5281
5282 (defun gnus-fetch-headers (articles)
5283   "Fetch headers of ARTICLES."
5284   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5285     (gnus-message 5 "Fetching headers for %s..." name)
5286     (prog1
5287         (if (eq 'nov
5288                 (setq gnus-headers-retrieved-by
5289                       (gnus-retrieve-headers
5290                        articles gnus-newsgroup-name
5291                        ;; We might want to fetch old headers, but
5292                        ;; not if there is only 1 article.
5293                        (and (or (and
5294                                  (not (eq gnus-fetch-old-headers 'some))
5295                                  (not (numberp gnus-fetch-old-headers)))
5296                                 (> (length articles) 1))
5297                             gnus-fetch-old-headers))))
5298             (gnus-get-newsgroup-headers-xover
5299              articles nil nil gnus-newsgroup-name t)
5300           (gnus-get-newsgroup-headers))
5301       (gnus-message 5 "Fetching headers for %s...done" name))))
5302
5303 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5304   "Select newsgroup GROUP.
5305 If READ-ALL is non-nil, all articles in the group are selected.
5306 If SELECT-ARTICLES, only select those articles from GROUP."
5307   (let* ((entry (gnus-group-entry group))
5308          ;;!!! Dirty hack; should be removed.
5309          (gnus-summary-ignore-duplicates
5310           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5311               t
5312             gnus-summary-ignore-duplicates))
5313          (info (nth 2 entry))
5314          articles fetched-articles cached)
5315
5316     (unless (gnus-check-server
5317              (set (make-local-variable 'gnus-current-select-method)
5318                   (gnus-find-method-for-group group)))
5319       (error "Couldn't open server"))
5320
5321     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5322         (gnus-activate-group group)     ; Or we can activate it...
5323         (progn                          ; Or we bug out.
5324           (when (equal major-mode 'gnus-summary-mode)
5325             (gnus-kill-buffer (current-buffer)))
5326           (error "Couldn't activate group %s: %s"
5327                  group (gnus-status-message group))))
5328
5329     (unless (gnus-request-group group t)
5330       (when (equal major-mode 'gnus-summary-mode)
5331         (gnus-kill-buffer (current-buffer)))
5332       (error "Couldn't request group %s: %s"
5333              group (gnus-status-message group)))
5334
5335     (when gnus-agent
5336       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5337
5338       (setq gnus-summary-use-undownloaded-faces
5339             (gnus-agent-find-parameter
5340              group
5341              'agent-enable-undownloaded-faces)))
5342
5343     (setq gnus-newsgroup-name group
5344           gnus-newsgroup-unselected nil
5345           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5346
5347     (let ((display (gnus-group-find-parameter group 'display)))
5348       (setq gnus-newsgroup-display
5349             (cond
5350              ((not (zerop (or (car-safe read-all) 0)))
5351               ;; The user entered the group with C-u SPC/RET, let's show
5352               ;; all articles.
5353               'gnus-not-ignore)
5354              ((eq display 'all)
5355               'gnus-not-ignore)
5356              ((arrayp display)
5357               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5358              ((numberp display)
5359               ;; The following is probably the "correct" solution, but
5360               ;; it makes Gnus fetch all headers and then limit the
5361               ;; articles (which is slow), so instead we hack the
5362               ;; select-articles parameter instead. -- Simon Josefsson
5363               ;; <jas@kth.se>
5364               ;;
5365               ;; (gnus-byte-compile
5366               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5367               ;;                         display)))))
5368               (setq select-articles
5369                     (gnus-uncompress-range
5370                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5371                              (if (> tmp 0)
5372                                  tmp
5373                                1))
5374                            (cdr (gnus-active group)))))
5375               nil)
5376              (t
5377               nil))))
5378
5379     (gnus-summary-setup-default-charset)
5380
5381     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5382     (when (gnus-virtual-group-p group)
5383       (setq cached gnus-newsgroup-cached))
5384
5385     (setq gnus-newsgroup-unreads
5386           (gnus-sorted-ndifference
5387            (gnus-sorted-ndifference gnus-newsgroup-unreads
5388                                     gnus-newsgroup-marked)
5389            gnus-newsgroup-dormant))
5390
5391     (setq gnus-newsgroup-processable nil)
5392
5393     (gnus-update-read-articles group gnus-newsgroup-unreads)
5394
5395     ;; Adjust and set lists of article marks.
5396     (when info
5397       (gnus-adjust-marked-articles info))
5398     (if (setq articles select-articles)
5399         (setq gnus-newsgroup-unselected
5400               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5401       (setq articles (gnus-articles-to-read group read-all)))
5402
5403     (cond
5404      ((null articles)
5405       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5406       'quit)
5407      ((eq articles 0) nil)
5408      (t
5409       ;; Init the dependencies hash table.
5410       (setq gnus-newsgroup-dependencies
5411             (gnus-make-hashtable (length articles)))
5412       (gnus-set-global-variables)
5413       ;; Retrieve the headers and read them in.
5414
5415       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5416
5417       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5418       (when cached
5419         (setq gnus-newsgroup-cached cached))
5420
5421       ;; Suppress duplicates?
5422       (when gnus-suppress-duplicates
5423         (gnus-dup-suppress-articles))
5424
5425       ;; Set the initial limit.
5426       (setq gnus-newsgroup-limit (copy-sequence articles))
5427       ;; Remove canceled articles from the list of unread articles.
5428       (setq fetched-articles
5429             (mapcar (lambda (headers) (mail-header-number headers))
5430                     gnus-newsgroup-headers))
5431       (setq gnus-newsgroup-articles fetched-articles)
5432       (setq gnus-newsgroup-unreads
5433             (gnus-sorted-nintersection
5434              gnus-newsgroup-unreads fetched-articles))
5435       (gnus-compute-unseen-list)
5436
5437       ;; Removed marked articles that do not exist.
5438       (gnus-update-missing-marks
5439        (gnus-sorted-difference articles fetched-articles))
5440       ;; We might want to build some more threads first.
5441       (when (and gnus-fetch-old-headers
5442                  (eq gnus-headers-retrieved-by 'nov))
5443         (if (eq gnus-fetch-old-headers 'invisible)
5444             (gnus-build-all-threads)
5445           (gnus-build-old-threads)))
5446       ;; Let the Gnus agent mark articles as read.
5447       (when gnus-agent
5448         (gnus-agent-get-undownloaded-list))
5449       ;; Remove list identifiers from subject
5450       (when gnus-list-identifiers
5451         (gnus-summary-remove-list-identifiers))
5452       ;; Check whether auto-expire is to be done in this group.
5453       (setq gnus-newsgroup-auto-expire
5454             (gnus-group-auto-expirable-p group))
5455       ;; Set up the article buffer now, if necessary.
5456       (unless gnus-single-article-buffer
5457         (gnus-article-setup-buffer))
5458       ;; First and last article in this newsgroup.
5459       (when gnus-newsgroup-headers
5460         (setq gnus-newsgroup-begin
5461               (mail-header-number (car gnus-newsgroup-headers))
5462               gnus-newsgroup-end
5463               (mail-header-number
5464                (gnus-last-element gnus-newsgroup-headers))))
5465       ;; GROUP is successfully selected.
5466       (or gnus-newsgroup-headers t)))))
5467
5468 (defun gnus-compute-unseen-list ()
5469   ;; The `seen' marks are treated specially.
5470   (if (not gnus-newsgroup-seen)
5471       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5472     (setq gnus-newsgroup-unseen
5473           (gnus-inverse-list-range-intersection
5474            gnus-newsgroup-articles gnus-newsgroup-seen))))
5475
5476 (defun gnus-summary-display-make-predicate (display)
5477   (require 'gnus-agent)
5478   (when (= (length display) 1)
5479     (setq display (car display)))
5480   (unless gnus-summary-display-cache
5481     (dolist (elem (append '((unread . unread)
5482                             (read . read)
5483                             (unseen . unseen))
5484                           gnus-article-mark-lists))
5485       (push (cons (cdr elem)
5486                   (gnus-byte-compile
5487                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5488             gnus-summary-display-cache)))
5489   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5490         (gnus-category-predicate-cache gnus-summary-display-cache))
5491     (gnus-get-predicate display)))
5492
5493 ;; Uses the dynamically bound `number' variable.
5494 (eval-when-compile
5495   (defvar number))
5496 (defun gnus-article-marked-p (type &optional article)
5497   (let ((article (or article number)))
5498     (cond
5499      ((eq type 'tick)
5500       (memq article gnus-newsgroup-marked))
5501      ((eq type 'spam)
5502       (memq article gnus-newsgroup-spam-marked))
5503      ((eq type 'unsend)
5504       (memq article gnus-newsgroup-unsendable))
5505      ((eq type 'undownload)
5506       (memq article gnus-newsgroup-undownloaded))
5507      ((eq type 'download)
5508       (memq article gnus-newsgroup-downloadable))
5509      ((eq type 'unread)
5510       (memq article gnus-newsgroup-unreads))
5511      ((eq type 'read)
5512       (memq article gnus-newsgroup-reads))
5513      ((eq type 'dormant)
5514       (memq article gnus-newsgroup-dormant) )
5515      ((eq type 'expire)
5516       (memq article gnus-newsgroup-expirable))
5517      ((eq type 'reply)
5518       (memq article gnus-newsgroup-replied))
5519      ((eq type 'killed)
5520       (memq article gnus-newsgroup-killed))
5521      ((eq type 'bookmark)
5522       (assq article gnus-newsgroup-bookmarks))
5523      ((eq type 'score)
5524       (assq article gnus-newsgroup-scored))
5525      ((eq type 'save)
5526       (memq article gnus-newsgroup-saved))
5527      ((eq type 'cache)
5528       (memq article gnus-newsgroup-cached))
5529      ((eq type 'forward)
5530       (memq article gnus-newsgroup-forwarded))
5531      ((eq type 'seen)
5532       (not (memq article gnus-newsgroup-unseen)))
5533      ((eq type 'recent)
5534       (memq article gnus-newsgroup-recent))
5535      (t t))))
5536
5537 (defun gnus-articles-to-read (group &optional read-all)
5538   "Find out what articles the user wants to read."
5539   (let* ((articles
5540           ;; Select all articles if `read-all' is non-nil, or if there
5541           ;; are no unread articles.
5542           (if (or read-all
5543                   (and (zerop (length gnus-newsgroup-marked))
5544                        (zerop (length gnus-newsgroup-unreads)))
5545                   ;; Fetch all if the predicate is non-nil.
5546                   gnus-newsgroup-display)
5547               ;; We want to select the headers for all the articles in
5548               ;; the group, so we select either all the active
5549               ;; articles in the group, or (if that's nil), the
5550               ;; articles in the cache.
5551               (or
5552                (gnus-uncompress-range (gnus-active group))
5553                (gnus-cache-articles-in-group group))
5554             ;; Select only the "normal" subset of articles.
5555             (gnus-sorted-nunion
5556              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5557              gnus-newsgroup-unreads)))
5558          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5559          (scored (length scored-list))
5560          (number (length articles))
5561          (marked (+ (length gnus-newsgroup-marked)
5562                     (length gnus-newsgroup-dormant)))
5563          (select
5564           (cond
5565            ((numberp read-all)
5566             read-all)
5567            ((numberp gnus-newsgroup-display)
5568             gnus-newsgroup-display)
5569            (t
5570             (condition-case ()
5571                 (cond
5572                  ((and (or (<= scored marked) (= scored number))
5573                        (numberp gnus-large-newsgroup)
5574                        (> number gnus-large-newsgroup))
5575                   (let* ((cursor-in-echo-area nil)
5576                          (initial (gnus-parameter-large-newsgroup-initial
5577                                    gnus-newsgroup-name))
5578                          (input
5579                           (read-string
5580                            (format
5581                             "How many articles from %s (%s %d): "
5582                             (gnus-limit-string
5583                              (gnus-group-decoded-name gnus-newsgroup-name)
5584                              35)
5585                             (if initial "max" "default")
5586                             number)
5587                            (if initial
5588                                (cons (number-to-string initial)
5589                                      0)))))
5590                     (if (string-match "^[ \t]*$" input) number input)))
5591                  ((and (> scored marked) (< scored number)
5592                        (> (- scored number) 20))
5593                   (let ((input
5594                          (read-string
5595                           (format "%s %s (%d scored, %d total): "
5596                                   "How many articles from"
5597                                   (gnus-group-decoded-name group)
5598                                   scored number))))
5599                     (if (string-match "^[ \t]*$" input)
5600                         number input)))
5601                  (t number))
5602               (quit
5603                (message "Quit getting the articles to read")
5604                nil))))))
5605     (setq select (if (stringp select) (string-to-number select) select))
5606     (if (or (null select) (zerop select))
5607         select
5608       (if (and (not (zerop scored)) (<= (abs select) scored))
5609           (progn
5610             (setq articles (sort scored-list '<))
5611             (setq number (length articles)))
5612         (setq articles (copy-sequence articles)))
5613
5614       (when (< (abs select) number)
5615         (if (< select 0)
5616             ;; Select the N oldest articles.
5617             (setcdr (nthcdr (1- (abs select)) articles) nil)
5618           ;; Select the N most recent articles.
5619           (setq articles (nthcdr (- number select) articles))))
5620       (setq gnus-newsgroup-unselected
5621             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5622       (when gnus-alter-articles-to-read-function
5623         (setq articles
5624               (sort
5625                (funcall gnus-alter-articles-to-read-function
5626                         gnus-newsgroup-name articles)
5627                '<)))
5628       articles)))
5629
5630 (defun gnus-killed-articles (killed articles)
5631   (let (out)
5632     (while articles
5633       (when (inline (gnus-member-of-range (car articles) killed))
5634         (push (car articles) out))
5635       (setq articles (cdr articles)))
5636     out))
5637
5638 (defun gnus-uncompress-marks (marks)
5639   "Uncompress the mark ranges in MARKS."
5640   (let ((uncompressed '(score bookmark))
5641         out)
5642     (while marks
5643       (if (memq (caar marks) uncompressed)
5644           (push (car marks) out)
5645         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5646       (setq marks (cdr marks)))
5647     out))
5648
5649 (defun gnus-article-mark-to-type (mark)
5650   "Return the type of MARK."
5651   (or (cadr (assq mark gnus-article-special-mark-lists))
5652       'list))
5653
5654 (defun gnus-article-unpropagatable-p (mark)
5655   "Return whether MARK should be propagated to back end."
5656   (memq mark gnus-article-unpropagated-mark-lists))
5657
5658 (defun gnus-adjust-marked-articles (info)
5659   "Set all article lists and remove all marks that are no longer valid."
5660   (let* ((marked-lists (gnus-info-marks info))
5661          (active (gnus-active (gnus-info-group info)))
5662          (min (car active))
5663          (max (cdr active))
5664          (types gnus-article-mark-lists)
5665          marks var articles article mark mark-type
5666          bgn end)
5667
5668     (dolist (marks marked-lists)
5669       (setq mark (car marks)
5670             mark-type (gnus-article-mark-to-type mark)
5671             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5672
5673       ;; We set the variable according to the type of the marks list,
5674       ;; and then adjust the marks to a subset of the active articles.
5675       (cond
5676        ;; Adjust "simple" lists - compressed yet unsorted
5677        ((eq mark-type 'list)
5678         ;; Simultaneously uncompress and clip to active range
5679         ;; See gnus-uncompress-range for a description of possible marks
5680         (let (l lh)
5681           (if (not (cadr marks))
5682               (set var nil)
5683             (setq articles (if (numberp (cddr marks))
5684                                (list (cdr marks))
5685                              (cdr marks))
5686                   lh (cons nil nil)
5687                   l lh)
5688
5689             (while (setq article (pop articles))
5690               (cond ((consp article)
5691                      (setq bgn (max (car article) min)
5692                            end (min (cdr article) max))
5693                      (while (<= bgn end)
5694                        (setq l (setcdr l (cons bgn nil))
5695                              bgn (1+ bgn))))
5696                     ((and (<= min article)
5697                           (>= max article))
5698                      (setq l (setcdr l (cons article nil))))))
5699             (set var (cdr lh)))))
5700        ;; Adjust assocs.
5701        ((eq mark-type 'tuple)
5702         (set var (setq articles (cdr marks)))
5703         (when (not (listp (cdr (symbol-value var))))
5704           (set var (list (symbol-value var))))
5705         (when (not (listp (cdr articles)))
5706           (setq articles (list articles)))
5707         (while articles
5708           (when (or (not (consp (setq article (pop articles))))
5709                     (< (car article) min)
5710                     (> (car article) max))
5711             (set var (delq article (symbol-value var))))))
5712        ;; Adjust ranges (sloppily).
5713        ((eq mark-type 'range)
5714         (cond
5715          ((eq mark 'seen)
5716           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5717           ;; It should be (seen (NUM1 . NUM2)).
5718           (when (numberp (cddr marks))
5719             (setcdr marks (list (cdr marks))))
5720           (setq articles (cdr marks))
5721           (while (and articles
5722                       (or (and (consp (car articles))
5723                                (> min (cdar articles)))
5724                           (and (numberp (car articles))
5725                                (> min (car articles)))))
5726             (pop articles))
5727           (set var articles))))))))
5728
5729 (defun gnus-update-missing-marks (missing)
5730   "Go through the list of MISSING articles and remove them from the mark lists."
5731   (when missing
5732     (let (var m)
5733       ;; Go through all types.
5734       (dolist (elem gnus-article-mark-lists)
5735         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5736           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5737           (when (symbol-value var)
5738             ;; This list has articles.  So we delete all missing
5739             ;; articles from it.
5740             (setq m missing)
5741             (while m
5742               (set var (delq (pop m) (symbol-value var))))))))))
5743
5744 (defun gnus-update-marks ()
5745   "Enter the various lists of marked articles into the newsgroup info list."
5746   (let ((types gnus-article-mark-lists)
5747         (info (gnus-get-info gnus-newsgroup-name))
5748         type list newmarked symbol delta-marks)
5749     (when info
5750       ;; Add all marks lists to the list of marks lists.
5751       (while (setq type (pop types))
5752         (setq list (symbol-value
5753                     (setq symbol
5754                           (intern (format "gnus-newsgroup-%s" (car type))))))
5755
5756         (when list
5757           ;; Get rid of the entries of the articles that have the
5758           ;; default score.
5759           (when (and (eq (cdr type) 'score)
5760                      gnus-save-score
5761                      list)
5762             (let* ((arts list)
5763                    (prev (cons nil list))
5764                    (all prev))
5765               (while arts
5766                 (if (or (not (consp (car arts)))
5767                         (= (cdar arts) gnus-summary-default-score))
5768                     (setcdr prev (cdr arts))
5769                   (setq prev arts))
5770                 (setq arts (cdr arts)))
5771               (setq list (cdr all)))))
5772
5773         (when (eq (cdr type) 'seen)
5774           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5775
5776         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5777           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5778
5779         (when (and (gnus-check-backend-function
5780                     'request-set-mark gnus-newsgroup-name)
5781                    (not (gnus-article-unpropagatable-p (cdr type))))
5782           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5783                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5784                  (add (gnus-remove-from-range
5785                        (gnus-copy-sequence list) old)))
5786             (when add
5787               (push (list add 'add (list (cdr type))) delta-marks))
5788             (when del
5789               (push (list del 'del (list (cdr type))) delta-marks))))
5790
5791         (when list
5792           (push (cons (cdr type) list) newmarked)))
5793
5794       (when delta-marks
5795         (unless (gnus-check-group gnus-newsgroup-name)
5796           (error "Can't open server for %s" gnus-newsgroup-name))
5797         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5798
5799       ;; Enter these new marks into the info of the group.
5800       (if (nthcdr 3 info)
5801           (setcar (nthcdr 3 info) newmarked)
5802         ;; Add the marks lists to the end of the info.
5803         (when newmarked
5804           (setcdr (nthcdr 2 info) (list newmarked))))
5805
5806       ;; Cut off the end of the info if there's nothing else there.
5807       (let ((i 5))
5808         (while (and (> i 2)
5809                     (not (nth i info)))
5810           (when (nthcdr (decf i) info)
5811             (setcdr (nthcdr i info) nil)))))))
5812
5813 (defun gnus-set-mode-line (where)
5814   "Set the mode line of the article or summary buffers.
5815 If WHERE is `summary', the summary mode line format will be used."
5816   ;; Is this mode line one we keep updated?
5817   (when (and (memq where gnus-updated-mode-lines)
5818              (symbol-value
5819               (intern (format "gnus-%s-mode-line-format-spec" where))))
5820     (let (mode-string)
5821       (save-excursion
5822         ;; We evaluate this in the summary buffer since these
5823         ;; variables are buffer-local to that buffer.
5824         (set-buffer gnus-summary-buffer)
5825        ;; We bind all these variables that are used in the `eval' form
5826         ;; below.
5827         (let* ((mformat (symbol-value
5828                          (intern
5829                           (format "gnus-%s-mode-line-format-spec" where))))
5830                (gnus-tmp-group-name (gnus-group-decoded-name
5831                                      gnus-newsgroup-name))
5832                (gnus-tmp-article-number (or gnus-current-article 0))
5833                (gnus-tmp-unread gnus-newsgroup-unreads)
5834                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5835                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5836                (gnus-tmp-unread-and-unselected
5837                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5838                             (zerop gnus-tmp-unselected))
5839                        "")
5840                       ((zerop gnus-tmp-unselected)
5841                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5842                       (t (format "{%d(+%d) more}"
5843                                  gnus-tmp-unread-and-unticked
5844                                  gnus-tmp-unselected))))
5845                (gnus-tmp-subject
5846                 (if (and gnus-current-headers
5847                          (vectorp gnus-current-headers))
5848                     (gnus-mode-string-quote
5849                      (mail-header-subject gnus-current-headers))
5850                   ""))
5851                bufname-length max-len
5852                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5853           (setq mode-string (eval mformat))
5854           (setq bufname-length (if (string-match "%b" mode-string)
5855                                    (- (length
5856                                        (buffer-name
5857                                         (if (eq where 'summary)
5858                                             nil
5859                                           (get-buffer gnus-article-buffer))))
5860                                       2)
5861                                  0))
5862           (setq max-len (max 4 (if gnus-mode-non-string-length
5863                                    (- (window-width)
5864                                       gnus-mode-non-string-length
5865                                       bufname-length)
5866                                  (length mode-string))))
5867           ;; We might have to chop a bit of the string off...
5868           (when (> (length mode-string) max-len)
5869             (setq mode-string
5870                   (concat (truncate-string-to-width mode-string (- max-len 3))
5871                           "...")))
5872           ;; Pad the mode string a bit.
5873           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5874       ;; Update the mode line.
5875       (setq mode-line-buffer-identification
5876             (gnus-mode-line-buffer-identification (list mode-string)))
5877       (set-buffer-modified-p t))))
5878
5879 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5880   "Go through the HEADERS list and add all Xrefs to a hash table.
5881 The resulting hash table is returned, or nil if no Xrefs were found."
5882   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5883          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5884          (xref-hashtb (gnus-make-hashtable))
5885          start group entry number xrefs header)
5886     (while headers
5887       (setq header (pop headers))
5888       (when (and (setq xrefs (mail-header-xref header))
5889                  (not (memq (setq number (mail-header-number header))
5890                             unreads)))
5891         (setq start 0)
5892         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5893           (setq start (match-end 0))
5894           (setq group (if prefix
5895                           (concat prefix (substring xrefs (match-beginning 1)
5896                                                     (match-end 1)))
5897                         (substring xrefs (match-beginning 1) (match-end 1))))
5898           (setq number
5899                 (string-to-number (substring xrefs (match-beginning 2)
5900                                           (match-end 2))))
5901           (if (setq entry (gnus-gethash group xref-hashtb))
5902               (setcdr entry (cons number (cdr entry)))
5903             (gnus-sethash group (cons number nil) xref-hashtb)))))
5904     (and start xref-hashtb)))
5905
5906 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5907   "Look through all the headers and mark the Xrefs as read."
5908   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5909         name info xref-hashtb idlist method nth4)
5910     (save-excursion
5911       (set-buffer gnus-group-buffer)
5912       (when (setq xref-hashtb
5913                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5914         (mapatoms
5915          (lambda (group)
5916            (unless (string= from-newsgroup (setq name (symbol-name group)))
5917              (setq idlist (symbol-value group))
5918              ;; Dead groups are not updated.
5919              (and (prog1
5920                       (setq info (gnus-get-info name))
5921                     (when (stringp (setq nth4 (gnus-info-method info)))
5922                       (setq nth4 (gnus-server-to-method nth4))))
5923                   ;; Only do the xrefs if the group has the same
5924                   ;; select method as the group we have just read.
5925                   (or (gnus-methods-equal-p
5926                        nth4 (gnus-find-method-for-group from-newsgroup))
5927                       virtual
5928                       (equal nth4 (setq method (gnus-find-method-for-group
5929                                                 from-newsgroup)))
5930                       (and (equal (car nth4) (car method))
5931                            (equal (nth 1 nth4) (nth 1 method))))
5932                   gnus-use-cross-reference
5933                   (or (not (eq gnus-use-cross-reference t))
5934                       virtual
5935                       ;; Only do cross-references on subscribed
5936                       ;; groups, if that is what is wanted.
5937                       (<= (gnus-info-level info) gnus-level-subscribed))
5938                   (gnus-group-make-articles-read name idlist))))
5939          xref-hashtb)))))
5940
5941 (defun gnus-compute-read-articles (group articles)
5942   (let* ((entry (gnus-group-entry group))
5943          (info (nth 2 entry))
5944          (active (gnus-active group))
5945          ninfo)
5946     (when entry
5947       ;; First peel off all invalid article numbers.
5948       (when active
5949         (let ((ids articles)
5950               id first)
5951           (while (setq id (pop ids))
5952             (when (and first (> id (cdr active)))
5953               ;; We'll end up in this situation in one particular
5954               ;; obscure situation.  If you re-scan a group and get
5955               ;; a new article that is cross-posted to a different
5956               ;; group that has not been re-scanned, you might get
5957               ;; crossposted article that has a higher number than
5958               ;; Gnus believes possible.  So we re-activate this
5959               ;; group as well.  This might mean doing the
5960               ;; crossposting thingy will *increase* the number
5961               ;; of articles in some groups.  Tsk, tsk.
5962               (setq active (or (gnus-activate-group group) active)))
5963             (when (or (> id (cdr active))
5964                       (< id (car active)))
5965               (setq articles (delq id articles))))))
5966       ;; If the read list is nil, we init it.
5967       (if (and active
5968                (null (gnus-info-read info))
5969                (> (car active) 1))
5970           (setq ninfo (cons 1 (1- (car active))))
5971         (setq ninfo (gnus-info-read info)))
5972       ;; Then we add the read articles to the range.
5973       (gnus-add-to-range
5974        ninfo (setq articles (sort articles '<))))))
5975
5976 (defun gnus-group-make-articles-read (group articles)
5977   "Update the info of GROUP to say that ARTICLES are read."
5978   (let* ((num 0)
5979          (entry (gnus-group-entry group))
5980          (info (nth 2 entry))
5981          (active (gnus-active group))
5982          range)
5983     (when entry
5984       (setq range (gnus-compute-read-articles group articles))
5985       (with-current-buffer gnus-group-buffer
5986         (gnus-undo-register
5987           `(progn
5988              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5989              (gnus-info-set-read ',info ',(gnus-info-read info))
5990              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5991              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5992              (gnus-group-update-group ,group t))))
5993       ;; Add the read articles to the range.
5994       (gnus-info-set-read info range)
5995       (gnus-request-set-mark group (list (list range 'add '(read))))
5996       ;; Then we have to re-compute how many unread
5997       ;; articles there are in this group.
5998       (when active
5999         (cond
6000          ((not range)
6001           (setq num (- (1+ (cdr active)) (car active))))
6002          ((not (listp (cdr range)))
6003           (setq num (- (cdr active) (- (1+ (cdr range))
6004                                        (car range)))))
6005          (t
6006           (while range
6007             (if (numberp (car range))
6008                 (setq num (1+ num))
6009               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6010             (setq range (cdr range)))
6011           (setq num (- (cdr active) num))))
6012         ;; Update the number of unread articles.
6013         (setcar entry num)
6014         ;; Update the group buffer.
6015         (unless (gnus-ephemeral-group-p group)
6016           (gnus-group-update-group group t))))))
6017
6018 (defvar gnus-newsgroup-none-id 0)
6019
6020 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6021   (let ((cur nntp-server-buffer)
6022         (dependencies
6023          (or dependencies
6024              (with-current-buffer gnus-summary-buffer
6025                gnus-newsgroup-dependencies)))
6026         headers id end ref number
6027         (mail-parse-charset gnus-newsgroup-charset)
6028         (mail-parse-ignored-charsets
6029          (save-excursion (condition-case nil
6030                              (set-buffer gnus-summary-buffer)
6031                            (error))
6032                          gnus-newsgroup-ignored-charsets)))
6033     (save-excursion
6034       (set-buffer nntp-server-buffer)
6035       ;; Translate all TAB characters into SPACE characters.
6036       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6037       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6038       (ietf-drums-unfold-fws)
6039       (gnus-run-hooks 'gnus-parse-headers-hook)
6040       (let ((case-fold-search t)
6041             in-reply-to header p lines chars)
6042         (goto-char (point-min))
6043         ;; Search to the beginning of the next header.  Error messages
6044         ;; do not begin with 2 or 3.
6045         (while (re-search-forward "^[23][0-9]+ " nil t)
6046           (setq id nil
6047                 ref nil)
6048           ;; This implementation of this function, with nine
6049           ;; search-forwards instead of the one re-search-forward and
6050           ;; a case (which basically was the old function) is actually
6051           ;; about twice as fast, even though it looks messier.  You
6052           ;; can't have everything, I guess.  Speed and elegance
6053           ;; doesn't always go hand in hand.
6054           (setq
6055            header
6056            (vector
6057             ;; Number.
6058             (prog1
6059                 (setq number (read cur))
6060               (end-of-line)
6061               (setq p (point))
6062               (narrow-to-region (point)
6063                                 (or (and (search-forward "\n.\n" nil t)
6064                                          (- (point) 2))
6065                                     (point))))
6066             ;; Subject.
6067             (progn
6068               (goto-char p)
6069               (if (search-forward "\nsubject:" nil t)
6070                   (funcall gnus-decode-encoded-word-function
6071                            (nnheader-header-value))
6072                 "(none)"))
6073             ;; From.
6074             (progn
6075               (goto-char p)
6076               (if (search-forward "\nfrom:" nil t)
6077                   (funcall gnus-decode-encoded-word-function
6078                            (nnheader-header-value))
6079                 "(nobody)"))
6080             ;; Date.
6081             (progn
6082               (goto-char p)
6083               (if (search-forward "\ndate:" nil t)
6084                   (nnheader-header-value) ""))
6085             ;; Message-ID.
6086             (progn
6087               (goto-char p)
6088               (setq id (if (re-search-forward
6089                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6090                            ;; We do it this way to make sure the Message-ID
6091                            ;; is (somewhat) syntactically valid.
6092                            (buffer-substring (match-beginning 1)
6093                                              (match-end 1))
6094                          ;; If there was no message-id, we just fake one
6095                          ;; to make subsequent routines simpler.
6096                          (nnheader-generate-fake-message-id number))))
6097             ;; References.
6098             (progn
6099               (goto-char p)
6100               (if (search-forward "\nreferences:" nil t)
6101                   (progn
6102                     (setq end (point))
6103                     (prog1
6104                         (nnheader-header-value)
6105                       (setq ref
6106                             (buffer-substring
6107                              (progn
6108                                (end-of-line)
6109                                (search-backward ">" end t)
6110                                (1+ (point)))
6111                              (progn
6112                                (search-backward "<" end t)
6113                                (point))))))
6114                 ;; Get the references from the in-reply-to header if there
6115                 ;; were no references and the in-reply-to header looks
6116                 ;; promising.
6117                 (if (and (search-forward "\nin-reply-to:" nil t)
6118                          (setq in-reply-to (nnheader-header-value))
6119                          (string-match "<[^>]+>" in-reply-to))
6120                     (let (ref2)
6121                       (setq ref (substring in-reply-to (match-beginning 0)
6122                                            (match-end 0)))
6123                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6124                         (setq ref2 (substring in-reply-to (match-beginning 0)
6125                                               (match-end 0)))
6126                         (when (> (length ref2) (length ref))
6127                           (setq ref ref2)))
6128                       ref)
6129                   (setq ref nil))))
6130             ;; Chars.
6131             (progn
6132               (goto-char p)
6133               (if (search-forward "\nchars: " nil t)
6134                   (if (numberp (setq chars (ignore-errors (read cur))))
6135                       chars -1)
6136                 -1))
6137             ;; Lines.
6138             (progn
6139               (goto-char p)
6140               (if (search-forward "\nlines: " nil t)
6141                   (if (numberp (setq lines (ignore-errors (read cur))))
6142                       lines -1)
6143                 -1))
6144             ;; Xref.
6145             (progn
6146               (goto-char p)
6147               (and (search-forward "\nxref:" nil t)
6148                    (nnheader-header-value)))
6149             ;; Extra.
6150             (when gnus-extra-headers
6151               (let ((extra gnus-extra-headers)
6152                     out)
6153                 (while extra
6154                   (goto-char p)
6155                   (when (search-forward
6156                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6157                     (push (cons (car extra) (nnheader-header-value))
6158                           out))
6159                   (pop extra))
6160                 out))))
6161           (when (equal id ref)
6162             (setq ref nil))
6163
6164           (when gnus-alter-header-function
6165             (funcall gnus-alter-header-function header)
6166             (setq id (mail-header-id header)
6167                   ref (gnus-parent-id (mail-header-references header))))
6168
6169           (when (setq header
6170                       (gnus-dependencies-add-header
6171                        header dependencies force-new))
6172             (push header headers))
6173           (goto-char (point-max))
6174           (widen))
6175         (nreverse headers)))))
6176
6177 ;; Goes through the xover lines and returns a list of vectors
6178 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6179                                                   force-new dependencies
6180                                                   group also-fetch-heads)
6181   "Parse the news overview data in the server buffer.
6182 Return a list of headers that match SEQUENCE (see
6183 `nntp-retrieve-headers')."
6184   ;; Get the Xref when the users reads the articles since most/some
6185   ;; NNTP servers do not include Xrefs when using XOVER.
6186   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6187   (let ((mail-parse-charset gnus-newsgroup-charset)
6188         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6189         (cur nntp-server-buffer)
6190         (dependencies (or dependencies gnus-newsgroup-dependencies))
6191         (allp (cond
6192                ((eq gnus-read-all-available-headers t)
6193                 t)
6194                ((and (stringp gnus-read-all-available-headers)
6195                      group)
6196                 (string-match gnus-read-all-available-headers group))
6197                (t
6198                 nil)))
6199         number headers header)
6200     (save-excursion
6201       (set-buffer nntp-server-buffer)
6202       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6203       ;; Allow the user to mangle the headers before parsing them.
6204       (gnus-run-hooks 'gnus-parse-headers-hook)
6205       (goto-char (point-min))
6206       (gnus-parse-without-error
6207         (while (and (or sequence allp)
6208                     (not (eobp)))
6209           (setq number (read cur))
6210           (when (not allp)
6211             (while (and sequence
6212                         (< (car sequence) number))
6213               (setq sequence (cdr sequence))))
6214           (when (and (or allp
6215                          (and sequence
6216                               (eq number (car sequence))))
6217                      (progn
6218                        (setq sequence (cdr sequence))
6219                        (setq header (inline
6220                                       (gnus-nov-parse-line
6221                                        number dependencies force-new)))))
6222             (push header headers))
6223           (forward-line 1)))
6224       ;; A common bug in inn is that if you have posted an article and
6225       ;; then retrieves the active file, it will answer correctly --
6226       ;; the new article is included.  However, a NOV entry for the
6227       ;; article may not have been generated yet, so this may fail.
6228       ;; We work around this problem by retrieving the last few
6229       ;; headers using HEAD.
6230       (if (or (not also-fetch-heads)
6231               (not sequence))
6232           ;; We (probably) got all the headers.
6233           (nreverse headers)
6234         (let ((gnus-nov-is-evil t))
6235           (nconc
6236            (nreverse headers)
6237            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6238              (gnus-get-newsgroup-headers))))))))
6239
6240 (defun gnus-article-get-xrefs ()
6241   "Fill in the Xref value in `gnus-current-headers', if necessary.
6242 This is meant to be called in `gnus-article-internal-prepare-hook'."
6243   (let ((headers (with-current-buffer gnus-summary-buffer
6244                    gnus-current-headers)))
6245     (or (not gnus-use-cross-reference)
6246         (not headers)
6247         (and (mail-header-xref headers)
6248              (not (string= (mail-header-xref headers) "")))
6249         (let ((case-fold-search t)
6250               xref)
6251           (save-restriction
6252             (nnheader-narrow-to-headers)
6253             (goto-char (point-min))
6254             (when (or (and (not (eobp))
6255                            (eq (downcase (char-after)) ?x)
6256                            (looking-at "Xref:"))
6257                       (search-forward "\nXref:" nil t))
6258               (goto-char (1+ (match-end 0)))
6259               (setq xref (buffer-substring (point) (point-at-eol)))
6260               (mail-header-set-xref headers xref)))))))
6261
6262 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6263   "Find article ID and insert the summary line for that article.
6264 OLD-HEADER can either be a header or a line number to insert
6265 the subject line on."
6266   (let* ((line (and (numberp old-header) old-header))
6267          (old-header (and (vectorp old-header) old-header))
6268          (header (cond ((and old-header use-old-header)
6269                         old-header)
6270                        ((and (numberp id)
6271                              (gnus-number-to-header id))
6272                         (gnus-number-to-header id))
6273                        (t
6274                         (gnus-read-header id))))
6275          (number (and (numberp id) id))
6276          d)
6277     (when header
6278       ;; Rebuild the thread that this article is part of and go to the
6279       ;; article we have fetched.
6280       (when (and (not gnus-show-threads)
6281                  old-header)
6282         (when (and number
6283                    (setq d (gnus-data-find (mail-header-number old-header))))
6284           (goto-char (gnus-data-pos d))
6285           (gnus-data-remove
6286            number
6287            (- (point-at-bol)
6288               (prog1
6289                   (1+ (point-at-eol))
6290                 (gnus-delete-line))))))
6291       ;; Remove list identifiers from subject.
6292       (when gnus-list-identifiers
6293         (let ((gnus-newsgroup-headers (list header)))
6294           (gnus-summary-remove-list-identifiers)))
6295       (when old-header
6296         (mail-header-set-number header (mail-header-number old-header)))
6297       (setq gnus-newsgroup-sparse
6298             (delq (setq number (mail-header-number header))
6299                   gnus-newsgroup-sparse))
6300       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6301       (push number gnus-newsgroup-limit)
6302       (gnus-rebuild-thread (mail-header-id header) line)
6303       (gnus-summary-goto-subject number nil t))
6304     (when (and (numberp number)
6305                (> number 0))
6306       ;; We have to update the boundaries even if we can't fetch the
6307       ;; article if ID is a number -- so that the next `P' or `N'
6308       ;; command will fetch the previous (or next) article even
6309       ;; if the one we tried to fetch this time has been canceled.
6310       (when (> number gnus-newsgroup-end)
6311         (setq gnus-newsgroup-end number))
6312       (when (< number gnus-newsgroup-begin)
6313         (setq gnus-newsgroup-begin number))
6314       (setq gnus-newsgroup-unselected
6315             (delq number gnus-newsgroup-unselected)))
6316     ;; Report back a success?
6317     (and header (mail-header-number header))))
6318
6319 ;;; Process/prefix in the summary buffer
6320
6321 (defun gnus-summary-work-articles (n)
6322   "Return a list of articles to be worked upon.
6323 The prefix argument, the list of process marked articles, and the
6324 current article will be taken into consideration."
6325   (save-excursion
6326     (set-buffer gnus-summary-buffer)
6327     (cond
6328      (n
6329       ;; A numerical prefix has been given.
6330       (setq n (prefix-numeric-value n))
6331       (let ((backward (< n 0))
6332             (n (abs (prefix-numeric-value n)))
6333             articles article)
6334         (save-excursion
6335           (while
6336               (and (> n 0)
6337                    (push (setq article (gnus-summary-article-number))
6338                          articles)
6339                    (if backward
6340                        (gnus-summary-find-prev nil article)
6341                      (gnus-summary-find-next nil article)))
6342             (decf n)))
6343         (nreverse articles)))
6344      ((and (gnus-region-active-p) (mark))
6345       (message "region active")
6346       ;; Work on the region between point and mark.
6347       (let ((max (max (point) (mark)))
6348             articles article)
6349         (save-excursion
6350           (goto-char (min (point) (mark)))
6351           (while
6352               (and
6353                (push (setq article (gnus-summary-article-number)) articles)
6354                (gnus-summary-find-next nil article)
6355                (< (point) max)))
6356           (nreverse articles))))
6357      (gnus-newsgroup-processable
6358       ;; There are process-marked articles present.
6359       ;; Save current state.
6360       (gnus-summary-save-process-mark)
6361       ;; Return the list.
6362       (reverse gnus-newsgroup-processable))
6363      (t
6364       ;; Just return the current article.
6365       (list (gnus-summary-article-number))))))
6366
6367 (defmacro gnus-summary-iterate (arg &rest forms)
6368   "Iterate over the process/prefixed articles and do FORMS.
6369 ARG is the interactive prefix given to the command.  FORMS will be
6370 executed with point over the summary line of the articles."
6371   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6372     `(let ((,articles (gnus-summary-work-articles ,arg)))
6373        (while ,articles
6374          (gnus-summary-goto-subject (car ,articles))
6375          ,@forms
6376          (pop ,articles)))))
6377
6378 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6379 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6380
6381 (defun gnus-summary-save-process-mark ()
6382   "Push the current set of process marked articles on the stack."
6383   (interactive)
6384   (push (copy-sequence gnus-newsgroup-processable)
6385         gnus-newsgroup-process-stack))
6386
6387 (defun gnus-summary-kill-process-mark ()
6388   "Push the current set of process marked articles on the stack and unmark."
6389   (interactive)
6390   (gnus-summary-save-process-mark)
6391   (gnus-summary-unmark-all-processable))
6392
6393 (defun gnus-summary-yank-process-mark ()
6394   "Pop the last process mark state off the stack and restore it."
6395   (interactive)
6396   (unless gnus-newsgroup-process-stack
6397     (error "Empty mark stack"))
6398   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6399
6400 (defun gnus-summary-process-mark-set (set)
6401   "Make SET into the current process marked articles."
6402   (gnus-summary-unmark-all-processable)
6403   (mapc 'gnus-summary-set-process-mark set))
6404
6405 ;;; Searching and stuff
6406
6407 (defun gnus-summary-search-group (&optional backward use-level)
6408   "Search for next unread newsgroup.
6409 If optional argument BACKWARD is non-nil, search backward instead."
6410   (save-excursion
6411     (set-buffer gnus-group-buffer)
6412     (when (gnus-group-search-forward
6413            backward nil (if use-level (gnus-group-group-level) nil))
6414       (gnus-group-group-name))))
6415
6416 (defun gnus-summary-best-group (&optional exclude-group)
6417   "Find the name of the best unread group.
6418 If EXCLUDE-GROUP, do not go to this group."
6419   (with-current-buffer gnus-group-buffer
6420     (save-excursion
6421       (gnus-group-best-unread-group exclude-group))))
6422
6423 (defun gnus-summary-find-next (&optional unread article backward)
6424   (if backward
6425       (gnus-summary-find-prev unread article)
6426     (let* ((dummy (gnus-summary-article-intangible-p))
6427            (article (or article (gnus-summary-article-number)))
6428            (data (gnus-data-find-list article))
6429            result)
6430       (when (and (not dummy)
6431                  (or (not gnus-summary-check-current)
6432                      (not unread)
6433                      (not (gnus-data-unread-p (car data)))))
6434         (setq data (cdr data)))
6435       (when (setq result
6436                   (if unread
6437                       (progn
6438                         (while data
6439                           (unless (memq (gnus-data-number (car data))
6440                                         (cond
6441                                          ((eq gnus-auto-goto-ignores
6442                                               'always-undownloaded)
6443                                           gnus-newsgroup-undownloaded)
6444                                          (gnus-plugged
6445                                           nil)
6446                                          ((eq gnus-auto-goto-ignores
6447                                               'unfetched)
6448                                           gnus-newsgroup-unfetched)
6449                                          ((eq gnus-auto-goto-ignores
6450                                               'undownloaded)
6451                                           gnus-newsgroup-undownloaded)))
6452                             (when (gnus-data-unread-p (car data))
6453                               (setq result (car data)
6454                                     data nil)))
6455                           (setq data (cdr data)))
6456                         result)
6457                     (car data)))
6458         (goto-char (gnus-data-pos result))
6459         (gnus-data-number result)))))
6460
6461 (defun gnus-summary-find-prev (&optional unread article)
6462   (let* ((eobp (eobp))
6463          (article (or article (gnus-summary-article-number)))
6464          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6465          result)
6466     (when (and (not eobp)
6467                (or (not gnus-summary-check-current)
6468                    (not unread)
6469                    (not (gnus-data-unread-p (car data)))))
6470       (setq data (cdr data)))
6471     (when (setq result
6472                 (if unread
6473                     (progn
6474                       (while data
6475                         (unless (memq (gnus-data-number (car data))
6476                                       (cond
6477                                        ((eq gnus-auto-goto-ignores
6478                                             'always-undownloaded)
6479                                         gnus-newsgroup-undownloaded)
6480                                        (gnus-plugged
6481                                         nil)
6482                                        ((eq gnus-auto-goto-ignores
6483                                             'unfetched)
6484                                         gnus-newsgroup-unfetched)
6485                                        ((eq gnus-auto-goto-ignores
6486                                             'undownloaded)
6487                                         gnus-newsgroup-undownloaded)))
6488                           (when (gnus-data-unread-p (car data))
6489                             (setq result (car data)
6490                                   data nil)))
6491                         (setq data (cdr data)))
6492                       result)
6493                   (car data)))
6494       (goto-char (gnus-data-pos result))
6495       (gnus-data-number result))))
6496
6497 (defun gnus-summary-find-subject (subject &optional unread backward article)
6498   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6499          (article (or article (gnus-summary-article-number)))
6500          (articles (gnus-data-list backward))
6501          (arts (gnus-data-find-list article articles))
6502          result)
6503     (when (or (not gnus-summary-check-current)
6504               (not unread)
6505               (not (gnus-data-unread-p (car arts))))
6506       (setq arts (cdr arts)))
6507     (while arts
6508       (and (or (not unread)
6509                (gnus-data-unread-p (car arts)))
6510            (vectorp (gnus-data-header (car arts)))
6511            (gnus-subject-equal
6512             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6513            (setq result (car arts)
6514                  arts nil))
6515       (setq arts (cdr arts)))
6516     (and result
6517          (goto-char (gnus-data-pos result))
6518          (gnus-data-number result))))
6519
6520 (defun gnus-summary-search-forward (&optional unread subject backward)
6521   "Search forward for an article.
6522 If UNREAD, look for unread articles.  If SUBJECT, look for
6523 articles with that subject.  If BACKWARD, search backward instead."
6524   (cond (subject (gnus-summary-find-subject subject unread backward))
6525         (backward (gnus-summary-find-prev unread))
6526         (t (gnus-summary-find-next unread))))
6527
6528 (defun gnus-recenter (&optional n)
6529   "Center point in window and redisplay frame.
6530 Also do horizontal recentering."
6531   (interactive "P")
6532   (when (and gnus-auto-center-summary
6533              (not (eq gnus-auto-center-summary 'vertical)))
6534     (gnus-horizontal-recenter))
6535   (recenter n))
6536
6537 (defun gnus-summary-recenter ()
6538   "Center point in the summary window.
6539 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6540 displayed, no centering will be performed."
6541   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6542   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6543   (interactive)
6544   ;; The user has to want it.
6545   (when gnus-auto-center-summary
6546     (let* ((top (cond ((< (window-height) 4) 0)
6547                       ((< (window-height) 7) 1)
6548                       (t (if (numberp gnus-auto-center-summary)
6549                              gnus-auto-center-summary
6550                            (/ (1- (window-height)) 2)))))
6551            (height (1- (window-height)))
6552            (bottom (save-excursion (goto-char (point-max))
6553                                    (forward-line (- height))
6554                                    (point)))
6555            (window (get-buffer-window (current-buffer))))
6556       (when (get-buffer-window gnus-article-buffer)
6557         ;; Only do recentering when the article buffer is displayed,
6558         ;; Set the window start to either `bottom', which is the biggest
6559         ;; possible valid number, or the second line from the top,
6560         ;; whichever is the least.
6561         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6562           (if (> bottom top-pos)
6563               ;; Keep the second line from the top visible
6564               (set-window-start window top-pos t)
6565             ;; Try to keep the bottom line visible; if it's partially
6566             ;; obscured, either scroll one more line to make it fully
6567             ;; visible, or revert to using TOP-POS.
6568             (save-excursion
6569               (goto-char (point-max))
6570               (forward-line -1)
6571               (let ((last-line-start (point)))
6572                 (goto-char bottom)
6573                 (set-window-start window (point) t)
6574                 (when (not (pos-visible-in-window-p last-line-start window))
6575                   (forward-line 1)
6576                   (set-window-start window (min (point) top-pos) t)))))))
6577       ;; Do horizontal recentering while we're at it.
6578       (when (and (get-buffer-window (current-buffer) t)
6579                  (not (eq gnus-auto-center-summary 'vertical)))
6580         (let ((selected (selected-window)))
6581           (select-window (get-buffer-window (current-buffer) t))
6582           (gnus-summary-position-point)
6583           (gnus-horizontal-recenter)
6584           (select-window selected))))))
6585
6586 (defun gnus-summary-jump-to-group (newsgroup)
6587   "Move point to NEWSGROUP in group mode buffer."
6588   ;; Keep update point of group mode buffer if visible.
6589   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6590       (save-window-excursion
6591         ;; Take care of tree window mode.
6592         (when (get-buffer-window gnus-group-buffer)
6593           (pop-to-buffer gnus-group-buffer))
6594         (gnus-group-jump-to-group newsgroup))
6595     (save-excursion
6596       ;; Take care of tree window mode.
6597       (if (get-buffer-window gnus-group-buffer)
6598           (pop-to-buffer gnus-group-buffer)
6599         (set-buffer gnus-group-buffer))
6600       (gnus-group-jump-to-group newsgroup))))
6601
6602 ;; This function returns a list of article numbers based on the
6603 ;; difference between the ranges of read articles in this group and
6604 ;; the range of active articles.
6605 (defun gnus-list-of-unread-articles (group)
6606   (let* ((read (gnus-info-read (gnus-get-info group)))
6607          (active (or (gnus-active group) (gnus-activate-group group)))
6608          (last (or (cdr active)
6609                    (error "Group %s couldn't be activated " group)))
6610          first nlast unread)
6611     ;; If none are read, then all are unread.
6612     (if (not read)
6613         (setq first (car active))
6614       ;; If the range of read articles is a single range, then the
6615       ;; first unread article is the article after the last read
6616       ;; article.  Sounds logical, doesn't it?
6617       (if (and (not (listp (cdr read)))
6618                (or (< (car read) (car active))
6619                    (progn (setq read (list read))
6620                           nil)))
6621           (setq first (max (car active) (1+ (cdr read))))
6622         ;; `read' is a list of ranges.
6623         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6624                                   (caar read)))
6625                   1)
6626           (setq first (car active)))
6627         (while read
6628           (when first
6629             (while (< first nlast)
6630               (setq unread (cons first unread)
6631                     first (1+ first))))
6632           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6633           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6634           (setq read (cdr read)))))
6635     ;; And add the last unread articles.
6636     (while (<= first last)
6637       (setq unread (cons first unread)
6638             first (1+ first)))
6639     ;; Return the list of unread articles.
6640     (delq 0 (nreverse unread))))
6641
6642 (defun gnus-list-of-read-articles (group)
6643   "Return a list of unread, unticked and non-dormant articles."
6644   (let* ((info (gnus-get-info group))
6645          (marked (gnus-info-marks info))
6646          (active (gnus-active group)))
6647     (and info active
6648          (gnus-list-range-difference
6649           (gnus-list-range-difference
6650            (gnus-sorted-complement
6651             (gnus-uncompress-range active)
6652             (gnus-list-of-unread-articles group))
6653            (cdr (assq 'dormant marked)))
6654           (cdr (assq 'tick marked))))))
6655
6656 ;; This function returns a sequence of article numbers based on the
6657 ;; difference between the ranges of read articles in this group and
6658 ;; the range of active articles.
6659 (defun gnus-sequence-of-unread-articles (group)
6660   (let* ((read (gnus-info-read (gnus-get-info group)))
6661          (active (or (gnus-active group) (gnus-activate-group group)))
6662          (last (cdr active))
6663          first nlast unread)
6664     ;; If none are read, then all are unread.
6665     (if (not read)
6666         (setq first (car active))
6667       ;; If the range of read articles is a single range, then the
6668       ;; first unread article is the article after the last read
6669       ;; article.  Sounds logical, doesn't it?
6670       (if (and (not (listp (cdr read)))
6671                (or (< (car read) (car active))
6672                    (progn (setq read (list read))
6673                           nil)))
6674           (setq first (max (car active) (1+ (cdr read))))
6675         ;; `read' is a list of ranges.
6676         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6677                                   (caar read)))
6678                   1)
6679           (setq first (car active)))
6680         (while read
6681           (when first
6682             (push (cons first nlast) unread))
6683           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6684           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6685           (setq read (cdr read)))))
6686     ;; And add the last unread articles.
6687     (cond ((not (and first last))
6688            nil)
6689           ((< first last)
6690            (push (cons first last) unread))
6691           ((= first last)
6692            (push first unread)))
6693     ;; Return the sequence of unread articles.
6694     (delq 0 (nreverse unread))))
6695
6696 ;; Various summary commands
6697
6698 (defun gnus-summary-select-article-buffer ()
6699   "Reconfigure windows to show article buffer."
6700   (interactive)
6701   (if (not (gnus-buffer-live-p gnus-article-buffer))
6702       (error "There is no article buffer for this summary buffer")
6703     (gnus-configure-windows 'article)
6704     (select-window (get-buffer-window gnus-article-buffer))))
6705
6706 (defun gnus-summary-universal-argument (arg)
6707   "Perform any operation on all articles that are process/prefixed."
6708   (interactive "P")
6709   (let ((articles (gnus-summary-work-articles arg))
6710         func article)
6711     (if (eq
6712          (setq
6713           func
6714           (key-binding
6715            (read-key-sequence
6716             (substitute-command-keys
6717              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6718          'undefined)
6719         (gnus-error 1 "Undefined key")
6720       (save-excursion
6721         (while articles
6722           (gnus-summary-goto-subject (setq article (pop articles)))
6723           (let (gnus-newsgroup-processable)
6724             (command-execute func))
6725           (gnus-summary-remove-process-mark article)))))
6726   (gnus-summary-position-point))
6727
6728 (defun gnus-summary-toggle-truncation (&optional arg)
6729   "Toggle truncation of summary lines.
6730 With ARG, turn line truncation on if ARG is positive."
6731   (interactive "P")
6732   (setq truncate-lines
6733         (if (null arg) (not truncate-lines)
6734           (> (prefix-numeric-value arg) 0)))
6735   (redraw-display))
6736
6737 (defun gnus-summary-find-for-reselect ()
6738   "Return the number of an article to stay on across a reselect.
6739 The current article is considered, then following articles, then previous
6740 articles.  An article is sought which is not cancelled and isn't a temporary
6741 insertion from another group.  If there's no such then return a dummy 0."
6742   (let (found)
6743     (dolist (rev '(nil t))
6744       (unless found      ; don't demand the reverse list if we don't need it
6745         (let ((data (gnus-data-find-list
6746                      (gnus-summary-article-number) (gnus-data-list rev))))
6747           (while (and data (not found))
6748             (if (and (< 0 (gnus-data-number (car data)))
6749                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6750                 (setq found (gnus-data-number (car data))))
6751             (setq data (cdr data))))))
6752     (or found 0)))
6753
6754 (defun gnus-summary-reselect-current-group (&optional all rescan)
6755   "Exit and then reselect the current newsgroup.
6756 The prefix argument ALL means to select all articles."
6757   (interactive "P")
6758   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6759     (error "Ephemeral groups can't be reselected"))
6760   (let ((current-subject (gnus-summary-find-for-reselect))
6761         (group gnus-newsgroup-name))
6762     (setq gnus-newsgroup-begin nil)
6763     (gnus-summary-exit nil 'leave-hidden)
6764     ;; We have to adjust the point of group mode buffer because
6765     ;; point was moved to the next unread newsgroup by exiting.
6766     (gnus-summary-jump-to-group group)
6767     (when rescan
6768       (save-excursion
6769         (gnus-group-get-new-news-this-group 1)))
6770     (gnus-group-read-group all t)
6771     (gnus-summary-goto-subject current-subject nil t)))
6772
6773 (defun gnus-summary-rescan-group (&optional all)
6774   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6775   (interactive "P")
6776   (gnus-summary-reselect-current-group all t))
6777
6778 (defun gnus-summary-update-info (&optional non-destructive)
6779   (save-excursion
6780     (let ((group gnus-newsgroup-name))
6781       (when group
6782         (when gnus-newsgroup-kill-headers
6783           (setq gnus-newsgroup-killed
6784                 (gnus-compress-sequence
6785                  (gnus-sorted-union
6786                   (gnus-list-range-intersection
6787                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6788                   gnus-newsgroup-unreads)
6789                  t)))
6790         (unless (listp (cdr gnus-newsgroup-killed))
6791           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6792         (let ((headers gnus-newsgroup-headers))
6793           ;; Set the new ranges of read articles.
6794           (with-current-buffer gnus-group-buffer
6795             (gnus-undo-force-boundary))
6796           (gnus-update-read-articles
6797            group (gnus-sorted-union
6798                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6799           ;; Set the current article marks.
6800           (let ((gnus-newsgroup-scored
6801                  (if (and (not gnus-save-score)
6802                           (not non-destructive))
6803                      nil
6804                    gnus-newsgroup-scored)))
6805             (save-excursion
6806               (gnus-update-marks)))
6807           ;; Do the cross-ref thing.
6808           (when gnus-use-cross-reference
6809             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6810           ;; Do not switch windows but change the buffer to work.
6811           (set-buffer gnus-group-buffer)
6812           (unless (gnus-ephemeral-group-p group)
6813             (gnus-group-update-group group)))))))
6814
6815 (defun gnus-summary-save-newsrc (&optional force)
6816   "Save the current number of read/marked articles in the dribble buffer.
6817 The dribble buffer will then be saved.
6818 If FORCE (the prefix), also save the .newsrc file(s)."
6819   (interactive "P")
6820   (gnus-summary-update-info t)
6821   (if force
6822       (gnus-save-newsrc-file)
6823     (gnus-dribble-save)))
6824
6825 (defun gnus-summary-exit (&optional temporary leave-hidden)
6826   "Exit reading current newsgroup, and then return to group selection mode.
6827 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6828   (interactive)
6829   (gnus-set-global-variables)
6830   (when (gnus-buffer-live-p gnus-article-buffer)
6831     (save-excursion
6832       (set-buffer gnus-article-buffer)
6833       (mm-destroy-parts gnus-article-mime-handles)
6834       ;; Set it to nil for safety reason.
6835       (setq gnus-article-mime-handle-alist nil)
6836       (setq gnus-article-mime-handles nil)))
6837   (gnus-kill-save-kill-buffer)
6838   (gnus-async-halt-prefetch)
6839   (let* ((group gnus-newsgroup-name)
6840          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6841          (gnus-group-is-exiting-p t)
6842          (mode major-mode)
6843          (group-point nil)
6844          (buf (current-buffer)))
6845     (unless quit-config
6846       ;; Do adaptive scoring, and possibly save score files.
6847       (when gnus-newsgroup-adaptive
6848         (gnus-score-adaptive))
6849       (when gnus-use-scoring
6850         (gnus-score-save)))
6851     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6852     ;; If we have several article buffers, we kill them at exit.
6853     (unless gnus-single-article-buffer
6854       (gnus-kill-buffer gnus-article-buffer)
6855       (gnus-kill-buffer gnus-original-article-buffer)
6856       (setq gnus-article-current nil))
6857     (when gnus-use-cache
6858       (gnus-cache-possibly-remove-articles)
6859       (gnus-cache-save-buffers))
6860     (gnus-async-prefetch-remove-group group)
6861     (when gnus-suppress-duplicates
6862       (gnus-dup-enter-articles))
6863     (when gnus-use-trees
6864       (gnus-tree-close group))
6865     (when gnus-use-cache
6866       (gnus-cache-write-active))
6867     ;; Remove entries for this group.
6868     (nnmail-purge-split-history (gnus-group-real-name group))
6869     ;; Make all changes in this group permanent.
6870     (unless quit-config
6871       (gnus-run-hooks 'gnus-exit-group-hook)
6872       (gnus-summary-update-info))
6873     (gnus-close-group group)
6874     ;; Make sure where we were, and go to next newsgroup.
6875     (set-buffer gnus-group-buffer)
6876     (unless quit-config
6877       (gnus-group-jump-to-group group))
6878     (gnus-run-hooks 'gnus-summary-exit-hook)
6879     (unless (or quit-config
6880                 ;; If this group has disappeared from the summary
6881                 ;; buffer, don't skip forwards.
6882                 (not (string= group (gnus-group-group-name))))
6883       (gnus-group-next-unread-group 1))
6884     (setq group-point (point))
6885     (if temporary
6886         nil                             ;Nothing to do.
6887       ;; If we have several article buffers, we kill them at exit.
6888       (unless gnus-single-article-buffer
6889         (gnus-kill-buffer gnus-article-buffer)
6890         (gnus-kill-buffer gnus-original-article-buffer)
6891         (setq gnus-article-current nil))
6892       (set-buffer buf)
6893       (if (not gnus-kill-summary-on-exit)
6894           (progn
6895             (gnus-deaden-summary)
6896             (setq mode nil))
6897         ;; We set all buffer-local variables to nil.  It is unclear why
6898         ;; this is needed, but if we don't, buffer-local variables are
6899         ;; not garbage-collected, it seems.  This would the lead to en
6900         ;; ever-growing Emacs.
6901         (gnus-summary-clear-local-variables)
6902         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6903           (gnus-summary-clear-local-variables))
6904         (when (get-buffer gnus-article-buffer)
6905           (bury-buffer gnus-article-buffer))
6906         ;; Return to group mode buffer.
6907         (when (eq mode 'gnus-summary-mode)
6908           (gnus-kill-buffer buf)))
6909       (setq gnus-current-select-method gnus-select-method)
6910       (set-buffer gnus-group-buffer)
6911       (if quit-config
6912           (gnus-handle-ephemeral-exit quit-config)
6913         (goto-char group-point)
6914         ;; If gnus-group-buffer is already displayed, make sure we also move
6915         ;; the cursor in the window that displays it.
6916         (let ((win (get-buffer-window (current-buffer) 0)))
6917           (if win (set-window-point win (point))))
6918         (unless leave-hidden
6919           (gnus-configure-windows 'group 'force)))
6920       ;; Clear the current group name.
6921       (unless quit-config
6922         (setq gnus-newsgroup-name nil)))))
6923
6924 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6925 (defun gnus-summary-exit-no-update (&optional no-questions)
6926   "Quit reading current newsgroup without updating read article info."
6927   (interactive)
6928   (let* ((group gnus-newsgroup-name)
6929          (gnus-group-is-exiting-p t)
6930          (gnus-group-is-exiting-without-update-p t)
6931          (quit-config (gnus-group-quit-config group)))
6932     (when (or no-questions
6933               gnus-expert-user
6934               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6935       (gnus-async-halt-prefetch)
6936       (run-hooks 'gnus-summary-prepare-exit-hook)
6937       (when (gnus-buffer-live-p gnus-article-buffer)
6938         (save-excursion
6939           (set-buffer gnus-article-buffer)
6940           (mm-destroy-parts gnus-article-mime-handles)
6941           ;; Set it to nil for safety reason.
6942           (setq gnus-article-mime-handle-alist nil)
6943           (setq gnus-article-mime-handles nil)))
6944       ;; If we have several article buffers, we kill them at exit.
6945       (unless gnus-single-article-buffer
6946         (gnus-kill-buffer gnus-article-buffer)
6947         (gnus-kill-buffer gnus-original-article-buffer)
6948         (setq gnus-article-current nil))
6949       (if (not gnus-kill-summary-on-exit)
6950           (gnus-deaden-summary)
6951         (gnus-close-group group)
6952         (gnus-summary-clear-local-variables)
6953         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6954           (gnus-summary-clear-local-variables))
6955         (gnus-kill-buffer gnus-summary-buffer))
6956       (unless gnus-single-article-buffer
6957         (setq gnus-article-current nil))
6958       (when gnus-use-trees
6959         (gnus-tree-close group))
6960       (gnus-async-prefetch-remove-group group)
6961       (when (get-buffer gnus-article-buffer)
6962         (bury-buffer gnus-article-buffer))
6963       ;; Return to the group buffer.
6964       (gnus-configure-windows 'group 'force)
6965       ;; Clear the current group name.
6966       (setq gnus-newsgroup-name nil)
6967       (unless (gnus-ephemeral-group-p group)
6968         (gnus-group-update-group group))
6969       (when (equal (gnus-group-group-name) group)
6970         (gnus-group-next-unread-group 1))
6971       (when quit-config
6972         (gnus-handle-ephemeral-exit quit-config)))))
6973
6974 (defun gnus-handle-ephemeral-exit (quit-config)
6975   "Handle movement when leaving an ephemeral group.
6976 The state which existed when entering the ephemeral is reset."
6977   (if (not (buffer-name (car quit-config)))
6978       (gnus-configure-windows 'group 'force)
6979     (set-buffer (car quit-config))
6980     (cond ((eq major-mode 'gnus-summary-mode)
6981            (gnus-set-global-variables))
6982           ((eq major-mode 'gnus-article-mode)
6983            (save-excursion
6984              ;; The `gnus-summary-buffer' variable may point
6985              ;; to the old summary buffer when using a single
6986              ;; article buffer.
6987              (unless (gnus-buffer-live-p gnus-summary-buffer)
6988                (set-buffer gnus-group-buffer))
6989              (set-buffer gnus-summary-buffer)
6990              (gnus-set-global-variables))))
6991     (if (or (eq (cdr quit-config) 'article)
6992             (eq (cdr quit-config) 'pick))
6993         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6994             (gnus-configure-windows 'pick 'force)
6995           (gnus-configure-windows (cdr quit-config) 'force))
6996       (gnus-configure-windows (cdr quit-config) 'force))
6997     (when (eq major-mode 'gnus-summary-mode)
6998       (gnus-summary-recenter)
6999       (gnus-summary-position-point))))
7000
7001 ;;; Dead summaries.
7002
7003 (defvar gnus-dead-summary-mode-map nil)
7004
7005 (unless gnus-dead-summary-mode-map
7006   (setq gnus-dead-summary-mode-map (make-keymap))
7007   (suppress-keymap gnus-dead-summary-mode-map)
7008   (substitute-key-definition
7009    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7010   (dolist (key '("\C-d" "\r" "\177" [delete]))
7011     (define-key gnus-dead-summary-mode-map
7012       key 'gnus-summary-wake-up-the-dead))
7013   (dolist (key '("q" "Q"))
7014     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7015
7016 (defvar gnus-dead-summary-mode nil
7017   "Minor mode for Gnus summary buffers.")
7018
7019 (defun gnus-dead-summary-mode (&optional arg)
7020   "Minor mode for Gnus summary buffers."
7021   (interactive "P")
7022   (when (eq major-mode 'gnus-summary-mode)
7023     (make-local-variable 'gnus-dead-summary-mode)
7024     (setq gnus-dead-summary-mode
7025           (if (null arg) (not gnus-dead-summary-mode)
7026             (> (prefix-numeric-value arg) 0)))
7027     (when gnus-dead-summary-mode
7028       (add-minor-mode
7029        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7030
7031 (defun gnus-deaden-summary ()
7032   "Make the current summary buffer into a dead summary buffer."
7033   ;; Kill any previous dead summary buffer.
7034   (when (and gnus-dead-summary
7035              (buffer-name gnus-dead-summary))
7036     (with-current-buffer gnus-dead-summary
7037       (when gnus-dead-summary-mode
7038         (kill-buffer (current-buffer)))))
7039   ;; Make this the current dead summary.
7040   (setq gnus-dead-summary (current-buffer))
7041   (gnus-dead-summary-mode 1)
7042   (let ((name (buffer-name)))
7043     (when (string-match "Summary" name)
7044       (rename-buffer
7045        (concat (substring name 0 (match-beginning 0)) "Dead "
7046                (substring name (match-beginning 0)))
7047        t)
7048       (bury-buffer))))
7049
7050 (defun gnus-kill-or-deaden-summary (buffer)
7051   "Kill or deaden the summary BUFFER."
7052   (save-excursion
7053     (when (and (buffer-name buffer)
7054                (not gnus-single-article-buffer))
7055       (with-current-buffer buffer
7056         (gnus-kill-buffer gnus-article-buffer)
7057         (gnus-kill-buffer gnus-original-article-buffer)))
7058     (cond
7059      ;; Kill the buffer.
7060      (gnus-kill-summary-on-exit
7061       (when (and gnus-use-trees
7062                  (gnus-buffer-exists-p buffer))
7063         (save-excursion
7064           (set-buffer buffer)
7065           (gnus-tree-close gnus-newsgroup-name)))
7066       (gnus-kill-buffer buffer))
7067      ;; Deaden the buffer.
7068      ((gnus-buffer-exists-p buffer)
7069       (save-excursion
7070         (set-buffer buffer)
7071         (gnus-deaden-summary))))))
7072
7073 (defun gnus-summary-wake-up-the-dead (&rest args)
7074   "Wake up the dead summary buffer."
7075   (interactive)
7076   (gnus-dead-summary-mode -1)
7077   (let ((name (buffer-name)))
7078     (when (string-match "Dead " name)
7079       (rename-buffer
7080        (concat (substring name 0 (match-beginning 0))
7081                (substring name (match-end 0)))
7082        t)))
7083   (gnus-message 3 "This dead summary is now alive again"))
7084
7085 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7086 (defun gnus-summary-fetch-faq (&optional faq-dir)
7087   "Fetch the FAQ for the current group.
7088 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7089 in."
7090   (interactive
7091    (list
7092     (when current-prefix-arg
7093       (completing-read
7094        "FAQ dir: " (and (listp gnus-group-faq-directory)
7095                         (mapcar 'list
7096                                 gnus-group-faq-directory))))))
7097   (let (gnus-faq-buffer)
7098     (when (setq gnus-faq-buffer
7099                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7100       (gnus-configure-windows 'summary-faq))))
7101
7102 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7103 (defun gnus-summary-describe-group (&optional force)
7104   "Describe the current newsgroup."
7105   (interactive "P")
7106   (gnus-group-describe-group force gnus-newsgroup-name))
7107
7108 (defun gnus-summary-describe-briefly ()
7109   "Describe summary mode commands briefly."
7110   (interactive)
7111   (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")))
7112
7113 ;; Walking around group mode buffer from summary mode.
7114
7115 (defun gnus-summary-next-group (&optional no-article target-group backward)
7116   "Exit current newsgroup and then select next unread newsgroup.
7117 If prefix argument NO-ARTICLE is non-nil, no article is selected
7118 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7119 previous group instead."
7120   (interactive "P")
7121   ;; Stop pre-fetching.
7122   (gnus-async-halt-prefetch)
7123   (let ((current-group gnus-newsgroup-name)
7124         (current-buffer (current-buffer))
7125         entered)
7126     ;; First we semi-exit this group to update Xrefs and all variables.
7127     ;; We can't do a real exit, because the window conf must remain
7128     ;; the same in case the user is prompted for info, and we don't
7129     ;; want the window conf to change before that...
7130     (gnus-summary-exit t)
7131     (while (not entered)
7132       ;; Then we find what group we are supposed to enter.
7133       (set-buffer gnus-group-buffer)
7134       (gnus-group-jump-to-group current-group)
7135       (setq target-group
7136             (or target-group
7137                 (if (eq gnus-keep-same-level 'best)
7138                     (gnus-summary-best-group gnus-newsgroup-name)
7139                   (gnus-summary-search-group backward gnus-keep-same-level))))
7140       (if (not target-group)
7141           ;; There are no further groups, so we return to the group
7142           ;; buffer.
7143           (progn
7144             (gnus-message 5 "Returning to the group buffer")
7145             (setq entered t)
7146             (when (gnus-buffer-live-p current-buffer)
7147               (set-buffer current-buffer)
7148               (gnus-summary-exit))
7149             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7150         ;; We try to enter the target group.
7151         (gnus-group-jump-to-group target-group)
7152         (let ((unreads (gnus-group-group-unread)))
7153           (if (and (or (eq t unreads)
7154                        (and unreads (not (zerop unreads))))
7155                    (gnus-summary-read-group
7156                     target-group nil no-article
7157                     (and (buffer-name current-buffer) current-buffer)
7158                     nil backward))
7159               (setq entered t)
7160             (setq current-group target-group
7161                   target-group nil)))))))
7162
7163 (defun gnus-summary-prev-group (&optional no-article)
7164   "Exit current newsgroup and then select previous unread newsgroup.
7165 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7166   (interactive "P")
7167   (gnus-summary-next-group no-article nil t))
7168
7169 ;; Walking around summary lines.
7170
7171 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7172   "Go to the first subject satisfying any non-nil constraint.
7173 If UNREAD is non-nil, the article should be unread.
7174 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7175 If UNSEEN is non-nil, the article should be unseen.
7176 Returns the article selected or nil if there are no matching articles."
7177   (interactive "P")
7178   (cond
7179    ;; Empty summary.
7180    ((null gnus-newsgroup-data)
7181     (gnus-message 3 "No articles in the group")
7182     nil)
7183    ;; Pick the first article.
7184    ((not (or unread undownloaded unseen))
7185     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7186     (gnus-data-number (car gnus-newsgroup-data)))
7187    ;; Find the first unread article.
7188    (t
7189     (let ((data gnus-newsgroup-data))
7190       (while (and data
7191                   (let ((num (gnus-data-number (car data))))
7192                     (or (memq num gnus-newsgroup-unfetched)
7193                         (not (or (and unread
7194                                       (memq num gnus-newsgroup-unreads))
7195                                  (and undownloaded
7196                                       (memq num gnus-newsgroup-undownloaded))
7197                                  (and unseen
7198                                       (memq num gnus-newsgroup-unseen)))))))
7199         (setq data (cdr data)))
7200       (prog1
7201           (if data
7202               (progn
7203                 (goto-char (gnus-data-pos (car data)))
7204                 (gnus-data-number (car data)))
7205             (gnus-message 3 "No more%s articles"
7206                           (let* ((r (when unread " unread"))
7207                                  (d (when undownloaded " undownloaded"))
7208                                  (s (when unseen " unseen"))
7209                                  (l (delq nil (list r d s))))
7210                             (cond ((= 3 (length l))
7211                                    (concat r "," d ", or" s))
7212                                   ((= 2 (length l))
7213                                    (concat (car l) ", or" (cadr l)))
7214                                   ((= 1 (length l))
7215                                    (car l))
7216                                   (t
7217                                    ""))))
7218             nil
7219             )
7220         (gnus-summary-position-point))))))
7221
7222 (defun gnus-summary-next-subject (n &optional unread dont-display)
7223   "Go to next N'th summary line.
7224 If N is negative, go to the previous N'th subject line.
7225 If UNREAD is non-nil, only unread articles are selected.
7226 The difference between N and the actual number of steps taken is
7227 returned."
7228   (interactive "p")
7229   (let ((backward (< n 0))
7230         (n (abs n)))
7231     (while (and (> n 0)
7232                 (if backward
7233                     (gnus-summary-find-prev unread)
7234                   (gnus-summary-find-next unread)))
7235       (unless (zerop (setq n (1- n)))
7236         (gnus-summary-show-thread)))
7237     (when (/= 0 n)
7238       (gnus-message 7 "No more%s articles"
7239                     (if unread " unread" "")))
7240     (unless dont-display
7241       (gnus-summary-recenter)
7242       (gnus-summary-position-point))
7243     n))
7244
7245 (defun gnus-summary-next-unread-subject (n)
7246   "Go to next N'th unread summary line."
7247   (interactive "p")
7248   (gnus-summary-next-subject n t))
7249
7250 (defun gnus-summary-prev-subject (n &optional unread)
7251   "Go to previous N'th summary line.
7252 If optional argument UNREAD is non-nil, only unread article is selected."
7253   (interactive "p")
7254   (gnus-summary-next-subject (- n) unread))
7255
7256 (defun gnus-summary-prev-unread-subject (n)
7257   "Go to previous N'th unread summary line."
7258   (interactive "p")
7259   (gnus-summary-next-subject (- n) t))
7260
7261 (defun gnus-summary-goto-subjects (articles)
7262   "Insert the subject header for ARTICLES in the current buffer."
7263   (save-excursion
7264     (dolist (article articles)
7265       (gnus-summary-goto-subject article t)))
7266   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7267   (gnus-summary-position-point))
7268
7269 (defun gnus-summary-goto-subject (article &optional force silent)
7270   "Go the subject line of ARTICLE.
7271 If FORCE, also allow jumping to articles not currently shown."
7272   (interactive "nArticle number: ")
7273   (unless (numberp article)
7274     (error "Article %s is not a number" article))
7275   (let ((b (point))
7276         (data (gnus-data-find article)))
7277     ;; We read in the article if we have to.
7278     (and (not data)
7279          force
7280          (gnus-summary-insert-subject
7281           article
7282           (if (or (numberp force) (vectorp force)) force)
7283           t)
7284          (setq data (gnus-data-find article)))
7285     (goto-char b)
7286     (if (not data)
7287         (progn
7288           (unless silent
7289             (gnus-message 3 "Can't find article %d" article))
7290           nil)
7291       (let ((pt (gnus-data-pos data)))
7292         (goto-char pt)
7293         (gnus-summary-set-article-display-arrow pt))
7294       (gnus-summary-position-point)
7295       article)))
7296
7297 ;; Walking around summary lines with displaying articles.
7298
7299 (defun gnus-summary-expand-window (&optional arg)
7300   "Make the summary buffer take up the entire Emacs frame.
7301 Given a prefix, will force an `article' buffer configuration."
7302   (interactive "P")
7303   (if arg
7304       (gnus-configure-windows 'article 'force)
7305     (gnus-configure-windows 'summary 'force)))
7306
7307 (defun gnus-summary-display-article (article &optional all-header)
7308   "Display ARTICLE in article buffer."
7309   (when (gnus-buffer-live-p gnus-article-buffer)
7310     (with-current-buffer gnus-article-buffer
7311       (mm-enable-multibyte)))
7312   (gnus-set-global-variables)
7313   (when (gnus-buffer-live-p gnus-article-buffer)
7314     (with-current-buffer gnus-article-buffer
7315       (setq gnus-article-charset gnus-newsgroup-charset)
7316       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7317       (mm-enable-multibyte)))
7318   (if (null article)
7319       nil
7320     (prog1
7321         (if gnus-summary-display-article-function
7322             (funcall gnus-summary-display-article-function article all-header)
7323           (gnus-article-prepare article all-header))
7324       (gnus-run-hooks 'gnus-select-article-hook)
7325       (when (and gnus-current-article
7326                  (not (zerop gnus-current-article)))
7327         (gnus-summary-goto-subject gnus-current-article))
7328       (gnus-summary-recenter)
7329       (when (and gnus-use-trees gnus-show-threads)
7330         (gnus-possibly-generate-tree article)
7331         (gnus-highlight-selected-tree article))
7332       ;; Successfully display article.
7333       (gnus-article-set-window-start
7334        (cdr (assq article gnus-newsgroup-bookmarks))))))
7335
7336 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7337   "Select the current article.
7338 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7339 non-nil, the article will be re-fetched even if it already present in
7340 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7341 be displayed."
7342   ;; Make sure we are in the summary buffer to work around bbdb bug.
7343   (unless (eq major-mode 'gnus-summary-mode)
7344     (set-buffer gnus-summary-buffer))
7345   (let ((article (or article (gnus-summary-article-number)))
7346         (all-headers (not (not all-headers))) ;Must be t or nil.
7347         gnus-summary-display-article-function)
7348     (and (not pseudo)
7349          (gnus-summary-article-pseudo-p article)
7350          (error "This is a pseudo-article"))
7351     (save-excursion
7352       (set-buffer gnus-summary-buffer)
7353       (if (or (and gnus-single-article-buffer
7354                    (or (null gnus-current-article)
7355                        (null gnus-article-current)
7356                        (null (get-buffer gnus-article-buffer))
7357                        (not (eq article (cdr gnus-article-current)))
7358                        (not (equal (car gnus-article-current)
7359                                    gnus-newsgroup-name))))
7360               (and (not gnus-single-article-buffer)
7361                    (or (null gnus-current-article)
7362                        (not (eq gnus-current-article article))))
7363               force)
7364           ;; The requested article is different from the current article.
7365           (progn
7366             (gnus-summary-display-article article all-headers)
7367             (when (gnus-buffer-live-p gnus-article-buffer)
7368               (with-current-buffer gnus-article-buffer
7369                 (if (not gnus-article-decoded-p) ;; a local variable
7370                     (mm-disable-multibyte))))
7371             (gnus-article-set-window-start
7372              (cdr (assq article gnus-newsgroup-bookmarks)))
7373             article)
7374         'old))))
7375
7376 (defun gnus-summary-force-verify-and-decrypt ()
7377   "Display buttons for signed/encrypted parts and verify/decrypt them."
7378   (interactive)
7379   (let ((mm-verify-option 'known)
7380         (mm-decrypt-option 'known)
7381         (gnus-article-emulate-mime t)
7382         (gnus-buttonized-mime-types (append (list "multipart/signed"
7383                                                   "multipart/encrypted")
7384                                             gnus-buttonized-mime-types)))
7385     (gnus-summary-select-article nil 'force)))
7386
7387 (defun gnus-summary-set-current-mark (&optional current-mark)
7388   "Obsolete function."
7389   nil)
7390
7391 (defun gnus-summary-next-article (&optional unread subject backward push)
7392   "Select the next article.
7393 If UNREAD, only unread articles are selected.
7394 If SUBJECT, only articles with SUBJECT are selected.
7395 If BACKWARD, the previous article is selected instead of the next."
7396   (interactive "P")
7397   (cond
7398    ;; Is there such an article?
7399    ((and (gnus-summary-search-forward unread subject backward)
7400          (or (gnus-summary-display-article (gnus-summary-article-number))
7401              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7402     (gnus-summary-position-point))
7403    ;; If not, we try the first unread, if that is wanted.
7404    ((and subject
7405          gnus-auto-select-same
7406          (gnus-summary-first-unread-article))
7407     (gnus-summary-position-point)
7408     (gnus-message 6 "Wrapped"))
7409    ;; Try to get next/previous article not displayed in this group.
7410    ((and gnus-auto-extend-newsgroup
7411          (not unread) (not subject))
7412     (gnus-summary-goto-article
7413      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7414      nil (count-lines (point-min) (point))))
7415    ;; Go to next/previous group.
7416    (t
7417     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7418       (gnus-summary-jump-to-group gnus-newsgroup-name))
7419     (let ((cmd last-command-char)
7420           (point
7421            (with-current-buffer gnus-group-buffer
7422              (point)))
7423           (group
7424            (if (eq gnus-keep-same-level 'best)
7425                (gnus-summary-best-group gnus-newsgroup-name)
7426              (gnus-summary-search-group backward gnus-keep-same-level))))
7427       ;; For some reason, the group window gets selected.  We change
7428       ;; it back.
7429       (select-window (get-buffer-window (current-buffer)))
7430       ;; Select next unread newsgroup automagically.
7431       (cond
7432        ((or (not gnus-auto-select-next)
7433             (not cmd))
7434         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7435        ((or (eq gnus-auto-select-next 'quietly)
7436             (and (eq gnus-auto-select-next 'slightly-quietly)
7437                  push)
7438             (and (eq gnus-auto-select-next 'almost-quietly)
7439                  (gnus-summary-last-article-p)))
7440         ;; Select quietly.
7441         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7442             (gnus-summary-exit)
7443           (gnus-message 7 "No more%s articles (%s)..."
7444                         (if unread " unread" "")
7445                         (if group (concat "selecting " group)
7446                           "exiting"))
7447           (gnus-summary-next-group nil group backward)))
7448        (t
7449         (when (gnus-key-press-event-p last-input-event)
7450           (gnus-summary-walk-group-buffer
7451            gnus-newsgroup-name cmd unread backward point))))))))
7452
7453 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7454   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7455                       (?\C-p (gnus-group-prev-unread-group 1))))
7456         (cursor-in-echo-area t)
7457         keve key group ended prompt)
7458     (save-excursion
7459       (set-buffer gnus-group-buffer)
7460       (goto-char start)
7461       (setq group
7462             (if (eq gnus-keep-same-level 'best)
7463                 (gnus-summary-best-group gnus-newsgroup-name)
7464               (gnus-summary-search-group backward gnus-keep-same-level))))
7465     (while (not ended)
7466       (setq prompt
7467             (format
7468              "No more%s articles%s " (if unread " unread" "")
7469              (if (and group
7470                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7471                  (format " (Type %s for %s [%s])"
7472                          (single-key-description cmd)
7473                          (gnus-group-decoded-name group)
7474                          (gnus-group-unread group))
7475                (format " (Type %s to exit %s)"
7476                        (single-key-description cmd)
7477                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7478       ;; Confirm auto selection.
7479       (setq key (car (setq keve (gnus-read-event-char prompt)))
7480             ended t)
7481       (cond
7482        ((assq key keystrokes)
7483         (let ((obuf (current-buffer)))
7484           (switch-to-buffer gnus-group-buffer)
7485           (when group
7486             (gnus-group-jump-to-group group))
7487           (eval (cadr (assq key keystrokes)))
7488           (setq group (gnus-group-group-name))
7489           (switch-to-buffer obuf))
7490         (setq ended nil))
7491        ((equal key cmd)
7492         (if (or (not group)
7493                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7494             (gnus-summary-exit)
7495           (gnus-summary-next-group nil group backward)))
7496        (t
7497         (push (cdr keve) unread-command-events))))))
7498
7499 (defun gnus-summary-next-unread-article ()
7500   "Select unread article after current one."
7501   (interactive)
7502   (gnus-summary-next-article
7503    (or (not (eq gnus-summary-goto-unread 'never))
7504        (gnus-summary-last-article-p (gnus-summary-article-number)))
7505    (and gnus-auto-select-same
7506         (gnus-summary-article-subject))))
7507
7508 (defun gnus-summary-prev-article (&optional unread subject)
7509   "Select the article after the current one.
7510 If UNREAD is non-nil, only unread articles are selected."
7511   (interactive "P")
7512   (gnus-summary-next-article unread subject t))
7513
7514 (defun gnus-summary-prev-unread-article ()
7515   "Select unread article before current one."
7516   (interactive)
7517   (gnus-summary-prev-article
7518    (or (not (eq gnus-summary-goto-unread 'never))
7519        (gnus-summary-first-article-p (gnus-summary-article-number)))
7520    (and gnus-auto-select-same
7521         (gnus-summary-article-subject))))
7522
7523 (defun gnus-summary-next-page (&optional lines circular stop)
7524   "Show next page of the selected article.
7525 If at the end of the current article, select the next article.
7526 LINES says how many lines should be scrolled up.
7527
7528 If CIRCULAR is non-nil, go to the start of the article instead of
7529 selecting the next article when reaching the end of the current
7530 article.
7531
7532 If STOP is non-nil, just stop when reaching the end of the message.
7533
7534 Also see the variable `gnus-article-skip-boring'."
7535   (interactive "P")
7536   (setq gnus-summary-buffer (current-buffer))
7537   (gnus-set-global-variables)
7538   (let ((article (gnus-summary-article-number))
7539         (article-window (get-buffer-window gnus-article-buffer t))
7540         endp)
7541     ;; If the buffer is empty, we have no article.
7542     (unless article
7543       (error "No article to select"))
7544     (gnus-configure-windows 'article)
7545     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7546         (if (and (eq gnus-summary-goto-unread 'never)
7547                  (not (gnus-summary-last-article-p article)))
7548             (gnus-summary-next-article)
7549           (gnus-summary-next-unread-article))
7550       (if (or (null gnus-current-article)
7551               (null gnus-article-current)
7552               (/= article (cdr gnus-article-current))
7553               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7554           ;; Selected subject is different from current article's.
7555           (gnus-summary-display-article article)
7556         (when article-window
7557           (gnus-eval-in-buffer-window gnus-article-buffer
7558             (setq endp (or (gnus-article-next-page lines)
7559                            (gnus-article-only-boring-p))))
7560           (when endp
7561             (cond (stop
7562                    (gnus-message 3 "End of message"))
7563                   (circular
7564                    (gnus-summary-beginning-of-article))
7565                   (lines
7566                    (gnus-message 3 "End of message"))
7567                   ((null lines)
7568                    (if (and (eq gnus-summary-goto-unread 'never)
7569                             (not (gnus-summary-last-article-p article)))
7570                        (gnus-summary-next-article)
7571                      (gnus-summary-next-unread-article))))))))
7572     (gnus-summary-recenter)
7573     (gnus-summary-position-point)))
7574
7575 (defun gnus-summary-prev-page (&optional lines move)
7576   "Show previous page of selected article.
7577 Argument LINES specifies lines to be scrolled down.
7578 If MOVE, move to the previous unread article if point is at
7579 the beginning of the buffer."
7580   (interactive "P")
7581   (let ((article (gnus-summary-article-number))
7582         (article-window (get-buffer-window gnus-article-buffer t))
7583         endp)
7584     (gnus-configure-windows 'article)
7585     (if (or (null gnus-current-article)
7586             (null gnus-article-current)
7587             (/= article (cdr gnus-article-current))
7588             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7589         ;; Selected subject is different from current article's.
7590         (gnus-summary-display-article article)
7591       (gnus-summary-recenter)
7592       (when article-window
7593         (gnus-eval-in-buffer-window gnus-article-buffer
7594           (setq endp (gnus-article-prev-page lines)))
7595         (when (and move endp)
7596           (cond (lines
7597                  (gnus-message 3 "Beginning of message"))
7598                 ((null lines)
7599                  (if (and (eq gnus-summary-goto-unread 'never)
7600                           (not (gnus-summary-first-article-p article)))
7601                      (gnus-summary-prev-article)
7602                    (gnus-summary-prev-unread-article))))))))
7603   (gnus-summary-position-point))
7604
7605 (defun gnus-summary-prev-page-or-article (&optional lines)
7606   "Show previous page of selected article.
7607 Argument LINES specifies lines to be scrolled down.
7608 If at the beginning of the article, go to the next article."
7609   (interactive "P")
7610   (gnus-summary-prev-page lines t))
7611
7612 (defun gnus-summary-scroll-up (lines)
7613   "Scroll up (or down) one line current article.
7614 Argument LINES specifies lines to be scrolled up (or down if negative)."
7615   (interactive "p")
7616   (gnus-configure-windows 'article)
7617   (gnus-summary-show-thread)
7618   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7619     (gnus-eval-in-buffer-window gnus-article-buffer
7620       (cond ((> lines 0)
7621              (when (gnus-article-next-page lines)
7622                (gnus-message 3 "End of message")))
7623             ((< lines 0)
7624              (gnus-article-prev-page (- lines))))))
7625   (gnus-summary-recenter)
7626   (gnus-summary-position-point))
7627
7628 (defun gnus-summary-scroll-down (lines)
7629   "Scroll down (or up) one line current article.
7630 Argument LINES specifies lines to be scrolled down (or up if negative)."
7631   (interactive "p")
7632   (gnus-summary-scroll-up (- lines)))
7633
7634 (defun gnus-summary-next-same-subject ()
7635   "Select next article which has the same subject as current one."
7636   (interactive)
7637   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7638
7639 (defun gnus-summary-prev-same-subject ()
7640   "Select previous article which has the same subject as current one."
7641   (interactive)
7642   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7643
7644 (defun gnus-summary-next-unread-same-subject ()
7645   "Select next unread article which has the same subject as current one."
7646   (interactive)
7647   (gnus-summary-next-article t (gnus-summary-article-subject)))
7648
7649 (defun gnus-summary-prev-unread-same-subject ()
7650   "Select previous unread article which has the same subject as current one."
7651   (interactive)
7652   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7653
7654 (defun gnus-summary-first-unread-article ()
7655   "Select the first unread article.
7656 Return nil if there are no unread articles."
7657   (interactive)
7658   (prog1
7659       (when (gnus-summary-first-subject t)
7660         (gnus-summary-show-thread)
7661         (gnus-summary-first-subject t)
7662         (gnus-summary-display-article (gnus-summary-article-number)))
7663     (gnus-summary-position-point)))
7664
7665 (defun gnus-summary-first-unread-subject ()
7666   "Place the point on the subject line of the first unread article.
7667 Return nil if there are no unread articles."
7668   (interactive)
7669   (prog1
7670       (when (gnus-summary-first-subject t)
7671         (gnus-summary-show-thread)
7672         (gnus-summary-first-subject t))
7673     (gnus-summary-position-point)))
7674
7675 (defun gnus-summary-first-unseen-subject ()
7676   "Place the point on the subject line of the first unseen article.
7677 Return nil if there are no unseen articles."
7678   (interactive)
7679   (prog1
7680       (when (gnus-summary-first-subject nil nil t)
7681         (gnus-summary-show-thread)
7682         (gnus-summary-first-subject nil nil t))
7683     (gnus-summary-position-point)))
7684
7685 (defun gnus-summary-first-unseen-or-unread-subject ()
7686   "Place the point on the subject line of the first unseen article or,
7687 if all article have been seen, on the subject line of the first unread
7688 article."
7689   (interactive)
7690   (prog1
7691       (unless (when (gnus-summary-first-subject nil nil t)
7692                 (gnus-summary-show-thread)
7693                 (gnus-summary-first-subject nil nil t))
7694         (when (gnus-summary-first-subject t)
7695           (gnus-summary-show-thread)
7696           (gnus-summary-first-subject t)))
7697     (gnus-summary-position-point)))
7698
7699 (defun gnus-summary-first-article ()
7700   "Select the first article.
7701 Return nil if there are no articles."
7702   (interactive)
7703   (prog1
7704       (when (gnus-summary-first-subject)
7705         (gnus-summary-show-thread)
7706         (gnus-summary-first-subject)
7707         (gnus-summary-display-article (gnus-summary-article-number)))
7708     (gnus-summary-position-point)))
7709
7710 (defun gnus-summary-best-unread-article (&optional arg)
7711   "Select the unread article with the highest score.
7712 If given a prefix argument, select the next unread article that has a
7713 score higher than the default score."
7714   (interactive "P")
7715   (let ((article (if arg
7716                      (gnus-summary-better-unread-subject)
7717                    (gnus-summary-best-unread-subject))))
7718     (if article
7719         (gnus-summary-goto-article article)
7720       (error "No unread articles"))))
7721
7722 (defun gnus-summary-best-unread-subject ()
7723   "Select the unread subject with the highest score."
7724   (interactive)
7725   (let ((best -1000000)
7726         (data gnus-newsgroup-data)
7727         article score)
7728     (while data
7729       (and (gnus-data-unread-p (car data))
7730            (> (setq score
7731                     (gnus-summary-article-score (gnus-data-number (car data))))
7732               best)
7733            (setq best score
7734                  article (gnus-data-number (car data))))
7735       (setq data (cdr data)))
7736     (when article
7737       (gnus-summary-goto-subject article))
7738     (gnus-summary-position-point)
7739     article))
7740
7741 (defun gnus-summary-better-unread-subject ()
7742   "Select the first unread subject that has a score over the default score."
7743   (interactive)
7744   (let ((data gnus-newsgroup-data)
7745         article score)
7746     (while (and (setq article (gnus-data-number (car data)))
7747                 (or (gnus-data-read-p (car data))
7748                     (not (> (gnus-summary-article-score article)
7749                             gnus-summary-default-score))))
7750       (setq data (cdr data)))
7751     (when article
7752       (gnus-summary-goto-subject article))
7753     (gnus-summary-position-point)
7754     article))
7755
7756 (defun gnus-summary-last-subject ()
7757   "Go to the last displayed subject line in the group."
7758   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7759     (when article
7760       (gnus-summary-goto-subject article))))
7761
7762 (defun gnus-summary-goto-article (article &optional all-headers force)
7763   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7764 If ALL-HEADERS is non-nil, no header lines are hidden.
7765 If FORCE, go to the article even if it isn't displayed.  If FORCE
7766 is a number, it is the line the article is to be displayed on."
7767   (interactive
7768    (list
7769     (completing-read
7770      "Article number or Message-ID: "
7771      (mapcar (lambda (number) (list (int-to-string number)))
7772              gnus-newsgroup-limit))
7773     current-prefix-arg
7774     t))
7775   (prog1
7776       (if (and (stringp article)
7777                (string-match "@\\|%40" article))
7778           (gnus-summary-refer-article article)
7779         (when (stringp article)
7780           (setq article (string-to-number article)))
7781         (if (gnus-summary-goto-subject article force)
7782             (gnus-summary-display-article article all-headers)
7783           (gnus-message 4 "Couldn't go to article %s" article) nil))
7784     (gnus-summary-position-point)))
7785
7786 (defun gnus-summary-goto-last-article ()
7787   "Go to the previously read article."
7788   (interactive)
7789   (prog1
7790       (when gnus-last-article
7791         (gnus-summary-goto-article gnus-last-article nil t))
7792     (gnus-summary-position-point)))
7793
7794 (defun gnus-summary-pop-article (number)
7795   "Pop one article off the history and go to the previous.
7796 NUMBER articles will be popped off."
7797   (interactive "p")
7798   (let (to)
7799     (setq gnus-newsgroup-history
7800           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7801     (if to
7802         (gnus-summary-goto-article (car to) nil t)
7803       (error "Article history empty")))
7804   (gnus-summary-position-point))
7805
7806 ;; Summary commands and functions for limiting the summary buffer.
7807
7808 (defun gnus-summary-limit-to-articles (n)
7809   "Limit the summary buffer to the next N articles.
7810 If not given a prefix, use the process marked articles instead."
7811   (interactive "P")
7812   (prog1
7813       (let ((articles (gnus-summary-work-articles n)))
7814         (setq gnus-newsgroup-processable nil)
7815         (gnus-summary-limit articles))
7816     (gnus-summary-position-point)))
7817
7818 (defun gnus-summary-pop-limit (&optional total)
7819   "Restore the previous limit.
7820 If given a prefix, remove all limits."
7821   (interactive "P")
7822   (when total
7823     (setq gnus-newsgroup-limits
7824           (list (mapcar (lambda (h) (mail-header-number h))
7825                         gnus-newsgroup-headers))))
7826   (unless gnus-newsgroup-limits
7827     (error "No limit to pop"))
7828   (prog1
7829       (gnus-summary-limit nil 'pop)
7830     (gnus-summary-position-point)))
7831
7832 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7833   "Limit the summary buffer to articles that have subjects that match a regexp.
7834 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7835   (interactive
7836    (list (read-string (if current-prefix-arg
7837                           "Exclude subject (regexp): "
7838                         "Limit to subject (regexp): "))
7839          nil current-prefix-arg))
7840   (unless header
7841     (setq header "subject"))
7842   (when (not (equal "" subject))
7843     (prog1
7844         (let ((articles (gnus-summary-find-matching
7845                          (or header "subject") subject 'all nil nil
7846                          not-matching)))
7847           (unless articles
7848             (error "Found no matches for \"%s\"" subject))
7849           (gnus-summary-limit articles))
7850       (gnus-summary-position-point))))
7851
7852 (defun gnus-summary-limit-to-author (from &optional not-matching)
7853   "Limit the summary buffer to articles that have authors that match a regexp.
7854 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7855   (interactive
7856    (list (read-string (if current-prefix-arg
7857                           "Exclude author (regexp): "
7858                         "Limit to author (regexp): "))
7859          current-prefix-arg))
7860   (gnus-summary-limit-to-subject from "from" not-matching))
7861
7862 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7863   "Limit the summary buffer to articles with the given RECIPIENT.
7864
7865 If NOT-MATCHING, exclude RECIPIENT.
7866
7867 To and Cc headers are checked.  You need to include them in
7868 `nnmail-extra-headers'."
7869   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7870   (interactive
7871    (list (read-string (format "%s recipient (regexp): "
7872                               (if current-prefix-arg "Exclude" "Limit to")))
7873          current-prefix-arg))
7874   (when (not (equal "" recipient))
7875     (prog1 (let* ((to
7876                    (if (memq 'To nnmail-extra-headers)
7877                        (gnus-summary-find-matching
7878                         (cons 'extra 'To) recipient 'all nil nil
7879                         not-matching)
7880                      (gnus-message
7881                       1 "`To' isn't present in `nnmail-extra-headers'")
7882                      (sit-for 1)
7883                      nil))
7884                   (cc
7885                    (if (memq 'Cc nnmail-extra-headers)
7886                        (gnus-summary-find-matching
7887                         (cons 'extra 'Cc) recipient 'all nil nil
7888                         not-matching)
7889                      (gnus-message
7890                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7891                      (sit-for 1)
7892                      nil))
7893                   (articles
7894                    (if not-matching
7895                        ;; We need the numbers that are in both lists:
7896                        (mapcar (lambda (a)
7897                                  (and (memq a to) a))
7898                                cc)
7899                      (nconc to cc))))
7900              (unless articles
7901                (error "Found no matches for \"%s\"" recipient))
7902              (gnus-summary-limit articles))
7903       (gnus-summary-position-point))))
7904
7905 (defun gnus-summary-limit-to-age (age &optional younger-p)
7906   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7907 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7908 articles that are younger than AGE days."
7909   (interactive
7910    (let ((younger current-prefix-arg)
7911          (days-got nil)
7912          days)
7913      (while (not days-got)
7914        (setq days (if younger
7915                       (read-string "Limit to articles younger than (in days, older when negative): ")
7916                     (read-string
7917                      "Limit to articles older than (in days, younger when negative): ")))
7918        (when (> (length days) 0)
7919          (setq days (read days)))
7920        (if (numberp days)
7921            (progn
7922              (setq days-got t)
7923              (when (< days 0)
7924                (setq younger (not younger))
7925                (setq days (* days -1))))
7926          (message "Please enter a number.")
7927          (sleep-for 1)))
7928      (list days younger)))
7929   (prog1
7930       (let ((data gnus-newsgroup-data)
7931             (cutoff (days-to-time age))
7932             articles d date is-younger)
7933         (while (setq d (pop data))
7934           (when (and (vectorp (gnus-data-header d))
7935                      (setq date (mail-header-date (gnus-data-header d))))
7936             (setq is-younger (time-less-p
7937                               (time-since (condition-case ()
7938                                               (date-to-time date)
7939                                             (error '(0 0))))
7940                               cutoff))
7941             (when (if younger-p
7942                       is-younger
7943                     (not is-younger))
7944               (push (gnus-data-number d) articles))))
7945         (gnus-summary-limit (nreverse articles)))
7946     (gnus-summary-position-point)))
7947
7948 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7949   "Limit the summary buffer to articles that match an 'extra' header."
7950   (interactive
7951    (let ((header
7952           (intern
7953            (gnus-completing-read-with-default
7954             (symbol-name (car gnus-extra-headers))
7955             (if current-prefix-arg
7956                 "Exclude extra header"
7957               "Limit extra header")
7958             (mapcar (lambda (x)
7959                       (cons (symbol-name x) x))
7960                     gnus-extra-headers)
7961             nil
7962             t))))
7963      (list header
7964            (read-string (format "%s header %s (regexp): "
7965                                 (if current-prefix-arg "Exclude" "Limit to")
7966                                 header))
7967            current-prefix-arg)))
7968   (when (not (equal "" regexp))
7969     (prog1
7970         (let ((articles (gnus-summary-find-matching
7971                          (cons 'extra header) regexp 'all nil nil
7972                          not-matching)))
7973           (unless articles
7974             (error "Found no matches for \"%s\"" regexp))
7975           (gnus-summary-limit articles))
7976       (gnus-summary-position-point))))
7977
7978 (defun gnus-summary-limit-to-display-predicate ()
7979   "Limit the summary buffer to the predicated in the `display' group parameter."
7980   (interactive)
7981   (unless gnus-newsgroup-display
7982     (error "There is no `display' group parameter"))
7983   (let (articles)
7984     (dolist (number gnus-newsgroup-articles)
7985       (when (funcall gnus-newsgroup-display)
7986         (push number articles)))
7987     (gnus-summary-limit articles))
7988   (gnus-summary-position-point))
7989
7990 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7991 (make-obsolete
7992  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7993
7994 (defun gnus-summary-limit-to-unread (&optional all)
7995   "Limit the summary buffer to articles that are not marked as read.
7996 If ALL is non-nil, limit strictly to unread articles."
7997   (interactive "P")
7998   (if all
7999       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8000     (gnus-summary-limit-to-marks
8001      ;; Concat all the marks that say that an article is read and have
8002      ;; those removed.
8003      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8004            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8005            gnus-low-score-mark gnus-expirable-mark
8006            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8007            gnus-duplicate-mark gnus-souped-mark)
8008      'reverse)))
8009
8010 (defun gnus-summary-limit-to-bodies (match &optional reverse)
8011   "Limit the summary buffer to articles that have bodies that match MATCH.
8012 If REVERSE (the prefix), limit to articles that don't match."
8013   (interactive "sMatch body (regexp): \nP")
8014   (let ((articles nil)
8015         (gnus-select-article-hook nil)  ;Disable hook.
8016         (gnus-article-prepare-hook nil)
8017         (gnus-use-article-prefetch nil)
8018         (gnus-keep-backlog nil)
8019         (gnus-break-pages nil)
8020         (gnus-summary-display-arrow nil)
8021         (gnus-updated-mode-lines nil)
8022         (gnus-auto-center-summary nil)
8023         (gnus-display-mime-function nil))
8024     (dolist (data gnus-newsgroup-data)
8025       (let (gnus-mark-article-hook)
8026         (gnus-summary-select-article t t nil (gnus-data-number data)))
8027       (save-excursion
8028         (set-buffer gnus-article-buffer)
8029         (article-goto-body)
8030         (let* ((case-fold-search t)
8031                (found (re-search-forward match nil t)))
8032           (when (or (and found
8033                          (not reverse))
8034                     (and (not found)
8035                          reverse))
8036             (push (gnus-data-number data) articles)))))
8037     (if (not articles)
8038         (message "No messages matched")
8039       (gnus-summary-limit articles)))
8040   (gnus-summary-position-point))
8041
8042 (defun gnus-summary-limit-to-replied (&optional unreplied)
8043   "Limit the summary buffer to replied articles.
8044 If UNREPLIED (the prefix), limit to unreplied articles."
8045   (interactive "P")
8046   (if unreplied
8047       (gnus-summary-limit
8048        (gnus-set-difference gnus-newsgroup-articles
8049         gnus-newsgroup-replied))
8050     (gnus-summary-limit gnus-newsgroup-replied))
8051   (gnus-summary-position-point))
8052
8053 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8054 (make-obsolete 'gnus-summary-delete-marked-with
8055                'gnus-summary-limit-exclude-marks)
8056
8057 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8058   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8059 If REVERSE, limit the summary buffer to articles that are marked
8060 with MARKS.  MARKS can either be a string of marks or a list of marks.
8061 Returns how many articles were removed."
8062   (interactive "sMarks: ")
8063   (gnus-summary-limit-to-marks marks t))
8064
8065 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8066   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8067 If REVERSE (the prefix), limit the summary buffer to articles that are
8068 not marked with MARKS.  MARKS can either be a string of marks or a
8069 list of marks.
8070 Returns how many articles were removed."
8071   (interactive "sMarks: \nP")
8072   (prog1
8073       (let ((data gnus-newsgroup-data)
8074             (marks (if (listp marks) marks
8075                      (append marks nil))) ; Transform to list.
8076             articles)
8077         (while data
8078           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8079                   (memq (gnus-data-mark (car data)) marks))
8080             (push (gnus-data-number (car data)) articles))
8081           (setq data (cdr data)))
8082         (gnus-summary-limit articles))
8083     (gnus-summary-position-point)))
8084
8085 (defun gnus-summary-limit-to-score (score)
8086   "Limit to articles with score at or above SCORE."
8087   (interactive "NLimit to articles with score of at least: ")
8088   (let ((data gnus-newsgroup-data)
8089         articles)
8090     (while data
8091       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8092                 score)
8093         (push (gnus-data-number (car data)) articles))
8094       (setq data (cdr data)))
8095     (prog1
8096         (gnus-summary-limit articles)
8097       (gnus-summary-position-point))))
8098
8099 (defun gnus-summary-limit-to-unseen ()
8100   "Limit to unseen articles."
8101   (interactive)
8102   (prog1
8103       (gnus-summary-limit gnus-newsgroup-unseen)
8104     (gnus-summary-position-point)))
8105
8106 (defun gnus-summary-limit-include-thread (id)
8107   "Display all the hidden articles that is in the thread with ID in it.
8108 When called interactively, ID is the Message-ID of the current
8109 article."
8110   (interactive (list (mail-header-id (gnus-summary-article-header))))
8111   (let ((articles (gnus-articles-in-thread
8112                    (gnus-id-to-thread (gnus-root-id id)))))
8113     (prog1
8114         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8115       (gnus-summary-limit-include-matching-articles
8116        "subject"
8117        (regexp-quote (gnus-simplify-subject-re
8118                       (mail-header-subject (gnus-id-to-header id)))))
8119       (gnus-summary-position-point))))
8120
8121 (defun gnus-summary-limit-include-matching-articles (header regexp)
8122   "Display all the hidden articles that have HEADERs that match REGEXP."
8123   (interactive (list (read-string "Match on header: ")
8124                      (read-string "Regexp: ")))
8125   (let ((articles (gnus-find-matching-articles header regexp)))
8126     (prog1
8127         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8128       (gnus-summary-position-point))))
8129
8130 (defun gnus-summary-insert-dormant-articles ()
8131   "Insert all the dormant articles for this group into the current buffer."
8132   (interactive)
8133   (let ((gnus-verbose (max 6 gnus-verbose)))
8134     (if (not gnus-newsgroup-dormant)
8135         (gnus-message 3 "No cached articles for this group")
8136       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8137
8138 (defun gnus-summary-limit-include-dormant ()
8139   "Display all the hidden articles that are marked as dormant.
8140 Note that this command only works on a subset of the articles currently
8141 fetched for this group."
8142   (interactive)
8143   (unless gnus-newsgroup-dormant
8144     (error "There are no dormant articles in this group"))
8145   (prog1
8146       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8147     (gnus-summary-position-point)))
8148
8149 (defun gnus-summary-limit-exclude-dormant ()
8150   "Hide all dormant articles."
8151   (interactive)
8152   (prog1
8153       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8154     (gnus-summary-position-point)))
8155
8156 (defun gnus-summary-limit-exclude-childless-dormant ()
8157   "Hide all dormant articles that have no children."
8158   (interactive)
8159   (let ((data (gnus-data-list t))
8160         articles d children)
8161     ;; Find all articles that are either not dormant or have
8162     ;; children.
8163     (while (setq d (pop data))
8164       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8165                 (and (setq children
8166                            (gnus-article-children (gnus-data-number d)))
8167                      (let (found)
8168                        (while children
8169                          (when (memq (car children) articles)
8170                            (setq children nil
8171                                  found t))
8172                          (pop children))
8173                        found)))
8174         (push (gnus-data-number d) articles)))
8175     ;; Do the limiting.
8176     (prog1
8177         (gnus-summary-limit articles)
8178       (gnus-summary-position-point))))
8179
8180 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8181   "Mark all unread excluded articles as read.
8182 If ALL, mark even excluded ticked and dormants as read."
8183   (interactive "P")
8184   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8185   (let ((articles (gnus-sorted-ndifference
8186                    (sort
8187                     (mapcar (lambda (h) (mail-header-number h))
8188                             gnus-newsgroup-headers)
8189                     '<)
8190                    gnus-newsgroup-limit))
8191         article)
8192     (setq gnus-newsgroup-unreads
8193           (gnus-sorted-intersection gnus-newsgroup-unreads
8194                                     gnus-newsgroup-limit))
8195     (if all
8196         (setq gnus-newsgroup-dormant nil
8197               gnus-newsgroup-marked nil
8198               gnus-newsgroup-reads
8199               (nconc
8200                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8201                gnus-newsgroup-reads))
8202       (while (setq article (pop articles))
8203         (unless (or (memq article gnus-newsgroup-dormant)
8204                     (memq article gnus-newsgroup-marked))
8205           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8206
8207 (defun gnus-summary-limit (articles &optional pop)
8208   (if pop
8209       ;; We pop the previous limit off the stack and use that.
8210       (setq articles (car gnus-newsgroup-limits)
8211             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8212     ;; We use the new limit, so we push the old limit on the stack.
8213     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8214   ;; Set the limit.
8215   (setq gnus-newsgroup-limit articles)
8216   (let ((total (length gnus-newsgroup-data))
8217         (data (gnus-data-find-list (gnus-summary-article-number)))
8218         (gnus-summary-mark-below nil)   ; Inhibit this.
8219         found)
8220     ;; This will do all the work of generating the new summary buffer
8221     ;; according to the new limit.
8222     (gnus-summary-prepare)
8223     ;; Hide any threads, possibly.
8224     (gnus-summary-maybe-hide-threads)
8225     ;; Try to return to the article you were at, or one in the
8226     ;; neighborhood.
8227     (when data
8228       ;; We try to find some article after the current one.
8229       (while data
8230         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8231           (setq data nil
8232                 found t))
8233         (setq data (cdr data))))
8234     (unless found
8235       ;; If there is no data, that means that we were after the last
8236       ;; article.  The same goes when we can't find any articles
8237       ;; after the current one.
8238       (goto-char (point-max))
8239       (gnus-summary-find-prev))
8240     (gnus-set-mode-line 'summary)
8241     ;; We return how many articles were removed from the summary
8242     ;; buffer as a result of the new limit.
8243     (- total (length gnus-newsgroup-data))))
8244
8245 (defsubst gnus-invisible-cut-children (threads)
8246   (let ((num 0))
8247     (while threads
8248       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8249         (incf num))
8250       (pop threads))
8251     (< num 2)))
8252
8253 (defsubst gnus-cut-thread (thread)
8254   "Go forwards in the thread until we find an article that we want to display."
8255   (when (or (eq gnus-fetch-old-headers 'some)
8256             (eq gnus-fetch-old-headers 'invisible)
8257             (numberp gnus-fetch-old-headers)
8258             (eq gnus-build-sparse-threads 'some)
8259             (eq gnus-build-sparse-threads 'more))
8260     ;; Deal with old-fetched headers and sparse threads.
8261     (while (and
8262             thread
8263             (or
8264              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8265              (gnus-summary-article-ancient-p
8266               (mail-header-number (car thread))))
8267             (if (or (<= (length (cdr thread)) 1)
8268                     (eq gnus-fetch-old-headers 'invisible))
8269                 (setq gnus-newsgroup-limit
8270                       (delq (mail-header-number (car thread))
8271                             gnus-newsgroup-limit)
8272                       thread (cadr thread))
8273               (when (gnus-invisible-cut-children (cdr thread))
8274                 (let ((th (cdr thread)))
8275                   (while th
8276                     (if (memq (mail-header-number (caar th))
8277                               gnus-newsgroup-limit)
8278                         (setq thread (car th)
8279                               th nil)
8280                       (setq th (cdr th))))))))))
8281   thread)
8282
8283 (defun gnus-cut-threads (threads)
8284   "Cut off all uninteresting articles from the beginning of THREADS."
8285   (when (or (eq gnus-fetch-old-headers 'some)
8286             (eq gnus-fetch-old-headers 'invisible)
8287             (numberp gnus-fetch-old-headers)
8288             (eq gnus-build-sparse-threads 'some)
8289             (eq gnus-build-sparse-threads 'more))
8290     (let ((th threads))
8291       (while th
8292         (setcar th (gnus-cut-thread (car th)))
8293         (setq th (cdr th)))))
8294   ;; Remove nixed out threads.
8295   (delq nil threads))
8296
8297 (defun gnus-summary-initial-limit (&optional show-if-empty)
8298   "Figure out what the initial limit is supposed to be on group entry.
8299 This entails weeding out unwanted dormants, low-scored articles,
8300 fetch-old-headers verbiage, and so on."
8301   ;; Most groups have nothing to remove.
8302   (if (or gnus-inhibit-limiting
8303           (and (null gnus-newsgroup-dormant)
8304                (eq gnus-newsgroup-display 'gnus-not-ignore)
8305                (not (eq gnus-fetch-old-headers 'some))
8306                (not (numberp gnus-fetch-old-headers))
8307                (not (eq gnus-fetch-old-headers 'invisible))
8308                (null gnus-summary-expunge-below)
8309                (not (eq gnus-build-sparse-threads 'some))
8310                (not (eq gnus-build-sparse-threads 'more))
8311                (null gnus-thread-expunge-below)
8312                (not gnus-use-nocem)))
8313       ()                                ; Do nothing.
8314     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8315     (setq gnus-newsgroup-limit nil)
8316     (mapatoms
8317      (lambda (node)
8318        (unless (car (symbol-value node))
8319          ;; These threads have no parents -- they are roots.
8320          (let ((nodes (cdr (symbol-value node)))
8321                thread)
8322            (while nodes
8323              (if (and gnus-thread-expunge-below
8324                       (< (gnus-thread-total-score (car nodes))
8325                          gnus-thread-expunge-below))
8326                  (gnus-expunge-thread (pop nodes))
8327                (setq thread (pop nodes))
8328                (gnus-summary-limit-children thread))))))
8329      gnus-newsgroup-dependencies)
8330     ;; If this limitation resulted in an empty group, we might
8331     ;; pop the previous limit and use it instead.
8332     (when (and (not gnus-newsgroup-limit)
8333                show-if-empty)
8334       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8335     gnus-newsgroup-limit))
8336
8337 (defun gnus-summary-limit-children (thread)
8338   "Return 1 if this subthread is visible and 0 if it is not."
8339   ;; First we get the number of visible children to this thread.  This
8340   ;; is done by recursing down the thread using this function, so this
8341   ;; will really go down to a leaf article first, before slowly
8342   ;; working its way up towards the root.
8343   (when thread
8344     (let* ((max-lisp-eval-depth 5000)
8345            (children
8346            (if (cdr thread)
8347                (apply '+ (mapcar 'gnus-summary-limit-children
8348                                  (cdr thread)))
8349              0))
8350           (number (mail-header-number (car thread)))
8351           score)
8352       (if (and
8353            (not (memq number gnus-newsgroup-marked))
8354            (or
8355             ;; If this article is dormant and has absolutely no visible
8356             ;; children, then this article isn't visible.
8357             (and (memq number gnus-newsgroup-dormant)
8358                  (zerop children))
8359             ;; If this is "fetch-old-headered" and there is no
8360             ;; visible children, then we don't want this article.
8361             (and (or (eq gnus-fetch-old-headers 'some)
8362                      (numberp gnus-fetch-old-headers))
8363                  (gnus-summary-article-ancient-p number)
8364                  (zerop children))
8365             ;; If this is "fetch-old-headered" and `invisible', then
8366             ;; we don't want this article.
8367             (and (eq gnus-fetch-old-headers 'invisible)
8368                  (gnus-summary-article-ancient-p number))
8369             ;; If this is a sparsely inserted article with no children,
8370             ;; we don't want it.
8371             (and (eq gnus-build-sparse-threads 'some)
8372                  (gnus-summary-article-sparse-p number)
8373                  (zerop children))
8374             ;; If we use expunging, and this article is really
8375             ;; low-scored, then we don't want this article.
8376             (when (and gnus-summary-expunge-below
8377                        (< (setq score
8378                                 (or (cdr (assq number gnus-newsgroup-scored))
8379                                     gnus-summary-default-score))
8380                           gnus-summary-expunge-below))
8381               ;; We increase the expunge-tally here, but that has
8382               ;; nothing to do with the limits, really.
8383               (incf gnus-newsgroup-expunged-tally)
8384               ;; We also mark as read here, if that's wanted.
8385               (when (and gnus-summary-mark-below
8386                          (< score gnus-summary-mark-below))
8387                 (setq gnus-newsgroup-unreads
8388                       (delq number gnus-newsgroup-unreads))
8389                 (if gnus-newsgroup-auto-expire
8390                     (push number gnus-newsgroup-expirable)
8391                   (push (cons number gnus-low-score-mark)
8392                         gnus-newsgroup-reads)))
8393               t)
8394             ;; Do the `display' group parameter.
8395             (and gnus-newsgroup-display
8396                  (not (funcall gnus-newsgroup-display)))
8397             ;; Check NoCeM things.
8398             (when (and gnus-use-nocem
8399                        (gnus-nocem-unwanted-article-p
8400                         (mail-header-id (car thread))))
8401               (setq gnus-newsgroup-unreads
8402                     (delq number gnus-newsgroup-unreads))
8403               t)))
8404           ;; Nope, invisible article.
8405           0
8406         ;; Ok, this article is to be visible, so we add it to the limit
8407         ;; and return 1.
8408         (push number gnus-newsgroup-limit)
8409         1))))
8410
8411 (defun gnus-expunge-thread (thread)
8412   "Mark all articles in THREAD as read."
8413   (let* ((number (mail-header-number (car thread))))
8414     (incf gnus-newsgroup-expunged-tally)
8415     ;; We also mark as read here, if that's wanted.
8416     (setq gnus-newsgroup-unreads
8417           (delq number gnus-newsgroup-unreads))
8418     (if gnus-newsgroup-auto-expire
8419         (push number gnus-newsgroup-expirable)
8420       (push (cons number gnus-low-score-mark)
8421             gnus-newsgroup-reads)))
8422   ;; Go recursively through all subthreads.
8423   (mapcar 'gnus-expunge-thread (cdr thread)))
8424
8425 ;; Summary article oriented commands
8426
8427 (defun gnus-summary-refer-parent-article (n)
8428   "Refer parent article N times.
8429 If N is negative, go to ancestor -N instead.
8430 The difference between N and the number of articles fetched is returned."
8431   (interactive "p")
8432   (let ((skip 1)
8433         error header ref)
8434     (when (not (natnump n))
8435       (setq skip (abs n)
8436             n 1))
8437     (while (and (> n 0)
8438                 (not error))
8439       (setq header (gnus-summary-article-header))
8440       (if (and (eq (mail-header-number header)
8441                    (cdr gnus-article-current))
8442                (equal gnus-newsgroup-name
8443                       (car gnus-article-current)))
8444           ;; If we try to find the parent of the currently
8445           ;; displayed article, then we take a look at the actual
8446           ;; References header, since this is slightly more
8447           ;; reliable than the References field we got from the
8448           ;; server.
8449           (save-excursion
8450             (set-buffer gnus-original-article-buffer)
8451             (nnheader-narrow-to-headers)
8452             (unless (setq ref (message-fetch-field "references"))
8453               (when (setq ref (message-fetch-field "in-reply-to"))
8454                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8455             (widen))
8456         (setq ref
8457               ;; It's not the current article, so we take a bet on
8458               ;; the value we got from the server.
8459               (mail-header-references header)))
8460       (if (and ref
8461                (not (equal ref "")))
8462           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8463             (gnus-message 1 "Couldn't find parent"))
8464         (gnus-message 1 "No references in article %d"
8465                       (gnus-summary-article-number))
8466         (setq error t))
8467       (decf n))
8468     (gnus-summary-position-point)
8469     n))
8470
8471 (defun gnus-summary-refer-references ()
8472   "Fetch all articles mentioned in the References header.
8473 Return the number of articles fetched."
8474   (interactive)
8475   (let ((ref (mail-header-references (gnus-summary-article-header)))
8476         (current (gnus-summary-article-number))
8477         (n 0))
8478     (if (or (not ref)
8479             (equal ref ""))
8480         (error "No References in the current article")
8481       ;; For each Message-ID in the References header...
8482       (while (string-match "<[^>]*>" ref)
8483         (incf n)
8484         ;; ... fetch that article.
8485         (gnus-summary-refer-article
8486          (prog1 (match-string 0 ref)
8487            (setq ref (substring ref (match-end 0))))))
8488       (gnus-summary-goto-subject current)
8489       (gnus-summary-position-point)
8490       n)))
8491
8492 (defun gnus-summary-refer-thread (&optional limit)
8493   "Fetch all articles in the current thread.
8494 If LIMIT (the numerical prefix), fetch that many old headers instead
8495 of what's specified by the `gnus-refer-thread-limit' variable."
8496   (interactive "P")
8497   (let ((id (mail-header-id (gnus-summary-article-header)))
8498         (limit (if limit (prefix-numeric-value limit)
8499                  gnus-refer-thread-limit)))
8500     (unless (eq gnus-fetch-old-headers 'invisible)
8501       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8502       ;; Retrieve the headers and read them in.
8503       (if (eq (if (numberp limit)
8504                   (gnus-retrieve-headers
8505                    (list (min
8506                           (+ (mail-header-number
8507                               (gnus-summary-article-header))
8508                              limit)
8509                           gnus-newsgroup-end))
8510                    gnus-newsgroup-name (* limit 2))
8511                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8512                 ;; headers.
8513                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8514                                        gnus-newsgroup-name limit))
8515               'nov)
8516           (gnus-build-all-threads)
8517         (error "Can't fetch thread from back ends that don't support NOV"))
8518       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8519     (gnus-summary-limit-include-thread id)))
8520
8521 (defun gnus-summary-refer-article (message-id)
8522   "Fetch an article specified by MESSAGE-ID."
8523   (interactive "sMessage-ID: ")
8524   (when (and (stringp message-id)
8525              (not (zerop (length message-id))))
8526     (setq message-id (gnus-replace-in-string message-id " " ""))
8527     ;; Construct the correct Message-ID if necessary.
8528     ;; Suggested by tale@pawl.rpi.edu.
8529     (unless (string-match "^<" message-id)
8530       (setq message-id (concat "<" message-id)))
8531     (unless (string-match ">$" message-id)
8532       (setq message-id (concat message-id ">")))
8533     ;; People often post MIDs from URLs, so unhex it:
8534     (unless (string-match "@" message-id)
8535       (setq message-id (gnus-url-unhex-string message-id)))
8536     (let* ((header (gnus-id-to-header message-id))
8537            (sparse (and header
8538                         (gnus-summary-article-sparse-p
8539                          (mail-header-number header))
8540                         (memq (mail-header-number header)
8541                               gnus-newsgroup-limit)))
8542            number)
8543       (cond
8544        ;; If the article is present in the buffer we just go to it.
8545        ((and header
8546              (or (not (gnus-summary-article-sparse-p
8547                        (mail-header-number header)))
8548                  sparse))
8549         (prog1
8550             (gnus-summary-goto-article
8551              (mail-header-number header) nil t)
8552           (when sparse
8553             (gnus-summary-update-article (mail-header-number header)))))
8554        (t
8555         ;; We fetch the article.
8556         (catch 'found
8557           (dolist (gnus-override-method (gnus-refer-article-methods))
8558             (when (and (gnus-check-server gnus-override-method)
8559                        ;; Fetch the header,
8560                        (setq number (gnus-summary-insert-subject message-id)))
8561               ;; and display the article.
8562               (gnus-summary-select-article nil nil nil number)
8563               (throw 'found t)))
8564           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8565
8566 (defun gnus-refer-article-methods ()
8567   "Return a list of referable methods."
8568   (cond
8569    ;; No method, so we default to current and native.
8570    ((null gnus-refer-article-method)
8571     (list gnus-current-select-method gnus-select-method))
8572    ;; Current.
8573    ((eq 'current gnus-refer-article-method)
8574     (list gnus-current-select-method))
8575    ;; List of select methods.
8576    ((not (and (symbolp (car gnus-refer-article-method))
8577               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8578     (let (out)
8579       (dolist (method gnus-refer-article-method)
8580         (push (if (eq 'current method)
8581                   gnus-current-select-method
8582                 method)
8583               out))
8584       (nreverse out)))
8585    ;; One single select method.
8586    (t
8587     (list gnus-refer-article-method))))
8588
8589 (defun gnus-summary-edit-parameters ()
8590   "Edit the group parameters of the current group."
8591   (interactive)
8592   (gnus-group-edit-group gnus-newsgroup-name 'params))
8593
8594 (defun gnus-summary-customize-parameters ()
8595   "Customize the group parameters of the current group."
8596   (interactive)
8597   (gnus-group-customize gnus-newsgroup-name))
8598
8599 (defun gnus-summary-enter-digest-group (&optional force)
8600   "Enter an nndoc group based on the current article.
8601 If FORCE, force a digest interpretation.  If not, try
8602 to guess what the document format is."
8603   (interactive "P")
8604   (let ((conf gnus-current-window-configuration))
8605     (save-window-excursion
8606       (save-excursion
8607         (let (gnus-article-prepare-hook
8608               gnus-display-mime-function
8609               gnus-break-pages)
8610           (gnus-summary-select-article))))
8611     (setq gnus-current-window-configuration conf)
8612     (let* ((name (format "%s-%d"
8613                          (gnus-group-prefixed-name
8614                           gnus-newsgroup-name (list 'nndoc ""))
8615                          (with-current-buffer gnus-summary-buffer
8616                            gnus-current-article)))
8617            (ogroup gnus-newsgroup-name)
8618            (params (append (gnus-info-params (gnus-get-info ogroup))
8619                            (list (cons 'to-group ogroup))
8620                            (list (cons 'parent-group ogroup))
8621                            (list (cons 'save-article-group ogroup))))
8622            (case-fold-search t)
8623            (buf (current-buffer))
8624            dig to-address)
8625       (save-excursion
8626         (set-buffer gnus-original-article-buffer)
8627         ;; Have the digest group inherit the main mail address of
8628         ;; the parent article.
8629         (when (setq to-address (or (gnus-fetch-field "reply-to")
8630                                    (gnus-fetch-field "from")))
8631           (setq params (append
8632                         (list (cons 'to-address
8633                                     (funcall gnus-decode-encoded-word-function
8634                                              to-address))))))
8635         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8636         (insert-buffer-substring gnus-original-article-buffer)
8637         ;; Remove lines that may lead nndoc to misinterpret the
8638         ;; document type.
8639         (narrow-to-region
8640          (goto-char (point-min))
8641          (or (search-forward "\n\n" nil t) (point)))
8642         (goto-char (point-min))
8643         (delete-matching-lines "^Path:\\|^From ")
8644         (widen))
8645       (unwind-protect
8646           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8647                     (gnus-newsgroup-ephemeral-ignored-charsets
8648                      gnus-newsgroup-ignored-charsets))
8649                 (gnus-group-read-ephemeral-group
8650                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8651                               (nndoc-article-type
8652                                ,(if force 'mbox 'guess)))
8653                  t nil nil nil
8654                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8655                                                         "ADAPT")))))
8656               ;; Make all postings to this group go to the parent group.
8657               (nconc (gnus-info-params (gnus-get-info name))
8658                      params)
8659             ;; Couldn't select this doc group.
8660             (switch-to-buffer buf)
8661             (gnus-set-global-variables)
8662             (gnus-configure-windows 'summary)
8663             (gnus-message 3 "Article couldn't be entered?"))
8664         (kill-buffer dig)))))
8665
8666 (defun gnus-summary-read-document (n)
8667   "Open a new group based on the current article(s).
8668 This will allow you to read digests and other similar
8669 documents as newsgroups.
8670 Obeys the standard process/prefix convention."
8671   (interactive "P")
8672   (let* ((ogroup gnus-newsgroup-name)
8673          (params (append (gnus-info-params (gnus-get-info ogroup))
8674                          (list (cons 'to-group ogroup))))
8675          group egroup groups vgroup)
8676     (dolist (article (gnus-summary-work-articles n))
8677       (setq group (format "%s-%d" gnus-newsgroup-name article))
8678       (gnus-summary-remove-process-mark article)
8679       (when (gnus-summary-display-article article)
8680         (save-excursion
8681           (with-temp-buffer
8682             (insert-buffer-substring gnus-original-article-buffer)
8683             ;; Remove some headers that may lead nndoc to make
8684             ;; the wrong guess.
8685             (message-narrow-to-head)
8686             (goto-char (point-min))
8687             (delete-matching-lines "^Path:\\|^From ")
8688             (widen)
8689             (if (setq egroup
8690                       (gnus-group-read-ephemeral-group
8691                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8692                                      (nndoc-article-type guess))
8693                        t nil t))
8694                 (progn
8695             ;; Make all postings to this group go to the parent group.
8696                   (nconc (gnus-info-params (gnus-get-info egroup))
8697                          params)
8698                   (push egroup groups))
8699               ;; Couldn't select this doc group.
8700               (gnus-error 3 "Article couldn't be entered"))))))
8701     ;; Now we have selected all the documents.
8702     (cond
8703      ((not groups)
8704       (error "None of the articles could be interpreted as documents"))
8705      ((gnus-group-read-ephemeral-group
8706        (setq vgroup (format
8707                      "nnvirtual:%s-%s" gnus-newsgroup-name
8708                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8709        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8710        t
8711        (cons (current-buffer) 'summary)))
8712      (t
8713       (error "Couldn't select virtual nndoc group")))))
8714
8715 (defun gnus-summary-isearch-article (&optional regexp-p)
8716   "Do incremental search forward on the current article.
8717 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8718   (interactive "P")
8719   (gnus-summary-select-article)
8720   (gnus-configure-windows 'article)
8721   (gnus-eval-in-buffer-window gnus-article-buffer
8722     (save-restriction
8723       (widen)
8724       (isearch-forward regexp-p))))
8725
8726 (defun gnus-summary-repeat-search-article-forward ()
8727   "Repeat the previous search forwards."
8728   (interactive)
8729   (unless gnus-last-search-regexp
8730     (error "No previous search"))
8731   (gnus-summary-search-article-forward gnus-last-search-regexp))
8732
8733 (defun gnus-summary-repeat-search-article-backward ()
8734   "Repeat the previous search backwards."
8735   (interactive)
8736   (unless gnus-last-search-regexp
8737     (error "No previous search"))
8738   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8739
8740 (defun gnus-summary-search-article-forward (regexp &optional backward)
8741   "Search for an article containing REGEXP forward.
8742 If BACKWARD, search backward instead."
8743   (interactive
8744    (list (read-string
8745           (format "Search article %s (regexp%s): "
8746                   (if current-prefix-arg "backward" "forward")
8747                   (if gnus-last-search-regexp
8748                       (concat ", default " gnus-last-search-regexp)
8749                     "")))
8750          current-prefix-arg))
8751   (if (string-equal regexp "")
8752       (setq regexp (or gnus-last-search-regexp ""))
8753     (setq gnus-last-search-regexp regexp)
8754     (setq gnus-article-before-search gnus-current-article))
8755   ;; Intentionally set gnus-last-article.
8756   (setq gnus-last-article gnus-article-before-search)
8757   (let ((gnus-last-article gnus-last-article))
8758     (if (gnus-summary-search-article regexp backward)
8759         (gnus-summary-show-thread)
8760       (signal 'search-failed (list regexp)))))
8761
8762 (defun gnus-summary-search-article-backward (regexp)
8763   "Search for an article containing REGEXP backward."
8764   (interactive
8765    (list (read-string
8766           (format "Search article backward (regexp%s): "
8767                   (if gnus-last-search-regexp
8768                       (concat ", default " gnus-last-search-regexp)
8769                     "")))))
8770   (gnus-summary-search-article-forward regexp 'backward))
8771
8772 (defun gnus-summary-search-article (regexp &optional backward)
8773   "Search for an article containing REGEXP.
8774 Optional argument BACKWARD means do search for backward.
8775 `gnus-select-article-hook' is not called during the search."
8776   ;; We have to require this here to make sure that the following
8777   ;; dynamic binding isn't shadowed by autoloading.
8778   (require 'gnus-async)
8779   (require 'gnus-art)
8780   (let ((gnus-select-article-hook nil)  ;Disable hook.
8781         (gnus-article-prepare-hook nil)
8782         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8783         (gnus-use-article-prefetch nil)
8784         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8785         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8786         (gnus-visual nil)
8787         (gnus-keep-backlog nil)
8788         (gnus-break-pages nil)
8789         (gnus-summary-display-arrow nil)
8790         (gnus-updated-mode-lines nil)
8791         (gnus-auto-center-summary nil)
8792         (sum (current-buffer))
8793         (gnus-display-mime-function nil)
8794         (found nil)
8795         point)
8796     (gnus-save-hidden-threads
8797       (gnus-summary-select-article)
8798       (set-buffer gnus-article-buffer)
8799       (goto-char (window-point (get-buffer-window (current-buffer))))
8800       (when backward
8801         (forward-line -1))
8802       (while (not found)
8803         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8804         (if (if backward
8805                 (re-search-backward regexp nil t)
8806               (re-search-forward regexp nil t))
8807             ;; We found the regexp.
8808             (progn
8809               (setq found 'found)
8810               (beginning-of-line)
8811               (set-window-start
8812                (get-buffer-window (current-buffer))
8813                (point))
8814               (forward-line 1)
8815               (set-window-point
8816                (get-buffer-window (current-buffer))
8817                (point))
8818               (set-buffer sum)
8819               (setq point (point)))
8820           ;; We didn't find it, so we go to the next article.
8821           (set-buffer sum)
8822           (setq found 'not)
8823           (while (eq found 'not)
8824             (if (not (if backward (gnus-summary-find-prev)
8825                        (gnus-summary-find-next)))
8826                 ;; No more articles.
8827                 (setq found t)
8828               ;; Select the next article and adjust point.
8829               (unless (gnus-summary-article-sparse-p
8830                        (gnus-summary-article-number))
8831                 (setq found nil)
8832                 (gnus-summary-select-article)
8833                 (set-buffer gnus-article-buffer)
8834                 (widen)
8835                 (goto-char (if backward (point-max) (point-min))))))))
8836       (gnus-message 7 ""))
8837     ;; Return whether we found the regexp.
8838     (when (eq found 'found)
8839       (goto-char point)
8840       (gnus-summary-show-thread)
8841       (gnus-summary-goto-subject gnus-current-article)
8842       (gnus-summary-position-point)
8843       t)))
8844
8845 (defun gnus-find-matching-articles (header regexp)
8846   "Return a list of all articles that match REGEXP on HEADER.
8847 This search includes all articles in the current group that Gnus has
8848 fetched headers for, whether they are displayed or not."
8849   (let ((articles nil)
8850         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8851         (case-fold-search t))
8852     (dolist (header gnus-newsgroup-headers)
8853       (when (string-match regexp (funcall func header))
8854         (push (mail-header-number header) articles)))
8855     (nreverse articles)))
8856
8857 (defun gnus-summary-find-matching (header regexp &optional backward unread
8858                                           not-case-fold not-matching)
8859   "Return a list of all articles that match REGEXP on HEADER.
8860 The search stars on the current article and goes forwards unless
8861 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8862 If UNREAD is non-nil, only unread articles will
8863 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8864 in the comparisons. If NOT-MATCHING, return a list of all articles that
8865 not match REGEXP on HEADER."
8866   (let ((case-fold-search (not not-case-fold))
8867         articles d func)
8868     (if (consp header)
8869         (if (eq (car header) 'extra)
8870             (setq func
8871                   `(lambda (h)
8872                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8873                          "")))
8874           (error "%s is an invalid header" header))
8875       (unless (fboundp (intern (concat "mail-header-" header)))
8876         (error "%s is not a valid header" header))
8877       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8878     (dolist (d (if (eq backward 'all)
8879                    gnus-newsgroup-data
8880                  (gnus-data-find-list
8881                   (gnus-summary-article-number)
8882                   (gnus-data-list backward))))
8883       (when (and (or (not unread)       ; We want all articles...
8884                      (gnus-data-unread-p d)) ; Or just unreads.
8885                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8886                  (if not-matching
8887                      (not (string-match
8888                            regexp
8889                            (funcall func (gnus-data-header d))))
8890                    (string-match regexp
8891                                  (funcall func (gnus-data-header d)))))
8892         (push (gnus-data-number d) articles))) ; Success!
8893     (nreverse articles)))
8894
8895 (defun gnus-summary-execute-command (header regexp command &optional backward)
8896   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8897 If HEADER is an empty string (or nil), the match is done on the entire
8898 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8899   (interactive
8900    (list (let ((completion-ignore-case t))
8901            (completing-read
8902             "Header name: "
8903             (mapcar (lambda (header) (list (format "%s" header)))
8904                     (append
8905                      '("Number" "Subject" "From" "Lines" "Date"
8906                        "Message-ID" "Xref" "References" "Body")
8907                      gnus-extra-headers))
8908             nil 'require-match))
8909          (read-string "Regexp: ")
8910          (read-key-sequence "Command: ")
8911          current-prefix-arg))
8912   (when (equal header "Body")
8913     (setq header ""))
8914   ;; Hidden thread subtrees must be searched as well.
8915   (gnus-summary-show-all-threads)
8916   ;; We don't want to change current point nor window configuration.
8917   (save-excursion
8918     (save-window-excursion
8919       (let (gnus-visual
8920             gnus-treat-strip-trailing-blank-lines
8921             gnus-treat-strip-leading-blank-lines
8922             gnus-treat-strip-multiple-blank-lines
8923             gnus-treat-hide-boring-headers
8924             gnus-treat-fold-newsgroups
8925             gnus-article-prepare-hook)
8926         (gnus-message 6 "Executing %s..." (key-description command))
8927         ;; We'd like to execute COMMAND interactively so as to give arguments.
8928         (gnus-execute header regexp
8929                       `(call-interactively ',(key-binding command))
8930                       backward)
8931         (gnus-message 6 "Executing %s...done" (key-description command))))))
8932
8933 (defun gnus-summary-beginning-of-article ()
8934   "Scroll the article back to the beginning."
8935   (interactive)
8936   (gnus-summary-select-article)
8937   (gnus-configure-windows 'article)
8938   (gnus-eval-in-buffer-window gnus-article-buffer
8939     (widen)
8940     (goto-char (point-min))
8941     (when gnus-break-pages
8942       (gnus-narrow-to-page))))
8943
8944 (defun gnus-summary-end-of-article ()
8945   "Scroll to the end of the article."
8946   (interactive)
8947   (gnus-summary-select-article)
8948   (gnus-configure-windows 'article)
8949   (gnus-eval-in-buffer-window gnus-article-buffer
8950     (widen)
8951     (goto-char (point-max))
8952     (recenter -3)
8953     (when gnus-break-pages
8954       (when (re-search-backward page-delimiter nil t)
8955         (narrow-to-region (match-end 0) (point-max)))
8956       (gnus-narrow-to-page))))
8957
8958 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8959   "Truncate to LEN and quote all \"(\"'s in STRING."
8960   (gnus-replace-in-string (if (and len (> (length string) len))
8961                               (substring string 0 len)
8962                             string)
8963                           "[()]" "\\\\\\&"))
8964
8965 (defun gnus-summary-print-article (&optional filename n)
8966   "Generate and print a PostScript image of the process-marked (mail) articles.
8967
8968 If used interactively, print the current article if none are
8969 process-marked.  With prefix arg, prompt the user for the name of the
8970 file to save in.
8971
8972 When used from Lisp, accept two optional args FILENAME and N.  N means
8973 to print the next N articles.  If N is negative, print the N previous
8974 articles.  If N is nil and articles have been marked with the process
8975 mark, print these instead.
8976
8977 If the optional first argument FILENAME is nil, send the image to the
8978 printer.  If FILENAME is a string, save the PostScript image in a file with
8979 that name.  If FILENAME is a number, prompt the user for the name of the file
8980 to save in."
8981   (interactive (list (ps-print-preprint current-prefix-arg)))
8982   (dolist (article (gnus-summary-work-articles n))
8983     (gnus-summary-select-article nil nil 'pseudo article)
8984     (gnus-eval-in-buffer-window gnus-article-buffer
8985       (gnus-print-buffer))
8986     (gnus-summary-remove-process-mark article))
8987   (ps-despool filename))
8988
8989 (defun gnus-print-buffer ()
8990   (let ((buffer (generate-new-buffer " *print*")))
8991     (unwind-protect
8992         (progn
8993           (copy-to-buffer buffer (point-min) (point-max))
8994           (set-buffer buffer)
8995           (gnus-remove-text-with-property 'gnus-decoration)
8996           (when (gnus-visual-p 'article-highlight 'highlight)
8997             ;; Copy-to-buffer doesn't copy overlay.  So redo
8998             ;; highlight.
8999             (let ((gnus-article-buffer buffer))
9000               (gnus-article-highlight-citation t)
9001               (gnus-article-highlight-signature)
9002               (gnus-article-emphasize)
9003               (gnus-article-delete-invisible-text)))
9004           (let ((ps-left-header
9005                  (list
9006                   (concat "("
9007                           (gnus-summary-print-truncate-and-quote
9008                            (mail-header-subject gnus-current-headers)
9009                            66) ")")
9010                   (concat "("
9011                           (gnus-summary-print-truncate-and-quote
9012                            (mail-header-from gnus-current-headers)
9013                            45) ")")))
9014                 (ps-right-header
9015                  (list
9016                   "/pagenumberstring load"
9017                   (concat "("
9018                           (mail-header-date gnus-current-headers) ")"))))
9019             (gnus-run-hooks 'gnus-ps-print-hook)
9020             (save-excursion
9021               (if window-system
9022                   (ps-spool-buffer-with-faces)
9023                 (ps-spool-buffer)))))
9024       (kill-buffer buffer))))
9025
9026 (defun gnus-summary-show-article (&optional arg)
9027   "Force redisplaying of the current article.
9028 If ARG (the prefix) is a number, show the article with the charset
9029 defined in `gnus-summary-show-article-charset-alist', or the charset
9030 input.
9031 If ARG (the prefix) is non-nil and not a number, show the raw article
9032 without any article massaging functions being run.  Normally, the key
9033 strokes are `C-u g'."
9034   (interactive "P")
9035   (cond
9036    ((numberp arg)
9037     (gnus-summary-show-article t)
9038     (let ((gnus-newsgroup-charset
9039            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9040                (mm-read-coding-system
9041                 "View as charset: " ;; actually it is coding system.
9042                 (with-current-buffer gnus-article-buffer
9043                   (mm-detect-coding-region (point) (point-max))))))
9044           (gnus-newsgroup-ignored-charsets 'gnus-all))
9045       (gnus-summary-select-article nil 'force)
9046       (let ((deps gnus-newsgroup-dependencies)
9047             head header lines)
9048         (save-excursion
9049           (set-buffer gnus-original-article-buffer)
9050           (save-restriction
9051             (message-narrow-to-head)
9052             (setq head (buffer-string))
9053             (goto-char (point-min))
9054             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9055               (goto-char (point-max))
9056               (widen)
9057               (setq lines (1- (count-lines (point) (point-max))))))
9058           (with-temp-buffer
9059             (insert (format "211 %d Article retrieved.\n"
9060                             (cdr gnus-article-current)))
9061             (insert head)
9062             (if lines (insert (format "Lines: %d\n" lines)))
9063             (insert ".\n")
9064             (let ((nntp-server-buffer (current-buffer)))
9065               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9066         (gnus-data-set-header
9067          (gnus-data-find (cdr gnus-article-current))
9068          header)
9069         (gnus-summary-update-article-line
9070          (cdr gnus-article-current) header)
9071         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9072           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9073    ((not arg)
9074     ;; Select the article the normal way.
9075     (gnus-summary-select-article nil 'force))
9076    (t
9077     ;; We have to require this here to make sure that the following
9078     ;; dynamic binding isn't shadowed by autoloading.
9079     (require 'gnus-async)
9080     (require 'gnus-art)
9081     ;; Bind the article treatment functions to nil.
9082     (let ((gnus-have-all-headers t)
9083           gnus-article-prepare-hook
9084           gnus-article-decode-hook
9085           gnus-display-mime-function
9086           gnus-break-pages)
9087       ;; Destroy any MIME parts.
9088       (when (gnus-buffer-live-p gnus-article-buffer)
9089         (save-excursion
9090           (set-buffer gnus-article-buffer)
9091           (mm-destroy-parts gnus-article-mime-handles)
9092           ;; Set it to nil for safety reason.
9093           (setq gnus-article-mime-handle-alist nil)
9094           (setq gnus-article-mime-handles nil)))
9095       (gnus-summary-select-article nil 'force))))
9096   (gnus-summary-goto-subject gnus-current-article)
9097   (gnus-summary-position-point))
9098
9099 (defun gnus-summary-show-raw-article ()
9100   "Show the raw article without any article massaging functions being run."
9101   (interactive)
9102   (gnus-summary-show-article t))
9103
9104 (defun gnus-summary-verbose-headers (&optional arg)
9105   "Toggle permanent full header display.
9106 If ARG is a positive number, turn header display on.
9107 If ARG is a negative number, turn header display off."
9108   (interactive "P")
9109   (setq gnus-show-all-headers
9110         (cond ((or (not (numberp arg))
9111                    (zerop arg))
9112                (not gnus-show-all-headers))
9113               ((natnump arg)
9114                t)))
9115   (gnus-summary-show-article))
9116
9117 (defun gnus-summary-toggle-header (&optional arg)
9118   "Show the headers if they are hidden, or hide them if they are shown.
9119 If ARG is a positive number, show the entire header.
9120 If ARG is a negative number, hide the unwanted header lines."
9121   (interactive "P")
9122   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9123                      (get-buffer-window gnus-article-buffer t))))
9124     (with-current-buffer gnus-article-buffer
9125       (widen)
9126       (article-narrow-to-head)
9127       (let* ((buffer-read-only nil)
9128              (inhibit-point-motion-hooks t)
9129              (hidden (if (numberp arg)
9130                          (>= arg 0)
9131                        (or (not (looking-at "[^ \t\n]+:"))
9132                            (gnus-article-hidden-text-p 'headers))))
9133              s e)
9134         (delete-region (point-min) (point-max))
9135         (with-current-buffer gnus-original-article-buffer
9136           (goto-char (setq s (point-min)))
9137           (setq e (if (search-forward "\n\n" nil t)
9138                       (1- (point))
9139                     (point-max))))
9140         (insert-buffer-substring gnus-original-article-buffer s e)
9141         (run-hooks 'gnus-article-decode-hook)
9142         (if hidden
9143             (let ((gnus-treat-hide-headers nil)
9144                   (gnus-treat-hide-boring-headers nil))
9145               (gnus-delete-wash-type 'headers)
9146               (gnus-treat-article 'head))
9147           (gnus-treat-article 'head))
9148         (widen)
9149         (if window
9150             (set-window-start window (goto-char (point-min))))
9151         (if gnus-break-pages
9152             (gnus-narrow-to-page)
9153           (when (gnus-visual-p 'page-marker)
9154             (let ((buffer-read-only nil))
9155               (gnus-remove-text-with-property 'gnus-prev)
9156               (gnus-remove-text-with-property 'gnus-next))))
9157         (gnus-set-mode-line 'article)))))
9158
9159 (defun gnus-summary-show-all-headers ()
9160   "Make all header lines visible."
9161   (interactive)
9162   (gnus-summary-toggle-header 1))
9163
9164 (defun gnus-summary-caesar-message (&optional arg)
9165   "Caesar rotate the current article by 13.
9166 The numerical prefix specifies how many places to rotate each letter
9167 forward."
9168   (interactive "P")
9169   (gnus-summary-select-article)
9170   (let ((mail-header-separator ""))
9171     (gnus-eval-in-buffer-window gnus-article-buffer
9172       (save-restriction
9173         (widen)
9174         (let ((start (window-start))
9175               buffer-read-only)
9176           (message-caesar-buffer-body arg)
9177           (set-window-start (get-buffer-window (current-buffer)) start)))))
9178   ;; Create buttons and stuff...
9179   (gnus-treat-article nil))
9180
9181 (defun gnus-summary-idna-message (&optional arg)
9182   "Decode IDNA encoded domain names in the current articles.
9183 IDNA encoded domain names looks like `xn--bar'.  If a string
9184 remain unencoded after running this function, it is likely an
9185 invalid IDNA string (`xn--bar' is invalid).
9186
9187 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9188 installed for this command to work."
9189   (interactive "P")
9190   (if (not (and (condition-case nil (require 'idna)
9191                   (file-error))
9192                 (mm-coding-system-p 'utf-8)
9193                 (executable-find (symbol-value 'idna-program))))
9194       (gnus-message
9195        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9196     (gnus-summary-select-article)
9197     (let ((mail-header-separator ""))
9198       (gnus-eval-in-buffer-window gnus-article-buffer
9199         (save-restriction
9200           (widen)
9201           (let ((start (window-start))
9202                 buffer-read-only)
9203             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9204               (replace-match (idna-to-unicode (match-string 1))))
9205             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9206
9207 (defun gnus-summary-morse-message (&optional arg)
9208   "Morse decode the current article."
9209   (interactive "P")
9210   (gnus-summary-select-article)
9211   (let ((mail-header-separator ""))
9212     (gnus-eval-in-buffer-window gnus-article-buffer
9213       (save-excursion
9214         (save-restriction
9215           (widen)
9216           (let ((pos (window-start))
9217                 buffer-read-only)
9218             (goto-char (point-min))
9219             (when (message-goto-body)
9220               (gnus-narrow-to-body))
9221             (goto-char (point-min))
9222             (while (search-forward "·" (point-max) t)
9223               (replace-match "."))
9224             (unmorse-region (point-min) (point-max))
9225             (widen)
9226             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9227
9228 (defun gnus-summary-stop-page-breaking ()
9229   "Stop page breaking in the current article."
9230   (interactive)
9231   (gnus-summary-select-article)
9232   (gnus-eval-in-buffer-window gnus-article-buffer
9233     (widen)
9234     (when (gnus-visual-p 'page-marker)
9235       (let ((buffer-read-only nil))
9236         (gnus-remove-text-with-property 'gnus-prev)
9237         (gnus-remove-text-with-property 'gnus-next))
9238       (setq gnus-page-broken nil))))
9239
9240 (defun gnus-summary-move-article (&optional n to-newsgroup
9241                                             select-method action)
9242   "Move the current article to a different newsgroup.
9243 If N is a positive number, move the N next articles.
9244 If N is a negative number, move the N previous articles.
9245 If N is nil and any articles have been marked with the process mark,
9246 move those articles instead.
9247 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9248 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9249 re-spool using this method.
9250
9251 When called interactively with TO-NEWSGROUP being nil, the value of
9252 the variable `gnus-move-split-methods' is used for finding a default
9253 for the target newsgroup.
9254
9255 For this function to work, both the current newsgroup and the
9256 newsgroup that you want to move to have to support the `request-move'
9257 and `request-accept' functions.
9258
9259 ACTION can be either `move' (the default), `crosspost' or `copy'."
9260   (interactive "P")
9261   (unless action
9262     (setq action 'move))
9263   ;; Check whether the source group supports the required functions.
9264   (cond ((and (eq action 'move)
9265               (not (gnus-check-backend-function
9266                     'request-move-article gnus-newsgroup-name)))
9267          (error "The current group does not support article moving"))
9268         ((and (eq action 'crosspost)
9269               (not (gnus-check-backend-function
9270                     'request-replace-article gnus-newsgroup-name)))
9271          (error "The current group does not support article editing")))
9272   (let ((articles (gnus-summary-work-articles n))
9273         (prefix (if (gnus-check-backend-function
9274                      'request-move-article gnus-newsgroup-name)
9275                     (funcall gnus-move-group-prefix-function
9276                              gnus-newsgroup-name)
9277                   ""))
9278         (names '((move "Move" "Moving")
9279                  (copy "Copy" "Copying")
9280                  (crosspost "Crosspost" "Crossposting")))
9281         (copy-buf (save-excursion
9282                     (nnheader-set-temp-buffer " *copy article*")))
9283         art-group to-method new-xref article to-groups articles-to-update-marks)
9284     (unless (assq action names)
9285       (error "Unknown action %s" action))
9286     ;; Read the newsgroup name.
9287     (when (and (not to-newsgroup)
9288                (not select-method))
9289       (if (and gnus-move-split-methods
9290                (not
9291                 (and (memq gnus-current-article articles)
9292                      (gnus-buffer-live-p gnus-original-article-buffer))))
9293           ;; When `gnus-move-split-methods' is non-nil, we have to
9294           ;; select an article to give `gnus-read-move-group-name' an
9295           ;; opportunity to suggest an appropriate default.  However,
9296           ;; we needn't render or mark the article.
9297           (let ((gnus-display-mime-function nil)
9298                 (gnus-article-prepare-hook nil)
9299                 (gnus-mark-article-hook nil))
9300             (gnus-summary-select-article nil nil nil (car articles))))
9301       (setq to-newsgroup
9302             (gnus-read-move-group-name
9303              (cadr (assq action names))
9304              (symbol-value (intern (format "gnus-current-%s-group" action)))
9305              articles prefix))
9306       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9307     (setq to-method (or select-method
9308                         (gnus-server-to-method
9309                          (gnus-group-method to-newsgroup))))
9310     ;; Check the method we are to move this article to...
9311     (unless (gnus-check-backend-function
9312              'request-accept-article (car to-method))
9313       (error "%s does not support article copying" (car to-method)))
9314     (unless (gnus-check-server to-method)
9315       (error "Can't open server %s" (car to-method)))
9316     (gnus-message 6 "%s to %s: %s..."
9317                   (caddr (assq action names))
9318                   (or (car select-method) to-newsgroup) articles)
9319     (while articles
9320       (setq article (pop articles))
9321       (setq
9322        art-group
9323        (cond
9324         ;; Move the article.
9325         ((eq action 'move)
9326          ;; Remove this article from future suppression.
9327          (gnus-dup-unsuppress-article article)
9328          (let* ((from-method (gnus-find-method-for-group
9329                               gnus-newsgroup-name))
9330                 (to-method (gnus-find-method-for-group
9331                             to-newsgroup))
9332                 (move-is-internal (gnus-method-equal from-method to-method)))
9333          (gnus-request-move-article
9334           article                       ; Article to move
9335           gnus-newsgroup-name           ; From newsgroup
9336           (nth 1 (gnus-find-method-for-group
9337                   gnus-newsgroup-name)) ; Server
9338           (list 'gnus-request-accept-article
9339                 to-newsgroup (list 'quote select-method)
9340                 (not articles) t)       ; Accept form
9341           (not articles)                ; Only save nov last time
9342           move-is-internal)))           ; is this move internal?
9343         ;; Copy the article.
9344         ((eq action 'copy)
9345          (save-excursion
9346            (set-buffer copy-buf)
9347            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9348              (save-restriction
9349                (nnheader-narrow-to-headers)
9350                (dolist (hdr gnus-copy-article-ignored-headers)
9351                  (message-remove-header hdr t)))
9352              (gnus-request-accept-article
9353               to-newsgroup select-method (not articles) t))))
9354         ;; Crosspost the article.
9355         ((eq action 'crosspost)
9356          (let ((xref (message-tokenize-header
9357                       (mail-header-xref (gnus-summary-article-header article))
9358                       " ")))
9359            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9360                                   ":" (number-to-string article)))
9361            (unless xref
9362              (setq xref (list (system-name))))
9363            (setq new-xref
9364                  (concat
9365                   (mapconcat 'identity
9366                              (delete "Xref:" (delete new-xref xref))
9367                              " ")
9368                   " " new-xref))
9369            (save-excursion
9370              (set-buffer copy-buf)
9371              ;; First put the article in the destination group.
9372              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9373              (when (consp (setq art-group
9374                                 (gnus-request-accept-article
9375                                  to-newsgroup select-method (not articles))))
9376                (setq new-xref (concat new-xref " " (car art-group)
9377                                       ":"
9378                                       (number-to-string (cdr art-group))))
9379                ;; Now we have the new Xrefs header, so we insert
9380                ;; it and replace the new article.
9381                (nnheader-replace-header "Xref" new-xref)
9382                (gnus-request-replace-article
9383                 (cdr art-group) to-newsgroup (current-buffer))
9384                art-group))))))
9385       (cond
9386        ((not art-group)
9387         (gnus-message 1 "Couldn't %s article %s: %s"
9388                       (cadr (assq action names)) article
9389                       (nnheader-get-report (car to-method))))
9390        ((eq art-group 'junk)
9391         (when (eq action 'move)
9392           (gnus-summary-mark-article article gnus-canceled-mark)
9393           (gnus-message 4 "Deleted article %s" article)
9394           ;; run the delete hook
9395           (run-hook-with-args 'gnus-summary-article-delete-hook
9396                               action
9397                               (gnus-data-header
9398                                (assoc article (gnus-data-list nil)))
9399                               gnus-newsgroup-name nil
9400                               select-method)))
9401        (t
9402         (let* ((pto-group (gnus-group-prefixed-name
9403                            (car art-group) to-method))
9404                (info (gnus-get-info pto-group))
9405                (to-group (gnus-info-group info))
9406                to-marks)
9407           ;; Update the group that has been moved to.
9408           (when (and info
9409                      (memq action '(move copy)))
9410             (unless (member to-group to-groups)
9411               (push to-group to-groups))
9412
9413             (unless (memq article gnus-newsgroup-unreads)
9414               (push 'read to-marks)
9415               (gnus-info-set-read
9416                info (gnus-add-to-range (gnus-info-read info)
9417                                        (list (cdr art-group)))))
9418
9419             ;; See whether the article is to be put in the cache.
9420             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9421                              gnus-article-mark-lists
9422                            (delete '(expirable . expire)
9423                                    (copy-sequence gnus-article-mark-lists))))
9424                   (to-article (cdr art-group)))
9425
9426               ;; Enter the article into the cache in the new group,
9427               ;; if that is required.
9428               (when gnus-use-cache
9429                 (gnus-cache-possibly-enter-article
9430                  to-group to-article
9431                  (memq article gnus-newsgroup-marked)
9432                  (memq article gnus-newsgroup-dormant)
9433                  (memq article gnus-newsgroup-unreads)))
9434
9435               (when gnus-preserve-marks
9436                 ;; Copy any marks over to the new group.
9437                 (when (and (equal to-group gnus-newsgroup-name)
9438                            (not (memq article gnus-newsgroup-unreads)))
9439                   ;; Mark this article as read in this group.
9440                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9441                   (setcdr (gnus-active to-group) to-article)
9442                   (setcdr gnus-newsgroup-active to-article))
9443
9444                 (while marks
9445                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9446                     (when (memq article (symbol-value
9447                                          (intern (format "gnus-newsgroup-%s"
9448                                                          (caar marks)))))
9449                       (push (cdar marks) to-marks)
9450                       ;; If the other group is the same as this group,
9451                       ;; then we have to add the mark to the list.
9452                       (when (equal to-group gnus-newsgroup-name)
9453                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9454                              (cons to-article
9455                                    (symbol-value
9456                                     (intern (format "gnus-newsgroup-%s"
9457                                                     (caar marks)))))))
9458                       ;; Copy the marks to other group.
9459                       (gnus-add-marked-articles
9460                        to-group (cdar marks) (list to-article) info)))
9461                   (setq marks (cdr marks)))
9462
9463                 (gnus-request-set-mark
9464                  to-group (list (list (list to-article) 'add to-marks))))
9465
9466               (gnus-dribble-enter
9467                (concat "(gnus-group-set-info '"
9468                        (gnus-prin1-to-string (gnus-get-info to-group))
9469                        ")"))))
9470
9471           ;; Update the Xref header in this article to point to
9472           ;; the new crossposted article we have just created.
9473           (when (eq action 'crosspost)
9474             (save-excursion
9475               (set-buffer copy-buf)
9476               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9477               (nnheader-replace-header "Xref" new-xref)
9478               (gnus-request-replace-article
9479                article gnus-newsgroup-name (current-buffer))))
9480
9481           ;; run the move/copy/crosspost/respool hook
9482           (run-hook-with-args 'gnus-summary-article-move-hook
9483                               action
9484                               (gnus-data-header
9485                                (assoc article (gnus-data-list nil)))
9486                               gnus-newsgroup-name
9487                               to-newsgroup
9488                               select-method))
9489
9490         ;;;!!!Why is this necessary?
9491         (set-buffer gnus-summary-buffer)
9492         
9493         (gnus-summary-goto-subject article)
9494         (when (eq action 'move)
9495           (gnus-summary-mark-article article gnus-canceled-mark))))
9496       (push article articles-to-update-marks))
9497
9498     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9499     ;; Re-activate all groups that have been moved to.
9500     (save-excursion
9501       (set-buffer gnus-group-buffer)
9502       (let ((gnus-group-marked to-groups))
9503         (gnus-group-get-new-news-this-group nil t)))
9504     
9505     (gnus-kill-buffer copy-buf)
9506     (gnus-summary-position-point)
9507     (gnus-set-mode-line 'summary)))
9508
9509 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9510   "Copy the current article to some other group.
9511 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9512 When called interactively, if TO-NEWSGROUP is nil, use the value of
9513 the variable `gnus-move-split-methods' for finding a default target
9514 newsgroup.
9515 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9516 re-spool using this method."
9517   (interactive "P")
9518   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9519
9520 (defun gnus-summary-crosspost-article (&optional n)
9521   "Crosspost the current article to some other group."
9522   (interactive "P")
9523   (gnus-summary-move-article n nil nil 'crosspost))
9524
9525 (defcustom gnus-summary-respool-default-method nil
9526   "Default method type for respooling an article.
9527 If nil, use to the current newsgroup method."
9528   :type 'symbol
9529   :group 'gnus-summary-mail)
9530
9531 (defcustom gnus-summary-display-while-building nil
9532   "If non-nil, show and update the summary buffer as it's being built.
9533 If the value is t, update the buffer after every line is inserted.  If
9534 the value is an integer (N), update the display every N lines."
9535   :version "22.1"
9536   :group 'gnus-thread
9537   :type '(choice (const :tag "off" nil)
9538                  number
9539                  (const :tag "frequently" t)))
9540
9541 (defun gnus-summary-respool-article (&optional n method)
9542   "Respool the current article.
9543 The article will be squeezed through the mail spooling process again,
9544 which means that it will be put in some mail newsgroup or other
9545 depending on `nnmail-split-methods'.
9546 If N is a positive number, respool the N next articles.
9547 If N is a negative number, respool the N previous articles.
9548 If N is nil and any articles have been marked with the process mark,
9549 respool those articles instead.
9550
9551 Respooling can be done both from mail groups and \"real\" newsgroups.
9552 In the former case, the articles in question will be moved from the
9553 current group into whatever groups they are destined to.  In the
9554 latter case, they will be copied into the relevant groups."
9555   (interactive
9556    (list current-prefix-arg
9557          (let* ((methods (gnus-methods-using 'respool))
9558                 (methname
9559                  (symbol-name (or gnus-summary-respool-default-method
9560                                   (car (gnus-find-method-for-group
9561                                         gnus-newsgroup-name)))))
9562                 (method
9563                  (gnus-completing-read-with-default
9564                   methname "Backend to use when respooling"
9565                   methods nil t nil 'gnus-mail-method-history))
9566                 ms)
9567            (cond
9568             ((zerop (length (setq ms (gnus-servers-using-backend
9569                                       (intern method)))))
9570              (list (intern method) ""))
9571             ((= 1 (length ms))
9572              (car ms))
9573             (t
9574              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9575                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9576                            ms-alist))))))))
9577   (unless method
9578     (error "No method given for respooling"))
9579   (if (assoc (symbol-name
9580               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9581              (gnus-methods-using 'respool))
9582       (gnus-summary-move-article n nil method)
9583     (gnus-summary-copy-article n nil method)))
9584
9585 (defun gnus-summary-import-article (file &optional edit)
9586   "Import an arbitrary file into a mail newsgroup."
9587   (interactive "fImport file: \nP")
9588   (let ((group gnus-newsgroup-name)
9589         (now (current-time))
9590         atts lines group-art)
9591     (unless (gnus-check-backend-function 'request-accept-article group)
9592       (error "%s does not support article importing" group))
9593     (or (file-readable-p file)
9594         (not (file-regular-p file))
9595         (error "Can't read %s" file))
9596     (save-excursion
9597       (set-buffer (gnus-get-buffer-create " *import file*"))
9598       (erase-buffer)
9599       (nnheader-insert-file-contents file)
9600       (goto-char (point-min))
9601       (if (nnheader-article-p)
9602           (save-restriction
9603             (goto-char (point-min))
9604             (search-forward "\n\n" nil t)
9605             (narrow-to-region (point-min) (1- (point)))
9606             (goto-char (point-min))
9607             (unless (re-search-forward "^date:" nil t)
9608               (goto-char (point-max))
9609               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9610        ;; This doesn't look like an article, so we fudge some headers.
9611         (setq atts (file-attributes file)
9612               lines (count-lines (point-min) (point-max)))
9613         (insert "From: " (read-string "From: ") "\n"
9614                 "Subject: " (read-string "Subject: ") "\n"
9615                 "Date: " (message-make-date (nth 5 atts)) "\n"
9616                 "Message-ID: " (message-make-message-id) "\n"
9617                 "Lines: " (int-to-string lines) "\n"
9618                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9619       (setq group-art (gnus-request-accept-article group nil t))
9620       (kill-buffer (current-buffer)))
9621     (setq gnus-newsgroup-active (gnus-activate-group group))
9622     (forward-line 1)
9623     (gnus-summary-goto-article (cdr group-art) nil t)
9624     (when edit
9625       (gnus-summary-edit-article))))
9626
9627 (defun gnus-summary-create-article ()
9628   "Create an article in a mail newsgroup."
9629   (interactive)
9630   (let ((group gnus-newsgroup-name)
9631         (now (current-time))
9632         group-art)
9633     (unless (gnus-check-backend-function 'request-accept-article group)
9634       (error "%s does not support article importing" group))
9635     (save-excursion
9636       (set-buffer (gnus-get-buffer-create " *import file*"))
9637       (erase-buffer)
9638       (goto-char (point-min))
9639       ;; This doesn't look like an article, so we fudge some headers.
9640       (insert "From: " (read-string "From: ") "\n"
9641               "Subject: " (read-string "Subject: ") "\n"
9642               "Date: " (message-make-date now) "\n"
9643               "Message-ID: " (message-make-message-id) "\n")
9644       (setq group-art (gnus-request-accept-article group nil t))
9645       (kill-buffer (current-buffer)))
9646     (setq gnus-newsgroup-active (gnus-activate-group group))
9647     (forward-line 1)
9648     (gnus-summary-goto-article (cdr group-art) nil t)
9649     (gnus-summary-edit-article)))
9650
9651 (defun gnus-summary-article-posted-p ()
9652   "Say whether the current (mail) article is available from news as well.
9653 This will be the case if the article has both been mailed and posted."
9654   (interactive)
9655   (let ((id (mail-header-references (gnus-summary-article-header)))
9656         (gnus-override-method (car (gnus-refer-article-methods))))
9657     (if (gnus-request-head id "")
9658         (gnus-message 2 "The current message was found on %s"
9659                       gnus-override-method)
9660       (gnus-message 2 "The current message couldn't be found on %s"
9661                     gnus-override-method)
9662       nil)))
9663
9664 (defun gnus-summary-expire-articles (&optional now)
9665   "Expire all articles that are marked as expirable in the current group."
9666   (interactive)
9667   (when (and (not gnus-group-is-exiting-without-update-p)
9668              (gnus-check-backend-function
9669               'request-expire-articles gnus-newsgroup-name))
9670     ;; This backend supports expiry.
9671     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9672            (expirable (if total
9673                           (progn
9674                             ;; We need to update the info for
9675                             ;; this group for `gnus-list-of-read-articles'
9676                             ;; to give us the right answer.
9677                             (gnus-run-hooks 'gnus-exit-group-hook)
9678                             (gnus-summary-update-info)
9679                             (gnus-list-of-read-articles gnus-newsgroup-name))
9680                         (setq gnus-newsgroup-expirable
9681                               (sort gnus-newsgroup-expirable '<))))
9682            (expiry-wait (if now 'immediate
9683                           (gnus-group-find-parameter
9684                            gnus-newsgroup-name 'expiry-wait)))
9685            (nnmail-expiry-target
9686             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9687                 nnmail-expiry-target))
9688            es)
9689       (when expirable
9690         ;; There are expirable articles in this group, so we run them
9691         ;; through the expiry process.
9692         (gnus-message 6 "Expiring articles...")
9693         (unless (gnus-check-group gnus-newsgroup-name)
9694           (error "Can't open server for %s" gnus-newsgroup-name))
9695         ;; The list of articles that weren't expired is returned.
9696         (save-excursion
9697           (if expiry-wait
9698               (let ((nnmail-expiry-wait-function nil)
9699                     (nnmail-expiry-wait expiry-wait))
9700                 (setq es (gnus-request-expire-articles
9701                           expirable gnus-newsgroup-name)))
9702             (setq es (gnus-request-expire-articles
9703                       expirable gnus-newsgroup-name)))
9704           (unless total
9705             (setq gnus-newsgroup-expirable es))
9706           ;; We go through the old list of expirable, and mark all
9707           ;; really expired articles as nonexistent.
9708           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9709             (let ((gnus-use-cache nil))
9710               (dolist (article expirable)
9711                 (when (and (not (memq article es))
9712                            (gnus-data-find article))
9713                   (gnus-summary-mark-article article gnus-canceled-mark)
9714                   (run-hook-with-args 'gnus-summary-article-expire-hook
9715                                       'delete
9716                                       (gnus-data-header
9717                                        (assoc article (gnus-data-list nil)))
9718                                       gnus-newsgroup-name
9719                                       nil
9720                                       nil))))))
9721         (gnus-message 6 "Expiring articles...done")))))
9722
9723 (defun gnus-summary-expire-articles-now ()
9724   "Expunge all expirable articles in the current group.
9725 This means that *all* articles that are marked as expirable will be
9726 deleted forever, right now."
9727   (interactive)
9728   (or gnus-expert-user
9729       (gnus-yes-or-no-p
9730        "Are you really, really sure you want to delete all expirable messages? ")
9731       (error "Phew!"))
9732   (gnus-summary-expire-articles t))
9733
9734 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9735 (defun gnus-summary-delete-article (&optional n)
9736   "Delete the N next (mail) articles.
9737 This command actually deletes articles.  This is not a marking
9738 command.  The article will disappear forever from your life, never to
9739 return.
9740
9741 If N is negative, delete backwards.
9742 If N is nil and articles have been marked with the process mark,
9743 delete these instead.
9744
9745 If `gnus-novice-user' is non-nil you will be asked for
9746 confirmation before the articles are deleted."
9747   (interactive "P")
9748   (unless (gnus-check-backend-function 'request-expire-articles
9749                                        gnus-newsgroup-name)
9750     (error "The current newsgroup does not support article deletion"))
9751   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9752     (error "Couldn't open server"))
9753   ;; Compute the list of articles to delete.
9754   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9755         (nnmail-expiry-target 'delete)
9756         not-deleted)
9757     (if (and gnus-novice-user
9758              (not (gnus-yes-or-no-p
9759                    (format "Do you really want to delete %s forever? "
9760                            (if (> (length articles) 1)
9761                                (format "these %s articles" (length articles))
9762                              "this article")))))
9763         ()
9764       ;; Delete the articles.
9765       (setq not-deleted (gnus-request-expire-articles
9766                          articles gnus-newsgroup-name 'force))
9767       (while articles
9768         (gnus-summary-remove-process-mark (car articles))
9769         ;; The backend might not have been able to delete the article
9770         ;; after all.
9771         (unless (memq (car articles) not-deleted)
9772           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9773         (let* ((article (car articles))
9774                (ghead  (gnus-data-header
9775                                     (assoc article (gnus-data-list nil)))))
9776           (run-hook-with-args 'gnus-summary-article-delete-hook
9777                               'delete ghead gnus-newsgroup-name nil
9778                               nil))
9779         (setq articles (cdr articles)))
9780       (when not-deleted
9781         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9782     (gnus-summary-position-point)
9783     (gnus-set-mode-line 'summary)
9784     not-deleted))
9785
9786 (defun gnus-summary-edit-article (&optional arg)
9787   "Edit the current article.
9788 This will have permanent effect only in mail groups.
9789 If ARG is nil, edit the decoded articles.
9790 If ARG is 1, edit the raw articles.
9791 If ARG is 2, edit the raw articles even in read-only groups.
9792 If ARG is 3, edit the articles with the current handles.
9793 Otherwise, allow editing of articles even in read-only
9794 groups."
9795   (interactive "P")
9796   (let (force raw current-handles)
9797     (cond
9798      ((null arg))
9799      ((eq arg 1)
9800       (setq raw t))
9801      ((eq arg 2)
9802       (setq raw t
9803             force t))
9804      ((eq arg 3)
9805       (setq current-handles
9806             (and (gnus-buffer-live-p gnus-article-buffer)
9807                  (with-current-buffer gnus-article-buffer
9808                    (prog1
9809                        gnus-article-mime-handles
9810                      (setq gnus-article-mime-handles nil))))))
9811      (t
9812       (setq force t)))
9813     (when (and raw (not force)
9814                (member gnus-newsgroup-name '("nndraft:delayed"
9815                                              "nndraft:drafts"
9816                                              "nndraft:queue")))
9817       (error "Can't edit the raw article in group %s"
9818              gnus-newsgroup-name))
9819     (save-excursion
9820       (set-buffer gnus-summary-buffer)
9821       (let ((mail-parse-charset gnus-newsgroup-charset)
9822             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9823         (gnus-set-global-variables)
9824         (when (and (not force)
9825                    (gnus-group-read-only-p))
9826           (error "The current newsgroup does not support article editing"))
9827         (gnus-summary-show-article t)
9828         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9829           (with-current-buffer gnus-article-buffer
9830             (mm-enable-multibyte)))
9831         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9832             (setq raw t))
9833         (gnus-article-edit-article
9834          (if raw 'ignore
9835            `(lambda ()
9836               (let ((mbl mml-buffer-list))
9837                 (setq mml-buffer-list nil)
9838                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9839                   (mime-to-mml ,'current-handles))
9840                 (let ((mbl1 mml-buffer-list))
9841                   (setq mml-buffer-list mbl)
9842                   (set (make-local-variable 'mml-buffer-list) mbl1))
9843                 (gnus-make-local-hook 'kill-buffer-hook)
9844                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9845          `(lambda (no-highlight)
9846             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9847                   (message-options message-options)
9848                   (message-options-set-recipient)
9849                   (mail-parse-ignored-charsets
9850                    ',gnus-newsgroup-ignored-charsets))
9851               ,(if (not raw) '(progn
9852                                 (mml-to-mime)
9853                                 (mml-destroy-buffers)
9854                                 (remove-hook 'kill-buffer-hook
9855                                              'mml-destroy-buffers t)
9856                                 (kill-local-variable 'mml-buffer-list)))
9857               (gnus-summary-edit-article-done
9858                ,(or (mail-header-references gnus-current-headers) "")
9859                ,(gnus-group-read-only-p)
9860                ,gnus-summary-buffer no-highlight))))))))
9861
9862 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9863
9864 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9865                                                  no-highlight)
9866   "Make edits to the current article permanent."
9867   (interactive)
9868   (save-excursion
9869    ;; The buffer restriction contains the entire article if it exists.
9870     (when (article-goto-body)
9871       (let ((lines (count-lines (point) (point-max)))
9872             (length (- (point-max) (point)))
9873             (case-fold-search t)
9874             (body (copy-marker (point))))
9875         (goto-char (point-min))
9876         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9877           (delete-region (match-beginning 1) (match-end 1))
9878           (insert (number-to-string length)))
9879         (goto-char (point-min))
9880         (when (re-search-forward
9881                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9882           (delete-region (match-beginning 1) (match-end 1))
9883           (insert (number-to-string length)))
9884         (goto-char (point-min))
9885         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9886           (delete-region (match-beginning 1) (match-end 1))
9887           (insert (number-to-string lines))))))
9888   ;; Replace the article.
9889   (let ((buf (current-buffer)))
9890     (with-temp-buffer
9891       (insert-buffer-substring buf)
9892
9893       (if (and (not read-only)
9894                (not (gnus-request-replace-article
9895                      (cdr gnus-article-current) (car gnus-article-current)
9896                      (current-buffer) t)))
9897           (error "Couldn't replace article")
9898         ;; Update the summary buffer.
9899         (if (and references
9900                  (equal (message-tokenize-header references " ")
9901                         (message-tokenize-header
9902                          (or (message-fetch-field "references") "") " ")))
9903             ;; We only have to update this line.
9904             (save-excursion
9905               (save-restriction
9906                 (message-narrow-to-head)
9907                 (let ((head (buffer-substring-no-properties
9908                              (point-min) (point-max)))
9909                       header)
9910                   (with-temp-buffer
9911                     (insert (format "211 %d Article retrieved.\n"
9912                                     (cdr gnus-article-current)))
9913                     (insert head)
9914                     (insert ".\n")
9915                     (let ((nntp-server-buffer (current-buffer)))
9916                       (setq header (car (gnus-get-newsgroup-headers
9917                                          nil t))))
9918                     (save-excursion
9919                       (set-buffer gnus-summary-buffer)
9920                       (gnus-data-set-header
9921                        (gnus-data-find (cdr gnus-article-current))
9922                        header)
9923                       (gnus-summary-update-article-line
9924                        (cdr gnus-article-current) header)
9925                       (if (gnus-summary-goto-subject
9926                            (cdr gnus-article-current) nil t)
9927                           (gnus-summary-update-secondary-mark
9928                            (cdr gnus-article-current))))))))
9929           ;; Update threads.
9930           (set-buffer (or buffer gnus-summary-buffer))
9931           (gnus-summary-update-article (cdr gnus-article-current))
9932           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9933               (gnus-summary-update-secondary-mark
9934                (cdr gnus-article-current))))
9935         ;; Prettify the article buffer again.
9936         (unless no-highlight
9937           (save-excursion
9938             (set-buffer gnus-article-buffer)
9939             ;;;!!! Fix this -- article should be rehighlighted.
9940             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9941             (set-buffer gnus-original-article-buffer)
9942             (gnus-request-article
9943              (cdr gnus-article-current)
9944              (car gnus-article-current) (current-buffer))))
9945         ;; Prettify the summary buffer line.
9946         (when (gnus-visual-p 'summary-highlight 'highlight)
9947           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9948
9949 (defun gnus-summary-edit-wash (key)
9950   "Perform editing command KEY in the article buffer."
9951   (interactive
9952    (list
9953     (progn
9954       (message "%s" (concat (this-command-keys) "- "))
9955       (read-char))))
9956   (message "")
9957   (gnus-summary-edit-article)
9958   (execute-kbd-macro (concat (this-command-keys) key))
9959   (gnus-article-edit-done))
9960
9961 ;;; Respooling
9962
9963 (defun gnus-summary-respool-query (&optional silent trace)
9964   "Query where the respool algorithm would put this article."
9965   (interactive)
9966   (let (gnus-mark-article-hook)
9967     (gnus-summary-select-article)
9968     (save-excursion
9969       (set-buffer gnus-original-article-buffer)
9970       (let ((groups (nnmail-article-group 'identity trace)))
9971         (unless silent
9972           (if groups
9973               (message "This message would go to %s"
9974                        (mapconcat 'car groups ", "))
9975             (message "This message would go to no groups"))
9976           groups)))))
9977
9978 (defun gnus-summary-respool-trace ()
9979   "Trace where the respool algorithm would put this article.
9980 Display a buffer showing all fancy splitting patterns which matched."
9981   (interactive)
9982   (gnus-summary-respool-query nil t))
9983
9984 ;; Summary marking commands.
9985
9986 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9987   "Mark articles which has the same subject as read, and then select the next.
9988 If UNMARK is positive, remove any kind of mark.
9989 If UNMARK is negative, tick articles."
9990   (interactive "P")
9991   (when unmark
9992     (setq unmark (prefix-numeric-value unmark)))
9993   (let ((count
9994          (gnus-summary-mark-same-subject
9995           (gnus-summary-article-subject) unmark)))
9996     ;; Select next unread article.  If auto-select-same mode, should
9997     ;; select the first unread article.
9998     (gnus-summary-next-article t (and gnus-auto-select-same
9999                                       (gnus-summary-article-subject)))
10000     (gnus-message 7 "%d article%s marked as %s"
10001                   count (if (= count 1) " is" "s are")
10002                   (if unmark "unread" "read"))))
10003
10004 (defun gnus-summary-kill-same-subject (&optional unmark)
10005   "Mark articles which has the same subject as read.
10006 If UNMARK is positive, remove any kind of mark.
10007 If UNMARK is negative, tick articles."
10008   (interactive "P")
10009   (when unmark
10010     (setq unmark (prefix-numeric-value unmark)))
10011   (let ((count
10012          (gnus-summary-mark-same-subject
10013           (gnus-summary-article-subject) unmark)))
10014     ;; If marked as read, go to next unread subject.
10015     (when (null unmark)
10016       ;; Go to next unread subject.
10017       (gnus-summary-next-subject 1 t))
10018     (gnus-message 7 "%d articles are marked as %s"
10019                   count (if unmark "unread" "read"))))
10020
10021 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10022   "Mark articles with same SUBJECT as read, and return marked number.
10023 If optional argument UNMARK is positive, remove any kinds of marks.
10024 If optional argument UNMARK is negative, mark articles as unread instead."
10025   (let ((count 1))
10026     (save-excursion
10027       (cond
10028        ((null unmark)                   ; Mark as read.
10029         (while (and
10030                 (progn
10031                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10032                   (gnus-summary-show-thread) t)
10033                 (gnus-summary-find-subject subject))
10034           (setq count (1+ count))))
10035        ((> unmark 0)                    ; Tick.
10036         (while (and
10037                 (progn
10038                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10039                   (gnus-summary-show-thread) t)
10040                 (gnus-summary-find-subject subject))
10041           (setq count (1+ count))))
10042        (t                               ; Mark as unread.
10043         (while (and
10044                 (progn
10045                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10046                   (gnus-summary-show-thread) t)
10047                 (gnus-summary-find-subject subject))
10048           (setq count (1+ count)))))
10049       (gnus-set-mode-line 'summary)
10050       ;; Return the number of marked articles.
10051       count)))
10052
10053 (defun gnus-summary-mark-as-processable (n &optional unmark)
10054   "Set the process mark on the next N articles.
10055 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10056 the process mark instead.  The difference between N and the actual
10057 number of articles marked is returned."
10058   (interactive "P")
10059   (if (and (null n) (gnus-region-active-p))
10060       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10061     (setq n (prefix-numeric-value n))
10062     (let ((backward (< n 0))
10063           (n (abs n)))
10064       (while (and
10065               (> n 0)
10066               (if unmark
10067                   (gnus-summary-remove-process-mark
10068                    (gnus-summary-article-number))
10069                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10070               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10071         (setq n (1- n)))
10072       (when (/= 0 n)
10073         (gnus-message 7 "No more articles"))
10074       (gnus-summary-recenter)
10075       (gnus-summary-position-point)
10076       n)))
10077
10078 (defun gnus-summary-unmark-as-processable (n)
10079   "Remove the process mark from the next N articles.
10080 If N is negative, unmark backward instead.  The difference between N and
10081 the actual number of articles unmarked is returned."
10082   (interactive "P")
10083   (gnus-summary-mark-as-processable n t))
10084
10085 (defun gnus-summary-unmark-all-processable ()
10086   "Remove the process mark from all articles."
10087   (interactive)
10088   (save-excursion
10089     (while gnus-newsgroup-processable
10090       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10091   (gnus-summary-position-point))
10092
10093 (defun gnus-summary-add-mark (article type)
10094   "Mark ARTICLE with a mark of TYPE."
10095   (let ((vtype (car (assq type gnus-article-mark-lists)))
10096         var)
10097     (if (not vtype)
10098         (error "No such mark type: %s" type)
10099       (setq var (intern (format "gnus-newsgroup-%s" type)))
10100       (set var (cons article (symbol-value var)))
10101       (if (memq type '(processable cached replied forwarded recent saved))
10102           (gnus-summary-update-secondary-mark article)
10103         ;;; !!! This is bogus.  We should find out what primary
10104         ;;; !!! mark we want to set.
10105         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10106
10107 (defun gnus-summary-mark-as-expirable (n)
10108   "Mark N articles forward as expirable.
10109 If N is negative, mark backward instead.  The difference between N and
10110 the actual number of articles marked is returned."
10111   (interactive "p")
10112   (gnus-summary-mark-forward n gnus-expirable-mark))
10113
10114 (defun gnus-summary-mark-as-spam (n)
10115   "Mark N articles forward as spam.
10116 If N is negative, mark backward instead.  The difference between N and
10117 the actual number of articles marked is returned."
10118   (interactive "p")
10119   (gnus-summary-mark-forward n gnus-spam-mark))
10120
10121 (defun gnus-summary-mark-article-as-replied (article)
10122   "Mark ARTICLE as replied to and update the summary line.
10123 ARTICLE can also be a list of articles."
10124   (interactive (list (gnus-summary-article-number)))
10125   (let ((articles (if (listp article) article (list article))))
10126     (dolist (article articles)
10127       (unless (numberp article)
10128         (error "%s is not a number" article))
10129       (push article gnus-newsgroup-replied)
10130       (let ((buffer-read-only nil))
10131         (when (gnus-summary-goto-subject article nil t)
10132           (gnus-summary-update-secondary-mark article))))))
10133
10134 (defun gnus-summary-mark-article-as-forwarded (article)
10135   "Mark ARTICLE as forwarded and update the summary line.
10136 ARTICLE can also be a list of articles."
10137   (let ((articles (if (listp article) article (list article))))
10138     (dolist (article articles)
10139       (push article gnus-newsgroup-forwarded)
10140       (let ((buffer-read-only nil))
10141         (when (gnus-summary-goto-subject article nil t)
10142           (gnus-summary-update-secondary-mark article))))))
10143
10144 (defun gnus-summary-set-bookmark (article)
10145   "Set a bookmark in current article."
10146   (interactive (list (gnus-summary-article-number)))
10147   (when (or (not (get-buffer gnus-article-buffer))
10148             (not gnus-current-article)
10149             (not gnus-article-current)
10150             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10151     (error "No current article selected"))
10152   ;; Remove old bookmark, if one exists.
10153   (gnus-pull article gnus-newsgroup-bookmarks)
10154   ;; Set the new bookmark, which is on the form
10155   ;; (article-number . line-number-in-body).
10156   (push
10157    (cons article
10158          (with-current-buffer gnus-article-buffer
10159            (count-lines
10160             (min (point)
10161                  (save-excursion
10162                    (article-goto-body)
10163                    (point)))
10164             (point))))
10165    gnus-newsgroup-bookmarks)
10166   (gnus-message 6 "A bookmark has been added to the current article."))
10167
10168 (defun gnus-summary-remove-bookmark (article)
10169   "Remove the bookmark from the current article."
10170   (interactive (list (gnus-summary-article-number)))
10171   ;; Remove old bookmark, if one exists.
10172   (if (not (assq article gnus-newsgroup-bookmarks))
10173       (gnus-message 6 "No bookmark in current article.")
10174     (gnus-pull article gnus-newsgroup-bookmarks)
10175     (gnus-message 6 "Removed bookmark.")))
10176
10177 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10178 (defun gnus-summary-mark-as-dormant (n)
10179   "Mark N articles forward as dormant.
10180 If N is negative, mark backward instead.  The difference between N and
10181 the actual number of articles marked is returned."
10182   (interactive "p")
10183   (gnus-summary-mark-forward n gnus-dormant-mark))
10184
10185 (defun gnus-summary-set-process-mark (article)
10186   "Set the process mark on ARTICLE and update the summary line."
10187   (setq gnus-newsgroup-processable
10188         (cons article
10189               (delq article gnus-newsgroup-processable)))
10190   (when (gnus-summary-goto-subject article)
10191     (gnus-summary-show-thread)
10192     (gnus-summary-goto-subject article)
10193     (gnus-summary-update-secondary-mark article)))
10194
10195 (defun gnus-summary-remove-process-mark (&rest articles)
10196   "Remove the process mark from ARTICLES and update the summary line."
10197   (dolist (article articles)
10198     (setq gnus-newsgroup-processable (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   t)
10204
10205 (defun gnus-summary-set-saved-mark (article)
10206   "Set the process mark on ARTICLE and update the summary line."
10207   (push article gnus-newsgroup-saved)
10208   (when (gnus-summary-goto-subject article)
10209     (gnus-summary-update-secondary-mark article)))
10210
10211 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10212   "Mark N articles as read forwards.
10213 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10214 The difference between N and the actual number of articles marked is
10215 returned.
10216 If NO-EXPIRE, auto-expiry will be inhibited."
10217   (interactive "p")
10218   (gnus-summary-show-thread)
10219   (let ((backward (< n 0))
10220         (gnus-summary-goto-unread
10221          (and gnus-summary-goto-unread
10222               (not (eq gnus-summary-goto-unread 'never))
10223               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10224                                     gnus-ticked-mark gnus-dormant-mark)))))
10225         (n (abs n))
10226         (mark (or mark gnus-del-mark)))
10227     (while (and (> n 0)
10228                 (gnus-summary-mark-article nil mark no-expire)
10229                 (zerop (gnus-summary-next-subject
10230                         (if backward -1 1)
10231                         (and gnus-summary-goto-unread
10232                              (not (eq gnus-summary-goto-unread 'never)))
10233                         t)))
10234       (setq n (1- n)))
10235     (when (/= 0 n)
10236       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10237     (gnus-summary-recenter)
10238     (gnus-summary-position-point)
10239     (gnus-set-mode-line 'summary)
10240     n))
10241
10242 (defun gnus-summary-mark-article-as-read (mark)
10243   "Mark the current article quickly as read with MARK."
10244   (let ((article (gnus-summary-article-number)))
10245     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10246     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10247     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10248     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10249     (push (cons article mark) gnus-newsgroup-reads)
10250     ;; Possibly remove from cache, if that is used.
10251     (when gnus-use-cache
10252       (gnus-cache-enter-remove-article article))
10253     ;; Allow the backend to change the mark.
10254     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10255     ;; Check for auto-expiry.
10256     (when (and gnus-newsgroup-auto-expire
10257                (memq mark gnus-auto-expirable-marks))
10258       (setq mark gnus-expirable-mark)
10259       ;; Let the backend know about the mark change.
10260       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10261       (push article gnus-newsgroup-expirable))
10262     ;; Set the mark in the buffer.
10263     (gnus-summary-update-mark mark 'unread)
10264     t))
10265
10266 (defun gnus-summary-mark-article-as-unread (mark)
10267   "Mark the current article quickly as unread with MARK."
10268   (let* ((article (gnus-summary-article-number))
10269          (old-mark (gnus-summary-article-mark article)))
10270     ;; Allow the backend to change the mark.
10271     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10272     (if (eq mark old-mark)
10273         t
10274       (if (<= article 0)
10275           (progn
10276             (gnus-error 1 "Can't mark negative article numbers")
10277             nil)
10278         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10279         (setq gnus-newsgroup-spam-marked
10280               (delq article gnus-newsgroup-spam-marked))
10281         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10282         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10283         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10284         (cond ((= mark gnus-ticked-mark)
10285                (setq gnus-newsgroup-marked
10286                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10287                                               article)))
10288               ((= mark gnus-spam-mark)
10289                (setq gnus-newsgroup-spam-marked
10290                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10291                                               article)))
10292               ((= mark gnus-dormant-mark)
10293                (setq gnus-newsgroup-dormant
10294                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10295                                               article)))
10296               (t
10297                (setq gnus-newsgroup-unreads
10298                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10299                                               article))))
10300         (gnus-pull article gnus-newsgroup-reads)
10301
10302         ;; See whether the article is to be put in the cache.
10303         (and gnus-use-cache
10304              (vectorp (gnus-summary-article-header article))
10305              (save-excursion
10306                (gnus-cache-possibly-enter-article
10307                 gnus-newsgroup-name article
10308                 (= mark gnus-ticked-mark)
10309                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10310
10311         ;; Fix the mark.
10312         (gnus-summary-update-mark mark 'unread)
10313         t))))
10314
10315 (defun gnus-summary-mark-article (&optional article mark no-expire)
10316   "Mark ARTICLE with MARK.  MARK can be any character.
10317 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10318 `??' (dormant) and `?E' (expirable).
10319 If MARK is nil, then the default character `?r' is used.
10320 If ARTICLE is nil, then the article on the current line will be
10321 marked.
10322 If NO-EXPIRE, auto-expiry will be inhibited."
10323   ;; The mark might be a string.
10324   (when (stringp mark)
10325     (setq mark (aref mark 0)))
10326   ;; If no mark is given, then we check auto-expiring.
10327   (when (null mark)
10328     (setq mark gnus-del-mark))
10329   (when (and (not no-expire)
10330              gnus-newsgroup-auto-expire
10331              (memq mark gnus-auto-expirable-marks))
10332     (setq mark gnus-expirable-mark))
10333   (let ((article (or article (gnus-summary-article-number)))
10334         (old-mark (gnus-summary-article-mark article)))
10335     ;; Allow the backend to change the mark.
10336     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10337     (if (eq mark old-mark)
10338         t
10339       (unless article
10340         (error "No article on current line"))
10341       (if (not (if (or (= mark gnus-unread-mark)
10342                        (= mark gnus-ticked-mark)
10343                        (= mark gnus-spam-mark)
10344                        (= mark gnus-dormant-mark))
10345                    (gnus-mark-article-as-unread article mark)
10346                  (gnus-mark-article-as-read article mark)))
10347           t
10348         ;; See whether the article is to be put in the cache.
10349         (and gnus-use-cache
10350              (not (= mark gnus-canceled-mark))
10351              (vectorp (gnus-summary-article-header article))
10352              (save-excursion
10353                (gnus-cache-possibly-enter-article
10354                 gnus-newsgroup-name article
10355                 (= mark gnus-ticked-mark)
10356                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10357
10358         (when (gnus-summary-goto-subject article nil t)
10359           (let ((buffer-read-only nil))
10360             (gnus-summary-show-thread)
10361             ;; Fix the mark.
10362             (gnus-summary-update-mark mark 'unread)
10363             t))))))
10364
10365 (defun gnus-summary-update-secondary-mark (article)
10366   "Update the secondary (read, process, cache) mark."
10367   (gnus-summary-update-mark
10368    (cond ((memq article gnus-newsgroup-processable)
10369           gnus-process-mark)
10370          ((memq article gnus-newsgroup-cached)
10371           gnus-cached-mark)
10372          ((memq article gnus-newsgroup-replied)
10373           gnus-replied-mark)
10374          ((memq article gnus-newsgroup-forwarded)
10375           gnus-forwarded-mark)
10376          ((memq article gnus-newsgroup-saved)
10377           gnus-saved-mark)
10378          ((memq article gnus-newsgroup-recent)
10379           gnus-recent-mark)
10380          ((memq article gnus-newsgroup-unseen)
10381           gnus-unseen-mark)
10382          (t gnus-no-mark))
10383    'replied)
10384   (when (gnus-visual-p 'summary-highlight 'highlight)
10385     (gnus-run-hooks 'gnus-summary-update-hook))
10386   t)
10387
10388 (defun gnus-summary-update-download-mark (article)
10389   "Update the download mark."
10390   (gnus-summary-update-mark
10391    (cond ((memq article gnus-newsgroup-undownloaded)
10392           gnus-undownloaded-mark)
10393          (gnus-newsgroup-agentized
10394           gnus-downloaded-mark)
10395          (t
10396           gnus-no-mark))
10397    'download)
10398   (gnus-summary-update-line t)
10399   t)
10400
10401 (defun gnus-summary-update-mark (mark type)
10402   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10403         (buffer-read-only nil))
10404     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10405     (when forward
10406       (when (looking-at "\r")
10407         (incf forward))
10408       (when (<= (+ forward (point)) (point-max))
10409         ;; Go to the right position on the line.
10410         (goto-char (+ forward (point)))
10411         ;; Replace the old mark with the new mark.
10412         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10413         ;; Optionally update the marks by some user rule.
10414         (when (eq type 'unread)
10415           (gnus-data-set-mark
10416            (gnus-data-find (gnus-summary-article-number)) mark)
10417           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10418
10419 (defun gnus-mark-article-as-read (article &optional mark)
10420   "Enter ARTICLE in the pertinent lists and remove it from others."
10421   ;; Make the article expirable.
10422   (let ((mark (or mark gnus-del-mark)))
10423     (setq gnus-newsgroup-expirable
10424           (if (= mark gnus-expirable-mark)
10425               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10426             (delq article gnus-newsgroup-expirable)))
10427     ;; Remove from unread and marked lists.
10428     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10429     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10430     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10431     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10432     (push (cons article mark) gnus-newsgroup-reads)
10433     ;; Possibly remove from cache, if that is used.
10434     (when gnus-use-cache
10435       (gnus-cache-enter-remove-article article))
10436     t))
10437
10438 (defun gnus-mark-article-as-unread (article &optional mark)
10439   "Enter ARTICLE in the pertinent lists and remove it from others."
10440   (let ((mark (or mark gnus-ticked-mark)))
10441     (if (<= article 0)
10442         (progn
10443           (gnus-error 1 "Can't mark negative article numbers")
10444           nil)
10445       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10446             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10447             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10448             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10449             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10450
10451       ;; Unsuppress duplicates?
10452       (when gnus-suppress-duplicates
10453         (gnus-dup-unsuppress-article article))
10454
10455       (cond ((= mark gnus-ticked-mark)
10456              (setq gnus-newsgroup-marked
10457                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10458             ((= mark gnus-spam-mark)
10459              (setq gnus-newsgroup-spam-marked
10460                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10461                                             article)))
10462             ((= mark gnus-dormant-mark)
10463              (setq gnus-newsgroup-dormant
10464                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10465             (t
10466              (setq gnus-newsgroup-unreads
10467                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10468       (gnus-pull article gnus-newsgroup-reads)
10469       t)))
10470
10471 (defalias 'gnus-summary-mark-as-unread-forward
10472   'gnus-summary-tick-article-forward)
10473 (make-obsolete 'gnus-summary-mark-as-unread-forward
10474                'gnus-summary-tick-article-forward)
10475 (defun gnus-summary-tick-article-forward (n)
10476   "Tick N articles forwards.
10477 If N is negative, tick backwards instead.
10478 The difference between N and the number of articles ticked is returned."
10479   (interactive "p")
10480   (gnus-summary-mark-forward n gnus-ticked-mark))
10481
10482 (defalias 'gnus-summary-mark-as-unread-backward
10483   'gnus-summary-tick-article-backward)
10484 (make-obsolete 'gnus-summary-mark-as-unread-backward
10485                'gnus-summary-tick-article-backward)
10486 (defun gnus-summary-tick-article-backward (n)
10487   "Tick N articles backwards.
10488 The difference between N and the number of articles ticked is returned."
10489   (interactive "p")
10490   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10491
10492 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10493 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10494 (defun gnus-summary-tick-article (&optional article clear-mark)
10495   "Mark current article as unread.
10496 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10497 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10498   (interactive)
10499   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10500                                        gnus-ticked-mark)))
10501
10502 (defun gnus-summary-mark-as-read-forward (n)
10503   "Mark N articles as read forwards.
10504 If N is negative, mark backwards instead.
10505 The difference between N and the actual number of articles marked is
10506 returned."
10507   (interactive "p")
10508   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10509
10510 (defun gnus-summary-mark-as-read-backward (n)
10511   "Mark the N articles as read backwards.
10512 The difference between N and the actual number of articles marked is
10513 returned."
10514   (interactive "p")
10515   (gnus-summary-mark-forward
10516    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10517
10518 (defun gnus-summary-mark-as-read (&optional article mark)
10519   "Mark current article as read.
10520 ARTICLE specifies the article to be marked as read.
10521 MARK specifies a string to be inserted at the beginning of the line."
10522   (gnus-summary-mark-article article mark))
10523
10524 (defun gnus-summary-clear-mark-forward (n)
10525   "Clear marks from N articles forward.
10526 If N is negative, clear backward instead.
10527 The difference between N and the number of marks cleared is returned."
10528   (interactive "p")
10529   (gnus-summary-mark-forward n gnus-unread-mark))
10530
10531 (defun gnus-summary-clear-mark-backward (n)
10532   "Clear marks from N articles backward.
10533 The difference between N and the number of marks cleared is returned."
10534   (interactive "p")
10535   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10536
10537 (defun gnus-summary-mark-unread-as-read ()
10538   "Intended to be used by `gnus-summary-mark-article-hook'."
10539   (when (memq gnus-current-article gnus-newsgroup-unreads)
10540     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10541
10542 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10543   "Intended to be used by `gnus-summary-mark-article-hook'."
10544   (let ((mark (gnus-summary-article-mark)))
10545     (when (or (gnus-unread-mark-p mark)
10546               (gnus-read-mark-p mark))
10547       (gnus-summary-mark-article gnus-current-article
10548                                  (or new-mark gnus-read-mark)))))
10549
10550 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10551   "Intended to be used by `gnus-summary-mark-article-hook'."
10552   (let ((mark (gnus-summary-article-mark)))
10553     (when (or (gnus-unread-mark-p mark)
10554               (gnus-read-mark-p mark))
10555       (gnus-summary-mark-article (gnus-summary-article-number)
10556                                  (or new-mark gnus-read-mark)))))
10557
10558 (defun gnus-summary-mark-unread-as-ticked ()
10559   "Intended to be used by `gnus-summary-mark-article-hook'."
10560   (when (memq gnus-current-article gnus-newsgroup-unreads)
10561     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10562
10563 (defun gnus-summary-mark-region-as-read (point mark all)
10564   "Mark all unread articles between point and mark as read.
10565 If given a prefix, mark all articles between point and mark as read,
10566 even ticked and dormant ones."
10567   (interactive "r\nP")
10568   (save-excursion
10569     (let (article)
10570       (goto-char point)
10571       (beginning-of-line)
10572       (while (and
10573               (< (point) mark)
10574               (progn
10575                 (when (or all
10576                           (memq (setq article (gnus-summary-article-number))
10577                                 gnus-newsgroup-unreads))
10578                   (gnus-summary-mark-article article gnus-del-mark))
10579                 t)
10580               (gnus-summary-find-next))))))
10581
10582 (defun gnus-summary-mark-below (score mark)
10583   "Mark articles with score less than SCORE with MARK."
10584   (interactive "P\ncMark: ")
10585   (setq score (if score
10586                   (prefix-numeric-value score)
10587                 (or gnus-summary-default-score 0)))
10588   (save-excursion
10589     (set-buffer gnus-summary-buffer)
10590     (goto-char (point-min))
10591     (while
10592         (progn
10593           (and (< (gnus-summary-article-score) score)
10594                (gnus-summary-mark-article nil mark))
10595           (gnus-summary-find-next)))))
10596
10597 (defun gnus-summary-kill-below (&optional score)
10598   "Mark articles with score below SCORE as read."
10599   (interactive "P")
10600   (gnus-summary-mark-below score gnus-killed-mark))
10601
10602 (defun gnus-summary-clear-above (&optional score)
10603   "Clear all marks from articles with score above SCORE."
10604   (interactive "P")
10605   (gnus-summary-mark-above score gnus-unread-mark))
10606
10607 (defun gnus-summary-tick-above (&optional score)
10608   "Tick all articles with score above SCORE."
10609   (interactive "P")
10610   (gnus-summary-mark-above score gnus-ticked-mark))
10611
10612 (defun gnus-summary-mark-above (score mark)
10613   "Mark articles with score over SCORE with MARK."
10614   (interactive "P\ncMark: ")
10615   (setq score (if score
10616                   (prefix-numeric-value score)
10617                 (or gnus-summary-default-score 0)))
10618   (save-excursion
10619     (set-buffer gnus-summary-buffer)
10620     (goto-char (point-min))
10621     (while (and (progn
10622                   (when (> (gnus-summary-article-score) score)
10623                     (gnus-summary-mark-article nil mark))
10624                   t)
10625                 (gnus-summary-find-next)))))
10626
10627 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10628 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10629 (defun gnus-summary-limit-include-expunged (&optional no-error)
10630   "Display all the hidden articles that were expunged for low scores."
10631   (interactive)
10632   (let ((buffer-read-only nil))
10633     (let ((scored gnus-newsgroup-scored)
10634           headers h)
10635       (while scored
10636         (unless (gnus-summary-article-header (caar scored))
10637           (and (setq h (gnus-number-to-header (caar scored)))
10638                (< (cdar scored) gnus-summary-expunge-below)
10639                (push h headers)))
10640         (setq scored (cdr scored)))
10641       (if (not headers)
10642           (when (not no-error)
10643             (error "No expunged articles hidden"))
10644         (goto-char (point-min))
10645         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10646         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10647         (mapcar (lambda (x) (push (mail-header-number x)
10648                                   gnus-newsgroup-limit))
10649                 headers)
10650         (gnus-summary-prepare-unthreaded (nreverse headers))
10651         (goto-char (point-min))
10652         (gnus-summary-position-point)
10653         t))))
10654
10655 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10656   "Mark all unread articles in this newsgroup as read.
10657 If prefix argument ALL is non-nil, ticked and dormant articles will
10658 also be marked as read.
10659 If QUIETLY is non-nil, no questions will be asked.
10660
10661 If TO-HERE is non-nil, it should be a point in the buffer.  All
10662 articles before (after, if REVERSE is set) this point will be marked
10663 as read.
10664
10665 Note that this function will only catch up the unread article
10666 in the current summary buffer limitation.
10667
10668 The number of articles marked as read is returned."
10669   (interactive "P")
10670   (prog1
10671       (save-excursion
10672         (when (or quietly
10673                   (not gnus-interactive-catchup) ;Without confirmation?
10674                   gnus-expert-user
10675                   (gnus-y-or-n-p
10676                    (if all
10677                        "Mark absolutely all articles as read? "
10678                      "Mark all unread articles as read? ")))
10679           (if (and not-mark
10680                    (not gnus-newsgroup-adaptive)
10681                    (not gnus-newsgroup-auto-expire)
10682                    (not gnus-suppress-duplicates)
10683                    (or (not gnus-use-cache)
10684                        (eq gnus-use-cache 'passive)))
10685               (progn
10686                 (when all
10687                   (setq gnus-newsgroup-marked nil
10688                         gnus-newsgroup-spam-marked nil
10689                         gnus-newsgroup-dormant nil))
10690                 (setq gnus-newsgroup-unreads
10691                       (gnus-sorted-nunion
10692                        (gnus-intersection gnus-newsgroup-unreads
10693                                           gnus-newsgroup-downloadable)
10694                        gnus-newsgroup-unfetched)))
10695             ;; We actually mark all articles as canceled, which we
10696             ;; have to do when using auto-expiry or adaptive scoring.
10697             (gnus-summary-show-all-threads)
10698             (if (and to-here reverse)
10699                 (progn
10700                   (goto-char to-here)
10701                   (gnus-summary-mark-current-read-and-unread-as-read
10702                    gnus-catchup-mark)
10703                   (while (gnus-summary-find-next (not all))
10704                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10705               (when (gnus-summary-first-subject (not all))
10706                 (while (and
10707                         (if to-here (< (point) to-here) t)
10708                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10709                         (gnus-summary-find-next (not all))))))
10710             (gnus-set-mode-line 'summary))
10711           t))
10712     (gnus-summary-position-point)))
10713
10714 (defun gnus-summary-catchup-to-here (&optional all)
10715   "Mark all unticked articles before the current one as read.
10716 If ALL is non-nil, also mark ticked and dormant articles as read."
10717   (interactive "P")
10718   (save-excursion
10719     (gnus-save-hidden-threads
10720       (let ((beg (point)))
10721         ;; We check that there are unread articles.
10722         (when (or all (gnus-summary-find-prev))
10723           (gnus-summary-catchup all t beg)))))
10724   (gnus-summary-position-point))
10725
10726 (defun gnus-summary-catchup-from-here (&optional all)
10727   "Mark all unticked articles after (and including) the current one as read.
10728 If ALL is non-nil, also mark ticked and dormant articles as read."
10729   (interactive "P")
10730   (save-excursion
10731     (gnus-save-hidden-threads
10732       (let ((beg (point)))
10733         ;; We check that there are unread articles.
10734         (when (or all (gnus-summary-find-next))
10735           (gnus-summary-catchup all t beg nil t)))))
10736   (gnus-summary-position-point))
10737
10738 (defun gnus-summary-catchup-all (&optional quietly)
10739   "Mark all articles in this newsgroup as read.
10740 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10741 instead, which marks only unread articles as read."
10742   (interactive "P")
10743   (gnus-summary-catchup t quietly))
10744
10745 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10746   "Mark all unread articles in this group as read, then exit.
10747 If prefix argument ALL is non-nil, all articles are marked as read.
10748 If QUIETLY is non-nil, no questions will be asked."
10749   (interactive "P")
10750   (when (gnus-summary-catchup all quietly nil 'fast)
10751     ;; Select next newsgroup or exit.
10752     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10753              (eq gnus-auto-select-next 'quietly))
10754         (gnus-summary-next-group nil)
10755       (gnus-summary-exit))))
10756
10757 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10758   "Mark all articles in this newsgroup as read, and then exit.
10759 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10760 instead, which marks only unread articles as read."
10761   (interactive "P")
10762   (gnus-summary-catchup-and-exit t quietly))
10763
10764 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10765   "Mark all articles in this group as read and select the next group.
10766 If given a prefix, mark all articles, unread as well as ticked, as
10767 read."
10768   (interactive "P")
10769   (save-excursion
10770     (gnus-summary-catchup all))
10771   (gnus-summary-next-group))
10772
10773 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10774   "Mark all articles in this group as read and select the previous 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 nil nil t))
10781
10782 ;;;
10783 ;;; with article
10784 ;;;
10785
10786 (defmacro gnus-with-article (article &rest forms)
10787   "Select ARTICLE and perform FORMS in the original article buffer.
10788 Then replace the article with the result."
10789   `(progn
10790      ;; We don't want the article to be marked as read.
10791      (let (gnus-mark-article-hook)
10792        (gnus-summary-select-article t t nil ,article))
10793      (set-buffer gnus-original-article-buffer)
10794      ,@forms
10795      (if (not (gnus-check-backend-function
10796                'request-replace-article (car gnus-article-current)))
10797          (gnus-message 5 "Read-only group; not replacing")
10798        (unless (gnus-request-replace-article
10799                 ,article (car gnus-article-current)
10800                 (current-buffer) t)
10801          (error "Couldn't replace article")))
10802      ;; The cache and backlog have to be flushed somewhat.
10803      (when gnus-keep-backlog
10804        (gnus-backlog-remove-article
10805         (car gnus-article-current) (cdr gnus-article-current)))
10806      (when gnus-use-cache
10807        (gnus-cache-update-article
10808         (car gnus-article-current) (cdr gnus-article-current)))))
10809
10810 (put 'gnus-with-article 'lisp-indent-function 1)
10811 (put 'gnus-with-article 'edebug-form-spec '(form body))
10812
10813 ;; Thread-based commands.
10814
10815 (defun gnus-summary-articles-in-thread (&optional article)
10816   "Return a list of all articles in the current thread.
10817 If ARTICLE is non-nil, return all articles in the thread that starts
10818 with that article."
10819   (let* ((article (or article (gnus-summary-article-number)))
10820          (data (gnus-data-find-list article))
10821          (top-level (gnus-data-level (car data)))
10822          (top-subject
10823           (cond ((null gnus-thread-operation-ignore-subject)
10824                  (gnus-simplify-subject-re
10825                   (mail-header-subject (gnus-data-header (car data)))))
10826                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10827                  (gnus-simplify-subject-fuzzy
10828                   (mail-header-subject (gnus-data-header (car data)))))
10829                 (t nil)))
10830          (end-point (save-excursion
10831                       (if (gnus-summary-go-to-next-thread)
10832                           (point) (point-max))))
10833          articles)
10834     (while (and data
10835                 (< (gnus-data-pos (car data)) end-point))
10836       (when (or (not top-subject)
10837                 (string= top-subject
10838                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10839                              (gnus-simplify-subject-fuzzy
10840                               (mail-header-subject
10841                                (gnus-data-header (car data))))
10842                            (gnus-simplify-subject-re
10843                             (mail-header-subject
10844                              (gnus-data-header (car data)))))))
10845         (push (gnus-data-number (car data)) articles))
10846       (unless (and (setq data (cdr data))
10847                    (> (gnus-data-level (car data)) top-level))
10848         (setq data nil)))
10849     ;; Return the list of articles.
10850     (nreverse articles)))
10851
10852 (defun gnus-summary-rethread-current ()
10853   "Rethread the thread the current article is part of."
10854   (interactive)
10855   (let* ((gnus-show-threads t)
10856          (article (gnus-summary-article-number))
10857          (id (mail-header-id (gnus-summary-article-header)))
10858          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10859     (unless id
10860       (error "No article on the current line"))
10861     (gnus-rebuild-thread id)
10862     (gnus-summary-goto-subject article)))
10863
10864 (defun gnus-summary-reparent-thread ()
10865   "Make the current article child of the marked (or previous) article.
10866
10867 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10868 is non-nil or the Subject: of both articles are the same."
10869   (interactive)
10870   (unless (not (gnus-group-read-only-p))
10871     (error "The current newsgroup does not support article editing"))
10872   (unless (<= (length gnus-newsgroup-processable) 1)
10873     (error "No more than one article may be marked"))
10874   (let ((child (gnus-summary-article-number))
10875         ;; First grab the marked article, otherwise one line up.
10876         (parent (if (not (null gnus-newsgroup-processable))
10877                     (car gnus-newsgroup-processable)
10878                   (save-excursion
10879                     (if (eq (forward-line -1) 0)
10880                         (gnus-summary-article-number)
10881                       (error "Beginning of summary buffer"))))))
10882     (gnus-summary-reparent-children parent (list child))))
10883
10884 (defun gnus-summary-reparent-children (parent children)
10885   "Make PARENT the parent of CHILDREN.
10886 When called interactively, PARENT is is current article and
10887 CHILDREN are the process-marked articles."
10888   (interactive
10889    (list (gnus-summary-article-number)
10890          (gnus-summary-work-articles nil)))
10891   (dolist (child children)
10892     (save-window-excursion
10893       (let ((gnus-article-buffer " *reparent*"))
10894         (unless (not (eq parent child))
10895           (error "An article may not be self-referential"))
10896         (let ((message-id (mail-header-id
10897                            (gnus-summary-article-header parent))))
10898           (unless (and message-id (not (equal message-id "")))
10899             (error "No message-id in desired parent"))
10900           (gnus-with-article child
10901             (save-restriction
10902               (goto-char (point-min))
10903               (message-narrow-to-head)
10904               (if (re-search-forward "^References: " nil t)
10905                   (progn
10906                     (re-search-forward "^[^ \t]" nil t)
10907                     (forward-line -1)
10908                     (end-of-line)
10909                     (insert " " message-id))
10910                 (insert "References: " message-id "\n"))))
10911           (set-buffer gnus-summary-buffer)
10912           (gnus-summary-unmark-all-processable)
10913           (gnus-summary-update-article child)
10914           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10915             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10916           (gnus-summary-rethread-current)
10917           (gnus-message 3 "Article %d is now the child of article %d"
10918                         child parent))))))
10919
10920 (defun gnus-summary-toggle-threads (&optional arg)
10921   "Toggle showing conversation threads.
10922 If ARG is positive number, turn showing conversation threads on."
10923   (interactive "P")
10924   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10925     (setq gnus-show-threads
10926           (if (null arg) (not gnus-show-threads)
10927             (> (prefix-numeric-value arg) 0)))
10928     (gnus-summary-prepare)
10929     (gnus-summary-goto-subject current)
10930     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10931     (gnus-summary-position-point)))
10932
10933 (defun gnus-summary-show-all-threads ()
10934   "Show all threads."
10935   (interactive)
10936   (save-excursion
10937     (let ((buffer-read-only nil))
10938       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10939   (gnus-summary-position-point))
10940
10941 (defun gnus-summary-show-thread ()
10942   "Show thread subtrees.
10943 Returns nil if no thread was there to be shown."
10944   (interactive)
10945   (let ((buffer-read-only nil)
10946         (orig (point))
10947         (end (point-at-eol))
10948         ;; Leave point at bol
10949         (beg (progn (beginning-of-line) (point))))
10950     (prog1
10951         ;; Any hidden lines here?
10952         (search-forward "\r" end t)
10953       (subst-char-in-region beg end ?\^M ?\n t)
10954       (goto-char orig)
10955       (gnus-summary-position-point))))
10956
10957 (defun gnus-summary-maybe-hide-threads ()
10958   "If requested, hide the threads that should be hidden."
10959   (when (and gnus-show-threads
10960              gnus-thread-hide-subtree)
10961     (gnus-summary-hide-all-threads
10962      (if (or (consp gnus-thread-hide-subtree)
10963              (functionp gnus-thread-hide-subtree))
10964          (gnus-make-predicate gnus-thread-hide-subtree)
10965        nil))))
10966
10967 ;;; Hiding predicates.
10968
10969 (defun gnus-article-unread-p (header)
10970   (memq (mail-header-number header) gnus-newsgroup-unreads))
10971
10972 (defun gnus-article-unseen-p (header)
10973   (memq (mail-header-number header) gnus-newsgroup-unseen))
10974
10975 (defun gnus-map-articles (predicate articles)
10976   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10977   (apply 'gnus-or (mapcar predicate
10978                           (mapcar (lambda (number)
10979                                     (gnus-summary-article-header number))
10980                                   articles))))
10981
10982 (defun gnus-summary-hide-all-threads (&optional predicate)
10983   "Hide all thread subtrees.
10984 If PREDICATE is supplied, threads that satisfy this predicate
10985 will not be hidden."
10986   (interactive)
10987   (save-excursion
10988     (goto-char (point-min))
10989     (let ((end nil))
10990       (while (not end)
10991         (when (or (not predicate)
10992                   (gnus-map-articles
10993                    predicate (gnus-summary-article-children)))
10994             (gnus-summary-hide-thread))
10995         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10996   (gnus-summary-position-point))
10997
10998 (defun gnus-summary-hide-thread ()
10999   "Hide thread subtrees.
11000 If PREDICATE is supplied, threads that satisfy this predicate
11001 will not be hidden.
11002 Returns nil if no threads were there to be hidden."
11003   (interactive)
11004   (let ((buffer-read-only nil)
11005         (start (point))
11006         (article (gnus-summary-article-number)))
11007     (goto-char start)
11008     ;; Go forward until either the buffer ends or the subthread
11009     ;; ends.
11010     (when (and (not (eobp))
11011                (or (zerop (gnus-summary-next-thread 1 t))
11012                    (goto-char (point-max))))
11013       (prog1
11014           (if (and (> (point) start)
11015                    (search-backward "\n" start t))
11016               (progn
11017                 (subst-char-in-region start (point) ?\n ?\^M)
11018                 (gnus-summary-goto-subject article))
11019             (goto-char start)
11020             nil)))))
11021
11022 (defun gnus-summary-go-to-next-thread (&optional previous)
11023   "Go to the same level (or less) next thread.
11024 If PREVIOUS is non-nil, go to previous thread instead.
11025 Return the article number moved to, or nil if moving was impossible."
11026   (let ((level (gnus-summary-thread-level))
11027         (way (if previous -1 1))
11028         (beg (point)))
11029     (forward-line way)
11030     (while (and (not (eobp))
11031                 (< level (gnus-summary-thread-level)))
11032       (forward-line way))
11033     (if (eobp)
11034         (progn
11035           (goto-char beg)
11036           nil)
11037       (setq beg (point))
11038       (prog1
11039           (gnus-summary-article-number)
11040         (goto-char beg)))))
11041
11042 (defun gnus-summary-next-thread (n &optional silent)
11043   "Go to the same level next N'th thread.
11044 If N is negative, search backward instead.
11045 Returns the difference between N and the number of skips actually
11046 done.
11047
11048 If SILENT, don't output messages."
11049   (interactive "p")
11050   (let ((backward (< n 0))
11051         (n (abs n)))
11052     (while (and (> n 0)
11053                 (gnus-summary-go-to-next-thread backward))
11054       (decf n))
11055     (unless silent
11056       (gnus-summary-position-point))
11057     (when (and (not silent) (/= 0 n))
11058       (gnus-message 7 "No more threads"))
11059     n))
11060
11061 (defun gnus-summary-prev-thread (n)
11062   "Go to the same level previous N'th thread.
11063 Returns the difference between N and the number of skips actually
11064 done."
11065   (interactive "p")
11066   (gnus-summary-next-thread (- n)))
11067
11068 (defun gnus-summary-go-down-thread ()
11069   "Go down one level in the current thread."
11070   (let ((children (gnus-summary-article-children)))
11071     (when children
11072       (gnus-summary-goto-subject (car children)))))
11073
11074 (defun gnus-summary-go-up-thread ()
11075   "Go up one level in the current thread."
11076   (let ((parent (gnus-summary-article-parent)))
11077     (when parent
11078       (gnus-summary-goto-subject parent))))
11079
11080 (defun gnus-summary-down-thread (n)
11081   "Go down thread N steps.
11082 If N is negative, go up instead.
11083 Returns the difference between N and how many steps down that were
11084 taken."
11085   (interactive "p")
11086   (let ((up (< n 0))
11087         (n (abs n)))
11088     (while (and (> n 0)
11089                 (if up (gnus-summary-go-up-thread)
11090                   (gnus-summary-go-down-thread)))
11091       (setq n (1- n)))
11092     (gnus-summary-position-point)
11093     (when (/= 0 n)
11094       (gnus-message 7 "Can't go further"))
11095     n))
11096
11097 (defun gnus-summary-up-thread (n)
11098   "Go up thread N steps.
11099 If N is negative, go down instead.
11100 Returns the difference between N and how many steps down that were
11101 taken."
11102   (interactive "p")
11103   (gnus-summary-down-thread (- n)))
11104
11105 (defun gnus-summary-top-thread ()
11106   "Go to the top of the thread."
11107   (interactive)
11108   (while (gnus-summary-go-up-thread))
11109   (gnus-summary-article-number))
11110
11111 (defun gnus-summary-kill-thread (&optional unmark)
11112   "Mark articles under current thread as read.
11113 If the prefix argument is positive, remove any kinds of marks.
11114 If the prefix argument is negative, tick articles instead."
11115   (interactive "P")
11116   (when unmark
11117     (setq unmark (prefix-numeric-value unmark)))
11118   (let ((articles (gnus-summary-articles-in-thread)))
11119     (save-excursion
11120       ;; Expand the thread.
11121       (gnus-summary-show-thread)
11122       ;; Mark all the articles.
11123       (while articles
11124         (gnus-summary-goto-subject (car articles))
11125         (cond ((null unmark)
11126                (gnus-summary-mark-article-as-read gnus-killed-mark))
11127               ((> unmark 0)
11128                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11129               (t
11130                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11131         (setq articles (cdr articles))))
11132     ;; Hide killed subtrees.
11133     (and (null unmark)
11134          gnus-thread-hide-killed
11135          (gnus-summary-hide-thread))
11136     ;; If marked as read, go to next unread subject.
11137     (when (null unmark)
11138       ;; Go to next unread subject.
11139       (gnus-summary-next-subject 1 t)))
11140   (gnus-set-mode-line 'summary))
11141
11142 ;; Summary sorting commands
11143
11144 (defun gnus-summary-sort-by-number (&optional reverse)
11145   "Sort the summary buffer by article number.
11146 Argument REVERSE means reverse order."
11147   (interactive "P")
11148   (gnus-summary-sort 'number reverse))
11149
11150 (defun gnus-summary-sort-by-random (&optional reverse)
11151   "Randomize the order in the summary buffer.
11152 Argument REVERSE means to randomize in reverse order."
11153   (interactive "P")
11154   (gnus-summary-sort 'random reverse))
11155
11156 (defun gnus-summary-sort-by-author (&optional reverse)
11157   "Sort the summary buffer by author name alphabetically.
11158 If `case-fold-search' is non-nil, case of letters is ignored.
11159 Argument REVERSE means reverse order."
11160   (interactive "P")
11161   (gnus-summary-sort 'author reverse))
11162
11163 (defun gnus-summary-sort-by-recipient (&optional reverse)
11164   "Sort the summary buffer by recipient name alphabetically.
11165 If `case-fold-search' is non-nil, case of letters is ignored.
11166 Argument REVERSE means reverse order."
11167   (interactive "P")
11168   (gnus-summary-sort 'recipient reverse))
11169
11170 (defun gnus-summary-sort-by-subject (&optional reverse)
11171   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11172 If `case-fold-search' is non-nil, case of letters is ignored.
11173 Argument REVERSE means reverse order."
11174   (interactive "P")
11175   (gnus-summary-sort 'subject reverse))
11176
11177 (defun gnus-summary-sort-by-date (&optional reverse)
11178   "Sort the summary buffer by date.
11179 Argument REVERSE means reverse order."
11180   (interactive "P")
11181   (gnus-summary-sort 'date reverse))
11182
11183 (defun gnus-summary-sort-by-score (&optional reverse)
11184   "Sort the summary buffer by score.
11185 Argument REVERSE means reverse order."
11186   (interactive "P")
11187   (gnus-summary-sort 'score reverse))
11188
11189 (defun gnus-summary-sort-by-lines (&optional reverse)
11190   "Sort the summary buffer by the number of lines.
11191 Argument REVERSE means reverse order."
11192   (interactive "P")
11193   (gnus-summary-sort 'lines reverse))
11194
11195 (defun gnus-summary-sort-by-chars (&optional reverse)
11196   "Sort the summary buffer by article length.
11197 Argument REVERSE means reverse order."
11198   (interactive "P")
11199   (gnus-summary-sort 'chars reverse))
11200
11201 (defun gnus-summary-sort-by-original (&optional reverse)
11202   "Sort the summary buffer using the default sorting method.
11203 Argument REVERSE means reverse order."
11204   (interactive "P")
11205   (let* ((buffer-read-only)
11206          (gnus-summary-prepare-hook nil))
11207     ;; We do the sorting by regenerating the threads.
11208     (gnus-summary-prepare)
11209     ;; Hide subthreads if needed.
11210     (gnus-summary-maybe-hide-threads)))
11211
11212 (defun gnus-summary-sort (predicate reverse)
11213   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11214   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11215          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11216          (gnus-thread-sort-functions
11217           (if (not reverse)
11218               thread
11219             `(lambda (t1 t2)
11220                (,thread t2 t1))))
11221          (gnus-sort-gathered-threads-function
11222           gnus-thread-sort-functions)
11223          (gnus-article-sort-functions
11224           (if (not reverse)
11225               article
11226             `(lambda (t1 t2)
11227                (,article t2 t1))))
11228          (buffer-read-only)
11229          (gnus-summary-prepare-hook nil))
11230     ;; We do the sorting by regenerating the threads.
11231     (gnus-summary-prepare)
11232     ;; Hide subthreads if needed.
11233     (gnus-summary-maybe-hide-threads)))
11234
11235 ;; Summary saving commands.
11236
11237 (defun gnus-summary-save-article (&optional n not-saved)
11238   "Save the current article using the default saver function.
11239 If N is a positive number, save the N next articles.
11240 If N is a negative number, save the N previous articles.
11241 If N is nil and any articles have been marked with the process mark,
11242 save those articles instead.
11243 The variable `gnus-default-article-saver' specifies the saver function.
11244
11245 If the optional second argument NOT-SAVED is non-nil, articles saved
11246 will not be marked as saved."
11247   (interactive "P")
11248   (require 'gnus-art)
11249   (let* ((articles (gnus-summary-work-articles n))
11250          (save-buffer (save-excursion
11251                         (nnheader-set-temp-buffer " *Gnus Save*")))
11252          (num (length articles))
11253          ;; Whether to save decoded articles or raw articles.
11254          (decode (when gnus-article-save-coding-system
11255                    (get gnus-default-article-saver :decode)))
11256          ;; When saving many articles in a single file, use the other
11257          ;; function to save articles other than the first one.
11258          (saver2 (get gnus-default-article-saver :function))
11259          (gnus-prompt-before-saving (and saver2 t))
11260          (gnus-default-article-saver gnus-default-article-saver)
11261          header file)
11262     (dolist (article articles)
11263       (setq header (gnus-summary-article-header article))
11264       (if (not (vectorp header))
11265           ;; This is a pseudo-article.
11266           (if (assq 'name header)
11267               (gnus-copy-file (cdr (assq 'name header)))
11268             (gnus-message 1 "Article %d is unsaveable" article))
11269         ;; This is a real article.
11270         (save-window-excursion
11271           (let ((gnus-display-mime-function (when decode
11272                                               gnus-display-mime-function))
11273                 (gnus-article-prepare-hook (when decode
11274                                              gnus-article-prepare-hook)))
11275             (gnus-summary-select-article t nil nil article)
11276             (gnus-summary-goto-subject article)))
11277         (save-excursion
11278           (set-buffer save-buffer)
11279           (erase-buffer)
11280           (insert-buffer-substring (if decode
11281                                        gnus-article-buffer
11282                                      gnus-original-article-buffer)))
11283         (setq file (gnus-article-save save-buffer file num))
11284         (gnus-summary-remove-process-mark article)
11285         (unless not-saved
11286           (gnus-summary-set-saved-mark article)))
11287       (when saver2
11288         (setq gnus-default-article-saver saver2
11289               saver2 nil)))
11290     (gnus-kill-buffer save-buffer)
11291     (gnus-summary-position-point)
11292     (gnus-set-mode-line 'summary)
11293     n))
11294
11295 (defun gnus-summary-pipe-output (&optional arg headers)
11296   "Pipe the current article to a subprocess.
11297 If N is a positive number, pipe the N next articles.
11298 If N is a negative number, pipe the N previous articles.
11299 If N is nil and any articles have been marked with the process mark,
11300 pipe those articles instead.
11301 If HEADERS (the symbolic prefix), include the headers, too."
11302   (interactive (gnus-interactive "P\ny"))
11303   (require 'gnus-art)
11304   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11305         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11306     (gnus-summary-save-article arg t))
11307   (let ((buffer (get-buffer "*Shell Command Output*")))
11308     (when (and buffer
11309                (not (zerop (buffer-size buffer))))
11310       (gnus-configure-windows 'pipe))))
11311
11312 (defun gnus-summary-save-article-mail (&optional arg)
11313   "Append the current article to a Unix mail box file.
11314 If N is a positive number, save the N next articles.
11315 If N is a negative number, save the N previous articles.
11316 If N is nil and any articles have been marked with the process mark,
11317 save those articles instead."
11318   (interactive "P")
11319   (require 'gnus-art)
11320   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11321     (gnus-summary-save-article arg)))
11322
11323 (defun gnus-summary-save-article-rmail (&optional arg)
11324   "Append the current article to an rmail 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-rmail))
11332     (gnus-summary-save-article arg)))
11333
11334 (defun gnus-summary-save-article-file (&optional arg)
11335   "Append the current article to a 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-file))
11343     (gnus-summary-save-article arg)))
11344
11345 (defun gnus-summary-write-article-file (&optional arg)
11346   "Write the current article to a file, deleting the previous 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-write-to-file))
11354     (gnus-summary-save-article arg)))
11355
11356 (defun gnus-summary-save-article-body-file (&optional arg)
11357   "Append the current article body to a 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-save-body-in-file))
11365     (gnus-summary-save-article arg)))
11366
11367 (defun gnus-summary-write-article-body-file (&optional arg)
11368   "Write the current article body to a file, deleting the previous 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-write-body-to-file))
11376     (gnus-summary-save-article arg)))
11377
11378 (defun gnus-summary-muttprint (&optional arg)
11379   "Print the current article using Muttprint.
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-pipe-to-muttprint))
11387     (gnus-summary-save-article arg t)))
11388
11389 (defun gnus-summary-pipe-message (program)
11390   "Pipe the current article through PROGRAM."
11391   (interactive "sProgram: ")
11392   (gnus-summary-select-article)
11393   (let ((mail-header-separator ""))
11394     (gnus-eval-in-buffer-window gnus-article-buffer
11395       (save-restriction
11396         (widen)
11397         (let ((start (window-start))
11398               buffer-read-only)
11399           (message-pipe-buffer-body program)
11400           (set-window-start (get-buffer-window (current-buffer)) start))))))
11401
11402 (defun gnus-get-split-value (methods)
11403   "Return a value based on the split METHODS."
11404   (let (split-name method result match)
11405     (when methods
11406       (save-excursion
11407         (set-buffer gnus-original-article-buffer)
11408         (save-restriction
11409           (nnheader-narrow-to-headers)
11410           (while (and methods (not split-name))
11411             (goto-char (point-min))
11412             (setq method (pop methods))
11413             (setq match (car method))
11414             (when (cond
11415                    ((stringp match)
11416                     ;; Regular expression.
11417                     (ignore-errors
11418                       (re-search-forward match nil t)))
11419                    ((functionp match)
11420                     ;; Function.
11421                     (save-restriction
11422                       (widen)
11423                       (setq result (funcall match gnus-newsgroup-name))))
11424                    ((consp match)
11425                     ;; Form.
11426                     (save-restriction
11427                       (widen)
11428                       (setq result (eval match)))))
11429               (setq split-name (cdr method))
11430               (cond ((stringp result)
11431                      (push (expand-file-name
11432                             result gnus-article-save-directory)
11433                            split-name))
11434                     ((consp result)
11435                      (setq split-name (append result split-name)))))))))
11436     (nreverse split-name)))
11437
11438 (defun gnus-valid-move-group-p (group)
11439   (and (boundp group)
11440        (symbol-name group)
11441        (symbol-value group)
11442        (gnus-get-function (gnus-find-method-for-group
11443                            (symbol-name group)) 'request-accept-article t)))
11444
11445 (defun gnus-read-move-group-name (prompt default articles prefix)
11446   "Read a group name."
11447   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11448          (minibuffer-confirm-incomplete nil) ; XEmacs
11449          (prom
11450           (format "%s %s to"
11451                   prompt
11452                   (if (> (length articles) 1)
11453                       (format "these %d articles" (length articles))
11454                     "this article")))
11455          (to-newsgroup
11456           (cond
11457            ((null split-name)
11458             (gnus-completing-read-with-default
11459              default prom
11460              gnus-active-hashtb
11461              'gnus-valid-move-group-p
11462              nil prefix
11463              'gnus-group-history))
11464            ((= 1 (length split-name))
11465             (gnus-completing-read-with-default
11466              (car split-name) prom
11467              gnus-active-hashtb
11468              'gnus-valid-move-group-p
11469              nil nil
11470              'gnus-group-history))
11471            (t
11472             (gnus-completing-read-with-default
11473              nil prom
11474              (mapcar 'list (nreverse split-name))
11475              nil nil nil
11476              'gnus-group-history))))
11477          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11478     (when to-newsgroup
11479       (if (or (string= to-newsgroup "")
11480               (string= to-newsgroup prefix))
11481           (setq to-newsgroup default))
11482       (unless to-newsgroup
11483         (error "No group name entered"))
11484       (or (gnus-active to-newsgroup)
11485           (gnus-activate-group to-newsgroup nil nil to-method)
11486           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11487                                      to-newsgroup))
11488               (or (and (gnus-request-create-group to-newsgroup to-method)
11489                        (gnus-activate-group
11490                         to-newsgroup nil nil to-method)
11491                        (gnus-subscribe-group to-newsgroup))
11492                   (error "Couldn't create group %s" to-newsgroup)))
11493           (error "No such group: %s" to-newsgroup)))
11494     to-newsgroup))
11495
11496 (defvar gnus-summary-save-parts-counter)
11497
11498 (defun gnus-summary-save-parts (type dir n &optional reverse)
11499   "Save parts matching TYPE to DIR.
11500 If REVERSE, save parts that do not match TYPE."
11501   (interactive
11502    (list (read-string "Save parts of type: "
11503                       (or (car gnus-summary-save-parts-type-history)
11504                           gnus-summary-save-parts-default-mime)
11505                       'gnus-summary-save-parts-type-history)
11506          (setq gnus-summary-save-parts-last-directory
11507                (read-file-name "Save to directory: "
11508                                gnus-summary-save-parts-last-directory
11509                                nil t))
11510          current-prefix-arg))
11511   (gnus-summary-iterate n
11512     (let ((gnus-display-mime-function nil)
11513           (gnus-inhibit-treatment t))
11514       (gnus-summary-select-article))
11515     (save-excursion
11516       (set-buffer gnus-article-buffer)
11517       (let ((handles (or gnus-article-mime-handles
11518                          (mm-dissect-buffer nil gnus-article-loose-mime)
11519                          (and gnus-article-emulate-mime
11520                               (mm-uu-dissect))))
11521             (gnus-summary-save-parts-counter 1))
11522         (when handles
11523           (gnus-summary-save-parts-1 type dir handles reverse)
11524           (unless gnus-article-mime-handles ;; Don't destroy this case.
11525             (mm-destroy-parts handles)))))))
11526
11527 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11528   (if (stringp (car handle))
11529       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11530               (cdr handle))
11531     (when (if reverse
11532               (not (string-match type (mm-handle-media-type handle)))
11533             (string-match type (mm-handle-media-type handle)))
11534       (let ((file (expand-file-name
11535                    (gnus-map-function
11536                     mm-file-name-rewrite-functions
11537                     (file-name-nondirectory
11538                      (or
11539                       (mail-content-type-get
11540                        (mm-handle-disposition handle) 'filename)
11541                       (mail-content-type-get
11542                        (mm-handle-type handle) 'name)
11543                       (format "%s.%d.%d" gnus-newsgroup-name
11544                               (cdr gnus-article-current)
11545                               gnus-summary-save-parts-counter))))
11546                    dir)))
11547         (incf gnus-summary-save-parts-counter)
11548         (unless (file-exists-p file)
11549           (mm-save-part-to-file handle file))))))
11550
11551 ;; Summary extract commands
11552
11553 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11554   (let ((buffer-read-only nil)
11555         (article (gnus-summary-article-number))
11556         after-article b e)
11557     (unless (gnus-summary-goto-subject article)
11558       (error "No such article: %d" article))
11559     (gnus-summary-position-point)
11560     ;; If all commands are to be bunched up on one line, we collect
11561     ;; them here.
11562     (unless gnus-view-pseudos-separately
11563       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11564             files action)
11565         (while ps
11566           (setq action (cdr (assq 'action (car ps))))
11567           (setq files (list (cdr (assq 'name (car ps)))))
11568           (while (and ps (cdr ps)
11569                       (string= (or action "1")
11570                                (or (cdr (assq 'action (cadr ps))) "2")))
11571             (push (cdr (assq 'name (cadr ps))) files)
11572             (setcdr ps (cddr ps)))
11573           (when files
11574             (when (not (string-match "%s" action))
11575               (push " " files))
11576             (push " " files)
11577             (when (assq 'execute (car ps))
11578               (setcdr (assq 'execute (car ps))
11579                       (funcall (if (string-match "%s" action)
11580                                    'format 'concat)
11581                                action
11582                                (mapconcat
11583                                 (lambda (f)
11584                                   (if (equal f " ")
11585                                       f
11586                                     (shell-quote-argument f)))
11587                                 files " ")))))
11588           (setq ps (cdr ps)))))
11589     (if (and gnus-view-pseudos (not not-view))
11590         (while pslist
11591           (when (assq 'execute (car pslist))
11592             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11593                                   (eq gnus-view-pseudos 'not-confirm)))
11594           (setq pslist (cdr pslist)))
11595       (save-excursion
11596         (while pslist
11597           (setq after-article (or (cdr (assq 'article (car pslist)))
11598                                   (gnus-summary-article-number)))
11599           (gnus-summary-goto-subject after-article)
11600           (forward-line 1)
11601           (setq b (point))
11602           (insert "    " (file-name-nondirectory
11603                           (cdr (assq 'name (car pslist))))
11604                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11605           (setq e (point))
11606           (forward-line -1)             ; back to `b'
11607           (gnus-add-text-properties
11608            b (1- e) (list 'gnus-number gnus-reffed-article-number
11609                           gnus-mouse-face-prop gnus-mouse-face))
11610           (gnus-data-enter
11611            after-article gnus-reffed-article-number
11612            gnus-unread-mark b (car pslist) 0 (- e b))
11613           (setq gnus-newsgroup-unreads
11614                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11615                                          gnus-reffed-article-number))
11616           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11617           (setq pslist (cdr pslist)))))))
11618
11619 (defun gnus-pseudos< (p1 p2)
11620   (let ((c1 (cdr (assq 'action p1)))
11621         (c2 (cdr (assq 'action p2))))
11622     (and c1 c2 (string< c1 c2))))
11623
11624 (defun gnus-request-pseudo-article (props)
11625   (cond ((assq 'execute props)
11626          (gnus-execute-command (cdr (assq 'execute props)))))
11627   (let ((gnus-current-article (gnus-summary-article-number)))
11628     (gnus-run-hooks 'gnus-mark-article-hook)))
11629
11630 (defun gnus-execute-command (command &optional automatic)
11631   (save-excursion
11632     (gnus-article-setup-buffer)
11633     (set-buffer gnus-article-buffer)
11634     (setq buffer-read-only nil)
11635     (let ((command (if automatic command
11636                      (read-string "Command: " (cons command 0)))))
11637       (erase-buffer)
11638       (insert "$ " command "\n\n")
11639       (if gnus-view-pseudo-asynchronously
11640           (start-process "gnus-execute" (current-buffer) shell-file-name
11641                          shell-command-switch command)
11642         (call-process shell-file-name nil t nil
11643                       shell-command-switch command)))))
11644
11645 ;; Summary kill commands.
11646
11647 (defun gnus-summary-edit-global-kill (article)
11648   "Edit the \"global\" kill file."
11649   (interactive (list (gnus-summary-article-number)))
11650   (gnus-group-edit-global-kill article))
11651
11652 (defun gnus-summary-edit-local-kill ()
11653   "Edit a local kill file applied to the current newsgroup."
11654   (interactive)
11655   (setq gnus-current-headers (gnus-summary-article-header))
11656   (gnus-group-edit-local-kill
11657    (gnus-summary-article-number) gnus-newsgroup-name))
11658
11659 ;;; Header reading.
11660
11661 (defun gnus-read-header (id &optional header)
11662   "Read the headers of article ID and enter them into the Gnus system."
11663   (let ((group gnus-newsgroup-name)
11664         (gnus-override-method
11665          (or
11666           gnus-override-method
11667           (and (gnus-news-group-p gnus-newsgroup-name)
11668                (car (gnus-refer-article-methods)))))
11669         where)
11670     ;; First we check to see whether the header in question is already
11671     ;; fetched.
11672     (if (stringp id)
11673         ;; This is a Message-ID.
11674         (setq header (or header (gnus-id-to-header id)))
11675       ;; This is an article number.
11676       (setq header (or header (gnus-summary-article-header id))))
11677     (if (and header
11678              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11679         ;; We have found the header.
11680         header
11681       ;; We have to really fetch the header to this article.
11682       (save-excursion
11683         (set-buffer nntp-server-buffer)
11684         (when (setq where (gnus-request-head id group))
11685           (nnheader-fold-continuation-lines)
11686           (goto-char (point-max))
11687           (insert ".\n")
11688           (goto-char (point-min))
11689           (insert "211 ")
11690           (princ (cond
11691                   ((numberp id) id)
11692                   ((cdr where) (cdr where))
11693                   (header (mail-header-number header))
11694                   (t gnus-reffed-article-number))
11695                  (current-buffer))
11696           (insert " Article retrieved.\n"))
11697         (if (or (not where)
11698                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11699             ()                          ; Malformed head.
11700           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11701             (when (and (stringp id)
11702                        (or
11703                         (not (string= (gnus-group-real-name group)
11704                                       (car where)))
11705                         (not (gnus-server-equal gnus-override-method
11706                                                 (gnus-group-method group)))))
11707               ;; If we fetched by Message-ID and the article came from
11708               ;; a different group (or server), we fudge some bogus
11709               ;; article numbers for this article.
11710               (mail-header-set-number header gnus-reffed-article-number))
11711             (save-excursion
11712               (set-buffer gnus-summary-buffer)
11713               (decf gnus-reffed-article-number)
11714               (gnus-remove-header (mail-header-number header))
11715               (push header gnus-newsgroup-headers)
11716               (setq gnus-current-headers header)
11717               (push (mail-header-number header) gnus-newsgroup-limit)))
11718           header)))))
11719
11720 (defun gnus-remove-header (number)
11721   "Remove header NUMBER from `gnus-newsgroup-headers'."
11722   (if (and gnus-newsgroup-headers
11723            (= number (mail-header-number (car gnus-newsgroup-headers))))
11724       (pop gnus-newsgroup-headers)
11725     (let ((headers gnus-newsgroup-headers))
11726       (while (and (cdr headers)
11727                   (not (= number (mail-header-number (cadr headers)))))
11728         (pop headers))
11729       (when (cdr headers)
11730         (setcdr headers (cddr headers))))))
11731
11732 ;;;
11733 ;;; summary highlights
11734 ;;;
11735
11736 (defun gnus-highlight-selected-summary ()
11737   "Highlight selected article in summary buffer."
11738   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11739   (when gnus-summary-selected-face
11740     (save-excursion
11741       (let* ((beg (point-at-bol))
11742              (end (point-at-eol))
11743              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11744              (from (if (get-text-property beg gnus-mouse-face-prop)
11745                        beg
11746                      (or (next-single-property-change
11747                           beg gnus-mouse-face-prop nil end)
11748                          beg)))
11749              (to
11750               (if (= from end)
11751                   (- from 2)
11752                 (or (next-single-property-change
11753                      from gnus-mouse-face-prop nil end)
11754                     end))))
11755         ;; If no mouse-face prop on line we will have to = from = end,
11756         ;; so we highlight the entire line instead.
11757         (when (= (+ to 2) from)
11758           (setq from beg)
11759           (setq to end))
11760         (if gnus-newsgroup-selected-overlay
11761             ;; Move old overlay.
11762             (gnus-move-overlay
11763              gnus-newsgroup-selected-overlay from to (current-buffer))
11764           ;; Create new overlay.
11765           (gnus-overlay-put
11766            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11767            'face gnus-summary-selected-face))))))
11768
11769 (defvar gnus-summary-highlight-line-cached nil)
11770 (defvar gnus-summary-highlight-line-trigger nil)
11771
11772 (defun gnus-summary-highlight-line-0 ()
11773   (if (and (eq gnus-summary-highlight-line-trigger
11774                gnus-summary-highlight)
11775            gnus-summary-highlight-line-cached)
11776       gnus-summary-highlight-line-cached
11777     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11778           gnus-summary-highlight-line-cached
11779           (let* ((cond (list 'cond))
11780                  (c cond)
11781                  (list gnus-summary-highlight))
11782             (while list
11783               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11784                               nil))
11785               (setq c (cdr c)
11786                     list (cdr list)))
11787             (gnus-byte-compile (list 'lambda nil cond))))))
11788
11789 (defun gnus-summary-highlight-line ()
11790   "Highlight current line according to `gnus-summary-highlight'."
11791   (let* ((beg (point-at-bol))
11792          (article (or (gnus-summary-article-number) gnus-current-article))
11793          (score (or (cdr (assq article
11794                                gnus-newsgroup-scored))
11795                     gnus-summary-default-score 0))
11796          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11797          (inhibit-read-only t)
11798          (default gnus-summary-default-score)
11799          (default-high gnus-summary-default-high-score)
11800          (default-low gnus-summary-default-low-score)
11801          (uncached (and gnus-summary-use-undownloaded-faces
11802                         (memq article gnus-newsgroup-undownloaded)
11803                         (not (memq article gnus-newsgroup-cached)))))
11804     (let ((face (funcall (gnus-summary-highlight-line-0))))
11805       (unless (eq face (get-text-property beg 'face))
11806         (gnus-put-text-property-excluding-characters-with-faces
11807          beg (point-at-eol) 'face
11808          (setq face (if (boundp face) (symbol-value face) face)))
11809         (when gnus-summary-highlight-line-function
11810           (funcall gnus-summary-highlight-line-function article face))))))
11811
11812 (defun gnus-update-read-articles (group unread &optional compute)
11813   "Update the list of read articles in GROUP.
11814 UNREAD is a sorted list."
11815   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11816         (info (gnus-get-info group))
11817         (prev 1)
11818         read)
11819     (if (or (not info) (not active))
11820         ;; There is no info on this group if it was, in fact,
11821         ;; killed.  Gnus stores no information on killed groups, so
11822         ;; there's nothing to be done.
11823         ;; One could store the information somewhere temporarily,
11824         ;; perhaps...  Hmmm...
11825         ()
11826       ;; Remove any negative articles numbers.
11827       (while (and unread (< (car unread) 0))
11828         (setq unread (cdr unread)))
11829       ;; Remove any expired article numbers
11830       (while (and unread (< (car unread) (car active)))
11831         (setq unread (cdr unread)))
11832       ;; Compute the ranges of read articles by looking at the list of
11833       ;; unread articles.
11834       (while unread
11835         (when (/= (car unread) prev)
11836           (push (if (= prev (1- (car unread))) prev
11837                   (cons prev (1- (car unread))))
11838                 read))
11839         (setq prev (1+ (car unread)))
11840         (setq unread (cdr unread)))
11841       (when (<= prev (cdr active))
11842         (push (cons prev (cdr active)) read))
11843       (setq read (if (> (length read) 1) (nreverse read) read))
11844       (if compute
11845           read
11846         (save-excursion
11847           (let (setmarkundo)
11848             ;; Propagate the read marks to the backend.
11849             (when (gnus-check-backend-function 'request-set-mark group)
11850               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11851                     (add (gnus-remove-from-range read (gnus-info-read info))))
11852                 (when (or add del)
11853                   (unless (gnus-check-group group)
11854                     (error "Can't open server for %s" group))
11855                   (gnus-request-set-mark
11856                    group (delq nil (list (if add (list add 'add '(read)))
11857                                          (if del (list del 'del '(read))))))
11858                   (setq setmarkundo
11859                         `(gnus-request-set-mark
11860                           ,group
11861                           ',(delq nil (list
11862                                        (if del (list del 'add '(read)))
11863                                        (if add (list add 'del '(read))))))))))
11864             (set-buffer gnus-group-buffer)
11865             (gnus-undo-register
11866               `(progn
11867                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11868                  (gnus-info-set-read ',info ',(gnus-info-read info))
11869                  (gnus-get-unread-articles-in-group ',info
11870                                                     (gnus-active ,group))
11871                  (gnus-group-update-group ,group t)
11872                  ,setmarkundo))))
11873         ;; Enter this list into the group info.
11874         (gnus-info-set-read info read)
11875         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11876         (gnus-get-unread-articles-in-group info (gnus-active group))
11877         t))))
11878
11879 (defun gnus-offer-save-summaries ()
11880   "Offer to save all active summary buffers."
11881   (let (buffers)
11882     ;; Go through all buffers and find all summaries.
11883     (dolist (buffer (buffer-list))
11884       (when (and (setq buffer (buffer-name buffer))
11885                  (string-match "Summary" buffer)
11886                  (with-current-buffer buffer
11887                    ;; We check that this is, indeed, a summary buffer.
11888                    (and (eq major-mode 'gnus-summary-mode)
11889                         ;; Also make sure this isn't bogus.
11890                         gnus-newsgroup-prepared
11891                         ;; Also make sure that this isn't a
11892                         ;; dead summary buffer.
11893                         (not gnus-dead-summary-mode))))
11894         (push buffer buffers)))
11895     ;; Go through all these summary buffers and offer to save them.
11896     (when buffers
11897       (save-excursion
11898         (map-y-or-n-p
11899          "Update summary buffer %s? "
11900          (lambda (buf)
11901            (switch-to-buffer buf)
11902            (gnus-summary-exit))
11903          buffers)))))
11904
11905 (defun gnus-summary-setup-default-charset ()
11906   "Setup newsgroup default charset."
11907   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11908       (setq gnus-newsgroup-charset nil)
11909     (let* ((ignored-charsets
11910             (or gnus-newsgroup-ephemeral-ignored-charsets
11911                 (append
11912                  (and gnus-newsgroup-name
11913                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11914                  gnus-newsgroup-ignored-charsets))))
11915       (setq gnus-newsgroup-charset
11916             (or gnus-newsgroup-ephemeral-charset
11917                 (and gnus-newsgroup-name
11918                      (gnus-parameter-charset gnus-newsgroup-name))
11919                 gnus-default-charset))
11920       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11921            ignored-charsets))))
11922
11923 ;;;
11924 ;;; Mime Commands
11925 ;;;
11926
11927 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11928   "Display the current article buffer fully MIME-buttonized.
11929 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11930 treated as multipart/mixed."
11931   (interactive "P")
11932   (require 'gnus-art)
11933   (let ((gnus-unbuttonized-mime-types nil)
11934         (gnus-mime-display-multipart-as-mixed show-all-parts))
11935     (gnus-summary-show-article)))
11936
11937 (defun gnus-summary-repair-multipart (article)
11938   "Add a Content-Type header to a multipart article without one."
11939   (interactive (list (gnus-summary-article-number)))
11940   (gnus-with-article article
11941     (message-narrow-to-head)
11942     (message-remove-header "Mime-Version")
11943     (goto-char (point-max))
11944     (insert "Mime-Version: 1.0\n")
11945     (widen)
11946     (when (search-forward "\n--" nil t)
11947       (let ((separator (buffer-substring (point) (point-at-eol))))
11948         (message-narrow-to-head)
11949         (message-remove-header "Content-Type")
11950         (goto-char (point-max))
11951         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11952                         separator))
11953         (widen))))
11954   (let (gnus-mark-article-hook)
11955     (gnus-summary-select-article t t nil article)))
11956
11957 (defun gnus-summary-toggle-display-buttonized ()
11958   "Toggle the buttonizing of the article buffer."
11959   (interactive)
11960   (require 'gnus-art)
11961   (if (setq gnus-inhibit-mime-unbuttonizing
11962             (not gnus-inhibit-mime-unbuttonizing))
11963       (let ((gnus-unbuttonized-mime-types nil))
11964         (gnus-summary-show-article))
11965     (gnus-summary-show-article)))
11966
11967 ;;;
11968 ;;; Generic summary marking commands
11969 ;;;
11970
11971 (defvar gnus-summary-marking-alist
11972   '((read gnus-del-mark "d")
11973     (unread gnus-unread-mark "u")
11974     (ticked gnus-ticked-mark "!")
11975     (dormant gnus-dormant-mark "?")
11976     (expirable gnus-expirable-mark "e"))
11977   "An alist of names/marks/keystrokes.")
11978
11979 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11980 (defvar gnus-summary-mark-map)
11981
11982 (defun gnus-summary-make-all-marking-commands ()
11983   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11984   (dolist (elem gnus-summary-marking-alist)
11985     (apply 'gnus-summary-make-marking-command elem)))
11986
11987 (defun gnus-summary-make-marking-command (name mark keystroke)
11988   (let ((map (make-sparse-keymap)))
11989     (define-key gnus-summary-generic-mark-map keystroke map)
11990     (dolist (lway `((next "next" next nil "n")
11991                     (next-unread "next unread" next t "N")
11992                     (prev "previous" prev nil "p")
11993                     (prev-unread "previous unread" prev t "P")
11994                     (nomove "" nil nil ,keystroke)))
11995       (let ((func (gnus-summary-make-marking-command-1
11996                    mark (car lway) lway name)))
11997         (setq func (eval func))
11998         (define-key map (nth 4 lway) func)))))
11999
12000 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12001   `(defun ,(intern
12002             (format "gnus-summary-put-mark-as-%s%s"
12003                     name (if (eq way 'nomove)
12004                              ""
12005                            (concat "-" (symbol-name way)))))
12006      (n)
12007      ,(format
12008        "Mark the current article as %s%s.
12009 If N, the prefix, then repeat N times.
12010 If N is negative, move in reverse order.
12011 The difference between N and the actual number of articles marked is
12012 returned."
12013        name (cadr lway))
12014      (interactive "p")
12015      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12016
12017 (defun gnus-summary-generic-mark (n mark move unread)
12018   "Mark N articles with MARK."
12019   (unless (eq major-mode 'gnus-summary-mode)
12020     (error "This command can only be used in the summary buffer"))
12021   (gnus-summary-show-thread)
12022   (let ((nummove
12023          (cond
12024           ((eq move 'next) 1)
12025           ((eq move 'prev) -1)
12026           (t 0))))
12027     (if (zerop nummove)
12028         (setq n 1)
12029       (when (< n 0)
12030         (setq n (abs n)
12031               nummove (* -1 nummove))))
12032     (while (and (> n 0)
12033                 (gnus-summary-mark-article nil mark)
12034                 (zerop (gnus-summary-next-subject nummove unread t)))
12035       (setq n (1- n)))
12036     (when (/= 0 n)
12037       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12038     (gnus-summary-recenter)
12039     (gnus-summary-position-point)
12040     (gnus-set-mode-line 'summary)
12041     n))
12042
12043 (defun gnus-summary-insert-articles (articles)
12044   (when (setq articles
12045               (gnus-sorted-difference articles
12046                                       (mapcar (lambda (h)
12047                                                 (mail-header-number h))
12048                                               gnus-newsgroup-headers)))
12049     (setq gnus-newsgroup-headers
12050           (gnus-merge 'list
12051                       gnus-newsgroup-headers
12052                       (gnus-fetch-headers articles)
12053                       'gnus-article-sort-by-number))
12054     ;; Suppress duplicates?
12055     (when gnus-suppress-duplicates
12056       (gnus-dup-suppress-articles))
12057
12058     ;; We might want to build some more threads first.
12059     (when (and gnus-fetch-old-headers
12060                (eq gnus-headers-retrieved-by 'nov))
12061       (if (eq gnus-fetch-old-headers 'invisible)
12062           (gnus-build-all-threads)
12063         (gnus-build-old-threads)))
12064     ;; Let the Gnus agent mark articles as read.
12065     (when gnus-agent
12066       (gnus-agent-get-undownloaded-list))
12067     ;; Remove list identifiers from subject
12068     (when gnus-list-identifiers
12069       (gnus-summary-remove-list-identifiers))
12070     ;; First and last article in this newsgroup.
12071     (when gnus-newsgroup-headers
12072       (setq gnus-newsgroup-begin
12073             (mail-header-number (car gnus-newsgroup-headers))
12074             gnus-newsgroup-end
12075             (mail-header-number
12076              (gnus-last-element gnus-newsgroup-headers))))
12077     (when gnus-use-scoring
12078       (gnus-possibly-score-headers))))
12079
12080 (defun gnus-summary-insert-old-articles (&optional all)
12081   "Insert all old articles in this group.
12082 If ALL is non-nil, already read articles become readable.
12083 If ALL is a number, fetch this number of articles."
12084   (interactive "P")
12085   (prog1
12086       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12087             older len)
12088         (setq older
12089               ;; Some nntp servers lie about their active range.  When
12090               ;; this happens, the active range can be in the millions.
12091               ;; Use a compressed range to avoid creating a huge list.
12092               (gnus-range-difference (list gnus-newsgroup-active) old))
12093         (setq len (gnus-range-length older))
12094         (cond
12095          ((null older) nil)
12096          ((numberp all)
12097           (if (< all len)
12098               (let ((older-range (nreverse older)))
12099                 (setq older nil)
12100
12101                 (while (> all 0)
12102                   (let* ((r (pop older-range))
12103                          (min (if (numberp r) r (car r)))
12104                          (max (if (numberp r) r (cdr r))))
12105                     (while (and (<= min max)
12106                                 (> all 0))
12107                       (push max older)
12108                       (setq all (1- all)
12109                             max (1- max))))))
12110             (setq older (gnus-uncompress-range older))))
12111          (all
12112           (setq older (gnus-uncompress-range older)))
12113          (t
12114           (when (and (numberp gnus-large-newsgroup)
12115                    (> len gnus-large-newsgroup))
12116               (let* ((cursor-in-echo-area nil)
12117                      (initial (gnus-parameter-large-newsgroup-initial
12118                                gnus-newsgroup-name))
12119                      (input
12120                       (read-string
12121                        (format
12122                         "How many articles from %s (%s %d): "
12123                         (gnus-limit-string
12124                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12125                         (if initial "max" "default")
12126                         len)
12127                        (if initial
12128                            (cons (number-to-string initial)
12129                                  0)))))
12130                 (unless (string-match "^[ \t]*$" input)
12131                   (setq all (string-to-number input))
12132                   (if (< all len)
12133                       (let ((older-range (nreverse older)))
12134                         (setq older nil)
12135
12136                         (while (> all 0)
12137                           (let* ((r (pop older-range))
12138                                  (min (if (numberp r) r (car r)))
12139                                  (max (if (numberp r) r (cdr r))))
12140                             (while (and (<= min max)
12141                                         (> all 0))
12142                               (push max older)
12143                               (setq all (1- all)
12144                                     max (1- max))))))))))
12145           (setq older (gnus-uncompress-range older))))
12146         (if (not older)
12147             (message "No old news.")
12148           (gnus-summary-insert-articles older)
12149           (gnus-summary-limit (gnus-sorted-nunion old older))))
12150     (gnus-summary-position-point)))
12151
12152 (defun gnus-summary-insert-new-articles ()
12153   "Insert all new articles in this group."
12154   (interactive)
12155   (prog1
12156       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12157             (old-active gnus-newsgroup-active)
12158             (nnmail-fetched-sources (list t))
12159             i new)
12160         (setq gnus-newsgroup-active
12161               (gnus-activate-group gnus-newsgroup-name 'scan))
12162         (setq i (cdr gnus-newsgroup-active))
12163         (while (> i (cdr old-active))
12164           (push i new)
12165           (decf i))
12166         (if (not new)
12167             (message "No gnus is bad news")
12168           (gnus-summary-insert-articles new)
12169           (setq gnus-newsgroup-unreads
12170                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12171           (gnus-summary-limit (gnus-sorted-nunion old new))))
12172     (gnus-summary-position-point)))
12173
12174 (gnus-summary-make-all-marking-commands)
12175
12176 (gnus-ems-redefine)
12177
12178 (provide 'gnus-sum)
12179
12180 (run-hooks 'gnus-sum-load-hook)
12181
12182 ;; Local Variables:
12183 ;; coding: iso-8859-1
12184 ;; End:
12185
12186 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12187 ;;; gnus-sum.el ends here