Synch with Oort Gnus.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
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 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify" 
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61
62 (defcustom gnus-kill-summary-on-exit t
63   "*If non-nil, kill the summary buffer when you exit from it.
64 If nil, the summary will become a \"*Dead Summary*\" buffer, and
65 it will be killed sometime later."
66   :group 'gnus-summary-exit
67   :type 'boolean)
68
69 (defcustom gnus-fetch-old-headers nil
70   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
71 If an unread article in the group refers to an older, already read (or
72 just marked as read) article, the old article will not normally be
73 displayed in the Summary buffer.  If this variable is non-nil, Gnus
74 will attempt to grab the headers to the old articles, and thereby
75 build complete threads.  If it has the value `some', only enough
76 headers to connect otherwise loose threads will be displayed.  This
77 variable can also be a number.  In that case, no more than that number
78 of old headers will be fetched.  If it has the value `invisible', all
79 old headers will be fetched, but none will be displayed.
80
81 The server has to support NOV for any of this to work."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const some)
85                  number
86                  (sexp :menu-tag "other" t)))
87
88 (defcustom gnus-refer-thread-limit 200
89   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
90 If t, fetch all the available old headers."
91   :group 'gnus-thread
92   :type '(choice number
93                  (sexp :menu-tag "other" t)))
94
95 (defcustom gnus-summary-make-false-root 'adopt
96   "*nil means that Gnus won't gather loose threads.
97 If the root of a thread has expired or been read in a previous
98 session, the information necessary to build a complete thread has been
99 lost.  Instead of having many small sub-threads from this original thread
100 scattered all over the summary buffer, Gnus can gather them.
101
102 If non-nil, Gnus will try to gather all loose sub-threads from an
103 original thread into one large thread.
104
105 If this variable is non-nil, it should be one of `none', `adopt',
106 `dummy' or `empty'.
107
108 If this variable is `none', Gnus will not make a false root, but just
109 present the sub-threads after another.
110 If this variable is `dummy', Gnus will create a dummy root that will
111 have all the sub-threads as children.
112 If this variable is `adopt', Gnus will make one of the \"children\"
113 the parent and mark all the step-children as such.
114 If this variable is `empty', the \"children\" are printed with empty
115 subject fields.  (Or rather, they will be printed with a string
116 given by the `gnus-summary-same-subject' variable.)"
117   :group 'gnus-thread
118   :type '(choice (const :tag "off" nil)
119                  (const none)
120                  (const dummy)
121                  (const adopt)
122                  (const empty)))
123
124 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
125   "*A regexp to match subjects to be excluded from loose thread gathering.
126 As loose thread gathering is done on subjects only, that means that
127 there can be many false gatherings performed.  By rooting out certain
128 common subjects, gathering might become saner."
129   :group 'gnus-thread
130   :type 'regexp)
131
132 (defcustom gnus-summary-gather-subject-limit nil
133   "*Maximum length of subject comparisons when gathering loose threads.
134 Use nil to compare full subjects.  Setting this variable to a low
135 number will help gather threads that have been corrupted by
136 newsreaders chopping off subject lines, but it might also mean that
137 unrelated articles that have subject that happen to begin with the
138 same few characters will be incorrectly gathered.
139
140 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
141 comparing subjects."
142   :group 'gnus-thread
143   :type '(choice (const :tag "off" nil)
144                  (const fuzzy)
145                  (sexp :menu-tag "on" t)))
146
147 (defcustom gnus-simplify-subject-functions nil
148   "List of functions taking a string argument that simplify subjects.
149 The functions are applied recursively.
150
151 Useful functions to put in this list include: `gnus-simplify-subject-re',
152 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
153   :group 'gnus-thread
154   :type '(repeat function))
155
156 (defcustom gnus-simplify-ignored-prefixes nil
157   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  regexp))
161
162 (defcustom gnus-build-sparse-threads nil
163   "*If non-nil, fill in the gaps in threads.
164 If `some', only fill in the gaps that are needed to tie loose threads
165 together.  If `more', fill in all leaf nodes that Gnus can find.  If
166 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  (const some)
170                  (const more)
171                  (sexp :menu-tag "all" t)))
172
173 (defcustom gnus-summary-thread-gathering-function
174   'gnus-gather-threads-by-subject
175   "*Function used for gathering loose threads.
176 There are two pre-defined functions: `gnus-gather-threads-by-subject',
177 which only takes Subjects into consideration; and
178 `gnus-gather-threads-by-references', which compared the References
179 headers of the articles to find matches."
180   :group 'gnus-thread
181   :type '(radio (function-item gnus-gather-threads-by-subject)
182                 (function-item gnus-gather-threads-by-references)
183                 (function :tag "other")))
184
185 (defcustom gnus-summary-same-subject ""
186   "*String indicating that the current article has the same subject as the previous.
187 This variable will only be used if the value of
188 `gnus-summary-make-false-root' is `empty'."
189   :group 'gnus-summary-format
190   :type 'string)
191
192 (defcustom gnus-summary-goto-unread t
193   "*If t, many commands will go to the next unread article.
194 This applies to marking commands as well as other commands that
195 \"naturally\" select the next article, like, for instance, `SPC' at
196 the end of an article.
197
198 If nil, the marking commands do NOT go to the next unread article
199 (they go to the next article instead).  If `never', commands that
200 usually go to the next unread article, will go to the next article,
201 whether it is read or not."
202   :group 'gnus-summary-marks
203   :link '(custom-manual "(gnus)Setting Marks")
204   :type '(choice (const :tag "off" nil)
205                  (const never)
206                  (sexp :menu-tag "on" t)))
207
208 (defcustom gnus-summary-default-score 0
209   "*Default article score level.
210 All scores generated by the score files will be added to this score.
211 If this variable is nil, scoring will be disabled."
212   :group 'gnus-score-default
213   :type '(choice (const :tag "disable")
214                  integer))
215
216 (defcustom gnus-summary-default-high-score 0
217   "*Default threshold for a high scored article.
218 An article will be highlighted as high scored if its score is greater
219 than this score."
220   :group 'gnus-score-default
221   :type 'integer)
222
223 (defcustom gnus-summary-default-low-score 0
224   "*Default threshold for a low scored article.
225 An article will be highlighted as low scored if its score is smaller
226 than this score."
227   :group 'gnus-score-default
228   :type 'integer)
229
230 (defcustom gnus-summary-zcore-fuzz 0
231   "*Fuzziness factor for the zcore in the summary buffer.
232 Articles with scores closer than this to `gnus-summary-default-score'
233 will not be marked."
234   :group 'gnus-summary-format
235   :type 'integer)
236
237 (defcustom gnus-simplify-subject-fuzzy-regexp nil
238   "*Strings to be removed when doing fuzzy matches.
239 This can either be a regular expression or list of regular expressions
240 that will be removed from subject strings if fuzzy subject
241 simplification is selected."
242   :group 'gnus-thread
243   :type '(repeat regexp))
244
245 (defcustom gnus-show-threads t
246   "*If non-nil, display threads in summary mode."
247   :group 'gnus-thread
248   :type 'boolean)
249
250 (defcustom gnus-thread-hide-subtree nil
251   "*If non-nil, hide all threads initially.
252 This can be a predicate specifier which says which threads to hide.
253 If threads are hidden, you have to run the command
254 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
255 to expose hidden threads."
256   :group 'gnus-thread
257   :type 'boolean)
258
259 (defcustom gnus-thread-hide-killed t
260   "*If non-nil, hide killed threads automatically."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-ignore-subject t
265   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
266 If nil, articles that have different subjects from their parents will
267 start separate threads."
268   :group 'gnus-thread
269   :type 'boolean)
270
271 (defcustom gnus-thread-operation-ignore-subject t
272   "*If non-nil, subjects will be ignored when doing thread commands.
273 This affects commands like `gnus-summary-kill-thread' and
274 `gnus-summary-lower-thread'.
275
276 If this variable is nil, articles in the same thread with different
277 subjects will not be included in the operation in question.  If this
278 variable is `fuzzy', only articles that have subjects that are fuzzily
279 equal will be included."
280   :group 'gnus-thread
281   :type '(choice (const :tag "off" nil)
282                  (const fuzzy)
283                  (sexp :tag "on" t)))
284
285 (defcustom gnus-thread-indent-level 4
286   "*Number that says how much each sub-thread should be indented."
287   :group 'gnus-thread
288   :type 'integer)
289
290 (defcustom gnus-auto-extend-newsgroup t
291   "*If non-nil, extend newsgroup forward and backward when requested."
292   :group 'gnus-summary-choose
293   :type 'boolean)
294
295 (defcustom gnus-auto-select-first t
296   "*If non-nil, select the article under point.
297 Which article this is is controlled by the `gnus-auto-select-subject'
298 variable.
299
300 If you want to prevent automatic selection of articles in some
301 newsgroups, set the variable to nil in `gnus-select-group-hook'."
302   :group 'gnus-group-select
303   :type '(choice (const :tag "none" nil)
304                  (sexp :menu-tag "first" t)))
305
306 (defcustom gnus-auto-select-subject 'unread
307   "*Says what subject to place under point when entering a group.
308
309 This variable can either be the symbols `first' (place point on the
310 first subject), `unread' (place point on the subject line of the first
311 unread article), `best' (place point on the subject line of the
312 higest-scored article), `unseen' (place point on the subject line of
313 the first unseen article), 'unseen-or-unread' (place point on the subject
314 line of the first unseen article or, if all article have been seen, on the
315 subject line of the first unread article), or a function to be called to
316 place point on some subject line."
317   :group 'gnus-group-select
318   :type '(choice (const best)
319                  (const unread)
320                  (const first)
321                  (const unseen)
322                  (const unseen-or-unread)))
323
324 (defcustom gnus-dont-select-after-jump-to-other-group nil
325   "If non-nil, don't select the first unread article after entering the
326 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
327 it is depend on the value of `gnus-auto-select-first' whether to select
328 or not."
329   :group 'gnus-group-select
330   :type 'boolean)
331
332 (defcustom gnus-auto-select-next t
333   "*If non-nil, offer to go to the next group from the end of the previous.
334 If the value is t and the next newsgroup is empty, Gnus will exit
335 summary mode and go back to group mode.  If the value is neither nil
336 nor t, Gnus will select the following unread newsgroup.  In
337 particular, if the value is the symbol `quietly', the next unread
338 newsgroup will be selected without any confirmation, and if it is
339 `almost-quietly', the next group will be selected without any
340 confirmation if you are located on the last article in the group.
341 Finally, if this variable is `slightly-quietly', the `Z n' command
342 will go to the next group without confirmation."
343   :group 'gnus-summary-maneuvering
344   :type '(choice (const :tag "off" nil)
345                  (const quietly)
346                  (const almost-quietly)
347                  (const slightly-quietly)
348                  (sexp :menu-tag "on" t)))
349
350 (defcustom gnus-auto-select-same nil
351   "*If non-nil, select the next article with the same subject.
352 If there are no more articles with the same subject, go to
353 the first unread article."
354   :group 'gnus-summary-maneuvering
355   :type 'boolean)
356
357 (defcustom gnus-summary-check-current nil
358   "*If non-nil, consider the current article when moving.
359 The \"unread\" movement commands will stay on the same line if the
360 current article is unread."
361   :group 'gnus-summary-maneuvering
362   :type 'boolean)
363
364 (defcustom gnus-auto-center-summary t
365   "*If non-nil, always center the current summary buffer.
366 In particular, if `vertical' do only vertical recentering.  If non-nil
367 and non-`vertical', do both horizontal and vertical recentering."
368   :group 'gnus-summary-maneuvering
369   :type '(choice (const :tag "none" nil)
370                  (const vertical)
371                  (integer :tag "height")
372                  (sexp :menu-tag "both" t)))
373
374 (defcustom gnus-show-all-headers nil
375   "*If non-nil, don't hide any headers."
376   :group 'gnus-article-hiding
377   :group 'gnus-article-headers
378   :type 'boolean)
379
380 (defcustom gnus-summary-ignore-duplicates nil
381   "*If non-nil, ignore articles with identical Message-ID headers."
382   :group 'gnus-summary
383   :type 'boolean)
384
385 (defcustom gnus-single-article-buffer t
386   "*If non-nil, display all articles in the same buffer.
387 If nil, each group will get its own article buffer."
388   :group 'gnus-article-various
389   :type 'boolean)
390
391 (defcustom gnus-break-pages t
392   "*If non-nil, do page breaking on articles.
393 The page delimiter is specified by the `gnus-page-delimiter'
394 variable."
395   :group 'gnus-article-various
396   :type 'boolean)
397
398 (defcustom gnus-show-mime t
399   "*If non-nil, do mime processing of articles.
400 The articles will simply be fed to the function given by
401 `gnus-article-display-method-for-mime'."
402   :group 'gnus-article-mime
403   :type 'boolean)
404
405 (defcustom gnus-move-split-methods nil
406   "*Variable used to suggest where articles are to be moved to.
407 It uses the same syntax as the `gnus-split-methods' variable.
408 However, whereas `gnus-split-methods' specifies file names as targets,
409 this variable specifies group names."
410   :group 'gnus-summary-mail
411   :type '(repeat (choice (list :value (fun) function)
412                          (cons :value ("" "") regexp (repeat string))
413                          (sexp :value nil))))
414
415 (defcustom gnus-unread-mark ?\ ;;;Whitespace
416   "*Mark used for unread articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-ticked-mark ?!
421   "*Mark used for ticked articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-dormant-mark ??
426   "*Mark used for dormant articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-del-mark ?r
431   "*Mark used for del'd articles."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-read-mark ?R
436   "*Mark used for read articles."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-expirable-mark ?E
441   "*Mark used for expirable articles."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-killed-mark ?K
446   "*Mark used for killed articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-souped-mark ?F
451   "*Mark used for souped articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-kill-file-mark ?X
456   "*Mark used for articles killed by kill files."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-low-score-mark ?Y
461   "*Mark used for articles with a low score."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-catchup-mark ?C
466   "*Mark used for articles that are caught up."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-replied-mark ?A
471   "*Mark used for articles that have been replied to."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-forwarded-mark ?F
476   "*Mark used for articles that have been forwarded."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-recent-mark ?N
481   "*Mark used for articles that are recent."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-cached-mark ?*
486   "*Mark used for articles that are in the cache."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-saved-mark ?S
491   "*Mark used for articles that have been saved."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-unseen-mark ?.
496   "*Mark used for articles that haven't been seen."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-no-mark ?\ ;;;Whitespace
501   "*Mark used for articles that have no other secondary mark."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-ancient-mark ?O
506   "*Mark used for ancient articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-sparse-mark ?Q
511   "*Mark used for sparsely reffed articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-canceled-mark ?G
516   "*Mark used for canceled articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-duplicate-mark ?M
521   "*Mark used for duplicate articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-undownloaded-mark ?@
526   "*Mark used for articles that weren't downloaded."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-downloadable-mark ?%
531   "*Mark used for articles that are to be downloaded."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unsendable-mark ?=
536   "*Mark used for articles that won't be sent."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-score-over-mark ?+
541   "*Score mark used for articles with high scores."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-score-below-mark ?-
546   "*Score mark used for articles with low scores."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
551   "*There is no thread under the article."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-not-empty-thread-mark ?=
556   "*There is a thread under the article."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-view-pseudo-asynchronously nil
561   "*If non-nil, Gnus will view pseudo-articles asynchronously."
562   :group 'gnus-extract-view
563   :type 'boolean)
564
565 (defcustom gnus-auto-expirable-marks
566   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
567         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
568         gnus-souped-mark gnus-duplicate-mark)
569   "*The list of marks converted into expiration if a group is auto-expirable."
570   :version "21.1"
571   :group 'gnus-summary
572   :type '(repeat character))
573
574 (defcustom gnus-inhibit-user-auto-expire t
575   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
576   :version "21.1"
577   :group 'gnus-summary
578   :type 'boolean)
579
580 (defcustom gnus-view-pseudos nil
581   "*If `automatic', pseudo-articles will be viewed automatically.
582 If `not-confirm', pseudos will be viewed automatically, and the user
583 will not be asked to confirm the command."
584   :group 'gnus-extract-view
585   :type '(choice (const :tag "off" nil)
586                  (const automatic)
587                  (const not-confirm)))
588
589 (defcustom gnus-view-pseudos-separately t
590   "*If non-nil, one pseudo-article will be created for each file to be viewed.
591 If nil, all files that use the same viewing command will be given as a
592 list of parameters to that command."
593   :group 'gnus-extract-view
594   :type 'boolean)
595
596 (defcustom gnus-insert-pseudo-articles t
597   "*If non-nil, insert pseudo-articles when decoding articles."
598   :group 'gnus-extract-view
599   :type 'boolean)
600
601 (defcustom gnus-summary-dummy-line-format
602   "  %(:                          :%) %S\n"
603   "*The format specification for the dummy roots in the summary buffer.
604 It works along the same lines as a normal formatting string,
605 with some simple extensions.
606
607 %S  The subject
608
609 General format specifiers can also be used.
610 See `(gnus)Formatting Variables'."
611   :link '(custom-manual "(gnus)Formatting Variables")
612   :group 'gnus-threading
613   :type 'string)
614
615 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
616   "*The format specification for the summary mode line.
617 It works along the same lines as a normal formatting string,
618 with some simple extensions:
619
620 %G  Group name
621 %p  Unprefixed group name
622 %A  Current article number
623 %z  Current article score
624 %V  Gnus version
625 %U  Number of unread articles in the group
626 %e  Number of unselected articles in the group
627 %Z  A string with unread/unselected article counts
628 %g  Shortish group name
629 %S  Subject of the current article
630 %u  User-defined spec
631 %s  Current score file name
632 %d  Number of dormant articles
633 %r  Number of articles that have been marked as read in this session
634 %E  Number of articles expunged by the score files"
635   :group 'gnus-summary-format
636   :type 'string)
637
638 (defcustom gnus-list-identifiers nil
639   "Regexp that matches list identifiers to be removed from subject.
640 This can also be a list of regexps."
641   :version "21.1"
642   :group 'gnus-summary-format
643   :group 'gnus-article-hiding
644   :type '(choice (const :tag "none" nil)
645                  (regexp :value ".*")
646                  (repeat :value (".*") regexp)))
647
648 (defcustom gnus-summary-mark-below 0
649   "*Mark all articles with a score below this variable as read.
650 This variable is local to each summary buffer and usually set by the
651 score file."
652   :group 'gnus-score-default
653   :type 'integer)
654
655 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
656   "*List of functions used for sorting articles in the summary buffer.
657
658 Each function takes two articles and returns non-nil if the first
659 article should be sorted before the other.  If you use more than one
660 function, the primary sort function should be the last.  You should
661 probably always include `gnus-article-sort-by-number' in the list of
662 sorting functions -- preferably first.  Also note that sorting by date
663 is often much slower than sorting by number, and the sorting order is
664 very similar.  (Sorting by date means sorting by the time the message
665 was sent, sorting by number means sorting by arrival time.)
666
667 Ready-made functions include `gnus-article-sort-by-number',
668 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
669 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
670
671 When threading is turned on, the variable `gnus-thread-sort-functions'
672 controls how articles are sorted."
673   :group 'gnus-summary-sort
674   :type '(repeat (choice (function-item gnus-article-sort-by-number)
675                          (function-item gnus-article-sort-by-author)
676                          (function-item gnus-article-sort-by-subject)
677                          (function-item gnus-article-sort-by-date)
678                          (function-item gnus-article-sort-by-score)
679                          (function :tag "other"))))
680
681 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
682   "*List of functions used for sorting threads in the summary buffer.
683 By default, threads are sorted by article number.
684
685 Each function takes two threads and returns non-nil if the first
686 thread should be sorted before the other.  If you use more than one
687 function, the primary sort function should be the last.  You should
688 probably always include `gnus-thread-sort-by-number' in the list of
689 sorting functions -- preferably first.  Also note that sorting by date
690 is often much slower than sorting by number, and the sorting order is
691 very similar.  (Sorting by date means sorting by the time the message
692 was sent, sorting by number means sorting by arrival time.)
693
694 Ready-made functions include `gnus-thread-sort-by-number',
695 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
696 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
697 `gnus-thread-sort-by-most-recent-number',
698 `gnus-thread-sort-by-most-recent-date', and
699 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
700
701 When threading is turned off, the variable
702 `gnus-article-sort-functions' controls how articles are sorted."
703   :group 'gnus-summary-sort
704   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
705                          (function-item gnus-thread-sort-by-author)
706                          (function-item gnus-thread-sort-by-subject)
707                          (function-item gnus-thread-sort-by-date)
708                          (function-item gnus-thread-sort-by-score)
709                          (function-item gnus-thread-sort-by-total-score)
710                          (function :tag "other"))))
711
712 (defcustom gnus-thread-score-function '+
713   "*Function used for calculating the total score of a thread.
714
715 The function is called with the scores of the article and each
716 subthread and should then return the score of the thread.
717
718 Some functions you can use are `+', `max', or `min'."
719   :group 'gnus-summary-sort
720   :type 'function)
721
722 (defcustom gnus-summary-expunge-below nil
723   "All articles that have a score less than this variable will be expunged.
724 This variable is local to the summary buffers."
725   :group 'gnus-score-default
726   :type '(choice (const :tag "off" nil)
727                  integer))
728
729 (defcustom gnus-thread-expunge-below nil
730   "All threads that have a total score less than this variable will be expunged.
731 See `gnus-thread-score-function' for en explanation of what a
732 \"thread score\" is.
733
734 This variable is local to the summary buffers."
735   :group 'gnus-threading
736   :group 'gnus-score-default
737   :type '(choice (const :tag "off" nil)
738                  integer))
739
740 (defcustom gnus-summary-mode-hook nil
741   "*A hook for Gnus summary mode.
742 This hook is run before any variables are set in the summary buffer."
743   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
744   :group 'gnus-summary-various
745   :type 'hook)
746
747 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
748 (when (featurep 'xemacs)
749   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
750   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
751   (add-hook 'gnus-summary-mode-hook
752             'gnus-xmas-switch-horizontal-scrollbar-off))
753
754 (defcustom gnus-summary-menu-hook nil
755   "*Hook run after the creation of the summary mode menu."
756   :group 'gnus-summary-visual
757   :type 'hook)
758
759 (defcustom gnus-summary-exit-hook nil
760   "*A hook called on exit from the summary buffer.
761 It will be called with point in the group buffer."
762   :group 'gnus-summary-exit
763   :type 'hook)
764
765 (defcustom gnus-summary-prepare-hook nil
766   "*A hook called after the summary buffer has been generated.
767 If you want to modify the summary buffer, you can use this hook."
768   :group 'gnus-summary-various
769   :type 'hook)
770
771 (defcustom gnus-summary-prepared-hook nil
772   "*A hook called as the last thing after the summary buffer has been generated."
773   :group 'gnus-summary-various
774   :type 'hook)
775
776 (defcustom gnus-summary-generate-hook nil
777   "*A hook run just before generating the summary buffer.
778 This hook is commonly used to customize threading variables and the
779 like."
780   :group 'gnus-summary-various
781   :type 'hook)
782
783 (defcustom gnus-select-group-hook nil
784   "*A hook called when a newsgroup is selected.
785
786 If you'd like to simplify subjects like the
787 `gnus-summary-next-same-subject' command does, you can use the
788 following hook:
789
790  (add-hook gnus-select-group-hook
791            (lambda ()
792              (mapcar (lambda (header)
793                        (mail-header-set-subject
794                         header
795                         (gnus-simplify-subject
796                          (mail-header-subject header) 're-only)))
797                      gnus-newsgroup-headers)))"
798   :group 'gnus-group-select
799   :type 'hook)
800
801 (defcustom gnus-select-article-hook nil
802   "*A hook called when an article is selected."
803   :group 'gnus-summary-choose
804   :type 'hook)
805
806 (defcustom gnus-visual-mark-article-hook
807   (list 'gnus-highlight-selected-summary)
808   "*Hook run after selecting an article in the summary buffer.
809 It is meant to be used for highlighting the article in some way.  It
810 is not run if `gnus-visual' is nil."
811   :group 'gnus-summary-visual
812   :type 'hook)
813
814 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
815   "*A hook called before parsing the headers."
816   :group 'gnus-various
817   :type 'hook)
818
819 (defcustom gnus-exit-group-hook nil
820   "*A hook called when exiting summary mode.
821 This hook is not called from the non-updating exit commands like `Q'."
822   :group 'gnus-various
823   :type 'hook)
824
825 (defcustom gnus-summary-update-hook
826   (list 'gnus-summary-highlight-line)
827   "*A hook called when a summary line is changed.
828 The hook will not be called if `gnus-visual' is nil.
829
830 The default function `gnus-summary-highlight-line' will
831 highlight the line according to the `gnus-summary-highlight'
832 variable."
833   :group 'gnus-summary-visual
834   :type 'hook)
835
836 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
837   "*A hook called when an article is selected for the first time.
838 The hook is intended to mark an article as read (or unread)
839 automatically when it is selected."
840   :group 'gnus-summary-choose
841   :type 'hook)
842
843 (defcustom gnus-group-no-more-groups-hook nil
844   "*A hook run when returning to group mode having no more (unread) groups."
845   :group 'gnus-group-select
846   :type 'hook)
847
848 (defcustom gnus-ps-print-hook nil
849   "*A hook run before ps-printing something from Gnus."
850   :group 'gnus-summary
851   :type 'hook)
852
853 (defcustom gnus-summary-display-arrow
854   (and (fboundp 'display-graphic-p)
855        (display-graphic-p))
856   "*If non-nil, display an arrow highlighting the current article."
857   :version "21.1"
858   :group 'gnus-summary
859   :type 'boolean)
860
861 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
862   "Face used for highlighting the current article in the summary buffer."
863   :group 'gnus-summary-visual
864   :type 'face)
865
866 (defcustom gnus-summary-highlight
867   '(((eq mark gnus-canceled-mark)
868      . gnus-summary-cancelled-face)
869     ((and (> score default-high)
870           (or (eq mark gnus-dormant-mark)
871               (eq mark gnus-ticked-mark)))
872      . gnus-summary-high-ticked-face)
873     ((and (< score default-low)
874           (or (eq mark gnus-dormant-mark)
875               (eq mark gnus-ticked-mark)))
876      . gnus-summary-low-ticked-face)
877     ((or (eq mark gnus-dormant-mark)
878          (eq mark gnus-ticked-mark))
879      . gnus-summary-normal-ticked-face)
880     ((and (> score default-high) (eq mark gnus-ancient-mark))
881      . gnus-summary-high-ancient-face)
882     ((and (< score default-low) (eq mark gnus-ancient-mark))
883      . gnus-summary-low-ancient-face)
884     ((eq mark gnus-ancient-mark)
885      . gnus-summary-normal-ancient-face)
886     ((and (> score default-high) (eq mark gnus-unread-mark))
887      . gnus-summary-high-unread-face)
888     ((and (< score default-low) (eq mark gnus-unread-mark))
889      . gnus-summary-low-unread-face)
890     ((eq mark gnus-unread-mark)
891      . gnus-summary-normal-unread-face)
892     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
893                                                   gnus-undownloaded-mark)))
894      . gnus-summary-high-unread-face)
895     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
896                                                  gnus-undownloaded-mark)))
897      . gnus-summary-low-unread-face)
898     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
899           (memq article gnus-newsgroup-unreads))
900      . gnus-summary-normal-unread-face)
901     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
902      . gnus-summary-normal-read-face)
903     ((> score default-high)
904      . gnus-summary-high-read-face)
905     ((< score default-low)
906      . gnus-summary-low-read-face)
907     (t
908      . gnus-summary-normal-read-face))
909   "*Controls the highlighting of summary buffer lines.
910
911 A list of (FORM . FACE) pairs.  When deciding how a a particular
912 summary line should be displayed, each form is evaluated.  The content
913 of the face field after the first true form is used.  You can change
914 how those summary lines are displayed, by editing the face field.
915
916 You can use the following variables in the FORM field.
917
918 score:        The article's score
919 default:      The default article score.
920 default-high: The default score for high scored articles.
921 default-low:  The default score for low scored articles.
922 below:        The score below which articles are automatically marked as read.
923 mark:         The articles mark."
924   :group 'gnus-summary-visual
925   :type '(repeat (cons (sexp :tag "Form" nil)
926                        face)))
927
928 (defcustom gnus-alter-header-function nil
929   "Function called to allow alteration of article header structures.
930 The function is called with one parameter, the article header vector,
931 which it may alter in any way.")
932
933 (defvar gnus-decode-encoded-word-function
934   (mime-find-field-decoder 'From 'nov)
935   "Variable that says which function should be used to decode a string with encoded words.")
936
937 (defcustom gnus-extra-headers '(To Newsgroups)
938   "*Extra headers to parse."
939   :version "21.1"
940   :group 'gnus-summary
941   :type '(repeat symbol))
942
943 (defcustom gnus-ignored-from-addresses
944   (and user-mail-address (regexp-quote user-mail-address))
945   "*Regexp of From headers that may be suppressed in favor of To headers."
946   :version "21.1"
947   :group 'gnus-summary
948   :type 'regexp)
949
950 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
951   "List of charsets that should be ignored.
952 When these charsets are used in the \"charset\" parameter, the
953 default charset will be used instead."
954   :version "21.1"
955   :type '(repeat symbol)
956   :group 'gnus-charset)
957
958 (gnus-define-group-parameter
959  ignored-charsets
960  :type list
961  :function-document
962  "Return the ignored charsets of GROUP."
963  :variable gnus-group-ignored-charsets-alist
964  :variable-default
965  '(("alt\\.chinese\\.text" iso-8859-1))
966  :variable-document
967  "Alist of regexps (to match group names) and charsets that should be ignored.
968 When these charsets are used in the \"charset\" parameter, the
969 default charset will be used instead."
970  :variable-group gnus-charset
971  :variable-type '(repeat (cons (regexp :tag "Group")
972                                (repeat symbol)))
973  :parameter-type '(choice :tag "Ignored charsets"
974                           :value nil
975                           (repeat (symbol)))
976  :parameter-document       "\
977 List of charsets that should be ignored.
978
979 When these charsets are used in the \"charset\" parameter, the
980 default charset will be used instead.")
981
982 (defcustom gnus-group-highlight-words-alist nil
983   "Alist of group regexps and highlight regexps.
984 This variable uses the same syntax as `gnus-emphasis-alist'."
985   :version "21.1"
986   :type '(repeat (cons (regexp :tag "Group")
987                        (repeat (list (regexp :tag "Highlight regexp")
988                                      (number :tag "Group for entire word" 0)
989                                      (number :tag "Group for displayed part" 0)
990                                      (symbol :tag "Face"
991                                              gnus-emphasis-highlight-words)))))
992   :group 'gnus-summary-visual)
993
994 (defcustom gnus-use-wheel nil
995   "Use Intelli-mouse on summary movement"
996   :type 'boolean
997   :group 'gnus-summary-maneuvering)
998
999 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1000   "Amount to scroll messages by spinning the mouse wheel.
1001 This is actually a cons cell, where the first item is the amount to scroll
1002 on a normal wheel event, and the second is the amount to scroll when the
1003 wheel is moved with the shift key depressed."
1004   :type '(cons (integer :tag "Shift") integer)
1005   :group 'gnus-summary-maneuvering)
1006
1007 (defcustom gnus-wheel-edge-resistance 2
1008   "How hard it should be to change the current article
1009 by moving the mouse over the edge of the article window."
1010   :type 'integer
1011   :group 'gnus-summary-maneuvering)
1012
1013 (defcustom gnus-summary-show-article-charset-alist
1014   nil
1015   "Alist of number and charset.
1016 The article will be shown with the charset corresponding to the
1017 numbered argument.
1018 For example: ((1 . cn-gb-2312) (2 . big5))."
1019   :version "21.1"
1020   :type '(repeat (cons (number :tag "Argument" 1)
1021                        (symbol :tag "Charset")))
1022   :group 'gnus-charset)
1023
1024 (defcustom gnus-preserve-marks t
1025   "Whether marks are preserved when moving, copying and respooling messages."
1026   :version "21.1"
1027   :type 'boolean
1028   :group 'gnus-summary-marks)
1029
1030 (defcustom gnus-alter-articles-to-read-function nil
1031   "Function to be called to alter the list of articles to be selected."
1032   :type '(choice (const nil) function)
1033   :group 'gnus-summary)
1034
1035 (defcustom gnus-orphan-score nil
1036   "*All orphans get this score added.  Set in the score file."
1037   :group 'gnus-score-default
1038   :type '(choice (const nil)
1039                  integer))
1040
1041 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1042   "*A regexp to match MIME parts when saving multiple parts of a message
1043 with gnus-summary-save-parts (X m). This regexp will be used by default
1044 when prompting the user for which type of files to save."
1045   :group 'gnus-summary
1046   :type 'regexp)
1047
1048 (defcustom gnus-read-all-available-headers nil
1049   "Whether Gnus should parse all headers made available to it.
1050 This is mostly relevant for slow backends where the user may
1051 wish to widen the summary buffer to include all headers
1052 that were fetched.  Say, for nnultimate groups."
1053   :group 'gnus-summary
1054   :type '(choice boolean regexp))
1055
1056 (defcustom gnus-summary-muttprint-program "muttprint"
1057   "Command (and optional arguments) used to run Muttprint."
1058   :version "21.3"
1059   :group 'gnus-summary
1060   :type 'string)
1061
1062 (defcustom gnus-article-loose-mime nil
1063   "If non-nil, don't require MIME-Version header.
1064 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1065 supply the MIME-Version header or deliberately strip it From the mail.
1066 Set it to non-nil, Gnus will treat some articles as MIME even if
1067 the MIME-Version header is missed."
1068   :version "21.3"
1069   :type 'boolean
1070   :group 'gnus-article)
1071
1072 ;;; Internal variables
1073
1074 (defvar gnus-summary-display-cache nil)
1075 (defvar gnus-article-mime-handles nil)
1076 (defvar gnus-article-decoded-p nil)
1077 (defvar gnus-article-charset nil)
1078 (defvar gnus-article-ignored-charsets nil)
1079 (defvar gnus-scores-exclude-files nil)
1080 (defvar gnus-page-broken nil)
1081 (defvar gnus-inhibit-mime-unbuttonizing nil)
1082
1083 (defvar gnus-original-article nil)
1084 (defvar gnus-article-internal-prepare-hook nil)
1085 (defvar gnus-newsgroup-process-stack nil)
1086
1087 (defvar gnus-thread-indent-array nil)
1088 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1089 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1090   "Function called to sort the articles within a thread after it has been gathered together.")
1091
1092 (defvar gnus-summary-save-parts-type-history nil)
1093 (defvar gnus-summary-save-parts-last-directory nil)
1094
1095 ;; Avoid highlighting in kill files.
1096 (defvar gnus-summary-inhibit-highlight nil)
1097 (defvar gnus-newsgroup-selected-overlay nil)
1098 (defvar gnus-inhibit-limiting nil)
1099 (defvar gnus-newsgroup-adaptive-score-file nil)
1100 (defvar gnus-current-score-file nil)
1101 (defvar gnus-current-move-group nil)
1102 (defvar gnus-current-copy-group nil)
1103 (defvar gnus-current-crosspost-group nil)
1104 (defvar gnus-newsgroup-display nil)
1105
1106 (defvar gnus-newsgroup-dependencies nil)
1107 (defvar gnus-newsgroup-adaptive nil)
1108 (defvar gnus-summary-display-article-function nil)
1109 (defvar gnus-summary-highlight-line-function nil
1110   "Function called after highlighting a summary line.")
1111
1112 (defvar gnus-summary-line-format-alist
1113   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1114     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1115     (?s gnus-tmp-subject-or-nil ?s)
1116     (?n gnus-tmp-name ?s)
1117     (?A (std11-address-string
1118          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1119     (?a (or (std11-full-name-string
1120              (car (mime-entity-read-field gnus-tmp-header 'From)))
1121             gnus-tmp-from) ?s)
1122     (?F gnus-tmp-from ?s)
1123     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1124     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1125     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1126     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1127     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1128     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1129     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1130     (?L gnus-tmp-lines ?s)
1131     (?I gnus-tmp-indentation ?s)
1132     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1133     (?R gnus-tmp-replied ?c)
1134     (?\[ gnus-tmp-opening-bracket ?c)
1135     (?\] gnus-tmp-closing-bracket ?c)
1136     (?\> (make-string gnus-tmp-level ? ) ?s)
1137     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1138     (?i gnus-tmp-score ?d)
1139     (?z gnus-tmp-score-char ?c)
1140     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1141     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1142     (?U gnus-tmp-unread ?c)
1143     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1144         ?s)
1145     (?t (gnus-summary-number-of-articles-in-thread
1146          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1147         ?d)
1148     (?e (gnus-summary-number-of-articles-in-thread
1149          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1150         ?c)
1151     (?u gnus-tmp-user-defined ?s)
1152     (?P (gnus-pick-line-number) ?d)
1153     (?B gnus-tmp-thread-tree-header-string ?s)
1154     (user-date (gnus-user-date
1155                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1156   "An alist of format specifications that can appear in summary lines.
1157 These are paired with what variables they correspond with, along with
1158 the type of the variable (string, integer, character, etc).")
1159
1160 (defvar gnus-summary-dummy-line-format-alist
1161   `((?S gnus-tmp-subject ?s)
1162     (?N gnus-tmp-number ?d)
1163     (?u gnus-tmp-user-defined ?s)))
1164
1165 (defvar gnus-summary-mode-line-format-alist
1166   `((?G gnus-tmp-group-name ?s)
1167     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1168     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1169     (?A gnus-tmp-article-number ?d)
1170     (?Z gnus-tmp-unread-and-unselected ?s)
1171     (?V gnus-version ?s)
1172     (?U gnus-tmp-unread-and-unticked ?d)
1173     (?S gnus-tmp-subject ?s)
1174     (?e gnus-tmp-unselected ?d)
1175     (?u gnus-tmp-user-defined ?s)
1176     (?d (length gnus-newsgroup-dormant) ?d)
1177     (?t (length gnus-newsgroup-marked) ?d)
1178     (?r (length gnus-newsgroup-reads) ?d)
1179     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1180     (?E gnus-newsgroup-expunged-tally ?d)
1181     (?s (gnus-current-score-file-nondirectory) ?s)))
1182
1183 (defvar gnus-last-search-regexp nil
1184   "Default regexp for article search command.")
1185
1186 (defvar gnus-summary-search-article-matched-data nil
1187   "Last matched data of article search command.  It is the local variable
1188 in `gnus-article-buffer' which consists of the list of start position,
1189 end position and text.")
1190
1191 (defvar gnus-last-shell-command nil
1192   "Default shell command on article.")
1193
1194 (defvar gnus-newsgroup-begin nil)
1195 (defvar gnus-newsgroup-end nil)
1196 (defvar gnus-newsgroup-last-rmail nil)
1197 (defvar gnus-newsgroup-last-mail nil)
1198 (defvar gnus-newsgroup-last-folder nil)
1199 (defvar gnus-newsgroup-last-file nil)
1200 (defvar gnus-newsgroup-auto-expire nil)
1201 (defvar gnus-newsgroup-active nil)
1202
1203 (defvar gnus-newsgroup-data nil)
1204 (defvar gnus-newsgroup-data-reverse nil)
1205 (defvar gnus-newsgroup-limit nil)
1206 (defvar gnus-newsgroup-limits nil)
1207
1208 (defvar gnus-newsgroup-unreads nil
1209   "Sorted list of unread articles in the current newsgroup.")
1210
1211 (defvar gnus-newsgroup-unselected nil
1212   "Sorted list of unselected unread articles in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-reads nil
1215   "Alist of read articles and article marks in the current newsgroup.")
1216
1217 (defvar gnus-newsgroup-expunged-tally nil)
1218
1219 (defvar gnus-newsgroup-marked nil
1220   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1221
1222 (defvar gnus-newsgroup-killed nil
1223   "List of ranges of articles that have been through the scoring process.")
1224
1225 (defvar gnus-newsgroup-cached nil
1226   "Sorted list of articles that come from the article cache.")
1227
1228 (defvar gnus-newsgroup-saved nil
1229   "List of articles that have been saved.")
1230
1231 (defvar gnus-newsgroup-kill-headers nil)
1232
1233 (defvar gnus-newsgroup-replied nil
1234   "List of articles that have been replied to in the current newsgroup.")
1235
1236 (defvar gnus-newsgroup-forwarded nil
1237   "List of articles that have been forwarded in the current newsgroup.")
1238
1239 (defvar gnus-newsgroup-recent nil
1240   "List of articles that have are recent in the current newsgroup.")
1241
1242 (defvar gnus-newsgroup-expirable nil
1243   "Sorted list of articles in the current newsgroup that can be expired.")
1244
1245 (defvar gnus-newsgroup-processable nil
1246   "List of articles in the current newsgroup that can be processed.")
1247
1248 (defvar gnus-newsgroup-downloadable nil
1249   "Sorted list of articles in the current newsgroup that can be processed.")
1250
1251 (defvar gnus-newsgroup-undownloaded nil
1252   "List of articles in the current newsgroup that haven't been downloaded..")
1253
1254 (defvar gnus-newsgroup-unsendable nil
1255   "List of articles in the current newsgroup that won't be sent.")
1256
1257 (defvar gnus-newsgroup-bookmarks nil
1258   "List of articles in the current newsgroup that have bookmarks.")
1259
1260 (defvar gnus-newsgroup-dormant nil
1261   "Sorted list of dormant articles in the current newsgroup.")
1262
1263 (defvar gnus-newsgroup-unseen nil
1264   "List of unseen articles in the current newsgroup.")
1265
1266 (defvar gnus-newsgroup-seen nil
1267   "Range of seen articles in the current newsgroup.")
1268
1269 (defvar gnus-newsgroup-articles nil
1270   "List of articles in the current newsgroup.")
1271
1272 (defvar gnus-newsgroup-scored nil
1273   "List of scored articles in the current newsgroup.")
1274
1275 (defvar gnus-newsgroup-incorporated nil
1276   "List of incorporated articles in the current newsgroup.")
1277
1278 (defvar gnus-newsgroup-headers nil
1279   "List of article headers in the current newsgroup.")
1280
1281 (defvar gnus-newsgroup-threads nil)
1282
1283 (defvar gnus-newsgroup-prepared nil
1284   "Whether the current group has been prepared properly.")
1285
1286 (defvar gnus-newsgroup-ancient nil
1287   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-sparse nil)
1290
1291 (defvar gnus-current-article nil)
1292 (defvar gnus-article-current nil)
1293 (defvar gnus-current-headers nil)
1294 (defvar gnus-have-all-headers nil)
1295 (defvar gnus-last-article nil)
1296 (defvar gnus-newsgroup-history nil)
1297 (defvar gnus-newsgroup-charset nil)
1298 (defvar gnus-newsgroup-ephemeral-charset nil)
1299 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1300
1301 (defvar gnus-article-before-search nil)
1302
1303 (defconst gnus-summary-local-variables
1304   '(gnus-newsgroup-name
1305     gnus-newsgroup-begin gnus-newsgroup-end
1306     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1307     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1308     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1309     gnus-newsgroup-unselected gnus-newsgroup-marked
1310     gnus-newsgroup-reads gnus-newsgroup-saved
1311     gnus-newsgroup-replied gnus-newsgroup-forwarded
1312     gnus-newsgroup-recent
1313     gnus-newsgroup-expirable
1314     gnus-newsgroup-processable gnus-newsgroup-killed
1315     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1316     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1317     gnus-newsgroup-seen gnus-newsgroup-articles
1318     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1319     gnus-newsgroup-headers gnus-newsgroup-threads
1320     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1321     gnus-current-article gnus-current-headers gnus-have-all-headers
1322     gnus-last-article gnus-article-internal-prepare-hook
1323     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1324     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1325     gnus-thread-expunge-below
1326     gnus-score-alist gnus-current-score-file
1327     (gnus-summary-expunge-below . global)
1328     (gnus-summary-mark-below . global)
1329     (gnus-orphan-score . global)
1330     gnus-newsgroup-active gnus-scores-exclude-files
1331     gnus-newsgroup-history gnus-newsgroup-ancient
1332     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1333     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1334     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1335     (gnus-newsgroup-expunged-tally . 0)
1336     gnus-cache-removable-articles gnus-newsgroup-cached
1337     gnus-newsgroup-data gnus-newsgroup-data-reverse
1338     gnus-newsgroup-limit gnus-newsgroup-limits
1339     gnus-newsgroup-charset gnus-newsgroup-display
1340     gnus-newsgroup-incorporated)
1341   "Variables that are buffer-local to the summary buffers.")
1342
1343 (defvar gnus-newsgroup-variables nil
1344   "A list of variables that have separate values in different newsgroups.
1345 A list of newsgroup (summary buffer) local variables, or cons of
1346 variables and their default values (when the default values are not
1347 nil), that should be made global while the summary buffer is active.
1348 These variables can be used to set variables in the group parameters
1349 while still allowing them to affect operations done in other
1350 buffers. For example:
1351
1352 \(setq gnus-newsgroup-variables
1353      '(message-use-followup-to
1354        (gnus-visible-headers .
1355          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1356 ")
1357
1358 ;; Byte-compiler warning.
1359 (eval-when-compile (defvar gnus-article-mode-map))
1360
1361 ;; Subject simplification.
1362
1363 (defun gnus-simplify-whitespace (str)
1364   "Remove excessive whitespace from STR."
1365   (let ((mystr str))
1366     ;; Multiple spaces.
1367     (while (string-match "[ \t][ \t]+" mystr)
1368       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1369                           " "
1370                           (substring mystr (match-end 0)))))
1371     ;; Leading spaces.
1372     (when (string-match "^[ \t]+" mystr)
1373       (setq mystr (substring mystr (match-end 0))))
1374     ;; Trailing spaces.
1375     (when (string-match "[ \t]+$" mystr)
1376       (setq mystr (substring mystr 0 (match-beginning 0))))
1377     mystr))
1378
1379 (defsubst gnus-simplify-subject-re (subject)
1380   "Remove \"Re:\" from subject lines."
1381   (if (string-match message-subject-re-regexp subject)
1382       (substring subject (match-end 0))
1383     subject))
1384
1385 (defun gnus-simplify-subject (subject &optional re-only)
1386   "Remove `Re:' and words in parentheses.
1387 If RE-ONLY is non-nil, strip leading `Re:'s only."
1388   (let ((case-fold-search t))           ;Ignore case.
1389     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1390     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1391       (setq subject (substring subject (match-end 0))))
1392     ;; Remove uninteresting prefixes.
1393     (when (and (not re-only)
1394                gnus-simplify-ignored-prefixes
1395                (string-match gnus-simplify-ignored-prefixes subject))
1396       (setq subject (substring subject (match-end 0))))
1397     ;; Remove words in parentheses from end.
1398     (unless re-only
1399       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1400         (setq subject (substring subject 0 (match-beginning 0)))))
1401     ;; Return subject string.
1402     subject))
1403
1404 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1405 ;; all whitespace.
1406 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1407   (goto-char (point-min))
1408   (while (re-search-forward regexp nil t)
1409     (replace-match (or newtext ""))))
1410
1411 (defun gnus-simplify-buffer-fuzzy ()
1412   "Simplify string in the buffer fuzzily.
1413 The string in the accessible portion of the current buffer is simplified.
1414 It is assumed to be a single-line subject.
1415 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1416 matter is removed.  Additional things can be deleted by setting
1417 `gnus-simplify-subject-fuzzy-regexp'."
1418   (let ((case-fold-search t)
1419         (modified-tick))
1420     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1421
1422     (while (not (eq modified-tick (buffer-modified-tick)))
1423       (setq modified-tick (buffer-modified-tick))
1424       (cond
1425        ((listp gnus-simplify-subject-fuzzy-regexp)
1426         (mapcar 'gnus-simplify-buffer-fuzzy-step
1427                 gnus-simplify-subject-fuzzy-regexp))
1428        (gnus-simplify-subject-fuzzy-regexp
1429         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1430       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1431       (gnus-simplify-buffer-fuzzy-step
1432        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1433       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1434
1435     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1436     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1437     (gnus-simplify-buffer-fuzzy-step " $")
1438     (gnus-simplify-buffer-fuzzy-step "^ +")))
1439
1440 (defun gnus-simplify-subject-fuzzy (subject)
1441   "Simplify a subject string fuzzily.
1442 See `gnus-simplify-buffer-fuzzy' for details."
1443   (save-excursion
1444     (gnus-set-work-buffer)
1445     (let ((case-fold-search t))
1446       ;; Remove uninteresting prefixes.
1447       (when (and gnus-simplify-ignored-prefixes
1448                  (string-match gnus-simplify-ignored-prefixes subject))
1449         (setq subject (substring subject (match-end 0))))
1450       (insert subject)
1451       (inline (gnus-simplify-buffer-fuzzy))
1452       (buffer-string))))
1453
1454 (defsubst gnus-simplify-subject-fully (subject)
1455   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1456   (cond
1457    (gnus-simplify-subject-functions
1458     (gnus-map-function gnus-simplify-subject-functions subject))
1459    ((null gnus-summary-gather-subject-limit)
1460     (gnus-simplify-subject-re subject))
1461    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1462     (gnus-simplify-subject-fuzzy subject))
1463    ((numberp gnus-summary-gather-subject-limit)
1464     (gnus-limit-string (gnus-simplify-subject-re subject)
1465                        gnus-summary-gather-subject-limit))
1466    (t
1467     subject)))
1468
1469 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1470   "Check whether two subjects are equal.
1471 If optional argument simple-first is t, first argument is already
1472 simplified."
1473   (cond
1474    ((null simple-first)
1475     (equal (gnus-simplify-subject-fully s1)
1476            (gnus-simplify-subject-fully s2)))
1477    (t
1478     (equal s1
1479            (gnus-simplify-subject-fully s2)))))
1480
1481 (defun gnus-summary-bubble-group ()
1482   "Increase the score of the current group.
1483 This is a handy function to add to `gnus-summary-exit-hook' to
1484 increase the score of each group you read."
1485   (gnus-group-add-score gnus-newsgroup-name))
1486
1487 \f
1488 ;;;
1489 ;;; Gnus summary mode
1490 ;;;
1491
1492 (put 'gnus-summary-mode 'mode-class 'special)
1493
1494 (defvar gnus-article-commands-menu)
1495
1496 (when t
1497   ;; Non-orthogonal keys
1498
1499   (gnus-define-keys gnus-summary-mode-map
1500     " " gnus-summary-next-page
1501     "\177" gnus-summary-prev-page
1502     [delete] gnus-summary-prev-page
1503     [backspace] gnus-summary-prev-page
1504     "\r" gnus-summary-scroll-up
1505     "\M-\r" gnus-summary-scroll-down
1506     "n" gnus-summary-next-unread-article
1507     "p" gnus-summary-prev-unread-article
1508     "N" gnus-summary-next-article
1509     "P" gnus-summary-prev-article
1510     "\M-\C-n" gnus-summary-next-same-subject
1511     "\M-\C-p" gnus-summary-prev-same-subject
1512     "\M-n" gnus-summary-next-unread-subject
1513     "\M-p" gnus-summary-prev-unread-subject
1514     "." gnus-summary-first-unread-article
1515     "," gnus-summary-best-unread-article
1516     "\M-s" gnus-summary-search-article-forward
1517     "\M-r" gnus-summary-search-article-backward
1518     "<" gnus-summary-beginning-of-article
1519     ">" gnus-summary-end-of-article
1520     "j" gnus-summary-goto-article
1521     "^" gnus-summary-refer-parent-article
1522     "\M-^" gnus-summary-refer-article
1523     "u" gnus-summary-tick-article-forward
1524     "!" gnus-summary-tick-article-forward
1525     "U" gnus-summary-tick-article-backward
1526     "d" gnus-summary-mark-as-read-forward
1527     "D" gnus-summary-mark-as-read-backward
1528     "E" gnus-summary-mark-as-expirable
1529     "\M-u" gnus-summary-clear-mark-forward
1530     "\M-U" gnus-summary-clear-mark-backward
1531     "k" gnus-summary-kill-same-subject-and-select
1532     "\C-k" gnus-summary-kill-same-subject
1533     "\M-\C-k" gnus-summary-kill-thread
1534     "\M-\C-l" gnus-summary-lower-thread
1535     "e" gnus-summary-edit-article
1536     "#" gnus-summary-mark-as-processable
1537     "\M-#" gnus-summary-unmark-as-processable
1538     "\M-\C-t" gnus-summary-toggle-threads
1539     "\M-\C-s" gnus-summary-show-thread
1540     "\M-\C-h" gnus-summary-hide-thread
1541     "\M-\C-f" gnus-summary-next-thread
1542     "\M-\C-b" gnus-summary-prev-thread
1543     [(meta down)] gnus-summary-next-thread
1544     [(meta up)] gnus-summary-prev-thread
1545     "\M-\C-u" gnus-summary-up-thread
1546     "\M-\C-d" gnus-summary-down-thread
1547     "&" gnus-summary-execute-command
1548     "c" gnus-summary-catchup-and-exit
1549     "\C-w" gnus-summary-mark-region-as-read
1550     "\C-t" gnus-summary-toggle-truncation
1551     "?" gnus-summary-mark-as-dormant
1552     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1553     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1554     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1555     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1556     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1557     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1558     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1559     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1560     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1561     "=" gnus-summary-expand-window
1562     "\C-x\C-s" gnus-summary-reselect-current-group
1563     "\M-g" gnus-summary-rescan-group
1564     "w" gnus-summary-stop-page-breaking
1565     "\C-c\C-r" gnus-summary-caesar-message
1566     "\M-t" gnus-summary-toggle-mime
1567     "f" gnus-summary-followup
1568     "F" gnus-summary-followup-with-original
1569     "C" gnus-summary-cancel-article
1570     "r" gnus-summary-reply
1571     "R" gnus-summary-reply-with-original
1572     "\C-c\C-f" gnus-summary-mail-forward
1573     "o" gnus-summary-save-article
1574     "\C-o" gnus-summary-save-article-mail
1575     "|" gnus-summary-pipe-output
1576     "\M-k" gnus-summary-edit-local-kill
1577     "\M-K" gnus-summary-edit-global-kill
1578     ;; "V" gnus-version
1579     "\C-c\C-d" gnus-summary-describe-group
1580     "q" gnus-summary-exit
1581     "Q" gnus-summary-exit-no-update
1582     "\C-c\C-i" gnus-info-find-node
1583     gnus-mouse-2 gnus-mouse-pick-article
1584     "m" gnus-summary-mail-other-window
1585     "a" gnus-summary-post-news
1586     "i" gnus-summary-news-other-window
1587     "x" gnus-summary-limit-to-unread
1588     "s" gnus-summary-isearch-article
1589     "t" gnus-article-toggle-headers
1590     "g" gnus-summary-show-article
1591     "l" gnus-summary-goto-last-article
1592     "v" gnus-summary-preview-mime-message
1593     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1594     "\C-d" gnus-summary-enter-digest-group
1595     "\M-\C-d" gnus-summary-read-document
1596     "\M-\C-e" gnus-summary-edit-parameters
1597     "\M-\C-a" gnus-summary-customize-parameters
1598     "\C-c\C-b" gnus-bug
1599     "\C-c\C-n" gnus-namazu-search
1600     "*" gnus-cache-enter-article
1601     "\M-*" gnus-cache-remove-article
1602     "\M-&" gnus-summary-universal-argument
1603     "\C-l" gnus-recenter
1604     "I" gnus-summary-increase-score
1605     "L" gnus-summary-lower-score
1606     "\M-i" gnus-symbolic-argument
1607     "h" gnus-summary-select-article-buffer
1608
1609     "V" gnus-summary-score-map
1610     "X" gnus-uu-extract-map
1611     "S" gnus-summary-send-map)
1612
1613   ;; Sort of orthogonal keymap
1614   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1615     "t" gnus-summary-tick-article-forward
1616     "!" gnus-summary-tick-article-forward
1617     "d" gnus-summary-mark-as-read-forward
1618     "r" gnus-summary-mark-as-read-forward
1619     "c" gnus-summary-clear-mark-forward
1620     " " gnus-summary-clear-mark-forward
1621     "e" gnus-summary-mark-as-expirable
1622     "x" gnus-summary-mark-as-expirable
1623     "?" gnus-summary-mark-as-dormant
1624     "b" gnus-summary-set-bookmark
1625     "B" gnus-summary-remove-bookmark
1626     "#" gnus-summary-mark-as-processable
1627     "\M-#" gnus-summary-unmark-as-processable
1628     "S" gnus-summary-limit-include-expunged
1629     "C" gnus-summary-catchup
1630     "H" gnus-summary-catchup-to-here
1631     "h" gnus-summary-catchup-from-here
1632     "\C-c" gnus-summary-catchup-all
1633     "k" gnus-summary-kill-same-subject-and-select
1634     "K" gnus-summary-kill-same-subject
1635     "P" gnus-uu-mark-map)
1636
1637   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1638     "c" gnus-summary-clear-above
1639     "u" gnus-summary-tick-above
1640     "m" gnus-summary-mark-above
1641     "k" gnus-summary-kill-below)
1642
1643   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1644     "/" gnus-summary-limit-to-subject
1645     "n" gnus-summary-limit-to-articles
1646     "w" gnus-summary-pop-limit
1647     "s" gnus-summary-limit-to-subject
1648     "a" gnus-summary-limit-to-author
1649     "u" gnus-summary-limit-to-unread
1650     "m" gnus-summary-limit-to-marks
1651     "M" gnus-summary-limit-exclude-marks
1652     "v" gnus-summary-limit-to-score
1653     "*" gnus-summary-limit-include-cached
1654     "D" gnus-summary-limit-include-dormant
1655     "T" gnus-summary-limit-include-thread
1656     "d" gnus-summary-limit-exclude-dormant
1657     "t" gnus-summary-limit-to-age
1658     "x" gnus-summary-limit-to-extra
1659     "p" gnus-summary-limit-to-display-predicate
1660     "E" gnus-summary-limit-include-expunged
1661     "c" gnus-summary-limit-exclude-childless-dormant
1662     "C" gnus-summary-limit-mark-excluded-as-read
1663     "o" gnus-summary-insert-old-articles
1664     "N" gnus-summary-insert-new-articles)
1665
1666   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1667     "n" gnus-summary-next-unread-article
1668     "p" gnus-summary-prev-unread-article
1669     "N" gnus-summary-next-article
1670     "P" gnus-summary-prev-article
1671     "\C-n" gnus-summary-next-same-subject
1672     "\C-p" gnus-summary-prev-same-subject
1673     "\M-n" gnus-summary-next-unread-subject
1674     "\M-p" gnus-summary-prev-unread-subject
1675     "f" gnus-summary-first-unread-article
1676     "b" gnus-summary-best-unread-article
1677     "j" gnus-summary-goto-article
1678     "g" gnus-summary-goto-subject
1679     "l" gnus-summary-goto-last-article
1680     "o" gnus-summary-pop-article)
1681
1682   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1683     "k" gnus-summary-kill-thread
1684     "l" gnus-summary-lower-thread
1685     "i" gnus-summary-raise-thread
1686     "T" gnus-summary-toggle-threads
1687     "t" gnus-summary-rethread-current
1688     "^" gnus-summary-reparent-thread
1689     "s" gnus-summary-show-thread
1690     "S" gnus-summary-show-all-threads
1691     "h" gnus-summary-hide-thread
1692     "H" gnus-summary-hide-all-threads
1693     "n" gnus-summary-next-thread
1694     "p" gnus-summary-prev-thread
1695     "u" gnus-summary-up-thread
1696     "o" gnus-summary-top-thread
1697     "d" gnus-summary-down-thread
1698     "#" gnus-uu-mark-thread
1699     "\M-#" gnus-uu-unmark-thread)
1700
1701   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1702     "g" gnus-summary-prepare
1703     "c" gnus-summary-insert-cached-articles)
1704
1705   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1706     "c" gnus-summary-catchup-and-exit
1707     "C" gnus-summary-catchup-all-and-exit
1708     "E" gnus-summary-exit-no-update
1709     "J" gnus-summary-jump-to-other-group
1710     "Q" gnus-summary-exit
1711     "Z" gnus-summary-exit
1712     "n" gnus-summary-catchup-and-goto-next-group
1713     "R" gnus-summary-reselect-current-group
1714     "G" gnus-summary-rescan-group
1715     "N" gnus-summary-next-group
1716     "s" gnus-summary-save-newsrc
1717     "P" gnus-summary-prev-group)
1718
1719   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1720     " " gnus-summary-next-page
1721     "n" gnus-summary-next-page
1722     "\177" gnus-summary-prev-page
1723     [delete] gnus-summary-prev-page
1724     "p" gnus-summary-prev-page
1725     "\r" gnus-summary-scroll-up
1726     "\M-\r" gnus-summary-scroll-down
1727     "<" gnus-summary-beginning-of-article
1728     ">" gnus-summary-end-of-article
1729     "b" gnus-summary-beginning-of-article
1730     "e" gnus-summary-end-of-article
1731     "^" gnus-summary-refer-parent-article
1732     "r" gnus-summary-refer-parent-article
1733     "D" gnus-summary-enter-digest-group
1734     "R" gnus-summary-refer-references
1735     "T" gnus-summary-refer-thread
1736     "g" gnus-summary-show-article
1737     "s" gnus-summary-isearch-article
1738     "P" gnus-summary-print-article
1739     "M" gnus-mailing-list-insinuate
1740     "t" gnus-article-babel)
1741
1742   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1743     "b" gnus-article-add-buttons
1744     "B" gnus-article-add-buttons-to-head
1745     "o" gnus-article-treat-overstrike
1746     "e" gnus-article-emphasize
1747     "w" gnus-article-fill-cited-article
1748     "Q" gnus-article-fill-long-lines
1749     "C" gnus-article-capitalize-sentences
1750     "c" gnus-article-remove-cr
1751     "Z" gnus-article-decode-HZ
1752     "h" gnus-article-wash-html
1753     "u" gnus-article-unsplit-urls
1754     "f" gnus-article-display-x-face
1755     "l" gnus-summary-stop-page-breaking
1756     "r" gnus-summary-caesar-message
1757     "t" gnus-article-toggle-headers
1758     "g" gnus-treat-smiley
1759     "v" gnus-summary-verbose-headers
1760     "m" gnus-summary-toggle-mime
1761     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1762     "p" gnus-article-verify-x-pgp-sig
1763     "d" gnus-article-treat-dumbquotes
1764     "k" gnus-article-outlook-deuglify-article)
1765
1766   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1767     "a" gnus-article-hide
1768     "h" gnus-article-toggle-headers
1769     "b" gnus-article-hide-boring-headers
1770     "s" gnus-article-hide-signature
1771     "c" gnus-article-hide-citation
1772     "C" gnus-article-hide-citation-in-followups
1773     "l" gnus-article-hide-list-identifiers
1774     "p" gnus-article-hide-pgp
1775     "B" gnus-article-strip-banner
1776     "P" gnus-article-hide-pem
1777     "\C-c" gnus-article-hide-citation-maybe)
1778
1779   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1780     "a" gnus-article-highlight
1781     "h" gnus-article-highlight-headers
1782     "c" gnus-article-highlight-citation
1783     "s" gnus-article-highlight-signature)
1784
1785   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1786     "f" gnus-article-treat-fold-headers
1787     "u" gnus-article-treat-unfold-headers
1788     "n" gnus-article-treat-fold-newsgroups)
1789
1790   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1791     "x" gnus-article-display-x-face
1792     "s" gnus-treat-smiley
1793     "D" gnus-article-remove-images
1794     "f" gnus-treat-from-picon
1795     "m" gnus-treat-mail-picon
1796     "n" gnus-treat-newsgroups-picon)
1797
1798   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1799     "z" gnus-article-date-ut
1800     "u" gnus-article-date-ut
1801     "l" gnus-article-date-local
1802     "p" gnus-article-date-english
1803     "e" gnus-article-date-lapsed
1804     "o" gnus-article-date-original
1805     "i" gnus-article-date-iso8601
1806     "s" gnus-article-date-user)
1807
1808   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1809     "t" gnus-article-remove-trailing-blank-lines
1810     "l" gnus-article-strip-leading-blank-lines
1811     "m" gnus-article-strip-multiple-blank-lines
1812     "a" gnus-article-strip-blank-lines
1813     "A" gnus-article-strip-all-blank-lines
1814     "s" gnus-article-strip-leading-space
1815     "e" gnus-article-strip-trailing-space
1816     "w" gnus-article-remove-leading-whitespace)
1817
1818   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1819     "v" gnus-version
1820     "f" gnus-summary-fetch-faq
1821     "d" gnus-summary-describe-group
1822     "h" gnus-summary-describe-briefly
1823     "i" gnus-info-find-node)
1824
1825   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1826     "e" gnus-summary-expire-articles
1827     "\M-\C-e" gnus-summary-expire-articles-now
1828     "\177" gnus-summary-delete-article
1829     [delete] gnus-summary-delete-article
1830     [backspace] gnus-summary-delete-article
1831     "m" gnus-summary-move-article
1832     "r" gnus-summary-respool-article
1833     "w" gnus-summary-edit-article
1834     "c" gnus-summary-copy-article
1835     "B" gnus-summary-crosspost-article
1836     "q" gnus-summary-respool-query
1837     "t" gnus-summary-respool-trace
1838     "i" gnus-summary-import-article
1839     "I" gnus-summary-create-article
1840     "p" gnus-summary-article-posted-p)
1841
1842   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1843     "o" gnus-summary-save-article
1844     "m" gnus-summary-save-article-mail
1845     "F" gnus-summary-write-article-file
1846     "r" gnus-summary-save-article-rmail
1847     "f" gnus-summary-save-article-file
1848     "b" gnus-summary-save-article-body-file
1849     "h" gnus-summary-save-article-folder
1850     "v" gnus-summary-save-article-vm
1851     "p" gnus-summary-pipe-output
1852     "P" gnus-summary-muttprint
1853     "s" gnus-soup-add-article)
1854
1855   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1856     "b" gnus-summary-display-buttonized
1857     "m" gnus-summary-repair-multipart
1858     "v" gnus-article-view-part
1859     "o" gnus-article-save-part
1860     "c" gnus-article-copy-part
1861     "C" gnus-article-view-part-as-charset
1862     "e" gnus-article-view-part-externally
1863     "E" gnus-article-encrypt-body
1864     "i" gnus-article-inline-part
1865     "|" gnus-article-pipe-part)
1866
1867   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1868     "p" gnus-summary-mark-as-processable
1869     "u" gnus-summary-unmark-as-processable
1870     "U" gnus-summary-unmark-all-processable
1871     "v" gnus-uu-mark-over
1872     "s" gnus-uu-mark-series
1873     "r" gnus-uu-mark-region
1874     "g" gnus-uu-unmark-region
1875     "R" gnus-uu-mark-by-regexp
1876     "G" gnus-uu-unmark-by-regexp
1877     "t" gnus-uu-mark-thread
1878     "T" gnus-uu-unmark-thread
1879     "a" gnus-uu-mark-all
1880     "b" gnus-uu-mark-buffer
1881     "S" gnus-uu-mark-sparse
1882     "k" gnus-summary-kill-process-mark
1883     "y" gnus-summary-yank-process-mark
1884     "w" gnus-summary-save-process-mark
1885     "i" gnus-uu-invert-processable)
1886
1887   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1888     ;;"x" gnus-uu-extract-any
1889     "m" gnus-summary-save-parts
1890     "u" gnus-uu-decode-uu
1891     "U" gnus-uu-decode-uu-and-save
1892     "s" gnus-uu-decode-unshar
1893     "S" gnus-uu-decode-unshar-and-save
1894     "o" gnus-uu-decode-save
1895     "O" gnus-uu-decode-save
1896     "b" gnus-uu-decode-binhex
1897     "B" gnus-uu-decode-binhex
1898     "p" gnus-uu-decode-postscript
1899     "P" gnus-uu-decode-postscript-and-save)
1900
1901   (gnus-define-keys
1902       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1903     "u" gnus-uu-decode-uu-view
1904     "U" gnus-uu-decode-uu-and-save-view
1905     "s" gnus-uu-decode-unshar-view
1906     "S" gnus-uu-decode-unshar-and-save-view
1907     "o" gnus-uu-decode-save-view
1908     "O" gnus-uu-decode-save-view
1909     "b" gnus-uu-decode-binhex-view
1910     "B" gnus-uu-decode-binhex-view
1911     "p" gnus-uu-decode-postscript-view
1912     "P" gnus-uu-decode-postscript-and-save-view))
1913
1914 (defvar gnus-article-post-menu nil)
1915
1916 (defun gnus-summary-make-menu-bar ()
1917   (gnus-turn-off-edit-menu 'summary)
1918
1919   (unless (boundp 'gnus-summary-misc-menu)
1920
1921     (easy-menu-define
1922      gnus-summary-kill-menu gnus-summary-mode-map ""
1923      (cons
1924       "Score"
1925       (nconc
1926        (list
1927         ["Customize" gnus-score-customize t])
1928        (gnus-make-score-map 'increase)
1929        (gnus-make-score-map 'lower)
1930        '(("Mark"
1931           ["Kill below" gnus-summary-kill-below t]
1932           ["Mark above" gnus-summary-mark-above t]
1933           ["Tick above" gnus-summary-tick-above t]
1934           ["Clear above" gnus-summary-clear-above t])
1935          ["Current score" gnus-summary-current-score t]
1936          ["Set score" gnus-summary-set-score t]
1937          ["Switch current score file..." gnus-score-change-score-file t]
1938          ["Set mark below..." gnus-score-set-mark-below t]
1939          ["Set expunge below..." gnus-score-set-expunge-below t]
1940          ["Edit current score file" gnus-score-edit-current-scores t]
1941          ["Edit score file" gnus-score-edit-file t]
1942          ["Trace score" gnus-score-find-trace t]
1943          ["Find words" gnus-score-find-favourite-words t]
1944          ["Rescore buffer" gnus-summary-rescore t]
1945          ["Increase score..." gnus-summary-increase-score t]
1946          ["Lower score..." gnus-summary-lower-score t]))))
1947
1948     ;; Define both the Article menu in the summary buffer and the
1949     ;; equivalent Commands menu in the article buffer here for
1950     ;; consistency.
1951     (let ((innards
1952            `(("Hide"
1953               ["All" gnus-article-hide t]
1954               ["Headers" gnus-article-toggle-headers t]
1955               ["Signature" gnus-article-hide-signature t]
1956               ["Citation" gnus-article-hide-citation t]
1957               ["List identifiers" gnus-article-hide-list-identifiers t]
1958               ["PGP" gnus-article-hide-pgp t]
1959               ["Banner" gnus-article-strip-banner t]
1960               ["Boring headers" gnus-article-hide-boring-headers t])
1961              ("Highlight"
1962               ["All" gnus-article-highlight t]
1963               ["Headers" gnus-article-highlight-headers t]
1964               ["Signature" gnus-article-highlight-signature t]
1965               ["Citation" gnus-article-highlight-citation t])
1966              ("Date"
1967               ["Local" gnus-article-date-local t]
1968               ["ISO8601" gnus-article-date-iso8601 t]
1969               ["UT" gnus-article-date-ut t]
1970               ["Original" gnus-article-date-original t]
1971               ["Lapsed" gnus-article-date-lapsed t]
1972               ["User-defined" gnus-article-date-user t])
1973              ("Display"
1974               ["Remove images" gnus-article-remove-images t]
1975               ["Toggle smiley" gnus-treat-smiley t]
1976               ["Show X-Face" gnus-article-display-x-face t]
1977               ["Show picons in From" gnus-treat-from-picon t]
1978               ["Show picons in mail headers" gnus-treat-mail-picon t]
1979               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
1980               ("View as different encoding"
1981                ,@(mapcar
1982                   (lambda (cs)
1983                     ;; Since easymenu under FSF Emacs doesn't allow lambda
1984                     ;; forms for menu commands, we should provide intern'ed
1985                     ;; function symbols.
1986                     (let ((command (intern (format "\
1987 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
1988                       (fset command
1989                             `(lambda ()
1990                                (interactive)
1991                                (let ((gnus-summary-show-article-charset-alist
1992                                       '((1 . ,cs))))
1993                                  (gnus-summary-show-article 1))))
1994                       `[,(symbol-name cs) ,command t]))
1995                   (sort (if (fboundp 'coding-system-list)
1996                             (coding-system-list)
1997                           ;;(mapcar 'car mm-mime-mule-charset-alist)
1998                           )
1999                         (lambda (a b)
2000                           (string< (symbol-name a)
2001                                    (symbol-name b)))))))
2002              ("Washing"
2003               ("Remove Blanks"
2004                ["Leading" gnus-article-strip-leading-blank-lines t]
2005                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2006                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2007                ["All of the above" gnus-article-strip-blank-lines t]
2008                ["All" gnus-article-strip-all-blank-lines t]
2009                ["Leading space" gnus-article-strip-leading-space t]
2010                ["Trailing space" gnus-article-strip-trailing-space t]
2011                ["Leading space in headers"
2012                 gnus-article-remove-leading-whitespace t])
2013               ["Overstrike" gnus-article-treat-overstrike t]
2014               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2015               ["Emphasis" gnus-article-emphasize t]
2016               ["Word wrap" gnus-article-fill-cited-article t]
2017               ["Fill long lines" gnus-article-fill-long-lines t]
2018               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2019               ["CR" gnus-article-remove-cr t]
2020               ["Rot 13" gnus-summary-caesar-message
2021                ,@(if (featurep 'xemacs) '(t)
2022                    '(:help "\"Caesar rotate\" article by 13"))]
2023               ["Unix pipe" gnus-summary-pipe-message t]
2024               ["Add buttons" gnus-article-add-buttons t]
2025               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2026               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2027               ["Toggle MIME" gnus-summary-toggle-mime t]
2028               ["Verbose header" gnus-summary-verbose-headers t]
2029               ["Toggle header" gnus-summary-toggle-header t]
2030               ["Unfold headers" gnus-article-treat-unfold-headers t]
2031               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2032               ["Html" gnus-article-wash-html t]
2033               ["URLs" gnus-article-unsplit-urls t]
2034               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2035               ["HZ" gnus-article-decode-HZ t]
2036               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2037               )
2038              ("Output"
2039               ["Save in default format" gnus-summary-save-article
2040                ,@(if (featurep 'xemacs) '(t)
2041                    '(:help "Save article using default method"))]
2042               ["Save in file" gnus-summary-save-article-file
2043                ,@(if (featurep 'xemacs) '(t)
2044                    '(:help "Save article in file"))]
2045               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2046               ["Save in MH folder" gnus-summary-save-article-folder t]
2047               ["Save in VM folder" gnus-summary-save-article-vm t]
2048               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2049               ["Save body in file" gnus-summary-save-article-body-file t]
2050               ["Pipe through a filter" gnus-summary-pipe-output t]
2051               ["Add to SOUP packet" gnus-soup-add-article t]
2052               ["Print with Muttprint" gnus-summary-muttprint t]
2053               ["Print" gnus-summary-print-article t])
2054              ("Backend"
2055               ["Respool article..." gnus-summary-respool-article t]
2056               ["Move article..." gnus-summary-move-article
2057                (gnus-check-backend-function
2058                 'request-move-article gnus-newsgroup-name)]
2059               ["Copy article..." gnus-summary-copy-article t]
2060               ["Crosspost article..." gnus-summary-crosspost-article
2061                (gnus-check-backend-function
2062                 'request-replace-article gnus-newsgroup-name)]
2063               ["Import file..." gnus-summary-import-article t]
2064               ["Create article..." gnus-summary-create-article t]
2065               ["Check if posted" gnus-summary-article-posted-p t]
2066               ["Edit article" gnus-summary-edit-article
2067                (not (gnus-group-read-only-p))]
2068               ["Delete article" gnus-summary-delete-article
2069                (gnus-check-backend-function
2070                 'request-expire-articles gnus-newsgroup-name)]
2071               ["Query respool" gnus-summary-respool-query t]
2072               ["Trace respool" gnus-summary-respool-trace t]
2073               ["Delete expirable articles" gnus-summary-expire-articles-now
2074                (gnus-check-backend-function
2075                 'request-expire-articles gnus-newsgroup-name)])
2076              ("Extract"
2077               ["Uudecode" gnus-uu-decode-uu
2078                ,@(if (featurep 'xemacs) '(t)
2079                    '(:help "Decode uuencoded article(s)"))]
2080               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2081               ["Unshar" gnus-uu-decode-unshar t]
2082               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2083               ["Save" gnus-uu-decode-save t]
2084               ["Binhex" gnus-uu-decode-binhex t]
2085               ["Postscript" gnus-uu-decode-postscript t])
2086              ("Cache"
2087               ["Enter article" gnus-cache-enter-article t]
2088               ["Remove article" gnus-cache-remove-article t])
2089              ["Translate" gnus-article-babel t]
2090              ["Select article buffer" gnus-summary-select-article-buffer t]
2091              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2092              ["Isearch article..." gnus-summary-isearch-article t]
2093              ["Beginning of the article" gnus-summary-beginning-of-article t]
2094              ["End of the article" gnus-summary-end-of-article t]
2095              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2096              ["Fetch referenced articles" gnus-summary-refer-references t]
2097              ["Fetch current thread" gnus-summary-refer-thread t]
2098              ["Fetch article with id..." gnus-summary-refer-article t]
2099              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2100              ["Redisplay" gnus-summary-show-article t]
2101              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2102       (easy-menu-define
2103        gnus-summary-article-menu gnus-summary-mode-map ""
2104        (cons "Article" innards))
2105
2106       (if (not (keymapp gnus-summary-article-menu))
2107           (easy-menu-define
2108            gnus-article-commands-menu gnus-article-mode-map ""
2109            (cons "Commands" innards))
2110         ;; in Emacs, don't share menu.
2111         (setq gnus-article-commands-menu
2112               (copy-keymap gnus-summary-article-menu))
2113         (define-key gnus-article-mode-map [menu-bar commands]
2114           (cons "Commands" gnus-article-commands-menu))))
2115
2116     (easy-menu-define
2117      gnus-summary-thread-menu gnus-summary-mode-map ""
2118      '("Threads"
2119        ["Toggle threading" gnus-summary-toggle-threads t]
2120        ["Hide threads" gnus-summary-hide-all-threads t]
2121        ["Show threads" gnus-summary-show-all-threads t]
2122        ["Hide thread" gnus-summary-hide-thread t]
2123        ["Show thread" gnus-summary-show-thread t]
2124        ["Go to next thread" gnus-summary-next-thread t]
2125        ["Go to previous thread" gnus-summary-prev-thread t]
2126        ["Go down thread" gnus-summary-down-thread t]
2127        ["Go up thread" gnus-summary-up-thread t]
2128        ["Top of thread" gnus-summary-top-thread t]
2129        ["Mark thread as read" gnus-summary-kill-thread t]
2130        ["Lower thread score" gnus-summary-lower-thread t]
2131        ["Raise thread score" gnus-summary-raise-thread t]
2132        ["Rethread current" gnus-summary-rethread-current t]))
2133
2134     (easy-menu-define
2135      gnus-summary-post-menu gnus-summary-mode-map ""
2136      `("Post"
2137        ["Send a message (mail or news)" gnus-summary-post-news
2138         ,@(if (featurep 'xemacs) '(t)
2139             '(:help "Post an article"))]
2140        ["Followup" gnus-summary-followup
2141         ,@(if (featurep 'xemacs) '(t)
2142             '(:help "Post followup to this article"))]
2143        ["Followup and yank" gnus-summary-followup-with-original
2144         ,@(if (featurep 'xemacs) '(t)
2145             '(:help "Post followup to this article, quoting its contents"))]
2146        ["Supersede article" gnus-summary-supersede-article t]
2147        ["Cancel article" gnus-summary-cancel-article
2148         ,@(if (featurep 'xemacs) '(t)
2149             '(:help "Cancel an article you posted"))]
2150        ["Reply" gnus-summary-reply t]
2151        ["Reply and yank" gnus-summary-reply-with-original t]
2152        ["Wide reply" gnus-summary-wide-reply t]
2153        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2154         ,@(if (featurep 'xemacs) '(t)
2155             '(:help "Mail a reply, quoting this article"))]
2156        ["Very wide reply" gnus-summary-very-wide-reply t]
2157        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2158         ,@(if (featurep 'xemacs) '(t)
2159             '(:help "Mail a very wide reply, quoting this article"))]
2160        ["Mail forward" gnus-summary-mail-forward t]
2161        ["Post forward" gnus-summary-post-forward t]
2162        ["Digest and mail" gnus-summary-digest-mail-forward t]
2163        ["Digest and post" gnus-summary-digest-post-forward t]
2164        ["Resend message" gnus-summary-resend-message t]
2165        ["Resend message edit" gnus-summary-resend-message-edit t]
2166        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2167        ["Send a mail" gnus-summary-mail-other-window t]
2168        ["Create a local message" gnus-summary-news-other-window t]
2169        ["Uuencode and post" gnus-uu-post-news
2170         ,@(if (featurep 'xemacs) '(t)
2171             '(:help "Post a uuencoded article"))]
2172        ["Followup via news" gnus-summary-followup-to-mail t]
2173        ["Followup via news and yank"
2174         gnus-summary-followup-to-mail-with-original t]
2175        ;;("Draft"
2176        ;;["Send" gnus-summary-send-draft t]
2177        ;;["Send bounced" gnus-resend-bounced-mail t])
2178        ))
2179
2180     (cond
2181      ((not (keymapp gnus-summary-post-menu))
2182       (setq gnus-article-post-menu gnus-summary-post-menu))
2183      ((not gnus-article-post-menu)
2184       ;; Don't share post menu.
2185       (setq gnus-article-post-menu
2186             (copy-keymap gnus-summary-post-menu))))
2187     (define-key gnus-article-mode-map [menu-bar post]
2188       (cons "Post" gnus-article-post-menu))
2189
2190     (easy-menu-define
2191      gnus-summary-misc-menu gnus-summary-mode-map ""
2192      `("Gnus"
2193        ("Mark Read"
2194         ["Mark as read" gnus-summary-mark-as-read-forward t]
2195         ["Mark same subject and select"
2196          gnus-summary-kill-same-subject-and-select t]
2197         ["Mark same subject" gnus-summary-kill-same-subject t]
2198         ["Catchup" gnus-summary-catchup
2199          ,@(if (featurep 'xemacs) '(t)
2200              '(:help "Mark unread articles in this group as read"))]
2201         ["Catchup all" gnus-summary-catchup-all t]
2202         ["Catchup to here" gnus-summary-catchup-to-here t]
2203         ["Catchup from here" gnus-summary-catchup-from-here t]
2204         ["Catchup region" gnus-summary-mark-region-as-read t]
2205         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2206        ("Mark Various"
2207         ["Tick" gnus-summary-tick-article-forward t]
2208         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2209         ["Remove marks" gnus-summary-clear-mark-forward t]
2210         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2211         ["Set bookmark" gnus-summary-set-bookmark t]
2212         ["Remove bookmark" gnus-summary-remove-bookmark t])
2213        ("Limit to"
2214         ["Marks..." gnus-summary-limit-to-marks t]
2215         ["Subject..." gnus-summary-limit-to-subject t]
2216         ["Author..." gnus-summary-limit-to-author t]
2217         ["Age..." gnus-summary-limit-to-age t]
2218         ["Extra..." gnus-summary-limit-to-extra t]
2219         ["Score" gnus-summary-limit-to-score t]
2220         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2221         ["Unread" gnus-summary-limit-to-unread t]
2222         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2223         ["Articles" gnus-summary-limit-to-articles t]
2224         ["Pop limit" gnus-summary-pop-limit t]
2225         ["Show dormant" gnus-summary-limit-include-dormant t]
2226         ["Hide childless dormant"
2227          gnus-summary-limit-exclude-childless-dormant t]
2228         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2229         ["Hide marked" gnus-summary-limit-exclude-marks t]
2230         ["Show expunged" gnus-summary-limit-include-expunged t])
2231        ("Process Mark"
2232         ["Set mark" gnus-summary-mark-as-processable t]
2233         ["Remove mark" gnus-summary-unmark-as-processable t]
2234         ["Remove all marks" gnus-summary-unmark-all-processable t]
2235         ["Mark above" gnus-uu-mark-over t]
2236         ["Mark series" gnus-uu-mark-series t]
2237         ["Mark region" gnus-uu-mark-region t]
2238         ["Unmark region" gnus-uu-unmark-region t]
2239         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2240         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2241         ["Mark all" gnus-uu-mark-all t]
2242         ["Mark buffer" gnus-uu-mark-buffer t]
2243         ["Mark sparse" gnus-uu-mark-sparse t]
2244         ["Mark thread" gnus-uu-mark-thread t]
2245         ["Unmark thread" gnus-uu-unmark-thread t]
2246         ("Process Mark Sets"
2247          ["Kill" gnus-summary-kill-process-mark t]
2248          ["Yank" gnus-summary-yank-process-mark
2249           gnus-newsgroup-process-stack]
2250          ["Save" gnus-summary-save-process-mark t]))
2251        ("Scroll article"
2252         ["Page forward" gnus-summary-next-page
2253          ,@(if (featurep 'xemacs) '(t)
2254              '(:help "Show next page of article"))]
2255         ["Page backward" gnus-summary-prev-page
2256          ,@(if (featurep 'xemacs) '(t)
2257              '(:help "Show previous page of article"))]
2258         ["Line forward" gnus-summary-scroll-up t])
2259        ("Move"
2260         ["Next unread article" gnus-summary-next-unread-article t]
2261         ["Previous unread article" gnus-summary-prev-unread-article t]
2262         ["Next article" gnus-summary-next-article t]
2263         ["Previous article" gnus-summary-prev-article t]
2264         ["Next unread subject" gnus-summary-next-unread-subject t]
2265         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2266         ["Next article same subject" gnus-summary-next-same-subject t]
2267         ["Previous article same subject" gnus-summary-prev-same-subject t]
2268         ["First unread article" gnus-summary-first-unread-article t]
2269         ["Best unread article" gnus-summary-best-unread-article t]
2270         ["Go to subject number..." gnus-summary-goto-subject t]
2271         ["Go to article number..." gnus-summary-goto-article t]
2272         ["Go to the last article" gnus-summary-goto-last-article t]
2273         ["Pop article off history" gnus-summary-pop-article t])
2274        ("Sort"
2275         ["Sort by number" gnus-summary-sort-by-number t]
2276         ["Sort by author" gnus-summary-sort-by-author t]
2277         ["Sort by subject" gnus-summary-sort-by-subject t]
2278         ["Sort by date" gnus-summary-sort-by-date t]
2279         ["Sort by score" gnus-summary-sort-by-score t]
2280         ["Sort by lines" gnus-summary-sort-by-lines t]
2281         ["Sort by characters" gnus-summary-sort-by-chars t]
2282         ["Original sort" gnus-summary-sort-by-original t])
2283        ("Help"
2284         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2285         ["Describe group" gnus-summary-describe-group t]
2286         ["Read manual" gnus-info-find-node t])
2287        ("Modes"
2288         ["Pick and read" gnus-pick-mode t]
2289         ["Binary" gnus-binary-mode t])
2290        ("Regeneration"
2291         ["Regenerate" gnus-summary-prepare t]
2292         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2293         ["Toggle threading" gnus-summary-toggle-threads t])
2294        ["See old articles" gnus-summary-insert-old-articles t]
2295        ["See new articles" gnus-summary-insert-new-articles t]
2296        ["Filter articles..." gnus-summary-execute-command t]
2297        ["Run command on subjects..." gnus-summary-universal-argument t]
2298        ["Search articles forward..." gnus-summary-search-article-forward t]
2299        ["Search articles backward..." gnus-summary-search-article-backward t]
2300        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2301        ["Expand window" gnus-summary-expand-window t]
2302        ["Expire expirable articles" gnus-summary-expire-articles
2303         (gnus-check-backend-function
2304          'request-expire-articles gnus-newsgroup-name)]
2305        ["Edit local kill file" gnus-summary-edit-local-kill t]
2306        ["Edit main kill file" gnus-summary-edit-global-kill t]
2307        ["Edit group parameters" gnus-summary-edit-parameters t]
2308        ["Customize group parameters" gnus-summary-customize-parameters t]
2309        ["Send a bug report" gnus-bug t]
2310        ("Exit"
2311         ["Catchup and exit" gnus-summary-catchup-and-exit
2312          ,@(if (featurep 'xemacs) '(t)
2313              '(:help "Mark unread articles in this group as read, then exit"))]
2314         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2315         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2316         ["Exit group" gnus-summary-exit
2317          ,@(if (featurep 'xemacs) '(t)
2318              '(:help "Exit current group, return to group selection mode"))]
2319         ["Exit group without updating" gnus-summary-exit-no-update t]
2320         ["Exit and goto next group" gnus-summary-next-group t]
2321         ["Exit and goto prev group" gnus-summary-prev-group t]
2322         ["Reselect group" gnus-summary-reselect-current-group t]
2323         ["Rescan group" gnus-summary-rescan-group t]
2324         ["Update dribble" gnus-summary-save-newsrc t])))
2325
2326     (gnus-run-hooks 'gnus-summary-menu-hook)))
2327
2328 (defvar gnus-summary-tool-bar-map nil)
2329
2330 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2331 ;; NB: A new function tool-bar-local-item-from-menu is added in Emacs
2332 ;; 21.2.50+.  Considering many users use Emacs 21, use
2333 ;; tool-bar-add-item-from-menu here.
2334 (defun gnus-summary-make-tool-bar ()
2335   (if (and
2336        (condition-case nil (require 'tool-bar) (error nil))
2337        (fboundp 'tool-bar-add-item-from-menu)
2338        (default-value 'tool-bar-mode)
2339        (not gnus-summary-tool-bar-map))
2340       (setq gnus-summary-tool-bar-map
2341             (let ((tool-bar-map (make-sparse-keymap))
2342                   (load-path (mm-image-load-path)))
2343               (tool-bar-add-item-from-menu
2344                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2345               (tool-bar-add-item-from-menu
2346                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2347               (tool-bar-add-item-from-menu
2348                'gnus-summary-post-news "post" gnus-summary-mode-map)
2349               (tool-bar-add-item-from-menu
2350                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2351               (tool-bar-add-item-from-menu
2352                'gnus-summary-followup "followup" gnus-summary-mode-map)
2353               (tool-bar-add-item-from-menu
2354                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2355               (tool-bar-add-item-from-menu
2356                'gnus-summary-reply "reply" gnus-summary-mode-map)
2357               (tool-bar-add-item-from-menu
2358                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2359               (tool-bar-add-item-from-menu
2360                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2361               (tool-bar-add-item-from-menu
2362                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2363               (tool-bar-add-item-from-menu
2364                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2365               (tool-bar-add-item-from-menu
2366                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2367               (tool-bar-add-item-from-menu
2368                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2369               (tool-bar-add-item-from-menu
2370                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2371               (tool-bar-add-item-from-menu
2372                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2373               tool-bar-map)))
2374   (if gnus-summary-tool-bar-map
2375       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2376
2377 (defun gnus-score-set-default (var value)
2378   "A version of set that updates the GNU Emacs menu-bar."
2379   (set var value)
2380   ;; It is the message that forces the active status to be updated.
2381   (message ""))
2382
2383 (defun gnus-make-score-map (type)
2384   "Make a summary score map of type TYPE."
2385   (if t
2386       nil
2387     (let ((headers '(("author" "from" string)
2388                      ("subject" "subject" string)
2389                      ("article body" "body" string)
2390                      ("article head" "head" string)
2391                      ("xref" "xref" string)
2392                      ("extra header" "extra" string)
2393                      ("lines" "lines" number)
2394                      ("followups to author" "followup" string)))
2395           (types '((number ("less than" <)
2396                            ("greater than" >)
2397                            ("equal" =))
2398                    (string ("substring" s)
2399                            ("exact string" e)
2400                            ("fuzzy string" f)
2401                            ("regexp" r))))
2402           (perms '(("temporary" (current-time-string))
2403                    ("permanent" nil)
2404                    ("immediate" now)))
2405           header)
2406       (list
2407        (apply
2408         'nconc
2409         (list
2410          (if (eq type 'lower)
2411              "Lower score"
2412            "Increase score"))
2413         (let (outh)
2414           (while headers
2415             (setq header (car headers))
2416             (setq outh
2417                   (cons
2418                    (apply
2419                     'nconc
2420                     (list (car header))
2421                     (let ((ts (cdr (assoc (nth 2 header) types)))
2422                           outt)
2423                       (while ts
2424                         (setq outt
2425                               (cons
2426                                (apply
2427                                 'nconc
2428                                 (list (caar ts))
2429                                 (let ((ps perms)
2430                                       outp)
2431                                   (while ps
2432                                     (setq outp
2433                                           (cons
2434                                            (vector
2435                                             (caar ps)
2436                                             (list
2437                                              'gnus-summary-score-entry
2438                                              (nth 1 header)
2439                                              (if (or (string= (nth 1 header)
2440                                                               "head")
2441                                                      (string= (nth 1 header)
2442                                                               "body"))
2443                                                  ""
2444                                                (list 'gnus-summary-header
2445                                                      (nth 1 header)))
2446                                              (list 'quote (nth 1 (car ts)))
2447                                              (list 'gnus-score-delta-default
2448                                                    nil)
2449                                              (nth 1 (car ps))
2450                                              t)
2451                                             t)
2452                                            outp))
2453                                     (setq ps (cdr ps)))
2454                                   (list (nreverse outp))))
2455                                outt))
2456                         (setq ts (cdr ts)))
2457                       (list (nreverse outt))))
2458                    outh))
2459             (setq headers (cdr headers)))
2460           (list (nreverse outh))))))))
2461
2462 \f
2463
2464 (defun gnus-summary-mode (&optional group)
2465   "Major mode for reading articles.
2466
2467 All normal editing commands are switched off.
2468 \\<gnus-summary-mode-map>
2469 Each line in this buffer represents one article.  To read an
2470 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2471 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2472 respectively.
2473
2474 You can also post articles and send mail from this buffer.  To
2475 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2476 of an article, type `\\[gnus-summary-reply]'.
2477
2478 There are approx. one gazillion commands you can execute in this
2479 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2480
2481 The following commands are available:
2482
2483 \\{gnus-summary-mode-map}"
2484   (interactive)
2485   (kill-all-local-variables)
2486   (when (gnus-visual-p 'summary-menu 'menu)
2487     (gnus-summary-make-menu-bar)
2488     (gnus-summary-make-tool-bar))
2489   (gnus-summary-make-local-variables)
2490   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2491     (gnus-summary-make-local-variables))
2492   (gnus-make-thread-indent-array)
2493   (gnus-simplify-mode-line)
2494   (setq major-mode 'gnus-summary-mode)
2495   (setq mode-name "Summary")
2496   (make-local-variable 'minor-mode-alist)
2497   (use-local-map gnus-summary-mode-map)
2498   (buffer-disable-undo)
2499   (setq buffer-read-only t)             ;Disable modification
2500   (setq truncate-lines t)
2501   (setq selective-display t)
2502   (setq selective-display-ellipses t)   ;Display `...'
2503   (gnus-summary-set-display-table)
2504   (gnus-set-default-directory)
2505   (setq gnus-newsgroup-name group)
2506   (unless (gnus-news-group-p group)
2507     (setq gnus-newsgroup-incorporated
2508           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2509   (make-local-variable 'gnus-summary-line-format)
2510   (make-local-variable 'gnus-summary-line-format-spec)
2511   (make-local-variable 'gnus-summary-dummy-line-format)
2512   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2513   (make-local-variable 'gnus-summary-mark-positions)
2514   (make-local-hook 'pre-command-hook)
2515   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2516   (gnus-run-hooks 'gnus-summary-mode-hook)
2517   (turn-on-gnus-mailing-list-mode)
2518   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2519   (gnus-update-summary-mark-positions))
2520
2521 (defun gnus-summary-make-local-variables ()
2522   "Make all the local summary buffer variables."
2523   (let (global)
2524     (dolist (local gnus-summary-local-variables)
2525       (if (consp local)
2526           (progn
2527             (if (eq (cdr local) 'global)
2528                 ;; Copy the global value of the variable.
2529                 (setq global (symbol-value (car local)))
2530               ;; Use the value from the list.
2531               (setq global (eval (cdr local))))
2532             (set (make-local-variable (car local)) global))
2533         ;; Simple nil-valued local variable.
2534         (set (make-local-variable local) nil)))))
2535
2536 (defun gnus-summary-clear-local-variables ()
2537   (let ((locals gnus-summary-local-variables))
2538     (while locals
2539       (if (consp (car locals))
2540           (and (vectorp (caar locals))
2541                (set (caar locals) nil))
2542         (and (vectorp (car locals))
2543              (set (car locals) nil)))
2544       (setq locals (cdr locals)))))
2545
2546 ;; Summary data functions.
2547
2548 (defmacro gnus-data-number (data)
2549   `(car ,data))
2550
2551 (defmacro gnus-data-set-number (data number)
2552   `(setcar ,data ,number))
2553
2554 (defmacro gnus-data-mark (data)
2555   `(nth 1 ,data))
2556
2557 (defmacro gnus-data-set-mark (data mark)
2558   `(setcar (nthcdr 1 ,data) ,mark))
2559
2560 (defmacro gnus-data-pos (data)
2561   `(nth 2 ,data))
2562
2563 (defmacro gnus-data-set-pos (data pos)
2564   `(setcar (nthcdr 2 ,data) ,pos))
2565
2566 (defmacro gnus-data-header (data)
2567   `(nth 3 ,data))
2568
2569 (defmacro gnus-data-set-header (data header)
2570   `(setcar (nthcdr 3 ,data) ,header))
2571
2572 (defmacro gnus-data-level (data)
2573   `(nth 4 ,data))
2574
2575 (defmacro gnus-data-unread-p (data)
2576   `(= (nth 1 ,data) gnus-unread-mark))
2577
2578 (defmacro gnus-data-read-p (data)
2579   `(/= (nth 1 ,data) gnus-unread-mark))
2580
2581 (defmacro gnus-data-pseudo-p (data)
2582   `(consp (nth 3 ,data)))
2583
2584 (defmacro gnus-data-find (number)
2585   `(assq ,number gnus-newsgroup-data))
2586
2587 (defmacro gnus-data-find-list (number &optional data)
2588   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2589      (memq (assq ,number bdata)
2590            bdata)))
2591
2592 (defmacro gnus-data-make (number mark pos header level)
2593   `(list ,number ,mark ,pos ,header ,level))
2594
2595 (defun gnus-data-enter (after-article number mark pos header level offset)
2596   (let ((data (gnus-data-find-list after-article)))
2597     (unless data
2598       (error "No such article: %d" after-article))
2599     (setcdr data (cons (gnus-data-make number mark pos header level)
2600                        (cdr data)))
2601     (setq gnus-newsgroup-data-reverse nil)
2602     (gnus-data-update-list (cddr data) offset)))
2603
2604 (defun gnus-data-enter-list (after-article list &optional offset)
2605   (when list
2606     (let ((data (and after-article (gnus-data-find-list after-article)))
2607           (ilist list))
2608       (if (not (or data
2609                    after-article))
2610           (let ((odata gnus-newsgroup-data))
2611             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2612             (when offset
2613               (gnus-data-update-list odata offset)))
2614         ;; Find the last element in the list to be spliced into the main
2615         ;; list.
2616         (while (cdr list)
2617           (setq list (cdr list)))
2618         (if (not data)
2619             (progn
2620               (setcdr list gnus-newsgroup-data)
2621               (setq gnus-newsgroup-data ilist)
2622               (when offset
2623                 (gnus-data-update-list (cdr list) offset)))
2624           (setcdr list (cdr data))
2625           (setcdr data ilist)
2626           (when offset
2627             (gnus-data-update-list (cdr list) offset))))
2628       (setq gnus-newsgroup-data-reverse nil))))
2629
2630 (defun gnus-data-remove (article &optional offset)
2631   (let ((data gnus-newsgroup-data))
2632     (if (= (gnus-data-number (car data)) article)
2633         (progn
2634           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2635                 gnus-newsgroup-data-reverse nil)
2636           (when offset
2637             (gnus-data-update-list gnus-newsgroup-data offset)))
2638       (while (cdr data)
2639         (when (= (gnus-data-number (cadr data)) article)
2640           (setcdr data (cddr data))
2641           (when offset
2642             (gnus-data-update-list (cdr data) offset))
2643           (setq data nil
2644                 gnus-newsgroup-data-reverse nil))
2645         (setq data (cdr data))))))
2646
2647 (defmacro gnus-data-list (backward)
2648   `(if ,backward
2649        (or gnus-newsgroup-data-reverse
2650            (setq gnus-newsgroup-data-reverse
2651                  (reverse gnus-newsgroup-data)))
2652      gnus-newsgroup-data))
2653
2654 (defun gnus-data-update-list (data offset)
2655   "Add OFFSET to the POS of all data entries in DATA."
2656   (setq gnus-newsgroup-data-reverse nil)
2657   (while data
2658     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2659     (setq data (cdr data))))
2660
2661 (defun gnus-summary-article-pseudo-p (article)
2662   "Say whether this article is a pseudo article or not."
2663   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2664
2665 (defmacro gnus-summary-article-sparse-p (article)
2666   "Say whether this article is a sparse article or not."
2667   `(memq ,article gnus-newsgroup-sparse))
2668
2669 (defmacro gnus-summary-article-ancient-p (article)
2670   "Say whether this article is a sparse article or not."
2671   `(memq ,article gnus-newsgroup-ancient))
2672
2673 (defun gnus-article-parent-p (number)
2674   "Say whether this article is a parent or not."
2675   (let ((data (gnus-data-find-list number)))
2676     (and (cdr data)                     ; There has to be an article after...
2677          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2678             (gnus-data-level (nth 1 data))))))
2679
2680 (defun gnus-article-children (number)
2681   "Return a list of all children to NUMBER."
2682   (let* ((data (gnus-data-find-list number))
2683          (level (gnus-data-level (car data)))
2684          children)
2685     (setq data (cdr data))
2686     (while (and data
2687                 (= (gnus-data-level (car data)) (1+ level)))
2688       (push (gnus-data-number (car data)) children)
2689       (setq data (cdr data)))
2690     children))
2691
2692 (defmacro gnus-summary-skip-intangible ()
2693   "If the current article is intangible, then jump to a different article."
2694   '(let ((to (get-text-property (point) 'gnus-intangible)))
2695      (and to (gnus-summary-goto-subject to))))
2696
2697 (defmacro gnus-summary-article-intangible-p ()
2698   "Say whether this article is intangible or not."
2699   '(get-text-property (point) 'gnus-intangible))
2700
2701 (defun gnus-article-read-p (article)
2702   "Say whether ARTICLE is read or not."
2703   (not (or (memq article gnus-newsgroup-marked)
2704            (memq article gnus-newsgroup-unreads)
2705            (memq article gnus-newsgroup-unselected)
2706            (memq article gnus-newsgroup-dormant))))
2707
2708 ;; Some summary mode macros.
2709
2710 (defmacro gnus-summary-article-number ()
2711   "The article number of the article on the current line.
2712 If there isn's an article number here, then we return the current
2713 article number."
2714   '(progn
2715      (gnus-summary-skip-intangible)
2716      (or (get-text-property (point) 'gnus-number)
2717          (gnus-summary-last-subject))))
2718
2719 (defmacro gnus-summary-article-header (&optional number)
2720   "Return the header of article NUMBER."
2721   `(gnus-data-header (gnus-data-find
2722                       ,(or number '(gnus-summary-article-number)))))
2723
2724 (defmacro gnus-summary-thread-level (&optional number)
2725   "Return the level of thread that starts with article NUMBER."
2726   `(if (and (eq gnus-summary-make-false-root 'dummy)
2727             (get-text-property (point) 'gnus-intangible))
2728        0
2729      (gnus-data-level (gnus-data-find
2730                        ,(or number '(gnus-summary-article-number))))))
2731
2732 (defmacro gnus-summary-article-mark (&optional number)
2733   "Return the mark of article NUMBER."
2734   `(gnus-data-mark (gnus-data-find
2735                     ,(or number '(gnus-summary-article-number)))))
2736
2737 (defmacro gnus-summary-article-pos (&optional number)
2738   "Return the position of the line of article NUMBER."
2739   `(gnus-data-pos (gnus-data-find
2740                    ,(or number '(gnus-summary-article-number)))))
2741
2742 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2743 (defmacro gnus-summary-article-subject (&optional number)
2744   "Return current subject string or nil if nothing."
2745   `(let ((headers
2746           ,(if number
2747                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2748              '(gnus-data-header (assq (gnus-summary-article-number)
2749                                       gnus-newsgroup-data)))))
2750      (and headers
2751           (vectorp headers)
2752           (mail-header-subject headers))))
2753
2754 (defmacro gnus-summary-article-score (&optional number)
2755   "Return current article score."
2756   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2757                   gnus-newsgroup-scored))
2758        gnus-summary-default-score 0))
2759
2760 (defun gnus-summary-article-children (&optional number)
2761   "Return a list of article numbers that are children of article NUMBER."
2762   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2763          (level (gnus-data-level (car data)))
2764          l children)
2765     (while (and (setq data (cdr data))
2766                 (> (setq l (gnus-data-level (car data))) level))
2767       (and (= (1+ level) l)
2768            (push (gnus-data-number (car data))
2769                  children)))
2770     (nreverse children)))
2771
2772 (defun gnus-summary-article-parent (&optional number)
2773   "Return the article number of the parent of article NUMBER."
2774   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2775                                     (gnus-data-list t)))
2776          (level (gnus-data-level (car data))))
2777     (if (zerop level)
2778         ()                              ; This is a root.
2779       ;; We search until we find an article with a level less than
2780       ;; this one.  That function has to be the parent.
2781       (while (and (setq data (cdr data))
2782                   (not (< (gnus-data-level (car data)) level))))
2783       (and data (gnus-data-number (car data))))))
2784
2785 (defun gnus-unread-mark-p (mark)
2786   "Say whether MARK is the unread mark."
2787   (= mark gnus-unread-mark))
2788
2789 (defun gnus-read-mark-p (mark)
2790   "Say whether MARK is one of the marks that mark as read.
2791 This is all marks except unread, ticked, dormant, and expirable."
2792   (not (or (= mark gnus-unread-mark)
2793            (= mark gnus-ticked-mark)
2794            (= mark gnus-dormant-mark)
2795            (= mark gnus-expirable-mark))))
2796
2797 (defmacro gnus-article-mark (number)
2798   "Return the MARK of article NUMBER.
2799 This macro should only be used when computing the mark the \"first\"
2800 time; i.e., when generating the summary lines.  After that,
2801 `gnus-summary-article-mark' should be used to examine the
2802 marks of articles."
2803   `(cond
2804     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2805     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2806     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2807     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2808     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2809     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2810     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2811     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2812            gnus-ancient-mark))))
2813
2814 ;; Saving hidden threads.
2815
2816 (defmacro gnus-save-hidden-threads (&rest forms)
2817   "Save hidden threads, eval FORMS, and restore the hidden threads."
2818   (let ((config (make-symbol "config")))
2819     `(let ((,config (gnus-hidden-threads-configuration)))
2820        (unwind-protect
2821            (save-excursion
2822              ,@forms)
2823          (gnus-restore-hidden-threads-configuration ,config)))))
2824 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2825 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2826
2827 (defun gnus-data-compute-positions ()
2828   "Compute the positions of all articles."
2829   (setq gnus-newsgroup-data-reverse nil)
2830   (let ((data gnus-newsgroup-data))
2831     (save-excursion
2832       (gnus-save-hidden-threads
2833         (gnus-summary-show-all-threads)
2834         (goto-char (point-min))
2835         (while data
2836           (while (get-text-property (point) 'gnus-intangible)
2837             (forward-line 1))
2838           (gnus-data-set-pos (car data) (+ (point) 3))
2839           (setq data (cdr data))
2840           (forward-line 1))))))
2841
2842 (defun gnus-hidden-threads-configuration ()
2843   "Return the current hidden threads configuration."
2844   (save-excursion
2845     (let (config)
2846       (goto-char (point-min))
2847       (while (search-forward "\r" nil t)
2848         (push (1- (point)) config))
2849       config)))
2850
2851 (defun gnus-restore-hidden-threads-configuration (config)
2852   "Restore hidden threads configuration from CONFIG."
2853   (save-excursion
2854     (let (point buffer-read-only)
2855       (while (setq point (pop config))
2856         (when (and (< point (point-max))
2857                    (goto-char point)
2858                    (eq (char-after) ?\n))
2859           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2860
2861 ;; Various summary mode internalish functions.
2862
2863 (defun gnus-mouse-pick-article (e)
2864   (interactive "e")
2865   (mouse-set-point e)
2866   (gnus-summary-next-page nil t))
2867
2868 (defun gnus-summary-set-display-table ()
2869   "Change the display table.
2870 Odd characters have a tendency to mess
2871 up nicely formatted displays - we make all possible glyphs
2872 display only a single character."
2873
2874   ;; We start from the standard display table, if any.
2875   (let ((table (or (copy-sequence standard-display-table)
2876                    (make-display-table)))
2877         (i 32))
2878     ;; Nix out all the control chars...
2879     (while (>= (setq i (1- i)) 0)
2880       (aset table i [??]))
2881     ;; ... but not newline and cr, of course.  (cr is necessary for the
2882     ;; selective display).
2883     (aset table ?\n nil)
2884     (aset table ?\r nil)
2885     ;; We keep TAB as well.
2886     (aset table ?\t nil)
2887     ;; We nix out any glyphs over 126 that are not set already.
2888     (let ((i 256))
2889       (while (>= (setq i (1- i)) 127)
2890         ;; Only modify if the entry is nil.
2891         (unless (aref table i)
2892           (aset table i [??]))))
2893     (setq buffer-display-table table)))
2894
2895 (defun gnus-summary-set-article-display-arrow (pos)
2896   "Update the overlay arrow to point to line at position POS."
2897   (when (and gnus-summary-display-arrow
2898              (boundp 'overlay-arrow-position)
2899              (boundp 'overlay-arrow-string))
2900     (save-excursion
2901       (goto-char pos)
2902       (beginning-of-line)
2903       (unless overlay-arrow-position
2904         (setq overlay-arrow-position (make-marker)))
2905       (setq overlay-arrow-string "=>"
2906             overlay-arrow-position (set-marker overlay-arrow-position
2907                                                (point)
2908                                                (current-buffer))))))
2909
2910 (defun gnus-summary-buffer-name (group)
2911   "Return the summary buffer name of GROUP."
2912   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2913
2914 (defun gnus-summary-setup-buffer (group)
2915   "Initialize summary buffer."
2916   (let ((buffer (gnus-summary-buffer-name group))
2917         (dead-name (concat "*Dead Summary "
2918                            (gnus-group-decoded-name group) "*")))
2919     ;; If a dead summary buffer exists, we kill it.
2920     (when (gnus-buffer-live-p dead-name)
2921       (gnus-kill-buffer dead-name))
2922     (if (get-buffer buffer)
2923         (progn
2924           (set-buffer buffer)
2925           (setq gnus-summary-buffer (current-buffer))
2926           (not gnus-newsgroup-prepared))
2927       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2928       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2929       (gnus-summary-mode group)
2930       (when gnus-carpal
2931         (gnus-carpal-setup-buffer 'summary))
2932       (unless gnus-single-article-buffer
2933         (make-local-variable 'gnus-article-buffer)
2934         (make-local-variable 'gnus-article-current)
2935         (make-local-variable 'gnus-original-article-buffer))
2936       (setq gnus-newsgroup-name group)
2937       ;; Set any local variables in the group parameters.
2938       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2939       t)))
2940
2941 (defun gnus-set-global-variables ()
2942   "Set the global equivalents of the buffer-local variables.
2943 They are set to the latest values they had.  These reflect the summary
2944 buffer that was in action when the last article was fetched."
2945   (when (eq major-mode 'gnus-summary-mode)
2946     (setq gnus-summary-buffer (current-buffer))
2947     (let ((name gnus-newsgroup-name)
2948           (marked gnus-newsgroup-marked)
2949           (unread gnus-newsgroup-unreads)
2950           (headers gnus-current-headers)
2951           (data gnus-newsgroup-data)
2952           (summary gnus-summary-buffer)
2953           (article-buffer gnus-article-buffer)
2954           (original gnus-original-article-buffer)
2955           (gac gnus-article-current)
2956           (reffed gnus-reffed-article-number)
2957           (score-file gnus-current-score-file)
2958           (default-charset gnus-newsgroup-charset)
2959           vlist)
2960       (let ((locals gnus-newsgroup-variables))
2961         (while locals
2962           (if (consp (car locals))
2963               (push (eval (caar locals)) vlist)
2964             (push (eval (car locals)) vlist))
2965           (setq locals (cdr locals)))
2966         (setq vlist (nreverse vlist)))
2967       (save-excursion
2968         (set-buffer gnus-group-buffer)
2969         (setq gnus-newsgroup-name name
2970               gnus-newsgroup-marked marked
2971               gnus-newsgroup-unreads unread
2972               gnus-current-headers headers
2973               gnus-newsgroup-data data
2974               gnus-article-current gac
2975               gnus-summary-buffer summary
2976               gnus-article-buffer article-buffer
2977               gnus-original-article-buffer original
2978               gnus-reffed-article-number reffed
2979               gnus-current-score-file score-file
2980               gnus-newsgroup-charset default-charset)
2981         (let ((locals gnus-newsgroup-variables))
2982           (while locals
2983             (if (consp (car locals))
2984                 (set (caar locals) (pop vlist))
2985               (set (car locals) (pop vlist)))
2986             (setq locals (cdr locals))))
2987         ;; The article buffer also has local variables.
2988         (when (gnus-buffer-live-p gnus-article-buffer)
2989           (set-buffer gnus-article-buffer)
2990           (setq gnus-summary-buffer summary))))))
2991
2992 (defun gnus-summary-article-unread-p (article)
2993   "Say whether ARTICLE is unread or not."
2994   (memq article gnus-newsgroup-unreads))
2995
2996 (defun gnus-summary-first-article-p (&optional article)
2997   "Return whether ARTICLE is the first article in the buffer."
2998   (if (not (setq article (or article (gnus-summary-article-number))))
2999       nil
3000     (eq article (caar gnus-newsgroup-data))))
3001
3002 (defun gnus-summary-last-article-p (&optional article)
3003   "Return whether ARTICLE is the last article in the buffer."
3004   (if (not (setq article (or article (gnus-summary-article-number))))
3005       ;; All non-existent numbers are the last article.  :-)
3006       t
3007     (not (cdr (gnus-data-find-list article)))))
3008
3009 (defun gnus-make-thread-indent-array ()
3010   (let ((n 200))
3011     (unless (and gnus-thread-indent-array
3012                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3013       (setq gnus-thread-indent-array (make-vector 201 "")
3014             gnus-thread-indent-array-level gnus-thread-indent-level)
3015       (while (>= n 0)
3016         (aset gnus-thread-indent-array n
3017               (make-string (* n gnus-thread-indent-level) ? ))
3018         (setq n (1- n))))))
3019
3020 (defun gnus-update-summary-mark-positions ()
3021   "Compute where the summary marks are to go."
3022   (save-excursion
3023     (when (gnus-buffer-exists-p gnus-summary-buffer)
3024       (set-buffer gnus-summary-buffer))
3025     (let ((gnus-replied-mark 129)
3026           (gnus-score-below-mark 130)
3027           (gnus-score-over-mark 130)
3028           (gnus-download-mark 131)
3029           (spec gnus-summary-line-format-spec)
3030           gnus-visual pos)
3031       (save-excursion
3032         (gnus-set-work-buffer)
3033         (let ((gnus-summary-line-format-spec spec)
3034               (gnus-newsgroup-downloadable '((0 . t))))
3035           (gnus-summary-insert-line
3036            (make-full-mail-header 0 "" "nobody"
3037                                   "05 Apr 2001 23:33:09 +0400"
3038                                   "" "" 0 0 "" nil)
3039            0 nil 128 t nil "" nil 1)
3040           (goto-char (point-min))
3041           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3042                                              (- (point) 2)))))
3043           (goto-char (point-min))
3044           (push (cons 'replied (and (search-forward "\201" nil t)
3045                                     (- (point) 2)))
3046                 pos)
3047           (goto-char (point-min))
3048           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
3049                 pos)
3050           (goto-char (point-min))
3051           (push (cons 'download
3052                       (and (search-forward "\203" nil t) (- (point) 2)))
3053                 pos)))
3054       (setq gnus-summary-mark-positions pos))))
3055
3056 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3057   "Insert a dummy root in the summary buffer."
3058   (beginning-of-line)
3059   (gnus-add-text-properties
3060    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3061    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3062
3063 (defun gnus-summary-extract-address-component (from)
3064   (or (car (funcall gnus-extract-address-components from))
3065       from))
3066
3067 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3068   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3069                                 default-mime-charset)))
3070     ;; Is it really necessary to do this next part for each summary line?
3071     ;; Luckily, doesn't seem to slow things down much.
3072     (or
3073      (and gnus-ignored-from-addresses
3074           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3075           (let ((extra-headers (mail-header-extra header))
3076                 to
3077                 newsgroups)
3078             (cond
3079              ((setq to (cdr (assq 'To extra-headers)))
3080               (concat "-> "
3081                       (inline
3082                         (gnus-summary-extract-address-component
3083                          (funcall gnus-decode-encoded-word-function to)))))
3084              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3085               (concat "=> " newsgroups)))))
3086      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3087
3088 (defun gnus-summary-insert-line (gnus-tmp-header
3089                                  gnus-tmp-level gnus-tmp-current
3090                                  gnus-tmp-unread gnus-tmp-replied
3091                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3092                                  &optional gnus-tmp-dummy gnus-tmp-score
3093                                  gnus-tmp-process)
3094   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3095          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3096          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3097          (gnus-tmp-score-char
3098           (if (or (null gnus-summary-default-score)
3099                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3100                       gnus-summary-zcore-fuzz))
3101               ?\ ;;;Whitespace
3102             (if (< gnus-tmp-score gnus-summary-default-score)
3103                 gnus-score-below-mark gnus-score-over-mark)))
3104          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3105          (gnus-tmp-replied
3106           (cond (gnus-tmp-process gnus-process-mark)
3107                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3108                  gnus-cached-mark)
3109                 (gnus-tmp-replied gnus-replied-mark)
3110                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3111                  gnus-forwarded-mark)
3112                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3113                  gnus-saved-mark)
3114                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3115                  gnus-recent-mark)
3116                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3117                  gnus-unseen-mark)
3118                 (t gnus-no-mark)))
3119          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3120          (gnus-tmp-name
3121           (cond
3122            ((string-match "<[^>]+> *$" gnus-tmp-from)
3123             (let ((beg (match-beginning 0)))
3124               (or (and (string-match "^\".+\"" gnus-tmp-from)
3125                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3126                   (substring gnus-tmp-from 0 beg))))
3127            ((string-match "(.+)" gnus-tmp-from)
3128             (substring gnus-tmp-from
3129                        (1+ (match-beginning 0)) (1- (match-end 0))))
3130            (t gnus-tmp-from)))
3131          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3132          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3133          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3134          (buffer-read-only nil))
3135     (when (string= gnus-tmp-name "")
3136       (setq gnus-tmp-name gnus-tmp-from))
3137     (unless (numberp gnus-tmp-lines)
3138       (setq gnus-tmp-lines -1))
3139     (if (= gnus-tmp-lines -1)
3140         (setq gnus-tmp-lines "?")
3141       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3142     (gnus-put-text-property-excluding-characters-with-faces
3143      (point)
3144      (progn (eval gnus-summary-line-format-spec) (point))
3145      'gnus-number gnus-tmp-number)
3146     (when (gnus-visual-p 'summary-highlight 'highlight)
3147       (forward-line -1)
3148       (gnus-run-hooks 'gnus-summary-update-hook)
3149       (forward-line 1))))
3150
3151 (defun gnus-summary-update-line (&optional dont-update)
3152   "Update summary line after change."
3153   (when (and gnus-summary-default-score
3154              (not gnus-summary-inhibit-highlight))
3155     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3156            (article (gnus-summary-article-number))
3157            (score (gnus-summary-article-score article)))
3158       (unless dont-update
3159         (if (and gnus-summary-mark-below
3160                  (< (gnus-summary-article-score)
3161                     gnus-summary-mark-below))
3162             ;; This article has a low score, so we mark it as read.
3163             (when (memq article gnus-newsgroup-unreads)
3164               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3165           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3166             ;; This article was previously marked as read on account
3167             ;; of a low score, but now it has risen, so we mark it as
3168             ;; unread.
3169             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3170         (gnus-summary-update-mark
3171          (if (or (null gnus-summary-default-score)
3172                  (<= (abs (- score gnus-summary-default-score))
3173                      gnus-summary-zcore-fuzz))
3174              ?\ ;;;Whitespace
3175            (if (< score gnus-summary-default-score)
3176                gnus-score-below-mark gnus-score-over-mark))
3177          'score))
3178       ;; Do visual highlighting.
3179       (when (gnus-visual-p 'summary-highlight 'highlight)
3180         (gnus-run-hooks 'gnus-summary-update-hook)))))
3181
3182 (defvar gnus-tmp-new-adopts nil)
3183
3184 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3185   "Return the number of articles in THREAD.
3186 This may be 0 in some cases -- if none of the articles in
3187 the thread are to be displayed."
3188   (let* ((number
3189           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3190           (cond
3191            ((not (listp thread))
3192             1)
3193            ((and (consp thread) (cdr thread))
3194             (apply
3195              '+ 1 (mapcar
3196                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3197            ((null thread)
3198             1)
3199            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3200             1)
3201            (t 0))))
3202     (when (and level (zerop level) gnus-tmp-new-adopts)
3203       (incf number
3204             (apply '+ (mapcar
3205                        'gnus-summary-number-of-articles-in-thread
3206                        gnus-tmp-new-adopts))))
3207     (if char
3208         (if (> number 1) gnus-not-empty-thread-mark
3209           gnus-empty-thread-mark)
3210       number)))
3211
3212 (defun gnus-summary-set-local-parameters (group)
3213   "Go through the local params of GROUP and set all variable specs in that list."
3214   (let ((params (gnus-group-find-parameter group))
3215         (vars '(quit-config))           ; Ignore quit-config.
3216         elem)
3217     (while params
3218       (setq elem (car params)
3219             params (cdr params))
3220       (and (consp elem)                 ; Has to be a cons.
3221            (consp (cdr elem))           ; The cdr has to be a list.
3222            (symbolp (car elem))         ; Has to be a symbol in there.
3223            (not (memq (car elem) vars))
3224            (ignore-errors               ; So we set it.
3225              (push (car elem) vars)
3226              (make-local-variable (car elem))
3227              (set (car elem) (eval (nth 1 elem))))))))
3228
3229 (defun gnus-summary-read-group (group &optional show-all no-article
3230                                       kill-buffer no-display backward
3231                                       select-articles)
3232   "Start reading news in newsgroup GROUP.
3233 If SHOW-ALL is non-nil, already read articles are also listed.
3234 If NO-ARTICLE is non-nil, no article is selected initially.
3235 If NO-DISPLAY, don't generate a summary buffer."
3236   (let (result)
3237     (while (and group
3238                 (null (setq result
3239                             (let ((gnus-auto-select-next nil))
3240                               (or (gnus-summary-read-group-1
3241                                    group show-all no-article
3242                                    kill-buffer no-display
3243                                    select-articles)
3244                                   (setq show-all nil
3245                                         select-articles nil)))))
3246                 (eq gnus-auto-select-next 'quietly))
3247       (set-buffer gnus-group-buffer)
3248       ;; The entry function called above goes to the next
3249       ;; group automatically, so we go two groups back
3250       ;; if we are searching for the previous group.
3251       (when backward
3252         (gnus-group-prev-unread-group 2))
3253       (if (not (equal group (gnus-group-group-name)))
3254           (setq group (gnus-group-group-name))
3255         (setq group nil)))
3256     result))
3257
3258 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3259   "Directly jump to the other GROUP from summary buffer.
3260 If SHOW-ALL is non-nil, already read articles are also listed."
3261   (interactive
3262    (if (eq gnus-summary-buffer (current-buffer))
3263        (list (completing-read
3264               "Group: " gnus-active-hashtb nil t
3265               (when (and gnus-newsgroup-name
3266                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3267                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3268               'gnus-group-history)
3269              current-prefix-arg)
3270      (error "%s must be invoked from a gnus summary buffer." this-command)))
3271   (unless (or (zerop (length group))
3272               (and gnus-newsgroup-name
3273                    (string-equal gnus-newsgroup-name group)))
3274     (gnus-summary-exit)
3275     (gnus-summary-read-group group show-all
3276                              gnus-dont-select-after-jump-to-other-group)))
3277
3278 (defun gnus-summary-read-group-1 (group show-all no-article
3279                                         kill-buffer no-display
3280                                         &optional select-articles)
3281   ;; Killed foreign groups can't be entered.
3282   ;;  (when (and (not (gnus-group-native-p group))
3283   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3284   ;;    (error "Dead non-native groups can't be entered"))
3285   (gnus-message 5 "Retrieving newsgroup: %s..."
3286                 (gnus-group-decoded-name group))
3287   (let* ((new-group (gnus-summary-setup-buffer group))
3288          (quit-config (gnus-group-quit-config group))
3289          (did-select (and new-group (gnus-select-newsgroup
3290                                      group show-all select-articles))))
3291     (cond
3292      ;; This summary buffer exists already, so we just select it.
3293      ((not new-group)
3294       (gnus-set-global-variables)
3295       (when kill-buffer
3296         (gnus-kill-or-deaden-summary kill-buffer))
3297       (gnus-configure-windows 'summary 'force)
3298       (gnus-set-mode-line 'summary)
3299       (gnus-summary-position-point)
3300       (message "")
3301       t)
3302      ;; We couldn't select this group.
3303      ((null did-select)
3304       (when (and (eq major-mode 'gnus-summary-mode)
3305                  (not (equal (current-buffer) kill-buffer)))
3306         (kill-buffer (current-buffer))
3307         (if (not quit-config)
3308             (progn
3309               ;; Update the info -- marks might need to be removed,
3310               ;; for instance.
3311               (gnus-summary-update-info)
3312               (set-buffer gnus-group-buffer)
3313               (gnus-group-jump-to-group group)
3314               (gnus-group-next-unread-group 1))
3315           (gnus-handle-ephemeral-exit quit-config)))
3316       (let ((grpinfo (gnus-get-info group)))
3317         (if (null (gnus-info-read grpinfo))
3318             (gnus-message 3 "Group %s contains no messages"
3319                           (gnus-group-decoded-name group))
3320           (gnus-message 3 "Can't select group")))
3321       nil)
3322      ;; The user did a `C-g' while prompting for number of articles,
3323      ;; so we exit this group.
3324      ((eq did-select 'quit)
3325       (and (eq major-mode 'gnus-summary-mode)
3326            (not (equal (current-buffer) kill-buffer))
3327            (kill-buffer (current-buffer)))
3328       (when kill-buffer
3329         (gnus-kill-or-deaden-summary kill-buffer))
3330       (if (not quit-config)
3331           (progn
3332             (set-buffer gnus-group-buffer)
3333             (gnus-group-jump-to-group group)
3334             (gnus-group-next-unread-group 1)
3335             (gnus-configure-windows 'group 'force))
3336         (gnus-handle-ephemeral-exit quit-config))
3337       ;; Finally signal the quit.
3338       (signal 'quit nil))
3339      ;; The group was successfully selected.
3340      (t
3341       (gnus-set-global-variables)
3342       ;; Save the active value in effect when the group was entered.
3343       (setq gnus-newsgroup-active
3344             (gnus-copy-sequence
3345              (gnus-active gnus-newsgroup-name)))
3346       ;; You can change the summary buffer in some way with this hook.
3347       (gnus-run-hooks 'gnus-select-group-hook)
3348       (gnus-update-format-specifications
3349        nil 'summary 'summary-mode 'summary-dummy)
3350       (gnus-update-summary-mark-positions)
3351       ;; Do score processing.
3352       (when gnus-use-scoring
3353         (gnus-possibly-score-headers))
3354       ;; Check whether to fill in the gaps in the threads.
3355       (when gnus-build-sparse-threads
3356         (gnus-build-sparse-threads))
3357       ;; Find the initial limit.
3358       (if gnus-show-threads
3359           (if show-all
3360               (let ((gnus-newsgroup-dormant nil))
3361                 (gnus-summary-initial-limit show-all))
3362             (gnus-summary-initial-limit show-all))
3363         ;; When untreaded, all articles are always shown.
3364         (setq gnus-newsgroup-limit
3365               (mapcar
3366                (lambda (header) (mail-header-number header))
3367                gnus-newsgroup-headers)))
3368       ;; Generate the summary buffer.
3369       (unless no-display
3370         (gnus-summary-prepare))
3371       (when gnus-use-trees
3372         (gnus-tree-open group)
3373         (setq gnus-summary-highlight-line-function
3374               'gnus-tree-highlight-article))
3375       ;; If the summary buffer is empty, but there are some low-scored
3376       ;; articles or some excluded dormants, we include these in the
3377       ;; buffer.
3378       (when (and (zerop (buffer-size))
3379                  (not no-display))
3380         (cond (gnus-newsgroup-dormant
3381                (gnus-summary-limit-include-dormant))
3382               ((and gnus-newsgroup-scored show-all)
3383                (gnus-summary-limit-include-expunged t))))
3384       ;; Function `gnus-apply-kill-file' must be called in this hook.
3385       (gnus-run-hooks 'gnus-apply-kill-hook)
3386       (if (and (zerop (buffer-size))
3387                (not no-display))
3388           (progn
3389             ;; This newsgroup is empty.
3390             (gnus-summary-catchup-and-exit nil t)
3391             (gnus-message 6 "No unread news")
3392             (when kill-buffer
3393               (gnus-kill-or-deaden-summary kill-buffer))
3394             ;; Return nil from this function.
3395             nil)
3396         ;; Hide conversation thread subtrees.  We cannot do this in
3397         ;; gnus-summary-prepare-hook since kill processing may not
3398         ;; work with hidden articles.
3399         (gnus-summary-maybe-hide-threads)
3400         (when kill-buffer
3401           (gnus-kill-or-deaden-summary kill-buffer))
3402         (gnus-summary-auto-select-subject)
3403         ;; Show first unread article if requested.
3404         (if (and (not no-article)
3405                  (not no-display)
3406                  gnus-newsgroup-unreads
3407                  gnus-auto-select-first)
3408             (progn
3409               (gnus-configure-windows 'summary)
3410               (let ((art (gnus-summary-article-number)))
3411                 (unless (or (memq art gnus-newsgroup-undownloaded)
3412                             (memq art gnus-newsgroup-downloadable))
3413                   (gnus-summary-goto-article art))))
3414           ;; Don't select any articles.
3415           (gnus-summary-position-point)
3416           (gnus-configure-windows 'summary 'force)
3417           (gnus-set-mode-line 'summary))
3418         (when (get-buffer-window gnus-group-buffer t)
3419           ;; Gotta use windows, because recenter does weird stuff if
3420           ;; the current buffer ain't the displayed window.
3421           (let ((owin (selected-window)))
3422             (select-window (get-buffer-window gnus-group-buffer t))
3423             (when (gnus-group-goto-group group)
3424               (recenter))
3425             (select-window owin)))
3426         ;; Mark this buffer as "prepared".
3427         (setq gnus-newsgroup-prepared t)
3428         (gnus-run-hooks 'gnus-summary-prepared-hook)
3429         t)))))
3430
3431 (defun gnus-summary-auto-select-subject ()
3432   "Select the subject line on initial group entry."
3433   (goto-char (point-min))
3434   (cond
3435    ((eq gnus-auto-select-subject 'best)
3436     (gnus-summary-best-unread-subject))
3437    ((eq gnus-auto-select-subject 'unread)
3438     (gnus-summary-first-unread-subject))
3439    ((eq gnus-auto-select-subject 'unseen)
3440     (gnus-summary-first-unseen-subject))
3441    ((eq gnus-auto-select-subject 'unseen-or-unread)
3442     (gnus-summary-first-unseen-or-unread-subject))
3443    ((eq gnus-auto-select-subject 'first)
3444     ;; Do nothing.
3445     )
3446    ((gnus-functionp gnus-auto-select-subject)
3447     (funcall gnus-auto-select-subject))))
3448
3449 (defun gnus-summary-prepare ()
3450   "Generate the summary buffer."
3451   (interactive)
3452   (let ((buffer-read-only nil))
3453     (erase-buffer)
3454     (setq gnus-newsgroup-data nil
3455           gnus-newsgroup-data-reverse nil)
3456     (gnus-run-hooks 'gnus-summary-generate-hook)
3457     ;; Generate the buffer, either with threads or without.
3458     (when gnus-newsgroup-headers
3459       (gnus-summary-prepare-threads
3460        (if gnus-show-threads
3461            (gnus-sort-gathered-threads
3462             (funcall gnus-summary-thread-gathering-function
3463                      (gnus-sort-threads
3464                       (gnus-cut-threads (gnus-make-threads)))))
3465          ;; Unthreaded display.
3466          (gnus-sort-articles gnus-newsgroup-headers))))
3467     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3468     ;; Call hooks for modifying summary buffer.
3469     (goto-char (point-min))
3470     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3471
3472 (defsubst gnus-general-simplify-subject (subject)
3473   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3474   (setq subject
3475         (cond
3476          ;; Truncate the subject.
3477          (gnus-simplify-subject-functions
3478           (gnus-map-function gnus-simplify-subject-functions subject))
3479          ((numberp gnus-summary-gather-subject-limit)
3480           (setq subject (gnus-simplify-subject-re subject))
3481           (if (> (length subject) gnus-summary-gather-subject-limit)
3482               (substring subject 0 gnus-summary-gather-subject-limit)
3483             subject))
3484          ;; Fuzzily simplify it.
3485          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3486           (gnus-simplify-subject-fuzzy subject))
3487          ;; Just remove the leading "Re:".
3488          (t
3489           (gnus-simplify-subject-re subject))))
3490
3491   (if (and gnus-summary-gather-exclude-subject
3492            (string-match gnus-summary-gather-exclude-subject subject))
3493       nil                               ; This article shouldn't be gathered
3494     subject))
3495
3496 (defun gnus-summary-simplify-subject-query ()
3497   "Query where the respool algorithm would put this article."
3498   (interactive)
3499   (gnus-summary-select-article)
3500   (message "%s"
3501            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3502
3503 (defun gnus-gather-threads-by-subject (threads)
3504   "Gather threads by looking at Subject headers."
3505   (if (not gnus-summary-make-false-root)
3506       threads
3507     (let ((hashtb (gnus-make-hashtable 1024))
3508           (prev threads)
3509           (result threads)
3510           subject hthread whole-subject)
3511       (while threads
3512         (setq subject (gnus-general-simplify-subject
3513                        (setq whole-subject (mail-header-subject
3514                                             (caar threads)))))
3515         (when subject
3516           (if (setq hthread (gnus-gethash subject hashtb))
3517               (progn
3518                 ;; We enter a dummy root into the thread, if we
3519                 ;; haven't done that already.
3520                 (unless (stringp (caar hthread))
3521                   (setcar hthread (list whole-subject (car hthread))))
3522                 ;; We add this new gathered thread to this gathered
3523                 ;; thread.
3524                 (setcdr (car hthread)
3525                         (nconc (cdar hthread) (list (car threads))))
3526                 ;; Remove it from the list of threads.
3527                 (setcdr prev (cdr threads))
3528                 (setq threads prev))
3529             ;; Enter this thread into the hash table.
3530             (gnus-sethash subject threads hashtb)))
3531         (setq prev threads)
3532         (setq threads (cdr threads)))
3533       result)))
3534
3535 (defun gnus-gather-threads-by-references (threads)
3536   "Gather threads by looking at References headers."
3537   (let ((idhashtb (gnus-make-hashtable 1024))
3538         (thhashtb (gnus-make-hashtable 1024))
3539         (prev threads)
3540         (result threads)
3541         ids references id gthread gid entered ref)
3542     (while threads
3543       (when (setq references (mail-header-references (caar threads)))
3544         (setq id (mail-header-id (caar threads))
3545               ids (inline (gnus-split-references references))
3546               entered nil)
3547         (while (setq ref (pop ids))
3548           (setq ids (delete ref ids))
3549           (if (not (setq gid (gnus-gethash ref idhashtb)))
3550               (progn
3551                 (gnus-sethash ref id idhashtb)
3552                 (gnus-sethash id threads thhashtb))
3553             (setq gthread (gnus-gethash gid thhashtb))
3554             (unless entered
3555               ;; We enter a dummy root into the thread, if we
3556               ;; haven't done that already.
3557               (unless (stringp (caar gthread))
3558                 (setcar gthread (list (mail-header-subject (caar gthread))
3559                                       (car gthread))))
3560               ;; We add this new gathered thread to this gathered
3561               ;; thread.
3562               (setcdr (car gthread)
3563                       (nconc (cdar gthread) (list (car threads)))))
3564             ;; Add it into the thread hash table.
3565             (gnus-sethash id gthread thhashtb)
3566             (setq entered t)
3567             ;; Remove it from the list of threads.
3568             (setcdr prev (cdr threads))
3569             (setq threads prev))))
3570       (setq prev threads)
3571       (setq threads (cdr threads)))
3572     result))
3573
3574 (defun gnus-sort-gathered-threads (threads)
3575   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3576   (let ((result threads))
3577     (while threads
3578       (when (stringp (caar threads))
3579         (setcdr (car threads)
3580                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3581       (setq threads (cdr threads)))
3582     result))
3583
3584 (defun gnus-thread-loop-p (root thread)
3585   "Say whether ROOT is in THREAD."
3586   (let ((stack (list thread))
3587         (infloop 0)
3588         th)
3589     (while (setq thread (pop stack))
3590       (setq th (cdr thread))
3591       (while (and th
3592                   (not (eq (caar th) root)))
3593         (pop th))
3594       (if th
3595           ;; We have found a loop.
3596           (let (ref-dep)
3597             (setcdr thread (delq (car th) (cdr thread)))
3598             (if (boundp (setq ref-dep (intern "none"
3599                                               gnus-newsgroup-dependencies)))
3600                 (setcdr (symbol-value ref-dep)
3601                         (nconc (cdr (symbol-value ref-dep))
3602                                (list (car th))))
3603               (set ref-dep (list nil (car th))))
3604             (setq infloop 1
3605                   stack nil))
3606         ;; Push all the subthreads onto the stack.
3607         (push (cdr thread) stack)))
3608     infloop))
3609
3610 (defun gnus-make-threads ()
3611   "Go through the dependency hashtb and find the roots.  Return all threads."
3612   (let (threads)
3613     (while (catch 'infloop
3614              (mapatoms
3615               (lambda (refs)
3616                 ;; Deal with self-referencing References loops.
3617                 (when (and (car (symbol-value refs))
3618                            (not (zerop
3619                                  (apply
3620                                   '+
3621                                   (mapcar
3622                                    (lambda (thread)
3623                                      (gnus-thread-loop-p
3624                                       (car (symbol-value refs)) thread))
3625                                    (cdr (symbol-value refs)))))))
3626                   (setq threads nil)
3627                   (throw 'infloop t))
3628                 (unless (car (symbol-value refs))
3629                   ;; These threads do not refer back to any other articles,
3630                   ;; so they're roots.
3631                   (setq threads (append (cdr (symbol-value refs)) threads))))
3632               gnus-newsgroup-dependencies)))
3633     threads))
3634
3635 ;; Build the thread tree.
3636 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3637   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3638
3639 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3640 if it was already present.
3641
3642 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3643 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3644 Message-IDs will be renamed to a unique Message-ID before being
3645 entered.
3646
3647 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3648   (let* ((id (mail-header-id header))
3649          (id-dep (and id (intern id dependencies)))
3650          ref ref-dep ref-header replaced)
3651     ;; Enter this `header' in the `dependencies' table.
3652     (cond
3653      ((not id-dep)
3654       (setq header nil))
3655      ;; The first two cases do the normal part: enter a new `header'
3656      ;; in the `dependencies' table.
3657      ((not (boundp id-dep))
3658       (set id-dep (list header)))
3659      ((null (car (symbol-value id-dep)))
3660       (setcar (symbol-value id-dep) header))
3661
3662      ;; From here the `header' was already present in the
3663      ;; `dependencies' table.
3664      (force-new
3665       ;; Overrides an existing entry;
3666       ;; just set the header part of the entry.
3667       (setcar (symbol-value id-dep) header)
3668       (setq replaced t))
3669
3670      ;; Renames the existing `header' to a unique Message-ID.
3671      ((not gnus-summary-ignore-duplicates)
3672       ;; An article with this Message-ID has already been seen.
3673       ;; We rename the Message-ID.
3674       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3675            (list header))
3676       (mail-header-set-id header id))
3677
3678      ;; The last case ignores an existing entry, except it adds any
3679      ;; additional Xrefs (in case the two articles came from different
3680      ;; servers.
3681      ;; Also sets `header' to `nil' meaning that the `dependencies'
3682      ;; table was *not* modified.
3683      (t
3684       (mail-header-set-xref
3685        (car (symbol-value id-dep))
3686        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3687                    "")
3688                (or (mail-header-xref header) "")))
3689       (setq header nil)))
3690
3691     (when (and header (not replaced))
3692       ;; First check that we are not creating a References loop.
3693       (setq ref (gnus-parent-id (mail-header-references header)))
3694       (while (and ref
3695                   (setq ref-dep (intern-soft ref dependencies))
3696                   (boundp ref-dep)
3697                   (setq ref-header (car (symbol-value ref-dep))))
3698         (if (string= id ref)
3699             ;; Yuk!  This is a reference loop.  Make the article be a
3700             ;; root article.
3701             (progn
3702               (mail-header-set-references (car (symbol-value id-dep)) "none")
3703               (setq ref nil))
3704           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3705       (setq ref (gnus-parent-id (mail-header-references header)))
3706       (setq ref-dep (intern (or ref "none") dependencies))
3707       (if (boundp ref-dep)
3708           (setcdr (symbol-value ref-dep)
3709                   (nconc (cdr (symbol-value ref-dep))
3710                          (list (symbol-value id-dep))))
3711         (set ref-dep (list nil (symbol-value id-dep)))))
3712     header))
3713
3714 (defun gnus-extract-message-id-from-in-reply-to (string)
3715   (if (string-match "<[^>]+>" string)
3716       (substring string (match-beginning 0) (match-end 0))
3717     nil))
3718
3719 (defun gnus-build-sparse-threads ()
3720   (let ((headers gnus-newsgroup-headers)
3721         (mail-parse-charset gnus-newsgroup-charset)
3722         (gnus-summary-ignore-duplicates t)
3723         header references generation relations
3724         subject child end new-child date)
3725     ;; First we create an alist of generations/relations, where
3726     ;; generations is how much we trust the relation, and the relation
3727     ;; is parent/child.
3728     (gnus-message 7 "Making sparse threads...")
3729     (save-excursion
3730       (nnheader-set-temp-buffer " *gnus sparse threads*")
3731       (while (setq header (pop headers))
3732         (when (and (setq references (mail-header-references header))
3733                    (not (string= references "")))
3734           (insert references)
3735           (setq child (mail-header-id header)
3736                 subject (mail-header-subject header)
3737                 date (mail-header-date header)
3738                 generation 0)
3739           (while (search-backward ">" nil t)
3740             (setq end (1+ (point)))
3741             (when (search-backward "<" nil t)
3742               (setq new-child (buffer-substring (point) end))
3743               (push (list (incf generation)
3744                           child (setq child new-child)
3745                           subject date)
3746                     relations)))
3747           (when child
3748             (push (list (1+ generation) child nil subject) relations))
3749           (erase-buffer)))
3750       (kill-buffer (current-buffer)))
3751     ;; Sort over trustworthiness.
3752     (mapcar
3753      (lambda (relation)
3754        (when (gnus-dependencies-add-header
3755               (make-full-mail-header-from-decoded-header
3756                gnus-reffed-article-number
3757                (nth 3 relation) "" (or (nth 4 relation) "")
3758                (nth 1 relation)
3759                (or (nth 2 relation) "") 0 0 "")
3760               gnus-newsgroup-dependencies nil)
3761          (push gnus-reffed-article-number gnus-newsgroup-limit)
3762          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3763          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3764                gnus-newsgroup-reads)
3765          (decf gnus-reffed-article-number)))
3766      (sort relations 'car-less-than-car))
3767     (gnus-message 7 "Making sparse threads...done")))
3768
3769 (defun gnus-build-old-threads ()
3770   ;; Look at all the articles that refer back to old articles, and
3771   ;; fetch the headers for the articles that aren't there.  This will
3772   ;; build complete threads - if the roots haven't been expired by the
3773   ;; server, that is.
3774   (let ((mail-parse-charset gnus-newsgroup-charset)
3775         id heads)
3776     (mapatoms
3777      (lambda (refs)
3778        (when (not (car (symbol-value refs)))
3779          (setq heads (cdr (symbol-value refs)))
3780          (while heads
3781            (if (memq (mail-header-number (caar heads))
3782                      gnus-newsgroup-dormant)
3783                (setq heads (cdr heads))
3784              (setq id (symbol-name refs))
3785              (while (and (setq id (gnus-build-get-header id))
3786                          (not (car (gnus-id-to-thread id)))))
3787              (setq heads nil)))))
3788      gnus-newsgroup-dependencies)))
3789
3790 ;; This function has to be called with point after the article number
3791 ;; on the beginning of the line.
3792 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3793   (let ((eol (gnus-point-at-eol))
3794         (buffer (current-buffer))
3795         header references in-reply-to)
3796
3797     ;; overview: [num subject from date id refs chars lines misc]
3798     (unwind-protect
3799         (progn
3800           (narrow-to-region (point) eol)
3801           (unless (eobp)
3802             (forward-char))
3803
3804           (setq header
3805                 (make-full-mail-header
3806                  number                         ; number
3807                  (nnheader-nov-field)           ; subject
3808                  (nnheader-nov-field)           ; from
3809                  (nnheader-nov-field)           ; date
3810                  (nnheader-nov-read-message-id) ; id
3811                  (nnheader-nov-field)           ; refs
3812                  (nnheader-nov-read-integer)    ; chars
3813                  (nnheader-nov-read-integer)    ; lines
3814                  (unless (eobp)
3815                    (if (looking-at "Xref: ")
3816                        (goto-char (match-end 0)))
3817                    (nnheader-nov-field))        ; Xref
3818                  (nnheader-nov-parse-extra))))  ; extra
3819
3820       (widen))
3821
3822     (when (and (string= references "")
3823                (setq in-reply-to (mail-header-extra header))
3824                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3825       (mail-header-set-references
3826        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3827
3828     (when gnus-alter-header-function
3829       (funcall gnus-alter-header-function header))
3830     (gnus-dependencies-add-header header dependencies force-new)))
3831
3832 (defun gnus-build-get-header (id)
3833   "Look through the buffer of NOV lines and find the header to ID.
3834 Enter this line into the dependencies hash table, and return
3835 the id of the parent article (if any)."
3836   (let ((deps gnus-newsgroup-dependencies)
3837         found header)
3838     (prog1
3839         (save-excursion
3840           (set-buffer nntp-server-buffer)
3841           (let ((case-fold-search nil))
3842             (goto-char (point-min))
3843             (while (and (not found)
3844                         (search-forward id nil t))
3845               (beginning-of-line)
3846               (setq found (looking-at
3847                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3848                                    (regexp-quote id))))
3849               (or found (beginning-of-line 2)))
3850             (when found
3851               (beginning-of-line)
3852               (and
3853                (setq header (gnus-nov-parse-line
3854                              (read (current-buffer)) deps))
3855                (gnus-parent-id (mail-header-references header))))))
3856       (when header
3857         (let ((number (mail-header-number header)))
3858           (push number gnus-newsgroup-limit)
3859           (push header gnus-newsgroup-headers)
3860           (if (memq number gnus-newsgroup-unselected)
3861               (progn
3862                 (setq gnus-newsgroup-unreads
3863                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3864                                                number))
3865                 (setq gnus-newsgroup-unselected
3866                       (delq number gnus-newsgroup-unselected)))
3867             (push number gnus-newsgroup-ancient)))))))
3868
3869 (defun gnus-build-all-threads ()
3870   "Read all the headers."
3871   (let ((gnus-summary-ignore-duplicates t)
3872         (mail-parse-charset gnus-newsgroup-charset)
3873         (dependencies gnus-newsgroup-dependencies)
3874         header article)
3875     (save-excursion
3876       (set-buffer nntp-server-buffer)
3877       (let ((case-fold-search nil))
3878         (goto-char (point-min))
3879         (while (not (eobp))
3880           (ignore-errors
3881             (setq article (read (current-buffer))
3882                   header (gnus-nov-parse-line article dependencies)))
3883           (when header
3884             (save-excursion
3885               (set-buffer gnus-summary-buffer)
3886               (push header gnus-newsgroup-headers)
3887               (if (memq (setq article (mail-header-number header))
3888                         gnus-newsgroup-unselected)
3889                   (progn
3890                     (setq gnus-newsgroup-unreads
3891                           (gnus-add-to-sorted-list
3892                            gnus-newsgroup-unreads article))
3893                     (setq gnus-newsgroup-unselected
3894                           (delq article gnus-newsgroup-unselected)))
3895                 (push article gnus-newsgroup-ancient)))
3896             (forward-line 1)))))))
3897
3898 (defun gnus-summary-update-article-line (article header)
3899   "Update the line for ARTICLE using HEADERS."
3900   (let* ((id (mail-header-id header))
3901          (thread (gnus-id-to-thread id)))
3902     (unless thread
3903       (error "Article in no thread"))
3904     ;; Update the thread.
3905     (setcar thread header)
3906     (gnus-summary-goto-subject article)
3907     (let* ((datal (gnus-data-find-list article))
3908            (data (car datal))
3909            (length (when (cdr datal)
3910                      (- (gnus-data-pos data)
3911                         (gnus-data-pos (cadr datal)))))
3912            (buffer-read-only nil)
3913            (level (gnus-summary-thread-level)))
3914       (gnus-delete-line)
3915       (gnus-summary-insert-line
3916        header level nil (gnus-article-mark article)
3917        (memq article gnus-newsgroup-replied)
3918        (memq article gnus-newsgroup-expirable)
3919        ;; Only insert the Subject string when it's different
3920        ;; from the previous Subject string.
3921        (if (and
3922             gnus-show-threads
3923             (gnus-subject-equal
3924              (condition-case ()
3925                  (mail-header-subject
3926                   (gnus-data-header
3927                    (cadr
3928                     (gnus-data-find-list
3929                      article
3930                      (gnus-data-list t)))))
3931                ;; Error on the side of excessive subjects.
3932                (error ""))
3933              (mail-header-subject header)))
3934            ""
3935          (mail-header-subject header))
3936        nil (cdr (assq article gnus-newsgroup-scored))
3937        (memq article gnus-newsgroup-processable))
3938       (when length
3939         (gnus-data-update-list
3940          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3941
3942 (defun gnus-summary-update-article (article &optional iheader)
3943   "Update ARTICLE in the summary buffer."
3944   (set-buffer gnus-summary-buffer)
3945   (let* ((header (gnus-summary-article-header article))
3946          (id (mail-header-id header))
3947          (data (gnus-data-find article))
3948          (thread (gnus-id-to-thread id))
3949          (references (mail-header-references header))
3950          (parent
3951           (gnus-id-to-thread
3952            (or (gnus-parent-id
3953                 (when (and references
3954                            (not (equal "" references)))
3955                   references))
3956                "none")))
3957          (buffer-read-only nil)
3958          (old (car thread)))
3959     (when thread
3960       (unless iheader
3961         (setcar thread nil)
3962         (when parent
3963           (delq thread parent)))
3964       (if (gnus-summary-insert-subject id header)
3965           ;; Set the (possibly) new article number in the data structure.
3966           (gnus-data-set-number data (gnus-id-to-article id))
3967         (setcar thread old)
3968         nil))))
3969
3970 (defun gnus-rebuild-thread (id &optional line)
3971   "Rebuild the thread containing ID.
3972 If LINE, insert the rebuilt thread starting on line LINE."
3973   (let ((buffer-read-only nil)
3974         old-pos current thread data)
3975     (if (not gnus-show-threads)
3976         (setq thread (list (car (gnus-id-to-thread id))))
3977       ;; Get the thread this article is part of.
3978       (setq thread (gnus-remove-thread id)))
3979     (setq old-pos (gnus-point-at-bol))
3980     (setq current (save-excursion
3981                     (and (re-search-backward "[\r\n]" nil t)
3982                          (gnus-summary-article-number))))
3983     ;; If this is a gathered thread, we have to go some re-gathering.
3984     (when (stringp (car thread))
3985       (let ((subject (car thread))
3986             roots thr)
3987         (setq thread (cdr thread))
3988         (while thread
3989           (unless (memq (setq thr (gnus-id-to-thread
3990                                    (gnus-root-id
3991                                     (mail-header-id (caar thread)))))
3992                         roots)
3993             (push thr roots))
3994           (setq thread (cdr thread)))
3995         ;; We now have all (unique) roots.
3996         (if (= (length roots) 1)
3997             ;; All the loose roots are now one solid root.
3998             (setq thread (car roots))
3999           (setq thread (cons subject (gnus-sort-threads roots))))))
4000     (let (threads)
4001       ;; We then insert this thread into the summary buffer.
4002       (when line
4003         (goto-char (point-min))
4004         (forward-line (1- line)))
4005       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4006         (if gnus-show-threads
4007             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4008           (gnus-summary-prepare-unthreaded thread))
4009         (setq data (nreverse gnus-newsgroup-data))
4010         (setq threads gnus-newsgroup-threads))
4011       ;; We splice the new data into the data structure.
4012       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4013       ;;!!! then we want to insert at the beginning of the buffer.
4014       ;;!!! That happens to be true with Gnus now, but that may
4015       ;;!!! change in the future.  Perhaps.
4016       (gnus-data-enter-list
4017        (if line nil current) data (- (point) old-pos))
4018       (setq gnus-newsgroup-threads
4019             (nconc threads gnus-newsgroup-threads))
4020       (gnus-data-compute-positions))))
4021
4022 (defun gnus-number-to-header (number)
4023   "Return the header for article NUMBER."
4024   (let ((headers gnus-newsgroup-headers))
4025     (while (and headers
4026                 (not (= number (mail-header-number (car headers)))))
4027       (pop headers))
4028     (when headers
4029       (car headers))))
4030
4031 (defun gnus-parent-headers (in-headers &optional generation)
4032   "Return the headers of the GENERATIONeth parent of HEADERS."
4033   (unless generation
4034     (setq generation 1))
4035   (let ((parent t)
4036         (headers in-headers)
4037         references)
4038     (while (and parent
4039                 (not (zerop generation))
4040                 (setq references (mail-header-references headers)))
4041       (setq headers (if (and references
4042                              (setq parent (gnus-parent-id references)))
4043                         (car (gnus-id-to-thread parent))
4044                       nil))
4045       (decf generation))
4046     (and (not (eq headers in-headers))
4047          headers)))
4048
4049 (defun gnus-id-to-thread (id)
4050   "Return the (sub-)thread where ID appears."
4051   (gnus-gethash id gnus-newsgroup-dependencies))
4052
4053 (defun gnus-id-to-article (id)
4054   "Return the article number of ID."
4055   (let ((thread (gnus-id-to-thread id)))
4056     (when (and thread
4057                (car thread))
4058       (mail-header-number (car thread)))))
4059
4060 (defun gnus-id-to-header (id)
4061   "Return the article headers of ID."
4062   (car (gnus-id-to-thread id)))
4063
4064 (defun gnus-article-displayed-root-p (article)
4065   "Say whether ARTICLE is a root(ish) article."
4066   (let ((level (gnus-summary-thread-level article))
4067         (refs (mail-header-references  (gnus-summary-article-header article)))
4068         particle)
4069     (cond
4070      ((null level) nil)
4071      ((zerop level) t)
4072      ((null refs) t)
4073      ((null (gnus-parent-id refs)) t)
4074      ((and (= 1 level)
4075            (null (setq particle (gnus-id-to-article
4076                                  (gnus-parent-id refs))))
4077            (null (gnus-summary-thread-level particle)))))))
4078
4079 (defun gnus-root-id (id)
4080   "Return the id of the root of the thread where ID appears."
4081   (let (last-id prev)
4082     (while (and id (setq prev (car (gnus-id-to-thread id))))
4083       (setq last-id id
4084             id (gnus-parent-id (mail-header-references prev))))
4085     last-id))
4086
4087 (defun gnus-articles-in-thread (thread)
4088   "Return the list of articles in THREAD."
4089   (cons (mail-header-number (car thread))
4090         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4091
4092 (defun gnus-remove-thread (id &optional dont-remove)
4093   "Remove the thread that has ID in it."
4094   (let (headers thread last-id)
4095     ;; First go up in this thread until we find the root.
4096     (setq last-id (gnus-root-id id)
4097           headers (message-flatten-list (gnus-id-to-thread last-id)))
4098     ;; We have now found the real root of this thread.  It might have
4099     ;; been gathered into some loose thread, so we have to search
4100     ;; through the threads to find the thread we wanted.
4101     (let ((threads gnus-newsgroup-threads)
4102           sub)
4103       (while threads
4104         (setq sub (car threads))
4105         (if (stringp (car sub))
4106             ;; This is a gathered thread, so we look at the roots
4107             ;; below it to find whether this article is in this
4108             ;; gathered root.
4109             (progn
4110               (setq sub (cdr sub))
4111               (while sub
4112                 (when (member (caar sub) headers)
4113                   (setq thread (car threads)
4114                         threads nil
4115                         sub nil))
4116                 (setq sub (cdr sub))))
4117           ;; It's an ordinary thread, so we check it.
4118           (when (eq (car sub) (car headers))
4119             (setq thread sub
4120                   threads nil)))
4121         (setq threads (cdr threads)))
4122       ;; If this article is in no thread, then it's a root.
4123       (if thread
4124           (unless dont-remove
4125             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4126         (setq thread (gnus-id-to-thread last-id)))
4127       (when thread
4128         (prog1
4129             thread                      ; We return this thread.
4130           (unless dont-remove
4131             (if (stringp (car thread))
4132                 (progn
4133                   ;; If we use dummy roots, then we have to remove the
4134                   ;; dummy root as well.
4135                   (when (eq gnus-summary-make-false-root 'dummy)
4136                     ;; We go to the dummy root by going to
4137                     ;; the first sub-"thread", and then one line up.
4138                     (gnus-summary-goto-article
4139                      (mail-header-number (caadr thread)))
4140                     (forward-line -1)
4141                     (gnus-delete-line)
4142                     (gnus-data-compute-positions))
4143                   (setq thread (cdr thread))
4144                   (while thread
4145                     (gnus-remove-thread-1 (car thread))
4146                     (setq thread (cdr thread))))
4147               (gnus-remove-thread-1 thread))))))))
4148
4149 (defun gnus-remove-thread-1 (thread)
4150   "Remove the thread THREAD recursively."
4151   (let ((number (mail-header-number (pop thread)))
4152         d)
4153     (setq thread (reverse thread))
4154     (while thread
4155       (gnus-remove-thread-1 (pop thread)))
4156     (when (setq d (gnus-data-find number))
4157       (goto-char (gnus-data-pos d))
4158       (gnus-summary-show-thread)
4159       (gnus-data-remove
4160        number
4161        (- (gnus-point-at-bol)
4162           (prog1
4163               (1+ (gnus-point-at-eol))
4164             (gnus-delete-line)))))))
4165
4166 (defun gnus-sort-threads-1 (threads func)
4167   (sort (mapcar (lambda (thread)
4168                   (cons (car thread)
4169                         (and (cdr thread)
4170                              (gnus-sort-threads-1 (cdr thread) func))))
4171                 threads) func))
4172
4173 (defun gnus-sort-threads (threads)
4174   "Sort THREADS."
4175   (if (not gnus-thread-sort-functions)
4176       threads
4177     (gnus-message 8 "Sorting threads...")
4178     (prog1
4179         (gnus-sort-threads-1
4180          threads
4181          (gnus-make-sort-function gnus-thread-sort-functions))
4182       (gnus-message 8 "Sorting threads...done"))))
4183
4184 (defun gnus-sort-articles (articles)
4185   "Sort ARTICLES."
4186   (when gnus-article-sort-functions
4187     (gnus-message 7 "Sorting articles...")
4188     (prog1
4189         (setq gnus-newsgroup-headers
4190               (sort articles (gnus-make-sort-function
4191                               gnus-article-sort-functions)))
4192       (gnus-message 7 "Sorting articles...done"))))
4193
4194 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4195 (defmacro gnus-thread-header (thread)
4196   "Return header of first article in THREAD.
4197 Note that THREAD must never, ever be anything else than a variable -
4198 using some other form will lead to serious barfage."
4199   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4200   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4201   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4202         (vector thread) 2))
4203
4204 (defsubst gnus-article-sort-by-number (h1 h2)
4205   "Sort articles by article number."
4206   (< (mail-header-number h1)
4207      (mail-header-number h2)))
4208
4209 (defun gnus-thread-sort-by-number (h1 h2)
4210   "Sort threads by root article number."
4211   (gnus-article-sort-by-number
4212    (gnus-thread-header h1) (gnus-thread-header h2)))
4213
4214 (defsubst gnus-article-sort-by-lines (h1 h2)
4215   "Sort articles by article Lines header."
4216   (< (mail-header-lines h1)
4217      (mail-header-lines h2)))
4218
4219 (defun gnus-thread-sort-by-lines (h1 h2)
4220   "Sort threads by root article Lines header."
4221   (gnus-article-sort-by-lines
4222    (gnus-thread-header h1) (gnus-thread-header h2)))
4223
4224 (defsubst gnus-article-sort-by-chars (h1 h2)
4225   "Sort articles by octet length."
4226   (< (mail-header-chars h1)
4227      (mail-header-chars h2)))
4228
4229 (defun gnus-thread-sort-by-chars (h1 h2)
4230   "Sort threads by root article octet length."
4231   (gnus-article-sort-by-chars
4232    (gnus-thread-header h1) (gnus-thread-header h2)))
4233
4234 (defsubst gnus-article-sort-by-author (h1 h2)
4235   "Sort articles by root author."
4236   (string-lessp
4237    (let ((addr (car (mime-entity-read-field h1 'From))))
4238      (or (std11-full-name-string addr)
4239          (std11-address-string addr)
4240          ""))
4241    (let ((addr (car (mime-entity-read-field h2 'From))))
4242      (or (std11-full-name-string addr)
4243          (std11-address-string addr)
4244          ""))
4245    ))
4246
4247 (defun gnus-thread-sort-by-author (h1 h2)
4248   "Sort threads by root author."
4249   (gnus-article-sort-by-author
4250    (gnus-thread-header h1)  (gnus-thread-header h2)))
4251
4252 (defsubst gnus-article-sort-by-subject (h1 h2)
4253   "Sort articles by root subject."
4254   (string-lessp
4255    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4256    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4257
4258 (defun gnus-thread-sort-by-subject (h1 h2)
4259   "Sort threads by root subject."
4260   (gnus-article-sort-by-subject
4261    (gnus-thread-header h1) (gnus-thread-header h2)))
4262
4263 (defsubst gnus-article-sort-by-date (h1 h2)
4264   "Sort articles by root article date."
4265   (time-less-p
4266    (gnus-date-get-time (mail-header-date h1))
4267    (gnus-date-get-time (mail-header-date h2))))
4268
4269 (defun gnus-thread-sort-by-date (h1 h2)
4270   "Sort threads by root article date."
4271   (gnus-article-sort-by-date
4272    (gnus-thread-header h1) (gnus-thread-header h2)))
4273
4274 (defsubst gnus-article-sort-by-score (h1 h2)
4275   "Sort articles by root article score.
4276 Unscored articles will be counted as having a score of zero."
4277   (> (or (cdr (assq (mail-header-number h1)
4278                     gnus-newsgroup-scored))
4279          gnus-summary-default-score 0)
4280      (or (cdr (assq (mail-header-number h2)
4281                     gnus-newsgroup-scored))
4282          gnus-summary-default-score 0)))
4283
4284 (defun gnus-thread-sort-by-score (h1 h2)
4285   "Sort threads by root article score."
4286   (gnus-article-sort-by-score
4287    (gnus-thread-header h1) (gnus-thread-header h2)))
4288
4289 (defun gnus-thread-sort-by-total-score (h1 h2)
4290   "Sort threads by the sum of all scores in the thread.
4291 Unscored articles will be counted as having a score of zero."
4292   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4293
4294 (defun gnus-thread-total-score (thread)
4295   ;; This function find the total score of THREAD.
4296   (cond
4297    ((null thread)
4298     0)
4299    ((consp thread)
4300     (if (stringp (car thread))
4301         (apply gnus-thread-score-function 0
4302                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4303       (gnus-thread-total-score-1 thread)))
4304    (t
4305     (gnus-thread-total-score-1 (list thread)))))
4306
4307 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4308   "Sort threads such that the thread with the most recently arrived article comes first."
4309   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4310
4311 (defun gnus-thread-highest-number (thread)
4312   "Return the highest article number in THREAD."
4313   (apply 'max (mapcar (lambda (header)
4314                         (mail-header-number header))
4315                       (message-flatten-list thread))))
4316
4317 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4318   "Sort threads such that the thread with the most recently dated article comes first."
4319   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4320
4321 (defun gnus-thread-latest-date (thread)
4322   "Return the highest article date in THREAD."
4323   (let ((previous-time 0))
4324     (apply 'max (mapcar
4325                  (lambda (header)
4326                    (setq previous-time
4327                          (time-to-seconds
4328                           (mail-header-parse-date
4329                            (condition-case ()
4330                                (mail-header-date header)
4331                              (error previous-time))))))
4332                  (sort
4333                   (message-flatten-list thread)
4334                   (lambda (h1 h2)
4335                     (< (mail-header-number h1)
4336                        (mail-header-number h2))))))))
4337
4338 (defun gnus-thread-total-score-1 (root)
4339   ;; This function find the total score of the thread below ROOT.
4340   (setq root (car root))
4341   (apply gnus-thread-score-function
4342          (or (append
4343               (mapcar 'gnus-thread-total-score
4344                       (cdr (gnus-id-to-thread (mail-header-id root))))
4345               (when (> (mail-header-number root) 0)
4346                 (list (or (cdr (assq (mail-header-number root)
4347                                      gnus-newsgroup-scored))
4348                           gnus-summary-default-score 0))))
4349              (list gnus-summary-default-score)
4350              '(0))))
4351
4352 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4353 (defvar gnus-tmp-prev-subject nil)
4354 (defvar gnus-tmp-false-parent nil)
4355 (defvar gnus-tmp-root-expunged nil)
4356 (defvar gnus-tmp-dummy-line nil)
4357
4358 (eval-when-compile (defvar gnus-tmp-header))
4359 (defun gnus-extra-header (type &optional header)
4360   "Return the extra header of TYPE."
4361   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4362       ""))
4363
4364 (defvar gnus-tmp-thread-tree-header-string "")
4365
4366 (defcustom gnus-sum-thread-tree-root "> "
4367   "With %B spec, used for the root of a thread.
4368 If nil, use subject instead."
4369   :type 'string
4370   :group 'gnus-thread)
4371 (defcustom gnus-sum-thread-tree-single-indent ""
4372   "With %B spec, used for a thread with just one message.
4373 If nil, use subject instead."
4374   :type 'string
4375   :group 'gnus-thread)
4376 (defcustom gnus-sum-thread-tree-vertical "| "
4377   "With %B spec, used for drawing a vertical line."
4378   :type 'string
4379   :group 'gnus-thread)
4380 (defcustom gnus-sum-thread-tree-indent "  "
4381   "With %B spec, used for indenting."
4382   :type 'string
4383   :group 'gnus-thread)
4384 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4385   "With %B spec, used for a leaf with brothers."
4386   :type 'string
4387   :group 'gnus-thread)
4388 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4389   "With %B spec, used for a leaf without brothers."
4390   :type 'string
4391   :group 'gnus-thread)
4392
4393 (defun gnus-summary-prepare-threads (threads)
4394   "Prepare summary buffer from THREADS and indentation LEVEL.
4395 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4396 or a straight list of headers."
4397   (gnus-message 7 "Generating summary...")
4398
4399   (setq gnus-newsgroup-threads threads)
4400   (beginning-of-line)
4401
4402   (let ((gnus-tmp-level 0)
4403         (default-score (or gnus-summary-default-score 0))
4404         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4405         thread number subject stack state gnus-tmp-gathered beg-match
4406         new-roots gnus-tmp-new-adopts thread-end
4407         gnus-tmp-header gnus-tmp-unread
4408         gnus-tmp-replied gnus-tmp-subject-or-nil
4409         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4410         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4411         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4412         tree-stack)
4413
4414     (setq gnus-tmp-prev-subject nil)
4415
4416     (if (vectorp (car threads))
4417         ;; If this is a straight (sic) list of headers, then a
4418         ;; threaded summary display isn't required, so we just create
4419         ;; an unthreaded one.
4420         (gnus-summary-prepare-unthreaded threads)
4421
4422       ;; Do the threaded display.
4423
4424       (while (or threads stack gnus-tmp-new-adopts new-roots)
4425
4426         (if (and (= gnus-tmp-level 0)
4427                  (or (not stack)
4428                      (= (caar stack) 0))
4429                  (not gnus-tmp-false-parent)
4430                  (or gnus-tmp-new-adopts new-roots))
4431             (if gnus-tmp-new-adopts
4432                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4433                       thread (list (car gnus-tmp-new-adopts))
4434                       gnus-tmp-header (caar thread)
4435                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4436               (when new-roots
4437                 (setq thread (list (car new-roots))
4438                       gnus-tmp-header (caar thread)
4439                       new-roots (cdr new-roots))))
4440
4441           (if threads
4442               ;; If there are some threads, we do them before the
4443               ;; threads on the stack.
4444               (setq thread threads
4445                     gnus-tmp-header (caar thread))
4446             ;; There were no current threads, so we pop something off
4447             ;; the stack.
4448             (setq state (car stack)
4449                   gnus-tmp-level (car state)
4450                   tree-stack (cadr state)
4451                   thread (caddr state)
4452                   stack (cdr stack)
4453                   gnus-tmp-header (caar thread))))
4454
4455         (setq gnus-tmp-false-parent nil)
4456         (setq gnus-tmp-root-expunged nil)
4457         (setq thread-end nil)
4458
4459         (if (stringp gnus-tmp-header)
4460             ;; The header is a dummy root.
4461             (cond
4462              ((eq gnus-summary-make-false-root 'adopt)
4463               ;; We let the first article adopt the rest.
4464               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4465                                                (cddar thread)))
4466               (setq gnus-tmp-gathered
4467                     (nconc (mapcar
4468                             (lambda (h) (mail-header-number (car h)))
4469                             (cddar thread))
4470                            gnus-tmp-gathered))
4471               (setq thread (cons (list (caar thread)
4472                                        (cadar thread))
4473                                  (cdr thread)))
4474               (setq gnus-tmp-level -1
4475                     gnus-tmp-false-parent t))
4476              ((eq gnus-summary-make-false-root 'empty)
4477               ;; We print adopted articles with empty subject fields.
4478               (setq gnus-tmp-gathered
4479                     (nconc (mapcar
4480                             (lambda (h) (mail-header-number (car h)))
4481                             (cddar thread))
4482                            gnus-tmp-gathered))
4483               (setq gnus-tmp-level -1))
4484              ((eq gnus-summary-make-false-root 'dummy)
4485               ;; We remember that we probably want to output a dummy
4486               ;; root.
4487               (setq gnus-tmp-dummy-line gnus-tmp-header)
4488               (setq gnus-tmp-prev-subject gnus-tmp-header))
4489              (t
4490               ;; We do not make a root for the gathered
4491               ;; sub-threads at all.
4492               (setq gnus-tmp-level -1)))
4493
4494           (setq number (mail-header-number gnus-tmp-header)
4495                 subject (mail-header-subject gnus-tmp-header))
4496
4497           (cond
4498            ;; If the thread has changed subject, we might want to make
4499            ;; this subthread into a root.
4500            ((and (null gnus-thread-ignore-subject)
4501                  (not (zerop gnus-tmp-level))
4502                  gnus-tmp-prev-subject
4503                  (not (inline
4504                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4505             (setq new-roots (nconc new-roots (list (car thread)))
4506                   thread-end t
4507                   gnus-tmp-header nil))
4508            ;; If the article lies outside the current limit,
4509            ;; then we do not display it.
4510            ((not (memq number gnus-newsgroup-limit))
4511             (setq gnus-tmp-gathered
4512                   (nconc (mapcar
4513                           (lambda (h) (mail-header-number (car h)))
4514                           (cdar thread))
4515                          gnus-tmp-gathered))
4516             (setq gnus-tmp-new-adopts (if (cdar thread)
4517                                           (append gnus-tmp-new-adopts
4518                                                   (cdar thread))
4519                                         gnus-tmp-new-adopts)
4520                   thread-end t
4521                   gnus-tmp-header nil)
4522             (when (zerop gnus-tmp-level)
4523               (setq gnus-tmp-root-expunged t)))
4524            ;; Perhaps this article is to be marked as read?
4525            ((and gnus-summary-mark-below
4526                  (< (or (cdr (assq number gnus-newsgroup-scored))
4527                         default-score)
4528                     gnus-summary-mark-below)
4529                  ;; Don't touch sparse articles.
4530                  (not (gnus-summary-article-sparse-p number))
4531                  (not (gnus-summary-article-ancient-p number)))
4532             (setq gnus-newsgroup-unreads
4533                   (delq number gnus-newsgroup-unreads))
4534             (if gnus-newsgroup-auto-expire
4535                 (setq gnus-newsgroup-expirable
4536                       (gnus-add-to-sorted-list
4537                        gnus-newsgroup-expirable number))
4538               (push (cons number gnus-low-score-mark)
4539                     gnus-newsgroup-reads))))
4540
4541           (when gnus-tmp-header
4542             ;; We may have an old dummy line to output before this
4543             ;; article.
4544             (when (and gnus-tmp-dummy-line
4545                        (gnus-subject-equal
4546                         gnus-tmp-dummy-line
4547                         (mail-header-subject gnus-tmp-header)))
4548               (gnus-summary-insert-dummy-line
4549                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4550               (setq gnus-tmp-dummy-line nil))
4551
4552             ;; Compute the mark.
4553             (setq gnus-tmp-unread (gnus-article-mark number))
4554
4555             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4556                                   gnus-tmp-header gnus-tmp-level)
4557                   gnus-newsgroup-data)
4558
4559             ;; Actually insert the line.
4560             (setq
4561              gnus-tmp-subject-or-nil
4562              (cond
4563               ((and gnus-thread-ignore-subject
4564                     gnus-tmp-prev-subject
4565                     (not (inline (gnus-subject-equal
4566                                   gnus-tmp-prev-subject subject))))
4567                subject)
4568               ((zerop gnus-tmp-level)
4569                (if (and (eq gnus-summary-make-false-root 'empty)
4570                         (memq number gnus-tmp-gathered)
4571                         gnus-tmp-prev-subject
4572                         (inline (gnus-subject-equal
4573                                  gnus-tmp-prev-subject subject)))
4574                    gnus-summary-same-subject
4575                  subject))
4576               (t gnus-summary-same-subject)))
4577             (if (and (eq gnus-summary-make-false-root 'adopt)
4578                      (= gnus-tmp-level 1)
4579                      (memq number gnus-tmp-gathered))
4580                 (setq gnus-tmp-opening-bracket ?\<
4581                       gnus-tmp-closing-bracket ?\>)
4582               (setq gnus-tmp-opening-bracket ?\[
4583                     gnus-tmp-closing-bracket ?\]))
4584             (setq
4585              gnus-tmp-indentation
4586              (aref gnus-thread-indent-array gnus-tmp-level)
4587              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4588              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4589                                 gnus-summary-default-score 0)
4590              gnus-tmp-score-char
4591              (if (or (null gnus-summary-default-score)
4592                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4593                          gnus-summary-zcore-fuzz))
4594                  ?\ ;;;Whitespace
4595                (if (< gnus-tmp-score gnus-summary-default-score)
4596                    gnus-score-below-mark gnus-score-over-mark))
4597              gnus-tmp-replied
4598              (cond ((memq number gnus-newsgroup-processable)
4599                     gnus-process-mark)
4600                    ((memq number gnus-newsgroup-cached)
4601                     gnus-cached-mark)
4602                    ((memq number gnus-newsgroup-replied)
4603                     gnus-replied-mark)
4604                    ((memq number gnus-newsgroup-forwarded)
4605                     gnus-forwarded-mark)
4606                    ((memq number gnus-newsgroup-saved)
4607                     gnus-saved-mark)
4608                    ((memq number gnus-newsgroup-recent)
4609                     gnus-recent-mark)
4610                    ((memq number gnus-newsgroup-unseen)
4611                     gnus-unseen-mark)
4612                    (t gnus-no-mark))
4613              gnus-tmp-from (mail-header-from gnus-tmp-header)
4614              gnus-tmp-name
4615              (cond
4616               ((string-match "<[^>]+> *$" gnus-tmp-from)
4617                (setq beg-match (match-beginning 0))
4618                (or (and (string-match "^\".+\"" gnus-tmp-from)
4619                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4620                    (substring gnus-tmp-from 0 beg-match)))
4621               ((string-match "(.+)" gnus-tmp-from)
4622                (substring gnus-tmp-from
4623                           (1+ (match-beginning 0)) (1- (match-end 0))))
4624               (t gnus-tmp-from))
4625              gnus-tmp-thread-tree-header-string
4626              (cond
4627               ((not gnus-show-threads) "")
4628               ((zerop gnus-tmp-level)
4629                (if (cdar thread)
4630                    (or gnus-sum-thread-tree-root subject)
4631                  (or gnus-sum-thread-tree-single-indent subject)))
4632               (t
4633                (concat (apply 'concat
4634                               (mapcar (lambda (item)
4635                                         (if (= item 1)
4636                                             gnus-sum-thread-tree-vertical
4637                                           gnus-sum-thread-tree-indent))
4638                                       (cdr (reverse tree-stack))))
4639                        (if (nth 1 thread)
4640                            gnus-sum-thread-tree-leaf-with-other
4641                          gnus-sum-thread-tree-single-leaf)))))
4642             (when (string= gnus-tmp-name "")
4643               (setq gnus-tmp-name gnus-tmp-from))
4644             (unless (numberp gnus-tmp-lines)
4645               (setq gnus-tmp-lines -1))
4646             (if (= gnus-tmp-lines -1)
4647                 (setq gnus-tmp-lines "?")
4648               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4649             (gnus-put-text-property
4650              (point)
4651              (progn (eval gnus-summary-line-format-spec) (point))
4652              'gnus-number number)
4653             (when gnus-visual-p
4654               (forward-line -1)
4655               (gnus-run-hooks 'gnus-summary-update-hook)
4656               (forward-line 1))
4657
4658             (setq gnus-tmp-prev-subject subject)))
4659
4660         (when (nth 1 thread)
4661           (push (list (max 0 gnus-tmp-level)
4662                       (copy-list tree-stack)
4663                       (nthcdr 1 thread))
4664                 stack))
4665         (push (if (nth 1 thread) 1 0) tree-stack)
4666         (incf gnus-tmp-level)
4667         (setq threads (if thread-end nil (cdar thread)))
4668         (unless threads
4669           (setq gnus-tmp-level 0)))))
4670   (gnus-message 7 "Generating summary...done"))
4671
4672 (defun gnus-summary-prepare-unthreaded (headers)
4673   "Generate an unthreaded summary buffer based on HEADERS."
4674   (let (header number mark)
4675
4676     (beginning-of-line)
4677
4678     (while headers
4679       ;; We may have to root out some bad articles...
4680       (when (memq (setq number (mail-header-number
4681                                 (setq header (pop headers))))
4682                   gnus-newsgroup-limit)
4683         ;; Mark article as read when it has a low score.
4684         (when (and gnus-summary-mark-below
4685                    (< (or (cdr (assq number gnus-newsgroup-scored))
4686                           gnus-summary-default-score 0)
4687                       gnus-summary-mark-below)
4688                    (not (gnus-summary-article-ancient-p number)))
4689           (setq gnus-newsgroup-unreads
4690                 (delq number gnus-newsgroup-unreads))
4691           (if gnus-newsgroup-auto-expire
4692               (push number gnus-newsgroup-expirable)
4693             (push (cons number gnus-low-score-mark)
4694                   gnus-newsgroup-reads)))
4695
4696         (setq mark (gnus-article-mark number))
4697         (push (gnus-data-make number mark (1+ (point)) header 0)
4698               gnus-newsgroup-data)
4699         (gnus-summary-insert-line
4700          header 0 number
4701          mark (memq number gnus-newsgroup-replied)
4702          (memq number gnus-newsgroup-expirable)
4703          (mail-header-subject header) nil
4704          (cdr (assq number gnus-newsgroup-scored))
4705          (memq number gnus-newsgroup-processable))))))
4706
4707 (defun gnus-summary-remove-list-identifiers ()
4708   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4709   (let ((regexp (if (consp gnus-list-identifiers)
4710                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4711                   gnus-list-identifiers))
4712         changed subject)
4713     (when regexp
4714       (dolist (header gnus-newsgroup-headers)
4715         (setq subject (mail-header-subject header)
4716               changed nil)
4717         (while (string-match
4718                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4719                 subject)
4720           (setq subject
4721                 (concat (substring subject 0 (match-beginning 2))
4722                         (substring subject (match-end 0)))
4723                 changed t))
4724         (when (and changed
4725                    (string-match
4726                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4727           (setq subject
4728                 (concat (substring subject 0 (match-beginning 1))
4729                         (substring subject (match-end 1)))))
4730         (when changed
4731           (mail-header-set-subject header subject))))))
4732
4733 (defun gnus-fetch-headers (articles)
4734   "Fetch headers of ARTICLES."
4735   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4736     (gnus-message 5 "Fetching headers for %s..." name)
4737     (prog1
4738         (if (eq 'nov
4739                 (setq gnus-headers-retrieved-by
4740                       (gnus-retrieve-headers
4741                        articles gnus-newsgroup-name
4742                        ;; We might want to fetch old headers, but
4743                        ;; not if there is only 1 article.
4744                        (and (or (and
4745                                  (not (eq gnus-fetch-old-headers 'some))
4746                                  (not (numberp gnus-fetch-old-headers)))
4747                                 (> (length articles) 1))
4748                             gnus-fetch-old-headers))))
4749             (gnus-get-newsgroup-headers-xover
4750              articles nil nil gnus-newsgroup-name t)
4751           (gnus-get-newsgroup-headers))
4752       (gnus-message 5 "Fetching headers for %s...done" name))))
4753
4754 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4755   "Select newsgroup GROUP.
4756 If READ-ALL is non-nil, all articles in the group are selected.
4757 If SELECT-ARTICLES, only select those articles from GROUP."
4758   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4759          ;;!!! Dirty hack; should be removed.
4760          (gnus-summary-ignore-duplicates
4761           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4762               t
4763             gnus-summary-ignore-duplicates))
4764          (info (nth 2 entry))
4765          articles fetched-articles cached)
4766
4767     (unless (gnus-check-server
4768              (set (make-local-variable 'gnus-current-select-method)
4769                   (gnus-find-method-for-group group)))
4770       (error "Couldn't open server"))
4771
4772     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4773         (gnus-activate-group group)     ; Or we can activate it...
4774         (progn                          ; Or we bug out.
4775           (when (equal major-mode 'gnus-summary-mode)
4776             (kill-buffer (current-buffer)))
4777           (error "Couldn't activate group %s: %s"
4778                  group (gnus-status-message group))))
4779
4780     (unless (gnus-request-group group t)
4781       (when (equal major-mode 'gnus-summary-mode)
4782         (kill-buffer (current-buffer)))
4783       (error "Couldn't request group %s: %s"
4784              group (gnus-status-message group)))
4785
4786     (setq gnus-newsgroup-name group
4787           gnus-newsgroup-unselected nil
4788           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4789
4790     (let ((display (gnus-group-find-parameter group 'display)))
4791       (setq gnus-newsgroup-display
4792             (cond
4793              ((not (zerop (or (car-safe read-all) 0)))
4794               ;; The user entered the group with C-u SPC/RET, let's show
4795               ;; all articles.
4796               'gnus-not-ignore)
4797              ((eq display 'all)
4798               'gnus-not-ignore)
4799              ((arrayp display)
4800               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4801              ((numberp display)
4802               ;; The following is probably the "correct" solution, but
4803               ;; it makes Gnus fetch all headers and then limit the
4804               ;; articles (which is slow), so instead we hack the
4805               ;; select-articles parameter instead. -- Simon Josefsson
4806               ;; <jas@kth.se>
4807               ;;
4808               ;; (gnus-byte-compile
4809               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4810               ;;                         display)))))
4811               (setq select-articles
4812                     (gnus-uncompress-range
4813                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4814                              (if (> tmp 0)
4815                                  tmp
4816                                1))
4817                            (cdr (gnus-active group)))))
4818               nil)
4819              (t
4820               nil))))
4821
4822     (gnus-summary-setup-default-charset)
4823
4824     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4825     (when (gnus-virtual-group-p group)
4826       (setq cached gnus-newsgroup-cached))
4827
4828     (setq gnus-newsgroup-unreads
4829           (gnus-sorted-ndifference
4830            (gnus-sorted-ndifference gnus-newsgroup-unreads
4831                                     gnus-newsgroup-marked)
4832            gnus-newsgroup-dormant))
4833
4834     (setq gnus-newsgroup-processable nil)
4835
4836     (gnus-update-read-articles group gnus-newsgroup-unreads)
4837
4838     ;; Adjust and set lists of article marks.
4839     (when info
4840       (gnus-adjust-marked-articles info))
4841
4842     (if (setq articles select-articles)
4843         (setq gnus-newsgroup-unselected
4844               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4845       (setq articles (gnus-articles-to-read group read-all)))
4846
4847     (cond
4848      ((null articles)
4849       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4850       'quit)
4851      ((eq articles 0) nil)
4852      (t
4853       ;; Init the dependencies hash table.
4854       (setq gnus-newsgroup-dependencies
4855             (gnus-make-hashtable (length articles)))
4856       (gnus-set-global-variables)
4857       ;; Retrieve the headers and read them in.
4858       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4859
4860       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4861       (when cached
4862         (setq gnus-newsgroup-cached cached))
4863
4864       ;; Suppress duplicates?
4865       (when gnus-suppress-duplicates
4866         (gnus-dup-suppress-articles))
4867
4868       ;; Set the initial limit.
4869       (setq gnus-newsgroup-limit (copy-sequence articles))
4870       ;; Remove canceled articles from the list of unread articles.
4871       (setq fetched-articles
4872             (mapcar (lambda (headers) (mail-header-number headers))
4873                     gnus-newsgroup-headers))
4874       (setq gnus-newsgroup-articles fetched-articles)
4875       (setq gnus-newsgroup-unreads
4876             (gnus-sorted-nintersection
4877              gnus-newsgroup-unreads fetched-articles))
4878       (gnus-compute-unseen-list)
4879
4880       ;; Removed marked articles that do not exist.
4881       (gnus-update-missing-marks
4882        (gnus-sorted-difference articles fetched-articles))
4883       ;; We might want to build some more threads first.
4884       (when (and gnus-fetch-old-headers
4885                  (eq gnus-headers-retrieved-by 'nov))
4886         (if (eq gnus-fetch-old-headers 'invisible)
4887             (gnus-build-all-threads)
4888           (gnus-build-old-threads)))
4889       ;; Let the Gnus agent mark articles as read.
4890       (when gnus-agent
4891         (gnus-agent-get-undownloaded-list))
4892       ;; Remove list identifiers from subject
4893       (when gnus-list-identifiers
4894         (gnus-summary-remove-list-identifiers))
4895       ;; Check whether auto-expire is to be done in this group.
4896       (setq gnus-newsgroup-auto-expire
4897             (gnus-group-auto-expirable-p group))
4898       ;; Set up the article buffer now, if necessary.
4899       (unless gnus-single-article-buffer
4900         (gnus-article-setup-buffer))
4901       ;; First and last article in this newsgroup.
4902       (when gnus-newsgroup-headers
4903         (setq gnus-newsgroup-begin
4904               (mail-header-number (car gnus-newsgroup-headers))
4905               gnus-newsgroup-end
4906               (mail-header-number
4907                (gnus-last-element gnus-newsgroup-headers))))
4908       ;; GROUP is successfully selected.
4909       (or gnus-newsgroup-headers t)))))
4910
4911 (defun gnus-compute-unseen-list ()
4912   ;; The `seen' marks are treated specially.
4913   (if (not gnus-newsgroup-seen)
4914       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4915     (setq gnus-newsgroup-unseen
4916           (gnus-inverse-list-range-intersection
4917            gnus-newsgroup-articles gnus-newsgroup-seen))))
4918
4919 (defun gnus-summary-display-make-predicate (display)
4920   (require 'gnus-agent)
4921   (when (= (length display) 1)
4922     (setq display (car display)))
4923   (unless gnus-summary-display-cache
4924     (dolist (elem (append '((unread . unread)
4925                             (read . read)
4926                             (unseen . unseen))
4927                           gnus-article-mark-lists))
4928       (push (cons (cdr elem)
4929                   (gnus-byte-compile
4930                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4931             gnus-summary-display-cache)))
4932   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4933         (gnus-category-predicate-cache gnus-summary-display-cache))
4934     (gnus-get-predicate display)))
4935
4936 ;; Uses the dynamically bound `number' variable.
4937 (defvar number)
4938 (defun gnus-article-marked-p (type &optional article)
4939   (let ((article (or article number)))
4940     (cond
4941      ((eq type 'tick)
4942       (memq article gnus-newsgroup-marked))
4943      ((eq type 'unsend)
4944       (memq article gnus-newsgroup-unsendable))
4945      ((eq type 'undownload)
4946       (memq article gnus-newsgroup-undownloaded))
4947      ((eq type 'download)
4948       (memq article gnus-newsgroup-downloadable))
4949      ((eq type 'unread)
4950       (memq article gnus-newsgroup-unreads))
4951      ((eq type 'read)
4952       (memq article gnus-newsgroup-reads))
4953      ((eq type 'dormant)
4954       (memq article gnus-newsgroup-dormant) )
4955      ((eq type 'expire)
4956       (memq article gnus-newsgroup-expirable))
4957      ((eq type 'reply)
4958       (memq article gnus-newsgroup-replied))
4959      ((eq type 'killed)
4960       (memq article gnus-newsgroup-killed))
4961      ((eq type 'bookmark)
4962       (assq article gnus-newsgroup-bookmarks))
4963      ((eq type 'score)
4964       (assq article gnus-newsgroup-scored))
4965      ((eq type 'save)
4966       (memq article gnus-newsgroup-saved))
4967      ((eq type 'cache)
4968       (memq article gnus-newsgroup-cached))
4969      ((eq type 'forward)
4970       (memq article gnus-newsgroup-forwarded))
4971      ((eq type 'seen)
4972       (not (memq article gnus-newsgroup-unseen)))
4973      ((eq type 'recent)
4974       (memq article gnus-newsgroup-recent))
4975      (t t))))
4976
4977 (defun gnus-articles-to-read (group &optional read-all)
4978   "Find out what articles the user wants to read."
4979   (let* ((articles
4980           ;; Select all articles if `read-all' is non-nil, or if there
4981           ;; are no unread articles.
4982           (if (or read-all
4983                   (and (zerop (length gnus-newsgroup-marked))
4984                        (zerop (length gnus-newsgroup-unreads)))
4985                   ;; Fetch all if the predicate is non-nil.
4986                   gnus-newsgroup-display)
4987               ;; We want to select the headers for all the articles in
4988               ;; the group, so we select either all the active
4989               ;; articles in the group, or (if that's nil), the
4990               ;; articles in the cache.
4991               (or
4992                (gnus-uncompress-range (gnus-active group))
4993                (gnus-cache-articles-in-group group))
4994             ;; Select only the "normal" subset of articles.
4995             (gnus-sorted-nunion
4996              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4997              gnus-newsgroup-unreads)))
4998          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4999          (scored (length scored-list))
5000          (number (length articles))
5001          (marked (+ (length gnus-newsgroup-marked)
5002                     (length gnus-newsgroup-dormant)))
5003          (select
5004           (cond
5005            ((numberp read-all)
5006             read-all)
5007            ((numberp gnus-newsgroup-display)
5008             gnus-newsgroup-display)
5009            (t
5010             (condition-case ()
5011                 (cond
5012                  ((and (or (<= scored marked) (= scored number))
5013                        (numberp gnus-large-newsgroup)
5014                        (> number gnus-large-newsgroup))
5015                   (let* ((cursor-in-echo-area nil)
5016                          (initial (gnus-parameter-large-newsgroup-initial
5017                                    gnus-newsgroup-name))
5018                          (input
5019                           (read-string
5020                            (format
5021                             "How many articles from %s (%s %d): "
5022                             (gnus-limit-string
5023                              (gnus-group-decoded-name gnus-newsgroup-name)
5024                              35)
5025                             (if initial "max" "default")
5026                             number)
5027                            (if initial
5028                                (cons (number-to-string initial)
5029                                      0)))))
5030                     (if (string-match "^[ \t]*$" input) number input)))
5031                  ((and (> scored marked) (< scored number)
5032                        (> (- scored number) 20))
5033                   (let ((input
5034                          (read-string
5035                           (format "%s %s (%d scored, %d total): "
5036                                   "How many articles from"
5037                                   (gnus-group-decoded-name group)
5038                                   scored number))))
5039                     (if (string-match "^[ \t]*$" input)
5040                         number input)))
5041                  (t number))
5042               (quit
5043                (message "Quit getting the articles to read")
5044                nil))))))
5045     (setq select (if (stringp select) (string-to-number select) select))
5046     (if (or (null select) (zerop select))
5047         select
5048       (if (and (not (zerop scored)) (<= (abs select) scored))
5049           (progn
5050             (setq articles (sort scored-list '<))
5051             (setq number (length articles)))
5052         (setq articles (copy-sequence articles)))
5053
5054       (when (< (abs select) number)
5055         (if (< select 0)
5056             ;; Select the N oldest articles.
5057             (setcdr (nthcdr (1- (abs select)) articles) nil)
5058           ;; Select the N most recent articles.
5059           (setq articles (nthcdr (- number select) articles))))
5060       (setq gnus-newsgroup-unselected
5061             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5062       (when gnus-alter-articles-to-read-function
5063         (setq gnus-newsgroup-unreads
5064               (sort
5065                (funcall gnus-alter-articles-to-read-function
5066                         gnus-newsgroup-name gnus-newsgroup-unreads)
5067                '<)))
5068       articles)))
5069
5070 (defun gnus-killed-articles (killed articles)
5071   (let (out)
5072     (while articles
5073       (when (inline (gnus-member-of-range (car articles) killed))
5074         (push (car articles) out))
5075       (setq articles (cdr articles)))
5076     out))
5077
5078 (defun gnus-uncompress-marks (marks)
5079   "Uncompress the mark ranges in MARKS."
5080   (let ((uncompressed '(score bookmark))
5081         out)
5082     (while marks
5083       (if (memq (caar marks) uncompressed)
5084           (push (car marks) out)
5085         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5086       (setq marks (cdr marks)))
5087     out))
5088
5089 (defun gnus-article-mark-to-type (mark)
5090   "Return the type of MARK."
5091   (or (cadr (assq mark gnus-article-special-mark-lists))
5092       'list))
5093
5094 (defun gnus-article-unpropagatable-p (mark)
5095   "Return whether MARK should be propagated to backend."
5096   (memq mark gnus-article-unpropagated-mark-lists))
5097
5098 (defun gnus-adjust-marked-articles (info)
5099   "Set all article lists and remove all marks that are no longer valid."
5100   (let* ((marked-lists (gnus-info-marks info))
5101          (active (gnus-active (gnus-info-group info)))
5102          (min (car active))
5103          (max (cdr active))
5104          (types gnus-article-mark-lists)
5105          marks var articles article mark mark-type)
5106
5107     (dolist (marks marked-lists)
5108       (setq mark (car marks)
5109             mark-type (gnus-article-mark-to-type mark)
5110             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5111
5112       ;; We set the variable according to the type of the marks list,
5113       ;; and then adjust the marks to a subset of the active articles.
5114       (cond
5115        ;; Adjust "simple" lists.
5116        ((eq mark-type 'list)
5117         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5118         (when (memq mark '(tick dormant expire reply save))
5119           (while articles
5120             (when (or (< (setq article (pop articles)) min) (> article max))
5121               (set var (delq article (symbol-value var)))))))
5122        ;; Adjust assocs.
5123        ((eq mark-type 'tuple)
5124         (set var (setq articles (cdr marks)))
5125         (when (not (listp (cdr (symbol-value var))))
5126           (set var (list (symbol-value var))))
5127         (when (not (listp (cdr articles)))
5128           (setq articles (list articles)))
5129         (while articles
5130           (when (or (not (consp (setq article (pop articles))))
5131                     (< (car article) min)
5132                     (> (car article) max))
5133             (set var (delq article (symbol-value var))))))
5134        ;; Adjust ranges (sloppily).
5135        ((eq mark-type 'range)
5136         (cond
5137          ((eq mark 'seen)
5138           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5139           ;; It should be (seen (NUM1 . NUM2)).
5140           (when (numberp (cddr marks))
5141             (setcdr marks (list (cdr marks))))
5142           (setq articles (cdr marks))
5143           (while (and articles
5144                       (or (and (consp (car articles))
5145                                (> min (cdar articles)))
5146                           (and (numberp (car articles))
5147                                (> min (car articles)))))
5148             (pop articles))
5149           (set var articles))))))))
5150
5151 (defun gnus-update-missing-marks (missing)
5152   "Go through the list of MISSING articles and remove them from the mark lists."
5153   (when missing
5154     (let (var m)
5155       ;; Go through all types.
5156       (dolist (elem gnus-article-mark-lists)
5157         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5158           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5159           (when (symbol-value var)
5160             ;; This list has articles.  So we delete all missing
5161             ;; articles from it.
5162             (setq m missing)
5163             (while m
5164               (set var (delq (pop m) (symbol-value var))))))))))
5165
5166 (defun gnus-update-marks ()
5167   "Enter the various lists of marked articles into the newsgroup info list."
5168   (let ((types gnus-article-mark-lists)
5169         (info (gnus-get-info gnus-newsgroup-name))
5170         type list newmarked symbol delta-marks)
5171     (when info
5172       ;; Add all marks lists to the list of marks lists.
5173       (while (setq type (pop types))
5174         (setq list (symbol-value
5175                     (setq symbol
5176                           (intern (format "gnus-newsgroup-%s" (car type))))))
5177
5178         (when list
5179           ;; Get rid of the entries of the articles that have the
5180           ;; default score.
5181           (when (and (eq (cdr type) 'score)
5182                      gnus-save-score
5183                      list)
5184             (let* ((arts list)
5185                    (prev (cons nil list))
5186                    (all prev))
5187               (while arts
5188                 (if (or (not (consp (car arts)))
5189                         (= (cdar arts) gnus-summary-default-score))
5190                     (setcdr prev (cdr arts))
5191                   (setq prev arts))
5192                 (setq arts (cdr arts)))
5193               (setq list (cdr all)))))
5194
5195         (when (eq (cdr type) 'seen)
5196           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5197
5198         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5199           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5200
5201         (when (and (gnus-check-backend-function
5202                     'request-set-mark gnus-newsgroup-name)
5203                    (not (gnus-article-unpropagatable-p (cdr type))))
5204           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5205                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5206                  (add (gnus-remove-from-range
5207                        (gnus-copy-sequence list) old)))
5208             (when add
5209               (push (list add 'add (list (cdr type))) delta-marks))
5210             (when del
5211               (push (list del 'del (list (cdr type))) delta-marks))))
5212
5213         (when list
5214           (push (cons (cdr type) list) newmarked)))
5215
5216       (when delta-marks
5217         (unless (gnus-check-group gnus-newsgroup-name)
5218           (error "Can't open server for %s" gnus-newsgroup-name))
5219         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5220
5221       ;; Enter these new marks into the info of the group.
5222       (if (nthcdr 3 info)
5223           (setcar (nthcdr 3 info) newmarked)
5224         ;; Add the marks lists to the end of the info.
5225         (when newmarked
5226           (setcdr (nthcdr 2 info) (list newmarked))))
5227
5228       ;; Cut off the end of the info if there's nothing else there.
5229       (let ((i 5))
5230         (while (and (> i 2)
5231                     (not (nth i info)))
5232           (when (nthcdr (decf i) info)
5233             (setcdr (nthcdr i info) nil)))))))
5234
5235 (defun gnus-set-mode-line (where)
5236   "Set the mode line of the article or summary buffers.
5237 If WHERE is `summary', the summary mode line format will be used."
5238   ;; Is this mode line one we keep updated?
5239   (when (and (memq where gnus-updated-mode-lines)
5240              (symbol-value
5241               (intern (format "gnus-%s-mode-line-format-spec" where))))
5242     (let (mode-string)
5243       (save-excursion
5244         ;; We evaluate this in the summary buffer since these
5245         ;; variables are buffer-local to that buffer.
5246         (set-buffer gnus-summary-buffer)
5247         ;; We bind all these variables that are used in the `eval' form
5248         ;; below.
5249         (let* ((mformat (symbol-value
5250                          (intern
5251                           (format "gnus-%s-mode-line-format-spec" where))))
5252                (gnus-tmp-group-name (gnus-group-decoded-name
5253                                      gnus-newsgroup-name))
5254                (gnus-tmp-article-number (or gnus-current-article 0))
5255                (gnus-tmp-unread gnus-newsgroup-unreads)
5256                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5257                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5258                (gnus-tmp-unread-and-unselected
5259                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5260                             (zerop gnus-tmp-unselected))
5261                        "")
5262                       ((zerop gnus-tmp-unselected)
5263                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5264                       (t (format "{%d(+%d) more}"
5265                                  gnus-tmp-unread-and-unticked
5266                                  gnus-tmp-unselected))))
5267                (gnus-tmp-subject
5268                 (if (and gnus-current-headers
5269                          (vectorp gnus-current-headers))
5270                     (gnus-mode-string-quote
5271                      (mail-header-subject gnus-current-headers))
5272                   ""))
5273                bufname-length max-len
5274                gnus-tmp-header);; passed as argument to any user-format-funcs
5275           (setq mode-string (eval mformat))
5276           (setq bufname-length (if (string-match "%b" mode-string)
5277                                    (- (length
5278                                        (buffer-name
5279                                         (if (eq where 'summary)
5280                                             nil
5281                                           (get-buffer gnus-article-buffer))))
5282                                       2)
5283                                  0))
5284           (setq max-len (max 4 (if gnus-mode-non-string-length
5285                                    (- (window-width)
5286                                       gnus-mode-non-string-length
5287                                       bufname-length)
5288                                  (length mode-string))))
5289           ;; We might have to chop a bit of the string off...
5290           (when (> (length mode-string) max-len)
5291             (setq mode-string
5292                   (concat (gnus-truncate-string mode-string (- max-len 3))
5293                           "...")))
5294           ;; Pad the mode string a bit.
5295           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5296       ;; Update the mode line.
5297       (setq mode-line-buffer-identification
5298             (gnus-mode-line-buffer-identification (list mode-string)))
5299       (set-buffer-modified-p t))))
5300
5301 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5302   "Go through the HEADERS list and add all Xrefs to a hash table.
5303 The resulting hash table is returned, or nil if no Xrefs were found."
5304   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5305          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5306          (xref-hashtb (gnus-make-hashtable))
5307          start group entry number xrefs header)
5308     (while headers
5309       (setq header (pop headers))
5310       (when (and (setq xrefs (mail-header-xref header))
5311                  (not (memq (setq number (mail-header-number header))
5312                             unreads)))
5313         (setq start 0)
5314         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5315           (setq start (match-end 0))
5316           (setq group (if prefix
5317                           (concat prefix (substring xrefs (match-beginning 1)
5318                                                     (match-end 1)))
5319                         (substring xrefs (match-beginning 1) (match-end 1))))
5320           (setq number
5321                 (string-to-int (substring xrefs (match-beginning 2)
5322                                           (match-end 2))))
5323           (if (setq entry (gnus-gethash group xref-hashtb))
5324               (setcdr entry (cons number (cdr entry)))
5325             (gnus-sethash group (cons number nil) xref-hashtb)))))
5326     (and start xref-hashtb)))
5327
5328 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5329   "Look through all the headers and mark the Xrefs as read."
5330   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5331         name entry info xref-hashtb idlist method nth4)
5332     (save-excursion
5333       (set-buffer gnus-group-buffer)
5334       (when (setq xref-hashtb
5335                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5336         (mapatoms
5337          (lambda (group)
5338            (unless (string= from-newsgroup (setq name (symbol-name group)))
5339              (setq idlist (symbol-value group))
5340              ;; Dead groups are not updated.
5341              (and (prog1
5342                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5343                             info (nth 2 entry))
5344                     (when (stringp (setq nth4 (gnus-info-method info)))
5345                       (setq nth4 (gnus-server-to-method nth4))))
5346                   ;; Only do the xrefs if the group has the same
5347                   ;; select method as the group we have just read.
5348                   (or (gnus-methods-equal-p
5349                        nth4 (gnus-find-method-for-group from-newsgroup))
5350                       virtual
5351                       (equal nth4 (setq method (gnus-find-method-for-group
5352                                                 from-newsgroup)))
5353                       (and (equal (car nth4) (car method))
5354                            (equal (nth 1 nth4) (nth 1 method))))
5355                   gnus-use-cross-reference
5356                   (or (not (eq gnus-use-cross-reference t))
5357                       virtual
5358                       ;; Only do cross-references on subscribed
5359                       ;; groups, if that is what is wanted.
5360                       (<= (gnus-info-level info) gnus-level-subscribed))
5361                   (gnus-group-make-articles-read name idlist))))
5362          xref-hashtb)))))
5363
5364 (defun gnus-compute-read-articles (group articles)
5365   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5366          (info (nth 2 entry))
5367          (active (gnus-active group))
5368          ninfo)
5369     (when entry
5370       ;; First peel off all invalid article numbers.
5371       (when active
5372         (let ((ids articles)
5373               id first)
5374           (while (setq id (pop ids))
5375             (when (and first (> id (cdr active)))
5376               ;; We'll end up in this situation in one particular
5377               ;; obscure situation.  If you re-scan a group and get
5378               ;; a new article that is cross-posted to a different
5379               ;; group that has not been re-scanned, you might get
5380               ;; crossposted article that has a higher number than
5381               ;; Gnus believes possible.  So we re-activate this
5382               ;; group as well.  This might mean doing the
5383               ;; crossposting thingy will *increase* the number
5384               ;; of articles in some groups.  Tsk, tsk.
5385               (setq active (or (gnus-activate-group group) active)))
5386             (when (or (> id (cdr active))
5387                       (< id (car active)))
5388               (setq articles (delq id articles))))))
5389       ;; If the read list is nil, we init it.
5390       (if (and active
5391                (null (gnus-info-read info))
5392                (> (car active) 1))
5393           (setq ninfo (cons 1 (1- (car active))))
5394         (setq ninfo (gnus-info-read info)))
5395       ;; Then we add the read articles to the range.
5396       (gnus-add-to-range
5397        ninfo (setq articles (sort articles '<))))))
5398
5399 (defun gnus-group-make-articles-read (group articles)
5400   "Update the info of GROUP to say that ARTICLES are read."
5401   (let* ((num 0)
5402          (entry (gnus-gethash group gnus-newsrc-hashtb))
5403          (info (nth 2 entry))
5404          (active (gnus-active group))
5405          range)
5406     (when entry
5407       (setq range (gnus-compute-read-articles group articles))
5408       (save-excursion
5409         (set-buffer gnus-group-buffer)
5410         (gnus-undo-register
5411           `(progn
5412              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5413              (gnus-info-set-read ',info ',(gnus-info-read info))
5414              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5415              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5416              (gnus-group-update-group ,group t))))
5417       ;; Add the read articles to the range.
5418       (gnus-info-set-read info range)
5419       (gnus-request-set-mark group (list (list range 'add '(read))))
5420       ;; Then we have to re-compute how many unread
5421       ;; articles there are in this group.
5422       (when active
5423         (cond
5424          ((not range)
5425           (setq num (- (1+ (cdr active)) (car active))))
5426          ((not (listp (cdr range)))
5427           (setq num (- (cdr active) (- (1+ (cdr range))
5428                                        (car range)))))
5429          (t
5430           (while range
5431             (if (numberp (car range))
5432                 (setq num (1+ num))
5433               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5434             (setq range (cdr range)))
5435           (setq num (- (cdr active) num))))
5436         ;; Update the number of unread articles.
5437         (setcar entry num)
5438         ;; Update the group buffer.
5439         (gnus-group-update-group group t)))))
5440
5441 (defvar gnus-newsgroup-none-id 0)
5442
5443 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5444   (let ((cur nntp-server-buffer)
5445         (dependencies
5446          (or dependencies
5447              (save-excursion (set-buffer gnus-summary-buffer)
5448                              gnus-newsgroup-dependencies)))
5449         headers id end ref
5450         (mail-parse-charset gnus-newsgroup-charset)
5451         (mail-parse-ignored-charsets
5452          (save-excursion (condition-case nil
5453                              (set-buffer gnus-summary-buffer)
5454                            (error))
5455                          gnus-newsgroup-ignored-charsets)))
5456     (save-excursion
5457       (set-buffer nntp-server-buffer)
5458       ;; Translate all TAB characters into SPACE characters.
5459       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5460       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5461       (gnus-run-hooks 'gnus-parse-headers-hook)
5462       (let ((case-fold-search t)
5463             in-reply-to header p lines chars ctype)
5464         (goto-char (point-min))
5465         ;; Search to the beginning of the next header.  Error messages
5466         ;; do not begin with 2 or 3.
5467         (while (re-search-forward "^[23][0-9]+ " nil t)
5468           (setq id nil
5469                 ref nil)
5470           ;; This implementation of this function, with nine
5471           ;; search-forwards instead of the one re-search-forward and
5472           ;; a case (which basically was the old function) is actually
5473           ;; about twice as fast, even though it looks messier.  You
5474           ;; can't have everything, I guess.  Speed and elegance
5475           ;; doesn't always go hand in hand.
5476           (setq
5477            header
5478            (make-full-mail-header
5479             ;; Number.
5480             (prog1
5481                 (read cur)
5482               (end-of-line)
5483               (setq p (point))
5484               (narrow-to-region (point)
5485                                 (or (and (search-forward "\n.\n" nil t)
5486                                          (- (point) 2))
5487                                     (point))))
5488             ;; Subject.
5489             (progn
5490               (goto-char p)
5491               (if (search-forward "\nsubject:" nil t)
5492                   (nnheader-header-value)
5493                 "(none)"))
5494             ;; From.
5495             (progn
5496               (goto-char p)
5497               (if (search-forward "\nfrom:" nil t)
5498                   (nnheader-header-value)
5499                 "(nobody)"))
5500             ;; Date.
5501             (progn
5502               (goto-char p)
5503               (if (search-forward "\ndate:" nil t)
5504                   (nnheader-header-value) ""))
5505             ;; Message-ID.
5506             (progn
5507               (goto-char p)
5508               (setq id (if (re-search-forward
5509                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5510                            ;; We do it this way to make sure the Message-ID
5511                            ;; is (somewhat) syntactically valid.
5512                            (buffer-substring (match-beginning 1)
5513                                              (match-end 1))
5514                          ;; If there was no message-id, we just fake one
5515                          ;; to make subsequent routines simpler.
5516                          (nnheader-generate-fake-message-id))))
5517             ;; References.
5518             (progn
5519               (goto-char p)
5520               (if (search-forward "\nreferences:" nil t)
5521                   (progn
5522                     (setq end (point))
5523                     (prog1
5524                         (nnheader-header-value)
5525                       (setq ref
5526                             (buffer-substring
5527                              (progn
5528                                ;; (end-of-line)
5529                                (search-backward ">" end t)
5530                                (1+ (point)))
5531                              (progn
5532                                (search-backward "<" end t)
5533                                (point))))))
5534                 ;; Get the references from the in-reply-to header if there
5535                 ;; were no references and the in-reply-to header looks
5536                 ;; promising.
5537                 (if (and (search-forward "\nin-reply-to:" nil t)
5538                          (setq in-reply-to (nnheader-header-value))
5539                          (string-match "<[^>]+>" in-reply-to))
5540                     (let (ref2)
5541                       (setq ref (substring in-reply-to (match-beginning 0)
5542                                            (match-end 0)))
5543                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5544                         (setq ref2 (substring in-reply-to (match-beginning 0)
5545                                               (match-end 0)))
5546                         (when (> (length ref2) (length ref))
5547                           (setq ref ref2)))
5548                       ref)
5549                   (setq ref nil))))
5550             ;; Chars.
5551             (progn
5552               (goto-char p)
5553               (if (search-forward "\nchars: " nil t)
5554                   (if (numberp (setq chars (ignore-errors (read cur))))
5555                       chars -1)
5556                 -1))
5557             ;; Lines.
5558             (progn
5559               (goto-char p)
5560               (if (search-forward "\nlines: " nil t)
5561                   (if (numberp (setq lines (ignore-errors (read cur))))
5562                       lines -1)
5563                 -1))
5564             ;; Xref.
5565             (progn
5566               (goto-char p)
5567               (and (search-forward "\nxref:" nil t)
5568                    (nnheader-header-value)))
5569             ;; Extra.
5570             (when gnus-extra-headers
5571               (let ((extra gnus-extra-headers)
5572                     out)
5573                 (while extra
5574                   (goto-char p)
5575                   (when (search-forward
5576                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5577                     (push (cons (car extra) (nnheader-header-value)) out))
5578                   (pop extra))
5579                 out))))
5580           (goto-char p)
5581           (if (and (search-forward "\ncontent-type: " nil t)
5582                    (setq ctype (nnheader-header-value)))
5583               (mime-entity-set-content-type-internal
5584                header (mime-parse-Content-Type ctype)))
5585           (when (equal id ref)
5586             (setq ref nil))
5587
5588           (when gnus-alter-header-function
5589             (funcall gnus-alter-header-function header)
5590             (setq id (mail-header-id header)
5591                   ref (gnus-parent-id (mail-header-references header))))
5592
5593           (when (setq header
5594                       (gnus-dependencies-add-header
5595                        header dependencies force-new))
5596             (push header headers))
5597           (goto-char (point-max))
5598           (widen))
5599         (nreverse headers)))))
5600
5601 ;; Goes through the xover lines and returns a list of vectors
5602 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5603                                                   force-new dependencies
5604                                                   group also-fetch-heads)
5605   "Parse the news overview data in the server buffer.
5606 Return a list of headers that match SEQUENCE (see
5607 `nntp-retrieve-headers')."
5608   ;; Get the Xref when the users reads the articles since most/some
5609   ;; NNTP servers do not include Xrefs when using XOVER.
5610   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5611   (let ((mail-parse-charset gnus-newsgroup-charset)
5612         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5613         (cur nntp-server-buffer)
5614         (dependencies (or dependencies gnus-newsgroup-dependencies))
5615         (allp (cond
5616                ((eq gnus-read-all-available-headers t)
5617                 t)
5618                ((stringp gnus-read-all-available-headers)
5619                 (string-match gnus-read-all-available-headers group))
5620                (t
5621                 nil)))
5622         number headers header)
5623     (save-excursion
5624       (set-buffer nntp-server-buffer)
5625       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5626       ;; Allow the user to mangle the headers before parsing them.
5627       (gnus-run-hooks 'gnus-parse-headers-hook)
5628       (goto-char (point-min))
5629       (gnus-parse-without-error
5630         (while (and (or sequence allp)
5631                     (not (eobp)))
5632           (setq number (read cur))
5633           (when (not allp)
5634             (while (and sequence
5635                         (< (car sequence) number))
5636               (setq sequence (cdr sequence))))
5637           (when (and (or allp
5638                          (and sequence
5639                               (eq number (car sequence))))
5640                      (progn
5641                        (setq sequence (cdr sequence))
5642                        (setq header (inline
5643                                       (gnus-nov-parse-line
5644                                        number dependencies force-new)))))
5645             (push header headers))
5646           (forward-line 1)))
5647       ;; A common bug in inn is that if you have posted an article and
5648       ;; then retrieves the active file, it will answer correctly --
5649       ;; the new article is included.  However, a NOV entry for the
5650       ;; article may not have been generated yet, so this may fail.
5651       ;; We work around this problem by retrieving the last few
5652       ;; headers using HEAD.
5653       (if (or (not also-fetch-heads)
5654               (not sequence))
5655           ;; We (probably) got all the headers.
5656           (nreverse headers)
5657         (let ((gnus-nov-is-evil t))
5658           (nconc
5659            (nreverse headers)
5660            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5661              (gnus-get-newsgroup-headers))))))))
5662
5663 (defun gnus-article-get-xrefs ()
5664   "Fill in the Xref value in `gnus-current-headers', if necessary.
5665 This is meant to be called in `gnus-article-internal-prepare-hook'."
5666   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5667                                  gnus-current-headers)))
5668     (or (not gnus-use-cross-reference)
5669         (not headers)
5670         (and (mail-header-xref headers)
5671              (not (string= (mail-header-xref headers) "")))
5672         (let ((case-fold-search t)
5673               xref)
5674           (save-restriction
5675             (nnheader-narrow-to-headers)
5676             (goto-char (point-min))
5677             (when (or (and (not (eobp))
5678                            (eq (downcase (char-after)) ?x)
5679                            (looking-at "Xref:"))
5680                       (search-forward "\nXref:" nil t))
5681               (goto-char (1+ (match-end 0)))
5682               (setq xref (buffer-substring (point)
5683                                            (progn (end-of-line) (point))))
5684               (mail-header-set-xref headers xref)))))))
5685
5686 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5687   "Find article ID and insert the summary line for that article.
5688 OLD-HEADER can either be a header or a line number to insert
5689 the subject line on."
5690   (let* ((line (and (numberp old-header) old-header))
5691          (old-header (and (vectorp old-header) old-header))
5692          (header (cond ((and old-header use-old-header)
5693                         old-header)
5694                        ((and (numberp id)
5695                              (gnus-number-to-header id))
5696                         (gnus-number-to-header id))
5697                        (t
5698                         (gnus-read-header id))))
5699          (number (and (numberp id) id))
5700          d)
5701     (when header
5702       ;; Rebuild the thread that this article is part of and go to the
5703       ;; article we have fetched.
5704       (when (and (not gnus-show-threads)
5705                  old-header)
5706         (when (and number
5707                    (setq d (gnus-data-find (mail-header-number old-header))))
5708           (goto-char (gnus-data-pos d))
5709           (gnus-data-remove
5710            number
5711            (- (gnus-point-at-bol)
5712               (prog1
5713                   (1+ (gnus-point-at-eol))
5714                 (gnus-delete-line))))))
5715       (when old-header
5716         (mail-header-set-number header (mail-header-number old-header)))
5717       (setq gnus-newsgroup-sparse
5718             (delq (setq number (mail-header-number header))
5719                   gnus-newsgroup-sparse))
5720       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5721       (push number gnus-newsgroup-limit)
5722       (gnus-rebuild-thread (mail-header-id header) line)
5723       (gnus-summary-goto-subject number nil t))
5724     (when (and (numberp number)
5725                (> number 0))
5726       ;; We have to update the boundaries even if we can't fetch the
5727       ;; article if ID is a number -- so that the next `P' or `N'
5728       ;; command will fetch the previous (or next) article even
5729       ;; if the one we tried to fetch this time has been canceled.
5730       (when (> number gnus-newsgroup-end)
5731         (setq gnus-newsgroup-end number))
5732       (when (< number gnus-newsgroup-begin)
5733         (setq gnus-newsgroup-begin number))
5734       (setq gnus-newsgroup-unselected
5735             (delq number gnus-newsgroup-unselected)))
5736     ;; Report back a success?
5737     (and header (mail-header-number header))))
5738
5739 ;;; Process/prefix in the summary buffer
5740
5741 (defun gnus-summary-work-articles (n)
5742   "Return a list of articles to be worked upon.
5743 The prefix argument, the list of process marked articles, and the
5744 current article will be taken into consideration."
5745   (save-excursion
5746     (set-buffer gnus-summary-buffer)
5747     (cond
5748      (n
5749       ;; A numerical prefix has been given.
5750       (setq n (prefix-numeric-value n))
5751       (let ((backward (< n 0))
5752             (n (abs (prefix-numeric-value n)))
5753             articles article)
5754         (save-excursion
5755           (while
5756               (and (> n 0)
5757                    (push (setq article (gnus-summary-article-number))
5758                          articles)
5759                    (if backward
5760                        (gnus-summary-find-prev nil article)
5761                      (gnus-summary-find-next nil article)))
5762             (decf n)))
5763         (nreverse articles)))
5764      ((and (gnus-region-active-p) (mark))
5765       (message "region active")
5766       ;; Work on the region between point and mark.
5767       (let ((max (max (point) (mark)))
5768             articles article)
5769         (save-excursion
5770           (goto-char (min (point) (mark)))
5771           (while
5772               (and
5773                (push (setq article (gnus-summary-article-number)) articles)
5774                (gnus-summary-find-next nil article)
5775                (< (point) max)))
5776           (nreverse articles))))
5777      (gnus-newsgroup-processable
5778       ;; There are process-marked articles present.
5779       ;; Save current state.
5780       (gnus-summary-save-process-mark)
5781       ;; Return the list.
5782       (reverse gnus-newsgroup-processable))
5783      (t
5784       ;; Just return the current article.
5785       (list (gnus-summary-article-number))))))
5786
5787 (defmacro gnus-summary-iterate (arg &rest forms)
5788   "Iterate over the process/prefixed articles and do FORMS.
5789 ARG is the interactive prefix given to the command.  FORMS will be
5790 executed with point over the summary line of the articles."
5791   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5792     `(let ((,articles (gnus-summary-work-articles ,arg)))
5793        (while ,articles
5794          (gnus-summary-goto-subject (car ,articles))
5795          ,@forms
5796          (pop ,articles)))))
5797
5798 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5799 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5800
5801 (defun gnus-summary-save-process-mark ()
5802   "Push the current set of process marked articles on the stack."
5803   (interactive)
5804   (push (copy-sequence gnus-newsgroup-processable)
5805         gnus-newsgroup-process-stack))
5806
5807 (defun gnus-summary-kill-process-mark ()
5808   "Push the current set of process marked articles on the stack and unmark."
5809   (interactive)
5810   (gnus-summary-save-process-mark)
5811   (gnus-summary-unmark-all-processable))
5812
5813 (defun gnus-summary-yank-process-mark ()
5814   "Pop the last process mark state off the stack and restore it."
5815   (interactive)
5816   (unless gnus-newsgroup-process-stack
5817     (error "Empty mark stack"))
5818   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5819
5820 (defun gnus-summary-process-mark-set (set)
5821   "Make SET into the current process marked articles."
5822   (gnus-summary-unmark-all-processable)
5823   (while set
5824     (gnus-summary-set-process-mark (pop set))))
5825
5826 ;;; Searching and stuff
5827
5828 (defun gnus-summary-search-group (&optional backward use-level)
5829   "Search for next unread newsgroup.
5830 If optional argument BACKWARD is non-nil, search backward instead."
5831   (save-excursion
5832     (set-buffer gnus-group-buffer)
5833     (when (gnus-group-search-forward
5834            backward nil (if use-level (gnus-group-group-level) nil))
5835       (gnus-group-group-name))))
5836
5837 (defun gnus-summary-best-group (&optional exclude-group)
5838   "Find the name of the best unread group.
5839 If EXCLUDE-GROUP, do not go to this group."
5840   (save-excursion
5841     (set-buffer gnus-group-buffer)
5842     (save-excursion
5843       (gnus-group-best-unread-group exclude-group))))
5844
5845 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5846   (if backward (gnus-summary-find-prev)
5847     (let* ((dummy (gnus-summary-article-intangible-p))
5848            (article (or article (gnus-summary-article-number)))
5849            (arts (gnus-data-find-list article))
5850            result)
5851       (when (and (not dummy)
5852                  (or (not gnus-summary-check-current)
5853                      (not unread)
5854                      (not (gnus-data-unread-p (car arts)))))
5855         (setq arts (cdr arts)))
5856       (when (setq result
5857                   (if unread
5858                       (progn
5859                         (while arts
5860                           (when (or (and undownloaded
5861                                          (eq gnus-undownloaded-mark
5862                                              (gnus-data-mark (car arts))))
5863                                     (gnus-data-unread-p (car arts)))
5864                             (setq result (car arts)
5865                                   arts nil))
5866                           (setq arts (cdr arts)))
5867                         result)
5868                     (car arts)))
5869         (goto-char (gnus-data-pos result))
5870         (gnus-data-number result)))))
5871
5872 (defun gnus-summary-find-prev (&optional unread article)
5873   (let* ((eobp (eobp))
5874          (article (or article (gnus-summary-article-number)))
5875          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5876          result)
5877     (when (and (not eobp)
5878                (or (not gnus-summary-check-current)
5879                    (not unread)
5880                    (not (gnus-data-unread-p (car arts)))))
5881       (setq arts (cdr arts)))
5882     (when (setq result
5883                 (if unread
5884                     (progn
5885                       (while arts
5886                         (when (gnus-data-unread-p (car arts))
5887                           (setq result (car arts)
5888                                 arts nil))
5889                         (setq arts (cdr arts)))
5890                       result)
5891                   (car arts)))
5892       (goto-char (gnus-data-pos result))
5893       (gnus-data-number result))))
5894
5895 (defun gnus-summary-find-subject (subject &optional unread backward article)
5896   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5897          (article (or article (gnus-summary-article-number)))
5898          (articles (gnus-data-list backward))
5899          (arts (gnus-data-find-list article articles))
5900          result)
5901     (when (or (not gnus-summary-check-current)
5902               (not unread)
5903               (not (gnus-data-unread-p (car arts))))
5904       (setq arts (cdr arts)))
5905     (while arts
5906       (and (or (not unread)
5907                (gnus-data-unread-p (car arts)))
5908            (vectorp (gnus-data-header (car arts)))
5909            (gnus-subject-equal
5910             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5911            (setq result (car arts)
5912                  arts nil))
5913       (setq arts (cdr arts)))
5914     (and result
5915          (goto-char (gnus-data-pos result))
5916          (gnus-data-number result))))
5917
5918 (defun gnus-summary-search-forward (&optional unread subject backward)
5919   "Search forward for an article.
5920 If UNREAD, look for unread articles.  If SUBJECT, look for
5921 articles with that subject.  If BACKWARD, search backward instead."
5922   (cond (subject (gnus-summary-find-subject subject unread backward))
5923         (backward (gnus-summary-find-prev unread))
5924         (t (gnus-summary-find-next unread))))
5925
5926 (defun gnus-recenter (&optional n)
5927   "Center point in window and redisplay frame.
5928 Also do horizontal recentering."
5929   (interactive "P")
5930   (when (and gnus-auto-center-summary
5931              (not (eq gnus-auto-center-summary 'vertical)))
5932     (gnus-horizontal-recenter))
5933   (recenter n))
5934
5935 (defun gnus-summary-recenter ()
5936   "Center point in the summary window.
5937 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5938 displayed, no centering will be performed."
5939   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5940   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5941   (interactive)
5942   (let* ((top (cond ((< (window-height) 4) 0)
5943                     ((< (window-height) 7) 1)
5944                     (t (if (numberp gnus-auto-center-summary)
5945                            gnus-auto-center-summary
5946                          2))))
5947          (height (1- (window-height)))
5948          (bottom (save-excursion (goto-char (point-max))
5949                                  (forward-line (- height))
5950                                  (point)))
5951          (window (get-buffer-window (current-buffer))))
5952     ;; The user has to want it.
5953     (when gnus-auto-center-summary
5954       (when (get-buffer-window gnus-article-buffer)
5955         ;; Only do recentering when the article buffer is displayed,
5956         ;; Set the window start to either `bottom', which is the biggest
5957         ;; possible valid number, or the second line from the top,
5958         ;; whichever is the least.
5959         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5960           (if (> bottom top-pos)
5961               ;; Keep the second line from the top visible
5962               (set-window-start window top-pos t)
5963             ;; Try to keep the bottom line visible; if it's partially
5964             ;; obscured, either scroll one more line to make it fully
5965             ;; visible, or revert to using TOP-POS.
5966             (save-excursion
5967               (goto-char (point-max))
5968               (forward-line -1)
5969               (let ((last-line-start (point)))
5970                 (goto-char bottom)
5971                 (set-window-start window (point) t)
5972                 (when (not (pos-visible-in-window-p last-line-start window))
5973                   (forward-line 1)
5974                   (set-window-start window (min (point) top-pos) t)))))))
5975       ;; Do horizontal recentering while we're at it.
5976       (when (and (get-buffer-window (current-buffer) t)
5977                  (not (eq gnus-auto-center-summary 'vertical)))
5978         (let ((selected (selected-window)))
5979           (select-window (get-buffer-window (current-buffer) t))
5980           (gnus-summary-position-point)
5981           (gnus-horizontal-recenter)
5982           (select-window selected))))))
5983
5984 (defun gnus-summary-jump-to-group (newsgroup)
5985   "Move point to NEWSGROUP in group mode buffer."
5986   ;; Keep update point of group mode buffer if visible.
5987   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5988       (save-window-excursion
5989         ;; Take care of tree window mode.
5990         (when (get-buffer-window gnus-group-buffer)
5991           (pop-to-buffer gnus-group-buffer))
5992         (gnus-group-jump-to-group newsgroup))
5993     (save-excursion
5994       ;; Take care of tree window mode.
5995       (if (get-buffer-window gnus-group-buffer)
5996           (pop-to-buffer gnus-group-buffer)
5997         (set-buffer gnus-group-buffer))
5998       (gnus-group-jump-to-group newsgroup))))
5999
6000 ;; This function returns a list of article numbers based on the
6001 ;; difference between the ranges of read articles in this group and
6002 ;; the range of active articles.
6003 (defun gnus-list-of-unread-articles (group)
6004   (let* ((read (gnus-info-read (gnus-get-info group)))
6005          (active (or (gnus-active group) (gnus-activate-group group)))
6006          (last (cdr active))
6007          first nlast unread)
6008     ;; If none are read, then all are unread.
6009     (if (not read)
6010         (setq first (car active))
6011       ;; If the range of read articles is a single range, then the
6012       ;; first unread article is the article after the last read
6013       ;; article.  Sounds logical, doesn't it?
6014       (if (and (not (listp (cdr read)))
6015                (or (< (car read) (car active))
6016                    (progn (setq read (list read))
6017                           nil)))
6018           (setq first (max (car active) (1+ (cdr read))))
6019         ;; `read' is a list of ranges.
6020         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6021                                   (caar read)))
6022                   1)
6023           (setq first (car active)))
6024         (while read
6025           (when first
6026             (while (< first nlast)
6027               (push first unread)
6028               (setq first (1+ first))))
6029           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6030           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6031           (setq read (cdr read)))))
6032     ;; And add the last unread articles.
6033     (while (<= first last)
6034       (push first unread)
6035       (setq first (1+ first)))
6036     ;; Return the list of unread articles.
6037     (delq 0 (nreverse unread))))
6038
6039 (defun gnus-list-of-read-articles (group)
6040   "Return a list of unread, unticked and non-dormant articles."
6041   (let* ((info (gnus-get-info group))
6042          (marked (gnus-info-marks info))
6043          (active (gnus-active group)))
6044     (and info active
6045          (gnus-list-range-difference
6046           (gnus-list-range-difference
6047            (gnus-sorted-complement
6048             (gnus-uncompress-range active)
6049             (gnus-list-of-unread-articles group))
6050            (cdr (assq 'dormant marked)))
6051           (cdr (assq 'tick marked))))))
6052
6053 ;; Various summary commands
6054
6055 (defun gnus-summary-select-article-buffer ()
6056   "Reconfigure windows to show article buffer."
6057   (interactive)
6058   (if (not (gnus-buffer-live-p gnus-article-buffer))
6059       (error "There is no article buffer for this summary buffer")
6060     (gnus-configure-windows 'article)
6061     (select-window (get-buffer-window gnus-article-buffer))))
6062
6063 (defun gnus-summary-universal-argument (arg)
6064   "Perform any operation on all articles that are process/prefixed."
6065   (interactive "P")
6066   (let ((articles (gnus-summary-work-articles arg))
6067         func article)
6068     (if (eq
6069          (setq
6070           func
6071           (key-binding
6072            (read-key-sequence
6073             (substitute-command-keys
6074              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6075          'undefined)
6076         (gnus-error 1 "Undefined key")
6077       (save-excursion
6078         (while articles
6079           (gnus-summary-goto-subject (setq article (pop articles)))
6080           (let (gnus-newsgroup-processable)
6081             (command-execute func))
6082           (gnus-summary-remove-process-mark article)))))
6083   (gnus-summary-position-point))
6084
6085 (defun gnus-summary-toggle-truncation (&optional arg)
6086   "Toggle truncation of summary lines.
6087 With arg, turn line truncation on iff arg is positive."
6088   (interactive "P")
6089   (setq truncate-lines
6090         (if (null arg) (not truncate-lines)
6091           (> (prefix-numeric-value arg) 0)))
6092   (redraw-display))
6093
6094 (defun gnus-summary-reselect-current-group (&optional all rescan)
6095   "Exit and then reselect the current newsgroup.
6096 The prefix argument ALL means to select all articles."
6097   (interactive "P")
6098   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6099     (error "Ephemeral groups can't be reselected"))
6100   (let ((current-subject (gnus-summary-article-number))
6101         (group gnus-newsgroup-name))
6102     (setq gnus-newsgroup-begin nil)
6103     (gnus-summary-exit)
6104     ;; We have to adjust the point of group mode buffer because
6105     ;; point was moved to the next unread newsgroup by exiting.
6106     (gnus-summary-jump-to-group group)
6107     (when rescan
6108       (save-excursion
6109         (save-window-excursion
6110           ;; Don't show group contents.
6111           (set-window-start (selected-window) (point-max))
6112           (gnus-group-get-new-news-this-group 1))))
6113     (gnus-group-read-group all t)
6114     (gnus-summary-goto-subject current-subject nil t)))
6115
6116 (defun gnus-summary-rescan-group (&optional all)
6117   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6118   (interactive "P")
6119   (gnus-summary-reselect-current-group all t))
6120
6121 (defun gnus-summary-update-info (&optional non-destructive)
6122   (save-excursion
6123     (let ((group gnus-newsgroup-name))
6124       (when group
6125         (when gnus-newsgroup-kill-headers
6126           (setq gnus-newsgroup-killed
6127                 (gnus-compress-sequence
6128                  (gnus-sorted-union
6129                   (gnus-list-range-intersection
6130                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6131                   gnus-newsgroup-unreads)
6132                  t)))
6133         (unless (listp (cdr gnus-newsgroup-killed))
6134           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6135         (let ((headers gnus-newsgroup-headers))
6136           ;; Set the new ranges of read articles.
6137           (save-excursion
6138             (set-buffer gnus-group-buffer)
6139             (gnus-undo-force-boundary))
6140           (gnus-update-read-articles
6141            group (gnus-sorted-union
6142                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6143           ;; Set the current article marks.
6144           (let ((gnus-newsgroup-scored
6145                  (if (and (not gnus-save-score)
6146                           (not non-destructive))
6147                      nil
6148                    gnus-newsgroup-scored)))
6149             (save-excursion
6150               (gnus-update-marks)))
6151           ;; Do the cross-ref thing.
6152           (when gnus-use-cross-reference
6153             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6154           ;; Do not switch windows but change the buffer to work.
6155           (set-buffer gnus-group-buffer)
6156           (unless (gnus-ephemeral-group-p group)
6157             (gnus-group-update-group group)))))))
6158
6159 (defun gnus-summary-save-newsrc (&optional force)
6160   "Save the current number of read/marked articles in the dribble buffer.
6161 The dribble buffer will then be saved.
6162 If FORCE (the prefix), also save the .newsrc file(s)."
6163   (interactive "P")
6164   (gnus-summary-update-info t)
6165   (if force
6166       (gnus-save-newsrc-file)
6167     (gnus-dribble-save)))
6168
6169 (defun gnus-summary-exit (&optional temporary)
6170   "Exit reading current newsgroup, and then return to group selection mode.
6171 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6172   (interactive)
6173   (gnus-set-global-variables)
6174   (gnus-kill-save-kill-buffer)
6175   (gnus-async-halt-prefetch)
6176   (let* ((group gnus-newsgroup-name)
6177          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6178          (mode major-mode)
6179          (group-point nil)
6180          (buf (current-buffer)))
6181     (unless quit-config
6182       ;; Do adaptive scoring, and possibly save score files.
6183       (when gnus-newsgroup-adaptive
6184         (gnus-score-adaptive))
6185       (when gnus-use-scoring
6186         (gnus-score-save)))
6187     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6188     ;; If we have several article buffers, we kill them at exit.
6189     (unless gnus-single-article-buffer
6190       (gnus-kill-buffer gnus-original-article-buffer)
6191       (setq gnus-article-current nil))
6192     (when gnus-use-cache
6193       (gnus-cache-possibly-remove-articles)
6194       (gnus-cache-save-buffers))
6195     (gnus-async-prefetch-remove-group group)
6196     (when gnus-suppress-duplicates
6197       (gnus-dup-enter-articles))
6198     (when gnus-use-trees
6199       (gnus-tree-close group))
6200     (when gnus-use-cache
6201       (gnus-cache-write-active))
6202     ;; Remove entries for this group.
6203     (nnmail-purge-split-history (gnus-group-real-name group))
6204     ;; Make all changes in this group permanent.
6205     (unless quit-config
6206       (gnus-run-hooks 'gnus-exit-group-hook)
6207       (gnus-summary-update-info))
6208     (gnus-close-group group)
6209     ;; Make sure where we were, and go to next newsgroup.
6210     (set-buffer gnus-group-buffer)
6211     (unless quit-config
6212       (gnus-group-jump-to-group group))
6213     (gnus-run-hooks 'gnus-summary-exit-hook)
6214     (unless (or quit-config
6215                 ;; If this group has disappeared from the summary
6216                 ;; buffer, don't skip forwards.
6217                 (not (string= group (gnus-group-group-name))))
6218       (gnus-group-next-unread-group 1))
6219     (setq group-point (point))
6220     (if temporary
6221         nil                             ;Nothing to do.
6222       ;; If we have several article buffers, we kill them at exit.
6223       (unless gnus-single-article-buffer
6224         (gnus-kill-buffer gnus-article-buffer)
6225         (gnus-kill-buffer gnus-original-article-buffer)
6226         (setq gnus-article-current nil))
6227       (set-buffer buf)
6228       (if (not gnus-kill-summary-on-exit)
6229           (progn
6230             (gnus-deaden-summary)
6231             (setq mode nil))
6232         ;; We set all buffer-local variables to nil.  It is unclear why
6233         ;; this is needed, but if we don't, buffer-local variables are
6234         ;; not garbage-collected, it seems.  This would the lead to en
6235         ;; ever-growing Emacs.
6236         (gnus-summary-clear-local-variables)
6237         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6238           (gnus-summary-clear-local-variables))
6239         (when (get-buffer gnus-article-buffer)
6240           (bury-buffer gnus-article-buffer))
6241         ;; We clear the global counterparts of the buffer-local
6242         ;; variables as well, just to be on the safe side.
6243         (set-buffer gnus-group-buffer)
6244         (gnus-summary-clear-local-variables)
6245         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6246           (gnus-summary-clear-local-variables)))
6247       (setq gnus-current-select-method gnus-select-method)
6248       (pop-to-buffer gnus-group-buffer)
6249       (if (not quit-config)
6250           (progn
6251             (goto-char group-point)
6252             (gnus-configure-windows 'group 'force)
6253             (unless (pos-visible-in-window-p)
6254               (forward-line (/ (static-if (featurep 'xemacs)
6255                                    (window-displayed-height)
6256                                  (1- (window-height)))
6257                                -2))
6258               (set-window-start (selected-window) (point))
6259               (goto-char group-point)))
6260         (gnus-handle-ephemeral-exit quit-config))
6261       ;; Return to group mode buffer.
6262       (when (eq mode 'gnus-summary-mode)
6263         (gnus-kill-buffer buf))
6264       ;; Clear the current group name.
6265       (unless quit-config
6266         (setq gnus-newsgroup-name nil)))))
6267
6268 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6269 (defun gnus-summary-exit-no-update (&optional no-questions)
6270   "Quit reading current newsgroup without updating read article info."
6271   (interactive)
6272   (let* ((group gnus-newsgroup-name)
6273          (quit-config (gnus-group-quit-config group)))
6274     (when (or no-questions
6275               gnus-expert-user
6276               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6277       (gnus-async-halt-prefetch)
6278       (mapcar 'funcall
6279               (delq 'gnus-summary-expire-articles
6280                     (copy-sequence gnus-summary-prepare-exit-hook)))
6281       ;; If we have several article buffers, we kill them at exit.
6282       (unless gnus-single-article-buffer
6283         (gnus-kill-buffer gnus-article-buffer)
6284         (gnus-kill-buffer gnus-original-article-buffer)
6285         (setq gnus-article-current nil))
6286       (if (not gnus-kill-summary-on-exit)
6287           (gnus-deaden-summary)
6288         (gnus-close-group group)
6289         (gnus-summary-clear-local-variables)
6290         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6291           (gnus-summary-clear-local-variables))
6292         (set-buffer gnus-group-buffer)
6293         (gnus-summary-clear-local-variables)
6294         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6295           (gnus-summary-clear-local-variables))
6296         (when (get-buffer gnus-summary-buffer)
6297           (kill-buffer gnus-summary-buffer)))
6298       (unless gnus-single-article-buffer
6299         (setq gnus-article-current nil))
6300       (when gnus-use-trees
6301         (gnus-tree-close group))
6302       (gnus-async-prefetch-remove-group group)
6303       (when (get-buffer gnus-article-buffer)
6304         (bury-buffer gnus-article-buffer))
6305       ;; Return to the group buffer.
6306       (gnus-configure-windows 'group 'force)
6307       ;; Clear the current group name.
6308       (setq gnus-newsgroup-name nil)
6309       (when (equal (gnus-group-group-name) group)
6310         (gnus-group-next-unread-group 1))
6311       (when quit-config
6312         (gnus-handle-ephemeral-exit quit-config)))))
6313
6314 (defun gnus-handle-ephemeral-exit (quit-config)
6315   "Handle movement when leaving an ephemeral group.
6316 The state which existed when entering the ephemeral is reset."
6317   (if (not (buffer-name (car quit-config)))
6318       (gnus-configure-windows 'group 'force)
6319     (set-buffer (car quit-config))
6320     (cond ((eq major-mode 'gnus-summary-mode)
6321            (gnus-set-global-variables))
6322           ((eq major-mode 'gnus-article-mode)
6323            (save-excursion
6324              ;; The `gnus-summary-buffer' variable may point
6325              ;; to the old summary buffer when using a single
6326              ;; article buffer.
6327              (unless (gnus-buffer-live-p gnus-summary-buffer)
6328                (set-buffer gnus-group-buffer))
6329              (set-buffer gnus-summary-buffer)
6330              (gnus-set-global-variables))))
6331     (if (or (eq (cdr quit-config) 'article)
6332             (eq (cdr quit-config) 'pick))
6333         (progn
6334           ;; The current article may be from the ephemeral group
6335           ;; thus it is best that we reload this article
6336           (gnus-summary-show-article)
6337           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6338               (gnus-configure-windows 'pick 'force)
6339             (gnus-configure-windows (cdr quit-config) 'force)))
6340       (gnus-configure-windows (cdr quit-config) 'force))
6341     (when (eq major-mode 'gnus-summary-mode)
6342       (gnus-summary-next-subject 1 nil t)
6343       (gnus-summary-recenter)
6344       (gnus-summary-position-point))))
6345
6346 (defun gnus-summary-preview-mime-message ()
6347   "MIME decode and play this message."
6348   (interactive)
6349   (let ((gnus-break-pages nil)
6350         (gnus-show-mime t))
6351     (gnus-summary-select-article gnus-show-all-headers t))
6352   (let ((w (get-buffer-window gnus-article-buffer)))
6353     (when w
6354       (select-window (get-buffer-window gnus-article-buffer)))))
6355
6356 ;;; Dead summaries.
6357
6358 (defvar gnus-dead-summary-mode-map nil)
6359
6360 (unless gnus-dead-summary-mode-map
6361   (setq gnus-dead-summary-mode-map (make-keymap))
6362   (suppress-keymap gnus-dead-summary-mode-map)
6363   (substitute-key-definition
6364    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6365   (dolist (key '("\C-d" "\r" "\177" [delete]))
6366     (define-key gnus-dead-summary-mode-map
6367       key 'gnus-summary-wake-up-the-dead))
6368   (dolist (key '("q" "Q"))
6369     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6370
6371 (defvar gnus-dead-summary-mode nil
6372   "Minor mode for Gnus summary buffers.")
6373
6374 (defun gnus-dead-summary-mode (&optional arg)
6375   "Minor mode for Gnus summary buffers."
6376   (interactive "P")
6377   (when (eq major-mode 'gnus-summary-mode)
6378     (make-local-variable 'gnus-dead-summary-mode)
6379     (setq gnus-dead-summary-mode
6380           (if (null arg) (not gnus-dead-summary-mode)
6381             (> (prefix-numeric-value arg) 0)))
6382     (when gnus-dead-summary-mode
6383       (gnus-add-minor-mode
6384        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6385
6386 (defun gnus-deaden-summary ()
6387   "Make the current summary buffer into a dead summary buffer."
6388   ;; Kill any previous dead summary buffer.
6389   (when (and gnus-dead-summary
6390              (buffer-name gnus-dead-summary))
6391     (save-excursion
6392       (set-buffer gnus-dead-summary)
6393       (when gnus-dead-summary-mode
6394         (kill-buffer (current-buffer)))))
6395   ;; Make this the current dead summary.
6396   (setq gnus-dead-summary (current-buffer))
6397   (gnus-dead-summary-mode 1)
6398   (let ((name (buffer-name)))
6399     (when (string-match "Summary" name)
6400       (rename-buffer
6401        (concat (substring name 0 (match-beginning 0)) "Dead "
6402                (substring name (match-beginning 0)))
6403        t)
6404       (bury-buffer))))
6405
6406 (defun gnus-kill-or-deaden-summary (buffer)
6407   "Kill or deaden the summary BUFFER."
6408   (save-excursion
6409     (when (and (buffer-name buffer)
6410                (not gnus-single-article-buffer))
6411       (save-excursion
6412         (set-buffer buffer)
6413         (gnus-kill-buffer gnus-article-buffer)
6414         (gnus-kill-buffer gnus-original-article-buffer)))
6415     (cond
6416      ;; Kill the buffer.
6417      (gnus-kill-summary-on-exit
6418       (when (and gnus-use-trees
6419                  (gnus-buffer-exists-p buffer))
6420         (save-excursion
6421           (set-buffer buffer)
6422           (gnus-tree-close gnus-newsgroup-name)))
6423       (gnus-kill-buffer buffer))
6424      ;; Deaden the buffer.
6425      ((gnus-buffer-exists-p buffer)
6426       (save-excursion
6427         (set-buffer buffer)
6428         (gnus-deaden-summary))))))
6429
6430 (defun gnus-summary-wake-up-the-dead (&rest args)
6431   "Wake up the dead summary buffer."
6432   (interactive)
6433   (gnus-dead-summary-mode -1)
6434   (let ((name (buffer-name)))
6435     (when (string-match "Dead " name)
6436       (rename-buffer
6437        (concat (substring name 0 (match-beginning 0))
6438                (substring name (match-end 0)))
6439        t)))
6440   (gnus-message 3 "This dead summary is now alive again"))
6441
6442 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6443 (defun gnus-summary-fetch-faq (&optional faq-dir)
6444   "Fetch the FAQ for the current group.
6445 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6446 in."
6447   (interactive
6448    (list
6449     (when current-prefix-arg
6450       (completing-read
6451        "Faq dir: " (and (listp gnus-group-faq-directory)
6452                         (mapcar (lambda (file) (list file))
6453                                 gnus-group-faq-directory))))))
6454   (let (gnus-faq-buffer)
6455     (when (setq gnus-faq-buffer
6456                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6457       (gnus-configure-windows 'summary-faq))))
6458
6459 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6460 (defun gnus-summary-describe-group (&optional force)
6461   "Describe the current newsgroup."
6462   (interactive "P")
6463   (gnus-group-describe-group force gnus-newsgroup-name))
6464
6465 (defun gnus-summary-describe-briefly ()
6466   "Describe summary mode commands briefly."
6467   (interactive)
6468   (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")))
6469
6470 ;; Walking around group mode buffer from summary mode.
6471
6472 (defun gnus-summary-next-group (&optional no-article target-group backward)
6473   "Exit current newsgroup and then select next unread newsgroup.
6474 If prefix argument NO-ARTICLE is non-nil, no article is selected
6475 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6476 previous group instead."
6477   (interactive "P")
6478   ;; Stop pre-fetching.
6479   (gnus-async-halt-prefetch)
6480   (let ((current-group gnus-newsgroup-name)
6481         (current-buffer (current-buffer))
6482         entered)
6483     ;; First we semi-exit this group to update Xrefs and all variables.
6484     ;; We can't do a real exit, because the window conf must remain
6485     ;; the same in case the user is prompted for info, and we don't
6486     ;; want the window conf to change before that...
6487     (gnus-summary-exit t)
6488     (while (not entered)
6489       ;; Then we find what group we are supposed to enter.
6490       (set-buffer gnus-group-buffer)
6491       (gnus-group-jump-to-group current-group)
6492       (setq target-group
6493             (or target-group
6494                 (if (eq gnus-keep-same-level 'best)
6495                     (gnus-summary-best-group gnus-newsgroup-name)
6496                   (gnus-summary-search-group backward gnus-keep-same-level))))
6497       (if (not target-group)
6498           ;; There are no further groups, so we return to the group
6499           ;; buffer.
6500           (progn
6501             (gnus-message 5 "Returning to the group buffer")
6502             (setq entered t)
6503             (when (gnus-buffer-live-p current-buffer)
6504               (set-buffer current-buffer)
6505               (gnus-summary-exit))
6506             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6507         ;; We try to enter the target group.
6508         (gnus-group-jump-to-group target-group)
6509         (let ((unreads (gnus-group-group-unread)))
6510           (if (and (or (eq t unreads)
6511                        (and unreads (not (zerop unreads))))
6512                    (gnus-summary-read-group
6513                     target-group nil no-article
6514                     (and (buffer-name current-buffer) current-buffer)
6515                     nil backward))
6516               (setq entered t)
6517             (setq current-group target-group
6518                   target-group nil)))))))
6519
6520 (defun gnus-summary-prev-group (&optional no-article)
6521   "Exit current newsgroup and then select previous unread newsgroup.
6522 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6523   (interactive "P")
6524   (gnus-summary-next-group no-article nil t))
6525
6526 ;; Walking around summary lines.
6527
6528 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6529   "Go to the first unread subject.
6530 If UNREAD is non-nil, go to the first unread article.
6531 Returns the article selected or nil if there are no unread articles."
6532   (interactive "P")
6533   (prog1
6534       (cond
6535        ;; Empty summary.
6536        ((null gnus-newsgroup-data)
6537         (gnus-message 3 "No articles in the group")
6538         nil)
6539        ;; Pick the first article.
6540        ((not unread)
6541         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6542         (gnus-data-number (car gnus-newsgroup-data)))
6543        ;; No unread articles.
6544        ((null gnus-newsgroup-unreads)
6545         (gnus-message 3 "No more unread articles")
6546         nil)
6547        ;; Find the first unread article.
6548        (t
6549         (let ((data gnus-newsgroup-data))
6550           (while (and data
6551                       (and (not (and undownloaded
6552                                      (eq gnus-undownloaded-mark
6553                                          (gnus-data-mark (car data)))))
6554                            (if unseen
6555                                (or (not (memq
6556                                          (gnus-data-number (car data))
6557                                          gnus-newsgroup-unseen))
6558                                    (not (gnus-data-unread-p (car data))))
6559                              (not (gnus-data-unread-p (car data))))))
6560             (setq data (cdr data)))
6561           (when data
6562             (goto-char (gnus-data-pos (car data)))
6563             (gnus-data-number (car data))))))
6564     (gnus-summary-position-point)))
6565
6566 (defun gnus-summary-next-subject (n &optional unread dont-display)
6567   "Go to next N'th summary line.
6568 If N is negative, go to the previous N'th subject line.
6569 If UNREAD is non-nil, only unread articles are selected.
6570 The difference between N and the actual number of steps taken is
6571 returned."
6572   (interactive "p")
6573   (let ((backward (< n 0))
6574         (n (abs n)))
6575     (while (and (> n 0)
6576                 (if backward
6577                     (gnus-summary-find-prev unread)
6578                   (gnus-summary-find-next unread)))
6579       (unless (zerop (setq n (1- n)))
6580         (gnus-summary-show-thread)))
6581     (when (/= 0 n)
6582       (gnus-message 7 "No more%s articles"
6583                     (if unread " unread" "")))
6584     (unless dont-display
6585       (gnus-summary-recenter)
6586       (gnus-summary-position-point))
6587     n))
6588
6589 (defun gnus-summary-next-unread-subject (n)
6590   "Go to next N'th unread summary line."
6591   (interactive "p")
6592   (gnus-summary-next-subject n t))
6593
6594 (defun gnus-summary-prev-subject (n &optional unread)
6595   "Go to previous N'th summary line.
6596 If optional argument UNREAD is non-nil, only unread article is selected."
6597   (interactive "p")
6598   (gnus-summary-next-subject (- n) unread))
6599
6600 (defun gnus-summary-prev-unread-subject (n)
6601   "Go to previous N'th unread summary line."
6602   (interactive "p")
6603   (gnus-summary-next-subject (- n) t))
6604
6605 (defun gnus-summary-goto-subject (article &optional force silent)
6606   "Go the subject line of ARTICLE.
6607 If FORCE, also allow jumping to articles not currently shown."
6608   (interactive "nArticle number: ")
6609   (unless (numberp article)
6610     (error "Article %s is not a number" article))
6611   (let ((b (point))
6612         (data (gnus-data-find article)))
6613     ;; We read in the article if we have to.
6614     (and (not data)
6615          force
6616          (gnus-summary-insert-subject
6617           article
6618           (if (or (numberp force) (vectorp force)) force)
6619           t)
6620          (setq data (gnus-data-find article)))
6621     (goto-char b)
6622     (if (not data)
6623         (progn
6624           (unless silent
6625             (gnus-message 3 "Can't find article %d" article))
6626           nil)
6627       (let ((pt (gnus-data-pos data)))
6628         (goto-char pt)
6629         (gnus-summary-set-article-display-arrow pt))
6630       (gnus-summary-position-point)
6631       article)))
6632
6633 ;; Walking around summary lines with displaying articles.
6634
6635 (defun gnus-summary-expand-window (&optional arg)
6636   "Make the summary buffer take up the entire Emacs frame.
6637 Given a prefix, will force an `article' buffer configuration."
6638   (interactive "P")
6639   (if arg
6640       (gnus-configure-windows 'article 'force)
6641     (gnus-configure-windows 'summary 'force)))
6642
6643 (defun gnus-summary-display-article (article &optional all-header)
6644   "Display ARTICLE in article buffer."
6645   (when (gnus-buffer-live-p gnus-article-buffer)
6646     (with-current-buffer gnus-article-buffer
6647       (set-buffer-multibyte t)))
6648   (gnus-set-global-variables)
6649   (when (gnus-buffer-live-p gnus-article-buffer)
6650     (with-current-buffer gnus-article-buffer
6651       (setq gnus-article-charset gnus-newsgroup-charset)
6652       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6653       (set-buffer-multibyte t)))
6654   (if (null article)
6655       nil
6656     (prog1
6657         (if gnus-summary-display-article-function
6658             (funcall gnus-summary-display-article-function article all-header)
6659           (gnus-article-prepare article all-header))
6660       (with-current-buffer gnus-article-buffer
6661         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6662              nil))
6663       (gnus-run-hooks 'gnus-select-article-hook)
6664       (when (and gnus-current-article
6665                  (not (zerop gnus-current-article)))
6666         (gnus-summary-goto-subject gnus-current-article))
6667       (gnus-summary-recenter)
6668       (when (and gnus-use-trees gnus-show-threads)
6669         (gnus-possibly-generate-tree article)
6670         (gnus-highlight-selected-tree article))
6671       ;; Successfully display article.
6672       (gnus-article-set-window-start
6673        (cdr (assq article gnus-newsgroup-bookmarks))))))
6674
6675 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6676   "Select the current article.
6677 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6678 non-nil, the article will be re-fetched even if it already present in
6679 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6680 be displayed."
6681   ;; Make sure we are in the summary buffer to work around bbdb bug.
6682   (unless (eq major-mode 'gnus-summary-mode)
6683     (set-buffer gnus-summary-buffer))
6684   (let ((article (or article (gnus-summary-article-number)))
6685         (all-headers (not (not all-headers))) ;Must be T or NIL.
6686         gnus-summary-display-article-function)
6687     (and (not pseudo)
6688          (gnus-summary-article-pseudo-p article)
6689          (error "This is a pseudo-article"))
6690     (save-excursion
6691       (set-buffer gnus-summary-buffer)
6692       (if (or (and gnus-single-article-buffer
6693                    (or (null gnus-current-article)
6694                        (null gnus-article-current)
6695                        (null (get-buffer gnus-article-buffer))
6696                        (not (eq article (cdr gnus-article-current)))
6697                        (not (equal (car gnus-article-current)
6698                                    gnus-newsgroup-name))))
6699               (and (not gnus-single-article-buffer)
6700                    (or (null gnus-current-article)
6701                        (not (eq gnus-current-article article))))
6702               force)
6703           ;; The requested article is different from the current article.
6704           (progn
6705             (gnus-summary-display-article article all-headers)
6706             (gnus-article-set-window-start
6707              (cdr (assq article gnus-newsgroup-bookmarks)))
6708             article)
6709         'old))))
6710
6711 (defun gnus-summary-force-verify-and-decrypt ()
6712   (interactive)
6713   (let ((mm-verify-option 'known)
6714         (mm-decrypt-option 'known)
6715         (gnus-buttonized-mime-types (append (list "multipart/signed"
6716                                                   "multipart/encrypted")
6717                                             gnus-buttonized-mime-types)))
6718     (gnus-summary-select-article nil 'force)))
6719
6720 (defun gnus-summary-set-current-mark (&optional current-mark)
6721   "Obsolete function."
6722   nil)
6723
6724 (defun gnus-summary-next-article (&optional unread subject backward push)
6725   "Select the next article.
6726 If UNREAD, only unread articles are selected.
6727 If SUBJECT, only articles with SUBJECT are selected.
6728 If BACKWARD, the previous article is selected instead of the next."
6729   (interactive "P")
6730   (cond
6731    ;; Is there such an article?
6732    ((and (gnus-summary-search-forward unread subject backward)
6733          (or (gnus-summary-display-article (gnus-summary-article-number))
6734              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6735     (gnus-summary-position-point))
6736    ;; If not, we try the first unread, if that is wanted.
6737    ((and subject
6738          gnus-auto-select-same
6739          (gnus-summary-first-unread-article))
6740     (gnus-summary-position-point)
6741     (gnus-message 6 "Wrapped"))
6742    ;; Try to get next/previous article not displayed in this group.
6743    ((and gnus-auto-extend-newsgroup
6744          (not unread) (not subject))
6745     (gnus-summary-goto-article
6746      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6747      nil (count-lines (point-min) (point))))
6748    ;; Go to next/previous group.
6749    (t
6750     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6751       (gnus-summary-jump-to-group gnus-newsgroup-name))
6752     (let ((cmd last-command-char)
6753           (point
6754            (save-excursion
6755              (set-buffer gnus-group-buffer)
6756              (point)))
6757           (group
6758            (if (eq gnus-keep-same-level 'best)
6759                (gnus-summary-best-group gnus-newsgroup-name)
6760              (gnus-summary-search-group backward gnus-keep-same-level))))
6761       ;; For some reason, the group window gets selected.  We change
6762       ;; it back.
6763       (select-window (get-buffer-window (current-buffer)))
6764       ;; Select next unread newsgroup automagically.
6765       (cond
6766        ((or (not gnus-auto-select-next)
6767             (not cmd))
6768         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6769        ((or (eq gnus-auto-select-next 'quietly)
6770             (and (eq gnus-auto-select-next 'slightly-quietly)
6771                  push)
6772             (and (eq gnus-auto-select-next 'almost-quietly)
6773                  (gnus-summary-last-article-p)))
6774         ;; Select quietly.
6775         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6776             (gnus-summary-exit)
6777           (gnus-message 7 "No more%s articles (%s)..."
6778                         (if unread " unread" "")
6779                         (if group (concat "selecting " group)
6780                           "exiting"))
6781           (gnus-summary-next-group nil group backward)))
6782        (t
6783         (when (gnus-key-press-event-p last-input-event)
6784           (gnus-summary-walk-group-buffer
6785            gnus-newsgroup-name cmd unread backward point))))))))
6786
6787 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6788   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6789                       (?\C-p (gnus-group-prev-unread-group 1))))
6790         (cursor-in-echo-area t)
6791         keve key group ended)
6792     (save-excursion
6793       (set-buffer gnus-group-buffer)
6794       (goto-char start)
6795       (setq group
6796             (if (eq gnus-keep-same-level 'best)
6797                 (gnus-summary-best-group gnus-newsgroup-name)
6798               (gnus-summary-search-group backward gnus-keep-same-level))))
6799     (while (not ended)
6800       (gnus-message
6801        5 "No more%s articles%s" (if unread " unread" "")
6802        (if (and group
6803                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6804            (format " (Type %s for %s [%s])"
6805                    (single-key-description cmd) group
6806                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6807          (format " (Type %s to exit %s)"
6808                  (single-key-description cmd)
6809                  gnus-newsgroup-name)))
6810       ;; Confirm auto selection.
6811       (setq key (car (setq keve (gnus-read-event-char))))
6812       (setq ended t)
6813       (cond
6814        ((assq key keystrokes)
6815         (let ((obuf (current-buffer)))
6816           (switch-to-buffer gnus-group-buffer)
6817           (when group
6818             (gnus-group-jump-to-group group))
6819           (eval (cadr (assq key keystrokes)))
6820           (setq group (gnus-group-group-name))
6821           (switch-to-buffer obuf))
6822         (setq ended nil))
6823        ((equal key cmd)
6824         (if (or (not group)
6825                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6826             (gnus-summary-exit)
6827           (gnus-summary-next-group nil group backward)))
6828        (t
6829         (push (cdr keve) unread-command-events))))))
6830
6831 (defun gnus-summary-next-unread-article ()
6832   "Select unread article after current one."
6833   (interactive)
6834   (gnus-summary-next-article
6835    (or (not (eq gnus-summary-goto-unread 'never))
6836        (gnus-summary-last-article-p (gnus-summary-article-number)))
6837    (and gnus-auto-select-same
6838         (gnus-summary-article-subject))))
6839
6840 (defun gnus-summary-prev-article (&optional unread subject)
6841   "Select the article after the current one.
6842 If UNREAD is non-nil, only unread articles are selected."
6843   (interactive "P")
6844   (gnus-summary-next-article unread subject t))
6845
6846 (defun gnus-summary-prev-unread-article ()
6847   "Select unread article before current one."
6848   (interactive)
6849   (gnus-summary-prev-article
6850    (or (not (eq gnus-summary-goto-unread 'never))
6851        (gnus-summary-first-article-p (gnus-summary-article-number)))
6852    (and gnus-auto-select-same
6853         (gnus-summary-article-subject))))
6854
6855 (defun gnus-summary-next-page (&optional lines circular)
6856   "Show next page of the selected article.
6857 If at the end of the current article, select the next article.
6858 LINES says how many lines should be scrolled up.
6859
6860 If CIRCULAR is non-nil, go to the start of the article instead of
6861 selecting the next article when reaching the end of the current
6862 article."
6863   (interactive "P")
6864   (setq gnus-summary-buffer (current-buffer))
6865   (gnus-set-global-variables)
6866   (let ((article (gnus-summary-article-number))
6867         (article-window (get-buffer-window gnus-article-buffer t))
6868         endp)
6869     ;; If the buffer is empty, we have no article.
6870     (unless article
6871       (error "No article to select"))
6872     (gnus-configure-windows 'article)
6873     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6874         (if (and (eq gnus-summary-goto-unread 'never)
6875                  (not (gnus-summary-last-article-p article)))
6876             (gnus-summary-next-article)
6877           (gnus-summary-next-unread-article))
6878       (if (or (null gnus-current-article)
6879               (null gnus-article-current)
6880               (/= article (cdr gnus-article-current))
6881               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6882           ;; Selected subject is different from current article's.
6883           (gnus-summary-display-article article)
6884         (when article-window
6885           (gnus-eval-in-buffer-window gnus-article-buffer
6886             (setq endp (gnus-article-next-page lines)))
6887           (when endp
6888             (cond (circular
6889                    (gnus-summary-beginning-of-article))
6890                   (lines
6891                    (gnus-message 3 "End of message"))
6892                   ((null lines)
6893                    (if (and (eq gnus-summary-goto-unread 'never)
6894                             (not (gnus-summary-last-article-p article)))
6895                        (gnus-summary-next-article)
6896                      (gnus-summary-next-unread-article))))))))
6897     (gnus-summary-recenter)
6898     (gnus-summary-position-point)))
6899
6900 (defun gnus-summary-prev-page (&optional lines move)
6901   "Show previous page of selected article.
6902 Argument LINES specifies lines to be scrolled down.
6903 If MOVE, move to the previous unread article if point is at
6904 the beginning of the buffer."
6905   (interactive "P")
6906   (let ((article (gnus-summary-article-number))
6907         (article-window (get-buffer-window gnus-article-buffer t))
6908         endp)
6909     (gnus-configure-windows 'article)
6910     (if (or (null gnus-current-article)
6911             (null gnus-article-current)
6912             (/= article (cdr gnus-article-current))
6913             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6914         ;; Selected subject is different from current article's.
6915         (gnus-summary-display-article article)
6916       (gnus-summary-recenter)
6917       (when article-window
6918         (gnus-eval-in-buffer-window gnus-article-buffer
6919           (setq endp (gnus-article-prev-page lines)))
6920         (when (and move endp)
6921           (cond (lines
6922                  (gnus-message 3 "Beginning of message"))
6923                 ((null lines)
6924                  (if (and (eq gnus-summary-goto-unread 'never)
6925                           (not (gnus-summary-first-article-p article)))
6926                      (gnus-summary-prev-article)
6927                    (gnus-summary-prev-unread-article))))))))
6928   (gnus-summary-position-point))
6929
6930 (defun gnus-summary-prev-page-or-article (&optional lines)
6931   "Show previous page of selected article.
6932 Argument LINES specifies lines to be scrolled down.
6933 If at the beginning of the article, go to the next article."
6934   (interactive "P")
6935   (gnus-summary-prev-page lines t))
6936
6937 (defun gnus-summary-scroll-up (lines)
6938   "Scroll up (or down) one line current article.
6939 Argument LINES specifies lines to be scrolled up (or down if negative)."
6940   (interactive "p")
6941   (gnus-configure-windows 'article)
6942   (gnus-summary-show-thread)
6943   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6944     (gnus-eval-in-buffer-window gnus-article-buffer
6945       (cond ((> lines 0)
6946              (when (gnus-article-next-page lines)
6947                (gnus-message 3 "End of message")))
6948             ((< lines 0)
6949              (gnus-article-prev-page (- lines))))))
6950   (gnus-summary-recenter)
6951   (gnus-summary-position-point))
6952
6953 (defun gnus-summary-scroll-down (lines)
6954   "Scroll down (or up) one line current article.
6955 Argument LINES specifies lines to be scrolled down (or up if negative)."
6956   (interactive "p")
6957   (gnus-summary-scroll-up (- lines)))
6958
6959 (defun gnus-summary-next-same-subject ()
6960   "Select next article which has the same subject as current one."
6961   (interactive)
6962   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6963
6964 (defun gnus-summary-prev-same-subject ()
6965   "Select previous article which has the same subject as current one."
6966   (interactive)
6967   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6968
6969 (defun gnus-summary-next-unread-same-subject ()
6970   "Select next unread article which has the same subject as current one."
6971   (interactive)
6972   (gnus-summary-next-article t (gnus-summary-article-subject)))
6973
6974 (defun gnus-summary-prev-unread-same-subject ()
6975   "Select previous unread article which has the same subject as current one."
6976   (interactive)
6977   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6978
6979 (defun gnus-summary-first-unread-article ()
6980   "Select the first unread article.
6981 Return nil if there are no unread articles."
6982   (interactive)
6983   (prog1
6984       (when (gnus-summary-first-subject t)
6985         (gnus-summary-show-thread)
6986         (gnus-summary-first-subject t)
6987         (gnus-summary-display-article (gnus-summary-article-number)))
6988     (gnus-summary-position-point)))
6989
6990 (defun gnus-summary-first-unread-subject ()
6991   "Place the point on the subject line of the first unread article.
6992 Return nil if there are no unread articles."
6993   (interactive)
6994   (prog1
6995       (when (gnus-summary-first-subject t)
6996         (gnus-summary-show-thread)
6997         (gnus-summary-first-subject t))
6998     (gnus-summary-position-point)))
6999
7000 (defun gnus-summary-first-unseen-subject ()
7001   "Place the point on the subject line of the first unseen article.
7002 Return nil if there are no unseen articles."
7003   (interactive)
7004   (prog1
7005       (when (gnus-summary-first-subject t t t)
7006         (gnus-summary-show-thread)
7007         (gnus-summary-first-subject t t t))
7008     (gnus-summary-position-point)))
7009
7010 (defun gnus-summary-first-unseen-or-unread-subject ()
7011   "Place the point on the subject line of the first unseen article.
7012 Return nil if there are no unseen articles."
7013   (interactive)
7014   (prog1
7015       (unless (when (gnus-summary-first-subject t t t)
7016                 (gnus-summary-show-thread)
7017                 (gnus-summary-first-subject t t t))
7018         (when (gnus-summary-first-subject t)
7019           (gnus-summary-show-thread)
7020           (gnus-summary-first-subject t)))
7021     (gnus-summary-position-point)))
7022
7023 (defun gnus-summary-first-article ()
7024   "Select the first article.
7025 Return nil if there are no articles."
7026   (interactive)
7027   (prog1
7028       (when (gnus-summary-first-subject)
7029         (gnus-summary-show-thread)
7030         (gnus-summary-first-subject)
7031         (gnus-summary-display-article (gnus-summary-article-number)))
7032     (gnus-summary-position-point)))
7033
7034 (defun gnus-summary-best-unread-article (&optional arg)
7035   "Select the unread article with the highest score.
7036 If given a prefix argument, select the next unread article that has a
7037 score higher than the default score."
7038   (interactive "P")
7039   (let ((article (if arg
7040                      (gnus-summary-better-unread-subject)
7041                    (gnus-summary-best-unread-subject))))
7042     (if article
7043         (gnus-summary-goto-article article)
7044       (error "No unread articles"))))
7045
7046 (defun gnus-summary-best-unread-subject ()
7047   "Select the unread subject with the highest score."
7048   (interactive)
7049   (let ((best -1000000)
7050         (data gnus-newsgroup-data)
7051         article score)
7052     (while data
7053       (and (gnus-data-unread-p (car data))
7054            (> (setq score
7055                     (gnus-summary-article-score (gnus-data-number (car data))))
7056               best)
7057            (setq best score
7058                  article (gnus-data-number (car data))))
7059       (setq data (cdr data)))
7060     (when article
7061       (gnus-summary-goto-subject article))
7062     (gnus-summary-position-point)
7063     article))
7064
7065 (defun gnus-summary-better-unread-subject ()
7066   "Select the first unread subject that has a score over the default score."
7067   (interactive)
7068   (let ((data gnus-newsgroup-data)
7069         article score)
7070     (while (and (setq article (gnus-data-number (car data)))
7071                 (or (gnus-data-read-p (car data))
7072                     (not (> (gnus-summary-article-score article)
7073                             gnus-summary-default-score))))
7074       (setq data (cdr data)))
7075     (when article
7076       (gnus-summary-goto-subject article))
7077     (gnus-summary-position-point)
7078     article))
7079
7080 (defun gnus-summary-last-subject ()
7081   "Go to the last displayed subject line in the group."
7082   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7083     (when article
7084       (gnus-summary-goto-subject article))))
7085
7086 (defun gnus-summary-goto-article (article &optional all-headers force)
7087   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7088 If ALL-HEADERS is non-nil, no header lines are hidden.
7089 If FORCE, go to the article even if it isn't displayed.  If FORCE
7090 is a number, it is the line the article is to be displayed on."
7091   (interactive
7092    (list
7093     (completing-read
7094      "Article number or Message-ID: "
7095      (mapcar (lambda (number) (list (int-to-string number)))
7096              gnus-newsgroup-limit))
7097     current-prefix-arg
7098     t))
7099   (prog1
7100       (if (and (stringp article)
7101                (string-match "@" article))
7102           (gnus-summary-refer-article article)
7103         (when (stringp article)
7104           (setq article (string-to-number article)))
7105         (if (gnus-summary-goto-subject article force)
7106             (gnus-summary-display-article article all-headers)
7107           (gnus-message 4 "Couldn't go to article %s" article) nil))
7108     (gnus-summary-position-point)))
7109
7110 (defun gnus-summary-goto-last-article ()
7111   "Go to the previously read article."
7112   (interactive)
7113   (prog1
7114       (when gnus-last-article
7115         (gnus-summary-goto-article gnus-last-article nil t))
7116     (gnus-summary-position-point)))
7117
7118 (defun gnus-summary-pop-article (number)
7119   "Pop one article off the history and go to the previous.
7120 NUMBER articles will be popped off."
7121   (interactive "p")
7122   (let (to)
7123     (setq gnus-newsgroup-history
7124           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7125     (if to
7126         (gnus-summary-goto-article (car to) nil t)
7127       (error "Article history empty")))
7128   (gnus-summary-position-point))
7129
7130 ;; Summary commands and functions for limiting the summary buffer.
7131
7132 (defun gnus-summary-limit-to-articles (n)
7133   "Limit the summary buffer to the next N articles.
7134 If not given a prefix, use the process marked articles instead."
7135   (interactive "P")
7136   (prog1
7137       (let ((articles (gnus-summary-work-articles n)))
7138         (setq gnus-newsgroup-processable nil)
7139         (gnus-summary-limit articles))
7140     (gnus-summary-position-point)))
7141
7142 (defun gnus-summary-pop-limit (&optional total)
7143   "Restore the previous limit.
7144 If given a prefix, remove all limits."
7145   (interactive "P")
7146   (when total
7147     (setq gnus-newsgroup-limits
7148           (list (mapcar (lambda (h) (mail-header-number h))
7149                         gnus-newsgroup-headers))))
7150   (unless gnus-newsgroup-limits
7151     (error "No limit to pop"))
7152   (prog1
7153       (gnus-summary-limit nil 'pop)
7154     (gnus-summary-position-point)))
7155
7156 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7157   "Limit the summary buffer to articles that have subjects that match a regexp.
7158 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7159   (interactive
7160    (list (read-string (if current-prefix-arg
7161                           "Exclude subject (regexp): "
7162                         "Limit to subject (regexp): "))
7163          nil current-prefix-arg))
7164   (unless header
7165     (setq header "subject"))
7166   (when (not (equal "" subject))
7167     (prog1
7168         (let ((articles (gnus-summary-find-matching
7169                          (or header "subject") subject 'all nil nil
7170                          not-matching)))
7171           (unless articles
7172             (error "Found no matches for \"%s\"" subject))
7173           (gnus-summary-limit articles))
7174       (gnus-summary-position-point))))
7175
7176 (defun gnus-summary-limit-to-author (from &optional not-matching)
7177   "Limit the summary buffer to articles that have authors that match a regexp.
7178 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7179   (interactive
7180    (list (read-string (if current-prefix-arg
7181                           "Exclude author (regexp): "
7182                         "Limit to author (regexp): "))
7183          current-prefix-arg))
7184   (gnus-summary-limit-to-subject from "from" not-matching))
7185
7186 (defun gnus-summary-limit-to-age (age &optional younger-p)
7187   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7188 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7189 articles that are younger than AGE days."
7190   (interactive
7191    (let ((younger current-prefix-arg)
7192          (days-got nil)
7193          days)
7194      (while (not days-got)
7195        (setq days (if younger
7196                       (read-string "Limit to articles within (in days): ")
7197                     (read-string "Limit to articles older than (in days): ")))
7198        (when (> (length days) 0)
7199          (setq days (read days)))
7200        (if (numberp days)
7201            (progn
7202              (setq days-got t)
7203              (if (< days 0)
7204                  (progn
7205                    (setq younger (not younger))
7206                    (setq days (* days -1)))))
7207          (message "Please enter a number.")
7208          (sleep-for 1)))
7209      (list days younger)))
7210   (prog1
7211       (let ((data gnus-newsgroup-data)
7212             (cutoff (days-to-time age))
7213             articles d date is-younger)
7214         (while (setq d (pop data))
7215           (when (and (vectorp (gnus-data-header d))
7216                      (setq date (mail-header-date (gnus-data-header d))))
7217             (setq is-younger (time-less-p
7218                               (time-since (condition-case ()
7219                                               (date-to-time date)
7220                                             (error '(0 0))))
7221                               cutoff))
7222             (when (if younger-p
7223                       is-younger
7224                     (not is-younger))
7225               (push (gnus-data-number d) articles))))
7226         (gnus-summary-limit (nreverse articles)))
7227     (gnus-summary-position-point)))
7228
7229 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7230   "Limit the summary buffer to articles that match an 'extra' header."
7231   (interactive
7232    (let ((header
7233           (intern
7234            (gnus-completing-read-with-default
7235             (symbol-name (car gnus-extra-headers))
7236             (if current-prefix-arg
7237                 "Exclude extra header:"
7238               "Limit extra header:")
7239             (mapcar (lambda (x)
7240                       (cons (symbol-name x) x))
7241                     gnus-extra-headers)
7242             nil
7243             t))))
7244      (list header
7245            (read-string (format "%s header %s (regexp): "
7246                                 (if current-prefix-arg "Exclude" "Limit to")
7247                                 header))
7248            current-prefix-arg)))
7249   (when (not (equal "" regexp))
7250     (prog1
7251         (let ((articles (gnus-summary-find-matching
7252                          (cons 'extra header) regexp 'all nil nil
7253                          not-matching)))
7254           (unless articles
7255             (error "Found no matches for \"%s\"" regexp))
7256           (gnus-summary-limit articles))
7257       (gnus-summary-position-point))))
7258
7259 (defun gnus-summary-limit-to-display-predicate ()
7260   "Limit the summary buffer to the predicated in the `display' group parameter."
7261   (interactive)
7262   (unless gnus-newsgroup-display
7263     (error "There is no `display' group parameter"))
7264   (let (articles)
7265     (dolist (number gnus-newsgroup-articles)
7266       (when (funcall gnus-newsgroup-display)
7267         (push number articles)))
7268     (gnus-summary-limit articles))
7269   (gnus-summary-position-point))
7270
7271 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7272 (make-obsolete
7273  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7274
7275 (defun gnus-summary-limit-to-unread (&optional all)
7276   "Limit the summary buffer to articles that are not marked as read.
7277 If ALL is non-nil, limit strictly to unread articles."
7278   (interactive "P")
7279   (if all
7280       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7281     (gnus-summary-limit-to-marks
7282      ;; Concat all the marks that say that an article is read and have
7283      ;; those removed.
7284      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7285            gnus-killed-mark gnus-kill-file-mark
7286            gnus-low-score-mark gnus-expirable-mark
7287            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7288            gnus-duplicate-mark gnus-souped-mark)
7289      'reverse)))
7290
7291 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7292 (make-obsolete 'gnus-summary-delete-marked-with
7293                'gnus-summary-limit-exclude-marks)
7294
7295 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7296   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7297 If REVERSE, limit the summary buffer to articles that are marked
7298 with MARKS.  MARKS can either be a string of marks or a list of marks.
7299 Returns how many articles were removed."
7300   (interactive "sMarks: ")
7301   (gnus-summary-limit-to-marks marks t))
7302
7303 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7304   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7305 If REVERSE (the prefix), limit the summary buffer to articles that are
7306 not marked with MARKS.  MARKS can either be a string of marks or a
7307 list of marks.
7308 Returns how many articles were removed."
7309   (interactive "sMarks: \nP")
7310   (prog1
7311       (let ((data gnus-newsgroup-data)
7312             (marks (if (listp marks) marks
7313                      (append marks nil))) ; Transform to list.
7314             articles)
7315         (while data
7316           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7317                   (memq (gnus-data-mark (car data)) marks))
7318             (push (gnus-data-number (car data)) articles))
7319           (setq data (cdr data)))
7320         (gnus-summary-limit articles))
7321     (gnus-summary-position-point)))
7322
7323 (defun gnus-summary-limit-to-score (score)
7324   "Limit to articles with score at or above SCORE."
7325   (interactive "NLimit to articles with score of at least: ")
7326   (let ((data gnus-newsgroup-data)
7327         articles)
7328     (while data
7329       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7330                 score)
7331         (push (gnus-data-number (car data)) articles))
7332       (setq data (cdr data)))
7333     (prog1
7334         (gnus-summary-limit articles)
7335       (gnus-summary-position-point))))
7336
7337 (defun gnus-summary-limit-include-thread (id)
7338   "Display all the hidden articles that is in the thread with ID in it.
7339 When called interactively, ID is the Message-ID of the current
7340 article."
7341   (interactive (list (mail-header-id (gnus-summary-article-header))))
7342   (let ((articles (gnus-articles-in-thread
7343                    (gnus-id-to-thread (gnus-root-id id)))))
7344     (prog1
7345         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7346       (gnus-summary-limit-include-matching-articles
7347        "subject"
7348        (regexp-quote (gnus-simplify-subject-re
7349                       (mail-header-subject (gnus-id-to-header id)))))
7350       (gnus-summary-position-point))))
7351
7352 (defun gnus-summary-limit-include-matching-articles (header regexp)
7353   "Display all the hidden articles that have HEADERs that match REGEXP."
7354   (interactive (list (read-string "Match on header: ")
7355                      (read-string "Regexp: ")))
7356   (let ((articles (gnus-find-matching-articles header regexp)))
7357     (prog1
7358         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7359       (gnus-summary-position-point))))
7360
7361 (defun gnus-summary-limit-include-dormant ()
7362   "Display all the hidden articles that are marked as dormant.
7363 Note that this command only works on a subset of the articles currently
7364 fetched for this group."
7365   (interactive)
7366   (unless gnus-newsgroup-dormant
7367     (error "There are no dormant articles in this group"))
7368   (prog1
7369       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7370     (gnus-summary-position-point)))
7371
7372 (defun gnus-summary-limit-exclude-dormant ()
7373   "Hide all dormant articles."
7374   (interactive)
7375   (prog1
7376       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7377     (gnus-summary-position-point)))
7378
7379 (defun gnus-summary-limit-exclude-childless-dormant ()
7380   "Hide all dormant articles that have no children."
7381   (interactive)
7382   (let ((data (gnus-data-list t))
7383         articles d children)
7384     ;; Find all articles that are either not dormant or have
7385     ;; children.
7386     (while (setq d (pop data))
7387       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7388                 (and (setq children
7389                            (gnus-article-children (gnus-data-number d)))
7390                      (let (found)
7391                        (while children
7392                          (when (memq (car children) articles)
7393                            (setq children nil
7394                                  found t))
7395                          (pop children))
7396                        found)))
7397         (push (gnus-data-number d) articles)))
7398     ;; Do the limiting.
7399     (prog1
7400         (gnus-summary-limit articles)
7401       (gnus-summary-position-point))))
7402
7403 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7404   "Mark all unread excluded articles as read.
7405 If ALL, mark even excluded ticked and dormants as read."
7406   (interactive "P")
7407   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7408   (let ((articles (gnus-sorted-ndifference
7409                    (sort
7410                     (mapcar (lambda (h) (mail-header-number h))
7411                             gnus-newsgroup-headers)
7412                     '<)
7413                    gnus-newsgroup-limit))
7414         article)
7415     (setq gnus-newsgroup-unreads
7416           (gnus-sorted-intersection gnus-newsgroup-unreads
7417                                     gnus-newsgroup-limit))
7418     (if all
7419         (setq gnus-newsgroup-dormant nil
7420               gnus-newsgroup-marked nil
7421               gnus-newsgroup-reads
7422               (nconc
7423                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7424                gnus-newsgroup-reads))
7425       (while (setq article (pop articles))
7426         (unless (or (memq article gnus-newsgroup-dormant)
7427                     (memq article gnus-newsgroup-marked))
7428           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7429
7430 (defun gnus-summary-limit (articles &optional pop)
7431   (if pop
7432       ;; We pop the previous limit off the stack and use that.
7433       (setq articles (car gnus-newsgroup-limits)
7434             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7435     ;; We use the new limit, so we push the old limit on the stack.
7436     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7437   ;; Set the limit.
7438   (setq gnus-newsgroup-limit articles)
7439   (let ((total (length gnus-newsgroup-data))
7440         (data (gnus-data-find-list (gnus-summary-article-number)))
7441         (gnus-summary-mark-below nil)   ; Inhibit this.
7442         found)
7443     ;; This will do all the work of generating the new summary buffer
7444     ;; according to the new limit.
7445     (gnus-summary-prepare)
7446     ;; Hide any threads, possibly.
7447     (gnus-summary-maybe-hide-threads)
7448     ;; Try to return to the article you were at, or one in the
7449     ;; neighborhood.
7450     (when data
7451       ;; We try to find some article after the current one.
7452       (while data
7453         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7454           (setq data nil
7455                 found t))
7456         (setq data (cdr data))))
7457     (unless found
7458       ;; If there is no data, that means that we were after the last
7459       ;; article.  The same goes when we can't find any articles
7460       ;; after the current one.
7461       (goto-char (point-max))
7462       (gnus-summary-find-prev))
7463     (gnus-set-mode-line 'summary)
7464     ;; We return how many articles were removed from the summary
7465     ;; buffer as a result of the new limit.
7466     (- total (length gnus-newsgroup-data))))
7467
7468 (defsubst gnus-invisible-cut-children (threads)
7469   (let ((num 0))
7470     (while threads
7471       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7472         (incf num))
7473       (pop threads))
7474     (< num 2)))
7475
7476 (defsubst gnus-cut-thread (thread)
7477   "Go forwards in the thread until we find an article that we want to display."
7478   (when (or (eq gnus-fetch-old-headers 'some)
7479             (eq gnus-fetch-old-headers 'invisible)
7480             (numberp gnus-fetch-old-headers)
7481             (eq gnus-build-sparse-threads 'some)
7482             (eq gnus-build-sparse-threads 'more))
7483     ;; Deal with old-fetched headers and sparse threads.
7484     (while (and
7485             thread
7486             (or
7487              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7488              (gnus-summary-article-ancient-p
7489               (mail-header-number (car thread))))
7490             (if (or (<= (length (cdr thread)) 1)
7491                     (eq gnus-fetch-old-headers 'invisible))
7492                 (setq gnus-newsgroup-limit
7493                       (delq (mail-header-number (car thread))
7494                             gnus-newsgroup-limit)
7495                       thread (cadr thread))
7496               (when (gnus-invisible-cut-children (cdr thread))
7497                 (let ((th (cdr thread)))
7498                   (while th
7499                     (if (memq (mail-header-number (caar th))
7500                               gnus-newsgroup-limit)
7501                         (setq thread (car th)
7502                               th nil)
7503                       (setq th (cdr th))))))))))
7504   thread)
7505
7506 (defun gnus-cut-threads (threads)
7507   "Cut off all uninteresting articles from the beginning of threads."
7508   (when (or (eq gnus-fetch-old-headers 'some)
7509             (eq gnus-fetch-old-headers 'invisible)
7510             (numberp gnus-fetch-old-headers)
7511             (eq gnus-build-sparse-threads 'some)
7512             (eq gnus-build-sparse-threads 'more))
7513     (let ((th threads))
7514       (while th
7515         (setcar th (gnus-cut-thread (car th)))
7516         (setq th (cdr th)))))
7517   ;; Remove nixed out threads.
7518   (delq nil threads))
7519
7520 (defun gnus-summary-initial-limit (&optional show-if-empty)
7521   "Figure out what the initial limit is supposed to be on group entry.
7522 This entails weeding out unwanted dormants, low-scored articles,
7523 fetch-old-headers verbiage, and so on."
7524   ;; Most groups have nothing to remove.
7525   (if (or gnus-inhibit-limiting
7526           (and (null gnus-newsgroup-dormant)
7527                (eq gnus-newsgroup-display 'gnus-not-ignore)
7528                (not (eq gnus-fetch-old-headers 'some))
7529                (not (numberp gnus-fetch-old-headers))
7530                (not (eq gnus-fetch-old-headers 'invisible))
7531                (null gnus-summary-expunge-below)
7532                (not (eq gnus-build-sparse-threads 'some))
7533                (not (eq gnus-build-sparse-threads 'more))
7534                (null gnus-thread-expunge-below)
7535                (not gnus-use-nocem)))
7536       ()                                ; Do nothing.
7537     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7538     (setq gnus-newsgroup-limit nil)
7539     (mapatoms
7540      (lambda (node)
7541        (unless (car (symbol-value node))
7542          ;; These threads have no parents -- they are roots.
7543          (let ((nodes (cdr (symbol-value node)))
7544                thread)
7545            (while nodes
7546              (if (and gnus-thread-expunge-below
7547                       (< (gnus-thread-total-score (car nodes))
7548                          gnus-thread-expunge-below))
7549                  (gnus-expunge-thread (pop nodes))
7550                (setq thread (pop nodes))
7551                (gnus-summary-limit-children thread))))))
7552      gnus-newsgroup-dependencies)
7553     ;; If this limitation resulted in an empty group, we might
7554     ;; pop the previous limit and use it instead.
7555     (when (and (not gnus-newsgroup-limit)
7556                show-if-empty)
7557       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7558     gnus-newsgroup-limit))
7559
7560 (defun gnus-summary-limit-children (thread)
7561   "Return 1 if this subthread is visible and 0 if it is not."
7562   ;; First we get the number of visible children to this thread.  This
7563   ;; is done by recursing down the thread using this function, so this
7564   ;; will really go down to a leaf article first, before slowly
7565   ;; working its way up towards the root.
7566   (when thread
7567     (let ((children
7568            (if (cdr thread)
7569                (apply '+ (mapcar 'gnus-summary-limit-children
7570                                  (cdr thread)))
7571              0))
7572           (number (mail-header-number (car thread)))
7573           score)
7574       (if (and
7575            (not (memq number gnus-newsgroup-marked))
7576            (or
7577             ;; If this article is dormant and has absolutely no visible
7578             ;; children, then this article isn't visible.
7579             (and (memq number gnus-newsgroup-dormant)
7580                  (zerop children))
7581             ;; If this is "fetch-old-headered" and there is no
7582             ;; visible children, then we don't want this article.
7583             (and (or (eq gnus-fetch-old-headers 'some)
7584                      (numberp gnus-fetch-old-headers))
7585                  (gnus-summary-article-ancient-p number)
7586                  (zerop children))
7587             ;; If this is "fetch-old-headered" and `invisible', then
7588             ;; we don't want this article.
7589             (and (eq gnus-fetch-old-headers 'invisible)
7590                  (gnus-summary-article-ancient-p number))
7591             ;; If this is a sparsely inserted article with no children,
7592             ;; we don't want it.
7593             (and (eq gnus-build-sparse-threads 'some)
7594                  (gnus-summary-article-sparse-p number)
7595                  (zerop children))
7596             ;; If we use expunging, and this article is really
7597             ;; low-scored, then we don't want this article.
7598             (when (and gnus-summary-expunge-below
7599                        (< (setq score
7600                                 (or (cdr (assq number gnus-newsgroup-scored))
7601                                     gnus-summary-default-score))
7602                           gnus-summary-expunge-below))
7603               ;; We increase the expunge-tally here, but that has
7604               ;; nothing to do with the limits, really.
7605               (incf gnus-newsgroup-expunged-tally)
7606               ;; We also mark as read here, if that's wanted.
7607               (when (and gnus-summary-mark-below
7608                          (< score gnus-summary-mark-below))
7609                 (setq gnus-newsgroup-unreads
7610                       (delq number gnus-newsgroup-unreads))
7611                 (if gnus-newsgroup-auto-expire
7612                     (push number gnus-newsgroup-expirable)
7613                   (push (cons number gnus-low-score-mark)
7614                         gnus-newsgroup-reads)))
7615               t)
7616             ;; Do the `display' group parameter.
7617             (and gnus-newsgroup-display
7618                  (not (funcall gnus-newsgroup-display)))
7619             ;; Check NoCeM things.
7620             (if (and gnus-use-nocem
7621                      (gnus-nocem-unwanted-article-p
7622                       (mail-header-id (car thread))))
7623                 (progn
7624                   (setq gnus-newsgroup-unreads
7625                         (delq number gnus-newsgroup-unreads))
7626                   t))))
7627           ;; Nope, invisible article.
7628           0
7629         ;; Ok, this article is to be visible, so we add it to the limit
7630         ;; and return 1.
7631         (push number gnus-newsgroup-limit)
7632         1))))
7633
7634 (defun gnus-expunge-thread (thread)
7635   "Mark all articles in THREAD as read."
7636   (let* ((number (mail-header-number (car thread))))
7637     (incf gnus-newsgroup-expunged-tally)
7638     ;; We also mark as read here, if that's wanted.
7639     (setq gnus-newsgroup-unreads
7640           (delq number gnus-newsgroup-unreads))
7641     (if gnus-newsgroup-auto-expire
7642         (push number gnus-newsgroup-expirable)
7643       (push (cons number gnus-low-score-mark)
7644             gnus-newsgroup-reads)))
7645   ;; Go recursively through all subthreads.
7646   (mapcar 'gnus-expunge-thread (cdr thread)))
7647
7648 ;; Summary article oriented commands
7649
7650 (defun gnus-summary-refer-parent-article (n)
7651   "Refer parent article N times.
7652 If N is negative, go to ancestor -N instead.
7653 The difference between N and the number of articles fetched is returned."
7654   (interactive "p")
7655   (let ((skip 1)
7656         error header ref)
7657     (when (not (natnump n))
7658       (setq skip (abs n)
7659             n 1))
7660     (while (and (> n 0)
7661                 (not error))
7662       (setq header (gnus-summary-article-header))
7663       (if (and (eq (mail-header-number header)
7664                    (cdr gnus-article-current))
7665                (equal gnus-newsgroup-name
7666                       (car gnus-article-current)))
7667           ;; If we try to find the parent of the currently
7668           ;; displayed article, then we take a look at the actual
7669           ;; References header, since this is slightly more
7670           ;; reliable than the References field we got from the
7671           ;; server.
7672           (save-excursion
7673             (set-buffer gnus-original-article-buffer)
7674             (nnheader-narrow-to-headers)
7675             (unless (setq ref (message-fetch-field "references"))
7676               (setq ref (message-fetch-field "in-reply-to")))
7677             (widen))
7678         (setq ref
7679               ;; It's not the current article, so we take a bet on
7680               ;; the value we got from the server.
7681               (mail-header-references header)))
7682       (if (and ref
7683                (not (equal ref "")))
7684           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7685             (gnus-message 1 "Couldn't find parent"))
7686         (gnus-message 1 "No references in article %d"
7687                       (gnus-summary-article-number))
7688         (setq error t))
7689       (decf n))
7690     (gnus-summary-position-point)
7691     n))
7692
7693 (defun gnus-summary-refer-references ()
7694   "Fetch all articles mentioned in the References header.
7695 Return the number of articles fetched."
7696   (interactive)
7697   (let ((ref (mail-header-references (gnus-summary-article-header)))
7698         (current (gnus-summary-article-number))
7699         (n 0))
7700     (if (or (not ref)
7701             (equal ref ""))
7702         (error "No References in the current article")
7703       ;; For each Message-ID in the References header...
7704       (while (string-match "<[^>]*>" ref)
7705         (incf n)
7706         ;; ... fetch that article.
7707         (gnus-summary-refer-article
7708          (prog1 (match-string 0 ref)
7709            (setq ref (substring ref (match-end 0))))))
7710       (gnus-summary-goto-subject current)
7711       (gnus-summary-position-point)
7712       n)))
7713
7714 (defun gnus-summary-refer-thread (&optional limit)
7715   "Fetch all articles in the current thread.
7716 If LIMIT (the numerical prefix), fetch that many old headers instead
7717 of what's specified by the `gnus-refer-thread-limit' variable."
7718   (interactive "P")
7719   (let ((id (mail-header-id (gnus-summary-article-header)))
7720         (limit (if limit (prefix-numeric-value limit)
7721                  gnus-refer-thread-limit)))
7722     ;; We want to fetch LIMIT *old* headers, but we also have to
7723     ;; re-fetch all the headers in the current buffer, because many of
7724     ;; them may be undisplayed.  So we adjust LIMIT.
7725     (when (numberp limit)
7726       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7727     (unless (eq gnus-fetch-old-headers 'invisible)
7728       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7729       ;; Retrieve the headers and read them in.
7730       (if (eq (gnus-retrieve-headers
7731                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7732               'nov)
7733           (gnus-build-all-threads)
7734         (error "Can't fetch thread from backends that don't support NOV"))
7735       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7736     (gnus-summary-limit-include-thread id)))
7737
7738 (defun gnus-summary-refer-article (message-id)
7739   "Fetch an article specified by MESSAGE-ID."
7740   (interactive "sMessage-ID: ")
7741   (when (and (stringp message-id)
7742              (not (zerop (length message-id))))
7743     ;; Construct the correct Message-ID if necessary.
7744     ;; Suggested by tale@pawl.rpi.edu.
7745     (unless (string-match "^<" message-id)
7746       (setq message-id (concat "<" message-id)))
7747     (unless (string-match ">$" message-id)
7748       (setq message-id (concat message-id ">")))
7749     (let* ((header (gnus-id-to-header message-id))
7750            (sparse (and header
7751                         (gnus-summary-article-sparse-p
7752                          (mail-header-number header))
7753                         (memq (mail-header-number header)
7754                               gnus-newsgroup-limit)))
7755            number)
7756       (cond
7757        ;; If the article is present in the buffer we just go to it.
7758        ((and header
7759              (or (not (gnus-summary-article-sparse-p
7760                        (mail-header-number header)))
7761                  sparse))
7762         (prog1
7763             (gnus-summary-goto-article
7764              (mail-header-number header) nil t)
7765           (when sparse
7766             (gnus-summary-update-article (mail-header-number header)))))
7767        (t
7768         ;; We fetch the article.
7769         (catch 'found
7770           (dolist (gnus-override-method (gnus-refer-article-methods))
7771             (gnus-check-server gnus-override-method)
7772             ;; Fetch the header, and display the article.
7773             (when (setq number (gnus-summary-insert-subject message-id))
7774               (gnus-summary-select-article nil nil nil number)
7775               (throw 'found t)))
7776           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7777
7778 (defun gnus-refer-article-methods ()
7779   "Return a list of referrable methods."
7780   (cond
7781    ;; No method, so we default to current and native.
7782    ((null gnus-refer-article-method)
7783     (list gnus-current-select-method gnus-select-method))
7784    ;; Current.
7785    ((eq 'current gnus-refer-article-method)
7786     (list gnus-current-select-method))
7787    ;; List of select methods.
7788    ((not (and (symbolp (car gnus-refer-article-method))
7789               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7790     (let (out)
7791       (dolist (method gnus-refer-article-method)
7792         (push (if (eq 'current method)
7793                   gnus-current-select-method
7794                 method)
7795               out))
7796       (nreverse out)))
7797    ;; One single select method.
7798    (t
7799     (list gnus-refer-article-method))))
7800
7801 (defun gnus-summary-edit-parameters ()
7802   "Edit the group parameters of the current group."
7803   (interactive)
7804   (gnus-group-edit-group gnus-newsgroup-name 'params))
7805
7806 (defun gnus-summary-customize-parameters ()
7807   "Customize the group parameters of the current group."
7808   (interactive)
7809   (gnus-group-customize gnus-newsgroup-name))
7810
7811 (defun gnus-summary-enter-digest-group (&optional force)
7812   "Enter an nndoc group based on the current article.
7813 If FORCE, force a digest interpretation.  If not, try
7814 to guess what the document format is."
7815   (interactive "P")
7816   (let ((conf gnus-current-window-configuration))
7817     (save-excursion
7818       (gnus-summary-select-article))
7819     (setq gnus-current-window-configuration conf)
7820     (let* ((name (format "%s-%d"
7821                          (gnus-group-prefixed-name
7822                           gnus-newsgroup-name (list 'nndoc ""))
7823                          (save-excursion
7824                            (set-buffer gnus-summary-buffer)
7825                            gnus-current-article)))
7826            (ogroup gnus-newsgroup-name)
7827            (params (append (gnus-info-params (gnus-get-info ogroup))
7828                            (list (cons 'to-group ogroup))
7829                            (list (cons 'save-article-group ogroup))))
7830            (case-fold-search t)
7831            (buf (current-buffer))
7832            dig to-address)
7833       (save-excursion
7834         (set-buffer gnus-original-article-buffer)
7835         ;; Have the digest group inherit the main mail address of
7836         ;; the parent article.
7837         (when (setq to-address (or (message-fetch-field "reply-to")
7838                                    (message-fetch-field "from")))
7839           (setq params (append
7840                         (list (cons 'to-address
7841                                     (funcall gnus-decode-encoded-word-function
7842                                              to-address))))))
7843         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7844         (insert-buffer-substring gnus-original-article-buffer)
7845         ;; Remove lines that may lead nndoc to misinterpret the
7846         ;; document type.
7847         (narrow-to-region
7848          (goto-char (point-min))
7849          (or (search-forward "\n\n" nil t) (point)))
7850         (goto-char (point-min))
7851         (delete-matching-lines "^Path:\\|^From ")
7852         (widen))
7853       (unwind-protect
7854           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7855                     (gnus-newsgroup-ephemeral-ignored-charsets
7856                      gnus-newsgroup-ignored-charsets))
7857                 (gnus-group-read-ephemeral-group
7858                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7859                               (nndoc-article-type
7860                                ,(if force 'mbox 'guess)))
7861                  t nil nil nil
7862                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7863                                                         "ADAPT")))))
7864               ;; Make all postings to this group go to the parent group.
7865               (nconc (gnus-info-params (gnus-get-info name))
7866                      params)
7867             ;; Couldn't select this doc group.
7868             (switch-to-buffer buf)
7869             (gnus-set-global-variables)
7870             (gnus-configure-windows 'summary)
7871             (gnus-message 3 "Article couldn't be entered?"))
7872         (kill-buffer dig)))))
7873
7874 (defun gnus-summary-read-document (n)
7875   "Open a new group based on the current article(s).
7876 This will allow you to read digests and other similar
7877 documents as newsgroups.
7878 Obeys the standard process/prefix convention."
7879   (interactive "P")
7880   (let* ((articles (gnus-summary-work-articles n))
7881          (ogroup gnus-newsgroup-name)
7882          (params (append (gnus-info-params (gnus-get-info ogroup))
7883                          (list (cons 'to-group ogroup))))
7884          article group egroup groups vgroup)
7885     (while (setq article (pop articles))
7886       (setq group (format "%s-%d" gnus-newsgroup-name article))
7887       (gnus-summary-remove-process-mark article)
7888       (when (gnus-summary-display-article article)
7889         (save-excursion
7890           (with-temp-buffer
7891             (insert-buffer-substring gnus-original-article-buffer)
7892             ;; Remove some headers that may lead nndoc to make
7893             ;; the wrong guess.
7894             (message-narrow-to-head)
7895             (goto-char (point-min))
7896             (delete-matching-lines "^\\(Path\\):\\|^From ")
7897             (widen)
7898             (if (setq egroup
7899                       (gnus-group-read-ephemeral-group
7900                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7901                                      (nndoc-article-type guess))
7902                        t nil t))
7903                 (progn
7904                   ;; Make all postings to this group go to the parent group.
7905                   (nconc (gnus-info-params (gnus-get-info egroup))
7906                          params)
7907                   (push egroup groups))
7908               ;; Couldn't select this doc group.
7909               (gnus-error 3 "Article couldn't be entered"))))))
7910     ;; Now we have selected all the documents.
7911     (cond
7912      ((not groups)
7913       (error "None of the articles could be interpreted as documents"))
7914      ((gnus-group-read-ephemeral-group
7915        (setq vgroup (format
7916                      "nnvirtual:%s-%s" gnus-newsgroup-name
7917                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7918        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7919        t
7920        (cons (current-buffer) 'summary)))
7921      (t
7922       (error "Couldn't select virtual nndoc group")))))
7923
7924 (defun gnus-summary-isearch-article (&optional regexp-p)
7925   "Do incremental search forward on the current article.
7926 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7927   (interactive "P")
7928   (let* ((gnus-inhibit-treatment t)
7929          (old (gnus-summary-select-article)))
7930     (gnus-configure-windows 'article)
7931     (gnus-eval-in-buffer-window gnus-article-buffer
7932       (save-restriction
7933         (widen)
7934         (when (eq 'old old)
7935           (gnus-article-show-all-headers))
7936         (goto-char (point-min))
7937         (isearch-forward regexp-p)))))
7938
7939 (defun gnus-summary-search-article-forward (regexp &optional backward)
7940   "Search for an article containing REGEXP forward.
7941 If BACKWARD, search backward instead."
7942   (interactive
7943    (list (read-string
7944           (format "Search article %s (regexp%s): "
7945                   (if current-prefix-arg "backward" "forward")
7946                   (if gnus-last-search-regexp
7947                       (concat ", default " gnus-last-search-regexp)
7948                     "")))
7949          current-prefix-arg))
7950   (if (string-equal regexp "")
7951       (setq regexp (or gnus-last-search-regexp ""))
7952     (setq gnus-last-search-regexp regexp)
7953     (setq gnus-article-before-search gnus-current-article))
7954   ;; Intentionally set gnus-last-article.
7955   (setq gnus-last-article gnus-article-before-search)
7956   (let ((gnus-last-article gnus-last-article))
7957     (if (gnus-summary-search-article regexp backward)
7958         (gnus-summary-show-thread)
7959       (error "Search failed: \"%s\"" regexp))))
7960
7961 (defun gnus-summary-search-article-backward (regexp)
7962   "Search for an article containing REGEXP backward."
7963   (interactive
7964    (list (read-string
7965           (format "Search article backward (regexp%s): "
7966                   (if gnus-last-search-regexp
7967                       (concat ", default " gnus-last-search-regexp)
7968                     "")))))
7969   (gnus-summary-search-article-forward regexp 'backward))
7970
7971 (eval-when-compile
7972   (defmacro gnus-summary-search-article-position-point (regexp backward)
7973     "Dehighlight the last matched text and goto the beginning position."
7974     (` (if (and gnus-summary-search-article-matched-data
7975                 (let ((text (caddr gnus-summary-search-article-matched-data))
7976                       (inhibit-read-only t)
7977                       buffer-read-only)
7978                   (delete-region
7979                    (goto-char (car gnus-summary-search-article-matched-data))
7980                    (cadr gnus-summary-search-article-matched-data))
7981                   (insert text)
7982                   (string-match (, regexp) text)))
7983            (if (, backward) (beginning-of-line) (end-of-line))
7984          (goto-char (if (, backward) (point-max) (point-min))))))
7985
7986   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7987     "Place point where X-Face image is displayed."
7988     (if (featurep 'xemacs)
7989         (` (let ((end (if (search-forward "\n\n" nil t)
7990                           (goto-char (1- (point)))
7991                         (point-min)))
7992                  extent)
7993              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7994              (unless (and (re-search-forward "^From:" end t)
7995                           (setq extent (extent-at (point)))
7996                           (extent-begin-glyph extent))
7997                (goto-char (, opoint)))))
7998       (` (let ((end (if (search-forward "\n\n" nil t)
7999                         (goto-char (1- (point)))
8000                       (point-min)))
8001                (start (or (search-backward "\n\n" nil t) (point-min))))
8002            (goto-char
8003             (or (text-property-any start end 'x-face-image t);; x-face-e21
8004                 (text-property-any start end 'x-face-mule-bitmap-image t)
8005                 (, opoint)))))))
8006
8007   (defmacro gnus-summary-search-article-highlight-matched-text
8008     (backward treated x-face)
8009     "Highlight matched text in the function `gnus-summary-search-article'."
8010     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8011              (end (set-marker (make-marker) (match-end 0)))
8012              (inhibit-read-only t)
8013              buffer-read-only)
8014          (unless treated
8015            (let ((,@
8016                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8017                     (mapcar
8018                      (lambda (item) (setq items (delq item items)))
8019                      '(gnus-treat-buttonize
8020                        gnus-treat-fill-article
8021                        gnus-treat-fill-long-lines
8022                        gnus-treat-emphasize
8023                        gnus-treat-highlight-headers
8024                        gnus-treat-highlight-citation
8025                        gnus-treat-highlight-signature
8026                        gnus-treat-overstrike
8027                        gnus-treat-display-xface
8028                        gnus-treat-buttonize-head
8029                        gnus-treat-decode-article-as-default-mime-charset))
8030                     (static-if (featurep 'xemacs)
8031                         items
8032                       (cons '(x-face-mule-delete-x-face-field
8033                               (quote never))
8034                             items))))
8035                  (gnus-treat-display-xface
8036                   (when (, x-face) gnus-treat-display-xface)))
8037              (gnus-article-prepare-mime-display)))
8038          (goto-char (if (, backward) start end))
8039          (when (, x-face)
8040            (gnus-summary-search-article-highlight-goto-x-face (point)))
8041          (setq gnus-summary-search-article-matched-data
8042                (list start end (buffer-substring start end)))
8043          (unless (eq start end);; matched text has been deleted. :-<
8044            (put-text-property start end 'face
8045                               (or (find-face 'isearch)
8046                                   'secondary-selection))))))
8047   )
8048
8049 (defun gnus-summary-search-article (regexp &optional backward)
8050   "Search for an article containing REGEXP.
8051 Optional argument BACKWARD means do search for backward.
8052 `gnus-select-article-hook' is not called during the search."
8053   ;; We have to require this here to make sure that the following
8054   ;; dynamic binding isn't shadowed by autoloading.
8055   (require 'gnus-async)
8056   (require 'gnus-art)
8057   (let ((gnus-select-article-hook nil)  ;Disable hook.
8058         (gnus-article-prepare-hook nil)
8059         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8060         (gnus-use-article-prefetch nil)
8061         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8062         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8063         (sum (current-buffer))
8064         (found nil)
8065         point treated)
8066     (gnus-save-hidden-threads
8067       (static-if (featurep 'xemacs)
8068           (let ((gnus-inhibit-treatment t))
8069             (setq treated (eq 'old (gnus-summary-select-article)))
8070             (when (and treated
8071                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8072                                  (window-live-p (get-buffer-window
8073                                                  gnus-article-buffer t)))))
8074               (gnus-summary-select-article nil t)
8075               (setq treated nil)))
8076         (let ((gnus-inhibit-treatment t)
8077               (x-face-mule-delete-x-face-field 'never))
8078           (setq treated (eq 'old (gnus-summary-select-article)))
8079           (when (and treated
8080                      (not
8081                       (and (gnus-buffer-live-p gnus-article-buffer)
8082                            (window-live-p (get-buffer-window
8083                                            gnus-article-buffer t))
8084                            (or (not (string-match "^\\^X-Face:" regexp))
8085                                (with-current-buffer gnus-article-buffer
8086                                  gnus-summary-search-article-matched-data)))))
8087             (gnus-summary-select-article nil t)
8088             (setq treated nil))))
8089       (set-buffer gnus-article-buffer)
8090       (widen)
8091       (if treated
8092           (progn
8093             (gnus-article-show-all-headers)
8094             (gnus-summary-search-article-position-point regexp backward))
8095         (goto-char (if backward (point-max) (point-min))))
8096       (while (not found)
8097         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8098         (if (if backward
8099                 (re-search-backward regexp nil t)
8100               (re-search-forward regexp nil t))
8101             ;; We found the regexp.
8102             (progn
8103               (gnus-summary-search-article-highlight-matched-text
8104                backward treated (string-match "^\\^X-Face:" regexp))
8105               (setq found 'found)
8106               (forward-line
8107                (/ (- 2 (window-height
8108                         (get-buffer-window gnus-article-buffer t)))
8109                   2))
8110               (set-window-start
8111                (get-buffer-window (current-buffer))
8112                (point))
8113               (set-buffer sum)
8114               (setq point (point)))
8115           ;; We didn't find it, so we go to the next article.
8116           (set-buffer sum)
8117           (setq found 'not)
8118           (while (eq found 'not)
8119             (if (not (if backward (gnus-summary-find-prev)
8120                        (gnus-summary-find-next)))
8121                 ;; No more articles.
8122                 (setq found t)
8123               ;; Select the next article and adjust point.
8124               (unless (gnus-summary-article-sparse-p
8125                        (gnus-summary-article-number))
8126                 (setq found nil)
8127                 (let ((gnus-inhibit-treatment t))
8128                   (gnus-summary-select-article))
8129                 (setq treated nil)
8130                 (set-buffer gnus-article-buffer)
8131                 (widen)
8132                 (goto-char (if backward (point-max) (point-min))))))))
8133       (gnus-message 7 ""))
8134     ;; Return whether we found the regexp.
8135     (when (eq found 'found)
8136       (goto-char point)
8137       (gnus-summary-show-thread)
8138       (gnus-summary-goto-subject gnus-current-article)
8139       (gnus-summary-position-point)
8140       t)))
8141
8142 (defun gnus-find-matching-articles (header regexp)
8143   "Return a list of all articles that match REGEXP on HEADER.
8144 This search includes all articles in the current group that Gnus has
8145 fetched headers for, whether they are displayed or not."
8146   (let ((articles nil)
8147         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8148         (case-fold-search t))
8149     (dolist (header gnus-newsgroup-headers)
8150       (when (string-match regexp (funcall func header))
8151         (push (mail-header-number header) articles)))
8152     (nreverse articles)))
8153
8154 (defun gnus-summary-find-matching (header regexp &optional backward unread
8155                                           not-case-fold not-matching)
8156   "Return a list of all articles that match REGEXP on HEADER.
8157 The search stars on the current article and goes forwards unless
8158 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8159 If UNREAD is non-nil, only unread articles will
8160 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8161 in the comparisons. If NOT-MATCHING, return a list of all articles that
8162 not match REGEXP on HEADER."
8163   (let ((case-fold-search (not not-case-fold))
8164         articles d func)
8165     (if (consp header)
8166         (if (eq (car header) 'extra)
8167             (setq func
8168                   `(lambda (h)
8169                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8170                          "")))
8171           (error "%s is an invalid header" header))
8172       (unless (fboundp (intern (concat "mail-header-" header)))
8173         (error "%s is not a valid header" header))
8174       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8175     (dolist (d (if (eq backward 'all)
8176                    gnus-newsgroup-data
8177                  (gnus-data-find-list
8178                   (gnus-summary-article-number)
8179                   (gnus-data-list backward))))
8180       (when (and (or (not unread)       ; We want all articles...
8181                      (gnus-data-unread-p d)) ; Or just unreads.
8182                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8183                  (if not-matching
8184                      (not (string-match
8185                            regexp
8186                            (funcall func (gnus-data-header d))))
8187                    (string-match regexp
8188                                  (funcall func (gnus-data-header d)))))
8189         (push (gnus-data-number d) articles))) ; Success!
8190     (nreverse articles)))
8191
8192 (defun gnus-summary-execute-command (header regexp command &optional backward)
8193   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8194 If HEADER is an empty string (or nil), the match is done on the entire
8195 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8196   (interactive
8197    (list (let ((completion-ignore-case t))
8198            (completing-read
8199             "Header name: "
8200             (mapcar (lambda (header) (list (format "%s" header)))
8201                     (append
8202                      '("Number" "Subject" "From" "Lines" "Date"
8203                        "Message-ID" "Xref" "References" "Body")
8204                      gnus-extra-headers))
8205             nil 'require-match))
8206          (read-string "Regexp: ")
8207          (read-key-sequence "Command: ")
8208          current-prefix-arg))
8209   (when (equal header "Body")
8210     (setq header ""))
8211   ;; Hidden thread subtrees must be searched as well.
8212   (gnus-summary-show-all-threads)
8213   ;; We don't want to change current point nor window configuration.
8214   (save-excursion
8215     (save-window-excursion
8216       (gnus-message 6 "Executing %s..." (key-description command))
8217       ;; We'd like to execute COMMAND interactively so as to give arguments.
8218       (gnus-execute header regexp
8219                     `(call-interactively ',(key-binding command))
8220                     backward)
8221       (gnus-message 6 "Executing %s...done" (key-description command)))))
8222
8223 (defun gnus-summary-beginning-of-article ()
8224   "Scroll the article back to the beginning."
8225   (interactive)
8226   (gnus-summary-select-article)
8227   (gnus-configure-windows 'article)
8228   (gnus-eval-in-buffer-window gnus-article-buffer
8229     (widen)
8230     (goto-char (point-min))
8231     (when gnus-page-broken
8232       (gnus-narrow-to-page))))
8233
8234 (defun gnus-summary-end-of-article ()
8235   "Scroll to the end of the article."
8236   (interactive)
8237   (gnus-summary-select-article)
8238   (gnus-configure-windows 'article)
8239   (gnus-eval-in-buffer-window gnus-article-buffer
8240     (widen)
8241     (goto-char (point-max))
8242     (recenter -3)
8243     (when gnus-page-broken
8244       (gnus-narrow-to-page))))
8245
8246 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8247   "Truncate to LEN and quote all \"(\"'s in STRING."
8248   (gnus-replace-in-string (if (and len (> (length string) len))
8249                               (substring string 0 len)
8250                             string)
8251                           "[()]" "\\\\\\&"))
8252
8253 (defun gnus-summary-print-article (&optional filename n)
8254   "Generate and print a PostScript image of the N next (mail) articles.
8255
8256 If N is negative, print the N previous articles.  If N is nil and articles
8257 have been marked with the process mark, print these instead.
8258
8259 If the optional first argument FILENAME is nil, send the image to the
8260 printer.  If FILENAME is a string, save the PostScript image in a file with
8261 that name.  If FILENAME is a number, prompt the user for the name of the file
8262 to save in."
8263   (interactive (list (ps-print-preprint current-prefix-arg)))
8264   (dolist (article (gnus-summary-work-articles n))
8265     (gnus-summary-select-article nil nil 'pseudo article)
8266     (gnus-eval-in-buffer-window gnus-article-buffer
8267       (gnus-print-buffer))
8268     (gnus-summary-remove-process-mark article))
8269   (ps-despool filename))
8270
8271 (defun gnus-print-buffer ()
8272   (let ((buffer (generate-new-buffer " *print*")))
8273     (unwind-protect
8274         (progn
8275           (copy-to-buffer buffer (point-min) (point-max))
8276           (set-buffer buffer)
8277           (gnus-article-delete-invisible-text)
8278           (gnus-remove-text-with-property 'gnus-decoration)
8279           (when (gnus-visual-p 'article-highlight 'highlight)
8280             ;; Copy-to-buffer doesn't copy overlay.  So redo
8281             ;; highlight.
8282             (let ((gnus-article-buffer buffer))
8283               (gnus-article-highlight-citation t)
8284               (gnus-article-highlight-signature)))
8285           (let ((ps-left-header
8286                  (list
8287                   (concat "("
8288                           (gnus-summary-print-truncate-and-quote
8289                            (mail-header-subject gnus-current-headers)
8290                            66) ")")
8291                   (concat "("
8292                           (gnus-summary-print-truncate-and-quote
8293                            (mail-header-from gnus-current-headers)
8294                            45) ")")))
8295                 (ps-right-header
8296                  (list
8297                   "/pagenumberstring load"
8298                   (concat "("
8299                           (mail-header-date gnus-current-headers) ")"))))
8300             (gnus-run-hooks 'gnus-ps-print-hook)
8301             (save-excursion
8302               (if window-system
8303                   (ps-spool-buffer-with-faces)
8304                 (ps-spool-buffer)))))
8305       (kill-buffer buffer))))
8306
8307 (defun gnus-summary-show-article (&optional arg)
8308   "Force redisplaying of the current article.
8309 If ARG (the prefix) is a number, show the article with the charset
8310 defined in `gnus-summary-show-article-charset-alist', or the charset
8311 input.
8312 If ARG (the prefix) is non-nil and not a number, show the raw article
8313 without any article massaging functions being run.  Normally, the key strokes
8314 are `C-u g'."
8315   (interactive "P")
8316   (cond
8317    ((numberp arg)
8318     (gnus-summary-show-article t)
8319     (let* ((gnus-newsgroup-charset
8320             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8321                 (mm-read-coding-system
8322                  "View as charset: " ;; actually it is coding system.
8323                  (save-excursion
8324                    (set-buffer gnus-article-buffer)
8325                    (mm-detect-coding-region (point) (point-max))))))
8326            (default-mime-charset gnus-newsgroup-charset)
8327            (gnus-newsgroup-ignored-charsets 'gnus-all))
8328       (gnus-summary-select-article nil 'force)
8329       (let ((deps gnus-newsgroup-dependencies)
8330             head header lines)
8331         (save-excursion
8332           (set-buffer gnus-original-article-buffer)
8333           (save-restriction
8334             (message-narrow-to-head)
8335             (setq head (buffer-string))
8336             (goto-char (point-min))
8337             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8338               (goto-char (point-max))
8339               (widen)
8340               (setq lines (1- (count-lines (point) (point-max))))))
8341           (with-temp-buffer
8342             (insert (format "211 %d Article retrieved.\n"
8343                             (cdr gnus-article-current)))
8344             (insert head)
8345             (if lines (insert (format "Lines: %d\n" lines)))
8346             (insert ".\n")
8347             (let ((nntp-server-buffer (current-buffer)))
8348               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8349         (gnus-data-set-header
8350          (gnus-data-find (cdr gnus-article-current))
8351          header)
8352         (gnus-summary-update-article-line
8353          (cdr gnus-article-current) header)
8354         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8355           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8356    ((not arg)
8357     ;; Select the article the normal way.
8358     (gnus-summary-select-article nil 'force))
8359    (t
8360     ;; We have to require this here to make sure that the following
8361     ;; dynamic binding isn't shadowed by autoloading.
8362     (require 'gnus-async)
8363     (require 'gnus-art)
8364     ;; Bind the article treatment functions to nil.
8365     (let ((gnus-have-all-headers t)
8366           gnus-article-prepare-hook
8367           gnus-article-decode-hook
8368           gnus-break-pages
8369           gnus-show-mime
8370           (gnus-inhibit-treatment t))
8371       (gnus-summary-select-article nil 'force))))
8372   (gnus-summary-goto-subject gnus-current-article)
8373   (gnus-summary-position-point))
8374
8375 (defun gnus-summary-show-raw-article ()
8376   "Show the raw article without any article massaging functions being run."
8377   (interactive)
8378   (gnus-summary-show-article t))
8379
8380 (defun gnus-summary-verbose-headers (&optional arg)
8381   "Toggle permanent full header display.
8382 If ARG is a positive number, turn header display on.
8383 If ARG is a negative number, turn header display off."
8384   (interactive "P")
8385   (setq gnus-show-all-headers
8386         (cond ((or (not (numberp arg))
8387                    (zerop arg))
8388                (not gnus-show-all-headers))
8389               ((natnump arg)
8390                t)))
8391   (gnus-summary-show-article))
8392
8393 (defun gnus-summary-toggle-header (&optional arg)
8394   "Show the headers if they are hidden, or hide them if they are shown.
8395 If ARG is a positive number, show the entire header.
8396 If ARG is a negative number, hide the unwanted header lines."
8397   (interactive "P")
8398   (save-excursion
8399     (set-buffer gnus-article-buffer)
8400     (save-restriction
8401       (let* ((buffer-read-only nil)
8402              (inhibit-point-motion-hooks t)
8403              hidden e)
8404         (save-restriction
8405           (article-narrow-to-head)
8406           (setq e (point-max)
8407                 hidden (if (numberp arg)
8408                            (>= arg 0)
8409                          (gnus-article-hidden-text-p 'headers))))
8410         (delete-region (point-min) e)
8411         (goto-char (point-min))
8412         (save-excursion
8413           (set-buffer gnus-original-article-buffer)
8414           (goto-char (point-min))
8415           (setq e (search-forward "\n\n" nil t)
8416                 e (if e (1- e) (point-max))))
8417         (insert-buffer-substring gnus-original-article-buffer 1 e)
8418         (save-restriction
8419           (narrow-to-region (point-min) (point))
8420           (article-decode-encoded-words)
8421           (if  hidden
8422               (let ((gnus-treat-hide-headers nil)
8423                     (gnus-treat-hide-boring-headers nil))
8424                 (gnus-delete-wash-type 'headers)
8425                 (gnus-treat-article 'head))
8426             (gnus-treat-article 'head)))
8427         (gnus-set-mode-line 'article)))))
8428
8429 (defun gnus-summary-show-all-headers ()
8430   "Make all header lines visible."
8431   (interactive)
8432   (gnus-summary-toggle-header 1))
8433
8434 (defun gnus-summary-toggle-mime (&optional arg)
8435   "Toggle MIME processing.
8436 If ARG is a positive number, turn MIME processing on."
8437   (interactive "P")
8438   (setq gnus-show-mime
8439         (if (null arg)
8440             (not gnus-show-mime)
8441           (> (prefix-numeric-value arg) 0)))
8442   (gnus-summary-select-article t 'force))
8443
8444 (defun gnus-summary-caesar-message (&optional arg)
8445   "Caesar rotate the current article by 13.
8446 The numerical prefix specifies how many places to rotate each letter
8447 forward."
8448   (interactive "P")
8449   (gnus-summary-select-article)
8450   (let ((mail-header-separator ""))
8451     (gnus-eval-in-buffer-window gnus-article-buffer
8452       (save-restriction
8453         (widen)
8454         (let ((start (window-start))
8455               buffer-read-only)
8456           (message-caesar-buffer-body arg)
8457           (set-window-start (get-buffer-window (current-buffer)) start))))))
8458
8459 (defun gnus-summary-stop-page-breaking ()
8460   "Stop page breaking in the current article."
8461   (interactive)
8462   (gnus-summary-select-article)
8463   (gnus-eval-in-buffer-window gnus-article-buffer
8464     (widen)
8465     (when (gnus-visual-p 'page-marker)
8466       (let ((buffer-read-only nil))
8467         (gnus-remove-text-with-property 'gnus-prev)
8468         (gnus-remove-text-with-property 'gnus-next))
8469       (setq gnus-page-broken nil))))
8470
8471 (defun gnus-summary-move-article (&optional n to-newsgroup
8472                                             select-method action)
8473   "Move the current article to a different newsgroup.
8474 If N is a positive number, move the N next articles.
8475 If N is a negative number, move the N previous articles.
8476 If N is nil and any articles have been marked with the process mark,
8477 move those articles instead.
8478 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8479 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8480 re-spool using this method.
8481
8482 When called interactively with TO-NEWSGROUP being nil, the value of
8483 the variable `gnus-move-split-methods' is used for finding a default
8484 for the target newsgroup.
8485
8486 For this function to work, both the current newsgroup and the
8487 newsgroup that you want to move to have to support the `request-move'
8488 and `request-accept' functions.
8489
8490 ACTION can be either `move' (the default), `crosspost' or `copy'."
8491   (interactive "P")
8492   (unless action
8493     (setq action 'move))
8494   ;; Check whether the source group supports the required functions.
8495   (cond ((and (eq action 'move)
8496               (not (gnus-check-backend-function
8497                     'request-move-article gnus-newsgroup-name)))
8498          (error "The current group does not support article moving"))
8499         ((and (eq action 'crosspost)
8500               (not (gnus-check-backend-function
8501                     'request-replace-article gnus-newsgroup-name)))
8502          (error "The current group does not support article editing")))
8503   (let ((articles (gnus-summary-work-articles n))
8504         (prefix (if (gnus-check-backend-function
8505                      'request-move-article gnus-newsgroup-name)
8506                     (gnus-group-real-prefix gnus-newsgroup-name)
8507                   ""))
8508         (names '((move "Move" "Moving")
8509                  (copy "Copy" "Copying")
8510                  (crosspost "Crosspost" "Crossposting")))
8511         (copy-buf (save-excursion
8512                     (nnheader-set-temp-buffer " *copy article*")))
8513         (default-marks gnus-article-mark-lists)
8514         (no-expire-marks (delete '(expirable . expire)
8515                                  (copy-sequence gnus-article-mark-lists)))
8516         art-group to-method new-xref article to-groups)
8517     (unless (assq action names)
8518       (error "Unknown action %s" action))
8519     ;; Read the newsgroup name.
8520     (when (and (not to-newsgroup)
8521                (not select-method))
8522       (if (and gnus-move-split-methods
8523                (not
8524                 (and (memq gnus-current-article articles)
8525                      (gnus-buffer-live-p gnus-original-article-buffer))))
8526           ;; When `gnus-move-split-methods' is non-nil, we have to
8527           ;; select an article to give `gnus-read-move-group-name' an
8528           ;; opportunity to suggest an appropriate default.  However,
8529           ;; we needn't render or mark the article.
8530           (let ((gnus-display-mime-function nil)
8531                 (gnus-article-prepare-hook nil)
8532                 (gnus-mark-article-hook nil))
8533             (gnus-summary-select-article nil nil nil (car articles))))
8534       (setq to-newsgroup
8535             (gnus-read-move-group-name
8536              (cadr (assq action names))
8537              (symbol-value (intern (format "gnus-current-%s-group" action)))
8538              articles prefix))
8539       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8540     (setq to-method (or select-method
8541                         (gnus-server-to-method
8542                          (gnus-group-method to-newsgroup))))
8543     ;; Check the method we are to move this article to...
8544     (unless (gnus-check-backend-function
8545              'request-accept-article (car to-method))
8546       (error "%s does not support article copying" (car to-method)))
8547     (unless (gnus-check-server to-method)
8548       (error "Can't open server %s" (car to-method)))
8549     (gnus-message 6 "%s to %s: %s..."
8550                   (caddr (assq action names))
8551                   (or (car select-method) to-newsgroup) articles)
8552     (while articles
8553       (setq article (pop articles))
8554       (setq
8555        art-group
8556        (cond
8557         ;; Move the article.
8558         ((eq action 'move)
8559          ;; Remove this article from future suppression.
8560          (gnus-dup-unsuppress-article article)
8561          (gnus-request-move-article
8562           article                       ; Article to move
8563           gnus-newsgroup-name           ; From newsgroup
8564           (nth 1 (gnus-find-method-for-group
8565                   gnus-newsgroup-name)) ; Server
8566           (list 'gnus-request-accept-article
8567                 to-newsgroup (list 'quote select-method)
8568                 (not articles) t)       ; Accept form
8569           (not articles)))              ; Only save nov last time
8570         ;; Copy the article.
8571         ((eq action 'copy)
8572          (save-excursion
8573            (set-buffer copy-buf)
8574            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8575              (gnus-request-accept-article
8576               to-newsgroup select-method (not articles) t))))
8577         ;; Crosspost the article.
8578         ((eq action 'crosspost)
8579          (let ((xref (message-tokenize-header
8580                       (mail-header-xref (gnus-summary-article-header article))
8581                       " ")))
8582            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8583                                   ":" (number-to-string article)))
8584            (unless xref
8585              (setq xref (list (system-name))))
8586            (setq new-xref
8587                  (concat
8588                   (mapconcat 'identity
8589                              (delete "Xref:" (delete new-xref xref))
8590                              " ")
8591                   " " new-xref))
8592            (save-excursion
8593              (set-buffer copy-buf)
8594              ;; First put the article in the destination group.
8595              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8596              (when (consp (setq art-group
8597                                 (gnus-request-accept-article
8598                                  to-newsgroup select-method (not articles))))
8599                (setq new-xref (concat new-xref " " (car art-group)
8600                                       ":"
8601                                       (number-to-string (cdr art-group))))
8602                ;; Now we have the new Xrefs header, so we insert
8603                ;; it and replace the new article.
8604                (nnheader-replace-header "Xref" new-xref)
8605                (gnus-request-replace-article
8606                 (cdr art-group) to-newsgroup (current-buffer))
8607                art-group))))))
8608       (cond
8609        ((not art-group)
8610         (gnus-message 1 "Couldn't %s article %s: %s"
8611                       (cadr (assq action names)) article
8612                       (nnheader-get-report (car to-method))))
8613        ((eq art-group 'junk)
8614         (when (eq action 'move)
8615           (gnus-summary-mark-article article gnus-canceled-mark)
8616           (gnus-message 4 "Deleted article %s" article)))
8617        (t
8618         (let* ((pto-group (gnus-group-prefixed-name
8619                            (car art-group) to-method))
8620                (entry
8621                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8622                (info (nth 2 entry))
8623                (to-group (gnus-info-group info))
8624                to-marks)
8625           ;; Update the group that has been moved to.
8626           (when (and info
8627                      (memq action '(move copy)))
8628             (unless (member to-group to-groups)
8629               (push to-group to-groups))
8630
8631             (unless (memq article gnus-newsgroup-unreads)
8632               (push 'read to-marks)
8633               (gnus-info-set-read
8634                info (gnus-add-to-range (gnus-info-read info)
8635                                        (list (cdr art-group)))))
8636
8637             ;; See whether the article is to be put in the cache.
8638             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8639                              default-marks
8640                            no-expire-marks))
8641                   (to-article (cdr art-group)))
8642
8643               ;; Enter the article into the cache in the new group,
8644               ;; if that is required.
8645               (when gnus-use-cache
8646                 (gnus-cache-possibly-enter-article
8647                  to-group to-article
8648                  (let ((header (copy-sequence
8649                                 (gnus-summary-article-header article))))
8650                    (mail-header-set-number header to-article)
8651                    header)
8652                  (memq article gnus-newsgroup-marked)
8653                  (memq article gnus-newsgroup-dormant)
8654                  (memq article gnus-newsgroup-unreads)))
8655
8656               (when gnus-preserve-marks
8657                 ;; Copy any marks over to the new group.
8658                 (when (and (equal to-group gnus-newsgroup-name)
8659                            (not (memq article gnus-newsgroup-unreads)))
8660                   ;; Mark this article as read in this group.
8661                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8662                   (setcdr (gnus-active to-group) to-article)
8663                   (setcdr gnus-newsgroup-active to-article))
8664
8665                 (while marks
8666                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8667                     (when (memq article (symbol-value
8668                                          (intern (format "gnus-newsgroup-%s"
8669                                                          (caar marks)))))
8670                       (push (cdar marks) to-marks)
8671                       ;; If the other group is the same as this group,
8672                       ;; then we have to add the mark to the list.
8673                       (when (equal to-group gnus-newsgroup-name)
8674                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8675                              (cons to-article
8676                                    (symbol-value
8677                                     (intern (format "gnus-newsgroup-%s"
8678                                                     (caar marks)))))))
8679                       ;; Copy the marks to other group.
8680                       (gnus-add-marked-articles
8681                        to-group (cdar marks) (list to-article) info)))
8682                   (setq marks (cdr marks)))
8683
8684                 (gnus-request-set-mark to-group (list (list (list to-article)
8685                                                             'add
8686                                                             to-marks))))
8687
8688               (gnus-dribble-enter
8689                (concat "(gnus-group-set-info '"
8690                        (gnus-prin1-to-string (gnus-get-info to-group))
8691                        ")"))))
8692
8693           ;; Update the Xref header in this article to point to
8694           ;; the new crossposted article we have just created.
8695           (when (eq action 'crosspost)
8696             (save-excursion
8697               (set-buffer copy-buf)
8698               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8699               (nnheader-replace-header "Xref" new-xref)
8700               (gnus-request-replace-article
8701                article gnus-newsgroup-name (current-buffer)))))
8702
8703         ;;;!!!Why is this necessary?
8704         (set-buffer gnus-summary-buffer)
8705
8706         (gnus-summary-goto-subject article)
8707         (when (eq action 'move)
8708           (gnus-summary-mark-article article gnus-canceled-mark))))
8709       (gnus-summary-remove-process-mark article))
8710     ;; Re-activate all groups that have been moved to.
8711     (save-excursion
8712       (set-buffer gnus-group-buffer)
8713       (let ((gnus-group-marked to-groups))
8714         (gnus-group-get-new-news-this-group nil t)))
8715
8716     (gnus-kill-buffer copy-buf)
8717     (gnus-summary-position-point)
8718     (gnus-set-mode-line 'summary)))
8719
8720 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8721   "Move the current article to a different newsgroup.
8722 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8723 When called interactively, if TO-NEWSGROUP is nil, use the value of
8724 the variable `gnus-move-split-methods' for finding a default target
8725 newsgroup.
8726 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8727 re-spool using this method."
8728   (interactive "P")
8729   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8730
8731 (defun gnus-summary-crosspost-article (&optional n)
8732   "Crosspost the current article to some other group."
8733   (interactive "P")
8734   (gnus-summary-move-article n nil nil 'crosspost))
8735
8736 (defcustom gnus-summary-respool-default-method nil
8737   "Default method type for respooling an article.
8738 If nil, use to the current newsgroup method."
8739   :type 'symbol
8740   :group 'gnus-summary-mail)
8741
8742 (defun gnus-summary-respool-article (&optional n method)
8743   "Respool the current article.
8744 The article will be squeezed through the mail spooling process again,
8745 which means that it will be put in some mail newsgroup or other
8746 depending on `nnmail-split-methods'.
8747 If N is a positive number, respool the N next articles.
8748 If N is a negative number, respool the N previous articles.
8749 If N is nil and any articles have been marked with the process mark,
8750 respool those articles instead.
8751
8752 Respooling can be done both from mail groups and \"real\" newsgroups.
8753 In the former case, the articles in question will be moved from the
8754 current group into whatever groups they are destined to.  In the
8755 latter case, they will be copied into the relevant groups."
8756   (interactive
8757    (list current-prefix-arg
8758          (let* ((methods (gnus-methods-using 'respool))
8759                 (methname
8760                  (symbol-name (or gnus-summary-respool-default-method
8761                                   (car (gnus-find-method-for-group
8762                                         gnus-newsgroup-name)))))
8763                 (method
8764                  (gnus-completing-read-with-default
8765                   methname "What backend do you want to use when respooling?"
8766                   methods nil t nil 'gnus-mail-method-history))
8767                 ms)
8768            (cond
8769             ((zerop (length (setq ms (gnus-servers-using-backend
8770                                       (intern method)))))
8771              (list (intern method) ""))
8772             ((= 1 (length ms))
8773              (car ms))
8774             (t
8775              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8776                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8777                            ms-alist))))))))
8778   (unless method
8779     (error "No method given for respooling"))
8780   (if (assoc (symbol-name
8781               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8782              (gnus-methods-using 'respool))
8783       (gnus-summary-move-article n nil method)
8784     (gnus-summary-copy-article n nil method)))
8785
8786 (defun gnus-summary-import-article (file &optional edit)
8787   "Import an arbitrary file into a mail newsgroup."
8788   (interactive "fImport file: \nP")
8789   (let ((group gnus-newsgroup-name)
8790         (now (current-time))
8791         atts lines group-art)
8792     (unless (gnus-check-backend-function 'request-accept-article group)
8793       (error "%s does not support article importing" group))
8794     (or (file-readable-p file)
8795         (not (file-regular-p file))
8796         (error "Can't read %s" file))
8797     (save-excursion
8798       (set-buffer (gnus-get-buffer-create " *import file*"))
8799       (erase-buffer)
8800       (nnheader-insert-file-contents file)
8801       (goto-char (point-min))
8802       (if (nnheader-article-p)
8803           (save-restriction
8804             (goto-char (point-min))
8805             (search-forward "\n\n" nil t)
8806             (narrow-to-region (point-min) (1- (point)))
8807             (goto-char (point-min))
8808             (unless (re-search-forward "^date:" nil t)
8809               (goto-char (point-max))
8810               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8811         ;; This doesn't look like an article, so we fudge some headers.
8812         (setq atts (file-attributes file)
8813               lines (count-lines (point-min) (point-max)))
8814         (insert "From: " (read-string "From: ") "\n"
8815                 "Subject: " (read-string "Subject: ") "\n"
8816                 "Date: " (message-make-date (nth 5 atts)) "\n"
8817                 "Message-ID: " (message-make-message-id) "\n"
8818                 "Lines: " (int-to-string lines) "\n"
8819                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8820       (setq group-art (gnus-request-accept-article group nil t))
8821       (kill-buffer (current-buffer)))
8822     (setq gnus-newsgroup-active (gnus-activate-group group))
8823     (forward-line 1)
8824     (gnus-summary-goto-article (cdr group-art) nil t)
8825     (when edit
8826       (gnus-summary-edit-article))))
8827
8828 (defun gnus-summary-create-article ()
8829   "Create an article in a mail newsgroup."
8830   (interactive)
8831   (let ((group gnus-newsgroup-name)
8832         (now (current-time))
8833         group-art)
8834     (unless (gnus-check-backend-function 'request-accept-article group)
8835       (error "%s does not support article importing" group))
8836     (save-excursion
8837       (set-buffer (gnus-get-buffer-create " *import file*"))
8838       (erase-buffer)
8839       (goto-char (point-min))
8840       ;; This doesn't look like an article, so we fudge some headers.
8841       (insert "From: " (read-string "From: ") "\n"
8842               "Subject: " (read-string "Subject: ") "\n"
8843               "Date: " (message-make-date now) "\n"
8844               "Message-ID: " (message-make-message-id) "\n")
8845       (setq group-art (gnus-request-accept-article group nil t))
8846       (kill-buffer (current-buffer)))
8847     (setq gnus-newsgroup-active (gnus-activate-group group))
8848     (forward-line 1)
8849     (gnus-summary-goto-article (cdr group-art) nil t)
8850     (gnus-summary-edit-article)))
8851
8852 (defun gnus-summary-article-posted-p ()
8853   "Say whether the current (mail) article is available from news as well.
8854 This will be the case if the article has both been mailed and posted."
8855   (interactive)
8856   (let ((id (mail-header-references (gnus-summary-article-header)))
8857         (gnus-override-method (car (gnus-refer-article-methods))))
8858     (if (gnus-request-head id "")
8859         (gnus-message 2 "The current message was found on %s"
8860                       gnus-override-method)
8861       (gnus-message 2 "The current message couldn't be found on %s"
8862                     gnus-override-method)
8863       nil)))
8864
8865 (defun gnus-summary-expire-articles (&optional now)
8866   "Expire all articles that are marked as expirable in the current group."
8867   (interactive)
8868   (when (gnus-check-backend-function
8869          'request-expire-articles gnus-newsgroup-name)
8870     ;; This backend supports expiry.
8871     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8872            (expirable (if total
8873                           (progn
8874                             ;; We need to update the info for
8875                             ;; this group for `gnus-list-of-read-articles'
8876                             ;; to give us the right answer.
8877                             (gnus-run-hooks 'gnus-exit-group-hook)
8878                             (gnus-summary-update-info)
8879                             (gnus-list-of-read-articles gnus-newsgroup-name))
8880                         (setq gnus-newsgroup-expirable
8881                               (sort gnus-newsgroup-expirable '<))))
8882            (expiry-wait (if now 'immediate
8883                           (gnus-group-find-parameter
8884                            gnus-newsgroup-name 'expiry-wait)))
8885            (nnmail-expiry-target
8886             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8887                 nnmail-expiry-target))
8888            es)
8889       (when expirable
8890         ;; There are expirable articles in this group, so we run them
8891         ;; through the expiry process.
8892         (gnus-message 6 "Expiring articles...")
8893         (unless (gnus-check-group gnus-newsgroup-name)
8894           (error "Can't open server for %s" gnus-newsgroup-name))
8895         ;; The list of articles that weren't expired is returned.
8896         (save-excursion
8897           (if expiry-wait
8898               (let ((nnmail-expiry-wait-function nil)
8899                     (nnmail-expiry-wait expiry-wait))
8900                 (setq es (gnus-request-expire-articles
8901                           expirable gnus-newsgroup-name)))
8902             (setq es (gnus-request-expire-articles
8903                       expirable gnus-newsgroup-name)))
8904           (unless total
8905             (setq gnus-newsgroup-expirable es))
8906           ;; We go through the old list of expirable, and mark all
8907           ;; really expired articles as nonexistent.
8908           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8909             (let ((gnus-use-cache nil))
8910               (dolist (article expirable)
8911                 (when (and (not (memq article es))
8912                            (gnus-data-find article))
8913                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8914         (gnus-message 6 "Expiring articles...done")))))
8915
8916 (defun gnus-summary-expire-articles-now ()
8917   "Expunge all expirable articles in the current group.
8918 This means that *all* articles that are marked as expirable will be
8919 deleted forever, right now."
8920   (interactive)
8921   (or gnus-expert-user
8922       (gnus-yes-or-no-p
8923        "Are you really, really, really sure you want to delete all these messages? ")
8924       (error "Phew!"))
8925   (gnus-summary-expire-articles t))
8926
8927 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8928 (defun gnus-summary-delete-article (&optional n)
8929   "Delete the N next (mail) articles.
8930 This command actually deletes articles.  This is not a marking
8931 command.  The article will disappear forever from your life, never to
8932 return.
8933 If N is negative, delete backwards.
8934 If N is nil and articles have been marked with the process mark,
8935 delete these instead."
8936   (interactive "P")
8937   (unless (gnus-check-backend-function 'request-expire-articles
8938                                        gnus-newsgroup-name)
8939     (error "The current newsgroup does not support article deletion"))
8940   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8941     (error "Couldn't open server"))
8942   ;; Compute the list of articles to delete.
8943   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8944         not-deleted)
8945     (if (and gnus-novice-user
8946              (not (gnus-yes-or-no-p
8947                    (format "Do you really want to delete %s forever? "
8948                            (if (> (length articles) 1)
8949                                (format "these %s articles" (length articles))
8950                              "this article")))))
8951         ()
8952       ;; Delete the articles.
8953       (setq not-deleted (gnus-request-expire-articles
8954                          articles gnus-newsgroup-name 'force))
8955       (while articles
8956         (gnus-summary-remove-process-mark (car articles))
8957         ;; The backend might not have been able to delete the article
8958         ;; after all.
8959         (unless (memq (car articles) not-deleted)
8960           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8961         (setq articles (cdr articles)))
8962       (when not-deleted
8963         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8964     (gnus-summary-position-point)
8965     (gnus-set-mode-line 'summary)
8966     not-deleted))
8967
8968 (defun gnus-summary-edit-article (&optional force)
8969   "Edit the current article.
8970 This will have permanent effect only in mail groups.
8971 If FORCE is non-nil, allow editing of articles even in read-only
8972 groups."
8973   (interactive "P")
8974   (save-excursion
8975     (set-buffer gnus-summary-buffer)
8976     (let ((mail-parse-charset gnus-newsgroup-charset)
8977           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8978       (gnus-set-global-variables)
8979       (when (and (not force)
8980                  (gnus-group-read-only-p))
8981         (error "The current newsgroup does not support article editing"))
8982       (gnus-summary-show-article t)
8983       (gnus-article-edit-article
8984        'ignore
8985        `(lambda (no-highlight)
8986           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8987                 (message-options message-options)
8988                 (message-options-set-recipient)
8989                 (mail-parse-ignored-charsets
8990                  ',gnus-newsgroup-ignored-charsets))
8991             (gnus-summary-edit-article-done
8992              ,(or (mail-header-references gnus-current-headers) "")
8993              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8994
8995 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8996
8997 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8998                                                  no-highlight)
8999   "Make edits to the current article permanent."
9000   (interactive)
9001   (save-excursion
9002     ;; The buffer restriction contains the entire article if it exists.
9003     (when (article-goto-body)
9004       (let ((lines (count-lines (point) (point-max)))
9005             (length (- (point-max) (point)))
9006             (case-fold-search t)
9007             (body (copy-marker (point))))
9008         (goto-char (point-min))
9009         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9010           (delete-region (match-beginning 1) (match-end 1))
9011           (insert (number-to-string length)))
9012         (goto-char (point-min))
9013         (when (re-search-forward
9014                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9015           (delete-region (match-beginning 1) (match-end 1))
9016           (insert (number-to-string length)))
9017         (goto-char (point-min))
9018         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9019           (delete-region (match-beginning 1) (match-end 1))
9020           (insert (number-to-string lines))))))
9021   ;; Replace the article.
9022   (let ((buf (current-buffer)))
9023     (with-temp-buffer
9024       (insert-buffer-substring buf)
9025
9026       (if (and (not read-only)
9027                (not (gnus-request-replace-article
9028                      (cdr gnus-article-current) (car gnus-article-current)
9029                      (current-buffer) t)))
9030           (error "Couldn't replace article")
9031         ;; Update the summary buffer.
9032         (if (and references
9033                  (equal (message-tokenize-header references " ")
9034                         (message-tokenize-header
9035                          (or (message-fetch-field "references") "") " ")))
9036             ;; We only have to update this line.
9037             (save-excursion
9038               (save-restriction
9039                 (message-narrow-to-head)
9040                 (let ((head (buffer-string))
9041                       header)
9042                   (with-temp-buffer
9043                     (insert (format "211 %d Article retrieved.\n"
9044                                     (cdr gnus-article-current)))
9045                     (insert head)
9046                     (insert ".\n")
9047                     (let ((nntp-server-buffer (current-buffer)))
9048                       (setq header (car (gnus-get-newsgroup-headers
9049                                          nil t))))
9050                     (save-excursion
9051                       (set-buffer gnus-summary-buffer)
9052                       (gnus-data-set-header
9053                        (gnus-data-find (cdr gnus-article-current))
9054                        header)
9055                       (gnus-summary-update-article-line
9056                        (cdr gnus-article-current) header)
9057                       (if (gnus-summary-goto-subject
9058                            (cdr gnus-article-current) nil t)
9059                           (gnus-summary-update-secondary-mark
9060                            (cdr gnus-article-current))))))))
9061           ;; Update threads.
9062           (set-buffer (or buffer gnus-summary-buffer))
9063           (gnus-summary-update-article (cdr gnus-article-current))
9064           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9065               (gnus-summary-update-secondary-mark
9066                (cdr gnus-article-current))))
9067         ;; Prettify the article buffer again.
9068         (unless no-highlight
9069           (save-excursion
9070             (set-buffer gnus-article-buffer)
9071             ;;;!!! Fix this -- article should be rehighlighted.
9072             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9073             (set-buffer gnus-original-article-buffer)
9074             (gnus-request-article
9075              (cdr gnus-article-current)
9076              (car gnus-article-current) (current-buffer))))
9077         ;; Prettify the summary buffer line.
9078         (when (gnus-visual-p 'summary-highlight 'highlight)
9079           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9080
9081 (defun gnus-summary-edit-wash (key)
9082   "Perform editing command KEY in the article buffer."
9083   (interactive
9084    (list
9085     (progn
9086       (message "%s" (concat (this-command-keys) "- "))
9087       (read-char))))
9088   (message "")
9089   (gnus-summary-edit-article)
9090   (execute-kbd-macro (concat (this-command-keys) key))
9091   (gnus-article-edit-done))
9092
9093 ;;; Respooling
9094
9095 (defun gnus-summary-respool-query (&optional silent trace)
9096   "Query where the respool algorithm would put this article."
9097   (interactive)
9098   (let (gnus-mark-article-hook)
9099     (gnus-summary-select-article)
9100     (save-excursion
9101       (set-buffer gnus-original-article-buffer)
9102       (save-restriction
9103         (message-narrow-to-head)
9104         (let ((groups (nnmail-article-group 'identity trace)))
9105           (unless silent
9106             (if groups
9107                 (message "This message would go to %s"
9108                          (mapconcat 'car groups ", "))
9109               (message "This message would go to no groups"))
9110             groups))))))
9111
9112 (defun gnus-summary-respool-trace ()
9113   "Trace where the respool algorithm would put this article.
9114 Display a buffer showing all fancy splitting patterns which matched."
9115   (interactive)
9116   (gnus-summary-respool-query nil t))
9117
9118 ;; Summary marking commands.
9119
9120 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9121   "Mark articles which has the same subject as read, and then select the next.
9122 If UNMARK is positive, remove any kind of mark.
9123 If UNMARK is negative, tick articles."
9124   (interactive "P")
9125   (when unmark
9126     (setq unmark (prefix-numeric-value unmark)))
9127   (let ((count
9128          (gnus-summary-mark-same-subject
9129           (gnus-summary-article-subject) unmark)))
9130     ;; Select next unread article.  If auto-select-same mode, should
9131     ;; select the first unread article.
9132     (gnus-summary-next-article t (and gnus-auto-select-same
9133                                       (gnus-summary-article-subject)))
9134     (gnus-message 7 "%d article%s marked as %s"
9135                   count (if (= count 1) " is" "s are")
9136                   (if unmark "unread" "read"))))
9137
9138 (defun gnus-summary-kill-same-subject (&optional unmark)
9139   "Mark articles which has the same subject as read.
9140 If UNMARK is positive, remove any kind of mark.
9141 If UNMARK is negative, tick articles."
9142   (interactive "P")
9143   (when unmark
9144     (setq unmark (prefix-numeric-value unmark)))
9145   (let ((count
9146          (gnus-summary-mark-same-subject
9147           (gnus-summary-article-subject) unmark)))
9148     ;; If marked as read, go to next unread subject.
9149     (when (null unmark)
9150       ;; Go to next unread subject.
9151       (gnus-summary-next-subject 1 t))
9152     (gnus-message 7 "%d articles are marked as %s"
9153                   count (if unmark "unread" "read"))))
9154
9155 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9156   "Mark articles with same SUBJECT as read, and return marked number.
9157 If optional argument UNMARK is positive, remove any kinds of marks.
9158 If optional argument UNMARK is negative, mark articles as unread instead."
9159   (let ((count 1))
9160     (save-excursion
9161       (cond
9162        ((null unmark)                   ; Mark as read.
9163         (while (and
9164                 (progn
9165                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9166                   (gnus-summary-show-thread) t)
9167                 (gnus-summary-find-subject subject))
9168           (setq count (1+ count))))
9169        ((> unmark 0)                    ; Tick.
9170         (while (and
9171                 (progn
9172                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9173                   (gnus-summary-show-thread) t)
9174                 (gnus-summary-find-subject subject))
9175           (setq count (1+ count))))
9176        (t                               ; Mark as unread.
9177         (while (and
9178                 (progn
9179                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9180                   (gnus-summary-show-thread) t)
9181                 (gnus-summary-find-subject subject))
9182           (setq count (1+ count)))))
9183       (gnus-set-mode-line 'summary)
9184       ;; Return the number of marked articles.
9185       count)))
9186
9187 (defun gnus-summary-mark-as-processable (n &optional unmark)
9188   "Set the process mark on the next N articles.
9189 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9190 the process mark instead.  The difference between N and the actual
9191 number of articles marked is returned."
9192   (interactive "P")
9193   (if (and (null n) (gnus-region-active-p))
9194       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9195     (setq n (prefix-numeric-value n))
9196     (let ((backward (< n 0))
9197           (n (abs n)))
9198       (while (and
9199               (> n 0)
9200               (if unmark
9201                   (gnus-summary-remove-process-mark
9202                    (gnus-summary-article-number))
9203                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9204               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9205         (setq n (1- n)))
9206       (when (/= 0 n)
9207         (gnus-message 7 "No more articles"))
9208       (gnus-summary-recenter)
9209       (gnus-summary-position-point)
9210       n)))
9211
9212 (defun gnus-summary-unmark-as-processable (n)
9213   "Remove the process mark from the next N articles.
9214 If N is negative, unmark backward instead.  The difference between N and
9215 the actual number of articles unmarked is returned."
9216   (interactive "P")
9217   (gnus-summary-mark-as-processable n t))
9218
9219 (defun gnus-summary-unmark-all-processable ()
9220   "Remove the process mark from all articles."
9221   (interactive)
9222   (save-excursion
9223     (while gnus-newsgroup-processable
9224       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9225   (gnus-summary-position-point))
9226
9227 (defun gnus-summary-add-mark (article type)
9228   "Mark ARTICLE with a mark of TYPE."
9229   (let ((vtype (car (assq type gnus-article-mark-lists)))
9230         var)
9231     (if (not vtype)
9232         (error "No such mark type: %s" type)
9233       (setq var (intern (format "gnus-newsgroup-%s" type)))
9234       (set var (cons article (symbol-value var)))
9235       (if (memq type '(processable cached replied forwarded recent saved))
9236           (gnus-summary-update-secondary-mark article)
9237         ;;; !!! This is bogus.  We should find out what primary
9238         ;;; !!! mark we want to set.
9239         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9240
9241 (defun gnus-summary-mark-as-expirable (n)
9242   "Mark N articles forward as expirable.
9243 If N is negative, mark backward instead.  The difference between N and
9244 the actual number of articles marked is returned."
9245   (interactive "p")
9246   (gnus-summary-mark-forward n gnus-expirable-mark))
9247
9248 (defun gnus-summary-mark-article-as-replied (article)
9249   "Mark ARTICLE as replied to and update the summary line.
9250 ARTICLE can also be a list of articles."
9251   (interactive (list (gnus-summary-article-number)))
9252   (let ((articles (if (listp article) article (list article))))
9253     (dolist (article articles)
9254       (push article gnus-newsgroup-replied)
9255       (let ((buffer-read-only nil))
9256         (when (gnus-summary-goto-subject article nil t)
9257           (gnus-summary-update-secondary-mark article))))))
9258
9259 (defun gnus-summary-mark-article-as-forwarded (article)
9260   "Mark ARTICLE as forwarded and update the summary line.
9261 ARTICLE can also be a list of articles."
9262   (let ((articles (if (listp article) article (list article))))
9263     (dolist (article articles)
9264       (push article gnus-newsgroup-forwarded)
9265       (let ((buffer-read-only nil))
9266         (when (gnus-summary-goto-subject article nil t)
9267           (gnus-summary-update-secondary-mark article))))))
9268
9269 (defun gnus-summary-set-bookmark (article)
9270   "Set a bookmark in current article."
9271   (interactive (list (gnus-summary-article-number)))
9272   (when (or (not (get-buffer gnus-article-buffer))
9273             (not gnus-current-article)
9274             (not gnus-article-current)
9275             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9276     (error "No current article selected"))
9277   ;; Remove old bookmark, if one exists.
9278   (let ((old (assq article gnus-newsgroup-bookmarks)))
9279     (when old
9280       (setq gnus-newsgroup-bookmarks
9281             (delq old gnus-newsgroup-bookmarks))))
9282   ;; Set the new bookmark, which is on the form
9283   ;; (article-number . line-number-in-body).
9284   (push
9285    (cons article
9286          (save-excursion
9287            (set-buffer gnus-article-buffer)
9288            (count-lines
9289             (min (point)
9290                  (save-excursion
9291                    (goto-char (point-min))
9292                    (search-forward "\n\n" nil t)
9293                    (point)))
9294             (point))))
9295    gnus-newsgroup-bookmarks)
9296   (gnus-message 6 "A bookmark has been added to the current article."))
9297
9298 (defun gnus-summary-remove-bookmark (article)
9299   "Remove the bookmark from the current article."
9300   (interactive (list (gnus-summary-article-number)))
9301   ;; Remove old bookmark, if one exists.
9302   (let ((old (assq article gnus-newsgroup-bookmarks)))
9303     (if old
9304         (progn
9305           (setq gnus-newsgroup-bookmarks
9306                 (delq old gnus-newsgroup-bookmarks))
9307           (gnus-message 6 "Removed bookmark."))
9308       (gnus-message 6 "No bookmark in current article."))))
9309
9310 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9311 (defun gnus-summary-mark-as-dormant (n)
9312   "Mark N articles forward as dormant.
9313 If N is negative, mark backward instead.  The difference between N and
9314 the actual number of articles marked is returned."
9315   (interactive "p")
9316   (gnus-summary-mark-forward n gnus-dormant-mark))
9317
9318 (defun gnus-summary-set-process-mark (article)
9319   "Set the process mark on ARTICLE and update the summary line."
9320   (setq gnus-newsgroup-processable
9321         (cons article
9322               (delq article gnus-newsgroup-processable)))
9323   (when (gnus-summary-goto-subject article)
9324     (gnus-summary-show-thread)
9325     (gnus-summary-goto-subject article)
9326     (gnus-summary-update-secondary-mark article)))
9327
9328 (defun gnus-summary-remove-process-mark (article)
9329   "Remove the process mark from ARTICLE and update the summary line."
9330   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9331   (when (gnus-summary-goto-subject article)
9332     (gnus-summary-show-thread)
9333     (gnus-summary-goto-subject article)
9334     (gnus-summary-update-secondary-mark article)))
9335
9336 (defun gnus-summary-set-saved-mark (article)
9337   "Set the process mark on ARTICLE and update the summary line."
9338   (push article gnus-newsgroup-saved)
9339   (when (gnus-summary-goto-subject article)
9340     (gnus-summary-update-secondary-mark article)))
9341
9342 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9343   "Mark N articles as read forwards.
9344 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9345 The difference between N and the actual number of articles marked is
9346 returned.
9347 Iff NO-EXPIRE, auto-expiry will be inhibited."
9348   (interactive "p")
9349   (gnus-summary-show-thread)
9350   (let ((backward (< n 0))
9351         (gnus-summary-goto-unread
9352          (and gnus-summary-goto-unread
9353               (not (eq gnus-summary-goto-unread 'never))
9354               (not (memq mark (list gnus-unread-mark
9355                                     gnus-ticked-mark gnus-dormant-mark)))))
9356         (n (abs n))
9357         (mark (or mark gnus-del-mark)))
9358     (while (and (> n 0)
9359                 (gnus-summary-mark-article nil mark no-expire)
9360                 (zerop (gnus-summary-next-subject
9361                         (if backward -1 1)
9362                         (and gnus-summary-goto-unread
9363                              (not (eq gnus-summary-goto-unread 'never)))
9364                         t)))
9365       (setq n (1- n)))
9366     (when (/= 0 n)
9367       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9368     (gnus-summary-recenter)
9369     (gnus-summary-position-point)
9370     (gnus-set-mode-line 'summary)
9371     n))
9372
9373 (defun gnus-summary-mark-article-as-read (mark)
9374   "Mark the current article quickly as read with MARK."
9375   (let ((article (gnus-summary-article-number)))
9376     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9377     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9378     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9379     (push (cons article mark) gnus-newsgroup-reads)
9380     ;; Possibly remove from cache, if that is used.
9381     (when gnus-use-cache
9382       (gnus-cache-enter-remove-article article))
9383     ;; Allow the backend to change the mark.
9384     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9385     ;; Check for auto-expiry.
9386     (when (and gnus-newsgroup-auto-expire
9387                (memq mark gnus-auto-expirable-marks))
9388       (setq mark gnus-expirable-mark)
9389       ;; Let the backend know about the mark change.
9390       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9391       (push article gnus-newsgroup-expirable))
9392     ;; Set the mark in the buffer.
9393     (gnus-summary-update-mark mark 'unread)
9394     t))
9395
9396 (defun gnus-summary-mark-article-as-unread (mark)
9397   "Mark the current article quickly as unread with MARK."
9398   (let* ((article (gnus-summary-article-number))
9399          (old-mark (gnus-summary-article-mark article)))
9400     ;; Allow the backend to change the mark.
9401     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9402     (if (eq mark old-mark)
9403         t
9404       (if (<= article 0)
9405           (progn
9406             (gnus-error 1 "Can't mark negative article numbers")
9407             nil)
9408         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9409         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9410         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9411         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9412         (cond ((= mark gnus-ticked-mark)
9413                (setq gnus-newsgroup-marked
9414                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9415                                               article)))
9416               ((= mark gnus-dormant-mark)
9417                (setq gnus-newsgroup-dormant
9418                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9419                                               article)))
9420               (t
9421                (setq gnus-newsgroup-unreads
9422                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9423                                               article))))
9424         (gnus-pull article gnus-newsgroup-reads)
9425
9426         ;; See whether the article is to be put in the cache.
9427         (and gnus-use-cache
9428              (vectorp (gnus-summary-article-header article))
9429              (save-excursion
9430                (gnus-cache-possibly-enter-article
9431                 gnus-newsgroup-name article
9432                 (gnus-summary-article-header article)
9433                 (= mark gnus-ticked-mark)
9434                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9435
9436         ;; Fix the mark.
9437         (gnus-summary-update-mark mark 'unread)
9438         t))))
9439
9440 (defun gnus-summary-mark-article (&optional article mark no-expire)
9441   "Mark ARTICLE with MARK.  MARK can be any character.
9442 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9443 `??' (dormant) and `?E' (expirable).
9444 If MARK is nil, then the default character `?r' is used.
9445 If ARTICLE is nil, then the article on the current line will be
9446 marked.
9447 Iff NO-EXPIRE, auto-expiry will be inhibited."
9448   ;; The mark might be a string.
9449   (when (stringp mark)
9450     (setq mark (aref mark 0)))
9451   ;; If no mark is given, then we check auto-expiring.
9452   (when (null mark)
9453     (setq mark gnus-del-mark))
9454   (when (and (not no-expire)
9455              gnus-newsgroup-auto-expire
9456              (memq mark gnus-auto-expirable-marks))
9457     (setq mark gnus-expirable-mark))
9458   (let ((article (or article (gnus-summary-article-number)))
9459         (old-mark (gnus-summary-article-mark article)))
9460     ;; Allow the backend to change the mark.
9461     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9462     (if (eq mark old-mark)
9463         t
9464       (unless article
9465         (error "No article on current line"))
9466       (if (not (if (or (= mark gnus-unread-mark)
9467                        (= mark gnus-ticked-mark)
9468                        (= mark gnus-dormant-mark))
9469                    (gnus-mark-article-as-unread article mark)
9470                  (gnus-mark-article-as-read article mark)))
9471           t
9472         ;; See whether the article is to be put in the cache.
9473         (and gnus-use-cache
9474              (not (= mark gnus-canceled-mark))
9475              (vectorp (gnus-summary-article-header article))
9476              (save-excursion
9477                (gnus-cache-possibly-enter-article
9478                 gnus-newsgroup-name article
9479                 (gnus-summary-article-header article)
9480                 (= mark gnus-ticked-mark)
9481                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9482
9483         (when (gnus-summary-goto-subject article nil t)
9484           (let ((buffer-read-only nil))
9485             (gnus-summary-show-thread)
9486             ;; Fix the mark.
9487             (gnus-summary-update-mark mark 'unread)
9488             t))))))
9489
9490 (defun gnus-summary-update-secondary-mark (article)
9491   "Update the secondary (read, process, cache) mark."
9492   (gnus-summary-update-mark
9493    (cond ((memq article gnus-newsgroup-processable)
9494           gnus-process-mark)
9495          ((memq article gnus-newsgroup-cached)
9496           gnus-cached-mark)
9497          ((memq article gnus-newsgroup-replied)
9498           gnus-replied-mark)
9499          ((memq article gnus-newsgroup-forwarded)
9500           gnus-forwarded-mark)
9501          ((memq article gnus-newsgroup-saved)
9502           gnus-saved-mark)
9503          ((memq article gnus-newsgroup-recent)
9504           gnus-recent-mark)
9505          ((memq article gnus-newsgroup-unseen)
9506           gnus-unseen-mark)
9507          (t gnus-no-mark))
9508    'replied)
9509   (when (gnus-visual-p 'summary-highlight 'highlight)
9510     (gnus-run-hooks 'gnus-summary-update-hook))
9511   t)
9512
9513 (defun gnus-summary-update-mark (mark type)
9514   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9515         (buffer-read-only nil))
9516     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9517     (when forward
9518       (when (looking-at "\r")
9519         (incf forward))
9520       (when (<= (+ forward (point)) (point-max))
9521         ;; Go to the right position on the line.
9522         (goto-char (+ forward (point)))
9523         ;; Replace the old mark with the new mark.
9524         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9525         ;; Optionally update the marks by some user rule.
9526         (when (eq type 'unread)
9527           (gnus-data-set-mark
9528            (gnus-data-find (gnus-summary-article-number)) mark)
9529           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9530
9531 (defun gnus-mark-article-as-read (article &optional mark)
9532   "Enter ARTICLE in the pertinent lists and remove it from others."
9533   ;; Make the article expirable.
9534   (let ((mark (or mark gnus-del-mark)))
9535     (setq gnus-newsgroup-expirable
9536           (if (= mark gnus-expirable-mark)
9537               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9538             (delq article gnus-newsgroup-expirable)))
9539     ;; Remove from unread and marked lists.
9540     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9541     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9542     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9543     (push (cons article mark) gnus-newsgroup-reads)
9544     ;; Possibly remove from cache, if that is used.
9545     (when gnus-use-cache
9546       (gnus-cache-enter-remove-article article))
9547     t))
9548
9549 (defun gnus-mark-article-as-unread (article &optional mark)
9550   "Enter ARTICLE in the pertinent lists and remove it from others."
9551   (let ((mark (or mark gnus-ticked-mark)))
9552     (if (<= article 0)
9553         (progn
9554           (gnus-error 1 "Can't mark negative article numbers")
9555           nil)
9556       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9557             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9558             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9559             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9560
9561       ;; Unsuppress duplicates?
9562       (when gnus-suppress-duplicates
9563         (gnus-dup-unsuppress-article article))
9564
9565       (cond ((= mark gnus-ticked-mark)
9566              (setq gnus-newsgroup-marked
9567                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9568             ((= mark gnus-dormant-mark)
9569              (setq gnus-newsgroup-dormant
9570                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9571             (t
9572              (setq gnus-newsgroup-unreads
9573                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9574       (gnus-pull article gnus-newsgroup-reads)
9575       t)))
9576
9577 (defalias 'gnus-summary-mark-as-unread-forward
9578   'gnus-summary-tick-article-forward)
9579 (make-obsolete 'gnus-summary-mark-as-unread-forward
9580                'gnus-summary-tick-article-forward)
9581 (defun gnus-summary-tick-article-forward (n)
9582   "Tick N articles forwards.
9583 If N is negative, tick backwards instead.
9584 The difference between N and the number of articles ticked is returned."
9585   (interactive "p")
9586   (gnus-summary-mark-forward n gnus-ticked-mark))
9587
9588 (defalias 'gnus-summary-mark-as-unread-backward
9589   'gnus-summary-tick-article-backward)
9590 (make-obsolete 'gnus-summary-mark-as-unread-backward
9591                'gnus-summary-tick-article-backward)
9592 (defun gnus-summary-tick-article-backward (n)
9593   "Tick N articles backwards.
9594 The difference between N and the number of articles ticked is returned."
9595   (interactive "p")
9596   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9597
9598 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9599 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9600 (defun gnus-summary-tick-article (&optional article clear-mark)
9601   "Mark current article as unread.
9602 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9603 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9604   (interactive)
9605   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9606                                        gnus-ticked-mark)))
9607
9608 (defun gnus-summary-mark-as-read-forward (n)
9609   "Mark N articles as read forwards.
9610 If N is negative, mark backwards instead.
9611 The difference between N and the actual number of articles marked is
9612 returned."
9613   (interactive "p")
9614   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9615
9616 (defun gnus-summary-mark-as-read-backward (n)
9617   "Mark the N articles as read backwards.
9618 The difference between N and the actual number of articles marked is
9619 returned."
9620   (interactive "p")
9621   (gnus-summary-mark-forward
9622    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9623
9624 (defun gnus-summary-mark-as-read (&optional article mark)
9625   "Mark current article as read.
9626 ARTICLE specifies the article to be marked as read.
9627 MARK specifies a string to be inserted at the beginning of the line."
9628   (gnus-summary-mark-article article mark))
9629
9630 (defun gnus-summary-clear-mark-forward (n)
9631   "Clear marks from N articles forward.
9632 If N is negative, clear backward instead.
9633 The difference between N and the number of marks cleared is returned."
9634   (interactive "p")
9635   (gnus-summary-mark-forward n gnus-unread-mark))
9636
9637 (defun gnus-summary-clear-mark-backward (n)
9638   "Clear marks from N articles backward.
9639 The difference between N and the number of marks cleared is returned."
9640   (interactive "p")
9641   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9642
9643 (defun gnus-summary-mark-unread-as-read ()
9644   "Intended to be used by `gnus-summary-mark-article-hook'."
9645   (when (memq gnus-current-article gnus-newsgroup-unreads)
9646     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9647
9648 (defun gnus-summary-mark-read-and-unread-as-read ()
9649   "Intended to be used by `gnus-summary-mark-article-hook'."
9650   (let ((mark (gnus-summary-article-mark)))
9651     (when (or (gnus-unread-mark-p mark)
9652               (gnus-read-mark-p mark))
9653       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9654
9655 (defun gnus-summary-mark-unread-as-ticked ()
9656   "Intended to be used by `gnus-summary-mark-article-hook'."
9657   (when (memq gnus-current-article gnus-newsgroup-unreads)
9658     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9659
9660 (defun gnus-summary-mark-region-as-read (point mark all)
9661   "Mark all unread articles between point and mark as read.
9662 If given a prefix, mark all articles between point and mark as read,
9663 even ticked and dormant ones."
9664   (interactive "r\nP")
9665   (save-excursion
9666     (let (article)
9667       (goto-char point)
9668       (beginning-of-line)
9669       (while (and
9670               (< (point) mark)
9671               (progn
9672                 (when (or all
9673                           (memq (setq article (gnus-summary-article-number))
9674                                 gnus-newsgroup-unreads))
9675                   (gnus-summary-mark-article article gnus-del-mark))
9676                 t)
9677               (gnus-summary-find-next))))))
9678
9679 (defun gnus-summary-mark-below (score mark)
9680   "Mark articles with score less than SCORE with MARK."
9681   (interactive "P\ncMark: ")
9682   (setq score (if score
9683                   (prefix-numeric-value score)
9684                 (or gnus-summary-default-score 0)))
9685   (save-excursion
9686     (set-buffer gnus-summary-buffer)
9687     (goto-char (point-min))
9688     (while
9689         (progn
9690           (and (< (gnus-summary-article-score) score)
9691                (gnus-summary-mark-article nil mark))
9692           (gnus-summary-find-next)))))
9693
9694 (defun gnus-summary-kill-below (&optional score)
9695   "Mark articles with score below SCORE as read."
9696   (interactive "P")
9697   (gnus-summary-mark-below score gnus-killed-mark))
9698
9699 (defun gnus-summary-clear-above (&optional score)
9700   "Clear all marks from articles with score above SCORE."
9701   (interactive "P")
9702   (gnus-summary-mark-above score gnus-unread-mark))
9703
9704 (defun gnus-summary-tick-above (&optional score)
9705   "Tick all articles with score above SCORE."
9706   (interactive "P")
9707   (gnus-summary-mark-above score gnus-ticked-mark))
9708
9709 (defun gnus-summary-mark-above (score mark)
9710   "Mark articles with score over SCORE with MARK."
9711   (interactive "P\ncMark: ")
9712   (setq score (if score
9713                   (prefix-numeric-value score)
9714                 (or gnus-summary-default-score 0)))
9715   (save-excursion
9716     (set-buffer gnus-summary-buffer)
9717     (goto-char (point-min))
9718     (while (and (progn
9719                   (when (> (gnus-summary-article-score) score)
9720                     (gnus-summary-mark-article nil mark))
9721                   t)
9722                 (gnus-summary-find-next)))))
9723
9724 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9725 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9726 (defun gnus-summary-limit-include-expunged (&optional no-error)
9727   "Display all the hidden articles that were expunged for low scores."
9728   (interactive)
9729   (let ((buffer-read-only nil))
9730     (let ((scored gnus-newsgroup-scored)
9731           headers h)
9732       (while scored
9733         (unless (gnus-summary-article-header (caar scored))
9734           (and (setq h (gnus-number-to-header (caar scored)))
9735                (< (cdar scored) gnus-summary-expunge-below)
9736                (push h headers)))
9737         (setq scored (cdr scored)))
9738       (if (not headers)
9739           (when (not no-error)
9740             (error "No expunged articles hidden"))
9741         (goto-char (point-min))
9742         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9743         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9744         (mapcar (lambda (x) (push (mail-header-number x)
9745                                   gnus-newsgroup-limit))
9746                 headers)
9747         (gnus-summary-prepare-unthreaded (nreverse headers))
9748         (goto-char (point-min))
9749         (gnus-summary-position-point)
9750         t))))
9751
9752 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9753   "Mark all unread articles in this newsgroup as read.
9754 If prefix argument ALL is non-nil, ticked and dormant articles will
9755 also be marked as read.
9756 If QUIETLY is non-nil, no questions will be asked.
9757 If TO-HERE is non-nil, it should be a point in the buffer.  All
9758 articles before (after, if REVERSE is set) this point will be marked as read.
9759 Note that this function will only catch up the unread article
9760 in the current summary buffer limitation.
9761 The number of articles marked as read is returned."
9762   (interactive "P")
9763   (prog1
9764       (save-excursion
9765         (when (or quietly
9766                   (not gnus-interactive-catchup) ;Without confirmation?
9767                   gnus-expert-user
9768                   (gnus-y-or-n-p
9769                    (if all
9770                        "Mark absolutely all articles as read? "
9771                      "Mark all unread articles as read? ")))
9772           (if (and not-mark
9773                    (not gnus-newsgroup-adaptive)
9774                    (not gnus-newsgroup-auto-expire)
9775                    (not gnus-suppress-duplicates)
9776                    (or (not gnus-use-cache)
9777                        (eq gnus-use-cache 'passive)))
9778               (progn
9779                 (when all
9780                   (setq gnus-newsgroup-marked nil
9781                         gnus-newsgroup-dormant nil))
9782                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9783             ;; We actually mark all articles as canceled, which we
9784             ;; have to do when using auto-expiry or adaptive scoring.
9785             (gnus-summary-show-all-threads)
9786             (if (and to-here reverse)
9787                 (progn
9788                   (goto-char to-here)
9789                   (while (and
9790                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9791                           (gnus-summary-find-next (not all) nil nil t))))
9792               (when (gnus-summary-first-subject (not all) t)
9793                 (while (and
9794                         (if to-here (< (point) to-here) t)
9795                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9796                         (gnus-summary-find-next (not all) nil nil t)))))
9797             (gnus-set-mode-line 'summary))
9798           t))
9799     (gnus-summary-position-point)))
9800
9801 (defun gnus-summary-catchup-to-here (&optional all)
9802   "Mark all unticked articles before the current one as read.
9803 If ALL is non-nil, also mark ticked and dormant articles as read."
9804   (interactive "P")
9805   (save-excursion
9806     (gnus-save-hidden-threads
9807       (let ((beg (point)))
9808         ;; We check that there are unread articles.
9809         (when (or all (gnus-summary-find-prev))
9810           (gnus-summary-catchup all t beg)))))
9811   (gnus-summary-position-point))
9812
9813 (defun gnus-summary-catchup-from-here (&optional all)
9814   "Mark all unticked articles after the current one as read.
9815 If ALL is non-nil, also mark ticked and dormant articles as read."
9816   (interactive "P")
9817   (save-excursion
9818     (gnus-save-hidden-threads
9819       (let ((beg (point)))
9820         ;; We check that there are unread articles.
9821         (when (or all (gnus-summary-find-next))
9822           (gnus-summary-catchup all t beg nil t)))))
9823   (gnus-summary-position-point))
9824
9825 (defun gnus-summary-catchup-all (&optional quietly)
9826   "Mark all articles in this newsgroup as read."
9827   (interactive "P")
9828   (gnus-summary-catchup t quietly))
9829
9830 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9831   "Mark all unread articles in this group as read, then exit.
9832 If prefix argument ALL is non-nil, all articles are marked as read.
9833 If QUIETLY is non-nil, no questions will be asked."
9834   (interactive "P")
9835   (when (gnus-summary-catchup all quietly nil 'fast)
9836     ;; Select next newsgroup or exit.
9837     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9838              (eq gnus-auto-select-next 'quietly))
9839         (gnus-summary-next-group nil)
9840       (gnus-summary-exit))))
9841
9842 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9843   "Mark all articles in this newsgroup as read, and then exit."
9844   (interactive "P")
9845   (gnus-summary-catchup-and-exit t quietly))
9846
9847 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9848   "Mark all articles in this group as read and select the next group.
9849 If given a prefix, mark all articles, unread as well as ticked, as
9850 read."
9851   (interactive "P")
9852   (save-excursion
9853     (gnus-summary-catchup all))
9854   (gnus-summary-next-group))
9855
9856 ;;;
9857 ;;; with article
9858 ;;;
9859
9860 (defmacro gnus-with-article (article &rest forms)
9861   "Select ARTICLE and perform FORMS in the original article buffer.
9862 Then replace the article with the result."
9863   `(progn
9864      ;; We don't want the article to be marked as read.
9865      (let (gnus-mark-article-hook)
9866        (gnus-summary-select-article t t nil ,article))
9867      (set-buffer gnus-original-article-buffer)
9868      ,@forms
9869      (if (not (gnus-check-backend-function
9870                'request-replace-article (car gnus-article-current)))
9871          (gnus-message 5 "Read-only group; not replacing")
9872        (unless (gnus-request-replace-article
9873                 ,article (car gnus-article-current)
9874                 (current-buffer) t)
9875          (error "Couldn't replace article")))
9876      ;; The cache and backlog have to be flushed somewhat.
9877      (when gnus-keep-backlog
9878        (gnus-backlog-remove-article
9879         (car gnus-article-current) (cdr gnus-article-current)))
9880      (when gnus-use-cache
9881        (gnus-cache-update-article
9882         (car gnus-article-current) (cdr gnus-article-current)))))
9883
9884 (put 'gnus-with-article 'lisp-indent-function 1)
9885 (put 'gnus-with-article 'edebug-form-spec '(form body))
9886
9887 ;; Thread-based commands.
9888
9889 (defun gnus-summary-articles-in-thread (&optional article)
9890   "Return a list of all articles in the current thread.
9891 If ARTICLE is non-nil, return all articles in the thread that starts
9892 with that article."
9893   (let* ((article (or article (gnus-summary-article-number)))
9894          (data (gnus-data-find-list article))
9895          (top-level (gnus-data-level (car data)))
9896          (top-subject
9897           (cond ((null gnus-thread-operation-ignore-subject)
9898                  (gnus-simplify-subject-re
9899                   (mail-header-subject (gnus-data-header (car data)))))
9900                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9901                  (gnus-simplify-subject-fuzzy
9902                   (mail-header-subject (gnus-data-header (car data)))))
9903                 (t nil)))
9904          (end-point (save-excursion
9905                       (if (gnus-summary-go-to-next-thread)
9906                           (point) (point-max))))
9907          articles)
9908     (while (and data
9909                 (< (gnus-data-pos (car data)) end-point))
9910       (when (or (not top-subject)
9911                 (string= top-subject
9912                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9913                              (gnus-simplify-subject-fuzzy
9914                               (mail-header-subject
9915                                (gnus-data-header (car data))))
9916                            (gnus-simplify-subject-re
9917                             (mail-header-subject
9918                              (gnus-data-header (car data)))))))
9919         (push (gnus-data-number (car data)) articles))
9920       (unless (and (setq data (cdr data))
9921                    (> (gnus-data-level (car data)) top-level))
9922         (setq data nil)))
9923     ;; Return the list of articles.
9924     (nreverse articles)))
9925
9926 (defun gnus-summary-rethread-current ()
9927   "Rethread the thread the current article is part of."
9928   (interactive)
9929   (let* ((gnus-show-threads t)
9930          (article (gnus-summary-article-number))
9931          (id (mail-header-id (gnus-summary-article-header)))
9932          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9933     (unless id
9934       (error "No article on the current line"))
9935     (gnus-rebuild-thread id)
9936     (gnus-summary-goto-subject article)))
9937
9938 (defun gnus-summary-reparent-thread ()
9939   "Make the current article child of the marked (or previous) article.
9940
9941 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9942 is non-nil or the Subject: of both articles are the same."
9943   (interactive)
9944   (unless (not (gnus-group-read-only-p))
9945     (error "The current newsgroup does not support article editing"))
9946   (unless (<= (length gnus-newsgroup-processable) 1)
9947     (error "No more than one article may be marked"))
9948   (save-window-excursion
9949     (let ((gnus-article-buffer " *reparent*")
9950           (current-article (gnus-summary-article-number))
9951           ;; First grab the marked article, otherwise one line up.
9952           (parent-article (if (not (null gnus-newsgroup-processable))
9953                               (car gnus-newsgroup-processable)
9954                             (save-excursion
9955                               (if (eq (forward-line -1) 0)
9956                                   (gnus-summary-article-number)
9957                                 (error "Beginning of summary buffer"))))))
9958       (unless (not (eq current-article parent-article))
9959         (error "An article may not be self-referential"))
9960       (let ((message-id (mail-header-id
9961                          (gnus-summary-article-header parent-article))))
9962         (unless (and message-id (not (equal message-id "")))
9963           (error "No message-id in desired parent"))
9964         (gnus-with-article current-article
9965           (save-restriction
9966             (goto-char (point-min))
9967             (message-narrow-to-head)
9968             (if (re-search-forward "^References: " nil t)
9969                 (progn
9970                   (re-search-forward "^[^ \t]" nil t)
9971                   (forward-line -1)
9972                   (end-of-line)
9973                   (insert " " message-id))
9974               (insert "References: " message-id "\n"))))
9975         (set-buffer gnus-summary-buffer)
9976         (gnus-summary-unmark-all-processable)
9977         (gnus-summary-update-article current-article)
9978         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9979             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9980         (gnus-summary-rethread-current)
9981         (gnus-message 3 "Article %d is now the child of article %d"
9982                       current-article parent-article)))))
9983
9984 (defun gnus-summary-toggle-threads (&optional arg)
9985   "Toggle showing conversation threads.
9986 If ARG is positive number, turn showing conversation threads on."
9987   (interactive "P")
9988   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9989     (setq gnus-show-threads
9990           (if (null arg) (not gnus-show-threads)
9991             (> (prefix-numeric-value arg) 0)))
9992     (gnus-summary-prepare)
9993     (gnus-summary-goto-subject current)
9994     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9995     (gnus-summary-position-point)))
9996
9997 (defun gnus-summary-show-all-threads ()
9998   "Show all threads."
9999   (interactive)
10000   (save-excursion
10001     (let ((buffer-read-only nil))
10002       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10003   (gnus-summary-position-point))
10004
10005 (defun gnus-summary-show-thread ()
10006   "Show thread subtrees.
10007 Returns nil if no thread was there to be shown."
10008   (interactive)
10009   (let ((buffer-read-only nil)
10010         (orig (point))
10011         ;; first goto end then to beg, to have point at beg after let
10012         (end (progn (end-of-line) (point)))
10013         (beg (progn (beginning-of-line) (point))))
10014     (prog1
10015         ;; Any hidden lines here?
10016         (search-forward "\r" end t)
10017       (subst-char-in-region beg end ?\^M ?\n t)
10018       (goto-char orig)
10019       (gnus-summary-position-point))))
10020
10021 (defun gnus-summary-maybe-hide-threads ()
10022   "If requested, hide the threads that should be hidden."
10023   (when (and gnus-show-threads
10024              gnus-thread-hide-subtree)
10025     (gnus-summary-hide-all-threads
10026      (if (or (consp gnus-thread-hide-subtree)
10027              (gnus-functionp gnus-thread-hide-subtree))
10028          (gnus-make-predicate gnus-thread-hide-subtree)
10029        nil))))
10030
10031 ;;; Hiding predicates.
10032
10033 (defun gnus-article-unread-p (header)
10034   (memq (mail-header-number header) gnus-newsgroup-unreads))
10035
10036 (defun gnus-article-unseen-p (header)
10037   (memq (mail-header-number header) gnus-newsgroup-unseen))
10038
10039 (defun gnus-map-articles (predicate articles)
10040   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10041   (apply 'gnus-or (mapcar predicate
10042                           (mapcar 'gnus-summary-article-header articles))))
10043
10044 (defun gnus-summary-hide-all-threads (&optional predicate)
10045   "Hide all thread subtrees.
10046 If PREDICATE is supplied, threads that satisfy this predicate
10047 will not be hidden."
10048   (interactive)
10049   (save-excursion
10050     (goto-char (point-min))
10051     (let ((end nil))
10052       (while (not end)
10053         (when (or (not predicate)
10054                   (gnus-map-articles
10055                    predicate (gnus-summary-article-children)))
10056             (gnus-summary-hide-thread))
10057         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10058   (gnus-summary-position-point))
10059
10060 (defun gnus-summary-hide-thread ()
10061   "Hide thread subtrees.
10062 If PREDICATE is supplied, threads that satisfy this predicate
10063 will not be hidden.
10064 Returns nil if no threads were there to be hidden."
10065   (interactive)
10066   (let ((buffer-read-only nil)
10067         (start (point))
10068         (article (gnus-summary-article-number)))
10069     (goto-char start)
10070     ;; Go forward until either the buffer ends or the subthread
10071     ;; ends.
10072     (when (and (not (eobp))
10073                (or (zerop (gnus-summary-next-thread 1 t))
10074                    (goto-char (point-max))))
10075       (prog1
10076           (if (and (> (point) start)
10077                    (search-backward "\n" start t))
10078               (progn
10079                 (subst-char-in-region start (point) ?\n ?\^M)
10080                 (gnus-summary-goto-subject article))
10081             (goto-char start)
10082             nil)))))
10083
10084 (defun gnus-summary-go-to-next-thread (&optional previous)
10085   "Go to the same level (or less) next thread.
10086 If PREVIOUS is non-nil, go to previous thread instead.
10087 Return the article number moved to, or nil if moving was impossible."
10088   (let ((level (gnus-summary-thread-level))
10089         (way (if previous -1 1))
10090         (beg (point)))
10091     (forward-line way)
10092     (while (and (not (eobp))
10093                 (< level (gnus-summary-thread-level)))
10094       (forward-line way))
10095     (if (eobp)
10096         (progn
10097           (goto-char beg)
10098           nil)
10099       (setq beg (point))
10100       (prog1
10101           (gnus-summary-article-number)
10102         (goto-char beg)))))
10103
10104 (defun gnus-summary-next-thread (n &optional silent)
10105   "Go to the same level next N'th thread.
10106 If N is negative, search backward instead.
10107 Returns the difference between N and the number of skips actually
10108 done.
10109
10110 If SILENT, don't output messages."
10111   (interactive "p")
10112   (let ((backward (< n 0))
10113         (n (abs n)))
10114     (while (and (> n 0)
10115                 (gnus-summary-go-to-next-thread backward))
10116       (decf n))
10117     (unless silent
10118       (gnus-summary-position-point))
10119     (when (and (not silent) (/= 0 n))
10120       (gnus-message 7 "No more threads"))
10121     n))
10122
10123 (defun gnus-summary-prev-thread (n)
10124   "Go to the same level previous N'th thread.
10125 Returns the difference between N and the number of skips actually
10126 done."
10127   (interactive "p")
10128   (gnus-summary-next-thread (- n)))
10129
10130 (defun gnus-summary-go-down-thread ()
10131   "Go down one level in the current thread."
10132   (let ((children (gnus-summary-article-children)))
10133     (when children
10134       (gnus-summary-goto-subject (car children)))))
10135
10136 (defun gnus-summary-go-up-thread ()
10137   "Go up one level in the current thread."
10138   (let ((parent (gnus-summary-article-parent)))
10139     (when parent
10140       (gnus-summary-goto-subject parent))))
10141
10142 (defun gnus-summary-down-thread (n)
10143   "Go down thread N steps.
10144 If N is negative, go up instead.
10145 Returns the difference between N and how many steps down that were
10146 taken."
10147   (interactive "p")
10148   (let ((up (< n 0))
10149         (n (abs n)))
10150     (while (and (> n 0)
10151                 (if up (gnus-summary-go-up-thread)
10152                   (gnus-summary-go-down-thread)))
10153       (setq n (1- n)))
10154     (gnus-summary-position-point)
10155     (when (/= 0 n)
10156       (gnus-message 7 "Can't go further"))
10157     n))
10158
10159 (defun gnus-summary-up-thread (n)
10160   "Go up thread N steps.
10161 If N is negative, go down instead.
10162 Returns the difference between N and how many steps down that were
10163 taken."
10164   (interactive "p")
10165   (gnus-summary-down-thread (- n)))
10166
10167 (defun gnus-summary-top-thread ()
10168   "Go to the top of the thread."
10169   (interactive)
10170   (while (gnus-summary-go-up-thread))
10171   (gnus-summary-article-number))
10172
10173 (defun gnus-summary-kill-thread (&optional unmark)
10174   "Mark articles under current thread as read.
10175 If the prefix argument is positive, remove any kinds of marks.
10176 If the prefix argument is negative, tick articles instead."
10177   (interactive "P")
10178   (when unmark
10179     (setq unmark (prefix-numeric-value unmark)))
10180   (let ((articles (gnus-summary-articles-in-thread)))
10181     (save-excursion
10182       ;; Expand the thread.
10183       (gnus-summary-show-thread)
10184       ;; Mark all the articles.
10185       (while articles
10186         (gnus-summary-goto-subject (car articles))
10187         (cond ((null unmark)
10188                (gnus-summary-mark-article-as-read gnus-killed-mark))
10189               ((> unmark 0)
10190                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10191               (t
10192                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10193         (setq articles (cdr articles))))
10194     ;; Hide killed subtrees.
10195     (and (null unmark)
10196          gnus-thread-hide-killed
10197          (gnus-summary-hide-thread))
10198     ;; If marked as read, go to next unread subject.
10199     (when (null unmark)
10200       ;; Go to next unread subject.
10201       (gnus-summary-next-subject 1 t)))
10202   (gnus-set-mode-line 'summary))
10203
10204 ;; Summary sorting commands
10205
10206 (defun gnus-summary-sort-by-number (&optional reverse)
10207   "Sort the summary buffer by article number.
10208 Argument REVERSE means reverse order."
10209   (interactive "P")
10210   (gnus-summary-sort 'number reverse))
10211
10212 (defun gnus-summary-sort-by-author (&optional reverse)
10213   "Sort the summary buffer by author name alphabetically.
10214 If `case-fold-search' is non-nil, case of letters is ignored.
10215 Argument REVERSE means reverse order."
10216   (interactive "P")
10217   (gnus-summary-sort 'author reverse))
10218
10219 (defun gnus-summary-sort-by-subject (&optional reverse)
10220   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10221 If `case-fold-search' is non-nil, case of letters is ignored.
10222 Argument REVERSE means reverse order."
10223   (interactive "P")
10224   (gnus-summary-sort 'subject reverse))
10225
10226 (defun gnus-summary-sort-by-date (&optional reverse)
10227   "Sort the summary buffer by date.
10228 Argument REVERSE means reverse order."
10229   (interactive "P")
10230   (gnus-summary-sort 'date reverse))
10231
10232 (defun gnus-summary-sort-by-score (&optional reverse)
10233   "Sort the summary buffer by score.
10234 Argument REVERSE means reverse order."
10235   (interactive "P")
10236   (gnus-summary-sort 'score reverse))
10237
10238 (defun gnus-summary-sort-by-lines (&optional reverse)
10239   "Sort the summary buffer by the number of lines.
10240 Argument REVERSE means reverse order."
10241   (interactive "P")
10242   (gnus-summary-sort 'lines reverse))
10243
10244 (defun gnus-summary-sort-by-chars (&optional reverse)
10245   "Sort the summary buffer by article length.
10246 Argument REVERSE means reverse order."
10247   (interactive "P")
10248   (gnus-summary-sort 'chars reverse))
10249
10250 (defun gnus-summary-sort-by-original (&optional reverse)
10251   "Sort the summary buffer using the default sorting method.
10252 Argument REVERSE means reverse order."
10253   (interactive "P")
10254   (let* ((buffer-read-only)
10255          (gnus-summary-prepare-hook nil))
10256     ;; We do the sorting by regenerating the threads.
10257     (gnus-summary-prepare)
10258     ;; Hide subthreads if needed.
10259     (gnus-summary-maybe-hide-threads)))
10260
10261 (defun gnus-summary-sort (predicate reverse)
10262   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10263   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10264          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10265          (gnus-thread-sort-functions
10266           (if (not reverse)
10267               thread
10268             `(lambda (t1 t2)
10269                (,thread t2 t1))))
10270          (gnus-sort-gathered-threads-function
10271           gnus-thread-sort-functions)
10272          (gnus-article-sort-functions
10273           (if (not reverse)
10274               article
10275             `(lambda (t1 t2)
10276                (,article t2 t1))))
10277          (buffer-read-only)
10278          (gnus-summary-prepare-hook nil))
10279     ;; We do the sorting by regenerating the threads.
10280     (gnus-summary-prepare)
10281     ;; Hide subthreads if needed.
10282     (gnus-summary-maybe-hide-threads)))
10283
10284 ;; Summary saving commands.
10285
10286 (defun gnus-summary-save-article (&optional n not-saved)
10287   "Save the current article using the default saver function.
10288 If N is a positive number, save the N next articles.
10289 If N is a negative number, save the N previous articles.
10290 If N is nil and any articles have been marked with the process mark,
10291 save those articles instead.
10292 The variable `gnus-default-article-saver' specifies the saver function."
10293   (interactive "P")
10294   (let* ((articles (gnus-summary-work-articles n))
10295          (save-buffer (save-excursion
10296                         (nnheader-set-temp-buffer " *Gnus Save*")))
10297          (num (length articles))
10298          header file)
10299     (dolist (article articles)
10300       (setq header (gnus-summary-article-header article))
10301       (if (not (vectorp header))
10302           ;; This is a pseudo-article.
10303           (if (assq 'name header)
10304               (gnus-copy-file (cdr (assq 'name header)))
10305             (gnus-message 1 "Article %d is unsaveable" article))
10306         ;; This is a real article.
10307         (save-window-excursion
10308           (let ((gnus-display-mime-function nil)
10309                 (gnus-article-prepare-hook nil))
10310             (gnus-summary-select-article t nil nil article)))
10311         (save-excursion
10312           (set-buffer save-buffer)
10313           (erase-buffer)
10314           (insert-buffer-substring gnus-original-article-buffer))
10315         (setq file (gnus-article-save save-buffer file num))
10316         (gnus-summary-remove-process-mark article)
10317         (unless not-saved
10318           (gnus-summary-set-saved-mark article))))
10319     (gnus-kill-buffer save-buffer)
10320     (gnus-summary-position-point)
10321     (gnus-set-mode-line 'summary)
10322     n))
10323
10324 (defun gnus-summary-pipe-output (&optional arg)
10325   "Pipe the current article to a subprocess.
10326 If N is a positive number, pipe the N next articles.
10327 If N is a negative number, pipe the N previous articles.
10328 If N is nil and any articles have been marked with the process mark,
10329 pipe those articles instead."
10330   (interactive "P")
10331   (require 'gnus-art)
10332   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10333     (gnus-summary-save-article arg t))
10334   (let ((buffer (get-buffer "*Shell Command Output*")))
10335     (if (and buffer
10336              (with-current-buffer buffer (> (point-max) (point-min))))
10337         (gnus-configure-windows 'pipe))))
10338
10339 (defun gnus-summary-save-article-mail (&optional arg)
10340   "Append the current article to an mail file.
10341 If N is a positive number, save the N next articles.
10342 If N is a negative number, save the N previous articles.
10343 If N is nil and any articles have been marked with the process mark,
10344 save those articles instead."
10345   (interactive "P")
10346   (require 'gnus-art)
10347   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10348     (gnus-summary-save-article arg)))
10349
10350 (defun gnus-summary-save-article-rmail (&optional arg)
10351   "Append the current article to an rmail file.
10352 If N is a positive number, save the N next articles.
10353 If N is a negative number, save the N previous articles.
10354 If N is nil and any articles have been marked with the process mark,
10355 save those articles instead."
10356   (interactive "P")
10357   (require 'gnus-art)
10358   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10359     (gnus-summary-save-article arg)))
10360
10361 (defun gnus-summary-save-article-file (&optional arg)
10362   "Append the current article to a file.
10363 If N is a positive number, save the N next articles.
10364 If N is a negative number, save the N previous articles.
10365 If N is nil and any articles have been marked with the process mark,
10366 save those articles instead."
10367   (interactive "P")
10368   (require 'gnus-art)
10369   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10370     (gnus-summary-save-article arg)))
10371
10372 (defun gnus-summary-write-article-file (&optional arg)
10373   "Write the current article to a file, deleting the previous file.
10374 If N is a positive number, save the N next articles.
10375 If N is a negative number, save the N previous articles.
10376 If N is nil and any articles have been marked with the process mark,
10377 save those articles instead."
10378   (interactive "P")
10379   (require 'gnus-art)
10380   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10381     (gnus-summary-save-article arg)))
10382
10383 (defun gnus-summary-save-article-body-file (&optional arg)
10384   "Append the current article body to a file.
10385 If N is a positive number, save the N next articles.
10386 If N is a negative number, save the N previous articles.
10387 If N is nil and any articles have been marked with the process mark,
10388 save those articles instead."
10389   (interactive "P")
10390   (require 'gnus-art)
10391   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10392     (gnus-summary-save-article arg)))
10393
10394 (defun gnus-summary-muttprint (&optional arg)
10395   "Print the current article using Muttprint.
10396 If N is a positive number, save the N next articles.
10397 If N is a negative number, save the N previous articles.
10398 If N is nil and any articles have been marked with the process mark,
10399 save those articles instead."
10400   (interactive "P")
10401   (require 'gnus-art)
10402   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10403     (gnus-summary-save-article arg t)))
10404
10405 (defun gnus-summary-pipe-message (program)
10406   "Pipe the current article through PROGRAM."
10407   (interactive "sProgram: ")
10408   (gnus-summary-select-article)
10409   (let ((mail-header-separator ""))
10410     (gnus-eval-in-buffer-window gnus-article-buffer
10411       (save-restriction
10412         (widen)
10413         (let ((start (window-start))
10414               buffer-read-only)
10415           (message-pipe-buffer-body program)
10416           (set-window-start (get-buffer-window (current-buffer)) start))))))
10417
10418 (defun gnus-get-split-value (methods)
10419   "Return a value based on the split METHODS."
10420   (let (split-name method result match)
10421     (when methods
10422       (save-excursion
10423         (set-buffer gnus-original-article-buffer)
10424         (save-restriction
10425           (nnheader-narrow-to-headers)
10426           (while (and methods (not split-name))
10427             (goto-char (point-min))
10428             (setq method (pop methods))
10429             (setq match (car method))
10430             (when (cond
10431                    ((stringp match)
10432                     ;; Regular expression.
10433                     (ignore-errors
10434                       (re-search-forward match nil t)))
10435                    ((gnus-functionp match)
10436                     ;; Function.
10437                     (save-restriction
10438                       (widen)
10439                       (setq result (funcall match gnus-newsgroup-name))))
10440                    ((consp match)
10441                     ;; Form.
10442                     (save-restriction
10443                       (widen)
10444                       (setq result (eval match)))))
10445               (setq split-name (cdr method))
10446               (cond ((stringp result)
10447                      (push (expand-file-name
10448                             result gnus-article-save-directory)
10449                            split-name))
10450                     ((consp result)
10451                      (setq split-name (append result split-name)))))))))
10452     (nreverse split-name)))
10453
10454 (defun gnus-valid-move-group-p (group)
10455   (and (boundp group)
10456        (symbol-name group)
10457        (symbol-value group)
10458        (gnus-get-function (gnus-find-method-for-group
10459                            (symbol-name group)) 'request-accept-article t)))
10460
10461 (defun gnus-read-move-group-name (prompt default articles prefix)
10462   "Read a group name."
10463   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10464          (minibuffer-confirm-incomplete nil) ; XEmacs
10465          (prom
10466           (format "%s %s to:"
10467                   prompt
10468                   (if (> (length articles) 1)
10469                       (format "these %d articles" (length articles))
10470                     "this article")))
10471          (to-newsgroup
10472           (cond
10473            ((null split-name)
10474             (gnus-completing-read-with-default
10475              default prom
10476              gnus-active-hashtb
10477              'gnus-valid-move-group-p
10478              nil prefix
10479              'gnus-group-history))
10480            ((= 1 (length split-name))
10481             (gnus-completing-read-with-default
10482              (car split-name) prom
10483              gnus-active-hashtb
10484              'gnus-valid-move-group-p
10485              nil nil
10486              'gnus-group-history))
10487            (t
10488             (gnus-completing-read-with-default
10489              nil prom
10490              (mapcar (lambda (el) (list el))
10491                      (nreverse split-name))
10492              nil nil nil
10493              'gnus-group-history))))
10494          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10495     (when to-newsgroup
10496       (if (or (string= to-newsgroup "")
10497               (string= to-newsgroup prefix))
10498           (setq to-newsgroup default))
10499       (unless to-newsgroup
10500         (error "No group name entered"))
10501       (or (gnus-active to-newsgroup)
10502           (gnus-activate-group to-newsgroup nil nil to-method)
10503           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10504                                      to-newsgroup))
10505               (or (and (gnus-request-create-group to-newsgroup to-method)
10506                        (gnus-activate-group
10507                         to-newsgroup nil nil to-method)
10508                        (gnus-subscribe-group to-newsgroup))
10509                   (error "Couldn't create group %s" to-newsgroup)))
10510           (error "No such group: %s" to-newsgroup)))
10511     to-newsgroup))
10512
10513 (defun gnus-summary-save-parts (type dir n &optional reverse)
10514   "Save parts matching TYPE to DIR.
10515 If REVERSE, save parts that do not match TYPE."
10516   (interactive
10517    (list (read-string "Save parts of type: "
10518                       (or (car gnus-summary-save-parts-type-history)
10519                           gnus-summary-save-parts-default-mime)
10520                       'gnus-summary-save-parts-type-history)
10521          (setq gnus-summary-save-parts-last-directory
10522                (read-file-name "Save to directory: "
10523                                gnus-summary-save-parts-last-directory
10524                                nil t))
10525          current-prefix-arg))
10526   (gnus-summary-iterate n
10527     (let ((gnus-display-mime-function nil)
10528           (gnus-inhibit-treatment t))
10529       (gnus-summary-select-article))
10530     (save-excursion
10531       (set-buffer gnus-article-buffer)
10532       (let ((handles (or gnus-article-mime-handles
10533                          (mm-dissect-buffer nil gnus-article-loose-mime)
10534                          (mm-uu-dissect))))
10535         (when handles
10536           (gnus-summary-save-parts-1 type dir handles reverse)
10537           (unless gnus-article-mime-handles ;; Don't destroy this case.
10538             (mm-destroy-parts handles)))))))
10539
10540 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10541   (if (stringp (car handle))
10542       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10543               (cdr handle))
10544     (when (if reverse
10545               (not (string-match type (mm-handle-media-type handle)))
10546             (string-match type (mm-handle-media-type handle)))
10547       (let ((file (expand-file-name
10548                    (file-name-nondirectory
10549                     (or
10550                      (mail-content-type-get
10551                       (mm-handle-disposition handle) 'filename)
10552                      (concat gnus-newsgroup-name
10553                              "." (number-to-string
10554                                   (cdr gnus-article-current)))))
10555                    dir)))
10556         (unless (file-exists-p file)
10557           (mm-save-part-to-file handle file))))))
10558
10559 ;; Summary extract commands
10560
10561 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10562   (let ((buffer-read-only nil)
10563         (article (gnus-summary-article-number))
10564         after-article b e)
10565     (unless (gnus-summary-goto-subject article)
10566       (error "No such article: %d" article))
10567     (gnus-summary-position-point)
10568     ;; If all commands are to be bunched up on one line, we collect
10569     ;; them here.
10570     (unless gnus-view-pseudos-separately
10571       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10572             files action)
10573         (while ps
10574           (setq action (cdr (assq 'action (car ps))))
10575           (setq files (list (cdr (assq 'name (car ps)))))
10576           (while (and ps (cdr ps)
10577                       (string= (or action "1")
10578                                (or (cdr (assq 'action (cadr ps))) "2")))
10579             (push (cdr (assq 'name (cadr ps))) files)
10580             (setcdr ps (cddr ps)))
10581           (when files
10582             (when (not (string-match "%s" action))
10583               (push " " files))
10584             (push " " files)
10585             (when (assq 'execute (car ps))
10586               (setcdr (assq 'execute (car ps))
10587                       (funcall (if (string-match "%s" action)
10588                                    'format 'concat)
10589                                action
10590                                (mapconcat
10591                                 (lambda (f)
10592                                   (if (equal f " ")
10593                                       f
10594                                     (gnus-quote-arg-for-sh-or-csh f)))
10595                                 files " ")))))
10596           (setq ps (cdr ps)))))
10597     (if (and gnus-view-pseudos (not not-view))
10598         (while pslist
10599           (when (assq 'execute (car pslist))
10600             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10601                                   (eq gnus-view-pseudos 'not-confirm)))
10602           (setq pslist (cdr pslist)))
10603       (save-excursion
10604         (while pslist
10605           (setq after-article (or (cdr (assq 'article (car pslist)))
10606                                   (gnus-summary-article-number)))
10607           (gnus-summary-goto-subject after-article)
10608           (forward-line 1)
10609           (setq b (point))
10610           (insert "    " (file-name-nondirectory
10611                           (cdr (assq 'name (car pslist))))
10612                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10613           (setq e (point))
10614           (forward-line -1)             ; back to `b'
10615           (gnus-add-text-properties
10616            b (1- e) (list 'gnus-number gnus-reffed-article-number
10617                           gnus-mouse-face-prop gnus-mouse-face))
10618           (gnus-data-enter
10619            after-article gnus-reffed-article-number
10620            gnus-unread-mark b (car pslist) 0 (- e b))
10621           (setq gnus-newsgroup-unreads
10622                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10623                                          gnus-reffed-article-number))
10624           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10625           (setq pslist (cdr pslist)))))))
10626
10627 (defun gnus-pseudos< (p1 p2)
10628   (let ((c1 (cdr (assq 'action p1)))
10629         (c2 (cdr (assq 'action p2))))
10630     (and c1 c2 (string< c1 c2))))
10631
10632 (defun gnus-request-pseudo-article (props)
10633   (cond ((assq 'execute props)
10634          (gnus-execute-command (cdr (assq 'execute props)))))
10635   (let ((gnus-current-article (gnus-summary-article-number)))
10636     (gnus-run-hooks 'gnus-mark-article-hook)))
10637
10638 (defun gnus-execute-command (command &optional automatic)
10639   (save-excursion
10640     (gnus-article-setup-buffer)
10641     (set-buffer gnus-article-buffer)
10642     (setq buffer-read-only nil)
10643     (let ((command (if automatic command
10644                      (read-string "Command: " (cons command 0)))))
10645       (erase-buffer)
10646       (insert "$ " command "\n\n")
10647       (if gnus-view-pseudo-asynchronously
10648           (start-process "gnus-execute" (current-buffer) shell-file-name
10649                          shell-command-switch command)
10650         (call-process shell-file-name nil t nil
10651                       shell-command-switch command)))))
10652
10653 ;; Summary kill commands.
10654
10655 (defun gnus-summary-edit-global-kill (article)
10656   "Edit the \"global\" kill file."
10657   (interactive (list (gnus-summary-article-number)))
10658   (gnus-group-edit-global-kill article))
10659
10660 (defun gnus-summary-edit-local-kill ()
10661   "Edit a local kill file applied to the current newsgroup."
10662   (interactive)
10663   (setq gnus-current-headers (gnus-summary-article-header))
10664   (gnus-group-edit-local-kill
10665    (gnus-summary-article-number) gnus-newsgroup-name))
10666
10667 ;;; Header reading.
10668
10669 (defun gnus-read-header (id &optional header)
10670   "Read the headers of article ID and enter them into the Gnus system."
10671   (let ((group gnus-newsgroup-name)
10672         (gnus-override-method
10673          (or
10674           gnus-override-method
10675           (and (gnus-news-group-p gnus-newsgroup-name)
10676                (car (gnus-refer-article-methods)))))
10677         where)
10678     ;; First we check to see whether the header in question is already
10679     ;; fetched.
10680     (if (stringp id)
10681         ;; This is a Message-ID.
10682         (setq header (or header (gnus-id-to-header id)))
10683       ;; This is an article number.
10684       (setq header (or header (gnus-summary-article-header id))))
10685     (if (and header
10686              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10687         ;; We have found the header.
10688         header
10689       ;; If this is a sparse article, we have to nix out its
10690       ;; previous entry in the thread hashtb.
10691       (when (and header
10692                  (gnus-summary-article-sparse-p (mail-header-number header)))
10693         (let* ((parent (gnus-parent-id (mail-header-references header)))
10694                (thread (and parent (gnus-id-to-thread parent))))
10695           (when thread
10696             (delq (assq header thread) thread))))
10697       ;; We have to really fetch the header to this article.
10698       (save-excursion
10699         (set-buffer nntp-server-buffer)
10700         (when (setq where (gnus-request-head id group))
10701           (nnheader-fold-continuation-lines)
10702           (goto-char (point-max))
10703           (insert ".\n")
10704           (goto-char (point-min))
10705           (insert "211 ")
10706           (princ (cond
10707                   ((numberp id) id)
10708                   ((cdr where) (cdr where))
10709                   (header (mail-header-number header))
10710                   (t gnus-reffed-article-number))
10711                  (current-buffer))
10712           (insert " Article retrieved.\n"))
10713         (if (or (not where)
10714                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10715             ()                          ; Malformed head.
10716           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10717             (when (and (stringp id)
10718                        (not (string= (gnus-group-real-name group)
10719                                      (car where))))
10720               ;; If we fetched by Message-ID and the article came
10721               ;; from a different group, we fudge some bogus article
10722               ;; numbers for this article.
10723               (mail-header-set-number header gnus-reffed-article-number))
10724             (save-excursion
10725               (set-buffer gnus-summary-buffer)
10726               (decf gnus-reffed-article-number)
10727               (gnus-remove-header (mail-header-number header))
10728               (push header gnus-newsgroup-headers)
10729               (setq gnus-current-headers header)
10730               (push (mail-header-number header) gnus-newsgroup-limit)))
10731           header)))))
10732
10733 (defun gnus-remove-header (number)
10734   "Remove header NUMBER from `gnus-newsgroup-headers'."
10735   (if (and gnus-newsgroup-headers
10736            (= number (mail-header-number (car gnus-newsgroup-headers))))
10737       (pop gnus-newsgroup-headers)
10738     (let ((headers gnus-newsgroup-headers))
10739       (while (and (cdr headers)
10740                   (not (= number (mail-header-number (cadr headers)))))
10741         (pop headers))
10742       (when (cdr headers)
10743         (setcdr headers (cddr headers))))))
10744
10745 ;;;
10746 ;;; summary highlights
10747 ;;;
10748
10749 (defun gnus-highlight-selected-summary ()
10750   "Highlight selected article in summary buffer."
10751   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10752   (when gnus-summary-selected-face
10753     (save-excursion
10754       (let* ((beg (progn (beginning-of-line) (point)))
10755              (end (progn (end-of-line) (point)))
10756              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10757              (from (if (get-text-property beg gnus-mouse-face-prop)
10758                        beg
10759                      (or (next-single-property-change
10760                           beg gnus-mouse-face-prop nil end)
10761                          beg)))
10762              (to
10763               (if (= from end)
10764                   (- from 2)
10765                 (or (next-single-property-change
10766                      from gnus-mouse-face-prop nil end)
10767                     end))))
10768         ;; If no mouse-face prop on line we will have to = from = end,
10769         ;; so we highlight the entire line instead.
10770         (when (= (+ to 2) from)
10771           (setq from beg)
10772           (setq to end))
10773         (if gnus-newsgroup-selected-overlay
10774             ;; Move old overlay.
10775             (gnus-move-overlay
10776              gnus-newsgroup-selected-overlay from to (current-buffer))
10777           ;; Create new overlay.
10778           (gnus-overlay-put
10779            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10780            'face gnus-summary-selected-face))))))
10781
10782 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10783 (defun gnus-summary-highlight-line ()
10784   "Highlight current line according to `gnus-summary-highlight'."
10785   (let* ((list gnus-summary-highlight)
10786          (beg (gnus-point-at-bol))
10787          (article (gnus-summary-article-number))
10788          (score (or (cdr (assq (or article gnus-current-article)
10789                                gnus-newsgroup-scored))
10790                     gnus-summary-default-score 0))
10791          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10792          (inhibit-read-only t)
10793          (default gnus-summary-default-score)
10794          (default-high gnus-summary-default-high-score)
10795          (default-low gnus-summary-default-low-score))
10796     ;; Eval the cars of the lists until we find a match.
10797     (while (and list
10798                 (not (eval (caar list))))
10799       (setq list (cdr list)))
10800     (let ((face (cdar list)))
10801       (unless (eq face (get-text-property beg 'face))
10802         (gnus-put-text-property-excluding-characters-with-faces
10803          beg (gnus-point-at-eol) 'face
10804          (setq face (if (boundp face) (symbol-value face) face)))
10805         (when gnus-summary-highlight-line-function
10806           (funcall gnus-summary-highlight-line-function article face))))))
10807
10808 (defun gnus-update-read-articles (group unread &optional compute)
10809   "Update the list of read articles in GROUP.
10810 UNREAD is a sorted list."
10811   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10812          (entry (gnus-gethash group gnus-newsrc-hashtb))
10813          (info (nth 2 entry))
10814          (prev 1)
10815          read)
10816     (if (or (not info) (not active))
10817         ;; There is no info on this group if it was, in fact,
10818         ;; killed.  Gnus stores no information on killed groups, so
10819         ;; there's nothing to be done.
10820         ;; One could store the information somewhere temporarily,
10821         ;; perhaps...  Hmmm...
10822         ()
10823       ;; Remove any negative articles numbers.
10824       (while (and unread (< (car unread) 0))
10825         (setq unread (cdr unread)))
10826       ;; Remove any expired article numbers
10827       (while (and unread (< (car unread) (car active)))
10828         (setq unread (cdr unread)))
10829       ;; Compute the ranges of read articles by looking at the list of
10830       ;; unread articles.
10831       (while unread
10832         (when (/= (car unread) prev)
10833           (push (if (= prev (1- (car unread))) prev
10834                   (cons prev (1- (car unread))))
10835                 read))
10836         (setq prev (1+ (car unread)))
10837         (setq unread (cdr unread)))
10838       (when (<= prev (cdr active))
10839         (push (cons prev (cdr active)) read))
10840       (setq read (if (> (length read) 1) (nreverse read) read))
10841       (if compute
10842           read
10843         (save-excursion
10844           (let (setmarkundo)
10845             ;; Propagate the read marks to the backend.
10846             (when (gnus-check-backend-function 'request-set-mark group)
10847               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10848                     (add (gnus-remove-from-range read (gnus-info-read info))))
10849                 (when (or add del)
10850                   (unless (gnus-check-group group)
10851                     (error "Can't open server for %s" group))
10852                   (gnus-request-set-mark
10853                    group (delq nil (list (if add (list add 'add '(read)))
10854                                          (if del (list del 'del '(read))))))
10855                   (setq setmarkundo
10856                         `(gnus-request-set-mark
10857                           ,group
10858                           ',(delq nil (list
10859                                        (if del (list del 'add '(read)))
10860                                        (if add (list add 'del '(read))))))))))
10861             (set-buffer gnus-group-buffer)
10862             (gnus-undo-register
10863               `(progn
10864                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10865                  (gnus-info-set-read ',info ',(gnus-info-read info))
10866                  (gnus-get-unread-articles-in-group ',info
10867                                                     (gnus-active ,group))
10868                  (gnus-group-update-group ,group t)
10869                  ,setmarkundo))))
10870         ;; Enter this list into the group info.
10871         (gnus-info-set-read info read)
10872         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10873         (gnus-get-unread-articles-in-group info (gnus-active group))
10874         t))))
10875
10876 (defun gnus-offer-save-summaries ()
10877   "Offer to save all active summary buffers."
10878   (let (buffers)
10879     ;; Go through all buffers and find all summaries.
10880     (dolist (buffer (buffer-list))
10881       (when (and (setq buffer (buffer-name buffer))
10882                  (string-match "Summary" buffer)
10883                  (save-excursion
10884                    (set-buffer buffer)
10885                    ;; We check that this is, indeed, a summary buffer.
10886                    (and (eq major-mode 'gnus-summary-mode)
10887                         ;; Also make sure this isn't bogus.
10888                         gnus-newsgroup-prepared
10889                         ;; Also make sure that this isn't a
10890                         ;; dead summary buffer.
10891                         (not gnus-dead-summary-mode))))
10892         (push buffer buffers)))
10893     ;; Go through all these summary buffers and offer to save them.
10894     (when buffers
10895       (save-excursion
10896         (map-y-or-n-p
10897          "Update summary buffer %s? "
10898          (lambda (buf)
10899            (switch-to-buffer buf)
10900            (gnus-summary-exit))
10901          buffers)))))
10902
10903
10904 ;;; @ for mime-partial
10905 ;;;
10906
10907 (defun gnus-request-partial-message ()
10908   (save-excursion
10909     (let ((number (gnus-summary-article-number))
10910           (group gnus-newsgroup-name)
10911           (mother gnus-article-buffer))
10912       (set-buffer (get-buffer-create " *Partial Article*"))
10913       (erase-buffer)
10914       (setq mime-preview-buffer mother)
10915       (gnus-request-article-this-buffer number group)
10916       (mime-parse-buffer)
10917       )))
10918
10919 (autoload 'mime-combine-message/partial-pieces-automatically
10920   "mime-partial"
10921   "Internal method to combine message/partial messages automatically.")
10922
10923 (mime-add-condition
10924  'action '((type . message)(subtype . partial)
10925            (major-mode . gnus-original-article-mode)
10926            (method . mime-combine-message/partial-pieces-automatically)
10927            (summary-buffer-exp . gnus-summary-buffer)
10928            (request-partial-message-method . gnus-request-partial-message)
10929            ))
10930
10931
10932 ;;; @ for message/rfc822
10933 ;;;
10934
10935 (defun gnus-mime-extract-message/rfc822 (entity situation)
10936   "Burst a forwarded article."
10937   (save-excursion
10938     (set-buffer gnus-summary-buffer)
10939     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10940                                    gnus-newsgroup-name 'gnus-group-history))
10941            (gnus-group-marked (list group))
10942            article info)
10943       (with-temp-buffer
10944         (mime-insert-entity-content entity)
10945         (setq article (gnus-request-accept-article group)))
10946       (when (and (consp article)
10947                  (numberp (setq article (cdr article))))
10948         (setq info (gnus-get-info group))
10949         (gnus-info-set-read info
10950                             (gnus-remove-from-range (gnus-info-read info)
10951                                                     (list article)))
10952         (when (string-equal group gnus-newsgroup-name)
10953           (forward-line 1)
10954           (let (gnus-show-threads)
10955             (gnus-summary-goto-subject article t))
10956           (gnus-summary-clear-mark-forward 1))
10957         (set-buffer gnus-group-buffer)
10958         (gnus-group-get-new-news-this-group nil t)))))
10959
10960 (mime-add-condition
10961  'action '((type . message)(subtype . rfc822)
10962            (major-mode . gnus-original-article-mode)
10963            (method . gnus-mime-extract-message/rfc822)
10964            (mode . "extract")
10965            ))
10966
10967 (mime-add-condition
10968  'action '((type . message)(subtype . news)
10969            (major-mode . gnus-original-article-mode)
10970            (method . gnus-mime-extract-message/rfc822)
10971            (mode . "extract")
10972            ))
10973
10974 (defun gnus-mime-extract-multipart (entity situation)
10975   (let ((children (mime-entity-children entity))
10976         mime-acting-situation-to-override
10977         f)
10978     (while children
10979       (mime-play-entity (car children)
10980                         (cons (assq 'mode situation)
10981                               mime-acting-situation-to-override))
10982       (setq children (cdr children)))
10983     (if (setq f (cdr (assq 'after-method
10984                            mime-acting-situation-to-override)))
10985         (eval f)
10986       )))
10987
10988 (mime-add-condition
10989  'action '((type . multipart)
10990            (method . gnus-mime-extract-multipart)
10991            (mode . "extract")
10992            )
10993  'with-default)
10994
10995
10996 ;;; @ end
10997 ;;;
10998
10999 (defun gnus-summary-setup-default-charset ()
11000   "Setup newsgroup default charset."
11001   (if (equal gnus-newsgroup-name "nndraft:drafts")
11002       (setq gnus-newsgroup-charset nil)
11003     (let* ((ignored-charsets
11004             (or gnus-newsgroup-ephemeral-ignored-charsets
11005                 (append
11006                  (and gnus-newsgroup-name
11007                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11008                  gnus-newsgroup-ignored-charsets))))
11009       (setq gnus-newsgroup-charset
11010             (or gnus-newsgroup-ephemeral-charset
11011                 (and gnus-newsgroup-name
11012                      (gnus-parameter-charset gnus-newsgroup-name))
11013                 gnus-default-charset))
11014       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11015            ignored-charsets))))
11016
11017 ;;;
11018 ;;; Mime Commands
11019 ;;;
11020
11021 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11022   "Display the current article buffer fully MIME-buttonized.
11023 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11024 treated as multipart/mixed."
11025   (interactive "P")
11026   (require 'gnus-art)
11027   (let ((gnus-unbuttonized-mime-types nil)
11028         (gnus-mime-display-multipart-as-mixed show-all-parts))
11029     (gnus-summary-show-article)))
11030
11031 (defun gnus-summary-repair-multipart (article)
11032   "Add a Content-Type header to a multipart article without one."
11033   (interactive (list (gnus-summary-article-number)))
11034   (gnus-with-article article
11035     (message-narrow-to-head)
11036     (message-remove-header "Mime-Version")
11037     (goto-char (point-max))
11038     (insert "Mime-Version: 1.0\n")
11039     (widen)
11040     (when (search-forward "\n--" nil t)
11041       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11042         (message-narrow-to-head)
11043         (message-remove-header "Content-Type")
11044         (goto-char (point-max))
11045         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11046                         separator))
11047         (widen))))
11048   (let (gnus-mark-article-hook)
11049     (gnus-summary-select-article t t nil article)))
11050
11051 (defun gnus-summary-toggle-display-buttonized ()
11052   "Toggle the buttonizing of the article buffer."
11053   (interactive)
11054   (require 'gnus-art)
11055   (if (setq gnus-inhibit-mime-unbuttonizing
11056             (not gnus-inhibit-mime-unbuttonizing))
11057       (let ((gnus-unbuttonized-mime-types nil))
11058         (gnus-summary-show-article))
11059     (gnus-summary-show-article)))
11060
11061 ;;;
11062 ;;; Intelli-mouse commmands
11063 ;;;
11064
11065 (defun gnus-wheel-summary-scroll (event)
11066   (interactive "e")
11067   (let ((amount (if (memq 'shift (event-modifiers event))
11068                     (car gnus-wheel-scroll-amount)
11069                   (cdr gnus-wheel-scroll-amount)))
11070         (direction (- (* (static-if (featurep 'xemacs)
11071                              (event-button event)
11072                            (cond ((eq 'mouse-4 (event-basic-type event))
11073                                   4)
11074                                  ((eq 'mouse-5 (event-basic-type event))
11075                                   5)))
11076                          2) 9))
11077         edge)
11078     (gnus-summary-scroll-up (* amount direction))
11079     (when (gnus-eval-in-buffer-window gnus-article-buffer
11080             (save-restriction
11081               (widen)
11082               (and (if (< 0 direction)
11083                        (gnus-article-next-page 0)
11084                      (gnus-article-prev-page 0)
11085                      (bobp))
11086                    (if (setq edge (get-text-property
11087                                    (point-min) 'gnus-wheel-edge))
11088                        (setq edge (* edge direction))
11089                      (setq edge -1))
11090                    (or (plusp edge)
11091                        (let ((buffer-read-only nil)
11092                              (inhibit-read-only t))
11093                          (put-text-property (point-min) (point-max)
11094                                             'gnus-wheel-edge direction)
11095                          nil))
11096                    (or (> edge gnus-wheel-edge-resistance)
11097                        (let ((buffer-read-only nil)
11098                              (inhibit-read-only t))
11099                          (put-text-property (point-min) (point-max)
11100                                             'gnus-wheel-edge
11101                                             (* (1+ edge) direction))
11102                          nil))
11103                    (eq last-command 'gnus-wheel-summary-scroll))))
11104       (gnus-summary-next-article nil nil (minusp direction)))))
11105
11106 (defun gnus-wheel-install ()
11107   "Enable mouse wheel support on summary window."
11108   (when gnus-use-wheel
11109     (let ((keys
11110            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11111       (dolist (key keys)
11112         (define-key gnus-summary-mode-map key
11113           'gnus-wheel-summary-scroll)))))
11114
11115 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11116
11117 ;;;
11118 ;;; Traditional PGP commmands
11119 ;;;
11120
11121 (defun gnus-summary-decrypt-article (&optional force)
11122   "Decrypt the current article in traditional PGP way.
11123 This will have permanent effect only in mail groups.
11124 If FORCE is non-nil, allow editing of articles even in read-only
11125 groups."
11126   (interactive "P")
11127   (gnus-summary-select-article t)
11128   (gnus-eval-in-buffer-window gnus-article-buffer
11129     (save-excursion
11130       (save-restriction
11131         (widen)
11132         (goto-char (point-min))
11133         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11134           (error "Not a traditional PGP message!"))
11135         (let ((armor-start (match-beginning 0)))
11136           (if (and (pgg-decrypt-region armor-start (point-max))
11137                    (or force (not (gnus-group-read-only-p))))
11138               (let ((inhibit-read-only t)
11139                     buffer-read-only)
11140                 (delete-region armor-start
11141                                (progn
11142                                  (re-search-forward "^-+END PGP" nil t)
11143                                  (beginning-of-line 2)
11144                                  (point)))
11145                 (insert-buffer-substring pgg-output-buffer))))))))
11146
11147 (defun gnus-summary-verify-article ()
11148   "Verify the current article in traditional PGP way."
11149   (interactive)
11150   (save-excursion
11151     (set-buffer gnus-original-article-buffer)
11152     (goto-char (point-min))
11153     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11154       (error "Not a traditional PGP message!"))
11155     (re-search-forward "^-+END PGP" nil t)
11156     (beginning-of-line 2)
11157     (call-interactively (function pgg-verify-region))))
11158
11159 ;;;
11160 ;;; Generic summary marking commands
11161 ;;;
11162
11163 (defvar gnus-summary-marking-alist
11164   '((read gnus-del-mark "d")
11165     (unread gnus-unread-mark "u")
11166     (ticked gnus-ticked-mark "!")
11167     (dormant gnus-dormant-mark "?")
11168     (expirable gnus-expirable-mark "e"))
11169   "An alist of names/marks/keystrokes.")
11170
11171 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11172 (defvar gnus-summary-mark-map)
11173
11174 (defun gnus-summary-make-all-marking-commands ()
11175   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11176   (dolist (elem gnus-summary-marking-alist)
11177     (apply 'gnus-summary-make-marking-command elem)))
11178
11179 (defun gnus-summary-make-marking-command (name mark keystroke)
11180   (let ((map (make-sparse-keymap)))
11181     (define-key gnus-summary-generic-mark-map keystroke map)
11182     (dolist (lway `((next "next" next nil "n")
11183                     (next-unread "next unread" next t "N")
11184                     (prev "previous" prev nil "p")
11185                     (prev-unread "previous unread" prev t "P")
11186                     (nomove "" nil nil ,keystroke)))
11187       (let ((func (gnus-summary-make-marking-command-1
11188                    mark (car lway) lway name)))
11189         (setq func (eval func))
11190         (define-key map (nth 4 lway) func)))))
11191
11192 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11193   `(defun ,(intern
11194             (format "gnus-summary-put-mark-as-%s%s"
11195                     name (if (eq way 'nomove)
11196                              ""
11197                            (concat "-" (symbol-name way)))))
11198      (n)
11199      ,(format
11200        "Mark the current article as %s%s.
11201 If N, the prefix, then repeat N times.
11202 If N is negative, move in reverse order.
11203 The difference between N and the actual number of articles marked is
11204 returned."
11205        name (car (cdr lway)))
11206      (interactive "p")
11207      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11208
11209 (defun gnus-summary-generic-mark (n mark move unread)
11210   "Mark N articles with MARK."
11211   (unless (eq major-mode 'gnus-summary-mode)
11212     (error "This command can only be used in the summary buffer"))
11213   (gnus-summary-show-thread)
11214   (let ((nummove
11215          (cond
11216           ((eq move 'next) 1)
11217           ((eq move 'prev) -1)
11218           (t 0))))
11219     (if (zerop nummove)
11220         (setq n 1)
11221       (when (< n 0)
11222         (setq n (abs n)
11223               nummove (* -1 nummove))))
11224     (while (and (> n 0)
11225                 (gnus-summary-mark-article nil mark)
11226                 (zerop (gnus-summary-next-subject nummove unread t)))
11227       (setq n (1- n)))
11228     (when (/= 0 n)
11229       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11230     (gnus-summary-recenter)
11231     (gnus-summary-position-point)
11232     (gnus-set-mode-line 'summary)
11233     n))
11234
11235 (defun gnus-summary-insert-articles (articles)
11236   (when (setq articles
11237               (gnus-sorted-difference articles
11238                                       (mapcar (lambda (h)
11239                                                 (mail-header-number h))
11240                                               gnus-newsgroup-headers)))
11241     (setq gnus-newsgroup-headers
11242           (merge 'list
11243                  gnus-newsgroup-headers
11244                  (gnus-fetch-headers articles)
11245                  'gnus-article-sort-by-number))
11246     ;; Suppress duplicates?
11247     (when gnus-suppress-duplicates
11248       (gnus-dup-suppress-articles))
11249
11250     ;; We might want to build some more threads first.
11251     (when (and gnus-fetch-old-headers
11252                (eq gnus-headers-retrieved-by 'nov))
11253       (if (eq gnus-fetch-old-headers 'invisible)
11254           (gnus-build-all-threads)
11255         (gnus-build-old-threads)))
11256     ;; Let the Gnus agent mark articles as read.
11257     (when gnus-agent
11258       (gnus-agent-get-undownloaded-list))
11259     ;; Remove list identifiers from subject
11260     (when gnus-list-identifiers
11261       (gnus-summary-remove-list-identifiers))
11262     ;; First and last article in this newsgroup.
11263     (when gnus-newsgroup-headers
11264       (setq gnus-newsgroup-begin
11265             (mail-header-number (car gnus-newsgroup-headers))
11266             gnus-newsgroup-end
11267             (mail-header-number
11268              (gnus-last-element gnus-newsgroup-headers))))
11269     (when gnus-use-scoring
11270       (gnus-possibly-score-headers))))
11271
11272 (defun gnus-summary-insert-old-articles (&optional all)
11273   "Insert all old articles in this group.
11274 If ALL is non-nil, already read articles become readable.
11275 If ALL is a number, fetch this number of articles."
11276   (interactive "P")
11277   (prog1
11278       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11279             older len)
11280         (setq older
11281               (gnus-sorted-difference
11282                (gnus-uncompress-range (list gnus-newsgroup-active))
11283                old))
11284         (setq len (length older))
11285         (cond
11286          ((null older) nil)
11287          ((numberp all)
11288           (if (< all len)
11289               (setq older (last older all))))
11290          (all nil)
11291          (t
11292           (if (and (numberp gnus-large-newsgroup)
11293                    (> len gnus-large-newsgroup))
11294               (let* ((cursor-in-echo-area nil)
11295                      (initial (gnus-parameter-large-newsgroup-initial 
11296                                gnus-newsgroup-name))
11297                      (input
11298                       (read-string
11299                        (format
11300                         "How many articles from %s (%s %d): "
11301                         (gnus-limit-string
11302                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11303                         (if initial "max" "default")
11304                         len)
11305                        (if initial
11306                            (cons (number-to-string initial)
11307                                  0)))))
11308                 (unless (string-match "^[ \t]*$" input)
11309                   (setq all (string-to-number input))
11310                   (if (< all len)
11311                       (setq older (last older all))))))))
11312         (if (not older)
11313             (message "No old news.")
11314           (gnus-summary-insert-articles older)
11315           (gnus-summary-limit (gnus-sorted-nunion old older))))
11316     (gnus-summary-position-point)))
11317
11318 (defun gnus-summary-insert-new-articles ()
11319   "Insert all new articles in this group."
11320   (interactive)
11321   (prog1
11322       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11323             (old-active gnus-newsgroup-active)
11324             (nnmail-fetched-sources (list t))
11325             i new)
11326         (setq gnus-newsgroup-active
11327               (gnus-activate-group gnus-newsgroup-name 'scan))
11328         (setq i (1+ (cdr old-active)))
11329         (while (<= i (cdr gnus-newsgroup-active))
11330           (push i new)
11331           (incf i))
11332         (if (not new)
11333             (message "No gnus is bad news.")
11334           (setq new (nreverse new))
11335           (gnus-summary-insert-articles new)
11336           (setq gnus-newsgroup-unreads
11337                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11338           (gnus-summary-limit (gnus-sorted-nunion old new))))
11339     (gnus-summary-position-point)))
11340
11341 (gnus-summary-make-all-marking-commands)
11342
11343 (gnus-ems-redefine)
11344
11345 (provide 'gnus-sum)
11346
11347 (run-hooks 'gnus-sum-load-hook)
11348
11349 ;;; gnus-sum.el ends here