(clean): New rule.
[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-map))
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 200
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-auto-expire nil)
1326 (defvar gnus-newsgroup-active nil)
1327
1328 (defvar gnus-newsgroup-data nil)
1329 (defvar gnus-newsgroup-data-reverse nil)
1330 (defvar gnus-newsgroup-limit nil)
1331 (defvar gnus-newsgroup-limits nil)
1332 (defvar gnus-summary-use-undownloaded-faces nil)
1333
1334 (defvar gnus-newsgroup-unreads nil
1335   "Sorted list of unread articles in the current newsgroup.")
1336
1337 (defvar gnus-newsgroup-unselected nil
1338   "Sorted list of unselected unread articles in the current newsgroup.")
1339
1340 (defvar gnus-newsgroup-reads nil
1341   "Alist of read articles and article marks in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-expunged-tally nil)
1344
1345 (defvar gnus-newsgroup-marked nil
1346   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1347
1348 (defvar gnus-newsgroup-spam-marked nil
1349   "List of ranges of articles that have been marked as spam.")
1350
1351 (defvar gnus-newsgroup-killed nil
1352   "List of ranges of articles that have been through the scoring process.")
1353
1354 (defvar gnus-newsgroup-cached nil
1355   "Sorted list of articles that come from the article cache.")
1356
1357 (defvar gnus-newsgroup-saved nil
1358   "List of articles that have been saved.")
1359
1360 (defvar gnus-newsgroup-kill-headers nil)
1361
1362 (defvar gnus-newsgroup-replied nil
1363   "List of articles that have been replied to in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-forwarded nil
1366   "List of articles that have been forwarded in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-recent nil
1369   "List of articles that have are recent in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expirable nil
1372   "Sorted list of articles in the current newsgroup that can be expired.")
1373
1374 (defvar gnus-newsgroup-processable nil
1375   "List of articles in the current newsgroup that can be processed.")
1376
1377 (defvar gnus-newsgroup-downloadable nil
1378   "Sorted list of articles in the current newsgroup that can be processed.")
1379
1380 (defvar gnus-newsgroup-unfetched nil
1381   "Sorted list of articles in the current newsgroup whose headers have
1382 not been fetched into the agent.
1383
1384 This list will always be a subset of gnus-newsgroup-undownloaded.")
1385
1386 (defvar gnus-newsgroup-undownloaded nil
1387   "List of articles in the current newsgroup that haven't been downloaded.")
1388
1389 (defvar gnus-newsgroup-unsendable nil
1390   "List of articles in the current newsgroup that won't be sent.")
1391
1392 (defvar gnus-newsgroup-bookmarks nil
1393   "List of articles in the current newsgroup that have bookmarks.")
1394
1395 (defvar gnus-newsgroup-dormant nil
1396   "Sorted list of dormant articles in the current newsgroup.")
1397
1398 (defvar gnus-newsgroup-unseen nil
1399   "List of unseen articles in the current newsgroup.")
1400
1401 (defvar gnus-newsgroup-seen nil
1402   "Range of seen articles in the current newsgroup.")
1403
1404 (defvar gnus-newsgroup-articles nil
1405   "List of articles in the current newsgroup.")
1406
1407 (defvar gnus-newsgroup-scored nil
1408   "List of scored articles in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-headers nil
1411   "List of article headers in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-threads nil)
1414
1415 (defvar gnus-newsgroup-prepared nil
1416   "Whether the current group has been prepared properly.")
1417
1418 (defvar gnus-newsgroup-ancient nil
1419   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1420
1421 (defvar gnus-newsgroup-sparse nil)
1422
1423 (defvar gnus-current-article nil)
1424 (defvar gnus-article-current nil)
1425 (defvar gnus-current-headers nil)
1426 (defvar gnus-have-all-headers nil)
1427 (defvar gnus-last-article nil)
1428 (defvar gnus-newsgroup-history nil)
1429 (defvar gnus-newsgroup-charset nil)
1430 (defvar gnus-newsgroup-ephemeral-charset nil)
1431 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1432
1433 (defvar gnus-article-before-search nil)
1434
1435 (defvar gnus-summary-local-variables
1436   '(gnus-newsgroup-name
1437     gnus-newsgroup-begin gnus-newsgroup-end
1438     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1439     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1440     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1441     gnus-newsgroup-unselected gnus-newsgroup-marked
1442     gnus-newsgroup-spam-marked
1443     gnus-newsgroup-reads gnus-newsgroup-saved
1444     gnus-newsgroup-replied gnus-newsgroup-forwarded
1445     gnus-newsgroup-recent
1446     gnus-newsgroup-expirable
1447     gnus-newsgroup-processable gnus-newsgroup-killed
1448     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1449     gnus-newsgroup-unfetched
1450     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1451     gnus-newsgroup-seen gnus-newsgroup-articles
1452     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1453     gnus-newsgroup-headers gnus-newsgroup-threads
1454     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1455     gnus-current-article gnus-current-headers gnus-have-all-headers
1456     gnus-last-article gnus-article-internal-prepare-hook
1457     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1458     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1459     gnus-thread-expunge-below
1460     gnus-score-alist gnus-current-score-file
1461     (gnus-summary-expunge-below . global)
1462     (gnus-summary-mark-below . global)
1463     (gnus-orphan-score . global)
1464     gnus-newsgroup-active gnus-scores-exclude-files
1465     gnus-newsgroup-history gnus-newsgroup-ancient
1466     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1467     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1468     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1469     (gnus-newsgroup-expunged-tally . 0)
1470     gnus-cache-removable-articles gnus-newsgroup-cached
1471     gnus-newsgroup-data gnus-newsgroup-data-reverse
1472     gnus-newsgroup-limit gnus-newsgroup-limits
1473     gnus-newsgroup-charset gnus-newsgroup-display
1474     gnus-summary-use-undownloaded-faces)
1475   "Variables that are buffer-local to the summary buffers.")
1476
1477 (defvar gnus-newsgroup-variables nil
1478   "A list of variables that have separate values in different newsgroups.
1479 A list of newsgroup (summary buffer) local variables, or cons of
1480 variables and their default expressions to be evalled (when the default
1481 values are not nil), that should be made global while the summary buffer
1482 is active.
1483
1484 Note: The default expressions will be evaluated (using function `eval')
1485 before assignment to the local variable rather than just assigned to it.
1486 If the default expression is the symbol `global', that symbol will not
1487 be evaluated but the global value of the local variable will be used
1488 instead.
1489
1490 These variables can be used to set variables in the group parameters
1491 while still allowing them to affect operations done in other buffers.
1492 For example:
1493
1494 \(setq gnus-newsgroup-variables
1495      '(message-use-followup-to
1496        (gnus-visible-headers .
1497          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1498 ")
1499
1500 ;; Byte-compiler warning.
1501 (eval-when-compile
1502   ;; Bind features so that require will believe that gnus-sum has
1503   ;; already been loaded (avoids infinite recursion)
1504   (let ((features (cons 'gnus-sum features)))
1505     ;; Several of the declarations in gnus-sum are needed to load the
1506     ;; following files. Right now, these definitions have been
1507     ;; compiled but not defined (evaluated).  We could either do a
1508     ;; eval-and-compile about all of the declarations or evaluate the
1509     ;; source file.
1510     (if (boundp 'gnus-newsgroup-variables)
1511         nil
1512       (load "gnus-sum.el" t t t))
1513     (require 'gnus)
1514     (require 'gnus-art)))
1515
1516 ;; MIME stuff.
1517
1518 (defvar gnus-decode-encoded-word-methods
1519   '(mail-decode-encoded-word-string)
1520   "List of methods used to decode encoded words.
1521
1522 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1523 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1524 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1525 whose names match REGEXP.
1526
1527 For example:
1528 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1529  mail-decode-encoded-word-string
1530  (\"chinese\" . rfc1843-decode-string))")
1531
1532 (defvar gnus-decode-encoded-word-methods-cache nil)
1533
1534 (defun gnus-multi-decode-encoded-word-string (string)
1535   "Apply the functions from `gnus-encoded-word-methods' that match."
1536   (unless (and gnus-decode-encoded-word-methods-cache
1537                (eq gnus-newsgroup-name
1538                    (car gnus-decode-encoded-word-methods-cache)))
1539     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1540     (mapcar (lambda (x)
1541               (if (symbolp x)
1542                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1543                 (if (and gnus-newsgroup-name
1544                          (string-match (car x) gnus-newsgroup-name))
1545                     (nconc gnus-decode-encoded-word-methods-cache
1546                            (list (cdr x))))))
1547             gnus-decode-encoded-word-methods))
1548   (let ((xlist gnus-decode-encoded-word-methods-cache))
1549     (pop xlist)
1550     (while xlist
1551       (setq string (funcall (pop xlist) string))))
1552   string)
1553
1554 ;; Subject simplification.
1555
1556 (defun gnus-simplify-whitespace (str)
1557   "Remove excessive whitespace from STR."
1558   ;; Multiple spaces.
1559   (while (string-match "[ \t][ \t]+" str)
1560     (setq str (concat (substring str 0 (match-beginning 0))
1561                         " "
1562                         (substring str (match-end 0)))))
1563   ;; Leading spaces.
1564   (when (string-match "^[ \t]+" str)
1565     (setq str (substring str (match-end 0))))
1566   ;; Trailing spaces.
1567   (when (string-match "[ \t]+$" str)
1568     (setq str (substring str 0 (match-beginning 0))))
1569   str)
1570
1571 (defun gnus-simplify-all-whitespace (str)
1572   "Remove all whitespace from STR."
1573   (while (string-match "[ \t\n]+" str)
1574     (setq str (replace-match "" nil nil str)))
1575   str)
1576
1577 (defsubst gnus-simplify-subject-re (subject)
1578   "Remove \"Re:\" from subject lines."
1579   (if (string-match message-subject-re-regexp subject)
1580       (substring subject (match-end 0))
1581     subject))
1582
1583 (defun gnus-simplify-subject (subject &optional re-only)
1584   "Remove `Re:' and words in parentheses.
1585 If RE-ONLY is non-nil, strip leading `Re:'s only."
1586   (let ((case-fold-search t))           ;Ignore case.
1587     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1588     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1589       (setq subject (substring subject (match-end 0))))
1590     ;; Remove uninteresting prefixes.
1591     (when (and (not re-only)
1592                gnus-simplify-ignored-prefixes
1593                (string-match gnus-simplify-ignored-prefixes subject))
1594       (setq subject (substring subject (match-end 0))))
1595     ;; Remove words in parentheses from end.
1596     (unless re-only
1597       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1598         (setq subject (substring subject 0 (match-beginning 0)))))
1599     ;; Return subject string.
1600     subject))
1601
1602 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1603 ;; all whitespace.
1604 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1605   (goto-char (point-min))
1606   (while (re-search-forward regexp nil t)
1607     (replace-match (or newtext ""))))
1608
1609 (defun gnus-simplify-buffer-fuzzy ()
1610   "Simplify string in the buffer fuzzily.
1611 The string in the accessible portion of the current buffer is simplified.
1612 It is assumed to be a single-line subject.
1613 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1614 matter is removed.  Additional things can be deleted by setting
1615 `gnus-simplify-subject-fuzzy-regexp'."
1616   (let ((case-fold-search t)
1617         (modified-tick))
1618     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1619
1620     (while (not (eq modified-tick (buffer-modified-tick)))
1621       (setq modified-tick (buffer-modified-tick))
1622       (cond
1623        ((listp gnus-simplify-subject-fuzzy-regexp)
1624         (mapcar 'gnus-simplify-buffer-fuzzy-step
1625                 gnus-simplify-subject-fuzzy-regexp))
1626        (gnus-simplify-subject-fuzzy-regexp
1627         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1628       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1629       (gnus-simplify-buffer-fuzzy-step
1630        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1631       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1632
1633     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1634     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1635     (gnus-simplify-buffer-fuzzy-step " $")
1636     (gnus-simplify-buffer-fuzzy-step "^ +")))
1637
1638 (defun gnus-simplify-subject-fuzzy (subject)
1639   "Simplify a subject string fuzzily.
1640 See `gnus-simplify-buffer-fuzzy' for details."
1641   (save-excursion
1642     (gnus-set-work-buffer)
1643     (let ((case-fold-search t))
1644       ;; Remove uninteresting prefixes.
1645       (when (and gnus-simplify-ignored-prefixes
1646                  (string-match gnus-simplify-ignored-prefixes subject))
1647         (setq subject (substring subject (match-end 0))))
1648       (insert subject)
1649       (inline (gnus-simplify-buffer-fuzzy))
1650       (buffer-string))))
1651
1652 (defsubst gnus-simplify-subject-fully (subject)
1653   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1654   (cond
1655    (gnus-simplify-subject-functions
1656     (gnus-map-function gnus-simplify-subject-functions subject))
1657    ((null gnus-summary-gather-subject-limit)
1658     (gnus-simplify-subject-re subject))
1659    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1660     (gnus-simplify-subject-fuzzy subject))
1661    ((numberp gnus-summary-gather-subject-limit)
1662     (gnus-limit-string (gnus-simplify-subject-re subject)
1663                        gnus-summary-gather-subject-limit))
1664    (t
1665     subject)))
1666
1667 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1668   "Check whether two subjects are equal.
1669 If optional argument SIMPLE-FIRST is t, first argument is already
1670 simplified."
1671   (cond
1672    ((null simple-first)
1673     (equal (gnus-simplify-subject-fully s1)
1674            (gnus-simplify-subject-fully s2)))
1675    (t
1676     (equal s1
1677            (gnus-simplify-subject-fully s2)))))
1678
1679 (defun gnus-summary-bubble-group ()
1680   "Increase the score of the current group.
1681 This is a handy function to add to `gnus-summary-exit-hook' to
1682 increase the score of each group you read."
1683   (gnus-group-add-score gnus-newsgroup-name))
1684
1685 \f
1686 ;;;
1687 ;;; Gnus summary mode
1688 ;;;
1689
1690 (put 'gnus-summary-mode 'mode-class 'special)
1691
1692 (defvar gnus-article-commands-menu)
1693
1694 ;; Non-orthogonal keys
1695
1696 (gnus-define-keys gnus-summary-mode-map
1697   " " gnus-summary-next-page
1698   "\177" gnus-summary-prev-page
1699   [delete] gnus-summary-prev-page
1700   [backspace] gnus-summary-prev-page
1701   "\r" gnus-summary-scroll-up
1702   "\M-\r" gnus-summary-scroll-down
1703   "n" gnus-summary-next-unread-article
1704   "p" gnus-summary-prev-unread-article
1705   "N" gnus-summary-next-article
1706   "P" gnus-summary-prev-article
1707   "\M-\C-n" gnus-summary-next-same-subject
1708   "\M-\C-p" gnus-summary-prev-same-subject
1709   "\M-n" gnus-summary-next-unread-subject
1710   "\M-p" gnus-summary-prev-unread-subject
1711   "." gnus-summary-first-unread-article
1712   "," gnus-summary-best-unread-article
1713   "\M-s" gnus-summary-search-article-forward
1714   "\M-r" gnus-summary-search-article-backward
1715   "<" gnus-summary-beginning-of-article
1716   ">" gnus-summary-end-of-article
1717   "j" gnus-summary-goto-article
1718   "^" gnus-summary-refer-parent-article
1719   "\M-^" gnus-summary-refer-article
1720   "u" gnus-summary-tick-article-forward
1721   "!" gnus-summary-tick-article-forward
1722   "U" gnus-summary-tick-article-backward
1723   "d" gnus-summary-mark-as-read-forward
1724   "D" gnus-summary-mark-as-read-backward
1725   "E" gnus-summary-mark-as-expirable
1726   "\M-u" gnus-summary-clear-mark-forward
1727   "\M-U" gnus-summary-clear-mark-backward
1728   "k" gnus-summary-kill-same-subject-and-select
1729   "\C-k" gnus-summary-kill-same-subject
1730   "\M-\C-k" gnus-summary-kill-thread
1731   "\M-\C-l" gnus-summary-lower-thread
1732   "e" gnus-summary-edit-article
1733   "#" gnus-summary-mark-as-processable
1734   "\M-#" gnus-summary-unmark-as-processable
1735   "\M-\C-t" gnus-summary-toggle-threads
1736   "\M-\C-s" gnus-summary-show-thread
1737   "\M-\C-h" gnus-summary-hide-thread
1738   "\M-\C-f" gnus-summary-next-thread
1739   "\M-\C-b" gnus-summary-prev-thread
1740   [(meta down)] gnus-summary-next-thread
1741   [(meta up)] gnus-summary-prev-thread
1742   "\M-\C-u" gnus-summary-up-thread
1743   "\M-\C-d" gnus-summary-down-thread
1744   "&" gnus-summary-execute-command
1745   "c" gnus-summary-catchup-and-exit
1746   "\C-w" gnus-summary-mark-region-as-read
1747   "\C-t" gnus-summary-toggle-truncation
1748   "?" gnus-summary-mark-as-dormant
1749   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1750   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1751   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1752   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1753   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1754   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1755   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1756   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1757   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1758   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1759   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1760   "=" gnus-summary-expand-window
1761   "\C-x\C-s" gnus-summary-reselect-current-group
1762   "\M-g" gnus-summary-rescan-group
1763   "w" gnus-summary-stop-page-breaking
1764   "\C-c\C-r" gnus-summary-caesar-message
1765   "f" gnus-summary-followup
1766   "F" gnus-summary-followup-with-original
1767   "C" gnus-summary-cancel-article
1768   "r" gnus-summary-reply
1769   "R" gnus-summary-reply-with-original
1770   "\C-c\C-f" gnus-summary-mail-forward
1771   "o" gnus-summary-save-article
1772   "\C-o" gnus-summary-save-article-mail
1773   "|" gnus-summary-pipe-output
1774   "\M-k" gnus-summary-edit-local-kill
1775   "\M-K" gnus-summary-edit-global-kill
1776   ;; "V" gnus-version
1777   "\C-c\C-d" gnus-summary-describe-group
1778   "q" gnus-summary-exit
1779   "Q" gnus-summary-exit-no-update
1780   "\C-c\C-i" gnus-info-find-node
1781   gnus-mouse-2 gnus-mouse-pick-article
1782   [follow-link] mouse-face
1783   "m" gnus-summary-mail-other-window
1784   "a" gnus-summary-post-news
1785   "i" gnus-summary-news-other-window
1786   "x" gnus-summary-limit-to-unread
1787   "s" gnus-summary-isearch-article
1788   "t" gnus-summary-toggle-header
1789   "g" gnus-summary-show-article
1790   "l" gnus-summary-goto-last-article
1791   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1792   "\C-d" gnus-summary-enter-digest-group
1793   "\M-\C-d" gnus-summary-read-document
1794   "\M-\C-e" gnus-summary-edit-parameters
1795   "\M-\C-a" gnus-summary-customize-parameters
1796   "\C-c\C-b" gnus-bug
1797   "*" gnus-cache-enter-article
1798   "\M-*" gnus-cache-remove-article
1799   "\M-&" gnus-summary-universal-argument
1800   "\C-l" gnus-recenter
1801   "I" gnus-summary-increase-score
1802   "L" gnus-summary-lower-score
1803   "\M-i" gnus-symbolic-argument
1804   "h" gnus-summary-select-article-buffer
1805
1806   "b" gnus-article-view-part
1807   "\M-t" gnus-summary-toggle-display-buttonized
1808
1809   "V" gnus-summary-score-map
1810   "X" gnus-uu-extract-map
1811   "S" gnus-summary-send-map)
1812
1813 ;; Sort of orthogonal keymap
1814 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1815   "t" gnus-summary-tick-article-forward
1816   "!" gnus-summary-tick-article-forward
1817   "d" gnus-summary-mark-as-read-forward
1818   "r" gnus-summary-mark-as-read-forward
1819   "c" gnus-summary-clear-mark-forward
1820   " " gnus-summary-clear-mark-forward
1821   "e" gnus-summary-mark-as-expirable
1822   "x" gnus-summary-mark-as-expirable
1823   "?" gnus-summary-mark-as-dormant
1824   "b" gnus-summary-set-bookmark
1825   "B" gnus-summary-remove-bookmark
1826   "#" gnus-summary-mark-as-processable
1827   "\M-#" gnus-summary-unmark-as-processable
1828   "S" gnus-summary-limit-include-expunged
1829   "C" gnus-summary-catchup
1830   "H" gnus-summary-catchup-to-here
1831   "h" gnus-summary-catchup-from-here
1832   "\C-c" gnus-summary-catchup-all
1833   "k" gnus-summary-kill-same-subject-and-select
1834   "K" gnus-summary-kill-same-subject
1835   "P" gnus-uu-mark-map)
1836
1837 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1838   "c" gnus-summary-clear-above
1839   "u" gnus-summary-tick-above
1840   "m" gnus-summary-mark-above
1841   "k" gnus-summary-kill-below)
1842
1843 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1844   "/" gnus-summary-limit-to-subject
1845   "n" gnus-summary-limit-to-articles
1846   "w" gnus-summary-pop-limit
1847   "s" gnus-summary-limit-to-subject
1848   "a" gnus-summary-limit-to-author
1849   "u" gnus-summary-limit-to-unread
1850   "m" gnus-summary-limit-to-marks
1851   "M" gnus-summary-limit-exclude-marks
1852   "v" gnus-summary-limit-to-score
1853   "*" gnus-summary-limit-include-cached
1854   "D" gnus-summary-limit-include-dormant
1855   "T" gnus-summary-limit-include-thread
1856   "d" gnus-summary-limit-exclude-dormant
1857   "t" gnus-summary-limit-to-age
1858   "." gnus-summary-limit-to-unseen
1859   "x" gnus-summary-limit-to-extra
1860   "p" gnus-summary-limit-to-display-predicate
1861   "E" gnus-summary-limit-include-expunged
1862   "c" gnus-summary-limit-exclude-childless-dormant
1863   "C" gnus-summary-limit-mark-excluded-as-read
1864   "o" gnus-summary-insert-old-articles
1865   "N" gnus-summary-insert-new-articles
1866   "r" gnus-summary-limit-to-replied
1867   "R" gnus-summary-limit-to-recipient)
1868
1869 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1870   "n" gnus-summary-next-unread-article
1871   "p" gnus-summary-prev-unread-article
1872   "N" gnus-summary-next-article
1873   "P" gnus-summary-prev-article
1874   "\C-n" gnus-summary-next-same-subject
1875   "\C-p" gnus-summary-prev-same-subject
1876   "\M-n" gnus-summary-next-unread-subject
1877   "\M-p" gnus-summary-prev-unread-subject
1878   "f" gnus-summary-first-unread-article
1879   "b" gnus-summary-best-unread-article
1880   "j" gnus-summary-goto-article
1881   "g" gnus-summary-goto-subject
1882   "l" gnus-summary-goto-last-article
1883   "o" gnus-summary-pop-article)
1884
1885 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1886   "k" gnus-summary-kill-thread
1887   "l" gnus-summary-lower-thread
1888   "i" gnus-summary-raise-thread
1889   "T" gnus-summary-toggle-threads
1890   "t" gnus-summary-rethread-current
1891   "^" gnus-summary-reparent-thread
1892   "s" gnus-summary-show-thread
1893   "S" gnus-summary-show-all-threads
1894   "h" gnus-summary-hide-thread
1895   "H" gnus-summary-hide-all-threads
1896   "n" gnus-summary-next-thread
1897   "p" gnus-summary-prev-thread
1898   "u" gnus-summary-up-thread
1899   "o" gnus-summary-top-thread
1900   "d" gnus-summary-down-thread
1901   "#" gnus-uu-mark-thread
1902   "\M-#" gnus-uu-unmark-thread)
1903
1904 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1905   "g" gnus-summary-prepare
1906   "c" gnus-summary-insert-cached-articles
1907   "d" gnus-summary-insert-dormant-articles)
1908
1909 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1910   "c" gnus-summary-catchup-and-exit
1911   "C" gnus-summary-catchup-all-and-exit
1912   "E" gnus-summary-exit-no-update
1913   "Q" gnus-summary-exit
1914   "Z" gnus-summary-exit
1915   "n" gnus-summary-catchup-and-goto-next-group
1916   "p" gnus-summary-catchup-and-goto-prev-group
1917   "R" gnus-summary-reselect-current-group
1918   "G" gnus-summary-rescan-group
1919   "N" gnus-summary-next-group
1920   "s" gnus-summary-save-newsrc
1921   "P" gnus-summary-prev-group)
1922
1923 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1924   " " gnus-summary-next-page
1925   "n" gnus-summary-next-page
1926   "\177" gnus-summary-prev-page
1927   [delete] gnus-summary-prev-page
1928   "p" gnus-summary-prev-page
1929   "\r" gnus-summary-scroll-up
1930   "\M-\r" gnus-summary-scroll-down
1931   "<" gnus-summary-beginning-of-article
1932   ">" gnus-summary-end-of-article
1933   "b" gnus-summary-beginning-of-article
1934   "e" gnus-summary-end-of-article
1935   "^" gnus-summary-refer-parent-article
1936   "r" gnus-summary-refer-parent-article
1937   "D" gnus-summary-enter-digest-group
1938   "R" gnus-summary-refer-references
1939   "T" gnus-summary-refer-thread
1940   "g" gnus-summary-show-article
1941   "s" gnus-summary-isearch-article
1942   "P" gnus-summary-print-article
1943   "M" gnus-mailing-list-insinuate
1944   "t" gnus-article-babel)
1945
1946 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1947   "b" gnus-article-add-buttons
1948   "B" gnus-article-add-buttons-to-head
1949   "o" gnus-article-treat-overstrike
1950   "e" gnus-article-emphasize
1951   "w" gnus-article-fill-cited-article
1952   "Q" gnus-article-fill-long-lines
1953   "C" gnus-article-capitalize-sentences
1954   "c" gnus-article-remove-cr
1955   "q" gnus-article-de-quoted-unreadable
1956   "6" gnus-article-de-base64-unreadable
1957   "Z" gnus-article-decode-HZ
1958   "A" gnus-article-treat-ansi-sequences
1959   "h" gnus-article-wash-html
1960   "u" gnus-article-unsplit-urls
1961   "s" gnus-summary-force-verify-and-decrypt
1962   "f" gnus-article-display-x-face
1963   "l" gnus-summary-stop-page-breaking
1964   "r" gnus-summary-caesar-message
1965   "m" gnus-summary-morse-message
1966   "t" gnus-summary-toggle-header
1967   "g" gnus-treat-smiley
1968   "v" gnus-summary-verbose-headers
1969   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1970   "p" gnus-article-verify-x-pgp-sig
1971   "d" gnus-article-treat-dumbquotes
1972   "i" gnus-summary-idna-message)
1973
1974 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1975   ;; mnemonic: deuglif*Y*
1976   "u" gnus-article-outlook-unwrap-lines
1977   "a" gnus-article-outlook-repair-attribution
1978   "c" gnus-article-outlook-rearrange-citation
1979   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1980
1981 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1982   "a" gnus-article-hide
1983   "h" gnus-article-hide-headers
1984   "b" gnus-article-hide-boring-headers
1985   "s" gnus-article-hide-signature
1986   "c" gnus-article-hide-citation
1987   "C" gnus-article-hide-citation-in-followups
1988   "l" gnus-article-hide-list-identifiers
1989   "B" gnus-article-strip-banner
1990   "P" gnus-article-hide-pem
1991   "\C-c" gnus-article-hide-citation-maybe)
1992
1993 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1994   "a" gnus-article-highlight
1995   "h" gnus-article-highlight-headers
1996   "c" gnus-article-highlight-citation
1997   "s" gnus-article-highlight-signature)
1998
1999 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2000   "f" gnus-article-treat-fold-headers
2001   "u" gnus-article-treat-unfold-headers
2002   "n" gnus-article-treat-fold-newsgroups)
2003
2004 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2005   "x" gnus-article-display-x-face
2006   "d" gnus-article-display-face
2007   "s" gnus-treat-smiley
2008   "D" gnus-article-remove-images
2009   "f" gnus-treat-from-picon
2010   "m" gnus-treat-mail-picon
2011   "n" gnus-treat-newsgroups-picon)
2012
2013 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2014   "w" gnus-article-decode-mime-words
2015   "c" gnus-article-decode-charset
2016   "v" gnus-mime-view-all-parts
2017   "b" gnus-article-view-part)
2018
2019 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2020   "z" gnus-article-date-ut
2021   "u" gnus-article-date-ut
2022   "l" gnus-article-date-local
2023   "p" gnus-article-date-english
2024   "e" gnus-article-date-lapsed
2025   "o" gnus-article-date-original
2026   "i" gnus-article-date-iso8601
2027   "s" gnus-article-date-user)
2028
2029 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2030   "t" gnus-article-remove-trailing-blank-lines
2031   "l" gnus-article-strip-leading-blank-lines
2032   "m" gnus-article-strip-multiple-blank-lines
2033   "a" gnus-article-strip-blank-lines
2034   "A" gnus-article-strip-all-blank-lines
2035   "s" gnus-article-strip-leading-space
2036   "e" gnus-article-strip-trailing-space
2037   "w" gnus-article-remove-leading-whitespace)
2038
2039 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2040   "v" gnus-version
2041   "f" gnus-summary-fetch-faq
2042   "d" gnus-summary-describe-group
2043   "h" gnus-summary-describe-briefly
2044   "i" gnus-info-find-node
2045   "c" gnus-group-fetch-charter
2046   "C" gnus-group-fetch-control)
2047
2048 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2049   "e" gnus-summary-expire-articles
2050   "\M-\C-e" gnus-summary-expire-articles-now
2051   "\177" gnus-summary-delete-article
2052   [delete] gnus-summary-delete-article
2053   [backspace] gnus-summary-delete-article
2054   "m" gnus-summary-move-article
2055   "r" gnus-summary-respool-article
2056   "w" gnus-summary-edit-article
2057   "c" gnus-summary-copy-article
2058   "B" gnus-summary-crosspost-article
2059   "q" gnus-summary-respool-query
2060   "t" gnus-summary-respool-trace
2061   "i" gnus-summary-import-article
2062   "I" gnus-summary-create-article
2063   "p" gnus-summary-article-posted-p)
2064
2065 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2066   "o" gnus-summary-save-article
2067   "m" gnus-summary-save-article-mail
2068   "F" gnus-summary-write-article-file
2069   "r" gnus-summary-save-article-rmail
2070   "f" gnus-summary-save-article-file
2071   "b" gnus-summary-save-article-body-file
2072   "h" gnus-summary-save-article-folder
2073   "v" gnus-summary-save-article-vm
2074   "p" gnus-summary-pipe-output
2075   "P" gnus-summary-muttprint
2076   "s" gnus-soup-add-article)
2077
2078 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2079   "b" gnus-summary-display-buttonized
2080   "m" gnus-summary-repair-multipart
2081   "v" gnus-article-view-part
2082   "o" gnus-article-save-part
2083   "O" gnus-article-save-part-and-strip
2084   "r" gnus-article-replace-part
2085   "d" gnus-article-delete-part
2086   "j" gnus-article-jump-to-part
2087   "c" gnus-article-copy-part
2088   "C" gnus-article-view-part-as-charset
2089   "e" gnus-article-view-part-externally
2090   "E" gnus-article-encrypt-body
2091   "i" gnus-article-inline-part
2092   "|" gnus-article-pipe-part)
2093
2094 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2095   "p" gnus-summary-mark-as-processable
2096   "u" gnus-summary-unmark-as-processable
2097   "U" gnus-summary-unmark-all-processable
2098   "v" gnus-uu-mark-over
2099   "s" gnus-uu-mark-series
2100   "r" gnus-uu-mark-region
2101   "g" gnus-uu-unmark-region
2102   "R" gnus-uu-mark-by-regexp
2103   "G" gnus-uu-unmark-by-regexp
2104   "t" gnus-uu-mark-thread
2105   "T" gnus-uu-unmark-thread
2106   "a" gnus-uu-mark-all
2107   "b" gnus-uu-mark-buffer
2108   "S" gnus-uu-mark-sparse
2109   "k" gnus-summary-kill-process-mark
2110   "y" gnus-summary-yank-process-mark
2111   "w" gnus-summary-save-process-mark
2112   "i" gnus-uu-invert-processable)
2113
2114 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2115   ;;"x" gnus-uu-extract-any
2116   "m" gnus-summary-save-parts
2117   "u" gnus-uu-decode-uu
2118   "U" gnus-uu-decode-uu-and-save
2119   "s" gnus-uu-decode-unshar
2120   "S" gnus-uu-decode-unshar-and-save
2121   "o" gnus-uu-decode-save
2122   "O" gnus-uu-decode-save
2123   "b" gnus-uu-decode-binhex
2124   "B" gnus-uu-decode-binhex
2125   "p" gnus-uu-decode-postscript
2126   "P" gnus-uu-decode-postscript-and-save)
2127
2128 (gnus-define-keys
2129     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2130   "u" gnus-uu-decode-uu-view
2131   "U" gnus-uu-decode-uu-and-save-view
2132   "s" gnus-uu-decode-unshar-view
2133   "S" gnus-uu-decode-unshar-and-save-view
2134   "o" gnus-uu-decode-save-view
2135   "O" gnus-uu-decode-save-view
2136   "b" gnus-uu-decode-binhex-view
2137   "B" gnus-uu-decode-binhex-view
2138   "p" gnus-uu-decode-postscript-view
2139   "P" gnus-uu-decode-postscript-and-save-view)
2140
2141 (defvar gnus-article-post-menu nil)
2142
2143 (defconst gnus-summary-menu-maxlen 20)
2144
2145 (defun gnus-summary-menu-split (menu)
2146   ;; If we have lots of elements, divide them into groups of 20
2147   ;; and make a pane (or submenu) for each one.
2148   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2149       (let ((menu menu) sublists next
2150             (i 1))
2151         (while menu
2152           ;; Pull off the next gnus-summary-menu-maxlen elements
2153           ;; and make them the next element of sublist.
2154           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2155           (if next
2156               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2157                       nil))
2158           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2159                                              (aref (car (last menu)) 0)) menu)
2160                                sublists))
2161           (setq i (1+ i))
2162           (setq menu next))
2163         (nreverse sublists))
2164     ;; Few elements--put them all in one pane.
2165     menu))
2166
2167 (defun gnus-summary-make-menu-bar ()
2168   (gnus-turn-off-edit-menu 'summary)
2169
2170   (unless (boundp 'gnus-summary-misc-menu)
2171
2172     (easy-menu-define
2173       gnus-summary-kill-menu gnus-summary-mode-map ""
2174       (cons
2175        "Score"
2176        (nconc
2177         (list
2178          ["Customize" gnus-score-customize t])
2179         (gnus-make-score-map 'increase)
2180         (gnus-make-score-map 'lower)
2181         '(("Mark"
2182            ["Kill below" gnus-summary-kill-below t]
2183            ["Mark above" gnus-summary-mark-above t]
2184            ["Tick above" gnus-summary-tick-above t]
2185            ["Clear above" gnus-summary-clear-above t])
2186           ["Current score" gnus-summary-current-score t]
2187           ["Set score" gnus-summary-set-score t]
2188           ["Switch current score file..." gnus-score-change-score-file t]
2189           ["Set mark below..." gnus-score-set-mark-below t]
2190           ["Set expunge below..." gnus-score-set-expunge-below t]
2191           ["Edit current score file" gnus-score-edit-current-scores t]
2192           ["Edit score file" gnus-score-edit-file t]
2193           ["Trace score" gnus-score-find-trace t]
2194           ["Find words" gnus-score-find-favourite-words t]
2195           ["Rescore buffer" gnus-summary-rescore t]
2196           ["Increase score..." gnus-summary-increase-score t]
2197           ["Lower score..." gnus-summary-lower-score t]))))
2198
2199     ;; Define both the Article menu in the summary buffer and the
2200     ;; equivalent Commands menu in the article buffer here for
2201     ;; consistency.
2202     (let ((innards
2203            `(("Hide"
2204               ["All" gnus-article-hide t]
2205               ["Headers" gnus-article-hide-headers t]
2206               ["Signature" gnus-article-hide-signature t]
2207               ["Citation" gnus-article-hide-citation t]
2208               ["List identifiers" gnus-article-hide-list-identifiers t]
2209               ["Banner" gnus-article-strip-banner t]
2210               ["Boring headers" gnus-article-hide-boring-headers t])
2211              ("Highlight"
2212               ["All" gnus-article-highlight t]
2213               ["Headers" gnus-article-highlight-headers t]
2214               ["Signature" gnus-article-highlight-signature t]
2215               ["Citation" gnus-article-highlight-citation t])
2216              ("MIME"
2217               ["Words" gnus-article-decode-mime-words t]
2218               ["Charset" gnus-article-decode-charset t]
2219               ["QP" gnus-article-de-quoted-unreadable t]
2220               ["Base64" gnus-article-de-base64-unreadable t]
2221               ["View MIME buttons" gnus-summary-display-buttonized t]
2222               ["View all" gnus-mime-view-all-parts t]
2223               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2224               ["Encrypt body" gnus-article-encrypt-body
2225                :active (not (gnus-group-read-only-p))
2226                ,@(if (featurep 'xemacs) nil
2227                    '(:help "Encrypt the message body on disk"))]
2228               ["Extract all parts..." gnus-summary-save-parts t]
2229               ("Multipart"
2230                ["Repair multipart" gnus-summary-repair-multipart t]
2231                ["Pipe part..." gnus-article-pipe-part t]
2232                ["Inline part" gnus-article-inline-part t]
2233                ["Encrypt body" gnus-article-encrypt-body
2234                 :active (not (gnus-group-read-only-p))
2235                ,@(if (featurep 'xemacs) nil
2236                    '(:help "Encrypt the message body on disk"))]
2237                ["View part externally" gnus-article-view-part-externally t]
2238                ["View part with charset..." gnus-article-view-part-as-charset t]
2239                ["Copy part" gnus-article-copy-part t]
2240                ["Save part..." gnus-article-save-part t]
2241                ["View part" gnus-article-view-part t]))
2242              ("Date"
2243               ["Local" gnus-article-date-local t]
2244               ["ISO8601" gnus-article-date-iso8601 t]
2245               ["UT" gnus-article-date-ut t]
2246               ["Original" gnus-article-date-original t]
2247               ["Lapsed" gnus-article-date-lapsed t]
2248               ["User-defined" gnus-article-date-user t])
2249              ("Display"
2250               ["Remove images" gnus-article-remove-images t]
2251               ["Toggle smiley" gnus-treat-smiley t]
2252               ["Show X-Face" gnus-article-display-x-face t]
2253               ["Show picons in From" gnus-treat-from-picon t]
2254               ["Show picons in mail headers" gnus-treat-mail-picon t]
2255               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2256               ("View as different encoding"
2257                ,@(gnus-summary-menu-split
2258                   (mapcar
2259                    (lambda (cs)
2260                      ;; Since easymenu under Emacs doesn't allow
2261                      ;; lambda forms for menu commands, we should
2262                      ;; provide intern'ed function symbols.
2263                      (let ((command (intern (format "\
2264 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2265                        (fset command
2266                              `(lambda ()
2267                                 (interactive)
2268                                 (let ((gnus-summary-show-article-charset-alist
2269                                        '((1 . ,cs))))
2270                                   (gnus-summary-show-article 1))))
2271                        `[,(symbol-name cs) ,command t]))
2272                    (sort (if (fboundp 'coding-system-list)
2273                              (coding-system-list)
2274                            (mapcar 'car mm-mime-mule-charset-alist))
2275                          'string<)))))
2276              ("Washing"
2277               ("Remove Blanks"
2278                ["Leading" gnus-article-strip-leading-blank-lines t]
2279                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2280                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2281                ["All of the above" gnus-article-strip-blank-lines t]
2282                ["All" gnus-article-strip-all-blank-lines t]
2283                ["Leading space" gnus-article-strip-leading-space t]
2284                ["Trailing space" gnus-article-strip-trailing-space t]
2285                ["Leading space in headers"
2286                 gnus-article-remove-leading-whitespace t])
2287               ["Overstrike" gnus-article-treat-overstrike t]
2288               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2289               ["Emphasis" gnus-article-emphasize t]
2290               ["Word wrap" gnus-article-fill-cited-article t]
2291               ["Fill long lines" gnus-article-fill-long-lines t]
2292               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2293               ["Remove CR" gnus-article-remove-cr t]
2294               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2295               ["Base64" gnus-article-de-base64-unreadable t]
2296               ["Rot 13" gnus-summary-caesar-message
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "\"Caesar rotate\" article by 13"))]
2299               ["De-IDNA" gnus-summary-idna-message t]
2300               ["Morse decode" gnus-summary-morse-message t]
2301               ["Unix pipe..." gnus-summary-pipe-message t]
2302               ["Add buttons" gnus-article-add-buttons t]
2303               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2304               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2305               ["Verbose header" gnus-summary-verbose-headers t]
2306               ["Toggle header" gnus-summary-toggle-header t]
2307               ["Unfold headers" gnus-article-treat-unfold-headers t]
2308               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2309               ["Html" gnus-article-wash-html t]
2310               ["Unsplit URLs" gnus-article-unsplit-urls t]
2311               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2312               ["Decode HZ" gnus-article-decode-HZ t]
2313               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2314               ("(Outlook) Deuglify"
2315                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2316                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2317                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2318                ["Full (Outlook) deuglify"
2319                 gnus-article-outlook-deuglify-article t])
2320               )
2321              ("Output"
2322               ["Save in default format..." gnus-summary-save-article
2323                ,@(if (featurep 'xemacs) '(t)
2324                    '(:help "Save article using default method"))]
2325               ["Save in file..." gnus-summary-save-article-file
2326                ,@(if (featurep 'xemacs) '(t)
2327                    '(:help "Save article in file"))]
2328               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2329               ["Save in MH folder..." gnus-summary-save-article-folder t]
2330               ["Save in VM folder..." gnus-summary-save-article-vm t]
2331               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2332               ["Save body in file..." gnus-summary-save-article-body-file t]
2333               ["Pipe through a filter..." gnus-summary-pipe-output t]
2334               ["Add to SOUP packet" gnus-soup-add-article t]
2335               ["Print with Muttprint..." gnus-summary-muttprint t]
2336               ["Print" gnus-summary-print-article
2337                ,@(if (featurep 'xemacs) '(t)
2338                    '(:help "Generate and print a PostScript image"))])
2339              ("Copy, move,... (Backend)"
2340               ,@(if (featurep 'xemacs) nil
2341                   '(:help "Copying, moving, expiring articles..."))
2342               ["Respool article..." gnus-summary-respool-article t]
2343               ["Move article..." gnus-summary-move-article
2344                (gnus-check-backend-function
2345                 'request-move-article gnus-newsgroup-name)]
2346               ["Copy article..." gnus-summary-copy-article t]
2347               ["Crosspost article..." gnus-summary-crosspost-article
2348                (gnus-check-backend-function
2349                 'request-replace-article gnus-newsgroup-name)]
2350               ["Import file..." gnus-summary-import-article
2351                (gnus-check-backend-function
2352                 'request-accept-article gnus-newsgroup-name)]
2353               ["Create article..." gnus-summary-create-article
2354                (gnus-check-backend-function
2355                 'request-accept-article gnus-newsgroup-name)]
2356               ["Check if posted" gnus-summary-article-posted-p t]
2357               ["Edit article" gnus-summary-edit-article
2358                (not (gnus-group-read-only-p))]
2359               ["Delete article" gnus-summary-delete-article
2360                (gnus-check-backend-function
2361                 'request-expire-articles gnus-newsgroup-name)]
2362               ["Query respool" gnus-summary-respool-query t]
2363               ["Trace respool" gnus-summary-respool-trace t]
2364               ["Delete expirable articles" gnus-summary-expire-articles-now
2365                (gnus-check-backend-function
2366                 'request-expire-articles gnus-newsgroup-name)])
2367              ("Extract"
2368               ["Uudecode" gnus-uu-decode-uu
2369                ,@(if (featurep 'xemacs) '(t)
2370                    '(:help "Decode uuencoded article(s)"))]
2371               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2372               ["Unshar" gnus-uu-decode-unshar t]
2373               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2374               ["Save" gnus-uu-decode-save t]
2375               ["Binhex" gnus-uu-decode-binhex t]
2376               ["Postscript" gnus-uu-decode-postscript t]
2377               ["All MIME parts" gnus-summary-save-parts t])
2378              ("Cache"
2379               ["Enter article" gnus-cache-enter-article t]
2380               ["Remove article" gnus-cache-remove-article t])
2381              ["Translate" gnus-article-babel t]
2382              ["Select article buffer" gnus-summary-select-article-buffer t]
2383              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2384              ["Isearch article..." gnus-summary-isearch-article t]
2385              ["Beginning of the article" gnus-summary-beginning-of-article t]
2386              ["End of the article" gnus-summary-end-of-article t]
2387              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2388              ["Fetch referenced articles" gnus-summary-refer-references t]
2389              ["Fetch current thread" gnus-summary-refer-thread t]
2390              ["Fetch article with id..." gnus-summary-refer-article t]
2391              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2392              ["Redisplay" gnus-summary-show-article t]
2393              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2394       (easy-menu-define
2395         gnus-summary-article-menu gnus-summary-mode-map ""
2396         (cons "Article" innards))
2397
2398       (if (not (keymapp gnus-summary-article-menu))
2399           (easy-menu-define
2400             gnus-article-commands-menu gnus-article-mode-map ""
2401             (cons "Commands" innards))
2402         ;; in Emacs, don't share menu.
2403         (setq gnus-article-commands-menu
2404               (copy-keymap gnus-summary-article-menu))
2405         (define-key gnus-article-mode-map [menu-bar commands]
2406           (cons "Commands" gnus-article-commands-menu))))
2407
2408     (easy-menu-define
2409       gnus-summary-thread-menu gnus-summary-mode-map ""
2410       '("Threads"
2411         ["Find all messages in thread" gnus-summary-refer-thread t]
2412         ["Toggle threading" gnus-summary-toggle-threads t]
2413         ["Hide threads" gnus-summary-hide-all-threads t]
2414         ["Show threads" gnus-summary-show-all-threads t]
2415         ["Hide thread" gnus-summary-hide-thread t]
2416         ["Show thread" gnus-summary-show-thread t]
2417         ["Go to next thread" gnus-summary-next-thread t]
2418         ["Go to previous thread" gnus-summary-prev-thread t]
2419         ["Go down thread" gnus-summary-down-thread t]
2420         ["Go up thread" gnus-summary-up-thread t]
2421         ["Top of thread" gnus-summary-top-thread t]
2422         ["Mark thread as read" gnus-summary-kill-thread t]
2423         ["Lower thread score" gnus-summary-lower-thread t]
2424         ["Raise thread score" gnus-summary-raise-thread t]
2425         ["Rethread current" gnus-summary-rethread-current t]))
2426
2427     (easy-menu-define
2428       gnus-summary-post-menu gnus-summary-mode-map ""
2429       `("Post"
2430         ["Send a message (mail or news)" gnus-summary-post-news
2431          ,@(if (featurep 'xemacs) '(t)
2432              '(:help "Compose a new message (mail or news)"))]
2433         ["Followup" gnus-summary-followup
2434          ,@(if (featurep 'xemacs) '(t)
2435              '(:help "Post followup to this article"))]
2436         ["Followup and yank" gnus-summary-followup-with-original
2437          ,@(if (featurep 'xemacs) '(t)
2438              '(:help "Post followup to this article, quoting its contents"))]
2439         ["Supersede article" gnus-summary-supersede-article t]
2440         ["Cancel article" gnus-summary-cancel-article
2441          ,@(if (featurep 'xemacs) '(t)
2442              '(:help "Cancel an article you posted"))]
2443         ["Reply" gnus-summary-reply t]
2444         ["Reply and yank" gnus-summary-reply-with-original t]
2445         ["Wide reply" gnus-summary-wide-reply t]
2446         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2447          ,@(if (featurep 'xemacs) '(t)
2448              '(:help "Mail a reply, quoting this article"))]
2449         ["Very wide reply" gnus-summary-very-wide-reply t]
2450         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2451          ,@(if (featurep 'xemacs) '(t)
2452              '(:help "Mail a very wide reply, quoting this article"))]
2453         ["Mail forward" gnus-summary-mail-forward t]
2454         ["Post forward" gnus-summary-post-forward t]
2455         ["Digest and mail" gnus-uu-digest-mail-forward t]
2456         ["Digest and post" gnus-uu-digest-post-forward t]
2457         ["Resend message" gnus-summary-resend-message t]
2458         ["Resend message edit" gnus-summary-resend-message-edit t]
2459         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2460         ["Send a mail" gnus-summary-mail-other-window t]
2461         ["Create a local message" gnus-summary-news-other-window t]
2462         ["Uuencode and post" gnus-uu-post-news
2463          ,@(if (featurep 'xemacs) '(t)
2464              '(:help "Post a uuencoded article"))]
2465         ["Followup via news" gnus-summary-followup-to-mail t]
2466         ["Followup via news and yank"
2467          gnus-summary-followup-to-mail-with-original t]
2468         ;;("Draft"
2469         ;;["Send" gnus-summary-send-draft t]
2470         ;;["Send bounced" gnus-resend-bounced-mail t])
2471         ))
2472
2473     (cond
2474      ((not (keymapp gnus-summary-post-menu))
2475       (setq gnus-article-post-menu gnus-summary-post-menu))
2476      ((not gnus-article-post-menu)
2477       ;; Don't share post menu.
2478       (setq gnus-article-post-menu
2479             (copy-keymap gnus-summary-post-menu))))
2480     (define-key gnus-article-mode-map [menu-bar post]
2481       (cons "Post" gnus-article-post-menu))
2482
2483     (easy-menu-define
2484       gnus-summary-misc-menu gnus-summary-mode-map ""
2485       `("Gnus"
2486         ("Mark Read"
2487          ["Mark as read" gnus-summary-mark-as-read-forward t]
2488          ["Mark same subject and select"
2489           gnus-summary-kill-same-subject-and-select t]
2490          ["Mark same subject" gnus-summary-kill-same-subject t]
2491          ["Catchup" gnus-summary-catchup
2492           ,@(if (featurep 'xemacs) '(t)
2493               '(:help "Mark unread articles in this group as read"))]
2494          ["Catchup all" gnus-summary-catchup-all t]
2495          ["Catchup to here" gnus-summary-catchup-to-here t]
2496          ["Catchup from here" gnus-summary-catchup-from-here t]
2497          ["Catchup region" gnus-summary-mark-region-as-read
2498           (gnus-mark-active-p)]
2499          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2500         ("Mark Various"
2501          ["Tick" gnus-summary-tick-article-forward t]
2502          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2503          ["Remove marks" gnus-summary-clear-mark-forward t]
2504          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2505          ["Set bookmark" gnus-summary-set-bookmark t]
2506          ["Remove bookmark" gnus-summary-remove-bookmark t])
2507         ("Limit to"
2508          ["Marks..." gnus-summary-limit-to-marks t]
2509          ["Subject..." gnus-summary-limit-to-subject t]
2510          ["Author..." gnus-summary-limit-to-author t]
2511          ["Recipient..." gnus-summary-limit-to-recipient t]
2512          ["Age..." gnus-summary-limit-to-age t]
2513          ["Extra..." gnus-summary-limit-to-extra t]
2514          ["Score..." gnus-summary-limit-to-score t]
2515          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2516          ["Unread" gnus-summary-limit-to-unread t]
2517          ["Unseen" gnus-summary-limit-to-unseen t]
2518          ["Replied" gnus-summary-limit-to-replied t]
2519          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2520          ["Next articles" gnus-summary-limit-to-articles t]
2521          ["Pop limit" gnus-summary-pop-limit t]
2522          ["Show dormant" gnus-summary-limit-include-dormant t]
2523          ["Hide childless dormant"
2524           gnus-summary-limit-exclude-childless-dormant t]
2525          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2526          ["Hide marked" gnus-summary-limit-exclude-marks t]
2527          ["Show expunged" gnus-summary-limit-include-expunged t])
2528         ("Process Mark"
2529          ["Set mark" gnus-summary-mark-as-processable t]
2530          ["Remove mark" gnus-summary-unmark-as-processable t]
2531          ["Remove all marks" gnus-summary-unmark-all-processable t]
2532          ["Invert marks" gnus-uu-invert-processable t]
2533          ["Mark above" gnus-uu-mark-over t]
2534          ["Mark series" gnus-uu-mark-series t]
2535          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2536          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2537          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2538          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2539          ["Mark all" gnus-uu-mark-all t]
2540          ["Mark buffer" gnus-uu-mark-buffer t]
2541          ["Mark sparse" gnus-uu-mark-sparse t]
2542          ["Mark thread" gnus-uu-mark-thread t]
2543          ["Unmark thread" gnus-uu-unmark-thread t]
2544          ("Process Mark Sets"
2545           ["Kill" gnus-summary-kill-process-mark t]
2546           ["Yank" gnus-summary-yank-process-mark
2547            gnus-newsgroup-process-stack]
2548           ["Save" gnus-summary-save-process-mark t]
2549           ["Run command on marked..." gnus-summary-universal-argument t]))
2550         ("Scroll article"
2551          ["Page forward" gnus-summary-next-page
2552           ,@(if (featurep 'xemacs) '(t)
2553               '(:help "Show next page of article"))]
2554          ["Page backward" gnus-summary-prev-page
2555           ,@(if (featurep 'xemacs) '(t)
2556               '(:help "Show previous page of article"))]
2557          ["Line forward" gnus-summary-scroll-up t])
2558         ("Move"
2559          ["Next unread article" gnus-summary-next-unread-article t]
2560          ["Previous unread article" gnus-summary-prev-unread-article t]
2561          ["Next article" gnus-summary-next-article t]
2562          ["Previous article" gnus-summary-prev-article t]
2563          ["Next unread subject" gnus-summary-next-unread-subject t]
2564          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2565          ["Next article same subject" gnus-summary-next-same-subject t]
2566          ["Previous article same subject" gnus-summary-prev-same-subject t]
2567          ["First unread article" gnus-summary-first-unread-article t]
2568          ["Best unread article" gnus-summary-best-unread-article t]
2569          ["Go to subject number..." gnus-summary-goto-subject t]
2570          ["Go to article number..." gnus-summary-goto-article t]
2571          ["Go to the last article" gnus-summary-goto-last-article t]
2572          ["Pop article off history" gnus-summary-pop-article t])
2573         ("Sort"
2574          ["Sort by number" gnus-summary-sort-by-number t]
2575          ["Sort by author" gnus-summary-sort-by-author t]
2576          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2577          ["Sort by subject" gnus-summary-sort-by-subject t]
2578          ["Sort by date" gnus-summary-sort-by-date t]
2579          ["Sort by score" gnus-summary-sort-by-score t]
2580          ["Sort by lines" gnus-summary-sort-by-lines t]
2581          ["Sort by characters" gnus-summary-sort-by-chars t]
2582          ["Randomize" gnus-summary-sort-by-random t]
2583          ["Original sort" gnus-summary-sort-by-original t])
2584         ("Help"
2585          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2586          ["Describe group" gnus-summary-describe-group t]
2587          ["Fetch charter" gnus-group-fetch-charter
2588           ,@(if (featurep 'xemacs) nil
2589               '(:help "Display the charter of the current group"))]
2590          ["Fetch control message" gnus-group-fetch-control
2591           ,@(if (featurep 'xemacs) nil
2592               '(:help "Display the archived control message for the current group"))]
2593          ["Read manual" gnus-info-find-node t])
2594         ("Modes"
2595          ["Pick and read" gnus-pick-mode t]
2596          ["Binary" gnus-binary-mode t])
2597         ("Regeneration"
2598          ["Regenerate" gnus-summary-prepare t]
2599          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2600          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2601          ["Toggle threading" gnus-summary-toggle-threads t])
2602         ["See old articles" gnus-summary-insert-old-articles t]
2603         ["See new articles" gnus-summary-insert-new-articles t]
2604         ["Filter articles..." gnus-summary-execute-command t]
2605         ["Run command on articles..." gnus-summary-universal-argument t]
2606         ["Search articles forward..." gnus-summary-search-article-forward t]
2607         ["Search articles backward..." gnus-summary-search-article-backward t]
2608         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2609         ["Expand window" gnus-summary-expand-window t]
2610         ["Expire expirable articles" gnus-summary-expire-articles
2611          (gnus-check-backend-function
2612           'request-expire-articles gnus-newsgroup-name)]
2613         ["Edit local kill file" gnus-summary-edit-local-kill t]
2614         ["Edit main kill file" gnus-summary-edit-global-kill t]
2615         ["Edit group parameters" gnus-summary-edit-parameters t]
2616         ["Customize group parameters" gnus-summary-customize-parameters t]
2617         ["Send a bug report" gnus-bug t]
2618         ("Exit"
2619          ["Catchup and exit" gnus-summary-catchup-and-exit
2620           ,@(if (featurep 'xemacs) '(t)
2621               '(:help "Mark unread articles in this group as read, then exit"))]
2622          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2623          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2624          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2625          ["Exit group" gnus-summary-exit
2626           ,@(if (featurep 'xemacs) '(t)
2627               '(:help "Exit current group, return to group selection mode"))]
2628          ["Exit group without updating" gnus-summary-exit-no-update t]
2629          ["Exit and goto next group" gnus-summary-next-group t]
2630          ["Exit and goto prev group" gnus-summary-prev-group t]
2631          ["Reselect group" gnus-summary-reselect-current-group t]
2632          ["Rescan group" gnus-summary-rescan-group t]
2633          ["Update dribble" gnus-summary-save-newsrc t])))
2634
2635     (gnus-run-hooks 'gnus-summary-menu-hook)))
2636
2637 (defvar gnus-summary-tool-bar-map nil)
2638
2639 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2640 ;; affect _new_ message buffers.  We might add a function that walks thru all
2641 ;; message-mode buffers and force the update.
2642 (defun gnus-summary-tool-bar-update (&optional symbol value)
2643   "Update summary mode toolbar.
2644 Setter function for custom variables."
2645   (if symbol
2646       ;; When used as ":set" function:
2647       (progn
2648         (set-default symbol value)
2649         (setq-default gnus-summary-tool-bar-map nil))
2650     (gnus-summary-make-tool-bar t)))
2651
2652 ;; The default will be changed when the new icons have been checked in:
2653 (defcustom gnus-summary-tool-bar 'gnus-summary-tool-bar-retro
2654   "Specifies the Gnus summary tool bar.
2655
2656 It can be either a list or a symbol refering to a list.  See
2657 `gmm-tool-bar-from-list' for the format of the list.  The
2658 default key map is `gnus-summary-mode-map'.
2659
2660 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2661 `gnus-summary-tool-bar-retro'."
2662   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2663                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2664                  (repeat :tag "User defined list" gmm-tool-bar-item)
2665                  (symbol))
2666   :version "23.0" ;; No Gnus
2667   :initialize 'custom-initialize-default
2668   :set 'gnus-summary-tool-bar-update
2669   :group 'gnus-summary)
2670
2671 (defcustom gnus-summary-tool-bar-gnome
2672   '((gnus-summary-post-news "compose" nil)
2673     (gnus-summary-reply-with-original "reply-author")
2674     (gnus-summary-reply "reply" nil :visible nil)
2675     (gnus-summary-followup-with-original "reply-all")
2676     (gnus-summary-followup "reply-all" nil :visible nil)
2677     (gnus-summary-mail-forward "forward")
2678     (gnus-summary-save-article "save") ;;  stock_mail-copy
2679     (gnus-summary-search-article-forward "search")
2680     (gnus-summary-print-article "print")
2681     ;; gnus-group-read-only-p
2682     (gnus-summary-mark-as-expirable
2683      "delete" nil
2684      :visible (gnus-check-backend-function 'request-expire-articles
2685                                            gnus-newsgroup-name))
2686     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2687     (gnus-summary-mark-as-spam
2688      "spam" t :visible (spam-group-ham-contents-p gnus-newsgroup-name)
2689      :help "Mark as spam")
2690     (gnus-summary-mark-as-read-forward
2691      "not-spam" nil :visible (spam-group-spam-contents-p gnus-newsgroup-name))
2692     ;; Some new commands that may need more suitable icons:
2693     (gnus-summary-save-newsrc "save" nil :visible nil)
2694     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2695     (gnus-summary-prev-article "left-arrow" nil :visible nil)  ;; Emacs 22
2696     (gnus-summary-next-article "right-arrow" nil :visible nil) ;; Emacs 22
2697     (gnus-summary-prev-unread-article "prev-node") ;; Emacs 22
2698     (gnus-summary-next-unread-article "next-node") ;; Emacs 22
2699     (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2700     ;;
2701     ;; Maybe some sort-by-... could be added:
2702     (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2703     (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2704     ;;
2705     (gnus-summary-insert-new-articles "inbox")
2706     ;;
2707     (gnus-summary-exit "exit-mode")
2708     ;;
2709     (gnus-info-find-node "help"))
2710   "List of functions for the summary tool bar (GNOME style).
2711
2712 See `gmm-tool-bar-from-list' for the format of the list."
2713   :type '(repeat gmm-tool-bar-item)
2714   :version "23.0" ;; No Gnus
2715   :initialize 'custom-initialize-default
2716   :set 'gnus-summary-tool-bar-update
2717   :group 'gnus-summary)
2718
2719 (defcustom gnus-summary-tool-bar-retro
2720   '((gnus-summary-prev-unread-article "prev-ur")
2721     (gnus-summary-next-unread-article "next-ur")
2722     (gnus-summary-post-news "post")
2723     (gnus-summary-followup-with-original "fuwo")
2724     (gnus-summary-followup "followup")
2725     (gnus-summary-reply-with-original "reply-wo")
2726     (gnus-summary-reply "reply")
2727     (gnus-summary-caesar-message "rot13")
2728     (gnus-uu-decode-uu "uu-decode")
2729     (gnus-summary-save-article-file "save-aif")
2730     (gnus-summary-save-article "save-art")
2731     (gnus-uu-post-news "uu-post")
2732     (gnus-summary-catchup "catchup")
2733     (gnus-summary-catchup-and-exit "cu-exit")
2734     (gnus-summary-exit "exit-summ")
2735     ;; Some new command that may need more suitable icons:
2736     (gnus-summary-print-article "print" nil :visible nil)
2737     (gnus-summary-mark-as-expirable "close" nil :visible nil)
2738     (gnus-summary-save-newsrc "save" nil :visible nil)
2739     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2740     (gnus-summary-search-article-forward "search" nil :visible nil)
2741     ;; (gnus-summary-insert-new-articles "paste" nil :visible nil)
2742     ;; (gnus-summary-toggle-threads "open" nil :visible nil)
2743     ;;
2744     (gnus-info-find-node "help" nil :visible nil))
2745   "List of functions for the summary tool bar (retro look).
2746
2747 See `gmm-tool-bar-from-list' for the format of the list."
2748   :type '(repeat gmm-tool-bar-item)
2749   :version "23.0" ;; No Gnus
2750   :initialize 'custom-initialize-default
2751   :set 'gnus-summary-tool-bar-update
2752   :group 'gnus-summary)
2753
2754 (defcustom gnus-summary-tool-bar-zap-list t
2755   "List of icon items from the global tool bar.
2756 These items are not displayed in the Gnus summary mode tool bar.
2757
2758 See `gmm-tool-bar-from-list' for the format of the list."
2759   :type 'gmm-tool-bar-zap-list
2760   :version "23.0" ;; No Gnus
2761   :initialize 'custom-initialize-default
2762   :set 'gnus-summary-tool-bar-update
2763   :group 'gnus-summary)
2764
2765 (defun gnus-summary-make-tool-bar (&optional force)
2766   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2767 When FORCE, rebuild the tool bar."
2768   (when (or (not gnus-summary-tool-bar-map) force)
2769     (let ((map (when (default-value 'tool-bar-mode)
2770                  (let ((load-path (mm-image-load-path)))
2771                    (gmm-tool-bar-from-list gnus-summary-tool-bar
2772                                                gnus-summary-tool-bar-zap-list
2773                                                'gnus-summary-mode-map)))))
2774       (when map
2775         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2776         ;; uses it's value.
2777         (setq gnus-summary-tool-bar-map map))))
2778   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2779
2780 (defun gnus-score-set-default (var value)
2781   "A version of set that updates the GNU Emacs menu-bar."
2782   (set var value)
2783   ;; It is the message that forces the active status to be updated.
2784   (message ""))
2785
2786 (defun gnus-make-score-map (type)
2787   "Make a summary score map of type TYPE."
2788   (if t
2789       nil
2790     (let ((headers '(("author" "from" string)
2791                      ("subject" "subject" string)
2792                      ("article body" "body" string)
2793                      ("article head" "head" string)
2794                      ("xref" "xref" string)
2795                      ("extra header" "extra" string)
2796                      ("lines" "lines" number)
2797                      ("followups to author" "followup" string)))
2798           (types '((number ("less than" <)
2799                            ("greater than" >)
2800                            ("equal" =))
2801                    (string ("substring" s)
2802                            ("exact string" e)
2803                            ("fuzzy string" f)
2804                            ("regexp" r))))
2805           (perms '(("temporary" (current-time-string))
2806                    ("permanent" nil)
2807                    ("immediate" now)))
2808           header)
2809       (list
2810        (apply
2811         'nconc
2812         (list
2813          (if (eq type 'lower)
2814              "Lower score"
2815            "Increase score"))
2816         (let (outh)
2817           (while headers
2818             (setq header (car headers))
2819             (setq outh
2820                   (cons
2821                    (apply
2822                     'nconc
2823                     (list (car header))
2824                     (let ((ts (cdr (assoc (nth 2 header) types)))
2825                           outt)
2826                       (while ts
2827                         (setq outt
2828                               (cons
2829                                (apply
2830                                 'nconc
2831                                 (list (caar ts))
2832                                 (let ((ps perms)
2833                                       outp)
2834                                   (while ps
2835                                     (setq outp
2836                                           (cons
2837                                            (vector
2838                                             (caar ps)
2839                                             (list
2840                                              'gnus-summary-score-entry
2841                                              (nth 1 header)
2842                                              (if (or (string= (nth 1 header)
2843                                                               "head")
2844                                                      (string= (nth 1 header)
2845                                                               "body"))
2846                                                  ""
2847                                                (list 'gnus-summary-header
2848                                                      (nth 1 header)))
2849                                              (list 'quote (nth 1 (car ts)))
2850                                              (list 'gnus-score-delta-default
2851                                                    nil)
2852                                              (nth 1 (car ps))
2853                                              t)
2854                                             t)
2855                                            outp))
2856                                     (setq ps (cdr ps)))
2857                                   (list (nreverse outp))))
2858                                outt))
2859                         (setq ts (cdr ts)))
2860                       (list (nreverse outt))))
2861                    outh))
2862             (setq headers (cdr headers)))
2863           (list (nreverse outh))))))))
2864
2865 \f
2866
2867 (defun gnus-summary-mode (&optional group)
2868   "Major mode for reading articles.
2869
2870 All normal editing commands are switched off.
2871 \\<gnus-summary-mode-map>
2872 Each line in this buffer represents one article.  To read an
2873 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2874 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2875 respectively.
2876
2877 You can also post articles and send mail from this buffer.  To
2878 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2879 of an article, type `\\[gnus-summary-reply]'.
2880
2881 There are approx. one gazillion commands you can execute in this
2882 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2883
2884 The following commands are available:
2885
2886 \\{gnus-summary-mode-map}"
2887   (interactive)
2888   (kill-all-local-variables)
2889   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2890     (gnus-summary-make-local-variables))
2891   (gnus-summary-make-local-variables)
2892   (setq gnus-newsgroup-name group)
2893   (when (gnus-visual-p 'summary-menu 'menu)
2894     (gnus-summary-make-menu-bar)
2895     (gnus-summary-make-tool-bar))
2896   (gnus-make-thread-indent-array)
2897   (gnus-simplify-mode-line)
2898   (setq major-mode 'gnus-summary-mode)
2899   (setq mode-name "Summary")
2900   (make-local-variable 'minor-mode-alist)
2901   (use-local-map gnus-summary-mode-map)
2902   (buffer-disable-undo)
2903   (setq buffer-read-only t              ;Disable modification
2904         show-trailing-whitespace nil)
2905   (setq truncate-lines t)
2906   (setq selective-display t)
2907   (setq selective-display-ellipses t)   ;Display `...'
2908   (gnus-summary-set-display-table)
2909   (gnus-set-default-directory)
2910   (make-local-variable 'gnus-summary-line-format)
2911   (make-local-variable 'gnus-summary-line-format-spec)
2912   (make-local-variable 'gnus-summary-dummy-line-format)
2913   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2914   (make-local-variable 'gnus-summary-mark-positions)
2915   (gnus-make-local-hook 'pre-command-hook)
2916   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2917   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2918   (turn-on-gnus-mailing-list-mode)
2919   (mm-enable-multibyte)
2920   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2921   (gnus-update-summary-mark-positions))
2922
2923 (defun gnus-summary-make-local-variables ()
2924   "Make all the local summary buffer variables."
2925   (let (global)
2926     (dolist (local gnus-summary-local-variables)
2927       (if (consp local)
2928           (progn
2929             (if (eq (cdr local) 'global)
2930                 ;; Copy the global value of the variable.
2931                 (setq global (symbol-value (car local)))
2932               ;; Use the value from the list.
2933               (setq global (eval (cdr local))))
2934             (set (make-local-variable (car local)) global))
2935         ;; Simple nil-valued local variable.
2936         (set (make-local-variable local) nil)))))
2937
2938 (defun gnus-summary-clear-local-variables ()
2939   (let ((locals gnus-summary-local-variables))
2940     (while locals
2941       (if (consp (car locals))
2942           (and (symbolp (caar locals))
2943                (set (caar locals) nil))
2944         (and (symbolp (car locals))
2945              (set (car locals) nil)))
2946       (setq locals (cdr locals)))))
2947
2948 ;; Summary data functions.
2949
2950 (defmacro gnus-data-number (data)
2951   `(car ,data))
2952
2953 (defmacro gnus-data-set-number (data number)
2954   `(setcar ,data ,number))
2955
2956 (defmacro gnus-data-mark (data)
2957   `(nth 1 ,data))
2958
2959 (defmacro gnus-data-set-mark (data mark)
2960   `(setcar (nthcdr 1 ,data) ,mark))
2961
2962 (defmacro gnus-data-pos (data)
2963   `(nth 2 ,data))
2964
2965 (defmacro gnus-data-set-pos (data pos)
2966   `(setcar (nthcdr 2 ,data) ,pos))
2967
2968 (defmacro gnus-data-header (data)
2969   `(nth 3 ,data))
2970
2971 (defmacro gnus-data-set-header (data header)
2972   `(setf (nth 3 ,data) ,header))
2973
2974 (defmacro gnus-data-level (data)
2975   `(nth 4 ,data))
2976
2977 (defmacro gnus-data-unread-p (data)
2978   `(= (nth 1 ,data) gnus-unread-mark))
2979
2980 (defmacro gnus-data-read-p (data)
2981   `(/= (nth 1 ,data) gnus-unread-mark))
2982
2983 (defmacro gnus-data-pseudo-p (data)
2984   `(consp (nth 3 ,data)))
2985
2986 (defmacro gnus-data-find (number)
2987   `(assq ,number gnus-newsgroup-data))
2988
2989 (defmacro gnus-data-find-list (number &optional data)
2990   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2991      (memq (assq ,number bdata)
2992            bdata)))
2993
2994 (defmacro gnus-data-make (number mark pos header level)
2995   `(list ,number ,mark ,pos ,header ,level))
2996
2997 (defun gnus-data-enter (after-article number mark pos header level offset)
2998   (let ((data (gnus-data-find-list after-article)))
2999     (unless data
3000       (error "No such article: %d" after-article))
3001     (setcdr data (cons (gnus-data-make number mark pos header level)
3002                        (cdr data)))
3003     (setq gnus-newsgroup-data-reverse nil)
3004     (gnus-data-update-list (cddr data) offset)))
3005
3006 (defun gnus-data-enter-list (after-article list &optional offset)
3007   (when list
3008     (let ((data (and after-article (gnus-data-find-list after-article)))
3009           (ilist list))
3010       (if (not (or data
3011                    after-article))
3012           (let ((odata gnus-newsgroup-data))
3013             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3014             (when offset
3015               (gnus-data-update-list odata offset)))
3016         ;; Find the last element in the list to be spliced into the main
3017         ;; list.
3018         (setq list (last list))
3019         (if (not data)
3020             (progn
3021               (setcdr list gnus-newsgroup-data)
3022               (setq gnus-newsgroup-data ilist)
3023               (when offset
3024                 (gnus-data-update-list (cdr list) offset)))
3025           (setcdr list (cdr data))
3026           (setcdr data ilist)
3027           (when offset
3028             (gnus-data-update-list (cdr list) offset))))
3029       (setq gnus-newsgroup-data-reverse nil))))
3030
3031 (defun gnus-data-remove (article &optional offset)
3032   (let ((data gnus-newsgroup-data))
3033     (if (= (gnus-data-number (car data)) article)
3034         (progn
3035           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3036                 gnus-newsgroup-data-reverse nil)
3037           (when offset
3038             (gnus-data-update-list gnus-newsgroup-data offset)))
3039       (while (cdr data)
3040         (when (= (gnus-data-number (cadr data)) article)
3041           (setcdr data (cddr data))
3042           (when offset
3043             (gnus-data-update-list (cdr data) offset))
3044           (setq data nil
3045                 gnus-newsgroup-data-reverse nil))
3046         (setq data (cdr data))))))
3047
3048 (defmacro gnus-data-list (backward)
3049   `(if ,backward
3050        (or gnus-newsgroup-data-reverse
3051            (setq gnus-newsgroup-data-reverse
3052                  (reverse gnus-newsgroup-data)))
3053      gnus-newsgroup-data))
3054
3055 (defun gnus-data-update-list (data offset)
3056   "Add OFFSET to the POS of all data entries in DATA."
3057   (setq gnus-newsgroup-data-reverse nil)
3058   (while data
3059     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3060     (setq data (cdr data))))
3061
3062 (defun gnus-summary-article-pseudo-p (article)
3063   "Say whether this article is a pseudo article or not."
3064   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3065
3066 (defmacro gnus-summary-article-sparse-p (article)
3067   "Say whether this article is a sparse article or not."
3068   `(memq ,article gnus-newsgroup-sparse))
3069
3070 (defmacro gnus-summary-article-ancient-p (article)
3071   "Say whether this article is a sparse article or not."
3072   `(memq ,article gnus-newsgroup-ancient))
3073
3074 (defun gnus-article-parent-p (number)
3075   "Say whether this article is a parent or not."
3076   (let ((data (gnus-data-find-list number)))
3077     (and (cdr data)              ; There has to be an article after...
3078          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3079             (gnus-data-level (nth 1 data))))))
3080
3081 (defun gnus-article-children (number)
3082   "Return a list of all children to NUMBER."
3083   (let* ((data (gnus-data-find-list number))
3084          (level (gnus-data-level (car data)))
3085          children)
3086     (setq data (cdr data))
3087     (while (and data
3088                 (= (gnus-data-level (car data)) (1+ level)))
3089       (push (gnus-data-number (car data)) children)
3090       (setq data (cdr data)))
3091     children))
3092
3093 (defmacro gnus-summary-skip-intangible ()
3094   "If the current article is intangible, then jump to a different article."
3095   '(let ((to (get-text-property (point) 'gnus-intangible)))
3096      (and to (gnus-summary-goto-subject to))))
3097
3098 (defmacro gnus-summary-article-intangible-p ()
3099   "Say whether this article is intangible or not."
3100   '(get-text-property (point) 'gnus-intangible))
3101
3102 (defun gnus-article-read-p (article)
3103   "Say whether ARTICLE is read or not."
3104   (not (or (memq article gnus-newsgroup-marked)
3105            (memq article gnus-newsgroup-spam-marked)
3106            (memq article gnus-newsgroup-unreads)
3107            (memq article gnus-newsgroup-unselected)
3108            (memq article gnus-newsgroup-dormant))))
3109
3110 ;; Some summary mode macros.
3111
3112 (defmacro gnus-summary-article-number ()
3113   "The article number of the article on the current line.
3114 If there isn't an article number here, then we return the current
3115 article number."
3116   '(progn
3117      (gnus-summary-skip-intangible)
3118      (or (get-text-property (point) 'gnus-number)
3119          (gnus-summary-last-subject))))
3120
3121 (defmacro gnus-summary-article-header (&optional number)
3122   "Return the header of article NUMBER."
3123   `(gnus-data-header (gnus-data-find
3124                       ,(or number '(gnus-summary-article-number)))))
3125
3126 (defmacro gnus-summary-thread-level (&optional number)
3127   "Return the level of thread that starts with article NUMBER."
3128   `(if (and (eq gnus-summary-make-false-root 'dummy)
3129             (get-text-property (point) 'gnus-intangible))
3130        0
3131      (gnus-data-level (gnus-data-find
3132                        ,(or number '(gnus-summary-article-number))))))
3133
3134 (defmacro gnus-summary-article-mark (&optional number)
3135   "Return the mark of article NUMBER."
3136   `(gnus-data-mark (gnus-data-find
3137                     ,(or number '(gnus-summary-article-number)))))
3138
3139 (defmacro gnus-summary-article-pos (&optional number)
3140   "Return the position of the line of article NUMBER."
3141   `(gnus-data-pos (gnus-data-find
3142                    ,(or number '(gnus-summary-article-number)))))
3143
3144 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3145 (defmacro gnus-summary-article-subject (&optional number)
3146   "Return current subject string or nil if nothing."
3147   `(let ((headers
3148           ,(if number
3149                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3150              '(gnus-data-header (assq (gnus-summary-article-number)
3151                                       gnus-newsgroup-data)))))
3152      (and headers
3153           (vectorp headers)
3154           (mail-header-subject headers))))
3155
3156 (defmacro gnus-summary-article-score (&optional number)
3157   "Return current article score."
3158   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3159                   gnus-newsgroup-scored))
3160        gnus-summary-default-score 0))
3161
3162 (defun gnus-summary-article-children (&optional number)
3163   "Return a list of article numbers that are children of article NUMBER."
3164   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3165          (level (gnus-data-level (car data)))
3166          l children)
3167     (while (and (setq data (cdr data))
3168                 (> (setq l (gnus-data-level (car data))) level))
3169       (and (= (1+ level) l)
3170            (push (gnus-data-number (car data))
3171                  children)))
3172     (nreverse children)))
3173
3174 (defun gnus-summary-article-parent (&optional number)
3175   "Return the article number of the parent of article NUMBER."
3176   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3177                                     (gnus-data-list t)))
3178          (level (gnus-data-level (car data))))
3179     (if (zerop level)
3180         ()                              ; This is a root.
3181       ;; We search until we find an article with a level less than
3182       ;; this one.  That function has to be the parent.
3183       (while (and (setq data (cdr data))
3184                   (not (< (gnus-data-level (car data)) level))))
3185       (and data (gnus-data-number (car data))))))
3186
3187 (defun gnus-unread-mark-p (mark)
3188   "Say whether MARK is the unread mark."
3189   (= mark gnus-unread-mark))
3190
3191 (defun gnus-read-mark-p (mark)
3192   "Say whether MARK is one of the marks that mark as read.
3193 This is all marks except unread, ticked, dormant, and expirable."
3194   (not (or (= mark gnus-unread-mark)
3195            (= mark gnus-ticked-mark)
3196            (= mark gnus-spam-mark)
3197            (= mark gnus-dormant-mark)
3198            (= mark gnus-expirable-mark))))
3199
3200 (defmacro gnus-article-mark (number)
3201   "Return the MARK of article NUMBER.
3202 This macro should only be used when computing the mark the \"first\"
3203 time; i.e., when generating the summary lines.  After that,
3204 `gnus-summary-article-mark' should be used to examine the
3205 marks of articles."
3206   `(cond
3207     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3208     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3209     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3210     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3211     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3212     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3213     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3214     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3215            gnus-ancient-mark))))
3216
3217 ;; Saving hidden threads.
3218
3219 (defmacro gnus-save-hidden-threads (&rest forms)
3220   "Save hidden threads, eval FORMS, and restore the hidden threads."
3221   (let ((config (make-symbol "config")))
3222     `(let ((,config (gnus-hidden-threads-configuration)))
3223        (unwind-protect
3224            (save-excursion
3225              ,@forms)
3226          (gnus-restore-hidden-threads-configuration ,config)))))
3227 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3228 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3229
3230 (defun gnus-data-compute-positions ()
3231   "Compute the positions of all articles."
3232   (setq gnus-newsgroup-data-reverse nil)
3233   (let ((data gnus-newsgroup-data))
3234     (save-excursion
3235       (gnus-save-hidden-threads
3236         (gnus-summary-show-all-threads)
3237         (goto-char (point-min))
3238         (while data
3239           (while (get-text-property (point) 'gnus-intangible)
3240             (forward-line 1))
3241           (gnus-data-set-pos (car data) (+ (point) 3))
3242           (setq data (cdr data))
3243           (forward-line 1))))))
3244
3245 (defun gnus-hidden-threads-configuration ()
3246   "Return the current hidden threads configuration."
3247   (save-excursion
3248     (let (config)
3249       (goto-char (point-min))
3250       (while (search-forward "\r" nil t)
3251         (push (1- (point)) config))
3252       config)))
3253
3254 (defun gnus-restore-hidden-threads-configuration (config)
3255   "Restore hidden threads configuration from CONFIG."
3256   (save-excursion
3257     (let (point buffer-read-only)
3258       (while (setq point (pop config))
3259         (when (and (< point (point-max))
3260                    (goto-char point)
3261                    (eq (char-after) ?\n))
3262           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3263
3264 ;; Various summary mode internalish functions.
3265
3266 (defun gnus-mouse-pick-article (e)
3267   (interactive "e")
3268   (mouse-set-point e)
3269   (gnus-summary-next-page nil t))
3270
3271 (defun gnus-summary-set-display-table ()
3272   "Change the display table.
3273 Odd characters have a tendency to mess
3274 up nicely formatted displays - we make all possible glyphs
3275 display only a single character."
3276
3277   ;; We start from the standard display table, if any.
3278   (let ((table (or (copy-sequence standard-display-table)
3279                    (make-display-table)))
3280         (i 32))
3281     ;; Nix out all the control chars...
3282     (while (>= (setq i (1- i)) 0)
3283       (aset table i [??]))
3284    ;; ... but not newline and cr, of course.  (cr is necessary for the
3285     ;; selective display).
3286     (aset table ?\n nil)
3287     (aset table ?\r nil)
3288     ;; We keep TAB as well.
3289     (aset table ?\t nil)
3290     ;; We nix out any glyphs over 126 that are not set already.
3291     (let ((i 256))
3292       (while (>= (setq i (1- i)) 127)
3293         ;; Only modify if the entry is nil.
3294         (unless (aref table i)
3295           (aset table i [??]))))
3296     (setq buffer-display-table table)))
3297
3298 (defun gnus-summary-set-article-display-arrow (pos)
3299   "Update the overlay arrow to point to line at position POS."
3300   (when (and gnus-summary-display-arrow
3301              (boundp 'overlay-arrow-position)
3302              (boundp 'overlay-arrow-string))
3303     (save-excursion
3304       (goto-char pos)
3305       (beginning-of-line)
3306       (unless overlay-arrow-position
3307         (setq overlay-arrow-position (make-marker)))
3308       (setq overlay-arrow-string "=>"
3309             overlay-arrow-position (set-marker overlay-arrow-position
3310                                                (point)
3311                                                (current-buffer))))))
3312
3313 (defun gnus-summary-setup-buffer (group)
3314   "Initialize summary buffer."
3315   (let ((buffer (gnus-summary-buffer-name group))
3316         (dead-name (concat "*Dead Summary "
3317                            (gnus-group-decoded-name group) "*")))
3318     ;; If a dead summary buffer exists, we kill it.
3319     (when (gnus-buffer-live-p dead-name)
3320       (gnus-kill-buffer dead-name))
3321     (if (get-buffer buffer)
3322         (progn
3323           (set-buffer buffer)
3324           (setq gnus-summary-buffer (current-buffer))
3325           (not gnus-newsgroup-prepared))
3326       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3327       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3328       (gnus-summary-mode group)
3329       (when gnus-carpal
3330         (gnus-carpal-setup-buffer 'summary))
3331       (unless gnus-single-article-buffer
3332         (make-local-variable 'gnus-article-buffer)
3333         (make-local-variable 'gnus-article-current)
3334         (make-local-variable 'gnus-original-article-buffer))
3335       (setq gnus-newsgroup-name group)
3336       ;; Set any local variables in the group parameters.
3337       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3338       t)))
3339
3340 (defun gnus-set-global-variables ()
3341   "Set the global equivalents of the buffer-local variables.
3342 They are set to the latest values they had.  These reflect the summary
3343 buffer that was in action when the last article was fetched."
3344   (when (eq major-mode 'gnus-summary-mode)
3345     (setq gnus-summary-buffer (current-buffer))
3346     (let ((name gnus-newsgroup-name)
3347           (marked gnus-newsgroup-marked)
3348           (spam gnus-newsgroup-spam-marked)
3349           (unread gnus-newsgroup-unreads)
3350           (headers gnus-current-headers)
3351           (data gnus-newsgroup-data)
3352           (summary gnus-summary-buffer)
3353           (article-buffer gnus-article-buffer)
3354           (original gnus-original-article-buffer)
3355           (gac gnus-article-current)
3356           (reffed gnus-reffed-article-number)
3357           (score-file gnus-current-score-file)
3358           (default-charset gnus-newsgroup-charset)
3359           vlist)
3360       (let ((locals gnus-newsgroup-variables))
3361         (while locals
3362           (if (consp (car locals))
3363               (push (eval (caar locals)) vlist)
3364             (push (eval (car locals)) vlist))
3365           (setq locals (cdr locals)))
3366         (setq vlist (nreverse vlist)))
3367       (with-current-buffer gnus-group-buffer
3368         (setq gnus-newsgroup-name name
3369               gnus-newsgroup-marked marked
3370               gnus-newsgroup-spam-marked spam
3371               gnus-newsgroup-unreads unread
3372               gnus-current-headers headers
3373               gnus-newsgroup-data data
3374               gnus-article-current gac
3375               gnus-summary-buffer summary
3376               gnus-article-buffer article-buffer
3377               gnus-original-article-buffer original
3378               gnus-reffed-article-number reffed
3379               gnus-current-score-file score-file
3380               gnus-newsgroup-charset default-charset)
3381         (let ((locals gnus-newsgroup-variables))
3382           (while locals
3383             (if (consp (car locals))
3384                 (set (caar locals) (pop vlist))
3385               (set (car locals) (pop vlist)))
3386             (setq locals (cdr locals))))
3387         ;; The article buffer also has local variables.
3388         (when (gnus-buffer-live-p gnus-article-buffer)
3389           (set-buffer gnus-article-buffer)
3390           (setq gnus-summary-buffer summary))))))
3391
3392 (defun gnus-summary-article-unread-p (article)
3393   "Say whether ARTICLE is unread or not."
3394   (memq article gnus-newsgroup-unreads))
3395
3396 (defun gnus-summary-first-article-p (&optional article)
3397   "Return whether ARTICLE is the first article in the buffer."
3398   (if (not (setq article (or article (gnus-summary-article-number))))
3399       nil
3400     (eq article (caar gnus-newsgroup-data))))
3401
3402 (defun gnus-summary-last-article-p (&optional article)
3403   "Return whether ARTICLE is the last article in the buffer."
3404   (if (not (setq article (or article (gnus-summary-article-number))))
3405       ;; All non-existent numbers are the last article.  :-)
3406       t
3407     (not (cdr (gnus-data-find-list article)))))
3408
3409 (defun gnus-make-thread-indent-array ()
3410   (let ((n 200))
3411     (unless (and gnus-thread-indent-array
3412                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3413       (setq gnus-thread-indent-array (make-vector 201 "")
3414             gnus-thread-indent-array-level gnus-thread-indent-level)
3415       (while (>= n 0)
3416         (aset gnus-thread-indent-array n
3417               (make-string (* n gnus-thread-indent-level) ? ))
3418         (setq n (1- n))))))
3419
3420 (defun gnus-update-summary-mark-positions ()
3421   "Compute where the summary marks are to go."
3422   (save-excursion
3423     (when (gnus-buffer-exists-p gnus-summary-buffer)
3424       (set-buffer gnus-summary-buffer))
3425     (let ((spec gnus-summary-line-format-spec)
3426           pos)
3427       (save-excursion
3428         (gnus-set-work-buffer)
3429         (let ((gnus-tmp-unread ?Z)
3430               (gnus-replied-mark ?Z)
3431               (gnus-score-below-mark ?Z)
3432               (gnus-score-over-mark ?Z)
3433               (gnus-undownloaded-mark ?Z)
3434               (gnus-summary-line-format-spec spec)
3435               (gnus-newsgroup-downloadable '(0))
3436               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3437               case-fold-search ignores)
3438           ;; Here, all marks are bound to Z.
3439           (gnus-summary-insert-line header
3440                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3441           (goto-char (point-min))
3442           ;; Memorize the positions of the same characters as dummy marks.
3443           (while (re-search-forward "[A-D]" nil t)
3444             (push (point) ignores))
3445           (erase-buffer)
3446           ;; We use A-D as dummy marks in order to know column positions
3447           ;; where marks should be inserted.
3448           (setq gnus-tmp-unread ?A
3449                 gnus-replied-mark ?B
3450                 gnus-score-below-mark ?C
3451                 gnus-score-over-mark ?C
3452                 gnus-undownloaded-mark ?D)
3453           (gnus-summary-insert-line header
3454                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3455           ;; Ignore characters which aren't dummy marks.
3456           (dolist (p ignores)
3457             (delete-region (goto-char (1- p)) p)
3458             (insert ?Z))
3459           (goto-char (point-min))
3460           (setq pos (list (cons 'unread
3461                                 (and (search-forward "A" nil t)
3462                                      (- (point) (point-min) 1)))))
3463           (goto-char (point-min))
3464           (push (cons 'replied (and (search-forward "B" nil t)
3465                                     (- (point) (point-min) 1)))
3466                 pos)
3467           (goto-char (point-min))
3468           (push (cons 'score (and (search-forward "C" nil t)
3469                                   (- (point) (point-min) 1)))
3470                 pos)
3471           (goto-char (point-min))
3472           (push (cons 'download (and (search-forward "D" nil t)
3473                                      (- (point) (point-min) 1)))
3474                 pos)))
3475       (setq gnus-summary-mark-positions pos))))
3476
3477 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3478   "Insert a dummy root in the summary buffer."
3479   (beginning-of-line)
3480   (gnus-add-text-properties
3481    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3482    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3483
3484 (defun gnus-summary-extract-address-component (from)
3485   (or (car (funcall gnus-extract-address-components from))
3486       from))
3487
3488 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3489   (let ((mail-parse-charset gnus-newsgroup-charset)
3490         ; Is it really necessary to do this next part for each summary line?
3491         ; Luckily, doesn't seem to slow things down much.
3492         (mail-parse-ignored-charsets
3493          (with-current-buffer gnus-summary-buffer
3494            gnus-newsgroup-ignored-charsets)))
3495     (or
3496      (and gnus-ignored-from-addresses
3497           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3498           (let ((extra-headers (mail-header-extra header))
3499                 to
3500                 newsgroups)
3501             (cond
3502              ((setq to (cdr (assq 'To extra-headers)))
3503               (concat gnus-summary-to-prefix
3504                       (inline
3505                         (gnus-summary-extract-address-component
3506                          (funcall gnus-decode-encoded-word-function to)))))
3507              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3508               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3509      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3510
3511 (defun gnus-summary-insert-line (gnus-tmp-header
3512                                  gnus-tmp-level gnus-tmp-current
3513                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3514                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3515                                  &optional gnus-tmp-dummy gnus-tmp-score
3516                                  gnus-tmp-process)
3517   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3518          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3519          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3520          (gnus-tmp-score-char
3521           (if (or (null gnus-summary-default-score)
3522                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3523                       gnus-summary-zcore-fuzz))
3524               ?                         ;Whitespace
3525             (if (< gnus-tmp-score gnus-summary-default-score)
3526                 gnus-score-below-mark gnus-score-over-mark)))
3527          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3528          (gnus-tmp-replied
3529           (cond (gnus-tmp-process gnus-process-mark)
3530                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3531                  gnus-cached-mark)
3532                 (gnus-tmp-replied gnus-replied-mark)
3533                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3534                  gnus-forwarded-mark)
3535                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3536                  gnus-saved-mark)
3537                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3538                  gnus-recent-mark)
3539                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3540                  gnus-unseen-mark)
3541                 (t gnus-no-mark)))
3542          (gnus-tmp-downloaded
3543           (cond (undownloaded
3544                  gnus-undownloaded-mark)
3545                 (gnus-newsgroup-agentized
3546                  gnus-downloaded-mark)
3547                 (t
3548                  gnus-no-mark)))
3549          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3550          (gnus-tmp-name
3551           (cond
3552            ((string-match "<[^>]+> *$" gnus-tmp-from)
3553             (let ((beg (match-beginning 0)))
3554               (or (and (string-match "^\".+\"" gnus-tmp-from)
3555                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3556                   (substring gnus-tmp-from 0 beg))))
3557            ((string-match "(.+)" gnus-tmp-from)
3558             (substring gnus-tmp-from
3559                        (1+ (match-beginning 0)) (1- (match-end 0))))
3560            (t gnus-tmp-from)))
3561          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3562          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3563          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3564          (buffer-read-only nil))
3565     (when (string= gnus-tmp-name "")
3566       (setq gnus-tmp-name gnus-tmp-from))
3567     (unless (numberp gnus-tmp-lines)
3568       (setq gnus-tmp-lines -1))
3569     (if (= gnus-tmp-lines -1)
3570         (setq gnus-tmp-lines "?")
3571       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3572       (gnus-put-text-property
3573      (point)
3574      (progn (eval gnus-summary-line-format-spec) (point))
3575        'gnus-number gnus-tmp-number)
3576     (when (gnus-visual-p 'summary-highlight 'highlight)
3577       (forward-line -1)
3578       (gnus-run-hooks 'gnus-summary-update-hook)
3579       (forward-line 1))))
3580
3581 (defun gnus-summary-update-line (&optional dont-update)
3582   "Update summary line after change."
3583   (when (and gnus-summary-default-score
3584              (not gnus-summary-inhibit-highlight))
3585     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3586            (article (gnus-summary-article-number))
3587            (score (gnus-summary-article-score article)))
3588       (unless dont-update
3589         (if (and gnus-summary-mark-below
3590                  (< (gnus-summary-article-score)
3591                     gnus-summary-mark-below))
3592             ;; This article has a low score, so we mark it as read.
3593             (when (memq article gnus-newsgroup-unreads)
3594               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3595           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3596             ;; This article was previously marked as read on account
3597             ;; of a low score, but now it has risen, so we mark it as
3598             ;; unread.
3599             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3600         (gnus-summary-update-mark
3601          (if (or (null gnus-summary-default-score)
3602                  (<= (abs (- score gnus-summary-default-score))
3603                      gnus-summary-zcore-fuzz))
3604              ?                          ;Whitespace
3605            (if (< score gnus-summary-default-score)
3606                gnus-score-below-mark gnus-score-over-mark))
3607          'score))
3608       ;; Do visual highlighting.
3609       (when (gnus-visual-p 'summary-highlight 'highlight)
3610         (gnus-run-hooks 'gnus-summary-update-hook)))))
3611
3612 (defvar gnus-tmp-new-adopts nil)
3613
3614 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3615   "Return the number of articles in THREAD.
3616 This may be 0 in some cases -- if none of the articles in
3617 the thread are to be displayed."
3618   (let* ((number
3619          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3620           (cond
3621            ((not (listp thread))
3622             1)
3623            ((and (consp thread) (cdr thread))
3624             (apply
3625              '+ 1 (mapcar
3626                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3627            ((null thread)
3628             1)
3629            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3630             1)
3631            (t 0))))
3632     (when (and level (zerop level) gnus-tmp-new-adopts)
3633       (incf number
3634             (apply '+ (mapcar
3635                        'gnus-summary-number-of-articles-in-thread
3636                        gnus-tmp-new-adopts))))
3637     (if char
3638         (if (> number 1) gnus-not-empty-thread-mark
3639           gnus-empty-thread-mark)
3640       number)))
3641
3642 (defsubst gnus-summary-line-message-size (head)
3643   "Return pretty-printed version of message size.
3644 This function is intended to be used in
3645 `gnus-summary-line-format-alist'."
3646   (let ((c (or (mail-header-chars head) -1)))
3647     (cond ((< c 0) "n/a")               ; chars not available
3648           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3649           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3650           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3651           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3652
3653
3654 (defun gnus-summary-set-local-parameters (group)
3655   "Go through the local params of GROUP and set all variable specs in that list."
3656   (let ((vars '(quit-config)))          ; Ignore quit-config.
3657     (dolist (elem (gnus-group-find-parameter group))
3658       (and (consp elem)                 ; Has to be a cons.
3659            (consp (cdr elem))           ; The cdr has to be a list.
3660            (symbolp (car elem))         ; Has to be a symbol in there.
3661            (not (memq (car elem) vars))
3662            (ignore-errors               ; So we set it.
3663              (push (car elem) vars)
3664              (make-local-variable (car elem))
3665              (set (car elem) (eval (nth 1 elem))))))))
3666
3667 (defun gnus-summary-read-group (group &optional show-all no-article
3668                                       kill-buffer no-display backward
3669                                       select-articles)
3670   "Start reading news in newsgroup GROUP.
3671 If SHOW-ALL is non-nil, already read articles are also listed.
3672 If NO-ARTICLE is non-nil, no article is selected initially.
3673 If NO-DISPLAY, don't generate a summary buffer."
3674   (let (result)
3675     (while (and group
3676                 (null (setq result
3677                             (let ((gnus-auto-select-next nil))
3678                               (or (gnus-summary-read-group-1
3679                                    group show-all no-article
3680                                    kill-buffer no-display
3681                                    select-articles)
3682                                   (setq show-all nil
3683                                         select-articles nil)))))
3684                 (eq gnus-auto-select-next 'quietly))
3685       (set-buffer gnus-group-buffer)
3686       ;; The entry function called above goes to the next
3687       ;; group automatically, so we go two groups back
3688       ;; if we are searching for the previous group.
3689       (when backward
3690         (gnus-group-prev-unread-group 2))
3691       (if (not (equal group (gnus-group-group-name)))
3692           (setq group (gnus-group-group-name))
3693         (setq group nil)))
3694     result))
3695
3696 (defun gnus-summary-read-group-1 (group show-all no-article
3697                                         kill-buffer no-display
3698                                         &optional select-articles)
3699   ;; Killed foreign groups can't be entered.
3700   ;;  (when (and (not (gnus-group-native-p group))
3701   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3702   ;;    (error "Dead non-native groups can't be entered"))
3703   (gnus-message 5 "Retrieving newsgroup: %s..."
3704                 (gnus-group-decoded-name group))
3705   (let* ((new-group (gnus-summary-setup-buffer group))
3706          (quit-config (gnus-group-quit-config group))
3707          (did-select (and new-group (gnus-select-newsgroup
3708                                      group show-all select-articles))))
3709     (cond
3710      ;; This summary buffer exists already, so we just select it.
3711      ((not new-group)
3712       (gnus-set-global-variables)
3713       (when kill-buffer
3714         (gnus-kill-or-deaden-summary kill-buffer))
3715       (gnus-configure-windows 'summary 'force)
3716       (gnus-set-mode-line 'summary)
3717       (gnus-summary-position-point)
3718       (message "")
3719       t)
3720      ;; We couldn't select this group.
3721      ((null did-select)
3722       (when (and (eq major-mode 'gnus-summary-mode)
3723                  (not (equal (current-buffer) kill-buffer)))
3724         (kill-buffer (current-buffer))
3725         (if (not quit-config)
3726             (progn
3727               ;; Update the info -- marks might need to be removed,
3728               ;; for instance.
3729               (gnus-summary-update-info)
3730               (set-buffer gnus-group-buffer)
3731               (gnus-group-jump-to-group group)
3732               (gnus-group-next-unread-group 1))
3733           (gnus-handle-ephemeral-exit quit-config)))
3734       (let ((grpinfo (gnus-get-info group)))
3735         (if (null (gnus-info-read grpinfo))
3736             (gnus-message 3 "Group %s contains no messages"
3737                           (gnus-group-decoded-name group))
3738           (gnus-message 3 "Can't select group")))
3739       nil)
3740      ;; The user did a `C-g' while prompting for number of articles,
3741      ;; so we exit this group.
3742      ((eq did-select 'quit)
3743       (and (eq major-mode 'gnus-summary-mode)
3744            (not (equal (current-buffer) kill-buffer))
3745            (kill-buffer (current-buffer)))
3746       (when kill-buffer
3747         (gnus-kill-or-deaden-summary kill-buffer))
3748       (if (not quit-config)
3749           (progn
3750             (set-buffer gnus-group-buffer)
3751             (gnus-group-jump-to-group group)
3752             (gnus-group-next-unread-group 1)
3753             (gnus-configure-windows 'group 'force))
3754         (gnus-handle-ephemeral-exit quit-config))
3755       ;; Finally signal the quit.
3756       (signal 'quit nil))
3757      ;; The group was successfully selected.
3758      (t
3759       (gnus-set-global-variables)
3760       ;; Save the active value in effect when the group was entered.
3761       (setq gnus-newsgroup-active
3762             (gnus-copy-sequence
3763              (gnus-active gnus-newsgroup-name)))
3764       ;; You can change the summary buffer in some way with this hook.
3765       (gnus-run-hooks 'gnus-select-group-hook)
3766       (when (memq 'summary (gnus-update-format-specifications
3767                             nil 'summary 'summary-mode 'summary-dummy))
3768         ;; The format specification for the summary line was updated,
3769         ;; so we need to update the mark positions as well.
3770         (gnus-update-summary-mark-positions))
3771       ;; Do score processing.
3772       (when gnus-use-scoring
3773         (gnus-possibly-score-headers))
3774       ;; Check whether to fill in the gaps in the threads.
3775       (when gnus-build-sparse-threads
3776         (gnus-build-sparse-threads))
3777       ;; Find the initial limit.
3778       (if show-all
3779           (let ((gnus-newsgroup-dormant nil))
3780             (gnus-summary-initial-limit show-all))
3781         (gnus-summary-initial-limit show-all))
3782       ;; Generate the summary buffer.
3783       (unless no-display
3784         (gnus-summary-prepare))
3785       (when gnus-use-trees
3786         (gnus-tree-open group)
3787         (setq gnus-summary-highlight-line-function
3788               'gnus-tree-highlight-article))
3789       ;; If the summary buffer is empty, but there are some low-scored
3790       ;; articles or some excluded dormants, we include these in the
3791       ;; buffer.
3792       (when (and (zerop (buffer-size))
3793                  (not no-display))
3794         (cond (gnus-newsgroup-dormant
3795                (gnus-summary-limit-include-dormant))
3796               ((and gnus-newsgroup-scored show-all)
3797                (gnus-summary-limit-include-expunged t))))
3798       ;; Function `gnus-apply-kill-file' must be called in this hook.
3799       (gnus-run-hooks 'gnus-apply-kill-hook)
3800       (if (and (zerop (buffer-size))
3801                (not no-display))
3802           (progn
3803             ;; This newsgroup is empty.
3804             (gnus-summary-catchup-and-exit nil t)
3805             (gnus-message 6 "No unread news")
3806             (when kill-buffer
3807               (gnus-kill-or-deaden-summary kill-buffer))
3808             ;; Return nil from this function.
3809             nil)
3810         ;; Hide conversation thread subtrees.  We cannot do this in
3811         ;; gnus-summary-prepare-hook since kill processing may not
3812         ;; work with hidden articles.
3813         (gnus-summary-maybe-hide-threads)
3814         (when kill-buffer
3815           (gnus-kill-or-deaden-summary kill-buffer))
3816         (gnus-summary-auto-select-subject)
3817         ;; Show first unread article if requested.
3818         (if (and (not no-article)
3819                  (not no-display)
3820                  gnus-newsgroup-unreads
3821                  gnus-auto-select-first)
3822             (progn
3823               (gnus-configure-windows 'summary)
3824               (let ((art (gnus-summary-article-number)))
3825                 (unless (and (not gnus-plugged)
3826                              (or (memq art gnus-newsgroup-undownloaded)
3827                                  (memq art gnus-newsgroup-downloadable)))
3828                   (gnus-summary-goto-article art))))
3829           ;; Don't select any articles.
3830           (gnus-summary-position-point)
3831           (gnus-configure-windows 'summary 'force)
3832           (gnus-set-mode-line 'summary))
3833         (when (and gnus-auto-center-group
3834                    (get-buffer-window gnus-group-buffer t))
3835           ;; Gotta use windows, because recenter does weird stuff if
3836           ;; the current buffer ain't the displayed window.
3837           (let ((owin (selected-window)))
3838             (select-window (get-buffer-window gnus-group-buffer t))
3839             (when (gnus-group-goto-group group)
3840               (recenter))
3841             (select-window owin)))
3842         ;; Mark this buffer as "prepared".
3843         (setq gnus-newsgroup-prepared t)
3844         (gnus-run-hooks 'gnus-summary-prepared-hook)
3845         (unless (gnus-ephemeral-group-p group)
3846           (gnus-group-update-group group))
3847         t)))))
3848
3849 (defun gnus-summary-auto-select-subject ()
3850   "Select the subject line on initial group entry."
3851   (goto-char (point-min))
3852   (cond
3853    ((eq gnus-auto-select-subject 'best)
3854     (gnus-summary-best-unread-subject))
3855    ((eq gnus-auto-select-subject 'unread)
3856     (gnus-summary-first-unread-subject))
3857    ((eq gnus-auto-select-subject 'unseen)
3858     (gnus-summary-first-unseen-subject))
3859    ((eq gnus-auto-select-subject 'unseen-or-unread)
3860     (gnus-summary-first-unseen-or-unread-subject))
3861    ((eq gnus-auto-select-subject 'first)
3862     ;; Do nothing.
3863     )
3864    ((functionp gnus-auto-select-subject)
3865     (funcall gnus-auto-select-subject))))
3866
3867 (defun gnus-summary-prepare ()
3868   "Generate the summary buffer."
3869   (interactive)
3870   (let ((buffer-read-only nil))
3871     (erase-buffer)
3872     (setq gnus-newsgroup-data nil
3873           gnus-newsgroup-data-reverse nil)
3874     (gnus-run-hooks 'gnus-summary-generate-hook)
3875     ;; Generate the buffer, either with threads or without.
3876     (when gnus-newsgroup-headers
3877       (gnus-summary-prepare-threads
3878        (if gnus-show-threads
3879            (gnus-sort-gathered-threads
3880             (funcall gnus-summary-thread-gathering-function
3881                      (gnus-sort-threads
3882                       (gnus-cut-threads (gnus-make-threads)))))
3883          ;; Unthreaded display.
3884          (gnus-sort-articles gnus-newsgroup-headers))))
3885     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3886     ;; Call hooks for modifying summary buffer.
3887     (goto-char (point-min))
3888     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3889
3890 (defsubst gnus-general-simplify-subject (subject)
3891   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3892   (setq subject
3893         (cond
3894          ;; Truncate the subject.
3895          (gnus-simplify-subject-functions
3896           (gnus-map-function gnus-simplify-subject-functions subject))
3897          ((numberp gnus-summary-gather-subject-limit)
3898           (setq subject (gnus-simplify-subject-re subject))
3899           (if (> (length subject) gnus-summary-gather-subject-limit)
3900               (substring subject 0 gnus-summary-gather-subject-limit)
3901             subject))
3902          ;; Fuzzily simplify it.
3903          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3904           (gnus-simplify-subject-fuzzy subject))
3905          ;; Just remove the leading "Re:".
3906          (t
3907           (gnus-simplify-subject-re subject))))
3908
3909   (if (and gnus-summary-gather-exclude-subject
3910            (string-match gnus-summary-gather-exclude-subject subject))
3911       nil                         ; This article shouldn't be gathered
3912     subject))
3913
3914 (defun gnus-summary-simplify-subject-query ()
3915   "Query where the respool algorithm would put this article."
3916   (interactive)
3917   (gnus-summary-select-article)
3918   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3919
3920 (defun gnus-gather-threads-by-subject (threads)
3921   "Gather threads by looking at Subject headers."
3922   (if (not gnus-summary-make-false-root)
3923       threads
3924     (let ((hashtb (gnus-make-hashtable 1024))
3925           (prev threads)
3926           (result threads)
3927           subject hthread whole-subject)
3928       (while threads
3929         (setq subject (gnus-general-simplify-subject
3930                        (setq whole-subject (mail-header-subject
3931                                             (caar threads)))))
3932         (when subject
3933           (if (setq hthread (gnus-gethash subject hashtb))
3934               (progn
3935                 ;; We enter a dummy root into the thread, if we
3936                 ;; haven't done that already.
3937                 (unless (stringp (caar hthread))
3938                   (setcar hthread (list whole-subject (car hthread))))
3939                 ;; We add this new gathered thread to this gathered
3940                 ;; thread.
3941                 (setcdr (car hthread)
3942                         (nconc (cdar hthread) (list (car threads))))
3943                 ;; Remove it from the list of threads.
3944                 (setcdr prev (cdr threads))
3945                 (setq threads prev))
3946             ;; Enter this thread into the hash table.
3947             (gnus-sethash subject
3948                           (if gnus-summary-make-false-root-always
3949                               (progn
3950                                 ;; If you want a dummy root above all
3951                                 ;; threads...
3952                                 (setcar threads (list whole-subject
3953                                                       (car threads)))
3954                                 threads)
3955                             threads)
3956                           hashtb)))
3957         (setq prev threads)
3958         (setq threads (cdr threads)))
3959       result)))
3960
3961 (defun gnus-gather-threads-by-references (threads)
3962   "Gather threads by looking at References headers."
3963   (let ((idhashtb (gnus-make-hashtable 1024))
3964         (thhashtb (gnus-make-hashtable 1024))
3965         (prev threads)
3966         (result threads)
3967         ids references id gthread gid entered ref)
3968     (while threads
3969       (when (setq references (mail-header-references (caar threads)))
3970         (setq id (mail-header-id (caar threads))
3971               ids (inline (gnus-split-references references))
3972               entered nil)
3973         (while (setq ref (pop ids))
3974           (setq ids (delete ref ids))
3975           (if (not (setq gid (gnus-gethash ref idhashtb)))
3976               (progn
3977                 (gnus-sethash ref id idhashtb)
3978                 (gnus-sethash id threads thhashtb))
3979             (setq gthread (gnus-gethash gid thhashtb))
3980             (unless entered
3981               ;; We enter a dummy root into the thread, if we
3982               ;; haven't done that already.
3983               (unless (stringp (caar gthread))
3984                 (setcar gthread (list (mail-header-subject (caar gthread))
3985                                       (car gthread))))
3986               ;; We add this new gathered thread to this gathered
3987               ;; thread.
3988               (setcdr (car gthread)
3989                       (nconc (cdar gthread) (list (car threads)))))
3990             ;; Add it into the thread hash table.
3991             (gnus-sethash id gthread thhashtb)
3992             (setq entered t)
3993             ;; Remove it from the list of threads.
3994             (setcdr prev (cdr threads))
3995             (setq threads prev))))
3996       (setq prev threads)
3997       (setq threads (cdr threads)))
3998     result))
3999
4000 (defun gnus-sort-gathered-threads (threads)
4001   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4002   (let ((result threads))
4003     (while threads
4004       (when (stringp (caar threads))
4005         (setcdr (car threads)
4006                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4007       (setq threads (cdr threads)))
4008     result))
4009
4010 (defun gnus-thread-loop-p (root thread)
4011   "Say whether ROOT is in THREAD."
4012   (let ((stack (list thread))
4013         (infloop 0)
4014         th)
4015     (while (setq thread (pop stack))
4016       (setq th (cdr thread))
4017       (while (and th
4018                   (not (eq (caar th) root)))
4019         (pop th))
4020       (if th
4021           ;; We have found a loop.
4022           (let (ref-dep)
4023             (setcdr thread (delq (car th) (cdr thread)))
4024             (if (boundp (setq ref-dep (intern "none"
4025                                               gnus-newsgroup-dependencies)))
4026                 (setcdr (symbol-value ref-dep)
4027                         (nconc (cdr (symbol-value ref-dep))
4028                                (list (car th))))
4029               (set ref-dep (list nil (car th))))
4030             (setq infloop 1
4031                   stack nil))
4032         ;; Push all the subthreads onto the stack.
4033         (push (cdr thread) stack)))
4034     infloop))
4035
4036 (defun gnus-make-threads ()
4037   "Go through the dependency hashtb and find the roots.  Return all threads."
4038   (let (threads)
4039     (while (catch 'infloop
4040              (mapatoms
4041               (lambda (refs)
4042                 ;; Deal with self-referencing References loops.
4043                 (when (and (car (symbol-value refs))
4044                            (not (zerop
4045                                  (apply
4046                                   '+
4047                                   (mapcar
4048                                    (lambda (thread)
4049                                      (gnus-thread-loop-p
4050                                       (car (symbol-value refs)) thread))
4051                                    (cdr (symbol-value refs)))))))
4052                   (setq threads nil)
4053                   (throw 'infloop t))
4054                 (unless (car (symbol-value refs))
4055                   ;; These threads do not refer back to any other
4056                   ;; articles, so they're roots.
4057                   (setq threads (append (cdr (symbol-value refs)) threads))))
4058               gnus-newsgroup-dependencies)))
4059     threads))
4060
4061 ;; Build the thread tree.
4062 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4063   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4064
4065 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4066 if it was already present.
4067
4068 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4069 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4070 Message-IDs will be renamed to a unique Message-ID before being
4071 entered.
4072
4073 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4074   (let* ((id (mail-header-id header))
4075          (id-dep (and id (intern id dependencies)))
4076          parent-id ref ref-dep ref-header replaced)
4077     ;; Enter this `header' in the `dependencies' table.
4078     (cond
4079      ((not id-dep)
4080       (setq header nil))
4081      ;; The first two cases do the normal part: enter a new `header'
4082      ;; in the `dependencies' table.
4083      ((not (boundp id-dep))
4084       (set id-dep (list header)))
4085      ((null (car (symbol-value id-dep)))
4086       (setcar (symbol-value id-dep) header))
4087
4088      ;; From here the `header' was already present in the
4089      ;; `dependencies' table.
4090      (force-new
4091       ;; Overrides an existing entry;
4092       ;; just set the header part of the entry.
4093       (setcar (symbol-value id-dep) header)
4094       (setq replaced t))
4095
4096      ;; Renames the existing `header' to a unique Message-ID.
4097      ((not gnus-summary-ignore-duplicates)
4098       ;; An article with this Message-ID has already been seen.
4099       ;; We rename the Message-ID.
4100       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4101            (list header))
4102       (mail-header-set-id header id))
4103
4104      ;; The last case ignores an existing entry, except it adds any
4105      ;; additional Xrefs (in case the two articles came from different
4106      ;; servers.
4107      ;; Also sets `header' to `nil' meaning that the `dependencies'
4108      ;; table was *not* modified.
4109      (t
4110       (mail-header-set-xref
4111        (car (symbol-value id-dep))
4112        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4113                    "")
4114                (or (mail-header-xref header) "")))
4115       (setq header nil)))
4116
4117     (when (and header (not replaced))
4118       ;; First check that we are not creating a References loop.
4119       (setq parent-id (gnus-parent-id (mail-header-references header)))
4120       (setq ref parent-id)
4121       (while (and ref
4122                   (setq ref-dep (intern-soft ref dependencies))
4123                   (boundp ref-dep)
4124                   (setq ref-header (car (symbol-value ref-dep))))
4125         (if (string= id ref)
4126             ;; Yuk!  This is a reference loop.  Make the article be a
4127             ;; root article.
4128             (progn
4129               (mail-header-set-references (car (symbol-value id-dep)) "none")
4130               (setq ref nil)
4131               (setq parent-id nil))
4132           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4133       (setq ref-dep (intern (or parent-id "none") dependencies))
4134       (if (boundp ref-dep)
4135           (setcdr (symbol-value ref-dep)
4136                   (nconc (cdr (symbol-value ref-dep))
4137                          (list (symbol-value id-dep))))
4138         (set ref-dep (list nil (symbol-value id-dep)))))
4139     header))
4140
4141 (defun gnus-extract-message-id-from-in-reply-to (string)
4142   (if (string-match "<[^>]+>" string)
4143       (substring string (match-beginning 0) (match-end 0))
4144     nil))
4145
4146 (defun gnus-build-sparse-threads ()
4147   (let ((headers gnus-newsgroup-headers)
4148         (mail-parse-charset gnus-newsgroup-charset)
4149         (gnus-summary-ignore-duplicates t)
4150         header references generation relations
4151         subject child end new-child date)
4152     ;; First we create an alist of generations/relations, where
4153     ;; generations is how much we trust the relation, and the relation
4154     ;; is parent/child.
4155     (gnus-message 7 "Making sparse threads...")
4156     (save-excursion
4157       (nnheader-set-temp-buffer " *gnus sparse threads*")
4158       (while (setq header (pop headers))
4159         (when (and (setq references (mail-header-references header))
4160                    (not (string= references "")))
4161           (insert references)
4162           (setq child (mail-header-id header)
4163                 subject (mail-header-subject header)
4164                 date (mail-header-date header)
4165                 generation 0)
4166           (while (search-backward ">" nil t)
4167             (setq end (1+ (point)))
4168             (when (search-backward "<" nil t)
4169               (setq new-child (buffer-substring (point) end))
4170               (push (list (incf generation)
4171                           child (setq child new-child)
4172                           subject date)
4173                     relations)))
4174           (when child
4175             (push (list (1+ generation) child nil subject) relations))
4176           (erase-buffer)))
4177       (kill-buffer (current-buffer)))
4178     ;; Sort over trustworthiness.
4179     (mapcar
4180      (lambda (relation)
4181        (when (gnus-dependencies-add-header
4182               (make-full-mail-header
4183                gnus-reffed-article-number
4184                (nth 3 relation) "" (or (nth 4 relation) "")
4185                (nth 1 relation)
4186                (or (nth 2 relation) "") 0 0 "")
4187               gnus-newsgroup-dependencies nil)
4188          (push gnus-reffed-article-number gnus-newsgroup-limit)
4189          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4190          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4191                gnus-newsgroup-reads)
4192          (decf gnus-reffed-article-number)))
4193      (sort relations 'car-less-than-car))
4194     (gnus-message 7 "Making sparse threads...done")))
4195
4196 (defun gnus-build-old-threads ()
4197   ;; Look at all the articles that refer back to old articles, and
4198   ;; fetch the headers for the articles that aren't there.  This will
4199   ;; build complete threads - if the roots haven't been expired by the
4200   ;; server, that is.
4201   (let ((mail-parse-charset gnus-newsgroup-charset)
4202         id heads)
4203     (mapatoms
4204      (lambda (refs)
4205        (when (not (car (symbol-value refs)))
4206          (setq heads (cdr (symbol-value refs)))
4207          (while heads
4208            (if (memq (mail-header-number (caar heads))
4209                      gnus-newsgroup-dormant)
4210                (setq heads (cdr heads))
4211              (setq id (symbol-name refs))
4212              (while (and (setq id (gnus-build-get-header id))
4213                          (not (car (gnus-id-to-thread id)))))
4214              (setq heads nil)))))
4215      gnus-newsgroup-dependencies)))
4216
4217 (defsubst gnus-remove-odd-characters (string)
4218   "Translate STRING into something that doesn't contain weird characters."
4219   (mm-subst-char-in-string
4220    ?\r ?\-
4221    (mm-subst-char-in-string ?\n ?\- string t) t))
4222
4223 ;; This function has to be called with point after the article number
4224 ;; on the beginning of the line.
4225 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4226   (let ((eol (point-at-eol))
4227         (buffer (current-buffer))
4228         header references in-reply-to)
4229
4230     ;; overview: [num subject from date id refs chars lines misc]
4231     (unwind-protect
4232         (let (x)
4233           (narrow-to-region (point) eol)
4234           (unless (eobp)
4235             (forward-char))
4236
4237           (setq header
4238                 (make-full-mail-header
4239                  number                 ; number
4240                  (condition-case ()     ; subject
4241                      (gnus-remove-odd-characters
4242                       (funcall gnus-decode-encoded-word-function
4243                                (setq x (nnheader-nov-field))))
4244                    (error x))
4245                  (condition-case ()     ; from
4246                      (gnus-remove-odd-characters
4247                       (funcall gnus-decode-encoded-word-function
4248                                (setq x (nnheader-nov-field))))
4249                    (error x))
4250                  (nnheader-nov-field)   ; date
4251                  (nnheader-nov-read-message-id number)  ; id
4252                  (setq references (nnheader-nov-field)) ; refs
4253                  (nnheader-nov-read-integer) ; chars
4254                  (nnheader-nov-read-integer) ; lines
4255                  (unless (eobp)
4256                    (if (looking-at "Xref: ")
4257                        (goto-char (match-end 0)))
4258                    (nnheader-nov-field)) ; Xref
4259                  (nnheader-nov-parse-extra)))) ; extra
4260
4261       (widen))
4262
4263     (when (and (string= references "")
4264                (setq in-reply-to (mail-header-extra header))
4265                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4266       (mail-header-set-references
4267        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4268
4269     (when gnus-alter-header-function
4270       (funcall gnus-alter-header-function header))
4271     (gnus-dependencies-add-header header dependencies force-new)))
4272
4273 (defun gnus-build-get-header (id)
4274   "Look through the buffer of NOV lines and find the header to ID.
4275 Enter this line into the dependencies hash table, and return
4276 the id of the parent article (if any)."
4277   (let ((deps gnus-newsgroup-dependencies)
4278         found header)
4279     (prog1
4280         (save-excursion
4281           (set-buffer nntp-server-buffer)
4282           (let ((case-fold-search nil))
4283             (goto-char (point-min))
4284             (while (and (not found)
4285                         (search-forward id nil t))
4286               (beginning-of-line)
4287               (setq found (looking-at
4288                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4289                                    (regexp-quote id))))
4290               (or found (beginning-of-line 2)))
4291             (when found
4292               (beginning-of-line)
4293               (and
4294                (setq header (gnus-nov-parse-line
4295                              (read (current-buffer)) deps))
4296                (gnus-parent-id (mail-header-references header))))))
4297       (when header
4298         (let ((number (mail-header-number header)))
4299           (push number gnus-newsgroup-limit)
4300           (push header gnus-newsgroup-headers)
4301           (if (memq number gnus-newsgroup-unselected)
4302               (progn
4303                 (setq gnus-newsgroup-unreads
4304                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4305                                                number))
4306                 (setq gnus-newsgroup-unselected
4307                       (delq number gnus-newsgroup-unselected)))
4308             (push number gnus-newsgroup-ancient)))))))
4309
4310 (defun gnus-build-all-threads ()
4311   "Read all the headers."
4312   (let ((gnus-summary-ignore-duplicates t)
4313         (mail-parse-charset gnus-newsgroup-charset)
4314         (dependencies gnus-newsgroup-dependencies)
4315         header article)
4316     (save-excursion
4317       (set-buffer nntp-server-buffer)
4318       (let ((case-fold-search nil))
4319         (goto-char (point-min))
4320         (while (not (eobp))
4321           (ignore-errors
4322             (setq article (read (current-buffer))
4323                   header (gnus-nov-parse-line article dependencies)))
4324           (when header
4325             (with-current-buffer gnus-summary-buffer
4326               (push header gnus-newsgroup-headers)
4327               (if (memq (setq article (mail-header-number header))
4328                         gnus-newsgroup-unselected)
4329                   (progn
4330                     (setq gnus-newsgroup-unreads
4331                           (gnus-add-to-sorted-list
4332                            gnus-newsgroup-unreads article))
4333                     (setq gnus-newsgroup-unselected
4334                           (delq article gnus-newsgroup-unselected)))
4335                 (push article gnus-newsgroup-ancient)))
4336             (forward-line 1)))))))
4337
4338 (defun gnus-summary-update-article-line (article header)
4339   "Update the line for ARTICLE using HEADER."
4340   (let* ((id (mail-header-id header))
4341          (thread (gnus-id-to-thread id)))
4342     (unless thread
4343       (error "Article in no thread"))
4344     ;; Update the thread.
4345     (setcar thread header)
4346     (gnus-summary-goto-subject article)
4347     (let* ((datal (gnus-data-find-list article))
4348            (data (car datal))
4349            (buffer-read-only nil)
4350            (level (gnus-summary-thread-level)))
4351       (gnus-delete-line)
4352       (let ((inserted (- (point)
4353                          (progn
4354                            (gnus-summary-insert-line
4355                             header level nil
4356                             (memq article gnus-newsgroup-undownloaded)
4357                             (gnus-article-mark article)
4358                             (memq article gnus-newsgroup-replied)
4359                             (memq article gnus-newsgroup-expirable)
4360                             ;; Only insert the Subject string when it's different
4361                             ;; from the previous Subject string.
4362                             (if (and
4363                                  gnus-show-threads
4364                                  (gnus-subject-equal
4365                                   (condition-case ()
4366                                       (mail-header-subject
4367                                        (gnus-data-header
4368                                         (cadr
4369                                          (gnus-data-find-list
4370                                           article
4371                                           (gnus-data-list t)))))
4372                                     ;; Error on the side of excessive subjects.
4373                                     (error ""))
4374                                   (mail-header-subject header)))
4375                                 ""
4376                               (mail-header-subject header))
4377                             nil (cdr (assq article gnus-newsgroup-scored))
4378                             (memq article gnus-newsgroup-processable))
4379                            (point)))))
4380         (when (cdr datal)
4381           (gnus-data-update-list
4382            (cdr datal)
4383            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4384
4385 (defun gnus-summary-update-article (article &optional iheader)
4386   "Update ARTICLE in the summary buffer."
4387   (set-buffer gnus-summary-buffer)
4388   (let* ((header (gnus-summary-article-header article))
4389          (id (mail-header-id header))
4390          (data (gnus-data-find article))
4391          (thread (gnus-id-to-thread id))
4392          (references (mail-header-references header))
4393          (parent
4394           (gnus-id-to-thread
4395            (or (gnus-parent-id
4396                 (when (and references
4397                            (not (equal "" references)))
4398                   references))
4399                "none")))
4400          (buffer-read-only nil)
4401          (old (car thread)))
4402     (when thread
4403       (unless iheader
4404         (setcar thread nil)
4405         (when parent
4406           (delq thread parent)))
4407       (if (gnus-summary-insert-subject id header)
4408           ;; Set the (possibly) new article number in the data structure.
4409           (gnus-data-set-number data (gnus-id-to-article id))
4410         (setcar thread old)
4411         nil))))
4412
4413 (defun gnus-rebuild-thread (id &optional line)
4414   "Rebuild the thread containing ID.
4415 If LINE, insert the rebuilt thread starting on line LINE."
4416   (let ((buffer-read-only nil)
4417         old-pos current thread data)
4418     (if (not gnus-show-threads)
4419         (setq thread (list (car (gnus-id-to-thread id))))
4420       ;; Get the thread this article is part of.
4421       (setq thread (gnus-remove-thread id)))
4422     (setq old-pos (point-at-bol))
4423     (setq current (save-excursion
4424                     (and (re-search-backward "[\r\n]" nil t)
4425                          (gnus-summary-article-number))))
4426     ;; If this is a gathered thread, we have to go some re-gathering.
4427     (when (stringp (car thread))
4428       (let ((subject (car thread))
4429             roots thr)
4430         (setq thread (cdr thread))
4431         (while thread
4432           (unless (memq (setq thr (gnus-id-to-thread
4433                                    (gnus-root-id
4434                                     (mail-header-id (caar thread)))))
4435                         roots)
4436             (push thr roots))
4437           (setq thread (cdr thread)))
4438         ;; We now have all (unique) roots.
4439         (if (= (length roots) 1)
4440             ;; All the loose roots are now one solid root.
4441             (setq thread (car roots))
4442           (setq thread (cons subject (gnus-sort-threads roots))))))
4443     (let (threads)
4444       ;; We then insert this thread into the summary buffer.
4445       (when line
4446         (goto-char (point-min))
4447         (forward-line (1- line)))
4448       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4449         (if gnus-show-threads
4450             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4451           (gnus-summary-prepare-unthreaded thread))
4452         (setq data (nreverse gnus-newsgroup-data))
4453         (setq threads gnus-newsgroup-threads))
4454       ;; We splice the new data into the data structure.
4455       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4456       ;;!!! then we want to insert at the beginning of the buffer.
4457       ;;!!! That happens to be true with Gnus now, but that may
4458       ;;!!! change in the future.  Perhaps.
4459       (gnus-data-enter-list
4460        (if line nil current) data (- (point) old-pos))
4461       (setq gnus-newsgroup-threads
4462             (nconc threads gnus-newsgroup-threads))
4463       (gnus-data-compute-positions))))
4464
4465 (defun gnus-number-to-header (number)
4466   "Return the header for article NUMBER."
4467   (let ((headers gnus-newsgroup-headers))
4468     (while (and headers
4469                 (not (= number (mail-header-number (car headers)))))
4470       (pop headers))
4471     (when headers
4472       (car headers))))
4473
4474 (defun gnus-parent-headers (in-headers &optional generation)
4475   "Return the headers of the GENERATIONeth parent of HEADERS."
4476   (unless generation
4477     (setq generation 1))
4478   (let ((parent t)
4479         (headers in-headers)
4480         references)
4481     (while (and parent
4482                 (not (zerop generation))
4483                 (setq references (mail-header-references headers)))
4484       (setq headers (if (and references
4485                              (setq parent (gnus-parent-id references)))
4486                         (car (gnus-id-to-thread parent))
4487                       nil))
4488       (decf generation))
4489     (and (not (eq headers in-headers))
4490          headers)))
4491
4492 (defun gnus-id-to-thread (id)
4493   "Return the (sub-)thread where ID appears."
4494   (gnus-gethash id gnus-newsgroup-dependencies))
4495
4496 (defun gnus-id-to-article (id)
4497   "Return the article number of ID."
4498   (let ((thread (gnus-id-to-thread id)))
4499     (when (and thread
4500                (car thread))
4501       (mail-header-number (car thread)))))
4502
4503 (defun gnus-id-to-header (id)
4504   "Return the article headers of ID."
4505   (car (gnus-id-to-thread id)))
4506
4507 (defun gnus-article-displayed-root-p (article)
4508   "Say whether ARTICLE is a root(ish) article."
4509   (let ((level (gnus-summary-thread-level article))
4510         (refs (mail-header-references  (gnus-summary-article-header article)))
4511         particle)
4512     (cond
4513      ((null level) nil)
4514      ((zerop level) t)
4515      ((null refs) t)
4516      ((null (gnus-parent-id refs)) t)
4517      ((and (= 1 level)
4518            (null (setq particle (gnus-id-to-article
4519                                  (gnus-parent-id refs))))
4520            (null (gnus-summary-thread-level particle)))))))
4521
4522 (defun gnus-root-id (id)
4523   "Return the id of the root of the thread where ID appears."
4524   (let (last-id prev)
4525     (while (and id (setq prev (car (gnus-id-to-thread id))))
4526       (setq last-id id
4527             id (gnus-parent-id (mail-header-references prev))))
4528     last-id))
4529
4530 (defun gnus-articles-in-thread (thread)
4531   "Return the list of articles in THREAD."
4532   (cons (mail-header-number (car thread))
4533         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4534
4535 (defun gnus-remove-thread (id &optional dont-remove)
4536   "Remove the thread that has ID in it."
4537   (let (headers thread last-id)
4538     ;; First go up in this thread until we find the root.
4539     (setq last-id (gnus-root-id id)
4540           headers (message-flatten-list (gnus-id-to-thread last-id)))
4541     ;; We have now found the real root of this thread.  It might have
4542     ;; been gathered into some loose thread, so we have to search
4543     ;; through the threads to find the thread we wanted.
4544     (let ((threads gnus-newsgroup-threads)
4545           sub)
4546       (while threads
4547         (setq sub (car threads))
4548         (if (stringp (car sub))
4549             ;; This is a gathered thread, so we look at the roots
4550             ;; below it to find whether this article is in this
4551             ;; gathered root.
4552             (progn
4553               (setq sub (cdr sub))
4554               (while sub
4555                 (when (member (caar sub) headers)
4556                   (setq thread (car threads)
4557                         threads nil
4558                         sub nil))
4559                 (setq sub (cdr sub))))
4560           ;; It's an ordinary thread, so we check it.
4561           (when (eq (car sub) (car headers))
4562             (setq thread sub
4563                   threads nil)))
4564         (setq threads (cdr threads)))
4565       ;; If this article is in no thread, then it's a root.
4566       (if thread
4567           (unless dont-remove
4568             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4569         (setq thread (gnus-id-to-thread last-id)))
4570       (when thread
4571         (prog1
4572             thread                      ; We return this thread.
4573           (unless dont-remove
4574             (if (stringp (car thread))
4575                 (progn
4576                   ;; If we use dummy roots, then we have to remove the
4577                   ;; dummy root as well.
4578                   (when (eq gnus-summary-make-false-root 'dummy)
4579                     ;; We go to the dummy root by going to
4580                     ;; the first sub-"thread", and then one line up.
4581                     (gnus-summary-goto-article
4582                      (mail-header-number (caadr thread)))
4583                     (forward-line -1)
4584                     (gnus-delete-line)
4585                     (gnus-data-compute-positions))
4586                   (setq thread (cdr thread))
4587                   (while thread
4588                     (gnus-remove-thread-1 (car thread))
4589                     (setq thread (cdr thread))))
4590               (gnus-remove-thread-1 thread))))))))
4591
4592 (defun gnus-remove-thread-1 (thread)
4593   "Remove the thread THREAD recursively."
4594   (let ((number (mail-header-number (pop thread)))
4595         d)
4596     (setq thread (reverse thread))
4597     (while thread
4598       (gnus-remove-thread-1 (pop thread)))
4599     (when (setq d (gnus-data-find number))
4600       (goto-char (gnus-data-pos d))
4601       (gnus-summary-show-thread)
4602       (gnus-data-remove
4603        number
4604        (- (point-at-bol)
4605           (prog1
4606               (1+ (point-at-eol))
4607             (gnus-delete-line)))))))
4608
4609 (defun gnus-sort-threads-1 (threads func)
4610   (sort (mapcar (lambda (thread)
4611                   (cons (car thread)
4612                         (and (cdr thread)
4613                              (gnus-sort-threads-1 (cdr thread) func))))
4614                 threads) func))
4615
4616 (defun gnus-sort-threads (threads)
4617   "Sort THREADS."
4618   (if (not gnus-thread-sort-functions)
4619       threads
4620     (gnus-message 8 "Sorting threads...")
4621     (let ((max-lisp-eval-depth 5000))
4622       (prog1 (gnus-sort-threads-1
4623          threads
4624          (gnus-make-sort-function gnus-thread-sort-functions))
4625         (gnus-message 8 "Sorting threads...done")))))
4626
4627 (defun gnus-sort-articles (articles)
4628   "Sort ARTICLES."
4629   (when gnus-article-sort-functions
4630     (gnus-message 7 "Sorting articles...")
4631     (prog1
4632         (setq gnus-newsgroup-headers
4633               (sort articles (gnus-make-sort-function
4634                               gnus-article-sort-functions)))
4635       (gnus-message 7 "Sorting articles...done"))))
4636
4637 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4638 (defmacro gnus-thread-header (thread)
4639   "Return header of first article in THREAD.
4640 Note that THREAD must never, ever be anything else than a variable -
4641 using some other form will lead to serious barfage."
4642   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4643   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4644   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4645         (vector thread) 2))
4646
4647 (defsubst gnus-article-sort-by-number (h1 h2)
4648   "Sort articles by article number."
4649   (< (mail-header-number h1)
4650      (mail-header-number h2)))
4651
4652 (defun gnus-thread-sort-by-number (h1 h2)
4653   "Sort threads by root article number."
4654   (gnus-article-sort-by-number
4655    (gnus-thread-header h1) (gnus-thread-header h2)))
4656
4657 (defsubst gnus-article-sort-by-random (h1 h2)
4658   "Sort articles by article number."
4659   (zerop (random 2)))
4660
4661 (defun gnus-thread-sort-by-random (h1 h2)
4662   "Sort threads by root article number."
4663   (gnus-article-sort-by-random
4664    (gnus-thread-header h1) (gnus-thread-header h2)))
4665
4666 (defsubst gnus-article-sort-by-lines (h1 h2)
4667   "Sort articles by article Lines header."
4668   (< (mail-header-lines h1)
4669      (mail-header-lines h2)))
4670
4671 (defun gnus-thread-sort-by-lines (h1 h2)
4672   "Sort threads by root article Lines header."
4673   (gnus-article-sort-by-lines
4674    (gnus-thread-header h1) (gnus-thread-header h2)))
4675
4676 (defsubst gnus-article-sort-by-chars (h1 h2)
4677   "Sort articles by octet length."
4678   (< (mail-header-chars h1)
4679      (mail-header-chars h2)))
4680
4681 (defun gnus-thread-sort-by-chars (h1 h2)
4682   "Sort threads by root article octet length."
4683   (gnus-article-sort-by-chars
4684    (gnus-thread-header h1) (gnus-thread-header h2)))
4685
4686 (defsubst gnus-article-sort-by-author (h1 h2)
4687   "Sort articles by root author."
4688   (string-lessp
4689    (let ((extract (funcall
4690                    gnus-extract-address-components
4691                    (mail-header-from h1))))
4692      (or (car extract) (cadr extract) ""))
4693    (let ((extract (funcall
4694                    gnus-extract-address-components
4695                    (mail-header-from h2))))
4696      (or (car extract) (cadr extract) ""))))
4697
4698 (defun gnus-thread-sort-by-author (h1 h2)
4699   "Sort threads by root author."
4700   (gnus-article-sort-by-author
4701    (gnus-thread-header h1)  (gnus-thread-header h2)))
4702
4703 (defsubst gnus-article-sort-by-recipient (h1 h2)
4704   "Sort articles by recipient."
4705   (string-lessp
4706    (let ((extract (funcall
4707                    gnus-extract-address-components
4708                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4709      (or (car extract) (cadr extract)))
4710    (let ((extract (funcall
4711                    gnus-extract-address-components
4712                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4713      (or (car extract) (cadr extract)))))
4714
4715 (defun gnus-thread-sort-by-recipient (h1 h2)
4716   "Sort threads by root recipient."
4717   (gnus-article-sort-by-recipient
4718    (gnus-thread-header h1) (gnus-thread-header h2)))
4719
4720 (defsubst gnus-article-sort-by-subject (h1 h2)
4721   "Sort articles by root subject."
4722   (string-lessp
4723    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4724    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4725
4726 (defun gnus-thread-sort-by-subject (h1 h2)
4727   "Sort threads by root subject."
4728   (gnus-article-sort-by-subject
4729    (gnus-thread-header h1) (gnus-thread-header h2)))
4730
4731 (defsubst gnus-article-sort-by-date (h1 h2)
4732   "Sort articles by root article date."
4733   (time-less-p
4734    (gnus-date-get-time (mail-header-date h1))
4735    (gnus-date-get-time (mail-header-date h2))))
4736
4737 (defun gnus-thread-sort-by-date (h1 h2)
4738   "Sort threads by root article date."
4739   (gnus-article-sort-by-date
4740    (gnus-thread-header h1) (gnus-thread-header h2)))
4741
4742 (defsubst gnus-article-sort-by-score (h1 h2)
4743   "Sort articles by root article score.
4744 Unscored articles will be counted as having a score of zero."
4745   (> (or (cdr (assq (mail-header-number h1)
4746                     gnus-newsgroup-scored))
4747          gnus-summary-default-score 0)
4748      (or (cdr (assq (mail-header-number h2)
4749                     gnus-newsgroup-scored))
4750          gnus-summary-default-score 0)))
4751
4752 (defun gnus-thread-sort-by-score (h1 h2)
4753   "Sort threads by root article score."
4754   (gnus-article-sort-by-score
4755    (gnus-thread-header h1) (gnus-thread-header h2)))
4756
4757 (defun gnus-thread-sort-by-total-score (h1 h2)
4758   "Sort threads by the sum of all scores in the thread.
4759 Unscored articles will be counted as having a score of zero."
4760   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4761
4762 (defun gnus-thread-total-score (thread)
4763   ;; This function find the total score of THREAD.
4764   (cond
4765    ((null thread)
4766     0)
4767    ((consp thread)
4768     (if (stringp (car thread))
4769         (apply gnus-thread-score-function 0
4770                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4771       (gnus-thread-total-score-1 thread)))
4772    (t
4773     (gnus-thread-total-score-1 (list thread)))))
4774
4775 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4776   "Sort threads such that the thread with the most recently arrived article comes first."
4777   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4778
4779 (defun gnus-thread-highest-number (thread)
4780   "Return the highest article number in THREAD."
4781   (apply 'max (mapcar (lambda (header)
4782                         (mail-header-number header))
4783                       (message-flatten-list thread))))
4784
4785 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4786   "Sort threads such that the thread with the most recently dated article comes first."
4787   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4788
4789 (defun gnus-thread-latest-date (thread)
4790   "Return the highest article date in THREAD."
4791   (let ((previous-time 0))
4792     (apply 'max
4793            (mapcar
4794             (lambda (header)
4795               (setq previous-time
4796                     (condition-case ()
4797                         (time-to-seconds (mail-header-parse-date
4798                                           (mail-header-date header)))
4799                       (error previous-time))))
4800             (sort
4801              (message-flatten-list thread)
4802              (lambda (h1 h2)
4803                (< (mail-header-number h1)
4804                   (mail-header-number h2))))))))
4805
4806 (defun gnus-thread-total-score-1 (root)
4807   ;; This function find the total score of the thread below ROOT.
4808   (setq root (car root))
4809   (apply gnus-thread-score-function
4810          (or (append
4811               (mapcar 'gnus-thread-total-score
4812                       (cdr (gnus-id-to-thread (mail-header-id root))))
4813               (when (> (mail-header-number root) 0)
4814                 (list (or (cdr (assq (mail-header-number root)
4815                                      gnus-newsgroup-scored))
4816                           gnus-summary-default-score 0))))
4817              (list gnus-summary-default-score)
4818              '(0))))
4819
4820 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4821 (defvar gnus-tmp-prev-subject nil)
4822 (defvar gnus-tmp-false-parent nil)
4823 (defvar gnus-tmp-root-expunged nil)
4824 (defvar gnus-tmp-dummy-line nil)
4825
4826 (eval-when-compile (defvar gnus-tmp-header))
4827 (defun gnus-extra-header (type &optional header)
4828   "Return the extra header of TYPE."
4829   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4830       ""))
4831
4832 (defvar gnus-tmp-thread-tree-header-string "")
4833
4834 (defcustom gnus-sum-thread-tree-root "> "
4835   "With %B spec, used for the root of a thread.
4836 If nil, use subject instead."
4837   :version "22.1"
4838   :type '(radio (const :format "%v  " nil) string)
4839   :group 'gnus-thread)
4840
4841 (defcustom gnus-sum-thread-tree-false-root "> "
4842   "With %B spec, used for a false root of a thread.
4843 If nil, use subject instead."
4844   :version "22.1"
4845   :type '(radio (const :format "%v  " nil) string)
4846   :group 'gnus-thread)
4847
4848 (defcustom gnus-sum-thread-tree-single-indent ""
4849   "With %B spec, used for a thread with just one message.
4850 If nil, use subject instead."
4851   :version "22.1"
4852   :type '(radio (const :format "%v  " nil) string)
4853   :group 'gnus-thread)
4854
4855 (defcustom gnus-sum-thread-tree-vertical "| "
4856   "With %B spec, used for drawing a vertical line."
4857   :version "22.1"
4858   :type 'string
4859   :group 'gnus-thread)
4860
4861 (defcustom gnus-sum-thread-tree-indent "  "
4862   "With %B spec, used for indenting."
4863   :version "22.1"
4864   :type 'string
4865   :group 'gnus-thread)
4866
4867 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4868   "With %B spec, used for a leaf with brothers."
4869   :version "22.1"
4870   :type 'string
4871   :group 'gnus-thread)
4872
4873 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4874   "With %B spec, used for a leaf without brothers."
4875   :version "22.1"
4876   :type 'string
4877   :group 'gnus-thread)
4878
4879 (defun gnus-summary-prepare-threads (threads)
4880   "Prepare summary buffer from THREADS and indentation LEVEL.
4881 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4882 or a straight list of headers."
4883   (gnus-message 7 "Generating summary...")
4884
4885   (setq gnus-newsgroup-threads threads)
4886   (beginning-of-line)
4887
4888   (let ((gnus-tmp-level 0)
4889         (default-score (or gnus-summary-default-score 0))
4890         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4891         (building-line-count gnus-summary-display-while-building)
4892         (building-count (integerp gnus-summary-display-while-building))
4893         thread number subject stack state gnus-tmp-gathered beg-match
4894         new-roots gnus-tmp-new-adopts thread-end simp-subject
4895         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4896         gnus-tmp-replied gnus-tmp-subject-or-nil
4897         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4898         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4899         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4900         tree-stack)
4901
4902     (setq gnus-tmp-prev-subject nil
4903           gnus-tmp-thread-tree-header-string "")
4904
4905     (if (vectorp (car threads))
4906         ;; If this is a straight (sic) list of headers, then a
4907         ;; threaded summary display isn't required, so we just create
4908         ;; an unthreaded one.
4909         (gnus-summary-prepare-unthreaded threads)
4910
4911       ;; Do the threaded display.
4912
4913       (if gnus-summary-display-while-building
4914           (switch-to-buffer (buffer-name)))
4915       (while (or threads stack gnus-tmp-new-adopts new-roots)
4916
4917         (if (and (= gnus-tmp-level 0)
4918                  (or (not stack)
4919                      (= (caar stack) 0))
4920                  (not gnus-tmp-false-parent)
4921                  (or gnus-tmp-new-adopts new-roots))
4922             (if gnus-tmp-new-adopts
4923                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4924                       thread (list (car gnus-tmp-new-adopts))
4925                       gnus-tmp-header (caar thread)
4926                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4927               (when new-roots
4928                 (setq thread (list (car new-roots))
4929                       gnus-tmp-header (caar thread)
4930                       new-roots (cdr new-roots))))
4931
4932           (if threads
4933               ;; If there are some threads, we do them before the
4934               ;; threads on the stack.
4935               (setq thread threads
4936                     gnus-tmp-header (caar thread))
4937             ;; There were no current threads, so we pop something off
4938             ;; the stack.
4939             (setq state (car stack)
4940                   gnus-tmp-level (car state)
4941                   tree-stack (cadr state)
4942                   thread (caddr state)
4943                   stack (cdr stack)
4944                   gnus-tmp-header (caar thread))))
4945
4946         (setq gnus-tmp-false-parent nil)
4947         (setq gnus-tmp-root-expunged nil)
4948         (setq thread-end nil)
4949
4950         (if (stringp gnus-tmp-header)
4951             ;; The header is a dummy root.
4952             (cond
4953              ((eq gnus-summary-make-false-root 'adopt)
4954               ;; We let the first article adopt the rest.
4955               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4956                                                (cddar thread)))
4957               (setq gnus-tmp-gathered
4958                     (nconc (mapcar
4959                             (lambda (h) (mail-header-number (car h)))
4960                             (cddar thread))
4961                            gnus-tmp-gathered))
4962               (setq thread (cons (list (caar thread)
4963                                        (cadar thread))
4964                                  (cdr thread)))
4965               (setq gnus-tmp-level -1
4966                     gnus-tmp-false-parent t))
4967              ((eq gnus-summary-make-false-root 'empty)
4968               ;; We print adopted articles with empty subject fields.
4969               (setq gnus-tmp-gathered
4970                     (nconc (mapcar
4971                             (lambda (h) (mail-header-number (car h)))
4972                             (cddar thread))
4973                            gnus-tmp-gathered))
4974               (setq gnus-tmp-level -1))
4975              ((eq gnus-summary-make-false-root 'dummy)
4976               ;; We remember that we probably want to output a dummy
4977               ;; root.
4978               (setq gnus-tmp-dummy-line gnus-tmp-header)
4979               (setq gnus-tmp-prev-subject gnus-tmp-header))
4980              (t
4981               ;; We do not make a root for the gathered
4982               ;; sub-threads at all.
4983               (setq gnus-tmp-level -1)))
4984
4985           (setq number (mail-header-number gnus-tmp-header)
4986                 subject (mail-header-subject gnus-tmp-header)
4987                 simp-subject (gnus-simplify-subject-fully subject))
4988
4989           (cond
4990            ;; If the thread has changed subject, we might want to make
4991            ;; this subthread into a root.
4992            ((and (null gnus-thread-ignore-subject)
4993                  (not (zerop gnus-tmp-level))
4994                  gnus-tmp-prev-subject
4995                  (not (string= gnus-tmp-prev-subject simp-subject)))
4996             (setq new-roots (nconc new-roots (list (car thread)))
4997                   thread-end t
4998                   gnus-tmp-header nil))
4999            ;; If the article lies outside the current limit,
5000            ;; then we do not display it.
5001            ((not (memq number gnus-newsgroup-limit))
5002             (setq gnus-tmp-gathered
5003                   (nconc (mapcar
5004                           (lambda (h) (mail-header-number (car h)))
5005                           (cdar thread))
5006                          gnus-tmp-gathered))
5007             (setq gnus-tmp-new-adopts (if (cdar thread)
5008                                           (append gnus-tmp-new-adopts
5009                                                   (cdar thread))
5010                                         gnus-tmp-new-adopts)
5011                   thread-end t
5012                   gnus-tmp-header nil)
5013             (when (zerop gnus-tmp-level)
5014               (setq gnus-tmp-root-expunged t)))
5015            ;; Perhaps this article is to be marked as read?
5016            ((and gnus-summary-mark-below
5017                  (< (or (cdr (assq number gnus-newsgroup-scored))
5018                         default-score)
5019                     gnus-summary-mark-below)
5020                  ;; Don't touch sparse articles.
5021                  (not (gnus-summary-article-sparse-p number))
5022                  (not (gnus-summary-article-ancient-p number)))
5023             (setq gnus-newsgroup-unreads
5024                   (delq number gnus-newsgroup-unreads))
5025             (if gnus-newsgroup-auto-expire
5026                 (setq gnus-newsgroup-expirable
5027                       (gnus-add-to-sorted-list
5028                        gnus-newsgroup-expirable number))
5029               (push (cons number gnus-low-score-mark)
5030                     gnus-newsgroup-reads))))
5031
5032           (when gnus-tmp-header
5033             ;; We may have an old dummy line to output before this
5034             ;; article.
5035             (when (and gnus-tmp-dummy-line
5036                        (gnus-subject-equal
5037                         gnus-tmp-dummy-line
5038                         (mail-header-subject gnus-tmp-header)))
5039               (gnus-summary-insert-dummy-line
5040                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5041               (setq gnus-tmp-dummy-line nil))
5042
5043             ;; Compute the mark.
5044             (setq gnus-tmp-unread (gnus-article-mark number))
5045
5046             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5047                                   gnus-tmp-header gnus-tmp-level)
5048                   gnus-newsgroup-data)
5049
5050             ;; Actually insert the line.
5051             (setq
5052              gnus-tmp-subject-or-nil
5053              (cond
5054               ((and gnus-thread-ignore-subject
5055                     gnus-tmp-prev-subject
5056                     (not (string= gnus-tmp-prev-subject simp-subject)))
5057                subject)
5058               ((zerop gnus-tmp-level)
5059                (if (and (eq gnus-summary-make-false-root 'empty)
5060                         (memq number gnus-tmp-gathered)
5061                         gnus-tmp-prev-subject
5062                         (string= gnus-tmp-prev-subject simp-subject))
5063                    gnus-summary-same-subject
5064                  subject))
5065               (t gnus-summary-same-subject)))
5066             (if (and (eq gnus-summary-make-false-root 'adopt)
5067                      (= gnus-tmp-level 1)
5068                      (memq number gnus-tmp-gathered))
5069                 (setq gnus-tmp-opening-bracket ?\<
5070                       gnus-tmp-closing-bracket ?\>)
5071               (setq gnus-tmp-opening-bracket ?\[
5072                     gnus-tmp-closing-bracket ?\]))
5073             (setq
5074              gnus-tmp-indentation
5075              (aref gnus-thread-indent-array gnus-tmp-level)
5076              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5077              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5078                                 gnus-summary-default-score 0)
5079              gnus-tmp-score-char
5080              (if (or (null gnus-summary-default-score)
5081                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5082                          gnus-summary-zcore-fuzz))
5083                  ?                      ;Whitespace
5084                (if (< gnus-tmp-score gnus-summary-default-score)
5085                    gnus-score-below-mark gnus-score-over-mark))
5086              gnus-tmp-replied
5087              (cond ((memq number gnus-newsgroup-processable)
5088                     gnus-process-mark)
5089                    ((memq number gnus-newsgroup-cached)
5090                     gnus-cached-mark)
5091                    ((memq number gnus-newsgroup-replied)
5092                     gnus-replied-mark)
5093                    ((memq number gnus-newsgroup-forwarded)
5094                     gnus-forwarded-mark)
5095                    ((memq number gnus-newsgroup-saved)
5096                     gnus-saved-mark)
5097                    ((memq number gnus-newsgroup-recent)
5098                     gnus-recent-mark)
5099                    ((memq number gnus-newsgroup-unseen)
5100                     gnus-unseen-mark)
5101                    (t gnus-no-mark))
5102              gnus-tmp-downloaded
5103              (cond ((memq number gnus-newsgroup-undownloaded)
5104                     gnus-undownloaded-mark)
5105                    (gnus-newsgroup-agentized
5106                     gnus-downloaded-mark)
5107                    (t
5108                     gnus-no-mark))
5109              gnus-tmp-from (mail-header-from gnus-tmp-header)
5110              gnus-tmp-name
5111              (cond
5112               ((string-match "<[^>]+> *$" gnus-tmp-from)
5113                (setq beg-match (match-beginning 0))
5114                (or (and (string-match "^\".+\"" gnus-tmp-from)
5115                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5116                    (substring gnus-tmp-from 0 beg-match)))
5117               ((string-match "(.+)" gnus-tmp-from)
5118                (substring gnus-tmp-from
5119                           (1+ (match-beginning 0)) (1- (match-end 0))))
5120               (t gnus-tmp-from))
5121
5122              ;; Do the %B string
5123              gnus-tmp-thread-tree-header-string
5124              (cond
5125               ((not gnus-show-threads) "")
5126               ((zerop gnus-tmp-level)
5127                (cond ((cdar thread)
5128                       (or gnus-sum-thread-tree-root subject))
5129                      (gnus-tmp-new-adopts
5130                       (or gnus-sum-thread-tree-false-root subject))
5131                      (t
5132                       (or gnus-sum-thread-tree-single-indent subject))))
5133               (t
5134                (concat (apply 'concat
5135                               (mapcar (lambda (item)
5136                                         (if (= item 1)
5137                                             gnus-sum-thread-tree-vertical
5138                                           gnus-sum-thread-tree-indent))
5139                                       (cdr (reverse tree-stack))))
5140                        (if (nth 1 thread)
5141                            gnus-sum-thread-tree-leaf-with-other
5142                          gnus-sum-thread-tree-single-leaf)))))
5143             (when (string= gnus-tmp-name "")
5144               (setq gnus-tmp-name gnus-tmp-from))
5145             (unless (numberp gnus-tmp-lines)
5146               (setq gnus-tmp-lines -1))
5147             (if (= gnus-tmp-lines -1)
5148                 (setq gnus-tmp-lines "?")
5149               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5150               (gnus-put-text-property
5151              (point)
5152              (progn (eval gnus-summary-line-format-spec) (point))
5153                'gnus-number number)
5154             (when gnus-visual-p
5155               (forward-line -1)
5156               (gnus-run-hooks 'gnus-summary-update-hook)
5157               (forward-line 1))
5158
5159             (setq gnus-tmp-prev-subject simp-subject)))
5160
5161         (when (nth 1 thread)
5162           (push (list (max 0 gnus-tmp-level)
5163                       (copy-sequence tree-stack)
5164                       (nthcdr 1 thread))
5165                 stack))
5166         (push (if (nth 1 thread) 1 0) tree-stack)
5167         (incf gnus-tmp-level)
5168         (setq threads (if thread-end nil (cdar thread)))
5169         (if gnus-summary-display-while-building
5170             (if building-count
5171                 (progn
5172                   ;; use a set frequency
5173                   (setq building-line-count (1- building-line-count))
5174                   (when (= building-line-count 0)
5175                     (sit-for 0)
5176                     (setq building-line-count
5177                           gnus-summary-display-while-building)))
5178               ;; always
5179               (sit-for 0)))
5180         (unless threads
5181           (setq gnus-tmp-level 0)))))
5182   (gnus-message 7 "Generating summary...done"))
5183
5184 (defun gnus-summary-prepare-unthreaded (headers)
5185   "Generate an unthreaded summary buffer based on HEADERS."
5186   (let (header number mark)
5187
5188     (beginning-of-line)
5189
5190     (while headers
5191       ;; We may have to root out some bad articles...
5192       (when (memq (setq number (mail-header-number
5193                                 (setq header (pop headers))))
5194                   gnus-newsgroup-limit)
5195         ;; Mark article as read when it has a low score.
5196         (when (and gnus-summary-mark-below
5197                    (< (or (cdr (assq number gnus-newsgroup-scored))
5198                           gnus-summary-default-score 0)
5199                       gnus-summary-mark-below)
5200                    (not (gnus-summary-article-ancient-p number)))
5201           (setq gnus-newsgroup-unreads
5202                 (delq number gnus-newsgroup-unreads))
5203           (if gnus-newsgroup-auto-expire
5204               (push number gnus-newsgroup-expirable)
5205             (push (cons number gnus-low-score-mark)
5206                   gnus-newsgroup-reads)))
5207
5208         (setq mark (gnus-article-mark number))
5209         (push (gnus-data-make number mark (1+ (point)) header 0)
5210               gnus-newsgroup-data)
5211         (gnus-summary-insert-line
5212          header 0 number
5213          (memq number gnus-newsgroup-undownloaded)
5214          mark (memq number gnus-newsgroup-replied)
5215          (memq number gnus-newsgroup-expirable)
5216          (mail-header-subject header) nil
5217          (cdr (assq number gnus-newsgroup-scored))
5218          (memq number gnus-newsgroup-processable))))))
5219
5220 (defun gnus-summary-remove-list-identifiers ()
5221   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5222   (let ((regexp (if (consp gnus-list-identifiers)
5223                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5224                   gnus-list-identifiers))
5225         changed subject)
5226     (when regexp
5227       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5228       (dolist (header gnus-newsgroup-headers)
5229         (setq subject (mail-header-subject header)
5230               changed nil)
5231         (while (string-match regexp subject)
5232           (setq subject
5233                 (concat (substring subject 0 (match-beginning 1))
5234                         (substring subject (match-end 0)))
5235                 changed t))
5236         (when changed
5237           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5238             (setq subject
5239                   (concat (substring subject 0 (match-beginning 1))
5240                           (substring subject (match-end 1)))))
5241           (mail-header-set-subject header subject))))))
5242
5243 (defun gnus-fetch-headers (articles)
5244   "Fetch headers of ARTICLES."
5245   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5246     (gnus-message 5 "Fetching headers for %s..." name)
5247     (prog1
5248         (if (eq 'nov
5249                 (setq gnus-headers-retrieved-by
5250                       (gnus-retrieve-headers
5251                        articles gnus-newsgroup-name
5252                        ;; We might want to fetch old headers, but
5253                        ;; not if there is only 1 article.
5254                        (and (or (and
5255                                  (not (eq gnus-fetch-old-headers 'some))
5256                                  (not (numberp gnus-fetch-old-headers)))
5257                                 (> (length articles) 1))
5258                             gnus-fetch-old-headers))))
5259             (gnus-get-newsgroup-headers-xover
5260              articles nil nil gnus-newsgroup-name t)
5261           (gnus-get-newsgroup-headers))
5262       (gnus-message 5 "Fetching headers for %s...done" name))))
5263
5264 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5265   "Select newsgroup GROUP.
5266 If READ-ALL is non-nil, all articles in the group are selected.
5267 If SELECT-ARTICLES, only select those articles from GROUP."
5268   (let* ((entry (gnus-group-entry group))
5269          ;;!!! Dirty hack; should be removed.
5270          (gnus-summary-ignore-duplicates
5271           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5272               t
5273             gnus-summary-ignore-duplicates))
5274          (info (nth 2 entry))
5275          articles fetched-articles cached)
5276
5277     (unless (gnus-check-server
5278              (set (make-local-variable 'gnus-current-select-method)
5279                   (gnus-find-method-for-group group)))
5280       (error "Couldn't open server"))
5281
5282     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5283         (gnus-activate-group group)     ; Or we can activate it...
5284         (progn                          ; Or we bug out.
5285           (when (equal major-mode 'gnus-summary-mode)
5286             (gnus-kill-buffer (current-buffer)))
5287           (error "Couldn't activate group %s: %s"
5288                  group (gnus-status-message group))))
5289
5290     (unless (gnus-request-group group t)
5291       (when (equal major-mode 'gnus-summary-mode)
5292         (gnus-kill-buffer (current-buffer)))
5293       (error "Couldn't request group %s: %s"
5294              group (gnus-status-message group)))
5295
5296     (when gnus-agent
5297       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5298
5299       (setq gnus-summary-use-undownloaded-faces
5300             (gnus-agent-find-parameter
5301              group
5302              'agent-enable-undownloaded-faces)))
5303
5304     (setq gnus-newsgroup-name group
5305           gnus-newsgroup-unselected nil
5306           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5307
5308     (let ((display (gnus-group-find-parameter group 'display)))
5309       (setq gnus-newsgroup-display
5310             (cond
5311              ((not (zerop (or (car-safe read-all) 0)))
5312               ;; The user entered the group with C-u SPC/RET, let's show
5313               ;; all articles.
5314               'gnus-not-ignore)
5315              ((eq display 'all)
5316               'gnus-not-ignore)
5317              ((arrayp display)
5318               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5319              ((numberp display)
5320               ;; The following is probably the "correct" solution, but
5321               ;; it makes Gnus fetch all headers and then limit the
5322               ;; articles (which is slow), so instead we hack the
5323               ;; select-articles parameter instead. -- Simon Josefsson
5324               ;; <jas@kth.se>
5325               ;;
5326               ;; (gnus-byte-compile
5327               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5328               ;;                         display)))))
5329               (setq select-articles
5330                     (gnus-uncompress-range
5331                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5332                              (if (> tmp 0)
5333                                  tmp
5334                                1))
5335                            (cdr (gnus-active group)))))
5336               nil)
5337              (t
5338               nil))))
5339
5340     (gnus-summary-setup-default-charset)
5341
5342     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5343     (when (gnus-virtual-group-p group)
5344       (setq cached gnus-newsgroup-cached))
5345
5346     (setq gnus-newsgroup-unreads
5347           (gnus-sorted-ndifference
5348            (gnus-sorted-ndifference gnus-newsgroup-unreads
5349                                     gnus-newsgroup-marked)
5350            gnus-newsgroup-dormant))
5351
5352     (setq gnus-newsgroup-processable nil)
5353
5354     (gnus-update-read-articles group gnus-newsgroup-unreads)
5355
5356     ;; Adjust and set lists of article marks.
5357     (when info
5358       (gnus-adjust-marked-articles info))
5359     (if (setq articles select-articles)
5360         (setq gnus-newsgroup-unselected
5361               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5362       (setq articles (gnus-articles-to-read group read-all)))
5363
5364     (cond
5365      ((null articles)
5366       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5367       'quit)
5368      ((eq articles 0) nil)
5369      (t
5370       ;; Init the dependencies hash table.
5371       (setq gnus-newsgroup-dependencies
5372             (gnus-make-hashtable (length articles)))
5373       (gnus-set-global-variables)
5374       ;; Retrieve the headers and read them in.
5375
5376       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5377
5378       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5379       (when cached
5380         (setq gnus-newsgroup-cached cached))
5381
5382       ;; Suppress duplicates?
5383       (when gnus-suppress-duplicates
5384         (gnus-dup-suppress-articles))
5385
5386       ;; Set the initial limit.
5387       (setq gnus-newsgroup-limit (copy-sequence articles))
5388       ;; Remove canceled articles from the list of unread articles.
5389       (setq fetched-articles
5390             (mapcar (lambda (headers) (mail-header-number headers))
5391                     gnus-newsgroup-headers))
5392       (setq gnus-newsgroup-articles fetched-articles)
5393       (setq gnus-newsgroup-unreads
5394             (gnus-sorted-nintersection
5395              gnus-newsgroup-unreads fetched-articles))
5396       (gnus-compute-unseen-list)
5397
5398       ;; Removed marked articles that do not exist.
5399       (gnus-update-missing-marks
5400        (gnus-sorted-difference articles fetched-articles))
5401       ;; We might want to build some more threads first.
5402       (when (and gnus-fetch-old-headers
5403                  (eq gnus-headers-retrieved-by 'nov))
5404         (if (eq gnus-fetch-old-headers 'invisible)
5405             (gnus-build-all-threads)
5406           (gnus-build-old-threads)))
5407       ;; Let the Gnus agent mark articles as read.
5408       (when gnus-agent
5409         (gnus-agent-get-undownloaded-list))
5410       ;; Remove list identifiers from subject
5411       (when gnus-list-identifiers
5412         (gnus-summary-remove-list-identifiers))
5413       ;; Check whether auto-expire is to be done in this group.
5414       (setq gnus-newsgroup-auto-expire
5415             (gnus-group-auto-expirable-p group))
5416       ;; Set up the article buffer now, if necessary.
5417       (unless gnus-single-article-buffer
5418         (gnus-article-setup-buffer))
5419       ;; First and last article in this newsgroup.
5420       (when gnus-newsgroup-headers
5421         (setq gnus-newsgroup-begin
5422               (mail-header-number (car gnus-newsgroup-headers))
5423               gnus-newsgroup-end
5424               (mail-header-number
5425                (gnus-last-element gnus-newsgroup-headers))))
5426       ;; GROUP is successfully selected.
5427       (or gnus-newsgroup-headers t)))))
5428
5429 (defun gnus-compute-unseen-list ()
5430   ;; The `seen' marks are treated specially.
5431   (if (not gnus-newsgroup-seen)
5432       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5433     (setq gnus-newsgroup-unseen
5434           (gnus-inverse-list-range-intersection
5435            gnus-newsgroup-articles gnus-newsgroup-seen))))
5436
5437 (defun gnus-summary-display-make-predicate (display)
5438   (require 'gnus-agent)
5439   (when (= (length display) 1)
5440     (setq display (car display)))
5441   (unless gnus-summary-display-cache
5442     (dolist (elem (append '((unread . unread)
5443                             (read . read)
5444                             (unseen . unseen))
5445                           gnus-article-mark-lists))
5446       (push (cons (cdr elem)
5447                   (gnus-byte-compile
5448                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5449             gnus-summary-display-cache)))
5450   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5451         (gnus-category-predicate-cache gnus-summary-display-cache))
5452     (gnus-get-predicate display)))
5453
5454 ;; Uses the dynamically bound `number' variable.
5455 (eval-when-compile
5456   (defvar number))
5457 (defun gnus-article-marked-p (type &optional article)
5458   (let ((article (or article number)))
5459     (cond
5460      ((eq type 'tick)
5461       (memq article gnus-newsgroup-marked))
5462      ((eq type 'spam)
5463       (memq article gnus-newsgroup-spam-marked))
5464      ((eq type 'unsend)
5465       (memq article gnus-newsgroup-unsendable))
5466      ((eq type 'undownload)
5467       (memq article gnus-newsgroup-undownloaded))
5468      ((eq type 'download)
5469       (memq article gnus-newsgroup-downloadable))
5470      ((eq type 'unread)
5471       (memq article gnus-newsgroup-unreads))
5472      ((eq type 'read)
5473       (memq article gnus-newsgroup-reads))
5474      ((eq type 'dormant)
5475       (memq article gnus-newsgroup-dormant) )
5476      ((eq type 'expire)
5477       (memq article gnus-newsgroup-expirable))
5478      ((eq type 'reply)
5479       (memq article gnus-newsgroup-replied))
5480      ((eq type 'killed)
5481       (memq article gnus-newsgroup-killed))
5482      ((eq type 'bookmark)
5483       (assq article gnus-newsgroup-bookmarks))
5484      ((eq type 'score)
5485       (assq article gnus-newsgroup-scored))
5486      ((eq type 'save)
5487       (memq article gnus-newsgroup-saved))
5488      ((eq type 'cache)
5489       (memq article gnus-newsgroup-cached))
5490      ((eq type 'forward)
5491       (memq article gnus-newsgroup-forwarded))
5492      ((eq type 'seen)
5493       (not (memq article gnus-newsgroup-unseen)))
5494      ((eq type 'recent)
5495       (memq article gnus-newsgroup-recent))
5496      (t t))))
5497
5498 (defun gnus-articles-to-read (group &optional read-all)
5499   "Find out what articles the user wants to read."
5500   (let* ((articles
5501           ;; Select all articles if `read-all' is non-nil, or if there
5502           ;; are no unread articles.
5503           (if (or read-all
5504                   (and (zerop (length gnus-newsgroup-marked))
5505                        (zerop (length gnus-newsgroup-unreads)))
5506                   ;; Fetch all if the predicate is non-nil.
5507                   gnus-newsgroup-display)
5508               ;; We want to select the headers for all the articles in
5509               ;; the group, so we select either all the active
5510               ;; articles in the group, or (if that's nil), the
5511               ;; articles in the cache.
5512               (or
5513                (gnus-uncompress-range (gnus-active group))
5514                (gnus-cache-articles-in-group group))
5515             ;; Select only the "normal" subset of articles.
5516             (gnus-sorted-nunion
5517              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5518              gnus-newsgroup-unreads)))
5519          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5520          (scored (length scored-list))
5521          (number (length articles))
5522          (marked (+ (length gnus-newsgroup-marked)
5523                     (length gnus-newsgroup-dormant)))
5524          (select
5525           (cond
5526            ((numberp read-all)
5527             read-all)
5528            ((numberp gnus-newsgroup-display)
5529             gnus-newsgroup-display)
5530            (t
5531             (condition-case ()
5532                 (cond
5533                  ((and (or (<= scored marked) (= scored number))
5534                        (numberp gnus-large-newsgroup)
5535                        (> number gnus-large-newsgroup))
5536                   (let* ((cursor-in-echo-area nil)
5537                          (initial (gnus-parameter-large-newsgroup-initial
5538                                    gnus-newsgroup-name))
5539                          (input
5540                           (read-string
5541                            (format
5542                             "How many articles from %s (%s %d): "
5543                             (gnus-limit-string
5544                              (gnus-group-decoded-name gnus-newsgroup-name)
5545                              35)
5546                             (if initial "max" "default")
5547                             number)
5548                            (if initial
5549                                (cons (number-to-string initial)
5550                                      0)))))
5551                     (if (string-match "^[ \t]*$" input) number input)))
5552                  ((and (> scored marked) (< scored number)
5553                        (> (- scored number) 20))
5554                   (let ((input
5555                          (read-string
5556                           (format "%s %s (%d scored, %d total): "
5557                                   "How many articles from"
5558                                   (gnus-group-decoded-name group)
5559                                   scored number))))
5560                     (if (string-match "^[ \t]*$" input)
5561                         number input)))
5562                  (t number))
5563               (quit
5564                (message "Quit getting the articles to read")
5565                nil))))))
5566     (setq select (if (stringp select) (string-to-number select) select))
5567     (if (or (null select) (zerop select))
5568         select
5569       (if (and (not (zerop scored)) (<= (abs select) scored))
5570           (progn
5571             (setq articles (sort scored-list '<))
5572             (setq number (length articles)))
5573         (setq articles (copy-sequence articles)))
5574
5575       (when (< (abs select) number)
5576         (if (< select 0)
5577             ;; Select the N oldest articles.
5578             (setcdr (nthcdr (1- (abs select)) articles) nil)
5579           ;; Select the N most recent articles.
5580           (setq articles (nthcdr (- number select) articles))))
5581       (setq gnus-newsgroup-unselected
5582             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5583       (when gnus-alter-articles-to-read-function
5584         (setq articles
5585               (sort
5586                (funcall gnus-alter-articles-to-read-function
5587                         gnus-newsgroup-name articles)
5588                '<)))
5589       articles)))
5590
5591 (defun gnus-killed-articles (killed articles)
5592   (let (out)
5593     (while articles
5594       (when (inline (gnus-member-of-range (car articles) killed))
5595         (push (car articles) out))
5596       (setq articles (cdr articles)))
5597     out))
5598
5599 (defun gnus-uncompress-marks (marks)
5600   "Uncompress the mark ranges in MARKS."
5601   (let ((uncompressed '(score bookmark))
5602         out)
5603     (while marks
5604       (if (memq (caar marks) uncompressed)
5605           (push (car marks) out)
5606         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5607       (setq marks (cdr marks)))
5608     out))
5609
5610 (defun gnus-article-mark-to-type (mark)
5611   "Return the type of MARK."
5612   (or (cadr (assq mark gnus-article-special-mark-lists))
5613       'list))
5614
5615 (defun gnus-article-unpropagatable-p (mark)
5616   "Return whether MARK should be propagated to back end."
5617   (memq mark gnus-article-unpropagated-mark-lists))
5618
5619 (defun gnus-adjust-marked-articles (info)
5620   "Set all article lists and remove all marks that are no longer valid."
5621   (let* ((marked-lists (gnus-info-marks info))
5622          (active (gnus-active (gnus-info-group info)))
5623          (min (car active))
5624          (max (cdr active))
5625          (types gnus-article-mark-lists)
5626          marks var articles article mark mark-type
5627          bgn end)
5628
5629     (dolist (marks marked-lists)
5630       (setq mark (car marks)
5631             mark-type (gnus-article-mark-to-type mark)
5632             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5633
5634       ;; We set the variable according to the type of the marks list,
5635       ;; and then adjust the marks to a subset of the active articles.
5636       (cond
5637        ;; Adjust "simple" lists - compressed yet unsorted
5638        ((eq mark-type 'list)
5639         ;; Simultaneously uncompress and clip to active range
5640         ;; See gnus-uncompress-range for a description of possible marks
5641         (let (l lh)
5642           (if (not (cadr marks))
5643               (set var nil)
5644             (setq articles (if (numberp (cddr marks))
5645                                (list (cdr marks))
5646                              (cdr marks))
5647                   lh (cons nil nil)
5648                   l lh)
5649
5650             (while (setq article (pop articles))
5651               (cond ((consp article)
5652                      (setq bgn (max (car article) min)
5653                            end (min (cdr article) max))
5654                      (while (<= bgn end)
5655                        (setq l (setcdr l (cons bgn nil))
5656                              bgn (1+ bgn))))
5657                     ((and (<= min article)
5658                           (>= max article))
5659                      (setq l (setcdr l (cons article nil))))))
5660             (set var (cdr lh)))))
5661        ;; Adjust assocs.
5662        ((eq mark-type 'tuple)
5663         (set var (setq articles (cdr marks)))
5664         (when (not (listp (cdr (symbol-value var))))
5665           (set var (list (symbol-value var))))
5666         (when (not (listp (cdr articles)))
5667           (setq articles (list articles)))
5668         (while articles
5669           (when (or (not (consp (setq article (pop articles))))
5670                     (< (car article) min)
5671                     (> (car article) max))
5672             (set var (delq article (symbol-value var))))))
5673        ;; Adjust ranges (sloppily).
5674        ((eq mark-type 'range)
5675         (cond
5676          ((eq mark 'seen)
5677           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5678           ;; It should be (seen (NUM1 . NUM2)).
5679           (when (numberp (cddr marks))
5680             (setcdr marks (list (cdr marks))))
5681           (setq articles (cdr marks))
5682           (while (and articles
5683                       (or (and (consp (car articles))
5684                                (> min (cdar articles)))
5685                           (and (numberp (car articles))
5686                                (> min (car articles)))))
5687             (pop articles))
5688           (set var articles))))))))
5689
5690 (defun gnus-update-missing-marks (missing)
5691   "Go through the list of MISSING articles and remove them from the mark lists."
5692   (when missing
5693     (let (var m)
5694       ;; Go through all types.
5695       (dolist (elem gnus-article-mark-lists)
5696         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5697           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5698           (when (symbol-value var)
5699             ;; This list has articles.  So we delete all missing
5700             ;; articles from it.
5701             (setq m missing)
5702             (while m
5703               (set var (delq (pop m) (symbol-value var))))))))))
5704
5705 (defun gnus-update-marks ()
5706   "Enter the various lists of marked articles into the newsgroup info list."
5707   (let ((types gnus-article-mark-lists)
5708         (info (gnus-get-info gnus-newsgroup-name))
5709         type list newmarked symbol delta-marks)
5710     (when info
5711       ;; Add all marks lists to the list of marks lists.
5712       (while (setq type (pop types))
5713         (setq list (symbol-value
5714                     (setq symbol
5715                           (intern (format "gnus-newsgroup-%s" (car type))))))
5716
5717         (when list
5718           ;; Get rid of the entries of the articles that have the
5719           ;; default score.
5720           (when (and (eq (cdr type) 'score)
5721                      gnus-save-score
5722                      list)
5723             (let* ((arts list)
5724                    (prev (cons nil list))
5725                    (all prev))
5726               (while arts
5727                 (if (or (not (consp (car arts)))
5728                         (= (cdar arts) gnus-summary-default-score))
5729                     (setcdr prev (cdr arts))
5730                   (setq prev arts))
5731                 (setq arts (cdr arts)))
5732               (setq list (cdr all)))))
5733
5734         (when (eq (cdr type) 'seen)
5735           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5736
5737         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5738           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5739
5740         (when (and (gnus-check-backend-function
5741                     'request-set-mark gnus-newsgroup-name)
5742                    (not (gnus-article-unpropagatable-p (cdr type))))
5743           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5744                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5745                  (add (gnus-remove-from-range
5746                        (gnus-copy-sequence list) old)))
5747             (when add
5748               (push (list add 'add (list (cdr type))) delta-marks))
5749             (when del
5750               (push (list del 'del (list (cdr type))) delta-marks))))
5751
5752         (when list
5753           (push (cons (cdr type) list) newmarked)))
5754
5755       (when delta-marks
5756         (unless (gnus-check-group gnus-newsgroup-name)
5757           (error "Can't open server for %s" gnus-newsgroup-name))
5758         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5759
5760       ;; Enter these new marks into the info of the group.
5761       (if (nthcdr 3 info)
5762           (setcar (nthcdr 3 info) newmarked)
5763         ;; Add the marks lists to the end of the info.
5764         (when newmarked
5765           (setcdr (nthcdr 2 info) (list newmarked))))
5766
5767       ;; Cut off the end of the info if there's nothing else there.
5768       (let ((i 5))
5769         (while (and (> i 2)
5770                     (not (nth i info)))
5771           (when (nthcdr (decf i) info)
5772             (setcdr (nthcdr i info) nil)))))))
5773
5774 (defun gnus-set-mode-line (where)
5775   "Set the mode line of the article or summary buffers.
5776 If WHERE is `summary', the summary mode line format will be used."
5777   ;; Is this mode line one we keep updated?
5778   (when (and (memq where gnus-updated-mode-lines)
5779              (symbol-value
5780               (intern (format "gnus-%s-mode-line-format-spec" where))))
5781     (let (mode-string)
5782       (save-excursion
5783         ;; We evaluate this in the summary buffer since these
5784         ;; variables are buffer-local to that buffer.
5785         (set-buffer gnus-summary-buffer)
5786        ;; We bind all these variables that are used in the `eval' form
5787         ;; below.
5788         (let* ((mformat (symbol-value
5789                          (intern
5790                           (format "gnus-%s-mode-line-format-spec" where))))
5791                (gnus-tmp-group-name (gnus-group-decoded-name
5792                                      gnus-newsgroup-name))
5793                (gnus-tmp-article-number (or gnus-current-article 0))
5794                (gnus-tmp-unread gnus-newsgroup-unreads)
5795                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5796                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5797                (gnus-tmp-unread-and-unselected
5798                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5799                             (zerop gnus-tmp-unselected))
5800                        "")
5801                       ((zerop gnus-tmp-unselected)
5802                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5803                       (t (format "{%d(+%d) more}"
5804                                  gnus-tmp-unread-and-unticked
5805                                  gnus-tmp-unselected))))
5806                (gnus-tmp-subject
5807                 (if (and gnus-current-headers
5808                          (vectorp gnus-current-headers))
5809                     (gnus-mode-string-quote
5810                      (mail-header-subject gnus-current-headers))
5811                   ""))
5812                bufname-length max-len
5813                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5814           (setq mode-string (eval mformat))
5815           (setq bufname-length (if (string-match "%b" mode-string)
5816                                    (- (length
5817                                        (buffer-name
5818                                         (if (eq where 'summary)
5819                                             nil
5820                                           (get-buffer gnus-article-buffer))))
5821                                       2)
5822                                  0))
5823           (setq max-len (max 4 (if gnus-mode-non-string-length
5824                                    (- (window-width)
5825                                       gnus-mode-non-string-length
5826                                       bufname-length)
5827                                  (length mode-string))))
5828           ;; We might have to chop a bit of the string off...
5829           (when (> (length mode-string) max-len)
5830             (setq mode-string
5831                   (concat (truncate-string-to-width mode-string (- max-len 3))
5832                           "...")))
5833           ;; Pad the mode string a bit.
5834           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5835       ;; Update the mode line.
5836       (setq mode-line-buffer-identification
5837             (gnus-mode-line-buffer-identification (list mode-string)))
5838       (set-buffer-modified-p t))))
5839
5840 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5841   "Go through the HEADERS list and add all Xrefs to a hash table.
5842 The resulting hash table is returned, or nil if no Xrefs were found."
5843   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5844          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5845          (xref-hashtb (gnus-make-hashtable))
5846          start group entry number xrefs header)
5847     (while headers
5848       (setq header (pop headers))
5849       (when (and (setq xrefs (mail-header-xref header))
5850                  (not (memq (setq number (mail-header-number header))
5851                             unreads)))
5852         (setq start 0)
5853         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5854           (setq start (match-end 0))
5855           (setq group (if prefix
5856                           (concat prefix (substring xrefs (match-beginning 1)
5857                                                     (match-end 1)))
5858                         (substring xrefs (match-beginning 1) (match-end 1))))
5859           (setq number
5860                 (string-to-number (substring xrefs (match-beginning 2)
5861                                           (match-end 2))))
5862           (if (setq entry (gnus-gethash group xref-hashtb))
5863               (setcdr entry (cons number (cdr entry)))
5864             (gnus-sethash group (cons number nil) xref-hashtb)))))
5865     (and start xref-hashtb)))
5866
5867 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5868   "Look through all the headers and mark the Xrefs as read."
5869   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5870         name info xref-hashtb idlist method nth4)
5871     (save-excursion
5872       (set-buffer gnus-group-buffer)
5873       (when (setq xref-hashtb
5874                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5875         (mapatoms
5876          (lambda (group)
5877            (unless (string= from-newsgroup (setq name (symbol-name group)))
5878              (setq idlist (symbol-value group))
5879              ;; Dead groups are not updated.
5880              (and (prog1
5881                       (setq info (gnus-get-info name))
5882                     (when (stringp (setq nth4 (gnus-info-method info)))
5883                       (setq nth4 (gnus-server-to-method nth4))))
5884                   ;; Only do the xrefs if the group has the same
5885                   ;; select method as the group we have just read.
5886                   (or (gnus-methods-equal-p
5887                        nth4 (gnus-find-method-for-group from-newsgroup))
5888                       virtual
5889                       (equal nth4 (setq method (gnus-find-method-for-group
5890                                                 from-newsgroup)))
5891                       (and (equal (car nth4) (car method))
5892                            (equal (nth 1 nth4) (nth 1 method))))
5893                   gnus-use-cross-reference
5894                   (or (not (eq gnus-use-cross-reference t))
5895                       virtual
5896                       ;; Only do cross-references on subscribed
5897                       ;; groups, if that is what is wanted.
5898                       (<= (gnus-info-level info) gnus-level-subscribed))
5899                   (gnus-group-make-articles-read name idlist))))
5900          xref-hashtb)))))
5901
5902 (defun gnus-compute-read-articles (group articles)
5903   (let* ((entry (gnus-group-entry group))
5904          (info (nth 2 entry))
5905          (active (gnus-active group))
5906          ninfo)
5907     (when entry
5908       ;; First peel off all invalid article numbers.
5909       (when active
5910         (let ((ids articles)
5911               id first)
5912           (while (setq id (pop ids))
5913             (when (and first (> id (cdr active)))
5914               ;; We'll end up in this situation in one particular
5915               ;; obscure situation.  If you re-scan a group and get
5916               ;; a new article that is cross-posted to a different
5917               ;; group that has not been re-scanned, you might get
5918               ;; crossposted article that has a higher number than
5919               ;; Gnus believes possible.  So we re-activate this
5920               ;; group as well.  This might mean doing the
5921               ;; crossposting thingy will *increase* the number
5922               ;; of articles in some groups.  Tsk, tsk.
5923               (setq active (or (gnus-activate-group group) active)))
5924             (when (or (> id (cdr active))
5925                       (< id (car active)))
5926               (setq articles (delq id articles))))))
5927       ;; If the read list is nil, we init it.
5928       (if (and active
5929                (null (gnus-info-read info))
5930                (> (car active) 1))
5931           (setq ninfo (cons 1 (1- (car active))))
5932         (setq ninfo (gnus-info-read info)))
5933       ;; Then we add the read articles to the range.
5934       (gnus-add-to-range
5935        ninfo (setq articles (sort articles '<))))))
5936
5937 (defun gnus-group-make-articles-read (group articles)
5938   "Update the info of GROUP to say that ARTICLES are read."
5939   (let* ((num 0)
5940          (entry (gnus-group-entry group))
5941          (info (nth 2 entry))
5942          (active (gnus-active group))
5943          range)
5944     (when entry
5945       (setq range (gnus-compute-read-articles group articles))
5946       (with-current-buffer gnus-group-buffer
5947         (gnus-undo-register
5948           `(progn
5949              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5950              (gnus-info-set-read ',info ',(gnus-info-read info))
5951              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5952              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5953              (gnus-group-update-group ,group t))))
5954       ;; Add the read articles to the range.
5955       (gnus-info-set-read info range)
5956       (gnus-request-set-mark group (list (list range 'add '(read))))
5957       ;; Then we have to re-compute how many unread
5958       ;; articles there are in this group.
5959       (when active
5960         (cond
5961          ((not range)
5962           (setq num (- (1+ (cdr active)) (car active))))
5963          ((not (listp (cdr range)))
5964           (setq num (- (cdr active) (- (1+ (cdr range))
5965                                        (car range)))))
5966          (t
5967           (while range
5968             (if (numberp (car range))
5969                 (setq num (1+ num))
5970               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5971             (setq range (cdr range)))
5972           (setq num (- (cdr active) num))))
5973         ;; Update the number of unread articles.
5974         (setcar entry num)
5975         ;; Update the group buffer.
5976         (unless (gnus-ephemeral-group-p group)
5977           (gnus-group-update-group group t))))))
5978
5979 (defvar gnus-newsgroup-none-id 0)
5980
5981 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5982   (let ((cur nntp-server-buffer)
5983         (dependencies
5984          (or dependencies
5985              (with-current-buffer gnus-summary-buffer
5986                gnus-newsgroup-dependencies)))
5987         headers id end ref number
5988         (mail-parse-charset gnus-newsgroup-charset)
5989         (mail-parse-ignored-charsets
5990          (save-excursion (condition-case nil
5991                              (set-buffer gnus-summary-buffer)
5992                            (error))
5993                          gnus-newsgroup-ignored-charsets)))
5994     (save-excursion
5995       (set-buffer nntp-server-buffer)
5996       ;; Translate all TAB characters into SPACE characters.
5997       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5998       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5999       (ietf-drums-unfold-fws)
6000       (gnus-run-hooks 'gnus-parse-headers-hook)
6001       (let ((case-fold-search t)
6002             in-reply-to header p lines chars)
6003         (goto-char (point-min))
6004         ;; Search to the beginning of the next header.  Error messages
6005         ;; do not begin with 2 or 3.
6006         (while (re-search-forward "^[23][0-9]+ " nil t)
6007           (setq id nil
6008                 ref nil)
6009           ;; This implementation of this function, with nine
6010           ;; search-forwards instead of the one re-search-forward and
6011           ;; a case (which basically was the old function) is actually
6012           ;; about twice as fast, even though it looks messier.  You
6013           ;; can't have everything, I guess.  Speed and elegance
6014           ;; doesn't always go hand in hand.
6015           (setq
6016            header
6017            (vector
6018             ;; Number.
6019             (prog1
6020                 (setq number (read cur))
6021               (end-of-line)
6022               (setq p (point))
6023               (narrow-to-region (point)
6024                                 (or (and (search-forward "\n.\n" nil t)
6025                                          (- (point) 2))
6026                                     (point))))
6027             ;; Subject.
6028             (progn
6029               (goto-char p)
6030               (if (search-forward "\nsubject:" nil t)
6031                   (funcall gnus-decode-encoded-word-function
6032                            (nnheader-header-value))
6033                 "(none)"))
6034             ;; From.
6035             (progn
6036               (goto-char p)
6037               (if (search-forward "\nfrom:" nil t)
6038                   (funcall gnus-decode-encoded-word-function
6039                            (nnheader-header-value))
6040                 "(nobody)"))
6041             ;; Date.
6042             (progn
6043               (goto-char p)
6044               (if (search-forward "\ndate:" nil t)
6045                   (nnheader-header-value) ""))
6046             ;; Message-ID.
6047             (progn
6048               (goto-char p)
6049               (setq id (if (re-search-forward
6050                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6051                            ;; We do it this way to make sure the Message-ID
6052                            ;; is (somewhat) syntactically valid.
6053                            (buffer-substring (match-beginning 1)
6054                                              (match-end 1))
6055                          ;; If there was no message-id, we just fake one
6056                          ;; to make subsequent routines simpler.
6057                          (nnheader-generate-fake-message-id number))))
6058             ;; References.
6059             (progn
6060               (goto-char p)
6061               (if (search-forward "\nreferences:" nil t)
6062                   (progn
6063                     (setq end (point))
6064                     (prog1
6065                         (nnheader-header-value)
6066                       (setq ref
6067                             (buffer-substring
6068                              (progn
6069                                (end-of-line)
6070                                (search-backward ">" end t)
6071                                (1+ (point)))
6072                              (progn
6073                                (search-backward "<" end t)
6074                                (point))))))
6075                 ;; Get the references from the in-reply-to header if there
6076                 ;; were no references and the in-reply-to header looks
6077                 ;; promising.
6078                 (if (and (search-forward "\nin-reply-to:" nil t)
6079                          (setq in-reply-to (nnheader-header-value))
6080                          (string-match "<[^>]+>" in-reply-to))
6081                     (let (ref2)
6082                       (setq ref (substring in-reply-to (match-beginning 0)
6083                                            (match-end 0)))
6084                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6085                         (setq ref2 (substring in-reply-to (match-beginning 0)
6086                                               (match-end 0)))
6087                         (when (> (length ref2) (length ref))
6088                           (setq ref ref2)))
6089                       ref)
6090                   (setq ref nil))))
6091             ;; Chars.
6092             (progn
6093               (goto-char p)
6094               (if (search-forward "\nchars: " nil t)
6095                   (if (numberp (setq chars (ignore-errors (read cur))))
6096                       chars -1)
6097                 -1))
6098             ;; Lines.
6099             (progn
6100               (goto-char p)
6101               (if (search-forward "\nlines: " nil t)
6102                   (if (numberp (setq lines (ignore-errors (read cur))))
6103                       lines -1)
6104                 -1))
6105             ;; Xref.
6106             (progn
6107               (goto-char p)
6108               (and (search-forward "\nxref:" nil t)
6109                    (nnheader-header-value)))
6110             ;; Extra.
6111             (when gnus-extra-headers
6112               (let ((extra gnus-extra-headers)
6113                     out)
6114                 (while extra
6115                   (goto-char p)
6116                   (when (search-forward
6117                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6118                     (push (cons (car extra) (nnheader-header-value))
6119                           out))
6120                   (pop extra))
6121                 out))))
6122           (when (equal id ref)
6123             (setq ref nil))
6124
6125           (when gnus-alter-header-function
6126             (funcall gnus-alter-header-function header)
6127             (setq id (mail-header-id header)
6128                   ref (gnus-parent-id (mail-header-references header))))
6129
6130           (when (setq header
6131                       (gnus-dependencies-add-header
6132                        header dependencies force-new))
6133             (push header headers))
6134           (goto-char (point-max))
6135           (widen))
6136         (nreverse headers)))))
6137
6138 ;; Goes through the xover lines and returns a list of vectors
6139 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6140                                                   force-new dependencies
6141                                                   group also-fetch-heads)
6142   "Parse the news overview data in the server buffer.
6143 Return a list of headers that match SEQUENCE (see
6144 `nntp-retrieve-headers')."
6145   ;; Get the Xref when the users reads the articles since most/some
6146   ;; NNTP servers do not include Xrefs when using XOVER.
6147   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6148   (let ((mail-parse-charset gnus-newsgroup-charset)
6149         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6150         (cur nntp-server-buffer)
6151         (dependencies (or dependencies gnus-newsgroup-dependencies))
6152         (allp (cond
6153                ((eq gnus-read-all-available-headers t)
6154                 t)
6155                ((stringp gnus-read-all-available-headers)
6156                 (string-match gnus-read-all-available-headers group))
6157                (t
6158                 nil)))
6159         number headers header)
6160     (save-excursion
6161       (set-buffer nntp-server-buffer)
6162       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6163       ;; Allow the user to mangle the headers before parsing them.
6164       (gnus-run-hooks 'gnus-parse-headers-hook)
6165       (goto-char (point-min))
6166       (gnus-parse-without-error
6167         (while (and (or sequence allp)
6168                     (not (eobp)))
6169           (setq number (read cur))
6170           (when (not allp)
6171             (while (and sequence
6172                         (< (car sequence) number))
6173               (setq sequence (cdr sequence))))
6174           (when (and (or allp
6175                          (and sequence
6176                               (eq number (car sequence))))
6177                      (progn
6178                        (setq sequence (cdr sequence))
6179                        (setq header (inline
6180                                       (gnus-nov-parse-line
6181                                        number dependencies force-new)))))
6182             (push header headers))
6183           (forward-line 1)))
6184       ;; A common bug in inn is that if you have posted an article and
6185       ;; then retrieves the active file, it will answer correctly --
6186       ;; the new article is included.  However, a NOV entry for the
6187       ;; article may not have been generated yet, so this may fail.
6188       ;; We work around this problem by retrieving the last few
6189       ;; headers using HEAD.
6190       (if (or (not also-fetch-heads)
6191               (not sequence))
6192           ;; We (probably) got all the headers.
6193           (nreverse headers)
6194         (let ((gnus-nov-is-evil t))
6195           (nconc
6196            (nreverse headers)
6197            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6198              (gnus-get-newsgroup-headers))))))))
6199
6200 (defun gnus-article-get-xrefs ()
6201   "Fill in the Xref value in `gnus-current-headers', if necessary.
6202 This is meant to be called in `gnus-article-internal-prepare-hook'."
6203   (let ((headers (with-current-buffer gnus-summary-buffer
6204                    gnus-current-headers)))
6205     (or (not gnus-use-cross-reference)
6206         (not headers)
6207         (and (mail-header-xref headers)
6208              (not (string= (mail-header-xref headers) "")))
6209         (let ((case-fold-search t)
6210               xref)
6211           (save-restriction
6212             (nnheader-narrow-to-headers)
6213             (goto-char (point-min))
6214             (when (or (and (not (eobp))
6215                            (eq (downcase (char-after)) ?x)
6216                            (looking-at "Xref:"))
6217                       (search-forward "\nXref:" nil t))
6218               (goto-char (1+ (match-end 0)))
6219               (setq xref (buffer-substring (point) (point-at-eol)))
6220               (mail-header-set-xref headers xref)))))))
6221
6222 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6223   "Find article ID and insert the summary line for that article.
6224 OLD-HEADER can either be a header or a line number to insert
6225 the subject line on."
6226   (let* ((line (and (numberp old-header) old-header))
6227          (old-header (and (vectorp old-header) old-header))
6228          (header (cond ((and old-header use-old-header)
6229                         old-header)
6230                        ((and (numberp id)
6231                              (gnus-number-to-header id))
6232                         (gnus-number-to-header id))
6233                        (t
6234                         (gnus-read-header id))))
6235          (number (and (numberp id) id))
6236          d)
6237     (when header
6238       ;; Rebuild the thread that this article is part of and go to the
6239       ;; article we have fetched.
6240       (when (and (not gnus-show-threads)
6241                  old-header)
6242         (when (and number
6243                    (setq d (gnus-data-find (mail-header-number old-header))))
6244           (goto-char (gnus-data-pos d))
6245           (gnus-data-remove
6246            number
6247            (- (point-at-bol)
6248               (prog1
6249                   (1+ (point-at-eol))
6250                 (gnus-delete-line))))))
6251       ;; Remove list identifiers from subject.
6252       (when gnus-list-identifiers
6253         (let ((gnus-newsgroup-headers (list header)))
6254           (gnus-summary-remove-list-identifiers)))
6255       (when old-header
6256         (mail-header-set-number header (mail-header-number old-header)))
6257       (setq gnus-newsgroup-sparse
6258             (delq (setq number (mail-header-number header))
6259                   gnus-newsgroup-sparse))
6260       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6261       (push number gnus-newsgroup-limit)
6262       (gnus-rebuild-thread (mail-header-id header) line)
6263       (gnus-summary-goto-subject number nil t))
6264     (when (and (numberp number)
6265                (> number 0))
6266       ;; We have to update the boundaries even if we can't fetch the
6267       ;; article if ID is a number -- so that the next `P' or `N'
6268       ;; command will fetch the previous (or next) article even
6269       ;; if the one we tried to fetch this time has been canceled.
6270       (when (> number gnus-newsgroup-end)
6271         (setq gnus-newsgroup-end number))
6272       (when (< number gnus-newsgroup-begin)
6273         (setq gnus-newsgroup-begin number))
6274       (setq gnus-newsgroup-unselected
6275             (delq number gnus-newsgroup-unselected)))
6276     ;; Report back a success?
6277     (and header (mail-header-number header))))
6278
6279 ;;; Process/prefix in the summary buffer
6280
6281 (defun gnus-summary-work-articles (n)
6282   "Return a list of articles to be worked upon.
6283 The prefix argument, the list of process marked articles, and the
6284 current article will be taken into consideration."
6285   (save-excursion
6286     (set-buffer gnus-summary-buffer)
6287     (cond
6288      (n
6289       ;; A numerical prefix has been given.
6290       (setq n (prefix-numeric-value n))
6291       (let ((backward (< n 0))
6292             (n (abs (prefix-numeric-value n)))
6293             articles article)
6294         (save-excursion
6295           (while
6296               (and (> n 0)
6297                    (push (setq article (gnus-summary-article-number))
6298                          articles)
6299                    (if backward
6300                        (gnus-summary-find-prev nil article)
6301                      (gnus-summary-find-next nil article)))
6302             (decf n)))
6303         (nreverse articles)))
6304      ((and (gnus-region-active-p) (mark))
6305       (message "region active")
6306       ;; Work on the region between point and mark.
6307       (let ((max (max (point) (mark)))
6308             articles article)
6309         (save-excursion
6310           (goto-char (min (point) (mark)))
6311           (while
6312               (and
6313                (push (setq article (gnus-summary-article-number)) articles)
6314                (gnus-summary-find-next nil article)
6315                (< (point) max)))
6316           (nreverse articles))))
6317      (gnus-newsgroup-processable
6318       ;; There are process-marked articles present.
6319       ;; Save current state.
6320       (gnus-summary-save-process-mark)
6321       ;; Return the list.
6322       (reverse gnus-newsgroup-processable))
6323      (t
6324       ;; Just return the current article.
6325       (list (gnus-summary-article-number))))))
6326
6327 (defmacro gnus-summary-iterate (arg &rest forms)
6328   "Iterate over the process/prefixed articles and do FORMS.
6329 ARG is the interactive prefix given to the command.  FORMS will be
6330 executed with point over the summary line of the articles."
6331   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6332     `(let ((,articles (gnus-summary-work-articles ,arg)))
6333        (while ,articles
6334          (gnus-summary-goto-subject (car ,articles))
6335          ,@forms
6336          (pop ,articles)))))
6337
6338 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6339 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6340
6341 (defun gnus-summary-save-process-mark ()
6342   "Push the current set of process marked articles on the stack."
6343   (interactive)
6344   (push (copy-sequence gnus-newsgroup-processable)
6345         gnus-newsgroup-process-stack))
6346
6347 (defun gnus-summary-kill-process-mark ()
6348   "Push the current set of process marked articles on the stack and unmark."
6349   (interactive)
6350   (gnus-summary-save-process-mark)
6351   (gnus-summary-unmark-all-processable))
6352
6353 (defun gnus-summary-yank-process-mark ()
6354   "Pop the last process mark state off the stack and restore it."
6355   (interactive)
6356   (unless gnus-newsgroup-process-stack
6357     (error "Empty mark stack"))
6358   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6359
6360 (defun gnus-summary-process-mark-set (set)
6361   "Make SET into the current process marked articles."
6362   (gnus-summary-unmark-all-processable)
6363   (mapc 'gnus-summary-set-process-mark set))
6364
6365 ;;; Searching and stuff
6366
6367 (defun gnus-summary-search-group (&optional backward use-level)
6368   "Search for next unread newsgroup.
6369 If optional argument BACKWARD is non-nil, search backward instead."
6370   (save-excursion
6371     (set-buffer gnus-group-buffer)
6372     (when (gnus-group-search-forward
6373            backward nil (if use-level (gnus-group-group-level) nil))
6374       (gnus-group-group-name))))
6375
6376 (defun gnus-summary-best-group (&optional exclude-group)
6377   "Find the name of the best unread group.
6378 If EXCLUDE-GROUP, do not go to this group."
6379   (with-current-buffer gnus-group-buffer
6380     (save-excursion
6381       (gnus-group-best-unread-group exclude-group))))
6382
6383 (defun gnus-summary-find-next (&optional unread article backward)
6384   (if backward
6385       (gnus-summary-find-prev unread article)
6386     (let* ((dummy (gnus-summary-article-intangible-p))
6387            (article (or article (gnus-summary-article-number)))
6388            (data (gnus-data-find-list article))
6389            result)
6390       (when (and (not dummy)
6391                  (or (not gnus-summary-check-current)
6392                      (not unread)
6393                      (not (gnus-data-unread-p (car data)))))
6394         (setq data (cdr data)))
6395       (when (setq result
6396                   (if unread
6397                       (progn
6398                         (while data
6399                           (unless (memq (gnus-data-number (car data))
6400                                         (cond
6401                                          ((eq gnus-auto-goto-ignores
6402                                               'always-undownloaded)
6403                                           gnus-newsgroup-undownloaded)
6404                                          (gnus-plugged
6405                                           nil)
6406                                          ((eq gnus-auto-goto-ignores
6407                                               'unfetched)
6408                                           gnus-newsgroup-unfetched)
6409                                          ((eq gnus-auto-goto-ignores
6410                                               'undownloaded)
6411                                           gnus-newsgroup-undownloaded)))
6412                             (when (gnus-data-unread-p (car data))
6413                               (setq result (car data)
6414                                     data nil)))
6415                           (setq data (cdr data)))
6416                         result)
6417                     (car data)))
6418         (goto-char (gnus-data-pos result))
6419         (gnus-data-number result)))))
6420
6421 (defun gnus-summary-find-prev (&optional unread article)
6422   (let* ((eobp (eobp))
6423          (article (or article (gnus-summary-article-number)))
6424          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6425          result)
6426     (when (and (not eobp)
6427                (or (not gnus-summary-check-current)
6428                    (not unread)
6429                    (not (gnus-data-unread-p (car data)))))
6430       (setq data (cdr data)))
6431     (when (setq result
6432                 (if unread
6433                     (progn
6434                       (while data
6435                         (unless (memq (gnus-data-number (car data))
6436                                       (cond
6437                                        ((eq gnus-auto-goto-ignores
6438                                             'always-undownloaded)
6439                                         gnus-newsgroup-undownloaded)
6440                                        (gnus-plugged
6441                                         nil)
6442                                        ((eq gnus-auto-goto-ignores
6443                                             'unfetched)
6444                                         gnus-newsgroup-unfetched)
6445                                        ((eq gnus-auto-goto-ignores
6446                                             'undownloaded)
6447                                         gnus-newsgroup-undownloaded)))
6448                           (when (gnus-data-unread-p (car data))
6449                             (setq result (car data)
6450                                   data nil)))
6451                         (setq data (cdr data)))
6452                       result)
6453                   (car data)))
6454       (goto-char (gnus-data-pos result))
6455       (gnus-data-number result))))
6456
6457 (defun gnus-summary-find-subject (subject &optional unread backward article)
6458   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6459          (article (or article (gnus-summary-article-number)))
6460          (articles (gnus-data-list backward))
6461          (arts (gnus-data-find-list article articles))
6462          result)
6463     (when (or (not gnus-summary-check-current)
6464               (not unread)
6465               (not (gnus-data-unread-p (car arts))))
6466       (setq arts (cdr arts)))
6467     (while arts
6468       (and (or (not unread)
6469                (gnus-data-unread-p (car arts)))
6470            (vectorp (gnus-data-header (car arts)))
6471            (gnus-subject-equal
6472             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6473            (setq result (car arts)
6474                  arts nil))
6475       (setq arts (cdr arts)))
6476     (and result
6477          (goto-char (gnus-data-pos result))
6478          (gnus-data-number result))))
6479
6480 (defun gnus-summary-search-forward (&optional unread subject backward)
6481   "Search forward for an article.
6482 If UNREAD, look for unread articles.  If SUBJECT, look for
6483 articles with that subject.  If BACKWARD, search backward instead."
6484   (cond (subject (gnus-summary-find-subject subject unread backward))
6485         (backward (gnus-summary-find-prev unread))
6486         (t (gnus-summary-find-next unread))))
6487
6488 (defun gnus-recenter (&optional n)
6489   "Center point in window and redisplay frame.
6490 Also do horizontal recentering."
6491   (interactive "P")
6492   (when (and gnus-auto-center-summary
6493              (not (eq gnus-auto-center-summary 'vertical)))
6494     (gnus-horizontal-recenter))
6495   (recenter n))
6496
6497 (defun gnus-summary-recenter ()
6498   "Center point in the summary window.
6499 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6500 displayed, no centering will be performed."
6501   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6502   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6503   (interactive)
6504   ;; The user has to want it.
6505   (when gnus-auto-center-summary
6506     (let* ((top (cond ((< (window-height) 4) 0)
6507                       ((< (window-height) 7) 1)
6508                       (t (if (numberp gnus-auto-center-summary)
6509                              gnus-auto-center-summary
6510                            (/ (1- (window-height)) 2)))))
6511            (height (1- (window-height)))
6512            (bottom (save-excursion (goto-char (point-max))
6513                                    (forward-line (- height))
6514                                    (point)))
6515            (window (get-buffer-window (current-buffer))))
6516       (when (get-buffer-window gnus-article-buffer)
6517         ;; Only do recentering when the article buffer is displayed,
6518         ;; Set the window start to either `bottom', which is the biggest
6519         ;; possible valid number, or the second line from the top,
6520         ;; whichever is the least.
6521         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6522           (if (> bottom top-pos)
6523               ;; Keep the second line from the top visible
6524               (set-window-start window top-pos t)
6525             ;; Try to keep the bottom line visible; if it's partially
6526             ;; obscured, either scroll one more line to make it fully
6527             ;; visible, or revert to using TOP-POS.
6528             (save-excursion
6529               (goto-char (point-max))
6530               (forward-line -1)
6531               (let ((last-line-start (point)))
6532                 (goto-char bottom)
6533                 (set-window-start window (point) t)
6534                 (when (not (pos-visible-in-window-p last-line-start window))
6535                   (forward-line 1)
6536                   (set-window-start window (min (point) top-pos) t)))))))
6537       ;; Do horizontal recentering while we're at it.
6538       (when (and (get-buffer-window (current-buffer) t)
6539                  (not (eq gnus-auto-center-summary 'vertical)))
6540         (let ((selected (selected-window)))
6541           (select-window (get-buffer-window (current-buffer) t))
6542           (gnus-summary-position-point)
6543           (gnus-horizontal-recenter)
6544           (select-window selected))))))
6545
6546 (defun gnus-summary-jump-to-group (newsgroup)
6547   "Move point to NEWSGROUP in group mode buffer."
6548   ;; Keep update point of group mode buffer if visible.
6549   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6550       (save-window-excursion
6551         ;; Take care of tree window mode.
6552         (when (get-buffer-window gnus-group-buffer)
6553           (pop-to-buffer gnus-group-buffer))
6554         (gnus-group-jump-to-group newsgroup))
6555     (save-excursion
6556       ;; Take care of tree window mode.
6557       (if (get-buffer-window gnus-group-buffer)
6558           (pop-to-buffer gnus-group-buffer)
6559         (set-buffer gnus-group-buffer))
6560       (gnus-group-jump-to-group newsgroup))))
6561
6562 ;; This function returns a list of article numbers based on the
6563 ;; difference between the ranges of read articles in this group and
6564 ;; the range of active articles.
6565 (defun gnus-list-of-unread-articles (group)
6566   (let* ((read (gnus-info-read (gnus-get-info group)))
6567          (active (or (gnus-active group) (gnus-activate-group group)))
6568          (last (or (cdr active)
6569                    (error "Group %s couldn't be activated " group)))
6570          first nlast unread)
6571     ;; If none are read, then all are unread.
6572     (if (not read)
6573         (setq first (car active))
6574       ;; If the range of read articles is a single range, then the
6575       ;; first unread article is the article after the last read
6576       ;; article.  Sounds logical, doesn't it?
6577       (if (and (not (listp (cdr read)))
6578                (or (< (car read) (car active))
6579                    (progn (setq read (list read))
6580                           nil)))
6581           (setq first (max (car active) (1+ (cdr read))))
6582         ;; `read' is a list of ranges.
6583         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6584                                   (caar read)))
6585                   1)
6586           (setq first (car active)))
6587         (while read
6588           (when first
6589             (while (< first nlast)
6590               (setq unread (cons first unread)
6591                     first (1+ first))))
6592           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6593           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6594           (setq read (cdr read)))))
6595     ;; And add the last unread articles.
6596     (while (<= first last)
6597       (setq unread (cons first unread)
6598             first (1+ first)))
6599     ;; Return the list of unread articles.
6600     (delq 0 (nreverse unread))))
6601
6602 (defun gnus-list-of-read-articles (group)
6603   "Return a list of unread, unticked and non-dormant articles."
6604   (let* ((info (gnus-get-info group))
6605          (marked (gnus-info-marks info))
6606          (active (gnus-active group)))
6607     (and info active
6608          (gnus-list-range-difference
6609           (gnus-list-range-difference
6610            (gnus-sorted-complement
6611             (gnus-uncompress-range active)
6612             (gnus-list-of-unread-articles group))
6613            (cdr (assq 'dormant marked)))
6614           (cdr (assq 'tick marked))))))
6615
6616 ;; This function returns a sequence of article numbers based on the
6617 ;; difference between the ranges of read articles in this group and
6618 ;; the range of active articles.
6619 (defun gnus-sequence-of-unread-articles (group)
6620   (let* ((read (gnus-info-read (gnus-get-info group)))
6621          (active (or (gnus-active group) (gnus-activate-group group)))
6622          (last (cdr active))
6623          first nlast unread)
6624     ;; If none are read, then all are unread.
6625     (if (not read)
6626         (setq first (car active))
6627       ;; If the range of read articles is a single range, then the
6628       ;; first unread article is the article after the last read
6629       ;; article.  Sounds logical, doesn't it?
6630       (if (and (not (listp (cdr read)))
6631                (or (< (car read) (car active))
6632                    (progn (setq read (list read))
6633                           nil)))
6634           (setq first (max (car active) (1+ (cdr read))))
6635         ;; `read' is a list of ranges.
6636         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6637                                   (caar read)))
6638                   1)
6639           (setq first (car active)))
6640         (while read
6641           (when first
6642             (push (cons first nlast) unread))
6643           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6644           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6645           (setq read (cdr read)))))
6646     ;; And add the last unread articles.
6647     (cond ((< first last)
6648            (push (cons first last) unread))
6649           ((= first last)
6650            (push first unread)))
6651     ;; Return the sequence of unread articles.
6652     (delq 0 (nreverse unread))))
6653
6654 ;; Various summary commands
6655
6656 (defun gnus-summary-select-article-buffer ()
6657   "Reconfigure windows to show article buffer."
6658   (interactive)
6659   (if (not (gnus-buffer-live-p gnus-article-buffer))
6660       (error "There is no article buffer for this summary buffer")
6661     (gnus-configure-windows 'article)
6662     (select-window (get-buffer-window gnus-article-buffer))))
6663
6664 (defun gnus-summary-universal-argument (arg)
6665   "Perform any operation on all articles that are process/prefixed."
6666   (interactive "P")
6667   (let ((articles (gnus-summary-work-articles arg))
6668         func article)
6669     (if (eq
6670          (setq
6671           func
6672           (key-binding
6673            (read-key-sequence
6674             (substitute-command-keys
6675              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6676          'undefined)
6677         (gnus-error 1 "Undefined key")
6678       (save-excursion
6679         (while articles
6680           (gnus-summary-goto-subject (setq article (pop articles)))
6681           (let (gnus-newsgroup-processable)
6682             (command-execute func))
6683           (gnus-summary-remove-process-mark article)))))
6684   (gnus-summary-position-point))
6685
6686 (defun gnus-summary-toggle-truncation (&optional arg)
6687   "Toggle truncation of summary lines.
6688 With ARG, turn line truncation on if ARG is positive."
6689   (interactive "P")
6690   (setq truncate-lines
6691         (if (null arg) (not truncate-lines)
6692           (> (prefix-numeric-value arg) 0)))
6693   (redraw-display))
6694
6695 (defun gnus-summary-find-for-reselect ()
6696   "Return the number of an article to stay on across a reselect.
6697 The current article is considered, then following articles, then previous
6698 articles.  An article is sought which is not cancelled and isn't a temporary
6699 insertion from another group.  If there's no such then return a dummy 0."
6700   (let (found)
6701     (dolist (rev '(nil t))
6702       (unless found      ; don't demand the reverse list if we don't need it
6703         (let ((data (gnus-data-find-list
6704                      (gnus-summary-article-number) (gnus-data-list rev))))
6705           (while (and data (not found))
6706             (if (and (< 0 (gnus-data-number (car data)))
6707                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6708                 (setq found (gnus-data-number (car data))))
6709             (setq data (cdr data))))))
6710     (or found 0)))
6711
6712 (defun gnus-summary-reselect-current-group (&optional all rescan)
6713   "Exit and then reselect the current newsgroup.
6714 The prefix argument ALL means to select all articles."
6715   (interactive "P")
6716   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6717     (error "Ephemeral groups can't be reselected"))
6718   (let ((current-subject (gnus-summary-find-for-reselect))
6719         (group gnus-newsgroup-name))
6720     (setq gnus-newsgroup-begin nil)
6721     (gnus-summary-exit nil 'leave-hidden)
6722     ;; We have to adjust the point of group mode buffer because
6723     ;; point was moved to the next unread newsgroup by exiting.
6724     (gnus-summary-jump-to-group group)
6725     (when rescan
6726       (save-excursion
6727         (gnus-group-get-new-news-this-group 1)))
6728     (gnus-group-read-group all t)
6729     (gnus-summary-goto-subject current-subject nil t)))
6730
6731 (defun gnus-summary-rescan-group (&optional all)
6732   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6733   (interactive "P")
6734   (gnus-summary-reselect-current-group all t))
6735
6736 (defun gnus-summary-update-info (&optional non-destructive)
6737   (save-excursion
6738     (let ((group gnus-newsgroup-name))
6739       (when group
6740         (when gnus-newsgroup-kill-headers
6741           (setq gnus-newsgroup-killed
6742                 (gnus-compress-sequence
6743                  (gnus-sorted-union
6744                   (gnus-list-range-intersection
6745                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6746                   gnus-newsgroup-unreads)
6747                  t)))
6748         (unless (listp (cdr gnus-newsgroup-killed))
6749           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6750         (let ((headers gnus-newsgroup-headers))
6751           ;; Set the new ranges of read articles.
6752           (with-current-buffer gnus-group-buffer
6753             (gnus-undo-force-boundary))
6754           (gnus-update-read-articles
6755            group (gnus-sorted-union
6756                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6757           ;; Set the current article marks.
6758           (let ((gnus-newsgroup-scored
6759                  (if (and (not gnus-save-score)
6760                           (not non-destructive))
6761                      nil
6762                    gnus-newsgroup-scored)))
6763             (save-excursion
6764               (gnus-update-marks)))
6765           ;; Do the cross-ref thing.
6766           (when gnus-use-cross-reference
6767             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6768           ;; Do not switch windows but change the buffer to work.
6769           (set-buffer gnus-group-buffer)
6770           (unless (gnus-ephemeral-group-p group)
6771             (gnus-group-update-group group)))))))
6772
6773 (defun gnus-summary-save-newsrc (&optional force)
6774   "Save the current number of read/marked articles in the dribble buffer.
6775 The dribble buffer will then be saved.
6776 If FORCE (the prefix), also save the .newsrc file(s)."
6777   (interactive "P")
6778   (gnus-summary-update-info t)
6779   (if force
6780       (gnus-save-newsrc-file)
6781     (gnus-dribble-save)))
6782
6783 (defun gnus-summary-exit (&optional temporary leave-hidden)
6784   "Exit reading current newsgroup, and then return to group selection mode.
6785 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6786   (interactive)
6787   (gnus-set-global-variables)
6788   (when (gnus-buffer-live-p gnus-article-buffer)
6789     (save-excursion
6790       (set-buffer gnus-article-buffer)
6791       (mm-destroy-parts gnus-article-mime-handles)
6792       ;; Set it to nil for safety reason.
6793       (setq gnus-article-mime-handle-alist nil)
6794       (setq gnus-article-mime-handles nil)))
6795   (gnus-kill-save-kill-buffer)
6796   (gnus-async-halt-prefetch)
6797   (let* ((group gnus-newsgroup-name)
6798          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6799          (gnus-group-is-exiting-p t)
6800          (mode major-mode)
6801          (group-point nil)
6802          (buf (current-buffer)))
6803     (unless quit-config
6804       ;; Do adaptive scoring, and possibly save score files.
6805       (when gnus-newsgroup-adaptive
6806         (gnus-score-adaptive))
6807       (when gnus-use-scoring
6808         (gnus-score-save)))
6809     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6810     ;; If we have several article buffers, we kill them at exit.
6811     (unless gnus-single-article-buffer
6812       (gnus-kill-buffer gnus-original-article-buffer)
6813       (setq gnus-article-current nil))
6814     (when gnus-use-cache
6815       (gnus-cache-possibly-remove-articles)
6816       (gnus-cache-save-buffers))
6817     (gnus-async-prefetch-remove-group group)
6818     (when gnus-suppress-duplicates
6819       (gnus-dup-enter-articles))
6820     (when gnus-use-trees
6821       (gnus-tree-close group))
6822     (when gnus-use-cache
6823       (gnus-cache-write-active))
6824     ;; Remove entries for this group.
6825     (nnmail-purge-split-history (gnus-group-real-name group))
6826     ;; Make all changes in this group permanent.
6827     (unless quit-config
6828       (gnus-run-hooks 'gnus-exit-group-hook)
6829       (gnus-summary-update-info))
6830     (gnus-close-group group)
6831     ;; Make sure where we were, and go to next newsgroup.
6832     (set-buffer gnus-group-buffer)
6833     (unless quit-config
6834       (gnus-group-jump-to-group group))
6835     (gnus-run-hooks 'gnus-summary-exit-hook)
6836     (unless (or quit-config
6837                 ;; If this group has disappeared from the summary
6838                 ;; buffer, don't skip forwards.
6839                 (not (string= group (gnus-group-group-name))))
6840       (gnus-group-next-unread-group 1))
6841     (setq group-point (point))
6842     (if temporary
6843         nil                             ;Nothing to do.
6844       ;; If we have several article buffers, we kill them at exit.
6845       (unless gnus-single-article-buffer
6846         (gnus-kill-buffer gnus-article-buffer)
6847         (gnus-kill-buffer gnus-original-article-buffer)
6848         (setq gnus-article-current nil))
6849       (set-buffer buf)
6850       (if (not gnus-kill-summary-on-exit)
6851           (progn
6852             (gnus-deaden-summary)
6853             (setq mode nil))
6854         ;; We set all buffer-local variables to nil.  It is unclear why
6855         ;; this is needed, but if we don't, buffer-local variables are
6856         ;; not garbage-collected, it seems.  This would the lead to en
6857         ;; ever-growing Emacs.
6858         (gnus-summary-clear-local-variables)
6859         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6860           (gnus-summary-clear-local-variables))
6861         (when (get-buffer gnus-article-buffer)
6862           (bury-buffer gnus-article-buffer))
6863         ;; Return to group mode buffer.
6864         (when (eq mode 'gnus-summary-mode)
6865           (gnus-kill-buffer buf)))
6866       (setq gnus-current-select-method gnus-select-method)
6867       (set-buffer gnus-group-buffer)
6868       (if quit-config
6869           (gnus-handle-ephemeral-exit quit-config)
6870         (goto-char group-point)
6871         ;; If gnus-group-buffer is already displayed, make sure we also move
6872         ;; the cursor in the window that displays it.
6873         (let ((win (get-buffer-window (current-buffer) 0)))
6874           (if win (set-window-point win (point))))
6875         (unless leave-hidden
6876           (gnus-configure-windows 'group 'force)))
6877       ;; Clear the current group name.
6878       (unless quit-config
6879         (setq gnus-newsgroup-name nil)))))
6880
6881 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6882 (defun gnus-summary-exit-no-update (&optional no-questions)
6883   "Quit reading current newsgroup without updating read article info."
6884   (interactive)
6885   (let* ((group gnus-newsgroup-name)
6886          (gnus-group-is-exiting-p t)
6887          (gnus-group-is-exiting-without-update-p t)
6888          (quit-config (gnus-group-quit-config group)))
6889     (when (or no-questions
6890               gnus-expert-user
6891               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6892       (gnus-async-halt-prefetch)
6893       (run-hooks 'gnus-summary-prepare-exit-hook)
6894       (when (gnus-buffer-live-p gnus-article-buffer)
6895         (save-excursion
6896           (set-buffer gnus-article-buffer)
6897           (mm-destroy-parts gnus-article-mime-handles)
6898           ;; Set it to nil for safety reason.
6899           (setq gnus-article-mime-handle-alist nil)
6900           (setq gnus-article-mime-handles nil)))
6901       ;; If we have several article buffers, we kill them at exit.
6902       (unless gnus-single-article-buffer
6903         (gnus-kill-buffer gnus-article-buffer)
6904         (gnus-kill-buffer gnus-original-article-buffer)
6905         (setq gnus-article-current nil))
6906       (if (not gnus-kill-summary-on-exit)
6907           (gnus-deaden-summary)
6908         (gnus-close-group group)
6909         (gnus-summary-clear-local-variables)
6910         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6911           (gnus-summary-clear-local-variables))
6912         (gnus-kill-buffer gnus-summary-buffer))
6913       (unless gnus-single-article-buffer
6914         (setq gnus-article-current nil))
6915       (when gnus-use-trees
6916         (gnus-tree-close group))
6917       (gnus-async-prefetch-remove-group group)
6918       (when (get-buffer gnus-article-buffer)
6919         (bury-buffer gnus-article-buffer))
6920       ;; Return to the group buffer.
6921       (gnus-configure-windows 'group 'force)
6922       ;; Clear the current group name.
6923       (setq gnus-newsgroup-name nil)
6924       (unless (gnus-ephemeral-group-p group)
6925         (gnus-group-update-group group))
6926       (when (equal (gnus-group-group-name) group)
6927         (gnus-group-next-unread-group 1))
6928       (when quit-config
6929         (gnus-handle-ephemeral-exit quit-config)))))
6930
6931 (defun gnus-handle-ephemeral-exit (quit-config)
6932   "Handle movement when leaving an ephemeral group.
6933 The state which existed when entering the ephemeral is reset."
6934   (if (not (buffer-name (car quit-config)))
6935       (gnus-configure-windows 'group 'force)
6936     (set-buffer (car quit-config))
6937     (cond ((eq major-mode 'gnus-summary-mode)
6938            (gnus-set-global-variables))
6939           ((eq major-mode 'gnus-article-mode)
6940            (save-excursion
6941              ;; The `gnus-summary-buffer' variable may point
6942              ;; to the old summary buffer when using a single
6943              ;; article buffer.
6944              (unless (gnus-buffer-live-p gnus-summary-buffer)
6945                (set-buffer gnus-group-buffer))
6946              (set-buffer gnus-summary-buffer)
6947              (gnus-set-global-variables))))
6948     (if (or (eq (cdr quit-config) 'article)
6949             (eq (cdr quit-config) 'pick))
6950         (progn
6951           ;; The current article may be from the ephemeral group
6952           ;; thus it is best that we reload this article
6953           ;;
6954           ;; If we're exiting from a large digest, this can be
6955           ;; extremely slow.  So, it's better not to reload it. -- jh.
6956           ;;(gnus-summary-show-article)
6957           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6958               (gnus-configure-windows 'pick 'force)
6959             (gnus-configure-windows (cdr quit-config) 'force)))
6960       (gnus-configure-windows (cdr quit-config) 'force))
6961     (when (eq major-mode 'gnus-summary-mode)
6962       (gnus-summary-next-subject 1 nil t)
6963       (gnus-summary-recenter)
6964       (gnus-summary-position-point))))
6965
6966 ;;; Dead summaries.
6967
6968 (defvar gnus-dead-summary-mode-map nil)
6969
6970 (unless gnus-dead-summary-mode-map
6971   (setq gnus-dead-summary-mode-map (make-keymap))
6972   (suppress-keymap gnus-dead-summary-mode-map)
6973   (substitute-key-definition
6974    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6975   (dolist (key '("\C-d" "\r" "\177" [delete]))
6976     (define-key gnus-dead-summary-mode-map
6977       key 'gnus-summary-wake-up-the-dead))
6978   (dolist (key '("q" "Q"))
6979     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6980
6981 (defvar gnus-dead-summary-mode nil
6982   "Minor mode for Gnus summary buffers.")
6983
6984 (defun gnus-dead-summary-mode (&optional arg)
6985   "Minor mode for Gnus summary buffers."
6986   (interactive "P")
6987   (when (eq major-mode 'gnus-summary-mode)
6988     (make-local-variable 'gnus-dead-summary-mode)
6989     (setq gnus-dead-summary-mode
6990           (if (null arg) (not gnus-dead-summary-mode)
6991             (> (prefix-numeric-value arg) 0)))
6992     (when gnus-dead-summary-mode
6993       (add-minor-mode
6994        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6995
6996 (defun gnus-deaden-summary ()
6997   "Make the current summary buffer into a dead summary buffer."
6998   ;; Kill any previous dead summary buffer.
6999   (when (and gnus-dead-summary
7000              (buffer-name gnus-dead-summary))
7001     (with-current-buffer gnus-dead-summary
7002       (when gnus-dead-summary-mode
7003         (kill-buffer (current-buffer)))))
7004   ;; Make this the current dead summary.
7005   (setq gnus-dead-summary (current-buffer))
7006   (gnus-dead-summary-mode 1)
7007   (let ((name (buffer-name)))
7008     (when (string-match "Summary" name)
7009       (rename-buffer
7010        (concat (substring name 0 (match-beginning 0)) "Dead "
7011                (substring name (match-beginning 0)))
7012        t)
7013       (bury-buffer))))
7014
7015 (defun gnus-kill-or-deaden-summary (buffer)
7016   "Kill or deaden the summary BUFFER."
7017   (save-excursion
7018     (when (and (buffer-name buffer)
7019                (not gnus-single-article-buffer))
7020       (with-current-buffer buffer
7021         (gnus-kill-buffer gnus-article-buffer)
7022         (gnus-kill-buffer gnus-original-article-buffer)))
7023     (cond
7024      ;; Kill the buffer.
7025      (gnus-kill-summary-on-exit
7026       (when (and gnus-use-trees
7027                  (gnus-buffer-exists-p buffer))
7028         (save-excursion
7029           (set-buffer buffer)
7030           (gnus-tree-close gnus-newsgroup-name)))
7031       (gnus-kill-buffer buffer))
7032      ;; Deaden the buffer.
7033      ((gnus-buffer-exists-p buffer)
7034       (save-excursion
7035         (set-buffer buffer)
7036         (gnus-deaden-summary))))))
7037
7038 (defun gnus-summary-wake-up-the-dead (&rest args)
7039   "Wake up the dead summary buffer."
7040   (interactive)
7041   (gnus-dead-summary-mode -1)
7042   (let ((name (buffer-name)))
7043     (when (string-match "Dead " name)
7044       (rename-buffer
7045        (concat (substring name 0 (match-beginning 0))
7046                (substring name (match-end 0)))
7047        t)))
7048   (gnus-message 3 "This dead summary is now alive again"))
7049
7050 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7051 (defun gnus-summary-fetch-faq (&optional faq-dir)
7052   "Fetch the FAQ for the current group.
7053 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7054 in."
7055   (interactive
7056    (list
7057     (when current-prefix-arg
7058       (completing-read
7059        "FAQ dir: " (and (listp gnus-group-faq-directory)
7060                         (mapcar 'list
7061                                 gnus-group-faq-directory))))))
7062   (let (gnus-faq-buffer)
7063     (when (setq gnus-faq-buffer
7064                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7065       (gnus-configure-windows 'summary-faq))))
7066
7067 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7068 (defun gnus-summary-describe-group (&optional force)
7069   "Describe the current newsgroup."
7070   (interactive "P")
7071   (gnus-group-describe-group force gnus-newsgroup-name))
7072
7073 (defun gnus-summary-describe-briefly ()
7074   "Describe summary mode commands briefly."
7075   (interactive)
7076   (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")))
7077
7078 ;; Walking around group mode buffer from summary mode.
7079
7080 (defun gnus-summary-next-group (&optional no-article target-group backward)
7081   "Exit current newsgroup and then select next unread newsgroup.
7082 If prefix argument NO-ARTICLE is non-nil, no article is selected
7083 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7084 previous group instead."
7085   (interactive "P")
7086   ;; Stop pre-fetching.
7087   (gnus-async-halt-prefetch)
7088   (let ((current-group gnus-newsgroup-name)
7089         (current-buffer (current-buffer))
7090         entered)
7091     ;; First we semi-exit this group to update Xrefs and all variables.
7092     ;; We can't do a real exit, because the window conf must remain
7093     ;; the same in case the user is prompted for info, and we don't
7094     ;; want the window conf to change before that...
7095     (gnus-summary-exit t)
7096     (while (not entered)
7097       ;; Then we find what group we are supposed to enter.
7098       (set-buffer gnus-group-buffer)
7099       (gnus-group-jump-to-group current-group)
7100       (setq target-group
7101             (or target-group
7102                 (if (eq gnus-keep-same-level 'best)
7103                     (gnus-summary-best-group gnus-newsgroup-name)
7104                   (gnus-summary-search-group backward gnus-keep-same-level))))
7105       (if (not target-group)
7106           ;; There are no further groups, so we return to the group
7107           ;; buffer.
7108           (progn
7109             (gnus-message 5 "Returning to the group buffer")
7110             (setq entered t)
7111             (when (gnus-buffer-live-p current-buffer)
7112               (set-buffer current-buffer)
7113               (gnus-summary-exit))
7114             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7115         ;; We try to enter the target group.
7116         (gnus-group-jump-to-group target-group)
7117         (let ((unreads (gnus-group-group-unread)))
7118           (if (and (or (eq t unreads)
7119                        (and unreads (not (zerop unreads))))
7120                    (gnus-summary-read-group
7121                     target-group nil no-article
7122                     (and (buffer-name current-buffer) current-buffer)
7123                     nil backward))
7124               (setq entered t)
7125             (setq current-group target-group
7126                   target-group nil)))))))
7127
7128 (defun gnus-summary-prev-group (&optional no-article)
7129   "Exit current newsgroup and then select previous unread newsgroup.
7130 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7131   (interactive "P")
7132   (gnus-summary-next-group no-article nil t))
7133
7134 ;; Walking around summary lines.
7135
7136 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7137   "Go to the first subject satisfying any non-nil constraint.
7138 If UNREAD is non-nil, the article should be unread.
7139 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7140 If UNSEEN is non-nil, the article should be unseen.
7141 Returns the article selected or nil if there are no matching articles."
7142   (interactive "P")
7143   (cond
7144    ;; Empty summary.
7145    ((null gnus-newsgroup-data)
7146     (gnus-message 3 "No articles in the group")
7147     nil)
7148    ;; Pick the first article.
7149    ((not (or unread undownloaded unseen))
7150     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7151     (gnus-data-number (car gnus-newsgroup-data)))
7152    ;; Find the first unread article.
7153    (t
7154     (let ((data gnus-newsgroup-data))
7155       (while (and data
7156                   (let ((num (gnus-data-number (car data))))
7157                     (or (memq num gnus-newsgroup-unfetched)
7158                         (not (or (and unread
7159                                       (memq num gnus-newsgroup-unreads))
7160                                  (and undownloaded
7161                                       (memq num gnus-newsgroup-undownloaded))
7162                                  (and unseen
7163                                       (memq num gnus-newsgroup-unseen)))))))
7164         (setq data (cdr data)))
7165       (prog1
7166           (if data
7167               (progn
7168                 (goto-char (gnus-data-pos (car data)))
7169                 (gnus-data-number (car data)))
7170             (gnus-message 3 "No more%s articles"
7171                           (let* ((r (when unread " unread"))
7172                                  (d (when undownloaded " undownloaded"))
7173                                  (s (when unseen " unseen"))
7174                                  (l (delq nil (list r d s))))
7175                             (cond ((= 3 (length l))
7176                                    (concat r "," d ", or" s))
7177                                   ((= 2 (length l))
7178                                    (concat (car l) ", or" (cadr l)))
7179                                   ((= 1 (length l))
7180                                    (car l))
7181                                   (t
7182                                    ""))))
7183             nil
7184             )
7185         (gnus-summary-position-point))))))
7186
7187 (defun gnus-summary-next-subject (n &optional unread dont-display)
7188   "Go to next N'th summary line.
7189 If N is negative, go to the previous N'th subject line.
7190 If UNREAD is non-nil, only unread articles are selected.
7191 The difference between N and the actual number of steps taken is
7192 returned."
7193   (interactive "p")
7194   (let ((backward (< n 0))
7195         (n (abs n)))
7196     (while (and (> n 0)
7197                 (if backward
7198                     (gnus-summary-find-prev unread)
7199                   (gnus-summary-find-next unread)))
7200       (unless (zerop (setq n (1- n)))
7201         (gnus-summary-show-thread)))
7202     (when (/= 0 n)
7203       (gnus-message 7 "No more%s articles"
7204                     (if unread " unread" "")))
7205     (unless dont-display
7206       (gnus-summary-recenter)
7207       (gnus-summary-position-point))
7208     n))
7209
7210 (defun gnus-summary-next-unread-subject (n)
7211   "Go to next N'th unread summary line."
7212   (interactive "p")
7213   (gnus-summary-next-subject n t))
7214
7215 (defun gnus-summary-prev-subject (n &optional unread)
7216   "Go to previous N'th summary line.
7217 If optional argument UNREAD is non-nil, only unread article is selected."
7218   (interactive "p")
7219   (gnus-summary-next-subject (- n) unread))
7220
7221 (defun gnus-summary-prev-unread-subject (n)
7222   "Go to previous N'th unread summary line."
7223   (interactive "p")
7224   (gnus-summary-next-subject (- n) t))
7225
7226 (defun gnus-summary-goto-subjects (articles)
7227   "Insert the subject header for ARTICLES in the current buffer."
7228   (save-excursion
7229     (dolist (article articles)
7230       (gnus-summary-goto-subject article t)))
7231   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7232   (gnus-summary-position-point))
7233
7234 (defun gnus-summary-goto-subject (article &optional force silent)
7235   "Go the subject line of ARTICLE.
7236 If FORCE, also allow jumping to articles not currently shown."
7237   (interactive "nArticle number: ")
7238   (unless (numberp article)
7239     (error "Article %s is not a number" article))
7240   (let ((b (point))
7241         (data (gnus-data-find article)))
7242     ;; We read in the article if we have to.
7243     (and (not data)
7244          force
7245          (gnus-summary-insert-subject
7246           article
7247           (if (or (numberp force) (vectorp force)) force)
7248           t)
7249          (setq data (gnus-data-find article)))
7250     (goto-char b)
7251     (if (not data)
7252         (progn
7253           (unless silent
7254             (gnus-message 3 "Can't find article %d" article))
7255           nil)
7256       (let ((pt (gnus-data-pos data)))
7257         (goto-char pt)
7258         (gnus-summary-set-article-display-arrow pt))
7259       (gnus-summary-position-point)
7260       article)))
7261
7262 ;; Walking around summary lines with displaying articles.
7263
7264 (defun gnus-summary-expand-window (&optional arg)
7265   "Make the summary buffer take up the entire Emacs frame.
7266 Given a prefix, will force an `article' buffer configuration."
7267   (interactive "P")
7268   (if arg
7269       (gnus-configure-windows 'article 'force)
7270     (gnus-configure-windows 'summary 'force)))
7271
7272 (defun gnus-summary-display-article (article &optional all-header)
7273   "Display ARTICLE in article buffer."
7274   (when (gnus-buffer-live-p gnus-article-buffer)
7275     (with-current-buffer gnus-article-buffer
7276       (mm-enable-multibyte)))
7277   (gnus-set-global-variables)
7278   (when (gnus-buffer-live-p gnus-article-buffer)
7279     (with-current-buffer gnus-article-buffer
7280       (setq gnus-article-charset gnus-newsgroup-charset)
7281       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7282       (mm-enable-multibyte)))
7283   (if (null article)
7284       nil
7285     (prog1
7286         (if gnus-summary-display-article-function
7287             (funcall gnus-summary-display-article-function article all-header)
7288           (gnus-article-prepare article all-header))
7289       (gnus-run-hooks 'gnus-select-article-hook)
7290       (when (and gnus-current-article
7291                  (not (zerop gnus-current-article)))
7292         (gnus-summary-goto-subject gnus-current-article))
7293       (gnus-summary-recenter)
7294       (when (and gnus-use-trees gnus-show-threads)
7295         (gnus-possibly-generate-tree article)
7296         (gnus-highlight-selected-tree article))
7297       ;; Successfully display article.
7298       (gnus-article-set-window-start
7299        (cdr (assq article gnus-newsgroup-bookmarks))))))
7300
7301 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7302   "Select the current article.
7303 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7304 non-nil, the article will be re-fetched even if it already present in
7305 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7306 be displayed."
7307   ;; Make sure we are in the summary buffer to work around bbdb bug.
7308   (unless (eq major-mode 'gnus-summary-mode)
7309     (set-buffer gnus-summary-buffer))
7310   (let ((article (or article (gnus-summary-article-number)))
7311         (all-headers (not (not all-headers))) ;Must be t or nil.
7312         gnus-summary-display-article-function)
7313     (and (not pseudo)
7314          (gnus-summary-article-pseudo-p article)
7315          (error "This is a pseudo-article"))
7316     (save-excursion
7317       (set-buffer gnus-summary-buffer)
7318       (if (or (and gnus-single-article-buffer
7319                    (or (null gnus-current-article)
7320                        (null gnus-article-current)
7321                        (null (get-buffer gnus-article-buffer))
7322                        (not (eq article (cdr gnus-article-current)))
7323                        (not (equal (car gnus-article-current)
7324                                    gnus-newsgroup-name))))
7325               (and (not gnus-single-article-buffer)
7326                    (or (null gnus-current-article)
7327                        (not (eq gnus-current-article article))))
7328               force)
7329           ;; The requested article is different from the current article.
7330           (progn
7331             (gnus-summary-display-article article all-headers)
7332             (when (gnus-buffer-live-p gnus-article-buffer)
7333               (with-current-buffer gnus-article-buffer
7334                 (if (not gnus-article-decoded-p) ;; a local variable
7335                     (mm-disable-multibyte))))
7336             (gnus-article-set-window-start
7337              (cdr (assq article gnus-newsgroup-bookmarks)))
7338             article)
7339         'old))))
7340
7341 (defun gnus-summary-force-verify-and-decrypt ()
7342   "Display buttons for signed/encrypted parts and verify/decrypt them."
7343   (interactive)
7344   (let ((mm-verify-option 'known)
7345         (mm-decrypt-option 'known)
7346         (gnus-article-emulate-mime t)
7347         (gnus-buttonized-mime-types (append (list "multipart/signed"
7348                                                   "multipart/encrypted")
7349                                             gnus-buttonized-mime-types)))
7350     (gnus-summary-select-article nil 'force)))
7351
7352 (defun gnus-summary-set-current-mark (&optional current-mark)
7353   "Obsolete function."
7354   nil)
7355
7356 (defun gnus-summary-next-article (&optional unread subject backward push)
7357   "Select the next article.
7358 If UNREAD, only unread articles are selected.
7359 If SUBJECT, only articles with SUBJECT are selected.
7360 If BACKWARD, the previous article is selected instead of the next."
7361   (interactive "P")
7362   (cond
7363    ;; Is there such an article?
7364    ((and (gnus-summary-search-forward unread subject backward)
7365          (or (gnus-summary-display-article (gnus-summary-article-number))
7366              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7367     (gnus-summary-position-point))
7368    ;; If not, we try the first unread, if that is wanted.
7369    ((and subject
7370          gnus-auto-select-same
7371          (gnus-summary-first-unread-article))
7372     (gnus-summary-position-point)
7373     (gnus-message 6 "Wrapped"))
7374    ;; Try to get next/previous article not displayed in this group.
7375    ((and gnus-auto-extend-newsgroup
7376          (not unread) (not subject))
7377     (gnus-summary-goto-article
7378      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7379      nil (count-lines (point-min) (point))))
7380    ;; Go to next/previous group.
7381    (t
7382     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7383       (gnus-summary-jump-to-group gnus-newsgroup-name))
7384     (let ((cmd last-command-char)
7385           (point
7386            (with-current-buffer gnus-group-buffer
7387              (point)))
7388           (group
7389            (if (eq gnus-keep-same-level 'best)
7390                (gnus-summary-best-group gnus-newsgroup-name)
7391              (gnus-summary-search-group backward gnus-keep-same-level))))
7392       ;; For some reason, the group window gets selected.  We change
7393       ;; it back.
7394       (select-window (get-buffer-window (current-buffer)))
7395       ;; Select next unread newsgroup automagically.
7396       (cond
7397        ((or (not gnus-auto-select-next)
7398             (not cmd))
7399         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7400        ((or (eq gnus-auto-select-next 'quietly)
7401             (and (eq gnus-auto-select-next 'slightly-quietly)
7402                  push)
7403             (and (eq gnus-auto-select-next 'almost-quietly)
7404                  (gnus-summary-last-article-p)))
7405         ;; Select quietly.
7406         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7407             (gnus-summary-exit)
7408           (gnus-message 7 "No more%s articles (%s)..."
7409                         (if unread " unread" "")
7410                         (if group (concat "selecting " group)
7411                           "exiting"))
7412           (gnus-summary-next-group nil group backward)))
7413        (t
7414         (when (gnus-key-press-event-p last-input-event)
7415           (gnus-summary-walk-group-buffer
7416            gnus-newsgroup-name cmd unread backward point))))))))
7417
7418 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7419   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7420                       (?\C-p (gnus-group-prev-unread-group 1))))
7421         (cursor-in-echo-area t)
7422         keve key group ended prompt)
7423     (save-excursion
7424       (set-buffer gnus-group-buffer)
7425       (goto-char start)
7426       (setq group
7427             (if (eq gnus-keep-same-level 'best)
7428                 (gnus-summary-best-group gnus-newsgroup-name)
7429               (gnus-summary-search-group backward gnus-keep-same-level))))
7430     (while (not ended)
7431       (setq prompt
7432             (format
7433              "No more%s articles%s " (if unread " unread" "")
7434              (if (and group
7435                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7436                  (format " (Type %s for %s [%s])"
7437                          (single-key-description cmd)
7438                          (gnus-group-decoded-name group)
7439                          (gnus-group-unread group))
7440                (format " (Type %s to exit %s)"
7441                        (single-key-description cmd)
7442                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7443       ;; Confirm auto selection.
7444       (setq key (car (setq keve (gnus-read-event-char prompt)))
7445             ended t)
7446       (cond
7447        ((assq key keystrokes)
7448         (let ((obuf (current-buffer)))
7449           (switch-to-buffer gnus-group-buffer)
7450           (when group
7451             (gnus-group-jump-to-group group))
7452           (eval (cadr (assq key keystrokes)))
7453           (setq group (gnus-group-group-name))
7454           (switch-to-buffer obuf))
7455         (setq ended nil))
7456        ((equal key cmd)
7457         (if (or (not group)
7458                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7459             (gnus-summary-exit)
7460           (gnus-summary-next-group nil group backward)))
7461        (t
7462         (push (cdr keve) unread-command-events))))))
7463
7464 (defun gnus-summary-next-unread-article ()
7465   "Select unread article after current one."
7466   (interactive)
7467   (gnus-summary-next-article
7468    (or (not (eq gnus-summary-goto-unread 'never))
7469        (gnus-summary-last-article-p (gnus-summary-article-number)))
7470    (and gnus-auto-select-same
7471         (gnus-summary-article-subject))))
7472
7473 (defun gnus-summary-prev-article (&optional unread subject)
7474   "Select the article after the current one.
7475 If UNREAD is non-nil, only unread articles are selected."
7476   (interactive "P")
7477   (gnus-summary-next-article unread subject t))
7478
7479 (defun gnus-summary-prev-unread-article ()
7480   "Select unread article before current one."
7481   (interactive)
7482   (gnus-summary-prev-article
7483    (or (not (eq gnus-summary-goto-unread 'never))
7484        (gnus-summary-first-article-p (gnus-summary-article-number)))
7485    (and gnus-auto-select-same
7486         (gnus-summary-article-subject))))
7487
7488 (defun gnus-summary-next-page (&optional lines circular stop)
7489   "Show next page of the selected article.
7490 If at the end of the current article, select the next article.
7491 LINES says how many lines should be scrolled up.
7492
7493 If CIRCULAR is non-nil, go to the start of the article instead of
7494 selecting the next article when reaching the end of the current
7495 article.
7496
7497 If STOP is non-nil, just stop when reaching the end of the message.
7498
7499 Also see the variable `gnus-article-skip-boring'."
7500   (interactive "P")
7501   (setq gnus-summary-buffer (current-buffer))
7502   (gnus-set-global-variables)
7503   (let ((article (gnus-summary-article-number))
7504         (article-window (get-buffer-window gnus-article-buffer t))
7505         endp)
7506     ;; If the buffer is empty, we have no article.
7507     (unless article
7508       (error "No article to select"))
7509     (gnus-configure-windows 'article)
7510     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7511         (if (and (eq gnus-summary-goto-unread 'never)
7512                  (not (gnus-summary-last-article-p article)))
7513             (gnus-summary-next-article)
7514           (gnus-summary-next-unread-article))
7515       (if (or (null gnus-current-article)
7516               (null gnus-article-current)
7517               (/= article (cdr gnus-article-current))
7518               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7519           ;; Selected subject is different from current article's.
7520           (gnus-summary-display-article article)
7521         (when article-window
7522           (gnus-eval-in-buffer-window gnus-article-buffer
7523             (setq endp (or (gnus-article-next-page lines)
7524                            (gnus-article-only-boring-p))))
7525           (when endp
7526             (cond (stop
7527                    (gnus-message 3 "End of message"))
7528                   (circular
7529                    (gnus-summary-beginning-of-article))
7530                   (lines
7531                    (gnus-message 3 "End of message"))
7532                   ((null lines)
7533                    (if (and (eq gnus-summary-goto-unread 'never)
7534                             (not (gnus-summary-last-article-p article)))
7535                        (gnus-summary-next-article)
7536                      (gnus-summary-next-unread-article))))))))
7537     (gnus-summary-recenter)
7538     (gnus-summary-position-point)))
7539
7540 (defun gnus-summary-prev-page (&optional lines move)
7541   "Show previous page of selected article.
7542 Argument LINES specifies lines to be scrolled down.
7543 If MOVE, move to the previous unread article if point is at
7544 the beginning of the buffer."
7545   (interactive "P")
7546   (let ((article (gnus-summary-article-number))
7547         (article-window (get-buffer-window gnus-article-buffer t))
7548         endp)
7549     (gnus-configure-windows '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       (gnus-summary-recenter)
7557       (when article-window
7558         (gnus-eval-in-buffer-window gnus-article-buffer
7559           (setq endp (gnus-article-prev-page lines)))
7560         (when (and move endp)
7561           (cond (lines
7562                  (gnus-message 3 "Beginning of message"))
7563                 ((null lines)
7564                  (if (and (eq gnus-summary-goto-unread 'never)
7565                           (not (gnus-summary-first-article-p article)))
7566                      (gnus-summary-prev-article)
7567                    (gnus-summary-prev-unread-article))))))))
7568   (gnus-summary-position-point))
7569
7570 (defun gnus-summary-prev-page-or-article (&optional lines)
7571   "Show previous page of selected article.
7572 Argument LINES specifies lines to be scrolled down.
7573 If at the beginning of the article, go to the next article."
7574   (interactive "P")
7575   (gnus-summary-prev-page lines t))
7576
7577 (defun gnus-summary-scroll-up (lines)
7578   "Scroll up (or down) one line current article.
7579 Argument LINES specifies lines to be scrolled up (or down if negative)."
7580   (interactive "p")
7581   (gnus-configure-windows 'article)
7582   (gnus-summary-show-thread)
7583   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7584     (gnus-eval-in-buffer-window gnus-article-buffer
7585       (cond ((> lines 0)
7586              (when (gnus-article-next-page lines)
7587                (gnus-message 3 "End of message")))
7588             ((< lines 0)
7589              (gnus-article-prev-page (- lines))))))
7590   (gnus-summary-recenter)
7591   (gnus-summary-position-point))
7592
7593 (defun gnus-summary-scroll-down (lines)
7594   "Scroll down (or up) one line current article.
7595 Argument LINES specifies lines to be scrolled down (or up if negative)."
7596   (interactive "p")
7597   (gnus-summary-scroll-up (- lines)))
7598
7599 (defun gnus-summary-next-same-subject ()
7600   "Select next article which has the same subject as current one."
7601   (interactive)
7602   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7603
7604 (defun gnus-summary-prev-same-subject ()
7605   "Select previous article which has the same subject as current one."
7606   (interactive)
7607   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7608
7609 (defun gnus-summary-next-unread-same-subject ()
7610   "Select next unread article which has the same subject as current one."
7611   (interactive)
7612   (gnus-summary-next-article t (gnus-summary-article-subject)))
7613
7614 (defun gnus-summary-prev-unread-same-subject ()
7615   "Select previous unread article which has the same subject as current one."
7616   (interactive)
7617   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7618
7619 (defun gnus-summary-first-unread-article ()
7620   "Select the first unread article.
7621 Return nil if there are no unread articles."
7622   (interactive)
7623   (prog1
7624       (when (gnus-summary-first-subject t)
7625         (gnus-summary-show-thread)
7626         (gnus-summary-first-subject t)
7627         (gnus-summary-display-article (gnus-summary-article-number)))
7628     (gnus-summary-position-point)))
7629
7630 (defun gnus-summary-first-unread-subject ()
7631   "Place the point on the subject line of the first unread article.
7632 Return nil if there are no unread articles."
7633   (interactive)
7634   (prog1
7635       (when (gnus-summary-first-subject t)
7636         (gnus-summary-show-thread)
7637         (gnus-summary-first-subject t))
7638     (gnus-summary-position-point)))
7639
7640 (defun gnus-summary-first-unseen-subject ()
7641   "Place the point on the subject line of the first unseen article.
7642 Return nil if there are no unseen articles."
7643   (interactive)
7644   (prog1
7645       (when (gnus-summary-first-subject nil nil t)
7646         (gnus-summary-show-thread)
7647         (gnus-summary-first-subject nil nil t))
7648     (gnus-summary-position-point)))
7649
7650 (defun gnus-summary-first-unseen-or-unread-subject ()
7651   "Place the point on the subject line of the first unseen article or,
7652 if all article have been seen, on the subject line of the first unread
7653 article."
7654   (interactive)
7655   (prog1
7656       (unless (when (gnus-summary-first-subject nil nil t)
7657                 (gnus-summary-show-thread)
7658                 (gnus-summary-first-subject nil nil t))
7659         (when (gnus-summary-first-subject t)
7660           (gnus-summary-show-thread)
7661           (gnus-summary-first-subject t)))
7662     (gnus-summary-position-point)))
7663
7664 (defun gnus-summary-first-article ()
7665   "Select the first article.
7666 Return nil if there are no articles."
7667   (interactive)
7668   (prog1
7669       (when (gnus-summary-first-subject)
7670         (gnus-summary-show-thread)
7671         (gnus-summary-first-subject)
7672         (gnus-summary-display-article (gnus-summary-article-number)))
7673     (gnus-summary-position-point)))
7674
7675 (defun gnus-summary-best-unread-article (&optional arg)
7676   "Select the unread article with the highest score.
7677 If given a prefix argument, select the next unread article that has a
7678 score higher than the default score."
7679   (interactive "P")
7680   (let ((article (if arg
7681                      (gnus-summary-better-unread-subject)
7682                    (gnus-summary-best-unread-subject))))
7683     (if article
7684         (gnus-summary-goto-article article)
7685       (error "No unread articles"))))
7686
7687 (defun gnus-summary-best-unread-subject ()
7688   "Select the unread subject with the highest score."
7689   (interactive)
7690   (let ((best -1000000)
7691         (data gnus-newsgroup-data)
7692         article score)
7693     (while data
7694       (and (gnus-data-unread-p (car data))
7695            (> (setq score
7696                     (gnus-summary-article-score (gnus-data-number (car data))))
7697               best)
7698            (setq best score
7699                  article (gnus-data-number (car data))))
7700       (setq data (cdr data)))
7701     (when article
7702       (gnus-summary-goto-subject article))
7703     (gnus-summary-position-point)
7704     article))
7705
7706 (defun gnus-summary-better-unread-subject ()
7707   "Select the first unread subject that has a score over the default score."
7708   (interactive)
7709   (let ((data gnus-newsgroup-data)
7710         article score)
7711     (while (and (setq article (gnus-data-number (car data)))
7712                 (or (gnus-data-read-p (car data))
7713                     (not (> (gnus-summary-article-score article)
7714                             gnus-summary-default-score))))
7715       (setq data (cdr data)))
7716     (when article
7717       (gnus-summary-goto-subject article))
7718     (gnus-summary-position-point)
7719     article))
7720
7721 (defun gnus-summary-last-subject ()
7722   "Go to the last displayed subject line in the group."
7723   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7724     (when article
7725       (gnus-summary-goto-subject article))))
7726
7727 (defun gnus-summary-goto-article (article &optional all-headers force)
7728   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7729 If ALL-HEADERS is non-nil, no header lines are hidden.
7730 If FORCE, go to the article even if it isn't displayed.  If FORCE
7731 is a number, it is the line the article is to be displayed on."
7732   (interactive
7733    (list
7734     (completing-read
7735      "Article number or Message-ID: "
7736      (mapcar (lambda (number) (list (int-to-string number)))
7737              gnus-newsgroup-limit))
7738     current-prefix-arg
7739     t))
7740   (prog1
7741       (if (and (stringp article)
7742                (string-match "@\\|%40" article))
7743           (gnus-summary-refer-article article)
7744         (when (stringp article)
7745           (setq article (string-to-number article)))
7746         (if (gnus-summary-goto-subject article force)
7747             (gnus-summary-display-article article all-headers)
7748           (gnus-message 4 "Couldn't go to article %s" article) nil))
7749     (gnus-summary-position-point)))
7750
7751 (defun gnus-summary-goto-last-article ()
7752   "Go to the previously read article."
7753   (interactive)
7754   (prog1
7755       (when gnus-last-article
7756         (gnus-summary-goto-article gnus-last-article nil t))
7757     (gnus-summary-position-point)))
7758
7759 (defun gnus-summary-pop-article (number)
7760   "Pop one article off the history and go to the previous.
7761 NUMBER articles will be popped off."
7762   (interactive "p")
7763   (let (to)
7764     (setq gnus-newsgroup-history
7765           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7766     (if to
7767         (gnus-summary-goto-article (car to) nil t)
7768       (error "Article history empty")))
7769   (gnus-summary-position-point))
7770
7771 ;; Summary commands and functions for limiting the summary buffer.
7772
7773 (defun gnus-summary-limit-to-articles (n)
7774   "Limit the summary buffer to the next N articles.
7775 If not given a prefix, use the process marked articles instead."
7776   (interactive "P")
7777   (prog1
7778       (let ((articles (gnus-summary-work-articles n)))
7779         (setq gnus-newsgroup-processable nil)
7780         (gnus-summary-limit articles))
7781     (gnus-summary-position-point)))
7782
7783 (defun gnus-summary-pop-limit (&optional total)
7784   "Restore the previous limit.
7785 If given a prefix, remove all limits."
7786   (interactive "P")
7787   (when total
7788     (setq gnus-newsgroup-limits
7789           (list (mapcar (lambda (h) (mail-header-number h))
7790                         gnus-newsgroup-headers))))
7791   (unless gnus-newsgroup-limits
7792     (error "No limit to pop"))
7793   (prog1
7794       (gnus-summary-limit nil 'pop)
7795     (gnus-summary-position-point)))
7796
7797 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7798   "Limit the summary buffer to articles that have subjects that match a regexp.
7799 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7800   (interactive
7801    (list (read-string (if current-prefix-arg
7802                           "Exclude subject (regexp): "
7803                         "Limit to subject (regexp): "))
7804          nil current-prefix-arg))
7805   (unless header
7806     (setq header "subject"))
7807   (when (not (equal "" subject))
7808     (prog1
7809         (let ((articles (gnus-summary-find-matching
7810                          (or header "subject") subject 'all nil nil
7811                          not-matching)))
7812           (unless articles
7813             (error "Found no matches for \"%s\"" subject))
7814           (gnus-summary-limit articles))
7815       (gnus-summary-position-point))))
7816
7817 (defun gnus-summary-limit-to-author (from &optional not-matching)
7818   "Limit the summary buffer to articles that have authors that match a regexp.
7819 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7820   (interactive
7821    (list (read-string (if current-prefix-arg
7822                           "Exclude author (regexp): "
7823                         "Limit to author (regexp): "))
7824          current-prefix-arg))
7825   (gnus-summary-limit-to-subject from "from" not-matching))
7826
7827 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7828   "Limit the summary buffer to articles with the given RECIPIENT.
7829
7830 If NOT-MATCHING, exclude RECIPIENT.
7831
7832 To and Cc headers are checked.  You need to include them in
7833 `nnmail-extra-headers'."
7834   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7835   (interactive
7836    (list (read-string (format "%s recipient (regexp): "
7837                               (if current-prefix-arg "Exclude" "Limit to")))
7838          current-prefix-arg))
7839   (when (not (equal "" recipient))
7840     (prog1 (let* ((to
7841                    (if (memq 'To nnmail-extra-headers)
7842                        (gnus-summary-find-matching
7843                         (cons 'extra 'To) recipient 'all nil nil
7844                         not-matching)
7845                      (gnus-message
7846                       1 "`To' isn't present in `nnmail-extra-headers'")
7847                      (sit-for 1)
7848                      nil))
7849                   (cc
7850                    (if (memq 'Cc nnmail-extra-headers)
7851                        (gnus-summary-find-matching
7852                         (cons 'extra 'Cc) recipient 'all nil nil
7853                         not-matching)
7854                      (gnus-message
7855                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7856                      (sit-for 1)
7857                      nil))
7858                   (articles
7859                    (if not-matching
7860                        ;; We need the numbers that are in both lists:
7861                        (mapcar (lambda (a)
7862                                  (and (memq a to) a))
7863                                cc)
7864                      (nconc to cc))))
7865              (unless articles
7866                (error "Found no matches for \"%s\"" recipient))
7867              (gnus-summary-limit articles))
7868       (gnus-summary-position-point))))
7869
7870 (defun gnus-summary-limit-to-age (age &optional younger-p)
7871   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7872 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7873 articles that are younger than AGE days."
7874   (interactive
7875    (let ((younger current-prefix-arg)
7876          (days-got nil)
7877          days)
7878      (while (not days-got)
7879        (setq days (if younger
7880                       (read-string "Limit to articles younger than (in days, older when negative): ")
7881                     (read-string
7882                      "Limit to articles older than (in days, younger when negative): ")))
7883        (when (> (length days) 0)
7884          (setq days (read days)))
7885        (if (numberp days)
7886            (progn
7887              (setq days-got t)
7888              (when (< days 0)
7889                (setq younger (not younger))
7890                (setq days (* days -1))))
7891          (message "Please enter a number.")
7892          (sleep-for 1)))
7893      (list days younger)))
7894   (prog1
7895       (let ((data gnus-newsgroup-data)
7896             (cutoff (days-to-time age))
7897             articles d date is-younger)
7898         (while (setq d (pop data))
7899           (when (and (vectorp (gnus-data-header d))
7900                      (setq date (mail-header-date (gnus-data-header d))))
7901             (setq is-younger (time-less-p
7902                               (time-since (condition-case ()
7903                                               (date-to-time date)
7904                                             (error '(0 0))))
7905                               cutoff))
7906             (when (if younger-p
7907                       is-younger
7908                     (not is-younger))
7909               (push (gnus-data-number d) articles))))
7910         (gnus-summary-limit (nreverse articles)))
7911     (gnus-summary-position-point)))
7912
7913 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7914   "Limit the summary buffer to articles that match an 'extra' header."
7915   (interactive
7916    (let ((header
7917           (intern
7918            (gnus-completing-read-with-default
7919             (symbol-name (car gnus-extra-headers))
7920             (if current-prefix-arg
7921                 "Exclude extra header"
7922               "Limit extra header")
7923             (mapcar (lambda (x)
7924                       (cons (symbol-name x) x))
7925                     gnus-extra-headers)
7926             nil
7927             t))))
7928      (list header
7929            (read-string (format "%s header %s (regexp): "
7930                                 (if current-prefix-arg "Exclude" "Limit to")
7931                                 header))
7932            current-prefix-arg)))
7933   (when (not (equal "" regexp))
7934     (prog1
7935         (let ((articles (gnus-summary-find-matching
7936                          (cons 'extra header) regexp 'all nil nil
7937                          not-matching)))
7938           (unless articles
7939             (error "Found no matches for \"%s\"" regexp))
7940           (gnus-summary-limit articles))
7941       (gnus-summary-position-point))))
7942
7943 (defun gnus-summary-limit-to-display-predicate ()
7944   "Limit the summary buffer to the predicated in the `display' group parameter."
7945   (interactive)
7946   (unless gnus-newsgroup-display
7947     (error "There is no `display' group parameter"))
7948   (let (articles)
7949     (dolist (number gnus-newsgroup-articles)
7950       (when (funcall gnus-newsgroup-display)
7951         (push number articles)))
7952     (gnus-summary-limit articles))
7953   (gnus-summary-position-point))
7954
7955 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7956 (make-obsolete
7957  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7958
7959 (defun gnus-summary-limit-to-unread (&optional all)
7960   "Limit the summary buffer to articles that are not marked as read.
7961 If ALL is non-nil, limit strictly to unread articles."
7962   (interactive "P")
7963   (if all
7964       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7965     (gnus-summary-limit-to-marks
7966      ;; Concat all the marks that say that an article is read and have
7967      ;; those removed.
7968      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7969            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7970            gnus-low-score-mark gnus-expirable-mark
7971            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7972            gnus-duplicate-mark gnus-souped-mark)
7973      'reverse)))
7974
7975 (defun gnus-summary-limit-to-replied (&optional unreplied)
7976   "Limit the summary buffer to replied articles.
7977 If UNREPLIED (the prefix), limit to unreplied articles."
7978   (interactive "P")
7979   (if unreplied
7980       (gnus-summary-limit
7981        (gnus-set-difference gnus-newsgroup-articles
7982         gnus-newsgroup-replied))
7983     (gnus-summary-limit gnus-newsgroup-replied))
7984   (gnus-summary-position-point))
7985
7986 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7987 (make-obsolete 'gnus-summary-delete-marked-with
7988                'gnus-summary-limit-exclude-marks)
7989
7990 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7991   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7992 If REVERSE, limit the summary buffer to articles that are marked
7993 with MARKS.  MARKS can either be a string of marks or a list of marks.
7994 Returns how many articles were removed."
7995   (interactive "sMarks: ")
7996   (gnus-summary-limit-to-marks marks t))
7997
7998 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7999   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8000 If REVERSE (the prefix), limit the summary buffer to articles that are
8001 not marked with MARKS.  MARKS can either be a string of marks or a
8002 list of marks.
8003 Returns how many articles were removed."
8004   (interactive "sMarks: \nP")
8005   (prog1
8006       (let ((data gnus-newsgroup-data)
8007             (marks (if (listp marks) marks
8008                      (append marks nil))) ; Transform to list.
8009             articles)
8010         (while data
8011           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8012                   (memq (gnus-data-mark (car data)) marks))
8013             (push (gnus-data-number (car data)) articles))
8014           (setq data (cdr data)))
8015         (gnus-summary-limit articles))
8016     (gnus-summary-position-point)))
8017
8018 (defun gnus-summary-limit-to-score (score)
8019   "Limit to articles with score at or above SCORE."
8020   (interactive "NLimit to articles with score of at least: ")
8021   (let ((data gnus-newsgroup-data)
8022         articles)
8023     (while data
8024       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8025                 score)
8026         (push (gnus-data-number (car data)) articles))
8027       (setq data (cdr data)))
8028     (prog1
8029         (gnus-summary-limit articles)
8030       (gnus-summary-position-point))))
8031
8032 (defun gnus-summary-limit-to-unseen ()
8033   "Limit to unseen articles."
8034   (interactive)
8035   (prog1
8036       (gnus-summary-limit gnus-newsgroup-unseen)
8037     (gnus-summary-position-point)))
8038
8039 (defun gnus-summary-limit-include-thread (id)
8040   "Display all the hidden articles that is in the thread with ID in it.
8041 When called interactively, ID is the Message-ID of the current
8042 article."
8043   (interactive (list (mail-header-id (gnus-summary-article-header))))
8044   (let ((articles (gnus-articles-in-thread
8045                    (gnus-id-to-thread (gnus-root-id id)))))
8046     (prog1
8047         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8048       (gnus-summary-limit-include-matching-articles
8049        "subject"
8050        (regexp-quote (gnus-simplify-subject-re
8051                       (mail-header-subject (gnus-id-to-header id)))))
8052       (gnus-summary-position-point))))
8053
8054 (defun gnus-summary-limit-include-matching-articles (header regexp)
8055   "Display all the hidden articles that have HEADERs that match REGEXP."
8056   (interactive (list (read-string "Match on header: ")
8057                      (read-string "Regexp: ")))
8058   (let ((articles (gnus-find-matching-articles header regexp)))
8059     (prog1
8060         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8061       (gnus-summary-position-point))))
8062
8063 (defun gnus-summary-insert-dormant-articles ()
8064   "Insert all the dormant articles for this group into the current buffer."
8065   (interactive)
8066   (let ((gnus-verbose (max 6 gnus-verbose)))
8067     (if (not gnus-newsgroup-dormant)
8068         (gnus-message 3 "No cached articles for this group")
8069       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8070
8071 (defun gnus-summary-limit-include-dormant ()
8072   "Display all the hidden articles that are marked as dormant.
8073 Note that this command only works on a subset of the articles currently
8074 fetched for this group."
8075   (interactive)
8076   (unless gnus-newsgroup-dormant
8077     (error "There are no dormant articles in this group"))
8078   (prog1
8079       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8080     (gnus-summary-position-point)))
8081
8082 (defun gnus-summary-limit-exclude-dormant ()
8083   "Hide all dormant articles."
8084   (interactive)
8085   (prog1
8086       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8087     (gnus-summary-position-point)))
8088
8089 (defun gnus-summary-limit-exclude-childless-dormant ()
8090   "Hide all dormant articles that have no children."
8091   (interactive)
8092   (let ((data (gnus-data-list t))
8093         articles d children)
8094     ;; Find all articles that are either not dormant or have
8095     ;; children.
8096     (while (setq d (pop data))
8097       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8098                 (and (setq children
8099                            (gnus-article-children (gnus-data-number d)))
8100                      (let (found)
8101                        (while children
8102                          (when (memq (car children) articles)
8103                            (setq children nil
8104                                  found t))
8105                          (pop children))
8106                        found)))
8107         (push (gnus-data-number d) articles)))
8108     ;; Do the limiting.
8109     (prog1
8110         (gnus-summary-limit articles)
8111       (gnus-summary-position-point))))
8112
8113 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8114   "Mark all unread excluded articles as read.
8115 If ALL, mark even excluded ticked and dormants as read."
8116   (interactive "P")
8117   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8118   (let ((articles (gnus-sorted-ndifference
8119                    (sort
8120                     (mapcar (lambda (h) (mail-header-number h))
8121                             gnus-newsgroup-headers)
8122                     '<)
8123                    gnus-newsgroup-limit))
8124         article)
8125     (setq gnus-newsgroup-unreads
8126           (gnus-sorted-intersection gnus-newsgroup-unreads
8127                                     gnus-newsgroup-limit))
8128     (if all
8129         (setq gnus-newsgroup-dormant nil
8130               gnus-newsgroup-marked nil
8131               gnus-newsgroup-reads
8132               (nconc
8133                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8134                gnus-newsgroup-reads))
8135       (while (setq article (pop articles))
8136         (unless (or (memq article gnus-newsgroup-dormant)
8137                     (memq article gnus-newsgroup-marked))
8138           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8139
8140 (defun gnus-summary-limit (articles &optional pop)
8141   (if pop
8142       ;; We pop the previous limit off the stack and use that.
8143       (setq articles (car gnus-newsgroup-limits)
8144             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8145     ;; We use the new limit, so we push the old limit on the stack.
8146     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8147   ;; Set the limit.
8148   (setq gnus-newsgroup-limit articles)
8149   (let ((total (length gnus-newsgroup-data))
8150         (data (gnus-data-find-list (gnus-summary-article-number)))
8151         (gnus-summary-mark-below nil)   ; Inhibit this.
8152         found)
8153     ;; This will do all the work of generating the new summary buffer
8154     ;; according to the new limit.
8155     (gnus-summary-prepare)
8156     ;; Hide any threads, possibly.
8157     (gnus-summary-maybe-hide-threads)
8158     ;; Try to return to the article you were at, or one in the
8159     ;; neighborhood.
8160     (when data
8161       ;; We try to find some article after the current one.
8162       (while data
8163         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8164           (setq data nil
8165                 found t))
8166         (setq data (cdr data))))
8167     (unless found
8168       ;; If there is no data, that means that we were after the last
8169       ;; article.  The same goes when we can't find any articles
8170       ;; after the current one.
8171       (goto-char (point-max))
8172       (gnus-summary-find-prev))
8173     (gnus-set-mode-line 'summary)
8174     ;; We return how many articles were removed from the summary
8175     ;; buffer as a result of the new limit.
8176     (- total (length gnus-newsgroup-data))))
8177
8178 (defsubst gnus-invisible-cut-children (threads)
8179   (let ((num 0))
8180     (while threads
8181       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8182         (incf num))
8183       (pop threads))
8184     (< num 2)))
8185
8186 (defsubst gnus-cut-thread (thread)
8187   "Go forwards in the thread until we find an article that we want to display."
8188   (when (or (eq gnus-fetch-old-headers 'some)
8189             (eq gnus-fetch-old-headers 'invisible)
8190             (numberp gnus-fetch-old-headers)
8191             (eq gnus-build-sparse-threads 'some)
8192             (eq gnus-build-sparse-threads 'more))
8193     ;; Deal with old-fetched headers and sparse threads.
8194     (while (and
8195             thread
8196             (or
8197              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8198              (gnus-summary-article-ancient-p
8199               (mail-header-number (car thread))))
8200             (if (or (<= (length (cdr thread)) 1)
8201                     (eq gnus-fetch-old-headers 'invisible))
8202                 (setq gnus-newsgroup-limit
8203                       (delq (mail-header-number (car thread))
8204                             gnus-newsgroup-limit)
8205                       thread (cadr thread))
8206               (when (gnus-invisible-cut-children (cdr thread))
8207                 (let ((th (cdr thread)))
8208                   (while th
8209                     (if (memq (mail-header-number (caar th))
8210                               gnus-newsgroup-limit)
8211                         (setq thread (car th)
8212                               th nil)
8213                       (setq th (cdr th))))))))))
8214   thread)
8215
8216 (defun gnus-cut-threads (threads)
8217   "Cut off all uninteresting articles from the beginning of THREADS."
8218   (when (or (eq gnus-fetch-old-headers 'some)
8219             (eq gnus-fetch-old-headers 'invisible)
8220             (numberp gnus-fetch-old-headers)
8221             (eq gnus-build-sparse-threads 'some)
8222             (eq gnus-build-sparse-threads 'more))
8223     (let ((th threads))
8224       (while th
8225         (setcar th (gnus-cut-thread (car th)))
8226         (setq th (cdr th)))))
8227   ;; Remove nixed out threads.
8228   (delq nil threads))
8229
8230 (defun gnus-summary-initial-limit (&optional show-if-empty)
8231   "Figure out what the initial limit is supposed to be on group entry.
8232 This entails weeding out unwanted dormants, low-scored articles,
8233 fetch-old-headers verbiage, and so on."
8234   ;; Most groups have nothing to remove.
8235   (if (or gnus-inhibit-limiting
8236           (and (null gnus-newsgroup-dormant)
8237                (eq gnus-newsgroup-display 'gnus-not-ignore)
8238                (not (eq gnus-fetch-old-headers 'some))
8239                (not (numberp gnus-fetch-old-headers))
8240                (not (eq gnus-fetch-old-headers 'invisible))
8241                (null gnus-summary-expunge-below)
8242                (not (eq gnus-build-sparse-threads 'some))
8243                (not (eq gnus-build-sparse-threads 'more))
8244                (null gnus-thread-expunge-below)
8245                (not gnus-use-nocem)))
8246       ()                                ; Do nothing.
8247     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8248     (setq gnus-newsgroup-limit nil)
8249     (mapatoms
8250      (lambda (node)
8251        (unless (car (symbol-value node))
8252          ;; These threads have no parents -- they are roots.
8253          (let ((nodes (cdr (symbol-value node)))
8254                thread)
8255            (while nodes
8256              (if (and gnus-thread-expunge-below
8257                       (< (gnus-thread-total-score (car nodes))
8258                          gnus-thread-expunge-below))
8259                  (gnus-expunge-thread (pop nodes))
8260                (setq thread (pop nodes))
8261                (gnus-summary-limit-children thread))))))
8262      gnus-newsgroup-dependencies)
8263     ;; If this limitation resulted in an empty group, we might
8264     ;; pop the previous limit and use it instead.
8265     (when (and (not gnus-newsgroup-limit)
8266                show-if-empty)
8267       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8268     gnus-newsgroup-limit))
8269
8270 (defun gnus-summary-limit-children (thread)
8271   "Return 1 if this subthread is visible and 0 if it is not."
8272   ;; First we get the number of visible children to this thread.  This
8273   ;; is done by recursing down the thread using this function, so this
8274   ;; will really go down to a leaf article first, before slowly
8275   ;; working its way up towards the root.
8276   (when thread
8277     (let* ((max-lisp-eval-depth 5000)
8278            (children
8279            (if (cdr thread)
8280                (apply '+ (mapcar 'gnus-summary-limit-children
8281                                  (cdr thread)))
8282              0))
8283           (number (mail-header-number (car thread)))
8284           score)
8285       (if (and
8286            (not (memq number gnus-newsgroup-marked))
8287            (or
8288             ;; If this article is dormant and has absolutely no visible
8289             ;; children, then this article isn't visible.
8290             (and (memq number gnus-newsgroup-dormant)
8291                  (zerop children))
8292             ;; If this is "fetch-old-headered" and there is no
8293             ;; visible children, then we don't want this article.
8294             (and (or (eq gnus-fetch-old-headers 'some)
8295                      (numberp gnus-fetch-old-headers))
8296                  (gnus-summary-article-ancient-p number)
8297                  (zerop children))
8298             ;; If this is "fetch-old-headered" and `invisible', then
8299             ;; we don't want this article.
8300             (and (eq gnus-fetch-old-headers 'invisible)
8301                  (gnus-summary-article-ancient-p number))
8302             ;; If this is a sparsely inserted article with no children,
8303             ;; we don't want it.
8304             (and (eq gnus-build-sparse-threads 'some)
8305                  (gnus-summary-article-sparse-p number)
8306                  (zerop children))
8307             ;; If we use expunging, and this article is really
8308             ;; low-scored, then we don't want this article.
8309             (when (and gnus-summary-expunge-below
8310                        (< (setq score
8311                                 (or (cdr (assq number gnus-newsgroup-scored))
8312                                     gnus-summary-default-score))
8313                           gnus-summary-expunge-below))
8314               ;; We increase the expunge-tally here, but that has
8315               ;; nothing to do with the limits, really.
8316               (incf gnus-newsgroup-expunged-tally)
8317               ;; We also mark as read here, if that's wanted.
8318               (when (and gnus-summary-mark-below
8319                          (< score gnus-summary-mark-below))
8320                 (setq gnus-newsgroup-unreads
8321                       (delq number gnus-newsgroup-unreads))
8322                 (if gnus-newsgroup-auto-expire
8323                     (push number gnus-newsgroup-expirable)
8324                   (push (cons number gnus-low-score-mark)
8325                         gnus-newsgroup-reads)))
8326               t)
8327             ;; Do the `display' group parameter.
8328             (and gnus-newsgroup-display
8329                  (not (funcall gnus-newsgroup-display)))
8330             ;; Check NoCeM things.
8331             (when (and gnus-use-nocem
8332                        (gnus-nocem-unwanted-article-p
8333                         (mail-header-id (car thread))))
8334               (setq gnus-newsgroup-unreads
8335                     (delq number gnus-newsgroup-unreads))
8336               t)))
8337           ;; Nope, invisible article.
8338           0
8339         ;; Ok, this article is to be visible, so we add it to the limit
8340         ;; and return 1.
8341         (push number gnus-newsgroup-limit)
8342         1))))
8343
8344 (defun gnus-expunge-thread (thread)
8345   "Mark all articles in THREAD as read."
8346   (let* ((number (mail-header-number (car thread))))
8347     (incf gnus-newsgroup-expunged-tally)
8348     ;; We also mark as read here, if that's wanted.
8349     (setq gnus-newsgroup-unreads
8350           (delq number gnus-newsgroup-unreads))
8351     (if gnus-newsgroup-auto-expire
8352         (push number gnus-newsgroup-expirable)
8353       (push (cons number gnus-low-score-mark)
8354             gnus-newsgroup-reads)))
8355   ;; Go recursively through all subthreads.
8356   (mapcar 'gnus-expunge-thread (cdr thread)))
8357
8358 ;; Summary article oriented commands
8359
8360 (defun gnus-summary-refer-parent-article (n)
8361   "Refer parent article N times.
8362 If N is negative, go to ancestor -N instead.
8363 The difference between N and the number of articles fetched is returned."
8364   (interactive "p")
8365   (let ((skip 1)
8366         error header ref)
8367     (when (not (natnump n))
8368       (setq skip (abs n)
8369             n 1))
8370     (while (and (> n 0)
8371                 (not error))
8372       (setq header (gnus-summary-article-header))
8373       (if (and (eq (mail-header-number header)
8374                    (cdr gnus-article-current))
8375                (equal gnus-newsgroup-name
8376                       (car gnus-article-current)))
8377           ;; If we try to find the parent of the currently
8378           ;; displayed article, then we take a look at the actual
8379           ;; References header, since this is slightly more
8380           ;; reliable than the References field we got from the
8381           ;; server.
8382           (save-excursion
8383             (set-buffer gnus-original-article-buffer)
8384             (nnheader-narrow-to-headers)
8385             (unless (setq ref (message-fetch-field "references"))
8386               (when (setq ref (message-fetch-field "in-reply-to"))
8387                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8388             (widen))
8389         (setq ref
8390               ;; It's not the current article, so we take a bet on
8391               ;; the value we got from the server.
8392               (mail-header-references header)))
8393       (if (and ref
8394                (not (equal ref "")))
8395           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8396             (gnus-message 1 "Couldn't find parent"))
8397         (gnus-message 1 "No references in article %d"
8398                       (gnus-summary-article-number))
8399         (setq error t))
8400       (decf n))
8401     (gnus-summary-position-point)
8402     n))
8403
8404 (defun gnus-summary-refer-references ()
8405   "Fetch all articles mentioned in the References header.
8406 Return the number of articles fetched."
8407   (interactive)
8408   (let ((ref (mail-header-references (gnus-summary-article-header)))
8409         (current (gnus-summary-article-number))
8410         (n 0))
8411     (if (or (not ref)
8412             (equal ref ""))
8413         (error "No References in the current article")
8414       ;; For each Message-ID in the References header...
8415       (while (string-match "<[^>]*>" ref)
8416         (incf n)
8417         ;; ... fetch that article.
8418         (gnus-summary-refer-article
8419          (prog1 (match-string 0 ref)
8420            (setq ref (substring ref (match-end 0))))))
8421       (gnus-summary-goto-subject current)
8422       (gnus-summary-position-point)
8423       n)))
8424
8425 (defun gnus-summary-refer-thread (&optional limit)
8426   "Fetch all articles in the current thread.
8427 If LIMIT (the numerical prefix), fetch that many old headers instead
8428 of what's specified by the `gnus-refer-thread-limit' variable."
8429   (interactive "P")
8430   (let ((id (mail-header-id (gnus-summary-article-header)))
8431         (limit (if limit (prefix-numeric-value limit)
8432                  gnus-refer-thread-limit)))
8433     (unless (eq gnus-fetch-old-headers 'invisible)
8434       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8435       ;; Retrieve the headers and read them in.
8436       (if (eq (if (numberp limit)
8437                   (gnus-retrieve-headers
8438                    (list (min
8439                           (+ (mail-header-number
8440                               (gnus-summary-article-header))
8441                              limit)
8442                           gnus-newsgroup-end))
8443                    gnus-newsgroup-name (* limit 2))
8444                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8445                 ;; headers.
8446                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8447                                        gnus-newsgroup-name limit))
8448               'nov)
8449           (gnus-build-all-threads)
8450         (error "Can't fetch thread from back ends that don't support NOV"))
8451       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8452     (gnus-summary-limit-include-thread id)))
8453
8454 (defun gnus-summary-refer-article (message-id)
8455   "Fetch an article specified by MESSAGE-ID."
8456   (interactive "sMessage-ID: ")
8457   (when (and (stringp message-id)
8458              (not (zerop (length message-id))))
8459     (setq message-id (gnus-replace-in-string message-id " " ""))
8460     ;; Construct the correct Message-ID if necessary.
8461     ;; Suggested by tale@pawl.rpi.edu.
8462     (unless (string-match "^<" message-id)
8463       (setq message-id (concat "<" message-id)))
8464     (unless (string-match ">$" message-id)
8465       (setq message-id (concat message-id ">")))
8466     ;; People often post MIDs from URLs, so unhex it:
8467     (unless (string-match "@" message-id)
8468       (setq message-id (gnus-url-unhex-string message-id)))
8469     (let* ((header (gnus-id-to-header message-id))
8470            (sparse (and header
8471                         (gnus-summary-article-sparse-p
8472                          (mail-header-number header))
8473                         (memq (mail-header-number header)
8474                               gnus-newsgroup-limit)))
8475            number)
8476       (cond
8477        ;; If the article is present in the buffer we just go to it.
8478        ((and header
8479              (or (not (gnus-summary-article-sparse-p
8480                        (mail-header-number header)))
8481                  sparse))
8482         (prog1
8483             (gnus-summary-goto-article
8484              (mail-header-number header) nil t)
8485           (when sparse
8486             (gnus-summary-update-article (mail-header-number header)))))
8487        (t
8488         ;; We fetch the article.
8489         (catch 'found
8490           (dolist (gnus-override-method (gnus-refer-article-methods))
8491             (when (and (gnus-check-server gnus-override-method)
8492                        ;; Fetch the header,
8493                        (setq number (gnus-summary-insert-subject message-id)))
8494               ;; and display the article.
8495               (gnus-summary-select-article nil nil nil number)
8496               (throw 'found t)))
8497           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8498
8499 (defun gnus-refer-article-methods ()
8500   "Return a list of referable methods."
8501   (cond
8502    ;; No method, so we default to current and native.
8503    ((null gnus-refer-article-method)
8504     (list gnus-current-select-method gnus-select-method))
8505    ;; Current.
8506    ((eq 'current gnus-refer-article-method)
8507     (list gnus-current-select-method))
8508    ;; List of select methods.
8509    ((not (and (symbolp (car gnus-refer-article-method))
8510               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8511     (let (out)
8512       (dolist (method gnus-refer-article-method)
8513         (push (if (eq 'current method)
8514                   gnus-current-select-method
8515                 method)
8516               out))
8517       (nreverse out)))
8518    ;; One single select method.
8519    (t
8520     (list gnus-refer-article-method))))
8521
8522 (defun gnus-summary-edit-parameters ()
8523   "Edit the group parameters of the current group."
8524   (interactive)
8525   (gnus-group-edit-group gnus-newsgroup-name 'params))
8526
8527 (defun gnus-summary-customize-parameters ()
8528   "Customize the group parameters of the current group."
8529   (interactive)
8530   (gnus-group-customize gnus-newsgroup-name))
8531
8532 (defun gnus-summary-enter-digest-group (&optional force)
8533   "Enter an nndoc group based on the current article.
8534 If FORCE, force a digest interpretation.  If not, try
8535 to guess what the document format is."
8536   (interactive "P")
8537   (let ((conf gnus-current-window-configuration))
8538     (save-window-excursion
8539       (save-excursion
8540         (let (gnus-article-prepare-hook
8541               gnus-display-mime-function
8542               gnus-break-pages)
8543           (gnus-summary-select-article))))
8544     (setq gnus-current-window-configuration conf)
8545     (let* ((name (format "%s-%d"
8546                          (gnus-group-prefixed-name
8547                           gnus-newsgroup-name (list 'nndoc ""))
8548                          (with-current-buffer gnus-summary-buffer
8549                            gnus-current-article)))
8550            (ogroup gnus-newsgroup-name)
8551            (params (append (gnus-info-params (gnus-get-info ogroup))
8552                            (list (cons 'to-group ogroup))
8553                            (list (cons 'parent-group ogroup))
8554                            (list (cons 'save-article-group ogroup))))
8555            (case-fold-search t)
8556            (buf (current-buffer))
8557            dig to-address)
8558       (save-excursion
8559         (set-buffer gnus-original-article-buffer)
8560         ;; Have the digest group inherit the main mail address of
8561         ;; the parent article.
8562         (when (setq to-address (or (gnus-fetch-field "reply-to")
8563                                    (gnus-fetch-field "from")))
8564           (setq params (append
8565                         (list (cons 'to-address
8566                                     (funcall gnus-decode-encoded-word-function
8567                                              to-address))))))
8568         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8569         (insert-buffer-substring gnus-original-article-buffer)
8570         ;; Remove lines that may lead nndoc to misinterpret the
8571         ;; document type.
8572         (narrow-to-region
8573          (goto-char (point-min))
8574          (or (search-forward "\n\n" nil t) (point)))
8575         (goto-char (point-min))
8576         (delete-matching-lines "^Path:\\|^From ")
8577         (widen))
8578       (unwind-protect
8579           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8580                     (gnus-newsgroup-ephemeral-ignored-charsets
8581                      gnus-newsgroup-ignored-charsets))
8582                 (gnus-group-read-ephemeral-group
8583                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8584                               (nndoc-article-type
8585                                ,(if force 'mbox 'guess)))
8586                  t nil nil nil
8587                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8588                                                         "ADAPT")))))
8589               ;; Make all postings to this group go to the parent group.
8590               (nconc (gnus-info-params (gnus-get-info name))
8591                      params)
8592             ;; Couldn't select this doc group.
8593             (switch-to-buffer buf)
8594             (gnus-set-global-variables)
8595             (gnus-configure-windows 'summary)
8596             (gnus-message 3 "Article couldn't be entered?"))
8597         (kill-buffer dig)))))
8598
8599 (defun gnus-summary-read-document (n)
8600   "Open a new group based on the current article(s).
8601 This will allow you to read digests and other similar
8602 documents as newsgroups.
8603 Obeys the standard process/prefix convention."
8604   (interactive "P")
8605   (let* ((ogroup gnus-newsgroup-name)
8606          (params (append (gnus-info-params (gnus-get-info ogroup))
8607                          (list (cons 'to-group ogroup))))
8608          group egroup groups vgroup)
8609     (dolist (article (gnus-summary-work-articles n))
8610       (setq group (format "%s-%d" gnus-newsgroup-name article))
8611       (gnus-summary-remove-process-mark article)
8612       (when (gnus-summary-display-article article)
8613         (save-excursion
8614           (with-temp-buffer
8615             (insert-buffer-substring gnus-original-article-buffer)
8616             ;; Remove some headers that may lead nndoc to make
8617             ;; the wrong guess.
8618             (message-narrow-to-head)
8619             (goto-char (point-min))
8620             (delete-matching-lines "^Path:\\|^From ")
8621             (widen)
8622             (if (setq egroup
8623                       (gnus-group-read-ephemeral-group
8624                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8625                                      (nndoc-article-type guess))
8626                        t nil t))
8627                 (progn
8628             ;; Make all postings to this group go to the parent group.
8629                   (nconc (gnus-info-params (gnus-get-info egroup))
8630                          params)
8631                   (push egroup groups))
8632               ;; Couldn't select this doc group.
8633               (gnus-error 3 "Article couldn't be entered"))))))
8634     ;; Now we have selected all the documents.
8635     (cond
8636      ((not groups)
8637       (error "None of the articles could be interpreted as documents"))
8638      ((gnus-group-read-ephemeral-group
8639        (setq vgroup (format
8640                      "nnvirtual:%s-%s" gnus-newsgroup-name
8641                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8642        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8643        t
8644        (cons (current-buffer) 'summary)))
8645      (t
8646       (error "Couldn't select virtual nndoc group")))))
8647
8648 (defun gnus-summary-isearch-article (&optional regexp-p)
8649   "Do incremental search forward on the current article.
8650 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8651   (interactive "P")
8652   (gnus-summary-select-article)
8653   (gnus-configure-windows 'article)
8654   (gnus-eval-in-buffer-window gnus-article-buffer
8655     (save-restriction
8656       (widen)
8657       (isearch-forward regexp-p))))
8658
8659 (defun gnus-summary-search-article-forward (regexp &optional backward)
8660   "Search for an article containing REGEXP forward.
8661 If BACKWARD, search backward instead."
8662   (interactive
8663    (list (read-string
8664           (format "Search article %s (regexp%s): "
8665                   (if current-prefix-arg "backward" "forward")
8666                   (if gnus-last-search-regexp
8667                       (concat ", default " gnus-last-search-regexp)
8668                     "")))
8669          current-prefix-arg))
8670   (if (string-equal regexp "")
8671       (setq regexp (or gnus-last-search-regexp ""))
8672     (setq gnus-last-search-regexp regexp)
8673     (setq gnus-article-before-search gnus-current-article))
8674   ;; Intentionally set gnus-last-article.
8675   (setq gnus-last-article gnus-article-before-search)
8676   (let ((gnus-last-article gnus-last-article))
8677     (if (gnus-summary-search-article regexp backward)
8678         (gnus-summary-show-thread)
8679       (signal 'search-failed (list regexp)))))
8680
8681 (defun gnus-summary-search-article-backward (regexp)
8682   "Search for an article containing REGEXP backward."
8683   (interactive
8684    (list (read-string
8685           (format "Search article backward (regexp%s): "
8686                   (if gnus-last-search-regexp
8687                       (concat ", default " gnus-last-search-regexp)
8688                     "")))))
8689   (gnus-summary-search-article-forward regexp 'backward))
8690
8691 (defun gnus-summary-search-article (regexp &optional backward)
8692   "Search for an article containing REGEXP.
8693 Optional argument BACKWARD means do search for backward.
8694 `gnus-select-article-hook' is not called during the search."
8695   ;; We have to require this here to make sure that the following
8696   ;; dynamic binding isn't shadowed by autoloading.
8697   (require 'gnus-async)
8698   (require 'gnus-art)
8699   (let ((gnus-select-article-hook nil)  ;Disable hook.
8700         (gnus-article-prepare-hook nil)
8701         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8702         (gnus-use-article-prefetch nil)
8703         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8704         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8705         (gnus-visual nil)
8706         (gnus-keep-backlog nil)
8707         (gnus-break-pages nil)
8708         (gnus-summary-display-arrow nil)
8709         (gnus-updated-mode-lines nil)
8710         (gnus-auto-center-summary nil)
8711         (sum (current-buffer))
8712         (gnus-display-mime-function nil)
8713         (found nil)
8714         point)
8715     (gnus-save-hidden-threads
8716       (gnus-summary-select-article)
8717       (set-buffer gnus-article-buffer)
8718       (goto-char (window-point (get-buffer-window (current-buffer))))
8719       (when backward
8720         (forward-line -1))
8721       (while (not found)
8722         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8723         (if (if backward
8724                 (re-search-backward regexp nil t)
8725               (re-search-forward regexp nil t))
8726             ;; We found the regexp.
8727             (progn
8728               (setq found 'found)
8729               (beginning-of-line)
8730               (set-window-start
8731                (get-buffer-window (current-buffer))
8732                (point))
8733               (forward-line 1)
8734               (set-window-point
8735                (get-buffer-window (current-buffer))
8736                (point))
8737               (set-buffer sum)
8738               (setq point (point)))
8739           ;; We didn't find it, so we go to the next article.
8740           (set-buffer sum)
8741           (setq found 'not)
8742           (while (eq found 'not)
8743             (if (not (if backward (gnus-summary-find-prev)
8744                        (gnus-summary-find-next)))
8745                 ;; No more articles.
8746                 (setq found t)
8747               ;; Select the next article and adjust point.
8748               (unless (gnus-summary-article-sparse-p
8749                        (gnus-summary-article-number))
8750                 (setq found nil)
8751                 (gnus-summary-select-article)
8752                 (set-buffer gnus-article-buffer)
8753                 (widen)
8754                 (goto-char (if backward (point-max) (point-min))))))))
8755       (gnus-message 7 ""))
8756     ;; Return whether we found the regexp.
8757     (when (eq found 'found)
8758       (goto-char point)
8759       (gnus-summary-show-thread)
8760       (gnus-summary-goto-subject gnus-current-article)
8761       (gnus-summary-position-point)
8762       t)))
8763
8764 (defun gnus-find-matching-articles (header regexp)
8765   "Return a list of all articles that match REGEXP on HEADER.
8766 This search includes all articles in the current group that Gnus has
8767 fetched headers for, whether they are displayed or not."
8768   (let ((articles nil)
8769         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8770         (case-fold-search t))
8771     (dolist (header gnus-newsgroup-headers)
8772       (when (string-match regexp (funcall func header))
8773         (push (mail-header-number header) articles)))
8774     (nreverse articles)))
8775
8776 (defun gnus-summary-find-matching (header regexp &optional backward unread
8777                                           not-case-fold not-matching)
8778   "Return a list of all articles that match REGEXP on HEADER.
8779 The search stars on the current article and goes forwards unless
8780 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8781 If UNREAD is non-nil, only unread articles will
8782 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8783 in the comparisons. If NOT-MATCHING, return a list of all articles that
8784 not match REGEXP on HEADER."
8785   (let ((case-fold-search (not not-case-fold))
8786         articles d func)
8787     (if (consp header)
8788         (if (eq (car header) 'extra)
8789             (setq func
8790                   `(lambda (h)
8791                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8792                          "")))
8793           (error "%s is an invalid header" header))
8794       (unless (fboundp (intern (concat "mail-header-" header)))
8795         (error "%s is not a valid header" header))
8796       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8797     (dolist (d (if (eq backward 'all)
8798                    gnus-newsgroup-data
8799                  (gnus-data-find-list
8800                   (gnus-summary-article-number)
8801                   (gnus-data-list backward))))
8802       (when (and (or (not unread)       ; We want all articles...
8803                      (gnus-data-unread-p d)) ; Or just unreads.
8804                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8805                  (if not-matching
8806                      (not (string-match
8807                            regexp
8808                            (funcall func (gnus-data-header d))))
8809                    (string-match regexp
8810                                  (funcall func (gnus-data-header d)))))
8811         (push (gnus-data-number d) articles))) ; Success!
8812     (nreverse articles)))
8813
8814 (defun gnus-summary-execute-command (header regexp command &optional backward)
8815   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8816 If HEADER is an empty string (or nil), the match is done on the entire
8817 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8818   (interactive
8819    (list (let ((completion-ignore-case t))
8820            (completing-read
8821             "Header name: "
8822             (mapcar (lambda (header) (list (format "%s" header)))
8823                     (append
8824                      '("Number" "Subject" "From" "Lines" "Date"
8825                        "Message-ID" "Xref" "References" "Body")
8826                      gnus-extra-headers))
8827             nil 'require-match))
8828          (read-string "Regexp: ")
8829          (read-key-sequence "Command: ")
8830          current-prefix-arg))
8831   (when (equal header "Body")
8832     (setq header ""))
8833   ;; Hidden thread subtrees must be searched as well.
8834   (gnus-summary-show-all-threads)
8835   ;; We don't want to change current point nor window configuration.
8836   (save-excursion
8837     (save-window-excursion
8838       (let (gnus-visual
8839             gnus-treat-strip-trailing-blank-lines
8840             gnus-treat-strip-leading-blank-lines
8841             gnus-treat-strip-multiple-blank-lines
8842             gnus-treat-hide-boring-headers
8843             gnus-treat-fold-newsgroups
8844             gnus-article-prepare-hook)
8845         (gnus-message 6 "Executing %s..." (key-description command))
8846         ;; We'd like to execute COMMAND interactively so as to give arguments.
8847         (gnus-execute header regexp
8848                       `(call-interactively ',(key-binding command))
8849                       backward)
8850         (gnus-message 6 "Executing %s...done" (key-description command))))))
8851
8852 (defun gnus-summary-beginning-of-article ()
8853   "Scroll the article back to the beginning."
8854   (interactive)
8855   (gnus-summary-select-article)
8856   (gnus-configure-windows 'article)
8857   (gnus-eval-in-buffer-window gnus-article-buffer
8858     (widen)
8859     (goto-char (point-min))
8860     (when gnus-break-pages
8861       (gnus-narrow-to-page))))
8862
8863 (defun gnus-summary-end-of-article ()
8864   "Scroll to the end of the article."
8865   (interactive)
8866   (gnus-summary-select-article)
8867   (gnus-configure-windows 'article)
8868   (gnus-eval-in-buffer-window gnus-article-buffer
8869     (widen)
8870     (goto-char (point-max))
8871     (recenter -3)
8872     (when gnus-break-pages
8873       (when (re-search-backward page-delimiter nil t)
8874         (narrow-to-region (match-end 0) (point-max)))
8875       (gnus-narrow-to-page))))
8876
8877 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8878   "Truncate to LEN and quote all \"(\"'s in STRING."
8879   (gnus-replace-in-string (if (and len (> (length string) len))
8880                               (substring string 0 len)
8881                             string)
8882                           "[()]" "\\\\\\&"))
8883
8884 (defun gnus-summary-print-article (&optional filename n)
8885   "Generate and print a PostScript image of the process-marked (mail) articles.
8886
8887 If used interactively, print the current article if none are
8888 process-marked.  With prefix arg, prompt the user for the name of the
8889 file to save in.
8890
8891 When used from Lisp, accept two optional args FILENAME and N.  N means
8892 to print the next N articles.  If N is negative, print the N previous
8893 articles.  If N is nil and articles have been marked with the process
8894 mark, print these instead.
8895
8896 If the optional first argument FILENAME is nil, send the image to the
8897 printer.  If FILENAME is a string, save the PostScript image in a file with
8898 that name.  If FILENAME is a number, prompt the user for the name of the file
8899 to save in."
8900   (interactive (list (ps-print-preprint current-prefix-arg)))
8901   (dolist (article (gnus-summary-work-articles n))
8902     (gnus-summary-select-article nil nil 'pseudo article)
8903     (gnus-eval-in-buffer-window gnus-article-buffer
8904       (gnus-print-buffer))
8905     (gnus-summary-remove-process-mark article))
8906   (ps-despool filename))
8907
8908 (defun gnus-print-buffer ()
8909   (let ((buffer (generate-new-buffer " *print*")))
8910     (unwind-protect
8911         (progn
8912           (copy-to-buffer buffer (point-min) (point-max))
8913           (set-buffer buffer)
8914           (gnus-remove-text-with-property 'gnus-decoration)
8915           (when (gnus-visual-p 'article-highlight 'highlight)
8916             ;; Copy-to-buffer doesn't copy overlay.  So redo
8917             ;; highlight.
8918             (let ((gnus-article-buffer buffer))
8919               (gnus-article-highlight-citation t)
8920               (gnus-article-highlight-signature)
8921               (gnus-article-emphasize)
8922               (gnus-article-delete-invisible-text)))
8923           (let ((ps-left-header
8924                  (list
8925                   (concat "("
8926                           (gnus-summary-print-truncate-and-quote
8927                            (mail-header-subject gnus-current-headers)
8928                            66) ")")
8929                   (concat "("
8930                           (gnus-summary-print-truncate-and-quote
8931                            (mail-header-from gnus-current-headers)
8932                            45) ")")))
8933                 (ps-right-header
8934                  (list
8935                   "/pagenumberstring load"
8936                   (concat "("
8937                           (mail-header-date gnus-current-headers) ")"))))
8938             (gnus-run-hooks 'gnus-ps-print-hook)
8939             (save-excursion
8940               (if window-system
8941                   (ps-spool-buffer-with-faces)
8942                 (ps-spool-buffer)))))
8943       (kill-buffer buffer))))
8944
8945 (defun gnus-summary-show-article (&optional arg)
8946   "Force redisplaying of the current article.
8947 If ARG (the prefix) is a number, show the article with the charset
8948 defined in `gnus-summary-show-article-charset-alist', or the charset
8949 input.
8950 If ARG (the prefix) is non-nil and not a number, show the raw article
8951 without any article massaging functions being run.  Normally, the key
8952 strokes are `C-u g'."
8953   (interactive "P")
8954   (cond
8955    ((numberp arg)
8956     (gnus-summary-show-article t)
8957     (let ((gnus-newsgroup-charset
8958            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8959                (mm-read-coding-system
8960                 "View as charset: " ;; actually it is coding system.
8961                 (with-current-buffer gnus-article-buffer
8962                   (mm-detect-coding-region (point) (point-max))))))
8963           (gnus-newsgroup-ignored-charsets 'gnus-all))
8964       (gnus-summary-select-article nil 'force)
8965       (let ((deps gnus-newsgroup-dependencies)
8966             head header lines)
8967         (save-excursion
8968           (set-buffer gnus-original-article-buffer)
8969           (save-restriction
8970             (message-narrow-to-head)
8971             (setq head (buffer-string))
8972             (goto-char (point-min))
8973             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8974               (goto-char (point-max))
8975               (widen)
8976               (setq lines (1- (count-lines (point) (point-max))))))
8977           (with-temp-buffer
8978             (insert (format "211 %d Article retrieved.\n"
8979                             (cdr gnus-article-current)))
8980             (insert head)
8981             (if lines (insert (format "Lines: %d\n" lines)))
8982             (insert ".\n")
8983             (let ((nntp-server-buffer (current-buffer)))
8984               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8985         (gnus-data-set-header
8986          (gnus-data-find (cdr gnus-article-current))
8987          header)
8988         (gnus-summary-update-article-line
8989          (cdr gnus-article-current) header)
8990         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8991           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8992    ((not arg)
8993     ;; Select the article the normal way.
8994     (gnus-summary-select-article nil 'force))
8995    (t
8996     ;; We have to require this here to make sure that the following
8997     ;; dynamic binding isn't shadowed by autoloading.
8998     (require 'gnus-async)
8999     (require 'gnus-art)
9000     ;; Bind the article treatment functions to nil.
9001     (let ((gnus-have-all-headers t)
9002           gnus-article-prepare-hook
9003           gnus-article-decode-hook
9004           gnus-display-mime-function
9005           gnus-break-pages)
9006       ;; Destroy any MIME parts.
9007       (when (gnus-buffer-live-p gnus-article-buffer)
9008         (save-excursion
9009           (set-buffer gnus-article-buffer)
9010           (mm-destroy-parts gnus-article-mime-handles)
9011           ;; Set it to nil for safety reason.
9012           (setq gnus-article-mime-handle-alist nil)
9013           (setq gnus-article-mime-handles nil)))
9014       (gnus-summary-select-article nil 'force))))
9015   (gnus-summary-goto-subject gnus-current-article)
9016   (gnus-summary-position-point))
9017
9018 (defun gnus-summary-show-raw-article ()
9019   "Show the raw article without any article massaging functions being run."
9020   (interactive)
9021   (gnus-summary-show-article t))
9022
9023 (defun gnus-summary-verbose-headers (&optional arg)
9024   "Toggle permanent full header display.
9025 If ARG is a positive number, turn header display on.
9026 If ARG is a negative number, turn header display off."
9027   (interactive "P")
9028   (setq gnus-show-all-headers
9029         (cond ((or (not (numberp arg))
9030                    (zerop arg))
9031                (not gnus-show-all-headers))
9032               ((natnump arg)
9033                t)))
9034   (gnus-summary-show-article))
9035
9036 (defun gnus-summary-toggle-header (&optional arg)
9037   "Show the headers if they are hidden, or hide them if they are shown.
9038 If ARG is a positive number, show the entire header.
9039 If ARG is a negative number, hide the unwanted header lines."
9040   (interactive "P")
9041   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9042                      (get-buffer-window gnus-article-buffer t))))
9043     (with-current-buffer gnus-article-buffer
9044       (widen)
9045       (article-narrow-to-head)
9046       (let* ((buffer-read-only nil)
9047              (inhibit-point-motion-hooks t)
9048              (hidden (if (numberp arg)
9049                          (>= arg 0)
9050                        (or (not (looking-at "[^ \t\n]+:"))
9051                            (gnus-article-hidden-text-p 'headers))))
9052              s e)
9053         (delete-region (point-min) (point-max))
9054         (with-current-buffer gnus-original-article-buffer
9055           (goto-char (setq s (point-min)))
9056           (setq e (if (search-forward "\n\n" nil t)
9057                       (1- (point))
9058                     (point-max))))
9059         (insert-buffer-substring gnus-original-article-buffer s e)
9060         (run-hooks 'gnus-article-decode-hook)
9061         (if hidden
9062             (let ((gnus-treat-hide-headers nil)
9063                   (gnus-treat-hide-boring-headers nil))
9064               (gnus-delete-wash-type 'headers)
9065               (gnus-treat-article 'head))
9066           (gnus-treat-article 'head))
9067         (widen)
9068         (if window
9069             (set-window-start window (goto-char (point-min))))
9070         (if gnus-break-pages
9071             (gnus-narrow-to-page)
9072           (when (gnus-visual-p 'page-marker)
9073             (let ((buffer-read-only nil))
9074               (gnus-remove-text-with-property 'gnus-prev)
9075               (gnus-remove-text-with-property 'gnus-next))))
9076         (gnus-set-mode-line 'article)))))
9077
9078 (defun gnus-summary-show-all-headers ()
9079   "Make all header lines visible."
9080   (interactive)
9081   (gnus-summary-toggle-header 1))
9082
9083 (defun gnus-summary-caesar-message (&optional arg)
9084   "Caesar rotate the current article by 13.
9085 The numerical prefix specifies how many places to rotate each letter
9086 forward."
9087   (interactive "P")
9088   (gnus-summary-select-article)
9089   (let ((mail-header-separator ""))
9090     (gnus-eval-in-buffer-window gnus-article-buffer
9091       (save-restriction
9092         (widen)
9093         (let ((start (window-start))
9094               buffer-read-only)
9095           (message-caesar-buffer-body arg)
9096           (set-window-start (get-buffer-window (current-buffer)) start)))))
9097   ;; Create buttons and stuff...
9098   (gnus-treat-article nil))
9099
9100 (defun gnus-summary-idna-message (&optional arg)
9101   "Decode IDNA encoded domain names in the current articles.
9102 IDNA encoded domain names looks like `xn--bar'.  If a string
9103 remain unencoded after running this function, it is likely an
9104 invalid IDNA string (`xn--bar' is invalid).
9105
9106 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9107 installed for this command to work."
9108   (interactive "P")
9109   (if (not (and (condition-case nil (require 'idna)
9110                   (file-error))
9111                 (mm-coding-system-p 'utf-8)
9112                 (executable-find (symbol-value 'idna-program))))
9113       (gnus-message
9114        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9115     (gnus-summary-select-article)
9116     (let ((mail-header-separator ""))
9117       (gnus-eval-in-buffer-window gnus-article-buffer
9118         (save-restriction
9119           (widen)
9120           (let ((start (window-start))
9121                 buffer-read-only)
9122             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9123               (replace-match (idna-to-unicode (match-string 1))))
9124             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9125
9126 (autoload 'unmorse-region "morse"
9127   "Convert morse coded text in region to ordinary ASCII text."
9128   t)
9129
9130 (defun gnus-summary-morse-message (&optional arg)
9131   "Morse decode the current article."
9132   (interactive "P")
9133   (gnus-summary-select-article)
9134   (let ((mail-header-separator ""))
9135     (gnus-eval-in-buffer-window gnus-article-buffer
9136       (save-excursion
9137         (save-restriction
9138           (widen)
9139           (let ((pos (window-start))
9140                 buffer-read-only)
9141             (goto-char (point-min))
9142             (when (message-goto-body)
9143               (gnus-narrow-to-body))
9144             (goto-char (point-min))
9145             (while (search-forward "·" (point-max) t)
9146               (replace-match "."))
9147             (unmorse-region (point-min) (point-max))
9148             (widen)
9149             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9150
9151 (defun gnus-summary-stop-page-breaking ()
9152   "Stop page breaking in the current article."
9153   (interactive)
9154   (gnus-summary-select-article)
9155   (gnus-eval-in-buffer-window gnus-article-buffer
9156     (widen)
9157     (when (gnus-visual-p 'page-marker)
9158       (let ((buffer-read-only nil))
9159         (gnus-remove-text-with-property 'gnus-prev)
9160         (gnus-remove-text-with-property 'gnus-next))
9161       (setq gnus-page-broken nil))))
9162
9163 (defun gnus-summary-move-article (&optional n to-newsgroup
9164                                             select-method action)
9165   "Move the current article to a different newsgroup.
9166 If N is a positive number, move the N next articles.
9167 If N is a negative number, move the N previous articles.
9168 If N is nil and any articles have been marked with the process mark,
9169 move those articles instead.
9170 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9171 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9172 re-spool using this method.
9173
9174 When called interactively with TO-NEWSGROUP being nil, the value of
9175 the variable `gnus-move-split-methods' is used for finding a default
9176 for the target newsgroup.
9177
9178 For this function to work, both the current newsgroup and the
9179 newsgroup that you want to move to have to support the `request-move'
9180 and `request-accept' functions.
9181
9182 ACTION can be either `move' (the default), `crosspost' or `copy'."
9183   (interactive "P")
9184   (unless action
9185     (setq action 'move))
9186   ;; Check whether the source group supports the required functions.
9187   (cond ((and (eq action 'move)
9188               (not (gnus-check-backend-function
9189                     'request-move-article gnus-newsgroup-name)))
9190          (error "The current group does not support article moving"))
9191         ((and (eq action 'crosspost)
9192               (not (gnus-check-backend-function
9193                     'request-replace-article gnus-newsgroup-name)))
9194          (error "The current group does not support article editing")))
9195   (let ((articles (gnus-summary-work-articles n))
9196         (prefix (if (gnus-check-backend-function
9197                      'request-move-article gnus-newsgroup-name)
9198                     (funcall gnus-move-group-prefix-function
9199                              gnus-newsgroup-name)
9200                   ""))
9201         (names '((move "Move" "Moving")
9202                  (copy "Copy" "Copying")
9203                  (crosspost "Crosspost" "Crossposting")))
9204         (copy-buf (save-excursion
9205                     (nnheader-set-temp-buffer " *copy article*")))
9206         art-group to-method new-xref article to-groups articles-to-update-marks)
9207     (unless (assq action names)
9208       (error "Unknown action %s" action))
9209     ;; Read the newsgroup name.
9210     (when (and (not to-newsgroup)
9211                (not select-method))
9212       (if (and gnus-move-split-methods
9213                (not
9214                 (and (memq gnus-current-article articles)
9215                      (gnus-buffer-live-p gnus-original-article-buffer))))
9216           ;; When `gnus-move-split-methods' is non-nil, we have to
9217           ;; select an article to give `gnus-read-move-group-name' an
9218           ;; opportunity to suggest an appropriate default.  However,
9219           ;; we needn't render or mark the article.
9220           (let ((gnus-display-mime-function nil)
9221                 (gnus-article-prepare-hook nil)
9222                 (gnus-mark-article-hook nil))
9223             (gnus-summary-select-article nil nil nil (car articles))))
9224       (setq to-newsgroup
9225             (gnus-read-move-group-name
9226              (cadr (assq action names))
9227              (symbol-value (intern (format "gnus-current-%s-group" action)))
9228              articles prefix))
9229       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9230     (setq to-method (or select-method
9231                         (gnus-server-to-method
9232                          (gnus-group-method to-newsgroup))))
9233     ;; Check the method we are to move this article to...
9234     (unless (gnus-check-backend-function
9235              'request-accept-article (car to-method))
9236       (error "%s does not support article copying" (car to-method)))
9237     (unless (gnus-check-server to-method)
9238       (error "Can't open server %s" (car to-method)))
9239     (gnus-message 6 "%s to %s: %s..."
9240                   (caddr (assq action names))
9241                   (or (car select-method) to-newsgroup) articles)
9242     (while articles
9243       (setq article (pop articles))
9244       (setq
9245        art-group
9246        (cond
9247         ;; Move the article.
9248         ((eq action 'move)
9249          ;; Remove this article from future suppression.
9250          (gnus-dup-unsuppress-article article)
9251          (let* ((from-method (gnus-find-method-for-group
9252                               gnus-newsgroup-name))
9253                 (to-method (gnus-find-method-for-group
9254                             to-newsgroup))
9255                 (move-is-internal (gnus-method-equal from-method to-method)))
9256          (gnus-request-move-article
9257           article                       ; Article to move
9258           gnus-newsgroup-name           ; From newsgroup
9259           (nth 1 (gnus-find-method-for-group
9260                   gnus-newsgroup-name)) ; Server
9261           (list 'gnus-request-accept-article
9262                 to-newsgroup (list 'quote select-method)
9263                 (not articles) t)       ; Accept form
9264           (not articles)                ; Only save nov last time
9265           move-is-internal)))           ; is this move internal?
9266         ;; Copy the article.
9267         ((eq action 'copy)
9268          (save-excursion
9269            (set-buffer copy-buf)
9270            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9271              (save-restriction
9272                (nnheader-narrow-to-headers)
9273                (dolist (hdr gnus-copy-article-ignored-headers)
9274                  (message-remove-header hdr t)))
9275              (gnus-request-accept-article
9276               to-newsgroup select-method (not articles) t))))
9277         ;; Crosspost the article.
9278         ((eq action 'crosspost)
9279          (let ((xref (message-tokenize-header
9280                       (mail-header-xref (gnus-summary-article-header article))
9281                       " ")))
9282            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9283                                   ":" (number-to-string article)))
9284            (unless xref
9285              (setq xref (list (system-name))))
9286            (setq new-xref
9287                  (concat
9288                   (mapconcat 'identity
9289                              (delete "Xref:" (delete new-xref xref))
9290                              " ")
9291                   " " new-xref))
9292            (save-excursion
9293              (set-buffer copy-buf)
9294              ;; First put the article in the destination group.
9295              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9296              (when (consp (setq art-group
9297                                 (gnus-request-accept-article
9298                                  to-newsgroup select-method (not articles))))
9299                (setq new-xref (concat new-xref " " (car art-group)
9300                                       ":"
9301                                       (number-to-string (cdr art-group))))
9302                ;; Now we have the new Xrefs header, so we insert
9303                ;; it and replace the new article.
9304                (nnheader-replace-header "Xref" new-xref)
9305                (gnus-request-replace-article
9306                 (cdr art-group) to-newsgroup (current-buffer))
9307                art-group))))))
9308       (cond
9309        ((not art-group)
9310         (gnus-message 1 "Couldn't %s article %s: %s"
9311                       (cadr (assq action names)) article
9312                       (nnheader-get-report (car to-method))))
9313        ((eq art-group 'junk)
9314         (when (eq action 'move)
9315           (gnus-summary-mark-article article gnus-canceled-mark)
9316           (gnus-message 4 "Deleted article %s" article)
9317           ;; run the delete hook
9318           (run-hook-with-args 'gnus-summary-article-delete-hook
9319                               action
9320                               (gnus-data-header
9321                                (assoc article (gnus-data-list nil)))
9322                               gnus-newsgroup-name nil
9323                               select-method)))
9324        (t
9325         (let* ((pto-group (gnus-group-prefixed-name
9326                            (car art-group) to-method))
9327                (info (gnus-get-info pto-group))
9328                (to-group (gnus-info-group info))
9329                to-marks)
9330           ;; Update the group that has been moved to.
9331           (when (and info
9332                      (memq action '(move copy)))
9333             (unless (member to-group to-groups)
9334               (push to-group to-groups))
9335
9336             (unless (memq article gnus-newsgroup-unreads)
9337               (push 'read to-marks)
9338               (gnus-info-set-read
9339                info (gnus-add-to-range (gnus-info-read info)
9340                                        (list (cdr art-group)))))
9341
9342             ;; See whether the article is to be put in the cache.
9343             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9344                              gnus-article-mark-lists
9345                            (delete '(expirable . expire)
9346                                    (copy-sequence gnus-article-mark-lists))))
9347                   (to-article (cdr art-group)))
9348
9349               ;; Enter the article into the cache in the new group,
9350               ;; if that is required.
9351               (when gnus-use-cache
9352                 (gnus-cache-possibly-enter-article
9353                  to-group to-article
9354                  (memq article gnus-newsgroup-marked)
9355                  (memq article gnus-newsgroup-dormant)
9356                  (memq article gnus-newsgroup-unreads)))
9357
9358               (when gnus-preserve-marks
9359                 ;; Copy any marks over to the new group.
9360                 (when (and (equal to-group gnus-newsgroup-name)
9361                            (not (memq article gnus-newsgroup-unreads)))
9362                   ;; Mark this article as read in this group.
9363                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9364                   (setcdr (gnus-active to-group) to-article)
9365                   (setcdr gnus-newsgroup-active to-article))
9366
9367                 (while marks
9368                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9369                     (when (memq article (symbol-value
9370                                          (intern (format "gnus-newsgroup-%s"
9371                                                          (caar marks)))))
9372                       (push (cdar marks) to-marks)
9373                       ;; If the other group is the same as this group,
9374                       ;; then we have to add the mark to the list.
9375                       (when (equal to-group gnus-newsgroup-name)
9376                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9377                              (cons to-article
9378                                    (symbol-value
9379                                     (intern (format "gnus-newsgroup-%s"
9380                                                     (caar marks)))))))
9381                       ;; Copy the marks to other group.
9382                       (gnus-add-marked-articles
9383                        to-group (cdar marks) (list to-article) info)))
9384                   (setq marks (cdr marks)))
9385
9386                 (gnus-request-set-mark
9387                  to-group (list (list (list to-article) 'add to-marks))))
9388
9389               (gnus-dribble-enter
9390                (concat "(gnus-group-set-info '"
9391                        (gnus-prin1-to-string (gnus-get-info to-group))
9392                        ")"))))
9393
9394           ;; Update the Xref header in this article to point to
9395           ;; the new crossposted article we have just created.
9396           (when (eq action 'crosspost)
9397             (save-excursion
9398               (set-buffer copy-buf)
9399               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9400               (nnheader-replace-header "Xref" new-xref)
9401               (gnus-request-replace-article
9402                article gnus-newsgroup-name (current-buffer))))
9403
9404           ;; run the move/copy/crosspost/respool hook
9405           (run-hook-with-args 'gnus-summary-article-move-hook
9406                               action
9407                               (gnus-data-header
9408                                (assoc article (gnus-data-list nil)))
9409                               gnus-newsgroup-name
9410                               to-newsgroup
9411                               select-method))
9412
9413         ;;;!!!Why is this necessary?
9414         (set-buffer gnus-summary-buffer)
9415         
9416         (gnus-summary-goto-subject article)
9417         (when (eq action 'move)
9418           (gnus-summary-mark-article article gnus-canceled-mark))))
9419       (push article articles-to-update-marks))
9420
9421     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9422     ;; Re-activate all groups that have been moved to.
9423     (save-excursion
9424       (set-buffer gnus-group-buffer)
9425       (let ((gnus-group-marked to-groups))
9426         (gnus-group-get-new-news-this-group nil t)))
9427     
9428     (gnus-kill-buffer copy-buf)
9429     (gnus-summary-position-point)
9430     (gnus-set-mode-line 'summary)))
9431
9432 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9433   "Copy the current article to some other group.
9434 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9435 When called interactively, if TO-NEWSGROUP is nil, use the value of
9436 the variable `gnus-move-split-methods' for finding a default target
9437 newsgroup.
9438 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9439 re-spool using this method."
9440   (interactive "P")
9441   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9442
9443 (defun gnus-summary-crosspost-article (&optional n)
9444   "Crosspost the current article to some other group."
9445   (interactive "P")
9446   (gnus-summary-move-article n nil nil 'crosspost))
9447
9448 (defcustom gnus-summary-respool-default-method nil
9449   "Default method type for respooling an article.
9450 If nil, use to the current newsgroup method."
9451   :type 'symbol
9452   :group 'gnus-summary-mail)
9453
9454 (defcustom gnus-summary-display-while-building nil
9455   "If non-nil, show and update the summary buffer as it's being built.
9456 If the value is t, update the buffer after every line is inserted.  If
9457 the value is an integer (N), update the display every N lines."
9458   :version "22.1"
9459   :group 'gnus-thread
9460   :type '(choice (const :tag "off" nil)
9461                  number
9462                  (const :tag "frequently" t)))
9463
9464 (defun gnus-summary-respool-article (&optional n method)
9465   "Respool the current article.
9466 The article will be squeezed through the mail spooling process again,
9467 which means that it will be put in some mail newsgroup or other
9468 depending on `nnmail-split-methods'.
9469 If N is a positive number, respool the N next articles.
9470 If N is a negative number, respool the N previous articles.
9471 If N is nil and any articles have been marked with the process mark,
9472 respool those articles instead.
9473
9474 Respooling can be done both from mail groups and \"real\" newsgroups.
9475 In the former case, the articles in question will be moved from the
9476 current group into whatever groups they are destined to.  In the
9477 latter case, they will be copied into the relevant groups."
9478   (interactive
9479    (list current-prefix-arg
9480          (let* ((methods (gnus-methods-using 'respool))
9481                 (methname
9482                  (symbol-name (or gnus-summary-respool-default-method
9483                                   (car (gnus-find-method-for-group
9484                                         gnus-newsgroup-name)))))
9485                 (method
9486                  (gnus-completing-read-with-default
9487                   methname "Backend to use when respooling"
9488                   methods nil t nil 'gnus-mail-method-history))
9489                 ms)
9490            (cond
9491             ((zerop (length (setq ms (gnus-servers-using-backend
9492                                       (intern method)))))
9493              (list (intern method) ""))
9494             ((= 1 (length ms))
9495              (car ms))
9496             (t
9497              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9498                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9499                            ms-alist))))))))
9500   (unless method
9501     (error "No method given for respooling"))
9502   (if (assoc (symbol-name
9503               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9504              (gnus-methods-using 'respool))
9505       (gnus-summary-move-article n nil method)
9506     (gnus-summary-copy-article n nil method)))
9507
9508 (defun gnus-summary-import-article (file &optional edit)
9509   "Import an arbitrary file into a mail newsgroup."
9510   (interactive "fImport file: \nP")
9511   (let ((group gnus-newsgroup-name)
9512         (now (current-time))
9513         atts lines group-art)
9514     (unless (gnus-check-backend-function 'request-accept-article group)
9515       (error "%s does not support article importing" group))
9516     (or (file-readable-p file)
9517         (not (file-regular-p file))
9518         (error "Can't read %s" file))
9519     (save-excursion
9520       (set-buffer (gnus-get-buffer-create " *import file*"))
9521       (erase-buffer)
9522       (nnheader-insert-file-contents file)
9523       (goto-char (point-min))
9524       (if (nnheader-article-p)
9525           (save-restriction
9526             (goto-char (point-min))
9527             (search-forward "\n\n" nil t)
9528             (narrow-to-region (point-min) (1- (point)))
9529             (goto-char (point-min))
9530             (unless (re-search-forward "^date:" nil t)
9531               (goto-char (point-max))
9532               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9533        ;; This doesn't look like an article, so we fudge some headers.
9534         (setq atts (file-attributes file)
9535               lines (count-lines (point-min) (point-max)))
9536         (insert "From: " (read-string "From: ") "\n"
9537                 "Subject: " (read-string "Subject: ") "\n"
9538                 "Date: " (message-make-date (nth 5 atts)) "\n"
9539                 "Message-ID: " (message-make-message-id) "\n"
9540                 "Lines: " (int-to-string lines) "\n"
9541                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9542       (setq group-art (gnus-request-accept-article group nil t))
9543       (kill-buffer (current-buffer)))
9544     (setq gnus-newsgroup-active (gnus-activate-group group))
9545     (forward-line 1)
9546     (gnus-summary-goto-article (cdr group-art) nil t)
9547     (when edit
9548       (gnus-summary-edit-article))))
9549
9550 (defun gnus-summary-create-article ()
9551   "Create an article in a mail newsgroup."
9552   (interactive)
9553   (let ((group gnus-newsgroup-name)
9554         (now (current-time))
9555         group-art)
9556     (unless (gnus-check-backend-function 'request-accept-article group)
9557       (error "%s does not support article importing" group))
9558     (save-excursion
9559       (set-buffer (gnus-get-buffer-create " *import file*"))
9560       (erase-buffer)
9561       (goto-char (point-min))
9562       ;; This doesn't look like an article, so we fudge some headers.
9563       (insert "From: " (read-string "From: ") "\n"
9564               "Subject: " (read-string "Subject: ") "\n"
9565               "Date: " (message-make-date now) "\n"
9566               "Message-ID: " (message-make-message-id) "\n")
9567       (setq group-art (gnus-request-accept-article group nil t))
9568       (kill-buffer (current-buffer)))
9569     (setq gnus-newsgroup-active (gnus-activate-group group))
9570     (forward-line 1)
9571     (gnus-summary-goto-article (cdr group-art) nil t)
9572     (gnus-summary-edit-article)))
9573
9574 (defun gnus-summary-article-posted-p ()
9575   "Say whether the current (mail) article is available from news as well.
9576 This will be the case if the article has both been mailed and posted."
9577   (interactive)
9578   (let ((id (mail-header-references (gnus-summary-article-header)))
9579         (gnus-override-method (car (gnus-refer-article-methods))))
9580     (if (gnus-request-head id "")
9581         (gnus-message 2 "The current message was found on %s"
9582                       gnus-override-method)
9583       (gnus-message 2 "The current message couldn't be found on %s"
9584                     gnus-override-method)
9585       nil)))
9586
9587 (defun gnus-summary-expire-articles (&optional now)
9588   "Expire all articles that are marked as expirable in the current group."
9589   (interactive)
9590   (when (and (not gnus-group-is-exiting-without-update-p)
9591              (gnus-check-backend-function
9592               'request-expire-articles gnus-newsgroup-name))
9593     ;; This backend supports expiry.
9594     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9595            (expirable (if total
9596                           (progn
9597                             ;; We need to update the info for
9598                             ;; this group for `gnus-list-of-read-articles'
9599                             ;; to give us the right answer.
9600                             (gnus-run-hooks 'gnus-exit-group-hook)
9601                             (gnus-summary-update-info)
9602                             (gnus-list-of-read-articles gnus-newsgroup-name))
9603                         (setq gnus-newsgroup-expirable
9604                               (sort gnus-newsgroup-expirable '<))))
9605            (expiry-wait (if now 'immediate
9606                           (gnus-group-find-parameter
9607                            gnus-newsgroup-name 'expiry-wait)))
9608            (nnmail-expiry-target
9609             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9610                 nnmail-expiry-target))
9611            es)
9612       (when expirable
9613         ;; There are expirable articles in this group, so we run them
9614         ;; through the expiry process.
9615         (gnus-message 6 "Expiring articles...")
9616         (unless (gnus-check-group gnus-newsgroup-name)
9617           (error "Can't open server for %s" gnus-newsgroup-name))
9618         ;; The list of articles that weren't expired is returned.
9619         (save-excursion
9620           (if expiry-wait
9621               (let ((nnmail-expiry-wait-function nil)
9622                     (nnmail-expiry-wait expiry-wait))
9623                 (setq es (gnus-request-expire-articles
9624                           expirable gnus-newsgroup-name)))
9625             (setq es (gnus-request-expire-articles
9626                       expirable gnus-newsgroup-name)))
9627           (unless total
9628             (setq gnus-newsgroup-expirable es))
9629           ;; We go through the old list of expirable, and mark all
9630           ;; really expired articles as nonexistent.
9631           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9632             (let ((gnus-use-cache nil))
9633               (dolist (article expirable)
9634                 (when (and (not (memq article es))
9635                            (gnus-data-find article))
9636                   (gnus-summary-mark-article article gnus-canceled-mark)
9637                   (run-hook-with-args 'gnus-summary-article-expire-hook
9638                                       'delete
9639                                       (gnus-data-header
9640                                        (assoc article (gnus-data-list nil)))
9641                                       gnus-newsgroup-name
9642                                       nil
9643                                       nil))))))
9644         (gnus-message 6 "Expiring articles...done")))))
9645
9646 (defun gnus-summary-expire-articles-now ()
9647   "Expunge all expirable articles in the current group.
9648 This means that *all* articles that are marked as expirable will be
9649 deleted forever, right now."
9650   (interactive)
9651   (or gnus-expert-user
9652       (gnus-yes-or-no-p
9653        "Are you really, really, really sure you want to delete all these messages? ")
9654       (error "Phew!"))
9655   (gnus-summary-expire-articles t))
9656
9657 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9658 (defun gnus-summary-delete-article (&optional n)
9659   "Delete the N next (mail) articles.
9660 This command actually deletes articles.  This is not a marking
9661 command.  The article will disappear forever from your life, never to
9662 return.
9663
9664 If N is negative, delete backwards.
9665 If N is nil and articles have been marked with the process mark,
9666 delete these instead.
9667
9668 If `gnus-novice-user' is non-nil you will be asked for
9669 confirmation before the articles are deleted."
9670   (interactive "P")
9671   (unless (gnus-check-backend-function 'request-expire-articles
9672                                        gnus-newsgroup-name)
9673     (error "The current newsgroup does not support article deletion"))
9674   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9675     (error "Couldn't open server"))
9676   ;; Compute the list of articles to delete.
9677   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9678         (nnmail-expiry-target 'delete)
9679         not-deleted)
9680     (if (and gnus-novice-user
9681              (not (gnus-yes-or-no-p
9682                    (format "Do you really want to delete %s forever? "
9683                            (if (> (length articles) 1)
9684                                (format "these %s articles" (length articles))
9685                              "this article")))))
9686         ()
9687       ;; Delete the articles.
9688       (setq not-deleted (gnus-request-expire-articles
9689                          articles gnus-newsgroup-name 'force))
9690       (while articles
9691         (gnus-summary-remove-process-mark (car articles))
9692         ;; The backend might not have been able to delete the article
9693         ;; after all.
9694         (unless (memq (car articles) not-deleted)
9695           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9696         (let* ((article (car articles))
9697                (ghead  (gnus-data-header
9698                                     (assoc article (gnus-data-list nil)))))
9699           (run-hook-with-args 'gnus-summary-article-delete-hook
9700                               'delete ghead gnus-newsgroup-name nil
9701                               nil))
9702         (setq articles (cdr articles)))
9703       (when not-deleted
9704         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9705     (gnus-summary-position-point)
9706     (gnus-set-mode-line 'summary)
9707     not-deleted))
9708
9709 (defun gnus-summary-edit-article (&optional arg)
9710   "Edit the current article.
9711 This will have permanent effect only in mail groups.
9712 If ARG is nil, edit the decoded articles.
9713 If ARG is 1, edit the raw articles.
9714 If ARG is 2, edit the raw articles even in read-only groups.
9715 If ARG is 3, edit the articles with the current handles.
9716 Otherwise, allow editing of articles even in read-only
9717 groups."
9718   (interactive "P")
9719   (let (force raw current-handles)
9720     (cond
9721      ((null arg))
9722      ((eq arg 1)
9723       (setq raw t))
9724      ((eq arg 2)
9725       (setq raw t
9726             force t))
9727      ((eq arg 3)
9728       (setq current-handles
9729             (and (gnus-buffer-live-p gnus-article-buffer)
9730                  (with-current-buffer gnus-article-buffer
9731                    (prog1
9732                        gnus-article-mime-handles
9733                      (setq gnus-article-mime-handles nil))))))
9734      (t
9735       (setq force t)))
9736     (when (and raw (not force)
9737                (member gnus-newsgroup-name '("nndraft:delayed"
9738                                              "nndraft:drafts"
9739                                              "nndraft:queue")))
9740       (error "Can't edit the raw article in group %s"
9741              gnus-newsgroup-name))
9742     (save-excursion
9743       (set-buffer gnus-summary-buffer)
9744       (let ((mail-parse-charset gnus-newsgroup-charset)
9745             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9746         (gnus-set-global-variables)
9747         (when (and (not force)
9748                    (gnus-group-read-only-p))
9749           (error "The current newsgroup does not support article editing"))
9750         (gnus-summary-show-article t)
9751         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9752           (with-current-buffer gnus-article-buffer
9753             (mm-enable-multibyte)))
9754         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9755             (setq raw t))
9756         (gnus-article-edit-article
9757          (if raw 'ignore
9758            `(lambda ()
9759               (let ((mbl mml-buffer-list))
9760                 (setq mml-buffer-list nil)
9761                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9762                   (mime-to-mml ,'current-handles))
9763                 (let ((mbl1 mml-buffer-list))
9764                   (setq mml-buffer-list mbl)
9765                   (set (make-local-variable 'mml-buffer-list) mbl1))
9766                 (gnus-make-local-hook 'kill-buffer-hook)
9767                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9768          `(lambda (no-highlight)
9769             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9770                   (message-options message-options)
9771                   (message-options-set-recipient)
9772                   (mail-parse-ignored-charsets
9773                    ',gnus-newsgroup-ignored-charsets))
9774               ,(if (not raw) '(progn
9775                                 (mml-to-mime)
9776                                 (mml-destroy-buffers)
9777                                 (remove-hook 'kill-buffer-hook
9778                                              'mml-destroy-buffers t)
9779                                 (kill-local-variable 'mml-buffer-list)))
9780               (gnus-summary-edit-article-done
9781                ,(or (mail-header-references gnus-current-headers) "")
9782                ,(gnus-group-read-only-p)
9783                ,gnus-summary-buffer no-highlight))))))))
9784
9785 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9786
9787 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9788                                                  no-highlight)
9789   "Make edits to the current article permanent."
9790   (interactive)
9791   (save-excursion
9792    ;; The buffer restriction contains the entire article if it exists.
9793     (when (article-goto-body)
9794       (let ((lines (count-lines (point) (point-max)))
9795             (length (- (point-max) (point)))
9796             (case-fold-search t)
9797             (body (copy-marker (point))))
9798         (goto-char (point-min))
9799         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9800           (delete-region (match-beginning 1) (match-end 1))
9801           (insert (number-to-string length)))
9802         (goto-char (point-min))
9803         (when (re-search-forward
9804                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9805           (delete-region (match-beginning 1) (match-end 1))
9806           (insert (number-to-string length)))
9807         (goto-char (point-min))
9808         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9809           (delete-region (match-beginning 1) (match-end 1))
9810           (insert (number-to-string lines))))))
9811   ;; Replace the article.
9812   (let ((buf (current-buffer)))
9813     (with-temp-buffer
9814       (insert-buffer-substring buf)
9815
9816       (if (and (not read-only)
9817                (not (gnus-request-replace-article
9818                      (cdr gnus-article-current) (car gnus-article-current)
9819                      (current-buffer) t)))
9820           (error "Couldn't replace article")
9821         ;; Update the summary buffer.
9822         (if (and references
9823                  (equal (message-tokenize-header references " ")
9824                         (message-tokenize-header
9825                          (or (message-fetch-field "references") "") " ")))
9826             ;; We only have to update this line.
9827             (save-excursion
9828               (save-restriction
9829                 (message-narrow-to-head)
9830                 (let ((head (buffer-substring-no-properties
9831                              (point-min) (point-max)))
9832                       header)
9833                   (with-temp-buffer
9834                     (insert (format "211 %d Article retrieved.\n"
9835                                     (cdr gnus-article-current)))
9836                     (insert head)
9837                     (insert ".\n")
9838                     (let ((nntp-server-buffer (current-buffer)))
9839                       (setq header (car (gnus-get-newsgroup-headers
9840                                          nil t))))
9841                     (save-excursion
9842                       (set-buffer gnus-summary-buffer)
9843                       (gnus-data-set-header
9844                        (gnus-data-find (cdr gnus-article-current))
9845                        header)
9846                       (gnus-summary-update-article-line
9847                        (cdr gnus-article-current) header)
9848                       (if (gnus-summary-goto-subject
9849                            (cdr gnus-article-current) nil t)
9850                           (gnus-summary-update-secondary-mark
9851                            (cdr gnus-article-current))))))))
9852           ;; Update threads.
9853           (set-buffer (or buffer gnus-summary-buffer))
9854           (gnus-summary-update-article (cdr gnus-article-current))
9855           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9856               (gnus-summary-update-secondary-mark
9857                (cdr gnus-article-current))))
9858         ;; Prettify the article buffer again.
9859         (unless no-highlight
9860           (save-excursion
9861             (set-buffer gnus-article-buffer)
9862             ;;;!!! Fix this -- article should be rehighlighted.
9863             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9864             (set-buffer gnus-original-article-buffer)
9865             (gnus-request-article
9866              (cdr gnus-article-current)
9867              (car gnus-article-current) (current-buffer))))
9868         ;; Prettify the summary buffer line.
9869         (when (gnus-visual-p 'summary-highlight 'highlight)
9870           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9871
9872 (defun gnus-summary-edit-wash (key)
9873   "Perform editing command KEY in the article buffer."
9874   (interactive
9875    (list
9876     (progn
9877       (message "%s" (concat (this-command-keys) "- "))
9878       (read-char))))
9879   (message "")
9880   (gnus-summary-edit-article)
9881   (execute-kbd-macro (concat (this-command-keys) key))
9882   (gnus-article-edit-done))
9883
9884 ;;; Respooling
9885
9886 (defun gnus-summary-respool-query (&optional silent trace)
9887   "Query where the respool algorithm would put this article."
9888   (interactive)
9889   (let (gnus-mark-article-hook)
9890     (gnus-summary-select-article)
9891     (save-excursion
9892       (set-buffer gnus-original-article-buffer)
9893       (let ((groups (nnmail-article-group 'identity trace)))
9894         (unless silent
9895           (if groups
9896               (message "This message would go to %s"
9897                        (mapconcat 'car groups ", "))
9898             (message "This message would go to no groups"))
9899           groups)))))
9900
9901 (defun gnus-summary-respool-trace ()
9902   "Trace where the respool algorithm would put this article.
9903 Display a buffer showing all fancy splitting patterns which matched."
9904   (interactive)
9905   (gnus-summary-respool-query nil t))
9906
9907 ;; Summary marking commands.
9908
9909 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9910   "Mark articles which has the same subject as read, and then select the next.
9911 If UNMARK is positive, remove any kind of mark.
9912 If UNMARK is negative, tick articles."
9913   (interactive "P")
9914   (when unmark
9915     (setq unmark (prefix-numeric-value unmark)))
9916   (let ((count
9917          (gnus-summary-mark-same-subject
9918           (gnus-summary-article-subject) unmark)))
9919     ;; Select next unread article.  If auto-select-same mode, should
9920     ;; select the first unread article.
9921     (gnus-summary-next-article t (and gnus-auto-select-same
9922                                       (gnus-summary-article-subject)))
9923     (gnus-message 7 "%d article%s marked as %s"
9924                   count (if (= count 1) " is" "s are")
9925                   (if unmark "unread" "read"))))
9926
9927 (defun gnus-summary-kill-same-subject (&optional unmark)
9928   "Mark articles which has the same subject as read.
9929 If UNMARK is positive, remove any kind of mark.
9930 If UNMARK is negative, tick articles."
9931   (interactive "P")
9932   (when unmark
9933     (setq unmark (prefix-numeric-value unmark)))
9934   (let ((count
9935          (gnus-summary-mark-same-subject
9936           (gnus-summary-article-subject) unmark)))
9937     ;; If marked as read, go to next unread subject.
9938     (when (null unmark)
9939       ;; Go to next unread subject.
9940       (gnus-summary-next-subject 1 t))
9941     (gnus-message 7 "%d articles are marked as %s"
9942                   count (if unmark "unread" "read"))))
9943
9944 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9945   "Mark articles with same SUBJECT as read, and return marked number.
9946 If optional argument UNMARK is positive, remove any kinds of marks.
9947 If optional argument UNMARK is negative, mark articles as unread instead."
9948   (let ((count 1))
9949     (save-excursion
9950       (cond
9951        ((null unmark)                   ; Mark as read.
9952         (while (and
9953                 (progn
9954                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9955                   (gnus-summary-show-thread) t)
9956                 (gnus-summary-find-subject subject))
9957           (setq count (1+ count))))
9958        ((> unmark 0)                    ; Tick.
9959         (while (and
9960                 (progn
9961                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9962                   (gnus-summary-show-thread) t)
9963                 (gnus-summary-find-subject subject))
9964           (setq count (1+ count))))
9965        (t                               ; Mark as unread.
9966         (while (and
9967                 (progn
9968                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9969                   (gnus-summary-show-thread) t)
9970                 (gnus-summary-find-subject subject))
9971           (setq count (1+ count)))))
9972       (gnus-set-mode-line 'summary)
9973       ;; Return the number of marked articles.
9974       count)))
9975
9976 (defun gnus-summary-mark-as-processable (n &optional unmark)
9977   "Set the process mark on the next N articles.
9978 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9979 the process mark instead.  The difference between N and the actual
9980 number of articles marked is returned."
9981   (interactive "P")
9982   (if (and (null n) (gnus-region-active-p))
9983       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9984     (setq n (prefix-numeric-value n))
9985     (let ((backward (< n 0))
9986           (n (abs n)))
9987       (while (and
9988               (> n 0)
9989               (if unmark
9990                   (gnus-summary-remove-process-mark
9991                    (gnus-summary-article-number))
9992                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9993               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9994         (setq n (1- n)))
9995       (when (/= 0 n)
9996         (gnus-message 7 "No more articles"))
9997       (gnus-summary-recenter)
9998       (gnus-summary-position-point)
9999       n)))
10000
10001 (defun gnus-summary-unmark-as-processable (n)
10002   "Remove the process mark from the next N articles.
10003 If N is negative, unmark backward instead.  The difference between N and
10004 the actual number of articles unmarked is returned."
10005   (interactive "P")
10006   (gnus-summary-mark-as-processable n t))
10007
10008 (defun gnus-summary-unmark-all-processable ()
10009   "Remove the process mark from all articles."
10010   (interactive)
10011   (save-excursion
10012     (while gnus-newsgroup-processable
10013       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10014   (gnus-summary-position-point))
10015
10016 (defun gnus-summary-add-mark (article type)
10017   "Mark ARTICLE with a mark of TYPE."
10018   (let ((vtype (car (assq type gnus-article-mark-lists)))
10019         var)
10020     (if (not vtype)
10021         (error "No such mark type: %s" type)
10022       (setq var (intern (format "gnus-newsgroup-%s" type)))
10023       (set var (cons article (symbol-value var)))
10024       (if (memq type '(processable cached replied forwarded recent saved))
10025           (gnus-summary-update-secondary-mark article)
10026         ;;; !!! This is bogus.  We should find out what primary
10027         ;;; !!! mark we want to set.
10028         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10029
10030 (defun gnus-summary-mark-as-expirable (n)
10031   "Mark N articles forward as expirable.
10032 If N is negative, mark backward instead.  The difference between N and
10033 the actual number of articles marked is returned."
10034   (interactive "p")
10035   (gnus-summary-mark-forward n gnus-expirable-mark))
10036
10037 (defun gnus-summary-mark-as-spam (n)
10038   "Mark N articles forward as spam.
10039 If N is negative, mark backward instead.  The difference between N and
10040 the actual number of articles marked is returned."
10041   (interactive "p")
10042   (gnus-summary-mark-forward n gnus-spam-mark))
10043
10044 (defun gnus-summary-mark-article-as-replied (article)
10045   "Mark ARTICLE as replied to and update the summary line.
10046 ARTICLE can also be a list of articles."
10047   (interactive (list (gnus-summary-article-number)))
10048   (let ((articles (if (listp article) article (list article))))
10049     (dolist (article articles)
10050       (unless (numberp article)
10051         (error "%s is not a number" article))
10052       (push article gnus-newsgroup-replied)
10053       (let ((buffer-read-only nil))
10054         (when (gnus-summary-goto-subject article nil t)
10055           (gnus-summary-update-secondary-mark article))))))
10056
10057 (defun gnus-summary-mark-article-as-forwarded (article)
10058   "Mark ARTICLE as forwarded and update the summary line.
10059 ARTICLE can also be a list of articles."
10060   (let ((articles (if (listp article) article (list article))))
10061     (dolist (article articles)
10062       (push article gnus-newsgroup-forwarded)
10063       (let ((buffer-read-only nil))
10064         (when (gnus-summary-goto-subject article nil t)
10065           (gnus-summary-update-secondary-mark article))))))
10066
10067 (defun gnus-summary-set-bookmark (article)
10068   "Set a bookmark in current article."
10069   (interactive (list (gnus-summary-article-number)))
10070   (when (or (not (get-buffer gnus-article-buffer))
10071             (not gnus-current-article)
10072             (not gnus-article-current)
10073             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10074     (error "No current article selected"))
10075   ;; Remove old bookmark, if one exists.
10076   (gnus-pull article gnus-newsgroup-bookmarks)
10077   ;; Set the new bookmark, which is on the form
10078   ;; (article-number . line-number-in-body).
10079   (push
10080    (cons article
10081          (with-current-buffer gnus-article-buffer
10082            (count-lines
10083             (min (point)
10084                  (save-excursion
10085                    (article-goto-body)
10086                    (point)))
10087             (point))))
10088    gnus-newsgroup-bookmarks)
10089   (gnus-message 6 "A bookmark has been added to the current article."))
10090
10091 (defun gnus-summary-remove-bookmark (article)
10092   "Remove the bookmark from the current article."
10093   (interactive (list (gnus-summary-article-number)))
10094   ;; Remove old bookmark, if one exists.
10095   (if (not (assq article gnus-newsgroup-bookmarks))
10096       (gnus-message 6 "No bookmark in current article.")
10097     (gnus-pull article gnus-newsgroup-bookmarks)
10098     (gnus-message 6 "Removed bookmark.")))
10099
10100 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10101 (defun gnus-summary-mark-as-dormant (n)
10102   "Mark N articles forward as dormant.
10103 If N is negative, mark backward instead.  The difference between N and
10104 the actual number of articles marked is returned."
10105   (interactive "p")
10106   (gnus-summary-mark-forward n gnus-dormant-mark))
10107
10108 (defun gnus-summary-set-process-mark (article)
10109   "Set the process mark on ARTICLE and update the summary line."
10110   (setq gnus-newsgroup-processable
10111         (cons article
10112               (delq article gnus-newsgroup-processable)))
10113   (when (gnus-summary-goto-subject article)
10114     (gnus-summary-show-thread)
10115     (gnus-summary-goto-subject article)
10116     (gnus-summary-update-secondary-mark article)))
10117
10118 (defun gnus-summary-remove-process-mark (&rest articles)
10119   "Remove the process mark from ARTICLES and update the summary line."
10120   (dolist (article articles)
10121     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10122     (when (gnus-summary-goto-subject article)
10123       (gnus-summary-show-thread)
10124       (gnus-summary-goto-subject article)
10125       (gnus-summary-update-secondary-mark article)))
10126   t)
10127
10128 (defun gnus-summary-set-saved-mark (article)
10129   "Set the process mark on ARTICLE and update the summary line."
10130   (push article gnus-newsgroup-saved)
10131   (when (gnus-summary-goto-subject article)
10132     (gnus-summary-update-secondary-mark article)))
10133
10134 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10135   "Mark N articles as read forwards.
10136 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10137 The difference between N and the actual number of articles marked is
10138 returned.
10139 If NO-EXPIRE, auto-expiry will be inhibited."
10140   (interactive "p")
10141   (gnus-summary-show-thread)
10142   (let ((backward (< n 0))
10143         (gnus-summary-goto-unread
10144          (and gnus-summary-goto-unread
10145               (not (eq gnus-summary-goto-unread 'never))
10146               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10147                                     gnus-ticked-mark gnus-dormant-mark)))))
10148         (n (abs n))
10149         (mark (or mark gnus-del-mark)))
10150     (while (and (> n 0)
10151                 (gnus-summary-mark-article nil mark no-expire)
10152                 (zerop (gnus-summary-next-subject
10153                         (if backward -1 1)
10154                         (and gnus-summary-goto-unread
10155                              (not (eq gnus-summary-goto-unread 'never)))
10156                         t)))
10157       (setq n (1- n)))
10158     (when (/= 0 n)
10159       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10160     (gnus-summary-recenter)
10161     (gnus-summary-position-point)
10162     (gnus-set-mode-line 'summary)
10163     n))
10164
10165 (defun gnus-summary-mark-article-as-read (mark)
10166   "Mark the current article quickly as read with MARK."
10167   (let ((article (gnus-summary-article-number)))
10168     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10169     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10170     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10171     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10172     (push (cons article mark) gnus-newsgroup-reads)
10173     ;; Possibly remove from cache, if that is used.
10174     (when gnus-use-cache
10175       (gnus-cache-enter-remove-article article))
10176     ;; Allow the backend to change the mark.
10177     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10178     ;; Check for auto-expiry.
10179     (when (and gnus-newsgroup-auto-expire
10180                (memq mark gnus-auto-expirable-marks))
10181       (setq mark gnus-expirable-mark)
10182       ;; Let the backend know about the mark change.
10183       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10184       (push article gnus-newsgroup-expirable))
10185     ;; Set the mark in the buffer.
10186     (gnus-summary-update-mark mark 'unread)
10187     t))
10188
10189 (defun gnus-summary-mark-article-as-unread (mark)
10190   "Mark the current article quickly as unread with MARK."
10191   (let* ((article (gnus-summary-article-number))
10192          (old-mark (gnus-summary-article-mark article)))
10193     ;; Allow the backend to change the mark.
10194     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10195     (if (eq mark old-mark)
10196         t
10197       (if (<= article 0)
10198           (progn
10199             (gnus-error 1 "Can't mark negative article numbers")
10200             nil)
10201         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10202         (setq gnus-newsgroup-spam-marked
10203               (delq article gnus-newsgroup-spam-marked))
10204         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10205         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10206         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10207         (cond ((= mark gnus-ticked-mark)
10208                (setq gnus-newsgroup-marked
10209                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10210                                               article)))
10211               ((= mark gnus-spam-mark)
10212                (setq gnus-newsgroup-spam-marked
10213                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10214                                               article)))
10215               ((= mark gnus-dormant-mark)
10216                (setq gnus-newsgroup-dormant
10217                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10218                                               article)))
10219               (t
10220                (setq gnus-newsgroup-unreads
10221                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10222                                               article))))
10223         (gnus-pull article gnus-newsgroup-reads)
10224
10225         ;; See whether the article is to be put in the cache.
10226         (and gnus-use-cache
10227              (vectorp (gnus-summary-article-header article))
10228              (save-excursion
10229                (gnus-cache-possibly-enter-article
10230                 gnus-newsgroup-name article
10231                 (= mark gnus-ticked-mark)
10232                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10233
10234         ;; Fix the mark.
10235         (gnus-summary-update-mark mark 'unread)
10236         t))))
10237
10238 (defun gnus-summary-mark-article (&optional article mark no-expire)
10239   "Mark ARTICLE with MARK.  MARK can be any character.
10240 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10241 `??' (dormant) and `?E' (expirable).
10242 If MARK is nil, then the default character `?r' is used.
10243 If ARTICLE is nil, then the article on the current line will be
10244 marked.
10245 If NO-EXPIRE, auto-expiry will be inhibited."
10246   ;; The mark might be a string.
10247   (when (stringp mark)
10248     (setq mark (aref mark 0)))
10249   ;; If no mark is given, then we check auto-expiring.
10250   (when (null mark)
10251     (setq mark gnus-del-mark))
10252   (when (and (not no-expire)
10253              gnus-newsgroup-auto-expire
10254              (memq mark gnus-auto-expirable-marks))
10255     (setq mark gnus-expirable-mark))
10256   (let ((article (or article (gnus-summary-article-number)))
10257         (old-mark (gnus-summary-article-mark article)))
10258     ;; Allow the backend to change the mark.
10259     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10260     (if (eq mark old-mark)
10261         t
10262       (unless article
10263         (error "No article on current line"))
10264       (if (not (if (or (= mark gnus-unread-mark)
10265                        (= mark gnus-ticked-mark)
10266                        (= mark gnus-spam-mark)
10267                        (= mark gnus-dormant-mark))
10268                    (gnus-mark-article-as-unread article mark)
10269                  (gnus-mark-article-as-read article mark)))
10270           t
10271         ;; See whether the article is to be put in the cache.
10272         (and gnus-use-cache
10273              (not (= mark gnus-canceled-mark))
10274              (vectorp (gnus-summary-article-header article))
10275              (save-excursion
10276                (gnus-cache-possibly-enter-article
10277                 gnus-newsgroup-name article
10278                 (= mark gnus-ticked-mark)
10279                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10280
10281         (when (gnus-summary-goto-subject article nil t)
10282           (let ((buffer-read-only nil))
10283             (gnus-summary-show-thread)
10284             ;; Fix the mark.
10285             (gnus-summary-update-mark mark 'unread)
10286             t))))))
10287
10288 (defun gnus-summary-update-secondary-mark (article)
10289   "Update the secondary (read, process, cache) mark."
10290   (gnus-summary-update-mark
10291    (cond ((memq article gnus-newsgroup-processable)
10292           gnus-process-mark)
10293          ((memq article gnus-newsgroup-cached)
10294           gnus-cached-mark)
10295          ((memq article gnus-newsgroup-replied)
10296           gnus-replied-mark)
10297          ((memq article gnus-newsgroup-forwarded)
10298           gnus-forwarded-mark)
10299          ((memq article gnus-newsgroup-saved)
10300           gnus-saved-mark)
10301          ((memq article gnus-newsgroup-recent)
10302           gnus-recent-mark)
10303          ((memq article gnus-newsgroup-unseen)
10304           gnus-unseen-mark)
10305          (t gnus-no-mark))
10306    'replied)
10307   (when (gnus-visual-p 'summary-highlight 'highlight)
10308     (gnus-run-hooks 'gnus-summary-update-hook))
10309   t)
10310
10311 (defun gnus-summary-update-download-mark (article)
10312   "Update the download mark."
10313   (gnus-summary-update-mark
10314    (cond ((memq article gnus-newsgroup-undownloaded)
10315           gnus-undownloaded-mark)
10316          (gnus-newsgroup-agentized
10317           gnus-downloaded-mark)
10318          (t
10319           gnus-no-mark))
10320    'download)
10321   (gnus-summary-update-line t)
10322   t)
10323
10324 (defun gnus-summary-update-mark (mark type)
10325   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10326         (buffer-read-only nil))
10327     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10328     (when forward
10329       (when (looking-at "\r")
10330         (incf forward))
10331       (when (<= (+ forward (point)) (point-max))
10332         ;; Go to the right position on the line.
10333         (goto-char (+ forward (point)))
10334         ;; Replace the old mark with the new mark.
10335         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10336         ;; Optionally update the marks by some user rule.
10337         (when (eq type 'unread)
10338           (gnus-data-set-mark
10339            (gnus-data-find (gnus-summary-article-number)) mark)
10340           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10341
10342 (defun gnus-mark-article-as-read (article &optional mark)
10343   "Enter ARTICLE in the pertinent lists and remove it from others."
10344   ;; Make the article expirable.
10345   (let ((mark (or mark gnus-del-mark)))
10346     (setq gnus-newsgroup-expirable
10347           (if (= mark gnus-expirable-mark)
10348               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10349             (delq article gnus-newsgroup-expirable)))
10350     ;; Remove from unread and marked lists.
10351     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10352     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10353     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10354     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10355     (push (cons article mark) gnus-newsgroup-reads)
10356     ;; Possibly remove from cache, if that is used.
10357     (when gnus-use-cache
10358       (gnus-cache-enter-remove-article article))
10359     t))
10360
10361 (defun gnus-mark-article-as-unread (article &optional mark)
10362   "Enter ARTICLE in the pertinent lists and remove it from others."
10363   (let ((mark (or mark gnus-ticked-mark)))
10364     (if (<= article 0)
10365         (progn
10366           (gnus-error 1 "Can't mark negative article numbers")
10367           nil)
10368       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10369             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10370             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10371             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10372             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10373
10374       ;; Unsuppress duplicates?
10375       (when gnus-suppress-duplicates
10376         (gnus-dup-unsuppress-article article))
10377
10378       (cond ((= mark gnus-ticked-mark)
10379              (setq gnus-newsgroup-marked
10380                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10381             ((= mark gnus-spam-mark)
10382              (setq gnus-newsgroup-spam-marked
10383                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10384                                             article)))
10385             ((= mark gnus-dormant-mark)
10386              (setq gnus-newsgroup-dormant
10387                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10388             (t
10389              (setq gnus-newsgroup-unreads
10390                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10391       (gnus-pull article gnus-newsgroup-reads)
10392       t)))
10393
10394 (defalias 'gnus-summary-mark-as-unread-forward
10395   'gnus-summary-tick-article-forward)
10396 (make-obsolete 'gnus-summary-mark-as-unread-forward
10397                'gnus-summary-tick-article-forward)
10398 (defun gnus-summary-tick-article-forward (n)
10399   "Tick N articles forwards.
10400 If N is negative, tick backwards instead.
10401 The difference between N and the number of articles ticked is returned."
10402   (interactive "p")
10403   (gnus-summary-mark-forward n gnus-ticked-mark))
10404
10405 (defalias 'gnus-summary-mark-as-unread-backward
10406   'gnus-summary-tick-article-backward)
10407 (make-obsolete 'gnus-summary-mark-as-unread-backward
10408                'gnus-summary-tick-article-backward)
10409 (defun gnus-summary-tick-article-backward (n)
10410   "Tick N articles backwards.
10411 The difference between N and the number of articles ticked is returned."
10412   (interactive "p")
10413   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10414
10415 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10416 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10417 (defun gnus-summary-tick-article (&optional article clear-mark)
10418   "Mark current article as unread.
10419 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10420 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10421   (interactive)
10422   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10423                                        gnus-ticked-mark)))
10424
10425 (defun gnus-summary-mark-as-read-forward (n)
10426   "Mark N articles as read forwards.
10427 If N is negative, mark backwards instead.
10428 The difference between N and the actual number of articles marked is
10429 returned."
10430   (interactive "p")
10431   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10432
10433 (defun gnus-summary-mark-as-read-backward (n)
10434   "Mark the N articles as read backwards.
10435 The difference between N and the actual number of articles marked is
10436 returned."
10437   (interactive "p")
10438   (gnus-summary-mark-forward
10439    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10440
10441 (defun gnus-summary-mark-as-read (&optional article mark)
10442   "Mark current article as read.
10443 ARTICLE specifies the article to be marked as read.
10444 MARK specifies a string to be inserted at the beginning of the line."
10445   (gnus-summary-mark-article article mark))
10446
10447 (defun gnus-summary-clear-mark-forward (n)
10448   "Clear marks from N articles forward.
10449 If N is negative, clear backward instead.
10450 The difference between N and the number of marks cleared is returned."
10451   (interactive "p")
10452   (gnus-summary-mark-forward n gnus-unread-mark))
10453
10454 (defun gnus-summary-clear-mark-backward (n)
10455   "Clear marks from N articles backward.
10456 The difference between N and the number of marks cleared is returned."
10457   (interactive "p")
10458   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10459
10460 (defun gnus-summary-mark-unread-as-read ()
10461   "Intended to be used by `gnus-summary-mark-article-hook'."
10462   (when (memq gnus-current-article gnus-newsgroup-unreads)
10463     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10464
10465 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10466   "Intended to be used by `gnus-summary-mark-article-hook'."
10467   (let ((mark (gnus-summary-article-mark)))
10468     (when (or (gnus-unread-mark-p mark)
10469               (gnus-read-mark-p mark))
10470       (gnus-summary-mark-article gnus-current-article
10471                                  (or new-mark gnus-read-mark)))))
10472
10473 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10474   "Intended to be used by `gnus-summary-mark-article-hook'."
10475   (let ((mark (gnus-summary-article-mark)))
10476     (when (or (gnus-unread-mark-p mark)
10477               (gnus-read-mark-p mark))
10478       (gnus-summary-mark-article (gnus-summary-article-number)
10479                                  (or new-mark gnus-read-mark)))))
10480
10481 (defun gnus-summary-mark-unread-as-ticked ()
10482   "Intended to be used by `gnus-summary-mark-article-hook'."
10483   (when (memq gnus-current-article gnus-newsgroup-unreads)
10484     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10485
10486 (defun gnus-summary-mark-region-as-read (point mark all)
10487   "Mark all unread articles between point and mark as read.
10488 If given a prefix, mark all articles between point and mark as read,
10489 even ticked and dormant ones."
10490   (interactive "r\nP")
10491   (save-excursion
10492     (let (article)
10493       (goto-char point)
10494       (beginning-of-line)
10495       (while (and
10496               (< (point) mark)
10497               (progn
10498                 (when (or all
10499                           (memq (setq article (gnus-summary-article-number))
10500                                 gnus-newsgroup-unreads))
10501                   (gnus-summary-mark-article article gnus-del-mark))
10502                 t)
10503               (gnus-summary-find-next))))))
10504
10505 (defun gnus-summary-mark-below (score mark)
10506   "Mark articles with score less than SCORE with MARK."
10507   (interactive "P\ncMark: ")
10508   (setq score (if score
10509                   (prefix-numeric-value score)
10510                 (or gnus-summary-default-score 0)))
10511   (save-excursion
10512     (set-buffer gnus-summary-buffer)
10513     (goto-char (point-min))
10514     (while
10515         (progn
10516           (and (< (gnus-summary-article-score) score)
10517                (gnus-summary-mark-article nil mark))
10518           (gnus-summary-find-next)))))
10519
10520 (defun gnus-summary-kill-below (&optional score)
10521   "Mark articles with score below SCORE as read."
10522   (interactive "P")
10523   (gnus-summary-mark-below score gnus-killed-mark))
10524
10525 (defun gnus-summary-clear-above (&optional score)
10526   "Clear all marks from articles with score above SCORE."
10527   (interactive "P")
10528   (gnus-summary-mark-above score gnus-unread-mark))
10529
10530 (defun gnus-summary-tick-above (&optional score)
10531   "Tick all articles with score above SCORE."
10532   (interactive "P")
10533   (gnus-summary-mark-above score gnus-ticked-mark))
10534
10535 (defun gnus-summary-mark-above (score mark)
10536   "Mark articles with score over SCORE with MARK."
10537   (interactive "P\ncMark: ")
10538   (setq score (if score
10539                   (prefix-numeric-value score)
10540                 (or gnus-summary-default-score 0)))
10541   (save-excursion
10542     (set-buffer gnus-summary-buffer)
10543     (goto-char (point-min))
10544     (while (and (progn
10545                   (when (> (gnus-summary-article-score) score)
10546                     (gnus-summary-mark-article nil mark))
10547                   t)
10548                 (gnus-summary-find-next)))))
10549
10550 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10551 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10552 (defun gnus-summary-limit-include-expunged (&optional no-error)
10553   "Display all the hidden articles that were expunged for low scores."
10554   (interactive)
10555   (let ((buffer-read-only nil))
10556     (let ((scored gnus-newsgroup-scored)
10557           headers h)
10558       (while scored
10559         (unless (gnus-summary-article-header (caar scored))
10560           (and (setq h (gnus-number-to-header (caar scored)))
10561                (< (cdar scored) gnus-summary-expunge-below)
10562                (push h headers)))
10563         (setq scored (cdr scored)))
10564       (if (not headers)
10565           (when (not no-error)
10566             (error "No expunged articles hidden"))
10567         (goto-char (point-min))
10568         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10569         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10570         (mapcar (lambda (x) (push (mail-header-number x)
10571                                   gnus-newsgroup-limit))
10572                 headers)
10573         (gnus-summary-prepare-unthreaded (nreverse headers))
10574         (goto-char (point-min))
10575         (gnus-summary-position-point)
10576         t))))
10577
10578 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10579   "Mark all unread articles in this newsgroup as read.
10580 If prefix argument ALL is non-nil, ticked and dormant articles will
10581 also be marked as read.
10582 If QUIETLY is non-nil, no questions will be asked.
10583
10584 If TO-HERE is non-nil, it should be a point in the buffer.  All
10585 articles before (after, if REVERSE is set) this point will be marked
10586 as read.
10587
10588 Note that this function will only catch up the unread article
10589 in the current summary buffer limitation.
10590
10591 The number of articles marked as read is returned."
10592   (interactive "P")
10593   (prog1
10594       (save-excursion
10595         (when (or quietly
10596                   (not gnus-interactive-catchup) ;Without confirmation?
10597                   gnus-expert-user
10598                   (gnus-y-or-n-p
10599                    (if all
10600                        "Mark absolutely all articles as read? "
10601                      "Mark all unread articles as read? ")))
10602           (if (and not-mark
10603                    (not gnus-newsgroup-adaptive)
10604                    (not gnus-newsgroup-auto-expire)
10605                    (not gnus-suppress-duplicates)
10606                    (or (not gnus-use-cache)
10607                        (eq gnus-use-cache 'passive)))
10608               (progn
10609                 (when all
10610                   (setq gnus-newsgroup-marked nil
10611                         gnus-newsgroup-spam-marked nil
10612                         gnus-newsgroup-dormant nil))
10613                 (setq gnus-newsgroup-unreads
10614                       (gnus-sorted-nunion
10615                        (gnus-intersection gnus-newsgroup-unreads
10616                                           gnus-newsgroup-downloadable)
10617                        gnus-newsgroup-unfetched)))
10618             ;; We actually mark all articles as canceled, which we
10619             ;; have to do when using auto-expiry or adaptive scoring.
10620             (gnus-summary-show-all-threads)
10621             (if (and to-here reverse)
10622                 (progn
10623                   (goto-char to-here)
10624                   (gnus-summary-mark-current-read-and-unread-as-read
10625                    gnus-catchup-mark)
10626                   (while (gnus-summary-find-next (not all))
10627                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10628               (when (gnus-summary-first-subject (not all))
10629                 (while (and
10630                         (if to-here (< (point) to-here) t)
10631                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10632                         (gnus-summary-find-next (not all))))))
10633             (gnus-set-mode-line 'summary))
10634           t))
10635     (gnus-summary-position-point)))
10636
10637 (defun gnus-summary-catchup-to-here (&optional all)
10638   "Mark all unticked articles before the current one as read.
10639 If ALL is non-nil, also mark ticked and dormant articles as read."
10640   (interactive "P")
10641   (save-excursion
10642     (gnus-save-hidden-threads
10643       (let ((beg (point)))
10644         ;; We check that there are unread articles.
10645         (when (or all (gnus-summary-find-prev))
10646           (gnus-summary-catchup all t beg)))))
10647   (gnus-summary-position-point))
10648
10649 (defun gnus-summary-catchup-from-here (&optional all)
10650   "Mark all unticked articles after (and including) the current one as read.
10651 If ALL is non-nil, also mark ticked and dormant articles as read."
10652   (interactive "P")
10653   (save-excursion
10654     (gnus-save-hidden-threads
10655       (let ((beg (point)))
10656         ;; We check that there are unread articles.
10657         (when (or all (gnus-summary-find-next))
10658           (gnus-summary-catchup all t beg nil t)))))
10659   (gnus-summary-position-point))
10660
10661 (defun gnus-summary-catchup-all (&optional quietly)
10662   "Mark all articles in this newsgroup as read.
10663 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10664 instead, which marks only unread articles as read."
10665   (interactive "P")
10666   (gnus-summary-catchup t quietly))
10667
10668 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10669   "Mark all unread articles in this group as read, then exit.
10670 If prefix argument ALL is non-nil, all articles are marked as read.
10671 If QUIETLY is non-nil, no questions will be asked."
10672   (interactive "P")
10673   (when (gnus-summary-catchup all quietly nil 'fast)
10674     ;; Select next newsgroup or exit.
10675     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10676              (eq gnus-auto-select-next 'quietly))
10677         (gnus-summary-next-group nil)
10678       (gnus-summary-exit))))
10679
10680 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10681   "Mark all articles in this newsgroup as read, and then exit.
10682 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10683 instead, which marks only unread articles as read."
10684   (interactive "P")
10685   (gnus-summary-catchup-and-exit t quietly))
10686
10687 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10688   "Mark all articles in this group as read and select the next group.
10689 If given a prefix, mark all articles, unread as well as ticked, as
10690 read."
10691   (interactive "P")
10692   (save-excursion
10693     (gnus-summary-catchup all))
10694   (gnus-summary-next-group))
10695
10696 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10697   "Mark all articles in this group as read and select the previous group.
10698 If given a prefix, mark all articles, unread as well as ticked, as
10699 read."
10700   (interactive "P")
10701   (save-excursion
10702     (gnus-summary-catchup all))
10703   (gnus-summary-next-group nil nil t))
10704
10705 ;;;
10706 ;;; with article
10707 ;;;
10708
10709 (defmacro gnus-with-article (article &rest forms)
10710   "Select ARTICLE and perform FORMS in the original article buffer.
10711 Then replace the article with the result."
10712   `(progn
10713      ;; We don't want the article to be marked as read.
10714      (let (gnus-mark-article-hook)
10715        (gnus-summary-select-article t t nil ,article))
10716      (set-buffer gnus-original-article-buffer)
10717      ,@forms
10718      (if (not (gnus-check-backend-function
10719                'request-replace-article (car gnus-article-current)))
10720          (gnus-message 5 "Read-only group; not replacing")
10721        (unless (gnus-request-replace-article
10722                 ,article (car gnus-article-current)
10723                 (current-buffer) t)
10724          (error "Couldn't replace article")))
10725      ;; The cache and backlog have to be flushed somewhat.
10726      (when gnus-keep-backlog
10727        (gnus-backlog-remove-article
10728         (car gnus-article-current) (cdr gnus-article-current)))
10729      (when gnus-use-cache
10730        (gnus-cache-update-article
10731         (car gnus-article-current) (cdr gnus-article-current)))))
10732
10733 (put 'gnus-with-article 'lisp-indent-function 1)
10734 (put 'gnus-with-article 'edebug-form-spec '(form body))
10735
10736 ;; Thread-based commands.
10737
10738 (defun gnus-summary-articles-in-thread (&optional article)
10739   "Return a list of all articles in the current thread.
10740 If ARTICLE is non-nil, return all articles in the thread that starts
10741 with that article."
10742   (let* ((article (or article (gnus-summary-article-number)))
10743          (data (gnus-data-find-list article))
10744          (top-level (gnus-data-level (car data)))
10745          (top-subject
10746           (cond ((null gnus-thread-operation-ignore-subject)
10747                  (gnus-simplify-subject-re
10748                   (mail-header-subject (gnus-data-header (car data)))))
10749                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10750                  (gnus-simplify-subject-fuzzy
10751                   (mail-header-subject (gnus-data-header (car data)))))
10752                 (t nil)))
10753          (end-point (save-excursion
10754                       (if (gnus-summary-go-to-next-thread)
10755                           (point) (point-max))))
10756          articles)
10757     (while (and data
10758                 (< (gnus-data-pos (car data)) end-point))
10759       (when (or (not top-subject)
10760                 (string= top-subject
10761                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10762                              (gnus-simplify-subject-fuzzy
10763                               (mail-header-subject
10764                                (gnus-data-header (car data))))
10765                            (gnus-simplify-subject-re
10766                             (mail-header-subject
10767                              (gnus-data-header (car data)))))))
10768         (push (gnus-data-number (car data)) articles))
10769       (unless (and (setq data (cdr data))
10770                    (> (gnus-data-level (car data)) top-level))
10771         (setq data nil)))
10772     ;; Return the list of articles.
10773     (nreverse articles)))
10774
10775 (defun gnus-summary-rethread-current ()
10776   "Rethread the thread the current article is part of."
10777   (interactive)
10778   (let* ((gnus-show-threads t)
10779          (article (gnus-summary-article-number))
10780          (id (mail-header-id (gnus-summary-article-header)))
10781          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10782     (unless id
10783       (error "No article on the current line"))
10784     (gnus-rebuild-thread id)
10785     (gnus-summary-goto-subject article)))
10786
10787 (defun gnus-summary-reparent-thread ()
10788   "Make the current article child of the marked (or previous) article.
10789
10790 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10791 is non-nil or the Subject: of both articles are the same."
10792   (interactive)
10793   (unless (not (gnus-group-read-only-p))
10794     (error "The current newsgroup does not support article editing"))
10795   (unless (<= (length gnus-newsgroup-processable) 1)
10796     (error "No more than one article may be marked"))
10797   (save-window-excursion
10798     (let ((gnus-article-buffer " *reparent*")
10799           (current-article (gnus-summary-article-number))
10800           ;; First grab the marked article, otherwise one line up.
10801           (parent-article (if (not (null gnus-newsgroup-processable))
10802                               (car gnus-newsgroup-processable)
10803                             (save-excursion
10804                               (if (eq (forward-line -1) 0)
10805                                   (gnus-summary-article-number)
10806                                 (error "Beginning of summary buffer"))))))
10807       (unless (not (eq current-article parent-article))
10808         (error "An article may not be self-referential"))
10809       (let ((message-id (mail-header-id
10810                          (gnus-summary-article-header parent-article))))
10811         (unless (and message-id (not (equal message-id "")))
10812           (error "No message-id in desired parent"))
10813         (gnus-with-article current-article
10814           (save-restriction
10815             (goto-char (point-min))
10816             (message-narrow-to-head)
10817             (if (re-search-forward "^References: " nil t)
10818                 (progn
10819                   (re-search-forward "^[^ \t]" nil t)
10820                   (forward-line -1)
10821                   (end-of-line)
10822                   (insert " " message-id))
10823               (insert "References: " message-id "\n"))))
10824         (set-buffer gnus-summary-buffer)
10825         (gnus-summary-unmark-all-processable)
10826         (gnus-summary-update-article current-article)
10827         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10828             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10829         (gnus-summary-rethread-current)
10830         (gnus-message 3 "Article %d is now the child of article %d"
10831                       current-article parent-article)))))
10832
10833 (defun gnus-summary-toggle-threads (&optional arg)
10834   "Toggle showing conversation threads.
10835 If ARG is positive number, turn showing conversation threads on."
10836   (interactive "P")
10837   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10838     (setq gnus-show-threads
10839           (if (null arg) (not gnus-show-threads)
10840             (> (prefix-numeric-value arg) 0)))
10841     (gnus-summary-prepare)
10842     (gnus-summary-goto-subject current)
10843     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10844     (gnus-summary-position-point)))
10845
10846 (defun gnus-summary-show-all-threads ()
10847   "Show all threads."
10848   (interactive)
10849   (save-excursion
10850     (let ((buffer-read-only nil))
10851       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10852   (gnus-summary-position-point))
10853
10854 (defun gnus-summary-show-thread ()
10855   "Show thread subtrees.
10856 Returns nil if no thread was there to be shown."
10857   (interactive)
10858   (let ((buffer-read-only nil)
10859         (orig (point))
10860         (end (point-at-eol))
10861         ;; Leave point at bol
10862         (beg (progn (beginning-of-line) (point))))
10863     (prog1
10864         ;; Any hidden lines here?
10865         (search-forward "\r" end t)
10866       (subst-char-in-region beg end ?\^M ?\n t)
10867       (goto-char orig)
10868       (gnus-summary-position-point))))
10869
10870 (defun gnus-summary-maybe-hide-threads ()
10871   "If requested, hide the threads that should be hidden."
10872   (when (and gnus-show-threads
10873              gnus-thread-hide-subtree)
10874     (gnus-summary-hide-all-threads
10875      (if (or (consp gnus-thread-hide-subtree)
10876              (functionp gnus-thread-hide-subtree))
10877          (gnus-make-predicate gnus-thread-hide-subtree)
10878        nil))))
10879
10880 ;;; Hiding predicates.
10881
10882 (defun gnus-article-unread-p (header)
10883   (memq (mail-header-number header) gnus-newsgroup-unreads))
10884
10885 (defun gnus-article-unseen-p (header)
10886   (memq (mail-header-number header) gnus-newsgroup-unseen))
10887
10888 (defun gnus-map-articles (predicate articles)
10889   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10890   (apply 'gnus-or (mapcar predicate
10891                           (mapcar 'gnus-summary-article-header articles))))
10892
10893 (defun gnus-summary-hide-all-threads (&optional predicate)
10894   "Hide all thread subtrees.
10895 If PREDICATE is supplied, threads that satisfy this predicate
10896 will not be hidden."
10897   (interactive)
10898   (save-excursion
10899     (goto-char (point-min))
10900     (let ((end nil))
10901       (while (not end)
10902         (when (or (not predicate)
10903                   (gnus-map-articles
10904                    predicate (gnus-summary-article-children)))
10905             (gnus-summary-hide-thread))
10906         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10907   (gnus-summary-position-point))
10908
10909 (defun gnus-summary-hide-thread ()
10910   "Hide thread subtrees.
10911 If PREDICATE is supplied, threads that satisfy this predicate
10912 will not be hidden.
10913 Returns nil if no threads were there to be hidden."
10914   (interactive)
10915   (let ((buffer-read-only nil)
10916         (start (point))
10917         (article (gnus-summary-article-number)))
10918     (goto-char start)
10919     ;; Go forward until either the buffer ends or the subthread
10920     ;; ends.
10921     (when (and (not (eobp))
10922                (or (zerop (gnus-summary-next-thread 1 t))
10923                    (goto-char (point-max))))
10924       (prog1
10925           (if (and (> (point) start)
10926                    (search-backward "\n" start t))
10927               (progn
10928                 (subst-char-in-region start (point) ?\n ?\^M)
10929                 (gnus-summary-goto-subject article))
10930             (goto-char start)
10931             nil)))))
10932
10933 (defun gnus-summary-go-to-next-thread (&optional previous)
10934   "Go to the same level (or less) next thread.
10935 If PREVIOUS is non-nil, go to previous thread instead.
10936 Return the article number moved to, or nil if moving was impossible."
10937   (let ((level (gnus-summary-thread-level))
10938         (way (if previous -1 1))
10939         (beg (point)))
10940     (forward-line way)
10941     (while (and (not (eobp))
10942                 (< level (gnus-summary-thread-level)))
10943       (forward-line way))
10944     (if (eobp)
10945         (progn
10946           (goto-char beg)
10947           nil)
10948       (setq beg (point))
10949       (prog1
10950           (gnus-summary-article-number)
10951         (goto-char beg)))))
10952
10953 (defun gnus-summary-next-thread (n &optional silent)
10954   "Go to the same level next N'th thread.
10955 If N is negative, search backward instead.
10956 Returns the difference between N and the number of skips actually
10957 done.
10958
10959 If SILENT, don't output messages."
10960   (interactive "p")
10961   (let ((backward (< n 0))
10962         (n (abs n)))
10963     (while (and (> n 0)
10964                 (gnus-summary-go-to-next-thread backward))
10965       (decf n))
10966     (unless silent
10967       (gnus-summary-position-point))
10968     (when (and (not silent) (/= 0 n))
10969       (gnus-message 7 "No more threads"))
10970     n))
10971
10972 (defun gnus-summary-prev-thread (n)
10973   "Go to the same level previous N'th thread.
10974 Returns the difference between N and the number of skips actually
10975 done."
10976   (interactive "p")
10977   (gnus-summary-next-thread (- n)))
10978
10979 (defun gnus-summary-go-down-thread ()
10980   "Go down one level in the current thread."
10981   (let ((children (gnus-summary-article-children)))
10982     (when children
10983       (gnus-summary-goto-subject (car children)))))
10984
10985 (defun gnus-summary-go-up-thread ()
10986   "Go up one level in the current thread."
10987   (let ((parent (gnus-summary-article-parent)))
10988     (when parent
10989       (gnus-summary-goto-subject parent))))
10990
10991 (defun gnus-summary-down-thread (n)
10992   "Go down thread N steps.
10993 If N is negative, go up instead.
10994 Returns the difference between N and how many steps down that were
10995 taken."
10996   (interactive "p")
10997   (let ((up (< n 0))
10998         (n (abs n)))
10999     (while (and (> n 0)
11000                 (if up (gnus-summary-go-up-thread)
11001                   (gnus-summary-go-down-thread)))
11002       (setq n (1- n)))
11003     (gnus-summary-position-point)
11004     (when (/= 0 n)
11005       (gnus-message 7 "Can't go further"))
11006     n))
11007
11008 (defun gnus-summary-up-thread (n)
11009   "Go up thread N steps.
11010 If N is negative, go down instead.
11011 Returns the difference between N and how many steps down that were
11012 taken."
11013   (interactive "p")
11014   (gnus-summary-down-thread (- n)))
11015
11016 (defun gnus-summary-top-thread ()
11017   "Go to the top of the thread."
11018   (interactive)
11019   (while (gnus-summary-go-up-thread))
11020   (gnus-summary-article-number))
11021
11022 (defun gnus-summary-kill-thread (&optional unmark)
11023   "Mark articles under current thread as read.
11024 If the prefix argument is positive, remove any kinds of marks.
11025 If the prefix argument is negative, tick articles instead."
11026   (interactive "P")
11027   (when unmark
11028     (setq unmark (prefix-numeric-value unmark)))
11029   (let ((articles (gnus-summary-articles-in-thread)))
11030     (save-excursion
11031       ;; Expand the thread.
11032       (gnus-summary-show-thread)
11033       ;; Mark all the articles.
11034       (while articles
11035         (gnus-summary-goto-subject (car articles))
11036         (cond ((null unmark)
11037                (gnus-summary-mark-article-as-read gnus-killed-mark))
11038               ((> unmark 0)
11039                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11040               (t
11041                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11042         (setq articles (cdr articles))))
11043     ;; Hide killed subtrees.
11044     (and (null unmark)
11045          gnus-thread-hide-killed
11046          (gnus-summary-hide-thread))
11047     ;; If marked as read, go to next unread subject.
11048     (when (null unmark)
11049       ;; Go to next unread subject.
11050       (gnus-summary-next-subject 1 t)))
11051   (gnus-set-mode-line 'summary))
11052
11053 ;; Summary sorting commands
11054
11055 (defun gnus-summary-sort-by-number (&optional reverse)
11056   "Sort the summary buffer by article number.
11057 Argument REVERSE means reverse order."
11058   (interactive "P")
11059   (gnus-summary-sort 'number reverse))
11060
11061 (defun gnus-summary-sort-by-random (&optional reverse)
11062   "Randomize the order in the summary buffer.
11063 Argument REVERSE means to randomize in reverse order."
11064   (interactive "P")
11065   (gnus-summary-sort 'random reverse))
11066
11067 (defun gnus-summary-sort-by-author (&optional reverse)
11068   "Sort the summary buffer by author name alphabetically.
11069 If `case-fold-search' is non-nil, case of letters is ignored.
11070 Argument REVERSE means reverse order."
11071   (interactive "P")
11072   (gnus-summary-sort 'author reverse))
11073
11074 (defun gnus-summary-sort-by-recipient (&optional reverse)
11075   "Sort the summary buffer by recipient name alphabetically.
11076 If `case-fold-search' is non-nil, case of letters is ignored.
11077 Argument REVERSE means reverse order."
11078   (interactive "P")
11079   (gnus-summary-sort 'recipient reverse))
11080
11081 (defun gnus-summary-sort-by-subject (&optional reverse)
11082   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11083 If `case-fold-search' is non-nil, case of letters is ignored.
11084 Argument REVERSE means reverse order."
11085   (interactive "P")
11086   (gnus-summary-sort 'subject reverse))
11087
11088 (defun gnus-summary-sort-by-date (&optional reverse)
11089   "Sort the summary buffer by date.
11090 Argument REVERSE means reverse order."
11091   (interactive "P")
11092   (gnus-summary-sort 'date reverse))
11093
11094 (defun gnus-summary-sort-by-score (&optional reverse)
11095   "Sort the summary buffer by score.
11096 Argument REVERSE means reverse order."
11097   (interactive "P")
11098   (gnus-summary-sort 'score reverse))
11099
11100 (defun gnus-summary-sort-by-lines (&optional reverse)
11101   "Sort the summary buffer by the number of lines.
11102 Argument REVERSE means reverse order."
11103   (interactive "P")
11104   (gnus-summary-sort 'lines reverse))
11105
11106 (defun gnus-summary-sort-by-chars (&optional reverse)
11107   "Sort the summary buffer by article length.
11108 Argument REVERSE means reverse order."
11109   (interactive "P")
11110   (gnus-summary-sort 'chars reverse))
11111
11112 (defun gnus-summary-sort-by-original (&optional reverse)
11113   "Sort the summary buffer using the default sorting method.
11114 Argument REVERSE means reverse order."
11115   (interactive "P")
11116   (let* ((buffer-read-only)
11117          (gnus-summary-prepare-hook nil))
11118     ;; We do the sorting by regenerating the threads.
11119     (gnus-summary-prepare)
11120     ;; Hide subthreads if needed.
11121     (gnus-summary-maybe-hide-threads)))
11122
11123 (defun gnus-summary-sort (predicate reverse)
11124   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11125   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11126          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11127          (gnus-thread-sort-functions
11128           (if (not reverse)
11129               thread
11130             `(lambda (t1 t2)
11131                (,thread t2 t1))))
11132          (gnus-sort-gathered-threads-function
11133           gnus-thread-sort-functions)
11134          (gnus-article-sort-functions
11135           (if (not reverse)
11136               article
11137             `(lambda (t1 t2)
11138                (,article t2 t1))))
11139          (buffer-read-only)
11140          (gnus-summary-prepare-hook nil))
11141     ;; We do the sorting by regenerating the threads.
11142     (gnus-summary-prepare)
11143     ;; Hide subthreads if needed.
11144     (gnus-summary-maybe-hide-threads)))
11145
11146 ;; Summary saving commands.
11147
11148 (defun gnus-summary-save-article (&optional n not-saved)
11149   "Save the current article using the default saver function.
11150 If N is a positive number, save the N next articles.
11151 If N is a negative number, save the N previous articles.
11152 If N is nil and any articles have been marked with the process mark,
11153 save those articles instead.
11154 The variable `gnus-default-article-saver' specifies the saver function."
11155   (interactive "P")
11156   (let* ((articles (gnus-summary-work-articles n))
11157          (save-buffer (save-excursion
11158                         (nnheader-set-temp-buffer " *Gnus Save*")))
11159          (num (length articles))
11160          header file)
11161     (dolist (article articles)
11162       (setq header (gnus-summary-article-header article))
11163       (if (not (vectorp header))
11164           ;; This is a pseudo-article.
11165           (if (assq 'name header)
11166               (gnus-copy-file (cdr (assq 'name header)))
11167             (gnus-message 1 "Article %d is unsaveable" article))
11168         ;; This is a real article.
11169         (save-window-excursion
11170           (let ((gnus-display-mime-function nil)
11171                 (gnus-article-prepare-hook nil))
11172             (gnus-summary-select-article t nil nil article)))
11173         (save-excursion
11174           (set-buffer save-buffer)
11175           (erase-buffer)
11176           (insert-buffer-substring gnus-original-article-buffer))
11177         (setq file (gnus-article-save save-buffer file num))
11178         (gnus-summary-remove-process-mark article)
11179         (unless not-saved
11180           (gnus-summary-set-saved-mark article))))
11181     (gnus-kill-buffer save-buffer)
11182     (gnus-summary-position-point)
11183     (gnus-set-mode-line 'summary)
11184     n))
11185
11186 (defun gnus-summary-pipe-output (&optional arg headers)
11187   "Pipe the current article to a subprocess.
11188 If N is a positive number, pipe the N next articles.
11189 If N is a negative number, pipe the N previous articles.
11190 If N is nil and any articles have been marked with the process mark,
11191 pipe those articles instead.
11192 If HEADERS (the symbolic prefix), include the headers, too."
11193   (interactive (gnus-interactive "P\ny"))
11194   (require 'gnus-art)
11195   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11196         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11197     (gnus-summary-save-article arg t))
11198   (let ((buffer (get-buffer "*Shell Command Output*")))
11199     (when (and buffer
11200                (not (zerop (buffer-size buffer))))
11201       (gnus-configure-windows 'pipe))))
11202
11203 (defun gnus-summary-save-article-mail (&optional arg)
11204   "Append the current article to an mail file.
11205 If N is a positive number, save the N next articles.
11206 If N is a negative number, save the N previous articles.
11207 If N is nil and any articles have been marked with the process mark,
11208 save those articles instead."
11209   (interactive "P")
11210   (require 'gnus-art)
11211   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11212     (gnus-summary-save-article arg)))
11213
11214 (defun gnus-summary-save-article-rmail (&optional arg)
11215   "Append the current article to an rmail file.
11216 If N is a positive number, save the N next articles.
11217 If N is a negative number, save the N previous articles.
11218 If N is nil and any articles have been marked with the process mark,
11219 save those articles instead."
11220   (interactive "P")
11221   (require 'gnus-art)
11222   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11223     (gnus-summary-save-article arg)))
11224
11225 (defun gnus-summary-save-article-file (&optional arg)
11226   "Append the current article to a file.
11227 If N is a positive number, save the N next articles.
11228 If N is a negative number, save the N previous articles.
11229 If N is nil and any articles have been marked with the process mark,
11230 save those articles instead."
11231   (interactive "P")
11232   (require 'gnus-art)
11233   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11234     (gnus-summary-save-article arg)))
11235
11236 (defun gnus-summary-write-article-file (&optional arg)
11237   "Write the current article to a file, deleting the previous file.
11238 If N is a positive number, save the N next articles.
11239 If N is a negative number, save the N previous articles.
11240 If N is nil and any articles have been marked with the process mark,
11241 save those articles instead."
11242   (interactive "P")
11243   (require 'gnus-art)
11244   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11245     (gnus-summary-save-article arg)))
11246
11247 (defun gnus-summary-save-article-body-file (&optional arg)
11248   "Append the current article body to a file.
11249 If N is a positive number, save the N next articles.
11250 If N is a negative number, save the N previous articles.
11251 If N is nil and any articles have been marked with the process mark,
11252 save those articles instead."
11253   (interactive "P")
11254   (require 'gnus-art)
11255   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11256     (gnus-summary-save-article arg)))
11257
11258 (defun gnus-summary-muttprint (&optional arg)
11259   "Print the current article using Muttprint.
11260 If N is a positive number, save the N next articles.
11261 If N is a negative number, save the N previous articles.
11262 If N is nil and any articles have been marked with the process mark,
11263 save those articles instead."
11264   (interactive "P")
11265   (require 'gnus-art)
11266   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11267     (gnus-summary-save-article arg t)))
11268
11269 (defun gnus-summary-pipe-message (program)
11270   "Pipe the current article through PROGRAM."
11271   (interactive "sProgram: ")
11272   (gnus-summary-select-article)
11273   (let ((mail-header-separator ""))
11274     (gnus-eval-in-buffer-window gnus-article-buffer
11275       (save-restriction
11276         (widen)
11277         (let ((start (window-start))
11278               buffer-read-only)
11279           (message-pipe-buffer-body program)
11280           (set-window-start (get-buffer-window (current-buffer)) start))))))
11281
11282 (defun gnus-get-split-value (methods)
11283   "Return a value based on the split METHODS."
11284   (let (split-name method result match)
11285     (when methods
11286       (save-excursion
11287         (set-buffer gnus-original-article-buffer)
11288         (save-restriction
11289           (nnheader-narrow-to-headers)
11290           (while (and methods (not split-name))
11291             (goto-char (point-min))
11292             (setq method (pop methods))
11293             (setq match (car method))
11294             (when (cond
11295                    ((stringp match)
11296                     ;; Regular expression.
11297                     (ignore-errors
11298                       (re-search-forward match nil t)))
11299                    ((functionp match)
11300                     ;; Function.
11301                     (save-restriction
11302                       (widen)
11303                       (setq result (funcall match gnus-newsgroup-name))))
11304                    ((consp match)
11305                     ;; Form.
11306                     (save-restriction
11307                       (widen)
11308                       (setq result (eval match)))))
11309               (setq split-name (cdr method))
11310               (cond ((stringp result)
11311                      (push (expand-file-name
11312                             result gnus-article-save-directory)
11313                            split-name))
11314                     ((consp result)
11315                      (setq split-name (append result split-name)))))))))
11316     (nreverse split-name)))
11317
11318 (defun gnus-valid-move-group-p (group)
11319   (and (boundp group)
11320        (symbol-name group)
11321        (symbol-value group)
11322        (gnus-get-function (gnus-find-method-for-group
11323                            (symbol-name group)) 'request-accept-article t)))
11324
11325 (defun gnus-read-move-group-name (prompt default articles prefix)
11326   "Read a group name."
11327   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11328          (minibuffer-confirm-incomplete nil) ; XEmacs
11329          (prom
11330           (format "%s %s to"
11331                   prompt
11332                   (if (> (length articles) 1)
11333                       (format "these %d articles" (length articles))
11334                     "this article")))
11335          (to-newsgroup
11336           (cond
11337            ((null split-name)
11338             (gnus-completing-read-with-default
11339              default prom
11340              gnus-active-hashtb
11341              'gnus-valid-move-group-p
11342              nil prefix
11343              'gnus-group-history))
11344            ((= 1 (length split-name))
11345             (gnus-completing-read-with-default
11346              (car split-name) prom
11347              gnus-active-hashtb
11348              'gnus-valid-move-group-p
11349              nil nil
11350              'gnus-group-history))
11351            (t
11352             (gnus-completing-read-with-default
11353              nil prom
11354              (mapcar 'list (nreverse split-name))
11355              nil nil nil
11356              'gnus-group-history))))
11357          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11358     (when to-newsgroup
11359       (if (or (string= to-newsgroup "")
11360               (string= to-newsgroup prefix))
11361           (setq to-newsgroup default))
11362       (unless to-newsgroup
11363         (error "No group name entered"))
11364       (or (gnus-active to-newsgroup)
11365           (gnus-activate-group to-newsgroup nil nil to-method)
11366           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11367                                      to-newsgroup))
11368               (or (and (gnus-request-create-group to-newsgroup to-method)
11369                        (gnus-activate-group
11370                         to-newsgroup nil nil to-method)
11371                        (gnus-subscribe-group to-newsgroup))
11372                   (error "Couldn't create group %s" to-newsgroup)))
11373           (error "No such group: %s" to-newsgroup)))
11374     to-newsgroup))
11375
11376 (defun gnus-summary-save-parts (type dir n &optional reverse)
11377   "Save parts matching TYPE to DIR.
11378 If REVERSE, save parts that do not match TYPE."
11379   (interactive
11380    (list (read-string "Save parts of type: "
11381                       (or (car gnus-summary-save-parts-type-history)
11382                           gnus-summary-save-parts-default-mime)
11383                       'gnus-summary-save-parts-type-history)
11384          (setq gnus-summary-save-parts-last-directory
11385                (read-file-name "Save to directory: "
11386                                gnus-summary-save-parts-last-directory
11387                                nil t))
11388          current-prefix-arg))
11389   (gnus-summary-iterate n
11390     (let ((gnus-display-mime-function nil)
11391           (gnus-inhibit-treatment t))
11392       (gnus-summary-select-article))
11393     (save-excursion
11394       (set-buffer gnus-article-buffer)
11395       (let ((handles (or gnus-article-mime-handles
11396                          (mm-dissect-buffer nil gnus-article-loose-mime)
11397                          (and gnus-article-emulate-mime
11398                               (mm-uu-dissect)))))
11399         (when handles
11400           (gnus-summary-save-parts-1 type dir handles reverse)
11401           (unless gnus-article-mime-handles ;; Don't destroy this case.
11402             (mm-destroy-parts handles)))))))
11403
11404 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11405   (if (stringp (car handle))
11406       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11407               (cdr handle))
11408     (when (if reverse
11409               (not (string-match type (mm-handle-media-type handle)))
11410             (string-match type (mm-handle-media-type handle)))
11411       (let ((file (expand-file-name
11412                    (gnus-map-function
11413                     mm-file-name-rewrite-functions
11414                     (file-name-nondirectory
11415                      (or
11416                       (mail-content-type-get
11417                        (mm-handle-disposition handle) 'filename)
11418                       (mail-content-type-get
11419                        (mm-handle-type handle) 'name)
11420                       (concat gnus-newsgroup-name
11421                               "." (number-to-string
11422                                    (cdr gnus-article-current))))))
11423                    dir)))
11424         (unless (file-exists-p file)
11425           (mm-save-part-to-file handle file))))))
11426
11427 ;; Summary extract commands
11428
11429 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11430   (let ((buffer-read-only nil)
11431         (article (gnus-summary-article-number))
11432         after-article b e)
11433     (unless (gnus-summary-goto-subject article)
11434       (error "No such article: %d" article))
11435     (gnus-summary-position-point)
11436     ;; If all commands are to be bunched up on one line, we collect
11437     ;; them here.
11438     (unless gnus-view-pseudos-separately
11439       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11440             files action)
11441         (while ps
11442           (setq action (cdr (assq 'action (car ps))))
11443           (setq files (list (cdr (assq 'name (car ps)))))
11444           (while (and ps (cdr ps)
11445                       (string= (or action "1")
11446                                (or (cdr (assq 'action (cadr ps))) "2")))
11447             (push (cdr (assq 'name (cadr ps))) files)
11448             (setcdr ps (cddr ps)))
11449           (when files
11450             (when (not (string-match "%s" action))
11451               (push " " files))
11452             (push " " files)
11453             (when (assq 'execute (car ps))
11454               (setcdr (assq 'execute (car ps))
11455                       (funcall (if (string-match "%s" action)
11456                                    'format 'concat)
11457                                action
11458                                (mapconcat
11459                                 (lambda (f)
11460                                   (if (equal f " ")
11461                                       f
11462                                     (shell-quote-argument f)))
11463                                 files " ")))))
11464           (setq ps (cdr ps)))))
11465     (if (and gnus-view-pseudos (not not-view))
11466         (while pslist
11467           (when (assq 'execute (car pslist))
11468             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11469                                   (eq gnus-view-pseudos 'not-confirm)))
11470           (setq pslist (cdr pslist)))
11471       (save-excursion
11472         (while pslist
11473           (setq after-article (or (cdr (assq 'article (car pslist)))
11474                                   (gnus-summary-article-number)))
11475           (gnus-summary-goto-subject after-article)
11476           (forward-line 1)
11477           (setq b (point))
11478           (insert "    " (file-name-nondirectory
11479                           (cdr (assq 'name (car pslist))))
11480                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11481           (setq e (point))
11482           (forward-line -1)             ; back to `b'
11483           (gnus-add-text-properties
11484            b (1- e) (list 'gnus-number gnus-reffed-article-number
11485                           gnus-mouse-face-prop gnus-mouse-face))
11486           (gnus-data-enter
11487            after-article gnus-reffed-article-number
11488            gnus-unread-mark b (car pslist) 0 (- e b))
11489           (setq gnus-newsgroup-unreads
11490                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11491                                          gnus-reffed-article-number))
11492           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11493           (setq pslist (cdr pslist)))))))
11494
11495 (defun gnus-pseudos< (p1 p2)
11496   (let ((c1 (cdr (assq 'action p1)))
11497         (c2 (cdr (assq 'action p2))))
11498     (and c1 c2 (string< c1 c2))))
11499
11500 (defun gnus-request-pseudo-article (props)
11501   (cond ((assq 'execute props)
11502          (gnus-execute-command (cdr (assq 'execute props)))))
11503   (let ((gnus-current-article (gnus-summary-article-number)))
11504     (gnus-run-hooks 'gnus-mark-article-hook)))
11505
11506 (defun gnus-execute-command (command &optional automatic)
11507   (save-excursion
11508     (gnus-article-setup-buffer)
11509     (set-buffer gnus-article-buffer)
11510     (setq buffer-read-only nil)
11511     (let ((command (if automatic command
11512                      (read-string "Command: " (cons command 0)))))
11513       (erase-buffer)
11514       (insert "$ " command "\n\n")
11515       (if gnus-view-pseudo-asynchronously
11516           (start-process "gnus-execute" (current-buffer) shell-file-name
11517                          shell-command-switch command)
11518         (call-process shell-file-name nil t nil
11519                       shell-command-switch command)))))
11520
11521 ;; Summary kill commands.
11522
11523 (defun gnus-summary-edit-global-kill (article)
11524   "Edit the \"global\" kill file."
11525   (interactive (list (gnus-summary-article-number)))
11526   (gnus-group-edit-global-kill article))
11527
11528 (defun gnus-summary-edit-local-kill ()
11529   "Edit a local kill file applied to the current newsgroup."
11530   (interactive)
11531   (setq gnus-current-headers (gnus-summary-article-header))
11532   (gnus-group-edit-local-kill
11533    (gnus-summary-article-number) gnus-newsgroup-name))
11534
11535 ;;; Header reading.
11536
11537 (defun gnus-read-header (id &optional header)
11538   "Read the headers of article ID and enter them into the Gnus system."
11539   (let ((group gnus-newsgroup-name)
11540         (gnus-override-method
11541          (or
11542           gnus-override-method
11543           (and (gnus-news-group-p gnus-newsgroup-name)
11544                (car (gnus-refer-article-methods)))))
11545         where)
11546     ;; First we check to see whether the header in question is already
11547     ;; fetched.
11548     (if (stringp id)
11549         ;; This is a Message-ID.
11550         (setq header (or header (gnus-id-to-header id)))
11551       ;; This is an article number.
11552       (setq header (or header (gnus-summary-article-header id))))
11553     (if (and header
11554              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11555         ;; We have found the header.
11556         header
11557       ;; We have to really fetch the header to this article.
11558       (save-excursion
11559         (set-buffer nntp-server-buffer)
11560         (when (setq where (gnus-request-head id group))
11561           (nnheader-fold-continuation-lines)
11562           (goto-char (point-max))
11563           (insert ".\n")
11564           (goto-char (point-min))
11565           (insert "211 ")
11566           (princ (cond
11567                   ((numberp id) id)
11568                   ((cdr where) (cdr where))
11569                   (header (mail-header-number header))
11570                   (t gnus-reffed-article-number))
11571                  (current-buffer))
11572           (insert " Article retrieved.\n"))
11573         (if (or (not where)
11574                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11575             ()                          ; Malformed head.
11576           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11577             (when (and (stringp id)
11578                        (not (string= (gnus-group-real-name group)
11579                                      (car where))))
11580               ;; If we fetched by Message-ID and the article came
11581               ;; from a different group, we fudge some bogus article
11582               ;; numbers for this article.
11583               (mail-header-set-number header gnus-reffed-article-number))
11584             (save-excursion
11585               (set-buffer gnus-summary-buffer)
11586               (decf gnus-reffed-article-number)
11587               (gnus-remove-header (mail-header-number header))
11588               (push header gnus-newsgroup-headers)
11589               (setq gnus-current-headers header)
11590               (push (mail-header-number header) gnus-newsgroup-limit)))
11591           header)))))
11592
11593 (defun gnus-remove-header (number)
11594   "Remove header NUMBER from `gnus-newsgroup-headers'."
11595   (if (and gnus-newsgroup-headers
11596            (= number (mail-header-number (car gnus-newsgroup-headers))))
11597       (pop gnus-newsgroup-headers)
11598     (let ((headers gnus-newsgroup-headers))
11599       (while (and (cdr headers)
11600                   (not (= number (mail-header-number (cadr headers)))))
11601         (pop headers))
11602       (when (cdr headers)
11603         (setcdr headers (cddr headers))))))
11604
11605 ;;;
11606 ;;; summary highlights
11607 ;;;
11608
11609 (defun gnus-highlight-selected-summary ()
11610   "Highlight selected article in summary buffer."
11611   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11612   (when gnus-summary-selected-face
11613     (save-excursion
11614       (let* ((beg (point-at-bol))
11615              (end (point-at-eol))
11616              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11617              (from (if (get-text-property beg gnus-mouse-face-prop)
11618                        beg
11619                      (or (next-single-property-change
11620                           beg gnus-mouse-face-prop nil end)
11621                          beg)))
11622              (to
11623               (if (= from end)
11624                   (- from 2)
11625                 (or (next-single-property-change
11626                      from gnus-mouse-face-prop nil end)
11627                     end))))
11628         ;; If no mouse-face prop on line we will have to = from = end,
11629         ;; so we highlight the entire line instead.
11630         (when (= (+ to 2) from)
11631           (setq from beg)
11632           (setq to end))
11633         (if gnus-newsgroup-selected-overlay
11634             ;; Move old overlay.
11635             (gnus-move-overlay
11636              gnus-newsgroup-selected-overlay from to (current-buffer))
11637           ;; Create new overlay.
11638           (gnus-overlay-put
11639            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11640            'face gnus-summary-selected-face))))))
11641
11642 (defvar gnus-summary-highlight-line-cached nil)
11643 (defvar gnus-summary-highlight-line-trigger nil)
11644
11645 (defun gnus-summary-highlight-line-0 ()
11646   (if (and (eq gnus-summary-highlight-line-trigger
11647                gnus-summary-highlight)
11648            gnus-summary-highlight-line-cached)
11649       gnus-summary-highlight-line-cached
11650     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11651           gnus-summary-highlight-line-cached
11652           (let* ((cond (list 'cond))
11653                  (c cond)
11654                  (list gnus-summary-highlight))
11655             (while list
11656               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11657                               nil))
11658               (setq c (cdr c)
11659                     list (cdr list)))
11660             (gnus-byte-compile (list 'lambda nil cond))))))
11661
11662 (defun gnus-summary-highlight-line ()
11663   "Highlight current line according to `gnus-summary-highlight'."
11664   (let* ((beg (point-at-bol))
11665          (article (or (gnus-summary-article-number) gnus-current-article))
11666          (score (or (cdr (assq article
11667                                gnus-newsgroup-scored))
11668                     gnus-summary-default-score 0))
11669          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11670          (inhibit-read-only t)
11671          (default gnus-summary-default-score)
11672          (default-high gnus-summary-default-high-score)
11673          (default-low gnus-summary-default-low-score)
11674          (uncached (and gnus-summary-use-undownloaded-faces
11675                         (memq article gnus-newsgroup-undownloaded)
11676                         (not (memq article gnus-newsgroup-cached)))))
11677     (let ((face (funcall (gnus-summary-highlight-line-0))))
11678       (unless (eq face (get-text-property beg 'face))
11679         (gnus-put-text-property-excluding-characters-with-faces
11680          beg (point-at-eol) 'face
11681          (setq face (if (boundp face) (symbol-value face) face)))
11682         (when gnus-summary-highlight-line-function
11683           (funcall gnus-summary-highlight-line-function article face))))))
11684
11685 (defun gnus-update-read-articles (group unread &optional compute)
11686   "Update the list of read articles in GROUP.
11687 UNREAD is a sorted list."
11688   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11689         (info (gnus-get-info group))
11690         (prev 1)
11691         read)
11692     (if (or (not info) (not active))
11693         ;; There is no info on this group if it was, in fact,
11694         ;; killed.  Gnus stores no information on killed groups, so
11695         ;; there's nothing to be done.
11696         ;; One could store the information somewhere temporarily,
11697         ;; perhaps...  Hmmm...
11698         ()
11699       ;; Remove any negative articles numbers.
11700       (while (and unread (< (car unread) 0))
11701         (setq unread (cdr unread)))
11702       ;; Remove any expired article numbers
11703       (while (and unread (< (car unread) (car active)))
11704         (setq unread (cdr unread)))
11705       ;; Compute the ranges of read articles by looking at the list of
11706       ;; unread articles.
11707       (while unread
11708         (when (/= (car unread) prev)
11709           (push (if (= prev (1- (car unread))) prev
11710                   (cons prev (1- (car unread))))
11711                 read))
11712         (setq prev (1+ (car unread)))
11713         (setq unread (cdr unread)))
11714       (when (<= prev (cdr active))
11715         (push (cons prev (cdr active)) read))
11716       (setq read (if (> (length read) 1) (nreverse read) read))
11717       (if compute
11718           read
11719         (save-excursion
11720           (let (setmarkundo)
11721             ;; Propagate the read marks to the backend.
11722             (when (gnus-check-backend-function 'request-set-mark group)
11723               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11724                     (add (gnus-remove-from-range read (gnus-info-read info))))
11725                 (when (or add del)
11726                   (unless (gnus-check-group group)
11727                     (error "Can't open server for %s" group))
11728                   (gnus-request-set-mark
11729                    group (delq nil (list (if add (list add 'add '(read)))
11730                                          (if del (list del 'del '(read))))))
11731                   (setq setmarkundo
11732                         `(gnus-request-set-mark
11733                           ,group
11734                           ',(delq nil (list
11735                                        (if del (list del 'add '(read)))
11736                                        (if add (list add 'del '(read))))))))))
11737             (set-buffer gnus-group-buffer)
11738             (gnus-undo-register
11739               `(progn
11740                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11741                  (gnus-info-set-read ',info ',(gnus-info-read info))
11742                  (gnus-get-unread-articles-in-group ',info
11743                                                     (gnus-active ,group))
11744                  (gnus-group-update-group ,group t)
11745                  ,setmarkundo))))
11746         ;; Enter this list into the group info.
11747         (gnus-info-set-read info read)
11748         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11749         (gnus-get-unread-articles-in-group info (gnus-active group))
11750         t))))
11751
11752 (defun gnus-offer-save-summaries ()
11753   "Offer to save all active summary buffers."
11754   (let (buffers)
11755     ;; Go through all buffers and find all summaries.
11756     (dolist (buffer (buffer-list))
11757       (when (and (setq buffer (buffer-name buffer))
11758                  (string-match "Summary" buffer)
11759                  (with-current-buffer buffer
11760                    ;; We check that this is, indeed, a summary buffer.
11761                    (and (eq major-mode 'gnus-summary-mode)
11762                         ;; Also make sure this isn't bogus.
11763                         gnus-newsgroup-prepared
11764                         ;; Also make sure that this isn't a
11765                         ;; dead summary buffer.
11766                         (not gnus-dead-summary-mode))))
11767         (push buffer buffers)))
11768     ;; Go through all these summary buffers and offer to save them.
11769     (when buffers
11770       (save-excursion
11771         (map-y-or-n-p
11772          "Update summary buffer %s? "
11773          (lambda (buf)
11774            (switch-to-buffer buf)
11775            (gnus-summary-exit))
11776          buffers)))))
11777
11778 (defun gnus-summary-setup-default-charset ()
11779   "Setup newsgroup default charset."
11780   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11781       (setq gnus-newsgroup-charset nil)
11782     (let* ((ignored-charsets
11783             (or gnus-newsgroup-ephemeral-ignored-charsets
11784                 (append
11785                  (and gnus-newsgroup-name
11786                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11787                  gnus-newsgroup-ignored-charsets))))
11788       (setq gnus-newsgroup-charset
11789             (or gnus-newsgroup-ephemeral-charset
11790                 (and gnus-newsgroup-name
11791                      (gnus-parameter-charset gnus-newsgroup-name))
11792                 gnus-default-charset))
11793       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11794            ignored-charsets))))
11795
11796 ;;;
11797 ;;; Mime Commands
11798 ;;;
11799
11800 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11801   "Display the current article buffer fully MIME-buttonized.
11802 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11803 treated as multipart/mixed."
11804   (interactive "P")
11805   (require 'gnus-art)
11806   (let ((gnus-unbuttonized-mime-types nil)
11807         (gnus-mime-display-multipart-as-mixed show-all-parts))
11808     (gnus-summary-show-article)))
11809
11810 (defun gnus-summary-repair-multipart (article)
11811   "Add a Content-Type header to a multipart article without one."
11812   (interactive (list (gnus-summary-article-number)))
11813   (gnus-with-article article
11814     (message-narrow-to-head)
11815     (message-remove-header "Mime-Version")
11816     (goto-char (point-max))
11817     (insert "Mime-Version: 1.0\n")
11818     (widen)
11819     (when (search-forward "\n--" nil t)
11820       (let ((separator (buffer-substring (point) (point-at-eol))))
11821         (message-narrow-to-head)
11822         (message-remove-header "Content-Type")
11823         (goto-char (point-max))
11824         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11825                         separator))
11826         (widen))))
11827   (let (gnus-mark-article-hook)
11828     (gnus-summary-select-article t t nil article)))
11829
11830 (defun gnus-summary-toggle-display-buttonized ()
11831   "Toggle the buttonizing of the article buffer."
11832   (interactive)
11833   (require 'gnus-art)
11834   (if (setq gnus-inhibit-mime-unbuttonizing
11835             (not gnus-inhibit-mime-unbuttonizing))
11836       (let ((gnus-unbuttonized-mime-types nil))
11837         (gnus-summary-show-article))
11838     (gnus-summary-show-article)))
11839
11840 ;;;
11841 ;;; Generic summary marking commands
11842 ;;;
11843
11844 (defvar gnus-summary-marking-alist
11845   '((read gnus-del-mark "d")
11846     (unread gnus-unread-mark "u")
11847     (ticked gnus-ticked-mark "!")
11848     (dormant gnus-dormant-mark "?")
11849     (expirable gnus-expirable-mark "e"))
11850   "An alist of names/marks/keystrokes.")
11851
11852 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11853 (defvar gnus-summary-mark-map)
11854
11855 (defun gnus-summary-make-all-marking-commands ()
11856   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11857   (dolist (elem gnus-summary-marking-alist)
11858     (apply 'gnus-summary-make-marking-command elem)))
11859
11860 (defun gnus-summary-make-marking-command (name mark keystroke)
11861   (let ((map (make-sparse-keymap)))
11862     (define-key gnus-summary-generic-mark-map keystroke map)
11863     (dolist (lway `((next "next" next nil "n")
11864                     (next-unread "next unread" next t "N")
11865                     (prev "previous" prev nil "p")
11866                     (prev-unread "previous unread" prev t "P")
11867                     (nomove "" nil nil ,keystroke)))
11868       (let ((func (gnus-summary-make-marking-command-1
11869                    mark (car lway) lway name)))
11870         (setq func (eval func))
11871         (define-key map (nth 4 lway) func)))))
11872
11873 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11874   `(defun ,(intern
11875             (format "gnus-summary-put-mark-as-%s%s"
11876                     name (if (eq way 'nomove)
11877                              ""
11878                            (concat "-" (symbol-name way)))))
11879      (n)
11880      ,(format
11881        "Mark the current article as %s%s.
11882 If N, the prefix, then repeat N times.
11883 If N is negative, move in reverse order.
11884 The difference between N and the actual number of articles marked is
11885 returned."
11886        name (cadr lway))
11887      (interactive "p")
11888      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11889
11890 (defun gnus-summary-generic-mark (n mark move unread)
11891   "Mark N articles with MARK."
11892   (unless (eq major-mode 'gnus-summary-mode)
11893     (error "This command can only be used in the summary buffer"))
11894   (gnus-summary-show-thread)
11895   (let ((nummove
11896          (cond
11897           ((eq move 'next) 1)
11898           ((eq move 'prev) -1)
11899           (t 0))))
11900     (if (zerop nummove)
11901         (setq n 1)
11902       (when (< n 0)
11903         (setq n (abs n)
11904               nummove (* -1 nummove))))
11905     (while (and (> n 0)
11906                 (gnus-summary-mark-article nil mark)
11907                 (zerop (gnus-summary-next-subject nummove unread t)))
11908       (setq n (1- n)))
11909     (when (/= 0 n)
11910       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11911     (gnus-summary-recenter)
11912     (gnus-summary-position-point)
11913     (gnus-set-mode-line 'summary)
11914     n))
11915
11916 (defun gnus-summary-insert-articles (articles)
11917   (when (setq articles
11918               (gnus-sorted-difference articles
11919                                       (mapcar (lambda (h)
11920                                                 (mail-header-number h))
11921                                               gnus-newsgroup-headers)))
11922     (setq gnus-newsgroup-headers
11923           (gnus-merge 'list
11924                       gnus-newsgroup-headers
11925                       (gnus-fetch-headers articles)
11926                       'gnus-article-sort-by-number))
11927     ;; Suppress duplicates?
11928     (when gnus-suppress-duplicates
11929       (gnus-dup-suppress-articles))
11930
11931     ;; We might want to build some more threads first.
11932     (when (and gnus-fetch-old-headers
11933                (eq gnus-headers-retrieved-by 'nov))
11934       (if (eq gnus-fetch-old-headers 'invisible)
11935           (gnus-build-all-threads)
11936         (gnus-build-old-threads)))
11937     ;; Let the Gnus agent mark articles as read.
11938     (when gnus-agent
11939       (gnus-agent-get-undownloaded-list))
11940     ;; Remove list identifiers from subject
11941     (when gnus-list-identifiers
11942       (gnus-summary-remove-list-identifiers))
11943     ;; First and last article in this newsgroup.
11944     (when gnus-newsgroup-headers
11945       (setq gnus-newsgroup-begin
11946             (mail-header-number (car gnus-newsgroup-headers))
11947             gnus-newsgroup-end
11948             (mail-header-number
11949              (gnus-last-element gnus-newsgroup-headers))))
11950     (when gnus-use-scoring
11951       (gnus-possibly-score-headers))))
11952
11953 (defun gnus-summary-insert-old-articles (&optional all)
11954   "Insert all old articles in this group.
11955 If ALL is non-nil, already read articles become readable.
11956 If ALL is a number, fetch this number of articles."
11957   (interactive "P")
11958   (prog1
11959       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11960             older len)
11961         (setq older
11962               ;; Some nntp servers lie about their active range.  When
11963               ;; this happens, the active range can be in the millions.
11964               ;; Use a compressed range to avoid creating a huge list.
11965               (gnus-range-difference (list gnus-newsgroup-active) old))
11966         (setq len (gnus-range-length older))
11967         (cond
11968          ((null older) nil)
11969          ((numberp all)
11970           (if (< all len)
11971               (let ((older-range (nreverse older)))
11972                 (setq older nil)
11973
11974                 (while (> all 0)
11975                   (let* ((r (pop older-range))
11976                          (min (if (numberp r) r (car r)))
11977                          (max (if (numberp r) r (cdr r))))
11978                     (while (and (<= min max)
11979                                 (> all 0))
11980                       (push max older)
11981                       (setq all (1- all)
11982                             max (1- max))))))
11983             (setq older (gnus-uncompress-range older))))
11984          (all
11985           (setq older (gnus-uncompress-range older)))
11986          (t
11987           (when (and (numberp gnus-large-newsgroup)
11988                    (> len gnus-large-newsgroup))
11989               (let* ((cursor-in-echo-area nil)
11990                      (initial (gnus-parameter-large-newsgroup-initial
11991                                gnus-newsgroup-name))
11992                      (input
11993                       (read-string
11994                        (format
11995                         "How many articles from %s (%s %d): "
11996                         (gnus-limit-string
11997                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11998                         (if initial "max" "default")
11999                         len)
12000                        (if initial
12001                            (cons (number-to-string initial)
12002                                  0)))))
12003                 (unless (string-match "^[ \t]*$" input)
12004                   (setq all (string-to-number input))
12005                   (if (< all len)
12006                       (let ((older-range (nreverse older)))
12007                         (setq older nil)
12008
12009                         (while (> all 0)
12010                           (let* ((r (pop older-range))
12011                                  (min (if (numberp r) r (car r)))
12012                                  (max (if (numberp r) r (cdr r))))
12013                             (while (and (<= min max)
12014                                         (> all 0))
12015                               (push max older)
12016                               (setq all (1- all)
12017                                     max (1- max))))))))))
12018           (setq older (gnus-uncompress-range older))))
12019         (if (not older)
12020             (message "No old news.")
12021           (gnus-summary-insert-articles older)
12022           (gnus-summary-limit (gnus-sorted-nunion old older))))
12023     (gnus-summary-position-point)))
12024
12025 (defun gnus-summary-insert-new-articles ()
12026   "Insert all new articles in this group."
12027   (interactive)
12028   (prog1
12029       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12030             (old-active gnus-newsgroup-active)
12031             (nnmail-fetched-sources (list t))
12032             i new)
12033         (setq gnus-newsgroup-active
12034               (gnus-activate-group gnus-newsgroup-name 'scan))
12035         (setq i (cdr gnus-newsgroup-active))
12036         (while (> i (cdr old-active))
12037           (push i new)
12038           (decf i))
12039         (if (not new)
12040             (message "No gnus is bad news")
12041           (gnus-summary-insert-articles new)
12042           (setq gnus-newsgroup-unreads
12043                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12044           (gnus-summary-limit (gnus-sorted-nunion old new))))
12045     (gnus-summary-position-point)))
12046
12047 (gnus-summary-make-all-marking-commands)
12048
12049 (gnus-ems-redefine)
12050
12051 (provide 'gnus-sum)
12052
12053 (run-hooks 'gnus-sum-load-hook)
12054
12055 ;; Local Variables:
12056 ;; coding: iso-8859-1
12057 ;; End:
12058
12059 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12060 ;;; gnus-sum.el ends here