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-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'mm-uu-dissect "mm-uu")
57 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
58   "Deuglify broken Outlook (Express) articles and redisplay."
59   t)
60
61 (defcustom gnus-kill-summary-on-exit t
62   "*If non-nil, kill the summary buffer when you exit from it.
63 If nil, the summary will become a \"*Dead Summary*\" buffer, and
64 it will be killed sometime later."
65   :group 'gnus-summary-exit
66   :type 'boolean)
67
68 (defcustom gnus-fetch-old-headers nil
69   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
70 If an unread article in the group refers to an older, already read (or
71 just marked as read) article, the old article will not normally be
72 displayed in the Summary buffer.  If this variable is non-nil, Gnus
73 will attempt to grab the headers to the old articles, and thereby
74 build complete threads.  If it has the value `some', only enough
75 headers to connect otherwise loose threads will be displayed.  This
76 variable can also be a number.  In that case, no more than that number
77 of old headers will be fetched.  If it has the value `invisible', all
78 old headers will be fetched, but none will be displayed.
79
80 The server has to support NOV for any of this to work."
81   :group 'gnus-thread
82   :type '(choice (const :tag "off" nil)
83                  (const some)
84                  number
85                  (sexp :menu-tag "other" t)))
86
87 (defcustom gnus-refer-thread-limit 200
88   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
89 If t, fetch all the available old headers."
90   :group 'gnus-thread
91   :type '(choice number
92                  (sexp :menu-tag "other" t)))
93
94 (defcustom gnus-summary-make-false-root 'adopt
95   "*nil means that Gnus won't gather loose threads.
96 If the root of a thread has expired or been read in a previous
97 session, the information necessary to build a complete thread has been
98 lost.  Instead of having many small sub-threads from this original thread
99 scattered all over the summary buffer, Gnus can gather them.
100
101 If non-nil, Gnus will try to gather all loose sub-threads from an
102 original thread into one large thread.
103
104 If this variable is non-nil, it should be one of `none', `adopt',
105 `dummy' or `empty'.
106
107 If this variable is `none', Gnus will not make a false root, but just
108 present the sub-threads after another.
109 If this variable is `dummy', Gnus will create a dummy root that will
110 have all the sub-threads as children.
111 If this variable is `adopt', Gnus will make one of the \"children\"
112 the parent and mark all the step-children as such.
113 If this variable is `empty', the \"children\" are printed with empty
114 subject fields.  (Or rather, they will be printed with a string
115 given by the `gnus-summary-same-subject' variable.)"
116   :group 'gnus-thread
117   :type '(choice (const :tag "off" nil)
118                  (const none)
119                  (const dummy)
120                  (const adopt)
121                  (const empty)))
122
123 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
124   "*A regexp to match subjects to be excluded from loose thread gathering.
125 As loose thread gathering is done on subjects only, that means that
126 there can be many false gatherings performed.  By rooting out certain
127 common subjects, gathering might become saner."
128   :group 'gnus-thread
129   :type 'regexp)
130
131 (defcustom gnus-summary-gather-subject-limit nil
132   "*Maximum length of subject comparisons when gathering loose threads.
133 Use nil to compare full subjects.  Setting this variable to a low
134 number will help gather threads that have been corrupted by
135 newsreaders chopping off subject lines, but it might also mean that
136 unrelated articles that have subject that happen to begin with the
137 same few characters will be incorrectly gathered.
138
139 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
140 comparing subjects."
141   :group 'gnus-thread
142   :type '(choice (const :tag "off" nil)
143                  (const fuzzy)
144                  (sexp :menu-tag "on" t)))
145
146 (defcustom gnus-simplify-subject-functions nil
147   "List of functions taking a string argument that simplify subjects.
148 The functions are applied recursively.
149
150 Useful functions to put in this list include:
151 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
152 `gnus-simplify-whitespace', and `gnus-simplify-all-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-spam-mark ?H
451   "*Mark used for spam articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-souped-mark ?F
456   "*Mark used for souped articles."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-kill-file-mark ?X
461   "*Mark used for articles killed by kill files."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-low-score-mark ?Y
466   "*Mark used for articles with a low score."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-catchup-mark ?C
471   "*Mark used for articles that are caught up."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-replied-mark ?A
476   "*Mark used for articles that have been replied to."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-forwarded-mark ?F
481   "*Mark used for articles that have been forwarded."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-recent-mark ?N
486   "*Mark used for articles that are recent."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-cached-mark ?*
491   "*Mark used for articles that are in the cache."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-saved-mark ?S
496   "*Mark used for articles that have been saved."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-unseen-mark ?.
501   "*Mark used for articles that haven't been seen."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-no-mark ?\ ;;;Whitespace
506   "*Mark used for articles that have no other secondary mark."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-ancient-mark ?O
511   "*Mark used for ancient articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-sparse-mark ?Q
516   "*Mark used for sparsely reffed articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-canceled-mark ?G
521   "*Mark used for canceled articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-duplicate-mark ?M
526   "*Mark used for duplicate articles."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-undownloaded-mark ?@
531   "*Mark used for articles that weren't downloaded."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-downloadable-mark ?%
536   "*Mark used for articles that are to be downloaded."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-unsendable-mark ?=
541   "*Mark used for articles that won't be sent."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-score-over-mark ?+
546   "*Score mark used for articles with high scores."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-score-below-mark ?-
551   "*Score mark used for articles with low scores."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
556   "*There is no thread under the article."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-not-empty-thread-mark ?=
561   "*There is a thread under the article."
562   :group 'gnus-summary-marks
563   :type 'character)
564
565 (defcustom gnus-view-pseudo-asynchronously nil
566   "*If non-nil, Gnus will view pseudo-articles asynchronously."
567   :group 'gnus-extract-view
568   :type 'boolean)
569
570 (defcustom gnus-auto-expirable-marks
571   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
572         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
573         gnus-souped-mark gnus-duplicate-mark)
574   "*The list of marks converted into expiration if a group is auto-expirable."
575   :version "21.1"
576   :group 'gnus-summary
577   :type '(repeat character))
578
579 (defcustom gnus-inhibit-user-auto-expire t
580   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
581   :version "21.1"
582   :group 'gnus-summary
583   :type 'boolean)
584
585 (defcustom gnus-view-pseudos nil
586   "*If `automatic', pseudo-articles will be viewed automatically.
587 If `not-confirm', pseudos will be viewed automatically, and the user
588 will not be asked to confirm the command."
589   :group 'gnus-extract-view
590   :type '(choice (const :tag "off" nil)
591                  (const automatic)
592                  (const not-confirm)))
593
594 (defcustom gnus-view-pseudos-separately t
595   "*If non-nil, one pseudo-article will be created for each file to be viewed.
596 If nil, all files that use the same viewing command will be given as a
597 list of parameters to that command."
598   :group 'gnus-extract-view
599   :type 'boolean)
600
601 (defcustom gnus-insert-pseudo-articles t
602   "*If non-nil, insert pseudo-articles when decoding articles."
603   :group 'gnus-extract-view
604   :type 'boolean)
605
606 (defcustom gnus-summary-dummy-line-format
607   "  %(:                          :%) %S\n"
608   "*The format specification for the dummy roots in the summary buffer.
609 It works along the same lines as a normal formatting string,
610 with some simple extensions.
611
612 %S  The subject
613
614 General format specifiers can also be used.
615 See `(gnus)Formatting Variables'."
616   :link '(custom-manual "(gnus)Formatting Variables")
617   :group 'gnus-threading
618   :type 'string)
619
620 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
621   "*The format specification for the summary mode line.
622 It works along the same lines as a normal formatting string,
623 with some simple extensions:
624
625 %G  Group name
626 %p  Unprefixed group name
627 %A  Current article number
628 %z  Current article score
629 %V  Gnus version
630 %U  Number of unread articles in the group
631 %e  Number of unselected articles in the group
632 %Z  A string with unread/unselected article counts
633 %g  Shortish group name
634 %S  Subject of the current article
635 %u  User-defined spec
636 %s  Current score file name
637 %d  Number of dormant articles
638 %r  Number of articles that have been marked as read in this session
639 %E  Number of articles expunged by the score files"
640   :group 'gnus-summary-format
641   :type 'string)
642
643 (defcustom gnus-list-identifiers nil
644   "Regexp that matches list identifiers to be removed from subject.
645 This can also be a list of regexps."
646   :version "21.1"
647   :group 'gnus-summary-format
648   :group 'gnus-article-hiding
649   :type '(choice (const :tag "none" nil)
650                  (regexp :value ".*")
651                  (repeat :value (".*") regexp)))
652
653 (defcustom gnus-summary-mark-below 0
654   "*Mark all articles with a score below this variable as read.
655 This variable is local to each summary buffer and usually set by the
656 score file."
657   :group 'gnus-score-default
658   :type 'integer)
659
660 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
661   "*List of functions used for sorting articles in the summary buffer.
662
663 Each function takes two articles and returns non-nil if the first
664 article should be sorted before the other.  If you use more than one
665 function, the primary sort function should be the last.  You should
666 probably always include `gnus-article-sort-by-number' in the list of
667 sorting functions -- preferably first.  Also note that sorting by date
668 is often much slower than sorting by number, and the sorting order is
669 very similar.  (Sorting by date means sorting by the time the message
670 was sent, sorting by number means sorting by arrival time.)
671
672 Ready-made functions include `gnus-article-sort-by-number',
673 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
674 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
675 and `gnus-article-sort-by-score'.
676
677 When threading is turned on, the variable `gnus-thread-sort-functions'
678 controls how articles are sorted."
679   :group 'gnus-summary-sort
680   :type '(repeat (choice (function-item gnus-article-sort-by-number)
681                          (function-item gnus-article-sort-by-author)
682                          (function-item gnus-article-sort-by-subject)
683                          (function-item gnus-article-sort-by-date)
684                          (function-item gnus-article-sort-by-score)
685                          (function-item gnus-article-sort-by-random)
686                          (function :tag "other"))))
687
688 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
689   "*List of functions used for sorting threads in the summary buffer.
690 By default, threads are sorted by article number.
691
692 Each function takes two threads and returns non-nil if the first
693 thread should be sorted before the other.  If you use more than one
694 function, the primary sort function should be the last.  You should
695 probably always include `gnus-thread-sort-by-number' in the list of
696 sorting functions -- preferably first.  Also note that sorting by date
697 is often much slower than sorting by number, and the sorting order is
698 very similar.  (Sorting by date means sorting by the time the message
699 was sent, sorting by number means sorting by arrival time.)
700
701 Ready-made functions include `gnus-thread-sort-by-number',
702 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
703 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
704 `gnus-thread-sort-by-most-recent-number',
705 `gnus-thread-sort-by-most-recent-date',
706 `gnus-thread-sort-by-random', and
707 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
708
709 When threading is turned off, the variable
710 `gnus-article-sort-functions' controls how articles are sorted."
711   :group 'gnus-summary-sort
712   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
713                          (function-item gnus-thread-sort-by-author)
714                          (function-item gnus-thread-sort-by-subject)
715                          (function-item gnus-thread-sort-by-date)
716                          (function-item gnus-thread-sort-by-score)
717                          (function-item gnus-thread-sort-by-total-score)
718                          (function-item gnus-thread-sort-by-random)
719                          (function :tag "other"))))
720
721 (defcustom gnus-thread-score-function '+
722   "*Function used for calculating the total score of a thread.
723
724 The function is called with the scores of the article and each
725 subthread and should then return the score of the thread.
726
727 Some functions you can use are `+', `max', or `min'."
728   :group 'gnus-summary-sort
729   :type 'function)
730
731 (defcustom gnus-summary-expunge-below nil
732   "All articles that have a score less than this variable will be expunged.
733 This variable is local to the summary buffers."
734   :group 'gnus-score-default
735   :type '(choice (const :tag "off" nil)
736                  integer))
737
738 (defcustom gnus-thread-expunge-below nil
739   "All threads that have a total score less than this variable will be expunged.
740 See `gnus-thread-score-function' for en explanation of what a
741 \"thread score\" is.
742
743 This variable is local to the summary buffers."
744   :group 'gnus-threading
745   :group 'gnus-score-default
746   :type '(choice (const :tag "off" nil)
747                  integer))
748
749 (defcustom gnus-summary-mode-hook nil
750   "*A hook for Gnus summary mode.
751 This hook is run before any variables are set in the summary buffer."
752   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
753   :group 'gnus-summary-various
754   :type 'hook)
755
756 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
757 (when (featurep 'xemacs)
758   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
759   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
760   (add-hook 'gnus-summary-mode-hook
761             'gnus-xmas-switch-horizontal-scrollbar-off))
762
763 (defcustom gnus-summary-menu-hook nil
764   "*Hook run after the creation of the summary mode menu."
765   :group 'gnus-summary-visual
766   :type 'hook)
767
768 (defcustom gnus-summary-exit-hook nil
769   "*A hook called on exit from the summary buffer.
770 It will be called with point in the group buffer."
771   :group 'gnus-summary-exit
772   :type 'hook)
773
774 (defcustom gnus-summary-prepare-hook nil
775   "*A hook called after the summary buffer has been generated.
776 If you want to modify the summary buffer, you can use this hook."
777   :group 'gnus-summary-various
778   :type 'hook)
779
780 (defcustom gnus-summary-prepared-hook nil
781   "*A hook called as the last thing after the summary buffer has been generated."
782   :group 'gnus-summary-various
783   :type 'hook)
784
785 (defcustom gnus-summary-generate-hook nil
786   "*A hook run just before generating the summary buffer.
787 This hook is commonly used to customize threading variables and the
788 like."
789   :group 'gnus-summary-various
790   :type 'hook)
791
792 (defcustom gnus-select-group-hook nil
793   "*A hook called when a newsgroup is selected.
794
795 If you'd like to simplify subjects like the
796 `gnus-summary-next-same-subject' command does, you can use the
797 following hook:
798
799  (add-hook gnus-select-group-hook
800            (lambda ()
801              (mapcar (lambda (header)
802                        (mail-header-set-subject
803                         header
804                         (gnus-simplify-subject
805                          (mail-header-subject header) 're-only)))
806                      gnus-newsgroup-headers)))"
807   :group 'gnus-group-select
808   :type 'hook)
809
810 (defcustom gnus-select-article-hook nil
811   "*A hook called when an article is selected."
812   :group 'gnus-summary-choose
813   :type 'hook)
814
815 (defcustom gnus-visual-mark-article-hook
816   (list 'gnus-highlight-selected-summary)
817   "*Hook run after selecting an article in the summary buffer.
818 It is meant to be used for highlighting the article in some way.  It
819 is not run if `gnus-visual' is nil."
820   :group 'gnus-summary-visual
821   :type 'hook)
822
823 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
824   "*A hook called before parsing the headers."
825   :group 'gnus-various
826   :type 'hook)
827
828 (defcustom gnus-exit-group-hook nil
829   "*A hook called when exiting summary mode.
830 This hook is not called from the non-updating exit commands like `Q'."
831   :group 'gnus-various
832   :type 'hook)
833
834 (defcustom gnus-summary-update-hook
835   (list 'gnus-summary-highlight-line)
836   "*A hook called when a summary line is changed.
837 The hook will not be called if `gnus-visual' is nil.
838
839 The default function `gnus-summary-highlight-line' will
840 highlight the line according to the `gnus-summary-highlight'
841 variable."
842   :group 'gnus-summary-visual
843   :type 'hook)
844
845 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
846   "*A hook called when an article is selected for the first time.
847 The hook is intended to mark an article as read (or unread)
848 automatically when it is selected."
849   :group 'gnus-summary-choose
850   :type 'hook)
851
852 (defcustom gnus-group-no-more-groups-hook nil
853   "*A hook run when returning to group mode having no more (unread) groups."
854   :group 'gnus-group-select
855   :type 'hook)
856
857 (defcustom gnus-ps-print-hook nil
858   "*A hook run before ps-printing something from Gnus."
859   :group 'gnus-summary
860   :type 'hook)
861
862 (defcustom gnus-summary-display-arrow
863   (and (fboundp 'display-graphic-p)
864        (display-graphic-p))
865   "*If non-nil, display an arrow highlighting the current article."
866   :version "21.1"
867   :group 'gnus-summary
868   :type 'boolean)
869
870 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
871   "Face used for highlighting the current article in the summary buffer."
872   :group 'gnus-summary-visual
873   :type 'face)
874
875 (defcustom gnus-summary-highlight
876   '(((eq mark gnus-canceled-mark)
877      . gnus-summary-cancelled-face)
878     ((and (> score default-high)
879           (or (eq mark gnus-dormant-mark)
880               (eq mark gnus-ticked-mark)))
881      . gnus-summary-high-ticked-face)
882     ((and (< score default-low)
883           (or (eq mark gnus-dormant-mark)
884               (eq mark gnus-ticked-mark)))
885      . gnus-summary-low-ticked-face)
886     ((or (eq mark gnus-dormant-mark)
887          (eq mark gnus-ticked-mark))
888      . gnus-summary-normal-ticked-face)
889     ((and (> score default-high) (eq mark gnus-ancient-mark))
890      . gnus-summary-high-ancient-face)
891     ((and (< score default-low) (eq mark gnus-ancient-mark))
892      . gnus-summary-low-ancient-face)
893     ((eq mark gnus-ancient-mark)
894      . gnus-summary-normal-ancient-face)
895     ((and (> score default-high) (eq mark gnus-unread-mark))
896      . gnus-summary-high-unread-face)
897     ((and (< score default-low) (eq mark gnus-unread-mark))
898      . gnus-summary-low-unread-face)
899     ((eq mark gnus-unread-mark)
900      . gnus-summary-normal-unread-face)
901     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
902                                                   gnus-undownloaded-mark)))
903      . gnus-summary-high-unread-face)
904     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
905                                                  gnus-undownloaded-mark)))
906      . gnus-summary-low-unread-face)
907     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
908           (memq article gnus-newsgroup-unreads))
909      . gnus-summary-normal-unread-face)
910     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
911      . gnus-summary-normal-read-face)
912     ((> score default-high)
913      . gnus-summary-high-read-face)
914     ((< score default-low)
915      . gnus-summary-low-read-face)
916     (t
917      . gnus-summary-normal-read-face))
918   "*Controls the highlighting of summary buffer lines.
919
920 A list of (FORM . FACE) pairs.  When deciding how a a particular
921 summary line should be displayed, each form is evaluated.  The content
922 of the face field after the first true form is used.  You can change
923 how those summary lines are displayed, by editing the face field.
924
925 You can use the following variables in the FORM field.
926
927 score:        The article's score
928 default:      The default article score.
929 default-high: The default score for high scored articles.
930 default-low:  The default score for low scored articles.
931 below:        The score below which articles are automatically marked as read.
932 mark:         The articles mark."
933   :group 'gnus-summary-visual
934   :type '(repeat (cons (sexp :tag "Form" nil)
935                        face)))
936
937 (defcustom gnus-alter-header-function nil
938   "Function called to allow alteration of article header structures.
939 The function is called with one parameter, the article header vector,
940 which it may alter in any way.")
941
942 (defvar gnus-decode-encoded-word-function
943   (mime-find-field-decoder 'From 'nov)
944   "Variable that says which function should be used to decode a string with encoded words.")
945
946 (defcustom gnus-extra-headers '(To Newsgroups)
947   "*Extra headers to parse."
948   :version "21.1"
949   :group 'gnus-summary
950   :type '(repeat symbol))
951
952 (defcustom gnus-ignored-from-addresses
953   (and user-mail-address (regexp-quote user-mail-address))
954   "*Regexp of From headers that may be suppressed in favor of To headers."
955   :version "21.1"
956   :group 'gnus-summary
957   :type 'regexp)
958
959 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
960   "List of charsets that should be ignored.
961 When these charsets are used in the \"charset\" parameter, the
962 default charset will be used instead."
963   :version "21.1"
964   :type '(repeat symbol)
965   :group 'gnus-charset)
966
967 (gnus-define-group-parameter
968  ignored-charsets
969  :type list
970  :function-document
971  "Return the ignored charsets of GROUP."
972  :variable gnus-group-ignored-charsets-alist
973  :variable-default
974  '(("alt\\.chinese\\.text" iso-8859-1))
975  :variable-document
976  "Alist of regexps (to match group names) and charsets that should be ignored.
977 When these charsets are used in the \"charset\" parameter, the
978 default charset will be used instead."
979  :variable-group gnus-charset
980  :variable-type '(repeat (cons (regexp :tag "Group")
981                                (repeat symbol)))
982  :parameter-type '(choice :tag "Ignored charsets"
983                           :value nil
984                           (repeat (symbol)))
985  :parameter-document       "\
986 List of charsets that should be ignored.
987
988 When these charsets are used in the \"charset\" parameter, the
989 default charset will be used instead.")
990
991 (defcustom gnus-group-highlight-words-alist nil
992   "Alist of group regexps and highlight regexps.
993 This variable uses the same syntax as `gnus-emphasis-alist'."
994   :version "21.1"
995   :type '(repeat (cons (regexp :tag "Group")
996                        (repeat (list (regexp :tag "Highlight regexp")
997                                      (number :tag "Group for entire word" 0)
998                                      (number :tag "Group for displayed part" 0)
999                                      (symbol :tag "Face"
1000                                              gnus-emphasis-highlight-words)))))
1001   :group 'gnus-summary-visual)
1002
1003 (defcustom gnus-use-wheel nil
1004   "Use Intelli-mouse on summary movement"
1005   :type 'boolean
1006   :group 'gnus-summary-maneuvering)
1007
1008 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1009   "Amount to scroll messages by spinning the mouse wheel.
1010 This is actually a cons cell, where the first item is the amount to scroll
1011 on a normal wheel event, and the second is the amount to scroll when the
1012 wheel is moved with the shift key depressed."
1013   :type '(cons (integer :tag "Shift") integer)
1014   :group 'gnus-summary-maneuvering)
1015
1016 (defcustom gnus-wheel-edge-resistance 2
1017   "How hard it should be to change the current article
1018 by moving the mouse over the edge of the article window."
1019   :type 'integer
1020   :group 'gnus-summary-maneuvering)
1021
1022 (defcustom gnus-summary-show-article-charset-alist
1023   nil
1024   "Alist of number and charset.
1025 The article will be shown with the charset corresponding to the
1026 numbered argument.
1027 For example: ((1 . cn-gb-2312) (2 . big5))."
1028   :version "21.1"
1029   :type '(repeat (cons (number :tag "Argument" 1)
1030                        (symbol :tag "Charset")))
1031   :group 'gnus-charset)
1032
1033 (defcustom gnus-preserve-marks t
1034   "Whether marks are preserved when moving, copying and respooling messages."
1035   :version "21.1"
1036   :type 'boolean
1037   :group 'gnus-summary-marks)
1038
1039 (defcustom gnus-alter-articles-to-read-function nil
1040   "Function to be called to alter the list of articles to be selected."
1041   :type '(choice (const nil) function)
1042   :group 'gnus-summary)
1043
1044 (defcustom gnus-orphan-score nil
1045   "*All orphans get this score added.  Set in the score file."
1046   :group 'gnus-score-default
1047   :type '(choice (const nil)
1048                  integer))
1049
1050 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1051   "*A regexp to match MIME parts when saving multiple parts of a message
1052 with gnus-summary-save-parts (X m). This regexp will be used by default
1053 when prompting the user for which type of files to save."
1054   :group 'gnus-summary
1055   :type 'regexp)
1056
1057 (defcustom gnus-read-all-available-headers nil
1058   "Whether Gnus should parse all headers made available to it.
1059 This is mostly relevant for slow backends where the user may
1060 wish to widen the summary buffer to include all headers
1061 that were fetched.  Say, for nnultimate groups."
1062   :group 'gnus-summary
1063   :type '(choice boolean regexp))
1064
1065 (defcustom gnus-summary-muttprint-program "muttprint"
1066   "Command (and optional arguments) used to run Muttprint."
1067   :version "21.3"
1068   :group 'gnus-summary
1069   :type 'string)
1070
1071 (defcustom gnus-article-loose-mime nil
1072   "If non-nil, don't require MIME-Version header.
1073 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1074 supply the MIME-Version header or deliberately strip it From the mail.
1075 Set it to non-nil, Gnus will treat some articles as MIME even if
1076 the MIME-Version header is missed."
1077   :version "21.3"
1078   :type 'boolean
1079   :group 'gnus-article)
1080
1081 ;;; Internal variables
1082
1083 (defvar gnus-summary-display-cache nil)
1084 (defvar gnus-article-mime-handles nil)
1085 (defvar gnus-article-decoded-p nil)
1086 (defvar gnus-article-charset nil)
1087 (defvar gnus-article-ignored-charsets nil)
1088 (defvar gnus-scores-exclude-files nil)
1089 (defvar gnus-page-broken nil)
1090 (defvar gnus-inhibit-mime-unbuttonizing nil)
1091
1092 (defvar gnus-original-article nil)
1093 (defvar gnus-article-internal-prepare-hook nil)
1094 (defvar gnus-newsgroup-process-stack nil)
1095
1096 (defvar gnus-thread-indent-array nil)
1097 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1098 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1099   "Function called to sort the articles within a thread after it has been gathered together.")
1100
1101 (defvar gnus-summary-save-parts-type-history nil)
1102 (defvar gnus-summary-save-parts-last-directory nil)
1103
1104 ;; Avoid highlighting in kill files.
1105 (defvar gnus-summary-inhibit-highlight nil)
1106 (defvar gnus-newsgroup-selected-overlay nil)
1107 (defvar gnus-inhibit-limiting nil)
1108 (defvar gnus-newsgroup-adaptive-score-file nil)
1109 (defvar gnus-current-score-file nil)
1110 (defvar gnus-current-move-group nil)
1111 (defvar gnus-current-copy-group nil)
1112 (defvar gnus-current-crosspost-group nil)
1113 (defvar gnus-newsgroup-display nil)
1114
1115 (defvar gnus-newsgroup-dependencies nil)
1116 (defvar gnus-newsgroup-adaptive nil)
1117 (defvar gnus-summary-display-article-function nil)
1118 (defvar gnus-summary-highlight-line-function nil
1119   "Function called after highlighting a summary line.")
1120
1121 (defvar gnus-summary-line-format-alist
1122   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1123     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1124     (?s gnus-tmp-subject-or-nil ?s)
1125     (?n gnus-tmp-name ?s)
1126     (?A (std11-address-string
1127          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1128     (?a (or (std11-full-name-string
1129              (car (mime-entity-read-field gnus-tmp-header 'From)))
1130             gnus-tmp-from) ?s)
1131     (?F gnus-tmp-from ?s)
1132     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1133     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1134     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1135     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1136     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1137     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1138     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1139     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1140     (?L gnus-tmp-lines ?s)
1141     (?I gnus-tmp-indentation ?s)
1142     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1143     (?R gnus-tmp-replied ?c)
1144     (?\[ gnus-tmp-opening-bracket ?c)
1145     (?\] gnus-tmp-closing-bracket ?c)
1146     (?\> (make-string gnus-tmp-level ? ) ?s)
1147     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1148     (?i gnus-tmp-score ?d)
1149     (?z gnus-tmp-score-char ?c)
1150     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1151     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1152     (?U gnus-tmp-unread ?c)
1153     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1154         ?s)
1155     (?t (gnus-summary-number-of-articles-in-thread
1156          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1157         ?d)
1158     (?e (gnus-summary-number-of-articles-in-thread
1159          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1160         ?c)
1161     (?u gnus-tmp-user-defined ?s)
1162     (?P (gnus-pick-line-number) ?d)
1163     (?B gnus-tmp-thread-tree-header-string ?s)
1164     (user-date (gnus-user-date
1165                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1166   "An alist of format specifications that can appear in summary lines.
1167 These are paired with what variables they correspond with, along with
1168 the type of the variable (string, integer, character, etc).")
1169
1170 (defvar gnus-summary-dummy-line-format-alist
1171   `((?S gnus-tmp-subject ?s)
1172     (?N gnus-tmp-number ?d)
1173     (?u gnus-tmp-user-defined ?s)))
1174
1175 (defvar gnus-summary-mode-line-format-alist
1176   `((?G gnus-tmp-group-name ?s)
1177     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1178     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1179     (?A gnus-tmp-article-number ?d)
1180     (?Z gnus-tmp-unread-and-unselected ?s)
1181     (?V gnus-version ?s)
1182     (?U gnus-tmp-unread-and-unticked ?d)
1183     (?S gnus-tmp-subject ?s)
1184     (?e gnus-tmp-unselected ?d)
1185     (?u gnus-tmp-user-defined ?s)
1186     (?d (length gnus-newsgroup-dormant) ?d)
1187     (?t (length gnus-newsgroup-marked) ?d)
1188     (?h (length gnus-newsgroup-spam-marked) ?d)
1189     (?r (length gnus-newsgroup-reads) ?d)
1190     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1191     (?E gnus-newsgroup-expunged-tally ?d)
1192     (?s (gnus-current-score-file-nondirectory) ?s)))
1193
1194 (defvar gnus-last-search-regexp nil
1195   "Default regexp for article search command.")
1196
1197 (defvar gnus-summary-search-article-matched-data nil
1198   "Last matched data of article search command.  It is the local variable
1199 in `gnus-article-buffer' which consists of the list of start position,
1200 end position and text.")
1201
1202 (defvar gnus-last-shell-command nil
1203   "Default shell command on article.")
1204
1205 (defvar gnus-newsgroup-begin nil)
1206 (defvar gnus-newsgroup-end nil)
1207 (defvar gnus-newsgroup-last-rmail nil)
1208 (defvar gnus-newsgroup-last-mail nil)
1209 (defvar gnus-newsgroup-last-folder nil)
1210 (defvar gnus-newsgroup-last-file nil)
1211 (defvar gnus-newsgroup-auto-expire nil)
1212 (defvar gnus-newsgroup-active nil)
1213
1214 (defvar gnus-newsgroup-data nil)
1215 (defvar gnus-newsgroup-data-reverse nil)
1216 (defvar gnus-newsgroup-limit nil)
1217 (defvar gnus-newsgroup-limits nil)
1218
1219 (defvar gnus-newsgroup-unreads nil
1220   "Sorted list of unread articles in the current newsgroup.")
1221
1222 (defvar gnus-newsgroup-unselected nil
1223   "Sorted list of unselected unread articles in the current newsgroup.")
1224
1225 (defvar gnus-newsgroup-reads nil
1226   "Alist of read articles and article marks in the current newsgroup.")
1227
1228 (defvar gnus-newsgroup-expunged-tally nil)
1229
1230 (defvar gnus-newsgroup-marked nil
1231   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1232
1233 (defvar gnus-newsgroup-spam-marked nil
1234   "List of ranges of articles that have been marked as spam.")
1235
1236 (defvar gnus-newsgroup-killed nil
1237   "List of ranges of articles that have been through the scoring process.")
1238
1239 (defvar gnus-newsgroup-cached nil
1240   "Sorted list of articles that come from the article cache.")
1241
1242 (defvar gnus-newsgroup-saved nil
1243   "List of articles that have been saved.")
1244
1245 (defvar gnus-newsgroup-kill-headers nil)
1246
1247 (defvar gnus-newsgroup-replied nil
1248   "List of articles that have been replied to in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-forwarded nil
1251   "List of articles that have been forwarded in the current newsgroup.")
1252
1253 (defvar gnus-newsgroup-recent nil
1254   "List of articles that have are recent in the current newsgroup.")
1255
1256 (defvar gnus-newsgroup-expirable nil
1257   "Sorted list of articles in the current newsgroup that can be expired.")
1258
1259 (defvar gnus-newsgroup-processable nil
1260   "List of articles in the current newsgroup that can be processed.")
1261
1262 (defvar gnus-newsgroup-downloadable nil
1263   "Sorted list of articles in the current newsgroup that can be processed.")
1264
1265 (defvar gnus-newsgroup-undownloaded nil
1266   "List of articles in the current newsgroup that haven't been downloaded..")
1267
1268 (defvar gnus-newsgroup-unsendable nil
1269   "List of articles in the current newsgroup that won't be sent.")
1270
1271 (defvar gnus-newsgroup-bookmarks nil
1272   "List of articles in the current newsgroup that have bookmarks.")
1273
1274 (defvar gnus-newsgroup-dormant nil
1275   "Sorted list of dormant articles in the current newsgroup.")
1276
1277 (defvar gnus-newsgroup-unseen nil
1278   "List of unseen articles in the current newsgroup.")
1279
1280 (defvar gnus-newsgroup-seen nil
1281   "Range of seen articles in the current newsgroup.")
1282
1283 (defvar gnus-newsgroup-articles nil
1284   "List of articles in the current newsgroup.")
1285
1286 (defvar gnus-newsgroup-scored nil
1287   "List of scored articles in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-incorporated nil
1290   "List of incorporated articles in the current newsgroup.")
1291
1292 (defvar gnus-newsgroup-headers nil
1293   "List of article headers in the current newsgroup.")
1294
1295 (defvar gnus-newsgroup-threads nil)
1296
1297 (defvar gnus-newsgroup-prepared nil
1298   "Whether the current group has been prepared properly.")
1299
1300 (defvar gnus-newsgroup-ancient nil
1301   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1302
1303 (defvar gnus-newsgroup-sparse nil)
1304
1305 (defvar gnus-current-article nil)
1306 (defvar gnus-article-current nil)
1307 (defvar gnus-current-headers nil)
1308 (defvar gnus-have-all-headers nil)
1309 (defvar gnus-last-article nil)
1310 (defvar gnus-newsgroup-history nil)
1311 (defvar gnus-newsgroup-charset nil)
1312 (defvar gnus-newsgroup-ephemeral-charset nil)
1313 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1314
1315 (defvar gnus-article-before-search nil)
1316
1317 (defconst gnus-summary-local-variables
1318   '(gnus-newsgroup-name
1319     gnus-newsgroup-begin gnus-newsgroup-end
1320     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1321     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1322     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1323     gnus-newsgroup-unselected gnus-newsgroup-marked
1324     gnus-newsgroup-spam-marked
1325     gnus-newsgroup-reads gnus-newsgroup-saved
1326     gnus-newsgroup-replied gnus-newsgroup-forwarded
1327     gnus-newsgroup-recent
1328     gnus-newsgroup-expirable
1329     gnus-newsgroup-processable gnus-newsgroup-killed
1330     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1331     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1332     gnus-newsgroup-seen gnus-newsgroup-articles
1333     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1334     gnus-newsgroup-headers gnus-newsgroup-threads
1335     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1336     gnus-current-article gnus-current-headers gnus-have-all-headers
1337     gnus-last-article gnus-article-internal-prepare-hook
1338     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1339     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1340     gnus-thread-expunge-below
1341     gnus-score-alist gnus-current-score-file
1342     (gnus-summary-expunge-below . global)
1343     (gnus-summary-mark-below . global)
1344     (gnus-orphan-score . global)
1345     gnus-newsgroup-active gnus-scores-exclude-files
1346     gnus-newsgroup-history gnus-newsgroup-ancient
1347     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1348     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1349     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1350     (gnus-newsgroup-expunged-tally . 0)
1351     gnus-cache-removable-articles gnus-newsgroup-cached
1352     gnus-newsgroup-data gnus-newsgroup-data-reverse
1353     gnus-newsgroup-limit gnus-newsgroup-limits
1354     gnus-newsgroup-charset gnus-newsgroup-display
1355     gnus-newsgroup-incorporated)
1356   "Variables that are buffer-local to the summary buffers.")
1357
1358 (defvar gnus-newsgroup-variables nil
1359   "A list of variables that have separate values in different newsgroups.
1360 A list of newsgroup (summary buffer) local variables, or cons of
1361 variables and their default values (when the default values are not
1362 nil), that should be made global while the summary buffer is active.
1363 These variables can be used to set variables in the group parameters
1364 while still allowing them to affect operations done in other
1365 buffers. For example:
1366
1367 \(setq gnus-newsgroup-variables
1368      '(message-use-followup-to
1369        (gnus-visible-headers .
1370          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1371 ")
1372
1373 ;; Byte-compiler warning.
1374 (eval-when-compile (defvar gnus-article-mode-map))
1375
1376 ;; Subject simplification.
1377
1378 (defun gnus-simplify-whitespace (str)
1379   "Remove excessive whitespace from STR."
1380   (let ((mystr str))
1381     ;; Multiple spaces.
1382     (while (string-match "[ \t][ \t]+" mystr)
1383       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1384                           " "
1385                           (substring mystr (match-end 0)))))
1386     ;; Leading spaces.
1387     (when (string-match "^[ \t]+" mystr)
1388       (setq mystr (substring mystr (match-end 0))))
1389     ;; Trailing spaces.
1390     (when (string-match "[ \t]+$" mystr)
1391       (setq mystr (substring mystr 0 (match-beginning 0))))
1392     mystr))
1393
1394 (defun gnus-simplify-all-whitespace (str)
1395   "Remove all whitespace from STR."
1396   (let ((mystr str))
1397     (while (string-match "[ \t\n]+" mystr)
1398       (setq mystr (replace-match "" nil nil mystr)))
1399     mystr))
1400
1401 (defsubst gnus-simplify-subject-re (subject)
1402   "Remove \"Re:\" from subject lines."
1403   (if (string-match message-subject-re-regexp subject)
1404       (substring subject (match-end 0))
1405     subject))
1406
1407 (defun gnus-simplify-subject (subject &optional re-only)
1408   "Remove `Re:' and words in parentheses.
1409 If RE-ONLY is non-nil, strip leading `Re:'s only."
1410   (let ((case-fold-search t))           ;Ignore case.
1411     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1412     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1413       (setq subject (substring subject (match-end 0))))
1414     ;; Remove uninteresting prefixes.
1415     (when (and (not re-only)
1416                gnus-simplify-ignored-prefixes
1417                (string-match gnus-simplify-ignored-prefixes subject))
1418       (setq subject (substring subject (match-end 0))))
1419     ;; Remove words in parentheses from end.
1420     (unless re-only
1421       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1422         (setq subject (substring subject 0 (match-beginning 0)))))
1423     ;; Return subject string.
1424     subject))
1425
1426 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1427 ;; all whitespace.
1428 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1429   (goto-char (point-min))
1430   (while (re-search-forward regexp nil t)
1431     (replace-match (or newtext ""))))
1432
1433 (defun gnus-simplify-buffer-fuzzy ()
1434   "Simplify string in the buffer fuzzily.
1435 The string in the accessible portion of the current buffer is simplified.
1436 It is assumed to be a single-line subject.
1437 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1438 matter is removed.  Additional things can be deleted by setting
1439 `gnus-simplify-subject-fuzzy-regexp'."
1440   (let ((case-fold-search t)
1441         (modified-tick))
1442     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1443
1444     (while (not (eq modified-tick (buffer-modified-tick)))
1445       (setq modified-tick (buffer-modified-tick))
1446       (cond
1447        ((listp gnus-simplify-subject-fuzzy-regexp)
1448         (mapcar 'gnus-simplify-buffer-fuzzy-step
1449                 gnus-simplify-subject-fuzzy-regexp))
1450        (gnus-simplify-subject-fuzzy-regexp
1451         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1452       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1453       (gnus-simplify-buffer-fuzzy-step
1454        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1455       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1456
1457     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1458     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1459     (gnus-simplify-buffer-fuzzy-step " $")
1460     (gnus-simplify-buffer-fuzzy-step "^ +")))
1461
1462 (defun gnus-simplify-subject-fuzzy (subject)
1463   "Simplify a subject string fuzzily.
1464 See `gnus-simplify-buffer-fuzzy' for details."
1465   (save-excursion
1466     (gnus-set-work-buffer)
1467     (let ((case-fold-search t))
1468       ;; Remove uninteresting prefixes.
1469       (when (and gnus-simplify-ignored-prefixes
1470                  (string-match gnus-simplify-ignored-prefixes subject))
1471         (setq subject (substring subject (match-end 0))))
1472       (insert subject)
1473       (inline (gnus-simplify-buffer-fuzzy))
1474       (buffer-string))))
1475
1476 (defsubst gnus-simplify-subject-fully (subject)
1477   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1478   (cond
1479    (gnus-simplify-subject-functions
1480     (gnus-map-function gnus-simplify-subject-functions subject))
1481    ((null gnus-summary-gather-subject-limit)
1482     (gnus-simplify-subject-re subject))
1483    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1484     (gnus-simplify-subject-fuzzy subject))
1485    ((numberp gnus-summary-gather-subject-limit)
1486     (gnus-limit-string (gnus-simplify-subject-re subject)
1487                        gnus-summary-gather-subject-limit))
1488    (t
1489     subject)))
1490
1491 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1492   "Check whether two subjects are equal.
1493 If optional argument simple-first is t, first argument is already
1494 simplified."
1495   (cond
1496    ((null simple-first)
1497     (equal (gnus-simplify-subject-fully s1)
1498            (gnus-simplify-subject-fully s2)))
1499    (t
1500     (equal s1
1501            (gnus-simplify-subject-fully s2)))))
1502
1503 (defun gnus-summary-bubble-group ()
1504   "Increase the score of the current group.
1505 This is a handy function to add to `gnus-summary-exit-hook' to
1506 increase the score of each group you read."
1507   (gnus-group-add-score gnus-newsgroup-name))
1508
1509 \f
1510 ;;;
1511 ;;; Gnus summary mode
1512 ;;;
1513
1514 (put 'gnus-summary-mode 'mode-class 'special)
1515
1516 (defvar gnus-article-commands-menu)
1517
1518 (when t
1519   ;; Non-orthogonal keys
1520
1521   (gnus-define-keys gnus-summary-mode-map
1522     " " gnus-summary-next-page
1523     "\177" gnus-summary-prev-page
1524     [delete] gnus-summary-prev-page
1525     [backspace] gnus-summary-prev-page
1526     "\r" gnus-summary-scroll-up
1527     "\M-\r" gnus-summary-scroll-down
1528     "n" gnus-summary-next-unread-article
1529     "p" gnus-summary-prev-unread-article
1530     "N" gnus-summary-next-article
1531     "P" gnus-summary-prev-article
1532     "\M-\C-n" gnus-summary-next-same-subject
1533     "\M-\C-p" gnus-summary-prev-same-subject
1534     "\M-n" gnus-summary-next-unread-subject
1535     "\M-p" gnus-summary-prev-unread-subject
1536     "." gnus-summary-first-unread-article
1537     "," gnus-summary-best-unread-article
1538     "\M-s" gnus-summary-search-article-forward
1539     "\M-r" gnus-summary-search-article-backward
1540     "<" gnus-summary-beginning-of-article
1541     ">" gnus-summary-end-of-article
1542     "j" gnus-summary-goto-article
1543     "^" gnus-summary-refer-parent-article
1544     "\M-^" gnus-summary-refer-article
1545     "u" gnus-summary-tick-article-forward
1546     "!" gnus-summary-tick-article-forward
1547     "U" gnus-summary-tick-article-backward
1548     "d" gnus-summary-mark-as-read-forward
1549     "D" gnus-summary-mark-as-read-backward
1550     "E" gnus-summary-mark-as-expirable
1551     "\M-u" gnus-summary-clear-mark-forward
1552     "\M-U" gnus-summary-clear-mark-backward
1553     "k" gnus-summary-kill-same-subject-and-select
1554     "\C-k" gnus-summary-kill-same-subject
1555     "\M-\C-k" gnus-summary-kill-thread
1556     "\M-\C-l" gnus-summary-lower-thread
1557     "e" gnus-summary-edit-article
1558     "#" gnus-summary-mark-as-processable
1559     "\M-#" gnus-summary-unmark-as-processable
1560     "\M-\C-t" gnus-summary-toggle-threads
1561     "\M-\C-s" gnus-summary-show-thread
1562     "\M-\C-h" gnus-summary-hide-thread
1563     "\M-\C-f" gnus-summary-next-thread
1564     "\M-\C-b" gnus-summary-prev-thread
1565     [(meta down)] gnus-summary-next-thread
1566     [(meta up)] gnus-summary-prev-thread
1567     "\M-\C-u" gnus-summary-up-thread
1568     "\M-\C-d" gnus-summary-down-thread
1569     "&" gnus-summary-execute-command
1570     "c" gnus-summary-catchup-and-exit
1571     "\C-w" gnus-summary-mark-region-as-read
1572     "\C-t" gnus-summary-toggle-truncation
1573     "?" gnus-summary-mark-as-dormant
1574     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1575     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1576     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1577     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1578     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1579     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1580     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1581     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1582     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1583     "\C-c\C-s\C-r" gnus-summary-sort-by-random
1584     "=" gnus-summary-expand-window
1585     "\C-x\C-s" gnus-summary-reselect-current-group
1586     "\M-g" gnus-summary-rescan-group
1587     "w" gnus-summary-stop-page-breaking
1588     "\C-c\C-r" gnus-summary-caesar-message
1589     "\M-t" gnus-summary-toggle-mime
1590     "f" gnus-summary-followup
1591     "F" gnus-summary-followup-with-original
1592     "C" gnus-summary-cancel-article
1593     "r" gnus-summary-reply
1594     "R" gnus-summary-reply-with-original
1595     "\C-c\C-f" gnus-summary-mail-forward
1596     "o" gnus-summary-save-article
1597     "\C-o" gnus-summary-save-article-mail
1598     "|" gnus-summary-pipe-output
1599     "\M-k" gnus-summary-edit-local-kill
1600     "\M-K" gnus-summary-edit-global-kill
1601     ;; "V" gnus-version
1602     "\C-c\C-d" gnus-summary-describe-group
1603     "q" gnus-summary-exit
1604     "Q" gnus-summary-exit-no-update
1605     "\C-c\C-i" gnus-info-find-node
1606     gnus-mouse-2 gnus-mouse-pick-article
1607     "m" gnus-summary-mail-other-window
1608     "a" gnus-summary-post-news
1609     "i" gnus-summary-news-other-window
1610     "x" gnus-summary-limit-to-unread
1611     "s" gnus-summary-isearch-article
1612     "t" gnus-summary-toggle-header
1613     "g" gnus-summary-show-article
1614     "l" gnus-summary-goto-last-article
1615     "v" gnus-summary-preview-mime-message
1616     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1617     "\C-d" gnus-summary-enter-digest-group
1618     "\M-\C-d" gnus-summary-read-document
1619     "\M-\C-e" gnus-summary-edit-parameters
1620     "\M-\C-a" gnus-summary-customize-parameters
1621     "\C-c\C-b" gnus-bug
1622     "\C-c\C-n" gnus-namazu-search
1623     "*" gnus-cache-enter-article
1624     "\M-*" gnus-cache-remove-article
1625     "\M-&" gnus-summary-universal-argument
1626     "\C-l" gnus-recenter
1627     "I" gnus-summary-increase-score
1628     "L" gnus-summary-lower-score
1629     "\M-i" gnus-symbolic-argument
1630     "h" gnus-summary-select-article-buffer
1631
1632     "V" gnus-summary-score-map
1633     "X" gnus-uu-extract-map
1634     "S" gnus-summary-send-map)
1635
1636   ;; Sort of orthogonal keymap
1637   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1638     "t" gnus-summary-tick-article-forward
1639     "!" gnus-summary-tick-article-forward
1640     "d" gnus-summary-mark-as-read-forward
1641     "r" gnus-summary-mark-as-read-forward
1642     "c" gnus-summary-clear-mark-forward
1643     " " gnus-summary-clear-mark-forward
1644     "e" gnus-summary-mark-as-expirable
1645     "x" gnus-summary-mark-as-expirable
1646     "?" gnus-summary-mark-as-dormant
1647     "b" gnus-summary-set-bookmark
1648     "B" gnus-summary-remove-bookmark
1649     "#" gnus-summary-mark-as-processable
1650     "\M-#" gnus-summary-unmark-as-processable
1651     "S" gnus-summary-limit-include-expunged
1652     "C" gnus-summary-catchup
1653     "H" gnus-summary-catchup-to-here
1654     "h" gnus-summary-catchup-from-here
1655     "\C-c" gnus-summary-catchup-all
1656     "k" gnus-summary-kill-same-subject-and-select
1657     "K" gnus-summary-kill-same-subject
1658     "P" gnus-uu-mark-map)
1659
1660   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1661     "c" gnus-summary-clear-above
1662     "u" gnus-summary-tick-above
1663     "m" gnus-summary-mark-above
1664     "k" gnus-summary-kill-below)
1665
1666   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1667     "/" gnus-summary-limit-to-subject
1668     "n" gnus-summary-limit-to-articles
1669     "w" gnus-summary-pop-limit
1670     "s" gnus-summary-limit-to-subject
1671     "a" gnus-summary-limit-to-author
1672     "u" gnus-summary-limit-to-unread
1673     "m" gnus-summary-limit-to-marks
1674     "M" gnus-summary-limit-exclude-marks
1675     "v" gnus-summary-limit-to-score
1676     "*" gnus-summary-limit-include-cached
1677     "D" gnus-summary-limit-include-dormant
1678     "T" gnus-summary-limit-include-thread
1679     "d" gnus-summary-limit-exclude-dormant
1680     "t" gnus-summary-limit-to-age
1681     "." gnus-summary-limit-to-unseen
1682     "x" gnus-summary-limit-to-extra
1683     "p" gnus-summary-limit-to-display-predicate
1684     "E" gnus-summary-limit-include-expunged
1685     "c" gnus-summary-limit-exclude-childless-dormant
1686     "C" gnus-summary-limit-mark-excluded-as-read
1687     "o" gnus-summary-insert-old-articles
1688     "N" gnus-summary-insert-new-articles)
1689
1690   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1691     "n" gnus-summary-next-unread-article
1692     "p" gnus-summary-prev-unread-article
1693     "N" gnus-summary-next-article
1694     "P" gnus-summary-prev-article
1695     "\C-n" gnus-summary-next-same-subject
1696     "\C-p" gnus-summary-prev-same-subject
1697     "\M-n" gnus-summary-next-unread-subject
1698     "\M-p" gnus-summary-prev-unread-subject
1699     "f" gnus-summary-first-unread-article
1700     "b" gnus-summary-best-unread-article
1701     "j" gnus-summary-goto-article
1702     "g" gnus-summary-goto-subject
1703     "l" gnus-summary-goto-last-article
1704     "o" gnus-summary-pop-article)
1705
1706   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1707     "k" gnus-summary-kill-thread
1708     "l" gnus-summary-lower-thread
1709     "i" gnus-summary-raise-thread
1710     "T" gnus-summary-toggle-threads
1711     "t" gnus-summary-rethread-current
1712     "^" gnus-summary-reparent-thread
1713     "s" gnus-summary-show-thread
1714     "S" gnus-summary-show-all-threads
1715     "h" gnus-summary-hide-thread
1716     "H" gnus-summary-hide-all-threads
1717     "n" gnus-summary-next-thread
1718     "p" gnus-summary-prev-thread
1719     "u" gnus-summary-up-thread
1720     "o" gnus-summary-top-thread
1721     "d" gnus-summary-down-thread
1722     "#" gnus-uu-mark-thread
1723     "\M-#" gnus-uu-unmark-thread)
1724
1725   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1726     "g" gnus-summary-prepare
1727     "c" gnus-summary-insert-cached-articles)
1728
1729   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1730     "c" gnus-summary-catchup-and-exit
1731     "C" gnus-summary-catchup-all-and-exit
1732     "E" gnus-summary-exit-no-update
1733     "J" gnus-summary-jump-to-other-group
1734     "Q" gnus-summary-exit
1735     "Z" gnus-summary-exit
1736     "n" gnus-summary-catchup-and-goto-next-group
1737     "R" gnus-summary-reselect-current-group
1738     "G" gnus-summary-rescan-group
1739     "N" gnus-summary-next-group
1740     "s" gnus-summary-save-newsrc
1741     "P" gnus-summary-prev-group)
1742
1743   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1744     " " gnus-summary-next-page
1745     "n" gnus-summary-next-page
1746     "\177" gnus-summary-prev-page
1747     [delete] gnus-summary-prev-page
1748     "p" gnus-summary-prev-page
1749     "\r" gnus-summary-scroll-up
1750     "\M-\r" gnus-summary-scroll-down
1751     "<" gnus-summary-beginning-of-article
1752     ">" gnus-summary-end-of-article
1753     "b" gnus-summary-beginning-of-article
1754     "e" gnus-summary-end-of-article
1755     "^" gnus-summary-refer-parent-article
1756     "r" gnus-summary-refer-parent-article
1757     "D" gnus-summary-enter-digest-group
1758     "R" gnus-summary-refer-references
1759     "T" gnus-summary-refer-thread
1760     "g" gnus-summary-show-article
1761     "s" gnus-summary-isearch-article
1762     "P" gnus-summary-print-article
1763     "M" gnus-mailing-list-insinuate
1764     "t" gnus-article-babel)
1765
1766   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1767     "b" gnus-article-add-buttons
1768     "B" gnus-article-add-buttons-to-head
1769     "o" gnus-article-treat-overstrike
1770     "e" gnus-article-emphasize
1771     "w" gnus-article-fill-cited-article
1772     "Q" gnus-article-fill-long-lines
1773     "C" gnus-article-capitalize-sentences
1774     "c" gnus-article-remove-cr
1775     "Z" gnus-article-decode-HZ
1776     "h" gnus-article-wash-html
1777     "u" gnus-article-unsplit-urls
1778     "f" gnus-article-display-x-face
1779     "l" gnus-summary-stop-page-breaking
1780     "r" gnus-summary-caesar-message
1781     "t" gnus-summary-toggle-header
1782     "g" gnus-treat-smiley
1783     "v" gnus-summary-verbose-headers
1784     "m" gnus-summary-toggle-mime
1785     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1786     "p" gnus-article-verify-x-pgp-sig
1787     "d" gnus-article-treat-dumbquotes
1788     "k" gnus-article-outlook-deuglify-article)
1789
1790   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1791     "a" gnus-article-hide
1792     "h" gnus-article-hide-headers
1793     "b" gnus-article-hide-boring-headers
1794     "s" gnus-article-hide-signature
1795     "c" gnus-article-hide-citation
1796     "C" gnus-article-hide-citation-in-followups
1797     "l" gnus-article-hide-list-identifiers
1798     "p" gnus-article-hide-pgp
1799     "B" gnus-article-strip-banner
1800     "P" gnus-article-hide-pem
1801     "\C-c" gnus-article-hide-citation-maybe)
1802
1803   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1804     "a" gnus-article-highlight
1805     "h" gnus-article-highlight-headers
1806     "c" gnus-article-highlight-citation
1807     "s" gnus-article-highlight-signature)
1808
1809   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1810     "f" gnus-article-treat-fold-headers
1811     "u" gnus-article-treat-unfold-headers
1812     "n" gnus-article-treat-fold-newsgroups)
1813
1814   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1815     "x" gnus-article-display-x-face
1816     "s" gnus-treat-smiley
1817     "D" gnus-article-remove-images
1818     "f" gnus-treat-from-picon
1819     "m" gnus-treat-mail-picon
1820     "n" gnus-treat-newsgroups-picon)
1821
1822   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1823     "z" gnus-article-date-ut
1824     "u" gnus-article-date-ut
1825     "l" gnus-article-date-local
1826     "p" gnus-article-date-english
1827     "e" gnus-article-date-lapsed
1828     "o" gnus-article-date-original
1829     "i" gnus-article-date-iso8601
1830     "s" gnus-article-date-user)
1831
1832   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1833     "t" gnus-article-remove-trailing-blank-lines
1834     "l" gnus-article-strip-leading-blank-lines
1835     "m" gnus-article-strip-multiple-blank-lines
1836     "a" gnus-article-strip-blank-lines
1837     "A" gnus-article-strip-all-blank-lines
1838     "s" gnus-article-strip-leading-space
1839     "e" gnus-article-strip-trailing-space
1840     "w" gnus-article-remove-leading-whitespace)
1841
1842   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1843     "v" gnus-version
1844     "f" gnus-summary-fetch-faq
1845     "d" gnus-summary-describe-group
1846     "h" gnus-summary-describe-briefly
1847     "i" gnus-info-find-node
1848     "c" gnus-group-fetch-charter
1849     "C" gnus-group-fetch-control)
1850
1851   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1852     "e" gnus-summary-expire-articles
1853     "\M-\C-e" gnus-summary-expire-articles-now
1854     "\177" gnus-summary-delete-article
1855     [delete] gnus-summary-delete-article
1856     [backspace] gnus-summary-delete-article
1857     "m" gnus-summary-move-article
1858     "r" gnus-summary-respool-article
1859     "w" gnus-summary-edit-article
1860     "c" gnus-summary-copy-article
1861     "B" gnus-summary-crosspost-article
1862     "q" gnus-summary-respool-query
1863     "t" gnus-summary-respool-trace
1864     "i" gnus-summary-import-article
1865     "I" gnus-summary-create-article
1866     "p" gnus-summary-article-posted-p)
1867
1868   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1869     "o" gnus-summary-save-article
1870     "m" gnus-summary-save-article-mail
1871     "F" gnus-summary-write-article-file
1872     "r" gnus-summary-save-article-rmail
1873     "f" gnus-summary-save-article-file
1874     "b" gnus-summary-save-article-body-file
1875     "h" gnus-summary-save-article-folder
1876     "v" gnus-summary-save-article-vm
1877     "p" gnus-summary-pipe-output
1878     "P" gnus-summary-muttprint
1879     "s" gnus-soup-add-article)
1880
1881   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1882     "b" gnus-summary-display-buttonized
1883     "m" gnus-summary-repair-multipart
1884     "v" gnus-article-view-part
1885     "o" gnus-article-save-part
1886     "c" gnus-article-copy-part
1887     "C" gnus-article-view-part-as-charset
1888     "e" gnus-article-view-part-externally
1889     "E" gnus-article-encrypt-body
1890     "i" gnus-article-inline-part
1891     "|" gnus-article-pipe-part)
1892
1893   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1894     "p" gnus-summary-mark-as-processable
1895     "u" gnus-summary-unmark-as-processable
1896     "U" gnus-summary-unmark-all-processable
1897     "v" gnus-uu-mark-over
1898     "s" gnus-uu-mark-series
1899     "r" gnus-uu-mark-region
1900     "g" gnus-uu-unmark-region
1901     "R" gnus-uu-mark-by-regexp
1902     "G" gnus-uu-unmark-by-regexp
1903     "t" gnus-uu-mark-thread
1904     "T" gnus-uu-unmark-thread
1905     "a" gnus-uu-mark-all
1906     "b" gnus-uu-mark-buffer
1907     "S" gnus-uu-mark-sparse
1908     "k" gnus-summary-kill-process-mark
1909     "y" gnus-summary-yank-process-mark
1910     "w" gnus-summary-save-process-mark
1911     "i" gnus-uu-invert-processable)
1912
1913   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1914     ;;"x" gnus-uu-extract-any
1915     "m" gnus-summary-save-parts
1916     "u" gnus-uu-decode-uu
1917     "U" gnus-uu-decode-uu-and-save
1918     "s" gnus-uu-decode-unshar
1919     "S" gnus-uu-decode-unshar-and-save
1920     "o" gnus-uu-decode-save
1921     "O" gnus-uu-decode-save
1922     "b" gnus-uu-decode-binhex
1923     "B" gnus-uu-decode-binhex
1924     "p" gnus-uu-decode-postscript
1925     "P" gnus-uu-decode-postscript-and-save)
1926
1927   (gnus-define-keys
1928       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1929     "u" gnus-uu-decode-uu-view
1930     "U" gnus-uu-decode-uu-and-save-view
1931     "s" gnus-uu-decode-unshar-view
1932     "S" gnus-uu-decode-unshar-and-save-view
1933     "o" gnus-uu-decode-save-view
1934     "O" gnus-uu-decode-save-view
1935     "b" gnus-uu-decode-binhex-view
1936     "B" gnus-uu-decode-binhex-view
1937     "p" gnus-uu-decode-postscript-view
1938     "P" gnus-uu-decode-postscript-and-save-view))
1939
1940 (defvar gnus-article-post-menu nil)
1941
1942 (defconst gnus-summary-menu-maxlen 20)
1943
1944 (defun gnus-summary-menu-split (menu)
1945   ;; If we have lots of elements, divide them into groups of 20
1946   ;; and make a pane (or submenu) for each one.
1947   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
1948       (let ((menu menu) sublists next
1949             (i 1))
1950         (while menu
1951           ;; Pull off the next gnus-summary-menu-maxlen elements
1952           ;; and make them the next element of sublist.
1953           (setq next (nthcdr gnus-summary-menu-maxlen menu))
1954           (if next
1955               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
1956                       nil))
1957           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
1958                                              (aref (car (last menu)) 0)) menu)
1959                                sublists))
1960           (setq i (1+ i))
1961           (setq menu next))
1962         (nreverse sublists))
1963     ;; Few elements--put them all in one pane.
1964     menu))
1965
1966 (defun gnus-summary-make-menu-bar ()
1967   (gnus-turn-off-edit-menu 'summary)
1968
1969   (unless (boundp 'gnus-summary-misc-menu)
1970
1971     (easy-menu-define
1972      gnus-summary-kill-menu gnus-summary-mode-map ""
1973      (cons
1974       "Score"
1975       (nconc
1976        (list
1977         ["Customize" gnus-score-customize t])
1978        (gnus-make-score-map 'increase)
1979        (gnus-make-score-map 'lower)
1980        '(("Mark"
1981           ["Kill below" gnus-summary-kill-below t]
1982           ["Mark above" gnus-summary-mark-above t]
1983           ["Tick above" gnus-summary-tick-above t]
1984           ["Clear above" gnus-summary-clear-above t])
1985          ["Current score" gnus-summary-current-score t]
1986          ["Set score" gnus-summary-set-score t]
1987          ["Switch current score file..." gnus-score-change-score-file t]
1988          ["Set mark below..." gnus-score-set-mark-below t]
1989          ["Set expunge below..." gnus-score-set-expunge-below t]
1990          ["Edit current score file" gnus-score-edit-current-scores t]
1991          ["Edit score file" gnus-score-edit-file t]
1992          ["Trace score" gnus-score-find-trace t]
1993          ["Find words" gnus-score-find-favourite-words t]
1994          ["Rescore buffer" gnus-summary-rescore t]
1995          ["Increase score..." gnus-summary-increase-score t]
1996          ["Lower score..." gnus-summary-lower-score t]))))
1997
1998     ;; Define both the Article menu in the summary buffer and the
1999     ;; equivalent Commands menu in the article buffer here for
2000     ;; consistency.
2001     (let ((innards
2002            `(("Hide"
2003               ["All" gnus-article-hide t]
2004               ["Headers" gnus-article-hide-headers t]
2005               ["Signature" gnus-article-hide-signature t]
2006               ["Citation" gnus-article-hide-citation t]
2007               ["List identifiers" gnus-article-hide-list-identifiers t]
2008               ["PGP" gnus-article-hide-pgp t]
2009               ["Banner" gnus-article-strip-banner t]
2010               ["Boring headers" gnus-article-hide-boring-headers t])
2011              ("Highlight"
2012               ["All" gnus-article-highlight t]
2013               ["Headers" gnus-article-highlight-headers t]
2014               ["Signature" gnus-article-highlight-signature t]
2015               ["Citation" gnus-article-highlight-citation t])
2016              ("Date"
2017               ["Local" gnus-article-date-local t]
2018               ["ISO8601" gnus-article-date-iso8601 t]
2019               ["UT" gnus-article-date-ut t]
2020               ["Original" gnus-article-date-original t]
2021               ["Lapsed" gnus-article-date-lapsed t]
2022               ["User-defined" gnus-article-date-user t])
2023              ("Display"
2024               ["Remove images" gnus-article-remove-images t]
2025               ["Toggle smiley" gnus-treat-smiley t]
2026               ["Show X-Face" gnus-article-display-x-face t]
2027               ["Show picons in From" gnus-treat-from-picon t]
2028               ["Show picons in mail headers" gnus-treat-mail-picon t]
2029               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2030               ("View as different encoding"
2031                ,@(gnus-summary-menu-split
2032                   (mapcar
2033                    (lambda (cs)
2034                      ;; Since easymenu under FSF Emacs doesn't allow lambda
2035                      ;; forms for menu commands, we should provide intern'ed
2036                      ;; function symbols.
2037                      (let ((command (intern (format "\
2038 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2039                        (fset command
2040                              `(lambda ()
2041                                 (interactive)
2042                                 (let ((gnus-summary-show-article-charset-alist
2043                                        '((1 . ,cs))))
2044                                   (gnus-summary-show-article 1))))
2045                        `[,(symbol-name cs) ,command t]))
2046                    (sort (if (fboundp 'coding-system-list)
2047                              (coding-system-list)
2048                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2049                            )
2050                          'string<)))))
2051              ("Washing"
2052               ("Remove Blanks"
2053                ["Leading" gnus-article-strip-leading-blank-lines t]
2054                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2055                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2056                ["All of the above" gnus-article-strip-blank-lines t]
2057                ["All" gnus-article-strip-all-blank-lines t]
2058                ["Leading space" gnus-article-strip-leading-space t]
2059                ["Trailing space" gnus-article-strip-trailing-space t]
2060                ["Leading space in headers"
2061                 gnus-article-remove-leading-whitespace t])
2062               ["Overstrike" gnus-article-treat-overstrike t]
2063               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2064               ["Emphasis" gnus-article-emphasize t]
2065               ["Word wrap" gnus-article-fill-cited-article t]
2066               ["Fill long lines" gnus-article-fill-long-lines t]
2067               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2068               ["CR" gnus-article-remove-cr t]
2069               ["Rot 13" gnus-summary-caesar-message
2070                ,@(if (featurep 'xemacs) '(t)
2071                    '(:help "\"Caesar rotate\" article by 13"))]
2072               ["Unix pipe..." gnus-summary-pipe-message t]
2073               ["Add buttons" gnus-article-add-buttons t]
2074               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2075               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2076               ["Toggle MIME" gnus-summary-toggle-mime t]
2077               ["Verbose header" gnus-summary-verbose-headers t]
2078               ["Toggle header" gnus-summary-toggle-header t]
2079               ["Unfold headers" gnus-article-treat-unfold-headers t]
2080               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2081               ["Html" gnus-article-wash-html t]
2082               ["URLs" gnus-article-unsplit-urls t]
2083               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2084               ["HZ" gnus-article-decode-HZ t]
2085               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2086               )
2087              ("Output"
2088               ["Save in default format" gnus-summary-save-article
2089                ,@(if (featurep 'xemacs) '(t)
2090                    '(:help "Save article using default method"))]
2091               ["Save in file" gnus-summary-save-article-file
2092                ,@(if (featurep 'xemacs) '(t)
2093                    '(:help "Save article in file"))]
2094               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2095               ["Save in MH folder" gnus-summary-save-article-folder t]
2096               ["Save in VM folder" gnus-summary-save-article-vm t]
2097               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2098               ["Save body in file" gnus-summary-save-article-body-file t]
2099               ["Pipe through a filter" gnus-summary-pipe-output t]
2100               ["Add to SOUP packet" gnus-soup-add-article t]
2101               ["Print with Muttprint" gnus-summary-muttprint t]
2102               ["Print" gnus-summary-print-article t])
2103              ("Backend"
2104               ["Respool article..." gnus-summary-respool-article t]
2105               ["Move article..." gnus-summary-move-article
2106                (gnus-check-backend-function
2107                 'request-move-article gnus-newsgroup-name)]
2108               ["Copy article..." gnus-summary-copy-article t]
2109               ["Crosspost article..." gnus-summary-crosspost-article
2110                (gnus-check-backend-function
2111                 'request-replace-article gnus-newsgroup-name)]
2112               ["Import file..." gnus-summary-import-article t]
2113               ["Create article..." gnus-summary-create-article t]
2114               ["Check if posted" gnus-summary-article-posted-p t]
2115               ["Edit article" gnus-summary-edit-article
2116                (not (gnus-group-read-only-p))]
2117               ["Delete article" gnus-summary-delete-article
2118                (gnus-check-backend-function
2119                 'request-expire-articles gnus-newsgroup-name)]
2120               ["Query respool" gnus-summary-respool-query t]
2121               ["Trace respool" gnus-summary-respool-trace t]
2122               ["Delete expirable articles" gnus-summary-expire-articles-now
2123                (gnus-check-backend-function
2124                 'request-expire-articles gnus-newsgroup-name)])
2125              ("Extract"
2126               ["Uudecode" gnus-uu-decode-uu
2127                ,@(if (featurep 'xemacs) '(t)
2128                    '(:help "Decode uuencoded article(s)"))]
2129               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2130               ["Unshar" gnus-uu-decode-unshar t]
2131               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2132               ["Save" gnus-uu-decode-save t]
2133               ["Binhex" gnus-uu-decode-binhex t]
2134               ["Postscript" gnus-uu-decode-postscript t])
2135              ("Cache"
2136               ["Enter article" gnus-cache-enter-article t]
2137               ["Remove article" gnus-cache-remove-article t])
2138              ["Translate" gnus-article-babel t]
2139              ["Select article buffer" gnus-summary-select-article-buffer t]
2140              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2141              ["Isearch article..." gnus-summary-isearch-article t]
2142              ["Beginning of the article" gnus-summary-beginning-of-article t]
2143              ["End of the article" gnus-summary-end-of-article t]
2144              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2145              ["Fetch referenced articles" gnus-summary-refer-references t]
2146              ["Fetch current thread" gnus-summary-refer-thread t]
2147              ["Fetch article with id..." gnus-summary-refer-article t]
2148              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2149              ["Redisplay" gnus-summary-show-article t]
2150              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2151       (easy-menu-define
2152        gnus-summary-article-menu gnus-summary-mode-map ""
2153        (cons "Article" innards))
2154
2155       (if (not (keymapp gnus-summary-article-menu))
2156           (easy-menu-define
2157            gnus-article-commands-menu gnus-article-mode-map ""
2158            (cons "Commands" innards))
2159         ;; in Emacs, don't share menu.
2160         (setq gnus-article-commands-menu
2161               (copy-keymap gnus-summary-article-menu))
2162         (define-key gnus-article-mode-map [menu-bar commands]
2163           (cons "Commands" gnus-article-commands-menu))))
2164
2165     (easy-menu-define
2166      gnus-summary-thread-menu gnus-summary-mode-map ""
2167      '("Threads"
2168        ["Toggle threading" gnus-summary-toggle-threads t]
2169        ["Hide threads" gnus-summary-hide-all-threads t]
2170        ["Show threads" gnus-summary-show-all-threads t]
2171        ["Hide thread" gnus-summary-hide-thread t]
2172        ["Show thread" gnus-summary-show-thread t]
2173        ["Go to next thread" gnus-summary-next-thread t]
2174        ["Go to previous thread" gnus-summary-prev-thread t]
2175        ["Go down thread" gnus-summary-down-thread t]
2176        ["Go up thread" gnus-summary-up-thread t]
2177        ["Top of thread" gnus-summary-top-thread t]
2178        ["Mark thread as read" gnus-summary-kill-thread t]
2179        ["Lower thread score" gnus-summary-lower-thread t]
2180        ["Raise thread score" gnus-summary-raise-thread t]
2181        ["Rethread current" gnus-summary-rethread-current t]))
2182
2183     (easy-menu-define
2184      gnus-summary-post-menu gnus-summary-mode-map ""
2185      `("Post"
2186        ["Send a message (mail or news)" gnus-summary-post-news
2187         ,@(if (featurep 'xemacs) '(t)
2188             '(:help "Post an article"))]
2189        ["Followup" gnus-summary-followup
2190         ,@(if (featurep 'xemacs) '(t)
2191             '(:help "Post followup to this article"))]
2192        ["Followup and yank" gnus-summary-followup-with-original
2193         ,@(if (featurep 'xemacs) '(t)
2194             '(:help "Post followup to this article, quoting its contents"))]
2195        ["Supersede article" gnus-summary-supersede-article t]
2196        ["Cancel article" gnus-summary-cancel-article
2197         ,@(if (featurep 'xemacs) '(t)
2198             '(:help "Cancel an article you posted"))]
2199        ["Reply" gnus-summary-reply t]
2200        ["Reply and yank" gnus-summary-reply-with-original t]
2201        ["Wide reply" gnus-summary-wide-reply t]
2202        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2203         ,@(if (featurep 'xemacs) '(t)
2204             '(:help "Mail a reply, quoting this article"))]
2205        ["Very wide reply" gnus-summary-very-wide-reply t]
2206        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2207         ,@(if (featurep 'xemacs) '(t)
2208             '(:help "Mail a very wide reply, quoting this article"))]
2209        ["Mail forward" gnus-summary-mail-forward t]
2210        ["Post forward" gnus-summary-post-forward t]
2211        ["Digest and mail" gnus-summary-digest-mail-forward t]
2212        ["Digest and post" gnus-summary-digest-post-forward t]
2213        ["Resend message" gnus-summary-resend-message t]
2214        ["Resend message edit" gnus-summary-resend-message-edit t]
2215        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2216        ["Send a mail" gnus-summary-mail-other-window t]
2217        ["Create a local message" gnus-summary-news-other-window t]
2218        ["Uuencode and post" gnus-uu-post-news
2219         ,@(if (featurep 'xemacs) '(t)
2220             '(:help "Post a uuencoded article"))]
2221        ["Followup via news" gnus-summary-followup-to-mail t]
2222        ["Followup via news and yank"
2223         gnus-summary-followup-to-mail-with-original t]
2224        ;;("Draft"
2225        ;;["Send" gnus-summary-send-draft t]
2226        ;;["Send bounced" gnus-resend-bounced-mail t])
2227        ))
2228
2229     (cond
2230      ((not (keymapp gnus-summary-post-menu))
2231       (setq gnus-article-post-menu gnus-summary-post-menu))
2232      ((not gnus-article-post-menu)
2233       ;; Don't share post menu.
2234       (setq gnus-article-post-menu
2235             (copy-keymap gnus-summary-post-menu))))
2236     (define-key gnus-article-mode-map [menu-bar post]
2237       (cons "Post" gnus-article-post-menu))
2238
2239     (easy-menu-define
2240      gnus-summary-misc-menu gnus-summary-mode-map ""
2241      `("Gnus"
2242        ("Mark Read"
2243         ["Mark as read" gnus-summary-mark-as-read-forward t]
2244         ["Mark same subject and select"
2245          gnus-summary-kill-same-subject-and-select t]
2246         ["Mark same subject" gnus-summary-kill-same-subject t]
2247         ["Catchup" gnus-summary-catchup
2248          ,@(if (featurep 'xemacs) '(t)
2249              '(:help "Mark unread articles in this group as read"))]
2250         ["Catchup all" gnus-summary-catchup-all t]
2251         ["Catchup to here" gnus-summary-catchup-to-here t]
2252         ["Catchup from here" gnus-summary-catchup-from-here t]
2253         ["Catchup region" gnus-summary-mark-region-as-read t]
2254         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2255        ("Mark Various"
2256         ["Tick" gnus-summary-tick-article-forward t]
2257         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2258         ["Remove marks" gnus-summary-clear-mark-forward t]
2259         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2260         ["Set bookmark" gnus-summary-set-bookmark t]
2261         ["Remove bookmark" gnus-summary-remove-bookmark t])
2262        ("Limit to"
2263         ["Marks..." gnus-summary-limit-to-marks t]
2264         ["Subject..." gnus-summary-limit-to-subject t]
2265         ["Author..." gnus-summary-limit-to-author t]
2266         ["Age..." gnus-summary-limit-to-age t]
2267         ["Extra..." gnus-summary-limit-to-extra t]
2268         ["Score..." gnus-summary-limit-to-score t]
2269         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2270         ["Unread" gnus-summary-limit-to-unread t]
2271         ["Unseen" gnus-summary-limit-to-unseen t]
2272         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2273         ["Articles" gnus-summary-limit-to-articles t]
2274         ["Pop limit" gnus-summary-pop-limit t]
2275         ["Show dormant" gnus-summary-limit-include-dormant t]
2276         ["Hide childless dormant"
2277          gnus-summary-limit-exclude-childless-dormant t]
2278         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2279         ["Hide marked" gnus-summary-limit-exclude-marks t]
2280         ["Show expunged" gnus-summary-limit-include-expunged t])
2281        ("Process Mark"
2282         ["Set mark" gnus-summary-mark-as-processable t]
2283         ["Remove mark" gnus-summary-unmark-as-processable t]
2284         ["Remove all marks" gnus-summary-unmark-all-processable t]
2285         ["Mark above" gnus-uu-mark-over t]
2286         ["Mark series" gnus-uu-mark-series t]
2287         ["Mark region" gnus-uu-mark-region t]
2288         ["Unmark region" gnus-uu-unmark-region t]
2289         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2290         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2291         ["Mark all" gnus-uu-mark-all t]
2292         ["Mark buffer" gnus-uu-mark-buffer t]
2293         ["Mark sparse" gnus-uu-mark-sparse t]
2294         ["Mark thread" gnus-uu-mark-thread t]
2295         ["Unmark thread" gnus-uu-unmark-thread t]
2296         ("Process Mark Sets"
2297          ["Kill" gnus-summary-kill-process-mark t]
2298          ["Yank" gnus-summary-yank-process-mark
2299           gnus-newsgroup-process-stack]
2300          ["Save" gnus-summary-save-process-mark t]))
2301        ("Scroll article"
2302         ["Page forward" gnus-summary-next-page
2303          ,@(if (featurep 'xemacs) '(t)
2304              '(:help "Show next page of article"))]
2305         ["Page backward" gnus-summary-prev-page
2306          ,@(if (featurep 'xemacs) '(t)
2307              '(:help "Show previous page of article"))]
2308         ["Line forward" gnus-summary-scroll-up t])
2309        ("Move"
2310         ["Next unread article" gnus-summary-next-unread-article t]
2311         ["Previous unread article" gnus-summary-prev-unread-article t]
2312         ["Next article" gnus-summary-next-article t]
2313         ["Previous article" gnus-summary-prev-article t]
2314         ["Next unread subject" gnus-summary-next-unread-subject t]
2315         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2316         ["Next article same subject" gnus-summary-next-same-subject t]
2317         ["Previous article same subject" gnus-summary-prev-same-subject t]
2318         ["First unread article" gnus-summary-first-unread-article t]
2319         ["Best unread article" gnus-summary-best-unread-article t]
2320         ["Go to subject number..." gnus-summary-goto-subject t]
2321         ["Go to article number..." gnus-summary-goto-article t]
2322         ["Go to the last article" gnus-summary-goto-last-article t]
2323         ["Pop article off history" gnus-summary-pop-article t])
2324        ("Sort"
2325         ["Sort by number" gnus-summary-sort-by-number t]
2326         ["Sort by author" gnus-summary-sort-by-author t]
2327         ["Sort by subject" gnus-summary-sort-by-subject t]
2328         ["Sort by date" gnus-summary-sort-by-date t]
2329         ["Sort by score" gnus-summary-sort-by-score t]
2330         ["Sort by lines" gnus-summary-sort-by-lines t]
2331         ["Sort by characters" gnus-summary-sort-by-chars t]
2332         ["Randomize" gnus-summary-sort-by-random t]
2333         ["Original sort" gnus-summary-sort-by-original t])
2334        ("Help"
2335         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2336         ["Describe group" gnus-summary-describe-group t]
2337         ["Fetch charter" gnus-group-fetch-charter
2338          ,@(if (featurep 'xemacs) nil
2339              '(:help "Display the charter of the current group"))]
2340         ["Fetch control message" gnus-group-fetch-control
2341          ,@(if (featurep 'xemacs) nil
2342              '(:help "Display the archived control message for the current group"))]
2343         ["Read manual" gnus-info-find-node t])
2344        ("Modes"
2345         ["Pick and read" gnus-pick-mode t]
2346         ["Binary" gnus-binary-mode t])
2347        ("Regeneration"
2348         ["Regenerate" gnus-summary-prepare t]
2349         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2350         ["Toggle threading" gnus-summary-toggle-threads t])
2351        ["See old articles" gnus-summary-insert-old-articles t]
2352        ["See new articles" gnus-summary-insert-new-articles t]
2353        ["Filter articles..." gnus-summary-execute-command t]
2354        ["Run command on subjects..." gnus-summary-universal-argument t]
2355        ["Search articles forward..." gnus-summary-search-article-forward t]
2356        ["Search articles backward..." gnus-summary-search-article-backward t]
2357        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2358        ["Expand window" gnus-summary-expand-window t]
2359        ["Expire expirable articles" gnus-summary-expire-articles
2360         (gnus-check-backend-function
2361          'request-expire-articles gnus-newsgroup-name)]
2362        ["Edit local kill file" gnus-summary-edit-local-kill t]
2363        ["Edit main kill file" gnus-summary-edit-global-kill t]
2364        ["Edit group parameters" gnus-summary-edit-parameters t]
2365        ["Customize group parameters" gnus-summary-customize-parameters t]
2366        ["Send a bug report" gnus-bug t]
2367        ("Exit"
2368         ["Catchup and exit" gnus-summary-catchup-and-exit
2369          ,@(if (featurep 'xemacs) '(t)
2370              '(:help "Mark unread articles in this group as read, then exit"))]
2371         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2372         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2373         ["Exit group" gnus-summary-exit
2374          ,@(if (featurep 'xemacs) '(t)
2375              '(:help "Exit current group, return to group selection mode"))]
2376         ["Exit group without updating" gnus-summary-exit-no-update t]
2377         ["Exit and goto next group" gnus-summary-next-group t]
2378         ["Exit and goto prev group" gnus-summary-prev-group t]
2379         ["Reselect group" gnus-summary-reselect-current-group t]
2380         ["Rescan group" gnus-summary-rescan-group t]
2381         ["Update dribble" gnus-summary-save-newsrc t])))
2382
2383     (gnus-run-hooks 'gnus-summary-menu-hook)))
2384
2385 (defvar gnus-summary-tool-bar-map nil)
2386
2387 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2388 (defun gnus-summary-make-tool-bar ()
2389   (if (and (fboundp 'tool-bar-add-item-from-menu)
2390            (default-value 'tool-bar-mode)
2391            (not gnus-summary-tool-bar-map))
2392       (setq gnus-summary-tool-bar-map
2393             (let ((tool-bar-map (make-sparse-keymap))
2394                   (load-path (mm-image-load-path)))
2395               (tool-bar-add-item-from-menu
2396                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2397               (tool-bar-add-item-from-menu
2398                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2399               (tool-bar-add-item-from-menu
2400                'gnus-summary-post-news "post" gnus-summary-mode-map)
2401               (tool-bar-add-item-from-menu
2402                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2403               (tool-bar-add-item-from-menu
2404                'gnus-summary-followup "followup" gnus-summary-mode-map)
2405               (tool-bar-add-item-from-menu
2406                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2407               (tool-bar-add-item-from-menu
2408                'gnus-summary-reply "reply" gnus-summary-mode-map)
2409               (tool-bar-add-item-from-menu
2410                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2411               (tool-bar-add-item-from-menu
2412                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2413               (tool-bar-add-item-from-menu
2414                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2415               (tool-bar-add-item-from-menu
2416                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2417               (tool-bar-add-item-from-menu
2418                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2419               (tool-bar-add-item-from-menu
2420                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2421               (tool-bar-add-item-from-menu
2422                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2423               (tool-bar-add-item-from-menu
2424                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2425               tool-bar-map)))
2426   (if gnus-summary-tool-bar-map
2427       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2428
2429 (defun gnus-score-set-default (var value)
2430   "A version of set that updates the GNU Emacs menu-bar."
2431   (set var value)
2432   ;; It is the message that forces the active status to be updated.
2433   (message ""))
2434
2435 (defun gnus-make-score-map (type)
2436   "Make a summary score map of type TYPE."
2437   (if t
2438       nil
2439     (let ((headers '(("author" "from" string)
2440                      ("subject" "subject" string)
2441                      ("article body" "body" string)
2442                      ("article head" "head" string)
2443                      ("xref" "xref" string)
2444                      ("extra header" "extra" string)
2445                      ("lines" "lines" number)
2446                      ("followups to author" "followup" string)))
2447           (types '((number ("less than" <)
2448                            ("greater than" >)
2449                            ("equal" =))
2450                    (string ("substring" s)
2451                            ("exact string" e)
2452                            ("fuzzy string" f)
2453                            ("regexp" r))))
2454           (perms '(("temporary" (current-time-string))
2455                    ("permanent" nil)
2456                    ("immediate" now)))
2457           header)
2458       (list
2459        (apply
2460         'nconc
2461         (list
2462          (if (eq type 'lower)
2463              "Lower score"
2464            "Increase score"))
2465         (let (outh)
2466           (while headers
2467             (setq header (car headers))
2468             (setq outh
2469                   (cons
2470                    (apply
2471                     'nconc
2472                     (list (car header))
2473                     (let ((ts (cdr (assoc (nth 2 header) types)))
2474                           outt)
2475                       (while ts
2476                         (setq outt
2477                               (cons
2478                                (apply
2479                                 'nconc
2480                                 (list (caar ts))
2481                                 (let ((ps perms)
2482                                       outp)
2483                                   (while ps
2484                                     (setq outp
2485                                           (cons
2486                                            (vector
2487                                             (caar ps)
2488                                             (list
2489                                              'gnus-summary-score-entry
2490                                              (nth 1 header)
2491                                              (if (or (string= (nth 1 header)
2492                                                               "head")
2493                                                      (string= (nth 1 header)
2494                                                               "body"))
2495                                                  ""
2496                                                (list 'gnus-summary-header
2497                                                      (nth 1 header)))
2498                                              (list 'quote (nth 1 (car ts)))
2499                                              (list 'gnus-score-delta-default
2500                                                    nil)
2501                                              (nth 1 (car ps))
2502                                              t)
2503                                             t)
2504                                            outp))
2505                                     (setq ps (cdr ps)))
2506                                   (list (nreverse outp))))
2507                                outt))
2508                         (setq ts (cdr ts)))
2509                       (list (nreverse outt))))
2510                    outh))
2511             (setq headers (cdr headers)))
2512           (list (nreverse outh))))))))
2513
2514 \f
2515
2516 (defun gnus-summary-mode (&optional group)
2517   "Major mode for reading articles.
2518
2519 All normal editing commands are switched off.
2520 \\<gnus-summary-mode-map>
2521 Each line in this buffer represents one article.  To read an
2522 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2523 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2524 respectively.
2525
2526 You can also post articles and send mail from this buffer.  To
2527 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2528 of an article, type `\\[gnus-summary-reply]'.
2529
2530 There are approx. one gazillion commands you can execute in this
2531 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2532
2533 The following commands are available:
2534
2535 \\{gnus-summary-mode-map}"
2536   (interactive)
2537   (kill-all-local-variables)
2538   (when (gnus-visual-p 'summary-menu 'menu)
2539     (gnus-summary-make-menu-bar)
2540     (gnus-summary-make-tool-bar))
2541   (gnus-summary-make-local-variables)
2542   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2543     (gnus-summary-make-local-variables))
2544   (gnus-make-thread-indent-array)
2545   (gnus-simplify-mode-line)
2546   (setq major-mode 'gnus-summary-mode)
2547   (setq mode-name "Summary")
2548   (make-local-variable 'minor-mode-alist)
2549   (use-local-map gnus-summary-mode-map)
2550   (buffer-disable-undo)
2551   (setq buffer-read-only t)             ;Disable modification
2552   (setq truncate-lines t)
2553   (setq selective-display t)
2554   (setq selective-display-ellipses t)   ;Display `...'
2555   (gnus-summary-set-display-table)
2556   (gnus-set-default-directory)
2557   (setq gnus-newsgroup-name group)
2558   (unless (gnus-news-group-p group)
2559     (setq gnus-newsgroup-incorporated
2560           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2561   (make-local-variable 'gnus-summary-line-format)
2562   (make-local-variable 'gnus-summary-line-format-spec)
2563   (make-local-variable 'gnus-summary-dummy-line-format)
2564   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2565   (make-local-variable 'gnus-summary-mark-positions)
2566   (make-local-hook 'pre-command-hook)
2567   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2568   (gnus-run-hooks 'gnus-summary-mode-hook)
2569   (turn-on-gnus-mailing-list-mode)
2570   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2571   (gnus-update-summary-mark-positions))
2572
2573 (defun gnus-summary-make-local-variables ()
2574   "Make all the local summary buffer variables."
2575   (let (global)
2576     (dolist (local gnus-summary-local-variables)
2577       (if (consp local)
2578           (progn
2579             (if (eq (cdr local) 'global)
2580                 ;; Copy the global value of the variable.
2581                 (setq global (symbol-value (car local)))
2582               ;; Use the value from the list.
2583               (setq global (eval (cdr local))))
2584             (set (make-local-variable (car local)) global))
2585         ;; Simple nil-valued local variable.
2586         (set (make-local-variable local) nil)))))
2587
2588 (defun gnus-summary-clear-local-variables ()
2589   (let ((locals gnus-summary-local-variables))
2590     (while locals
2591       (if (consp (car locals))
2592           (and (vectorp (caar locals))
2593                (set (caar locals) nil))
2594         (and (vectorp (car locals))
2595              (set (car locals) nil)))
2596       (setq locals (cdr locals)))))
2597
2598 ;; Summary data functions.
2599
2600 (defmacro gnus-data-number (data)
2601   `(car ,data))
2602
2603 (defmacro gnus-data-set-number (data number)
2604   `(setcar ,data ,number))
2605
2606 (defmacro gnus-data-mark (data)
2607   `(nth 1 ,data))
2608
2609 (defmacro gnus-data-set-mark (data mark)
2610   `(setcar (nthcdr 1 ,data) ,mark))
2611
2612 (defmacro gnus-data-pos (data)
2613   `(nth 2 ,data))
2614
2615 (defmacro gnus-data-set-pos (data pos)
2616   `(setcar (nthcdr 2 ,data) ,pos))
2617
2618 (defmacro gnus-data-header (data)
2619   `(nth 3 ,data))
2620
2621 (defmacro gnus-data-set-header (data header)
2622   `(setcar (nthcdr 3 ,data) ,header))
2623
2624 (defmacro gnus-data-level (data)
2625   `(nth 4 ,data))
2626
2627 (defmacro gnus-data-unread-p (data)
2628   `(= (nth 1 ,data) gnus-unread-mark))
2629
2630 (defmacro gnus-data-read-p (data)
2631   `(/= (nth 1 ,data) gnus-unread-mark))
2632
2633 (defmacro gnus-data-pseudo-p (data)
2634   `(consp (nth 3 ,data)))
2635
2636 (defmacro gnus-data-find (number)
2637   `(assq ,number gnus-newsgroup-data))
2638
2639 (defmacro gnus-data-find-list (number &optional data)
2640   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2641      (memq (assq ,number bdata)
2642            bdata)))
2643
2644 (defmacro gnus-data-make (number mark pos header level)
2645   `(list ,number ,mark ,pos ,header ,level))
2646
2647 (defun gnus-data-enter (after-article number mark pos header level offset)
2648   (let ((data (gnus-data-find-list after-article)))
2649     (unless data
2650       (error "No such article: %d" after-article))
2651     (setcdr data (cons (gnus-data-make number mark pos header level)
2652                        (cdr data)))
2653     (setq gnus-newsgroup-data-reverse nil)
2654     (gnus-data-update-list (cddr data) offset)))
2655
2656 (defun gnus-data-enter-list (after-article list &optional offset)
2657   (when list
2658     (let ((data (and after-article (gnus-data-find-list after-article)))
2659           (ilist list))
2660       (if (not (or data
2661                    after-article))
2662           (let ((odata gnus-newsgroup-data))
2663             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2664             (when offset
2665               (gnus-data-update-list odata offset)))
2666         ;; Find the last element in the list to be spliced into the main
2667         ;; list.
2668         (while (cdr list)
2669           (setq list (cdr list)))
2670         (if (not data)
2671             (progn
2672               (setcdr list gnus-newsgroup-data)
2673               (setq gnus-newsgroup-data ilist)
2674               (when offset
2675                 (gnus-data-update-list (cdr list) offset)))
2676           (setcdr list (cdr data))
2677           (setcdr data ilist)
2678           (when offset
2679             (gnus-data-update-list (cdr list) offset))))
2680       (setq gnus-newsgroup-data-reverse nil))))
2681
2682 (defun gnus-data-remove (article &optional offset)
2683   (let ((data gnus-newsgroup-data))
2684     (if (= (gnus-data-number (car data)) article)
2685         (progn
2686           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2687                 gnus-newsgroup-data-reverse nil)
2688           (when offset
2689             (gnus-data-update-list gnus-newsgroup-data offset)))
2690       (while (cdr data)
2691         (when (= (gnus-data-number (cadr data)) article)
2692           (setcdr data (cddr data))
2693           (when offset
2694             (gnus-data-update-list (cdr data) offset))
2695           (setq data nil
2696                 gnus-newsgroup-data-reverse nil))
2697         (setq data (cdr data))))))
2698
2699 (defmacro gnus-data-list (backward)
2700   `(if ,backward
2701        (or gnus-newsgroup-data-reverse
2702            (setq gnus-newsgroup-data-reverse
2703                  (reverse gnus-newsgroup-data)))
2704      gnus-newsgroup-data))
2705
2706 (defun gnus-data-update-list (data offset)
2707   "Add OFFSET to the POS of all data entries in DATA."
2708   (setq gnus-newsgroup-data-reverse nil)
2709   (while data
2710     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2711     (setq data (cdr data))))
2712
2713 (defun gnus-summary-article-pseudo-p (article)
2714   "Say whether this article is a pseudo article or not."
2715   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2716
2717 (defmacro gnus-summary-article-sparse-p (article)
2718   "Say whether this article is a sparse article or not."
2719   `(memq ,article gnus-newsgroup-sparse))
2720
2721 (defmacro gnus-summary-article-ancient-p (article)
2722   "Say whether this article is a sparse article or not."
2723   `(memq ,article gnus-newsgroup-ancient))
2724
2725 (defun gnus-article-parent-p (number)
2726   "Say whether this article is a parent or not."
2727   (let ((data (gnus-data-find-list number)))
2728     (and (cdr data)                     ; There has to be an article after...
2729          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2730             (gnus-data-level (nth 1 data))))))
2731
2732 (defun gnus-article-children (number)
2733   "Return a list of all children to NUMBER."
2734   (let* ((data (gnus-data-find-list number))
2735          (level (gnus-data-level (car data)))
2736          children)
2737     (setq data (cdr data))
2738     (while (and data
2739                 (= (gnus-data-level (car data)) (1+ level)))
2740       (push (gnus-data-number (car data)) children)
2741       (setq data (cdr data)))
2742     children))
2743
2744 (defmacro gnus-summary-skip-intangible ()
2745   "If the current article is intangible, then jump to a different article."
2746   '(let ((to (get-text-property (point) 'gnus-intangible)))
2747      (and to (gnus-summary-goto-subject to))))
2748
2749 (defmacro gnus-summary-article-intangible-p ()
2750   "Say whether this article is intangible or not."
2751   '(get-text-property (point) 'gnus-intangible))
2752
2753 (defun gnus-article-read-p (article)
2754   "Say whether ARTICLE is read or not."
2755   (not (or (memq article gnus-newsgroup-marked)
2756            (memq article gnus-newsgroup-spam-marked)
2757            (memq article gnus-newsgroup-unreads)
2758            (memq article gnus-newsgroup-unselected)
2759            (memq article gnus-newsgroup-dormant))))
2760
2761 ;; Some summary mode macros.
2762
2763 (defmacro gnus-summary-article-number ()
2764   "The article number of the article on the current line.
2765 If there isn's an article number here, then we return the current
2766 article number."
2767   '(progn
2768      (gnus-summary-skip-intangible)
2769      (or (get-text-property (point) 'gnus-number)
2770          (gnus-summary-last-subject))))
2771
2772 (defmacro gnus-summary-article-header (&optional number)
2773   "Return the header of article NUMBER."
2774   `(gnus-data-header (gnus-data-find
2775                       ,(or number '(gnus-summary-article-number)))))
2776
2777 (defmacro gnus-summary-thread-level (&optional number)
2778   "Return the level of thread that starts with article NUMBER."
2779   `(if (and (eq gnus-summary-make-false-root 'dummy)
2780             (get-text-property (point) 'gnus-intangible))
2781        0
2782      (gnus-data-level (gnus-data-find
2783                        ,(or number '(gnus-summary-article-number))))))
2784
2785 (defmacro gnus-summary-article-mark (&optional number)
2786   "Return the mark of article NUMBER."
2787   `(gnus-data-mark (gnus-data-find
2788                     ,(or number '(gnus-summary-article-number)))))
2789
2790 (defmacro gnus-summary-article-pos (&optional number)
2791   "Return the position of the line of article NUMBER."
2792   `(gnus-data-pos (gnus-data-find
2793                    ,(or number '(gnus-summary-article-number)))))
2794
2795 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2796 (defmacro gnus-summary-article-subject (&optional number)
2797   "Return current subject string or nil if nothing."
2798   `(let ((headers
2799           ,(if number
2800                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2801              '(gnus-data-header (assq (gnus-summary-article-number)
2802                                       gnus-newsgroup-data)))))
2803      (and headers
2804           (vectorp headers)
2805           (mail-header-subject headers))))
2806
2807 (defmacro gnus-summary-article-score (&optional number)
2808   "Return current article score."
2809   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2810                   gnus-newsgroup-scored))
2811        gnus-summary-default-score 0))
2812
2813 (defun gnus-summary-article-children (&optional number)
2814   "Return a list of article numbers that are children of article NUMBER."
2815   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2816          (level (gnus-data-level (car data)))
2817          l children)
2818     (while (and (setq data (cdr data))
2819                 (> (setq l (gnus-data-level (car data))) level))
2820       (and (= (1+ level) l)
2821            (push (gnus-data-number (car data))
2822                  children)))
2823     (nreverse children)))
2824
2825 (defun gnus-summary-article-parent (&optional number)
2826   "Return the article number of the parent of article NUMBER."
2827   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2828                                     (gnus-data-list t)))
2829          (level (gnus-data-level (car data))))
2830     (if (zerop level)
2831         ()                              ; This is a root.
2832       ;; We search until we find an article with a level less than
2833       ;; this one.  That function has to be the parent.
2834       (while (and (setq data (cdr data))
2835                   (not (< (gnus-data-level (car data)) level))))
2836       (and data (gnus-data-number (car data))))))
2837
2838 (defun gnus-unread-mark-p (mark)
2839   "Say whether MARK is the unread mark."
2840   (= mark gnus-unread-mark))
2841
2842 (defun gnus-read-mark-p (mark)
2843   "Say whether MARK is one of the marks that mark as read.
2844 This is all marks except unread, ticked, dormant, and expirable."
2845   (not (or (= mark gnus-unread-mark)
2846            (= mark gnus-ticked-mark)
2847            (= mark gnus-dormant-mark)
2848            (= mark gnus-expirable-mark))))
2849
2850 (defmacro gnus-article-mark (number)
2851   "Return the MARK of article NUMBER.
2852 This macro should only be used when computing the mark the \"first\"
2853 time; i.e., when generating the summary lines.  After that,
2854 `gnus-summary-article-mark' should be used to examine the
2855 marks of articles."
2856   `(cond
2857     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2858     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2859     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2860     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2861     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2862     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2863     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2864     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2865     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2866            gnus-ancient-mark))))
2867
2868 ;; Saving hidden threads.
2869
2870 (defmacro gnus-save-hidden-threads (&rest forms)
2871   "Save hidden threads, eval FORMS, and restore the hidden threads."
2872   (let ((config (make-symbol "config")))
2873     `(let ((,config (gnus-hidden-threads-configuration)))
2874        (unwind-protect
2875            (save-excursion
2876              ,@forms)
2877          (gnus-restore-hidden-threads-configuration ,config)))))
2878 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2879 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2880
2881 (defun gnus-data-compute-positions ()
2882   "Compute the positions of all articles."
2883   (setq gnus-newsgroup-data-reverse nil)
2884   (let ((data gnus-newsgroup-data))
2885     (save-excursion
2886       (gnus-save-hidden-threads
2887         (gnus-summary-show-all-threads)
2888         (goto-char (point-min))
2889         (while data
2890           (while (get-text-property (point) 'gnus-intangible)
2891             (forward-line 1))
2892           (gnus-data-set-pos (car data) (+ (point) 3))
2893           (setq data (cdr data))
2894           (forward-line 1))))))
2895
2896 (defun gnus-hidden-threads-configuration ()
2897   "Return the current hidden threads configuration."
2898   (save-excursion
2899     (let (config)
2900       (goto-char (point-min))
2901       (while (search-forward "\r" nil t)
2902         (push (1- (point)) config))
2903       config)))
2904
2905 (defun gnus-restore-hidden-threads-configuration (config)
2906   "Restore hidden threads configuration from CONFIG."
2907   (save-excursion
2908     (let (point buffer-read-only)
2909       (while (setq point (pop config))
2910         (when (and (< point (point-max))
2911                    (goto-char point)
2912                    (eq (char-after) ?\n))
2913           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2914
2915 ;; Various summary mode internalish functions.
2916
2917 (defun gnus-mouse-pick-article (e)
2918   (interactive "e")
2919   (mouse-set-point e)
2920   (gnus-summary-next-page nil t))
2921
2922 (defun gnus-summary-set-display-table ()
2923   "Change the display table.
2924 Odd characters have a tendency to mess
2925 up nicely formatted displays - we make all possible glyphs
2926 display only a single character."
2927
2928   ;; We start from the standard display table, if any.
2929   (let ((table (or (copy-sequence standard-display-table)
2930                    (make-display-table)))
2931         (i 32))
2932     ;; Nix out all the control chars...
2933     (while (>= (setq i (1- i)) 0)
2934       (aset table i [??]))
2935     ;; ... but not newline and cr, of course.  (cr is necessary for the
2936     ;; selective display).
2937     (aset table ?\n nil)
2938     (aset table ?\r nil)
2939     ;; We keep TAB as well.
2940     (aset table ?\t nil)
2941     ;; We nix out any glyphs over 126 that are not set already.
2942     (let ((i 256))
2943       (while (>= (setq i (1- i)) 127)
2944         ;; Only modify if the entry is nil.
2945         (unless (aref table i)
2946           (aset table i [??]))))
2947     (setq buffer-display-table table)))
2948
2949 (defun gnus-summary-set-article-display-arrow (pos)
2950   "Update the overlay arrow to point to line at position POS."
2951   (when (and gnus-summary-display-arrow
2952              (boundp 'overlay-arrow-position)
2953              (boundp 'overlay-arrow-string))
2954     (save-excursion
2955       (goto-char pos)
2956       (beginning-of-line)
2957       (unless overlay-arrow-position
2958         (setq overlay-arrow-position (make-marker)))
2959       (setq overlay-arrow-string "=>"
2960             overlay-arrow-position (set-marker overlay-arrow-position
2961                                                (point)
2962                                                (current-buffer))))))
2963
2964 (defun gnus-summary-buffer-name (group)
2965   "Return the summary buffer name of GROUP."
2966   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2967
2968 (defun gnus-summary-setup-buffer (group)
2969   "Initialize summary buffer."
2970   (let ((buffer (gnus-summary-buffer-name group))
2971         (dead-name (concat "*Dead Summary "
2972                            (gnus-group-decoded-name group) "*")))
2973     ;; If a dead summary buffer exists, we kill it.
2974     (when (gnus-buffer-live-p dead-name)
2975       (gnus-kill-buffer dead-name))
2976     (if (get-buffer buffer)
2977         (progn
2978           (set-buffer buffer)
2979           (setq gnus-summary-buffer (current-buffer))
2980           (not gnus-newsgroup-prepared))
2981       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2982       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2983       (gnus-summary-mode group)
2984       (when gnus-carpal
2985         (gnus-carpal-setup-buffer 'summary))
2986       (unless gnus-single-article-buffer
2987         (make-local-variable 'gnus-article-buffer)
2988         (make-local-variable 'gnus-article-current)
2989         (make-local-variable 'gnus-original-article-buffer))
2990       (setq gnus-newsgroup-name group)
2991       ;; Set any local variables in the group parameters.
2992       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2993       t)))
2994
2995 (defun gnus-set-global-variables ()
2996   "Set the global equivalents of the buffer-local variables.
2997 They are set to the latest values they had.  These reflect the summary
2998 buffer that was in action when the last article was fetched."
2999   (when (eq major-mode 'gnus-summary-mode)
3000     (setq gnus-summary-buffer (current-buffer))
3001     (let ((name gnus-newsgroup-name)
3002           (marked gnus-newsgroup-marked)
3003           (spam gnus-newsgroup-spam-marked)
3004           (unread gnus-newsgroup-unreads)
3005           (headers gnus-current-headers)
3006           (data gnus-newsgroup-data)
3007           (summary gnus-summary-buffer)
3008           (article-buffer gnus-article-buffer)
3009           (original gnus-original-article-buffer)
3010           (gac gnus-article-current)
3011           (reffed gnus-reffed-article-number)
3012           (score-file gnus-current-score-file)
3013           (default-charset gnus-newsgroup-charset)
3014           vlist)
3015       (let ((locals gnus-newsgroup-variables))
3016         (while locals
3017           (if (consp (car locals))
3018               (push (eval (caar locals)) vlist)
3019             (push (eval (car locals)) vlist))
3020           (setq locals (cdr locals)))
3021         (setq vlist (nreverse vlist)))
3022       (save-excursion
3023         (set-buffer gnus-group-buffer)
3024         (setq gnus-newsgroup-name name
3025               gnus-newsgroup-marked marked
3026               gnus-newsgroup-spam-marked spam
3027               gnus-newsgroup-unreads unread
3028               gnus-current-headers headers
3029               gnus-newsgroup-data data
3030               gnus-article-current gac
3031               gnus-summary-buffer summary
3032               gnus-article-buffer article-buffer
3033               gnus-original-article-buffer original
3034               gnus-reffed-article-number reffed
3035               gnus-current-score-file score-file
3036               gnus-newsgroup-charset default-charset)
3037         (let ((locals gnus-newsgroup-variables))
3038           (while locals
3039             (if (consp (car locals))
3040                 (set (caar locals) (pop vlist))
3041               (set (car locals) (pop vlist)))
3042             (setq locals (cdr locals))))
3043         ;; The article buffer also has local variables.
3044         (when (gnus-buffer-live-p gnus-article-buffer)
3045           (set-buffer gnus-article-buffer)
3046           (setq gnus-summary-buffer summary))))))
3047
3048 (defun gnus-summary-article-unread-p (article)
3049   "Say whether ARTICLE is unread or not."
3050   (memq article gnus-newsgroup-unreads))
3051
3052 (defun gnus-summary-first-article-p (&optional article)
3053   "Return whether ARTICLE is the first article in the buffer."
3054   (if (not (setq article (or article (gnus-summary-article-number))))
3055       nil
3056     (eq article (caar gnus-newsgroup-data))))
3057
3058 (defun gnus-summary-last-article-p (&optional article)
3059   "Return whether ARTICLE is the last article in the buffer."
3060   (if (not (setq article (or article (gnus-summary-article-number))))
3061       ;; All non-existent numbers are the last article.  :-)
3062       t
3063     (not (cdr (gnus-data-find-list article)))))
3064
3065 (defun gnus-make-thread-indent-array ()
3066   (let ((n 200))
3067     (unless (and gnus-thread-indent-array
3068                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3069       (setq gnus-thread-indent-array (make-vector 201 "")
3070             gnus-thread-indent-array-level gnus-thread-indent-level)
3071       (while (>= n 0)
3072         (aset gnus-thread-indent-array n
3073               (make-string (* n gnus-thread-indent-level) ? ))
3074         (setq n (1- n))))))
3075
3076 (defun gnus-update-summary-mark-positions ()
3077   "Compute where the summary marks are to go."
3078   (save-excursion
3079     (when (gnus-buffer-exists-p gnus-summary-buffer)
3080       (set-buffer gnus-summary-buffer))
3081     (let ((gnus-replied-mark 129)
3082           (gnus-score-below-mark 130)
3083           (gnus-score-over-mark 130)
3084           (gnus-download-mark 131)
3085           (spec gnus-summary-line-format-spec)
3086           gnus-visual pos)
3087       (save-excursion
3088         (gnus-set-work-buffer)
3089         (let ((gnus-summary-line-format-spec spec)
3090               (gnus-newsgroup-downloadable '((0 . t))))
3091           (gnus-summary-insert-line
3092            (make-full-mail-header 0 "" "nobody"
3093                                   "05 Apr 2001 23:33:09 +0400"
3094                                   "" "" 0 0 "" nil)
3095            0 nil 128 t nil "" nil 1)
3096           (goto-char (point-min))
3097           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3098                                              (- (point) (point-min) 1)))))
3099           (goto-char (point-min))
3100           (push (cons 'replied (and (search-forward "\201" nil t)
3101                                     (- (point) (point-min) 1)))
3102                 pos)
3103           (goto-char (point-min))
3104           (push (cons 'score (and (search-forward "\202" nil t)
3105                                   (- (point) (point-min) 1)))
3106                 pos)
3107           (goto-char (point-min))
3108           (push (cons 'download
3109                       (and (search-forward "\203" nil t)
3110                            (- (point) (point-min) 1)))
3111                 pos)))
3112       (setq gnus-summary-mark-positions pos))))
3113
3114 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3115   "Insert a dummy root in the summary buffer."
3116   (beginning-of-line)
3117   (gnus-add-text-properties
3118    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3119    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3120
3121 (defun gnus-summary-extract-address-component (from)
3122   (or (car (funcall gnus-extract-address-components from))
3123       from))
3124
3125 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3126   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3127                                 default-mime-charset)))
3128     ;; Is it really necessary to do this next part for each summary line?
3129     ;; Luckily, doesn't seem to slow things down much.
3130     (or
3131      (and gnus-ignored-from-addresses
3132           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3133           (let ((extra-headers (mail-header-extra header))
3134                 to
3135                 newsgroups)
3136             (cond
3137              ((setq to (cdr (assq 'To extra-headers)))
3138               (concat "-> "
3139                       (inline
3140                         (gnus-summary-extract-address-component
3141                          (funcall gnus-decode-encoded-word-function to)))))
3142              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3143               (concat "=> " newsgroups)))))
3144      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3145
3146 (defun gnus-summary-insert-line (gnus-tmp-header
3147                                  gnus-tmp-level gnus-tmp-current
3148                                  gnus-tmp-unread gnus-tmp-replied
3149                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3150                                  &optional gnus-tmp-dummy gnus-tmp-score
3151                                  gnus-tmp-process)
3152   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3153          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3154          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3155          (gnus-tmp-score-char
3156           (if (or (null gnus-summary-default-score)
3157                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3158                       gnus-summary-zcore-fuzz))
3159               ?\ ;;;Whitespace
3160             (if (< gnus-tmp-score gnus-summary-default-score)
3161                 gnus-score-below-mark gnus-score-over-mark)))
3162          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3163          (gnus-tmp-replied
3164           (cond (gnus-tmp-process gnus-process-mark)
3165                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3166                  gnus-cached-mark)
3167                 (gnus-tmp-replied gnus-replied-mark)
3168                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3169                  gnus-forwarded-mark)
3170                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3171                  gnus-saved-mark)
3172                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3173                  gnus-recent-mark)
3174                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3175                  gnus-unseen-mark)
3176                 (t gnus-no-mark)))
3177          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3178          (gnus-tmp-name
3179           (cond
3180            ((string-match "<[^>]+> *$" gnus-tmp-from)
3181             (let ((beg (match-beginning 0)))
3182               (or (and (string-match "^\".+\"" gnus-tmp-from)
3183                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3184                   (substring gnus-tmp-from 0 beg))))
3185            ((string-match "(.+)" gnus-tmp-from)
3186             (substring gnus-tmp-from
3187                        (1+ (match-beginning 0)) (1- (match-end 0))))
3188            (t gnus-tmp-from)))
3189          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3190          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3191          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3192          (buffer-read-only nil))
3193     (when (string= gnus-tmp-name "")
3194       (setq gnus-tmp-name gnus-tmp-from))
3195     (unless (numberp gnus-tmp-lines)
3196       (setq gnus-tmp-lines -1))
3197     (if (= gnus-tmp-lines -1)
3198         (setq gnus-tmp-lines "?")
3199       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3200     (gnus-put-text-property-excluding-characters-with-faces
3201      (point)
3202      (progn (eval gnus-summary-line-format-spec) (point))
3203      'gnus-number gnus-tmp-number)
3204     (when (gnus-visual-p 'summary-highlight 'highlight)
3205       (forward-line -1)
3206       (gnus-run-hooks 'gnus-summary-update-hook)
3207       (forward-line 1))))
3208
3209 (defun gnus-summary-update-line (&optional dont-update)
3210   "Update summary line after change."
3211   (when (and gnus-summary-default-score
3212              (not gnus-summary-inhibit-highlight))
3213     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3214            (article (gnus-summary-article-number))
3215            (score (gnus-summary-article-score article)))
3216       (unless dont-update
3217         (if (and gnus-summary-mark-below
3218                  (< (gnus-summary-article-score)
3219                     gnus-summary-mark-below))
3220             ;; This article has a low score, so we mark it as read.
3221             (when (memq article gnus-newsgroup-unreads)
3222               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3223           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3224             ;; This article was previously marked as read on account
3225             ;; of a low score, but now it has risen, so we mark it as
3226             ;; unread.
3227             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3228         (gnus-summary-update-mark
3229          (if (or (null gnus-summary-default-score)
3230                  (<= (abs (- score gnus-summary-default-score))
3231                      gnus-summary-zcore-fuzz))
3232              ?\ ;;;Whitespace
3233            (if (< score gnus-summary-default-score)
3234                gnus-score-below-mark gnus-score-over-mark))
3235          'score))
3236       ;; Do visual highlighting.
3237       (when (gnus-visual-p 'summary-highlight 'highlight)
3238         (gnus-run-hooks 'gnus-summary-update-hook)))))
3239
3240 (defvar gnus-tmp-new-adopts nil)
3241
3242 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3243   "Return the number of articles in THREAD.
3244 This may be 0 in some cases -- if none of the articles in
3245 the thread are to be displayed."
3246   (let* ((number
3247           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3248           (cond
3249            ((not (listp thread))
3250             1)
3251            ((and (consp thread) (cdr thread))
3252             (apply
3253              '+ 1 (mapcar
3254                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3255            ((null thread)
3256             1)
3257            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3258             1)
3259            (t 0))))
3260     (when (and level (zerop level) gnus-tmp-new-adopts)
3261       (incf number
3262             (apply '+ (mapcar
3263                        'gnus-summary-number-of-articles-in-thread
3264                        gnus-tmp-new-adopts))))
3265     (if char
3266         (if (> number 1) gnus-not-empty-thread-mark
3267           gnus-empty-thread-mark)
3268       number)))
3269
3270 (defsubst gnus-summary-line-message-size (head)
3271   "Return pretty-printed version of message size.
3272 This function is intended to be used in
3273 `gnus-summary-line-format-alist', which see."
3274   (let ((c (or (mail-header-chars head) -1)))
3275     (cond ((< c 0) "n/a")               ; chars not available
3276           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3277           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3278           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3279           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3280
3281
3282 (defun gnus-summary-set-local-parameters (group)
3283   "Go through the local params of GROUP and set all variable specs in that list."
3284   (let ((params (gnus-group-find-parameter group))
3285         (vars '(quit-config))           ; Ignore quit-config.
3286         elem)
3287     (while params
3288       (setq elem (car params)
3289             params (cdr params))
3290       (and (consp elem)                 ; Has to be a cons.
3291            (consp (cdr elem))           ; The cdr has to be a list.
3292            (symbolp (car elem))         ; Has to be a symbol in there.
3293            (not (memq (car elem) vars))
3294            (ignore-errors               ; So we set it.
3295              (push (car elem) vars)
3296              (make-local-variable (car elem))
3297              (set (car elem) (eval (nth 1 elem))))))))
3298
3299 (defun gnus-summary-read-group (group &optional show-all no-article
3300                                       kill-buffer no-display backward
3301                                       select-articles)
3302   "Start reading news in newsgroup GROUP.
3303 If SHOW-ALL is non-nil, already read articles are also listed.
3304 If NO-ARTICLE is non-nil, no article is selected initially.
3305 If NO-DISPLAY, don't generate a summary buffer."
3306   (let (result)
3307     (while (and group
3308                 (null (setq result
3309                             (let ((gnus-auto-select-next nil))
3310                               (or (gnus-summary-read-group-1
3311                                    group show-all no-article
3312                                    kill-buffer no-display
3313                                    select-articles)
3314                                   (setq show-all nil
3315                                         select-articles nil)))))
3316                 (eq gnus-auto-select-next 'quietly))
3317       (set-buffer gnus-group-buffer)
3318       ;; The entry function called above goes to the next
3319       ;; group automatically, so we go two groups back
3320       ;; if we are searching for the previous group.
3321       (when backward
3322         (gnus-group-prev-unread-group 2))
3323       (if (not (equal group (gnus-group-group-name)))
3324           (setq group (gnus-group-group-name))
3325         (setq group nil)))
3326     result))
3327
3328 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3329   "Directly jump to the other GROUP from summary buffer.
3330 If SHOW-ALL is non-nil, already read articles are also listed."
3331   (interactive
3332    (if (eq gnus-summary-buffer (current-buffer))
3333        (list (completing-read
3334               "Group: " gnus-active-hashtb nil t
3335               (when (and gnus-newsgroup-name
3336                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3337                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3338               'gnus-group-history)
3339              current-prefix-arg)
3340      (error "%s must be invoked from a gnus summary buffer." this-command)))
3341   (unless (or (zerop (length group))
3342               (and gnus-newsgroup-name
3343                    (string-equal gnus-newsgroup-name group)))
3344     (gnus-summary-exit)
3345     (gnus-summary-read-group group show-all
3346                              gnus-dont-select-after-jump-to-other-group)))
3347
3348 (defun gnus-summary-read-group-1 (group show-all no-article
3349                                         kill-buffer no-display
3350                                         &optional select-articles)
3351   ;; Killed foreign groups can't be entered.
3352   ;;  (when (and (not (gnus-group-native-p group))
3353   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3354   ;;    (error "Dead non-native groups can't be entered"))
3355   (gnus-message 5 "Retrieving newsgroup: %s..."
3356                 (gnus-group-decoded-name group))
3357   (let* ((new-group (gnus-summary-setup-buffer group))
3358          (quit-config (gnus-group-quit-config group))
3359          (did-select (and new-group (gnus-select-newsgroup
3360                                      group show-all select-articles))))
3361     (cond
3362      ;; This summary buffer exists already, so we just select it.
3363      ((not new-group)
3364       (gnus-set-global-variables)
3365       (when kill-buffer
3366         (gnus-kill-or-deaden-summary kill-buffer))
3367       (gnus-configure-windows 'summary 'force)
3368       (gnus-set-mode-line 'summary)
3369       (gnus-summary-position-point)
3370       (message "")
3371       t)
3372      ;; We couldn't select this group.
3373      ((null did-select)
3374       (when (and (eq major-mode 'gnus-summary-mode)
3375                  (not (equal (current-buffer) kill-buffer)))
3376         (kill-buffer (current-buffer))
3377         (if (not quit-config)
3378             (progn
3379               ;; Update the info -- marks might need to be removed,
3380               ;; for instance.
3381               (gnus-summary-update-info)
3382               (set-buffer gnus-group-buffer)
3383               (gnus-group-jump-to-group group)
3384               (gnus-group-next-unread-group 1))
3385           (gnus-handle-ephemeral-exit quit-config)))
3386       (let ((grpinfo (gnus-get-info group)))
3387         (if (null (gnus-info-read grpinfo))
3388             (gnus-message 3 "Group %s contains no messages"
3389                           (gnus-group-decoded-name group))
3390           (gnus-message 3 "Can't select group")))
3391       nil)
3392      ;; The user did a `C-g' while prompting for number of articles,
3393      ;; so we exit this group.
3394      ((eq did-select 'quit)
3395       (and (eq major-mode 'gnus-summary-mode)
3396            (not (equal (current-buffer) kill-buffer))
3397            (kill-buffer (current-buffer)))
3398       (when kill-buffer
3399         (gnus-kill-or-deaden-summary kill-buffer))
3400       (if (not quit-config)
3401           (progn
3402             (set-buffer gnus-group-buffer)
3403             (gnus-group-jump-to-group group)
3404             (gnus-group-next-unread-group 1)
3405             (gnus-configure-windows 'group 'force))
3406         (gnus-handle-ephemeral-exit quit-config))
3407       ;; Finally signal the quit.
3408       (signal 'quit nil))
3409      ;; The group was successfully selected.
3410      (t
3411       (gnus-set-global-variables)
3412       ;; Save the active value in effect when the group was entered.
3413       (setq gnus-newsgroup-active
3414             (gnus-copy-sequence
3415              (gnus-active gnus-newsgroup-name)))
3416       ;; You can change the summary buffer in some way with this hook.
3417       (gnus-run-hooks 'gnus-select-group-hook)
3418       (gnus-update-format-specifications
3419        nil 'summary 'summary-mode 'summary-dummy)
3420       (gnus-update-summary-mark-positions)
3421       ;; Do score processing.
3422       (when gnus-use-scoring
3423         (gnus-possibly-score-headers))
3424       ;; Check whether to fill in the gaps in the threads.
3425       (when gnus-build-sparse-threads
3426         (gnus-build-sparse-threads))
3427       ;; Find the initial limit.
3428       (if gnus-show-threads
3429           (if show-all
3430               (let ((gnus-newsgroup-dormant nil))
3431                 (gnus-summary-initial-limit show-all))
3432             (gnus-summary-initial-limit show-all))
3433         ;; When untreaded, all articles are always shown.
3434         (setq gnus-newsgroup-limit
3435               (mapcar
3436                (lambda (header) (mail-header-number header))
3437                gnus-newsgroup-headers)))
3438       ;; Generate the summary buffer.
3439       (unless no-display
3440         (gnus-summary-prepare))
3441       (when gnus-use-trees
3442         (gnus-tree-open group)
3443         (setq gnus-summary-highlight-line-function
3444               'gnus-tree-highlight-article))
3445       ;; If the summary buffer is empty, but there are some low-scored
3446       ;; articles or some excluded dormants, we include these in the
3447       ;; buffer.
3448       (when (and (zerop (buffer-size))
3449                  (not no-display))
3450         (cond (gnus-newsgroup-dormant
3451                (gnus-summary-limit-include-dormant))
3452               ((and gnus-newsgroup-scored show-all)
3453                (gnus-summary-limit-include-expunged t))))
3454       ;; Function `gnus-apply-kill-file' must be called in this hook.
3455       (gnus-run-hooks 'gnus-apply-kill-hook)
3456       (if (and (zerop (buffer-size))
3457                (not no-display))
3458           (progn
3459             ;; This newsgroup is empty.
3460             (gnus-summary-catchup-and-exit nil t)
3461             (gnus-message 6 "No unread news")
3462             (when kill-buffer
3463               (gnus-kill-or-deaden-summary kill-buffer))
3464             ;; Return nil from this function.
3465             nil)
3466         ;; Hide conversation thread subtrees.  We cannot do this in
3467         ;; gnus-summary-prepare-hook since kill processing may not
3468         ;; work with hidden articles.
3469         (gnus-summary-maybe-hide-threads)
3470         (when kill-buffer
3471           (gnus-kill-or-deaden-summary kill-buffer))
3472         (gnus-summary-auto-select-subject)
3473         ;; Show first unread article if requested.
3474         (if (and (not no-article)
3475                  (not no-display)
3476                  gnus-newsgroup-unreads
3477                  gnus-auto-select-first)
3478             (progn
3479               (gnus-configure-windows 'summary)
3480               (let ((art (gnus-summary-article-number)))
3481                 (unless (or (memq art gnus-newsgroup-undownloaded)
3482                             (memq art gnus-newsgroup-downloadable))
3483                   (gnus-summary-goto-article art))))
3484           ;; Don't select any articles.
3485           (gnus-summary-position-point)
3486           (gnus-configure-windows 'summary 'force)
3487           (gnus-set-mode-line 'summary))
3488         (when (get-buffer-window gnus-group-buffer t)
3489           ;; Gotta use windows, because recenter does weird stuff if
3490           ;; the current buffer ain't the displayed window.
3491           (let ((owin (selected-window)))
3492             (select-window (get-buffer-window gnus-group-buffer t))
3493             (when (gnus-group-goto-group group)
3494               (recenter))
3495             (select-window owin)))
3496         ;; Mark this buffer as "prepared".
3497         (setq gnus-newsgroup-prepared t)
3498         (gnus-run-hooks 'gnus-summary-prepared-hook)
3499         t)))))
3500
3501 (defun gnus-summary-auto-select-subject ()
3502   "Select the subject line on initial group entry."
3503   (goto-char (point-min))
3504   (cond
3505    ((eq gnus-auto-select-subject 'best)
3506     (gnus-summary-best-unread-subject))
3507    ((eq gnus-auto-select-subject 'unread)
3508     (gnus-summary-first-unread-subject))
3509    ((eq gnus-auto-select-subject 'unseen)
3510     (gnus-summary-first-unseen-subject))
3511    ((eq gnus-auto-select-subject 'unseen-or-unread)
3512     (gnus-summary-first-unseen-or-unread-subject))
3513    ((eq gnus-auto-select-subject 'first)
3514     ;; Do nothing.
3515     )
3516    ((gnus-functionp gnus-auto-select-subject)
3517     (funcall gnus-auto-select-subject))))
3518
3519 (defun gnus-summary-prepare ()
3520   "Generate the summary buffer."
3521   (interactive)
3522   (let ((buffer-read-only nil))
3523     (erase-buffer)
3524     (setq gnus-newsgroup-data nil
3525           gnus-newsgroup-data-reverse nil)
3526     (gnus-run-hooks 'gnus-summary-generate-hook)
3527     ;; Generate the buffer, either with threads or without.
3528     (when gnus-newsgroup-headers
3529       (gnus-summary-prepare-threads
3530        (if gnus-show-threads
3531            (gnus-sort-gathered-threads
3532             (funcall gnus-summary-thread-gathering-function
3533                      (gnus-sort-threads
3534                       (gnus-cut-threads (gnus-make-threads)))))
3535          ;; Unthreaded display.
3536          (gnus-sort-articles gnus-newsgroup-headers))))
3537     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3538     ;; Call hooks for modifying summary buffer.
3539     (goto-char (point-min))
3540     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3541
3542 (defsubst gnus-general-simplify-subject (subject)
3543   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3544   (setq subject
3545         (cond
3546          ;; Truncate the subject.
3547          (gnus-simplify-subject-functions
3548           (gnus-map-function gnus-simplify-subject-functions subject))
3549          ((numberp gnus-summary-gather-subject-limit)
3550           (setq subject (gnus-simplify-subject-re subject))
3551           (if (> (length subject) gnus-summary-gather-subject-limit)
3552               (substring subject 0 gnus-summary-gather-subject-limit)
3553             subject))
3554          ;; Fuzzily simplify it.
3555          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3556           (gnus-simplify-subject-fuzzy subject))
3557          ;; Just remove the leading "Re:".
3558          (t
3559           (gnus-simplify-subject-re subject))))
3560
3561   (if (and gnus-summary-gather-exclude-subject
3562            (string-match gnus-summary-gather-exclude-subject subject))
3563       nil                               ; This article shouldn't be gathered
3564     subject))
3565
3566 (defun gnus-summary-simplify-subject-query ()
3567   "Query where the respool algorithm would put this article."
3568   (interactive)
3569   (gnus-summary-select-article)
3570   (message "%s"
3571            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3572
3573 (defun gnus-gather-threads-by-subject (threads)
3574   "Gather threads by looking at Subject headers."
3575   (if (not gnus-summary-make-false-root)
3576       threads
3577     (let ((hashtb (gnus-make-hashtable 1024))
3578           (prev threads)
3579           (result threads)
3580           subject hthread whole-subject)
3581       (while threads
3582         (setq subject (gnus-general-simplify-subject
3583                        (setq whole-subject (mail-header-subject
3584                                             (caar threads)))))
3585         (when subject
3586           (if (setq hthread (gnus-gethash subject hashtb))
3587               (progn
3588                 ;; We enter a dummy root into the thread, if we
3589                 ;; haven't done that already.
3590                 (unless (stringp (caar hthread))
3591                   (setcar hthread (list whole-subject (car hthread))))
3592                 ;; We add this new gathered thread to this gathered
3593                 ;; thread.
3594                 (setcdr (car hthread)
3595                         (nconc (cdar hthread) (list (car threads))))
3596                 ;; Remove it from the list of threads.
3597                 (setcdr prev (cdr threads))
3598                 (setq threads prev))
3599             ;; Enter this thread into the hash table.
3600             (gnus-sethash subject threads hashtb)))
3601         (setq prev threads)
3602         (setq threads (cdr threads)))
3603       result)))
3604
3605 (defun gnus-gather-threads-by-references (threads)
3606   "Gather threads by looking at References headers."
3607   (let ((idhashtb (gnus-make-hashtable 1024))
3608         (thhashtb (gnus-make-hashtable 1024))
3609         (prev threads)
3610         (result threads)
3611         ids references id gthread gid entered ref)
3612     (while threads
3613       (when (setq references (mail-header-references (caar threads)))
3614         (setq id (mail-header-id (caar threads))
3615               ids (inline (gnus-split-references references))
3616               entered nil)
3617         (while (setq ref (pop ids))
3618           (setq ids (delete ref ids))
3619           (if (not (setq gid (gnus-gethash ref idhashtb)))
3620               (progn
3621                 (gnus-sethash ref id idhashtb)
3622                 (gnus-sethash id threads thhashtb))
3623             (setq gthread (gnus-gethash gid thhashtb))
3624             (unless entered
3625               ;; We enter a dummy root into the thread, if we
3626               ;; haven't done that already.
3627               (unless (stringp (caar gthread))
3628                 (setcar gthread (list (mail-header-subject (caar gthread))
3629                                       (car gthread))))
3630               ;; We add this new gathered thread to this gathered
3631               ;; thread.
3632               (setcdr (car gthread)
3633                       (nconc (cdar gthread) (list (car threads)))))
3634             ;; Add it into the thread hash table.
3635             (gnus-sethash id gthread thhashtb)
3636             (setq entered t)
3637             ;; Remove it from the list of threads.
3638             (setcdr prev (cdr threads))
3639             (setq threads prev))))
3640       (setq prev threads)
3641       (setq threads (cdr threads)))
3642     result))
3643
3644 (defun gnus-sort-gathered-threads (threads)
3645   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3646   (let ((result threads))
3647     (while threads
3648       (when (stringp (caar threads))
3649         (setcdr (car threads)
3650                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3651       (setq threads (cdr threads)))
3652     result))
3653
3654 (defun gnus-thread-loop-p (root thread)
3655   "Say whether ROOT is in THREAD."
3656   (let ((stack (list thread))
3657         (infloop 0)
3658         th)
3659     (while (setq thread (pop stack))
3660       (setq th (cdr thread))
3661       (while (and th
3662                   (not (eq (caar th) root)))
3663         (pop th))
3664       (if th
3665           ;; We have found a loop.
3666           (let (ref-dep)
3667             (setcdr thread (delq (car th) (cdr thread)))
3668             (if (boundp (setq ref-dep (intern "none"
3669                                               gnus-newsgroup-dependencies)))
3670                 (setcdr (symbol-value ref-dep)
3671                         (nconc (cdr (symbol-value ref-dep))
3672                                (list (car th))))
3673               (set ref-dep (list nil (car th))))
3674             (setq infloop 1
3675                   stack nil))
3676         ;; Push all the subthreads onto the stack.
3677         (push (cdr thread) stack)))
3678     infloop))
3679
3680 (defun gnus-make-threads ()
3681   "Go through the dependency hashtb and find the roots.  Return all threads."
3682   (let (threads)
3683     (while (catch 'infloop
3684              (mapatoms
3685               (lambda (refs)
3686                 ;; Deal with self-referencing References loops.
3687                 (when (and (car (symbol-value refs))
3688                            (not (zerop
3689                                  (apply
3690                                   '+
3691                                   (mapcar
3692                                    (lambda (thread)
3693                                      (gnus-thread-loop-p
3694                                       (car (symbol-value refs)) thread))
3695                                    (cdr (symbol-value refs)))))))
3696                   (setq threads nil)
3697                   (throw 'infloop t))
3698                 (unless (car (symbol-value refs))
3699                   ;; These threads do not refer back to any other articles,
3700                   ;; so they're roots.
3701                   (setq threads (append (cdr (symbol-value refs)) threads))))
3702               gnus-newsgroup-dependencies)))
3703     threads))
3704
3705 ;; Build the thread tree.
3706 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3707   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3708
3709 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3710 if it was already present.
3711
3712 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3713 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3714 Message-IDs will be renamed to a unique Message-ID before being
3715 entered.
3716
3717 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3718   (let* ((id (mail-header-id header))
3719          (id-dep (and id (intern id dependencies)))
3720          parent-id ref ref-dep ref-header replaced)
3721     ;; Enter this `header' in the `dependencies' table.
3722     (cond
3723      ((not id-dep)
3724       (setq header nil))
3725      ;; The first two cases do the normal part: enter a new `header'
3726      ;; in the `dependencies' table.
3727      ((not (boundp id-dep))
3728       (set id-dep (list header)))
3729      ((null (car (symbol-value id-dep)))
3730       (setcar (symbol-value id-dep) header))
3731
3732      ;; From here the `header' was already present in the
3733      ;; `dependencies' table.
3734      (force-new
3735       ;; Overrides an existing entry;
3736       ;; just set the header part of the entry.
3737       (setcar (symbol-value id-dep) header)
3738       (setq replaced t))
3739
3740      ;; Renames the existing `header' to a unique Message-ID.
3741      ((not gnus-summary-ignore-duplicates)
3742       ;; An article with this Message-ID has already been seen.
3743       ;; We rename the Message-ID.
3744       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3745            (list header))
3746       (mail-header-set-id header id))
3747
3748      ;; The last case ignores an existing entry, except it adds any
3749      ;; additional Xrefs (in case the two articles came from different
3750      ;; servers.
3751      ;; Also sets `header' to `nil' meaning that the `dependencies'
3752      ;; table was *not* modified.
3753      (t
3754       (mail-header-set-xref
3755        (car (symbol-value id-dep))
3756        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3757                    "")
3758                (or (mail-header-xref header) "")))
3759       (setq header nil)))
3760
3761     (when (and header (not replaced))
3762       ;; First check that we are not creating a References loop.
3763       (setq parent-id (gnus-parent-id (mail-header-references header)))
3764       (setq ref parent-id)
3765       (while (and ref
3766                   (setq ref-dep (intern-soft ref dependencies))
3767                   (boundp ref-dep)
3768                   (setq ref-header (car (symbol-value ref-dep))))
3769         (if (string= id ref)
3770             ;; Yuk!  This is a reference loop.  Make the article be a
3771             ;; root article.
3772             (progn
3773               (mail-header-set-references (car (symbol-value id-dep)) "none")
3774               (setq ref nil)
3775               (setq parent-id nil))
3776           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3777       (setq ref-dep (intern (or parent-id "none") dependencies))
3778       (if (boundp ref-dep)
3779           (setcdr (symbol-value ref-dep)
3780                   (nconc (cdr (symbol-value ref-dep))
3781                          (list (symbol-value id-dep))))
3782         (set ref-dep (list nil (symbol-value id-dep)))))
3783     header))
3784
3785 (defun gnus-extract-message-id-from-in-reply-to (string)
3786   (if (string-match "<[^>]+>" string)
3787       (substring string (match-beginning 0) (match-end 0))
3788     nil))
3789
3790 (defun gnus-build-sparse-threads ()
3791   (let ((headers gnus-newsgroup-headers)
3792         (mail-parse-charset gnus-newsgroup-charset)
3793         (gnus-summary-ignore-duplicates t)
3794         header references generation relations
3795         subject child end new-child date)
3796     ;; First we create an alist of generations/relations, where
3797     ;; generations is how much we trust the relation, and the relation
3798     ;; is parent/child.
3799     (gnus-message 7 "Making sparse threads...")
3800     (save-excursion
3801       (nnheader-set-temp-buffer " *gnus sparse threads*")
3802       (while (setq header (pop headers))
3803         (when (and (setq references (mail-header-references header))
3804                    (not (string= references "")))
3805           (insert references)
3806           (setq child (mail-header-id header)
3807                 subject (mail-header-subject header)
3808                 date (mail-header-date header)
3809                 generation 0)
3810           (while (search-backward ">" nil t)
3811             (setq end (1+ (point)))
3812             (when (search-backward "<" nil t)
3813               (setq new-child (buffer-substring (point) end))
3814               (push (list (incf generation)
3815                           child (setq child new-child)
3816                           subject date)
3817                     relations)))
3818           (when child
3819             (push (list (1+ generation) child nil subject) relations))
3820           (erase-buffer)))
3821       (kill-buffer (current-buffer)))
3822     ;; Sort over trustworthiness.
3823     (mapcar
3824      (lambda (relation)
3825        (when (gnus-dependencies-add-header
3826               (make-full-mail-header-from-decoded-header
3827                gnus-reffed-article-number
3828                (nth 3 relation) "" (or (nth 4 relation) "")
3829                (nth 1 relation)
3830                (or (nth 2 relation) "") 0 0 "")
3831               gnus-newsgroup-dependencies nil)
3832          (push gnus-reffed-article-number gnus-newsgroup-limit)
3833          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3834          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3835                gnus-newsgroup-reads)
3836          (decf gnus-reffed-article-number)))
3837      (sort relations 'car-less-than-car))
3838     (gnus-message 7 "Making sparse threads...done")))
3839
3840 (defun gnus-build-old-threads ()
3841   ;; Look at all the articles that refer back to old articles, and
3842   ;; fetch the headers for the articles that aren't there.  This will
3843   ;; build complete threads - if the roots haven't been expired by the
3844   ;; server, that is.
3845   (let ((mail-parse-charset gnus-newsgroup-charset)
3846         id heads)
3847     (mapatoms
3848      (lambda (refs)
3849        (when (not (car (symbol-value refs)))
3850          (setq heads (cdr (symbol-value refs)))
3851          (while heads
3852            (if (memq (mail-header-number (caar heads))
3853                      gnus-newsgroup-dormant)
3854                (setq heads (cdr heads))
3855              (setq id (symbol-name refs))
3856              (while (and (setq id (gnus-build-get-header id))
3857                          (not (car (gnus-id-to-thread id)))))
3858              (setq heads nil)))))
3859      gnus-newsgroup-dependencies)))
3860
3861 ;; This function has to be called with point after the article number
3862 ;; on the beginning of the line.
3863 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3864   (let ((eol (gnus-point-at-eol))
3865         (buffer (current-buffer))
3866         header references in-reply-to)
3867
3868     ;; overview: [num subject from date id refs chars lines misc]
3869     (unwind-protect
3870         (progn
3871           (narrow-to-region (point) eol)
3872           (unless (eobp)
3873             (forward-char))
3874
3875           (setq header
3876                 (make-full-mail-header
3877                  number                         ; number
3878                  (nnheader-nov-field)           ; subject
3879                  (nnheader-nov-field)           ; from
3880                  (nnheader-nov-field)           ; date
3881                  (nnheader-nov-read-message-id) ; id
3882                  (nnheader-nov-field)           ; refs
3883                  (nnheader-nov-read-integer)    ; chars
3884                  (nnheader-nov-read-integer)    ; lines
3885                  (unless (eobp)
3886                    (if (looking-at "Xref: ")
3887                        (goto-char (match-end 0)))
3888                    (nnheader-nov-field))        ; Xref
3889                  (nnheader-nov-parse-extra))))  ; extra
3890
3891       (widen))
3892
3893     (when (and (string= references "")
3894                (setq in-reply-to (mail-header-extra header))
3895                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3896       (mail-header-set-references
3897        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3898
3899     (when gnus-alter-header-function
3900       (funcall gnus-alter-header-function header))
3901     (gnus-dependencies-add-header header dependencies force-new)))
3902
3903 (defun gnus-build-get-header (id)
3904   "Look through the buffer of NOV lines and find the header to ID.
3905 Enter this line into the dependencies hash table, and return
3906 the id of the parent article (if any)."
3907   (let ((deps gnus-newsgroup-dependencies)
3908         found header)
3909     (prog1
3910         (save-excursion
3911           (set-buffer nntp-server-buffer)
3912           (let ((case-fold-search nil))
3913             (goto-char (point-min))
3914             (while (and (not found)
3915                         (search-forward id nil t))
3916               (beginning-of-line)
3917               (setq found (looking-at
3918                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3919                                    (regexp-quote id))))
3920               (or found (beginning-of-line 2)))
3921             (when found
3922               (beginning-of-line)
3923               (and
3924                (setq header (gnus-nov-parse-line
3925                              (read (current-buffer)) deps))
3926                (gnus-parent-id (mail-header-references header))))))
3927       (when header
3928         (let ((number (mail-header-number header)))
3929           (push number gnus-newsgroup-limit)
3930           (push header gnus-newsgroup-headers)
3931           (if (memq number gnus-newsgroup-unselected)
3932               (progn
3933                 (setq gnus-newsgroup-unreads
3934                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3935                                                number))
3936                 (setq gnus-newsgroup-unselected
3937                       (delq number gnus-newsgroup-unselected)))
3938             (push number gnus-newsgroup-ancient)))))))
3939
3940 (defun gnus-build-all-threads ()
3941   "Read all the headers."
3942   (let ((gnus-summary-ignore-duplicates t)
3943         (mail-parse-charset gnus-newsgroup-charset)
3944         (dependencies gnus-newsgroup-dependencies)
3945         header article)
3946     (save-excursion
3947       (set-buffer nntp-server-buffer)
3948       (let ((case-fold-search nil))
3949         (goto-char (point-min))
3950         (while (not (eobp))
3951           (ignore-errors
3952             (setq article (read (current-buffer))
3953                   header (gnus-nov-parse-line article dependencies)))
3954           (when header
3955             (save-excursion
3956               (set-buffer gnus-summary-buffer)
3957               (push header gnus-newsgroup-headers)
3958               (if (memq (setq article (mail-header-number header))
3959                         gnus-newsgroup-unselected)
3960                   (progn
3961                     (setq gnus-newsgroup-unreads
3962                           (gnus-add-to-sorted-list
3963                            gnus-newsgroup-unreads article))
3964                     (setq gnus-newsgroup-unselected
3965                           (delq article gnus-newsgroup-unselected)))
3966                 (push article gnus-newsgroup-ancient)))
3967             (forward-line 1)))))))
3968
3969 (defun gnus-summary-update-article-line (article header)
3970   "Update the line for ARTICLE using HEADERS."
3971   (let* ((id (mail-header-id header))
3972          (thread (gnus-id-to-thread id)))
3973     (unless thread
3974       (error "Article in no thread"))
3975     ;; Update the thread.
3976     (setcar thread header)
3977     (gnus-summary-goto-subject article)
3978     (let* ((datal (gnus-data-find-list article))
3979            (data (car datal))
3980            (length (when (cdr datal)
3981                      (- (gnus-data-pos data)
3982                         (gnus-data-pos (cadr datal)))))
3983            (buffer-read-only nil)
3984            (level (gnus-summary-thread-level)))
3985       (gnus-delete-line)
3986       (gnus-summary-insert-line
3987        header level nil (gnus-article-mark article)
3988        (memq article gnus-newsgroup-replied)
3989        (memq article gnus-newsgroup-expirable)
3990        ;; Only insert the Subject string when it's different
3991        ;; from the previous Subject string.
3992        (if (and
3993             gnus-show-threads
3994             (gnus-subject-equal
3995              (condition-case ()
3996                  (mail-header-subject
3997                   (gnus-data-header
3998                    (cadr
3999                     (gnus-data-find-list
4000                      article
4001                      (gnus-data-list t)))))
4002                ;; Error on the side of excessive subjects.
4003                (error ""))
4004              (mail-header-subject header)))
4005            ""
4006          (mail-header-subject header))
4007        nil (cdr (assq article gnus-newsgroup-scored))
4008        (memq article gnus-newsgroup-processable))
4009       (when length
4010         (gnus-data-update-list
4011          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
4012
4013 (defun gnus-summary-update-article (article &optional iheader)
4014   "Update ARTICLE in the summary buffer."
4015   (set-buffer gnus-summary-buffer)
4016   (let* ((header (gnus-summary-article-header article))
4017          (id (mail-header-id header))
4018          (data (gnus-data-find article))
4019          (thread (gnus-id-to-thread id))
4020          (references (mail-header-references header))
4021          (parent
4022           (gnus-id-to-thread
4023            (or (gnus-parent-id
4024                 (when (and references
4025                            (not (equal "" references)))
4026                   references))
4027                "none")))
4028          (buffer-read-only nil)
4029          (old (car thread)))
4030     (when thread
4031       (unless iheader
4032         (setcar thread nil)
4033         (when parent
4034           (delq thread parent)))
4035       (if (gnus-summary-insert-subject id header)
4036           ;; Set the (possibly) new article number in the data structure.
4037           (gnus-data-set-number data (gnus-id-to-article id))
4038         (setcar thread old)
4039         nil))))
4040
4041 (defun gnus-rebuild-thread (id &optional line)
4042   "Rebuild the thread containing ID.
4043 If LINE, insert the rebuilt thread starting on line LINE."
4044   (let ((buffer-read-only nil)
4045         old-pos current thread data)
4046     (if (not gnus-show-threads)
4047         (setq thread (list (car (gnus-id-to-thread id))))
4048       ;; Get the thread this article is part of.
4049       (setq thread (gnus-remove-thread id)))
4050     (setq old-pos (gnus-point-at-bol))
4051     (setq current (save-excursion
4052                     (and (re-search-backward "[\r\n]" nil t)
4053                          (gnus-summary-article-number))))
4054     ;; If this is a gathered thread, we have to go some re-gathering.
4055     (when (stringp (car thread))
4056       (let ((subject (car thread))
4057             roots thr)
4058         (setq thread (cdr thread))
4059         (while thread
4060           (unless (memq (setq thr (gnus-id-to-thread
4061                                    (gnus-root-id
4062                                     (mail-header-id (caar thread)))))
4063                         roots)
4064             (push thr roots))
4065           (setq thread (cdr thread)))
4066         ;; We now have all (unique) roots.
4067         (if (= (length roots) 1)
4068             ;; All the loose roots are now one solid root.
4069             (setq thread (car roots))
4070           (setq thread (cons subject (gnus-sort-threads roots))))))
4071     (let (threads)
4072       ;; We then insert this thread into the summary buffer.
4073       (when line
4074         (goto-char (point-min))
4075         (forward-line (1- line)))
4076       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4077         (if gnus-show-threads
4078             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4079           (gnus-summary-prepare-unthreaded thread))
4080         (setq data (nreverse gnus-newsgroup-data))
4081         (setq threads gnus-newsgroup-threads))
4082       ;; We splice the new data into the data structure.
4083       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4084       ;;!!! then we want to insert at the beginning of the buffer.
4085       ;;!!! That happens to be true with Gnus now, but that may
4086       ;;!!! change in the future.  Perhaps.
4087       (gnus-data-enter-list
4088        (if line nil current) data (- (point) old-pos))
4089       (setq gnus-newsgroup-threads
4090             (nconc threads gnus-newsgroup-threads))
4091       (gnus-data-compute-positions))))
4092
4093 (defun gnus-number-to-header (number)
4094   "Return the header for article NUMBER."
4095   (let ((headers gnus-newsgroup-headers))
4096     (while (and headers
4097                 (not (= number (mail-header-number (car headers)))))
4098       (pop headers))
4099     (when headers
4100       (car headers))))
4101
4102 (defun gnus-parent-headers (in-headers &optional generation)
4103   "Return the headers of the GENERATIONeth parent of HEADERS."
4104   (unless generation
4105     (setq generation 1))
4106   (let ((parent t)
4107         (headers in-headers)
4108         references)
4109     (while (and parent
4110                 (not (zerop generation))
4111                 (setq references (mail-header-references headers)))
4112       (setq headers (if (and references
4113                              (setq parent (gnus-parent-id references)))
4114                         (car (gnus-id-to-thread parent))
4115                       nil))
4116       (decf generation))
4117     (and (not (eq headers in-headers))
4118          headers)))
4119
4120 (defun gnus-id-to-thread (id)
4121   "Return the (sub-)thread where ID appears."
4122   (gnus-gethash id gnus-newsgroup-dependencies))
4123
4124 (defun gnus-id-to-article (id)
4125   "Return the article number of ID."
4126   (let ((thread (gnus-id-to-thread id)))
4127     (when (and thread
4128                (car thread))
4129       (mail-header-number (car thread)))))
4130
4131 (defun gnus-id-to-header (id)
4132   "Return the article headers of ID."
4133   (car (gnus-id-to-thread id)))
4134
4135 (defun gnus-article-displayed-root-p (article)
4136   "Say whether ARTICLE is a root(ish) article."
4137   (let ((level (gnus-summary-thread-level article))
4138         (refs (mail-header-references  (gnus-summary-article-header article)))
4139         particle)
4140     (cond
4141      ((null level) nil)
4142      ((zerop level) t)
4143      ((null refs) t)
4144      ((null (gnus-parent-id refs)) t)
4145      ((and (= 1 level)
4146            (null (setq particle (gnus-id-to-article
4147                                  (gnus-parent-id refs))))
4148            (null (gnus-summary-thread-level particle)))))))
4149
4150 (defun gnus-root-id (id)
4151   "Return the id of the root of the thread where ID appears."
4152   (let (last-id prev)
4153     (while (and id (setq prev (car (gnus-id-to-thread id))))
4154       (setq last-id id
4155             id (gnus-parent-id (mail-header-references prev))))
4156     last-id))
4157
4158 (defun gnus-articles-in-thread (thread)
4159   "Return the list of articles in THREAD."
4160   (cons (mail-header-number (car thread))
4161         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4162
4163 (defun gnus-remove-thread (id &optional dont-remove)
4164   "Remove the thread that has ID in it."
4165   (let (headers thread last-id)
4166     ;; First go up in this thread until we find the root.
4167     (setq last-id (gnus-root-id id)
4168           headers (message-flatten-list (gnus-id-to-thread last-id)))
4169     ;; We have now found the real root of this thread.  It might have
4170     ;; been gathered into some loose thread, so we have to search
4171     ;; through the threads to find the thread we wanted.
4172     (let ((threads gnus-newsgroup-threads)
4173           sub)
4174       (while threads
4175         (setq sub (car threads))
4176         (if (stringp (car sub))
4177             ;; This is a gathered thread, so we look at the roots
4178             ;; below it to find whether this article is in this
4179             ;; gathered root.
4180             (progn
4181               (setq sub (cdr sub))
4182               (while sub
4183                 (when (member (caar sub) headers)
4184                   (setq thread (car threads)
4185                         threads nil
4186                         sub nil))
4187                 (setq sub (cdr sub))))
4188           ;; It's an ordinary thread, so we check it.
4189           (when (eq (car sub) (car headers))
4190             (setq thread sub
4191                   threads nil)))
4192         (setq threads (cdr threads)))
4193       ;; If this article is in no thread, then it's a root.
4194       (if thread
4195           (unless dont-remove
4196             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4197         (setq thread (gnus-id-to-thread last-id)))
4198       (when thread
4199         (prog1
4200             thread                      ; We return this thread.
4201           (unless dont-remove
4202             (if (stringp (car thread))
4203                 (progn
4204                   ;; If we use dummy roots, then we have to remove the
4205                   ;; dummy root as well.
4206                   (when (eq gnus-summary-make-false-root 'dummy)
4207                     ;; We go to the dummy root by going to
4208                     ;; the first sub-"thread", and then one line up.
4209                     (gnus-summary-goto-article
4210                      (mail-header-number (caadr thread)))
4211                     (forward-line -1)
4212                     (gnus-delete-line)
4213                     (gnus-data-compute-positions))
4214                   (setq thread (cdr thread))
4215                   (while thread
4216                     (gnus-remove-thread-1 (car thread))
4217                     (setq thread (cdr thread))))
4218               (gnus-remove-thread-1 thread))))))))
4219
4220 (defun gnus-remove-thread-1 (thread)
4221   "Remove the thread THREAD recursively."
4222   (let ((number (mail-header-number (pop thread)))
4223         d)
4224     (setq thread (reverse thread))
4225     (while thread
4226       (gnus-remove-thread-1 (pop thread)))
4227     (when (setq d (gnus-data-find number))
4228       (goto-char (gnus-data-pos d))
4229       (gnus-summary-show-thread)
4230       (gnus-data-remove
4231        number
4232        (- (gnus-point-at-bol)
4233           (prog1
4234               (1+ (gnus-point-at-eol))
4235             (gnus-delete-line)))))))
4236
4237 (defun gnus-sort-threads-1 (threads func)
4238   (sort (mapcar (lambda (thread)
4239                   (cons (car thread)
4240                         (and (cdr thread)
4241                              (gnus-sort-threads-1 (cdr thread) func))))
4242                 threads) func))
4243
4244 (defun gnus-sort-threads (threads)
4245   "Sort THREADS."
4246   (if (not gnus-thread-sort-functions)
4247       threads
4248     (gnus-message 8 "Sorting threads...")
4249     (prog1
4250         (gnus-sort-threads-1
4251          threads
4252          (gnus-make-sort-function gnus-thread-sort-functions))
4253       (gnus-message 8 "Sorting threads...done"))))
4254
4255 (defun gnus-sort-articles (articles)
4256   "Sort ARTICLES."
4257   (when gnus-article-sort-functions
4258     (gnus-message 7 "Sorting articles...")
4259     (prog1
4260         (setq gnus-newsgroup-headers
4261               (sort articles (gnus-make-sort-function
4262                               gnus-article-sort-functions)))
4263       (gnus-message 7 "Sorting articles...done"))))
4264
4265 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4266 (defmacro gnus-thread-header (thread)
4267   "Return header of first article in THREAD.
4268 Note that THREAD must never, ever be anything else than a variable -
4269 using some other form will lead to serious barfage."
4270   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4271   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4272   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4273         (vector thread) 2))
4274
4275 (defsubst gnus-article-sort-by-number (h1 h2)
4276   "Sort articles by article number."
4277   (< (mail-header-number h1)
4278      (mail-header-number h2)))
4279
4280 (defun gnus-thread-sort-by-number (h1 h2)
4281   "Sort threads by root article number."
4282   (gnus-article-sort-by-number
4283    (gnus-thread-header h1) (gnus-thread-header h2)))
4284
4285 (defsubst gnus-article-sort-by-random (h1 h2)
4286   "Sort articles by article number."
4287   (zerop (random 2)))
4288
4289 (defun gnus-thread-sort-by-random (h1 h2)
4290   "Sort threads by root article number."
4291   (gnus-article-sort-by-random
4292    (gnus-thread-header h1) (gnus-thread-header h2)))
4293
4294 (defsubst gnus-article-sort-by-lines (h1 h2)
4295   "Sort articles by article Lines header."
4296   (< (mail-header-lines h1)
4297      (mail-header-lines h2)))
4298
4299 (defun gnus-thread-sort-by-lines (h1 h2)
4300   "Sort threads by root article Lines header."
4301   (gnus-article-sort-by-lines
4302    (gnus-thread-header h1) (gnus-thread-header h2)))
4303
4304 (defsubst gnus-article-sort-by-chars (h1 h2)
4305   "Sort articles by octet length."
4306   (< (mail-header-chars h1)
4307      (mail-header-chars h2)))
4308
4309 (defun gnus-thread-sort-by-chars (h1 h2)
4310   "Sort threads by root article octet length."
4311   (gnus-article-sort-by-chars
4312    (gnus-thread-header h1) (gnus-thread-header h2)))
4313
4314 (defsubst gnus-article-sort-by-author (h1 h2)
4315   "Sort articles by root author."
4316   (string-lessp
4317    (let ((addr (car (mime-entity-read-field h1 'From))))
4318      (or (std11-full-name-string addr)
4319          (std11-address-string addr)
4320          ""))
4321    (let ((addr (car (mime-entity-read-field h2 'From))))
4322      (or (std11-full-name-string addr)
4323          (std11-address-string addr)
4324          ""))
4325    ))
4326
4327 (defun gnus-thread-sort-by-author (h1 h2)
4328   "Sort threads by root author."
4329   (gnus-article-sort-by-author
4330    (gnus-thread-header h1)  (gnus-thread-header h2)))
4331
4332 (defsubst gnus-article-sort-by-subject (h1 h2)
4333   "Sort articles by root subject."
4334   (string-lessp
4335    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4336    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4337
4338 (defun gnus-thread-sort-by-subject (h1 h2)
4339   "Sort threads by root subject."
4340   (gnus-article-sort-by-subject
4341    (gnus-thread-header h1) (gnus-thread-header h2)))
4342
4343 (defsubst gnus-article-sort-by-date (h1 h2)
4344   "Sort articles by root article date."
4345   (time-less-p
4346    (gnus-date-get-time (mail-header-date h1))
4347    (gnus-date-get-time (mail-header-date h2))))
4348
4349 (defun gnus-thread-sort-by-date (h1 h2)
4350   "Sort threads by root article date."
4351   (gnus-article-sort-by-date
4352    (gnus-thread-header h1) (gnus-thread-header h2)))
4353
4354 (defsubst gnus-article-sort-by-score (h1 h2)
4355   "Sort articles by root article score.
4356 Unscored articles will be counted as having a score of zero."
4357   (> (or (cdr (assq (mail-header-number h1)
4358                     gnus-newsgroup-scored))
4359          gnus-summary-default-score 0)
4360      (or (cdr (assq (mail-header-number h2)
4361                     gnus-newsgroup-scored))
4362          gnus-summary-default-score 0)))
4363
4364 (defun gnus-thread-sort-by-score (h1 h2)
4365   "Sort threads by root article score."
4366   (gnus-article-sort-by-score
4367    (gnus-thread-header h1) (gnus-thread-header h2)))
4368
4369 (defun gnus-thread-sort-by-total-score (h1 h2)
4370   "Sort threads by the sum of all scores in the thread.
4371 Unscored articles will be counted as having a score of zero."
4372   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4373
4374 (defun gnus-thread-total-score (thread)
4375   ;; This function find the total score of THREAD.
4376   (cond
4377    ((null thread)
4378     0)
4379    ((consp thread)
4380     (if (stringp (car thread))
4381         (apply gnus-thread-score-function 0
4382                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4383       (gnus-thread-total-score-1 thread)))
4384    (t
4385     (gnus-thread-total-score-1 (list thread)))))
4386
4387 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4388   "Sort threads such that the thread with the most recently arrived article comes first."
4389   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4390
4391 (defun gnus-thread-highest-number (thread)
4392   "Return the highest article number in THREAD."
4393   (apply 'max (mapcar (lambda (header)
4394                         (mail-header-number header))
4395                       (message-flatten-list thread))))
4396
4397 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4398   "Sort threads such that the thread with the most recently dated article comes first."
4399   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4400
4401 (defun gnus-thread-latest-date (thread)
4402   "Return the highest article date in THREAD."
4403   (let ((previous-time 0))
4404     (apply 'max (mapcar
4405                  (lambda (header)
4406                    (setq previous-time
4407                          (time-to-seconds
4408                           (mail-header-parse-date
4409                            (condition-case ()
4410                                (mail-header-date header)
4411                              (error previous-time))))))
4412                  (sort
4413                   (message-flatten-list thread)
4414                   (lambda (h1 h2)
4415                     (< (mail-header-number h1)
4416                        (mail-header-number h2))))))))
4417
4418 (defun gnus-thread-total-score-1 (root)
4419   ;; This function find the total score of the thread below ROOT.
4420   (setq root (car root))
4421   (apply gnus-thread-score-function
4422          (or (append
4423               (mapcar 'gnus-thread-total-score
4424                       (cdr (gnus-id-to-thread (mail-header-id root))))
4425               (when (> (mail-header-number root) 0)
4426                 (list (or (cdr (assq (mail-header-number root)
4427                                      gnus-newsgroup-scored))
4428                           gnus-summary-default-score 0))))
4429              (list gnus-summary-default-score)
4430              '(0))))
4431
4432 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4433 (defvar gnus-tmp-prev-subject nil)
4434 (defvar gnus-tmp-false-parent nil)
4435 (defvar gnus-tmp-root-expunged nil)
4436 (defvar gnus-tmp-dummy-line nil)
4437
4438 (eval-when-compile (defvar gnus-tmp-header))
4439 (defun gnus-extra-header (type &optional header)
4440   "Return the extra header of TYPE."
4441   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4442       ""))
4443
4444 (defvar gnus-tmp-thread-tree-header-string "")
4445
4446 (defcustom gnus-sum-thread-tree-root "> "
4447   "With %B spec, used for the root of a thread.
4448 If nil, use subject instead."
4449   :type 'string
4450   :group 'gnus-thread)
4451 (defcustom gnus-sum-thread-tree-single-indent ""
4452   "With %B spec, used for a thread with just one message.
4453 If nil, use subject instead."
4454   :type 'string
4455   :group 'gnus-thread)
4456 (defcustom gnus-sum-thread-tree-vertical "| "
4457   "With %B spec, used for drawing a vertical line."
4458   :type 'string
4459   :group 'gnus-thread)
4460 (defcustom gnus-sum-thread-tree-indent "  "
4461   "With %B spec, used for indenting."
4462   :type 'string
4463   :group 'gnus-thread)
4464 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4465   "With %B spec, used for a leaf with brothers."
4466   :type 'string
4467   :group 'gnus-thread)
4468 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4469   "With %B spec, used for a leaf without brothers."
4470   :type 'string
4471   :group 'gnus-thread)
4472
4473 (defun gnus-summary-prepare-threads (threads)
4474   "Prepare summary buffer from THREADS and indentation LEVEL.
4475 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4476 or a straight list of headers."
4477   (gnus-message 7 "Generating summary...")
4478
4479   (setq gnus-newsgroup-threads threads)
4480   (beginning-of-line)
4481
4482   (let ((gnus-tmp-level 0)
4483         (default-score (or gnus-summary-default-score 0))
4484         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4485         thread number subject stack state gnus-tmp-gathered beg-match
4486         new-roots gnus-tmp-new-adopts thread-end simp-subject
4487         gnus-tmp-header gnus-tmp-unread
4488         gnus-tmp-replied gnus-tmp-subject-or-nil
4489         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4490         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4491         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4492         tree-stack)
4493
4494     (setq gnus-tmp-prev-subject nil)
4495
4496     (if (vectorp (car threads))
4497         ;; If this is a straight (sic) list of headers, then a
4498         ;; threaded summary display isn't required, so we just create
4499         ;; an unthreaded one.
4500         (gnus-summary-prepare-unthreaded threads)
4501
4502       ;; Do the threaded display.
4503
4504       (while (or threads stack gnus-tmp-new-adopts new-roots)
4505
4506         (if (and (= gnus-tmp-level 0)
4507                  (or (not stack)
4508                      (= (caar stack) 0))
4509                  (not gnus-tmp-false-parent)
4510                  (or gnus-tmp-new-adopts new-roots))
4511             (if gnus-tmp-new-adopts
4512                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4513                       thread (list (car gnus-tmp-new-adopts))
4514                       gnus-tmp-header (caar thread)
4515                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4516               (when new-roots
4517                 (setq thread (list (car new-roots))
4518                       gnus-tmp-header (caar thread)
4519                       new-roots (cdr new-roots))))
4520
4521           (if threads
4522               ;; If there are some threads, we do them before the
4523               ;; threads on the stack.
4524               (setq thread threads
4525                     gnus-tmp-header (caar thread))
4526             ;; There were no current threads, so we pop something off
4527             ;; the stack.
4528             (setq state (car stack)
4529                   gnus-tmp-level (car state)
4530                   tree-stack (cadr state)
4531                   thread (caddr state)
4532                   stack (cdr stack)
4533                   gnus-tmp-header (caar thread))))
4534
4535         (setq gnus-tmp-false-parent nil)
4536         (setq gnus-tmp-root-expunged nil)
4537         (setq thread-end nil)
4538
4539         (if (stringp gnus-tmp-header)
4540             ;; The header is a dummy root.
4541             (cond
4542              ((eq gnus-summary-make-false-root 'adopt)
4543               ;; We let the first article adopt the rest.
4544               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4545                                                (cddar thread)))
4546               (setq gnus-tmp-gathered
4547                     (nconc (mapcar
4548                             (lambda (h) (mail-header-number (car h)))
4549                             (cddar thread))
4550                            gnus-tmp-gathered))
4551               (setq thread (cons (list (caar thread)
4552                                        (cadar thread))
4553                                  (cdr thread)))
4554               (setq gnus-tmp-level -1
4555                     gnus-tmp-false-parent t))
4556              ((eq gnus-summary-make-false-root 'empty)
4557               ;; We print adopted articles with empty subject fields.
4558               (setq gnus-tmp-gathered
4559                     (nconc (mapcar
4560                             (lambda (h) (mail-header-number (car h)))
4561                             (cddar thread))
4562                            gnus-tmp-gathered))
4563               (setq gnus-tmp-level -1))
4564              ((eq gnus-summary-make-false-root 'dummy)
4565               ;; We remember that we probably want to output a dummy
4566               ;; root.
4567               (setq gnus-tmp-dummy-line gnus-tmp-header)
4568               (setq gnus-tmp-prev-subject gnus-tmp-header))
4569              (t
4570               ;; We do not make a root for the gathered
4571               ;; sub-threads at all.
4572               (setq gnus-tmp-level -1)))
4573
4574           (setq number (mail-header-number gnus-tmp-header)
4575                 subject (mail-header-subject gnus-tmp-header)
4576                 simp-subject (gnus-simplify-subject-fully subject))
4577
4578           (cond
4579            ;; If the thread has changed subject, we might want to make
4580            ;; this subthread into a root.
4581            ((and (null gnus-thread-ignore-subject)
4582                  (not (zerop gnus-tmp-level))
4583                  gnus-tmp-prev-subject
4584                  (not (string= gnus-tmp-prev-subject simp-subject)))
4585             (setq new-roots (nconc new-roots (list (car thread)))
4586                   thread-end t
4587                   gnus-tmp-header nil))
4588            ;; If the article lies outside the current limit,
4589            ;; then we do not display it.
4590            ((not (memq number gnus-newsgroup-limit))
4591             (setq gnus-tmp-gathered
4592                   (nconc (mapcar
4593                           (lambda (h) (mail-header-number (car h)))
4594                           (cdar thread))
4595                          gnus-tmp-gathered))
4596             (setq gnus-tmp-new-adopts (if (cdar thread)
4597                                           (append gnus-tmp-new-adopts
4598                                                   (cdar thread))
4599                                         gnus-tmp-new-adopts)
4600                   thread-end t
4601                   gnus-tmp-header nil)
4602             (when (zerop gnus-tmp-level)
4603               (setq gnus-tmp-root-expunged t)))
4604            ;; Perhaps this article is to be marked as read?
4605            ((and gnus-summary-mark-below
4606                  (< (or (cdr (assq number gnus-newsgroup-scored))
4607                         default-score)
4608                     gnus-summary-mark-below)
4609                  ;; Don't touch sparse articles.
4610                  (not (gnus-summary-article-sparse-p number))
4611                  (not (gnus-summary-article-ancient-p number)))
4612             (setq gnus-newsgroup-unreads
4613                   (delq number gnus-newsgroup-unreads))
4614             (if gnus-newsgroup-auto-expire
4615                 (setq gnus-newsgroup-expirable
4616                       (gnus-add-to-sorted-list
4617                        gnus-newsgroup-expirable number))
4618               (push (cons number gnus-low-score-mark)
4619                     gnus-newsgroup-reads))))
4620
4621           (when gnus-tmp-header
4622             ;; We may have an old dummy line to output before this
4623             ;; article.
4624             (when (and gnus-tmp-dummy-line
4625                        (gnus-subject-equal
4626                         gnus-tmp-dummy-line
4627                         (mail-header-subject gnus-tmp-header)))
4628               (gnus-summary-insert-dummy-line
4629                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4630               (setq gnus-tmp-dummy-line nil))
4631
4632             ;; Compute the mark.
4633             (setq gnus-tmp-unread (gnus-article-mark number))
4634
4635             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4636                                   gnus-tmp-header gnus-tmp-level)
4637                   gnus-newsgroup-data)
4638
4639             ;; Actually insert the line.
4640             (setq
4641              gnus-tmp-subject-or-nil
4642              (cond
4643               ((and gnus-thread-ignore-subject
4644                     gnus-tmp-prev-subject
4645                     (not (string= gnus-tmp-prev-subject simp-subject)))
4646                subject)
4647               ((zerop gnus-tmp-level)
4648                (if (and (eq gnus-summary-make-false-root 'empty)
4649                         (memq number gnus-tmp-gathered)
4650                         gnus-tmp-prev-subject
4651                         (string= gnus-tmp-prev-subject simp-subject))
4652                    gnus-summary-same-subject
4653                  subject))
4654               (t gnus-summary-same-subject)))
4655             (if (and (eq gnus-summary-make-false-root 'adopt)
4656                      (= gnus-tmp-level 1)
4657                      (memq number gnus-tmp-gathered))
4658                 (setq gnus-tmp-opening-bracket ?\<
4659                       gnus-tmp-closing-bracket ?\>)
4660               (setq gnus-tmp-opening-bracket ?\[
4661                     gnus-tmp-closing-bracket ?\]))
4662             (setq
4663              gnus-tmp-indentation
4664              (aref gnus-thread-indent-array gnus-tmp-level)
4665              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4666              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4667                                 gnus-summary-default-score 0)
4668              gnus-tmp-score-char
4669              (if (or (null gnus-summary-default-score)
4670                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4671                          gnus-summary-zcore-fuzz))
4672                  ?\ ;;;Whitespace
4673                (if (< gnus-tmp-score gnus-summary-default-score)
4674                    gnus-score-below-mark gnus-score-over-mark))
4675              gnus-tmp-replied
4676              (cond ((memq number gnus-newsgroup-processable)
4677                     gnus-process-mark)
4678                    ((memq number gnus-newsgroup-cached)
4679                     gnus-cached-mark)
4680                    ((memq number gnus-newsgroup-replied)
4681                     gnus-replied-mark)
4682                    ((memq number gnus-newsgroup-forwarded)
4683                     gnus-forwarded-mark)
4684                    ((memq number gnus-newsgroup-saved)
4685                     gnus-saved-mark)
4686                    ((memq number gnus-newsgroup-recent)
4687                     gnus-recent-mark)
4688                    ((memq number gnus-newsgroup-unseen)
4689                     gnus-unseen-mark)
4690                    (t gnus-no-mark))
4691              gnus-tmp-from (mail-header-from gnus-tmp-header)
4692              gnus-tmp-name
4693              (cond
4694               ((string-match "<[^>]+> *$" gnus-tmp-from)
4695                (setq beg-match (match-beginning 0))
4696                (or (and (string-match "^\".+\"" gnus-tmp-from)
4697                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4698                    (substring gnus-tmp-from 0 beg-match)))
4699               ((string-match "(.+)" gnus-tmp-from)
4700                (substring gnus-tmp-from
4701                           (1+ (match-beginning 0)) (1- (match-end 0))))
4702               (t gnus-tmp-from))
4703              gnus-tmp-thread-tree-header-string
4704              (cond
4705               ((not gnus-show-threads) "")
4706               ((zerop gnus-tmp-level)
4707                (if (cdar thread)
4708                    (or gnus-sum-thread-tree-root subject)
4709                  (or gnus-sum-thread-tree-single-indent subject)))
4710               (t
4711                (concat (apply 'concat
4712                               (mapcar (lambda (item)
4713                                         (if (= item 1)
4714                                             gnus-sum-thread-tree-vertical
4715                                           gnus-sum-thread-tree-indent))
4716                                       (cdr (reverse tree-stack))))
4717                        (if (nth 1 thread)
4718                            gnus-sum-thread-tree-leaf-with-other
4719                          gnus-sum-thread-tree-single-leaf)))))
4720             (when (string= gnus-tmp-name "")
4721               (setq gnus-tmp-name gnus-tmp-from))
4722             (unless (numberp gnus-tmp-lines)
4723               (setq gnus-tmp-lines -1))
4724             (if (= gnus-tmp-lines -1)
4725                 (setq gnus-tmp-lines "?")
4726               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4727             (gnus-put-text-property
4728              (point)
4729              (progn (eval gnus-summary-line-format-spec) (point))
4730              'gnus-number number)
4731             (when gnus-visual-p
4732               (forward-line -1)
4733               (gnus-run-hooks 'gnus-summary-update-hook)
4734               (forward-line 1))
4735
4736             (setq gnus-tmp-prev-subject simp-subject)))
4737
4738         (when (nth 1 thread)
4739           (push (list (max 0 gnus-tmp-level)
4740                       (copy-list tree-stack)
4741                       (nthcdr 1 thread))
4742                 stack))
4743         (push (if (nth 1 thread) 1 0) tree-stack)
4744         (incf gnus-tmp-level)
4745         (setq threads (if thread-end nil (cdar thread)))
4746         (unless threads
4747           (setq gnus-tmp-level 0)))))
4748   (gnus-message 7 "Generating summary...done"))
4749
4750 (defun gnus-summary-prepare-unthreaded (headers)
4751   "Generate an unthreaded summary buffer based on HEADERS."
4752   (let (header number mark)
4753
4754     (beginning-of-line)
4755
4756     (while headers
4757       ;; We may have to root out some bad articles...
4758       (when (memq (setq number (mail-header-number
4759                                 (setq header (pop headers))))
4760                   gnus-newsgroup-limit)
4761         ;; Mark article as read when it has a low score.
4762         (when (and gnus-summary-mark-below
4763                    (< (or (cdr (assq number gnus-newsgroup-scored))
4764                           gnus-summary-default-score 0)
4765                       gnus-summary-mark-below)
4766                    (not (gnus-summary-article-ancient-p number)))
4767           (setq gnus-newsgroup-unreads
4768                 (delq number gnus-newsgroup-unreads))
4769           (if gnus-newsgroup-auto-expire
4770               (push number gnus-newsgroup-expirable)
4771             (push (cons number gnus-low-score-mark)
4772                   gnus-newsgroup-reads)))
4773
4774         (setq mark (gnus-article-mark number))
4775         (push (gnus-data-make number mark (1+ (point)) header 0)
4776               gnus-newsgroup-data)
4777         (gnus-summary-insert-line
4778          header 0 number
4779          mark (memq number gnus-newsgroup-replied)
4780          (memq number gnus-newsgroup-expirable)
4781          (mail-header-subject header) nil
4782          (cdr (assq number gnus-newsgroup-scored))
4783          (memq number gnus-newsgroup-processable))))))
4784
4785 (defun gnus-summary-remove-list-identifiers ()
4786   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4787   (let ((regexp (if (consp gnus-list-identifiers)
4788                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4789                   gnus-list-identifiers))
4790         changed subject)
4791     (when regexp
4792       (dolist (header gnus-newsgroup-headers)
4793         (setq subject (mail-header-subject header)
4794               changed nil)
4795         (while (string-match
4796                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4797                 subject)
4798           (setq subject
4799                 (concat (substring subject 0 (match-beginning 2))
4800                         (substring subject (match-end 0)))
4801                 changed t))
4802         (when (and changed
4803                    (string-match
4804                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4805           (setq subject
4806                 (concat (substring subject 0 (match-beginning 1))
4807                         (substring subject (match-end 1)))))
4808         (when changed
4809           (mail-header-set-subject header subject))))))
4810
4811 (defun gnus-fetch-headers (articles)
4812   "Fetch headers of ARTICLES."
4813   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4814     (gnus-message 5 "Fetching headers for %s..." name)
4815     (prog1
4816         (if (eq 'nov
4817                 (setq gnus-headers-retrieved-by
4818                       (gnus-retrieve-headers
4819                        articles gnus-newsgroup-name
4820                        ;; We might want to fetch old headers, but
4821                        ;; not if there is only 1 article.
4822                        (and (or (and
4823                                  (not (eq gnus-fetch-old-headers 'some))
4824                                  (not (numberp gnus-fetch-old-headers)))
4825                                 (> (length articles) 1))
4826                             gnus-fetch-old-headers))))
4827             (gnus-get-newsgroup-headers-xover
4828              articles nil nil gnus-newsgroup-name t)
4829           (gnus-get-newsgroup-headers))
4830       (gnus-message 5 "Fetching headers for %s...done" name))))
4831
4832 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4833   "Select newsgroup GROUP.
4834 If READ-ALL is non-nil, all articles in the group are selected.
4835 If SELECT-ARTICLES, only select those articles from GROUP."
4836   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4837          ;;!!! Dirty hack; should be removed.
4838          (gnus-summary-ignore-duplicates
4839           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4840               t
4841             gnus-summary-ignore-duplicates))
4842          (info (nth 2 entry))
4843          articles fetched-articles cached)
4844
4845     (unless (gnus-check-server
4846              (set (make-local-variable 'gnus-current-select-method)
4847                   (gnus-find-method-for-group group)))
4848       (error "Couldn't open server"))
4849
4850     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4851         (gnus-activate-group group)     ; Or we can activate it...
4852         (progn                          ; Or we bug out.
4853           (when (equal major-mode 'gnus-summary-mode)
4854             (kill-buffer (current-buffer)))
4855           (error "Couldn't activate group %s: %s"
4856                  group (gnus-status-message group))))
4857
4858     (unless (gnus-request-group group t)
4859       (when (equal major-mode 'gnus-summary-mode)
4860         (kill-buffer (current-buffer)))
4861       (error "Couldn't request group %s: %s"
4862              group (gnus-status-message group)))
4863
4864     (setq gnus-newsgroup-name group
4865           gnus-newsgroup-unselected nil
4866           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4867
4868     (let ((display (gnus-group-find-parameter group 'display)))
4869       (setq gnus-newsgroup-display
4870             (cond
4871              ((not (zerop (or (car-safe read-all) 0)))
4872               ;; The user entered the group with C-u SPC/RET, let's show
4873               ;; all articles.
4874               'gnus-not-ignore)
4875              ((eq display 'all)
4876               'gnus-not-ignore)
4877              ((arrayp display)
4878               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4879              ((numberp display)
4880               ;; The following is probably the "correct" solution, but
4881               ;; it makes Gnus fetch all headers and then limit the
4882               ;; articles (which is slow), so instead we hack the
4883               ;; select-articles parameter instead. -- Simon Josefsson
4884               ;; <jas@kth.se>
4885               ;;
4886               ;; (gnus-byte-compile
4887               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4888               ;;                         display)))))
4889               (setq select-articles
4890                     (gnus-uncompress-range
4891                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4892                              (if (> tmp 0)
4893                                  tmp
4894                                1))
4895                            (cdr (gnus-active group)))))
4896               nil)
4897              (t
4898               nil))))
4899
4900     (gnus-summary-setup-default-charset)
4901
4902     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4903     (when (gnus-virtual-group-p group)
4904       (setq cached gnus-newsgroup-cached))
4905
4906     (setq gnus-newsgroup-unreads
4907           (gnus-sorted-ndifference
4908            (gnus-sorted-ndifference gnus-newsgroup-unreads
4909                                     gnus-newsgroup-marked)
4910            gnus-newsgroup-dormant))
4911
4912     (setq gnus-newsgroup-processable nil)
4913
4914     (gnus-update-read-articles group gnus-newsgroup-unreads)
4915
4916     ;; Adjust and set lists of article marks.
4917     (when info
4918       (gnus-adjust-marked-articles info))
4919
4920     (if (setq articles select-articles)
4921         (setq gnus-newsgroup-unselected
4922               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4923       (setq articles (gnus-articles-to-read group read-all)))
4924
4925     (cond
4926      ((null articles)
4927       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4928       'quit)
4929      ((eq articles 0) nil)
4930      (t
4931       ;; Init the dependencies hash table.
4932       (setq gnus-newsgroup-dependencies
4933             (gnus-make-hashtable (length articles)))
4934       (gnus-set-global-variables)
4935       ;; Retrieve the headers and read them in.
4936       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4937
4938       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4939       (when cached
4940         (setq gnus-newsgroup-cached cached))
4941
4942       ;; Suppress duplicates?
4943       (when gnus-suppress-duplicates
4944         (gnus-dup-suppress-articles))
4945
4946       ;; Set the initial limit.
4947       (setq gnus-newsgroup-limit (copy-sequence articles))
4948       ;; Remove canceled articles from the list of unread articles.
4949       (setq fetched-articles
4950             (mapcar (lambda (headers) (mail-header-number headers))
4951                     gnus-newsgroup-headers))
4952       (setq gnus-newsgroup-articles fetched-articles)
4953       (setq gnus-newsgroup-unreads
4954             (gnus-sorted-nintersection
4955              gnus-newsgroup-unreads fetched-articles))
4956       (gnus-compute-unseen-list)
4957
4958       ;; Removed marked articles that do not exist.
4959       (gnus-update-missing-marks
4960        (gnus-sorted-difference articles fetched-articles))
4961       ;; We might want to build some more threads first.
4962       (when (and gnus-fetch-old-headers
4963                  (eq gnus-headers-retrieved-by 'nov))
4964         (if (eq gnus-fetch-old-headers 'invisible)
4965             (gnus-build-all-threads)
4966           (gnus-build-old-threads)))
4967       ;; Let the Gnus agent mark articles as read.
4968       (when gnus-agent
4969         (gnus-agent-get-undownloaded-list))
4970       ;; Remove list identifiers from subject
4971       (when gnus-list-identifiers
4972         (gnus-summary-remove-list-identifiers))
4973       ;; Check whether auto-expire is to be done in this group.
4974       (setq gnus-newsgroup-auto-expire
4975             (gnus-group-auto-expirable-p group))
4976       ;; Set up the article buffer now, if necessary.
4977       (unless gnus-single-article-buffer
4978         (gnus-article-setup-buffer))
4979       ;; First and last article in this newsgroup.
4980       (when gnus-newsgroup-headers
4981         (setq gnus-newsgroup-begin
4982               (mail-header-number (car gnus-newsgroup-headers))
4983               gnus-newsgroup-end
4984               (mail-header-number
4985                (gnus-last-element gnus-newsgroup-headers))))
4986       ;; GROUP is successfully selected.
4987       (or gnus-newsgroup-headers t)))))
4988
4989 (defun gnus-compute-unseen-list ()
4990   ;; The `seen' marks are treated specially.
4991   (if (not gnus-newsgroup-seen)
4992       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4993     (setq gnus-newsgroup-unseen
4994           (gnus-inverse-list-range-intersection
4995            gnus-newsgroup-articles gnus-newsgroup-seen))))
4996
4997 (defun gnus-summary-display-make-predicate (display)
4998   (require 'gnus-agent)
4999   (when (= (length display) 1)
5000     (setq display (car display)))
5001   (unless gnus-summary-display-cache
5002     (dolist (elem (append '((unread . unread)
5003                             (read . read)
5004                             (unseen . unseen))
5005                           gnus-article-mark-lists))
5006       (push (cons (cdr elem)
5007                   (gnus-byte-compile
5008                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5009             gnus-summary-display-cache)))
5010   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5011         (gnus-category-predicate-cache gnus-summary-display-cache))
5012     (gnus-get-predicate display)))
5013
5014 ;; Uses the dynamically bound `number' variable.
5015 (defvar number)
5016 (defun gnus-article-marked-p (type &optional article)
5017   (let ((article (or article number)))
5018     (cond
5019      ((eq type 'tick)
5020       (memq article gnus-newsgroup-marked))
5021      ((eq type 'spam)
5022       (memq article gnus-newsgroup-spam-marked))
5023      ((eq type 'unsend)
5024       (memq article gnus-newsgroup-unsendable))
5025      ((eq type 'undownload)
5026       (memq article gnus-newsgroup-undownloaded))
5027      ((eq type 'download)
5028       (memq article gnus-newsgroup-downloadable))
5029      ((eq type 'unread)
5030       (memq article gnus-newsgroup-unreads))
5031      ((eq type 'read)
5032       (memq article gnus-newsgroup-reads))
5033      ((eq type 'dormant)
5034       (memq article gnus-newsgroup-dormant) )
5035      ((eq type 'expire)
5036       (memq article gnus-newsgroup-expirable))
5037      ((eq type 'reply)
5038       (memq article gnus-newsgroup-replied))
5039      ((eq type 'killed)
5040       (memq article gnus-newsgroup-killed))
5041      ((eq type 'bookmark)
5042       (assq article gnus-newsgroup-bookmarks))
5043      ((eq type 'score)
5044       (assq article gnus-newsgroup-scored))
5045      ((eq type 'save)
5046       (memq article gnus-newsgroup-saved))
5047      ((eq type 'cache)
5048       (memq article gnus-newsgroup-cached))
5049      ((eq type 'forward)
5050       (memq article gnus-newsgroup-forwarded))
5051      ((eq type 'seen)
5052       (not (memq article gnus-newsgroup-unseen)))
5053      ((eq type 'recent)
5054       (memq article gnus-newsgroup-recent))
5055      (t t))))
5056
5057 (defun gnus-articles-to-read (group &optional read-all)
5058   "Find out what articles the user wants to read."
5059   (let* ((articles
5060           ;; Select all articles if `read-all' is non-nil, or if there
5061           ;; are no unread articles.
5062           (if (or read-all
5063                   (and (zerop (length gnus-newsgroup-marked))
5064                        (zerop (length gnus-newsgroup-unreads)))
5065                   ;; Fetch all if the predicate is non-nil.
5066                   gnus-newsgroup-display)
5067               ;; We want to select the headers for all the articles in
5068               ;; the group, so we select either all the active
5069               ;; articles in the group, or (if that's nil), the
5070               ;; articles in the cache.
5071               (or
5072                (gnus-uncompress-range (gnus-active group))
5073                (gnus-cache-articles-in-group group))
5074             ;; Select only the "normal" subset of articles.
5075             (gnus-sorted-nunion
5076              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5077              gnus-newsgroup-unreads)))
5078          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5079          (scored (length scored-list))
5080          (number (length articles))
5081          (marked (+ (length gnus-newsgroup-marked)
5082                     (length gnus-newsgroup-dormant)))
5083          (select
5084           (cond
5085            ((numberp read-all)
5086             read-all)
5087            ((numberp gnus-newsgroup-display)
5088             gnus-newsgroup-display)
5089            (t
5090             (condition-case ()
5091                 (cond
5092                  ((and (or (<= scored marked) (= scored number))
5093                        (numberp gnus-large-newsgroup)
5094                        (> number gnus-large-newsgroup))
5095                   (let* ((cursor-in-echo-area nil)
5096                          (initial (gnus-parameter-large-newsgroup-initial
5097                                    gnus-newsgroup-name))
5098                          (input
5099                           (read-string
5100                            (format
5101                             "How many articles from %s (%s %d): "
5102                             (gnus-limit-string
5103                              (gnus-group-decoded-name gnus-newsgroup-name)
5104                              35)
5105                             (if initial "max" "default")
5106                             number)
5107                            (if initial
5108                                (cons (number-to-string initial)
5109                                      0)))))
5110                     (if (string-match "^[ \t]*$" input) number input)))
5111                  ((and (> scored marked) (< scored number)
5112                        (> (- scored number) 20))
5113                   (let ((input
5114                          (read-string
5115                           (format "%s %s (%d scored, %d total): "
5116                                   "How many articles from"
5117                                   (gnus-group-decoded-name group)
5118                                   scored number))))
5119                     (if (string-match "^[ \t]*$" input)
5120                         number input)))
5121                  (t number))
5122               (quit
5123                (message "Quit getting the articles to read")
5124                nil))))))
5125     (setq select (if (stringp select) (string-to-number select) select))
5126     (if (or (null select) (zerop select))
5127         select
5128       (if (and (not (zerop scored)) (<= (abs select) scored))
5129           (progn
5130             (setq articles (sort scored-list '<))
5131             (setq number (length articles)))
5132         (setq articles (copy-sequence articles)))
5133
5134       (when (< (abs select) number)
5135         (if (< select 0)
5136             ;; Select the N oldest articles.
5137             (setcdr (nthcdr (1- (abs select)) articles) nil)
5138           ;; Select the N most recent articles.
5139           (setq articles (nthcdr (- number select) articles))))
5140       (setq gnus-newsgroup-unselected
5141             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5142       (when gnus-alter-articles-to-read-function
5143         (setq gnus-newsgroup-unreads
5144               (sort
5145                (funcall gnus-alter-articles-to-read-function
5146                         gnus-newsgroup-name gnus-newsgroup-unreads)
5147                '<)))
5148       articles)))
5149
5150 (defun gnus-killed-articles (killed articles)
5151   (let (out)
5152     (while articles
5153       (when (inline (gnus-member-of-range (car articles) killed))
5154         (push (car articles) out))
5155       (setq articles (cdr articles)))
5156     out))
5157
5158 (defun gnus-uncompress-marks (marks)
5159   "Uncompress the mark ranges in MARKS."
5160   (let ((uncompressed '(score bookmark))
5161         out)
5162     (while marks
5163       (if (memq (caar marks) uncompressed)
5164           (push (car marks) out)
5165         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5166       (setq marks (cdr marks)))
5167     out))
5168
5169 (defun gnus-article-mark-to-type (mark)
5170   "Return the type of MARK."
5171   (or (cadr (assq mark gnus-article-special-mark-lists))
5172       'list))
5173
5174 (defun gnus-article-unpropagatable-p (mark)
5175   "Return whether MARK should be propagated to backend."
5176   (memq mark gnus-article-unpropagated-mark-lists))
5177
5178 (defun gnus-adjust-marked-articles (info)
5179   "Set all article lists and remove all marks that are no longer valid."
5180   (let* ((marked-lists (gnus-info-marks info))
5181          (active (gnus-active (gnus-info-group info)))
5182          (min (car active))
5183          (max (cdr active))
5184          (types gnus-article-mark-lists)
5185          marks var articles article mark mark-type)
5186
5187     (dolist (marks marked-lists)
5188       (setq mark (car marks)
5189             mark-type (gnus-article-mark-to-type mark)
5190             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5191
5192       ;; We set the variable according to the type of the marks list,
5193       ;; and then adjust the marks to a subset of the active articles.
5194       (cond
5195        ;; Adjust "simple" lists.
5196        ((eq mark-type 'list)
5197         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5198         (when (memq mark '(tick dormant expire reply save))
5199           (while articles
5200             (when (or (< (setq article (pop articles)) min) (> article max))
5201               (set var (delq article (symbol-value var)))))))
5202        ;; Adjust assocs.
5203        ((eq mark-type 'tuple)
5204         (set var (setq articles (cdr marks)))
5205         (when (not (listp (cdr (symbol-value var))))
5206           (set var (list (symbol-value var))))
5207         (when (not (listp (cdr articles)))
5208           (setq articles (list articles)))
5209         (while articles
5210           (when (or (not (consp (setq article (pop articles))))
5211                     (< (car article) min)
5212                     (> (car article) max))
5213             (set var (delq article (symbol-value var))))))
5214        ;; Adjust ranges (sloppily).
5215        ((eq mark-type 'range)
5216         (cond
5217          ((eq mark 'seen)
5218           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5219           ;; It should be (seen (NUM1 . NUM2)).
5220           (when (numberp (cddr marks))
5221             (setcdr marks (list (cdr marks))))
5222           (setq articles (cdr marks))
5223           (while (and articles
5224                       (or (and (consp (car articles))
5225                                (> min (cdar articles)))
5226                           (and (numberp (car articles))
5227                                (> min (car articles)))))
5228             (pop articles))
5229           (set var articles))))))))
5230
5231 (defun gnus-update-missing-marks (missing)
5232   "Go through the list of MISSING articles and remove them from the mark lists."
5233   (when missing
5234     (let (var m)
5235       ;; Go through all types.
5236       (dolist (elem gnus-article-mark-lists)
5237         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5238           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5239           (when (symbol-value var)
5240             ;; This list has articles.  So we delete all missing
5241             ;; articles from it.
5242             (setq m missing)
5243             (while m
5244               (set var (delq (pop m) (symbol-value var))))))))))
5245
5246 (defun gnus-update-marks ()
5247   "Enter the various lists of marked articles into the newsgroup info list."
5248   (let ((types gnus-article-mark-lists)
5249         (info (gnus-get-info gnus-newsgroup-name))
5250         type list newmarked symbol delta-marks)
5251     (when info
5252       ;; Add all marks lists to the list of marks lists.
5253       (while (setq type (pop types))
5254         (setq list (symbol-value
5255                     (setq symbol
5256                           (intern (format "gnus-newsgroup-%s" (car type))))))
5257
5258         (when list
5259           ;; Get rid of the entries of the articles that have the
5260           ;; default score.
5261           (when (and (eq (cdr type) 'score)
5262                      gnus-save-score
5263                      list)
5264             (let* ((arts list)
5265                    (prev (cons nil list))
5266                    (all prev))
5267               (while arts
5268                 (if (or (not (consp (car arts)))
5269                         (= (cdar arts) gnus-summary-default-score))
5270                     (setcdr prev (cdr arts))
5271                   (setq prev arts))
5272                 (setq arts (cdr arts)))
5273               (setq list (cdr all)))))
5274
5275         (when (eq (cdr type) 'seen)
5276           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5277
5278         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5279           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5280
5281         (when (and (gnus-check-backend-function
5282                     'request-set-mark gnus-newsgroup-name)
5283                    (not (gnus-article-unpropagatable-p (cdr type))))
5284           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5285                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5286                  (add (gnus-remove-from-range
5287                        (gnus-copy-sequence list) old)))
5288             (when add
5289               (push (list add 'add (list (cdr type))) delta-marks))
5290             (when del
5291               (push (list del 'del (list (cdr type))) delta-marks))))
5292
5293         (when list
5294           (push (cons (cdr type) list) newmarked)))
5295
5296       (when delta-marks
5297         (unless (gnus-check-group gnus-newsgroup-name)
5298           (error "Can't open server for %s" gnus-newsgroup-name))
5299         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5300
5301       ;; Enter these new marks into the info of the group.
5302       (if (nthcdr 3 info)
5303           (setcar (nthcdr 3 info) newmarked)
5304         ;; Add the marks lists to the end of the info.
5305         (when newmarked
5306           (setcdr (nthcdr 2 info) (list newmarked))))
5307
5308       ;; Cut off the end of the info if there's nothing else there.
5309       (let ((i 5))
5310         (while (and (> i 2)
5311                     (not (nth i info)))
5312           (when (nthcdr (decf i) info)
5313             (setcdr (nthcdr i info) nil)))))))
5314
5315 (defun gnus-set-mode-line (where)
5316   "Set the mode line of the article or summary buffers.
5317 If WHERE is `summary', the summary mode line format will be used."
5318   ;; Is this mode line one we keep updated?
5319   (when (and (memq where gnus-updated-mode-lines)
5320              (symbol-value
5321               (intern (format "gnus-%s-mode-line-format-spec" where))))
5322     (let (mode-string)
5323       (save-excursion
5324         ;; We evaluate this in the summary buffer since these
5325         ;; variables are buffer-local to that buffer.
5326         (set-buffer gnus-summary-buffer)
5327         ;; We bind all these variables that are used in the `eval' form
5328         ;; below.
5329         (let* ((mformat (symbol-value
5330                          (intern
5331                           (format "gnus-%s-mode-line-format-spec" where))))
5332                (gnus-tmp-group-name (gnus-group-decoded-name
5333                                      gnus-newsgroup-name))
5334                (gnus-tmp-article-number (or gnus-current-article 0))
5335                (gnus-tmp-unread gnus-newsgroup-unreads)
5336                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5337                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5338                (gnus-tmp-unread-and-unselected
5339                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5340                             (zerop gnus-tmp-unselected))
5341                        "")
5342                       ((zerop gnus-tmp-unselected)
5343                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5344                       (t (format "{%d(+%d) more}"
5345                                  gnus-tmp-unread-and-unticked
5346                                  gnus-tmp-unselected))))
5347                (gnus-tmp-subject
5348                 (if (and gnus-current-headers
5349                          (vectorp gnus-current-headers))
5350                     (gnus-mode-string-quote
5351                      (mail-header-subject gnus-current-headers))
5352                   ""))
5353                bufname-length max-len
5354                gnus-tmp-header);; passed as argument to any user-format-funcs
5355           (setq mode-string (eval mformat))
5356           (setq bufname-length (if (string-match "%b" mode-string)
5357                                    (- (length
5358                                        (buffer-name
5359                                         (if (eq where 'summary)
5360                                             nil
5361                                           (get-buffer gnus-article-buffer))))
5362                                       2)
5363                                  0))
5364           (setq max-len (max 4 (if gnus-mode-non-string-length
5365                                    (- (window-width)
5366                                       gnus-mode-non-string-length
5367                                       bufname-length)
5368                                  (length mode-string))))
5369           ;; We might have to chop a bit of the string off...
5370           (when (> (length mode-string) max-len)
5371             (setq mode-string
5372                   (concat (gnus-truncate-string mode-string (- max-len 3))
5373                           "...")))
5374           ;; Pad the mode string a bit.
5375           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5376       ;; Update the mode line.
5377       (setq mode-line-buffer-identification
5378             (gnus-mode-line-buffer-identification (list mode-string)))
5379       (set-buffer-modified-p t))))
5380
5381 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5382   "Go through the HEADERS list and add all Xrefs to a hash table.
5383 The resulting hash table is returned, or nil if no Xrefs were found."
5384   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5385          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5386          (xref-hashtb (gnus-make-hashtable))
5387          start group entry number xrefs header)
5388     (while headers
5389       (setq header (pop headers))
5390       (when (and (setq xrefs (mail-header-xref header))
5391                  (not (memq (setq number (mail-header-number header))
5392                             unreads)))
5393         (setq start 0)
5394         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5395           (setq start (match-end 0))
5396           (setq group (if prefix
5397                           (concat prefix (substring xrefs (match-beginning 1)
5398                                                     (match-end 1)))
5399                         (substring xrefs (match-beginning 1) (match-end 1))))
5400           (setq number
5401                 (string-to-int (substring xrefs (match-beginning 2)
5402                                           (match-end 2))))
5403           (if (setq entry (gnus-gethash group xref-hashtb))
5404               (setcdr entry (cons number (cdr entry)))
5405             (gnus-sethash group (cons number nil) xref-hashtb)))))
5406     (and start xref-hashtb)))
5407
5408 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5409   "Look through all the headers and mark the Xrefs as read."
5410   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5411         name entry info xref-hashtb idlist method nth4)
5412     (save-excursion
5413       (set-buffer gnus-group-buffer)
5414       (when (setq xref-hashtb
5415                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5416         (mapatoms
5417          (lambda (group)
5418            (unless (string= from-newsgroup (setq name (symbol-name group)))
5419              (setq idlist (symbol-value group))
5420              ;; Dead groups are not updated.
5421              (and (prog1
5422                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5423                             info (nth 2 entry))
5424                     (when (stringp (setq nth4 (gnus-info-method info)))
5425                       (setq nth4 (gnus-server-to-method nth4))))
5426                   ;; Only do the xrefs if the group has the same
5427                   ;; select method as the group we have just read.
5428                   (or (gnus-methods-equal-p
5429                        nth4 (gnus-find-method-for-group from-newsgroup))
5430                       virtual
5431                       (equal nth4 (setq method (gnus-find-method-for-group
5432                                                 from-newsgroup)))
5433                       (and (equal (car nth4) (car method))
5434                            (equal (nth 1 nth4) (nth 1 method))))
5435                   gnus-use-cross-reference
5436                   (or (not (eq gnus-use-cross-reference t))
5437                       virtual
5438                       ;; Only do cross-references on subscribed
5439                       ;; groups, if that is what is wanted.
5440                       (<= (gnus-info-level info) gnus-level-subscribed))
5441                   (gnus-group-make-articles-read name idlist))))
5442          xref-hashtb)))))
5443
5444 (defun gnus-compute-read-articles (group articles)
5445   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5446          (info (nth 2 entry))
5447          (active (gnus-active group))
5448          ninfo)
5449     (when entry
5450       ;; First peel off all invalid article numbers.
5451       (when active
5452         (let ((ids articles)
5453               id first)
5454           (while (setq id (pop ids))
5455             (when (and first (> id (cdr active)))
5456               ;; We'll end up in this situation in one particular
5457               ;; obscure situation.  If you re-scan a group and get
5458               ;; a new article that is cross-posted to a different
5459               ;; group that has not been re-scanned, you might get
5460               ;; crossposted article that has a higher number than
5461               ;; Gnus believes possible.  So we re-activate this
5462               ;; group as well.  This might mean doing the
5463               ;; crossposting thingy will *increase* the number
5464               ;; of articles in some groups.  Tsk, tsk.
5465               (setq active (or (gnus-activate-group group) active)))
5466             (when (or (> id (cdr active))
5467                       (< id (car active)))
5468               (setq articles (delq id articles))))))
5469       ;; If the read list is nil, we init it.
5470       (if (and active
5471                (null (gnus-info-read info))
5472                (> (car active) 1))
5473           (setq ninfo (cons 1 (1- (car active))))
5474         (setq ninfo (gnus-info-read info)))
5475       ;; Then we add the read articles to the range.
5476       (gnus-add-to-range
5477        ninfo (setq articles (sort articles '<))))))
5478
5479 (defun gnus-group-make-articles-read (group articles)
5480   "Update the info of GROUP to say that ARTICLES are read."
5481   (let* ((num 0)
5482          (entry (gnus-gethash group gnus-newsrc-hashtb))
5483          (info (nth 2 entry))
5484          (active (gnus-active group))
5485          range)
5486     (when entry
5487       (setq range (gnus-compute-read-articles group articles))
5488       (save-excursion
5489         (set-buffer gnus-group-buffer)
5490         (gnus-undo-register
5491           `(progn
5492              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5493              (gnus-info-set-read ',info ',(gnus-info-read info))
5494              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5495              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5496              (gnus-group-update-group ,group t))))
5497       ;; Add the read articles to the range.
5498       (gnus-info-set-read info range)
5499       (gnus-request-set-mark group (list (list range 'add '(read))))
5500       ;; Then we have to re-compute how many unread
5501       ;; articles there are in this group.
5502       (when active
5503         (cond
5504          ((not range)
5505           (setq num (- (1+ (cdr active)) (car active))))
5506          ((not (listp (cdr range)))
5507           (setq num (- (cdr active) (- (1+ (cdr range))
5508                                        (car range)))))
5509          (t
5510           (while range
5511             (if (numberp (car range))
5512                 (setq num (1+ num))
5513               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5514             (setq range (cdr range)))
5515           (setq num (- (cdr active) num))))
5516         ;; Update the number of unread articles.
5517         (setcar entry num)
5518         ;; Update the group buffer.
5519         (gnus-group-update-group group t)))))
5520
5521 (defvar gnus-newsgroup-none-id 0)
5522
5523 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5524   (let ((cur nntp-server-buffer)
5525         (dependencies
5526          (or dependencies
5527              (save-excursion (set-buffer gnus-summary-buffer)
5528                              gnus-newsgroup-dependencies)))
5529         headers id end ref
5530         (mail-parse-charset gnus-newsgroup-charset)
5531         (mail-parse-ignored-charsets
5532          (save-excursion (condition-case nil
5533                              (set-buffer gnus-summary-buffer)
5534                            (error))
5535                          gnus-newsgroup-ignored-charsets)))
5536     (save-excursion
5537       (set-buffer nntp-server-buffer)
5538       ;; Translate all TAB characters into SPACE characters.
5539       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5540       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5541       (gnus-run-hooks 'gnus-parse-headers-hook)
5542       (let ((case-fold-search t)
5543             in-reply-to header p lines chars ctype)
5544         (goto-char (point-min))
5545         ;; Search to the beginning of the next header.  Error messages
5546         ;; do not begin with 2 or 3.
5547         (while (re-search-forward "^[23][0-9]+ " nil t)
5548           (setq id nil
5549                 ref nil)
5550           ;; This implementation of this function, with nine
5551           ;; search-forwards instead of the one re-search-forward and
5552           ;; a case (which basically was the old function) is actually
5553           ;; about twice as fast, even though it looks messier.  You
5554           ;; can't have everything, I guess.  Speed and elegance
5555           ;; doesn't always go hand in hand.
5556           (setq
5557            header
5558            (make-full-mail-header
5559             ;; Number.
5560             (prog1
5561                 (read cur)
5562               (end-of-line)
5563               (setq p (point))
5564               (narrow-to-region (point)
5565                                 (or (and (search-forward "\n.\n" nil t)
5566                                          (- (point) 2))
5567                                     (point))))
5568             ;; Subject.
5569             (progn
5570               (goto-char p)
5571               (if (search-forward "\nsubject:" nil t)
5572                   (nnheader-header-value)
5573                 "(none)"))
5574             ;; From.
5575             (progn
5576               (goto-char p)
5577               (if (search-forward "\nfrom:" nil t)
5578                   (nnheader-header-value)
5579                 "(nobody)"))
5580             ;; Date.
5581             (progn
5582               (goto-char p)
5583               (if (search-forward "\ndate:" nil t)
5584                   (nnheader-header-value) ""))
5585             ;; Message-ID.
5586             (progn
5587               (goto-char p)
5588               (setq id (if (re-search-forward
5589                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5590                            ;; We do it this way to make sure the Message-ID
5591                            ;; is (somewhat) syntactically valid.
5592                            (buffer-substring (match-beginning 1)
5593                                              (match-end 1))
5594                          ;; If there was no message-id, we just fake one
5595                          ;; to make subsequent routines simpler.
5596                          (nnheader-generate-fake-message-id))))
5597             ;; References.
5598             (progn
5599               (goto-char p)
5600               (if (search-forward "\nreferences:" nil t)
5601                   (progn
5602                     (setq end (point))
5603                     (prog1
5604                         (nnheader-header-value)
5605                       (setq ref
5606                             (buffer-substring
5607                              (progn
5608                                ;; (end-of-line)
5609                                (search-backward ">" end t)
5610                                (1+ (point)))
5611                              (progn
5612                                (search-backward "<" end t)
5613                                (point))))))
5614                 ;; Get the references from the in-reply-to header if there
5615                 ;; were no references and the in-reply-to header looks
5616                 ;; promising.
5617                 (if (and (search-forward "\nin-reply-to:" nil t)
5618                          (setq in-reply-to (nnheader-header-value))
5619                          (string-match "<[^>]+>" in-reply-to))
5620                     (let (ref2)
5621                       (setq ref (substring in-reply-to (match-beginning 0)
5622                                            (match-end 0)))
5623                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5624                         (setq ref2 (substring in-reply-to (match-beginning 0)
5625                                               (match-end 0)))
5626                         (when (> (length ref2) (length ref))
5627                           (setq ref ref2)))
5628                       ref)
5629                   (setq ref nil))))
5630             ;; Chars.
5631             (progn
5632               (goto-char p)
5633               (if (search-forward "\nchars: " nil t)
5634                   (if (numberp (setq chars (ignore-errors (read cur))))
5635                       chars -1)
5636                 -1))
5637             ;; Lines.
5638             (progn
5639               (goto-char p)
5640               (if (search-forward "\nlines: " nil t)
5641                   (if (numberp (setq lines (ignore-errors (read cur))))
5642                       lines -1)
5643                 -1))
5644             ;; Xref.
5645             (progn
5646               (goto-char p)
5647               (and (search-forward "\nxref:" nil t)
5648                    (nnheader-header-value)))
5649             ;; Extra.
5650             (when gnus-extra-headers
5651               (let ((extra gnus-extra-headers)
5652                     out)
5653                 (while extra
5654                   (goto-char p)
5655                   (when (search-forward
5656                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5657                     (push (cons (car extra) (nnheader-header-value)) out))
5658                   (pop extra))
5659                 out))))
5660           (goto-char p)
5661           (if (and (search-forward "\ncontent-type: " nil t)
5662                    (setq ctype (nnheader-header-value)))
5663               (mime-entity-set-content-type-internal
5664                header (mime-parse-Content-Type ctype)))
5665           (when (equal id ref)
5666             (setq ref nil))
5667
5668           (when gnus-alter-header-function
5669             (funcall gnus-alter-header-function header)
5670             (setq id (mail-header-id header)
5671                   ref (gnus-parent-id (mail-header-references header))))
5672
5673           (when (setq header
5674                       (gnus-dependencies-add-header
5675                        header dependencies force-new))
5676             (push header headers))
5677           (goto-char (point-max))
5678           (widen))
5679         (nreverse headers)))))
5680
5681 ;; Goes through the xover lines and returns a list of vectors
5682 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5683                                                   force-new dependencies
5684                                                   group also-fetch-heads)
5685   "Parse the news overview data in the server buffer.
5686 Return a list of headers that match SEQUENCE (see
5687 `nntp-retrieve-headers')."
5688   ;; Get the Xref when the users reads the articles since most/some
5689   ;; NNTP servers do not include Xrefs when using XOVER.
5690   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5691   (let ((mail-parse-charset gnus-newsgroup-charset)
5692         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5693         (cur nntp-server-buffer)
5694         (dependencies (or dependencies gnus-newsgroup-dependencies))
5695         (allp (cond
5696                ((eq gnus-read-all-available-headers t)
5697                 t)
5698                ((stringp gnus-read-all-available-headers)
5699                 (string-match gnus-read-all-available-headers group))
5700                (t
5701                 nil)))
5702         number headers header)
5703     (save-excursion
5704       (set-buffer nntp-server-buffer)
5705       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5706       ;; Allow the user to mangle the headers before parsing them.
5707       (gnus-run-hooks 'gnus-parse-headers-hook)
5708       (goto-char (point-min))
5709       (gnus-parse-without-error
5710         (while (and (or sequence allp)
5711                     (not (eobp)))
5712           (setq number (read cur))
5713           (when (not allp)
5714             (while (and sequence
5715                         (< (car sequence) number))
5716               (setq sequence (cdr sequence))))
5717           (when (and (or allp
5718                          (and sequence
5719                               (eq number (car sequence))))
5720                      (progn
5721                        (setq sequence (cdr sequence))
5722                        (setq header (inline
5723                                       (gnus-nov-parse-line
5724                                        number dependencies force-new)))))
5725             (push header headers))
5726           (forward-line 1)))
5727       ;; A common bug in inn is that if you have posted an article and
5728       ;; then retrieves the active file, it will answer correctly --
5729       ;; the new article is included.  However, a NOV entry for the
5730       ;; article may not have been generated yet, so this may fail.
5731       ;; We work around this problem by retrieving the last few
5732       ;; headers using HEAD.
5733       (if (or (not also-fetch-heads)
5734               (not sequence))
5735           ;; We (probably) got all the headers.
5736           (nreverse headers)
5737         (let ((gnus-nov-is-evil t))
5738           (nconc
5739            (nreverse headers)
5740            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5741              (gnus-get-newsgroup-headers))))))))
5742
5743 (defun gnus-article-get-xrefs ()
5744   "Fill in the Xref value in `gnus-current-headers', if necessary.
5745 This is meant to be called in `gnus-article-internal-prepare-hook'."
5746   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5747                                  gnus-current-headers)))
5748     (or (not gnus-use-cross-reference)
5749         (not headers)
5750         (and (mail-header-xref headers)
5751              (not (string= (mail-header-xref headers) "")))
5752         (let ((case-fold-search t)
5753               xref)
5754           (save-restriction
5755             (nnheader-narrow-to-headers)
5756             (goto-char (point-min))
5757             (when (or (and (not (eobp))
5758                            (eq (downcase (char-after)) ?x)
5759                            (looking-at "Xref:"))
5760                       (search-forward "\nXref:" nil t))
5761               (goto-char (1+ (match-end 0)))
5762               (setq xref (buffer-substring (point)
5763                                            (progn (end-of-line) (point))))
5764               (mail-header-set-xref headers xref)))))))
5765
5766 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5767   "Find article ID and insert the summary line for that article.
5768 OLD-HEADER can either be a header or a line number to insert
5769 the subject line on."
5770   (let* ((line (and (numberp old-header) old-header))
5771          (old-header (and (vectorp old-header) old-header))
5772          (header (cond ((and old-header use-old-header)
5773                         old-header)
5774                        ((and (numberp id)
5775                              (gnus-number-to-header id))
5776                         (gnus-number-to-header id))
5777                        (t
5778                         (gnus-read-header id))))
5779          (number (and (numberp id) id))
5780          d)
5781     (when header
5782       ;; Rebuild the thread that this article is part of and go to the
5783       ;; article we have fetched.
5784       (when (and (not gnus-show-threads)
5785                  old-header)
5786         (when (and number
5787                    (setq d (gnus-data-find (mail-header-number old-header))))
5788           (goto-char (gnus-data-pos d))
5789           (gnus-data-remove
5790            number
5791            (- (gnus-point-at-bol)
5792               (prog1
5793                   (1+ (gnus-point-at-eol))
5794                 (gnus-delete-line))))))
5795       (when old-header
5796         (mail-header-set-number header (mail-header-number old-header)))
5797       (setq gnus-newsgroup-sparse
5798             (delq (setq number (mail-header-number header))
5799                   gnus-newsgroup-sparse))
5800       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5801       (push number gnus-newsgroup-limit)
5802       (gnus-rebuild-thread (mail-header-id header) line)
5803       (gnus-summary-goto-subject number nil t))
5804     (when (and (numberp number)
5805                (> number 0))
5806       ;; We have to update the boundaries even if we can't fetch the
5807       ;; article if ID is a number -- so that the next `P' or `N'
5808       ;; command will fetch the previous (or next) article even
5809       ;; if the one we tried to fetch this time has been canceled.
5810       (when (> number gnus-newsgroup-end)
5811         (setq gnus-newsgroup-end number))
5812       (when (< number gnus-newsgroup-begin)
5813         (setq gnus-newsgroup-begin number))
5814       (setq gnus-newsgroup-unselected
5815             (delq number gnus-newsgroup-unselected)))
5816     ;; Report back a success?
5817     (and header (mail-header-number header))))
5818
5819 ;;; Process/prefix in the summary buffer
5820
5821 (defun gnus-summary-work-articles (n)
5822   "Return a list of articles to be worked upon.
5823 The prefix argument, the list of process marked articles, and the
5824 current article will be taken into consideration."
5825   (save-excursion
5826     (set-buffer gnus-summary-buffer)
5827     (cond
5828      (n
5829       ;; A numerical prefix has been given.
5830       (setq n (prefix-numeric-value n))
5831       (let ((backward (< n 0))
5832             (n (abs (prefix-numeric-value n)))
5833             articles article)
5834         (save-excursion
5835           (while
5836               (and (> n 0)
5837                    (push (setq article (gnus-summary-article-number))
5838                          articles)
5839                    (if backward
5840                        (gnus-summary-find-prev nil article)
5841                      (gnus-summary-find-next nil article)))
5842             (decf n)))
5843         (nreverse articles)))
5844      ((and (gnus-region-active-p) (mark))
5845       (message "region active")
5846       ;; Work on the region between point and mark.
5847       (let ((max (max (point) (mark)))
5848             articles article)
5849         (save-excursion
5850           (goto-char (min (point) (mark)))
5851           (while
5852               (and
5853                (push (setq article (gnus-summary-article-number)) articles)
5854                (gnus-summary-find-next nil article)
5855                (< (point) max)))
5856           (nreverse articles))))
5857      (gnus-newsgroup-processable
5858       ;; There are process-marked articles present.
5859       ;; Save current state.
5860       (gnus-summary-save-process-mark)
5861       ;; Return the list.
5862       (reverse gnus-newsgroup-processable))
5863      (t
5864       ;; Just return the current article.
5865       (list (gnus-summary-article-number))))))
5866
5867 (defmacro gnus-summary-iterate (arg &rest forms)
5868   "Iterate over the process/prefixed articles and do FORMS.
5869 ARG is the interactive prefix given to the command.  FORMS will be
5870 executed with point over the summary line of the articles."
5871   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5872     `(let ((,articles (gnus-summary-work-articles ,arg)))
5873        (while ,articles
5874          (gnus-summary-goto-subject (car ,articles))
5875          ,@forms
5876          (pop ,articles)))))
5877
5878 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5879 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5880
5881 (defun gnus-summary-save-process-mark ()
5882   "Push the current set of process marked articles on the stack."
5883   (interactive)
5884   (push (copy-sequence gnus-newsgroup-processable)
5885         gnus-newsgroup-process-stack))
5886
5887 (defun gnus-summary-kill-process-mark ()
5888   "Push the current set of process marked articles on the stack and unmark."
5889   (interactive)
5890   (gnus-summary-save-process-mark)
5891   (gnus-summary-unmark-all-processable))
5892
5893 (defun gnus-summary-yank-process-mark ()
5894   "Pop the last process mark state off the stack and restore it."
5895   (interactive)
5896   (unless gnus-newsgroup-process-stack
5897     (error "Empty mark stack"))
5898   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5899
5900 (defun gnus-summary-process-mark-set (set)
5901   "Make SET into the current process marked articles."
5902   (gnus-summary-unmark-all-processable)
5903   (while set
5904     (gnus-summary-set-process-mark (pop set))))
5905
5906 ;;; Searching and stuff
5907
5908 (defun gnus-summary-search-group (&optional backward use-level)
5909   "Search for next unread newsgroup.
5910 If optional argument BACKWARD is non-nil, search backward instead."
5911   (save-excursion
5912     (set-buffer gnus-group-buffer)
5913     (when (gnus-group-search-forward
5914            backward nil (if use-level (gnus-group-group-level) nil))
5915       (gnus-group-group-name))))
5916
5917 (defun gnus-summary-best-group (&optional exclude-group)
5918   "Find the name of the best unread group.
5919 If EXCLUDE-GROUP, do not go to this group."
5920   (save-excursion
5921     (set-buffer gnus-group-buffer)
5922     (save-excursion
5923       (gnus-group-best-unread-group exclude-group))))
5924
5925 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5926   (if backward (gnus-summary-find-prev)
5927     (let* ((dummy (gnus-summary-article-intangible-p))
5928            (article (or article (gnus-summary-article-number)))
5929            (arts (gnus-data-find-list article))
5930            result)
5931       (when (and (not dummy)
5932                  (or (not gnus-summary-check-current)
5933                      (not unread)
5934                      (not (gnus-data-unread-p (car arts)))))
5935         (setq arts (cdr arts)))
5936       (when (setq result
5937                   (if unread
5938                       (progn
5939                         (while arts
5940                           (when (or (and undownloaded
5941                                          (eq gnus-undownloaded-mark
5942                                              (gnus-data-mark (car arts))))
5943                                     (gnus-data-unread-p (car arts)))
5944                             (setq result (car arts)
5945                                   arts nil))
5946                           (setq arts (cdr arts)))
5947                         result)
5948                     (car arts)))
5949         (goto-char (gnus-data-pos result))
5950         (gnus-data-number result)))))
5951
5952 (defun gnus-summary-find-prev (&optional unread article)
5953   (let* ((eobp (eobp))
5954          (article (or article (gnus-summary-article-number)))
5955          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5956          result)
5957     (when (and (not eobp)
5958                (or (not gnus-summary-check-current)
5959                    (not unread)
5960                    (not (gnus-data-unread-p (car arts)))))
5961       (setq arts (cdr arts)))
5962     (when (setq result
5963                 (if unread
5964                     (progn
5965                       (while arts
5966                         (when (gnus-data-unread-p (car arts))
5967                           (setq result (car arts)
5968                                 arts nil))
5969                         (setq arts (cdr arts)))
5970                       result)
5971                   (car arts)))
5972       (goto-char (gnus-data-pos result))
5973       (gnus-data-number result))))
5974
5975 (defun gnus-summary-find-subject (subject &optional unread backward article)
5976   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5977          (article (or article (gnus-summary-article-number)))
5978          (articles (gnus-data-list backward))
5979          (arts (gnus-data-find-list article articles))
5980          result)
5981     (when (or (not gnus-summary-check-current)
5982               (not unread)
5983               (not (gnus-data-unread-p (car arts))))
5984       (setq arts (cdr arts)))
5985     (while arts
5986       (and (or (not unread)
5987                (gnus-data-unread-p (car arts)))
5988            (vectorp (gnus-data-header (car arts)))
5989            (gnus-subject-equal
5990             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5991            (setq result (car arts)
5992                  arts nil))
5993       (setq arts (cdr arts)))
5994     (and result
5995          (goto-char (gnus-data-pos result))
5996          (gnus-data-number result))))
5997
5998 (defun gnus-summary-search-forward (&optional unread subject backward)
5999   "Search forward for an article.
6000 If UNREAD, look for unread articles.  If SUBJECT, look for
6001 articles with that subject.  If BACKWARD, search backward instead."
6002   (cond (subject (gnus-summary-find-subject subject unread backward))
6003         (backward (gnus-summary-find-prev unread))
6004         (t (gnus-summary-find-next unread))))
6005
6006 (defun gnus-recenter (&optional n)
6007   "Center point in window and redisplay frame.
6008 Also do horizontal recentering."
6009   (interactive "P")
6010   (when (and gnus-auto-center-summary
6011              (not (eq gnus-auto-center-summary 'vertical)))
6012     (gnus-horizontal-recenter))
6013   (recenter n))
6014
6015 (defun gnus-summary-recenter ()
6016   "Center point in the summary window.
6017 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6018 displayed, no centering will be performed."
6019   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6020   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6021   (interactive)
6022   (let* ((top (cond ((< (window-height) 4) 0)
6023                     ((< (window-height) 7) 1)
6024                     (t (if (numberp gnus-auto-center-summary)
6025                            gnus-auto-center-summary
6026                          2))))
6027          (height (1- (window-height)))
6028          (bottom (save-excursion (goto-char (point-max))
6029                                  (forward-line (- height))
6030                                  (point)))
6031          (window (get-buffer-window (current-buffer))))
6032     ;; The user has to want it.
6033     (when gnus-auto-center-summary
6034       (when (get-buffer-window gnus-article-buffer)
6035         ;; Only do recentering when the article buffer is displayed,
6036         ;; Set the window start to either `bottom', which is the biggest
6037         ;; possible valid number, or the second line from the top,
6038         ;; whichever is the least.
6039         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6040           (if (> bottom top-pos)
6041               ;; Keep the second line from the top visible
6042               (set-window-start window top-pos t)
6043             ;; Try to keep the bottom line visible; if it's partially
6044             ;; obscured, either scroll one more line to make it fully
6045             ;; visible, or revert to using TOP-POS.
6046             (save-excursion
6047               (goto-char (point-max))
6048               (forward-line -1)
6049               (let ((last-line-start (point)))
6050                 (goto-char bottom)
6051                 (set-window-start window (point) t)
6052                 (when (not (pos-visible-in-window-p last-line-start window))
6053                   (forward-line 1)
6054                   (set-window-start window (min (point) top-pos) t)))))))
6055       ;; Do horizontal recentering while we're at it.
6056       (when (and (get-buffer-window (current-buffer) t)
6057                  (not (eq gnus-auto-center-summary 'vertical)))
6058         (let ((selected (selected-window)))
6059           (select-window (get-buffer-window (current-buffer) t))
6060           (gnus-summary-position-point)
6061           (gnus-horizontal-recenter)
6062           (select-window selected))))))
6063
6064 (defun gnus-summary-jump-to-group (newsgroup)
6065   "Move point to NEWSGROUP in group mode buffer."
6066   ;; Keep update point of group mode buffer if visible.
6067   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6068       (save-window-excursion
6069         ;; Take care of tree window mode.
6070         (when (get-buffer-window gnus-group-buffer)
6071           (pop-to-buffer gnus-group-buffer))
6072         (gnus-group-jump-to-group newsgroup))
6073     (save-excursion
6074       ;; Take care of tree window mode.
6075       (if (get-buffer-window gnus-group-buffer)
6076           (pop-to-buffer gnus-group-buffer)
6077         (set-buffer gnus-group-buffer))
6078       (gnus-group-jump-to-group newsgroup))))
6079
6080 ;; This function returns a list of article numbers based on the
6081 ;; difference between the ranges of read articles in this group and
6082 ;; the range of active articles.
6083 (defun gnus-list-of-unread-articles (group)
6084   (let* ((read (gnus-info-read (gnus-get-info group)))
6085          (active (or (gnus-active group) (gnus-activate-group group)))
6086          (last (cdr active))
6087          first nlast unread)
6088     ;; If none are read, then all are unread.
6089     (if (not read)
6090         (setq first (car active))
6091       ;; If the range of read articles is a single range, then the
6092       ;; first unread article is the article after the last read
6093       ;; article.  Sounds logical, doesn't it?
6094       (if (and (not (listp (cdr read)))
6095                (or (< (car read) (car active))
6096                    (progn (setq read (list read))
6097                           nil)))
6098           (setq first (max (car active) (1+ (cdr read))))
6099         ;; `read' is a list of ranges.
6100         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6101                                   (caar read)))
6102                   1)
6103           (setq first (car active)))
6104         (while read
6105           (when first
6106             (while (< first nlast)
6107               (push first unread)
6108               (setq first (1+ first))))
6109           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6110           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6111           (setq read (cdr read)))))
6112     ;; And add the last unread articles.
6113     (while (<= first last)
6114       (push first unread)
6115       (setq first (1+ first)))
6116     ;; Return the list of unread articles.
6117     (delq 0 (nreverse unread))))
6118
6119 (defun gnus-list-of-read-articles (group)
6120   "Return a list of unread, unticked and non-dormant articles."
6121   (let* ((info (gnus-get-info group))
6122          (marked (gnus-info-marks info))
6123          (active (gnus-active group)))
6124     (and info active
6125          (gnus-list-range-difference
6126           (gnus-list-range-difference
6127            (gnus-sorted-complement
6128             (gnus-uncompress-range active)
6129             (gnus-list-of-unread-articles group))
6130            (cdr (assq 'dormant marked)))
6131           (cdr (assq 'tick marked))))))
6132
6133 ;; Various summary commands
6134
6135 (defun gnus-summary-select-article-buffer ()
6136   "Reconfigure windows to show article buffer."
6137   (interactive)
6138   (if (not (gnus-buffer-live-p gnus-article-buffer))
6139       (error "There is no article buffer for this summary buffer")
6140     (gnus-configure-windows 'article)
6141     (select-window (get-buffer-window gnus-article-buffer))))
6142
6143 (defun gnus-summary-universal-argument (arg)
6144   "Perform any operation on all articles that are process/prefixed."
6145   (interactive "P")
6146   (let ((articles (gnus-summary-work-articles arg))
6147         func article)
6148     (if (eq
6149          (setq
6150           func
6151           (key-binding
6152            (read-key-sequence
6153             (substitute-command-keys
6154              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6155          'undefined)
6156         (gnus-error 1 "Undefined key")
6157       (save-excursion
6158         (while articles
6159           (gnus-summary-goto-subject (setq article (pop articles)))
6160           (let (gnus-newsgroup-processable)
6161             (command-execute func))
6162           (gnus-summary-remove-process-mark article)))))
6163   (gnus-summary-position-point))
6164
6165 (defun gnus-summary-toggle-truncation (&optional arg)
6166   "Toggle truncation of summary lines.
6167 With arg, turn line truncation on iff arg is positive."
6168   (interactive "P")
6169   (setq truncate-lines
6170         (if (null arg) (not truncate-lines)
6171           (> (prefix-numeric-value arg) 0)))
6172   (redraw-display))
6173
6174 (defun gnus-summary-reselect-current-group (&optional all rescan)
6175   "Exit and then reselect the current newsgroup.
6176 The prefix argument ALL means to select all articles."
6177   (interactive "P")
6178   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6179     (error "Ephemeral groups can't be reselected"))
6180   (let ((current-subject (gnus-summary-article-number))
6181         (group gnus-newsgroup-name))
6182     (setq gnus-newsgroup-begin nil)
6183     (gnus-summary-exit)
6184     ;; We have to adjust the point of group mode buffer because
6185     ;; point was moved to the next unread newsgroup by exiting.
6186     (gnus-summary-jump-to-group group)
6187     (when rescan
6188       (save-excursion
6189         (save-window-excursion
6190           ;; Don't show group contents.
6191           (set-window-start (selected-window) (point-max))
6192           (gnus-group-get-new-news-this-group 1))))
6193     (gnus-group-read-group all t)
6194     (gnus-summary-goto-subject current-subject nil t)))
6195
6196 (defun gnus-summary-rescan-group (&optional all)
6197   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6198   (interactive "P")
6199   (gnus-summary-reselect-current-group all t))
6200
6201 (defun gnus-summary-update-info (&optional non-destructive)
6202   (save-excursion
6203     (let ((group gnus-newsgroup-name))
6204       (when group
6205         (when gnus-newsgroup-kill-headers
6206           (setq gnus-newsgroup-killed
6207                 (gnus-compress-sequence
6208                  (gnus-sorted-union
6209                   (gnus-list-range-intersection
6210                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6211                   gnus-newsgroup-unreads)
6212                  t)))
6213         (unless (listp (cdr gnus-newsgroup-killed))
6214           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6215         (let ((headers gnus-newsgroup-headers))
6216           ;; Set the new ranges of read articles.
6217           (save-excursion
6218             (set-buffer gnus-group-buffer)
6219             (gnus-undo-force-boundary))
6220           (gnus-update-read-articles
6221            group (gnus-sorted-union
6222                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6223           ;; Set the current article marks.
6224           (let ((gnus-newsgroup-scored
6225                  (if (and (not gnus-save-score)
6226                           (not non-destructive))
6227                      nil
6228                    gnus-newsgroup-scored)))
6229             (save-excursion
6230               (gnus-update-marks)))
6231           ;; Do the cross-ref thing.
6232           (when gnus-use-cross-reference
6233             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6234           ;; Do not switch windows but change the buffer to work.
6235           (set-buffer gnus-group-buffer)
6236           (unless (gnus-ephemeral-group-p group)
6237             (gnus-group-update-group group)))))))
6238
6239 (defun gnus-summary-save-newsrc (&optional force)
6240   "Save the current number of read/marked articles in the dribble buffer.
6241 The dribble buffer will then be saved.
6242 If FORCE (the prefix), also save the .newsrc file(s)."
6243   (interactive "P")
6244   (gnus-summary-update-info t)
6245   (if force
6246       (gnus-save-newsrc-file)
6247     (gnus-dribble-save)))
6248
6249 (defun gnus-summary-exit (&optional temporary)
6250   "Exit reading current newsgroup, and then return to group selection mode.
6251 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6252   (interactive)
6253   (gnus-set-global-variables)
6254   (gnus-kill-save-kill-buffer)
6255   (gnus-async-halt-prefetch)
6256   (let* ((group gnus-newsgroup-name)
6257          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6258          (mode major-mode)
6259          (group-point nil)
6260          (buf (current-buffer)))
6261     (unless quit-config
6262       ;; Do adaptive scoring, and possibly save score files.
6263       (when gnus-newsgroup-adaptive
6264         (gnus-score-adaptive))
6265       (when gnus-use-scoring
6266         (gnus-score-save)))
6267     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6268     ;; If we have several article buffers, we kill them at exit.
6269     (unless gnus-single-article-buffer
6270       (gnus-kill-buffer gnus-original-article-buffer)
6271       (setq gnus-article-current nil))
6272     (when gnus-use-cache
6273       (gnus-cache-possibly-remove-articles)
6274       (gnus-cache-save-buffers))
6275     (gnus-async-prefetch-remove-group group)
6276     (when gnus-suppress-duplicates
6277       (gnus-dup-enter-articles))
6278     (when gnus-use-trees
6279       (gnus-tree-close group))
6280     (when gnus-use-cache
6281       (gnus-cache-write-active))
6282     ;; Remove entries for this group.
6283     (nnmail-purge-split-history (gnus-group-real-name group))
6284     ;; Make all changes in this group permanent.
6285     (unless quit-config
6286       (gnus-run-hooks 'gnus-exit-group-hook)
6287       (gnus-summary-update-info))
6288     (gnus-close-group group)
6289     ;; Make sure where we were, and go to next newsgroup.
6290     (set-buffer gnus-group-buffer)
6291     (unless quit-config
6292       (gnus-group-jump-to-group group))
6293     (gnus-run-hooks 'gnus-summary-exit-hook)
6294     (unless (or quit-config
6295                 ;; If this group has disappeared from the summary
6296                 ;; buffer, don't skip forwards.
6297                 (not (string= group (gnus-group-group-name))))
6298       (gnus-group-next-unread-group 1))
6299     (setq group-point (point))
6300     (if temporary
6301         nil                             ;Nothing to do.
6302       ;; If we have several article buffers, we kill them at exit.
6303       (unless gnus-single-article-buffer
6304         (gnus-kill-buffer gnus-article-buffer)
6305         (gnus-kill-buffer gnus-original-article-buffer)
6306         (setq gnus-article-current nil))
6307       (set-buffer buf)
6308       (if (not gnus-kill-summary-on-exit)
6309           (progn
6310             (gnus-deaden-summary)
6311             (setq mode nil))
6312         ;; We set all buffer-local variables to nil.  It is unclear why
6313         ;; this is needed, but if we don't, buffer-local variables are
6314         ;; not garbage-collected, it seems.  This would the lead to en
6315         ;; ever-growing Emacs.
6316         (gnus-summary-clear-local-variables)
6317         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6318           (gnus-summary-clear-local-variables))
6319         (when (get-buffer gnus-article-buffer)
6320           (bury-buffer gnus-article-buffer))
6321         ;; We clear the global counterparts of the buffer-local
6322         ;; variables as well, just to be on the safe side.
6323         (set-buffer gnus-group-buffer)
6324         (gnus-summary-clear-local-variables)
6325         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6326           (gnus-summary-clear-local-variables)))
6327       (setq gnus-current-select-method gnus-select-method)
6328       (pop-to-buffer gnus-group-buffer)
6329       (if (not quit-config)
6330           (progn
6331             (goto-char group-point)
6332             (gnus-configure-windows 'group 'force)
6333             (unless (pos-visible-in-window-p)
6334               (forward-line (/ (static-if (featurep 'xemacs)
6335                                    (window-displayed-height)
6336                                  (1- (window-height)))
6337                                -2))
6338               (set-window-start (selected-window) (point))
6339               (goto-char group-point)))
6340         (gnus-handle-ephemeral-exit quit-config))
6341       ;; Return to group mode buffer.
6342       (when (eq mode 'gnus-summary-mode)
6343         (gnus-kill-buffer buf))
6344       ;; Clear the current group name.
6345       (unless quit-config
6346         (setq gnus-newsgroup-name nil)))))
6347
6348 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6349 (defun gnus-summary-exit-no-update (&optional no-questions)
6350   "Quit reading current newsgroup without updating read article info."
6351   (interactive)
6352   (let* ((group gnus-newsgroup-name)
6353          (quit-config (gnus-group-quit-config group)))
6354     (when (or no-questions
6355               gnus-expert-user
6356               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6357       (gnus-async-halt-prefetch)
6358       (mapcar 'funcall
6359               (delq 'gnus-summary-expire-articles
6360                     (copy-sequence gnus-summary-prepare-exit-hook)))
6361       ;; If we have several article buffers, we kill them at exit.
6362       (unless gnus-single-article-buffer
6363         (gnus-kill-buffer gnus-article-buffer)
6364         (gnus-kill-buffer gnus-original-article-buffer)
6365         (setq gnus-article-current nil))
6366       (if (not gnus-kill-summary-on-exit)
6367           (gnus-deaden-summary)
6368         (gnus-close-group group)
6369         (gnus-summary-clear-local-variables)
6370         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6371           (gnus-summary-clear-local-variables))
6372         (set-buffer gnus-group-buffer)
6373         (gnus-summary-clear-local-variables)
6374         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6375           (gnus-summary-clear-local-variables))
6376         (when (get-buffer gnus-summary-buffer)
6377           (kill-buffer gnus-summary-buffer)))
6378       (unless gnus-single-article-buffer
6379         (setq gnus-article-current nil))
6380       (when gnus-use-trees
6381         (gnus-tree-close group))
6382       (gnus-async-prefetch-remove-group group)
6383       (when (get-buffer gnus-article-buffer)
6384         (bury-buffer gnus-article-buffer))
6385       ;; Return to the group buffer.
6386       (gnus-configure-windows 'group 'force)
6387       ;; Clear the current group name.
6388       (setq gnus-newsgroup-name nil)
6389       (when (equal (gnus-group-group-name) group)
6390         (gnus-group-next-unread-group 1))
6391       (when quit-config
6392         (gnus-handle-ephemeral-exit quit-config)))))
6393
6394 (defun gnus-handle-ephemeral-exit (quit-config)
6395   "Handle movement when leaving an ephemeral group.
6396 The state which existed when entering the ephemeral is reset."
6397   (if (not (buffer-name (car quit-config)))
6398       (gnus-configure-windows 'group 'force)
6399     (set-buffer (car quit-config))
6400     (cond ((eq major-mode 'gnus-summary-mode)
6401            (gnus-set-global-variables))
6402           ((eq major-mode 'gnus-article-mode)
6403            (save-excursion
6404              ;; The `gnus-summary-buffer' variable may point
6405              ;; to the old summary buffer when using a single
6406              ;; article buffer.
6407              (unless (gnus-buffer-live-p gnus-summary-buffer)
6408                (set-buffer gnus-group-buffer))
6409              (set-buffer gnus-summary-buffer)
6410              (gnus-set-global-variables))))
6411     (if (or (eq (cdr quit-config) 'article)
6412             (eq (cdr quit-config) 'pick))
6413         (progn
6414           ;; The current article may be from the ephemeral group
6415           ;; thus it is best that we reload this article
6416           (gnus-summary-show-article)
6417           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6418               (gnus-configure-windows 'pick 'force)
6419             (gnus-configure-windows (cdr quit-config) 'force)))
6420       (gnus-configure-windows (cdr quit-config) 'force))
6421     (when (eq major-mode 'gnus-summary-mode)
6422       (gnus-summary-next-subject 1 nil t)
6423       (gnus-summary-recenter)
6424       (gnus-summary-position-point))))
6425
6426 (defun gnus-summary-preview-mime-message ()
6427   "MIME decode and play this message."
6428   (interactive)
6429   (let ((gnus-break-pages nil)
6430         (gnus-show-mime t))
6431     (gnus-summary-select-article gnus-show-all-headers t))
6432   (let ((w (get-buffer-window gnus-article-buffer)))
6433     (when w
6434       (select-window (get-buffer-window gnus-article-buffer)))))
6435
6436 ;;; Dead summaries.
6437
6438 (defvar gnus-dead-summary-mode-map nil)
6439
6440 (unless gnus-dead-summary-mode-map
6441   (setq gnus-dead-summary-mode-map (make-keymap))
6442   (suppress-keymap gnus-dead-summary-mode-map)
6443   (substitute-key-definition
6444    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6445   (dolist (key '("\C-d" "\r" "\177" [delete]))
6446     (define-key gnus-dead-summary-mode-map
6447       key 'gnus-summary-wake-up-the-dead))
6448   (dolist (key '("q" "Q"))
6449     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6450
6451 (defvar gnus-dead-summary-mode nil
6452   "Minor mode for Gnus summary buffers.")
6453
6454 (defun gnus-dead-summary-mode (&optional arg)
6455   "Minor mode for Gnus summary buffers."
6456   (interactive "P")
6457   (when (eq major-mode 'gnus-summary-mode)
6458     (make-local-variable 'gnus-dead-summary-mode)
6459     (setq gnus-dead-summary-mode
6460           (if (null arg) (not gnus-dead-summary-mode)
6461             (> (prefix-numeric-value arg) 0)))
6462     (when gnus-dead-summary-mode
6463       (gnus-add-minor-mode
6464        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6465
6466 (defun gnus-deaden-summary ()
6467   "Make the current summary buffer into a dead summary buffer."
6468   ;; Kill any previous dead summary buffer.
6469   (when (and gnus-dead-summary
6470              (buffer-name gnus-dead-summary))
6471     (save-excursion
6472       (set-buffer gnus-dead-summary)
6473       (when gnus-dead-summary-mode
6474         (kill-buffer (current-buffer)))))
6475   ;; Make this the current dead summary.
6476   (setq gnus-dead-summary (current-buffer))
6477   (gnus-dead-summary-mode 1)
6478   (let ((name (buffer-name)))
6479     (when (string-match "Summary" name)
6480       (rename-buffer
6481        (concat (substring name 0 (match-beginning 0)) "Dead "
6482                (substring name (match-beginning 0)))
6483        t)
6484       (bury-buffer))))
6485
6486 (defun gnus-kill-or-deaden-summary (buffer)
6487   "Kill or deaden the summary BUFFER."
6488   (save-excursion
6489     (when (and (buffer-name buffer)
6490                (not gnus-single-article-buffer))
6491       (save-excursion
6492         (set-buffer buffer)
6493         (gnus-kill-buffer gnus-article-buffer)
6494         (gnus-kill-buffer gnus-original-article-buffer)))
6495     (cond
6496      ;; Kill the buffer.
6497      (gnus-kill-summary-on-exit
6498       (when (and gnus-use-trees
6499                  (gnus-buffer-exists-p buffer))
6500         (save-excursion
6501           (set-buffer buffer)
6502           (gnus-tree-close gnus-newsgroup-name)))
6503       (gnus-kill-buffer buffer))
6504      ;; Deaden the buffer.
6505      ((gnus-buffer-exists-p buffer)
6506       (save-excursion
6507         (set-buffer buffer)
6508         (gnus-deaden-summary))))))
6509
6510 (defun gnus-summary-wake-up-the-dead (&rest args)
6511   "Wake up the dead summary buffer."
6512   (interactive)
6513   (gnus-dead-summary-mode -1)
6514   (let ((name (buffer-name)))
6515     (when (string-match "Dead " name)
6516       (rename-buffer
6517        (concat (substring name 0 (match-beginning 0))
6518                (substring name (match-end 0)))
6519        t)))
6520   (gnus-message 3 "This dead summary is now alive again"))
6521
6522 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6523 (defun gnus-summary-fetch-faq (&optional faq-dir)
6524   "Fetch the FAQ for the current group.
6525 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6526 in."
6527   (interactive
6528    (list
6529     (when current-prefix-arg
6530       (completing-read
6531        "Faq dir: " (and (listp gnus-group-faq-directory)
6532                         (mapcar (lambda (file) (list file))
6533                                 gnus-group-faq-directory))))))
6534   (let (gnus-faq-buffer)
6535     (when (setq gnus-faq-buffer
6536                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6537       (gnus-configure-windows 'summary-faq))))
6538
6539 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6540 (defun gnus-summary-describe-group (&optional force)
6541   "Describe the current newsgroup."
6542   (interactive "P")
6543   (gnus-group-describe-group force gnus-newsgroup-name))
6544
6545 (defun gnus-summary-describe-briefly ()
6546   "Describe summary mode commands briefly."
6547   (interactive)
6548   (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")))
6549
6550 ;; Walking around group mode buffer from summary mode.
6551
6552 (defun gnus-summary-next-group (&optional no-article target-group backward)
6553   "Exit current newsgroup and then select next unread newsgroup.
6554 If prefix argument NO-ARTICLE is non-nil, no article is selected
6555 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6556 previous group instead."
6557   (interactive "P")
6558   ;; Stop pre-fetching.
6559   (gnus-async-halt-prefetch)
6560   (let ((current-group gnus-newsgroup-name)
6561         (current-buffer (current-buffer))
6562         entered)
6563     (gnus-summary-exit t)
6564     (while (not entered)
6565       ;; Then we find what group we are supposed to enter.
6566       (set-buffer gnus-group-buffer)
6567       (gnus-group-jump-to-group current-group)
6568       (setq target-group
6569             (or target-group
6570                 (if (eq gnus-keep-same-level 'best)
6571                     (gnus-summary-best-group gnus-newsgroup-name)
6572                   (gnus-summary-search-group backward gnus-keep-same-level))))
6573       (if (not target-group)
6574           ;; There are no further groups, so we return to the group
6575           ;; buffer.
6576           (progn
6577             (gnus-message 5 "Returning to the group buffer")
6578             (setq entered t)
6579             (when (gnus-buffer-live-p current-buffer)
6580               (set-buffer current-buffer)
6581               (gnus-summary-exit))
6582             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6583         ;; We try to enter the target group.
6584         (gnus-group-jump-to-group target-group)
6585         (let ((unreads (gnus-group-group-unread)))
6586           (if (and (or (eq t unreads)
6587                        (and unreads (not (zerop unreads))))
6588                    (progn
6589                      ;; Now we semi-exit this group to update Xrefs
6590                      ;; and all variables.  We can't do a real exit,
6591                      ;; because the window conf must remain the same
6592                      ;; in case the user is prompted for info, and we
6593                      ;; don't want the window conf to change before
6594                      ;; that...
6595                      (when (gnus-buffer-live-p current-buffer)
6596                        (set-buffer current-buffer)
6597                        (gnus-summary-exit t))
6598                      (gnus-summary-read-group
6599                       target-group nil no-article
6600                       (and (buffer-name current-buffer) current-buffer)
6601                       nil backward)))
6602               (setq entered t)
6603             (setq current-group target-group
6604                   target-group nil)))))))
6605
6606 (defun gnus-summary-prev-group (&optional no-article)
6607   "Exit current newsgroup and then select previous unread newsgroup.
6608 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6609   (interactive "P")
6610   (gnus-summary-next-group no-article nil t))
6611
6612 ;; Walking around summary lines.
6613
6614 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6615   "Go to the first unread subject.
6616 If UNREAD is non-nil, go to the first unread article.
6617 Returns the article selected or nil if there are no unread articles."
6618   (interactive "P")
6619   (prog1
6620       (cond
6621        ;; Empty summary.
6622        ((null gnus-newsgroup-data)
6623         (gnus-message 3 "No articles in the group")
6624         nil)
6625        ;; Pick the first article.
6626        ((not unread)
6627         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6628         (gnus-data-number (car gnus-newsgroup-data)))
6629        ;; No unread articles.
6630        ((null gnus-newsgroup-unreads)
6631         (gnus-message 3 "No more unread articles")
6632         nil)
6633        ;; Find the first unread article.
6634        (t
6635         (let ((data gnus-newsgroup-data))
6636           (while (and data
6637                       (and (not (and undownloaded
6638                                      (eq gnus-undownloaded-mark
6639                                          (gnus-data-mark (car data)))))
6640                            (if unseen
6641                                (or (not (memq
6642                                          (gnus-data-number (car data))
6643                                          gnus-newsgroup-unseen))
6644                                    (not (gnus-data-unread-p (car data))))
6645                              (not (gnus-data-unread-p (car data))))))
6646             (setq data (cdr data)))
6647           (when data
6648             (goto-char (gnus-data-pos (car data)))
6649             (gnus-data-number (car data))))))
6650     (gnus-summary-position-point)))
6651
6652 (defun gnus-summary-next-subject (n &optional unread dont-display)
6653   "Go to next N'th summary line.
6654 If N is negative, go to the previous N'th subject line.
6655 If UNREAD is non-nil, only unread articles are selected.
6656 The difference between N and the actual number of steps taken is
6657 returned."
6658   (interactive "p")
6659   (let ((backward (< n 0))
6660         (n (abs n)))
6661     (while (and (> n 0)
6662                 (if backward
6663                     (gnus-summary-find-prev unread)
6664                   (gnus-summary-find-next unread)))
6665       (unless (zerop (setq n (1- n)))
6666         (gnus-summary-show-thread)))
6667     (when (/= 0 n)
6668       (gnus-message 7 "No more%s articles"
6669                     (if unread " unread" "")))
6670     (unless dont-display
6671       (gnus-summary-recenter)
6672       (gnus-summary-position-point))
6673     n))
6674
6675 (defun gnus-summary-next-unread-subject (n)
6676   "Go to next N'th unread summary line."
6677   (interactive "p")
6678   (gnus-summary-next-subject n t))
6679
6680 (defun gnus-summary-prev-subject (n &optional unread)
6681   "Go to previous N'th summary line.
6682 If optional argument UNREAD is non-nil, only unread article is selected."
6683   (interactive "p")
6684   (gnus-summary-next-subject (- n) unread))
6685
6686 (defun gnus-summary-prev-unread-subject (n)
6687   "Go to previous N'th unread summary line."
6688   (interactive "p")
6689   (gnus-summary-next-subject (- n) t))
6690
6691 (defun gnus-summary-goto-subject (article &optional force silent)
6692   "Go the subject line of ARTICLE.
6693 If FORCE, also allow jumping to articles not currently shown."
6694   (interactive "nArticle number: ")
6695   (unless (numberp article)
6696     (error "Article %s is not a number" article))
6697   (let ((b (point))
6698         (data (gnus-data-find article)))
6699     ;; We read in the article if we have to.
6700     (and (not data)
6701          force
6702          (gnus-summary-insert-subject
6703           article
6704           (if (or (numberp force) (vectorp force)) force)
6705           t)
6706          (setq data (gnus-data-find article)))
6707     (goto-char b)
6708     (if (not data)
6709         (progn
6710           (unless silent
6711             (gnus-message 3 "Can't find article %d" article))
6712           nil)
6713       (let ((pt (gnus-data-pos data)))
6714         (goto-char pt)
6715         (gnus-summary-set-article-display-arrow pt))
6716       (gnus-summary-position-point)
6717       article)))
6718
6719 ;; Walking around summary lines with displaying articles.
6720
6721 (defun gnus-summary-expand-window (&optional arg)
6722   "Make the summary buffer take up the entire Emacs frame.
6723 Given a prefix, will force an `article' buffer configuration."
6724   (interactive "P")
6725   (if arg
6726       (gnus-configure-windows 'article 'force)
6727     (gnus-configure-windows 'summary 'force)))
6728
6729 (defun gnus-summary-display-article (article &optional all-header)
6730   "Display ARTICLE in article buffer."
6731   (when (gnus-buffer-live-p gnus-article-buffer)
6732     (with-current-buffer gnus-article-buffer
6733       (set-buffer-multibyte t)))
6734   (gnus-set-global-variables)
6735   (when (gnus-buffer-live-p gnus-article-buffer)
6736     (with-current-buffer gnus-article-buffer
6737       (setq gnus-article-charset gnus-newsgroup-charset)
6738       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6739       (set-buffer-multibyte t)))
6740   (if (null article)
6741       nil
6742     (prog1
6743         (if gnus-summary-display-article-function
6744             (funcall gnus-summary-display-article-function article all-header)
6745           (gnus-article-prepare article all-header))
6746       (with-current-buffer gnus-article-buffer
6747         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6748              nil))
6749       (gnus-run-hooks 'gnus-select-article-hook)
6750       (when (and gnus-current-article
6751                  (not (zerop gnus-current-article)))
6752         (gnus-summary-goto-subject gnus-current-article))
6753       (gnus-summary-recenter)
6754       (when (and gnus-use-trees gnus-show-threads)
6755         (gnus-possibly-generate-tree article)
6756         (gnus-highlight-selected-tree article))
6757       ;; Successfully display article.
6758       (gnus-article-set-window-start
6759        (cdr (assq article gnus-newsgroup-bookmarks))))))
6760
6761 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6762   "Select the current article.
6763 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6764 non-nil, the article will be re-fetched even if it already present in
6765 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6766 be displayed."
6767   ;; Make sure we are in the summary buffer to work around bbdb bug.
6768   (unless (eq major-mode 'gnus-summary-mode)
6769     (set-buffer gnus-summary-buffer))
6770   (let ((article (or article (gnus-summary-article-number)))
6771         (all-headers (not (not all-headers))) ;Must be T or NIL.
6772         gnus-summary-display-article-function)
6773     (and (not pseudo)
6774          (gnus-summary-article-pseudo-p article)
6775          (error "This is a pseudo-article"))
6776     (save-excursion
6777       (set-buffer gnus-summary-buffer)
6778       (if (or (and gnus-single-article-buffer
6779                    (or (null gnus-current-article)
6780                        (null gnus-article-current)
6781                        (null (get-buffer gnus-article-buffer))
6782                        (not (eq article (cdr gnus-article-current)))
6783                        (not (equal (car gnus-article-current)
6784                                    gnus-newsgroup-name))))
6785               (and (not gnus-single-article-buffer)
6786                    (or (null gnus-current-article)
6787                        (not (eq gnus-current-article article))))
6788               force)
6789           ;; The requested article is different from the current article.
6790           (progn
6791             (gnus-summary-display-article article all-headers)
6792             (gnus-article-set-window-start
6793              (cdr (assq article gnus-newsgroup-bookmarks)))
6794             article)
6795         'old))))
6796
6797 (defun gnus-summary-force-verify-and-decrypt ()
6798   (interactive)
6799   (let ((mm-verify-option 'known)
6800         (mm-decrypt-option 'known)
6801         (gnus-buttonized-mime-types (append (list "multipart/signed"
6802                                                   "multipart/encrypted")
6803                                             gnus-buttonized-mime-types)))
6804     (gnus-summary-select-article nil 'force)))
6805
6806 (defun gnus-summary-set-current-mark (&optional current-mark)
6807   "Obsolete function."
6808   nil)
6809
6810 (defun gnus-summary-next-article (&optional unread subject backward push)
6811   "Select the next article.
6812 If UNREAD, only unread articles are selected.
6813 If SUBJECT, only articles with SUBJECT are selected.
6814 If BACKWARD, the previous article is selected instead of the next."
6815   (interactive "P")
6816   (cond
6817    ;; Is there such an article?
6818    ((and (gnus-summary-search-forward unread subject backward)
6819          (or (gnus-summary-display-article (gnus-summary-article-number))
6820              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6821     (gnus-summary-position-point))
6822    ;; If not, we try the first unread, if that is wanted.
6823    ((and subject
6824          gnus-auto-select-same
6825          (gnus-summary-first-unread-article))
6826     (gnus-summary-position-point)
6827     (gnus-message 6 "Wrapped"))
6828    ;; Try to get next/previous article not displayed in this group.
6829    ((and gnus-auto-extend-newsgroup
6830          (not unread) (not subject))
6831     (gnus-summary-goto-article
6832      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6833      nil (count-lines (point-min) (point))))
6834    ;; Go to next/previous group.
6835    (t
6836     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6837       (gnus-summary-jump-to-group gnus-newsgroup-name))
6838     (let ((cmd last-command-char)
6839           (point
6840            (save-excursion
6841              (set-buffer gnus-group-buffer)
6842              (point)))
6843           (group
6844            (if (eq gnus-keep-same-level 'best)
6845                (gnus-summary-best-group gnus-newsgroup-name)
6846              (gnus-summary-search-group backward gnus-keep-same-level))))
6847       ;; For some reason, the group window gets selected.  We change
6848       ;; it back.
6849       (select-window (get-buffer-window (current-buffer)))
6850       ;; Select next unread newsgroup automagically.
6851       (cond
6852        ((or (not gnus-auto-select-next)
6853             (not cmd))
6854         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6855        ((or (eq gnus-auto-select-next 'quietly)
6856             (and (eq gnus-auto-select-next 'slightly-quietly)
6857                  push)
6858             (and (eq gnus-auto-select-next 'almost-quietly)
6859                  (gnus-summary-last-article-p)))
6860         ;; Select quietly.
6861         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6862             (gnus-summary-exit)
6863           (gnus-message 7 "No more%s articles (%s)..."
6864                         (if unread " unread" "")
6865                         (if group (concat "selecting " group)
6866                           "exiting"))
6867           (gnus-summary-next-group nil group backward)))
6868        (t
6869         (when (gnus-key-press-event-p last-input-event)
6870           (gnus-summary-walk-group-buffer
6871            gnus-newsgroup-name cmd unread backward point))))))))
6872
6873 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6874   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6875                       (?\C-p (gnus-group-prev-unread-group 1))))
6876         (cursor-in-echo-area t)
6877         keve key group ended)
6878     (save-excursion
6879       (set-buffer gnus-group-buffer)
6880       (goto-char start)
6881       (setq group
6882             (if (eq gnus-keep-same-level 'best)
6883                 (gnus-summary-best-group gnus-newsgroup-name)
6884               (gnus-summary-search-group backward gnus-keep-same-level))))
6885     (while (not ended)
6886       (gnus-message
6887        5 "No more%s articles%s" (if unread " unread" "")
6888        (if (and group
6889                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6890            (format " (Type %s for %s [%s])"
6891                    (single-key-description cmd) group
6892                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6893          (format " (Type %s to exit %s)"
6894                  (single-key-description cmd)
6895                  gnus-newsgroup-name)))
6896       ;; Confirm auto selection.
6897       (setq key (car (setq keve (gnus-read-event-char))))
6898       (setq ended t)
6899       (cond
6900        ((assq key keystrokes)
6901         (let ((obuf (current-buffer)))
6902           (switch-to-buffer gnus-group-buffer)
6903           (when group
6904             (gnus-group-jump-to-group group))
6905           (eval (cadr (assq key keystrokes)))
6906           (setq group (gnus-group-group-name))
6907           (switch-to-buffer obuf))
6908         (setq ended nil))
6909        ((equal key cmd)
6910         (if (or (not group)
6911                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6912             (gnus-summary-exit)
6913           (gnus-summary-next-group nil group backward)))
6914        (t
6915         (push (cdr keve) unread-command-events))))))
6916
6917 (defun gnus-summary-next-unread-article ()
6918   "Select unread article after current one."
6919   (interactive)
6920   (gnus-summary-next-article
6921    (or (not (eq gnus-summary-goto-unread 'never))
6922        (gnus-summary-last-article-p (gnus-summary-article-number)))
6923    (and gnus-auto-select-same
6924         (gnus-summary-article-subject))))
6925
6926 (defun gnus-summary-prev-article (&optional unread subject)
6927   "Select the article after the current one.
6928 If UNREAD is non-nil, only unread articles are selected."
6929   (interactive "P")
6930   (gnus-summary-next-article unread subject t))
6931
6932 (defun gnus-summary-prev-unread-article ()
6933   "Select unread article before current one."
6934   (interactive)
6935   (gnus-summary-prev-article
6936    (or (not (eq gnus-summary-goto-unread 'never))
6937        (gnus-summary-first-article-p (gnus-summary-article-number)))
6938    (and gnus-auto-select-same
6939         (gnus-summary-article-subject))))
6940
6941 (defun gnus-summary-next-page (&optional lines circular)
6942   "Show next page of the selected article.
6943 If at the end of the current article, select the next article.
6944 LINES says how many lines should be scrolled up.
6945
6946 If CIRCULAR is non-nil, go to the start of the article instead of
6947 selecting the next article when reaching the end of the current
6948 article."
6949   (interactive "P")
6950   (setq gnus-summary-buffer (current-buffer))
6951   (gnus-set-global-variables)
6952   (let ((article (gnus-summary-article-number))
6953         (article-window (get-buffer-window gnus-article-buffer t))
6954         endp)
6955     ;; If the buffer is empty, we have no article.
6956     (unless article
6957       (error "No article to select"))
6958     (gnus-configure-windows 'article)
6959     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6960         (if (and (eq gnus-summary-goto-unread 'never)
6961                  (not (gnus-summary-last-article-p article)))
6962             (gnus-summary-next-article)
6963           (gnus-summary-next-unread-article))
6964       (if (or (null gnus-current-article)
6965               (null gnus-article-current)
6966               (/= article (cdr gnus-article-current))
6967               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6968           ;; Selected subject is different from current article's.
6969           (gnus-summary-display-article article)
6970         (when article-window
6971           (gnus-eval-in-buffer-window gnus-article-buffer
6972             (setq endp (gnus-article-next-page lines)))
6973           (when endp
6974             (cond (circular
6975                    (gnus-summary-beginning-of-article))
6976                   (lines
6977                    (gnus-message 3 "End of message"))
6978                   ((null lines)
6979                    (if (and (eq gnus-summary-goto-unread 'never)
6980                             (not (gnus-summary-last-article-p article)))
6981                        (gnus-summary-next-article)
6982                      (gnus-summary-next-unread-article))))))))
6983     (gnus-summary-recenter)
6984     (gnus-summary-position-point)))
6985
6986 (defun gnus-summary-prev-page (&optional lines move)
6987   "Show previous page of selected article.
6988 Argument LINES specifies lines to be scrolled down.
6989 If MOVE, move to the previous unread article if point is at
6990 the beginning of the buffer."
6991   (interactive "P")
6992   (let ((article (gnus-summary-article-number))
6993         (article-window (get-buffer-window gnus-article-buffer t))
6994         endp)
6995     (gnus-configure-windows 'article)
6996     (if (or (null gnus-current-article)
6997             (null gnus-article-current)
6998             (/= article (cdr gnus-article-current))
6999             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7000         ;; Selected subject is different from current article's.
7001         (gnus-summary-display-article article)
7002       (gnus-summary-recenter)
7003       (when article-window
7004         (gnus-eval-in-buffer-window gnus-article-buffer
7005           (setq endp (gnus-article-prev-page lines)))
7006         (when (and move endp)
7007           (cond (lines
7008                  (gnus-message 3 "Beginning of message"))
7009                 ((null lines)
7010                  (if (and (eq gnus-summary-goto-unread 'never)
7011                           (not (gnus-summary-first-article-p article)))
7012                      (gnus-summary-prev-article)
7013                    (gnus-summary-prev-unread-article))))))))
7014   (gnus-summary-position-point))
7015
7016 (defun gnus-summary-prev-page-or-article (&optional lines)
7017   "Show previous page of selected article.
7018 Argument LINES specifies lines to be scrolled down.
7019 If at the beginning of the article, go to the next article."
7020   (interactive "P")
7021   (gnus-summary-prev-page lines t))
7022
7023 (defun gnus-summary-scroll-up (lines)
7024   "Scroll up (or down) one line current article.
7025 Argument LINES specifies lines to be scrolled up (or down if negative)."
7026   (interactive "p")
7027   (gnus-configure-windows 'article)
7028   (gnus-summary-show-thread)
7029   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7030     (gnus-eval-in-buffer-window gnus-article-buffer
7031       (cond ((> lines 0)
7032              (when (gnus-article-next-page lines)
7033                (gnus-message 3 "End of message")))
7034             ((< lines 0)
7035              (gnus-article-prev-page (- lines))))))
7036   (gnus-summary-recenter)
7037   (gnus-summary-position-point))
7038
7039 (defun gnus-summary-scroll-down (lines)
7040   "Scroll down (or up) one line current article.
7041 Argument LINES specifies lines to be scrolled down (or up if negative)."
7042   (interactive "p")
7043   (gnus-summary-scroll-up (- lines)))
7044
7045 (defun gnus-summary-next-same-subject ()
7046   "Select next article which has the same subject as current one."
7047   (interactive)
7048   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7049
7050 (defun gnus-summary-prev-same-subject ()
7051   "Select previous article which has the same subject as current one."
7052   (interactive)
7053   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7054
7055 (defun gnus-summary-next-unread-same-subject ()
7056   "Select next unread article which has the same subject as current one."
7057   (interactive)
7058   (gnus-summary-next-article t (gnus-summary-article-subject)))
7059
7060 (defun gnus-summary-prev-unread-same-subject ()
7061   "Select previous unread article which has the same subject as current one."
7062   (interactive)
7063   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7064
7065 (defun gnus-summary-first-unread-article ()
7066   "Select the first unread article.
7067 Return nil if there are no unread articles."
7068   (interactive)
7069   (prog1
7070       (when (gnus-summary-first-subject t)
7071         (gnus-summary-show-thread)
7072         (gnus-summary-first-subject t)
7073         (gnus-summary-display-article (gnus-summary-article-number)))
7074     (gnus-summary-position-point)))
7075
7076 (defun gnus-summary-first-unread-subject ()
7077   "Place the point on the subject line of the first unread article.
7078 Return nil if there are no unread articles."
7079   (interactive)
7080   (prog1
7081       (when (gnus-summary-first-subject t)
7082         (gnus-summary-show-thread)
7083         (gnus-summary-first-subject t))
7084     (gnus-summary-position-point)))
7085
7086 (defun gnus-summary-first-unseen-subject ()
7087   "Place the point on the subject line of the first unseen article.
7088 Return nil if there are no unseen articles."
7089   (interactive)
7090   (prog1
7091       (when (gnus-summary-first-subject t t t)
7092         (gnus-summary-show-thread)
7093         (gnus-summary-first-subject t t t))
7094     (gnus-summary-position-point)))
7095
7096 (defun gnus-summary-first-unseen-or-unread-subject ()
7097   "Place the point on the subject line of the first unseen article.
7098 Return nil if there are no unseen articles."
7099   (interactive)
7100   (prog1
7101       (unless (when (gnus-summary-first-subject t t t)
7102                 (gnus-summary-show-thread)
7103                 (gnus-summary-first-subject t t t))
7104         (when (gnus-summary-first-subject t)
7105           (gnus-summary-show-thread)
7106           (gnus-summary-first-subject t)))
7107     (gnus-summary-position-point)))
7108
7109 (defun gnus-summary-first-article ()
7110   "Select the first article.
7111 Return nil if there are no articles."
7112   (interactive)
7113   (prog1
7114       (when (gnus-summary-first-subject)
7115         (gnus-summary-show-thread)
7116         (gnus-summary-first-subject)
7117         (gnus-summary-display-article (gnus-summary-article-number)))
7118     (gnus-summary-position-point)))
7119
7120 (defun gnus-summary-best-unread-article (&optional arg)
7121   "Select the unread article with the highest score.
7122 If given a prefix argument, select the next unread article that has a
7123 score higher than the default score."
7124   (interactive "P")
7125   (let ((article (if arg
7126                      (gnus-summary-better-unread-subject)
7127                    (gnus-summary-best-unread-subject))))
7128     (if article
7129         (gnus-summary-goto-article article)
7130       (error "No unread articles"))))
7131
7132 (defun gnus-summary-best-unread-subject ()
7133   "Select the unread subject with the highest score."
7134   (interactive)
7135   (let ((best -1000000)
7136         (data gnus-newsgroup-data)
7137         article score)
7138     (while data
7139       (and (gnus-data-unread-p (car data))
7140            (> (setq score
7141                     (gnus-summary-article-score (gnus-data-number (car data))))
7142               best)
7143            (setq best score
7144                  article (gnus-data-number (car data))))
7145       (setq data (cdr data)))
7146     (when article
7147       (gnus-summary-goto-subject article))
7148     (gnus-summary-position-point)
7149     article))
7150
7151 (defun gnus-summary-better-unread-subject ()
7152   "Select the first unread subject that has a score over the default score."
7153   (interactive)
7154   (let ((data gnus-newsgroup-data)
7155         article score)
7156     (while (and (setq article (gnus-data-number (car data)))
7157                 (or (gnus-data-read-p (car data))
7158                     (not (> (gnus-summary-article-score article)
7159                             gnus-summary-default-score))))
7160       (setq data (cdr data)))
7161     (when article
7162       (gnus-summary-goto-subject article))
7163     (gnus-summary-position-point)
7164     article))
7165
7166 (defun gnus-summary-last-subject ()
7167   "Go to the last displayed subject line in the group."
7168   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7169     (when article
7170       (gnus-summary-goto-subject article))))
7171
7172 (defun gnus-summary-goto-article (article &optional all-headers force)
7173   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7174 If ALL-HEADERS is non-nil, no header lines are hidden.
7175 If FORCE, go to the article even if it isn't displayed.  If FORCE
7176 is a number, it is the line the article is to be displayed on."
7177   (interactive
7178    (list
7179     (completing-read
7180      "Article number or Message-ID: "
7181      (mapcar (lambda (number) (list (int-to-string number)))
7182              gnus-newsgroup-limit))
7183     current-prefix-arg
7184     t))
7185   (prog1
7186       (if (and (stringp article)
7187                (string-match "@" article))
7188           (gnus-summary-refer-article article)
7189         (when (stringp article)
7190           (setq article (string-to-number article)))
7191         (if (gnus-summary-goto-subject article force)
7192             (gnus-summary-display-article article all-headers)
7193           (gnus-message 4 "Couldn't go to article %s" article) nil))
7194     (gnus-summary-position-point)))
7195
7196 (defun gnus-summary-goto-last-article ()
7197   "Go to the previously read article."
7198   (interactive)
7199   (prog1
7200       (when gnus-last-article
7201         (gnus-summary-goto-article gnus-last-article nil t))
7202     (gnus-summary-position-point)))
7203
7204 (defun gnus-summary-pop-article (number)
7205   "Pop one article off the history and go to the previous.
7206 NUMBER articles will be popped off."
7207   (interactive "p")
7208   (let (to)
7209     (setq gnus-newsgroup-history
7210           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7211     (if to
7212         (gnus-summary-goto-article (car to) nil t)
7213       (error "Article history empty")))
7214   (gnus-summary-position-point))
7215
7216 ;; Summary commands and functions for limiting the summary buffer.
7217
7218 (defun gnus-summary-limit-to-articles (n)
7219   "Limit the summary buffer to the next N articles.
7220 If not given a prefix, use the process marked articles instead."
7221   (interactive "P")
7222   (prog1
7223       (let ((articles (gnus-summary-work-articles n)))
7224         (setq gnus-newsgroup-processable nil)
7225         (gnus-summary-limit articles))
7226     (gnus-summary-position-point)))
7227
7228 (defun gnus-summary-pop-limit (&optional total)
7229   "Restore the previous limit.
7230 If given a prefix, remove all limits."
7231   (interactive "P")
7232   (when total
7233     (setq gnus-newsgroup-limits
7234           (list (mapcar (lambda (h) (mail-header-number h))
7235                         gnus-newsgroup-headers))))
7236   (unless gnus-newsgroup-limits
7237     (error "No limit to pop"))
7238   (prog1
7239       (gnus-summary-limit nil 'pop)
7240     (gnus-summary-position-point)))
7241
7242 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7243   "Limit the summary buffer to articles that have subjects that match a regexp.
7244 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7245   (interactive
7246    (list (read-string (if current-prefix-arg
7247                           "Exclude subject (regexp): "
7248                         "Limit to subject (regexp): "))
7249          nil current-prefix-arg))
7250   (unless header
7251     (setq header "subject"))
7252   (when (not (equal "" subject))
7253     (prog1
7254         (let ((articles (gnus-summary-find-matching
7255                          (or header "subject") subject 'all nil nil
7256                          not-matching)))
7257           (unless articles
7258             (error "Found no matches for \"%s\"" subject))
7259           (gnus-summary-limit articles))
7260       (gnus-summary-position-point))))
7261
7262 (defun gnus-summary-limit-to-author (from &optional not-matching)
7263   "Limit the summary buffer to articles that have authors that match a regexp.
7264 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7265   (interactive
7266    (list (read-string (if current-prefix-arg
7267                           "Exclude author (regexp): "
7268                         "Limit to author (regexp): "))
7269          current-prefix-arg))
7270   (gnus-summary-limit-to-subject from "from" not-matching))
7271
7272 (defun gnus-summary-limit-to-age (age &optional younger-p)
7273   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7274 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7275 articles that are younger than AGE days."
7276   (interactive
7277    (let ((younger current-prefix-arg)
7278          (days-got nil)
7279          days)
7280      (while (not days-got)
7281        (setq days (if younger
7282                       (read-string "Limit to articles within (in days): ")
7283                     (read-string "Limit to articles older than (in days): ")))
7284        (when (> (length days) 0)
7285          (setq days (read days)))
7286        (if (numberp days)
7287            (progn
7288              (setq days-got t)
7289              (if (< days 0)
7290                  (progn
7291                    (setq younger (not younger))
7292                    (setq days (* days -1)))))
7293          (message "Please enter a number.")
7294          (sleep-for 1)))
7295      (list days younger)))
7296   (prog1
7297       (let ((data gnus-newsgroup-data)
7298             (cutoff (days-to-time age))
7299             articles d date is-younger)
7300         (while (setq d (pop data))
7301           (when (and (vectorp (gnus-data-header d))
7302                      (setq date (mail-header-date (gnus-data-header d))))
7303             (setq is-younger (time-less-p
7304                               (time-since (condition-case ()
7305                                               (date-to-time date)
7306                                             (error '(0 0))))
7307                               cutoff))
7308             (when (if younger-p
7309                       is-younger
7310                     (not is-younger))
7311               (push (gnus-data-number d) articles))))
7312         (gnus-summary-limit (nreverse articles)))
7313     (gnus-summary-position-point)))
7314
7315 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7316   "Limit the summary buffer to articles that match an 'extra' header."
7317   (interactive
7318    (let ((header
7319           (intern
7320            (gnus-completing-read-with-default
7321             (symbol-name (car gnus-extra-headers))
7322             (if current-prefix-arg
7323                 "Exclude extra header:"
7324               "Limit extra header:")
7325             (mapcar (lambda (x)
7326                       (cons (symbol-name x) x))
7327                     gnus-extra-headers)
7328             nil
7329             t))))
7330      (list header
7331            (read-string (format "%s header %s (regexp): "
7332                                 (if current-prefix-arg "Exclude" "Limit to")
7333                                 header))
7334            current-prefix-arg)))
7335   (when (not (equal "" regexp))
7336     (prog1
7337         (let ((articles (gnus-summary-find-matching
7338                          (cons 'extra header) regexp 'all nil nil
7339                          not-matching)))
7340           (unless articles
7341             (error "Found no matches for \"%s\"" regexp))
7342           (gnus-summary-limit articles))
7343       (gnus-summary-position-point))))
7344
7345 (defun gnus-summary-limit-to-display-predicate ()
7346   "Limit the summary buffer to the predicated in the `display' group parameter."
7347   (interactive)
7348   (unless gnus-newsgroup-display
7349     (error "There is no `display' group parameter"))
7350   (let (articles)
7351     (dolist (number gnus-newsgroup-articles)
7352       (when (funcall gnus-newsgroup-display)
7353         (push number articles)))
7354     (gnus-summary-limit articles))
7355   (gnus-summary-position-point))
7356
7357 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7358 (make-obsolete
7359  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7360
7361 (defun gnus-summary-limit-to-unread (&optional all)
7362   "Limit the summary buffer to articles that are not marked as read.
7363 If ALL is non-nil, limit strictly to unread articles."
7364   (interactive "P")
7365   (if all
7366       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7367     (gnus-summary-limit-to-marks
7368      ;; Concat all the marks that say that an article is read and have
7369      ;; those removed.
7370      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7371            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7372            gnus-low-score-mark gnus-expirable-mark
7373            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7374            gnus-duplicate-mark gnus-souped-mark)
7375      'reverse)))
7376
7377 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7378 (make-obsolete 'gnus-summary-delete-marked-with
7379                'gnus-summary-limit-exclude-marks)
7380
7381 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7382   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7383 If REVERSE, limit the summary buffer to articles that are marked
7384 with MARKS.  MARKS can either be a string of marks or a list of marks.
7385 Returns how many articles were removed."
7386   (interactive "sMarks: ")
7387   (gnus-summary-limit-to-marks marks t))
7388
7389 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7390   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7391 If REVERSE (the prefix), limit the summary buffer to articles that are
7392 not marked with MARKS.  MARKS can either be a string of marks or a
7393 list of marks.
7394 Returns how many articles were removed."
7395   (interactive "sMarks: \nP")
7396   (prog1
7397       (let ((data gnus-newsgroup-data)
7398             (marks (if (listp marks) marks
7399                      (append marks nil))) ; Transform to list.
7400             articles)
7401         (while data
7402           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7403                   (memq (gnus-data-mark (car data)) marks))
7404             (push (gnus-data-number (car data)) articles))
7405           (setq data (cdr data)))
7406         (gnus-summary-limit articles))
7407     (gnus-summary-position-point)))
7408
7409 (defun gnus-summary-limit-to-score (score)
7410   "Limit to articles with score at or above SCORE."
7411   (interactive "NLimit to articles with score of at least: ")
7412   (let ((data gnus-newsgroup-data)
7413         articles)
7414     (while data
7415       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7416                 score)
7417         (push (gnus-data-number (car data)) articles))
7418       (setq data (cdr data)))
7419     (prog1
7420         (gnus-summary-limit articles)
7421       (gnus-summary-position-point))))
7422
7423 (defun gnus-summary-limit-to-unseen ()
7424   "Limit to unseen articles."
7425   (interactive)
7426   (prog1
7427       (gnus-summary-limit gnus-newsgroup-unseen)
7428     (gnus-summary-position-point)))
7429
7430 (defun gnus-summary-limit-include-thread (id)
7431   "Display all the hidden articles that is in the thread with ID in it.
7432 When called interactively, ID is the Message-ID of the current
7433 article."
7434   (interactive (list (mail-header-id (gnus-summary-article-header))))
7435   (let ((articles (gnus-articles-in-thread
7436                    (gnus-id-to-thread (gnus-root-id id)))))
7437     (prog1
7438         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7439       (gnus-summary-limit-include-matching-articles
7440        "subject"
7441        (regexp-quote (gnus-simplify-subject-re
7442                       (mail-header-subject (gnus-id-to-header id)))))
7443       (gnus-summary-position-point))))
7444
7445 (defun gnus-summary-limit-include-matching-articles (header regexp)
7446   "Display all the hidden articles that have HEADERs that match REGEXP."
7447   (interactive (list (read-string "Match on header: ")
7448                      (read-string "Regexp: ")))
7449   (let ((articles (gnus-find-matching-articles header regexp)))
7450     (prog1
7451         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7452       (gnus-summary-position-point))))
7453
7454 (defun gnus-summary-limit-include-dormant ()
7455   "Display all the hidden articles that are marked as dormant.
7456 Note that this command only works on a subset of the articles currently
7457 fetched for this group."
7458   (interactive)
7459   (unless gnus-newsgroup-dormant
7460     (error "There are no dormant articles in this group"))
7461   (prog1
7462       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7463     (gnus-summary-position-point)))
7464
7465 (defun gnus-summary-limit-exclude-dormant ()
7466   "Hide all dormant articles."
7467   (interactive)
7468   (prog1
7469       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7470     (gnus-summary-position-point)))
7471
7472 (defun gnus-summary-limit-exclude-childless-dormant ()
7473   "Hide all dormant articles that have no children."
7474   (interactive)
7475   (let ((data (gnus-data-list t))
7476         articles d children)
7477     ;; Find all articles that are either not dormant or have
7478     ;; children.
7479     (while (setq d (pop data))
7480       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7481                 (and (setq children
7482                            (gnus-article-children (gnus-data-number d)))
7483                      (let (found)
7484                        (while children
7485                          (when (memq (car children) articles)
7486                            (setq children nil
7487                                  found t))
7488                          (pop children))
7489                        found)))
7490         (push (gnus-data-number d) articles)))
7491     ;; Do the limiting.
7492     (prog1
7493         (gnus-summary-limit articles)
7494       (gnus-summary-position-point))))
7495
7496 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7497   "Mark all unread excluded articles as read.
7498 If ALL, mark even excluded ticked and dormants as read."
7499   (interactive "P")
7500   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7501   (let ((articles (gnus-sorted-ndifference
7502                    (sort
7503                     (mapcar (lambda (h) (mail-header-number h))
7504                             gnus-newsgroup-headers)
7505                     '<)
7506                    gnus-newsgroup-limit))
7507         article)
7508     (setq gnus-newsgroup-unreads
7509           (gnus-sorted-intersection gnus-newsgroup-unreads
7510                                     gnus-newsgroup-limit))
7511     (if all
7512         (setq gnus-newsgroup-dormant nil
7513               gnus-newsgroup-marked nil
7514               gnus-newsgroup-reads
7515               (nconc
7516                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7517                gnus-newsgroup-reads))
7518       (while (setq article (pop articles))
7519         (unless (or (memq article gnus-newsgroup-dormant)
7520                     (memq article gnus-newsgroup-marked))
7521           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7522
7523 (defun gnus-summary-limit (articles &optional pop)
7524   (if pop
7525       ;; We pop the previous limit off the stack and use that.
7526       (setq articles (car gnus-newsgroup-limits)
7527             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7528     ;; We use the new limit, so we push the old limit on the stack.
7529     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7530   ;; Set the limit.
7531   (setq gnus-newsgroup-limit articles)
7532   (let ((total (length gnus-newsgroup-data))
7533         (data (gnus-data-find-list (gnus-summary-article-number)))
7534         (gnus-summary-mark-below nil)   ; Inhibit this.
7535         found)
7536     ;; This will do all the work of generating the new summary buffer
7537     ;; according to the new limit.
7538     (gnus-summary-prepare)
7539     ;; Hide any threads, possibly.
7540     (gnus-summary-maybe-hide-threads)
7541     ;; Try to return to the article you were at, or one in the
7542     ;; neighborhood.
7543     (when data
7544       ;; We try to find some article after the current one.
7545       (while data
7546         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7547           (setq data nil
7548                 found t))
7549         (setq data (cdr data))))
7550     (unless found
7551       ;; If there is no data, that means that we were after the last
7552       ;; article.  The same goes when we can't find any articles
7553       ;; after the current one.
7554       (goto-char (point-max))
7555       (gnus-summary-find-prev))
7556     (gnus-set-mode-line 'summary)
7557     ;; We return how many articles were removed from the summary
7558     ;; buffer as a result of the new limit.
7559     (- total (length gnus-newsgroup-data))))
7560
7561 (defsubst gnus-invisible-cut-children (threads)
7562   (let ((num 0))
7563     (while threads
7564       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7565         (incf num))
7566       (pop threads))
7567     (< num 2)))
7568
7569 (defsubst gnus-cut-thread (thread)
7570   "Go forwards in the thread until we find an article that we want to display."
7571   (when (or (eq gnus-fetch-old-headers 'some)
7572             (eq gnus-fetch-old-headers 'invisible)
7573             (numberp gnus-fetch-old-headers)
7574             (eq gnus-build-sparse-threads 'some)
7575             (eq gnus-build-sparse-threads 'more))
7576     ;; Deal with old-fetched headers and sparse threads.
7577     (while (and
7578             thread
7579             (or
7580              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7581              (gnus-summary-article-ancient-p
7582               (mail-header-number (car thread))))
7583             (if (or (<= (length (cdr thread)) 1)
7584                     (eq gnus-fetch-old-headers 'invisible))
7585                 (setq gnus-newsgroup-limit
7586                       (delq (mail-header-number (car thread))
7587                             gnus-newsgroup-limit)
7588                       thread (cadr thread))
7589               (when (gnus-invisible-cut-children (cdr thread))
7590                 (let ((th (cdr thread)))
7591                   (while th
7592                     (if (memq (mail-header-number (caar th))
7593                               gnus-newsgroup-limit)
7594                         (setq thread (car th)
7595                               th nil)
7596                       (setq th (cdr th))))))))))
7597   thread)
7598
7599 (defun gnus-cut-threads (threads)
7600   "Cut off all uninteresting articles from the beginning of threads."
7601   (when (or (eq gnus-fetch-old-headers 'some)
7602             (eq gnus-fetch-old-headers 'invisible)
7603             (numberp gnus-fetch-old-headers)
7604             (eq gnus-build-sparse-threads 'some)
7605             (eq gnus-build-sparse-threads 'more))
7606     (let ((th threads))
7607       (while th
7608         (setcar th (gnus-cut-thread (car th)))
7609         (setq th (cdr th)))))
7610   ;; Remove nixed out threads.
7611   (delq nil threads))
7612
7613 (defun gnus-summary-initial-limit (&optional show-if-empty)
7614   "Figure out what the initial limit is supposed to be on group entry.
7615 This entails weeding out unwanted dormants, low-scored articles,
7616 fetch-old-headers verbiage, and so on."
7617   ;; Most groups have nothing to remove.
7618   (if (or gnus-inhibit-limiting
7619           (and (null gnus-newsgroup-dormant)
7620                (eq gnus-newsgroup-display 'gnus-not-ignore)
7621                (not (eq gnus-fetch-old-headers 'some))
7622                (not (numberp gnus-fetch-old-headers))
7623                (not (eq gnus-fetch-old-headers 'invisible))
7624                (null gnus-summary-expunge-below)
7625                (not (eq gnus-build-sparse-threads 'some))
7626                (not (eq gnus-build-sparse-threads 'more))
7627                (null gnus-thread-expunge-below)
7628                (not gnus-use-nocem)))
7629       ()                                ; Do nothing.
7630     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7631     (setq gnus-newsgroup-limit nil)
7632     (mapatoms
7633      (lambda (node)
7634        (unless (car (symbol-value node))
7635          ;; These threads have no parents -- they are roots.
7636          (let ((nodes (cdr (symbol-value node)))
7637                thread)
7638            (while nodes
7639              (if (and gnus-thread-expunge-below
7640                       (< (gnus-thread-total-score (car nodes))
7641                          gnus-thread-expunge-below))
7642                  (gnus-expunge-thread (pop nodes))
7643                (setq thread (pop nodes))
7644                (gnus-summary-limit-children thread))))))
7645      gnus-newsgroup-dependencies)
7646     ;; If this limitation resulted in an empty group, we might
7647     ;; pop the previous limit and use it instead.
7648     (when (and (not gnus-newsgroup-limit)
7649                show-if-empty)
7650       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7651     gnus-newsgroup-limit))
7652
7653 (defun gnus-summary-limit-children (thread)
7654   "Return 1 if this subthread is visible and 0 if it is not."
7655   ;; First we get the number of visible children to this thread.  This
7656   ;; is done by recursing down the thread using this function, so this
7657   ;; will really go down to a leaf article first, before slowly
7658   ;; working its way up towards the root.
7659   (when thread
7660     (let ((children
7661            (if (cdr thread)
7662                (apply '+ (mapcar 'gnus-summary-limit-children
7663                                  (cdr thread)))
7664              0))
7665           (number (mail-header-number (car thread)))
7666           score)
7667       (if (and
7668            (not (memq number gnus-newsgroup-marked))
7669            (or
7670             ;; If this article is dormant and has absolutely no visible
7671             ;; children, then this article isn't visible.
7672             (and (memq number gnus-newsgroup-dormant)
7673                  (zerop children))
7674             ;; If this is "fetch-old-headered" and there is no
7675             ;; visible children, then we don't want this article.
7676             (and (or (eq gnus-fetch-old-headers 'some)
7677                      (numberp gnus-fetch-old-headers))
7678                  (gnus-summary-article-ancient-p number)
7679                  (zerop children))
7680             ;; If this is "fetch-old-headered" and `invisible', then
7681             ;; we don't want this article.
7682             (and (eq gnus-fetch-old-headers 'invisible)
7683                  (gnus-summary-article-ancient-p number))
7684             ;; If this is a sparsely inserted article with no children,
7685             ;; we don't want it.
7686             (and (eq gnus-build-sparse-threads 'some)
7687                  (gnus-summary-article-sparse-p number)
7688                  (zerop children))
7689             ;; If we use expunging, and this article is really
7690             ;; low-scored, then we don't want this article.
7691             (when (and gnus-summary-expunge-below
7692                        (< (setq score
7693                                 (or (cdr (assq number gnus-newsgroup-scored))
7694                                     gnus-summary-default-score))
7695                           gnus-summary-expunge-below))
7696               ;; We increase the expunge-tally here, but that has
7697               ;; nothing to do with the limits, really.
7698               (incf gnus-newsgroup-expunged-tally)
7699               ;; We also mark as read here, if that's wanted.
7700               (when (and gnus-summary-mark-below
7701                          (< score gnus-summary-mark-below))
7702                 (setq gnus-newsgroup-unreads
7703                       (delq number gnus-newsgroup-unreads))
7704                 (if gnus-newsgroup-auto-expire
7705                     (push number gnus-newsgroup-expirable)
7706                   (push (cons number gnus-low-score-mark)
7707                         gnus-newsgroup-reads)))
7708               t)
7709             ;; Do the `display' group parameter.
7710             (and gnus-newsgroup-display
7711                  (not (funcall gnus-newsgroup-display)))
7712             ;; Check NoCeM things.
7713             (if (and gnus-use-nocem
7714                      (gnus-nocem-unwanted-article-p
7715                       (mail-header-id (car thread))))
7716                 (progn
7717                   (setq gnus-newsgroup-unreads
7718                         (delq number gnus-newsgroup-unreads))
7719                   t))))
7720           ;; Nope, invisible article.
7721           0
7722         ;; Ok, this article is to be visible, so we add it to the limit
7723         ;; and return 1.
7724         (push number gnus-newsgroup-limit)
7725         1))))
7726
7727 (defun gnus-expunge-thread (thread)
7728   "Mark all articles in THREAD as read."
7729   (let* ((number (mail-header-number (car thread))))
7730     (incf gnus-newsgroup-expunged-tally)
7731     ;; We also mark as read here, if that's wanted.
7732     (setq gnus-newsgroup-unreads
7733           (delq number gnus-newsgroup-unreads))
7734     (if gnus-newsgroup-auto-expire
7735         (push number gnus-newsgroup-expirable)
7736       (push (cons number gnus-low-score-mark)
7737             gnus-newsgroup-reads)))
7738   ;; Go recursively through all subthreads.
7739   (mapcar 'gnus-expunge-thread (cdr thread)))
7740
7741 ;; Summary article oriented commands
7742
7743 (defun gnus-summary-refer-parent-article (n)
7744   "Refer parent article N times.
7745 If N is negative, go to ancestor -N instead.
7746 The difference between N and the number of articles fetched is returned."
7747   (interactive "p")
7748   (let ((skip 1)
7749         error header ref)
7750     (when (not (natnump n))
7751       (setq skip (abs n)
7752             n 1))
7753     (while (and (> n 0)
7754                 (not error))
7755       (setq header (gnus-summary-article-header))
7756       (if (and (eq (mail-header-number header)
7757                    (cdr gnus-article-current))
7758                (equal gnus-newsgroup-name
7759                       (car gnus-article-current)))
7760           ;; If we try to find the parent of the currently
7761           ;; displayed article, then we take a look at the actual
7762           ;; References header, since this is slightly more
7763           ;; reliable than the References field we got from the
7764           ;; server.
7765           (save-excursion
7766             (set-buffer gnus-original-article-buffer)
7767             (nnheader-narrow-to-headers)
7768             (unless (setq ref (message-fetch-field "references"))
7769               (setq ref (message-fetch-field "in-reply-to")))
7770             (widen))
7771         (setq ref
7772               ;; It's not the current article, so we take a bet on
7773               ;; the value we got from the server.
7774               (mail-header-references header)))
7775       (if (and ref
7776                (not (equal ref "")))
7777           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7778             (gnus-message 1 "Couldn't find parent"))
7779         (gnus-message 1 "No references in article %d"
7780                       (gnus-summary-article-number))
7781         (setq error t))
7782       (decf n))
7783     (gnus-summary-position-point)
7784     n))
7785
7786 (defun gnus-summary-refer-references ()
7787   "Fetch all articles mentioned in the References header.
7788 Return the number of articles fetched."
7789   (interactive)
7790   (let ((ref (mail-header-references (gnus-summary-article-header)))
7791         (current (gnus-summary-article-number))
7792         (n 0))
7793     (if (or (not ref)
7794             (equal ref ""))
7795         (error "No References in the current article")
7796       ;; For each Message-ID in the References header...
7797       (while (string-match "<[^>]*>" ref)
7798         (incf n)
7799         ;; ... fetch that article.
7800         (gnus-summary-refer-article
7801          (prog1 (match-string 0 ref)
7802            (setq ref (substring ref (match-end 0))))))
7803       (gnus-summary-goto-subject current)
7804       (gnus-summary-position-point)
7805       n)))
7806
7807 (defun gnus-summary-refer-thread (&optional limit)
7808   "Fetch all articles in the current thread.
7809 If LIMIT (the numerical prefix), fetch that many old headers instead
7810 of what's specified by the `gnus-refer-thread-limit' variable."
7811   (interactive "P")
7812   (let ((id (mail-header-id (gnus-summary-article-header)))
7813         (limit (if limit (prefix-numeric-value limit)
7814                  gnus-refer-thread-limit)))
7815     ;; We want to fetch LIMIT *old* headers, but we also have to
7816     ;; re-fetch all the headers in the current buffer, because many of
7817     ;; them may be undisplayed.  So we adjust LIMIT.
7818     (when (numberp limit)
7819       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7820     (unless (eq gnus-fetch-old-headers 'invisible)
7821       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7822       ;; Retrieve the headers and read them in.
7823       (if (eq (gnus-retrieve-headers
7824                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7825               'nov)
7826           (gnus-build-all-threads)
7827         (error "Can't fetch thread from backends that don't support NOV"))
7828       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7829     (gnus-summary-limit-include-thread id)))
7830
7831 (defun gnus-summary-refer-article (message-id)
7832   "Fetch an article specified by MESSAGE-ID."
7833   (interactive "sMessage-ID: ")
7834   (when (and (stringp message-id)
7835              (not (zerop (length message-id))))
7836     ;; Construct the correct Message-ID if necessary.
7837     ;; Suggested by tale@pawl.rpi.edu.
7838     (unless (string-match "^<" message-id)
7839       (setq message-id (concat "<" message-id)))
7840     (unless (string-match ">$" message-id)
7841       (setq message-id (concat message-id ">")))
7842     (let* ((header (gnus-id-to-header message-id))
7843            (sparse (and header
7844                         (gnus-summary-article-sparse-p
7845                          (mail-header-number header))
7846                         (memq (mail-header-number header)
7847                               gnus-newsgroup-limit)))
7848            number)
7849       (cond
7850        ;; If the article is present in the buffer we just go to it.
7851        ((and header
7852              (or (not (gnus-summary-article-sparse-p
7853                        (mail-header-number header)))
7854                  sparse))
7855         (prog1
7856             (gnus-summary-goto-article
7857              (mail-header-number header) nil t)
7858           (when sparse
7859             (gnus-summary-update-article (mail-header-number header)))))
7860        (t
7861         ;; We fetch the article.
7862         (catch 'found
7863           (dolist (gnus-override-method (gnus-refer-article-methods))
7864             (gnus-check-server gnus-override-method)
7865             ;; Fetch the header, and display the article.
7866             (when (setq number (gnus-summary-insert-subject message-id))
7867               (gnus-summary-select-article nil nil nil number)
7868               (throw 'found t)))
7869           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7870
7871 (defun gnus-refer-article-methods ()
7872   "Return a list of referrable methods."
7873   (cond
7874    ;; No method, so we default to current and native.
7875    ((null gnus-refer-article-method)
7876     (list gnus-current-select-method gnus-select-method))
7877    ;; Current.
7878    ((eq 'current gnus-refer-article-method)
7879     (list gnus-current-select-method))
7880    ;; List of select methods.
7881    ((not (and (symbolp (car gnus-refer-article-method))
7882               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7883     (let (out)
7884       (dolist (method gnus-refer-article-method)
7885         (push (if (eq 'current method)
7886                   gnus-current-select-method
7887                 method)
7888               out))
7889       (nreverse out)))
7890    ;; One single select method.
7891    (t
7892     (list gnus-refer-article-method))))
7893
7894 (defun gnus-summary-edit-parameters ()
7895   "Edit the group parameters of the current group."
7896   (interactive)
7897   (gnus-group-edit-group gnus-newsgroup-name 'params))
7898
7899 (defun gnus-summary-customize-parameters ()
7900   "Customize the group parameters of the current group."
7901   (interactive)
7902   (gnus-group-customize gnus-newsgroup-name))
7903
7904 (defun gnus-summary-enter-digest-group (&optional force)
7905   "Enter an nndoc group based on the current article.
7906 If FORCE, force a digest interpretation.  If not, try
7907 to guess what the document format is."
7908   (interactive "P")
7909   (let ((conf gnus-current-window-configuration))
7910     (save-excursion
7911       (gnus-summary-select-article))
7912     (setq gnus-current-window-configuration conf)
7913     (let* ((name (format "%s-%d"
7914                          (gnus-group-prefixed-name
7915                           gnus-newsgroup-name (list 'nndoc ""))
7916                          (save-excursion
7917                            (set-buffer gnus-summary-buffer)
7918                            gnus-current-article)))
7919            (ogroup gnus-newsgroup-name)
7920            (params (append (gnus-info-params (gnus-get-info ogroup))
7921                            (list (cons 'to-group ogroup))
7922                            (list (cons 'save-article-group ogroup))))
7923            (case-fold-search t)
7924            (buf (current-buffer))
7925            dig to-address)
7926       (save-excursion
7927         (set-buffer gnus-original-article-buffer)
7928         ;; Have the digest group inherit the main mail address of
7929         ;; the parent article.
7930         (when (setq to-address (or (gnus-fetch-field "reply-to")
7931                                    (gnus-fetch-field "from")))
7932           (setq params (append
7933                         (list (cons 'to-address
7934                                     (funcall gnus-decode-encoded-word-function
7935                                              to-address))))))
7936         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7937         (insert-buffer-substring gnus-original-article-buffer)
7938         ;; Remove lines that may lead nndoc to misinterpret the
7939         ;; document type.
7940         (narrow-to-region
7941          (goto-char (point-min))
7942          (or (search-forward "\n\n" nil t) (point)))
7943         (goto-char (point-min))
7944         (delete-matching-lines "^Path:\\|^From ")
7945         (widen))
7946       (unwind-protect
7947           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7948                     (gnus-newsgroup-ephemeral-ignored-charsets
7949                      gnus-newsgroup-ignored-charsets))
7950                 (gnus-group-read-ephemeral-group
7951                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7952                               (nndoc-article-type
7953                                ,(if force 'mbox 'guess)))
7954                  t nil nil nil
7955                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7956                                                         "ADAPT")))))
7957               ;; Make all postings to this group go to the parent group.
7958               (nconc (gnus-info-params (gnus-get-info name))
7959                      params)
7960             ;; Couldn't select this doc group.
7961             (switch-to-buffer buf)
7962             (gnus-set-global-variables)
7963             (gnus-configure-windows 'summary)
7964             (gnus-message 3 "Article couldn't be entered?"))
7965         (kill-buffer dig)))))
7966
7967 (defun gnus-summary-read-document (n)
7968   "Open a new group based on the current article(s).
7969 This will allow you to read digests and other similar
7970 documents as newsgroups.
7971 Obeys the standard process/prefix convention."
7972   (interactive "P")
7973   (let* ((articles (gnus-summary-work-articles n))
7974          (ogroup gnus-newsgroup-name)
7975          (params (append (gnus-info-params (gnus-get-info ogroup))
7976                          (list (cons 'to-group ogroup))))
7977          article group egroup groups vgroup)
7978     (while (setq article (pop articles))
7979       (setq group (format "%s-%d" gnus-newsgroup-name article))
7980       (gnus-summary-remove-process-mark article)
7981       (when (gnus-summary-display-article article)
7982         (save-excursion
7983           (with-temp-buffer
7984             (insert-buffer-substring gnus-original-article-buffer)
7985             ;; Remove some headers that may lead nndoc to make
7986             ;; the wrong guess.
7987             (message-narrow-to-head)
7988             (goto-char (point-min))
7989             (delete-matching-lines "^\\(Path\\):\\|^From ")
7990             (widen)
7991             (if (setq egroup
7992                       (gnus-group-read-ephemeral-group
7993                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7994                                      (nndoc-article-type guess))
7995                        t nil t))
7996                 (progn
7997                   ;; Make all postings to this group go to the parent group.
7998                   (nconc (gnus-info-params (gnus-get-info egroup))
7999                          params)
8000                   (push egroup groups))
8001               ;; Couldn't select this doc group.
8002               (gnus-error 3 "Article couldn't be entered"))))))
8003     ;; Now we have selected all the documents.
8004     (cond
8005      ((not groups)
8006       (error "None of the articles could be interpreted as documents"))
8007      ((gnus-group-read-ephemeral-group
8008        (setq vgroup (format
8009                      "nnvirtual:%s-%s" gnus-newsgroup-name
8010                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8011        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8012        t
8013        (cons (current-buffer) 'summary)))
8014      (t
8015       (error "Couldn't select virtual nndoc group")))))
8016
8017 (defun gnus-summary-isearch-article (&optional regexp-p)
8018   "Do incremental search forward on the current article.
8019 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8020   (interactive "P")
8021   (let* ((gnus-inhibit-treatment t)
8022          (old (gnus-summary-select-article)))
8023     (gnus-configure-windows 'article)
8024     (gnus-eval-in-buffer-window gnus-article-buffer
8025       (save-restriction
8026         (widen)
8027         (when (eq 'old old)
8028           (gnus-article-show-all-headers))
8029         (goto-char (point-min))
8030         (isearch-forward regexp-p)))))
8031
8032 (defun gnus-summary-search-article-forward (regexp &optional backward)
8033   "Search for an article containing REGEXP forward.
8034 If BACKWARD, search backward instead."
8035   (interactive
8036    (list (read-string
8037           (format "Search article %s (regexp%s): "
8038                   (if current-prefix-arg "backward" "forward")
8039                   (if gnus-last-search-regexp
8040                       (concat ", default " gnus-last-search-regexp)
8041                     "")))
8042          current-prefix-arg))
8043   (if (string-equal regexp "")
8044       (setq regexp (or gnus-last-search-regexp ""))
8045     (setq gnus-last-search-regexp regexp)
8046     (setq gnus-article-before-search gnus-current-article))
8047   ;; Intentionally set gnus-last-article.
8048   (setq gnus-last-article gnus-article-before-search)
8049   (let ((gnus-last-article gnus-last-article))
8050     (if (gnus-summary-search-article regexp backward)
8051         (gnus-summary-show-thread)
8052       (error "Search failed: \"%s\"" regexp))))
8053
8054 (defun gnus-summary-search-article-backward (regexp)
8055   "Search for an article containing REGEXP backward."
8056   (interactive
8057    (list (read-string
8058           (format "Search article backward (regexp%s): "
8059                   (if gnus-last-search-regexp
8060                       (concat ", default " gnus-last-search-regexp)
8061                     "")))))
8062   (gnus-summary-search-article-forward regexp 'backward))
8063
8064 (eval-when-compile
8065   (defmacro gnus-summary-search-article-position-point (regexp backward)
8066     "Dehighlight the last matched text and goto the beginning position."
8067     (` (if (and gnus-summary-search-article-matched-data
8068                 (let ((text (caddr gnus-summary-search-article-matched-data))
8069                       (inhibit-read-only t)
8070                       buffer-read-only)
8071                   (delete-region
8072                    (goto-char (car gnus-summary-search-article-matched-data))
8073                    (cadr gnus-summary-search-article-matched-data))
8074                   (insert text)
8075                   (string-match (, regexp) text)))
8076            (if (, backward) (beginning-of-line) (end-of-line))
8077          (goto-char (if (, backward) (point-max) (point-min))))))
8078
8079   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8080     "Place point where X-Face image is displayed."
8081     (if (featurep 'xemacs)
8082         (` (let ((end (if (search-forward "\n\n" nil t)
8083                           (goto-char (1- (point)))
8084                         (point-min)))
8085                  extent)
8086              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8087              (unless (and (re-search-forward "^From:" end t)
8088                           (setq extent (extent-at (point)))
8089                           (extent-begin-glyph extent))
8090                (goto-char (, opoint)))))
8091       (` (let ((end (if (search-forward "\n\n" nil t)
8092                         (goto-char (1- (point)))
8093                       (point-min)))
8094                (start (or (search-backward "\n\n" nil t) (point-min))))
8095            (goto-char
8096             (or (text-property-any start end 'x-face-image t);; x-face-e21
8097                 (text-property-any start end 'x-face-mule-bitmap-image t)
8098                 (, opoint)))))))
8099
8100   (defmacro gnus-summary-search-article-highlight-matched-text
8101     (backward treated x-face)
8102     "Highlight matched text in the function `gnus-summary-search-article'."
8103     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8104              (end (set-marker (make-marker) (match-end 0)))
8105              (inhibit-read-only t)
8106              buffer-read-only)
8107          (unless treated
8108            (let ((,@
8109                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8110                     (mapcar
8111                      (lambda (item) (setq items (delq item items)))
8112                      '(gnus-treat-buttonize
8113                        gnus-treat-fill-article
8114                        gnus-treat-fill-long-lines
8115                        gnus-treat-emphasize
8116                        gnus-treat-highlight-headers
8117                        gnus-treat-highlight-citation
8118                        gnus-treat-highlight-signature
8119                        gnus-treat-overstrike
8120                        gnus-treat-display-xface
8121                        gnus-treat-buttonize-head
8122                        gnus-treat-decode-article-as-default-mime-charset))
8123                     (static-if (featurep 'xemacs)
8124                         items
8125                       (cons '(x-face-mule-delete-x-face-field
8126                               (quote never))
8127                             items))))
8128                  (gnus-treat-display-xface
8129                   (when (, x-face) gnus-treat-display-xface)))
8130              (gnus-article-prepare-mime-display)))
8131          (goto-char (if (, backward) start end))
8132          (when (, x-face)
8133            (gnus-summary-search-article-highlight-goto-x-face (point)))
8134          (setq gnus-summary-search-article-matched-data
8135                (list start end (buffer-substring start end)))
8136          (unless (eq start end);; matched text has been deleted. :-<
8137            (put-text-property start end 'face
8138                               (or (find-face 'isearch)
8139                                   'secondary-selection))))))
8140   )
8141
8142 (defun gnus-summary-search-article (regexp &optional backward)
8143   "Search for an article containing REGEXP.
8144 Optional argument BACKWARD means do search for backward.
8145 `gnus-select-article-hook' is not called during the search."
8146   ;; We have to require this here to make sure that the following
8147   ;; dynamic binding isn't shadowed by autoloading.
8148   (require 'gnus-async)
8149   (require 'gnus-art)
8150   (let ((gnus-select-article-hook nil)  ;Disable hook.
8151         (gnus-article-prepare-hook nil)
8152         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8153         (gnus-use-article-prefetch nil)
8154         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8155         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8156         (sum (current-buffer))
8157         (found nil)
8158         point treated)
8159     (gnus-save-hidden-threads
8160       (static-if (featurep 'xemacs)
8161           (let ((gnus-inhibit-treatment t))
8162             (setq treated (eq 'old (gnus-summary-select-article)))
8163             (when (and treated
8164                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8165                                  (window-live-p (get-buffer-window
8166                                                  gnus-article-buffer t)))))
8167               (gnus-summary-select-article nil t)
8168               (setq treated nil)))
8169         (let ((gnus-inhibit-treatment t)
8170               (x-face-mule-delete-x-face-field 'never))
8171           (setq treated (eq 'old (gnus-summary-select-article)))
8172           (when (and treated
8173                      (not
8174                       (and (gnus-buffer-live-p gnus-article-buffer)
8175                            (window-live-p (get-buffer-window
8176                                            gnus-article-buffer t))
8177                            (or (not (string-match "^\\^X-Face:" regexp))
8178                                (with-current-buffer gnus-article-buffer
8179                                  gnus-summary-search-article-matched-data)))))
8180             (gnus-summary-select-article nil t)
8181             (setq treated nil))))
8182       (set-buffer gnus-article-buffer)
8183       (widen)
8184       (if treated
8185           (progn
8186             (gnus-article-show-all-headers)
8187             (gnus-summary-search-article-position-point regexp backward))
8188         (goto-char (if backward (point-max) (point-min))))
8189       (while (not found)
8190         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8191         (if (if backward
8192                 (re-search-backward regexp nil t)
8193               (re-search-forward regexp nil t))
8194             ;; We found the regexp.
8195             (progn
8196               (gnus-summary-search-article-highlight-matched-text
8197                backward treated (string-match "^\\^X-Face:" regexp))
8198               (setq found 'found)
8199               (forward-line
8200                (/ (- 2 (window-height
8201                         (get-buffer-window gnus-article-buffer t)))
8202                   2))
8203               (set-window-start
8204                (get-buffer-window (current-buffer))
8205                (point))
8206               (set-buffer sum)
8207               (setq point (point)))
8208           ;; We didn't find it, so we go to the next article.
8209           (set-buffer sum)
8210           (setq found 'not)
8211           (while (eq found 'not)
8212             (if (not (if backward (gnus-summary-find-prev)
8213                        (gnus-summary-find-next)))
8214                 ;; No more articles.
8215                 (setq found t)
8216               ;; Select the next article and adjust point.
8217               (unless (gnus-summary-article-sparse-p
8218                        (gnus-summary-article-number))
8219                 (setq found nil)
8220                 (let ((gnus-inhibit-treatment t))
8221                   (gnus-summary-select-article))
8222                 (setq treated nil)
8223                 (set-buffer gnus-article-buffer)
8224                 (widen)
8225                 (goto-char (if backward (point-max) (point-min))))))))
8226       (gnus-message 7 ""))
8227     ;; Return whether we found the regexp.
8228     (when (eq found 'found)
8229       (goto-char point)
8230       (gnus-summary-show-thread)
8231       (gnus-summary-goto-subject gnus-current-article)
8232       (gnus-summary-position-point)
8233       t)))
8234
8235 (defun gnus-find-matching-articles (header regexp)
8236   "Return a list of all articles that match REGEXP on HEADER.
8237 This search includes all articles in the current group that Gnus has
8238 fetched headers for, whether they are displayed or not."
8239   (let ((articles nil)
8240         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8241         (case-fold-search t))
8242     (dolist (header gnus-newsgroup-headers)
8243       (when (string-match regexp (funcall func header))
8244         (push (mail-header-number header) articles)))
8245     (nreverse articles)))
8246
8247 (defun gnus-summary-find-matching (header regexp &optional backward unread
8248                                           not-case-fold not-matching)
8249   "Return a list of all articles that match REGEXP on HEADER.
8250 The search stars on the current article and goes forwards unless
8251 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8252 If UNREAD is non-nil, only unread articles will
8253 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8254 in the comparisons. If NOT-MATCHING, return a list of all articles that
8255 not match REGEXP on HEADER."
8256   (let ((case-fold-search (not not-case-fold))
8257         articles d func)
8258     (if (consp header)
8259         (if (eq (car header) 'extra)
8260             (setq func
8261                   `(lambda (h)
8262                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8263                          "")))
8264           (error "%s is an invalid header" header))
8265       (unless (fboundp (intern (concat "mail-header-" header)))
8266         (error "%s is not a valid header" header))
8267       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8268     (dolist (d (if (eq backward 'all)
8269                    gnus-newsgroup-data
8270                  (gnus-data-find-list
8271                   (gnus-summary-article-number)
8272                   (gnus-data-list backward))))
8273       (when (and (or (not unread)       ; We want all articles...
8274                      (gnus-data-unread-p d)) ; Or just unreads.
8275                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8276                  (if not-matching
8277                      (not (string-match
8278                            regexp
8279                            (funcall func (gnus-data-header d))))
8280                    (string-match regexp
8281                                  (funcall func (gnus-data-header d)))))
8282         (push (gnus-data-number d) articles))) ; Success!
8283     (nreverse articles)))
8284
8285 (defun gnus-summary-execute-command (header regexp command &optional backward)
8286   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8287 If HEADER is an empty string (or nil), the match is done on the entire
8288 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8289   (interactive
8290    (list (let ((completion-ignore-case t))
8291            (completing-read
8292             "Header name: "
8293             (mapcar (lambda (header) (list (format "%s" header)))
8294                     (append
8295                      '("Number" "Subject" "From" "Lines" "Date"
8296                        "Message-ID" "Xref" "References" "Body")
8297                      gnus-extra-headers))
8298             nil 'require-match))
8299          (read-string "Regexp: ")
8300          (read-key-sequence "Command: ")
8301          current-prefix-arg))
8302   (when (equal header "Body")
8303     (setq header ""))
8304   ;; Hidden thread subtrees must be searched as well.
8305   (gnus-summary-show-all-threads)
8306   ;; We don't want to change current point nor window configuration.
8307   (save-excursion
8308     (save-window-excursion
8309       (gnus-message 6 "Executing %s..." (key-description command))
8310       ;; We'd like to execute COMMAND interactively so as to give arguments.
8311       (gnus-execute header regexp
8312                     `(call-interactively ',(key-binding command))
8313                     backward)
8314       (gnus-message 6 "Executing %s...done" (key-description command)))))
8315
8316 (defun gnus-summary-beginning-of-article ()
8317   "Scroll the article back to the beginning."
8318   (interactive)
8319   (gnus-summary-select-article)
8320   (gnus-configure-windows 'article)
8321   (gnus-eval-in-buffer-window gnus-article-buffer
8322     (widen)
8323     (goto-char (point-min))
8324     (when gnus-page-broken
8325       (gnus-narrow-to-page))))
8326
8327 (defun gnus-summary-end-of-article ()
8328   "Scroll to the end of the article."
8329   (interactive)
8330   (gnus-summary-select-article)
8331   (gnus-configure-windows 'article)
8332   (gnus-eval-in-buffer-window gnus-article-buffer
8333     (widen)
8334     (goto-char (point-max))
8335     (recenter -3)
8336     (when gnus-page-broken
8337       (gnus-narrow-to-page))))
8338
8339 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8340   "Truncate to LEN and quote all \"(\"'s in STRING."
8341   (gnus-replace-in-string (if (and len (> (length string) len))
8342                               (substring string 0 len)
8343                             string)
8344                           "[()]" "\\\\\\&"))
8345
8346 (defun gnus-summary-print-article (&optional filename n)
8347   "Generate and print a PostScript image of the N next (mail) articles.
8348
8349 If N is negative, print the N previous articles.  If N is nil and articles
8350 have been marked with the process mark, print these instead.
8351
8352 If the optional first argument FILENAME is nil, send the image to the
8353 printer.  If FILENAME is a string, save the PostScript image in a file with
8354 that name.  If FILENAME is a number, prompt the user for the name of the file
8355 to save in."
8356   (interactive (list (ps-print-preprint current-prefix-arg)))
8357   (dolist (article (gnus-summary-work-articles n))
8358     (gnus-summary-select-article nil nil 'pseudo article)
8359     (gnus-eval-in-buffer-window gnus-article-buffer
8360       (gnus-print-buffer))
8361     (gnus-summary-remove-process-mark article))
8362   (ps-despool filename))
8363
8364 (defun gnus-print-buffer ()
8365   (let ((buffer (generate-new-buffer " *print*")))
8366     (unwind-protect
8367         (progn
8368           (copy-to-buffer buffer (point-min) (point-max))
8369           (set-buffer buffer)
8370           (gnus-article-delete-invisible-text)
8371           (gnus-remove-text-with-property 'gnus-decoration)
8372           (when (gnus-visual-p 'article-highlight 'highlight)
8373             ;; Copy-to-buffer doesn't copy overlay.  So redo
8374             ;; highlight.
8375             (let ((gnus-article-buffer buffer))
8376               (gnus-article-highlight-citation t)
8377               (gnus-article-highlight-signature)))
8378           (let ((ps-left-header
8379                  (list
8380                   (concat "("
8381                           (gnus-summary-print-truncate-and-quote
8382                            (mail-header-subject gnus-current-headers)
8383                            66) ")")
8384                   (concat "("
8385                           (gnus-summary-print-truncate-and-quote
8386                            (mail-header-from gnus-current-headers)
8387                            45) ")")))
8388                 (ps-right-header
8389                  (list
8390                   "/pagenumberstring load"
8391                   (concat "("
8392                           (mail-header-date gnus-current-headers) ")"))))
8393             (gnus-run-hooks 'gnus-ps-print-hook)
8394             (save-excursion
8395               (if window-system
8396                   (ps-spool-buffer-with-faces)
8397                 (ps-spool-buffer)))))
8398       (kill-buffer buffer))))
8399
8400 (defun gnus-summary-show-article (&optional arg)
8401   "Force redisplaying of the current article.
8402 If ARG (the prefix) is a number, show the article with the charset
8403 defined in `gnus-summary-show-article-charset-alist', or the charset
8404 input.
8405 If ARG (the prefix) is non-nil and not a number, show the raw article
8406 without any article massaging functions being run.  Normally, the key strokes
8407 are `C-u g'."
8408   (interactive "P")
8409   (cond
8410    ((numberp arg)
8411     (gnus-summary-show-article t)
8412     (let* ((gnus-newsgroup-charset
8413             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8414                 (mm-read-coding-system
8415                  "View as charset: " ;; actually it is coding system.
8416                  (save-excursion
8417                    (set-buffer gnus-article-buffer)
8418                    (mm-detect-coding-region (point) (point-max))))))
8419            (default-mime-charset gnus-newsgroup-charset)
8420            (gnus-newsgroup-ignored-charsets 'gnus-all))
8421       (gnus-summary-select-article nil 'force)
8422       (let ((deps gnus-newsgroup-dependencies)
8423             head header lines)
8424         (save-excursion
8425           (set-buffer gnus-original-article-buffer)
8426           (save-restriction
8427             (message-narrow-to-head)
8428             (setq head (buffer-string))
8429             (goto-char (point-min))
8430             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8431               (goto-char (point-max))
8432               (widen)
8433               (setq lines (1- (count-lines (point) (point-max))))))
8434           (with-temp-buffer
8435             (insert (format "211 %d Article retrieved.\n"
8436                             (cdr gnus-article-current)))
8437             (insert head)
8438             (if lines (insert (format "Lines: %d\n" lines)))
8439             (insert ".\n")
8440             (let ((nntp-server-buffer (current-buffer)))
8441               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8442         (gnus-data-set-header
8443          (gnus-data-find (cdr gnus-article-current))
8444          header)
8445         (gnus-summary-update-article-line
8446          (cdr gnus-article-current) header)
8447         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8448           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8449    ((not arg)
8450     ;; Select the article the normal way.
8451     (gnus-summary-select-article nil 'force))
8452    (t
8453     ;; We have to require this here to make sure that the following
8454     ;; dynamic binding isn't shadowed by autoloading.
8455     (require 'gnus-async)
8456     (require 'gnus-art)
8457     ;; Bind the article treatment functions to nil.
8458     (let ((gnus-have-all-headers t)
8459           gnus-article-prepare-hook
8460           gnus-article-decode-hook
8461           gnus-break-pages
8462           gnus-show-mime
8463           (gnus-inhibit-treatment t))
8464       (gnus-summary-select-article nil 'force))))
8465   (gnus-summary-goto-subject gnus-current-article)
8466   (gnus-summary-position-point))
8467
8468 (defun gnus-summary-show-raw-article ()
8469   "Show the raw article without any article massaging functions being run."
8470   (interactive)
8471   (gnus-summary-show-article t))
8472
8473 (defun gnus-summary-verbose-headers (&optional arg)
8474   "Toggle permanent full header display.
8475 If ARG is a positive number, turn header display on.
8476 If ARG is a negative number, turn header display off."
8477   (interactive "P")
8478   (setq gnus-show-all-headers
8479         (cond ((or (not (numberp arg))
8480                    (zerop arg))
8481                (not gnus-show-all-headers))
8482               ((natnump arg)
8483                t)))
8484   (gnus-summary-show-article))
8485
8486 (defun gnus-summary-toggle-header (&optional arg)
8487   "Show the headers if they are hidden, or hide them if they are shown.
8488 If ARG is a positive number, show the entire header.
8489 If ARG is a negative number, hide the unwanted header lines."
8490   (interactive "P")
8491   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8492                      (get-buffer-window gnus-article-buffer t))))
8493     (with-current-buffer gnus-article-buffer
8494       (widen)
8495       (article-narrow-to-head)
8496       (let* ((buffer-read-only nil)
8497              (inhibit-point-motion-hooks t)
8498              (hidden (if (numberp arg)
8499                          (>= arg 0)
8500                        (gnus-article-hidden-text-p 'headers)))
8501              s e)
8502         (delete-region (point-min) (point-max))
8503         (with-current-buffer gnus-original-article-buffer
8504           (goto-char (setq s (point-min)))
8505           (setq e (if (search-forward "\n\n" nil t)
8506                       (1- (point))
8507                     (point-max))))
8508         (insert-buffer-substring gnus-original-article-buffer s e)
8509         (article-decode-encoded-words)
8510         (if hidden
8511             (let ((gnus-treat-hide-headers nil)
8512                   (gnus-treat-hide-boring-headers nil))
8513               (gnus-delete-wash-type 'headers)
8514               (gnus-treat-article 'head))
8515           (gnus-treat-article 'head))
8516         (widen)
8517         (if window
8518             (set-window-start window (goto-char (point-min))))
8519         (setq gnus-page-broken
8520               (when gnus-break-pages
8521                 (gnus-narrow-to-page)
8522                 t))
8523         (gnus-set-mode-line 'article)))))
8524
8525 (defun gnus-summary-show-all-headers ()
8526   "Make all header lines visible."
8527   (interactive)
8528   (gnus-summary-toggle-header 1))
8529
8530 (defun gnus-summary-toggle-mime (&optional arg)
8531   "Toggle MIME processing.
8532 If ARG is a positive number, turn MIME processing on."
8533   (interactive "P")
8534   (setq gnus-show-mime
8535         (if (null arg)
8536             (not gnus-show-mime)
8537           (> (prefix-numeric-value arg) 0)))
8538   (gnus-summary-select-article t 'force))
8539
8540 (defun gnus-summary-caesar-message (&optional arg)
8541   "Caesar rotate the current article by 13.
8542 The numerical prefix specifies how many places to rotate each letter
8543 forward."
8544   (interactive "P")
8545   (gnus-summary-select-article)
8546   (let ((mail-header-separator ""))
8547     (gnus-eval-in-buffer-window gnus-article-buffer
8548       (save-restriction
8549         (widen)
8550         (let ((start (window-start))
8551               buffer-read-only)
8552           (message-caesar-buffer-body arg)
8553           (set-window-start (get-buffer-window (current-buffer)) start))))))
8554
8555 (defun gnus-summary-stop-page-breaking ()
8556   "Stop page breaking in the current article."
8557   (interactive)
8558   (gnus-summary-select-article)
8559   (gnus-eval-in-buffer-window gnus-article-buffer
8560     (widen)
8561     (when (gnus-visual-p 'page-marker)
8562       (let ((buffer-read-only nil))
8563         (gnus-remove-text-with-property 'gnus-prev)
8564         (gnus-remove-text-with-property 'gnus-next))
8565       (setq gnus-page-broken nil))))
8566
8567 (defun gnus-summary-move-article (&optional n to-newsgroup
8568                                             select-method action)
8569   "Move the current article to a different newsgroup.
8570 If N is a positive number, move the N next articles.
8571 If N is a negative number, move the N previous articles.
8572 If N is nil and any articles have been marked with the process mark,
8573 move those articles instead.
8574 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8575 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8576 re-spool using this method.
8577
8578 When called interactively with TO-NEWSGROUP being nil, the value of
8579 the variable `gnus-move-split-methods' is used for finding a default
8580 for the target newsgroup.
8581
8582 For this function to work, both the current newsgroup and the
8583 newsgroup that you want to move to have to support the `request-move'
8584 and `request-accept' functions.
8585
8586 ACTION can be either `move' (the default), `crosspost' or `copy'."
8587   (interactive "P")
8588   (unless action
8589     (setq action 'move))
8590   ;; Check whether the source group supports the required functions.
8591   (cond ((and (eq action 'move)
8592               (not (gnus-check-backend-function
8593                     'request-move-article gnus-newsgroup-name)))
8594          (error "The current group does not support article moving"))
8595         ((and (eq action 'crosspost)
8596               (not (gnus-check-backend-function
8597                     'request-replace-article gnus-newsgroup-name)))
8598          (error "The current group does not support article editing")))
8599   (let ((articles (gnus-summary-work-articles n))
8600         (prefix (if (gnus-check-backend-function
8601                      'request-move-article gnus-newsgroup-name)
8602                     (gnus-group-real-prefix gnus-newsgroup-name)
8603                   ""))
8604         (names '((move "Move" "Moving")
8605                  (copy "Copy" "Copying")
8606                  (crosspost "Crosspost" "Crossposting")))
8607         (copy-buf (save-excursion
8608                     (nnheader-set-temp-buffer " *copy article*")))
8609         (default-marks gnus-article-mark-lists)
8610         (no-expire-marks (delete '(expirable . expire)
8611                                  (copy-sequence gnus-article-mark-lists)))
8612         art-group to-method new-xref article to-groups)
8613     (unless (assq action names)
8614       (error "Unknown action %s" action))
8615     ;; Read the newsgroup name.
8616     (when (and (not to-newsgroup)
8617                (not select-method))
8618       (if (and gnus-move-split-methods
8619                (not
8620                 (and (memq gnus-current-article articles)
8621                      (gnus-buffer-live-p gnus-original-article-buffer))))
8622           ;; When `gnus-move-split-methods' is non-nil, we have to
8623           ;; select an article to give `gnus-read-move-group-name' an
8624           ;; opportunity to suggest an appropriate default.  However,
8625           ;; we needn't render or mark the article.
8626           (let ((gnus-display-mime-function nil)
8627                 (gnus-article-prepare-hook nil)
8628                 (gnus-mark-article-hook nil))
8629             (gnus-summary-select-article nil nil nil (car articles))))
8630       (setq to-newsgroup
8631             (gnus-read-move-group-name
8632              (cadr (assq action names))
8633              (symbol-value (intern (format "gnus-current-%s-group" action)))
8634              articles prefix))
8635       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8636     (setq to-method (or select-method
8637                         (gnus-server-to-method
8638                          (gnus-group-method to-newsgroup))))
8639     ;; Check the method we are to move this article to...
8640     (unless (gnus-check-backend-function
8641              'request-accept-article (car to-method))
8642       (error "%s does not support article copying" (car to-method)))
8643     (unless (gnus-check-server to-method)
8644       (error "Can't open server %s" (car to-method)))
8645     (gnus-message 6 "%s to %s: %s..."
8646                   (caddr (assq action names))
8647                   (or (car select-method) to-newsgroup) articles)
8648     (while articles
8649       (setq article (pop articles))
8650       (setq
8651        art-group
8652        (cond
8653         ;; Move the article.
8654         ((eq action 'move)
8655          ;; Remove this article from future suppression.
8656          (gnus-dup-unsuppress-article article)
8657          (gnus-request-move-article
8658           article                       ; Article to move
8659           gnus-newsgroup-name           ; From newsgroup
8660           (nth 1 (gnus-find-method-for-group
8661                   gnus-newsgroup-name)) ; Server
8662           (list 'gnus-request-accept-article
8663                 to-newsgroup (list 'quote select-method)
8664                 (not articles) t)       ; Accept form
8665           (not articles)))              ; Only save nov last time
8666         ;; Copy the article.
8667         ((eq action 'copy)
8668          (save-excursion
8669            (set-buffer copy-buf)
8670            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8671              (gnus-request-accept-article
8672               to-newsgroup select-method (not articles) t))))
8673         ;; Crosspost the article.
8674         ((eq action 'crosspost)
8675          (let ((xref (message-tokenize-header
8676                       (mail-header-xref (gnus-summary-article-header article))
8677                       " ")))
8678            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8679                                   ":" (number-to-string article)))
8680            (unless xref
8681              (setq xref (list (system-name))))
8682            (setq new-xref
8683                  (concat
8684                   (mapconcat 'identity
8685                              (delete "Xref:" (delete new-xref xref))
8686                              " ")
8687                   " " new-xref))
8688            (save-excursion
8689              (set-buffer copy-buf)
8690              ;; First put the article in the destination group.
8691              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8692              (when (consp (setq art-group
8693                                 (gnus-request-accept-article
8694                                  to-newsgroup select-method (not articles))))
8695                (setq new-xref (concat new-xref " " (car art-group)
8696                                       ":"
8697                                       (number-to-string (cdr art-group))))
8698                ;; Now we have the new Xrefs header, so we insert
8699                ;; it and replace the new article.
8700                (nnheader-replace-header "Xref" new-xref)
8701                (gnus-request-replace-article
8702                 (cdr art-group) to-newsgroup (current-buffer))
8703                art-group))))))
8704       (cond
8705        ((not art-group)
8706         (gnus-message 1 "Couldn't %s article %s: %s"
8707                       (cadr (assq action names)) article
8708                       (nnheader-get-report (car to-method))))
8709        ((eq art-group 'junk)
8710         (when (eq action 'move)
8711           (gnus-summary-mark-article article gnus-canceled-mark)
8712           (gnus-message 4 "Deleted article %s" article)))
8713        (t
8714         (let* ((pto-group (gnus-group-prefixed-name
8715                            (car art-group) to-method))
8716                (entry
8717                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8718                (info (nth 2 entry))
8719                (to-group (gnus-info-group info))
8720                to-marks)
8721           ;; Update the group that has been moved to.
8722           (when (and info
8723                      (memq action '(move copy)))
8724             (unless (member to-group to-groups)
8725               (push to-group to-groups))
8726
8727             (unless (memq article gnus-newsgroup-unreads)
8728               (push 'read to-marks)
8729               (gnus-info-set-read
8730                info (gnus-add-to-range (gnus-info-read info)
8731                                        (list (cdr art-group)))))
8732
8733             ;; See whether the article is to be put in the cache.
8734             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8735                              default-marks
8736                            no-expire-marks))
8737                   (to-article (cdr art-group)))
8738
8739               ;; Enter the article into the cache in the new group,
8740               ;; if that is required.
8741               (when gnus-use-cache
8742                 (gnus-cache-possibly-enter-article
8743                  to-group to-article
8744                  (let ((header (copy-sequence
8745                                 (gnus-summary-article-header article))))
8746                    (mail-header-set-number header to-article)
8747                    header)
8748                  (memq article gnus-newsgroup-marked)
8749                  (memq article gnus-newsgroup-dormant)
8750                  (memq article gnus-newsgroup-unreads)))
8751
8752               (when gnus-preserve-marks
8753                 ;; Copy any marks over to the new group.
8754                 (when (and (equal to-group gnus-newsgroup-name)
8755                            (not (memq article gnus-newsgroup-unreads)))
8756                   ;; Mark this article as read in this group.
8757                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8758                   (setcdr (gnus-active to-group) to-article)
8759                   (setcdr gnus-newsgroup-active to-article))
8760
8761                 (while marks
8762                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8763                     (when (memq article (symbol-value
8764                                          (intern (format "gnus-newsgroup-%s"
8765                                                          (caar marks)))))
8766                       (push (cdar marks) to-marks)
8767                       ;; If the other group is the same as this group,
8768                       ;; then we have to add the mark to the list.
8769                       (when (equal to-group gnus-newsgroup-name)
8770                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8771                              (cons to-article
8772                                    (symbol-value
8773                                     (intern (format "gnus-newsgroup-%s"
8774                                                     (caar marks)))))))
8775                       ;; Copy the marks to other group.
8776                       (gnus-add-marked-articles
8777                        to-group (cdar marks) (list to-article) info)))
8778                   (setq marks (cdr marks)))
8779
8780                 (gnus-request-set-mark to-group (list (list (list to-article)
8781                                                             'add
8782                                                             to-marks))))
8783
8784               (gnus-dribble-enter
8785                (concat "(gnus-group-set-info '"
8786                        (gnus-prin1-to-string (gnus-get-info to-group))
8787                        ")"))))
8788
8789           ;; Update the Xref header in this article to point to
8790           ;; the new crossposted article we have just created.
8791           (when (eq action 'crosspost)
8792             (save-excursion
8793               (set-buffer copy-buf)
8794               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8795               (nnheader-replace-header "Xref" new-xref)
8796               (gnus-request-replace-article
8797                article gnus-newsgroup-name (current-buffer)))))
8798
8799         ;;;!!!Why is this necessary?
8800         (set-buffer gnus-summary-buffer)
8801
8802         (gnus-summary-goto-subject article)
8803         (when (eq action 'move)
8804           (gnus-summary-mark-article article gnus-canceled-mark))))
8805       (gnus-summary-remove-process-mark article))
8806     ;; Re-activate all groups that have been moved to.
8807     (save-excursion
8808       (set-buffer gnus-group-buffer)
8809       (let ((gnus-group-marked to-groups))
8810         (gnus-group-get-new-news-this-group nil t)))
8811
8812     (gnus-kill-buffer copy-buf)
8813     (gnus-summary-position-point)
8814     (gnus-set-mode-line 'summary)))
8815
8816 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8817   "Move the current article to a different newsgroup.
8818 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8819 When called interactively, if TO-NEWSGROUP is nil, use the value of
8820 the variable `gnus-move-split-methods' for finding a default target
8821 newsgroup.
8822 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8823 re-spool using this method."
8824   (interactive "P")
8825   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8826
8827 (defun gnus-summary-crosspost-article (&optional n)
8828   "Crosspost the current article to some other group."
8829   (interactive "P")
8830   (gnus-summary-move-article n nil nil 'crosspost))
8831
8832 (defcustom gnus-summary-respool-default-method nil
8833   "Default method type for respooling an article.
8834 If nil, use to the current newsgroup method."
8835   :type 'symbol
8836   :group 'gnus-summary-mail)
8837
8838 (defun gnus-summary-respool-article (&optional n method)
8839   "Respool the current article.
8840 The article will be squeezed through the mail spooling process again,
8841 which means that it will be put in some mail newsgroup or other
8842 depending on `nnmail-split-methods'.
8843 If N is a positive number, respool the N next articles.
8844 If N is a negative number, respool the N previous articles.
8845 If N is nil and any articles have been marked with the process mark,
8846 respool those articles instead.
8847
8848 Respooling can be done both from mail groups and \"real\" newsgroups.
8849 In the former case, the articles in question will be moved from the
8850 current group into whatever groups they are destined to.  In the
8851 latter case, they will be copied into the relevant groups."
8852   (interactive
8853    (list current-prefix-arg
8854          (let* ((methods (gnus-methods-using 'respool))
8855                 (methname
8856                  (symbol-name (or gnus-summary-respool-default-method
8857                                   (car (gnus-find-method-for-group
8858                                         gnus-newsgroup-name)))))
8859                 (method
8860                  (gnus-completing-read-with-default
8861                   methname "What backend do you want to use when respooling?"
8862                   methods nil t nil 'gnus-mail-method-history))
8863                 ms)
8864            (cond
8865             ((zerop (length (setq ms (gnus-servers-using-backend
8866                                       (intern method)))))
8867              (list (intern method) ""))
8868             ((= 1 (length ms))
8869              (car ms))
8870             (t
8871              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8872                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8873                            ms-alist))))))))
8874   (unless method
8875     (error "No method given for respooling"))
8876   (if (assoc (symbol-name
8877               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8878              (gnus-methods-using 'respool))
8879       (gnus-summary-move-article n nil method)
8880     (gnus-summary-copy-article n nil method)))
8881
8882 (defun gnus-summary-import-article (file &optional edit)
8883   "Import an arbitrary file into a mail newsgroup."
8884   (interactive "fImport file: \nP")
8885   (let ((group gnus-newsgroup-name)
8886         (now (current-time))
8887         atts lines group-art)
8888     (unless (gnus-check-backend-function 'request-accept-article group)
8889       (error "%s does not support article importing" group))
8890     (or (file-readable-p file)
8891         (not (file-regular-p file))
8892         (error "Can't read %s" file))
8893     (save-excursion
8894       (set-buffer (gnus-get-buffer-create " *import file*"))
8895       (erase-buffer)
8896       (nnheader-insert-file-contents file)
8897       (goto-char (point-min))
8898       (if (nnheader-article-p)
8899           (save-restriction
8900             (goto-char (point-min))
8901             (search-forward "\n\n" nil t)
8902             (narrow-to-region (point-min) (1- (point)))
8903             (goto-char (point-min))
8904             (unless (re-search-forward "^date:" nil t)
8905               (goto-char (point-max))
8906               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8907         ;; This doesn't look like an article, so we fudge some headers.
8908         (setq atts (file-attributes file)
8909               lines (count-lines (point-min) (point-max)))
8910         (insert "From: " (read-string "From: ") "\n"
8911                 "Subject: " (read-string "Subject: ") "\n"
8912                 "Date: " (message-make-date (nth 5 atts)) "\n"
8913                 "Message-ID: " (message-make-message-id) "\n"
8914                 "Lines: " (int-to-string lines) "\n"
8915                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8916       (setq group-art (gnus-request-accept-article group nil t))
8917       (kill-buffer (current-buffer)))
8918     (setq gnus-newsgroup-active (gnus-activate-group group))
8919     (forward-line 1)
8920     (gnus-summary-goto-article (cdr group-art) nil t)
8921     (when edit
8922       (gnus-summary-edit-article))))
8923
8924 (defun gnus-summary-create-article ()
8925   "Create an article in a mail newsgroup."
8926   (interactive)
8927   (let ((group gnus-newsgroup-name)
8928         (now (current-time))
8929         group-art)
8930     (unless (gnus-check-backend-function 'request-accept-article group)
8931       (error "%s does not support article importing" group))
8932     (save-excursion
8933       (set-buffer (gnus-get-buffer-create " *import file*"))
8934       (erase-buffer)
8935       (goto-char (point-min))
8936       ;; This doesn't look like an article, so we fudge some headers.
8937       (insert "From: " (read-string "From: ") "\n"
8938               "Subject: " (read-string "Subject: ") "\n"
8939               "Date: " (message-make-date now) "\n"
8940               "Message-ID: " (message-make-message-id) "\n")
8941       (setq group-art (gnus-request-accept-article group nil t))
8942       (kill-buffer (current-buffer)))
8943     (setq gnus-newsgroup-active (gnus-activate-group group))
8944     (forward-line 1)
8945     (gnus-summary-goto-article (cdr group-art) nil t)
8946     (gnus-summary-edit-article)))
8947
8948 (defun gnus-summary-article-posted-p ()
8949   "Say whether the current (mail) article is available from news as well.
8950 This will be the case if the article has both been mailed and posted."
8951   (interactive)
8952   (let ((id (mail-header-references (gnus-summary-article-header)))
8953         (gnus-override-method (car (gnus-refer-article-methods))))
8954     (if (gnus-request-head id "")
8955         (gnus-message 2 "The current message was found on %s"
8956                       gnus-override-method)
8957       (gnus-message 2 "The current message couldn't be found on %s"
8958                     gnus-override-method)
8959       nil)))
8960
8961 (defun gnus-summary-expire-articles (&optional now)
8962   "Expire all articles that are marked as expirable in the current group."
8963   (interactive)
8964   (when (gnus-check-backend-function
8965          'request-expire-articles gnus-newsgroup-name)
8966     ;; This backend supports expiry.
8967     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8968            (expirable (if total
8969                           (progn
8970                             ;; We need to update the info for
8971                             ;; this group for `gnus-list-of-read-articles'
8972                             ;; to give us the right answer.
8973                             (gnus-run-hooks 'gnus-exit-group-hook)
8974                             (gnus-summary-update-info)
8975                             (gnus-list-of-read-articles gnus-newsgroup-name))
8976                         (setq gnus-newsgroup-expirable
8977                               (sort gnus-newsgroup-expirable '<))))
8978            (expiry-wait (if now 'immediate
8979                           (gnus-group-find-parameter
8980                            gnus-newsgroup-name 'expiry-wait)))
8981            (nnmail-expiry-target
8982             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8983                 nnmail-expiry-target))
8984            es)
8985       (when expirable
8986         ;; There are expirable articles in this group, so we run them
8987         ;; through the expiry process.
8988         (gnus-message 6 "Expiring articles...")
8989         (unless (gnus-check-group gnus-newsgroup-name)
8990           (error "Can't open server for %s" gnus-newsgroup-name))
8991         ;; The list of articles that weren't expired is returned.
8992         (save-excursion
8993           (if expiry-wait
8994               (let ((nnmail-expiry-wait-function nil)
8995                     (nnmail-expiry-wait expiry-wait))
8996                 (setq es (gnus-request-expire-articles
8997                           expirable gnus-newsgroup-name)))
8998             (setq es (gnus-request-expire-articles
8999                       expirable gnus-newsgroup-name)))
9000           (unless total
9001             (setq gnus-newsgroup-expirable es))
9002           ;; We go through the old list of expirable, and mark all
9003           ;; really expired articles as nonexistent.
9004           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9005             (let ((gnus-use-cache nil))
9006               (dolist (article expirable)
9007                 (when (and (not (memq article es))
9008                            (gnus-data-find article))
9009                   (gnus-summary-mark-article article gnus-canceled-mark))))))
9010         (gnus-message 6 "Expiring articles...done")))))
9011
9012 (defun gnus-summary-expire-articles-now ()
9013   "Expunge all expirable articles in the current group.
9014 This means that *all* articles that are marked as expirable will be
9015 deleted forever, right now."
9016   (interactive)
9017   (or gnus-expert-user
9018       (gnus-yes-or-no-p
9019        "Are you really, really, really sure you want to delete all these messages? ")
9020       (error "Phew!"))
9021   (gnus-summary-expire-articles t))
9022
9023 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9024 (defun gnus-summary-delete-article (&optional n)
9025   "Delete the N next (mail) articles.
9026 This command actually deletes articles.  This is not a marking
9027 command.  The article will disappear forever from your life, never to
9028 return.
9029 If N is negative, delete backwards.
9030 If N is nil and articles have been marked with the process mark,
9031 delete these instead."
9032   (interactive "P")
9033   (unless (gnus-check-backend-function 'request-expire-articles
9034                                        gnus-newsgroup-name)
9035     (error "The current newsgroup does not support article deletion"))
9036   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9037     (error "Couldn't open server"))
9038   ;; Compute the list of articles to delete.
9039   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9040         (nnmail-expiry-target 'delete)
9041         not-deleted)
9042     (if (and gnus-novice-user
9043              (not (gnus-yes-or-no-p
9044                    (format "Do you really want to delete %s forever? "
9045                            (if (> (length articles) 1)
9046                                (format "these %s articles" (length articles))
9047                              "this article")))))
9048         ()
9049       ;; Delete the articles.
9050       (setq not-deleted (gnus-request-expire-articles
9051                          articles gnus-newsgroup-name 'force))
9052       (while articles
9053         (gnus-summary-remove-process-mark (car articles))
9054         ;; The backend might not have been able to delete the article
9055         ;; after all.
9056         (unless (memq (car articles) not-deleted)
9057           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9058         (setq articles (cdr articles)))
9059       (when not-deleted
9060         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9061     (gnus-summary-position-point)
9062     (gnus-set-mode-line 'summary)
9063     not-deleted))
9064
9065 (defun gnus-summary-edit-article (&optional force)
9066   "Edit the current article.
9067 This will have permanent effect only in mail groups.
9068 If FORCE is non-nil, allow editing of articles even in read-only
9069 groups."
9070   (interactive "P")
9071   (save-excursion
9072     (set-buffer gnus-summary-buffer)
9073     (let ((mail-parse-charset gnus-newsgroup-charset)
9074           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9075       (gnus-set-global-variables)
9076       (when (and (not force)
9077                  (gnus-group-read-only-p))
9078         (error "The current newsgroup does not support article editing"))
9079       (gnus-summary-show-article t)
9080       (gnus-article-edit-article
9081        'ignore
9082        `(lambda (no-highlight)
9083           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9084                 (message-options message-options)
9085                 (message-options-set-recipient)
9086                 (mail-parse-ignored-charsets
9087                  ',gnus-newsgroup-ignored-charsets))
9088             (gnus-summary-edit-article-done
9089              ,(or (mail-header-references gnus-current-headers) "")
9090              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9091
9092 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9093
9094 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9095                                                  no-highlight)
9096   "Make edits to the current article permanent."
9097   (interactive)
9098   (save-excursion
9099     ;; The buffer restriction contains the entire article if it exists.
9100     (when (article-goto-body)
9101       (let ((lines (count-lines (point) (point-max)))
9102             (length (- (point-max) (point)))
9103             (case-fold-search t)
9104             (body (copy-marker (point))))
9105         (goto-char (point-min))
9106         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9107           (delete-region (match-beginning 1) (match-end 1))
9108           (insert (number-to-string length)))
9109         (goto-char (point-min))
9110         (when (re-search-forward
9111                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9112           (delete-region (match-beginning 1) (match-end 1))
9113           (insert (number-to-string length)))
9114         (goto-char (point-min))
9115         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9116           (delete-region (match-beginning 1) (match-end 1))
9117           (insert (number-to-string lines))))))
9118   ;; Replace the article.
9119   (let ((buf (current-buffer)))
9120     (with-temp-buffer
9121       (insert-buffer-substring buf)
9122
9123       (if (and (not read-only)
9124                (not (gnus-request-replace-article
9125                      (cdr gnus-article-current) (car gnus-article-current)
9126                      (current-buffer) t)))
9127           (error "Couldn't replace article")
9128         ;; Update the summary buffer.
9129         (if (and references
9130                  (equal (message-tokenize-header references " ")
9131                         (message-tokenize-header
9132                          (or (message-fetch-field "references") "") " ")))
9133             ;; We only have to update this line.
9134             (save-excursion
9135               (save-restriction
9136                 (message-narrow-to-head)
9137                 (let ((head (buffer-string))
9138                       header)
9139                   (with-temp-buffer
9140                     (insert (format "211 %d Article retrieved.\n"
9141                                     (cdr gnus-article-current)))
9142                     (insert head)
9143                     (insert ".\n")
9144                     (let ((nntp-server-buffer (current-buffer)))
9145                       (setq header (car (gnus-get-newsgroup-headers
9146                                          nil t))))
9147                     (save-excursion
9148                       (set-buffer gnus-summary-buffer)
9149                       (gnus-data-set-header
9150                        (gnus-data-find (cdr gnus-article-current))
9151                        header)
9152                       (gnus-summary-update-article-line
9153                        (cdr gnus-article-current) header)
9154                       (if (gnus-summary-goto-subject
9155                            (cdr gnus-article-current) nil t)
9156                           (gnus-summary-update-secondary-mark
9157                            (cdr gnus-article-current))))))))
9158           ;; Update threads.
9159           (set-buffer (or buffer gnus-summary-buffer))
9160           (gnus-summary-update-article (cdr gnus-article-current))
9161           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9162               (gnus-summary-update-secondary-mark
9163                (cdr gnus-article-current))))
9164         ;; Prettify the article buffer again.
9165         (unless no-highlight
9166           (save-excursion
9167             (set-buffer gnus-article-buffer)
9168             ;;;!!! Fix this -- article should be rehighlighted.
9169             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9170             (set-buffer gnus-original-article-buffer)
9171             (gnus-request-article
9172              (cdr gnus-article-current)
9173              (car gnus-article-current) (current-buffer))))
9174         ;; Prettify the summary buffer line.
9175         (when (gnus-visual-p 'summary-highlight 'highlight)
9176           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9177
9178 (defun gnus-summary-edit-wash (key)
9179   "Perform editing command KEY in the article buffer."
9180   (interactive
9181    (list
9182     (progn
9183       (message "%s" (concat (this-command-keys) "- "))
9184       (read-char))))
9185   (message "")
9186   (gnus-summary-edit-article)
9187   (execute-kbd-macro (concat (this-command-keys) key))
9188   (gnus-article-edit-done))
9189
9190 ;;; Respooling
9191
9192 (defun gnus-summary-respool-query (&optional silent trace)
9193   "Query where the respool algorithm would put this article."
9194   (interactive)
9195   (let (gnus-mark-article-hook)
9196     (gnus-summary-select-article)
9197     (save-excursion
9198       (set-buffer gnus-original-article-buffer)
9199       (save-restriction
9200         (message-narrow-to-head)
9201         (let ((groups (nnmail-article-group 'identity trace)))
9202           (unless silent
9203             (if groups
9204                 (message "This message would go to %s"
9205                          (mapconcat 'car groups ", "))
9206               (message "This message would go to no groups"))
9207             groups))))))
9208
9209 (defun gnus-summary-respool-trace ()
9210   "Trace where the respool algorithm would put this article.
9211 Display a buffer showing all fancy splitting patterns which matched."
9212   (interactive)
9213   (gnus-summary-respool-query nil t))
9214
9215 ;; Summary marking commands.
9216
9217 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9218   "Mark articles which has the same subject as read, and then select the next.
9219 If UNMARK is positive, remove any kind of mark.
9220 If UNMARK is negative, tick articles."
9221   (interactive "P")
9222   (when unmark
9223     (setq unmark (prefix-numeric-value unmark)))
9224   (let ((count
9225          (gnus-summary-mark-same-subject
9226           (gnus-summary-article-subject) unmark)))
9227     ;; Select next unread article.  If auto-select-same mode, should
9228     ;; select the first unread article.
9229     (gnus-summary-next-article t (and gnus-auto-select-same
9230                                       (gnus-summary-article-subject)))
9231     (gnus-message 7 "%d article%s marked as %s"
9232                   count (if (= count 1) " is" "s are")
9233                   (if unmark "unread" "read"))))
9234
9235 (defun gnus-summary-kill-same-subject (&optional unmark)
9236   "Mark articles which has the same subject as read.
9237 If UNMARK is positive, remove any kind of mark.
9238 If UNMARK is negative, tick articles."
9239   (interactive "P")
9240   (when unmark
9241     (setq unmark (prefix-numeric-value unmark)))
9242   (let ((count
9243          (gnus-summary-mark-same-subject
9244           (gnus-summary-article-subject) unmark)))
9245     ;; If marked as read, go to next unread subject.
9246     (when (null unmark)
9247       ;; Go to next unread subject.
9248       (gnus-summary-next-subject 1 t))
9249     (gnus-message 7 "%d articles are marked as %s"
9250                   count (if unmark "unread" "read"))))
9251
9252 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9253   "Mark articles with same SUBJECT as read, and return marked number.
9254 If optional argument UNMARK is positive, remove any kinds of marks.
9255 If optional argument UNMARK is negative, mark articles as unread instead."
9256   (let ((count 1))
9257     (save-excursion
9258       (cond
9259        ((null unmark)                   ; Mark as read.
9260         (while (and
9261                 (progn
9262                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9263                   (gnus-summary-show-thread) t)
9264                 (gnus-summary-find-subject subject))
9265           (setq count (1+ count))))
9266        ((> unmark 0)                    ; Tick.
9267         (while (and
9268                 (progn
9269                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9270                   (gnus-summary-show-thread) t)
9271                 (gnus-summary-find-subject subject))
9272           (setq count (1+ count))))
9273        (t                               ; Mark as unread.
9274         (while (and
9275                 (progn
9276                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9277                   (gnus-summary-show-thread) t)
9278                 (gnus-summary-find-subject subject))
9279           (setq count (1+ count)))))
9280       (gnus-set-mode-line 'summary)
9281       ;; Return the number of marked articles.
9282       count)))
9283
9284 (defun gnus-summary-mark-as-processable (n &optional unmark)
9285   "Set the process mark on the next N articles.
9286 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9287 the process mark instead.  The difference between N and the actual
9288 number of articles marked is returned."
9289   (interactive "P")
9290   (if (and (null n) (gnus-region-active-p))
9291       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9292     (setq n (prefix-numeric-value n))
9293     (let ((backward (< n 0))
9294           (n (abs n)))
9295       (while (and
9296               (> n 0)
9297               (if unmark
9298                   (gnus-summary-remove-process-mark
9299                    (gnus-summary-article-number))
9300                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9301               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9302         (setq n (1- n)))
9303       (when (/= 0 n)
9304         (gnus-message 7 "No more articles"))
9305       (gnus-summary-recenter)
9306       (gnus-summary-position-point)
9307       n)))
9308
9309 (defun gnus-summary-unmark-as-processable (n)
9310   "Remove the process mark from the next N articles.
9311 If N is negative, unmark backward instead.  The difference between N and
9312 the actual number of articles unmarked is returned."
9313   (interactive "P")
9314   (gnus-summary-mark-as-processable n t))
9315
9316 (defun gnus-summary-unmark-all-processable ()
9317   "Remove the process mark from all articles."
9318   (interactive)
9319   (save-excursion
9320     (while gnus-newsgroup-processable
9321       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9322   (gnus-summary-position-point))
9323
9324 (defun gnus-summary-add-mark (article type)
9325   "Mark ARTICLE with a mark of TYPE."
9326   (let ((vtype (car (assq type gnus-article-mark-lists)))
9327         var)
9328     (if (not vtype)
9329         (error "No such mark type: %s" type)
9330       (setq var (intern (format "gnus-newsgroup-%s" type)))
9331       (set var (cons article (symbol-value var)))
9332       (if (memq type '(processable cached replied forwarded recent saved))
9333           (gnus-summary-update-secondary-mark article)
9334         ;;; !!! This is bogus.  We should find out what primary
9335         ;;; !!! mark we want to set.
9336         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9337
9338 (defun gnus-summary-mark-as-expirable (n)
9339   "Mark N articles forward as expirable.
9340 If N is negative, mark backward instead.  The difference between N and
9341 the actual number of articles marked is returned."
9342   (interactive "p")
9343   (gnus-summary-mark-forward n gnus-expirable-mark))
9344
9345 (defun gnus-summary-mark-as-spam (n)
9346   "Mark N articles forward as spam.
9347 If N is negative, mark backward instead.  The difference between N and
9348 the actual number of articles marked is returned."
9349   (interactive "p")
9350   (gnus-summary-mark-forward n gnus-spam-mark))
9351
9352 (defun gnus-summary-mark-article-as-replied (article)
9353   "Mark ARTICLE as replied to and update the summary line.
9354 ARTICLE can also be a list of articles."
9355   (interactive (list (gnus-summary-article-number)))
9356   (let ((articles (if (listp article) article (list article))))
9357     (dolist (article articles)
9358       (push article gnus-newsgroup-replied)
9359       (let ((buffer-read-only nil))
9360         (when (gnus-summary-goto-subject article nil t)
9361           (gnus-summary-update-secondary-mark article))))))
9362
9363 (defun gnus-summary-mark-article-as-forwarded (article)
9364   "Mark ARTICLE as forwarded and update the summary line.
9365 ARTICLE can also be a list of articles."
9366   (let ((articles (if (listp article) article (list article))))
9367     (dolist (article articles)
9368       (push article gnus-newsgroup-forwarded)
9369       (let ((buffer-read-only nil))
9370         (when (gnus-summary-goto-subject article nil t)
9371           (gnus-summary-update-secondary-mark article))))))
9372
9373 (defun gnus-summary-set-bookmark (article)
9374   "Set a bookmark in current article."
9375   (interactive (list (gnus-summary-article-number)))
9376   (when (or (not (get-buffer gnus-article-buffer))
9377             (not gnus-current-article)
9378             (not gnus-article-current)
9379             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9380     (error "No current article selected"))
9381   ;; Remove old bookmark, if one exists.
9382   (let ((old (assq article gnus-newsgroup-bookmarks)))
9383     (when old
9384       (setq gnus-newsgroup-bookmarks
9385             (delq old gnus-newsgroup-bookmarks))))
9386   ;; Set the new bookmark, which is on the form
9387   ;; (article-number . line-number-in-body).
9388   (push
9389    (cons article
9390          (save-excursion
9391            (set-buffer gnus-article-buffer)
9392            (count-lines
9393             (min (point)
9394                  (save-excursion
9395                    (goto-char (point-min))
9396                    (search-forward "\n\n" nil t)
9397                    (point)))
9398             (point))))
9399    gnus-newsgroup-bookmarks)
9400   (gnus-message 6 "A bookmark has been added to the current article."))
9401
9402 (defun gnus-summary-remove-bookmark (article)
9403   "Remove the bookmark from the current article."
9404   (interactive (list (gnus-summary-article-number)))
9405   ;; Remove old bookmark, if one exists.
9406   (let ((old (assq article gnus-newsgroup-bookmarks)))
9407     (if old
9408         (progn
9409           (setq gnus-newsgroup-bookmarks
9410                 (delq old gnus-newsgroup-bookmarks))
9411           (gnus-message 6 "Removed bookmark."))
9412       (gnus-message 6 "No bookmark in current article."))))
9413
9414 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9415 (defun gnus-summary-mark-as-dormant (n)
9416   "Mark N articles forward as dormant.
9417 If N is negative, mark backward instead.  The difference between N and
9418 the actual number of articles marked is returned."
9419   (interactive "p")
9420   (gnus-summary-mark-forward n gnus-dormant-mark))
9421
9422 (defun gnus-summary-set-process-mark (article)
9423   "Set the process mark on ARTICLE and update the summary line."
9424   (setq gnus-newsgroup-processable
9425         (cons article
9426               (delq article gnus-newsgroup-processable)))
9427   (when (gnus-summary-goto-subject article)
9428     (gnus-summary-show-thread)
9429     (gnus-summary-goto-subject article)
9430     (gnus-summary-update-secondary-mark article)))
9431
9432 (defun gnus-summary-remove-process-mark (article)
9433   "Remove the process mark from ARTICLE and update the summary line."
9434   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9435   (when (gnus-summary-goto-subject article)
9436     (gnus-summary-show-thread)
9437     (gnus-summary-goto-subject article)
9438     (gnus-summary-update-secondary-mark article)))
9439
9440 (defun gnus-summary-set-saved-mark (article)
9441   "Set the process mark on ARTICLE and update the summary line."
9442   (push article gnus-newsgroup-saved)
9443   (when (gnus-summary-goto-subject article)
9444     (gnus-summary-update-secondary-mark article)))
9445
9446 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9447   "Mark N articles as read forwards.
9448 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9449 The difference between N and the actual number of articles marked is
9450 returned.
9451 Iff NO-EXPIRE, auto-expiry will be inhibited."
9452   (interactive "p")
9453   (gnus-summary-show-thread)
9454   (let ((backward (< n 0))
9455         (gnus-summary-goto-unread
9456          (and gnus-summary-goto-unread
9457               (not (eq gnus-summary-goto-unread 'never))
9458               (not (memq mark (list gnus-unread-mark
9459                                     gnus-ticked-mark gnus-dormant-mark)))))
9460         (n (abs n))
9461         (mark (or mark gnus-del-mark)))
9462     (while (and (> n 0)
9463                 (gnus-summary-mark-article nil mark no-expire)
9464                 (zerop (gnus-summary-next-subject
9465                         (if backward -1 1)
9466                         (and gnus-summary-goto-unread
9467                              (not (eq gnus-summary-goto-unread 'never)))
9468                         t)))
9469       (setq n (1- n)))
9470     (when (/= 0 n)
9471       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9472     (gnus-summary-recenter)
9473     (gnus-summary-position-point)
9474     (gnus-set-mode-line 'summary)
9475     n))
9476
9477 (defun gnus-summary-mark-article-as-read (mark)
9478   "Mark the current article quickly as read with MARK."
9479   (let ((article (gnus-summary-article-number)))
9480     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9481     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9482     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9483     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9484     (push (cons article mark) gnus-newsgroup-reads)
9485     ;; Possibly remove from cache, if that is used.
9486     (when gnus-use-cache
9487       (gnus-cache-enter-remove-article article))
9488     ;; Allow the backend to change the mark.
9489     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9490     ;; Check for auto-expiry.
9491     (when (and gnus-newsgroup-auto-expire
9492                (memq mark gnus-auto-expirable-marks))
9493       (setq mark gnus-expirable-mark)
9494       ;; Let the backend know about the mark change.
9495       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9496       (push article gnus-newsgroup-expirable))
9497     ;; Set the mark in the buffer.
9498     (gnus-summary-update-mark mark 'unread)
9499     t))
9500
9501 (defun gnus-summary-mark-article-as-unread (mark)
9502   "Mark the current article quickly as unread with MARK."
9503   (let* ((article (gnus-summary-article-number))
9504          (old-mark (gnus-summary-article-mark article)))
9505     ;; Allow the backend to change the mark.
9506     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9507     (if (eq mark old-mark)
9508         t
9509       (if (<= article 0)
9510           (progn
9511             (gnus-error 1 "Can't mark negative article numbers")
9512             nil)
9513         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9514         (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9515         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9516         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9517         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9518         (cond ((= mark gnus-ticked-mark)
9519                (setq gnus-newsgroup-marked
9520                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9521                                               article)))
9522               ((= mark gnus-spam-mark)
9523                (setq gnus-newsgroup-spam-marked
9524                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9525                                               article)))
9526               ((= mark gnus-dormant-mark)
9527                (setq gnus-newsgroup-dormant
9528                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9529                                               article)))
9530               (t
9531                (setq gnus-newsgroup-unreads
9532                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9533                                               article))))
9534         (gnus-pull article gnus-newsgroup-reads)
9535
9536         ;; See whether the article is to be put in the cache.
9537         (and gnus-use-cache
9538              (vectorp (gnus-summary-article-header article))
9539              (save-excursion
9540                (gnus-cache-possibly-enter-article
9541                 gnus-newsgroup-name article
9542                 (gnus-summary-article-header article)
9543                 (= mark gnus-ticked-mark)
9544                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9545
9546         ;; Fix the mark.
9547         (gnus-summary-update-mark mark 'unread)
9548         t))))
9549
9550 (defun gnus-summary-mark-article (&optional article mark no-expire)
9551   "Mark ARTICLE with MARK.  MARK can be any character.
9552 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9553 `??' (dormant) and `?E' (expirable).
9554 If MARK is nil, then the default character `?r' is used.
9555 If ARTICLE is nil, then the article on the current line will be
9556 marked.
9557 Iff NO-EXPIRE, auto-expiry will be inhibited."
9558   ;; The mark might be a string.
9559   (when (stringp mark)
9560     (setq mark (aref mark 0)))
9561   ;; If no mark is given, then we check auto-expiring.
9562   (when (null mark)
9563     (setq mark gnus-del-mark))
9564   (when (and (not no-expire)
9565              gnus-newsgroup-auto-expire
9566              (memq mark gnus-auto-expirable-marks))
9567     (setq mark gnus-expirable-mark))
9568   (let ((article (or article (gnus-summary-article-number)))
9569         (old-mark (gnus-summary-article-mark article)))
9570     ;; Allow the backend to change the mark.
9571     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9572     (if (eq mark old-mark)
9573         t
9574       (unless article
9575         (error "No article on current line"))
9576       (if (not (if (or (= mark gnus-unread-mark)
9577                        (= mark gnus-ticked-mark)
9578                        (= mark gnus-spam-mark)
9579                        (= mark gnus-dormant-mark))
9580                    (gnus-mark-article-as-unread article mark)
9581                  (gnus-mark-article-as-read article mark)))
9582           t
9583         ;; See whether the article is to be put in the cache.
9584         (and gnus-use-cache
9585              (not (= mark gnus-canceled-mark))
9586              (vectorp (gnus-summary-article-header article))
9587              (save-excursion
9588                (gnus-cache-possibly-enter-article
9589                 gnus-newsgroup-name article
9590                 (gnus-summary-article-header article)
9591                 (= mark gnus-ticked-mark)
9592                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9593
9594         (when (gnus-summary-goto-subject article nil t)
9595           (let ((buffer-read-only nil))
9596             (gnus-summary-show-thread)
9597             ;; Fix the mark.
9598             (gnus-summary-update-mark mark 'unread)
9599             t))))))
9600
9601 (defun gnus-summary-update-secondary-mark (article)
9602   "Update the secondary (read, process, cache) mark."
9603   (gnus-summary-update-mark
9604    (cond ((memq article gnus-newsgroup-processable)
9605           gnus-process-mark)
9606          ((memq article gnus-newsgroup-cached)
9607           gnus-cached-mark)
9608          ((memq article gnus-newsgroup-replied)
9609           gnus-replied-mark)
9610          ((memq article gnus-newsgroup-forwarded)
9611           gnus-forwarded-mark)
9612          ((memq article gnus-newsgroup-saved)
9613           gnus-saved-mark)
9614          ((memq article gnus-newsgroup-recent)
9615           gnus-recent-mark)
9616          ((memq article gnus-newsgroup-unseen)
9617           gnus-unseen-mark)
9618          (t gnus-no-mark))
9619    'replied)
9620   (when (gnus-visual-p 'summary-highlight 'highlight)
9621     (gnus-run-hooks 'gnus-summary-update-hook))
9622   t)
9623
9624 (defun gnus-summary-update-mark (mark type)
9625   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9626         (buffer-read-only nil))
9627     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9628     (when forward
9629       (when (looking-at "\r")
9630         (incf forward))
9631       (when (<= (+ forward (point)) (point-max))
9632         ;; Go to the right position on the line.
9633         (goto-char (+ forward (point)))
9634         ;; Replace the old mark with the new mark.
9635         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9636         ;; Optionally update the marks by some user rule.
9637         (when (eq type 'unread)
9638           (gnus-data-set-mark
9639            (gnus-data-find (gnus-summary-article-number)) mark)
9640           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9641
9642 (defun gnus-mark-article-as-read (article &optional mark)
9643   "Enter ARTICLE in the pertinent lists and remove it from others."
9644   ;; Make the article expirable.
9645   (let ((mark (or mark gnus-del-mark)))
9646     (setq gnus-newsgroup-expirable
9647           (if (= mark gnus-expirable-mark)
9648               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9649             (delq article gnus-newsgroup-expirable)))
9650     ;; Remove from unread and marked lists.
9651     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9652     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9653     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9654     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9655     (push (cons article mark) gnus-newsgroup-reads)
9656     ;; Possibly remove from cache, if that is used.
9657     (when gnus-use-cache
9658       (gnus-cache-enter-remove-article article))
9659     t))
9660
9661 (defun gnus-mark-article-as-unread (article &optional mark)
9662   "Enter ARTICLE in the pertinent lists and remove it from others."
9663   (let ((mark (or mark gnus-ticked-mark)))
9664     (if (<= article 0)
9665         (progn
9666           (gnus-error 1 "Can't mark negative article numbers")
9667           nil)
9668       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9669             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
9670             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9671             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9672             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9673
9674       ;; Unsuppress duplicates?
9675       (when gnus-suppress-duplicates
9676         (gnus-dup-unsuppress-article article))
9677
9678       (cond ((= mark gnus-ticked-mark)
9679              (setq gnus-newsgroup-marked
9680                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9681             ((= mark gnus-spam-mark)
9682              (setq gnus-newsgroup-spam-marked
9683                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked article)))
9684             ((= mark gnus-dormant-mark)
9685              (setq gnus-newsgroup-dormant
9686                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9687             (t
9688              (setq gnus-newsgroup-unreads
9689                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9690       (gnus-pull article gnus-newsgroup-reads)
9691       t)))
9692
9693 (defalias 'gnus-summary-mark-as-unread-forward
9694   'gnus-summary-tick-article-forward)
9695 (make-obsolete 'gnus-summary-mark-as-unread-forward
9696                'gnus-summary-tick-article-forward)
9697 (defun gnus-summary-tick-article-forward (n)
9698   "Tick N articles forwards.
9699 If N is negative, tick backwards instead.
9700 The difference between N and the number of articles ticked is returned."
9701   (interactive "p")
9702   (gnus-summary-mark-forward n gnus-ticked-mark))
9703
9704 (defalias 'gnus-summary-mark-as-unread-backward
9705   'gnus-summary-tick-article-backward)
9706 (make-obsolete 'gnus-summary-mark-as-unread-backward
9707                'gnus-summary-tick-article-backward)
9708 (defun gnus-summary-tick-article-backward (n)
9709   "Tick N articles backwards.
9710 The difference between N and the number of articles ticked is returned."
9711   (interactive "p")
9712   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9713
9714 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9715 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9716 (defun gnus-summary-tick-article (&optional article clear-mark)
9717   "Mark current article as unread.
9718 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9719 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9720   (interactive)
9721   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9722                                        gnus-ticked-mark)))
9723
9724 (defun gnus-summary-mark-as-read-forward (n)
9725   "Mark N articles as read forwards.
9726 If N is negative, mark backwards instead.
9727 The difference between N and the actual number of articles marked is
9728 returned."
9729   (interactive "p")
9730   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9731
9732 (defun gnus-summary-mark-as-read-backward (n)
9733   "Mark the N articles as read backwards.
9734 The difference between N and the actual number of articles marked is
9735 returned."
9736   (interactive "p")
9737   (gnus-summary-mark-forward
9738    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9739
9740 (defun gnus-summary-mark-as-read (&optional article mark)
9741   "Mark current article as read.
9742 ARTICLE specifies the article to be marked as read.
9743 MARK specifies a string to be inserted at the beginning of the line."
9744   (gnus-summary-mark-article article mark))
9745
9746 (defun gnus-summary-clear-mark-forward (n)
9747   "Clear marks from N articles forward.
9748 If N is negative, clear backward instead.
9749 The difference between N and the number of marks cleared is returned."
9750   (interactive "p")
9751   (gnus-summary-mark-forward n gnus-unread-mark))
9752
9753 (defun gnus-summary-clear-mark-backward (n)
9754   "Clear marks from N articles backward.
9755 The difference between N and the number of marks cleared is returned."
9756   (interactive "p")
9757   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9758
9759 (defun gnus-summary-mark-unread-as-read ()
9760   "Intended to be used by `gnus-summary-mark-article-hook'."
9761   (when (memq gnus-current-article gnus-newsgroup-unreads)
9762     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9763
9764 (defun gnus-summary-mark-read-and-unread-as-read ()
9765   "Intended to be used by `gnus-summary-mark-article-hook'."
9766   (let ((mark (gnus-summary-article-mark)))
9767     (when (or (gnus-unread-mark-p mark)
9768               (gnus-read-mark-p mark))
9769       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9770
9771 (defun gnus-summary-mark-unread-as-ticked ()
9772   "Intended to be used by `gnus-summary-mark-article-hook'."
9773   (when (memq gnus-current-article gnus-newsgroup-unreads)
9774     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9775
9776 (defun gnus-summary-mark-region-as-read (point mark all)
9777   "Mark all unread articles between point and mark as read.
9778 If given a prefix, mark all articles between point and mark as read,
9779 even ticked and dormant ones."
9780   (interactive "r\nP")
9781   (save-excursion
9782     (let (article)
9783       (goto-char point)
9784       (beginning-of-line)
9785       (while (and
9786               (< (point) mark)
9787               (progn
9788                 (when (or all
9789                           (memq (setq article (gnus-summary-article-number))
9790                                 gnus-newsgroup-unreads))
9791                   (gnus-summary-mark-article article gnus-del-mark))
9792                 t)
9793               (gnus-summary-find-next))))))
9794
9795 (defun gnus-summary-mark-below (score mark)
9796   "Mark articles with score less than SCORE with MARK."
9797   (interactive "P\ncMark: ")
9798   (setq score (if score
9799                   (prefix-numeric-value score)
9800                 (or gnus-summary-default-score 0)))
9801   (save-excursion
9802     (set-buffer gnus-summary-buffer)
9803     (goto-char (point-min))
9804     (while
9805         (progn
9806           (and (< (gnus-summary-article-score) score)
9807                (gnus-summary-mark-article nil mark))
9808           (gnus-summary-find-next)))))
9809
9810 (defun gnus-summary-kill-below (&optional score)
9811   "Mark articles with score below SCORE as read."
9812   (interactive "P")
9813   (gnus-summary-mark-below score gnus-killed-mark))
9814
9815 (defun gnus-summary-clear-above (&optional score)
9816   "Clear all marks from articles with score above SCORE."
9817   (interactive "P")
9818   (gnus-summary-mark-above score gnus-unread-mark))
9819
9820 (defun gnus-summary-tick-above (&optional score)
9821   "Tick all articles with score above SCORE."
9822   (interactive "P")
9823   (gnus-summary-mark-above score gnus-ticked-mark))
9824
9825 (defun gnus-summary-mark-above (score mark)
9826   "Mark articles with score over SCORE with MARK."
9827   (interactive "P\ncMark: ")
9828   (setq score (if score
9829                   (prefix-numeric-value score)
9830                 (or gnus-summary-default-score 0)))
9831   (save-excursion
9832     (set-buffer gnus-summary-buffer)
9833     (goto-char (point-min))
9834     (while (and (progn
9835                   (when (> (gnus-summary-article-score) score)
9836                     (gnus-summary-mark-article nil mark))
9837                   t)
9838                 (gnus-summary-find-next)))))
9839
9840 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9841 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9842 (defun gnus-summary-limit-include-expunged (&optional no-error)
9843   "Display all the hidden articles that were expunged for low scores."
9844   (interactive)
9845   (let ((buffer-read-only nil))
9846     (let ((scored gnus-newsgroup-scored)
9847           headers h)
9848       (while scored
9849         (unless (gnus-summary-article-header (caar scored))
9850           (and (setq h (gnus-number-to-header (caar scored)))
9851                (< (cdar scored) gnus-summary-expunge-below)
9852                (push h headers)))
9853         (setq scored (cdr scored)))
9854       (if (not headers)
9855           (when (not no-error)
9856             (error "No expunged articles hidden"))
9857         (goto-char (point-min))
9858         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9859         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9860         (mapcar (lambda (x) (push (mail-header-number x)
9861                                   gnus-newsgroup-limit))
9862                 headers)
9863         (gnus-summary-prepare-unthreaded (nreverse headers))
9864         (goto-char (point-min))
9865         (gnus-summary-position-point)
9866         t))))
9867
9868 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9869   "Mark all unread articles in this newsgroup as read.
9870 If prefix argument ALL is non-nil, ticked and dormant articles will
9871 also be marked as read.
9872 If QUIETLY is non-nil, no questions will be asked.
9873 If TO-HERE is non-nil, it should be a point in the buffer.  All
9874 articles before (after, if REVERSE is set) this point will be marked as read.
9875 Note that this function will only catch up the unread article
9876 in the current summary buffer limitation.
9877 The number of articles marked as read is returned."
9878   (interactive "P")
9879   (prog1
9880       (save-excursion
9881         (when (or quietly
9882                   (not gnus-interactive-catchup) ;Without confirmation?
9883                   gnus-expert-user
9884                   (gnus-y-or-n-p
9885                    (if all
9886                        "Mark absolutely all articles as read? "
9887                      "Mark all unread articles as read? ")))
9888           (if (and not-mark
9889                    (not gnus-newsgroup-adaptive)
9890                    (not gnus-newsgroup-auto-expire)
9891                    (not gnus-suppress-duplicates)
9892                    (or (not gnus-use-cache)
9893                        (eq gnus-use-cache 'passive)))
9894               (progn
9895                 (when all
9896                   (setq gnus-newsgroup-marked nil
9897                         gnus-newsgroup-spam-marked nil
9898                         gnus-newsgroup-dormant nil))
9899                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9900             ;; We actually mark all articles as canceled, which we
9901             ;; have to do when using auto-expiry or adaptive scoring.
9902             (gnus-summary-show-all-threads)
9903             (if (and to-here reverse)
9904                 (progn
9905                   (goto-char to-here)
9906                   (while (and
9907                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9908                           (gnus-summary-find-next (not all) nil nil t))))
9909               (when (gnus-summary-first-subject (not all) t)
9910                 (while (and
9911                         (if to-here (< (point) to-here) t)
9912                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9913                         (gnus-summary-find-next (not all) nil nil t)))))
9914             (gnus-set-mode-line 'summary))
9915           t))
9916     (gnus-summary-position-point)))
9917
9918 (defun gnus-summary-catchup-to-here (&optional all)
9919   "Mark all unticked articles before the current one as read.
9920 If ALL is non-nil, also mark ticked and dormant articles as read."
9921   (interactive "P")
9922   (save-excursion
9923     (gnus-save-hidden-threads
9924       (let ((beg (point)))
9925         ;; We check that there are unread articles.
9926         (when (or all (gnus-summary-find-prev))
9927           (gnus-summary-catchup all t beg)))))
9928   (gnus-summary-position-point))
9929
9930 (defun gnus-summary-catchup-from-here (&optional all)
9931   "Mark all unticked articles after the current one as read.
9932 If ALL is non-nil, also mark ticked and dormant articles as read."
9933   (interactive "P")
9934   (save-excursion
9935     (gnus-save-hidden-threads
9936       (let ((beg (point)))
9937         ;; We check that there are unread articles.
9938         (when (or all (gnus-summary-find-next))
9939           (gnus-summary-catchup all t beg nil t)))))
9940   (gnus-summary-position-point))
9941
9942 (defun gnus-summary-catchup-all (&optional quietly)
9943   "Mark all articles in this newsgroup as read."
9944   (interactive "P")
9945   (gnus-summary-catchup t quietly))
9946
9947 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9948   "Mark all unread articles in this group as read, then exit.
9949 If prefix argument ALL is non-nil, all articles are marked as read.
9950 If QUIETLY is non-nil, no questions will be asked."
9951   (interactive "P")
9952   (when (gnus-summary-catchup all quietly nil 'fast)
9953     ;; Select next newsgroup or exit.
9954     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9955              (eq gnus-auto-select-next 'quietly))
9956         (gnus-summary-next-group nil)
9957       (gnus-summary-exit))))
9958
9959 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9960   "Mark all articles in this newsgroup as read, and then exit."
9961   (interactive "P")
9962   (gnus-summary-catchup-and-exit t quietly))
9963
9964 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9965   "Mark all articles in this group as read and select the next group.
9966 If given a prefix, mark all articles, unread as well as ticked, as
9967 read."
9968   (interactive "P")
9969   (save-excursion
9970     (gnus-summary-catchup all))
9971   (gnus-summary-next-group))
9972
9973 ;;;
9974 ;;; with article
9975 ;;;
9976
9977 (defmacro gnus-with-article (article &rest forms)
9978   "Select ARTICLE and perform FORMS in the original article buffer.
9979 Then replace the article with the result."
9980   `(progn
9981      ;; We don't want the article to be marked as read.
9982      (let (gnus-mark-article-hook)
9983        (gnus-summary-select-article t t nil ,article))
9984      (set-buffer gnus-original-article-buffer)
9985      ,@forms
9986      (if (not (gnus-check-backend-function
9987                'request-replace-article (car gnus-article-current)))
9988          (gnus-message 5 "Read-only group; not replacing")
9989        (unless (gnus-request-replace-article
9990                 ,article (car gnus-article-current)
9991                 (current-buffer) t)
9992          (error "Couldn't replace article")))
9993      ;; The cache and backlog have to be flushed somewhat.
9994      (when gnus-keep-backlog
9995        (gnus-backlog-remove-article
9996         (car gnus-article-current) (cdr gnus-article-current)))
9997      (when gnus-use-cache
9998        (gnus-cache-update-article
9999         (car gnus-article-current) (cdr gnus-article-current)))))
10000
10001 (put 'gnus-with-article 'lisp-indent-function 1)
10002 (put 'gnus-with-article 'edebug-form-spec '(form body))
10003
10004 ;; Thread-based commands.
10005
10006 (defun gnus-summary-articles-in-thread (&optional article)
10007   "Return a list of all articles in the current thread.
10008 If ARTICLE is non-nil, return all articles in the thread that starts
10009 with that article."
10010   (let* ((article (or article (gnus-summary-article-number)))
10011          (data (gnus-data-find-list article))
10012          (top-level (gnus-data-level (car data)))
10013          (top-subject
10014           (cond ((null gnus-thread-operation-ignore-subject)
10015                  (gnus-simplify-subject-re
10016                   (mail-header-subject (gnus-data-header (car data)))))
10017                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10018                  (gnus-simplify-subject-fuzzy
10019                   (mail-header-subject (gnus-data-header (car data)))))
10020                 (t nil)))
10021          (end-point (save-excursion
10022                       (if (gnus-summary-go-to-next-thread)
10023                           (point) (point-max))))
10024          articles)
10025     (while (and data
10026                 (< (gnus-data-pos (car data)) end-point))
10027       (when (or (not top-subject)
10028                 (string= top-subject
10029                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10030                              (gnus-simplify-subject-fuzzy
10031                               (mail-header-subject
10032                                (gnus-data-header (car data))))
10033                            (gnus-simplify-subject-re
10034                             (mail-header-subject
10035                              (gnus-data-header (car data)))))))
10036         (push (gnus-data-number (car data)) articles))
10037       (unless (and (setq data (cdr data))
10038                    (> (gnus-data-level (car data)) top-level))
10039         (setq data nil)))
10040     ;; Return the list of articles.
10041     (nreverse articles)))
10042
10043 (defun gnus-summary-rethread-current ()
10044   "Rethread the thread the current article is part of."
10045   (interactive)
10046   (let* ((gnus-show-threads t)
10047          (article (gnus-summary-article-number))
10048          (id (mail-header-id (gnus-summary-article-header)))
10049          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10050     (unless id
10051       (error "No article on the current line"))
10052     (gnus-rebuild-thread id)
10053     (gnus-summary-goto-subject article)))
10054
10055 (defun gnus-summary-reparent-thread ()
10056   "Make the current article child of the marked (or previous) article.
10057
10058 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10059 is non-nil or the Subject: of both articles are the same."
10060   (interactive)
10061   (unless (not (gnus-group-read-only-p))
10062     (error "The current newsgroup does not support article editing"))
10063   (unless (<= (length gnus-newsgroup-processable) 1)
10064     (error "No more than one article may be marked"))
10065   (save-window-excursion
10066     (let ((gnus-article-buffer " *reparent*")
10067           (current-article (gnus-summary-article-number))
10068           ;; First grab the marked article, otherwise one line up.
10069           (parent-article (if (not (null gnus-newsgroup-processable))
10070                               (car gnus-newsgroup-processable)
10071                             (save-excursion
10072                               (if (eq (forward-line -1) 0)
10073                                   (gnus-summary-article-number)
10074                                 (error "Beginning of summary buffer"))))))
10075       (unless (not (eq current-article parent-article))
10076         (error "An article may not be self-referential"))
10077       (let ((message-id (mail-header-id
10078                          (gnus-summary-article-header parent-article))))
10079         (unless (and message-id (not (equal message-id "")))
10080           (error "No message-id in desired parent"))
10081         (gnus-with-article current-article
10082           (save-restriction
10083             (goto-char (point-min))
10084             (message-narrow-to-head)
10085             (if (re-search-forward "^References: " nil t)
10086                 (progn
10087                   (re-search-forward "^[^ \t]" nil t)
10088                   (forward-line -1)
10089                   (end-of-line)
10090                   (insert " " message-id))
10091               (insert "References: " message-id "\n"))))
10092         (set-buffer gnus-summary-buffer)
10093         (gnus-summary-unmark-all-processable)
10094         (gnus-summary-update-article current-article)
10095         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10096             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10097         (gnus-summary-rethread-current)
10098         (gnus-message 3 "Article %d is now the child of article %d"
10099                       current-article parent-article)))))
10100
10101 (defun gnus-summary-toggle-threads (&optional arg)
10102   "Toggle showing conversation threads.
10103 If ARG is positive number, turn showing conversation threads on."
10104   (interactive "P")
10105   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10106     (setq gnus-show-threads
10107           (if (null arg) (not gnus-show-threads)
10108             (> (prefix-numeric-value arg) 0)))
10109     (gnus-summary-prepare)
10110     (gnus-summary-goto-subject current)
10111     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10112     (gnus-summary-position-point)))
10113
10114 (defun gnus-summary-show-all-threads ()
10115   "Show all threads."
10116   (interactive)
10117   (save-excursion
10118     (let ((buffer-read-only nil))
10119       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10120   (gnus-summary-position-point))
10121
10122 (defun gnus-summary-show-thread ()
10123   "Show thread subtrees.
10124 Returns nil if no thread was there to be shown."
10125   (interactive)
10126   (let ((buffer-read-only nil)
10127         (orig (point))
10128         ;; first goto end then to beg, to have point at beg after let
10129         (end (progn (end-of-line) (point)))
10130         (beg (progn (beginning-of-line) (point))))
10131     (prog1
10132         ;; Any hidden lines here?
10133         (search-forward "\r" end t)
10134       (subst-char-in-region beg end ?\^M ?\n t)
10135       (goto-char orig)
10136       (gnus-summary-position-point))))
10137
10138 (defun gnus-summary-maybe-hide-threads ()
10139   "If requested, hide the threads that should be hidden."
10140   (when (and gnus-show-threads
10141              gnus-thread-hide-subtree)
10142     (gnus-summary-hide-all-threads
10143      (if (or (consp gnus-thread-hide-subtree)
10144              (gnus-functionp gnus-thread-hide-subtree))
10145          (gnus-make-predicate gnus-thread-hide-subtree)
10146        nil))))
10147
10148 ;;; Hiding predicates.
10149
10150 (defun gnus-article-unread-p (header)
10151   (memq (mail-header-number header) gnus-newsgroup-unreads))
10152
10153 (defun gnus-article-unseen-p (header)
10154   (memq (mail-header-number header) gnus-newsgroup-unseen))
10155
10156 (defun gnus-map-articles (predicate articles)
10157   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10158   (apply 'gnus-or (mapcar predicate
10159                           (mapcar 'gnus-summary-article-header articles))))
10160
10161 (defun gnus-summary-hide-all-threads (&optional predicate)
10162   "Hide all thread subtrees.
10163 If PREDICATE is supplied, threads that satisfy this predicate
10164 will not be hidden."
10165   (interactive)
10166   (save-excursion
10167     (goto-char (point-min))
10168     (let ((end nil))
10169       (while (not end)
10170         (when (or (not predicate)
10171                   (gnus-map-articles
10172                    predicate (gnus-summary-article-children)))
10173             (gnus-summary-hide-thread))
10174         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10175   (gnus-summary-position-point))
10176
10177 (defun gnus-summary-hide-thread ()
10178   "Hide thread subtrees.
10179 If PREDICATE is supplied, threads that satisfy this predicate
10180 will not be hidden.
10181 Returns nil if no threads were there to be hidden."
10182   (interactive)
10183   (let ((buffer-read-only nil)
10184         (start (point))
10185         (article (gnus-summary-article-number)))
10186     (goto-char start)
10187     ;; Go forward until either the buffer ends or the subthread
10188     ;; ends.
10189     (when (and (not (eobp))
10190                (or (zerop (gnus-summary-next-thread 1 t))
10191                    (goto-char (point-max))))
10192       (prog1
10193           (if (and (> (point) start)
10194                    (search-backward "\n" start t))
10195               (progn
10196                 (subst-char-in-region start (point) ?\n ?\^M)
10197                 (gnus-summary-goto-subject article))
10198             (goto-char start)
10199             nil)))))
10200
10201 (defun gnus-summary-go-to-next-thread (&optional previous)
10202   "Go to the same level (or less) next thread.
10203 If PREVIOUS is non-nil, go to previous thread instead.
10204 Return the article number moved to, or nil if moving was impossible."
10205   (let ((level (gnus-summary-thread-level))
10206         (way (if previous -1 1))
10207         (beg (point)))
10208     (forward-line way)
10209     (while (and (not (eobp))
10210                 (< level (gnus-summary-thread-level)))
10211       (forward-line way))
10212     (if (eobp)
10213         (progn
10214           (goto-char beg)
10215           nil)
10216       (setq beg (point))
10217       (prog1
10218           (gnus-summary-article-number)
10219         (goto-char beg)))))
10220
10221 (defun gnus-summary-next-thread (n &optional silent)
10222   "Go to the same level next N'th thread.
10223 If N is negative, search backward instead.
10224 Returns the difference between N and the number of skips actually
10225 done.
10226
10227 If SILENT, don't output messages."
10228   (interactive "p")
10229   (let ((backward (< n 0))
10230         (n (abs n)))
10231     (while (and (> n 0)
10232                 (gnus-summary-go-to-next-thread backward))
10233       (decf n))
10234     (unless silent
10235       (gnus-summary-position-point))
10236     (when (and (not silent) (/= 0 n))
10237       (gnus-message 7 "No more threads"))
10238     n))
10239
10240 (defun gnus-summary-prev-thread (n)
10241   "Go to the same level previous N'th thread.
10242 Returns the difference between N and the number of skips actually
10243 done."
10244   (interactive "p")
10245   (gnus-summary-next-thread (- n)))
10246
10247 (defun gnus-summary-go-down-thread ()
10248   "Go down one level in the current thread."
10249   (let ((children (gnus-summary-article-children)))
10250     (when children
10251       (gnus-summary-goto-subject (car children)))))
10252
10253 (defun gnus-summary-go-up-thread ()
10254   "Go up one level in the current thread."
10255   (let ((parent (gnus-summary-article-parent)))
10256     (when parent
10257       (gnus-summary-goto-subject parent))))
10258
10259 (defun gnus-summary-down-thread (n)
10260   "Go down thread N steps.
10261 If N is negative, go up instead.
10262 Returns the difference between N and how many steps down that were
10263 taken."
10264   (interactive "p")
10265   (let ((up (< n 0))
10266         (n (abs n)))
10267     (while (and (> n 0)
10268                 (if up (gnus-summary-go-up-thread)
10269                   (gnus-summary-go-down-thread)))
10270       (setq n (1- n)))
10271     (gnus-summary-position-point)
10272     (when (/= 0 n)
10273       (gnus-message 7 "Can't go further"))
10274     n))
10275
10276 (defun gnus-summary-up-thread (n)
10277   "Go up thread N steps.
10278 If N is negative, go down instead.
10279 Returns the difference between N and how many steps down that were
10280 taken."
10281   (interactive "p")
10282   (gnus-summary-down-thread (- n)))
10283
10284 (defun gnus-summary-top-thread ()
10285   "Go to the top of the thread."
10286   (interactive)
10287   (while (gnus-summary-go-up-thread))
10288   (gnus-summary-article-number))
10289
10290 (defun gnus-summary-kill-thread (&optional unmark)
10291   "Mark articles under current thread as read.
10292 If the prefix argument is positive, remove any kinds of marks.
10293 If the prefix argument is negative, tick articles instead."
10294   (interactive "P")
10295   (when unmark
10296     (setq unmark (prefix-numeric-value unmark)))
10297   (let ((articles (gnus-summary-articles-in-thread)))
10298     (save-excursion
10299       ;; Expand the thread.
10300       (gnus-summary-show-thread)
10301       ;; Mark all the articles.
10302       (while articles
10303         (gnus-summary-goto-subject (car articles))
10304         (cond ((null unmark)
10305                (gnus-summary-mark-article-as-read gnus-killed-mark))
10306               ((> unmark 0)
10307                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10308               (t
10309                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10310         (setq articles (cdr articles))))
10311     ;; Hide killed subtrees.
10312     (and (null unmark)
10313          gnus-thread-hide-killed
10314          (gnus-summary-hide-thread))
10315     ;; If marked as read, go to next unread subject.
10316     (when (null unmark)
10317       ;; Go to next unread subject.
10318       (gnus-summary-next-subject 1 t)))
10319   (gnus-set-mode-line 'summary))
10320
10321 ;; Summary sorting commands
10322
10323 (defun gnus-summary-sort-by-number (&optional reverse)
10324   "Sort the summary buffer by article number.
10325 Argument REVERSE means reverse order."
10326   (interactive "P")
10327   (gnus-summary-sort 'number reverse))
10328
10329 (defun gnus-summary-sort-by-random (&optional reverse)
10330   "Randomize the order in the summary buffer.
10331 Argument REVERSE means to randomize in reverse order."
10332   (interactive "P")
10333   (gnus-summary-sort 'random reverse))
10334
10335 (defun gnus-summary-sort-by-author (&optional reverse)
10336   "Sort the summary buffer by author name alphabetically.
10337 If `case-fold-search' is non-nil, case of letters is ignored.
10338 Argument REVERSE means reverse order."
10339   (interactive "P")
10340   (gnus-summary-sort 'author reverse))
10341
10342 (defun gnus-summary-sort-by-subject (&optional reverse)
10343   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10344 If `case-fold-search' is non-nil, case of letters is ignored.
10345 Argument REVERSE means reverse order."
10346   (interactive "P")
10347   (gnus-summary-sort 'subject reverse))
10348
10349 (defun gnus-summary-sort-by-date (&optional reverse)
10350   "Sort the summary buffer by date.
10351 Argument REVERSE means reverse order."
10352   (interactive "P")
10353   (gnus-summary-sort 'date reverse))
10354
10355 (defun gnus-summary-sort-by-score (&optional reverse)
10356   "Sort the summary buffer by score.
10357 Argument REVERSE means reverse order."
10358   (interactive "P")
10359   (gnus-summary-sort 'score reverse))
10360
10361 (defun gnus-summary-sort-by-lines (&optional reverse)
10362   "Sort the summary buffer by the number of lines.
10363 Argument REVERSE means reverse order."
10364   (interactive "P")
10365   (gnus-summary-sort 'lines reverse))
10366
10367 (defun gnus-summary-sort-by-chars (&optional reverse)
10368   "Sort the summary buffer by article length.
10369 Argument REVERSE means reverse order."
10370   (interactive "P")
10371   (gnus-summary-sort 'chars reverse))
10372
10373 (defun gnus-summary-sort-by-original (&optional reverse)
10374   "Sort the summary buffer using the default sorting method.
10375 Argument REVERSE means reverse order."
10376   (interactive "P")
10377   (let* ((buffer-read-only)
10378          (gnus-summary-prepare-hook nil))
10379     ;; We do the sorting by regenerating the threads.
10380     (gnus-summary-prepare)
10381     ;; Hide subthreads if needed.
10382     (gnus-summary-maybe-hide-threads)))
10383
10384 (defun gnus-summary-sort (predicate reverse)
10385   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10386   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10387          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10388          (gnus-thread-sort-functions
10389           (if (not reverse)
10390               thread
10391             `(lambda (t1 t2)
10392                (,thread t2 t1))))
10393          (gnus-sort-gathered-threads-function
10394           gnus-thread-sort-functions)
10395          (gnus-article-sort-functions
10396           (if (not reverse)
10397               article
10398             `(lambda (t1 t2)
10399                (,article t2 t1))))
10400          (buffer-read-only)
10401          (gnus-summary-prepare-hook nil))
10402     ;; We do the sorting by regenerating the threads.
10403     (gnus-summary-prepare)
10404     ;; Hide subthreads if needed.
10405     (gnus-summary-maybe-hide-threads)))
10406
10407 ;; Summary saving commands.
10408
10409 (defun gnus-summary-save-article (&optional n not-saved)
10410   "Save the current article using the default saver function.
10411 If N is a positive number, save the N next articles.
10412 If N is a negative number, save the N previous articles.
10413 If N is nil and any articles have been marked with the process mark,
10414 save those articles instead.
10415 The variable `gnus-default-article-saver' specifies the saver function."
10416   (interactive "P")
10417   (let* ((articles (gnus-summary-work-articles n))
10418          (save-buffer (save-excursion
10419                         (nnheader-set-temp-buffer " *Gnus Save*")))
10420          (num (length articles))
10421          header file)
10422     (dolist (article articles)
10423       (setq header (gnus-summary-article-header article))
10424       (if (not (vectorp header))
10425           ;; This is a pseudo-article.
10426           (if (assq 'name header)
10427               (gnus-copy-file (cdr (assq 'name header)))
10428             (gnus-message 1 "Article %d is unsaveable" article))
10429         ;; This is a real article.
10430         (save-window-excursion
10431           (let ((gnus-display-mime-function nil)
10432                 (gnus-article-prepare-hook nil))
10433             (gnus-summary-select-article t nil nil article)))
10434         (save-excursion
10435           (set-buffer save-buffer)
10436           (erase-buffer)
10437           (insert-buffer-substring gnus-original-article-buffer))
10438         (setq file (gnus-article-save save-buffer file num))
10439         (gnus-summary-remove-process-mark article)
10440         (unless not-saved
10441           (gnus-summary-set-saved-mark article))))
10442     (gnus-kill-buffer save-buffer)
10443     (gnus-summary-position-point)
10444     (gnus-set-mode-line 'summary)
10445     n))
10446
10447 (defun gnus-summary-pipe-output (&optional arg)
10448   "Pipe the current article to a subprocess.
10449 If N is a positive number, pipe the N next articles.
10450 If N is a negative number, pipe the N previous articles.
10451 If N is nil and any articles have been marked with the process mark,
10452 pipe those articles instead."
10453   (interactive "P")
10454   (require 'gnus-art)
10455   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10456     (gnus-summary-save-article arg t))
10457   (let ((buffer (get-buffer "*Shell Command Output*")))
10458     (if (and buffer
10459              (with-current-buffer buffer (> (point-max) (point-min))))
10460         (gnus-configure-windows 'pipe))))
10461
10462 (defun gnus-summary-save-article-mail (&optional arg)
10463   "Append the current article to an mail file.
10464 If N is a positive number, save the N next articles.
10465 If N is a negative number, save the N previous articles.
10466 If N is nil and any articles have been marked with the process mark,
10467 save those articles instead."
10468   (interactive "P")
10469   (require 'gnus-art)
10470   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10471     (gnus-summary-save-article arg)))
10472
10473 (defun gnus-summary-save-article-rmail (&optional arg)
10474   "Append the current article to an rmail file.
10475 If N is a positive number, save the N next articles.
10476 If N is a negative number, save the N previous articles.
10477 If N is nil and any articles have been marked with the process mark,
10478 save those articles instead."
10479   (interactive "P")
10480   (require 'gnus-art)
10481   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10482     (gnus-summary-save-article arg)))
10483
10484 (defun gnus-summary-save-article-file (&optional arg)
10485   "Append the current article to a file.
10486 If N is a positive number, save the N next articles.
10487 If N is a negative number, save the N previous articles.
10488 If N is nil and any articles have been marked with the process mark,
10489 save those articles instead."
10490   (interactive "P")
10491   (require 'gnus-art)
10492   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10493     (gnus-summary-save-article arg)))
10494
10495 (defun gnus-summary-write-article-file (&optional arg)
10496   "Write the current article to a file, deleting the previous file.
10497 If N is a positive number, save the N next articles.
10498 If N is a negative number, save the N previous articles.
10499 If N is nil and any articles have been marked with the process mark,
10500 save those articles instead."
10501   (interactive "P")
10502   (require 'gnus-art)
10503   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10504     (gnus-summary-save-article arg)))
10505
10506 (defun gnus-summary-save-article-body-file (&optional arg)
10507   "Append the current article body to a file.
10508 If N is a positive number, save the N next articles.
10509 If N is a negative number, save the N previous articles.
10510 If N is nil and any articles have been marked with the process mark,
10511 save those articles instead."
10512   (interactive "P")
10513   (require 'gnus-art)
10514   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10515     (gnus-summary-save-article arg)))
10516
10517 (defun gnus-summary-muttprint (&optional arg)
10518   "Print the current article using Muttprint.
10519 If N is a positive number, save the N next articles.
10520 If N is a negative number, save the N previous articles.
10521 If N is nil and any articles have been marked with the process mark,
10522 save those articles instead."
10523   (interactive "P")
10524   (require 'gnus-art)
10525   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10526     (gnus-summary-save-article arg t)))
10527
10528 (defun gnus-summary-pipe-message (program)
10529   "Pipe the current article through PROGRAM."
10530   (interactive "sProgram: ")
10531   (gnus-summary-select-article)
10532   (let ((mail-header-separator ""))
10533     (gnus-eval-in-buffer-window gnus-article-buffer
10534       (save-restriction
10535         (widen)
10536         (let ((start (window-start))
10537               buffer-read-only)
10538           (message-pipe-buffer-body program)
10539           (set-window-start (get-buffer-window (current-buffer)) start))))))
10540
10541 (defun gnus-get-split-value (methods)
10542   "Return a value based on the split METHODS."
10543   (let (split-name method result match)
10544     (when methods
10545       (save-excursion
10546         (set-buffer gnus-original-article-buffer)
10547         (save-restriction
10548           (nnheader-narrow-to-headers)
10549           (while (and methods (not split-name))
10550             (goto-char (point-min))
10551             (setq method (pop methods))
10552             (setq match (car method))
10553             (when (cond
10554                    ((stringp match)
10555                     ;; Regular expression.
10556                     (ignore-errors
10557                       (re-search-forward match nil t)))
10558                    ((gnus-functionp match)
10559                     ;; Function.
10560                     (save-restriction
10561                       (widen)
10562                       (setq result (funcall match gnus-newsgroup-name))))
10563                    ((consp match)
10564                     ;; Form.
10565                     (save-restriction
10566                       (widen)
10567                       (setq result (eval match)))))
10568               (setq split-name (cdr method))
10569               (cond ((stringp result)
10570                      (push (expand-file-name
10571                             result gnus-article-save-directory)
10572                            split-name))
10573                     ((consp result)
10574                      (setq split-name (append result split-name)))))))))
10575     (nreverse split-name)))
10576
10577 (defun gnus-valid-move-group-p (group)
10578   (and (boundp group)
10579        (symbol-name group)
10580        (symbol-value group)
10581        (gnus-get-function (gnus-find-method-for-group
10582                            (symbol-name group)) 'request-accept-article t)))
10583
10584 (defun gnus-read-move-group-name (prompt default articles prefix)
10585   "Read a group name."
10586   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10587          (minibuffer-confirm-incomplete nil) ; XEmacs
10588          (prom
10589           (format "%s %s to:"
10590                   prompt
10591                   (if (> (length articles) 1)
10592                       (format "these %d articles" (length articles))
10593                     "this article")))
10594          (to-newsgroup
10595           (cond
10596            ((null split-name)
10597             (gnus-completing-read-with-default
10598              default prom
10599              gnus-active-hashtb
10600              'gnus-valid-move-group-p
10601              nil prefix
10602              'gnus-group-history))
10603            ((= 1 (length split-name))
10604             (gnus-completing-read-with-default
10605              (car split-name) prom
10606              gnus-active-hashtb
10607              'gnus-valid-move-group-p
10608              nil nil
10609              'gnus-group-history))
10610            (t
10611             (gnus-completing-read-with-default
10612              nil prom
10613              (mapcar (lambda (el) (list el))
10614                      (nreverse split-name))
10615              nil nil nil
10616              'gnus-group-history))))
10617          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10618     (when to-newsgroup
10619       (if (or (string= to-newsgroup "")
10620               (string= to-newsgroup prefix))
10621           (setq to-newsgroup default))
10622       (unless to-newsgroup
10623         (error "No group name entered"))
10624       (or (gnus-active to-newsgroup)
10625           (gnus-activate-group to-newsgroup nil nil to-method)
10626           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10627                                      to-newsgroup))
10628               (or (and (gnus-request-create-group to-newsgroup to-method)
10629                        (gnus-activate-group
10630                         to-newsgroup nil nil to-method)
10631                        (gnus-subscribe-group to-newsgroup))
10632                   (error "Couldn't create group %s" to-newsgroup)))
10633           (error "No such group: %s" to-newsgroup)))
10634     to-newsgroup))
10635
10636 (defun gnus-summary-save-parts (type dir n &optional reverse)
10637   "Save parts matching TYPE to DIR.
10638 If REVERSE, save parts that do not match TYPE."
10639   (interactive
10640    (list (read-string "Save parts of type: "
10641                       (or (car gnus-summary-save-parts-type-history)
10642                           gnus-summary-save-parts-default-mime)
10643                       'gnus-summary-save-parts-type-history)
10644          (setq gnus-summary-save-parts-last-directory
10645                (read-file-name "Save to directory: "
10646                                gnus-summary-save-parts-last-directory
10647                                nil t))
10648          current-prefix-arg))
10649   (gnus-summary-iterate n
10650     (let ((gnus-display-mime-function nil)
10651           (gnus-inhibit-treatment t))
10652       (gnus-summary-select-article))
10653     (save-excursion
10654       (set-buffer gnus-article-buffer)
10655       (let ((handles (or gnus-article-mime-handles
10656                          (mm-dissect-buffer nil gnus-article-loose-mime)
10657                          (mm-uu-dissect))))
10658         (when handles
10659           (gnus-summary-save-parts-1 type dir handles reverse)
10660           (unless gnus-article-mime-handles ;; Don't destroy this case.
10661             (mm-destroy-parts handles)))))))
10662
10663 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10664   (if (stringp (car handle))
10665       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10666               (cdr handle))
10667     (when (if reverse
10668               (not (string-match type (mm-handle-media-type handle)))
10669             (string-match type (mm-handle-media-type handle)))
10670       (let ((file (expand-file-name
10671                    (file-name-nondirectory
10672                     (or
10673                      (mail-content-type-get
10674                       (mm-handle-disposition handle) 'filename)
10675                      (concat gnus-newsgroup-name
10676                              "." (number-to-string
10677                                   (cdr gnus-article-current)))))
10678                    dir)))
10679         (unless (file-exists-p file)
10680           (mm-save-part-to-file handle file))))))
10681
10682 ;; Summary extract commands
10683
10684 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10685   (let ((buffer-read-only nil)
10686         (article (gnus-summary-article-number))
10687         after-article b e)
10688     (unless (gnus-summary-goto-subject article)
10689       (error "No such article: %d" article))
10690     (gnus-summary-position-point)
10691     ;; If all commands are to be bunched up on one line, we collect
10692     ;; them here.
10693     (unless gnus-view-pseudos-separately
10694       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10695             files action)
10696         (while ps
10697           (setq action (cdr (assq 'action (car ps))))
10698           (setq files (list (cdr (assq 'name (car ps)))))
10699           (while (and ps (cdr ps)
10700                       (string= (or action "1")
10701                                (or (cdr (assq 'action (cadr ps))) "2")))
10702             (push (cdr (assq 'name (cadr ps))) files)
10703             (setcdr ps (cddr ps)))
10704           (when files
10705             (when (not (string-match "%s" action))
10706               (push " " files))
10707             (push " " files)
10708             (when (assq 'execute (car ps))
10709               (setcdr (assq 'execute (car ps))
10710                       (funcall (if (string-match "%s" action)
10711                                    'format 'concat)
10712                                action
10713                                (mapconcat
10714                                 (lambda (f)
10715                                   (if (equal f " ")
10716                                       f
10717                                     (gnus-quote-arg-for-sh-or-csh f)))
10718                                 files " ")))))
10719           (setq ps (cdr ps)))))
10720     (if (and gnus-view-pseudos (not not-view))
10721         (while pslist
10722           (when (assq 'execute (car pslist))
10723             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10724                                   (eq gnus-view-pseudos 'not-confirm)))
10725           (setq pslist (cdr pslist)))
10726       (save-excursion
10727         (while pslist
10728           (setq after-article (or (cdr (assq 'article (car pslist)))
10729                                   (gnus-summary-article-number)))
10730           (gnus-summary-goto-subject after-article)
10731           (forward-line 1)
10732           (setq b (point))
10733           (insert "    " (file-name-nondirectory
10734                           (cdr (assq 'name (car pslist))))
10735                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10736           (setq e (point))
10737           (forward-line -1)             ; back to `b'
10738           (gnus-add-text-properties
10739            b (1- e) (list 'gnus-number gnus-reffed-article-number
10740                           gnus-mouse-face-prop gnus-mouse-face))
10741           (gnus-data-enter
10742            after-article gnus-reffed-article-number
10743            gnus-unread-mark b (car pslist) 0 (- e b))
10744           (setq gnus-newsgroup-unreads
10745                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10746                                          gnus-reffed-article-number))
10747           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10748           (setq pslist (cdr pslist)))))))
10749
10750 (defun gnus-pseudos< (p1 p2)
10751   (let ((c1 (cdr (assq 'action p1)))
10752         (c2 (cdr (assq 'action p2))))
10753     (and c1 c2 (string< c1 c2))))
10754
10755 (defun gnus-request-pseudo-article (props)
10756   (cond ((assq 'execute props)
10757          (gnus-execute-command (cdr (assq 'execute props)))))
10758   (let ((gnus-current-article (gnus-summary-article-number)))
10759     (gnus-run-hooks 'gnus-mark-article-hook)))
10760
10761 (defun gnus-execute-command (command &optional automatic)
10762   (save-excursion
10763     (gnus-article-setup-buffer)
10764     (set-buffer gnus-article-buffer)
10765     (setq buffer-read-only nil)
10766     (let ((command (if automatic command
10767                      (read-string "Command: " (cons command 0)))))
10768       (erase-buffer)
10769       (insert "$ " command "\n\n")
10770       (if gnus-view-pseudo-asynchronously
10771           (start-process "gnus-execute" (current-buffer) shell-file-name
10772                          shell-command-switch command)
10773         (call-process shell-file-name nil t nil
10774                       shell-command-switch command)))))
10775
10776 ;; Summary kill commands.
10777
10778 (defun gnus-summary-edit-global-kill (article)
10779   "Edit the \"global\" kill file."
10780   (interactive (list (gnus-summary-article-number)))
10781   (gnus-group-edit-global-kill article))
10782
10783 (defun gnus-summary-edit-local-kill ()
10784   "Edit a local kill file applied to the current newsgroup."
10785   (interactive)
10786   (setq gnus-current-headers (gnus-summary-article-header))
10787   (gnus-group-edit-local-kill
10788    (gnus-summary-article-number) gnus-newsgroup-name))
10789
10790 ;;; Header reading.
10791
10792 (defun gnus-read-header (id &optional header)
10793   "Read the headers of article ID and enter them into the Gnus system."
10794   (let ((group gnus-newsgroup-name)
10795         (gnus-override-method
10796          (or
10797           gnus-override-method
10798           (and (gnus-news-group-p gnus-newsgroup-name)
10799                (car (gnus-refer-article-methods)))))
10800         where)
10801     ;; First we check to see whether the header in question is already
10802     ;; fetched.
10803     (if (stringp id)
10804         ;; This is a Message-ID.
10805         (setq header (or header (gnus-id-to-header id)))
10806       ;; This is an article number.
10807       (setq header (or header (gnus-summary-article-header id))))
10808     (if (and header
10809              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10810         ;; We have found the header.
10811         header
10812       ;; If this is a sparse article, we have to nix out its
10813       ;; previous entry in the thread hashtb.
10814       (when (and header
10815                  (gnus-summary-article-sparse-p (mail-header-number header)))
10816         (let* ((parent (gnus-parent-id (mail-header-references header)))
10817                (thread (and parent (gnus-id-to-thread parent))))
10818           (when thread
10819             (delq (assq header thread) thread))))
10820       ;; We have to really fetch the header to this article.
10821       (save-excursion
10822         (set-buffer nntp-server-buffer)
10823         (when (setq where (gnus-request-head id group))
10824           (nnheader-fold-continuation-lines)
10825           (goto-char (point-max))
10826           (insert ".\n")
10827           (goto-char (point-min))
10828           (insert "211 ")
10829           (princ (cond
10830                   ((numberp id) id)
10831                   ((cdr where) (cdr where))
10832                   (header (mail-header-number header))
10833                   (t gnus-reffed-article-number))
10834                  (current-buffer))
10835           (insert " Article retrieved.\n"))
10836         (if (or (not where)
10837                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10838             ()                          ; Malformed head.
10839           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10840             (when (and (stringp id)
10841                        (not (string= (gnus-group-real-name group)
10842                                      (car where))))
10843               ;; If we fetched by Message-ID and the article came
10844               ;; from a different group, we fudge some bogus article
10845               ;; numbers for this article.
10846               (mail-header-set-number header gnus-reffed-article-number))
10847             (save-excursion
10848               (set-buffer gnus-summary-buffer)
10849               (decf gnus-reffed-article-number)
10850               (gnus-remove-header (mail-header-number header))
10851               (push header gnus-newsgroup-headers)
10852               (setq gnus-current-headers header)
10853               (push (mail-header-number header) gnus-newsgroup-limit)))
10854           header)))))
10855
10856 (defun gnus-remove-header (number)
10857   "Remove header NUMBER from `gnus-newsgroup-headers'."
10858   (if (and gnus-newsgroup-headers
10859            (= number (mail-header-number (car gnus-newsgroup-headers))))
10860       (pop gnus-newsgroup-headers)
10861     (let ((headers gnus-newsgroup-headers))
10862       (while (and (cdr headers)
10863                   (not (= number (mail-header-number (cadr headers)))))
10864         (pop headers))
10865       (when (cdr headers)
10866         (setcdr headers (cddr headers))))))
10867
10868 ;;;
10869 ;;; summary highlights
10870 ;;;
10871
10872 (defun gnus-highlight-selected-summary ()
10873   "Highlight selected article in summary buffer."
10874   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10875   (when gnus-summary-selected-face
10876     (save-excursion
10877       (let* ((beg (progn (beginning-of-line) (point)))
10878              (end (progn (end-of-line) (point)))
10879              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10880              (from (if (get-text-property beg gnus-mouse-face-prop)
10881                        beg
10882                      (or (next-single-property-change
10883                           beg gnus-mouse-face-prop nil end)
10884                          beg)))
10885              (to
10886               (if (= from end)
10887                   (- from 2)
10888                 (or (next-single-property-change
10889                      from gnus-mouse-face-prop nil end)
10890                     end))))
10891         ;; If no mouse-face prop on line we will have to = from = end,
10892         ;; so we highlight the entire line instead.
10893         (when (= (+ to 2) from)
10894           (setq from beg)
10895           (setq to end))
10896         (if gnus-newsgroup-selected-overlay
10897             ;; Move old overlay.
10898             (gnus-move-overlay
10899              gnus-newsgroup-selected-overlay from to (current-buffer))
10900           ;; Create new overlay.
10901           (gnus-overlay-put
10902            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10903            'face gnus-summary-selected-face))))))
10904
10905 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10906 (defun gnus-summary-highlight-line ()
10907   "Highlight current line according to `gnus-summary-highlight'."
10908   (let* ((list gnus-summary-highlight)
10909          (beg (gnus-point-at-bol))
10910          (article (gnus-summary-article-number))
10911          (score (or (cdr (assq (or article gnus-current-article)
10912                                gnus-newsgroup-scored))
10913                     gnus-summary-default-score 0))
10914          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10915          (inhibit-read-only t)
10916          (default gnus-summary-default-score)
10917          (default-high gnus-summary-default-high-score)
10918          (default-low gnus-summary-default-low-score))
10919     ;; Eval the cars of the lists until we find a match.
10920     (while (and list
10921                 (not (eval (caar list))))
10922       (setq list (cdr list)))
10923     (let ((face (cdar list)))
10924       (unless (eq face (get-text-property beg 'face))
10925         (gnus-put-text-property-excluding-characters-with-faces
10926          beg (gnus-point-at-eol) 'face
10927          (setq face (if (boundp face) (symbol-value face) face)))
10928         (when gnus-summary-highlight-line-function
10929           (funcall gnus-summary-highlight-line-function article face))))))
10930
10931 (defun gnus-update-read-articles (group unread &optional compute)
10932   "Update the list of read articles in GROUP.
10933 UNREAD is a sorted list."
10934   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10935          (entry (gnus-gethash group gnus-newsrc-hashtb))
10936          (info (nth 2 entry))
10937          (prev 1)
10938          read)
10939     (if (or (not info) (not active))
10940         ;; There is no info on this group if it was, in fact,
10941         ;; killed.  Gnus stores no information on killed groups, so
10942         ;; there's nothing to be done.
10943         ;; One could store the information somewhere temporarily,
10944         ;; perhaps...  Hmmm...
10945         ()
10946       ;; Remove any negative articles numbers.
10947       (while (and unread (< (car unread) 0))
10948         (setq unread (cdr unread)))
10949       ;; Remove any expired article numbers
10950       (while (and unread (< (car unread) (car active)))
10951         (setq unread (cdr unread)))
10952       ;; Compute the ranges of read articles by looking at the list of
10953       ;; unread articles.
10954       (while unread
10955         (when (/= (car unread) prev)
10956           (push (if (= prev (1- (car unread))) prev
10957                   (cons prev (1- (car unread))))
10958                 read))
10959         (setq prev (1+ (car unread)))
10960         (setq unread (cdr unread)))
10961       (when (<= prev (cdr active))
10962         (push (cons prev (cdr active)) read))
10963       (setq read (if (> (length read) 1) (nreverse read) read))
10964       (if compute
10965           read
10966         (save-excursion
10967           (let (setmarkundo)
10968             ;; Propagate the read marks to the backend.
10969             (when (gnus-check-backend-function 'request-set-mark group)
10970               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10971                     (add (gnus-remove-from-range read (gnus-info-read info))))
10972                 (when (or add del)
10973                   (unless (gnus-check-group group)
10974                     (error "Can't open server for %s" group))
10975                   (gnus-request-set-mark
10976                    group (delq nil (list (if add (list add 'add '(read)))
10977                                          (if del (list del 'del '(read))))))
10978                   (setq setmarkundo
10979                         `(gnus-request-set-mark
10980                           ,group
10981                           ',(delq nil (list
10982                                        (if del (list del 'add '(read)))
10983                                        (if add (list add 'del '(read))))))))))
10984             (set-buffer gnus-group-buffer)
10985             (gnus-undo-register
10986               `(progn
10987                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10988                  (gnus-info-set-read ',info ',(gnus-info-read info))
10989                  (gnus-get-unread-articles-in-group ',info
10990                                                     (gnus-active ,group))
10991                  (gnus-group-update-group ,group t)
10992                  ,setmarkundo))))
10993         ;; Enter this list into the group info.
10994         (gnus-info-set-read info read)
10995         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10996         (gnus-get-unread-articles-in-group info (gnus-active group))
10997         t))))
10998
10999 (defun gnus-offer-save-summaries ()
11000   "Offer to save all active summary buffers."
11001   (let (buffers)
11002     ;; Go through all buffers and find all summaries.
11003     (dolist (buffer (buffer-list))
11004       (when (and (setq buffer (buffer-name buffer))
11005                  (string-match "Summary" buffer)
11006                  (save-excursion
11007                    (set-buffer buffer)
11008                    ;; We check that this is, indeed, a summary buffer.
11009                    (and (eq major-mode 'gnus-summary-mode)
11010                         ;; Also make sure this isn't bogus.
11011                         gnus-newsgroup-prepared
11012                         ;; Also make sure that this isn't a
11013                         ;; dead summary buffer.
11014                         (not gnus-dead-summary-mode))))
11015         (push buffer buffers)))
11016     ;; Go through all these summary buffers and offer to save them.
11017     (when buffers
11018       (save-excursion
11019         (map-y-or-n-p
11020          "Update summary buffer %s? "
11021          (lambda (buf)
11022            (switch-to-buffer buf)
11023            (gnus-summary-exit))
11024          buffers)))))
11025
11026
11027 ;;; @ for mime-partial
11028 ;;;
11029
11030 (defun gnus-request-partial-message ()
11031   (save-excursion
11032     (let ((number (gnus-summary-article-number))
11033           (group gnus-newsgroup-name)
11034           (mother gnus-article-buffer))
11035       (set-buffer (get-buffer-create " *Partial Article*"))
11036       (erase-buffer)
11037       (setq mime-preview-buffer mother)
11038       (gnus-request-article-this-buffer number group)
11039       (mime-parse-buffer)
11040       )))
11041
11042 (autoload 'mime-combine-message/partial-pieces-automatically
11043   "mime-partial"
11044   "Internal method to combine message/partial messages automatically.")
11045
11046 (mime-add-condition
11047  'action '((type . message)(subtype . partial)
11048            (major-mode . gnus-original-article-mode)
11049            (method . mime-combine-message/partial-pieces-automatically)
11050            (summary-buffer-exp . gnus-summary-buffer)
11051            (request-partial-message-method . gnus-request-partial-message)
11052            ))
11053
11054
11055 ;;; @ for message/rfc822
11056 ;;;
11057
11058 (defun gnus-mime-extract-message/rfc822 (entity situation)
11059   "Burst a forwarded article."
11060   (save-excursion
11061     (set-buffer gnus-summary-buffer)
11062     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11063                                    gnus-newsgroup-name 'gnus-group-history))
11064            (gnus-group-marked (list group))
11065            article info)
11066       (with-temp-buffer
11067         (mime-insert-entity-content entity)
11068         (setq article (gnus-request-accept-article group)))
11069       (when (and (consp article)
11070                  (numberp (setq article (cdr article))))
11071         (setq info (gnus-get-info group))
11072         (gnus-info-set-read info
11073                             (gnus-remove-from-range (gnus-info-read info)
11074                                                     (list article)))
11075         (when (string-equal group gnus-newsgroup-name)
11076           (forward-line 1)
11077           (let (gnus-show-threads)
11078             (gnus-summary-goto-subject article t))
11079           (gnus-summary-clear-mark-forward 1))
11080         (set-buffer gnus-group-buffer)
11081         (gnus-group-get-new-news-this-group nil t)))))
11082
11083 (mime-add-condition
11084  'action '((type . message)(subtype . rfc822)
11085            (major-mode . gnus-original-article-mode)
11086            (method . gnus-mime-extract-message/rfc822)
11087            (mode . "extract")
11088            ))
11089
11090 (mime-add-condition
11091  'action '((type . message)(subtype . news)
11092            (major-mode . gnus-original-article-mode)
11093            (method . gnus-mime-extract-message/rfc822)
11094            (mode . "extract")
11095            ))
11096
11097 (defun gnus-mime-extract-multipart (entity situation)
11098   (let ((children (mime-entity-children entity))
11099         mime-acting-situation-to-override
11100         f)
11101     (while children
11102       (mime-play-entity (car children)
11103                         (cons (assq 'mode situation)
11104                               mime-acting-situation-to-override))
11105       (setq children (cdr children)))
11106     (if (setq f (cdr (assq 'after-method
11107                            mime-acting-situation-to-override)))
11108         (eval f)
11109       )))
11110
11111 (mime-add-condition
11112  'action '((type . multipart)
11113            (method . gnus-mime-extract-multipart)
11114            (mode . "extract")
11115            )
11116  'with-default)
11117
11118
11119 ;;; @ end
11120 ;;;
11121
11122 (defun gnus-summary-inherit-default-charset ()
11123   "Import `default-mime-charset' from summary buffer."
11124   (if (buffer-live-p gnus-summary-buffer)
11125       (if (local-variable-p 'default-mime-charset gnus-summary-buffer)
11126           (progn
11127             (make-local-variable 'default-mime-charset)
11128             (setq default-mime-charset
11129                   (with-current-buffer gnus-summary-buffer
11130                     default-mime-charset)))
11131         (kill-local-variable 'default-mime-charset))))
11132
11133 (defun gnus-summary-setup-default-charset ()
11134   "Setup newsgroup default charset."
11135   (if (equal gnus-newsgroup-name "nndraft:drafts")
11136       (progn
11137         (setq gnus-newsgroup-charset nil)
11138         (make-local-variable 'default-mime-charset)
11139         (setq default-mime-charset nil))
11140     (let ((ignored-charsets
11141            (or gnus-newsgroup-ephemeral-ignored-charsets
11142                (append
11143                 (and gnus-newsgroup-name
11144                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11145                 gnus-newsgroup-ignored-charsets)))
11146           charset)
11147       (setq gnus-newsgroup-charset
11148             (or gnus-newsgroup-ephemeral-charset
11149                 (when (and gnus-newsgroup-name
11150                            (setq charset (gnus-parameter-charset
11151                                           gnus-newsgroup-name)))
11152                   (make-local-variable 'default-mime-charset)
11153                   (setq default-mime-charset charset))
11154                 gnus-default-charset))
11155       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11156            ignored-charsets))))
11157
11158 ;;;
11159 ;;; Mime Commands
11160 ;;;
11161
11162 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11163   "Display the current article buffer fully MIME-buttonized.
11164 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11165 treated as multipart/mixed."
11166   (interactive "P")
11167   (require 'gnus-art)
11168   (let ((gnus-unbuttonized-mime-types nil)
11169         (gnus-mime-display-multipart-as-mixed show-all-parts))
11170     (gnus-summary-show-article)))
11171
11172 (defun gnus-summary-repair-multipart (article)
11173   "Add a Content-Type header to a multipart article without one."
11174   (interactive (list (gnus-summary-article-number)))
11175   (gnus-with-article article
11176     (message-narrow-to-head)
11177     (message-remove-header "Mime-Version")
11178     (goto-char (point-max))
11179     (insert "Mime-Version: 1.0\n")
11180     (widen)
11181     (when (search-forward "\n--" nil t)
11182       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11183         (message-narrow-to-head)
11184         (message-remove-header "Content-Type")
11185         (goto-char (point-max))
11186         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11187                         separator))
11188         (widen))))
11189   (let (gnus-mark-article-hook)
11190     (gnus-summary-select-article t t nil article)))
11191
11192 (defun gnus-summary-toggle-display-buttonized ()
11193   "Toggle the buttonizing of the article buffer."
11194   (interactive)
11195   (require 'gnus-art)
11196   (if (setq gnus-inhibit-mime-unbuttonizing
11197             (not gnus-inhibit-mime-unbuttonizing))
11198       (let ((gnus-unbuttonized-mime-types nil))
11199         (gnus-summary-show-article))
11200     (gnus-summary-show-article)))
11201
11202 ;;;
11203 ;;; Intelli-mouse commmands
11204 ;;;
11205
11206 (defun gnus-wheel-summary-scroll (event)
11207   (interactive "e")
11208   (let ((amount (if (memq 'shift (event-modifiers event))
11209                     (car gnus-wheel-scroll-amount)
11210                   (cdr gnus-wheel-scroll-amount)))
11211         (direction (- (* (static-if (featurep 'xemacs)
11212                              (event-button event)
11213                            (cond ((eq 'mouse-4 (event-basic-type event))
11214                                   4)
11215                                  ((eq 'mouse-5 (event-basic-type event))
11216                                   5)))
11217                          2) 9))
11218         edge)
11219     (gnus-summary-scroll-up (* amount direction))
11220     (when (gnus-eval-in-buffer-window gnus-article-buffer
11221             (save-restriction
11222               (widen)
11223               (and (if (< 0 direction)
11224                        (gnus-article-next-page 0)
11225                      (gnus-article-prev-page 0)
11226                      (bobp))
11227                    (if (setq edge (get-text-property
11228                                    (point-min) 'gnus-wheel-edge))
11229                        (setq edge (* edge direction))
11230                      (setq edge -1))
11231                    (or (plusp edge)
11232                        (let ((buffer-read-only nil)
11233                              (inhibit-read-only t))
11234                          (put-text-property (point-min) (point-max)
11235                                             'gnus-wheel-edge direction)
11236                          nil))
11237                    (or (> edge gnus-wheel-edge-resistance)
11238                        (let ((buffer-read-only nil)
11239                              (inhibit-read-only t))
11240                          (put-text-property (point-min) (point-max)
11241                                             'gnus-wheel-edge
11242                                             (* (1+ edge) direction))
11243                          nil))
11244                    (eq last-command 'gnus-wheel-summary-scroll))))
11245       (gnus-summary-next-article nil nil (minusp direction)))))
11246
11247 (defun gnus-wheel-install ()
11248   "Enable mouse wheel support on summary window."
11249   (when gnus-use-wheel
11250     (let ((keys
11251            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11252       (dolist (key keys)
11253         (define-key gnus-summary-mode-map key
11254           'gnus-wheel-summary-scroll)))))
11255
11256 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11257
11258 ;;;
11259 ;;; Traditional PGP commmands
11260 ;;;
11261
11262 (defun gnus-summary-decrypt-article (&optional force)
11263   "Decrypt the current article in traditional PGP way.
11264 This will have permanent effect only in mail groups.
11265 If FORCE is non-nil, allow editing of articles even in read-only
11266 groups."
11267   (interactive "P")
11268   (gnus-summary-select-article t)
11269   (gnus-eval-in-buffer-window gnus-article-buffer
11270     (save-excursion
11271       (save-restriction
11272         (widen)
11273         (goto-char (point-min))
11274         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11275           (error "Not a traditional PGP message!"))
11276         (let ((armor-start (match-beginning 0)))
11277           (if (and (pgg-decrypt-region armor-start (point-max))
11278                    (or force (not (gnus-group-read-only-p))))
11279               (let ((inhibit-read-only t)
11280                     buffer-read-only)
11281                 (delete-region armor-start
11282                                (progn
11283                                  (re-search-forward "^-+END PGP" nil t)
11284                                  (beginning-of-line 2)
11285                                  (point)))
11286                 (insert-buffer-substring pgg-output-buffer))))))))
11287
11288 (defun gnus-summary-verify-article ()
11289   "Verify the current article in traditional PGP way."
11290   (interactive)
11291   (save-excursion
11292     (set-buffer gnus-original-article-buffer)
11293     (goto-char (point-min))
11294     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11295       (error "Not a traditional PGP message!"))
11296     (re-search-forward "^-+END PGP" nil t)
11297     (beginning-of-line 2)
11298     (call-interactively (function pgg-verify-region))))
11299
11300 ;;;
11301 ;;; Generic summary marking commands
11302 ;;;
11303
11304 (defvar gnus-summary-marking-alist
11305   '((read gnus-del-mark "d")
11306     (unread gnus-unread-mark "u")
11307     (ticked gnus-ticked-mark "!")
11308     (dormant gnus-dormant-mark "?")
11309     (expirable gnus-expirable-mark "e"))
11310   "An alist of names/marks/keystrokes.")
11311
11312 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11313 (defvar gnus-summary-mark-map)
11314
11315 (defun gnus-summary-make-all-marking-commands ()
11316   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11317   (dolist (elem gnus-summary-marking-alist)
11318     (apply 'gnus-summary-make-marking-command elem)))
11319
11320 (defun gnus-summary-make-marking-command (name mark keystroke)
11321   (let ((map (make-sparse-keymap)))
11322     (define-key gnus-summary-generic-mark-map keystroke map)
11323     (dolist (lway `((next "next" next nil "n")
11324                     (next-unread "next unread" next t "N")
11325                     (prev "previous" prev nil "p")
11326                     (prev-unread "previous unread" prev t "P")
11327                     (nomove "" nil nil ,keystroke)))
11328       (let ((func (gnus-summary-make-marking-command-1
11329                    mark (car lway) lway name)))
11330         (setq func (eval func))
11331         (define-key map (nth 4 lway) func)))))
11332
11333 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11334   `(defun ,(intern
11335             (format "gnus-summary-put-mark-as-%s%s"
11336                     name (if (eq way 'nomove)
11337                              ""
11338                            (concat "-" (symbol-name way)))))
11339      (n)
11340      ,(format
11341        "Mark the current article as %s%s.
11342 If N, the prefix, then repeat N times.
11343 If N is negative, move in reverse order.
11344 The difference between N and the actual number of articles marked is
11345 returned."
11346        name (car (cdr lway)))
11347      (interactive "p")
11348      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11349
11350 (defun gnus-summary-generic-mark (n mark move unread)
11351   "Mark N articles with MARK."
11352   (unless (eq major-mode 'gnus-summary-mode)
11353     (error "This command can only be used in the summary buffer"))
11354   (gnus-summary-show-thread)
11355   (let ((nummove
11356          (cond
11357           ((eq move 'next) 1)
11358           ((eq move 'prev) -1)
11359           (t 0))))
11360     (if (zerop nummove)
11361         (setq n 1)
11362       (when (< n 0)
11363         (setq n (abs n)
11364               nummove (* -1 nummove))))
11365     (while (and (> n 0)
11366                 (gnus-summary-mark-article nil mark)
11367                 (zerop (gnus-summary-next-subject nummove unread t)))
11368       (setq n (1- n)))
11369     (when (/= 0 n)
11370       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11371     (gnus-summary-recenter)
11372     (gnus-summary-position-point)
11373     (gnus-set-mode-line 'summary)
11374     n))
11375
11376 (defun gnus-summary-insert-articles (articles)
11377   (when (setq articles
11378               (gnus-sorted-difference articles
11379                                       (mapcar (lambda (h)
11380                                                 (mail-header-number h))
11381                                               gnus-newsgroup-headers)))
11382     (setq gnus-newsgroup-headers
11383           (merge 'list
11384                  gnus-newsgroup-headers
11385                  (gnus-fetch-headers articles)
11386                  'gnus-article-sort-by-number))
11387     ;; Suppress duplicates?
11388     (when gnus-suppress-duplicates
11389       (gnus-dup-suppress-articles))
11390
11391     ;; We might want to build some more threads first.
11392     (when (and gnus-fetch-old-headers
11393                (eq gnus-headers-retrieved-by 'nov))
11394       (if (eq gnus-fetch-old-headers 'invisible)
11395           (gnus-build-all-threads)
11396         (gnus-build-old-threads)))
11397     ;; Let the Gnus agent mark articles as read.
11398     (when gnus-agent
11399       (gnus-agent-get-undownloaded-list))
11400     ;; Remove list identifiers from subject
11401     (when gnus-list-identifiers
11402       (gnus-summary-remove-list-identifiers))
11403     ;; First and last article in this newsgroup.
11404     (when gnus-newsgroup-headers
11405       (setq gnus-newsgroup-begin
11406             (mail-header-number (car gnus-newsgroup-headers))
11407             gnus-newsgroup-end
11408             (mail-header-number
11409              (gnus-last-element gnus-newsgroup-headers))))
11410     (when gnus-use-scoring
11411       (gnus-possibly-score-headers))))
11412
11413 (defun gnus-summary-insert-old-articles (&optional all)
11414   "Insert all old articles in this group.
11415 If ALL is non-nil, already read articles become readable.
11416 If ALL is a number, fetch this number of articles."
11417   (interactive "P")
11418   (prog1
11419       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11420             older len)
11421         (setq older
11422               (gnus-sorted-difference
11423                (gnus-uncompress-range (list gnus-newsgroup-active))
11424                old))
11425         (setq len (length older))
11426         (cond
11427          ((null older) nil)
11428          ((numberp all)
11429           (if (< all len)
11430               (setq older (last older all))))
11431          (all nil)
11432          (t
11433           (if (and (numberp gnus-large-newsgroup)
11434                    (> len gnus-large-newsgroup))
11435               (let* ((cursor-in-echo-area nil)
11436                      (initial (gnus-parameter-large-newsgroup-initial
11437                                gnus-newsgroup-name))
11438                      (input
11439                       (read-string
11440                        (format
11441                         "How many articles from %s (%s %d): "
11442                         (gnus-limit-string
11443                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11444                         (if initial "max" "default")
11445                         len)
11446                        (if initial
11447                            (cons (number-to-string initial)
11448                                  0)))))
11449                 (unless (string-match "^[ \t]*$" input)
11450                   (setq all (string-to-number input))
11451                   (if (< all len)
11452                       (setq older (last older all))))))))
11453         (if (not older)
11454             (message "No old news.")
11455           (gnus-summary-insert-articles older)
11456           (gnus-summary-limit (gnus-sorted-nunion old older))))
11457     (gnus-summary-position-point)))
11458
11459 (defun gnus-summary-insert-new-articles ()
11460   "Insert all new articles in this group."
11461   (interactive)
11462   (prog1
11463       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11464             (old-active gnus-newsgroup-active)
11465             (nnmail-fetched-sources (list t))
11466             i new)
11467         (setq gnus-newsgroup-active
11468               (gnus-activate-group gnus-newsgroup-name 'scan))
11469         (setq i (cdr gnus-newsgroup-active))
11470         (while (> i (cdr old-active))
11471           (push i new)
11472           (decf i))
11473         (if (not new)
11474             (message "No gnus is bad news.")
11475           (gnus-summary-insert-articles new)
11476           (setq gnus-newsgroup-unreads
11477                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11478           (gnus-summary-limit (gnus-sorted-nunion old new))))
11479     (gnus-summary-position-point)))
11480
11481 (gnus-summary-make-all-marking-commands)
11482
11483 (gnus-ems-redefine)
11484
11485 (provide 'gnus-sum)
11486
11487 (run-hooks 'gnus-sum-load-hook)
11488
11489 ;;; gnus-sum.el ends here