Applied a patch from Keiichi-san.
[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: `gnus-simplify-subject-re',
151 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
152   :group 'gnus-thread
153   :type '(repeat function))
154
155 (defcustom gnus-simplify-ignored-prefixes nil
156   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
157   :group 'gnus-thread
158   :type '(choice (const :tag "off" nil)
159                  regexp))
160
161 (defcustom gnus-build-sparse-threads nil
162   "*If non-nil, fill in the gaps in threads.
163 If `some', only fill in the gaps that are needed to tie loose threads
164 together.  If `more', fill in all leaf nodes that Gnus can find.  If
165 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  (const some)
169                  (const more)
170                  (sexp :menu-tag "all" t)))
171
172 (defcustom gnus-summary-thread-gathering-function
173   'gnus-gather-threads-by-subject
174   "*Function used for gathering loose threads.
175 There are two pre-defined functions: `gnus-gather-threads-by-subject',
176 which only takes Subjects into consideration; and
177 `gnus-gather-threads-by-references', which compared the References
178 headers of the articles to find matches."
179   :group 'gnus-thread
180   :type '(radio (function-item gnus-gather-threads-by-subject)
181                 (function-item gnus-gather-threads-by-references)
182                 (function :tag "other")))
183
184 (defcustom gnus-summary-same-subject ""
185   "*String indicating that the current article has the same subject as the previous.
186 This variable will only be used if the value of
187 `gnus-summary-make-false-root' is `empty'."
188   :group 'gnus-summary-format
189   :type 'string)
190
191 (defcustom gnus-summary-goto-unread t
192   "*If t, many commands will go to the next unread article.
193 This applies to marking commands as well as other commands that
194 \"naturally\" select the next article, like, for instance, `SPC' at
195 the end of an article.
196
197 If nil, the marking commands do NOT go to the next unread article
198 (they go to the next article instead).  If `never', commands that
199 usually go to the next unread article, will go to the next article,
200 whether it is read or not."
201   :group 'gnus-summary-marks
202   :link '(custom-manual "(gnus)Setting Marks")
203   :type '(choice (const :tag "off" nil)
204                  (const never)
205                  (sexp :menu-tag "on" t)))
206
207 (defcustom gnus-summary-default-score 0
208   "*Default article score level.
209 All scores generated by the score files will be added to this score.
210 If this variable is nil, scoring will be disabled."
211   :group 'gnus-score-default
212   :type '(choice (const :tag "disable")
213                  integer))
214
215 (defcustom gnus-summary-default-high-score 0
216   "*Default threshold for a high scored article.
217 An article will be highlighted as high scored if its score is greater
218 than this score."
219   :group 'gnus-score-default
220   :type 'integer)
221
222 (defcustom gnus-summary-default-low-score 0
223   "*Default threshold for a low scored article.
224 An article will be highlighted as low scored if its score is smaller
225 than this score."
226   :group 'gnus-score-default
227   :type 'integer)
228
229 (defcustom gnus-summary-zcore-fuzz 0
230   "*Fuzziness factor for the zcore in the summary buffer.
231 Articles with scores closer than this to `gnus-summary-default-score'
232 will not be marked."
233   :group 'gnus-summary-format
234   :type 'integer)
235
236 (defcustom gnus-simplify-subject-fuzzy-regexp nil
237   "*Strings to be removed when doing fuzzy matches.
238 This can either be a regular expression or list of regular expressions
239 that will be removed from subject strings if fuzzy subject
240 simplification is selected."
241   :group 'gnus-thread
242   :type '(repeat regexp))
243
244 (defcustom gnus-show-threads t
245   "*If non-nil, display threads in summary mode."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-hide-subtree nil
250   "*If non-nil, hide all threads initially.
251 This can be a predicate specifier which says which threads to hide.
252 If threads are hidden, you have to run the command
253 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
254 to expose hidden threads."
255   :group 'gnus-thread
256   :type 'boolean)
257
258 (defcustom gnus-thread-hide-killed t
259   "*If non-nil, hide killed threads automatically."
260   :group 'gnus-thread
261   :type 'boolean)
262
263 (defcustom gnus-thread-ignore-subject t
264   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
265 If nil, articles that have different subjects from their parents will
266 start separate threads."
267   :group 'gnus-thread
268   :type 'boolean)
269
270 (defcustom gnus-thread-operation-ignore-subject t
271   "*If non-nil, subjects will be ignored when doing thread commands.
272 This affects commands like `gnus-summary-kill-thread' and
273 `gnus-summary-lower-thread'.
274
275 If this variable is nil, articles in the same thread with different
276 subjects will not be included in the operation in question.  If this
277 variable is `fuzzy', only articles that have subjects that are fuzzily
278 equal will be included."
279   :group 'gnus-thread
280   :type '(choice (const :tag "off" nil)
281                  (const fuzzy)
282                  (sexp :tag "on" t)))
283
284 (defcustom gnus-thread-indent-level 4
285   "*Number that says how much each sub-thread should be indented."
286   :group 'gnus-thread
287   :type 'integer)
288
289 (defcustom gnus-auto-extend-newsgroup t
290   "*If non-nil, extend newsgroup forward and backward when requested."
291   :group 'gnus-summary-choose
292   :type 'boolean)
293
294 (defcustom gnus-auto-select-first t
295   "*If non-nil, select the article under point.
296 Which article this is is controlled by the `gnus-auto-select-subject'
297 variable.
298
299 If you want to prevent automatic selection of articles in some
300 newsgroups, set the variable to nil in `gnus-select-group-hook'."
301   :group 'gnus-group-select
302   :type '(choice (const :tag "none" nil)
303                  (sexp :menu-tag "first" t)))
304
305 (defcustom gnus-auto-select-subject 'unread
306   "*Says what subject to place under point when entering a group.
307
308 This variable can either be the symbols `first' (place point on the
309 first subject), `unread' (place point on the subject line of the first
310 unread article), `best' (place point on the subject line of the
311 higest-scored article), `unseen' (place point on the subject line of
312 the first unseen article), 'unseen-or-unread' (place point on the subject
313 line of the first unseen article or, if all article have been seen, on the
314 subject line of the first unread article), or a function to be called to
315 place point on some subject line."
316   :group 'gnus-group-select
317   :type '(choice (const best)
318                  (const unread)
319                  (const first)
320                  (const unseen)
321                  (const unseen-or-unread)))
322
323 (defcustom gnus-dont-select-after-jump-to-other-group nil
324   "If non-nil, don't select the first unread article after entering the
325 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
326 it is depend on the value of `gnus-auto-select-first' whether to select
327 or not."
328   :group 'gnus-group-select
329   :type 'boolean)
330
331 (defcustom gnus-auto-select-next t
332   "*If non-nil, offer to go to the next group from the end of the previous.
333 If the value is t and the next newsgroup is empty, Gnus will exit
334 summary mode and go back to group mode.  If the value is neither nil
335 nor t, Gnus will select the following unread newsgroup.  In
336 particular, if the value is the symbol `quietly', the next unread
337 newsgroup will be selected without any confirmation, and if it is
338 `almost-quietly', the next group will be selected without any
339 confirmation if you are located on the last article in the group.
340 Finally, if this variable is `slightly-quietly', the `Z n' command
341 will go to the next group without confirmation."
342   :group 'gnus-summary-maneuvering
343   :type '(choice (const :tag "off" nil)
344                  (const quietly)
345                  (const almost-quietly)
346                  (const slightly-quietly)
347                  (sexp :menu-tag "on" t)))
348
349 (defcustom gnus-auto-select-same nil
350   "*If non-nil, select the next article with the same subject.
351 If there are no more articles with the same subject, go to
352 the first unread article."
353   :group 'gnus-summary-maneuvering
354   :type 'boolean)
355
356 (defcustom gnus-summary-check-current nil
357   "*If non-nil, consider the current article when moving.
358 The \"unread\" movement commands will stay on the same line if the
359 current article is unread."
360   :group 'gnus-summary-maneuvering
361   :type 'boolean)
362
363 (defcustom gnus-auto-center-summary t
364   "*If non-nil, always center the current summary buffer.
365 In particular, if `vertical' do only vertical recentering.  If non-nil
366 and non-`vertical', do both horizontal and vertical recentering."
367   :group 'gnus-summary-maneuvering
368   :type '(choice (const :tag "none" nil)
369                  (const vertical)
370                  (integer :tag "height")
371                  (sexp :menu-tag "both" t)))
372
373 (defcustom gnus-show-all-headers nil
374   "*If non-nil, don't hide any headers."
375   :group 'gnus-article-hiding
376   :group 'gnus-article-headers
377   :type 'boolean)
378
379 (defcustom gnus-summary-ignore-duplicates nil
380   "*If non-nil, ignore articles with identical Message-ID headers."
381   :group 'gnus-summary
382   :type 'boolean)
383
384 (defcustom gnus-single-article-buffer t
385   "*If non-nil, display all articles in the same buffer.
386 If nil, each group will get its own article buffer."
387   :group 'gnus-article-various
388   :type 'boolean)
389
390 (defcustom gnus-break-pages t
391   "*If non-nil, do page breaking on articles.
392 The page delimiter is specified by the `gnus-page-delimiter'
393 variable."
394   :group 'gnus-article-various
395   :type 'boolean)
396
397 (defcustom gnus-show-mime t
398   "*If non-nil, do mime processing of articles.
399 The articles will simply be fed to the function given by
400 `gnus-article-display-method-for-mime'."
401   :group 'gnus-article-mime
402   :type 'boolean)
403
404 (defcustom gnus-move-split-methods nil
405   "*Variable used to suggest where articles are to be moved to.
406 It uses the same syntax as the `gnus-split-methods' variable.
407 However, whereas `gnus-split-methods' specifies file names as targets,
408 this variable specifies group names."
409   :group 'gnus-summary-mail
410   :type '(repeat (choice (list :value (fun) function)
411                          (cons :value ("" "") regexp (repeat string))
412                          (sexp :value nil))))
413
414 (defcustom gnus-unread-mark ?\ ;;;Whitespace
415   "*Mark used for unread articles."
416   :group 'gnus-summary-marks
417   :type 'character)
418
419 (defcustom gnus-ticked-mark ?!
420   "*Mark used for ticked articles."
421   :group 'gnus-summary-marks
422   :type 'character)
423
424 (defcustom gnus-dormant-mark ??
425   "*Mark used for dormant articles."
426   :group 'gnus-summary-marks
427   :type 'character)
428
429 (defcustom gnus-del-mark ?r
430   "*Mark used for del'd articles."
431   :group 'gnus-summary-marks
432   :type 'character)
433
434 (defcustom gnus-read-mark ?R
435   "*Mark used for read articles."
436   :group 'gnus-summary-marks
437   :type 'character)
438
439 (defcustom gnus-expirable-mark ?E
440   "*Mark used for expirable articles."
441   :group 'gnus-summary-marks
442   :type 'character)
443
444 (defcustom gnus-killed-mark ?K
445   "*Mark used for killed articles."
446   :group 'gnus-summary-marks
447   :type 'character)
448
449 (defcustom gnus-spam-mark ?H
450   "*Mark used for spam articles."
451   :group 'gnus-summary-marks
452   :type 'character)
453
454 (defcustom gnus-souped-mark ?F
455   "*Mark used for souped articles."
456   :group 'gnus-summary-marks
457   :type 'character)
458
459 (defcustom gnus-kill-file-mark ?X
460   "*Mark used for articles killed by kill files."
461   :group 'gnus-summary-marks
462   :type 'character)
463
464 (defcustom gnus-low-score-mark ?Y
465   "*Mark used for articles with a low score."
466   :group 'gnus-summary-marks
467   :type 'character)
468
469 (defcustom gnus-catchup-mark ?C
470   "*Mark used for articles that are caught up."
471   :group 'gnus-summary-marks
472   :type 'character)
473
474 (defcustom gnus-replied-mark ?A
475   "*Mark used for articles that have been replied to."
476   :group 'gnus-summary-marks
477   :type 'character)
478
479 (defcustom gnus-forwarded-mark ?F
480   "*Mark used for articles that have been forwarded."
481   :group 'gnus-summary-marks
482   :type 'character)
483
484 (defcustom gnus-recent-mark ?N
485   "*Mark used for articles that are recent."
486   :group 'gnus-summary-marks
487   :type 'character)
488
489 (defcustom gnus-cached-mark ?*
490   "*Mark used for articles that are in the cache."
491   :group 'gnus-summary-marks
492   :type 'character)
493
494 (defcustom gnus-saved-mark ?S
495   "*Mark used for articles that have been saved."
496   :group 'gnus-summary-marks
497   :type 'character)
498
499 (defcustom gnus-unseen-mark ?.
500   "*Mark used for articles that haven't been seen."
501   :group 'gnus-summary-marks
502   :type 'character)
503
504 (defcustom gnus-no-mark ?\ ;;;Whitespace
505   "*Mark used for articles that have no other secondary mark."
506   :group 'gnus-summary-marks
507   :type 'character)
508
509 (defcustom gnus-ancient-mark ?O
510   "*Mark used for ancient articles."
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-sparse-mark ?Q
515   "*Mark used for sparsely reffed articles."
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-canceled-mark ?G
520   "*Mark used for canceled articles."
521   :group 'gnus-summary-marks
522   :type 'character)
523
524 (defcustom gnus-duplicate-mark ?M
525   "*Mark used for duplicate articles."
526   :group 'gnus-summary-marks
527   :type 'character)
528
529 (defcustom gnus-undownloaded-mark ?@
530   "*Mark used for articles that weren't downloaded."
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-downloadable-mark ?%
535   "*Mark used for articles that are to be downloaded."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-unsendable-mark ?=
540   "*Mark used for articles that won't be sent."
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-score-over-mark ?+
545   "*Score mark used for articles with high scores."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-score-below-mark ?-
550   "*Score mark used for articles with low scores."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
555   "*There is no thread under the article."
556   :group 'gnus-summary-marks
557   :type 'character)
558
559 (defcustom gnus-not-empty-thread-mark ?=
560   "*There is a thread under the article."
561   :group 'gnus-summary-marks
562   :type 'character)
563
564 (defcustom gnus-view-pseudo-asynchronously nil
565   "*If non-nil, Gnus will view pseudo-articles asynchronously."
566   :group 'gnus-extract-view
567   :type 'boolean)
568
569 (defcustom gnus-auto-expirable-marks
570   (list gnus-spam-mark gnus-killed-mark gnus-del-mark gnus-catchup-mark
571         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
572         gnus-souped-mark gnus-duplicate-mark)
573   "*The list of marks converted into expiration if a group is auto-expirable."
574   :version "21.1"
575   :group 'gnus-summary
576   :type '(repeat character))
577
578 (defcustom gnus-inhibit-user-auto-expire t
579   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
580   :version "21.1"
581   :group 'gnus-summary
582   :type 'boolean)
583
584 (defcustom gnus-view-pseudos nil
585   "*If `automatic', pseudo-articles will be viewed automatically.
586 If `not-confirm', pseudos will be viewed automatically, and the user
587 will not be asked to confirm the command."
588   :group 'gnus-extract-view
589   :type '(choice (const :tag "off" nil)
590                  (const automatic)
591                  (const not-confirm)))
592
593 (defcustom gnus-view-pseudos-separately t
594   "*If non-nil, one pseudo-article will be created for each file to be viewed.
595 If nil, all files that use the same viewing command will be given as a
596 list of parameters to that command."
597   :group 'gnus-extract-view
598   :type 'boolean)
599
600 (defcustom gnus-insert-pseudo-articles t
601   "*If non-nil, insert pseudo-articles when decoding articles."
602   :group 'gnus-extract-view
603   :type 'boolean)
604
605 (defcustom gnus-summary-dummy-line-format
606   "  %(:                          :%) %S\n"
607   "*The format specification for the dummy roots in the summary buffer.
608 It works along the same lines as a normal formatting string,
609 with some simple extensions.
610
611 %S  The subject
612
613 General format specifiers can also be used.
614 See `(gnus)Formatting Variables'."
615   :link '(custom-manual "(gnus)Formatting Variables")
616   :group 'gnus-threading
617   :type 'string)
618
619 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
620   "*The format specification for the summary mode line.
621 It works along the same lines as a normal formatting string,
622 with some simple extensions:
623
624 %G  Group name
625 %p  Unprefixed group name
626 %A  Current article number
627 %z  Current article score
628 %V  Gnus version
629 %U  Number of unread articles in the group
630 %e  Number of unselected articles in the group
631 %Z  A string with unread/unselected article counts
632 %g  Shortish group name
633 %S  Subject of the current article
634 %u  User-defined spec
635 %s  Current score file name
636 %d  Number of dormant articles
637 %r  Number of articles that have been marked as read in this session
638 %E  Number of articles expunged by the score files"
639   :group 'gnus-summary-format
640   :type 'string)
641
642 (defcustom gnus-list-identifiers nil
643   "Regexp that matches list identifiers to be removed from subject.
644 This can also be a list of regexps."
645   :version "21.1"
646   :group 'gnus-summary-format
647   :group 'gnus-article-hiding
648   :type '(choice (const :tag "none" nil)
649                  (regexp :value ".*")
650                  (repeat :value (".*") regexp)))
651
652 (defcustom gnus-summary-mark-below 0
653   "*Mark all articles with a score below this variable as read.
654 This variable is local to each summary buffer and usually set by the
655 score file."
656   :group 'gnus-score-default
657   :type 'integer)
658
659 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
660   "*List of functions used for sorting articles in the summary buffer.
661
662 Each function takes two articles and returns non-nil if the first
663 article should be sorted before the other.  If you use more than one
664 function, the primary sort function should be the last.  You should
665 probably always include `gnus-article-sort-by-number' in the list of
666 sorting functions -- preferably first.  Also note that sorting by date
667 is often much slower than sorting by number, and the sorting order is
668 very similar.  (Sorting by date means sorting by the time the message
669 was sent, sorting by number means sorting by arrival time.)
670
671 Ready-made functions include `gnus-article-sort-by-number',
672 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
673 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
674
675 When threading is turned on, the variable `gnus-thread-sort-functions'
676 controls how articles are sorted."
677   :group 'gnus-summary-sort
678   :type '(repeat (choice (function-item gnus-article-sort-by-number)
679                          (function-item gnus-article-sort-by-author)
680                          (function-item gnus-article-sort-by-subject)
681                          (function-item gnus-article-sort-by-date)
682                          (function-item gnus-article-sort-by-score)
683                          (function :tag "other"))))
684
685 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
686   "*List of functions used for sorting threads in the summary buffer.
687 By default, threads are sorted by article number.
688
689 Each function takes two threads and returns non-nil if the first
690 thread should be sorted before the other.  If you use more than one
691 function, the primary sort function should be the last.  You should
692 probably always include `gnus-thread-sort-by-number' in the list of
693 sorting functions -- preferably first.  Also note that sorting by date
694 is often much slower than sorting by number, and the sorting order is
695 very similar.  (Sorting by date means sorting by the time the message
696 was sent, sorting by number means sorting by arrival time.)
697
698 Ready-made functions include `gnus-thread-sort-by-number',
699 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
700 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
701 `gnus-thread-sort-by-most-recent-number',
702 `gnus-thread-sort-by-most-recent-date', and
703 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
704
705 When threading is turned off, the variable
706 `gnus-article-sort-functions' controls how articles are sorted."
707   :group 'gnus-summary-sort
708   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
709                          (function-item gnus-thread-sort-by-author)
710                          (function-item gnus-thread-sort-by-subject)
711                          (function-item gnus-thread-sort-by-date)
712                          (function-item gnus-thread-sort-by-score)
713                          (function-item gnus-thread-sort-by-total-score)
714                          (function :tag "other"))))
715
716 (defcustom gnus-thread-score-function '+
717   "*Function used for calculating the total score of a thread.
718
719 The function is called with the scores of the article and each
720 subthread and should then return the score of the thread.
721
722 Some functions you can use are `+', `max', or `min'."
723   :group 'gnus-summary-sort
724   :type 'function)
725
726 (defcustom gnus-summary-expunge-below nil
727   "All articles that have a score less than this variable will be expunged.
728 This variable is local to the summary buffers."
729   :group 'gnus-score-default
730   :type '(choice (const :tag "off" nil)
731                  integer))
732
733 (defcustom gnus-thread-expunge-below nil
734   "All threads that have a total score less than this variable will be expunged.
735 See `gnus-thread-score-function' for en explanation of what a
736 \"thread score\" is.
737
738 This variable is local to the summary buffers."
739   :group 'gnus-threading
740   :group 'gnus-score-default
741   :type '(choice (const :tag "off" nil)
742                  integer))
743
744 (defcustom gnus-summary-mode-hook nil
745   "*A hook for Gnus summary mode.
746 This hook is run before any variables are set in the summary buffer."
747   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
748   :group 'gnus-summary-various
749   :type 'hook)
750
751 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
752 (when (featurep 'xemacs)
753   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
754   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
755   (add-hook 'gnus-summary-mode-hook
756             'gnus-xmas-switch-horizontal-scrollbar-off))
757
758 (defcustom gnus-summary-menu-hook nil
759   "*Hook run after the creation of the summary mode menu."
760   :group 'gnus-summary-visual
761   :type 'hook)
762
763 (defcustom gnus-summary-exit-hook nil
764   "*A hook called on exit from the summary buffer.
765 It will be called with point in the group buffer."
766   :group 'gnus-summary-exit
767   :type 'hook)
768
769 (defcustom gnus-summary-prepare-hook nil
770   "*A hook called after the summary buffer has been generated.
771 If you want to modify the summary buffer, you can use this hook."
772   :group 'gnus-summary-various
773   :type 'hook)
774
775 (defcustom gnus-summary-prepared-hook nil
776   "*A hook called as the last thing after the summary buffer has been generated."
777   :group 'gnus-summary-various
778   :type 'hook)
779
780 (defcustom gnus-summary-generate-hook nil
781   "*A hook run just before generating the summary buffer.
782 This hook is commonly used to customize threading variables and the
783 like."
784   :group 'gnus-summary-various
785   :type 'hook)
786
787 (defcustom gnus-select-group-hook nil
788   "*A hook called when a newsgroup is selected.
789
790 If you'd like to simplify subjects like the
791 `gnus-summary-next-same-subject' command does, you can use the
792 following hook:
793
794  (add-hook gnus-select-group-hook
795            (lambda ()
796              (mapcar (lambda (header)
797                        (mail-header-set-subject
798                         header
799                         (gnus-simplify-subject
800                          (mail-header-subject header) 're-only)))
801                      gnus-newsgroup-headers)))"
802   :group 'gnus-group-select
803   :type 'hook)
804
805 (defcustom gnus-select-article-hook nil
806   "*A hook called when an article is selected."
807   :group 'gnus-summary-choose
808   :type 'hook)
809
810 (defcustom gnus-visual-mark-article-hook
811   (list 'gnus-highlight-selected-summary)
812   "*Hook run after selecting an article in the summary buffer.
813 It is meant to be used for highlighting the article in some way.  It
814 is not run if `gnus-visual' is nil."
815   :group 'gnus-summary-visual
816   :type 'hook)
817
818 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
819   "*A hook called before parsing the headers."
820   :group 'gnus-various
821   :type 'hook)
822
823 (defcustom gnus-exit-group-hook nil
824   "*A hook called when exiting summary mode.
825 This hook is not called from the non-updating exit commands like `Q'."
826   :group 'gnus-various
827   :type 'hook)
828
829 (defcustom gnus-summary-update-hook
830   (list 'gnus-summary-highlight-line)
831   "*A hook called when a summary line is changed.
832 The hook will not be called if `gnus-visual' is nil.
833
834 The default function `gnus-summary-highlight-line' will
835 highlight the line according to the `gnus-summary-highlight'
836 variable."
837   :group 'gnus-summary-visual
838   :type 'hook)
839
840 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
841   "*A hook called when an article is selected for the first time.
842 The hook is intended to mark an article as read (or unread)
843 automatically when it is selected."
844   :group 'gnus-summary-choose
845   :type 'hook)
846
847 (defcustom gnus-group-no-more-groups-hook nil
848   "*A hook run when returning to group mode having no more (unread) groups."
849   :group 'gnus-group-select
850   :type 'hook)
851
852 (defcustom gnus-ps-print-hook nil
853   "*A hook run before ps-printing something from Gnus."
854   :group 'gnus-summary
855   :type 'hook)
856
857 (defcustom gnus-summary-display-arrow
858   (and (fboundp 'display-graphic-p)
859        (display-graphic-p))
860   "*If non-nil, display an arrow highlighting the current article."
861   :version "21.1"
862   :group 'gnus-summary
863   :type 'boolean)
864
865 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
866   "Face used for highlighting the current article in the summary buffer."
867   :group 'gnus-summary-visual
868   :type 'face)
869
870 (defcustom gnus-summary-highlight
871   '(((eq mark gnus-canceled-mark)
872      . gnus-summary-cancelled-face)
873     ((and (> score default-high)
874           (or (eq mark gnus-dormant-mark)
875               (eq mark gnus-ticked-mark)))
876      . gnus-summary-high-ticked-face)
877     ((and (< score default-low)
878           (or (eq mark gnus-dormant-mark)
879               (eq mark gnus-ticked-mark)))
880      . gnus-summary-low-ticked-face)
881     ((or (eq mark gnus-dormant-mark)
882          (eq mark gnus-ticked-mark))
883      . gnus-summary-normal-ticked-face)
884     ((and (> score default-high) (eq mark gnus-ancient-mark))
885      . gnus-summary-high-ancient-face)
886     ((and (< score default-low) (eq mark gnus-ancient-mark))
887      . gnus-summary-low-ancient-face)
888     ((eq mark gnus-ancient-mark)
889      . gnus-summary-normal-ancient-face)
890     ((and (> score default-high) (eq mark gnus-unread-mark))
891      . gnus-summary-high-unread-face)
892     ((and (< score default-low) (eq mark gnus-unread-mark))
893      . gnus-summary-low-unread-face)
894     ((eq mark gnus-unread-mark)
895      . gnus-summary-normal-unread-face)
896     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
897                                                   gnus-undownloaded-mark)))
898      . gnus-summary-high-unread-face)
899     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
900                                                  gnus-undownloaded-mark)))
901      . gnus-summary-low-unread-face)
902     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
903           (memq article gnus-newsgroup-unreads))
904      . gnus-summary-normal-unread-face)
905     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
906      . gnus-summary-normal-read-face)
907     ((> score default-high)
908      . gnus-summary-high-read-face)
909     ((< score default-low)
910      . gnus-summary-low-read-face)
911     (t
912      . gnus-summary-normal-read-face))
913   "*Controls the highlighting of summary buffer lines.
914
915 A list of (FORM . FACE) pairs.  When deciding how a a particular
916 summary line should be displayed, each form is evaluated.  The content
917 of the face field after the first true form is used.  You can change
918 how those summary lines are displayed, by editing the face field.
919
920 You can use the following variables in the FORM field.
921
922 score:        The article's score
923 default:      The default article score.
924 default-high: The default score for high scored articles.
925 default-low:  The default score for low scored articles.
926 below:        The score below which articles are automatically marked as read.
927 mark:         The articles mark."
928   :group 'gnus-summary-visual
929   :type '(repeat (cons (sexp :tag "Form" nil)
930                        face)))
931
932 (defcustom gnus-alter-header-function nil
933   "Function called to allow alteration of article header structures.
934 The function is called with one parameter, the article header vector,
935 which it may alter in any way.")
936
937 (defvar gnus-decode-encoded-word-function
938   (mime-find-field-decoder 'From 'nov)
939   "Variable that says which function should be used to decode a string with encoded words.")
940
941 (defcustom gnus-extra-headers '(To Newsgroups)
942   "*Extra headers to parse."
943   :version "21.1"
944   :group 'gnus-summary
945   :type '(repeat symbol))
946
947 (defcustom gnus-ignored-from-addresses
948   (and user-mail-address (regexp-quote user-mail-address))
949   "*Regexp of From headers that may be suppressed in favor of To headers."
950   :version "21.1"
951   :group 'gnus-summary
952   :type 'regexp)
953
954 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
955   "List of charsets that should be ignored.
956 When these charsets are used in the \"charset\" parameter, the
957 default charset will be used instead."
958   :version "21.1"
959   :type '(repeat symbol)
960   :group 'gnus-charset)
961
962 (gnus-define-group-parameter
963  ignored-charsets
964  :type list
965  :function-document
966  "Return the ignored charsets of GROUP."
967  :variable gnus-group-ignored-charsets-alist
968  :variable-default
969  '(("alt\\.chinese\\.text" iso-8859-1))
970  :variable-document
971  "Alist of regexps (to match group names) and charsets that should be ignored.
972 When these charsets are used in the \"charset\" parameter, the
973 default charset will be used instead."
974  :variable-group gnus-charset
975  :variable-type '(repeat (cons (regexp :tag "Group")
976                                (repeat symbol)))
977  :parameter-type '(choice :tag "Ignored charsets"
978                           :value nil
979                           (repeat (symbol)))
980  :parameter-document       "\
981 List of charsets that should be ignored.
982
983 When these charsets are used in the \"charset\" parameter, the
984 default charset will be used instead.")
985
986 (defcustom gnus-group-highlight-words-alist nil
987   "Alist of group regexps and highlight regexps.
988 This variable uses the same syntax as `gnus-emphasis-alist'."
989   :version "21.1"
990   :type '(repeat (cons (regexp :tag "Group")
991                        (repeat (list (regexp :tag "Highlight regexp")
992                                      (number :tag "Group for entire word" 0)
993                                      (number :tag "Group for displayed part" 0)
994                                      (symbol :tag "Face"
995                                              gnus-emphasis-highlight-words)))))
996   :group 'gnus-summary-visual)
997
998 (defcustom gnus-use-wheel nil
999   "Use Intelli-mouse on summary movement"
1000   :type 'boolean
1001   :group 'gnus-summary-maneuvering)
1002
1003 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1004   "Amount to scroll messages by spinning the mouse wheel.
1005 This is actually a cons cell, where the first item is the amount to scroll
1006 on a normal wheel event, and the second is the amount to scroll when the
1007 wheel is moved with the shift key depressed."
1008   :type '(cons (integer :tag "Shift") integer)
1009   :group 'gnus-summary-maneuvering)
1010
1011 (defcustom gnus-wheel-edge-resistance 2
1012   "How hard it should be to change the current article
1013 by moving the mouse over the edge of the article window."
1014   :type 'integer
1015   :group 'gnus-summary-maneuvering)
1016
1017 (defcustom gnus-summary-show-article-charset-alist
1018   nil
1019   "Alist of number and charset.
1020 The article will be shown with the charset corresponding to the
1021 numbered argument.
1022 For example: ((1 . cn-gb-2312) (2 . big5))."
1023   :version "21.1"
1024   :type '(repeat (cons (number :tag "Argument" 1)
1025                        (symbol :tag "Charset")))
1026   :group 'gnus-charset)
1027
1028 (defcustom gnus-preserve-marks t
1029   "Whether marks are preserved when moving, copying and respooling messages."
1030   :version "21.1"
1031   :type 'boolean
1032   :group 'gnus-summary-marks)
1033
1034 (defcustom gnus-alter-articles-to-read-function nil
1035   "Function to be called to alter the list of articles to be selected."
1036   :type '(choice (const nil) function)
1037   :group 'gnus-summary)
1038
1039 (defcustom gnus-orphan-score nil
1040   "*All orphans get this score added.  Set in the score file."
1041   :group 'gnus-score-default
1042   :type '(choice (const nil)
1043                  integer))
1044
1045 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1046   "*A regexp to match MIME parts when saving multiple parts of a message
1047 with gnus-summary-save-parts (X m). This regexp will be used by default
1048 when prompting the user for which type of files to save."
1049   :group 'gnus-summary
1050   :type 'regexp)
1051
1052 (defcustom gnus-read-all-available-headers nil
1053   "Whether Gnus should parse all headers made available to it.
1054 This is mostly relevant for slow backends where the user may
1055 wish to widen the summary buffer to include all headers
1056 that were fetched.  Say, for nnultimate groups."
1057   :group 'gnus-summary
1058   :type '(choice boolean regexp))
1059
1060 (defcustom gnus-summary-muttprint-program "muttprint"
1061   "Command (and optional arguments) used to run Muttprint."
1062   :version "21.3"
1063   :group 'gnus-summary
1064   :type 'string)
1065
1066 (defcustom gnus-article-loose-mime nil
1067   "If non-nil, don't require MIME-Version header.
1068 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1069 supply the MIME-Version header or deliberately strip it From the mail.
1070 Set it to non-nil, Gnus will treat some articles as MIME even if
1071 the MIME-Version header is missed."
1072   :version "21.3"
1073   :type 'boolean
1074   :group 'gnus-article)
1075
1076 ;;; Internal variables
1077
1078 (defvar gnus-summary-display-cache nil)
1079 (defvar gnus-article-mime-handles nil)
1080 (defvar gnus-article-decoded-p nil)
1081 (defvar gnus-article-charset nil)
1082 (defvar gnus-article-ignored-charsets nil)
1083 (defvar gnus-scores-exclude-files nil)
1084 (defvar gnus-page-broken nil)
1085 (defvar gnus-inhibit-mime-unbuttonizing nil)
1086
1087 (defvar gnus-original-article nil)
1088 (defvar gnus-article-internal-prepare-hook nil)
1089 (defvar gnus-newsgroup-process-stack nil)
1090
1091 (defvar gnus-thread-indent-array nil)
1092 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1093 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1094   "Function called to sort the articles within a thread after it has been gathered together.")
1095
1096 (defvar gnus-summary-save-parts-type-history nil)
1097 (defvar gnus-summary-save-parts-last-directory nil)
1098
1099 ;; Avoid highlighting in kill files.
1100 (defvar gnus-summary-inhibit-highlight nil)
1101 (defvar gnus-newsgroup-selected-overlay nil)
1102 (defvar gnus-inhibit-limiting nil)
1103 (defvar gnus-newsgroup-adaptive-score-file nil)
1104 (defvar gnus-current-score-file nil)
1105 (defvar gnus-current-move-group nil)
1106 (defvar gnus-current-copy-group nil)
1107 (defvar gnus-current-crosspost-group nil)
1108 (defvar gnus-newsgroup-display nil)
1109
1110 (defvar gnus-newsgroup-dependencies nil)
1111 (defvar gnus-newsgroup-adaptive nil)
1112 (defvar gnus-summary-display-article-function nil)
1113 (defvar gnus-summary-highlight-line-function nil
1114   "Function called after highlighting a summary line.")
1115
1116 (defvar gnus-summary-line-format-alist
1117   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1118     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1119     (?s gnus-tmp-subject-or-nil ?s)
1120     (?n gnus-tmp-name ?s)
1121     (?A (std11-address-string
1122          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1123     (?a (or (std11-full-name-string
1124              (car (mime-entity-read-field gnus-tmp-header 'From)))
1125             gnus-tmp-from) ?s)
1126     (?F gnus-tmp-from ?s)
1127     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1128     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1129     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1130     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1131     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1132     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1133     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1134     (?L gnus-tmp-lines ?s)
1135     (?I gnus-tmp-indentation ?s)
1136     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1137     (?R gnus-tmp-replied ?c)
1138     (?\[ gnus-tmp-opening-bracket ?c)
1139     (?\] gnus-tmp-closing-bracket ?c)
1140     (?\> (make-string gnus-tmp-level ? ) ?s)
1141     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1142     (?i gnus-tmp-score ?d)
1143     (?z gnus-tmp-score-char ?c)
1144     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1145     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1146     (?U gnus-tmp-unread ?c)
1147     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1148         ?s)
1149     (?t (gnus-summary-number-of-articles-in-thread
1150          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1151         ?d)
1152     (?e (gnus-summary-number-of-articles-in-thread
1153          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1154         ?c)
1155     (?u gnus-tmp-user-defined ?s)
1156     (?P (gnus-pick-line-number) ?d)
1157     (?B gnus-tmp-thread-tree-header-string ?s)
1158     (user-date (gnus-user-date
1159                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1160   "An alist of format specifications that can appear in summary lines.
1161 These are paired with what variables they correspond with, along with
1162 the type of the variable (string, integer, character, etc).")
1163
1164 (defvar gnus-summary-dummy-line-format-alist
1165   `((?S gnus-tmp-subject ?s)
1166     (?N gnus-tmp-number ?d)
1167     (?u gnus-tmp-user-defined ?s)))
1168
1169 (defvar gnus-summary-mode-line-format-alist
1170   `((?G gnus-tmp-group-name ?s)
1171     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1172     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1173     (?A gnus-tmp-article-number ?d)
1174     (?Z gnus-tmp-unread-and-unselected ?s)
1175     (?V gnus-version ?s)
1176     (?U gnus-tmp-unread-and-unticked ?d)
1177     (?S gnus-tmp-subject ?s)
1178     (?e gnus-tmp-unselected ?d)
1179     (?u gnus-tmp-user-defined ?s)
1180     (?d (length gnus-newsgroup-dormant) ?d)
1181     (?t (length gnus-newsgroup-marked) ?d)
1182     (?r (length gnus-newsgroup-reads) ?d)
1183     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1184     (?E gnus-newsgroup-expunged-tally ?d)
1185     (?s (gnus-current-score-file-nondirectory) ?s)))
1186
1187 (defvar gnus-last-search-regexp nil
1188   "Default regexp for article search command.")
1189
1190 (defvar gnus-summary-search-article-matched-data nil
1191   "Last matched data of article search command.  It is the local variable
1192 in `gnus-article-buffer' which consists of the list of start position,
1193 end position and text.")
1194
1195 (defvar gnus-last-shell-command nil
1196   "Default shell command on article.")
1197
1198 (defvar gnus-newsgroup-begin nil)
1199 (defvar gnus-newsgroup-end nil)
1200 (defvar gnus-newsgroup-last-rmail nil)
1201 (defvar gnus-newsgroup-last-mail nil)
1202 (defvar gnus-newsgroup-last-folder nil)
1203 (defvar gnus-newsgroup-last-file nil)
1204 (defvar gnus-newsgroup-auto-expire nil)
1205 (defvar gnus-newsgroup-active nil)
1206
1207 (defvar gnus-newsgroup-data nil)
1208 (defvar gnus-newsgroup-data-reverse nil)
1209 (defvar gnus-newsgroup-limit nil)
1210 (defvar gnus-newsgroup-limits nil)
1211
1212 (defvar gnus-newsgroup-unreads nil
1213   "Sorted list of unread articles in the current newsgroup.")
1214
1215 (defvar gnus-newsgroup-unselected nil
1216   "Sorted list of unselected unread articles in the current newsgroup.")
1217
1218 (defvar gnus-newsgroup-reads nil
1219   "Alist of read articles and article marks in the current newsgroup.")
1220
1221 (defvar gnus-newsgroup-expunged-tally nil)
1222
1223 (defvar gnus-newsgroup-marked nil
1224   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1225
1226 (defvar gnus-newsgroup-killed nil
1227   "List of ranges of articles that have been through the scoring process.")
1228
1229 (defvar gnus-newsgroup-cached nil
1230   "Sorted list of articles that come from the article cache.")
1231
1232 (defvar gnus-newsgroup-saved nil
1233   "List of articles that have been saved.")
1234
1235 (defvar gnus-newsgroup-kill-headers nil)
1236
1237 (defvar gnus-newsgroup-replied nil
1238   "List of articles that have been replied to in the current newsgroup.")
1239
1240 (defvar gnus-newsgroup-forwarded nil
1241   "List of articles that have been forwarded in the current newsgroup.")
1242
1243 (defvar gnus-newsgroup-recent nil
1244   "List of articles that have are recent in the current newsgroup.")
1245
1246 (defvar gnus-newsgroup-expirable nil
1247   "Sorted list of articles in the current newsgroup that can be expired.")
1248
1249 (defvar gnus-newsgroup-processable nil
1250   "List of articles in the current newsgroup that can be processed.")
1251
1252 (defvar gnus-newsgroup-downloadable nil
1253   "Sorted list of articles in the current newsgroup that can be processed.")
1254
1255 (defvar gnus-newsgroup-undownloaded nil
1256   "List of articles in the current newsgroup that haven't been downloaded..")
1257
1258 (defvar gnus-newsgroup-unsendable nil
1259   "List of articles in the current newsgroup that won't be sent.")
1260
1261 (defvar gnus-newsgroup-bookmarks nil
1262   "List of articles in the current newsgroup that have bookmarks.")
1263
1264 (defvar gnus-newsgroup-dormant nil
1265   "Sorted list of dormant articles in the current newsgroup.")
1266
1267 (defvar gnus-newsgroup-unseen nil
1268   "List of unseen articles in the current newsgroup.")
1269
1270 (defvar gnus-newsgroup-seen nil
1271   "Range of seen articles in the current newsgroup.")
1272
1273 (defvar gnus-newsgroup-articles nil
1274   "List of articles in the current newsgroup.")
1275
1276 (defvar gnus-newsgroup-scored nil
1277   "List of scored articles in the current newsgroup.")
1278
1279 (defvar gnus-newsgroup-incorporated nil
1280   "List of incorporated articles in the current newsgroup.")
1281
1282 (defvar gnus-newsgroup-headers nil
1283   "List of article headers in the current newsgroup.")
1284
1285 (defvar gnus-newsgroup-threads nil)
1286
1287 (defvar gnus-newsgroup-prepared nil
1288   "Whether the current group has been prepared properly.")
1289
1290 (defvar gnus-newsgroup-ancient nil
1291   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1292
1293 (defvar gnus-newsgroup-sparse nil)
1294
1295 (defvar gnus-current-article nil)
1296 (defvar gnus-article-current nil)
1297 (defvar gnus-current-headers nil)
1298 (defvar gnus-have-all-headers nil)
1299 (defvar gnus-last-article nil)
1300 (defvar gnus-newsgroup-history nil)
1301 (defvar gnus-newsgroup-charset nil)
1302 (defvar gnus-newsgroup-ephemeral-charset nil)
1303 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1304
1305 (defvar gnus-article-before-search nil)
1306
1307 (defconst gnus-summary-local-variables
1308   '(gnus-newsgroup-name
1309     gnus-newsgroup-begin gnus-newsgroup-end
1310     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1311     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1312     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1313     gnus-newsgroup-unselected gnus-newsgroup-marked
1314     gnus-newsgroup-reads gnus-newsgroup-saved
1315     gnus-newsgroup-replied gnus-newsgroup-forwarded
1316     gnus-newsgroup-recent
1317     gnus-newsgroup-expirable
1318     gnus-newsgroup-processable gnus-newsgroup-killed
1319     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1320     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1321     gnus-newsgroup-seen gnus-newsgroup-articles
1322     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1323     gnus-newsgroup-headers gnus-newsgroup-threads
1324     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1325     gnus-current-article gnus-current-headers gnus-have-all-headers
1326     gnus-last-article gnus-article-internal-prepare-hook
1327     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1328     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1329     gnus-thread-expunge-below
1330     gnus-score-alist gnus-current-score-file
1331     (gnus-summary-expunge-below . global)
1332     (gnus-summary-mark-below . global)
1333     (gnus-orphan-score . global)
1334     gnus-newsgroup-active gnus-scores-exclude-files
1335     gnus-newsgroup-history gnus-newsgroup-ancient
1336     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1337     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1338     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1339     (gnus-newsgroup-expunged-tally . 0)
1340     gnus-cache-removable-articles gnus-newsgroup-cached
1341     gnus-newsgroup-data gnus-newsgroup-data-reverse
1342     gnus-newsgroup-limit gnus-newsgroup-limits
1343     gnus-newsgroup-charset gnus-newsgroup-display
1344     gnus-newsgroup-incorporated)
1345   "Variables that are buffer-local to the summary buffers.")
1346
1347 (defvar gnus-newsgroup-variables nil
1348   "A list of variables that have separate values in different newsgroups.
1349 A list of newsgroup (summary buffer) local variables, or cons of
1350 variables and their default values (when the default values are not
1351 nil), that should be made global while the summary buffer is active.
1352 These variables can be used to set variables in the group parameters
1353 while still allowing them to affect operations done in other
1354 buffers. For example:
1355
1356 \(setq gnus-newsgroup-variables
1357      '(message-use-followup-to
1358        (gnus-visible-headers .
1359          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1360 ")
1361
1362 ;; Byte-compiler warning.
1363 (eval-when-compile (defvar gnus-article-mode-map))
1364
1365 ;; Subject simplification.
1366
1367 (defun gnus-simplify-whitespace (str)
1368   "Remove excessive whitespace from STR."
1369   (let ((mystr str))
1370     ;; Multiple spaces.
1371     (while (string-match "[ \t][ \t]+" mystr)
1372       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1373                           " "
1374                           (substring mystr (match-end 0)))))
1375     ;; Leading spaces.
1376     (when (string-match "^[ \t]+" mystr)
1377       (setq mystr (substring mystr (match-end 0))))
1378     ;; Trailing spaces.
1379     (when (string-match "[ \t]+$" mystr)
1380       (setq mystr (substring mystr 0 (match-beginning 0))))
1381     mystr))
1382
1383 (defsubst gnus-simplify-subject-re (subject)
1384   "Remove \"Re:\" from subject lines."
1385   (if (string-match message-subject-re-regexp subject)
1386       (substring subject (match-end 0))
1387     subject))
1388
1389 (defun gnus-simplify-subject (subject &optional re-only)
1390   "Remove `Re:' and words in parentheses.
1391 If RE-ONLY is non-nil, strip leading `Re:'s only."
1392   (let ((case-fold-search t))           ;Ignore case.
1393     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1394     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1395       (setq subject (substring subject (match-end 0))))
1396     ;; Remove uninteresting prefixes.
1397     (when (and (not re-only)
1398                gnus-simplify-ignored-prefixes
1399                (string-match gnus-simplify-ignored-prefixes subject))
1400       (setq subject (substring subject (match-end 0))))
1401     ;; Remove words in parentheses from end.
1402     (unless re-only
1403       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1404         (setq subject (substring subject 0 (match-beginning 0)))))
1405     ;; Return subject string.
1406     subject))
1407
1408 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1409 ;; all whitespace.
1410 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1411   (goto-char (point-min))
1412   (while (re-search-forward regexp nil t)
1413     (replace-match (or newtext ""))))
1414
1415 (defun gnus-simplify-buffer-fuzzy ()
1416   "Simplify string in the buffer fuzzily.
1417 The string in the accessible portion of the current buffer is simplified.
1418 It is assumed to be a single-line subject.
1419 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1420 matter is removed.  Additional things can be deleted by setting
1421 `gnus-simplify-subject-fuzzy-regexp'."
1422   (let ((case-fold-search t)
1423         (modified-tick))
1424     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1425
1426     (while (not (eq modified-tick (buffer-modified-tick)))
1427       (setq modified-tick (buffer-modified-tick))
1428       (cond
1429        ((listp gnus-simplify-subject-fuzzy-regexp)
1430         (mapcar 'gnus-simplify-buffer-fuzzy-step
1431                 gnus-simplify-subject-fuzzy-regexp))
1432        (gnus-simplify-subject-fuzzy-regexp
1433         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1434       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1435       (gnus-simplify-buffer-fuzzy-step
1436        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1437       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1438
1439     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1440     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1441     (gnus-simplify-buffer-fuzzy-step " $")
1442     (gnus-simplify-buffer-fuzzy-step "^ +")))
1443
1444 (defun gnus-simplify-subject-fuzzy (subject)
1445   "Simplify a subject string fuzzily.
1446 See `gnus-simplify-buffer-fuzzy' for details."
1447   (save-excursion
1448     (gnus-set-work-buffer)
1449     (let ((case-fold-search t))
1450       ;; Remove uninteresting prefixes.
1451       (when (and gnus-simplify-ignored-prefixes
1452                  (string-match gnus-simplify-ignored-prefixes subject))
1453         (setq subject (substring subject (match-end 0))))
1454       (insert subject)
1455       (inline (gnus-simplify-buffer-fuzzy))
1456       (buffer-string))))
1457
1458 (defsubst gnus-simplify-subject-fully (subject)
1459   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1460   (cond
1461    (gnus-simplify-subject-functions
1462     (gnus-map-function gnus-simplify-subject-functions subject))
1463    ((null gnus-summary-gather-subject-limit)
1464     (gnus-simplify-subject-re subject))
1465    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1466     (gnus-simplify-subject-fuzzy subject))
1467    ((numberp gnus-summary-gather-subject-limit)
1468     (gnus-limit-string (gnus-simplify-subject-re subject)
1469                        gnus-summary-gather-subject-limit))
1470    (t
1471     subject)))
1472
1473 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1474   "Check whether two subjects are equal.
1475 If optional argument simple-first is t, first argument is already
1476 simplified."
1477   (cond
1478    ((null simple-first)
1479     (equal (gnus-simplify-subject-fully s1)
1480            (gnus-simplify-subject-fully s2)))
1481    (t
1482     (equal s1
1483            (gnus-simplify-subject-fully s2)))))
1484
1485 (defun gnus-summary-bubble-group ()
1486   "Increase the score of the current group.
1487 This is a handy function to add to `gnus-summary-exit-hook' to
1488 increase the score of each group you read."
1489   (gnus-group-add-score gnus-newsgroup-name))
1490
1491 \f
1492 ;;;
1493 ;;; Gnus summary mode
1494 ;;;
1495
1496 (put 'gnus-summary-mode 'mode-class 'special)
1497
1498 (defvar gnus-article-commands-menu)
1499
1500 (when t
1501   ;; Non-orthogonal keys
1502
1503   (gnus-define-keys gnus-summary-mode-map
1504     " " gnus-summary-next-page
1505     "\177" gnus-summary-prev-page
1506     [delete] gnus-summary-prev-page
1507     [backspace] gnus-summary-prev-page
1508     "\r" gnus-summary-scroll-up
1509     "\M-\r" gnus-summary-scroll-down
1510     "n" gnus-summary-next-unread-article
1511     "p" gnus-summary-prev-unread-article
1512     "N" gnus-summary-next-article
1513     "P" gnus-summary-prev-article
1514     "\M-\C-n" gnus-summary-next-same-subject
1515     "\M-\C-p" gnus-summary-prev-same-subject
1516     "\M-n" gnus-summary-next-unread-subject
1517     "\M-p" gnus-summary-prev-unread-subject
1518     "." gnus-summary-first-unread-article
1519     "," gnus-summary-best-unread-article
1520     "\M-s" gnus-summary-search-article-forward
1521     "\M-r" gnus-summary-search-article-backward
1522     "<" gnus-summary-beginning-of-article
1523     ">" gnus-summary-end-of-article
1524     "j" gnus-summary-goto-article
1525     "^" gnus-summary-refer-parent-article
1526     "\M-^" gnus-summary-refer-article
1527     "u" gnus-summary-tick-article-forward
1528     "!" gnus-summary-tick-article-forward
1529     "U" gnus-summary-tick-article-backward
1530     "d" gnus-summary-mark-as-read-forward
1531     "D" gnus-summary-mark-as-read-backward
1532     "E" gnus-summary-mark-as-expirable
1533     "\M-u" gnus-summary-clear-mark-forward
1534     "\M-U" gnus-summary-clear-mark-backward
1535     "k" gnus-summary-kill-same-subject-and-select
1536     "\C-k" gnus-summary-kill-same-subject
1537     "\M-\C-k" gnus-summary-kill-thread
1538     "\M-\C-l" gnus-summary-lower-thread
1539     "e" gnus-summary-edit-article
1540     "#" gnus-summary-mark-as-processable
1541     "\M-#" gnus-summary-unmark-as-processable
1542     "\M-\C-t" gnus-summary-toggle-threads
1543     "\M-\C-s" gnus-summary-show-thread
1544     "\M-\C-h" gnus-summary-hide-thread
1545     "\M-\C-f" gnus-summary-next-thread
1546     "\M-\C-b" gnus-summary-prev-thread
1547     [(meta down)] gnus-summary-next-thread
1548     [(meta up)] gnus-summary-prev-thread
1549     "\M-\C-u" gnus-summary-up-thread
1550     "\M-\C-d" gnus-summary-down-thread
1551     "&" gnus-summary-execute-command
1552     "c" gnus-summary-catchup-and-exit
1553     "\C-w" gnus-summary-mark-region-as-read
1554     "\C-t" gnus-summary-toggle-truncation
1555     "?" gnus-summary-mark-as-dormant
1556     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1557     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1558     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1559     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1560     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1561     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1562     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1563     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1564     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1565     "=" gnus-summary-expand-window
1566     "\C-x\C-s" gnus-summary-reselect-current-group
1567     "\M-g" gnus-summary-rescan-group
1568     "w" gnus-summary-stop-page-breaking
1569     "\C-c\C-r" gnus-summary-caesar-message
1570     "\M-t" gnus-summary-toggle-mime
1571     "f" gnus-summary-followup
1572     "F" gnus-summary-followup-with-original
1573     "C" gnus-summary-cancel-article
1574     "r" gnus-summary-reply
1575     "R" gnus-summary-reply-with-original
1576     "\C-c\C-f" gnus-summary-mail-forward
1577     "o" gnus-summary-save-article
1578     "\C-o" gnus-summary-save-article-mail
1579     "|" gnus-summary-pipe-output
1580     "\M-k" gnus-summary-edit-local-kill
1581     "\M-K" gnus-summary-edit-global-kill
1582     ;; "V" gnus-version
1583     "\C-c\C-d" gnus-summary-describe-group
1584     "q" gnus-summary-exit
1585     "Q" gnus-summary-exit-no-update
1586     "\C-c\C-i" gnus-info-find-node
1587     gnus-mouse-2 gnus-mouse-pick-article
1588     "m" gnus-summary-mail-other-window
1589     "a" gnus-summary-post-news
1590     "i" gnus-summary-news-other-window
1591     "x" gnus-summary-limit-to-unread
1592     "s" gnus-summary-isearch-article
1593     "t" gnus-article-toggle-headers
1594     "g" gnus-summary-show-article
1595     "l" gnus-summary-goto-last-article
1596     "v" gnus-summary-preview-mime-message
1597     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1598     "\C-d" gnus-summary-enter-digest-group
1599     "\M-\C-d" gnus-summary-read-document
1600     "\M-\C-e" gnus-summary-edit-parameters
1601     "\M-\C-a" gnus-summary-customize-parameters
1602     "\C-c\C-b" gnus-bug
1603     "\C-c\C-n" gnus-namazu-search
1604     "*" gnus-cache-enter-article
1605     "\M-*" gnus-cache-remove-article
1606     "\M-&" gnus-summary-universal-argument
1607     "\C-l" gnus-recenter
1608     "I" gnus-summary-increase-score
1609     "L" gnus-summary-lower-score
1610     "\M-i" gnus-symbolic-argument
1611     "h" gnus-summary-select-article-buffer
1612
1613     "V" gnus-summary-score-map
1614     "X" gnus-uu-extract-map
1615     "S" gnus-summary-send-map)
1616
1617   ;; Sort of orthogonal keymap
1618   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1619     "t" gnus-summary-tick-article-forward
1620     "!" gnus-summary-tick-article-forward
1621     "d" gnus-summary-mark-as-read-forward
1622     "r" gnus-summary-mark-as-read-forward
1623     "c" gnus-summary-clear-mark-forward
1624     " " gnus-summary-clear-mark-forward
1625     "e" gnus-summary-mark-as-expirable
1626     "x" gnus-summary-mark-as-expirable
1627     "?" gnus-summary-mark-as-dormant
1628     "b" gnus-summary-set-bookmark
1629     "B" gnus-summary-remove-bookmark
1630     "#" gnus-summary-mark-as-processable
1631     "\M-#" gnus-summary-unmark-as-processable
1632     "S" gnus-summary-limit-include-expunged
1633     "C" gnus-summary-catchup
1634     "H" gnus-summary-catchup-to-here
1635     "h" gnus-summary-catchup-from-here
1636     "\C-c" gnus-summary-catchup-all
1637     "k" gnus-summary-kill-same-subject-and-select
1638     "K" gnus-summary-kill-same-subject
1639     "P" gnus-uu-mark-map)
1640
1641   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1642     "c" gnus-summary-clear-above
1643     "u" gnus-summary-tick-above
1644     "m" gnus-summary-mark-above
1645     "k" gnus-summary-kill-below)
1646
1647   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1648     "/" gnus-summary-limit-to-subject
1649     "n" gnus-summary-limit-to-articles
1650     "w" gnus-summary-pop-limit
1651     "s" gnus-summary-limit-to-subject
1652     "a" gnus-summary-limit-to-author
1653     "u" gnus-summary-limit-to-unread
1654     "m" gnus-summary-limit-to-marks
1655     "M" gnus-summary-limit-exclude-marks
1656     "v" gnus-summary-limit-to-score
1657     "*" gnus-summary-limit-include-cached
1658     "D" gnus-summary-limit-include-dormant
1659     "T" gnus-summary-limit-include-thread
1660     "d" gnus-summary-limit-exclude-dormant
1661     "t" gnus-summary-limit-to-age
1662     "x" gnus-summary-limit-to-extra
1663     "p" gnus-summary-limit-to-display-predicate
1664     "E" gnus-summary-limit-include-expunged
1665     "c" gnus-summary-limit-exclude-childless-dormant
1666     "C" gnus-summary-limit-mark-excluded-as-read
1667     "o" gnus-summary-insert-old-articles
1668     "N" gnus-summary-insert-new-articles)
1669
1670   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1671     "n" gnus-summary-next-unread-article
1672     "p" gnus-summary-prev-unread-article
1673     "N" gnus-summary-next-article
1674     "P" gnus-summary-prev-article
1675     "\C-n" gnus-summary-next-same-subject
1676     "\C-p" gnus-summary-prev-same-subject
1677     "\M-n" gnus-summary-next-unread-subject
1678     "\M-p" gnus-summary-prev-unread-subject
1679     "f" gnus-summary-first-unread-article
1680     "b" gnus-summary-best-unread-article
1681     "j" gnus-summary-goto-article
1682     "g" gnus-summary-goto-subject
1683     "l" gnus-summary-goto-last-article
1684     "o" gnus-summary-pop-article)
1685
1686   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1687     "k" gnus-summary-kill-thread
1688     "l" gnus-summary-lower-thread
1689     "i" gnus-summary-raise-thread
1690     "T" gnus-summary-toggle-threads
1691     "t" gnus-summary-rethread-current
1692     "^" gnus-summary-reparent-thread
1693     "s" gnus-summary-show-thread
1694     "S" gnus-summary-show-all-threads
1695     "h" gnus-summary-hide-thread
1696     "H" gnus-summary-hide-all-threads
1697     "n" gnus-summary-next-thread
1698     "p" gnus-summary-prev-thread
1699     "u" gnus-summary-up-thread
1700     "o" gnus-summary-top-thread
1701     "d" gnus-summary-down-thread
1702     "#" gnus-uu-mark-thread
1703     "\M-#" gnus-uu-unmark-thread)
1704
1705   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1706     "g" gnus-summary-prepare
1707     "c" gnus-summary-insert-cached-articles)
1708
1709   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1710     "c" gnus-summary-catchup-and-exit
1711     "C" gnus-summary-catchup-all-and-exit
1712     "E" gnus-summary-exit-no-update
1713     "J" gnus-summary-jump-to-other-group
1714     "Q" gnus-summary-exit
1715     "Z" gnus-summary-exit
1716     "n" gnus-summary-catchup-and-goto-next-group
1717     "R" gnus-summary-reselect-current-group
1718     "G" gnus-summary-rescan-group
1719     "N" gnus-summary-next-group
1720     "s" gnus-summary-save-newsrc
1721     "P" gnus-summary-prev-group)
1722
1723   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1724     " " gnus-summary-next-page
1725     "n" gnus-summary-next-page
1726     "\177" gnus-summary-prev-page
1727     [delete] gnus-summary-prev-page
1728     "p" gnus-summary-prev-page
1729     "\r" gnus-summary-scroll-up
1730     "\M-\r" gnus-summary-scroll-down
1731     "<" gnus-summary-beginning-of-article
1732     ">" gnus-summary-end-of-article
1733     "b" gnus-summary-beginning-of-article
1734     "e" gnus-summary-end-of-article
1735     "^" gnus-summary-refer-parent-article
1736     "r" gnus-summary-refer-parent-article
1737     "D" gnus-summary-enter-digest-group
1738     "R" gnus-summary-refer-references
1739     "T" gnus-summary-refer-thread
1740     "g" gnus-summary-show-article
1741     "s" gnus-summary-isearch-article
1742     "P" gnus-summary-print-article
1743     "M" gnus-mailing-list-insinuate
1744     "t" gnus-article-babel)
1745
1746   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1747     "b" gnus-article-add-buttons
1748     "B" gnus-article-add-buttons-to-head
1749     "o" gnus-article-treat-overstrike
1750     "e" gnus-article-emphasize
1751     "w" gnus-article-fill-cited-article
1752     "Q" gnus-article-fill-long-lines
1753     "C" gnus-article-capitalize-sentences
1754     "c" gnus-article-remove-cr
1755     "Z" gnus-article-decode-HZ
1756     "h" gnus-article-wash-html
1757     "u" gnus-article-unsplit-urls
1758     "f" gnus-article-display-x-face
1759     "l" gnus-summary-stop-page-breaking
1760     "r" gnus-summary-caesar-message
1761     "t" gnus-article-toggle-headers
1762     "g" gnus-treat-smiley
1763     "v" gnus-summary-verbose-headers
1764     "m" gnus-summary-toggle-mime
1765     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1766     "p" gnus-article-verify-x-pgp-sig
1767     "d" gnus-article-treat-dumbquotes
1768     "k" gnus-article-outlook-deuglify-article)
1769
1770   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1771     "a" gnus-article-hide
1772     "h" gnus-article-toggle-headers
1773     "b" gnus-article-hide-boring-headers
1774     "s" gnus-article-hide-signature
1775     "c" gnus-article-hide-citation
1776     "C" gnus-article-hide-citation-in-followups
1777     "l" gnus-article-hide-list-identifiers
1778     "p" gnus-article-hide-pgp
1779     "B" gnus-article-strip-banner
1780     "P" gnus-article-hide-pem
1781     "\C-c" gnus-article-hide-citation-maybe)
1782
1783   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1784     "a" gnus-article-highlight
1785     "h" gnus-article-highlight-headers
1786     "c" gnus-article-highlight-citation
1787     "s" gnus-article-highlight-signature)
1788
1789   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1790     "f" gnus-article-treat-fold-headers
1791     "u" gnus-article-treat-unfold-headers
1792     "n" gnus-article-treat-fold-newsgroups)
1793
1794   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1795     "x" gnus-article-display-x-face
1796     "s" gnus-treat-smiley
1797     "D" gnus-article-remove-images
1798     "f" gnus-treat-from-picon
1799     "m" gnus-treat-mail-picon
1800     "n" gnus-treat-newsgroups-picon)
1801
1802   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1803     "z" gnus-article-date-ut
1804     "u" gnus-article-date-ut
1805     "l" gnus-article-date-local
1806     "p" gnus-article-date-english
1807     "e" gnus-article-date-lapsed
1808     "o" gnus-article-date-original
1809     "i" gnus-article-date-iso8601
1810     "s" gnus-article-date-user)
1811
1812   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1813     "t" gnus-article-remove-trailing-blank-lines
1814     "l" gnus-article-strip-leading-blank-lines
1815     "m" gnus-article-strip-multiple-blank-lines
1816     "a" gnus-article-strip-blank-lines
1817     "A" gnus-article-strip-all-blank-lines
1818     "s" gnus-article-strip-leading-space
1819     "e" gnus-article-strip-trailing-space
1820     "w" gnus-article-remove-leading-whitespace)
1821
1822   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1823     "v" gnus-version
1824     "f" gnus-summary-fetch-faq
1825     "d" gnus-summary-describe-group
1826     "h" gnus-summary-describe-briefly
1827     "i" gnus-info-find-node)
1828
1829   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1830     "e" gnus-summary-expire-articles
1831     "\M-\C-e" gnus-summary-expire-articles-now
1832     "\177" gnus-summary-delete-article
1833     [delete] gnus-summary-delete-article
1834     [backspace] gnus-summary-delete-article
1835     "m" gnus-summary-move-article
1836     "r" gnus-summary-respool-article
1837     "w" gnus-summary-edit-article
1838     "c" gnus-summary-copy-article
1839     "B" gnus-summary-crosspost-article
1840     "q" gnus-summary-respool-query
1841     "t" gnus-summary-respool-trace
1842     "i" gnus-summary-import-article
1843     "I" gnus-summary-create-article
1844     "p" gnus-summary-article-posted-p)
1845
1846   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1847     "o" gnus-summary-save-article
1848     "m" gnus-summary-save-article-mail
1849     "F" gnus-summary-write-article-file
1850     "r" gnus-summary-save-article-rmail
1851     "f" gnus-summary-save-article-file
1852     "b" gnus-summary-save-article-body-file
1853     "h" gnus-summary-save-article-folder
1854     "v" gnus-summary-save-article-vm
1855     "p" gnus-summary-pipe-output
1856     "P" gnus-summary-muttprint
1857     "s" gnus-soup-add-article)
1858
1859   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1860     "b" gnus-summary-display-buttonized
1861     "m" gnus-summary-repair-multipart
1862     "v" gnus-article-view-part
1863     "o" gnus-article-save-part
1864     "c" gnus-article-copy-part
1865     "C" gnus-article-view-part-as-charset
1866     "e" gnus-article-view-part-externally
1867     "E" gnus-article-encrypt-body
1868     "i" gnus-article-inline-part
1869     "|" gnus-article-pipe-part)
1870
1871   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1872     "p" gnus-summary-mark-as-processable
1873     "u" gnus-summary-unmark-as-processable
1874     "U" gnus-summary-unmark-all-processable
1875     "v" gnus-uu-mark-over
1876     "s" gnus-uu-mark-series
1877     "r" gnus-uu-mark-region
1878     "g" gnus-uu-unmark-region
1879     "R" gnus-uu-mark-by-regexp
1880     "G" gnus-uu-unmark-by-regexp
1881     "t" gnus-uu-mark-thread
1882     "T" gnus-uu-unmark-thread
1883     "a" gnus-uu-mark-all
1884     "b" gnus-uu-mark-buffer
1885     "S" gnus-uu-mark-sparse
1886     "k" gnus-summary-kill-process-mark
1887     "y" gnus-summary-yank-process-mark
1888     "w" gnus-summary-save-process-mark
1889     "i" gnus-uu-invert-processable)
1890
1891   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1892     ;;"x" gnus-uu-extract-any
1893     "m" gnus-summary-save-parts
1894     "u" gnus-uu-decode-uu
1895     "U" gnus-uu-decode-uu-and-save
1896     "s" gnus-uu-decode-unshar
1897     "S" gnus-uu-decode-unshar-and-save
1898     "o" gnus-uu-decode-save
1899     "O" gnus-uu-decode-save
1900     "b" gnus-uu-decode-binhex
1901     "B" gnus-uu-decode-binhex
1902     "p" gnus-uu-decode-postscript
1903     "P" gnus-uu-decode-postscript-and-save)
1904
1905   (gnus-define-keys
1906       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1907     "u" gnus-uu-decode-uu-view
1908     "U" gnus-uu-decode-uu-and-save-view
1909     "s" gnus-uu-decode-unshar-view
1910     "S" gnus-uu-decode-unshar-and-save-view
1911     "o" gnus-uu-decode-save-view
1912     "O" gnus-uu-decode-save-view
1913     "b" gnus-uu-decode-binhex-view
1914     "B" gnus-uu-decode-binhex-view
1915     "p" gnus-uu-decode-postscript-view
1916     "P" gnus-uu-decode-postscript-and-save-view))
1917
1918 (defvar gnus-article-post-menu nil)
1919
1920 (defun gnus-summary-make-menu-bar ()
1921   (gnus-turn-off-edit-menu 'summary)
1922
1923   (unless (boundp 'gnus-summary-misc-menu)
1924
1925     (easy-menu-define
1926      gnus-summary-kill-menu gnus-summary-mode-map ""
1927      (cons
1928       "Score"
1929       (nconc
1930        (list
1931         ["Customize" gnus-score-customize t])
1932        (gnus-make-score-map 'increase)
1933        (gnus-make-score-map 'lower)
1934        '(("Mark"
1935           ["Kill below" gnus-summary-kill-below t]
1936           ["Mark above" gnus-summary-mark-above t]
1937           ["Tick above" gnus-summary-tick-above t]
1938           ["Clear above" gnus-summary-clear-above t])
1939          ["Current score" gnus-summary-current-score t]
1940          ["Set score" gnus-summary-set-score t]
1941          ["Switch current score file..." gnus-score-change-score-file t]
1942          ["Set mark below..." gnus-score-set-mark-below t]
1943          ["Set expunge below..." gnus-score-set-expunge-below t]
1944          ["Edit current score file" gnus-score-edit-current-scores t]
1945          ["Edit score file" gnus-score-edit-file t]
1946          ["Trace score" gnus-score-find-trace t]
1947          ["Find words" gnus-score-find-favourite-words t]
1948          ["Rescore buffer" gnus-summary-rescore t]
1949          ["Increase score..." gnus-summary-increase-score t]
1950          ["Lower score..." gnus-summary-lower-score t]))))
1951
1952     ;; Define both the Article menu in the summary buffer and the
1953     ;; equivalent Commands menu in the article buffer here for
1954     ;; consistency.
1955     (let ((innards
1956            `(("Hide"
1957               ["All" gnus-article-hide t]
1958               ["Headers" gnus-article-toggle-headers t]
1959               ["Signature" gnus-article-hide-signature t]
1960               ["Citation" gnus-article-hide-citation t]
1961               ["List identifiers" gnus-article-hide-list-identifiers t]
1962               ["PGP" gnus-article-hide-pgp t]
1963               ["Banner" gnus-article-strip-banner t]
1964               ["Boring headers" gnus-article-hide-boring-headers t])
1965              ("Highlight"
1966               ["All" gnus-article-highlight t]
1967               ["Headers" gnus-article-highlight-headers t]
1968               ["Signature" gnus-article-highlight-signature t]
1969               ["Citation" gnus-article-highlight-citation t])
1970              ("Date"
1971               ["Local" gnus-article-date-local t]
1972               ["ISO8601" gnus-article-date-iso8601 t]
1973               ["UT" gnus-article-date-ut t]
1974               ["Original" gnus-article-date-original t]
1975               ["Lapsed" gnus-article-date-lapsed t]
1976               ["User-defined" gnus-article-date-user t])
1977              ("Display"
1978               ["Remove images" gnus-article-remove-images t]
1979               ["Toggle smiley" gnus-treat-smiley t]
1980               ["Show X-Face" gnus-article-display-x-face t]
1981               ["Show picons in From" gnus-treat-from-picon t]
1982               ["Show picons in mail headers" gnus-treat-mail-picon t]
1983               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
1984               ("View as different encoding"
1985                ,@(mapcar
1986                   (lambda (cs)
1987                     ;; Since easymenu under FSF Emacs doesn't allow lambda
1988                     ;; forms for menu commands, we should provide intern'ed
1989                     ;; function symbols.
1990                     (let ((command (intern (format "\
1991 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
1992                       (fset command
1993                             `(lambda ()
1994                                (interactive)
1995                                (let ((gnus-summary-show-article-charset-alist
1996                                       '((1 . ,cs))))
1997                                  (gnus-summary-show-article 1))))
1998                       `[,(symbol-name cs) ,command t]))
1999                   (sort (if (fboundp 'coding-system-list)
2000                             (coding-system-list)
2001                           ;;(mapcar 'car mm-mime-mule-charset-alist)
2002                           )
2003                         (lambda (a b)
2004                           (string< (symbol-name a)
2005                                    (symbol-name b)))))))
2006              ("Washing"
2007               ("Remove Blanks"
2008                ["Leading" gnus-article-strip-leading-blank-lines t]
2009                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2010                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2011                ["All of the above" gnus-article-strip-blank-lines t]
2012                ["All" gnus-article-strip-all-blank-lines t]
2013                ["Leading space" gnus-article-strip-leading-space t]
2014                ["Trailing space" gnus-article-strip-trailing-space t]
2015                ["Leading space in headers"
2016                 gnus-article-remove-leading-whitespace t])
2017               ["Overstrike" gnus-article-treat-overstrike t]
2018               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2019               ["Emphasis" gnus-article-emphasize t]
2020               ["Word wrap" gnus-article-fill-cited-article t]
2021               ["Fill long lines" gnus-article-fill-long-lines t]
2022               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2023               ["CR" gnus-article-remove-cr t]
2024               ["Rot 13" gnus-summary-caesar-message
2025                ,@(if (featurep 'xemacs) '(t)
2026                    '(:help "\"Caesar rotate\" article by 13"))]
2027               ["Unix pipe" gnus-summary-pipe-message t]
2028               ["Add buttons" gnus-article-add-buttons t]
2029               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2030               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2031               ["Toggle MIME" gnus-summary-toggle-mime t]
2032               ["Verbose header" gnus-summary-verbose-headers t]
2033               ["Toggle header" gnus-summary-toggle-header t]
2034               ["Unfold headers" gnus-article-treat-unfold-headers t]
2035               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2036               ["Html" gnus-article-wash-html t]
2037               ["URLs" gnus-article-unsplit-urls t]
2038               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2039               ["HZ" gnus-article-decode-HZ t]
2040               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2041               )
2042              ("Output"
2043               ["Save in default format" gnus-summary-save-article
2044                ,@(if (featurep 'xemacs) '(t)
2045                    '(:help "Save article using default method"))]
2046               ["Save in file" gnus-summary-save-article-file
2047                ,@(if (featurep 'xemacs) '(t)
2048                    '(:help "Save article in file"))]
2049               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2050               ["Save in MH folder" gnus-summary-save-article-folder t]
2051               ["Save in VM folder" gnus-summary-save-article-vm t]
2052               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2053               ["Save body in file" gnus-summary-save-article-body-file t]
2054               ["Pipe through a filter" gnus-summary-pipe-output t]
2055               ["Add to SOUP packet" gnus-soup-add-article t]
2056               ["Print with Muttprint" gnus-summary-muttprint t]
2057               ["Print" gnus-summary-print-article t])
2058              ("Backend"
2059               ["Respool article..." gnus-summary-respool-article t]
2060               ["Move article..." gnus-summary-move-article
2061                (gnus-check-backend-function
2062                 'request-move-article gnus-newsgroup-name)]
2063               ["Copy article..." gnus-summary-copy-article t]
2064               ["Crosspost article..." gnus-summary-crosspost-article
2065                (gnus-check-backend-function
2066                 'request-replace-article gnus-newsgroup-name)]
2067               ["Import file..." gnus-summary-import-article t]
2068               ["Create article..." gnus-summary-create-article t]
2069               ["Check if posted" gnus-summary-article-posted-p t]
2070               ["Edit article" gnus-summary-edit-article
2071                (not (gnus-group-read-only-p))]
2072               ["Delete article" gnus-summary-delete-article
2073                (gnus-check-backend-function
2074                 'request-expire-articles gnus-newsgroup-name)]
2075               ["Query respool" gnus-summary-respool-query t]
2076               ["Trace respool" gnus-summary-respool-trace t]
2077               ["Delete expirable articles" gnus-summary-expire-articles-now
2078                (gnus-check-backend-function
2079                 'request-expire-articles gnus-newsgroup-name)])
2080              ("Extract"
2081               ["Uudecode" gnus-uu-decode-uu
2082                ,@(if (featurep 'xemacs) '(t)
2083                    '(:help "Decode uuencoded article(s)"))]
2084               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2085               ["Unshar" gnus-uu-decode-unshar t]
2086               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2087               ["Save" gnus-uu-decode-save t]
2088               ["Binhex" gnus-uu-decode-binhex t]
2089               ["Postscript" gnus-uu-decode-postscript t])
2090              ("Cache"
2091               ["Enter article" gnus-cache-enter-article t]
2092               ["Remove article" gnus-cache-remove-article t])
2093              ["Translate" gnus-article-babel t]
2094              ["Select article buffer" gnus-summary-select-article-buffer t]
2095              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2096              ["Isearch article..." gnus-summary-isearch-article t]
2097              ["Beginning of the article" gnus-summary-beginning-of-article t]
2098              ["End of the article" gnus-summary-end-of-article t]
2099              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2100              ["Fetch referenced articles" gnus-summary-refer-references t]
2101              ["Fetch current thread" gnus-summary-refer-thread t]
2102              ["Fetch article with id..." gnus-summary-refer-article t]
2103              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2104              ["Redisplay" gnus-summary-show-article t]
2105              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2106       (easy-menu-define
2107        gnus-summary-article-menu gnus-summary-mode-map ""
2108        (cons "Article" innards))
2109
2110       (if (not (keymapp gnus-summary-article-menu))
2111           (easy-menu-define
2112            gnus-article-commands-menu gnus-article-mode-map ""
2113            (cons "Commands" innards))
2114         ;; in Emacs, don't share menu.
2115         (setq gnus-article-commands-menu
2116               (copy-keymap gnus-summary-article-menu))
2117         (define-key gnus-article-mode-map [menu-bar commands]
2118           (cons "Commands" gnus-article-commands-menu))))
2119
2120     (easy-menu-define
2121      gnus-summary-thread-menu gnus-summary-mode-map ""
2122      '("Threads"
2123        ["Toggle threading" gnus-summary-toggle-threads t]
2124        ["Hide threads" gnus-summary-hide-all-threads t]
2125        ["Show threads" gnus-summary-show-all-threads t]
2126        ["Hide thread" gnus-summary-hide-thread t]
2127        ["Show thread" gnus-summary-show-thread t]
2128        ["Go to next thread" gnus-summary-next-thread t]
2129        ["Go to previous thread" gnus-summary-prev-thread t]
2130        ["Go down thread" gnus-summary-down-thread t]
2131        ["Go up thread" gnus-summary-up-thread t]
2132        ["Top of thread" gnus-summary-top-thread t]
2133        ["Mark thread as read" gnus-summary-kill-thread t]
2134        ["Lower thread score" gnus-summary-lower-thread t]
2135        ["Raise thread score" gnus-summary-raise-thread t]
2136        ["Rethread current" gnus-summary-rethread-current t]))
2137
2138     (easy-menu-define
2139      gnus-summary-post-menu gnus-summary-mode-map ""
2140      `("Post"
2141        ["Send a message (mail or news)" gnus-summary-post-news
2142         ,@(if (featurep 'xemacs) '(t)
2143             '(:help "Post an article"))]
2144        ["Followup" gnus-summary-followup
2145         ,@(if (featurep 'xemacs) '(t)
2146             '(:help "Post followup to this article"))]
2147        ["Followup and yank" gnus-summary-followup-with-original
2148         ,@(if (featurep 'xemacs) '(t)
2149             '(:help "Post followup to this article, quoting its contents"))]
2150        ["Supersede article" gnus-summary-supersede-article t]
2151        ["Cancel article" gnus-summary-cancel-article
2152         ,@(if (featurep 'xemacs) '(t)
2153             '(:help "Cancel an article you posted"))]
2154        ["Reply" gnus-summary-reply t]
2155        ["Reply and yank" gnus-summary-reply-with-original t]
2156        ["Wide reply" gnus-summary-wide-reply t]
2157        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2158         ,@(if (featurep 'xemacs) '(t)
2159             '(:help "Mail a reply, quoting this article"))]
2160        ["Very wide reply" gnus-summary-very-wide-reply t]
2161        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2162         ,@(if (featurep 'xemacs) '(t)
2163             '(:help "Mail a very wide reply, quoting this article"))]
2164        ["Mail forward" gnus-summary-mail-forward t]
2165        ["Post forward" gnus-summary-post-forward t]
2166        ["Digest and mail" gnus-summary-digest-mail-forward t]
2167        ["Digest and post" gnus-summary-digest-post-forward t]
2168        ["Resend message" gnus-summary-resend-message t]
2169        ["Resend message edit" gnus-summary-resend-message-edit t]
2170        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2171        ["Send a mail" gnus-summary-mail-other-window t]
2172        ["Create a local message" gnus-summary-news-other-window t]
2173        ["Uuencode and post" gnus-uu-post-news
2174         ,@(if (featurep 'xemacs) '(t)
2175             '(:help "Post a uuencoded article"))]
2176        ["Followup via news" gnus-summary-followup-to-mail t]
2177        ["Followup via news and yank"
2178         gnus-summary-followup-to-mail-with-original t]
2179        ;;("Draft"
2180        ;;["Send" gnus-summary-send-draft t]
2181        ;;["Send bounced" gnus-resend-bounced-mail t])
2182        ))
2183
2184     (cond
2185      ((not (keymapp gnus-summary-post-menu))
2186       (setq gnus-article-post-menu gnus-summary-post-menu))
2187      ((not gnus-article-post-menu)
2188       ;; Don't share post menu.
2189       (setq gnus-article-post-menu
2190             (copy-keymap gnus-summary-post-menu))))
2191     (define-key gnus-article-mode-map [menu-bar post]
2192       (cons "Post" gnus-article-post-menu))
2193
2194     (easy-menu-define
2195      gnus-summary-misc-menu gnus-summary-mode-map ""
2196      `("Gnus"
2197        ("Mark Read"
2198         ["Mark as read" gnus-summary-mark-as-read-forward t]
2199         ["Mark same subject and select"
2200          gnus-summary-kill-same-subject-and-select t]
2201         ["Mark same subject" gnus-summary-kill-same-subject t]
2202         ["Catchup" gnus-summary-catchup
2203          ,@(if (featurep 'xemacs) '(t)
2204              '(:help "Mark unread articles in this group as read"))]
2205         ["Catchup all" gnus-summary-catchup-all t]
2206         ["Catchup to here" gnus-summary-catchup-to-here t]
2207         ["Catchup from here" gnus-summary-catchup-from-here t]
2208         ["Catchup region" gnus-summary-mark-region-as-read t]
2209         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2210        ("Mark Various"
2211         ["Tick" gnus-summary-tick-article-forward t]
2212         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2213         ["Remove marks" gnus-summary-clear-mark-forward t]
2214         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2215         ["Set bookmark" gnus-summary-set-bookmark t]
2216         ["Remove bookmark" gnus-summary-remove-bookmark t])
2217        ("Limit to"
2218         ["Marks..." gnus-summary-limit-to-marks t]
2219         ["Subject..." gnus-summary-limit-to-subject t]
2220         ["Author..." gnus-summary-limit-to-author t]
2221         ["Age..." gnus-summary-limit-to-age t]
2222         ["Extra..." gnus-summary-limit-to-extra t]
2223         ["Score" gnus-summary-limit-to-score t]
2224         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2225         ["Unread" gnus-summary-limit-to-unread t]
2226         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2227         ["Articles" gnus-summary-limit-to-articles t]
2228         ["Pop limit" gnus-summary-pop-limit t]
2229         ["Show dormant" gnus-summary-limit-include-dormant t]
2230         ["Hide childless dormant"
2231          gnus-summary-limit-exclude-childless-dormant t]
2232         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2233         ["Hide marked" gnus-summary-limit-exclude-marks t]
2234         ["Show expunged" gnus-summary-limit-include-expunged t])
2235        ("Process Mark"
2236         ["Set mark" gnus-summary-mark-as-processable t]
2237         ["Remove mark" gnus-summary-unmark-as-processable t]
2238         ["Remove all marks" gnus-summary-unmark-all-processable t]
2239         ["Mark above" gnus-uu-mark-over t]
2240         ["Mark series" gnus-uu-mark-series t]
2241         ["Mark region" gnus-uu-mark-region t]
2242         ["Unmark region" gnus-uu-unmark-region t]
2243         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2244         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2245         ["Mark all" gnus-uu-mark-all t]
2246         ["Mark buffer" gnus-uu-mark-buffer t]
2247         ["Mark sparse" gnus-uu-mark-sparse t]
2248         ["Mark thread" gnus-uu-mark-thread t]
2249         ["Unmark thread" gnus-uu-unmark-thread t]
2250         ("Process Mark Sets"
2251          ["Kill" gnus-summary-kill-process-mark t]
2252          ["Yank" gnus-summary-yank-process-mark
2253           gnus-newsgroup-process-stack]
2254          ["Save" gnus-summary-save-process-mark t]))
2255        ("Scroll article"
2256         ["Page forward" gnus-summary-next-page
2257          ,@(if (featurep 'xemacs) '(t)
2258              '(:help "Show next page of article"))]
2259         ["Page backward" gnus-summary-prev-page
2260          ,@(if (featurep 'xemacs) '(t)
2261              '(:help "Show previous page of article"))]
2262         ["Line forward" gnus-summary-scroll-up t])
2263        ("Move"
2264         ["Next unread article" gnus-summary-next-unread-article t]
2265         ["Previous unread article" gnus-summary-prev-unread-article t]
2266         ["Next article" gnus-summary-next-article t]
2267         ["Previous article" gnus-summary-prev-article t]
2268         ["Next unread subject" gnus-summary-next-unread-subject t]
2269         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2270         ["Next article same subject" gnus-summary-next-same-subject t]
2271         ["Previous article same subject" gnus-summary-prev-same-subject t]
2272         ["First unread article" gnus-summary-first-unread-article t]
2273         ["Best unread article" gnus-summary-best-unread-article t]
2274         ["Go to subject number..." gnus-summary-goto-subject t]
2275         ["Go to article number..." gnus-summary-goto-article t]
2276         ["Go to the last article" gnus-summary-goto-last-article t]
2277         ["Pop article off history" gnus-summary-pop-article t])
2278        ("Sort"
2279         ["Sort by number" gnus-summary-sort-by-number t]
2280         ["Sort by author" gnus-summary-sort-by-author t]
2281         ["Sort by subject" gnus-summary-sort-by-subject t]
2282         ["Sort by date" gnus-summary-sort-by-date t]
2283         ["Sort by score" gnus-summary-sort-by-score t]
2284         ["Sort by lines" gnus-summary-sort-by-lines t]
2285         ["Sort by characters" gnus-summary-sort-by-chars t]
2286         ["Original sort" gnus-summary-sort-by-original t])
2287        ("Help"
2288         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2289         ["Describe group" gnus-summary-describe-group t]
2290         ["Read manual" gnus-info-find-node t])
2291        ("Modes"
2292         ["Pick and read" gnus-pick-mode t]
2293         ["Binary" gnus-binary-mode t])
2294        ("Regeneration"
2295         ["Regenerate" gnus-summary-prepare t]
2296         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2297         ["Toggle threading" gnus-summary-toggle-threads t])
2298        ["See old articles" gnus-summary-insert-old-articles t]
2299        ["See new articles" gnus-summary-insert-new-articles t]
2300        ["Filter articles..." gnus-summary-execute-command t]
2301        ["Run command on subjects..." gnus-summary-universal-argument t]
2302        ["Search articles forward..." gnus-summary-search-article-forward t]
2303        ["Search articles backward..." gnus-summary-search-article-backward t]
2304        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2305        ["Expand window" gnus-summary-expand-window t]
2306        ["Expire expirable articles" gnus-summary-expire-articles
2307         (gnus-check-backend-function
2308          'request-expire-articles gnus-newsgroup-name)]
2309        ["Edit local kill file" gnus-summary-edit-local-kill t]
2310        ["Edit main kill file" gnus-summary-edit-global-kill t]
2311        ["Edit group parameters" gnus-summary-edit-parameters t]
2312        ["Customize group parameters" gnus-summary-customize-parameters t]
2313        ["Send a bug report" gnus-bug t]
2314        ("Exit"
2315         ["Catchup and exit" gnus-summary-catchup-and-exit
2316          ,@(if (featurep 'xemacs) '(t)
2317              '(:help "Mark unread articles in this group as read, then exit"))]
2318         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2319         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2320         ["Exit group" gnus-summary-exit
2321          ,@(if (featurep 'xemacs) '(t)
2322              '(:help "Exit current group, return to group selection mode"))]
2323         ["Exit group without updating" gnus-summary-exit-no-update t]
2324         ["Exit and goto next group" gnus-summary-next-group t]
2325         ["Exit and goto prev group" gnus-summary-prev-group t]
2326         ["Reselect group" gnus-summary-reselect-current-group t]
2327         ["Rescan group" gnus-summary-rescan-group t]
2328         ["Update dribble" gnus-summary-save-newsrc t])))
2329
2330     (gnus-run-hooks 'gnus-summary-menu-hook)))
2331
2332 (defvar gnus-summary-tool-bar-map nil)
2333
2334 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2335 (defun gnus-summary-make-tool-bar ()
2336   (if (and (fboundp 'tool-bar-add-item-from-menu)
2337            (default-value 'tool-bar-mode)
2338            (not gnus-summary-tool-bar-map))
2339       (setq gnus-summary-tool-bar-map
2340             (let ((tool-bar-map (make-sparse-keymap))
2341                   (load-path (mm-image-load-path)))
2342               (tool-bar-add-item-from-menu
2343                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2344               (tool-bar-add-item-from-menu
2345                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2346               (tool-bar-add-item-from-menu
2347                'gnus-summary-post-news "post" gnus-summary-mode-map)
2348               (tool-bar-add-item-from-menu
2349                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2350               (tool-bar-add-item-from-menu
2351                'gnus-summary-followup "followup" gnus-summary-mode-map)
2352               (tool-bar-add-item-from-menu
2353                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2354               (tool-bar-add-item-from-menu
2355                'gnus-summary-reply "reply" gnus-summary-mode-map)
2356               (tool-bar-add-item-from-menu
2357                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2358               (tool-bar-add-item-from-menu
2359                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2360               (tool-bar-add-item-from-menu
2361                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2362               (tool-bar-add-item-from-menu
2363                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2364               (tool-bar-add-item-from-menu
2365                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2366               (tool-bar-add-item-from-menu
2367                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2368               (tool-bar-add-item-from-menu
2369                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2370               (tool-bar-add-item-from-menu
2371                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2372               tool-bar-map)))
2373   (if gnus-summary-tool-bar-map
2374       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2375
2376 (defun gnus-score-set-default (var value)
2377   "A version of set that updates the GNU Emacs menu-bar."
2378   (set var value)
2379   ;; It is the message that forces the active status to be updated.
2380   (message ""))
2381
2382 (defun gnus-make-score-map (type)
2383   "Make a summary score map of type TYPE."
2384   (if t
2385       nil
2386     (let ((headers '(("author" "from" string)
2387                      ("subject" "subject" string)
2388                      ("article body" "body" string)
2389                      ("article head" "head" string)
2390                      ("xref" "xref" string)
2391                      ("extra header" "extra" string)
2392                      ("lines" "lines" number)
2393                      ("followups to author" "followup" string)))
2394           (types '((number ("less than" <)
2395                            ("greater than" >)
2396                            ("equal" =))
2397                    (string ("substring" s)
2398                            ("exact string" e)
2399                            ("fuzzy string" f)
2400                            ("regexp" r))))
2401           (perms '(("temporary" (current-time-string))
2402                    ("permanent" nil)
2403                    ("immediate" now)))
2404           header)
2405       (list
2406        (apply
2407         'nconc
2408         (list
2409          (if (eq type 'lower)
2410              "Lower score"
2411            "Increase score"))
2412         (let (outh)
2413           (while headers
2414             (setq header (car headers))
2415             (setq outh
2416                   (cons
2417                    (apply
2418                     'nconc
2419                     (list (car header))
2420                     (let ((ts (cdr (assoc (nth 2 header) types)))
2421                           outt)
2422                       (while ts
2423                         (setq outt
2424                               (cons
2425                                (apply
2426                                 'nconc
2427                                 (list (caar ts))
2428                                 (let ((ps perms)
2429                                       outp)
2430                                   (while ps
2431                                     (setq outp
2432                                           (cons
2433                                            (vector
2434                                             (caar ps)
2435                                             (list
2436                                              'gnus-summary-score-entry
2437                                              (nth 1 header)
2438                                              (if (or (string= (nth 1 header)
2439                                                               "head")
2440                                                      (string= (nth 1 header)
2441                                                               "body"))
2442                                                  ""
2443                                                (list 'gnus-summary-header
2444                                                      (nth 1 header)))
2445                                              (list 'quote (nth 1 (car ts)))
2446                                              (list 'gnus-score-delta-default
2447                                                    nil)
2448                                              (nth 1 (car ps))
2449                                              t)
2450                                             t)
2451                                            outp))
2452                                     (setq ps (cdr ps)))
2453                                   (list (nreverse outp))))
2454                                outt))
2455                         (setq ts (cdr ts)))
2456                       (list (nreverse outt))))
2457                    outh))
2458             (setq headers (cdr headers)))
2459           (list (nreverse outh))))))))
2460
2461 \f
2462
2463 (defun gnus-summary-mode (&optional group)
2464   "Major mode for reading articles.
2465
2466 All normal editing commands are switched off.
2467 \\<gnus-summary-mode-map>
2468 Each line in this buffer represents one article.  To read an
2469 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2470 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2471 respectively.
2472
2473 You can also post articles and send mail from this buffer.  To
2474 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2475 of an article, type `\\[gnus-summary-reply]'.
2476
2477 There are approx. one gazillion commands you can execute in this
2478 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2479
2480 The following commands are available:
2481
2482 \\{gnus-summary-mode-map}"
2483   (interactive)
2484   (kill-all-local-variables)
2485   (when (gnus-visual-p 'summary-menu 'menu)
2486     (gnus-summary-make-menu-bar)
2487     (gnus-summary-make-tool-bar))
2488   (gnus-summary-make-local-variables)
2489   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2490     (gnus-summary-make-local-variables))
2491   (gnus-make-thread-indent-array)
2492   (gnus-simplify-mode-line)
2493   (setq major-mode 'gnus-summary-mode)
2494   (setq mode-name "Summary")
2495   (make-local-variable 'minor-mode-alist)
2496   (use-local-map gnus-summary-mode-map)
2497   (buffer-disable-undo)
2498   (setq buffer-read-only t)             ;Disable modification
2499   (setq truncate-lines t)
2500   (setq selective-display t)
2501   (setq selective-display-ellipses t)   ;Display `...'
2502   (gnus-summary-set-display-table)
2503   (gnus-set-default-directory)
2504   (setq gnus-newsgroup-name group)
2505   (unless (gnus-news-group-p group)
2506     (setq gnus-newsgroup-incorporated
2507           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2508   (make-local-variable 'gnus-summary-line-format)
2509   (make-local-variable 'gnus-summary-line-format-spec)
2510   (make-local-variable 'gnus-summary-dummy-line-format)
2511   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2512   (make-local-variable 'gnus-summary-mark-positions)
2513   (make-local-hook 'pre-command-hook)
2514   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2515   (gnus-run-hooks 'gnus-summary-mode-hook)
2516   (turn-on-gnus-mailing-list-mode)
2517   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2518   (gnus-update-summary-mark-positions))
2519
2520 (defun gnus-summary-make-local-variables ()
2521   "Make all the local summary buffer variables."
2522   (let (global)
2523     (dolist (local gnus-summary-local-variables)
2524       (if (consp local)
2525           (progn
2526             (if (eq (cdr local) 'global)
2527                 ;; Copy the global value of the variable.
2528                 (setq global (symbol-value (car local)))
2529               ;; Use the value from the list.
2530               (setq global (eval (cdr local))))
2531             (set (make-local-variable (car local)) global))
2532         ;; Simple nil-valued local variable.
2533         (set (make-local-variable local) nil)))))
2534
2535 (defun gnus-summary-clear-local-variables ()
2536   (let ((locals gnus-summary-local-variables))
2537     (while locals
2538       (if (consp (car locals))
2539           (and (vectorp (caar locals))
2540                (set (caar locals) nil))
2541         (and (vectorp (car locals))
2542              (set (car locals) nil)))
2543       (setq locals (cdr locals)))))
2544
2545 ;; Summary data functions.
2546
2547 (defmacro gnus-data-number (data)
2548   `(car ,data))
2549
2550 (defmacro gnus-data-set-number (data number)
2551   `(setcar ,data ,number))
2552
2553 (defmacro gnus-data-mark (data)
2554   `(nth 1 ,data))
2555
2556 (defmacro gnus-data-set-mark (data mark)
2557   `(setcar (nthcdr 1 ,data) ,mark))
2558
2559 (defmacro gnus-data-pos (data)
2560   `(nth 2 ,data))
2561
2562 (defmacro gnus-data-set-pos (data pos)
2563   `(setcar (nthcdr 2 ,data) ,pos))
2564
2565 (defmacro gnus-data-header (data)
2566   `(nth 3 ,data))
2567
2568 (defmacro gnus-data-set-header (data header)
2569   `(setcar (nthcdr 3 ,data) ,header))
2570
2571 (defmacro gnus-data-level (data)
2572   `(nth 4 ,data))
2573
2574 (defmacro gnus-data-unread-p (data)
2575   `(= (nth 1 ,data) gnus-unread-mark))
2576
2577 (defmacro gnus-data-read-p (data)
2578   `(/= (nth 1 ,data) gnus-unread-mark))
2579
2580 (defmacro gnus-data-pseudo-p (data)
2581   `(consp (nth 3 ,data)))
2582
2583 (defmacro gnus-data-find (number)
2584   `(assq ,number gnus-newsgroup-data))
2585
2586 (defmacro gnus-data-find-list (number &optional data)
2587   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2588      (memq (assq ,number bdata)
2589            bdata)))
2590
2591 (defmacro gnus-data-make (number mark pos header level)
2592   `(list ,number ,mark ,pos ,header ,level))
2593
2594 (defun gnus-data-enter (after-article number mark pos header level offset)
2595   (let ((data (gnus-data-find-list after-article)))
2596     (unless data
2597       (error "No such article: %d" after-article))
2598     (setcdr data (cons (gnus-data-make number mark pos header level)
2599                        (cdr data)))
2600     (setq gnus-newsgroup-data-reverse nil)
2601     (gnus-data-update-list (cddr data) offset)))
2602
2603 (defun gnus-data-enter-list (after-article list &optional offset)
2604   (when list
2605     (let ((data (and after-article (gnus-data-find-list after-article)))
2606           (ilist list))
2607       (if (not (or data
2608                    after-article))
2609           (let ((odata gnus-newsgroup-data))
2610             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2611             (when offset
2612               (gnus-data-update-list odata offset)))
2613         ;; Find the last element in the list to be spliced into the main
2614         ;; list.
2615         (while (cdr list)
2616           (setq list (cdr list)))
2617         (if (not data)
2618             (progn
2619               (setcdr list gnus-newsgroup-data)
2620               (setq gnus-newsgroup-data ilist)
2621               (when offset
2622                 (gnus-data-update-list (cdr list) offset)))
2623           (setcdr list (cdr data))
2624           (setcdr data ilist)
2625           (when offset
2626             (gnus-data-update-list (cdr list) offset))))
2627       (setq gnus-newsgroup-data-reverse nil))))
2628
2629 (defun gnus-data-remove (article &optional offset)
2630   (let ((data gnus-newsgroup-data))
2631     (if (= (gnus-data-number (car data)) article)
2632         (progn
2633           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2634                 gnus-newsgroup-data-reverse nil)
2635           (when offset
2636             (gnus-data-update-list gnus-newsgroup-data offset)))
2637       (while (cdr data)
2638         (when (= (gnus-data-number (cadr data)) article)
2639           (setcdr data (cddr data))
2640           (when offset
2641             (gnus-data-update-list (cdr data) offset))
2642           (setq data nil
2643                 gnus-newsgroup-data-reverse nil))
2644         (setq data (cdr data))))))
2645
2646 (defmacro gnus-data-list (backward)
2647   `(if ,backward
2648        (or gnus-newsgroup-data-reverse
2649            (setq gnus-newsgroup-data-reverse
2650                  (reverse gnus-newsgroup-data)))
2651      gnus-newsgroup-data))
2652
2653 (defun gnus-data-update-list (data offset)
2654   "Add OFFSET to the POS of all data entries in DATA."
2655   (setq gnus-newsgroup-data-reverse nil)
2656   (while data
2657     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2658     (setq data (cdr data))))
2659
2660 (defun gnus-summary-article-pseudo-p (article)
2661   "Say whether this article is a pseudo article or not."
2662   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2663
2664 (defmacro gnus-summary-article-sparse-p (article)
2665   "Say whether this article is a sparse article or not."
2666   `(memq ,article gnus-newsgroup-sparse))
2667
2668 (defmacro gnus-summary-article-ancient-p (article)
2669   "Say whether this article is a sparse article or not."
2670   `(memq ,article gnus-newsgroup-ancient))
2671
2672 (defun gnus-article-parent-p (number)
2673   "Say whether this article is a parent or not."
2674   (let ((data (gnus-data-find-list number)))
2675     (and (cdr data)                     ; There has to be an article after...
2676          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2677             (gnus-data-level (nth 1 data))))))
2678
2679 (defun gnus-article-children (number)
2680   "Return a list of all children to NUMBER."
2681   (let* ((data (gnus-data-find-list number))
2682          (level (gnus-data-level (car data)))
2683          children)
2684     (setq data (cdr data))
2685     (while (and data
2686                 (= (gnus-data-level (car data)) (1+ level)))
2687       (push (gnus-data-number (car data)) children)
2688       (setq data (cdr data)))
2689     children))
2690
2691 (defmacro gnus-summary-skip-intangible ()
2692   "If the current article is intangible, then jump to a different article."
2693   '(let ((to (get-text-property (point) 'gnus-intangible)))
2694      (and to (gnus-summary-goto-subject to))))
2695
2696 (defmacro gnus-summary-article-intangible-p ()
2697   "Say whether this article is intangible or not."
2698   '(get-text-property (point) 'gnus-intangible))
2699
2700 (defun gnus-article-read-p (article)
2701   "Say whether ARTICLE is read or not."
2702   (not (or (memq article gnus-newsgroup-marked)
2703            (memq article gnus-newsgroup-unreads)
2704            (memq article gnus-newsgroup-unselected)
2705            (memq article gnus-newsgroup-dormant))))
2706
2707 ;; Some summary mode macros.
2708
2709 (defmacro gnus-summary-article-number ()
2710   "The article number of the article on the current line.
2711 If there isn's an article number here, then we return the current
2712 article number."
2713   '(progn
2714      (gnus-summary-skip-intangible)
2715      (or (get-text-property (point) 'gnus-number)
2716          (gnus-summary-last-subject))))
2717
2718 (defmacro gnus-summary-article-header (&optional number)
2719   "Return the header of article NUMBER."
2720   `(gnus-data-header (gnus-data-find
2721                       ,(or number '(gnus-summary-article-number)))))
2722
2723 (defmacro gnus-summary-thread-level (&optional number)
2724   "Return the level of thread that starts with article NUMBER."
2725   `(if (and (eq gnus-summary-make-false-root 'dummy)
2726             (get-text-property (point) 'gnus-intangible))
2727        0
2728      (gnus-data-level (gnus-data-find
2729                        ,(or number '(gnus-summary-article-number))))))
2730
2731 (defmacro gnus-summary-article-mark (&optional number)
2732   "Return the mark of article NUMBER."
2733   `(gnus-data-mark (gnus-data-find
2734                     ,(or number '(gnus-summary-article-number)))))
2735
2736 (defmacro gnus-summary-article-pos (&optional number)
2737   "Return the position of the line of article NUMBER."
2738   `(gnus-data-pos (gnus-data-find
2739                    ,(or number '(gnus-summary-article-number)))))
2740
2741 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2742 (defmacro gnus-summary-article-subject (&optional number)
2743   "Return current subject string or nil if nothing."
2744   `(let ((headers
2745           ,(if number
2746                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2747              '(gnus-data-header (assq (gnus-summary-article-number)
2748                                       gnus-newsgroup-data)))))
2749      (and headers
2750           (vectorp headers)
2751           (mail-header-subject headers))))
2752
2753 (defmacro gnus-summary-article-score (&optional number)
2754   "Return current article score."
2755   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2756                   gnus-newsgroup-scored))
2757        gnus-summary-default-score 0))
2758
2759 (defun gnus-summary-article-children (&optional number)
2760   "Return a list of article numbers that are children of article NUMBER."
2761   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2762          (level (gnus-data-level (car data)))
2763          l children)
2764     (while (and (setq data (cdr data))
2765                 (> (setq l (gnus-data-level (car data))) level))
2766       (and (= (1+ level) l)
2767            (push (gnus-data-number (car data))
2768                  children)))
2769     (nreverse children)))
2770
2771 (defun gnus-summary-article-parent (&optional number)
2772   "Return the article number of the parent of article NUMBER."
2773   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2774                                     (gnus-data-list t)))
2775          (level (gnus-data-level (car data))))
2776     (if (zerop level)
2777         ()                              ; This is a root.
2778       ;; We search until we find an article with a level less than
2779       ;; this one.  That function has to be the parent.
2780       (while (and (setq data (cdr data))
2781                   (not (< (gnus-data-level (car data)) level))))
2782       (and data (gnus-data-number (car data))))))
2783
2784 (defun gnus-unread-mark-p (mark)
2785   "Say whether MARK is the unread mark."
2786   (= mark gnus-unread-mark))
2787
2788 (defun gnus-read-mark-p (mark)
2789   "Say whether MARK is one of the marks that mark as read.
2790 This is all marks except unread, ticked, dormant, and expirable."
2791   (not (or (= mark gnus-unread-mark)
2792            (= mark gnus-ticked-mark)
2793            (= mark gnus-dormant-mark)
2794            (= mark gnus-expirable-mark))))
2795
2796 (defmacro gnus-article-mark (number)
2797   "Return the MARK of article NUMBER.
2798 This macro should only be used when computing the mark the \"first\"
2799 time; i.e., when generating the summary lines.  After that,
2800 `gnus-summary-article-mark' should be used to examine the
2801 marks of articles."
2802   `(cond
2803     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2804     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2805     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2806     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2807     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2808     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2809     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2810     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2811            gnus-ancient-mark))))
2812
2813 ;; Saving hidden threads.
2814
2815 (defmacro gnus-save-hidden-threads (&rest forms)
2816   "Save hidden threads, eval FORMS, and restore the hidden threads."
2817   (let ((config (make-symbol "config")))
2818     `(let ((,config (gnus-hidden-threads-configuration)))
2819        (unwind-protect
2820            (save-excursion
2821              ,@forms)
2822          (gnus-restore-hidden-threads-configuration ,config)))))
2823 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2824 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2825
2826 (defun gnus-data-compute-positions ()
2827   "Compute the positions of all articles."
2828   (setq gnus-newsgroup-data-reverse nil)
2829   (let ((data gnus-newsgroup-data))
2830     (save-excursion
2831       (gnus-save-hidden-threads
2832         (gnus-summary-show-all-threads)
2833         (goto-char (point-min))
2834         (while data
2835           (while (get-text-property (point) 'gnus-intangible)
2836             (forward-line 1))
2837           (gnus-data-set-pos (car data) (+ (point) 3))
2838           (setq data (cdr data))
2839           (forward-line 1))))))
2840
2841 (defun gnus-hidden-threads-configuration ()
2842   "Return the current hidden threads configuration."
2843   (save-excursion
2844     (let (config)
2845       (goto-char (point-min))
2846       (while (search-forward "\r" nil t)
2847         (push (1- (point)) config))
2848       config)))
2849
2850 (defun gnus-restore-hidden-threads-configuration (config)
2851   "Restore hidden threads configuration from CONFIG."
2852   (save-excursion
2853     (let (point buffer-read-only)
2854       (while (setq point (pop config))
2855         (when (and (< point (point-max))
2856                    (goto-char point)
2857                    (eq (char-after) ?\n))
2858           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2859
2860 ;; Various summary mode internalish functions.
2861
2862 (defun gnus-mouse-pick-article (e)
2863   (interactive "e")
2864   (mouse-set-point e)
2865   (gnus-summary-next-page nil t))
2866
2867 (defun gnus-summary-set-display-table ()
2868   "Change the display table.
2869 Odd characters have a tendency to mess
2870 up nicely formatted displays - we make all possible glyphs
2871 display only a single character."
2872
2873   ;; We start from the standard display table, if any.
2874   (let ((table (or (copy-sequence standard-display-table)
2875                    (make-display-table)))
2876         (i 32))
2877     ;; Nix out all the control chars...
2878     (while (>= (setq i (1- i)) 0)
2879       (aset table i [??]))
2880     ;; ... but not newline and cr, of course.  (cr is necessary for the
2881     ;; selective display).
2882     (aset table ?\n nil)
2883     (aset table ?\r nil)
2884     ;; We keep TAB as well.
2885     (aset table ?\t nil)
2886     ;; We nix out any glyphs over 126 that are not set already.
2887     (let ((i 256))
2888       (while (>= (setq i (1- i)) 127)
2889         ;; Only modify if the entry is nil.
2890         (unless (aref table i)
2891           (aset table i [??]))))
2892     (setq buffer-display-table table)))
2893
2894 (defun gnus-summary-set-article-display-arrow (pos)
2895   "Update the overlay arrow to point to line at position POS."
2896   (when (and gnus-summary-display-arrow
2897              (boundp 'overlay-arrow-position)
2898              (boundp 'overlay-arrow-string))
2899     (save-excursion
2900       (goto-char pos)
2901       (beginning-of-line)
2902       (unless overlay-arrow-position
2903         (setq overlay-arrow-position (make-marker)))
2904       (setq overlay-arrow-string "=>"
2905             overlay-arrow-position (set-marker overlay-arrow-position
2906                                                (point)
2907                                                (current-buffer))))))
2908
2909 (defun gnus-summary-buffer-name (group)
2910   "Return the summary buffer name of GROUP."
2911   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2912
2913 (defun gnus-summary-setup-buffer (group)
2914   "Initialize summary buffer."
2915   (let ((buffer (gnus-summary-buffer-name group))
2916         (dead-name (concat "*Dead Summary "
2917                            (gnus-group-decoded-name group) "*")))
2918     ;; If a dead summary buffer exists, we kill it.
2919     (when (gnus-buffer-live-p dead-name)
2920       (gnus-kill-buffer dead-name))
2921     (if (get-buffer buffer)
2922         (progn
2923           (set-buffer buffer)
2924           (setq gnus-summary-buffer (current-buffer))
2925           (not gnus-newsgroup-prepared))
2926       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2927       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2928       (gnus-summary-mode group)
2929       (when gnus-carpal
2930         (gnus-carpal-setup-buffer 'summary))
2931       (unless gnus-single-article-buffer
2932         (make-local-variable 'gnus-article-buffer)
2933         (make-local-variable 'gnus-article-current)
2934         (make-local-variable 'gnus-original-article-buffer))
2935       (setq gnus-newsgroup-name group)
2936       ;; Set any local variables in the group parameters.
2937       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2938       t)))
2939
2940 (defun gnus-set-global-variables ()
2941   "Set the global equivalents of the buffer-local variables.
2942 They are set to the latest values they had.  These reflect the summary
2943 buffer that was in action when the last article was fetched."
2944   (when (eq major-mode 'gnus-summary-mode)
2945     (setq gnus-summary-buffer (current-buffer))
2946     (let ((name gnus-newsgroup-name)
2947           (marked gnus-newsgroup-marked)
2948           (unread gnus-newsgroup-unreads)
2949           (headers gnus-current-headers)
2950           (data gnus-newsgroup-data)
2951           (summary gnus-summary-buffer)
2952           (article-buffer gnus-article-buffer)
2953           (original gnus-original-article-buffer)
2954           (gac gnus-article-current)
2955           (reffed gnus-reffed-article-number)
2956           (score-file gnus-current-score-file)
2957           (default-charset gnus-newsgroup-charset)
2958           vlist)
2959       (let ((locals gnus-newsgroup-variables))
2960         (while locals
2961           (if (consp (car locals))
2962               (push (eval (caar locals)) vlist)
2963             (push (eval (car locals)) vlist))
2964           (setq locals (cdr locals)))
2965         (setq vlist (nreverse vlist)))
2966       (save-excursion
2967         (set-buffer gnus-group-buffer)
2968         (setq gnus-newsgroup-name name
2969               gnus-newsgroup-marked marked
2970               gnus-newsgroup-unreads unread
2971               gnus-current-headers headers
2972               gnus-newsgroup-data data
2973               gnus-article-current gac
2974               gnus-summary-buffer summary
2975               gnus-article-buffer article-buffer
2976               gnus-original-article-buffer original
2977               gnus-reffed-article-number reffed
2978               gnus-current-score-file score-file
2979               gnus-newsgroup-charset default-charset)
2980         (let ((locals gnus-newsgroup-variables))
2981           (while locals
2982             (if (consp (car locals))
2983                 (set (caar locals) (pop vlist))
2984               (set (car locals) (pop vlist)))
2985             (setq locals (cdr locals))))
2986         ;; The article buffer also has local variables.
2987         (when (gnus-buffer-live-p gnus-article-buffer)
2988           (set-buffer gnus-article-buffer)
2989           (setq gnus-summary-buffer summary))))))
2990
2991 (defun gnus-summary-article-unread-p (article)
2992   "Say whether ARTICLE is unread or not."
2993   (memq article gnus-newsgroup-unreads))
2994
2995 (defun gnus-summary-first-article-p (&optional article)
2996   "Return whether ARTICLE is the first article in the buffer."
2997   (if (not (setq article (or article (gnus-summary-article-number))))
2998       nil
2999     (eq article (caar gnus-newsgroup-data))))
3000
3001 (defun gnus-summary-last-article-p (&optional article)
3002   "Return whether ARTICLE is the last article in the buffer."
3003   (if (not (setq article (or article (gnus-summary-article-number))))
3004       ;; All non-existent numbers are the last article.  :-)
3005       t
3006     (not (cdr (gnus-data-find-list article)))))
3007
3008 (defun gnus-make-thread-indent-array ()
3009   (let ((n 200))
3010     (unless (and gnus-thread-indent-array
3011                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3012       (setq gnus-thread-indent-array (make-vector 201 "")
3013             gnus-thread-indent-array-level gnus-thread-indent-level)
3014       (while (>= n 0)
3015         (aset gnus-thread-indent-array n
3016               (make-string (* n gnus-thread-indent-level) ? ))
3017         (setq n (1- n))))))
3018
3019 (defun gnus-update-summary-mark-positions ()
3020   "Compute where the summary marks are to go."
3021   (save-excursion
3022     (when (gnus-buffer-exists-p gnus-summary-buffer)
3023       (set-buffer gnus-summary-buffer))
3024     (let ((gnus-replied-mark 129)
3025           (gnus-score-below-mark 130)
3026           (gnus-score-over-mark 130)
3027           (gnus-download-mark 131)
3028           (spec gnus-summary-line-format-spec)
3029           gnus-visual pos)
3030       (save-excursion
3031         (gnus-set-work-buffer)
3032         (let ((gnus-summary-line-format-spec spec)
3033               (gnus-newsgroup-downloadable '((0 . t))))
3034           (gnus-summary-insert-line
3035            (make-full-mail-header 0 "" "nobody"
3036                                   "05 Apr 2001 23:33:09 +0400"
3037                                   "" "" 0 0 "" nil)
3038            0 nil 128 t nil "" nil 1)
3039           (goto-char (point-min))
3040           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3041                                              (- (point) (point-min) 1)))))
3042           (goto-char (point-min))
3043           (push (cons 'replied (and (search-forward "\201" nil t)
3044                                     (- (point) (point-min) 1)))
3045                 pos)
3046           (goto-char (point-min))
3047           (push (cons 'score (and (search-forward "\202" nil t)
3048                                   (- (point) (point-min) 1)))
3049                 pos)
3050           (goto-char (point-min))
3051           (push (cons 'download
3052                       (and (search-forward "\203" nil t)
3053                            (- (point) (point-min) 1)))
3054                 pos)))
3055       (setq gnus-summary-mark-positions pos))))
3056
3057 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3058   "Insert a dummy root in the summary buffer."
3059   (beginning-of-line)
3060   (gnus-add-text-properties
3061    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3062    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3063
3064 (defun gnus-summary-extract-address-component (from)
3065   (or (car (funcall gnus-extract-address-components from))
3066       from))
3067
3068 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3069   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3070                                 default-mime-charset)))
3071     ;; Is it really necessary to do this next part for each summary line?
3072     ;; Luckily, doesn't seem to slow things down much.
3073     (or
3074      (and gnus-ignored-from-addresses
3075           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3076           (let ((extra-headers (mail-header-extra header))
3077                 to
3078                 newsgroups)
3079             (cond
3080              ((setq to (cdr (assq 'To extra-headers)))
3081               (concat "-> "
3082                       (inline
3083                         (gnus-summary-extract-address-component
3084                          (funcall gnus-decode-encoded-word-function to)))))
3085              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3086               (concat "=> " newsgroups)))))
3087      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3088
3089 (defun gnus-summary-insert-line (gnus-tmp-header
3090                                  gnus-tmp-level gnus-tmp-current
3091                                  gnus-tmp-unread gnus-tmp-replied
3092                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3093                                  &optional gnus-tmp-dummy gnus-tmp-score
3094                                  gnus-tmp-process)
3095   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3096          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3097          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3098          (gnus-tmp-score-char
3099           (if (or (null gnus-summary-default-score)
3100                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3101                       gnus-summary-zcore-fuzz))
3102               ?\ ;;;Whitespace
3103             (if (< gnus-tmp-score gnus-summary-default-score)
3104                 gnus-score-below-mark gnus-score-over-mark)))
3105          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3106          (gnus-tmp-replied
3107           (cond (gnus-tmp-process gnus-process-mark)
3108                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3109                  gnus-cached-mark)
3110                 (gnus-tmp-replied gnus-replied-mark)
3111                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3112                  gnus-forwarded-mark)
3113                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3114                  gnus-saved-mark)
3115                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3116                  gnus-recent-mark)
3117                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3118                  gnus-unseen-mark)
3119                 (t gnus-no-mark)))
3120          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3121          (gnus-tmp-name
3122           (cond
3123            ((string-match "<[^>]+> *$" gnus-tmp-from)
3124             (let ((beg (match-beginning 0)))
3125               (or (and (string-match "^\".+\"" gnus-tmp-from)
3126                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3127                   (substring gnus-tmp-from 0 beg))))
3128            ((string-match "(.+)" gnus-tmp-from)
3129             (substring gnus-tmp-from
3130                        (1+ (match-beginning 0)) (1- (match-end 0))))
3131            (t gnus-tmp-from)))
3132          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3133          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3134          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3135          (buffer-read-only nil))
3136     (when (string= gnus-tmp-name "")
3137       (setq gnus-tmp-name gnus-tmp-from))
3138     (unless (numberp gnus-tmp-lines)
3139       (setq gnus-tmp-lines -1))
3140     (if (= gnus-tmp-lines -1)
3141         (setq gnus-tmp-lines "?")
3142       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3143     (gnus-put-text-property-excluding-characters-with-faces
3144      (point)
3145      (progn (eval gnus-summary-line-format-spec) (point))
3146      'gnus-number gnus-tmp-number)
3147     (when (gnus-visual-p 'summary-highlight 'highlight)
3148       (forward-line -1)
3149       (gnus-run-hooks 'gnus-summary-update-hook)
3150       (forward-line 1))))
3151
3152 (defun gnus-summary-update-line (&optional dont-update)
3153   "Update summary line after change."
3154   (when (and gnus-summary-default-score
3155              (not gnus-summary-inhibit-highlight))
3156     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3157            (article (gnus-summary-article-number))
3158            (score (gnus-summary-article-score article)))
3159       (unless dont-update
3160         (if (and gnus-summary-mark-below
3161                  (< (gnus-summary-article-score)
3162                     gnus-summary-mark-below))
3163             ;; This article has a low score, so we mark it as read.
3164             (when (memq article gnus-newsgroup-unreads)
3165               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3166           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3167             ;; This article was previously marked as read on account
3168             ;; of a low score, but now it has risen, so we mark it as
3169             ;; unread.
3170             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3171         (gnus-summary-update-mark
3172          (if (or (null gnus-summary-default-score)
3173                  (<= (abs (- score gnus-summary-default-score))
3174                      gnus-summary-zcore-fuzz))
3175              ?\ ;;;Whitespace
3176            (if (< score gnus-summary-default-score)
3177                gnus-score-below-mark gnus-score-over-mark))
3178          'score))
3179       ;; Do visual highlighting.
3180       (when (gnus-visual-p 'summary-highlight 'highlight)
3181         (gnus-run-hooks 'gnus-summary-update-hook)))))
3182
3183 (defvar gnus-tmp-new-adopts nil)
3184
3185 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3186   "Return the number of articles in THREAD.
3187 This may be 0 in some cases -- if none of the articles in
3188 the thread are to be displayed."
3189   (let* ((number
3190           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3191           (cond
3192            ((not (listp thread))
3193             1)
3194            ((and (consp thread) (cdr thread))
3195             (apply
3196              '+ 1 (mapcar
3197                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3198            ((null thread)
3199             1)
3200            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3201             1)
3202            (t 0))))
3203     (when (and level (zerop level) gnus-tmp-new-adopts)
3204       (incf number
3205             (apply '+ (mapcar
3206                        'gnus-summary-number-of-articles-in-thread
3207                        gnus-tmp-new-adopts))))
3208     (if char
3209         (if (> number 1) gnus-not-empty-thread-mark
3210           gnus-empty-thread-mark)
3211       number)))
3212
3213 (defun gnus-summary-set-local-parameters (group)
3214   "Go through the local params of GROUP and set all variable specs in that list."
3215   (let ((params (gnus-group-find-parameter group))
3216         (vars '(quit-config))           ; Ignore quit-config.
3217         elem)
3218     (while params
3219       (setq elem (car params)
3220             params (cdr params))
3221       (and (consp elem)                 ; Has to be a cons.
3222            (consp (cdr elem))           ; The cdr has to be a list.
3223            (symbolp (car elem))         ; Has to be a symbol in there.
3224            (not (memq (car elem) vars))
3225            (ignore-errors               ; So we set it.
3226              (push (car elem) vars)
3227              (make-local-variable (car elem))
3228              (set (car elem) (eval (nth 1 elem))))))))
3229
3230 (defun gnus-summary-read-group (group &optional show-all no-article
3231                                       kill-buffer no-display backward
3232                                       select-articles)
3233   "Start reading news in newsgroup GROUP.
3234 If SHOW-ALL is non-nil, already read articles are also listed.
3235 If NO-ARTICLE is non-nil, no article is selected initially.
3236 If NO-DISPLAY, don't generate a summary buffer."
3237   (let (result)
3238     (while (and group
3239                 (null (setq result
3240                             (let ((gnus-auto-select-next nil))
3241                               (or (gnus-summary-read-group-1
3242                                    group show-all no-article
3243                                    kill-buffer no-display
3244                                    select-articles)
3245                                   (setq show-all nil
3246                                         select-articles nil)))))
3247                 (eq gnus-auto-select-next 'quietly))
3248       (set-buffer gnus-group-buffer)
3249       ;; The entry function called above goes to the next
3250       ;; group automatically, so we go two groups back
3251       ;; if we are searching for the previous group.
3252       (when backward
3253         (gnus-group-prev-unread-group 2))
3254       (if (not (equal group (gnus-group-group-name)))
3255           (setq group (gnus-group-group-name))
3256         (setq group nil)))
3257     result))
3258
3259 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3260   "Directly jump to the other GROUP from summary buffer.
3261 If SHOW-ALL is non-nil, already read articles are also listed."
3262   (interactive
3263    (if (eq gnus-summary-buffer (current-buffer))
3264        (list (completing-read
3265               "Group: " gnus-active-hashtb nil t
3266               (when (and gnus-newsgroup-name
3267                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3268                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3269               'gnus-group-history)
3270              current-prefix-arg)
3271      (error "%s must be invoked from a gnus summary buffer." this-command)))
3272   (unless (or (zerop (length group))
3273               (and gnus-newsgroup-name
3274                    (string-equal gnus-newsgroup-name group)))
3275     (gnus-summary-exit)
3276     (gnus-summary-read-group group show-all
3277                              gnus-dont-select-after-jump-to-other-group)))
3278
3279 (defun gnus-summary-read-group-1 (group show-all no-article
3280                                         kill-buffer no-display
3281                                         &optional select-articles)
3282   ;; Killed foreign groups can't be entered.
3283   ;;  (when (and (not (gnus-group-native-p group))
3284   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3285   ;;    (error "Dead non-native groups can't be entered"))
3286   (gnus-message 5 "Retrieving newsgroup: %s..."
3287                 (gnus-group-decoded-name group))
3288   (let* ((new-group (gnus-summary-setup-buffer group))
3289          (quit-config (gnus-group-quit-config group))
3290          (did-select (and new-group (gnus-select-newsgroup
3291                                      group show-all select-articles))))
3292     (cond
3293      ;; This summary buffer exists already, so we just select it.
3294      ((not new-group)
3295       (gnus-set-global-variables)
3296       (when kill-buffer
3297         (gnus-kill-or-deaden-summary kill-buffer))
3298       (gnus-configure-windows 'summary 'force)
3299       (gnus-set-mode-line 'summary)
3300       (gnus-summary-position-point)
3301       (message "")
3302       t)
3303      ;; We couldn't select this group.
3304      ((null did-select)
3305       (when (and (eq major-mode 'gnus-summary-mode)
3306                  (not (equal (current-buffer) kill-buffer)))
3307         (kill-buffer (current-buffer))
3308         (if (not quit-config)
3309             (progn
3310               ;; Update the info -- marks might need to be removed,
3311               ;; for instance.
3312               (gnus-summary-update-info)
3313               (set-buffer gnus-group-buffer)
3314               (gnus-group-jump-to-group group)
3315               (gnus-group-next-unread-group 1))
3316           (gnus-handle-ephemeral-exit quit-config)))
3317       (let ((grpinfo (gnus-get-info group)))
3318         (if (null (gnus-info-read grpinfo))
3319             (gnus-message 3 "Group %s contains no messages"
3320                           (gnus-group-decoded-name group))
3321           (gnus-message 3 "Can't select group")))
3322       nil)
3323      ;; The user did a `C-g' while prompting for number of articles,
3324      ;; so we exit this group.
3325      ((eq did-select 'quit)
3326       (and (eq major-mode 'gnus-summary-mode)
3327            (not (equal (current-buffer) kill-buffer))
3328            (kill-buffer (current-buffer)))
3329       (when kill-buffer
3330         (gnus-kill-or-deaden-summary kill-buffer))
3331       (if (not quit-config)
3332           (progn
3333             (set-buffer gnus-group-buffer)
3334             (gnus-group-jump-to-group group)
3335             (gnus-group-next-unread-group 1)
3336             (gnus-configure-windows 'group 'force))
3337         (gnus-handle-ephemeral-exit quit-config))
3338       ;; Finally signal the quit.
3339       (signal 'quit nil))
3340      ;; The group was successfully selected.
3341      (t
3342       (gnus-set-global-variables)
3343       ;; Save the active value in effect when the group was entered.
3344       (setq gnus-newsgroup-active
3345             (gnus-copy-sequence
3346              (gnus-active gnus-newsgroup-name)))
3347       ;; You can change the summary buffer in some way with this hook.
3348       (gnus-run-hooks 'gnus-select-group-hook)
3349       (gnus-update-format-specifications
3350        nil 'summary 'summary-mode 'summary-dummy)
3351       (gnus-update-summary-mark-positions)
3352       ;; Do score processing.
3353       (when gnus-use-scoring
3354         (gnus-possibly-score-headers))
3355       ;; Check whether to fill in the gaps in the threads.
3356       (when gnus-build-sparse-threads
3357         (gnus-build-sparse-threads))
3358       ;; Find the initial limit.
3359       (if gnus-show-threads
3360           (if show-all
3361               (let ((gnus-newsgroup-dormant nil))
3362                 (gnus-summary-initial-limit show-all))
3363             (gnus-summary-initial-limit show-all))
3364         ;; When untreaded, all articles are always shown.
3365         (setq gnus-newsgroup-limit
3366               (mapcar
3367                (lambda (header) (mail-header-number header))
3368                gnus-newsgroup-headers)))
3369       ;; Generate the summary buffer.
3370       (unless no-display
3371         (gnus-summary-prepare))
3372       (when gnus-use-trees
3373         (gnus-tree-open group)
3374         (setq gnus-summary-highlight-line-function
3375               'gnus-tree-highlight-article))
3376       ;; If the summary buffer is empty, but there are some low-scored
3377       ;; articles or some excluded dormants, we include these in the
3378       ;; buffer.
3379       (when (and (zerop (buffer-size))
3380                  (not no-display))
3381         (cond (gnus-newsgroup-dormant
3382                (gnus-summary-limit-include-dormant))
3383               ((and gnus-newsgroup-scored show-all)
3384                (gnus-summary-limit-include-expunged t))))
3385       ;; Function `gnus-apply-kill-file' must be called in this hook.
3386       (gnus-run-hooks 'gnus-apply-kill-hook)
3387       (if (and (zerop (buffer-size))
3388                (not no-display))
3389           (progn
3390             ;; This newsgroup is empty.
3391             (gnus-summary-catchup-and-exit nil t)
3392             (gnus-message 6 "No unread news")
3393             (when kill-buffer
3394               (gnus-kill-or-deaden-summary kill-buffer))
3395             ;; Return nil from this function.
3396             nil)
3397         ;; Hide conversation thread subtrees.  We cannot do this in
3398         ;; gnus-summary-prepare-hook since kill processing may not
3399         ;; work with hidden articles.
3400         (gnus-summary-maybe-hide-threads)
3401         (when kill-buffer
3402           (gnus-kill-or-deaden-summary kill-buffer))
3403         (gnus-summary-auto-select-subject)
3404         ;; Show first unread article if requested.
3405         (if (and (not no-article)
3406                  (not no-display)
3407                  gnus-newsgroup-unreads
3408                  gnus-auto-select-first)
3409             (progn
3410               (gnus-configure-windows 'summary)
3411               (let ((art (gnus-summary-article-number)))
3412                 (unless (or (memq art gnus-newsgroup-undownloaded)
3413                             (memq art gnus-newsgroup-downloadable))
3414                   (gnus-summary-goto-article art))))
3415           ;; Don't select any articles.
3416           (gnus-summary-position-point)
3417           (gnus-configure-windows 'summary 'force)
3418           (gnus-set-mode-line 'summary))
3419         (when (get-buffer-window gnus-group-buffer t)
3420           ;; Gotta use windows, because recenter does weird stuff if
3421           ;; the current buffer ain't the displayed window.
3422           (let ((owin (selected-window)))
3423             (select-window (get-buffer-window gnus-group-buffer t))
3424             (when (gnus-group-goto-group group)
3425               (recenter))
3426             (select-window owin)))
3427         ;; Mark this buffer as "prepared".
3428         (setq gnus-newsgroup-prepared t)
3429         (gnus-run-hooks 'gnus-summary-prepared-hook)
3430         t)))))
3431
3432 (defun gnus-summary-auto-select-subject ()
3433   "Select the subject line on initial group entry."
3434   (goto-char (point-min))
3435   (cond
3436    ((eq gnus-auto-select-subject 'best)
3437     (gnus-summary-best-unread-subject))
3438    ((eq gnus-auto-select-subject 'unread)
3439     (gnus-summary-first-unread-subject))
3440    ((eq gnus-auto-select-subject 'unseen)
3441     (gnus-summary-first-unseen-subject))
3442    ((eq gnus-auto-select-subject 'unseen-or-unread)
3443     (gnus-summary-first-unseen-or-unread-subject))
3444    ((eq gnus-auto-select-subject 'first)
3445     ;; Do nothing.
3446     )
3447    ((gnus-functionp gnus-auto-select-subject)
3448     (funcall gnus-auto-select-subject))))
3449
3450 (defun gnus-summary-prepare ()
3451   "Generate the summary buffer."
3452   (interactive)
3453   (let ((buffer-read-only nil))
3454     (erase-buffer)
3455     (setq gnus-newsgroup-data nil
3456           gnus-newsgroup-data-reverse nil)
3457     (gnus-run-hooks 'gnus-summary-generate-hook)
3458     ;; Generate the buffer, either with threads or without.
3459     (when gnus-newsgroup-headers
3460       (gnus-summary-prepare-threads
3461        (if gnus-show-threads
3462            (gnus-sort-gathered-threads
3463             (funcall gnus-summary-thread-gathering-function
3464                      (gnus-sort-threads
3465                       (gnus-cut-threads (gnus-make-threads)))))
3466          ;; Unthreaded display.
3467          (gnus-sort-articles gnus-newsgroup-headers))))
3468     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3469     ;; Call hooks for modifying summary buffer.
3470     (goto-char (point-min))
3471     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3472
3473 (defsubst gnus-general-simplify-subject (subject)
3474   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3475   (setq subject
3476         (cond
3477          ;; Truncate the subject.
3478          (gnus-simplify-subject-functions
3479           (gnus-map-function gnus-simplify-subject-functions subject))
3480          ((numberp gnus-summary-gather-subject-limit)
3481           (setq subject (gnus-simplify-subject-re subject))
3482           (if (> (length subject) gnus-summary-gather-subject-limit)
3483               (substring subject 0 gnus-summary-gather-subject-limit)
3484             subject))
3485          ;; Fuzzily simplify it.
3486          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3487           (gnus-simplify-subject-fuzzy subject))
3488          ;; Just remove the leading "Re:".
3489          (t
3490           (gnus-simplify-subject-re subject))))
3491
3492   (if (and gnus-summary-gather-exclude-subject
3493            (string-match gnus-summary-gather-exclude-subject subject))
3494       nil                               ; This article shouldn't be gathered
3495     subject))
3496
3497 (defun gnus-summary-simplify-subject-query ()
3498   "Query where the respool algorithm would put this article."
3499   (interactive)
3500   (gnus-summary-select-article)
3501   (message "%s"
3502            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3503
3504 (defun gnus-gather-threads-by-subject (threads)
3505   "Gather threads by looking at Subject headers."
3506   (if (not gnus-summary-make-false-root)
3507       threads
3508     (let ((hashtb (gnus-make-hashtable 1024))
3509           (prev threads)
3510           (result threads)
3511           subject hthread whole-subject)
3512       (while threads
3513         (setq subject (gnus-general-simplify-subject
3514                        (setq whole-subject (mail-header-subject
3515                                             (caar threads)))))
3516         (when subject
3517           (if (setq hthread (gnus-gethash subject hashtb))
3518               (progn
3519                 ;; We enter a dummy root into the thread, if we
3520                 ;; haven't done that already.
3521                 (unless (stringp (caar hthread))
3522                   (setcar hthread (list whole-subject (car hthread))))
3523                 ;; We add this new gathered thread to this gathered
3524                 ;; thread.
3525                 (setcdr (car hthread)
3526                         (nconc (cdar hthread) (list (car threads))))
3527                 ;; Remove it from the list of threads.
3528                 (setcdr prev (cdr threads))
3529                 (setq threads prev))
3530             ;; Enter this thread into the hash table.
3531             (gnus-sethash subject threads hashtb)))
3532         (setq prev threads)
3533         (setq threads (cdr threads)))
3534       result)))
3535
3536 (defun gnus-gather-threads-by-references (threads)
3537   "Gather threads by looking at References headers."
3538   (let ((idhashtb (gnus-make-hashtable 1024))
3539         (thhashtb (gnus-make-hashtable 1024))
3540         (prev threads)
3541         (result threads)
3542         ids references id gthread gid entered ref)
3543     (while threads
3544       (when (setq references (mail-header-references (caar threads)))
3545         (setq id (mail-header-id (caar threads))
3546               ids (inline (gnus-split-references references))
3547               entered nil)
3548         (while (setq ref (pop ids))
3549           (setq ids (delete ref ids))
3550           (if (not (setq gid (gnus-gethash ref idhashtb)))
3551               (progn
3552                 (gnus-sethash ref id idhashtb)
3553                 (gnus-sethash id threads thhashtb))
3554             (setq gthread (gnus-gethash gid thhashtb))
3555             (unless entered
3556               ;; We enter a dummy root into the thread, if we
3557               ;; haven't done that already.
3558               (unless (stringp (caar gthread))
3559                 (setcar gthread (list (mail-header-subject (caar gthread))
3560                                       (car gthread))))
3561               ;; We add this new gathered thread to this gathered
3562               ;; thread.
3563               (setcdr (car gthread)
3564                       (nconc (cdar gthread) (list (car threads)))))
3565             ;; Add it into the thread hash table.
3566             (gnus-sethash id gthread thhashtb)
3567             (setq entered t)
3568             ;; Remove it from the list of threads.
3569             (setcdr prev (cdr threads))
3570             (setq threads prev))))
3571       (setq prev threads)
3572       (setq threads (cdr threads)))
3573     result))
3574
3575 (defun gnus-sort-gathered-threads (threads)
3576   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3577   (let ((result threads))
3578     (while threads
3579       (when (stringp (caar threads))
3580         (setcdr (car threads)
3581                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3582       (setq threads (cdr threads)))
3583     result))
3584
3585 (defun gnus-thread-loop-p (root thread)
3586   "Say whether ROOT is in THREAD."
3587   (let ((stack (list thread))
3588         (infloop 0)
3589         th)
3590     (while (setq thread (pop stack))
3591       (setq th (cdr thread))
3592       (while (and th
3593                   (not (eq (caar th) root)))
3594         (pop th))
3595       (if th
3596           ;; We have found a loop.
3597           (let (ref-dep)
3598             (setcdr thread (delq (car th) (cdr thread)))
3599             (if (boundp (setq ref-dep (intern "none"
3600                                               gnus-newsgroup-dependencies)))
3601                 (setcdr (symbol-value ref-dep)
3602                         (nconc (cdr (symbol-value ref-dep))
3603                                (list (car th))))
3604               (set ref-dep (list nil (car th))))
3605             (setq infloop 1
3606                   stack nil))
3607         ;; Push all the subthreads onto the stack.
3608         (push (cdr thread) stack)))
3609     infloop))
3610
3611 (defun gnus-make-threads ()
3612   "Go through the dependency hashtb and find the roots.  Return all threads."
3613   (let (threads)
3614     (while (catch 'infloop
3615              (mapatoms
3616               (lambda (refs)
3617                 ;; Deal with self-referencing References loops.
3618                 (when (and (car (symbol-value refs))
3619                            (not (zerop
3620                                  (apply
3621                                   '+
3622                                   (mapcar
3623                                    (lambda (thread)
3624                                      (gnus-thread-loop-p
3625                                       (car (symbol-value refs)) thread))
3626                                    (cdr (symbol-value refs)))))))
3627                   (setq threads nil)
3628                   (throw 'infloop t))
3629                 (unless (car (symbol-value refs))
3630                   ;; These threads do not refer back to any other articles,
3631                   ;; so they're roots.
3632                   (setq threads (append (cdr (symbol-value refs)) threads))))
3633               gnus-newsgroup-dependencies)))
3634     threads))
3635
3636 ;; Build the thread tree.
3637 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3638   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3639
3640 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3641 if it was already present.
3642
3643 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3644 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3645 Message-IDs will be renamed to a unique Message-ID before being
3646 entered.
3647
3648 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3649   (let* ((id (mail-header-id header))
3650          (id-dep (and id (intern id dependencies)))
3651          ref ref-dep ref-header replaced)
3652     ;; Enter this `header' in the `dependencies' table.
3653     (cond
3654      ((not id-dep)
3655       (setq header nil))
3656      ;; The first two cases do the normal part: enter a new `header'
3657      ;; in the `dependencies' table.
3658      ((not (boundp id-dep))
3659       (set id-dep (list header)))
3660      ((null (car (symbol-value id-dep)))
3661       (setcar (symbol-value id-dep) header))
3662
3663      ;; From here the `header' was already present in the
3664      ;; `dependencies' table.
3665      (force-new
3666       ;; Overrides an existing entry;
3667       ;; just set the header part of the entry.
3668       (setcar (symbol-value id-dep) header)
3669       (setq replaced t))
3670
3671      ;; Renames the existing `header' to a unique Message-ID.
3672      ((not gnus-summary-ignore-duplicates)
3673       ;; An article with this Message-ID has already been seen.
3674       ;; We rename the Message-ID.
3675       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3676            (list header))
3677       (mail-header-set-id header id))
3678
3679      ;; The last case ignores an existing entry, except it adds any
3680      ;; additional Xrefs (in case the two articles came from different
3681      ;; servers.
3682      ;; Also sets `header' to `nil' meaning that the `dependencies'
3683      ;; table was *not* modified.
3684      (t
3685       (mail-header-set-xref
3686        (car (symbol-value id-dep))
3687        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3688                    "")
3689                (or (mail-header-xref header) "")))
3690       (setq header nil)))
3691
3692     (when (and header (not replaced))
3693       ;; First check that we are not creating a References loop.
3694       (setq ref (gnus-parent-id (mail-header-references header)))
3695       (while (and ref
3696                   (setq ref-dep (intern-soft ref dependencies))
3697                   (boundp ref-dep)
3698                   (setq ref-header (car (symbol-value ref-dep))))
3699         (if (string= id ref)
3700             ;; Yuk!  This is a reference loop.  Make the article be a
3701             ;; root article.
3702             (progn
3703               (mail-header-set-references (car (symbol-value id-dep)) "none")
3704               (setq ref nil))
3705           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3706       (setq ref (gnus-parent-id (mail-header-references header)))
3707       (setq ref-dep (intern (or ref "none") dependencies))
3708       (if (boundp ref-dep)
3709           (setcdr (symbol-value ref-dep)
3710                   (nconc (cdr (symbol-value ref-dep))
3711                          (list (symbol-value id-dep))))
3712         (set ref-dep (list nil (symbol-value id-dep)))))
3713     header))
3714
3715 (defun gnus-extract-message-id-from-in-reply-to (string)
3716   (if (string-match "<[^>]+>" string)
3717       (substring string (match-beginning 0) (match-end 0))
3718     nil))
3719
3720 (defun gnus-build-sparse-threads ()
3721   (let ((headers gnus-newsgroup-headers)
3722         (mail-parse-charset gnus-newsgroup-charset)
3723         (gnus-summary-ignore-duplicates t)
3724         header references generation relations
3725         subject child end new-child date)
3726     ;; First we create an alist of generations/relations, where
3727     ;; generations is how much we trust the relation, and the relation
3728     ;; is parent/child.
3729     (gnus-message 7 "Making sparse threads...")
3730     (save-excursion
3731       (nnheader-set-temp-buffer " *gnus sparse threads*")
3732       (while (setq header (pop headers))
3733         (when (and (setq references (mail-header-references header))
3734                    (not (string= references "")))
3735           (insert references)
3736           (setq child (mail-header-id header)
3737                 subject (mail-header-subject header)
3738                 date (mail-header-date header)
3739                 generation 0)
3740           (while (search-backward ">" nil t)
3741             (setq end (1+ (point)))
3742             (when (search-backward "<" nil t)
3743               (setq new-child (buffer-substring (point) end))
3744               (push (list (incf generation)
3745                           child (setq child new-child)
3746                           subject date)
3747                     relations)))
3748           (when child
3749             (push (list (1+ generation) child nil subject) relations))
3750           (erase-buffer)))
3751       (kill-buffer (current-buffer)))
3752     ;; Sort over trustworthiness.
3753     (mapcar
3754      (lambda (relation)
3755        (when (gnus-dependencies-add-header
3756               (make-full-mail-header-from-decoded-header
3757                gnus-reffed-article-number
3758                (nth 3 relation) "" (or (nth 4 relation) "")
3759                (nth 1 relation)
3760                (or (nth 2 relation) "") 0 0 "")
3761               gnus-newsgroup-dependencies nil)
3762          (push gnus-reffed-article-number gnus-newsgroup-limit)
3763          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3764          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3765                gnus-newsgroup-reads)
3766          (decf gnus-reffed-article-number)))
3767      (sort relations 'car-less-than-car))
3768     (gnus-message 7 "Making sparse threads...done")))
3769
3770 (defun gnus-build-old-threads ()
3771   ;; Look at all the articles that refer back to old articles, and
3772   ;; fetch the headers for the articles that aren't there.  This will
3773   ;; build complete threads - if the roots haven't been expired by the
3774   ;; server, that is.
3775   (let ((mail-parse-charset gnus-newsgroup-charset)
3776         id heads)
3777     (mapatoms
3778      (lambda (refs)
3779        (when (not (car (symbol-value refs)))
3780          (setq heads (cdr (symbol-value refs)))
3781          (while heads
3782            (if (memq (mail-header-number (caar heads))
3783                      gnus-newsgroup-dormant)
3784                (setq heads (cdr heads))
3785              (setq id (symbol-name refs))
3786              (while (and (setq id (gnus-build-get-header id))
3787                          (not (car (gnus-id-to-thread id)))))
3788              (setq heads nil)))))
3789      gnus-newsgroup-dependencies)))
3790
3791 ;; This function has to be called with point after the article number
3792 ;; on the beginning of the line.
3793 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3794   (let ((eol (gnus-point-at-eol))
3795         (buffer (current-buffer))
3796         header references in-reply-to)
3797
3798     ;; overview: [num subject from date id refs chars lines misc]
3799     (unwind-protect
3800         (progn
3801           (narrow-to-region (point) eol)
3802           (unless (eobp)
3803             (forward-char))
3804
3805           (setq header
3806                 (make-full-mail-header
3807                  number                         ; number
3808                  (nnheader-nov-field)           ; subject
3809                  (nnheader-nov-field)           ; from
3810                  (nnheader-nov-field)           ; date
3811                  (nnheader-nov-read-message-id) ; id
3812                  (nnheader-nov-field)           ; refs
3813                  (nnheader-nov-read-integer)    ; chars
3814                  (nnheader-nov-read-integer)    ; lines
3815                  (unless (eobp)
3816                    (if (looking-at "Xref: ")
3817                        (goto-char (match-end 0)))
3818                    (nnheader-nov-field))        ; Xref
3819                  (nnheader-nov-parse-extra))))  ; extra
3820
3821       (widen))
3822
3823     (when (and (string= references "")
3824                (setq in-reply-to (mail-header-extra header))
3825                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3826       (mail-header-set-references
3827        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3828
3829     (when gnus-alter-header-function
3830       (funcall gnus-alter-header-function header))
3831     (gnus-dependencies-add-header header dependencies force-new)))
3832
3833 (defun gnus-build-get-header (id)
3834   "Look through the buffer of NOV lines and find the header to ID.
3835 Enter this line into the dependencies hash table, and return
3836 the id of the parent article (if any)."
3837   (let ((deps gnus-newsgroup-dependencies)
3838         found header)
3839     (prog1
3840         (save-excursion
3841           (set-buffer nntp-server-buffer)
3842           (let ((case-fold-search nil))
3843             (goto-char (point-min))
3844             (while (and (not found)
3845                         (search-forward id nil t))
3846               (beginning-of-line)
3847               (setq found (looking-at
3848                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3849                                    (regexp-quote id))))
3850               (or found (beginning-of-line 2)))
3851             (when found
3852               (beginning-of-line)
3853               (and
3854                (setq header (gnus-nov-parse-line
3855                              (read (current-buffer)) deps))
3856                (gnus-parent-id (mail-header-references header))))))
3857       (when header
3858         (let ((number (mail-header-number header)))
3859           (push number gnus-newsgroup-limit)
3860           (push header gnus-newsgroup-headers)
3861           (if (memq number gnus-newsgroup-unselected)
3862               (progn
3863                 (setq gnus-newsgroup-unreads
3864                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3865                                                number))
3866                 (setq gnus-newsgroup-unselected
3867                       (delq number gnus-newsgroup-unselected)))
3868             (push number gnus-newsgroup-ancient)))))))
3869
3870 (defun gnus-build-all-threads ()
3871   "Read all the headers."
3872   (let ((gnus-summary-ignore-duplicates t)
3873         (mail-parse-charset gnus-newsgroup-charset)
3874         (dependencies gnus-newsgroup-dependencies)
3875         header article)
3876     (save-excursion
3877       (set-buffer nntp-server-buffer)
3878       (let ((case-fold-search nil))
3879         (goto-char (point-min))
3880         (while (not (eobp))
3881           (ignore-errors
3882             (setq article (read (current-buffer))
3883                   header (gnus-nov-parse-line article dependencies)))
3884           (when header
3885             (save-excursion
3886               (set-buffer gnus-summary-buffer)
3887               (push header gnus-newsgroup-headers)
3888               (if (memq (setq article (mail-header-number header))
3889                         gnus-newsgroup-unselected)
3890                   (progn
3891                     (setq gnus-newsgroup-unreads
3892                           (gnus-add-to-sorted-list
3893                            gnus-newsgroup-unreads article))
3894                     (setq gnus-newsgroup-unselected
3895                           (delq article gnus-newsgroup-unselected)))
3896                 (push article gnus-newsgroup-ancient)))
3897             (forward-line 1)))))))
3898
3899 (defun gnus-summary-update-article-line (article header)
3900   "Update the line for ARTICLE using HEADERS."
3901   (let* ((id (mail-header-id header))
3902          (thread (gnus-id-to-thread id)))
3903     (unless thread
3904       (error "Article in no thread"))
3905     ;; Update the thread.
3906     (setcar thread header)
3907     (gnus-summary-goto-subject article)
3908     (let* ((datal (gnus-data-find-list article))
3909            (data (car datal))
3910            (length (when (cdr datal)
3911                      (- (gnus-data-pos data)
3912                         (gnus-data-pos (cadr datal)))))
3913            (buffer-read-only nil)
3914            (level (gnus-summary-thread-level)))
3915       (gnus-delete-line)
3916       (gnus-summary-insert-line
3917        header level nil (gnus-article-mark article)
3918        (memq article gnus-newsgroup-replied)
3919        (memq article gnus-newsgroup-expirable)
3920        ;; Only insert the Subject string when it's different
3921        ;; from the previous Subject string.
3922        (if (and
3923             gnus-show-threads
3924             (gnus-subject-equal
3925              (condition-case ()
3926                  (mail-header-subject
3927                   (gnus-data-header
3928                    (cadr
3929                     (gnus-data-find-list
3930                      article
3931                      (gnus-data-list t)))))
3932                ;; Error on the side of excessive subjects.
3933                (error ""))
3934              (mail-header-subject header)))
3935            ""
3936          (mail-header-subject header))
3937        nil (cdr (assq article gnus-newsgroup-scored))
3938        (memq article gnus-newsgroup-processable))
3939       (when length
3940         (gnus-data-update-list
3941          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3942
3943 (defun gnus-summary-update-article (article &optional iheader)
3944   "Update ARTICLE in the summary buffer."
3945   (set-buffer gnus-summary-buffer)
3946   (let* ((header (gnus-summary-article-header article))
3947          (id (mail-header-id header))
3948          (data (gnus-data-find article))
3949          (thread (gnus-id-to-thread id))
3950          (references (mail-header-references header))
3951          (parent
3952           (gnus-id-to-thread
3953            (or (gnus-parent-id
3954                 (when (and references
3955                            (not (equal "" references)))
3956                   references))
3957                "none")))
3958          (buffer-read-only nil)
3959          (old (car thread)))
3960     (when thread
3961       (unless iheader
3962         (setcar thread nil)
3963         (when parent
3964           (delq thread parent)))
3965       (if (gnus-summary-insert-subject id header)
3966           ;; Set the (possibly) new article number in the data structure.
3967           (gnus-data-set-number data (gnus-id-to-article id))
3968         (setcar thread old)
3969         nil))))
3970
3971 (defun gnus-rebuild-thread (id &optional line)
3972   "Rebuild the thread containing ID.
3973 If LINE, insert the rebuilt thread starting on line LINE."
3974   (let ((buffer-read-only nil)
3975         old-pos current thread data)
3976     (if (not gnus-show-threads)
3977         (setq thread (list (car (gnus-id-to-thread id))))
3978       ;; Get the thread this article is part of.
3979       (setq thread (gnus-remove-thread id)))
3980     (setq old-pos (gnus-point-at-bol))
3981     (setq current (save-excursion
3982                     (and (re-search-backward "[\r\n]" nil t)
3983                          (gnus-summary-article-number))))
3984     ;; If this is a gathered thread, we have to go some re-gathering.
3985     (when (stringp (car thread))
3986       (let ((subject (car thread))
3987             roots thr)
3988         (setq thread (cdr thread))
3989         (while thread
3990           (unless (memq (setq thr (gnus-id-to-thread
3991                                    (gnus-root-id
3992                                     (mail-header-id (caar thread)))))
3993                         roots)
3994             (push thr roots))
3995           (setq thread (cdr thread)))
3996         ;; We now have all (unique) roots.
3997         (if (= (length roots) 1)
3998             ;; All the loose roots are now one solid root.
3999             (setq thread (car roots))
4000           (setq thread (cons subject (gnus-sort-threads roots))))))
4001     (let (threads)
4002       ;; We then insert this thread into the summary buffer.
4003       (when line
4004         (goto-char (point-min))
4005         (forward-line (1- line)))
4006       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4007         (if gnus-show-threads
4008             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4009           (gnus-summary-prepare-unthreaded thread))
4010         (setq data (nreverse gnus-newsgroup-data))
4011         (setq threads gnus-newsgroup-threads))
4012       ;; We splice the new data into the data structure.
4013       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4014       ;;!!! then we want to insert at the beginning of the buffer.
4015       ;;!!! That happens to be true with Gnus now, but that may
4016       ;;!!! change in the future.  Perhaps.
4017       (gnus-data-enter-list
4018        (if line nil current) data (- (point) old-pos))
4019       (setq gnus-newsgroup-threads
4020             (nconc threads gnus-newsgroup-threads))
4021       (gnus-data-compute-positions))))
4022
4023 (defun gnus-number-to-header (number)
4024   "Return the header for article NUMBER."
4025   (let ((headers gnus-newsgroup-headers))
4026     (while (and headers
4027                 (not (= number (mail-header-number (car headers)))))
4028       (pop headers))
4029     (when headers
4030       (car headers))))
4031
4032 (defun gnus-parent-headers (in-headers &optional generation)
4033   "Return the headers of the GENERATIONeth parent of HEADERS."
4034   (unless generation
4035     (setq generation 1))
4036   (let ((parent t)
4037         (headers in-headers)
4038         references)
4039     (while (and parent
4040                 (not (zerop generation))
4041                 (setq references (mail-header-references headers)))
4042       (setq headers (if (and references
4043                              (setq parent (gnus-parent-id references)))
4044                         (car (gnus-id-to-thread parent))
4045                       nil))
4046       (decf generation))
4047     (and (not (eq headers in-headers))
4048          headers)))
4049
4050 (defun gnus-id-to-thread (id)
4051   "Return the (sub-)thread where ID appears."
4052   (gnus-gethash id gnus-newsgroup-dependencies))
4053
4054 (defun gnus-id-to-article (id)
4055   "Return the article number of ID."
4056   (let ((thread (gnus-id-to-thread id)))
4057     (when (and thread
4058                (car thread))
4059       (mail-header-number (car thread)))))
4060
4061 (defun gnus-id-to-header (id)
4062   "Return the article headers of ID."
4063   (car (gnus-id-to-thread id)))
4064
4065 (defun gnus-article-displayed-root-p (article)
4066   "Say whether ARTICLE is a root(ish) article."
4067   (let ((level (gnus-summary-thread-level article))
4068         (refs (mail-header-references  (gnus-summary-article-header article)))
4069         particle)
4070     (cond
4071      ((null level) nil)
4072      ((zerop level) t)
4073      ((null refs) t)
4074      ((null (gnus-parent-id refs)) t)
4075      ((and (= 1 level)
4076            (null (setq particle (gnus-id-to-article
4077                                  (gnus-parent-id refs))))
4078            (null (gnus-summary-thread-level particle)))))))
4079
4080 (defun gnus-root-id (id)
4081   "Return the id of the root of the thread where ID appears."
4082   (let (last-id prev)
4083     (while (and id (setq prev (car (gnus-id-to-thread id))))
4084       (setq last-id id
4085             id (gnus-parent-id (mail-header-references prev))))
4086     last-id))
4087
4088 (defun gnus-articles-in-thread (thread)
4089   "Return the list of articles in THREAD."
4090   (cons (mail-header-number (car thread))
4091         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4092
4093 (defun gnus-remove-thread (id &optional dont-remove)
4094   "Remove the thread that has ID in it."
4095   (let (headers thread last-id)
4096     ;; First go up in this thread until we find the root.
4097     (setq last-id (gnus-root-id id)
4098           headers (message-flatten-list (gnus-id-to-thread last-id)))
4099     ;; We have now found the real root of this thread.  It might have
4100     ;; been gathered into some loose thread, so we have to search
4101     ;; through the threads to find the thread we wanted.
4102     (let ((threads gnus-newsgroup-threads)
4103           sub)
4104       (while threads
4105         (setq sub (car threads))
4106         (if (stringp (car sub))
4107             ;; This is a gathered thread, so we look at the roots
4108             ;; below it to find whether this article is in this
4109             ;; gathered root.
4110             (progn
4111               (setq sub (cdr sub))
4112               (while sub
4113                 (when (member (caar sub) headers)
4114                   (setq thread (car threads)
4115                         threads nil
4116                         sub nil))
4117                 (setq sub (cdr sub))))
4118           ;; It's an ordinary thread, so we check it.
4119           (when (eq (car sub) (car headers))
4120             (setq thread sub
4121                   threads nil)))
4122         (setq threads (cdr threads)))
4123       ;; If this article is in no thread, then it's a root.
4124       (if thread
4125           (unless dont-remove
4126             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4127         (setq thread (gnus-id-to-thread last-id)))
4128       (when thread
4129         (prog1
4130             thread                      ; We return this thread.
4131           (unless dont-remove
4132             (if (stringp (car thread))
4133                 (progn
4134                   ;; If we use dummy roots, then we have to remove the
4135                   ;; dummy root as well.
4136                   (when (eq gnus-summary-make-false-root 'dummy)
4137                     ;; We go to the dummy root by going to
4138                     ;; the first sub-"thread", and then one line up.
4139                     (gnus-summary-goto-article
4140                      (mail-header-number (caadr thread)))
4141                     (forward-line -1)
4142                     (gnus-delete-line)
4143                     (gnus-data-compute-positions))
4144                   (setq thread (cdr thread))
4145                   (while thread
4146                     (gnus-remove-thread-1 (car thread))
4147                     (setq thread (cdr thread))))
4148               (gnus-remove-thread-1 thread))))))))
4149
4150 (defun gnus-remove-thread-1 (thread)
4151   "Remove the thread THREAD recursively."
4152   (let ((number (mail-header-number (pop thread)))
4153         d)
4154     (setq thread (reverse thread))
4155     (while thread
4156       (gnus-remove-thread-1 (pop thread)))
4157     (when (setq d (gnus-data-find number))
4158       (goto-char (gnus-data-pos d))
4159       (gnus-summary-show-thread)
4160       (gnus-data-remove
4161        number
4162        (- (gnus-point-at-bol)
4163           (prog1
4164               (1+ (gnus-point-at-eol))
4165             (gnus-delete-line)))))))
4166
4167 (defun gnus-sort-threads-1 (threads func)
4168   (sort (mapcar (lambda (thread)
4169                   (cons (car thread)
4170                         (and (cdr thread)
4171                              (gnus-sort-threads-1 (cdr thread) func))))
4172                 threads) func))
4173
4174 (defun gnus-sort-threads (threads)
4175   "Sort THREADS."
4176   (if (not gnus-thread-sort-functions)
4177       threads
4178     (gnus-message 8 "Sorting threads...")
4179     (prog1
4180         (gnus-sort-threads-1
4181          threads
4182          (gnus-make-sort-function gnus-thread-sort-functions))
4183       (gnus-message 8 "Sorting threads...done"))))
4184
4185 (defun gnus-sort-articles (articles)
4186   "Sort ARTICLES."
4187   (when gnus-article-sort-functions
4188     (gnus-message 7 "Sorting articles...")
4189     (prog1
4190         (setq gnus-newsgroup-headers
4191               (sort articles (gnus-make-sort-function
4192                               gnus-article-sort-functions)))
4193       (gnus-message 7 "Sorting articles...done"))))
4194
4195 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4196 (defmacro gnus-thread-header (thread)
4197   "Return header of first article in THREAD.
4198 Note that THREAD must never, ever be anything else than a variable -
4199 using some other form will lead to serious barfage."
4200   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4201   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4202   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4203         (vector thread) 2))
4204
4205 (defsubst gnus-article-sort-by-number (h1 h2)
4206   "Sort articles by article number."
4207   (< (mail-header-number h1)
4208      (mail-header-number h2)))
4209
4210 (defun gnus-thread-sort-by-number (h1 h2)
4211   "Sort threads by root article number."
4212   (gnus-article-sort-by-number
4213    (gnus-thread-header h1) (gnus-thread-header h2)))
4214
4215 (defsubst gnus-article-sort-by-lines (h1 h2)
4216   "Sort articles by article Lines header."
4217   (< (mail-header-lines h1)
4218      (mail-header-lines h2)))
4219
4220 (defun gnus-thread-sort-by-lines (h1 h2)
4221   "Sort threads by root article Lines header."
4222   (gnus-article-sort-by-lines
4223    (gnus-thread-header h1) (gnus-thread-header h2)))
4224
4225 (defsubst gnus-article-sort-by-chars (h1 h2)
4226   "Sort articles by octet length."
4227   (< (mail-header-chars h1)
4228      (mail-header-chars h2)))
4229
4230 (defun gnus-thread-sort-by-chars (h1 h2)
4231   "Sort threads by root article octet length."
4232   (gnus-article-sort-by-chars
4233    (gnus-thread-header h1) (gnus-thread-header h2)))
4234
4235 (defsubst gnus-article-sort-by-author (h1 h2)
4236   "Sort articles by root author."
4237   (string-lessp
4238    (let ((addr (car (mime-entity-read-field h1 'From))))
4239      (or (std11-full-name-string addr)
4240          (std11-address-string addr)
4241          ""))
4242    (let ((addr (car (mime-entity-read-field h2 'From))))
4243      (or (std11-full-name-string addr)
4244          (std11-address-string addr)
4245          ""))
4246    ))
4247
4248 (defun gnus-thread-sort-by-author (h1 h2)
4249   "Sort threads by root author."
4250   (gnus-article-sort-by-author
4251    (gnus-thread-header h1)  (gnus-thread-header h2)))
4252
4253 (defsubst gnus-article-sort-by-subject (h1 h2)
4254   "Sort articles by root subject."
4255   (string-lessp
4256    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4257    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4258
4259 (defun gnus-thread-sort-by-subject (h1 h2)
4260   "Sort threads by root subject."
4261   (gnus-article-sort-by-subject
4262    (gnus-thread-header h1) (gnus-thread-header h2)))
4263
4264 (defsubst gnus-article-sort-by-date (h1 h2)
4265   "Sort articles by root article date."
4266   (time-less-p
4267    (gnus-date-get-time (mail-header-date h1))
4268    (gnus-date-get-time (mail-header-date h2))))
4269
4270 (defun gnus-thread-sort-by-date (h1 h2)
4271   "Sort threads by root article date."
4272   (gnus-article-sort-by-date
4273    (gnus-thread-header h1) (gnus-thread-header h2)))
4274
4275 (defsubst gnus-article-sort-by-score (h1 h2)
4276   "Sort articles by root article score.
4277 Unscored articles will be counted as having a score of zero."
4278   (> (or (cdr (assq (mail-header-number h1)
4279                     gnus-newsgroup-scored))
4280          gnus-summary-default-score 0)
4281      (or (cdr (assq (mail-header-number h2)
4282                     gnus-newsgroup-scored))
4283          gnus-summary-default-score 0)))
4284
4285 (defun gnus-thread-sort-by-score (h1 h2)
4286   "Sort threads by root article score."
4287   (gnus-article-sort-by-score
4288    (gnus-thread-header h1) (gnus-thread-header h2)))
4289
4290 (defun gnus-thread-sort-by-total-score (h1 h2)
4291   "Sort threads by the sum of all scores in the thread.
4292 Unscored articles will be counted as having a score of zero."
4293   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4294
4295 (defun gnus-thread-total-score (thread)
4296   ;; This function find the total score of THREAD.
4297   (cond
4298    ((null thread)
4299     0)
4300    ((consp thread)
4301     (if (stringp (car thread))
4302         (apply gnus-thread-score-function 0
4303                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4304       (gnus-thread-total-score-1 thread)))
4305    (t
4306     (gnus-thread-total-score-1 (list thread)))))
4307
4308 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4309   "Sort threads such that the thread with the most recently arrived article comes first."
4310   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4311
4312 (defun gnus-thread-highest-number (thread)
4313   "Return the highest article number in THREAD."
4314   (apply 'max (mapcar (lambda (header)
4315                         (mail-header-number header))
4316                       (message-flatten-list thread))))
4317
4318 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4319   "Sort threads such that the thread with the most recently dated article comes first."
4320   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4321
4322 (defun gnus-thread-latest-date (thread)
4323   "Return the highest article date in THREAD."
4324   (let ((previous-time 0))
4325     (apply 'max (mapcar
4326                  (lambda (header)
4327                    (setq previous-time
4328                          (time-to-seconds
4329                           (mail-header-parse-date
4330                            (condition-case ()
4331                                (mail-header-date header)
4332                              (error previous-time))))))
4333                  (sort
4334                   (message-flatten-list thread)
4335                   (lambda (h1 h2)
4336                     (< (mail-header-number h1)
4337                        (mail-header-number h2))))))))
4338
4339 (defun gnus-thread-total-score-1 (root)
4340   ;; This function find the total score of the thread below ROOT.
4341   (setq root (car root))
4342   (apply gnus-thread-score-function
4343          (or (append
4344               (mapcar 'gnus-thread-total-score
4345                       (cdr (gnus-id-to-thread (mail-header-id root))))
4346               (when (> (mail-header-number root) 0)
4347                 (list (or (cdr (assq (mail-header-number root)
4348                                      gnus-newsgroup-scored))
4349                           gnus-summary-default-score 0))))
4350              (list gnus-summary-default-score)
4351              '(0))))
4352
4353 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4354 (defvar gnus-tmp-prev-subject nil)
4355 (defvar gnus-tmp-false-parent nil)
4356 (defvar gnus-tmp-root-expunged nil)
4357 (defvar gnus-tmp-dummy-line nil)
4358
4359 (eval-when-compile (defvar gnus-tmp-header))
4360 (defun gnus-extra-header (type &optional header)
4361   "Return the extra header of TYPE."
4362   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4363       ""))
4364
4365 (defvar gnus-tmp-thread-tree-header-string "")
4366
4367 (defcustom gnus-sum-thread-tree-root "> "
4368   "With %B spec, used for the root of a thread.
4369 If nil, use subject instead."
4370   :type 'string
4371   :group 'gnus-thread)
4372 (defcustom gnus-sum-thread-tree-single-indent ""
4373   "With %B spec, used for a thread with just one message.
4374 If nil, use subject instead."
4375   :type 'string
4376   :group 'gnus-thread)
4377 (defcustom gnus-sum-thread-tree-vertical "| "
4378   "With %B spec, used for drawing a vertical line."
4379   :type 'string
4380   :group 'gnus-thread)
4381 (defcustom gnus-sum-thread-tree-indent "  "
4382   "With %B spec, used for indenting."
4383   :type 'string
4384   :group 'gnus-thread)
4385 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4386   "With %B spec, used for a leaf with brothers."
4387   :type 'string
4388   :group 'gnus-thread)
4389 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4390   "With %B spec, used for a leaf without brothers."
4391   :type 'string
4392   :group 'gnus-thread)
4393
4394 (defun gnus-summary-prepare-threads (threads)
4395   "Prepare summary buffer from THREADS and indentation LEVEL.
4396 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4397 or a straight list of headers."
4398   (gnus-message 7 "Generating summary...")
4399
4400   (setq gnus-newsgroup-threads threads)
4401   (beginning-of-line)
4402
4403   (let ((gnus-tmp-level 0)
4404         (default-score (or gnus-summary-default-score 0))
4405         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4406         thread number subject stack state gnus-tmp-gathered beg-match
4407         new-roots gnus-tmp-new-adopts thread-end
4408         gnus-tmp-header gnus-tmp-unread
4409         gnus-tmp-replied gnus-tmp-subject-or-nil
4410         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4411         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4412         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4413         tree-stack)
4414
4415     (setq gnus-tmp-prev-subject nil)
4416
4417     (if (vectorp (car threads))
4418         ;; If this is a straight (sic) list of headers, then a
4419         ;; threaded summary display isn't required, so we just create
4420         ;; an unthreaded one.
4421         (gnus-summary-prepare-unthreaded threads)
4422
4423       ;; Do the threaded display.
4424
4425       (while (or threads stack gnus-tmp-new-adopts new-roots)
4426
4427         (if (and (= gnus-tmp-level 0)
4428                  (or (not stack)
4429                      (= (caar stack) 0))
4430                  (not gnus-tmp-false-parent)
4431                  (or gnus-tmp-new-adopts new-roots))
4432             (if gnus-tmp-new-adopts
4433                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4434                       thread (list (car gnus-tmp-new-adopts))
4435                       gnus-tmp-header (caar thread)
4436                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4437               (when new-roots
4438                 (setq thread (list (car new-roots))
4439                       gnus-tmp-header (caar thread)
4440                       new-roots (cdr new-roots))))
4441
4442           (if threads
4443               ;; If there are some threads, we do them before the
4444               ;; threads on the stack.
4445               (setq thread threads
4446                     gnus-tmp-header (caar thread))
4447             ;; There were no current threads, so we pop something off
4448             ;; the stack.
4449             (setq state (car stack)
4450                   gnus-tmp-level (car state)
4451                   tree-stack (cadr state)
4452                   thread (caddr state)
4453                   stack (cdr stack)
4454                   gnus-tmp-header (caar thread))))
4455
4456         (setq gnus-tmp-false-parent nil)
4457         (setq gnus-tmp-root-expunged nil)
4458         (setq thread-end nil)
4459
4460         (if (stringp gnus-tmp-header)
4461             ;; The header is a dummy root.
4462             (cond
4463              ((eq gnus-summary-make-false-root 'adopt)
4464               ;; We let the first article adopt the rest.
4465               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4466                                                (cddar thread)))
4467               (setq gnus-tmp-gathered
4468                     (nconc (mapcar
4469                             (lambda (h) (mail-header-number (car h)))
4470                             (cddar thread))
4471                            gnus-tmp-gathered))
4472               (setq thread (cons (list (caar thread)
4473                                        (cadar thread))
4474                                  (cdr thread)))
4475               (setq gnus-tmp-level -1
4476                     gnus-tmp-false-parent t))
4477              ((eq gnus-summary-make-false-root 'empty)
4478               ;; We print adopted articles with empty subject fields.
4479               (setq gnus-tmp-gathered
4480                     (nconc (mapcar
4481                             (lambda (h) (mail-header-number (car h)))
4482                             (cddar thread))
4483                            gnus-tmp-gathered))
4484               (setq gnus-tmp-level -1))
4485              ((eq gnus-summary-make-false-root 'dummy)
4486               ;; We remember that we probably want to output a dummy
4487               ;; root.
4488               (setq gnus-tmp-dummy-line gnus-tmp-header)
4489               (setq gnus-tmp-prev-subject gnus-tmp-header))
4490              (t
4491               ;; We do not make a root for the gathered
4492               ;; sub-threads at all.
4493               (setq gnus-tmp-level -1)))
4494
4495           (setq number (mail-header-number gnus-tmp-header)
4496                 subject (mail-header-subject gnus-tmp-header))
4497
4498           (cond
4499            ;; If the thread has changed subject, we might want to make
4500            ;; this subthread into a root.
4501            ((and (null gnus-thread-ignore-subject)
4502                  (not (zerop gnus-tmp-level))
4503                  gnus-tmp-prev-subject
4504                  (not (inline
4505                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4506             (setq new-roots (nconc new-roots (list (car thread)))
4507                   thread-end t
4508                   gnus-tmp-header nil))
4509            ;; If the article lies outside the current limit,
4510            ;; then we do not display it.
4511            ((not (memq number gnus-newsgroup-limit))
4512             (setq gnus-tmp-gathered
4513                   (nconc (mapcar
4514                           (lambda (h) (mail-header-number (car h)))
4515                           (cdar thread))
4516                          gnus-tmp-gathered))
4517             (setq gnus-tmp-new-adopts (if (cdar thread)
4518                                           (append gnus-tmp-new-adopts
4519                                                   (cdar thread))
4520                                         gnus-tmp-new-adopts)
4521                   thread-end t
4522                   gnus-tmp-header nil)
4523             (when (zerop gnus-tmp-level)
4524               (setq gnus-tmp-root-expunged t)))
4525            ;; Perhaps this article is to be marked as read?
4526            ((and gnus-summary-mark-below
4527                  (< (or (cdr (assq number gnus-newsgroup-scored))
4528                         default-score)
4529                     gnus-summary-mark-below)
4530                  ;; Don't touch sparse articles.
4531                  (not (gnus-summary-article-sparse-p number))
4532                  (not (gnus-summary-article-ancient-p number)))
4533             (setq gnus-newsgroup-unreads
4534                   (delq number gnus-newsgroup-unreads))
4535             (if gnus-newsgroup-auto-expire
4536                 (setq gnus-newsgroup-expirable
4537                       (gnus-add-to-sorted-list
4538                        gnus-newsgroup-expirable number))
4539               (push (cons number gnus-low-score-mark)
4540                     gnus-newsgroup-reads))))
4541
4542           (when gnus-tmp-header
4543             ;; We may have an old dummy line to output before this
4544             ;; article.
4545             (when (and gnus-tmp-dummy-line
4546                        (gnus-subject-equal
4547                         gnus-tmp-dummy-line
4548                         (mail-header-subject gnus-tmp-header)))
4549               (gnus-summary-insert-dummy-line
4550                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4551               (setq gnus-tmp-dummy-line nil))
4552
4553             ;; Compute the mark.
4554             (setq gnus-tmp-unread (gnus-article-mark number))
4555
4556             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4557                                   gnus-tmp-header gnus-tmp-level)
4558                   gnus-newsgroup-data)
4559
4560             ;; Actually insert the line.
4561             (setq
4562              gnus-tmp-subject-or-nil
4563              (cond
4564               ((and gnus-thread-ignore-subject
4565                     gnus-tmp-prev-subject
4566                     (not (inline (gnus-subject-equal
4567                                   gnus-tmp-prev-subject subject))))
4568                subject)
4569               ((zerop gnus-tmp-level)
4570                (if (and (eq gnus-summary-make-false-root 'empty)
4571                         (memq number gnus-tmp-gathered)
4572                         gnus-tmp-prev-subject
4573                         (inline (gnus-subject-equal
4574                                  gnus-tmp-prev-subject subject)))
4575                    gnus-summary-same-subject
4576                  subject))
4577               (t gnus-summary-same-subject)))
4578             (if (and (eq gnus-summary-make-false-root 'adopt)
4579                      (= gnus-tmp-level 1)
4580                      (memq number gnus-tmp-gathered))
4581                 (setq gnus-tmp-opening-bracket ?\<
4582                       gnus-tmp-closing-bracket ?\>)
4583               (setq gnus-tmp-opening-bracket ?\[
4584                     gnus-tmp-closing-bracket ?\]))
4585             (setq
4586              gnus-tmp-indentation
4587              (aref gnus-thread-indent-array gnus-tmp-level)
4588              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4589              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4590                                 gnus-summary-default-score 0)
4591              gnus-tmp-score-char
4592              (if (or (null gnus-summary-default-score)
4593                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4594                          gnus-summary-zcore-fuzz))
4595                  ?\ ;;;Whitespace
4596                (if (< gnus-tmp-score gnus-summary-default-score)
4597                    gnus-score-below-mark gnus-score-over-mark))
4598              gnus-tmp-replied
4599              (cond ((memq number gnus-newsgroup-processable)
4600                     gnus-process-mark)
4601                    ((memq number gnus-newsgroup-cached)
4602                     gnus-cached-mark)
4603                    ((memq number gnus-newsgroup-replied)
4604                     gnus-replied-mark)
4605                    ((memq number gnus-newsgroup-forwarded)
4606                     gnus-forwarded-mark)
4607                    ((memq number gnus-newsgroup-saved)
4608                     gnus-saved-mark)
4609                    ((memq number gnus-newsgroup-recent)
4610                     gnus-recent-mark)
4611                    ((memq number gnus-newsgroup-unseen)
4612                     gnus-unseen-mark)
4613                    (t gnus-no-mark))
4614              gnus-tmp-from (mail-header-from gnus-tmp-header)
4615              gnus-tmp-name
4616              (cond
4617               ((string-match "<[^>]+> *$" gnus-tmp-from)
4618                (setq beg-match (match-beginning 0))
4619                (or (and (string-match "^\".+\"" gnus-tmp-from)
4620                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4621                    (substring gnus-tmp-from 0 beg-match)))
4622               ((string-match "(.+)" gnus-tmp-from)
4623                (substring gnus-tmp-from
4624                           (1+ (match-beginning 0)) (1- (match-end 0))))
4625               (t gnus-tmp-from))
4626              gnus-tmp-thread-tree-header-string
4627              (cond
4628               ((not gnus-show-threads) "")
4629               ((zerop gnus-tmp-level)
4630                (if (cdar thread)
4631                    (or gnus-sum-thread-tree-root subject)
4632                  (or gnus-sum-thread-tree-single-indent subject)))
4633               (t
4634                (concat (apply 'concat
4635                               (mapcar (lambda (item)
4636                                         (if (= item 1)
4637                                             gnus-sum-thread-tree-vertical
4638                                           gnus-sum-thread-tree-indent))
4639                                       (cdr (reverse tree-stack))))
4640                        (if (nth 1 thread)
4641                            gnus-sum-thread-tree-leaf-with-other
4642                          gnus-sum-thread-tree-single-leaf)))))
4643             (when (string= gnus-tmp-name "")
4644               (setq gnus-tmp-name gnus-tmp-from))
4645             (unless (numberp gnus-tmp-lines)
4646               (setq gnus-tmp-lines -1))
4647             (if (= gnus-tmp-lines -1)
4648                 (setq gnus-tmp-lines "?")
4649               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4650             (gnus-put-text-property
4651              (point)
4652              (progn (eval gnus-summary-line-format-spec) (point))
4653              'gnus-number number)
4654             (when gnus-visual-p
4655               (forward-line -1)
4656               (gnus-run-hooks 'gnus-summary-update-hook)
4657               (forward-line 1))
4658
4659             (setq gnus-tmp-prev-subject subject)))
4660
4661         (when (nth 1 thread)
4662           (push (list (max 0 gnus-tmp-level)
4663                       (copy-list tree-stack)
4664                       (nthcdr 1 thread))
4665                 stack))
4666         (push (if (nth 1 thread) 1 0) tree-stack)
4667         (incf gnus-tmp-level)
4668         (setq threads (if thread-end nil (cdar thread)))
4669         (unless threads
4670           (setq gnus-tmp-level 0)))))
4671   (gnus-message 7 "Generating summary...done"))
4672
4673 (defun gnus-summary-prepare-unthreaded (headers)
4674   "Generate an unthreaded summary buffer based on HEADERS."
4675   (let (header number mark)
4676
4677     (beginning-of-line)
4678
4679     (while headers
4680       ;; We may have to root out some bad articles...
4681       (when (memq (setq number (mail-header-number
4682                                 (setq header (pop headers))))
4683                   gnus-newsgroup-limit)
4684         ;; Mark article as read when it has a low score.
4685         (when (and gnus-summary-mark-below
4686                    (< (or (cdr (assq number gnus-newsgroup-scored))
4687                           gnus-summary-default-score 0)
4688                       gnus-summary-mark-below)
4689                    (not (gnus-summary-article-ancient-p number)))
4690           (setq gnus-newsgroup-unreads
4691                 (delq number gnus-newsgroup-unreads))
4692           (if gnus-newsgroup-auto-expire
4693               (push number gnus-newsgroup-expirable)
4694             (push (cons number gnus-low-score-mark)
4695                   gnus-newsgroup-reads)))
4696
4697         (setq mark (gnus-article-mark number))
4698         (push (gnus-data-make number mark (1+ (point)) header 0)
4699               gnus-newsgroup-data)
4700         (gnus-summary-insert-line
4701          header 0 number
4702          mark (memq number gnus-newsgroup-replied)
4703          (memq number gnus-newsgroup-expirable)
4704          (mail-header-subject header) nil
4705          (cdr (assq number gnus-newsgroup-scored))
4706          (memq number gnus-newsgroup-processable))))))
4707
4708 (defun gnus-summary-remove-list-identifiers ()
4709   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4710   (let ((regexp (if (consp gnus-list-identifiers)
4711                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4712                   gnus-list-identifiers))
4713         changed subject)
4714     (when regexp
4715       (dolist (header gnus-newsgroup-headers)
4716         (setq subject (mail-header-subject header)
4717               changed nil)
4718         (while (string-match
4719                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4720                 subject)
4721           (setq subject
4722                 (concat (substring subject 0 (match-beginning 2))
4723                         (substring subject (match-end 0)))
4724                 changed t))
4725         (when (and changed
4726                    (string-match
4727                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4728           (setq subject
4729                 (concat (substring subject 0 (match-beginning 1))
4730                         (substring subject (match-end 1)))))
4731         (when changed
4732           (mail-header-set-subject header subject))))))
4733
4734 (defun gnus-fetch-headers (articles)
4735   "Fetch headers of ARTICLES."
4736   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4737     (gnus-message 5 "Fetching headers for %s..." name)
4738     (prog1
4739         (if (eq 'nov
4740                 (setq gnus-headers-retrieved-by
4741                       (gnus-retrieve-headers
4742                        articles gnus-newsgroup-name
4743                        ;; We might want to fetch old headers, but
4744                        ;; not if there is only 1 article.
4745                        (and (or (and
4746                                  (not (eq gnus-fetch-old-headers 'some))
4747                                  (not (numberp gnus-fetch-old-headers)))
4748                                 (> (length articles) 1))
4749                             gnus-fetch-old-headers))))
4750             (gnus-get-newsgroup-headers-xover
4751              articles nil nil gnus-newsgroup-name t)
4752           (gnus-get-newsgroup-headers))
4753       (gnus-message 5 "Fetching headers for %s...done" name))))
4754
4755 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4756   "Select newsgroup GROUP.
4757 If READ-ALL is non-nil, all articles in the group are selected.
4758 If SELECT-ARTICLES, only select those articles from GROUP."
4759   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4760          ;;!!! Dirty hack; should be removed.
4761          (gnus-summary-ignore-duplicates
4762           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4763               t
4764             gnus-summary-ignore-duplicates))
4765          (info (nth 2 entry))
4766          articles fetched-articles cached)
4767
4768     (unless (gnus-check-server
4769              (set (make-local-variable 'gnus-current-select-method)
4770                   (gnus-find-method-for-group group)))
4771       (error "Couldn't open server"))
4772
4773     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4774         (gnus-activate-group group)     ; Or we can activate it...
4775         (progn                          ; Or we bug out.
4776           (when (equal major-mode 'gnus-summary-mode)
4777             (kill-buffer (current-buffer)))
4778           (error "Couldn't activate group %s: %s"
4779                  group (gnus-status-message group))))
4780
4781     (unless (gnus-request-group group t)
4782       (when (equal major-mode 'gnus-summary-mode)
4783         (kill-buffer (current-buffer)))
4784       (error "Couldn't request group %s: %s"
4785              group (gnus-status-message group)))
4786
4787     (setq gnus-newsgroup-name group
4788           gnus-newsgroup-unselected nil
4789           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4790
4791     (let ((display (gnus-group-find-parameter group 'display)))
4792       (setq gnus-newsgroup-display
4793             (cond
4794              ((not (zerop (or (car-safe read-all) 0)))
4795               ;; The user entered the group with C-u SPC/RET, let's show
4796               ;; all articles.
4797               'gnus-not-ignore)
4798              ((eq display 'all)
4799               'gnus-not-ignore)
4800              ((arrayp display)
4801               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4802              ((numberp display)
4803               ;; The following is probably the "correct" solution, but
4804               ;; it makes Gnus fetch all headers and then limit the
4805               ;; articles (which is slow), so instead we hack the
4806               ;; select-articles parameter instead. -- Simon Josefsson
4807               ;; <jas@kth.se>
4808               ;;
4809               ;; (gnus-byte-compile
4810               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4811               ;;                         display)))))
4812               (setq select-articles
4813                     (gnus-uncompress-range
4814                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4815                              (if (> tmp 0)
4816                                  tmp
4817                                1))
4818                            (cdr (gnus-active group)))))
4819               nil)
4820              (t
4821               nil))))
4822
4823     (gnus-summary-setup-default-charset)
4824
4825     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4826     (when (gnus-virtual-group-p group)
4827       (setq cached gnus-newsgroup-cached))
4828
4829     (setq gnus-newsgroup-unreads
4830           (gnus-sorted-ndifference
4831            (gnus-sorted-ndifference gnus-newsgroup-unreads
4832                                     gnus-newsgroup-marked)
4833            gnus-newsgroup-dormant))
4834
4835     (setq gnus-newsgroup-processable nil)
4836
4837     (gnus-update-read-articles group gnus-newsgroup-unreads)
4838
4839     ;; Adjust and set lists of article marks.
4840     (when info
4841       (gnus-adjust-marked-articles info))
4842
4843     (if (setq articles select-articles)
4844         (setq gnus-newsgroup-unselected
4845               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4846       (setq articles (gnus-articles-to-read group read-all)))
4847
4848     (cond
4849      ((null articles)
4850       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4851       'quit)
4852      ((eq articles 0) nil)
4853      (t
4854       ;; Init the dependencies hash table.
4855       (setq gnus-newsgroup-dependencies
4856             (gnus-make-hashtable (length articles)))
4857       (gnus-set-global-variables)
4858       ;; Retrieve the headers and read them in.
4859       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4860
4861       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4862       (when cached
4863         (setq gnus-newsgroup-cached cached))
4864
4865       ;; Suppress duplicates?
4866       (when gnus-suppress-duplicates
4867         (gnus-dup-suppress-articles))
4868
4869       ;; Set the initial limit.
4870       (setq gnus-newsgroup-limit (copy-sequence articles))
4871       ;; Remove canceled articles from the list of unread articles.
4872       (setq fetched-articles
4873             (mapcar (lambda (headers) (mail-header-number headers))
4874                     gnus-newsgroup-headers))
4875       (setq gnus-newsgroup-articles fetched-articles)
4876       (setq gnus-newsgroup-unreads
4877             (gnus-sorted-nintersection
4878              gnus-newsgroup-unreads fetched-articles))
4879       (gnus-compute-unseen-list)
4880
4881       ;; Removed marked articles that do not exist.
4882       (gnus-update-missing-marks
4883        (gnus-sorted-difference articles fetched-articles))
4884       ;; We might want to build some more threads first.
4885       (when (and gnus-fetch-old-headers
4886                  (eq gnus-headers-retrieved-by 'nov))
4887         (if (eq gnus-fetch-old-headers 'invisible)
4888             (gnus-build-all-threads)
4889           (gnus-build-old-threads)))
4890       ;; Let the Gnus agent mark articles as read.
4891       (when gnus-agent
4892         (gnus-agent-get-undownloaded-list))
4893       ;; Remove list identifiers from subject
4894       (when gnus-list-identifiers
4895         (gnus-summary-remove-list-identifiers))
4896       ;; Check whether auto-expire is to be done in this group.
4897       (setq gnus-newsgroup-auto-expire
4898             (gnus-group-auto-expirable-p group))
4899       ;; Set up the article buffer now, if necessary.
4900       (unless gnus-single-article-buffer
4901         (gnus-article-setup-buffer))
4902       ;; First and last article in this newsgroup.
4903       (when gnus-newsgroup-headers
4904         (setq gnus-newsgroup-begin
4905               (mail-header-number (car gnus-newsgroup-headers))
4906               gnus-newsgroup-end
4907               (mail-header-number
4908                (gnus-last-element gnus-newsgroup-headers))))
4909       ;; GROUP is successfully selected.
4910       (or gnus-newsgroup-headers t)))))
4911
4912 (defun gnus-compute-unseen-list ()
4913   ;; The `seen' marks are treated specially.
4914   (if (not gnus-newsgroup-seen)
4915       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4916     (setq gnus-newsgroup-unseen
4917           (gnus-inverse-list-range-intersection
4918            gnus-newsgroup-articles gnus-newsgroup-seen))))
4919
4920 (defun gnus-summary-display-make-predicate (display)
4921   (require 'gnus-agent)
4922   (when (= (length display) 1)
4923     (setq display (car display)))
4924   (unless gnus-summary-display-cache
4925     (dolist (elem (append '((unread . unread)
4926                             (read . read)
4927                             (unseen . unseen))
4928                           gnus-article-mark-lists))
4929       (push (cons (cdr elem)
4930                   (gnus-byte-compile
4931                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4932             gnus-summary-display-cache)))
4933   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4934         (gnus-category-predicate-cache gnus-summary-display-cache))
4935     (gnus-get-predicate display)))
4936
4937 ;; Uses the dynamically bound `number' variable.
4938 (defvar number)
4939 (defun gnus-article-marked-p (type &optional article)
4940   (let ((article (or article number)))
4941     (cond
4942      ((eq type 'tick)
4943       (memq article gnus-newsgroup-marked))
4944      ((eq type 'unsend)
4945       (memq article gnus-newsgroup-unsendable))
4946      ((eq type 'undownload)
4947       (memq article gnus-newsgroup-undownloaded))
4948      ((eq type 'download)
4949       (memq article gnus-newsgroup-downloadable))
4950      ((eq type 'unread)
4951       (memq article gnus-newsgroup-unreads))
4952      ((eq type 'read)
4953       (memq article gnus-newsgroup-reads))
4954      ((eq type 'dormant)
4955       (memq article gnus-newsgroup-dormant) )
4956      ((eq type 'expire)
4957       (memq article gnus-newsgroup-expirable))
4958      ((eq type 'reply)
4959       (memq article gnus-newsgroup-replied))
4960      ((eq type 'killed)
4961       (memq article gnus-newsgroup-killed))
4962      ((eq type 'bookmark)
4963       (assq article gnus-newsgroup-bookmarks))
4964      ((eq type 'score)
4965       (assq article gnus-newsgroup-scored))
4966      ((eq type 'save)
4967       (memq article gnus-newsgroup-saved))
4968      ((eq type 'cache)
4969       (memq article gnus-newsgroup-cached))
4970      ((eq type 'forward)
4971       (memq article gnus-newsgroup-forwarded))
4972      ((eq type 'seen)
4973       (not (memq article gnus-newsgroup-unseen)))
4974      ((eq type 'recent)
4975       (memq article gnus-newsgroup-recent))
4976      (t t))))
4977
4978 (defun gnus-articles-to-read (group &optional read-all)
4979   "Find out what articles the user wants to read."
4980   (let* ((articles
4981           ;; Select all articles if `read-all' is non-nil, or if there
4982           ;; are no unread articles.
4983           (if (or read-all
4984                   (and (zerop (length gnus-newsgroup-marked))
4985                        (zerop (length gnus-newsgroup-unreads)))
4986                   ;; Fetch all if the predicate is non-nil.
4987                   gnus-newsgroup-display)
4988               ;; We want to select the headers for all the articles in
4989               ;; the group, so we select either all the active
4990               ;; articles in the group, or (if that's nil), the
4991               ;; articles in the cache.
4992               (or
4993                (gnus-uncompress-range (gnus-active group))
4994                (gnus-cache-articles-in-group group))
4995             ;; Select only the "normal" subset of articles.
4996             (gnus-sorted-nunion
4997              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4998              gnus-newsgroup-unreads)))
4999          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5000          (scored (length scored-list))
5001          (number (length articles))
5002          (marked (+ (length gnus-newsgroup-marked)
5003                     (length gnus-newsgroup-dormant)))
5004          (select
5005           (cond
5006            ((numberp read-all)
5007             read-all)
5008            ((numberp gnus-newsgroup-display)
5009             gnus-newsgroup-display)
5010            (t
5011             (condition-case ()
5012                 (cond
5013                  ((and (or (<= scored marked) (= scored number))
5014                        (numberp gnus-large-newsgroup)
5015                        (> number gnus-large-newsgroup))
5016                   (let* ((cursor-in-echo-area nil)
5017                          (initial (gnus-parameter-large-newsgroup-initial
5018                                    gnus-newsgroup-name))
5019                          (input
5020                           (read-string
5021                            (format
5022                             "How many articles from %s (%s %d): "
5023                             (gnus-limit-string
5024                              (gnus-group-decoded-name gnus-newsgroup-name)
5025                              35)
5026                             (if initial "max" "default")
5027                             number)
5028                            (if initial
5029                                (cons (number-to-string initial)
5030                                      0)))))
5031                     (if (string-match "^[ \t]*$" input) number input)))
5032                  ((and (> scored marked) (< scored number)
5033                        (> (- scored number) 20))
5034                   (let ((input
5035                          (read-string
5036                           (format "%s %s (%d scored, %d total): "
5037                                   "How many articles from"
5038                                   (gnus-group-decoded-name group)
5039                                   scored number))))
5040                     (if (string-match "^[ \t]*$" input)
5041                         number input)))
5042                  (t number))
5043               (quit
5044                (message "Quit getting the articles to read")
5045                nil))))))
5046     (setq select (if (stringp select) (string-to-number select) select))
5047     (if (or (null select) (zerop select))
5048         select
5049       (if (and (not (zerop scored)) (<= (abs select) scored))
5050           (progn
5051             (setq articles (sort scored-list '<))
5052             (setq number (length articles)))
5053         (setq articles (copy-sequence articles)))
5054
5055       (when (< (abs select) number)
5056         (if (< select 0)
5057             ;; Select the N oldest articles.
5058             (setcdr (nthcdr (1- (abs select)) articles) nil)
5059           ;; Select the N most recent articles.
5060           (setq articles (nthcdr (- number select) articles))))
5061       (setq gnus-newsgroup-unselected
5062             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5063       (when gnus-alter-articles-to-read-function
5064         (setq gnus-newsgroup-unreads
5065               (sort
5066                (funcall gnus-alter-articles-to-read-function
5067                         gnus-newsgroup-name gnus-newsgroup-unreads)
5068                '<)))
5069       articles)))
5070
5071 (defun gnus-killed-articles (killed articles)
5072   (let (out)
5073     (while articles
5074       (when (inline (gnus-member-of-range (car articles) killed))
5075         (push (car articles) out))
5076       (setq articles (cdr articles)))
5077     out))
5078
5079 (defun gnus-uncompress-marks (marks)
5080   "Uncompress the mark ranges in MARKS."
5081   (let ((uncompressed '(score bookmark))
5082         out)
5083     (while marks
5084       (if (memq (caar marks) uncompressed)
5085           (push (car marks) out)
5086         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5087       (setq marks (cdr marks)))
5088     out))
5089
5090 (defun gnus-article-mark-to-type (mark)
5091   "Return the type of MARK."
5092   (or (cadr (assq mark gnus-article-special-mark-lists))
5093       'list))
5094
5095 (defun gnus-article-unpropagatable-p (mark)
5096   "Return whether MARK should be propagated to backend."
5097   (memq mark gnus-article-unpropagated-mark-lists))
5098
5099 (defun gnus-adjust-marked-articles (info)
5100   "Set all article lists and remove all marks that are no longer valid."
5101   (let* ((marked-lists (gnus-info-marks info))
5102          (active (gnus-active (gnus-info-group info)))
5103          (min (car active))
5104          (max (cdr active))
5105          (types gnus-article-mark-lists)
5106          marks var articles article mark mark-type)
5107
5108     (dolist (marks marked-lists)
5109       (setq mark (car marks)
5110             mark-type (gnus-article-mark-to-type mark)
5111             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5112
5113       ;; We set the variable according to the type of the marks list,
5114       ;; and then adjust the marks to a subset of the active articles.
5115       (cond
5116        ;; Adjust "simple" lists.
5117        ((eq mark-type 'list)
5118         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5119         (when (memq mark '(tick dormant expire reply save))
5120           (while articles
5121             (when (or (< (setq article (pop articles)) min) (> article max))
5122               (set var (delq article (symbol-value var)))))))
5123        ;; Adjust assocs.
5124        ((eq mark-type 'tuple)
5125         (set var (setq articles (cdr marks)))
5126         (when (not (listp (cdr (symbol-value var))))
5127           (set var (list (symbol-value var))))
5128         (when (not (listp (cdr articles)))
5129           (setq articles (list articles)))
5130         (while articles
5131           (when (or (not (consp (setq article (pop articles))))
5132                     (< (car article) min)
5133                     (> (car article) max))
5134             (set var (delq article (symbol-value var))))))
5135        ;; Adjust ranges (sloppily).
5136        ((eq mark-type 'range)
5137         (cond
5138          ((eq mark 'seen)
5139           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5140           ;; It should be (seen (NUM1 . NUM2)).
5141           (when (numberp (cddr marks))
5142             (setcdr marks (list (cdr marks))))
5143           (setq articles (cdr marks))
5144           (while (and articles
5145                       (or (and (consp (car articles))
5146                                (> min (cdar articles)))
5147                           (and (numberp (car articles))
5148                                (> min (car articles)))))
5149             (pop articles))
5150           (set var articles))))))))
5151
5152 (defun gnus-update-missing-marks (missing)
5153   "Go through the list of MISSING articles and remove them from the mark lists."
5154   (when missing
5155     (let (var m)
5156       ;; Go through all types.
5157       (dolist (elem gnus-article-mark-lists)
5158         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5159           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5160           (when (symbol-value var)
5161             ;; This list has articles.  So we delete all missing
5162             ;; articles from it.
5163             (setq m missing)
5164             (while m
5165               (set var (delq (pop m) (symbol-value var))))))))))
5166
5167 (defun gnus-update-marks ()
5168   "Enter the various lists of marked articles into the newsgroup info list."
5169   (let ((types gnus-article-mark-lists)
5170         (info (gnus-get-info gnus-newsgroup-name))
5171         type list newmarked symbol delta-marks)
5172     (when info
5173       ;; Add all marks lists to the list of marks lists.
5174       (while (setq type (pop types))
5175         (setq list (symbol-value
5176                     (setq symbol
5177                           (intern (format "gnus-newsgroup-%s" (car type))))))
5178
5179         (when list
5180           ;; Get rid of the entries of the articles that have the
5181           ;; default score.
5182           (when (and (eq (cdr type) 'score)
5183                      gnus-save-score
5184                      list)
5185             (let* ((arts list)
5186                    (prev (cons nil list))
5187                    (all prev))
5188               (while arts
5189                 (if (or (not (consp (car arts)))
5190                         (= (cdar arts) gnus-summary-default-score))
5191                     (setcdr prev (cdr arts))
5192                   (setq prev arts))
5193                 (setq arts (cdr arts)))
5194               (setq list (cdr all)))))
5195
5196         (when (eq (cdr type) 'seen)
5197           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5198
5199         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5200           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5201
5202         (when (and (gnus-check-backend-function
5203                     'request-set-mark gnus-newsgroup-name)
5204                    (not (gnus-article-unpropagatable-p (cdr type))))
5205           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5206                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5207                  (add (gnus-remove-from-range
5208                        (gnus-copy-sequence list) old)))
5209             (when add
5210               (push (list add 'add (list (cdr type))) delta-marks))
5211             (when del
5212               (push (list del 'del (list (cdr type))) delta-marks))))
5213
5214         (when list
5215           (push (cons (cdr type) list) newmarked)))
5216
5217       (when delta-marks
5218         (unless (gnus-check-group gnus-newsgroup-name)
5219           (error "Can't open server for %s" gnus-newsgroup-name))
5220         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5221
5222       ;; Enter these new marks into the info of the group.
5223       (if (nthcdr 3 info)
5224           (setcar (nthcdr 3 info) newmarked)
5225         ;; Add the marks lists to the end of the info.
5226         (when newmarked
5227           (setcdr (nthcdr 2 info) (list newmarked))))
5228
5229       ;; Cut off the end of the info if there's nothing else there.
5230       (let ((i 5))
5231         (while (and (> i 2)
5232                     (not (nth i info)))
5233           (when (nthcdr (decf i) info)
5234             (setcdr (nthcdr i info) nil)))))))
5235
5236 (defun gnus-set-mode-line (where)
5237   "Set the mode line of the article or summary buffers.
5238 If WHERE is `summary', the summary mode line format will be used."
5239   ;; Is this mode line one we keep updated?
5240   (when (and (memq where gnus-updated-mode-lines)
5241              (symbol-value
5242               (intern (format "gnus-%s-mode-line-format-spec" where))))
5243     (let (mode-string)
5244       (save-excursion
5245         ;; We evaluate this in the summary buffer since these
5246         ;; variables are buffer-local to that buffer.
5247         (set-buffer gnus-summary-buffer)
5248         ;; We bind all these variables that are used in the `eval' form
5249         ;; below.
5250         (let* ((mformat (symbol-value
5251                          (intern
5252                           (format "gnus-%s-mode-line-format-spec" where))))
5253                (gnus-tmp-group-name (gnus-group-decoded-name
5254                                      gnus-newsgroup-name))
5255                (gnus-tmp-article-number (or gnus-current-article 0))
5256                (gnus-tmp-unread gnus-newsgroup-unreads)
5257                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5258                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5259                (gnus-tmp-unread-and-unselected
5260                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5261                             (zerop gnus-tmp-unselected))
5262                        "")
5263                       ((zerop gnus-tmp-unselected)
5264                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5265                       (t (format "{%d(+%d) more}"
5266                                  gnus-tmp-unread-and-unticked
5267                                  gnus-tmp-unselected))))
5268                (gnus-tmp-subject
5269                 (if (and gnus-current-headers
5270                          (vectorp gnus-current-headers))
5271                     (gnus-mode-string-quote
5272                      (mail-header-subject gnus-current-headers))
5273                   ""))
5274                bufname-length max-len
5275                gnus-tmp-header);; passed as argument to any user-format-funcs
5276           (setq mode-string (eval mformat))
5277           (setq bufname-length (if (string-match "%b" mode-string)
5278                                    (- (length
5279                                        (buffer-name
5280                                         (if (eq where 'summary)
5281                                             nil
5282                                           (get-buffer gnus-article-buffer))))
5283                                       2)
5284                                  0))
5285           (setq max-len (max 4 (if gnus-mode-non-string-length
5286                                    (- (window-width)
5287                                       gnus-mode-non-string-length
5288                                       bufname-length)
5289                                  (length mode-string))))
5290           ;; We might have to chop a bit of the string off...
5291           (when (> (length mode-string) max-len)
5292             (setq mode-string
5293                   (concat (gnus-truncate-string mode-string (- max-len 3))
5294                           "...")))
5295           ;; Pad the mode string a bit.
5296           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5297       ;; Update the mode line.
5298       (setq mode-line-buffer-identification
5299             (gnus-mode-line-buffer-identification (list mode-string)))
5300       (set-buffer-modified-p t))))
5301
5302 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5303   "Go through the HEADERS list and add all Xrefs to a hash table.
5304 The resulting hash table is returned, or nil if no Xrefs were found."
5305   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5306          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5307          (xref-hashtb (gnus-make-hashtable))
5308          start group entry number xrefs header)
5309     (while headers
5310       (setq header (pop headers))
5311       (when (and (setq xrefs (mail-header-xref header))
5312                  (not (memq (setq number (mail-header-number header))
5313                             unreads)))
5314         (setq start 0)
5315         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5316           (setq start (match-end 0))
5317           (setq group (if prefix
5318                           (concat prefix (substring xrefs (match-beginning 1)
5319                                                     (match-end 1)))
5320                         (substring xrefs (match-beginning 1) (match-end 1))))
5321           (setq number
5322                 (string-to-int (substring xrefs (match-beginning 2)
5323                                           (match-end 2))))
5324           (if (setq entry (gnus-gethash group xref-hashtb))
5325               (setcdr entry (cons number (cdr entry)))
5326             (gnus-sethash group (cons number nil) xref-hashtb)))))
5327     (and start xref-hashtb)))
5328
5329 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5330   "Look through all the headers and mark the Xrefs as read."
5331   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5332         name entry info xref-hashtb idlist method nth4)
5333     (save-excursion
5334       (set-buffer gnus-group-buffer)
5335       (when (setq xref-hashtb
5336                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5337         (mapatoms
5338          (lambda (group)
5339            (unless (string= from-newsgroup (setq name (symbol-name group)))
5340              (setq idlist (symbol-value group))
5341              ;; Dead groups are not updated.
5342              (and (prog1
5343                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5344                             info (nth 2 entry))
5345                     (when (stringp (setq nth4 (gnus-info-method info)))
5346                       (setq nth4 (gnus-server-to-method nth4))))
5347                   ;; Only do the xrefs if the group has the same
5348                   ;; select method as the group we have just read.
5349                   (or (gnus-methods-equal-p
5350                        nth4 (gnus-find-method-for-group from-newsgroup))
5351                       virtual
5352                       (equal nth4 (setq method (gnus-find-method-for-group
5353                                                 from-newsgroup)))
5354                       (and (equal (car nth4) (car method))
5355                            (equal (nth 1 nth4) (nth 1 method))))
5356                   gnus-use-cross-reference
5357                   (or (not (eq gnus-use-cross-reference t))
5358                       virtual
5359                       ;; Only do cross-references on subscribed
5360                       ;; groups, if that is what is wanted.
5361                       (<= (gnus-info-level info) gnus-level-subscribed))
5362                   (gnus-group-make-articles-read name idlist))))
5363          xref-hashtb)))))
5364
5365 (defun gnus-compute-read-articles (group articles)
5366   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5367          (info (nth 2 entry))
5368          (active (gnus-active group))
5369          ninfo)
5370     (when entry
5371       ;; First peel off all invalid article numbers.
5372       (when active
5373         (let ((ids articles)
5374               id first)
5375           (while (setq id (pop ids))
5376             (when (and first (> id (cdr active)))
5377               ;; We'll end up in this situation in one particular
5378               ;; obscure situation.  If you re-scan a group and get
5379               ;; a new article that is cross-posted to a different
5380               ;; group that has not been re-scanned, you might get
5381               ;; crossposted article that has a higher number than
5382               ;; Gnus believes possible.  So we re-activate this
5383               ;; group as well.  This might mean doing the
5384               ;; crossposting thingy will *increase* the number
5385               ;; of articles in some groups.  Tsk, tsk.
5386               (setq active (or (gnus-activate-group group) active)))
5387             (when (or (> id (cdr active))
5388                       (< id (car active)))
5389               (setq articles (delq id articles))))))
5390       ;; If the read list is nil, we init it.
5391       (if (and active
5392                (null (gnus-info-read info))
5393                (> (car active) 1))
5394           (setq ninfo (cons 1 (1- (car active))))
5395         (setq ninfo (gnus-info-read info)))
5396       ;; Then we add the read articles to the range.
5397       (gnus-add-to-range
5398        ninfo (setq articles (sort articles '<))))))
5399
5400 (defun gnus-group-make-articles-read (group articles)
5401   "Update the info of GROUP to say that ARTICLES are read."
5402   (let* ((num 0)
5403          (entry (gnus-gethash group gnus-newsrc-hashtb))
5404          (info (nth 2 entry))
5405          (active (gnus-active group))
5406          range)
5407     (when entry
5408       (setq range (gnus-compute-read-articles group articles))
5409       (save-excursion
5410         (set-buffer gnus-group-buffer)
5411         (gnus-undo-register
5412           `(progn
5413              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5414              (gnus-info-set-read ',info ',(gnus-info-read info))
5415              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5416              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5417              (gnus-group-update-group ,group t))))
5418       ;; Add the read articles to the range.
5419       (gnus-info-set-read info range)
5420       (gnus-request-set-mark group (list (list range 'add '(read))))
5421       ;; Then we have to re-compute how many unread
5422       ;; articles there are in this group.
5423       (when active
5424         (cond
5425          ((not range)
5426           (setq num (- (1+ (cdr active)) (car active))))
5427          ((not (listp (cdr range)))
5428           (setq num (- (cdr active) (- (1+ (cdr range))
5429                                        (car range)))))
5430          (t
5431           (while range
5432             (if (numberp (car range))
5433                 (setq num (1+ num))
5434               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5435             (setq range (cdr range)))
5436           (setq num (- (cdr active) num))))
5437         ;; Update the number of unread articles.
5438         (setcar entry num)
5439         ;; Update the group buffer.
5440         (gnus-group-update-group group t)))))
5441
5442 (defvar gnus-newsgroup-none-id 0)
5443
5444 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5445   (let ((cur nntp-server-buffer)
5446         (dependencies
5447          (or dependencies
5448              (save-excursion (set-buffer gnus-summary-buffer)
5449                              gnus-newsgroup-dependencies)))
5450         headers id end ref
5451         (mail-parse-charset gnus-newsgroup-charset)
5452         (mail-parse-ignored-charsets
5453          (save-excursion (condition-case nil
5454                              (set-buffer gnus-summary-buffer)
5455                            (error))
5456                          gnus-newsgroup-ignored-charsets)))
5457     (save-excursion
5458       (set-buffer nntp-server-buffer)
5459       ;; Translate all TAB characters into SPACE characters.
5460       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5461       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5462       (gnus-run-hooks 'gnus-parse-headers-hook)
5463       (let ((case-fold-search t)
5464             in-reply-to header p lines chars ctype)
5465         (goto-char (point-min))
5466         ;; Search to the beginning of the next header.  Error messages
5467         ;; do not begin with 2 or 3.
5468         (while (re-search-forward "^[23][0-9]+ " nil t)
5469           (setq id nil
5470                 ref nil)
5471           ;; This implementation of this function, with nine
5472           ;; search-forwards instead of the one re-search-forward and
5473           ;; a case (which basically was the old function) is actually
5474           ;; about twice as fast, even though it looks messier.  You
5475           ;; can't have everything, I guess.  Speed and elegance
5476           ;; doesn't always go hand in hand.
5477           (setq
5478            header
5479            (make-full-mail-header
5480             ;; Number.
5481             (prog1
5482                 (read cur)
5483               (end-of-line)
5484               (setq p (point))
5485               (narrow-to-region (point)
5486                                 (or (and (search-forward "\n.\n" nil t)
5487                                          (- (point) 2))
5488                                     (point))))
5489             ;; Subject.
5490             (progn
5491               (goto-char p)
5492               (if (search-forward "\nsubject:" nil t)
5493                   (nnheader-header-value)
5494                 "(none)"))
5495             ;; From.
5496             (progn
5497               (goto-char p)
5498               (if (search-forward "\nfrom:" nil t)
5499                   (nnheader-header-value)
5500                 "(nobody)"))
5501             ;; Date.
5502             (progn
5503               (goto-char p)
5504               (if (search-forward "\ndate:" nil t)
5505                   (nnheader-header-value) ""))
5506             ;; Message-ID.
5507             (progn
5508               (goto-char p)
5509               (setq id (if (re-search-forward
5510                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5511                            ;; We do it this way to make sure the Message-ID
5512                            ;; is (somewhat) syntactically valid.
5513                            (buffer-substring (match-beginning 1)
5514                                              (match-end 1))
5515                          ;; If there was no message-id, we just fake one
5516                          ;; to make subsequent routines simpler.
5517                          (nnheader-generate-fake-message-id))))
5518             ;; References.
5519             (progn
5520               (goto-char p)
5521               (if (search-forward "\nreferences:" nil t)
5522                   (progn
5523                     (setq end (point))
5524                     (prog1
5525                         (nnheader-header-value)
5526                       (setq ref
5527                             (buffer-substring
5528                              (progn
5529                                ;; (end-of-line)
5530                                (search-backward ">" end t)
5531                                (1+ (point)))
5532                              (progn
5533                                (search-backward "<" end t)
5534                                (point))))))
5535                 ;; Get the references from the in-reply-to header if there
5536                 ;; were no references and the in-reply-to header looks
5537                 ;; promising.
5538                 (if (and (search-forward "\nin-reply-to:" nil t)
5539                          (setq in-reply-to (nnheader-header-value))
5540                          (string-match "<[^>]+>" in-reply-to))
5541                     (let (ref2)
5542                       (setq ref (substring in-reply-to (match-beginning 0)
5543                                            (match-end 0)))
5544                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5545                         (setq ref2 (substring in-reply-to (match-beginning 0)
5546                                               (match-end 0)))
5547                         (when (> (length ref2) (length ref))
5548                           (setq ref ref2)))
5549                       ref)
5550                   (setq ref nil))))
5551             ;; Chars.
5552             (progn
5553               (goto-char p)
5554               (if (search-forward "\nchars: " nil t)
5555                   (if (numberp (setq chars (ignore-errors (read cur))))
5556                       chars -1)
5557                 -1))
5558             ;; Lines.
5559             (progn
5560               (goto-char p)
5561               (if (search-forward "\nlines: " nil t)
5562                   (if (numberp (setq lines (ignore-errors (read cur))))
5563                       lines -1)
5564                 -1))
5565             ;; Xref.
5566             (progn
5567               (goto-char p)
5568               (and (search-forward "\nxref:" nil t)
5569                    (nnheader-header-value)))
5570             ;; Extra.
5571             (when gnus-extra-headers
5572               (let ((extra gnus-extra-headers)
5573                     out)
5574                 (while extra
5575                   (goto-char p)
5576                   (when (search-forward
5577                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5578                     (push (cons (car extra) (nnheader-header-value)) out))
5579                   (pop extra))
5580                 out))))
5581           (goto-char p)
5582           (if (and (search-forward "\ncontent-type: " nil t)
5583                    (setq ctype (nnheader-header-value)))
5584               (mime-entity-set-content-type-internal
5585                header (mime-parse-Content-Type ctype)))
5586           (when (equal id ref)
5587             (setq ref nil))
5588
5589           (when gnus-alter-header-function
5590             (funcall gnus-alter-header-function header)
5591             (setq id (mail-header-id header)
5592                   ref (gnus-parent-id (mail-header-references header))))
5593
5594           (when (setq header
5595                       (gnus-dependencies-add-header
5596                        header dependencies force-new))
5597             (push header headers))
5598           (goto-char (point-max))
5599           (widen))
5600         (nreverse headers)))))
5601
5602 ;; Goes through the xover lines and returns a list of vectors
5603 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5604                                                   force-new dependencies
5605                                                   group also-fetch-heads)
5606   "Parse the news overview data in the server buffer.
5607 Return a list of headers that match SEQUENCE (see
5608 `nntp-retrieve-headers')."
5609   ;; Get the Xref when the users reads the articles since most/some
5610   ;; NNTP servers do not include Xrefs when using XOVER.
5611   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5612   (let ((mail-parse-charset gnus-newsgroup-charset)
5613         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5614         (cur nntp-server-buffer)
5615         (dependencies (or dependencies gnus-newsgroup-dependencies))
5616         (allp (cond
5617                ((eq gnus-read-all-available-headers t)
5618                 t)
5619                ((stringp gnus-read-all-available-headers)
5620                 (string-match gnus-read-all-available-headers group))
5621                (t
5622                 nil)))
5623         number headers header)
5624     (save-excursion
5625       (set-buffer nntp-server-buffer)
5626       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5627       ;; Allow the user to mangle the headers before parsing them.
5628       (gnus-run-hooks 'gnus-parse-headers-hook)
5629       (goto-char (point-min))
5630       (gnus-parse-without-error
5631         (while (and (or sequence allp)
5632                     (not (eobp)))
5633           (setq number (read cur))
5634           (when (not allp)
5635             (while (and sequence
5636                         (< (car sequence) number))
5637               (setq sequence (cdr sequence))))
5638           (when (and (or allp
5639                          (and sequence
5640                               (eq number (car sequence))))
5641                      (progn
5642                        (setq sequence (cdr sequence))
5643                        (setq header (inline
5644                                       (gnus-nov-parse-line
5645                                        number dependencies force-new)))))
5646             (push header headers))
5647           (forward-line 1)))
5648       ;; A common bug in inn is that if you have posted an article and
5649       ;; then retrieves the active file, it will answer correctly --
5650       ;; the new article is included.  However, a NOV entry for the
5651       ;; article may not have been generated yet, so this may fail.
5652       ;; We work around this problem by retrieving the last few
5653       ;; headers using HEAD.
5654       (if (or (not also-fetch-heads)
5655               (not sequence))
5656           ;; We (probably) got all the headers.
5657           (nreverse headers)
5658         (let ((gnus-nov-is-evil t))
5659           (nconc
5660            (nreverse headers)
5661            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5662              (gnus-get-newsgroup-headers))))))))
5663
5664 (defun gnus-article-get-xrefs ()
5665   "Fill in the Xref value in `gnus-current-headers', if necessary.
5666 This is meant to be called in `gnus-article-internal-prepare-hook'."
5667   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5668                                  gnus-current-headers)))
5669     (or (not gnus-use-cross-reference)
5670         (not headers)
5671         (and (mail-header-xref headers)
5672              (not (string= (mail-header-xref headers) "")))
5673         (let ((case-fold-search t)
5674               xref)
5675           (save-restriction
5676             (nnheader-narrow-to-headers)
5677             (goto-char (point-min))
5678             (when (or (and (not (eobp))
5679                            (eq (downcase (char-after)) ?x)
5680                            (looking-at "Xref:"))
5681                       (search-forward "\nXref:" nil t))
5682               (goto-char (1+ (match-end 0)))
5683               (setq xref (buffer-substring (point)
5684                                            (progn (end-of-line) (point))))
5685               (mail-header-set-xref headers xref)))))))
5686
5687 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5688   "Find article ID and insert the summary line for that article.
5689 OLD-HEADER can either be a header or a line number to insert
5690 the subject line on."
5691   (let* ((line (and (numberp old-header) old-header))
5692          (old-header (and (vectorp old-header) old-header))
5693          (header (cond ((and old-header use-old-header)
5694                         old-header)
5695                        ((and (numberp id)
5696                              (gnus-number-to-header id))
5697                         (gnus-number-to-header id))
5698                        (t
5699                         (gnus-read-header id))))
5700          (number (and (numberp id) id))
5701          d)
5702     (when header
5703       ;; Rebuild the thread that this article is part of and go to the
5704       ;; article we have fetched.
5705       (when (and (not gnus-show-threads)
5706                  old-header)
5707         (when (and number
5708                    (setq d (gnus-data-find (mail-header-number old-header))))
5709           (goto-char (gnus-data-pos d))
5710           (gnus-data-remove
5711            number
5712            (- (gnus-point-at-bol)
5713               (prog1
5714                   (1+ (gnus-point-at-eol))
5715                 (gnus-delete-line))))))
5716       (when old-header
5717         (mail-header-set-number header (mail-header-number old-header)))
5718       (setq gnus-newsgroup-sparse
5719             (delq (setq number (mail-header-number header))
5720                   gnus-newsgroup-sparse))
5721       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5722       (push number gnus-newsgroup-limit)
5723       (gnus-rebuild-thread (mail-header-id header) line)
5724       (gnus-summary-goto-subject number nil t))
5725     (when (and (numberp number)
5726                (> number 0))
5727       ;; We have to update the boundaries even if we can't fetch the
5728       ;; article if ID is a number -- so that the next `P' or `N'
5729       ;; command will fetch the previous (or next) article even
5730       ;; if the one we tried to fetch this time has been canceled.
5731       (when (> number gnus-newsgroup-end)
5732         (setq gnus-newsgroup-end number))
5733       (when (< number gnus-newsgroup-begin)
5734         (setq gnus-newsgroup-begin number))
5735       (setq gnus-newsgroup-unselected
5736             (delq number gnus-newsgroup-unselected)))
5737     ;; Report back a success?
5738     (and header (mail-header-number header))))
5739
5740 ;;; Process/prefix in the summary buffer
5741
5742 (defun gnus-summary-work-articles (n)
5743   "Return a list of articles to be worked upon.
5744 The prefix argument, the list of process marked articles, and the
5745 current article will be taken into consideration."
5746   (save-excursion
5747     (set-buffer gnus-summary-buffer)
5748     (cond
5749      (n
5750       ;; A numerical prefix has been given.
5751       (setq n (prefix-numeric-value n))
5752       (let ((backward (< n 0))
5753             (n (abs (prefix-numeric-value n)))
5754             articles article)
5755         (save-excursion
5756           (while
5757               (and (> n 0)
5758                    (push (setq article (gnus-summary-article-number))
5759                          articles)
5760                    (if backward
5761                        (gnus-summary-find-prev nil article)
5762                      (gnus-summary-find-next nil article)))
5763             (decf n)))
5764         (nreverse articles)))
5765      ((and (gnus-region-active-p) (mark))
5766       (message "region active")
5767       ;; Work on the region between point and mark.
5768       (let ((max (max (point) (mark)))
5769             articles article)
5770         (save-excursion
5771           (goto-char (min (point) (mark)))
5772           (while
5773               (and
5774                (push (setq article (gnus-summary-article-number)) articles)
5775                (gnus-summary-find-next nil article)
5776                (< (point) max)))
5777           (nreverse articles))))
5778      (gnus-newsgroup-processable
5779       ;; There are process-marked articles present.
5780       ;; Save current state.
5781       (gnus-summary-save-process-mark)
5782       ;; Return the list.
5783       (reverse gnus-newsgroup-processable))
5784      (t
5785       ;; Just return the current article.
5786       (list (gnus-summary-article-number))))))
5787
5788 (defmacro gnus-summary-iterate (arg &rest forms)
5789   "Iterate over the process/prefixed articles and do FORMS.
5790 ARG is the interactive prefix given to the command.  FORMS will be
5791 executed with point over the summary line of the articles."
5792   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5793     `(let ((,articles (gnus-summary-work-articles ,arg)))
5794        (while ,articles
5795          (gnus-summary-goto-subject (car ,articles))
5796          ,@forms
5797          (pop ,articles)))))
5798
5799 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5800 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5801
5802 (defun gnus-summary-save-process-mark ()
5803   "Push the current set of process marked articles on the stack."
5804   (interactive)
5805   (push (copy-sequence gnus-newsgroup-processable)
5806         gnus-newsgroup-process-stack))
5807
5808 (defun gnus-summary-kill-process-mark ()
5809   "Push the current set of process marked articles on the stack and unmark."
5810   (interactive)
5811   (gnus-summary-save-process-mark)
5812   (gnus-summary-unmark-all-processable))
5813
5814 (defun gnus-summary-yank-process-mark ()
5815   "Pop the last process mark state off the stack and restore it."
5816   (interactive)
5817   (unless gnus-newsgroup-process-stack
5818     (error "Empty mark stack"))
5819   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5820
5821 (defun gnus-summary-process-mark-set (set)
5822   "Make SET into the current process marked articles."
5823   (gnus-summary-unmark-all-processable)
5824   (while set
5825     (gnus-summary-set-process-mark (pop set))))
5826
5827 ;;; Searching and stuff
5828
5829 (defun gnus-summary-search-group (&optional backward use-level)
5830   "Search for next unread newsgroup.
5831 If optional argument BACKWARD is non-nil, search backward instead."
5832   (save-excursion
5833     (set-buffer gnus-group-buffer)
5834     (when (gnus-group-search-forward
5835            backward nil (if use-level (gnus-group-group-level) nil))
5836       (gnus-group-group-name))))
5837
5838 (defun gnus-summary-best-group (&optional exclude-group)
5839   "Find the name of the best unread group.
5840 If EXCLUDE-GROUP, do not go to this group."
5841   (save-excursion
5842     (set-buffer gnus-group-buffer)
5843     (save-excursion
5844       (gnus-group-best-unread-group exclude-group))))
5845
5846 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5847   (if backward (gnus-summary-find-prev)
5848     (let* ((dummy (gnus-summary-article-intangible-p))
5849            (article (or article (gnus-summary-article-number)))
5850            (arts (gnus-data-find-list article))
5851            result)
5852       (when (and (not dummy)
5853                  (or (not gnus-summary-check-current)
5854                      (not unread)
5855                      (not (gnus-data-unread-p (car arts)))))
5856         (setq arts (cdr arts)))
5857       (when (setq result
5858                   (if unread
5859                       (progn
5860                         (while arts
5861                           (when (or (and undownloaded
5862                                          (eq gnus-undownloaded-mark
5863                                              (gnus-data-mark (car arts))))
5864                                     (gnus-data-unread-p (car arts)))
5865                             (setq result (car arts)
5866                                   arts nil))
5867                           (setq arts (cdr arts)))
5868                         result)
5869                     (car arts)))
5870         (goto-char (gnus-data-pos result))
5871         (gnus-data-number result)))))
5872
5873 (defun gnus-summary-find-prev (&optional unread article)
5874   (let* ((eobp (eobp))
5875          (article (or article (gnus-summary-article-number)))
5876          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5877          result)
5878     (when (and (not eobp)
5879                (or (not gnus-summary-check-current)
5880                    (not unread)
5881                    (not (gnus-data-unread-p (car arts)))))
5882       (setq arts (cdr arts)))
5883     (when (setq result
5884                 (if unread
5885                     (progn
5886                       (while arts
5887                         (when (gnus-data-unread-p (car arts))
5888                           (setq result (car arts)
5889                                 arts nil))
5890                         (setq arts (cdr arts)))
5891                       result)
5892                   (car arts)))
5893       (goto-char (gnus-data-pos result))
5894       (gnus-data-number result))))
5895
5896 (defun gnus-summary-find-subject (subject &optional unread backward article)
5897   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5898          (article (or article (gnus-summary-article-number)))
5899          (articles (gnus-data-list backward))
5900          (arts (gnus-data-find-list article articles))
5901          result)
5902     (when (or (not gnus-summary-check-current)
5903               (not unread)
5904               (not (gnus-data-unread-p (car arts))))
5905       (setq arts (cdr arts)))
5906     (while arts
5907       (and (or (not unread)
5908                (gnus-data-unread-p (car arts)))
5909            (vectorp (gnus-data-header (car arts)))
5910            (gnus-subject-equal
5911             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5912            (setq result (car arts)
5913                  arts nil))
5914       (setq arts (cdr arts)))
5915     (and result
5916          (goto-char (gnus-data-pos result))
5917          (gnus-data-number result))))
5918
5919 (defun gnus-summary-search-forward (&optional unread subject backward)
5920   "Search forward for an article.
5921 If UNREAD, look for unread articles.  If SUBJECT, look for
5922 articles with that subject.  If BACKWARD, search backward instead."
5923   (cond (subject (gnus-summary-find-subject subject unread backward))
5924         (backward (gnus-summary-find-prev unread))
5925         (t (gnus-summary-find-next unread))))
5926
5927 (defun gnus-recenter (&optional n)
5928   "Center point in window and redisplay frame.
5929 Also do horizontal recentering."
5930   (interactive "P")
5931   (when (and gnus-auto-center-summary
5932              (not (eq gnus-auto-center-summary 'vertical)))
5933     (gnus-horizontal-recenter))
5934   (recenter n))
5935
5936 (defun gnus-summary-recenter ()
5937   "Center point in the summary window.
5938 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5939 displayed, no centering will be performed."
5940   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5941   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5942   (interactive)
5943   (let* ((top (cond ((< (window-height) 4) 0)
5944                     ((< (window-height) 7) 1)
5945                     (t (if (numberp gnus-auto-center-summary)
5946                            gnus-auto-center-summary
5947                          2))))
5948          (height (1- (window-height)))
5949          (bottom (save-excursion (goto-char (point-max))
5950                                  (forward-line (- height))
5951                                  (point)))
5952          (window (get-buffer-window (current-buffer))))
5953     ;; The user has to want it.
5954     (when gnus-auto-center-summary
5955       (when (get-buffer-window gnus-article-buffer)
5956         ;; Only do recentering when the article buffer is displayed,
5957         ;; Set the window start to either `bottom', which is the biggest
5958         ;; possible valid number, or the second line from the top,
5959         ;; whichever is the least.
5960         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5961           (if (> bottom top-pos)
5962               ;; Keep the second line from the top visible
5963               (set-window-start window top-pos t)
5964             ;; Try to keep the bottom line visible; if it's partially
5965             ;; obscured, either scroll one more line to make it fully
5966             ;; visible, or revert to using TOP-POS.
5967             (save-excursion
5968               (goto-char (point-max))
5969               (forward-line -1)
5970               (let ((last-line-start (point)))
5971                 (goto-char bottom)
5972                 (set-window-start window (point) t)
5973                 (when (not (pos-visible-in-window-p last-line-start window))
5974                   (forward-line 1)
5975                   (set-window-start window (min (point) top-pos) t)))))))
5976       ;; Do horizontal recentering while we're at it.
5977       (when (and (get-buffer-window (current-buffer) t)
5978                  (not (eq gnus-auto-center-summary 'vertical)))
5979         (let ((selected (selected-window)))
5980           (select-window (get-buffer-window (current-buffer) t))
5981           (gnus-summary-position-point)
5982           (gnus-horizontal-recenter)
5983           (select-window selected))))))
5984
5985 (defun gnus-summary-jump-to-group (newsgroup)
5986   "Move point to NEWSGROUP in group mode buffer."
5987   ;; Keep update point of group mode buffer if visible.
5988   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5989       (save-window-excursion
5990         ;; Take care of tree window mode.
5991         (when (get-buffer-window gnus-group-buffer)
5992           (pop-to-buffer gnus-group-buffer))
5993         (gnus-group-jump-to-group newsgroup))
5994     (save-excursion
5995       ;; Take care of tree window mode.
5996       (if (get-buffer-window gnus-group-buffer)
5997           (pop-to-buffer gnus-group-buffer)
5998         (set-buffer gnus-group-buffer))
5999       (gnus-group-jump-to-group newsgroup))))
6000
6001 ;; This function returns a list of article numbers based on the
6002 ;; difference between the ranges of read articles in this group and
6003 ;; the range of active articles.
6004 (defun gnus-list-of-unread-articles (group)
6005   (let* ((read (gnus-info-read (gnus-get-info group)))
6006          (active (or (gnus-active group) (gnus-activate-group group)))
6007          (last (cdr active))
6008          first nlast unread)
6009     ;; If none are read, then all are unread.
6010     (if (not read)
6011         (setq first (car active))
6012       ;; If the range of read articles is a single range, then the
6013       ;; first unread article is the article after the last read
6014       ;; article.  Sounds logical, doesn't it?
6015       (if (and (not (listp (cdr read)))
6016                (or (< (car read) (car active))
6017                    (progn (setq read (list read))
6018                           nil)))
6019           (setq first (max (car active) (1+ (cdr read))))
6020         ;; `read' is a list of ranges.
6021         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6022                                   (caar read)))
6023                   1)
6024           (setq first (car active)))
6025         (while read
6026           (when first
6027             (while (< first nlast)
6028               (push first unread)
6029               (setq first (1+ first))))
6030           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6031           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6032           (setq read (cdr read)))))
6033     ;; And add the last unread articles.
6034     (while (<= first last)
6035       (push first unread)
6036       (setq first (1+ first)))
6037     ;; Return the list of unread articles.
6038     (delq 0 (nreverse unread))))
6039
6040 (defun gnus-list-of-read-articles (group)
6041   "Return a list of unread, unticked and non-dormant articles."
6042   (let* ((info (gnus-get-info group))
6043          (marked (gnus-info-marks info))
6044          (active (gnus-active group)))
6045     (and info active
6046          (gnus-list-range-difference
6047           (gnus-list-range-difference
6048            (gnus-sorted-complement
6049             (gnus-uncompress-range active)
6050             (gnus-list-of-unread-articles group))
6051            (cdr (assq 'dormant marked)))
6052           (cdr (assq 'tick marked))))))
6053
6054 ;; Various summary commands
6055
6056 (defun gnus-summary-select-article-buffer ()
6057   "Reconfigure windows to show article buffer."
6058   (interactive)
6059   (if (not (gnus-buffer-live-p gnus-article-buffer))
6060       (error "There is no article buffer for this summary buffer")
6061     (gnus-configure-windows 'article)
6062     (select-window (get-buffer-window gnus-article-buffer))))
6063
6064 (defun gnus-summary-universal-argument (arg)
6065   "Perform any operation on all articles that are process/prefixed."
6066   (interactive "P")
6067   (let ((articles (gnus-summary-work-articles arg))
6068         func article)
6069     (if (eq
6070          (setq
6071           func
6072           (key-binding
6073            (read-key-sequence
6074             (substitute-command-keys
6075              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6076          'undefined)
6077         (gnus-error 1 "Undefined key")
6078       (save-excursion
6079         (while articles
6080           (gnus-summary-goto-subject (setq article (pop articles)))
6081           (let (gnus-newsgroup-processable)
6082             (command-execute func))
6083           (gnus-summary-remove-process-mark article)))))
6084   (gnus-summary-position-point))
6085
6086 (defun gnus-summary-toggle-truncation (&optional arg)
6087   "Toggle truncation of summary lines.
6088 With arg, turn line truncation on iff arg is positive."
6089   (interactive "P")
6090   (setq truncate-lines
6091         (if (null arg) (not truncate-lines)
6092           (> (prefix-numeric-value arg) 0)))
6093   (redraw-display))
6094
6095 (defun gnus-summary-reselect-current-group (&optional all rescan)
6096   "Exit and then reselect the current newsgroup.
6097 The prefix argument ALL means to select all articles."
6098   (interactive "P")
6099   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6100     (error "Ephemeral groups can't be reselected"))
6101   (let ((current-subject (gnus-summary-article-number))
6102         (group gnus-newsgroup-name))
6103     (setq gnus-newsgroup-begin nil)
6104     (gnus-summary-exit)
6105     ;; We have to adjust the point of group mode buffer because
6106     ;; point was moved to the next unread newsgroup by exiting.
6107     (gnus-summary-jump-to-group group)
6108     (when rescan
6109       (save-excursion
6110         (save-window-excursion
6111           ;; Don't show group contents.
6112           (set-window-start (selected-window) (point-max))
6113           (gnus-group-get-new-news-this-group 1))))
6114     (gnus-group-read-group all t)
6115     (gnus-summary-goto-subject current-subject nil t)))
6116
6117 (defun gnus-summary-rescan-group (&optional all)
6118   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6119   (interactive "P")
6120   (gnus-summary-reselect-current-group all t))
6121
6122 (defun gnus-summary-update-info (&optional non-destructive)
6123   (save-excursion
6124     (let ((group gnus-newsgroup-name))
6125       (when group
6126         (when gnus-newsgroup-kill-headers
6127           (setq gnus-newsgroup-killed
6128                 (gnus-compress-sequence
6129                  (gnus-sorted-union
6130                   (gnus-list-range-intersection
6131                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6132                   gnus-newsgroup-unreads)
6133                  t)))
6134         (unless (listp (cdr gnus-newsgroup-killed))
6135           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6136         (let ((headers gnus-newsgroup-headers))
6137           ;; Set the new ranges of read articles.
6138           (save-excursion
6139             (set-buffer gnus-group-buffer)
6140             (gnus-undo-force-boundary))
6141           (gnus-update-read-articles
6142            group (gnus-sorted-union
6143                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6144           ;; Set the current article marks.
6145           (let ((gnus-newsgroup-scored
6146                  (if (and (not gnus-save-score)
6147                           (not non-destructive))
6148                      nil
6149                    gnus-newsgroup-scored)))
6150             (save-excursion
6151               (gnus-update-marks)))
6152           ;; Do the cross-ref thing.
6153           (when gnus-use-cross-reference
6154             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6155           ;; Do not switch windows but change the buffer to work.
6156           (set-buffer gnus-group-buffer)
6157           (unless (gnus-ephemeral-group-p group)
6158             (gnus-group-update-group group)))))))
6159
6160 (defun gnus-summary-save-newsrc (&optional force)
6161   "Save the current number of read/marked articles in the dribble buffer.
6162 The dribble buffer will then be saved.
6163 If FORCE (the prefix), also save the .newsrc file(s)."
6164   (interactive "P")
6165   (gnus-summary-update-info t)
6166   (if force
6167       (gnus-save-newsrc-file)
6168     (gnus-dribble-save)))
6169
6170 (defun gnus-summary-exit (&optional temporary)
6171   "Exit reading current newsgroup, and then return to group selection mode.
6172 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6173   (interactive)
6174   (gnus-set-global-variables)
6175   (gnus-kill-save-kill-buffer)
6176   (gnus-async-halt-prefetch)
6177   (let* ((group gnus-newsgroup-name)
6178          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6179          (mode major-mode)
6180          (group-point nil)
6181          (buf (current-buffer)))
6182     (unless quit-config
6183       ;; Do adaptive scoring, and possibly save score files.
6184       (when gnus-newsgroup-adaptive
6185         (gnus-score-adaptive))
6186       (when gnus-use-scoring
6187         (gnus-score-save)))
6188     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6189     ;; If we have several article buffers, we kill them at exit.
6190     (unless gnus-single-article-buffer
6191       (gnus-kill-buffer gnus-original-article-buffer)
6192       (setq gnus-article-current nil))
6193     (when gnus-use-cache
6194       (gnus-cache-possibly-remove-articles)
6195       (gnus-cache-save-buffers))
6196     (gnus-async-prefetch-remove-group group)
6197     (when gnus-suppress-duplicates
6198       (gnus-dup-enter-articles))
6199     (when gnus-use-trees
6200       (gnus-tree-close group))
6201     (when gnus-use-cache
6202       (gnus-cache-write-active))
6203     ;; Remove entries for this group.
6204     (nnmail-purge-split-history (gnus-group-real-name group))
6205     ;; Make all changes in this group permanent.
6206     (unless quit-config
6207       (gnus-run-hooks 'gnus-exit-group-hook)
6208       (gnus-summary-update-info))
6209     (gnus-close-group group)
6210     ;; Make sure where we were, and go to next newsgroup.
6211     (set-buffer gnus-group-buffer)
6212     (unless quit-config
6213       (gnus-group-jump-to-group group))
6214     (gnus-run-hooks 'gnus-summary-exit-hook)
6215     (unless (or quit-config
6216                 ;; If this group has disappeared from the summary
6217                 ;; buffer, don't skip forwards.
6218                 (not (string= group (gnus-group-group-name))))
6219       (gnus-group-next-unread-group 1))
6220     (setq group-point (point))
6221     (if temporary
6222         nil                             ;Nothing to do.
6223       ;; If we have several article buffers, we kill them at exit.
6224       (unless gnus-single-article-buffer
6225         (gnus-kill-buffer gnus-article-buffer)
6226         (gnus-kill-buffer gnus-original-article-buffer)
6227         (setq gnus-article-current nil))
6228       (set-buffer buf)
6229       (if (not gnus-kill-summary-on-exit)
6230           (progn
6231             (gnus-deaden-summary)
6232             (setq mode nil))
6233         ;; We set all buffer-local variables to nil.  It is unclear why
6234         ;; this is needed, but if we don't, buffer-local variables are
6235         ;; not garbage-collected, it seems.  This would the lead to en
6236         ;; ever-growing Emacs.
6237         (gnus-summary-clear-local-variables)
6238         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6239           (gnus-summary-clear-local-variables))
6240         (when (get-buffer gnus-article-buffer)
6241           (bury-buffer gnus-article-buffer))
6242         ;; We clear the global counterparts of the buffer-local
6243         ;; variables as well, just to be on the safe side.
6244         (set-buffer gnus-group-buffer)
6245         (gnus-summary-clear-local-variables)
6246         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6247           (gnus-summary-clear-local-variables)))
6248       (setq gnus-current-select-method gnus-select-method)
6249       (pop-to-buffer gnus-group-buffer)
6250       (if (not quit-config)
6251           (progn
6252             (goto-char group-point)
6253             (gnus-configure-windows 'group 'force)
6254             (unless (pos-visible-in-window-p)
6255               (forward-line (/ (static-if (featurep 'xemacs)
6256                                    (window-displayed-height)
6257                                  (1- (window-height)))
6258                                -2))
6259               (set-window-start (selected-window) (point))
6260               (goto-char group-point)))
6261         (gnus-handle-ephemeral-exit quit-config))
6262       ;; Return to group mode buffer.
6263       (when (eq mode 'gnus-summary-mode)
6264         (gnus-kill-buffer buf))
6265       ;; Clear the current group name.
6266       (unless quit-config
6267         (setq gnus-newsgroup-name nil)))))
6268
6269 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6270 (defun gnus-summary-exit-no-update (&optional no-questions)
6271   "Quit reading current newsgroup without updating read article info."
6272   (interactive)
6273   (let* ((group gnus-newsgroup-name)
6274          (quit-config (gnus-group-quit-config group)))
6275     (when (or no-questions
6276               gnus-expert-user
6277               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6278       (gnus-async-halt-prefetch)
6279       (mapcar 'funcall
6280               (delq 'gnus-summary-expire-articles
6281                     (copy-sequence gnus-summary-prepare-exit-hook)))
6282       ;; If we have several article buffers, we kill them at exit.
6283       (unless gnus-single-article-buffer
6284         (gnus-kill-buffer gnus-article-buffer)
6285         (gnus-kill-buffer gnus-original-article-buffer)
6286         (setq gnus-article-current nil))
6287       (if (not gnus-kill-summary-on-exit)
6288           (gnus-deaden-summary)
6289         (gnus-close-group group)
6290         (gnus-summary-clear-local-variables)
6291         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6292           (gnus-summary-clear-local-variables))
6293         (set-buffer gnus-group-buffer)
6294         (gnus-summary-clear-local-variables)
6295         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6296           (gnus-summary-clear-local-variables))
6297         (when (get-buffer gnus-summary-buffer)
6298           (kill-buffer gnus-summary-buffer)))
6299       (unless gnus-single-article-buffer
6300         (setq gnus-article-current nil))
6301       (when gnus-use-trees
6302         (gnus-tree-close group))
6303       (gnus-async-prefetch-remove-group group)
6304       (when (get-buffer gnus-article-buffer)
6305         (bury-buffer gnus-article-buffer))
6306       ;; Return to the group buffer.
6307       (gnus-configure-windows 'group 'force)
6308       ;; Clear the current group name.
6309       (setq gnus-newsgroup-name nil)
6310       (when (equal (gnus-group-group-name) group)
6311         (gnus-group-next-unread-group 1))
6312       (when quit-config
6313         (gnus-handle-ephemeral-exit quit-config)))))
6314
6315 (defun gnus-handle-ephemeral-exit (quit-config)
6316   "Handle movement when leaving an ephemeral group.
6317 The state which existed when entering the ephemeral is reset."
6318   (if (not (buffer-name (car quit-config)))
6319       (gnus-configure-windows 'group 'force)
6320     (set-buffer (car quit-config))
6321     (cond ((eq major-mode 'gnus-summary-mode)
6322            (gnus-set-global-variables))
6323           ((eq major-mode 'gnus-article-mode)
6324            (save-excursion
6325              ;; The `gnus-summary-buffer' variable may point
6326              ;; to the old summary buffer when using a single
6327              ;; article buffer.
6328              (unless (gnus-buffer-live-p gnus-summary-buffer)
6329                (set-buffer gnus-group-buffer))
6330              (set-buffer gnus-summary-buffer)
6331              (gnus-set-global-variables))))
6332     (if (or (eq (cdr quit-config) 'article)
6333             (eq (cdr quit-config) 'pick))
6334         (progn
6335           ;; The current article may be from the ephemeral group
6336           ;; thus it is best that we reload this article
6337           (gnus-summary-show-article)
6338           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6339               (gnus-configure-windows 'pick 'force)
6340             (gnus-configure-windows (cdr quit-config) 'force)))
6341       (gnus-configure-windows (cdr quit-config) 'force))
6342     (when (eq major-mode 'gnus-summary-mode)
6343       (gnus-summary-next-subject 1 nil t)
6344       (gnus-summary-recenter)
6345       (gnus-summary-position-point))))
6346
6347 (defun gnus-summary-preview-mime-message ()
6348   "MIME decode and play this message."
6349   (interactive)
6350   (let ((gnus-break-pages nil)
6351         (gnus-show-mime t))
6352     (gnus-summary-select-article gnus-show-all-headers t))
6353   (let ((w (get-buffer-window gnus-article-buffer)))
6354     (when w
6355       (select-window (get-buffer-window gnus-article-buffer)))))
6356
6357 ;;; Dead summaries.
6358
6359 (defvar gnus-dead-summary-mode-map nil)
6360
6361 (unless gnus-dead-summary-mode-map
6362   (setq gnus-dead-summary-mode-map (make-keymap))
6363   (suppress-keymap gnus-dead-summary-mode-map)
6364   (substitute-key-definition
6365    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6366   (dolist (key '("\C-d" "\r" "\177" [delete]))
6367     (define-key gnus-dead-summary-mode-map
6368       key 'gnus-summary-wake-up-the-dead))
6369   (dolist (key '("q" "Q"))
6370     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6371
6372 (defvar gnus-dead-summary-mode nil
6373   "Minor mode for Gnus summary buffers.")
6374
6375 (defun gnus-dead-summary-mode (&optional arg)
6376   "Minor mode for Gnus summary buffers."
6377   (interactive "P")
6378   (when (eq major-mode 'gnus-summary-mode)
6379     (make-local-variable 'gnus-dead-summary-mode)
6380     (setq gnus-dead-summary-mode
6381           (if (null arg) (not gnus-dead-summary-mode)
6382             (> (prefix-numeric-value arg) 0)))
6383     (when gnus-dead-summary-mode
6384       (gnus-add-minor-mode
6385        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6386
6387 (defun gnus-deaden-summary ()
6388   "Make the current summary buffer into a dead summary buffer."
6389   ;; Kill any previous dead summary buffer.
6390   (when (and gnus-dead-summary
6391              (buffer-name gnus-dead-summary))
6392     (save-excursion
6393       (set-buffer gnus-dead-summary)
6394       (when gnus-dead-summary-mode
6395         (kill-buffer (current-buffer)))))
6396   ;; Make this the current dead summary.
6397   (setq gnus-dead-summary (current-buffer))
6398   (gnus-dead-summary-mode 1)
6399   (let ((name (buffer-name)))
6400     (when (string-match "Summary" name)
6401       (rename-buffer
6402        (concat (substring name 0 (match-beginning 0)) "Dead "
6403                (substring name (match-beginning 0)))
6404        t)
6405       (bury-buffer))))
6406
6407 (defun gnus-kill-or-deaden-summary (buffer)
6408   "Kill or deaden the summary BUFFER."
6409   (save-excursion
6410     (when (and (buffer-name buffer)
6411                (not gnus-single-article-buffer))
6412       (save-excursion
6413         (set-buffer buffer)
6414         (gnus-kill-buffer gnus-article-buffer)
6415         (gnus-kill-buffer gnus-original-article-buffer)))
6416     (cond
6417      ;; Kill the buffer.
6418      (gnus-kill-summary-on-exit
6419       (when (and gnus-use-trees
6420                  (gnus-buffer-exists-p buffer))
6421         (save-excursion
6422           (set-buffer buffer)
6423           (gnus-tree-close gnus-newsgroup-name)))
6424       (gnus-kill-buffer buffer))
6425      ;; Deaden the buffer.
6426      ((gnus-buffer-exists-p buffer)
6427       (save-excursion
6428         (set-buffer buffer)
6429         (gnus-deaden-summary))))))
6430
6431 (defun gnus-summary-wake-up-the-dead (&rest args)
6432   "Wake up the dead summary buffer."
6433   (interactive)
6434   (gnus-dead-summary-mode -1)
6435   (let ((name (buffer-name)))
6436     (when (string-match "Dead " name)
6437       (rename-buffer
6438        (concat (substring name 0 (match-beginning 0))
6439                (substring name (match-end 0)))
6440        t)))
6441   (gnus-message 3 "This dead summary is now alive again"))
6442
6443 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6444 (defun gnus-summary-fetch-faq (&optional faq-dir)
6445   "Fetch the FAQ for the current group.
6446 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6447 in."
6448   (interactive
6449    (list
6450     (when current-prefix-arg
6451       (completing-read
6452        "Faq dir: " (and (listp gnus-group-faq-directory)
6453                         (mapcar (lambda (file) (list file))
6454                                 gnus-group-faq-directory))))))
6455   (let (gnus-faq-buffer)
6456     (when (setq gnus-faq-buffer
6457                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6458       (gnus-configure-windows 'summary-faq))))
6459
6460 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6461 (defun gnus-summary-describe-group (&optional force)
6462   "Describe the current newsgroup."
6463   (interactive "P")
6464   (gnus-group-describe-group force gnus-newsgroup-name))
6465
6466 (defun gnus-summary-describe-briefly ()
6467   "Describe summary mode commands briefly."
6468   (interactive)
6469   (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")))
6470
6471 ;; Walking around group mode buffer from summary mode.
6472
6473 (defun gnus-summary-next-group (&optional no-article target-group backward)
6474   "Exit current newsgroup and then select next unread newsgroup.
6475 If prefix argument NO-ARTICLE is non-nil, no article is selected
6476 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6477 previous group instead."
6478   (interactive "P")
6479   ;; Stop pre-fetching.
6480   (gnus-async-halt-prefetch)
6481   (let ((current-group gnus-newsgroup-name)
6482         (current-buffer (current-buffer))
6483         entered)
6484     ;; First we semi-exit this group to update Xrefs and all variables.
6485     ;; We can't do a real exit, because the window conf must remain
6486     ;; the same in case the user is prompted for info, and we don't
6487     ;; want the window conf to change before that...
6488     (gnus-summary-exit t)
6489     (while (not entered)
6490       ;; Then we find what group we are supposed to enter.
6491       (set-buffer gnus-group-buffer)
6492       (gnus-group-jump-to-group current-group)
6493       (setq target-group
6494             (or target-group
6495                 (if (eq gnus-keep-same-level 'best)
6496                     (gnus-summary-best-group gnus-newsgroup-name)
6497                   (gnus-summary-search-group backward gnus-keep-same-level))))
6498       (if (not target-group)
6499           ;; There are no further groups, so we return to the group
6500           ;; buffer.
6501           (progn
6502             (gnus-message 5 "Returning to the group buffer")
6503             (setq entered t)
6504             (when (gnus-buffer-live-p current-buffer)
6505               (set-buffer current-buffer)
6506               (gnus-summary-exit))
6507             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6508         ;; We try to enter the target group.
6509         (gnus-group-jump-to-group target-group)
6510         (let ((unreads (gnus-group-group-unread)))
6511           (if (and (or (eq t unreads)
6512                        (and unreads (not (zerop unreads))))
6513                    (gnus-summary-read-group
6514                     target-group nil no-article
6515                     (and (buffer-name current-buffer) current-buffer)
6516                     nil backward))
6517               (setq entered t)
6518             (setq current-group target-group
6519                   target-group nil)))))))
6520
6521 (defun gnus-summary-prev-group (&optional no-article)
6522   "Exit current newsgroup and then select previous unread newsgroup.
6523 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6524   (interactive "P")
6525   (gnus-summary-next-group no-article nil t))
6526
6527 ;; Walking around summary lines.
6528
6529 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6530   "Go to the first unread subject.
6531 If UNREAD is non-nil, go to the first unread article.
6532 Returns the article selected or nil if there are no unread articles."
6533   (interactive "P")
6534   (prog1
6535       (cond
6536        ;; Empty summary.
6537        ((null gnus-newsgroup-data)
6538         (gnus-message 3 "No articles in the group")
6539         nil)
6540        ;; Pick the first article.
6541        ((not unread)
6542         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6543         (gnus-data-number (car gnus-newsgroup-data)))
6544        ;; No unread articles.
6545        ((null gnus-newsgroup-unreads)
6546         (gnus-message 3 "No more unread articles")
6547         nil)
6548        ;; Find the first unread article.
6549        (t
6550         (let ((data gnus-newsgroup-data))
6551           (while (and data
6552                       (and (not (and undownloaded
6553                                      (eq gnus-undownloaded-mark
6554                                          (gnus-data-mark (car data)))))
6555                            (if unseen
6556                                (or (not (memq
6557                                          (gnus-data-number (car data))
6558                                          gnus-newsgroup-unseen))
6559                                    (not (gnus-data-unread-p (car data))))
6560                              (not (gnus-data-unread-p (car data))))))
6561             (setq data (cdr data)))
6562           (when data
6563             (goto-char (gnus-data-pos (car data)))
6564             (gnus-data-number (car data))))))
6565     (gnus-summary-position-point)))
6566
6567 (defun gnus-summary-next-subject (n &optional unread dont-display)
6568   "Go to next N'th summary line.
6569 If N is negative, go to the previous N'th subject line.
6570 If UNREAD is non-nil, only unread articles are selected.
6571 The difference between N and the actual number of steps taken is
6572 returned."
6573   (interactive "p")
6574   (let ((backward (< n 0))
6575         (n (abs n)))
6576     (while (and (> n 0)
6577                 (if backward
6578                     (gnus-summary-find-prev unread)
6579                   (gnus-summary-find-next unread)))
6580       (unless (zerop (setq n (1- n)))
6581         (gnus-summary-show-thread)))
6582     (when (/= 0 n)
6583       (gnus-message 7 "No more%s articles"
6584                     (if unread " unread" "")))
6585     (unless dont-display
6586       (gnus-summary-recenter)
6587       (gnus-summary-position-point))
6588     n))
6589
6590 (defun gnus-summary-next-unread-subject (n)
6591   "Go to next N'th unread summary line."
6592   (interactive "p")
6593   (gnus-summary-next-subject n t))
6594
6595 (defun gnus-summary-prev-subject (n &optional unread)
6596   "Go to previous N'th summary line.
6597 If optional argument UNREAD is non-nil, only unread article is selected."
6598   (interactive "p")
6599   (gnus-summary-next-subject (- n) unread))
6600
6601 (defun gnus-summary-prev-unread-subject (n)
6602   "Go to previous N'th unread summary line."
6603   (interactive "p")
6604   (gnus-summary-next-subject (- n) t))
6605
6606 (defun gnus-summary-goto-subject (article &optional force silent)
6607   "Go the subject line of ARTICLE.
6608 If FORCE, also allow jumping to articles not currently shown."
6609   (interactive "nArticle number: ")
6610   (unless (numberp article)
6611     (error "Article %s is not a number" article))
6612   (let ((b (point))
6613         (data (gnus-data-find article)))
6614     ;; We read in the article if we have to.
6615     (and (not data)
6616          force
6617          (gnus-summary-insert-subject
6618           article
6619           (if (or (numberp force) (vectorp force)) force)
6620           t)
6621          (setq data (gnus-data-find article)))
6622     (goto-char b)
6623     (if (not data)
6624         (progn
6625           (unless silent
6626             (gnus-message 3 "Can't find article %d" article))
6627           nil)
6628       (let ((pt (gnus-data-pos data)))
6629         (goto-char pt)
6630         (gnus-summary-set-article-display-arrow pt))
6631       (gnus-summary-position-point)
6632       article)))
6633
6634 ;; Walking around summary lines with displaying articles.
6635
6636 (defun gnus-summary-expand-window (&optional arg)
6637   "Make the summary buffer take up the entire Emacs frame.
6638 Given a prefix, will force an `article' buffer configuration."
6639   (interactive "P")
6640   (if arg
6641       (gnus-configure-windows 'article 'force)
6642     (gnus-configure-windows 'summary 'force)))
6643
6644 (defun gnus-summary-display-article (article &optional all-header)
6645   "Display ARTICLE in article buffer."
6646   (when (gnus-buffer-live-p gnus-article-buffer)
6647     (with-current-buffer gnus-article-buffer
6648       (set-buffer-multibyte t)))
6649   (gnus-set-global-variables)
6650   (when (gnus-buffer-live-p gnus-article-buffer)
6651     (with-current-buffer gnus-article-buffer
6652       (setq gnus-article-charset gnus-newsgroup-charset)
6653       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6654       (set-buffer-multibyte t)))
6655   (if (null article)
6656       nil
6657     (prog1
6658         (if gnus-summary-display-article-function
6659             (funcall gnus-summary-display-article-function article all-header)
6660           (gnus-article-prepare article all-header))
6661       (with-current-buffer gnus-article-buffer
6662         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6663              nil))
6664       (gnus-run-hooks 'gnus-select-article-hook)
6665       (when (and gnus-current-article
6666                  (not (zerop gnus-current-article)))
6667         (gnus-summary-goto-subject gnus-current-article))
6668       (gnus-summary-recenter)
6669       (when (and gnus-use-trees gnus-show-threads)
6670         (gnus-possibly-generate-tree article)
6671         (gnus-highlight-selected-tree article))
6672       ;; Successfully display article.
6673       (gnus-article-set-window-start
6674        (cdr (assq article gnus-newsgroup-bookmarks))))))
6675
6676 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6677   "Select the current article.
6678 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6679 non-nil, the article will be re-fetched even if it already present in
6680 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6681 be displayed."
6682   ;; Make sure we are in the summary buffer to work around bbdb bug.
6683   (unless (eq major-mode 'gnus-summary-mode)
6684     (set-buffer gnus-summary-buffer))
6685   (let ((article (or article (gnus-summary-article-number)))
6686         (all-headers (not (not all-headers))) ;Must be T or NIL.
6687         gnus-summary-display-article-function)
6688     (and (not pseudo)
6689          (gnus-summary-article-pseudo-p article)
6690          (error "This is a pseudo-article"))
6691     (save-excursion
6692       (set-buffer gnus-summary-buffer)
6693       (if (or (and gnus-single-article-buffer
6694                    (or (null gnus-current-article)
6695                        (null gnus-article-current)
6696                        (null (get-buffer gnus-article-buffer))
6697                        (not (eq article (cdr gnus-article-current)))
6698                        (not (equal (car gnus-article-current)
6699                                    gnus-newsgroup-name))))
6700               (and (not gnus-single-article-buffer)
6701                    (or (null gnus-current-article)
6702                        (not (eq gnus-current-article article))))
6703               force)
6704           ;; The requested article is different from the current article.
6705           (progn
6706             (gnus-summary-display-article article all-headers)
6707             (gnus-article-set-window-start
6708              (cdr (assq article gnus-newsgroup-bookmarks)))
6709             article)
6710         'old))))
6711
6712 (defun gnus-summary-force-verify-and-decrypt ()
6713   (interactive)
6714   (let ((mm-verify-option 'known)
6715         (mm-decrypt-option 'known)
6716         (gnus-buttonized-mime-types (append (list "multipart/signed"
6717                                                   "multipart/encrypted")
6718                                             gnus-buttonized-mime-types)))
6719     (gnus-summary-select-article nil 'force)))
6720
6721 (defun gnus-summary-set-current-mark (&optional current-mark)
6722   "Obsolete function."
6723   nil)
6724
6725 (defun gnus-summary-next-article (&optional unread subject backward push)
6726   "Select the next article.
6727 If UNREAD, only unread articles are selected.
6728 If SUBJECT, only articles with SUBJECT are selected.
6729 If BACKWARD, the previous article is selected instead of the next."
6730   (interactive "P")
6731   (cond
6732    ;; Is there such an article?
6733    ((and (gnus-summary-search-forward unread subject backward)
6734          (or (gnus-summary-display-article (gnus-summary-article-number))
6735              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6736     (gnus-summary-position-point))
6737    ;; If not, we try the first unread, if that is wanted.
6738    ((and subject
6739          gnus-auto-select-same
6740          (gnus-summary-first-unread-article))
6741     (gnus-summary-position-point)
6742     (gnus-message 6 "Wrapped"))
6743    ;; Try to get next/previous article not displayed in this group.
6744    ((and gnus-auto-extend-newsgroup
6745          (not unread) (not subject))
6746     (gnus-summary-goto-article
6747      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6748      nil (count-lines (point-min) (point))))
6749    ;; Go to next/previous group.
6750    (t
6751     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6752       (gnus-summary-jump-to-group gnus-newsgroup-name))
6753     (let ((cmd last-command-char)
6754           (point
6755            (save-excursion
6756              (set-buffer gnus-group-buffer)
6757              (point)))
6758           (group
6759            (if (eq gnus-keep-same-level 'best)
6760                (gnus-summary-best-group gnus-newsgroup-name)
6761              (gnus-summary-search-group backward gnus-keep-same-level))))
6762       ;; For some reason, the group window gets selected.  We change
6763       ;; it back.
6764       (select-window (get-buffer-window (current-buffer)))
6765       ;; Select next unread newsgroup automagically.
6766       (cond
6767        ((or (not gnus-auto-select-next)
6768             (not cmd))
6769         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6770        ((or (eq gnus-auto-select-next 'quietly)
6771             (and (eq gnus-auto-select-next 'slightly-quietly)
6772                  push)
6773             (and (eq gnus-auto-select-next 'almost-quietly)
6774                  (gnus-summary-last-article-p)))
6775         ;; Select quietly.
6776         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6777             (gnus-summary-exit)
6778           (gnus-message 7 "No more%s articles (%s)..."
6779                         (if unread " unread" "")
6780                         (if group (concat "selecting " group)
6781                           "exiting"))
6782           (gnus-summary-next-group nil group backward)))
6783        (t
6784         (when (gnus-key-press-event-p last-input-event)
6785           (gnus-summary-walk-group-buffer
6786            gnus-newsgroup-name cmd unread backward point))))))))
6787
6788 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6789   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6790                       (?\C-p (gnus-group-prev-unread-group 1))))
6791         (cursor-in-echo-area t)
6792         keve key group ended)
6793     (save-excursion
6794       (set-buffer gnus-group-buffer)
6795       (goto-char start)
6796       (setq group
6797             (if (eq gnus-keep-same-level 'best)
6798                 (gnus-summary-best-group gnus-newsgroup-name)
6799               (gnus-summary-search-group backward gnus-keep-same-level))))
6800     (while (not ended)
6801       (gnus-message
6802        5 "No more%s articles%s" (if unread " unread" "")
6803        (if (and group
6804                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6805            (format " (Type %s for %s [%s])"
6806                    (single-key-description cmd) group
6807                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6808          (format " (Type %s to exit %s)"
6809                  (single-key-description cmd)
6810                  gnus-newsgroup-name)))
6811       ;; Confirm auto selection.
6812       (setq key (car (setq keve (gnus-read-event-char))))
6813       (setq ended t)
6814       (cond
6815        ((assq key keystrokes)
6816         (let ((obuf (current-buffer)))
6817           (switch-to-buffer gnus-group-buffer)
6818           (when group
6819             (gnus-group-jump-to-group group))
6820           (eval (cadr (assq key keystrokes)))
6821           (setq group (gnus-group-group-name))
6822           (switch-to-buffer obuf))
6823         (setq ended nil))
6824        ((equal key cmd)
6825         (if (or (not group)
6826                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6827             (gnus-summary-exit)
6828           (gnus-summary-next-group nil group backward)))
6829        (t
6830         (push (cdr keve) unread-command-events))))))
6831
6832 (defun gnus-summary-next-unread-article ()
6833   "Select unread article after current one."
6834   (interactive)
6835   (gnus-summary-next-article
6836    (or (not (eq gnus-summary-goto-unread 'never))
6837        (gnus-summary-last-article-p (gnus-summary-article-number)))
6838    (and gnus-auto-select-same
6839         (gnus-summary-article-subject))))
6840
6841 (defun gnus-summary-prev-article (&optional unread subject)
6842   "Select the article after the current one.
6843 If UNREAD is non-nil, only unread articles are selected."
6844   (interactive "P")
6845   (gnus-summary-next-article unread subject t))
6846
6847 (defun gnus-summary-prev-unread-article ()
6848   "Select unread article before current one."
6849   (interactive)
6850   (gnus-summary-prev-article
6851    (or (not (eq gnus-summary-goto-unread 'never))
6852        (gnus-summary-first-article-p (gnus-summary-article-number)))
6853    (and gnus-auto-select-same
6854         (gnus-summary-article-subject))))
6855
6856 (defun gnus-summary-next-page (&optional lines circular)
6857   "Show next page of the selected article.
6858 If at the end of the current article, select the next article.
6859 LINES says how many lines should be scrolled up.
6860
6861 If CIRCULAR is non-nil, go to the start of the article instead of
6862 selecting the next article when reaching the end of the current
6863 article."
6864   (interactive "P")
6865   (setq gnus-summary-buffer (current-buffer))
6866   (gnus-set-global-variables)
6867   (let ((article (gnus-summary-article-number))
6868         (article-window (get-buffer-window gnus-article-buffer t))
6869         endp)
6870     ;; If the buffer is empty, we have no article.
6871     (unless article
6872       (error "No article to select"))
6873     (gnus-configure-windows 'article)
6874     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6875         (if (and (eq gnus-summary-goto-unread 'never)
6876                  (not (gnus-summary-last-article-p article)))
6877             (gnus-summary-next-article)
6878           (gnus-summary-next-unread-article))
6879       (if (or (null gnus-current-article)
6880               (null gnus-article-current)
6881               (/= article (cdr gnus-article-current))
6882               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6883           ;; Selected subject is different from current article's.
6884           (gnus-summary-display-article article)
6885         (when article-window
6886           (gnus-eval-in-buffer-window gnus-article-buffer
6887             (setq endp (gnus-article-next-page lines)))
6888           (when endp
6889             (cond (circular
6890                    (gnus-summary-beginning-of-article))
6891                   (lines
6892                    (gnus-message 3 "End of message"))
6893                   ((null lines)
6894                    (if (and (eq gnus-summary-goto-unread 'never)
6895                             (not (gnus-summary-last-article-p article)))
6896                        (gnus-summary-next-article)
6897                      (gnus-summary-next-unread-article))))))))
6898     (gnus-summary-recenter)
6899     (gnus-summary-position-point)))
6900
6901 (defun gnus-summary-prev-page (&optional lines move)
6902   "Show previous page of selected article.
6903 Argument LINES specifies lines to be scrolled down.
6904 If MOVE, move to the previous unread article if point is at
6905 the beginning of the buffer."
6906   (interactive "P")
6907   (let ((article (gnus-summary-article-number))
6908         (article-window (get-buffer-window gnus-article-buffer t))
6909         endp)
6910     (gnus-configure-windows 'article)
6911     (if (or (null gnus-current-article)
6912             (null gnus-article-current)
6913             (/= article (cdr gnus-article-current))
6914             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6915         ;; Selected subject is different from current article's.
6916         (gnus-summary-display-article article)
6917       (gnus-summary-recenter)
6918       (when article-window
6919         (gnus-eval-in-buffer-window gnus-article-buffer
6920           (setq endp (gnus-article-prev-page lines)))
6921         (when (and move endp)
6922           (cond (lines
6923                  (gnus-message 3 "Beginning of message"))
6924                 ((null lines)
6925                  (if (and (eq gnus-summary-goto-unread 'never)
6926                           (not (gnus-summary-first-article-p article)))
6927                      (gnus-summary-prev-article)
6928                    (gnus-summary-prev-unread-article))))))))
6929   (gnus-summary-position-point))
6930
6931 (defun gnus-summary-prev-page-or-article (&optional lines)
6932   "Show previous page of selected article.
6933 Argument LINES specifies lines to be scrolled down.
6934 If at the beginning of the article, go to the next article."
6935   (interactive "P")
6936   (gnus-summary-prev-page lines t))
6937
6938 (defun gnus-summary-scroll-up (lines)
6939   "Scroll up (or down) one line current article.
6940 Argument LINES specifies lines to be scrolled up (or down if negative)."
6941   (interactive "p")
6942   (gnus-configure-windows 'article)
6943   (gnus-summary-show-thread)
6944   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6945     (gnus-eval-in-buffer-window gnus-article-buffer
6946       (cond ((> lines 0)
6947              (when (gnus-article-next-page lines)
6948                (gnus-message 3 "End of message")))
6949             ((< lines 0)
6950              (gnus-article-prev-page (- lines))))))
6951   (gnus-summary-recenter)
6952   (gnus-summary-position-point))
6953
6954 (defun gnus-summary-scroll-down (lines)
6955   "Scroll down (or up) one line current article.
6956 Argument LINES specifies lines to be scrolled down (or up if negative)."
6957   (interactive "p")
6958   (gnus-summary-scroll-up (- lines)))
6959
6960 (defun gnus-summary-next-same-subject ()
6961   "Select next article which has the same subject as current one."
6962   (interactive)
6963   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6964
6965 (defun gnus-summary-prev-same-subject ()
6966   "Select previous article which has the same subject as current one."
6967   (interactive)
6968   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6969
6970 (defun gnus-summary-next-unread-same-subject ()
6971   "Select next unread article which has the same subject as current one."
6972   (interactive)
6973   (gnus-summary-next-article t (gnus-summary-article-subject)))
6974
6975 (defun gnus-summary-prev-unread-same-subject ()
6976   "Select previous unread article which has the same subject as current one."
6977   (interactive)
6978   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6979
6980 (defun gnus-summary-first-unread-article ()
6981   "Select the first unread article.
6982 Return nil if there are no unread articles."
6983   (interactive)
6984   (prog1
6985       (when (gnus-summary-first-subject t)
6986         (gnus-summary-show-thread)
6987         (gnus-summary-first-subject t)
6988         (gnus-summary-display-article (gnus-summary-article-number)))
6989     (gnus-summary-position-point)))
6990
6991 (defun gnus-summary-first-unread-subject ()
6992   "Place the point on the subject line of the first unread article.
6993 Return nil if there are no unread articles."
6994   (interactive)
6995   (prog1
6996       (when (gnus-summary-first-subject t)
6997         (gnus-summary-show-thread)
6998         (gnus-summary-first-subject t))
6999     (gnus-summary-position-point)))
7000
7001 (defun gnus-summary-first-unseen-subject ()
7002   "Place the point on the subject line of the first unseen article.
7003 Return nil if there are no unseen articles."
7004   (interactive)
7005   (prog1
7006       (when (gnus-summary-first-subject t t t)
7007         (gnus-summary-show-thread)
7008         (gnus-summary-first-subject t t t))
7009     (gnus-summary-position-point)))
7010
7011 (defun gnus-summary-first-unseen-or-unread-subject ()
7012   "Place the point on the subject line of the first unseen article.
7013 Return nil if there are no unseen articles."
7014   (interactive)
7015   (prog1
7016       (unless (when (gnus-summary-first-subject t t t)
7017                 (gnus-summary-show-thread)
7018                 (gnus-summary-first-subject t t t))
7019         (when (gnus-summary-first-subject t)
7020           (gnus-summary-show-thread)
7021           (gnus-summary-first-subject t)))
7022     (gnus-summary-position-point)))
7023
7024 (defun gnus-summary-first-article ()
7025   "Select the first article.
7026 Return nil if there are no articles."
7027   (interactive)
7028   (prog1
7029       (when (gnus-summary-first-subject)
7030         (gnus-summary-show-thread)
7031         (gnus-summary-first-subject)
7032         (gnus-summary-display-article (gnus-summary-article-number)))
7033     (gnus-summary-position-point)))
7034
7035 (defun gnus-summary-best-unread-article (&optional arg)
7036   "Select the unread article with the highest score.
7037 If given a prefix argument, select the next unread article that has a
7038 score higher than the default score."
7039   (interactive "P")
7040   (let ((article (if arg
7041                      (gnus-summary-better-unread-subject)
7042                    (gnus-summary-best-unread-subject))))
7043     (if article
7044         (gnus-summary-goto-article article)
7045       (error "No unread articles"))))
7046
7047 (defun gnus-summary-best-unread-subject ()
7048   "Select the unread subject with the highest score."
7049   (interactive)
7050   (let ((best -1000000)
7051         (data gnus-newsgroup-data)
7052         article score)
7053     (while data
7054       (and (gnus-data-unread-p (car data))
7055            (> (setq score
7056                     (gnus-summary-article-score (gnus-data-number (car data))))
7057               best)
7058            (setq best score
7059                  article (gnus-data-number (car data))))
7060       (setq data (cdr data)))
7061     (when article
7062       (gnus-summary-goto-subject article))
7063     (gnus-summary-position-point)
7064     article))
7065
7066 (defun gnus-summary-better-unread-subject ()
7067   "Select the first unread subject that has a score over the default score."
7068   (interactive)
7069   (let ((data gnus-newsgroup-data)
7070         article score)
7071     (while (and (setq article (gnus-data-number (car data)))
7072                 (or (gnus-data-read-p (car data))
7073                     (not (> (gnus-summary-article-score article)
7074                             gnus-summary-default-score))))
7075       (setq data (cdr data)))
7076     (when article
7077       (gnus-summary-goto-subject article))
7078     (gnus-summary-position-point)
7079     article))
7080
7081 (defun gnus-summary-last-subject ()
7082   "Go to the last displayed subject line in the group."
7083   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7084     (when article
7085       (gnus-summary-goto-subject article))))
7086
7087 (defun gnus-summary-goto-article (article &optional all-headers force)
7088   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7089 If ALL-HEADERS is non-nil, no header lines are hidden.
7090 If FORCE, go to the article even if it isn't displayed.  If FORCE
7091 is a number, it is the line the article is to be displayed on."
7092   (interactive
7093    (list
7094     (completing-read
7095      "Article number or Message-ID: "
7096      (mapcar (lambda (number) (list (int-to-string number)))
7097              gnus-newsgroup-limit))
7098     current-prefix-arg
7099     t))
7100   (prog1
7101       (if (and (stringp article)
7102                (string-match "@" article))
7103           (gnus-summary-refer-article article)
7104         (when (stringp article)
7105           (setq article (string-to-number article)))
7106         (if (gnus-summary-goto-subject article force)
7107             (gnus-summary-display-article article all-headers)
7108           (gnus-message 4 "Couldn't go to article %s" article) nil))
7109     (gnus-summary-position-point)))
7110
7111 (defun gnus-summary-goto-last-article ()
7112   "Go to the previously read article."
7113   (interactive)
7114   (prog1
7115       (when gnus-last-article
7116         (gnus-summary-goto-article gnus-last-article nil t))
7117     (gnus-summary-position-point)))
7118
7119 (defun gnus-summary-pop-article (number)
7120   "Pop one article off the history and go to the previous.
7121 NUMBER articles will be popped off."
7122   (interactive "p")
7123   (let (to)
7124     (setq gnus-newsgroup-history
7125           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7126     (if to
7127         (gnus-summary-goto-article (car to) nil t)
7128       (error "Article history empty")))
7129   (gnus-summary-position-point))
7130
7131 ;; Summary commands and functions for limiting the summary buffer.
7132
7133 (defun gnus-summary-limit-to-articles (n)
7134   "Limit the summary buffer to the next N articles.
7135 If not given a prefix, use the process marked articles instead."
7136   (interactive "P")
7137   (prog1
7138       (let ((articles (gnus-summary-work-articles n)))
7139         (setq gnus-newsgroup-processable nil)
7140         (gnus-summary-limit articles))
7141     (gnus-summary-position-point)))
7142
7143 (defun gnus-summary-pop-limit (&optional total)
7144   "Restore the previous limit.
7145 If given a prefix, remove all limits."
7146   (interactive "P")
7147   (when total
7148     (setq gnus-newsgroup-limits
7149           (list (mapcar (lambda (h) (mail-header-number h))
7150                         gnus-newsgroup-headers))))
7151   (unless gnus-newsgroup-limits
7152     (error "No limit to pop"))
7153   (prog1
7154       (gnus-summary-limit nil 'pop)
7155     (gnus-summary-position-point)))
7156
7157 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7158   "Limit the summary buffer to articles that have subjects that match a regexp.
7159 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7160   (interactive
7161    (list (read-string (if current-prefix-arg
7162                           "Exclude subject (regexp): "
7163                         "Limit to subject (regexp): "))
7164          nil current-prefix-arg))
7165   (unless header
7166     (setq header "subject"))
7167   (when (not (equal "" subject))
7168     (prog1
7169         (let ((articles (gnus-summary-find-matching
7170                          (or header "subject") subject 'all nil nil
7171                          not-matching)))
7172           (unless articles
7173             (error "Found no matches for \"%s\"" subject))
7174           (gnus-summary-limit articles))
7175       (gnus-summary-position-point))))
7176
7177 (defun gnus-summary-limit-to-author (from &optional not-matching)
7178   "Limit the summary buffer to articles that have authors that match a regexp.
7179 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7180   (interactive
7181    (list (read-string (if current-prefix-arg
7182                           "Exclude author (regexp): "
7183                         "Limit to author (regexp): "))
7184          current-prefix-arg))
7185   (gnus-summary-limit-to-subject from "from" not-matching))
7186
7187 (defun gnus-summary-limit-to-age (age &optional younger-p)
7188   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7189 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7190 articles that are younger than AGE days."
7191   (interactive
7192    (let ((younger current-prefix-arg)
7193          (days-got nil)
7194          days)
7195      (while (not days-got)
7196        (setq days (if younger
7197                       (read-string "Limit to articles within (in days): ")
7198                     (read-string "Limit to articles older than (in days): ")))
7199        (when (> (length days) 0)
7200          (setq days (read days)))
7201        (if (numberp days)
7202            (progn
7203              (setq days-got t)
7204              (if (< days 0)
7205                  (progn
7206                    (setq younger (not younger))
7207                    (setq days (* days -1)))))
7208          (message "Please enter a number.")
7209          (sleep-for 1)))
7210      (list days younger)))
7211   (prog1
7212       (let ((data gnus-newsgroup-data)
7213             (cutoff (days-to-time age))
7214             articles d date is-younger)
7215         (while (setq d (pop data))
7216           (when (and (vectorp (gnus-data-header d))
7217                      (setq date (mail-header-date (gnus-data-header d))))
7218             (setq is-younger (time-less-p
7219                               (time-since (condition-case ()
7220                                               (date-to-time date)
7221                                             (error '(0 0))))
7222                               cutoff))
7223             (when (if younger-p
7224                       is-younger
7225                     (not is-younger))
7226               (push (gnus-data-number d) articles))))
7227         (gnus-summary-limit (nreverse articles)))
7228     (gnus-summary-position-point)))
7229
7230 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7231   "Limit the summary buffer to articles that match an 'extra' header."
7232   (interactive
7233    (let ((header
7234           (intern
7235            (gnus-completing-read-with-default
7236             (symbol-name (car gnus-extra-headers))
7237             (if current-prefix-arg
7238                 "Exclude extra header:"
7239               "Limit extra header:")
7240             (mapcar (lambda (x)
7241                       (cons (symbol-name x) x))
7242                     gnus-extra-headers)
7243             nil
7244             t))))
7245      (list header
7246            (read-string (format "%s header %s (regexp): "
7247                                 (if current-prefix-arg "Exclude" "Limit to")
7248                                 header))
7249            current-prefix-arg)))
7250   (when (not (equal "" regexp))
7251     (prog1
7252         (let ((articles (gnus-summary-find-matching
7253                          (cons 'extra header) regexp 'all nil nil
7254                          not-matching)))
7255           (unless articles
7256             (error "Found no matches for \"%s\"" regexp))
7257           (gnus-summary-limit articles))
7258       (gnus-summary-position-point))))
7259
7260 (defun gnus-summary-limit-to-display-predicate ()
7261   "Limit the summary buffer to the predicated in the `display' group parameter."
7262   (interactive)
7263   (unless gnus-newsgroup-display
7264     (error "There is no `display' group parameter"))
7265   (let (articles)
7266     (dolist (number gnus-newsgroup-articles)
7267       (when (funcall gnus-newsgroup-display)
7268         (push number articles)))
7269     (gnus-summary-limit articles))
7270   (gnus-summary-position-point))
7271
7272 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7273 (make-obsolete
7274  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7275
7276 (defun gnus-summary-limit-to-unread (&optional all)
7277   "Limit the summary buffer to articles that are not marked as read.
7278 If ALL is non-nil, limit strictly to unread articles."
7279   (interactive "P")
7280   (if all
7281       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7282     (gnus-summary-limit-to-marks
7283      ;; Concat all the marks that say that an article is read and have
7284      ;; those removed.
7285      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7286            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7287            gnus-low-score-mark gnus-expirable-mark
7288            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7289            gnus-duplicate-mark gnus-souped-mark)
7290      'reverse)))
7291
7292 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7293 (make-obsolete 'gnus-summary-delete-marked-with
7294                'gnus-summary-limit-exclude-marks)
7295
7296 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7297   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7298 If REVERSE, limit the summary buffer to articles that are marked
7299 with MARKS.  MARKS can either be a string of marks or a list of marks.
7300 Returns how many articles were removed."
7301   (interactive "sMarks: ")
7302   (gnus-summary-limit-to-marks marks t))
7303
7304 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7305   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7306 If REVERSE (the prefix), limit the summary buffer to articles that are
7307 not marked with MARKS.  MARKS can either be a string of marks or a
7308 list of marks.
7309 Returns how many articles were removed."
7310   (interactive "sMarks: \nP")
7311   (prog1
7312       (let ((data gnus-newsgroup-data)
7313             (marks (if (listp marks) marks
7314                      (append marks nil))) ; Transform to list.
7315             articles)
7316         (while data
7317           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7318                   (memq (gnus-data-mark (car data)) marks))
7319             (push (gnus-data-number (car data)) articles))
7320           (setq data (cdr data)))
7321         (gnus-summary-limit articles))
7322     (gnus-summary-position-point)))
7323
7324 (defun gnus-summary-limit-to-score (score)
7325   "Limit to articles with score at or above SCORE."
7326   (interactive "NLimit to articles with score of at least: ")
7327   (let ((data gnus-newsgroup-data)
7328         articles)
7329     (while data
7330       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7331                 score)
7332         (push (gnus-data-number (car data)) articles))
7333       (setq data (cdr data)))
7334     (prog1
7335         (gnus-summary-limit articles)
7336       (gnus-summary-position-point))))
7337
7338 (defun gnus-summary-limit-include-thread (id)
7339   "Display all the hidden articles that is in the thread with ID in it.
7340 When called interactively, ID is the Message-ID of the current
7341 article."
7342   (interactive (list (mail-header-id (gnus-summary-article-header))))
7343   (let ((articles (gnus-articles-in-thread
7344                    (gnus-id-to-thread (gnus-root-id id)))))
7345     (prog1
7346         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7347       (gnus-summary-limit-include-matching-articles
7348        "subject"
7349        (regexp-quote (gnus-simplify-subject-re
7350                       (mail-header-subject (gnus-id-to-header id)))))
7351       (gnus-summary-position-point))))
7352
7353 (defun gnus-summary-limit-include-matching-articles (header regexp)
7354   "Display all the hidden articles that have HEADERs that match REGEXP."
7355   (interactive (list (read-string "Match on header: ")
7356                      (read-string "Regexp: ")))
7357   (let ((articles (gnus-find-matching-articles header regexp)))
7358     (prog1
7359         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7360       (gnus-summary-position-point))))
7361
7362 (defun gnus-summary-limit-include-dormant ()
7363   "Display all the hidden articles that are marked as dormant.
7364 Note that this command only works on a subset of the articles currently
7365 fetched for this group."
7366   (interactive)
7367   (unless gnus-newsgroup-dormant
7368     (error "There are no dormant articles in this group"))
7369   (prog1
7370       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7371     (gnus-summary-position-point)))
7372
7373 (defun gnus-summary-limit-exclude-dormant ()
7374   "Hide all dormant articles."
7375   (interactive)
7376   (prog1
7377       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7378     (gnus-summary-position-point)))
7379
7380 (defun gnus-summary-limit-exclude-childless-dormant ()
7381   "Hide all dormant articles that have no children."
7382   (interactive)
7383   (let ((data (gnus-data-list t))
7384         articles d children)
7385     ;; Find all articles that are either not dormant or have
7386     ;; children.
7387     (while (setq d (pop data))
7388       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7389                 (and (setq children
7390                            (gnus-article-children (gnus-data-number d)))
7391                      (let (found)
7392                        (while children
7393                          (when (memq (car children) articles)
7394                            (setq children nil
7395                                  found t))
7396                          (pop children))
7397                        found)))
7398         (push (gnus-data-number d) articles)))
7399     ;; Do the limiting.
7400     (prog1
7401         (gnus-summary-limit articles)
7402       (gnus-summary-position-point))))
7403
7404 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7405   "Mark all unread excluded articles as read.
7406 If ALL, mark even excluded ticked and dormants as read."
7407   (interactive "P")
7408   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7409   (let ((articles (gnus-sorted-ndifference
7410                    (sort
7411                     (mapcar (lambda (h) (mail-header-number h))
7412                             gnus-newsgroup-headers)
7413                     '<)
7414                    gnus-newsgroup-limit))
7415         article)
7416     (setq gnus-newsgroup-unreads
7417           (gnus-sorted-intersection gnus-newsgroup-unreads
7418                                     gnus-newsgroup-limit))
7419     (if all
7420         (setq gnus-newsgroup-dormant nil
7421               gnus-newsgroup-marked nil
7422               gnus-newsgroup-reads
7423               (nconc
7424                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7425                gnus-newsgroup-reads))
7426       (while (setq article (pop articles))
7427         (unless (or (memq article gnus-newsgroup-dormant)
7428                     (memq article gnus-newsgroup-marked))
7429           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7430
7431 (defun gnus-summary-limit (articles &optional pop)
7432   (if pop
7433       ;; We pop the previous limit off the stack and use that.
7434       (setq articles (car gnus-newsgroup-limits)
7435             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7436     ;; We use the new limit, so we push the old limit on the stack.
7437     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7438   ;; Set the limit.
7439   (setq gnus-newsgroup-limit articles)
7440   (let ((total (length gnus-newsgroup-data))
7441         (data (gnus-data-find-list (gnus-summary-article-number)))
7442         (gnus-summary-mark-below nil)   ; Inhibit this.
7443         found)
7444     ;; This will do all the work of generating the new summary buffer
7445     ;; according to the new limit.
7446     (gnus-summary-prepare)
7447     ;; Hide any threads, possibly.
7448     (gnus-summary-maybe-hide-threads)
7449     ;; Try to return to the article you were at, or one in the
7450     ;; neighborhood.
7451     (when data
7452       ;; We try to find some article after the current one.
7453       (while data
7454         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7455           (setq data nil
7456                 found t))
7457         (setq data (cdr data))))
7458     (unless found
7459       ;; If there is no data, that means that we were after the last
7460       ;; article.  The same goes when we can't find any articles
7461       ;; after the current one.
7462       (goto-char (point-max))
7463       (gnus-summary-find-prev))
7464     (gnus-set-mode-line 'summary)
7465     ;; We return how many articles were removed from the summary
7466     ;; buffer as a result of the new limit.
7467     (- total (length gnus-newsgroup-data))))
7468
7469 (defsubst gnus-invisible-cut-children (threads)
7470   (let ((num 0))
7471     (while threads
7472       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7473         (incf num))
7474       (pop threads))
7475     (< num 2)))
7476
7477 (defsubst gnus-cut-thread (thread)
7478   "Go forwards in the thread until we find an article that we want to display."
7479   (when (or (eq gnus-fetch-old-headers 'some)
7480             (eq gnus-fetch-old-headers 'invisible)
7481             (numberp gnus-fetch-old-headers)
7482             (eq gnus-build-sparse-threads 'some)
7483             (eq gnus-build-sparse-threads 'more))
7484     ;; Deal with old-fetched headers and sparse threads.
7485     (while (and
7486             thread
7487             (or
7488              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7489              (gnus-summary-article-ancient-p
7490               (mail-header-number (car thread))))
7491             (if (or (<= (length (cdr thread)) 1)
7492                     (eq gnus-fetch-old-headers 'invisible))
7493                 (setq gnus-newsgroup-limit
7494                       (delq (mail-header-number (car thread))
7495                             gnus-newsgroup-limit)
7496                       thread (cadr thread))
7497               (when (gnus-invisible-cut-children (cdr thread))
7498                 (let ((th (cdr thread)))
7499                   (while th
7500                     (if (memq (mail-header-number (caar th))
7501                               gnus-newsgroup-limit)
7502                         (setq thread (car th)
7503                               th nil)
7504                       (setq th (cdr th))))))))))
7505   thread)
7506
7507 (defun gnus-cut-threads (threads)
7508   "Cut off all uninteresting articles from the beginning of threads."
7509   (when (or (eq gnus-fetch-old-headers 'some)
7510             (eq gnus-fetch-old-headers 'invisible)
7511             (numberp gnus-fetch-old-headers)
7512             (eq gnus-build-sparse-threads 'some)
7513             (eq gnus-build-sparse-threads 'more))
7514     (let ((th threads))
7515       (while th
7516         (setcar th (gnus-cut-thread (car th)))
7517         (setq th (cdr th)))))
7518   ;; Remove nixed out threads.
7519   (delq nil threads))
7520
7521 (defun gnus-summary-initial-limit (&optional show-if-empty)
7522   "Figure out what the initial limit is supposed to be on group entry.
7523 This entails weeding out unwanted dormants, low-scored articles,
7524 fetch-old-headers verbiage, and so on."
7525   ;; Most groups have nothing to remove.
7526   (if (or gnus-inhibit-limiting
7527           (and (null gnus-newsgroup-dormant)
7528                (eq gnus-newsgroup-display 'gnus-not-ignore)
7529                (not (eq gnus-fetch-old-headers 'some))
7530                (not (numberp gnus-fetch-old-headers))
7531                (not (eq gnus-fetch-old-headers 'invisible))
7532                (null gnus-summary-expunge-below)
7533                (not (eq gnus-build-sparse-threads 'some))
7534                (not (eq gnus-build-sparse-threads 'more))
7535                (null gnus-thread-expunge-below)
7536                (not gnus-use-nocem)))
7537       ()                                ; Do nothing.
7538     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7539     (setq gnus-newsgroup-limit nil)
7540     (mapatoms
7541      (lambda (node)
7542        (unless (car (symbol-value node))
7543          ;; These threads have no parents -- they are roots.
7544          (let ((nodes (cdr (symbol-value node)))
7545                thread)
7546            (while nodes
7547              (if (and gnus-thread-expunge-below
7548                       (< (gnus-thread-total-score (car nodes))
7549                          gnus-thread-expunge-below))
7550                  (gnus-expunge-thread (pop nodes))
7551                (setq thread (pop nodes))
7552                (gnus-summary-limit-children thread))))))
7553      gnus-newsgroup-dependencies)
7554     ;; If this limitation resulted in an empty group, we might
7555     ;; pop the previous limit and use it instead.
7556     (when (and (not gnus-newsgroup-limit)
7557                show-if-empty)
7558       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7559     gnus-newsgroup-limit))
7560
7561 (defun gnus-summary-limit-children (thread)
7562   "Return 1 if this subthread is visible and 0 if it is not."
7563   ;; First we get the number of visible children to this thread.  This
7564   ;; is done by recursing down the thread using this function, so this
7565   ;; will really go down to a leaf article first, before slowly
7566   ;; working its way up towards the root.
7567   (when thread
7568     (let ((children
7569            (if (cdr thread)
7570                (apply '+ (mapcar 'gnus-summary-limit-children
7571                                  (cdr thread)))
7572              0))
7573           (number (mail-header-number (car thread)))
7574           score)
7575       (if (and
7576            (not (memq number gnus-newsgroup-marked))
7577            (or
7578             ;; If this article is dormant and has absolutely no visible
7579             ;; children, then this article isn't visible.
7580             (and (memq number gnus-newsgroup-dormant)
7581                  (zerop children))
7582             ;; If this is "fetch-old-headered" and there is no
7583             ;; visible children, then we don't want this article.
7584             (and (or (eq gnus-fetch-old-headers 'some)
7585                      (numberp gnus-fetch-old-headers))
7586                  (gnus-summary-article-ancient-p number)
7587                  (zerop children))
7588             ;; If this is "fetch-old-headered" and `invisible', then
7589             ;; we don't want this article.
7590             (and (eq gnus-fetch-old-headers 'invisible)
7591                  (gnus-summary-article-ancient-p number))
7592             ;; If this is a sparsely inserted article with no children,
7593             ;; we don't want it.
7594             (and (eq gnus-build-sparse-threads 'some)
7595                  (gnus-summary-article-sparse-p number)
7596                  (zerop children))
7597             ;; If we use expunging, and this article is really
7598             ;; low-scored, then we don't want this article.
7599             (when (and gnus-summary-expunge-below
7600                        (< (setq score
7601                                 (or (cdr (assq number gnus-newsgroup-scored))
7602                                     gnus-summary-default-score))
7603                           gnus-summary-expunge-below))
7604               ;; We increase the expunge-tally here, but that has
7605               ;; nothing to do with the limits, really.
7606               (incf gnus-newsgroup-expunged-tally)
7607               ;; We also mark as read here, if that's wanted.
7608               (when (and gnus-summary-mark-below
7609                          (< score gnus-summary-mark-below))
7610                 (setq gnus-newsgroup-unreads
7611                       (delq number gnus-newsgroup-unreads))
7612                 (if gnus-newsgroup-auto-expire
7613                     (push number gnus-newsgroup-expirable)
7614                   (push (cons number gnus-low-score-mark)
7615                         gnus-newsgroup-reads)))
7616               t)
7617             ;; Do the `display' group parameter.
7618             (and gnus-newsgroup-display
7619                  (not (funcall gnus-newsgroup-display)))
7620             ;; Check NoCeM things.
7621             (if (and gnus-use-nocem
7622                      (gnus-nocem-unwanted-article-p
7623                       (mail-header-id (car thread))))
7624                 (progn
7625                   (setq gnus-newsgroup-unreads
7626                         (delq number gnus-newsgroup-unreads))
7627                   t))))
7628           ;; Nope, invisible article.
7629           0
7630         ;; Ok, this article is to be visible, so we add it to the limit
7631         ;; and return 1.
7632         (push number gnus-newsgroup-limit)
7633         1))))
7634
7635 (defun gnus-expunge-thread (thread)
7636   "Mark all articles in THREAD as read."
7637   (let* ((number (mail-header-number (car thread))))
7638     (incf gnus-newsgroup-expunged-tally)
7639     ;; We also mark as read here, if that's wanted.
7640     (setq gnus-newsgroup-unreads
7641           (delq number gnus-newsgroup-unreads))
7642     (if gnus-newsgroup-auto-expire
7643         (push number gnus-newsgroup-expirable)
7644       (push (cons number gnus-low-score-mark)
7645             gnus-newsgroup-reads)))
7646   ;; Go recursively through all subthreads.
7647   (mapcar 'gnus-expunge-thread (cdr thread)))
7648
7649 ;; Summary article oriented commands
7650
7651 (defun gnus-summary-refer-parent-article (n)
7652   "Refer parent article N times.
7653 If N is negative, go to ancestor -N instead.
7654 The difference between N and the number of articles fetched is returned."
7655   (interactive "p")
7656   (let ((skip 1)
7657         error header ref)
7658     (when (not (natnump n))
7659       (setq skip (abs n)
7660             n 1))
7661     (while (and (> n 0)
7662                 (not error))
7663       (setq header (gnus-summary-article-header))
7664       (if (and (eq (mail-header-number header)
7665                    (cdr gnus-article-current))
7666                (equal gnus-newsgroup-name
7667                       (car gnus-article-current)))
7668           ;; If we try to find the parent of the currently
7669           ;; displayed article, then we take a look at the actual
7670           ;; References header, since this is slightly more
7671           ;; reliable than the References field we got from the
7672           ;; server.
7673           (save-excursion
7674             (set-buffer gnus-original-article-buffer)
7675             (nnheader-narrow-to-headers)
7676             (unless (setq ref (message-fetch-field "references"))
7677               (setq ref (message-fetch-field "in-reply-to")))
7678             (widen))
7679         (setq ref
7680               ;; It's not the current article, so we take a bet on
7681               ;; the value we got from the server.
7682               (mail-header-references header)))
7683       (if (and ref
7684                (not (equal ref "")))
7685           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7686             (gnus-message 1 "Couldn't find parent"))
7687         (gnus-message 1 "No references in article %d"
7688                       (gnus-summary-article-number))
7689         (setq error t))
7690       (decf n))
7691     (gnus-summary-position-point)
7692     n))
7693
7694 (defun gnus-summary-refer-references ()
7695   "Fetch all articles mentioned in the References header.
7696 Return the number of articles fetched."
7697   (interactive)
7698   (let ((ref (mail-header-references (gnus-summary-article-header)))
7699         (current (gnus-summary-article-number))
7700         (n 0))
7701     (if (or (not ref)
7702             (equal ref ""))
7703         (error "No References in the current article")
7704       ;; For each Message-ID in the References header...
7705       (while (string-match "<[^>]*>" ref)
7706         (incf n)
7707         ;; ... fetch that article.
7708         (gnus-summary-refer-article
7709          (prog1 (match-string 0 ref)
7710            (setq ref (substring ref (match-end 0))))))
7711       (gnus-summary-goto-subject current)
7712       (gnus-summary-position-point)
7713       n)))
7714
7715 (defun gnus-summary-refer-thread (&optional limit)
7716   "Fetch all articles in the current thread.
7717 If LIMIT (the numerical prefix), fetch that many old headers instead
7718 of what's specified by the `gnus-refer-thread-limit' variable."
7719   (interactive "P")
7720   (let ((id (mail-header-id (gnus-summary-article-header)))
7721         (limit (if limit (prefix-numeric-value limit)
7722                  gnus-refer-thread-limit)))
7723     ;; We want to fetch LIMIT *old* headers, but we also have to
7724     ;; re-fetch all the headers in the current buffer, because many of
7725     ;; them may be undisplayed.  So we adjust LIMIT.
7726     (when (numberp limit)
7727       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7728     (unless (eq gnus-fetch-old-headers 'invisible)
7729       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7730       ;; Retrieve the headers and read them in.
7731       (if (eq (gnus-retrieve-headers
7732                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7733               'nov)
7734           (gnus-build-all-threads)
7735         (error "Can't fetch thread from backends that don't support NOV"))
7736       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7737     (gnus-summary-limit-include-thread id)))
7738
7739 (defun gnus-summary-refer-article (message-id)
7740   "Fetch an article specified by MESSAGE-ID."
7741   (interactive "sMessage-ID: ")
7742   (when (and (stringp message-id)
7743              (not (zerop (length message-id))))
7744     ;; Construct the correct Message-ID if necessary.
7745     ;; Suggested by tale@pawl.rpi.edu.
7746     (unless (string-match "^<" message-id)
7747       (setq message-id (concat "<" message-id)))
7748     (unless (string-match ">$" message-id)
7749       (setq message-id (concat message-id ">")))
7750     (let* ((header (gnus-id-to-header message-id))
7751            (sparse (and header
7752                         (gnus-summary-article-sparse-p
7753                          (mail-header-number header))
7754                         (memq (mail-header-number header)
7755                               gnus-newsgroup-limit)))
7756            number)
7757       (cond
7758        ;; If the article is present in the buffer we just go to it.
7759        ((and header
7760              (or (not (gnus-summary-article-sparse-p
7761                        (mail-header-number header)))
7762                  sparse))
7763         (prog1
7764             (gnus-summary-goto-article
7765              (mail-header-number header) nil t)
7766           (when sparse
7767             (gnus-summary-update-article (mail-header-number header)))))
7768        (t
7769         ;; We fetch the article.
7770         (catch 'found
7771           (dolist (gnus-override-method (gnus-refer-article-methods))
7772             (gnus-check-server gnus-override-method)
7773             ;; Fetch the header, and display the article.
7774             (when (setq number (gnus-summary-insert-subject message-id))
7775               (gnus-summary-select-article nil nil nil number)
7776               (throw 'found t)))
7777           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7778
7779 (defun gnus-refer-article-methods ()
7780   "Return a list of referrable methods."
7781   (cond
7782    ;; No method, so we default to current and native.
7783    ((null gnus-refer-article-method)
7784     (list gnus-current-select-method gnus-select-method))
7785    ;; Current.
7786    ((eq 'current gnus-refer-article-method)
7787     (list gnus-current-select-method))
7788    ;; List of select methods.
7789    ((not (and (symbolp (car gnus-refer-article-method))
7790               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7791     (let (out)
7792       (dolist (method gnus-refer-article-method)
7793         (push (if (eq 'current method)
7794                   gnus-current-select-method
7795                 method)
7796               out))
7797       (nreverse out)))
7798    ;; One single select method.
7799    (t
7800     (list gnus-refer-article-method))))
7801
7802 (defun gnus-summary-edit-parameters ()
7803   "Edit the group parameters of the current group."
7804   (interactive)
7805   (gnus-group-edit-group gnus-newsgroup-name 'params))
7806
7807 (defun gnus-summary-customize-parameters ()
7808   "Customize the group parameters of the current group."
7809   (interactive)
7810   (gnus-group-customize gnus-newsgroup-name))
7811
7812 (defun gnus-summary-enter-digest-group (&optional force)
7813   "Enter an nndoc group based on the current article.
7814 If FORCE, force a digest interpretation.  If not, try
7815 to guess what the document format is."
7816   (interactive "P")
7817   (let ((conf gnus-current-window-configuration))
7818     (save-excursion
7819       (gnus-summary-select-article))
7820     (setq gnus-current-window-configuration conf)
7821     (let* ((name (format "%s-%d"
7822                          (gnus-group-prefixed-name
7823                           gnus-newsgroup-name (list 'nndoc ""))
7824                          (save-excursion
7825                            (set-buffer gnus-summary-buffer)
7826                            gnus-current-article)))
7827            (ogroup gnus-newsgroup-name)
7828            (params (append (gnus-info-params (gnus-get-info ogroup))
7829                            (list (cons 'to-group ogroup))
7830                            (list (cons 'save-article-group ogroup))))
7831            (case-fold-search t)
7832            (buf (current-buffer))
7833            dig to-address)
7834       (save-excursion
7835         (set-buffer gnus-original-article-buffer)
7836         ;; Have the digest group inherit the main mail address of
7837         ;; the parent article.
7838         (when (setq to-address (or (message-fetch-field "reply-to")
7839                                    (message-fetch-field "from")))
7840           (setq params (append
7841                         (list (cons 'to-address
7842                                     (funcall gnus-decode-encoded-word-function
7843                                              to-address))))))
7844         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7845         (insert-buffer-substring gnus-original-article-buffer)
7846         ;; Remove lines that may lead nndoc to misinterpret the
7847         ;; document type.
7848         (narrow-to-region
7849          (goto-char (point-min))
7850          (or (search-forward "\n\n" nil t) (point)))
7851         (goto-char (point-min))
7852         (delete-matching-lines "^Path:\\|^From ")
7853         (widen))
7854       (unwind-protect
7855           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7856                     (gnus-newsgroup-ephemeral-ignored-charsets
7857                      gnus-newsgroup-ignored-charsets))
7858                 (gnus-group-read-ephemeral-group
7859                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7860                               (nndoc-article-type
7861                                ,(if force 'mbox 'guess)))
7862                  t nil nil nil
7863                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7864                                                         "ADAPT")))))
7865               ;; Make all postings to this group go to the parent group.
7866               (nconc (gnus-info-params (gnus-get-info name))
7867                      params)
7868             ;; Couldn't select this doc group.
7869             (switch-to-buffer buf)
7870             (gnus-set-global-variables)
7871             (gnus-configure-windows 'summary)
7872             (gnus-message 3 "Article couldn't be entered?"))
7873         (kill-buffer dig)))))
7874
7875 (defun gnus-summary-read-document (n)
7876   "Open a new group based on the current article(s).
7877 This will allow you to read digests and other similar
7878 documents as newsgroups.
7879 Obeys the standard process/prefix convention."
7880   (interactive "P")
7881   (let* ((articles (gnus-summary-work-articles n))
7882          (ogroup gnus-newsgroup-name)
7883          (params (append (gnus-info-params (gnus-get-info ogroup))
7884                          (list (cons 'to-group ogroup))))
7885          article group egroup groups vgroup)
7886     (while (setq article (pop articles))
7887       (setq group (format "%s-%d" gnus-newsgroup-name article))
7888       (gnus-summary-remove-process-mark article)
7889       (when (gnus-summary-display-article article)
7890         (save-excursion
7891           (with-temp-buffer
7892             (insert-buffer-substring gnus-original-article-buffer)
7893             ;; Remove some headers that may lead nndoc to make
7894             ;; the wrong guess.
7895             (message-narrow-to-head)
7896             (goto-char (point-min))
7897             (delete-matching-lines "^\\(Path\\):\\|^From ")
7898             (widen)
7899             (if (setq egroup
7900                       (gnus-group-read-ephemeral-group
7901                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7902                                      (nndoc-article-type guess))
7903                        t nil t))
7904                 (progn
7905                   ;; Make all postings to this group go to the parent group.
7906                   (nconc (gnus-info-params (gnus-get-info egroup))
7907                          params)
7908                   (push egroup groups))
7909               ;; Couldn't select this doc group.
7910               (gnus-error 3 "Article couldn't be entered"))))))
7911     ;; Now we have selected all the documents.
7912     (cond
7913      ((not groups)
7914       (error "None of the articles could be interpreted as documents"))
7915      ((gnus-group-read-ephemeral-group
7916        (setq vgroup (format
7917                      "nnvirtual:%s-%s" gnus-newsgroup-name
7918                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7919        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7920        t
7921        (cons (current-buffer) 'summary)))
7922      (t
7923       (error "Couldn't select virtual nndoc group")))))
7924
7925 (defun gnus-summary-isearch-article (&optional regexp-p)
7926   "Do incremental search forward on the current article.
7927 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7928   (interactive "P")
7929   (let* ((gnus-inhibit-treatment t)
7930          (old (gnus-summary-select-article)))
7931     (gnus-configure-windows 'article)
7932     (gnus-eval-in-buffer-window gnus-article-buffer
7933       (save-restriction
7934         (widen)
7935         (when (eq 'old old)
7936           (gnus-article-show-all-headers))
7937         (goto-char (point-min))
7938         (isearch-forward regexp-p)))))
7939
7940 (defun gnus-summary-search-article-forward (regexp &optional backward)
7941   "Search for an article containing REGEXP forward.
7942 If BACKWARD, search backward instead."
7943   (interactive
7944    (list (read-string
7945           (format "Search article %s (regexp%s): "
7946                   (if current-prefix-arg "backward" "forward")
7947                   (if gnus-last-search-regexp
7948                       (concat ", default " gnus-last-search-regexp)
7949                     "")))
7950          current-prefix-arg))
7951   (if (string-equal regexp "")
7952       (setq regexp (or gnus-last-search-regexp ""))
7953     (setq gnus-last-search-regexp regexp)
7954     (setq gnus-article-before-search gnus-current-article))
7955   ;; Intentionally set gnus-last-article.
7956   (setq gnus-last-article gnus-article-before-search)
7957   (let ((gnus-last-article gnus-last-article))
7958     (if (gnus-summary-search-article regexp backward)
7959         (gnus-summary-show-thread)
7960       (error "Search failed: \"%s\"" regexp))))
7961
7962 (defun gnus-summary-search-article-backward (regexp)
7963   "Search for an article containing REGEXP backward."
7964   (interactive
7965    (list (read-string
7966           (format "Search article backward (regexp%s): "
7967                   (if gnus-last-search-regexp
7968                       (concat ", default " gnus-last-search-regexp)
7969                     "")))))
7970   (gnus-summary-search-article-forward regexp 'backward))
7971
7972 (eval-when-compile
7973   (defmacro gnus-summary-search-article-position-point (regexp backward)
7974     "Dehighlight the last matched text and goto the beginning position."
7975     (` (if (and gnus-summary-search-article-matched-data
7976                 (let ((text (caddr gnus-summary-search-article-matched-data))
7977                       (inhibit-read-only t)
7978                       buffer-read-only)
7979                   (delete-region
7980                    (goto-char (car gnus-summary-search-article-matched-data))
7981                    (cadr gnus-summary-search-article-matched-data))
7982                   (insert text)
7983                   (string-match (, regexp) text)))
7984            (if (, backward) (beginning-of-line) (end-of-line))
7985          (goto-char (if (, backward) (point-max) (point-min))))))
7986
7987   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7988     "Place point where X-Face image is displayed."
7989     (if (featurep 'xemacs)
7990         (` (let ((end (if (search-forward "\n\n" nil t)
7991                           (goto-char (1- (point)))
7992                         (point-min)))
7993                  extent)
7994              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7995              (unless (and (re-search-forward "^From:" end t)
7996                           (setq extent (extent-at (point)))
7997                           (extent-begin-glyph extent))
7998                (goto-char (, opoint)))))
7999       (` (let ((end (if (search-forward "\n\n" nil t)
8000                         (goto-char (1- (point)))
8001                       (point-min)))
8002                (start (or (search-backward "\n\n" nil t) (point-min))))
8003            (goto-char
8004             (or (text-property-any start end 'x-face-image t);; x-face-e21
8005                 (text-property-any start end 'x-face-mule-bitmap-image t)
8006                 (, opoint)))))))
8007
8008   (defmacro gnus-summary-search-article-highlight-matched-text
8009     (backward treated x-face)
8010     "Highlight matched text in the function `gnus-summary-search-article'."
8011     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8012              (end (set-marker (make-marker) (match-end 0)))
8013              (inhibit-read-only t)
8014              buffer-read-only)
8015          (unless treated
8016            (let ((,@
8017                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8018                     (mapcar
8019                      (lambda (item) (setq items (delq item items)))
8020                      '(gnus-treat-buttonize
8021                        gnus-treat-fill-article
8022                        gnus-treat-fill-long-lines
8023                        gnus-treat-emphasize
8024                        gnus-treat-highlight-headers
8025                        gnus-treat-highlight-citation
8026                        gnus-treat-highlight-signature
8027                        gnus-treat-overstrike
8028                        gnus-treat-display-xface
8029                        gnus-treat-buttonize-head
8030                        gnus-treat-decode-article-as-default-mime-charset))
8031                     (static-if (featurep 'xemacs)
8032                         items
8033                       (cons '(x-face-mule-delete-x-face-field
8034                               (quote never))
8035                             items))))
8036                  (gnus-treat-display-xface
8037                   (when (, x-face) gnus-treat-display-xface)))
8038              (gnus-article-prepare-mime-display)))
8039          (goto-char (if (, backward) start end))
8040          (when (, x-face)
8041            (gnus-summary-search-article-highlight-goto-x-face (point)))
8042          (setq gnus-summary-search-article-matched-data
8043                (list start end (buffer-substring start end)))
8044          (unless (eq start end);; matched text has been deleted. :-<
8045            (put-text-property start end 'face
8046                               (or (find-face 'isearch)
8047                                   'secondary-selection))))))
8048   )
8049
8050 (defun gnus-summary-search-article (regexp &optional backward)
8051   "Search for an article containing REGEXP.
8052 Optional argument BACKWARD means do search for backward.
8053 `gnus-select-article-hook' is not called during the search."
8054   ;; We have to require this here to make sure that the following
8055   ;; dynamic binding isn't shadowed by autoloading.
8056   (require 'gnus-async)
8057   (require 'gnus-art)
8058   (let ((gnus-select-article-hook nil)  ;Disable hook.
8059         (gnus-article-prepare-hook nil)
8060         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8061         (gnus-use-article-prefetch nil)
8062         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8063         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8064         (sum (current-buffer))
8065         (found nil)
8066         point treated)
8067     (gnus-save-hidden-threads
8068       (static-if (featurep 'xemacs)
8069           (let ((gnus-inhibit-treatment t))
8070             (setq treated (eq 'old (gnus-summary-select-article)))
8071             (when (and treated
8072                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8073                                  (window-live-p (get-buffer-window
8074                                                  gnus-article-buffer t)))))
8075               (gnus-summary-select-article nil t)
8076               (setq treated nil)))
8077         (let ((gnus-inhibit-treatment t)
8078               (x-face-mule-delete-x-face-field 'never))
8079           (setq treated (eq 'old (gnus-summary-select-article)))
8080           (when (and treated
8081                      (not
8082                       (and (gnus-buffer-live-p gnus-article-buffer)
8083                            (window-live-p (get-buffer-window
8084                                            gnus-article-buffer t))
8085                            (or (not (string-match "^\\^X-Face:" regexp))
8086                                (with-current-buffer gnus-article-buffer
8087                                  gnus-summary-search-article-matched-data)))))
8088             (gnus-summary-select-article nil t)
8089             (setq treated nil))))
8090       (set-buffer gnus-article-buffer)
8091       (widen)
8092       (if treated
8093           (progn
8094             (gnus-article-show-all-headers)
8095             (gnus-summary-search-article-position-point regexp backward))
8096         (goto-char (if backward (point-max) (point-min))))
8097       (while (not found)
8098         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8099         (if (if backward
8100                 (re-search-backward regexp nil t)
8101               (re-search-forward regexp nil t))
8102             ;; We found the regexp.
8103             (progn
8104               (gnus-summary-search-article-highlight-matched-text
8105                backward treated (string-match "^\\^X-Face:" regexp))
8106               (setq found 'found)
8107               (forward-line
8108                (/ (- 2 (window-height
8109                         (get-buffer-window gnus-article-buffer t)))
8110                   2))
8111               (set-window-start
8112                (get-buffer-window (current-buffer))
8113                (point))
8114               (set-buffer sum)
8115               (setq point (point)))
8116           ;; We didn't find it, so we go to the next article.
8117           (set-buffer sum)
8118           (setq found 'not)
8119           (while (eq found 'not)
8120             (if (not (if backward (gnus-summary-find-prev)
8121                        (gnus-summary-find-next)))
8122                 ;; No more articles.
8123                 (setq found t)
8124               ;; Select the next article and adjust point.
8125               (unless (gnus-summary-article-sparse-p
8126                        (gnus-summary-article-number))
8127                 (setq found nil)
8128                 (let ((gnus-inhibit-treatment t))
8129                   (gnus-summary-select-article))
8130                 (setq treated nil)
8131                 (set-buffer gnus-article-buffer)
8132                 (widen)
8133                 (goto-char (if backward (point-max) (point-min))))))))
8134       (gnus-message 7 ""))
8135     ;; Return whether we found the regexp.
8136     (when (eq found 'found)
8137       (goto-char point)
8138       (gnus-summary-show-thread)
8139       (gnus-summary-goto-subject gnus-current-article)
8140       (gnus-summary-position-point)
8141       t)))
8142
8143 (defun gnus-find-matching-articles (header regexp)
8144   "Return a list of all articles that match REGEXP on HEADER.
8145 This search includes all articles in the current group that Gnus has
8146 fetched headers for, whether they are displayed or not."
8147   (let ((articles nil)
8148         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8149         (case-fold-search t))
8150     (dolist (header gnus-newsgroup-headers)
8151       (when (string-match regexp (funcall func header))
8152         (push (mail-header-number header) articles)))
8153     (nreverse articles)))
8154
8155 (defun gnus-summary-find-matching (header regexp &optional backward unread
8156                                           not-case-fold not-matching)
8157   "Return a list of all articles that match REGEXP on HEADER.
8158 The search stars on the current article and goes forwards unless
8159 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8160 If UNREAD is non-nil, only unread articles will
8161 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8162 in the comparisons. If NOT-MATCHING, return a list of all articles that
8163 not match REGEXP on HEADER."
8164   (let ((case-fold-search (not not-case-fold))
8165         articles d func)
8166     (if (consp header)
8167         (if (eq (car header) 'extra)
8168             (setq func
8169                   `(lambda (h)
8170                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8171                          "")))
8172           (error "%s is an invalid header" header))
8173       (unless (fboundp (intern (concat "mail-header-" header)))
8174         (error "%s is not a valid header" header))
8175       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8176     (dolist (d (if (eq backward 'all)
8177                    gnus-newsgroup-data
8178                  (gnus-data-find-list
8179                   (gnus-summary-article-number)
8180                   (gnus-data-list backward))))
8181       (when (and (or (not unread)       ; We want all articles...
8182                      (gnus-data-unread-p d)) ; Or just unreads.
8183                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8184                  (if not-matching
8185                      (not (string-match
8186                            regexp
8187                            (funcall func (gnus-data-header d))))
8188                    (string-match regexp
8189                                  (funcall func (gnus-data-header d)))))
8190         (push (gnus-data-number d) articles))) ; Success!
8191     (nreverse articles)))
8192
8193 (defun gnus-summary-execute-command (header regexp command &optional backward)
8194   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8195 If HEADER is an empty string (or nil), the match is done on the entire
8196 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8197   (interactive
8198    (list (let ((completion-ignore-case t))
8199            (completing-read
8200             "Header name: "
8201             (mapcar (lambda (header) (list (format "%s" header)))
8202                     (append
8203                      '("Number" "Subject" "From" "Lines" "Date"
8204                        "Message-ID" "Xref" "References" "Body")
8205                      gnus-extra-headers))
8206             nil 'require-match))
8207          (read-string "Regexp: ")
8208          (read-key-sequence "Command: ")
8209          current-prefix-arg))
8210   (when (equal header "Body")
8211     (setq header ""))
8212   ;; Hidden thread subtrees must be searched as well.
8213   (gnus-summary-show-all-threads)
8214   ;; We don't want to change current point nor window configuration.
8215   (save-excursion
8216     (save-window-excursion
8217       (gnus-message 6 "Executing %s..." (key-description command))
8218       ;; We'd like to execute COMMAND interactively so as to give arguments.
8219       (gnus-execute header regexp
8220                     `(call-interactively ',(key-binding command))
8221                     backward)
8222       (gnus-message 6 "Executing %s...done" (key-description command)))))
8223
8224 (defun gnus-summary-beginning-of-article ()
8225   "Scroll the article back to the beginning."
8226   (interactive)
8227   (gnus-summary-select-article)
8228   (gnus-configure-windows 'article)
8229   (gnus-eval-in-buffer-window gnus-article-buffer
8230     (widen)
8231     (goto-char (point-min))
8232     (when gnus-page-broken
8233       (gnus-narrow-to-page))))
8234
8235 (defun gnus-summary-end-of-article ()
8236   "Scroll to the end of the article."
8237   (interactive)
8238   (gnus-summary-select-article)
8239   (gnus-configure-windows 'article)
8240   (gnus-eval-in-buffer-window gnus-article-buffer
8241     (widen)
8242     (goto-char (point-max))
8243     (recenter -3)
8244     (when gnus-page-broken
8245       (gnus-narrow-to-page))))
8246
8247 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8248   "Truncate to LEN and quote all \"(\"'s in STRING."
8249   (gnus-replace-in-string (if (and len (> (length string) len))
8250                               (substring string 0 len)
8251                             string)
8252                           "[()]" "\\\\\\&"))
8253
8254 (defun gnus-summary-print-article (&optional filename n)
8255   "Generate and print a PostScript image of the N next (mail) articles.
8256
8257 If N is negative, print the N previous articles.  If N is nil and articles
8258 have been marked with the process mark, print these instead.
8259
8260 If the optional first argument FILENAME is nil, send the image to the
8261 printer.  If FILENAME is a string, save the PostScript image in a file with
8262 that name.  If FILENAME is a number, prompt the user for the name of the file
8263 to save in."
8264   (interactive (list (ps-print-preprint current-prefix-arg)))
8265   (dolist (article (gnus-summary-work-articles n))
8266     (gnus-summary-select-article nil nil 'pseudo article)
8267     (gnus-eval-in-buffer-window gnus-article-buffer
8268       (gnus-print-buffer))
8269     (gnus-summary-remove-process-mark article))
8270   (ps-despool filename))
8271
8272 (defun gnus-print-buffer ()
8273   (let ((buffer (generate-new-buffer " *print*")))
8274     (unwind-protect
8275         (progn
8276           (copy-to-buffer buffer (point-min) (point-max))
8277           (set-buffer buffer)
8278           (gnus-article-delete-invisible-text)
8279           (gnus-remove-text-with-property 'gnus-decoration)
8280           (when (gnus-visual-p 'article-highlight 'highlight)
8281             ;; Copy-to-buffer doesn't copy overlay.  So redo
8282             ;; highlight.
8283             (let ((gnus-article-buffer buffer))
8284               (gnus-article-highlight-citation t)
8285               (gnus-article-highlight-signature)))
8286           (let ((ps-left-header
8287                  (list
8288                   (concat "("
8289                           (gnus-summary-print-truncate-and-quote
8290                            (mail-header-subject gnus-current-headers)
8291                            66) ")")
8292                   (concat "("
8293                           (gnus-summary-print-truncate-and-quote
8294                            (mail-header-from gnus-current-headers)
8295                            45) ")")))
8296                 (ps-right-header
8297                  (list
8298                   "/pagenumberstring load"
8299                   (concat "("
8300                           (mail-header-date gnus-current-headers) ")"))))
8301             (gnus-run-hooks 'gnus-ps-print-hook)
8302             (save-excursion
8303               (if window-system
8304                   (ps-spool-buffer-with-faces)
8305                 (ps-spool-buffer)))))
8306       (kill-buffer buffer))))
8307
8308 (defun gnus-summary-show-article (&optional arg)
8309   "Force redisplaying of the current article.
8310 If ARG (the prefix) is a number, show the article with the charset
8311 defined in `gnus-summary-show-article-charset-alist', or the charset
8312 input.
8313 If ARG (the prefix) is non-nil and not a number, show the raw article
8314 without any article massaging functions being run.  Normally, the key strokes
8315 are `C-u g'."
8316   (interactive "P")
8317   (cond
8318    ((numberp arg)
8319     (gnus-summary-show-article t)
8320     (let* ((gnus-newsgroup-charset
8321             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8322                 (mm-read-coding-system
8323                  "View as charset: " ;; actually it is coding system.
8324                  (save-excursion
8325                    (set-buffer gnus-article-buffer)
8326                    (mm-detect-coding-region (point) (point-max))))))
8327            (default-mime-charset gnus-newsgroup-charset)
8328            (gnus-newsgroup-ignored-charsets 'gnus-all))
8329       (gnus-summary-select-article nil 'force)
8330       (let ((deps gnus-newsgroup-dependencies)
8331             head header lines)
8332         (save-excursion
8333           (set-buffer gnus-original-article-buffer)
8334           (save-restriction
8335             (message-narrow-to-head)
8336             (setq head (buffer-string))
8337             (goto-char (point-min))
8338             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8339               (goto-char (point-max))
8340               (widen)
8341               (setq lines (1- (count-lines (point) (point-max))))))
8342           (with-temp-buffer
8343             (insert (format "211 %d Article retrieved.\n"
8344                             (cdr gnus-article-current)))
8345             (insert head)
8346             (if lines (insert (format "Lines: %d\n" lines)))
8347             (insert ".\n")
8348             (let ((nntp-server-buffer (current-buffer)))
8349               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8350         (gnus-data-set-header
8351          (gnus-data-find (cdr gnus-article-current))
8352          header)
8353         (gnus-summary-update-article-line
8354          (cdr gnus-article-current) header)
8355         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8356           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8357    ((not arg)
8358     ;; Select the article the normal way.
8359     (gnus-summary-select-article nil 'force))
8360    (t
8361     ;; We have to require this here to make sure that the following
8362     ;; dynamic binding isn't shadowed by autoloading.
8363     (require 'gnus-async)
8364     (require 'gnus-art)
8365     ;; Bind the article treatment functions to nil.
8366     (let ((gnus-have-all-headers t)
8367           gnus-article-prepare-hook
8368           gnus-article-decode-hook
8369           gnus-break-pages
8370           gnus-show-mime
8371           (gnus-inhibit-treatment t))
8372       (gnus-summary-select-article nil 'force))))
8373   (gnus-summary-goto-subject gnus-current-article)
8374   (gnus-summary-position-point))
8375
8376 (defun gnus-summary-show-raw-article ()
8377   "Show the raw article without any article massaging functions being run."
8378   (interactive)
8379   (gnus-summary-show-article t))
8380
8381 (defun gnus-summary-verbose-headers (&optional arg)
8382   "Toggle permanent full header display.
8383 If ARG is a positive number, turn header display on.
8384 If ARG is a negative number, turn header display off."
8385   (interactive "P")
8386   (setq gnus-show-all-headers
8387         (cond ((or (not (numberp arg))
8388                    (zerop arg))
8389                (not gnus-show-all-headers))
8390               ((natnump arg)
8391                t)))
8392   (gnus-summary-show-article))
8393
8394 (defun gnus-summary-toggle-header (&optional arg)
8395   "Show the headers if they are hidden, or hide them if they are shown.
8396 If ARG is a positive number, show the entire header.
8397 If ARG is a negative number, hide the unwanted header lines."
8398   (interactive "P")
8399   (save-excursion
8400     (set-buffer gnus-article-buffer)
8401     (save-restriction
8402       (let* ((buffer-read-only nil)
8403              (inhibit-point-motion-hooks t)
8404              hidden s e)
8405         (save-restriction
8406           (article-narrow-to-head)
8407           (setq e (point-max)
8408                 hidden (if (numberp arg)
8409                            (>= arg 0)
8410                          (gnus-article-hidden-text-p 'headers))))
8411         (delete-region (point-min) e)
8412         (goto-char (point-min))
8413         (with-current-buffer gnus-original-article-buffer
8414           (goto-char (setq s (point-min)))
8415           (setq e (search-forward "\n\n" nil t)
8416                 e (if e (1- e) (point-max))))
8417         (insert-buffer-substring gnus-original-article-buffer s e)
8418         (save-restriction
8419           (narrow-to-region (point-min) (point))
8420           (article-decode-encoded-words)
8421           (if  hidden
8422               (let ((gnus-treat-hide-headers nil)
8423                     (gnus-treat-hide-boring-headers nil))
8424                 (gnus-delete-wash-type 'headers)
8425                 (gnus-treat-article 'head))
8426             (gnus-treat-article 'head)))
8427         (gnus-set-mode-line 'article)))))
8428
8429 (defun gnus-summary-show-all-headers ()
8430   "Make all header lines visible."
8431   (interactive)
8432   (gnus-summary-toggle-header 1))
8433
8434 (defun gnus-summary-toggle-mime (&optional arg)
8435   "Toggle MIME processing.
8436 If ARG is a positive number, turn MIME processing on."
8437   (interactive "P")
8438   (setq gnus-show-mime
8439         (if (null arg)
8440             (not gnus-show-mime)
8441           (> (prefix-numeric-value arg) 0)))
8442   (gnus-summary-select-article t 'force))
8443
8444 (defun gnus-summary-caesar-message (&optional arg)
8445   "Caesar rotate the current article by 13.
8446 The numerical prefix specifies how many places to rotate each letter
8447 forward."
8448   (interactive "P")
8449   (gnus-summary-select-article)
8450   (let ((mail-header-separator ""))
8451     (gnus-eval-in-buffer-window gnus-article-buffer
8452       (save-restriction
8453         (widen)
8454         (let ((start (window-start))
8455               buffer-read-only)
8456           (message-caesar-buffer-body arg)
8457           (set-window-start (get-buffer-window (current-buffer)) start))))))
8458
8459 (defun gnus-summary-stop-page-breaking ()
8460   "Stop page breaking in the current article."
8461   (interactive)
8462   (gnus-summary-select-article)
8463   (gnus-eval-in-buffer-window gnus-article-buffer
8464     (widen)
8465     (when (gnus-visual-p 'page-marker)
8466       (let ((buffer-read-only nil))
8467         (gnus-remove-text-with-property 'gnus-prev)
8468         (gnus-remove-text-with-property 'gnus-next))
8469       (setq gnus-page-broken nil))))
8470
8471 (defun gnus-summary-move-article (&optional n to-newsgroup
8472                                             select-method action)
8473   "Move the current article to a different newsgroup.
8474 If N is a positive number, move the N next articles.
8475 If N is a negative number, move the N previous articles.
8476 If N is nil and any articles have been marked with the process mark,
8477 move those articles instead.
8478 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8479 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8480 re-spool using this method.
8481
8482 When called interactively with TO-NEWSGROUP being nil, the value of
8483 the variable `gnus-move-split-methods' is used for finding a default
8484 for the target newsgroup.
8485
8486 For this function to work, both the current newsgroup and the
8487 newsgroup that you want to move to have to support the `request-move'
8488 and `request-accept' functions.
8489
8490 ACTION can be either `move' (the default), `crosspost' or `copy'."
8491   (interactive "P")
8492   (unless action
8493     (setq action 'move))
8494   ;; Check whether the source group supports the required functions.
8495   (cond ((and (eq action 'move)
8496               (not (gnus-check-backend-function
8497                     'request-move-article gnus-newsgroup-name)))
8498          (error "The current group does not support article moving"))
8499         ((and (eq action 'crosspost)
8500               (not (gnus-check-backend-function
8501                     'request-replace-article gnus-newsgroup-name)))
8502          (error "The current group does not support article editing")))
8503   (let ((articles (gnus-summary-work-articles n))
8504         (prefix (if (gnus-check-backend-function
8505                      'request-move-article gnus-newsgroup-name)
8506                     (gnus-group-real-prefix gnus-newsgroup-name)
8507                   ""))
8508         (names '((move "Move" "Moving")
8509                  (copy "Copy" "Copying")
8510                  (crosspost "Crosspost" "Crossposting")))
8511         (copy-buf (save-excursion
8512                     (nnheader-set-temp-buffer " *copy article*")))
8513         (default-marks gnus-article-mark-lists)
8514         (no-expire-marks (delete '(expirable . expire)
8515                                  (copy-sequence gnus-article-mark-lists)))
8516         art-group to-method new-xref article to-groups)
8517     (unless (assq action names)
8518       (error "Unknown action %s" action))
8519     ;; Read the newsgroup name.
8520     (when (and (not to-newsgroup)
8521                (not select-method))
8522       (if (and gnus-move-split-methods
8523                (not
8524                 (and (memq gnus-current-article articles)
8525                      (gnus-buffer-live-p gnus-original-article-buffer))))
8526           ;; When `gnus-move-split-methods' is non-nil, we have to
8527           ;; select an article to give `gnus-read-move-group-name' an
8528           ;; opportunity to suggest an appropriate default.  However,
8529           ;; we needn't render or mark the article.
8530           (let ((gnus-display-mime-function nil)
8531                 (gnus-article-prepare-hook nil)
8532                 (gnus-mark-article-hook nil))
8533             (gnus-summary-select-article nil nil nil (car articles))))
8534       (setq to-newsgroup
8535             (gnus-read-move-group-name
8536              (cadr (assq action names))
8537              (symbol-value (intern (format "gnus-current-%s-group" action)))
8538              articles prefix))
8539       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8540     (setq to-method (or select-method
8541                         (gnus-server-to-method
8542                          (gnus-group-method to-newsgroup))))
8543     ;; Check the method we are to move this article to...
8544     (unless (gnus-check-backend-function
8545              'request-accept-article (car to-method))
8546       (error "%s does not support article copying" (car to-method)))
8547     (unless (gnus-check-server to-method)
8548       (error "Can't open server %s" (car to-method)))
8549     (gnus-message 6 "%s to %s: %s..."
8550                   (caddr (assq action names))
8551                   (or (car select-method) to-newsgroup) articles)
8552     (while articles
8553       (setq article (pop articles))
8554       (setq
8555        art-group
8556        (cond
8557         ;; Move the article.
8558         ((eq action 'move)
8559          ;; Remove this article from future suppression.
8560          (gnus-dup-unsuppress-article article)
8561          (gnus-request-move-article
8562           article                       ; Article to move
8563           gnus-newsgroup-name           ; From newsgroup
8564           (nth 1 (gnus-find-method-for-group
8565                   gnus-newsgroup-name)) ; Server
8566           (list 'gnus-request-accept-article
8567                 to-newsgroup (list 'quote select-method)
8568                 (not articles) t)       ; Accept form
8569           (not articles)))              ; Only save nov last time
8570         ;; Copy the article.
8571         ((eq action 'copy)
8572          (save-excursion
8573            (set-buffer copy-buf)
8574            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8575              (gnus-request-accept-article
8576               to-newsgroup select-method (not articles) t))))
8577         ;; Crosspost the article.
8578         ((eq action 'crosspost)
8579          (let ((xref (message-tokenize-header
8580                       (mail-header-xref (gnus-summary-article-header article))
8581                       " ")))
8582            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8583                                   ":" (number-to-string article)))
8584            (unless xref
8585              (setq xref (list (system-name))))
8586            (setq new-xref
8587                  (concat
8588                   (mapconcat 'identity
8589                              (delete "Xref:" (delete new-xref xref))
8590                              " ")
8591                   " " new-xref))
8592            (save-excursion
8593              (set-buffer copy-buf)
8594              ;; First put the article in the destination group.
8595              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8596              (when (consp (setq art-group
8597                                 (gnus-request-accept-article
8598                                  to-newsgroup select-method (not articles))))
8599                (setq new-xref (concat new-xref " " (car art-group)
8600                                       ":"
8601                                       (number-to-string (cdr art-group))))
8602                ;; Now we have the new Xrefs header, so we insert
8603                ;; it and replace the new article.
8604                (nnheader-replace-header "Xref" new-xref)
8605                (gnus-request-replace-article
8606                 (cdr art-group) to-newsgroup (current-buffer))
8607                art-group))))))
8608       (cond
8609        ((not art-group)
8610         (gnus-message 1 "Couldn't %s article %s: %s"
8611                       (cadr (assq action names)) article
8612                       (nnheader-get-report (car to-method))))
8613        ((eq art-group 'junk)
8614         (when (eq action 'move)
8615           (gnus-summary-mark-article article gnus-canceled-mark)
8616           (gnus-message 4 "Deleted article %s" article)))
8617        (t
8618         (let* ((pto-group (gnus-group-prefixed-name
8619                            (car art-group) to-method))
8620                (entry
8621                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8622                (info (nth 2 entry))
8623                (to-group (gnus-info-group info))
8624                to-marks)
8625           ;; Update the group that has been moved to.
8626           (when (and info
8627                      (memq action '(move copy)))
8628             (unless (member to-group to-groups)
8629               (push to-group to-groups))
8630
8631             (unless (memq article gnus-newsgroup-unreads)
8632               (push 'read to-marks)
8633               (gnus-info-set-read
8634                info (gnus-add-to-range (gnus-info-read info)
8635                                        (list (cdr art-group)))))
8636
8637             ;; See whether the article is to be put in the cache.
8638             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8639                              default-marks
8640                            no-expire-marks))
8641                   (to-article (cdr art-group)))
8642
8643               ;; Enter the article into the cache in the new group,
8644               ;; if that is required.
8645               (when gnus-use-cache
8646                 (gnus-cache-possibly-enter-article
8647                  to-group to-article
8648                  (let ((header (copy-sequence
8649                                 (gnus-summary-article-header article))))
8650                    (mail-header-set-number header to-article)
8651                    header)
8652                  (memq article gnus-newsgroup-marked)
8653                  (memq article gnus-newsgroup-dormant)
8654                  (memq article gnus-newsgroup-unreads)))
8655
8656               (when gnus-preserve-marks
8657                 ;; Copy any marks over to the new group.
8658                 (when (and (equal to-group gnus-newsgroup-name)
8659                            (not (memq article gnus-newsgroup-unreads)))
8660                   ;; Mark this article as read in this group.
8661                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8662                   (setcdr (gnus-active to-group) to-article)
8663                   (setcdr gnus-newsgroup-active to-article))
8664
8665                 (while marks
8666                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8667                     (when (memq article (symbol-value
8668                                          (intern (format "gnus-newsgroup-%s"
8669                                                          (caar marks)))))
8670                       (push (cdar marks) to-marks)
8671                       ;; If the other group is the same as this group,
8672                       ;; then we have to add the mark to the list.
8673                       (when (equal to-group gnus-newsgroup-name)
8674                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8675                              (cons to-article
8676                                    (symbol-value
8677                                     (intern (format "gnus-newsgroup-%s"
8678                                                     (caar marks)))))))
8679                       ;; Copy the marks to other group.
8680                       (gnus-add-marked-articles
8681                        to-group (cdar marks) (list to-article) info)))
8682                   (setq marks (cdr marks)))
8683
8684                 (gnus-request-set-mark to-group (list (list (list to-article)
8685                                                             'add
8686                                                             to-marks))))
8687
8688               (gnus-dribble-enter
8689                (concat "(gnus-group-set-info '"
8690                        (gnus-prin1-to-string (gnus-get-info to-group))
8691                        ")"))))
8692
8693           ;; Update the Xref header in this article to point to
8694           ;; the new crossposted article we have just created.
8695           (when (eq action 'crosspost)
8696             (save-excursion
8697               (set-buffer copy-buf)
8698               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8699               (nnheader-replace-header "Xref" new-xref)
8700               (gnus-request-replace-article
8701                article gnus-newsgroup-name (current-buffer)))))
8702
8703         ;;;!!!Why is this necessary?
8704         (set-buffer gnus-summary-buffer)
8705
8706         (gnus-summary-goto-subject article)
8707         (when (eq action 'move)
8708           (gnus-summary-mark-article article gnus-canceled-mark))))
8709       (gnus-summary-remove-process-mark article))
8710     ;; Re-activate all groups that have been moved to.
8711     (save-excursion
8712       (set-buffer gnus-group-buffer)
8713       (let ((gnus-group-marked to-groups))
8714         (gnus-group-get-new-news-this-group nil t)))
8715
8716     (gnus-kill-buffer copy-buf)
8717     (gnus-summary-position-point)
8718     (gnus-set-mode-line 'summary)))
8719
8720 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8721   "Move the current article to a different newsgroup.
8722 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8723 When called interactively, if TO-NEWSGROUP is nil, use the value of
8724 the variable `gnus-move-split-methods' for finding a default target
8725 newsgroup.
8726 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8727 re-spool using this method."
8728   (interactive "P")
8729   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8730
8731 (defun gnus-summary-crosspost-article (&optional n)
8732   "Crosspost the current article to some other group."
8733   (interactive "P")
8734   (gnus-summary-move-article n nil nil 'crosspost))
8735
8736 (defcustom gnus-summary-respool-default-method nil
8737   "Default method type for respooling an article.
8738 If nil, use to the current newsgroup method."
8739   :type 'symbol
8740   :group 'gnus-summary-mail)
8741
8742 (defun gnus-summary-respool-article (&optional n method)
8743   "Respool the current article.
8744 The article will be squeezed through the mail spooling process again,
8745 which means that it will be put in some mail newsgroup or other
8746 depending on `nnmail-split-methods'.
8747 If N is a positive number, respool the N next articles.
8748 If N is a negative number, respool the N previous articles.
8749 If N is nil and any articles have been marked with the process mark,
8750 respool those articles instead.
8751
8752 Respooling can be done both from mail groups and \"real\" newsgroups.
8753 In the former case, the articles in question will be moved from the
8754 current group into whatever groups they are destined to.  In the
8755 latter case, they will be copied into the relevant groups."
8756   (interactive
8757    (list current-prefix-arg
8758          (let* ((methods (gnus-methods-using 'respool))
8759                 (methname
8760                  (symbol-name (or gnus-summary-respool-default-method
8761                                   (car (gnus-find-method-for-group
8762                                         gnus-newsgroup-name)))))
8763                 (method
8764                  (gnus-completing-read-with-default
8765                   methname "What backend do you want to use when respooling?"
8766                   methods nil t nil 'gnus-mail-method-history))
8767                 ms)
8768            (cond
8769             ((zerop (length (setq ms (gnus-servers-using-backend
8770                                       (intern method)))))
8771              (list (intern method) ""))
8772             ((= 1 (length ms))
8773              (car ms))
8774             (t
8775              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8776                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8777                            ms-alist))))))))
8778   (unless method
8779     (error "No method given for respooling"))
8780   (if (assoc (symbol-name
8781               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8782              (gnus-methods-using 'respool))
8783       (gnus-summary-move-article n nil method)
8784     (gnus-summary-copy-article n nil method)))
8785
8786 (defun gnus-summary-import-article (file &optional edit)
8787   "Import an arbitrary file into a mail newsgroup."
8788   (interactive "fImport file: \nP")
8789   (let ((group gnus-newsgroup-name)
8790         (now (current-time))
8791         atts lines group-art)
8792     (unless (gnus-check-backend-function 'request-accept-article group)
8793       (error "%s does not support article importing" group))
8794     (or (file-readable-p file)
8795         (not (file-regular-p file))
8796         (error "Can't read %s" file))
8797     (save-excursion
8798       (set-buffer (gnus-get-buffer-create " *import file*"))
8799       (erase-buffer)
8800       (nnheader-insert-file-contents file)
8801       (goto-char (point-min))
8802       (if (nnheader-article-p)
8803           (save-restriction
8804             (goto-char (point-min))
8805             (search-forward "\n\n" nil t)
8806             (narrow-to-region (point-min) (1- (point)))
8807             (goto-char (point-min))
8808             (unless (re-search-forward "^date:" nil t)
8809               (goto-char (point-max))
8810               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8811         ;; This doesn't look like an article, so we fudge some headers.
8812         (setq atts (file-attributes file)
8813               lines (count-lines (point-min) (point-max)))
8814         (insert "From: " (read-string "From: ") "\n"
8815                 "Subject: " (read-string "Subject: ") "\n"
8816                 "Date: " (message-make-date (nth 5 atts)) "\n"
8817                 "Message-ID: " (message-make-message-id) "\n"
8818                 "Lines: " (int-to-string lines) "\n"
8819                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8820       (setq group-art (gnus-request-accept-article group nil t))
8821       (kill-buffer (current-buffer)))
8822     (setq gnus-newsgroup-active (gnus-activate-group group))
8823     (forward-line 1)
8824     (gnus-summary-goto-article (cdr group-art) nil t)
8825     (when edit
8826       (gnus-summary-edit-article))))
8827
8828 (defun gnus-summary-create-article ()
8829   "Create an article in a mail newsgroup."
8830   (interactive)
8831   (let ((group gnus-newsgroup-name)
8832         (now (current-time))
8833         group-art)
8834     (unless (gnus-check-backend-function 'request-accept-article group)
8835       (error "%s does not support article importing" group))
8836     (save-excursion
8837       (set-buffer (gnus-get-buffer-create " *import file*"))
8838       (erase-buffer)
8839       (goto-char (point-min))
8840       ;; This doesn't look like an article, so we fudge some headers.
8841       (insert "From: " (read-string "From: ") "\n"
8842               "Subject: " (read-string "Subject: ") "\n"
8843               "Date: " (message-make-date now) "\n"
8844               "Message-ID: " (message-make-message-id) "\n")
8845       (setq group-art (gnus-request-accept-article group nil t))
8846       (kill-buffer (current-buffer)))
8847     (setq gnus-newsgroup-active (gnus-activate-group group))
8848     (forward-line 1)
8849     (gnus-summary-goto-article (cdr group-art) nil t)
8850     (gnus-summary-edit-article)))
8851
8852 (defun gnus-summary-article-posted-p ()
8853   "Say whether the current (mail) article is available from news as well.
8854 This will be the case if the article has both been mailed and posted."
8855   (interactive)
8856   (let ((id (mail-header-references (gnus-summary-article-header)))
8857         (gnus-override-method (car (gnus-refer-article-methods))))
8858     (if (gnus-request-head id "")
8859         (gnus-message 2 "The current message was found on %s"
8860                       gnus-override-method)
8861       (gnus-message 2 "The current message couldn't be found on %s"
8862                     gnus-override-method)
8863       nil)))
8864
8865 (defun gnus-summary-expire-articles (&optional now)
8866   "Expire all articles that are marked as expirable in the current group."
8867   (interactive)
8868   (when (gnus-check-backend-function
8869          'request-expire-articles gnus-newsgroup-name)
8870     ;; This backend supports expiry.
8871     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8872            (expirable (if total
8873                           (progn
8874                             ;; We need to update the info for
8875                             ;; this group for `gnus-list-of-read-articles'
8876                             ;; to give us the right answer.
8877                             (gnus-run-hooks 'gnus-exit-group-hook)
8878                             (gnus-summary-update-info)
8879                             (gnus-list-of-read-articles gnus-newsgroup-name))
8880                         (setq gnus-newsgroup-expirable
8881                               (sort gnus-newsgroup-expirable '<))))
8882            (expiry-wait (if now 'immediate
8883                           (gnus-group-find-parameter
8884                            gnus-newsgroup-name 'expiry-wait)))
8885            (nnmail-expiry-target
8886             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8887                 nnmail-expiry-target))
8888            es)
8889       (when expirable
8890         ;; There are expirable articles in this group, so we run them
8891         ;; through the expiry process.
8892         (gnus-message 6 "Expiring articles...")
8893         (unless (gnus-check-group gnus-newsgroup-name)
8894           (error "Can't open server for %s" gnus-newsgroup-name))
8895         ;; The list of articles that weren't expired is returned.
8896         (save-excursion
8897           (if expiry-wait
8898               (let ((nnmail-expiry-wait-function nil)
8899                     (nnmail-expiry-wait expiry-wait))
8900                 (setq es (gnus-request-expire-articles
8901                           expirable gnus-newsgroup-name)))
8902             (setq es (gnus-request-expire-articles
8903                       expirable gnus-newsgroup-name)))
8904           (unless total
8905             (setq gnus-newsgroup-expirable es))
8906           ;; We go through the old list of expirable, and mark all
8907           ;; really expired articles as nonexistent.
8908           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8909             (let ((gnus-use-cache nil))
8910               (dolist (article expirable)
8911                 (when (and (not (memq article es))
8912                            (gnus-data-find article))
8913                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8914         (gnus-message 6 "Expiring articles...done")))))
8915
8916 (defun gnus-summary-expire-articles-now ()
8917   "Expunge all expirable articles in the current group.
8918 This means that *all* articles that are marked as expirable will be
8919 deleted forever, right now."
8920   (interactive)
8921   (or gnus-expert-user
8922       (gnus-yes-or-no-p
8923        "Are you really, really, really sure you want to delete all these messages? ")
8924       (error "Phew!"))
8925   (gnus-summary-expire-articles t))
8926
8927 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8928 (defun gnus-summary-delete-article (&optional n)
8929   "Delete the N next (mail) articles.
8930 This command actually deletes articles.  This is not a marking
8931 command.  The article will disappear forever from your life, never to
8932 return.
8933 If N is negative, delete backwards.
8934 If N is nil and articles have been marked with the process mark,
8935 delete these instead."
8936   (interactive "P")
8937   (unless (gnus-check-backend-function 'request-expire-articles
8938                                        gnus-newsgroup-name)
8939     (error "The current newsgroup does not support article deletion"))
8940   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8941     (error "Couldn't open server"))
8942   ;; Compute the list of articles to delete.
8943   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8944         not-deleted)
8945     (if (and gnus-novice-user
8946              (not (gnus-yes-or-no-p
8947                    (format "Do you really want to delete %s forever? "
8948                            (if (> (length articles) 1)
8949                                (format "these %s articles" (length articles))
8950                              "this article")))))
8951         ()
8952       ;; Delete the articles.
8953       (setq not-deleted (gnus-request-expire-articles
8954                          articles gnus-newsgroup-name 'force))
8955       (while articles
8956         (gnus-summary-remove-process-mark (car articles))
8957         ;; The backend might not have been able to delete the article
8958         ;; after all.
8959         (unless (memq (car articles) not-deleted)
8960           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8961         (setq articles (cdr articles)))
8962       (when not-deleted
8963         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8964     (gnus-summary-position-point)
8965     (gnus-set-mode-line 'summary)
8966     not-deleted))
8967
8968 (defun gnus-summary-edit-article (&optional force)
8969   "Edit the current article.
8970 This will have permanent effect only in mail groups.
8971 If FORCE is non-nil, allow editing of articles even in read-only
8972 groups."
8973   (interactive "P")
8974   (save-excursion
8975     (set-buffer gnus-summary-buffer)
8976     (let ((mail-parse-charset gnus-newsgroup-charset)
8977           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8978       (gnus-set-global-variables)
8979       (when (and (not force)
8980                  (gnus-group-read-only-p))
8981         (error "The current newsgroup does not support article editing"))
8982       (gnus-summary-show-article t)
8983       (gnus-article-edit-article
8984        'ignore
8985        `(lambda (no-highlight)
8986           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8987                 (message-options message-options)
8988                 (message-options-set-recipient)
8989                 (mail-parse-ignored-charsets
8990                  ',gnus-newsgroup-ignored-charsets))
8991             (gnus-summary-edit-article-done
8992              ,(or (mail-header-references gnus-current-headers) "")
8993              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8994
8995 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8996
8997 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8998                                                  no-highlight)
8999   "Make edits to the current article permanent."
9000   (interactive)
9001   (save-excursion
9002     ;; The buffer restriction contains the entire article if it exists.
9003     (when (article-goto-body)
9004       (let ((lines (count-lines (point) (point-max)))
9005             (length (- (point-max) (point)))
9006             (case-fold-search t)
9007             (body (copy-marker (point))))
9008         (goto-char (point-min))
9009         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9010           (delete-region (match-beginning 1) (match-end 1))
9011           (insert (number-to-string length)))
9012         (goto-char (point-min))
9013         (when (re-search-forward
9014                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9015           (delete-region (match-beginning 1) (match-end 1))
9016           (insert (number-to-string length)))
9017         (goto-char (point-min))
9018         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9019           (delete-region (match-beginning 1) (match-end 1))
9020           (insert (number-to-string lines))))))
9021   ;; Replace the article.
9022   (let ((buf (current-buffer)))
9023     (with-temp-buffer
9024       (insert-buffer-substring buf)
9025
9026       (if (and (not read-only)
9027                (not (gnus-request-replace-article
9028                      (cdr gnus-article-current) (car gnus-article-current)
9029                      (current-buffer) t)))
9030           (error "Couldn't replace article")
9031         ;; Update the summary buffer.
9032         (if (and references
9033                  (equal (message-tokenize-header references " ")
9034                         (message-tokenize-header
9035                          (or (message-fetch-field "references") "") " ")))
9036             ;; We only have to update this line.
9037             (save-excursion
9038               (save-restriction
9039                 (message-narrow-to-head)
9040                 (let ((head (buffer-string))
9041                       header)
9042                   (with-temp-buffer
9043                     (insert (format "211 %d Article retrieved.\n"
9044                                     (cdr gnus-article-current)))
9045                     (insert head)
9046                     (insert ".\n")
9047                     (let ((nntp-server-buffer (current-buffer)))
9048                       (setq header (car (gnus-get-newsgroup-headers
9049                                          nil t))))
9050                     (save-excursion
9051                       (set-buffer gnus-summary-buffer)
9052                       (gnus-data-set-header
9053                        (gnus-data-find (cdr gnus-article-current))
9054                        header)
9055                       (gnus-summary-update-article-line
9056                        (cdr gnus-article-current) header)
9057                       (if (gnus-summary-goto-subject
9058                            (cdr gnus-article-current) nil t)
9059                           (gnus-summary-update-secondary-mark
9060                            (cdr gnus-article-current))))))))
9061           ;; Update threads.
9062           (set-buffer (or buffer gnus-summary-buffer))
9063           (gnus-summary-update-article (cdr gnus-article-current))
9064           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9065               (gnus-summary-update-secondary-mark
9066                (cdr gnus-article-current))))
9067         ;; Prettify the article buffer again.
9068         (unless no-highlight
9069           (save-excursion
9070             (set-buffer gnus-article-buffer)
9071             ;;;!!! Fix this -- article should be rehighlighted.
9072             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9073             (set-buffer gnus-original-article-buffer)
9074             (gnus-request-article
9075              (cdr gnus-article-current)
9076              (car gnus-article-current) (current-buffer))))
9077         ;; Prettify the summary buffer line.
9078         (when (gnus-visual-p 'summary-highlight 'highlight)
9079           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9080
9081 (defun gnus-summary-edit-wash (key)
9082   "Perform editing command KEY in the article buffer."
9083   (interactive
9084    (list
9085     (progn
9086       (message "%s" (concat (this-command-keys) "- "))
9087       (read-char))))
9088   (message "")
9089   (gnus-summary-edit-article)
9090   (execute-kbd-macro (concat (this-command-keys) key))
9091   (gnus-article-edit-done))
9092
9093 ;;; Respooling
9094
9095 (defun gnus-summary-respool-query (&optional silent trace)
9096   "Query where the respool algorithm would put this article."
9097   (interactive)
9098   (let (gnus-mark-article-hook)
9099     (gnus-summary-select-article)
9100     (save-excursion
9101       (set-buffer gnus-original-article-buffer)
9102       (save-restriction
9103         (message-narrow-to-head)
9104         (let ((groups (nnmail-article-group 'identity trace)))
9105           (unless silent
9106             (if groups
9107                 (message "This message would go to %s"
9108                          (mapconcat 'car groups ", "))
9109               (message "This message would go to no groups"))
9110             groups))))))
9111
9112 (defun gnus-summary-respool-trace ()
9113   "Trace where the respool algorithm would put this article.
9114 Display a buffer showing all fancy splitting patterns which matched."
9115   (interactive)
9116   (gnus-summary-respool-query nil t))
9117
9118 ;; Summary marking commands.
9119
9120 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9121   "Mark articles which has the same subject as read, and then select the next.
9122 If UNMARK is positive, remove any kind of mark.
9123 If UNMARK is negative, tick articles."
9124   (interactive "P")
9125   (when unmark
9126     (setq unmark (prefix-numeric-value unmark)))
9127   (let ((count
9128          (gnus-summary-mark-same-subject
9129           (gnus-summary-article-subject) unmark)))
9130     ;; Select next unread article.  If auto-select-same mode, should
9131     ;; select the first unread article.
9132     (gnus-summary-next-article t (and gnus-auto-select-same
9133                                       (gnus-summary-article-subject)))
9134     (gnus-message 7 "%d article%s marked as %s"
9135                   count (if (= count 1) " is" "s are")
9136                   (if unmark "unread" "read"))))
9137
9138 (defun gnus-summary-kill-same-subject (&optional unmark)
9139   "Mark articles which has the same subject as read.
9140 If UNMARK is positive, remove any kind of mark.
9141 If UNMARK is negative, tick articles."
9142   (interactive "P")
9143   (when unmark
9144     (setq unmark (prefix-numeric-value unmark)))
9145   (let ((count
9146          (gnus-summary-mark-same-subject
9147           (gnus-summary-article-subject) unmark)))
9148     ;; If marked as read, go to next unread subject.
9149     (when (null unmark)
9150       ;; Go to next unread subject.
9151       (gnus-summary-next-subject 1 t))
9152     (gnus-message 7 "%d articles are marked as %s"
9153                   count (if unmark "unread" "read"))))
9154
9155 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9156   "Mark articles with same SUBJECT as read, and return marked number.
9157 If optional argument UNMARK is positive, remove any kinds of marks.
9158 If optional argument UNMARK is negative, mark articles as unread instead."
9159   (let ((count 1))
9160     (save-excursion
9161       (cond
9162        ((null unmark)                   ; Mark as read.
9163         (while (and
9164                 (progn
9165                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9166                   (gnus-summary-show-thread) t)
9167                 (gnus-summary-find-subject subject))
9168           (setq count (1+ count))))
9169        ((> unmark 0)                    ; Tick.
9170         (while (and
9171                 (progn
9172                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9173                   (gnus-summary-show-thread) t)
9174                 (gnus-summary-find-subject subject))
9175           (setq count (1+ count))))
9176        (t                               ; Mark as unread.
9177         (while (and
9178                 (progn
9179                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9180                   (gnus-summary-show-thread) t)
9181                 (gnus-summary-find-subject subject))
9182           (setq count (1+ count)))))
9183       (gnus-set-mode-line 'summary)
9184       ;; Return the number of marked articles.
9185       count)))
9186
9187 (defun gnus-summary-mark-as-processable (n &optional unmark)
9188   "Set the process mark on the next N articles.
9189 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9190 the process mark instead.  The difference between N and the actual
9191 number of articles marked is returned."
9192   (interactive "P")
9193   (if (and (null n) (gnus-region-active-p))
9194       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9195     (setq n (prefix-numeric-value n))
9196     (let ((backward (< n 0))
9197           (n (abs n)))
9198       (while (and
9199               (> n 0)
9200               (if unmark
9201                   (gnus-summary-remove-process-mark
9202                    (gnus-summary-article-number))
9203                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9204               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9205         (setq n (1- n)))
9206       (when (/= 0 n)
9207         (gnus-message 7 "No more articles"))
9208       (gnus-summary-recenter)
9209       (gnus-summary-position-point)
9210       n)))
9211
9212 (defun gnus-summary-unmark-as-processable (n)
9213   "Remove the process mark from the next N articles.
9214 If N is negative, unmark backward instead.  The difference between N and
9215 the actual number of articles unmarked is returned."
9216   (interactive "P")
9217   (gnus-summary-mark-as-processable n t))
9218
9219 (defun gnus-summary-unmark-all-processable ()
9220   "Remove the process mark from all articles."
9221   (interactive)
9222   (save-excursion
9223     (while gnus-newsgroup-processable
9224       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9225   (gnus-summary-position-point))
9226
9227 (defun gnus-summary-add-mark (article type)
9228   "Mark ARTICLE with a mark of TYPE."
9229   (let ((vtype (car (assq type gnus-article-mark-lists)))
9230         var)
9231     (if (not vtype)
9232         (error "No such mark type: %s" type)
9233       (setq var (intern (format "gnus-newsgroup-%s" type)))
9234       (set var (cons article (symbol-value var)))
9235       (if (memq type '(processable cached replied forwarded recent saved))
9236           (gnus-summary-update-secondary-mark article)
9237         ;;; !!! This is bogus.  We should find out what primary
9238         ;;; !!! mark we want to set.
9239         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9240
9241 (defun gnus-summary-mark-as-expirable (n)
9242   "Mark N articles forward as expirable.
9243 If N is negative, mark backward instead.  The difference between N and
9244 the actual number of articles marked is returned."
9245   (interactive "p")
9246   (gnus-summary-mark-forward n gnus-expirable-mark))
9247
9248 (defun gnus-summary-mark-as-spam (n)
9249   "Mark N articles forward as spam.
9250 If N is negative, mark backward instead.  The difference between N and
9251 the actual number of articles marked is returned."
9252   (interactive "p")
9253   (gnus-summary-mark-forward n gnus-spam-mark))
9254
9255 (defun gnus-summary-mark-article-as-replied (article)
9256   "Mark ARTICLE as replied to and update the summary line.
9257 ARTICLE can also be a list of articles."
9258   (interactive (list (gnus-summary-article-number)))
9259   (let ((articles (if (listp article) article (list article))))
9260     (dolist (article articles)
9261       (push article gnus-newsgroup-replied)
9262       (let ((buffer-read-only nil))
9263         (when (gnus-summary-goto-subject article nil t)
9264           (gnus-summary-update-secondary-mark article))))))
9265
9266 (defun gnus-summary-mark-article-as-forwarded (article)
9267   "Mark ARTICLE as forwarded and update the summary line.
9268 ARTICLE can also be a list of articles."
9269   (let ((articles (if (listp article) article (list article))))
9270     (dolist (article articles)
9271       (push article gnus-newsgroup-forwarded)
9272       (let ((buffer-read-only nil))
9273         (when (gnus-summary-goto-subject article nil t)
9274           (gnus-summary-update-secondary-mark article))))))
9275
9276 (defun gnus-summary-set-bookmark (article)
9277   "Set a bookmark in current article."
9278   (interactive (list (gnus-summary-article-number)))
9279   (when (or (not (get-buffer gnus-article-buffer))
9280             (not gnus-current-article)
9281             (not gnus-article-current)
9282             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9283     (error "No current article selected"))
9284   ;; Remove old bookmark, if one exists.
9285   (let ((old (assq article gnus-newsgroup-bookmarks)))
9286     (when old
9287       (setq gnus-newsgroup-bookmarks
9288             (delq old gnus-newsgroup-bookmarks))))
9289   ;; Set the new bookmark, which is on the form
9290   ;; (article-number . line-number-in-body).
9291   (push
9292    (cons article
9293          (save-excursion
9294            (set-buffer gnus-article-buffer)
9295            (count-lines
9296             (min (point)
9297                  (save-excursion
9298                    (goto-char (point-min))
9299                    (search-forward "\n\n" nil t)
9300                    (point)))
9301             (point))))
9302    gnus-newsgroup-bookmarks)
9303   (gnus-message 6 "A bookmark has been added to the current article."))
9304
9305 (defun gnus-summary-remove-bookmark (article)
9306   "Remove the bookmark from the current article."
9307   (interactive (list (gnus-summary-article-number)))
9308   ;; Remove old bookmark, if one exists.
9309   (let ((old (assq article gnus-newsgroup-bookmarks)))
9310     (if old
9311         (progn
9312           (setq gnus-newsgroup-bookmarks
9313                 (delq old gnus-newsgroup-bookmarks))
9314           (gnus-message 6 "Removed bookmark."))
9315       (gnus-message 6 "No bookmark in current article."))))
9316
9317 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9318 (defun gnus-summary-mark-as-dormant (n)
9319   "Mark N articles forward as dormant.
9320 If N is negative, mark backward instead.  The difference between N and
9321 the actual number of articles marked is returned."
9322   (interactive "p")
9323   (gnus-summary-mark-forward n gnus-dormant-mark))
9324
9325 (defun gnus-summary-set-process-mark (article)
9326   "Set the process mark on ARTICLE and update the summary line."
9327   (setq gnus-newsgroup-processable
9328         (cons article
9329               (delq article gnus-newsgroup-processable)))
9330   (when (gnus-summary-goto-subject article)
9331     (gnus-summary-show-thread)
9332     (gnus-summary-goto-subject article)
9333     (gnus-summary-update-secondary-mark article)))
9334
9335 (defun gnus-summary-remove-process-mark (article)
9336   "Remove the process mark from ARTICLE and update the summary line."
9337   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9338   (when (gnus-summary-goto-subject article)
9339     (gnus-summary-show-thread)
9340     (gnus-summary-goto-subject article)
9341     (gnus-summary-update-secondary-mark article)))
9342
9343 (defun gnus-summary-set-saved-mark (article)
9344   "Set the process mark on ARTICLE and update the summary line."
9345   (push article gnus-newsgroup-saved)
9346   (when (gnus-summary-goto-subject article)
9347     (gnus-summary-update-secondary-mark article)))
9348
9349 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9350   "Mark N articles as read forwards.
9351 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9352 The difference between N and the actual number of articles marked is
9353 returned.
9354 Iff NO-EXPIRE, auto-expiry will be inhibited."
9355   (interactive "p")
9356   (gnus-summary-show-thread)
9357   (let ((backward (< n 0))
9358         (gnus-summary-goto-unread
9359          (and gnus-summary-goto-unread
9360               (not (eq gnus-summary-goto-unread 'never))
9361               (not (memq mark (list gnus-unread-mark
9362                                     gnus-ticked-mark gnus-dormant-mark)))))
9363         (n (abs n))
9364         (mark (or mark gnus-del-mark)))
9365     (while (and (> n 0)
9366                 (gnus-summary-mark-article nil mark no-expire)
9367                 (zerop (gnus-summary-next-subject
9368                         (if backward -1 1)
9369                         (and gnus-summary-goto-unread
9370                              (not (eq gnus-summary-goto-unread 'never)))
9371                         t)))
9372       (setq n (1- n)))
9373     (when (/= 0 n)
9374       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9375     (gnus-summary-recenter)
9376     (gnus-summary-position-point)
9377     (gnus-set-mode-line 'summary)
9378     n))
9379
9380 (defun gnus-summary-mark-article-as-read (mark)
9381   "Mark the current article quickly as read with MARK."
9382   (let ((article (gnus-summary-article-number)))
9383     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9384     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9385     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9386     (push (cons article mark) gnus-newsgroup-reads)
9387     ;; Possibly remove from cache, if that is used.
9388     (when gnus-use-cache
9389       (gnus-cache-enter-remove-article article))
9390     ;; Allow the backend to change the mark.
9391     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9392     ;; Check for auto-expiry.
9393     (when (and gnus-newsgroup-auto-expire
9394                (memq mark gnus-auto-expirable-marks))
9395       (setq mark gnus-expirable-mark)
9396       ;; Let the backend know about the mark change.
9397       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9398       (push article gnus-newsgroup-expirable))
9399     ;; Set the mark in the buffer.
9400     (gnus-summary-update-mark mark 'unread)
9401     t))
9402
9403 (defun gnus-summary-mark-article-as-unread (mark)
9404   "Mark the current article quickly as unread with MARK."
9405   (let* ((article (gnus-summary-article-number))
9406          (old-mark (gnus-summary-article-mark article)))
9407     ;; Allow the backend to change the mark.
9408     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9409     (if (eq mark old-mark)
9410         t
9411       (if (<= article 0)
9412           (progn
9413             (gnus-error 1 "Can't mark negative article numbers")
9414             nil)
9415         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9416         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9417         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9418         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9419         (cond ((= mark gnus-ticked-mark)
9420                (setq gnus-newsgroup-marked
9421                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9422                                               article)))
9423               ((= mark gnus-dormant-mark)
9424                (setq gnus-newsgroup-dormant
9425                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9426                                               article)))
9427               (t
9428                (setq gnus-newsgroup-unreads
9429                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9430                                               article))))
9431         (gnus-pull article gnus-newsgroup-reads)
9432
9433         ;; See whether the article is to be put in the cache.
9434         (and gnus-use-cache
9435              (vectorp (gnus-summary-article-header article))
9436              (save-excursion
9437                (gnus-cache-possibly-enter-article
9438                 gnus-newsgroup-name article
9439                 (gnus-summary-article-header article)
9440                 (= mark gnus-ticked-mark)
9441                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9442
9443         ;; Fix the mark.
9444         (gnus-summary-update-mark mark 'unread)
9445         t))))
9446
9447 (defun gnus-summary-mark-article (&optional article mark no-expire)
9448   "Mark ARTICLE with MARK.  MARK can be any character.
9449 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9450 `??' (dormant) and `?E' (expirable).
9451 If MARK is nil, then the default character `?r' is used.
9452 If ARTICLE is nil, then the article on the current line will be
9453 marked.
9454 Iff NO-EXPIRE, auto-expiry will be inhibited."
9455   ;; The mark might be a string.
9456   (when (stringp mark)
9457     (setq mark (aref mark 0)))
9458   ;; If no mark is given, then we check auto-expiring.
9459   (when (null mark)
9460     (setq mark gnus-del-mark))
9461   (when (and (not no-expire)
9462              gnus-newsgroup-auto-expire
9463              (memq mark gnus-auto-expirable-marks))
9464     (setq mark gnus-expirable-mark))
9465   (let ((article (or article (gnus-summary-article-number)))
9466         (old-mark (gnus-summary-article-mark article)))
9467     ;; Allow the backend to change the mark.
9468     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9469     (if (eq mark old-mark)
9470         t
9471       (unless article
9472         (error "No article on current line"))
9473       (if (not (if (or (= mark gnus-unread-mark)
9474                        (= mark gnus-ticked-mark)
9475                        (= mark gnus-dormant-mark))
9476                    (gnus-mark-article-as-unread article mark)
9477                  (gnus-mark-article-as-read article mark)))
9478           t
9479         ;; See whether the article is to be put in the cache.
9480         (and gnus-use-cache
9481              (not (= mark gnus-canceled-mark))
9482              (vectorp (gnus-summary-article-header article))
9483              (save-excursion
9484                (gnus-cache-possibly-enter-article
9485                 gnus-newsgroup-name article
9486                 (gnus-summary-article-header article)
9487                 (= mark gnus-ticked-mark)
9488                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9489
9490         (when (gnus-summary-goto-subject article nil t)
9491           (let ((buffer-read-only nil))
9492             (gnus-summary-show-thread)
9493             ;; Fix the mark.
9494             (gnus-summary-update-mark mark 'unread)
9495             t))))))
9496
9497 (defun gnus-summary-update-secondary-mark (article)
9498   "Update the secondary (read, process, cache) mark."
9499   (gnus-summary-update-mark
9500    (cond ((memq article gnus-newsgroup-processable)
9501           gnus-process-mark)
9502          ((memq article gnus-newsgroup-cached)
9503           gnus-cached-mark)
9504          ((memq article gnus-newsgroup-replied)
9505           gnus-replied-mark)
9506          ((memq article gnus-newsgroup-forwarded)
9507           gnus-forwarded-mark)
9508          ((memq article gnus-newsgroup-saved)
9509           gnus-saved-mark)
9510          ((memq article gnus-newsgroup-recent)
9511           gnus-recent-mark)
9512          ((memq article gnus-newsgroup-unseen)
9513           gnus-unseen-mark)
9514          (t gnus-no-mark))
9515    'replied)
9516   (when (gnus-visual-p 'summary-highlight 'highlight)
9517     (gnus-run-hooks 'gnus-summary-update-hook))
9518   t)
9519
9520 (defun gnus-summary-update-mark (mark type)
9521   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9522         (buffer-read-only nil))
9523     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9524     (when forward
9525       (when (looking-at "\r")
9526         (incf forward))
9527       (when (<= (+ forward (point)) (point-max))
9528         ;; Go to the right position on the line.
9529         (goto-char (+ forward (point)))
9530         ;; Replace the old mark with the new mark.
9531         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9532         ;; Optionally update the marks by some user rule.
9533         (when (eq type 'unread)
9534           (gnus-data-set-mark
9535            (gnus-data-find (gnus-summary-article-number)) mark)
9536           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9537
9538 (defun gnus-mark-article-as-read (article &optional mark)
9539   "Enter ARTICLE in the pertinent lists and remove it from others."
9540   ;; Make the article expirable.
9541   (let ((mark (or mark gnus-del-mark)))
9542     (setq gnus-newsgroup-expirable
9543           (if (= mark gnus-expirable-mark)
9544               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9545             (delq article gnus-newsgroup-expirable)))
9546     ;; Remove from unread and marked lists.
9547     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9548     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9549     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9550     (push (cons article mark) gnus-newsgroup-reads)
9551     ;; Possibly remove from cache, if that is used.
9552     (when gnus-use-cache
9553       (gnus-cache-enter-remove-article article))
9554     t))
9555
9556 (defun gnus-mark-article-as-unread (article &optional mark)
9557   "Enter ARTICLE in the pertinent lists and remove it from others."
9558   (let ((mark (or mark gnus-ticked-mark)))
9559     (if (<= article 0)
9560         (progn
9561           (gnus-error 1 "Can't mark negative article numbers")
9562           nil)
9563       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9564             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9565             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9566             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9567
9568       ;; Unsuppress duplicates?
9569       (when gnus-suppress-duplicates
9570         (gnus-dup-unsuppress-article article))
9571
9572       (cond ((= mark gnus-ticked-mark)
9573              (setq gnus-newsgroup-marked
9574                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9575             ((= mark gnus-dormant-mark)
9576              (setq gnus-newsgroup-dormant
9577                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9578             (t
9579              (setq gnus-newsgroup-unreads
9580                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9581       (gnus-pull article gnus-newsgroup-reads)
9582       t)))
9583
9584 (defalias 'gnus-summary-mark-as-unread-forward
9585   'gnus-summary-tick-article-forward)
9586 (make-obsolete 'gnus-summary-mark-as-unread-forward
9587                'gnus-summary-tick-article-forward)
9588 (defun gnus-summary-tick-article-forward (n)
9589   "Tick N articles forwards.
9590 If N is negative, tick backwards instead.
9591 The difference between N and the number of articles ticked is returned."
9592   (interactive "p")
9593   (gnus-summary-mark-forward n gnus-ticked-mark))
9594
9595 (defalias 'gnus-summary-mark-as-unread-backward
9596   'gnus-summary-tick-article-backward)
9597 (make-obsolete 'gnus-summary-mark-as-unread-backward
9598                'gnus-summary-tick-article-backward)
9599 (defun gnus-summary-tick-article-backward (n)
9600   "Tick N articles backwards.
9601 The difference between N and the number of articles ticked is returned."
9602   (interactive "p")
9603   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9604
9605 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9606 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9607 (defun gnus-summary-tick-article (&optional article clear-mark)
9608   "Mark current article as unread.
9609 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9610 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9611   (interactive)
9612   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9613                                        gnus-ticked-mark)))
9614
9615 (defun gnus-summary-mark-as-read-forward (n)
9616   "Mark N articles as read forwards.
9617 If N is negative, mark backwards instead.
9618 The difference between N and the actual number of articles marked is
9619 returned."
9620   (interactive "p")
9621   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9622
9623 (defun gnus-summary-mark-as-read-backward (n)
9624   "Mark the N articles as read backwards.
9625 The difference between N and the actual number of articles marked is
9626 returned."
9627   (interactive "p")
9628   (gnus-summary-mark-forward
9629    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9630
9631 (defun gnus-summary-mark-as-read (&optional article mark)
9632   "Mark current article as read.
9633 ARTICLE specifies the article to be marked as read.
9634 MARK specifies a string to be inserted at the beginning of the line."
9635   (gnus-summary-mark-article article mark))
9636
9637 (defun gnus-summary-clear-mark-forward (n)
9638   "Clear marks from N articles forward.
9639 If N is negative, clear backward instead.
9640 The difference between N and the number of marks cleared is returned."
9641   (interactive "p")
9642   (gnus-summary-mark-forward n gnus-unread-mark))
9643
9644 (defun gnus-summary-clear-mark-backward (n)
9645   "Clear marks from N articles backward.
9646 The difference between N and the number of marks cleared is returned."
9647   (interactive "p")
9648   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9649
9650 (defun gnus-summary-mark-unread-as-read ()
9651   "Intended to be used by `gnus-summary-mark-article-hook'."
9652   (when (memq gnus-current-article gnus-newsgroup-unreads)
9653     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9654
9655 (defun gnus-summary-mark-read-and-unread-as-read ()
9656   "Intended to be used by `gnus-summary-mark-article-hook'."
9657   (let ((mark (gnus-summary-article-mark)))
9658     (when (or (gnus-unread-mark-p mark)
9659               (gnus-read-mark-p mark))
9660       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9661
9662 (defun gnus-summary-mark-unread-as-ticked ()
9663   "Intended to be used by `gnus-summary-mark-article-hook'."
9664   (when (memq gnus-current-article gnus-newsgroup-unreads)
9665     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9666
9667 (defun gnus-summary-mark-region-as-read (point mark all)
9668   "Mark all unread articles between point and mark as read.
9669 If given a prefix, mark all articles between point and mark as read,
9670 even ticked and dormant ones."
9671   (interactive "r\nP")
9672   (save-excursion
9673     (let (article)
9674       (goto-char point)
9675       (beginning-of-line)
9676       (while (and
9677               (< (point) mark)
9678               (progn
9679                 (when (or all
9680                           (memq (setq article (gnus-summary-article-number))
9681                                 gnus-newsgroup-unreads))
9682                   (gnus-summary-mark-article article gnus-del-mark))
9683                 t)
9684               (gnus-summary-find-next))))))
9685
9686 (defun gnus-summary-mark-below (score mark)
9687   "Mark articles with score less than SCORE with MARK."
9688   (interactive "P\ncMark: ")
9689   (setq score (if score
9690                   (prefix-numeric-value score)
9691                 (or gnus-summary-default-score 0)))
9692   (save-excursion
9693     (set-buffer gnus-summary-buffer)
9694     (goto-char (point-min))
9695     (while
9696         (progn
9697           (and (< (gnus-summary-article-score) score)
9698                (gnus-summary-mark-article nil mark))
9699           (gnus-summary-find-next)))))
9700
9701 (defun gnus-summary-kill-below (&optional score)
9702   "Mark articles with score below SCORE as read."
9703   (interactive "P")
9704   (gnus-summary-mark-below score gnus-killed-mark))
9705
9706 (defun gnus-summary-clear-above (&optional score)
9707   "Clear all marks from articles with score above SCORE."
9708   (interactive "P")
9709   (gnus-summary-mark-above score gnus-unread-mark))
9710
9711 (defun gnus-summary-tick-above (&optional score)
9712   "Tick all articles with score above SCORE."
9713   (interactive "P")
9714   (gnus-summary-mark-above score gnus-ticked-mark))
9715
9716 (defun gnus-summary-mark-above (score mark)
9717   "Mark articles with score over SCORE with MARK."
9718   (interactive "P\ncMark: ")
9719   (setq score (if score
9720                   (prefix-numeric-value score)
9721                 (or gnus-summary-default-score 0)))
9722   (save-excursion
9723     (set-buffer gnus-summary-buffer)
9724     (goto-char (point-min))
9725     (while (and (progn
9726                   (when (> (gnus-summary-article-score) score)
9727                     (gnus-summary-mark-article nil mark))
9728                   t)
9729                 (gnus-summary-find-next)))))
9730
9731 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9732 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9733 (defun gnus-summary-limit-include-expunged (&optional no-error)
9734   "Display all the hidden articles that were expunged for low scores."
9735   (interactive)
9736   (let ((buffer-read-only nil))
9737     (let ((scored gnus-newsgroup-scored)
9738           headers h)
9739       (while scored
9740         (unless (gnus-summary-article-header (caar scored))
9741           (and (setq h (gnus-number-to-header (caar scored)))
9742                (< (cdar scored) gnus-summary-expunge-below)
9743                (push h headers)))
9744         (setq scored (cdr scored)))
9745       (if (not headers)
9746           (when (not no-error)
9747             (error "No expunged articles hidden"))
9748         (goto-char (point-min))
9749         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9750         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9751         (mapcar (lambda (x) (push (mail-header-number x)
9752                                   gnus-newsgroup-limit))
9753                 headers)
9754         (gnus-summary-prepare-unthreaded (nreverse headers))
9755         (goto-char (point-min))
9756         (gnus-summary-position-point)
9757         t))))
9758
9759 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9760   "Mark all unread articles in this newsgroup as read.
9761 If prefix argument ALL is non-nil, ticked and dormant articles will
9762 also be marked as read.
9763 If QUIETLY is non-nil, no questions will be asked.
9764 If TO-HERE is non-nil, it should be a point in the buffer.  All
9765 articles before (after, if REVERSE is set) this point will be marked as read.
9766 Note that this function will only catch up the unread article
9767 in the current summary buffer limitation.
9768 The number of articles marked as read is returned."
9769   (interactive "P")
9770   (prog1
9771       (save-excursion
9772         (when (or quietly
9773                   (not gnus-interactive-catchup) ;Without confirmation?
9774                   gnus-expert-user
9775                   (gnus-y-or-n-p
9776                    (if all
9777                        "Mark absolutely all articles as read? "
9778                      "Mark all unread articles as read? ")))
9779           (if (and not-mark
9780                    (not gnus-newsgroup-adaptive)
9781                    (not gnus-newsgroup-auto-expire)
9782                    (not gnus-suppress-duplicates)
9783                    (or (not gnus-use-cache)
9784                        (eq gnus-use-cache 'passive)))
9785               (progn
9786                 (when all
9787                   (setq gnus-newsgroup-marked nil
9788                         gnus-newsgroup-dormant nil))
9789                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9790             ;; We actually mark all articles as canceled, which we
9791             ;; have to do when using auto-expiry or adaptive scoring.
9792             (gnus-summary-show-all-threads)
9793             (if (and to-here reverse)
9794                 (progn
9795                   (goto-char to-here)
9796                   (while (and
9797                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9798                           (gnus-summary-find-next (not all) nil nil t))))
9799               (when (gnus-summary-first-subject (not all) t)
9800                 (while (and
9801                         (if to-here (< (point) to-here) t)
9802                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9803                         (gnus-summary-find-next (not all) nil nil t)))))
9804             (gnus-set-mode-line 'summary))
9805           t))
9806     (gnus-summary-position-point)))
9807
9808 (defun gnus-summary-catchup-to-here (&optional all)
9809   "Mark all unticked articles before the current one as read.
9810 If ALL is non-nil, also mark ticked and dormant articles as read."
9811   (interactive "P")
9812   (save-excursion
9813     (gnus-save-hidden-threads
9814       (let ((beg (point)))
9815         ;; We check that there are unread articles.
9816         (when (or all (gnus-summary-find-prev))
9817           (gnus-summary-catchup all t beg)))))
9818   (gnus-summary-position-point))
9819
9820 (defun gnus-summary-catchup-from-here (&optional all)
9821   "Mark all unticked articles after the current one as read.
9822 If ALL is non-nil, also mark ticked and dormant articles as read."
9823   (interactive "P")
9824   (save-excursion
9825     (gnus-save-hidden-threads
9826       (let ((beg (point)))
9827         ;; We check that there are unread articles.
9828         (when (or all (gnus-summary-find-next))
9829           (gnus-summary-catchup all t beg nil t)))))
9830   (gnus-summary-position-point))
9831
9832 (defun gnus-summary-catchup-all (&optional quietly)
9833   "Mark all articles in this newsgroup as read."
9834   (interactive "P")
9835   (gnus-summary-catchup t quietly))
9836
9837 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9838   "Mark all unread articles in this group as read, then exit.
9839 If prefix argument ALL is non-nil, all articles are marked as read.
9840 If QUIETLY is non-nil, no questions will be asked."
9841   (interactive "P")
9842   (when (gnus-summary-catchup all quietly nil 'fast)
9843     ;; Select next newsgroup or exit.
9844     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9845              (eq gnus-auto-select-next 'quietly))
9846         (gnus-summary-next-group nil)
9847       (gnus-summary-exit))))
9848
9849 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9850   "Mark all articles in this newsgroup as read, and then exit."
9851   (interactive "P")
9852   (gnus-summary-catchup-and-exit t quietly))
9853
9854 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9855   "Mark all articles in this group as read and select the next group.
9856 If given a prefix, mark all articles, unread as well as ticked, as
9857 read."
9858   (interactive "P")
9859   (save-excursion
9860     (gnus-summary-catchup all))
9861   (gnus-summary-next-group))
9862
9863 ;;;
9864 ;;; with article
9865 ;;;
9866
9867 (defmacro gnus-with-article (article &rest forms)
9868   "Select ARTICLE and perform FORMS in the original article buffer.
9869 Then replace the article with the result."
9870   `(progn
9871      ;; We don't want the article to be marked as read.
9872      (let (gnus-mark-article-hook)
9873        (gnus-summary-select-article t t nil ,article))
9874      (set-buffer gnus-original-article-buffer)
9875      ,@forms
9876      (if (not (gnus-check-backend-function
9877                'request-replace-article (car gnus-article-current)))
9878          (gnus-message 5 "Read-only group; not replacing")
9879        (unless (gnus-request-replace-article
9880                 ,article (car gnus-article-current)
9881                 (current-buffer) t)
9882          (error "Couldn't replace article")))
9883      ;; The cache and backlog have to be flushed somewhat.
9884      (when gnus-keep-backlog
9885        (gnus-backlog-remove-article
9886         (car gnus-article-current) (cdr gnus-article-current)))
9887      (when gnus-use-cache
9888        (gnus-cache-update-article
9889         (car gnus-article-current) (cdr gnus-article-current)))))
9890
9891 (put 'gnus-with-article 'lisp-indent-function 1)
9892 (put 'gnus-with-article 'edebug-form-spec '(form body))
9893
9894 ;; Thread-based commands.
9895
9896 (defun gnus-summary-articles-in-thread (&optional article)
9897   "Return a list of all articles in the current thread.
9898 If ARTICLE is non-nil, return all articles in the thread that starts
9899 with that article."
9900   (let* ((article (or article (gnus-summary-article-number)))
9901          (data (gnus-data-find-list article))
9902          (top-level (gnus-data-level (car data)))
9903          (top-subject
9904           (cond ((null gnus-thread-operation-ignore-subject)
9905                  (gnus-simplify-subject-re
9906                   (mail-header-subject (gnus-data-header (car data)))))
9907                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9908                  (gnus-simplify-subject-fuzzy
9909                   (mail-header-subject (gnus-data-header (car data)))))
9910                 (t nil)))
9911          (end-point (save-excursion
9912                       (if (gnus-summary-go-to-next-thread)
9913                           (point) (point-max))))
9914          articles)
9915     (while (and data
9916                 (< (gnus-data-pos (car data)) end-point))
9917       (when (or (not top-subject)
9918                 (string= top-subject
9919                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9920                              (gnus-simplify-subject-fuzzy
9921                               (mail-header-subject
9922                                (gnus-data-header (car data))))
9923                            (gnus-simplify-subject-re
9924                             (mail-header-subject
9925                              (gnus-data-header (car data)))))))
9926         (push (gnus-data-number (car data)) articles))
9927       (unless (and (setq data (cdr data))
9928                    (> (gnus-data-level (car data)) top-level))
9929         (setq data nil)))
9930     ;; Return the list of articles.
9931     (nreverse articles)))
9932
9933 (defun gnus-summary-rethread-current ()
9934   "Rethread the thread the current article is part of."
9935   (interactive)
9936   (let* ((gnus-show-threads t)
9937          (article (gnus-summary-article-number))
9938          (id (mail-header-id (gnus-summary-article-header)))
9939          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9940     (unless id
9941       (error "No article on the current line"))
9942     (gnus-rebuild-thread id)
9943     (gnus-summary-goto-subject article)))
9944
9945 (defun gnus-summary-reparent-thread ()
9946   "Make the current article child of the marked (or previous) article.
9947
9948 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9949 is non-nil or the Subject: of both articles are the same."
9950   (interactive)
9951   (unless (not (gnus-group-read-only-p))
9952     (error "The current newsgroup does not support article editing"))
9953   (unless (<= (length gnus-newsgroup-processable) 1)
9954     (error "No more than one article may be marked"))
9955   (save-window-excursion
9956     (let ((gnus-article-buffer " *reparent*")
9957           (current-article (gnus-summary-article-number))
9958           ;; First grab the marked article, otherwise one line up.
9959           (parent-article (if (not (null gnus-newsgroup-processable))
9960                               (car gnus-newsgroup-processable)
9961                             (save-excursion
9962                               (if (eq (forward-line -1) 0)
9963                                   (gnus-summary-article-number)
9964                                 (error "Beginning of summary buffer"))))))
9965       (unless (not (eq current-article parent-article))
9966         (error "An article may not be self-referential"))
9967       (let ((message-id (mail-header-id
9968                          (gnus-summary-article-header parent-article))))
9969         (unless (and message-id (not (equal message-id "")))
9970           (error "No message-id in desired parent"))
9971         (gnus-with-article current-article
9972           (save-restriction
9973             (goto-char (point-min))
9974             (message-narrow-to-head)
9975             (if (re-search-forward "^References: " nil t)
9976                 (progn
9977                   (re-search-forward "^[^ \t]" nil t)
9978                   (forward-line -1)
9979                   (end-of-line)
9980                   (insert " " message-id))
9981               (insert "References: " message-id "\n"))))
9982         (set-buffer gnus-summary-buffer)
9983         (gnus-summary-unmark-all-processable)
9984         (gnus-summary-update-article current-article)
9985         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9986             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9987         (gnus-summary-rethread-current)
9988         (gnus-message 3 "Article %d is now the child of article %d"
9989                       current-article parent-article)))))
9990
9991 (defun gnus-summary-toggle-threads (&optional arg)
9992   "Toggle showing conversation threads.
9993 If ARG is positive number, turn showing conversation threads on."
9994   (interactive "P")
9995   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9996     (setq gnus-show-threads
9997           (if (null arg) (not gnus-show-threads)
9998             (> (prefix-numeric-value arg) 0)))
9999     (gnus-summary-prepare)
10000     (gnus-summary-goto-subject current)
10001     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10002     (gnus-summary-position-point)))
10003
10004 (defun gnus-summary-show-all-threads ()
10005   "Show all threads."
10006   (interactive)
10007   (save-excursion
10008     (let ((buffer-read-only nil))
10009       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10010   (gnus-summary-position-point))
10011
10012 (defun gnus-summary-show-thread ()
10013   "Show thread subtrees.
10014 Returns nil if no thread was there to be shown."
10015   (interactive)
10016   (let ((buffer-read-only nil)
10017         (orig (point))
10018         ;; first goto end then to beg, to have point at beg after let
10019         (end (progn (end-of-line) (point)))
10020         (beg (progn (beginning-of-line) (point))))
10021     (prog1
10022         ;; Any hidden lines here?
10023         (search-forward "\r" end t)
10024       (subst-char-in-region beg end ?\^M ?\n t)
10025       (goto-char orig)
10026       (gnus-summary-position-point))))
10027
10028 (defun gnus-summary-maybe-hide-threads ()
10029   "If requested, hide the threads that should be hidden."
10030   (when (and gnus-show-threads
10031              gnus-thread-hide-subtree)
10032     (gnus-summary-hide-all-threads
10033      (if (or (consp gnus-thread-hide-subtree)
10034              (gnus-functionp gnus-thread-hide-subtree))
10035          (gnus-make-predicate gnus-thread-hide-subtree)
10036        nil))))
10037
10038 ;;; Hiding predicates.
10039
10040 (defun gnus-article-unread-p (header)
10041   (memq (mail-header-number header) gnus-newsgroup-unreads))
10042
10043 (defun gnus-article-unseen-p (header)
10044   (memq (mail-header-number header) gnus-newsgroup-unseen))
10045
10046 (defun gnus-map-articles (predicate articles)
10047   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10048   (apply 'gnus-or (mapcar predicate
10049                           (mapcar 'gnus-summary-article-header articles))))
10050
10051 (defun gnus-summary-hide-all-threads (&optional predicate)
10052   "Hide all thread subtrees.
10053 If PREDICATE is supplied, threads that satisfy this predicate
10054 will not be hidden."
10055   (interactive)
10056   (save-excursion
10057     (goto-char (point-min))
10058     (let ((end nil))
10059       (while (not end)
10060         (when (or (not predicate)
10061                   (gnus-map-articles
10062                    predicate (gnus-summary-article-children)))
10063             (gnus-summary-hide-thread))
10064         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10065   (gnus-summary-position-point))
10066
10067 (defun gnus-summary-hide-thread ()
10068   "Hide thread subtrees.
10069 If PREDICATE is supplied, threads that satisfy this predicate
10070 will not be hidden.
10071 Returns nil if no threads were there to be hidden."
10072   (interactive)
10073   (let ((buffer-read-only nil)
10074         (start (point))
10075         (article (gnus-summary-article-number)))
10076     (goto-char start)
10077     ;; Go forward until either the buffer ends or the subthread
10078     ;; ends.
10079     (when (and (not (eobp))
10080                (or (zerop (gnus-summary-next-thread 1 t))
10081                    (goto-char (point-max))))
10082       (prog1
10083           (if (and (> (point) start)
10084                    (search-backward "\n" start t))
10085               (progn
10086                 (subst-char-in-region start (point) ?\n ?\^M)
10087                 (gnus-summary-goto-subject article))
10088             (goto-char start)
10089             nil)))))
10090
10091 (defun gnus-summary-go-to-next-thread (&optional previous)
10092   "Go to the same level (or less) next thread.
10093 If PREVIOUS is non-nil, go to previous thread instead.
10094 Return the article number moved to, or nil if moving was impossible."
10095   (let ((level (gnus-summary-thread-level))
10096         (way (if previous -1 1))
10097         (beg (point)))
10098     (forward-line way)
10099     (while (and (not (eobp))
10100                 (< level (gnus-summary-thread-level)))
10101       (forward-line way))
10102     (if (eobp)
10103         (progn
10104           (goto-char beg)
10105           nil)
10106       (setq beg (point))
10107       (prog1
10108           (gnus-summary-article-number)
10109         (goto-char beg)))))
10110
10111 (defun gnus-summary-next-thread (n &optional silent)
10112   "Go to the same level next N'th thread.
10113 If N is negative, search backward instead.
10114 Returns the difference between N and the number of skips actually
10115 done.
10116
10117 If SILENT, don't output messages."
10118   (interactive "p")
10119   (let ((backward (< n 0))
10120         (n (abs n)))
10121     (while (and (> n 0)
10122                 (gnus-summary-go-to-next-thread backward))
10123       (decf n))
10124     (unless silent
10125       (gnus-summary-position-point))
10126     (when (and (not silent) (/= 0 n))
10127       (gnus-message 7 "No more threads"))
10128     n))
10129
10130 (defun gnus-summary-prev-thread (n)
10131   "Go to the same level previous N'th thread.
10132 Returns the difference between N and the number of skips actually
10133 done."
10134   (interactive "p")
10135   (gnus-summary-next-thread (- n)))
10136
10137 (defun gnus-summary-go-down-thread ()
10138   "Go down one level in the current thread."
10139   (let ((children (gnus-summary-article-children)))
10140     (when children
10141       (gnus-summary-goto-subject (car children)))))
10142
10143 (defun gnus-summary-go-up-thread ()
10144   "Go up one level in the current thread."
10145   (let ((parent (gnus-summary-article-parent)))
10146     (when parent
10147       (gnus-summary-goto-subject parent))))
10148
10149 (defun gnus-summary-down-thread (n)
10150   "Go down thread N steps.
10151 If N is negative, go up instead.
10152 Returns the difference between N and how many steps down that were
10153 taken."
10154   (interactive "p")
10155   (let ((up (< n 0))
10156         (n (abs n)))
10157     (while (and (> n 0)
10158                 (if up (gnus-summary-go-up-thread)
10159                   (gnus-summary-go-down-thread)))
10160       (setq n (1- n)))
10161     (gnus-summary-position-point)
10162     (when (/= 0 n)
10163       (gnus-message 7 "Can't go further"))
10164     n))
10165
10166 (defun gnus-summary-up-thread (n)
10167   "Go up thread N steps.
10168 If N is negative, go down instead.
10169 Returns the difference between N and how many steps down that were
10170 taken."
10171   (interactive "p")
10172   (gnus-summary-down-thread (- n)))
10173
10174 (defun gnus-summary-top-thread ()
10175   "Go to the top of the thread."
10176   (interactive)
10177   (while (gnus-summary-go-up-thread))
10178   (gnus-summary-article-number))
10179
10180 (defun gnus-summary-kill-thread (&optional unmark)
10181   "Mark articles under current thread as read.
10182 If the prefix argument is positive, remove any kinds of marks.
10183 If the prefix argument is negative, tick articles instead."
10184   (interactive "P")
10185   (when unmark
10186     (setq unmark (prefix-numeric-value unmark)))
10187   (let ((articles (gnus-summary-articles-in-thread)))
10188     (save-excursion
10189       ;; Expand the thread.
10190       (gnus-summary-show-thread)
10191       ;; Mark all the articles.
10192       (while articles
10193         (gnus-summary-goto-subject (car articles))
10194         (cond ((null unmark)
10195                (gnus-summary-mark-article-as-read gnus-killed-mark))
10196               ((> unmark 0)
10197                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10198               (t
10199                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10200         (setq articles (cdr articles))))
10201     ;; Hide killed subtrees.
10202     (and (null unmark)
10203          gnus-thread-hide-killed
10204          (gnus-summary-hide-thread))
10205     ;; If marked as read, go to next unread subject.
10206     (when (null unmark)
10207       ;; Go to next unread subject.
10208       (gnus-summary-next-subject 1 t)))
10209   (gnus-set-mode-line 'summary))
10210
10211 ;; Summary sorting commands
10212
10213 (defun gnus-summary-sort-by-number (&optional reverse)
10214   "Sort the summary buffer by article number.
10215 Argument REVERSE means reverse order."
10216   (interactive "P")
10217   (gnus-summary-sort 'number reverse))
10218
10219 (defun gnus-summary-sort-by-author (&optional reverse)
10220   "Sort the summary buffer by author name alphabetically.
10221 If `case-fold-search' is non-nil, case of letters is ignored.
10222 Argument REVERSE means reverse order."
10223   (interactive "P")
10224   (gnus-summary-sort 'author reverse))
10225
10226 (defun gnus-summary-sort-by-subject (&optional reverse)
10227   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10228 If `case-fold-search' is non-nil, case of letters is ignored.
10229 Argument REVERSE means reverse order."
10230   (interactive "P")
10231   (gnus-summary-sort 'subject reverse))
10232
10233 (defun gnus-summary-sort-by-date (&optional reverse)
10234   "Sort the summary buffer by date.
10235 Argument REVERSE means reverse order."
10236   (interactive "P")
10237   (gnus-summary-sort 'date reverse))
10238
10239 (defun gnus-summary-sort-by-score (&optional reverse)
10240   "Sort the summary buffer by score.
10241 Argument REVERSE means reverse order."
10242   (interactive "P")
10243   (gnus-summary-sort 'score reverse))
10244
10245 (defun gnus-summary-sort-by-lines (&optional reverse)
10246   "Sort the summary buffer by the number of lines.
10247 Argument REVERSE means reverse order."
10248   (interactive "P")
10249   (gnus-summary-sort 'lines reverse))
10250
10251 (defun gnus-summary-sort-by-chars (&optional reverse)
10252   "Sort the summary buffer by article length.
10253 Argument REVERSE means reverse order."
10254   (interactive "P")
10255   (gnus-summary-sort 'chars reverse))
10256
10257 (defun gnus-summary-sort-by-original (&optional reverse)
10258   "Sort the summary buffer using the default sorting method.
10259 Argument REVERSE means reverse order."
10260   (interactive "P")
10261   (let* ((buffer-read-only)
10262          (gnus-summary-prepare-hook nil))
10263     ;; We do the sorting by regenerating the threads.
10264     (gnus-summary-prepare)
10265     ;; Hide subthreads if needed.
10266     (gnus-summary-maybe-hide-threads)))
10267
10268 (defun gnus-summary-sort (predicate reverse)
10269   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10270   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10271          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10272          (gnus-thread-sort-functions
10273           (if (not reverse)
10274               thread
10275             `(lambda (t1 t2)
10276                (,thread t2 t1))))
10277          (gnus-sort-gathered-threads-function
10278           gnus-thread-sort-functions)
10279          (gnus-article-sort-functions
10280           (if (not reverse)
10281               article
10282             `(lambda (t1 t2)
10283                (,article t2 t1))))
10284          (buffer-read-only)
10285          (gnus-summary-prepare-hook nil))
10286     ;; We do the sorting by regenerating the threads.
10287     (gnus-summary-prepare)
10288     ;; Hide subthreads if needed.
10289     (gnus-summary-maybe-hide-threads)))
10290
10291 ;; Summary saving commands.
10292
10293 (defun gnus-summary-save-article (&optional n not-saved)
10294   "Save the current article using the default saver function.
10295 If N is a positive number, save the N next articles.
10296 If N is a negative number, save the N previous articles.
10297 If N is nil and any articles have been marked with the process mark,
10298 save those articles instead.
10299 The variable `gnus-default-article-saver' specifies the saver function."
10300   (interactive "P")
10301   (let* ((articles (gnus-summary-work-articles n))
10302          (save-buffer (save-excursion
10303                         (nnheader-set-temp-buffer " *Gnus Save*")))
10304          (num (length articles))
10305          header file)
10306     (dolist (article articles)
10307       (setq header (gnus-summary-article-header article))
10308       (if (not (vectorp header))
10309           ;; This is a pseudo-article.
10310           (if (assq 'name header)
10311               (gnus-copy-file (cdr (assq 'name header)))
10312             (gnus-message 1 "Article %d is unsaveable" article))
10313         ;; This is a real article.
10314         (save-window-excursion
10315           (let ((gnus-display-mime-function nil)
10316                 (gnus-article-prepare-hook nil))
10317             (gnus-summary-select-article t nil nil article)))
10318         (save-excursion
10319           (set-buffer save-buffer)
10320           (erase-buffer)
10321           (insert-buffer-substring gnus-original-article-buffer))
10322         (setq file (gnus-article-save save-buffer file num))
10323         (gnus-summary-remove-process-mark article)
10324         (unless not-saved
10325           (gnus-summary-set-saved-mark article))))
10326     (gnus-kill-buffer save-buffer)
10327     (gnus-summary-position-point)
10328     (gnus-set-mode-line 'summary)
10329     n))
10330
10331 (defun gnus-summary-pipe-output (&optional arg)
10332   "Pipe the current article to a subprocess.
10333 If N is a positive number, pipe the N next articles.
10334 If N is a negative number, pipe the N previous articles.
10335 If N is nil and any articles have been marked with the process mark,
10336 pipe those articles instead."
10337   (interactive "P")
10338   (require 'gnus-art)
10339   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10340     (gnus-summary-save-article arg t))
10341   (let ((buffer (get-buffer "*Shell Command Output*")))
10342     (if (and buffer
10343              (with-current-buffer buffer (> (point-max) (point-min))))
10344         (gnus-configure-windows 'pipe))))
10345
10346 (defun gnus-summary-save-article-mail (&optional arg)
10347   "Append the current article to an mail file.
10348 If N is a positive number, save the N next articles.
10349 If N is a negative number, save the N previous articles.
10350 If N is nil and any articles have been marked with the process mark,
10351 save those articles instead."
10352   (interactive "P")
10353   (require 'gnus-art)
10354   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10355     (gnus-summary-save-article arg)))
10356
10357 (defun gnus-summary-save-article-rmail (&optional arg)
10358   "Append the current article to an rmail file.
10359 If N is a positive number, save the N next articles.
10360 If N is a negative number, save the N previous articles.
10361 If N is nil and any articles have been marked with the process mark,
10362 save those articles instead."
10363   (interactive "P")
10364   (require 'gnus-art)
10365   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10366     (gnus-summary-save-article arg)))
10367
10368 (defun gnus-summary-save-article-file (&optional arg)
10369   "Append the current article to a file.
10370 If N is a positive number, save the N next articles.
10371 If N is a negative number, save the N previous articles.
10372 If N is nil and any articles have been marked with the process mark,
10373 save those articles instead."
10374   (interactive "P")
10375   (require 'gnus-art)
10376   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10377     (gnus-summary-save-article arg)))
10378
10379 (defun gnus-summary-write-article-file (&optional arg)
10380   "Write the current article to a file, deleting the previous file.
10381 If N is a positive number, save the N next articles.
10382 If N is a negative number, save the N previous articles.
10383 If N is nil and any articles have been marked with the process mark,
10384 save those articles instead."
10385   (interactive "P")
10386   (require 'gnus-art)
10387   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10388     (gnus-summary-save-article arg)))
10389
10390 (defun gnus-summary-save-article-body-file (&optional arg)
10391   "Append the current article body to a file.
10392 If N is a positive number, save the N next articles.
10393 If N is a negative number, save the N previous articles.
10394 If N is nil and any articles have been marked with the process mark,
10395 save those articles instead."
10396   (interactive "P")
10397   (require 'gnus-art)
10398   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10399     (gnus-summary-save-article arg)))
10400
10401 (defun gnus-summary-muttprint (&optional arg)
10402   "Print the current article using Muttprint.
10403 If N is a positive number, save the N next articles.
10404 If N is a negative number, save the N previous articles.
10405 If N is nil and any articles have been marked with the process mark,
10406 save those articles instead."
10407   (interactive "P")
10408   (require 'gnus-art)
10409   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10410     (gnus-summary-save-article arg t)))
10411
10412 (defun gnus-summary-pipe-message (program)
10413   "Pipe the current article through PROGRAM."
10414   (interactive "sProgram: ")
10415   (gnus-summary-select-article)
10416   (let ((mail-header-separator ""))
10417     (gnus-eval-in-buffer-window gnus-article-buffer
10418       (save-restriction
10419         (widen)
10420         (let ((start (window-start))
10421               buffer-read-only)
10422           (message-pipe-buffer-body program)
10423           (set-window-start (get-buffer-window (current-buffer)) start))))))
10424
10425 (defun gnus-get-split-value (methods)
10426   "Return a value based on the split METHODS."
10427   (let (split-name method result match)
10428     (when methods
10429       (save-excursion
10430         (set-buffer gnus-original-article-buffer)
10431         (save-restriction
10432           (nnheader-narrow-to-headers)
10433           (while (and methods (not split-name))
10434             (goto-char (point-min))
10435             (setq method (pop methods))
10436             (setq match (car method))
10437             (when (cond
10438                    ((stringp match)
10439                     ;; Regular expression.
10440                     (ignore-errors
10441                       (re-search-forward match nil t)))
10442                    ((gnus-functionp match)
10443                     ;; Function.
10444                     (save-restriction
10445                       (widen)
10446                       (setq result (funcall match gnus-newsgroup-name))))
10447                    ((consp match)
10448                     ;; Form.
10449                     (save-restriction
10450                       (widen)
10451                       (setq result (eval match)))))
10452               (setq split-name (cdr method))
10453               (cond ((stringp result)
10454                      (push (expand-file-name
10455                             result gnus-article-save-directory)
10456                            split-name))
10457                     ((consp result)
10458                      (setq split-name (append result split-name)))))))))
10459     (nreverse split-name)))
10460
10461 (defun gnus-valid-move-group-p (group)
10462   (and (boundp group)
10463        (symbol-name group)
10464        (symbol-value group)
10465        (gnus-get-function (gnus-find-method-for-group
10466                            (symbol-name group)) 'request-accept-article t)))
10467
10468 (defun gnus-read-move-group-name (prompt default articles prefix)
10469   "Read a group name."
10470   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10471          (minibuffer-confirm-incomplete nil) ; XEmacs
10472          (prom
10473           (format "%s %s to:"
10474                   prompt
10475                   (if (> (length articles) 1)
10476                       (format "these %d articles" (length articles))
10477                     "this article")))
10478          (to-newsgroup
10479           (cond
10480            ((null split-name)
10481             (gnus-completing-read-with-default
10482              default prom
10483              gnus-active-hashtb
10484              'gnus-valid-move-group-p
10485              nil prefix
10486              'gnus-group-history))
10487            ((= 1 (length split-name))
10488             (gnus-completing-read-with-default
10489              (car split-name) prom
10490              gnus-active-hashtb
10491              'gnus-valid-move-group-p
10492              nil nil
10493              'gnus-group-history))
10494            (t
10495             (gnus-completing-read-with-default
10496              nil prom
10497              (mapcar (lambda (el) (list el))
10498                      (nreverse split-name))
10499              nil nil nil
10500              'gnus-group-history))))
10501          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10502     (when to-newsgroup
10503       (if (or (string= to-newsgroup "")
10504               (string= to-newsgroup prefix))
10505           (setq to-newsgroup default))
10506       (unless to-newsgroup
10507         (error "No group name entered"))
10508       (or (gnus-active to-newsgroup)
10509           (gnus-activate-group to-newsgroup nil nil to-method)
10510           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10511                                      to-newsgroup))
10512               (or (and (gnus-request-create-group to-newsgroup to-method)
10513                        (gnus-activate-group
10514                         to-newsgroup nil nil to-method)
10515                        (gnus-subscribe-group to-newsgroup))
10516                   (error "Couldn't create group %s" to-newsgroup)))
10517           (error "No such group: %s" to-newsgroup)))
10518     to-newsgroup))
10519
10520 (defun gnus-summary-save-parts (type dir n &optional reverse)
10521   "Save parts matching TYPE to DIR.
10522 If REVERSE, save parts that do not match TYPE."
10523   (interactive
10524    (list (read-string "Save parts of type: "
10525                       (or (car gnus-summary-save-parts-type-history)
10526                           gnus-summary-save-parts-default-mime)
10527                       'gnus-summary-save-parts-type-history)
10528          (setq gnus-summary-save-parts-last-directory
10529                (read-file-name "Save to directory: "
10530                                gnus-summary-save-parts-last-directory
10531                                nil t))
10532          current-prefix-arg))
10533   (gnus-summary-iterate n
10534     (let ((gnus-display-mime-function nil)
10535           (gnus-inhibit-treatment t))
10536       (gnus-summary-select-article))
10537     (save-excursion
10538       (set-buffer gnus-article-buffer)
10539       (let ((handles (or gnus-article-mime-handles
10540                          (mm-dissect-buffer nil gnus-article-loose-mime)
10541                          (mm-uu-dissect))))
10542         (when handles
10543           (gnus-summary-save-parts-1 type dir handles reverse)
10544           (unless gnus-article-mime-handles ;; Don't destroy this case.
10545             (mm-destroy-parts handles)))))))
10546
10547 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10548   (if (stringp (car handle))
10549       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10550               (cdr handle))
10551     (when (if reverse
10552               (not (string-match type (mm-handle-media-type handle)))
10553             (string-match type (mm-handle-media-type handle)))
10554       (let ((file (expand-file-name
10555                    (file-name-nondirectory
10556                     (or
10557                      (mail-content-type-get
10558                       (mm-handle-disposition handle) 'filename)
10559                      (concat gnus-newsgroup-name
10560                              "." (number-to-string
10561                                   (cdr gnus-article-current)))))
10562                    dir)))
10563         (unless (file-exists-p file)
10564           (mm-save-part-to-file handle file))))))
10565
10566 ;; Summary extract commands
10567
10568 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10569   (let ((buffer-read-only nil)
10570         (article (gnus-summary-article-number))
10571         after-article b e)
10572     (unless (gnus-summary-goto-subject article)
10573       (error "No such article: %d" article))
10574     (gnus-summary-position-point)
10575     ;; If all commands are to be bunched up on one line, we collect
10576     ;; them here.
10577     (unless gnus-view-pseudos-separately
10578       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10579             files action)
10580         (while ps
10581           (setq action (cdr (assq 'action (car ps))))
10582           (setq files (list (cdr (assq 'name (car ps)))))
10583           (while (and ps (cdr ps)
10584                       (string= (or action "1")
10585                                (or (cdr (assq 'action (cadr ps))) "2")))
10586             (push (cdr (assq 'name (cadr ps))) files)
10587             (setcdr ps (cddr ps)))
10588           (when files
10589             (when (not (string-match "%s" action))
10590               (push " " files))
10591             (push " " files)
10592             (when (assq 'execute (car ps))
10593               (setcdr (assq 'execute (car ps))
10594                       (funcall (if (string-match "%s" action)
10595                                    'format 'concat)
10596                                action
10597                                (mapconcat
10598                                 (lambda (f)
10599                                   (if (equal f " ")
10600                                       f
10601                                     (gnus-quote-arg-for-sh-or-csh f)))
10602                                 files " ")))))
10603           (setq ps (cdr ps)))))
10604     (if (and gnus-view-pseudos (not not-view))
10605         (while pslist
10606           (when (assq 'execute (car pslist))
10607             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10608                                   (eq gnus-view-pseudos 'not-confirm)))
10609           (setq pslist (cdr pslist)))
10610       (save-excursion
10611         (while pslist
10612           (setq after-article (or (cdr (assq 'article (car pslist)))
10613                                   (gnus-summary-article-number)))
10614           (gnus-summary-goto-subject after-article)
10615           (forward-line 1)
10616           (setq b (point))
10617           (insert "    " (file-name-nondirectory
10618                           (cdr (assq 'name (car pslist))))
10619                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10620           (setq e (point))
10621           (forward-line -1)             ; back to `b'
10622           (gnus-add-text-properties
10623            b (1- e) (list 'gnus-number gnus-reffed-article-number
10624                           gnus-mouse-face-prop gnus-mouse-face))
10625           (gnus-data-enter
10626            after-article gnus-reffed-article-number
10627            gnus-unread-mark b (car pslist) 0 (- e b))
10628           (setq gnus-newsgroup-unreads
10629                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10630                                          gnus-reffed-article-number))
10631           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10632           (setq pslist (cdr pslist)))))))
10633
10634 (defun gnus-pseudos< (p1 p2)
10635   (let ((c1 (cdr (assq 'action p1)))
10636         (c2 (cdr (assq 'action p2))))
10637     (and c1 c2 (string< c1 c2))))
10638
10639 (defun gnus-request-pseudo-article (props)
10640   (cond ((assq 'execute props)
10641          (gnus-execute-command (cdr (assq 'execute props)))))
10642   (let ((gnus-current-article (gnus-summary-article-number)))
10643     (gnus-run-hooks 'gnus-mark-article-hook)))
10644
10645 (defun gnus-execute-command (command &optional automatic)
10646   (save-excursion
10647     (gnus-article-setup-buffer)
10648     (set-buffer gnus-article-buffer)
10649     (setq buffer-read-only nil)
10650     (let ((command (if automatic command
10651                      (read-string "Command: " (cons command 0)))))
10652       (erase-buffer)
10653       (insert "$ " command "\n\n")
10654       (if gnus-view-pseudo-asynchronously
10655           (start-process "gnus-execute" (current-buffer) shell-file-name
10656                          shell-command-switch command)
10657         (call-process shell-file-name nil t nil
10658                       shell-command-switch command)))))
10659
10660 ;; Summary kill commands.
10661
10662 (defun gnus-summary-edit-global-kill (article)
10663   "Edit the \"global\" kill file."
10664   (interactive (list (gnus-summary-article-number)))
10665   (gnus-group-edit-global-kill article))
10666
10667 (defun gnus-summary-edit-local-kill ()
10668   "Edit a local kill file applied to the current newsgroup."
10669   (interactive)
10670   (setq gnus-current-headers (gnus-summary-article-header))
10671   (gnus-group-edit-local-kill
10672    (gnus-summary-article-number) gnus-newsgroup-name))
10673
10674 ;;; Header reading.
10675
10676 (defun gnus-read-header (id &optional header)
10677   "Read the headers of article ID and enter them into the Gnus system."
10678   (let ((group gnus-newsgroup-name)
10679         (gnus-override-method
10680          (or
10681           gnus-override-method
10682           (and (gnus-news-group-p gnus-newsgroup-name)
10683                (car (gnus-refer-article-methods)))))
10684         where)
10685     ;; First we check to see whether the header in question is already
10686     ;; fetched.
10687     (if (stringp id)
10688         ;; This is a Message-ID.
10689         (setq header (or header (gnus-id-to-header id)))
10690       ;; This is an article number.
10691       (setq header (or header (gnus-summary-article-header id))))
10692     (if (and header
10693              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10694         ;; We have found the header.
10695         header
10696       ;; If this is a sparse article, we have to nix out its
10697       ;; previous entry in the thread hashtb.
10698       (when (and header
10699                  (gnus-summary-article-sparse-p (mail-header-number header)))
10700         (let* ((parent (gnus-parent-id (mail-header-references header)))
10701                (thread (and parent (gnus-id-to-thread parent))))
10702           (when thread
10703             (delq (assq header thread) thread))))
10704       ;; We have to really fetch the header to this article.
10705       (save-excursion
10706         (set-buffer nntp-server-buffer)
10707         (when (setq where (gnus-request-head id group))
10708           (nnheader-fold-continuation-lines)
10709           (goto-char (point-max))
10710           (insert ".\n")
10711           (goto-char (point-min))
10712           (insert "211 ")
10713           (princ (cond
10714                   ((numberp id) id)
10715                   ((cdr where) (cdr where))
10716                   (header (mail-header-number header))
10717                   (t gnus-reffed-article-number))
10718                  (current-buffer))
10719           (insert " Article retrieved.\n"))
10720         (if (or (not where)
10721                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10722             ()                          ; Malformed head.
10723           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10724             (when (and (stringp id)
10725                        (not (string= (gnus-group-real-name group)
10726                                      (car where))))
10727               ;; If we fetched by Message-ID and the article came
10728               ;; from a different group, we fudge some bogus article
10729               ;; numbers for this article.
10730               (mail-header-set-number header gnus-reffed-article-number))
10731             (save-excursion
10732               (set-buffer gnus-summary-buffer)
10733               (decf gnus-reffed-article-number)
10734               (gnus-remove-header (mail-header-number header))
10735               (push header gnus-newsgroup-headers)
10736               (setq gnus-current-headers header)
10737               (push (mail-header-number header) gnus-newsgroup-limit)))
10738           header)))))
10739
10740 (defun gnus-remove-header (number)
10741   "Remove header NUMBER from `gnus-newsgroup-headers'."
10742   (if (and gnus-newsgroup-headers
10743            (= number (mail-header-number (car gnus-newsgroup-headers))))
10744       (pop gnus-newsgroup-headers)
10745     (let ((headers gnus-newsgroup-headers))
10746       (while (and (cdr headers)
10747                   (not (= number (mail-header-number (cadr headers)))))
10748         (pop headers))
10749       (when (cdr headers)
10750         (setcdr headers (cddr headers))))))
10751
10752 ;;;
10753 ;;; summary highlights
10754 ;;;
10755
10756 (defun gnus-highlight-selected-summary ()
10757   "Highlight selected article in summary buffer."
10758   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10759   (when gnus-summary-selected-face
10760     (save-excursion
10761       (let* ((beg (progn (beginning-of-line) (point)))
10762              (end (progn (end-of-line) (point)))
10763              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10764              (from (if (get-text-property beg gnus-mouse-face-prop)
10765                        beg
10766                      (or (next-single-property-change
10767                           beg gnus-mouse-face-prop nil end)
10768                          beg)))
10769              (to
10770               (if (= from end)
10771                   (- from 2)
10772                 (or (next-single-property-change
10773                      from gnus-mouse-face-prop nil end)
10774                     end))))
10775         ;; If no mouse-face prop on line we will have to = from = end,
10776         ;; so we highlight the entire line instead.
10777         (when (= (+ to 2) from)
10778           (setq from beg)
10779           (setq to end))
10780         (if gnus-newsgroup-selected-overlay
10781             ;; Move old overlay.
10782             (gnus-move-overlay
10783              gnus-newsgroup-selected-overlay from to (current-buffer))
10784           ;; Create new overlay.
10785           (gnus-overlay-put
10786            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10787            'face gnus-summary-selected-face))))))
10788
10789 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10790 (defun gnus-summary-highlight-line ()
10791   "Highlight current line according to `gnus-summary-highlight'."
10792   (let* ((list gnus-summary-highlight)
10793          (beg (gnus-point-at-bol))
10794          (article (gnus-summary-article-number))
10795          (score (or (cdr (assq (or article gnus-current-article)
10796                                gnus-newsgroup-scored))
10797                     gnus-summary-default-score 0))
10798          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10799          (inhibit-read-only t)
10800          (default gnus-summary-default-score)
10801          (default-high gnus-summary-default-high-score)
10802          (default-low gnus-summary-default-low-score))
10803     ;; Eval the cars of the lists until we find a match.
10804     (while (and list
10805                 (not (eval (caar list))))
10806       (setq list (cdr list)))
10807     (let ((face (cdar list)))
10808       (unless (eq face (get-text-property beg 'face))
10809         (gnus-put-text-property-excluding-characters-with-faces
10810          beg (gnus-point-at-eol) 'face
10811          (setq face (if (boundp face) (symbol-value face) face)))
10812         (when gnus-summary-highlight-line-function
10813           (funcall gnus-summary-highlight-line-function article face))))))
10814
10815 (defun gnus-update-read-articles (group unread &optional compute)
10816   "Update the list of read articles in GROUP.
10817 UNREAD is a sorted list."
10818   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10819          (entry (gnus-gethash group gnus-newsrc-hashtb))
10820          (info (nth 2 entry))
10821          (prev 1)
10822          read)
10823     (if (or (not info) (not active))
10824         ;; There is no info on this group if it was, in fact,
10825         ;; killed.  Gnus stores no information on killed groups, so
10826         ;; there's nothing to be done.
10827         ;; One could store the information somewhere temporarily,
10828         ;; perhaps...  Hmmm...
10829         ()
10830       ;; Remove any negative articles numbers.
10831       (while (and unread (< (car unread) 0))
10832         (setq unread (cdr unread)))
10833       ;; Remove any expired article numbers
10834       (while (and unread (< (car unread) (car active)))
10835         (setq unread (cdr unread)))
10836       ;; Compute the ranges of read articles by looking at the list of
10837       ;; unread articles.
10838       (while unread
10839         (when (/= (car unread) prev)
10840           (push (if (= prev (1- (car unread))) prev
10841                   (cons prev (1- (car unread))))
10842                 read))
10843         (setq prev (1+ (car unread)))
10844         (setq unread (cdr unread)))
10845       (when (<= prev (cdr active))
10846         (push (cons prev (cdr active)) read))
10847       (setq read (if (> (length read) 1) (nreverse read) read))
10848       (if compute
10849           read
10850         (save-excursion
10851           (let (setmarkundo)
10852             ;; Propagate the read marks to the backend.
10853             (when (gnus-check-backend-function 'request-set-mark group)
10854               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10855                     (add (gnus-remove-from-range read (gnus-info-read info))))
10856                 (when (or add del)
10857                   (unless (gnus-check-group group)
10858                     (error "Can't open server for %s" group))
10859                   (gnus-request-set-mark
10860                    group (delq nil (list (if add (list add 'add '(read)))
10861                                          (if del (list del 'del '(read))))))
10862                   (setq setmarkundo
10863                         `(gnus-request-set-mark
10864                           ,group
10865                           ',(delq nil (list
10866                                        (if del (list del 'add '(read)))
10867                                        (if add (list add 'del '(read))))))))))
10868             (set-buffer gnus-group-buffer)
10869             (gnus-undo-register
10870               `(progn
10871                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10872                  (gnus-info-set-read ',info ',(gnus-info-read info))
10873                  (gnus-get-unread-articles-in-group ',info
10874                                                     (gnus-active ,group))
10875                  (gnus-group-update-group ,group t)
10876                  ,setmarkundo))))
10877         ;; Enter this list into the group info.
10878         (gnus-info-set-read info read)
10879         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10880         (gnus-get-unread-articles-in-group info (gnus-active group))
10881         t))))
10882
10883 (defun gnus-offer-save-summaries ()
10884   "Offer to save all active summary buffers."
10885   (let (buffers)
10886     ;; Go through all buffers and find all summaries.
10887     (dolist (buffer (buffer-list))
10888       (when (and (setq buffer (buffer-name buffer))
10889                  (string-match "Summary" buffer)
10890                  (save-excursion
10891                    (set-buffer buffer)
10892                    ;; We check that this is, indeed, a summary buffer.
10893                    (and (eq major-mode 'gnus-summary-mode)
10894                         ;; Also make sure this isn't bogus.
10895                         gnus-newsgroup-prepared
10896                         ;; Also make sure that this isn't a
10897                         ;; dead summary buffer.
10898                         (not gnus-dead-summary-mode))))
10899         (push buffer buffers)))
10900     ;; Go through all these summary buffers and offer to save them.
10901     (when buffers
10902       (save-excursion
10903         (map-y-or-n-p
10904          "Update summary buffer %s? "
10905          (lambda (buf)
10906            (switch-to-buffer buf)
10907            (gnus-summary-exit))
10908          buffers)))))
10909
10910
10911 ;;; @ for mime-partial
10912 ;;;
10913
10914 (defun gnus-request-partial-message ()
10915   (save-excursion
10916     (let ((number (gnus-summary-article-number))
10917           (group gnus-newsgroup-name)
10918           (mother gnus-article-buffer))
10919       (set-buffer (get-buffer-create " *Partial Article*"))
10920       (erase-buffer)
10921       (setq mime-preview-buffer mother)
10922       (gnus-request-article-this-buffer number group)
10923       (mime-parse-buffer)
10924       )))
10925
10926 (autoload 'mime-combine-message/partial-pieces-automatically
10927   "mime-partial"
10928   "Internal method to combine message/partial messages automatically.")
10929
10930 (mime-add-condition
10931  'action '((type . message)(subtype . partial)
10932            (major-mode . gnus-original-article-mode)
10933            (method . mime-combine-message/partial-pieces-automatically)
10934            (summary-buffer-exp . gnus-summary-buffer)
10935            (request-partial-message-method . gnus-request-partial-message)
10936            ))
10937
10938
10939 ;;; @ for message/rfc822
10940 ;;;
10941
10942 (defun gnus-mime-extract-message/rfc822 (entity situation)
10943   "Burst a forwarded article."
10944   (save-excursion
10945     (set-buffer gnus-summary-buffer)
10946     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10947                                    gnus-newsgroup-name 'gnus-group-history))
10948            (gnus-group-marked (list group))
10949            article info)
10950       (with-temp-buffer
10951         (mime-insert-entity-content entity)
10952         (setq article (gnus-request-accept-article group)))
10953       (when (and (consp article)
10954                  (numberp (setq article (cdr article))))
10955         (setq info (gnus-get-info group))
10956         (gnus-info-set-read info
10957                             (gnus-remove-from-range (gnus-info-read info)
10958                                                     (list article)))
10959         (when (string-equal group gnus-newsgroup-name)
10960           (forward-line 1)
10961           (let (gnus-show-threads)
10962             (gnus-summary-goto-subject article t))
10963           (gnus-summary-clear-mark-forward 1))
10964         (set-buffer gnus-group-buffer)
10965         (gnus-group-get-new-news-this-group nil t)))))
10966
10967 (mime-add-condition
10968  'action '((type . message)(subtype . rfc822)
10969            (major-mode . gnus-original-article-mode)
10970            (method . gnus-mime-extract-message/rfc822)
10971            (mode . "extract")
10972            ))
10973
10974 (mime-add-condition
10975  'action '((type . message)(subtype . news)
10976            (major-mode . gnus-original-article-mode)
10977            (method . gnus-mime-extract-message/rfc822)
10978            (mode . "extract")
10979            ))
10980
10981 (defun gnus-mime-extract-multipart (entity situation)
10982   (let ((children (mime-entity-children entity))
10983         mime-acting-situation-to-override
10984         f)
10985     (while children
10986       (mime-play-entity (car children)
10987                         (cons (assq 'mode situation)
10988                               mime-acting-situation-to-override))
10989       (setq children (cdr children)))
10990     (if (setq f (cdr (assq 'after-method
10991                            mime-acting-situation-to-override)))
10992         (eval f)
10993       )))
10994
10995 (mime-add-condition
10996  'action '((type . multipart)
10997            (method . gnus-mime-extract-multipart)
10998            (mode . "extract")
10999            )
11000  'with-default)
11001
11002
11003 ;;; @ end
11004 ;;;
11005
11006 (defun gnus-summary-inherit-default-charset ()
11007   "Import `default-mime-charset' from summary buffer."
11008   (if (buffer-live-p gnus-summary-buffer)
11009       (if (local-variable-p 'default-mime-charset gnus-summary-buffer)
11010           (progn
11011             (make-local-variable 'default-mime-charset)
11012             (setq default-mime-charset
11013                   (with-current-buffer gnus-summary-buffer
11014                     default-mime-charset)))
11015         (kill-local-variable 'default-mime-charset))))
11016
11017 (defun gnus-summary-setup-default-charset ()
11018   "Setup newsgroup default charset."
11019   (if (equal gnus-newsgroup-name "nndraft:drafts")
11020       (progn
11021         (setq gnus-newsgroup-charset nil)
11022         (make-local-variable 'default-mime-charset)
11023         (setq default-mime-charset nil))
11024     (let ((ignored-charsets
11025            (or gnus-newsgroup-ephemeral-ignored-charsets
11026                (append
11027                 (and gnus-newsgroup-name
11028                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11029                 gnus-newsgroup-ignored-charsets)))
11030           charset)
11031       (setq gnus-newsgroup-charset
11032             (or gnus-newsgroup-ephemeral-charset
11033                 (when (and gnus-newsgroup-name
11034                            (setq charset (gnus-parameter-charset
11035                                           gnus-newsgroup-name)))
11036                   (make-local-variable 'default-mime-charset)
11037                   (setq default-mime-charset charset))
11038                 gnus-default-charset))
11039       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11040            ignored-charsets))))
11041
11042 ;;;
11043 ;;; Mime Commands
11044 ;;;
11045
11046 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11047   "Display the current article buffer fully MIME-buttonized.
11048 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11049 treated as multipart/mixed."
11050   (interactive "P")
11051   (require 'gnus-art)
11052   (let ((gnus-unbuttonized-mime-types nil)
11053         (gnus-mime-display-multipart-as-mixed show-all-parts))
11054     (gnus-summary-show-article)))
11055
11056 (defun gnus-summary-repair-multipart (article)
11057   "Add a Content-Type header to a multipart article without one."
11058   (interactive (list (gnus-summary-article-number)))
11059   (gnus-with-article article
11060     (message-narrow-to-head)
11061     (message-remove-header "Mime-Version")
11062     (goto-char (point-max))
11063     (insert "Mime-Version: 1.0\n")
11064     (widen)
11065     (when (search-forward "\n--" nil t)
11066       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11067         (message-narrow-to-head)
11068         (message-remove-header "Content-Type")
11069         (goto-char (point-max))
11070         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11071                         separator))
11072         (widen))))
11073   (let (gnus-mark-article-hook)
11074     (gnus-summary-select-article t t nil article)))
11075
11076 (defun gnus-summary-toggle-display-buttonized ()
11077   "Toggle the buttonizing of the article buffer."
11078   (interactive)
11079   (require 'gnus-art)
11080   (if (setq gnus-inhibit-mime-unbuttonizing
11081             (not gnus-inhibit-mime-unbuttonizing))
11082       (let ((gnus-unbuttonized-mime-types nil))
11083         (gnus-summary-show-article))
11084     (gnus-summary-show-article)))
11085
11086 ;;;
11087 ;;; Intelli-mouse commmands
11088 ;;;
11089
11090 (defun gnus-wheel-summary-scroll (event)
11091   (interactive "e")
11092   (let ((amount (if (memq 'shift (event-modifiers event))
11093                     (car gnus-wheel-scroll-amount)
11094                   (cdr gnus-wheel-scroll-amount)))
11095         (direction (- (* (static-if (featurep 'xemacs)
11096                              (event-button event)
11097                            (cond ((eq 'mouse-4 (event-basic-type event))
11098                                   4)
11099                                  ((eq 'mouse-5 (event-basic-type event))
11100                                   5)))
11101                          2) 9))
11102         edge)
11103     (gnus-summary-scroll-up (* amount direction))
11104     (when (gnus-eval-in-buffer-window gnus-article-buffer
11105             (save-restriction
11106               (widen)
11107               (and (if (< 0 direction)
11108                        (gnus-article-next-page 0)
11109                      (gnus-article-prev-page 0)
11110                      (bobp))
11111                    (if (setq edge (get-text-property
11112                                    (point-min) 'gnus-wheel-edge))
11113                        (setq edge (* edge direction))
11114                      (setq edge -1))
11115                    (or (plusp edge)
11116                        (let ((buffer-read-only nil)
11117                              (inhibit-read-only t))
11118                          (put-text-property (point-min) (point-max)
11119                                             'gnus-wheel-edge direction)
11120                          nil))
11121                    (or (> edge gnus-wheel-edge-resistance)
11122                        (let ((buffer-read-only nil)
11123                              (inhibit-read-only t))
11124                          (put-text-property (point-min) (point-max)
11125                                             'gnus-wheel-edge
11126                                             (* (1+ edge) direction))
11127                          nil))
11128                    (eq last-command 'gnus-wheel-summary-scroll))))
11129       (gnus-summary-next-article nil nil (minusp direction)))))
11130
11131 (defun gnus-wheel-install ()
11132   "Enable mouse wheel support on summary window."
11133   (when gnus-use-wheel
11134     (let ((keys
11135            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11136       (dolist (key keys)
11137         (define-key gnus-summary-mode-map key
11138           'gnus-wheel-summary-scroll)))))
11139
11140 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11141
11142 ;;;
11143 ;;; Traditional PGP commmands
11144 ;;;
11145
11146 (defun gnus-summary-decrypt-article (&optional force)
11147   "Decrypt the current article in traditional PGP way.
11148 This will have permanent effect only in mail groups.
11149 If FORCE is non-nil, allow editing of articles even in read-only
11150 groups."
11151   (interactive "P")
11152   (gnus-summary-select-article t)
11153   (gnus-eval-in-buffer-window gnus-article-buffer
11154     (save-excursion
11155       (save-restriction
11156         (widen)
11157         (goto-char (point-min))
11158         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11159           (error "Not a traditional PGP message!"))
11160         (let ((armor-start (match-beginning 0)))
11161           (if (and (pgg-decrypt-region armor-start (point-max))
11162                    (or force (not (gnus-group-read-only-p))))
11163               (let ((inhibit-read-only t)
11164                     buffer-read-only)
11165                 (delete-region armor-start
11166                                (progn
11167                                  (re-search-forward "^-+END PGP" nil t)
11168                                  (beginning-of-line 2)
11169                                  (point)))
11170                 (insert-buffer-substring pgg-output-buffer))))))))
11171
11172 (defun gnus-summary-verify-article ()
11173   "Verify the current article in traditional PGP way."
11174   (interactive)
11175   (save-excursion
11176     (set-buffer gnus-original-article-buffer)
11177     (goto-char (point-min))
11178     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11179       (error "Not a traditional PGP message!"))
11180     (re-search-forward "^-+END PGP" nil t)
11181     (beginning-of-line 2)
11182     (call-interactively (function pgg-verify-region))))
11183
11184 ;;;
11185 ;;; Generic summary marking commands
11186 ;;;
11187
11188 (defvar gnus-summary-marking-alist
11189   '((read gnus-del-mark "d")
11190     (unread gnus-unread-mark "u")
11191     (ticked gnus-ticked-mark "!")
11192     (dormant gnus-dormant-mark "?")
11193     (expirable gnus-expirable-mark "e"))
11194   "An alist of names/marks/keystrokes.")
11195
11196 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11197 (defvar gnus-summary-mark-map)
11198
11199 (defun gnus-summary-make-all-marking-commands ()
11200   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11201   (dolist (elem gnus-summary-marking-alist)
11202     (apply 'gnus-summary-make-marking-command elem)))
11203
11204 (defun gnus-summary-make-marking-command (name mark keystroke)
11205   (let ((map (make-sparse-keymap)))
11206     (define-key gnus-summary-generic-mark-map keystroke map)
11207     (dolist (lway `((next "next" next nil "n")
11208                     (next-unread "next unread" next t "N")
11209                     (prev "previous" prev nil "p")
11210                     (prev-unread "previous unread" prev t "P")
11211                     (nomove "" nil nil ,keystroke)))
11212       (let ((func (gnus-summary-make-marking-command-1
11213                    mark (car lway) lway name)))
11214         (setq func (eval func))
11215         (define-key map (nth 4 lway) func)))))
11216
11217 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11218   `(defun ,(intern
11219             (format "gnus-summary-put-mark-as-%s%s"
11220                     name (if (eq way 'nomove)
11221                              ""
11222                            (concat "-" (symbol-name way)))))
11223      (n)
11224      ,(format
11225        "Mark the current article as %s%s.
11226 If N, the prefix, then repeat N times.
11227 If N is negative, move in reverse order.
11228 The difference between N and the actual number of articles marked is
11229 returned."
11230        name (car (cdr lway)))
11231      (interactive "p")
11232      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11233
11234 (defun gnus-summary-generic-mark (n mark move unread)
11235   "Mark N articles with MARK."
11236   (unless (eq major-mode 'gnus-summary-mode)
11237     (error "This command can only be used in the summary buffer"))
11238   (gnus-summary-show-thread)
11239   (let ((nummove
11240          (cond
11241           ((eq move 'next) 1)
11242           ((eq move 'prev) -1)
11243           (t 0))))
11244     (if (zerop nummove)
11245         (setq n 1)
11246       (when (< n 0)
11247         (setq n (abs n)
11248               nummove (* -1 nummove))))
11249     (while (and (> n 0)
11250                 (gnus-summary-mark-article nil mark)
11251                 (zerop (gnus-summary-next-subject nummove unread t)))
11252       (setq n (1- n)))
11253     (when (/= 0 n)
11254       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11255     (gnus-summary-recenter)
11256     (gnus-summary-position-point)
11257     (gnus-set-mode-line 'summary)
11258     n))
11259
11260 (defun gnus-summary-insert-articles (articles)
11261   (when (setq articles
11262               (gnus-sorted-difference articles
11263                                       (mapcar (lambda (h)
11264                                                 (mail-header-number h))
11265                                               gnus-newsgroup-headers)))
11266     (setq gnus-newsgroup-headers
11267           (merge 'list
11268                  gnus-newsgroup-headers
11269                  (gnus-fetch-headers articles)
11270                  'gnus-article-sort-by-number))
11271     ;; Suppress duplicates?
11272     (when gnus-suppress-duplicates
11273       (gnus-dup-suppress-articles))
11274
11275     ;; We might want to build some more threads first.
11276     (when (and gnus-fetch-old-headers
11277                (eq gnus-headers-retrieved-by 'nov))
11278       (if (eq gnus-fetch-old-headers 'invisible)
11279           (gnus-build-all-threads)
11280         (gnus-build-old-threads)))
11281     ;; Let the Gnus agent mark articles as read.
11282     (when gnus-agent
11283       (gnus-agent-get-undownloaded-list))
11284     ;; Remove list identifiers from subject
11285     (when gnus-list-identifiers
11286       (gnus-summary-remove-list-identifiers))
11287     ;; First and last article in this newsgroup.
11288     (when gnus-newsgroup-headers
11289       (setq gnus-newsgroup-begin
11290             (mail-header-number (car gnus-newsgroup-headers))
11291             gnus-newsgroup-end
11292             (mail-header-number
11293              (gnus-last-element gnus-newsgroup-headers))))
11294     (when gnus-use-scoring
11295       (gnus-possibly-score-headers))))
11296
11297 (defun gnus-summary-insert-old-articles (&optional all)
11298   "Insert all old articles in this group.
11299 If ALL is non-nil, already read articles become readable.
11300 If ALL is a number, fetch this number of articles."
11301   (interactive "P")
11302   (prog1
11303       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11304             older len)
11305         (setq older
11306               (gnus-sorted-difference
11307                (gnus-uncompress-range (list gnus-newsgroup-active))
11308                old))
11309         (setq len (length older))
11310         (cond
11311          ((null older) nil)
11312          ((numberp all)
11313           (if (< all len)
11314               (setq older (last older all))))
11315          (all nil)
11316          (t
11317           (if (and (numberp gnus-large-newsgroup)
11318                    (> len gnus-large-newsgroup))
11319               (let* ((cursor-in-echo-area nil)
11320                      (initial (gnus-parameter-large-newsgroup-initial 
11321                                gnus-newsgroup-name))
11322                      (input
11323                       (read-string
11324                        (format
11325                         "How many articles from %s (%s %d): "
11326                         (gnus-limit-string
11327                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11328                         (if initial "max" "default")
11329                         len)
11330                        (if initial
11331                            (cons (number-to-string initial)
11332                                  0)))))
11333                 (unless (string-match "^[ \t]*$" input)
11334                   (setq all (string-to-number input))
11335                   (if (< all len)
11336                       (setq older (last older all))))))))
11337         (if (not older)
11338             (message "No old news.")
11339           (gnus-summary-insert-articles older)
11340           (gnus-summary-limit (gnus-sorted-nunion old older))))
11341     (gnus-summary-position-point)))
11342
11343 (defun gnus-summary-insert-new-articles ()
11344   "Insert all new articles in this group."
11345   (interactive)
11346   (prog1
11347       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11348             (old-active gnus-newsgroup-active)
11349             (nnmail-fetched-sources (list t))
11350             i new)
11351         (setq gnus-newsgroup-active
11352               (gnus-activate-group gnus-newsgroup-name 'scan))
11353         (setq i (1+ (cdr old-active)))
11354         (while (<= i (cdr gnus-newsgroup-active))
11355           (push i new)
11356           (incf i))
11357         (if (not new)
11358             (message "No gnus is bad news.")
11359           (setq new (nreverse new))
11360           (gnus-summary-insert-articles new)
11361           (setq gnus-newsgroup-unreads
11362                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11363           (gnus-summary-limit (gnus-sorted-nunion old new))))
11364     (gnus-summary-position-point)))
11365
11366 (gnus-summary-make-all-marking-commands)
11367
11368 (gnus-ems-redefine)
11369
11370 (provide 'gnus-sum)
11371
11372 (run-hooks 'gnus-sum-load-hook)
11373
11374 ;;; gnus-sum.el ends here